Java 类org.eclipse.ui.handlers.RegistryToggleState 实例源码

项目: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;
}
项目: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);
    }
}
项目:smaccm    文件:PropertiesViewPart.java   
@Override
public void createPartControl(final Composite parent) {
    view.createView(parent);

    final ICommandService commandService = (ICommandService)getSite().getService(ICommandService.class);
    final Command command = commandService.getCommand(UIConstants.TOGGLE_SHOW_ONLY_ERRORS_AND_WARNINGS_COMMAND_ID);
    setShowOnlyErrorsAndWarnings((Boolean)command.getState(RegistryToggleState.STATE_ID).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
    }
项目: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();
        }
    }