summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Drossel2008-07-03 11:40:54 (EDT)
committerCarsten Drossel2008-07-03 11:40:54 (EDT)
commitd1580fef19141bc6283afa47092f8ad10ec6237d (patch)
treefd139b73294e20464c71ce2fc15e10683886ea80
parent5cd9545cbfaf007af3d2253d8be67014b1452b36 (diff)
downloadorg.eclipse.riena-d1580fef19141bc6283afa47092f8ad10ec6237d.zip
org.eclipse.riena-d1580fef19141bc6283afa47092f8ad10ec6237d.tar.gz
org.eclipse.riena-d1580fef19141bc6283afa47092f8ad10ec6237d.tar.bz2
added MessageBoxMessageMarkerViewer
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewerTest.java119
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java4
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewer.java96
3 files changed, 217 insertions, 2 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewerTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewerTest.java
new file mode 100644
index 0000000..e43f56d
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewerTest.java
@@ -0,0 +1,119 @@
+/*******************************************************************************
+ * 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.easymock.EasyMock;
+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.riena.ui.ridgets.IMessageBoxRidget;
+import org.eclipse.swt.widgets.Shell;
+
+/**
+ * Test for the MessageBoxMessageMarkerViewer.
+ */
+public class MessageBoxMessageMarkerViewerTest extends TestCase {
+
+ private DefaultRealm realm;
+ private Shell shell;
+ private MessageBoxMessageMarkerViewer messageMarkerViewer;
+ private IMessageBoxRidget messageBoxRidget;
+ private TextRidget ridget;
+ private String errorMessage;
+ private ErrorMessageMarker errorMessageMarker;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ realm = new DefaultRealm();
+ shell = new Shell();
+
+ ridget = new TextRidget();
+
+ messageBoxRidget = EasyMock.createMock(IMessageBoxRidget.class);
+ messageMarkerViewer = new MessageBoxMessageMarkerViewer(messageBoxRidget);
+ messageMarkerViewer.addRidget(ridget);
+ messageMarkerViewer.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();
+ }
+
+ public void testSetVisible() throws Exception {
+
+ assertFalse(messageMarkerViewer.isVisible());
+
+ EasyMock.replay(messageBoxRidget);
+
+ messageMarkerViewer.setVisible(true);
+
+ EasyMock.verify(messageBoxRidget);
+ assertFalse(messageMarkerViewer.isVisible());
+
+ EasyMock.reset(messageBoxRidget);
+ EasyMock.replay(messageBoxRidget);
+
+ ridget.addMarker(errorMessageMarker);
+
+ EasyMock.verify(messageBoxRidget);
+ assertFalse(messageMarkerViewer.isVisible());
+
+ EasyMock.reset(messageBoxRidget);
+ messageBoxRidget.setText(errorMessage);
+ EasyMock.expect(messageBoxRidget.show()).andReturn(IMessageBoxRidget.OK);
+ EasyMock.replay(messageBoxRidget);
+
+ messageMarkerViewer.setVisible(true);
+
+ EasyMock.verify(messageBoxRidget);
+ assertFalse(messageMarkerViewer.isVisible());
+
+ EasyMock.reset(messageBoxRidget);
+ messageBoxRidget.setText(errorMessage);
+ EasyMock.expect(messageBoxRidget.show()).andReturn(IMessageBoxRidget.OK);
+ EasyMock.replay(messageBoxRidget);
+
+ TextRidget anotherRidget = new TextRidget();
+ String anotherMessage = errorMessage + "2";
+ anotherRidget.addMarker(new MessageMarker(anotherMessage));
+ messageMarkerViewer.addRidget(anotherRidget);
+ messageMarkerViewer.setVisible(true);
+
+ EasyMock.verify(messageBoxRidget);
+ assertFalse(messageMarkerViewer.isVisible());
+
+ EasyMock.reset(messageBoxRidget);
+ messageBoxRidget.setText(errorMessage + "\n" + anotherMessage);
+ EasyMock.expect(messageBoxRidget.show()).andReturn(IMessageBoxRidget.OK);
+ EasyMock.replay(messageBoxRidget);
+
+ messageMarkerViewer.addMarkerType(MessageMarker.class);
+ messageMarkerViewer.setVisible(true);
+
+ EasyMock.verify(messageBoxRidget);
+ assertFalse(messageMarkerViewer.isVisible());
+ }
+}
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 66ed3fe..1e809b0 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
@@ -28,7 +28,7 @@ import org.eclipse.riena.ui.ridgets.IMarkableRidget;
public abstract class AbstractMessageMarkerViewer implements IMessageMarkerViewer {
private HashSet<Class<? extends IMessageMarker>> markerTypes;
- private Collection<IMarkableRidget> ridgets;
+ protected Collection<IMarkableRidget> ridgets;
private boolean visible;
public AbstractMessageMarkerViewer() {
@@ -117,7 +117,7 @@ public abstract class AbstractMessageMarkerViewer implements IMessageMarkerViewe
return result;
}
- private class MessageMarkerComparator implements Comparator<IMessageMarker> {
+ protected class MessageMarkerComparator implements Comparator<IMessageMarker> {
/**
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewer.java
new file mode 100644
index 0000000..8d2c689
--- /dev/null
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/MessageBoxMessageMarkerViewer.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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.io.StringWriter;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.LinkedHashSet;
+import java.util.List;
+
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
+import org.eclipse.riena.ui.ridgets.IMarkableRidget;
+import org.eclipse.riena.ui.ridgets.IMessageBoxRidget;
+
+/**
+ * Visualizes certain types of message markers by displaying the message in a
+ * message box.
+ */
+public class MessageBoxMessageMarkerViewer extends AbstractMessageMarkerViewer {
+
+ private IMessageBoxRidget messageBoxRidget;
+
+ public MessageBoxMessageMarkerViewer(IMessageBoxRidget messageBoxRidget) {
+ this.messageBoxRidget = messageBoxRidget;
+ setVisible(false);
+ }
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.AbstractMessageMarkerViewer#hideMessages(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ */
+ @Override
+ protected void hideMessages(IMarkableRidget ridget) {
+ // automatically hidden when the message box is closed
+ }
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.AbstractMessageMarkerViewer#showMessages(org.eclipse.riena.ui.ridgets.IMarkableRidget)
+ */
+ @Override
+ protected void showMessages(IMarkableRidget ridget) {
+ if (isVisible()) {
+ String message = getMessage();
+ if (message.length() > 0) {
+ messageBoxRidget.setText(message);
+ messageBoxRidget.show();
+ }
+ setVisible(false);
+ }
+ }
+
+ /**
+ * Construct a Message of all Adapter for display, remove the marker!
+ *
+ * @return a complete Message
+ */
+ private String getMessage() {
+ Collection<IMessageMarker> allMessageMarker = new LinkedHashSet<IMessageMarker>();
+ IMarkableRidget nextMarkableAdapter = null;
+ Collection<IMarkableRidget> localMarkableAdapter = new HashSet<IMarkableRidget>();
+ localMarkableAdapter.addAll(ridgets);
+ for (Iterator i = localMarkableAdapter.iterator(); i.hasNext();) {
+ nextMarkableAdapter = (IMarkableRidget) i.next();
+ allMessageMarker.addAll(getMessageMarker(nextMarkableAdapter, false));
+ }
+ return constructMessage(allMessageMarker);
+ }
+
+ private String constructMessage(Collection<IMessageMarker> pMessageMarker) {
+ StringWriter sw = new StringWriter();
+ if (pMessageMarker != null) {
+ List<IMessageMarker> sortedMarkers = new ArrayList<IMessageMarker>(pMessageMarker);
+ Collections.sort(sortedMarkers, new MessageMarkerComparator());
+ for (IMessageMarker nextMarker : sortedMarkers) {
+ if (sw.toString().trim().length() > 0) {
+ sw.write("\n");
+ }
+ if (nextMarker.getMessage() != null) {
+ sw.write(nextMarker.getMessage());
+ }
+ }
+ }
+ return sw.toString().trim();
+ }
+
+}