Example usage for com.vaadin.ui DragAndDropWrapper DragAndDropWrapper

List of usage examples for com.vaadin.ui DragAndDropWrapper DragAndDropWrapper

Introduction

In this page you can find the example usage for com.vaadin.ui DragAndDropWrapper DragAndDropWrapper.

Prototype

public DragAndDropWrapper(Component root) 

Source Link

Document

Wraps given component in a DragAndDropWrapper .

Usage

From source file:org.s23m.cell.editor.semanticdomain.ui.components.layout.LinkCreationFormLayout.java

License:Mozilla Public License

public void initLayout() {
    setCaption(action.getCaption());//from  ww  w  . j  a  v  a  2 s .c o m
    // main window layout
    setWidth(FULL_SIZE);
    setMargin(true);
    setSpacing(true);
    final Form inputForm = new Form();
    inputForm.setReadOnly(true);
    inputForm.setWidth(INPUT_FORM_WIDTH);
    addComponent(inputForm);
    inputForm.setImmediate(true);
    inputForm.setWriteThrough(false);

    // set up form data binding
    final LinkData linkData = new LinkData(fromInstance);
    linkData.setToInstance(S23MKernel.coreGraphs.vertex); //default target instance
    final BeanItem<LinkData> item = new BeanItem<LinkData>(linkData);
    inputForm.setItemDataSource(item);
    inputForm.setVisibleItemProperties(LinkData.getDisplayedInstances());
    final HorizontalLayout buttonBarLayout = new HorizontalLayout();
    buttonBarLayout.setSpacing(true);
    buttonBarLayout.setHeight(BUTTON_BAR_HEIGHT);
    inputForm.getFooter().addComponent(buttonBarLayout);

    for (final String key : LinkData.getDisplayedInstances()) {
        inputForm.getField(key).setWidth(FIELD_WIDTH);
    }

    // drop handler
    final DragAndDropWrapper targetWrapper = new DragAndDropWrapper(inputForm);
    targetWrapper.setWidth(FULL_SIZE);
    targetWrapper.setHeight(FULL_SIZE);

    targetWrapper.setDropHandler(new DropHandler() {

        public void drop(final DragAndDropEvent event) {
            final DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
            final TreeNode node = (TreeNode) t.getData("itemId");
            inputForm.getItemDataSource().getItemProperty(LinkData.TO_INSTANCE).setValue(node.getSet());
            inputForm.getField(LinkData.TARGET).requestRepaint();
        }

        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });
    addComponent(targetWrapper);
    //parent.getMainApplication().getContainmentTreePanel().setEditMode(true);
    //add all visible instances from the fromInstance
    //parent.getMainApplication().getContainmentTreePanel().getScopeMap()
    //      .putAll(addAllVisibleInstanceUUIDs(fromInstance));
    //changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), null, null);
    //((org.s23m.cell.editor.semanticdomain.Editor)getApplication()).updateContainmentTree();

    final Button okBtn = new Button("OK", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            // create a new link instance
            final Set metaInstance = (action.equals(TreeActionHandler.ACTION_CREATE_VISIBILITY))
                    ? S23MKernel.coreGraphs.visibility
                    : S23MKernel.coreGraphs.superSetReference;
            if (action.equals(TreeActionHandler.ACTION_CREATE_VISIBILITY)
                    || action.equals(TreeActionHandler.ACTION_CREATE_SSR)) {
                final Set src = (Set) inputForm.getItemDataSource().getItemProperty(LinkData.FROM_INSTANCE)
                        .getValue();
                final Set trgt = (Set) inputForm.getItemDataSource().getItemProperty(LinkData.TO_INSTANCE)
                        .getValue();
                if (src != null && trgt != null) {
                    final Set v = Instantiation.arrow(metaInstance, src, trgt);
                    String msg = "";
                    if (!v.identity().isEqualTo(
                            S23MSemanticDomains.semanticErr_TargetIsNotWithinVisibility.identity())) {
                        inputForm.commit();
                        msg = "Successfully created a new link";
                        parent.getMainApplication().getMainWindow().showNotification(msg);
                        ((org.s23m.cell.editor.semanticdomain.Editor) getApplication()).updateContainmentTree();
                        parent.closeTab(LinkCreationFormLayout.this);
                    } else {
                        msg = "Failed creating a visibility link: " + v.identity().name();
                        parent.getMainApplication().getMainWindow().showNotification("Error",
                                v.identity().name(), Notification.TYPE_ERROR_MESSAGE);
                    }
                    //parent.getMainApplication().getConsole().setValue(
                    //      parent.getMainApplication().getConsole().getValue() + msg
                    //            + "\n");
                }
            }
            //parent.getMainApplication().getContainmentTreePanel().setEditMode(false);
            //parent.getMainApplication().getContainmentTreePanel().getScopeMap().clear();
            //changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), null, null);
        }
    });

    final Button closeBtn = new Button("Cancel", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            inputForm.discard();
            parent.getMainApplication().getContainmentTreePanel().setEditMode(false);
            parent.getMainApplication().getContainmentTreePanel().getScopeMap().clear();
            ((org.s23m.cell.editor.semanticdomain.Editor) getApplication()).updateContainmentTree();
            //changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), null, null);
            //changeSupport.removePropertyChangeListener(EditorController.getInstance());
            parent.closeTab(LinkCreationFormLayout.this);
        }
    });

    buttonBarLayout.addComponent(okBtn);
    buttonBarLayout.addComponent(closeBtn);
    buttonBarLayout.setComponentAlignment(closeBtn, Alignment.TOP_RIGHT);
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.layout.SemanticInstanceCreationFormLayout.java

