Example usage for org.eclipse.jface.action ContributionItem setId

List of usage examples for org.eclipse.jface.action ContributionItem setId

Introduction

In this page you can find the example usage for org.eclipse.jface.action ContributionItem setId.

Prototype

public void setId(String itemId) 

Source Link

Document

The ID for this contribution item.

Usage

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

License:Open Source License

/**
 * Returns proxy/*w  w w. j  av a2  s. c  om*/
 * 
 * @return
 */
public Tool getTool() {
    if (tool == null) {
        Display display = Display.getCurrent();
        if (display == null)
            display = Display.getDefault();
        final Display finalDisplay = display;
        Runnable runnable = new Runnable() {
            public void run() {
                BusyIndicator.showWhile(finalDisplay, new Runnable() {
                    public void run() {
                        String klassName = element.getAttribute("class"); //$NON-NLS-1$
                        if (klassName != null) {
                            try {
                                Object o = element.createExecutableExtension("class"); //$NON-NLS-1$
                                tool = (Tool) o;

                                if (tool instanceof AbstractTool) {
                                    ((AbstractTool) tool).init(element);
                                }

                                /* Tool cursors framework */
                                if (tool instanceof ModalTool) {
                                    if (defaultCursorID != null) {
                                        ((ModalTool) tool).setCursorID(defaultCursorID);
                                        tool.setProperty(ToolConstants.DEFAULT_CURSOR_ID_KEY, defaultCursorID);
                                    }
                                }

                                tool.setContext(toolContext);
                                tool.setEnabled(isEnabled());

                                if (tool instanceof ModalTool) {
                                    IMapEditorSelectionProvider selectionProvider = getSelectionProvider();
                                    ModalTool modalTool = (ModalTool) tool;
                                    modalTool.setSelectionProvider(selectionProvider);
                                }

                            } catch (CoreException e) {
                                ProjectUIPlugin.log("Error loading tool", e); //$NON-NLS-1$
                            }
                        }

                        IConfigurationElement[] toolElementChildren = element.getChildren();

                        for (IConfigurationElement toolElement : toolElementChildren) {

                            if (toolElement.getAttribute("class") != null) {
                                try {
                                    String contributionId = toolElement.getAttribute("id");

                                    Object optionsContribution = toolElement.createExecutableExtension("class");
                                    ContributionItem contributionItem = (ContributionItem) optionsContribution;
                                    contributionItem.setId(contributionId);

                                    addOptionsContribution((ContributionItem) optionsContribution);
                                } catch (CoreException e) {
                                    // TODO Auto-generated catch block
                                    e.printStackTrace();
                                }
                            }

                        }

                    }
                });
            }
        };

        PlatformGIS.syncInDisplayThread(runnable);
    }
    return tool;
}