package com.quantum.view.bookmark; import com.quantum.Messages; import com.quantum.model.Bookmark; import org.eclipse.jface.dialogs.InputDialog; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IViewPart; import org.eclipse.ui.actions.SelectionListenerAction; /** * @author BC */ public class RenameAction extends SelectionListenerAction { private IViewPart viewPart; /** * @param text */ protected RenameAction(IViewPart viewPart) { super(Messages.getString(RenameAction.class.getName() + ".text")); this.viewPart = viewPart; } /** * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection) */ protected boolean updateSelection(IStructuredSelection selection) { boolean enabled = super.updateSelection(selection); return enabled & selection.size() == 1 & selection.getFirstElement() instanceof BookmarkNode; } private Bookmark getBookmark() { return ((BookmarkNode) getSelectedNonResources().get(0)).getBookmark(); } /** * @see org.eclipse.jface.action.IAction#run() */ public void run() { InputDialog dialog = new InputDialog(this.viewPart.getSite().getShell(), "Select a new name", "Name: ", getBookmark().getName(), null); int result = dialog.open(); if (result == InputDialog.OK) { getBookmark().setName(dialog.getValue()); } } }