1 11 package org.eclipse.jdt.internal.debug.ui; 12 13 import java.util.HashMap ; 14 import java.util.Iterator ; 15 import java.util.Map ; 16 17 import org.eclipse.jdt.internal.debug.core.HeapWalkingManager; 18 import org.eclipse.jface.preference.PreferencePage; 19 import org.eclipse.swt.events.ModifyEvent; 20 import org.eclipse.swt.events.ModifyListener; 21 import org.eclipse.swt.layout.GridData; 22 import org.eclipse.swt.widgets.Button; 23 import org.eclipse.swt.widgets.Composite; 24 import org.eclipse.swt.widgets.Control; 25 import org.eclipse.swt.widgets.Group; 26 import org.eclipse.swt.widgets.Text; 27 import org.eclipse.ui.IWorkbench; 28 import org.eclipse.ui.IWorkbenchPreferencePage; 29 import org.eclipse.ui.PlatformUI; 30 31 38 public class HeapWalkingPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { 39 40 private Button fShowReferencesInVarView; 41 private Text fAllReferencesMaxCount; 42 private Text fAllInstancesMaxCount; 43 private Map fErrorMessages; 44 45 48 public void init(IWorkbench workbench) { 49 fErrorMessages = new HashMap (); 50 } 51 52 55 public void createControl(Composite parent) { 56 super.createControl(parent); 57 PlatformUI.getWorkbench().getHelpSystem().setHelp(getControl(), IJavaDebugHelpContextIds.JAVA_HEAPWALKING_PREFERENCE_PAGE); 59 } 60 61 64 protected Control createContents(Composite parent) { 65 66 Composite comp = SWTFactory.createComposite(parent, parent.getFont(), 1, 1, GridData.FILL_BOTH); 67 68 SWTFactory.createWrapLabel(comp, DebugUIMessages.HeapWalkingPreferencePage_0, 1, 300); 69 SWTFactory.createVerticalSpacer(comp, 2); 70 71 fShowReferencesInVarView = SWTFactory.createCheckButton(comp, DebugUIMessages.HeapWalkingPreferencePage_5, null, HeapWalkingManager.getDefault().isShowReferenceInVarView(), 1); 72 SWTFactory.createVerticalSpacer(comp, 2); 73 74 Group group = SWTFactory.createGroup(comp, DebugUIMessages.HeapWalkingPreferencePage_3, 2, 1, GridData.FILL_HORIZONTAL); 75 SWTFactory.createLabel(group, DebugUIMessages.HeapWalkingPreferencePage_4, 2); 76 77 SWTFactory.createLabel(group, DebugUIMessages.HeapWalkingPreferencePage_1, 1); 78 fAllInstancesMaxCount = SWTFactory.createSingleText(group, 1); 79 fAllInstancesMaxCount.addModifyListener(new ModifyListener(){ 80 public void modifyText(ModifyEvent e) { 81 try{ 82 int result = Integer.parseInt(fAllInstancesMaxCount.getText()); 83 if (result < 0) throw new NumberFormatException (); 84 clearErrorMessage(fAllInstancesMaxCount); 85 } catch (NumberFormatException exception){ 86 setErrorMessage(fAllInstancesMaxCount, DebugUIMessages.HeapWalkingPreferencePage_6); 87 } 88 } 89 }); 90 fAllInstancesMaxCount.setText("" + HeapWalkingManager.getDefault().getAllInstancesMaxCount()); 92 SWTFactory.createLabel(group, DebugUIMessages.HeapWalkingPreferencePage_2, 1); 93 fAllReferencesMaxCount = SWTFactory.createSingleText(group, 1); 94 fAllReferencesMaxCount.addModifyListener(new ModifyListener(){ 95 public void modifyText(ModifyEvent e) { 96 try{ 97 int result = Integer.parseInt(fAllReferencesMaxCount.getText()); 98 if (result < 0) throw new NumberFormatException (); 99 clearErrorMessage(fAllReferencesMaxCount); 100 } catch (NumberFormatException exception){ 101 setErrorMessage(fAllReferencesMaxCount, DebugUIMessages.HeapWalkingPreferencePage_6); 102 } 103 } 104 }); 105 fAllReferencesMaxCount.setText("" + HeapWalkingManager.getDefault().getAllReferencesMaxCount()); 107 return comp; 108 } 109 110 113 public boolean performOk() { 114 boolean result = super.performOk(); 115 if (result){ 116 HeapWalkingManager.getDefault().setShowReferenceInVarView(fShowReferencesInVarView.getSelection()); 117 try{ 118 int maxReferences = Integer.parseInt(fAllReferencesMaxCount.getText()); 119 HeapWalkingManager.getDefault().setAllReferencesMaxCount(maxReferences); 120 } catch (NumberFormatException exception){ 121 setErrorMessage(fAllReferencesMaxCount,DebugUIMessages.HeapWalkingPreferencePage_6); 122 return false; 123 } 124 try{ 125 int maxReferences = Integer.parseInt(fAllInstancesMaxCount.getText()); 126 HeapWalkingManager.getDefault().setAllInstancesMaxCount(maxReferences); 127 } catch (NumberFormatException exception){ 128 setErrorMessage(fAllInstancesMaxCount,DebugUIMessages.HeapWalkingPreferencePage_6); 129 result = false; 130 } 131 HeapWalkingManager.getDefault().setShowReferenceInVarView(fShowReferencesInVarView.getSelection()); 132 } 133 return result; 134 } 135 136 144 private void setErrorMessage(Object cause, String message){ 145 fErrorMessages.put(cause,message); 146 setErrorMessage(message); 147 setValid(false); 148 } 149 150 157 private void clearErrorMessage(Object cause){ 158 fErrorMessages.remove(cause); 159 Iterator iter = fErrorMessages.values().iterator(); 160 if (iter.hasNext()){ 161 setErrorMessage((String )iter.next()); 162 } else { 163 setErrorMessage(null); 164 setValid(true); 165 } 166 } 167 168 171 protected void performDefaults() { 172 HeapWalkingManager.getDefault().resetToDefaultSettings(); 173 fAllReferencesMaxCount.setText(Integer.toString(HeapWalkingManager.getDefault().getAllReferencesMaxCount())); 174 fAllInstancesMaxCount.setText(Integer.toString(HeapWalkingManager.getDefault().getAllReferencesMaxCount())); 175 fShowReferencesInVarView.setSelection(HeapWalkingManager.getDefault().isShowReferenceInVarView()); 176 } 177 178 181 public void dispose() { 182 super.dispose(); 183 fErrorMessages.clear(); 184 } 185 186 } 187 | Popular Tags |