Example usage for org.eclipse.jface.resource JFaceResources getImage

List of usage examples for org.eclipse.jface.resource JFaceResources getImage

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getImage.

Prototype

public static Image getImage(String key) 

Source Link

Document

Returns the image in JFace's image registry with the given key, or null if none.

Usage

From source file:org.eclipse.edt.ide.ui.internal.property.pages.VariableBlock.java

License:Open Source License

private void updateDeprecationWarning() {
    if (fWarning == null || fWarning.isDisposed())
        return;//from   w  w  w.j a  va 2s.  c  o m

    for (Iterator iter = fSelectedElements.iterator(); iter.hasNext();) {
        CPVariableElement element = (CPVariableElement) iter.next();
        String deprecationMessage = element.getDeprecationMessage();
        if (deprecationMessage != null) {
            fWarning.setText(deprecationMessage);
            fWarning.setImage(JFaceResources.getImage(Dialog.DLG_IMG_MESSAGE_WARNING));
            return;
        }
    }
    fWarning.setText(null);
    fWarning.setImage(null);
}

From source file:org.eclipse.emf.ecoretools.design.properties.BindingViewHelper.java

License:Open Source License

/**
 * {@inheritDoc}//from   ww  w .  ja  v  a 2  s.  c o m
 * @see org.eclipse.emf.eef.runtime.ui.parts.ViewHelper#createHelpButton(org.eclipse.swt.widgets.Composite, java.lang.Object)
 */
@SuppressWarnings("unused")
public Control createHelpButton(Composite parent, Object feature) {
    //To manage in future
    String helpID = null;
    String alternate = context.getPropertiesEditingComponent().getHelpContent(feature, toolkit == null ? 0 : 1);
    Image image = JFaceResources.getImage(DLG_IMG_HELP);
    if (helpID != null && !EMPTY_STRING.equals(helpID)) { //$NON-NLS-1$
        ToolBar result = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
        ((GridLayout) parent.getLayout()).numColumns++;
        result.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
        ToolItem item = new ToolItem(result, SWT.NONE);
        item.setImage(image);
        if (alternate != null && !EMPTY_STRING.equals(alternate)) //$NON-NLS-1$
            item.setToolTipText(alternate);
        return result;
    } else {
        Label result = null;
        if (toolkit != null) {
            result = toolkit.createLabel(parent, EMPTY_STRING); //$NON-NLS-1$
        } else {
            result = new Label(parent, SWT.NONE);
        }
        if (alternate != null && !EMPTY_STRING.equals(alternate)) { //$NON-NLS-1$
            result.setImage(image);
            result.setToolTipText(alternate);
        }
        return result;
    }
}

From source file:org.eclipse.emf.eef.runtime.ui.widgets.FormUtils.java

License:Open Source License

/**
 * Creates a button with a help image and put the defined tooltip in parameter.
 * //from w w w .  ja  v  a  2  s .c om
 * @param parent
 *            the parent composite
 * @param the
 *            message to use for tooltip
 */
public static Control createHelpButton(FormToolkit widgetFactory, Composite parent, String helpMessage,
        String helpID) {
    Image image = JFaceResources.getImage(DLG_IMG_HELP);
    if (helpID != null && !"".equals(helpID)) { //$NON-NLS-1$
        ToolBar result = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
        ((GridLayout) parent.getLayout()).numColumns++;
        result.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
        ToolItem item = new ToolItem(result, SWT.NONE);
        item.setImage(image);
        if (helpMessage != null && !"".equals(helpMessage)) //$NON-NLS-1$
            item.setToolTipText(helpMessage);
        return result;
    } else {
        Label result = widgetFactory.createLabel(parent, ""); //$NON-NLS-1$
        if (helpMessage != null && !"".equals(helpMessage)) { //$NON-NLS-1$
            result.setImage(image);
            result.setToolTipText(helpMessage);
        }
        return result;
    }
}

