Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 256731 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/pde/internal/ds/ui/messages.properties (+5 lines)
Lines 34-41 Link Here
34
DSFileWizardPage_browse=Browse...
34
DSFileWizardPage_browse=Browse...
35
DSFileWizardPage_selectType= Select Type
35
DSFileWizardPage_selectType= Select Type
36
DSFileWizardPage_not_OSGI_folder=By convention, component files should be located in OSGI-INF/ folder
36
DSFileWizardPage_not_OSGI_folder=By convention, component files should be located in OSGI-INF/ folder
37
DSFileWizardPage_createMethods=Generate &lifecycle methods
37
38
38
DSNewWizard_title=New Component Definition
39
DSNewWizard_title=New Component Definition
40
DSNewWizard_createOSGIFolder_title=Create OSGI-INF Folder
41
DSNewWizard_createOSGIFolder_message=Do you want to create the OSGI-INF folder? (recomended)
42
DSNewWizard_defaultOSGIFolder_title=OSGI-INF Folder
43
DSNewWizard_defaultOSGIFolder_message=Make OSGI-INF as default folder? (recomended)
39
44
40
DSImplementationDetails_title=Definition
45
DSImplementationDetails_title=Definition
41
DSImplementationDetails_description=Specify the service's implementation class:
46
DSImplementationDetails_description=Specify the service's implementation class:
(-)src/org/eclipse/pde/internal/ds/ui/Messages.java (+6 lines)
Lines 40-47 Link Here
40
	public static String DSFileWizardPage_browse;
40
	public static String DSFileWizardPage_browse;
41
	public static String DSFileWizardPage_selectType;
41
	public static String DSFileWizardPage_selectType;
42
	public static String DSFileWizardPage_not_OSGI_folder;
42
	public static String DSFileWizardPage_not_OSGI_folder;
43
	public static String DSFileWizardPage_createMethods;
43
	
44
	
44
	public static String DSNewWizard_title;
45
	public static String DSNewWizard_title;
46
	public static String DSNewWizard_createOSGIFolder_title;
47
	public static String DSNewWizard_createOSGIFolder_message;
48
	public static String DSNewWizard_defaultOSGIFolder_title;
49
	public static String DSNewWizard_defaultOSGIFolder_message;
45
	
50
	
46
	public static String DSImplementationDetails_title;
51
	public static String DSImplementationDetails_title;
47
	public static String DSImplementationDetails_description;
52
	public static String DSImplementationDetails_description;
Lines 165-170 Link Here
165
	
170
	
166
	public static String DSService_title;
171
	public static String DSService_title;
167
172
173
168
	
174
	
169
	
175
	
