Search in sources :

Example 6 with DropAction

use of org.apache.pivot.wtk.DropAction in project pivot by apache.

the class JSONViewer method drop.

public DropAction drop(Manifest dragContent) {
    DropAction dropAction = null;
    try {
        FileList fileList = dragContent.getFileList();
        if (fileList.getLength() == 1) {
            File file = fileList.get(0);
            JSONSerializer jsonSerializer = new JSONSerializer();
            @SuppressWarnings("resource") FileInputStream fileInputStream = null;
            try {
                try {
                    fileInputStream = new FileInputStream(file);
                    setValue(jsonSerializer.readObject(fileInputStream));
                } finally {
                    if (fileInputStream != null) {
                        fileInputStream.close();
                    }
                }
            } catch (Exception exception) {
                Prompt.prompt(exception.getMessage(), window);
            }
            window.setTitle(WINDOW_TITLE + " - " + file.getName());
            dropAction = DropAction.COPY;
        } else {
            Prompt.prompt("Multiple files not supported.", window);
        }
    } catch (IOException exception) {
        Prompt.prompt(exception.getMessage(), window);
    }
    return dropAction;
}
Also used : FileList(org.apache.pivot.io.FileList) DropAction(org.apache.pivot.wtk.DropAction) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException) JSONSerializer(org.apache.pivot.json.JSONSerializer)

Aggregations

IOException (java.io.IOException)6 DropAction (org.apache.pivot.wtk.DropAction)6 FileList (org.apache.pivot.io.FileList)4 Component (org.apache.pivot.wtk.Component)4 DropTarget (org.apache.pivot.wtk.DropTarget)4 Manifest (org.apache.pivot.wtk.Manifest)4 File (java.io.File)3 DragSource (org.apache.pivot.wtk.DragSource)3 LocalManifest (org.apache.pivot.wtk.LocalManifest)3 Point (org.apache.pivot.wtk.Point)3 FileInputStream (java.io.FileInputStream)2 Button (org.apache.pivot.wtk.Button)2 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)2 PushButton (org.apache.pivot.wtk.PushButton)2 Visual (org.apache.pivot.wtk.Visual)2 Image (org.apache.pivot.wtk.media.Image)2 Font (java.awt.Font)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 Sequence (org.apache.pivot.collections.Sequence)1 JSONSerializer (org.apache.pivot.json.JSONSerializer)1