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