KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > debug > ui > propertypages > VMCapabilitiesPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2006, 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.ui.propertypages;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15
16 import org.eclipse.debug.core.model.IDebugElement;
17 import org.eclipse.debug.core.model.IDebugTarget;
18 import org.eclipse.debug.core.model.IProcess;
19 import org.eclipse.jdi.internal.VirtualMachineImpl;
20 import org.eclipse.jdt.internal.debug.core.model.JDIDebugTarget;
21 import org.eclipse.jdt.internal.debug.ui.IJavaDebugHelpContextIds;
22 import org.eclipse.jdt.internal.debug.ui.JDIDebugUIPlugin;
23 import org.eclipse.jdt.internal.debug.ui.SWTFactory;
24 import org.eclipse.jface.preference.IPreferenceStore;
25 import org.eclipse.jface.resource.JFaceResources;
26 import org.eclipse.swt.SWT;
27 import org.eclipse.swt.graphics.Font;
28 import org.eclipse.swt.layout.GridData;
29 import org.eclipse.swt.layout.GridLayout;
30 import org.eclipse.swt.widgets.Composite;
31 import org.eclipse.swt.widgets.Control;
32 import org.eclipse.swt.widgets.Label;
33 import org.eclipse.swt.widgets.Text;
34 import org.eclipse.ui.PlatformUI;
35 import org.eclipse.ui.dialogs.PropertyPage;
36 import org.eclipse.ui.forms.events.ExpansionAdapter;
37 import org.eclipse.ui.forms.events.ExpansionEvent;
38 import org.eclipse.ui.forms.widgets.ExpandableComposite;
39 import org.eclipse.ui.forms.widgets.SharedScrolledComposite;
40
41 /**
42  * This class provides a properties page displaying all of the capabilities
43  * of the VM associated with the selected <code>IDebugTarget</code> or <code>IProcess</code>
44  *
45  * @since 3.3
46  */

47 public class VMCapabilitiesPropertyPage extends PropertyPage {
48
49     /**
50      * Provides a scrollable area for the expansion composites
51      */

52     class ScrollPain extends SharedScrolledComposite {
53         public ScrollPain(Composite parent) {
54             super(parent, SWT.V_SCROLL | SWT.H_SCROLL);
55             setExpandHorizontal(true);
56             setExpandVertical(true);
57             GridLayout layout = new GridLayout(1, false);
58             layout.marginHeight = 0;
59             layout.marginWidth = 0;
60             setLayout(layout);
61         }
62     }
63     
64     private List JavaDoc fExpandedComps;
65     private static final String JavaDoc EXPANDED_STATE = "vmc_expanded_state"; //$NON-NLS-1$
66
private static Font fHeadingFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT);
67     
68     /**
69      * Constructor
70      */

71     public VMCapabilitiesPropertyPage() {
72         fExpandedComps = new ArrayList JavaDoc();
73     }
74
75     /* (non-Javadoc)
76      * @see org.eclipse.jface.preference.PreferencePage#createContents(org.eclipse.swt.widgets.Composite)
77      */

