Merge forgetten class from Sebastian Raffel's work

git-svn-id: https://pmd.svn.sourceforge.net/svnroot/pmd/trunk@3952 51baf565-9d33-0410-a72c-fc3788e3496d
This commit is contained in:
Philippe Herlin
2005-11-03 21:25:12 +00:00
parent 38393a62ec
commit 3a44820f7d

View File

@ -0,0 +1,80 @@
package net.sourceforge.pmd.eclipse.actions;
import net.sourceforge.pmd.eclipse.PMDConstants;
import net.sourceforge.pmd.eclipse.PMDPlugin;
import net.sourceforge.pmd.eclipse.views.DataflowView;
import org.eclipse.core.resources.IResource;
import org.eclipse.jdt.core.IMethod;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PartInitException;
/**
*
* @author SebastianRaffel ( 26.05.2005 )
*/
public class ShowDataflowAction implements IObjectActionDelegate {
private IWorkbenchPage workbenchPage;
private DataflowView dataflowView;
private IResource resource;
private IMethod method;
/* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart) */
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
workbenchPage = targetPart.getSite().getPage();
}
/* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction) */
public void run(IAction action) {
if (workbenchPage != null) {
try {
dataflowView = (DataflowView)
workbenchPage.showView(PMDPlugin.ID_DATAFLOWVIEW);
if (method != null)
dataflowView.showMethod(method);
} catch (PartInitException pie) {
PMDPlugin.getDefault().logError(
PMDConstants.MSGKEY_ERROR_VIEW_EXCEPTION +
this.toString(), pie);
}
}
}
/* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection) */
public void selectionChanged(IAction action, ISelection selection) {
if (!PMDPlugin.getDefault().useDFA()) {
action.setEnabled(false);
return;
} else {
action.setEnabled(true);
}
if (selection instanceof IStructuredSelection) {
IStructuredSelection sel = (IStructuredSelection) selection;
Object element = sel.getFirstElement();
method = null;
resource = null;
if (element instanceof IMethod) {
method = (IMethod) element;
resource = method.getResource();
}
}
}
}