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/wizards/DSNewWizard.java (-6 / +159 lines)
Lines 14-29 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.IJavaElement;
24
import org.eclipse.jdt.core.IJavaProject;
25
import org.eclipse.jdt.core.IMethod;
26
import org.eclipse.jdt.core.IType;
27
import org.eclipse.jdt.core.JavaCore;
28
import org.eclipse.jdt.core.JavaModelException;
29
import org.eclipse.jdt.internal.core.JavaElement;
30
import org.eclipse.jdt.internal.ui.packageview.ClassPathContainer;
31
import org.eclipse.jdt.ui.JavaUI;
17
import org.eclipse.jface.dialogs.IDialogSettings;
32
import org.eclipse.jface.dialogs.IDialogSettings;
18
import org.eclipse.jface.operation.IRunnableWithProgress;
33
import org.eclipse.jface.operation.IRunnableWithProgress;
19
import org.eclipse.jface.viewers.IStructuredSelection;
34
import org.eclipse.jface.viewers.IStructuredSelection;
35
import org.eclipse.jface.viewers.StructuredSelection;
20
import org.eclipse.jface.wizard.Wizard;
36
import org.eclipse.jface.wizard.Wizard;
21
import org.eclipse.pde.internal.ds.ui.Activator;
37
import org.eclipse.pde.internal.ds.ui.Activator;
22
import org.eclipse.pde.internal.ds.ui.Messages;
38
import org.eclipse.pde.internal.ds.ui.Messages;
39
import org.eclipse.pde.internal.ds.ui.parts.HandyPromptDialog;
40
import org.eclipse.pde.internal.ui.PDEPlugin;
41
import org.eclipse.ui.IEditorPart;
23
import org.eclipse.ui.INewWizard;
42
import org.eclipse.ui.INewWizard;
24
import org.eclipse.ui.IWorkbench;
43
import org.eclipse.ui.IWorkbench;
44
import org.eclipse.ui.PartInitException;
25
45
26
public class DSNewWizard extends Wizard implements INewWizard {
46
public class DSNewWizard extends Wizard implements INewWizard {
47
	private static final String F_createOSGIFolder_key = "create_folder"; //$NON-NLS-1$
48
	private static final String F_OSGI_FOLDER_NAME = "OSGI-INF"; //$NON-NLS-1$
27
	protected DSFileWizardPage fMainPage;
49
	protected DSFileWizardPage fMainPage;
28
50
29
	public DSNewWizard() {
51
	public DSNewWizard() {
Lines 33-64 Link Here
33
	/*
55
	/*
34
	 * (non-Javadoc)
56
	 * (non-Javadoc)
35
	 * 
57
	 * 
36
	 * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
58
	 * @see
59
	 * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#addPages()
37
	 */
60
	 */
38
	public void addPages() {
61
	public void addPages() {
39
		 addPage(fMainPage);
62
		addPage(fMainPage);
40
	}
63
	}
41
	
64
42
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
65
	public void init(IWorkbench workbench, IStructuredSelection currentSelection) {
43
		setWindowTitle(Messages.DSNewWizard_title);
66
		setWindowTitle(Messages.DSNewWizard_title);
44
		setDialogSettings(Activator.getDefault().getDialogSettings());
67
		setDialogSettings(PDEPlugin.getDefault().getDialogSettings());
68
		currentSelection = getOSGIFolderSelection(currentSelection);
45
		fMainPage = new DSFileWizardPage(currentSelection);
69
		fMainPage = new DSFileWizardPage(currentSelection);
46
	}
70
	}
47
71
72
	private IStructuredSelection getOSGIFolderSelection(
73
			IStructuredSelection currentSelection) {
74
		if (currentSelection != null) {
75
			Object element = currentSelection.getFirstElement();
76
			if (element != null) {
77
				IProject project = getProject(element);
78
				if (project != null) {
79
					IResource findMember = project
80
							.findMember(F_OSGI_FOLDER_NAME);
81
					if (findMember != null) {
82
						if (findMember instanceof IFolder) {
83
							currentSelection = new StructuredSelection(
84
									findMember);
85
						}
86
					} else {
87
						currentSelection = getNewFolderPath(currentSelection,
88
								project);
89
					}
90
				}
91
			}
92
93
		}
94
		return currentSelection;
95
	}
96
97
	private IStructuredSelection getNewFolderPath(
98
			IStructuredSelection currentSelection, IProject project) {
99
		if (this.getDialogSettings().get(F_createOSGIFolder_key) == null) {
100
			// show dialog
101
			HandyPromptDialog dialog = new HandyPromptDialog(this.getShell(),
102
					Messages.DSNewWizard_createOSGIFolder_message);
103
			dialog.setCancelButtonText(null);
104
			dialog.setTitle(Messages.DSNewWizard_createOSGIFolder_title);
105
			int checkboxId = dialog.addCheckbox(
106
					Messages.DSNewWizard_RememberMyDecision, false);
107
			dialog.open();
108
109
			// return osgiFolder selection if yes button was selected
110
			boolean value = dialog.getReturnCode() == HandyPromptDialog.YES_ID;
111
			if (value) {
112
				IFolder folder = project.getFolder(F_OSGI_FOLDER_NAME);
113
				try {
114
					folder.create(false, true, new NullProgressMonitor());
115
					currentSelection = new StructuredSelection(folder);
116
				} catch (CoreException e) {
117
				}
118
			}
119
			// save user option selection if checkbox was selected
120
			if (dialog.isCheckboxSelected(checkboxId)) {
121
				this.getDialogSettings().put(F_createOSGIFolder_key, value);
122
			}
123
		} else {
124
			if (this.getDialogSettings().getBoolean(F_createOSGIFolder_key)) {
125
				IFolder folder = project.getFolder(F_OSGI_FOLDER_NAME);
126
				try {
127
					folder.create(false, true, new NullProgressMonitor());
128
					currentSelection = new StructuredSelection(folder);
129
				} catch (CoreException e) {
130
				}
131
			}
132
		}
133
		return currentSelection;
134
	}
135
136
	private IProject getProject(Object element) {
137
		IProject project = null;
138
		if (element instanceof IResource) {
139
			project = ((IResource) element).getProject();
140
		} else if (element instanceof JavaElement) {
141
			project = ((JavaElement) element).getJavaProject().getProject();
142
		} else if (element instanceof ClassPathContainer) {
143
			project = ((ClassPathContainer) element).getJavaProject()
144
					.getProject();
145
		}
146
		return project;
147
	}
148
48
	/*
149
	/*
49
	 * (non-Javadoc)
150
	 * (non-Javadoc)
50
	 * 
151
	 * 
51
	 * @see org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish()
152
	 * @see
153
	 * org.eclipse.ui.wizards.newresource.BasicNewFileResourceWizard#performFinish
154
	 * ()
52
	 */
155
	 */
53
	public boolean performFinish() {
156
	public boolean performFinish() {
54
		try {
157
		try {
158
159
			String implementationClassValue = fMainPage
160
					.getDSImplementationClassValue();
161
			if (fMainPage.isGenerateMethodsButtonSelected()) {
162
				IMethod firstMethod = createMethods(implementationClassValue);
163
				openInJavaEditor(firstMethod);
164
			}
165
55
			IDialogSettings settings = getDialogSettings();
166
			IDialogSettings settings = getDialogSettings();
56
			if (settings != null) {
167
			if (settings != null) {
57
				fMainPage.saveSettings(settings);
168
				fMainPage.saveSettings(settings);
58
			}
169
			}
59
			IRunnableWithProgress op = new DSCreationOperation(fMainPage
170
			IRunnableWithProgress op = new DSCreationOperation(fMainPage
60
					.createNewFile(), fMainPage.getDSComponentNameValue(),
171
					.createNewFile(), fMainPage.getDSComponentNameValue(),
61
					fMainPage.getDSImplementationClassValue());
172
					implementationClassValue);
62
173
63
			getContainer().run(false, true, op);
174
			getContainer().run(false, true, op);
64
		} catch (InvocationTargetException e) {
175
		} catch (InvocationTargetException e) {
Lines 66-72 Link Here
66
			return false;
177
			return false;
67
		} catch (InterruptedException e) {
178
		} catch (InterruptedException e) {
68
			return false;
179
			return false;
180
		} catch (JavaModelException e) {
181
			return false;
182
		} catch (PartInitException e) {
183
			return false;
69
		}
184
		}
70
		return true;
185
		return true;
71
	}
186
	}
187
188
	private void openInJavaEditor(IMethod firstMethod)
189
			throws JavaModelException, PartInitException {
190
		if (firstMethod != null) {
191
			IEditorPart javaEditor;
192
			javaEditor = JavaUI.openInEditor(firstMethod.getCompilationUnit());
193
			JavaUI.revealInEditor(javaEditor, (IJavaElement) firstMethod);
194
		}
195
	}
196
197
	private IMethod createMethods(String implementationClassValue)
198
			throws JavaModelException {
199
200
		IJavaProject proj = JavaCore.create(fMainPage.getProject());
201
		IType saved_type = proj.findType(implementationClassValue);
202
		ICompilationUnit workingCU = saved_type.getCompilationUnit()
203
				.getWorkingCopy(new NullProgressMonitor());
204
205
		// create import
206
		String importString = "org.osgi.service.component.ComponentContext";//$NON-NLS-1$
207
		workingCU.createImport(importString, null, new NullProgressMonitor());
208
209
		// create methods
210
		IType workingType = workingCU.getType(saved_type.getElementName());
211
		String activateMethodString = "protected void activate(ComponentContext context) {\n" //$NON-NLS-1$
212
				+ "	// TODO Auto-generated method stub \n}";//$NON-NLS-1$
213
		String deactivateMethodString = "protected void deactivate(ComponentContext context) {\n" //$NON-NLS-1$
214
				+ "	// TODO Auto-generated method stub \n}";//$NON-NLS-1$
215
		IMethod first_method = workingType.createMethod(activateMethodString,
216
				null, false, new NullProgressMonitor());
217
		workingType.createMethod(deactivateMethodString, null, false,
218
				new NullProgressMonitor());
219
220
		workingCU.commitWorkingCopy(false, new NullProgressMonitor());
221
		return first_method;
222
223
	}
224
72
}
225
}
(-)src/org/eclipse/pde/internal/ds/ui/wizards/DSFileWizardPage.java (-23 / +95 lines)
Lines 15-26 Link Here
15
15
16
import org.eclipse.core.resources.IProject;
16
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IResource;
17
import org.eclipse.core.resources.IResource;
18
import org.eclipse.core.resources.ResourcesPlugin;
19
import org.eclipse.core.runtime.CoreException;
18
import org.eclipse.core.runtime.CoreException;
20
import org.eclipse.core.runtime.IStatus;
19
import org.eclipse.core.runtime.IStatus;
21
import org.eclipse.core.runtime.Status;
20
import org.eclipse.core.runtime.Status;
22
import org.eclipse.jdt.core.IJavaElement;
21
import org.eclipse.jdt.core.IJavaElement;
23
import org.eclipse.jdt.core.IJavaProject;
22
import org.eclipse.jdt.core.IJavaProject;
23
import org.eclipse.jdt.core.IMethod;
24
import org.eclipse.jdt.core.IType;
24
import org.eclipse.jdt.core.IType;
25
import org.eclipse.jdt.core.JavaCore;
25
import org.eclipse.jdt.core.JavaCore;
26
import org.eclipse.jdt.core.search.SearchEngine;
26
import org.eclipse.jdt.core.search.SearchEngine;
Lines 37-42 Link Here
37
import org.eclipse.pde.internal.ds.ui.Activator;
37
import org.eclipse.pde.internal.ds.ui.Activator;
38
import org.eclipse.pde.internal.ds.ui.Messages;
38
import org.eclipse.pde.internal.ds.ui.Messages;
39
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;
40
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
41
import org.eclipse.pde.internal.ui.util.PDEModelUtility;
41
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.SWT;
42
import org.eclipse.swt.events.ModifyEvent;
43
import org.eclipse.swt.events.ModifyEvent;
Lines 68-74 Link Here
68
69
69
	private static final String F_DEFAULT_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$
70
	private static final String F_DEFAULT_COMPONENT_NAME = "component.xml"; //$NON-NLS-1$
70
71
71
	private static final String S_COMPONENT_NAME = "component"; //$NON-NLS-1$
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$
72
75
73
	private Group fGroup;
76
	private Group fGroup;
74
77
Lines 79-86 Link Here
79
	private Hyperlink fDSImplementationClassHyperlink;
82
	private Hyperlink fDSImplementationClassHyperlink;
80
	private Button fDSImplementationClassButton;
83
	private Button fDSImplementationClassButton;
81
84
85
	private Button fGenerateMethodsButton;
86
82
	private IStructuredSelection fSelection;
87
	private IStructuredSelection fSelection;
83
88
89
	private IProject project;
90
84
	public DSFileWizardPage(IStructuredSelection selection) {
91
	public DSFileWizardPage(IStructuredSelection selection) {
85
		super(F_PAGE_NAME, selection);
92
		super(F_PAGE_NAME, selection);
86
		this.fSelection = selection;
93
		this.fSelection = selection;
Lines 90-96 Link Here
90
	/*
97
	/*
91
	 * (non-Javadoc)
98
	 * (non-Javadoc)
92
	 * 
99
	 * 
93
	 * @see org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage#initialize()
100
	 * @see
101
	 * org.eclipse.pde.internal.ui.wizards.cheatsheet.CheatSheetFileWizardPage
102
	 * #initialize()
94
	 */
103
	 */
95
	protected void initialize() {
104
	protected void initialize() {
96
		setTitle(Messages.DSFileWizardPage_title);
105
		setTitle(Messages.DSFileWizardPage_title);
Lines 100-110 Link Here
100
	}
109
	}
101
110
102
	private void setComponentName() {
111
	private void setComponentName() {
103
		Object element = fSelection.getFirstElement();
112
		if (fSelection != null) {
104
		if (element != null) {
113
			Object element = fSelection.getFirstElement();
105
			IProject project = getProject(element);
114
			if (element != null) {
106
			if (project != null)
115
				IProject project = getProject(element);
107
				setComponentNameText(project);
116
				if (project != null)
117
					setComponentNameText(project);
118
			}
108
		}
119
		}
109
	}
120
	}
110
121
Lines 118-123 Link Here
118
			project = ((ClassPathContainer) element).getJavaProject()
129
			project = ((ClassPathContainer) element).getJavaProject()
119
					.getProject();
130
					.getProject();
120
		}
131
		}
132
		this.project = project;
133
		return project;
134
	}
