Java 类org.eclipse.core.commands.State 实例源码

项目:mytourbook    文件:ActionHandlerPhotoFilter.java   
@Override
public void setEnabled(final Object evaluationContext) {

    super.setEnabled(evaluationContext);

    if (_isAppPhotoFilterInitialized == false) {

        _isAppPhotoFilterInitialized = true;

        /*
         * initialize app photo filter, this is a hack because the whole app startup should be
         * sometimes be streamlined, it's more and more confusing
         */
        final Command command = ((ICommandService) PlatformUI//
                .getWorkbench()
                .getService(ICommandService.class))//
                .getCommand(ActionHandlerPhotoFilter.COMMAND_ID);

        final State state = command.getState(RegistryToggleState.STATE_ID);
        final Boolean isPhotoFilterActive = (Boolean) state.getValue();

        TourbookPlugin.setActivePhotoFilter(isPhotoFilterActive);
    }
}
项目:translationstudio8    文件:CommandsPropertyTester.java   
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;
}
项目:tmxeditor8    文件:CommandsPropertyTester.java   
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;
}
项目:DynamicSpotter    文件:ExpertViewHandler.java   
@SuppressWarnings("rawtypes")
@Override
public void updateElement(UIElement element, Map parameters) {
    Activator activator = Activator.getDefault();
    if (activator.getSelectedProjects().size() == 1) {
        IProject project = activator.getSelectedProjects().iterator().next();
        String projectName = project.getName();

        boolean enabled = SpotterProjectSupport.isExpertViewEnabled(projectName);
        State state = getCommandState(null);
        state.setValue(Boolean.valueOf(enabled));

        String label = (enabled ? "Disable" : "Enable") + " Expert View";
        element.setText(label);
    }
}
项目:DynamicSpotter    文件:ExpertViewHandler.java   
/**
 * Retrieves the toggle state of the command.
 * 
 * @param expertViewCommand
 *            the command or <code>null</code> to manually try to lookup the
 *            command
 * 
 * @return the toggle state of the command
 */
private State getCommandState(Command expertViewCommand) {
    Command command = expertViewCommand;

    if (command == null && commandService != null) {
        command = commandService.getCommand(EXPERT_VIEW_COMMAND_ID);
    }

    if (command == null) {
        throw new RuntimeException("Unable to retrieve command " + EXPERT_VIEW_COMMAND_ID);
    }

    State state = command.getState(TOGGLE_STATE_ID);

    if (state == null) {
        throw new RuntimeException("Unable to retrieve state " + TOGGLE_STATE_ID + " from command "
                + EXPERT_VIEW_COMMAND_ID);
    }

    return state;
}
项目:elexis-3-base    文件:InputHandler.java   
private void toggleButtonOff(){
    ICommandService commandService =
        (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command toggleCommand = commandService.getCommand(COMMAND_ID);

    State state = toggleCommand.getState("STYLE");
    boolean currentState = (Boolean) state.getValue();
    if (currentState) {
        // turn it off
        state.setValue(!currentState);
        UiDesk.getDisplay().syncExec(new Runnable() {

            public void run(){
                commandService.refreshElements(toggleCommand.getId(), null);
            }
        });
    }
}
项目:elexis-3-base    文件:ToggleHandler.java   
public final Object execute(ExecutionEvent event) throws ExecutionException {
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);

    // update toggled state
    State state = event.getCommand().getState(IMenuStateIds.STYLE);
    if (state == null)
        throw new ExecutionException(
                "You need to declare a ToggleState with id=STYLE for your command to use ToggleHandler!");
    boolean currentState = (Boolean) state.getValue();
    boolean newState = !currentState;
    state.setValue(newState);

    // trigger element update
    executeToggle(event, newState);
    commandService.refreshElements(event.getCommand().getId(), null);

    // return value is reserved for future apis
    return null;
}
项目:elexis-3-base    文件:ToggleHandler.java   
public final Object execute(ExecutionEvent event) throws ExecutionException {
    ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    this.commandId = event.getCommand().getId();

    // update toggled state
    State state = event.getCommand().getState(IMenuStateIds.STYLE);
    if (state == null)
        throw new ExecutionException(
                "You need to declare a ToggleState with id=STYLE for your command to use ToggleHandler!");
    boolean currentState = (Boolean) state.getValue();
    boolean newState = !currentState;
    state.setValue(newState);

    // trigger element update
    executeToggle(event, newState);
    commandService.refreshElements(event.getCommand().getId(), null);

    // return value is reserved for future apis
    return null;
}
项目:elexis-3-base    文件:ServerControl.java   
@Override
public void updateElement(final UIElement element, Map parameters){
    ICommandService commandService =
        (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = commandService.getCommand(ID);
    final State state = command.getState(IMenuStateIds.STYLE);
    if (state != null) {
        PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
            @Override
            public void run(){
                element.setChecked((Boolean) state.getValue());
            }
        });

    }

}
项目:d-case_editor    文件:DcaseLayoutProvider.java   
/**
 * {@inheritDoc}
 */
