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

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

Introduction

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

Prototype

public static ResourceManager getResources() 

Source Link

Document

Returns the ResourceManager for the current display.

Usage

From source file:org.eclipse.ease.discovery.ui.internal.common.GradientToolTip.java

License:Open Source License

private void initResources(Control control) {
    resourceManager = new LocalResourceManager(JFaceResources.getResources());
    colors = new NotificationPopupColors(control.getDisplay(), resourceManager);
}

From source file:org.eclipse.ease.modules.unittest.ui.views.UnitTestView.java

License:Open Source License

@Override
public void createPartControl(final Composite parent) {
    parent.setLayout(new GridLayout(1, false));

    final Composite composite = new Composite(parent, SWT.NONE);
    composite.setLayout(new GridLayout(8, false));
    composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    fResourceManager = new LocalResourceManager(JFaceResources.getResources(), composite);

    final Label lblErrorIcon = new Label(composite, SWT.NONE);
    final GridData gdLblErrorIcon = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLblErrorIcon.horizontalIndent = 50;
    lblErrorIcon.setLayoutData(gdLblErrorIcon);
    lblErrorIcon.setImage(fResourceManager.createImage(Activator.getImageDescriptor(Activator.ICON_ERROR)));

    final Label lblErrors = new Label(composite, SWT.NONE);
    lblErrors.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblErrors.setAlignment(SWT.CENTER);//from  w  ww. ja v a2s  . c o  m
    lblErrors.setText("Errors:");

    lblErrorCount = new Label(composite, SWT.NONE);
    final GridData gd_lblErrorCount = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gd_lblErrorCount.horizontalIndent = 20;
    lblErrorCount.setLayoutData(gd_lblErrorCount);

    final Label lblFailureIcon = new Label(composite, SWT.NONE);
    final GridData gdLblFailureIcon = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLblFailureIcon.horizontalIndent = 50;
    lblFailureIcon.setLayoutData(gdLblFailureIcon);
    lblFailureIcon.setImage(fResourceManager.createImage(Activator.getImageDescriptor(Activator.ICON_FAILURE)));

    final Label lblFailures = new Label(composite, SWT.NONE);
    lblFailures.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblFailures.setAlignment(SWT.CENTER);
    lblFailures.setText("Failures:");

    lblFailureCount = new Label(composite, SWT.NONE);
    final GridData gdLblFailureCount = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gdLblFailureCount.horizontalIndent = 20;
    lblFailureCount.setLayoutData(gdLblFailureCount);

    lblTimeLeftText = new Label(composite, SWT.NONE);
    final GridData gdLabel = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLabel.horizontalIndent = 50;
    lblTimeLeftText.setLayoutData(gdLabel);
    lblTimeLeftText.setText("Time left: ");
    lblTimeLeftText.setVisible(false);

    lblTimeLeft = new Label(composite, SWT.NONE);
    final GridData gdLblTimeLeft = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdLblTimeLeft.horizontalIndent = 20;
    lblTimeLeft.setLayoutData(gdLblTimeLeft);
    lblTimeLeft.setVisible(false);

    fProgressBar = new ProgressBar(parent, SWT.NONE);
    fProgressBar.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    sashForm = new SashForm(parent, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    sashForm.setOrientation(SWT.VERTICAL);

    fFileTreeViewer = new TreeViewer(sashForm, SWT.BORDER | SWT.MULTI);
    fFileTreeViewer.setContentProvider(new TestSuiteContentProvider());

    fFileTreeViewer.setComparator(new ViewerComparator() {
        @Override
        public final int category(final Object element) {
            if (element instanceof TestFile)
                return 1;

            return 0;
        }
    });

    // use a decorated label provider
    final LabelProvider provider = new TestSuiteLabelProvider(fResourceManager);
    fFileTreeViewer.setLabelProvider(new DecoratedLabelProvider(provider));

    fFileTreeViewer.addDoubleClickListener(new IDoubleClickListener() {
        @Override
        public void doubleClick(final DoubleClickEvent event) {
            try {
                final Object element = ((IStructuredSelection) event.getSelection()).getFirstElement();
                if (element instanceof TestFile) {
                    final Object file = ((TestFile) element).getFile();
                    if (file instanceof IFile)
                        UIModule.showEditor((IFile) ((TestFile) element).getFile());

                } else if (element instanceof TestSuite)
                    UIModule.showEditor(((TestSuite) element).getModel().getFile());

            } catch (final Throwable e) {
                // TODO handle this exception (but for now, at least know it happened)
                throw new RuntimeException(e);

            }
        }
    });
    fFileTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ITreeSelection selection = (ITreeSelection) event.getSelection();
            final Object element = selection.getFirstElement();

            if (element instanceof TestComposite) {
                // test set selected
                fTestTreeViewer.setInput(element);

                if (sashForm.getWeights()[1] == 0)
                    sashForm.setWeights(fSashWeights);

                fTestTreeViewer.refresh();

            } else {
                // test container selected, or no selection at all
                fTestTreeViewer.setInput(null);

                if (sashForm.getWeights()[1] != 0)
                    fSashWeights = sashForm.getWeights();

                sashForm.setWeights(new int[] { 100, 0 });
            }
        }
    });

    // create tree viewer for tests
    fTestTreeViewer = createTestArea(sashForm);

    sashForm.setWeights(new int[] { 1, 1 });

    // add context menu support
    final MenuManager menuManager = new MenuManager();
    final Menu menu = menuManager.createContextMenu(fFileTreeViewer.getTree());
    fFileTreeViewer.getTree().setMenu(menu);
    getSite().registerContextMenu(menuManager, fFileTreeViewer);

    final MenuManager menuManager2 = new MenuManager();
    final Menu menu2 = menuManager2.createContextMenu(fFileTreeViewer.getTree());
    fTestTreeViewer.getTree().setMenu(menu2);
    getSite().registerContextMenu(menuManager2, fTestTreeViewer);

    // add collapseAll/expandAll handlers
    final IHandlerService handlerService = getSite().getService(IHandlerService.class);
    mCollapseAllHandler = new CollapseAllHandler(fFileTreeViewer);
    handlerService.activateHandler(CollapseAllHandler.COMMAND_ID, mCollapseAllHandler);
    mExpandAllHandler = new ExpandAllHandler(fFileTreeViewer);
    handlerService.activateHandler(ExpandAllHandler.COMMAND_ID, mExpandAllHandler);

    // menuManager.setRemoveAllWhenShown(true);

    // load last suite
    if (mMemento != null) {
        final IMemento currentSuiteNode = mMemento.getChild(XML_CURRENT_SUITE);
        if (currentSuiteNode != null) {
            final Path path = new Path(currentSuiteNode.getTextData());
            final IFile suiteFile = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
            try {
                loadSuite(new TestSuite(new TestSuiteModel(suiteFile)));
            } catch (final Exception e) {
                // loading failed, ignore
            }
        }
    }

    // register for console events
    ConsolePlugin.getDefault().getConsoleManager().addConsoleListener(UnitTestView.this);

    final MultiSelectionProvider selectionProvider = new MultiSelectionProvider();
    selectionProvider.addSelectionProvider(fFileTreeViewer);
    selectionProvider.addSelectionProvider(fTestTreeViewer);

    getSite().setSelectionProvider(selectionProvider);
}

