Example usage for com.google.gwt.user.client.ui Label addDragOverHandler

List of usage examples for com.google.gwt.user.client.ui Label addDragOverHandler

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui Label addDragOverHandler.

Prototype

public HandlerRegistration addDragOverHandler(DragOverHandler handler) 

Source Link

Usage

From source file:com.gwt2go.dev.client.ui.widget.LazySimplePanel.java

License:Apache License

@Override
protected Widget createWidget() {
    SimplePanel panel = new SimplePanel();
    VerticalPanel vrPanel = new VerticalPanel();

    final Label label = new Label("Drag me");
    label.getElement().setDraggable(Element.DRAGGABLE_TRUE);

    label.addDragStartHandler(new DragStartHandler() {

        @Override/* w  w w. ja v a  2s  .com*/
        public void onDragStart(DragStartEvent event) {
            // required
            event.setData("text", "Hello World");

            // optinal: show copy of the image
            event.getDataTransfer().setDragImage(label.getElement(), 10, 10);
        }
    });

    // some widgets do not implement drag handles
    // for that reason you can use addDomHandler()
    /* label.addDomHandler(new DragStartHandler() {
       @Override
       public void onDragStart(DragStartEvent event) {
    // required
    event.setData("text", "Hello World again;)");
            
    // optional
    event.getDataTransfer().setDragImage(label.getElement(), 10, 10);
       }
    }, DragStartEvent.getType()); */

    final Label target = new Label("Drag onto me");
    // required: you must add dragoverhandler to create a target
    target.addDragOverHandler(new DragOverHandler() {
        @Override
        public void onDragOver(DragOverEvent event) {
            target.getElement().getStyle().setBackgroundColor("#ffa");
        }
    });

    // add drop hanlder
    target.addDropHandler(new DropHandler() {
        @Override
        public void onDrop(DropEvent event) {
            // prevent the native text drop
            event.preventDefault();

            // get the data out of the event
            String data = event.getData("text");
            target.setText(data);
        }
    });

    panel.add(vrPanel);
    vrPanel.getElement().appendChild(this.nameSpan);
    vrPanel.add(label);
    vrPanel.add(target);
    return panel;
}

From source file:it.alexabbi.aproject.client.ui.second.SecondPageImpl.java

License:Open Source License

public SecondPageImpl() {
    logger.info("SecondPageImpl");
    initWidget(binder.createAndBindUi(this));

    Storage storage = Storage.getLocalStorageIfSupported();
    if (storage != null) {

        storage.setItem("a", "pippo");
    }//from  www.j a v  a  2s.c  o m

    final String valore = storage.getItem("a");

    final Label label = new Label();
    label.setText("DRAG ME");
    label.getElement().setDraggable("TRUE");
    pannello.add(label);

    label.addDragStartHandler(new DragStartHandler() {

        @Override
        public void onDragStart(DragStartEvent event) {
            event.setData("prova", "DROPPATO");
            //event.getDataTransfer().setDragImage(label, 10, 10);
        }
    });
    final Label label2 = new Label();
    label2.setText("DROP HERE");
    pannello2.add(label2);

    label2.addDragOverHandler(new DragOverHandler() {

        @Override
        public void onDragOver(DragOverEvent event) {

            //label2.getElement().setTitle("cicco");
        }
    });

    label2.addDropHandler(new DropHandler() {

        @Override
        public void onDrop(DropEvent event) {
            // TODO Auto-generated method stub
            event.preventDefault();

            String data = event.getData("prova");
            label2.setText(data);
        }
    });

}

From source file:org.wisepersist.gwt.uploader.demo.client.MultiUploadWithProgressBarAndDragAndDrop.java

License:Apache License

