KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > views > memory > MemoryView


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.views.memory;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.Enumeration JavaDoc;
15 import java.util.Hashtable JavaDoc;
16 import java.util.StringTokenizer JavaDoc;
17
18 import org.eclipse.core.commands.AbstractHandler;
19 import org.eclipse.core.commands.ExecutionEvent;
20 import org.eclipse.core.commands.ExecutionException;
21 import org.eclipse.core.runtime.IAdaptable;
22 import org.eclipse.core.runtime.Preferences;
23 import org.eclipse.debug.internal.ui.DebugUIMessages;
24 import org.eclipse.debug.internal.ui.DebugUIPlugin;
25 import org.eclipse.debug.internal.ui.views.variables.VariablesViewMessages;
26 import org.eclipse.debug.ui.DebugUITools;
27 import org.eclipse.debug.ui.IDebugUIConstants;
28 import org.eclipse.debug.ui.memory.IMemoryRenderingContainer;
29 import org.eclipse.debug.ui.memory.IMemoryRenderingSite;
30 import org.eclipse.debug.ui.memory.IMemoryRenderingSynchronizationService;
31 import org.eclipse.jface.action.IAction;
32 import org.eclipse.jface.action.IMenuManager;
33 import org.eclipse.jface.action.MenuManager;
34 import org.eclipse.jface.action.Separator;
35 import org.eclipse.jface.action.ToolBarManager;
36 import org.eclipse.jface.viewers.ISelection;
37 import org.eclipse.jface.viewers.ISelectionChangedListener;
38 import org.eclipse.jface.viewers.ISelectionProvider;
39 import org.eclipse.jface.viewers.IStructuredSelection;
40 import org.eclipse.jface.viewers.SelectionChangedEvent;
41 import org.eclipse.jface.viewers.StructuredSelection;
42 import org.eclipse.swt.SWT;
43 import org.eclipse.swt.custom.SashForm;
44 import org.eclipse.swt.custom.ViewForm;
45 import org.eclipse.swt.events.FocusAdapter;
46 import org.eclipse.swt.events.FocusEvent;
47 import org.eclipse.swt.widgets.Composite;
48 import org.eclipse.swt.widgets.Control;
49 import org.eclipse.swt.widgets.Event;
50 import org.eclipse.swt.widgets.Label;
51 import org.eclipse.swt.widgets.Listener;
52 import org.eclipse.swt.widgets.ToolBar;
53 import org.eclipse.ui.IActionBars;
54 import org.eclipse.ui.IPartListener2;
55 import org.eclipse.ui.IViewReference;
56 import org.eclipse.ui.IViewSite;
57 import org.eclipse.ui.IWorkbenchPart;
58 import org.eclipse.ui.IWorkbenchPartReference;
59 import org.eclipse.ui.PartInitException;
60 import org.eclipse.ui.PlatformUI;
61 import org.eclipse.ui.commands.ICommandService;
62 import org.eclipse.ui.contexts.IContextService;
63 import org.eclipse.ui.handlers.IHandlerService;
64 import org.eclipse.ui.part.ViewPart;
65
66 /**
67  *
68  * @since 3.0
69  */

