UIB : remove NPE 96/18696/1
authorgyeongmin.ju <gyeongmin.ju@samsung.com>
Fri, 28 Mar 2014 07:58:32 +0000 (16:58 +0900)
committergyeongmin.ju <gyeongmin.ju@samsung.com>
Fri, 28 Mar 2014 07:58:32 +0000 (16:58 +0900)
Signed-off-by: gyeongmin.ju <gyeongmin.ju@samsung.com>
Change-Id: Id8757b4c3d5e8b0bae3fd783dcca1ee09d81d6f8

org.tizen.webuibuilder/src/org/tizen/webuibuilder/bridge/DesignerGoingBridge.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/browserwidget/ImageBufferedBrowserPool.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/extintrf/DeclarationViewInfoProvider.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/gef/viewer/HoverBrowserViewer.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/ui/handler/PageDesignerFileSelectionHandler.java

index 8319ba1..859633c 100644 (file)
@@ -169,9 +169,21 @@ public class DesignerGoingBridge extends GoingBridge {
 
         JsNumber x, y, w, h;
         x = JsNumber.check(ret.get("x"));
+        if (x == null) {
+            x = new JsNumber(0);
+        }
         y = JsNumber.check(ret.get("y"));
+        if (y == null) {
+            y = new JsNumber(0);
+        }
         w = JsNumber.check(ret.get("w"));
+        if (w == null) {
+            w = new JsNumber(0);
+        }
         h = JsNumber.check(ret.get("h"));
+        if (h == null) {
+            h = new JsNumber(0);
+        }
 
         JsNumber l, r, t, b;
         l = JsNumber.check(ret.get("l"));
@@ -321,8 +333,10 @@ public class DesignerGoingBridge extends GoingBridge {
                 return null;
             }
             JsString wid = JsString.check(obj.get("wid"));
-            WidgetPosition widgetPosition = parseWidgetPosition(obj.get("rectangle"));
-            result.put(wid.value(), widgetPosition);
+            if (wid != null) {
+                WidgetPosition widgetPosition = parseWidgetPosition(obj.get("rectangle"));
+                result.put(wid.value(), widgetPosition);
+            }
         }
         return result;
     }
