1 11 package org.eclipse.pde.internal.ui.editor.plugin; 12 13 import java.util.HashSet ; 14 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Path; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.pde.core.plugin.IPluginLibrary; 19 import org.eclipse.pde.internal.core.ClasspathUtilCore; 20 import org.eclipse.pde.internal.ui.PDEPlugin; 21 import org.eclipse.pde.internal.ui.PDEUIMessages; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.events.ModifyEvent; 24 import org.eclipse.swt.events.ModifyListener; 25 import org.eclipse.swt.layout.GridData; 26 import org.eclipse.swt.layout.GridLayout; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Control; 29 import org.eclipse.swt.widgets.Label; 30 import org.eclipse.swt.widgets.Shell; 31 import org.eclipse.swt.widgets.Text; 32 import org.eclipse.ui.dialogs.SelectionStatusDialog; 33 34 public class NewRuntimeLibraryDialog extends SelectionStatusDialog { 35 private Text libraryText; 36 private IPluginLibrary[] libraries; 37 private DuplicateStatusValidator validator; 38 private String libraryName; 39 private HashSet librarySet; 40 41 class DuplicateStatusValidator { 42 public IStatus validate(String text) { 43 String id = PDEPlugin.getPluginId(); 44 if (text.length() == 0) 45 return new Status(IStatus.ERROR, id, IStatus.ERROR, 46 PDEUIMessages.AddLibraryDialog_emptyLibraries, null); 47 48 if (text.indexOf(' ') != -1) 49 return new Status(IStatus.ERROR, id, IStatus.ERROR, 50 PDEUIMessages.AddLibraryDialog_nospaces, null); 51 52 if (libraries == null || libraries.length == 0) 53 return new Status(IStatus.OK, id, IStatus.OK, "", null); 55 if (librarySet.contains(new Path(ClasspathUtilCore.expandLibraryName(text)))) 56 return new Status(IStatus.ERROR, id, IStatus.ERROR, 57 PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_validationError, 58 null); 59 return new Status(IStatus.OK, id, IStatus.OK, "", null); } 61 } 62 public NewRuntimeLibraryDialog(Shell parent, IPluginLibrary[] libraries) { 63 super(parent); 64 this.libraries = libraries; 65 this.validator = new DuplicateStatusValidator(); 66 librarySet = new HashSet (); 67 for (int i = 0; i < libraries.length; i++) { 68 librarySet.add(new Path(ClasspathUtilCore.expandLibraryName(libraries[i].getName()))); 69 } 70 setStatusLineAboveButtons(true); 71 } 72 75 protected void computeResult() { 76 } 77 80 protected Control createDialogArea(Composite parent) { 81 Composite container = new Composite(parent, SWT.NONE); 82 GridLayout layout = new GridLayout(); 83 layout.marginHeight = layout.marginWidth = 8; 84 layout.numColumns = 1; 85 86 layout.makeColumnsEqualWidth = false; 87 container.setLayout(layout); 88 GridData gd = new GridData(GridData.FILL_BOTH); 89 container.setLayoutData(gd); 90 Label libraryLabel = new Label(container, SWT.NULL); 91 gd = new GridData(GridData.FILL_HORIZONTAL); 92 libraryLabel.setLayoutData(gd); 93 libraryLabel.setText(PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_label); 94 95 libraryText = new Text(container, SWT.SINGLE|SWT.BORDER); 96 gd = new GridData(GridData.FILL_HORIZONTAL); 97 libraryText.setLayoutData(gd); 98 libraryText.setText(PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_default); 99 libraryText.addModifyListener(new ModifyListener() { 100 public void modifyText(ModifyEvent e) { 101 updateStatus(validator.validate(libraryText.getText())); 102 } 103 }); 104 applyDialogFont(container); 105 return container; 106 } 107 110 public int open() { 111 libraryText.setText("library.jar"); libraryText.setSelection(0, libraryText.getText().length() - 4); 113 return super.open(); 114 } 115 public String getLibraryName(){ 116 return libraryName; 117 } 118 119 122 protected void okPressed() { 123 libraryName = libraryText.getText(); 124 super.okPressed(); 125 } 126 127 } 128 | Popular Tags |