1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import java.util.ArrayList ; 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 41 public class ClasspathContainerDefaultPage extends NewElementWizardPage implements IClasspathContainerPage, IClasspathContainerPageExtension { 42 43 private StringDialogField fEntryField; 44 private ArrayList fUsedPaths; 45 46 49 public ClasspathContainerDefaultPage() { 50 super("ClasspathContainerDefaultPage"); setTitle(NewWizardMessages.ClasspathContainerDefaultPage_title); 52 setDescription(NewWizardMessages.ClasspathContainerDefaultPage_description); 53 setImageDescriptor(JavaPluginImages.DESC_WIZBAN_ADD_LIBRARY); 54 55 fUsedPaths= new ArrayList (); 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 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 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 107 public boolean finish() { 108 return true; 109 } 110 111 114 public IClasspathEntry getSelection() { 115 return JavaCore.newContainerEntry(new Path(fEntryField.getText())); 116 } 117 118 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 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(""); } 140 } 141 142 143 144 } 145 | Popular Tags |