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