License:Mozilla Public License

private void initLayout() {
    setCaption(action.getCaption());/*  w w  w.  ja  v a 2s.  c o  m*/
    setWidth(FULL_SIZE);
    setMargin(true);
    setSpacing(true);

    final Form inputForm = new Form();
    inputForm.setReadOnly(true);
    inputForm.setWidth(INPUT_FORM_WIDTH);
    addComponent(inputForm);
    inputForm.setImmediate(true);
    inputForm.setWriteThrough(false);

    inputForm.setFormFieldFactory(new FormFieldFactory() {
        public Field createField(final Item item, final Object propertyId, final Component uiContext) {
            final String textLabel = DefaultFieldFactory.createCaptionByPropertyId(propertyId);
            final TextField f = new TextField(textLabel);
            if (propertyId.toString().equals(SemanticInstanceData.REFERENCED_SEMANTIC_IDENTITY_NAME)) {
                f.setRequiredError(textLabel + " is a mandatory field.");
                f.setRequired(true);
            }
            if (action.equals(TreeActionHandler.ACTION_ADD_SEMANTIC_DOMAIN)) {
                if (propertyId.toString().equals(SemanticInstanceData.NAME)) {
                    f.setRequiredError(textLabel + " is a mandatory field.");
                    f.setRequired(true);
                }
            }
            return f;
        }
    });

    //set up form data binding
    final SemanticInstanceData formData = new SemanticInstanceData("", "", containerInstnace);
    final BeanItem<SemanticInstanceData> item = new BeanItem<SemanticInstanceData>(formData);
    inputForm.setItemDataSource(item);
    if (action.equals(TreeActionHandler.ACTION_ADD_SEMANTIC_ROLE)) {
        inputForm.setVisibleItemProperties(SemanticInstanceData.getDisplayedInstancesForSemanticRole());
    } else {
        inputForm.setVisibleItemProperties(SemanticInstanceData.getDisplayedInstances());
    }

    // drop handler
    final DragAndDropWrapper targetWrapper = new DragAndDropWrapper(inputForm);
    targetWrapper.setWidth(INPUT_FORM_WIDTH);
    targetWrapper.setHeight(INPUT_FORM_WIDTH);

    targetWrapper.setDropHandler(new DropHandler() {

        public void drop(final DragAndDropEvent event) {
            final DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
            final TreeNode node = (TreeNode) t.getData("itemId");
            inputForm.getItemDataSource().getItemProperty(SemanticInstanceData.REFERENCED_SEMANTIC_IDENTITY)
                    .setValue(node.getSet());
            inputForm.getField(SemanticInstanceData.REFERENCED_SEMANTIC_IDENTITY_NAME).requestRepaint();
        }

        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }
    });

    addComponent(targetWrapper);

    final HorizontalLayout buttonBarLayout = new HorizontalLayout();
    buttonBarLayout.setSpacing(true);
    buttonBarLayout.setHeight(BUTTON_BAR_HEIGHT);
    inputForm.getFooter().addComponent(buttonBarLayout);

    final Button okBtn = new Button("OK", new Button.ClickListener() {
        public void buttonClick(final ClickEvent event) {
            try {
                if (action.equals(TreeActionHandler.ACTION_ADD_SEMANTIC_IDENTITY)) {
                    inputForm.commit();
                    if (isAnonymousData(formData)) {
                        Instantiation.addAnonymousDisjunctSemanticIdentitySet(formData.getSemanticDomain());
                    } else {
                        Instantiation.addDisjunctSemanticIdentitySet(formData.getName(),
                                formData.getPluralName(), formData.getSemanticDomain());
                    }
                    closeOperation("New semantic identity is created");
                } else if (action.equals(TreeActionHandler.ACTION_ADD_SEMANTIC_DOMAIN)) {
                    inputForm.commit();
                    if (!isAnonymousData(formData)) {
                        Instantiation.addSemanticDomain(formData.getName(), formData.getPluralName(),
                                formData.getSemanticDomain());
                        closeOperation("New semantic domain is created");
                    }
                } else if (action.equals(TreeActionHandler.ACTION_ADD_SEMANTIC_ROLE)) {
                    inputForm.commit();
                    if (formData.getReferencedSemanticIdentity() != null) {
                        F_Transaction.commitChangedSets();
                        log.info("Changeset size " + org.s23m.cell.api.Query.changedSets().size());

                        if (isAnonymousData(formData)) {
                            final Set r = Instantiation.addAnonymousSemanticRole(formData.getSemanticDomain(),
                                    formData.getReferencedSemanticIdentity());
                            log.info("AnonymousSemanticRole " + r.identity().uniqueRepresentationReference()
                                    + " created.");
                        } else {
                            final Set r = Instantiation.addSemanticRole(formData.getName(),
                                    formData.getPluralName(), formData.getSemanticDomain(),
                                    formData.getReferencedSemanticIdentity());
                            log.info("Semantic role " + r.identity().name() + " created.");
                        }

                        log.info("Changeset size after creation "
                                + org.s23m.cell.api.Query.changedSets().size());
                        closeOperation("New semantic role is created");
                    } else {
                        parentTab.getMainApplication().getMainWindow().showNotification(
                                "Missing referenced semantic identity", Window.Notification.TYPE_ERROR_MESSAGE);
                    }
                }
            } catch (final EmptyValueException th) {
            }
        }

        private void closeOperation(final String message) {
            parentTab.getMainApplication().getMainWindow().showNotification(message);
            ((Editor) getApplication()).updateContainmentTree();
            //changeSupport.firePropertyChange(EditorEvents.CHANGESET_MODIFIED.getEventName(), null, null);
            //changeSupport.removePropertyChangeListener(EditorController.getInstance());
            parentTab.closeTab(SemanticInstanceCreationFormLayout.this);
        }
    });

    final Button cancelBtn = new Button("Cancel", 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());
            parentTab.closeTab(SemanticInstanceCreationFormLayout.this);
        }
    });

    buttonBarLayout.addComponent(okBtn);
    buttonBarLayout.addComponent(cancelBtn);
    buttonBarLayout.setComponentAlignment(cancelBtn, Alignment.TOP_RIGHT);

}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.layout.VertexCreationFormLayout.java

