From f8800e84226ad56a244680476fcb2117aa756413 Mon Sep 17 00:00:00 2001 From: Joonas Lehtinen Date: Wed, 20 Jun 2007 08:24:48 +0000 Subject: [PATCH] Simplified customlayout, now locations can be put into divs with ids set svn changeset:1773/svn branch:trunk --- .../layout/featurebrowser-mainlayout.html | 166 ++++++++---------- WebContent/theme/demo/style.css | 23 --- .../terminal/gwt/client/ui/ICustomLayout.java | 145 +++++++++------ 3 files changed, 169 insertions(+), 165 deletions(-) diff --git a/WebContent/theme/demo/layout/featurebrowser-mainlayout.html b/WebContent/theme/demo/layout/featurebrowser-mainlayout.html index ac0623983c..ee66b4919e 100644 --- a/WebContent/theme/demo/layout/featurebrowser-mainlayout.html +++ b/WebContent/theme/demo/layout/featurebrowser-mainlayout.html @@ -1,90 +1,80 @@ - + -
- -
-
puu
-
- -
- - - - - - -
- - - - - - -
- -
demo
- -
-
-
- -
-
tabs
-
+
- +
+
tree
+
-
-
properties
-
+
+ + + + + + +
+ + + + + + +
+
demo
+
+
+
-
- - - - - - - -
-
themes
-
-
restart
-
-
+
+
tabsheet
+
+ + + +
+
properties
+
+ +
+ + + + + + + +
themesrestart
+
+ +
-
-
diff --git a/WebContent/theme/demo/style.css b/WebContent/theme/demo/style.css index 5a6d60f81b..e69de29bb2 100644 --- a/WebContent/theme/demo/style.css +++ b/WebContent/theme/demo/style.css @@ -1,23 +0,0 @@ -.itmtk .tree-menu .content, -.itmtk .tree-menu .content .node, -.itmtk .tree-menu .content .nodes, -.itmtk .tree-menu .content .node IMG { - background: none; - border: 0; -} - -#featurebrowser-divider { - background-image: url(layout/img/tab_handle.png); -} - -#featurebrowser-mainlayout -{ - background-image: url(layout/img/m_bg.png); - background-repeat: no-repeat; -} - -#featurebrowser-features { - position: absolute; - overflow: auto; - left: 0; -} \ No newline at end of file diff --git a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java index 43dedca116..6fe29ab7d0 100644 --- a/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java +++ b/src/com/itmill/toolkit/terminal/gwt/client/ui/ICustomLayout.java @@ -2,8 +2,11 @@ package com.itmill.toolkit.terminal.gwt.client.ui; import java.util.HashMap; import java.util.Iterator; +import java.util.NoSuchElementException; +import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; +import com.google.gwt.user.client.ui.ComplexPanel; import com.google.gwt.user.client.ui.HTMLPanel; import com.google.gwt.user.client.ui.SimplePanel; import com.google.gwt.user.client.ui.Widget; @@ -13,34 +16,50 @@ import com.itmill.toolkit.terminal.gwt.client.Layout; import com.itmill.toolkit.terminal.gwt.client.Paintable; import com.itmill.toolkit.terminal.gwt.client.UIDL; -public class ICustomLayout extends SimplePanel implements Paintable, Layout { +public class ICustomLayout extends ComplexPanel implements Paintable, Layout { - private HashMap componentToWrapper = new HashMap(); - - HTMLPanel html; + private HashMap locationToElement = new HashMap(); + + private HashMap locationToWidget = new HashMap(); String currentStyle; - String locationPrefix = HTMLPanel.createUniqueId() + "_"; - String scripts = ""; + + String pid; + + public ICustomLayout() { + setElement(DOM.createDiv()); + } + + public void add(Widget widget, String location) { + Element elem = (Element) locationToElement.get(location); + if (elem == null) { + throw new NoSuchElementException(); + } + Widget previous = (Widget) locationToWidget.get(location); + if (widget.equals(previous)) return; + remove(previous); + super.add(widget, elem); + locationToWidget.put(location,widget); + } public void updateFromUIDL(UIDL uidl, Client client) { if (client.updateComponent(this, uidl, false)) return; + pid = uidl.getId(); + updateHTML(uidl, client); - componentToWrapper.clear(); - html.clear(); for (Iterator i = uidl.getChildIterator(); i.hasNext();) { UIDL uidlForChild = (UIDL) i.next(); if (uidlForChild.getTag().equals("location")) { String location = uidlForChild.getStringAttribute("name"); Widget child = client.getWidget(uidlForChild.getChildUIDL(0)); try { - html.add(child, locationPrefix + location); + add(child, location); } catch (Exception e) { // If no location is found, this component is not visible } @@ -65,22 +84,45 @@ public class ICustomLayout extends SimplePanel implements Paintable, Layout { currentStyle = newStyle; } template = extractBodyAndScriptsFromTemplate(template); - html = new HTMLPanel(template); - addUniqueIdsForLocations(html.getElement(), locationPrefix); + DOM.setInnerHTML(getElement(), template); + + locationToElement.clear(); + scanForLocations(getElement()); Widget parent = getParent(); while (parent != null && !(parent instanceof IWindow)) parent = parent.getParent(); if (parent != null && ((IWindow) parent).getTheme() != null) ; - prefixImgSrcs(html.getElement(), "../theme/" + prefixImgSrcs(getElement(), "../theme/" + ((IWindow) parent).getTheme() + "/layout/"); - add(html); } + private void scanForLocations(Element elem) { + + String location = getLocation(elem); + if (location != null) { + locationToElement.put(location, elem); + DOM.setInnerHTML(elem, ""); + } else { + int len = DOM.getChildCount(elem); + for (int i=0; i