1 /*******************************************************************************
2  * Copyright (c) 2003, 2015 IBM Corporation and others.
3  *
4  * This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License 2.0
6  * which accompanies this distribution, and is available at
7  * https://www.eclipse.org/legal/epl-2.0/
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  *     IBM Corporation - initial API and implementation
13  *******************************************************************************/
14 package org.eclipse.ui.navigator;
15 
16 /**
17  * <p>
18  * Enumeration of the OverridePolicy values supported by the Common Navigator.
19  * </p>
20  *
21  * @since 3.4
22  */
23 public final class OverridePolicy {
24 
25 	/**
26 	 * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
27 	 * an int.
28 	 */
29 	public static final int InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE = -1;
30 
31 	/**
32 	 * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as an int.
33 	 */
34 	public static final int InvokeAlwaysRegardlessOfSuppressedExt_VALUE = 1;
35 
36 	/**
37 	 * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
38 	 * a String.
39 	 */
40 	public static final String InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_LITERAL = "InvokeOnlyIfSuppressedExtAlsoVisibleAndActive"; //$NON-NLS-1$
41 
42 	/**
43 	 * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as a
44 	 * String.
45 	 */
46 	public static final String InvokeAlwaysRegardlessOfSuppressedExt_LITERAL = "InvokeAlwaysRegardlessOfSuppressedExt"; //$NON-NLS-1$
47 
48 	/**
49 	 * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
50 	 * a OverridePolicy enumeration.
51 	 */
52 	public static final OverridePolicy InvokeOnlyIfSuppressedExtAlsoVisibleAndActive = new OverridePolicy(
53 			InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE,
54 			InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_LITERAL);
55 
56 	/**
57 	 * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as a
58 	 * OverridePolicy enumeration.
59 	 */
60 	public static final OverridePolicy InvokeAlwaysRegardlessOfSuppressedExt = new OverridePolicy(
61 			InvokeAlwaysRegardlessOfSuppressedExt_VALUE,
62 			InvokeAlwaysRegardlessOfSuppressedExt_LITERAL);
63 
64 	/**
65 	 * The ordered array of possible enumeration values.
66 	 */
67 	public static final OverridePolicy[] ENUM_ARRAY = new OverridePolicy[] {
68 			InvokeOnlyIfSuppressedExtAlsoVisibleAndActive,
69 			InvokeAlwaysRegardlessOfSuppressedExt };
70 
71 	/**
72 	 *
73 	 * Returns the correct instance of the OverridePolicy ENUM for aLiteral.
74 	 *
75 	 * <p>
76 	 * This method will return InvokeAlwaysRegardlessOfSuppressedExt if the
77 	 * supplied value of aLiteral is invalid.
78 	 * </p>
79 	 *
80 	 * @param aLiteral
81 	 *            One of the defined *_LITERAL constants of this class
82 	 * @return The corresponding OverridePolicy Enum or
83 	 *         InvokeAlwaysRegardlessOfSuppressedExt if aLiteral is invalid
84 	 */
get(String aLiteral)85 	public static OverridePolicy get(String aLiteral) {
86 		for (OverridePolicy policy : ENUM_ARRAY) {
87 			if (policy.getLiteral().equals(aLiteral)) {
88 				return policy;
89 			}
90 		}
91 		return InvokeAlwaysRegardlessOfSuppressedExt;
92 	}
93 
94 	/**
95 	 *
96 	 * Returns the correct instance of the OverridePolicy ENUM for aValue.
97 	 *
98 	 * <p>
99 	 * This method will return InvokeAlwaysRegardlessOfSuppressedExt if the
100 	 * supplied value of aValue is invalid.
101 	 * </p>
102 	 *
103 	 * @param aValue
104 	 *            One of the defined *_VALUE constants of this class
105 	 * @return The corresponding OverridePolicy Enum or
106 	 *         InvokeAlwaysRegardlessOfSuppressedExt if aValue is invalid
107 	 */
get(int aValue)108 	public static OverridePolicy get(int aValue) {
109 
110 		switch (aValue) {
111 		case InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE:
112 			return InvokeOnlyIfSuppressedExtAlsoVisibleAndActive;
113 		case InvokeAlwaysRegardlessOfSuppressedExt_VALUE:
114 		default:
115 			return InvokeAlwaysRegardlessOfSuppressedExt;
116 
117 		}
118 	}
119 
120 	private final int value;
121 
122 	private final String literal;
123 
OverridePolicy(int aValue, String aLiteral)124 	protected OverridePolicy(int aValue, String aLiteral) {
125 		value = aValue;
126 		literal = aLiteral;
127 	}
128 
129 	/**
130 	 *
131 	 * @return The literal string for this specific OverridePolicy.
132 	 */
getLiteral()133 	public String getLiteral() {
134 		return literal;
135 	}
136 
137 	/**
138 	 *
139 	 * @return The integer value for this specific OverridePolicy.
140 	 */
getValue()141 	public int getValue() {
142 		return value;
143 	}
144 }
145