summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCarsten Drossel2008-06-30 05:43:50 (EDT)
committerCarsten Drossel2008-06-30 05:43:50 (EDT)
commit5ae498d24d74815210e72b46d65496f80e1ce7bc (patch)
treed33f20354dab2cb606262f1387c8cf004743d812
parentd9e5ad489e1fa2312026e0a25c9923d22d8c20d3 (diff)
downloadorg.eclipse.riena-5ae498d24d74815210e72b46d65496f80e1ce7bc.zip
org.eclipse.riena-5ae498d24d74815210e72b46d65496f80e1ce7bc.tar.gz
org.eclipse.riena-5ae498d24d74815210e72b46d65496f80e1ce7bc.tar.bz2
extended editable ridgets to show messages when a validation fails using MessageMarkers
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TextRidgetTest2.java59
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/AllTests.java1
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/ValueBindingSupportTest.java264
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java139
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewerTest.java53
-rw-r--r--org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/validation/tests/ValidatorCollectionTest.java4
-rw-r--r--org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractEditableRidget.java37
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IEditableRidget.java103
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ValueBindingSupport.java115
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/AbstractMessageMarkerViewer.java27
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/IMessageMarkerViewer.java15
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java18
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/TooltipMessageMarkerViewer.java31
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/ValidationMessageMarker.java58
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/AbstractValidDate.java3
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MaxLength.java2
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MinLength.java4
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/RequiredField.java4
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidCharacters.java2
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidDecimal.java8
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidEmailAddress.java2
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidExpression.java3
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidInteger.java8
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidRange.java5
-rw-r--r--org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidationRuleStatus.java16
25 files changed, 877 insertions, 104 deletions
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TextRidgetTest2.java b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TextRidgetTest2.java
index db889ef..847edaa 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TextRidgetTest2.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/internal/ui/ridgets/swt/TextRidgetTest2.java
@@ -12,12 +12,16 @@ package org.eclipse.riena.internal.ui.ridgets.swt;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.util.Collection;
import java.util.Date;
import org.easymock.EasyMock;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.riena.core.marker.IMarker;
import org.eclipse.riena.navigation.ui.swt.binding.DefaultSwtControlRidgetMapper;
import org.eclipse.riena.tests.UITestHelper;
import org.eclipse.riena.ui.core.marker.ErrorMarker;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
import org.eclipse.riena.ui.ridgets.IRidget;
import org.eclipse.riena.ui.ridgets.ITextFieldRidget;
import org.eclipse.riena.ui.ridgets.databinding.DateToStringConverter;
@@ -30,6 +34,8 @@ import org.eclipse.riena.ui.ridgets.validation.MaxLength;
import org.eclipse.riena.ui.ridgets.validation.MinLength;
import org.eclipse.riena.ui.ridgets.validation.ValidCharacters;
import org.eclipse.riena.ui.ridgets.validation.ValidIntermediateDate;
+import org.eclipse.riena.ui.ridgets.validation.ValidationFailure;
+import org.eclipse.riena.ui.ridgets.validation.ValidationRuleStatus;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
@@ -701,4 +707,57 @@ public class TextRidgetTest2 extends AbstractSWTRidgetTest {
assertEquals("this is not too short", model.getValue());
}
+ public void testValidationMessage() throws Exception {
+ Text control = getUIControl();
+ ITextFieldRidget ridget = getRidget();
+ ridget.bindToModel(bean, TestBean.PROPERTY);
+ ridget.addValidationRule(new EvenNumberOfCharacters());
+ ridget.setDirectWriting(true);
+
+ ridget.addValidationMessage("TestTextTooShortMessage");
+
+ assertEquals(0, ridget.getMarkers().size());
+
+ UITestHelper.sendString(control.getDisplay(), "a");
+
+ assertEquals(2, ridget.getMarkers().size());
+ assertEquals("TestTextTooShortMessage", getMessageMarker(ridget.getMarkers()).getMessage());
+
+ UITestHelper.sendString(control.getDisplay(), "b");
+
+ assertEquals(0, ridget.getMarkers().size());
+ }
+
+ private IMessageMarker getMessageMarker(Collection<? extends IMarker> markers) {
+ for (IMarker marker : markers) {
+ if (marker instanceof IMessageMarker) {
+ return (IMessageMarker) marker;
+ }
+ }
+ return null;
+ }
+
+ private class EvenNumberOfCharacters implements IValidationRule {
+
+ public IStatus validate(final Object value) {
+ if (value == null) {
+ return ValidationRuleStatus.ok();
+ }
+ if (value instanceof String) {
+ final String string = (String) value;
+ if (string.length() % 2 == 0) {
+ return ValidationRuleStatus.ok();
+ }
+ return ValidationRuleStatus.error(false, "Odd number of characters.", this);
+ }
+ throw new ValidationFailure(getClass().getName() + " can only validate objects of type "
+ + String.class.getName());
+ }
+
+ public ValidationTime getValidationTime() {
+ return ValidationTime.ON_UPDATE_TO_MODEL;
+ }
+
+ }
+
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/AllTests.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/AllTests.java
index 8871e98..ec14c6f 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/AllTests.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/AllTests.java
@@ -39,6 +39,7 @@ public class AllTests extends TestCase {
public static Test suite() {
TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(ValueBindingSupportTest.class);
suite.addTestSuite(GregorianCalendarToStringConverterTest.class);
suite.addTestSuite(StringToGregorianCalendarConverterTest.class);
suite.addTestSuite(RidgetUpdateValueStrategyTest.class);
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/ValueBindingSupportTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/ValueBindingSupportTest.java
new file mode 100644
index 0000000..eff040a
--- /dev/null
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/ValueBindingSupportTest.java
@@ -0,0 +1,264 @@
+/*******************************************************************************
+ * 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.databinding.beans.BeansObservables;
+import org.eclipse.core.databinding.observable.value.IObservableValue;
+import org.eclipse.core.databinding.observable.value.WritableValue;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.riena.core.marker.IMarkable;
+import org.eclipse.riena.core.marker.Markable;
+import org.eclipse.riena.internal.ui.ridgets.swt.DefaultRealm;
+import org.eclipse.riena.ui.core.marker.ErrorMarker;
+import org.eclipse.riena.ui.core.marker.ErrorMessageMarker;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
+import org.eclipse.riena.ui.core.marker.MessageMarker;
+import org.eclipse.riena.ui.ridgets.util.beans.TestBean;
+import org.eclipse.riena.ui.ridgets.validation.IValidationRule;
+import org.eclipse.riena.ui.ridgets.validation.ValidationFailure;
+import org.eclipse.riena.ui.ridgets.validation.ValidationRuleStatus;
+
+/**
+ * Tests for the ValueBindingSupport.
+ */
+public class ValueBindingSupportTest extends TestCase {
+
+ private DefaultRealm realm;
+ private ValueBindingSupport valueBindingSupport;
+ private TestBean bean;
+ private IObservableValue model;
+ private IObservableValue target;
+ private IMarkable markable;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ realm = new DefaultRealm();
+
+ bean = new TestBean();
+ model = BeansObservables.observeValue(bean, TestBean.PROPERTY);
+ target = new WritableValue();
+
+ valueBindingSupport = new ValueBindingSupport(target, model);
+
+ markable = new Markable();
+ valueBindingSupport.setMarkable(markable);
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ realm.dispose();
+ realm = null;
+ super.tearDown();
+ }
+
+ public void testUpdateFromModelOnRequest() throws Exception {
+
+ assertNull(target.getValue());
+
+ bean.setProperty("TestValue");
+
+ assertNull(target.getValue());
+
+ valueBindingSupport.updateFromModel();
+
+ assertEquals("TestValue", target.getValue());
+ }
+
+ public void testUpdateFromTargetImmediately() throws Exception {
+
+ assertNull(bean.getProperty());
+
+ target.setValue("TestValue");
+
+ assertEquals("TestValue", bean.getProperty());
+ }
+
+ public void testValidationMessagesAddAndRemove() throws Exception {
+
+ valueBindingSupport.addValidationRule(new EvenNumberOfCharacters());
+ valueBindingSupport.addValidationMessage("TestMessage1");
+ valueBindingSupport.addValidationMessage("TestMessage2");
+ ErrorMessageMarker messageMarker1 = new ErrorMessageMarker("TestMessage3");
+ valueBindingSupport.addValidationMessage(messageMarker1);
+ MessageMarker messageMarker2 = new MessageMarker("TestMessage4");
+ valueBindingSupport.addValidationMessage(messageMarker2);
+
+ assertEquals(0, markable.getMarkers().size());
+
+ target.setValue("odd");
+
+ assertEquals(5, markable.getMarkers().size());
+ assertMessageMarkers("TestMessage1", "TestMessage2", "TestMessage3", "TestMessage4");
+
+ target.setValue("even");
+
+ assertEquals(0, markable.getMarkers().size());
+
+ valueBindingSupport.removeValidationMessage("TestMessage1");
+ valueBindingSupport.removeValidationMessage(messageMarker1);
+
+ target.setValue("odd");
+
+ assertEquals(3, markable.getMarkers().size());
+ assertMessageMarkers("TestMessage2", "TestMessage4");
+
+ target.setValue("even");
+
+ assertEquals(0, markable.getMarkers().size());
+
+ valueBindingSupport.removeValidationMessage("TestMessage2");
+ valueBindingSupport.removeValidationMessage(messageMarker2);
+
+ target.setValue("odd");
+
+ assertEquals(1, markable.getMarkers().size());
+ assertTrue(markable.getMarkers().iterator().next() instanceof ErrorMarker);
+
+ target.setValue("even");
+
+ assertEquals(0, markable.getMarkers().size());
+ }
+
+ public void testValidationMessagesAddAndRemoveWhileActive() throws Exception {
+
+ valueBindingSupport.addValidationRule(new EvenNumberOfCharacters());
+ target.setValue("odd");
+
+ assertEquals(1, markable.getMarkers().size());
+ assertTrue(markable.getMarkers().iterator().next() instanceof ErrorMarker);
+
+ valueBindingSupport.addValidationMessage("TestMessage1");
+
+ assertEquals(2, markable.getMarkers().size());
+ assertMessageMarkers("TestMessage1");
+
+ MessageMarker messageMarker = new MessageMarker("TestMessage2");
+ valueBindingSupport.addValidationMessage(messageMarker);
+
+ assertEquals(3, markable.getMarkers().size());
+ assertMessageMarkers("TestMessage1", "TestMessage2");
+
+ valueBindingSupport.removeValidationMessage("TestMessage1");
+
+ assertEquals(2, markable.getMarkers().size());
+ assertMessageMarkers("TestMessage2");
+
+ valueBindingSupport.removeValidationMessage(messageMarker);
+
+ assertEquals(1, markable.getMarkers().size());
+ assertTrue(markable.getMarkers().iterator().next() instanceof ErrorMarker);
+ }
+
+ public void testSpecialValidationMessages() throws Exception {
+
+ EvenNumberOfCharacters evenNumberOfCharacters = new EvenNumberOfCharacters();
+ NotEndingWithDisaster notEndingWithDisaster = new NotEndingWithDisaster();
+ valueBindingSupport.addValidationRule(evenNumberOfCharacters);
+ valueBindingSupport.addValidationRule(notEndingWithDisaster);
+ valueBindingSupport.addValidationMessage("TestNotEvenMessage1", evenNumberOfCharacters);
+ valueBindingSupport.addValidationMessage(new MessageMarker("TestNotEvenMessage2"), evenNumberOfCharacters);
+ valueBindingSupport.addValidationMessage("TestDisasterMessage", notEndingWithDisaster);
+
+ assertEquals(0, markable.getMarkers().size());
+
+ target.setValue("Disaster");
+
+ assertEquals(2, markable.getMarkers().size());
+ assertMessageMarkers("TestDisasterMessage");
+
+ System.out.println("Disaster Area...");
+
+ target.setValue("Disaster Area");
+
+ // /////////////////////////////////////////////////////////////////////////
+ //
+ // Hallo Carsten!
+ // Hier werden offenbar alle Marker gesetzt... Finde heraus, wieso...
+ //
+ // /////////////////////////////////////////////////////////////////////////
+
+ assertEquals(3, markable.getMarkers().size());
+ assertMessageMarkers("TestNotEvenMessage1", "TestNotEvenMessage2");
+
+ target.setValue("We are teetering on the brink of disaster");
+
+ assertEquals(4, markable.getMarkers().size());
+ assertMessageMarkers("TestNotEvenMessage1", "TestNotEvenMessage2", "TestDisasterMessage");
+
+ target.setValue("Save again");
+
+ assertEquals(0, markable.getMarkers().size());
+ }
+
+ void assertMessageMarkers(String... messages) {
+ Collection<String> missingMessages = new ArrayList<String>(Arrays.asList(messages));
+
+ for (IMessageMarker messageMarker : markable.getMarkersOfType(IMessageMarker.class)) {
+ missingMessages.remove(messageMarker.getMessage());
+ }
+
+ assertTrue("missing MessageMarker for " + missingMessages, missingMessages.isEmpty());
+ }
+
+ private class EvenNumberOfCharacters implements IValidationRule {
+
+ public IStatus validate(final Object value) {
+ if (value == null) {
+ return ValidationRuleStatus.ok();
+ }
+ if (value instanceof String) {
+ final String string = (String) value;
+ if (string.length() % 2 == 0) {
+ return ValidationRuleStatus.ok();
+ }
+ return ValidationRuleStatus.error(false, "Odd number of characters.", this);
+ }
+ throw new ValidationFailure(getClass().getName() + " can only validate objects of type "
+ + String.class.getName());
+ }
+
+ public ValidationTime getValidationTime() {
+ return ValidationTime.ON_UPDATE_TO_MODEL;
+ }
+
+ }
+
+ private class NotEndingWithDisaster implements IValidationRule {
+
+ public IStatus validate(final Object value) {
+ if (value == null) {
+ return ValidationRuleStatus.ok();
+ }
+ if (value instanceof String) {
+ final String string = (String) value;
+ if (!string.toLowerCase().endsWith("disaster")) {
+ return ValidationRuleStatus.ok();
+ }
+ return ValidationRuleStatus.error(false, "It ends with disaster.", this);
+ }
+ throw new ValidationFailure(getClass().getName() + " can only validate objects of type "
+ + String.class.getName());
+ }
+
+ public ValidationTime getValidationTime() {
+ return ValidationTime.ON_UPDATE_TO_MODEL;
+ }
+
+ }
+
+}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java
index 79314af..0efbe47 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewerTest.java
@@ -16,9 +16,9 @@ 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.IStatusbarRidget;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.FocusListener;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
@@ -87,10 +87,6 @@ public class StatusbarMessageMarkerViewerTest extends TestCase {
super.tearDown();
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testHandleFocusEvents() throws Exception {
String testErrorMessage = "Test Error in Adapter 1";
@@ -108,26 +104,11 @@ public class StatusbarMessageMarkerViewerTest extends TestCase {
statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
EasyMock.replay(statusbarRidget);
- text2.addFocusListener(new FocusListener() {
-
- public void focusLost(org.eclipse.swt.events.FocusEvent e) {
- System.out.println("FL");
- }
-
- public void focusGained(org.eclipse.swt.events.FocusEvent e) {
- System.out.println("FG");
- }
- });
-
text2.setFocus();
EasyMock.verify(statusbarRidget);
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testHandleFocusEventsAndModifiedMessage() throws Exception {
String testErrorMessage = "Test Error in Adapter 1";
@@ -190,10 +171,6 @@ public class StatusbarMessageMarkerViewerTest extends TestCase {
EasyMock.verify(statusbarRidget);
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testRemoveRidget() throws Exception {
String testErrorMessage = "Test Error in Adapter 1";
@@ -221,4 +198,118 @@ public class StatusbarMessageMarkerViewerTest extends TestCase {
EasyMock.verify(statusbarRidget);
}
+ public void testAddAndRemoveMarkerType() throws Exception {
+
+ EasyMock.replay(statusbarRidget);
+
+ String messageDifferentType = "TestDifferentMarkerType";
+ ridget2.addMarker(new MessageMarker(messageDifferentType));
+
+ statusbarMessageMarkerViewer.addMarkerType(MessageMarker.class);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
+ statusbarRidget.setMessage(messageDifferentType);
+ EasyMock.replay(statusbarRidget);
+
+ text2.setFocus();
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(messageDifferentType);
+ statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.removeMarkerType(MessageMarker.class);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
+ statusbarRidget.setMessage(messageDifferentType);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.addMarkerType(MessageMarker.class);
+
+ EasyMock.verify(statusbarRidget);
+ }
+
+ public void testSetVisible() throws Exception {
+
+ String testErrorMessage = "Test Error in Adapter 1";
+
+ statusbarMessageMarkerViewer.setVisible(false);
+ ridget1.addMarker(new ErrorMessageMarker(testErrorMessage));
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
+ statusbarRidget.setMessage(testErrorMessage);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.setVisible(true);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(testErrorMessage);
+ statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
+ EasyMock.replay(statusbarRidget);
+
+ statusbarMessageMarkerViewer.setVisible(false);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.replay(statusbarRidget);
+
+ text2.setFocus();
+ text1.setFocus();
+
+ EasyMock.verify(statusbarRidget);
+ }
+
+ public void testTwoMarkers() throws Exception {
+
+ String testErrorMessage1 = "Test Error 1 in Adapter 1";
+ ErrorMessageMarker marker1 = new ErrorMessageMarker(testErrorMessage1);
+ statusbarMessageMarkerViewer.addMarkerType(MessageMarker.class);
+ String testErrorMessage2 = "Test Error 2 in Adapter 1";
+ MessageMarker marker2 = new MessageMarker(testErrorMessage2);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(EMPTY_STATUSBAR_MESSAGE);
+ statusbarRidget.setMessage(testErrorMessage1);
+ EasyMock.replay(statusbarRidget);
+
+ ridget1.addMarker(marker1);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ statusbarRidget.setMessage(testErrorMessage1 + " " + testErrorMessage2);
+ EasyMock.replay(statusbarRidget);
+
+ ridget1.addMarker(marker2);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ statusbarRidget.setMessage(testErrorMessage2);
+ EasyMock.replay(statusbarRidget);
+
+ ridget1.removeMarker(marker1);
+
+ EasyMock.verify(statusbarRidget);
+ EasyMock.reset(statusbarRidget);
+
+ EasyMock.expect(statusbarRidget.getMessage()).andReturn(testErrorMessage2);
+ statusbarRidget.setMessage(EMPTY_STATUSBAR_MESSAGE);
+ EasyMock.replay(statusbarRidget);
+
+ ridget1.removeMarker(marker2);
+
+ 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
index 1d96ad6..9878560 100644
--- 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
@@ -61,10 +61,6 @@ public class TooltipMessageMarkerViewerTest extends TestCase {
super.tearDown();
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testSetMessage() throws Exception {
assertNull(ridget.getToolTipText());
@@ -78,10 +74,6 @@ public class TooltipMessageMarkerViewerTest extends TestCase {
assertNull(ridget.getToolTipText());
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testSetMessageExistingTooltip() throws Exception {
String existingTooltip = "TestExistingTooltip";
@@ -97,10 +89,6 @@ public class TooltipMessageMarkerViewerTest extends TestCase {
assertEquals(existingTooltip, ridget.getToolTipText());
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
public void testAddRidgetWithMarker() throws Exception {
TextRidget anotherRidget = new TextRidget();
@@ -115,11 +103,7 @@ public class TooltipMessageMarkerViewerTest extends TestCase {
assertNull(anotherRidget.getToolTipText());
}
- /**
- * @throws Exception
- * Handled by JUnit.
- */
- public void testAddMarkerType() throws Exception {
+ public void testAddAndRemoveMarkerType() throws Exception {
TextRidget anotherRidget = new TextRidget();
String anotherMessage = "TestAnotherMessage";
@@ -139,4 +123,39 @@ public class TooltipMessageMarkerViewerTest extends TestCase {
assertNull(anotherRidget.getToolTipText());
}
+ public void testVisible() throws Exception {
+
+ ridget.addMarker(errorMessageMarker);
+
+ tooltipMessageMarkerViewer.setVisible(false);
+
+ assertNull(ridget.getToolTipText());
+
+ tooltipMessageMarkerViewer.setVisible(true);
+
+ assertEquals(errorMessage, ridget.getToolTipText());
+ }
+
+ public void testSetMessageTwoMarkers() throws Exception {
+
+ assertNull(ridget.getToolTipText());
+
+ ridget.addMarker(errorMessageMarker);
+ String secondMessage = "TestASecondMarker";
+ MessageMarker secondMarker = new MessageMarker(secondMessage);
+ tooltipMessageMarkerViewer.addMarkerType(MessageMarker.class);
+ ridget.addMarker(secondMarker);
+
+ assertEquals(errorMessage + "; " + secondMessage, ridget.getToolTipText());
+
+ ridget.removeMarker(errorMessageMarker);
+
+ assertEquals(secondMessage, ridget.getToolTipText());
+
+ ridget.removeMarker(secondMarker);
+
+ assertEquals(null, ridget.getToolTipText());
+ assertNull(ridget.getToolTipText());
+ }
+
}
diff --git a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/validation/tests/ValidatorCollectionTest.java b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/validation/tests/ValidatorCollectionTest.java
index a9c9c48..07f9439 100644
--- a/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/validation/tests/ValidatorCollectionTest.java
+++ b/org.eclipse.riena.tests/src/org/eclipse/riena/ui/ridgets/validation/tests/ValidatorCollectionTest.java
@@ -37,13 +37,13 @@ public class ValidatorCollectionTest extends TestCase {
private static final IValidator ALWAYS_FAIL_1 = new IValidator() {
public IStatus validate(final Object value) {
- return ValidationRuleStatus.error(false, "always fails");
+ return ValidationRuleStatus.error(false, "always fails", this);
}
};
private static final IValidator ALWAYS_FAIL_2 = new IValidator() {
public IStatus validate(final Object value) {
- return ValidationRuleStatus.error(false, "always fails");
+ return ValidationRuleStatus.error(false, "always fails", this);
}
};
diff --git a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractEditableRidget.java b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractEditableRidget.java
index 21f7146..90d5082 100644
--- a/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractEditableRidget.java
+++ b/org.eclipse.riena.ui.ridgets.swt/src/org/eclipse/riena/internal/ui/ridgets/swt/AbstractEditableRidget.java
@@ -16,6 +16,7 @@ import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
import org.eclipse.riena.ui.ridgets.IEditableRidget;
import org.eclipse.riena.ui.ridgets.IValidationCallback;
import org.eclipse.riena.ui.ridgets.validation.IValidationRuleStatus;
@@ -57,9 +58,10 @@ public abstract class AbstractEditableRidget extends AbstractValueRidget impleme
* @see IValidationCallback#validationRulesChecked(IStatus)
*
* @param status
- * The result of validation.
+ * The result of validation.
*/
public void validationRulesChecked(IStatus status) {
+ getValueBindingSupport().validationRulesChecked(status);
if (status.isOK()) {
setErrorMarked(false);
} else {
@@ -96,4 +98,37 @@ public abstract class AbstractEditableRidget extends AbstractValueRidget impleme
}
}
}
+
+ public void addValidationMessage(IMessageMarker messageMarker, IValidator validationRule) {
+ getValueBindingSupport().addValidationMessage(messageMarker, validationRule);
+ }
+
+ public void addValidationMessage(IMessageMarker messageMarker) {
+ getValueBindingSupport().addValidationMessage(messageMarker);
+ }
+
+ public void addValidationMessage(String message, IValidator validationRule) {
+ getValueBindingSupport().addValidationMessage(message, validationRule);
+ }
+
+ public void addValidationMessage(String message) {
+ getValueBindingSupport().addValidationMessage(message);
+ }
+
+ public void removeValidationMessage(IMessageMarker messageMarker, IValidator validationRule) {
+ getValueBindingSupport().removeValidationMessage(messageMarker, validationRule);
+ }
+
+ public void removeValidationMessage(IMessageMarker messageMarker) {
+ getValueBindingSupport().removeValidationMessage(messageMarker);
+ }
+
+ public void removeValidationMessage(String message, IValidator validationRule) {
+ getValueBindingSupport().removeValidationMessage(message, validationRule);
+ }
+
+ public void removeValidationMessage(String message) {
+ getValueBindingSupport().removeValidationMessage(message);
+ }
+
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IEditableRidget.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IEditableRidget.java
index 09f06f4..ae6dc75 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IEditableRidget.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/IEditableRidget.java
@@ -14,6 +14,7 @@ import java.util.Collection;
import org.eclipse.core.databinding.conversion.IConverter;
import org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
import org.eclipse.riena.ui.ridgets.validation.IValidationRule;
import org.eclipse.riena.ui.ridgets.validation.IValidationRuleStatus;
@@ -24,7 +25,7 @@ public interface IEditableRidget extends IValueRidget, IValidationCallback {
/**
* @return The converter used when updating from the UI-control to the
- * model.
+ * model.
*/
IConverter getUIControlToModelConverter();
@@ -32,7 +33,7 @@ public interface IEditableRidget extends IValueRidget, IValidationCallback {
* Sets the converter used when updating from the UI-control to the model.
*
* @param converter
- * The new converter.
+ * The new converter.
*/
void setUIControlToModelConverter(IConverter converter);
@@ -54,9 +55,9 @@ public interface IEditableRidget extends IValueRidget, IValidationCallback {
* @see IValidationRuleStatus
*
* @param validationRule
- * The validation rule to add (non-null).
+ * The validation rule to add (non-null).
* @throws RuntimeException
- * if validationRule is null.
+ * if validationRule is null.
*/
void addValidationRule(IValidator validationRule);
@@ -64,8 +65,100 @@ public interface IEditableRidget extends IValueRidget, IValidationCallback {
* Removes a validator.
*
* @param validationRule
- * The validation rule to remove.
+ * The validation rule to remove.
*/
void removeValidationRule(IValidator validationRule);
+ /**
+ * Adds a message to be displayed when any validation rule of the ridget
+ * fails.
+ *
+ * @param message
+ * A message related to the failed validation.
+ */
+ void addValidationMessage(String message);
+
+ /**
+ * Adds a message to be displayed when the specified validation rule fails.
+ * This will not add the rule to the ridget. If the specified rule was not
+ * added to the ridget the message will never be displayed.
+ *
+ * @see #addValidationRule(IValidator)
+ * @param message
+ * A message related to the failed validation.
+ * @param validationRule
+ * The validation rule related to the message.
+ */
+ void addValidationMessage(String message, IValidator validationRule);
+
+ /**
+ * Adds an IMessageMarker to be added to the ridget automatically when and
+ * only when a validation rule fails.
+ *
+ * @see org.eclipse.riena.core.marker.IMarkable#addMarker(org.eclipse.riena.core.marker.IMarker)
+ * @see org.eclipse.riena.core.marker.IMarkable#removeMarker(org.eclipse.riena.core.marker.IMarker)
+ * @param messageMarker
+ * An IMessageMarker related to the failed validation.
+ */
+ void addValidationMessage(IMessageMarker messageMarker);
+
+ /**
+ * Adds an IMessageMarker to be added to the ridget automatically when and
+ * only when the specified validation rule fails. This will not add the rule
+ * to the ridget. If the specified rule was not added to the ridget the
+ * message will never be displayed.
+ *
+ * @see #addValidationRule(IValidator)
+ * @see org.eclipse.riena.core.marker.IMarkable#addMarker(org.eclipse.riena.core.marker.IMarker)
+ * @see org.eclipse.riena.core.marker.IMarkable#removeMarker(org.eclipse.riena.core.marker.IMarker)
+ * @param messageMarker
+ * An IMessageMarker related to the failed validation.
+ * @param validationRule
+ * The validation rule related to the IMessageMarker.
+ */
+ void addValidationMessage(IMessageMarker messageMarker, IValidator validationRule);
+
+ /**
+ * Removes a message to be displayed when any validation rule of the ridget
+ * fails. If the message was never added this method does nothing.
+ *
+ * @param message
+ * The message to remove.
+ */
+ void removeValidationMessage(String message);
+
+ /**
+ * Removes a message to be displayed when the specified validation rule of
+ * the ridget fails. If the message was never added this method does
+ * nothing.
+ *
+ * @param message
+ * The message to remove.
+ * @param validationRule
+ * The validation rule related to the message.
+ */
+ void removeValidationMessage(String message, IValidator validationRule);
+
+ /**
+ * Removes an IMessageMarker to be added to the ridget automatically when
+ * and only when a validation rule fails. If the IMessageMarker was never
+ * added this method does nothing.
+ *
+ * @param messageMarker
+ * The IMessageMarker to remove.
+ */
+ void removeValidationMessage(IMessageMarker messageMarker);
+
+ /**
+ * Removes an IMessageMarker to be added to the ridget automatically when
+ * and only when the specified validation rule fails. If the IMessageMarker
+ * was never added this method does nothing.
+ *
+ * @param messageMarker
+ * The IMessageMarker to remove.
+ * @param validationRule
+ * The validation rule related to the IMessageMarker.
+ */
+ void removeValidationMessage(IMessageMarker messageMarker, IValidator validationRule);
+
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ValueBindingSupport.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ValueBindingSupport.java
index 364d795..7fe27db 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ValueBindingSupport.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/ValueBindingSupport.java
@@ -15,16 +15,21 @@ import org.eclipse.core.databinding.observable.value.IValueChangeListener;
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.riena.core.marker.IMarkable;
import org.eclipse.riena.ui.core.marker.ErrorMarker;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
+import org.eclipse.riena.ui.core.marker.MessageMarker;
import org.eclipse.riena.ui.ridgets.databinding.RidgetUpdateValueStrategy;
+import org.eclipse.riena.ui.ridgets.marker.ValidationMessageMarker;
import org.eclipse.riena.ui.ridgets.validation.IValidationRule;
+import org.eclipse.riena.ui.ridgets.validation.ValidationRuleStatus;
import org.eclipse.riena.ui.ridgets.validation.ValidatorCollection;
/**
* Helper class for Ridgets to delegate their value binding issues to.
*/
-public class ValueBindingSupport {
+public class ValueBindingSupport implements IValidationCallback {
private DataBindingContext context;
private IObservableValue targetOV;
@@ -37,6 +42,8 @@ public class ValueBindingSupport {
private ErrorMarker errorMarker = new ErrorMarker();
private IMarkable markable;
+ private Collection<ValidationMessageMarker> validationMessageMarkers = new ArrayList<ValidationMessageMarker>(0);
+ private IStatus lastValidationStatus;
public ValueBindingSupport(IObservableValue target) {
bindToTarget(target);
@@ -83,7 +90,7 @@ public class ValueBindingSupport {
* Adds a validation rule.
*
* @param validationRule
- * The validation rule to add
+ * The validation rule to add
* @return true, if the onEditValidators were changed, false otherwise
* @see #getOnEditValidators()
*/
@@ -101,7 +108,7 @@ public class ValueBindingSupport {
* Removes a validation rule.
*
* @param validationRule
- * The validation rule to remove
+ * The validation rule to remove
* @return true, if the onEditValidators were changed, false otherwise
* @see #getOnEditValidators()
*/
@@ -124,9 +131,8 @@ public class ValueBindingSupport {
}
/**
- * @see
- * org.eclipse.riena.ui.ridgets.IValueRidget#bindToModel(org.eclipse.core
- * .databinding.observable.value.IObservableValue)
+ * @see org.eclipse.riena.ui.ridgets.IValueRidget#bindToModel(org.eclipse.core
+ * .databinding.observable.value.IObservableValue)
*/
public void bindToModel(IObservableValue observableValue) {
modelOV = observableValue;
@@ -134,9 +140,8 @@ public class ValueBindingSupport {
}
/**
- * @see
- * org.eclipse.riena.ui.ridgets.IValueRidget#bindToModel(java.lang.Object,
- * java.lang.String)
+ * @see org.eclipse.riena.ui.ridgets.IValueRidget#bindToModel(java.lang.Object,
+ * java.lang.String)
*/
public void bindToModel(Object bean, String propertyName) {
modelOV = BeansObservables.observeValue(bean, propertyName);
@@ -180,6 +185,7 @@ public class ValueBindingSupport {
} else {
markable.addMarker(errorMarker);
}
+ updateValidationMessageMarkers(newStatus);
}
});
}
@@ -220,4 +226,95 @@ public class ValueBindingSupport {
&& ((IValidationRule) validationRule).getValidationTime() == IValidationRule.ValidationTime.ON_UI_CONTROL_EDITED;
}
+ private void updateValidationMessageMarkers(IStatus status) {
+ lastValidationStatus = status;
+ for (ValidationMessageMarker validationMessageMarker : validationMessageMarkers) {
+ removeValidationMessageMarker(validationMessageMarker);
+
+ if (!status.isOK()) {
+ addValidationMessageMarker(validationMessageMarker);
+ }
+ }
+ }
+
+ public void validationRulesChecked(IStatus status) {
+ updateValidationMessageMarkers(status);
+ }
+
+ public void addValidationMessage(String message) {
+ addValidationMessage(new MessageMarker(message));
+ }
+
+ public void addValidationMessage(IMessageMarker messageMarker) {
+ ValidationMessageMarker validationMessageMarker = new ValidationMessageMarker(messageMarker);
+ validationMessageMarkers.add(validationMessageMarker);
+ if (isErrorMarked()) {
+ addValidationMessageMarker(validationMessageMarker);
+ }
+ }
+
+ public void addValidationMessage(String message, IValidator validationRule) {
+ addValidationMessage(new MessageMarker(message), validationRule);
+ }
+
+ public void addValidationMessage(IMessageMarker messageMarker, IValidator validationRule) {
+ ValidationMessageMarker validationMessageMarker = new ValidationMessageMarker(messageMarker, validationRule);
+ validationMessageMarkers.add(validationMessageMarker);
+ if (isErrorMarked()) {
+ addValidationMessageMarker(validationMessageMarker);
+ }
+ }
+
+ public void removeValidationMessage(String message) {
+ removeValidationMessage(new MessageMarker(message));
+ }
+
+ public void removeValidationMessage(IMessageMarker messageMarker) {
+ ValidationMessageMarker validationMessageMarker = new ValidationMessageMarker(messageMarker);
+ validationMessageMarkers.remove(validationMessageMarker);
+ if (isErrorMarked()) {
+ removeValidationMessageMarker(validationMessageMarker);
+ }
+ }
+
+ public void removeValidationMessage(String message, IValidator validationRule) {
+ removeValidationMessage(new MessageMarker(message), validationRule);
+ }
+
+ public void removeValidationMessage(IMessageMarker messageMarker, IValidator validationRule) {
+ ValidationMessageMarker validationMessageMarker = new ValidationMessageMarker(messageMarker, validationRule);
+ validationMessageMarkers.remove(validationMessageMarker);
+ if (isErrorMarked()) {
+ removeValidationMessageMarker(validationMessageMarker);
+ }
+ }
+
+ private boolean isErrorMarked() {
+ return markable.getMarkers().contains(errorMarker);
+ }
+
+ private void addValidationMessageMarker(ValidationMessageMarker validationMessageMarker) {
+ if (validationMessageMarker.getValidationRule() == null
+ || isSourceOf(validationMessageMarker.getValidationRule(), lastValidationStatus)) {
+ markable.addMarker(validationMessageMarker);
+ }
+ }
+
+ private boolean isSourceOf(IValidator validationRule, IStatus status) {
+ if (status instanceof ValidationRuleStatus) {
+ return validationRule.equals(((ValidationRuleStatus) status).getSource());
+ } else if (status instanceof MultiStatus) {
+ for (IStatus childStatus : ((MultiStatus) status).getChildren()) {
+ if (isSourceOf(validationRule, childStatus)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void removeValidationMessageMarker(ValidationMessageMarker validationMessageMarker) {
+ markable.removeMarker(validationMessageMarker);
+ }
+
}
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 1abc580..1fd19ee 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
@@ -25,8 +25,16 @@ 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>();
+ private HashSet<Class<? extends IMessageMarker>> markerTypes;
+ private Collection<IMarkableRidget> ridgets;
+ private boolean visible;
+
+ public AbstractMessageMarkerViewer() {
+ markerTypes = new LinkedHashSet<Class<? extends IMessageMarker>>();
+ ridgets = new ArrayList<IMarkableRidget>();
+ visible = true;
+ markerTypes.add(ValidationMessageMarker.class);
+ }
/**
* @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
@@ -60,6 +68,21 @@ public abstract class AbstractMessageMarkerViewer implements IMessageMarkerViewe
showMessages();
}
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#isVisible()
+ */
+ public boolean isVisible() {
+ return visible;
+ }
+
+ /**
+ * @see org.eclipse.riena.ui.ridgets.marker.IMessageMarkerViewer#setVisible(boolean)
+ */
+ public void setVisible(boolean visible) {
+ this.visible = visible;
+ showMessages();
+ }
+
private void showMessages() {
for (IMarkableRidget ridget : ridgets) {
showMessages(ridget);
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/IMessageMarkerViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/IMessageMarkerViewer.java
index 9c0906b..41c1ae8 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/IMessageMarkerViewer.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/IMessageMarkerViewer.java
@@ -53,4 +53,19 @@ public interface IMessageMarkerViewer {
*/
void removeMarkerType(Class<? extends IMessageMarker> markerClass);
+ /**
+ * Indicates whether the visualization of the message markers is visible.
+ *
+ * @return The visible state.
+ */
+ boolean isVisible();
+
+ /**
+ * Sets the visibility of the visualization of the message markers.
+ *
+ * @param visible
+ * The new visible state.
+ */
+ void setVisible(boolean visible);
+
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java
index c022daa..27fb04e 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/StatusbarMessageMarkerViewer.java
@@ -54,16 +54,16 @@ public class StatusbarMessageMarkerViewer extends AbstractMessageMarkerViewer {
}
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) {
- setStatusbarMessage(message);
- } else {
- hideMessages(markableRidget);
+ if (markableRidget.hasFocus()) {
+ Collection messageMarker = this.getMessageMarker(markableRidget);
+ String message = constructMessage(messageMarker).trim();
+ // show the message only if there is something to show
+ if (message.length() > 0 && isVisible()) {
+ setStatusbarMessage(message);
+ } else {
+ hideMessages(markableRidget);
+ }
}
- // }
}
protected void hideMessages(IMarkableRidget ridget) {
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
index ce2ce73..00f4d18 100644
--- 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
@@ -28,7 +28,8 @@ import org.eclipse.riena.ui.ridgets.IMarkableRidget;
public class TooltipMessageMarkerViewer extends AbstractMessageMarkerViewer {
private PropertyChangeListener markerPropertyChangeListener = new MarkerPropertyChangeListener();
- private HashMap<IMarkableRidget, String> oldMessage = new LinkedHashMap<IMarkableRidget, String>();
+ private HashMap<IMarkableRidget, String> tooltipMessage = new LinkedHashMap<IMarkableRidget, String>();
+ private HashMap<IMarkableRidget, String> originalTooltipMessage = new LinkedHashMap<IMarkableRidget, String>();
/**
* @see org.eclipse.riena.ui.ridgets.marker.AbstractMessageMarkerViewer#addRidget(org.eclipse.riena.ui.ridgets.IMarkableRidget)
@@ -40,30 +41,34 @@ public class TooltipMessageMarkerViewer extends AbstractMessageMarkerViewer {
}
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) {
+ if (message.length() > 0 && isVisible()) {
+ showMessages(markableRidget, message);
+ } else {
+ hideMessages(markableRidget);
+ }
+ }
+
+ private void showMessages(IMarkableRidget markableRidget, String message) {
+ if (tooltipMessage.get(markableRidget) == null) {
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());
+ if (!message.equals(tooltiptext.trim())) {
+ originalTooltipMessage.put(markableRidget, tooltiptext.trim());
}
} else {
- oldMessage.put(markableRidget, null);
+ originalTooltipMessage.put(markableRidget, null);
}
- markableRidget.setToolTipText(message);
- } else {
- hideMessages(markableRidget);
}
- // }
+ markableRidget.setToolTipText(message);
+ tooltipMessage.put(markableRidget, message);
}
protected void hideMessages(IMarkableRidget markableRidget) {
- markableRidget.setToolTipText(oldMessage.get(markableRidget));
+ markableRidget.setToolTipText(originalTooltipMessage.get(markableRidget));
+ tooltipMessage.put(markableRidget, null);
}
private String constructMessage(Collection messageMarker) {
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/ValidationMessageMarker.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/ValidationMessageMarker.java
new file mode 100644
index 0000000..907b454
--- /dev/null
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/marker/ValidationMessageMarker.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * 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 org.eclipse.core.databinding.validation.IValidator;
+import org.eclipse.riena.core.marker.AbstractMarker;
+import org.eclipse.riena.ui.core.marker.IMessageMarker;
+
+public class ValidationMessageMarker extends AbstractMarker implements IMessageMarker {
+
+ private static final String MESSAGE_MARKER_ATTRIBUTE = "wrappedMessageMarker";
+
+ private IValidator validationRule;
+
+ public ValidationMessageMarker(IMessageMarker messageMarker) {
+ setAttribute(MESSAGE_MARKER_ATTRIBUTE, messageMarker);
+ }
+
+ public ValidationMessageMarker(IMessageMarker messageMarker, IValidator validationRule) {
+ this(messageMarker);
+ this.validationRule = validationRule;
+ }
+
+ public String getMessage() {
+ return getMessageMarker().getMessage();
+ }
+
+ public IValidator getValidationRule() {
+ return validationRule;
+ }
+
+ public IMessageMarker getMessageMarker() {
+ return (IMessageMarker) getAttribute(MESSAGE_MARKER_ATTRIBUTE);
+ }
+
+ /**
+ * @see org.eclipse.riena.core.marker.AbstractMarker#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object other) {
+ if (other instanceof ValidationMessageMarker) {
+ ValidationMessageMarker otherValidationMessageMarker = (ValidationMessageMarker) other;
+ return super.equals(other)
+ && ((getValidationRule() == null && otherValidationMessageMarker.getValidationRule() == null) || (getValidationRule() != null && getValidationRule()
+ .equals(otherValidationMessageMarker.getValidationRule())));
+ }
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/AbstractValidDate.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/AbstractValidDate.java
index 4c5ac1f..8336c16 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/AbstractValidDate.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/AbstractValidDate.java
@@ -65,7 +65,8 @@ public abstract class AbstractValidDate implements IValidationRule {
}
final String string = (String) value;
if (string.length() > 0 && !isDateValid(string, pattern)) {
- return ValidationRuleStatus.error(false, "Invalid date (must match the pattern " + pattern + ").");
+ return ValidationRuleStatus
+ .error(false, "Invalid date (must match the pattern " + pattern + ").", this);
}
}
return ValidationRuleStatus.ok();
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MaxLength.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MaxLength.java
index 9bf329f..4dcc58d 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MaxLength.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MaxLength.java
@@ -38,7 +38,7 @@ public class MaxLength implements IValidationRule {
if (length > maxLength) {
return ValidationRuleStatus.error(true, "'" + string + "' must not be longer than " + maxLength
- + " characters.");
+ + " characters.", this);
}
return ValidationRuleStatus.ok();
} else {
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MinLength.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MinLength.java
index c6d3fee..ab3ff0e 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MinLength.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/MinLength.java
@@ -30,7 +30,7 @@ public class MinLength implements IValidationRule {
if (value == null) {
if (minLength > 0) {
return ValidationRuleStatus.error(false, "rule treats null as a blank string, which is shorter than "
- + minLength + " characters.");
+ + minLength + " characters.", this);
}
return ValidationRuleStatus.ok();
}
@@ -40,7 +40,7 @@ public class MinLength implements IValidationRule {
return ValidationRuleStatus.ok();
}
return ValidationRuleStatus.error(false, "String ''" + string + "' is less than " + minLength
- + " characters long.");
+ + " characters long.", this);
}
throw new ValidationFailure(getClass().getName() + " can only validate objects of type "
+ String.class.getName());
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/RequiredField.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/RequiredField.java
index 295c4fe..216bb21 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/RequiredField.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/RequiredField.java
@@ -65,7 +65,7 @@ public class RequiredField implements IValidationRule {
*/
public IStatus validate(final Object value) {
if (value == null) {
- return ValidationRuleStatus.error(true, "Value is null.");
+ return ValidationRuleStatus.error(true, "Value is null.", this);
}
if (!(value instanceof String)) {
throw new ValidationFailure(getClass().getSimpleName() + " can only validate objects of type "
@@ -79,6 +79,6 @@ public class RequiredField implements IValidationRule {
return ValidationRuleStatus.ok();
}
}
- return ValidationRuleStatus.error(true, "'String must not be blank.");
+ return ValidationRuleStatus.error(true, "'String must not be blank.", this);
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidCharacters.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidCharacters.java
index 9e36ae7..8984985 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidCharacters.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidCharacters.java
@@ -57,7 +57,7 @@ public class ValidCharacters implements IValidationRule {
final char currentChar = string.charAt(t);
if (Arrays.binarySearch(allowedCharsSorted, currentChar) < 0) {
return ValidationRuleStatus.error(true, "Character '" + currentChar + "' in text '" + value
- + "' is not allowed.");
+ + "' is not allowed.", this);
}
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidDecimal.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidDecimal.java
index 1351655..e0d207a 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidDecimal.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidDecimal.java
@@ -89,26 +89,26 @@ public class ValidDecimal implements IValidationRule {
if (!partialCheckSupported) {
if (scanned.decimalSeperatorIndex < 0) {
return ValidationRuleStatus.error(true, "no decimal separator '"
- + symbols.getDecimalSeparator() + "' in String '" + string + '\'');
+ + symbols.getDecimalSeparator() + "' in String '" + string + '\'', this);
}
// test if grouping character is behind decimal separator:
if (scanned.groupingSeparatorIndex > scanned.decimalSeperatorIndex) {
return ValidationRuleStatus.error(true, "grouping-separator '" + symbols.getGroupingSeparator()
+ "' behind decimal-seperator '" + symbols.getDecimalSeparator() + "' in string '"
- + string + '\'');
+ + string + '\'', this);
}
}
// test if alien character present:
if (scanned.lastAlienCharIndex > -1) {
return ValidationRuleStatus.error(true, "unrecognized character '" + scanned.lastAlienCharacter
- + "' in string '" + string + '\'');
+ + "' in string '" + string + '\'', this);
}
try {
synchronized (format) {// NumberFormat not threadsafe!
format.parse(string);
}
} catch (final ParseException e) {
- return ValidationRuleStatus.error(true, "cannot parse string '" + string + "' to number.");
+ return ValidationRuleStatus.error(true, "cannot parse string '" + string + "' to number.", this);
}
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidEmailAddress.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidEmailAddress.java
index 5cc2c9e..877c945 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidEmailAddress.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidEmailAddress.java
@@ -48,7 +48,7 @@ public class ValidEmailAddress implements IValidationRule {
if (toBeChecked.length() == 0 || GenericValidator.isEmail(toBeChecked)) {
return ValidationRuleStatus.ok();
}
- return ValidationRuleStatus.error(true, "String '" + toBeChecked + "' is no valid email address");
+ return ValidationRuleStatus.error(true, "String '" + toBeChecked + "' is no valid email address", this);
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidExpression.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidExpression.java
index c70a976..73ab852 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidExpression.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidExpression.java
@@ -114,7 +114,8 @@ public class ValidExpression implements IValidationRule {
if (matcher.match("/" + pattern + "/" + options, string)) { //$NON-NLS-1$//$NON-NLS-2$
return ValidationRuleStatus.ok();
}
- return ValidationRuleStatus.error(true, "'String '" + string + "' does not match regex '" + pattern + "'.");
+ return ValidationRuleStatus.error(true, "'String '" + string + "' does not match regex '" + pattern + "'.",
+ this);
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidInteger.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidInteger.java
index 68bb6ee..328dc1b 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidInteger.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidInteger.java
@@ -91,17 +91,17 @@ public class ValidInteger extends ValidDecimal {
final ScanResult scanned = scan(string);
if (scanned.decimalSeperatorIndex >= 0) {
return ValidationRuleStatus.error(true, "no integer: decimal separator '"
- + getSymbols().getDecimalSeparator() + "' in String '" + string + '\'');
+ + getSymbols().getDecimalSeparator() + "' in String '" + string + '\'', this);
}
// test if sign present
if (!signed && scanned.minusSignIndex > -1) {
return ValidationRuleStatus.error(true, "minus sign present at position '" + scanned.minusSignIndex
- + "' in string '" + string + "' where an unsigned integer was expected.");
+ + "' in string '" + string + "' where an unsigned integer was expected.", this);
}
// test if alien character present:
if (scanned.lastAlienCharIndex > -1) {
return ValidationRuleStatus.error(true, "unrecognized character '" + scanned.lastAlienCharacter
- + "' in string '" + string + '\'');
+ + "' in string '" + string + '\'', this);
}
try {
final DecimalFormat format = getFormat();
@@ -109,7 +109,7 @@ public class ValidInteger extends ValidDecimal {
format.parse(string);
}
} catch (final ParseException e) {
- return ValidationRuleStatus.error(true, "cannot parse string '" + string + "' to number.");
+ return ValidationRuleStatus.error(true, "cannot parse string '" + string + "' to number.", this);
}
}
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidRange.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidRange.java
index 578671c..565e19f 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidRange.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidRange.java
@@ -105,14 +105,15 @@ public class ValidRange extends ValidDecimal {
} catch (final ParseException e) {
// should never occur, as super.validate(Object) will
// make this method return earlier
- return ValidationRuleStatus.error(true, "cannot parse string '" + string + "' to number.");
+ return ValidationRuleStatus
+ .error(true, "cannot parse string '" + string + "' to number.", this);
}
}
}
}
if (currentValue.compareTo(min) < 0 || currentValue.compareTo(max) > 0) {
return ValidationRuleStatus.error(true, "value " + currentValue + "' out of range: [" + min + ".." + max
- + "].");
+ + "].", this);
}
return ValidationRuleStatus.ok();
}
diff --git a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidationRuleStatus.java b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidationRuleStatus.java
index 7255848..e74b249 100644
--- a/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidationRuleStatus.java
+++ b/org.eclipse.riena.ui.ridgets/src/org/eclipse/riena/ui/ridgets/validation/ValidationRuleStatus.java
@@ -10,6 +10,7 @@
*******************************************************************************/
package org.eclipse.riena.ui.ridgets.validation;
+import org.eclipse.core.databinding.validation.IValidator;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Status;
@@ -21,8 +22,15 @@ import org.eclipse.riena.internal.ui.ridgets.Activator;
*/
public class ValidationRuleStatus extends Status implements IValidationRuleStatus {
- private ValidationRuleStatus(int severity, int code, String message) {
+ private IValidator source;
+
+ private ValidationRuleStatus(int severity, int code, String message, IValidator source) {
super(severity, Activator.PLUGIN_ID, code, message, null);
+ this.source = source;
+ }
+
+ public IValidator getSource() {
+ return source;
}
/**
@@ -43,14 +51,16 @@ public class ValidationRuleStatus extends Status implements IValidationRuleStatu
* blocked.
* @param message
* A message.
+ * @param source
+ * The validation rule that failed.
* @return An ERROR status.
*/
- public static IStatus error(boolean blocker, String message) {
+ public static IStatus error(boolean blocker, String message, IValidator source) {
int code = ERROR_ALLOW_WITH_MESSAGE;
if (blocker) {
code = ERROR_BLOCK_WITH_FLASH;
}
- return new ValidationRuleStatus(IStatus.ERROR, code, message);
+ return new ValidationRuleStatus(IStatus.ERROR, code, message, source);
}
/**