aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniel Rolka2013-04-17 11:24:57 (EDT)
committerPaul Webster2013-04-18 11:04:30 (EDT)
commitecc24a3208fa0c32e882a8abd82749b0d265708d (patch)
treeaf16695412345a161e6b2bf75773390fb4da2869
parentdab06efe26e54a1588e6a9d106287cd27762be1c (diff)
downloadeclipse.platform.ui-ecc24a3208fa0c32e882a8abd82749b0d265708d.zip
eclipse.platform.ui-ecc24a3208fa0c32e882a8abd82749b0d265708d.tar.gz
eclipse.platform.ui-ecc24a3208fa0c32e882a8abd82749b0d265708d.tar.bz2
Bug 371510 - IWorkbenchSiteProgressService.warnOfContentChange notrefs/changes/27/11927/5
implemented in 4.x The review comments have been applied Change-Id: I044c8b2d81aed816dd44991836447a71f1756985
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/SWTPartRenderer.java11
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.renderers.swt/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRenderer.java100
-rw-r--r--bundles/org.eclipse.e4.ui.workbench.swt/src/org/eclipse/e4/ui/internal/workbench/swt/CSSConstants.java4
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/progress/WorkbenchSiteProgressService.java5
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/tests/UIAllTests.java4
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/StackRendererTest.java79
-rw-r--r--tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/TabStateHandlerTest.java299
-rw-r--r--tests/org.eclipse.ui.tests/Eclipse UI Tests/org/eclipse/ui/tests/internal/WorkbenchSiteProgressServiceModelTagsTest.java15
8 files changed, 436 insertions, 81 deletions
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 5963bef..cd28a73 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
@@ -66,10 +66,15 @@ public abstract class SWTPartRenderer extends AbstractPartRenderer {
public void setCSSInfo(MUIElement me, Object widget) {
// Set up the CSS Styling parameters; id & class
IEclipseContext ctxt = getContext(me);
- if (ctxt == null)
+ if (ctxt == null) {
ctxt = getContext(me);
- final IStylingEngine engine = (IStylingEngine) getContext(me).get(
- IStylingEngine.SERVICE_NAME);
+ }
+ if (ctxt == null) {
+ return;
+ }
+
+ final IStylingEngine engine = (IStylingEngine) ctxt
+ .get(IStylingEngine.SERVICE_NAME);
if (engine == null)
return;
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 c2c43d0..b09aa4a 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
@@ -151,7 +151,7 @@ public class StackRenderer extends LazyStackRenderer {
*/
private EventHandler childrenHandler;
- private EventHandler tagsChangeHandler;
+ private EventHandler tabStateHandler;
private boolean ignoreTabSelChanges = false;
@@ -489,38 +489,11 @@ 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);
-
- }
- }
- };
+ tabStateHandler = new TabStateHandler();
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));
+ tabStateHandler);
+ eventBroker.subscribe(UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT,
+ tabStateHandler);
}
/**
@@ -579,7 +552,7 @@ public class StackRenderer extends LazyStackRenderer {
eventBroker.unsubscribe(dirtyUpdater);
eventBroker.unsubscribe(viewMenuUpdater);
eventBroker.unsubscribe(childrenHandler);
- eventBroker.unsubscribe(tagsChangeHandler);
+ eventBroker.unsubscribe(tabStateHandler);
}
private String getLabel(MUILabel itemPart, String newName) {
@@ -1605,4 +1578,65 @@ public class StackRenderer extends LazyStackRenderer {
}
return false;
}
+
+ @SuppressWarnings("javadoc")
+ public class TabStateHandler implements 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 (!validateElement(element)
+ || !validateValues(oldValue, newValue)) {
+ return;
+ }
+
+ MPart part = newValue instanceof MPlaceholder ? (MPart) ((MPlaceholder) newValue)
+ .getRef() : (MPart) element;
+ CTabItem cti = findItemForPart(part);
+
+ if (cti == null) {
+ return;
+ }
+
+ if (CSSConstants.CSS_CONTENT_CHANGE_CLASS.equals(newValue)) {
+ part.getTags().remove(CSSConstants.CSS_CONTENT_CHANGE_CLASS);
+ if (cti != cti.getParent().getSelection()) {
+ part.getTags().add(CSSConstants.CSS_HIGHLIGHTED_CLASS);
+ }
+ } else if (newValue instanceof MPlaceholder // part gets active
+ && part.getTags().contains(
+ CSSConstants.CSS_HIGHLIGHTED_CLASS)) {
+ part.getTags().remove(CSSConstants.CSS_HIGHLIGHTED_CLASS);
+ }
+
+ setCSSInfo(part, cti);
+ reapplyStyles(cti);
+ }
+
+ public boolean validateElement(MUIElement element) {
+ return element instanceof MPart || element instanceof MPartStack;
+ }
+
+ public boolean validateValues(Object oldValue, Object newValue) {
+ return newValue instanceof MPlaceholder // part gets active
+ || isTagAdded(CSSConstants.CSS_BUSY_CLASS, oldValue,
+ newValue) // part gets busy
+ || isTagRemoved(CSSConstants.CSS_BUSY_CLASS, oldValue,
+ newValue) // part gets idle
+ || isTagAdded(CSSConstants.CSS_CONTENT_CHANGE_CLASS,
+ oldValue, newValue); // content of part changed
+ }
+
+ private boolean isTagAdded(String tagName, Object oldValue,
+ Object newValue) {
+ return oldValue == null && tagName.equals(newValue);
+ }
+
+ private boolean isTagRemoved(String tagName, Object oldValue,
+ Object newValue) {
+ return newValue == null && tagName.equals(oldValue);
+ }
+ }
}
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
index fb495ea..31200c2 100644
--- 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
@@ -15,4 +15,8 @@ public class CSSConstants {
public static final String CSS_BUSY_CLASS = "busy";
public static final String CSS_ACTIVE_CLASS = "active";
+
+ public static final String CSS_HIGHLIGHTED_CLASS = "highlighted";
+
+ public static final String CSS_CONTENT_CHANGE_CLASS = "contentChange";
} \ 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 31a0633..84c6b24 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
@@ -334,7 +334,10 @@ public class WorkbenchSiteProgressService implements
* @see org.eclipse.ui.progress.IWorkbenchSiteProgressService#warnOfContentChange()
*/
public void warnOfContentChange() {
- // site.getPane().showHighlight();
+ MPart part = site.getModel();
+ if (!part.getTags().contains(CSSConstants.CSS_CONTENT_CHANGE_CLASS)) {
+ part.getTags().add(CSSConstants.CSS_CONTENT_CHANGE_CLASS);
+ }
}
/*
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 416760e..d0a179b 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
@@ -37,6 +37,9 @@ 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;
+import org.eclipse.e4.ui.workbench.renderers.swt.TabStateHandlerTest;
+
+//import org.eclipse.e4.ui.workbench.renderers.swt.StackRendererTest;
/**
*
@@ -71,6 +74,7 @@ public class UIAllTests extends TestSuite {
addTestSuite(PartFocusTest.class);
addTestSuite(ModelElementTest.class);
addTestSuite(StackRendererTest.class);
+ addTestSuite(TabStateHandlerTest.class);
// addTestSuite(SWTPartRendererTest.class);
}
}
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
index 7978acd..684765d 100644
--- 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
@@ -18,21 +18,22 @@ 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.advanced.MPlaceholder;
+import org.eclipse.e4.ui.model.application.ui.advanced.impl.AdvancedFactoryImpl;
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.services.internal.events.EventBroker;
import org.eclipse.e4.ui.workbench.UIEvents;
import org.eclipse.swt.custom.CTabItem;
import org.eclipse.swt.widgets.Display;
@@ -42,6 +43,7 @@ public class StackRendererTest extends TestCase {
private E4Workbench wb;
private MPart part;
private CTabItemStylingMethodsListener executedMethodsListener;
+ private MPartStack partStack;
@Override
protected void setUp() throws Exception {
@@ -52,7 +54,7 @@ public class StackRendererTest extends TestCase {
MApplication application = ApplicationFactoryImpl.eINSTANCE
.createApplication();
MWindow window = BasicFactoryImpl.eINSTANCE.createWindow();
- MPartStack partStack = BasicFactoryImpl.eINSTANCE.createPartStack();
+ partStack = BasicFactoryImpl.eINSTANCE.createPartStack();
part = BasicFactoryImpl.eINSTANCE.createPart();
part.setLabel("some title");
@@ -88,50 +90,45 @@ public class StackRendererTest extends TestCase {
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()
+ public void testTabStateHandlerWhenOneOfSupportedTagChangeEvents()
throws Exception {
- part.getTags().add("not busy tag");
+ // given
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put(UIEvents.EventTags.ELEMENT, part);
+ params.put(UIEvents.EventTags.NEW_VALUE, CSSConstants.CSS_BUSY_CLASS);
+ params.put(UIEvents.EventTags.OLD_VALUE, null);
- assertEquals(0,
+ // when
+ context.get(EventBroker.class).send(
+ UIEvents.ApplicationElement.TOPIC_TAGS.replace(
+ UIEvents.ALL_SUB_TOPICS, UIEvents.EventTypes.SET),
+ params);
+
+ // then
+ assertEquals(1,
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),
+ public void testTabStateHandlerWhenSelectionChangedEvent() throws Exception {
+ // given
+ MPlaceholder placeHolder = AdvancedFactoryImpl.eINSTANCE
+ .createPlaceholder();
+ placeHolder.setRef(part);
+
+ HashMap<String, Object> params = new HashMap<String, Object>();
+ params.put(UIEvents.EventTags.ELEMENT, partStack);
+ params.put(UIEvents.EventTags.NEW_VALUE, placeHolder);
+ params.put(UIEvents.EventTags.OLD_VALUE, null);
+
+ // when
+ context.get(EventBroker.class).send(
+ UIEvents.ElementContainer.TOPIC_SELECTEDELEMENT.replace(
+ UIEvents.ALL_SUB_TOPICS, UIEvents.EventTypes.SET),
params);
- assertEquals(0,
+ // then
+ assertEquals(1,
executedMethodsListener
.getMethodExecutionCount("setClassnameAndId(.+)"));
}
@@ -161,10 +158,6 @@ public class StackRendererTest extends TestCase {
&& 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) {
diff --git a/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/TabStateHandlerTest.java b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/TabStateHandlerTest.java
new file mode 100644
index 0000000..c008c32
--- /dev/null
+++ b/tests/org.eclipse.e4.ui.tests/src/org/eclipse/e4/ui/workbench/renderers/swt/TabStateHandlerTest.java
@@ -0,0 +1,299 @@
+/*******************************************************************************
+ * 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.HashMap;
+import java.util.Map;
+import junit.framework.TestCase;
+import org.eclipse.e4.ui.internal.workbench.swt.CSSConstants;
+import org.eclipse.e4.ui.model.application.ui.MUIElement;
+import org.eclipse.e4.ui.model.application.ui.advanced.MPlaceholder;
+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.workbench.UIEvents;
+import org.eclipse.e4.ui.workbench.renderers.swt.StackRenderer.TabStateHandler;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.CTabFolder;
+import org.eclipse.swt.custom.CTabItem;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Widget;
+import org.osgi.service.event.Event;
+
+public class TabStateHandlerTest extends TestCase {
+ private StackRendererTestable renderer;
+ private TabStateHandler handler;
+ private Shell shell;
+
+ @Override
+ public void setUp() throws Exception {
+ shell = new Shell();
+ renderer = new StackRendererTestable();
+ handler = renderer.new TabStateHandler();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ shell.dispose();
+ }
+
+ public void testValidateElement() throws Exception {
+ assertTrue(handler.validateElement(MBasicFactory.INSTANCE.createPart()));
+ assertTrue(handler.validateElement(MBasicFactory.INSTANCE
+ .createPartStack()));
+ }
+
+ public void testValidateElementWhenInvalidElement() throws Exception {
+ assertFalse(handler.validateElement(MBasicFactory.INSTANCE
+ .createTrimBar()));
+ assertFalse(handler.validateElement(null));
+ }
+
+ public void testValidateValues() throws Exception {
+ assertTrue(handler.validateValues(null,
+ placeHolder(MBasicFactory.INSTANCE.createPart())));
+ assertTrue(handler.validateValues(null, CSSConstants.CSS_BUSY_CLASS));
+ assertTrue(handler.validateValues(CSSConstants.CSS_BUSY_CLASS, null));
+ assertTrue(handler.validateValues(null,
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS));
+ }
+
+ public void testValidateValuesWhenInvalidValue() throws Exception {
+ assertFalse(handler.validateValues(null,
+ MBasicFactory.INSTANCE.createPart()));
+ assertFalse(handler.validateValues(null, "new not supported tag"));
+ }
+
+ public void testHandleEventWhenTabBusyEvent() throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
+
+ renderer.tabItemForPart = tabItem;
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE,
+ CSSConstants.CSS_BUSY_CLASS), new EventParam(
+ UIEvents.EventTags.OLD_VALUE, null)));
+
+ // then
+ assertEquals(0, part.getTags().size());
+ assertTrue(renderer.setCSSInfoExecuted);
+ assertTrue(renderer.reapplyStylesExecuted);
+
+ tabItem.dispose();
+ tabFolder.dispose();
+ }
+
+ public void testHandleEventWhenTabIdleEvent() throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
+
+ renderer.tabItemForPart = tabItem;
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE, null),
+ new EventParam(UIEvents.EventTags.OLD_VALUE,
+ CSSConstants.CSS_BUSY_CLASS)));
+
+ // then
+ assertEquals(0, part.getTags().size());
+ assertTrue(renderer.setCSSInfoExecuted);
+ assertTrue(renderer.reapplyStylesExecuted);
+
+ tabItem.dispose();
+ tabFolder.dispose();
+ }
+
+ public void testHandleEventWhenTabContentChangedEventAndTabInactive()
+ throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem1 = new CTabItem(tabFolder, SWT.NONE);
+ CTabItem tabItem2 = new CTabItem(tabFolder, SWT.NONE);
+
+ part.getTags().add(CSSConstants.CSS_CONTENT_CHANGE_CLASS);
+ tabFolder.setSelection(tabItem2);
+ renderer.tabItemForPart = tabItem1;
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE,
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS), new EventParam(
+ UIEvents.EventTags.OLD_VALUE, null)));
+
+ // then
+ assertTrue(part.getTags().contains(CSSConstants.CSS_HIGHLIGHTED_CLASS));
+ assertFalse(part.getTags().contains(
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS));
+ assertTrue(renderer.setCSSInfoExecuted);
+ assertTrue(renderer.reapplyStylesExecuted);
+
+ tabItem1.dispose();
+ tabItem2.dispose();
+ tabFolder.dispose();
+ }
+
+ public void testHandleEventWhenTabContentChangedEventAndTabActive()
+ throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem1 = new CTabItem(tabFolder, SWT.NONE);
+ CTabItem tabItem2 = new CTabItem(tabFolder, SWT.NONE);
+
+ part.getTags().add(CSSConstants.CSS_CONTENT_CHANGE_CLASS);
+ tabFolder.setSelection(tabItem1);
+ renderer.tabItemForPart = tabItem1;
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE,
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS), new EventParam(
+ UIEvents.EventTags.OLD_VALUE, null)));
+
+ // then
+ assertFalse(part.getTags().contains(CSSConstants.CSS_HIGHLIGHTED_CLASS));
+ assertFalse(part.getTags().contains(
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS));
+ assertTrue(renderer.setCSSInfoExecuted);
+ assertTrue(renderer.reapplyStylesExecuted);
+
+ tabItem1.dispose();
+ tabItem2.dispose();
+ tabFolder.dispose();
+ }
+
+ public void testHandleEventWhenTabActivateEventAndItsContentChanged()
+ throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
+
+ part.getTags().add(CSSConstants.CSS_HIGHLIGHTED_CLASS);
+ renderer.tabItemForPart = tabItem;
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE,
+ placeHolder(part)), new EventParam(
+ UIEvents.EventTags.OLD_VALUE, null)));
+
+ // then
+ assertFalse(part.getTags().contains(CSSConstants.CSS_HIGHLIGHTED_CLASS));
+ assertTrue(renderer.setCSSInfoExecuted);
+ assertTrue(renderer.reapplyStylesExecuted);
+
+ tabItem.dispose();
+ tabFolder.dispose();
+ }
+
+ public void testHandleEventWhenTabActivateEventAndTabItemForPartNotFound()
+ throws Exception {
+ // given
+ MPart part = MBasicFactory.INSTANCE.createPart();
+ CTabFolder tabFolder = new CTabFolder(shell, SWT.NONE);
+ CTabItem tabItem = new CTabItem(tabFolder, SWT.NONE);
+
+ part.getTags().add(CSSConstants.CSS_HIGHLIGHTED_CLASS);
+ renderer.tabItemForPart = null; // just to expose the scenario condition
+
+ // when
+ handler.handleEvent(event(new EventParam(UIEvents.EventTags.ELEMENT,
+ part), new EventParam(UIEvents.EventTags.NEW_VALUE,
+ placeHolder(part)), new EventParam(
+ UIEvents.EventTags.OLD_VALUE, null)));
+
+ // then
+ assertTrue(part.getTags().contains(CSSConstants.CSS_HIGHLIGHTED_CLASS));
+ assertFalse(renderer.setCSSInfoExecuted);
+ assertFalse(renderer.reapplyStylesExecuted);
+
+ tabItem.dispose();
+ tabFolder.dispose();
+ }
+
+ // helper functions
+ private static class StackRendererTestable extends StackRenderer {
+ boolean setCSSInfoExecuted;
+ boolean reapplyStylesExecuted;
+ CTabItem tabItemForPart;
+
+ @Override
+ public void setCSSInfo(MUIElement me, Object widget) {
+ setCSSInfoExecuted = true;
+ }
+
+ @Override
+ protected void reapplyStyles(Widget widget) {
+ reapplyStylesExecuted = true;
+ }
+
+ @Override
+ protected CTabItem findItemForPart(MPart part) {
+ return tabItemForPart;
+ }
+ }
+
+ private MPlaceholder placeHolder(final MPart part) {
+ return (MPlaceholder) Proxy.newProxyInstance(getClass()
+ .getClassLoader(), new Class<?>[] { MPlaceholder.class },
+ new InvocationHandler() {
+ public Object invoke(Object arg0, Method method,
+ Object[] arg2) throws Throwable {
+ if ("getRef".equals(method.getName())) {
+ return part;
+ }
+ return null;
+ }
+ });
+ }
+
+ private class EventParam implements Map.Entry<String, Object> {
+ private String key;
+ private Object value;
+
+ public EventParam(String key, Object value) {
+ this.key = key;
+ this.value = value;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public Object setValue(Object arg0) {
+ return null;
+ }
+ }
+
+ private Event event(EventParam... params) {
+ HashMap<String, Object> paramsMap = new HashMap<String, Object>();
+ for (EventParam param : params) {
+ paramsMap.put(param.getKey(), param.getValue());
+ }
+ return new Event("topic", paramsMap);
+ }
+} \ No newline at end of file
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
index f65d048..a8062eb 100644
--- 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
@@ -103,6 +103,11 @@ public class WorkbenchSiteProgressServiceModelTagsTest extends UITestCase {
assertRemoveBusyTagEvent(receivedEvent);
}
+ public void testWarnOfContentChange() throws Exception {
+ progressService.warnOfContentChange();
+
+ assertContentChangeTagEvent(receivedEvent);
+ }
//helper functions
private static class WorkbenchSiteProgressServiceTestable extends WorkbenchSiteProgressService {
@@ -132,6 +137,14 @@ public class WorkbenchSiteProgressServiceModelTagsTest extends UITestCase {
assertModelTagChangedEvent(event);
assertEquals(CSSConstants.CSS_BUSY_CLASS, event.getProperty(UIEvents.EventTags.OLD_VALUE));
assertNull(event.getProperty(UIEvents.EventTags.NEW_VALUE));
-
+ }
+
+ private void assertContentChangeTagEvent(Event event) {
+ assertModelTagChangedEvent(event);
+
+ // we check if any event for the CSS_CONTENT_CHANGE_CLASS tag was propagated.
+ // It happens when the warmOfContentChange method was executed
+ assertTrue(CSSConstants.CSS_CONTENT_CHANGE_CLASS.equals(event.getProperty(UIEvents.EventTags.OLD_VALUE)) ||
+ CSSConstants.CSS_CONTENT_CHANGE_CLASS.equals(event.getProperty(UIEvents.EventTags.NEW_VALUE)));
}
}