KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > core > HeapWalkingManager


1 /*******************************************************************************
2  * Copyright (c) 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.jdt.internal.debug.core;
12
13 import org.eclipse.debug.core.model.IDebugElement;
14 import org.eclipse.debug.core.model.IDebugTarget;
15 import org.eclipse.jdt.debug.core.IJavaDebugTarget;
16
17 /**
18  * Controls preferences related to heap walking so that they are available in java
19  * debug model code, but can be updated through the UI.
20  *
21  * @since 3.3
22  */

23 public class HeapWalkingManager{
24     
25     private static HeapWalkingManager fgSingleton;
26     
27     /**
28      * Constructor. Intended to be called by getDefault()
29      */

30     protected HeapWalkingManager() {}
31     
32     /**
33      * Returns whether the given parent object is a debug element with a debug target
34      * that supports retrieval of instance and reference information from the VM.
35      *
36      * @param object the object to test, can be <code>null</code>
37      * @return whether the given object has a debug target that supports heap walking
38      */

39     public static boolean supportsHeapWalking(Object JavaDoc object){
40         if (object instanceof IDebugElement){
41             IDebugTarget target = ((IDebugElement)object).getDebugTarget();
42             if (target instanceof IJavaDebugTarget){
43                 return ((IJavaDebugTarget)target).supportsInstanceRetrieval();
44             }
45         }
46         return false;
47     }
48     
49     /**
50      * @return the default singleton instance of the manager
51      */

52     public static HeapWalkingManager getDefault() {
53         if (fgSingleton == null){
54             fgSingleton = new HeapWalkingManager();
55         }
56         return fgSingleton;
57     }
58     
59     /**
60      * @return preference dictating whether to display references as variables in variables view.
61      */

62     public boolean isShowReferenceInVarView() {
63         return JDIDebugPlugin.getDefault().getPluginPreferences().getBoolean(JDIDebugPlugin.PREF_SHOW_REFERENCES_IN_VAR_VIEW);
64     }
65     
66     /**
67      * @return preference dictating the maximum number of references that should be displayed to the user
68      */

69     public int getAllReferencesMaxCount() {
70         return JDIDebugPlugin.getDefault().getPluginPreferences().getInt(JDIDebugPlugin.PREF_ALL_REFERENCES_MAX_COUNT);
71     }
72     
73     /**
74      * @return preference dictating the maximum number of instances that should be displayed to the user
75      */

76     public int getAllInstancesMaxCount() {
77         return JDIDebugPlugin.getDefault().getPluginPreferences().getInt(JDIDebugPlugin.PREF_ALL_INSTANCES_MAX_COUNT);
78     }
79     
80     /**
81      * Stores the passed vale in the preference store
82      *
83      * @param value whether to display references as variables in the variables view
84      */

85     public void setShowReferenceInVarView(boolean value) {
86         JDIDebugPlugin.getDefault().getPluginPreferences().setValue(JDIDebugPlugin.PREF_SHOW_REFERENCES_IN_VAR_VIEW,value);
87     }
88     
89     /**
90      * Stores the passed value in the preference store
91      *
92      * @param max the maximum number of references that should be displayed to the user
93      */

94     public void setAllReferencesMaxCount(int max){
95         JDIDebugPlugin.getDefault().getPluginPreferences().setValue(JDIDebugPlugin.PREF_ALL_REFERENCES_MAX_COUNT, max);
96     }
97     
98     /**
99      * Stores the passed value in the preference store
100      *
101      * @param max the maximum number of instances that should be displayed to the user
102      */

103     public void setAllInstancesMaxCount(int max){
104         JDIDebugPlugin.getDefault().getPluginPreferences().setValue(JDIDebugPlugin.PREF_ALL_INSTANCES_MAX_COUNT, max);
105     }
106     
107     /**
108      * Resets the preferences controlled by this manager to their default settings
109      */

110     public void resetToDefaultSettings(){
111         JDIDebugPlugin.getDefault().getPluginPreferences().setToDefault(JDIDebugPlugin.PREF_SHOW_REFERENCES_IN_VAR_VIEW);
112         JDIDebugPlugin.getDefault().getPluginPreferences().setToDefault(JDIDebugPlugin.PREF_ALL_REFERENCES_MAX_COUNT);
113         JDIDebugPlugin.getDefault().getPluginPreferences().setToDefault(JDIDebugPlugin.PREF_ALL_INSTANCES_MAX_COUNT);
114     }
115     
116 }
117
Popular Tags