Code formatted to 70 columns.
-----------------------------
import java.util.Vector;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.Node;
import com.google.gwt.user.client.ui.HTMLPanel;
public class ListPanel extends HTMLPanel{
// aunts should actually be auntsOrUncles or childOfGrandparent
// , but that's too long
Vector<Node> aunts= new Vector<Node>();
public ListPanel(String html) {
super(html);
}
/*
Make the children of ListPanel into aunts/uncles of ListPanel
The parent of ListPanel is just a temporary proxy. Remove it.
***********SomeLayout.ui.xml *************************
<tag1>
<tag2>
<my:ListPanel>
text1
<tag3> </tag3>
<tag4> </tag4>
...
<tagn> </tagn>
text2
</my:ListPanel>
</tag2>
</tag1>
*********** Results ********************
<tag1>
text1
<tag3> </tag3>
<tag4> </tag4>
...
<tagn> </tagn>
text2
</tag1>
*/
@Override
protected void onLoad() {
super.onLoad();
// printNodeStack("ListPanel.onLoad1", getElement());
// turn children into uncles/aunts
aunts.clear();
Node proxyParent = getElement().getParentNode();
// The parent becomes the first child-Of-grandparent
aunts.add(proxyParent);
for(Node child = getElement().getFirstChild()
;child != null
;child = child.getNextSibling()){
aunts.add(child);
}
Element grandParent = proxyParent.getParentElement();
for(int i = 1; i < aunts.size();i++){
Node refChild = aunts.get(i-1);
Node newChild = aunts.get(i);
grandParent.insertAfter(newChild, refChild);
}
// remove proxy element
proxyParent.removeFromParent();
aunts.remove(proxyParent);
if(aunts.size()> 0){
// printNodeStack("ListPanel.onLoad2", aunts.get(0));
}
}
// static private void printNodeStack(String location
// , Node elementI) {
// Node previousElement = null;
// for(int i = 1; i < 4 && elementI != null; i++){
// if(i==1){
// System.out.println(location + " stack[" + i+"] "
// + elementI.toString());
// }else {
// String msg0 = previousElement.toString();
// String msg1 = elementI.toString();
// System.out.println(location + " stack[" + i+"] "
// + replace(msg1,msg0, " Message"+(i-1) + " "));
// }
// previousElement = elementI;
// elementI = elementI.getParentElement();
// }
// }
// static private String replace(String contents
// , String match
// , String replacement){
// int beginIndex = 0;
// StringBuffer buf = new StringBuffer();
// for(int matchIndex = contents.indexOf(match)
// ; matchIndex != -1
// ; matchIndex = contents.indexOf(match,beginIndex) ){
// if(matchIndex != beginIndex){
// buf.append(contents.substring(beginIndex
// , matchIndex-1));
// }
// buf.append(replacement);
// beginIndex = matchIndex+match.length();
// }
// if(beginIndex < contents.length()){
// buf.append(contents.substring(beginIndex));
// }
// return buf.toString();
// }
}
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.