KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javadocexport > JavadocTreeWizardPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.jdt.internal.ui.javadocexport;
12
13 import java.io.File JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Set JavaDoc;
18 import java.util.StringTokenizer JavaDoc;
19
20 import org.eclipse.core.runtime.CoreException;
21 import org.eclipse.core.runtime.IPath;
22 import org.eclipse.core.runtime.IStatus;
23 import org.eclipse.core.runtime.Path;
24
25 import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.resources.IWorkspaceRoot;
27 import org.eclipse.core.resources.ResourcesPlugin;
28
29 import org.eclipse.swt.SWT;
30 import org.eclipse.swt.custom.CLabel;
31 import org.eclipse.swt.events.ModifyEvent;
32 import org.eclipse.swt.events.ModifyListener;
33 import org.eclipse.swt.events.SelectionAdapter;
34 import org.eclipse.swt.events.SelectionEvent;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Combo;
39 import org.eclipse.swt.widgets.Composite;
40 import org.eclipse.swt.widgets.Control;
41 import org.eclipse.swt.widgets.FileDialog;
42 import org.eclipse.swt.widgets.Label;
43 import org.eclipse.swt.widgets.Text;
44 import org.eclipse.swt.widgets.TreeItem;
45
46 import org.eclipse.jface.dialogs.Dialog;
47 import org.eclipse.jface.viewers.CheckStateChangedEvent;
48 import org.eclipse.jface.viewers.ICheckStateListener;
49 import org.eclipse.jface.viewers.ITreeContentProvider;
50 import org.eclipse.jface.viewers.StructuredSelection;
51
52 import org.eclipse.ui.PlatformUI;
53
54 import org.eclipse.jdt.core.ICompilationUnit;
55 import org.eclipse.jdt.core.IJavaElement;
56 import org.eclipse.jdt.core.IJavaProject;
57 import org.eclipse.jdt.core.IPackageFragment;
58 import org.eclipse.jdt.core.IPackageFragmentRoot;
59 import org.eclipse.jdt.core.JavaConventions;
60 import org.eclipse.jdt.core.JavaModelException;
61
62 import org.eclipse.jdt.launching.JavaRuntime;
63
64 import org.eclipse.jdt.ui.JavaElementComparator;
65 import org.eclipse.jdt.ui.JavaElementLabelProvider;
66
67 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds;
68 import org.eclipse.jdt.internal.ui.JavaPlugin;
69 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo;
70 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil;
71 import org.eclipse.jdt.internal.ui.jarpackager.CheckboxTreeAndListGroup;
72 import org.eclipse.jdt.internal.ui.util.SWTUtil;
73
74 public class JavadocTreeWizardPage extends JavadocWizardPage {
75
76     private CheckboxTreeAndListGroup fInputGroup;
77
78     private Text fDestinationText;
79     private Combo fJavadocCommandText;
80     private Text fDocletText;
81     private Text fDocletTypeText;
82     private Button fStandardButton;
83     private Button fDestinationBrowserButton;
84     private Button fCustomButton;
85     private Button fPrivateVisibility;
86     private Button fProtectedVisibility;
87     private Button fPackageVisibility;
88     private Button fPublicVisibility;
89     private Label fDocletLabel;
90     private Label fDocletTypeLabel;
91     private Label fDestinationLabel;
92     private CLabel fDescriptionLabel;
93     
94     private String JavaDoc fVisibilitySelection;
95
96     private JavadocOptionsManager fStore;
97
98     private StatusInfo fJavadocStatus;
99     private StatusInfo fDestinationStatus;
100     private StatusInfo fDocletStatus;
101     private StatusInfo fTreeStatus;
102     private StatusInfo fPreferenceStatus;
103     private StatusInfo fWizardStatus;
104
105     private final int PREFERENCESTATUS= 0;
106     private final int CUSTOMSTATUS= 1;
107     private final int STANDARDSTATUS= 2;
108     private final int TREESTATUS= 3;
109     private final int JAVADOCSTATUS= 4;
110
111     /**
112      * Constructor for JavadocTreeWizardPage.
113      * @param pageName
114      */

115     protected JavadocTreeWizardPage(String JavaDoc pageName, JavadocOptionsManager store) {
116         super(pageName);
117         setDescription(JavadocExportMessages.JavadocTreeWizardPage_javadoctreewizardpage_description);
118
119         fStore= store;
120
121         // Status variables
122
fJavadocStatus= new StatusInfo();
123         fDestinationStatus= new StatusInfo();
124         fDocletStatus= new StatusInfo();
125         fTreeStatus= new StatusInfo();
126         fPreferenceStatus= new StatusInfo();
127         fWizardStatus= store.getWizardStatus();
128     }
129
130     /*
131      * @see IDialogPage#createControl(Composite)
132      */

133     public void createControl(Composite parent) {
134         initializeDialogUnits(parent);
135
136         final Composite composite= new Composite(parent, SWT.NONE);
137         final GridLayout layout= new GridLayout();
138         layout.numColumns= 6;
139         composite.setLayout(layout);
140
141         createJavadocCommandSet(composite);
142         createInputGroup(composite);
143         createVisibilitySet(composite);
144         createOptionsSet(composite);
145
146         setControl(composite);
147         Dialog.applyDialogFont(composite);
148         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IJavaHelpContextIds.JAVADOC_TREE_PAGE);
149     }
150     
151     protected void createJavadocCommandSet(Composite composite) {
152         
153         final int numColumns= 2;
154         
155         GridLayout layout= createGridLayout(numColumns);
156         layout.marginHeight= 0;
157         layout.marginWidth= 0;
158         Composite group = new Composite(composite, SWT.NONE);
159         group.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 6, 0));
160         group.setLayout(layout);
161
162         createLabel(group, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_javadoccommand_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, numColumns, 0));
163         fJavadocCommandText= createCombo(group, SWT.NONE, null, createGridData(GridData.FILL_HORIZONTAL, numColumns - 1, 0));
164
165         fJavadocCommandText.addModifyListener(new ModifyListener() {
166             public void modifyText(ModifyEvent e) {
167                 doValidation(JAVADOCSTATUS);
168             }
169         });
170
171         final Button javadocCommandBrowserButton= createButton(group, SWT.PUSH, JavadocExportMessages.JavadocTreeWizardPage_javadoccommand_button_label, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, 0));
172         SWTUtil.setButtonDimensionHint(javadocCommandBrowserButton);
173
174         javadocCommandBrowserButton.addSelectionListener(new SelectionAdapter() {
175             public void widgetSelected(SelectionEvent event) {
176                 browseForJavadocCommand();
177             }
178         });
179     }
180     
181
182     
183     
184     protected void createInputGroup(Composite composite) {
185
186         createLabel(composite, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_checkboxtreeandlistgroup_label, createGridData(6));
187         Composite c= new Composite(composite, SWT.NONE);
188         GridLayout layout= new GridLayout();
189         layout.numColumns= 1;
190         layout.makeColumnsEqualWidth= true;
191         layout.marginWidth= 0;
192         layout.marginHeight= 0;
193         c.setLayout(layout);
194         c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 6, 0));
195         
196         ITreeContentProvider treeContentProvider= new JavadocProjectContentProvider();
197         ITreeContentProvider listContentProvider= new JavadocMemberContentProvider();
198         fInputGroup= new CheckboxTreeAndListGroup(c, this, treeContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), listContentProvider, new JavaElementLabelProvider(JavaElementLabelProvider.SHOW_DEFAULT), SWT.NONE, convertWidthInCharsToPixels(60), convertHeightInCharsToPixels(10));
199
200         fInputGroup.addCheckStateListener(new ICheckStateListener() {
201             public void checkStateChanged(CheckStateChangedEvent e) {
202                 doValidation(TREESTATUS);
203             }
204         });
205         fInputGroup.setTreeComparator(new JavaElementComparator());
206         
207         IJavaElement[] elements= fStore.getInitialElements();
208         setTreeChecked(elements);
209         if (elements.length > 0) {
210             fInputGroup.setTreeSelection(new StructuredSelection(elements[0].getJavaProject()));
211         }
212
213         fInputGroup.aboutToOpen();
214     }
215
216     private void createVisibilitySet(Composite composite) {
217
218         GridLayout visibilityLayout= createGridLayout(4);
219         visibilityLayout.marginHeight= 0;
220         visibilityLayout.marginWidth= 0;
221         Composite visibilityGroup= new Composite(composite, SWT.NONE);
222         visibilityGroup.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 6, 0));
223         visibilityGroup.setLayout(visibilityLayout);
224
225         createLabel(visibilityGroup, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_visibilitygroup_label, createGridData(GridData.FILL_HORIZONTAL, 4, 0));
226         fPrivateVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_privatebutton_label, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
227         fPackageVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_packagebutton_label, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
228         fProtectedVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_protectedbutton_label, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
229         fPublicVisibility= createButton(visibilityGroup, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_publicbutton_label, createGridData(GridData.FILL_HORIZONTAL, 1, 0));
230
231         fDescriptionLabel= new CLabel(visibilityGroup, SWT.LEFT);
232         fDescriptionLabel.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 4, convertWidthInCharsToPixels(3) - 3)); // INDENT of CLabel
233

