KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > clif > scenario > util > isac > gui > tree > dnd > ScenarioTreeDragListener


1 /*
2 * CLIF is a Load Injection Framework
3 * Copyright (C) 2004 France Telecom R&D
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 * CLIF
20 *
21 * Contact: clif@objectweb.org
22 */

23 package org.objectweb.clif.scenario.util.isac.gui.tree.dnd;
24
25 import org.apache.log4j.Category;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27 import org.eclipse.jface.viewers.StructuredViewer;
28 import org.eclipse.swt.dnd.DND;
29 import org.eclipse.swt.dnd.DragSourceAdapter;
30 import org.eclipse.swt.dnd.DragSourceEvent;
31 import org.objectweb.clif.scenario.util.isac.util.tree.Node;
32 import org.objectweb.clif.scenario.util.isac.util.tree.ScenarioNode;
33 import org.objectweb.clif.scenario.util.isac.util.tree.TreeManager;
34
35 /**
36  * Supports dragging ScenarioNodes from a structured viewer
37  *
38  * @author JC Meillaud
39  * @author A Peyrard
40  */

41 public class ScenarioTreeDragListener extends DragSourceAdapter {
42     static Category cat = Category.getInstance(ScenarioTreeDragListener.class.getName());
43     private StructuredViewer viewer ;
44     private TreeManager treeManager ;
45
46     /**
47      * Constructor
48      * @param viewer The viewer where listen
49      */

50     public ScenarioTreeDragListener(StructuredViewer viewer) {
51         cat.debug("-> constructor") ;
52         this.viewer = viewer;
53         // get the instance of the tree manager
54
this.treeManager = TreeManager.getTreeManager(null) ;
55     }
56
57     /**
58      * Method declared on DragSourceListener
59      * @param event The event source
60      */

61     public void dragFinished(DragSourceEvent event) {
62         cat.debug("-> dragFinished") ;
63         if (!event.doit)
64             return;
65         // if the node was moved, remove it from the source viewer
66
if (event.detail == DND.DROP_MOVE) {
67             IStructuredSelection selection =
68                 (IStructuredSelection) viewer.getSelection();
69             ScenarioNode tree = (ScenarioNode) selection.getFirstElement();
70             this.treeManager.deleteBehaviorsTreeNode(tree) ;
71             viewer.refresh();
72         }
73     }
74     
75     /**
76      * Method declared on DragSourceListener
77      * @param event The event source
78      */

79     public void dragSetData(DragSourceEvent event) {
80         cat.debug("-> dragSetData") ;
81         IStructuredSelection selection =
82             (IStructuredSelection) viewer.getSelection();
83         ScenarioNode tree = (ScenarioNode) selection.getFirstElement();
84         if (ScenarioTreeTransfer
85             .getInstance()
86             .isSupportedType(event.dataType)) {
87             event.data = tree;
88         }
89     }
90     
91     /**
92      * Method declared on DragSourceListener
93      * @param event The event source
94      */

95     public void dragStart(DragSourceEvent event) {
96         cat.debug("-> dragStart") ;
97         IStructuredSelection selection =
98             (IStructuredSelection) viewer.getSelection();
99         if (selection.size() == 1) {
100             String JavaDoc type = (String JavaDoc)this.treeManager.getNodeType((ScenarioNode)selection.getFirstElement()) ;
101             // can not be a behavior or a plugins node...
102
if (!Node.isStructureNode(type)) {
103                 event.doit = true;
104                 return;
105             }
106         }
107         event.doit = false;
108     }
109 }
110
Popular Tags