From source file:org.eclipse.ease.ui.view.ScriptShell.java

License:Open Source License

@Override
public final void createPartControl(final Composite parent) {

    // setup resource manager
    mResourceManager = new LocalResourceManager(JFaceResources.getResources(), parent);

    // setup layout
    parent.setLayout(new GridLayout());

    sashForm = new SashForm(parent, SWT.NONE);
    sashForm.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    mOutputText = new StyledText(sashForm, SWT.V_SCROLL | SWT.READ_ONLY | SWT.BORDER);

    // set monospaced font
    final Object os = Platform.getOS();
    if ("win32".equals(os))
        mOutputText/*from  w w w.j  av  a  2s  .com*/
                .setFont(mResourceManager.createFont(FontDescriptor.createFrom("Courier New", 10, SWT.NONE)));

    else if ("linux".equals(os))
        mOutputText.setFont(mResourceManager.createFont(FontDescriptor.createFrom("Monospace", 10, SWT.NONE)));

    mOutputText.setEditable(false);
    mOutputText.addMouseListener(new MouseListener() {

        @Override
        public void mouseUp(final MouseEvent e) {
        }

        @Override
        public void mouseDown(final MouseEvent e) {
        }

        @Override
        public void mouseDoubleClick(final MouseEvent e) {
            // copy line under cursor in input box
            String selected = mOutputText.getLine(mOutputText.getLineIndex(e.y));
            if (!selected.isEmpty()) {
                mInputCombo.setText(selected);
                mInputCombo.setFocus();
                mInputCombo.setSelection(new Point(0, selected.length()));
            }
        }
    });

    fScriptComposite = new ScriptComposite(this, getSite(), sashForm, SWT.NONE);
    fScriptComposite.setEngine(fScriptEngine.getDescription().getID());

    sashForm.setWeights(mSashWeights);
    mInputCombo = new Combo(parent, SWT.NONE);
    mInputCombo.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetDefaultSelected(final SelectionEvent e) {
            final String input = mInputCombo.getText();
            mInputCombo.setText("");

            addToHistory(input);
            fScriptEngine.executeAsync(input);
        }
    });

    mInputCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    // restore command history
    if (mInitMemento != null) {
        for (final IMemento node : mInitMemento.getChildren(XML_HISTORY_NODE)) {
            if (node.getTextData() != null)
                mInputCombo.add(node.getTextData());
        }
    }

    // clear reference as we are done with initialization
    mInitMemento = null;

    // add DND support
    ShellDropTarget.addDropSupport(mOutputText, this);

    // set view title
    setPartName(fScriptEngine.getName() + " " + super.getTitle());

    // read default preferences
    Preferences prefs = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID)
            .node(IPreferenceConstants.NODE_SHELL);

    fHistoryLength = prefs.getInt(IPreferenceConstants.SHELL_HISTORY_LENGTH,
            IPreferenceConstants.DEFAULT_SHELL_HISTORY_LENGTH);
    fAutoFocus = prefs.getBoolean(IPreferenceConstants.SHELL_AUTOFOCUS,
            IPreferenceConstants.DEFAULT_SHELL_AUTOFOCUS);
    fKeepCommand = prefs.getBoolean(IPreferenceConstants.SHELL_KEEP_COMMAND,
            IPreferenceConstants.DEFAULT_SHELL_KEEP_COMMAND);

    if (fAutoFocus) {
        if (fAutoFocusListener == null)
            fAutoFocusListener = new AutoFocus();

        mOutputText.addKeyListener(fAutoFocusListener);
    }

    // run startup commands, do this for all supported script types
    runStartupCommands();
}

