]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.ui/src/org/simantics/ui/DoubleClickEvent.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.ui / src / org / simantics / ui / DoubleClickEvent.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
3  * in Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.ui;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collections;\r
16 import java.util.EventObject;\r
17 import java.util.List;\r
18 \r
19 import org.eclipse.jface.action.IAction;\r
20 import org.simantics.db.ReadGraph;\r
21 import org.simantics.utils.datastructures.hints.HintContext;\r
22 import org.simantics.utils.ui.action.IPriorityAction;\r
23 import org.simantics.utils.ui.action.PriorityActionAdapter;\r
24 \r
25 /**\r
26  * TODO: multiple selection support\r
27  * \r
28  * @author Tuukka Lehtonen\r
29  */\r
30 public class DoubleClickEvent extends EventObject {\r
31 \r
32     private static final long     serialVersionUID = 1730213767249571862L;\r
33 \r
34     private boolean               consumed         = false;\r
35 \r
36     private final ReadGraph       graph;\r
37 \r
38     private final Object          resource;\r
39 \r
40     private List<IPriorityAction> actions          = new ArrayList<IPriorityAction>();\r
41 \r
42     private HintContext           hintContext      = new HintContext();\r
43 \r
44     public DoubleClickEvent(Object source, ReadGraph g, Object resource) {\r
45         super(source);\r
46         this.graph = g;\r
47         this.resource = resource;\r
48     }\r
49 \r
50     public ReadGraph getGraph() {\r
51         return graph;\r
52     }\r
53 \r
54     public Object getResource() {\r
55         return resource;\r
56     }\r
57 \r
58     /**\r
59      * Mark the event as accepted which suppresses further double click handler\r
60      * calls.\r
61      */\r
62     public void consume() {\r
63         consumed = true;\r
64     }\r
65 \r
66     public boolean isConsumed() {\r
67         return consumed;\r
68     }\r
69 \r
70     /**\r
71      * Add a possible action with normal priority.\r
72      * \r
73      * @param action\r
74      */\r
75     public void add(IAction action) {\r
76         actions.add(new PriorityActionAdapter(IPriorityAction.NORMAL, action));\r
77     }\r
78 \r
79     /**\r
80      * Add a possible prioritized action.\r
81      * \r
82      * @param action\r
83      */\r
84     public void add(IPriorityAction action) {\r
85         actions.add(action);\r
86     }\r
87 \r
88     /**\r
89      * Only used internally by the doubleclick extension point.\r
90      * \r
91      * @return\r
92      */\r
93     public IPriorityAction[] getOrderedActions() {\r
94         List<IPriorityAction> copy = new ArrayList<IPriorityAction>(actions);\r
95         Collections.sort(copy);\r
96         return copy.toArray(new IPriorityAction[copy.size()]);\r
97     }\r
98 \r
99     public HintContext getHintContext() {\r
100         return hintContext;\r
101     }\r
102 \r
103 }\r