001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.plugin;
011:
012: import java.util.HashSet;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.core.runtime.Path;
016: import org.eclipse.core.runtime.Status;
017: import org.eclipse.pde.core.plugin.IPluginLibrary;
018: import org.eclipse.pde.internal.core.ClasspathUtilCore;
019: import org.eclipse.pde.internal.ui.PDEPlugin;
020: import org.eclipse.pde.internal.ui.PDEUIMessages;
021: import org.eclipse.swt.SWT;
022: import org.eclipse.swt.events.ModifyEvent;
023: import org.eclipse.swt.events.ModifyListener;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.layout.GridLayout;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Control;
028: import org.eclipse.swt.widgets.Label;
029: import org.eclipse.swt.widgets.Shell;
030: import org.eclipse.swt.widgets.Text;
031: import org.eclipse.ui.dialogs.SelectionStatusDialog;
032:
033: public class NewRuntimeLibraryDialog extends SelectionStatusDialog {
034: private Text libraryText;
035: private IPluginLibrary[] libraries;
036: private DuplicateStatusValidator validator;
037: private String libraryName;
038: private HashSet librarySet;
039:
040: class DuplicateStatusValidator {
041: public IStatus validate(String text) {
042: String id = PDEPlugin.getPluginId();
043: if (text.length() == 0)
044: return new Status(IStatus.ERROR, id, IStatus.ERROR,
045: PDEUIMessages.AddLibraryDialog_emptyLibraries,
046: null);
047:
048: if (text.indexOf(' ') != -1)
049: return new Status(IStatus.ERROR, id, IStatus.ERROR,
050: PDEUIMessages.AddLibraryDialog_nospaces, null);
051:
052: if (libraries == null || libraries.length == 0)
053: return new Status(IStatus.OK, id, IStatus.OK, "", null); //$NON-NLS-1$
054:
055: if (librarySet.contains(new Path(ClasspathUtilCore
056: .expandLibraryName(text))))
057: return new Status(
058: IStatus.ERROR,
059: id,
060: IStatus.ERROR,
061: PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_validationError,
062: null);
063: return new Status(IStatus.OK, id, IStatus.OK, "", null); //$NON-NLS-1$
064: }
065: }
066:
067: public NewRuntimeLibraryDialog(Shell parent,
068: IPluginLibrary[] libraries) {
069: super (parent);
070: this .libraries = libraries;
071: this .validator = new DuplicateStatusValidator();
072: librarySet = new HashSet();
073: for (int i = 0; i < libraries.length; i++) {
074: librarySet.add(new Path(ClasspathUtilCore
075: .expandLibraryName(libraries[i].getName())));
076: }
077: setStatusLineAboveButtons(true);
078: }
079:
080: /* (non-Javadoc)
081: * @see org.eclipse.ui.dialogs.SelectionStatusDialog#computeResult()
082: */
083: protected void computeResult() {
084: }
085:
086: /* (non-Javadoc)
087: * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
088: */
089: protected Control createDialogArea(Composite parent) {
090: Composite container = new Composite(parent, SWT.NONE);
091: GridLayout layout = new GridLayout();
092: layout.marginHeight = layout.marginWidth = 8;
093: layout.numColumns = 1;
094:
095: layout.makeColumnsEqualWidth = false;
096: container.setLayout(layout);
097: GridData gd = new GridData(GridData.FILL_BOTH);
098: container.setLayoutData(gd);
099: Label libraryLabel = new Label(container, SWT.NULL);
100: gd = new GridData(GridData.FILL_HORIZONTAL);
101: libraryLabel.setLayoutData(gd);
102: libraryLabel
103: .setText(PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_label);
104:
105: libraryText = new Text(container, SWT.SINGLE | SWT.BORDER);
106: gd = new GridData(GridData.FILL_HORIZONTAL);
107: libraryText.setLayoutData(gd);
108: libraryText
109: .setText(PDEUIMessages.ManifestEditor_RuntimeLibraryDialog_default);
110: libraryText.addModifyListener(new ModifyListener() {
111: public void modifyText(ModifyEvent e) {
112: updateStatus(validator.validate(libraryText.getText()));
113: }
114: });
115: applyDialogFont(container);
116: return container;
117: }
118:
119: /* (non-Javadoc)
120: * @see org.eclipse.jface.window.Window#open()
121: */
122: public int open() {
123: libraryText.setText("library.jar"); //$NON-NLS-1$
124: libraryText.setSelection(0, libraryText.getText().length() - 4);
125: return super .open();
126: }
127:
128: public String getLibraryName() {
129: return libraryName;
130: }
131:
132: /* (non-Javadoc)
133: * @see org.eclipse.ui.dialogs.SelectionStatusDialog#okPressed()
134: */
135: protected void okPressed() {
136: libraryName = libraryText.getText();
137: super.okPressed();
138: }
139:
140: }
|