234         fPrivateVisibility.addSelectionListener(new SelectionAdapter() {
235             public void widgetSelected(SelectionEvent e) {
236                 if (((Button) e.widget).getSelection()) {
237                     fVisibilitySelection= fStore.PRIVATE;
238                     fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_privatevisibilitydescription_label);
239                 }
240             }
241         });
242         fPackageVisibility.addSelectionListener(new SelectionAdapter() {
243             public void widgetSelected(SelectionEvent e) {
244                 if (((Button) e.widget).getSelection()) {
245                     fVisibilitySelection= fStore.PACKAGE;
246                     fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_packagevisibledescription_label);
247                 }
248             }
249         });
250         fProtectedVisibility.addSelectionListener(new SelectionAdapter() {
251             public void widgetSelected(SelectionEvent e) {
252                 if (((Button) e.widget).getSelection()) {
253                     fVisibilitySelection= fStore.PROTECTED;
254                     fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_protectedvisibilitydescription_label);
255                 }
256             }
257         });
258
259         fPublicVisibility.addSelectionListener(new SelectionAdapter() {
260             public void widgetSelected(SelectionEvent e) {
261                 if (((Button) e.widget).getSelection()) {
262                     fVisibilitySelection= fStore.PUBLIC;
263                     fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_publicvisibilitydescription_label);
264                 }
265             }
266         });
267
268         setVisibilitySettings();
269
270     }
271
272     protected void setVisibilitySettings() {
273         fVisibilitySelection= fStore.getAccess();
274         fPrivateVisibility.setSelection(fVisibilitySelection.equals(fStore.PRIVATE));
275         if (fPrivateVisibility.getSelection())
276             fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_privatevisibilitydescription_label);
277
278         fProtectedVisibility.setSelection(fVisibilitySelection.equals(fStore.PROTECTED));
279         if (fProtectedVisibility.getSelection())
280             fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_protectedvisibilitydescription_label);
281
282         fPackageVisibility.setSelection(fVisibilitySelection.equals(fStore.PACKAGE));
283         if (fPackageVisibility.getSelection())
284             fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_packagevisibledescription_label);
285
286         fPublicVisibility.setSelection(fVisibilitySelection.equals(fStore.PUBLIC));
287         if (fPublicVisibility.getSelection())
288             fDescriptionLabel.setText(JavadocExportMessages.JavadocTreeWizardPage_publicvisibilitydescription_label);
289     }
290
291     private void createOptionsSet(Composite composite) {
292         
293         final int numColumns= 4;
294
295         final GridLayout layout= createGridLayout(numColumns);
296         layout.marginHeight= 0;
297         layout.marginWidth= 0;
298         Composite group= new Composite(composite, SWT.NONE);
299         group.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 6, 0));
300         group.setLayout(layout);
301
302         fStandardButton= createButton(group, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_standarddocletbutton_label, createGridData(GridData.HORIZONTAL_ALIGN_FILL, numColumns, 0));
303
304         fDestinationLabel= createLabel(group, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_destinationfield_label, createGridData(GridData.HORIZONTAL_ALIGN_FILL, 1, convertWidthInCharsToPixels(3)));
305         fDestinationText= createText(group, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, numColumns - 2, 0));
306         ((GridData) fDestinationText.getLayoutData()).widthHint= 0;
307         fDestinationText.addModifyListener(new ModifyListener() {
308             public void modifyText(ModifyEvent e) {
309                 doValidation(STANDARDSTATUS);
310             }
311         });
312
313         fDestinationBrowserButton= createButton(group, SWT.PUSH, JavadocExportMessages.JavadocTreeWizardPage_destinationbrowse_label, createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 0));
314         SWTUtil.setButtonDimensionHint(fDestinationBrowserButton);
315
316         //Option to use custom doclet
317
fCustomButton= createButton(group, SWT.RADIO, JavadocExportMessages.JavadocTreeWizardPage_customdocletbutton_label, createGridData(GridData.HORIZONTAL_ALIGN_FILL, numColumns, 0));
318         
319         //For Entering location of custom doclet
320
fDocletTypeLabel= createLabel(group, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_docletnamefield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, convertWidthInCharsToPixels(3)));
321         fDocletTypeText= createText(group, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, numColumns - 1, 0));
322         ((GridData) fDocletTypeText.getLayoutData()).widthHint= 0;
323         
324         
325         fDocletTypeText.addModifyListener(new ModifyListener() {
326             public void modifyText(ModifyEvent e) {
327                 doValidation(CUSTOMSTATUS);
328             }
329         });
330
331         fDocletLabel= createLabel(group, SWT.NONE, JavadocExportMessages.JavadocTreeWizardPage_docletpathfield_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 1, convertWidthInCharsToPixels(3)));
332         fDocletText= createText(group, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.HORIZONTAL_ALIGN_FILL, numColumns - 1, 0));
333         ((GridData) fDocletText.getLayoutData()).widthHint= 0;
334         
335         fDocletText.addModifyListener(new ModifyListener() {
336             public void modifyText(ModifyEvent e) {
337                 doValidation(CUSTOMSTATUS);
338             }
339
340         });
341
342         //Add Listeners
343
fCustomButton.addSelectionListener(new EnableSelectionAdapter(new Control[] { fDocletLabel, fDocletText, fDocletTypeLabel, fDocletTypeText }, new Control[] { fDestinationLabel, fDestinationText, fDestinationBrowserButton }));
344         fCustomButton.addSelectionListener(new SelectionAdapter() {
345             public void widgetSelected(SelectionEvent e) {
346                 doValidation(CUSTOMSTATUS);
347             }
348         });
349         fStandardButton.addSelectionListener(new EnableSelectionAdapter(new Control[] { fDestinationLabel, fDestinationText, fDestinationBrowserButton }, new Control[] { fDocletLabel, fDocletText, fDocletTypeLabel, fDocletTypeText }));
350         fStandardButton.addSelectionListener(new SelectionAdapter() {
351             public void widgetSelected(SelectionEvent e) {
352                 doValidation(STANDARDSTATUS);
353             }
354         });
355         fDestinationBrowserButton.addSelectionListener(new SelectionAdapter() {
356             public void widgetSelected(SelectionEvent event) {
357                 String JavaDoc text= handleFolderBrowseButtonPressed(fDestinationText.getText(), JavadocExportMessages.JavadocTreeWizardPage_destinationbrowsedialog_title,
358                         JavadocExportMessages.JavadocTreeWizardPage_destinationbrowsedialog_label);
359                 fDestinationText.setText(text);
360             }
361         });
362
363         setOptionSetSettings();
364     }
365
366     public boolean getCustom() {
367         return fCustomButton.getSelection();
368     }
369
370     private void setOptionSetSettings() {
371
372         if (!fStore.isFromStandard()) {
373             fCustomButton.setSelection(true);
374             fDocletText.setText(fStore.getDocletPath());
375             fDocletTypeText.setText(fStore.getDocletName());
376             fDestinationText.setText(fStore.getDestination());
377             fDestinationText.setEnabled(false);
378             fDestinationBrowserButton.setEnabled(false);
379             fDestinationLabel.setEnabled(false);
380             
381         } else {
382             fStandardButton.setSelection(true);
383             fDestinationText.setText(fStore.getDestination());
384             fDocletText.setText(fStore.getDocletPath());
385             fDocletTypeText.setText(fStore.getDocletName());
386             fDocletText.setEnabled(false);
387             fDocletLabel.setEnabled(false);
388             fDocletTypeText.setEnabled(false);
389             fDocletTypeLabel.setEnabled(false);
390         }
391         
392         fJavadocCommandText.setItems(fStore.getJavadocCommandHistory());
393         fJavadocCommandText.select(0);
394     }
395
396     /**
397      * Receives of list of elements selected by the user and passes them
398      * to the CheckedTree. List can contain multiple projects and elements from
399      * different projects. If the list of seletected elements is empty a default
400      * project is selected.
401      */

