1 11 package org.eclipse.pde.internal.ui.views.dependencies; 12 13 import java.util.ArrayList ; 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.runtime.Preferences; 18 import org.eclipse.jface.action.Action; 19 import org.eclipse.jface.action.IAction; 20 import org.eclipse.jface.action.IContributionItem; 21 import org.eclipse.jface.action.IToolBarManager; 22 import org.eclipse.jface.action.Separator; 23 import org.eclipse.jface.action.SubContributionItem; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 import org.eclipse.osgi.util.NLS; 26 import org.eclipse.pde.core.plugin.IPlugin; 27 import org.eclipse.pde.core.plugin.IPluginModel; 28 import org.eclipse.pde.core.plugin.IPluginModelBase; 29 import org.eclipse.pde.core.plugin.PluginRegistry; 30 import org.eclipse.pde.internal.core.PDECore; 31 import org.eclipse.pde.internal.core.builders.DependencyLoop; 32 import org.eclipse.pde.internal.core.builders.DependencyLoopFinder; 33 import org.eclipse.pde.internal.ui.IHelpContextIds; 34 import org.eclipse.pde.internal.ui.IPreferenceConstants; 35 import org.eclipse.pde.internal.ui.PDEPlugin; 36 import org.eclipse.pde.internal.ui.PDEPluginImages; 37 import org.eclipse.pde.internal.ui.PDEUIMessages; 38 import org.eclipse.pde.internal.ui.editor.plugin.LoopDialog; 39 import org.eclipse.swt.custom.BusyIndicator; 40 import org.eclipse.swt.graphics.Image; 41 import org.eclipse.swt.widgets.Composite; 42 import org.eclipse.ui.IActionBars; 43 import org.eclipse.ui.IMemento; 44 import org.eclipse.ui.IPropertyListener; 45 import org.eclipse.ui.IViewSite; 46 import org.eclipse.ui.IWorkbenchPart; 47 import org.eclipse.ui.IWorkbenchPartSite; 48 import org.eclipse.ui.PartInitException; 49 import org.eclipse.ui.PlatformUI; 50 import org.eclipse.ui.part.IPage; 51 import org.eclipse.ui.part.IPageBookViewPage; 52 import org.eclipse.ui.part.PageBook; 53 import org.eclipse.ui.part.PageBookView; 54 55 public class DependenciesView extends PageBookView implements 56 IPreferenceConstants, IHelpContextIds { 57 58 static class DummyPart implements IWorkbenchPart { 59 public void addPropertyListener(IPropertyListener listener) { 60 } 61 62 public void createPartControl(Composite parent) { 63 } 64 65 public void dispose() { 66 } 67 68 public Object getAdapter(Class adapter) { 69 return null; 70 } 71 72 public IWorkbenchPartSite getSite() { 73 return null; 74 } 75 76 public String getTitle() { 77 return null; 78 } 79 80 public Image getTitleImage() { 81 return null; 82 } 83 84 public String getTitleToolTip() { 85 return null; 86 } 87 88 public void removePropertyListener(IPropertyListener listener) { 89 } 90 91 public void setFocus() { 92 } 93 } 94 95 class ShowLoopsAction extends Action { 96 97 public ShowLoopsAction() { 98 super("", AS_PUSH_BUTTON); setText(PDEUIMessages.DependenciesView_ShowLoopsAction_label); 100 setDescription(PDEUIMessages.DependenciesView_ShowLoopsAction_description); 101 setToolTipText(PDEUIMessages.DependenciesView_ShowLoopsAction_tooltip); 102 setImageDescriptor(PDEPluginImages.DESC_DEP_LOOP); 103 setDisabledImageDescriptor(PDEPluginImages.DESC_DEP_LOOP_DISABLED); 104 setEnabled(false); 105 } 106 107 110 public void run() { 111 LoopDialog dialog = new LoopDialog(PDEPlugin 112 .getActiveWorkbenchShell(), fLoops); 113 dialog.open(); 114 } 115 } 116 117 class ShowCalleesAction extends Action { 118 119 public ShowCalleesAction() { 120 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowCalleesAction_label); 122 setDescription(PDEUIMessages.DependenciesView_ShowCalleesAction_description); 123 setToolTipText(PDEUIMessages.DependenciesView_ShowCalleesAction_tooltip); 124 setImageDescriptor(PDEPluginImages.DESC_CALLEES); 125 setDisabledImageDescriptor(PDEPluginImages.DESC_CALLEES_DISABLED); 126 } 127 128 131 public void run() { 132 if (isChecked()) { 133 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, false); 134 setViewType(false); 135 } 136 } 137 } 138 139 class ShowCallersAction extends Action { 140 public ShowCallersAction() { 141 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowCallersAction_label); 143 setDescription(PDEUIMessages.DependenciesView_ShowCallersAction_description); 144 setToolTipText(PDEUIMessages.DependenciesView_ShowCallersAction_tooltip); 145 setImageDescriptor(PDEPluginImages.DESC_CALLERS); 146 setDisabledImageDescriptor(PDEPluginImages.DESC_CALLERS_DISABLED); 147 } 148 149 152 public void run() { 153 if (isChecked()) { 154 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, true); 155 setViewType(true); 156 } 157 } 158 } 159 160 class ShowListAction extends Action { 161 public ShowListAction() { 162 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowListAction_label); 164 setDescription(PDEUIMessages.DependenciesView_ShowListAction_description); 165 setToolTipText(PDEUIMessages.DependenciesView_ShowListAction_tooltip); 166 setImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT); 167 setDisabledImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT_DISABLED); 168 } 169 170 173 public void run() { 174 if (isChecked()) { 175 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, true); 176 setPresentation(true); 177 } 178 } 179 } 180 181 class ShowTreeAction extends Action { 182 183 public ShowTreeAction() { 184 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowTreeAction_label); 186 setDescription(PDEUIMessages.DependenciesView_ShowTreeAction_description); 187 setToolTipText(PDEUIMessages.DependenciesView_ShowTreeAction_tooltip); 188 setImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT); 189 setDisabledImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT_DISABLED); 190 } 191 192 195 public void run() { 196 if (isChecked()) { 197 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, false); 198 setPresentation(false); 199 } 200 } 201 } 202 203 class ShowStateAction extends Action { 204 205 public ShowStateAction() { 206 super(PDEUIMessages.DependenciesView_showStateAction_label, IAction.AS_CHECK_BOX); 207 setDescription(PDEUIMessages.DependenciesView_showStateAction_description); 208 setToolTipText(PDEUIMessages.DependenciesView_showStateAction_toolTip); 209 setImageDescriptor(PDEPluginImages.DESC_REQ_PLUGINS_OBJ); 210 setId(SHOW_STATE_ACTION_ID); 211 } 212 213 216 public void run() { 217 fPreferences.setValue(DEPS_VIEW_SHOW_STATE, isChecked()); 218 enableStateView(isChecked()); 219 } 220 } 221 222 protected static final IWorkbenchPart PART_CALLEES_LIST = new DummyPart(); 223 224 protected static final IWorkbenchPart PART_CALLEES_TREE = new DummyPart(); 225 226 protected static final IWorkbenchPart PART_CALLERS_LIST = new DummyPart(); 227 228 protected static final IWorkbenchPart PART_CALLERS_TREE = new DummyPart(); 229 230 protected static final IWorkbenchPart PART_STATE_TREE = new DummyPart(); 231 232 public static final String TREE_ACTION_GROUP = "tree"; 234 protected static final String MEMENTO_KEY_INPUT = "inputPluginId"; 236 protected static final String SHOW_STATE_ACTION_ID = "show.state.action"; 238 private static final DependencyLoop[] NO_LOOPS = new DependencyLoop[0]; 239 240 private Map fPagesToParts; 241 242 private Map fPartsToPages; 243 244 private Object fInput; 245 246 private Preferences fPreferences = PDEPlugin.getDefault() 247 .getPluginPreferences(); 248 249 private ShowCalleesAction fShowCallees; 250 251 private ShowCallersAction fShowCallers; 252 253 private ShowListAction fShowList; 254 255 private ShowTreeAction fShowTree; 256 257 private ShowLoopsAction fShowLoops; 258 259 private ArrayList fInputHistory; 261 262 private DependencyLoop[] fLoops; 263 264 private HistoryDropDownAction fHistoryDropDownAction; 265 266 private Action fShowState; 267 268 private IWorkbenchPart fLastDependenciesPart = null; 269 272 public DependenciesView() { 273 super(); 274 fPartsToPages = new HashMap (4); 275 fPagesToParts = new HashMap (4); 276 fInputHistory= new ArrayList (); 277 fLoops = NO_LOOPS; 278 } 279 280 private void contributeToActionBars(IActionBars actionBars) { 281 contributeToLocalToolBar(actionBars.getToolBarManager()); 282 actionBars.updateActionBars(); 283 } 284 285 private void contributeToLocalToolBar(IToolBarManager manager) { 286 manager.add(new Separator(TREE_ACTION_GROUP)); 287 manager.add(new Separator("type")); manager.appendToGroup("type", fShowCallees); manager.appendToGroup("type", fShowCallers); manager.add(new Separator("presentation")); manager.appendToGroup("presentation", fShowTree); manager.appendToGroup("presentation", fShowList); manager.add(new Separator("history")); manager.add(fShowLoops); 295 manager.add(fHistoryDropDownAction); 296 manager.add(new Separator("state")); manager.add(fShowState); 298 if (PART_STATE_TREE.equals(getCurrentContributingPart())) 299 enableDependenciesActions(false); 300 } 301 302 307 protected IPage createDefaultPage(PageBook book) { 308 if (fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE)) 309 return createPage(PART_STATE_TREE); 310 return createPage(getDefaultPart()); 311 } 312 313 private IWorkbenchPart getDefaultPart() { 314 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)) { 315 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 316 return PART_CALLERS_LIST; 317 } 318 return PART_CALLERS_TREE; 319 } 320 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 321 return PART_CALLEES_LIST; 322 } 323 return PART_CALLEES_TREE; 324 } 325 326 329 private IPageBookViewPage createPage(IWorkbenchPart part) { 330 IPageBookViewPage page; 331 if (part == PART_CALLEES_TREE) { 332 page = new DependenciesViewTreePage(this, 333 new CalleesTreeContentProvider(this)); 334 } else if (part == PART_CALLEES_LIST) { 335 page = new DependenciesViewListPage(this, 336 new CalleesListContentProvider(this)); 337 } else if (part == PART_CALLERS_TREE) { 338 page = new DependenciesViewTreePage(this, 339 new CallersTreeContentProvider(this)); 340 } else if (part == PART_CALLERS_LIST){ 341 page = new DependenciesViewListPage(this, 342 new CallersListContentProvider(this)); 343 } else { 344 page = new StateViewPage(this); 345 } 346 347 initPage(page); 348 page.createControl(getPageBook()); 349 fPartsToPages.put(part, page); 350 fPagesToParts.put(page, part); 351 return page; 352 } 353 354 359 public void createPartControl(Composite parent) { 360 super.createPartControl(parent); 361 fShowCallees = new ShowCalleesAction(); 362 fShowCallees.setChecked(!fPreferences 363 .getBoolean(DEPS_VIEW_SHOW_CALLERS)); 364 fShowCallers = new ShowCallersAction(); 365 fShowCallers 366 .setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)); 367 368 fShowTree = new ShowTreeAction(); 369 fShowTree.setChecked(!fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)); 370 fShowList = new ShowListAction(); 371 fShowList.setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)); 372 373 fShowLoops = new ShowLoopsAction(); 374 fShowLoops.setEnabled(fLoops != NO_LOOPS); 375 376 fHistoryDropDownAction= new HistoryDropDownAction(this); 377 fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty()); 378 379 fShowState = new ShowStateAction(); 380 fShowState.setChecked(fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE)); 381 382 IActionBars actionBars = getViewSite().getActionBars(); 383 contributeToActionBars(actionBars); 384 385 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.DEPENDENCIES_VIEW); 386 } 387 388 393 protected PageRec doCreatePage(IWorkbenchPart part) { 394 IPageBookViewPage page = (IPageBookViewPage) fPartsToPages.get(part); 395 if (page == null && !fPartsToPages.containsKey(part)) { 396 page = createPage(part); 397 } 398 if (page != null) { 399 return new PageRec(part, page); 400 } 401 return null; 402 } 403 404 410 protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { 411 IPage page = pageRecord.page; 412 page.dispose(); 413 pageRecord.dispose(); 414 415 fPartsToPages.remove(part); 417 } 418 419 424 protected IWorkbenchPart getBootstrapPart() { 425 if (fInput == null || fPreferences.getBoolean(DEPS_VIEW_SHOW_STATE)) 426 return PART_STATE_TREE; 427 return getDefaultPart(); 428 } 429 430 436 public void init(IViewSite site, IMemento memento) throws PartInitException { 437 super.init(site, memento); 438 if(memento == null) 439 return; 440 String id = memento.getString(MEMENTO_KEY_INPUT); 441 if (id != null) { 442 IPluginModelBase plugin = PluginRegistry.findModel(id); 443 if (plugin != null) { 444 fInput = plugin; 445 addHistoryEntry(id); 446 findLoops(); 447 } 448 } 449 } 450 451 456 protected boolean isImportant(IWorkbenchPart part) { 457 return part instanceof DummyPart; 458 } 459 460 public void openTo(Object object) { 461 if (getCurrentContributingPart() == PART_STATE_TREE) { 463 fShowState.setChecked(false); 464 fShowState.run(); 465 } 466 if (object != null && !object.equals(fInput)) { 467 if(object instanceof IPluginModelBase){ 468 String id =((IPluginModelBase)object).getPluginBase().getId(); 469 addHistoryEntry(id); 470 } 471 } 472 updateInput(object); 473 } 474 475 public void openCallersFor(Object object) { 476 if (getCurrentContributingPart() == PART_STATE_TREE) 477 fLastDependenciesPart = (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) ? PART_CALLERS_LIST : 478 PART_CALLERS_TREE; 479 else if (!fShowCallers.isChecked() && fShowCallees.isChecked()) { 480 fShowCallers.setChecked(true); 481 fShowCallees.setChecked(false); 482 fShowCallers.run(); 483 } 484 openTo(object); 485 } 486 487 public void openCalleesFor(Object object) { 488 if (getCurrentContributingPart() == PART_STATE_TREE) 489 fLastDependenciesPart = (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) ? PART_CALLEES_LIST : 490 PART_CALLEES_TREE; 491 else if (!fShowCallees.isChecked() && fShowCallers.isChecked()) { 492 fShowCallees.setChecked(true); 493 fShowCallers.setChecked(false); 494 fShowCallees.run(); 495 } 496 openTo(object); 497 } 498 499 private void updateInput(Object object) { 500 fInput = object; 501 findLoops(); 502 ((DependenciesViewPage) getCurrentPage()).setInput(object); 503 } 504 505 508 private void findLoops() { 509 fLoops = NO_LOOPS; 510 if (fInput != null && fInput instanceof IPluginModel) { 511 BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell() 512 .getDisplay(), new Runnable () { 513 518 public void run() { 519 IPlugin plugin = ((IPluginModel) fInput).getPlugin(); 520 DependencyLoop[] loops = DependencyLoopFinder 521 .findLoops(plugin); 522 if (loops.length > 0) { 523 fLoops = loops; 524 } 525 } 526 }); 527 } 528 if(fShowLoops != null) 529 fShowLoops.setEnabled(fLoops != NO_LOOPS); 530 } 531 532 537 public void saveState(IMemento memento) { 538 super.saveState(memento); 539 if (fInput != null && fInput instanceof IPluginModelBase) { 540 String inputPluginId = ((IPluginModelBase) fInput).getPluginBase() 541 .getId(); 542 memento.putString(MEMENTO_KEY_INPUT, inputPluginId); 543 } 544 } 545 546 void setPresentation(boolean listNotTree) { 547 IWorkbenchPart currentPart = getCurrentContributingPart(); 548 if (listNotTree) { 549 if (currentPart == PART_CALLEES_TREE) { 550 partActivated(PART_CALLEES_LIST); 551 } else if (currentPart == PART_CALLERS_TREE) { 552 partActivated(PART_CALLERS_LIST); 553 } 554 555 } else { 556 if (currentPart == PART_CALLEES_LIST) { 557 partActivated(PART_CALLEES_TREE); 558 } else if (currentPart == PART_CALLERS_LIST) { 559 partActivated(PART_CALLERS_TREE); 560 } 561 562 } 563 } 564 565 void setViewType(boolean callers) { 566 IWorkbenchPart currentPart = getCurrentContributingPart(); 567 if (callers) { 568 if (currentPart == PART_CALLEES_TREE) { 569 partActivated(PART_CALLERS_TREE); 570 } else if (currentPart == PART_CALLEES_LIST) { 571 partActivated(PART_CALLERS_LIST); 572 } 573 574 } else { 575 if (currentPart == PART_CALLERS_TREE) { 576 partActivated(PART_CALLEES_TREE); 577 } else if (currentPart == PART_CALLERS_LIST) { 578 partActivated(PART_CALLEES_LIST); 579 } 580 581 } 582 } 583 584 589 protected void showPageRec(PageRec pageRec) { 590 IPage currPage = getCurrentPage(); 591 if (pageRec.page.equals(currPage)) { 593 super.showPageRec(pageRec); 594 return; 595 } 596 IStructuredSelection selection = null; 597 if (currPage instanceof DependenciesViewPage) { 598 selection = ((DependenciesViewPage)currPage).getSelection(); 599 ((DependenciesViewPage)currPage).setActive(false); 600 } else if (currPage instanceof StateViewPage) { 601 ((StateViewPage)currPage).setActive(false); 602 } 603 IPage p = pageRec.page; 604 if (p instanceof DependenciesViewPage) { 605 ((DependenciesViewPage) p).setInput(fInput); 606 ((DependenciesViewPage) p).setActive(true); 608 } 609 super.showPageRec(pageRec); 610 if (p instanceof DependenciesViewPage) { 611 updateTitle(fInput); 612 ((DependenciesViewPage) p).setSelection(selection); 613 } else if (p instanceof StateViewPage){ 614 ((StateViewPage)p).setActive(true); 615 } 616 } 617 618 void updateTitle(Object newInput) { 619 if (newInput == null) { 620 updateTitle(""); } else if (!newInput.equals(PDECore.getDefault().getModelManager())) { 622 String name = PDEPlugin.getDefault().getLabelProvider().getText( 623 newInput); 624 String title; 625 if (getCurrentContributingPart() == PART_CALLEES_TREE) { 626 title = NLS.bind(PDEUIMessages.DependenciesView_callees_tree_title, name); 627 } else if (getCurrentContributingPart() == PART_CALLEES_LIST) { 628 title = NLS.bind(PDEUIMessages.DependenciesView_callees_list_title, name); 629 } else if (getCurrentContributingPart() == PART_CALLERS_TREE) { 630 title = NLS.bind(PDEUIMessages.DependenciesView_callers_tree_title, name); 631 } else { 632 title = NLS.bind(PDEUIMessages.DependenciesView_callers_list_title, name); 633 } 634 if(fLoops != NO_LOOPS){ 635 title = title + " " + PDEUIMessages.DependenciesView_cycles_title; } 637 updateTitle(title); 638 } 639 } 640 641 void updateTitle(String description) { 642 setContentDescription(description); 643 setTitleToolTip(getTitle()); 644 } 645 646 650 private void addHistoryEntry(String entry) { 651 if (fInputHistory.contains(entry)) { 652 fInputHistory.remove(entry); 653 } 654 fInputHistory.add(0, entry); 655 if (fHistoryDropDownAction != null) 656 fHistoryDropDownAction.setEnabled(true); 657 } 658 659 private void updateHistoryEntries() { 660 for (int i= fInputHistory.size() - 1; i >= 0; i--) { 661 String type= (String ) fInputHistory.get(i); 662 if (PluginRegistry.findModel(type)==null) { 663 fInputHistory.remove(i); 664 } 665 } 666 if (fHistoryDropDownAction != null) 667 fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty()); 668 } 669 670 674 public void gotoHistoryEntry(String entry) { 675 if (fInputHistory.contains(entry)) { 676 updateInput(PluginRegistry.findModel(entry)); 677 } 678 } 679 680 684 public String [] getHistoryEntries() { 685 if (fInputHistory.size() > 0) { 686 updateHistoryEntries(); 687 } 688 return (String []) fInputHistory.toArray(new String [fInputHistory.size()]); 689 } 690 691 695 public void setHistoryEntries(String [] elems) { 696 fInputHistory.clear(); 697 for (int i= 0; i < elems.length; i++) { 698 fInputHistory.add(elems[i]); 699 } 700 updateHistoryEntries(); 701 } 702 705 public String getInput() { 706 if(fInput!=null){ 707 return ((IPluginModelBase)fInput).getPluginBase().getId(); 708 } 709 return null; 710 } 711 712 public boolean isShowingCallers() { 713 return fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS); 714 } 715 716 protected void enableStateView(boolean enabled) { 717 if (enabled) { 718 fLastDependenciesPart = getCurrentContributingPart(); 719 partActivated(DependenciesView.PART_STATE_TREE); 720 } else { 721 if (fLastDependenciesPart != null) 722 partActivated(fLastDependenciesPart); 723 else 724 partActivated(getDefaultPart()); 725 fLastDependenciesPart = null; 726 } 727 enableDependenciesActions(!enabled); 728 getViewSite().getActionBars().getToolBarManager().update(true); 729 } 730 731 private void enableDependenciesActions(boolean enabled) { 733 IContributionItem[] items = getViewSite().getActionBars().getToolBarManager().getItems(); 734 for (int i = 0; i < items.length; i++) { 735 if (!(SHOW_STATE_ACTION_ID.equals(items[i].getId()) || "state".equals(items[i].getId())) && !(items[i] instanceof SubContributionItem)) items[i].setVisible(enabled); 738 } 739 } 740 } 741 | Popular Tags |