1 11 12 package org.eclipse.jdt.internal.ui.javadocexport; 13 14 import java.io.File ; 15 import java.lang.reflect.InvocationTargetException ; 16 import java.net.URL ; 17 import java.util.ArrayList ; 18 import java.util.Arrays ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.eclipse.core.runtime.CoreException; 24 import org.eclipse.core.runtime.IPath; 25 import org.eclipse.core.runtime.IProgressMonitor; 26 import org.eclipse.core.runtime.IStatus; 27 28 import org.eclipse.core.resources.IProject; 29 import org.eclipse.core.resources.IWorkspaceRunnable; 30 31 import org.eclipse.swt.SWT; 32 import org.eclipse.swt.events.ModifyEvent; 33 import org.eclipse.swt.events.ModifyListener; 34 import org.eclipse.swt.events.SelectionAdapter; 35 import org.eclipse.swt.events.SelectionEvent; 36 import org.eclipse.swt.layout.GridData; 37 import org.eclipse.swt.layout.GridLayout; 38 import org.eclipse.swt.widgets.Button; 39 import org.eclipse.swt.widgets.Composite; 40 import org.eclipse.swt.widgets.Control; 41 import org.eclipse.swt.widgets.Group; 42 import org.eclipse.swt.widgets.Shell; 43 import org.eclipse.swt.widgets.Text; 44 45 import org.eclipse.jface.dialogs.Dialog; 46 import org.eclipse.jface.dialogs.StatusDialog; 47 import org.eclipse.jface.viewers.ViewerComparator; 48 import org.eclipse.jface.window.Window; 49 50 import org.eclipse.ui.PlatformUI; 51 52 import org.eclipse.jdt.core.IClasspathEntry; 53 import org.eclipse.jdt.core.IJavaProject; 54 import org.eclipse.jdt.core.JavaCore; 55 56 import org.eclipse.jdt.launching.IRuntimeClasspathEntry; 57 import org.eclipse.jdt.launching.JavaRuntime; 58 59 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 60 import org.eclipse.jdt.internal.ui.JavaPlugin; 61 import org.eclipse.jdt.internal.ui.actions.WorkbenchRunnableAdapter; 62 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 63 import org.eclipse.jdt.internal.ui.dialogs.StatusUtil; 64 import org.eclipse.jdt.internal.ui.preferences.JavadocConfigurationBlock; 65 import org.eclipse.jdt.internal.ui.util.ExceptionHandler; 66 import org.eclipse.jdt.internal.ui.util.SWTUtil; 67 import org.eclipse.jdt.internal.ui.wizards.IStatusChangeListener; 68 import org.eclipse.jdt.internal.ui.wizards.dialogfields.CheckedListDialogField; 69 import org.eclipse.jdt.internal.ui.wizards.dialogfields.DialogField; 70 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IDialogFieldListener; 71 import org.eclipse.jdt.internal.ui.wizards.dialogfields.IListAdapter; 72 import org.eclipse.jdt.internal.ui.wizards.dialogfields.LayoutUtil; 73 import org.eclipse.jdt.internal.ui.wizards.dialogfields.ListDialogField; 74 75 public class JavadocStandardWizardPage extends JavadocWizardPage { 76 77 78 private final int STYLESHEETSTATUS= 1; 79 private final int LINK_REFERENCES= 2; 80 81 private JavadocOptionsManager fStore; 82 private Composite fUpperComposite; 83 84 private Group fBasicOptionsGroup; 85 private Group fTagsGroup; 86 87 private Button fTitleButton; 88 private Text fTitleText; 89 private Text fStyleSheetText; 90 private FlaggedButton fDeprecatedList; 91 private FlaggedButton fDeprecatedCheck; 92 private FlaggedButton fIndexCheck; 93 private FlaggedButton fSeperatedIndexCheck; 94 private Button fStyleSheetBrowseButton; 95 private Button fStyleSheetButton; 96 97 private CheckedListDialogField fListDialogField; 98 99 private StatusInfo fStyleSheetStatus; 100 private StatusInfo fLinkRefStatus; 101 102 private ArrayList fButtonsList; 103 private JavadocTreeWizardPage fFirstPage; 104 105 106 public JavadocStandardWizardPage(String pageName, JavadocTreeWizardPage firstPage, JavadocOptionsManager store) { 107 super(pageName); 108 fFirstPage= firstPage; 109 setDescription(JavadocExportMessages.JavadocStandardWizardPage_description); 110 111 fStore= store; 112 fButtonsList= new ArrayList (); 113 fStyleSheetStatus= new StatusInfo(); 114 fLinkRefStatus= new StatusInfo(); 115 } 116 119 public void createControl(Composite parent) { 120 121 initializeDialogUnits(parent); 122 123 fUpperComposite= new Composite(parent, SWT.NONE); 124 fUpperComposite.setFont(parent.getFont()); 125 fUpperComposite.setLayoutData(createGridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL, 1, 0)); 126 127 GridLayout layout= createGridLayout(4); 128 layout.marginHeight= 0; 129 fUpperComposite.setLayout(layout); 130 131 createBasicOptionsGroup(fUpperComposite); 132 createTagOptionsGroup(fUpperComposite); 133 createListDialogField(fUpperComposite); 134 createStyleSheetGroup(fUpperComposite); 135 136 setControl(fUpperComposite); 137 Dialog.applyDialogFont(fUpperComposite); 138 PlatformUI.getWorkbench().getHelpSystem().setHelp(fUpperComposite, IJavaHelpContextIds.JAVADOC_STANDARD_PAGE); 139 } 140 private void createBasicOptionsGroup(Composite composite) { 141 142 fTitleButton= createButton(composite, SWT.CHECK, JavadocExportMessages.JavadocStandardWizardPage_titlebutton_label, createGridData(1)); 143 fTitleText= createText(composite, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 3, 0)); 144 String text= fStore.getTitle(); 145 if (!text.equals("")) { fTitleText.setText(text); 147 fTitleButton.setSelection(true); 148 } else 149 fTitleText.setEnabled(false); 150 151 fBasicOptionsGroup= new Group(composite, SWT.SHADOW_ETCHED_IN); 152 fBasicOptionsGroup.setLayout(createGridLayout(1)); 153 fBasicOptionsGroup.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 2, 0)); 154 fBasicOptionsGroup.setText(JavadocExportMessages.JavadocStandardWizardPage_basicgroup_label); 155 156 new FlaggedButton(fBasicOptionsGroup, JavadocExportMessages.JavadocStandardWizardPage_usebutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.USE, true); 157 new FlaggedButton(fBasicOptionsGroup, JavadocExportMessages.JavadocStandardWizardPage_hierarchybutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.NOTREE, false); 158 new FlaggedButton(fBasicOptionsGroup, JavadocExportMessages.JavadocStandardWizardPage_navigartorbutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.NONAVBAR, false); 159 160 fIndexCheck= new FlaggedButton(fBasicOptionsGroup, JavadocExportMessages.JavadocStandardWizardPage_indexbutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.NOINDEX, false); 161 162 fSeperatedIndexCheck= new FlaggedButton(fBasicOptionsGroup, JavadocExportMessages.JavadocStandardWizardPage_seperateindexbutton_label, createGridData(GridData.GRAB_HORIZONTAL, 1, convertWidthInCharsToPixels(3)), fStore.SPLITINDEX, true); 163 fSeperatedIndexCheck.getButton().setEnabled(fIndexCheck.getButton().getSelection()); 164 165 fIndexCheck.getButton().addSelectionListener(new ToggleSelectionAdapter(new Control[] { fSeperatedIndexCheck.getButton()})); 166 fTitleButton.addSelectionListener(new ToggleSelectionAdapter(new Control[] { fTitleText })); 167 168 } 169 170 private void createTagOptionsGroup(Composite composite) { 171 fTagsGroup= new Group(composite, SWT.SHADOW_ETCHED_IN); 172 fTagsGroup.setLayout(createGridLayout(1)); 173 fTagsGroup.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 2, 0)); 174 fTagsGroup.setText(JavadocExportMessages.JavadocStandardWizardPage_tagsgroup_label); 175 176 new FlaggedButton(fTagsGroup, JavadocExportMessages.JavadocStandardWizardPage_authorbutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.AUTHOR, true); 177 new FlaggedButton(fTagsGroup, JavadocExportMessages.JavadocStandardWizardPage_versionbutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.VERSION, true); 178 fDeprecatedCheck= new FlaggedButton(fTagsGroup, JavadocExportMessages.JavadocStandardWizardPage_deprecatedbutton_label, new GridData(GridData.FILL_HORIZONTAL), fStore.NODEPRECATED, false); 179 fDeprecatedList= new FlaggedButton(fTagsGroup, JavadocExportMessages.JavadocStandardWizardPage_deprecatedlistbutton_label, createGridData(GridData.FILL_HORIZONTAL, 1, convertWidthInCharsToPixels(3)), fStore.NODEPRECATEDLIST, false); 180 fDeprecatedList.getButton().setEnabled(fDeprecatedCheck.getButton().getSelection()); 181 182 fDeprecatedCheck.getButton().addSelectionListener(new ToggleSelectionAdapter(new Control[] { fDeprecatedList.getButton()})); 183 } 185 private void createStyleSheetGroup(Composite composite) { 186 Composite c= new Composite(composite, SWT.NONE); 187 c.setLayout(createGridLayout(3)); 188 c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL, 4, 0)); 189 ((GridLayout) c.getLayout()).marginWidth= 0; 190 191 fStyleSheetButton= createButton(c, SWT.CHECK, JavadocExportMessages.JavadocStandardWizardPage_stylesheettext_label, createGridData(1)); 192 fStyleSheetText= createText(c, SWT.SINGLE | SWT.BORDER, null, createGridData(GridData.FILL_HORIZONTAL, 1, 0)); 193 ((GridData) fStyleSheetText.getLayoutData()).widthHint= 200; 195 fStyleSheetBrowseButton= createButton(c, SWT.PUSH, JavadocExportMessages.JavadocStandardWizardPage_stylesheetbrowsebutton_label, createGridData(GridData.HORIZONTAL_ALIGN_END, 1, 0)); 196 SWTUtil.setButtonDimensionHint(fStyleSheetBrowseButton); 197 198 String str= fStore.getStyleSheet(); 199 if (str.equals("")) { fStyleSheetText.setEnabled(false); 202 fStyleSheetBrowseButton.setEnabled(false); 203 } else { 204 fStyleSheetButton.setSelection(true); 205 fStyleSheetText.setText(str); 206 } 207 208 fStyleSheetButton.addSelectionListener(new ToggleSelectionAdapter(new Control[] { fStyleSheetText, fStyleSheetBrowseButton }) { 210 public void validate() { 211 doValidation(STYLESHEETSTATUS); 212 } 213 }); 214 215 fStyleSheetText.addModifyListener(new ModifyListener() { 216 public void modifyText(ModifyEvent e) { 217 doValidation(STYLESHEETSTATUS); 218 } 219 }); 220 221 fStyleSheetBrowseButton.addSelectionListener(new SelectionAdapter() { 222 public void widgetSelected(SelectionEvent event) { 223 handleFileBrowseButtonPressed(fStyleSheetText, new String [] { "*.css" }, JavadocExportMessages.JavadocSpecificsWizardPage_stylesheetbrowsedialog_title); } 225 }); 226 227 } 228 229 private void createListDialogField(Composite composite) { 230 Composite c= new Composite(composite, SWT.NONE); 231 c.setFont(composite.getFont()); 232 c.setLayout(createGridLayout(3)); 233 c.setLayoutData(createGridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL, 4, 0)); 234 ((GridLayout) c.getLayout()).marginWidth= 0; 235 236 String [] buttonlabels= new String [] { JavadocExportMessages.JavadocStandardWizardPage_selectallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_clearallbutton_label, JavadocExportMessages.JavadocStandardWizardPage_configurebutton_label}; 237 238 JavadocLinkDialogLabelProvider labelProvider= new JavadocLinkDialogLabelProvider(); 239 240 ListAdapter adapter= new ListAdapter(); 241 242 fListDialogField= new CheckedListDialogField(adapter, buttonlabels, labelProvider); 243 fListDialogField.setDialogFieldListener(adapter); 244 fListDialogField.setCheckAllButtonIndex(0); 245 fListDialogField.setUncheckAllButtonIndex(1); 246 fListDialogField.setViewerComparator(new ViewerComparator()); 247 248 createLabel(c, SWT.NONE, JavadocExportMessages.JavadocStandardWizardPage_referencedclasses_label, createGridData(GridData.HORIZONTAL_ALIGN_BEGINNING, 4, 0)); 249 fListDialogField.doFillIntoGrid(c, 3); 250 251 LayoutUtil.setHorizontalGrabbing(fListDialogField.getListControl(null)); 252 253 fListDialogField.enableButton(2, false); 254 } 255 256 private List getCheckedReferences(JavadocLinkRef[] referencesClasses) { 257 List checkedElements= new ArrayList (); 258 259 String hrefs[]= fStore.getHRefs(); 260 if (hrefs.length > 0) { 261 HashSet set= new HashSet (); 262 for (int i= 0; i < hrefs.length; i++) { 263 set.add(hrefs[i]); 264 } 265 for (int i = 0; i < referencesClasses.length; i++) { 266 JavadocLinkRef curr= referencesClasses[i]; 267 URL url= curr.getURL(); 268 if (url != null && set.contains(url.toExternalForm())) { 269 checkedElements.add(curr); 270 } 271 } 272 } 273 return checkedElements; 274 } 275 276 277 278 281 private JavadocLinkRef[] getReferencedElements(IJavaProject[] checkedProjects) { 282 HashSet result= new HashSet (); 283 for (int i= 0; i < checkedProjects.length; i++) { 284 IJavaProject project= checkedProjects[i]; 285 try { 286 collectReferencedElements(project, result); 287 } catch (CoreException e) { 288 JavaPlugin.log(e); 289 } 291 } 292 return (JavadocLinkRef[]) result.toArray(new JavadocLinkRef[result.size()]); 293 } 294 295 private void collectReferencedElements(IJavaProject project, HashSet result) throws CoreException { 296 IRuntimeClasspathEntry[] unresolved = JavaRuntime.computeUnresolvedRuntimeClasspath(project); 297 for (int i= 0; i < unresolved.length; i++) { 298 IRuntimeClasspathEntry curr= unresolved[i]; 299 if (curr.getType() == IRuntimeClasspathEntry.PROJECT) { 300 result.add(new JavadocLinkRef(JavaCore.create((IProject) curr.getResource()))); 301 } else { 302 IRuntimeClasspathEntry[] entries= JavaRuntime.resolveRuntimeClasspathEntry(curr, project); 303 for (int k = 0; k < entries.length; k++) { 304 IRuntimeClasspathEntry entry= entries[k]; 305 if (entry.getType() == IRuntimeClasspathEntry.PROJECT) { 306 result.add(new JavadocLinkRef(JavaCore.create((IProject) entry.getResource()))); 307 } else if (entry.getType() == IRuntimeClasspathEntry.ARCHIVE) { 308 IClasspathEntry classpathEntry= entry.getClasspathEntry(); 309 if (classpathEntry != null) { 310 IPath containerPath= null; 311 if (curr.getType() == IRuntimeClasspathEntry.CONTAINER) { 312 containerPath= curr.getPath(); 313 } 314 result.add(new JavadocLinkRef(containerPath, classpathEntry, project)); 315 } 316 } 317 } 318 } 319 } 320 } 321 322 final void doValidation(int VALIDATE) { 323 switch (VALIDATE) { 324 case STYLESHEETSTATUS : 325 fStyleSheetStatus= new StatusInfo(); 326 if (fStyleSheetButton.getSelection()) { 327 String filename= fStyleSheetText.getText(); 328 if (filename.length() == 0) { 329 fStyleSheetStatus.setError(JavadocExportMessages.JavadocSpecificsWizardPage_overviewnotfound_error); 330 } else { 331 File file= new File (filename); 332 String ext= filename.substring(filename.lastIndexOf('.') + 1); 333 if (!file.isFile()) { 334 fStyleSheetStatus.setError(JavadocExportMessages.JavadocStandardWizardPage_stylesheetnopath_error); 335 } else if (!ext.equalsIgnoreCase("css")) { fStyleSheetStatus.setError(JavadocExportMessages.JavadocStandardWizardPage_stylesheetnotcss_error); 337 } 338 } 339 } 340 break; 341 case LINK_REFERENCES: 342 fLinkRefStatus= new StatusInfo(); 343 List list= fListDialogField.getCheckedElements(); 344 for (int i= 0; i < list.size(); i++) { 345 JavadocLinkRef curr= (JavadocLinkRef) list.get(i); 346 URL url= curr.getURL(); 347 if (url == null) { 348 fLinkRefStatus.setWarning(JavadocExportMessages.JavadocStandardWizardPage_nolinkref_error); 349 break; 350 } else if ("jar".equals(url.getProtocol())) { fLinkRefStatus.setWarning(JavadocExportMessages.JavadocStandardWizardPage_nojarlinkref_error); 352 break; 353 } 354 } 355 break; 356 } 357 358 updateStatus(findMostSevereStatus()); 359 360 } 361 362 private IStatus findMostSevereStatus() { 363 return StatusUtil.getMostSevere(new IStatus[] { fStyleSheetStatus, fLinkRefStatus }); 364 } 365 366 public void updateStore() { 367 368 if (fTitleButton.getSelection()) 369 fStore.setTitle(fTitleText.getText()); 370 else 371 fStore.setTitle(""); 373 if (true) { 376 Object [] buttons= fButtonsList.toArray(); 377 for (int i= 0; i < buttons.length; i++) { 378 FlaggedButton button= (FlaggedButton) buttons[i]; 379 if (button.getButton().getEnabled()) 380 fStore.setBoolean(button.getFlag(), !(button.getButton().getSelection() ^ button.show())); 381 else 382 fStore.setBoolean(button.getFlag(), false == button.show()); 383 } 384 } 385 386 if (fStyleSheetText.getEnabled()) 387 fStore.setStyleSheet(fStyleSheetText.getText()); 388 else 389 fStore.setStyleSheet(""); 391 fStore.setHRefs(getHRefs()); 392 } 393 394 private String [] getHRefs() { 395 HashSet res= new HashSet (); 396 List checked= fListDialogField.getCheckedElements(); 397 for (Iterator iterator= checked.iterator(); iterator.hasNext();) { 398 JavadocLinkRef element= (JavadocLinkRef) iterator.next(); 399 URL url= element.getURL(); 400 if (url != null) { 401 res.add(url.toExternalForm()); 402 } 403 } 404 return (String []) res.toArray(new String [res.size()]); 405 } 406 407 409 public void setVisible(boolean visible) { 410 super.setVisible(visible); 411 if (visible) { 412 doValidation(STYLESHEETSTATUS); 413 updateHRefList(fFirstPage.getCheckedProjects()); 414 } else { 415 fStore.setHRefs(getHRefs()); 416 } 417 } 418 419 424 private void updateHRefList(IJavaProject[] checkedProjects) { 425 JavadocLinkRef[] res= getReferencedElements(checkedProjects); 426 fListDialogField.setElements(Arrays.asList(res)); 427 428 List checked= getCheckedReferences(res); 429 fListDialogField.setCheckedElements(checked); 430 } 431 432 public void init() { 433 updateStatus(new StatusInfo()); 434 } 435 436 protected class FlaggedButton { 437 438 private Button fButton; 439 private String fFlag; 440 private boolean fShowFlag; 441 442 public FlaggedButton(Composite composite, String message, GridData gridData, String flag, boolean show) { 443 fFlag= flag; 444 fShowFlag= show; 445 fButton= createButton(composite, SWT.CHECK, message, gridData); 446 fButtonsList.add(this); 447 setButtonSettings(); 448 } 449 450 public Button getButton() { 451 return fButton; 452 } 453 454 public String getFlag() { 455 return fFlag; 456 } 457 public boolean show() { 458 return fShowFlag; 459 } 460 461 private void setButtonSettings() { 462 463 fButton.setSelection(!(fStore.getBoolean(fFlag) ^ fShowFlag)); 464 } 465 466 } 468 private class ListAdapter implements IListAdapter, IDialogFieldListener { 469 470 473 public void customButtonPressed(ListDialogField field, int index) { 474 if (index == 2) 475 doEditButtonPressed(); 476 } 477 478 481 public void selectionChanged(ListDialogField field) { 482 List selection= fListDialogField.getSelectedElements(); 483 if (selection.size() != 1) { 484 fListDialogField.enableButton(2, false); 485 } else { 486 fListDialogField.enableButton(2, true); 487 } 488 } 489 490 public void doubleClicked(ListDialogField field) { 491 doEditButtonPressed(); 492 } 493 494 public void dialogFieldChanged(DialogField field) { 495 doValidation(LINK_REFERENCES); 496 } 497 498 } 499 500 503 private void doEditButtonPressed() { 504 505 List selected= fListDialogField.getSelectedElements(); 506 if (selected.isEmpty()) { 507 return; 508 } 509 JavadocLinkRef obj= (JavadocLinkRef) selected.get(0); 510 if (obj != null) { 511 JavadocPropertyDialog jdialog= new JavadocPropertyDialog(getShell(), obj); 512 if (jdialog.open() == Window.OK) { 513 fListDialogField.refresh(); 514 } 515 } 516 517 } 518 519 private class JavadocPropertyDialog extends StatusDialog implements IStatusChangeListener { 520 521 private JavadocConfigurationBlock fJavadocConfigurationBlock; 522 private JavadocLinkRef fElement; 523 524 public JavadocPropertyDialog(Shell parent, JavadocLinkRef selection) { 525 super(parent); 526 setTitle(JavadocExportMessages.JavadocStandardWizardPage_javadocpropertydialog_title); 527 528 fElement= selection; 529 URL initialLocation= selection.getURL(); 530 fJavadocConfigurationBlock= new JavadocConfigurationBlock(parent, this, initialLocation, selection.isProjectRef()); 531 } 532 533 protected Control createDialogArea(Composite parent) { 534 Composite composite= (Composite) super.createDialogArea(parent); 535 Control inner= fJavadocConfigurationBlock.createContents(composite); 536 inner.setLayoutData(new GridData(GridData.FILL_BOTH)); 537 applyDialogFont(composite); 538 return composite; 539 } 540 541 public void statusChanged(IStatus status) { 542 updateStatus(status); 543 544 } 545 546 549 protected void okPressed() { 550 try { 551 IWorkspaceRunnable runnable= new IWorkspaceRunnable() { 552 public void run(IProgressMonitor monitor) throws CoreException { 553 URL javadocLocation= fJavadocConfigurationBlock.getJavadocLocation(); 554 fElement.setURL(javadocLocation, monitor); 555 } 556 }; 557 PlatformUI.getWorkbench().getProgressService().run(true, true, new WorkbenchRunnableAdapter(runnable)); 558 559 } catch (InvocationTargetException e) { 560 String title= JavadocExportMessages.JavadocStandardWizardPage_configurecontainer_error_title; 561 String message= JavadocExportMessages.JavadocStandardWizardPage_configurecontainer_error_message; 562 ExceptionHandler.handle(e, getShell(), title, message); 563 } catch (InterruptedException e) { 564 } 566 567 fListDialogField.refresh(); 568 doValidation(LINK_REFERENCES); 569 super.okPressed(); 570 } 571 572 575 protected void configureShell(Shell newShell) { 576 super.configureShell(newShell); 577 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.JAVADOC_PROPERTY_DIALOG); 578 } 579 } 580 } 581 | Popular Tags |