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

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

Introduction

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

Prototype

void addPropertyChangeListener(IPropertyChangeListener listener);

Source Link

Document

Adds a property change listener to this action.

Usage

From source file:com.diffplug.common.swt.jface.JFaceRx.java

License:Apache License

/**
 * Returns an `RxBox<Boolean>` for the toggle state of the given action as an RxBox.
 * <p>/*from  www  .  j a v a2 s .c  o  m*/
 * Applicable to IAction.AS_CHECK_BOX and AS_RADIO_BUTTON.
 */
public static @SwtThread RxBox<Boolean> toggle(IAction action) {
    Preconditions.checkArgument(SwtMisc.flagIsSet(IAction.AS_CHECK_BOX, action.getStyle())
            || SwtMisc.flagIsSet(IAction.AS_RADIO_BUTTON, action.getStyle()));
    RxBox<Boolean> box = RxBox.of(action.isChecked());
    action.addPropertyChangeListener(e -> {
        if ("checked".equals(e.getProperty())) {
            box.set((Boolean) e.getNewValue());
        }
    });
    Rx.subscribe(box, isChecked -> {
        action.setChecked(isChecked);
    });
    return box;
}

From source file:com.microsoft.tfs.client.common.ui.framework.action.ToolbarPulldownAction.java

License:Open Source License

/**
 * Adds a new sub-action to this {@link ToolbarPulldownAction}. The
 * sub-action will be shown in the pull-down menu that is displayed for this
 * item. If this is the first sub-action being added, it will become the
 * default sub-action. You can manually set the default sub-action be
 * calling {@link #setDefaultSubAction(IAction)}.
 *
 * @param subAction//from w  w  w . ja v  a  2 s  . c o  m
 *        a new sub-action to add (must not be <code>null</code>)
 */
public void addSubAction(final IAction subAction) {
    Check.notNull(subAction, "subAction"); //$NON-NLS-1$

    subActions.add(subAction);
    subAction.addPropertyChangeListener(subActionPropertyChangeListener);
    recomputeEnablement();

    disposeSubActionMenu();
}

From source file:com.nokia.tools.media.utils.tooltip.TitlebarComposite.java

License:Open Source License

public void addTitleAction(final IAction action, EActionLocation location) {
    final Canvas canvas = new Canvas(titlebar, SWT.NONE);
    switch (location) {
    case BEGINNING:
        canvas.moveAbove(null);//  w ww.j av  a2 s . c o m
        break;
    case END:
        canvas.moveBelow(null);
        break;
    case ABOVE_TITLE:
        canvas.moveAbove(title);
        break;
    case BELOV_TITLE:
    default:
        canvas.moveBelow(title);
        break;
    }

    ((GridLayout) titlebar.getLayout()).numColumns++;

    if (resourcesToDispose == null) {
        resourcesToDispose = new ArrayList<Resource>();
    }

    final CanvasListener canvasListener = new CanvasListener(action, canvas);

    final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent event) {
            if (IAction.IMAGE == event.getProperty()) {
                ImageDescriptor imgDesc = action.getImageDescriptor();
                ImageDescriptor hoverImgDesc = action.getHoverImageDescriptor();
                ImageDescriptor disabledImgDesc = action.getDisabledImageDescriptor();

                canvasListener.setImg(imgDesc);
                canvasListener.setHoverImg(hoverImgDesc);
                canvasListener.setDisabledImg(disabledImgDesc);
            }

            if (IAction.TEXT == event.getProperty() || IAction.TOOL_TIP_TEXT == event.getProperty()) {
                if (action.getToolTipText() != null) {
                    canvas.setToolTipText(action.getToolTipText());
                } else if (action.getText() != null) {
                    canvas.setToolTipText(action.getText());
                }
            }

            canvas.redraw();
            canvas.update();
        }
    };

    action.addPropertyChangeListener(propertyChangeListener);

    canvas.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            action.removePropertyChangeListener(propertyChangeListener);
        }
    });

    propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.IMAGE, null, null));
    propertyChangeListener.propertyChange(new PropertyChangeEvent(this, IAction.TEXT, null, null));

    Rectangle bounds = canvasListener.img.getBounds();

    GridData gd = new GridData(bounds.width, bounds.height);
    canvas.setLayoutData(gd);

    canvas.addListener(SWT.Paint, canvasListener);
    canvas.addListener(SWT.MouseEnter, canvasListener);
    canvas.addListener(SWT.MouseExit, canvasListener);
    canvas.addListener(SWT.MouseUp, canvasListener);
}