402     private void setTreeChecked(IJavaElement[] sourceElements) {
403         for (int i= 0; i < sourceElements.length; i++) {
404             IJavaElement curr= sourceElements[i];
405             if (curr instanceof ICompilationUnit) {
406                 fInputGroup.initialCheckListItem(curr);
407             } else if (curr instanceof IPackageFragment) {
408                 fInputGroup.initialCheckTreeItem(curr);
409             } else if (curr instanceof IJavaProject) {
410                 fInputGroup.initialCheckTreeItem(curr);
411             } else if (curr instanceof IPackageFragmentRoot) {
412                 IPackageFragmentRoot root= (IPackageFragmentRoot) curr;
413                 if (!root.isArchive())
414                     fInputGroup.initialCheckTreeItem(curr);
415             }
416         }
417     }
418
419     private IPath[] getSourcePath(IJavaProject[] projects) {
420         HashSet JavaDoc res= new HashSet JavaDoc();
421         //loops through all projects and gets a list if of their source paths
422
for (int k= 0; k < projects.length; k++) {
423             IJavaProject iJavaProject= projects[k];
424
425             try {
426                 IPackageFragmentRoot[] roots= iJavaProject.getPackageFragmentRoots();
427                 for (int i= 0; i < roots.length; i++) {
428                     IPackageFragmentRoot curr= roots[i];
429                     if (curr.getKind() == IPackageFragmentRoot.K_SOURCE) {
430                         IResource resource= curr.getResource();
431                         if (resource != null) {
432                             // Using get location is OK here. If the source folder
433
// isn't local we can't create Javadoc for it.
434
IPath p= resource.getLocation();
435                             if (p != null) {
436                                 res.add(p);
437                             }
438                         }
439                     }
440                 }
441             } catch (JavaModelException e) {
442                 JavaPlugin.log(e);
443             }
444         }
445         return (IPath[]) res.toArray(new IPath[res.size()]);
446     }
447
448     private IPath[] getClassPath(IJavaProject[] javaProjects) {
449         HashSet JavaDoc res= new HashSet JavaDoc();
450
451         IWorkspaceRoot root= ResourcesPlugin.getWorkspace().getRoot();
452         for (int j= 0; j < javaProjects.length; j++) {
453             IJavaProject curr= javaProjects[j];
454             try {
455                 IPath outputLocation= null;
456                 
457                 // Not really clear yet what to do here for EFS. See bug
458
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=113233.
459

460                 // However if the output location is not local it is currently
461
// not part of JavaRuntime.computeDefaultRuntimeClassPath either
462
// so it will be simply not added to the result which would be
463
// correct.
464
IResource outputPathFolder= root.findMember(curr.getOutputLocation());
465                 if (outputPathFolder != null)
466                     outputLocation= outputPathFolder.getLocation();
467
468                 String JavaDoc[] classPath= JavaRuntime.computeDefaultRuntimeClassPath(curr);
469                 for (int i= 0; i < classPath.length; i++) {
470                     IPath path= Path.fromOSString(classPath[i]);
471                     if (!path.equals(outputLocation)) {
472                         res.add(path);
473                     }
474                 }
475             } catch (CoreException e) {
476                 JavaPlugin.log(e);
477             }
478         }
479         return (IPath[]) res.toArray(new IPath[res.size()]);
480     }
481
482     /**
483      * Gets a list of elements to generated javadoc for from each project.
484      * Javadoc can be generated for either a IPackageFragment or a ICompilationUnit.
485      */

