KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > bookmarkexplorer > BookmarkNavigator


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.bookmarkexplorer;
13
14 import java.util.ArrayList JavaDoc;
15
16 import org.eclipse.core.resources.IMarker;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.core.resources.IWorkspace;
19 import org.eclipse.core.resources.IWorkspaceRoot;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.Platform;
23 import org.eclipse.jface.action.Action;
24 import org.eclipse.jface.action.IMenuListener;
25 import org.eclipse.jface.action.IMenuManager;
26 import org.eclipse.jface.action.IToolBarManager;
27 import org.eclipse.jface.action.MenuManager;
28 import org.eclipse.jface.action.Separator;
29 import org.eclipse.jface.dialogs.IDialogSettings;
30 import org.eclipse.jface.viewers.ColumnLayoutData;
31 import org.eclipse.jface.viewers.ColumnPixelData;
32 import org.eclipse.jface.viewers.ColumnWeightData;
33 import org.eclipse.jface.viewers.ILabelProvider;
34 import org.eclipse.jface.viewers.IOpenListener;
35 import org.eclipse.jface.viewers.ISelectionChangedListener;
36 import org.eclipse.jface.viewers.IStructuredSelection;
37 import org.eclipse.jface.viewers.OpenEvent;
38 import org.eclipse.jface.viewers.SelectionChangedEvent;
39 import org.eclipse.jface.viewers.StructuredSelection;
40 import org.eclipse.jface.viewers.StructuredViewer;
41 import org.eclipse.jface.viewers.TableLayout;
42 import org.eclipse.jface.viewers.TableViewer;
43 import org.eclipse.swt.SWT;
44 import org.eclipse.swt.dnd.Clipboard;
45 import org.eclipse.swt.dnd.DND;
46 import org.eclipse.swt.dnd.DragSourceAdapter;
47 import org.eclipse.swt.dnd.DragSourceEvent;
48 import org.eclipse.swt.dnd.DragSourceListener;
49 import org.eclipse.swt.dnd.TextTransfer;
50 import org.eclipse.swt.dnd.Transfer;
51 import org.eclipse.swt.events.KeyAdapter;
52 import org.eclipse.swt.events.KeyEvent;
53 import org.eclipse.swt.events.SelectionAdapter;
54 import org.eclipse.swt.events.SelectionEvent;
55 import org.eclipse.swt.events.SelectionListener;
56 import org.eclipse.swt.widgets.Composite;
57 import org.eclipse.swt.widgets.Menu;
58 import org.eclipse.swt.widgets.ScrollBar;
59 import org.eclipse.swt.widgets.Scrollable;
60 import org.eclipse.swt.widgets.Shell;
61 import org.eclipse.swt.widgets.Table;
62 import org.eclipse.swt.widgets.TableColumn;
63 import org.eclipse.ui.IActionBars;
64 import org.eclipse.ui.IMemento;
65 import org.eclipse.ui.IPageLayout;
66 import org.eclipse.ui.ISharedImages;
67 import org.eclipse.ui.IViewSite;
68 import org.eclipse.ui.IWorkbenchActionConstants;
69 import org.eclipse.ui.PartInitException;
70 import org.eclipse.ui.PlatformUI;
71 import org.eclipse.ui.actions.ActionFactory;
72 import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
73 import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages;
74 import org.eclipse.ui.part.IShowInSource;
75 import org.eclipse.ui.part.IShowInTargetList;
76 import org.eclipse.ui.part.MarkerTransfer;
77 import org.eclipse.ui.part.ShowInContext;
78 import org.eclipse.ui.part.ViewPart;
79 import org.eclipse.ui.plugin.AbstractUIPlugin;
80 import org.eclipse.ui.views.navigator.ShowInNavigatorAction;
81
82 /**
83  * Main class for the bookmark navigator for displaying bookmarks on
84  * resources and opening an editor on the bookmarked resource when the user
85  * commands.
86  * <p>
87  * This standard view has id <code>"org.eclipse.ui.views.BookmarkNavigator"</code>.
88  * </p>
89  * <p>
90  * The workbench will automatically instantiate this class when a bookmark
91  * navigator is needed for a workbench window. This class is not intended
92  * to be instantiated or subclassed by clients.
93  * </p>
94  */