License:Mozilla Public License

private void createInputForm() {
    setCaption(action.getCaption());//from w  ww .  j a  v  a  2  s  . c o m
    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);
}

From source file:org.vaadin.alump.masonry.DnDMasonryLayout.java

License:Apache License

/**
 * Create DnD wrapper for component if not yet defined
 * @param component Component wrapped/*from w  ww  .  j a  v a2 s .c o  m*/
 * @return Wrapper made or found
 */
protected DragAndDropWrapper createComponentDnDWrapper(Component component, String wrapperStyleName) {
    DragAndDropWrapper wrapper = getComponentDnDWrapper(component);
    if (wrapper == null) {
        wrapper = new DragAndDropWrapper(component);
        wrapper.addStyleName("masonry-dnd-wrapper");
        if (wrapperStyleName != null) {
            wrapper.addStyleName(wrapperStyleName);
        }
        wrapper.setDragStartMode(allowReorder ? getComponentDragStartMode() : DragStartMode.NONE);
        wrapper.setDropHandler(createDropHandlerForComponents(wrapper));
    }
    return wrapper;
}

From source file:org.vaadin.easyuploads.MultiFileUploadExt.java

License:Open Source License

/**
 * Sets up DragAndDropWrapper to accept multi file drops.
 *//* w  w w .ja v a2 s . c o  m*/
private void prepareDropZone() {
    if (dropZone == null) {
        Component label = new Label(getAreaText(), ContentMode.HTML);
        label.setSizeUndefined();
        dropZone = new DragAndDropWrapper(label);
        dropZone.setStyleName("v-multifileupload-dropzone");
        dropZone.setSizeUndefined();
        addComponent(dropZone, 1);
        dropZone.setDropHandler(this);
        addStyleName("no-horizontal-drag-hints");
        addStyleName("no-vertical-drag-hints");
    }
}

From source file:v7cr.vaadin.V7MultiFileUpload.java

License:Open Source License

/**
 * Sets up DragAndDropWrapper to accept multi file drops.
 *//*www .  j a va2 s.  co m*/
private void prepareDropZone() {
    if (dropZone == null) {
        Component label = new Label(getAreaText(), Label.CONTENT_XHTML);
        label.setSizeUndefined();
        dropZone = new DragAndDropWrapper(label);
        dropZone.setStyleName("v-multifileupload-dropzone");
        dropZone.setSizeUndefined();
        addComponent(dropZone, 1);
        dropZone.setDropHandler(this);
        addStyleName("no-horizontal-drag-hints");
        addStyleName("no-vertical-drag-hints");
    }
}