486     private IJavaElement[] getSourceElements(IJavaProject[] projects) {
487         ArrayList JavaDoc res= new ArrayList JavaDoc();
488         try {
489             Set JavaDoc allChecked= fInputGroup.getAllCheckedTreeItems();
490
491             Set JavaDoc incompletePackages= new HashSet JavaDoc();
492             for (int h= 0; h < projects.length; h++) {
493                 IJavaProject iJavaProject= projects[h];
494
495                 IPackageFragmentRoot[] roots= iJavaProject.getPackageFragmentRoots();
496                 for (int i= 0; i < roots.length; i++) {
497                     IPackageFragmentRoot root= roots[i];
498                     if (root.getKind() == IPackageFragmentRoot.K_SOURCE) {
499                         IPath rootLocation= root.getResource().getLocation();
500                         IJavaElement[] packs= root.getChildren();
501                         for (int k= 0; k < packs.length; k++) {
502                             IJavaElement curr= packs[k];
503                             if (curr.getElementType() == IJavaElement.PACKAGE_FRAGMENT) {
504                                 // default packages are always incomplete
505
if (curr.getElementName().length() == 0 || !allChecked.contains(curr)
506                                         || fInputGroup.isTreeItemGreyChecked(curr) || !isAccessibleLocation(curr.getResource().getLocation(), rootLocation)) {
507                                     incompletePackages.add(curr.getElementName());
508                                 }
509                             }
510                         }
511                     }
512                 }
513             }
514
515             Iterator JavaDoc checkedElements= fInputGroup.getAllCheckedListItems();
516             while (checkedElements.hasNext()) {
517                 Object JavaDoc element= checkedElements.next();
518                 if (element instanceof ICompilationUnit) {
519                     ICompilationUnit unit= (ICompilationUnit) element;
520                     if (incompletePackages.contains(unit.getParent().getElementName())) {
521                         res.add(unit);
522                     }
523                 }
524             }
525
526             Set JavaDoc addedPackages= new HashSet JavaDoc();
527
528             checkedElements= allChecked.iterator();
529             while (checkedElements.hasNext()) {
530                 Object JavaDoc element= checkedElements.next();
531                 if (element instanceof IPackageFragment) {
532                     IPackageFragment fragment= (IPackageFragment) element;
533                     String JavaDoc name= fragment.getElementName();
534                     if (!incompletePackages.contains(name) && !addedPackages.contains(name)) {
535                         res.add(fragment);
536                         addedPackages.add(name);
537                     }
538                 }
539             }
540
541         } catch (JavaModelException e) {
542             JavaPlugin.log(e);
543         }
544         return (IJavaElement[]) res.toArray(new IJavaElement[res.size()]);
545     }
546
547     private boolean isAccessibleLocation(IPath packageLocation, IPath rootLocation) {
548         return rootLocation != null && packageLocation != null && rootLocation.isPrefixOf(packageLocation);
549     }
550
551     protected void updateStore(IJavaProject[] checkedProjects) {
552
553         if (fCustomButton.getSelection()) {
554             fStore.setDocletName(fDocletTypeText.getText());
555             fStore.setDocletPath(fDocletText.getText());
556             fStore.setFromStandard(false);
557         }
558         if (fStandardButton.getSelection()) {
559             fStore.setFromStandard(true);
560             //the destination used in javadoc generation
561
fStore.setDestination(fDestinationText.getText());
562         }
563
564         fStore.setSourcepath(getSourcePath(checkedProjects));
565         fStore.setClasspath(getClassPath(checkedProjects));
566         fStore.setAccess(fVisibilitySelection);
567         fStore.setSelectedElements(getSourceElements(checkedProjects));
568         
569         ArrayList JavaDoc commands= new ArrayList JavaDoc();
570         commands.add(fJavadocCommandText.getText()); // must be first
571
String JavaDoc[] items= fJavadocCommandText.getItems();
572         for (int i= 0; i < items.length; i++) {
573             String JavaDoc curr= items[i];
574             if (!commands.contains(curr)) {
575                 commands.add(curr);
576             }
577         }
578         fStore.setJavadocCommandHistory((String JavaDoc[]) commands.toArray(new String JavaDoc[commands.size()]));
579     }
580
581     public IJavaProject[] getCheckedProjects() {
582         ArrayList JavaDoc res= new ArrayList JavaDoc();
583         TreeItem[] treeItems= fInputGroup.getTree().getItems();
584         for (int i= 0; i < treeItems.length; i++) {
585             if (treeItems[i].getChecked()) {
586                 Object JavaDoc curr= treeItems[i].getData();
587                 if (curr instanceof IJavaProject) {
588                     res.add(curr);
589                 }
590             }
591         }
592         return (IJavaProject[]) res.toArray(new IJavaProject[res.size()]);
593     }
594     
595     protected void doValidation(int validate) {
596
597         
598         switch (validate) {
599             case PREFERENCESTATUS :
600                 fPreferenceStatus= new StatusInfo();
601                 fDocletStatus= new StatusInfo();
602                 updateStatus(findMostSevereStatus());
603                 break;
604             case CUSTOMSTATUS :
605
606                 if (fCustomButton.getSelection()) {
607                     fDestinationStatus= new StatusInfo();
608                     fDocletStatus= new StatusInfo();
609                     String JavaDoc doclet= fDocletTypeText.getText();
610                     String JavaDoc docletPath= fDocletText.getText();
611                     if (doclet.length() == 0) {
612                         fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_nodocletname_error);
613
614                     } else if (JavaConventions.validateJavaTypeName(doclet).matches(IStatus.ERROR)) {
615                         fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invaliddocletname_error);
616                     } else if ((docletPath.length() == 0) || !validDocletPath(docletPath)) {
617                         fDocletStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invaliddocletpath_error);
618                     }
619                     updateStatus(findMostSevereStatus());
620                 }
621                 break;
622
623             case STANDARDSTATUS :
624                 if (fStandardButton.getSelection()) {
625                     fDestinationStatus= new StatusInfo();
626                     fDocletStatus= new StatusInfo();
627                     String JavaDoc dest= fDestinationText.getText();
628                     if (dest.length() == 0) {
629                         fDestinationStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_nodestination_error);
630                     }
631                     File JavaDoc file= new File JavaDoc(dest);
632                     if (!Path.ROOT.isValidPath(dest) || file.isFile()) {
633                         fDestinationStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invaliddestination_error);
634                     }
635                     if (new File JavaDoc(dest, "package-list").exists() || new File JavaDoc(dest, "index.html").exists()) //$NON-NLS-1$//$NON-NLS-2$
636
fDestinationStatus.setWarning(JavadocExportMessages.JavadocTreeWizardPage_warning_mayoverwritefiles);
637                     updateStatus(findMostSevereStatus());
638                 }
639                 break;
640
641             case TREESTATUS :
642
643                 fTreeStatus= new StatusInfo();
644
645                 if (!fInputGroup.getAllCheckedListItems().hasNext())
646                     fTreeStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_invalidtreeselection_error);
647                 updateStatus(findMostSevereStatus());
648
649                 break;
650                 
651             case JAVADOCSTATUS:
652                 fJavadocStatus= new StatusInfo();
653                 String JavaDoc text= fJavadocCommandText.getText();
654                 if (text.length() == 0) {
655                     fJavadocStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_javadoccmd_error_enterpath);
656                 } else {
657                     File JavaDoc file= new File JavaDoc(text);
658                     if (!file.isFile()) {
659                         fJavadocStatus.setError(JavadocExportMessages.JavadocTreeWizardPage_javadoccmd_error_notexists);
660                     }
661                 }
662                 updateStatus(findMostSevereStatus());
663                 break;
664         } //end switch
665

