KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > wizards > buildpaths > CPListElementAttribute


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.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 /**
26   */

27 public class CPListElementAttribute {
28
29     private CPListElement fParent;
30     private String JavaDoc fKey;
31     private Object JavaDoc fValue;
32     private final boolean fBuiltIn;
33     private IStatus fStatus;
34     
35     private ClasspathAttributeAccess fCachedAccess;
36     
37     public CPListElementAttribute(CPListElement parent, String JavaDoc key, Object JavaDoc value, boolean builtIn) {
38         fKey= key;
39         fValue= value;
40         fParent= parent;
41         fBuiltIn= builtIn;
42         if (!builtIn) {
43             Assert.isTrue(value instanceof String JavaDoc || 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 JavaDoc) fValue);
55     }
56     
57     public CPListElement getParent() {
58         return fParent;
59     }
60     
61     /**
62      * @return Returns <code>true</code> if the attribute is a built in attribute.
63      */

64     public boolean isBuiltIn() {
65         return fBuiltIn;
66     }
67     
68     /**
69      * @return Returns <code>true</code> if the attribute a on a container child and is read-only
70      */

71     public boolean isNonModifiable() {
72         return fStatus != null && !fStatus.isOK();
73     }
74     
75     /**
76      * @return Returns <code>true</code> if the attribute a on a container child and is not supported
77      */

78     public boolean isNotSupported() {
79         return fStatus != null && fStatus.getCode() == ClasspathContainerInitializer.ATTRIBUTE_NOT_SUPPORTED;
80     }
81     
82     /**
83      * @return Returns the container child status or <code>null</code> if the attribute is not in a container child
84      */

85     private IStatus getContainerChildStatus() {
86         return fParent.getContainerChildStatus(this);
87     }
88     
89     
90     /**
91      * Returns the key.
92      * @return String
93      */

94     public String JavaDoc getKey() {
95         return fKey;
96     }
97
98     /**
99      * Returns the value.
100      * @return Object
101      */

102     public Object JavaDoc getValue() {
103         return fValue;
104     }
105     
106     /**
107      * Returns the value.
108      * @param value value to set
109      */

110     public void setValue(Object JavaDoc value) {
111         fValue= value;
112         fCachedAccess= null;
113         getParent().attributeChanged(fKey);
114     }
115     
116     public boolean equals(Object JavaDoc 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