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

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

Introduction

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

Prototype

ImageDescriptor getImageDescriptor();

Source Link

Document

Returns the image for this action as an image descriptor.

Usage

From source file:ch.elexis.core.ui.laboratory.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void init(final Shell shell) {
    List<IAction> orderActions = Extensions.getClasses(
            Extensions.getExtensions(ExtensionPointConstantsUi.LABORORDER), "ToolbarAction", //$NON-NLS-1$ //$NON-NLS-2$
            false);//from  w w  w  .  java2s  .  c  o m
    for (IAction action : orderActions) {
        if (action.getId() != null && action.getImageDescriptor() != null && action.getText() != null) {
            this.actions.add(action);
        } else {
            log.log(MessageFormat.format("Missing #id, #imagedescriptor or #text for LaborOrder action: {0}",
                    action.getText()), Log.WARNINGS);
        }
    }
    if (this.actions != null && this.actions.size() > 0) {
        String selectedId = CoreHub.localCfg.get(LAB_ORDER_SELECTED_ACTION_ID, null);
        if (selectedId != null) {
            for (IAction action : this.actions) {
                if (selectedId.equals(action.getId())) {
                    this.selectedAction = action;
                }
            }
        }
        if (this.selectedAction == null) {
            this.selectedAction = this.actions.get(0);
        }
    }
}

From source file:ch.elexis.core.ui.laboratory.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@Override
public Menu getMenu(final Control parent) {
    if (this.menu == null) {
        this.menu = new Menu(parent);
        for (final IAction action : this.actions) {
            final MenuItem menuItem = new MenuItem(this.menu, SWT.PUSH);
            final Image image = action.getImageDescriptor().createImage();
            menuItem.setImage(image);/*  ww w  . j  a va  2  s  .c o  m*/
            menuItem.setText(action.getText());

            // Add listeners
            menuItem.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    select(parent, action, image);
                    action.run();
                }
            });
        }

    }

    return this.menu;
}

From source file:ch.elexis.views.LaborOrderPulldownMenuCreator.java

License:Open Source License

@SuppressWarnings("unchecked")
private void init(final Shell shell) {
    List<IAction> orderActions = Extensions.getClasses(Extensions.getExtensions("ch.elexis.LaborOrder"), //$NON-NLS-1$
            "ToolbarAction", //$NON-NLS-1$
            false);//  www .  j  a  v  a2 s  .  c o  m
    for (IAction action : orderActions) {
        if (action.getId() != null && action.getImageDescriptor() != null && action.getText() != null) {
            this.actions.add(action);
        } else {
            log.log(MessageFormat.format("Missing #id, #imagedescriptor or #text for LaborOrder action: {0}",
                    action.getText()), Log.WARNINGS);
        }
    }
    if (this.actions != null && this.actions.size() > 0) {
        String selectedId = Hub.localCfg.get(LAB_ORDER_SELECTED_ACTION_ID, null);
        if (selectedId != null) {
            for (IAction action : this.actions) {
                if (selectedId.equals(action.getId())) {
                    this.selectedAction = action;
                }
            }
        }
        if (this.selectedAction == null) {
            this.selectedAction = this.actions.get(0);
        }
    }
}

From source file:com.atlassian.connector.eclipse.internal.crucible.ui.editor.parts.ExpandablePart.java

License:Open Source License

protected ImageHyperlink createActionHyperlink(Composite actionsComposite, FormToolkit toolkit,
        final IAction action) {

    if (action instanceof IReviewAction) {
        ((IReviewAction) action).setActionListener(actionListener);
    }/*from   w  w  w  .j  a  v a 2  s  .  c o m*/
    ImageHyperlink link = toolkit.createImageHyperlink(actionsComposite, SWT.NONE);
    if (action.getImageDescriptor() != null) {
        link.setImage(CommonImages.getImage(action.getImageDescriptor()));
    } else {
        link.setText(action.getText());
    }
    link.setToolTipText(action.getToolTipText());
    link.addHyperlinkListener(new HyperlinkAdapter() {
        @Override
        public void linkActivated(HyperlinkEvent e) {
            action.run();
        }
    });
    return link;
}

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

License:Apache License

private Actions(IAction action) {
    this.text = action.getText();
    this.style = Style.of(action);
    if (action instanceof ActionImp) {
        callback = ((ActionImp) action).callback;
    } else {/*from  www.  j  av a2s  .  c om*/
        callback = (a, e) -> {
            if (e == null) {
                action.run();
            } else {
                action.runWithEvent(e);
            }
        };
    }
    this.img = action.getImageDescriptor();
    this.accelerator = action.getAccelerator();
    this.tooltip = action.getToolTipText();

    if (accelerator != SWT.NONE) {
        // the toolTip might have had an accelerator added,
        // which we'll want to strip so it doesn't get doubled
        String hint = getAcceleratorHint(accelerator);
        if (tooltip.endsWith(hint)) {
            tooltip = tooltip.substring(0, tooltip.length() - hint.length());
        }
    }
}

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