135
136
	public IProject getProject() {
121
		return project;
137
		return project;
122
	}
138
	}
123
139
Lines 139-146 Link Here
139
	protected void createAdvancedControls(Composite parent) {
155
	protected void createAdvancedControls(Composite parent) {
140
		IDialogSettings settings = getDialogSettings();
156
		IDialogSettings settings = getDialogSettings();
141
		if (settings != null) {
157
		if (settings != null) {
142
			String component = settings.get(S_COMPONENT_NAME);
158
			String component = settings.get(F_COMPONENT_NAME);
143
			if (component != null && !component.equals("")) { //$NON-NLS-1$
159
			if (component != null && !component.equals("")) {
144
				setFileName(component);
160
				setFileName(component);
145
			} else {
161
			} else {
146
				setFileName(F_DEFAULT_COMPONENT_NAME);
162
				setFileName(F_DEFAULT_COMPONENT_NAME);
Lines 170-176 Link Here
170
				setPageComplete(isPageComplete());
186
				setPageComplete(isPageComplete());
171
			}
187
			}
172
		});
188
		});
173
		setComponentName();
174
189
175
		fDSImplementationClassHyperlink = new Hyperlink(fGroup, SWT.NONE);
190
		fDSImplementationClassHyperlink = new Hyperlink(fGroup, SWT.NONE);
