@PostConstruct public void init() { CommonGlobals.getInstance().registerI18n((I18NConstants) GWT.create(I18NConstants.class)); PickupDragController dragController = new PickupDragController(dndController.getBoundaryPanel(), true); dragController.registerDropController(new DisposeDropController(view.getPanel())); CommonGlobals.getInstance().registerDragController(dragController); try { formServices .call( new RemoteCallback<Map<String, String>>() { @Override public void callback(Map<String, String> properties) { for (String key : properties.keySet()) { RepresentationFactory.registerItemClassName(key, properties.get(key)); } } }) .getFormBuilderProperties(); formServices .call( new RemoteCallback<Void>() { @Override public void callback(Void nothing) {} }) .listMenuItems(); } catch (MenuServiceException ex) { Logger.getLogger(FormBuilderPalettePresenter.class.getName()).log(Level.SEVERE, null, ex); } }
/** UI form item. Represents a piece of user entered HTML */ @Reflectable public class HTMLFormItem extends FBFormItem { private final I18NConstants i18n = CommonGlobals.getInstance().getI18n(); private HTML html = new HTML(); public HTMLFormItem() { this(new ArrayList<FBFormEffect>()); } public HTMLFormItem(List<FBFormEffect> formEffects) { super(formEffects); html.setHTML("<div style=\"background-color: #DDDDDD; \">HTML: Click to edit</div>"); add(html); setWidth("200px"); setHeight("100px"); setSize(getWidth(), getHeight()); } @Override public Map<String, Object> getFormItemPropertiesMap() { Map<String, Object> map = new HashMap<String, Object>(); map.put("width", getWidth()); map.put("height", getHeight()); return map; } @Override public FBInplaceEditor createInplaceEditor() { return new HTMLFormItemEditor(this); } @Override public void saveValues(Map<String, Object> asPropertiesMap) { this.setWidth(extractString(asPropertiesMap.get("width"))); this.setHeight(extractString(asPropertiesMap.get("height"))); populate(this.html); } private void populate(HTML html) { if (getWidth() != null) { html.setWidth(getWidth()); } if (getHeight() != null) { html.setHeight(getHeight()); } } public void setContent(String html) { this.html.setHTML(html); } @Override public FormBuilderDTO getRepresentation() { FormBuilderDTO dto = super.getRepresentation(); dto.setString("content", html.getHTML()); return dto; } @Override public void populate(FormBuilderDTO dto) throws FormBuilderException { if (!dto.getClassName().endsWith("HTMLRepresentation")) { throw new FormBuilderException(i18n.RepNotOfType(dto.getClassName(), "HTMLRepresentation")); } super.populate(dto); this.setContent(dto.getString("content")); } @Override public FBFormItem cloneItem() { HTMLFormItem clone = new HTMLFormItem(getFormEffects()); clone.setHeight(getHeight()); clone.setWidth(getWidth()); clone.setContent(this.html.getHTML()); clone.populate(clone.html); return clone; } public String getTextContent() { return this.html.getText(); } public String getHtmlContent() { return this.html.getHTML(); } public void setTextContent(String textContent) { this.html.setText(textContent); } public void setHtmlContent(String htmlContent) { this.html.setHTML(htmlContent); } @Override public Widget cloneDisplay(Map<String, Object> data) { HTML html = new HTML(); html.setHTML(this.html.getHTML()); populate(html); super.populateActions(html.getElement()); return html; } }