KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Tom Schindl <tom.schindl@bestsolution.at> - Fix for
11  * Bug 154289 [Viewers] - NPE in TreeEditorImpl.activateCellEditor
12  *******************************************************************************/

13
14 package org.eclipse.ui.views.markers.internal;
15
16 import java.util.HashMap JavaDoc;
17 import java.util.Map JavaDoc;
18
19 import org.eclipse.core.commands.ExecutionException;
20 import org.eclipse.core.commands.operations.IUndoContext;
21 import org.eclipse.core.commands.operations.IUndoableOperation;
22 import org.eclipse.core.resources.IMarker;
23 import org.eclipse.core.runtime.CoreException;
24 import org.eclipse.jface.action.IMenuManager;
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.ICellModifier;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30 import org.eclipse.jface.viewers.TextCellEditor;
31 import org.eclipse.jface.viewers.TreeViewer;
32 import org.eclipse.swt.widgets.Composite;
33 import org.eclipse.swt.widgets.Item;
34 import org.eclipse.ui.PlatformUI;
35 import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
36 import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
37 import org.eclipse.ui.internal.ide.IDEInternalPreferences;
38 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
39 import org.eclipse.ui.part.CellEditorActionHandler;
40
41 /**
42  * The BookmarkView is the marker view for bookmarks.
43  *
44  */

