예제 #1
0
  /**
   * Updates the radio state of the command to the given value
   *
   * @param command the command whose state should be updated
   * @param newState the new state
   * @throws ExecutionException When the command doesn't have a radio state
   * @since 3.5
   */
  public static void updateRadioState(Command command, String newState) throws ExecutionException {

    State state = command.getState(RadioState.STATE_ID);
    if (state == null)
      throw new ExecutionException("The command does not have a radio state"); // $NON-NLS-1$
    state.setValue(newState);
  }
  @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);
    }
  }
예제 #3
0
 public final void setText(final String text) {
   final State state = command.getCommand().getState(INamedHandleStateIds.NAME);
   if (state instanceof TextState) {
     final String currentValue = (String) state.getValue();
     if (!Util.equals(text, currentValue)) {
       state.setValue(text);
     }
   }
 }
예제 #4
0
  public final boolean isChecked() {
    final State state = command.getCommand().getState(IMenuStateIds.STYLE);
    if (state instanceof ToggleState) {
      final Boolean currentValue = (Boolean) state.getValue();
      return currentValue.booleanValue();
    }

    return false;
  }
예제 #5
0
  public static boolean isShowPlanNames() {
    ICommandService commandService =
        (ICommandService)
            PlatformUI.getWorkbench().getActiveWorkbenchWindow().getService(ICommandService.class);

    Command command = commandService.getCommand("at.ac.tuwien.ieg.asbruedit.show-planname-toggle");

    State state = command.getState("org.eclipse.ui.commands.toggleState");

    boolean isToggled = (Boolean) state.getValue();
    return isToggled;
  }
예제 #6
0
  /**
   * Toggles the command's state.
   *
   * @param command The command whose state needs to be toggled
   * @return the original value before toggling
   * @throws ExecutionException When the command doesn't contain the toggle state or when the state
   *     doesn't contain a boolean value
   * @since 3.5
   */
  public static boolean toggleCommandState(Command command) 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();
    state.setValue(Boolean.valueOf(!oldValue));
    return oldValue;
  }
예제 #7
0
 public final void setChecked(final boolean checked) {
   final State state = command.getCommand().getState(IMenuStateIds.STYLE);
   if (state instanceof ToggleState) {
     final Boolean currentValue = (Boolean) state.getValue();
     if (checked != currentValue.booleanValue()) {
       if (checked) {
         state.setValue(Boolean.TRUE);
       } else {
         state.setValue(Boolean.FALSE);
       }
     }
   }
 }
예제 #8
0
  /**
   * Checks whether the radio state of the command is same as the radio state parameter's value
   *
   * @param event The execution event that contains the application context
   * @return <code>true</code> whe the values are same, <code>false</code> otherwise
   * @throws ExecutionException When the command doesn't have the radio state or the event doesn't
   *     have the radio state parameter
   * @since 3.5
   */
  public static boolean matchesRadioState(ExecutionEvent event) throws ExecutionException {

    String parameter = event.getParameter(RadioState.PARAMETER_ID);
    if (parameter == null)
      throw new ExecutionException(
          "The event does not have the radio state parameter"); //$NON-NLS-1$

    Command command = event.getCommand();
    State state = command.getState(RadioState.STATE_ID);
    if (state == null)
      throw new ExecutionException("The command does not have a radio state"); // $NON-NLS-1$
    if (!(state.getValue() instanceof String))
      throw new ExecutionException(
          "The command's radio state doesn't contain a String value"); //$NON-NLS-1$

    return parameter.equals(state.getValue());
  }