1 12 package org.eclipse.debug.internal.ui.views.variables; 13 14 import java.io.ByteArrayInputStream ; 15 import java.io.ByteArrayOutputStream ; 16 import java.io.IOException ; 17 import java.io.InputStreamReader ; 18 import java.io.OutputStreamWriter ; 19 20 import org.eclipse.core.runtime.IProgressMonitor; 21 import org.eclipse.core.runtime.IStatus; 22 import org.eclipse.core.runtime.Status; 23 import org.eclipse.core.runtime.jobs.Job; 24 import org.eclipse.debug.core.DebugException; 25 import org.eclipse.debug.internal.ui.DebugUIPlugin; 26 import org.eclipse.debug.internal.ui.DelegatingModelPresentation; 27 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 28 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 29 import org.eclipse.debug.internal.ui.LazyModelPresentation; 30 import org.eclipse.debug.internal.ui.VariablesViewModelPresentation; 31 import org.eclipse.debug.internal.ui.actions.CollapseAllAction; 32 import org.eclipse.debug.internal.ui.actions.ConfigureColumnsAction; 33 import org.eclipse.debug.internal.ui.actions.variables.ChangeVariableValueAction; 34 import org.eclipse.debug.internal.ui.actions.variables.ShowTypesAction; 35 import org.eclipse.debug.internal.ui.actions.variables.ToggleDetailPaneAction; 36 import org.eclipse.debug.internal.ui.preferences.IDebugPreferenceConstants; 37 import org.eclipse.debug.internal.ui.viewers.model.VirtualFindAction; 38 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelChangedListener; 39 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDelta; 40 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelDeltaVisitor; 41 import org.eclipse.debug.internal.ui.viewers.model.provisional.IModelProxy; 42 import org.eclipse.debug.internal.ui.viewers.model.provisional.IPresentationContext; 43 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdate; 44 import org.eclipse.debug.internal.ui.viewers.model.provisional.IViewerUpdateListener; 45 import org.eclipse.debug.internal.ui.viewers.model.provisional.TreeModelViewer; 46 import org.eclipse.debug.internal.ui.views.DebugModelPresentationContext; 47 import org.eclipse.debug.internal.ui.views.IDebugExceptionHandler; 48 import org.eclipse.debug.internal.ui.views.variables.details.AvailableDetailPanesAction; 49 import org.eclipse.debug.internal.ui.views.variables.details.DetailPaneProxy; 50 import org.eclipse.debug.internal.ui.views.variables.details.IDetailPaneContainer; 51 import org.eclipse.debug.ui.AbstractDebugView; 52 import org.eclipse.debug.ui.DebugUITools; 53 import org.eclipse.debug.ui.IDebugModelPresentation; 54 import org.eclipse.debug.ui.IDebugUIConstants; 55 import org.eclipse.debug.ui.contexts.DebugContextEvent; 56 import org.eclipse.debug.ui.contexts.IDebugContextListener; 57 import org.eclipse.jface.action.IAction; 58 import org.eclipse.jface.action.IMenuListener; 59 import org.eclipse.jface.action.IMenuManager; 60 import org.eclipse.jface.action.IStatusLineManager; 61 import org.eclipse.jface.action.IToolBarManager; 62 import org.eclipse.jface.action.MenuManager; 63 import org.eclipse.jface.action.Separator; 64 import org.eclipse.jface.preference.IPreferenceStore; 65 import org.eclipse.jface.resource.JFaceResources; 66 import org.eclipse.jface.util.IPropertyChangeListener; 67 import org.eclipse.jface.util.PropertyChangeEvent; 68 import org.eclipse.jface.viewers.DoubleClickEvent; 69 import org.eclipse.jface.viewers.ISelection; 70 import org.eclipse.jface.viewers.ISelectionChangedListener; 71 import org.eclipse.jface.viewers.IStructuredSelection; 72 import org.eclipse.jface.viewers.SelectionChangedEvent; 73 import org.eclipse.jface.viewers.StructuredViewer; 74 import org.eclipse.jface.viewers.TreeViewer; 75 import org.eclipse.jface.viewers.Viewer; 76 import org.eclipse.swt.SWT; 77 import org.eclipse.swt.custom.SashForm; 78 import org.eclipse.swt.events.FocusAdapter; 79 import org.eclipse.swt.events.FocusEvent; 80 import org.eclipse.swt.widgets.Composite; 81 import org.eclipse.swt.widgets.Control; 82 import org.eclipse.swt.widgets.Event; 83 import org.eclipse.swt.widgets.Listener; 84 import org.eclipse.ui.IActionBars; 85 import org.eclipse.ui.IMemento; 86 import org.eclipse.ui.IPerspectiveDescriptor; 87 import org.eclipse.ui.IPerspectiveListener; 88 import org.eclipse.ui.IViewSite; 89 import org.eclipse.ui.IWorkbenchActionConstants; 90 import org.eclipse.ui.IWorkbenchPage; 91 import org.eclipse.ui.IWorkbenchPart; 92 import org.eclipse.ui.IWorkbenchPartSite; 93 import org.eclipse.ui.PartInitException; 94 import org.eclipse.ui.WorkbenchException; 95 import org.eclipse.ui.XMLMemento; 96 import org.eclipse.ui.progress.UIJob; 97 import org.eclipse.ui.texteditor.IUpdate; 98 99 102 public class VariablesView extends AbstractDebugView implements IDebugContextListener, 103 IPropertyChangeListener, IDebugExceptionHandler, 104 IPerspectiveListener, IModelChangedListener, 105 IViewerUpdateListener, IDetailPaneContainer { 106 107 111 private VariablesViewModelPresentation fModelPresentation; 112 113 117 private SashForm fSashForm; 118 119 123 private DetailPaneProxy fDetailPane; 124 125 130 private boolean fTreeHasFocus = true; 131 132 136 private ISelectionChangedListener fTreeSelectionChangedListener; 137 138 142 private Listener fDetailPaneActivatedListener; 143 144 148 private static final int[] DEFAULT_SASH_WEIGHTS = {13, 6}; 149 private int[] fLastSashWeights; 150 private boolean fToggledDetailOnce; 151 private String fCurrentDetailPaneOrientation = IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_HIDDEN; 152 private ToggleDetailPaneAction[] fToggleDetailPaneActions; 153 private ConfigureColumnsAction fConfigureColumnsAction; 154 155 protected String PREF_STATE_MEMENTO = "pref_state_memento."; 157 public static final String LOGICAL_STRUCTURE_TYPE_PREFIX = "VAR_LS_"; 159 164 public static final String PRESENTATION_SHOW_LOGICAL_STRUCTURES = "PRESENTATION_SHOW_LOGICAL_STRUCTURES"; 166 170 protected static final String SASH_VIEW_PART = DebugUIPlugin.getUniqueIdentifier() + ".SASH_VIEW_PART"; 175 protected static final String SASH_DETAILS_PART = DebugUIPlugin.getUniqueIdentifier() + ".SASH_DETAILS_PART"; 177 180 protected static final String VARIABLES_FIND_ELEMENT_ACTION = FIND_ACTION + ".Variables"; 182 185 protected static final String VARIABLES_SELECT_ALL_ACTION = SELECT_ALL_ACTION + ".Variables"; 187 190 protected static final String VARIABLES_COPY_ACTION = COPY_ACTION + ".Variables"; 192 195 class Visitor implements IModelDeltaVisitor { 196 201 private boolean fTriggerDetails = false; 202 205 public boolean visit(IModelDelta delta, int depth) { 206 if ((delta.getFlags() & IModelDelta.CONTENT) > 0) { 207 fTriggerDetails = true; 208 return false; 209 } 210 return true; 211 } 212 213 public void reset() { 214 fTriggerDetails = false; 215 } 216 217 public boolean isTriggerDetails() { 218 return fTriggerDetails; 219 } 220 221 } 222 225 private Visitor fVisitor = new Visitor(); 226 227 230 private Job fTriggerDetailsJob = new UIJob("trigger details") { 232 public IStatus runInUIThread(IProgressMonitor monitor) { 233 if (monitor.isCanceled()) { 234 return Status.CANCEL_STATUS; 235 } 236 refreshDetailPaneContents(); 237 return Status.OK_STATUS; 238 } 239 }; 240 241 247 public void dispose() { 248 249 DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).removeDebugContextListener(this); 250 getSite().getWorkbenchWindow().removePerspectiveListener(this); 251 DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this); 252 JFaceResources.getFontRegistry().removeListener(this); 253 TreeModelViewer viewer = getVariablesViewer(); 254 if (viewer != null) { 255 viewer.removeModelChangedListener(this); 256 viewer.removeViewerUpdateListener(this); 257 } 258 if (fDetailPane != null) fDetailPane.dispose(); 259 super.dispose(); 260 } 261 262 266 protected void setViewerInput(Object context) { 267 268 if (context == null) { 269 fDetailPane.display(null); 271 } 272 273 Object current = getViewer().getInput(); 274 275 if (current == null && context == null) { 276 return; 277 } 278 279 if (current != null && current.equals(context)) { 280 return; 281 } 282 283 showViewer(); 284 getViewer().setInput(context); 285 } 286 287 290 public void propertyChange(PropertyChangeEvent event) { 291 String propertyName= event.getProperty(); 292 if (propertyName.equals(IDebugUIConstants.PREF_CHANGED_DEBUG_ELEMENT_COLOR) || 293 propertyName.equals(IInternalDebugUIConstants.PREF_CHANGED_VALUE_BACKGROUND) || 294 propertyName.equals(IInternalDebugUIConstants.VARIABLE_TEXT_FONT)) { 295 getViewer().refresh(); 296 } 297 } 298 299 302 public Viewer createViewer(Composite parent) { 303 304 fTriggerDetailsJob.setSystem(true); 305 306 fSashForm = new SashForm(parent, SWT.NONE); 308 309 fModelPresentation = new VariablesViewModelPresentation(); 310 DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this); 311 JFaceResources.getFontRegistry().addListener(this); 312 313 TreeModelViewer variablesViewer = createTreeViewer(fSashForm); 314 315 fSashForm.setMaximizedControl(variablesViewer.getControl()); 316 317 fDetailPane = new DetailPaneProxy(this); 318 fDetailPane.display(null); 320 createOrientationActions(variablesViewer); 321 IPreferenceStore prefStore = DebugUIPlugin.getDefault().getPreferenceStore(); 322 String orientation = prefStore.getString(getDetailPanePreferenceKey()); 323 for (int i = 0; i < fToggleDetailPaneActions.length; i++) { 324 fToggleDetailPaneActions[i].setChecked(fToggleDetailPaneActions[i].getOrientation().equals(orientation)); 325 } 326 setDetailPaneOrientation(orientation); 327 IMemento memento = getMemento(); 328 if (memento != null) { 329 variablesViewer.initState(memento); 330 } 331 332 variablesViewer.addModelChangedListener(this); 333 variablesViewer.addViewerUpdateListener(this); 334 335 return variablesViewer; 336 } 337 338 341 public void init(IViewSite site, IMemento memento) throws PartInitException { 342 super.init(site, memento); 343 PREF_STATE_MEMENTO = PREF_STATE_MEMENTO + site.getId(); 344 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 345 String string = store.getString(PREF_STATE_MEMENTO); 346 if(string.length() > 0) { 347 ByteArrayInputStream bin = new ByteArrayInputStream (string.getBytes()); 348 InputStreamReader reader = new InputStreamReader (bin); 349 try { 350 XMLMemento stateMemento = XMLMemento.createReadRoot(reader); 351 setMemento(stateMemento); 352 } catch (WorkbenchException e) { 353 } finally { 354 try { 355 reader.close(); 356 bin.close(); 357 } catch (IOException e){} 358 } 359 } 360 IMemento mem = getMemento(); 361 setLastSashWeights(DEFAULT_SASH_WEIGHTS); 363 if (mem != null) { 364 Integer sw = mem.getInteger(SASH_VIEW_PART); 365 if(sw != null) { 366 int view = sw.intValue(); 367 sw = mem.getInteger(SASH_DETAILS_PART); 368 if(sw != null) { 369 int details = sw.intValue(); 370 if(view > -1 & details > -1) { 371 setLastSashWeights(new int[] {view, details}); 372 } 373 } 374 } 375 } 376 site.getWorkbenchWindow().addPerspectiveListener(this); 377 } 378 379 382 public void partDeactivated(IWorkbenchPart part) { 383 String id = part.getSite().getId(); 384 if (id.equals(getSite().getId())) { 385 ByteArrayOutputStream bout = new ByteArrayOutputStream (); 386 OutputStreamWriter writer = new OutputStreamWriter (bout); 387 388 try { 389 XMLMemento memento = XMLMemento.createWriteRoot("VariablesViewMemento"); saveViewerState(memento); 391 memento.save(writer); 392 393 IPreferenceStore store = DebugUIPlugin.getDefault().getPreferenceStore(); 394 String xmlString = bout.toString(); 395 store.putValue(PREF_STATE_MEMENTO, xmlString); 396 } catch (IOException e) { 397 } finally { 398 try { 399 writer.close(); 400 bout.close(); 401 } catch (IOException e) { 402 } 403 } 404 } 405 super.partDeactivated(part); 406 } 407 408 412 public void saveViewerState(IMemento memento) { 413 if (fSashForm != null && !fSashForm.isDisposed()) { 414 int[] weights = fSashForm.getWeights(); 415 memento.putInteger(SASH_VIEW_PART, weights[0]); 416 memento.putInteger(SASH_DETAILS_PART, weights[1]); 417 } 418 getVariablesViewer().saveState(memento); 419 } 420 421 424 protected String getDetailPanePreferenceKey() { 425 return IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_ORIENTATION; 426 } 427 428 431 protected TreeModelViewer createTreeViewer(Composite parent) { 432 433 int style = getViewerStyle(); 434 final TreeModelViewer variablesViewer = new TreeModelViewer(parent, style, 435 new DebugModelPresentationContext(getPresentationContextId(), fModelPresentation)); 436 437 variablesViewer.getControl().addFocusListener(new FocusAdapter() { 438 public void focusGained(FocusEvent e) { 439 fTreeHasFocus = true; 440 getSite().setSelectionProvider(variablesViewer); 441 setAction(SELECT_ALL_ACTION, getAction(VARIABLES_SELECT_ALL_ACTION)); 442 setAction(COPY_ACTION, getAction(VARIABLES_COPY_ACTION)); 443 setAction(FIND_ACTION, getAction(VARIABLES_FIND_ELEMENT_ACTION)); 444 getViewSite().getActionBars().updateActionBars(); 445 } 446 447 public void focusLost(FocusEvent e){ 448 getSite().setSelectionProvider(null); 449 setAction(SELECT_ALL_ACTION, null); 450 setAction(COPY_ACTION,null); 451 setAction(FIND_ACTION, null); 452 getViewSite().getActionBars().updateActionBars(); 453 } 454 }); 455 variablesViewer.getPresentationContext().addPropertyChangeListener( 456 new IPropertyChangeListener() { 457 public void propertyChange(PropertyChangeEvent event) { 458 if (IPresentationContext.PROPERTY_COLUMNS.equals(event.getProperty())) { 459 IAction action = getAction("ShowTypeNames"); if (action != null) { 461 action.setEnabled(event.getNewValue() == null); 462 } 463 } 464 } 465 }); 466 467 getSite().setSelectionProvider(variablesViewer); 468 variablesViewer.addPostSelectionChangedListener(getTreeSelectionChangedListener()); 469 DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).addDebugContextListener(this); 470 return variablesViewer; 471 } 472 473 478 protected String getPresentationContextId() { 479 return IDebugUIConstants.ID_VARIABLE_VIEW; 480 } 481 482 487 protected int getViewerStyle() { 488 return SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.VIRTUAL | SWT.FULL_SELECTION; 489 } 490 491 494 protected String getHelpContextId() { 495 return IDebugHelpContextIds.VARIABLE_VIEW; 496 } 497 498 504 public void setDetailPaneOrientation(String orientation) { 505 if (orientation.equals(fCurrentDetailPaneOrientation)) { 506 return; 507 } 508 if (orientation.equals(IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_HIDDEN)) { 509 hideDetailPane(); 510 } else { 511 int vertOrHoriz = orientation.equals(IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_UNDERNEATH) ? SWT.VERTICAL : SWT.HORIZONTAL; 512 fSashForm.setOrientation(vertOrHoriz); 513 if (IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_HIDDEN.equals(fCurrentDetailPaneOrientation)) { 514 showDetailPane(); 515 } 516 } 517 fCurrentDetailPaneOrientation = orientation; 518 DebugUIPlugin.getDefault().getPreferenceStore().setValue(getDetailPanePreferenceKey(), orientation); 519 } 520 521 524 private void hideDetailPane() { 525 if (fToggledDetailOnce) { 526 setLastSashWeights(fSashForm.getWeights()); 527 } 528 fSashForm.setMaximizedControl(getViewer().getControl()); 529 } 530 531 534 private void showDetailPane() { 535 fSashForm.setMaximizedControl(null); 536 fSashForm.setWeights(getLastSashWeights()); 537 refreshDetailPaneContents(); 538 revealTreeSelection(); 539 fToggledDetailOnce = true; 540 } 541 542 545 protected void revealTreeSelection() { 546 StructuredViewer viewer = (StructuredViewer) getViewer(); 547 if (viewer != null) { 548 ISelection selection = viewer.getSelection(); 549 if (selection instanceof IStructuredSelection) { 550 Object selected = ((IStructuredSelection)selection).getFirstElement(); 551 if (selected != null) { 552 viewer.reveal(selected); 553 } 554 } 555 } 556 } 557 558 566 protected int[] getLastSashWeights() { 567 if (fLastSashWeights == null) { 568 fLastSashWeights = DEFAULT_SASH_WEIGHTS; 569 } 570 else if(fLastSashWeights[0] < 0 || fLastSashWeights[1] < 0) { 572 fLastSashWeights = DEFAULT_SASH_WEIGHTS; 573 } 574 return fLastSashWeights; 575 } 576 577 581 protected void setLastSashWeights(int[] weights) { 582 fLastSashWeights = weights; 583 } 584 585 588 protected void createActions() { 589 IAction action = new ShowTypesAction(this); 590 setAction("ShowTypeNames",action); 592 action = new ToggleLogicalStructureAction(this); 593 setAction("ToggleContentProviders", action); 595 action = new CollapseAllAction((TreeViewer)getViewer()); 596 setAction("CollapseAll", action); 598 action = new ChangeVariableValueAction(this); 599 action.setEnabled(false); 600 setAction("ChangeVariableValue", action); 602 action= new VirtualFindAction(getVariablesViewer()); 603 setAction(VARIABLES_FIND_ELEMENT_ACTION, action); 604 } 605 606 612 protected void createContextMenu(Control menuControl) { 613 super.createContextMenu(menuControl); 614 setAction(VARIABLES_COPY_ACTION, getAction(COPY_ACTION)); 615 } 616 617 622 private void createOrientationActions(TreeModelViewer viewer) { 623 IActionBars actionBars = getViewSite().getActionBars(); 624 IMenuManager viewMenu = actionBars.getMenuManager(); 625 626 fToggleDetailPaneActions = new ToggleDetailPaneAction[3]; 627 fToggleDetailPaneActions[0] = new ToggleDetailPaneAction(this, IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_UNDERNEATH, null); 628 fToggleDetailPaneActions[1] = new ToggleDetailPaneAction(this, IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_RIGHT, null); 629 fToggleDetailPaneActions[2] = new ToggleDetailPaneAction(this, IDebugPreferenceConstants.VARIABLES_DETAIL_PANE_HIDDEN, getToggleActionLabel()); 630 viewMenu.add(new Separator()); 631 final MenuManager layoutSubMenu = new MenuManager(VariablesViewMessages.VariablesView_40); 632 layoutSubMenu.setRemoveAllWhenShown(true); 633 layoutSubMenu.add(fToggleDetailPaneActions[0]); 634 layoutSubMenu.add(fToggleDetailPaneActions[1]); 635 layoutSubMenu.add(fToggleDetailPaneActions[2]); 636 viewMenu.add(layoutSubMenu); 637 viewMenu.add(new Separator()); 638 639 fConfigureColumnsAction = new ConfigureColumnsAction(viewer); 640 setAction("ToggleColmns", new ToggleShowColumnsAction(viewer)); 642 layoutSubMenu.addMenuListener(new IMenuListener() { 643 public void menuAboutToShow(IMenuManager manager) { 644 layoutSubMenu.add(fToggleDetailPaneActions[0]); 645 layoutSubMenu.add(fToggleDetailPaneActions[1]); 646 layoutSubMenu.add(fToggleDetailPaneActions[2]); 647 IAction action = getAction("ToggleColmns"); ((IUpdate)action).update(); 649 if (action.isEnabled()) { 650 layoutSubMenu.add(action); 651 } 652 fConfigureColumnsAction.update(); 653 if (fConfigureColumnsAction.isEnabled()) { 654 layoutSubMenu.add(fConfigureColumnsAction); 655 } 656 } 657 }); 658 } 659 660 666 protected String getToggleActionLabel(){ 667 return VariablesViewMessages.VariablesView_41; 668 } 669 670 675 protected void configureToolBar(IToolBarManager tbm) { 676 tbm.add(new Separator(this.getClass().getName())); 677 tbm.add(new Separator(IDebugUIConstants.RENDER_GROUP)); 678 tbm.add(getAction("ShowTypeNames")); tbm.add(getAction("ToggleContentProviders")); tbm.add(getAction("CollapseAll")); } 682 683 689 protected void fillContextMenu(IMenuManager menu) { 690 691 menu.add(new Separator(IDebugUIConstants.EMPTY_VARIABLE_GROUP)); 692 menu.add(new Separator(IDebugUIConstants.VARIABLE_GROUP)); 693 menu.add(getAction(VARIABLES_FIND_ELEMENT_ACTION)); 694 menu.add(getAction("ChangeVariableValue")); menu.add(new Separator()); 696 IAction action = new AvailableLogicalStructuresAction(this); 697 if (action.isEnabled()) { 698 menu.add(action); 699 } 700 action = new AvailableDetailPanesAction(this); 701 if (isDetailPaneVisible() && action.isEnabled()) { 702 menu.add(action); 703 } 704 menu.add(new Separator(IDebugUIConstants.EMPTY_RENDER_GROUP)); 705 menu.add(new Separator(IDebugUIConstants.EMPTY_NAVIGATION_GROUP)); 706 menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); 707 } 708 709 713 protected ISelectionChangedListener getTreeSelectionChangedListener() { 714 if (fTreeSelectionChangedListener == null) { 715 fTreeSelectionChangedListener = new ISelectionChangedListener() { 716 public void selectionChanged(final SelectionChangedEvent event) { 717 if (event.getSelectionProvider().equals(getViewer())) { 718 clearStatusLine(); 719 if (fSashForm.getMaximizedControl() == getViewer().getControl()) { 721 return; 722 } 723 refreshDetailPaneContents(); 724 treeSelectionChanged(event); 725 } 726 } 727 }; 728 } 729 return fTreeSelectionChangedListener; 730 } 731 732 737 protected void treeSelectionChanged(SelectionChangedEvent event) {} 738 739 742 public String getCurrentPaneID() { 743 return fDetailPane.getCurrentPaneID(); 744 } 745 746 749 public IStructuredSelection getCurrentSelection() { 750 if (getViewer() != null){ 751 return (IStructuredSelection)getViewer().getSelection(); 752 } 753 return null; 754 } 755 756 759 public Composite getParentComposite() { 760 return fSashForm; 761 } 762 763 766 public IWorkbenchPartSite getWorkbenchPartSite() { 767 return getSite(); 768 } 769 770 773 public void refreshDetailPaneContents() { 774 fDetailPane.display(getCurrentSelection()); 775 } 776 777 780 public void paneChanged(String newPaneID) { 781 if (fDetailPaneActivatedListener == null){ 782 fDetailPaneActivatedListener = new Listener() { 783 public void handleEvent(Event event) { 784 fTreeHasFocus = false; 785 } 786 }; 787 } 788 fDetailPane.getCurrentControl().addListener(SWT.Activate, fDetailPaneActivatedListener); 789 } 790 791 794 protected IDebugModelPresentation getModelPresentation() { 795 if (fModelPresentation == null) { 796 fModelPresentation = new VariablesViewModelPresentation(); 797 } 798 return fModelPresentation; 799 } 800 801 804 public Object getAdapter(Class required) { 805 if (IDebugModelPresentation.class.equals(required)) { 806 return getModelPresentation(); 807 } 808 else if (fDetailPane != null){ 809 Object adapter = fDetailPane.getAdapter(required); 810 if (adapter != null) return adapter; 811 } 812 return super.getAdapter(required); 813 } 814 815 820 protected void updateAction(String actionId) { 821 IAction action= getAction(actionId); 822 if (action instanceof IUpdate) { 823 ((IUpdate) action).update(); 824 } 825 } 826 827 830 protected boolean isDetailPaneVisible() { 831 return !fToggleDetailPaneActions[2].isChecked(); 832 } 833 834 837 protected Control getDefaultControl() { 838 return fSashForm; 839 } 840 841 844 public void handleException(DebugException e) { 845 showMessage(e.getMessage()); 846 } 847 848 851 public void debugContextChanged(DebugContextEvent event) { 852 if ((event.getFlags() & DebugContextEvent.ACTIVATED) > 0) { 853 contextActivated(event.getContext()); 854 } 855 } 856 857 861 protected void contextActivated(ISelection selection) { 862 if (!isAvailable() || !isVisible()) { 863 return; 864 } 865 866 if (selection instanceof IStructuredSelection) { 867 setViewerInput(((IStructuredSelection)selection).getFirstElement()); 868 } 869 showViewer(); 870 871 updateAction(VARIABLES_FIND_ELEMENT_ACTION); 872 updateAction(FIND_ACTION); 873 } 874 875 881 public void doubleClick(DoubleClickEvent event) { 882 IAction action = getAction(DOUBLE_CLICK_ACTION); 883 if (action != null && action.isEnabled()) { 884 action.run(); 885 } 886 } 887 888 891 public IDebugModelPresentation getPresentation(String id) { 892 if (getViewer() instanceof StructuredViewer) { 893 IDebugModelPresentation lp = getModelPresentation(); 894 if (lp instanceof DelegatingModelPresentation) { 895 return ((DelegatingModelPresentation)lp).getPresentation(id); 896 } 897 if (lp instanceof LazyModelPresentation) { 898 if (((LazyModelPresentation)lp).getDebugModelIdentifier().equals(id)) { 899 return lp; 900 } 901 } 902 } 903 return null; 904 } 905 906 909 public boolean isMainViewerAvailable() { 910 return isAvailable(); 911 } 912 913 916 protected IPresentationContext getPresentationContext() { 917 return getVariablesViewer().getPresentationContext(); 918 } 919 920 923 public void setShowLogicalStructure(boolean flag) { 924 getPresentationContext().setProperty(PRESENTATION_SHOW_LOGICAL_STRUCTURES, Boolean.valueOf(flag)); 925 } 926 927 930 public boolean isShowLogicalStructure() { 931 Boolean show = (Boolean ) getPresentationContext().getProperty(PRESENTATION_SHOW_LOGICAL_STRUCTURES); 932 return show != null && show.booleanValue(); 933 } 934 935 938 protected void becomesHidden() { 939 setViewerInput(null); 940 super.becomesHidden(); 941 } 942 943 946 protected void becomesVisible() { 947 super.becomesVisible(); 948 ISelection selection = DebugUITools.getDebugContextManager().getContextService(getSite().getWorkbenchWindow()).getActiveContext(); 949 contextActivated(selection); 950 } 951 952 955 protected TreeModelViewer getVariablesViewer() { 956 return (TreeModelViewer) getViewer(); 957 } 958 959 962 protected void clearStatusLine() { 963 IStatusLineManager manager = getViewSite().getActionBars().getStatusLineManager(); 964 manager.setErrorMessage(null); 965 manager.setMessage(null); 966 } 967 968 971 public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {} 972 973 976 public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) { 977 if(changeId.equals(IWorkbenchPage.CHANGE_RESET)) { 978 setLastSashWeights(DEFAULT_SASH_WEIGHTS); 979 fSashForm.setWeights(DEFAULT_SASH_WEIGHTS); 980 } 981 } 982 983 986 public void modelChanged(IModelDelta delta, IModelProxy proxy) { 987 fVisitor.reset(); 988 delta.accept(fVisitor); 989 } 990 991 994 public void updateComplete(IViewerUpdate update) { 995 IStatus status = update.getStatus(); 996 if (!update.isCanceled()) { 997 if (status != null && status.getCode() != IStatus.OK) { 998 showMessage(status.getMessage()); 999 } else { 1000 showViewer(); 1001 } 1002 } 1003 } 1004 1005 1008 public void updateStarted(IViewerUpdate update) { 1009 } 1010 1011 1014 public synchronized void viewerUpdatesBegin() { 1015 fTriggerDetailsJob.cancel(); 1016 } 1017 1018 1021 public synchronized void viewerUpdatesComplete() { 1022 if (fVisitor.isTriggerDetails()) { 1023 fTriggerDetailsJob.schedule(); 1024 } 1025 } 1026 1027 1030 public void setFocus() { 1031 boolean success = false; 1032 if (!fTreeHasFocus && fDetailPane != null){ 1033 success = fDetailPane.setFocus(); 1034 } 1035 if (!success && getViewer() != null){ 1037 getViewer().getControl().setFocus(); 1038 } 1039 } 1040} 1041 | Popular Tags |