70 public class MemoryView extends ViewPart implements IMemoryRenderingSite {
71
72     protected MemoryViewSelectionProvider fSelectionProvider;
73     private MemoryViewPartListener fPartListener;
74     
75     private SashForm fSashForm;
76     private Hashtable JavaDoc fViewPanes = new Hashtable JavaDoc();
77     private Hashtable JavaDoc fViewPaneControls = new Hashtable JavaDoc();
78     private ArrayList JavaDoc fVisibleViewPanes = new ArrayList JavaDoc();
79     private boolean fVisible;
80     
81     private ArrayList JavaDoc fWeights = new ArrayList JavaDoc();
82     
83     private static final String JavaDoc VISIBILITY_PREF = IDebugUIConstants.ID_MEMORY_VIEW+".viewPanesVisibility"; //$NON-NLS-1$
84
private static final String JavaDoc ID_MEMORY_VIEW_CONTEXT = "org.eclipse.debug.ui.memoryview"; //$NON-NLS-1$
85
private static final String JavaDoc ID_ADD_MEMORY_BLOCK_COMMAND = "org.eclipse.debug.ui.commands.addMemoryMonitor"; //$NON-NLS-1$
86
private static final String JavaDoc ID_TOGGLE_MEMORY_MONITORS_PANE_COMMAND = "org.eclipse.debug.ui.commands.toggleMemoryMonitorsPane"; //$NON-NLS-1$
87
private static final String JavaDoc ID_NEXT_MEMORY_BLOCK_COMMAND = "org.eclipse.debug.ui.commands.nextMemoryBlock"; //$NON-NLS-1$
88

89     public static final String JavaDoc VIEW_PANE_ORIENTATION_PREF = IDebugUIConstants.ID_MEMORY_VIEW+".orientation"; //$NON-NLS-1$
90
public static final int HORIZONTAL_VIEW_ORIENTATION = 0;
91     public static final int VERTICAL_VIEW_ORIENTATION =1;
92
93     private String JavaDoc[] defaultVisiblePaneIds ={MemoryBlocksTreeViewPane.PANE_ID, IDebugUIConstants.ID_RENDERING_VIEW_PANE_1};
94         
95     private MemoryBlocksTreeViewPane fMemBlkViewer;
96     
97     private MemoryViewSynchronizationService fSyncService;
98     
99     private boolean fPinMBDisplay = false; // pin memory block display, on by default
100
private static int fViewCnt = 0;
101
102     private AbstractHandler fAddHandler;
103     private AbstractHandler fToggleMonitorsHandler;
104     private AbstractHandler fNextMemoryBlockHandler;
105     
106     private ViewPaneOrientationAction[] fOrientationActions;
107     private int fViewOrientation = HORIZONTAL_VIEW_ORIENTATION;
108     
109     private String JavaDoc fActivePaneId;
110         
111     class MemoryViewSelectionProvider implements ISelectionProvider, ISelectionChangedListener
112     {
113         ArrayList JavaDoc fListeners = new ArrayList JavaDoc();
114         
115         IStructuredSelection fSelections = new StructuredSelection();
116
117         /* (non-Javadoc)
118          * @see org.eclipse.jface.viewers.ISelectionProvider#addSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
119          */

120         public void addSelectionChangedListener(ISelectionChangedListener listener)
121         {
122             if (!fListeners.contains(listener))
123                 fListeners.add(listener);
124             
125         }
126
127         /* (non-Javadoc)
128          * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
129          */

130         public ISelection getSelection()
131         {
132             return fSelections;
133         }
134
135         /* (non-Javadoc)
136          * @see org.eclipse.jface.viewers.ISelectionProvider#removeSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
137          */

138         public void removeSelectionChangedListener(ISelectionChangedListener listener)
139         {
140             if (fListeners.contains(listener))
141                 fListeners.remove(listener);
142             
143         }
144
145         /* (non-Javadoc)
146          * @see org.eclipse.jface.viewers.ISelectionProvider#setSelection(org.eclipse.jface.viewers.ISelection)
147          */

148         public void setSelection(ISelection selection)
149         {
150             if (selection instanceof IStructuredSelection)
151             {
152                 boolean fireChanged = false;
153                 
154                 // only fire change event if the selection has really changed
155
if (fSelections.getFirstElement() != ((IStructuredSelection)selection).getFirstElement())
156                     fireChanged = true;
157
158                 fSelections = (IStructuredSelection)selection;
159                 
160                 if (fireChanged)
161                     fireChanged();
162             }
163         }
164         
165         public void fireChanged()
166         {
167             SelectionChangedEvent evt = new SelectionChangedEvent(this, getSelection());
168             for (int i=0; i<fListeners.size(); i++)
169             {
170                 ((ISelectionChangedListener)fListeners.get(i)).selectionChanged(evt);
171             }
172         }
173
174         /* (non-Javadoc)
175          * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
176          */

177         public void selectionChanged(SelectionChangedEvent event) {
178             ISelection viewPaneSelection = event.getSelection();
179             
180             if (viewPaneSelection instanceof IStructuredSelection)
181             {
182                 Object JavaDoc selected = ((IStructuredSelection)viewPaneSelection).getFirstElement();
183             
184                 if (selected != null)
185                 {
186                     StructuredSelection strucSelection = new StructuredSelection(new Object JavaDoc[]{selected});
187                     setSelection(strucSelection);
188                 }
189                 else
190                 {
191                     setSelection(viewPaneSelection);
192                 }
193             }
194         }
195     }
196     
197     class MemoryViewPartListener implements IPartListener2
198     {
199         IMemoryRenderingSite fView = null;
200         
201         public MemoryViewPartListener(IMemoryRenderingSite view)
202         {
203             fView = view;
204         }
205
206         /* (non-Javadoc)
207          * @see org.eclipse.ui.IPartListener2#partActivated(org.eclipse.ui.IWorkbenchPartReference)
208          */

209         public void partActivated(IWorkbenchPartReference ref) {
210         }
211
212         /* (non-Javadoc)
213          * @see org.eclipse.ui.IPartListener2#partBroughtToTop(org.eclipse.ui.IWorkbenchPartReference)
214          */

215         public void partBroughtToTop(IWorkbenchPartReference ref) {
216         }
217
218         /* (non-Javadoc)
219          * @see org.eclipse.ui.IPartListener2#partClosed(org.eclipse.ui.IWorkbenchPartReference)
220          */

221         public void partClosed(IWorkbenchPartReference ref) {
222         }
223
224         /* (non-Javadoc)
225          * @see org.eclipse.ui.IPartListener2#partDeactivated(org.eclipse.ui.IWorkbenchPartReference)
226          */

227         public void partDeactivated(IWorkbenchPartReference ref) {
228         }
229
230         /* (non-Javadoc)
231          * @see org.eclipse.ui.IPartListener2#partHidden(org.eclipse.ui.IWorkbenchPartReference)
232          */

233         public void partHidden(IWorkbenchPartReference ref) {
234             
235             IWorkbenchPart part = ref.getPart(false);
236             
237             if (part == fView)
238             {
239                 setVisible(false);
240             }
241         }
242
243         /* (non-Javadoc)
244          * @see org.eclipse.ui.IPartListener2#partVisible(org.eclipse.ui.IWorkbenchPartReference)
245          */

246         public void partVisible(IWorkbenchPartReference ref) {
247             IWorkbenchPart part = ref.getPart(false);
248             
249             if (part == fView)
250             {
251                 setVisible(true);
252                 restoreView();
253             }
254
255         }
256
257         /* (non-Javadoc)
258          * @see org.eclipse.ui.IPartListener2#partInputChanged(org.eclipse.ui.IWorkbenchPartReference)
259          */

260         public void partInputChanged(IWorkbenchPartReference ref) {
261         }
262
263         public void partOpened(IWorkbenchPartReference ref)
264         {
265         }
266     }
267     
268     public void init(IViewSite site) throws PartInitException {
269         super.init(site);
270         
271         fViewCnt ++;
272         String JavaDoc secondaryId = site.getSecondaryId();
273         if (secondaryId != null)
274             MemoryViewIdRegistry.registerView(secondaryId);
275         
276         // only do this the first time
277
// not sure if there is a bug in the UI... if the view is
278
// not a primary view and if it's hidden, the view is not
279
// init and created until it becomes visible.
280
if (fViewCnt == 1)
281         {
282             // also try to find other views and register
283
if (DebugUIPlugin.getActiveWorkbenchWindow() != null &&
284                 DebugUIPlugin.getActiveWorkbenchWindow().getActivePage() != null)
285             {
286                 IViewReference references[] = DebugUIPlugin.getActiveWorkbenchWindow().getActivePage().getViewReferences();
287                 for (int i=0; i<references.length; i++)
288                 {
289                     if (references[i].getSecondaryId() != null)
290                     {
291                         MemoryViewIdRegistry.registerView(references[i].getSecondaryId());
292                     }
293                 }
294             }
295         }
296         
297         fSyncService = new MemoryViewSynchronizationService();
298     }
299     
300     /* (non-Javadoc)
301      * @see org.eclipse.ui.part.WorkbenchPart#createPartControl(org.eclipse.swt.widgets.Composite)
302      */

303     public void createPartControl(Composite parent) {
304         fSashForm = new SashForm(parent, SWT.HORIZONTAL);
305         
306         fSelectionProvider = new MemoryViewSelectionProvider();
307         
308         // set up selection provider and listeners
309
getSite().setSelectionProvider(fSelectionProvider);
310
311         createMemoryBlocksTreeViewPane(fSashForm);
312         createRenderingViewPane(IDebugUIConstants.ID_RENDERING_VIEW_PANE_1);
313         createRenderingViewPane(IDebugUIConstants.ID_RENDERING_VIEW_PANE_2);
314         
315         setVisible(true);
316         
317         // set up weights in sashform
318
Integer JavaDoc[] weights = (Integer JavaDoc[])fWeights.toArray(new Integer JavaDoc[fWeights.size()]);
319         int[] intWeights = new int[weights.length];
320         for (int i=0; i<weights.length; i++)
321         {
322             intWeights[i] = weights[i].intValue();
323         }
324         fSashForm.setWeights(intWeights);
325         loadViewPanesVisibility();
326         
327         createOrientationActions();
328         loadOrientation();
329         
330         fPartListener = new MemoryViewPartListener(this);
331         getSite().getPage().addPartListener(fPartListener);
332         activateHandlers();
333         // restore view pane after finishing creating all the view panes
334
restoreView();
335     }
336
337     
338     public void activateHandlers() {
339         ICommandService commandSupport = (ICommandService)getSite().getService(ICommandService.class);
340         IHandlerService handlerService = (IHandlerService)getSite().getService(IHandlerService.class);
341         IContextService contextSupport = (IContextService)getSite().getService(IContextService.class);
342         
343         if (commandSupport != null && handlerService != null && contextSupport != null)
344         {
345             contextSupport.activateContext(ID_MEMORY_VIEW_CONTEXT);
346                 
347             fAddHandler = new AbstractHandler() {
348                     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
349                         IAdaptable context = DebugUITools.getDebugContext();
350                         if (context != null && MemoryViewUtil.isValidSelection(new StructuredSelection(context)))
351                         {
352                             RetargetAddMemoryBlockAction action = new RetargetAddMemoryBlockAction(MemoryView.this);
353                             action.run();
354                             action.dispose();
355                         }
356                         return null;
357                     }};
358             handlerService.activateHandler(ID_ADD_MEMORY_BLOCK_COMMAND, fAddHandler);
359             
360             fToggleMonitorsHandler = new AbstractHandler() {
361                     public Object JavaDoc execute(ExecutionEvent event) throws ExecutionException {
362                         ToggleMemoryMonitorsAction action = new ToggleMemoryMonitorsAction();
363                         action.init(MemoryView.this);
364                         action.run();
365                         action.dispose();
366                         return null;
367                     }
368                 };
369             
370             handlerService.activateHandler(ID_TOGGLE_MEMORY_MONITORS_PANE_COMMAND, fToggleMonitorsHandler);
371             
372             fNextMemoryBlockHandler = new AbstractHandler() {
373
374                 public Object JavaDoc execute(ExecutionEvent event)
375                         throws ExecutionException {
376                     SwitchMemoryBlockAction action = new SwitchMemoryBlockAction();
377                     action.init(MemoryView.this);
378                     action.run();
379                     action.dispose();
380                     return null;
381                 }
382             };
383             handlerService.activateHandler(ID_NEXT_MEMORY_BLOCK_COMMAND, fNextMemoryBlockHandler);
384         }
385     }
386     
387     /**
388      *
389      */

