KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > TaskView


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers.internal;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
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 /**
46  * The TaskView is the view for displaying task markers.
47  */

48 public class TaskView extends MarkerView {
49
50     private static final String JavaDoc COMPLETION = "completion"; //$NON-NLS-1$
51

52     private final IField[] HIDDEN_FIELDS = { new FieldCreationTime() };
53
54     private final static String JavaDoc[] ROOT_TYPES = { IMarker.TASK };
55
56     private final static String JavaDoc[] 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 JavaDoc TAG_DIALOG_SECTION = "org.eclipse.ui.views.task"; //$NON-NLS-1$
61

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 JavaDoc getValue(Object JavaDoc element, String JavaDoc 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 JavaDoc(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, ""); //$NON-NLS-1$
83
}
84             }
85
86             return null;
87         }
88
89         public boolean canModify(Object JavaDoc element, String JavaDoc property) {
90             return Util.isEditable(((ConcreteMarker) element).getMarker());
91         }
92
93         public void modify(Object JavaDoc element, String JavaDoc property, Object JavaDoc value) {
94             if (element instanceof Item) {
95                 Item item = (Item) element;
96                 Object JavaDoc 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 JavaDoc oldValue = getValue(data, property);
105                         if (oldValue != null && !oldValue.equals(value)) {
106                             Map JavaDoc attrs = new HashMap JavaDoc();
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 JavaDoc(IMarker.PRIORITY_HIGH
112                                                 - ((Integer JavaDoc) 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                             // something rather unexpected occurred.
129
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 JavaDoc[] priorities = new String JavaDoc[] { 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     /*
190      * (non-Javadoc)
191      *
192      * @see org.eclipse.ui.views.markers.internal.TableView#getDialogSettings()
193      */

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     /*
229      * (non-Javadoc)
230      *
231      * @see org.eclipse.ui.views.markers.internal.TableView#getSortingFields()
232      */

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     /*
244      * (non-Javadoc)
245      *
246      * @see org.eclipse.ui.views.markers.internal.TableView#getAllFields()
247      */

248     protected IField[] getAllFields() {
249         return getSortingFields();
250     }
251
252     protected String JavaDoc[] 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         // TODO: added because nick doesn't like public API inherited from
264
// internal classes
265
super.setSelection(structuredSelection, reveal);
266     }
267
268     /*
269      * (non-Javadoc)
270      *
271      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerTypes()
272      */

273     protected String JavaDoc[] getMarkerTypes() {
274         return new String JavaDoc[] { IMarker.TASK };
275     }
276
277     protected String JavaDoc getStaticContextId() {
278         return PlatformUI.PLUGIN_ID + ".task_list_view_context"; //$NON-NLS-1$
279
}
280
281     /*
282      * (non-Javadoc)
283      *
284      * @see org.eclipse.ui.views.markers.internal.MarkerView#createFiltersDialog()
285      */

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     /*
295      * (non-Javadoc)
296      *
297      * @see org.eclipse.ui.views.markers.internal.MarkerView#createFilter(java.lang.String)
298      */

299     protected MarkerFilter createFilter(String JavaDoc name) {
300         return new TaskFilter(name);
301     }
302
303     /*
304      * (non-Javadoc)
305      *
306      * @see org.eclipse.ui.views.markers.internal.MarkerView#getSectionTag()
307      */

308     protected String JavaDoc getSectionTag() {
309         return TAG_DIALOG_SECTION;
310     }
311
312     /*
313      * (non-Javadoc)
314      *
315      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerEnablementPreferenceName()
316      */

317     String JavaDoc getMarkerEnablementPreferenceName() {
318         return IDEInternalPreferences.LIMIT_TASKS;
319     }
320
321     /*
322      * (non-Javadoc)
323      *
324      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerLimitPreferenceName()
325      */

326     String JavaDoc getMarkerLimitPreferenceName() {
327         return IDEInternalPreferences.TASKS_LIMIT;
328     }
329
330     /*
331      * (non-Javadoc)
332      *
333      * @see org.eclipse.ui.views.markers.internal.MarkerView#getFiltersPreferenceName()
334      */

335     String JavaDoc getFiltersPreferenceName() {
336         return IDEInternalPreferences.TASKS_FILTERS;
337     }
338     
339     /* (non-Javadoc)
340      * @see org.eclipse.ui.views.markers.internal.TableView#updateDirectionIndicator(org.eclipse.swt.widgets.TreeColumn)
341      */

342     void updateDirectionIndicator(TreeColumn column) {
343         // Do nothing due to images being obscured
344
}
345
346     /*
347      * (non-Javadoc)
348      *
349      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerName()
350      */

351     protected String JavaDoc getMarkerName() {
352         return MarkerMessages.task_title;
353     }
354     
355     /*
356      * (non-Javadoc)
357      * @see org.eclipse.ui.views.markers.internal.MarkerView#getUndoContext()
358      */

359     protected IUndoContext getUndoContext() {
360         return WorkspaceUndoUtil.getTasksUndoContext();
361     }
362 }
363
Popular Tags