2

I have a problem with the browser behaviour to drop files. I have a "ContentPanel" which contains a file drag and drop area. when I drag and drop a file there everything is ok but when I drop the file in some other place inside of the "ContentPanel", the browser opens the file (behaviour by default).

How can I avoid this? Nothing should happens in this last case.

2
  • 1
    If you solved your problem, please post the solution as an answer instead of editing it into the question.
    – Ral Zarek
    Jan 24, 2013 at 15:56
  • 1
    Yup,in addition to what @RalZarek said, mark your answer as 'accepted'. That's the way we do 'SOLVED' here :-) Jan 24, 2013 at 15:59

1 Answer 1

2

It is necessary 2 drop handlers, one for the content panel and other for drag and drop area.

public FileUploadWidget() {

    RootPanel rootPanel = RootPanel.get();
    DropHandler dropHandlerRoot = new DropHandler(rootPanel);

    dropHandlerRoot.addFileEventHandler(new FileEventHandler() {
        @Override
        public void onFiles(FileEvent event) {
            // Nothing to do, avoid the default browser 
            // behaviour which is to open the file
        }
    });

    // Drag and drop area handler
    dropHandler = new DropHandler(dragAndDropArea);
    dropHandler.addFileEventHandler(new FileEventHandler() {
        @Override
        public void onFiles(FileEvent event) {
            JsArray<File> files = event.getFiles();

            for (int i = 0; i < files.length(); ++i) {
                File file = files.get(i);
                addFile(file);
                handleSizeChange();
            }
        }
    });
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.