summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Drossel2008-06-23 13:01:47 (EDT)
committerCarsten Drossel2008-06-23 13:01:47 (EDT)
commit7b7c1c1d211bf2119ebf8eea4e0565db7117f8f4 (patch)
tree82261aeebdb895c32d44b9e01254b628c77399fe
parent6ed8f7ad087f27a698dd6be996e40860c2b54a0f (diff)
downloadorg.eclipse.riena-7b7c1c1d211bf2119ebf8eea4e0565db7117f8f4.zip
org.eclipse.riena-7b7c1c1d211bf2119ebf8eea4e0565db7117f8f4.tar.gz
org.eclipse.riena-7b7c1c1d211bf2119ebf8eea4e0565db7117f8f4.tar.bz2
added TooltipMessageMarkerViewer, renamed StatusbarViewer to StatusbarMessageMarkerViewer
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/AllTests.java3
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java (renamed from org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewerTest.java)79
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewerTest.java142
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java30
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java (renamed from org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewer.java)29
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewer.java100
6 files changed, 321 insertions, 62 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/AllTests.java
index e434e16..78cef74 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/AllTests.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/AllTests.java
@@ -21,7 +21,8 @@ public class AllTests {
public static Test suite() {
TestSuite suite = new TestSuite("Test for org.eclipse.riena.ui.ridgets.marker");
// $JUnit-BEGIN$
- suite.addTestSuite(StatusbarViewerTest.class);
+ suite.addTestSuite(StatusbarMessageMarkerViewerTest.class);
+ suite.addTestSuite(TooltipMessageMarkerViewerTest.class);
// $JUnit-END$
return suite;
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewerTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java
index 5ea9789..79314af 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewerTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java
@@ -17,7 +17,6 @@ import org.eclipse.riena.internal.ui.ridgets.swt.DefaultRealm;
import org.eclipse.riena.internal.ui.ridgets.swt.TextRidget;
import org.eclipse.riena.ui.core.marker.ErrorMessageMarker;
import org.eclipse.riena.ui.ridgets.IStatusbarRidget;
-import org.eclipse.riena.ui.ridgets.listener.FocusEvent;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.layout.RowLayout;
@@ -25,15 +24,15 @@ import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
/**
- * Tests for the StatusbarViewer.
+ * Tests for the StatusbarMessageMarkerViewer.
*/
-public class StatusbarViewerTest extends TestCase {
+public class StatusbarMessageMarkerViewerTest extends TestCase {
private static final String EMPTY_STATUSBAR_MESSAGE = "TestEmptyStatusbar";
private DefaultRealm realm;
private Shell shell;
- private StatusbarViewer statusbarViewer;
+ private StatusbarMessageMarkerViewer statusbarMessageMarkerViewer;
private IStatusbarRidget statusbarRidget;
private Text text1;
private Text text2;
@@ -59,10 +58,10 @@ public class StatusbarViewerTest extends TestCase {
statusbarRidget = EasyMock.createMock(IStatusbarRidget.class);
- statusbarViewer = new StatusbarViewer(statusbarRidget);
- statusbarViewer.addRidget(ridget1);
- statusbarViewer.addRidget(ridget2);
- statusbarViewer.addMarkerType(ErrorMessageMarker.class);
+ statusbarMessageMarkerViewer = new StatusbarMessageMarkerViewer(statusbarRidget);
+ statusbarMessageMarkerViewer.addRidget(ridget1);
+ statusbarMessageMarkerViewer.addRidget(ridget2);
+ statusbarMessageMarkerViewer.addMarkerType(ErrorMessageMarker.class);
shell.setSize(100, 100);
shell.setLocation(0, 0);
@@ -125,35 +124,6 @@ public class StatusbarViewerTest extends TestCase {
EasyMock.verify(statusbarRidget);
}
- // /**
- // * Test for problem report #429.
- // *
- // * @throws Exception
- // * Handled by JUnit.
- // */
- // public void testHandleReversedFocusEvents() throws Exception {
- //
- // String testErrorMessage = "Test Error in Adapter 1";
- //
- // EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
- // statusbarRidget.setMessage(testErrorMessage);
- // EasyMock.replay(statusbarRidget);
- //
- // ridget1.addMarker(new ErrorMessageMarker(testErrorMessage));
- //
- // EasyMock.verify(statusbarRidget);
- // EasyMock.reset(statusbarRidget);
- //
- // EasyMock.expect(statusbarRidget.getMessage()).andReturn(testErrorMessage);
- // statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
- // EasyMock.replay(statusbarRidget);
- //
- // ridget2.fireFocusGained();
- // ridget1.fireFocusLost();
- //
- // EasyMock.verify(statusbarRidget);
- // }
-
/**
* @throws Exception
* Handled by JUnit.
@@ -220,20 +190,35 @@ public class StatusbarViewerTest extends TestCase {
EasyMock.verify(statusbarRidget);
}
- private class TestRidget extends TextRidget {
+ /**
+ * @throws Exception
+ * Handled by JUnit.
+ */
+ public void testRemoveRidget() throws Exception {
- private boolean focused = false;
+ String testErrorMessage = "Test Error in Adapter 1";
+ ErrorMessageMarker errorMessageMarker1 = new ErrorMessageMarker(testErrorMessage);
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
+ statusbarRidget.setMessage(testErrorMessage);
+ EasyMock.replay(statusbarRidget);
+ ridget1.addMarker(errorMessageMarker1);
+ text1.setFocus();
- private void fireFocusGained() {
- focused = true;
- fireFocusGained(new FocusEvent(null, this));
- }
+ EasyMock.reset(statusbarRidget);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.removeRidget(ridget2);
- private void fireFocusLost() {
- focused = false;
- fireFocusLost(new FocusEvent(this, null));
- }
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(testErrorMessage);
+ statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.removeRidget(ridget1);
+
+ EasyMock.verify(statusbarRidget);
}
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewerTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewerTest.java
new file mode 100644
index 0000000..1d96ad6
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewerTest.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.ui.ridgets.marker;
+
+import junit.framework.TestCase;
+
+import org.eclipse.riena.internal.ui.ridgets.swt.DefaultRealm;
+import org.eclipse.riena.internal.ui.ridgets.swt.TextRidget;
+import org.eclipse.riena.ui.core.marker.ErrorMessageMarker;
+import org.eclipse.riena.ui.core.marker.MessageMarker;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Tests for the TooltipMessageMarkerViewer.
+ */
+public class TooltipMessageMarkerViewerTest extends TestCase {
+
+ private DefaultRealm realm;
+ private Shell shell;
+ private TooltipMessageMarkerViewer tooltipMessageMarkerViewer;
+ private TextRidget ridget;
+ private String errorMessage;
+ private ErrorMessageMarker errorMessageMarker;
+
+ /**
+ * @see junit.framework.TestCase#setUp()
+ */
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ realm = new DefaultRealm();
+ shell = new Shell();
+
+ ridget = new TextRidget();
+
+ tooltipMessageMarkerViewer = new TooltipMessageMarkerViewer();
+ tooltipMessageMarkerViewer.addRidget(ridget);
+ tooltipMessageMarkerViewer.addMarkerType(ErrorMessageMarker.class);
+
+ errorMessage = "TestErrorMessage";
+ errorMessageMarker = new ErrorMessageMarker(errorMessage);
+ }
+
+ /**
+ * @see junit.framework.TestCase#tearDown()
+ */
+ @Override
+ protected void tearDown() throws Exception {
+ shell.dispose();
+ shell = null;
+ realm.dispose();
+ realm = null;
+ super.tearDown();
+ }
+
+ /**
+ * @throws Exception
+ * Handled by JUnit.
+ */
+ public void testSetMessage() throws Exception {
+
+ assertNull(ridget.getToolTipText());
+
+ ridget.addMarker(errorMessageMarker);
+
+ assertEquals(errorMessage, ridget.getToolTipText());
+
+ ridget.removeMarker(errorMessageMarker);
+
+ assertNull(ridget.getToolTipText());
+ }
+
+ /**
+ * @throws Exception
+ * Handled by JUnit.
+ */
+ public void testSetMessageExistingTooltip() throws Exception {
+
+ String existingTooltip = "TestExistingTooltip";
+
+ ridget.setToolTipText(existingTooltip);
+
+ ridget.addMarker(errorMessageMarker);
+
+ assertEquals(errorMessage, ridget.getToolTipText());
+
+ ridget.removeMarker(errorMessageMarker);
+
+ assertEquals(existingTooltip, ridget.getToolTipText());
+ }
+
+ /**
+ * @throws Exception
+ * Handled by JUnit.
+ */
+ public void testAddRidgetWithMarker() throws Exception {
+
+ TextRidget anotherRidget = new TextRidget();
+ anotherRidget.addMarker(errorMessageMarker);
+
+ tooltipMessageMarkerViewer.addRidget(anotherRidget);
+
+ assertEquals(errorMessage, anotherRidget.getToolTipText());
+
+ tooltipMessageMarkerViewer.removeRidget(anotherRidget);
+
+ assertNull(anotherRidget.getToolTipText());
+ }
+
+ /**
+ * @throws Exception
+ * Handled by JUnit.
+ */
+ public void testAddMarkerType() throws Exception {
+
+ TextRidget anotherRidget = new TextRidget();
+ String anotherMessage = "TestAnotherMessage";
+ MessageMarker anotherMarker = new MessageMarker(anotherMessage);
+ anotherRidget.addMarker(anotherMarker);
+
+ tooltipMessageMarkerViewer.addRidget(anotherRidget);
+
+ assertNull(anotherRidget.getToolTipText());
+
+ tooltipMessageMarkerViewer.addMarkerType(MessageMarker.class);
+
+ assertEquals(anotherMessage, anotherRidget.getToolTipText());
+
+ tooltipMessageMarkerViewer.removeMarkerType(MessageMarker.class);
+
+ assertNull(anotherRidget.getToolTipText());
+ }
+
+}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java
index 2069df3..1abc580 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.riena.ui.ridgets.marker;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
@@ -25,12 +26,30 @@ import org.eclipse.riena.ui.ridgets.IMarkableRidget;
public abstract class AbstractMessageMarkerViewer implements IMessageMarkerViewer {
private HashSet<Class<? extends IMessageMarker>> markerTypes = new LinkedHashSet<Class<? extends IMessageMarker>>();
+ private Collection<IMarkableRidget> ridgets = new ArrayList<IMarkableRidget>();
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ */
+ public void addRidget(IMarkableRidget markableRidget) {
+ ridgets.add(markableRidget);
+ showMessages(markableRidget);
+ }
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#removeRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ */
+ public void removeRidget(IMarkableRidget markableRidget) {
+ ridgets.remove(markableRidget);
+ hideMessages(markableRidget);
+ }
/**
* @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#addMarkerType(java.lang.Class)
*/
public void addMarkerType(Class<? extends IMessageMarker> markerClass) {
markerTypes.add(markerClass);
+ showMessages();
}
/**
@@ -38,8 +57,19 @@ public abstract class AbstractMessageMarkerViewer implements IMessageMarkerViewe
*/
public void removeMarkerType(Class<? extends IMessageMarker> markerClass) {
markerTypes.remove(markerClass);
+ showMessages();
+ }
+
+ private void showMessages() {
+ for (IMarkableRidget ridget : ridgets) {
+ showMessages(ridget);
+ }
}
+ protected abstract void showMessages(IMarkableRidget ridget);
+
+ protected abstract void hideMessages(IMarkableRidget ridget);
+
protected Collection<IMessageMarker> getMessageMarker(IMarkableRidget markableRidget) {
return getMessageMarker(markableRidget, false);
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java
index 80ad90f..c022daa 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarViewer.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java
@@ -26,7 +26,7 @@ import org.eclipse.riena.ui.ridgets.listener.IFocusListener;
* Visualizes certain types of message markers by displaying the message in the
* statusbar.
*/
-public class StatusbarViewer extends AbstractMessageMarkerViewer {
+public class StatusbarMessageMarkerViewer extends AbstractMessageMarkerViewer {
private String statusbarMessage;
private String originalStatusbarMessage;
@@ -37,40 +37,41 @@ public class StatusbarViewer extends AbstractMessageMarkerViewer {
/**
* @param statusbarRidget
+ * The statusbar.
*/
- public StatusbarViewer(IStatusbarRidget statusbarRidget) {
+ public StatusbarMessageMarkerViewer(IStatusbarRidget statusbarRidget) {
this.statusbar = statusbarRidget;
}
/**
- * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ * @see org.eclipse.riena.ui.ridgets.marker.AbstractMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
*/
+ @Override
public void addRidget(IMarkableRidget markableRidget) {
+ super.addRidget(markableRidget);
markableRidget.addPropertyChangeListener(markerPropertyChangeListener);
markableRidget.addFocusListener(ridgetFocusListener);
}
- /**
- * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#removeRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
- */
- public void removeRidget(IMarkableRidget markableRidget) {
- // TODO Auto-generated method stub
-
- }
-
- private void showMessages(IMarkableRidget pMarkableAdapter) {
+ protected void showMessages(IMarkableRidget markableRidget) {
// if (this.isVisible()) {
- Collection messageMarker = this.getMessageMarker(pMarkableAdapter);
+ Collection messageMarker = this.getMessageMarker(markableRidget);
String message = constructMessage(messageMarker).trim();
// show the message only if there is something to show
if (message.length() > 0) {
setStatusbarMessage(message);
} else {
- resetStatusbarMessage();
+ hideMessages(markableRidget);
}
// }
}
+ protected void hideMessages(IMarkableRidget ridget) {
+ if (ridget.hasFocus()) {
+ resetStatusbarMessage();
+ }
+ }
+
private void setStatusbarMessage(String message) {
if (getStatusBar() != null) {
if (statusbarMessage == null) {
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewer.java
new file mode 100644
index 0000000..ce2ce73
--- /dev/null
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewer.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * Copyright (c) 2007, 2008 compeople AG 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:
+ * compeople AG - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.riena.ui.ridgets.marker;
+
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.io.StringWriter;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedHashMap;
+
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
+import org.eclipse.riena.ui.ridgets.IMarkableRidget;
+
+/**
+ * Visualizes certain types of message markers by setting the tooltip of the
+ * Ridget.
+ */
+public class TooltipMessageMarkerViewer extends AbstractMessageMarkerViewer {
+
+ private PropertyChangeListener markerPropertyChangeListener = new MarkerPropertyChangeListener();
+ private HashMap<IMarkableRidget, String> oldMessage = new LinkedHashMap<IMarkableRidget, String>();
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.AbstractMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ */
+ @Override
+ public void addRidget(IMarkableRidget markableRidget) {
+ super.addRidget(markableRidget);
+ markableRidget.addPropertyChangeListener(markerPropertyChangeListener);
+ }
+
+ protected void showMessages(IMarkableRidget markableRidget) {
+ // if (this.isVisible()) {
+ Collection messageMarker = this.getMessageMarker(markableRidget);
+ String message = constructMessage(messageMarker).trim();
+ // show the message only if there is something to show
+ if (message.length() > 0) {
+ String tooltiptext = markableRidget.getToolTipText();
+ if (tooltiptext != null) {
+ if (message.equals(tooltiptext.trim())) {
+ // do nothing old Message wird nicht überschrieben
+ } else {
+ oldMessage.put(markableRidget, tooltiptext.trim());
+ }
+ } else {
+ oldMessage.put(markableRidget, null);
+ }
+ markableRidget.setToolTipText(message);
+ } else {
+ hideMessages(markableRidget);
+ }
+ // }
+ }
+
+ protected void hideMessages(IMarkableRidget markableRidget) {
+ markableRidget.setToolTipText(oldMessage.get(markableRidget));
+ }
+
+ private String constructMessage(Collection messageMarker) {
+ StringWriter sw = new StringWriter();
+ IMessageMarker nextMarker = null;
+ if (messageMarker != null) {
+ for (Iterator i = messageMarker.iterator(); i.hasNext();) {
+ nextMarker = (IMessageMarker) i.next();
+ if (sw.toString().trim().length() > 0) {
+ sw.write("; ");
+ }
+ if (nextMarker.getMessage() != null) {
+ sw.write(nextMarker.getMessage());
+ }
+ }
+ }
+ return sw.toString().trim();
+ }
+
+ private class MarkerPropertyChangeListener implements PropertyChangeListener {
+
+ /**
+ * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
+ */
+ public void propertyChange(PropertyChangeEvent evt) {
+ if (evt.getPropertyName().equals(IMarkableRidget.PROPERTY_MARKER)
+ && evt.getSource() instanceof IMarkableRidget) {
+ showMessages((IMarkableRidget) evt.getSource());
+ }
+ }
+
+ }
+
+}