1 11 package org.eclipse.pde.internal.ui.view; 12 13 import java.io.File ; 14 import java.io.FileInputStream ; 15 import java.io.FileOutputStream ; 16 import java.io.IOException ; 17 import java.lang.reflect.InvocationTargetException ; 18 import java.util.ArrayList ; 19 import java.util.HashSet ; 20 import java.util.Iterator ; 21 import java.util.Locale ; 22 import java.util.Set ; 23 24 import org.eclipse.core.resources.IStorage; 25 import org.eclipse.core.runtime.CoreException; 26 import org.eclipse.core.runtime.IConfigurationElement; 27 import org.eclipse.core.runtime.IProgressMonitor; 28 import org.eclipse.jdt.core.IClassFile; 29 import org.eclipse.jdt.core.IPackageFragment; 30 import org.eclipse.jdt.core.JavaModelException; 31 import org.eclipse.jdt.ui.JavaUI; 32 import org.eclipse.jdt.ui.actions.OpenAction; 33 import org.eclipse.jface.action.Action; 34 import org.eclipse.jface.action.IMenuListener; 35 import org.eclipse.jface.action.IMenuManager; 36 import org.eclipse.jface.action.IToolBarManager; 37 import org.eclipse.jface.action.MenuManager; 38 import org.eclipse.jface.action.Separator; 39 import org.eclipse.jface.dialogs.IDialogSettings; 40 import org.eclipse.jface.operation.IRunnableWithProgress; 41 import org.eclipse.jface.resource.ImageDescriptor; 42 import org.eclipse.jface.util.IPropertyChangeListener; 43 import org.eclipse.jface.util.PropertyChangeEvent; 44 import org.eclipse.jface.viewers.DoubleClickEvent; 45 import org.eclipse.jface.viewers.IDoubleClickListener; 46 import org.eclipse.jface.viewers.ISelection; 47 import org.eclipse.jface.viewers.ISelectionChangedListener; 48 import org.eclipse.jface.viewers.IStructuredSelection; 49 import org.eclipse.jface.viewers.LabelProvider; 50 import org.eclipse.jface.viewers.SelectionChangedEvent; 51 import org.eclipse.jface.viewers.StructuredSelection; 52 import org.eclipse.jface.viewers.TreeViewer; 53 import org.eclipse.jface.viewers.Viewer; 54 import org.eclipse.jface.viewers.ViewerFilter; 55 import org.eclipse.osgi.util.NLS; 56 import org.eclipse.pde.core.plugin.IPluginBase; 57 import org.eclipse.pde.core.plugin.IPluginImport; 58 import org.eclipse.pde.core.plugin.IPluginModelBase; 59 import org.eclipse.pde.internal.core.EntryFileAdapter; 60 import org.eclipse.pde.internal.core.FileAdapter; 61 import org.eclipse.pde.internal.core.ModelEntry; 62 import org.eclipse.pde.internal.core.PDECore; 63 import org.eclipse.pde.internal.core.PluginModelManager; 64 import org.eclipse.pde.internal.core.plugin.WorkspacePluginModelBase; 65 import org.eclipse.pde.internal.ui.IHelpContextIds; 66 import org.eclipse.pde.internal.ui.IPDEUIConstants; 67 import org.eclipse.pde.internal.ui.IPreferenceConstants; 68 import org.eclipse.pde.internal.ui.PDEPlugin; 69 import org.eclipse.pde.internal.ui.PDEPluginImages; 70 import org.eclipse.pde.internal.ui.PDEUIMessages; 71 import org.eclipse.pde.internal.ui.editor.JarEntryEditorInput; 72 import org.eclipse.pde.internal.ui.editor.SystemFileEditorInput; 73 import org.eclipse.pde.internal.ui.editor.plugin.ManifestEditor; 74 import org.eclipse.pde.internal.ui.search.PluginSearchActionGroup; 75 import org.eclipse.pde.internal.ui.wizards.ListUtil; 76 import org.eclipse.swt.SWT; 77 import org.eclipse.swt.custom.BusyIndicator; 78 import org.eclipse.swt.dnd.Clipboard; 79 import org.eclipse.swt.dnd.DND; 80 import org.eclipse.swt.dnd.FileTransfer; 81 import org.eclipse.swt.dnd.Transfer; 82 import org.eclipse.swt.program.Program; 83 import org.eclipse.swt.widgets.Composite; 84 import org.eclipse.swt.widgets.Menu; 85 import org.eclipse.ui.IActionBars; 86 import org.eclipse.ui.IEditorInput; 87 import org.eclipse.ui.IPageLayout; 88 import org.eclipse.ui.ISharedImages; 89 import org.eclipse.ui.IWorkbenchActionConstants; 90 import org.eclipse.ui.IWorkbenchPage; 91 import org.eclipse.ui.PartInitException; 92 import org.eclipse.ui.PlatformUI; 93 import org.eclipse.ui.actions.ActionContext; 94 import org.eclipse.ui.actions.ActionFactory; 95 import org.eclipse.ui.part.DrillDownAdapter; 96 import org.eclipse.ui.part.ViewPart; 97 98 public class PluginsView extends ViewPart { 99 private static final String DEFAULT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor"; private static final String HIDE_WRKSPC = "hideWorkspace"; private static final String HIDE_EXENABLED = "hideEnabledExternal"; private static final String SHOW_EXDISABLED = "showDisabledExternal"; private TreeViewer treeViewer; 104 private DrillDownAdapter drillDownAdapter; 105 private IPropertyChangeListener propertyListener; 106 private Action openAction; 107 private Action hideExtDisabledFilterAction; 108 private Action hideExtEnabledFilterAction; 109 private Action hideWorkspaceFilterAction; 110 private Action openManifestAction; 111 private Action openSchemaAction; 112 private Action openSystemEditorAction; 113 private Action openClassFileAction; 114 private Action openDependenciesAdapter; 115 private OpenDependenciesAction openDependenciesAction; 116 private Action openTextEditorAction; 117 private Action selectDependentAction; 118 private Action selectInJavaSearchAction; 119 private Action addToJavaSearchAction; 120 private Action removeFromJavaSearchAction; 121 private Action selectAllAction; 122 private CollapseAllAction collapseAllAction; 123 private ShowInWorkspaceAction showInNavigatorAction; 124 private ShowInWorkspaceAction showInPackagesAction; 125 private DisabledFilter hideExtEnabledFilter = new DisabledFilter(true); 126 private DisabledFilter hideExtDisabledFilter = new DisabledFilter(false); 127 private WorkspaceFilter hideWorkspaceFilter = new WorkspaceFilter(); 128 private JavaFilter javaFilter = new JavaFilter(); 129 private CopyToClipboardAction copyAction; 130 private Clipboard clipboard; 131 132 class DisabledFilter extends ViewerFilter { 133 134 boolean fEnabled; 135 DisabledFilter(boolean enabled) { 136 fEnabled = enabled; 137 } 138 public boolean select(Viewer v, Object parent, Object element) { 139 if (element instanceof ModelEntry) { 140 ModelEntry entry = (ModelEntry) element; 141 if (entry.getWorkspaceModel() == null) { 142 IPluginModelBase externalModel = entry.getExternalModel(); 143 if (externalModel != null) 144 return externalModel.isEnabled() != fEnabled; 145 } 146 } 147 return true; 148 } 149 } 150 151 class WorkspaceFilter extends ViewerFilter { 152 public boolean select(Viewer v, Object parent, Object element) { 153 if (element instanceof ModelEntry) { 154 ModelEntry entry = (ModelEntry) element; 155 return entry.getWorkspaceModel() == null; 156 } 157 return true; 158 } 159 } 160 161 class JavaFilter extends ViewerFilter { 162 public boolean select(Viewer v, Object parent, Object element) { 163 if (element instanceof IPackageFragment) { 164 IPackageFragment packageFragment = (IPackageFragment) element; 165 try { 166 return packageFragment.hasChildren(); 167 } catch (JavaModelException e) { 168 return false; 169 } 170 } 171 return true; 172 } 173 } 174 175 class CollapseAllAction extends Action { 176 public CollapseAllAction() { 177 super(); 178 setText(PDEUIMessages.PluginsView_CollapseAllAction_label); 179 setDescription(PDEUIMessages.PluginsView_CollapseAllAction_description); 180 setToolTipText(PDEUIMessages.PluginsView_CollapseAllAction_tooltip); 181 setImageDescriptor(PDEPluginImages.DESC_COLLAPSE_ALL); 182 } 183 184 189 public void run() { 190 super.run(); 191 treeViewer.collapseAll(); 192 } 193 } 194 195 198 public PluginsView() { 199 propertyListener = new IPropertyChangeListener() { 200 public void propertyChange(PropertyChangeEvent event) { 201 String property = event.getProperty(); 202 if (property.equals(IPreferenceConstants.PROP_SHOW_OBJECTS)) { 203 treeViewer.refresh(); 204 } 205 } 206 }; 207 } 208 209 public void dispose() { 210 PDEPlugin.getDefault().getPreferenceStore().removePropertyChangeListener( 211 propertyListener); 212 openDependenciesAction.dispose(); 213 if (clipboard != null) { 214 clipboard.dispose(); 215 clipboard = null; 216 } 217 super.dispose(); 218 } 219 220 223 public void createPartControl(Composite parent) { 224 treeViewer = new TreeViewer(parent, SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL); 225 drillDownAdapter = new DrillDownAdapter(treeViewer); 226 PluginModelManager manager = PDECore.getDefault().getModelManager(); 227 treeViewer.setContentProvider(new PluginsContentProvider(this, manager)); 228 treeViewer.setLabelProvider(new PluginsLabelProvider()); 229 treeViewer.setSorter(ListUtil.PLUGIN_SORTER); 230 initDragAndDrop(); 231 makeActions(); 232 initFilters(); 233 IActionBars actionBars = getViewSite().getActionBars(); 234 contributeToActionBars(actionBars); 235 registerGlobalActions(actionBars); 236 hookContextMenu(); 237 hookDoubleClickAction(); 238 treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { 239 public void selectionChanged(SelectionChangedEvent e) { 240 handleSelectionChanged(e.getSelection()); 241 } 242 }); 243 treeViewer.setInput(manager); 244 updateContentDescription(); 245 PDEPlugin.getDefault().getPreferenceStore().addPropertyChangeListener( 246 propertyListener); 247 getViewSite().setSelectionProvider(treeViewer); 248 249 PlatformUI.getWorkbench().getHelpSystem().setHelp( 250 treeViewer.getControl(), 251 IHelpContextIds.PLUGINS_VIEW); 252 } 253 254 private void contributeToActionBars(IActionBars actionBars) { 255 contributeToLocalToolBar(actionBars.getToolBarManager()); 256 contributeToDropDownMenu(actionBars.getMenuManager()); 257 } 258 259 private void contributeToDropDownMenu(IMenuManager manager) { 260 manager.add(hideWorkspaceFilterAction); 261 manager.add(hideExtEnabledFilterAction); 262 manager.add(hideExtDisabledFilterAction); 263 } 264 265 private void contributeToLocalToolBar(IToolBarManager manager) { 266 drillDownAdapter.addNavigationActions(manager); 267 manager.add(new Separator()); 268 manager.add(collapseAllAction); 269 } 270 271 private void registerGlobalActions(IActionBars actionBars) { 272 actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(), 273 selectAllAction); 274 } 275 private void makeActions() { 276 clipboard = new Clipboard(treeViewer.getTree().getDisplay()); 277 openAction = new Action() { 278 public void run() { 279 handleDoubleClick(); 280 } 281 }; 282 openAction.setText(PDEUIMessages.PluginsView_open); 283 284 openDependenciesAction = new OpenDependenciesAction(); 285 openDependenciesAction.init(PDEPlugin.getActiveWorkbenchWindow()); 286 openDependenciesAdapter = new Action() { 287 public void run() { 288 ModelEntry entry = getEnclosingEntry(); 289 IPluginModelBase model = entry.getActiveModel(); 290 openDependenciesAction.selectionChanged( 291 this, new StructuredSelection(model)); 292 openDependenciesAction.run(this); 293 } 294 }; 295 openDependenciesAdapter.setText(PDEUIMessages.PluginsView_openDependencies); 296 hideExtDisabledFilterAction = new Action() { 297 public void run() { 298 boolean checked = hideExtDisabledFilterAction.isChecked(); 299 if (checked) 300 treeViewer.removeFilter(hideExtDisabledFilter); 301 else 302 treeViewer.addFilter(hideExtDisabledFilter); 303 getSettings().put(SHOW_EXDISABLED, checked); 304 updateContentDescription(); 305 } 306 }; 307 hideExtDisabledFilterAction.setText(PDEUIMessages.PluginsView_showDisabled); 308 hideExtEnabledFilterAction = new Action() { 309 public void run() { 310 boolean checked = hideExtEnabledFilterAction.isChecked(); 311 if (checked) 312 treeViewer.removeFilter(hideExtEnabledFilter); 313 else 314 treeViewer.addFilter(hideExtEnabledFilter); 315 getSettings().put(HIDE_EXENABLED, !checked); 316 updateContentDescription(); 317 } 318 }; 319 hideExtEnabledFilterAction.setText(PDEUIMessages.PluginsView_showEnabled); 320 hideWorkspaceFilterAction = new Action() { 321 public void run() { 322 boolean checked = hideWorkspaceFilterAction.isChecked(); 323 if (checked) 324 treeViewer.removeFilter(hideWorkspaceFilter); 325 else 326 treeViewer.addFilter(hideWorkspaceFilter); 327 getSettings().put(HIDE_WRKSPC, !checked); 328 updateContentDescription(); 329 } 330 }; 331 hideWorkspaceFilterAction.setText(PDEUIMessages.PluginsView_showWorkspace); 332 333 openTextEditorAction = new Action() { 334 public void run() { 335 handleOpenTextEditor(getSelectedFile(), null); 336 } 337 }; 338 openTextEditorAction.setText(PDEUIMessages.PluginsView_textEditor); 339 openTextEditorAction.setImageDescriptor( 340 PlatformUI.getWorkbench().getSharedImages().getImageDescriptor( 341 ISharedImages.IMG_OBJ_FILE)); 342 343 openSystemEditorAction = new Action() { 344 public void run() { 345 handleOpenSystemEditor(getSelectedFile()); 346 } 347 }; 348 openSystemEditorAction.setText(PDEUIMessages.PluginsView_systemEditor); 349 openManifestAction = new Action() { 350 public void run() { 351 handleOpenManifestEditor(getSelectedFile()); 352 } 353 }; 354 openManifestAction.setText(PDEUIMessages.PluginsView_manifestEditor); 355 356 openSchemaAction = new Action() { 357 public void run() { 358 handleOpenSchemaEditor(getSelectedFile()); 359 } 360 }; 361 openSchemaAction.setText(PDEUIMessages.PluginsView_schemaEditor); 362 363 copyAction = new CopyToClipboardAction(clipboard); 364 copyAction.setText(PDEUIMessages.PluginsView_copy); 365 366 selectDependentAction = new Action() { 367 public void run() { 368 handleSelectDependent(); 369 } 370 }; 371 selectDependentAction.setText(PDEUIMessages.PluginsView_dependentPlugins); 372 373 selectInJavaSearchAction = new Action() { 374 public void run() { 375 handleSelectInJavaSearch(); 376 } 377 }; 378 selectInJavaSearchAction.setText(PDEUIMessages.PluginsView_pluginsInJavaSearch); 379 380 selectAllAction = new Action() { 381 public void run() { 382 super.run(); 383 treeViewer.getTree().selectAll(); 384 } 385 }; 386 selectAllAction.setText(PDEUIMessages.PluginsView_SelectAllAction_label); 387 388 addToJavaSearchAction = new Action() { 389 public void run() { 390 handleJavaSearch(true); 391 } 392 }; 393 addToJavaSearchAction.setText(PDEUIMessages.PluginsView_addToJavaSearch); 394 395 removeFromJavaSearchAction = new Action() { 396 public void run() { 397 handleJavaSearch(false); 398 } 399 }; 400 removeFromJavaSearchAction.setText(PDEUIMessages.PluginsView_removeFromJavaSearch); 401 402 showInNavigatorAction = 403 new ShowInWorkspaceAction(IPageLayout.ID_RES_NAV, treeViewer); 404 showInNavigatorAction.setText(PDEUIMessages.PluginsView_showInNavigator); 405 showInPackagesAction = 406 new ShowInWorkspaceAction(JavaUI.ID_PACKAGES, treeViewer); 407 showInPackagesAction.setText(PDEUIMessages.PluginsView_showInPackageExplorer); 408 409 collapseAllAction = new CollapseAllAction(); 410 411 openClassFileAction = new OpenAction(getViewSite()); 412 } 413 414 private FileAdapter getSelectedFile() { 415 Object obj = getSelectedObject(); 416 if (obj instanceof FileAdapter) 417 return (FileAdapter) obj; 418 return null; 419 } 420 421 private ModelEntry getEnclosingEntry() { 422 Object obj = getSelectedObject(); 423 if (obj == null) 424 return null; 425 if (obj instanceof ModelEntry) 426 return (ModelEntry) obj; 427 if (obj instanceof FileAdapter) { 428 FileAdapter file = (FileAdapter) obj; 429 if (file.isManifest()) { 430 FileAdapter parent = file.getParent(); 431 if (parent instanceof EntryFileAdapter) 432 return ((EntryFileAdapter) parent).getEntry(); 433 } 434 } 435 return null; 436 } 437 438 private Object getSelectedObject() { 439 IStructuredSelection selection = 440 (IStructuredSelection) treeViewer.getSelection(); 441 if (selection.isEmpty() || selection.size() != 1) 442 return null; 443 return selection.getFirstElement(); 444 } 445 private void fillContextMenu(IMenuManager manager) { 446 IStructuredSelection selection = 447 (IStructuredSelection) treeViewer.getSelection(); 448 449 if (selection.size() == 1) { 450 Object sobj = selection.getFirstElement(); 451 boolean addSeparator = false; 452 if (sobj instanceof ModelEntry) { 453 ModelEntry entry = (ModelEntry) sobj; 454 IPluginModelBase model = entry.getActiveModel(); 455 File file = new File (model.getInstallLocation()); 456 if (file.isFile() || model.getUnderlyingResource() != null) { 457 manager.add(openAction); 458 } 459 } 460 if (sobj instanceof FileAdapter 461 && ((FileAdapter) sobj).isDirectory() == false) { 462 manager.add(openAction); 463 MenuManager openWithMenu = new MenuManager(PDEUIMessages.PluginsView_openWith); 464 fillOpenWithMenu(openWithMenu, sobj); 465 manager.add(openWithMenu); 466 addSeparator = true; 467 } 468 if (sobj instanceof IStorage) { 469 manager.add(openAction); 470 addSeparator = true; 471 } 472 if (sobj instanceof IClassFile) { 473 manager.add(openClassFileAction); 474 addSeparator = true; 475 } 476 ModelEntry entry = getEnclosingEntry(); 477 if (entry != null) { 478 manager.add(openDependenciesAdapter); 479 manager.add(new Separator()); 480 PluginSearchActionGroup actionGroup = 481 new PluginSearchActionGroup(); 482 actionGroup.setContext(new ActionContext(selection)); 483 actionGroup.fillContextMenu(manager); 484 addSeparator = true; 485 } 486 if (addSeparator) 487 manager.add(new Separator()); 488 } 489 if (selection.size() > 0) { 490 boolean addSeparator = false; 491 if (showInNavigatorAction.isApplicable()) { 492 manager.add(showInNavigatorAction); 493 addSeparator = true; 494 } 495 if (showInPackagesAction.isApplicable()) { 496 manager.add(showInPackagesAction); 497 addSeparator = true; 498 } 499 if (addSeparator) { 500 manager.add(new Separator()); 501 } 502 if (ImportActionGroup.canImport(selection)) { 503 ImportActionGroup actionGroup = new ImportActionGroup(); 504 actionGroup.setContext(new ActionContext(selection)); 505 actionGroup.fillContextMenu(manager); 506 manager.add(new Separator()); 507 } 508 addSeparator = false; 509 if (canDoJavaSearchOperation(selection, true)) { 510 manager.add(addToJavaSearchAction); 511 addSeparator = true; 512 } 513 if (canDoJavaSearchOperation(selection, false)) { 514 manager.add(removeFromJavaSearchAction); 515 addSeparator = true; 516 } 517 if (addSeparator) { 518 manager.add(new Separator()); 519 } 520 } 521 copyAction.setSelection(selection); 522 manager.add(copyAction); 523 IMenuManager selectionMenu = new MenuManager(PDEUIMessages.PluginsView_select); 524 manager.add(selectionMenu); 525 if (selection.size() > 0) 526 selectionMenu.add(selectDependentAction); 527 selectionMenu.add(selectInJavaSearchAction); 528 selectionMenu.add(selectAllAction); 529 manager.add(new Separator()); 530 drillDownAdapter.addNavigationActions(manager); 531 manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 532 } 533 private void fillOpenWithMenu(IMenuManager manager, Object obj) { 534 FileAdapter adapter = (FileAdapter) obj; 535 String editorId = adapter.getEditorId(); 536 537 String fileName = adapter.getFile().getName(); 538 String lcFileName = fileName.toLowerCase(Locale.ENGLISH); 539 ImageDescriptor desc = 540 PlatformUI.getWorkbench().getEditorRegistry().getImageDescriptor( 541 fileName); 542 if (lcFileName.equals("plugin.xml") || lcFileName.equals("fragment.xml") || lcFileName.equals("manifest.mf")) { openManifestAction.setImageDescriptor(desc); 546 manager.add(openManifestAction); 547 manager.add(new Separator()); 548 openManifestAction.setChecked( 549 editorId != null 550 && editorId.equals(IPDEUIConstants.MANIFEST_EDITOR_ID)); 551 } 552 if (lcFileName.endsWith(".mxsd") || lcFileName.endsWith(".exsd")) { openSchemaAction.setImageDescriptor(desc); 554 manager.add(openSchemaAction); 555 manager.add(new Separator()); 556 openSchemaAction.setChecked( 557 editorId != null 558 && editorId.equals(IPDEUIConstants.SCHEMA_EDITOR_ID)); 559 } 560 manager.add(openTextEditorAction); 561 openTextEditorAction.setChecked( 562 editorId == null || editorId.equals(DEFAULT_EDITOR_ID)); 563 openSystemEditorAction.setImageDescriptor(desc); 564 openSystemEditorAction.setChecked(editorId != null && editorId.equals("@system")); manager.add(openSystemEditorAction); 566 } 567 568 private boolean canDoJavaSearchOperation( 569 IStructuredSelection selection, 570 boolean add) { 571 int nhits = 0; 572 for (Iterator iter = selection.iterator(); iter.hasNext();) { 573 Object obj = iter.next(); 574 if (obj instanceof ModelEntry) { 575 ModelEntry entry = (ModelEntry) obj; 576 if (entry.getWorkspaceModel() == null) { 577 if (add && entry.isInJavaSearch() == false) 578 nhits++; 579 if (!add && entry.isInJavaSearch()) 580 nhits++; 581 } 582 } 583 } 584 return nhits > 0; 585 } 586 587 protected void initDragAndDrop() { 588 int ops = DND.DROP_COPY | DND.DROP_MOVE; 589 Transfer[] transfers = new Transfer[] { FileTransfer.getInstance()}; 590 treeViewer.addDragSupport( 591 ops, 592 transfers, 593 new PluginsDragAdapter(treeViewer)); 594 } 595 596 private IDialogSettings getSettings() { 597 IDialogSettings master = PDEPlugin.getDefault().getDialogSettings(); 598 IDialogSettings section = master.getSection("pluginsView"); if (section == null) { 600 section = master.addNewSection("pluginsView"); } 602 return section; 603 } 604 605 private void initFilters() { 606 IDialogSettings settings = getSettings(); 607 treeViewer.addFilter(javaFilter); 608 boolean hideWorkspace = settings.getBoolean(HIDE_WRKSPC); 609 boolean hideEnabledExternal = settings.getBoolean(HIDE_EXENABLED); 610 boolean hideDisabledExternal = !settings.getBoolean(SHOW_EXDISABLED); 611 if (hideWorkspace) 612 treeViewer.addFilter(hideWorkspaceFilter); 613 if (hideEnabledExternal) 614 treeViewer.addFilter(hideExtEnabledFilter); 615 if (hideDisabledExternal) 616 treeViewer.addFilter(hideExtDisabledFilter); 617 hideWorkspaceFilterAction.setChecked(!hideWorkspace); 618 hideExtEnabledFilterAction.setChecked(!hideEnabledExternal); 619 hideExtDisabledFilterAction.setChecked(!hideDisabledExternal); 620 } 621 622 private void hookContextMenu() { 623 MenuManager menuMgr = new MenuManager("#PopupMenu"); menuMgr.setRemoveAllWhenShown(true); 625 menuMgr.addMenuListener(new IMenuListener() { 626 public void menuAboutToShow(IMenuManager manager) { 627 PluginsView.this.fillContextMenu(manager); 628 } 629 }); 630 Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); 631 treeViewer.getControl().setMenu(menu); 632 getSite().registerContextMenu(menuMgr, treeViewer); 633 } 634 635 private void handleDoubleClick() { 636 Object obj = getSelectedObject(); 637 if (obj instanceof ModelEntry) { 638 boolean expanded = treeViewer.getExpandedState(obj); 639 treeViewer.setExpandedState(obj, !expanded); 640 if (treeViewer.getExpandedState(obj) == expanded) { 641 ModelEntry modelEntry = (ModelEntry) obj; 643 ManifestEditor.openPluginEditor(modelEntry.getId()); 644 } 645 } 646 if (obj instanceof FileAdapter) { 647 FileAdapter adapter = (FileAdapter) obj; 648 if (adapter.isDirectory()) { 649 treeViewer.setExpandedState( 650 adapter, 651 !treeViewer.getExpandedState(adapter)); 652 return; 653 } 654 String editorId = adapter.getEditorId(); 655 if (editorId != null && editorId.equals("@system")) handleOpenSystemEditor(adapter); 657 else 658 handleOpenTextEditor(adapter, editorId); 659 } 660 if (obj instanceof IClassFile) { 661 openClassFileAction.run(); 662 } 663 if (obj instanceof IStorage) { 664 handleOpenStorage((IStorage) obj); 665 } 666 } 667 668 private void handleOpenStorage(IStorage obj) { 669 IWorkbenchPage page = PDEPlugin.getActivePage(); 670 IEditorInput input = new JarEntryEditorInput(obj); 671 try { 672 page.openEditor(input, DEFAULT_EDITOR_ID); 673 } catch (PartInitException e) { 674 PDEPlugin.logException(e); 675 } 676 } 677 678 private void handleJavaSearch(final boolean add) { 679 IStructuredSelection selection = 680 (IStructuredSelection) treeViewer.getSelection(); 681 if (selection.size() == 0) 682 return; 683 684 ArrayList result = new ArrayList (); 685 686 for (Iterator iter = selection.iterator(); iter.hasNext();) { 687 ModelEntry entry = (ModelEntry) iter.next(); 688 if (entry.getWorkspaceModel() != null) 689 continue; 690 if (entry.isInJavaSearch() == !add) 691 result.add(entry); 692 } 693 if (result.size() == 0) 694 return; 695 final ModelEntry[] array = 696 (ModelEntry[]) result.toArray(new ModelEntry[result.size()]); 697 698 IRunnableWithProgress op = new IRunnableWithProgress() { 699 public void run(IProgressMonitor monitor) 700 throws InvocationTargetException { 701 PluginModelManager manager = 702 PDECore.getDefault().getModelManager(); 703 try { 704 manager.setInJavaSearch(array, add, monitor); 705 } catch (CoreException e) { 706 throw new InvocationTargetException (e); 707 } finally { 708 monitor.done(); 709 } 710 } 711 }; 712 713 try { 714 PlatformUI.getWorkbench().getProgressService().busyCursorWhile(op); 715 } catch (InterruptedException e) { 716 } catch (InvocationTargetException e) { 717 PDEPlugin.logException(e); 718 } 719 } 720 721 private void handleSelectDependent() { 722 IStructuredSelection selection = 723 (IStructuredSelection) treeViewer.getSelection(); 724 if (selection.size() == 0) 725 return; 726 HashSet set = new HashSet (); 727 for (Iterator iter = selection.iterator(); iter.hasNext();) { 728 ModelEntry entry = (ModelEntry) iter.next(); 729 set.add(entry); 730 addDependentEntries(entry, set); 731 } 732 treeViewer.setSelection(new StructuredSelection(set.toArray())); 733 } 734 private void handleSelectInJavaSearch() { 735 PluginsContentProvider provider = 736 (PluginsContentProvider) treeViewer.getContentProvider(); 737 Object [] elements = provider.getElements(treeViewer.getInput()); 738 ArrayList result = new ArrayList (); 739 for (int i = 0; i < elements.length; i++) { 740 Object element = elements[i]; 741 if (element instanceof ModelEntry) { 742 ModelEntry entry = (ModelEntry) element; 743 if (entry.isInJavaSearch()) 744 result.add(entry); 745 } 746 } 747 treeViewer.setSelection(new StructuredSelection(result.toArray())); 748 } 749 750 private void addDependentEntries(ModelEntry entry, Set set) { 751 if (entry.isEmpty() 752 || entry.getActiveModel() instanceof WorkspacePluginModelBase) 753 return; 754 IPluginModelBase model = entry.getExternalModel(); 755 if (model == null) 756 return; 757 IPluginBase plugin = model.getPluginBase(); 758 if (plugin == null) 759 return; 760 IPluginImport[] iimports = plugin.getImports(); 761 PluginModelManager manager = PDECore.getDefault().getModelManager(); 762 for (int i = 0; i < iimports.length; i++) { 763 IPluginImport iimport = iimports[i]; 764 ModelEntry ientry = 765 manager.findEntry(iimport.getId()); 766 if (ientry != null) { 767 set.add(ientry); 768 addDependentEntries(ientry, set); 769 } 770 } 771 } 772 773 private void handleOpenTextEditor(FileAdapter adapter, String editorId) { 774 if (adapter == null) 775 return; 776 IWorkbenchPage page = PDEPlugin.getActivePage(); 777 if (editorId == null) { 778 if (adapter.isManifest()) 779 editorId = IPDEUIConstants.MANIFEST_EDITOR_ID; 780 else if (adapter.isSchema()) 781 editorId = IPDEUIConstants.SCHEMA_EDITOR_ID; 782 } 783 try { 784 if (editorId == null || editorId.equals("@system")) editorId = DEFAULT_EDITOR_ID; 786 page.openEditor( 787 new SystemFileEditorInput(adapter.getFile()), 788 editorId); 789 adapter.setEditorId(editorId); 790 } catch (PartInitException e) { 791 PDEPlugin.logException(e); 792 } 793 } 794 795 private void handleOpenManifestEditor(FileAdapter adapter) { 796 handleOpenTextEditor(adapter, IPDEUIConstants.MANIFEST_EDITOR_ID); 797 } 798 799 private void handleOpenSchemaEditor(FileAdapter adapter) { 800 handleOpenTextEditor(adapter, IPDEUIConstants.SCHEMA_EDITOR_ID); 801 } 802 803 private void handleOpenSystemEditor(FileAdapter adapter) { 804 if (adapter == null) 805 return; 806 File localFile = null; 807 808 try { 809 localFile = getLocalCopy(adapter.getFile()); 810 } catch (IOException e) { 811 PDEPlugin.logException(e); 812 return; 813 } catch (CoreException e) { 814 PDEPlugin.logException(e); 815 } 816 final File file = localFile; 818 final boolean result[] = new boolean[1]; 819 BusyIndicator 820 .showWhile(treeViewer.getTree().getDisplay(), new Runnable () { 821 public void run() { 822 String path = file.getAbsolutePath(); 824 result[0] = Program.launch(path); 825 } 826 }); 827 828 if (!result[0]) { 830 PDEPlugin.logException( 831 new PartInitException( 832 NLS.bind(PDEUIMessages.PluginsView_unableToOpen, file.getName()))); 833 } else { 834 adapter.setEditorId("@system"); } 836 } 837 838 private File getLocalCopy(File file) throws IOException , CoreException { 839 String fileName = file.getName(); 844 String prefix; 845 String suffix = null; 846 int dotLoc = fileName.indexOf('.'); 847 if (dotLoc != -1) { 848 prefix = fileName.substring(0, dotLoc); 849 suffix = fileName.substring(dotLoc); 850 } else { 851 prefix = fileName; 852 } 853 854 File tmpFile = File.createTempFile(prefix, suffix); 855 tmpFile.deleteOnExit(); 856 FileOutputStream fos = new FileOutputStream (tmpFile); 857 FileInputStream fis = new FileInputStream (file); 858 byte[] cbuffer = new byte[1024]; 859 int read = 0; 860 861 while (read != -1) { 862 read = fis.read(cbuffer); 863 if (read != -1) 864 fos.write(cbuffer, 0, read); 865 } 866 fos.flush(); 867 fos.close(); 868 fis.close(); 869 tmpFile.setReadOnly(); 870 return tmpFile; 871 } 872 873 private void handleSelectionChanged(ISelection selection) { 874 String text = ""; Object obj = getSelectedObject(); 876 if (obj instanceof ModelEntry) { 877 IPluginModelBase model = ((ModelEntry) obj).getActiveModel(); 878 text = model.getInstallLocation(); 879 } 880 if (obj instanceof FileAdapter) { 881 text = ((FileAdapter) obj).getFile().getAbsolutePath(); 882 } 883 getViewSite().getActionBars().getStatusLineManager().setMessage(text); 884 } 885 886 private void hookDoubleClickAction() { 887 treeViewer.addDoubleClickListener(new IDoubleClickListener() { 888 public void doubleClick(DoubleClickEvent event) { 889 handleDoubleClick(); 890 } 891 }); 892 } 893 894 897 public void setFocus() { 898 treeViewer.getTree().setFocus(); 899 } 900 void updateTitle(Object newInput) { 901 IConfigurationElement config = getConfigurationElement(); 902 if (config == null) 903 return; 904 905 if (newInput == null 906 || newInput.equals(PDECore.getDefault().getModelManager())) { 907 setContentDescription(""); setTitleToolTip(getTitle()); 909 } else { 910 String viewName = config.getAttribute("name"); String name = ((LabelProvider) treeViewer.getLabelProvider()).getText(newInput); 912 setContentDescription(viewName + ": " + name); setTitleToolTip(getInputPath(newInput)); 914 } 915 } 916 private String getInputPath(Object input) { 917 if (input instanceof FileAdapter) { 918 return "file: " + ((FileAdapter) input).getFile().getAbsolutePath(); } 920 if (input instanceof ModelEntry) { 921 IPluginModelBase model = ((ModelEntry) input).getActiveModel(); 922 return "plugin: " + model.getInstallLocation(); } 924 return ""; } 926 927 private void updateContentDescription() { 928 String total = Integer.toString(((PluginModelManager)treeViewer.getInput()).getEntries().length); 929 String visible = Integer.toString(treeViewer.getTree().getItemCount()); 930 setContentDescription(NLS.bind(PDEUIMessages.PluginsView_description, visible, total)); 931 } 932 933 } 934 | Popular Tags |