Example usage for org.eclipse.jface.action IAction CHECKED

List of usage examples for org.eclipse.jface.action IAction CHECKED

Introduction

In this page you can find the example usage for org.eclipse.jface.action IAction CHECKED.

Prototype

String CHECKED

To view the source code for org.eclipse.jface.action IAction CHECKED.

Click Source Link

Document

Property name of an action's checked status (value "checked").

Usage

From source file:com.arc.cdt.debug.seecode.ui.internal.display.DeferredButton.java

License:Open Source License

DeferredButton(int actionStyle) {
    mAction = new Action("", actionStyle) {
        @Override/* w  ww. j a va 2s  . com*/
        public void run() {
            notifyObservers();
        }

    };
    mAction.addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.CHECKED.equals(event.getProperty()))
                notifyObservers();

        }
    });
    mAction.setId("Button" + sItem++);
}

From source file:com.github.haixing_hu.swt.action.ActionContributionItemEx.java

License:Open Source License

/**
 * Synchronizes the UI with the given property.
 *
 * @param propertyName//from   www .  j ava2  s .  c o m
 *          the name of the property, or <code>null</code> meaning all
 *          applicable properties
 */
@Override
public void update(String propertyName) {
    if (widget != null) {
        // determine what to do
        final boolean textChanged = (propertyName == null) || propertyName.equals(IAction.TEXT);
        boolean imageChanged = (propertyName == null) || propertyName.equals(IAction.IMAGE);
        final boolean tooltipTextChanged = (propertyName == null) || propertyName.equals(IAction.TOOL_TIP_TEXT);
        final boolean enableStateChanged = (propertyName == null) || propertyName.equals(IAction.ENABLED)
                || propertyName.equals(IContributionManagerOverrides.P_ENABLED);
        final boolean checkChanged = ((action.getStyle() == IAction.AS_CHECK_BOX)
                || (action.getStyle() == IAction.AS_RADIO_BUTTON))
                && ((propertyName == null) || propertyName.equals(IAction.CHECKED));

        if (!showImage) {
            //  do not update the image if not show image
            imageChanged = false;
        }
        if (widget instanceof ToolItem) {
            final ToolItem ti = (ToolItem) widget;
            String text = action.getText();
            // the set text is shown only if there is no image or if forced
            // by MODE_FORCE_TEXT
            final boolean showText = (text != null)
                    && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action));

            // only do the trimming if the text will be used
            if (showText && (text != null)) {
                text = Action.removeAcceleratorText(text);
                text = Action.removeMnemonics(text);
            }

            if (textChanged) {
                final String textToSet = showText ? text : ""; //$NON-NLS-1$
                final boolean rightStyle = (ti.getParent().getStyle() & SWT.RIGHT) != 0;
                if (rightStyle || !ti.getText().equals(textToSet)) {
                    // In addition to being required to update the text if
                    // it
                    // gets nulled out in the action, this is also a
                    // workaround
                    // for bug 50151: Using SWT.RIGHT on a ToolBar leaves
                    // blank space
                    ti.setText(textToSet);
                }
            }

            if (imageChanged) {
                // only substitute a missing image if it has no text
                updateImages(!showText);
            }

            if (tooltipTextChanged || textChanged) {
                String toolTip = action.getToolTipText();
                if ((toolTip == null) || (toolTip.length() == 0)) {
                    toolTip = text;
                }

                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();
                final String commandId = action.getActionDefinitionId();
                if ((callback != null) && (commandId != null) && (toolTip != null)) {
                    final String acceleratorText = callback.getAcceleratorText(commandId);
                    if ((acceleratorText != null) && (acceleratorText.length() != 0)) {
                        toolTip = JFaceResources.format("Toolbar_Tooltip_Accelerator", //$NON-NLS-1$
                                new Object[] { toolTip, acceleratorText });
                    }
                }

                // if the text is showing, then only set the tooltip if
                // different
                if (!showText || ((toolTip != null) && !toolTip.equals(text))) {
                    ti.setToolTipText(toolTip);
                } else {
                    ti.setToolTipText(null);
                }
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (ti.getEnabled() != shouldBeEnabled) {
                    ti.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (ti.getSelection() != bv) {
                    ti.setSelection(bv);
                }
            }
            return;
        }

        if (widget instanceof MenuItem) {
            final MenuItem mi = (MenuItem) widget;

            if (textChanged) {
                int accelerator = 0;
                String acceleratorText = null;
                final ActionEx updatedAction = getAction();
                String text = null;
                accelerator = updatedAction.getAccelerator();
                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();

                // Block accelerators that are already in use.
                if ((accelerator != 0) && (callback != null) && (callback.isAcceleratorInUse(accelerator))) {
                    accelerator = 0;
                }

                /*
                 * Process accelerators on GTK in a special way to avoid Bug 42009. We
                 * will override the native input method by allowing these reserved
                 * accelerators to be placed on the menu. We will only do this for
                 * "Ctrl+Shift+[0-9A-FU]".
                 */
                final String commandId = updatedAction.getActionDefinitionId();
                if ((Util.isGtk()) && (callback instanceof IBindingManagerCallback) && (commandId != null)) {
                    final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;
                    final IKeyLookup lookup = KeyLookupFactory.getDefault();
                    final TriggerSequence[] triggerSequences = bindingManagerCallback
                            .getActiveBindingsFor(commandId);
                    for (final TriggerSequence triggerSequence : triggerSequences) {
                        final Trigger[] triggers = triggerSequence.getTriggers();
                        if (triggers.length == 1) {
                            final Trigger trigger = triggers[0];
                            if (trigger instanceof KeyStroke) {
                                final KeyStroke currentKeyStroke = (KeyStroke) trigger;
                                final int currentNaturalKey = currentKeyStroke.getNaturalKey();
                                if ((currentKeyStroke
                                        .getModifierKeys() == (lookup.getCtrl() | lookup.getShift()))
                                        && (((currentNaturalKey >= '0') && (currentNaturalKey <= '9'))
                                                || ((currentNaturalKey >= 'A') && (currentNaturalKey <= 'F'))
                                                || (currentNaturalKey == 'U'))) {
                                    accelerator = currentKeyStroke.getModifierKeys() | currentNaturalKey;
                                    acceleratorText = triggerSequence.format();
                                    break;
                                }
                            }
                        }
                    }
                }

                if (accelerator == 0) {
                    if ((callback != null) && (commandId != null)) {
                        acceleratorText = callback.getAcceleratorText(commandId);
                    }
                }

                IContributionManagerOverrides overrides = null;

                if (getParent() != null) {
                    overrides = getParent().getOverrides();
                }

                if (overrides != null) {
                    text = getParent().getOverrides().getText(this);
                }

                mi.setAccelerator(accelerator);

                if (text == null) {
                    text = updatedAction.getText();
                }

                if ((text != null) && (acceleratorText == null)) {
                    // use extracted accelerator text in case accelerator
                    // cannot be fully represented in one int (e.g.
                    // multi-stroke keys)
                    acceleratorText = LegacyActionTools.extractAcceleratorText(text);
                    if ((acceleratorText == null) && (accelerator != 0)) {
                        acceleratorText = Action.convertAccelerator(accelerator);
                    }
                }

                if (text == null) {
                    text = ""; //$NON-NLS-1$
                } else {
                    text = Action.removeAcceleratorText(text);
                }

                // add "..." if the action will show a dialog
                if (updatedAction.isShowDialog()) {
                    text = text + dialogIndicator;
                }

                if (acceleratorText == null) {
                    mi.setText(text);
                } else {
                    mi.setText(text + '\t' + acceleratorText);
                }
            }

            if (imageChanged) {
                updateImages(false);
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (mi.getEnabled() != shouldBeEnabled) {
                    mi.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (mi.getSelection() != bv) {
                    mi.setSelection(bv);
                }
            }

            return;
        }

        if (widget instanceof Button) {
            final Button button = (Button) widget;

            if (imageChanged) {
                updateImages(false);
            }

            if (textChanged) {
                String text = action.getText();
                final boolean showText = (text != null)
                        && (((getMode() & MODE_FORCE_TEXT) != 0) || !hasImages(action));
                // only do the trimming if the text will be used
                if (showText) {
                    text = Action.removeAcceleratorText(text);
                }
                final String textToSet = showText ? text : ""; //$NON-NLS-1$
                button.setText(textToSet);
            }

            if (tooltipTextChanged) {
                button.setToolTipText(action.getToolTipText());
            }

            if (enableStateChanged) {
                final boolean shouldBeEnabled = action.isEnabled() && isEnabledAllowed();

                if (button.getEnabled() != shouldBeEnabled) {
                    button.setEnabled(shouldBeEnabled);
                }
            }

            if (checkChanged) {
                final boolean bv = action.isChecked();

                if (button.getSelection() != bv) {
                    button.setSelection(bv);
                }
            }
            return;
        }
    }
}

