01: /*
02: * FieldsTableTransferHandler.java
03: *
04: * Created on May 15, 2007, 4:31:24 PM
05: *
06: * To change this template, choose Tools | Template Manager
07: * and open the template in the editor.
08: */
09:
10: package it.businesslogic.ireport.gui.dnd;
11:
12: import it.businesslogic.ireport.JRField;
13: import java.awt.datatransfer.DataFlavor;
14: import java.awt.datatransfer.Transferable;
15: import java.awt.datatransfer.UnsupportedFlavorException;
16: import java.io.IOException;
17: import javax.swing.JComponent;
18: import javax.swing.TransferHandler;
19:
20: /**
21: *
22: * @author gtoffoli
23: */
24: public class FieldsContainerTransferHandler extends TransferHandler {
25:
26: private FieldsContainer fieldsContainer = null;
27:
28: public FieldsContainer getFieldsContainer() {
29: return fieldsContainer;
30: }
31:
32: public void setFieldsContainer(FieldsContainer fieldsContainer) {
33: this .fieldsContainer = fieldsContainer;
34: }
35:
36: public FieldsContainerTransferHandler(
37: FieldsContainer fieldsContainer) {
38: this .fieldsContainer = fieldsContainer;
39: }
40:
41: public boolean importData(JComponent c, Transferable t) {
42: if (canImport(c, t.getTransferDataFlavors())) {
43: try {
44:
45: JRField field = (JRField) t.getTransferData(t
46: .getTransferDataFlavors()[0]);
47:
48: if (fieldsContainer != null) {
49: fieldsContainer.addField(field);
50: }
51:
52: return true;
53: } catch (UnsupportedFlavorException ufe) {
54: } catch (IOException ioe) {
55: }
56: }
57:
58: return false;
59: }
60:
61: public boolean canImport(JComponent c, DataFlavor[] flavors) {
62:
63: for (int i = 0; i < flavors.length; i++) {
64: if (flavors[i]
65: .getMimeType()
66: .equals(
67: "application/x-java-serialized-object; class=it.businesslogic.ireport.JRField")) {
68: return true;
69: }
70: }
71: return false;
72: }
73:
74: }
|