1 12 package org.eclipse.jdt.internal.ui.callhierarchy; 13 14 import org.eclipse.swt.SWT; 15 import org.eclipse.swt.events.ModifyEvent; 16 import org.eclipse.swt.events.ModifyListener; 17 import org.eclipse.swt.events.SelectionAdapter; 18 import org.eclipse.swt.events.SelectionEvent; 19 import org.eclipse.swt.layout.GridData; 20 import org.eclipse.swt.layout.GridLayout; 21 import org.eclipse.swt.widgets.Button; 22 import org.eclipse.swt.widgets.Composite; 23 import org.eclipse.swt.widgets.Control; 24 import org.eclipse.swt.widgets.Label; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.swt.widgets.Text; 27 28 import org.eclipse.jface.dialogs.IDialogConstants; 29 import org.eclipse.jface.dialogs.StatusDialog; 30 31 import org.eclipse.ui.PlatformUI; 32 33 import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; 34 import org.eclipse.jdt.internal.ui.dialogs.StatusInfo; 35 36 import org.eclipse.jdt.internal.corext.callhierarchy.CallHierarchy; 37 38 class FiltersDialog extends StatusDialog { 39 private Label fNamesHelpText; 40 private Button fFilterOnNames; 41 private Text fNames; 42 private Text fMaxCallDepth; 43 44 47 protected FiltersDialog(Shell parentShell) { 48 super(parentShell); 49 } 50 51 54 protected void configureShell(Shell newShell) { 55 super.configureShell(newShell); 56 newShell.setText(CallHierarchyMessages.FiltersDialog_filter); 57 PlatformUI.getWorkbench().getHelpSystem().setHelp(newShell, IJavaHelpContextIds.CALL_HIERARCHY_FILTERS_DIALOG); 58 } 59 60 63 protected Control createDialogArea(Composite parent) { 64 Composite superComposite = (Composite) super.createDialogArea(parent); 65 66 Composite composite = new Composite(superComposite, SWT.NONE); 67 composite.setFont(superComposite.getFont()); 68 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 69 70 GridLayout layout = new GridLayout(); 71 layout.marginHeight= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); 72 layout.marginWidth= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); 73 layout.verticalSpacing= convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); 74 layout.horizontalSpacing= convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); 75 composite.setLayout(layout); 76 77 createNamesArea(composite); 78 new Label(composite, SWT.NONE); createMaxCallDepthArea(composite); 80 81 updateUIFromFilter(); 82 83 return composite; 84 } 85 86 private void createMaxCallDepthArea(Composite parent) { 87 Composite composite= new Composite(parent, SWT.NONE); 88 composite.setFont(parent.getFont()); 89 GridLayout layout = new GridLayout(); 90 layout.numColumns = 2; 91 composite.setLayout(layout); 92 93 Label label= new Label(composite, SWT.NONE); 94 label.setFont(composite.getFont()); 95 label.setText(CallHierarchyMessages.FiltersDialog_maxCallDepth); 96 97 fMaxCallDepth = new Text(composite, SWT.SINGLE | SWT.BORDER); 98 fMaxCallDepth.setFont(composite.getFont()); 99 fMaxCallDepth.setTextLimit(6); 100 fMaxCallDepth.addModifyListener(new ModifyListener() { 101 public void modifyText(ModifyEvent e) { 102 validateInput(); 103 } 104 }); 105 106 GridData gridData = new GridData(); 107 gridData.widthHint = convertWidthInCharsToPixels(10); 108 fMaxCallDepth.setLayoutData(gridData); 109 } 110 111 private void createNamesArea(Composite parent) { 112 fFilterOnNames = createCheckbox(parent, 113 CallHierarchyMessages.FiltersDialog_filterOnNames, true); 114 115 fNames= new Text(parent, SWT.SINGLE | SWT.BORDER); 116 fNames.setFont(parent.getFont()); 117 fNames.addModifyListener(new ModifyListener() { 118 public void modifyText(ModifyEvent e) { 119 validateInput(); 120 } 121 }); 122 123 GridData gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.GRAB_HORIZONTAL); 124 gridData.widthHint = convertWidthInCharsToPixels(60); 125 fNames.setLayoutData(gridData); 126 127 fNamesHelpText= new Label(parent, SWT.LEFT); 128 fNamesHelpText.setFont(parent.getFont()); 129 fNamesHelpText.setText(CallHierarchyMessages.FiltersDialog_filterOnNamesSubCaption); 130 } 131 132 142 private Button createCheckbox(Composite parent, String text, boolean grabRow) { 143 Button button = new Button(parent, SWT.CHECK); 144 button.setFont(parent.getFont()); 145 146 if (grabRow) { 147 GridData gridData = new GridData(GridData.FILL_HORIZONTAL); 148 button.setLayoutData(gridData); 149 } 150 151 button.setText(text); 152 button.addSelectionListener(new SelectionAdapter() { 153 public void widgetSelected(SelectionEvent e) { 154 validateInput(); 155 updateEnabledState(); 156 } 157 }); 158 159 return button; 160 } 161 162 165 private void updateEnabledState() { 166 fNames.setEnabled(fFilterOnNames.getSelection()); 167 fNamesHelpText.setEnabled(fFilterOnNames.getSelection()); 168 } 169 170 173 private void updateFilterFromUI() { 174 int maxCallDepth = Integer.parseInt(this.fMaxCallDepth.getText()); 175 176 CallHierarchyUI.getDefault().setMaxCallDepth(maxCallDepth); 177 CallHierarchy.getDefault().setFilters(fNames.getText()); 178 CallHierarchy.getDefault().setFilterEnabled(fFilterOnNames.getSelection()); 179 } 180 181 184 private void updateUIFromFilter() { 185 fMaxCallDepth.setText(String.valueOf(CallHierarchyUI.getDefault().getMaxCallDepth())); 186 fNames.setText(CallHierarchy.getDefault().getFilters()); 187 fFilterOnNames.setSelection(CallHierarchy.getDefault().isFilterEnabled()); 188 updateEnabledState(); 189 } 190 191 197 protected void okPressed() { 198 if (!isMaxCallDepthValid()) { 199 if (fMaxCallDepth.forceFocus()) { 200 fMaxCallDepth.setSelection(0, fMaxCallDepth.getCharCount()); 201 fMaxCallDepth.showSelection(); 202 } 203 } 204 205 updateFilterFromUI(); 206 super.okPressed(); 207 } 208 209 private boolean isMaxCallDepthValid() { 210 String text= fMaxCallDepth.getText(); 211 if (text.length() == 0) 212 return false; 213 214 try { 215 int maxCallDepth= Integer.parseInt(text); 216 217 return (maxCallDepth >= 1 && maxCallDepth <= 99); 218 } catch (NumberFormatException e) { 219 return false; 220 } 221 } 222 223 private void validateInput() { 224 StatusInfo status= new StatusInfo(); 225 if (!isMaxCallDepthValid()) { 226 status.setError(CallHierarchyMessages.FiltersDialog_messageMaxCallDepthInvalid); 227 } 228 updateStatus(status); 229 } 230 } 231 | Popular Tags |