KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > commands > Priority


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.commands;
12
13 import org.eclipse.core.expressions.Expression;
14 import org.eclipse.ui.ISources;
15 import org.eclipse.ui.internal.util.Util;
16
17 /**
18  * <p>
19  * An instance of this interface represents a priority for use with instances of
20  * <code>HandlerSubmission</code>.
21  * </p>
22  * <p>
23  * The order of precedence (from highest to lowest) is as follows. Submissions
24  * with higher priority will be preferred over those with lower priority.
25  * </p>
26  * <ol>
27  * <li>MEDIUM</li>
28  * <li>LOW</li>
29  * <li>LEGACY</li>
30  * </ol>
31  * </p>
32  * <p>
33  * This class is not intended to be extended by clients.
34  * </p>
35  *
36  * @since 3.0
37  * @see HandlerSubmission
38  * @see org.eclipse.ui.ISources
39  * @see org.eclipse.ui.handlers.IHandlerService#activateHandler(String,
40  * IHandler, Expression)
41  * @deprecated This concept is now captured in the <code>ISources</code>
42  * integer constants.
43  *
44  */

45 public final class Priority implements Comparable JavaDoc {
46
47     /**
48      * An instance representing 'legacy' priority.
49      */

50     public final static Priority LEGACY = new Priority(ISources.LEGACY_LEGACY);
51
52     /**
53      * An instance representing 'low' priority.
54      */

55     public final static Priority LOW = new Priority(ISources.LEGACY_LOW);
56
57     /**
58      * An instance representing 'medium' priority.
59      */

60     public final static Priority MEDIUM = new Priority(ISources.LEGACY_MEDIUM);
61
62     /**
63      * The string representation of this priority. This is computed once
64      * (lazily). Before it is computed, this value is <code>null</code>.
65      */

66     private transient String JavaDoc string = null;
67
68     /**
69      * The priority value for this instance. A lesser integer is considered to
70      * have a higher priority.
71      */

72     private int value;
73
74     /**
75      * Constructs a new instance of <code>Priority</code> using a value. This
76      * constructor should only be used internally. Priority instances should be
77      * retrieved from the static members defined above.
78      *
79      * @param value
80      * The priority value; a lesser integer is consider to have a
81      * higher priority value.
82      */

83     private Priority(int value) {
84         this.value = value;
85     }
86
87     /**
88      * @see Comparable#compareTo(java.lang.Object)
89      */

90     public int compareTo(Object JavaDoc object) {
91         Priority castedObject = (Priority) object;
92         int compareTo = Util.compare(value, castedObject.value);
93         return compareTo;
94     }
95
96     /**
97      * The value for this priority. The lesser the value, the higher priority
98      * this represents.
99      *
100      * @return The integer priority value.
101      */

102     int getValue() {
103         return value;
104     }
105
106     /**
107      * @see Object#toString()
108      */

109     public String JavaDoc toString() {
110         if (string == null) {
111             final StringBuffer JavaDoc stringBuffer = new StringBuffer JavaDoc();
112             stringBuffer.append("[value="); //$NON-NLS-1$
113
stringBuffer.append(value);
114             stringBuffer.append(']');
115             string = stringBuffer.toString();
116         }
117
118         return string;
119     }
120 }
121
Popular Tags