DATABIND : support multi binding in the widget 77/20577/1
authorjaeyeol lee <jaeyeol148.lee@samsung.com>
Fri, 9 May 2014 09:29:29 +0000 (18:29 +0900)
committerjaeyeol lee <jaeyeol148.lee@samsung.com>
Fri, 9 May 2014 09:29:29 +0000 (18:29 +0900)
Change-Id: Ibe00e4699844219e0fd5b94be9d7e8a1e337c3e6
Signed-off-by: jaeyeol lee <jaeyeol148.lee@samsung.com>
org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/tizen.types.xml
org.tizen.webuibuilder/res/descriptors/Tizen-web-ui-fw/widget/html.label.widget.xml
org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/policies/DesignerXYLayoutEditPolicy.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingEventDelegater.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/DataBindingTooltipParser.java

index 957e382..57a9414 100644 (file)
        </type>
 
        <type id="attrtext@databinding">
-               <constant value="attr" displayName=""/>
+               <constant value="attr" displayName="form"/>
+               <constant value="attr" displayName="for"/>
                <constant value="text" displayName=""/>
        </type>
 </types>
\ No newline at end of file
index 224a591..606da98 100644 (file)
@@ -24,7 +24,7 @@
        </property> -->
        <property name="for" type="string" displayName="For" default=""/>
        
-       <property name="data-bind" type="text@databinding" displayName="Data Binding" default="" initValue=""/>
+       <property name="data-bind" type="attrtext@databinding" displayName="Data Binding" default="" initValue=""/>
 
        <event name="ontap" displayName="Tap" eventType="event.defaultevent" />
        <event name="ontaphold" displayName="TapHold" eventType="event.defaultevent" />
index c01b713..47ccfab 100644 (file)
 
 package org.tizen.webuibuilder.gef.policies;
 
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
 import org.eclipse.draw2d.PositionConstants;
 import org.eclipse.draw2d.geometry.Point;
@@ -54,6 +57,7 @@ import org.tizen.webuibuilder.model.descriptors.ConstantDescriptor;
 import org.tizen.webuibuilder.ui.editor.dnd.listener.PageDesignerDropTargetListener;
 import org.tizen.webuibuilder.ui.editor.ruler.DesignerGuide;
 import org.tizen.webuibuilder.ui.editor.ruler.commands.ChangeGuideCommand;
+import org.tizen.webuibuilder.ui.views.databinding.DataBindingTooltipParser;
 
 
 public class DesignerXYLayoutEditPolicy extends HoverViewerXYLayoutEditPolicy {
@@ -176,25 +180,22 @@ public class DesignerXYLayoutEditPolicy extends HoverViewerXYLayoutEditPolicy {
                                          SWT.POP_UP);
 
                         for (int i = 0; i < list.size(); i++) {
-                            MenuItem item = new MenuItem(contextMenu, SWT.PUSH);
-                            String value = list.get(i).getValue();
-                            String displayName = list.get(i).getDisplayName();
-                            final String str;
+                            final MenuItem item = new MenuItem(contextMenu, SWT.PUSH);
+                            final String value = list.get(i).getValue();
+                            final String displayName = list.get(i).getDisplayName();
                             if ((displayName != null) && (!displayName.isEmpty())) {
                                 item.setText(displayName);
-                                str =
-                                        value + ": { " + displayName + ": " + property2.getValue()
-                                                + " }";
                             } else {
                                 item.setText(value);
-                                str = value + ": " + property2.getValue();
                             }
 
                             item.addListener(SWT.Selection, new Listener() {
                                 public void handleEvent(Event e) {
+                                    String str = targetPart.getProperty(BuilderConstants.ATTRIBUTE_DATA_BIND).getValue();
+                                    final String info = makeInfoString(property2, displayName, value, str);
                                     command =
                                             new SetPartPropertyCommand(targetPart, BuilderConstants.ATTRIBUTE_DATA_BIND,
-                                                                       str);
+                                                                       info);
                                 }
                             });
                         }
@@ -217,6 +218,37 @@ public class DesignerXYLayoutEditPolicy extends HoverViewerXYLayoutEditPolicy {
         return command;
     }
 
