1 11 package org.eclipse.core.internal.variables; 12 13 import org.eclipse.core.runtime.CoreException; 14 import org.eclipse.core.runtime.IConfigurationElement; 15 import org.eclipse.core.variables.IValueVariable; 16 import org.eclipse.core.variables.IValueVariableInitializer; 17 import org.eclipse.core.variables.VariablesPlugin; 18 import org.eclipse.osgi.util.NLS; 19 20 23 public class ContributedValueVariable extends StringVariable implements IValueVariable { 24 25 28 private String fValue; 29 30 33 private boolean fInitialized = false; 34 35 38 private boolean fReadOnly; 39 40 50 public ContributedValueVariable(String name, String description, boolean readOnly, IConfigurationElement configurationElement) { 51 super(name, description, configurationElement); 52 fReadOnly = readOnly; 53 } 54 55 58 public void setValue(String value) { 59 if (!isReadOnly() || !isInitialized()){ 60 fValue = value; 61 setInitialized(true); 62 StringVariableManager.getDefault().notifyChanged(this); 63 } 64 } 65 66 69 public String getValue() { 70 if (!isInitialized()) { 71 initialize(); 72 } 73 return fValue; 74 } 75 76 79 private void initialize() { 80 if (getConfigurationElement() != null) { 81 String value = getConfigurationElement().getAttribute("initialValue"); if (value == null) { 84 String className = getConfigurationElement().getAttribute("initializerClass"); if (className != null) { 87 try { 88 Object object = getConfigurationElement().createExecutableExtension("initializerClass"); if (object instanceof IValueVariableInitializer) { 90 IValueVariableInitializer initializer = (IValueVariableInitializer)object; 91 initializer.initialize(this); 92 } else { 93 VariablesPlugin.logMessage(NLS.bind("Unable to initialize variable {0} - initializer must be an instance of IValueVariableInitializer.", new String []{getName()}), null); } 95 } catch (CoreException e) { 96 VariablesPlugin.logMessage(NLS.bind("Unable to initialize variable {0}",new String []{getName()}), e); } 98 } 99 } else { 100 setValue(value); 101 } 102 } 103 setInitialized(true); 104 } 105 106 115 protected boolean isInitialized() { 116 return fInitialized; 117 } 118 119 124 protected void setInitialized(boolean initialized) { 125 fInitialized = initialized; 126 } 127 128 131 public boolean isReadOnly() { 132 return fReadOnly; 133 } 134 135 138 public boolean isContributed() { 139 return getConfigurationElement() != null; 140 } 141 142 } 143 | Popular Tags |