index f3446ed..70ea9a1 100644 (file)
@@ -37,7 +37,7 @@ public class ImageBufferedBrowserPool implements Runnable {
 
     private List<ImageBufferedBrowser> imageBufferedBrowserList;
     private DesignerGoingBridge goingBridge;
-    private Map<String, WidgetPosition> allWidgetPositions;
+    //private Map<String, WidgetPosition> allWidgetPositions;
     private Display display;
     private ContentsAreaChangedListener listener;
     private int tickTime = 40;
@@ -48,7 +48,7 @@ public class ImageBufferedBrowserPool implements Runnable {
         this.display = display;
         this.listener = listener;
 
-        allWidgetPositions = null;
+        //allWidgetPositions = null;
 
         display.timerExec(tickTime, this);
     }
@@ -73,30 +73,30 @@ public class ImageBufferedBrowserPool implements Runnable {
         return imageBufferedBrowserList.get(index);
     }
 
-    public Map<String, WidgetPosition> getWidgetPositions() {
-        if (allWidgetPositions == null) {
-            allWidgetPositions = goingBridge.getAllWidgetPositions();
-        }
-        return allWidgetPositions;
-    }
-
-    public WidgetPosition getWidgetPosition(String partId) {
-        Map<String, WidgetPosition> pos = getWidgetPositions();
-        return (pos != null) ? pos.get(partId) : null;
-    }
-
-    private void invalidateWidgetPositions() {
-        allWidgetPositions = null;
-    }
+//    public Map<String, WidgetPosition> getWidgetPositions() {
+//        if (allWidgetPositions == null) {
+//            allWidgetPositions = goingBridge.getAllWidgetPositions();
+//        }
+//        return allWidgetPositions;
+//    }
+//
+//    public WidgetPosition getWidgetPosition(String partId) {
+//        Map<String, WidgetPosition> pos = getWidgetPositions();
+//        return (pos != null) ? pos.get(partId) : null;
+//    }
+//
+//    private void invalidateWidgetPositions() {
+//        allWidgetPositions = null;
+//    }
 
     public void setBrowserSize(int index, int width, int height) {
         getBrowser(index).setBrowserSize(width, height);
-        invalidateWidgetPositions();
+        //invalidateWidgetPositions();
     }
 
-    public void updateSizeEditings() {
-        invalidateWidgetPositions();
-    }
+//    public void updateSizeEditings() {
+//        invalidateWidgetPositions();
+//    }
 
     @Override
     public void run() {
index b12e982..03977d0 100644 (file)
@@ -260,19 +260,38 @@ public class DeclarationViewInfoProvider implements IDeclarationViewInfoProvider
 
         StringBuffer strBuf = new StringBuffer();
         String strLine = null;
+        
+        
+        FileReader fr = null;
+        BufferedReader br = null;
         try {
-               FileReader fr = new FileReader(jsPath);
-            BufferedReader br = new BufferedReader(fr);
+            fr = new FileReader(jsPath);
+            br = new BufferedReader(fr);
             while ((strLine = br.readLine()) != null) {
                 strBuf.append(strLine);
                 strBuf.append(System.getProperty("line.separator"));
             }
-            fr.close();
         } catch (FileNotFoundException e) {
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
         } finally {
+            if(br != null) {
+                try {
+                    br.close();
+                } catch (IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
+            if(fr != null) {
+                try {
+                    fr.close();
+                } catch (IOException e) {
+                    // TODO Auto-generated catch block
+                    e.printStackTrace();
+                }
+            }
         }
         return strBuf.toString();
     }
@@ -453,6 +472,10 @@ public class DeclarationViewInfoProvider implements IDeclarationViewInfoProvider
         if (getTargetModel() == null) {
             return null;
         }
+        
+        if (getDescriptorManager() == null) {
+            return null;
+        }
 
         String code =
                 CodeGenerator.generateCode(getTargetModel(), includePid, getDescriptorManager()
index 181a928..d68ef66 100644 (file)
@@ -20,6 +20,7 @@
  *
  */
 
+
 package org.tizen.webuibuilder.gef.viewer;
 
 import java.beans.PropertyChangeEvent;
@@ -78,929 +79,911 @@ import org.tizen.webuibuilder.ui.editor.BrowserLayoutEvent;
 import org.tizen.webuibuilder.ui.editor.IBrowserLayoutListener;
 import org.tizen.webuibuilder.ui.editor.ScreenSize;
 
+
 public class HoverBrowserViewer extends ScrollingGraphicalViewer
-/* GraphicalViewerImpl */implements ISelectionChangedListener,
-               ContentsAreaChangedListener, IPartListener, ICssListener,
-               IBrowserLayoutListener {
-
-       // private String TEMP_FILE = "res/html/ground.html";
-
-       private DesignerGoingBridge goingBridge;
-       // private int currentPage = 0;
-       private EditPart currentPageEditPart = null;
-       private HoverViewerRootEditPart rootEditPart;
-       protected ImageBufferedBrowserProvider webBrowser;
-       protected PageData pageData;
-       private Part rootPart;
-       private int scrollPos = 0;
-       protected String theme;
-       protected String scale;
-       private Point originalSize;
-       private float zoomScale;
-       private boolean landscape;
-       protected IEditorInput editorInput;
-       private ToolTip tooltip;
-       // private IProject project;
-       protected AppManager appManager;
-
-       protected boolean isValidTempHtml = false;
-       protected String tempHtml = null;
-       protected String rootPathUri = null;
-       protected String pagePathUri = null;
-
-       private List<IBrowserLayoutListener> listeners = new LinkedList<IBrowserLayoutListener>();
-
-       public HoverBrowserViewer(AppManager appManager, /* PageData pageData, */
-                       ScreenSize screen, IEditorInput editorInput) {
-               // this.pageData = pageData;
-               originalSize = new Point(screen.getWidth(), screen.getHeight());
-               this.appManager = appManager;
-               this.pageData = appManager.getPageData(0);
-               this.theme = appManager.getFrameworkTheme();
-               this.scale = appManager.getFrameworkScale();
-               this.editorInput = editorInput;
-
-               addSelectionChangedListener(this);
-               addBrowserLayoutListener(this);
-       }
-
-       @Override
-       public void setContents(Object contents) {
-               super.setContents(contents);
-
-               rootPart = (Part) contents; // pageData.getRootPart();
-               rootPart.addPartListener(this, true);
-               rootPart.addCssListener(this, true);
-
-               currentPageEditPart = getFirstPageEditPart();
-       }
-
-       @Override
-       protected void handleDispose(DisposeEvent e) {
-               rootPart.removePartListener(this);
-               rootPart.removeCssListener(this);
-               super.handleDispose(e);
-       }
-
-       @Override
-       public void setControl(Control control) {
-               super.setControl(control);
-
-               if (control != null) {
-                       getFigureCanvas().setHorizontalScrollBarVisibility(
-                                       FigureCanvas.AUTOMATIC);
-                       getFigureCanvas().setVerticalScrollBarVisibility(
-                                       FigureCanvas.AUTOMATIC);
-
-                       webBrowser = createBrowser(control.getParent());
-                       initLayout();
-                       resizeBrowser();
-
-                       addEventListener(this);
-                       addDropTargetListener();
-               }
-       }
-
-       // @Override
-       public Control createControl2(Composite parent) {
-               return null;
-       }
-
-       /**
-        * Adds a part listener.
-        * 
-        * @param listener
-        *            a part listener
-        * @param includeBubbleEvents
-        *            whether bubble listener is used.
-        */
-       public void addBrowserLayoutListener(IBrowserLayoutListener listener) {
-               listeners.add(listener);
-       }
-
-       /**
-        * Removes a part listener.
-        * 
-        * @param listener
-        *            a part listener
-        */
-       public void removeBrowserLayoutListener(IBrowserLayoutListener listener) {
-               listeners.remove(listener);
-       }
-
-       /**
-        * Fires a css event.
-        * 
-        * @param event
-        *            a css event
-        * @param listeners
-        *            a List containing css listener
-        */
-       private void fireEvent(BrowserLayoutEvent event) {
-               if (event == null || listeners == null) {
-                       return;
-               }
-
-               int size = listeners.size();
-               for (int i = 0; i < size; i++) {
-                       IBrowserLayoutListener listener = listeners.get(i);
-                       switch (event.getEventType()) {
-                       case COMPLETED:
-                               listener.completed();
-                               break;
-                       case SIZE_CHANGED:
-                               listener.sizeChanged(event.getParam1(), event.getParam2());
-                               break;
-                       case SCROLLAREA_CHANGED:
-                               listener.scrollAreaChanged(event.getParam1(), event.getParam2());
-                               break;
-                       case SCROLLED:
-                               listener.scrolled(event.getParam1());
-                               break;
-                       default:
-                               assert (false);
-                       }
-               }
-       }
-
-       @Override
-       protected void createDefaultRoot() {
-               setRootEditPart(new HoverViewerRootEditPart());
-       }
-
-       public IEditorInput getEditorInput() {
-               return editorInput;
-       }
-
-       private ImageBufferedBrowserProvider createBrowser(Composite parent) {
-               ImageBufferedBrowserProvider webBrowser = new ImageBufferedBrowserProvider(
-                               parent.getDisplay(), this);
-               zoomScale = 1.0f;
-               webBrowser.getBrowser().addProgressListener(new ProgressListener() {
-                       @Override
-                       public void loadFinished(boolean ok) {
-                               HoverBrowserViewer.this.completed();
-                       }
-
-                       @Override
-                       public void updateImage() {
-                               browserScrolled();
-                       }
-               });
-
-               initTempHtml();
-
-               return webBrowser;
-       }
-
-       protected void initTempHtml() {
-               // String tempFilePath = appManager
-               // .getFileFullPath("tizen-ui-builder-tool/" + TEMP_FILE);
-               // tempHtml = FileIo.readFile(tempFilePath);
-               // if (tempHtml != null) {
-               // String toolPathUri =
-               // ResourceManager.getFileURL(BuilderPlugin.PLUGIN_ID, null).toString();
-
-               Path path2 = new Path(editorInput.getToolTipText());
-               IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path2);
-               URI pagePath = file.getParent().getLocationURI();
-               pagePathUri = (pagePath != null) ? pagePath.toString() : "";
-
-               file = (IFile) editorInput.getAdapter(IFile.class);
-               if (file != null) {
-                       IProject project = file.getProject();
-                       rootPathUri = project.getLocationURI().toString();
-               }
-               //
-               // tempHtml = tempHtml.replace("%tool_path%", toolPathUri);
-               // tempHtml = tempHtml.replace("%root_path%", rootPathUri);
-               // tempHtml = tempHtml.replace("%page_path%", pagePathUri);
-               // tempHtml = tempHtml.replace("%page_name%", pageData.getName());
-               // tempHtml = tempHtml.replace("%page_css_path%", rootPathUri + "/" +
-               // pageData.getCssPath());
-               //
-               // isValidTempHtml = true;
-               // } else {
-               tempHtml = "<html><body>None</body></html>";
-               isValidTempHtml = false;
-               // }
-       }
-
-       public void initLayout() {
-               int index = appManager.getPageIndex(pageData);
-
-               tempHtml = appManager.getEditHtml(index, rootPathUri, pagePathUri);
-
-               webBrowser.getBrowser().setHtml(tempHtml, pagePathUri);
-       }
-
-       public void showTooltipText(int x, int y, String text) {
-               if (tooltip == null) {
-                       tooltip = new ToolTip(getControl().getShell(), SWT.BALLOON);
-
-                       getControl().addFocusListener(new FocusListener() {
-                               @Override
-                               public void focusLost(FocusEvent e) {
-                                       tooltip.setVisible(false);
-                               }
-
-                               @Override
-                               public void focusGained(FocusEvent e) {
-                                       // Do nothing
-                               }
-                       });
-               }
-
-               tooltip.setVisible(false);
-               // tooltip.setAutoHide(true);
-               tooltip.setMessage(text);
-               // Point location = getControl().toDisplay(getControl().getSize().x,
-               // getControl().getSize().y);
-               Point location = getControl().toDisplay(getControl().getBounds().x,
-                               getControl().getBounds().y);
-
-               // tooltip.setLocation(location.x - getControl().getSize().x +
-               // getControl().getBorderWidth(), location.y -
-               // getControl().getBorderWidth());
-               x = location.x + (int) (x * zoomScale);
-               y = location.y + (int) (y * zoomScale);
-               tooltip.setLocation(x, y);
-               tooltip.setVisible(true);
-       }
-
-       public void hideTooltipText() {
-               if (tooltip != null) {
-                       tooltip.setVisible(false);
-               }
-       }
-
-       // public Point getTotalSize() {
-       // return layout.getTotalSize();
-       // }
-
-       // public int getClientHeight() {
-       // return webBrowser.getClientHeight(zoomScale);
-       // }
-
-       protected void addDropTargetListener() {
-
-       }
-
-       @Override
-       public void completed() {
-               rootEditPart = (HoverViewerRootEditPart) getRootEditPart();
-               rootEditPart.getBrowserScrollBar().addPropertyChangeListener(
-                               new PropertyChangeListener() {
-
-                                       @Override
-                                       public void propertyChange(PropertyChangeEvent event) {
-                                               if (RangeModel.PROPERTY_VALUE.equals(event
-                                                               .getPropertyName())) {
-                                                       if (event.getNewValue() instanceof Integer) {
-                                                               setScrollPos(((Integer) event.getNewValue())
-                                                                               .intValue());
-                                                               // setScrollPos((int)event.getNewValue);
-                                                       }
-                                               }
-
-                                       }
-                               });
-               goingBridge = new DesignerGoingBridge(webBrowser.getBrowser());
-               setBasePath();
-               resizeBrowser();
-               updateModel();
-               updateStyle();
-               rootEditPart.refresh();
-
-               scrollToCenter();
-       }
-
-       private void setBasePath() {
-               Path path = new Path(editorInput.getToolTipText());
-               IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
-               if (file != null) {
-                       goingBridge.setBasePath(file.getParent().getLocation().toString());
-               }
-       }
-
-       public void setScrollPos(int scrollPos) {
-               if (this.scrollPos != scrollPos) {
-                       this.scrollPos = scrollPos;
-                       fireEvent(new BrowserLayoutEvent(
-                                       BrowserLayoutEvent.EventType.SCROLLED, scrollPos, 0));
-                       goingBridge.scrollTo(-scrollPos);
-                       browserScrolled();
-               }
-       }
-
-       // public ProjectManager getProjectManager() {
-       // return projectManager;
-       // }
-
-       public DescriptorManager getDescriptorManager() {
-               if (appManager != null) {
-                       return appManager.getDescriptorManager();
-               }
-
-               return null;
-       }
-
-       public AppManager getAppManager() {
-               return appManager;
-       }
-
-       public PageData getPageData() {
-               return pageData;
-       }
-
-       public ImageBufferedBrowserProvider getWebBrowser() {
-               return webBrowser;
-       }
-
-       public int getScrollPos() {
-               return scrollPos;
-       }
-
-       public void updateStyle() {
-               int scrollpos = getScrollPos();
-
-               String style = generateCssCode();
-               // String style =
-               // CodeGenerator.generateCssCode(pageData.getCurrentCssFile());
-               setCssStyle(style);
-
-               if (getGoingBridge() != null) {
-                       // max = browserViewer.getBrowser().getContentsSize().y;
-                       WidgetPosition pos = getGoingBridge().getClientBound();
-                       int max = (pos != null) ? pos.height : 0;
-                       pos = getGoingBridge().getWindowBound();
-                       int thumb = (pos != null) ? pos.height : 0;
-                       // int thumb = getClientHeight();
-                       // scrollBar.setScrollSize(max, thumb, false);
-                       fireEvent(new BrowserLayoutEvent(
-                                       BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max, thumb));
-                       if (thumb >= max) {
-                               getGoingBridge().scrollTo(0);
-                       } else {
-                               getGoingBridge().scrollTo(-scrollpos);
-                       }
-                       if (rootPart != null) {
-                               AbsolutePositionProvider provider = rootPart
-                                               .getAbsolutePositionProvider();
-                               if (provider != null) {
-                                       provider.setBasePositionY((pos != null) ? pos.y : 0);
-                                       provider.setScrollSize(scrollpos);
-                               }
-                       }
-               }
-               // scrollBar.setScrollSize(max, thumb);
-               // scrollBar.updateScroll();
-               if (webBrowser != null) {
-                       webBrowser.updateSizeEditings();
-               }
-               updateWidgetPosition();
-       }
-
-       public void updateModel() {
-               int scrollpos = getScrollPos();
-
-               if (getCurrentPage() != null) {
-                       // pageData.syncStyleToData();
-                       // String page = getCurrentPage().getCode(true);
-                       String page = CodeGenerator.generateCode((Part) getCurrentPage()
-                                       .getModel(), true, appManager.getDescriptorManager()
-                                       .getXsltDocument(), false);
-                       page = page.replace("\\", "\\\\");
-                       webBrowser.changeBody(page);
-               }
-               if (getGoingBridge() != null) {
-                       // max = browserViewer.getBrowser().getContentsSize().y;
-                       WidgetPosition pos = getGoingBridge().getClientBound();
-                       int max = (pos != null) ? pos.height : 0;
-                       pos = getGoingBridge().getWindowBound();
-                       int thumb = (pos != null) ? pos.height : 0;
-                       // int thumb = getClientHeight();
-                       // scrollBar.setScrollSize(max, thumb, false);
-                       fireEvent(new BrowserLayoutEvent(
-                                       BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max, thumb));
-                       if (thumb >= max) {
-                               getGoingBridge().scrollTo(0);
-                       } else {
-                               getGoingBridge().scrollTo(-scrollpos);
-                       }
-                       if (rootPart != null) {
-                               AbsolutePositionProvider provider = rootPart
-                                               .getAbsolutePositionProvider();
-                               if (provider != null) {
-                                       provider.setBasePositionY((pos != null) ? pos.y : 0);
-                                       provider.setScrollSize(scrollpos);
-                               }
-                       }
-               }
-               // scrollBar.setScrollSize(max, thumb);
-               // scrollBar.updateScroll();
-               webBrowser.updateSizeEditings();
-               updateWidgetPosition();
-       }
-
-       public HoverViewerEditPart getCurrentPage() {
-               if (rootEditPart == null || rootEditPart.getContents() == null) {
-                       return null;
-               }
-
-               // @SuppressWarnings("unchecked")
-               // List<EditPart> children = rootEditPart.getContents().getChildren();
-               // if (currentPage >= children.size()) {
-               // currentPage = children.size() - 1;
-               // } else if (currentPage < 0) {
-               // return null;
-               // }
-               // return (HoverViewerEditPart) children.get(currentPage);
-
-               return (HoverViewerEditPart) currentPageEditPart;
-       }
-
-       @Override
-       public void updateArea() {
-               if (getGoingBridge() != null) {
-                       // max = browserViewer.getBrowser().getContentsSize().y;
-                       WidgetPosition pos = getGoingBridge().getClientBound();
-                       int max = (pos != null) ? pos.height : 0;
-                       pos = getGoingBridge().getWindowBound();
-                       int thumb = (pos != null) ? pos.height : 0;
-                       // int thumb = getClientHeight();
-                       // scrollBar.setScrollSize(max, thumb, false);
-                       fireEvent(new BrowserLayoutEvent(
-                                       BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max, thumb));
-               }
-               // scrollBar.setScrollSize(max, thumb);
-               // scrollBar.updateScroll();
-       }
-
-       protected void addEventListener(EditPartViewer designEditPartViewer) {
-               HoverBrowserEventDelegator delegator = new HoverBrowserEventDelegator(
-                               designEditPartViewer);
-               getControl().addMouseMoveListener(delegator);
-               getControl().addMouseListener(delegator);
-               getControl().addKeyListener(delegator);
-               getControl().addKeyListener(new KeyAdapter() {
-                       @Override
-                       public void keyPressed(KeyEvent e) {
-                               if (e.keyCode == SWT.ESC) {
-                                       @SuppressWarnings("unchecked")
-                                       List<EditPart> eps = getSelectedEditParts();
-                                       for (EditPart ep : eps) {
-                                               if (ep instanceof HoverViewerEditPart) {
-                                                       EditPart parent = ep.getParent();
-                                                       if (parent != null && parent.getModel() != null) {
-                                                               HoverBrowserViewer.this.select(parent);
-                                                               break;
-                                                       }
-                                               }
-                                       }
-                               }
-                       }
-               });
-       }
-
-       public void setShowingSize(int width, int height) {
-               originalSize = new Point(width, height);
-               resizeBrowser();
-               webBrowser.updateSizeEditings();
-       }
-
-       public Point getShowingSize() {
-               return originalSize;
-       }
-
-       private void setCssStyle(String cssStyle) {
-               // Logger.trace("setCssStyle : " + cssStyle.substring(0, 40));
-               goingBridge.setCssStyle(cssStyle);
-       }
-
-       public ImageBufferedBrowserProvider getBrowser() {
-               return webBrowser;
-       }
-
-       public DesignerGoingBridge getGoingBridge() {
-               return goingBridge;
-       }
-
-       public void setLandscape(boolean landscape) {
-               if (landscape != this.landscape) {
-                       this.landscape = landscape;
-                       resizeBrowser();
-                       scrollToCenter();
-                       webBrowser.updateSizeEditings();
-               }
-       }
-
-       public void zoomBrowser(float scale) {
-               if (rootEditPart != null) {
-                       updateScrollBar();
-                       rootEditPart.getZoomManager().setZoom(scale);
-                       rootEditPart.updateBrowserSize();
-               }
-
-               this.zoomScale = scale;
-               // if (layout != null) {
-               // layout.zoomMargin(scale);
-               // }
-               resizeBrowser();
-               webBrowser.updateSizeEditings();
-       }
-
-       public void setViewLocation(int x, int y) {
-               if (rootEditPart != null) {
-                       rootEditPart.getZoomManager().setViewLocation(
-                                       new org.eclipse.draw2d.geometry.Point(x, y));
-               }
-       }
-
-       public Point getViewLocation() {
-               if (rootEditPart != null) {
-                       org.eclipse.draw2d.geometry.Point p;
-                       p = rootEditPart.getZoomManager().getViewport().getViewLocation();
-                       return new Point(p.x, p.y);
-               }
-               return new Point(0, 0);
-       }
-
-       private void resizeBrowser() {
-               Point usingSize;
-
-               if (landscape) {
-                       usingSize = new Point(originalSize.y, originalSize.x);
-               } else {
-                       usingSize = originalSize;
-               }
-               Point size = new Point((int) (usingSize.x * zoomScale),
-                               (int) (usingSize.y * zoomScale));
-
-               webBrowser.getBrowser().setZoomScale(zoomScale);
-
-               org.tizen.webuibuilder.browserwidget.Point browserSize = webBrowser
-                               .getBrowser().getBrowserSize();
-               if (browserSize.x != usingSize.x || browserSize.y != usingSize.y) {
-                       webBrowser.setBrowserSize(usingSize.x, usingSize.y);
-                       updateWidgetPosition();
-
-               }
-
-               // webBrowser.setSize(size);
-
-               // if (scrollBar != null) {
-               if (getGoingBridge() != null) {
-                       // max = browserViewer.getBrowser().getContentsSize().y;
-                       WidgetPosition pos = getGoingBridge().getClientBound();
-                       int max = (pos != null) ? pos.height : 0;
-                       pos = getGoingBridge().getWindowBound();
-                       // int thumb = getClientHeight();
-                       int thumb = (pos != null) ? pos.height : 0;
-                       // scrollBar.setScrollSize(max, thumb, false);
-                       fireEvent(new BrowserLayoutEvent(
-                                       BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max, thumb));
-               }
-               // }
-               // layoutComposite.layout();
-               // if (scrollBar != null) {
-               // scrollBar.updateScroll();
-               // }
-               //
-               // layoutComposite.redraw();
-               // webBrowser.redraw();
-
-               fireEvent(new BrowserLayoutEvent(
-                               BrowserLayoutEvent.EventType.SIZE_CHANGED, size.x, size.y));
-       }
-
-       public void updateAllPositionsForce() {
-               webBrowser.updateSizeEditings();
-               updateWidgetPosition();
-       }
-
-       private void browserScrolled() {
-               if (rootPart != null) {
-                       AbsolutePositionProvider provider = rootPart
-                                       .getAbsolutePositionProvider();
-                       if (provider != null) {
-                               provider.setScrollSize(getScrollPos());
-                       }
-               }
-               updateAllPositionsForce();
-       }
-
-       // public IProject getProject() {
-       // return project;
-       // }
-
-       protected void updateOneWidgetPosition(Part part,
-                       Map<String, WidgetPosition> widgetPositions, boolean isFireEvent) {
-               if (part != null) {
-                       if (part.getPartId() != null && !part.getPartId().isEmpty()) {
-                               WidgetPosition pos = widgetPositions.get(part.getPartId());
-                               if (pos != null) {
-                                       if (isFireEvent) {
-                                               part.setVisualPosition(pos);
-                                       } else {
-                                               part.setVisualPosition(pos);
-                                       }
-                               }
-                       }
-
-                       for (Part part2 : part.getChildren()) {
-                               updateOneWidgetPosition(part2, widgetPositions, isFireEvent);
-                       }
-               }
-       }
-
-       public void updateWidgetPosition() {
-               Map<String, WidgetPosition> widgetPositions = webBrowser
-                               .getWidgetPositions();
-               if (widgetPositions != null) {
-                       updateScrollBar();
-                       if (rootPart != null) {
-                               updateOneWidgetPosition(rootPart, widgetPositions, true);
-                               rootPart.updateRelativePosition();
-                               // getRootEditPart().refresh();
-                               // rootPart.fireEvent(new
-                               // PartEvent(PartEvent.EventType.POSITION_CHANGED, rootPart,
-                               // null,
-                               // null));
-                       }
-               }
-       }
-
-       private EditPart getFirstPageEditPart() {
-               EditPart doc = getRootEditPart().getContents();
-               @SuppressWarnings("unchecked")
-               List<EditPart> pages = doc.getChildren();
-               if (pages.size() > 0) {
-                       return pages.get(0);
-               } else {
-                       return null;
-               }
-       }
-
-       private EditPart getPageEditPart(EditPart editPart) {
-               EditPart pageEditPart = null;
-
-               while (editPart != null) {
-                       Object model = editPart.getModel();
-                       if (model instanceof Part) {
-                               if (((Part) model).getDescriptorId().equals("tizen.page")) {
-                                       pageEditPart = editPart;
-                                       break;
-                               }
-                       }
-                       editPart = editPart.getParent();
-               }
-
-               return pageEditPart;
-       }
-
-       private void DeactivateAllPages() {
-               EditPart doc = getRootEditPart().getContents();
-               List<EditPart> pages = doc.getChildren();
-               for (EditPart page : pages) {
-                       page.deactivate();
-               }
-       }
-
-       private void HideAllPages() {
-               EditPart doc = getRootEditPart().getContents();
-               List<EditPart> pages = doc.getChildren();
-               for (EditPart page : pages) {
-                       ((HoverViewerEditPart) page).getFigure().setVisible(false);
-               }
-       }
-
-       @Override
-       public void setSelection(ISelection newSelection) {
-               EditPart firstSelEditPart = null;
-
-               EditPart rootEditPart = this.getRootEditPart();
-               Iterator<Object> iterator = ((IStructuredSelection) newSelection)
-                               .iterator();
-               while (iterator.hasNext()) {
-                       EditPart editPart = (EditPart) iterator.next();
-                       if (firstSelEditPart == null) {
-                               firstSelEditPart = editPart;
-                               break;
-                       }
-               }
-
-               if (firstSelEditPart != null) {
-                       PageData pageData2 = appManager
-                                       .findPageData((Part) firstSelEditPart.getModel());
-                       if (pageData2 != null && pageData2 != pageData) {
-                               pageData = pageData2;
-
-                               EditPart pageEditPart = getPageEditPart(firstSelEditPart);
-                               currentPageEditPart = pageEditPart;
-
-                               HideAllPages();
-                               ((HoverViewerEditPart) currentPageEditPart).getFigure()
-                                               .setVisible(true);
-                               // DeactivateAllPages();
-                               // currentPageEditPart.activate();
-
-                               updateModel();
-                       }
-               }
-
-               super.setSelection(newSelection);
-
-               IStructuredSelection selection = (IStructuredSelection) newSelection;
-               if (selection.size() > 0) {
-                       EditPart editpart = (EditPart) selection.toList().get(
-                                       selection.size() - 1);
-                       Part part = (Part) editpart.getModel();
-               }
-       }
-
-       @Override
-       public void selectionChanged(SelectionChangedEvent event) {
-               List<?> oldSelection = ((IStructuredSelection) event.getSelection())
-                               .toList();
-               final List<Object> newSelection = new ArrayList<Object>(
-                               oldSelection.size());
-               newSelection.addAll(oldSelection);
-
-               EditPart firstSelEditPart = null;
-
-               EditPart rootEditPart = this.getRootEditPart();
-               Iterator<Object> iterator = newSelection.iterator();
-               while (iterator.hasNext()) {
-                       EditPart editPart = (EditPart) iterator.next();
-                       if (firstSelEditPart == null) {
-                               firstSelEditPart = editPart;
-                       }
-
-                       while (editPart != null && editPart != rootEditPart) {
-                               editPart = editPart.getParent();
-                               if (newSelection.contains(editPart)) {
-                                       iterator.remove();
-                                       break;
-                               }
-                       }
-               }
-
-               if (newSelection.size() < oldSelection.size()) {
-                       this.getControl().getDisplay().asyncExec(new Runnable() {
-                               @Override
-                               public void run() {
-                                       setSelection(new StructuredSelection(newSelection));
-                               }
-                       });
-               }
-
-               // if(firstSelEditPart != null){
-               // PageData pageData2 =
-               // appManager.findPageData((Part)firstSelEditPart.getModel());
-               // if(pageData != pageData2){
-               // pageData = pageData2;
-               //
-               // EditPart pageEditPart = getPageEditPart(firstSelEditPart);
-               // currentPageEditPart = pageEditPart;
-               //
-               // HideAllPages();
-               // ((HoverViewerEditPart)currentPageEditPart).getFigure().setVisible(true);
-               //
-               // updateModel();
-               // }
-               // }
-       }
-
-       public void scrollToCenter() {
-               Composite composite = getControl().getParent();
-               if (composite instanceof HoverBrowserRulerComposite) {
-                       Rectangle editor = ((HoverBrowserRulerComposite) composite)
-                                       .getEditorBounds();
-                       float zoom = getZoomScale();
-                       int x = 0, y = 0;
-                       org.tizen.webuibuilder.browserwidget.Point browser = getBrowser()
-                                       .getBrowser().getBrowserSize();
-
-                       if (editor.width > zoom * browser.x) {
-                               x = (int) ((zoom * browser.x - editor.width) / 2);
-                       }
-                       if (editor.height > zoom * browser.y) {
-                               y = (int) ((zoom * browser.y - editor.height) / 2);
-                       }
-
-                       setViewLocation(x, y);
-               }
-       }
-
-       private void updateScrollBar() {
-               if (rootEditPart != null) {
-                       rootEditPart.updateScrollBar();
-                       rootEditPart.getFigure().repaint();
-               }
-       }
-
-       @Override
-       public void childAdded(PartEvent e) {
-               updateStyle();
-       }
-
-       @Override
-       public void childMoved(PartEvent e) {
-               updateStyle();
-       }
-
-       @Override
-       public void childRemoved(PartEvent e) {
-               updateStyle();
-       }
-
-       @Override
-       public void propertyChanged(PartEvent e) {
-       }
-
-       @Override
-       public void positionChanged(PartEvent e) {
-       }
-
-       @Override
-       public void eventChanged(PartEvent e) {
-               // TODO Auto-generated method stub
-
-       }
-
-       @Override
-       public void visualPositionChanged(PartEvent e) {
-               // TODO Auto-generated method stub
-
-       }
-
-       @Override
-       public void needRefresh(PartEvent e) {
-               updateStyle();
-
-       }
-
-       @Override
-       public void cssPropertyChanged(CssEvent event) {
-               updateStyle();
-       }
-
-       @Override
-       public void cssSelectorAdded(CssEvent event) {
-               updateStyle();
-       }
-
-       @Override
-       public void cssSelectorRemoved(CssEvent event) {
-               updateStyle();
-       }
-
-       @Override
-       public void needRefresh(CssEvent event) {
-               // TODO Auto-generated method stub
-               // updateStyle();
-       }
-
-       public float getZoomScale() {
-               return zoomScale;
-       }
-
-       public boolean isLandScape() {
-               return landscape;
-       }
-
-       protected String generateCssCode() {
-               return CodeGenerator.generateCssCode(rootPart);
-       }
-
-       @Override
-       public void reveal(EditPart part) {
-               super.reveal(part);
-       }
-
-       @Override
-       public void sizeChanged(int width, int height) {
-               RootEditPart rootEditPart = getRootEditPart();
-               if (rootEditPart instanceof HoverViewerRootEditPart) {
-                       org.tizen.webuibuilder.browserwidget.Point browserSize = webBrowser
-                                       .getBrowser().getBrowserSize();
-                       ((HoverViewerRootEditPart) rootEditPart).updateBrowserSize(
-                                       browserSize.x, browserSize.y);
-               }
-       }
-
-       @Override
-       public void scrollAreaChanged(int max, int thumb) {
-               if (rootEditPart != null) {
-                       // rootEditPart.getBrowserScrollBar().setMaximum(max);
-               }
-
-       }
-
-       @Override
-       public void scrolled(int scrollPos) {
-               // TODO Auto-generated method stub
-
-       }
+/* GraphicalViewerImpl */implements ISelectionChangedListener, ContentsAreaChangedListener,
+        IPartListener, ICssListener, IBrowserLayoutListener {
+
+    // private String TEMP_FILE = "res/html/ground.html";
+
+    private DesignerGoingBridge goingBridge;
+    // private int currentPage = 0;
+    private EditPart currentPageEditPart = null;
+    private HoverViewerRootEditPart rootEditPart;
+    protected ImageBufferedBrowserProvider webBrowser;
+    protected PageData pageData;
+    private Part rootPart;
+    private int scrollPos = 0;
+    protected String theme;
+    protected String scale;
+    private Point originalSize;
+    private float zoomScale;
+    private boolean landscape;
+    protected IEditorInput editorInput;
+    private ToolTip tooltip;
+    // private IProject project;
+    protected AppManager appManager;
+
+    protected boolean isValidTempHtml = false;
+    protected String tempHtml = null;
+    protected String rootPathUri = null;
+    protected String pagePathUri = null;
+
+    private List<IBrowserLayoutListener> listeners = new LinkedList<IBrowserLayoutListener>();
+
+    public HoverBrowserViewer(AppManager appManager, /* PageData pageData, */
+            ScreenSize screen, IEditorInput editorInput) {
+        // this.pageData = pageData;
+        originalSize = new Point(screen.getWidth(), screen.getHeight());
+        this.appManager = appManager;
+        this.pageData = appManager.getPageData(0);
+        this.theme = appManager.getFrameworkTheme();
+        this.scale = appManager.getFrameworkScale();
+        this.editorInput = editorInput;
+
+        addSelectionChangedListener(this);
+        addBrowserLayoutListener(this);
+    }
+
+    @Override
+    public void setContents(Object contents) {
+        super.setContents(contents);
+
+        rootPart = (Part) contents; // pageData.getRootPart();
+        rootPart.addPartListener(this, true);
+        rootPart.addCssListener(this, true);
+
+        currentPageEditPart = getFirstPageEditPart();
+    }
+
+    @Override
+    protected void handleDispose(DisposeEvent e) {
+        rootPart.removePartListener(this);
+        rootPart.removeCssListener(this);
+        super.handleDispose(e);
+    }
+
+    @Override
+    public void setControl(Control control) {
+        super.setControl(control);
+
+        if (control != null) {
+            getFigureCanvas().setHorizontalScrollBarVisibility(FigureCanvas.AUTOMATIC);
+            getFigureCanvas().setVerticalScrollBarVisibility(FigureCanvas.AUTOMATIC);
+
+            webBrowser = createBrowser(control.getParent());
+            initLayout();
+            resizeBrowser();
+
+            addEventListener(this);
+            addDropTargetListener();
+        }
+    }
+
+    // @Override
+    public Control createControl2(Composite parent) {
+        return null;
+    }
+
+    /**
+     * Adds a part listener.
+     * 
+     * @param listener
+     *            a part listener
+     * @param includeBubbleEvents
+     *            whether bubble listener is used.
+     */
+    public void addBrowserLayoutListener(IBrowserLayoutListener listener) {
+        listeners.add(listener);
+    }
+
+    /**
+     * Removes a part listener.
+     * 
+     * @param listener
+     *            a part listener
+     */
+    public void removeBrowserLayoutListener(IBrowserLayoutListener listener) {
+        listeners.remove(listener);
+    }
+
+    /**
+     * Fires a css event.
+     * 
+     * @param event
+     *            a css event
+     * @param listeners
+     *            a List containing css listener
+     */
+    private void fireEvent(BrowserLayoutEvent event) {
+        if (event == null || listeners == null) {
+            return;
+        }
+
+        int size = listeners.size();
+        for (int i = 0; i < size; i++) {
+            IBrowserLayoutListener listener = listeners.get(i);
+            switch (event.getEventType()) {
+                case COMPLETED:
+                    listener.completed();
+                    break;
+                case SIZE_CHANGED:
+                    listener.sizeChanged(event.getParam1(), event.getParam2());
+                    break;
+                case SCROLLAREA_CHANGED:
+                    listener.scrollAreaChanged(event.getParam1(), event.getParam2());
+                    break;
+                case SCROLLED:
+                    listener.scrolled(event.getParam1());
+                    break;
+                default:
+                    assert (false);
+            }
+        }
+    }
+
+    @Override
+    protected void createDefaultRoot() {
+        setRootEditPart(new HoverViewerRootEditPart());
+    }
+
+    public IEditorInput getEditorInput() {
+        return editorInput;
+    }
+
+    private ImageBufferedBrowserProvider createBrowser(Composite parent) {
+        ImageBufferedBrowserProvider webBrowser =
+                new ImageBufferedBrowserProvider(parent.getDisplay(), this);
+        zoomScale = 1.0f;
+        webBrowser.getBrowser().addProgressListener(new ProgressListener() {
+            @Override
+            public void loadFinished(boolean ok) {
+                HoverBrowserViewer.this.completed();
+            }
+
+            @Override
+            public void updateImage() {
+                browserScrolled();
+            }
+        });
+
+        initTempHtml();
+
+        return webBrowser;
+    }
+
+    protected void initTempHtml() {
+        // String tempFilePath = appManager
+        // .getFileFullPath("tizen-ui-builder-tool/" + TEMP_FILE);
+        // tempHtml = FileIo.readFile(tempFilePath);
+        // if (tempHtml != null) {
+        // String toolPathUri =
+        // ResourceManager.getFileURL(BuilderPlugin.PLUGIN_ID, null).toString();
+
+        Path path2 = new Path(editorInput.getToolTipText());
+        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path2);
+        URI pagePath = file.getParent().getLocationURI();
+        pagePathUri = (pagePath != null) ? pagePath.toString() : "";
+
+        file = (IFile) editorInput.getAdapter(IFile.class);
+        if (file != null) {
+            IProject project = file.getProject();
+            rootPathUri = project.getLocationURI().toString();
+        }
+        //
+        // tempHtml = tempHtml.replace("%tool_path%", toolPathUri);
+        // tempHtml = tempHtml.replace("%root_path%", rootPathUri);
+        // tempHtml = tempHtml.replace("%page_path%", pagePathUri);
+        // tempHtml = tempHtml.replace("%page_name%", pageData.getName());
+        // tempHtml = tempHtml.replace("%page_css_path%", rootPathUri + "/" +
+        // pageData.getCssPath());
+        //
+        // isValidTempHtml = true;
+        // } else {
+        tempHtml = "<html><body>None</body></html>";
+        isValidTempHtml = false;
+        // }
+    }
+
+    public void initLayout() {
+        int index = appManager.getPageIndex(pageData);
+
+        tempHtml = appManager.getEditHtml(index, rootPathUri, pagePathUri);
+
+        webBrowser.getBrowser().setHtml(tempHtml, pagePathUri);
+    }
+
+    public void showTooltipText(int x, int y, String text) {
+        if (tooltip == null) {
+            tooltip = new ToolTip(getControl().getShell(), SWT.BALLOON);
+
+            getControl().addFocusListener(new FocusListener() {
+                @Override
+                public void focusLost(FocusEvent e) {
+                    tooltip.setVisible(false);
+                }
+
+                @Override
+                public void focusGained(FocusEvent e) {
+                    // Do nothing
+                }
+            });
+        }
+
+        tooltip.setVisible(false);
+        // tooltip.setAutoHide(true);
+        tooltip.setMessage(text);
+        // Point location = getControl().toDisplay(getControl().getSize().x,
+        // getControl().getSize().y);
+        Point location =
+                getControl().toDisplay(getControl().getBounds().x, getControl().getBounds().y);
+
+        // tooltip.setLocation(location.x - getControl().getSize().x +
+        // getControl().getBorderWidth(), location.y -
+        // getControl().getBorderWidth());
+        x = location.x + (int) (x * zoomScale);
+        y = location.y + (int) (y * zoomScale);
+        tooltip.setLocation(x, y);
+        tooltip.setVisible(true);
+    }
+
+    public void hideTooltipText() {
+        if (tooltip != null) {
+            tooltip.setVisible(false);
+        }
+    }
+
+    // public Point getTotalSize() {
+    // return layout.getTotalSize();
+    // }
+
+    // public int getClientHeight() {
+    // return webBrowser.getClientHeight(zoomScale);
+    // }
+
+    protected void addDropTargetListener() {
+
+    }
+
+    @Override
+    public void completed() {
+        rootEditPart = (HoverViewerRootEditPart) getRootEditPart();
+        rootEditPart.getBrowserScrollBar().addPropertyChangeListener(new PropertyChangeListener() {
+
+            @Override
+            public void propertyChange(PropertyChangeEvent event) {
+                if (RangeModel.PROPERTY_VALUE.equals(event.getPropertyName())) {
+                    if (event.getNewValue() instanceof Integer) {
+                        setScrollPos(((Integer) event.getNewValue()).intValue());
+                        // setScrollPos((int)event.getNewValue);
+                    }
+                }
+
+            }
+        });
+        goingBridge = new DesignerGoingBridge(webBrowser.getBrowser());
+        setBasePath();
+        resizeBrowser();
+        updateModel();
+        updateStyle();
+        rootEditPart.refresh();
+
+        scrollToCenter();
+    }
+
+    private void setBasePath() {
+        Path path = new Path(editorInput.getToolTipText());
+        IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
+        if (file != null) {
+            goingBridge.setBasePath(file.getParent().getLocation().toString());
+        }
+    }
+
+    public void setScrollPos(int scrollPos) {
+        if (this.scrollPos != scrollPos) {
+            this.scrollPos = scrollPos;
+            fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SCROLLED, scrollPos, 0));
+            goingBridge.scrollTo(-scrollPos);
+            browserScrolled();
+        }
+    }
+
+    // public ProjectManager getProjectManager() {
+    // return projectManager;
+    // }
+
+    public DescriptorManager getDescriptorManager() {
+        if (appManager != null) {
+            return appManager.getDescriptorManager();
+        }
+
+        return null;
+    }
+
+    public AppManager getAppManager() {
+        return appManager;
+    }
+
+    public PageData getPageData() {
+        return pageData;
+    }
+
+    public ImageBufferedBrowserProvider getWebBrowser() {
+        return webBrowser;
+    }
+
+    public int getScrollPos() {
+        return scrollPos;
+    }
+
+    public void updateStyle() {
+        int scrollpos = getScrollPos();
+
+        String style = generateCssCode();
+        // String style =
+        // CodeGenerator.generateCssCode(pageData.getCurrentCssFile());
+        setCssStyle(style);
+
+        if (getGoingBridge() != null) {
+            // max = browserViewer.getBrowser().getContentsSize().y;
+            WidgetPosition pos = getGoingBridge().getClientBound();
+            int max = (pos != null) ? pos.height : 0;
+            pos = getGoingBridge().getWindowBound();
+            int thumb = (pos != null) ? pos.height : 0;
+            // int thumb = getClientHeight();
+            // scrollBar.setScrollSize(max, thumb, false);
+            fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max,
+                                             thumb));
+            if (thumb >= max) {
+                getGoingBridge().scrollTo(0);
+            } else {
+                getGoingBridge().scrollTo(-scrollpos);
+            }
+            if (rootPart != null) {
+                AbsolutePositionProvider provider = rootPart.getAbsolutePositionProvider();
+                if (provider != null) {
+                    provider.setBasePositionY((pos != null) ? pos.y : 0);
+                    provider.setScrollSize(scrollpos);
+                }
+            }
+        }
+        // scrollBar.setScrollSize(max, thumb);
+        // scrollBar.updateScroll();
+        if (webBrowser != null) {
+            webBrowser.updateSizeEditings();
+        }
+        updateWidgetPosition();
+    }
+
+    public void updateModel() {
+        int scrollpos = getScrollPos();
+
+        if (getCurrentPage() != null) {
+            // pageData.syncStyleToData();
+            // String page = getCurrentPage().getCode(true);
+            String page =
+                    CodeGenerator.generateCode((Part) getCurrentPage().getModel(), true, appManager
+                            .getDescriptorManager().getXsltDocument(), false);
+            page = page.replace("\\", "\\\\");
+            webBrowser.changeBody(page);
+        }
+        if (getGoingBridge() != null) {
+            // max = browserViewer.getBrowser().getContentsSize().y;
+            WidgetPosition pos = getGoingBridge().getClientBound();
+            int max = (pos != null) ? pos.height : 0;
+            pos = getGoingBridge().getWindowBound();
+            int thumb = (pos != null) ? pos.height : 0;
+            // int thumb = getClientHeight();
+            // scrollBar.setScrollSize(max, thumb, false);
+            fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max,
+                                             thumb));
+            if (thumb >= max) {
+                getGoingBridge().scrollTo(0);
+            } else {
+                getGoingBridge().scrollTo(-scrollpos);
+            }
+            if (rootPart != null) {
+                AbsolutePositionProvider provider = rootPart.getAbsolutePositionProvider();
+                if (provider != null) {
+                    provider.setBasePositionY((pos != null) ? pos.y : 0);
+                    provider.setScrollSize(scrollpos);
+                }
+            }
+        }
+        // scrollBar.setScrollSize(max, thumb);
+        // scrollBar.updateScroll();
+        webBrowser.updateSizeEditings();
+        updateWidgetPosition();
+    }
+
+    public HoverViewerEditPart getCurrentPage() {
+        if (rootEditPart == null || rootEditPart.getContents() == null) {
+            return null;
+        }
+
+        // @SuppressWarnings("unchecked")
+        // List<EditPart> children = rootEditPart.getContents().getChildren();
+        // if (currentPage >= children.size()) {
+        // currentPage = children.size() - 1;
+        // } else if (currentPage < 0) {
+        // return null;
+        // }
+        // return (HoverViewerEditPart) children.get(currentPage);
+
+        return (HoverViewerEditPart) currentPageEditPart;
+    }
+
+    @Override
+    public void updateArea() {
+        if (getGoingBridge() != null) {
+            // max = browserViewer.getBrowser().getContentsSize().y;
+            WidgetPosition pos = getGoingBridge().getClientBound();
+            int max = (pos != null) ? pos.height : 0;
+            pos = getGoingBridge().getWindowBound();
+            int thumb = (pos != null) ? pos.height : 0;
+            // int thumb = getClientHeight();
+            // scrollBar.setScrollSize(max, thumb, false);
+            fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max,
+                                             thumb));
+        }
+        // scrollBar.setScrollSize(max, thumb);
+        // scrollBar.updateScroll();
+    }
+
+    protected void addEventListener(EditPartViewer designEditPartViewer) {
+        HoverBrowserEventDelegator delegator = new HoverBrowserEventDelegator(designEditPartViewer);
+        getControl().addMouseMoveListener(delegator);
+        getControl().addMouseListener(delegator);
+        getControl().addKeyListener(delegator);
+        getControl().addKeyListener(new KeyAdapter() {
+            @Override
+            public void keyPressed(KeyEvent e) {
+                if (e.keyCode == SWT.ESC) {
+                    @SuppressWarnings("unchecked")
+                    List<EditPart> eps = getSelectedEditParts();
+                    for (EditPart ep : eps) {
+                        if (ep instanceof HoverViewerEditPart) {
+                            EditPart parent = ep.getParent();
+                            if (parent != null && parent.getModel() != null) {
+                                HoverBrowserViewer.this.select(parent);
+                                break;
+                            }
+                        }
+                    }
+                }
+            }
+        });
+    }
+
+    public void setShowingSize(int width, int height) {
+        originalSize = new Point(width, height);
+        resizeBrowser();
+        webBrowser.updateSizeEditings();
+    }
+
+    public Point getShowingSize() {
+        return originalSize;
+    }
+
+    private void setCssStyle(String cssStyle) {
+        // Logger.trace("setCssStyle : " + cssStyle.substring(0, 40));
+        goingBridge.setCssStyle(cssStyle);
+    }
+
+    public ImageBufferedBrowserProvider getBrowser() {
+        return webBrowser;
+    }
+
+    public DesignerGoingBridge getGoingBridge() {
+        return goingBridge;
+    }
+
+    public void setLandscape(boolean landscape) {
+        if (landscape != this.landscape) {
+            this.landscape = landscape;
+            resizeBrowser();
+            scrollToCenter();
+            webBrowser.updateSizeEditings();
+        }
+    }
+
+    public void zoomBrowser(float scale) {
+        if (rootEditPart != null) {
+            updateScrollBar();
+            rootEditPart.getZoomManager().setZoom(scale);
+            rootEditPart.updateBrowserSize();
+        }
+
+        this.zoomScale = scale;
+        // if (layout != null) {
+        // layout.zoomMargin(scale);
+        // }
+        resizeBrowser();
+        webBrowser.updateSizeEditings();
+    }
+
+    public void setViewLocation(int x, int y) {
+        if (rootEditPart != null) {
+            rootEditPart.getZoomManager().setViewLocation(new org.eclipse.draw2d.geometry.Point(x,
+                                                                                                y));
+        }
+    }
+
+    public Point getViewLocation() {
+        if (rootEditPart != null) {
+            org.eclipse.draw2d.geometry.Point p;
+            p = rootEditPart.getZoomManager().getViewport().getViewLocation();
+            return new Point(p.x, p.y);
+        }
+        return new Point(0, 0);
+    }
+
+    private void resizeBrowser() {
+        Point usingSize;
+
+        if (landscape) {
+            usingSize = new Point(originalSize.y, originalSize.x);
+        } else {
+            usingSize = originalSize;
+        }
+        Point size = new Point((int) (usingSize.x * zoomScale), (int) (usingSize.y * zoomScale));
+
+        webBrowser.getBrowser().setZoomScale(zoomScale);
+
+        org.tizen.webuibuilder.browserwidget.Point browserSize =
+                webBrowser.getBrowser().getBrowserSize();
+        if (browserSize.x != usingSize.x || browserSize.y != usingSize.y) {
+            webBrowser.setBrowserSize(usingSize.x, usingSize.y);
+            updateWidgetPosition();
+
+        }
+
+        // webBrowser.setSize(size);
+
+        // if (scrollBar != null) {
+        if (getGoingBridge() != null) {
+            // max = browserViewer.getBrowser().getContentsSize().y;
+            WidgetPosition pos = getGoingBridge().getClientBound();
+            int max = (pos != null) ? pos.height : 0;
+            pos = getGoingBridge().getWindowBound();
+            // int thumb = getClientHeight();
+            int thumb = (pos != null) ? pos.height : 0;
+            // scrollBar.setScrollSize(max, thumb, false);
+            fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SCROLLAREA_CHANGED, max,
+                                             thumb));
+        }
+        // }
+        // layoutComposite.layout();
+        // if (scrollBar != null) {
+        // scrollBar.updateScroll();
+        // }
+        //
+        // layoutComposite.redraw();
+        // webBrowser.redraw();
+
+        fireEvent(new BrowserLayoutEvent(BrowserLayoutEvent.EventType.SIZE_CHANGED, size.x, size.y));
+    }
+
+    public void updateAllPositionsForce() {
+        webBrowser.updateSizeEditings();
+        updateWidgetPosition();
+    }
+
+    private void browserScrolled() {
+        if (rootPart != null) {
+            AbsolutePositionProvider provider = rootPart.getAbsolutePositionProvider();
+            if (provider != null) {
+                provider.setScrollSize(getScrollPos());
+            }
+        }
+        updateAllPositionsForce();
+    }
+
+    // public IProject getProject() {
+    // return project;
+    // }
+
+    protected void updateOneWidgetPosition(Part part, Map<String, WidgetPosition> widgetPositions,
+                                           boolean isFireEvent) {
+        if (part != null) {
+            if (part.getPartId() != null && !part.getPartId().isEmpty()) {
+                WidgetPosition pos = widgetPositions.get(part.getPartId());
+                if (pos != null) {
+                    if (isFireEvent) {
+                        part.setVisualPosition(pos);
+                    } else {
+                        part.setVisualPosition(pos);
+                    }
+                }
+            }
+
+            for (Part part2 : part.getChildren()) {
+                updateOneWidgetPosition(part2, widgetPositions, isFireEvent);
+            }
+        }
+    }
+
+    public void updateWidgetPosition() {
+        if (webBrowser != null) {
+            Map<String, WidgetPosition> widgetPositions = webBrowser.getWidgetPositions();
+            if (widgetPositions != null) {
+                if (rootPart != null) {
+                    updateOneWidgetPosition(rootPart, widgetPositions, true);
+                    rootPart.updateRelativePosition();
+                    // getRootEditPart().refresh();
+                    // rootPart.fireEvent(new
+                    // PartEvent(PartEvent.EventType.POSITION_CHANGED, rootPart,
+                    // null,
+                    // null));
+                }
+            }
+        }
+        updateScrollBar();
+    }
+
+    private EditPart getFirstPageEditPart() {
+        EditPart doc = getRootEditPart().getContents();
+        @SuppressWarnings("unchecked")
+        List<EditPart> pages = doc.getChildren();
+        if (pages.size() > 0) {
+            return pages.get(0);
+        } else {
+            return null;
+        }
+    }
+
+    private EditPart getPageEditPart(EditPart editPart) {
+        EditPart pageEditPart = null;
+
+        while (editPart != null) {
+            Object model = editPart.getModel();
+            if (model instanceof Part) {
+                if (((Part) model).getDescriptorId().equals("tizen.page")) {
+                    pageEditPart = editPart;
+                    break;
+                }
+            }
+            editPart = editPart.getParent();
+        }
+
+        return pageEditPart;
+    }
+
+    private void DeactivateAllPages() {
+        EditPart doc = getRootEditPart().getContents();
+        List<EditPart> pages = doc.getChildren();
+        for (EditPart page : pages) {
+            page.deactivate();
+        }
+    }
+
+    private void HideAllPages() {
+        EditPart doc = getRootEditPart().getContents();
+        List<EditPart> pages = doc.getChildren();
+        for (EditPart page : pages) {
+            ((HoverViewerEditPart) page).getFigure().setVisible(false);
+        }
+    }
+
+    @Override
+    public void setSelection(ISelection newSelection) {
+        EditPart firstSelEditPart = null;
+
+        EditPart rootEditPart = this.getRootEditPart();
+        Iterator<Object> iterator = ((IStructuredSelection) newSelection).iterator();
+        while (iterator.hasNext()) {
+            EditPart editPart = (EditPart) iterator.next();
+            if (firstSelEditPart == null) {
+                firstSelEditPart = editPart;
+                break;
+            }
+        }
+
+        if (firstSelEditPart != null) {
+            PageData pageData2 = appManager.findPageData((Part) firstSelEditPart.getModel());
+            if (pageData2 != null && pageData2 != pageData) {
+                pageData = pageData2;
+
+                EditPart pageEditPart = getPageEditPart(firstSelEditPart);
+                currentPageEditPart = pageEditPart;
+
+                HideAllPages();
+                ((HoverViewerEditPart) currentPageEditPart).getFigure().setVisible(true);
+                // DeactivateAllPages();
+                // currentPageEditPart.activate();
+
+                updateModel();
+            }
+        }
+
+        super.setSelection(newSelection);
+
+        IStructuredSelection selection = (IStructuredSelection) newSelection;
+        if (selection.size() > 0) {
+            EditPart editpart = (EditPart) selection.toList().get(selection.size() - 1);
+            Part part = (Part) editpart.getModel();
+        }
+    }
+
+    @Override
+    public void selectionChanged(SelectionChangedEvent event) {
+        List<?> oldSelection = ((IStructuredSelection) event.getSelection()).toList();
+        final List<Object> newSelection = new ArrayList<Object>(oldSelection.size());
+        newSelection.addAll(oldSelection);
+
+        EditPart firstSelEditPart = null;
+
+        EditPart rootEditPart = this.getRootEditPart();
+        Iterator<Object> iterator = newSelection.iterator();
+        while (iterator.hasNext()) {
+            EditPart editPart = (EditPart) iterator.next();
+            if (firstSelEditPart == null) {
+                firstSelEditPart = editPart;
+            }
+
+            while (editPart != null && editPart != rootEditPart) {
+                editPart = editPart.getParent();
+                if (newSelection.contains(editPart)) {
+                    iterator.remove();
+                    break;
+                }
+            }
+        }
+
+        if (newSelection.size() < oldSelection.size()) {
+            this.getControl().getDisplay().asyncExec(new Runnable() {
+                @Override
+                public void run() {
+                    setSelection(new StructuredSelection(newSelection));
+                }
+            });
+        }
+
+        // if(firstSelEditPart != null){
+        // PageData pageData2 =
+        // appManager.findPageData((Part)firstSelEditPart.getModel());
+        // if(pageData != pageData2){
+        // pageData = pageData2;
+        //
+        // EditPart pageEditPart = getPageEditPart(firstSelEditPart);
+        // currentPageEditPart = pageEditPart;
+        //
+        // HideAllPages();
+        // ((HoverViewerEditPart)currentPageEditPart).getFigure().setVisible(true);
+        //
+        // updateModel();
+        // }
+        // }
+    }
+
+    public void scrollToCenter() {
+        Composite composite = getControl().getParent();
+        if (composite instanceof HoverBrowserRulerComposite) {
+            Rectangle editor = ((HoverBrowserRulerComposite) composite).getEditorBounds();
+            float zoom = getZoomScale();
+            int x = 0, y = 0;
+            org.tizen.webuibuilder.browserwidget.Point browser =
+                    getBrowser().getBrowser().getBrowserSize();
+
+            if (editor.width > zoom * browser.x) {
+                x = (int) ((zoom * browser.x - editor.width) / 2);
+            }
+            if (editor.height > zoom * browser.y) {
+                y = (int) ((zoom * browser.y - editor.height) / 2);
+            }
+
+            setViewLocation(x, y);
+        }
+    }
+
+    private void updateScrollBar() {
+        if (rootEditPart != null) {
+            rootEditPart.updateScrollBar();
+            rootEditPart.getFigure().repaint();
+        }
+    }
+
+    @Override
+    public void childAdded(PartEvent e) {
+        updateStyle();
+    }
+
+    @Override
+    public void childMoved(PartEvent e) {
+        updateStyle();
+    }
+
+    @Override
+    public void childRemoved(PartEvent e) {
+        updateStyle();
+    }
+
+    @Override
+    public void propertyChanged(PartEvent e) {
+    }
+
+    @Override
+    public void positionChanged(PartEvent e) {
+    }
+
+    @Override
+    public void eventChanged(PartEvent e) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void visualPositionChanged(PartEvent e) {
+        // TODO Auto-generated method stub
+
+    }
+
+    @Override
+    public void needRefresh(PartEvent e) {
+        updateStyle();
+
+    }
+
+    @Override
+    public void cssPropertyChanged(CssEvent event) {
+        updateStyle();
+    }
+
+    @Override
+    public void cssSelectorAdded(CssEvent event) {
+        updateStyle();
+    }
+
+    @Override
+    public void cssSelectorRemoved(CssEvent event) {
+        updateStyle();
+    }
+
+    @Override
+    public void needRefresh(CssEvent event) {
+        // TODO Auto-generated method stub
+        // updateStyle();
+    }
+
+    public float getZoomScale() {
+        return zoomScale;
+    }
+
+    public boolean isLandScape() {
+        return landscape;
+    }
+
+    protected String generateCssCode() {
+        return CodeGenerator.generateCssCode(rootPart);
+    }
+
+    @Override
+    public void reveal(EditPart part) {
+        super.reveal(part);
+    }
+
+    @Override
+    public void sizeChanged(int width, int height) {
+        RootEditPart rootEditPart = getRootEditPart();
+        if (rootEditPart instanceof HoverViewerRootEditPart) {
+            org.tizen.webuibuilder.browserwidget.Point browserSize =
+                    webBrowser.getBrowser().getBrowserSize();
+            ((HoverViewerRootEditPart) rootEditPart)
+                    .updateBrowserSize(browserSize.x, browserSize.y);
+        }
+    }
+
+    @Override
+    public void scrollAreaChanged(int max, int thumb) {
+        if (rootEditPart != null) {
+            // rootEditPart.getBrowserScrollBar().setMaximum(max);
+        }
+
+    }
+
+    @Override
+    public void scrolled(int scrollPos) {
+        // TODO Auto-generated method stub
+
+    }
 }
