|
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 |
} |