KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > visualcontent > ui > nodetree > CopyXPathAction


1 package org.visualcontent.ui.nodetree;
2
3 import javax.jcr.Node;
4 import javax.jcr.RepositoryException;
5
6 import org.eclipse.jface.action.Action;
7 import org.eclipse.jface.action.IAction;
8 import org.eclipse.jface.dialogs.MessageDialog;
9 import org.eclipse.jface.viewers.ISelection;
10 import org.eclipse.jface.viewers.IStructuredSelection;
11 import org.eclipse.jface.viewers.StructuredSelection;
12 import org.eclipse.swt.dnd.TextTransfer;
13 import org.eclipse.swt.dnd.Transfer;
14 import org.eclipse.swt.widgets.Shell;
15 import org.eclipse.ui.IObjectActionDelegate;
16 import org.eclipse.ui.ISelectionListener;
17 import org.eclipse.ui.IWorkbenchPart;
18 import org.visualcontent.ui.UiPlugin;
19 import org.visualcontent.ui.nodetree.NodeTreeViewPart;
20
21 public class CopyXPathAction extends Action implements ISelectionListener{
22
23     private NodeTreeViewPart view;
24     private ISelection selection;
25
26     /**
27      * Constructor for Action1.
28      * @param text
29      */

30     public CopyXPathAction(NodeTreeViewPart aView, String JavaDoc text) {
31         super(text);
32         this.view = aView;
33         this.view.getSite().getPage().addSelectionListener(
34                 "org.visualcontent.ui.nodetree.NodeTreeViewPart", (ISelectionListener) this);
35
36     }
37
38     /**
39      */

40     public void run() {
41         if (selection instanceof IStructuredSelection){
42             IStructuredSelection structuredSelection = (IStructuredSelection) selection;
43             Object JavaDoc nodeObj = structuredSelection.getFirstElement();
44             if ( nodeObj instanceof Node){
45                 Node node = (Node) nodeObj;
46                 String JavaDoc path = null;
47                 try {
48                     path = node.getPath();
49                 } catch (RepositoryException e) {
50                     UiPlugin.getDefault().showError("Could not get the path of the node.",e);
51                 }
52                 view.getClipboard().setContents(new Object JavaDoc[]{path}, new Transfer[]{TextTransfer.getInstance()});
53             }
54         }
55     }
56     
57     // Implement the method defined in ISelectionListener, to consume UI
58
// selections
59
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
60         this.selection=selection;
61     }
62 }
63
Popular Tags