DATABIND : Set Source Dialog Modify and Bug Fix. 23/22023/4
authorparary <kyunghan80.park@samsung.com>
Thu, 29 May 2014 01:51:07 +0000 (10:51 +0900)
committerparary <kyunghan80.park@samsung.com>
Thu, 29 May 2014 01:58:23 +0000 (10:58 +0900)
modify - xmlToJson converter ( attribute prefix, text prefix ).
bug fix - File select dialog double click error.
bug fix - xml data include line feed error.
bug fix -  tree item height lower than combo in tree.

Change-Id: Iec53e4091a26ac8e7cd91ee1d115c2d0990f0638
Signed-off-by: parary <kyunghan80.park@samsung.com>
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/views/databinding/dialog/Helper.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 099d392..8dcf8e6 100644 (file)
@@ -52,6 +52,8 @@ import javax.xml.transform.stream.StreamResult;
 
 import org.eclipse.core.resources.IFile;
 import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.custom.TreeEditor;
@@ -70,6 +72,7 @@ import org.eclipse.swt.widgets.Tree;
 import org.eclipse.swt.widgets.TreeItem;
 import org.eclipse.ui.PlatformUI;
 import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.ISelectionStatusValidator;
 import org.eclipse.ui.model.WorkbenchContentProvider;
 import org.eclipse.ui.model.WorkbenchLabelProvider;
 import org.tizen.web.config.schema.model.Privilege;
@@ -100,9 +103,10 @@ public class Helper {
         OBJECT, ARRAY, PRIMITIVE
     }
 
-    private static final String xmlConvertAttrPrifix = "@";
-    private static final String xmlConvertTextPrifix = "#";
-    private static final String xmlConvertTextName = "text";
+    private static final String xmlAttrPrefix = "";
+    private static final String xmlTextPrefix = "";
+    private static final String xmlTextName = "text";
+    private static String nullFixAttrPrefix = null;
 
     private static Gson gson;
     private static DocumentBuilderFactory dbf;
