/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#createWidget * (org.eclipse.e4.ui.model.application.ui.MUIElement, java.lang.Object) */ @Override public Object createWidget(final MUIElement element, Object parent) { if (!(element instanceof MToolBar) || !(parent instanceof Composite)) return null; final MToolBar toolbarModel = (MToolBar) element; ToolBar newTB = createToolbar(toolbarModel, (Composite) parent); bindWidget(element, newTB); processContribution(toolbarModel, toolbarModel.getElementId()); Control renderedCtrl = newTB; MUIElement parentElement = element.getParent(); if (parentElement instanceof MTrimBar) { element.getTags().add("Draggable"); // $NON-NLS-1$ setCSSInfo(element, newTB); boolean vertical = false; MTrimBar bar = (MTrimBar) parentElement; vertical = bar.getSide() == SideValue.LEFT || bar.getSide() == SideValue.RIGHT; IEclipseContext parentContext = getContextForParent(element); CSSRenderingUtils cssUtils = parentContext.get(CSSRenderingUtils.class); if (cssUtils != null) { renderedCtrl = (Composite) cssUtils.frameMeIfPossible(newTB, null, vertical, true); } } return renderedCtrl; }
public static boolean processAddition( final MToolBar toolBarModel, MToolBarContribution toolBarContribution, List<MToolBarElement> contributions, HashSet<String> existingSeparatorNames) { int idx = getIndex(toolBarModel, toolBarContribution.getPositionInParent()); if (idx == -1) { return false; } for (MToolBarElement item : toolBarContribution.getChildren()) { if (item instanceof MToolBarSeparator && existingSeparatorNames.contains(item.getElementId())) { // skip this, it's already there continue; } MToolBarElement copy = (MToolBarElement) EcoreUtil.copy((EObject) item); if (DEBUG) { trace( "addToolBarContribution " + copy, toolBarModel.getWidget(), toolBarModel); //$NON-NLS-1$ } toolBarModel.getChildren().add(idx++, copy); contributions.add(copy); if (copy instanceof MToolBarSeparator && copy.getElementId() != null) { existingSeparatorNames.add(copy.getElementId()); } } return true; }
/* * (non-Javadoc) * * @see * org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer#postProcess * (org.eclipse.e4.ui.model.application.ui.MUIElement) */ @Override public void postProcess(MUIElement element) { if (element instanceof MToolBar) { MToolBar toolbarModel = (MToolBar) element; if (toolbarModel.getTransientData().containsKey(POST_PROCESSING_FUNCTION)) { Object obj = toolbarModel.getTransientData().get(POST_PROCESSING_FUNCTION); if (obj instanceof IContextFunction) { IContextFunction func = (IContextFunction) obj; final IEclipseContext ctx = getContext(toolbarModel); toolbarModel.getTransientData().put(POST_PROCESSING_DISPOSE, func.compute(ctx, null)); } } } }
@Override public void processContents(MElementContainer<MUIElement> container) { super.processContents(container); IEclipseContext ctx = getContext(container); ExpressionContext eContext = new ExpressionContext(ctx); ArrayList<MToolBarContribution> toContribute = new ArrayList<MToolBarContribution>(); MElementContainer<?> toolbarObj = container; MToolBar toolbarModel = (MToolBar) toolbarObj; ContributionsAnalyzer.gatherToolBarContributions( toolbarModel, application.getToolBarContributions(), toolbarModel.getElementId(), toContribute, eContext); addToolBarContributions(toolbarModel, toContribute, ctx, eContext, pendingCleanup); }
public static void addToolBarContributions( final MToolBar toolbarModel, ArrayList<MToolBarContribution> toContribute, IEclipseContext ctx, final ExpressionContext eContext, HashMap<MToolBar, ArrayList<ArrayList<MToolBarElement>>> pendingCleanup) { HashSet<String> existingSeparatorNames = new HashSet<String>(); for (MToolBarElement child : toolbarModel.getChildren()) { String elementId = child.getElementId(); if (child instanceof MToolBarSeparator && elementId != null) { existingSeparatorNames.add(elementId); } } boolean done = toContribute.size() == 0; while (!done) { ArrayList<MToolBarContribution> curList = new ArrayList<MToolBarContribution>(toContribute); int retryCount = toContribute.size(); toContribute.clear(); for (final MToolBarContribution contribution : curList) { final ArrayList<MToolBarElement> toRemove = new ArrayList<MToolBarElement>(); if (!ContributionsAnalyzer.processAddition( toolbarModel, contribution, toRemove, existingSeparatorNames)) { toContribute.add(contribution); } else { if (contribution.getVisibleWhen() != null) { ctx.runAndTrack( new RunAndTrack() { @Override public boolean changed(IEclipseContext context) { if (!toolbarModel.isToBeRendered() || !toolbarModel.isVisible() || toolbarModel.getWidget() == null) { return false; } boolean rc = ContributionsAnalyzer.isVisible(contribution, eContext); for (MToolBarElement child : toRemove) { child.setToBeRendered(rc); } return true; } }); } ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup.get(toolbarModel); if (lists == null) { lists = new ArrayList<ArrayList<MToolBarElement>>(); pendingCleanup.put(toolbarModel, lists); } lists.add(toRemove); } } // We're done if the retryList is now empty (everything done) or // if the list hasn't changed at all (no hope) done = (toContribute.size() == 0) || (toContribute.size() == retryCount); } }
@Override public void disposeWidget(MUIElement element) { if (element instanceof MPart) { MPart part = (MPart) element; MToolBar toolBar = part.getToolbar(); if (toolBar != null) { Widget widget = (Widget) toolBar.getWidget(); if (widget != null) { unbindWidget(toolBar); widget.dispose(); } } for (MMenu menu : part.getMenus()) { engine.removeGui(menu); } } super.disposeWidget(element); }
private void restorePersistedState(MApplication application, MPart part) { final Map<String, String> persistedState = application.getPersistedState(); showSuppressedLines = toolbox.parseBoolean(persistedState.get(IPersistenceKey.TERMINAL_SUPPRESS_LINES)); showGrblStateLines = toolbox.parseBoolean(persistedState.get(IPersistenceKey.TERMINAL_GRBL_STATE)); showGcodeModeLines = toolbox.parseBoolean(persistedState.get(IPersistenceKey.TERMINAL_GRBL_MODES)); // set the state of the direct menu items according to persisted state // find the two direct menu items final MToolBar toolbar = part.getToolbar(); List<MToolBarElement> toolBarChildren = toolbar.getChildren(); for (MToolBarElement child : toolBarChildren) { if (child instanceof MHandledToolItem && child .getElementId() .equals("de.jungierek.grblrunner.handledtoolitem.terminal.togglesuppresslines")) { LOG.debug( "restorePersistedState: child=" + child.getElementId() + " class=" + child.getClass()); MMenu menu = ((MHandledToolItem) child).getMenu(); if (menu != null) { List<MMenuElement> items = menu.getChildren(); for (MMenuElement item : items) { LOG.debug( "restorePersistedState: item=" + item.getElementId() + "class=" + child.getClass()); switch (item.getElementId()) { case "de.jungierek.grblrunner.directmenuitem.togglesuppresslines.grblstate": ((MMenuItem) item).setSelected(showGrblStateLines); break; case "de.jungierek.grblrunner.directmenuitem.togglesuppresslines.gcodestate": ((MMenuItem) item).setSelected(showGcodeModeLines); break; default: break; } } } } } }
protected void cleanUp(MToolBar element) { ArrayList<ArrayList<MToolBarElement>> lists = pendingCleanup.remove(element); if (lists == null) { return; } for (ArrayList<MToolBarElement> list : lists) { for (MToolBarElement child : list) { element.getChildren().remove(child); } } }
private IEclipseContext getStaticContext() { if (infoContext == null) { IEclipseContext parentContext = renderer.getContext(toolbarModel); if (parentContext != null) { infoContext = parentContext.createChild(STATIC_CONTEXT); } else { infoContext = EclipseContextFactory.create(STATIC_CONTEXT); } ContributionsAnalyzer.populateModelInterfaces( toolbarModel, infoContext, toolbarModel.getClass().getInterfaces()); infoContext.set(ToolBarRenderer.class, renderer); } return infoContext; }
public void reconcileManagerToModel(IToolBarManager menuManager, MToolBar toolBar) { List<MToolBarElement> modelChildren = toolBar.getChildren(); HashSet<MOpaqueToolItem> oldModelItems = new HashSet<MOpaqueToolItem>(); for (MToolBarElement itemModel : modelChildren) { if (itemModel instanceof MOpaqueToolItem) { oldModelItems.add((MOpaqueToolItem) itemModel); } } IContributionItem[] items = menuManager.getItems(); for (int src = 0, dest = 0; src < items.length; src++, dest++) { IContributionItem item = items[src]; MToolBarElement element = getToolElement(item); if (element == null) { MOpaqueToolItem legacyItem = MenuFactoryImpl.eINSTANCE.createOpaqueToolItem(); legacyItem.setElementId(item.getId()); legacyItem.setVisible(item.isVisible()); legacyItem.setOpaqueItem(item); linkModelToContribution(legacyItem, item); modelChildren.add(dest, legacyItem); } else if (element instanceof MOpaqueToolItem) { MOpaqueToolItem legacyItem = (MOpaqueToolItem) element; oldModelItems.remove(legacyItem); if (modelChildren.size() > dest) { if (modelChildren.get(dest) != legacyItem) { modelChildren.remove(legacyItem); modelChildren.add(dest, legacyItem); } } else { modelChildren.add(legacyItem); } } } if (!oldModelItems.isEmpty()) { modelChildren.removeAll(oldModelItems); for (MOpaqueToolItem model : oldModelItems) { clearModelToContribution(model, (IContributionItem) model.getOpaqueItem()); } } }
public boolean mergeIntoModel() { int idx = getIndex(toolbarModel, toolbarContribution.getPositionInParent()); if (idx == -1) { return false; } final List<MToolBarElement> copyElements = new ArrayList<MToolBarElement>(); for (MToolBarElement item : toolbarContribution.getChildren()) { MToolBarElement copy = (MToolBarElement) EcoreUtil.copy((EObject) item); copyElements.add(copy); } for (MToolBarElement copy : copyElements) { // if a visibleWhen clause is defined, the item should not be // visible until the clause has been evaluated and returned 'true' copy.setVisible(!anyVisibleWhen()); generatedElements.add(copy); toolbarModel.getChildren().add(idx++, copy); } return true; }