Example usage for org.eclipse.jface.resource LocalResourceManager LocalResourceManager

List of usage examples for org.eclipse.jface.resource LocalResourceManager LocalResourceManager

Introduction

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

Prototype

public LocalResourceManager(ResourceManager parentRegistry) 

Source Link

Document

Creates a local registry that delegates to the given global registry for all resource allocation and deallocation.

Usage

From source file:at.bitandart.zoubek.mervin.diagram.diff.parts.WorkspaceEditPart.java

License:Open Source License

public WorkspaceEditPart(View model) {
    super(model);

    try {//from  ww  w  .  j a va  2s  .c  o  m
        registryResourceManager = new RegistryResourceManager(new PluginMervinResourceRegistry(),
                new LocalResourceManager(JFaceResources.getResources()));
    } catch (MalformedURLException e) {
        throw new IllegalStateException(e);
    }
}

From source file:au.com.cybersearch2.controls.ImageFactory.java

License:Open Source License

/**
 * Returns local Resource Manager//from  w ww  . ja va 2  s .c  om
 * @return ResourceManager object
 */
protected ResourceManager getResourceManager() {
    if (resourceManager == null)
        sync.syncExec(new Runnable() {

            @Override
            public void run() {
                // getResources() returns the ResourceManager for the current display. 
                // May only be called from a UI thread.
                ResourceManager resources = JFaceResources.getResources();
                resourceManager = new LocalResourceManager(resources);
            }
        });
    return resourceManager;
}

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

License:Open Source License

/**
 * Updates the images for this action./*from   www  .ja  va2s . com*/
 *
 * @param forceImage
 *          <code>true</code> if some form of image is compulsory, and
 *          <code>false</code> if it is acceptable for this item to have no
 *          image
 * @return <code>true</code> if there are images for this action,
 *         <code>false</code> if not
 */
private boolean updateImages(boolean forceImage) {

    final ResourceManager parentResourceManager = JFaceResources.getResources();

    if (widget instanceof ToolItem) {
        if (USE_COLOR_ICONS) {
            ImageDescriptor image = action.getHoverImageDescriptor();
            if (image == null) {
                image = action.getImageDescriptor();
            }
            final ImageDescriptor disabledImage = action.getDisabledImageDescriptor();

            // Make sure there is a valid image.
            if ((image == null) && forceImage) {
                image = ImageDescriptor.getMissingImageDescriptor();
            }

            final LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);

            // performance: more efficient in SWT to set disabled and hot
            // image before regular image
            ((ToolItem) widget).setDisabledImage(
                    disabledImage == null ? null : localManager.createImageWithDefault(disabledImage));
            ((ToolItem) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));

            disposeOldImages();
            imageManager = localManager;

            return image != null;
        }
        ImageDescriptor image = action.getImageDescriptor();
        ImageDescriptor hoverImage = action.getHoverImageDescriptor();
        final ImageDescriptor disabledImage = action.getDisabledImageDescriptor();

        // If there is no regular image, but there is a hover image,
        // convert the hover image to gray and use it as the regular image.
        if ((image == null) && (hoverImage != null)) {
            image = ImageDescriptor.createWithFlags(action.getHoverImageDescriptor(), SWT.IMAGE_GRAY);
        } else {
            // If there is no hover image, use the regular image as the
            // hover image,
            // and convert the regular image to gray
            if ((hoverImage == null) && (image != null)) {
                hoverImage = image;
                image = ImageDescriptor.createWithFlags(action.getImageDescriptor(), SWT.IMAGE_GRAY);
            }
        }

        // Make sure there is a valid image.
        if ((hoverImage == null) && (image == null) && forceImage) {
            image = ImageDescriptor.getMissingImageDescriptor();
        }

        // Create a local resource manager to remember the images we've
        // allocated for this tool item
        final LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);

        // performance: more efficient in SWT to set disabled and hot image
        // before regular image
        ((ToolItem) widget).setDisabledImage(
                disabledImage == null ? null : localManager.createImageWithDefault(disabledImage));
        ((ToolItem) widget)
                .setHotImage(hoverImage == null ? null : localManager.createImageWithDefault(hoverImage));
        ((ToolItem) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));

        // Now that we're no longer referencing the old images, clear them
        // out.
        disposeOldImages();
        imageManager = localManager;

        return image != null;
    } else if ((widget instanceof Item) || (widget instanceof Button)) {

        // Use hover image if there is one, otherwise use regular image.
        ImageDescriptor image = action.getHoverImageDescriptor();
        if (image == null) {
            image = action.getImageDescriptor();
        }
        // Make sure there is a valid image.
        if ((image == null) && forceImage) {
            image = ImageDescriptor.getMissingImageDescriptor();
        }

        // Create a local resource manager to remember the images we've
        // allocated for this widget
        final LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);

        if (widget instanceof Item) {
            ((Item) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));
        } else if (widget instanceof Button) {
            ((Button) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));
        }

        // Now that we're no longer referencing the old images, clear them
        // out.
        disposeOldImages();
        imageManager = localManager;

        return image != null;
    }
    return false;
}