170
176
(-)src/org/eclipse/pde/internal/ds/ui/wizards/DSNewWizard.java (-5 / +127 lines)
Lines 14-28 Link Here
14
14
15
import java.lang.reflect.InvocationTargetException;
15
import java.lang.reflect.InvocationTargetException;
16
16
17
import org.eclipse.core.resources.IFolder;
18
import org.eclipse.core.resources.IProject;
19
import org.eclipse.core.resources.IResource;
20
import org.eclipse.core.runtime.CoreException;
21
import org.eclipse.core.runtime.NullProgressMonitor;
22
import org.eclipse.jdt.core.ICompilationUnit;
23
import org.eclipse.jdt.core.IJavaProject;
24
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.JavaModelException;
27
import org.eclipse.jdt.internal.core.JavaElement;
28
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
29
import org.eclipse.jface.dialogs.IDialogSettings;
30
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.jface.operation.IRunnableWithProgress;
31
import org.eclipse.jface.operation.IRunnableWithProgress;
18
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.IStructuredSelection;
33
import org.eclipse.jface.viewers.StructuredSelection;
19
import org.eclipse.jface.wizard.Wizard;
34
import org.eclipse.jface.wizard.Wizard;
20
import org.eclipse.pde.internal.ds.ui.Activator;
35
import org.eclipse.pde.internal.ds.ui.Activator;
21
import org.eclipse.pde.internal.ds.ui.Messages;
36
import org.eclipse.pde.internal.ds.ui.Messages;
37
import org.eclipse.pde.internal.ui.PDEPlugin;
22
import org.eclipse.ui.INewWizard;
38
import org.eclipse.ui.INewWizard;
23
import org.eclipse.ui.IWorkbench;
39
import org.eclipse.ui.IWorkbench;
24
40
25
public class DSNewWizard extends Wizard implements INewWizard {
41
public class DSNewWizard extends Wizard implements INewWizard {
42
	private static final String F_DefaultOSGIFolder_key = "default_folder";
43
	private static final String F_OSGI_FOLDER_NAME = "OSGI-INF";
26
	protected DSFileWizardPage fMainPage;
44
	protected DSFileWizardPage fMainPage;
27
45
28
	public DSNewWizard() {
46
	public DSNewWizard() {
Lines 32-59 Link Here
32
	/*
50
	/*
33
	 * (non-Javadoc)
51
	 * (non-Javadoc)
34
	 * 
52
	 * 
35
	 * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
53
	 * @see
54
	 * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
36
	 */
55
	 */
37
	public void addPages() {
56
	public void addPages() {
38
		 addPage(fMainPage);
57
		addPage(fMainPage);
39
	}
58
	}
40
	
59
41
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
60
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
42
		setWindowTitle(Messages.DSNewWizard_title);
61
		setWindowTitle(Messages.DSNewWizard_title);
62
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
63
		boolean value = false;
64
		if (this.getDialogSettings().get(F_DefaultOSGIFolder_key) == null) {
65
			value = MessageDialog.openQuestion(this.getShell(),
66
					Messages.DSNewWizard_defaultOSGIFolder_title,
67
					Messages.DSNewWizard_defaultOSGIFolder_message);
68
			this.getDialogSettings().put(F_DefaultOSGIFolder_key, value);
69
		} else {
70
			value = this.getDialogSettings().getBoolean(F_DefaultOSGIFolder_key);
71
		}
72
73
		currentSelection = setCurrentSelection(currentSelection);
74
43
		fMainPage = new DSFileWizardPage(currentSelection);
75
		fMainPage = new DSFileWizardPage(currentSelection);
44
	}
76
	}
45
77
78
	private IStructuredSelection setCurrentSelection(
79
			IStructuredSelection currentSelection) {
80
		if (currentSelection != null) {
81
			Object element = currentSelection.getFirstElement();
82
			if (element != null) {
83
				IProject project = getProject(element);
84
				if (project != null) {
85
					IResource findMember = project.findMember(F_OSGI_FOLDER_NAME);
86
					if (findMember != null) {
87
						if (findMember instanceof IFolder) {
88
							currentSelection = new StructuredSelection(
89
									findMember);
90
						}
91
					} else {
92
						if (MessageDialog
93
								.openQuestion(this.getShell(),
94
								Messages.DSNewWizard_createOSGIFolder_title,
95
								Messages.DSNewWizard_createOSGIFolder_message)) {
96
							IFolder folder = project.getFolder(F_OSGI_FOLDER_NAME);
97
							try {
98
								folder.create(false, true,
99
								 new NullProgressMonitor());
100
								currentSelection = new StructuredSelection(
101
										folder);
102
							} catch (CoreException e) {
103
							}
104
						}
105
					}
106
				}
107
			}
108
109
		}
110
		return currentSelection;
111
	}
112
113
	private IProject getProject(Object element) {
114
		IProject project = null;
115
		if (element instanceof IResource) {
116
			project = ((IResource) element).getProject();
117
		} else if (element instanceof JavaElement) {
118
			project = ((JavaElement) element).getJavaProject().getProject();
119
		} else if (element instanceof ClassPathContainer) {
120
			project = ((ClassPathContainer) element).getJavaProject()
121
					.getProject();
122
		}
123
		return project;
124
	}
125
46
	/*
126
	/*
47
	 * (non-Javadoc)
127
	 * (non-Javadoc)
48
	 * 
128
	 * 
49
	 * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish()
129
	 * @see
130
	 * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish
131
	 * ()
50
	 */
132
	 */
51
	public boolean performFinish() {
133
	public boolean performFinish() {
52
		try {
134
		try {
53
135
136
			String implementationClassValue = fMainPage
137
					.getDSImplementationClassValue();
138
			if (fMainPage.isGenerateMethodsButtonSelected()) {
139
				createMethods(implementationClassValue);
140
			}
141
142
			IDialogSettings settings = getDialogSettings();
143
			if (settings != null) {
144
				fMainPage.saveSettings(settings);
145
			}
54
			IRunnableWithProgress op = new DSCreationOperation(fMainPage
146
			IRunnableWithProgress op = new DSCreationOperation(fMainPage
55
					.createNewFile(), fMainPage.getDSComponentNameValue(),
147
					.createNewFile(), fMainPage.getDSComponentNameValue(),
56
					fMainPage.getDSImplementationClassValue());
148
					implementationClassValue);
57
149
58
			getContainer().run(false, true, op);
150
			getContainer().run(false, true, op);
59
		} catch (InvocationTargetException e) {
151
		} catch (InvocationTargetException e) {
Lines 61-67 Link Here
61
			return false;
153
			return false;
62
		} catch (InterruptedException e) {
154
		} catch (InterruptedException e) {
63
			return false;
155
			return false;
156
157
		} catch (JavaModelException e) {
158
			return false;
64
		}
159
		}
65
		return true;
160
		return true;
66
	}
161
	}
162
163
	private void createMethods(String implementationClassValue)
164
			throws JavaModelException {
165
166
		IJavaProject proj = JavaCore.create(fMainPage.getProject());
167
		IType saved_type = proj.findType(implementationClassValue);
168
		ICompilationUnit workingCU = saved_type.getCompilationUnit()
169
				.getWorkingCopy(new NullProgressMonitor());
170
171
		// create import
172
		String importString = "org.osgi.service.component.ComponentContext";//$NON-NLS-1$
173
		workingCU.createImport(importString, null, new NullProgressMonitor());
174
175
		// create methods
176
		IType workingType = workingCU.getType(saved_type.getElementName());
177
		String activateMethodString = "protected void activate(ComponentContext context) {\n" //$NON-NLS-1$
178
				+ "	// TODO Auto-generated method stub \n}";//$NON-NLS-1$
179
		String deactivateMethodString = "protected void deactivate(ComponentContext context) {\n" //$NON-NLS-1$
180
				+ "	// TODO Auto-generated method stub \n}";//$NON-NLS-1$
181
		workingType.createMethod(activateMethodString, null, false,
182
				new NullProgressMonitor());
183
		workingType.createMethod(deactivateMethodString, null, false,
184
				new NullProgressMonitor());
185
186
		workingCU.commitWorkingCopy(false, new NullProgressMonitor());
187
	}
188
67
}
189
}
(-)src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java (-13 / +116 lines)
Lines 20-25 Link Here
20
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
21
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
22
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IMethod;
23
import org.eclipse.jdt.core.IType;
24
import org.eclipse.jdt.core.IType;
24
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.search.SearchEngine;
26
import org.eclipse.jdt.core.search.SearchEngine;
Lines 27-32 Link Here
27
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
28
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
28
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
29
import org.eclipse.jdt.ui.IJavaElementSearchConstants;
29
import org.eclipse.jdt.ui.JavaUI;
30
import org.eclipse.jdt.ui.JavaUI;
31
import org.eclipse.jface.dialogs.IDialogSettings;
30
import org.eclipse.jface.viewers.IStructuredSelection;
32
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.window.Window;
33
import org.eclipse.jface.window.Window;
32
import org.eclipse.jface.wizard.WizardDialog;
34
import org.eclipse.jface.wizard.WizardDialog;
Lines 35-40 Link Here
35
import org.eclipse.pde.internal.ds.ui.Activator;
37
import org.eclipse.pde.internal.ds.ui.Activator;
36
import org.eclipse.pde.internal.ds.ui.Messages;
38
import org.eclipse.pde.internal.ds.ui.Messages;
37
import org.eclipse.pde.internal.ds.ui.SWTUtil;
39
import org.eclipse.pde.internal.ds.ui.SWTUtil;
40
import org.eclipse.pde.internal.ui.PDEPlugin;
38
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
41
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
39
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.SWT;
40
import org.eclipse.swt.events.ModifyEvent;
43
import org.eclipse.swt.events.ModifyEvent;
Lines 64-70 Link Here
64
67
65
	private static final String F_FILE_EXTENSION = "xml"; //$NON-NLS-1$
