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
9 IBM Corporation - Initial implementation
11 **********************************************************************/
12 package net.sourceforge.phpeclipse.actions;
14 import java.util.Iterator;
16 import net.sourceforge.phpdt.externaltools.launchConfigurations.ExternalToolsUtil;
17 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
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;
30 public class PHPDocumentorAction implements IObjectActionDelegate {
32 private IWorkbenchPart workbenchPart;
34 * Constructor for Action1.
36 public PHPDocumentorAction() {
41 * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
43 public void setActivePart(IAction action, IWorkbenchPart targetPart) {
44 workbenchPart = targetPart;
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());
52 // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$
56 public void run(IAction action) {
57 ISelectionProvider selectionProvider = null;
58 selectionProvider = workbenchPart.getSite().getSelectionProvider();
60 StructuredSelection selection = null;
61 selection = (StructuredSelection) selectionProvider.getSelection();
63 final IPreferenceStore store = PHPeclipsePlugin.getDefault().getPreferenceStore();
64 final String phpExecutable = store.getString(PHPeclipsePlugin.PHP_RUN_PREF);
67 Iterator iterator = null;
68 iterator = selection.iterator();
69 while (iterator.hasNext()) {
70 // obj => selected object in the view
71 Object obj = iterator.next();
74 if (obj instanceof IResource) {
75 IResource resource = (IResource) obj;
78 switch (resource.getType()) {
79 case IResource.PROJECT :
80 IProject project = (IProject) resource;
81 String projectName = project.getLocation().toString();
82 String targetDirectory = projectName + "/phpdoc";
84 // C:\>php.exe "C:\Path\To\phpdoc" -t targetdir -o HTML:default:default -d parsedir
86 "\"C:\\php\\phpDocumentor\\phpdoc\" -t " + targetDirectory + " -o HTML:default:default -d " + projectName;
87 ExternalToolsUtil.execute("phpdocumentor", phpExecutable, argument, true);
89 // case IResource.FILE :
91 // IFile file = (IFile) resource;
92 // PHPParserSuperclass.phpExternalParse(file);
99 * @see IActionDelegate#selectionChanged(IAction, ISelection)
101 public void selectionChanged(IAction action, ISelection selection) {