From source file:com.github.haixing_hu.swt.menu.MenuManagerEx.java

License:Open Source License

@Override
public void fill(Menu parent, int index) {
    if ((menuItem == null) || menuItem.isDisposed()) {
        if (index >= 0) {
            menuItem = new MenuItem(parent, SWT.CASCADE, index);
        } else {//from w w  w.ja v a 2  s.  c  o  m
            menuItem = new MenuItem(parent, SWT.CASCADE);
        }

        final String text = getMenuText();
        if (text != null) {
            menuItem.setText(text);
        }

        if (image != null) {
            final LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
            menuItem.setImage(localManager.createImage(image));
            disposeOldImages();
            imageManager = localManager;
        }

        if (!menuExist()) {
            menu = new Menu(parent);
            menu.setData(MANAGER_KEY, this);
        }

        menuItem.setMenu(menu);

        initializeMenu();

        setDirty(true);
    }
}

From source file:com.github.haixing_hu.swt.menu.MenuManagerEx.java

License:Open Source License

@Override
public void update(String property) {
    final IContributionItem items[] = getItems();

    for (final IContributionItem item : items) {
        item.update(property);//from ww  w .j  a  v a 2s . co  m
    }

    if ((menu != null) && !menu.isDisposed() && (menu.getParentItem() != null)) {
        if (IAction.TEXT.equals(property)) {
            String text = getOverrides().getText(this);

            if (text == null) {
                text = getMenuText();
            }

            if (text != null) {
                final ExternalActionManager.ICallback callback = ExternalActionManager.getInstance()
                        .getCallback();

                if (callback != null) {
                    final int index = text.indexOf('&');

                    if ((index >= 0) && (index < (text.length() - 1))) {
                        final char character = Character.toUpperCase(text.charAt(index + 1));

                        if (callback.isAcceleratorInUse(SWT.ALT | character) && isTopLevelMenu()) {
                            if (index == 0) {
                                text = text.substring(1);
                            } else {
                                text = text.substring(0, index) + text.substring(index + 1);
                            }
                        }
                    }
                }

                menu.getParentItem().setText(text);
            }
        } else if (IAction.IMAGE.equals(property) && (image != null)) {
            final LocalResourceManager localManager = new LocalResourceManager(JFaceResources.getResources());
            menu.getParentItem().setImage(localManager.createImage(image));
            disposeOldImages();
            imageManager = localManager;
        }
    }
}

From source file:com.google.dart.tools.ui.internal.problemsview.ProblemsView.java

License:Open Source License

private static ResourceManager getImageManager() {
    if (resourceManager == null) {
        resourceManager = new LocalResourceManager(JFaceResources.getResources());
    }// ww  w .j a v a 2 s  . c o  m

    return resourceManager;
}

From source file:com.google.gdt.eclipse.managedapis.BaseResources.java

License:Open Source License

private void doInitResources() {
    if (null != Display.getCurrent()) {
        resourceManager = new LocalResourceManager(JFaceResources.getResources(display));
        disabledColorDescriptor = new RGB(0x69, 0x69, 0x69);
        h2FontDescriptor = createFontDescriptor(SWT.BOLD, 1.25f);
        initialized = true;/*  ww  w .j  av  a  2s .com*/
    }
}

From source file:com.liferay.ide.project.ui.wizard.WorkingSetGroup.java

License:Open Source License

