Add dynamic team actions in Eclipse - eclipse

I am developing an Eclipse Team Plugin. I want to contribute the Team popup menu, so I have defined an action in my plugin.xml file:
<plugin>
<extension point="org.eclipse.ui.popupMenus">
<objectContribution
adaptable="true"
id="com.myexample.ui.ResourceContributions"
objectClass="org.eclipse.core.resources.IResource">
<action
class="com.myexample.ui.actions.MyAction"
id="com.myexample.ui.actions.MyActionId"
label="Execute action" />
</objectContribution>
</extension
</plugin>
Also have an implementation for the action:
public class MyAction extends TeamAction {
...
}
At this point all is ok, my action is shown and I can execute it.
Now, what I want is to change the text of the action dynamically, when the selection changes, depending in some properties of the selected objects.
Is this possible? How could I do it? Could I do it programmatically?

Here is what I would try:
Override TeamAction.selectionChanged(IAction action, ISelection selection) in your MyAction class
Invoke IAction.setText(String text) in your overridden method.

Related

View does not displayed

I have made Hello World RCP application and got the following class structure:
ApplicationActionBarAdvisor.java
ApplicationWorkbenchAdvisor.java
ApplicationWorkbenchWindowAdvisor.java
Application.java
Perspective.java
Further I tried to add some view to the perspective.
Add extension point to my plugin.xml:
<extension point="org.eclipse.ui.views">
<view
class="first.rcp.application.MainView"
id="first.rcp.application.MainView"
name="name"
restorable="true">
</view>
</extension>
and created class MainView.java.
Add additional code to Perspective.createInitialLayout():
layout.addStandaloneView(MainView.ID, true, IPageLayout.LEFT, 1.0f, layout.getEditorArea());
IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IWorkbenchPage activePage = activeWorkbenchWindow.getActivePage();
try {
activePage.showView(MainView.ID);
} catch (PartInitException e) {
e.printStackTrace();
}
But view does not displayed.
I set breakpoint into Perspective.createInitialLayout() and found that it is not performed.
I tried to add showPerspective() method to ApplicationWorkbenchWindowAdvisor() and set PERSPECTIVE_ID in ApplicationWorkbenchAdvisor to the id of my perspective.
But the code into Perspective.createInitialLayout() still not performed.
Which point it should be called from?
Eclipse IDE have Java perspective with number of views opened by default. I.e. createInitialLayout() of the Java perspective is called during launching of eclipse IDE. How is it implemented? May be there are some configuration file?
My perspective declaration is:
<extension point="org.eclipse.ui.perspectives">
<perspective
name="RCP Perspective"
class="first.rcp.application.Perspective"
id="first.rcp.application.Perspective">
</perspective>
</extension>
The code in ApplicationWorkbenchAdvisor.getInitialWindowPerspectiveId() is:
public String getInitialWindowPerspectiveId() {
return PERSPECTIVE_ID;
}
private static final String PERSPECTIVE_ID = "first.rcp.application.Perspective";
Solution №1.
Go through the New Plug-in project wizard, make sure 'would you like to create a rich client application' is set to Yes, make sure 'Generate an activator, a Java class that controls the plug-in lifecycle' is cheked and select 'Hello RCP' on the Available Template page.
Go to MANIFEST.MF, Extensions. Add new extension 'org.eclipse.ui.views', add an appropriate class.
Add new extension 'org.eclipse.ui.perspectiveExtensions' with the view. Specify view id to the id of the previously created view.
Solution №2.
Go through the New Plug-in project wizard, make sure 'would you like to create a rich client application' is set to Yes, make sure 'Generate an activator, a Java class that controls the plug-in lifecycle' is cheked and select 'RCP application with a view' on the Available Template page.

Add custom properties to eclipse's project class

