Update property view on click of project explorer, eclipse plugin - eclipse

I have created a custom project in project explorer. Whenever I click on custom project folder currently it shows default property sheet but I want to customize this property sheet.
I have gone through the tabbed property example but I am not able customize it.
Please can anyone provide me some sample examples or code for same.
Thanks.

how to connect that property view to an editor or project explorer
model classes for you custom project and its folders should implement IAdaptable interface and return an object implementing IPropertySource that describes given element. it will be passed to properties view automatically when you click on the element.
alternativelly, you can avoid implementing IAdaptable and create an IAdapterFactory that converts an instance of you project/folder element into corresponding IPropertySoure but then you have to make Eclipse framework aware of your IAdapterFactory implementation.
public class MyProjectAdapterFactory implements IAdapterFactory {
#Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType== IPropertySource.class && adaptableObject instanceof MyProject){
return new MyProjectPropertySource((MyProject) adaptableObject);
}
return null;
}
#Override
public Class[] getAdapterList() {
return new Class[] { IPropertySource.class };
}
}
register it in you plugin.xml file:
<extension point="org.eclipse.core.runtime.adapters">
<factory adaptableType="my.example.MyProject" class="my.example.MyProjectAdapterFactory">
<adapter type="org.eclipse.ui.views.properties.IPropertySource"/>
</factory>
</extension>
look at the full tutorial: http://www.vogella.de/articles/EclipsePlugIn/article.html

Related

How to add action item to the coolbar of e4 eclipse rcp application?

I am currently trying to port my eclipse 3 rcp application to e4.The major hurdle I am facing is to use action item which i was using in e3.In eclipse 3 application i was creating action item of coolbar by extending action.The code was looking like below spinets.
public class Testaction extends Action {
private IWorkbenchWindow window;
public Testaction (IWorkbenchWindow window, String string) {
setText(string);
setToolTipText(string);
setId("ID");
setImageDescriptor(Activator.getImageDescriptor("/icons/some.png"));
this.window = window;
}
#override
public void run() {
/**
Do something
**/
super.run();
}
was adding it to coolbar through
toolbar.add(demoaction);
But with e4 this part seems to be changed and I understand that there we need to have annotation #Execute which will excute the contribution which we will be giving through setcontribuitionuri as below snippet
part.setContributionURI(
"bundleclass://bundle/bundle.contribuitionclass");
I just want to know whether I can use my old action class here or i need to port everything to newer style .
Any help on this will be appreciated.Thanks in advance...
e4 does not support Actions for model elements in the Application.e4xmi.
The simplest conversion is to use a Direct ToolItem in the tool bar. However using a Handled ToolItem with a Command and Handler is more flexible.
In either case the Image, Label and Tooltip are specified in the Application.e4xmi.

Add icons to elements in ElementListSelectionDialog

I have the following code to create a dialog in a RCP Eclipse application using the ElementListSelectionDialog class:
ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new LabelProvider());
dialog.setTitle("test");
dialog.setMessage("test");
dialog.setMultipleSelection(false);
dialog.setElements(new String[]{"test1", "test2", "test3"});
dialog.open();
The previous code generates this dialog:
This is fine but I also want to add icons to the elements in the list, similar to how it looks the web.xml editor:
You need to extend the LabelProvider you are passing to the ElementListSelectionDialog constructor and override the
public Image getImage(Object element)
method. This will be called for each of the objects you add to the dialog with the setElements method.

How do I make eclipse custom view take data from the file currently active in the editor?

I recently went into creating my own personal DSL with xtext and manage to create a mini programming language based on C (simple expressions and basic functions). My current task it to create a custom tree view for the language that would allow me to see all the functions as root elements and the instructions inside them as children.
My actual problem that I can't seem to resolve is exactly how do I make the custom tree view I wish to create take the data from the file that I'm currently working on.
I have an RCP product ready for the DSL that I can use and I would like to include this view over there.
I have created the interface for the view with WindowBuilder and made it as a ViewPart.
In the end I wish it to look close to what the standard outline for a java program looks like.
Thanks for the help in advance.
If you work with your own view, you can add an IPartListener implementation that will notify you on when an editor is activated with the following code:
getViewSite().getPage().addPartListener(new IPartListener() {
#Override
public void partOpened(IWorkbenchPart part) {
}
#Override
public void partDeactivated(IWorkbenchPart part) {
}
#Override
public void partClosed(IWorkbenchPart part) {
}
#Override
public void partBroughtToTop(IWorkbenchPart part) {
}
#Override
public void partActivated(IWorkbenchPart part) {
// Add view initialization from the new part
}
});