390     private void createMemoryBlocksTreeViewPane(Composite parent) {
391         
392         fMemBlkViewer = new MemoryBlocksTreeViewPane(this);
393         fViewPanes.put(MemoryBlocksTreeViewPane.PANE_ID, fMemBlkViewer);
394         ViewForm viewerViewForm = new ViewForm(parent, SWT.NONE);
395         PlatformUI.getWorkbench().getHelpSystem().setHelp(viewerViewForm, IDebugUIConstants.PLUGIN_ID + ".MemoryView_context"); //$NON-NLS-1$
396
fViewPaneControls.put(MemoryBlocksTreeViewPane.PANE_ID, viewerViewForm);
397         fWeights.add(new Integer JavaDoc(15));
398         
399         fMemBlkViewer.addSelectionListener(fSelectionProvider);
400         
401         Control viewerControl = fMemBlkViewer.createViewPane(viewerViewForm, MemoryBlocksTreeViewPane.PANE_ID, DebugUIMessages.MemoryView_Memory_monitors);
402         viewerViewForm.setContent(viewerControl);
403         
404         ISelection selection = fMemBlkViewer.getSelectionProvider().getSelection();
405         if (selection != null)
406             fSelectionProvider.setSelection(selection);
407
408         ToolBarManager viewerToolBarMgr = new ToolBarManager(SWT.FLAT);
409         IAction[] actions = fMemBlkViewer.getActions();
410         for (int i=0; i<actions.length; i++)
411         {
412             viewerToolBarMgr.add(actions[i]);
413         }
414         ToolBar viewerToolbar = viewerToolBarMgr.createControl(viewerViewForm);
415         viewerViewForm.setTopRight(viewerToolbar);
416         
417         Label viewerLabel = new Label(viewerViewForm, SWT.WRAP);
418         viewerLabel.setText(DebugUIMessages.MemoryView_Memory_monitors);
419         viewerViewForm.setTopLeft(viewerLabel);
420         
421         fMemBlkViewer.getControl().addFocusListener(new FocusAdapter() {
422             public void focusGained(FocusEvent e) {
423                 fActivePaneId = fMemBlkViewer.getId();
424             }});
425     }
426
427     /**
428      * @return an activate listener for the given view pane
429      *
430      */

