PageRenderTime 47ms CodeModel.GetById 41ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/mpv5/ui/misc/DatabaseObjectTransferable.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 43 lines | 32 code | 8 blank | 3 comment | 3 complexity | a680aa96fd178e56ea09d1276792ef75 MD5 | raw file
 1package mpv5.ui.misc;
 2
 3
 4import java.awt.datatransfer.DataFlavor;
 5import java.awt.datatransfer.Transferable;
 6import java.awt.datatransfer.UnsupportedFlavorException;
 7import java.io.IOException;
 8import java.util.List;
 9import mpv5.db.common.DatabaseObject;
10import mpv5.logging.Log;
11
12public class DatabaseObjectTransferable implements Transferable {
13
14    /**
15     * The drag n drop Flavor for DatabaseObjects
16     */
17    public static final DataFlavor FLAVOR = new DataFlavor(DatabaseObject[].class, "DatabaseObject Transfer");
18    private List<DatabaseObject> obj;
19
20    public DatabaseObjectTransferable(List<DatabaseObject> value) {
21        obj = value;
22    }
23
24    @Override
25    public DataFlavor[] getTransferDataFlavors() {
26        return new DataFlavor[]{FLAVOR};
27    }
28
29    @Override
30    public boolean isDataFlavorSupported(DataFlavor flavor) {
31        return flavor == FLAVOR;
32    }
33
34    @Override
35    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
36        if (isDataFlavorSupported(flavor)) {
37            Log.Debug(this, "Returning array: " + obj);
38            return obj.toArray(new DatabaseObject[0]);
39        } else {
40            throw new UnsupportedFlavorException(flavor);
41        }
42    }
43}