DATABIND : bug Fix remove combo in Tree. 92/18792/1
authorparary <kyunghan80.park@samsung.com>
Tue, 1 Apr 2014 08:31:25 +0000 (17:31 +0900)
committerparary <kyunghan80.park@samsung.com>
Tue, 1 Apr 2014 08:31:25 +0000 (17:31 +0900)
Change-Id: Icdb3077e46455a8f403432bb10fa1ff5ae52ed8e
Signed-off-by: parary <kyunghan80.park@samsung.com>
org.tizen.webuibuilder/.gitignore
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/FileSystemSubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/RuntimeAPISubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/SetSourcePage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/StaticSubPage.java

index 63371cb..1e6f1dd 100644 (file)
 /bin
 /bin
 /bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
+/bin
index 8d1221b..a3eeb34 100644 (file)
@@ -1,3 +1,24 @@
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
 package org.tizen.webuibuilder.ui.views.databinding.dialog;
 
 import java.util.Map;
index 7dd4231..1a4684c 100644 (file)
@@ -1,3 +1,24 @@
+/*
+ * UI Builder
+ *
+ * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * Contributors:
+ * - S-Core Co., Ltd
+ *
+ */
 package org.tizen.webuibuilder.ui.views.databinding.dialog;
 
 import java.util.Arrays;
