1 12 13 package org.eclipse.ui.views.markers.internal; 14 15 import java.util.Map ; 16 17 import org.eclipse.core.resources.IMarker; 18 import org.eclipse.swt.SWT; 19 import org.eclipse.swt.events.SelectionAdapter; 20 import org.eclipse.swt.events.SelectionEvent; 21 import org.eclipse.swt.events.TraverseEvent; 22 import org.eclipse.swt.events.TraverseListener; 23 import org.eclipse.swt.layout.GridData; 24 import org.eclipse.swt.layout.GridLayout; 25 import org.eclipse.swt.widgets.Button; 26 import org.eclipse.swt.widgets.Combo; 27 import org.eclipse.swt.widgets.Composite; 28 import org.eclipse.swt.widgets.Label; 29 import org.eclipse.swt.widgets.Shell; 30 31 36 public class DialogTaskProperties extends DialogMarkerProperties { 37 38 private static final String PRIORITY_HIGH = 39 MarkerMessages.propertiesDialog_priorityHigh; 40 41 private static final String PRIORITY_NORMAL = 42 MarkerMessages.propertiesDialog_priorityNormal; 43 44 private static final String PRIORITY_LOW = 45 MarkerMessages.propertiesDialog_priorityLow; 46 47 protected Combo priorityCombo; 48 49 protected Button completedCheckbox; 50 51 54 public DialogTaskProperties(Shell parentShell) { 55 super(parentShell); 56 setType(IMarker.TASK); 57 } 58 59 62 DialogTaskProperties(Shell parentShell, String title) { 63 super(parentShell, title); 64 setType(IMarker.TASK); 65 } 66 67 71 protected void createAttributesArea(Composite parent) { 72 createSeperator(parent); 73 super.createAttributesArea(parent); 74 75 Label label = new Label(parent, SWT.NONE); 76 label.setText(MarkerMessages.propertiesDialog_priority); 77 78 Composite composite = new Composite(parent, SWT.NONE); 79 GridLayout layout = new GridLayout(); 80 layout.numColumns = 2; 81 layout.marginWidth = 0; 82 layout.marginHeight = 0; 83 composite.setLayout(layout); 84 85 priorityCombo = new Combo(composite, SWT.READ_ONLY); 86 priorityCombo.setItems(new String [] { PRIORITY_HIGH, PRIORITY_NORMAL, 87 PRIORITY_LOW }); 88 priorityCombo.addTraverseListener(new TraverseListener() { 90 public void keyTraversed(TraverseEvent e) { 91 if (e.detail == SWT.TRAVERSE_ESCAPE 92 || e.detail == SWT.TRAVERSE_RETURN) { 93 e.doit = false; 94 } 95 } 96 }); 97 priorityCombo.addSelectionListener(new SelectionAdapter() { 98 public void widgetSelected(SelectionEvent e) { 99 if (getMarker() == null) { 100 Map initialAttributes = getInitialAttributes(); 101 initialAttributes.put(IMarker.PRIORITY, new Integer ( 102 getPriorityFromDialog())); 103 } 104 markDirty(); 105 } 106 }); 107 108 completedCheckbox = new Button(composite, SWT.CHECK); 109 completedCheckbox.setText(MarkerMessages.propertiesDialog_completed); 110 GridData gridData = new GridData(); 111 gridData.horizontalIndent = convertHorizontalDLUsToPixels(20); 112 completedCheckbox.setLayoutData(gridData); 113 completedCheckbox.addSelectionListener(new SelectionAdapter() { 114 public void widgetSelected(SelectionEvent e) { 115 if (getMarker() == null) { 116 Map initialAttributes = getInitialAttributes(); 117 initialAttributes.put(IMarker.DONE, completedCheckbox.getSelection() ? Boolean.TRUE : Boolean.FALSE); 118 } 119 markDirty(); 120 } 121 }); 122 } 123 124 protected boolean getCompleted() { 125 IMarker marker = getMarker(); 126 if (marker == null) { 127 Map attributes = getInitialAttributes(); 128 Object done = attributes.get(IMarker.DONE); 129 return done != null && done instanceof Boolean 130 && ((Boolean ) done).booleanValue(); 131 } 132 return marker.getAttribute(IMarker.DONE, false); 133 } 134 135 protected int getPriority() { 136 IMarker marker = getMarker(); 137 int priority = IMarker.PRIORITY_NORMAL; 138 if (marker == null) { 139 Map attributes = getInitialAttributes(); 140 Object priorityObj = attributes.get(IMarker.PRIORITY); 141 if (priorityObj != null && priorityObj instanceof Integer ) { 142 priority = ((Integer ) priorityObj).intValue(); 143 } 144 } else { 145 priority = marker.getAttribute(IMarker.PRIORITY, 146 IMarker.PRIORITY_NORMAL); 147 } 148 return priority; 149 } 150 151 155 protected void updateEnablement() { 156 super.updateEnablement(); 157 priorityCombo.setEnabled(isEditable()); 158 completedCheckbox.setEnabled(isEditable()); 159 } 160 161 165 protected void updateDialogForNewMarker() { 166 Map initialAttributes = getInitialAttributes(); 167 int priority = getPriority(); 168 initialAttributes.put(IMarker.PRIORITY, new Integer (priority)); 169 if (priority == IMarker.PRIORITY_HIGH) { 170 priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH)); 171 } else if (priority == IMarker.PRIORITY_LOW) { 172 priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW)); 173 } else { 174 priorityCombo.select(priorityCombo.indexOf(PRIORITY_NORMAL)); 175 } 176 boolean completed = getCompleted(); 177 initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE : Boolean.FALSE); 178 completedCheckbox.setSelection(completed); 179 super.updateDialogForNewMarker(); 180 } 181 182 186 protected void updateDialogFromMarker() { 187 Map initialAttributes = getInitialAttributes(); 188 int priority = getPriority(); 189 initialAttributes.put(IMarker.PRIORITY, new Integer (priority)); 190 if (priority == IMarker.PRIORITY_HIGH) { 191 priorityCombo.select(priorityCombo.indexOf(PRIORITY_HIGH)); 192 } else if (priority == IMarker.PRIORITY_LOW) { 193 priorityCombo.select(priorityCombo.indexOf(PRIORITY_LOW)); 194 } else { 195 priorityCombo.select(priorityCombo.indexOf(PRIORITY_NORMAL)); 196 } 197 boolean completed = getCompleted(); 198 initialAttributes.put(IMarker.DONE, completed ? Boolean.TRUE : Boolean.FALSE); 199 completedCheckbox.setSelection(completed); 200 super.updateDialogFromMarker(); 201 } 202 203 private int getPriorityFromDialog() { 204 int priority = IMarker.PRIORITY_NORMAL; 205 if (priorityCombo.getSelectionIndex() == priorityCombo 206 .indexOf(PRIORITY_HIGH)) { 207 priority = IMarker.PRIORITY_HIGH; 208 } else if (priorityCombo.getSelectionIndex() == priorityCombo 209 .indexOf(PRIORITY_LOW)) { 210 priority = IMarker.PRIORITY_LOW; 211 } 212 return priority; 213 } 214 215 219 protected Map getMarkerAttributes() { 220 Map attrs = super.getMarkerAttributes(); 221 attrs.put(IMarker.PRIORITY, new Integer (getPriorityFromDialog())); 222 attrs.put(IMarker.DONE, completedCheckbox.getSelection() ? Boolean.TRUE : Boolean.FALSE); 223 Object userEditable = attrs.get(IMarker.USER_EDITABLE); 224 if (userEditable == null || !(userEditable instanceof Boolean )) { 225 attrs.put(IMarker.USER_EDITABLE, Boolean.TRUE); 226 } 227 return attrs; 228 } 229 230 235 protected String getModifyOperationTitle() { 236 return MarkerMessages.modifyTask_title; 237 } 238 239 244 protected String getCreateOperationTitle() { 245 return MarkerMessages.DialogTaskProperties_CreateTask; 246 247 } 248 249 } 250 | Popular Tags |