From source file:fr.inria.linuxtools.tmf.ui.views.callstack.CallStackView.java

License:Open Source License

private void contributeToActionBars() {
    IActionBars bars = getViewSite().getActionBars();
    fillLocalToolBar(bars.getToolBarManager());

    // Create pin action
    contributePinActionToToolBar();/*from  ww w .  jav a 2 s.c  o  m*/
    fPinAction.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.CHECKED.equals(event.getProperty()) && !isPinned()) {
                if (fSavedRangeSyncSignal != null) {
                    synchToRange(fSavedRangeSyncSignal);
                    fSavedRangeSyncSignal = null;
                }

                if (fSavedTimeSyncSignal != null) {
                    synchToTime(fSavedTimeSyncSignal);
                    fSavedTimeSyncSignal = null;
                }
            }
        }
    });
}

From source file:org.eclipse.e4.tools.properties.PropertySheet.java

License:Open Source License

/**
  * The <code>PropertySheet</code> implementation of this <code>IWorkbenchPart</code>
  * method creates a <code>PageBook</code> control with its default page showing.
  *//*  w  ww .ja va  2s.  c  o m*/
public void createPartControl(Composite parent) {
    super.createPartControl(parent);

    pinPropertySheetAction.addPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.CHECKED.equals(event.getProperty())) {
                updateContentDescription();
            }
        }
    });
    IMenuManager menuManager = getViewSite().getActionBars().getMenuManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    menuManager.add(pinPropertySheetAction);

    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    toolBarManager.add(pinPropertySheetAction);

    getSite().getPage().getWorkbenchWindow().getWorkbench().getHelpSystem().setHelp(getPageBook(),
            IPropertiesHelpContextIds.PROPERTY_SHEET_VIEW);
}