index 1173231..d3426f6 100644 (file)
@@ -92,7 +92,7 @@ public class SetSourcePage extends Dialog {
        
        private Map<String, Button> dataButtonMap = new HashMap<String,Button>();
        
-       private List<String> types = Arrays.asList( new String[]{ "Boolean","Number","String" } );
+       private List<String> types = Arrays.asList( new String[]{ "Boolean","Number","String", "Object", "Array" } );
        
        /**
         * Constructor.
@@ -686,6 +686,9 @@ public class SetSourcePage extends Dialog {
                             public void focusLost(FocusEvent event) {
                                 treeItem.setText(column, text.getText());
                                 text.dispose();
+                                if( currentSubPage instanceof StaticSubPage ){
+                                    staticSubPage.updateJsonFromTree();
+                                }
                             }
                         });
 
@@ -699,11 +702,19 @@ public class SetSourcePage extends Dialog {
                                 switch (event.keyCode) {
                                     case SWT.CR:
                                         treeItem.setText(column, text.getText());
+                                        if( currentSubPage instanceof StaticSubPage ){
+                                            staticSubPage.updateJsonFromTree();
+                                        }
+                                        text.dispose();
                                         break;
                                     case SWT.KEYPAD_CR:
                                         // Enter hit--set the text into the tree and
                                         // drop through
                                         treeItem.setText(column, text.getText());
+                                        if( currentSubPage instanceof StaticSubPage ){
+                                            staticSubPage.updateJsonFromTree();
+                                        }
+                                        text.dispose();
                                         break;
                                     case SWT.ESC:
                                         // End editing session
@@ -752,6 +763,9 @@ public class SetSourcePage extends Dialog {
                         public void focusLost(FocusEvent event) {
                             item.setText(text.getText());
                             text.dispose();
+                            if( currentSubPage instanceof StaticSubPage ){
+                                staticSubPage.updateJsonFromTree();
+                            }
                         }
                     });
 
@@ -768,6 +782,10 @@ public class SetSourcePage extends Dialog {
                                     // Enter hit--set the text into the tree and
                                     // drop through
                                     item.setText(text.getText());
+                                    if( currentSubPage instanceof StaticSubPage ){
+                                        staticSubPage.updateJsonFromTree();
+                                    }
+                                    text.dispose();
                                     break;
                                 case SWT.ESC:
                                     // End editing session
@@ -818,25 +836,30 @@ public class SetSourcePage extends Dialog {
         combo.select( Arrays.asList(comboItems).indexOf(data) );
         combo.pack();
         
-        combo.addSelectionListener(new SelectionListener() {
+        combo.setData( "parentItem", item );
+        
+        treeEditor.minimumWidth = dialogTree.getColumn(2).getWidth();
+        treeEditor.horizontalAlignment = SWT.CENTER;
+        treeEditor.setEditor(combo, item, 2);
+
+        item.setData("TREEEDITORFORCOMBO", treeEditor);
+        
+        combo.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
                 CCombo combo = (CCombo) e.getSource();
-                TreeEditor treeEditor = (TreeEditor) ((Tree)combo.getParent()).getSelection()[0].getData( "TREEEDITORFORCOMBO" );
+                TreeItem parentItem = (TreeItem) combo.getData("parentItem");
+                TreeEditor treeEditor = (TreeEditor) parentItem.getData( "TREEEDITORFORCOMBO" );
                 String[] comboItems = { "String", "Number", "Boolean", "Object", "Array" };
-                treeEditor.getItem().setText(2, comboItems[combo.getSelectionIndex()]);
-            }
-            @Override
-            public void widgetDefaultSelected(SelectionEvent e) {
+                String selectedText = comboItems[combo.getSelectionIndex()];
+                treeEditor.getItem().setText(2, selectedText);
+                
+                if( selectedText.equals("Object") || selectedText.equals("Array") ){
+                    treeEditor.getItem().setText(1, "");
+                }
             }
         });
 
-        treeEditor.minimumWidth = dialogTree.getColumn(2).getWidth();
-        treeEditor.horizontalAlignment = SWT.CENTER;
-        treeEditor.setEditor(combo, item, 2);
-
-        item.setData("TREEEDITORFORCOMBO", treeEditor);
-
         return combo;
     }
        
@@ -846,23 +869,46 @@ public class SetSourcePage extends Dialog {
            if( dialogTree.getSelection().length > 0 )
             parentItem = dialogTree.getSelection()[0];
         
+           String[] ableTypes = new String[]{ "Object", "Array", "Index" };
+        
+        if( parentItem != null && !Arrays.asList(ableTypes).contains(parentItem.getText(2) ) ){
+            return;
+        }
+        
         TreeItem item;
         if (parentItem == null) {
             item = new TreeItem(dialogTree, SWT.NONE);
         } else {
             item = new TreeItem(parentItem, SWT.NONE);
         }
-        item.setText(new String[] { "data", "test", "String" });
+        
+        String key = "data";
+        String value = "test";
+        String type = "String";
+        
+        if( parentItem != null && currentSubPage instanceof StaticSubPage && parentItem.getText(2).equals("Array") ){
+            type = "Index";
+            value = "";
+            key = String.valueOf(parentItem.getItemCount()-1);
+        }
+        
+        item.setText(new String[] { key, value, type });
         
         TreeItemData treeItemData = new TreeItemData();
         treeItemData.setSource( "custom" );
         treeItemData.setObjectType("String");
-        treeItemData.setObjectValue("String");
+        treeItemData.setObjectValue( type );
         
         item.setData("TREEITEMDATA", treeItemData);
         
-        addComboInTreeItem(item, "String");
+        if( !type.equals("Index") )
+            addComboInTreeItem(item, "String");
+        
         dialogTree.showItem(item);
+        
+        if( currentSubPage instanceof StaticSubPage ){
+            staticSubPage.updateJsonFromTree();
+        }
     }
        
        private void removeAllItems() {
@@ -879,6 +925,11 @@ public class SetSourcePage extends Dialog {
         for (TreeItem treeItem : treeItems) {
             removeAllChildrenRecursively(treeItem);
         }
+        
+        if( currentSubPage instanceof StaticSubPage ){
+            staticSubPage.updateJsonFromTree();
+        }
+        
         // for redraw
         dialogTree.setSize(dialogTree.getSize().x, dialogTree.getSize().y - 1);
         dialogTree.setSize(dialogTree.getSize().x, dialogTree.getSize().y + 1);
@@ -931,6 +982,10 @@ public class SetSourcePage extends Dialog {
             item.setText(str);
             item.setData( "TREEITEMDATA", data);
             dialogTree.select(item);
+            
+            if( currentSubPage instanceof StaticSubPage ){
+                staticSubPage.updateJsonFromTree();
+            }
         }
     }
     
index 5fcb0cb..cb958e3 100644 (file)
@@ -204,16 +204,17 @@ public class StaticSubPage implements SourceDialogSubPage {
 
                 JsonObject json = Helper.readJsonFromFile( jsonFile );
                 
+                for( Control control : parentDataTree.getChildren() ){
+                    control.dispose();
+                }
+                parentDataTree.removeAll();
+                
                 if (json != null) {
                     jsonString = prettyGson.toJson( json );
                     staticSourceStyledText.setText( jsonString );
                 }else{
                     jsonString = "";
                     staticSourceStyledText.setText( "" );
-                    for( Control control : parentDataTree.getChildren() ){
-                        control.dispose();
-                    }
-                    parentDataTree.removeAll();
                 }
             }
         };
@@ -319,12 +320,19 @@ public class StaticSubPage implements SourceDialogSubPage {
         staticSourceStyledText.addModifyListener(new ModifyListener() {
             @Override
             public void modifyText(ModifyEvent e) {
+                
+                if( staticSourceStyledText.getData( "editing" ) != null && (Boolean) staticSourceStyledText.getData( "editing" ) )
+                    return;
+                
                 JsonObject json = null;
                 try{
                     json = normalGson.fromJson(staticSourceStyledText.getText(), JsonObject.class);   
                 }catch(Exception ex){}
                 
                 if(json != null){
+                    for ( Control control : parentDataTree.getChildren() ) {
+                        control.dispose();
+                    }
                     parentDataTree.removeAll();
                     Helper.makeTreeItem( json, parentDataTree, null, true );
                 }
@@ -332,21 +340,6 @@ public class StaticSubPage implements SourceDialogSubPage {
         });
        }
        
-//     private void makeTreeFromJsonText( String text, Object object ) {
-//             
-//             JsonObject jsonObj = null;
-//             
-//             try{
-//                     jsonObj = normalGson.fromJson( text, JsonObject.class );
-//             }catch(Exception e){
-//                     MessageBox messageBox = new MessageBox(parentGroup.getShell(), SWT.ICON_ERROR);
-//                 messageBox.setMessage("Invalid JSON Text");
-//                 messageBox.open();
-//                     return;
-//             }
-//             Helper.makeTreeItem( jsonObj, parentDataTree, null, true );
-//     }
-       
     @Override
     public void setButtonsState( Map<String, Button> dataButtonMap ) {
         dataButtonMap.get("addTreeItem").setEnabled(true);
@@ -377,12 +370,26 @@ public class StaticSubPage implements SourceDialogSubPage {
             staticSourceStyledText.setText( prettyGson.toJson(json) );
         
         jsonFile = dataModel.getStaticFilePath();
-        
-//        if( json != null )
-//            Helper.makeTreeItem(json, parentDataTree, null, true);
     }
 
     public Composite getDataComposite() {
         return dataComposite;
     }
+    
+    public void updateJsonFromTree(){
+        if (parentDataTree.getItemCount() > 0 ) {
+          JsonObject root = new JsonObject();
+          TreeItem[] items = parentDataTree.getItems();
+          for (TreeItem item : items) {
+              Helper.makeJsonFromTree( item, root);
+          }
+          staticSourceStyledText.setData( "editing", true  );
+          staticSourceStyledText.setText(prettyGson.toJson(root));
+          staticSourceStyledText.setData( "editing", false  );
+      }else{
+          staticSourceStyledText.setData( "editing", true  );
+          staticSourceStyledText.setText( "" );
+          staticSourceStyledText.setData( "editing", false  );
+      }
+    }
 }