@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;
  }
Example #2
0
 @Override
 protected boolean validateDragAndDropWrapper(final DragAndDropWrapper wrapperSource) {
   final String tagData = wrapperSource.getData().toString();
   if (wrapperSource.getId().startsWith(SPUIDefinitions.DISTRIBUTION_TAG_ID_PREFIXS)) {
     return !isNoTagButton(tagData, SPUIDefinitions.DISTRIBUTION_TAG_BUTTON);
   } else if (wrapperSource.getId().startsWith(SPUIDefinitions.TARGET_TAG_ID_PREFIXS)) {
     return !isNoTagButton(tagData, SPUIDefinitions.TARGET_TAG_BUTTON);
   }
   uiNotification.displayValidationError(notAllowedMsg);
   return false;
 }
 public void clearMenuSelection(HorizontalLayout menu) {
   for (Iterator<Component> it = menu.getComponentIterator(); it.hasNext(); ) {
     Component next = it.next();
     if (next instanceof NativeButton) {
       next.removeStyleName("selected");
     } else if (next instanceof DragAndDropWrapper) {
       // Wow, this is ugly (even uglier than the rest of the code)
       ((DragAndDropWrapper) next).iterator().next().removeStyleName("selected");
     }
   }
 }
Example #4
0
 @Override
 public void attach() {
   reload();
   super.attach();
 }
  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);
  }