1 13 14 package org.eclipse.ui.views.markers.internal; 15 16 import java.util.HashMap ; 17 import java.util.Map ; 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 45 public class BookmarkView extends MarkerView { 46 47 private final IField[] HIDDEN_FIELDS = { new FieldCreationTime() }; 48 49 private final static String [] ROOT_TYPES = { IMarker.BOOKMARK }; 50 51 private final static String [] TABLE_COLUMN_PROPERTIES = {IMarker.MESSAGE, 52 Util.EMPTY_STRING, 53 Util.EMPTY_STRING, 54 Util.EMPTY_STRING 55 }; 56 57 private final static String TAG_DIALOG_SECTION = "org.eclipse.ui.views.bookmark"; 59 private final IField[] VISIBLE_FIELDS = {new FieldMessage(), 60 new FieldResource(), new FieldFolder(), new FieldLineNumber() }; 61 62 private ICellModifier cellModifier = new ICellModifier() { 63 66 public Object getValue(Object element, String property) { 67 if (element instanceof ConcreteMarker 68 && IMarker.MESSAGE.equals(property)) { 69 return ((ConcreteMarker) element).getDescription(); 70 } 71 return null; 72 } 73 74 77 public boolean canModify(Object element, String property) { 78 return element instanceof ConcreteMarker && IMarker.MESSAGE.equals(property); 79 } 80 81 84 public void modify(Object element, String property, Object value) { 85 if (element instanceof Item) { 86 Item item = (Item) element; 87 Object 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 attrs = new HashMap (); 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 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 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 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 185 protected IField[] getAllFields() { 186 return getSortingFields(); 187 } 188 189 protected String [] getRootTypes() { 190 return ROOT_TYPES; 191 } 192 193 194 public void setSelection(IStructuredSelection structuredSelection, 195 boolean reveal) { 196 super.setSelection(structuredSelection, reveal); 199 } 200 201 206 protected String [] getMarkerTypes() { 207 return new String [] { IMarker.BOOKMARK }; 208 } 209 210 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 getStaticContextId() { 222 return PlatformUI.PLUGIN_ID + ".bookmark_view_context"; } 224 225 228 protected MarkerFilter createFilter(String name) { 229 return new BookmarkFilter(name); 230 } 231 232 235 protected String getSectionTag() { 236 return TAG_DIALOG_SECTION; 237 } 238 239 242 void fillContextMenuAdditions(IMenuManager manager) { 243 245 } 246 247 250 String getMarkerEnablementPreferenceName() { 251 return IDEInternalPreferences.LIMIT_BOOKMARKS; 252 } 253 254 257 String getMarkerLimitPreferenceName() { 258 return IDEInternalPreferences.BOOKMARKS_LIMIT; 259 } 260 261 264 String getFiltersPreferenceName() { 265 return IDEInternalPreferences.BOOKMARKS_FILTERS; 266 } 267 268 273 protected String getMarkerName() { 274 return MarkerMessages.bookmark_title; 275 } 276 277 281 protected IUndoContext getUndoContext() { 282 return WorkspaceUndoUtil.getBookmarksUndoContext(); 283 } 284 285 } 286 | Popular Tags |