@Override protected Component initContent() { DragAndDropWrapper wrapper = new DragAndDropWrapper(parameter); wrapper.setDropHandler( new DropHandler() { @Override public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } @Override public void drop(DragAndDropEvent event) { if (parameter.isReadOnly()) return; DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); Object sourceItemId = t.getData("itemId"); String source = ""; if (sourceItemId instanceof BeanItem<?>) { Object bean = ((BeanItem<?>) sourceItemId).getBean(); source = ((DragDropBean) bean).getExpression(); } else if (sourceItemId instanceof DragDropBean) { source = ((DragDropBean) sourceItemId).getExpression(); } String newValue = parameter.getValue() + source; parameter.setValue(newValue); parameter.focus(); } }); return wrapper; }
private void createInputForm() { setCaption(action.getCaption()); setWidth(WINDOW_WIDTH); setMargin(true); setSpacing(true); final Form inputForm = new Form(); inputForm.setWidth(INPUT_FORM_WIDTH); addComponent(inputForm); inputForm.setImmediate(true); inputForm.setWriteThrough(false); final InstantiationData instData = new InstantiationData(metaInstance, containerInstance.identity().name(), false, "", ""); final BeanItem<InstantiationData> instItem = new BeanItem<InstantiationData>(instData); inputForm.setItemDataSource(instItem); inputForm.setVisibleItemProperties(InstantiationData.getDisplayOrder()); // drop handler final DragAndDropWrapper targetWrapper = new DragAndDropWrapper(inputForm); targetWrapper.setWidth(WINDOW_WIDTH); targetWrapper.setHeight("100%"); targetWrapper.setDropHandler( new DropHandler() { public void drop(final DragAndDropEvent event) { final DataBoundTransferable t = (DataBoundTransferable) event.getTransferable(); final TreeNode node = (TreeNode) t.getData("itemId"); if (SetType.isSemanticDomainNode(node.getSet())) { instData.setIdentity(node.getSet()); inputForm.getField(InstantiationData.NAME).requestRepaint(); inputForm.getField(InstantiationData.PLURAL_NAME).requestRepaint(); inputForm.setComponentError(null); } else { inputForm .getItemDataSource() .getItemProperty(InstantiationData.METAINSTANCE) .setValue(node.getSet()); inputForm.getField(InstantiationData.METAINSTANCE_NAME).requestRepaint(); } } public AcceptCriterion getAcceptCriterion() { return AcceptAll.get(); } }); addComponent(targetWrapper); final HorizontalLayout okbar = new HorizontalLayout(); okbar.setSpacing(true); okbar.setHeight(BUTTON_BAR_HEIGHT); inputForm.getFooter().addComponent(okbar); for (final String key : InstantiationData.getDisplayOrder()) { inputForm.getField(key).setWidth(FIELD_WIDTH); } final Button okBtn = new Button( OK_BUTTON_TEXT, new Button.ClickListener() { public void buttonClick(final ClickEvent event) { // create a new instance inputForm.commit(); if (!checkForEmptyInstances(instData)) { Set s = null; String msgCaption = ""; if (action.equals(TreeActionHandler.ACTION_ADD)) { msgCaption = INSTANCE_ADDITION_MSG; if (instData.isAbstract()) {; s = containerInstance.addAbstract( instData.getMetaInstance(), instData.getIdentity()); } else { s = containerInstance.addConcrete( instData.getMetaInstance(), instData.getIdentity()); } } else if (action.equals(TreeActionHandler.ACTION_INSTANTIATE)) { msgCaption = INSTANCE_INSTANTIATION_MSG; if (instData.isAbstract()) { s = Instantiation.instantiateAbstract(metaInstance, instData.getIdentity()); } else { s = Instantiation.instantiateConcrete(metaInstance, instData.getIdentity()); } } if (s != null && s.identity().name().equals(instData.getName())) { parent.getMainApplication().getMainWindow().showNotification(msgCaption); ((org.s23m.cell.editor.semanticdomain.Editor) getApplication()) .updateContainmentTree(); // changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), null, null); // changeSupport.removePropertyChangeListener(EditorController.getInstance()); parent.closeTab(VertexCreationFormLayout.this); } else { parent .getMainApplication() .getMainWindow() .showNotification( "Error", s.identity().name(), Notification.TYPE_ERROR_MESSAGE); } } } private boolean checkForEmptyInstances(final InstantiationData instData) { boolean gotEmptyValue = false; if (instData.getMetaInstance() == null) { inputForm.setComponentError( new UserError( DefaultFieldFactory.createCaptionByPropertyId( InstantiationData.METAINSTANCE) + " is missing.")); gotEmptyValue = true; } if (instData.getIdentity() == null) { inputForm.setComponentError( new UserError( DefaultFieldFactory.createCaptionByPropertyId(InstantiationData.IDENTITY) + " is missing.")); gotEmptyValue = true; } return gotEmptyValue; } }); final Button closeBtn = new Button( CANCEL_BUTTON_TEXT, new Button.ClickListener() { public void buttonClick(final ClickEvent event) { inputForm.discard(); ((org.s23m.cell.editor.semanticdomain.Editor) getApplication()) .updateContainmentTree(); // changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), // null, null); changeSupport.removePropertyChangeListener(EditorController.getInstance()); parent.closeTab(VertexCreationFormLayout.this); } }); okbar.addComponent(okBtn); okbar.addComponent(closeBtn); okbar.setComponentAlignment(closeBtn, Alignment.TOP_RIGHT); }