+    
+    private String makeInfoString(PartProperty property2, String displayName, String value, String str) {
+        String string = "";
+        
+        if ((str != null) && (!str.isEmpty())) {
+            Map<String, String> bindingInfos = DataBindingTooltipParser.parseToMap(str);
+            
+            if (bindingInfos.containsKey(value)) {
+                bindingInfos.remove(value);
+            } else if (bindingInfos.containsKey("attr-"+displayName)) {
+                bindingInfos.remove("attr-"+displayName);
+            }
+            
+            if ((displayName != null) && (!displayName.isEmpty())) {
+                bindingInfos.put(value+"-"+displayName, property2.getValue());
+            } else {
+                bindingInfos.put(value, property2.getValue());
+            }
+            
+            string = DataBindingTooltipParser.makeStringFromMap(bindingInfos);
+        } else {
+            if ((displayName != null) && (!displayName.isEmpty())) {
+                string = value + ": { " + displayName + ": " + property2.getValue() + " }";
+            } else {
+                string = value + ": " + property2.getValue();
+            }
+        }
+        
+        return string;
+    }
+
     private boolean hasProperty(EditPart editPart, String name) {
         if (editPart == null) {
             return false;
index 8405d15..56f0854 100644 (file)
@@ -33,7 +33,7 @@ public class DataBindingEventDelegater implements IPageDataListener {
        
        public void valueChanged(Part part, String attributeDataBind,
                        String value, boolean undoable) {
-               commandStack.execute(new SetPartPropertyCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, "", true)); 
+               commandStack.execute(new SetPartPropertyCommand(part, BuilderConstants.ATTRIBUTE_DATA_BIND, value, true));      
        }
 
 }
index 934c1b2..316977e 100644 (file)
@@ -26,6 +26,7 @@ package org.tizen.webuibuilder.ui.views.databinding;
 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 
 import org.eclipse.core.resources.IProject;
 import org.eclipse.gef.EditPart;
@@ -301,16 +302,22 @@ public class DataBindingPage extends Page implements IBindingDataSetListener {
             if (part.getProperty(BuilderConstants.ATTRIBUTE_DATA_BIND) != null) {
                 String propertyValue =
                         part.getProperty(BuilderConstants.ATTRIBUTE_DATA_BIND).getValue();
+                
                 if ((propertyValue != null) && (!propertyValue.isEmpty())) {
-                    String[] str = propertyValue.split(": ");
-                    if (str[1].startsWith(BuilderConstants.DATABINDING_ARRAYITEM_VALUE_PREFIX)) {
-                        String parentPropertyValue = getParentPropertyValue(part, str[1]);
-                        if (parentPropertyValue != null) {
-                            addInfoTableItem(part, parentPropertyValue, part.getIdPropertyValue(),
-                                             str[0]);
+                    Map<String, String> bindingInfos = DataBindingTooltipParser.parseToMap(propertyValue);
+                    Object[] bindingTypes = bindingInfos.keySet().toArray();
+                    for (Object bindingType : bindingTypes) {
+                        String key = bindingType.toString();
+                        String modelValue = bindingInfos.get(key);
+                        if (modelValue.startsWith(BuilderConstants.DATABINDING_ARRAYITEM_VALUE_PREFIX)) {
+                            String parentPropertyValue = getParentPropertyValue(part, modelValue);
+                            if (parentPropertyValue != null) {
+                                addInfoTableItem(part, parentPropertyValue, part.getIdPropertyValue(),
+                                                 key);
+                            }
+                        } else {
+                            addInfoTableItem(part, modelValue, part.getIdPropertyValue(), key);
                         }
-                    } else {
-                        addInfoTableItem(part, str[1], part.getIdPropertyValue(), str[0]);
                     }
                 }
             }
@@ -789,9 +796,9 @@ public class DataBindingPage extends Page implements IBindingDataSetListener {
      * @param item
      * @param editor
      */
-    public void removeInfoTableItem(Part part) {
+    public void removeInfoTableItem(Part part, String bindingInfo) {
         if (delegater != null) {
-            delegater.valueChanged(part, BuilderConstants.ATTRIBUTE_DATA_BIND, "", true);
+            delegater.valueChanged(part, BuilderConstants.ATTRIBUTE_DATA_BIND, bindingInfo, true);
         }
     }
     
@@ -911,8 +918,20 @@ public class DataBindingPage extends Page implements IBindingDataSetListener {
         TableItem[] tableItems = infoTableViewer.getTable().getSelection();
         for (TableItem tableItem : tableItems) {
             Part part = (Part) tableItem.getData("PART");
+            String tableTypeValue = tableItem.getText(2);
             if (part != null) {
-                removeInfoTableItem(part);
+                String propertyValue =
+                        part.getProperty(BuilderConstants.ATTRIBUTE_DATA_BIND).getValue();
+                if ((propertyValue != null) && (!propertyValue.isEmpty())) {
+                    Map<String, String> bindingInfos = DataBindingTooltipParser.parseToMap(propertyValue);
+                    Object[] bindingTypes = bindingInfos.keySet().toArray();
+                    for (Object bindingType : bindingTypes) {
+                        if ((tableTypeValue != null) && (bindingType.toString().equals(tableTypeValue))) {
+                            bindingInfos.remove(bindingType);
+                            removeInfoTableItem(part, DataBindingTooltipParser.makeStringFromMap(bindingInfos));
+                        }
+                    }
+                }
             }
         }
     }
@@ -1526,7 +1545,7 @@ public class DataBindingPage extends Page implements IBindingDataSetListener {
         if (pageDesigner != null) {
             List<BindingData> models = pageDesigner.getAppManager().getViewModels();
             for (BindingData model : models) {
-                if (model.getSourceName().equals(e.getOldValue())) {
+                if ((model.getSourceName() != null)&&(model.getSourceName().equals(e.getOldValue()))) {
                     model.setSourceName(e.getValue());
                 }
             }
index 7cb4444..3736cb4 100644 (file)
@@ -3,7 +3,9 @@
 package org.tizen.webuibuilder.ui.views.databinding;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 
 import javax.activation.CommandInfo;
 
@@ -79,4 +81,96 @@ public class DataBindingTooltipParser {
         }
         return sample;
     }
+    
+    public static Map<String, String> parseToMap(String str) {
+        Map<String, String> bindingInfos = new HashMap<String, String>();
+        if ((str.contains("attr: { ")) && (!str.startsWith("attr: { "))) {
+            String[] temps = str.split("attr: \\{ ");
+            if ((temps[0] != null) && (!temps[0].isEmpty())) {
+                String[] infos = temps[0].split(", ");
+                for (String info : infos) {
+                    put(bindingInfos, info);
+                }
+                
+                if ((temps.length > 1) && (temps[1] != null) && (!temps[1].isEmpty())) {
+                    temps[1] = temps[1].replaceAll("attr:", "");
+                    temps[1] = temps[1].replaceAll(" \\{ ", "");
+                    temps[1] = temps[1].replaceAll(" }", "");
+                    
+                    String[] infos2 = temps[1].split(", ");
+                    for (String info : infos2) {
+                        info = new StringBuffer(info).insert(0, "attr-").toString();
+                        put(bindingInfos, info);
+                    }
+                }
+            }
+        } else if ((str.contains("attr: { ")) && (str.startsWith("attr: { "))) {
+            String[] temps = str.split(" }, ");
+            if ((temps[0] != null) && (!temps[0].isEmpty())) {
+                temps[0] = temps[0].replaceAll("attr:", "");
+                temps[0] = temps[0].replaceAll(" \\{ ", "");
+                temps[0] = temps[0].replaceAll(" }", "");
+                
+                String[] infos2 = temps[0].split(", ");
+                for (String info : infos2) {
+                    info = new StringBuffer(info).insert(0, "attr-").toString();
+                    put(bindingInfos, info);
+                }
+                if ((temps.length > 1) && (temps[1] != null) && (!temps[1].isEmpty())) {                    
+                    String[] infos = temps[1].split(", ");
+                    for (String info : infos) {
+                        put(bindingInfos, info);
+                    }
+                }
+            }
+        } else {
+            if (str.contains(", ")) {
+                String[] infos = str.split(", ");
+                for (String info : infos) {
+                    put(bindingInfos, info);
+                }
+            } else {
+                put(bindingInfos, str);
+            }
+        }
+        return bindingInfos;
+    }
+    
+    private static void put(Map<String, String> bindingInfos, String string) {
+        String[] infos = string.split(": ");
+        if ((infos[0] != null) && (!infos[0].isEmpty())) { 
+            if ((infos[1] != null) && (!infos[1].isEmpty())) {
+                bindingInfos.put(infos[0], infos[1]);
+            }
+        }
+        
+    }
+
+    public static String makeStringFromMap(Map<String, String> bindingInfos) {
+        Object[] bindingTypes = bindingInfos.keySet().toArray();
+        String string = "";
+        for (Object bindingType : bindingTypes) {
+            String key = bindingType.toString();
+            String modelValue = bindingInfos.get(key);
+            if (key.startsWith("attr-")) {
+                key = key.replaceAll("attr-", "");
+                if (string.contains("attr")) {
+                    int index = string.lastIndexOf(" }");
+                    string = new StringBuffer(string).insert(index, ", " + key + ": " + modelValue).toString();
+                } else {
+                    if (!string.isEmpty()) {
+                        string += ", ";
+                    }
+                    string += "attr: { " + key + ": " + modelValue + " }";
+                }
+            } else {
+                if (!string.isEmpty()) {
+                    string += ", ";
+                }
+                string += key + ": " + modelValue;
+            }
+        }
+        
+        return string;
+    }
 }