Thursday, October 17, 2013

Launching a URL in external browser from an eclipse plugin

public class HelpHandler extends AbstractHandler implements IHandler{


public static final String HELP_LIBRARY = "http:/kk.com/KKLibrary/";

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {

try {
PlatformUI.getWorkbench().getBrowserSupport().getExternalBrowser().openURL(new URL(HELP_LIBRARY ));
} catch (PartInitException e) {
e.printStackTrace();
} catch (MalformedURLException e) {
e.printStackTrace();
}
return null;
}
}

Tuesday, October 15, 2013

toArray Dynamic behaviour

public class ToArrayTest {

public static void main(String[] args) {

ArrayList<String> arrayList = new ArrayList<String>();
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");

//what happens here??, since I have allocated new String[0] for single element, will it return single element or all elements ??
String[] array = arrayList.toArray(new String[0]); 
System.out.println(array.length);

}
}


Output:  4


As per spec, it's going to create a new array, if it does not fit in.
Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. If the list fits in the specified array, it is returned therein. Otherwise, a new array is allocated with the runtime type of the specified array and the size of this list. 

Wednesday, October 9, 2013

Understanding how Eclipse plug-ins work with OSGi

Install the plug-in bundle in the Equinox console


  1. Install the plug-in bundle in the Equinox console.
    osgi> install file:///<path to bundle>
    Equinox lists the bundle ID for the newly installed bundle:
    Bundle id is 17
  2. Enter the following line to start the bundle in the Equinox console, where <id> is the bundle ID assigned when the bundle was installed:
    osgi>  start <id>
  3. Retrieve the service status in the Equinox console to verify that the bundle started:
    osgi> ss
    When the bundle starts, the bundle lists the ACTIVE state, for example:
    17      ACTIVE      com.mycompany.plugin.bundle_xx

Eclipse Equinox and OSGI

Go through this article to get the understanding on Eclipse Equinox
http://www.theserverside.com/news/1365049/Eclipse-Equinox-and-OSGi

Understanding UML Class diagrams


http://msdn.microsoft.com/en-us/library/dd409437%28VS.100%29.aspx



Three classes showing relationships and properties
Shape
Element
Description
1
Class
A definition of objects that share given structural or behavioral characteristics. For more information, see Properties of Types in UML Class Diagrams.
1
Classifier
The general name for a class, interface, or enumeration. Components, use cases, and actors are also classifiers.
2
Collapse/ Expand control
If you cannot see the details of a classifier, click the expander at upper-left of the classifier. You might also have to click the [+] on each segment.
3
Attribute
A typed value attached to each instance of a classifier.
To add an attribute, click the Attributes section and then press ENTER. Type the signature of the attribute. For more information, seeProperties of Attributes in UML Class Diagrams.
4
Operation
A method or function that can be performed by instances of a classifier. To add an operation, click the Operations section and then pressENTER. Type the signature of the operation. For more information, see Properties of Operations in UML Class Diagrams.
5
Association
A relationship between the members of two classifiers. For more information, see Properties of Associations in UML Class Diagrams.
5a
Aggregation
An association representing a shared ownership relationship. The Aggregation property of the owner role is set to Shared.
5b
Composition
An Association representing a whole-part relationship. The Aggregation property of the owner role is set to Composite.
6
Association Name
The name of an association. The name can be left empty.
7
Role Name
The name of a role, that is, one end of an association. Can be used to refer to the associated object. In the previous illustration, for any OrderOO.ChosenMenu is its associated Menu.
Each role has its own properties, listed under the properties of the association.
8
Multiplicity
Indicates how many of the objects at this end can be linked to each object at the other. In the example, each Order must be linked to exactly one Menu.
* means that there is no upper limit to the number of links that can be made.
9
Generalization
The specific classifier inherits part of its definition from the general classifier. The general classifier is at the arrow end of the connector. Attributes, associations, and operations are inherited by the specific classifier.
Use the Inheritance tool to create a generalization between two classifiers.
Package containing interface and enumeration
Shape
Element
Description
10
Interface
A definition of part of the externally visible behavior of an object. For more information, see Properties of Types in UML Class Diagrams.
11
Enumeration
A classifier that consists of a set of literal values.
12
Package
A group of classifiers, associations, actions, lifelines, components and packages. A logical class diagram shows that the member classifiers and packages are contained within the package.
Names are scoped within packages so that Class1 within Package1 is distinct from Class1 outside that package. The name of the package appears as part of the Qualified Name properties of its contents.
You can set the Linked Package property of any UML diagram to refer to a package. All the elements that you create on that diagram will then become part of the package. They will appear under the package in UML Model Explorer.
13
Import
A relationship between packages, indicating that one package includes all the definitions of another.
14
Dependency
The definition or implementation of the dependent classifier might change if the classifier at the arrowhead end is changed.
Realization shown with conector and lollipop
Shape
Element
Description
15
Realization
The class implements the operations and attributes defined by the interface.
Use the Inheritance tool to create a realization between a class and an interface.
16
Realization
An alternative presentation of the same relationship. The label on the lollipop symbol identifies the interface.
To create this presentation, select an existing realization relationship. A Action tag appears near the association. Click the action tag, and then clickShow as Lollipop.

Monday, October 7, 2013

Loading a file from OSGI bundle


Bundle bundle = Activator.getDefault().getBundle();
Path path = new Path("path/to/your/file.extension"); //$NON-NLS-1$
URL url = FileLocator.find(bundle, path, Collections.EMPTY_MAP);
URL fileUrl = null;
try {
fileUrl = FileLocator.toFileURL(url);
}
catch (IOException e) {
// Will happen if the file cannot be read for some reason
e.printStackTrace();
}
File file = new File(fileUrl.getPath());


http://codeache.blogspot.in/2007/05/loading-files-with-rcp.html