From source file:de.ovgu.featureide.ui.views.collaboration.outline.Outline.java

License:Open Source License

/**
 * @param toolBarManager/*  w w  w  .  j  av  a 2s.  c  om*/
 */
private void fillLocalToolBar(IToolBarManager manager) {
    dropDownAction.setMenuCreator(new IMenuCreator() {
        Menu fMenu = null;

        @Override
        public Menu getMenu(Menu parent) {
            return null;
        }

        @Override
        public Menu getMenu(Control parent) {
            fMenu = new Menu(parent);

            for (IAction curAction : actionOfProv) {
                curAction.addPropertyChangeListener(Outline.this);
                if (curAction instanceof ProviderAction && ((ProviderAction) curAction).getLabelProvider()
                        .getOutlineType() == selectedOutlineType) {
                    ActionContributionItem item = new ActionContributionItem(curAction);

                    item.fill(fMenu, -1);
                }
            }
            return fMenu;
        }

        @Override
        public void dispose() {
            if (fMenu != null) {
                fMenu.dispose();
            }
        }
    });
    manager.add(dropDownAction);
}

From source file:fable.framework.toolbox.CheckableActionGroup.java

License:Open Source License

public void add(IAction action) {
    if (action.getStyle() != IAction.AS_CHECK_BOX)
        throw new RuntimeException("Only check actions are supported!");
    action.addPropertyChangeListener(this);
    actions.add(action);/*from  www .j ava  2s . c o  m*/
}

From source file:fable.framework.toolbox.MenuAction.java

License:Open Source License

public void add(final IAction action) {
    actions.add(action);
    action.addPropertyChangeListener(this);
}

From source file:net.refractions.udig.project.ui.internal.tool.display.ToolManager.java

License:Open Source License

/**
 * Creates a action that acts as a proxy for the tool in the editor toolbar.
 * <p>//from  w  w  w. j  ava  2 s. co m
 * The client code must set the name image descriptor etc... of the Action
 * </p>
 * 
 * @param toolID the id of the tool
 * @param categoryID the category the tool is part of
 * @return a proxy action that can be put in other toolbars
 */
public IAction createToolAction(final String toolID, final String categoryID) {
    final IAction toolAction = new Action() {
        @Override
        public void runWithEvent(Event event) {
            IAction action = getTool(toolID, categoryID);
            if (action != null && action.isEnabled()) {
                action.runWithEvent(event);
            }
        }
    };
    toolAction.addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getProperty().equals(IAction.ENABLED)) {
                toolAction.setEnabled((Boolean) event.getNewValue());
            }
        }

    });
    toolAction.setEnabled(getTool(toolID, categoryID).isEnabled());
    addToolAction(toolAction);
    return toolAction;
}

From source file:org.apache.sling.ide.eclipse.ui.internal.ServersActionModeFiddlerActionDelegate.java

License:Apache License

