private void resetPerspectiveModel( MPerspective persp, MWindow window, boolean removeSharedPlaceholders) { if (persp == null) { return; } if (removeSharedPlaceholders) { // Remove any views (Placeholders) from the shared area EPartService ps = window.getContext().get(EPartService.class); List<MArea> areas = findElements(window, null, MArea.class, null); if (areas.size() == 1) { MArea area = areas.get(0); // Strip out the placeholders in visible stacks List<MPlaceholder> phList = findElements(area, null, MPlaceholder.class, null); for (MPlaceholder ph : phList) { ps.hidePart((MPart) ph.getRef()); ph.getParent().getChildren().remove(ph); } // Prevent shared stacks ids from clashing with the ones in the perspective List<MPartStack> stacks = findElements(area, null, MPartStack.class, null); for (MPartStack stack : stacks) { String generatedId = "PartStack@" + Integer.toHexString(stack.hashCode()); // $NON-NLS-1$ stack.setElementId(generatedId); } // Also remove any min/max tags on the area (or its placeholder) MUIElement areaPresentation = area; if (area.getCurSharedRef() != null) { areaPresentation = area.getCurSharedRef(); } areaPresentation.getTags().remove(IPresentationEngine.MAXIMIZED); areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED); areaPresentation.getTags().remove(IPresentationEngine.MINIMIZED_BY_ZOOM); } } // Remove any minimized stacks for this perspective List<MTrimBar> bars = findElements(window, null, MTrimBar.class, null); List<MToolControl> toRemove = new ArrayList<>(); for (MTrimBar bar : bars) { for (MUIElement barKid : bar.getChildren()) { if (!(barKid instanceof MToolControl)) { continue; } String id = barKid.getElementId(); if (id != null && id.contains(persp.getElementId())) { toRemove.add((MToolControl) barKid); } } } for (MToolControl toolControl : toRemove) { // Close any open fast view toolControl.setToBeRendered(false); toolControl.getParent().getChildren().remove(toolControl); } }
@PostConstruct void createWidget(Composite parent, MToolControl toolControl) { psME = toolControl; MUIElement meParent = psME.getParent(); int orientation = SWT.HORIZONTAL; if (meParent instanceof MTrimBar) { MTrimBar bar = (MTrimBar) meParent; if (bar.getSide() == SideValue.RIGHT || bar.getSide() == SideValue.LEFT) orientation = SWT.VERTICAL; } comp = new Composite(parent, SWT.NONE); RowLayout layout = new RowLayout(SWT.HORIZONTAL); layout.marginLeft = layout.marginRight = 8; layout.marginBottom = 4; layout.marginTop = 6; comp.setLayout(layout); psTB = new ToolBar(comp, SWT.FLAT | SWT.WRAP | SWT.RIGHT + orientation); comp.addPaintListener( new PaintListener() { public void paintControl(PaintEvent e) { paint(e); } }); toolParent = ((Control) toolControl.getParent().getWidget()); toolParent.addPaintListener( new PaintListener() { public void paintControl(PaintEvent e) { if (borderColor == null) borderColor = e.display.getSystemColor(SWT.COLOR_BLACK); e.gc.setForeground(borderColor); Rectangle bounds = ((Control) e.widget).getBounds(); e.gc.drawLine(0, bounds.height - 1, bounds.width, bounds.height - 1); } }); comp.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { dispose(); } }); psTB.addMenuDetectListener( new MenuDetectListener() { public void menuDetected(MenuDetectEvent e) { ToolBar tb = (ToolBar) e.widget; Point p = new Point(e.x, e.y); p = psTB.getDisplay().map(null, psTB, p); ToolItem item = tb.getItem(p); if (item == null) E4Util.message(" ToolBar menu"); // $NON-NLS-1$ else { MPerspective persp = (MPerspective) item.getData(); if (persp == null) E4Util.message(" Add button Menu"); // $NON-NLS-1$ else openMenuFor(item, persp); } } }); psTB.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent e) { disposeTBImages(); } }); psTB.getAccessible() .addAccessibleListener( new AccessibleAdapter() { public void getName(AccessibleEvent e) { if (0 <= e.childID && e.childID < psTB.getItemCount()) { ToolItem item = psTB.getItem(e.childID); if (item != null) { e.result = item.getToolTipText(); } } } }); hookupDnD(psTB); final ToolItem createItem = new ToolItem(psTB, SWT.PUSH); createItem.setImage(getOpenPerspectiveImage()); createItem.setToolTipText(WorkbenchMessages.OpenPerspectiveDialogAction_tooltip); createItem.addSelectionListener( new SelectionListener() { public void widgetSelected(SelectionEvent e) { selectPerspective(); } public void widgetDefaultSelected(SelectionEvent e) { selectPerspective(); } }); new ToolItem(psTB, SWT.SEPARATOR); MPerspectiveStack stack = getPerspectiveStack(); if (stack != null) { // Create an item for each perspective that should show up for (MPerspective persp : stack.getChildren()) { if (persp.isToBeRendered()) { addPerspectiveItem(persp); } } } }