1 package com.quantum.view.bookmark;
3 import java.beans.PropertyChangeEvent;
4 import java.beans.PropertyChangeListener;
6 import org.eclipse.jface.viewers.IStructuredSelection;
7 import org.eclipse.jface.wizard.Wizard;
8 import org.eclipse.jface.wizard.WizardDialog;
9 import org.eclipse.ui.IViewPart;
10 import org.eclipse.ui.actions.SelectionListenerAction;
12 import com.quantum.Messages;
13 import com.quantum.model.Bookmark;
14 import com.quantum.wizards.BookmarkNameWizardPage;
19 public class RenameAction extends SelectionListenerAction {
21 public class RenameWizard extends Wizard implements PropertyChangeListener {
23 private BookmarkNameWizardPage page;
26 public RenameWizard(String name) {
30 public void addPages() {
32 this.page = new BookmarkNameWizardPage("pageName", this.name);
33 this.page.addPropertyChangeListener(this);
37 public void dispose() {
38 this.page.removePropertyChangeListener(this);
41 public boolean performFinish() {
45 public void propertyChange(PropertyChangeEvent event) {
46 if ("name".equals(event.getPropertyName())) {
47 setName((String) event.getNewValue());
51 public String getName() {
54 public void setName(String name) {
60 private IViewPart viewPart;
65 protected RenameAction(IViewPart viewPart) {
66 super(Messages.getString(RenameAction.class.getName() + ".text"));
67 this.viewPart = viewPart;
71 * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
73 protected boolean updateSelection(IStructuredSelection selection) {
74 boolean enabled = super.updateSelection(selection);
75 return enabled & selection.size() == 1 &
76 selection.getFirstElement() instanceof BookmarkNode;
79 private Bookmark getBookmark() {
80 return ((BookmarkNode) getSelectedNonResources().get(0)).getBookmark();
84 * @see org.eclipse.jface.action.IAction#run()
87 RenameWizard wizard = new RenameWizard(getBookmark().getName());
88 WizardDialog dialog = new WizardDialog(this.viewPart.getSite().getShell(), wizard);
89 int result = dialog.open();
90 if (result == WizardDialog.OK) {
91 getBookmark().setName(wizard.getName());