176
		fDSImplementationClassHyperlink
191
		fDSImplementationClassHyperlink
Lines 181-195 Link Here
181
		fDSImplementationClassHyperlink
196
		fDSImplementationClassHyperlink
182
				.addHyperlinkListener(new IHyperlinkListener() {
197
				.addHyperlinkListener(new IHyperlinkListener() {
183
198
184
			public void linkActivated(HyperlinkEvent e) {
199
					public void linkActivated(HyperlinkEvent e) {
185
						String value = fDSImplementationClassText.getText();
200
						String value = fDSImplementationClassText.getText();
186
						value = handleLinkActivated(value, false);
201
						value = handleLinkActivated(value, false);
187
						if (value != null)
202
						if (value != null)
188
							fDSImplementationClassText.setText(value);
203
							fDSImplementationClassText.setText(value);
189
204
190
			}
205
					}
191
206
192
			private String handleLinkActivated(String value,
207
					private String handleLinkActivated(String value,
193
							boolean isInter) {
208
							boolean isInter) {
194
						Object object = fSelection.getFirstElement();
209
						Object object = fSelection.getFirstElement();
195
						if (object != null) {
210
						if (object != null) {
Lines 217-245 Link Here
217
										SWTUtil.setDialogSize(dialog, 400, 500);
232
										SWTUtil.setDialogSize(dialog, 400, 500);
218
										if (dialog.open() == Window.OK) {
233
										if (dialog.open() == Window.OK) {
219
											return wizard.getQualifiedName();
234
											return wizard.getQualifiedName();
235
										}
236
									}
220
								}
237
								}
221
							}
222
						}
223
							} catch (PartInitException e1) {
238
							} catch (PartInitException e1) {
224
							} catch (CoreException e1) {
239
							} catch (CoreException e1) {
225
					}
240
							}
226
						}
241
						}
227
						return null;
242
						return null;
228
					}
243
					}
