- added include declarations to Outline view
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / RenameAction.java
1 package com.quantum.view.bookmark;
2
3 import com.quantum.Messages;
4 import com.quantum.model.Bookmark;
5
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;
10
11 /**
12  * @author BC
13  */
14 public class RenameAction extends SelectionListenerAction {
15
16     private IViewPart viewPart;
17
18     /**
19      * @param text
20      */
21     protected RenameAction(IViewPart viewPart) {
22         super(Messages.getString(RenameAction.class.getName() + ".text"));
23         this.viewPart = viewPart;
24     }
25     
26     
27
28     /**
29      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
30      */
31     protected boolean updateSelection(IStructuredSelection selection) {
32         boolean enabled = super.updateSelection(selection);
33         return enabled & selection.size() == 1 & 
34             selection.getFirstElement() instanceof BookmarkNode;
35     }
36     
37     private Bookmark getBookmark() {
38         return ((BookmarkNode) getSelectedNonResources().get(0)).getBookmark();
39     }
40
41     /**
42      * @see org.eclipse.jface.action.IAction#run()
43      */
44     public void 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());
50         }
51     }
52 }