RCP applicatoon activities

Posted by Peter on Stack Overflow See other posts from Stack Overflow or by Peter
Published on 2011-11-16T09:42:40Z Indexed on 2011/11/16 9:51 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

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. But when i try to disable view and open perspective, that contains that view (myproject.view.input), it opened without that view, but also throws exception:

!STACK 1
org.eclipse.ui.PartInitException: Could not create view: myproject.view.input
    at org.eclipse.ui.internal.ViewFactory.createView(ViewFactory.java:158)

I can show full stacktrace if anyone want.

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. Sorry for big post and bad language

© Stack Overflow or respective owner

Related posts about java

Related posts about eclipse