229
244
230
			public void linkEntered(HyperlinkEvent e) {
245
					public void linkEntered(HyperlinkEvent e) {
231
						fDSImplementationClassHyperlink.setForeground(Display
246
						fDSImplementationClassHyperlink.setForeground(Display
232
								.getDefault().getSystemColor(
247
								.getDefault().getSystemColor(
233
										SWT.COLOR_DARK_BLUE));
248
										SWT.COLOR_DARK_BLUE));
234
					}
249
					}
235
250
236
			public void linkExited(HyperlinkEvent e) {
251
					public void linkExited(HyperlinkEvent e) {
237
						fDSImplementationClassHyperlink.setForeground(Display
252
						fDSImplementationClassHyperlink.setForeground(Display
238
								.getDefault().getSystemColor(SWT.COLOR_BLUE));
253
								.getDefault().getSystemColor(SWT.COLOR_BLUE));
239
254
240
			}
255
					}
241
256
242
		});
257
				});
243
258
244
		// Implementation Class Text
259
		// Implementation Class Text
245
		fDSImplementationClassText = new Text(fGroup, SWT.SINGLE | SWT.BORDER);
260
		fDSImplementationClassText = new Text(fGroup, SWT.SINGLE | SWT.BORDER);
Lines 290-295 Link Here
290
				}
305
				}
291
			}
306
			}
292
		});
307
		});
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();
293
		validatePage();
315
		validatePage();
294
	}
316
	}
295
317
Lines 324-339 Link Here
324
	}
346
	}
325
347
326
	public boolean isPageComplete() {
348
	public boolean isPageComplete() {
349
		updateCreateMethodsButton();
327
		return checkPageComplete() & validatePage();
350
		return checkPageComplete() & validatePage();
328
	}
351
	}
329
352
330
	public void saveSettings(IDialogSettings settings) {
353
	public void saveSettings(IDialogSettings settings) {
331
		settings.put(S_COMPONENT_NAME, getFileName());
354
		settings.put(F_COMPONENT_NAME, getFileName());
355
		if (fGenerateMethodsButton.isEnabled()) {
356
			settings.put(F_GENERATE_METHODS, fGenerateMethodsButton
357
					.getSelection());
358
		}
359
332
	}
360
	}