431     private Listener createDeactivateListener(final IMemoryViewPane viewPane) {
432         Listener deactivateListener = new Listener() {
433             private String JavaDoc id=viewPane.getId();
434             public void handleEvent(Event event) {
435                 if (fActivePaneId.equals(id))
436                     viewPane.removeSelctionListener(fSelectionProvider);
437             }};
438         return deactivateListener;
439     }
440
441     /**
442      * @return a deactivate listener for the given view pane
443      */

444     private Listener createActivateListener(final IMemoryViewPane viewPane) {
445         Listener activateListener = new Listener() {
446             private String JavaDoc id=viewPane.getId();
447             public void handleEvent(Event event) {
448                 fActivePaneId = id;
449                 viewPane.addSelectionListener(fSelectionProvider);
450                 fSelectionProvider.setSelection(viewPane.getSelectionProvider().getSelection());
451             }};
452         return activateListener;
453     }
454
455     /**
456      *
457      */

458     public void createRenderingViewPane(final String JavaDoc paneId) {
459         final RenderingViewPane renderingPane = new RenderingViewPane(this);
460         fViewPanes.put(paneId, renderingPane);
461         ViewForm renderingViewForm = new ViewForm(fSashForm, SWT.NONE);
462         fViewPaneControls.put(paneId, renderingViewForm);
463         fWeights.add(new Integer JavaDoc(40));
464         
465         Control renderingControl = renderingPane.createViewPane(renderingViewForm, paneId, DebugUIMessages.MemoryView_Memory_renderings);
466         PlatformUI.getWorkbench().getHelpSystem().setHelp(renderingControl, IDebugUIConstants.PLUGIN_ID + ".MemoryView_context"); //$NON-NLS-1$
467
renderingViewForm.setContent(renderingControl);
468         
469         ToolBarManager renderingViewMgr = new ToolBarManager(SWT.FLAT);
470         IAction[] renderingActions = renderingPane.getActions();
471         for (int i=0; i<renderingActions.length; i++)
472         {
473             renderingViewMgr.add(renderingActions[i]);
474         }
475         
476         ToolBar renderingToolbar = renderingViewMgr.createControl(renderingViewForm);
477         renderingViewForm.setTopRight(renderingToolbar);
478         
479         Label renderingLabel = new Label(renderingViewForm, SWT.NONE);
480         renderingLabel.setText(renderingPane.getLabel());
481         renderingViewForm.setTopLeft(renderingLabel);
482         
483         Listener renderingActivateListener = createActivateListener(renderingPane);
484         renderingControl.addListener(SWT.Activate, renderingActivateListener);
485         
486         Listener renderingDeactivateListener = createDeactivateListener(renderingPane);
487         renderingControl.addListener(SWT.Deactivate, renderingDeactivateListener);
488
489     }
490     /* (non-Javadoc)
491      * @see org.eclipse.ui.part.WorkbenchPart#setFocus()
492      */

