views:

290

answers:

4

Hello.

I'm integrating Subversive 0.7.8 into an Eclipse Platform 3.4.2 RCP app. I want to remove (or disable) the SVN "Commit" action in the popup menu of the "Synchronize" view. How can I do ... ?

Thank you for your help. JM.D

A: 

Why would you need to do that ? Can't you simply make it that your users don't have the right to commit using svn rights ?

David Pierre
That's not my use case. I have my own VCS actions that differ from the Subversive ones (specific Commit, and so on).I don't want the user to be able to trigger the Subversive actions.
JM.D
A: 

Two ways: Either alter the plugin.xml files inside the plugins from subversion to remove the contributions (which means that you have to keep your own version of the plugins), or you can remove specific contributions from the platform.

The removal normally takes place in the class that extends the IApplication interface, before you launch the actual Platform.

This is basically a hack, but it will allow you to do what you want without touching the subversion plugins. I don't know the names of the contributions (You would have to look them up in the source code from the plugins) but the code looks like:

IExtensionRegistry extensionRegistry = InternalPlatform.getDefault().getRegistry();

List uiExtensionsToRemove = Arrays.toList(new String[] {"org.eclipse.ui.views.ProgressView" });  // Removing the progress view in this example


String[] tmpNamespaces = extensionRegistry.getNamespaces();
    for (int i = 0; i < tmpNamespaces.length; i++) {
        String tmpNamespace = tmpNamespaces[i];
            try {
                IExtension[] tmpExtensions = extensionRegistry.getExtensions(tmpNamespace);
                for (int j = 0; j < tmpExtensions.length; j++) {
                    IExtension tmpExtension = tmpExtensions[j];
                    ExtensionHandle tmpEHandle = (ExtensionHandle)tmpExtension;
                    String tmpEPUID = tmpEHandle.getExtensionPointUniqueIdentifier();

                    if ("org.eclipse.search.searchPages".equals(tmpEPUID) || "org.eclipse.ui.preferencePages".equals(tmpEPUID) || "org.eclipse.ui.popupMenus".equals(tmpEPUID) || "org.eclipse.ui.actionSets".equals(tmpEPUID)
                            || "org.eclipse.ui.views".equals(tmpEPUID) || "org.eclipse.ui.perspectives".equals(tmpEPUID)) {
                        // only remove part of ui extensions
                        if (tmpEHandle.getNamespace().startsWith("org.eclipse.ui")) {
                            String idOfFirstExtension = tmpEHandle.getConfigurationElements()[0].getAttribute("id");
                            if (!uiExtensionsToRemove.contains(idOfFirstExtension)) {
                                continue;
                            }
                        }
                        removeExtension(tmpEHandle);
                }
            } catch (InvalidRegistryObjectException iroe) {

            }
            //System.out.println("Namespace: " + tmpNamespace);
        }

private void removeExtension(ExtensionHandle extensionHandle) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException, SecurityException, NoSuchMethodException {
    if (removeExtensionMethod == null) {
        removeExtensionMethod = extensionRegistry.getClass().getDeclaredMethod("removeExtension", new Class[] { int.class });
        removeExtensionMethod.setAccessible(true);
    }
    // well, this is some magic:
    int tmpExtId = extensionHandle.hashCode();
    removeExtensionMethod.invoke(extensionRegistry, new Object[] { new Integer(tmpExtId) });
}
Mario Ortegón
Thank you for the hack but the Subversive/Team/Platform framework is a little more complicated ... (not simple contributions in plugin.xml).And even if I want to hack the popup menu with your code, I don't know when I have to do it !! The life cycle of the contributed actions is (very) tricky.Need some more help, thanks.
JM.D
See : http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/team/ui/synchronize/package-summary.htmland : http://help.eclipse.org/ganymede/topic/org.eclipse.platform.doc.isv/reference/api/org/eclipse/team/ui/synchronize/SynchronizePageActionGroup.html
JM.D
A: 

You should certainly check out Activities.

thSoft
Unfortunately, the developers of the Subversive plugin didn't use the "command" model for these actions, and they are not disabled by activities (which I used to remove the "Team" sub-menu in the main window. Noway ... I had to patch directly the (complex) code ...
JM.D
OMGWTF... Sorry for you...
thSoft
A: 

really cool stuff man! this reflection trick allowed me to remove the unwanted popup menus from org.eclipse.team.ui und org.eclipse.compare in my rcp thanks so much!

peter z.