1 11 12 package org.eclipse.ui.views.markers.internal; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.core.commands.ExecutionException; 18 import org.eclipse.core.commands.operations.IUndoContext; 19 import org.eclipse.core.commands.operations.IUndoableOperation; 20 import org.eclipse.core.resources.IMarker; 21 import org.eclipse.core.runtime.CoreException; 22 import org.eclipse.jface.action.IMenuManager; 23 import org.eclipse.jface.action.IToolBarManager; 24 import org.eclipse.jface.action.Separator; 25 import org.eclipse.jface.dialogs.ErrorDialog; 26 import org.eclipse.jface.dialogs.IDialogSettings; 27 import org.eclipse.jface.viewers.CellEditor; 28 import org.eclipse.jface.viewers.CheckboxCellEditor; 29 import org.eclipse.jface.viewers.ComboBoxCellEditor; 30 import org.eclipse.jface.viewers.ICellModifier; 31 import org.eclipse.jface.viewers.IStructuredSelection; 32 import org.eclipse.jface.viewers.TextCellEditor; 33 import org.eclipse.jface.viewers.TreeViewer; 34 import org.eclipse.swt.SWT; 35 import org.eclipse.swt.widgets.Composite; 36 import org.eclipse.swt.widgets.Item; 37 import org.eclipse.swt.widgets.TreeColumn; 38 import org.eclipse.ui.PlatformUI; 39 import org.eclipse.ui.ide.undo.UpdateMarkersOperation; 40 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil; 41 import org.eclipse.ui.internal.ide.IDEInternalPreferences; 42 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; 43 import org.eclipse.ui.part.CellEditorActionHandler; 44 45 48 public class TaskView extends MarkerView { 49 50 private static final String COMPLETION = "completion"; 52 private final IField[] HIDDEN_FIELDS = { new FieldCreationTime() }; 53 54 private final static String [] ROOT_TYPES = { IMarker.TASK }; 55 56 private final static String [] TABLE_COLUMN_PROPERTIES = { 57 COMPLETION, IMarker.PRIORITY, IMarker.MESSAGE, 58 Util.EMPTY_STRING, Util.EMPTY_STRING, Util.EMPTY_STRING }; 59 60 private final static String TAG_DIALOG_SECTION = "org.eclipse.ui.views.task"; 62 private final IField[] VISIBLE_FIELDS = { 63 new FieldDone(), new FieldPriority(), new FieldMessage(), 64 new FieldResource(), new FieldFolder(), new FieldLineNumber() }; 65 66 private ICellModifier cellModifier = new ICellModifier() { 67 public Object getValue(Object element, String property) { 68 if (element instanceof ConcreteMarker) { 69 IMarker marker = ((ConcreteMarker) element).getMarker(); 70 71 if (COMPLETION.equals(property)) { 72 return marker.getAttribute(IMarker.DONE, false) ? Boolean.TRUE : Boolean.FALSE; 73 } 74 75 if (IMarker.PRIORITY.equals(property)) { 76 return new Integer (IMarker.PRIORITY_HIGH 77 - marker.getAttribute(IMarker.PRIORITY, 78 IMarker.PRIORITY_NORMAL)); 79 } 80 81 if (IMarker.MESSAGE.equals(property)) { 82 return marker.getAttribute(IMarker.MESSAGE, ""); } 84 } 85 86 return null; 87 } 88 89 public boolean canModify(Object element, String property) { 90 return Util.isEditable(((ConcreteMarker) element).getMarker()); 91 } 92 93 public void modify(Object element, String property, Object value) { 94 if (element instanceof Item) { 95 Item item = (Item) element; 96 Object data = item.getData(); 97 98 if (data instanceof ConcreteMarker) { 99 ConcreteMarker concreteMarker = (ConcreteMarker) data; 100 101 IMarker marker = concreteMarker.getMarker(); 102 103 try { 104 Object oldValue = getValue(data, property); 105 if (oldValue != null && !oldValue.equals(value)) { 106 Map attrs = new HashMap (); 107 if (COMPLETION.equals(property)) 108 attrs.put(IMarker.DONE, value); 109 else if (IMarker.PRIORITY.equals(property)) 110 attrs.put(IMarker.PRIORITY, 111 new Integer (IMarker.PRIORITY_HIGH 112 - ((Integer ) value).intValue())); 113 else if (IMarker.MESSAGE.equals(property)) 114 attrs.put(IMarker.MESSAGE, value); 115 if (!attrs.isEmpty()) { 116 IUndoableOperation op = new UpdateMarkersOperation(marker, attrs, MarkerMessages.modifyTask_title, true); 117 PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute( 118 op, null, WorkspaceUndoUtil.getUIInfoAdapter(getSite().getShell())); 119 } 120 } 121 concreteMarker.refresh(); 122 } catch (ExecutionException e) { 123 if (e.getCause() instanceof CoreException) { 124 ErrorDialog.openError( 125 getSite().getShell(), 126 MarkerMessages.errorModifyingTask, null, ((CoreException)e.getCause()).getStatus()); 127 } else { 128 IDEWorkbenchPlugin.log(MarkerMessages.errorModifyingTask, e); 130 } 131 } 132 } 133 } 134 } 135 }; 136 137 private CellEditorActionHandler cellEditorActionHandler; 138 139 private ActionAddGlobalTask addGlobalTaskAction; 140 141 private ActionDeleteCompleted deleteCompletedAction; 142 143 private ActionMarkCompleted markCompletedAction; 144 145 public void createPartControl(Composite parent) { 146 super.createPartControl(parent); 147 148 TreeViewer treeViewer = getViewer(); 149 CellEditor cellEditors[] = new CellEditor[treeViewer.getTree() 150 .getColumnCount()]; 151 cellEditors[0] = new CheckboxCellEditor(treeViewer.getTree()); 152 153 String [] priorities = new String [] { MarkerMessages.priority_high, 154 MarkerMessages.priority_normal, MarkerMessages.priority_low }; 155 156 cellEditors[1] = new ComboBoxCellEditor(treeViewer.getTree(), 157 priorities, SWT.READ_ONLY); 158 CellEditor descriptionCellEditor = new TextCellEditor(treeViewer 159 .getTree()); 160 cellEditors[2] = descriptionCellEditor; 161 treeViewer.setCellEditors(cellEditors); 162 treeViewer.setCellModifier(cellModifier); 163 treeViewer.setColumnProperties(TABLE_COLUMN_PROPERTIES); 164 165 cellEditorActionHandler = new CellEditorActionHandler(getViewSite() 166 .getActionBars()); 167 cellEditorActionHandler.addCellEditor(descriptionCellEditor); 168 cellEditorActionHandler.setCopyAction(copyAction); 169 cellEditorActionHandler.setPasteAction(pasteAction); 170 cellEditorActionHandler.setDeleteAction(deleteAction); 171 cellEditorActionHandler.setSelectAllAction(selectAllAction); 172 cellEditorActionHandler.setUndoAction(undoAction); 173 cellEditorActionHandler.setRedoAction(redoAction); 174 175 } 176 177 public void dispose() { 178 if (cellEditorActionHandler != null) { 179 cellEditorActionHandler.dispose(); 180 } 181 182 if (markCompletedAction != null) { 183 markCompletedAction.dispose(); 184 } 185 186 super.dispose(); 187 } 188 189 194 protected IDialogSettings getDialogSettings() { 195 IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault() 196 .getDialogSettings(); 197 IDialogSettings settings = workbenchSettings 198 .getSection(TAG_DIALOG_SECTION); 199 200 if (settings == null) { 201 settings = workbenchSettings.addNewSection(TAG_DIALOG_SECTION); 202 } 203 204 return settings; 205 } 206 207 protected void createActions() { 208 super.createActions(); 209 210 addGlobalTaskAction = new ActionAddGlobalTask(this); 211 deleteCompletedAction = new ActionDeleteCompleted(this, getViewer()); 212 markCompletedAction = new ActionMarkCompleted(getViewer()); 213 propertiesAction = new ActionTaskProperties(this, getViewer()); 214 } 215 216 protected void fillContextMenu(IMenuManager manager) { 217 manager.add(addGlobalTaskAction); 218 manager.add(new Separator()); 219 super.fillContextMenu(manager); 220 } 221 222 protected void fillContextMenuAdditions(IMenuManager manager) { 223 manager.add(new Separator()); 224 manager.add(markCompletedAction); 225 manager.add(deleteCompletedAction); 226 } 227 228 233 protected IField[] getSortingFields() { 234 IField[] all = new IField[VISIBLE_FIELDS.length + HIDDEN_FIELDS.length]; 235 236 System.arraycopy(VISIBLE_FIELDS, 0, all, 0, VISIBLE_FIELDS.length); 237 System.arraycopy(HIDDEN_FIELDS, 0, all, VISIBLE_FIELDS.length, 238 HIDDEN_FIELDS.length); 239 240 return all; 241 } 242 243 248 protected IField[] getAllFields() { 249 return getSortingFields(); 250 } 251 252 protected String [] getRootTypes() { 253 return ROOT_TYPES; 254 } 255 256 protected void initToolBar(IToolBarManager toolBarManager) { 257 toolBarManager.add(addGlobalTaskAction); 258 super.initToolBar(toolBarManager); 259 } 260 261 public void setSelection(IStructuredSelection structuredSelection, 262 boolean reveal) { 263 super.setSelection(structuredSelection, reveal); 266 } 267 268 273 protected String [] getMarkerTypes() { 274 return new String [] { IMarker.TASK }; 275 } 276 277 protected String getStaticContextId() { 278 return PlatformUI.PLUGIN_ID + ".task_list_view_context"; } 280 281 286 protected DialogMarkerFilter createFiltersDialog() { 287 288 MarkerFilter[] filters = getUserFilters(); 289 TaskFilter[] taskFilters = new TaskFilter[filters.length]; 290 System.arraycopy(filters, 0, taskFilters, 0, filters.length); 291 return new DialogTaskFilter(getSite().getShell(), taskFilters); 292 } 293 294 299 protected MarkerFilter createFilter(String name) { 300 return new TaskFilter(name); 301 } 302 303 308 protected String getSectionTag() { 309 return TAG_DIALOG_SECTION; 310 } 311 312 317 String getMarkerEnablementPreferenceName() { 318 return IDEInternalPreferences.LIMIT_TASKS; 319 } 320 321 326 String getMarkerLimitPreferenceName() { 327 return IDEInternalPreferences.TASKS_LIMIT; 328 } 329 330 335 String getFiltersPreferenceName() { 336 return IDEInternalPreferences.TASKS_FILTERS; 337 } 338 339 342 void updateDirectionIndicator(TreeColumn column) { 343 } 345 346 351 protected String getMarkerName() { 352 return MarkerMessages.task_title; 353 } 354 355 359 protected IUndoContext getUndoContext() { 360 return WorkspaceUndoUtil.getTasksUndoContext(); 361 } 362 } 363 | Popular Tags |