493     public void setFocus() {
494         if (fActivePaneId == null)
495             fActivePaneId = fMemBlkViewer.getId();
496         
497         IMemoryViewPane pane = getViewPane(fActivePaneId);
498         pane.getControl().setFocus();
499     }
500     
501     public void dispose() {
502         getSite().getPage().removePartListener(fPartListener);
503         
504         Enumeration JavaDoc enumeration = fViewPanes.elements();
505         while (enumeration.hasMoreElements())
506         {
507             Object JavaDoc element = enumeration.nextElement();
508             if (element instanceof IMemoryViewPane)
509             {
510                 ((IMemoryViewPane)element).dispose();
511             }
512         }
513         
514         fViewPaneControls.clear();
515         
516         IViewSite viewSite = getViewSite();
517         String JavaDoc secondaryId = viewSite.getSecondaryId();
518         if (secondaryId != null)
519             MemoryViewIdRegistry.deregisterView(secondaryId);
520         
521         fSyncService.shutdown();
522         
523         if (fAddHandler != null)
524             fAddHandler.dispose();
525         
526         if (fToggleMonitorsHandler != null)
527             fToggleMonitorsHandler.dispose();
528         
529         if (fNextMemoryBlockHandler != null)
530             fNextMemoryBlockHandler.dispose();
531         
532         super.dispose();
533     }
534     
535     private void setVisible(boolean visible)
536     {
537         IMemoryViewPane[] viewPanes = getViewPanes();
538         
539         for (int i=0; i<viewPanes.length; i++)
540         {
541             // if currently visible, take view pane's visibility into account
542
// else force view pane to be visible if it is listed in
543
// "visible view panes" array list.
544
if (fVisible)
545                 viewPanes[i].setVisible(visible && viewPanes[i].isVisible());
546             else
547             {
548                 if (isViewPaneVisible(viewPanes[i].getId()))
549                     viewPanes[i].setVisible(visible);
550             }
551         }
552         
553         fVisible = visible;
554     }
555
556     /* (non-Javadoc)
557      * @see org.eclipse.debug.internal.ui.views.memory.IMultipaneMemoryView#getViewPane(java.lang.String)
558      */

