/** * @see org.eclipse.core.commands.IStateListener#handleStateChange(org.eclipse.core.commands.State, * java.lang.Object) */ public void handleStateChange(State state, Object oldValue) { try { this.verboseBranchMode = ((Boolean) state.getValue()) .booleanValue(); } catch (Exception e) { Activator.logError(e.getMessage(), e); } }
@Override public void addListener(final IStateListener listener) { if (state == null) { addListenerObject(listener); } else { state.addListener(listener); } }
@Override public void removeListener(final IStateListener listener) { if (state == null) { removeListenerObject(listener); } else { state.removeListener(listener); } }
@Override public 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); } } } }
/** * Constructs a repositories view label provider */ public RepositoriesViewLabelProvider() { ICommandService srv = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); verboseBranchModeState = srv.getCommand(ToggleBranchCommitCommand.ID) .getState(ToggleBranchCommitCommand.TOGGLE_STATE); verboseBranchModeState.addListener(this); try { this.verboseBranchMode = ((Boolean) verboseBranchModeState .getValue()).booleanValue(); } catch (Exception e) { Activator.logError(e.getMessage(), e); } }
state = (State) configurationElement .createExecutableExtension(stateAttributeName); state.setId(getId()); configurationElement = null; state.addListener((IStateListener) element);
@Override public void setId(final String id) { super.setId(id); if (state != null) { state.setId(id); } }
@Override public void dispose() { if (state != null) { state.dispose(); if (state instanceof PersistentState) { final PersistentState persistableState = (PersistentState) state; if (persistableState.shouldPersist() && preferenceStore != null && preferenceKey != null) { persistableState.save(preferenceStore, preferenceKey); } } } }
/** * Adds a listener to changes for this state. * * @param listener * The listener to add; must not be <code>null</code>. */ public void addListener(final IStateListener listener) { addListenerObject(listener); }
/** * Sets the value for this state object. * * @param value * The value to set; may be anything. */ public void setValue(final Object value) { if (!Util.equals(this.value, value)) { final Object oldValue = this.value; this.value = value; fireStateChanged(oldValue); } } }
/** * Notifies listeners to this state that it has changed in some way. * * @param oldValue * The old value; may be anything. */ protected final void fireStateChanged(final Object oldValue) { final Object[] listeners = getListeners(); for (int i = 0; i < listeners.length; i++) { final IStateListener listener = (IStateListener) listeners[i]; listener.handleStateChange(this, oldValue); } }
@Override public void setDescription(final String text) { final State state = command.getCommand().getState( INamedHandleStateIds.DESCRIPTION); if (state instanceof TextState) { final String currentValue = (String) state.getValue(); if (!Objects.equals(text, currentValue)) { state.setValue(text); } } }
/** * Constructs this instance */ public RepositoriesViewContentProvider() { ICommandService srv = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); commandState = srv.getCommand( ToggleBranchHierarchyCommand.ID) .getState(ToggleBranchHierarchyCommand.TOGGLE_STATE); commandState.addListener(this); try { this.branchHierarchyMode = ((Boolean) commandState.getValue()) .booleanValue(); } catch (Exception e) { Activator.handleError(e.getMessage(), e, false); } }
/** * <p> * Adds a state to this command. This will add this state to the active * handler, if the active handler is an instance of {@link IObjectWithState}. * </p> * <p> * A single instance of {@link State} cannot be registered with multiple * commands. Each command requires its own unique instance. * </p> * * @param id * The identifier of the state to add; must not be * <code>null</code>. * @param state * The state to add; must not be <code>null</code>. * @since 3.2 */ @Override public void addState(final String id, final State state) { super.addState(id, state); state.setId(id); if (handler instanceof IObjectWithState) { ((IObjectWithState) handler).addState(id, state); } }
/** * Adds a listener to changes for this state. * * @param listener * The listener to add; must not be <code>null</code>. */ public void addListener(final IStateListener listener) { addListenerObject(listener); }
/** * Sets the value for this state object. * * @param value * The value to set; may be anything. */ public void setValue(final Object value) { if (!Util.equals(this.value, value)) { final Object oldValue = this.value; this.value = value; fireStateChanged(oldValue); } } }
/** * Notifies listeners to this state that it has changed in some way. * * @param oldValue * The old value; may be anything. */ protected final void fireStateChanged(final Object oldValue) { for (Object listener : getListeners()) { final IStateListener stateListener = (IStateListener) listener; stateListener.handleStateChange(this, oldValue); } }
@Override public Object getValue() { if (loadState()) { return state.getValue(); } return null; }