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

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

Introduction

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

Prototype

@Override
public void setVisible(boolean visible) 

Source Link

Document

The default implementation of this IContributionItem method stores the value in an internal state variable, which is true by default.

Usage

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

License:Open Source License

/**
 * This method goes through the steps of deactivating the current tool option contribution and 
 * activating the new tool option contribution.
 * /* w ww .  ja  v a 2  s  .c  o m*/
 * @param statusLine
 * @param modalToolProxy
 */
private void initToolOptionsContribution(IStatusLineManager statusLine, ToolProxy modalToolProxy) {
    if (statusLine != null) {

        if (preferencesShortcutToolOptions == null || preferencesShortcutToolOptions.isDisposed()) {
            preferencesShortcutToolOptions = new PreferencesShortcutToolOptionsContributionItem();
            statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, preferencesShortcutToolOptions);
            preferencesShortcutToolOptions.setVisible(true);
        }
        preferencesShortcutToolOptions.update(modalToolProxy);

        //TODO, cache contributions instead of destroying them and recreating them

        //remove old tool contribution
        for (ContributionItem contribution : optionsContribution) {
            statusLine.remove(contribution.getId());
        }

        //get the new contributions
        optionsContribution = modalToolProxy.getOptionsContribution();

        //set all new contributions
        for (ContributionItem contribution : optionsContribution) {
            statusLine.appendToGroup(StatusLineManager.BEGIN_GROUP, contribution);
            contribution.setVisible(true);
        }

        statusLine.update(true);
    }
}

From source file:org.eclipse.birt.report.designer.ui.viewer.StaticHTMLViewer.java

License:Open Source License

