SNIPPET : Refactoring id policy 24/18524/1
authorjeonghwan kim <jeonghwan0613.kim@samsung.com>
Tue, 25 Mar 2014 09:09:39 +0000 (18:09 +0900)
committerjeonghwan kim <jeonghwan0613.kim@samsung.com>
Tue, 25 Mar 2014 09:09:39 +0000 (18:09 +0900)
Change-Id: I108bd86c570995ae28f5d6279f9c881966502948
Signed-off-by: jeonghwan kim <jeonghwan0613.kim@samsung.com>
25 files changed:
org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/dnd/model/SnippetTemplate.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/ISerializer.java [new file with mode: 0644]
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/Part.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/nature/WebUIBuilderNature.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/converter/Converter.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/pagetemplate/ui/wizard/policy/CreatePolicy.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/converter/AbstractConverter.java [new file with mode: 0644]
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/converter/Converter.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/converter/IConverter.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/ISnippetManager.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/manager/SnippetManager.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/model/Descriptor.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/model/IDescriptor.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/model/ISnippet.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/model/Snippet.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/CreateWizard.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/CreateWizardFirstPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/ExportWizard.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/ExportWizardFirstPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/ImportWizard.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/ImportWizardFirstPage.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/policy/CreatePolicy.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/policy/ExportPolicy.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/ui/wizards/policy/ImportPolicy.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/editor/ComponentsCreator.java

index c1ea055..d9d5c78 100644 (file)
@@ -24,7 +24,6 @@
 package org.tizen.webuibuilder.gef.dnd.model;
 
 import org.eclipse.gef.requests.CreationFactory;
-import org.tizen.webuibuilder.model.Part;
 import org.tizen.webuibuilder.model.descriptors.DescriptorManager;
 import org.tizen.webuibuilder.snippet.converter.Converter;
 import org.tizen.webuibuilder.snippet.model.ISnippet;
@@ -38,8 +37,7 @@ public class SnippetTemplate extends AbstractTemplate {
         this.snippet = snippet;
         this.descriptorManager = descriptorManager;
         setType(SNIPPET);
-        SnippetCreationFactory factory =
-                new SnippetCreationFactory();
+        SnippetCreationFactory factory = new SnippetCreationFactory();
         setFactory(factory);
     }
 
@@ -56,9 +54,8 @@ public class SnippetTemplate extends AbstractTemplate {
         @Override
         public Object getNewObject() {
             String text = snippet.getDescriptor().getText();
-            Converter converter = new Converter(descriptorManager);
-            Part part = converter.convert(text);
-            return part;
+            Converter converter = new Converter();
+            return converter.convert(text);
         }
 
         /*
diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/ISerializer.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/ISerializer.java
new file mode 100644 (file)
index 0000000..594ebc4
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.model;
+
+
+
+public interface ISerializer {
+    /**
+     * 
+     * @return
+     */
+    public String serialize();
+
+    /**
+     * 
+     * @param text
+     */
+    public void deserialize(String text);
+}
\ No newline at end of file
index f948c3a..71bc920 100644 (file)
@@ -55,7 +55,7 @@ import org.w3c.dom.Element;
 /**
  * A model class.
  */
