KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15
16 import org.eclipse.swt.widgets.Shell;
17
18 import org.eclipse.jface.resource.ImageDescriptor;
19
20 import org.eclipse.jdt.core.IClasspathAttribute;
21 import org.eclipse.jdt.core.JavaCore;
22
23 import org.eclipse.jdt.internal.corext.javadoc.JavaDocLocations;
24 import org.eclipse.jdt.internal.corext.util.Messages;
25
26 import org.eclipse.jdt.ui.wizards.BuildPathDialogAccess;
27 import org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration;
28
29 import org.eclipse.jdt.internal.ui.JavaPluginImages;
30 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
31
32 public class JavadocAttributeConfiguration extends ClasspathAttributeConfiguration {
33
34     /* (non-Javadoc)
35      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#getImageDescriptor(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
36      */

37     public ImageDescriptor getImageDescriptor(ClasspathAttributeAccess attribute) {
38         return JavaPluginImages.DESC_OBJS_JAVADOC_LOCATION_ATTRIB;
39     }
40
41     /* (non-Javadoc)
42      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#getNameLabel(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
43      */

44     public String JavaDoc getNameLabel(ClasspathAttributeAccess attribute) {
45         return NewWizardMessages.CPListLabelProvider_javadoc_location_label;
46     }
47     
48     /* (non-Javadoc)
49      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#getValueLabel(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
50      */

51     public String JavaDoc getValueLabel(ClasspathAttributeAccess access) {
52         String JavaDoc arg= null;
53         String JavaDoc str= access.getClasspathAttribute().getValue();
54         if (str != null) {
55             String JavaDoc prefix= JavaDocLocations.ARCHIVE_PREFIX;
56             if (str.startsWith(prefix)) {
57                 int sepIndex= str.lastIndexOf("!/"); //$NON-NLS-1$
58
if (sepIndex == -1) {
59                     arg= str.substring(prefix.length());
60                 } else {
61                     String JavaDoc archive= str.substring(prefix.length(), sepIndex);
62                     String JavaDoc root= str.substring(sepIndex + 2);
63                     if (root.length() > 0) {
64                         arg= Messages.format(NewWizardMessages.CPListLabelProvider_twopart, new String JavaDoc[] { archive, root });
65                     } else {
66                         arg= archive;
67                     }
68                 }
69             } else {
70                 arg= str;
71             }
72         } else {
73             arg= NewWizardMessages.CPListLabelProvider_none;
74         }
75         return arg;
76     }
77
78     /* (non-Javadoc)
79      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#performEdit(org.eclipse.swt.widgets.Shell, org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
80      */

81     public IClasspathAttribute performEdit(Shell shell, ClasspathAttributeAccess attribute) {
82         String JavaDoc initialLocation= attribute.getClasspathAttribute().getValue();
83         String JavaDoc elementName= attribute.getParentClasspassEntry().getPath().lastSegment();
84         try {
85             URL JavaDoc locationURL= initialLocation != null ? new URL JavaDoc(initialLocation) : null;
86             URL JavaDoc[] result= BuildPathDialogAccess.configureJavadocLocation(shell, elementName, locationURL);
87             if (result != null) {
88                 URL JavaDoc newURL= result[0];
89                 String JavaDoc string= newURL != null ? newURL.toExternalForm() : null;
90                 return JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, string);
91             }
92         } catch (MalformedURLException JavaDoc e) {
93             // todo
94
}
95         return null;
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#performRemove(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
100      */

101     public IClasspathAttribute performRemove(ClasspathAttributeAccess attribute) {
102         return JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, null);
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#canEdit(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
107      */

108     public boolean canEdit(ClasspathAttributeAccess attribute) {
109         return true;
110     }
111
112     /* (non-Javadoc)
113      * @see org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration#canRemove(org.eclipse.jdt.ui.wizards.ClasspathAttributeConfiguration.ClasspathAttributeAccess)
114      */

115     public boolean canRemove(ClasspathAttributeAccess attribute) {
116         return attribute.getClasspathAttribute().getValue() != null;
117     }
118
119
120
121 }
122
Popular Tags