@Override
public Widget getUploaderPanel() {
    final VerticalPanel progressBarPanel = new VerticalPanel();
    final Map<String, ProgressBar> progressBars = new LinkedHashMap<String, ProgressBar>();
    final Map<String, Image> cancelButtons = new LinkedHashMap<String, Image>();
    uploader.setUploadURL("/upload").setButtonImageURL(AppResources.INSTANCE.upload().getSafeUri().asString())
            .setButtonWidth(133).setButtonHeight(22).setFileSizeLimit("50 MB")
            .setButtonCursor(Uploader.Cursor.HAND).setButtonAction(Uploader.ButtonAction.SELECT_FILES)
            .setFileQueuedHandler(new FileQueuedHandler() {
                public boolean onFileQueued(final FileQueuedEvent fileQueuedEvent) {
                    // Create a Progress Bar for this file
                    final ProgressBar progressBar = new ProgressBar(0.0, 1.0, 0.0,
                            new CancelProgressBarTextFormatter());
                    progressBar.setTitle(fileQueuedEvent.getFile().getName());
                    progressBar.setHeight("18px");
                    progressBar.setWidth("200px");
                    progressBars.put(fileQueuedEvent.getFile().getId(), progressBar);

                    // Add Cancel Button Image
                    final Image cancelButton = new Image(
                            AppResources.INSTANCE.cancel().getSafeUri().asString());
                    cancelButton.setStyleName("cancelButton");
                    cancelButton.addClickHandler(new ClickHandler() {
                        public void onClick(ClickEvent event) {
                            uploader.cancelUpload(fileQueuedEvent.getFile().getId(), false);
                            progressBars.get(fileQueuedEvent.getFile().getId()).setProgress(-1.0d);
                            cancelButton.removeFromParent();
                        }/*w w  w  . ja va  2 s.co m*/
                    });
                    cancelButtons.put(fileQueuedEvent.getFile().getId(), cancelButton);

                    // Add the Bar and Button to the interface
                    HorizontalPanel progressBarAndButtonPanel = new HorizontalPanel();
                    progressBarAndButtonPanel.add(progressBar);
                    progressBarAndButtonPanel.add(cancelButton);
                    progressBarPanel.add(progressBarAndButtonPanel);

                    return true;
                }
            }).setUploadProgressHandler(new UploadProgressHandler() {
                public boolean onUploadProgress(UploadProgressEvent uploadProgressEvent) {
                    ProgressBar progressBar = progressBars.get(uploadProgressEvent.getFile().getId());
                    progressBar.setProgress((double) uploadProgressEvent.getBytesComplete()
                            / uploadProgressEvent.getBytesTotal());
                    return true;
                }
            }).setUploadCompleteHandler(new UploadCompleteHandler() {
                public boolean onUploadComplete(UploadCompleteEvent uploadCompleteEvent) {
                    cancelButtons.get(uploadCompleteEvent.getFile().getId()).removeFromParent();
                    uploader.startUpload();
                    return true;
                }
            }).setFileDialogStartHandler(new FileDialogStartHandler() {
                public boolean onFileDialogStartEvent(FileDialogStartEvent fileDialogStartEvent) {
                    if (uploader.getStats().getUploadsInProgress() <= 0) {
                        // Clear the uploads that have completed, if none are in process
                        progressBarPanel.clear();
                        progressBars.clear();
                        cancelButtons.clear();
                    }
                    return true;
                }
            }).setFileDialogCompleteHandler(new FileDialogCompleteHandler() {
                public boolean onFileDialogComplete(FileDialogCompleteEvent fileDialogCompleteEvent) {
                    if (fileDialogCompleteEvent.getTotalFilesInQueue() > 0) {
                        if (uploader.getStats().getUploadsInProgress() <= 0) {
                            uploader.startUpload();
                        }
                    }
                    return true;
                }
            }).setFileQueueErrorHandler(new FileQueueErrorHandler() {
                public boolean onFileQueueError(FileQueueErrorEvent fileQueueErrorEvent) {
                    Window.alert("Upload of file " + fileQueueErrorEvent.getFile().getName()
                            + " failed due to [" + fileQueueErrorEvent.getErrorCode().toString() + "]: "
                            + fileQueueErrorEvent.getMessage());
                    return true;
                }
            }).setUploadErrorHandler(new UploadErrorHandler() {
                public boolean onUploadError(UploadErrorEvent uploadErrorEvent) {
                    cancelButtons.get(uploadErrorEvent.getFile().getId()).removeFromParent();
                    Window.alert("Upload of file " + uploadErrorEvent.getFile().getName() + " failed due to ["
                            + uploadErrorEvent.getErrorCode().toString() + "]: "
                            + uploadErrorEvent.getMessage());
                    return true;
                }
            });

    VerticalPanel verticalPanel = new VerticalPanel();
    verticalPanel.add(uploader);

    if (Uploader.isAjaxUploadWithProgressEventsSupported()) {
        final Label dropFilesLabel = new Label("Drop Files Here");
        dropFilesLabel.setStyleName("dropFilesLabel");
        dropFilesLabel.addDragOverHandler(new DragOverHandler() {
            public void onDragOver(DragOverEvent event) {
                if (!uploader.getButtonDisabled()) {
                    dropFilesLabel.addStyleName("dropFilesLabelHover");
                }
            }
        });
        dropFilesLabel.addDragLeaveHandler(new DragLeaveHandler() {
            public void onDragLeave(DragLeaveEvent event) {
                dropFilesLabel.removeStyleName("dropFilesLabelHover");
            }
        });
        dropFilesLabel.addDropHandler(new DropHandler() {
            public void onDrop(DropEvent event) {
                dropFilesLabel.removeStyleName("dropFilesLabelHover");

                if (uploader.getStats().getUploadsInProgress() <= 0) {
                    progressBarPanel.clear();
                    progressBars.clear();
                    cancelButtons.clear();
                }

                uploader.addFilesToQueue(Uploader.getDroppedFiles(event.getNativeEvent()));
                event.preventDefault();
            }
        });
        verticalPanel.add(dropFilesLabel);
    }

    HorizontalPanel horizontalPanel = new HorizontalPanel();
    horizontalPanel.add(verticalPanel);
    horizontalPanel.add(progressBarPanel);
    horizontalPanel.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE);
    horizontalPanel.setCellHorizontalAlignment(uploader, HorizontalPanel.ALIGN_LEFT);
    horizontalPanel.setCellHorizontalAlignment(progressBarPanel, HorizontalPanel.ALIGN_RIGHT);
    return horizontalPanel;
}