95 public class BookmarkNavigator extends ViewPart {
96     private Table table;
97
98     private TableViewer viewer;
99
100     private OpenBookmarkAction openAction;
101
102     private CopyBookmarkAction copyAction;
103
104     private PasteBookmarkAction pasteAction;
105
106     private RemoveBookmarkAction removeAction;
107
108     private EditBookmarkAction editAction;
109
110     private SelectAllAction selectAllAction;
111
112     private ShowInNavigatorAction showInNavigatorAction;
113
114     private SortByAction sortByDescriptionAction;
115
116     private SortByAction sortByResourceAction;
117
118     private SortByAction sortByFolderAction;
119
120     private SortByAction sortByLineAction;
121
122     private SortByAction sortByCreationTime;
123
124     private ChangeSortDirectionAction sortAscendingAction;
125
126     private ChangeSortDirectionAction sortDescendingAction;
127
128     private IMemento memento;
129
130     private BookmarkSorter comparator;
131
132     private Clipboard clipboard;
133
134     private final String JavaDoc columnHeaders[] = {
135             BookmarkMessages.ColumnIcon_header,
136             BookmarkMessages.ColumnDescription_header,
137             BookmarkMessages.ColumnResource_header,
138             BookmarkMessages.ColumnFolder_header,
139             BookmarkMessages.ColumnLocation_header };
140
141     private ColumnLayoutData columnLayouts[] = {
142             new ColumnPixelData(16, false, true), new ColumnWeightData(200),
143             new ColumnWeightData(75), new ColumnWeightData(150),
144             new ColumnWeightData(60) };
145
146     // Persistance tags.
147
private static final String JavaDoc TAG_SELECTION = "selection"; //$NON-NLS-1$
148

149     private static final String JavaDoc TAG_ID = "id";//$NON-NLS-1$
150

151     private static final String JavaDoc TAG_MARKER = "marker";//$NON-NLS-1$
152

153     private static final String JavaDoc TAG_RESOURCE = "resource";//$NON-NLS-1$
154

155     private static final String JavaDoc TAG_VERTICAL_POSITION = "verticalPosition";//$NON-NLS-1$
156

157     private static final String JavaDoc TAG_HORIZONTAL_POSITION = "horizontalPosition";//$NON-NLS-1$
158

159     class SortByAction extends Action {
160
161         private int column;
162
163         /**
164          * @param column
165          */

166         public SortByAction(int column) {
167             this.column = column;
168         }
169
170         public void run() {
171             comparator.setTopPriority(column);
172             updateSortState();
173             viewer.refresh();
174             IDialogSettings workbenchSettings = getPlugin().getDialogSettings();
175             IDialogSettings settings = workbenchSettings
176                     .getSection("BookmarkSortState");//$NON-NLS-1$
177
if (settings == null) {
178                 settings = workbenchSettings.addNewSection("BookmarkSortState");//$NON-NLS-1$
179
}
180             comparator.saveState(settings);
181         }
182     }
183
184     class ChangeSortDirectionAction extends Action {
185
186         private int direction;
187
188         /**
189          * @param direction
190          */

191         public ChangeSortDirectionAction(int direction) {
192             this.direction = direction;
193         }
194
195         public void run() {
196             comparator.setTopPriorityDirection(direction);
197             updateSortState();
198             viewer.refresh();
199             IDialogSettings workbenchSettings = getPlugin().getDialogSettings();
200             IDialogSettings settings = workbenchSettings
201                     .getSection("BookmarkSortState");//$NON-NLS-1$
202
if (settings == null) {
203                 settings = workbenchSettings.addNewSection("BookmarkSortState");//$NON-NLS-1$
204
}
205             comparator.saveState(settings);
206         }
207     }
208
209     /**
210      * Creates the bookmarks view.
211      */

212     public BookmarkNavigator() {
213         super();
214     }
215
216     /**
217      * Adds this views contributions to the workbench.
218      */

219     void addContributions() {
220         ISharedImages sharedImages = PlatformUI.getWorkbench()
221                 .getSharedImages();
222
223         // Create the actions.
224
openAction = new OpenBookmarkAction(this);
225         openAction
226                 .setImageDescriptor(IDEWorkbenchPlugin.getIDEImageDescriptor("elcl16/gotoobj_tsk.gif"));//$NON-NLS-1$
227

228         copyAction = new CopyBookmarkAction(this);
229         copyAction.setImageDescriptor(sharedImages
230                 .getImageDescriptor(ISharedImages.IMG_TOOL_COPY));
231
232         pasteAction = new PasteBookmarkAction(this);
233         pasteAction.setImageDescriptor(sharedImages
234                 .getImageDescriptor(ISharedImages.IMG_TOOL_PASTE));
235
236         removeAction = new RemoveBookmarkAction(this);
237         removeAction.setImageDescriptor(sharedImages
238                 .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE));
239         removeAction.setDisabledImageDescriptor(sharedImages
240                 .getImageDescriptor(ISharedImages.IMG_TOOL_DELETE_DISABLED));
241
242         editAction = new EditBookmarkAction(this);
243
244         selectAllAction = new SelectAllAction(this);
245         showInNavigatorAction = new ShowInNavigatorAction(getViewSite()
246                 .getPage(), viewer);
247
248         // initializes action enabled state
249
handleSelectionChanged(StructuredSelection.EMPTY);
250
251         // Create dynamic menu mgr. Dynamic is currently required to
252
// support action contributions.
253
MenuManager mgr = new MenuManager();
254         mgr.setRemoveAllWhenShown(true);
255         mgr.addMenuListener(new IMenuListener() {
256             public void menuAboutToShow(IMenuManager mgr) {
257                 fillContextMenu(mgr);
258             }
259         });
260         Menu menu = mgr.createContextMenu(viewer.getControl());
261         viewer.getControl().setMenu(menu);
262         getSite().registerContextMenu(mgr, viewer);
263
264         // Add actions to the local tool bar
265
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
266         tbm.add(removeAction);
267         tbm.add(openAction);
268         tbm.update(false);
269
270         // Register with action service.
271
IActionBars actionBars = getViewSite().getActionBars();
272         actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(),
273                 copyAction);
274         actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(),
275                 pasteAction);
276         actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(),
277                 removeAction);
278         actionBars.setGlobalActionHandler(ActionFactory.SELECT_ALL.getId(),
279                 selectAllAction);
280
281         // Set the double click action.
282
viewer.addOpenListener(new IOpenListener() {
283             public void open(OpenEvent event) {
284                 openAction.run();
285             }
286         });
287         viewer.addSelectionChangedListener(new ISelectionChangedListener() {
288             public void selectionChanged(SelectionChangedEvent event) {
289                 handleSelectionChanged((IStructuredSelection) event
290                         .getSelection());
291             }
292         });
293         viewer.getControl().addKeyListener(new KeyAdapter() {
294             public void keyPressed(KeyEvent e) {
295                 handleKeyPressed(e);
296             }
297         });
298     }
299
300     /* (non-Javadoc)
301      * Method declared on IWorkbenchPart.
302      */

