@Override public void removePerspectiveModel(MPerspective persp, MWindow window) { // pick a new perspective to become active (if any) MUIElement psElement = persp.getParent(); MPerspectiveStack ps = (MPerspectiveStack) psElement; boolean foundNewSelection = false; if (ps.getSelectedElement() == persp) { for (MPerspective p : ps.getChildren()) { if (p != persp && p.isToBeRendered()) { ps.setSelectedElement(p); foundNewSelection = true; break; } } if (!foundNewSelection) { ps.setSelectedElement(null); } } // Remove transient elements (minimized stacks, detached windows) resetPerspectiveModel(persp, window, false); // unrender the perspective and remove it persp.setToBeRendered(false); ps.getChildren().remove(persp); }
@Override public void doProcessContent(MPerspectiveStack element) { WPerspectiveStack<N, I, IC> stack = getWidget(element); List<WStackItem<I, IC>> items = new ArrayList<WStackItem<I, IC>>(); WStackItem<I, IC> initalItem = null; for (MPerspective e : element.getChildren()) { // Precreate the rendering context for the subitem AbstractRenderer<MPerspective, ?> renderer = factory.getRenderer(e); if (renderer != null && e.isToBeRendered() && e.isVisible()) { WStackItem<I, IC> item = createStackItem(stack, e, renderer); items.add(item); if (e == element.getSelectedElement()) { initalItem = item; } } } if (!items.isEmpty()) { if (initalItem == null || items.size() == 1 || items.get(0) == initalItem) { stack.addItems(items); } else { stack.addItem(initalItem); if (items.get(items.size() - 1) == initalItem) { stack.addItems(0, items.subList(0, items.size() - 1)); } else { int idx = items.indexOf(initalItem); stack.addItems(0, items.subList(0, idx)); stack.addItems(items.subList(idx + 1, items.size())); } } } if (element.getSelectedElement() != null) { handleSelectedElement(element, null, element.getSelectedElement()); } else if (!element.getChildren().isEmpty()) { // TODO Should this be done through the part service???? element.setSelectedElement(element.getChildren().get(0)); } }
private void initializedPerspectiveSwticherPanel(MPerspectiveStack perspectiveStack) { if (perspectiveSwitcherPanel != null) return; // initialize perspective switcher panel perspectiveStackForSwitcher = perspectiveStack; boolean iconsOnly = perspectiveStackForSwitcher.getTags().contains(Tags.ICONS_ONLY); perspectiveSwitcherPanel = new HorizontalLayout(); perspectiveSwitcherPanel.setStyleName("perspectivepanel"); perspectiveSwitcherPanel.setSizeUndefined(); Button openPerspectiveButton = new Button("Open"); openPerspectiveButton.addStyleName("vaaclipsebutton"); openPerspectiveButton.addStyleName("icononly"); openPerspectiveButton.setIcon( new ThemeResource("../vaaclipse_default_theme/img/open_perspective.png")); perspectiveSwitcherPanel.addComponent(openPerspectiveButton); openPerspectiveButton.addListener( new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { openOpenPerspectiveWindow(); // change focus Component parent = event.getButton().getParent(); while (parent != null) { if (parent instanceof Component.Focusable) { ((Component.Focusable) parent).focus(); break; } else { parent = parent.getParent(); } } } }); // add separator between openPerspectiveButton and perspective's buttons Label separator = new Label(); separator.setSizeUndefined(); separator.addStyleName("horizontalseparator"); separator.setHeight("100%"); perspectiveSwitcherPanel.addComponent(separator); // add buttons to perspective switch panel for (final MPerspective perspective : perspectiveStackForSwitcher.getChildren()) { Component button = createPerspectiveButton(perspective); if (button != null) perspectiveSwitcherPanel.addComponent(button); } }
private void refreshPerspectiveStackVisibility(MPerspectiveStack stack) { perspectiveSwitcherPanel.setVisible(stack.getChildren().size() > 0); }
@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); } } } }