1 11 package org.eclipse.jdt.internal.debug.ui.propertypages; 12 13 import java.util.ArrayList ; 14 import java.util.List ; 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 47 public class VMCapabilitiesPropertyPage extends PropertyPage { 48 49 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 fExpandedComps; 65 private static final String EXPANDED_STATE = "vmc_expanded_state"; private static Font fHeadingFont = JFaceResources.getFontRegistry().getBold(JFaceResources.DIALOG_FONT); 67 68 71 public VMCapabilitiesPropertyPage() { 72 fExpandedComps = new ArrayList (); 73 } 74 75 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 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 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 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 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()); text.setBackground(parent.getBackground()); 156 } 157 158 161 public void createControl(Composite parent) { 162 super.createControl(parent); 163 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.VMCAPABILITIES_PROPERTY_PAGE); 164 } 165 166 170 private VirtualMachineImpl getVM() { 171 Object 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 195 private void createCapabilityEntry(Composite parent, String label, boolean enabled) { 196 SWTFactory.createCheckButton(parent, null, null, enabled, 1).setEnabled(false); 197 SWTFactory.createLabel(parent, label, parent.getFont(), 1); 198 } 199 200 209 private ExpandableComposite createExpandibleComposite(Composite parent, int style, String 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 225 protected IPreferenceStore doGetPreferenceStore() { 226 return JDIDebugUIPlugin.getDefault().getPreferenceStore(); 227 } 228 229 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 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 261 public boolean performOk() { 262 boolean ok = super.performOk(); 263 persistExpansionState(); 264 return ok; 265 } 266 267 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 |