index 347cd70..3684b7f 100644 (file)
@@ -140,13 +140,15 @@ public class PageDesignerFileSelectionHandler extends CycleBaseHandler {
         if (pageDesigner == null) {
             return;
         }
-        List<String> filePaths = pageDesigner.getAppManager().getFilePackage(0);
         List<IFile> fileList = new ArrayList<IFile>();
-        for (String filePath : filePaths) {
-            IPath path = new Path(filePath);
-            String name = path.lastSegment();
-            IFile file = project.getFile(name);
-            fileList.add(file);
+        List<String> filePaths = pageDesigner.getAppManager().getFilePackage(0);
+        if (filePaths != null) {
+            for (String filePath : filePaths) {
+                IPath path = new Path(filePath);
+                String name = path.lastSegment();
+                IFile file = project.getFile(name);
+                fileList.add(file);
+            }
         }
 
         changOrderOfList(fileList, inputFile);
@@ -186,9 +188,11 @@ public class PageDesignerFileSelectionHandler extends CycleBaseHandler {
         PageDesignerForHTML pageDesigner = (PageDesignerForHTML) editor;
         AppManager appManager = pageDesigner.getAppManager();
         List<String> files = appManager.getFilePackage(0);
-        for (String packageFile : files) {
-            if (packageFile.equals(file.getFullPath().toString())) {
-                return true;
+        if (files != null) {
+            for (String packageFile : files) {
+                if (packageFile.equals(file.getFullPath().toString())) {
+                    return true;
+                }
             }
         }
         return false;