From source file:org.eclipse.emf.eef.runtime.ui.widgets.SWTUtils.java

License:Open Source License

/**
 * Creates a button with a help image and put the defined tooltip in parameter.
 * //from ww  w  . j  av a2  s.c o m
 * @param parent
 *            the parent composite
 * @param the
 *            message to use for tooltip
 */
public static Control createHelpButton(final Composite parent, String helpMessage, String helpID) {
    Image image = JFaceResources.getImage(DLG_IMG_HELP);
    if (helpID != null && !"".equals(helpID)) { //$NON-NLS-1$
        ToolBar result = new ToolBar(parent, SWT.FLAT | SWT.NO_FOCUS);
        ((GridLayout) parent.getLayout()).numColumns++;
        result.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
        ToolItem item = new ToolItem(result, SWT.NONE);
        item.setImage(image);
        if (helpMessage != null && !"".equals(helpMessage)) //$NON-NLS-1$
            item.setToolTipText(helpMessage);
        return result;
    } else {
        CLabel result = new CLabel(parent, SWT.NONE);
        if (helpMessage != null && !"".equals(helpMessage)) { //$NON-NLS-1$
            result.setImage(image);
            result.setToolTipText(helpMessage);
        }
        return result;
    }
}

From source file:org.eclipse.fx.ide.ui.mobile.sim.launch.MainTab.java

License:Open Source License

@Override
public Image getImage() {
    return JFaceResources.getImage("SimTabImage");
}