From source file:org.eclipse.gmf.internal.bridge.ui.dashboard.DashboardPart.java

License:Open Source License

public void init(IViewSite site, IMemento memento) throws PartInitException {
    super.init(site, memento);
    if (memento != null) {
        dashboardInitialProjectName = memento.getString(ACTIVE_PROJECT_KEY);
        String syncSelectionValue = memento.getString(SYNC_SELECTION_KEY);
        if (syncSelectionValue != null) {
            syncSelection = Boolean.valueOf(syncSelectionValue).booleanValue();
        }// w  w w  .ja v  a2 s.  c  om
    }
    IAction syncSelectionAction = new Action(Messages.DashboardPart_Synchronize, IAction.AS_CHECK_BOX) {
    };
    syncSelectionAction.setToolTipText(Messages.DashboardPart_SynchronizeSelection);
    ImageDescriptor synchImage = Plugin.getDefault().getImageRegistry().getDescriptor(Plugin.SYNC_ICON);
    if (synchImage != null) {
        syncSelectionAction.setImageDescriptor(synchImage);
    }
    syncSelectionAction.setChecked(syncSelection);
    syncSelectionAction.addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.CHECKED.equals(event.getProperty())) {
                syncSelection = ((Boolean) event.getNewValue()).booleanValue();
                if (syncSelection && mediator != null && activeProject != mediator.getProject()) {
                    updateDashboardProject(activeProject);
                }
            }
        }
    });
    site.getActionBars().getToolBarManager().add(syncSelectionAction);
}

From source file:org.eclipse.rcptt.ui.panels.Actions.java

License:Open Source License

public static final IObservableValue observeChecked(IAction action) {
    return JFaceProperties.value(IAction.class, "checked", IAction.CHECKED) //$NON-NLS-1$
            .observe(action);/*from   w  w w.  j  av a 2s  . c  o  m*/
}

From source file:org.eclipse.riena.e4.launcher.part.MenuHelper.java

License:Open Source License