@@ -111,6 +115,11 @@ public class Helper {
 
     static {
 
+        if( xmlAttrPrefix.trim().length() == 0)
+            nullFixAttrPrefix = "__@@__";
+        else 
+            nullFixAttrPrefix = xmlAttrPrefix;
+        
         gson = new GsonBuilder().setPrettyPrinting().serializeNulls().create();
 
         dbf = DocumentBuilderFactory.newInstance();
@@ -631,7 +640,7 @@ public class Helper {
 
         for ( int j = 0; j < node.getAttributes().getLength(); j++ ) {
             Node attNode = node.getAttributes().item( j );
-            jsonOb.addProperty( xmlConvertAttrPrifix + attNode.getNodeName(),
+            jsonOb.addProperty( xmlAttrPrefix + attNode.getNodeName(),
                                 attNode.getNodeValue() );
             isExistChild = true;
         }
@@ -642,7 +651,7 @@ public class Helper {
         String textNodeName = "";
         
         if ( isExistChild )
-            textNodeName = xmlConvertTextPrifix + xmlConvertTextName;
+            textNodeName = xmlTextPrefix + xmlTextName;
 
         if ( node.getFirstChild() != null && node.getFirstChild().getNodeType() == Node.TEXT_NODE
                 && node.getFirstChild().getTextContent().trim().length() != 0 ) {
@@ -680,16 +689,13 @@ public class Helper {
     public static Combo addComboInTreeItem( TreeItem item, String data, final SourceDialogSubPage currentSubPage ) {
 
         TreeEditor treeEditor = new TreeEditor( item.getParent() );
-        treeEditor.horizontalAlignment = SWT.CENTER;
-        treeEditor.verticalAlignment = SWT.CENTER;
         treeEditor.grabHorizontal = true;
         treeEditor.grabVertical = true;
-//        treeEditor.minimumHeight = item.getParent().getItemHeight()-1;
-//        treeEditor.minimumWidth = item.getParent().getColumn( 2 ).getWidth() -1;
 
-        Combo combo = new Combo( item.getParent(), SWT.SINGLE | SWT.BORDER | SWT.READ_ONLY );
+        Combo combo = new Combo( item.getParent(), SWT.SINGLE | SWT.READ_ONLY );
         treeEditor.setEditor( combo, item, 2 );
         final String[] comboItems = { "String", "Number", "Boolean", "Object", "Array" };
+        
         combo.setVisibleItemCount( comboItems.length );
         combo.setItems( comboItems );
         combo.select( Arrays.asList( comboItems ).indexOf( data ) );
@@ -700,7 +706,7 @@ public class Helper {
         combo.addSelectionListener( new SelectionAdapter() {
             @Override
             public void widgetSelected( SelectionEvent e ) {
-                CCombo combo = (CCombo) e.getSource();
+                Combo combo = (Combo) e.getSource();
                 TreeItem parentItem = (TreeItem) combo.getData( "parentItem" );
                 String selectedText = comboItems[combo.getSelectionIndex()];
 
@@ -798,13 +804,18 @@ public class Helper {
             }
         } else if ( jsonElement.isJsonObject() ) {
             JsonObject jb = jsonElement.getAsJsonObject();
+            
+            JsonElement textElement = jb.get( xmlTextPrefix + xmlTextName ); 
+            if( textElement != null )
+                element.setTextContent( textElement.getAsString() );
+            
             Set<Entry<String, JsonElement>> entrys = jb.entrySet();
             for ( Entry<String, JsonElement> entry : entrys ) {
 
                 String key = entry.getKey();
                 Element newChild = null;
-
-                if ( !key.startsWith( xmlConvertAttrPrifix ) && !key.equals( xmlConvertTextPrifix + xmlConvertTextName ) ){
+                
+                if ( !key.startsWith( nullFixAttrPrefix ) && !key.equals( xmlTextPrefix + xmlTextName ) ){
                     newChild = doc.createElement( key );
                     
                     if ( element == null )
@@ -815,10 +826,10 @@ public class Helper {
 
                 if ( entry.getValue().isJsonPrimitive() ) {
                     String value = entry.getValue().getAsJsonPrimitive().getAsString();
-                    if ( xmlConvertAttrPrifix.length() != 0 && key.startsWith( xmlConvertAttrPrifix ) ) {
+                    if ( key.startsWith( nullFixAttrPrefix ) ) {
                         element.setAttribute( key.substring( 1, key.length() ), value );
-                    } else if ( key.equals( xmlConvertTextPrifix + xmlConvertTextName ) ) {
-                        element.setTextContent( value );
+                    } else if ( key.equals( xmlTextPrefix + xmlTextName ) ) {
+                        continue;
                     } else {
                         newChild.setTextContent( value );
                     }
@@ -844,8 +855,23 @@ public class Helper {
                 new ElementTreeSelectionDialog( Display.getCurrent().getActiveShell(),
                                                 new WorkbenchLabelProvider(),
                                                 new WorkbenchContentProvider() );
+        
+        dialog.setValidator(new ISelectionStatusValidator() {
+            @Override
+            public IStatus validate(final Object[] selection) {
+                if (selection.length > 0) {
+                    final Object item = selection[0];
+                    if ( !(item instanceof IFile) ) {
+                            return new Status(IStatus.ERROR, "unknownId","");
+                    }
+                }
+                return new Status( IStatus.OK, "unknownId", "");
+            }
+        });
+        
         dialog.setTitle( "Select File" );
-
+        dialog.setDoubleClickSelects( true );
+        
         IProject project = null;
 
         IFile file =
index cfadceb..b7cd3ff 100644 (file)
@@ -60,7 +60,9 @@ import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Control;
 import org.eclipse.swt.widgets.Dialog;
 import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
 import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Listener;
 import org.eclipse.swt.widgets.Shell;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.swt.widgets.Tree;
@@ -600,6 +602,14 @@ public class SetSourcePage extends Dialog {
         expandAll.setLayoutData(data);
         
         dialogTree = new Tree(treeComposite, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION );
+        
+        dialogTree.addListener( SWT.MeasureItem, new Listener() {
+            @Override
+            public void handleEvent( Event event ) {
+                event.height=19;
+            }
+        } );
+
 
         dialogTree.setLinesVisible(true);
         dialogTree.setHeaderVisible(true);
@@ -1007,6 +1017,9 @@ public class SetSourcePage extends Dialog {
             key = String.valueOf(parentItem.getItemCount()-1);
         }
         
+        if( !type.equals("Index") )
+            Helper.addComboInTreeItem(item, type, currentSubPage);
+        
         item.setText(new String[] { key, value, type });
         
         TreeItemData treeItemData = new TreeItemData();
@@ -1016,9 +1029,6 @@ public class SetSourcePage extends Dialog {
         
         item.setData("TREEITEMDATA", treeItemData);
         
-        if( !type.equals("Index") )
-            Helper.addComboInTreeItem(item, type, currentSubPage);
-        
         dialogTree.showItem(item);
         
         if( currentSubPage instanceof StaticSubPage ){
index 609e4ae..bb7d378 100644 (file)
@@ -112,10 +112,10 @@ public class StaticSubPage implements SourceDialogSubPage {
         try{
             if ( typeCombo.getSelectionIndex() == 0 ){
                 obj = normalGson.fromJson( text, JsonObject.class );
-                compactData = normalGson.toJson( obj ) ;
+                compactData = normalGson.toJson( obj );
             }else{
                 obj = Helper.parseXML( text  );
-                compactData = text.replaceAll( ">\\s*<", "><" )
+                compactData = text.replaceAll( ">\\s*<", "><" ).replace( "\r\n", "" ).replaceAll("\"", "'");
             }
         }catch(Exception e){}
 
@@ -516,7 +516,7 @@ public class StaticSubPage implements SourceDialogSubPage {
                 if ( json != null ) {
                     TreeRefreshTask task = new TreeRefreshTask(subPage, json);
                     parentDataTree.setData( "LAST_TASK", task );
-                    parentDataTree.getDisplay().timerExec( 600, task );
+                    parentDataTree.getDisplay().timerExec( 800, task );
                     
                     
                 }