303     public void createPartControl(Composite parent) {
304         clipboard = new Clipboard(parent.getDisplay());
305         createTable(parent);
306         viewer = new TableViewer(table);
307         createColumns();
308
309         comparator = new BookmarkSorter();
310         viewer.setContentProvider(new BookmarkContentProvider(this));
311         viewer.setLabelProvider(new BookmarkLabelProvider(this));
312         viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
313         viewer.setComparator(comparator);
314
315         IDialogSettings workbenchSettings = getPlugin().getDialogSettings();
316         IDialogSettings settings = workbenchSettings
317                 .getSection("BookmarkSortState");//$NON-NLS-1$
318
comparator.restoreState(settings);
319
320         addContributions();
321         initDragAndDrop();
322         createSortActions();
323         fillActionBars();
324         updateSortState();
325         updatePasteEnablement();
326
327         getSite().setSelectionProvider(viewer);
328
329         if (memento != null) {
330             restoreState(memento);
331         }
332         memento = null;
333
334         PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
335                 IBookmarkHelpContextIds.BOOKMARK_VIEW);
336     }
337
338     public void dispose() {
339         if (clipboard != null) {
340             clipboard.dispose();
341         }
342     }
343
344     /**
345      * Notifies this listener that the menu is about to be shown by
346      * the given menu manager.
347      *
348      * @param manager the menu manager
349      */