68
	private static final String F_FILE_EXTENSION = "xml"; //$NON-NLS-1$
66
69
67
	private static final String F_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$
70
	private static final String F_DEFAULT_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$
71
72
	private static final String F_COMPONENT_NAME = "component"; //$NON-NLS-1$
73
74
	private static final String F_GENERATE_METHODS = "generate_methods"; //$NON-NLS-1$
68
75
69
	private Group fGroup;
76
	private Group fGroup;
70
77
Lines 75-82 Link Here
75
	private Hyperlink fDSImplementationClassHyperlink;
82
	private Hyperlink fDSImplementationClassHyperlink;
76
	private Button fDSImplementationClassButton;
83
	private Button fDSImplementationClassButton;
77
84
85
	private Button fGenerateMethodsButton;
86
78
	private IStructuredSelection fSelection;
87
	private IStructuredSelection fSelection;
79
88
89
	private IProject project;
90
80
	public DSFileWizardPage(IStructuredSelection selection) {
91
	public DSFileWizardPage(IStructuredSelection selection) {
81
		super(F_PAGE_NAME, selection);
92
		super(F_PAGE_NAME, selection);
82
		this.fSelection = selection;
93
		this.fSelection = selection;
Lines 86-107 Link Here
86
	/*
97
	/*
87
	 * (non-Javadoc)
98
	 * (non-Javadoc)
88
	 * 
99
	 * 
89
	 * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#initialize()
100
	 * @see
101
	 * org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage
102
	 * #initialize()
90
	 */
103
	 */
91
	protected void initialize() {
104
	protected void initialize() {
92
		setTitle(Messages.DSFileWizardPage_title);
105
		setTitle(Messages.DSFileWizardPage_title);
93
		setDescription(Messages.DSFileWizardPage_description);
106
		setDescription(Messages.DSFileWizardPage_description);
94
		// Force the file extension to be 'xml'
107
		// Force the file extension to be 'xml'
95
		setFileExtension(F_FILE_EXTENSION);
108
		setFileExtension(F_FILE_EXTENSION);
96
		setFileName(F_COMPONENT_NAME);
97
	}
109
	}
98
110
99
	private void setComponentName() {
111
	private void setComponentName() {
100
		Object element = fSelection.getFirstElement();
112
		if (fSelection != null) {
101
		if (element != null) {
113
			Object element = fSelection.getFirstElement();
102
			IProject project = getProject(element);
114
			if (element != null) {
103
			if (project != null)
115
				IProject project = getProject(element);
104
				setComponentNameText(project);
116
				if (project != null)
117
					setComponentNameText(project);
118
			}
105
		}
119
		}
106
	}
120
	}
107
121
Lines 115-120 Link Here
115
			project = ((ClassPathContainer) element).getJavaProject()
129
			project = ((ClassPathContainer) element).getJavaProject()
116
					.getProject();
130
					.getProject();
117
		}
131
		}