333
361
334
	protected boolean validatePage() {
362
	protected boolean validatePage() {
335
		if (fDSImplementationClassText != null) {
363
		if (fDSImplementationClassText != null) {
336
			IStatus status = ResourcesPlugin.getWorkspace().validateName(
364
			IStatus status = PDEPlugin.getWorkspace().validateName(
337
					fDSImplementationClassText.getText(), IResource.FILE);
365
					fDSImplementationClassText.getText(), IResource.FILE);
338
			if (!status.isOK()) {
366
			if (!status.isOK()) {
339
				setErrorMessage(status.getMessage());
367
				setErrorMessage(status.getMessage());
Lines 343-346 Link Here
343
		return super.validatePage();
371
		return super.validatePage();
344
	}
372
	}
345
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
	}
346
}
418
}
(-)src/org/eclipse/pde/internal/ds/ui/Messages.java (+8 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;
50
	public static String DSNewWizard_RememberMyDecision;
45
	
51
	
46
	public static String DSImplementationDetails_title;
52
	public static String DSImplementationDetails_title;
47
	public static String DSImplementationDetails_description;
53
	public static String DSImplementationDetails_description;
Lines 165-170 Link Here
165
	
171
	
166
	public static String DSService_title;
172
	public static String DSService_title;
167
173
174
	public static String HandyPromptDialog_Prompt;
175
	public static String HandyPromptDialog_UnknownButtonId;
168
	
176
	
169
	
177
	
170
178
(-)src/org/eclipse/pde/internal/ds/ui/messages.properties (-1 / +10 lines)
Lines 34-41 Link Here
34
DSFileWizardPage_browse=Bro&wse...
34
DSFileWizardPage_browse=Bro&wse...
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? (recommended)
42
DSNewWizard_defaultOSGIFolder_title=OSGI-INF Folder
43
DSNewWizard_defaultOSGIFolder_message=Make OSGI-INF as default folder? (recommended)
44
DSNewWizard_RememberMyDecision=Remember my decision
39
45
40
DSImplementationDetails_title=Definition
46
DSImplementationDetails_title=Definition
41
DSImplementationDetails_description=Specify the service's implementation class:
47
DSImplementationDetails_description=Specify the service's implementation class:
Lines 155-158 Link Here
155
161
156
DSServiceComponentSection_immediateButtonMessage=This component is immediately activated
162
DSServiceComponentSection_immediateButtonMessage=This component is immediately activated
157
DSServiceComponentSection_enabledButtonMessage=This component is enabled when started
163
DSServiceComponentSection_enabledButtonMessage=This component is enabled when started
158
DSService_title=Services
164
DSService_title=Services
165
166
HandyPromptDialog_Prompt=Prompt
167
HandyPromptDialog_UnknownButtonId=Unknown button id {0}
(-)src/org/eclipse/pde/internal/ds/ui/parts/IHandyDialog.java (+43 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2007 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.ds.ui.parts;
12
13
import org.eclipse.jface.dialogs.IDialogConstants;
14
15
public interface IHandyDialog {
16
	// Values returned by open()
17
	public static final int CANCEL_ID = IDialogConstants.CANCEL_ID;
18
	public static final int NO_ID = IDialogConstants.NO_ID;
19
	public static final int OK_ID = IDialogConstants.OK_ID;
20
	public static final int YES_ID = IDialogConstants.YES_ID;
21
22
	/**
23
	 * @see org.eclipse.jface.window.Window.open()
24
	 */
25
	public int open();
26
27
	/**
28
	 * Set the size of the dialog.  This is only a hint, since dialogs must
29
	 * respect the dialog font size.  The most you can expect is that the
30
	 * dialog will be no smaller than the width and height specified.
31
	 *
32
	 * @param width  The width of the dialog.
33
	 * @param height The height of the dialog.
34
	 */
35
	public void setSize(int width, int height);
36
37
	/**
38
	 * Set the title of the dialog.
39
	 *
40
	 * @param title  The title of the dialog.
41
	 */
42
	public void setTitle(String title);
43
}
(-)src/org/eclipse/pde/internal/ds/ui/parts/IHandyPromptDialog.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2007 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.ds.ui.parts;
12
13
import org.eclipse.swt.graphics.Image;
14
15
public interface IHandyPromptDialog extends IHandyDialog {
16
	public int addCheckbox(String text, boolean selected);
17
	public int addRadioButton(String text, boolean selected);
18
	public void defaultButtonIsCancel();
19
	public void defaultButtonIsNo();
20
	public void defaultButtonIsYes();
21
	public int getSelectedRadioButtonId();
22
	public boolean isCheckboxSelected(int id);
23
	public void removeAllCheckboxes();
24
	public void removeAllRadioButtons();
25
	public void setCancelButtonText(String cancelButtonText);
26
	public void setCheckboxGroupText(String checkboxGroupText);
27
	public void setCheckboxSelected(int id, boolean selected);
28
	public void setImage(Image image);
29
	public void setNoButtonText(String negativeButtonLabel);
30
	public void setRadioButtonGroupText(String radioButtonGroupText);
31
	public void setRadioButtonSelected(int id, boolean selected);
32
	public void setYesButtonText(String positiveButtonLabel);
33
	public void useErrorIcon();
34
	public void useInformationIcon();
35
	public void useQuestionIcon();
36
	public void useWarningIcon();
37
}
(-)src/org/eclipse/pde/internal/ds/ui/parts/HandyDialog.java (+120 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2007 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.ds.ui.parts;
12
13
import org.eclipse.jface.dialogs.Dialog;
14
import org.eclipse.swt.graphics.Image;
15
import org.eclipse.swt.graphics.Point;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Control;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Shell;
20
21
abstract class HandyDialog extends Dialog implements IHandyDialog {
22
	private String title;
23
	private Point size;
24
25
	protected HandyDialog(Shell parentShell) {
26
		super(parentShell);
27
	}
28
29
	/**
30
	 * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell)
31
	 */
32
	protected void configureShell(Shell shell) {
33
		super.configureShell(shell);
34
		configureShellTitle(shell);
35
	}
36
37
	private void configureShellTitle(Shell shell) {
38
		String title = getTitle();
39
		if (title == null)
40
			return;  // Early return.
41
		shell.setText(title);
42
	}
43
44
	protected abstract void createArea(Composite composite);
45
46
	/**
47
	 * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
48
	 */
49
	protected final Control createDialogArea(Composite parent) {
50
		Composite composite = (Composite) super.createDialogArea(parent);
51
		createArea(composite);
52
		postCreateArea(composite);
53
		Dialog.applyDialogFont(composite);
54
		return composite;
55
	}
56
57
	private Display getDisplay() {
58
		Shell shell = getShell();
59
		Display display = shell != null ? shell.getDisplay() : Display.getDefault();
60
		return display;
61
	}
62
63
	/**
64
	 * @see org.eclipse.jface.window.Window#getInitialSize()
65
	 */
66
	protected Point getInitialSize() {
67
		Point initialSize = super.getInitialSize();
68
		Point result = initialSize;
69
		Point size = getSize();
70
71
		if (size != null) {
72
			if (size.x >= initialSize.x) {
73
				result.x = size.x;
74
			}
75
76
			if (size.y >= initialSize.y) {
77
				result.y = size.y;
78
			}
79
		}
80
81
		return result;
82
	}
83
84
	private Point getSize() {
85
		return size;
86
	}
87
88
	protected final Image getSystemImage(int id) {
89
		Display display = getDisplay();
90
		Image image = display.getSystemImage(id);
91
		return image;
92
	}
93
94
	private String getTitle() {
95
		return title;
96
	}
97
98
	protected void postCreateArea(Composite composite) {
99
		// No-op
100
	}
101
102
	/**
103
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyDialog#setSize(int, int)
104
	 */
105
	public void setSize(int width, int height) {
106
		Point point = new Point(width, height);
107
		setSize(point);
108
	}
109
110
	private void setSize(Point size) {
111
		this.size = size;
112
	}
113
114
	/**
115
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setTitle(java.lang.String)
116
	 */
117
	public void setTitle(String title) {
118
		this.title = title;
119
	}
120
}
(-)src/org/eclipse/pde/internal/ds/ui/parts/HandyPromptDialog.java (+599 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2001, 2007 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.ds.ui.parts;
12
13
import java.text.MessageFormat;
14
import java.util.ArrayList;
15
import java.util.Iterator;
16
import java.util.List;
17
18
import org.eclipse.jface.dialogs.IDialogConstants;
19
import org.eclipse.pde.internal.ds.ui.Messages;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.graphics.Image;
22
import org.eclipse.swt.layout.GridData;
23
import org.eclipse.swt.layout.GridLayout;
24
import org.eclipse.swt.layout.RowLayout;
25
import org.eclipse.swt.widgets.Button;
26
import org.eclipse.swt.widgets.Composite;
27
import org.eclipse.swt.widgets.Group;
28
import org.eclipse.swt.widgets.Label;
29
import org.eclipse.swt.widgets.Shell;
30
31
/**
32
 * A handy Yes/No/Cancel dialog.
33
 */
34
public class HandyPromptDialog extends HandyDialog implements IHandyPromptDialog {
35
	private static class ButtonDetails extends Object {
36
		private Button button;
37
		private boolean selected;
38
		private String text;
39
	}
40
41
	private static final String PROMPT_KEY = "HandyPromptDialog.Prompt";  //$NON-NLS-1$
42
	private static final String UNKNOWN_BUTTON_ID_KEY = "HandyPromptDialog.UnknownButtonId";  //$NON-NLS-1$
43
44
	private static final int NO_DEFAULT_BUTTON_ID = -1;
45
46
	private String cancelButtonText;
47
	private List/*<ButtonDetails>*/ checkboxButtons;
48
	private String checkboxGroupText;
49
	private int defaultButtonId;
50
	private Image image;
51
	private String noButtonText;
52
	private String prompt;
53
	private List/*<ButtonDetails>*/ radioButtons;
54
	private String radioButtonGroupText;
55
	private String yesButtonText;
56
57
	public HandyPromptDialog(Shell parentShell, String prompt) {
58
		super(parentShell);
59
		setTitle(Messages.HandyPromptDialog_Prompt);
60
		setPrompt(prompt);
61
		initializeCheckboxButtons();
62
		initializeRadioButtons();
63
		initializePushButtons();
64
		setDefaultButtonId(HandyPromptDialog.NO_DEFAULT_BUTTON_ID);
65
	}
66
67
	private int addButton(List/*<ButtonDetails>*/ list, String text, boolean selected) {
68
		synchronized (list) {
69
			int size = list.size();
70
			ButtonDetails details = new ButtonDetails();
71
			details.text = text;
72
			details.selected = selected;
73
			list.add(details);
74
			return size;
75
		}
76
	}
77
78
	/**
79
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#addCheckbox(java.lang.String, boolean)
80
	 */
81
	public int addCheckbox(String text, boolean selected) {
82
		List/*<ButtonDetails>*/ list = getCheckboxButtons();
83
		int id = addButton(list, text, selected);
84
		return id;
85
	}
86
87
	/**
88
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#addRadioButton(java.lang.String, boolean)
89
	 */
90
	public int addRadioButton(String text, boolean selected) {
91
		List/*<ButtonDetails>*/ list = getRadioButtons();
92
		int id = addButton(list, text, selected);
93
		return id;
94
	}
95
96
	/**
97
	 * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
98
	 */
99
	protected void buttonPressed(int buttonId) {
100
		try {
101
			updateButtonSelections();
102
			setReturnCode(buttonId);
103
		} finally {
104
			close();
105
		}
106
	}
107
108
	private void checkButtonId(List/*<ButtonDetails>*/ list, int id) {
109
		int size = list.size();
110
		if (id < size)
111
			return;  // Early return.
112
113
		String pattern = Messages.HandyPromptDialog_UnknownButtonId;
114
		Object[] values = new Object[] {
115
			new Integer(id)
116
		};
117
		String message = MessageFormat.format(pattern, values);
118
		throw new IllegalArgumentException(message);
119
	}
120
121
	/**
122
	 * @see org.eclipse.soda.sat.plugin.ui.internal.HandyDialog#createArea(org.eclipse.swt.widgets.Composite)
123
	 */
124
	protected void createArea(Composite composite) {
125
		createPromptControls(composite);
126
	}
127
128
	private Button createButton(Composite parent, int id, String label) {
129
		int defaultButtonId = getDefaultButtonId();
130
		boolean defaultButton = defaultButtonId == id;
131
		Button button = createButton(parent, id, label, defaultButton);
132
		return button;
133
	}
134
135
	/**
136
	 * @see org.eclipse.jface.dialogs.Dialog#createButton(org.eclipse.swt.widgets.Composite, int, java.lang.String, boolean)
137
	 */
138
	protected Button createButton(Composite parent, int id, String label, boolean defaultButton) {
139
		Button button = super.createButton(parent, id, label, defaultButton);
140
141
		// Force the default button to take focus.  This fixes an apparent
142
		// bug in SWT where the default button does not always take focus.
143
		// Strangely enough, the default button seems to take focus when the
144
		// HandyPromptDialog has at least one radio button or checkbox.
145
146
		if (defaultButton == true) {
147
			button.setFocus();
148
		}
149
150
		return button;
151
	}
152
153
	private void createButtons(List/* <ButtonDetails> */list,
154
			Composite parent, boolean grabExcessSpace, String groupText,
155
			int style) {
156
		synchronized (list) {
157
			boolean empty = list.isEmpty();
158
			if (empty == true)
159
				return;  // Early return.
160
161
			Composite composite;
162
			RowLayout layout = new RowLayout(SWT.VERTICAL);
163
164
			if (groupText == null) {
165
				composite = new Composite(parent, SWT.NONE);
166
				layout.marginLeft = 0;
167
				layout.marginRight = 0;
168
				layout.marginTop = 0;
169
				layout.marginBottom = 0;
170
			} else {
171
				Group group = new Group(parent, SWT.NONE);
172
				group.setText(groupText);
173
				composite = group;
174
			}
175
176
			composite.setLayout(layout);
177
178
			int alignment = grabExcessSpace == true ? SWT.FILL : SWT.BEGINNING;
179
			Object data = new GridData(alignment, alignment, grabExcessSpace, grabExcessSpace);
180
			composite.setLayoutData(data);
181
182
			Iterator/*<ButtonDetails>*/ iterator = list.iterator();
183
			while (iterator.hasNext() == true) {
184
				ButtonDetails details = (ButtonDetails) iterator.next();
185
				Button button = new Button(composite, style);
186
				button.setText(details.text);
187
				button.setSelection(details.selected);
188
				details.button = button;
189
			}
190
		}
191
	}
192
193
	/**
194
	 * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
195
	 */
196
	protected void createButtonsForButtonBar(Composite parent) {
197
		createYesButtonForButtonBar(parent);
198
		createNoButtonForButtonBar(parent);
199
		createCancelButtonForButtonBar(parent);
200
	}
201
202
	private Button createCancelButtonForButtonBar(Composite parent) {
203
		String label = getCancelButtonText();
204
		if (label == null)
205
			return null;  // Early return.
206
		int id = IHandyDialog.CANCEL_ID;
207
		Button button = createButton(parent, id, label);
208
		return button;
209
	}
210
211
	private Button createNoButtonForButtonBar(Composite parent) {
212
		String label = getNoButtonText();
213
		if (label == null)
214
			return null;  // Early return.
215
		int id = IHandyDialog.NO_ID;
216
		Button button = createButton(parent, id, label);
217
		return button;
218
	}
219
220
	private void createPromptButtonControls(Composite parent) {
221
		int columns = 0;
222
223
		List/*<ButtonDetails>*/ checkboxButtons = getCheckboxButtons();
224
		boolean hasCheckboxButtons = checkboxButtons.isEmpty() == false;
225
226
		if (hasCheckboxButtons == true) {
227
			columns++;
228
		}
229
230
		List/*<ButtonDetails>*/ radioButtons = getRadioButtons();
231
		boolean hasRadioButtons = radioButtons.isEmpty() == false;
232
233
		if (hasRadioButtons == true) {
234
			columns++;
235
		}
236
237
		if (columns == 0)
238
			return;  // Early return.
239
240
		Composite composite = createPromptButtonControlsComposite(parent, columns);
241
242
		if (hasCheckboxButtons == true) {
243
			String groupText = getCheckboxGroupText();
244
			createButtons(checkboxButtons, composite, hasRadioButtons, groupText, SWT.CHECK);
245
		}
246
247
		if (hasRadioButtons == true) {
248
			String groupText = getRadioButtonGroupText();
249
			createButtons(radioButtons, composite, hasCheckboxButtons, groupText, SWT.RADIO);
250
		}
251
	}
252
253
	private Composite createPromptButtonControlsComposite(Composite parent, int columns) {
254
		GridLayout layout = new GridLayout(columns, false);
255
		layout.marginWidth = 0;
256
		layout.marginHeight = 0;
257
		layout.marginTop = 20;
258
		layout.marginHeight = 0;
259
260
		if (columns > 1) {
261
			layout.horizontalSpacing = 10;
262
		}
263
264
		Composite composite = new Composite(parent, SWT.NONE);
265
		composite.setLayout(layout);
266
267
		Object data = new GridData(SWT.FILL, SWT.FILL, true, false);
268
		composite.setLayoutData(data);
269
270
		return composite;
271
	}
272
273
	private void createPromptControls(Composite parent) {
274
		createPromptLabelControls(parent);
275
		createPromptButtonControls(parent);
276
	}
277
278
	private void createPromptLabelControls(Composite parent) {
279
		GridData data;
280
281
		Composite composite = new Composite(parent, SWT.NONE);
282
		GridLayout layout = new GridLayout(2, false);
283
		layout.marginWidth = 0;
284
		layout.marginHeight = 0;
285
		composite.setLayout(layout);
286
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
287
		composite.setLayoutData(data);
288
289
		Label icon = new Label(composite, SWT.LEFT | SWT.NONE);
290
		Image image = getImage();
291
		icon.setImage(image);
292
293
		Label label = new Label(composite, SWT.WRAP);
294
		String prompt = getPrompt();
295
		label.setText(prompt);
296
		data = new GridData(SWT.FILL, SWT.CENTER, true, true);
297
		data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.MINIMUM_MESSAGE_AREA_WIDTH);
298
		label.setLayoutData(data);
299
	}
300
301
	private Button createYesButtonForButtonBar(Composite parent) {
302
		String label = getYesButtonText();
303
		if (label == null)
304
			return null;  // Early return.
305
		int id = IHandyDialog.YES_ID;
306
		Button button = createButton(parent, id, label);
307
		return button;
308
	}
309
310
	/**
311
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsCancel()
312
	 */
313
	public void defaultButtonIsCancel() {
314
		setDefaultButtonId(IHandyDialog.CANCEL_ID);
315
	}
316
317
	/**
318
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsNo()
319
	 */
320
	public void defaultButtonIsNo() {
321
		setDefaultButtonId(IHandyDialog.NO_ID);
322
	}
323
324
	/**
325
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#defaultButtonIsYes()
326
	 */
327
	public void defaultButtonIsYes() {
328
		setDefaultButtonId(IHandyDialog.YES_ID);
329
	}
330
331
	private ButtonDetails getButtonDetails(List/*<ButtonDetails>*/ list, int id) {
332
		checkButtonId(list, id);
333
		ButtonDetails details = (ButtonDetails) list.get(id);
334
		return details;
335
	}
336
337
	private String getCancelButtonText() {
338
		return cancelButtonText;
339
	}
340
341
	private ButtonDetails getCheckboxButtonDetails(int id) {
342
		List/*<ButtonDetails>*/ list = getCheckboxButtons();
343
		ButtonDetails details = getButtonDetails(list, id);
344
		return details;
345
	}
346
347
	private List/*<ButtonDetails>*/ getCheckboxButtons() {
348
		return checkboxButtons;
349
	}
350
351
	private String getCheckboxGroupText() {
352
		return checkboxGroupText;
353
	}
354
355
	private int getDefaultButtonId() {
356
		synchronized (this) {
357
			if (defaultButtonId == -1) {
358
				int id = guessDefaultButtonId();
359
				setDefaultButtonId(id);
360
			}
361
		}
362
363
		return defaultButtonId;
364
	}
365
366
	private Image getImage() {
367
		synchronized (this) {
368
			if (image == null) {
369
				useInformationIcon();
370
			}
371
		}
372
		return image;
373
	}
374
375
	private String getNoButtonText() {
376
		return noButtonText;
377
	}
378
379
	private String getPrompt() {
380
		return prompt;
381
	}
382
383
	private ButtonDetails getRadioButtonDetails(int id) {
384
		List/*<ButtonDetails>*/ list = getRadioButtons();
385
		ButtonDetails details = getButtonDetails(list, id);
386
		return details;
387
	}
388
389
	private String getRadioButtonGroupText() {
390
		return radioButtonGroupText;
391
	}
392
393
	private List/*<ButtonDetails>*/ getRadioButtons() {
394
		return radioButtons;
395
	}
396
397
	/**
398
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#getSelectedRadioButtonId()
399
	 */
400
	public int getSelectedRadioButtonId() {
401
		List/*<ButtonDetails>*/ list = getRadioButtons();
402
		int size = list.size();
403
404
		for (int id = 0; id < size; id++) {
405
			ButtonDetails details = (ButtonDetails) list.get(id);
406
			if (details.selected == true)
407
				return id;  // Early return.
408
		}
409
410
		return -1;
411
	}
412
413
	private String getYesButtonText() {
414
		return yesButtonText;
415
	}
416
417
	private int guessDefaultButtonId() {
418
		Object text;
419
420
		text = getCancelButtonText();
421
		if (text != null) return IHandyDialog.CANCEL_ID;
422
423
		text = getNoButtonText();
424
		if (text != null) return IHandyDialog.NO_ID;
425
426
		text = getYesButtonText();
427
		if (text != null) return IHandyDialog.YES_ID;
428
429
		return HandyPromptDialog.NO_DEFAULT_BUTTON_ID;
430
	}
431
432
	private void initializeCheckboxButtons() {
433
		setCheckboxButtons(new ArrayList/*<ButtonDetails>*/(3));
434
	}
435
436
	private void initializePushButtons() {
437
		setYesButtonText(IDialogConstants.YES_LABEL);
438
		setNoButtonText(IDialogConstants.NO_LABEL);
439
		setCancelButtonText('&' + IDialogConstants.CANCEL_LABEL);
440
	}
441
442
	private void initializeRadioButtons() {
443
		setRadioButtons(new ArrayList/*<ButtonDetails>*/(3));
444
	}
445
446
	/**
447
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#isCheckboxSelected(int)
448
	 */
449
	public boolean isCheckboxSelected(int id) {
450
		ButtonDetails details = getCheckboxButtonDetails(id);
451
		return details.selected;
452
	}
453
454
	/**
455
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#removeAllCheckboxes()
456
	 */
457
	public void removeAllCheckboxes() {
458
		initializeCheckboxButtons();
459
	}
460
461
	/**
462
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#removeAllRadioButtons()
463
	 */
464
	public void removeAllRadioButtons() {
465
		initializeRadioButtons();
466
	}
467
468
	/**
469
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCancelButtonText(java.lang.String)
470
	 */
471
	public void setCancelButtonText(String cancelButtonText) {
472
		this.cancelButtonText = cancelButtonText;
473
	}
474
475
	private void setCheckboxButtons(List/*<ButtonDetails>*/ checkboxButtons) {
476
		this.checkboxButtons = checkboxButtons;
477
	}
478
479
	/**
480
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCheckboxGroupText(java.lang.String)
481
	 */
482
	public void setCheckboxGroupText(String checkboxGroupText) {
483
		this.checkboxGroupText = checkboxGroupText;
484
	}
485
486
	/**
487
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setCheckboxSelected(int, boolean)
488
	 */
489
	public void setCheckboxSelected(int id, boolean selected) {
490
		ButtonDetails details = getCheckboxButtonDetails(id);
491
		details.selected = selected;
492
	}
493
494
	private void setDefaultButtonId(int defaultButtonId) {
495
		this.defaultButtonId = defaultButtonId;
496
	}
497
498
	/**
499
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setImage(org.eclipse.swt.graphics.Image)
500
	 */
501
	public void setImage(Image image) {
502
		this.image = image;
503
	}
504
505
	private void setImage(int id) {
506
		Image image = getSystemImage(id);
507
		setImage(image);
508
	}
509
510
	/**
511
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setNoButtonText(java.lang.String)
512
	 */
513
	public void setNoButtonText(String noButtonText) {
514
		this.noButtonText = noButtonText;
515
	}
516
517
	private void setPrompt(String prompt) {
518
		this.prompt = prompt;
519
	}
520
521
	/**
522
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setRadioButtonGroupText(java.lang.String)
523
	 */
524
	public void setRadioButtonGroupText(String radioButtonGroupText) {
525
		this.radioButtonGroupText = radioButtonGroupText;
526
	}
527
528
	private void setRadioButtons(List/*<ButtonDetails>*/ radioButtons) {
529
		this.radioButtons = radioButtons;
530
	}
531
532
	/**
533
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setRadioButtonSelected(int, boolean)
534
	 */
535
	public void setRadioButtonSelected(int id, boolean selected) {
536
		ButtonDetails details = getRadioButtonDetails(id);
537
		details.selected = selected;
538
	}
539
540
	/**
541
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#setYesButtonText(java.lang.String)
542
	 */
543
	public void setYesButtonText(String yesButtonText) {
544
		this.yesButtonText = yesButtonText;
545
	}
546
547
	private void updateButtonSelections() {
548
		updateCheckboxButtonSelections();
549
		updateRadioButtonSelections();
550
	}
551
552
	private void updateButtonSelections(List/*<ButtonDetails>*/ list) {
553
		synchronized (list) {
554
			Iterator/*<ButtonDetails>*/ iterator = list.iterator();
555
			while (iterator.hasNext() == true) {
556
				ButtonDetails details = (ButtonDetails) iterator.next();
557
				details.selected = details.button.getSelection();
558
			}
559
		}
560
	}
561
562
	private void updateCheckboxButtonSelections() {
563
		List/*<ButtonDetails>*/ list = getCheckboxButtons();
564
		updateButtonSelections(list);
565
	}
566
567
	private void updateRadioButtonSelections() {
568
		List/*<ButtonDetails>*/ list = getRadioButtons();
569
		updateButtonSelections(list);
570
	}
571
572
	/**
573
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useErrorIcon()
574
	 */
575
	public void useErrorIcon() {
576
		setImage(SWT.ICON_ERROR);
577
	}
578
579
	/**
580
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useInformationIcon()
581
	 */
582
	public void useInformationIcon() {
583
		setImage(SWT.ICON_INFORMATION);
584
	}
585
586
	/**
587
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useQuestionIcon()
588
	 */
589
	public void useQuestionIcon() {
590
		setImage(SWT.ICON_QUESTION);
591
	}
592
593
	/**
594
	 * @see org.eclipse.soda.sat.plugin.ui.util.IHandyPromptDialog#useWarningIcon()
595
	 */
596
	public void useWarningIcon() {
597
		setImage(SWT.ICON_WARNING);
598
	}
599
}

Return to bug 256731