1) CLASSNAME is specified by the property 'name' == CLASSNAME. When doing it by the...
[phpeclipse.git] / net.sourceforge.phpeclipse.test / src / net / sourceforge / phpeclipse / example / outline / Import2Console.java
1 package net.sourceforge.phpeclipse.example.outline;
2
3 import net.sourceforge.phpdt.core.IImportDeclaration;
4
5 import org.eclipse.core.resources.IWorkspace;
6 import org.eclipse.core.resources.ResourcesPlugin;
7 import org.eclipse.jface.action.IAction;
8 import org.eclipse.jface.viewers.ISelection;
9 import org.eclipse.jface.viewers.IStructuredSelection;
10 import org.eclipse.ui.IActionDelegate;
11 import org.eclipse.ui.IObjectActionDelegate;
12 import org.eclipse.ui.IWorkbenchPart;
13 import org.eclipse.ui.IWorkbenchPartSite;
14
15 public class Import2Console implements IObjectActionDelegate {
16
17         private IWorkbenchPartSite myPartSite = null;
18
19         private IWorkspace myWorkspace = null;
20
21         private IWorkbenchPart myWorkbenchPart = null;
22
23         private IImportDeclaration myType = null;
24
25         public Import2Console() {
26                 // this(new PackageSelector());
27         }
28
29         // public CreateMock(IPackageSelector aPackageSelector) {
30         // myPackageSelector = aPackageSelector;
31         // }
32
33         /**
34          * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
35          */
36         public void setActivePart(IAction action, IWorkbenchPart targetPart) {
37                 myWorkspace = ResourcesPlugin.getWorkspace();
38                 myWorkbenchPart = targetPart;
39         }
40
41         /**
42          * @see IActionDelegate#run(IAction)
43          */
44         public void run(IAction action) {
45                 try {
46                         String actionId = action.getId();
47                         showSourceInConsole(actionId);
48                 } catch (Exception e) {
49                         e.printStackTrace();
50                 }
51         }
52
53         /**
54          * @see IActionDelegate#selectionChanged(IAction, ISelection)
55          */
56         public void selectionChanged(IAction action, ISelection selection) {
57                 if (selection instanceof IStructuredSelection) {
58                         Object item = ((IStructuredSelection) selection).getFirstElement();
59                         myType = (IImportDeclaration) item; // this plugin only reacts to
60                                                                                                 // IImportDeclaration's
61                 }
62         }
63
64         private void showSourceInConsole(String actionId) throws Exception {
65
66                 String src = myType.getSource();
67                 System.out.println(actionId);
68                 System.out.println("Source :" + src);
69
70         }
71
72 }