License:Open Source License

/**
 * Returns whether the given action has any images.
 *
 * @param actionToCheck/*  www.j  ava 2s. c  o  m*/
 *          the action
 * @return <code>true</code> if the action has any images, <code>false</code>
 *         if not
 */
private boolean hasImages(IAction actionToCheck) {
    return (actionToCheck.getImageDescriptor() != null) || (actionToCheck.getHoverImageDescriptor() != null)
            || (actionToCheck.getDisabledImageDescriptor() != null);
}

From source file:com.google.gdt.eclipse.designer.uibinder.model.util.EventsHandlersSupportTest.java

License:Open Source License

public void test_contextMenu() throws Exception {
    createTestClass("// filler filler filler filler filler", "// filler filler filler filler filler",
            "  @UiField Button button;", "  @UiHandler('button')", "  void onButtonClick(ClickEvent event) {",
            "  }");
    parse("// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>",
            "  <g:FlowPanel>", "    <g:Button wbp:name='button' ui:field='button'/>", "  </g:FlowPanel>",
            "</ui:UiBinder>");
    refresh();// w w  w.  j  ava2  s . co m
    WidgetInfo button = getObjectByName("button");
    //
    IMenuManager contextMenu = getContextMenu(button);
    // check action for existing "onClick" event
    {
        IAction action = findChildAction(contextMenu, "onClick -> onButtonClick");
        assertNotNull(action);
        assertSame(EventsPropertyUtils.LISTENER_METHOD_IMAGE_DESCRIPTOR, action.getImageDescriptor());
        // run, no change expected
        String expectedSource = getJavaSourceToAssert();
        action.run();
        assertEquals(expectedSource, getJavaSourceToAssert());
    }
    // add new method using action
    {
        IMenuManager manager2 = findChildMenuManager(contextMenu, "Add event handler");
        IAction action = findChildAction(manager2, "onFocus");
        assertNotNull(action);
        // run, new method should be added
        action.run();
        waitEventLoop(0);
        DesignerPlugin.getActiveEditor().doSave(null);
        assertJava(decorateTestClassLines("// filler filler filler filler filler",
                "// filler filler filler filler filler", "  @UiField Button button;", "  @UiHandler('button')",
                "  void onButtonClick(ClickEvent event) {", "  }", "  @UiHandler('button')",
                "  void onButtonFocus(FocusEvent event) {", "  }"));
    }
}

From source file:com.google.gdt.eclipse.designer.uibinder.model.widgets.GridTest.java

License:Open Source License

/**
 * Test for {@link Cell} context menu./*from   ww w  .jav a2  s  .com*/
 */
public void test_contextMenu_insertCell() throws Exception {
    parse("// filler filler filler filler filler", "<ui:UiBinder>", "  <g:Grid>", "    <g:row>",
            "      <g:cell wbp:name='cell'/>", "    </g:row>", "  </g:Grid>", "</ui:UiBinder>");
    Cell cell = getObjectByName("cell");
    //
    IMenuManager contextMenu = getContextMenu(cell);
    IAction action = findChildAction(contextMenu, "Insert cell");
    assertNotNull(action);
    assertNotNull(action.getImageDescriptor());
    action.run();
    assertXML("// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>",
            "  <g:Grid>", "    <g:row>", "      <g:cell>New cell</g:cell>", "      <g:cell wbp:name='cell'/>",
            "    </g:row>", "  </g:Grid>", "</ui:UiBinder>");
}

From source file:com.google.gdt.eclipse.designer.uibinder.model.widgets.GridTest.java

License:Open Source License

/**
 * Test for {@link Cell} context menu.//from   w w w.ja v a 2s.c om
 */
public void test_contextMenu_appendCell() throws Exception {
    parse("// filler filler filler filler filler", "<ui:UiBinder>", "  <g:Grid>", "    <g:row>",
            "      <g:cell wbp:name='cell'/>", "    </g:row>", "  </g:Grid>", "</ui:UiBinder>");
    Cell cell = getObjectByName("cell");
    //
    IMenuManager contextMenu = getContextMenu(cell);
    IAction action = findChildAction(contextMenu, "Append cell");
    assertNotNull(action);
    assertNotNull(action.getImageDescriptor());
    action.run();
    assertXML("// filler filler filler filler filler", "// filler filler filler filler filler", "<ui:UiBinder>",
            "  <g:Grid>", "    <g:row>", "      <g:cell wbp:name='cell'/>", "      <g:cell>New cell</g:cell>",
            "    </g:row>", "  </g:Grid>", "</ui:UiBinder>");
}

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 w  w.  ja  v  a  2 s.  com
        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);
}