UIB: added "getNewIdProperty" method in Part 69/21769/1
authoryoungduk.hwang <youngduk.hwang@samsung.com>
Tue, 27 May 2014 14:24:25 +0000 (23:24 +0900)
committeryoungduk.hwang <youngduk.hwang@samsung.com>
Tue, 27 May 2014 14:24:25 +0000 (23:24 +0900)
Now we can know a part's IdProperty before the part is added. Then
unnecessary PropertyChanged event won't be fired.

Change-Id: I26846cfef82da43864d96fad0176bd82a01d6204
Signed-off-by: youngduk.hwang <youngduk.hwang@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/commands/CreatePageCommand.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/WidgetValidator.java

index 955ec8b..b1405e8 100644 (file)
@@ -29,6 +29,7 @@ import java.util.List;
 import org.eclipse.gef.commands.Command;
 import org.tizen.webuibuilder.BuilderConstants;
 import org.tizen.webuibuilder.model.Part;
+import org.tizen.webuibuilder.model.WidgetValidator;
 import org.tizen.webuibuilder.model.app.AppManagerForHTML;
 import org.tizen.webuibuilder.model.filedata.PageFileData;
 import org.tizen.webuibuilder.model.page.PageData;
@@ -58,6 +59,19 @@ public class CreatePageCommand extends Command {
                pageDatas = new ArrayList<PageData>(size);
                
                for(int i = 0; i < size; i++) {
+                       String propertyId = pageFileData.getName(i);
+                       Part part = pageFileData.getRootPart(i);
+                       Part baseRootPart = appManager.getPageDataSet().getBaseRootPart();
+                       
+                       if ( propertyId == null ||
+                    (propertyId != null && 
+                     !part.canSetPropertyValue(baseRootPart, BuilderConstants.PROPERTY_ID, propertyId).equals(WidgetValidator.OK))) {
+                               String newId = part.getNewIdProperty(baseRootPart);
+                       part.setPropertyValue(BuilderConstants.PROPERTY_ID, newId, false);
+                       pageFileData.setName(i, newId);
+                       part.getElement().setAttribute(BuilderConstants.PROPERTY_ID, newId);
+                       }
+                       
                        PageData pageData = new PageDataForHTML(BuilderConstants.EMPTY,
                                        pageFileData, i, appManager.getDocument(),
                                        appManager.getDescriptorManager(), null);
index cc14cef..8b7a4f0 100644 (file)
@@ -1077,6 +1077,21 @@ public class Part implements ISerializer {
     public String canSetPropertyValue(String propertyName, String value) {
         return new WidgetValidator().canSetPropertyValue(this, propertyName, value);
     }
+    
+    /**
+     * Returns OK if property value can be set.
+     * 
+     * @param parent
+     *            a part to be parent {@link Part}
+     * @param propertyName
+     *            a property name
+     * @param value
+     *            a property value
+     * @return OK if property value can be set, and error message otherwise
+     */
+    public String canSetPropertyValue(Part parent, String propertyName, String value) {
+        return new WidgetValidator().canSetPropertyValue(this, parent, propertyName, value);
+    }
 
     /**
      * Returns OK if property value can be set.
@@ -2912,4 +2927,18 @@ public class Part implements ISerializer {
         return editSelectorMap;
     }
 
+    public String getNewIdProperty(Part parent) {
+       // Sets property id by using descriptor id and index.
+        String descriptorId = this.getDescriptorId();
+        int beginIndex = descriptorId.indexOf(BuilderConstants.DOT, 0) + 1;
+        int endIndex = descriptorId.length();
+        String id = descriptorId.substring(beginIndex, endIndex);
+
+        int idIndex = 1;
+        while (this.canSetPropertyValue(parent, PROPERTY_ID, id + String.valueOf(idIndex)) != WidgetValidator.OK) {
+            idIndex++;
+        }
+        
+        return id + String.valueOf(idIndex);
+    }
 }
index 15af7ff..ad126d2 100644 (file)
@@ -104,7 +104,25 @@ public class WidgetValidator {
      * @return OK if property value can be set, and error message otherwise
      */
     public String canSetPropertyValue(Part part, String propertyName, String value) {
-        if (part == null) {
+       return canSetPropertyValue(part, null, propertyName, value);
+    }
+
+    /**
+     * Returns OK if property value can be set.
+     * 
+     * @param part
+     *            a {@link Part}
+     * @param parent
+     *            a part to be parent {@link Part}
+     * @param propertyName
+     *            a property name
+     * @param value
+     *            a property value
+     * @return OK if property value can be set, and error message otherwise
+     */
+       public String canSetPropertyValue(Part part, Part parent,
+                       String propertyName, String value) {
+               if (part == null) {
             // This case should not be happened.
             return ERROR;
         }
@@ -139,12 +157,12 @@ public class WidgetValidator {
                 break;
         }
 
-        String message = checkPropertyConditions(part, desc.getConditionDescriptors(), value);
+        String message = checkPropertyConditions(part, parent, desc.getConditionDescriptors(), value);
 
         return message;
-    }
+       }
 
-    /**
+       /**
      * Returns OK if property value can be set.
      * 
      * @param condition
@@ -294,97 +312,112 @@ public class WidgetValidator {
      * 
      * @param part
      *            a {@link Part}
+     * @param parent
+     *            a part to be parent {@link Part}            
      * @param conditions
      *            a List containing {@link ConditionDescriptor}
      * @param value
      *            a property value to check validity
      * @return OK if property condition is valid, and error message otherwise
      */
-    private String checkPropertyConditions(Part part, List<PropertyConditionDescriptor> conditions,
-                                           String value) {
-        if (conditions == null) {
+    private String checkPropertyConditions(Part part, Part parent,
+                       List<PropertyConditionDescriptor> conditions, String value) {
+       if (conditions == null) {
             // This case should not be happened.
             return ERROR;
         }
-
-        int size = conditions.size();
+        
+       int size = conditions.size();
         if (size == 0) {
             return OK;
         }
 
         for (int i = 0; i < size; i++) {
-            String message = checkPropertyCondition(part, conditions.get(i), value);
+            String message = checkPropertyCondition(part, parent, conditions.get(i), value);
             if (message != OK) {
                 return message;
             }
         }
 
         return OK;
-    }
+       }
 
     /**
      * Returns OK if property condition is valid.
      * 
      * @param part
      *            a {@link Part}
+     * @param parent
+     *            a part to be parent {@link Part}
      * @param condition
      *            a {@link ConditionDescriptor}
      * @param value
      *            a property value to check validity
      * @return OK if property condition is valid, and error message otherwise
      */
-    private String checkPropertyCondition(Part part, PropertyConditionDescriptor condition,
-                                          String value) {
-        if (part == null || condition == null || value == null) {
-            // This case should not be happened.
-            return ERROR;
-        }
-
-        String name = condition.getName();
-        String error = condition.getError();
-
-        if (name.equals(PropertyConditionDescriptor.STRING_ID)) {
-            if (!checkIdValue(value)) {
-                return BuilderMessages.ERROR_ID_INVALID;
-            }
-            Part doc = part.getOwnerDocument();
-            if (doc != null) {
-                if (!searchUsedPropertyValue(part, doc, BuilderConstants.PROPERTY_ID, value, false)) {
-                    return getErrorMessage(error);
-                }
-            }
-
-            Part pagepart = part.getOwnerPage();
-            if (pagepart != null) {
-                if (!searchUsedPropertyValue(part, pagepart, BuilderConstants.PROPERTY_ID, value,
-                                             true)) {
-                    return getErrorMessage(error);
-                }
-            }
-        } else if (name.equals(PropertyConditionDescriptor.STRING_MAX_LENGTH)) {
-            String conditionValue = condition.getValue();
-            int length = Long.valueOf(conditionValue).intValue();
-
-            if (value.length() > length) {
-                return NLS.bind(getErrorMessage(error), conditionValue);
-            }
-        } else if (name.equals(PropertyConditionDescriptor.INTEGER_MIN)) {
-            String conditionValue = condition.getValue();
-
-            if (!checkMinValue(value, conditionValue)) {
-                return NLS.bind(getErrorMessage(error), conditionValue);
-            }
-        } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX)) {
-            String conditionValue = condition.getValue();
-
-            if (!checkMaxValue(value, conditionValue)) {
-                return NLS.bind(getErrorMessage(error), conditionValue);
-            }
-        }
-
-        return OK;
+    private String checkPropertyCondition(Part part, Part parent,  
+                                                                         PropertyConditionDescriptor condition, String value) {
+       if (part == null || condition == null || value == null) {
+               // This case should not be happened.
+               return ERROR;
+       }
+
+       String name = condition.getName();
+       String error = condition.getError();
+
+       if (name.equals(PropertyConditionDescriptor.STRING_ID)) {
+               if (!checkIdValue(value)) {
+                       return BuilderMessages.ERROR_ID_INVALID;
+               }
+               
+               Part docPart = null;
+               Part pagePart = null;
+               
+               if(parent != null) {
+                       docPart = (part.isDocumentPart()) ? part : parent.getOwnerDocument();
+                       pagePart = (part.isPagePart()) ? part : parent.getOwnerPage();
+               } else {
+                       docPart = part.getOwnerDocument();
+                       pagePart = part.getOwnerPage();
+               }
+               
+               if (docPart != null) {
+                       if (!searchUsedPropertyValue(part, docPart, BuilderConstants.PROPERTY_ID, value, false)) {
+                               return getErrorMessage(error);
+                       }
+               }
+
+               if (pagePart != null) {
+                       if (!searchUsedPropertyValue(part, pagePart, BuilderConstants.PROPERTY_ID, value,
+                                       true)) {
+                               return getErrorMessage(error);
+                       }
+               }
+       } else if (name.equals(PropertyConditionDescriptor.STRING_MAX_LENGTH)) {
+               String conditionValue = condition.getValue();
+               int length = Long.valueOf(conditionValue).intValue();
+
+               if (value.length() > length) {
+                       return NLS.bind(getErrorMessage(error), conditionValue);
+               }
+       } else if (name.equals(PropertyConditionDescriptor.INTEGER_MIN)) {
+               String conditionValue = condition.getValue();
+
+               if (!checkMinValue(value, conditionValue)) {
+                       return NLS.bind(getErrorMessage(error), conditionValue);
+               }
+       } else if (name.equals(PropertyConditionDescriptor.INTEGER_MAX)) {
+               String conditionValue = condition.getValue();
+
+               if (!checkMaxValue(value, conditionValue)) {
+                       return NLS.bind(getErrorMessage(error), conditionValue);
+               }
+       }
+
+       return OK;
     }
 
+    
     /**
      * Returns an error message corresponding to the key.
      *