Example usage for com.vaadin.ui DragAndDropWrapper setDropHandler

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

Introduction

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

Prototype

public void setDropHandler(DropHandler dropHandler) 

Source Link

Usage

From source file:org.lucidj.browser.AbstractCell.java

License:Apache License

private Component build_left_panel() {
    left_panel = new CssLayout();
    left_panel.setWidth(32, Sizeable.Unit.PIXELS);
    left_panel.addStyleName("cell-panel-left");
    left_panel.setHeight(100, Sizeable.Unit.PERCENTAGE);

    String icon_url = "/VAADIN/~/formulas/impossible.png";
    String icon_title = "The Unknown";

    ComponentInterface component_interface = Aggregate.adapt(ComponentInterface.class, source_object);
    if (component_interface != null) {
        // If it is a valid component, displays its icon on the top left corner of the cell
        ComponentDescriptor descriptor = (ComponentDescriptor) component_interface
                .getProperty(ComponentDescriptor.DESCRIPTOR);

        if (descriptor != null) {
            icon_url = descriptor.getIconUrl();
            icon_title = descriptor.getIconTitle();
        }/*from  w  w  w . ja  v  a2  s .c  o  m*/
    }

    String component_icon_html = "<img class='component-icon' src='" + icon_url + "' title='"
            + SafeHtmlUtils.htmlEscape(icon_title) + "'/>";
    component_icon = new Label(component_icon_html, ContentMode.HTML);
    left_panel.addComponent(component_icon);

    // Put the component in a D&D wrapper and allow dragging it
    final DragAndDropWrapper panel_dd_wrap = new DragAndDropWrapper(left_panel);
    panel_dd_wrap.setDragStartMode(DragAndDropWrapper.DragStartMode.COMPONENT_OTHER);
    panel_dd_wrap.setDragImageComponent(component_icon);
    panel_dd_wrap.addStyleName("no-horizontal-drag-hints");
    panel_dd_wrap.addStyleName("no-box-drag-hints");

    // Set the wrapper to wrap tightly around the component
    panel_dd_wrap.setHeight(100, Sizeable.Unit.PERCENTAGE);
    panel_dd_wrap.setWidthUndefined();
    panel_dd_wrap.setId("test");

    // Setup DD handlers for component insertion
    panel_dd_wrap.setData(this);
    panel_dd_wrap.setDropHandler(this);

    // While left_panel is kept in order to be customized, here we return D&D wrapper
    return (panel_dd_wrap);
}

From source file:org.s23m.cell.editor.semanticdomain.ui.components.field.SetField.java

License:Mozilla Public License

private void init() {
    final VerticalLayout mainLayout = new VerticalLayout();
    final Label lbl = new Label(caption);
    mainLayout.addComponent(lbl);//from  w w w  .ja v  a  2  s.  c o m
    txtField = new TextField();
    txtField.setValue(setData.getName());
    txtField.setWidth(FIELD_WIDTH);
    setImmediate(true);
    setCompositionRoot(mainLayout);

    txtField.addListener(new Property.ValueChangeListener() {
        public void valueChange(final com.vaadin.data.Property.ValueChangeEvent event) {
            final String value = (String) txtField.getValue();
            setValue(value);
        }
    });

    // drop handler
    final DragAndDropWrapper targetWrapper = new DragAndDropWrapper(txtField);
    targetWrapper.setDropHandler(new DropHandler() {

        public void drop(final DragAndDropEvent event) {
            final DataBoundTransferable t = (DataBoundTransferable) event.getTransferable();
            final TreeNode node = (TreeNode) t.getData("itemId");
            setData.setSet(node.getSet());
            txtField.setValue(setData.getName());
            setValue(node.getSet());
            txtField.requestRepaint();
        }

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

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

License:Mozilla Public License

public void initLayout() {
    setCaption(action.getCaption());/*  w w  w .  j  a  v a2  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  . j  ava 2s  .  co  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  w  w  .j  a  va2  s  . co 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  w w. 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;
}