350     void fillContextMenu(IMenuManager manager) {
351         manager.add(openAction);
352         manager.add(copyAction);
353         updatePasteEnablement();
354         manager.add(pasteAction);
355         manager.add(removeAction);
356         manager.add(selectAllAction);
357         manager.add(showInNavigatorAction);
358         manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
359         manager.add(new Separator());
360         manager.add(editAction);
361     }
362
363     /* (non-Javadoc)
364      * @see org.eclipse.core.runtime.IAdaptable#getAdapter(Class)
365      */

366     public Object JavaDoc getAdapter(Class JavaDoc adapter) {
367         if (adapter == IShowInSource.class) {
368             return new IShowInSource() {
369                 public ShowInContext getShowInContext() {
370                     return new ShowInContext(null, getViewer().getSelection());
371                 }
372             };
373         }
374         if (adapter == IShowInTargetList.class) {
375             return new IShowInTargetList() {
376                 public String JavaDoc[] getShowInTargetIds() {
377                     return new String JavaDoc[] { IPageLayout.ID_RES_NAV };
378                 }
379
380             };
381         }
382         return super.getAdapter(adapter);
383     }
384
385     /**
386      * Returns the UI plugin for the bookmarks view.
387      */

388     static AbstractUIPlugin getPlugin() {
389         return (AbstractUIPlugin) Platform.getPlugin(PlatformUI.PLUGIN_ID);
390     }
391
392     /**
393      * Returns the shell.
394      */

395     Shell getShell() {
396         return getViewSite().getShell();
397     }
398
399     /**
400      * Returns the viewer used to display bookmarks.
401      *
402      * @return the viewer, or <code>null</code> if this view's controls
403      * have not been created yet
404      */

405     StructuredViewer getViewer() {
406         return viewer;
407     }
408
409     /**
410      * Returns the workspace.
411      */

412     IWorkspace getWorkspace() {
413         return ResourcesPlugin.getWorkspace();
414     }
415
416     /**
417      * Handles key events in viewer.
418      */

419     void handleKeyPressed(KeyEvent event) {
420         if (event.character == SWT.DEL && event.stateMask == 0
421                 && removeAction.isEnabled()) {
422             removeAction.run();
423         }
424     }
425
426     /**
427      * Handles a selection change.
428      *
429      * @param selection the new selection
430      */

431     void handleSelectionChanged(IStructuredSelection selection) {
432         //update the actions
433
openAction.selectionChanged(selection);
434         removeAction.selectionChanged(selection);
435         editAction.selectionChanged(selection);
436         selectAllAction.selectionChanged(selection);
437         showInNavigatorAction.selectionChanged(selection);
438     }
439
440     /* (non-Javadoc)
441      * Method declared on IViewPart.
442      */

443     public void init(IViewSite site, IMemento memento) throws PartInitException {
444         super.init(site, memento);
445         this.memento = memento;
446     }
447
448     /**
449      * Adds drag and drop support to the bookmark navigator.
450      */