From source file:org.eclipse.fx.ide.ui.preview.LivePreviewPart.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NONE);
    container.setLayout(new GridLayout(3, false));

    folder = new CTabFolder(container, SWT.BOTTOM | SWT.BORDER);
    folder.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true, 3, 1));

    document = new Document();

    //      parent.getDisplay().syncExec(new Runnable() {
    ////from w  ww  . j  a va  2 s  . c  om
    //         @Override
    //         public void run() {

    {
        CTabItem item = new CTabItem(folder, SWT.NONE);

        item.setText("Preview");
        item.setImage(JFaceResources.getImage(IMAGE_PREVIEW));

        swtFXContainer = new FXCanvas(folder, SWT.NONE);
        swtFXContainer.setEnabled(false);

        item.setControl(swtFXContainer);

        rootPane_new = new BorderPane();
        BorderPane pane = new BorderPane();
        pane.setCenter(rootPane_new);
        defaultScene = new Scene(pane, -1, -1, Platform.isSupported(ConditionalFeature.SCENE3D));
        currentScene = defaultScene;
        swtFXContainer.setScene(defaultScene);
    }

    {
        logItem = new CTabItem(folder, SWT.NONE);
        logItem.setText("Error log");
        logItem.setImage(JFaceResources.getImage(IMAGE_OK));

        logStatement = new Text(folder, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL);
        logStatement.setEditable(false);
        logItem.setControl(logStatement);

        Menu m = new Menu(logStatement);
        logStatement.setMenu(m);
        MenuItem clearItem = new MenuItem(m, SWT.PUSH);
        clearItem.setText("Clear Log");
        clearItem.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                logStatement.setText("");
            }
        });
    }

    {
        CTabItem fxmlContent = new CTabItem(folder, SWT.NONE);
        fxmlContent.setText("FXML-Source");
        fxmlContent.setImage(JFaceResources.getImage(IMAGE_FXML_CONTENT));

        final AnnotationModel model = new AnnotationModel();
        VerticalRuler verticalRuler = new VerticalRuler(VERTICAL_RULER_WIDTH, new AnnotationAccess());
        int styles = SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION;
        SourceViewer sourceViewer = new SourceViewer(folder, verticalRuler, styles);
        sourceViewer.configure(new XMLConfiguration(new ColorManager()));
        sourceViewer.setEditable(false);
        sourceViewer.getTextWidget().setFont(JFaceResources.getTextFont());

        IDocumentPartitioner partitioner = new FastPartitioner(new XMLPartitionScanner(),
                new String[] { XMLPartitionScanner.XML_TAG, XMLPartitionScanner.XML_COMMENT });
        partitioner.connect(document);
        document.setDocumentPartitioner(partitioner);
        sourceViewer.setDocument(document);
        verticalRuler.setModel(model);
        fxmlContent.setControl(sourceViewer.getControl());
    }

    folder.setSelection(0);

    statusLabelIcon = new Label(container, SWT.NONE);
    statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_NOPREVIEW));

    statusLabelText = new Label(container, SWT.NONE);
    statusLabelText.setText(NO_PREVIEW_TEXT);
    statusLabelText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Composite scaleControl = new Composite(container, SWT.NONE);
    scaleControl.setLayoutData(new GridData(GridData.END, GridData.CENTER, false, false));
    scaleControl.setLayout(new GridLayout(2, false));

    Label l = new Label(scaleControl, SWT.NONE);
    l.setText("Zoom");

    scale = new Spinner(scaleControl, SWT.BORDER);
    scale.setMinimum(10);
    scale.setMaximum(500);
    scale.setIncrement(10);
    scale.setSelection(100);
    scale.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            rootPane_new.getTransforms()
                    .setAll(Transform.scale(scale.getSelection() / 100.0, scale.getSelection() / 100.0));
            if (currentFile != null) {
                scaleMap.put(currentFile, scale.getSelection());
            }
        }
    });

    parent.layout(true, true);

    if (currentData != null) {
        refreshContent(currentData);
    }
    //         }
    //      });

    parent.layout(true, true);

    Action loadController = new Action("", IAction.AS_CHECK_BOX) {
        @Override
        public void run() {
            preference.putBoolean(PREF_LOAD_CONTROLLER, !preference.getBoolean(PREF_LOAD_CONTROLLER, false));
            try {
                preference.flush();
                synchronizer.refreshPreview();
            } catch (BackingStoreException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    };
    loadController.setChecked(preference.getBoolean(PREF_LOAD_CONTROLLER, false));
    loadController.setImageDescriptor(JFaceResources.getImageRegistry().getDescriptor(IMAGE_LOAD_CONTROLLER));
    loadController.setToolTipText("Load the controller");

    Action refresh = new Action("", JFaceResources.getImageRegistry().getDescriptor(IMAGE_REFRESH)) {
        @Override
        public void run() {
            synchronizer.refreshPreview();
        }
    };
    refresh.setToolTipText("Force a refresh");

    MenuManager mgr = new MenuManager();
    for (SCREEN_SIZE s : SCREEN_SIZE.values()) {
        mgr.add(new ScreenAction(s));
    }
    final Menu m = mgr.createContextMenu(parent);

    screenSize = new Action("ScreenSize", IAction.AS_DROP_DOWN_MENU) {
        @Override
        public void runWithEvent(Event event) {
            if (event.detail == SWT.DROP_DOWN) {
                ToolItem i = (ToolItem) event.widget;
                m.setLocation(i.getParent().toDisplay(event.x, event.y));
                m.setVisible(true);
            }
        }
    };
    getViewSite().getActionBars().getToolBarManager().add(screenSize);
    getViewSite().getActionBars().getToolBarManager().add(new Action("Horizontal", Action.AS_CHECK_BOX) {
        @Override
        public void run() {
            updateResolution(currentSize, isChecked());
        }
    });
    getViewSite().getActionBars().getToolBarManager().add(refresh);
    getViewSite().getActionBars().getToolBarManager().add(loadController);
}

From source file:org.eclipse.fx.ide.ui.preview.LivePreviewPart.java

License:Open Source License

private void saveRefreshContent(final ContentData contentData) {
    folder.setVisible(true);//  ww w . j a  v  a  2s .  c  o  m

    ClassLoader cl = null;

    FXMLLoader loader;
    if (contentData.extraJarPath != null && !contentData.extraJarPath.isEmpty() && swtFXContainer != null) {
        final URLClassLoader previewClassLoader = new PreviewURLClassloader(
                contentData.extraJarPath.toArray(new URL[0]), swtFXContainer.getClass().getClassLoader());

        cl = Thread.currentThread().getContextClassLoader();
        Thread.currentThread().setContextClassLoader(previewClassLoader);

        loader = new FXMLLoader();
        loader.setBuilderFactory(new BuilderFactory() {
            private BuilderFactory f = new JavaFXBuilderFactory(previewClassLoader);

            @Override
            public Builder<?> getBuilder(Class<?> type) {
                return f.getBuilder(type);
            }
        });
        loader.setClassLoader(previewClassLoader);
    } else {
        loader = new FXMLLoader();
    }

    final StringBuilder exception = new StringBuilder();

    try {
        currentFile = contentData.file;
        ReflectiveInvoke.setStaticLoad(loader, !preference.getBoolean(PREF_LOAD_CONTROLLER, false));
        try {
            // TODO Should we set this to the bin-Folder??
            loader.setLocation(
                    contentData.file.getParent().getLocation().toFile().getAbsoluteFile().toURI().toURL());
        } catch (MalformedURLException e1) {
            // TODO Auto-generated catch block
            e1.printStackTrace();
        }

        if (contentData.resourceBundle != null) {
            FileInputStream in = null;
            try {
                in = new FileInputStream(new File(contentData.resourceBundle));
                Properties p = new Properties();
                p.load(in);

                final Object[][] entries = new Object[p.entrySet().size()][];
                int i = 0;
                for (Entry<Object, Object> e : p.entrySet()) {
                    entries[i++] = new Object[] { e.getKey(), e.getValue() };
                }

                ListResourceBundle b = new ListResourceBundle() {

                    @Override
                    protected Object[][] getContents() {
                        return entries;
                    }
                };
                ResourceBundle rb = new ResourceBundle() {

                    @Override
                    protected Object handleGetObject(String key) {
                        Object object = b.handleGetObject(key);
                        if (object == null) {
                            exception.append("Warning: Missing key '" + key + "'\n");
                            object = "!" + key + "!";
                        }
                        return object;
                    }

                    @Override
                    public Enumeration<String> getKeys() {
                        return b.getKeys();
                    }

                    @Override
                    public boolean containsKey(String key) {
                        return true;
                    }
                };
                loader.setResources(b);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                if (in != null) {
                    try {
                        in.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        } else {
            ResourceBundle rb = new ResourceBundle() {

                @Override
                protected Object handleGetObject(String key) {
                    exception.append("Warning: No resource bundle provided\n");
                    return "!" + key + "!";
                }

                @Override
                public Enumeration<String> getKeys() {
                    return Collections.emptyEnumeration();
                }

                @Override
                public boolean containsKey(String key) {
                    return true;
                }
            };
            loader.setResources(rb);
        }

        try {
            document.set(contentData.contents);
            ByteArrayInputStream out = new ByteArrayInputStream(contentData.contents.getBytes());
            Object root = loader.load(out);
            out.close();

            Scene scene = null;
            if (root instanceof Scene) {
                scene = (Scene) root;
                rootPane_new = scene.getRoot();
            } else {
                if (contentData.previewSceneSetup != null) {
                    ByteArrayInputStream sceneOut = new ByteArrayInputStream(
                            contentData.previewSceneSetup.getBytes());
                    Object sceneRoot = loader.load(sceneOut);
                    if (sceneRoot instanceof Scene) {
                        scene = (Scene) sceneRoot;
                    }
                }

                rootPane_new = (Node) root;

                if (scene == null) {
                    Parent p;
                    BorderPane b = new BorderPane();
                    b.setCenter(rootPane_new);
                    p = b;

                    ((BorderPane) defaultScene.getRoot()).setCenter(p);
                    scene = defaultScene;
                    //
                    //                  scene = new Scene(p, -1, -1, Platform.isSupported(ConditionalFeature.SCENE3D));
                    //                  if( Platform.isSupported(ConditionalFeature.SCENE3D) ) {
                    //                     scene.setCamera(new PerspectiveCamera());
                    //                  }
                } else {
                    Node n = scene.getRoot().lookup("#previewcontainer");
                    if (n == null || !(n instanceof Parent)) {
                        n = scene.getRoot();
                    }

                    String previewFeature = null;

                    if (n.getUserData() != null && n.getUserData() != null) {
                        previewFeature = n.getUserData().toString().trim();
                    }

                    if (previewFeature != null) {
                        try {
                            String mName = "set" + Character.toUpperCase(previewFeature.charAt(0))
                                    + previewFeature.substring(1);
                            Method m = n.getClass().getMethod(mName, Node.class);
                            m.invoke(n, rootPane_new);
                        } catch (Throwable t) {
                            String mName = "get" + Character.toUpperCase(previewFeature.charAt(0))
                                    + previewFeature.substring(1);
                            Method m = n.getClass().getMethod(mName);
                            Object o = m.invoke(n);
                            if (o instanceof List) {
                                ((List<Object>) o).add(rootPane_new);
                            }
                        }
                    } else {
                        if (n instanceof BorderPane) {
                            ((BorderPane) n).setCenter(rootPane_new);
                        } else if (n instanceof Pane) {
                            ((Pane) n).getChildren().add(rootPane_new);
                        } else {
                            throw new IllegalStateException(
                                    "The parent in the scene is not a Pane. Set a preview-property styleclass on the control");
                        }
                    }
                }
            }

            if (rootPane_new != null) {
                if (scaleMap.containsKey(currentFile)) {
                    int value = scaleMap.get(currentFile).intValue();
                    scale.setSelection(value);

                    rootPane_new.getTransforms().setAll(Transform.scale(value / 100.0, value / 100.0));
                } else {
                    scale.setSelection(100);
                    rootPane_new.getTransforms().clear();
                }
            }

            // Force CSS-Reloading
            if (isJavaFX2()) {
                ReflectiveInvoke.onStyleManagerClass(scene);
            }

            // In FX8 we need to remove the stylesheets on the old scene to force reloading them
            if (swtFXContainer.getScene() != null) {
                swtFXContainer.getScene().getStylesheets().clear();
            }

            scene.getStylesheets().addAll(contentData.cssFiles);
            currentScene = scene;
            folder.setSelection(0);
            swtFXContainer.setScene(scene);
            contentData.sceneGraphCallback.accept(scene.getRoot());
        } catch (Exception e) {
            StringWriter sw = new StringWriter();
            e.printStackTrace(new PrintWriter(sw));
            exception.append(sw.toString());
        }
    } finally {
        if (cl != null) {
            Thread.currentThread().setContextClassLoader(cl);
        }
    }

    if (exception.length() > 0) {
        final String innerException = exception.toString();
        if (folder.isDisposed()) {
            return;
        }

        folder.getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                if (innerException != null) {
                    logItem.setImage(JFaceResources.getImage(IMAGE_ERROR));
                    statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_ERROR));
                    statusLabelText.setText(SimpleDateFormat.getTimeInstance().format(new Date())
                            + ": Error while updating preview");
                    setTitleImage(JFaceResources.getImage(IMAGE_TAB_ERROR));
                    folder.setSelection(logItem);
                }

                logStatement.setText("");
                logStatement.append("================================================================="
                        + logStatement.getLineDelimiter());
                logStatement.append("Preview loading @ " + new Date() + logStatement.getLineDelimiter());
                logStatement.append("================================================================="
                        + logStatement.getLineDelimiter());

                if (innerException != null) {
                    logStatement.append("Exception:" + logStatement.getLineDelimiter());
                    logStatement.append("----------" + logStatement.getLineDelimiter());
                    logStatement.append(innerException + logStatement.getLineDelimiter());
                    logStatement.append(logStatement.getLineDelimiter() + logStatement.getLineDelimiter());
                    logStatement.setSelection(0);
                }
            }
        });

    } else {
        folder.getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                folder.setSelection(0);
                logItem.setImage(JFaceResources.getImage(IMAGE_OK));
                statusLabelIcon.setImage(JFaceResources.getImage(IMAGE_STATUS_OK));
                statusLabelText
                        .setText(SimpleDateFormat.getTimeInstance().format(new Date()) + ": Preview updated");
                setTitleImage(JFaceResources.getImage(IMAGE_TAB_NORMAL));
            }
        });
    }
}

