KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > plugin > NewRuntimeLibraryDialog


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.pde.internal.ui.editor.plugin;
12
13 import java.util.HashSet JavaDoc;
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 JavaDoc libraryName;
39     private HashSet JavaDoc librarySet;
40     
41     class DuplicateStatusValidator {
42         public IStatus validate(String JavaDoc text) {
43             String JavaDoc 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); //$NON-NLS-1$
54

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); //$NON-NLS-1$
60
}
61     }
62     public NewRuntimeLibraryDialog(Shell parent, IPluginLibrary[] libraries) {
63         super(parent);
64         this.libraries = libraries;
65         this.validator = new DuplicateStatusValidator();
66         librarySet = new HashSet JavaDoc();
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     /* (non-Javadoc)
73      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
74      */

75     protected void computeResult() {
76     }
77     /* (non-Javadoc)
78      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
79      */

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     /* (non-Javadoc)
108      * @see org.eclipse.jface.window.Window#open()
109      */

110     public int open() {
111         libraryText.setText("library.jar"); //$NON-NLS-1$
112
libraryText.setSelection(0, libraryText.getText().length() - 4);
113         return super.open();
114     }
115     public String JavaDoc getLibraryName(){
116         return libraryName;
117     }
118
119     /* (non-Javadoc)
120      * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
121      */

122     protected void okPressed() {
123         libraryName = libraryText.getText();
124         super.okPressed();
125     }
126
127 }
128
Popular Tags