private static IContextFunction createToggleFunction(final IConfigurationElement element) {
    final Object ice = element.getParent();
    if (!(ice instanceof IConfigurationElement)) {
        return null;
    }/*www  .j av  a  2  s  .  c  o  m*/

    // identify the type of contribution that this is
    final IConfigurationElement parent = (IConfigurationElement) ice;
    final int type = getType(parent.getName());
    if (type == -1) {
        // unknown, don't create a toggling function
        return null;
    }

    final IContextFunction generator = new ContextFunction() {
        private ActionDescriptor getDescriptor(final IEclipseContext context) {
            switch (type) {
            case ActionDescriptor.T_WORKBENCH:
                final IWorkbenchWindow window = context.get(IWorkbenchWindow.class);
                return window == null ? null : new ActionDescriptor(element, type, window);
            case ActionDescriptor.T_EDITOR:
                return new ActionDescriptor(element, type, null);
            case ActionDescriptor.T_VIEW:
                final MPart part = context.get(MPart.class);
                if (part != null) {
                    final Object object = part.getObject();
                    if (object instanceof CompatibilityPart) {
                        return new ActionDescriptor(element, type, ((CompatibilityPart) object).getPart());
                    }
                }
                return null;
            default:
                return null;
            }
        }

        @Override
        public Object compute(final IEclipseContext context, final String contextKey) {
            final MHandledItem model = context.get(MHandledItem.class);
            if (model == null) {
                return null;
            }
            final ActionDescriptor desc = getDescriptor(context);
            final IAction action = desc.getAction();
            final IPropertyChangeListener propListener = new IPropertyChangeListener() {
                public void propertyChange(final PropertyChangeEvent event) {
                    if (IAction.CHECKED.equals(event.getProperty())) {
                        boolean checked = false;
                        if (event.getNewValue() instanceof Boolean) {
                            checked = ((Boolean) event.getNewValue()).booleanValue();
                        }
                        model.setSelected(checked);
                    }
                }
            };
            action.addPropertyChangeListener(propListener);
            final Runnable obj = new Runnable() {
                @Execute
                public void run() {
                    action.removePropertyChangeListener(propListener);
                }
            };
            model.setSelected(action.isChecked());
            return obj;
        }
    };
    return generator;
}

From source file:org.eclipse.riena.e4.launcher.part.MenuHelper.java

License:Open Source License

public static MToolItem createToolItem(final MApplication application, final ActionContributionItem item) {
    final IAction action = item.getAction();
    final String id = action.getActionDefinitionId();
    if (id != null) {
        for (final MCommand command : application.getCommands()) {
            if (id.equals(command.getElementId())) {
                final MHandledToolItem toolItem = MenuFactoryImpl.eINSTANCE.createHandledToolItem();
                toolItem.setCommand(command);
                toolItem.setContributorURI(command.getContributorURI());

                String iconURI = getIconURI(action.getImageDescriptor(), application.getContext());
                if (iconURI == null) {
                    iconURI = getIconURI(id, application.getContext(), ICommandImageService.TYPE_DEFAULT);
                    if (iconURI == null) {
                        toolItem.setLabel(command.getCommandName());
                    } else {
                        toolItem.setIconURI(iconURI);
                    }//from  www  .  j  a v  a 2  s . co m
                } else {
                    toolItem.setIconURI(iconURI);
                }
                if (action.getToolTipText() != null) {
                    toolItem.setTooltip(action.getToolTipText());
                }

                String disabledIconURI = getIconURI(action.getDisabledImageDescriptor(),
                        application.getContext());
                if (disabledIconURI == null) {
                    disabledIconURI = getIconURI(id, application.getContext(),
                            ICommandImageService.TYPE_DEFAULT);
                }
                if (disabledIconURI != null) {
                    setDisabledIconURI(toolItem, disabledIconURI);
                }

                switch (action.getStyle()) {
                case IAction.AS_CHECK_BOX:
                    toolItem.setType(ItemType.CHECK);
                    toolItem.setSelected(action.isChecked());
                    break;
                case IAction.AS_RADIO_BUTTON:
                    toolItem.setType(ItemType.RADIO);
                    toolItem.setSelected(action.isChecked());
                    break;
                default:
                    toolItem.setType(ItemType.PUSH);
                    break;
                }
                final String itemId = item.getId();
                toolItem.setElementId(itemId == null ? id : itemId);

                return toolItem;
            }
        }
    } else {
        final MDirectToolItem toolItem = MenuFactoryImpl.eINSTANCE.createDirectToolItem();
        final String itemId = item.getId();
        toolItem.setElementId(itemId);
        String iconURI = getIconURI(action.getImageDescriptor(), application.getContext());
        if (iconURI == null) {
            if (itemId == null) {
                if (action.getText() != null) {
                    toolItem.setLabel(action.getText());
                }
            } else {
                iconURI = getIconURI(itemId, application.getContext(), ICommandImageService.TYPE_DEFAULT);
                if (iconURI == null) {
                    if (action.getText() != null) {
                        toolItem.setLabel(action.getText());
                    }
                } else {
                    toolItem.setIconURI(iconURI);
                }
            }
        } else {
            toolItem.setIconURI(iconURI);
        }
        if (action.getToolTipText() != null) {
            toolItem.setTooltip(action.getToolTipText());
        }

        switch (action.getStyle()) {
        case IAction.AS_CHECK_BOX:
            toolItem.setType(ItemType.CHECK);
            toolItem.setSelected(action.isChecked());
            break;
        case IAction.AS_RADIO_BUTTON:
            toolItem.setType(ItemType.RADIO);
            toolItem.setSelected(action.isChecked());
            break;
        default:
            toolItem.setType(ItemType.PUSH);
            break;
        }
        toolItem.setContributionURI("bundleclass://org.eclipse.ui.workbench/programmic.contribution"); //$NON-NLS-1$
        toolItem.setObject(new DirectProxy(action));
        toolItem.setEnabled(action.isEnabled());

        final IPropertyChangeListener propertyListener = new IPropertyChangeListener() {
            public void propertyChange(final PropertyChangeEvent event) {
                final String property = event.getProperty();
                if (property.equals(IAction.ENABLED)) {
                    toolItem.setEnabled(action.isEnabled());
                } else if (property.equals(IAction.CHECKED)) {
                    toolItem.setSelected(action.isChecked());
                } else if (property.equals(IAction.TEXT)) {
                    toolItem.setLabel(action.getText());
                } else if (property.equals(IAction.TOOL_TIP_TEXT)) {
                    toolItem.setLabel(action.getToolTipText());
                }
            }
        };
        // property listener is removed in
        // DirectContributionItem#handleWidgetDispose()
        action.addPropertyChangeListener(propertyListener);
        toolItem.getTransientData().put(DirectContributionItem.DISPOSABLE, new Runnable() {
            public void run() {
                action.removePropertyChangeListener(propertyListener);
            }
        });
        return toolItem;
    }
    return null;
}

