org.eclipse.core.commands.State Java Examples

The following examples show how to use org.eclipse.core.commands.State. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PCalTranslateAutomaticallyHandler.java    From tlaplus with MIT License 6 votes vote down vote up
@Inject
public void initializeAtStartup(final IWorkbench workbench, final ICommandService commandService) {
	/*
	 * Check the UI state of the IHandler/Command which indicates if the user
	 * enabled automatic PlusCal conversion.
	 */
	final Command command = commandService.getCommand("toolbox.command.module.translate.automatially");
	final State state = command.getState(RegistryToggleState.STATE_ID);
	if (!((Boolean) state.getValue()).booleanValue()) {
		return;
	}
	// This IHander is stateful even across Toolbox restarts. In other words, if the
	// user enables automatic PlusCal translation, it will remain enabled even after
	// a Toolbox restart. This means we have to register this EventHandler at the
	// IEventBroker during Toolbox startup.
	// It is vital that we use the Workbench's IEventBroker instance. If e.g. we
	// would use an IEventBroker from higher up the IEclipseContext hierarchy, the
	// broker would be disposed when a new spec gets opened while the IHandler's state
	// remains enabled.
	workbench.getService(IEventBroker.class).unsubscribe(this);
	Assert.isTrue(workbench.getService(IEventBroker.class).subscribe(TLAEditor.PRE_SAVE_EVENT, this));
}
 
Example #2
Source File: CommandsPropertyTester.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean test(final Object receiver, final String property,
		final Object[] args, final Object expectedValue) {
	if (receiver instanceof IServiceLocator && args.length == 1
			&& args[0] instanceof String) {
		final IServiceLocator locator = (IServiceLocator) receiver;
		if (TOGGLE_PROPERTY_NAME.equals(property)) {
			final String commandId = args[0].toString();
			final ICommandService commandService = (ICommandService) locator
					.getService(ICommandService.class);
			final Command command = commandService.getCommand(commandId);
			final State state = command
					.getState(RegistryToggleState.STATE_ID);
			if (state != null) {
				return state.getValue().equals(expectedValue);
			}
		}
	}
	return false;
}
 
Example #3
Source File: CommandsPropertyTester.java    From tmxeditor8 with GNU General Public License v2.0 6 votes vote down vote up
public boolean test(final Object receiver, final String property,
		final Object[] args, final Object expectedValue) {
	if (receiver instanceof IServiceLocator && args.length == 1
			&& args[0] instanceof String) {
		final IServiceLocator locator = (IServiceLocator) receiver;
		if (TOGGLE_PROPERTY_NAME.equals(property)) {
			final String commandId = args[0].toString();
			final ICommandService commandService = (ICommandService) locator
					.getService(ICommandService.class);
			final Command command = commandService.getCommand(commandId);
			final State state = command
					.getState(RegistryToggleState.STATE_ID);
			if (state != null) {
				return state.getValue().equals(expectedValue);
			}
		}
	}
	return false;
}
 
Example #4
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void setCommandState(boolean state)
{
	ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	Command command = service.getCommand(COMMAND_ID);
	State commandState = command.getState(COMMAND_STATE);
	if (((Boolean) commandState.getValue()) != state)
	{
		commandState.setValue(state);
		service.refreshElements(COMMAND_ID, null);
	}
}
 
Example #5
Source File: ToggleWordWrapHandler.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setEnabled(Object evaluationContext)
{
	Object activeSite = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_SITE_NAME);
	Object activeEditor = ((IEvaluationContext) evaluationContext).getVariable(ISources.ACTIVE_EDITOR_NAME);
	if (activeSite instanceof IWorkbenchSite && activeEditor instanceof AbstractThemeableEditor)
	{
		ICommandService commandService = (ICommandService) ((IWorkbenchSite) activeSite)
				.getService(ICommandService.class);
		Command command = commandService.getCommand(COMMAND_ID);
		State state = command.getState(RegistryToggleState.STATE_ID);
		state.setValue(((AbstractThemeableEditor) activeEditor).getWordWrapEnabled());
	}
}
 
Example #6
Source File: SelectNextOccurrenceHandler.java    From eclipse-multicursor with Eclipse Public License 1.0 5 votes vote down vote up
private SelectInProgress getCurrentState() {
	State state = getState(ID_SELECTS_IN_PROGRESS);
	if (state == null) {
		return null;
	} else {
		return (SelectInProgress) state.getValue();
	}
}
 
Example #7
Source File: MedicationViewHelper.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public static ViewerSortOrder getSelectedComparator(){
	ICommandService service =
		(ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
	Command command = service.getCommand(ApplyCustomSortingHandler.CMD_ID);
	State state = command.getState(ApplyCustomSortingHandler.STATE_ID);
	
	if ((Boolean) state.getValue()) {
		return ViewerSortOrder.getSortOrderPerValue(ViewerSortOrder.MANUAL.val);
	} else {
		return ViewerSortOrder.getSortOrderPerValue(ViewerSortOrder.DEFAULT.val);
	}
}
 
Example #8
Source File: PrintTakingsListHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
public SorterAdapter(ExecutionEvent event){
	ICommandService commandService = (ICommandService) HandlerUtil.getActiveSite(event)
		.getService(ICommandService.class);
	if (commandService != null) {
		Command command = commandService.getCommand(ApplyCustomSortingHandler.CMD_ID);
		State state = command.getState(ApplyCustomSortingHandler.STATE_ID);
		if (state.getValue() instanceof Boolean) {
			if ((Boolean) state.getValue()) {
				mode = SorterAdapter.CompareMode.MANUAL;
			}
		}
	}
}
 
Example #9
Source File: SelectNextOccurrenceHandler.java    From eclipse-multicursor with Eclipse Public License 1.0 4 votes vote down vote up
private void saveCurrentState(SelectInProgress selectInProgress) {
	State state = new State();
	state.setValue(selectInProgress);
	state.setId(ID_SELECTS_IN_PROGRESS);
	addState(ID_SELECTS_IN_PROGRESS, state);
}
 
Example #10
Source File: SelectNextOccurrenceHandler.java    From eclipse-multicursor with Eclipse Public License 1.0 4 votes vote down vote up
@Override
	public void handleStateChange(State state, Object oldValue) {
//		logger.debug("State changed; new value=" + state.getId() + ":" + state.getValue() + " and old value="
//				+ oldValue);
	}