How to create custom image decorator in java file using eclipse plugin

I would like to use some decorators in my Eclipse plugin. I have created a plugin where I created my own editor for my own .test file. If the user edits .test file and saves it. The file must show some decorations not only the .test file but also the project must show the decorator. I am stuck with this problem I can't find any good tutorial to create decorators.
I Have seen some of the websites like https://www.eclipse.org/articles/Article-Decorators/decorators.html but I couldn't get the exact point.
Will some one please tell me how to create custom decorator for my eclipse plugin.
A ILightweightLabelDecorator is the most common type of decorator
Declare this in your plugin.xml with something like this:
<extension point="org.eclipse.ui.decorators">
<decorator
id="my.decorator.id"
class="my.decorator.Decorator"
label="My Decorator"
state="true"
lightweight="true"
adaptable="true">
<enablement>
<objectClass name="org.eclipse.core.resources.IResource"/>
</enablement>
</decorator>
</extension>
You will have to adjust the enablement to suit what you want.
Your decorator class would be something like:
public class Decorator extends BaseLabelDecorator implements ILightweightLabelDecorator
{
#Override
public void decorate(final Object element, final IDecoration decoration)
{
// TODO call decoration methods to add overlay images or prefix / suffix text
}
}

Eclipse RCP: how to get Show View menu instead of a dialog

I've added to my perspective's org.eclipse.ui.menus
<command
commandId="org.eclipse.ui.views.showView"
style="pulldown">
</command>
This adds Show View item to main menu, but this item is not a menu (as in the Eclipse Window menu). Instead pressing it shows a dialog where I can select a view. How do I get a menu instead?
You have to create ContributionItem class like below:
public class MyShowViewContributionItem extends org.eclipse.ui.internal.ShowViewMenu {
public MyShowViewContributionItem() {
this("om.myplugin.myShowViewId");
}
public MyShowViewContributionItem(String id) {
super(org.eclipse.ui.PlatformUI.getWorkbench().getActiveWorkbenchWindow(), id);
}
}
then in your plugin.xml org.eclipse.ui.menus extension:
<menu
label="My Show View">
<dynamic
class="com.myplugin.MyShowViewContributionItem"
id="com.myplugin.myShowViewId">
</dynamic>
</menu>
Cheers,
Max
Just to share on my recent experiment in trying to do the same thing, what Max suggested in his answer will work but leaves you using internal code (resulting in a 'Discouraged Access' warning).
Another approach is to build the menu through your applications action bar advisor. Although, this approach will leave you to having to write code (oppose to use providing menu contributions in the plugin XML definition). Consider the following example:
public class ApplicationActionBarAdvisor extends ActionBarAdvisor
{
private IContributionItem contributionOpenPerspective;
private IContributionItem contributionShowView;
...
protected void makeActions(IWorkbenchWindow window)
{
...
contributionOpenPerspective = ContributionItemFactory.
PERSPECTIVES_SHORTLIST.create(window);
contributionShowView = ContributionItemFactory.
VIEWS_SHORTLIST.create(window);
...
}
protected void fillMenuBar(IMenuManager menuBar)
{
...
MenuManager windowMenu = new MenuManager("&Window",
IWorkbenchActionConstants.M_WINDOW);
menuBar.add(windowMenu);
MenuManager openPerspectiveMenu = new MenuManager("&Open Perspective");
openPerspectiveMenu.add(perspectivesContribution);
windowMenu.add(openPerspectiveMenu);
MenuManager showViewMenu = new MenuManager("Show &View");
showViewMenu.add(viewsContribution);
windowMenu.add(showViewMenu);
...
}
}
A possible downside to this approach is with the interaction between menus created in the advisor and menus created by menu contributions. Since advisor menu items are created before menu contributions, you are left to deal with adding more sorting logic in your menu contributions. This might be fine for most people, however, you lose the 'feel' of a centralized menu structure from org.eclipse.ui.menus (even if the feeling is an illusion when other plugins come into play with their own menu contributions).
I've also included the building of a perspective menu as well; completely option, but I added it if anyone was attempting to perform the same menu building with perspectives.