2

We are creating a web application using Vaadin. Our application contains alot of drag and drop features.

We have an object which is drag-able. We can click on it to open its menu as well.

Sometimes that when we click that item it behaves as if it is dragged. When this happens we are unable to open its menu because the component is in dragmode.

All components with the same functionality behave the same however in development environment, when we restart the tomcat the problem disappeared?

I noticed that when the components start showing me this behavior the webpage in FireFox the behavior is fine there?

Kevvvvyp
  • 1,704
  • 2
  • 18
  • 38
SSH
  • 1,609
  • 2
  • 22
  • 42
  • Did my answer help you at all? – Kevvvvyp Apr 27 '15 at 09:05
  • hey @KevinPaton actually I am busy with some other stuff but actually putting another button for drag mode doesn't suits us , but really unable to find the real issue until now , why this is happening.... – SSH Apr 28 '15 at 08:28
  • Yeah I know its not ideal, I'm facing a similar situation at the moment. Hope you get a fix! – Kevvvvyp Apr 28 '15 at 08:38
  • @KevinPaton thnx for your effort...but as you are facing the same so is that some Vaadin's bug ?or at ours end – SSH Apr 28 '15 at 08:41

1 Answers1

0

A simple solution to this could be to introduce a drag mode/edit button which would allow the user to switch the drag mode on and off.

This would mean the user could interact with the components and then enter this "drag mode" when they wished to drag them. Hence reducing the frustration of trying to interact with the component and it starting to "drag" instead.

I've create a simple example program to try out below.

public class DemoUI extends UI {

    HorizontalSplitPanel splitPanel;
    DragAndDropWrapper wrapperA;
    DragAndDropWrapper wrapperB;

    DragAndDropWrapper splitPaneWrapper;
    Button buttonA;
    Button buttonB;
    private boolean isDragMode = false;

    @WebServlet(value = "/*", asyncSupported = true)
    @VaadinServletConfiguration(productionMode = false, ui = DemoUI.class)
    public static class Servlet extends VaadinServlet {
    }

    @Override
    protected void init(VaadinRequest request) {

        final HorizontalSplitPanel splitPanel = new HorizontalSplitPanel();

        Button buttonA = new Button("Button A");
        Button buttonB = new Button("Button B");

        final DragAndDropWrapper wrapperA = new DragAndDropWrapper(buttonA);
        final DragAndDropWrapper wrapperB = new DragAndDropWrapper(buttonB);

        final VerticalLayout leftPanel = new VerticalLayout();
        final VerticalLayout rightPanel = new VerticalLayout();

        DragAndDropWrapper leftPanelWrapper = new DragAndDropWrapper(leftPanel);
        DragAndDropWrapper rightPanelWrapper = new     DragAndDropWrapper(rightPanel);

        buttonA.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                Notification.show("Button A was clicked");

            }

        });

        buttonB.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                Notification.show("Button B was clicked");

            }

        });

        leftPanelWrapper.setDropHandler(new DropHandler() {

            @Override
            public void drop(DragAndDropEvent event) {
                leftPanel.addComponent(event.getTransferable().getSourceComponent());

            }

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

        });

        rightPanelWrapper.setDropHandler(new DropHandler() {

            @Override
            public void drop(DragAndDropEvent event) {
                rightPanel.addComponent(event.getTransferable().getSourceComponent());

            }

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

        });

        final Button dragMode = new Button("Drag Mode On");

        dragMode.addClickListener(new ClickListener() {

            @Override
            public void buttonClick(ClickEvent event) {
                isDragMode = !isDragMode;
                if (isDragMode) {
                    dragMode.setCaption("Drag Mode Off");
                    wrapperA.setDragStartMode(DragStartMode.WRAPPER);
                    wrapperB.setDragStartMode(DragStartMode.WRAPPER);
                } else {
                    dragMode.setCaption("Drag Mode On");
                    wrapperA.setDragStartMode(DragStartMode.NONE);
                    wrapperB.setDragStartMode(DragStartMode.NONE);
                }

            }

        });

        leftPanel.setSizeFull();
        rightPanel.setSizeFull();
        leftPanelWrapper.setSizeFull();
        rightPanelWrapper.setSizeFull();

        leftPanel.addComponent(wrapperA);
        rightPanel.addComponent(wrapperB);

        splitPanel.setFirstComponent(leftPanelWrapper);
        splitPanel.setSecondComponent(rightPanelWrapper);
        splitPanel.setSizeFull();

        VerticalLayout layout = new VerticalLayout();
        layout.addComponent(dragMode);
        layout.addComponent(splitPanel);
        layout.setSizeFull();

        this.setContent(layout);
        this.setSizeFull();
}

. Program screen shot

All the best.

Kevvvvyp
  • 1,704
  • 2
  • 18
  • 38