UIB : code refactoring for PREVENT 16/18516/1
authorgyeongmin.ju <gyeongmin.ju@samsung.com>
Tue, 25 Mar 2014 06:37:03 +0000 (15:37 +0900)
committergyeongmin.ju <gyeongmin.ju@samsung.com>
Tue, 25 Mar 2014 06:37:03 +0000 (15:37 +0900)
Signed-off-by: gyeongmin.ju <gyeongmin.ju@samsung.com>
Change-Id: Ibbda6505669aad4ea7e5ab2a60a2dc71caf4ebe3

org.tizen.webuibuilder/src/org/tizen/webuibuilder/animator/model/AnimatorModelManager.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/model/app/AppManagerForHTML.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/io/DescriptorReader.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/io/PageReader_ver_2.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/io/PageWriter.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/page/PageDataForHTML.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/project/ProjectManager.java
org.tizen.webuibuilder/src/org/tizen/webuibuilder/model/project/io/ProjectWriter.java

index 017e36a..19e9e8f 100644 (file)
@@ -1391,15 +1391,17 @@ public class AnimatorModelManager implements ISelectionListener, IPageDataSetLis
             if (!((AnimatorPart)rootPart).hasAnimation()) {
                 Document editDoc = ((AppManagerForHTML) appManager).getDocument();
                 NodeList heads = editDoc.getElementsByTagName("head");
-                if (heads == null) {
-                    Element newElmHead = editDoc.createElement("head");
-                    if(newElmHead != null) {
-                       editDoc.insertBefore(newElmHead, editDoc.getFirstChild());
+                Element head = null;
+                if (heads != null) {
+                    head = (Element) heads.item(0);
+                } else {
+                       head = editDoc.createElement("head");
+                    if(head != null) {
+                       editDoc.insertBefore(head, editDoc.getFirstChild());
                     }
                 }
-                Element elm = (Element) heads.item(0);
 
-                NodeList scripts = elm.getElementsByTagName("script");
+                NodeList scripts = head.getElementsByTagName("script");
                 if (scripts != null) {
                     int len = scripts.getLength();
                     for (int i = 0; i < len; i++) {
@@ -1415,7 +1417,7 @@ public class AnimatorModelManager implements ISelectionListener, IPageDataSetLis
                         }
                     }
                 }
-                NodeList links = elm.getElementsByTagName("link");
+                NodeList links = head.getElementsByTagName("link");
                 if (links != null) {
                     int len = links.getLength();
                     for (int i = 0; i < len; i++) {
index d5d171e..b12e982 100644 (file)
@@ -261,7 +261,7 @@ public class DeclarationViewInfoProvider implements IDeclarationViewInfoProvider
         StringBuffer strBuf = new StringBuffer();
         String strLine = null;
         try {
-            FileReader fr = new FileReader(jsPath);
+               FileReader fr = new FileReader(jsPath);
             BufferedReader br = new BufferedReader(fr);
             while ((strLine = br.readLine()) != null) {
                 strBuf.append(strLine);
@@ -272,6 +272,7 @@ public class DeclarationViewInfoProvider implements IDeclarationViewInfoProvider
             e.printStackTrace();
         } catch (IOException e) {
             e.printStackTrace();
+        } finally {
         }
         return strBuf.toString();
     }
index 27c1ba9..181a928 100644 (file)
@@ -20,7 +20,6 @@
  *
  */
 
-
 package org.tizen.webuibuilder.gef.viewer;
 
 import java.beans.PropertyChangeEvent;
@@ -79,904 +78,929 @@ 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();
-        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();
-            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() {
+               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
+
+       }
 }
index 2422671..e12db40 100644 (file)
@@ -439,17 +439,19 @@ public class AppManagerForHTML extends AppManager {
         Document editDoc = (Document) getDocument().cloneNode(true);
 
         NodeList heads = editDoc.getElementsByTagName("head");
-        if (heads == null) {
-            Element newElmHead = editDoc.createElement("head");
-            editDoc.insertBefore(newElmHead, editDoc.getFirstChild());
+        Element head = null;
+        if (heads != null) {
+               head = (Element) heads.item(0);
+        } else {
+               head = editDoc.createElement("head");
+            editDoc.insertBefore(head, editDoc.getFirstChild());
         }
-        Element elm = (Element) heads.item(0);
 
         Element newElmBase = editDoc.createElement("base");
         newElmBase.setAttribute("href", rootPathUri + "/");
-        elm.insertBefore(newElmBase, elm.getFirstChild());
+        head.insertBefore(newElmBase, head.getFirstChild());
 
-        NodeList elemList = elm.getChildNodes();
+        NodeList elemList = head.getChildNodes();
         for(int i = elemList.getLength(); i >= 0; i--){
                Node childNode = elemList.item(i);
                if(childNode instanceof Element){
@@ -460,7 +462,7 @@ public class AppManagerForHTML extends AppManager {
                        String filename = src.substring(fileidx + 1);
                        if (!filename.equals("jquery.js") && !filename.equals("tizen-web-ui-fw-libs.js")
                                && !filename.equals("tizen-web-ui-fw.js")) {
-                               elm.removeChild(childNode);
+                               head.removeChild(childNode);
                        }
                        }
             }
@@ -468,19 +470,21 @@ public class AppManagerForHTML extends AppManager {
 
         Element newElm = editDoc.createElement("script");
         newElm.setAttribute("src", "./tizen-ui-builder-tool/res/html/ground.js");
-        elm.appendChild(newElm);
+        head.appendChild(newElm);
 
         Element newElm2 = editDoc.createElement("style");
         newElm2.setAttribute("type", "text/css");
         newElm2.setAttribute("id", "page_style");
-        elm.appendChild(newElm2);
+        head.appendChild(newElm2);
 
         NodeList bodys = editDoc.getElementsByTagName("body");
-        if (bodys == null) {
-            Element newElmBody = editDoc.createElement("body");
-            editDoc.appendChild(newElmBody);
+        Element body = null;
+        if (bodys != null) {
+               body = (Element) bodys.item(0);
+        } else {
+            body = editDoc.createElement("body");
+            editDoc.appendChild(body);
         }
-        Element body = (Element) bodys.item(0);
         int len = body.getChildNodes().getLength();
         for (int i = 0; i < len; i++) {
             body.removeChild(body.getFirstChild());
@@ -497,17 +501,19 @@ public class AppManagerForHTML extends AppManager {
         Document editDoc = (Document) getDocument().cloneNode(true);
 
         NodeList heads = editDoc.getElementsByTagName("head");
-        if (heads == null) {
-            Element newElmHead = editDoc.createElement("head");
-            editDoc.insertBefore(newElmHead, editDoc.getFirstChild());
+        Element head = null;
+        if (heads != null) {
+               head = (Element) heads.item(0);
+        } else {
+               head = editDoc.createElement("head");
+            editDoc.insertBefore(head, editDoc.getFirstChild());
         }
-        Element elm = (Element) heads.item(0);
 
         Element newElmBase = editDoc.createElement("base");
         newElmBase.setAttribute("href", rootPathUri + "/");
-        elm.insertBefore(newElmBase, elm.getFirstChild());
+        head.insertBefore(newElmBase, head.getFirstChild());
 
-        NodeList elemList = elm.getChildNodes();
+        NodeList elemList = head.getChildNodes();
         for(int i = elemList.getLength(); i >= 0; i--){
                Node childNode = elemList.item(i);
                if(childNode instanceof Element){
@@ -518,7 +524,7 @@ public class AppManagerForHTML extends AppManager {
                        String filename = src.substring(fileidx + 1);
                        if (!filename.equals("jquery.js") && !filename.equals("tizen-web-ui-fw-libs.js")
                                && !filename.equals("tizen-web-ui-fw.js")) {
-                               elm.removeChild(childNode);
+                               head.removeChild(childNode);
                        }
                        }
             }
@@ -538,11 +544,11 @@ public class AppManagerForHTML extends AppManager {
         newAniElm1.setAttribute("type", "text/css");
         newAniElm1.setAttribute("id", "animationCss");
         newAniElm1.setTextContent(animatorCss);
-        elm.appendChild(newAniElm1);
+        head.appendChild(newAniElm1);
 
         Element newAniElm2 = editDoc.createElement("script");
         newAniElm2.setTextContent(animatorJs);
-        elm.appendChild(newAniElm2);
+        head.appendChild(newAniElm2);
 
         /*
          * page_stye
@@ -550,35 +556,37 @@ public class AppManagerForHTML extends AppManager {
         Element newElm1 = editDoc.createElement("style");
         newElm1.setAttribute("type", "text/css");
         newElm1.setAttribute("id", "page_style");
-        elm.appendChild(newElm1);
+        head.appendChild(newElm1);
 
         /*
          * ground.js
          */
         Element newElm2 = editDoc.createElement("script");
         newElm2.setAttribute("src", "./tizen-ui-builder-tool/res/html/ground.js");
-        elm.appendChild(newElm2);
+        head.appendChild(newElm2);
 
         /*
          * ani_bridge.js
          */
         Element newAniElm3 = editDoc.createElement("script");
         newAniElm3.setAttribute("src", "./tizen-ui-builder-tool/res/animator/js/ani-bridge.js");
-        elm.appendChild(newAniElm3);
+        head.appendChild(newAniElm3);
 
         /*
          * tizen_animator_fw.js
          */
         Element newAniElm4 = editDoc.createElement("script");
         newAniElm4.setAttribute("src", "tizen-ui-builder-fw/tizen-animator-fw.js");
-        elm.appendChild(newAniElm4);
+        head.appendChild(newAniElm4);
 
         NodeList bodys = editDoc.getElementsByTagName("body");
-        if (bodys == null) {
-            Element newElmBody = editDoc.createElement("body");
-            editDoc.appendChild(newElmBody);
+        Element body = null;
+        if (bodys != null) {
+            body = (Element) bodys.item(0);
+        } else {
+               body = editDoc.createElement("body");
+            editDoc.appendChild(body);
         }
-        Element body = (Element) bodys.item(0);
         int len = body.getChildNodes().getLength();
         for (int i = 0; i < len; i++) {
             body.removeChild(body.getFirstChild());
index 6bdb71e..8a8f002 100644 (file)
@@ -197,7 +197,7 @@ public class DescriptorReader {
                        e.printStackTrace();
                }
 
-               if (doc != null && doc.getDocumentElement() != null) {
+               if (builder != null && doc != null && doc.getDocumentElement() != null) {
                        xslRoot = doc.createElementNS(XSL_NAMESPACE, XSL_STYLESHEET);
                        xslRoot.setPrefix(XSL_PREFIX);
                        xslRoot.setAttribute(ATTR_STYLESHEET_VERSION, VALUE_STYLESHEET_VERSION);
index 89681d5..ffdbf2b 100644 (file)
@@ -274,12 +274,14 @@ public class PageReader_ver_2 {
             }
 
             // 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);
-                }
+                       if (selectors != null){
+                   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.
index c22a93c..b046897 100644 (file)
@@ -76,6 +76,7 @@ public class PageWriter {
                                        BuilderConstants.XML);
                } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
+                       return;
                }
 
                try {
index 301040b..611f65b 100644 (file)
@@ -84,8 +84,15 @@ public class PageDataForHTML extends PageData {
         if (document == null) {
             return;
         }
-
+        if (event == null) {
+            return;
+        }
+        
         Part parent = (Part) event.getPart();
+        if (parent == null) {
+            return;
+        }
+
         Element parentElement = parent.getElement();
         if (parentElement == null) {
             return;
@@ -145,9 +152,9 @@ public class PageDataForHTML extends PageData {
     public void childAdded(PartEvent event) {
         // super.childAdded(event);
 
-        if (event != null) {
+        //if (event != null) {
             addElement(event);
-        }
+        //}
 
         super.childAdded(event);
     }
@@ -156,9 +163,9 @@ public class PageDataForHTML extends PageData {
     public void childMoved(PartEvent event) {
         // super.childMoved(event);
 
-        if (event != null) {
+        //if (event != null) {
             addElement(event);
-        }
+        //}
 
         super.childMoved(event);
     }
@@ -179,15 +186,14 @@ public class PageDataForHTML extends PageData {
             transformer.setOutputProperty(OutputKeys.METHOD, BuilderConstants.HTML);
         } catch (TransformerConfigurationException e) {
             e.printStackTrace();
+            return null;
         }
 
         DOMSource source = new DOMSource(element);
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         StreamResult result = new StreamResult(baos);
-        // StreamResult result2 = new StreamResult(System.out);
         try {
             transformer.transform(source, result);
-            // transformer.transform(source, result2);
         } catch (TransformerException e) {
             e.printStackTrace();
         }
index 0ffa3d2..aa0f6eb 100644 (file)
@@ -116,11 +116,16 @@ public class ProjectManager {
                File cssDescriptorFile = descriptorPath.append(
                                BuilderConstants.CSS_DESCRIPTOR_FILE).toFile();
 
+               if (project != null){
                IFile file = project.getFile(BuilderConstants.PROJECT_FILE);
-               if (file.exists()) {
-                       descriptorManagerOld = DescriptorManager.loadDescriptor(
-                                       descriptorFileOld, cssDescriptorFileOld);
+                       if (file.exists()) {
+                               descriptorManagerOld = DescriptorManager.loadDescriptor(
+                                               descriptorFileOld, cssDescriptorFileOld);
+                       }
+               } else {
+                       descriptorManagerOld = null;
                }
+               
                descriptorManager = DescriptorManager.loadDescriptor(descriptorFile,
                                cssDescriptorFile);
 
index d4d68cc..28b5c49 100644 (file)
@@ -67,6 +67,7 @@ public class ProjectWriter {
                                        BuilderConstants.XML);
                } catch (TransformerConfigurationException e) {
                        e.printStackTrace();
+                       return;
                }
 
                try {