45 public class BookmarkView extends MarkerView {
46
47     private final IField[] HIDDEN_FIELDS = { new FieldCreationTime() };
48
49     private final static String JavaDoc[] ROOT_TYPES = { IMarker.BOOKMARK };
50
51     private final static String JavaDoc[] TABLE_COLUMN_PROPERTIES = {IMarker.MESSAGE,
52         Util.EMPTY_STRING,
53         Util.EMPTY_STRING,
54         Util.EMPTY_STRING
55     };
56
57     private final static String JavaDoc TAG_DIALOG_SECTION = "org.eclipse.ui.views.bookmark"; //$NON-NLS-1$
58

59     private final IField[] VISIBLE_FIELDS = {new FieldMessage(),
60             new FieldResource(), new FieldFolder(), new FieldLineNumber() };
61
62     private ICellModifier cellModifier = new ICellModifier() {
63         /* (non-Javadoc)
64          * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
65          */

66         public Object JavaDoc getValue(Object JavaDoc element, String JavaDoc property) {
67             if (element instanceof ConcreteMarker
68                     && IMarker.MESSAGE.equals(property)) {
69                 return ((ConcreteMarker) element).getDescription();
70             }
71             return null;
72         }
73
74         /* (non-Javadoc)
75          * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
76          */

77         public boolean canModify(Object JavaDoc element, String JavaDoc property) {
78             return element instanceof ConcreteMarker && IMarker.MESSAGE.equals(property);
79         }
80
81         /* (non-Javadoc)
82          * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
83          */

84         public void modify(Object JavaDoc element, String JavaDoc property, Object JavaDoc value) {
85             if (element instanceof Item) {
86                 Item item = (Item) element;
87                 Object JavaDoc data = item.getData();
88
89                 if (data instanceof ConcreteMarker) {
90                     IMarker marker = ((ConcreteMarker) data).getMarker();
91
92                     try {
93                         if (!marker.getAttribute(property).equals(value)) {
94                             if (IMarker.MESSAGE.equals(property)) {
95                                 Map JavaDoc attrs = new HashMap JavaDoc();
96                                 attrs.put(IMarker.MESSAGE, value);
97                                 IUndoableOperation op = new UpdateMarkersOperation(marker, attrs, MarkerMessages.modifyBookmark_title, true);
98                                    PlatformUI.getWorkbench().getOperationSupport().getOperationHistory().execute(
99                                            op, null, WorkspaceUndoUtil.getUIInfoAdapter(getSite().getShell()));
100                             }
101                         }
102                     } catch (ExecutionException e) {
103                         if (e.getCause() instanceof CoreException) {
104                             ErrorDialog.openError(
105                                     getSite().getShell(),
106                                     MarkerMessages.errorModifyingBookmark, null, ((CoreException)e.getCause()).getStatus());
107                         } else {
108                             // something rather unexpected occurred.
109
IDEWorkbenchPlugin.log(MarkerMessages.errorModifyingBookmark, e);
110                         }
111                     } catch (CoreException e) {
112                         ErrorDialog.openError(
113                                 getSite().getShell(),
114                                 MarkerMessages.errorModifyingBookmark, null, e.getStatus());
115                     }
116                 }
117             }
118         }
119     };
120
121     private CellEditorActionHandler cellEditorActionHandler;
122
123     /* (non-Javadoc)
124      * @see org.eclipse.ui.views.markers.internal.MarkerView#createPartControl(org.eclipse.swt.widgets.Composite)
125      */

126     public void createPartControl(Composite parent) {
127         super.createPartControl(parent);
128
129         TreeViewer treeViewer = getViewer();
130         CellEditor cellEditors[] = new CellEditor[treeViewer.getTree()
131                 .getColumnCount()];
132         CellEditor descriptionCellEditor = new TextCellEditor(treeViewer
133                 .getTree());
134         cellEditors[0] = descriptionCellEditor;
135         treeViewer.setCellEditors(cellEditors);
136         treeViewer.setCellModifier(cellModifier);
137         treeViewer.setColumnProperties(TABLE_COLUMN_PROPERTIES);
138
139         cellEditorActionHandler = new CellEditorActionHandler(getViewSite()
140                 .getActionBars());
141         cellEditorActionHandler.addCellEditor(descriptionCellEditor);
142         cellEditorActionHandler.setCopyAction(copyAction);
143         cellEditorActionHandler.setPasteAction(pasteAction);
144         cellEditorActionHandler.setDeleteAction(deleteAction);
145         cellEditorActionHandler.setSelectAllAction(selectAllAction);
146         cellEditorActionHandler.setUndoAction(undoAction);
147         cellEditorActionHandler.setRedoAction(redoAction);
148     }
149
150     public void dispose() {
151         if (cellEditorActionHandler != null) {
152             cellEditorActionHandler.dispose();
153         }
154
155         super.dispose();
156     }
157
158     protected IDialogSettings getDialogSettings() {
159         IDialogSettings workbenchSettings = IDEWorkbenchPlugin.getDefault().getDialogSettings();
160         IDialogSettings settings = workbenchSettings
161                 .getSection(TAG_DIALOG_SECTION);
162
163         if (settings == null) {
164             settings = workbenchSettings.addNewSection(TAG_DIALOG_SECTION);
165         }
166
167         return settings;
168     }
169
170     /* (non-Javadoc)
171      * @see org.eclipse.ui.views.markers.internal.TableView#getSortingFields()
172      */

173     protected IField[] getSortingFields() {
174         IField[] all = new IField[VISIBLE_FIELDS.length + HIDDEN_FIELDS.length];
175         
176         System.arraycopy(VISIBLE_FIELDS, 0, all, 0, VISIBLE_FIELDS.length);
177         System.arraycopy(HIDDEN_FIELDS, 0, all, VISIBLE_FIELDS.length, HIDDEN_FIELDS.length);
178         
179         return all;
180     }
181     
182     /* (non-Javadoc)
183      * @see org.eclipse.ui.views.markers.internal.TableView#getAllFields()
184      */

185     protected IField[] getAllFields() {
186         return getSortingFields();
187     }
188
189     protected String JavaDoc[] getRootTypes() {
190         return ROOT_TYPES;
191     }
192
193
194     public void setSelection(IStructuredSelection structuredSelection,
195             boolean reveal) {
196         // TODO: added because nick doesn't like public API inherited from
197
// internal classes
198
super.setSelection(structuredSelection, reveal);
199     }
200
201     /*
202      * (non-Javadoc)
203      *
204      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerTypes()
205      */

206     protected String JavaDoc[] getMarkerTypes() {
207         return new String JavaDoc[] { IMarker.BOOKMARK };
208     }
209
210     /* (non-Javadoc)
211      * @see org.eclipse.ui.views.markers.internal.MarkerView#createFiltersDialog()
212      */

213     protected DialogMarkerFilter createFiltersDialog() {
214
215         MarkerFilter[] filters = getUserFilters();
216         BookmarkFilter[] bookmarkFilters = new BookmarkFilter[filters.length];
217         System.arraycopy(filters, 0, bookmarkFilters, 0, filters.length);
218         return new DialogBookmarkFilter(getSite().getShell(), bookmarkFilters);
219     }
220
221     protected String JavaDoc getStaticContextId() {
222         return PlatformUI.PLUGIN_ID + ".bookmark_view_context"; //$NON-NLS-1$
223
}
224
225     /* (non-Javadoc)
226      * @see org.eclipse.ui.views.markers.internal.MarkerView#createFilter(java.lang.String)
227      */

228     protected MarkerFilter createFilter(String JavaDoc name) {
229         return new BookmarkFilter(name);
230     }
231
232     /* (non-Javadoc)
233      * @see org.eclipse.ui.views.markers.internal.MarkerView#getSectionTag()
234      */

235     protected String JavaDoc getSectionTag() {
236         return TAG_DIALOG_SECTION;
237     }
238     
239     /* (non-Javadoc)
240      * @see org.eclipse.ui.views.markers.internal.MarkerView#fillContextMenuAdditions(org.eclipse.jface.action.IMenuManager)
241      */

242     void fillContextMenuAdditions(IMenuManager manager) {
243         //Do nothing in this view
244

245     }
246     
247     /* (non-Javadoc)
248      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerEnablementPreferenceName()
249      */

250     String JavaDoc getMarkerEnablementPreferenceName() {
251         return IDEInternalPreferences.LIMIT_BOOKMARKS;
252     }
253     
254     /* (non-Javadoc)
255      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerLimitPreferenceName()
256      */

257     String JavaDoc getMarkerLimitPreferenceName() {
258         return IDEInternalPreferences.BOOKMARKS_LIMIT;
259     }
260     
261     /* (non-Javadoc)
262      * @see org.eclipse.ui.views.markers.internal.MarkerView#getFiltersPreferenceName()
263      */

264     String JavaDoc getFiltersPreferenceName() {
265         return IDEInternalPreferences.BOOKMARKS_FILTERS;
266     }
267     
268     /*
269      * (non-Javadoc)
270      *
271      * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerName()
272      */

273     protected String JavaDoc getMarkerName() {
274         return MarkerMessages.bookmark_title;
275     }
276     
277     /*
278      * (non-Javadoc)
279      * @see org.eclipse.ui.views.markers.internal.MarkerView#getUndoContext()
280      */

281     protected IUndoContext getUndoContext() {
282         return WorkspaceUndoUtil.getBookmarksUndoContext();
283     }
284     
285 }
286
Popular Tags