132
		this.project = project;
133
		return project;
134
	}
135
136
	public IProject getProject() {
118
		return project;
137
		return project;
119
	}
138
	}
120
139
Lines 134-139 Link Here
134
	}
153
	}
135
154
136
	protected void createAdvancedControls(Composite parent) {
155
	protected void createAdvancedControls(Composite parent) {
156
		IDialogSettings settings = getDialogSettings();
157
		if (settings != null) {
158
			String component = settings.get(F_COMPONENT_NAME);
159
			if (component != null && !component.equals("")) {
160
				setFileName(component);
161
			} else {
162
				setFileName(F_DEFAULT_COMPONENT_NAME);
163
			}
164
		} else {
165
			setFileName(F_DEFAULT_COMPONENT_NAME);
166
		}
137
167
138
		// Controls Group
168
		// Controls Group
139
		fGroup = new Group(parent, SWT.NONE);
169
		fGroup = new Group(parent, SWT.NONE);
Lines 153-162 Link Here
153
		fDSComponentNameText.setText(""); //$NON-NLS-1$
183
		fDSComponentNameText.setText(""); //$NON-NLS-1$
154
		fDSComponentNameText.addModifyListener(new ModifyListener() {
184
		fDSComponentNameText.addModifyListener(new ModifyListener() {
155
			public void modifyText(ModifyEvent e) {
185
			public void modifyText(ModifyEvent e) {
156
				setPageComplete(checkPageComplete());
186
				setPageComplete(isPageComplete());
157
			}
187
			}
158
		});
188
		});
159
		setComponentName();
160
189
161
		fDSImplementationClassHyperlink = new Hyperlink(fGroup, SWT.NONE);
190
		fDSImplementationClassHyperlink = new Hyperlink(fGroup, SWT.NONE);
162
		fDSImplementationClassHyperlink
191
		fDSImplementationClassHyperlink
Lines 236-242 Link Here
236
		fDSImplementationClassText.setText(""); //$NON-NLS-1$
265
		fDSImplementationClassText.setText(""); //$NON-NLS-1$
237
		fDSImplementationClassText.addModifyListener(new ModifyListener() {
266
		fDSImplementationClassText.addModifyListener(new ModifyListener() {
238
			public void modifyText(ModifyEvent e) {
267
			public void modifyText(ModifyEvent e) {
239
				setPageComplete(checkPageComplete());
268
				setPageComplete(isPageComplete());
240
			}
269
			}
241
		});
270
		});
242
271
Lines 277-282 Link Here
277
			}
306
			}