451     protected void initDragAndDrop() {
452         int operations = DND.DROP_COPY;
453         Transfer[] transferTypes = new Transfer[] {
454                 MarkerTransfer.getInstance(), TextTransfer.getInstance() };
455         DragSourceListener listener = new DragSourceAdapter() {
456             public void dragSetData(DragSourceEvent event) {
457                 performDragSetData(event);
458             }
459
460             public void dragFinished(DragSourceEvent event) {
461             }
462         };
463         viewer.addDragSupport(operations, transferTypes, listener);
464     }
465
466     /**
467      * The user is attempting to drag marker data. Add the appropriate
468      * data to the event depending on the transfer type.
469      */

470     void performDragSetData(DragSourceEvent event) {
471         if (MarkerTransfer.getInstance().isSupportedType(event.dataType)) {
472             event.data = ((IStructuredSelection) viewer.getSelection())
473                     .toArray();
474             return;
475         }
476         if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
477             Object JavaDoc[] markers = ((IStructuredSelection) viewer.getSelection())
478                     .toArray();
479             if (markers != null) {
480                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
481                 ILabelProvider provider = (ILabelProvider) getViewer()
482                         .getLabelProvider();
483                 for (int i = 0; i < markers.length; i++) {
484                     if (i > 0) {
485                         buffer.append(System.getProperty("line.separator")); //$NON-NLS-1$
486
}
487                     String JavaDoc text = provider.getText(markers[i]);
488                     if(text != null) {
489                         buffer.append(text);
490                     }
491                 }
492                 event.data = buffer.toString();
493             }
494             return;
495         }
496     }
497
498     void restoreState(IMemento memento) {
499         IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
500         IMemento selectionMem = memento.getChild(TAG_SELECTION);
501         if (selectionMem != null) {
502             ArrayList JavaDoc selectionList = new ArrayList JavaDoc();
503             IMemento markerMems[] = selectionMem.getChildren(TAG_MARKER);
504             for (int i = 0; i < markerMems.length; i++) {
505                 try {
506                     long id = new Long JavaDoc(markerMems[i].getString(TAG_ID))
507                             .longValue();
508                     IResource resource = root.findMember(markerMems[i]
509                             .getString(TAG_RESOURCE));
510                     if (resource != null) {
511                         IMarker marker = resource.findMarker(id);
512                         if (marker != null) {
513                             selectionList.add(marker);
514                         }
515                     }
516                 } catch (CoreException e) {
517                 }
518             }
519             viewer.setSelection(new StructuredSelection(selectionList));
520         }
521
522         Scrollable scrollable = (Scrollable) viewer.getControl();
523         //save vertical position
524
ScrollBar bar = scrollable.getVerticalBar();
525         if (bar != null) {
526             try {
527                 String JavaDoc posStr = memento.getString(TAG_VERTICAL_POSITION);
528                 int position;
529                 position = new Integer JavaDoc(posStr).intValue();
530                 bar.setSelection(position);
531             } catch (NumberFormatException JavaDoc e) {
532             }
533         }
534         bar = scrollable.getHorizontalBar();
535         if (bar != null) {
536             try {
537                 String JavaDoc posStr = memento.getString(TAG_HORIZONTAL_POSITION);
538                 int position;
539                 position = new Integer JavaDoc(posStr).intValue();
540                 bar.setSelection(position);
541             } catch (NumberFormatException JavaDoc e) {
542             }
543         }
544
545         updateSortState();
546         viewer.refresh();
547     }
548
549     public void saveState(IMemento memento) {
550         if (viewer == null) {
551             if (this.memento != null) {
552                 memento.putMemento(this.memento);
553             }
554             return;
555         }
556
557         Scrollable scrollable = (Scrollable) viewer.getControl();
558         Object JavaDoc markers[] = ((IStructuredSelection) viewer.getSelection())
559                 .toArray();
560         if (markers.length > 0) {
561             IMemento selectionMem = memento.createChild(TAG_SELECTION);
562             for (int i = 0; i < markers.length; i++) {
563                 IMemento elementMem = selectionMem.createChild(TAG_MARKER);
564                 IMarker marker = (IMarker) markers[i];
565                 elementMem.putString(TAG_RESOURCE, marker.getResource()
566                         .getFullPath().toString());
567                 elementMem.putString(TAG_ID, String.valueOf(marker.getId()));
568             }
569         }
570
571         //save vertical position
572
ScrollBar bar = scrollable.getVerticalBar();
573         int position = bar != null ? bar.getSelection() : 0;
574         memento.putString(TAG_VERTICAL_POSITION, String.valueOf(position));
575         //save horizontal position
576
bar = scrollable.getHorizontalBar();
577         position = bar != null ? bar.getSelection() : 0;
578         memento.putString(TAG_HORIZONTAL_POSITION, String.valueOf(position));
579
580     }
581
582     /* (non-Javadoc)
583      * Method declared on IWorkbenchPart.
584      */

