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 java.util.Locale;
013:
014: import org.eclipse.core.runtime.IStatus;
015: import org.eclipse.jdt.core.JavaConventions;
016: import org.eclipse.jface.dialogs.Dialog;
017: import org.eclipse.jface.dialogs.IDialogSettings;
018: import org.eclipse.jface.dialogs.IMessageProvider;
019: import org.eclipse.jface.resource.JFaceResources;
020: import org.eclipse.pde.internal.core.util.PDEJavaHelper;
021: import org.eclipse.pde.internal.ui.IHelpContextIds;
022: import org.eclipse.pde.internal.ui.PDEUIMessages;
023: import org.eclipse.pde.internal.ui.wizards.IProjectProvider;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.events.ModifyEvent;
026: import org.eclipse.swt.events.ModifyListener;
027: import org.eclipse.swt.events.SelectionAdapter;
028: import org.eclipse.swt.events.SelectionEvent;
029: import org.eclipse.swt.layout.GridData;
030: import org.eclipse.swt.layout.GridLayout;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Group;
034: import org.eclipse.swt.widgets.Label;
035: import org.eclipse.swt.widgets.Text;
036: import org.eclipse.ui.PlatformUI;
037:
038: public class PluginContentPage extends ContentPage {
039: protected final static int P_CLASS_GROUP = 2;
040:
041: private Text fClassText;
042: private Button fGenerateClass;
043: private Button fUIPlugin;
044: private Label fClassLabel;
045:
046: private Label fLabel;
047: private Button fYesButton;
048: private Button fNoButton;
049:
050: private final static String S_GENERATE_ACTIVATOR = "generateActivator"; //$NON-NLS-1$
051: private final static String S_UI_PLUGIN = "uiPlugin"; //$NON-NLS-1$
052: private final static String S_RCP_PLUGIN = "rcpPlugin"; //$NON-NLS-1$
053:
054: private ModifyListener classListener = new ModifyListener() {
055: public void modifyText(ModifyEvent e) {
056: if (fInitialized)
057: fChangedGroups |= P_CLASS_GROUP;
058: validatePage();
059: }
060: };
061:
062: private Group fRCPGroup;
063:
064: public PluginContentPage(String pageName,
065: IProjectProvider provider, NewProjectCreationPage page,
066: AbstractFieldData data) {
067: super (pageName, provider, page, data);
068: setTitle(PDEUIMessages.ContentPage_title);
069: setDescription(PDEUIMessages.ContentPage_desc);
070: }
071:
072: /* (non-Javadoc)
073: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#createControl(org.eclipse.swt.widgets.Composite)
074: */
075: public void createControl(Composite parent) {
076: Composite container = new Composite(parent, SWT.NONE);
077: container.setLayout(new GridLayout());
078:
079: createPluginPropertiesGroup(container);
080: createPluginClassGroup(container);
081: createRCPGroup(container);
082:
083: Dialog.applyDialogFont(container);
084: setControl(container);
085: PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(),
086: IHelpContextIds.NEW_PROJECT_REQUIRED_DATA);
087: }
088:
089: private void createPluginPropertiesGroup(Composite container) {
090: Group propertiesGroup = new Group(container, SWT.NONE);
091: propertiesGroup.setLayout(new GridLayout(2, false));
092: propertiesGroup.setLayoutData(new GridData(
093: GridData.FILL_HORIZONTAL));
094: propertiesGroup.setText(PDEUIMessages.ContentPage_pGroup);
095:
096: Label label = new Label(propertiesGroup, SWT.NONE);
097: label.setText(PDEUIMessages.ContentPage_pid);
098: fIdText = createText(propertiesGroup, propertiesListener);
099:
100: label = new Label(propertiesGroup, SWT.NONE);
101: label.setText(PDEUIMessages.ContentPage_pversion);
102: fVersionText = createText(propertiesGroup, propertiesListener);
103:
104: label = new Label(propertiesGroup, SWT.NONE);
105: label.setText(PDEUIMessages.ContentPage_pname);
106: fNameText = createText(propertiesGroup, propertiesListener);
107:
108: label = new Label(propertiesGroup, SWT.NONE);
109: label.setText(PDEUIMessages.ContentPage_pprovider);
110: fProviderText = createText(propertiesGroup, propertiesListener);
111:
112: fLibraryLabel = new Label(propertiesGroup, SWT.NONE);
113: fLibraryLabel
114: .setText(PDEUIMessages.ProjectStructurePage_library);
115: fLibraryText = createText(propertiesGroup, propertiesListener);
116: }
117:
118: private void createPluginClassGroup(Composite container) {
119: Group classGroup = new Group(container, SWT.NONE);
120: classGroup.setLayout(new GridLayout(2, false));
121: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
122: gd.horizontalSpan = 2;
123: classGroup.setLayoutData(gd);
124: classGroup.setText(PDEUIMessages.ContentPage_pClassGroup);
125:
126: IDialogSettings settings = getDialogSettings();
127:
128: fGenerateClass = new Button(classGroup, SWT.CHECK);
129: fGenerateClass.setText(PDEUIMessages.ContentPage_generate);
130: fGenerateClass.setSelection((settings != null) ? !settings
131: .getBoolean(S_GENERATE_ACTIVATOR) : true);
132: gd = new GridData();
133: gd.horizontalSpan = 2;
134: fGenerateClass.setLayoutData(gd);
135: fGenerateClass.addSelectionListener(new SelectionAdapter() {
136: public void widgetSelected(SelectionEvent e) {
137: fClassLabel.setEnabled(fGenerateClass.getSelection());
138: fClassText.setEnabled(fGenerateClass.getSelection());
139: updateData();
140: validatePage();
141: }
142: });
143:
144: fClassLabel = new Label(classGroup, SWT.NONE);
145: fClassLabel.setText(PDEUIMessages.ContentPage_classname);
146: gd = new GridData();
147: gd.horizontalIndent = 20;
148: fClassLabel.setLayoutData(gd);
149: fClassText = createText(classGroup, classListener);
150:
151: fUIPlugin = new Button(classGroup, SWT.CHECK);
152: fUIPlugin.setText(PDEUIMessages.ContentPage_uicontribution);
153: fUIPlugin.setSelection((settings != null) ? !settings
154: .getBoolean(S_UI_PLUGIN) : true);
155: gd = new GridData();
156: gd.horizontalSpan = 2;
157: fUIPlugin.setLayoutData(gd);
158: fUIPlugin.addSelectionListener(new SelectionAdapter() {
159: public void widgetSelected(SelectionEvent e) {
160: updateData();
161: validatePage();
162: }
163: });
164: }
165:
166: public void updateData() {
167: super .updateData();
168: PluginFieldData data = (PluginFieldData) fData;
169: data.setClassname(fClassText.getText().trim());
170: data.setUIPlugin(fUIPlugin.getSelection());
171: data.setDoGenerateClass(fGenerateClass.isEnabled()
172: && fGenerateClass.getSelection());
173: data.setRCPApplicationPlugin(!fData.isSimple() && !isPureOSGi()
174: && fYesButton.getSelection());
175: }
176:
177: private void createRCPGroup(Composite container) {
178: fRCPGroup = new Group(container, SWT.NONE);
179: fRCPGroup.setLayout(new GridLayout(2, false));
180: fRCPGroup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
181: fRCPGroup.setText(PDEUIMessages.PluginContentPage_rcpGroup);
182:
183: createRCPQuestion(fRCPGroup, 2);
184: }
185:
186: private void createRCPQuestion(Composite parent, int horizontalSpan) {
187: Composite comp = new Composite(parent, SWT.NONE);
188: GridLayout layout = new GridLayout(3, false);
189: layout.marginHeight = layout.marginWidth = 0;
190: comp.setLayout(layout);
191: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
192: gd.horizontalSpan = horizontalSpan;
193: comp.setLayoutData(gd);
194:
195: fLabel = new Label(comp, SWT.NONE);
196: fLabel.setText(PDEUIMessages.PluginContentPage_appQuestion);
197: fLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
198:
199: IDialogSettings settings = getDialogSettings();
200: boolean rcpApp = (settings != null) ? settings
201: .getBoolean(S_RCP_PLUGIN) : false;
202:
203: fYesButton = new Button(comp, SWT.RADIO);
204: fYesButton.setText(PDEUIMessages.PluginContentPage_yes);
205: fYesButton.setSelection(rcpApp);
206: gd = new GridData();
207: gd.widthHint = getButtonWidthHint(fYesButton);
208: fYesButton.setLayoutData(gd);
209: fYesButton.addSelectionListener(new SelectionAdapter() {
210: public void widgetSelected(SelectionEvent e) {
211: updateData();
212: getContainer().updateButtons();
213: }
214: });
215:
216: fNoButton = new Button(comp, SWT.RADIO);
217: fNoButton.setText(PDEUIMessages.PluginContentPage_no);
218: fNoButton.setSelection(!rcpApp);
219: gd = new GridData();
220: gd.widthHint = getButtonWidthHint(fNoButton);
221: fNoButton.setLayoutData(gd);
222: }
223:
224: /* (non-Javadoc)
225: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#setVisible(boolean)
226: */
227: public void setVisible(boolean visible) {
228: if (visible) {
229: fMainPage.updateData();
230: fGenerateClass.setEnabled(!fData.isSimple());
231: fClassLabel.setEnabled(!fData.isSimple()
232: && fGenerateClass.getSelection());
233: fClassText.setEnabled(!fData.isSimple()
234: && fGenerateClass.getSelection());
235: boolean wasUIPluginEnabled = fUIPlugin.isEnabled();
236: fUIPlugin.setEnabled(!fData.isSimple() && !isPureOSGi());
237: // if fUIPlugin is disabled, set selection to false
238: if (!fUIPlugin.isEnabled()) {
239: fUIPlugin.setSelection(false);
240: }
241: // if the fUIPlugin was disabled and is now enabled, then set the selection to true
242: else if (!wasUIPluginEnabled) {
243: fUIPlugin.setSelection(true);
244: }
245:
246: // plugin class group
247: if (((fChangedGroups & P_CLASS_GROUP) == 0)) {
248: int oldfChanged = fChangedGroups;
249: fClassText.setText(computeId().toLowerCase(
250: Locale.ENGLISH)
251: + ".Activator"); //$NON-NLS-1$
252: fChangedGroups = oldfChanged;
253: }
254: fRCPGroup.setVisible(!fData.isSimple() && !isPureOSGi());
255: }
256: super .setVisible(visible);
257: }
258:
259: private boolean isPureOSGi() {
260: return ((PluginFieldData) fData).getOSGiFramework() != null;
261: }
262:
263: /* (non-Javadoc)
264: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#validatePage()
265: */
266: protected void validatePage() {
267: String errorMessage = validateProperties();
268: if (errorMessage == null && fGenerateClass.isEnabled()
269: && fGenerateClass.getSelection()) {
270: IStatus status = JavaConventions.validateJavaTypeName(
271: fClassText.getText().trim(), PDEJavaHelper
272: .getJavaSourceLevel(null), PDEJavaHelper
273: .getJavaComplianceLevel(null));
274: if (status.getSeverity() == IStatus.ERROR) {
275: errorMessage = status.getMessage();
276: } else if (status.getSeverity() == IStatus.WARNING) {
277: setMessage(status.getMessage(),
278: IMessageProvider.WARNING);
279: }
280: }
281: setErrorMessage(errorMessage);
282: setPageComplete(errorMessage == null);
283: }
284:
285: /* (non-Javadoc)
286: * @see org.eclipse.pde.internal.ui.wizards.plugin.ContentPage#getNameFieldQualifier()
287: */
288: protected String getNameFieldQualifier() {
289: return PDEUIMessages.ContentPage_plugin;
290: }
291:
292: private static int getButtonWidthHint(Button button) {
293: if (button.getFont().equals(JFaceResources.getDefaultFont()))
294: button.setFont(JFaceResources.getDialogFont());
295: return Math.max(50, button.computeSize(SWT.DEFAULT,
296: SWT.DEFAULT, true).x);
297: }
298:
299: protected void saveSettings(IDialogSettings settings) {
300: settings.put(S_GENERATE_ACTIVATOR, !fGenerateClass
301: .getSelection());
302: if (fUIPlugin.isEnabled())
303: settings.put(S_UI_PLUGIN, !fUIPlugin.getSelection());
304: settings.put(S_RCP_PLUGIN, fYesButton.getSelection());
305: }
306: }
|