78     protected Control createContents(Composite parent) {
79         noDefaultAndApplyButton();
80         final ScrollPain scomp = new ScrollPain(parent);
81         GridData gd = new GridData(GridData.FILL_BOTH);
82         scomp.setLayout(new GridLayout());
83         scomp.setLayoutData(gd);
84         final Composite comp = new Composite(scomp, SWT.NONE);
85         comp.setLayout(new GridLayout(2, true));
86         gd = new GridData(GridData.FILL_BOTH);
87         comp.setLayoutData(gd);
88         scomp.setContent(comp);
89         VirtualMachineImpl vm = getVM();
90         if(vm == null) {
91             setErrorMessage(PropertyPageMessages.VMCapabilitiesPropertyPage_0);
92         }
93         else {
94             createExplanation(comp);
95             SWTFactory.createVerticalSpacer(comp, 1);
96             createHeadingLabel(comp, vm);
97             SWTFactory.createVerticalSpacer(comp, 1);
98             
99             // breakpoints
100
ExpandableComposite breakpoints = createExpandibleComposite(comp, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT, PropertyPageMessages.VMCapabilitiesPropertyPage_27, 2, GridData.FILL_HORIZONTAL);
101             fExpandedComps.add(breakpoints);
102             Composite bp_inner = SWTFactory.createComposite(breakpoints, comp.getFont(), 2, 2, GridData.FILL_HORIZONTAL);
103             breakpoints.setClient(bp_inner);
104             createCapabilityEntry(bp_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_4, vm.canUseInstanceFilters());
105             createCapabilityEntry(bp_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_9, vm.canWatchFieldModification());
106             createCapabilityEntry(bp_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_10, vm.canWatchFieldAccess());
107             createCapabilityEntry(bp_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_24, vm.canGetMethodReturnValues());
108             createCapabilityEntry(bp_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_25, vm.canRequestMonitorEvents());
109             
110             // hot code replace
111
ExpandableComposite hcr = createExpandibleComposite(comp, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT, PropertyPageMessages.VMCapabilitiesPropertyPage_28, 2, GridData.FILL_HORIZONTAL);
112             fExpandedComps.add(hcr);
113             Composite hcr_inner = SWTFactory.createComposite(hcr, comp.getFont(), 2, 2, GridData.FILL_HORIZONTAL);
114             hcr.setClient(hcr_inner);
115             createCapabilityEntry(hcr_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_15, vm.canRedefineClasses());
116             createCapabilityEntry(hcr_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_12, vm.canAddMethod());
117             createCapabilityEntry(hcr_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_16, vm.canUnrestrictedlyRedefineClasses());
118             
119             // stepping
120
ExpandableComposite stepping = createExpandibleComposite(comp, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT, PropertyPageMessages.VMCapabilitiesPropertyPage_29, 2, GridData.FILL_HORIZONTAL);
121             fExpandedComps.add(stepping);
122             Composite stepping_inner = SWTFactory.createComposite(stepping, comp.getFont(), 2, 2, GridData.FILL_HORIZONTAL);
123             stepping.setClient(stepping_inner);
124             createCapabilityEntry(stepping_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_14, vm.canPopFrames());
125             createCapabilityEntry(stepping_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_3, vm.canGetSyntheticAttribute());
126             createCapabilityEntry(stepping_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_21, vm.canForceEarlyReturn());
127             
128             // others
129
ExpandableComposite general = createExpandibleComposite(comp, ExpandableComposite.TWISTIE | ExpandableComposite.CLIENT_INDENT, PropertyPageMessages.VMCapabilitiesPropertyPage_30, 2, GridData.FILL_HORIZONTAL);
130             fExpandedComps.add(general);
131             Composite general_inner = SWTFactory.createComposite(general, comp.getFont(), 2, 2, GridData.FILL_HORIZONTAL);
132             general.setClient(general_inner);
133             createCapabilityEntry(general_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_6, vm.canGetCurrentContendedMonitor() && vm.canGetOwnedMonitorInfo());
134             createCapabilityEntry(general_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_18, vm.canSetDefaultStratum());
135             createCapabilityEntry(general_inner, PropertyPageMessages.VMCapabilitiesPropertyPage_26, vm.canGetInstanceInfo());
136             
137             restoreExpansionState();
138         }
139         applyDialogFont(comp);
140         return comp;
141     }
142     
143     private void createExplanation(Composite parent) {
144         Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 2, GridData.FILL_HORIZONTAL);
145         Label label = new Label(comp, SWT.WRAP);
146         label.setFont(parent.getFont());
147         label.setText(PropertyPageMessages.VMCapabilitiesPropertyPage_31);
148         label.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
149     }
150     
151     private void createHeadingLabel(Composite parent, VirtualMachineImpl vm) {
152         Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 2, 2, GridData.FILL_HORIZONTAL);
153         SWTFactory.createLabel(comp, PropertyPageMessages.VMCapabilitiesPropertyPage_1, fHeadingFont, 1);
154         Text text = SWTFactory.createText(comp, SWT.READ_ONLY, 1, vm.name()+" "+vm.version()); //$NON-NLS-1$
155
text.setBackground(parent.getBackground());
156     }
157     
158     /* (non-Javadoc)
159      * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
160      */

161     public void createControl(Composite parent) {
162         super.createControl(parent);
163         PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.VMCAPABILITIES_PROPERTY_PAGE);
164     }
165     
166     /**
167      * Returns the VM from the debug target
168      * @return the VM form the element
169      */