From source file:org.eclipse.team.internal.ccvs.ui.actions.CVSAction.java

License:Open Source License

/**
 * Initializes a retarget action that will listen to part changes and allow parts to
 * override this action's behavior. The retarget action is used if this
 * action is shown in a top-level menu or toolbar.
 * @param window the workbench window showing this action
 * @since 3.1/*from   w  w w  .j  ava2  s.  c o  m*/
 */
private void initializeRetargetAction(IWorkbenchWindow window) {
    // Don't need to specify a the title because it will use this actions
    // title instead.
    retargetAction = new RetargetAction(getId(), ""); //$NON-NLS-1$
    retargetAction.addPropertyChangeListener(new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(IAction.ENABLED)) {
                Object val = event.getNewValue();
                if (val instanceof Boolean && action != null) {
                    action.setEnabled(((Boolean) val).booleanValue());
                }
            } else if (event.getProperty().equals(IAction.CHECKED)) {
                Object val = event.getNewValue();
                if (val instanceof Boolean && action != null) {
                    action.setChecked(((Boolean) val).booleanValue());
                }
            } else if (event.getProperty().equals(IAction.TEXT)) {
                Object val = event.getNewValue();
                if (val instanceof String && action != null) {
                    action.setText((String) val);
                }
            } else if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                Object val = event.getNewValue();
                if (val instanceof String && action != null) {
                    action.setToolTipText((String) val);
                }
            } else if (event.getProperty().equals(SubActionBars.P_ACTION_HANDLERS)) {
                if (action != null && retargetAction != null) {
                    action.setEnabled(retargetAction.isEnabled());
                }
            }
        }
    });
    window.getPartService().addPartListener(retargetAction);
    IWorkbenchPart activePart = window.getPartService().getActivePart();
    if (activePart != null)
        retargetAction.partActivated(activePart);
}

From source file:org.eclipse.tracecompass.extension.internal.callstack.ui.views.callstack.CallStackView.java

License:Open Source License

private void contributeToActionBars() {
    // Create pin action
    contributePinActionToToolBar();//from   w w  w .j av a  2 s  .  co  m
    fPinAction.addPropertyChangeListener(new IPropertyChangeListener() {
        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.CHECKED.equals(event.getProperty()) && !isPinned()) {
                if (fSavedRangeSyncSignal != null) {
                    windowRangeUpdated(fSavedRangeSyncSignal);
                    fSavedRangeSyncSignal = null;
                }

                if (fSavedTimeSyncSignal != null) {
                    selectionRangeUpdated(fSavedTimeSyncSignal);
                    fSavedTimeSyncSignal = null;
                }
            }
        }
    });
}