DATABIND : Modify Set Source Dialog. 45/21745/2
authorparary <kyunghan80.park@samsung.com>
Tue, 27 May 2014 08:17:21 +0000 (17:17 +0900)
committerKyungHan Park <kyunghan80.park@samsung.com>
Tue, 27 May 2014 08:19:28 +0000 (01:19 -0700)
     change source type name Upper case to lower case( Static, Remote,
     File System Data source).
     static data source text update when combo in tree select .
     data model use compact data string.

Change-Id: I2aa8b0e8dcb93806b1a0dc5f1050a2f176ab61e8
Signed-off-by: parary <kyunghan80.park@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/CalendarSubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/CallHistorySubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/ContactSubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/FileSystemSubPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/Helper.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/RemoteCallSubPage.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 37866c4..ca50c82 100644 (file)
@@ -198,7 +198,7 @@ public class CalendarSubPage implements SourceDialogSubPage {
         data.right = new FormAttachment(100, 5);
         
         laodButton.setLayoutData(data);
-        
+        final SourceDialogSubPage subPage = this;
         laodButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -211,7 +211,7 @@ public class CalendarSubPage implements SourceDialogSubPage {
                 JsonObject json;
                 try {
                     json = Helper.readJsonFromStream( new FileInputStream( new File( path ) ) );
-                    Helper.makeTreeItem( json, parentDataTree, null, false);
+                    Helper.makeTreeItem( json, parentDataTree, null, false, subPage);
                 } catch (FileNotFoundException e1) {
                     e1.printStackTrace();
                 }
@@ -300,7 +300,7 @@ public class CalendarSubPage implements SourceDialogSubPage {
         settingComposite.layout();
         
         JsonObject json = gson.fromJson(dataModel.getJsonData(), JsonObject.class );
-        Helper.makeTreeItem(json, parentDataTree, null, false);
+        Helper.makeTreeItem(json, parentDataTree, null, false, this);
 
     }
 
index 6b2da8f..1ebd34a 100644 (file)
@@ -191,7 +191,7 @@ public class CallHistorySubPage implements SourceDialogSubPage {
         data.right = new FormAttachment(100, 5);
         
         laodButton.setLayoutData(data);
-        
+        final SourceDialogSubPage subPage = this;
         laodButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -204,7 +204,7 @@ public class CallHistorySubPage implements SourceDialogSubPage {
                 JsonObject json;
                 try {
                     json = Helper.readJsonFromStream( new FileInputStream( new File( path ) ) );
-                    Helper.makeTreeItem( json, parentDataTree, null, false);
+                    Helper.makeTreeItem( json, parentDataTree, null, false, subPage);
                 } catch (FileNotFoundException e1) {
                     e1.printStackTrace();
                 }
@@ -285,7 +285,7 @@ public class CallHistorySubPage implements SourceDialogSubPage {
         descContents.setText( descText );
         
         JsonObject json = gson.fromJson(dataModel.getJsonData(), JsonObject.class );
-        Helper.makeTreeItem(json, parentDataTree, null, false);
+        Helper.makeTreeItem(json, parentDataTree, null, false, this);
     }
 
 }
index 14d7710..81e581a 100644 (file)
@@ -179,7 +179,7 @@ public class ContactSubPage implements SourceDialogSubPage {
         data.right = new FormAttachment(100, 5);
         
         laodButton.setLayoutData(data);
-        
+        final SourceDialogSubPage subPage = this;
         laodButton.addSelectionListener(new SelectionAdapter() {
             @Override
             public void widgetSelected(SelectionEvent e) {
@@ -192,7 +192,7 @@ public class ContactSubPage implements SourceDialogSubPage {
                 JsonObject json;
                 try {
                     json = Helper.readJsonFromStream( new FileInputStream( new File( path ) ) );
-                    Helper.makeTreeItem( json, parentDataTree, null, false);
+                    Helper.makeTreeItem( json, parentDataTree, null, false, subPage);
                 } catch (FileNotFoundException e1) {
                     e1.printStackTrace();
                 }
@@ -276,7 +276,7 @@ public class ContactSubPage implements SourceDialogSubPage {
         descContents.setText( descText );
         
         JsonObject json = gson.fromJson(dataModel.getJsonData(), JsonObject.class );
-        Helper.makeTreeItem(json, parentDataTree, null, false);
+        Helper.makeTreeItem(json, parentDataTree, null, false, this);
     }
 
 }
index 2b24171..517891c 100644 (file)
@@ -86,7 +86,7 @@ public class FileSystemSubPage implements SourceDialogSubPage {
         dataModel.setJsonData( normalGson.toJson(root) );
         dataModel.setStaticFilePath( textPath.getText() );
         
-        dataModel.setSourceType( typeCombo.getText() );
+        dataModel.setSourceType( typeCombo.getText().toLowerCase() );
         
         return dataModel;
     }
@@ -116,6 +116,8 @@ public class FileSystemSubPage implements SourceDialogSubPage {
 
         loadButton.setLayoutData( data );
         
+        final SourceDialogSubPage subPage = this;
+        
         loadButton.addSelectionListener( new SelectionAdapter() {
             @Override
             public void widgetSelected( SelectionEvent e ) {
@@ -136,7 +138,7 @@ public class FileSystemSubPage implements SourceDialogSubPage {
                     }
                     
                     if( json != null ){
-                        Helper.makeTreeItem( json, parentDataTree, null, false);
+                        Helper.makeTreeItem( json, parentDataTree, null, false, subPage);
                     }else{
                         parentDataTree.removeAll();
                     }
@@ -167,7 +169,7 @@ public class FileSystemSubPage implements SourceDialogSubPage {
             public void widgetSelected(SelectionEvent e) {
                 IFile file = Helper.getProjectfile();
                 if(file != null ){
-                    textPath.setText( file.getProjectRelativePath().toPortableString() );
+                    textPath.setText( "./" + file.getProjectRelativePath().toPortableString() );
                 }
             }
         });
@@ -231,7 +233,7 @@ public class FileSystemSubPage implements SourceDialogSubPage {
         
         textPath.setText( dataModel.getStaticFilePath() );
         
-        typeCombo.select( Arrays.asList( comboItems ).indexOf( dataModel.getSourceType() ) );
+        typeCombo.select( Arrays.asList( comboItems ).indexOf( dataModel.getSourceType().toUpperCase() ) );
         
         IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
         IFile editorFile = (IFile)workbenchPage.getActiveEditor().getEditorInput().getAdapter(IFile.class);
@@ -251,7 +253,7 @@ public class FileSystemSubPage implements SourceDialogSubPage {
                 }
                 
                 if( json != null ){
-                    Helper.makeTreeItem( json, parentDataTree, null, false);
+                    Helper.makeTreeItem( json, parentDataTree, null, false, this);
                 }
             } catch (CoreException e) {
                 e.printStackTrace();
index 3325eb3..824371e 100644 (file)
@@ -224,8 +224,7 @@ public class Helper {
         return result;
     }
 
-    public static void makeTreeItem( JsonElement jsonElement, Tree tree, TreeItem item,
-                                     boolean includeIndex ) {
+    public static void makeTreeItem( JsonElement jsonElement, Tree tree, TreeItem item, boolean includeIndex, SourceDialogSubPage currentSubPage ) {
         if ( jsonElement.isJsonArray() ) {
             JsonArray array = jsonElement.getAsJsonArray();
 
@@ -233,10 +232,10 @@ public class Helper {
                 if ( includeIndex ) {
                     TreeItem indexItem = new TreeItem( item, 0 );
                     careteTreeItem( indexItem, String.valueOf( i ), null, "Index" );
-                    makeTreeItem( array.get( i ), tree, indexItem, includeIndex );
+                    makeTreeItem( array.get( i ), tree, indexItem, includeIndex, currentSubPage );
                     indexItem.setExpanded( true );
                 } else {
-                    makeTreeItem( array.get( i ), tree, item, includeIndex );
+                    makeTreeItem( array.get( i ), tree, item, includeIndex, currentSubPage );
                     item.setExpanded( true );
                     break;
                 }
@@ -266,28 +265,28 @@ public class Helper {
 
                     careteTreeItem( treeItem, entry.getKey(), jp.getAsString(), type );
                     if ( includeIndex )
-                        Helper.addComboInTreeItem( treeItem, type );
+                        Helper.addComboInTreeItem( treeItem, type, currentSubPage );
                 } else if ( entry.getValue().isJsonObject() ) {
                     careteTreeItem( treeItem, entry.getKey(), null, "Object" );
 
                     if ( includeIndex )
-                        Helper.addComboInTreeItem( treeItem, "Object" );
+                        Helper.addComboInTreeItem( treeItem, "Object", currentSubPage );
 
-                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex );
+                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex, currentSubPage );
                 } else if ( entry.getValue().isJsonArray() ) {
                     careteTreeItem( treeItem, entry.getKey(), null, "Array" );
 
                     if ( includeIndex )
-                        Helper.addComboInTreeItem( treeItem, "Array" );
+                        Helper.addComboInTreeItem( treeItem, "Array", currentSubPage );
 
-                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex );
+                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex, currentSubPage );
                 } else if ( entry.getValue().isJsonNull() ) {
                     careteTreeItem( treeItem, entry.getKey(), null, "Undefined" );
 
                     if ( includeIndex )
-                        Helper.addComboInTreeItem( treeItem, "String" );
+                        Helper.addComboInTreeItem( treeItem, "String", currentSubPage );
 
-                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex );
+                    makeTreeItem( entry.getValue(), tree, treeItem, includeIndex, currentSubPage );
 
                 }
                 treeItem.setExpanded( true );
@@ -309,7 +308,7 @@ public class Helper {
                 Helper.careteTreeItem( primitiveItem, null, jp.getAsString(), type );
 
                 if ( includeIndex )
-                    Helper.addComboInTreeItem( primitiveItem, type );
+                    Helper.addComboInTreeItem( primitiveItem, type, currentSubPage );
 
                 item.setExpanded( true );
             }
@@ -677,7 +676,7 @@ public class Helper {
         return result;
     }
 
-    public static CCombo addComboInTreeItem( TreeItem item, String data ) {
+    public static CCombo addComboInTreeItem( TreeItem item, String data, final SourceDialogSubPage currentSubPage ) {
 
         TreeEditor treeEditor = new TreeEditor( item.getParent() );
         treeEditor.horizontalAlignment = SWT.CENTER;
@@ -708,6 +707,10 @@ public class Helper {
                 }
 
                 parentItem.setText( 2, selectedText );
+                
+                if( currentSubPage instanceof StaticSubPage ){
+                    ((StaticSubPage)currentSubPage).updateJsonFromTree();
+                }
             }
         } );
         return combo;
index 04b0c79..4969cf7 100644 (file)
@@ -98,7 +98,7 @@ public class RemoteCallSubPage implements SourceDialogSubPage {
         dataModel.setMethod( methodSettingCombo.getText() );
         dataModel.setProxy( proxySettingCombo.getText() );
         dataModel.setQuery( Helper.getParamString( requestParam.getItems() ) );
-        dataModel.setSourceType( sourceTypeCombo.getText() );
+        dataModel.setSourceType( sourceTypeCombo.getText().toLowerCase() );
         dataModel.setTimeout( timeoutText.getText() );
 
         HashMap<String, String> headers = new HashMap<String, String>();
@@ -450,7 +450,7 @@ public class RemoteCallSubPage implements SourceDialogSubPage {
         }
 
         if ( json != null ) {
-            Helper.makeTreeItem( json, parentDataTree, null, false );
+            Helper.makeTreeItem( json, parentDataTree, null, false, this );
         } else {
             for ( Control control : parentDataTree.getChildren() ) {
                 control.dispose();
@@ -511,10 +511,10 @@ public class RemoteCallSubPage implements SourceDialogSubPage {
 
         setParamString( dataModel.getQuery() );
         sourceTypeCombo.select( Arrays.asList( sourceTypeCombo.getItems() )
-                .indexOf( dataModel.getSourceType() ) );
+                .indexOf( dataModel.getSourceType().toUpperCase() ) );
         timeoutText.setText( dataModel.getTimeout() );
 
-        Helper.makeTreeItem( json, parentDataTree, null, false );
+        Helper.makeTreeItem( json, parentDataTree, null, false, this );
     }
 
     private void setParamString( String query ) {
index 9893f88..2a1facd 100644 (file)
@@ -1014,7 +1014,7 @@ public class SetSourcePage extends Dialog {
         item.setData("TREEITEMDATA", treeItemData);
         
         if( !type.equals("Index") )
-            Helper.addComboInTreeItem(item, type);
+            Helper.addComboInTreeItem(item, type, currentSubPage);
         
         dialogTree.showItem(item);
         
index 95aa828..609e4ae 100644 (file)
@@ -107,12 +107,16 @@ public class StaticSubPage implements SourceDialogSubPage {
         BindingData dataModel = new BindingData();
 
         Object obj = null;
-        
+        String compactData = "";
+        String text = staticSourceStyledText.getText();
         try{
-            if ( typeCombo.getSelectionIndex() == 0 )
-                obj = normalGson.fromJson( staticSourceStyledText.getText(), JsonObject.class );
-            else
-                obj = Helper.parseXML( staticSourceStyledText.getText()  );
+            if ( typeCombo.getSelectionIndex() == 0 ){
+                obj = normalGson.fromJson( text, JsonObject.class );
+                compactData = normalGson.toJson( obj ) ;
+            }else{
+                obj = Helper.parseXML( text  );
+                compactData = text.replaceAll( ">\\s*<", "><" ); 
+            }
         }catch(Exception e){}
 
         if( obj == null ){
@@ -129,9 +133,9 @@ public class StaticSubPage implements SourceDialogSubPage {
             Helper.makeJsonFromTree( item, root );
         }
 
-        dataModel.setJsonData( staticSourceStyledText.getText() );
+        dataModel.setJsonData( compactData );
         dataModel.setStaticFilePath( jsonFile );
-        dataModel.setSourceType( typeCombo.getText() );
+        dataModel.setSourceType( typeCombo.getText().toLowerCase() );
 
         return dataModel;
     }
@@ -159,7 +163,7 @@ public class StaticSubPage implements SourceDialogSubPage {
 
             if ( json != null ) {
                 parentDataTree.removeAll();
-                Helper.makeTreeItem( json, parentDataTree, null, true );
+                Helper.makeTreeItem( json, parentDataTree, null, true, this );
             }
         }
 
@@ -305,10 +309,8 @@ public class StaticSubPage implements SourceDialogSubPage {
                     } else {
                         result = Helper.getStringFromDocument( Helper.getXMLFromJson( null, null, jo ), true );
                     }
-                }catch(Exception e){
-                    e.printStackTrace();
-                }
-                if( result.length() == 0 ){
+                }catch(Exception e){ }
+                if( result.length() == 0 || parentDataTree.getChildren().length == 0 ){
                     staticSourceStyledText.setText( result );
                 }else{
                     staticSourceStyledText.setData( "editing", true );
@@ -479,7 +481,7 @@ public class StaticSubPage implements SourceDialogSubPage {
         staticSourceStyledText.setData( "editing", false );
 
         staticSourceStyledText.setKeyBinding( SWT.DEL, ST.DELETE_NEXT );
-        
+        final SourceDialogSubPage subPage = this;
         staticSourceStyledText.addModifyListener( new ModifyListener() {
             @Override
             public void modifyText( ModifyEvent e ) {
@@ -512,7 +514,7 @@ public class StaticSubPage implements SourceDialogSubPage {
                 }
 
                 if ( json != null ) {
-                    TreeRefreshTask task = new TreeRefreshTask(json);
+                    TreeRefreshTask task = new TreeRefreshTask(subPage, json);
                     parentDataTree.setData( "LAST_TASK", task );
                     parentDataTree.getDisplay().timerExec( 600, task );
                     
@@ -525,8 +527,10 @@ public class StaticSubPage implements SourceDialogSubPage {
     class TreeRefreshTask implements Runnable {
         
         private JsonObject taskJson;
+        private SourceDialogSubPage subPage;
         
-        TreeRefreshTask(JsonObject taskJson){
+        TreeRefreshTask(SourceDialogSubPage currentSubPage, JsonObject taskJson){
+            this.subPage = currentSubPage;
             this.taskJson = taskJson;
         }
         
@@ -539,7 +543,7 @@ public class StaticSubPage implements SourceDialogSubPage {
             }
             
             parentDataTree.removeAll();
-            Helper.makeTreeItem( taskJson, parentDataTree, null, true );
+            Helper.makeTreeItem( taskJson, parentDataTree, null, true, subPage );
         }
     };
 
@@ -571,7 +575,7 @@ public class StaticSubPage implements SourceDialogSubPage {
         jsonFile = dataModel.getStaticFilePath();
 
         if ( dataModel.getSourceType() != null )
-            typeCombo.select( Arrays.asList( comboItems ).indexOf( dataModel.getSourceType() ) );
+            typeCombo.select( Arrays.asList( comboItems ).indexOf( dataModel.getSourceType().toUpperCase() ) );
 
         if ( dataModel.getJsonData() != null )
             staticSourceStyledText.setText( dataModel.getJsonData() );