-public class Part {
+public class Part implements ISerializer {
 
     public enum PartClass {
         DUMMY_PART, DOCUMENT_PART, PAGE_PART, WIDGET_PART
@@ -69,7 +69,7 @@ public class Part {
      * An unique part-id.
      */
     private static int uniquePartId = 1;
-    
+
     // private PositionMode positionMode = PositionMode.RELATIVE_POSITION;
     private Rectangle position = null;
     private Rectangle originalPosition = null;
@@ -238,9 +238,9 @@ public class Part {
      *            a descriptor of a {@link Part}
      */
     public Part(Object ownerRef, PartDescriptor descriptor) {
-       this(ownerRef, descriptor, PartClass.DUMMY_PART);
+        this(ownerRef, descriptor, PartClass.DUMMY_PART);
     }
-    
+
     /**
      * Generates an unique part-id within this Document.
      * 
@@ -256,7 +256,7 @@ public class Part {
 
         return id;
     }
-    
+
     /**
      * Gets a owner reference of a {@link Part}.
      * 
@@ -280,7 +280,7 @@ public class Part {
             }
         }
     }
-    
+
     /**
      * Sets a partClass of a {@link Part}.
      * 
@@ -288,9 +288,9 @@ public class Part {
      *            a partClass of a {@link Part}
      */
     public void setPartClass(PartClass partClass) {
-       this.partClass = partClass;
+        this.partClass = partClass;
     }
-    
+
     /**
      * Gets a documentPart of a {@link Part}.
      * 
@@ -298,7 +298,7 @@ public class Part {
      *            a owner reference of a {@link Part}
      */
     public boolean isDocumentPart() {
-       return partClass == PartClass.DOCUMENT_PART;
+        return partClass == PartClass.DOCUMENT_PART;
     }
 
     /**
@@ -308,7 +308,7 @@ public class Part {
      *            a owner reference of a {@link Part}
      */
     public boolean isPagePart() {
-       return partClass == PartClass.PAGE_PART;
+        return partClass == PartClass.PAGE_PART;
     }
 
     /**
@@ -318,7 +318,7 @@ public class Part {
      *            a owner reference of a {@link Part}
      */
     public boolean isWidgetPart() {
-       return partClass == PartClass.WIDGET_PART;
+        return partClass == PartClass.WIDGET_PART;
     }
 
     /**
@@ -2122,20 +2122,20 @@ public class Part {
      * @param docHavingIdGenerator
      *            a {@link DocumentPart}
      */
-    private void setUniqueId(/*DocumentPart docHavingIdGenerator*/) {
-//        if (docHavingIdGenerator == null) {
-//            return;
-//        }
+    private void setUniqueId(/* DocumentPart docHavingIdGenerator */) {
+        // if (docHavingIdGenerator == null) {
+        // return;
+        // }
 
         String thisId = getPartId();
         String uniquePartId = getUniquePartId();
         if (thisId.isEmpty()) {
             setPartId(uniquePartId);
-        } else if (getOwnerDocument() != null){
-               if(getOwnerDocument().getChildOfId(thisId, true) != null) {
-                   // if doc has part with id already
-                   setPartId(uniquePartId);
-               }
+        } else if (getOwnerDocument() != null) {
+            if (getOwnerDocument().getChildOfId(thisId, true) != null) {
+                // if doc has part with id already
+                setPartId(uniquePartId);
+            }
         }
 
         Iterator<Part> itr = children.iterator();
@@ -2504,12 +2504,12 @@ public class Part {
             }
         }
     }
-    
+
     @Override
     public String toString() {
         return descriptor.getDescriptorId() + SPACE + getIdPropertyValue();
     }
-    
+
     /**
      * Gets default selector name. (e.g. #pageDd #widgetId).
      * 
@@ -2529,5 +2529,26 @@ public class Part {
             return builder.toString();
         }
     }
-    
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.tizen.webuibuilder.model.ISerializer#serialize()
+     */
+    @Override
+    public String serialize() {
+        // TODO : Implementation
+        return null;
+    }
+
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.tizen.webuibuilder.model.ISerializer#deserialize(java.lang.String)
+     */
+    @Override
+    public void deserialize(String text) {
+        // TODO : Implementation
+    }
+
 }
index f6c2b16..ac8de9d 100644 (file)
@@ -24,7 +24,6 @@
 package org.tizen.webuibuilder.nature;
 
 import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
 import org.eclipse.core.resources.IProjectNature;
 import org.eclipse.core.runtime.CoreException;
 import org.tizen.webuibuilder.BuilderPlugin;
index e93764b..a966c1c 100644 (file)
 
 package org.tizen.webuibuilder.pagetemplate.converter;
 
-import org.tizen.webuibuilder.model.Part;
-import org.tizen.webuibuilder.model.descriptors.DescriptorManager;
-import org.tizen.webuibuilder.model.io.CodeGenerator;
-import org.tizen.webuibuilder.snippet.converter.IConverter;
+import org.tizen.webuibuilder.model.ISerializer;
+import org.tizen.webuibuilder.snippet.converter.AbstractConverter;
 
 
-public class Converter implements IConverter {
-    private DescriptorManager descriptorManager;
-
-    private Converter() {
+public class Converter extends AbstractConverter {
+    public Converter() {
         super();
     }
 
-    public Converter(DescriptorManager descriptorManager) {
-        this();
-        this.descriptorManager = descriptorManager;
-    }
-
-    /*
-     * (non-Javadoc)
-     * 
-     * @see
-     * org.tizen.webuibuilder.feature.snippet.converter.IConverter#convert(org.tizen.webuibuilder
-     * .model.Part)
-     */
-    @Override
-    public String convert(Part part) {
-        String html =
-                CodeGenerator.generateCode(part, false, descriptorManager.getXsltDocument(), false);
-        return html;
-    }
-
     /*
      * (non-Javadoc)
-     * 
      * @see org.tizen.webuibuilder.snippet.converter.IConverter#convert(java.lang.String)
      */
     @Override
-    public Part convert(String text) {
+    public ISerializer convert(String text) {
         return null;
     }
 
index 297c96e..efea2a4 100644 (file)
@@ -82,7 +82,7 @@ public class CreatePolicy implements IWizardPolicy {
         // Create Descriptor
         template.setImageDescriptor(imageDescriptor);
         IDescriptor descriptor = new Descriptor();
-        Converter converter = new Converter(descriptorManager);
+        Converter converter = new Converter();
         String text = converter.convert(parts.get(0));
         descriptor.setText(text);
         template.setDescriptor(descriptor);
diff --git a/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/converter/AbstractConverter.java b/org.tizen.webuibuilder/src/org/tizen/webuibuilder/snippet/converter/AbstractConverter.java
new file mode 100644 (file)
index 0000000..61d88c1
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * 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.snippet.converter;
+
+import org.tizen.webuibuilder.model.ISerializer;
+
+
+
+public abstract class AbstractConverter implements IConverter {
+    /*
+     * (non-Javadoc)
+     * @see org.tizen.webuibuilder.snippet.converter.IConverter#convert(java.lang.Object)
+     */
+    @Override
+    public String convert(ISerializer model) {
+        return model.serialize();
+    }
+
+}
index 33e11c5..3a89c8e 100644 (file)
 
 package org.tizen.webuibuilder.snippet.converter;
 
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.StringBufferInputStream;
-import java.io.StringWriter;
-import java.util.List;
+import org.tizen.webuibuilder.model.ISerializer;
 
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerConfigurationException;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-import org.tizen.webuibuilder.BuilderConstants;
-import org.tizen.webuibuilder.model.Part;
-import org.tizen.webuibuilder.model.Part.PartClass;
-import org.tizen.webuibuilder.model.css.CssSelector;
-import org.tizen.webuibuilder.model.descriptors.DescriptorManager;
-import org.tizen.webuibuilder.model.descriptors.PagePartDescriptor;
-import org.tizen.webuibuilder.model.descriptors.PartDescriptor;
-import org.tizen.webuibuilder.model.descriptors.PropertyDescriptor;
-import org.tizen.webuibuilder.model.descriptors.TypeDescriptor;
-import org.tizen.webuibuilder.model.descriptors.WidgetPartDescriptor;
-import org.tizen.webuibuilder.model.io.PageReader_ver_2;
-import org.tizen.webuibuilder.model.io.PageWriter_ver_2;
-
-
-public class Converter implements IConverter {
-    private static int INDENT_SIZE = 4;
-    private DescriptorManager descriptorManager;
 
+public class Converter extends AbstractConverter {
     public Converter() {
         super();
     }
 
-    public Converter(DescriptorManager descriptorManager) {
-        this();
-        this.descriptorManager = descriptorManager;
-    }
-
     /*
      * (non-Javadoc)
-     * 
-     * @see
-     * org.tizen.webuibuilder.feature.snippet.converter.IConverter#convert(org.tizen.webuibuilder
-     * .model.Part)
+     * @see org.tizen.webuibuilder.snippet.converter.IConverter#convert(java.lang.String)
      */
     @Override
-    public String convert(Part part) {
-        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
-        DocumentBuilder builder = null;
-               try {
-                       builder = docFactory.newDocumentBuilder();
-               } catch (ParserConfigurationException e1) {
-                       // TODO Auto-generated catch block
-                       e1.printStackTrace();
-               }
-        
-        Document document = builder.newDocument();
-
-        Element rootElement = document.createElement("descriptor");
-        Element cssElement = document.createElement("tizen.css");
-        Element partElement = document.createElement("tizen.part");
-        partElement.appendChild(PageWriter_ver_2.writePart(document, part, false));
-        rootElement.appendChild(PageWriter_ver_2.writeCss(document, cssElement, part));
-        rootElement.appendChild(partElement);
-        document.appendChild(rootElement);
-
-        StringWriter stringWriter = new StringWriter();
-        
-               DOMSource source = new DOMSource(document);
-               StreamResult result = new StreamResult(stringWriter);
-
-               TransformerFactory factory = TransformerFactory.newInstance();
-               Transformer transformer = null;
-               try {
-                       transformer = factory.newTransformer();
-                       transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION,
-                                       BuilderConstants.YES);
-                       transformer.setOutputProperty(OutputKeys.ENCODING,
-                                       BuilderConstants.ENCODING);
-                       transformer.setOutputProperty(OutputKeys.METHOD,
-                                       BuilderConstants.XML);
-               } catch (TransformerConfigurationException e) {
-                       e.printStackTrace();
-               }
-
-               try {
-                       transformer.transform(source, result);
-               } catch (TransformerException e) {
-                       e.printStackTrace();
-               }
-               
-//        OutputFormat prettyFormat = OutputFormat.createPrettyPrint();
-//        prettyFormat.setIndentSize(INDENT_SIZE);
-//
-//        XMLWriter xmlwriter = new XMLWriter(stringWriter, prettyFormat);
-//        try {
-//            xmlwriter.write(document);
-//            xmlwriter.close();
-//        } catch (IOException e) {
-//            e.printStackTrace();
-//        }
-
-        return stringWriter.getBuffer().toString();
-    }
-
-    public Part convert(String text) {
-       DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();  
-       DocumentBuilder builder = null;
-        Document doc = null;
-
-        try {
-                       builder = factory.newDocumentBuilder();
-                       doc = builder.parse(new StringBufferInputStream(text));
-               } catch (ParserConfigurationException e) {
-                       e.printStackTrace();
-               } catch (SAXException e) {
-                       e.printStackTrace();
-               } catch (IOException e) {
-                       e.printStackTrace();
-               }
-
-        Element rootElement = doc.getDocumentElement();
-        List<CssSelector> selectors = null;
-        NodeList elemList = rootElement.getElementsByTagName("tizen.css");
-        for (int i = 0; i < elemList.getLength(); i++) {
-            Element childElement = (Element) elemList.item(i);
-            selectors = PageReader_ver_2.parseStyle((Element) childElement);
-        }
-
-        elemList = rootElement.getElementsByTagName("tizen.part");
-        if(elemList.getLength() > 0) {
-            Element childElement = (Element) elemList.item(0);
-            Part part = parse(childElement, descriptorManager, selectors);
-            return part;
-        } else {
-               return null;
-        }
-    }
-
-    private static Part parse(Element element, DescriptorManager descriptorManager,
-                              List<CssSelector> selectors) {
-        Part part = null;
-        PartDescriptor descriptor = descriptorManager.getPartDescriptor(element.getNodeName());
-        if (descriptor == null) {
-        } else {
-            if (descriptor instanceof WidgetPartDescriptor) {
-                part = new Part(null, (WidgetPartDescriptor) descriptor);
-            } else if (descriptor instanceof PagePartDescriptor) {
-                part = new Part(null, (PagePartDescriptor) descriptor);
-                part.setPartClass(PartClass.PAGE_PART);
-            } else {
-                // cannot be here
-                assert (false);
-            }
-
-            // Sets events and properties.
-            Attr attr = null;
-            NamedNodeMap attrList = element.getAttributes();
-            for (int i = 0; i < attrList.getLength(); i++) {
-                attr = (Attr) attrList.item(i);
-                if (BuilderConstants.ATTRIBUTE_EVENT_PREFIX.equals((attr.getName())
-                        .substring(0, BuilderConstants.ATTRIBUTE_EVENT_PREFIX.length()))) {
-                    part.setEventValue(attr.getName(), attr.getValue());
-                } else {
-                    part.setPropertyValueWhenPageRead(attr.getName(), attr.getValue());
-                }
-            }
-            String text = element.getTextContent();
-            if (!text.isEmpty()) {
-                PropertyDescriptor prop = null;
-                for (Object attrObj : descriptor.getPropertyDescriptors()) {
-                    prop = (PropertyDescriptor) attrObj;
-                    if (prop.getPropertyType().equals(TypeDescriptor.ID_OF_HTMLSTRING)) {
-                        part.setPropertyValueWhenPageRead(prop.getPropertyName(), text);
-                        break;
-                    }
-                }
-            }
-
-            // Sets selectors.
-            int size = selectors.size();
-            for (int i = 0; i < size; i++) {
-                CssSelector selector = selectors.get(i);
-                if (part.getIdPropertyValue().equals(selector.getPartId())) {
-                    part.addSelector(selector.getSelectorName(), selector);
-                }
-            }
-
-            // Adds children.
-            NodeList elemList = element.getChildNodes();
-            for (int i = 0; i < elemList.getLength(); i++) {
-               Node childNode = elemList.item(i);
-               if(childNode instanceof Element){
-                       Part childpart = parse((Element)childNode, descriptorManager, selectors);
-                       part.addChildWhenPageRead(childpart);
-               }
-            }
-        }
-
-        return part;
+    public ISerializer convert(String text) {
+        return null;
     }
 
-}
+}
\ No newline at end of file
index 2b5e6e9..b8d8a04 100644 (file)
 
 package org.tizen.webuibuilder.snippet.converter;
 
-import org.tizen.webuibuilder.model.Part;
-
+import org.tizen.webuibuilder.model.ISerializer;
 
 public interface IConverter {
-    public Part convert(String text);
+    public ISerializer convert(String text);
 
-    public String convert(Part part);
+    public String convert(ISerializer model);
 }
\ No newline at end of file
index b7fc0c1..8457281 100644 (file)
 
 package org.tizen.webuibuilder.snippet.manager;
 
-import java.util.List;
+import java.util.Collection;
 
 import org.tizen.webuibuilder.snippet.model.ISnippet;
 
-
+/**
+ * Interface for a snippet manager
+ * <p>
+ * The class <code>SnippetManager</code> provides an implementation of this interface.
+ * </p>
+ * 
+ * @see SnippetManager
+ */
 public interface ISnippetManager {
-    public List<?> getSnippets();
+    public Collection<?> getSnippets();
 
     public boolean create(ISnippet snippet);
 
index 3bfcd7a..09607b2 100644 (file)
 package org.tizen.webuibuilder.snippet.manager;
 
 import java.io.File;
-import java.util.ArrayList;
-import java.util.List;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Map;
 
 import org.eclipse.core.runtime.IPath;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.tizen.common.util.FileUtil;
 import org.tizen.webuibuilder.snippet.InternalMessages;
 import org.tizen.webuibuilder.snippet.loader.ISnippetLoader;
@@ -37,10 +40,12 @@ import org.tizen.webuibuilder.utility.ResourceUtil;
 
 
 public class SnippetManager implements ISnippetManager {
-    private List<ISnippet> snippets;
+    private Map<Integer, ISnippet> snippets = null;
+    private Logger logger = LoggerFactory.getLogger(getClass());
 
     public SnippetManager() {
         super();
+        snippets = new HashMap<Integer, ISnippet>();
         load();
     }
 
@@ -50,8 +55,8 @@ public class SnippetManager implements ISnippetManager {
      * @see org.tizen.webuibuilder.feature.snippet.manager.ISnippetManager#getSnippets()
      */
     @Override
-    public List<ISnippet> getSnippets() {
-        return snippets;
+    public Collection<ISnippet> getSnippets() {
+        return snippets.values();
     }
 
     /*
@@ -176,7 +181,7 @@ public class SnippetManager implements ISnippetManager {
         snippets = load(getDefaultPath());
     }
 
-    private List<ISnippet> load(String path) {
+    private Map<Integer, ISnippet> load(String path) {
         File folder = new File(path);
         if (!folder.exists()) {
             return null;
@@ -184,31 +189,42 @@ public class SnippetManager implements ISnippetManager {
         if (!folder.isDirectory()) {
             return null;
         }
-        List<ISnippet> snippets = new ArrayList<ISnippet>();
+
+        Map<Integer, ISnippet> snippets = new HashMap<Integer, ISnippet>();
         File[] files = folder.listFiles();
         for (File file : files) {
+            // snippet directory has file
             if (!file.isDirectory()) {
+                logger.warn("snippet directory has file");
                 continue;
             }
 
             String snippetPath = path + IPath.SEPARATOR + file.getName();
             ISnippetLoader loader = new SnippetLoader();
+            // snippet load fail
             ISnippet snippet = loader.load(snippetPath);
             if (snippet == null) {
+                logger.warn("snippet load fail");
                 continue;
             }
-            snippets.add(snippet);
+
+            // snippet id consistency broken
+            Integer key = Integer.parseInt(snippet.getId());
+            if (snippets.containsKey(key)) {
+                logger.warn("snippet id consistency broken");
+                return null;
+            }
+            snippets.put(key, snippet);
         }
         return snippets;
     }
 
-    private String createId() {
-        Integer id = null;
-        if (snippets.size() > 0) {
-            String lastId = snippets.get(snippets.size() - 1).getId();
-            id = Integer.valueOf(lastId) + 1;
-        } else {
-            id = Integer.valueOf(1);
+    protected String createId() {
+        // initialize id
+        Integer id = Integer.valueOf(1);
+        logger.info("id : " + id);
+        while (snippets.containsKey(id)) {
+            id = id + 1;
         }
         return id.toString();
     }
index 1b19c82..5293db1 100644 (file)
 package org.tizen.webuibuilder.snippet.model;
 
 public class Descriptor implements IDescriptor {
-    private String text;
+    private String text = null;
 
     public Descriptor() {
         super();
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.tizen.webuibuilder.snippet.model.IDescriptor#setText(java.lang.String)
+     */
+    @Override
     public void setText(String text) {
         this.text = text;
     }
 
+    /*
+     * (non-Javadoc)
+     * 
+     * @see org.tizen.webuibuilder.snippet.model.IDescriptor#getText()
+     */
+    @Override
     public String getText() {
         return text;
     }
index 5c7282d..5543828 100644 (file)
 
 package org.tizen.webuibuilder.snippet.model;
 
+/**
+ * Interface for a descriptor.
+ * <p>
+ * The class <code>Descriptor</code> provides an implementation of this interface.
+ * </p>
+ * 
+ * @see Descriptor
+ */
 public interface IDescriptor {
+    /**
+     * Sets the descriptor text.
+     */
     public void setText(String text);
 
+    /**
+     * Gets the descriptor text.
+     * 
+     * @return descriptor text.
+     */
     public String getText();
 }
\ No newline at end of file
index f4811c2..3879b7f 100644 (file)
@@ -26,24 +26,72 @@ package org.tizen.webuibuilder.snippet.model;
 import org.eclipse.jface.resource.ImageDescriptor;
 
 
+/**
+ * Interface for a snippet.
+ * <p>
+ * The class <code>Snippet</code> provides an implementation of this interface.
+ * </p>
+ * 
+ * @see Snippet
+ */
 public interface ISnippet {
+    /**
+     * Sets the snippet id.
+     */
     public void setId(String id);
 
+    /**
+     * Gets the snippet's id.
+     * 
+     * @return snippet id.
+     */
     public String getId();
 
+    /**
+     * Sets the snippet name.
+     */
     public void setName(String name);
 
+    /**
+     * Gets the snippet's name.
+     * 
+     * @return snippet name.
+     */
     public String getName();
 
+    /**
+     * Sets the snippet description.
+     */
     public void setDescription(String description);
 
+    /**
+     * Gets the snippet's description.
+     * 
+     * @return snippet description.
+     */
     public String getDescription();
 
+    /**
+     * Sets the image descriptor.
+     */
     public void setImageDescriptor(ImageDescriptor imageDescriptor);
 
+    /**
+     * Gets the image descriptor.
+     * 
+     * @return image descriptor.
+     */
     public ImageDescriptor getImageDescriptor();
 
+    /**
+     * Sets the descriptor.
+     */
     public void setDescriptor(IDescriptor descriptor);
 
+    /**
+     * Gets the descriptor.
+     * 
+     * @return descriptor.
+     */
     public IDescriptor getDescriptor();
 }
\ No newline at end of file
index 5af04bf..d49ada1 100644 (file)
@@ -27,11 +27,11 @@ import org.eclipse.jface.resource.ImageDescriptor;
 
 
 public class Snippet implements ISnippet {
-    private String id;
-    private String name;
-    private String description;
-    private ImageDescriptor imageDescriptor;
-    private IDescriptor descriptor;
+    private String id = null;
+    private String name = null;
+    private String description = null;
+    private ImageDescriptor imageDescriptor = null;
+    private IDescriptor descriptor = null;
 
     public Snippet() {
         super();
index dc007fb..8e640f8 100644 (file)
@@ -35,8 +35,8 @@ import org.tizen.webuibuilder.utility.ResourceManager;
 
 
 public class CreateWizard extends Wizard {
-    private List<Part> parts;
-    private CreateWizardFirstPage firstPage;
+    private List<Part> parts = null;
+    private CreateWizardFirstPage firstPage = null;
 
     public CreateWizard(List<Part> parts) {
         super();
index c71d68f..4434200 100644 (file)
@@ -47,20 +47,20 @@ public class CreateWizardFirstPage extends WizardPage implements ModifyListener,
     public static final String NAME = CreateWizardFirstPage.class.getName();
 
     // controls
-    private Composite rootComposite;
+    private Composite rootComposite = null;
 
-    private Composite imageComposite;
-    private Label imageLabel;
-    private Text imageText;
-    private Button imageBrowseButton;
+    private Composite imageComposite = null;
+    private Label imageLabel = null;
+    private Text imageText = null;
+    private Button imageBrowseButton = null;
 
-    private Composite nameComposite;
-    private Label nameLabel;
-    private Text nameText;
+    private Composite nameComposite = null;
+    private Label nameLabel = null;
+    private Text nameText = null;
 
-    private Composite descriptionComposite;
-    private Label descriptionLabel;
-    private Text descriptionText;
+    private Composite descriptionComposite = null;
+    private Label descriptionLabel = null;
+    private Text descriptionText = null;
 
     protected CreateWizardFirstPage(String pageName, String title, ImageDescriptor titleImage) {
         super(pageName, title, titleImage);
index afb673a..333211d 100644 (file)
@@ -35,7 +35,7 @@ import org.tizen.webuibuilder.utility.ResourceManager;
 
 
 public class ExportWizard extends Wizard implements IExportWizard {
-    private ExportWizardFirstPage fFirstPage;
+    private ExportWizardFirstPage fFirstPage = null;
 
     /*
      * (non-Javadoc)
index 3e25494..ed028c9 100644 (file)
@@ -23,6 +23,7 @@
 
 package org.tizen.webuibuilder.snippet.ui.wizards;
 
+import java.util.Collection;
 import java.util.List;
 
 import org.eclipse.jface.resource.ImageDescriptor;
@@ -59,23 +60,23 @@ public class ExportWizardFirstPage extends WizardPage implements ISelectionChang
     public static final String NAME = ExportWizardFirstPage.class.getName();
 
     // controls
-    private Composite rootComposite;
+    private Composite rootComposite = null;
 
-    private Composite snippetComposite;
-    private Label snippetLabel;
-    private Text snippetText;
-    private TableViewer viewer;
+    private Composite snippetComposite = null;
+    private Label snippetLabel = null;
+    private Text snippetText = null;
+    private TableViewer viewer = null;
 
-    private Composite pathComposite;
-    private Label pathLabel;
-    private Text pathText;
-    private Button pathBrowseButton;
+    private Composite pathComposite = null;
+    private Label pathLabel = null;
+    private Text pathText = null;
+    private Button pathBrowseButton = null;
 
-    private Composite nameComposite;
-    private Label nameLabel;
-    private Text nameText;
+    private Composite nameComposite = null;
+    private Label nameLabel = null;
+    private Text nameText = null;
 
-    private ISnippet snippet;
+    private ISnippet snippet = null;
 
     public ISnippet getSnippet() {
         return snippet;
@@ -198,8 +199,8 @@ public class ExportWizardFirstPage extends WizardPage implements ISelectionChang
          */
         @Override
         public Object[] getElements(Object inputElement) {
-            if (inputElement instanceof List) {
-                List<?> descriptors = (List<?>) inputElement;
+            if (inputElement instanceof Collection) {
+                Collection<?> descriptors = (Collection<?>) inputElement;
                 return descriptors.toArray();
             }
             return null;
index 91c7306..18b8d40 100644 (file)
@@ -33,7 +33,7 @@ import org.tizen.webuibuilder.utility.ResourceManager;
 
 
 public class ImportWizard extends Wizard {
-    private ImportWizardFirstPage firstPage;
+    private ImportWizardFirstPage firstPage = null;
 
     public ImportWizard() {
         super();
index 3d9e447..c1f7518 100644 (file)
@@ -46,22 +46,22 @@ public class ImportWizardFirstPage extends WizardPage implements ModifyListener,
     public static final String NAME = ImportWizardFirstPage.class.getName();
 
     // controls
-    private Composite rootComposite;
+    private Composite rootComposite = null;
 
-    private Composite importComposite;
-    private Label importLabel;
-    private Text importText;
-    private Button importBrowseButton;
+    private Composite importComposite = null;
+    private Label importLabel = null;
+    private Text importText = null;
+    private Button importBrowseButton = null;
 
-    private Composite nameComposite;
-    private Label nameLabel;
-    private Text nameText;
+    private Composite nameComposite = null;
+    private Label nameLabel = null;
+    private Text nameText = null;
 
-    private Composite descriptionComposite;
-    private Label descriptionLabel;
-    private Text descriptionText;
+    private Composite descriptionComposite = null;
+    private Label descriptionLabel = null;
+    private Text descriptionText = null;
 
-    private ISnippet snippet;
+    private ISnippet snippet = null;
 
     protected ImportWizardFirstPage(String pageName, String title, ImageDescriptor titleImage) {
         super(pageName, title, titleImage);
index c2e3f15..543efc6 100644 (file)
 package org.tizen.webuibuilder.snippet.ui.wizards.policy;
 
 import java.io.File;
-import java.util.List;
 
 import org.eclipse.jface.resource.ImageDescriptor;
 import org.eclipse.swt.graphics.ImageData;
 import org.eclipse.swt.graphics.ImageLoader;
 import org.tizen.webuibuilder.model.Part;
-import org.tizen.webuibuilder.snippet.converter.Converter;
 import org.tizen.webuibuilder.snippet.manager.ISnippetManager;
 import org.tizen.webuibuilder.snippet.manager.SnippetManager;
 import org.tizen.webuibuilder.snippet.model.Descriptor;
@@ -41,18 +39,18 @@ import org.tizen.webuibuilder.ui.wizards.IWizardPolicy;
 
 
 public class CreatePolicy implements IWizardPolicy {
-    private List<Part> parts;
-    private String name;
-    private String description;
-    private String imagePath;
+    private Object model = null;
+    private String name = null;
+    private String description = null;
+    private String imagePath = null;
 
     @SuppressWarnings("unused")
     private CreatePolicy() {
         super();
     }
 
-    public CreatePolicy(List<Part> parts, String name, String description, String imagePath) {
-        this.parts = parts;
+    public CreatePolicy(Object model, String name, String description, String imagePath) {
+        this.model = model;
         this.name = name;
         this.description = description;
         this.imagePath = imagePath;
@@ -75,11 +73,16 @@ public class CreatePolicy implements IWizardPolicy {
         ImageLoader imageLoader = new ImageLoader();
         ImageData[] imageData = imageLoader.load(imageFile.getPath());
         ImageDescriptor imageDescriptor = ImageDescriptor.createFromImageData(imageData[0]);
-        // Create Descriptor
         snippet.setImageDescriptor(imageDescriptor);
+        // Create Descriptor
         IDescriptor descriptor = new Descriptor();
-        Converter converter = new Converter();
-        String text = converter.convert(parts.get(0));
+        if (!(model instanceof Part)) {
+            return false;
+        }
+        // TODO : implementation Model -> String serialization
+//        Converter converter = new Converter();
+//        String text = converter.convert(parts.get(0));
+        String text = "";
         descriptor.setText(text);
         snippet.setDescriptor(descriptor);
 
index 3e121dd..0c86bd1 100644 (file)
@@ -30,9 +30,9 @@ import org.tizen.webuibuilder.ui.wizards.IWizardPolicy;
 
 
 public class ExportPolicy implements IWizardPolicy {
-    private ISnippet snippet;
-    private String exportPath;
-    private String name;
+    private ISnippet snippet = null;
+    private String exportPath = null;
+    private String name = null;
 
     private ExportPolicy() {
         super();
index 2c5ede5..21cf5c9 100644 (file)
@@ -30,7 +30,7 @@ import org.tizen.webuibuilder.ui.wizards.IWizardPolicy;
 
 
 public class ImportPolicy implements IWizardPolicy {
-    private ISnippet snippet;
+    private ISnippet snippet = null;
 
     private ImportPolicy() {
         super();
index 6eb6c05..b061875 100644 (file)
@@ -138,7 +138,7 @@ public class ComponentsCreator {
     private void addSnippetEntry(PaletteRoot root) {
         PaletteDrawer snippetDrawer = createPaletteDrawer(DesignerMessages.ComponentsCreator_0);
         SnippetManager snippetManager = new SnippetManager();
-        List<ISnippet> snippets = snippetManager.getSnippets();
+        Collection<ISnippet> snippets = snippetManager.getSnippets();
         if (snippets == null) {
             return;
         }