559     public IMemoryViewPane getViewPane(String JavaDoc paneId) {
560         return (IMemoryViewPane)fViewPanes.get(paneId);
561     }
562
563     /* (non-Javadoc)
564      * @see org.eclipse.debug.internal.ui.views.memory.IMultipaneMemoryView#getViewPanes()
565      */

566     public IMemoryViewPane[] getViewPanes() {
567         IMemoryViewPane[] viewPanes = new IMemoryViewPane[fViewPanes.size()];
568
569         Enumeration JavaDoc enumeration = fViewPanes.elements();
570         int i=0;
571         while (enumeration.hasMoreElements())
572         {
573             viewPanes[i] = (IMemoryViewPane)enumeration.nextElement();
574             i++;
575         }
576         
577         return viewPanes;
578     }
579     
580     /**
581      * Restore each view pane from the memory view based on current
582      * debug selection
583      */

584     private void restoreView() {
585         IMemoryViewPane[] viewPanes = getViewPanes();
586         for (int i=0; i<viewPanes.length; i++)
587         {
588             viewPanes[i].restoreViewPane();
589         }
590     }
591     /* (non-Javadoc)
592      * @see org.eclipse.debug.internal.ui.views.memory.IMultipaneMemoryView#showViewPane(boolean, java.lang.String)
593      */

