Peter
Peter

Reputation: 305

RCP application activities

I have a problem with my RCP application.

First, I defined an activity in my plugin.xml:

<extension
     point="org.eclipse.ui.activities">
  <activity
        id="myproject.view.input.activity"
        name="myproject.view.input.activity">
     <enabledWhen>
        <with
              variable="myproject.view.input.active">
           <equals
                 value="ENABLED">
           </equals>
        </with>
     </enabledWhen>
  </activity>
  <activityPatternBinding
        activityId="myproject.view.input.activity"
        pattern="myproject.gui/myproject.view.input">
  </activityPatternBinding>

Then i defined my SourceProvider:

<extension
     point="org.eclipse.ui.services">
  <sourceProvider
        provider="myproject.util.CommandState">
     <variable
           name="myproject.view.input.active"
           priorityLevel="workbench">
     </variable>

And, finally, my CommandState class:

public class CommandState extends AbstractSourceProvider {

    public final static String OUTPUT_VIEW = "myproject.view.input.active";
    // then goes some others variables, i just skip them
    // ....

    public final static String [] ACTIONS = {OUTPUT_VIEW /*and all others variables*/};

    public final static String ENABLED = "ENABLED";
    public final static String DISENABLED = "DISENABLED";

    private final Map <String, String> currentState = new HashMap <String, String> ();

    @Override
    public void dispose() {
    }

    @Override
    public String[] getProvidedSourceNames() {
        return ACTIONS;
    }

    @Override
    public Map <String, String> getCurrentState() {
        return currentState;
    }

    public void setEnabled(boolean enabled, String [] commands) {
        String value = enabled ? ENABLED : DISENABLED;
        for (String command : commands) {
            currentState.put(command, value);
            fireSourceChanged(ISources.WORKBENCH, command, value);
        }
    }
}

In my Login window, application checks user permissions, and enable or disable views, commands, etc. with setEnabled method of CommandState. For commands it works fine, they are enabling or disabling correctly (i disable them in some other way, but it works fine even if i disable them via activities, in the same way as i described). But when i try to disable view and open perspective, that contains that view (myproject.view.input), it opens without that view, but also throws exception:

!ENTRY org.eclipse.ui 4 4 2011-11-16 15:54:43.284
!MESSAGE Exception in org.eclipse.ui.internal.PageLayout.addView: org.eclipse.ui.PartInitException: Could not create view: myproject.view.input

!ENTRY org.eclipse.ui 4 4 2011-11-16 15:54:43.321
!MESSAGE Exception in org.eclipse.ui.internal.PageLayout.addView: org.eclipse.ui.PartInitException: Could not create view: myproject.view.input
!STACK 1
org.eclipse.ui.PartInitException: Could not create view: myproject.view.input
    at org.eclipse.ui.internal.ViewFactory.createView(ViewFactory.java:158)
    at org.eclipse.ui.internal.LayoutHelper.createView(LayoutHelper.java:162)
    at org.eclipse.ui.internal.PageLayout.createView(PageLayout.java:543)
    at org.eclipse.ui.internal.PageLayout.addView(PageLayout.java:416)
    at org.eclipse.ui.internal.PageLayout.addStandaloneView(PageLayout.java:894)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.processView(PerspectiveExtensionReader.java:295)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.processExtension(PerspectiveExtensionReader.java:118)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.readElement(PerspectiveExtensionReader.java:355)
    at org.eclipse.ui.internal.registry.RegistryReader.readElements(RegistryReader.java:144)
    at org.eclipse.ui.internal.registry.RegistryReader.readExtension(RegistryReader.java:155)
    at org.eclipse.ui.internal.registry.RegistryReader.readRegistry(RegistryReader.java:176)
    at org.eclipse.ui.internal.registry.PerspectiveExtensionReader.extendLayout(PerspectiveExtensionReader.java:82)
    at org.eclipse.ui.internal.Perspective.loadPredefinedPersp(Perspective.java:818)
    at org.eclipse.ui.internal.Perspective.createPresentation(Perspective.java:270)
    at org.eclipse.ui.internal.Perspective.<init>(Perspective.java:156)
    at org.eclipse.ui.internal.tweaklets.Workbench3xImplementation.createPerspective(Workbench3xImplementation.java:55)
    at org.eclipse.ui.internal.WorkbenchPage.createPerspective(WorkbenchPage.java:1672)
    at org.eclipse.ui.internal.WorkbenchPage.busySetPerspective(WorkbenchPage.java:1034)
    at org.eclipse.ui.internal.WorkbenchPage.access$16(WorkbenchPage.java:1025)
    at org.eclipse.ui.internal.WorkbenchPage$19.run(WorkbenchPage.java:3715)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.setPerspective(WorkbenchPage.java:3713)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.openPerspective(ShowPerspectiveHandler.java:146)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.openOther(ShowPerspectiveHandler.java:118)
    at org.eclipse.ui.handlers.ShowPerspectiveHandler.execute(ShowPerspectiveHandler.java:57)
    at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:293)
    at org.eclipse.core.commands.Command.executeWithChecks(Command.java:476)
    at org.eclipse.ui.internal.handlers.HandlerService.executeCommand(HandlerService.java:178)
    at org.eclipse.ui.internal.handlers.SlaveHandlerService.executeCommand(SlaveHandlerService.java:247)
    at org.eclipse.ui.actions.PerspectiveMenu.runOther(PerspectiveMenu.java:376)
    at org.eclipse.ui.actions.PerspectiveMenu$3.runWithEvent(PerspectiveMenu.java:130)
    at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
    at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
    at org.eclipse.jface.action.ActionContributionItem$5.handleEvent(ActionContributionItem.java:411)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1258)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3540)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3161)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2640)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2604)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2438)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:671)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:664)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at myproject.arm.demo.Application.start(Application.java:28)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:616)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:620)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:575)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1408)
    at org.eclipse.equinox.launcher.Main.main(Main.java:1384)
!SUBENTRY 1 org.eclipse.ui 4 0 2011-11-16 15:54:43.322
!MESSAGE Could not create view: myproject.view.input

I tried to debug my application and before i open my perspective whith that view, i checked currentState of my CommandState source provider, and all seemes to be ok: all variables values are correct and myproject.view.input.active = DISABLED

Can anyone say, why exception is thrown? Thanks for any help, or any ideas. Sorry for big post and bad language

*Edited: added full stacktrace

Upvotes: 2

Views: 1292

Answers (1)

Paul Webster
Paul Webster

Reputation: 10654

The system is working. An activity can make a view or wizard not visible to the user, but give them the option to deliberately show it.

An activity with an enabledWhen element removes the view from the view registry as well, so the user cannot deliberately show it, even if they wanted to. This is to prevent users from opening admin views in RCP apps.

You added the view to your perspective, and if your activity is disabled it's as if that view definition doesn't exist.

You should add that view as a view placeholder, or in an admin perspective. If the user logs in with an admin role, then you can show the view or select the admin perspective.

Upvotes: 3

Related Questions