From source file:org.eclipse.egit.ui.internal.components.CheckboxLabelProvider.java

License:Open Source License

/**
 * Create label provider for provided viewer.
 *
 * @param control/*www .  j av  a 2  s.  c  o  m*/
 *            viewer where label provided is used.
 */
public CheckboxLabelProvider(final Control control) {
    resourceManager = new LocalResourceManager(JFaceResources.getResources());

    imageCheckedEnabled = createCheckboxImage(resourceManager, control, true, true);
    imageUncheckedEnabled = createCheckboxImage(resourceManager, control, false, true);
    imageCheckedDisabled = createCheckboxImage(resourceManager, control, true, false);
    imageUncheckedDisabled = createCheckboxImage(resourceManager, control, false, false);
}

From source file:org.eclipse.egit.ui.internal.components.TitleAndImageDialog.java

License:Open Source License

/**
 * Retrieves this dialog's {@link LocalResourceManager}.
 *
 * @return the {@link LocalResourceManager}
 *///from w  w w  .  jav  a 2s . c  om
protected ResourceManager getResourceManager() {
    if (resourceManager == null) {
        resourceManager = new LocalResourceManager(JFaceResources.getResources());
    }
    return resourceManager;
}

From source file:org.eclipse.egit.ui.internal.GitLabelProvider.java

License:Open Source License

private ResourceManager getImageCache() {
    if (imageCache == null)
        imageCache = new LocalResourceManager(JFaceResources.getResources());
    return imageCache;
}

From source file:org.eclipse.egit.ui.internal.history.CommitSelectionDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().grab(true, true).applyTo(main);
    final ResourceManager resources = new LocalResourceManager(JFaceResources.getResources());
    UIUtils.hookDisposal(main, resources);
    table = new CommitGraphTable(main, null, resources);
    table.getTableView().addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            commitId = null;/*from  ww w.  ja  va 2  s. c  o  m*/
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.size() == 1)
                commitId = ((SWTCommit) sel.getFirstElement()).getId();
            getButton(OK).setEnabled(commitId != null);
        }
    });
    table.getTableView().addOpenListener(new IOpenListener() {
        public void open(OpenEvent event) {
            if (getButton(OK).isEnabled())
                buttonPressed(OK);
        }
    });
    // allow for some room here
    GridDataFactory.fillDefaults().grab(true, true).minSize(SWT.DEFAULT, 400).applyTo(table.getControl());
    allCommits = new SWTCommitList(table.getControl(), resources);
    return main;
}