I have a custom project nature and created a new project that has this new custom nature.
What I am trying to do now, is extend the properties of that project, so when it is selected e.g. in package explorer view, not only the standard project properties are shown in the (standard) property-view but also customized ones (like the nature of the selected project - but only for a project that has my custom nature)
Is this possible with standard eclipse extension points?
I have doubts since I don't have my own class where I could register a property-descriptor, just a new nature.
You should be able to define a project properties page without a project class, as I've done in the Haskell plugin:
<page
name="%projectFlagsPP_name"
class="net.sf.eclipsefp.haskell.ui.properties.UserFlagsPP"
id="net.sf.eclipsefp.haskell.ui.properties.UserFlagsPP">
<filter
name="nature"
value="net.sf.eclipsefp.haskell.core.project.HaskellNature">
</filter>
<filter
name="open"
value="true">
</filter>
<enabledWhen>
<adapt type="org.eclipse.core.resources.IProject" />
</enabledWhen>
</page>
And then the java code starts like:
public class UserFlagsPP extends PropertyPage implements
IWorkbenchPreferencePage {
This says that the property page will appear for a IProject that has the Haskell Nature...

Extend Teamsite actions

I was wondering if it possible to extend Teamsite functionality? For example, I would like to add my own button under Actions -> MyAction which would perform my java based operation (update pages or something)?
For custom menu actions you'll need to make modifications to
<iw-home>/local/config/lib/content_center/customer_src/etc/conf/customer/ui_custom.xml
There should be some examples in the file unless you've erased the contents. The basic format is as follows:
<action-list id="iw.ccpro.filesys.menubar">
<menu id="iw.ccpro.action.menu">
<link id="company.ccpro.list_directory.custMenuAction.link"
label="Custom Action"
description="Custom Action Description"
url="/iw-bin/custom_menu_action.ipl"
target="_blank"
icon="/base/images/customIcon.gif"
/>
</menu>
</action-list>
For a Java based operation you would just change the url to your servlet path.
For example:
url="<iw-hostname>/iw-cc/command/customJavaAction"

How can I create a view using the E4 programming model to be a plug-in for Eclipse 4.2 or above?

Most of the existing Eclipse plug-ins use the extension registry and subclasses of ViewPart, coupled with the compatibility layer. As a result, writing a new view (especially using the new plug-in wizard in PDE) results in plug-ins that look like:
<plugin>
<extension point="org.eclipse.ui.views">
<view name="Example View" class="org.example.ExampleView"/>
</extension>
</plugin>
public class ExampleView extends ViewPart {
public void createPartControl(Composite parent) {
...
}
}
Is it possible to take advantage of the E4 programming model to create a view like:
public class Example {
#Inject
public Example(Composite parent) {
...
}
}
and have that hooked into an existing Eclipse 4.2 instance, so that it shows up in the 'Show View' menu? If so, how is it declaratively wired in (since that the LegacyIDE.e4xmi is immutable and can't be added to).
Look at the code I've written for the e4 model editor (http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.emf.editor3x/src/org/eclipse/e4/tools/emf/editor3x).
I've a set of wrappers for this at http://git.eclipse.org/c/e4/org.eclipse.e4.tools.git/tree/bundles/org.eclipse.e4.tools.compat for 4.3 we plan on direct support.

Is it possible to make subfolders in the "Show View" menu?

Let's say I have some view called "My View".
I know I can create a category, "My Category", and place my view inside it.
I'd like to create a subfolder/category inside "My Category" called "Sub Folder" and place my view inside it.
Then the view would be found through the "Show View" popup as follows:
My Category -> Sub Folder -> My View
I know you can do this with exports/imports, but it doesn't seem like you can with views.
Here is a sample plugin.xml
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="My Category"
id="My_Category">
</category>
<category
id="My_Sub_Folder"
name="Sub Folder"
parentCategory="My_Category">
</category>
<view
name="My View"
icon="icons/sample.gif"
category="My_Sub_Folder"
class="sample_plugin.views.SampleView"
id="sample_plugin.views.SampleView">
</view>
</extension>
</plugin>
However, when I use the plugin.xml above, the view category does not show up and the view is found in the "Other" category. If I change the view category back to "My_Category", the view shows up in the parent category.
(revised answer)
You can set up a parent category hierarchy, but the Show View menu will not respect this.
https://bugs.eclipse.org/bugs/show_bug.cgi?id=92894
So the answer is effectively no.
Here is the documentation on setting up the useless parent category:
http://help.eclipse.org/helios/topic/org.eclipse.platform.doc.isv/reference/extension-points/org_eclipse_ui_views.html
it could be that your using package explorer. Switch to Navigator (window-->show view ---> other -------> Navigator)
now you can see the project as folders instead of packages.