594     public void showViewPane(boolean show, String JavaDoc paneId) {
595         
596         Control viewPaneControl = (Control)fViewPaneControls.get(paneId);
597         
598         if (viewPaneControl != null)
599         {
600             Control children[] = fSashForm.getChildren();
601             
602             for (int i=0; i<children.length; i++)
603             {
604                 if (children[i] == viewPaneControl)
605                 {
606                     children[i].setVisible(show);
607                     IMemoryViewPane viewPane = (IMemoryViewPane)fViewPanes.get(paneId);
608                     if (viewPane != null)
609                         viewPane.setVisible(show);
610                 }
611             }
612             fSashForm.layout();
613         }
614         
615         storeViewPaneVisibility();
616     }
617     /* (non-Javadoc)
618      * @see org.eclipse.debug.internal.ui.views.memory.IMultipaneMemoryView#isViewPaneVisible(java.lang.String)
619      */

620     public boolean isViewPaneVisible(String JavaDoc paneId) {
621         return fVisibleViewPanes.contains(paneId);
622     }
623     
624     private void storeViewPaneVisibility()
625     {
626         fVisibleViewPanes.clear();
627         Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
628         StringBuffer JavaDoc visibleViewPanes= new StringBuffer JavaDoc();
629         
630         Enumeration JavaDoc enumeration = fViewPaneControls.keys();
631         
632         while (enumeration.hasMoreElements())
633         {
634             String JavaDoc paneId = (String JavaDoc)enumeration.nextElement();
635             
636             Control control = (Control)fViewPaneControls.get(paneId);
637             if (control.isVisible())
638             {
639                 visibleViewPanes.append(paneId);
640                 visibleViewPanes.append(","); //$NON-NLS-1$
641
fVisibleViewPanes.add(paneId);
642             }
643         }
644         
645         prefs.setValue(getVisibilityPrefId(), visibleViewPanes.toString());
646     }
647     
648     private void loadViewPanesVisibility()
649     {
650         Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
651         String JavaDoc visiblePanes = prefs.getString(getVisibilityPrefId());
652         
653         if (visiblePanes != null && visiblePanes.length() > 0)
654         {
655             StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(visiblePanes, ","); //$NON-NLS-1$
656
while (tokenizer.hasMoreTokens())
657             {
658                 String JavaDoc paneId = tokenizer.nextToken();
659                 fVisibleViewPanes.add(paneId);
660             }
661         }
662         else
663         {
664             for (int i=0 ;i<defaultVisiblePaneIds.length; i++)
665             {
666                 fVisibleViewPanes.add(defaultVisiblePaneIds[i]);
667             }
668         }
669         
670         Enumeration JavaDoc enumeration = fViewPaneControls.keys();
671         while (enumeration.hasMoreElements())
672         {
673             String JavaDoc paneId = (String JavaDoc)enumeration.nextElement();
674             boolean visible = false;
675             if(fVisibleViewPanes.contains(paneId))
676                 visible = true;
677             
678             Control control = (Control)fViewPaneControls.get(paneId);
679             control.setVisible(visible);
680             
681             IMemoryViewPane viewPane = (IMemoryViewPane)fViewPanes.get(paneId);
682             viewPane.setVisible(visible);
683         }
684         
685         fSashForm.layout();
686     }
687     
688     private void loadOrientation()
689     {
690         Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
691         fViewOrientation = prefs.getInt(getOrientationPrefId());
692         
693         for (int i=0; i<fOrientationActions.length; i++)
694         {
695             if (fOrientationActions[i].getOrientation() == fViewOrientation)
696             {
697                 fOrientationActions[i].run();
698             }
699         }
700         updateOrientationActions();
701     }
702     
703     private void saveOrientation()
704     {
705         Preferences prefs = DebugUIPlugin.getDefault().getPluginPreferences();
706         prefs.setValue(getOrientationPrefId(), fViewOrientation);
707     }
708     
709     private void updateOrientationActions()
710     {
711         for (int i=0; i<fOrientationActions.length; i++)
712         {
713             if (fOrientationActions[i].getOrientation() == fViewOrientation)
714             {
715                 fOrientationActions[i].setChecked(true);
716             }
717             else
718             {
719                 fOrientationActions[i].setChecked(false);
720             }
721             
722         }
723     }
724
725     /* (non-Javadoc)
726      * @see org.eclipse.debug.ui.memory.IMemoryRenderingSite#getSynchronizationService()
727      */

