]>
Commit | Line | Data |
---|---|---|
1b2798f6 EK |
1 | /******************************************************************************* |
2 | * Copyright (c) 2000, 2011 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 | * Ferenc Hechler, ferenc_hechler@users.sourceforge.net - 83258 [jar exporter] Deploy java application as executable jar | |
11 | *******************************************************************************/ | |
12 | package org.eclipse.jdt.internal.ui.jarpackager; | |
13 | ||
14 | import java.lang.reflect.InvocationTargetException; | |
15 | import java.util.HashSet; | |
16 | import java.util.Iterator; | |
17 | import java.util.Set; | |
18 | ||
19 | import org.eclipse.swt.SWT; | |
20 | import org.eclipse.swt.custom.BusyIndicator; | |
21 | import org.eclipse.swt.events.SelectionAdapter; | |
22 | import org.eclipse.swt.events.SelectionEvent; | |
23 | import org.eclipse.swt.layout.GridData; | |
24 | import org.eclipse.swt.layout.GridLayout; | |
25 | import org.eclipse.swt.widgets.Button; | |
26 | import org.eclipse.swt.widgets.Composite; | |
27 | import org.eclipse.swt.widgets.Label; | |
28 | import org.eclipse.swt.widgets.Link; | |
29 | import org.eclipse.swt.widgets.TreeItem; | |
30 | ||
31 | import org.eclipse.core.runtime.IAdaptable; | |
32 | import org.eclipse.core.runtime.IPath; | |
33 | import org.eclipse.core.runtime.IProgressMonitor; | |
34 | import org.eclipse.core.runtime.IStatus; | |
35 | ||
36 | import org.eclipse.core.resources.IFile; | |
37 | import org.eclipse.core.resources.IProject; | |
38 | import org.eclipse.core.resources.IResource; | |
39 | import org.eclipse.core.resources.IWorkspace; | |
40 | import org.eclipse.core.resources.ResourcesPlugin; | |
41 | ||
42 | import org.eclipse.jface.dialogs.Dialog; | |
43 | import org.eclipse.jface.dialogs.IDialogSettings; | |
44 | import org.eclipse.jface.operation.IRunnableWithProgress; | |
45 | import org.eclipse.jface.viewers.CheckStateChangedEvent; | |
46 | import org.eclipse.jface.viewers.DecoratingLabelProvider; | |
47 | import org.eclipse.jface.viewers.ICheckStateListener; | |
48 | import org.eclipse.jface.viewers.IStructuredSelection; | |
49 | import org.eclipse.jface.viewers.ITreeContentProvider; | |
50 | import org.eclipse.jface.viewers.Viewer; | |
51 | import org.eclipse.jface.viewers.ViewerFilter; | |
52 | import org.eclipse.jface.wizard.IWizardPage; | |
53 | ||
54 | import org.eclipse.ui.PlatformUI; | |
55 | ||
56 | import org.eclipse.ltk.core.refactoring.RefactoringCore; | |
57 | import org.eclipse.ltk.core.refactoring.history.IRefactoringHistoryService; | |
58 | import org.eclipse.ltk.core.refactoring.history.RefactoringHistory; | |
59 | ||
60 | import org.eclipse.jdt.core.IClassFile; | |
61 | import org.eclipse.jdt.core.IClasspathEntry; | |
62 | import org.eclipse.jdt.core.IJavaElement; | |
63 | import org.eclipse.jdt.core.IJavaModel; | |
64 | import org.eclipse.jdt.core.IPackageFragment; | |
65 | import org.eclipse.jdt.core.IPackageFragmentRoot; | |
66 | import org.eclipse.jdt.core.JavaCore; | |
67 | import org.eclipse.jdt.core.JavaModelException; | |
68 | import org.eclipse.jdt.core.refactoring.descriptors.JavaRefactoringDescriptor; | |
69 | ||
70 | import org.eclipse.jdt.ui.JavaElementLabelProvider; | |
71 | import org.eclipse.jdt.ui.ProblemsLabelDecorator; | |
72 | import org.eclipse.jdt.ui.StandardJavaElementContentProvider; | |
73 | import org.eclipse.jdt.ui.jarpackager.JarPackageData; | |
74 | ||
75 | import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; | |
76 | import org.eclipse.jdt.internal.ui.util.ExceptionHandler; | |
77 | import org.eclipse.jdt.internal.ui.util.SWTUtil; | |
78 | ||
79 | /** | |
80 | * Page 1 of the JAR Package wizard | |
81 | */ | |
82 | public class JarPackageWizardPage extends AbstractJarDestinationWizardPage { | |
83 | ||
84 | public JarPackageData fJarPackage; | |
85 | IStructuredSelection fInitialSelection; | |
86 | CheckboxTreeAndListGroup fInputGroup; | |
87 | ||
88 | // widgets | |
89 | public Button fExportClassFilesCheckbox; | |
90 | public Button fExportOutputFoldersCheckbox; | |
91 | public Button fExportJavaFilesCheckbox; | |
92 | public Button fExportRefactoringsCheckbox; | |
93 | private Link fRefactoringLink; | |
94 | ||
95 | public Button fCompressCheckbox; | |
96 | public Button fOverwriteCheckbox; | |
97 | public Button fIncludeDirectoryEntriesCheckbox; | |
98 | boolean fInitiallySelecting= true; | |
99 | ||
100 | // dialog store id constants | |
101 | private static final String PAGE_NAME= "JarPackageWizardPage"; //$NON-NLS-1$ | |
102 | ||
103 | public static final String STORE_EXPORT_CLASS_FILES= PAGE_NAME + ".EXPORT_CLASS_FILES"; //$NON-NLS-1$ | |
104 | public static final String STORE_EXPORT_OUTPUT_FOLDERS= PAGE_NAME + ".EXPORT_OUTPUT_FOLDER"; //$NON-NLS-1$ | |
105 | public static final String STORE_EXPORT_JAVA_FILES= PAGE_NAME + ".EXPORT_JAVA_FILES"; //$NON-NLS-1$ | |
106 | ||
107 | public static final String STORE_REFACTORINGS= PAGE_NAME + ".REFACTORINGS"; //$NON-NLS-1$ | |
108 | public static final String STORE_COMPRESS= PAGE_NAME + ".COMPRESS"; //$NON-NLS-1$ | |
109 | public final static String STORE_OVERWRITE= PAGE_NAME + ".OVERWRITE"; //$NON-NLS-1$ | |
110 | public final static String STORE_INCLUDE_DIRECTORY_ENTRIES= PAGE_NAME + ".INCLUDE_DIRECTORY_ENTRIES"; //$NON-NLS-1$ | |
111 | ||
112 | // other constants | |
113 | private static final int SIZING_SELECTION_WIDGET_WIDTH= 480; | |
114 | private static final int SIZING_SELECTION_WIDGET_HEIGHT= 150; | |
115 | ||
116 | /** | |
117 | * Create an instance of this class | |
118 | * | |
119 | * @param jarPackage an object containing all required information to make an export | |
120 | * @param selection the initial selection | |
121 | */ | |
122 | public JarPackageWizardPage(JarPackageData jarPackage, IStructuredSelection selection) { | |
123 | super(PAGE_NAME, selection, jarPackage); | |
124 | setTitle(JarPackagerMessages.JarPackageWizardPage_title); | |
125 | setDescription(JarPackagerMessages.JarPackageWizardPage_description); | |
126 | fJarPackage= jarPackage; | |
127 | fInitialSelection= selection; | |
128 | } | |
129 | ||
130 | /* | |
131 | * Method declared on IDialogPage. | |
132 | */ | |
133 | @Override | |
134 | public void createControl(final Composite parent) { | |
135 | ||
136 | initializeDialogUnits(parent); | |
137 | ||
138 | Composite composite= new Composite(parent, SWT.NULL); | |
139 | composite.setLayout(new GridLayout()); | |
140 | composite.setLayoutData( | |
141 | new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); | |
142 | ||
143 | createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_whatToExport_label); | |
144 | createInputGroup(composite); | |
145 | ||
146 | createExportTypeGroup(composite); | |
147 | ||
148 | new Label(composite, SWT.NONE); // vertical spacer | |
149 | ||
150 | ||
151 | createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_whereToExport_label); | |
152 | createDestinationGroup(composite); | |
153 | ||
154 | createPlainLabel(composite, JarPackagerMessages.JarPackageWizardPage_options_label); | |
155 | createOptionsGroup(composite); | |
156 | ||
157 | restoreResourceSpecificationWidgetValues(); // superclass API defines this hook | |
158 | restoreWidgetValues(); | |
159 | if (fInitialSelection != null) | |
160 | BusyIndicator.showWhile(parent.getDisplay(), new Runnable() { | |
161 | public void run() { | |
162 | setupBasedOnInitialSelections(); | |
163 | } | |
164 | }); | |
165 | ||
166 | setControl(composite); | |
167 | update(); | |
168 | fRefactoringLink.setEnabled(fExportRefactoringsCheckbox.getSelection()); | |
169 | giveFocusToDestination(); | |
170 | ||
171 | Dialog.applyDialogFont(composite); | |
172 | PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.JARPACKAGER_WIZARD_PAGE); | |
173 | } | |
174 | ||
175 | /** | |
176 | * Create the export options specification widgets. | |
177 | * | |
178 | * @param parent org.eclipse.swt.widgets.Composite | |
179 | */ | |
180 | @Override | |
181 | protected void createOptionsGroup(Composite parent) { | |
182 | Composite optionsGroup= new Composite(parent, SWT.NONE); | |
183 | GridLayout layout= new GridLayout(); | |
184 | layout.marginHeight= 0; | |
185 | optionsGroup.setLayout(layout); | |
186 | ||
187 | fCompressCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
188 | fCompressCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_compress_text); | |
189 | fCompressCheckbox.addListener(SWT.Selection, this); | |
190 | ||
191 | fIncludeDirectoryEntriesCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
192 | fIncludeDirectoryEntriesCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_includeDirectoryEntries_text); | |
193 | fIncludeDirectoryEntriesCheckbox.addListener(SWT.Selection, this); | |
194 | ||
195 | fOverwriteCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
196 | fOverwriteCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_overwrite_text); | |
197 | fOverwriteCheckbox.addListener(SWT.Selection, this); | |
198 | } | |
199 | ||
200 | /** | |
201 | * Returns an iterator over this page's collection of currently-specified | |
202 | * elements to be exported. This is the primary element selection facility | |
203 | * accessor for subclasses. | |
204 | * | |
205 | * @return an iterator over the collection of elements currently selected for export | |
206 | */ | |
207 | @Override | |
208 | protected Iterator<Object> getSelectedResourcesIterator() { | |
209 | return fInputGroup.getAllCheckedListItems(); | |
210 | } | |
211 | ||
212 | /** | |
213 | * Persists resource specification control setting that are to be restored | |
214 | * in the next instance of this page. Subclasses wishing to persist | |
215 | * settings for their controls should extend the hook method | |
216 | * <code>internalSaveWidgetValues</code>. | |
217 | */ | |
218 | @Override | |
219 | public final void saveWidgetValues() { | |
220 | super.saveWidgetValues(); | |
221 | // update directory names history | |
222 | IDialogSettings settings= getDialogSettings(); | |
223 | if (settings != null) { | |
224 | fJarPackage.generated_7240984037865640765(settings); | |
225 | } | |
226 | // Allow subclasses to save values | |
227 | internalSaveWidgetValues(); | |
228 | } | |
229 | ||
230 | /** | |
231 | * Hook method for subclasses to persist their settings. | |
232 | */ | |
233 | @Override | |
234 | protected void internalSaveWidgetValues() { | |
235 | } | |
236 | ||
237 | /** | |
238 | * Hook method for restoring widget values to the values that they held | |
239 | * last time this wizard was used to completion. | |
240 | */ | |
241 | @Override | |
242 | protected void restoreWidgetValues() { | |
243 | if (!((JarPackageWizard)getWizard()).isInitializingFromJarPackage()) | |
244 | initializeJarPackage(); | |
245 | ||
246 | fExportClassFilesCheckbox.setSelection(fJarPackage.areClassFilesExported()); | |
247 | fExportOutputFoldersCheckbox.setSelection(fJarPackage.areOutputFoldersExported()); | |
248 | fExportJavaFilesCheckbox.setSelection(fJarPackage.areJavaFilesExported()); | |
249 | ||
250 | super.restoreWidgetValues(); | |
251 | ||
252 | // options | |
253 | fJarPackage.generated_1859976933767906524(this); | |
254 | } | |
255 | ||
256 | /** | |
257 | * Initializes the JAR package from last used wizard page values. | |
258 | */ | |
259 | @Override | |
260 | protected void initializeJarPackage() { | |
261 | super.initializeJarPackage(); | |
262 | ||
263 | IDialogSettings settings= getDialogSettings(); | |
264 | if (settings != null) { | |
265 | // source | |
266 | fJarPackage.generated_1688104107673011805(this, settings); | |
267 | } | |
268 | } | |
269 | ||
270 | /** | |
271 | * Stores the widget values in the JAR package. | |
272 | */ | |
273 | @Override | |
274 | protected void updateModel() { | |
275 | if (getControl() == null) | |
276 | return; | |
277 | ||
278 | // source | |
279 | fJarPackage.generated_2266142971517492814(this); | |
280 | ||
281 | super.updateModel(); | |
282 | // options | |
283 | if (fExportRefactoringsCheckbox != null) | |
284 | fJarPackage.setRefactoringAware(fExportRefactoringsCheckbox.getSelection()); | |
285 | else | |
286 | fJarPackage.setRefactoringAware(false); | |
287 | fJarPackage.setCompress(fCompressCheckbox.getSelection()); | |
288 | fJarPackage.setIncludeDirectoryEntries(fIncludeDirectoryEntriesCheckbox.getSelection()); | |
289 | fJarPackage.setOverwrite(fOverwriteCheckbox.getSelection()); | |
290 | } | |
291 | ||
292 | /** | |
293 | * Returns the resource for the specified path. | |
294 | * | |
295 | * @param path the path for which the resource should be returned | |
296 | * @return the resource specified by the path or <code>null</code> | |
297 | */ | |
298 | protected IResource findResource(IPath path) { | |
299 | IWorkspace workspace= ResourcesPlugin.getWorkspace(); | |
300 | IStatus result= workspace.validatePath( | |
301 | path.toString(), | |
302 | IResource.ROOT | IResource.PROJECT | IResource.FOLDER | IResource.FILE); | |
303 | if (result.isOK() && workspace.getRoot().exists(path)) | |
304 | return workspace.getRoot().findMember(path); | |
305 | return null; | |
306 | } | |
307 | ||
308 | /** | |
309 | * Creates the checkbox tree and list for selecting resources. | |
310 | * | |
311 | * @param parent the parent control | |
312 | */ | |
313 | protected void createInputGroup(Composite parent) { | |
314 | int labelFlags= JavaElementLabelProvider.SHOW_BASICS | |
315 | | JavaElementLabelProvider.SHOW_OVERLAY_ICONS | |
316 | | JavaElementLabelProvider.SHOW_SMALL_ICONS; | |
317 | ITreeContentProvider treeContentProvider= | |
318 | new StandardJavaElementContentProvider() { | |
319 | @Override | |
320 | public boolean hasChildren(Object element) { | |
321 | // prevent the + from being shown in front of packages | |
322 | return !(element instanceof IPackageFragment) && super.hasChildren(element); | |
323 | } | |
324 | }; | |
325 | final DecoratingLabelProvider provider= new DecoratingLabelProvider(new JavaElementLabelProvider(labelFlags), new ProblemsLabelDecorator(null)); | |
326 | fInputGroup= new CheckboxTreeAndListGroup( | |
327 | parent, | |
328 | JavaCore.create(ResourcesPlugin.getWorkspace().getRoot()), | |
329 | treeContentProvider, | |
330 | provider, | |
331 | new StandardJavaElementContentProvider(), | |
332 | provider, | |
333 | SWT.NONE, | |
334 | SIZING_SELECTION_WIDGET_WIDTH, | |
335 | SIZING_SELECTION_WIDGET_HEIGHT) { | |
336 | ||
337 | @Override | |
338 | protected void setTreeChecked(final Object element, final boolean state) { | |
339 | if (fInitiallySelecting && element instanceof IResource) { | |
340 | final IResource resource= (IResource) element; | |
341 | if (resource.getName().charAt(0) == '.') | |
342 | return; | |
343 | } | |
344 | super.setTreeChecked(element, state); | |
345 | } | |
346 | }; | |
347 | fInputGroup.generated_313957834793235097(); | |
348 | fInputGroup.addTreeFilter(new ContainerFilter(ContainerFilter.FILTER_NON_CONTAINERS)); | |
349 | fInputGroup.addTreeFilter(new ViewerFilter() { | |
350 | @Override | |
351 | public boolean select(Viewer viewer, Object p, Object element) { | |
352 | if (element instanceof IPackageFragmentRoot) { | |
353 | IPackageFragmentRoot root= (IPackageFragmentRoot) element; | |
354 | return !root.isArchive() && !root.isExternal(); | |
355 | } | |
356 | return true; | |
357 | } | |
358 | }); | |
359 | fInputGroup.addListFilter(new ContainerFilter(ContainerFilter.FILTER_CONTAINERS)); | |
360 | fInputGroup.getTree().addListener(SWT.MouseUp, this); | |
361 | fInputGroup.getTable().addListener(SWT.MouseUp, this); | |
362 | ||
363 | SWTUtil.setAccessibilityText(fInputGroup.getTree(), JarPackagerMessages.JarPackageWizardPage_tree_accessibility_message); | |
364 | SWTUtil.setAccessibilityText(fInputGroup.getTable(), JarPackagerMessages.JarPackageWizardPage_table_accessibility_message); | |
365 | ||
366 | ICheckStateListener listener = new ICheckStateListener() { | |
367 | public void checkStateChanged(CheckStateChangedEvent event) { | |
368 | update(); | |
369 | } | |
370 | }; | |
371 | ||
372 | fInputGroup.addCheckStateListener(listener); | |
373 | } | |
374 | ||
375 | /** | |
376 | * Creates the export type controls. | |
377 | * | |
378 | * @param parent | |
379 | * the parent control | |
380 | */ | |
381 | protected void createExportTypeGroup(Composite parent) { | |
382 | Composite optionsGroup= new Composite(parent, SWT.NONE); | |
383 | GridLayout layout= new GridLayout(); | |
384 | layout.marginHeight= 0; | |
385 | optionsGroup.setLayout(layout); | |
386 | ||
387 | fExportClassFilesCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
388 | fExportClassFilesCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_exportClassFiles_text); | |
389 | fExportClassFilesCheckbox.addListener(SWT.Selection, this); | |
390 | ||
391 | fExportOutputFoldersCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
392 | fExportOutputFoldersCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_exportOutputFolders_text); | |
393 | fExportOutputFoldersCheckbox.addListener(SWT.Selection, this); | |
394 | ||
395 | fExportJavaFilesCheckbox= new Button(optionsGroup, SWT.CHECK | SWT.LEFT); | |
396 | fExportJavaFilesCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_exportJavaFiles_text); | |
397 | fExportJavaFilesCheckbox.addListener(SWT.Selection, this); | |
398 | ||
399 | Composite refactoringsGroup= new Composite(optionsGroup, SWT.NONE); | |
400 | layout= new GridLayout(); | |
401 | layout.horizontalSpacing= 0; | |
402 | layout.marginWidth= 0; | |
403 | layout.marginHeight= 0; | |
404 | layout.numColumns= 2; | |
405 | refactoringsGroup.setLayout(layout); | |
406 | ||
407 | fExportRefactoringsCheckbox= new Button(refactoringsGroup, SWT.CHECK | SWT.LEFT); | |
408 | fExportRefactoringsCheckbox.setText(JarPackagerMessages.JarPackageWizardPage_refactorings_text); | |
409 | fExportRefactoringsCheckbox.addListener(SWT.Selection, this); | |
410 | ||
411 | fRefactoringLink= new Link(refactoringsGroup, SWT.WRAP); | |
412 | fRefactoringLink.setText(JarPackagerMessages.JarPackageWizardPage_configure_label); | |
413 | fRefactoringLink.addSelectionListener(new SelectionAdapter() { | |
414 | ||
415 | @Override | |
416 | public void widgetSelected(SelectionEvent event) { | |
417 | openRefactoringDialog(); | |
418 | } | |
419 | ||
420 | }); | |
421 | fRefactoringLink.setToolTipText(JarPackagerMessages.JarPackageWizardPage_configure_tooltip); | |
422 | GridData data= new GridData(GridData.BEGINNING | GridData.GRAB_HORIZONTAL); | |
423 | fRefactoringLink.setLayoutData(data); | |
424 | ||
425 | fExportRefactoringsCheckbox.addSelectionListener(new SelectionAdapter() { | |
426 | ||
427 | @Override | |
428 | public void widgetSelected(SelectionEvent event) { | |
429 | fRefactoringLink.setEnabled(fExportRefactoringsCheckbox.getSelection()); | |
430 | } | |
431 | }); | |
432 | } | |
433 | ||
434 | /** | |
435 | * Opens the dialog to configure refactorings. | |
436 | */ | |
437 | protected void openRefactoringDialog() { | |
438 | final RefactoringHistory[] history= { null}; | |
439 | final IRefactoringHistoryService service= RefactoringCore.getHistoryService(); | |
440 | try { | |
441 | service.connect(); | |
442 | final Set<IProject> set= new HashSet<IProject>(); | |
443 | final Object[] elements= fJarPackage.getElements(); | |
444 | for (int index= 0; index < elements.length; index++) { | |
445 | if (elements[index] instanceof IAdaptable) { | |
446 | final IAdaptable adaptable= (IAdaptable) elements[index]; | |
447 | final IResource resource= (IResource) adaptable.getAdapter(IResource.class); | |
448 | if (resource != null) | |
449 | set.add(resource.getProject()); | |
450 | } | |
451 | } | |
452 | try { | |
453 | getContainer().run(false, true, new IRunnableWithProgress() { | |
454 | ||
455 | public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { | |
456 | history[0]= service.getRefactoringHistory(set.toArray(new IProject[set.size()]), 0, Long.MAX_VALUE, JavaRefactoringDescriptor.JAR_MIGRATION, monitor); | |
457 | } | |
458 | }); | |
459 | } catch (InvocationTargetException exception) { | |
460 | ExceptionHandler.handle(exception, getShell(), JarPackagerMessages.JarPackageWizardPage_error_caption, JarPackagerMessages.JarPackageWizardPage_error_label); | |
461 | return; | |
462 | } catch (InterruptedException exception) { | |
463 | return; | |
464 | } | |
465 | new JarRefactoringDialog(getShell(), getDialogSettings(), fJarPackage, history[0]).open(); | |
466 | updatePageCompletion(); | |
467 | } finally { | |
468 | service.disconnect(); | |
469 | } | |
470 | } | |
471 | ||
472 | /** | |
473 | * Updates the enablement of this page's controls. Subclasses may extend. | |
474 | */ | |
475 | @Override | |
476 | protected void updateWidgetEnablements() { | |
477 | if (fExportRefactoringsCheckbox != null) { | |
478 | final boolean selection= fExportRefactoringsCheckbox.getSelection(); | |
479 | fIncludeDirectoryEntriesCheckbox.setEnabled(!selection); | |
480 | if (selection) { | |
481 | fIncludeDirectoryEntriesCheckbox.setSelection(true); | |
482 | fJarPackage.setIncludeDirectoryEntries(true); | |
483 | } | |
484 | } | |
485 | } | |
486 | ||
487 | /* | |
488 | * Overrides method from IJarPackageWizardPage | |
489 | */ | |
490 | @Override | |
491 | public boolean isPageComplete() { | |
492 | boolean complete= validateSourceGroup(); | |
493 | complete= validateDestinationGroup() && complete; | |
494 | complete= validateOptionsGroup() && complete; | |
495 | if (complete) | |
496 | setErrorMessage(null); | |
497 | return complete; | |
498 | } | |
499 | ||
500 | @Override | |
501 | protected void updatePageCompletion() { | |
502 | boolean pageComplete= isPageComplete(); | |
503 | setPageComplete(pageComplete); | |
504 | if (pageComplete) | |
505 | setErrorMessage(null); | |
506 | updateRefactoringMessage(); | |
507 | } | |
508 | ||
509 | protected void updateRefactoringMessage() { | |
510 | String currentMessage= getMessage(); | |
511 | fJarPackage.generated_831327282507552201(this, currentMessage); | |
512 | } | |
513 | ||
514 | /* | |
515 | * Overrides method from WizardDataTransferPage | |
516 | */ | |
517 | @Override | |
518 | protected boolean validateOptionsGroup() { | |
519 | return true; | |
520 | } | |
521 | ||
522 | /* | |
523 | * Overrides method from WizardDataTransferPage | |
524 | */ | |
525 | @Override | |
526 | protected boolean validateSourceGroup() { | |
527 | if (!(fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection() || fExportJavaFilesCheckbox.getSelection())) { | |
528 | setErrorMessage(JarPackagerMessages.JarPackageWizardPage_error_noExportTypeChecked); | |
529 | return false; | |
530 | } | |
531 | ||
532 | if (getSelectedResources().size() == 0) { | |
533 | if (getErrorMessage() != null) | |
534 | setErrorMessage(null); | |
535 | return false; | |
536 | } | |
537 | if (fExportClassFilesCheckbox.getSelection() || fExportOutputFoldersCheckbox.getSelection()) | |
538 | return true; | |
539 | ||
540 | // Source file only export - check if there are source files | |
541 | Iterator<Object> iter= getSelectedResourcesIterator(); | |
542 | while (iter.hasNext()) { | |
543 | Object element= iter.next(); | |
544 | if (element instanceof IClassFile) { | |
545 | IPackageFragmentRoot root= (IPackageFragmentRoot)((IClassFile)element).getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT); | |
546 | if (root == null) | |
547 | continue; | |
548 | IClasspathEntry cpEntry; | |
549 | try { | |
550 | cpEntry= root.getRawClasspathEntry(); | |
551 | } catch (JavaModelException e) { | |
552 | continue; | |
553 | } | |
554 | if (cpEntry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { | |
555 | return true; | |
556 | } | |
557 | } else { | |
558 | return true; | |
559 | } | |
560 | } | |
561 | ||
562 | if (getErrorMessage() != null) | |
563 | setErrorMessage(null); | |
564 | return false; | |
565 | } | |
566 | ||
567 | /** | |
568 | * Creates a file resource handle for the file with the given workspace path. | |
569 | * This method does not create the file resource; this is the responsibility | |
570 | * of <code>createFile</code>. | |
571 | * | |
572 | * @param filePath the path of the file resource to create a handle for | |
573 | * @return the new file resource handle | |
574 | */ | |
575 | protected IFile createFileHandle(IPath filePath) { | |
576 | if (filePath.isValidPath(filePath.toString()) && filePath.segmentCount() >= 2) | |
577 | return ResourcesPlugin.getWorkspace().getRoot().getFile(filePath); | |
578 | else | |
579 | return null; | |
580 | } | |
581 | ||
582 | /* | |
583 | * Overrides method from WizardExportResourcePage | |
584 | */ | |
585 | @Override | |
586 | protected void setupBasedOnInitialSelections() { | |
587 | TreeItem[] items= fInputGroup.generated_4569908924196255318(this); | |
588 | int i= 0; | |
589 | while (i < items.length && !items[i].getChecked()) | |
590 | i++; | |
591 | if (i < items.length) { | |
592 | fInputGroup.getTree().setSelection(new TreeItem[] {items[i]}); | |
593 | fInputGroup.getTree().showSelection(); | |
594 | fInputGroup.populateListViewer(items[i].getData()); | |
595 | } | |
596 | } | |
597 | ||
598 | /* | |
599 | * Method declared on IWizardPage. | |
600 | */ | |
601 | @Override | |
602 | public void setPreviousPage(IWizardPage page) { | |
603 | super.setPreviousPage(page); | |
604 | if (getControl() != null) | |
605 | updatePageCompletion(); | |
606 | } | |
607 | ||
608 | Object[] getSelectedElementsWithoutContainedChildren() { | |
609 | Set<Object> closure= removeContainedChildren(fInputGroup.getWhiteCheckedTreeItems()); | |
610 | closure.addAll(getExportedNonContainers()); | |
611 | return closure.toArray(); | |
612 | } | |
613 | ||
614 | private Set<Object> removeContainedChildren(Set<Object> elements) { | |
615 | Set<Object> newList= new HashSet<Object>(elements.size()); | |
616 | Set<Object> javaElementResources= getCorrespondingContainers(elements); | |
617 | Iterator<Object> iter= elements.iterator(); | |
618 | boolean removedOne= false; | |
619 | while (iter.hasNext()) { | |
620 | Object element= iter.next(); | |
621 | Object parent; | |
622 | if (element instanceof IResource) | |
623 | parent= ((IResource)element).getParent(); | |
624 | else if (element instanceof IJavaElement) { | |
625 | parent= ((IJavaElement)element).getParent(); | |
626 | if (parent instanceof IPackageFragmentRoot) { | |
627 | IPackageFragmentRoot pkgRoot= (IPackageFragmentRoot)parent; | |
628 | try { | |
629 | if (pkgRoot.getCorrespondingResource() instanceof IProject) | |
630 | parent= pkgRoot.getJavaProject(); | |
631 | } catch (JavaModelException ex) { | |
632 | // leave parent as is | |
633 | } | |
634 | } | |
635 | } | |
636 | else { | |
637 | // unknown type | |
638 | newList.add(element); | |
639 | continue; | |
640 | } | |
641 | if (element instanceof IJavaModel || ((!(parent instanceof IJavaModel)) && (elements.contains(parent) || javaElementResources.contains(parent)))) | |
642 | removedOne= true; | |
643 | else | |
644 | newList.add(element); | |
645 | } | |
646 | if (removedOne) | |
647 | return removeContainedChildren(newList); | |
648 | else | |
649 | return newList; | |
650 | } | |
651 | ||
652 | private Set<Object> getExportedNonContainers() { | |
653 | return fInputGroup.generated_2166614146303887296(this); | |
654 | } | |
655 | ||
656 | /* | |
657 | * Create a list with the folders / projects that correspond | |
658 | * to the Java elements (Java project, package, package root) | |
659 | */ | |
660 | Set<Object> getCorrespondingContainers(Set<Object> elements) { | |
661 | Set<Object> javaElementResources= new HashSet<Object>(elements.size()); | |
662 | Iterator<Object> iter= elements.iterator(); | |
663 | while (iter.hasNext()) { | |
664 | Object element= iter.next(); | |
665 | if (element instanceof IJavaElement) { | |
666 | IJavaElement je= (IJavaElement)element; | |
667 | int type= je.getElementType(); | |
668 | if (type == IJavaElement.JAVA_PROJECT || type == IJavaElement.PACKAGE_FRAGMENT || type == IJavaElement.PACKAGE_FRAGMENT_ROOT) { | |
669 | // exclude default package since it is covered by the root | |
670 | if (!(type == IJavaElement.PACKAGE_FRAGMENT && ((IPackageFragment)element).isDefaultPackage())) { | |
671 | Object resource; | |
672 | try { | |
673 | resource= je.getCorrespondingResource(); | |
674 | } catch (JavaModelException ex) { | |
675 | resource= null; | |
676 | } | |
677 | if (resource != null) | |
678 | javaElementResources.add(resource); | |
679 | } | |
680 | } | |
681 | } | |
682 | } | |
683 | return javaElementResources; | |
684 | } | |
685 | ||
686 | public Object[] getSelectedElements() { | |
687 | return getSelectedResources().toArray(); | |
688 | } | |
689 | } |