KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ojb > tools > mapping > reversedb2 > ojbmetatreemodel > OjbMetaTreeNodesDragWorker


1 /* Copyright 2002-2005 The Apache Software Foundation
2  *
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */

15
16 package org.apache.ojb.tools.mapping.reversedb2.ojbmetatreemodel;
17
18 import org.apache.ojb.tools.mapping.reversedb2.dnd2.*;
19 import java.awt.Component JavaDoc;
20 import java.awt.datatransfer.Transferable JavaDoc;
21 import java.awt.Image JavaDoc;
22 import org.apache.ojb.broker.metadata.AttributeDescriptorBase;
23 /**
24  *
25  * @author Florian Bruckner
26  */

27 public class OjbMetaTreeNodesDragWorker implements DragCopyCutWorkerInterface
28 {
29     
30     /** Creates a new instance of OjbMetaTreeNodesDragWorker */
31     public OjbMetaTreeNodesDragWorker()
32     {
33     }
34     
35     /** Is called to notify you that the export this Worker has been notified of
36      * has finished. action shows you which action has been performed, e.g. if it
37      * is DRAG_MOVE you can remove the dragged items from your model.
38      * @param c The component that acts as the drag source
39      * @param action The drag action that has been performed
40      *
41      */

42     public void exportDone(Component JavaDoc c, int action)
43     {
44     }
45     
46     /** Is called to notify you that the export has started. This is always
47      * called after getTransferable, so you should know which items are exported.
48      * This method is currently not called by the framework, but may be in future.
49      * @param c The component that acts as the drag source
50      * @param action The drag action that is going to be performed
51      *
52      */

53     public void exportStarted(Component JavaDoc c, int action)
54     {
55     }
56     
57     /** Return a bitmask of acceptable actions. In most cases you will only support
58      * DRAG_COPY, but sometimes you might support DRAG_LINK or DRAG_MOVE as well.
59      * @param c The component that acts as the drag source
60      * @return A bitmask of possible drag actions for the given Component
61      *
62      */

63     public int getAcceptableActions(Component JavaDoc c)
64     {
65         if (c instanceof javax.swing.JTree JavaDoc
66             && ((javax.swing.JTree JavaDoc)c).getModel() instanceof OjbMetaDataTreeModel)
67             return DnDWorkerConstants.DRAG_COPY | DnDWorkerConstants.DRAG_LINK;
68         else return DnDWorkerConstants.NONE;
69     }
70     
71     /** DnD on some platforms supports displaying a drag image in addition
72      * to the drag cursor (Windows is known not to support it, so if you are
73      * on Windows you might be doing all right, but still see no image)
74      * @return an Image that shall be displayed with the cursor.
75      * @param c The component that acts as the drag source
76      * @param t The transferable that is used in this DnD process
77      * @param action The currently requested action for the ongoing drag process
78      *
79      */

80     public Image JavaDoc getDragImage(Component JavaDoc c, Transferable JavaDoc t, int action)
81     {
82         return null;
83     }
84     
85     /** Return a Transferable with the data you whish to export. You also get
86      * the Component the DnD actions has been started for. If the component
87      * supports selection you must first check which items are selected and
88      * afterwards put those items in the Transferable.
89      * @param c The component that acts as the drag source
90      * @return a Transferable containing the exported data
91      *
92      */

93     public Transferable JavaDoc getTransferable(Component JavaDoc c)
94     {
95         if (c instanceof javax.swing.JTree JavaDoc
96             && ((javax.swing.JTree JavaDoc)c).getModel() instanceof OjbMetaDataTreeModel)
97         {
98             try
99             {
100                 javax.swing.JTree JavaDoc tree = (javax.swing.JTree JavaDoc)c;
101                 OjbMetaDataTreeModel model = (OjbMetaDataTreeModel)tree.getModel();
102                 AttributeDescriptorBase descriptors[] = new AttributeDescriptorBase[tree.getSelectionCount()];
103                 for (int i = 0; tree.getSelectionPaths() != null && i < tree.getSelectionPaths().length; i++)
104                 {
105                     Object JavaDoc o = ((OjbMetaTreeNode)tree.getSelectionPaths()[i].getLastPathComponent()).getAssociatedDescriptor();
106                     if (o instanceof AttributeDescriptorBase)
107                     {
108                         System.err.println(" adding Node" + o);
109                         descriptors[i] = (AttributeDescriptorBase) o;
110                     }
111                 }
112                 return new OjbMetadataTransferable(descriptors);
113             }
114             catch (Throwable JavaDoc t)
115             {
116                 t.printStackTrace();
117             }
118         }
119         return null;
120     }
121     
122 }
123
Popular Tags