001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 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.wizards.plugin;
011:
012: import org.eclipse.core.runtime.IStatus;
013: import org.eclipse.jface.dialogs.Dialog;
014: import org.eclipse.jface.window.Window;
015: import org.eclipse.pde.core.plugin.IPlugin;
016: import org.eclipse.pde.core.plugin.IPluginModel;
017: import org.eclipse.pde.core.plugin.PluginRegistry;
018: import org.eclipse.pde.internal.core.util.VersionUtil;
019: import org.eclipse.pde.internal.ui.IHelpContextIds;
020: import org.eclipse.pde.internal.ui.PDEUIMessages;
021: import org.eclipse.pde.internal.ui.parts.PluginVersionPart;
022: import org.eclipse.pde.internal.ui.util.SWTUtil;
023: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
024: import org.eclipse.pde.internal.ui.wizards.PluginSelectionDialog;
025: import org.eclipse.swt.SWT;
026: import org.eclipse.swt.custom.BusyIndicator;
027: import org.eclipse.swt.custom.StackLayout;
028: import org.eclipse.swt.events.ModifyEvent;
029: import org.eclipse.swt.events.ModifyListener;
030: import org.eclipse.swt.events.SelectionAdapter;
031: import org.eclipse.swt.events.SelectionEvent;
032: import org.eclipse.swt.layout.GridData;
033: import org.eclipse.swt.layout.GridLayout;
034: import org.eclipse.swt.widgets.Button;
035: import org.eclipse.swt.widgets.Combo;
036: import org.eclipse.swt.widgets.Composite;
037: import org.eclipse.swt.widgets.Control;
038: import org.eclipse.swt.widgets.Group;
039: import org.eclipse.swt.widgets.Label;
040: import org.eclipse.swt.widgets.Text;
041: import org.eclipse.ui.PlatformUI;
042: import org.osgi.framework.Version;
043:
044: public class FragmentContentPage extends ContentPage {
045:
046: private Text fPluginIdText_newV;
047: private Text fPluginIdText_oldV;
048: private Text fPluginVersion;
049: private Combo fMatchCombo;
050: private boolean fNewVersion;
051: private Composite fNotebook;
052: private StackLayout fNotebookLayout;
053: private Composite fOldComp;
054: private Composite fNewComp;
055: private PluginVersionPart fVersionPart;
056:
057: protected ModifyListener listener = new ModifyListener() {
058: public void modifyText(ModifyEvent e) {
059: validatePage();
060: }
061: };
062:
063: public FragmentContentPage(String pageName,
064: IProjectProvider provider, NewProjectCreationPage page,
065: AbstractFieldData data) {
066: super (pageName, provider, page, data);
067: setTitle(PDEUIMessages.ContentPage_ftitle);
068: setDescription(PDEUIMessages.ContentPage_fdesc);
069: updateVersion(false);
070: fVersionPart = new PluginVersionPart(fNewVersion);
071: }
072:
073: /* (non-Javadoc)
074: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#createControl(org.eclipse.swt.widgets.Composite)
075: */
076: public void createControl(Composite parent) {
077: Composite container = new Composite(parent, SWT.NONE);
078: GridLayout layout = new GridLayout();
079: layout.verticalSpacing = 15;
080: container.setLayout(layout);
081:
082: createFragmentPropertiesGroup(container);
083: createParentPluginGroup(container);
084:
085: Dialog.applyDialogFont(container);
086: setControl(container);
087: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
088: IHelpContextIds.NEW_FRAGMENT_REQUIRED_DATA);
089: }
090:
091: public void createFragmentPropertiesGroup(Composite container) {
092: Group propertiesGroup = new Group(container, SWT.NONE);
093: propertiesGroup.setLayout(new GridLayout(2, false));
094: propertiesGroup.setLayoutData(new GridData(
095: GridData.FILL_HORIZONTAL));
096: propertiesGroup.setText(PDEUIMessages.ContentPage_fGroup);
097:
098: Label label = new Label(propertiesGroup, SWT.NONE);
099: label.setText(PDEUIMessages.ContentPage_fid);
100: fIdText = createText(propertiesGroup, propertiesListener);
101:
102: label = new Label(propertiesGroup, SWT.NONE);
103: label.setText(PDEUIMessages.ContentPage_fversion);
104: fVersionText = createText(propertiesGroup, propertiesListener);
105:
106: label = new Label(propertiesGroup, SWT.NONE);
107: label.setText(PDEUIMessages.ContentPage_fname);
108: fNameText = createText(propertiesGroup, propertiesListener);
109:
110: label = new Label(propertiesGroup, SWT.NONE);
111: label.setText(PDEUIMessages.ContentPage_fprovider);
112: fProviderText = createText(propertiesGroup, propertiesListener);
113:
114: fLibraryLabel = new Label(propertiesGroup, SWT.NONE);
115: fLibraryLabel
116: .setText(PDEUIMessages.ProjectStructurePage_library);
117: fLibraryText = createText(propertiesGroup, propertiesListener);
118: }
119:
120: private void createParentPluginGroup(Composite container) {
121: Group parentGroup = new Group(container, SWT.NONE);
122: parentGroup.setLayout(new GridLayout(2, false));
123: parentGroup
124: .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
125: parentGroup
126: .setText(PDEUIMessages.ContentPage_parentPluginGroup);
127:
128: fNotebook = new Composite(parentGroup, SWT.NONE);
129: GridData gd = new GridData(GridData.FILL_BOTH);
130: gd.horizontalSpan = 2;
131: fNotebook.setLayoutData(gd);
132: fNotebookLayout = new StackLayout();
133: fNotebook.setLayout(fNotebookLayout);
134:
135: fNewComp = createNewVersionComp(fNotebook);
136: fOldComp = createOldVersionComp(fNotebook);
137: fNotebookLayout.topControl = fNewVersion ? fNewComp : fOldComp;
138:
139: }
140:
141: private Composite createNewVersionComp(Composite notebook) {
142: Composite comp = new Composite(notebook, SWT.NONE);
143: GridLayout layout = new GridLayout(3, false);
144: layout.marginHeight = layout.marginWidth = 0;
145: comp.setLayout(layout);
146:
147: Label label = new Label(comp, SWT.NONE);
148: label.setText(PDEUIMessages.FragmentContentPage_pid);
149: fPluginIdText_newV = createPluginIdContainer(comp, true, 2);
150:
151: fVersionPart.createVersionFields(comp, false, true);
152: fVersionPart.addListeners(listener, listener);
153: return comp;
154: }
155:
156: private Composite createOldVersionComp(Composite notebook) {
157: Composite comp = new Composite(notebook, SWT.NONE);
158: GridLayout layout = new GridLayout(2, false);
159: layout.marginHeight = layout.marginWidth = 0;
160: comp.setLayout(layout);
161:
162: Label label = new Label(comp, SWT.NONE);
163: label.setText(PDEUIMessages.FragmentContentPage_pid);
164:
165: Composite container = new Composite(comp, SWT.NONE);
166: layout = new GridLayout(2, false);
167: layout.marginHeight = layout.marginWidth = 0;
168: container.setLayout(layout);
169: container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
170:
171: fPluginIdText_oldV = createPluginIdContainer(container, false,
172: 1);
173:
174: label = new Label(comp, SWT.NONE);
175: label.setText(PDEUIMessages.FragmentContentPage_pversion);
176: fPluginVersion = createText(comp, listener);
177:
178: label = new Label(comp, SWT.NONE);
179: label.setText(PDEUIMessages.ContentPage_matchRule);
180:
181: fMatchCombo = new Combo(comp, SWT.READ_ONLY | SWT.BORDER);
182: fMatchCombo
183: .setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
184: fMatchCombo.setItems(new String[] {
185: "", //$NON-NLS-1$
186: PDEUIMessages.ManifestEditor_MatchSection_equivalent,
187: PDEUIMessages.ManifestEditor_MatchSection_compatible,
188: PDEUIMessages.ManifestEditor_MatchSection_perfect,
189: PDEUIMessages.ManifestEditor_MatchSection_greater });
190: fMatchCombo.setText(fMatchCombo.getItem(0));
191: return comp;
192: }
193:
194: private Text createPluginIdContainer(Composite parent,
195: final boolean validateRange, int span) {
196: final Text pluginText = createText(parent, listener);
197:
198: Button browse = new Button(parent, SWT.PUSH);
199: browse.setText(PDEUIMessages.ContentPage_browse);
200: browse.setLayoutData(new GridData());
201: browse.addSelectionListener(new SelectionAdapter() {
202: public void widgetSelected(SelectionEvent e) {
203: BusyIndicator.showWhile(pluginText.getDisplay(),
204: new Runnable() {
205: public void run() {
206: PluginSelectionDialog dialog = new PluginSelectionDialog(
207: pluginText.getShell(), false,
208: false);
209: dialog.create();
210: if (dialog.open() == Window.OK) {
211: IPluginModel model = (IPluginModel) dialog
212: .getFirstResult();
213: IPlugin plugin = model.getPlugin();
214: String version = computeInitialPluginVersion(plugin
215: .getVersion());
216: if (validateRange) {
217: fVersionPart
218: .setVersion(version);
219: fVersionPart.preloadFields();
220: } else {
221: fPluginVersion.setText(version);
222: }
223: pluginText.setText(plugin.getId());
224: }
225: }
226: });
227: }
228: });
229: SWTUtil.setButtonDimensionHint(browse);
230: return pluginText;
231: }
232:
233: private String computeInitialPluginVersion(String pluginVersion) {
234: if (pluginVersion != null
235: && VersionUtil.validateVersion(pluginVersion).isOK()) {
236: Version pvi = Version.parseVersion(pluginVersion);
237: return pvi.getMajor() + "." + pvi.getMinor() //$NON-NLS-1$
238: + "." + pvi.getMicro(); //$NON-NLS-1$
239: }
240:
241: return pluginVersion;
242: }
243:
244: public void updateData() {
245: super .updateData();
246: String version;
247: if (fNewVersion) {
248: version = fVersionPart.getVersion();
249: ((FragmentFieldData) fData).setPluginId(fPluginIdText_newV
250: .getText().trim());
251: } else {
252: version = fPluginVersion.getText().trim();
253: ((FragmentFieldData) fData).setPluginId(fPluginIdText_oldV
254: .getText().trim());
255: ((FragmentFieldData) fData).setMatch(fMatchCombo
256: .getSelectionIndex());
257: }
258: ((FragmentFieldData) fData).setPluginVersion(version);
259: }
260:
261: /* (non-Javadoc)
262: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#validatePage()
263: */
264: protected void validatePage() {
265: String errorMessage = validateProperties();
266:
267: if (errorMessage == null) {
268: String pluginID = fNewVersion ? fPluginIdText_newV
269: .getText().trim() : fPluginIdText_oldV.getText()
270: .trim();
271: if (pluginID.length() == 0) {
272: errorMessage = PDEUIMessages.ContentPage_nopid;
273: } else if (!(PluginRegistry.findModel(pluginID) instanceof IPluginModel)) {
274: errorMessage = PDEUIMessages.ContentPage_pluginNotFound;
275: } else {
276: if (fNewVersion) {
277: IStatus status = fVersionPart
278: .validateFullVersionRangeText(false);
279: if (status.getSeverity() != IStatus.OK) {
280: errorMessage = status.getMessage();
281: }
282: } else {
283: errorMessage = validateVersion(fPluginVersion);
284: }
285: }
286: }
287: if (fInitialized)
288: setErrorMessage(errorMessage);
289: setPageComplete(errorMessage == null);
290: }
291:
292: /* (non-Javadoc)
293: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#getNameFieldQualifier()
294: */
295: protected String getNameFieldQualifier() {
296: return PDEUIMessages.ContentPage_fragment;
297: }
298:
299: /* (non-Javadoc)
300: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#setVisible(boolean)
301: */
302: public void setVisible(boolean visible) {
303: if (visible) {
304: fMainPage.updateData();
305: updateVersion(true);
306: }
307: super .setVisible(visible);
308: }
309:
310: private void updateVersion(boolean updateComposite) {
311: fNewVersion = Double.parseDouble(fData.getTargetVersion()) > 3.0;
312: if (updateComposite) {
313: Control oldPage = fNotebookLayout.topControl;
314: if (fNewVersion)
315: fNotebookLayout.topControl = fNewComp;
316: else
317: fNotebookLayout.topControl = fOldComp;
318: if (oldPage != fNotebookLayout.topControl)
319: fNotebook.layout();
320: }
321: }
322: }
|