/** * Wraps an element in a PartStack if it's a MPart or an MPlaceholder that references an MPart * * @param element * The element to be wrapped * @return The wrapper for the given element */ private MWindowElement wrapElementForWindow(MPartSashContainerElement element) { if (element instanceof MPlaceholder) { MUIElement ref = ((MPlaceholder) element).getRef(); if (ref instanceof MPart) { MPartStack newPS = MBasicFactory.INSTANCE.createPartStack(); newPS.getChildren().add((MPlaceholder) element); return newPS; } } else if (element instanceof MPart) { MPartStack newPS = MBasicFactory.INSTANCE.createPartStack(); newPS.getChildren().add((MPart) element); return newPS; } else if (element instanceof MWindowElement) { return (MWindowElement) element; } return null; }
private void attach() { dragElement.getParent().getChildren().remove(dragElement); ((Shell) baseWindow.getWidget()).getDisplay().update(); dragWindow = MBasicFactory.INSTANCE.createWindow(); dragWindow.getTags().add(DragHostId); // define the initial location and size for the window Point cp = ((Shell) baseWindow.getWidget()).getDisplay() .getCursorLocation(); Point size = new Point(200, 200); if (dragElement.getWidget() instanceof Control) { Control ctrl = (Control) dragElement.getWidget(); size = ctrl.getSize(); } else if (dragElement.getWidget() instanceof ToolItem) { ToolItem ti = (ToolItem) dragElement.getWidget(); Rectangle bounds = ti.getBounds(); size = new Point(bounds.width + 3, bounds.height + 3); } dragWindow.setX(cp.x + xOffset); dragWindow.setY(cp.y + yOffset); dragWindow.setWidth(size.x); dragWindow.setHeight(size.y); // add the window as a child of the base window baseWindow.getWindows().add(dragWindow); getShell().layout(getShell().getChildren(), SWT.CHANGED | SWT.DEFER); getShell().setVisible(true); }
@Override public void detach(MPartSashContainerElement element, int x, int y, int width, int height) { // If we're showing through a placehoilder then detach it... if (element.getCurSharedRef() != null) { element = element.getCurSharedRef(); } // Determine the correct parent for the new window MWindow window = getTopLevelWindowFor(element); MPerspective thePersp = getPerspectiveFor(element); MTrimmedWindow newWindow = MBasicFactory.INSTANCE.createTrimmedWindow(); newWindow.setX(x); newWindow.setY(y); newWindow.setWidth(width); newWindow.setHeight(height); element.getParent().getChildren().remove(element); MWindowElement uiRoot = wrapElementForWindow(element); newWindow.getChildren().add(uiRoot); if (thePersp != null) { thePersp.getWindows().add(newWindow); } else if (window != null) { window.getWindows().add(newWindow); } }
private void attach() { dragElement.getParent().getChildren().remove(dragElement); ((Shell) baseWindow.getWidget()).getDisplay().update(); dragWindow = MBasicFactory.INSTANCE.createWindow(); dragWindow.getTags().add(DragHostId); formatModel(dragWindow); // define the initial location and size for the window Point cp = ((Shell) baseWindow.getWidget()).getDisplay() .getCursorLocation(); Point size = new Point(200, 200); if (dragElement.getWidget() instanceof Control) { Control ctrl = (Control) dragElement.getWidget(); size = ctrl.getSize(); } else if (dragElement.getWidget() instanceof ToolItem) { ToolItem ti = (ToolItem) dragElement.getWidget(); Rectangle bounds = ti.getBounds(); size = new Point(bounds.width + 3, bounds.height + 3); } dragWindow.setX(cp.x + xOffset); dragWindow.setY(cp.y + yOffset); dragWindow.setWidth(size.x); dragWindow.setHeight(size.y); // add the window as a child of the base window baseWindow.getWindows().add(dragWindow); getShell().layout(getShell().getChildren(), SWT.CHANGED | SWT.DEFER); getShell().setVisible(true); }