278
		});
307
		});
279
308
309
		fGenerateMethodsButton = new Button(fGroup, SWT.CHECK);
310
		fGenerateMethodsButton.setText(Messages.DSFileWizardPage_createMethods);
311
		fGenerateMethodsButton.setEnabled(false);
312
		fGenerateMethodsButton.setSelection(false);
313
314
		setComponentName();
315
		validatePage();
280
	}
316
	}
281
317
282
	public String getDSComponentNameValue() {
318
	public String getDSComponentNameValue() {
Lines 298-304 Link Here
298
	/*
334
	/*
299
	 * (non-Javadoc)
335
	 * (non-Javadoc)
300
	 * 
336
	 * 
301
	 * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validateLinkedResource()
337
	 * @see
338
	 * org.eclipse.ui.dialogs.WizardNewFileCreationPage#validateLinkedResource()
302
	 */
339
	 */
303
	protected IStatus validateLinkedResource() {
340
	protected IStatus validateLinkedResource() {
304
		return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$
341
		return new Status(IStatus.OK, Activator.PLUGIN_ID, IStatus.OK, "", null); //$NON-NLS-1$
Lines 309-315 Link Here
309
	}
346
	}
310
347
311
	public boolean isPageComplete() {
348
	public boolean isPageComplete() {
312
		return checkPageComplete();
349
		updateCreateMethodsButton();
350
		return checkPageComplete() & validatePage();
313
	}
351
	}
314
352
353
	public void saveSettings(IDialogSettings settings) {
354
		settings.put(F_COMPONENT_NAME, getFileName());
355
		if (fGenerateMethodsButton.isEnabled()) {
356
			settings.put(F_GENERATE_METHODS, fGenerateMethodsButton
357
					.getSelection());
358
		}
359
360
	}
361
362
	protected boolean validatePage() {
363
		if (fDSImplementationClassText != null) {
364
			IStatus status = PDEPlugin.getWorkspace().validateName(
365
					fDSImplementationClassText.getText(), IResource.FILE);
366
			if (!status.isOK()) {
367
				setErrorMessage(status.getMessage());
368
				return false;
369
			}
370
		}
371
		return super.validatePage();
372
	}
373
374
	private void updateCreateMethodsButton() {
375
		boolean wasDisabled = !fGenerateMethodsButton.isEnabled();
376
		try {
377
			IType type = JavaCore.create(this.getProject()).findType(
378
					this.getDSImplementationClassValue());
379
			if (type != null) {
380
				IMethod methodActivate = type.getMethod("activate", //$NON-NLS-1$
381
						new String[] { "QComponentContext;" }); //$NON-NLS-1$
382
				IMethod methodDeactivate = type.getMethod("deactivate", //$NON-NLS-1$
383
						new String[] { "QComponentContext;" }); //$NON-NLS-1$
384
				if (type.findMethods(methodActivate) == null
385
						&& type.findMethods(methodDeactivate) == null) {
386
					if (wasDisabled) {
387
						enableAndToggleGenerateButton();
388
					}
389
					return;
390
				}
391
			}
392
		} catch (Exception e) {
393
		}
394
		fGenerateMethodsButton.setEnabled(false);
395
		fGenerateMethodsButton.setSelection(false);
396
397
	}
398
399
	private void enableAndToggleGenerateButton() {
400
		fGenerateMethodsButton.setEnabled(true);
401
		IDialogSettings settings = getDialogSettings();
402
		if (settings != null) {
403
			if (settings.get(F_GENERATE_METHODS) != null) {
404
				fGenerateMethodsButton.setSelection(settings
405
						.getBoolean(F_GENERATE_METHODS));
406
407
			} else {
408
				fGenerateMethodsButton.setSelection(true);
409
			}
410
		} else {
411
			fGenerateMethodsButton.setSelection(true);
412
		}
413
	}
414
415
	public boolean isGenerateMethodsButtonSelected() {
416
		return fGenerateMethodsButton.getSelection();
417
	}
315
}
418
}

Return to bug 256731