@Override
protected DirectedGraphLayout createGraphLayout() {

    // gets target command menu.
    ICommandService commandService =
            (ICommandService) PlatformUI.getWorkbench()
                .getService(ICommandService.class);
    Command radioCommand = commandService.getCommand(CONST_ARRANGE_ANGLE_COMMAND);

    // gets current arrange direction state.
    State state = radioCommand.getState(CONST_RADIO_COMMAND_STATE);
    String currentState = state.getValue().toString();

    // sets command state to angle instance.
    if (currentState.equals(CONST_HORIZONTAL_VALUE)) {
        ArrangeAngle.createInstance().setAngle(ArrangeAngle.Direction.Horizontal);
    } else {
        ArrangeAngle.createInstance().setAngle(ArrangeAngle.Direction.Vertical);
    }

    return new DcaseDirectedGraphLayout();
}
项目:yamcs-studio    文件:SwitchProcessorHandler.java   
@Override
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters) {
    ICommandService service = (ICommandService) element.getServiceLocator().getService(ICommandService.class);
    String state = (String) parameters.get(RadioState.PARAMETER_ID);
    Command command = service.getCommand(SwitchProcessorCompoundContributionItem.SWITCH_PROCESSOR_COMMAND);
    State commandState = command.getState(RadioState.STATE_ID);
    if (commandState.getValue().equals(state)) {
        element.setChecked(true);
    }
}
项目:SPELL    文件:CommandHelper.java   
public static void setToggleCommandState(String commandId, String stateId, boolean stateValue) throws ExecutionException
{
    ICommandService svc = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = svc.getCommand(commandId);
    State state = command.getState("org.eclipse.ui.commands.toggleState");
    if (state == null)
        throw new ExecutionException("The command does not have a toggle state"); //$NON-NLS-1$
    if (!(state.getValue() instanceof Boolean))
        throw new ExecutionException("The command's toggle state doesn't contain a boolean value"); //$NON-NLS-1$
    state.setValue(new Boolean(stateValue));
}
项目:APICloud-Studio    文件:CommonEditorPlugin.java   
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);
    }
}
项目:APICloud-Studio    文件:ToggleWordWrapHandler.java   
@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());
    }
}
项目:OpenSPIFe    文件:AbstractPlanEditorHandler.java   
protected void selectionChanged(ISelection selection) {
    boolean enabled = isEnabledForSelection(selection);
    setBaseEnabled(enabled);
    Command command = getCommand();
    State state = command.getState(RegistryToggleState.STATE_ID);
    if (state != null) {
        boolean checked = isCheckedForSelection(selection);
        try {
            setCommandState(command, checked);
        } catch (ExecutionException e) {
            LogUtil.error(e);
        }
    }
}
项目:OpenSPIFe    文件:AbstractPlanEditorHandler.java   
protected static boolean getCommandState(Command command) {
    State toggleState = command.getState(RegistryToggleState.STATE_ID);
    if (toggleState != null) {
        Object value = toggleState.getValue();
        if (CommonUtils.equals(Boolean.TRUE, value)) {
            return true;
        }
    }
    return false;
}
项目:OpenSPIFe    文件:AbstractPlanEditorHandler.java   
protected static void setCommandState(Command command, boolean newValue) throws ExecutionException {
    State state = command.getState(RegistryToggleState.STATE_ID);
    if(state == null)
        throw new ExecutionException("The command does not have a toggle state"); //$NON-NLS-1$
     if(!(state.getValue() instanceof Boolean))
        throw new ExecutionException("The command's toggle state doesn't contain a boolean value"); //$NON-NLS-1$
    boolean oldValue = ((Boolean) state.getValue()).booleanValue();
    if (oldValue != newValue) {
        HandlerUtil.toggleCommandState(command);
    }
}
项目:gef-gwt    文件:RadioState.java   
public final void handleStateChange(final State state,
        final Object oldValue) {
    final Object newValue = state.getValue();
    if (newValue instanceof Boolean) {
        if (((Boolean) newValue).booleanValue()) {
            activateMember((RadioState) state);
        }
    }
}
项目:DynamicSpotter    文件:ExpertViewHandler.java   
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Activator activator = Activator.getDefault();
    IStructuredSelection sel = (IStructuredSelection) activator.getNavigatorViewer().getSelection();
    ISpotterProjectElement projectElement = null;
    if (!sel.isEmpty()) {
        projectElement = (ISpotterProjectElement) sel.getFirstElement();
    }

    if (projectElement == null || activator.getSelectedProjects().size() != 1) {
        return null;
    }

    Command command = event.getCommand();
    State state = getCommandState(command);

    boolean oldValue = (boolean) state.getValue();
    String projectName = projectElement.getProject().getName();

    // prompt confirmation only if trying to enable
    boolean confirm = oldValue || DialogUtils.openConfirm(MSG_CONFIRM_ENABLE);

    if (confirm && SpotterProjectSupport.setExpertModeEnabled(projectName, !oldValue)) {
        HandlerUtil.toggleCommandState(command);

        SpotterUtils.refreshProjectParent(projectElement);
    }

    return null;
}
项目:eclipse-multicursor    文件:SelectNextOccurrenceHandler.java   
private SelectInProgress getCurrentState() {
    State state = getState(ID_SELECTS_IN_PROGRESS);
    if (state == null) {
        return null;
    } else {
        return (SelectInProgress) state.getValue();
    }
}
项目:elexis-3-core    文件:MedicationViewHelper.java   
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);
    }
}
项目:elexis-3-core    文件:PrintTakingsListHandler.java   
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;
            }
        }
    }
}
项目:elexis-3-base    文件:ToggleHandler.java   
/**
 * Update command element with toggle state
 */
