KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.util.ArrayList JavaDoc;
14
15 import org.eclipse.core.runtime.IPath;
16 import org.eclipse.core.runtime.Path;
17 import org.eclipse.jdt.core.IClasspathEntry;
18 import org.eclipse.jdt.core.IJavaProject;
19 import org.eclipse.jdt.core.JavaCore;
20 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
21 import org.eclipse.jdt.internal.ui.JavaPluginImages;
22 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
23 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages;
24 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField;
25 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener;
26 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil;
27 import org.eclipse.jdt.internal.ui.wizards.dialogfields.StringDialogField;
28 import org.eclipse.jdt.ui.wizards.IClasspathContainerPage;
29 import org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension;
30 import org.eclipse.jdt.ui.wizards.NewElementWizardPage;
31 import org.eclipse.swt.SWT;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34
35 import org.eclipse.jface.dialogs.Dialog;
36
37 import org.eclipse.ui.PlatformUI;
38
39 /**
40   */

41 public class ClasspathContainerDefaultPage extends NewElementWizardPage implements IClasspathContainerPage, IClasspathContainerPageExtension {
42
43     private StringDialogField fEntryField;
44     private ArrayList JavaDoc fUsedPaths;
45
46     /**
47      * Constructor for ClasspathContainerDefaultPage.
48      */

49     public ClasspathContainerDefaultPage() {
50         super("ClasspathContainerDefaultPage"); //$NON-NLS-1$
51
setTitle(NewWizardMessages.ClasspathContainerDefaultPage_title);
52         setDescription(NewWizardMessages.ClasspathContainerDefaultPage_description);
53         setImageDescriptor(JavaPluginImages.DESC_WIZBAN_ADD_LIBRARY);
54         
55         fUsedPaths= new ArrayList JavaDoc();
56         
57         fEntryField= new StringDialogField();
58         fEntryField.setLabelText(NewWizardMessages.ClasspathContainerDefaultPage_path_label);
59         fEntryField.setDialogFieldListener(new IDialogFieldListener() {
60             public void dialogFieldChanged(DialogField field) {
61                 validatePath();
62             }
63         });
64         validatePath();
65     }
66
67     private void validatePath() {
68         StatusInfo status= new StatusInfo();
69         String JavaDoc str= fEntryField.getText();
70         if (str.length() == 0) {
71             status.setError(NewWizardMessages.ClasspathContainerDefaultPage_path_error_enterpath);
72         } else if (!Path.ROOT.isValidPath(str)) {
73             status.setError(NewWizardMessages.ClasspathContainerDefaultPage_path_error_invalidpath);
74         } else {
75             IPath path= new Path(str);
76             if (path.segmentCount() == 0) {
77                 status.setError(NewWizardMessages.ClasspathContainerDefaultPage_path_error_needssegment);
78             } else if (fUsedPaths.contains(path)) {
79                 status.setError(NewWizardMessages.ClasspathContainerDefaultPage_path_error_alreadyexists);
80             }
81         }
82         updateStatus(status);
83     }
84
85     /* (non-Javadoc)
86      * @see IDialogPage#createControl(Composite)
87      */

88     public void createControl(Composite parent) {
89         Composite composite= new Composite(parent, SWT.NONE);
90         GridLayout layout= new GridLayout();
91         layout.numColumns= 1;
92         composite.setLayout(layout);
93         
94         fEntryField.doFillIntoGrid(composite, 2);
95         LayoutUtil.setHorizontalGrabbing(fEntryField.getTextControl(null));
96         
97         fEntryField.setFocus();
98         
99         setControl(composite);
100         Dialog.applyDialogFont(composite);
101         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.CLASSPATH_CONTAINER_DEFAULT_PAGE);
102     }
103
104     /* (non-Javadoc)
105      * @see IClasspathContainerPage#finish()
106      */

107     public boolean finish() {
108         return true;
109     }
110     
111     /* (non-Javadoc)
112      * @see IClasspathContainerPage#getSelection()
113      */

114     public IClasspathEntry getSelection() {
115         return JavaCore.newContainerEntry(new Path(fEntryField.getText()));
116     }
117     
118     /* (non-Javadoc)
119      * @see org.eclipse.jdt.ui.wizards.IClasspathContainerPageExtension#initialize(org.eclipse.jdt.core.IJavaProject, org.eclipse.jdt.core.IClasspathEntry)
120      */

121     public void initialize(IJavaProject project, IClasspathEntry[] currentEntries) {
122         for (int i= 0; i < currentEntries.length; i++) {
123             IClasspathEntry curr= currentEntries[i];
124             if (curr.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
125                 fUsedPaths.add(curr.getPath());
126             }
127         }
128     }
129
130     /* (non-Javadoc)
131      * @see IClasspathContainerPage#setSelection(IClasspathEntry)
132      */

133     public void setSelection(IClasspathEntry containerEntry) {
134         if (containerEntry != null) {
135             fUsedPaths.remove(containerEntry.getPath());
136             fEntryField.setText(containerEntry.getPath().toString());
137         } else {
138             fEntryField.setText(""); //$NON-NLS-1$
139
}
140     }
141
142
143
144 }
145
Popular Tags