1 11 12 package org.eclipse.ui.views.markers.internal; 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.events.SelectionListener; 20 import org.eclipse.swt.events.TraverseEvent; 21 import org.eclipse.swt.events.TraverseListener; 22 import org.eclipse.swt.layout.GridData; 23 import org.eclipse.swt.layout.GridLayout; 24 import org.eclipse.swt.widgets.Button; 25 import org.eclipse.swt.widgets.Combo; 26 import org.eclipse.swt.widgets.Composite; 27 import org.eclipse.swt.widgets.Label; 28 import org.eclipse.swt.widgets.Shell; 29 import org.eclipse.swt.widgets.Text; 30 31 public class DialogTaskFilter extends 32 org.eclipse.ui.views.markers.internal.DialogMarkerFilter { 33 34 private DescriptionGroup descriptionGroup; 35 36 private PriorityGroup priorityGroup; 37 38 private StatusGroup statusGroup; 39 40 private class DescriptionGroup { 41 private Label descriptionLabel; 42 43 private Combo combo; 44 45 private Text description; 46 47 private String contains = MarkerMessages.filtersDialog_contains; 48 49 private String doesNotContain = MarkerMessages.filtersDialog_doesNotContain; 50 51 56 public DescriptionGroup(Composite parent) { 57 descriptionLabel = new Label(parent, SWT.NONE); 58 descriptionLabel.setFont(parent.getFont()); 59 descriptionLabel.setText( 60 MarkerMessages.filtersDialog_descriptionLabel); 61 62 combo = new Combo(parent, SWT.READ_ONLY); 63 combo.setFont(parent.getFont()); 64 combo.add(contains); 65 combo.add(doesNotContain); 66 combo.addSelectionListener(new SelectionAdapter(){ 67 70 public void widgetSelected(SelectionEvent e) { 71 updateForSelection(); 72 } 73 }); 74 combo.addTraverseListener(new TraverseListener() { 77 public void keyTraversed(TraverseEvent e) { 78 if (e.detail == SWT.TRAVERSE_ESCAPE 79 || e.detail == SWT.TRAVERSE_RETURN) { 80 e.doit = false; 81 } 82 } 83 }); 84 85 description = new Text(parent, SWT.SINGLE | SWT.BORDER); 86 description.setFont(parent.getFont()); 87 GridData data = new GridData(GridData.FILL_HORIZONTAL); 88 data.horizontalSpan = 3; 89 description.setLayoutData(data); 90 description.addModifyListener(new ModifyListener() { 91 public void modifyText(ModifyEvent e) { 92 DialogTaskFilter.this.markDirty(); 93 } 94 }); 95 } 96 97 public boolean getContains() { 98 return combo.getSelectionIndex() == combo.indexOf(contains); 99 } 100 101 public void setContains(boolean value) { 102 if (value) { 103 combo.select(combo.indexOf(contains)); 104 } else { 105 combo.select(combo.indexOf(doesNotContain)); 106 } 107 } 108 109 public void setDescription(String text) { 110 if (text == null) { 111 description.setText(""); } else { 113 description.setText(text); 114 } 115 } 116 117 public String getDescription() { 118 return description.getText(); 119 } 120 121 125 public void updateEnablement(boolean enabled) { 126 descriptionLabel.setEnabled(enabled); 127 combo.setEnabled(enabled); 128 description.setEnabled(enabled); 129 } 130 } 131 132 private class PriorityGroup { 133 private Button enablementButton; 134 135 private Button highButton; 136 137 private Button normalButton; 138 139 private Button lowButton; 140 141 146 public PriorityGroup(Composite parent) { 147 SelectionListener listener = new SelectionAdapter() { 148 153 public void widgetSelected(SelectionEvent e) { 154 updateEnablement(true); 155 DialogTaskFilter.this.markDirty(); 156 } 157 }; 158 159 enablementButton = new Button(parent, SWT.CHECK); 160 GridData data = new GridData(GridData.FILL_HORIZONTAL); 161 data.horizontalSpan = 2; 162 enablementButton.setLayoutData(data); 163 enablementButton.setFont(parent.getFont()); 164 enablementButton.setText( 165 MarkerMessages.filtersDialog_priorityLabel); 166 enablementButton.addSelectionListener(listener); 167 168 highButton = new Button(parent, SWT.CHECK); 169 highButton.setFont(parent.getFont()); 170 highButton 171 .setText(MarkerMessages.filtersDialog_priorityHigh); 172 highButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 173 highButton.addSelectionListener(new SelectionAdapter(){ 174 177 public void widgetSelected(SelectionEvent e) { 178 updateForSelection(); 179 } 180 }); 181 182 normalButton = new Button(parent, SWT.CHECK); 183 normalButton.setFont(parent.getFont()); 184 normalButton.setText(MarkerMessages.filtersDialog_priorityNormal); 185 normalButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 186 normalButton.addSelectionListener(new SelectionAdapter(){ 187 190 public void widgetSelected(SelectionEvent e) { 191 updateForSelection(); 192 } 193 }); 194 195 lowButton = new Button(parent, SWT.CHECK); 196 lowButton.setFont(parent.getFont()); 197 lowButton.setText(MarkerMessages.filtersDialog_priorityLow); 198 lowButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 199 lowButton.addSelectionListener(new SelectionAdapter(){ 200 203 public void widgetSelected(SelectionEvent e) { 204 updateForSelection(); 205 } 206 }); 207 } 208 209 public boolean isPriorityEnabled() { 210 return enablementButton.getSelection(); 211 } 212 213 public void setEnabled(boolean enabled) { 214 enablementButton.setSelection(enabled); 215 } 216 217 public boolean isHighSelected() { 218 return highButton.getSelection(); 219 } 220 221 public void setHighSelected(boolean selected) { 222 highButton.setSelection(selected); 223 } 224 225 public boolean isNormalSelected() { 226 return normalButton.getSelection(); 227 } 228 229 public void setNormalSelected(boolean selected) { 230 normalButton.setSelection(selected); 231 } 232 233 public boolean isLowSelected() { 234 return lowButton.getSelection(); 235 } 236 237 public void setLowSelected(boolean selected) { 238 lowButton.setSelection(selected); 239 } 240 241 245 public void updateEnablement(boolean enabled) { 246 enablementButton.setEnabled(enabled); 247 highButton.setEnabled(enabled && isPriorityEnabled()); 248 normalButton 249 .setEnabled(enabled && isPriorityEnabled()); 250 lowButton.setEnabled(enabled && isPriorityEnabled()); 251 } 252 } 253 254 private class StatusGroup { 255 private Button enablementButton; 256 257 private Button completeButton; 258 259 private Button incompleteButton; 260 261 266 public StatusGroup(Composite parent) { 267 SelectionListener enablementListener = new SelectionAdapter() { 268 public void widgetSelected(SelectionEvent e) { 269 updateEnablement(true); 270 DialogTaskFilter.this.markDirty(); 271 } 272 }; 273 274 enablementButton = new Button(parent, SWT.CHECK); 275 GridData data = new GridData(GridData.FILL_HORIZONTAL); 276 data.horizontalSpan = 2; 277 enablementButton.setLayoutData(data); 278 enablementButton.setFont(parent.getFont()); 279 enablementButton.setText(MarkerMessages.filtersDialog_statusLabel); 280 enablementButton.addSelectionListener(enablementListener); 281 282 Composite composite = new Composite(parent, SWT.NONE); 283 composite.setFont(parent.getFont()); 284 GridLayout layout = new GridLayout(2, false); 285 layout.marginHeight = 0; 286 layout.marginWidth = 0; 287 composite.setLayout(layout); 288 data = new GridData(GridData.FILL_HORIZONTAL); 289 data.horizontalSpan = 3; 290 composite.setLayoutData(data); 291 292 SelectionListener listener = new SelectionAdapter() { 293 public void widgetSelected(SelectionEvent e) { 294 completeButton.setSelection(!incompleteButton 295 .getSelection()); 296 incompleteButton.setSelection(!completeButton 297 .getSelection()); 298 DialogTaskFilter.this.markDirty(); 299 } 300 }; 301 302 completeButton = new Button(composite, SWT.RADIO); 303 completeButton.setFont(composite.getFont()); 304 completeButton.setText(MarkerMessages.filtersDialog_statusComplete); 305 completeButton.addSelectionListener(listener); 306 307 incompleteButton = new Button(composite, SWT.RADIO); 308 incompleteButton.setFont(composite.getFont()); 309 incompleteButton.setText(MarkerMessages.filtersDialog_statusIncomplete); 310 incompleteButton.addSelectionListener(listener); 311 } 312 313 public boolean isStatusEnabled() { 314 return enablementButton.getSelection(); 315 } 316 317 public void setEnabled(boolean enabled) { 318 enablementButton.setSelection(enabled); 319 } 320 321 public boolean getDone() { 322 return completeButton.getSelection(); 323 } 324 325 public void setDone(boolean done) { 326 completeButton.setSelection(done); 327 incompleteButton.setSelection(!done); 328 } 329 330 334 public void updateEnablement(boolean enabled) { 335 enablementButton.setEnabled(enabled); 336 completeButton.setEnabled(isStatusEnabled() 337 && enabled); 338 incompleteButton.setEnabled(isStatusEnabled() 339 && enabled); 340 } 341 } 342 343 349 public DialogTaskFilter(Shell parentShell, TaskFilter[] filters) { 350 super(parentShell, filters); 351 } 352 353 358 protected void createAttributesArea(Composite parent) { 359 Composite composite = new Composite(parent, SWT.NONE); 360 composite.setFont(parent.getFont()); 361 composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); 362 GridLayout layout = new GridLayout(5, false); 363 layout.verticalSpacing = 7; 364 composite.setLayout(layout); 365 366 descriptionGroup = new DescriptionGroup(composite); 367 priorityGroup = new PriorityGroup(composite); 368 statusGroup = new StatusGroup(composite); 369 } 370 371 374 protected void updateFilterFromUI(MarkerFilter filter) { 375 super.updateFilterFromUI(filter); 376 377 TaskFilter taskFilter = (TaskFilter)filter; 378 taskFilter.setContains(descriptionGroup.getContains()); 379 taskFilter.setDescription(descriptionGroup.getDescription().trim()); 380 381 taskFilter.setSelectByPriority(priorityGroup.isPriorityEnabled()); 382 int priority = 0; 383 if (priorityGroup.isHighSelected()) { 384 priority = priority | TaskFilter.PRIORITY_HIGH; 385 } 386 if (priorityGroup.isNormalSelected()) { 387 priority = priority | TaskFilter.PRIORITY_NORMAL; 388 } 389 if (priorityGroup.isLowSelected()) { 390 priority = priority | TaskFilter.PRIORITY_LOW; 391 } 392 taskFilter.setPriority(priority); 393 394 taskFilter.setSelectByDone(statusGroup.isStatusEnabled()); 395 taskFilter.setDone(statusGroup.getDone()); 396 397 } 398 399 402 protected void updateUIWithFilter(MarkerFilter filter) { 403 TaskFilter taskFilter = (TaskFilter)filter; 404 descriptionGroup.setContains(taskFilter.getContains()); 405 descriptionGroup.setDescription(taskFilter.getDescription()); 406 407 priorityGroup.setEnabled(taskFilter.getSelectByPriority()); 408 int priority = taskFilter.getPriority(); 409 priorityGroup 410 .setHighSelected((priority & TaskFilter.PRIORITY_HIGH) > 0); 411 priorityGroup 412 .setNormalSelected((priority & TaskFilter.PRIORITY_NORMAL) > 0); 413 priorityGroup.setLowSelected((priority & TaskFilter.PRIORITY_LOW) > 0); 414 415 statusGroup.setEnabled(taskFilter.getSelectByDone()); 416 statusGroup.setDone(taskFilter.getDone()); 417 418 super.updateUIWithFilter(filter); 419 420 421 } 422 423 426 protected void updateEnabledState(boolean enabled) { 427 super.updateEnabledState(enabled); 428 descriptionGroup.updateEnablement(enabled); 429 priorityGroup.updateEnablement(enabled); 430 statusGroup.updateEnablement(enabled); 431 } 432 433 434 439 protected void resetPressed() { 440 descriptionGroup.setContains(TaskFilter.DEFAULT_CONTAINS); 441 descriptionGroup.setDescription(TaskFilter.DEFAULT_DESCRIPTION); 442 443 priorityGroup.setEnabled(TaskFilter.DEFAULT_SELECT_BY_PRIORITY); 444 priorityGroup 445 .setHighSelected((TaskFilter.DEFAULT_PRIORITY & TaskFilter.PRIORITY_HIGH) > 0); 446 priorityGroup 447 .setNormalSelected((TaskFilter.DEFAULT_PRIORITY & TaskFilter.PRIORITY_NORMAL) > 0); 448 priorityGroup 449 .setLowSelected((TaskFilter.DEFAULT_PRIORITY & TaskFilter.PRIORITY_NORMAL) > 0); 450 451 statusGroup.setEnabled(TaskFilter.DEFAULT_SELECT_BY_DONE); 452 statusGroup.setDone(TaskFilter.DEFAULT_DONE); 453 454 super.resetPressed(); 455 } 456 457 462 protected MarkerFilter newFilter(String newName) { 463 return new TaskFilter(newName); 464 } 465 466 } 467 | Popular Tags |