Refactory: nl1 plugin.
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / actions / PHPExternalParserAction.java
1 /**********************************************************************
2  Copyright (c) 2000, 2002 IBM Corp. and others.
3  All rights reserved. This program and the accompanying materials
4  are made available under the terms of the Common Public License v1.0
5  which accompanies this distribution, and is available at
6  http://www.eclipse.org/legal/cpl-v10.html
7
8  Contributors:
9  IBM Corporation - Initial implementation
10  www.phpeclipse.de
11  **********************************************************************/
12 package net.sourceforge.phpdt.externaltools.actions;
13
14 import java.util.Iterator;
15
16 import org.eclipse.core.resources.IFile;
17 import org.eclipse.core.resources.IResource;
18 import org.eclipse.jface.action.IAction;
19 import org.eclipse.jface.viewers.ISelection;
20 import org.eclipse.jface.viewers.ISelectionProvider;
21 import org.eclipse.jface.viewers.StructuredSelection;
22 import org.eclipse.ui.IActionDelegate;
23 import org.eclipse.ui.IObjectActionDelegate;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 public class PHPExternalParserAction implements IObjectActionDelegate {
27
28         private IWorkbenchPart workbenchPart;
29
30         /**
31          * Constructor for Action1.
32          */
33         public PHPExternalParserAction() {
34                 super();
35         }
36
37         /**
38          * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
39          */
40         public void setActivePart(IAction action, IWorkbenchPart targetPart) {
41                 workbenchPart = targetPart;
42         }
43
44         // public static void open(final URL url, final Shell shell, final String
45         // dialogTitle) {
46         // IHelp help= WorkbenchHelp.getHelpSupport();
47         // if (help != null) {
48         // WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
49         // } else {
50         // showMessage(shell, dialogTitle,
51         // ActionMessages.getString("OpenBrowserUtil.help_not_available"), false);
52         // //$NON-NLS-1$
53         // }
54         // }
55
56         public void run(IAction action) {
57                 ISelectionProvider selectionProvider = null;
58                 selectionProvider = workbenchPart.getSite().getSelectionProvider();
59
60                 StructuredSelection selection = null;
61                 selection = (StructuredSelection) selectionProvider.getSelection();
62
63                 // Shell shell = null;
64                 Iterator iterator = null;
65                 iterator = selection.iterator();
66                 while (iterator.hasNext()) {
67                         // obj => selected object in the view
68                         Object obj = iterator.next();
69
70                         // is it a resource
71                         if (obj instanceof IResource) {
72                                 IResource resource = (IResource) obj;
73
74                                 // check if it's a file resource
75                                 switch (resource.getType()) {
76
77                                 case IResource.FILE:
78                                         // single file:
79                                         ExternalPHPParser parser = new ExternalPHPParser(
80                                                         (IFile) resource);
81                                         parser.phpExternalParse();
82                                 }
83                         }
84                 }
85         }
86
87         /**
88          * @see IActionDelegate#selectionChanged(IAction, ISelection)
89          */
90         public void selectionChanged(IAction action, ISelection selection) {
91         }
92
93 }