public void updateElement(UIElement element, @SuppressWarnings("rawtypes") Map parameters){
    ICommandService commandService =
        (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = commandService.getCommand(COMMAND_ID);
    State state = command.getState(IMenuStateIds.STYLE);
    if (state != null)
        element.setChecked((Boolean) state.getValue());

}
项目:elexis-3-base    文件:ToggleHandler.java   
/**
 * Update command element with toggle state
 */
public void updateElement(UIElement element, Map parameters) {
    if (this.commandId != null) {
        ICommandService commandService = (ICommandService) PlatformUI.getWorkbench().getService(
                ICommandService.class);
        Command command = commandService.getCommand(commandId);
        State state = command.getState(IMenuStateIds.STYLE);
        if (state != null)
            element.setChecked((Boolean) state.getValue());
    }
}
项目:yamcs-studio    文件:EventLogView.java   
private void updateState() {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = service.getCommand(EventLog.CMD_SCROLL_LOCK);
    State state = command.getState(EventLog.STATE_SCROLL_LOCK);
    enableScrollLock((Boolean) state.getValue());
}
项目:mytourbook    文件:ActionHandlerSyncPhotoWithTour.java   
@Override
    public void setEnabled(final Object evaluationContext) {

        super.setEnabled(evaluationContext);

        if (_isInitializedState && _isInitializedView) {
            return;
        }

        final IWorkbench wb = PlatformUI.getWorkbench();

        if (_isInitializedState == false) {

            /**
             * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             * <p>
             * getting the state works only the first time, otherwise it returns the OLD state
             * <p>
             * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
             */

            final Command command = ((ICommandService) wb.getService(ICommandService.class)).getCommand(COMMAND_ID);

            final State state = command.getState(RegistryToggleState.STATE_ID);

            _isSyncPhotoWithTour = (Boolean) state.getValue();

            _isInitializedState = true;
        }

        /*
         * get PicDirView
         */
        PicDirView picDirView = null;

        for (final IWorkbenchWindow wbWindow : wb.getWorkbenchWindows()) {

            final IWorkbenchPage wbPage = wbWindow.getActivePage();

            if (wbPage != null) {

                for (final IViewReference viewRef : wbPage.getViewReferences()) {
                    if (viewRef.getId().equals(PicDirView.ID)) {
                        final IViewPart viewPart = viewRef.getView(false);
                        if (viewPart instanceof PicDirView) {
                            picDirView = (PicDirView) viewPart;
                            break;
                        }
                    }
                }
            }
        }

        if (picDirView != null) {

            _isInitializedView = true;

            picDirView.setSelectionConverter(_isSyncPhotoWithTour ? _syncSelectionProvider : null);
        }

//      System.out.println(UI.timeStampNano() + " _isSyncPhotoWithTour " + _isSyncPhotoWithTour);
//      // TODO remove SYSTEM.OUT.PRINTLN
    }
项目:OpenSPIFe    文件:ZoomSweepTool.java   
public void changeButtonState(Boolean value) {
    ICommandService service = (ICommandService) PlatformUI.getWorkbench().getService(ICommandService.class);
    Command command = service.getCommand(ZoomSweepToolHandler.COMMAND_ID);
    State state = command.getState(ZoomSweepToolHandler.ZOOM_SWEEP_TOOGLE_STATE);
    state.setValue(value);
}
项目:eclipse-multicursor    文件:SelectNextOccurrenceHandler.java   
private void saveCurrentState(SelectInProgress selectInProgress) {
    State state = new State();
    state.setValue(selectInProgress);
    state.setId(ID_SELECTS_IN_PROGRESS);
    addState(ID_SELECTS_IN_PROGRESS, state);
}
项目:eclipse-multicursor    文件:SelectNextOccurrenceHandler.java   
@Override
    public void handleStateChange(State state, Object oldValue) {
//      logger.debug("State changed; new value=" + state.getId() + ":" + state.getValue() + " and old value="
//              + oldValue);
    }
项目:mytourbook    文件:TourPhotoLinkView.java   
private void onSelectionChanged(final ISelection selection, final IWorkbenchPart part) {

//      System.out.println(UI.timeStampNano() + " onSelectionChanged\t" + selection);
//      // TODO remove SYSTEM.OUT.PRINTLN

        if (selection instanceof SyncSelection) {

            final ISelection originalSelection = ((SyncSelection) selection).getSelection();

            if (originalSelection instanceof PhotoSelection) {
                showPhotosAndTours(((PhotoSelection) originalSelection).galleryPhotos);
            }

        } else if (selection instanceof PhotoSelection && part instanceof PicDirView) {

            /**
             * accept photo selection ONLY from the pic dir view, otherwise other photo selections
             * will cause a view update
             */

            final PhotoSelection photoSelection = (PhotoSelection) selection;

            final Command command = _commandService.getCommand(ActionHandlerSyncPhotoWithTour.COMMAND_ID);
            final State state = command.getState(RegistryToggleState.STATE_ID);
            final boolean isSync = (Boolean) state.getValue();

            if (isSync) {
                showPhotosAndTours(photoSelection.galleryPhotos);
            }

        } else if (selection instanceof SelectionDeletedTours) {

            clearView();

            _photoMgr.resetTourStartEnd();
        }
    }