Monday, August 25, 2014

Open a perspective in a new window

Using the following code we can use a perspective in a separate window:



String myPerspectiveid = "dk.bording.viking.rcp.ui.till.editor.TillDesignerPerspective";
PlatformUI.getWorkbench().getActiveWorkbenchWindow().openPage(myPerspectiveid , null);

Sunday, August 24, 2014

Eclipse RCP: How to Hide or Remove a Contribution Item from a toolbar or Menubar

Using the following code we can hide or remove a Contribution item from a toolbar or menubar



private void hidePinbuttonFromPropertySheet() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IViewPart view = page.findView(IPageLayout.ID_PROP_SHEET);   String id = "";
if(view!=null)
{
for ( IContributionItem item : view.getViewSite().getActionBars().getToolBarManager().getItems()) {
if (item.getId().indexOf("PinPropertySheetAction")!=-1) { id = item.getId();
break;
}
}
view.getViewSite().getActionBars().getToolBarManager().remove(id);
view.getViewSite().getActionBars().getToolBarManager().update(false); } }


Thursday, May 2, 2013

Copy Resources from Eclipse Plug-in to Local File System

If we need to read a resource from an eclipse plugin and want to save it to local file system we can use following code :





















Following code will copy basicTemplate.diagram to local-file system:


private void copyTemplateToLocalDirectory() {

URI diagramTemplateFileUri = URI.createPlatformPluginURI(
"/dk.bording.viking.rcp.ui.till.editor/templates/basicTemplate.diagram", true);

URIConverter uriConverter = new ExtensibleURIConverterImpl();
try {

InputStream infile =  uriConverter.createInputStream(diagramTemplateFileUri);
FileOutputStream file = new FileOutputStream( new File(Platform.getInstanceLocation().getURL().getPath()+File.separator+NewFileName.diagram"));
file.write(ByteStreams.toByteArray(infile));
file.close();

} catch (IOException e1) {

e1.printStackTrace();
}

}





PopertyTesters : Requesting Evaluation of Expressions

The command framework is quite lazy. It doesn't really care about your expressions and your wishes about when handlers should be enabled or not. It’s your duty to refresh the enabled state of your handlers by telling the IEvaluationService. It’s not wise to refresh the commands regularly as it can be quite expensive. Instead triggering the refresh on events is the way to go.

using the following code we can Request Evalueation of our Expressoin:


 protected void requestRefresh() {
  IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  IEvaluationService evaluationService = (IEvaluationService) window.getService(IEvaluationService.class);
  if (evaluationService != null) {
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_FOO);
   evaluationService.requestEvaluation(PROPERTY_NAMESPACE + "." + PROPERTY_CAN_BAR);
  }
 }


More information can be found:
http://www.robertwloch.net/2011/01/eclipse-tips-tricks-property-testers-with-command-core-expressions/

Wednesday, January 2, 2013

Eclipse RCP : Execute a command programatically

using the folowing code we can execute a command in eclipse rcp:



IHandlerService handlerService = (IHandlerService) PlatformUI.getWorkbench().getService(IHandlerService.class);
try {
handlerService.executeCommand("org.eclipse.ui.ToggleCoolbarAction", null);
} catch (NotDefinedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotEnabledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NotHandledException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

Tuesday, September 25, 2012

List of all available plug in for eclipse

If you need list of all the available plug-in available for eclipse platform please visit the following website:

http://www.eclipseplugincentral.com/



Sunday, July 15, 2012

Useful Eclipse Shortcut Keys

 http://www.javaprogrammingforums.com/java-jdk-ide-tutorials/19-useful-eclipse-shortcut-keys.html
Shortcut keys make life that little bit quicker! They aid you in working faster and become very handy when programming in Eclipse.

For a full list of shortcuts, in Eclipse 3.1 and above you can press Ctrl+Shift+L for a handy popup.


Shortcuts:


Ctrl+Shift+T

Find Java Type

Start typing the name and the list gets smaller. Try typing the capital letters of the class only (e.g. type "CME" to find "ConcurrentModificationException")

Ctrl+Shift+R

Find Resource

Use this to look for XML files, text files, or files of any other type. which are in your workspace.

Ctrl+E

Open Editor Drop-Down

Presents a popup window listing currently opened files. Start typing to limit the list or simply use the down arrow key.

Ctrl+O

Quick Outline

Use this to find a method or a member variable in a class. Start typing to limit the choices. Press Ctrl+O a second time to include inherited methods.

Ctrl+Space

Content Assist

Context sensitive content completion suggestions while editing Java code.

Ctrl+Shift+Space

Context Information

If typing a method call with several parameters use this to show the applicable parameter types. The current parameter where the cursor is will be shown in bold.

Ctrl+Shift+O

Organize Imports

After typing a class name use this shortcut to insert an import statement. This works if multiple class names haven't been imported too.

F3

Open Declaration

Drills down to the declaration of the type, method, or variable the cursor is on. This works much like a browser hyperlink.

Alt+Left

Backward History

This works like a browser's Back button.

Alt+Right

Forward History

This works like a browser's Forward button

Ctrl+L

Go to Line

Go to a specific line number.

F4

Open Type Hierarchy

Show the type hierarchy (downward tree) or the supertype hierarchy (upward tree).

Ctrl+Alt+H

Open Call Hierarchy

Show where a method is called from. In the Call Hierarchy view keep expanding the tree to continue tracing the call chain.

Ctrl+H

Open Search Dialog

Opens a search dialog with extensive search options for Java packages, types, methods, and fields.

Alt+Shift+R

Rename - Refactoring

Use this to rename type, method, or field. All existing references will be refactored as well.

Alt+Shift+L

Extract Local Variable

Use this to create a local variable from the selected expression. This is useful for breaking up larger expressions to avoid long lines.

Alt+Shift+M

Extract Method

Use this to extract a new method from existing code. The parameter list and return type will be automatically created.

Alt+Shift+Up
Alt+Shift+Down
Alt+Shift+Left
Alt+Shift+Right


Select Enclosing Element / Restore Last Selection / Select Previous Element /
Select Next Element


Useful for selecting context-sensitive blocks (e.g. surrounding loop, method, class, etc.)

Ctrl+Up
Ctrl+Down


Scroll Line Up / Scroll Line Down

Very handy if you want to scroll by 1 line without changing your cursor position or using the mouse.

Ctrl+Shift+U
Alt+Shift+U


Go to Previous Member / Go to Next Member

Great for stepping down through the methods of a Java source file.

Ctrl+Shift+U
Alt+Shift+U


Show Occurrences in File / Remove Occurrences Annotations

Use this to search within the same file - useful for occurrences of private fields and methods.

Ctrl+Shift+P

Go to Matching Bracket

Helps to find the closing bracket of lengthly if-else statements.

Ctrl+J
Ctrl+Shift+J


Incremental Find / Reverse Incremental Find

The first matching occurrence is shown with each typed letter. Press again and the next matching occurrence is shown.

Shift+Enter
Ctrl+Shift+Enter


Insert Line Below / Insert Line Above

Insert a line above or below the current line.

Ctrl+/
Ctrl+\


Add Block Comment / Remove Block Comment

Comment in/out blocks of code with a key stroke.

Ctrl+M

Maximize Active View or Editor

Maximize the current view or editor at the expense of all other currently shown views. Press again to restore to normal view.

Ctrl+F6
Ctrl+F7
Ctrl+F8


Next Editor / Next View / Next Perspective

Learn these to switch among edited files, open views and perspectives.

Ctrl+Alt+Up
Ctrl+Alt+Down


Duplicate Lines / Copy Lines

Doesn't seem like it at first but a great shortcut once you learn to use it. Instead of select, copy and paste simply select and duplicate without affecting the clipboard.

Alt+/

Word Completion

This is excellent for code editing or writing plain help files with variables and other words having no English language equivalents. The word completion is based on the set of words already present in the current file.

Ctrl+I

Correct Indentation

Select a block of Java code or an entire class file and use this shortcut to correct its indentation.

5 Strategies for Getting More Work Done in Less Time

Summary.    You’ve got more to do than could possibly get done with your current work style. You’ve prioritized. You’ve planned. You’ve dele...