@Override
public void selectionChanged(IAction action, ISelection selection) {
    server = null;/*from  ww  w .  j  a  v a  2  s .  co m*/
    modules = null;
    if (selection != null && (selection instanceof IStructuredSelection)) {
        IStructuredSelection iss = (IStructuredSelection) selection;
        Object first = iss.getFirstElement();
        if (first instanceof IServer) {
            server = (IServer) first;
            modules = null;
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServer
                Iterator<?> it = iss.iterator();
                it.next(); // skip the first, we have that above already
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServer)) {
                        server = null;
                        modules = null;
                        break;
                    }
                }
            }
        } else if (first instanceof IServerModule) {
            modules = new LinkedList<>();
            IServerModule module = (IServerModule) first;
            modules.add(module.getModule());
            server = module.getServer();
            if (iss.size() > 1) {
                // verify that all selected elements are of type IServerModule
                // plus add the module[] to the modules list
                Iterator<?> it = iss.iterator();
                it.next(); // skip the first, we have that above already
                while (it.hasNext()) {
                    Object next = it.next();
                    if (!(next instanceof IServerModule)) {
                        server = null;
                        module = null;
                        break;
                    } else {
                        module = (IServerModule) next;
                        modules.add(module.getModule());
                    }
                }
            }
        }
    }

    if (server != null) {
        if (server.getServerState() != IServer.STATE_STARTED) {
            server = null;
            modules = null;
        }
    }
    cleanAction.setEnabled(server != null);
    publishAction.setEnabled(server != null);

    action.setEnabled(true);
    final IAction serverRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.run");
    final IAction serverDebugAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.debug");
    IAction stopRunAction = actionBars.getGlobalActionHandler("org.eclipse.wst.server.stop");
    if (serverRunAction == null || stopRunAction == null || serverDebugAction == null) {
        return;
    }
    //      serverRunAction.setHoverImageDescriptor(SharedImages.SLING_LOG);
    serverRunAction.setHoverImageDescriptor(SharedImages.RUN_CONNECT);
    serverDebugAction.setHoverImageDescriptor(SharedImages.DEBUG_CONNECT);
    stopRunAction.setHoverImageDescriptor(SharedImages.DISCONNECT);

    findWstPublishAction();

    for (ActionContributionItem appendedAction : appendedToolbarActionContributionItems) {
        if (!contributionAdded(appendedAction)) {
            actionBars.getToolBarManager().add(appendedAction);
        }
    }
    if (wstPublishAction != null) {
        wstPublishAction.setVisible(false);
        publishActionContributionItem.setVisible(true);
    } else {
        // otherwise hide it, as it is an unexpected situation
        publishActionContributionItem.setVisible(false);
    }

    final String runText = "Connect to server in run mode";
    if (runTooltipListener == null) {
        runTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(runText)) {
                        serverRunAction.setToolTipText(runText);
                    }
                }
            }
        };
        serverRunAction.addPropertyChangeListener(runTooltipListener);
    }
    final String debugText = "Connect to server in debug mode";
    if (debugTooltipListener == null) {
        debugTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(debugText)) {
                        serverDebugAction.setToolTipText(debugText);
                    }
                }
            }
        };
        serverDebugAction.addPropertyChangeListener(debugTooltipListener);
    }
    final String disconnectText = "Disconnect from server";
    if (disconnectTooltipListener == null) {
        disconnectTooltipListener = new IPropertyChangeListener() {

            @Override
            public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(IAction.TOOL_TIP_TEXT)) {
                    if (!event.getNewValue().equals(disconnectText)) {
                        serverRunAction.setToolTipText(disconnectText);
                    }
                }
            }
        };
        stopRunAction.addPropertyChangeListener(disconnectTooltipListener);
    }

    serverRunAction.setToolTipText(runText);
    serverDebugAction.setToolTipText(debugText);
    stopRunAction.setToolTipText(disconnectText);

}

From source file:org.dawb.common.ui.menu.CheckableActionGroup.java

License:Open Source License

public void add(IAction action) {
    action.addPropertyChangeListener(this);
    actions.add(action);
}

From source file:org.eclipse.birt.report.designer.internal.ui.swt.custom.TabbedPropertyTitle.java

License:Open Source License

public void setActions(IAction[] actions) {
    if (actions != null) {
        if (toolbar != null) {
            while (toolbar.getItemCount() > 0) {
                ToolItem item = toolbar.getItem(0);
                IAction action = (IAction) actionMap.get(item);
                if (action != null)
                    action.removePropertyChangeListener(this);
                item.dispose();//from   w  w w.  j  ava2s.  c o  m
            }
            actionMap.clear();
            toolbar.dispose();
        }

        toolbar = new ToolBar(label, SWT.FLAT);
        toolbar.setBackground(gbg);
        GridData gd = new GridData();
        gd.grabExcessHorizontalSpace = true;
        gd.horizontalAlignment = SWT.END;
        gd.grabExcessVerticalSpace = true;
        gd.verticalAlignment = SWT.CENTER;
        toolbar.setLayoutData(gd);

        for (int i = 0; i < actions.length; i++) {
            IAction action = actions[i];
            int flags = SWT.PUSH;
            if (action != null) {
                int style = action.getStyle();
                if (style == IAction.AS_CHECK_BOX) {
                    flags = SWT.CHECK;
                } else if (style == IAction.AS_RADIO_BUTTON) {
                    flags = SWT.RADIO;
                } else if (style == IAction.AS_DROP_DOWN_MENU) {
                    flags = SWT.DROP_DOWN;
                }
            }
            ToolItem item = new ToolItem(toolbar, flags);
            item.addListener(SWT.Selection, getToolItemListener());
            action.addPropertyChangeListener(this);
            actionMap.put(item, action);
        }
        updateToolBar();
        label.layout();
    } else {
        if (toolbar != null) {
            toolbar.dispose();
            toolbar = null;
        }
    }
}