initial quantum version
[phpeclipse.git] / archive / net.sourceforge.phpeclipse.quantum.sql / src / com / quantum / view / bookmark / PasteAction.java
1 package com.quantum.view.bookmark;
2
3 import com.quantum.Messages;
4 import com.quantum.QuantumPlugin;
5 import com.quantum.model.Bookmark;
6 import com.quantum.model.BookmarkCollection;
7
8 import org.eclipse.jface.viewers.ISelectionProvider;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.ui.IViewPart;
11 import org.eclipse.ui.actions.SelectionListenerAction;
12
13
14 final class PasteAction extends SelectionListenerAction {
15     private IViewPart view;
16     private BookmarkClipboard bookmarkClipboard;
17     /**
18      * @param BookmarkView
19      */
20     public PasteAction(IViewPart view, BookmarkClipboard bookmarkClipboard, 
21         ISelectionProvider selectionProvider) {
22         super(Messages.getString(PasteAction.class.getName() + ".text"));
23         setImageDescriptor(QuantumPlugin.getImageDescriptor("paste.gif"));
24         this.view = view;
25         selectionProvider.addSelectionChangedListener(this);
26         this.bookmarkClipboard = bookmarkClipboard;
27     }
28     public void run() {
29                 if (this.bookmarkClipboard.getBookmark() != null) {
30                         Bookmark bookmark = new Bookmark(this.bookmarkClipboard.getBookmark());
31                         String copyName = BookmarkCollection.getInstance().getCopyName(bookmark.getName());
32                         bookmark.setName(copyName); //$NON-NLS-1$
33                         BookmarkCollection.getInstance().addBookmark(bookmark);
34                 }
35         }
36     
37     /* (non-Javadoc)
38      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
39      */
40     protected boolean updateSelection(IStructuredSelection selection) {
41         boolean enabled = super.updateSelection(selection);
42         enabled &= this.bookmarkClipboard.getBookmark() != null;
43         return enabled;
44     }
45
46 }