public Control createUI(Composite parent) {
    if (parent == null) {
        return null;
    }//ww w . ja  v  a 2  s .c o m
    toolkit = new FormToolkit(parent.getDisplay());
    form = toolkit.createForm(parent);

    form.setFont(JFaceResources.getFontRegistry().get(JFaceResources.BANNER_FONT));
    form.setImage(
            StaticHTMLPrviewPlugin.getDefault().getImageRegistry().get(StaticHTMLPrviewPlugin.IMG_FORM_TITLE));

    toolkit.decorateFormHeading(form);
    form.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridLayout layout = new GridLayout();
    layout.horizontalSpacing = layout.verticalSpacing = 0;
    layout.marginWidth = layout.marginHeight = 0;
    form.getBody().setLayout(layout);

    // Re-run the report action
    reRunReportAction = new Action("Re-run the report", //$NON-NLS-1$
            Action.AS_PUSH_BUTTON) {

        public void run() {
            render();
        }
    };
    reRunReportAction.setToolTipText("Re-run the report"); //$NON-NLS-1$
    reRunReportAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_RE_RUN));
    form.getToolBarManager().add(reRunReportAction);

    // paramAction
    paramAction = new Action("Enter parameter", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            render();
        }
    };
    paramAction.setToolTipText("Open Parameters Dialog"); //$NON-NLS-1$
    paramAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_PARAMS));
    form.getToolBarManager().add(paramAction);

    // tocAction
    tocAction = new Action("TOC", Action.AS_RADIO_BUTTON) { //$NON-NLS-1$

        public void run() {
            if (sashForm.getMaximizedControl() != null) {
                sashForm.setMaximizedControl(null);
                setChecked(true);
            } else {
                sashForm.setMaximizedControl(browserContainer);
                setChecked(false);
            }
        }
    };
    tocAction.setToolTipText("Show TOC"); //$NON-NLS-1$
    tocAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_TOC));
    tocAction.setChecked(false);
    form.getToolBarManager().add(tocAction);

    form.getToolBarManager().add(new Separator());

    // navFirstAction
    navFirstAction = new Action("First", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            currentPageNum = 1;
            renderWithoutAskingForParams();
        }
    };
    navFirstAction.setToolTipText("First"); //$NON-NLS-1$
    navFirstAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_NAV_FIRST));
    form.getToolBarManager().add(navFirstAction);

    // navPreAction
    navPreAction = new Action("Previous", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            if (currentPageNum > 1) {
                currentPageNum--;
                renderWithoutAskingForParams();
            }
        }
    };

    navPreAction.setToolTipText("Previous"); //$NON-NLS-1$
    navPreAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_NAV_PRE));
    form.getToolBarManager().add(navPreAction);

    // navNextAction
    navNextAction = new Action("Next", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            if (currentPageNum < totalPageNum) {
                currentPageNum++;
                renderWithoutAskingForParams();
            }
        }
    };

    navNextAction.setToolTipText("Next"); //$NON-NLS-1$
    navNextAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_NAV_NEXT));
    form.getToolBarManager().add(navNextAction);

    // navLastAction
    navLastAction = new Action("Last", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            currentPageNum = totalPageNum;
            renderWithoutAskingForParams();
        }
    };

    navLastAction.setToolTipText("Last"); //$NON-NLS-1$
    navLastAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_NAV_LAST));
    form.getToolBarManager().add(navLastAction);

    form.getToolBarManager().add(new Separator());

    ContributionItem inputText = new ContributionItem() {

        public void fill(ToolBar parent, int index) {
            ToolItem toolitem = new ToolItem(parent, SWT.SEPARATOR, index);
            Composite container = new Composite(parent, SWT.NULL);
            // container.setFont( JFaceResources.getFontRegistry( )
            // .get( JFaceResources.TEXT_FONT ) );
            GridLayout layout = new GridLayout();
            layout.numColumns = 2;
            layout.marginWidth = layout.marginHeight = 1;
            container.setLayout(layout);
            Label label = new Label(container, SWT.NULL);
            label.setFont(container.getFont());
            label.setText("Go to page:"); //$NON-NLS-1$

            goPageInput = toolkit.createText(container, "", SWT.BORDER); //$NON-NLS-1$
            goPageInput.setFont(container.getFont());

            goPageInput.setLayoutData(new GridData(GridData.FILL_BOTH));
            goPageInput.addKeyListener(new KeyAdapter() {

                public void keyPressed(KeyEvent e) {
                    if (e.character == SWT.LF || e.character == SWT.CR) {
                        if (navGoAction.isEnabled()) {
                            currentPageNum = Long.parseLong(goPageInput.getText());
                            renderWithoutAskingForParams();
                        }
                    }
                }

            });

            goPageInput.addModifyListener(new ModifyListener() {

                /**
                 * last valid status
                 */
                private boolean isValid = true;

                public void modifyText(ModifyEvent e) {
                    if (!"".equals(goPageInput.getText())) //$NON-NLS-1$
                    {
                        try {
                            long page = Long.parseLong(goPageInput.getText());
                            if (page > 0 && page <= totalPageNum) {
                                if (!isValid) {
                                    form.setMessage(null);
                                    isValid = true;
                                }
                                navGoAction.setEnabled(true);
                            } else {
                                form.setMessage("Page Number '" //$NON-NLS-1$
                                        + page + "' is invalid!", //$NON-NLS-1$
                                        IMessageProvider.ERROR);
                                isValid = false;
                                navGoAction.setEnabled(false);
                            }
                        } catch (NumberFormatException e1) {
                            form.setMessage("Page Number '" //$NON-NLS-1$
                                    + goPageInput.getText() + "' is invalid!", //$NON-NLS-1$
                                    IMessageProvider.ERROR);
                            isValid = false;
                            navGoAction.setEnabled(false);
                        }
                    } else {
                        form.setMessage(null);
                        isValid = true;
                    }
                }
            });

            toolitem.setWidth(label.computeSize(SWT.DEFAULT, SWT.DEFAULT).x + 40);
            toolitem.setControl(container);
        }

    };
    inputText.setVisible(true);
    form.getToolBarManager().add(inputText);

    // navSelectAction
    navGoAction = new Action("Go to page", Action.AS_PUSH_BUTTON) { //$NON-NLS-1$

        public void run() {
            if (goPageInput != null && !goPageInput.isDisposed()) {
                currentPageNum = Long.parseLong(goPageInput.getText());
                // render( );
                renderWithoutAskingForParams();
            }
        }
    };

    navGoAction.setToolTipText("Go to page"); //$NON-NLS-1$
    navGoAction.setImageDescriptor(StaticHTMLPrviewPlugin.getDefault().getImageRegistry()
            .getDescriptor(StaticHTMLPrviewPlugin.IMG_NAV_GO));
    form.getToolBarManager().add(navGoAction);

    form.updateToolBar();

    sashForm = new SashForm(form.getBody(), SWT.NULL);
    sashForm.setLayoutData(new GridData(GridData.FILL_BOTH));
    sashForm.setLayout(layout);
    toolkit.adapt(sashForm, false, false);

    createTOCSection(sashForm);
    createBrowserSection(sashForm);

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

    toolkit.paintBordersFor(form.getBody());

    return this.form;
}