KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.eclipse.core.resources.IFile;
15 import org.eclipse.core.resources.IMarker;
16 import org.eclipse.core.resources.IResource;
17 import org.eclipse.jface.viewers.IStructuredSelection;
18 import org.eclipse.ui.PlatformUI;
19 import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages;
20
21 /**
22  * Opens a properties dialog allowing the user to edit the bookmark's description.
23  */

24 class EditBookmarkAction extends BookmarkAction {
25
26     protected EditBookmarkAction(BookmarkNavigator view) {
27         super(view, BookmarkMessages.Properties_text);
28         PlatformUI.getWorkbench().getHelpSystem().setHelp(this,
29                 IBookmarkHelpContextIds.BOOKMARK_PROPERTIES_ACTION);
30         setEnabled(false);
31     }
32
33     private IMarker marker;
34
35     public void run() {
36         if (marker != null) {
37             editBookmark();
38         }
39     }
40
41     /**
42      * Sets marker to the current selection if the selection is an instance of
43      * <code>org.eclipse.core.resources.IMarker<code> and the selected marker's
44      * resource is an instance of <code>org.eclipse.core.resources.IFile<code>.
45      * Otherwise sets marker to null.
46      */

47     public void selectionChanged(IStructuredSelection selection) {
48         marker = null;
49         setEnabled(false);
50
51         if (selection.size() != 1) {
52             return;
53         }
54
55         Object JavaDoc o = selection.getFirstElement();
56         if (!(o instanceof IMarker)) {
57             return;
58         }
59
60         IMarker selectedMarker = (IMarker) o;
61         IResource resource = selectedMarker.getResource();
62         if (resource instanceof IFile) {
63             marker = selectedMarker;
64             setEnabled(true);
65         }
66     }
67
68     private void editBookmark() {
69         BookmarkPropertiesDialog dialog = new BookmarkPropertiesDialog(
70                 getView().getSite().getShell());
71         dialog.setMarker(marker);
72         dialog.open();
73     }
74 }
75
Popular Tags