Window - drag and drop - dissapearing content

Hi everyone,
I am developing drag and drop portal in smart gwt. The portal consist of:
-one HStack (named horizontalContainer);
-multiple VStacks;
-multiple Window objects.

HStack contains VStacks, VStacks contain Windows. This way i have columns of windows, and I can drag and drop windows among columns.

Here is the code in which I create new column:
VStack column = new VStack(10);
column.setLayoutMargin(10);
column.setShowEdges(true);
column.setCanAcceptDrop(true);
column.setDropLineThickness(4);
column.setDropLineProperties(dropLineProperties);
horizontalContainer.addMember(column);
where
dropLineProperties = new HashMap<String, String>();
dropLineProperties.put(“backgroundColor”, “#40c040”);

For Window object I use my own wrapper class, that looks like that:
public class SmartWorkspaceItem_Window extends com.smartgwt.client.widgets.Window {
public SmartWorkspaceItem_Window(Widget widget, String title) {
super();
setCanDragReposition(true);
setCanDrop(true);
setCanDragResize(true);

	setTitle(title);   
	setWidth("320px");
	setHeight("200px");
	addItem(widget);	          
}

}
Eventually, I add my SmartWorkspaceItem_Window instances to columns:
currCol.addMember(portlet)
where portlet is an instance of SmartWorkspaceItem_Window.

Now I want to add two windows:
portlet = new SmartWorkspaceItem_Window(new com.smartgwt.client.widgets.Label(“Test”),“Label”);
and
portlet = new SmartWorkspaceItem_Window(new com.google.gwt.user.client.ui.Frame.Frame(“http://www.google.com”),“Frame”);

When I start the portal, everything looks cool. But the trouble is when I start to drag and drop. The window that contains label works fine, but when I drop window that contains gwt frame, the frame disappears, and I end up with empty window.

Any ideas how to solve this?

Moved post to SmartGWT forum

Hello marcinjunger,

This looks like some kind of GWT interop problem which we’ll have to look at.

In the meantime there’s a SmartGWT component called HTMLPane that loads pages, similar to the GWT frame class.

similar behavior with FocusPanel

Hi,
thanks for yur answer!
I will check the HTMLPane, have I’m stuck with another composite component that behaves in the same way. I have a FocusPanel that is added to Window. The FocusPanel contains DecoratedTabPanel.

That means that either I’m doing something really stupid, or there is bigger problem.

SOURCE CODE - did not fit in previous post

Here is the complete code of my component:
BASE CLASS
public abstract class SwtBase extends BaseWidget implements BaseSwtPortlet, RequesterCallback, EventingClient {
public String swtId;
public Requester requestBuilder;
/** If there is an error we put the message here; If not empty, portlet displays label with that message instead of frame*/
protected String errorContent = “”;
/**
* Event listener called from another widget.
/
public abstract void sageOnEvent(String action, String data);
/
*
* A reference to the internal GWT panel
/
public abstract Widget getPanel();
/
*
* The XML parser; Gets portlet metadata from XML;
* If something goes wrong, saves error message in errorContent
/
public abstract void parseXml(String xmlData);
/
*
* The widget ID used to associate events.
*/
public void setPortletId(String swtId) {
this.swtId = swtId;
}

/**
 * The widget ID used to associate events.
 */
public String getPortletId() {
	return swtId;
}

/**
 * This is the (asynchronous) AJAX metadata call
 */
protected void getData(String url) {
	requestBuilder = new Requester(url, this);
}

/**
 * This is the common AJAX response callback.
 */
public void onRequestFinished(Requester requester) {
	if(requester.error){
		Window.alert(requester.response);
	}else{
		parseXml(requester.response);
		buildPortlet();
	}
}
/**
 * The portlet builder.  This builds the portlet based on data got from parseXml;
 */	
protected abstract void buildPortlet();

/**
 * Event sender to another widget.  Events are sent via the event channel
 */
public void sagePublish(String nameSpace,
		String topic,
		String action,
		String data) {
	EventChannel.sagePublish(nameSpace,topic,action,data);
}

/**
 * Subscribe for event from other widgets.  Events are delivered via the event channel
 */
public void sageSubscribe(String nameSpace,
		String topic,
		String portletId,
		Object subscriber) {
	EventChannel.sageSubscribe(nameSpace,topic,portletId,subscriber);
}

/**
 * &lt;b&gt;Native JSNI:&lt;/b&gt; Call an external customised javascript function
 */
protected native void callJs(String script) /*-{
$wnd.setTimeout(script, 100);

}-*/;
}

THE COMPOSITE COMPONENT
public class TabGroupPortlet extends SwtBase implements TabListener,PortletConstants {

private static final String THIS_WIDGET_TYPE = "TabGroupPortlet";

private final FocusPanel wrapPanel;
private final DecoratedTabPanel tabPanel;
private static final TreeMap metadata = new TreeMap();
private static boolean eventReceived = false;


/**
 * The constructor reads its bootstrap SData location from the enclosing page.
 * It then makes an AJAX call to the bootstrap location for its initialising metadata.
 */
public TabGroupPortlet(WorkspaceItemMetadata itemMetadata) {
	setPortletId(itemMetadata.id);
	tabPanel = new DecoratedTabPanel();
	tabPanel.getDeckPanel().setAnimationEnabled(true);
	tabPanel.addTabListener(this);		
	tabPanel.setWidth("100%");
	tabPanel.setHeight("100%");		
	
	wrapPanel = new FocusPanel();
	wrapPanel.add(tabPanel);
	wrapPanel.setWidth("100%");
	wrapPanel.setHeight("100%");
	getData(itemMetadata.binding);
}

/**
 * Access the internal panel widget for display.
 */
@Override
public Widget getPanel() {
	return wrapPanel;
}

/**
 * The event callback.
 */
@Override
public void sageOnEvent(String action, String data) {
	Window.alert(this.getPortletId() + " received an event: " + action + ", " + data);
}

/**
 * The SData parser
 */
@Override
public void parseXml(String xmlData) {
	Document doc = null;

	try {
		doc = XMLParser.parse(xmlData);
	} catch (DOMException e) {
		Window.alert("Can't parse XML:

" + e.toString());
}

	if (null != doc) {
		Element rootNode = doc.getDocumentElement();
		XMLParser.removeWhitespace(rootNode);
		NodeList entries = rootNode.getElementsByTagName(ENTRY_NODE);
		for (int i=0; i&lt;entries.getLength(); i++) {
			Element entry = (Element) entries.item(i);
			NamedNodeMap attributes = entry.getAttributes();
			if (attributes.getLength() &gt; 0) {
				HashMap metaEntry = new HashMap();
				metaEntry.put("title", attributes.getNamedItem(TITLE_ATTRIBUTE).getNodeValue());
				if (null != attributes.getNamedItem(URL_ATTRIBUTE) &&
						!attributes.getNamedItem(URL_ATTRIBUTE).getNodeValue().equals("")) {
					metaEntry.put("url", attributes.getNamedItem(URL_ATTRIBUTE).getNodeValue());
				}
				if (null != attributes.getNamedItem(SCRIPT_ATTRIBUTE) &&
						!attributes.getNamedItem(SCRIPT_ATTRIBUTE).getNodeValue().equals("")) {
					metaEntry.put("script", attributes.getNamedItem(SCRIPT_ATTRIBUTE).getNodeValue());
				}

				// Add inter-widget onclick events if present
				NodeList eventNodes = entry.getElementsByTagName(EVENT_NODE);
				if (null != eventNodes && eventNodes.getLength() &gt; 0) {
					ArrayList events = new ArrayList();
					for (int j=0; j&lt;eventNodes.getLength(); j++) {
						Element event = (Element)eventNodes.item(j);
						NamedNodeMap eventAttributes = event.getAttributes();
						if (null != eventAttributes && eventAttributes.getLength() &gt; 0) {
							String nameSpace = eventAttributes.getNamedItem(NAMESPACE_ATTRIBUTE).getNodeValue();
							String direction = eventAttributes.getNamedItem(DIRECTION_ATTRIBUTE).getNodeValue();
							HashMap eventItem = new HashMap();
							eventItem.put("nameSpace", nameSpace);
							eventItem.put("direction", direction);
							if (null != eventAttributes.getNamedItem(ACTION_ATTRIBUTE)) {
								String action = eventAttributes.getNamedItem(ACTION_ATTRIBUTE).getNodeValue();
								eventItem.put("action", action);
							}

							if (null != event.getElementsByTagName(TOPIC_NODE)) {
								String topic = ((Element)event.getElementsByTagName(TOPIC_NODE).item(0)).getFirstChild().getNodeValue();
								eventItem.put("topic", topic);
							}

							if (null != event.getElementsByTagName(DATA_NODE)) {
								if (null != ((Element)event.getElementsByTagName(DATA_NODE).item(0))) {
									Element dataElm = (Element)event.getElementsByTagName(DATA_NODE).item(0);
									if (null != dataElm.getFirstChild()) {
										String data = dataElm.getFirstChild().getNodeValue();
										eventItem.put("data", data);
									}
								}
							}
							events.add(eventItem);
						}
					}
					metaEntry.put("event", events);
				}
				metadata.put(metaEntry.get("title"), metaEntry);
			}
		}
	} else {
		Window.alert("Cannot parse XML: " + xmlData);
	}
}

/**
 * The tab group builder.  This builds the tab group from the SData received.
 */
protected void buildPortlet() {
	if (metadata.size() &gt; 0) {
		for (Iterator itr=metadata.entrySet().iterator(); itr.hasNext();) {
			Map.Entry entry = (Map.Entry)itr.next();
			HashMap value = (HashMap)metadata.get(entry.getKey());
			if (null != value && value.size() &gt; 0) {
				String tabName = (String)value.get("title");
				String tabUrl = (String)value.get("url");

				Frame frame = new Frame(tabUrl);
				tabPanel.add(frame, tabName);

				// Subscribe to events if set
				if (null != value.get("event")) {
					ArrayList events = (ArrayList)value.get("event");
					for (int i=0; i&lt;events.size(); i++) {
						final HashMap eventItem = (HashMap)events.get(i);
						final String nameSpace = (String)eventItem.get("nameSpace");
						final String direction = (String)eventItem.get("direction");
						final String topic = (String)eventItem.get("topic");
						if (direction.equals(SUBSCRIBE)) {
							sageSubscribe(nameSpace, topic, this.getPortletId(), this);
						}
					}
				}
			}
		}
		tabPanel.selectTab(0);			
	}
}

/*
 * Tab event listener triggered before the select event is sent.
 */
public boolean onBeforeTabSelected(SourcesTabEvents sender, int tabIndex) {
	if (!eventReceived) {
		String url = (String)((HashMap)(metadata.values().toArray()[tabIndex])).get("url");
		String tabTitle = (String)((HashMap)(metadata.values().toArray()[tabIndex])).get("title");
		String script = (String)((HashMap)(metadata.values().toArray()[tabIndex])).get("script");

		// Send an event if set in metadata
		if (null != ((HashMap)(metadata.values().toArray()[tabIndex])).get("event")) {
			final ArrayList events = (ArrayList)((HashMap)(metadata.values().toArray()[tabIndex])).get("event");
			for (int i=0; i&lt;events.size(); i++) {
				final HashMap eventItem = (HashMap)events.get(i);
				final String nameSpace = (String)eventItem.get("nameSpace");
				final String direction = (String)eventItem.get("direction");
				final String action = (String)eventItem.get("action");
				final String topic = (String)eventItem.get("topic");
				final String data = (String)eventItem.get("data");
				if (direction.equals(PUBLISH)) {
					sagePublish(nameSpace, topic, action, data);
				}
			}
		}

		// Navigate to an url if set in metadata
		if (null != url && !url.equals("")) {
			Frame frame = new Frame(url);
			tabPanel.remove(tabIndex);
			tabPanel.insert(frame, tabTitle, tabIndex);
		}

		// Call an external javascript function
		if (null != script && !script.equals("")) {
			callJs(script);
		}
	}
	return true;
}

/*
 * Tab event listener triggered when the select event is sent.
 */
public void onTabSelected(SourcesTabEvents sender, int tabIndex) {
	//resize(tabIndex);
}

private void resize(int tabIndex) {
	// resize fix:- see http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/033d073d49de3598
	int height = Window.getClientHeight() - tabPanel.getDeckPanel().getAbsoluteTop() - 8;
	tabPanel.getWidget(tabIndex).setHeight("" + height);
}

}

HTMLPane

I replaced Frame with HTMLPane, and got:
[ERROR] Uncaught exception escaped
java.lang.IllegalStateException: Cannot change configuration property ‘contentsType’ to page after the component has been created.
at com.smartgwt.client.widgets.BaseWidget.error(BaseWidget.java:379)
at com.smartgwt.client.widgets.BaseWidget.error(BaseWidget.java:367)
at com.smartgwt.client.widgets.BaseWidget.setAttribute(BaseWidget.java:389)
at com.smartgwt.client.widgets.HTMLFlow.setContentsType(HTMLFlow.java:352)
at com.smartgwt.client.widgets.HTMLPane.setIFrameURL(HTMLPane.java:61)
at com.sage.sgwt.client.portlet.IframePortlet.buildPortlet(IframePortlet.java:181)
(…)

Haven’t seen your code for the HTMLPane version yet, but try setting contentsType before adding the component to the tabPanel (or whatever other parent).