deletet because wrongly uploaded
[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     Klaus Hartlage - www.eclipseproject.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.IObjectActionDelegate;
27 import org.eclipse.ui.IWorkbenchPart;
28
29 public class PHPDocumentorAction implements IObjectActionDelegate {
30
31   private IWorkbenchPart workbenchPart;
32   /**
33    * Constructor for Action1.
34    */
35   public PHPDocumentorAction() {
36     super();
37   }
38
39   /**
40    * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
41    */
42   public void setActivePart(IAction action, IWorkbenchPart targetPart) {
43     workbenchPart = targetPart;
44   }
45
46   //  public static void open(final URL url, final Shell shell, final String dialogTitle) {
47   //    IHelp help= WorkbenchHelp.getHelpSupport();
48   //    if (help != null) {
49   //      WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm());
50   //    } else {
51   //      showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
52   //    }
53   //  }
54
55   public void run(IAction action) {
56     ISelectionProvider selectionProvider = null;
57     selectionProvider = workbenchPart.getSite().getSelectionProvider();
58
59     StructuredSelection selection = null;
60     selection = (StructuredSelection) selectionProvider.getSelection();
61
62     final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
63     final String phpExecutable = store.getString(PHPeclipsePlugin.PHP_RUN_PREF);
64
65     //Shell shell = null;
66     Iterator iterator = null;
67     iterator = selection.iterator();
68     while (iterator.hasNext()) {
69       //  obj => selected object in the view
70       Object obj = iterator.next();
71
72       // is it a resource
73       if (obj instanceof IResource) {
74         IResource resource = (IResource) obj;
75
76         // check the resource
77         switch (resource.getType()) {
78           case IResource.PROJECT :
79             IProject project = (IProject) resource;
80             String projectName = project.getLocation().toString();
81             String targetDirectory = projectName + "/phpdoc";
82             // example: 
83             // C:\>php.exe "C:\Path\To\phpdoc" -t targetdir -o HTML:default:default -d parsedir
84             String argument =
85               "\"C:\\php\\phpDocumentor\\phpdoc\" -t " + targetDirectory + " -o HTML:default:default -d " + projectName;
86             ExternalToolsUtil.execute("phpdocumentor", phpExecutable, argument, true);
87             break;
88             //          case IResource.FILE :
89             //            // single file:
90             //            IFile file = (IFile) resource;
91             //            PHPParserSuperclass.phpExternalParse(file);
92         }
93       }
94     }
95   }
96
97   /**
98    * @see IActionDelegate#selectionChanged(IAction, ISelection)
99    */
100   public void selectionChanged(IAction action, ISelection selection) {
101   }
102
103 }