585     public void setFocus() {
586         if (viewer != null) {
587             viewer.getControl().setFocus();
588         }
589     }
590
591     void createColumns() {
592         SelectionListener headerListener = new SelectionAdapter() {
593             /**
594              * Handles the case of user selecting the
595              * header area.
596              * <p>If the column has not been selected previously,
597              * it will set the sorter of that column to be
598              * the current tasklist sorter. Repeated
599              * presses on the same column header will
600              * toggle sorting order (ascending/descending).
601              */

602             public void widgetSelected(SelectionEvent e) {
603                 // column selected - first column doesn't count
604
int column = table.indexOf((TableColumn) e.widget) - 1;
605                 if (column == comparator.getTopPriority()) {
606                     comparator.reverseTopPriority();
607                 } else {
608                     comparator.setTopPriority(column);
609                 }
610                 updateSortState();
611                 viewer.refresh();
612                 IDialogSettings workbenchSettings = getPlugin()
613                         .getDialogSettings();
614                 IDialogSettings settings = workbenchSettings
615                         .getSection("BookmarkSortState");//$NON-NLS-1$
616
if (settings == null) {
617                     settings = workbenchSettings
618                             .addNewSection("BookmarkSortState");//$NON-NLS-1$
619
}
620                 comparator.saveState(settings);
621             }
622         };
623
624         TableLayout layout = new TableLayout();
625         table.setLayout(layout);
626         table.setHeaderVisible(true);
627         for (int i = 0; i < columnHeaders.length; i++) {
628             layout.addColumnData(columnLayouts[i]);
629             TableColumn tc = new TableColumn(table, SWT.NONE, i);
630             tc.setResizable(columnLayouts[i].resizable);
631             tc.setText(columnHeaders[i]);
632             if (i > 0) {
633                 tc.addSelectionListener(headerListener);
634             }
635         }
636     }
637
638     /**
639      * Creates the table control.
640      */

641     void createTable(Composite parent) {
642         table = new Table(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI
643                 | SWT.FULL_SELECTION);
644         table.setLinesVisible(true);
645         //table.setLayout(new TableLayout());
646
}
647
648     /**
649      * Fills the local tool bar and menu manager with actions.
650      */