From source file:org.eclipse.egit.ui.internal.reflog.ReflogView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayoutFactory.fillDefaults().applyTo(parent);

    toolkit = new FormToolkit(parent.getDisplay());
    parent.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            toolkit.dispose();//www  .j  a  v a 2  s .com
        }
    });

    form = toolkit.createForm(parent);

    Image repoImage = UIIcons.REPOSITORY.createImage();
    UIUtils.hookDisposal(form, repoImage);
    final Image branchImage = UIIcons.CHANGESET.createImage();
    UIUtils.hookDisposal(form, branchImage);
    form.setImage(repoImage);
    form.setText(UIText.StagingView_NoSelectionTitle);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(form);
    toolkit.decorateFormHeading(form);
    GridLayoutFactory.fillDefaults().applyTo(form.getBody());

    Composite tableComposite = toolkit.createComposite(form.getBody());
    tableComposite.setLayout(new GridLayout());

    GridDataFactory.fillDefaults().grab(true, true).applyTo(tableComposite);

    final TreeColumnLayout layout = new TreeColumnLayout();

    FilteredTree filteredTree = new FilteredTree(tableComposite, SWT.NONE | SWT.BORDER | SWT.FULL_SELECTION,
            new PatternFilter(), true) {
        @Override
        protected void createControl(Composite composite, int treeStyle) {
            super.createControl(composite, treeStyle);
            treeComposite.setLayout(layout);
        }
    };

    toolkit.adapt(filteredTree);
    refLogTableTreeViewer = filteredTree.getViewer();
    refLogTableTreeViewer.getTree().setLinesVisible(true);
    refLogTableTreeViewer.getTree().setHeaderVisible(true);
    refLogTableTreeViewer.setContentProvider(new ReflogViewContentProvider());

    ColumnViewerToolTipSupport.enableFor(refLogTableTreeViewer);

    TreeViewerColumn toColumn = createColumn(layout, UIText.ReflogView_CommitColumnHeader, 10, SWT.LEFT);
    toColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            final ReflogEntry entry = (ReflogEntry) element;
            return entry.getNewId().abbreviate(7).name();
        }

        @Override
        public String getToolTipText(Object element) {
            final ReflogEntry entry = (ReflogEntry) element;
            return entry.getNewId().name();
        }

        @Override
        public Image getImage(Object element) {
            return branchImage;
        }

    });

    TreeViewerColumn commitMessageColumn = createColumn(layout, UIText.ReflogView_CommitMessageColumnHeader, 40,
            SWT.LEFT);
    commitMessageColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            final ReflogEntry entry = (ReflogEntry) element;
            RevCommit c = getCommit(entry);
            return c == null ? "" : c.getShortMessage(); //$NON-NLS-1$
        }

        private RevCommit getCommit(final ReflogEntry entry) {
            RevWalk walk = new RevWalk(getRepository());
            walk.setRetainBody(true);
            RevCommit c = null;
            try {
                c = walk.parseCommit(entry.getNewId());
            } catch (IOException ignored) {
                // ignore
            } finally {
                walk.release();
            }
            return c;
        }
    });

    TreeViewerColumn dateColumn = createColumn(layout, UIText.ReflogView_DateColumnHeader, 15, SWT.LEFT);
    dateColumn.setLabelProvider(new ColumnLabelProvider() {

        @Override
        public String getText(Object element) {
            final ReflogEntry entry = (ReflogEntry) element;
            final PersonIdent who = entry.getWho();
            // TODO add option to use RelativeDateFormatter
            return absoluteFormatter.format(who.getWhen());
        }

        @Override
        public Image getImage(Object element) {
            return null;
        }

    });

    TreeViewerColumn messageColumn = createColumn(layout, UIText.ReflogView_MessageColumnHeader, 40, SWT.LEFT);
    messageColumn.setLabelProvider(new ColumnLabelProvider() {

        private ResourceManager resourceManager = new LocalResourceManager(JFaceResources.getResources());

        @Override
        public String getText(Object element) {
            final ReflogEntry entry = (ReflogEntry) element;
            return entry.getComment();
        }

        public Image getImage(Object element) {
            String comment = ((ReflogEntry) element).getComment();
            if (comment.startsWith("commit:") || comment.startsWith("commit (initial):")) //$NON-NLS-1$ //$NON-NLS-2$
                return (Image) resourceManager.get(UIIcons.COMMIT);
            if (comment.startsWith("commit (amend):")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.AMEND_COMMIT);
            if (comment.startsWith("pull")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.PULL);
            if (comment.startsWith("clone")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.CLONEGIT);
            if (comment.startsWith("rebase")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.REBASE);
            if (comment.startsWith("merge")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.MERGE);
            if (comment.startsWith("fetch")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.FETCH);
            if (comment.startsWith("branch")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.CREATE_BRANCH);
            if (comment.startsWith("checkout")) //$NON-NLS-1$
                return (Image) resourceManager.get(UIIcons.CHECKOUT);
            return null;
        }

        public void dispose() {
            resourceManager.dispose();
            super.dispose();
        }
    });

    new OpenAndLinkWithEditorHelper(refLogTableTreeViewer) {
        @Override
        protected void linkToEditor(ISelection selection) {
            // Not supported

        }

        @Override
        protected void open(ISelection sel, boolean activate) {
            handleOpen(sel, OpenStrategy.activateOnOpen());
        }

        @Override
        protected void activate(ISelection selection) {
            handleOpen(selection, true);
        }

        private void handleOpen(ISelection selection, boolean activateOnOpen) {
            if (selection instanceof IStructuredSelection)
                if (selection.isEmpty())
                    return;
            Repository repo = getRepository();
            if (repo == null)
                return;
            RevWalk walk = new RevWalk(repo);
            try {
                for (Object element : ((IStructuredSelection) selection).toArray()) {
                    ReflogEntry entry = (ReflogEntry) element;
                    ObjectId id = entry.getNewId();
                    if (id == null || id.equals(ObjectId.zeroId()))
                        id = entry.getOldId();
                    if (id != null && !id.equals(ObjectId.zeroId()))
                        CommitEditor.openQuiet(new RepositoryCommit(repo, walk.parseCommit(id)),
                                activateOnOpen);
                }
            } catch (IOException e) {
                Activator.logError(UIText.ReflogView_ErrorOnOpenCommit, e);
            } finally {
                walk.release();
            }
        }
    };

    selectionChangedListener = new ISelectionListener() {
        public void selectionChanged(IWorkbenchPart part, ISelection selection) {
            if (part instanceof IEditorPart) {
                IEditorInput input = ((IEditorPart) part).getEditorInput();
                if (input instanceof IFileEditorInput)
                    reactOnSelection(new StructuredSelection(((IFileEditorInput) input).getFile()));
            } else
                reactOnSelection(selection);
        }
    };

    IWorkbenchPartSite site = getSite();
    ISelectionService service = (ISelectionService) site.getService(ISelectionService.class);
    service.addPostSelectionListener(selectionChangedListener);

    // Use current selection to populate reflog view
    ISelection selection = service.getSelection();
    if (selection != null && !selection.isEmpty()) {
        IWorkbenchPart part = site.getPage().getActivePart();
        if (part != null)
            selectionChangedListener.selectionChanged(part, selection);
    }

    site.setSelectionProvider(refLogTableTreeViewer);

    addRefsChangedListener = Repository.getGlobalListenerList().addRefsChangedListener(this);

    // register context menu
    MenuManager menuManager = new MenuManager();
    menuManager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    Tree tree = refLogTableTreeViewer.getTree();
    tree.setMenu(menuManager.createContextMenu(tree));
    getSite().registerContextMenu(POPUP_MENU_ID, menuManager, refLogTableTreeViewer);
}

From source file:org.eclipse.equinox.internal.p2.ui.discovery.DiscoveryUi.java

License:Open Source License

public static CommonColors getCommonsColors() {
    if (commonColors == null) {
        commonColors = new CommonColors(Display.getDefault(), JFaceResources.getResources());
    }//from  w  w  w .ja  v  a  2  s. c om
    return commonColors;
}

From source file:org.eclipse.gef.ui.parts.AbstractEditPartViewer.java

License:Open Source License

/**
 * @see org.eclipse.gef.EditPartViewer#getResourceManager()
 *///from   w  w w.  j av  a 2s. c  om
public ResourceManager getResourceManager() {
    if (resources != null)
        return resources;
    Assert.isNotNull(getControl());
    resources = new LocalResourceManager(JFaceResources.getResources());
    return resources;
}