From source file:org.eclipse.gmf.runtime.diagram.ui.render.internal.dialogs.CopyToImageDialog.java

License:Open Source License

/**
 *   Create the message group in the dialog used to display error messages.
 *   @param parent the parent widget/*from   ww w.  j a  v a  2s  . co m*/
 */
private void createMessageGroup(Composite parent) {
    Composite composite = createComposite(parent, 2);

    messageImageLabel = new Label(composite, SWT.NONE);
    messageImageLabel.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_ERROR));
    messageImageLabel.setVisible(false);

    messageLabel = new Label(composite, SWT.NONE);
    GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.FILL_HORIZONTAL);
    gridData.widthHint = 250;
    messageLabel.setLayoutData(gridData);
    messageLabel.setVisible(false);
}

From source file:org.eclipse.help.ui.internal.views.MissingContentPart.java

License:Open Source License

private void createHelpMissingLink(Composite container, FormToolkit toolkit, String imageKey, String linkText,
        String linkTarget, boolean isRemoteUnavailableLink) {
    final String target = linkTarget;
    final boolean isRemote = isRemoteUnavailableLink;
    Composite padding = new Composite(container, SWT.NULL);
    GridData paddingData = new GridData();
    paddingData.heightHint = 2;//from   w ww.  ja  v  a  2  s  . co m
    padding.setLayoutData(paddingData);
    toolkit.adapt(padding);
    Image warningImage = JFaceResources.getImage(imageKey);
    statusLink = toolkit.createImageHyperlink(container, SWT.NULL);
    statusLink.setText(linkText);
    statusLink.setImage(warningImage);
    statusLink.addHyperlinkListener(new HyperlinkAdapter() {
        public void linkActivated(HyperlinkEvent e) {
            helpPart.showURL(target);
            if (isRemote) {
                helpPart.checkRemoteStatus();
            } else {
                helpPart.checkPlaceholderStatus();
            }
        }
    });
    GridData statusData = new GridData(GridData.BEGINNING, GridData.CENTER, false, false);
    statusLink.setLayoutData(statusData);
}

From source file:org.eclipse.ice.client.widgets.moose.CheckboxCellContentProvider.java

License:Open Source License

/**
 * Provides a checkbox <code>Image</code> depending on whether the cell is
 * enabled/disabled and selected/unselected.
 *//*  w  ww  .j a  v  a  2 s.  c  o m*/
@Override
public Image getImage(Object element) {
    Image image = null;

    // Depending on whether or not the element is checked and enabled, set
    // its image.
    if (isEnabled(element)) {
        if (isSelected(element)) {
            image = JFaceResources.getImage(ENABLED_CHECKED);
        } else {
            image = JFaceResources.getImage(ENABLED_UNCHECKED);
        }
    } else if (isSelected(element)) {
        image = JFaceResources.getImage(DISABLED_CHECKED);
    } else {
        image = JFaceResources.getImage(DISABLED_UNCHECKED);
    }

    return image;
}