hi,
guys from Instantiations should post some more,
For me it looks (and I have used that on many occasions to wrap raw elements into drag&drop featuers) that:
- Drag&Drop requries at least something like FlowPanel/ComplexPanel with a method like "add" and "add at position" to allow us to add widget and then reorder it in widget tree.
- All widgets needs to descent from Widget to be D&D (WYSWIG) in Desing view,
- an "drop" area (here Panel) in composite source widget needs to have "Expose that widget" feature applied1,
example for you:
// IMPL:
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Element;
import com.google.gwt.user.client.ui.FlowPanel;
public class FieldsetImpl extends FlowPanel {
private Element legend;
public FieldsetImpl() {
setElement(DOM.createElement("fieldset"));
DOM.setInnerHTML(getElement(), "");
legend = DOM.createElement("legend");
DOM.appendChild(getElement(), legend);
}
/* @Override */
public String getTitle() {
return DOM.getInnerText(legend);
}
/**
* Override to have title'd legend
*/
/* @Override */
public void setTitle(String title) {
DOM.setInnerText(legend, (title == null ? "" : title));
super.setTitle(title);
}
}
now Composite:
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.user.client.ui.Composite;
public class Fieldset extends Composite {
private FieldsetImpl fieldset;
public Fieldset() {
fieldset = new FieldsetImpl();
initWidget(fieldset);
}
public FieldsetImpl getFieldset() {
return fieldset;
}
/* @Override */
public void setTitle(String title) {
fieldset.setTitle(title);
}
/* @Override */
public String getTitle() {
return fieldset.getTitle();
}
}
(NOTE: Composite also created using D&D whyshiw Design view, however there are no other visible elements on that wiget),
note that I had to expose decorated widget in order to pick it by design view:
CODE GENERATED by GWT Designer after using D&D of those custom widgets:
- Code: Select all
package com.mycompany.project.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.PasswordTextBox;
import com.google.gwt.user.client.ui.RootPanel;
/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class TestXML implements EntryPoint {
JavaScriptObject xml;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();
final Fieldset fieldsetWidget = new Fieldset();
rootPanel.add(fieldsetWidget);
fieldsetWidget.setTitle("Fieldset");
final PasswordTextBox passwordTextBox = new PasswordTextBox();
fieldsetWidget.getFieldset().add(passwordTextBox);
passwordTextBox.setText("password");
final Button loginButton = new Button();
fieldsetWidget.getFieldset().add(loginButton);
loginButton.setText("Login");
}
}
hth
regards,
Peter