728     public IMemoryRenderingSynchronizationService getSynchronizationService() {
729         return fSyncService;
730     }
731
732     /* (non-Javadoc)
733      * @see org.eclipse.debug.ui.memory.IMemoryRenderingSite#getMemoryRenderingContainers()
734      */

735     public IMemoryRenderingContainer[] getMemoryRenderingContainers() {
736         Enumeration JavaDoc enumeration = fViewPanes.elements();
737         ArrayList JavaDoc containers = new ArrayList JavaDoc();
738         while (enumeration.hasMoreElements()){
739             Object JavaDoc obj = enumeration.nextElement();
740             if (obj instanceof IMemoryRenderingContainer)
741                 containers.add(obj);
742         }
743         
744         return (IMemoryRenderingContainer[])containers.toArray(new IMemoryRenderingContainer[containers.size()]);
745     }
746
747     /* (non-Javadoc)
748      * @see org.eclipse.debug.ui.memory.IMemoryRenderingSite#getContainer(java.lang.String)
749      */

750     public IMemoryRenderingContainer getContainer(String JavaDoc id) {
751         Object JavaDoc viewPane = fViewPanes.get(id);
752         
753         if (viewPane instanceof IMemoryRenderingContainer)
754             return (IMemoryRenderingContainer)viewPane;
755         
756         return null;
757     }
758
759     public boolean isPinMBDisplay() {
760         return fPinMBDisplay;
761     }
762     
763
764     public void setPinMBDisplay(boolean pinMBDisplay) {
765         fPinMBDisplay = pinMBDisplay;
766     }
767     
768     private String JavaDoc getVisibilityPrefId()
769     {
770         IViewSite vs = getViewSite();
771         String JavaDoc viewId = vs.getSecondaryId();
772         
773         if (viewId != null)
774             return VISIBILITY_PREF + "." + viewId; //$NON-NLS-1$
775

776         return VISIBILITY_PREF;
777     }
778     
779     private String JavaDoc getOrientationPrefId()
780     {
781         IViewSite vs = getViewSite();
782         String JavaDoc viewId = vs.getSecondaryId();
783         
784         if (viewId != null)
785             return VIEW_PANE_ORIENTATION_PREF + "." + viewId; //$NON-NLS-1$
786

787         return VIEW_PANE_ORIENTATION_PREF;
788     }
789     
790     private void createOrientationActions()
791     {
792         IActionBars actionBars = getViewSite().getActionBars();
793         IMenuManager viewMenu = actionBars.getMenuManager();
794         
795         fOrientationActions = new ViewPaneOrientationAction[2];
796         fOrientationActions[0] = new ViewPaneOrientationAction(this, HORIZONTAL_VIEW_ORIENTATION);
797         fOrientationActions[1] = new ViewPaneOrientationAction(this, VERTICAL_VIEW_ORIENTATION);
798         
799         viewMenu.add(new Separator());
800         MenuManager layoutSubMenu = new MenuManager(VariablesViewMessages.VariablesView_40);
801         layoutSubMenu.add(fOrientationActions[0]);
802         layoutSubMenu.add(fOrientationActions[1]);
803         viewMenu.add(layoutSubMenu);
804         viewMenu.add(new Separator());
805     }
806     
807     public void setViewPanesOrientation(int orientation)
808     {
809         fViewOrientation = orientation;
810         if (fViewOrientation == VERTICAL_VIEW_ORIENTATION)
811             fSashForm.setOrientation(SWT.VERTICAL);
812         else
813             fSashForm.setOrientation(SWT.HORIZONTAL);
814         
815         saveOrientation();
816         updateOrientationActions();
817     }
818     
819     public int getViewPanesOrientation()
820     {
821         return fViewOrientation;
822     }
823 }
824
Popular Tags