1 package com.quantum.view.bookmark;
3 import com.quantum.Messages;
4 import com.quantum.model.Bookmark;
6 import org.eclipse.jface.dialogs.InputDialog;
7 import org.eclipse.jface.viewers.IStructuredSelection;
8 import org.eclipse.ui.IViewPart;
9 import org.eclipse.ui.actions.SelectionListenerAction;
14 public class RenameAction extends SelectionListenerAction {
16 private IViewPart viewPart;
21 protected RenameAction(IViewPart viewPart) {
22 super(Messages.getString(RenameAction.class.getName() + ".text"));
23 this.viewPart = viewPart;
29 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
31 protected boolean updateSelection(IStructuredSelection selection) {
32 boolean enabled = super.updateSelection(selection);
33 return enabled & selection.size() == 1 &
34 selection.getFirstElement() instanceof BookmarkNode;
37 private Bookmark getBookmark() {
38 return ((BookmarkNode) getSelectedNonResources().get(0)).getBookmark();
42 * @see org.eclipse.jface.action.IAction#run()
45 InputDialog dialog = new InputDialog(this.viewPart.getSite().getShell(), "Select a new name",
46 "Name: ", getBookmark().getName(), null);
47 int result = dialog.open();
48 if (result == InputDialog.OK) {
49 getBookmark().setName(dialog.getValue());