651     void fillActionBars() {
652         IActionBars actionBars = getViewSite().getActionBars();
653         IMenuManager menu = actionBars.getMenuManager();
654         IMenuManager submenu = new MenuManager(BookmarkMessages.SortMenuGroup_text);
655         menu.add(submenu);
656         submenu.add(sortByDescriptionAction);
657         submenu.add(sortByResourceAction);
658         submenu.add(sortByFolderAction);
659         submenu.add(sortByLineAction);
660         submenu.add(sortByCreationTime);
661         submenu.add(new Separator());
662         submenu.add(sortAscendingAction);
663         submenu.add(sortDescendingAction);
664     }
665
666     void createSortActions() {
667         sortByDescriptionAction = new SortByAction(BookmarkSorter.DESCRIPTION);
668         sortByDescriptionAction.setText(BookmarkMessages.ColumnDescription_text);
669         PlatformUI.getWorkbench().getHelpSystem().setHelp(
670                 sortByDescriptionAction,
671                 IBookmarkHelpContextIds.SORT_DESCRIPTION_ACTION);
672
673         sortByResourceAction = new SortByAction(BookmarkSorter.RESOURCE);
674         sortByResourceAction.setText(BookmarkMessages.ColumnResource_text);
675         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortByResourceAction,
676                 IBookmarkHelpContextIds.SORT_RESOURCE_ACTION);
677
678         sortByFolderAction = new SortByAction(BookmarkSorter.FOLDER);
679         sortByFolderAction.setText(BookmarkMessages.ColumnFolder_text);
680         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortByFolderAction,
681                 IBookmarkHelpContextIds.SORT_FOLDER_ACTION);
682
683         sortByLineAction = new SortByAction(BookmarkSorter.LOCATION);
684         sortByLineAction.setText(BookmarkMessages.ColumnLocation_text);
685         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortByLineAction,
686                 IBookmarkHelpContextIds.SORT_LOCATION_ACTION);
687
688         sortByCreationTime = new SortByAction(BookmarkSorter.CREATION_TIME);
689         sortByCreationTime.setText(BookmarkMessages.ColumnCreationTime_text);
690         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortByCreationTime,
691                 IBookmarkHelpContextIds.SORT_CREATION_TIME_ACTION);
692
693         sortAscendingAction = new ChangeSortDirectionAction(
694                 BookmarkSorter.ASCENDING);
695         sortAscendingAction.setText(BookmarkMessages.SortDirectionAscending_text);
696         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortAscendingAction,
697                 IBookmarkHelpContextIds.SORT_ASCENDING_ACTION);
698
699         sortDescendingAction = new ChangeSortDirectionAction(
700                 BookmarkSorter.DESCENDING);
701         sortDescendingAction.setText(BookmarkMessages.SortDirectionDescending_text);
702         PlatformUI.getWorkbench().getHelpSystem().setHelp(sortDescendingAction,
703                 IBookmarkHelpContextIds.SORT_DESCENDING_ACTION);
704     }
705
706     void updateSortState() {
707         int column = comparator.getTopPriority();
708         sortByDescriptionAction
709                 .setChecked(column == BookmarkSorter.DESCRIPTION);
710         sortByResourceAction.setChecked(column == BookmarkSorter.RESOURCE);
711         sortByFolderAction.setChecked(column == BookmarkSorter.FOLDER);
712         sortByLineAction.setChecked(column == BookmarkSorter.LOCATION);
713         sortByCreationTime.setChecked(column == BookmarkSorter.CREATION_TIME);
714
715         int direction = comparator.getTopPriorityDirection();
716         sortAscendingAction.setChecked(direction == BookmarkSorter.ASCENDING);
717         sortDescendingAction.setChecked(direction == BookmarkSorter.DESCENDING);
718     }
719
720     /**
721      * Updates the enablement of the paste action
722      */

723     void updatePasteEnablement() {
724         // Paste if clipboard contains tasks
725
MarkerTransfer transfer = MarkerTransfer.getInstance();
726         IMarker[] markerData = (IMarker[]) getClipboard().getContents(transfer);
727         boolean canPaste = false;
728         if (markerData != null) {
729             for (int i = 0; i < markerData.length; i++) {
730                 try {
731                     if (markerData[i].getType().equals(IMarker.BOOKMARK)) {
732                         canPaste = true;
733                         break;
734                     }
735                 } catch (CoreException e) {
736                     canPaste = false;
737                 }
738             }
739         }
740         pasteAction.setEnabled(canPaste);
741     }
742
743     Clipboard getClipboard() {
744         return clipboard;
745     }
746
747 }
748
749
Popular Tags