incubator-odf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From svanteschub...@apache.org
Subject svn commit: r1714431 - in /incubator/odf/trunk/simple/src: main/java/org/odftoolkit/simple/table/Cell.java test/java/org/odftoolkit/simple/table/TableCellTest.java
Date Sun, 15 Nov 2015 11:33:02 GMT
Author: svanteschubert
Date: Sun Nov 15 11:33:02 2015
New Revision: 1714431

URL: http://svn.apache.org/viewvc?rev=1714431&view=rev
Log:
#ODFTOOLKIT-410# implemented by Raimund Hölle - Set table:error-message for content-validation
to activate actual validation

Modified:
    incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java
    incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java

Modified: incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java?rev=1714431&r1=1714430&r2=1714431&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java (original)
+++ incubator/odf/trunk/simple/src/main/java/org/odftoolkit/simple/table/Cell.java Sun Nov
15 11:33:02 2015
@@ -39,6 +39,7 @@ import javax.swing.JTextField;
 import org.odftoolkit.odfdom.dom.OdfDocumentNamespace;
 import org.odftoolkit.odfdom.dom.attribute.fo.FoTextAlignAttribute;
 import org.odftoolkit.odfdom.dom.attribute.office.OfficeValueTypeAttribute;
+import org.odftoolkit.odfdom.dom.attribute.table.TableMessageTypeAttribute;
 import org.odftoolkit.odfdom.dom.element.OdfStylableElement;
 import org.odftoolkit.odfdom.dom.element.OdfStyleBase;
 import org.odftoolkit.odfdom.dom.element.dc.DcCreatorElement;
@@ -53,6 +54,7 @@ import org.odftoolkit.odfdom.dom.element
 import org.odftoolkit.odfdom.dom.element.table.TableContentValidationElement;
 import org.odftoolkit.odfdom.dom.element.table.TableContentValidationsElement;
 import org.odftoolkit.odfdom.dom.element.table.TableCoveredTableCellElement;
+import org.odftoolkit.odfdom.dom.element.table.TableErrorMessageElement;
 import org.odftoolkit.odfdom.dom.element.table.TableHelpMessageElement;
 import org.odftoolkit.odfdom.dom.element.table.TableTableCellElement;
 import org.odftoolkit.odfdom.dom.element.table.TableTableCellElementBase;
@@ -2383,6 +2385,10 @@ public class Cell extends Component impl
 	/**
 	 * Specifies the allowed values of this cell in a list. Any value out of
 	 * this list is invalid.
+   * <p>
+   * NOTE: The validity list is per default only used for a drop down box
+   * to select possible values. Validation error messages can be enabled
+   * by {@code setInputErrorMessage()}.
 	 * <p>
 	 * NOTE: Now, the validity rule does not take effect when a cell value
 	 * is updated by Simple ODF API yet.
@@ -2390,6 +2396,8 @@ public class Cell extends Component impl
 	 * @param values
 	 *            the list of allowed values.
 	 * @since 0.6
+   *
+   * @see #setInputErrorMessage(String, String, String)
 	 */
 	public void setValidityList(List<String> values) {
 		try {
@@ -2440,6 +2448,53 @@ public class Cell extends Component impl
 		}
 	}
 
+  /**
+   * Sets the title and text of the message box which will
+   * be displayed if if invalid input is entered into the cell.
+   * <p>
+   * This message has only effect if a content validation is
+   * active for the cell, e. g. by setting a validation list.
+   *
+   * @param title Title of the message box. May be {@code null} for using
+   *              default title.
+   * @param text Text of the message box. May be {@code null} for using
+   *             default message.
+   * @param messageType The severity of the message. If {@code null}, the
+   *                    default is used ("stop"). Allowed values are enumerated
+   *                    by {@code TableMessageTypeAttribute.Value}: {@code "stop"}
+   *                    (Default), {@code "warning"}, {@code "information"}.
+   * @since 0.8.2
+   *
+   * @see #setValidityList(List)
+   * @see TableMessageTypeAttribute.Value
+   */
+  public void setInputErrorMessage(String title, String text, String messageType) {
+    try {
+      TableContentValidationElement validationElement = getContentValidationEle();
+      TableErrorMessageElement errorMessageElement = OdfElement.findFirstChildNode(TableErrorMessageElement.class,
+          validationElement);
+      if (errorMessageElement != null) {
+        validationElement.removeChild(errorMessageElement);
+      }
+      errorMessageElement = validationElement.newTableErrorMessageElement();
+      errorMessageElement.setTableDisplayAttribute(true);
+      if (title != null) {
+        errorMessageElement.setTableTitleAttribute(title);
+      }
+      if (text != null) {
+         errorMessageElement.newTextPElement().setTextContent(text);
+      }
+      if (messageType == null) {
+        messageType = TableMessageTypeAttribute.DEFAULT_VALUE;
+      }
+      errorMessageElement.setTableMessageTypeAttribute(messageType);
+
+    } catch (Exception e) {
+      Logger.getLogger(Cell.class.getName()).log(Level.SEVERE, null, e);
+    }
+  }
+
+
 	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
 	//////////////////////////////////////// private methods ///////////////////////////////////////////////////////////
 	///////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Modified: incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
URL: http://svn.apache.org/viewvc/incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java?rev=1714431&r1=1714430&r2=1714431&view=diff
==============================================================================
--- incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
(original)
+++ incubator/odf/trunk/simple/src/test/java/org/odftoolkit/simple/table/TableCellTest.java
Sun Nov 15 11:33:02 2015
@@ -1432,6 +1432,24 @@ public class TableCellTest {
 		}
 	}
 
+  @Test
+  public void testSetValidityListAndInputErrorMessage() {
+    try {
+      int rowindex = 3, columnindex = 2;
+      Table table = odsdoc.getTableByName("Sheet2");
+      Cell fcell = table.getCellByPosition(columnindex, rowindex);
+      List<String> values = new ArrayList<String>(Arrays.asList("Mon", "Tue",
"Wed", "Thu", "Fri"));
+      fcell.setValidityList(values);
+      fcell.setInputErrorMessage("Error message", "This cell only allows working days.",
null);
+      fcell.setStringValue("Tue");
+      Assert.assertNotNull(fcell.getOdfElement().getTableContentValidationNameAttribute());
+      saveods();
+    } catch (Exception e) {
+      Logger.getLogger(TableCellTest.class.getName()).log(Level.SEVERE, null, e);
+      Assert.fail(e.getMessage());
+    }
+  }
+
 	private void compareResults(Element element, String input, String[] output) {
 		int i;
 		int nSpaces;



Mime
View raw message