1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import org.eclipse.core.runtime.Assert; 14 import org.eclipse.core.runtime.IStatus; 15 16 import org.eclipse.jdt.core.ClasspathContainerInitializer; 17 import org.eclipse.jdt.core.IClasspathAttribute; 18 import org.eclipse.jdt.core.IClasspathEntry; 19 import org.eclipse.jdt.core.IJavaProject; 20 import org.eclipse.jdt.core.JavaCore; 21 22 import org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess; 23 24 25 27 public class CPListElementAttribute { 28 29 private CPListElement fParent; 30 private String fKey; 31 private Object fValue; 32 private final boolean fBuiltIn; 33 private IStatus fStatus; 34 35 private ClasspathAttributeAccess fCachedAccess; 36 37 public CPListElementAttribute(CPListElement parent, String key, Object value, boolean builtIn) { 38 fKey= key; 39 fValue= value; 40 fParent= parent; 41 fBuiltIn= builtIn; 42 if (!builtIn) { 43 Assert.isTrue(value instanceof String || value == null); 44 } 45 fStatus= getContainerChildStatus(); 46 } 47 48 private CPListElementAttribute(boolean buildIn) { 49 fBuiltIn= buildIn; 50 } 51 52 public IClasspathAttribute getClasspathAttribute() { 53 Assert.isTrue(!fBuiltIn); 54 return JavaCore.newClasspathAttribute(fKey, (String ) fValue); 55 } 56 57 public CPListElement getParent() { 58 return fParent; 59 } 60 61 64 public boolean isBuiltIn() { 65 return fBuiltIn; 66 } 67 68 71 public boolean isNonModifiable() { 72 return fStatus != null && !fStatus.isOK(); 73 } 74 75 78 public boolean isNotSupported() { 79 return fStatus != null && fStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED; 80 } 81 82 85 private IStatus getContainerChildStatus() { 86 return fParent.getContainerChildStatus(this); 87 } 88 89 90 94 public String getKey() { 95 return fKey; 96 } 97 98 102 public Object getValue() { 103 return fValue; 104 } 105 106 110 public void setValue(Object value) { 111 fValue= value; 112 fCachedAccess= null; 113 getParent().attributeChanged(fKey); 114 } 115 116 public boolean equals(Object obj) { 117 if (!(obj instanceof CPListElementAttribute)) 118 return false; 119 CPListElementAttribute attrib= (CPListElementAttribute)obj; 120 return attrib.fKey== this.fKey && attrib.getParent().getPath().equals(fParent.getPath()); 121 } 122 123 public CPListElementAttribute copy() { 124 CPListElementAttribute result= new CPListElementAttribute(fBuiltIn); 125 result.fParent= fParent; 126 result.fKey= fKey; 127 result.fValue= fValue; 128 result.fStatus= fStatus; 129 return result; 130 } 131 132 public ClasspathAttributeAccess getClasspathAttributeAccess() { 133 if (fCachedAccess == null) { 134 fCachedAccess= new ClasspathAttributeAccess() { 135 public IClasspathAttribute getClasspathAttribute() { 136 return CPListElementAttribute.this.getClasspathAttribute(); 137 } 138 public IJavaProject getJavaProject() { 139 return getParent().getJavaProject(); 140 } 141 public IClasspathEntry getParentClasspassEntry() { 142 return getParent().getClasspathEntry(); 143 } 144 }; 145 } 146 return fCachedAccess; 147 } 148 149 150 } 151 | Popular Tags |