fd1cb21f7cc69184d127ef62ae1943ac80e21b29
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / 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.phpeclipse.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.IObjectActionDelegate;
23 import org.eclipse.ui.IWorkbenchPart;
24
25
26 public class PHPExternalParserAction implements IObjectActionDelegate {
27
28   private IWorkbenchPart workbenchPart;
29   /**
30    * Constructor for Action1.
31    */
32   public PHPExternalParserAction() {
33     super();
34   }
35
36   /**
37    * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
38    */
39   public void setActivePart(IAction action, IWorkbenchPart targetPart) {
40     workbenchPart = targetPart;
41   }
42
43   //  public static void open(final URL url, final Shell shell, final String dialogTitle) {
44   //    IHelp help= WorkbenchHelp.getHelpSupport();
45   //    if (help != null) {
46   //      WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
47   //    } else {
48   //      showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
49   //    }
50   //  }
51
52   public void run(IAction action) {
53     ISelectionProvider selectionProvider = null;
54     selectionProvider = workbenchPart.getSite().getSelectionProvider();
55
56     StructuredSelection selection = null;
57     selection = (StructuredSelection) selectionProvider.getSelection();
58
59     //Shell shell = null;
60     Iterator iterator = null;
61     iterator = selection.iterator();
62     while (iterator.hasNext()) {
63       //  obj => selected object in the view
64       Object obj = iterator.next();
65
66       // is it a resource
67       if (obj instanceof IResource) {
68         IResource resource = (IResource) obj;
69
70         // check if it's a file resource
71         switch (resource.getType()) {
72  
73           case IResource.FILE :
74             // single file:
75           ExternalPHPParser parser = new ExternalPHPParser((IFile)resource);
76           parser.phpExternalParse();
77         }
78       }
79     }
80   }
81
82   /**
83    * @see IActionDelegate#selectionChanged(IAction, ISelection)
84    */
85   public void selectionChanged(IAction action, ISelection selection) {
86   }
87
88 }