summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorDaniel Rolka2013-04-10 17:27:08 (EDT)
committer Paul Webster2013-04-11 08:30:00 (EDT)
commit206a549d1120f41c2758188a5a7181759ef4553c (patch)
treeb5f358af4380027f1d267282360ae6e560c62199
parent1b47884667d03546f226926b1c7093d1079a1058 (diff)
downloadeclipse.platform.ui-206a549d1120f41c2758188a5a7181759ef4553c.zip
eclipse.platform.ui-206a549d1120f41c2758188a5a7181759ef4553c.tar.gz
eclipse.platform.ui-206a549d1120f41c2758188a5a7181759ef4553c.tar.bz2
Bug 372466 - Part tabs no longer show that they are busy.refs/changes/13/11513/7
The review comments have been applied Change-Id: I7fc59f89450a4e2f4f700e07a85c0388711fa50e
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java10
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java73
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java9
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSConstants.java18
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java15
-rw-r--r--tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF3
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java3
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SWTPartRendererTest.java112
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java178
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java1
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/WorkbenchSiteProgressServiceModelTagsTest.java137
-rw-r--r--tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF3
13 files changed, 557 insertions, 8 deletions
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF
index 77c2736..1f3cee0 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/META-INF/MANIFEST.MF
@@ -24,7 +24,8 @@ Require-Bundle: org.eclipse.e4.ui.workbench;bundle-version="0.9.0",
org.eclipse.e4.ui.css.core;bundle-version="0.9.0",
org.eclipse.osgi;bundle-version="[3.6.0,4.0.0)",
org.eclipse.e4.ui.di;bundle-version="0.9.0",
- org.eclipse.emf.ecore;bundle-version="2.7.0"
+ org.eclipse.emf.ecore;bundle-version="2.7.0",
+ org.eclipse.e4.ui.css.swt;bundle-version="0.11.0"
Export-Package: org.eclipse.e4.ui.internal.workbench.renderers.swt;x-friends:="org.eclipse.ui.workbench",
org.eclipse.e4.ui.workbench.renderers.swt;x-friends:="org.eclipse.e4.ui.workbench.addons.swt,org.eclipse.ui.workbench"
Bundle-ActivationPolicy: lazy
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
index 0342643..5963bef 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java
@@ -15,6 +15,8 @@ import java.util.List;
import java.util.Map;
import org.eclipse.e4.core.contexts.IEclipseContext;
import org.eclipse.e4.core.services.log.Logger;
+import org.eclipse.e4.ui.css.core.engine.CSSEngine;
+import org.eclipse.e4.ui.css.swt.dom.WidgetElement;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
import org.eclipse.e4.ui.model.application.ui.MUIElement;
@@ -85,6 +87,14 @@ public abstract class SWTPartRenderer extends AbstractPartRenderer {
engine.setClassnameAndId(widget, cssClassStr, id);
}
+ @SuppressWarnings("restriction")
+ protected void reapplyStyles(Widget widget) {
+ CSSEngine engine = WidgetElement.getEngine(widget);
+ if (engine != null) {
+ engine.reapply();
+ }
+ }
+
public void bindWidget(MUIElement me, Object widget) {
if (widget instanceof Widget) {
((Widget) widget).setData(OWNING_ME, me);
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
index 5e8b91b..c2c43d0 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java
@@ -23,6 +23,7 @@ import org.eclipse.e4.core.services.events.IEventBroker;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.BasicPartList;
import org.eclipse.e4.ui.internal.workbench.renderers.swt.SWTRenderersMessages;
import org.eclipse.e4.ui.internal.workbench.swt.AbstractPartRenderer;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
import org.eclipse.e4.ui.internal.workbench.swt.CSSRenderingUtils;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
@@ -150,6 +151,8 @@ public class StackRenderer extends LazyStackRenderer {
*/
private EventHandler childrenHandler;
+ private EventHandler tagsChangeHandler;
+
private boolean ignoreTabSelChanges = false;
private ActivationJob activationJob = null;
@@ -291,6 +294,7 @@ public class StackRenderer extends LazyStackRenderer {
public void init() {
super.init(eventBroker);
+ // TODO: Refactor using findItemForPart(MPart) method
itemUpdater = new EventHandler() {
public void handleEvent(Event event) {
MUIElement element = (MUIElement) event
@@ -342,6 +346,7 @@ public class StackRenderer extends LazyStackRenderer {
eventBroker.subscribe(UIEvents.UILabel.TOPIC_ALL, itemUpdater);
+ // TODO: Refactor using findItemForPart(MPart) method
dirtyUpdater = new EventHandler() {
public void handleEvent(Event event) {
Object objElement = event
@@ -483,6 +488,39 @@ public class StackRenderer extends LazyStackRenderer {
};
eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_CHILDREN,
childrenHandler);
+
+ tagsChangeHandler = new EventHandler() {
+ public void handleEvent(Event event) {
+ MUIElement element = (MUIElement) event
+ .getProperty(UIEvents.EventTags.ELEMENT);
+ Object newValue = event
+ .getProperty(UIEvents.EventTags.NEW_VALUE);
+ Object oldValue = event
+ .getProperty(UIEvents.EventTags.OLD_VALUE);
+
+ if (!(element instanceof MPart)
+ || !isBusyTagModified(oldValue, newValue)) {
+ return;
+ }
+
+ MPart part = (MPart) element;
+ CTabItem cti = findItemForPart(part);
+ if (cti != null) {
+ setCSSInfo(part, cti);
+ reapplyStyles(cti);
+
+ }
+ }
+ };
+ eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS,
+ tagsChangeHandler);
+ }
+
+ private boolean isBusyTagModified(Object oldValue, Object newValue) {
+ return (newValue == null && CSSConstants.CSS_BUSY_CLASS
+ .equals(oldValue))
+ || (oldValue == null && CSSConstants.CSS_BUSY_CLASS
+ .equals(newValue));
}
/**
@@ -541,6 +579,7 @@ public class StackRenderer extends LazyStackRenderer {
eventBroker.unsubscribe(dirtyUpdater);
eventBroker.unsubscribe(viewMenuUpdater);
eventBroker.unsubscribe(childrenHandler);
+ eventBroker.unsubscribe(tagsChangeHandler);
}
private String getLabel(MUILabel itemPart, String newName) {
@@ -826,6 +865,40 @@ public class StackRenderer extends LazyStackRenderer {
return null;
}
+ protected CTabItem findItemForPart(MPart part) {
+ // is this a direct child of the stack?
+ if (part.getParent() != null
+ && part.getParent().getRenderer() == StackRenderer.this) {
+ CTabItem cti = findItemForPart(part, part.getParent());
+ if (cti != null) {
+ return cti;
+ }
+ }
+
+ // Do we have any stacks with place holders for the element
+ // that's changed?
+ MWindow win = modelService.getTopLevelWindowFor(part);
+ List<MPlaceholder> refs = modelService.findElements(win, null,
+ MPlaceholder.class, null);
+ if (refs != null) {
+ for (MPlaceholder ref : refs) {
+ if (ref.getRef() != part)
+ continue;
+
+ MElementContainer<MUIElement> refParent = ref.getParent();
+ // can be null, see bug 328296
+ if (refParent != null
+ && refParent.getRenderer() instanceof StackRenderer) {
+ CTabItem cti = findItemForPart(ref, refParent);
+ if (cti != null) {
+ return cti;
+ }
+ }
+ }
+ }
+ return null;
+ }
+
@Override
public void hideChild(MElementContainer<MUIElement> parentElement,
MUIElement child) {
diff --git a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
index d883f49..822063f 100644
--- a/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
+++ b/bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/WBWRenderer.java
@@ -26,6 +26,7 @@ import org.eclipse.e4.core.services.log.Logger;
import org.eclipse.e4.ui.internal.workbench.Activator;
import org.eclipse.e4.ui.internal.workbench.E4Workbench;
import org.eclipse.e4.ui.internal.workbench.Policy;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.MContext;
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
@@ -135,7 +136,7 @@ public class WBWRenderer extends SWTPartRenderer {
}
if (activePart != null) {
- activePart.getTags().remove("active"); //$NON-NLS-1$
+ activePart.getTags().remove(CSSConstants.CSS_ACTIVE_CLASS);
MUIElement parent = activePart.getParent();
if (parent == null && activePart.getCurSharedRef() != null) {
@@ -153,7 +154,7 @@ public class WBWRenderer extends SWTPartRenderer {
activePart = p;
if (activePart != null) {
- activePart.getTags().add("active"); //$NON-NLS-1$
+ activePart.getTags().add(CSSConstants.CSS_ACTIVE_CLASS);
MUIElement parent = activePart.getParent();
if (parent == null && activePart.getCurSharedRef() != null) {
MPlaceholder ph = activePart.getCurSharedRef();
@@ -169,9 +170,9 @@ public class WBWRenderer extends SWTPartRenderer {
private void styleStack(MPartStack stack, boolean active) {
if (!active)
- stack.getTags().remove("active"); //$NON-NLS-1$
+ stack.getTags().remove(CSSConstants.CSS_ACTIVE_CLASS);
else
- stack.getTags().add("active"); //$NON-NLS-1$
+ stack.getTags().add(CSSConstants.CSS_ACTIVE_CLASS);
if (stack.getWidget() != null)
setCSSInfo(stack, stack.getWidget());
diff --git a/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSConstants.java b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSConstants.java
new file mode 100644
index 0000000..fb495ea
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSConstants.java
@@ -0,0 +1,18 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.internal.workbench.swt;
+
+public class CSSConstants {
+ public static final String CSS_BUSY_CLASS = "busy";
+
+ public static final String CSS_ACTIVE_CLASS = "active";
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java
index 4cb05ff..31a0633 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java
@@ -23,6 +23,8 @@ import org.eclipse.core.runtime.jobs.IJobChangeListener;
import org.eclipse.core.runtime.jobs.ISchedulingRule;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
import org.eclipse.jface.operation.IRunnableContext;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.resource.ImageDescriptor;
@@ -128,7 +130,7 @@ public class WorkbenchSiteProgressService implements
cursor = getWaitCursor(control.getDisplay());
}
control.setCursor(cursor);
- // site.getPane().setBusy(busy);
+ showBusy(busy);
IWorkbenchPart part = site.getPart();
if (part instanceof WorkbenchPart) {
((WorkbenchPart) part).showBusy(busy);
@@ -445,4 +447,15 @@ public class WorkbenchSiteProgressService implements
public SiteUpdateJob getUpdateJob() {
return updateJob;
}
+
+ protected void showBusy(boolean busy) {
+ MPart part = site.getModel();
+ boolean containsBusyTag = part.getTags().contains(CSSConstants.CSS_BUSY_CLASS);
+
+ if (busy && !containsBusyTag) {
+ part.getTags().add(CSSConstants.CSS_BUSY_CLASS);
+ } else if (!busy && containsBusyTag) {
+ part.getTags().remove(CSSConstants.CSS_BUSY_CLASS);
+ }
+ }
}
diff --git a/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF
index 04afebf..cc4c1bd 100644
--- a/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.e4.ui.tests/META-INF/MANIFEST.MF
@@ -29,7 +29,8 @@ Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="2.4.0",
org.eclipse.e4.ui.di;bundle-version="0.9.0",
org.eclipse.e4.core.di.extensions;bundle-version="0.9.0",
org.eclipse.core.expressions;bundle-version="3.4.200",
- org.eclipse.e4.ui.workbench.addons.swt;bundle-version="0.9.0"
+ org.eclipse.e4.ui.workbench.addons.swt;bundle-version="0.9.0",
+ org.eclipse.e4.ui.css.swt;bundle-version="0.11.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
Import-Package: javax.annotation;version="1.0.0",
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java
index 0fd7b5c..416760e 100644
--- a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java
@@ -36,6 +36,7 @@ import org.eclipse.e4.ui.tests.workbench.MWindowTest;
import org.eclipse.e4.ui.tests.workbench.PartFocusTest;
import org.eclipse.e4.ui.tests.workbench.PartRenderingEngineTests;
import org.eclipse.e4.ui.tests.workbench.SashRendererTest;
+import org.eclipse.e4.ui.workbench.renderers.swt.StackRendererTest;
/**
*
@@ -69,5 +70,7 @@ public class UIAllTests extends TestSuite {
addTestSuite(InjectionEventTest.class);
addTestSuite(PartFocusTest.class);
addTestSuite(ModelElementTest.class);
+ addTestSuite(StackRendererTest.class);
+ // addTestSuite(SWTPartRendererTest.class);
}
}
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SWTPartRendererTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SWTPartRendererTest.java
new file mode 100644
index 0000000..fe7b2ab
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/workbench/SWTPartRendererTest.java
@@ -0,0 +1,112 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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 java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.eclipse.e4.core.contexts.EclipseContextFactory;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.basic.MBasicFactory;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.services.IStylingEngine;
+import org.eclipse.e4.ui.workbench.renderers.swt.SWTPartRenderer;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+
+public class SWTPartRendererTest extends TestCase {
+ private SWTPartRenderer renderer;
+ private Shell shell;
+ private MPart part;
+ private IEclipseContext context;
+ private Map<String, Object[]> stylingEngineExecutedMethods;
+
+ @Override
+ public void setUp() throws Exception {
+ renderer = new SWTPartRenderer() {
+ @Override
+ public Object createWidget(MUIElement element, Object parent) {
+ return null;
+ }
+ };
+
+ shell = Display.getDefault().getActiveShell();
+ stylingEngineExecutedMethods = new HashMap<String, Object[]>();
+
+ context = EclipseContextFactory.create();
+ context.set(IStylingEngine.SERVICE_NAME, Proxy.newProxyInstance(
+ getClass().getClassLoader(),
+ new Class<?>[] { IStylingEngine.class },
+ new InvocationHandler() {
+ public Object invoke(Object proxy, Method method,
+ Object[] args) throws Throwable {
+ stylingEngineExecutedMethods.put(method.getName(), args);
+ return null;
+ }
+ }));
+
+ part = MBasicFactory.INSTANCE.createPart();
+ part.setElementId("org.eclipse.elementId");
+ part.setContext(context);
+
+ }
+
+ public void testSetCSSInfo() throws Exception {
+ Button button = new Button(shell, SWT.PUSH);
+
+ renderer.setCSSInfo(part, button);
+ Object[] setClassnameAndIdParams = stylingEngineExecutedMethods
+ .get("setClassnameAndId");
+
+ assertNotNull(setClassnameAndIdParams);
+ assertEquals(3, setClassnameAndIdParams.length);
+ assertEquals(button, setClassnameAndIdParams[0]);
+ assertEquals("MPart", setClassnameAndIdParams[1].toString());
+ assertEquals("org-eclipse-elementId",
+ setClassnameAndIdParams[2].toString());
+ }
+
+ public void testSetCSSInfoWhenUIElementWithTags() throws Exception {
+ Button button = new Button(shell, SWT.PUSH);
+ part.getTags().add("tag1");
+ part.getTags().add("tag2");
+
+ renderer.setCSSInfo(part, button);
+ Object[] setClassnameAndIdParams = stylingEngineExecutedMethods
+ .get("setClassnameAndId");
+
+ assertNotNull(setClassnameAndIdParams);
+ assertEquals(3, setClassnameAndIdParams.length);
+ assertEquals(button, setClassnameAndIdParams[0]);
+ assertEquals("MPart tag1 tag2", setClassnameAndIdParams[1].toString());
+ assertEquals("org-eclipse-elementId",
+ setClassnameAndIdParams[2].toString());
+ }
+
+ public void testSetCSSInfoWhenNoCSSStylingEngineInContext()
+ throws Exception {
+ Button button = new Button(shell, SWT.PUSH);
+ context.remove(IStylingEngine.SERVICE_NAME);
+
+ renderer.setCSSInfo(part, button);
+ Object[] setClassnameAndIdParams = stylingEngineExecutedMethods
+ .get("setClassnameAndId");
+
+ assertNull(setClassnameAndIdParams);
+ }
+}
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java
new file mode 100644
index 0000000..7978acd
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java
@@ -0,0 +1,178 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.workbench.renderers.swt;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.events.IEventBroker;
+import org.eclipse.e4.ui.internal.workbench.E4Workbench;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
+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.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.e4.ui.services.IStylingEngine;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.widgets.Display;
+
+public class StackRendererTest extends TestCase {
+ private IEclipseContext context;
+ private E4Workbench wb;
+ private MPart part;
+ private CTabItemStylingMethodsListener executedMethodsListener;
+
+ @Override
+ protected void setUp() throws Exception {
+ context = E4Application.createDefaultContext();
+ context.set(E4Workbench.PRESENTATION_URI_ARG,
+ PartRenderingEngine.engineURI);
+
+ MApplication application = ApplicationFactoryImpl.eINSTANCE
+ .createApplication();
+ MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
+ MPartStack partStack = BasicFactoryImpl.eINSTANCE.createPartStack();
+ part = BasicFactoryImpl.eINSTANCE.createPart();
+ part.setLabel("some title");
+
+ application.getChildren().add(window);
+ application.setSelectedElement(window);
+
+ window.getChildren().add(partStack);
+ partStack.getChildren().add(part);
+
+ application.setContext(context);
+ context.set(MApplication.class.getName(), application);
+
+ executedMethodsListener = new CTabItemStylingMethodsListener(part);
+
+ wb = new E4Workbench(application, context);
+ wb.getContext().set(
+ IStylingEngine.class,
+ (IStylingEngine) Proxy.newProxyInstance(getClass()
+ .getClassLoader(),
+ new Class<?>[] { IStylingEngine.class },
+ executedMethodsListener));
+
+ wb.createAndRunUI(window);
+ while (Display.getDefault().readAndDispatch())
+ ;
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ if (wb != null) {
+ wb.close();
+ }
+ context.dispose();
+ }
+
+ public void testTagsChangeHandlerWhenBusyTagAddEvent() throws Exception {
+ part.getTags().add(CSSConstants.CSS_BUSY_CLASS);
+
+ assertEquals(1,
+ executedMethodsListener
+ .getMethodExecutionCount("setClassnameAndId(.+)"));
+ assertTrue(executedMethodsListener
+ .isMethodExecuted("setClassnameAndId(.+MPart "
+ + CSSConstants.CSS_BUSY_CLASS + ".+)"));
+ }
+
+ public void testTagsChangeHandlerWhenBusyTagRemoveEvent() throws Exception {
+ part.getTags().add(CSSConstants.CSS_BUSY_CLASS);
+ part.getTags().remove(CSSConstants.CSS_BUSY_CLASS);
+
+ assertEquals(2,
+ executedMethodsListener
+ .getMethodExecutionCount("setClassnameAndId(.+)"));
+ assertTrue(executedMethodsListener
+ .isMethodExecuted("setClassnameAndId(.+MPart "
+ + CSSConstants.CSS_BUSY_CLASS + ".+)"));
+ assertTrue(executedMethodsListener
+ .isMethodExecuted("setClassnameAndId(.+MPart.+)"));
+ }
+
+ public void testTagsChangeHandlerWhenNotBusyTagModifiedEvent()
+ throws Exception {
+ part.getTags().add("not busy tag");
+
+ assertEquals(0,
+ executedMethodsListener
+ .getMethodExecutionCount("setClassnameAndId(.+)"));
+ }
+
+ public void testTagsChangeHandlerWhenNotTagReleatedEvent() throws Exception {
+ Map<String, Object> params = new HashMap<String, Object>();
+ params.put(UIEvents.EventTags.ELEMENT, part);
+
+ context.get(IEventBroker.class).send(
+ UIEvents.ApplicationElement.TOPIC_ELEMENTID.replace(
+ UIEvents.ALL_SUB_TOPICS, UIEvents.EventTypes.ADD),
+ params);
+
+ assertEquals(0,
+ executedMethodsListener
+ .getMethodExecutionCount("setClassnameAndId(.+)"));
+ }
+
+ // helper functions
+ private static class CTabItemStylingMethodsListener implements
+ InvocationHandler {
+ private MPart part;
+ private List<String> methods;
+
+ public CTabItemStylingMethodsListener(MPart part) {
+ this.part = part;
+ methods = new ArrayList<String>();
+ }
+
+ public Object invoke(Object proxy, Method method, Object[] args)
+ throws Throwable {
+ if (isTabItemForPart(args[0])) {
+ methods.add(String.format("%s(%s)", method.getName(),
+ Arrays.toString(args)));
+ }
+ return null;
+ }
+
+ private boolean isTabItemForPart(Object obj) {
+ return obj instanceof CTabItem
+ && part.getLabel().equals(((CTabItem) obj).getText());
+ }
+
+ public boolean isMethodExecuted(String methodPattern) {
+ return getMethodExecutionCount(methodPattern) > 0;
+ }
+
+ public int getMethodExecutionCount(String methodPattern) {
+ int result = 0;
+ for (String method : methods) {
+ if (method.matches(methodPattern)) {
+ result++;
+ }
+ }
+ return result;
+ }
+ }
+}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java
index d0dda6b..60f817a 100644
--- a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/InternalTestSuite.java
@@ -63,5 +63,6 @@ public class InternalTestSuite extends TestSuite {
addTest(new TestSuite(PerspectiveSwitcherTest.class));
addTest(new TestSuite(StickyViewManagerTest.class));
addTest(new TestSuite(FileEditorMappingTest.class));
+ addTest(new TestSuite(WorkbenchSiteProgressServiceModelTagsTest.class));
}
}
diff --git a/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/WorkbenchSiteProgressServiceModelTagsTest.java b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/WorkbenchSiteProgressServiceModelTagsTest.java
new file mode 100644
index 0000000..f65d048
--- /dev/null
+++ b/tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/WorkbenchSiteProgressServiceModelTagsTest.java
@@ -0,0 +1,137 @@
+/*******************************************************************************
+ * Copyright (c) 2013 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.ui.tests.internal;
+
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.services.events.IEventBroker;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.internal.ModelUtils;
+import org.eclipse.e4.ui.workbench.UIEvents;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.internal.PartSite;
+import org.eclipse.ui.internal.progress.WorkbenchSiteProgressService;
+import org.eclipse.ui.tests.api.workbenchpart.EmptyView;
+import org.eclipse.ui.tests.harness.util.UITestCase;
+import org.osgi.service.event.Event;
+import org.osgi.service.event.EventHandler;
+
+/**
+ * @since 3.5
+ *
+ */
+public class WorkbenchSiteProgressServiceModelTagsTest extends UITestCase {
+ private IWorkbenchWindow window;
+
+ private IWorkbenchPage page;
+
+ private EmptyView view;
+
+ private Event receivedEvent;
+
+ private EventHandler eventHandler;
+
+ private IEventBroker eventBroker;
+
+ private PartSite site;
+
+ private WorkbenchSiteProgressServiceTestable progressService;
+
+ public WorkbenchSiteProgressServiceModelTagsTest(String testName) {
+ super(testName);
+ }
+
+ protected void doSetUp() throws Exception {
+ super.doSetUp();
+ window = openTestWindow();
+ page = window.getActivePage();
+ String viewId = "org.eclipse.ui.tests.workbenchpart.EmptyView";
+ view = (EmptyView) page.showView(viewId);
+
+ assertTrue(page.getActivePart().getSite() instanceof PartSite);
+ site = (PartSite) page.getActivePart().getSite();
+
+ progressService = new WorkbenchSiteProgressServiceTestable(site);
+
+ IEclipseContext context = ModelUtils.getContainingContext(site.getModel());
+ assertNotNull(context);
+
+ eventHandler = new EventHandler() {
+ public void handleEvent(Event event) {
+ receivedEvent = event;
+
+ }
+ };
+
+ eventBroker = context.get(IEventBroker.class);
+ eventBroker.subscribe(UIEvents.ApplicationElement.TOPIC_TAGS, eventHandler);
+ }
+
+
+ protected void doTearDown() throws Exception {
+ eventBroker.unsubscribe(eventHandler);
+ eventBroker = null;
+ page.hideView(view);
+ super.doTearDown();
+ }
+
+ public void testShowBusyWhenCurrentlyIdle() throws Exception {
+ site.getModel().getTags().remove(CSSConstants.CSS_BUSY_CLASS); /* state idle */
+
+ progressService.showBusy(true);
+
+ assertTrue(site.getModel().getTags().contains(CSSConstants.CSS_BUSY_CLASS));
+ assertAddBusyTagEvent(receivedEvent);
+ }
+
+ public void testShowBusyWhenCurrentlyBusy() throws Exception {
+ site.getModel().getTags().add(CSSConstants.CSS_BUSY_CLASS); /* state busy */
+
+ progressService.showBusy(false);
+
+ assertFalse(site.getModel().getTags().contains(CSSConstants.CSS_BUSY_CLASS));
+ assertRemoveBusyTagEvent(receivedEvent);
+ }
+
+
+ //helper functions
+ private static class WorkbenchSiteProgressServiceTestable extends WorkbenchSiteProgressService {
+ public WorkbenchSiteProgressServiceTestable(PartSite partSite) {
+ super(partSite);
+ }
+
+ @Override
+ public void showBusy(boolean busy) {
+ super.showBusy(busy);
+ }
+ }
+
+ private void assertModelTagChangedEvent(Event event) {
+ assertNotNull(event);
+ assertTrue(event.getProperty(UIEvents.EventTags.ELEMENT) instanceof MPart);
+ assertEquals(UIEvents.ApplicationElement.TAGS, event.getProperty(UIEvents.EventTags.ATTNAME));
+ }
+
+ private void assertAddBusyTagEvent(Event event) {
+ assertModelTagChangedEvent(event);
+ assertNull(event.getProperty(UIEvents.EventTags.OLD_VALUE));
+ assertEquals(CSSConstants.CSS_BUSY_CLASS, event.getProperty(UIEvents.EventTags.NEW_VALUE));
+ }
+
+ private void assertRemoveBusyTagEvent(Event event) {
+ assertModelTagChangedEvent(event);
+ assertEquals(CSSConstants.CSS_BUSY_CLASS, event.getProperty(UIEvents.EventTags.OLD_VALUE));
+ assertNull(event.getProperty(UIEvents.EventTags.NEW_VALUE));
+
+ }
+}
diff --git a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
index c46080e..32d174f 100644
--- a/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
+++ b/tests/org.eclipse.ui.tests/META-INF/MANIFEST.MF
@@ -42,7 +42,8 @@ Require-Bundle: org.eclipse.core.runtime.compatibility,
org.eclipse.e4.core.di.extensions;bundle-version="0.10.0",
org.eclipse.e4.ui.services;bundle-version="0.10.0",
org.eclipse.e4.ui.workbench.addons.swt;bundle-version="0.10.0",
- org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.10.0"
+ org.eclipse.e4.ui.workbench.renderers.swt;bundle-version="0.10.0",
+ org.eclipse.osgi.services;bundle-version="3.3.100"
Eclipse-AutoStart: true
Export-Package: org.eclipse.ui.tests.api,
org.eclipse.ui.tests.menus