01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.views.bookmarkexplorer;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.resources.IMarker;
14: import org.eclipse.core.resources.IResource;
15: import org.eclipse.jface.viewers.IStructuredSelection;
16: import org.eclipse.ui.PlatformUI;
17: import org.eclipse.ui.internal.views.bookmarkexplorer.BookmarkMessages;
18:
19: /**
20: * Opens a properties dialog allowing the user to edit the bookmark's description.
21: */
22: class EditBookmarkAction extends BookmarkAction {
23:
24: protected EditBookmarkAction(BookmarkNavigator view) {
25: super (view, BookmarkMessages.Properties_text);
26: PlatformUI.getWorkbench().getHelpSystem().setHelp(this ,
27: IBookmarkHelpContextIds.BOOKMARK_PROPERTIES_ACTION);
28: setEnabled(false);
29: }
30:
31: private IMarker marker;
32:
33: public void run() {
34: if (marker != null) {
35: editBookmark();
36: }
37: }
38:
39: /**
40: * Sets marker to the current selection if the selection is an instance of
41: * <code>org.eclipse.core.resources.IMarker<code> and the selected marker's
42: * resource is an instance of <code>org.eclipse.core.resources.IFile<code>.
43: * Otherwise sets marker to null.
44: */
45: public void selectionChanged(IStructuredSelection selection) {
46: marker = null;
47: setEnabled(false);
48:
49: if (selection.size() != 1) {
50: return;
51: }
52:
53: Object o = selection.getFirstElement();
54: if (!(o instanceof IMarker)) {
55: return;
56: }
57:
58: IMarker selectedMarker = (IMarker) o;
59: IResource resource = selectedMarker.getResource();
60: if (resource instanceof IFile) {
61: marker = selectedMarker;
62: setEnabled(true);
63: }
64: }
65:
66: private void editBookmark() {
67: BookmarkPropertiesDialog dialog = new BookmarkPropertiesDialog(
68: getView().getSite().getShell());
69: dialog.setMarker(marker);
70: dialog.open();
71: }
72: }
|