666         
667     }
668     
669     protected void browseForJavadocCommand() {
670         FileDialog dialog= new FileDialog(getShell());
671         dialog.setText(JavadocExportMessages.JavadocTreeWizardPage_javadoccmd_dialog_title);
672         String JavaDoc dirName= fJavadocCommandText.getText();
673         dialog.setFileName(dirName);
674         String JavaDoc selectedDirectory= dialog.open();
675         if (selectedDirectory != null) {
676             ArrayList JavaDoc newItems= new ArrayList JavaDoc();
677             String JavaDoc[] items= fJavadocCommandText.getItems();
678             newItems.add(selectedDirectory);
679             for (int i= 0; i < items.length && newItems.size() < 5; i++) { // only keep the last 5 entries
680
String JavaDoc curr= items[i];
681                 if (!newItems.contains(curr)) {
682                     newItems.add(curr);
683                 }
684             }
685             fJavadocCommandText.setItems((String JavaDoc[]) newItems.toArray(new String JavaDoc[newItems.size()]));
686             fJavadocCommandText.select(0);
687         }
688     }
689     
690
691     private boolean validDocletPath(String JavaDoc docletPath) {
692         StringTokenizer JavaDoc tokens= new StringTokenizer JavaDoc(docletPath, ";"); //$NON-NLS-1$
693
while (tokens.hasMoreTokens()) {
694             File JavaDoc file= new File JavaDoc(tokens.nextToken());
695             if (!file.exists())
696                 return false;
697         }
698         return true;
699     }
700
701     /**
702      * Finds the most severe error (if there is one)
703      */

704     private IStatus findMostSevereStatus() {
705         return StatusUtil.getMostSevere(new IStatus[] { fJavadocStatus, fPreferenceStatus, fDestinationStatus, fDocletStatus, fTreeStatus, fWizardStatus });
706     }
707
708     public void init() {
709         updateStatus(new StatusInfo());
710     }
711
712     public void setVisible(boolean visible) {
713         if (visible) {
714             doValidation(STANDARDSTATUS);
715             doValidation(CUSTOMSTATUS);
716             doValidation(TREESTATUS);
717             doValidation(PREFERENCESTATUS);
718             doValidation(JAVADOCSTATUS);
719         }
720         super.setVisible(visible);
721     }
722
723 }
724
Popular Tags