170     private VirtualMachineImpl getVM() {
171         Object JavaDoc obj = getElement();
172         IDebugTarget target = null;
173         if(obj instanceof IDebugElement) {
174             target = (IDebugTarget) ((IDebugElement)obj).getAdapter(IDebugTarget.class);
175         }
176         else if(obj instanceof IProcess) {
177             target = (IDebugTarget) ((IProcess)obj).getAdapter(IDebugTarget.class);
178         }
179         if(target != null) {
180             if(!target.isTerminated() && !target.isDisconnected()) {
181                 if(target instanceof JDIDebugTarget) {
182                     return (VirtualMachineImpl) ((JDIDebugTarget)target).getVM();
183                 }
184             }
185         }
186         return null;
187     }
188     
189     /**
190      * Returns a new capability entry for a specified group
191      * @param parent the parent group to add this entry to
192      * @param label the text for the label
193      * @param enabled the checked state of the check button
194      */

195     private void createCapabilityEntry(Composite parent, String JavaDoc label, boolean enabled) {
196         SWTFactory.createCheckButton(parent, null, null, enabled, 1).setEnabled(false);
197         SWTFactory.createLabel(parent, label, parent.getFont(), 1);
198     }
199     
200     /**
201      * Creates an ExpandibleComposite widget
202      * @param parent the parent to add this widget to
203      * @param style the style for ExpandibleComposite expanding handle, and layout
204      * @param label the label for the widget
205      * @param hspan how many columns to span in the parent
206      * @param fill the fill style for the widget
207      * @return a new ExpandibleComposite widget
208      */

209     private ExpandableComposite createExpandibleComposite(Composite parent, int style, String JavaDoc label, int hspan, int fill) {
210         ExpandableComposite ex = SWTFactory.createExpandibleComposite(parent, style, label, hspan, fill);
211         ex.addExpansionListener(new ExpansionAdapter() {
212             public void expansionStateChanged(ExpansionEvent e) {
213                 ScrollPain sp = getParentScrollPane((ExpandableComposite) e.getSource());
214                 if(sp != null) {
215                     sp.reflow(true);
216                 }
217             }
218         });
219         return ex;
220     }
221     
222     /* (non-Javadoc)
223      * @see org.eclipse.jface.preference.PreferencePage#doGetPreferenceStore()
224      */

225     protected IPreferenceStore doGetPreferenceStore() {
226         return JDIDebugUIPlugin.getDefault().getPreferenceStore();
227     }
228     
229     /**
230      * save the expansion state for next time, this only happens when the user selects the OK button when closing the dialog
231      */

232     private void persistExpansionState() {
233         IPreferenceStore store = getPreferenceStore();
234         if(store != null) {
235             for (int i = 0; i < fExpandedComps.size(); i++) {
236                 store.setValue(EXPANDED_STATE+i, ((ExpandableComposite) fExpandedComps.get(i)).isExpanded());
237             }
238         }
239     }
240     
241     /**
242      * restore the expansion state
243      */

244     private void restoreExpansionState() {
245         IPreferenceStore store = getPreferenceStore();
246         if(store == null) {
247             ((ExpandableComposite)fExpandedComps.get(0)).setExpanded(true);
248         }
249         else {
250             ExpandableComposite ex;
251             for (int i = 0; i < fExpandedComps.size(); i++) {
252                 ex = (ExpandableComposite) fExpandedComps.get(i);
253                 ex.setExpanded(store.getBoolean(EXPANDED_STATE+i));
254             }
255         }
256     }
257         
258     /* (non-Javadoc)
259      * @see org.eclipse.jface.preference.PreferencePage#performOk()
260      */

261     public boolean performOk() {
262         boolean ok = super.performOk();
263         persistExpansionState();
264         return ok;
265     }
266
267     /**
268      * Finds the parent ScrollPain that needs to be notified that it should reFlow to show the new elements
269      * @param comp the initial comp
270      * @return the parent or null, in this case though, we will never return null
271      */

272     private ScrollPain getParentScrollPane(Composite comp) {
273         Control parent = comp.getParent();
274         while(parent != null && !(parent instanceof ScrollPain)) {
275             parent = parent.getParent();
276         }
277         if(parent != null) {
278             return (ScrollPain)parent;
279         }
280         return null;
281     }
282 }
283
Popular Tags