001: /*******************************************************************************
002: * Copyright (c) 2003, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.internal.navigator.extensions;
011:
012: /**
013: * <p>
014: * Enumeration of the OverridePolicy values supported by the Common Navigator.
015: * </p>
016: *
017: * @since 3.2
018: */
019: public final class OverridePolicy {
020:
021: /**
022: * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
023: * an int.
024: */
025: public static final int InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE = -1;
026:
027: /**
028: * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as an int.
029: */
030: public static final int InvokeAlwaysRegardlessOfSuppressedExt_VALUE = 1;
031:
032: /**
033: * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
034: * a String.
035: */
036: public static final String InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_LITERAL = "InvokeOnlyIfSuppressedExtAlsoVisibleAndActive"; //$NON-NLS-1$
037:
038: /**
039: * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as a
040: * String.
041: */
042: public static final String InvokeAlwaysRegardlessOfSuppressedExt_LITERAL = "InvokeAlwaysRegardlessOfSuppressedExt"; //$NON-NLS-1$
043:
044: /**
045: * Indicates InvokeOnlyIfSuppressedExtAlsoVisibleAndActive OverridePolicy as
046: * a OverridePolicy enumeration.
047: */
048: public static final OverridePolicy InvokeOnlyIfSuppressedExtAlsoVisibleAndActive = new OverridePolicy(
049: InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE,
050: InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_LITERAL);
051:
052: /**
053: * Indicates InvokeAlwaysRegardlessOfSuppressedExt OverridePolicy as a
054: * OverridePolicy enumeration.
055: */
056: public static final OverridePolicy InvokeAlwaysRegardlessOfSuppressedExt = new OverridePolicy(
057: InvokeAlwaysRegardlessOfSuppressedExt_VALUE,
058: InvokeAlwaysRegardlessOfSuppressedExt_LITERAL);
059:
060: /**
061: * The ordered array of possible enumeration values.
062: */
063: public static final OverridePolicy[] ENUM_ARRAY = new OverridePolicy[] {
064: InvokeOnlyIfSuppressedExtAlsoVisibleAndActive,
065: InvokeAlwaysRegardlessOfSuppressedExt };
066:
067: /**
068: *
069: * Returns the correct instance of the OverridePolicy ENUM for aLiteral.
070: *
071: * <p>
072: * This method will return InvokeAlwaysRegardlessOfSuppressedExt if the
073: * supplied value of aLiteral is invalid.
074: * </p>
075: *
076: * @param aLiteral
077: * One of the defined *_LITERAL constants of this class
078: * @return The corresponding OverridePolicy Enum or
079: * InvokeAlwaysRegardlessOfSuppressedExt if aLiteral is invalid
080: */
081: public static OverridePolicy get(String aLiteral) {
082: for (int i = 0; i < ENUM_ARRAY.length; i++) {
083: if (ENUM_ARRAY[i].getLiteral().equals(aLiteral)) {
084: return ENUM_ARRAY[i];
085: }
086: }
087: return InvokeAlwaysRegardlessOfSuppressedExt;
088: }
089:
090: /**
091: *
092: * Returns the correct instance of the OverridePolicy ENUM for aValue.
093: *
094: * <p>
095: * This method will return InvokeAlwaysRegardlessOfSuppressedExt if the
096: * supplied value of aValue is invalid.
097: * </p>
098: *
099: * @param aValue
100: * One of the defined *_VALUE constants of this class
101: * @return The corresponding OverridePolicy Enum or
102: * InvokeAlwaysRegardlessOfSuppressedExt if aValue is invalid
103: */
104: public static OverridePolicy get(int aValue) {
105:
106: switch (aValue) {
107: case InvokeOnlyIfSuppressedExtAlsoVisibleAndActive_VALUE:
108: return InvokeOnlyIfSuppressedExtAlsoVisibleAndActive;
109: case InvokeAlwaysRegardlessOfSuppressedExt_VALUE:
110: default:
111: return InvokeAlwaysRegardlessOfSuppressedExt;
112:
113: }
114: }
115:
116: private final int value;
117:
118: private final String literal;
119:
120: protected OverridePolicy(int aValue, String aLiteral) {
121: value = aValue;
122: literal = aLiteral;
123: }
124:
125: /**
126: *
127: * @return The literal string for this specific OverridePolicy.
128: */
129: public String getLiteral() {
130: return literal;
131: }
132:
133: /**
134: *
135: * @return The integer value for this specific OverridePolicy.
136: */
137: public int getValue() {
138: return value;
139: }
140: }
|