UIB: apply n-screen to preview 93/21693/1
authorgyeongmin.ju <gyeongmin.ju@samsung.com>
Mon, 26 May 2014 12:51:07 +0000 (21:51 +0900)
committergyeongmin.ju <gyeongmin.ju@samsung.com>
Mon, 26 May 2014 12:51:07 +0000 (21:51 +0900)
Signed-off-by: gyeongmin.ju <gyeongmin.ju@samsung.com>
Change-Id: I8ba407070a9212c03deba84ff11273ca00ad2b8a

org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/app/AppManagerForHTML.java

index 050957d..3832fee 100644 (file)
@@ -130,7 +130,7 @@ public class AppManagerForHTML extends AppManager {
                         // pageData.addPageListener(this);
                     }
                 }
-                
+
             }
         } else {
             // appManager = new AppManager(projectManager, null);
@@ -308,20 +308,21 @@ public class AppManagerForHTML extends AppManager {
 
         String page = "data-role=\"page\""; //$NON-NLS-1$
         String newHtml = null;
-               if (html.contains(page)) {
-                       String id = BuilderConstants.PROPERTY_ID + BuilderConstants.EQUAL
-                                       + BuilderConstants.QUOTATION_MARK;
-                       int startIndex = html.indexOf(id, html.indexOf(page)) + 4;
-                       String startHtml = html.substring(0, startIndex);
-                       int endIndex = html.indexOf(BuilderConstants.QUOTATION_MARK,
-                                       startIndex);
-                       String endHtml = html.substring(endIndex, html.length());
-                       newHtml = startHtml + pageName + endHtml;
-               }
-               return (newHtml != null) ? HtmlReader.loadHtmlStream(this,
-                               new ByteArrayInputStream(newHtml.getBytes())) : null;
-       }
-    
+        if (html.contains(page)) {
+            String id =
+                    BuilderConstants.PROPERTY_ID + BuilderConstants.EQUAL
+                            + BuilderConstants.QUOTATION_MARK;
+            int startIndex = html.indexOf(id, html.indexOf(page)) + 4;
+            String startHtml = html.substring(0, startIndex);
+            int endIndex = html.indexOf(BuilderConstants.QUOTATION_MARK, startIndex);
+            String endHtml = html.substring(endIndex, html.length());
+            newHtml = startHtml + pageName + endHtml;
+        }
+        return (newHtml != null) ? HtmlReader.loadHtmlStream(this,
+                                                             new ByteArrayInputStream(newHtml
+                                                                     .getBytes())) : null;
+    }
+
     @Override
     public void addPage(PageData page, boolean isExistsPagePart) {
         String path = null;
@@ -330,17 +331,18 @@ public class AppManagerForHTML extends AppManager {
                     getProjectManager().getProject().getFile(page.getPagePath())
                             .getProjectRelativePath().toString();
         } else {
-               path = pageFileName.substring(0,
-                               pageFileName.lastIndexOf("/", pageFileName.length()-1));
+            path =
+                    pageFileName
+                            .substring(0, pageFileName.lastIndexOf("/", pageFileName.length() - 1));
         }
-        
+
         pageDataSet.addPage(page, path, isExistsPagePart);
-        
-        if(isExistsPagePart) {
-               DomUtil.appendPageNode(document, DomUtil.BODY_ELEMENT, page.getPagePart().getElement());
+
+        if (isExistsPagePart) {
+            DomUtil.appendPageNode(document, DomUtil.BODY_ELEMENT, page.getPagePart().getElement());
         }
     }
-    
+
     @Override
     public void addPage(int index, PageData page, boolean isExistsPagePart) {
         String path = null;
@@ -349,18 +351,20 @@ public class AppManagerForHTML extends AppManager {
                     getProjectManager().getProject().getFile(page.getPagePath())
                             .getProjectRelativePath().toString();
         } else {
-               path = pageFileName.substring(0,
-                               pageFileName.lastIndexOf('/', pageFileName.length()-1));
+            path =
+                    pageFileName
+                            .substring(0, pageFileName.lastIndexOf('/', pageFileName.length() - 1));
         }
-        
-        if(isExistsPagePart) {
-               PageData refPageData = getPageByIndex(index); 
-               DomUtil.insertBeforePageNode(document, DomUtil.BODY_ELEMENT, page.getPagePart().getElement(), 
-                               (refPageData != null) ? refPageData.getPagePart().getElement() : null);
+
+        if (isExistsPagePart) {
+            PageData refPageData = getPageByIndex(index);
+            DomUtil.insertBeforePageNode(document, DomUtil.BODY_ELEMENT, page.getPagePart()
+                    .getElement(), (refPageData != null) ? refPageData.getPagePart().getElement()
+                    : null);
         }
         pageDataSet.addPage(index, page, path, isExistsPagePart);
     }
-    
+
     public void addPage(String html, String pageName) {
         if (html == null || pageName == null) {
             return;
@@ -411,23 +415,24 @@ public class AppManagerForHTML extends AppManager {
 
     @Override
     public void removePage(int index) {
-       
-       DomUtil.removePageNode(document, DomUtil.BODY_ELEMENT, getPageData(index).getPagePart().getElement());
-       
-       pageDataSet.removePageWithPart(index);
-
-               if (index == startupPage) {
-                       if (getPages().size() > 0) {
-                               if (index >= getPages().size()) {
-                                       index = getPages().size() - 1;
-                               }
-                               setStartupPage(index);
-                       } else {
-                               setStartupPage(-1);
-                       }
-               }
+
+        DomUtil.removePageNode(document, DomUtil.BODY_ELEMENT, getPageData(index).getPagePart()
+                .getElement());
+
+        pageDataSet.removePageWithPart(index);
+
+        if (index == startupPage) {
+            if (getPages().size() > 0) {
+                if (index >= getPages().size()) {
+                    index = getPages().size() - 1;
+                }
+                setStartupPage(index);
+            } else {
+                setStartupPage(-1);
+            }
+        }
     }
-    
+
     @Override
     public void removeAllPages() {
         pageDataSet.removeAllPagesWithPart();
@@ -485,13 +490,13 @@ public class AppManagerForHTML extends AppManager {
     public Document getDocument() {
         return document;
     }
-    
+
     public void setDocument(Document document) {
-       this.document = document;
+        this.document = document;
     }
-    
+
     public String getPageFileName() {
-       return this.pageFileName;
+        return this.pageFileName;
     }
 
     @Override
@@ -749,6 +754,7 @@ public class AppManagerForHTML extends AppManager {
         head.insertBefore(newElmBase, head.getFirstChild());
 
         String html = null;
+        String css = null;
         if (rootPart != null) {
             Part part = null;
             if (rootPart.isDocumentPart()) {
@@ -760,12 +766,19 @@ public class AppManagerForHTML extends AppManager {
             html =
                     CodeGenerator.generateCode(part, false, getDescriptorManager()
                             .getXsltDocument(), false);
+            css = CodeGenerator.generateCssCode(part);
         }
 
         Element newElm = editDoc.createElement("script");
         newElm.setAttribute("src", "./tizen-ui-builder-tool/res/html/preview.js");
         head.appendChild(newElm);
 
+        Element newElm2 = editDoc.createElement("style");
+        newElm2.setAttribute("type", "text/css");
+        newElm2.setAttribute("id", "page_style");
+        newElm2.setTextContent("%css%");
+        head.appendChild(newElm2);
+
         NodeList bodys = editDoc.getElementsByTagName("body");
         Element body = null;
         if (bodys == null) {
@@ -778,17 +791,21 @@ public class AppManagerForHTML extends AppManager {
         for (int i = 0; i < len; i++) {
             body.removeChild(body.getFirstChild());
         }
+        body.setTextContent("%html%");
 
         if (html == null) {
             html = "";
         }
-        body.setTextContent("%html%");
+        if (css == null) {
+            css = "";
+        }
 
         // String tempHtml =
         // HtmlWriter.writeToString((Element)editDoc.getFirstChild().getChildNodes().item(index));
         String tempHtml = HtmlWriter.writeToString(editDoc);
 
         tempHtml = tempHtml.replace("%html%", html);
+        tempHtml = tempHtml.replace("%css%", css);
 
         return tempHtml;
     }