1 11 package org.eclipse.pde.internal.ui.view; 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.IToolBarManager; 20 import org.eclipse.jface.action.Separator; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.pde.core.plugin.IPlugin; 24 import org.eclipse.pde.core.plugin.IPluginModel; 25 import org.eclipse.pde.core.plugin.IPluginModelBase; 26 import org.eclipse.pde.internal.core.PDECore; 27 import org.eclipse.pde.internal.core.builders.DependencyLoop; 28 import org.eclipse.pde.internal.core.builders.DependencyLoopFinder; 29 import org.eclipse.pde.internal.ui.IHelpContextIds; 30 import org.eclipse.pde.internal.ui.IPreferenceConstants; 31 import org.eclipse.pde.internal.ui.PDEPlugin; 32 import org.eclipse.pde.internal.ui.PDEPluginImages; 33 import org.eclipse.pde.internal.ui.PDEUIMessages; 34 import org.eclipse.pde.internal.ui.editor.plugin.LoopDialog; 35 import org.eclipse.swt.custom.BusyIndicator; 36 import org.eclipse.swt.graphics.Image; 37 import org.eclipse.swt.widgets.Composite; 38 import org.eclipse.ui.IActionBars; 39 import org.eclipse.ui.IMemento; 40 import org.eclipse.ui.IPropertyListener; 41 import org.eclipse.ui.IViewSite; 42 import org.eclipse.ui.IWorkbenchPart; 43 import org.eclipse.ui.IWorkbenchPartSite; 44 import org.eclipse.ui.PartInitException; 45 import org.eclipse.ui.PlatformUI; 46 import org.eclipse.ui.part.IPage; 47 import org.eclipse.ui.part.IPageBookViewPage; 48 import org.eclipse.ui.part.PageBook; 49 import org.eclipse.ui.part.PageBookView; 50 51 public class DependenciesView extends PageBookView implements 52 IPreferenceConstants, IHelpContextIds { 53 54 static class DummyPart implements IWorkbenchPart { 55 public void addPropertyListener(IPropertyListener listener) { 56 } 57 58 public void createPartControl(Composite parent) { 59 } 60 61 public void dispose() { 62 } 63 64 public Object getAdapter(Class adapter) { 65 return null; 66 } 67 68 public IWorkbenchPartSite getSite() { 69 return null; 70 } 71 72 public String getTitle() { 73 return null; 74 } 75 76 public Image getTitleImage() { 77 return null; 78 } 79 80 public String getTitleToolTip() { 81 return null; 82 } 83 84 public void removePropertyListener(IPropertyListener listener) { 85 } 86 87 public void setFocus() { 88 } 89 } 90 91 class ShowLoopsAction extends Action { 92 93 public ShowLoopsAction() { 94 super("", AS_PUSH_BUTTON); setText(PDEUIMessages.DependenciesView_ShowLoopsAction_label); 96 setDescription(PDEUIMessages.DependenciesView_ShowLoopsAction_description); 97 setToolTipText(PDEUIMessages.DependenciesView_ShowLoopsAction_tooltip); 98 setImageDescriptor(PDEPluginImages.DESC_DEP_LOOP); 99 setDisabledImageDescriptor(PDEPluginImages.DESC_DEP_LOOP_DISABLED); 100 setEnabled(false); 101 } 102 103 106 public void run() { 107 LoopDialog dialog = new LoopDialog(PDEPlugin 108 .getActiveWorkbenchShell(), fLoops); 109 dialog.open(); 110 } 111 } 112 113 class ShowCalleesAction extends Action { 114 115 public ShowCalleesAction() { 116 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowCalleesAction_label); 118 setDescription(PDEUIMessages.DependenciesView_ShowCalleesAction_description); 119 setToolTipText(PDEUIMessages.DependenciesView_ShowCalleesAction_tooltip); 120 setImageDescriptor(PDEPluginImages.DESC_CALLEES); 121 setDisabledImageDescriptor(PDEPluginImages.DESC_CALLEES_DISABLED); 122 } 123 124 127 public void run() { 128 if (isChecked()) { 129 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, false); 130 setViewType(false); 131 } 132 } 133 } 134 135 class ShowCallersAction extends Action { 136 public ShowCallersAction() { 137 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowCallersAction_label); 139 setDescription(PDEUIMessages.DependenciesView_ShowCallersAction_description); 140 setToolTipText(PDEUIMessages.DependenciesView_ShowCallersAction_tooltip); 141 setImageDescriptor(PDEPluginImages.DESC_CALLERS); 142 setDisabledImageDescriptor(PDEPluginImages.DESC_CALLERS_DISABLED); 143 } 144 145 148 public void run() { 149 if (isChecked()) { 150 fPreferences.setValue(DEPS_VIEW_SHOW_CALLERS, true); 151 setViewType(true); 152 } 153 } 154 } 155 156 class ShowListAction extends Action { 157 public ShowListAction() { 158 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowListAction_label); 160 setDescription(PDEUIMessages.DependenciesView_ShowListAction_description); 161 setToolTipText(PDEUIMessages.DependenciesView_ShowListAction_tooltip); 162 setImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT); 163 setDisabledImageDescriptor(PDEPluginImages.DESC_FLAT_LAYOUT_DISABLED); 164 } 165 166 169 public void run() { 170 if (isChecked()) { 171 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, true); 172 setPresentation(true); 173 } 174 } 175 } 176 177 class ShowTreeAction extends Action { 178 179 public ShowTreeAction() { 180 super("", AS_RADIO_BUTTON); setText(PDEUIMessages.DependenciesView_ShowTreeAction_label); 182 setDescription(PDEUIMessages.DependenciesView_ShowTreeAction_description); 183 setToolTipText(PDEUIMessages.DependenciesView_ShowTreeAction_tooltip); 184 setImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT); 185 setDisabledImageDescriptor(PDEPluginImages.DESC_HIERARCHICAL_LAYOUT_DISABLED); 186 } 187 188 191 public void run() { 192 if (isChecked()) { 193 fPreferences.setValue(DEPS_VIEW_SHOW_LIST, false); 194 setPresentation(false); 195 } 196 } 197 } 198 199 protected static final IWorkbenchPart PART_CALLEES_LIST = new DummyPart(); 200 201 protected static final IWorkbenchPart PART_CALLEES_TREE = new DummyPart(); 202 203 protected static final IWorkbenchPart PART_CALLERS_LIST = new DummyPart(); 204 205 protected static final IWorkbenchPart PART_CALLERS_TREE = new DummyPart(); 206 207 public static final String TREE_ACTION_GROUP = "tree"; 209 protected static final String MEMENTO_KEY_INPUT = "inputPluginId"; 211 private static final DependencyLoop[] NO_LOOPS = new DependencyLoop[0]; 212 213 private Map fPagesToParts; 214 215 private Map fPartsToPages; 216 217 private Object fInput; 218 219 private Preferences fPreferences = PDEPlugin.getDefault() 220 .getPluginPreferences(); 221 222 private ShowCalleesAction fShowCallees; 223 224 private ShowCallersAction fShowCallers; 225 226 private ShowListAction fShowList; 227 228 private ShowTreeAction fShowTree; 229 230 private ShowLoopsAction fShowLoops; 231 232 private ArrayList fInputHistory; 234 235 private DependencyLoop[] fLoops; 236 237 private HistoryDropDownAction fHistoryDropDownAction; 238 241 public DependenciesView() { 242 super(); 243 fPartsToPages = new HashMap (4); 244 fPagesToParts = new HashMap (4); 245 fInputHistory= new ArrayList (); 246 fLoops = NO_LOOPS; 247 } 248 249 private void contributeToActionBars(IActionBars actionBars) { 250 contributeToLocalToolBar(actionBars.getToolBarManager()); 251 actionBars.updateActionBars(); 252 } 253 254 private void contributeToLocalToolBar(IToolBarManager manager) { 255 manager.add(new Separator(TREE_ACTION_GROUP)); 256 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); 264 manager.add(fHistoryDropDownAction); 265 } 266 267 272 protected IPage createDefaultPage(PageBook book) { 273 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)) { 274 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 275 return createPage(PART_CALLERS_LIST); 276 277 } 278 return createPage(PART_CALLERS_TREE); 279 } 280 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 281 return createPage(PART_CALLEES_LIST); 282 283 } 284 return createPage(PART_CALLEES_TREE); 285 } 286 287 290 private DependenciesViewPage createPage(IWorkbenchPart part) { 291 DependenciesViewPage page; 292 if (part == PART_CALLEES_TREE) { 293 page = new DependenciesViewTreePage(this, 294 new CalleesTreeContentProvider(this)); 295 } else if (part == PART_CALLEES_LIST) { 296 page = new DependenciesViewListPage(this, 297 new CalleesListContentProvider(this)); 298 } else if (part == PART_CALLERS_TREE) { 299 page = new DependenciesViewTreePage(this, 300 new CallersTreeContentProvider(this)); 301 } else { 302 page = new DependenciesViewListPage(this, 303 new CallersListContentProvider(this)); 304 } 305 306 initPage(page); 307 page.createControl(getPageBook()); 308 fPartsToPages.put(part, page); 309 fPagesToParts.put(page, part); 310 return page; 311 } 312 313 318 public void createPartControl(Composite parent) { 319 super.createPartControl(parent); 320 fShowCallees = new ShowCalleesAction(); 321 fShowCallees.setChecked(!fPreferences 322 .getBoolean(DEPS_VIEW_SHOW_CALLERS)); 323 fShowCallers = new ShowCallersAction(); 324 fShowCallers 325 .setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)); 326 327 fShowTree = new ShowTreeAction(); 328 fShowTree.setChecked(!fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)); 329 fShowList = new ShowListAction(); 330 fShowList.setChecked(fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)); 331 332 fShowLoops = new ShowLoopsAction(); 333 fShowLoops.setEnabled(fLoops != NO_LOOPS); 334 335 fHistoryDropDownAction= new HistoryDropDownAction(this); 336 fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty()); 337 338 IActionBars actionBars = getViewSite().getActionBars(); 339 contributeToActionBars(actionBars); 340 341 PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IHelpContextIds.DEPENDENCIES_VIEW); 342 } 343 344 349 protected PageRec doCreatePage(IWorkbenchPart part) { 350 IPageBookViewPage page = (IPageBookViewPage) fPartsToPages.get(part); 351 if (page == null && !fPartsToPages.containsKey(part)) { 352 page = createPage(part); 353 } 354 if (page != null) { 355 return new PageRec(part, page); 356 } 357 return null; 358 } 359 360 366 protected void doDestroyPage(IWorkbenchPart part, PageRec pageRecord) { 367 IPage page = pageRecord.page; 368 page.dispose(); 369 pageRecord.dispose(); 370 371 fPartsToPages.remove(part); 373 } 374 375 380 protected IWorkbenchPart getBootstrapPart() { 381 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_CALLERS)) { 382 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 383 return PART_CALLERS_LIST; 384 385 } 386 return PART_CALLERS_TREE; 387 } 388 if (fPreferences.getBoolean(DEPS_VIEW_SHOW_LIST)) { 389 return PART_CALLEES_LIST; 390 391 } 392 return PART_CALLEES_TREE; 393 } 394 395 401 public void init(IViewSite site, IMemento memento) throws PartInitException { 402 super.init(site, memento); 403 if(memento == null) 404 return; 405 String id = memento.getString(MEMENTO_KEY_INPUT); 406 if (id != null) { 407 IPluginModelBase plugin = PDECore.getDefault().getModelManager().findModel(id); 408 if (plugin != null) { 409 fInput = plugin; 410 addHistoryEntry(id); 411 findLoops(); 412 } 413 } 414 } 415 416 421 protected boolean isImportant(IWorkbenchPart part) { 422 return part instanceof DummyPart; 423 } 424 425 public void openTo(Object object) { 426 if (object != null && !object.equals(fInput)) { 427 if(object instanceof IPluginModelBase){ 428 String id =((IPluginModelBase)object).getPluginBase().getId(); 429 addHistoryEntry(id); 430 } 431 } 432 updateInput(object); 433 } 434 435 private void updateInput(Object object) { 436 fInput = object; 437 findLoops(); 438 ((DependenciesViewPage) getCurrentPage()).setInput(object); 439 } 440 441 444 private void findLoops() { 445 fLoops = NO_LOOPS; 446 if (fInput != null && fInput instanceof IPluginModel) { 447 BusyIndicator.showWhile(PDEPlugin.getActiveWorkbenchShell() 448 .getDisplay(), new Runnable () { 449 454 public void run() { 455 IPlugin plugin = ((IPluginModel) fInput).getPlugin(); 456 DependencyLoop[] loops = DependencyLoopFinder 457 .findLoops(plugin); 458 if (loops.length > 0) { 459 fLoops = loops; 460 } 461 } 462 }); 463 } 464 if(fShowLoops != null) 465 fShowLoops.setEnabled(fLoops != NO_LOOPS); 466 } 467 468 473 public void saveState(IMemento memento) { 474 super.saveState(memento); 475 if (fInput != null && fInput instanceof IPluginModelBase) { 476 String inputPluginId = ((IPluginModelBase) fInput).getPluginBase() 477 .getId(); 478 memento.putString(MEMENTO_KEY_INPUT, inputPluginId); 479 } 480 } 481 482 void setPresentation(boolean listNotTree) { 483 IWorkbenchPart currentPart = getCurrentContributingPart(); 484 if (listNotTree) { 485 if (currentPart == PART_CALLEES_TREE) { 486 partActivated(PART_CALLEES_LIST); 487 } else if (currentPart == PART_CALLERS_TREE) { 488 partActivated(PART_CALLERS_LIST); 489 } 490 491 } else { 492 if (currentPart == PART_CALLEES_LIST) { 493 partActivated(PART_CALLEES_TREE); 494 } else if (currentPart == PART_CALLERS_LIST) { 495 partActivated(PART_CALLERS_TREE); 496 } 497 498 } 499 } 500 501 void setViewType(boolean callers) { 502 IWorkbenchPart currentPart = getCurrentContributingPart(); 503 if (callers) { 504 if (currentPart == PART_CALLEES_TREE) { 505 partActivated(PART_CALLERS_TREE); 506 } else if (currentPart == PART_CALLEES_LIST) { 507 partActivated(PART_CALLERS_LIST); 508 } 509 510 } else { 511 if (currentPart == PART_CALLERS_TREE) { 512 partActivated(PART_CALLEES_TREE); 513 } else if (currentPart == PART_CALLERS_LIST) { 514 partActivated(PART_CALLEES_LIST); 515 } 516 517 } 518 } 519 520 525 protected void showPageRec(PageRec pageRec) { 526 IPage currPage = getCurrentPage(); 527 IStructuredSelection selection = null; 528 if (currPage instanceof DependenciesViewPage) 529 selection = ((DependenciesViewPage)currPage).getSelection(); 530 IPage p = pageRec.page; 531 ((DependenciesViewPage) p).setInput(fInput); 532 super.showPageRec(pageRec); 533 updateTitle(fInput); 534 ((DependenciesViewPage) p).setSelection(selection); 535 } 536 537 void updateTitle(Object newInput) { 538 if (newInput == null) { 539 setContentDescription(""); } else if (!newInput.equals(PDECore.getDefault().getModelManager())) { 541 String name = PDEPlugin.getDefault().getLabelProvider().getText( 542 newInput); 543 String title; 544 if (getCurrentContributingPart() == PART_CALLEES_TREE) { 545 title = NLS.bind(PDEUIMessages.DependenciesView_callees_tree_title, name); 546 } else if (getCurrentContributingPart() == PART_CALLEES_LIST) { 547 title = NLS.bind(PDEUIMessages.DependenciesView_callees_list_title, name); 548 } else if (getCurrentContributingPart() == PART_CALLERS_TREE) { 549 title = NLS.bind(PDEUIMessages.DependenciesView_callers_tree_title, name); 550 } else { 551 title = NLS.bind(PDEUIMessages.DependenciesView_callers_list_title, name); 552 } 553 if(fLoops != NO_LOOPS){ 554 title = title + " " + PDEUIMessages.DependenciesView_cycles_title; } 556 setContentDescription(title); 557 } 558 setTitleToolTip(getTitle()); 559 } 560 561 565 private void addHistoryEntry(String entry) { 566 if (fInputHistory.contains(entry)) { 567 fInputHistory.remove(entry); 568 } 569 fInputHistory.add(0, entry); 570 if (fHistoryDropDownAction != null) 571 fHistoryDropDownAction.setEnabled(true); 572 } 573 574 private void updateHistoryEntries() { 575 for (int i= fInputHistory.size() - 1; i >= 0; i--) { 576 String type= (String ) fInputHistory.get(i); 577 if (PDECore.getDefault().getModelManager().findModel(type)==null) { 578 fInputHistory.remove(i); 579 } 580 } 581 if (fHistoryDropDownAction != null) 582 fHistoryDropDownAction.setEnabled(!fInputHistory.isEmpty()); 583 } 584 585 589 public void gotoHistoryEntry(String entry) { 590 if (fInputHistory.contains(entry)) { 591 updateInput(PDECore.getDefault().getModelManager().findModel(entry)); 592 } 593 } 594 595 599 public String [] getHistoryEntries() { 600 if (fInputHistory.size() > 0) { 601 updateHistoryEntries(); 602 } 603 return (String []) fInputHistory.toArray(new String [fInputHistory.size()]); 604 } 605 606 610 public void setHistoryEntries(String [] elems) { 611 fInputHistory.clear(); 612 for (int i= 0; i < elems.length; i++) { 613 fInputHistory.add(elems[i]); 614 } 615 updateHistoryEntries(); 616 } 617 620 public String getInput() { 621 if(fInput!=null){ 622 return ((IPluginModelBase)fInput).getPluginBase().getId(); 623 } 624 return null; 625 } 626 } 627 | Popular Tags |