001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: * Tom Schindl <tom.schindl@bestsolution.at> - Fix for
011: * Bug 154289 [Viewers] - NPE in TreeEditorImpl.activateCellEditor
012: *******************************************************************************/package org.eclipse.ui.views.markers.internal;
013:
014: import java.util.HashMap;
015: import java.util.Map;
016:
017: import org.eclipse.core.commands.ExecutionException;
018: import org.eclipse.core.commands.operations.IUndoContext;
019: import org.eclipse.core.commands.operations.IUndoableOperation;
020: import org.eclipse.core.resources.IMarker;
021: import org.eclipse.core.runtime.CoreException;
022: import org.eclipse.jface.action.IMenuManager;
023: import org.eclipse.jface.dialogs.ErrorDialog;
024: import org.eclipse.jface.dialogs.IDialogSettings;
025: import org.eclipse.jface.viewers.CellEditor;
026: import org.eclipse.jface.viewers.ICellModifier;
027: import org.eclipse.jface.viewers.IStructuredSelection;
028: import org.eclipse.jface.viewers.TextCellEditor;
029: import org.eclipse.jface.viewers.TreeViewer;
030: import org.eclipse.swt.widgets.Composite;
031: import org.eclipse.swt.widgets.Item;
032: import org.eclipse.ui.PlatformUI;
033: import org.eclipse.ui.ide.undo.UpdateMarkersOperation;
034: import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
035: import org.eclipse.ui.internal.ide.IDEInternalPreferences;
036: import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
037: import org.eclipse.ui.part.CellEditorActionHandler;
038:
039: /**
040: * The BookmarkView is the marker view for bookmarks.
041: *
042: */
043: public class BookmarkView extends MarkerView {
044:
045: private final IField[] HIDDEN_FIELDS = { new FieldCreationTime() };
046:
047: private final static String[] ROOT_TYPES = { IMarker.BOOKMARK };
048:
049: private final static String[] TABLE_COLUMN_PROPERTIES = {
050: IMarker.MESSAGE, Util.EMPTY_STRING, Util.EMPTY_STRING,
051: Util.EMPTY_STRING };
052:
053: private final static String TAG_DIALOG_SECTION = "org.eclipse.ui.views.bookmark"; //$NON-NLS-1$
054:
055: private final IField[] VISIBLE_FIELDS = { new FieldMessage(),
056: new FieldResource(), new FieldFolder(),
057: new FieldLineNumber() };
058:
059: private ICellModifier cellModifier = new ICellModifier() {
060: /* (non-Javadoc)
061: * @see org.eclipse.jface.viewers.ICellModifier#getValue(java.lang.Object, java.lang.String)
062: */
063: public Object getValue(Object element, String property) {
064: if (element instanceof ConcreteMarker
065: && IMarker.MESSAGE.equals(property)) {
066: return ((ConcreteMarker) element).getDescription();
067: }
068: return null;
069: }
070:
071: /* (non-Javadoc)
072: * @see org.eclipse.jface.viewers.ICellModifier#canModify(java.lang.Object, java.lang.String)
073: */
074: public boolean canModify(Object element, String property) {
075: return element instanceof ConcreteMarker
076: && IMarker.MESSAGE.equals(property);
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.jface.viewers.ICellModifier#modify(java.lang.Object, java.lang.String, java.lang.Object)
081: */
082: public void modify(Object element, String property, Object value) {
083: if (element instanceof Item) {
084: Item item = (Item) element;
085: Object data = item.getData();
086:
087: if (data instanceof ConcreteMarker) {
088: IMarker marker = ((ConcreteMarker) data)
089: .getMarker();
090:
091: try {
092: if (!marker.getAttribute(property)
093: .equals(value)) {
094: if (IMarker.MESSAGE.equals(property)) {
095: Map attrs = new HashMap();
096: attrs.put(IMarker.MESSAGE, value);
097: IUndoableOperation op = new UpdateMarkersOperation(
098: marker,
099: attrs,
100: MarkerMessages.modifyBookmark_title,
101: true);
102: PlatformUI
103: .getWorkbench()
104: .getOperationSupport()
105: .getOperationHistory()
106: .execute(
107: op,
108: null,
109: WorkspaceUndoUtil
110: .getUIInfoAdapter(getSite()
111: .getShell()));
112: }
113: }
114: } catch (ExecutionException e) {
115: if (e.getCause() instanceof CoreException) {
116: ErrorDialog
117: .openError(
118: getSite().getShell(),
119: MarkerMessages.errorModifyingBookmark,
120: null, ((CoreException) e
121: .getCause())
122: .getStatus());
123: } else {
124: // something rather unexpected occurred.
125: IDEWorkbenchPlugin
126: .log(
127: MarkerMessages.errorModifyingBookmark,
128: e);
129: }
130: } catch (CoreException e) {
131: ErrorDialog.openError(getSite().getShell(),
132: MarkerMessages.errorModifyingBookmark,
133: null, e.getStatus());
134: }
135: }
136: }
137: }
138: };
139:
140: private CellEditorActionHandler cellEditorActionHandler;
141:
142: /* (non-Javadoc)
143: * @see org.eclipse.ui.views.markers.internal.MarkerView#createPartControl(org.eclipse.swt.widgets.Composite)
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: CellEditor descriptionCellEditor = new TextCellEditor(
152: treeViewer.getTree());
153: cellEditors[0] = descriptionCellEditor;
154: treeViewer.setCellEditors(cellEditors);
155: treeViewer.setCellModifier(cellModifier);
156: treeViewer.setColumnProperties(TABLE_COLUMN_PROPERTIES);
157:
158: cellEditorActionHandler = new CellEditorActionHandler(
159: getViewSite().getActionBars());
160: cellEditorActionHandler.addCellEditor(descriptionCellEditor);
161: cellEditorActionHandler.setCopyAction(copyAction);
162: cellEditorActionHandler.setPasteAction(pasteAction);
163: cellEditorActionHandler.setDeleteAction(deleteAction);
164: cellEditorActionHandler.setSelectAllAction(selectAllAction);
165: cellEditorActionHandler.setUndoAction(undoAction);
166: cellEditorActionHandler.setRedoAction(redoAction);
167: }
168:
169: public void dispose() {
170: if (cellEditorActionHandler != null) {
171: cellEditorActionHandler.dispose();
172: }
173:
174: super .dispose();
175: }
176:
177: protected IDialogSettings getDialogSettings() {
178: IDialogSettings workbenchSettings = IDEWorkbenchPlugin
179: .getDefault().getDialogSettings();
180: IDialogSettings settings = workbenchSettings
181: .getSection(TAG_DIALOG_SECTION);
182:
183: if (settings == null) {
184: settings = workbenchSettings
185: .addNewSection(TAG_DIALOG_SECTION);
186: }
187:
188: return settings;
189: }
190:
191: /* (non-Javadoc)
192: * @see org.eclipse.ui.views.markers.internal.TableView#getSortingFields()
193: */
194: protected IField[] getSortingFields() {
195: IField[] all = new IField[VISIBLE_FIELDS.length
196: + HIDDEN_FIELDS.length];
197:
198: System.arraycopy(VISIBLE_FIELDS, 0, all, 0,
199: VISIBLE_FIELDS.length);
200: System.arraycopy(HIDDEN_FIELDS, 0, all, VISIBLE_FIELDS.length,
201: HIDDEN_FIELDS.length);
202:
203: return all;
204: }
205:
206: /* (non-Javadoc)
207: * @see org.eclipse.ui.views.markers.internal.TableView#getAllFields()
208: */
209: protected IField[] getAllFields() {
210: return getSortingFields();
211: }
212:
213: protected String[] getRootTypes() {
214: return ROOT_TYPES;
215: }
216:
217: public void setSelection(IStructuredSelection structuredSelection,
218: boolean reveal) {
219: // TODO: added because nick doesn't like public API inherited from
220: // internal classes
221: super .setSelection(structuredSelection, reveal);
222: }
223:
224: /*
225: * (non-Javadoc)
226: *
227: * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerTypes()
228: */
229: protected String[] getMarkerTypes() {
230: return new String[] { IMarker.BOOKMARK };
231: }
232:
233: /* (non-Javadoc)
234: * @see org.eclipse.ui.views.markers.internal.MarkerView#createFiltersDialog()
235: */
236: protected DialogMarkerFilter createFiltersDialog() {
237:
238: MarkerFilter[] filters = getUserFilters();
239: BookmarkFilter[] bookmarkFilters = new BookmarkFilter[filters.length];
240: System
241: .arraycopy(filters, 0, bookmarkFilters, 0,
242: filters.length);
243: return new DialogBookmarkFilter(getSite().getShell(),
244: bookmarkFilters);
245: }
246:
247: protected String getStaticContextId() {
248: return PlatformUI.PLUGIN_ID + ".bookmark_view_context"; //$NON-NLS-1$
249: }
250:
251: /* (non-Javadoc)
252: * @see org.eclipse.ui.views.markers.internal.MarkerView#createFilter(java.lang.String)
253: */
254: protected MarkerFilter createFilter(String name) {
255: return new BookmarkFilter(name);
256: }
257:
258: /* (non-Javadoc)
259: * @see org.eclipse.ui.views.markers.internal.MarkerView#getSectionTag()
260: */
261: protected String getSectionTag() {
262: return TAG_DIALOG_SECTION;
263: }
264:
265: /* (non-Javadoc)
266: * @see org.eclipse.ui.views.markers.internal.MarkerView#fillContextMenuAdditions(org.eclipse.jface.action.IMenuManager)
267: */
268: void fillContextMenuAdditions(IMenuManager manager) {
269: //Do nothing in this view
270:
271: }
272:
273: /* (non-Javadoc)
274: * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerEnablementPreferenceName()
275: */
276: String getMarkerEnablementPreferenceName() {
277: return IDEInternalPreferences.LIMIT_BOOKMARKS;
278: }
279:
280: /* (non-Javadoc)
281: * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerLimitPreferenceName()
282: */
283: String getMarkerLimitPreferenceName() {
284: return IDEInternalPreferences.BOOKMARKS_LIMIT;
285: }
286:
287: /* (non-Javadoc)
288: * @see org.eclipse.ui.views.markers.internal.MarkerView#getFiltersPreferenceName()
289: */
290: String getFiltersPreferenceName() {
291: return IDEInternalPreferences.BOOKMARKS_FILTERS;
292: }
293:
294: /*
295: * (non-Javadoc)
296: *
297: * @see org.eclipse.ui.views.markers.internal.MarkerView#getMarkerName()
298: */
299: protected String getMarkerName() {
300: return MarkerMessages.bookmark_title;
301: }
302:
303: /*
304: * (non-Javadoc)
305: * @see org.eclipse.ui.views.markers.internal.MarkerView#getUndoContext()
306: */
307: protected IUndoContext getUndoContext() {
308: return WorkspaceUndoUtil.getBookmarksUndoContext();
309: }
310:
311: }
|