Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Plugin Development Environment (PDE) » INamedHandleStateIds.NAME does not work
INamedHandleStateIds.NAME does not work [message #1768453] Tue, 18 July 2017 23:47
Chris So is currently offline Chris SoFriend
Messages: 3
Registered: October 2016
Junior Member
Hi at all,

I try to make a drop-down toolbar item, where the root command name should be updated when an item in the drop-down is clicked. I found INamedHandleStateIds.NAME that should handle this change when added to the command, but it does not change the name of the command. Also, TEXT and NAME as state name do not work. I searched for nearly 5 days now but does not found any solution for this case.


My code looks like this at the moment:
plugin.xml
<command
            defaultHandler="org.test.SelectContextHandler"
            description="Select Context"
            id="org.test.command.context"
            name="Default Context">
         <state
               class="org.eclipse.jface.menus.TextState"
               id="TEXT">
         </state>
      </command>


In the dynamic menu contribution, I add entries with:
final CommandContributionItemParameter contributionParameter = new CommandContributionItemParameter(
							mServiceLocator, SelectContextHandler.ID, SelectContextHandler.ID, CommandContributionItem.STYLE_CHECK);
					contributionParameter.visibleEnabled = true;
					contributionParameter.parameters = params;
					contributionParameter.label = expression.name;

					items.add(new CommandContributionItem(contributionParameter));


The SelectContextHandler:
public class SelectContextHandler extends AbstractHandlerWithState  {

	public static final String ID = "org.test.command.context";

	@Override
	public void handleStateChange(State state, Object oldValue) {
	}

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
//		this.addState(INamedHandleStateIds.NAME, new TextState());
		for (String s : this.getStateIds()) {
			System.out.println(s);
		}
		State count = getState(IMenuStateIds.NAME);
		if (count == null) {
			count = event.getCommand().getState(IMenuStateIds.NAME);
		}
		if (count == null) {
			this.addState(IMenuStateIds.NAME, new TextState());
			count = getState(IMenuStateIds.NAME);
		}
		String val = (String) count.getValue();
		if (val == null || val.length()==0) {
			val = "0";
		}
		String rc = increment(val);
		count.setValue(rc);
		System.out.println("New count: " + rc);
		return null;
	}

	private String increment(String val) {
		int i = Integer.parseInt(val);
		return "" + (i+1);
	}
}


A stack is given, but I don't understand if it's my fault or a bug.
org.eclipse.e4.core.di.InjectionException: java.lang.NullPointerException
	at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:65)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:305)
	at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:239)
	at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:132)
	at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:152)
	at org.eclipse.core.commands.Command.executeWithChecks(Command.java:494)
	at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:487)
	at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:210)
	at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:431)
	at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.handleWidgetSelection(AbstractContributionItem.java:446)
	at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.lambda$2(AbstractContributionItem.java:472)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:86)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4428)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1079)
	at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4238)
	at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3817)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1155)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1044)
	at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:153)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:680)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:336)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:594)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:148)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:151)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:134)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:388)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:243)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.lang.reflect.Method.invoke(Unknown Source)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:653)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:590)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1499)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1472)


Does anyone know whether this is a bug or there exists another way to do this?

Thanks in advance :)

[Updated on: Wed, 19 July 2017 00:10]

Report message to a moderator

Previous Topic:Defer Plugin Loading on Eclipse Startup
Next Topic:How to create projection support with contributor class MultiPageEditorContributor
Goto Forum:
  


Current Time: Thu Mar 28 11:09:35 GMT 2024

Powered by FUDForum. Page generated in 0.05897 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top