Introduce management of multivalued properties in a single table cell for String...
authorBruno Sinou <bsinou@argeo.org>
Wed, 27 Nov 2013 17:49:15 +0000 (17:49 +0000)
committerBruno Sinou <bsinou@argeo.org>
Wed, 27 Nov 2013 17:49:15 +0000 (17:49 +0000)
https://www.argeo.org/bugzilla/show_bug.cgi?id=203

git-svn-id: https://svn.argeo.org/commons/trunk@6660 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

base/runtime/org.argeo.eclipse.ui.jcr/src/main/java/org/argeo/eclipse/ui/jcr/lists/SimpleJcrNodeLabelProvider.java

index 83b081b1474ed83ed8f3a8b0a0d94eca5be0c7d2..fa755bad212b3027c3a0f4d7fafff851c70826f8 100644 (file)
@@ -17,6 +17,7 @@ import org.eclipse.jface.viewers.ColumnLabelProvider;
  * Base implementation of a label provider for widgets that display JCR Rows.
  */
 public class SimpleJcrNodeLabelProvider extends ColumnLabelProvider {
+       private static final long serialVersionUID = -5215787695436221993L;
 
        private final static String DEFAULT_DATE_FORMAT = "EEE, dd MMM yyyy";
        private final static String DEFAULT_NUMBER_FORMAT = "#,##0.0";
@@ -58,34 +59,54 @@ public class SimpleJcrNodeLabelProvider extends ColumnLabelProvider {
                try {
                        Node currNode = (Node) element;
 
-                       Value value = null;
-                       if (currNode.hasProperty(propertyName))
-                               value = currNode.getProperty(propertyName).getValue();
-                       else
-                               return "";
+                       if (currNode.hasProperty(propertyName)) {
+                               if (currNode.getProperty(propertyName).isMultiple()) {
+                                       StringBuilder builder = new StringBuilder();
+                                       for (Value value : currNode.getProperty(propertyName)
+                                                       .getValues()) {
+                                               String currStr = getSingleValueAsString(value);
+                                               if (notEmptyString(currStr))
+                                                       builder.append(currStr).append("; ");
+                                       }
+                                       if (builder.length() > 0)
+                                               builder.deleteCharAt(builder.length() - 2);
 
-                       switch (value.getType()) {
-                       case PropertyType.STRING:
-                               return value.getString();
-                       case PropertyType.BOOLEAN:
-                               return "" + value.getBoolean();
-                       case PropertyType.DATE:
-                               return dateFormat.format(value.getDate().getTime());
-                       case PropertyType.LONG:
-                               return "" + value.getLong();
-                       case PropertyType.DECIMAL:
-                               return numberFormat.format(value.getDecimal());
-                       case PropertyType.DOUBLE:
-                               return numberFormat.format(value.getDouble());
-                       default:
-                               throw new ArgeoException("Unimplemented label provider "
-                                               + "for property type " + value.getType());
-                       }
+                                       return builder.toString();
+                               } else
+                                       return getSingleValueAsString(currNode.getProperty(
+                                                       propertyName).getValue());
+                       } else
+                               return "";
                } catch (RepositoryException re) {
                        throw new ArgeoException("Unable to get text from row", re);
                }
        }
 
+       private String getSingleValueAsString(Value value)
+                       throws RepositoryException {
+               switch (value.getType()) {
+               case PropertyType.STRING:
+                       return value.getString();
+               case PropertyType.BOOLEAN:
+                       return "" + value.getBoolean();
+               case PropertyType.DATE:
+                       return dateFormat.format(value.getDate().getTime());
+               case PropertyType.LONG:
+                       return "" + value.getLong();
+               case PropertyType.DECIMAL:
+                       return numberFormat.format(value.getDecimal());
+               case PropertyType.DOUBLE:
+                       return numberFormat.format(value.getDouble());
+               default:
+                       throw new ArgeoException("Unimplemented label provider "
+                                       + "for property type " + value.getType());
+               }
+       }
+
+       private boolean notEmptyString(String string) {
+               return string != null && !"".equals(string.trim());
+       }
+
        public void setDateFormat(String dateFormatPattern) {
                dateFormat = new SimpleDateFormat(dateFormatPattern);
        }