blob: c7c2c9e3fca4cb4429170a2b4a4823a2369320f6 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2009, 2010 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
******************************************************************************/
package org.eclipse.e4.ui.tests.workbench;
import junit.framework.TestCase;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.di.IDisposable;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.internal.workbench.swt.E4Application;
import org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.impl.ApplicationFactoryImpl;
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.e4.ui.model.application.ui.basic.MPartSashContainer;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.model.application.ui.basic.impl.BasicFactoryImpl;
import org.eclipse.swt.custom.CTabFolder;
import org.eclipse.swt.custom.CTabItem;
public class MSaveablePartTest extends TestCase {
protected IEclipseContext appContext;
protected E4Workbench wb;
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#setUp()
*/
@Override
protected void setUp() throws Exception {
appContext = E4Application.createDefaultContext();
appContext.set(E4Workbench.PRESENTATION_URI_ARG,
PartRenderingEngine.engineURI);
}
/*
* (non-Javadoc)
*
* @see junit.framework.TestCase#tearDown()
*/
@Override
protected void tearDown() throws Exception {
if (wb != null) {
wb.close();
}
if (appContext instanceof IDisposable) {
((IDisposable) appContext).dispose();
}
}
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());
}
private MWindow createWindowWithOneView(String partName) {
final MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
window.setHeight(300);
window.setWidth(400);
window.setLabel("MyWindow");
MPartSashContainer sash = BasicFactoryImpl.eINSTANCE
.createPartSashContainer();
window.getChildren().add(sash);
MPartStack stack = BasicFactoryImpl.eINSTANCE.createPartStack();
sash.getChildren().add(stack);
MPart contributedPart = BasicFactoryImpl.eINSTANCE.createPart();
stack.getChildren().add(contributedPart);
contributedPart.setLabel(partName);
contributedPart
.setContributionURI("platform:/plugin/org.eclipse.e4.ui.tests/org.eclipse.e4.ui.tests.workbench.SampleView");
return window;
}
}