@Override public boolean isEmpty() { return topTrim.getChildren().isEmpty(); }
@Override public void appendToGroup(String groupName, IContributionItem item) { List<MToolBar> toolBars = modelService.findElements(window, groupName, MToolBar.class); if (toolBars.size() == 1) { MToolBar el = toolBars.get(0); MTrimBar trimBar = getTrim(el); int index = trimBar.getChildren().indexOf(el); index = index + 1 < trimBar.getChildren().size() ? index : -1; add(trimBar, index, item); } add(topTrim, -1, item); }
/** * @param element * the trimBar to be cleaned up */ protected void cleanUp(MTrimBar element) { for (MTrimElement child : element.getPendingCleanup()) { element.getChildren().remove(child); } element.getPendingCleanup().clear(); } }
private static void cleanUpTrimBar(MTrimBar element) { for (MTrimElement child : element.getPendingCleanup()) { element.getChildren().remove(child); } element.getPendingCleanup().clear(); }
@Override public void insertAfter(String id, IContributionItem item) { MToolBar afterElement = getToolBar(id); if (afterElement == null || getTrim(afterElement) == null) { return; } MTrimBar trimBar = getTrim(afterElement); int index = trimBar.getChildren().indexOf(afterElement); index = index + 1 < trimBar.getChildren().size() ? index + 1 : -1; add(trimBar, index, item); }
private void dock(MUIElement dragElement, MUIElement insertBefore) { dragElement.setToBeRendered(false); dragElement.getParent().getChildren().remove(dragElement); dragElement.setVisible(true); if (insertBefore == null) { trimBar.getChildren().add((MTrimElement) dragElement); } else { int dropIndex = trimBar.getChildren().indexOf(insertBefore); trimBar.getChildren().add(dropIndex, (MTrimElement) dragElement); } dragElement.setToBeRendered(true); Control trimCtrl = (Control) dragElement.getWidget(); trimCtrl.setBackground(trimCtrl.getDisplay().getSystemColor(SWT.COLOR_GREEN)); }
private void dock(MUIElement dragElement, MUIElement insertBefore) { dragElement.setToBeRendered(false); dragElement.getParent().getChildren().remove(dragElement); dragElement.setVisible(true); if (insertBefore == null) { trimBar.getChildren().add((MTrimElement) dragElement); } else { int dropIndex = trimBar.getChildren().indexOf(insertBefore); trimBar.getChildren().add(dropIndex, (MTrimElement) dragElement); } dragElement.setToBeRendered(true); Control trimCtrl = (Control) dragElement.getWidget(); if (trimCtrl != null) { trimCtrl.setBackground(trimCtrl.getDisplay().getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW)); } }
/** * @param element * the trimBar to be cleaned up */ protected void cleanUp(MTrimBar element) { IRendererFactory rendererFactory = context.get(IRendererFactory.class); for (MTrimElement child : element.getPendingCleanup()) { element.getChildren().remove(child); if (child instanceof ToolBarImpl) { ToolBarImpl tb = (ToolBarImpl) child; releaseToolbar(rendererFactory, tb); } } element.getPendingCleanup().clear(); List<MTrimElement> children = element.getChildren(); for (MTrimElement mTrimElement : children) { if (mTrimElement instanceof ToolBarImpl) { ToolBarImpl tb = (ToolBarImpl) mTrimElement; releaseToolbar(rendererFactory, tb); } } }
@Override public void insertBefore(String id, IContributionItem item) { MToolBar beforeElement = getToolBar(id); if (beforeElement == null || getTrim(beforeElement) == null) { return; } MTrimBar trimBar = getTrim(beforeElement); int index = trimBar.getChildren().indexOf(beforeElement); add(trimBar, index, item); }
@Override public void prependToGroup(String groupName, IContributionItem item) { MUIElement gnElement = modelService.find(groupName, window); if (gnElement instanceof MToolBar) { MTrimBar trimBar = getTrim((MTrimElement) gnElement); int index = trimBar.getChildren().indexOf(gnElement); add(trimBar, index, item); } add(topTrim, -1, item); }
@Override public boolean track(MUIElement dragElement, DnDInfo info) { SideValue curSide = getDropSide(info); if (side != curSide) { return false; } MUIElement insertBefore = getInsertionElement(dragElement, info); // Check for no-ops MUIElement curParent = dragElement.getParent(); List<MTrimElement> trimKids = trimBar.getChildren(); boolean sameParent = curParent == trimBar; boolean alreadyThere = false; if (sameParent) { if (insertBefore == null) { alreadyThere = trimKids.get(trimKids.size() - 1) == dragElement; } else { alreadyThere = insertBefore == dragElement; // Reflexive if (!alreadyThere) { alreadyThere = trimKids.indexOf(dragElement) == (trimKids.indexOf(insertBefore) - 1); } } } if (!sameParent || !alreadyThere) { dock(dragElement, insertBefore); } return true; }
@Override public boolean track(MUIElement dragElement, DnDInfo info) { SideValue curSide = getDropSide(info); if (side != curSide) return false; MUIElement insertBefore = getInsertionElement(dragElement, info); // Check for no-ops MUIElement curParent = dragElement.getParent(); List<MTrimElement> trimKids = trimBar.getChildren(); boolean sameParent = curParent == trimBar; boolean alreadyThere = false; if (sameParent) { if (insertBefore == null) { alreadyThere = trimKids.get(trimKids.size() - 1) == dragElement; } else { alreadyThere = insertBefore == dragElement; // Reflexive if (!alreadyThere) { alreadyThere = trimKids.indexOf(dragElement) == (trimKids.indexOf(insertBefore) - 1); } } } if (!sameParent || !alreadyThere) { dock(dragElement, insertBefore); } return true; }
private MToolControl addTrimElement(MTrimBar bottomTrim, IConfigurationElement ice, String id, boolean isBefore, String relTo, String classSpec) { // is it already in the trim ? MUIElement existingTrim = modelService.find(id, bottomTrim); if (existingTrim != null) { iceMap.put((MToolControl) existingTrim, ice); return (MToolControl) existingTrim; } // Ok, create one but only if we can site it correctly int insertIndex = bottomTrim.getChildren().size(); if (relTo != null) { MUIElement foundRel = modelService.find(relTo, bottomTrim); if (foundRel == null) return null; insertIndex = bottomTrim.getChildren().indexOf(foundRel); if (!isBefore) insertIndex++; } MToolControl newTrimElement = modelService.createModelElement(MToolControl.class); newTrimElement.setElementId(id); newTrimElement.setToBeRendered(classSpec != null); if (classSpec != null) { newTrimElement .setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.LegacyTrim"); //$NON-NLS-1$ } newTrimElement.setContributorURI(URIHelper.constructPlatformURI(ice.getContributor())); iceMap.put(newTrimElement, ice); bottomTrim.getChildren().add(insertIndex, newTrimElement); return newTrimElement; }
private void createTrim(MUIElement element, MPerspective perspective) { if (!(window instanceof MTrimmedWindow)) { return; } String trimStr = perspective.getPersistedState().get("trims"); //$NON-NLS-1$ MTrimmedWindow win = (MTrimmedWindow) window; // Is there already a TrimControl there ? String trimId = element.getElementId() + getMinimizedElementSuffix(perspective); MToolControl trimStack = (MToolControl) modelService.find(trimId, window); if (trimStack == null) { trimStack = MenuFactoryImpl.eINSTANCE.createToolControl(); trimStack.setElementId(trimId); trimStack.setContributionURI(TrimStack.CONTRIBUTION_URI); trimStack.getTags().add("TrimStack"); //$NON-NLS-1$ // Check if we have a cached location MTrimBar bar = getBarForElement(element, win, trimStr); int index = getIndex(element, trimStr); if (index == -1 || index >= bar.getChildren().size()) bar.getChildren().add(trimStack); else bar.getChildren().add(index, trimStack); bar.setVisible(true); } else { // get the parent trim bar, see bug 320756 MUIElement parent = trimStack.getParent(); parent.setVisible(true); trimStack.setToBeRendered(true); } }
private String getStackTrimLoc(MPartStack stack, String perspIdStr) { MWindow stackWin = modelService.getTopLevelWindowFor(stack);// getContainingWindow(stack); MUIElement tcElement = modelService.find(stack.getElementId() + perspIdStr, stackWin); if (tcElement == null) return ""; //$NON-NLS-1$ MTrimBar bar = (MTrimBar) ((MUIElement) tcElement.getParent()); int sideVal = bar.getSide().getValue(); int index = bar.getChildren().indexOf(tcElement); return stack.getElementId() + ' ' + sideVal + ' ' + index + "#"; //$NON-NLS-1$ } };
public static boolean processAddition(final MTrimBar trimBar, MTrimContribution contribution, List<MTrimElement> contributions, HashSet<String> existingToolbarIds) { int idx = getIndex(trimBar, contribution.getPositionInParent()); if (idx == -1) { return false; } for (MTrimElement item : contribution.getChildren()) { if (item instanceof MToolBar && existingToolbarIds.contains(item.getElementId())) { // skip this, it's already there continue; } MTrimElement copy = (MTrimElement) EcoreUtil.copy((EObject) item); if (DEBUG) { trace("addTrimContribution " + copy, trimBar.getWidget(), trimBar); //$NON-NLS-1$ } trimBar.getChildren().add(idx++, copy); contributions.add(copy); if (copy instanceof MToolBar && copy.getElementId() != null) { existingToolbarIds.add(copy.getElementId()); } } return true; }
private String getStackTrimLoc(MPartStack stack, MPerspective perspective) { MWindow stackWin = modelService.getTopLevelWindowFor(stack); MUIElement tcElement = modelService.find(TrimStackIdHelper.createTrimStackId(stack, perspective, stackWin), stackWin); if (tcElement == null) { return ""; //$NON-NLS-1$ } MTrimBar bar = (MTrimBar) ((MUIElement) tcElement.getParent()); int sideVal = bar.getSide().getValue(); int index = bar.getChildren().indexOf(tcElement); return stack.getElementId() + ' ' + sideVal + ' ' + index + "#"; //$NON-NLS-1$ }
statusLine.setContributionURI(WorkbenchWindow.TRIM_CONTRIBUTION_URI); statusLine.getTags().add(TrimBarLayout.SPACER); statusBar.getChildren().add(statusLine);
/** * Install the Intro Launch Bar into the provided window. * * @param window * the window to host the launch bar * @param modelRoot * the current intro configuration, with pages * @param element * the launch bar configuration * @return the launch bar instance */ public static IntroLaunchBar create(IWorkbenchWindow window, IntroModelRoot modelRoot, IntroLaunchBarElement element) { EModelService modelService = window.getService(EModelService.class); MTrimmedWindow trimmedWindow = window.getService(MTrimmedWindow.class); MToolControl trimControl = modelService.createModelElement(MToolControl.class); trimControl.setElementId(LAUNCHBAR_ID); trimControl.setContributionURI(BUNDLECLASS_URI); // Must record sufficient information so as to be able to obtain the // launch configuration on workspace restart trimControl.getPersistedState().put(INTRO_CONFIG_ID, modelRoot.getId()); trimControl.getPersistedState().put(LAST_PAGE_ID, modelRoot.getCurrentPageId()); trimControl.getTags().add(IPresentationEngine.DRAGGABLE); MTrimBar bar = modelService.getTrim(trimmedWindow, determineLocation(element)); bar.getChildren().add(trimControl); // should now be rendered return (IntroLaunchBar) trimControl.getObject(); }
@Override public void doProcessContent(MTrimBar element) { WTrimBar<N> trimBar = getWidget(element); if( trimBar == null ) { getLogger().error("Could not find widget for '"+element+"'"); //$NON-NLS-1$ //$NON-NLS-2$ return; } for (MTrimElement e : element.getChildren()) { if (e.isToBeRendered()) { WLayoutedWidget<MTrimElement> trimElementWidget = engineCreateWidget(e); if (trimElementWidget != null && isChildRenderedAndVisible(e)) { trimBar.addChild(trimElementWidget); } } } }