private void createControl(Composite container) {
    addToWorkingSetButton = new Button(container, SWT.CHECK);
    GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
    gd_addToWorkingSetButton.verticalIndent = 12;
    addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
    addToWorkingSetButton.setSelection(true);
    addToWorkingSetButton.setData("name", "addToWorkingSetButton"); //$NON-NLS-1$ //$NON-NLS-2$
    addToWorkingSetButton.setText("Add project to working set");
    addToWorkingSetButton.setSelection(false);

    final Label workingsetLabel = new Label(container, SWT.NONE);
    GridData gd_workingsetLabel = new GridData();
    gd_workingsetLabel.horizontalIndent = 10;
    workingsetLabel.setLayoutData(gd_workingsetLabel);
    workingsetLabel.setEnabled(false);//from w w w.j  a va2  s  . c om
    workingsetLabel.setData("name", "workingsetLabel"); //$NON-NLS-1$ //$NON-NLS-2$
    workingsetLabel.setText("Working set:");

    Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
    workingsetCombo.setEnabled(false);
    workingsetCombo.setData("name", "workingsetCombo"); //$NON-NLS-1$ //$NON-NLS-2$
    workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    workingsetComboViewer = new ComboViewer(workingsetCombo);
    workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {
        public Object[] getElements(Object input) {
            if (input instanceof IWorkingSet[]) {
                return (IWorkingSet[]) input;
            } else if (input instanceof List<?>) {
                return new Object[] { input };
            } else if (input instanceof Set<?>) {
                return ((Set<?>) input).toArray();
            }
            return new IWorkingSet[0];
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        public void dispose() {
        }
    });
    workingsetComboViewer.setLabelProvider(new LabelProvider() {
        private ResourceManager images = new LocalResourceManager(JFaceResources.getResources());

        @SuppressWarnings("deprecation")
        public Image getImage(Object element) {
            if (element instanceof IWorkingSet) {
                ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
                if (imageDescriptor != null) {
                    try {
                        return (Image) images.create(imageDescriptor);
                    } catch (DeviceResourceException ex) {
                        return null;
                    }
                }
            }
            return super.getImage(element);
        }

        public String getText(Object element) {
            if (element instanceof IWorkingSet) {
                return ((IWorkingSet) element).getLabel();
            } else if (element instanceof List<?>) {
                StringBuffer sb = new StringBuffer();
                for (Object o : (List<?>) element) {
                    if (o instanceof IWorkingSet) {
                        if (sb.length() > 0) {
                            sb.append(", "); //$NON-NLS-1$
                        }
                        sb.append(((IWorkingSet) o).getLabel());
                    }
                }
                return sb.toString();
            }
            return super.getText(element);
        }

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

    workingsetComboViewer.setComparator(new ViewerComparator());

    final Button newWorkingSetButton = new Button(container, SWT.NONE);
    newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    newWorkingSetButton.setData("name", "configureButton"); //$NON-NLS-1$ //$NON-NLS-2$
    newWorkingSetButton.setText("More...");
    newWorkingSetButton.setEnabled(false);
    newWorkingSetButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(final SelectionEvent e) {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(shell, true,
                    WORKING_SET_IDS.toArray(new String[0]));
            if (dialog.open() == Window.OK) {
                IWorkingSet[] workingSets = dialog.getSelection();
                selectWorkingSets(Arrays.asList(workingSets));
            }
        }
    });

    if (selectWorkingSets(workingSets)) {
        addToWorkingSetButton.setSelection(true);
        workingsetLabel.setEnabled(true);
        workingsetComboViewer.getCombo().setEnabled(true);
        newWorkingSetButton.setEnabled(true);
    }

    addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
            workingsetLabel.setEnabled(addToWorkingingSet);
            workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
            newWorkingSetButton.setEnabled(addToWorkingingSet);
            if (addToWorkingingSet) {
                updateConfiguration();
            } else {
                workingSets.clear();
            }
        }
    });

    workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateConfiguration();
        }
    });
}

From source file:com.mentor.nucleus.bp.model.compare.providers.TreeDifferenceLabelProvider.java

License:Open Source License

private ResourceManager getResourceManager() {
    if (resourceManager == null) {
        resourceManager = new LocalResourceManager(JFaceResources.getResources());
    }/*from  w ww. jav a  2  s.c  o  m*/
    return resourceManager;
}

From source file:com.nokia.carbide.remoteconnections.internal.ui.mylyn.AbstractNotificationPopup.java

License:Open Source License

public AbstractNotificationPopup(Display display, int style) {
    super(new Shell(display));
    setShellStyle(style);/*from   www.  ja  v a  2  s. c o m*/

    this.display = display;
    resources = new LocalResourceManager(JFaceResources.getResources());
    initResources();

    closeJob.setSystem(true);
}