420c23a2f9eda4809d64bea4857a70bb606d80db
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpeclipse / actions / PHPDocumentorAction.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 net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
18
19 import org.eclipse.core.resources.IProject;
20 import org.eclipse.core.resources.IResource;
21 import org.eclipse.jface.action.IAction;
22 import org.eclipse.jface.preference.IPreferenceStore;
23 import org.eclipse.jface.viewers.ISelection;
24 import org.eclipse.jface.viewers.ISelectionProvider;
25 import org.eclipse.jface.viewers.StructuredSelection;
26 import org.eclipse.ui.IActionDelegate;
27 import org.eclipse.ui.IObjectActionDelegate;
28 import org.eclipse.ui.IWorkbenchPart;
29
30 public class PHPDocumentorAction implements IObjectActionDelegate {
31
32   private IWorkbenchPart workbenchPart;
33   /**
34    * Constructor for Action1.
35    */
36   public PHPDocumentorAction() {
37     super();
38   }
39
40   /**
41    * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
42    */
43   public void setActivePart(IAction action, IWorkbenchPart targetPart) {
44     workbenchPart = targetPart;
45   }
46
47   //  public static void open(final URL url, final Shell shell, final String dialogTitle) {
48   //    IHelp help= WorkbenchHelp.getHelpSupport();
49   //    if (help != null) {
50   //      WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
51   //    } else {
52   //      showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$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     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
64     final String phpExecutable = store.getString(PHPeclipsePlugin.PHP_RUN_PREF);
65
66     //Shell shell = null;
67     Iterator iterator = null;
68     iterator = selection.iterator();
69     while (iterator.hasNext()) {
70       //  obj => selected object in the view
71       Object obj = iterator.next();
72
73       // is it a resource
74       if (obj instanceof IResource) {
75         IResource resource = (IResource) obj;
76
77         // check the resource
78         switch (resource.getType()) {
79           case IResource.PROJECT :
80             IProject project = (IProject) resource;
81             String projectName = project.getLocation().toString();
82             String targetDirectory = projectName + "/phpdoc";
83             // example: 
84             // C:\>php.exe "C:\Path\To\phpdoc" -t targetdir -o HTML:default:default -d parsedir
85             String argument =
86               "\"C:\\php\\phpDocumentor\\phpdoc\" -t " + targetDirectory + " -o HTML:default:default -d " + projectName;
87             ExternalToolsUtil.execute("phpdocumentor", phpExecutable, argument, true);
88             break;
89             //          case IResource.FILE :
90             //            // single file:
91             //            IFile file = (IFile) resource;
92             //            PHPParserSuperclass.phpExternalParse(file);
93         }
94       }
95     }
96   }
97
98   /**
99    * @see IActionDelegate#selectionChanged(IAction, ISelection)
100    */
101   public void selectionChanged(IAction action, ISelection selection) {
102   }
103
104 }