]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/action/PriorityAction.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.utils.ui / src / org / simantics / utils / ui / action / PriorityAction.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.utils.ui.action;\r
13 \r
14 import org.eclipse.jface.action.Action;\r
15 import org.eclipse.jface.resource.ImageDescriptor;\r
16 \r
17 /**\r
18  * Extendable implementation of {@link IPriorityAction} based on {@link Action}.\r
19  * PriorityActions are comparable by their priorities.\r
20  * \r
21  * Note: this class has a natural ordering that is inconsistent with equals.\r
22  * \r
23  * @author Tuukka Lehtonen\r
24  */\r
25 public class PriorityAction extends Action implements IPriorityAction {\r
26 \r
27     private final int priority;\r
28     \r
29     public PriorityAction() {\r
30         super();\r
31         this.priority = IPriorityAction.NORMAL;\r
32     }\r
33 \r
34     public PriorityAction(String text, ImageDescriptor image) {\r
35         super(text, image);\r
36         this.priority = IPriorityAction.NORMAL;\r
37     }\r
38 \r
39     public PriorityAction(String text, int style) {\r
40         super(text, style);\r
41         this.priority = IPriorityAction.NORMAL;\r
42     }\r
43 \r
44     public PriorityAction(String text) {\r
45         super(text);\r
46         this.priority = IPriorityAction.NORMAL;\r
47     }\r
48 \r
49     public PriorityAction(int priority) {\r
50         super();\r
51         this.priority = priority;\r
52     }\r
53 \r
54     public PriorityAction(int priority, String text, ImageDescriptor image) {\r
55         super(text, image);\r
56         this.priority = priority;\r
57     }\r
58 \r
59     public PriorityAction(int priority, String text, int style) {\r
60         super(text, style);\r
61         this.priority = priority;\r
62     }\r
63 \r
64     public PriorityAction(int priority, String text) {\r
65         super(text);\r
66         this.priority = priority;\r
67     }\r
68     \r
69     /* (non-Javadoc)\r
70      * @see org.simantics.utils.ui.action.IPriorityAction#getPriority()\r
71      */\r
72     public int getPriority() {\r
73         return priority;\r
74     }\r
75 \r
76     public int compareTo(IPriorityAction o) {\r
77         int op = o.getPriority();\r
78         // delta < 0 when priority < op\r
79         // delta > 0 when priority > op\r
80         int delta = op - getPriority();\r
81         return delta;\r
82     }\r
83     \r
84 }\r