Example usage for org.eclipse.jface.action ToolBarManager insert

List of usage examples for org.eclipse.jface.action ToolBarManager insert

Introduction

In this page you can find the example usage for org.eclipse.jface.action ToolBarManager insert.

Prototype

public void insert(int index, IContributionItem item) 

Source Link

Document

Insert the item at the given index.

Usage

From source file:de.loskutov.anyedit.actions.internal.StartupHelper.java

License:Open Source License

private static int insert(IDirtyWorkaround myAction, ToolBarManager manager, int controlIdx) {
    IContributionItem item;/*  w  ww .ja  va2s  .  c  o m*/
    // get "file->save" action
    item = manager.find(myAction.getId());
    if (item != null) {
        // copy references to opened editor/part
        myAction.copyStateAndDispose(item);
        if (controlIdx < 0) {
            // get/remember position
            IContributionItem[] items = manager.getItems();
            for (int i = 0; i < items.length; i++) {
                if (items[i].isSeparator() || items[i] instanceof ActionContributionItem) {
                    controlIdx++;
                    if (items[i] == item) {
                        break;
                    }
                }
            }
        }
        // clean old one
        manager.remove(item);
        item = new ActionContributionItem(myAction);
        manager.insert(controlIdx, item);
        // refresh menu gui
        manager.update(true);
    } else if (controlIdx >= 0) {
        item = new ActionContributionItem(myAction);
        manager.insert(controlIdx, item);
        // refresh menu gui
        manager.update(true);
    }
    return controlIdx;
}

From source file:de.loskutov.bco.compare.BytecodeCompare.java

License:Open Source License

/**
 * @see org.eclipse.compare.CompareEditorInput#createContents(org.eclipse.swt.widgets.Composite)
 *///from w  w w . j  a va 2 s . co  m
@Override
public Control createContents(final Composite parent) {
    Object obj = parent.getData();
    if (obj == null) {
        obj = parent.getParent().getData();
    }
    // dirty hook on this place to get reference to editor
    // CompareEditor extends EditorPart implements IReusableEditor
    if (obj instanceof IReusableEditor) {
        myEditor = (IReusableEditor) obj;
    }

    Control control = super.createContents(parent);

    CompareViewerSwitchingPane inputPane = getInputPane();
    if (inputPane != null) {
        ToolBarManager toolBarManager2 = CompareViewerPane.getToolBarManager(inputPane);
        if (toolBarManager2 == null) {
            return control;
        }
        boolean separatorExist = false;
        if (toolBarManager2.find(hideLineInfoAction.getId()) == null) {
            if (!separatorExist) {
                separatorExist = true;
                toolBarManager2.insert(0, new Separator("bco")); //$NON-NLS-1$
            }
            toolBarManager2.insertBefore("bco", hideLineInfoAction); //$NON-NLS-1$
            //                toolBarManager2.update(true);
        }
        if (toolBarManager2.find(hideLocalsAction.getId()) == null) {
            if (!separatorExist) {
                separatorExist = true;
                toolBarManager2.insert(0, new Separator("bco")); //$NON-NLS-1$
            }
            toolBarManager2.insertBefore("bco", hideLocalsAction); //$NON-NLS-1$
            //                toolBarManager2.update(true);
        }

        if (toolBarManager2.find(hideStackMapAction.getId()) == null) {
            if (!separatorExist) {
                separatorExist = true;
                toolBarManager2.insert(0, new Separator("bco")); //$NON-NLS-1$
            }
            toolBarManager2.insertBefore("bco", hideStackMapAction); //$NON-NLS-1$
            //                toolBarManager2.update(true);
        }
        if (toolBarManager2.find(expandStackMapAction.getId()) == null) {
            if (!separatorExist) {
                separatorExist = true;
                toolBarManager2.insert(0, new Separator("bco")); //$NON-NLS-1$
            }
            toolBarManager2.insertBefore("bco", expandStackMapAction); //$NON-NLS-1$
            //                toolBarManager2.update(true);
        }

        if (toolBarManager2.find(toggleAsmifierModeAction.getId()) == null) {
            if (!separatorExist) {
                toolBarManager2.insert(0, new Separator("bco")); //$NON-NLS-1$
                separatorExist = true;
            }
            toolBarManager2.insertBefore("bco", toggleAsmifierModeAction); //$NON-NLS-1$
            //                toolBarManager2.update(true);
        }
        try {
            toolBarManager2.update(true);
            toolBarManager2.getControl().getParent().layout(true);
            toolBarManager2.getControl().getParent().update();
        } catch (NullPointerException e) {
            // ignore, i'm just curios why we need this code in 3.2 and expect
            // some unwanted side effects...
        }
    }
    return control;
}

From source file:net.yatomiya.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.java

License:Open Source License

private void addToManager(ToolBarManager parentManager, MToolBarElement model, IContributionItem ci) {
    MElementContainer<MUIElement> parent = model.getParent();
    // technically this shouldn't happen
    if (parent == null) {
        parentManager.add(ci);/* w w w . ja  v a2  s  .c  om*/
    } else {
        int index = parent.getChildren().indexOf(model);
        // shouldn't be -1, but better safe than sorry
        if (index > parentManager.getSize() || index == -1) {
            parentManager.add(ci);
        } else {
            parentManager.insert(index, ci);
        }
    }
}

From source file:org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.java

License:Open Source License

/**
 * @param parentManager/*from  w w  w .j  ava 2  s  . com*/
 * @param itemModel
 * @param ci
 */
private void addToManager(ToolBarManager parentManager, MToolBarElement model, IContributionItem ci) {
    MElementContainer<MUIElement> parent = model.getParent();
    // technically this shouldn't happen
    if (parent == null) {
        parentManager.add(ci);
    } else {
        int index = parent.getChildren().indexOf(model);
        // shouldn't be -1, but better safe than sorry
        if (index > parentManager.getSize() || index == -1) {
            parentManager.add(ci);
        } else {
            parentManager.insert(index, ci);
        }
    }
}