private MWindow getWindow() { if (workbenchWindow != null) return workbenchWindow; if (application.getSelectedElement() != null) return application.getSelectedElement(); List<MWindow> windows = application.getChildren(); if (windows.size() != 0) return windows.get(0); return null; }
/* * Action implementation for the toolbar button */ @SuppressWarnings("restriction") void toolbarButtonClicked(NSControl source) { try { NSWindow window = source.window(); Field idField = NSWindow.class.getField("id"); // $NON-NLS-1$ Object idValue = idField.get(window); Display display = Display.getCurrent(); Widget widget = (Widget) invokeMethod( Display.class, display, "findWidget", new Object[] {idValue}); // $NON-NLS-1$ if (!(widget instanceof Shell)) { return; } Shell shell = (Shell) widget; for (MWindow mwin : app.getChildren()) { if (mwin.getWidget() == shell) { if (!runCommand(COMMAND_ID_TOGGLE_COOLBAR)) { // there may be a menu item to do the toggle... runAction(COMMAND_ID_TOGGLE_COOLBAR); } } } } catch (Exception e) { // theoretically, one of // SecurityException,Illegal*Exception,InvocationTargetException,NoSuch*Exception // not expected to happen at all. log(e); } }
public void testCreateView() { final MWindow window = createWindowWithOneView("Part Name"); MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication(); application.getChildren().add(window); application.setContext(appContext); appContext.set(MApplication.class.getName(), application); wb = new E4Workbench(application, appContext); wb.createAndRunUI(window); MPartSashContainer container = (MPartSashContainer) window.getChildren().get(0); MPartStack stack = (MPartStack) container.getChildren().get(0); MPart part = (MPart) stack.getChildren().get(0); CTabFolder folder = (CTabFolder) stack.getWidget(); CTabItem item = folder.getItem(0); assertEquals("Part Name", item.getText()); assertFalse(part.isDirty()); part.setDirty(true); assertEquals("*Part Name", item.getText()); part.setDirty(false); assertEquals("Part Name", item.getText()); }
/** Process defined windows and menu contributions */ protected void processModelMenus() { for (MWindow window : app.getChildren()) { redirectHandledMenuItems(window.getMainMenu()); } for (MMenuContribution contribution : app.getMenuContributions()) { processMenuContribution(contribution); } }
@Test public void testBug310027() { MApplication application = ApplicationFactoryImpl.eINSTANCE.createApplication(); MWindow window = BasicFactoryImpl.eINSTANCE.createWindow(); MPartSashContainer container = BasicFactoryImpl.eINSTANCE.createPartSashContainer(); MPartStack partStackA = BasicFactoryImpl.eINSTANCE.createPartStack(); MPartStack partStackB = BasicFactoryImpl.eINSTANCE.createPartStack(); MPart partA = BasicFactoryImpl.eINSTANCE.createPart(); MPart partB = BasicFactoryImpl.eINSTANCE.createPart(); window.setWidth(600); window.setHeight(400); partStackA.setContainerData("50"); partStackB.setContainerData("50"); application.getChildren().add(window); application.setSelectedElement(window); window.getChildren().add(container); window.setSelectedElement(container); container.getChildren().add(partStackA); container.getChildren().add(partStackB); container.setSelectedElement(partStackA); partStackA.getChildren().add(partA); partStackA.setSelectedElement(partA); partStackA.getChildren().add(partB); partStackA.setSelectedElement(partB); application.setContext(appContext); appContext.set(MApplication.class, application); wb = new E4Workbench(application, appContext); wb.createAndRunUI(window); assertEquals("50", partStackA.getContainerData()); assertEquals("50", partStackB.getContainerData()); partStackB.setToBeRendered(false); while (Display.getDefault().readAndDispatch()) ; assertEquals("50", partStackA.getContainerData()); }
public void stop() { // FIXME Without this call the test-suite fails cleanUp(); if (theApp != null) { for (MWindow window : theApp.getChildren()) { if (window.getWidget() != null) { removeGui(window); } } } else if (testShell != null && !testShell.isDisposed()) { Object model = testShell.getData(AbstractPartRenderer.OWNING_ME); if (model instanceof MUIElement) { removeGui((MUIElement) model); } else { testShell.close(); } } }
private void testTrimContainer_Side( SideValue applicationState, SideValue userChange, SideValue newApplicationState) { MApplication application = createApplication(); MTrimmedWindow window = createTrimmedWindow(application); MTrimBar trimBar = BasicFactoryImpl.eINSTANCE.createTrimBar(); trimBar.setSide(applicationState); window.getTrimBars().add(trimBar); saveModel(); ModelReconciler reconciler = createModelReconciler(); reconciler.recordChanges(application); trimBar.setSide(userChange); Object serialize = reconciler.serialize(); application = createApplication(); window = (MTrimmedWindow) application.getChildren().get(0); trimBar = window.getTrimBars().get(0); trimBar.setSide(newApplicationState); Collection<ModelDelta> deltas = constructDeltas(application, serialize); assertEquals(newApplicationState, trimBar.getSide()); applyAll(deltas); if (userChange == applicationState) { // no change from the user, the new state is applied assertEquals(newApplicationState, trimBar.getSide()); } else { // user change must override application state assertEquals(userChange, trimBar.getSide()); } }
public static void initializeServices(MApplication appModel) { IEclipseContext appContext = appModel.getContext(); // make sure we only add trackers once if (appContext.containsKey(CONTEXT_INITIALIZED)) return; appContext.set(CONTEXT_INITIALIZED, "true"); initializeApplicationServices(appContext); List<MWindow> windows = appModel.getChildren(); for (MWindow childWindow : windows) { initializeWindowServices(childWindow); } ((EObject) appModel) .eAdapters() .add( new AdapterImpl() { @Override public void notifyChanged(Notification notification) { if (notification.getFeatureID(MApplication.class) != UiPackageImpl.ELEMENT_CONTAINER__CHILDREN) return; if (notification.getEventType() != Notification.ADD) return; MWindow childWindow = (MWindow) notification.getNewValue(); initializeWindowServices(childWindow); } }); }
@Before public void setUp() throws Exception { appContext = E4Application.createDefaultContext(); appContext.set(E4Workbench.PRESENTATION_URI_ARG, PartRenderingEngine.engineURI); ems = appContext.get(EModelService.class); window = ems.createModelElement(MWindow.class); window.setWidth(500); window.setHeight(500); MPartSashContainer sash = ems.createModelElement(MPartSashContainer.class); window.getChildren().add(sash); window.setSelectedElement(sash); MPartStack stack = ems.createModelElement(MPartStack.class); sash.getChildren().add(stack); sash.setSelectedElement(stack); part = ems.createModelElement(MPart.class); part.setElementId("Part"); part.setLabel("Part"); part.setToolbar(ems.createModelElement(MToolBar.class)); part.setContributionURI(Activator.asURI(PartBackend.class)); stack.getChildren().add(part); toolControl = ems.createModelElement(MToolControl.class); toolControl.setElementId("ToolControl"); toolControl.setContributionURI(Activator.asURI(TextField.class)); part.getToolbar().getChildren().add(toolControl); stack = ems.createModelElement(MPartStack.class); sash.getChildren().add(stack); sash.setSelectedElement(stack); otherPart = ems.createModelElement(MPart.class); otherPart.setElementId("OtherPart"); otherPart.setLabel("OtherPart"); otherPart.setContributionURI(Activator.asURI(PartBackend.class)); stack.getChildren().add(otherPart); MApplication application = ems.createModelElement(MApplication.class); application.getChildren().add(window); application.setContext(appContext); appContext.set(MApplication.class, application); wb = new E4Workbench(application, appContext); wb.createAndRunUI(window); eps = window.getContext().get(EPartService.class); // ensure the parts are populated and the contributions instantiated eps.activate(part); eps.activate(otherPart); processEvents(); // ensure our model backend objects are created assertNotNull(part.getObject()); assertNotNull(toolControl.getObject()); assertNotNull(otherPart.getObject()); assertNotNull(part.getWidget()); assertNotNull(toolControl.getWidget()); assertNotNull(otherPart.getWidget()); // ensure focus is set to otherPart.text1 eps.activate(otherPart); processEvents(); assertTrue(((PartBackend) otherPart.getObject()).text1.isFocusControl()); }
protected MTrimmedWindow createTrimmedWindow(MApplication application) { MTrimmedWindow window = BasicFactoryImpl.eINSTANCE.createTrimmedWindow(); application.getChildren().add(window); return window; }