// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: EasyLookAction.java
package org.jxc.easylook.popup.actions;
import java.io.File;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.core.PackageFragment;
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.IWorkbenchPart;
public class EasyLookAction
implements IObjectActionDelegate
{
private Object selected;
private Class selectedClass;
public EasyLookAction()
{
selected = null;
selectedClass = null;
}
public void setActivePart(IAction iaction, IWorkbenchPart iworkbenchpart)
{
}
public void run(IAction action)
{
if (selected == null)
return;
File directory = null;
if (selected instanceof IResource)
directory = new File(((IResource)selected).getLocation().toOSString());
if (selected instanceof IFile)
directory = directory.getParentFile();
if (directory == null)
return;
try
{
Runtime.getRuntime().exec((new StringBuilder("explorer.exe /n,")).append(directory.toString()).toString());
}
catch (Exception ) { }
}
public void selectionChanged(IAction action, ISelection selection)
{
try
{
IAdaptable adaptable = null;
selected = "unknown";
if (selection instanceof IStructuredSelection)
{
adaptable = (IAdaptable)((IStructuredSelection)selection).getFirstElement();
selectedClass = adaptable.getClass();
if (adaptable instanceof IResource)
selected = (IResource)adaptable;
else
if ((adaptable instanceof PackageFragment) && (((PackageFragment)adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot))
selected = getJarFile(((PackageFragment)adaptable).getPackageFragmentRoot());
else
if (adaptable instanceof JarPackageFragmentRoot)
selected = getJarFile(adaptable);
else
selected = (IResource)adaptable.getAdapter(org/eclipse/core/resources/IResource);
}
}
catch (Throwable ) { }
}
protected File getJarFile(IAdaptable adaptable)
{
JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot)adaptable;
File selected = jpfr.getPath().makeAbsolute().toFile();
if (!selected.exists())
{
File projectFile = new File(jpfr.getJavaProject().getProject().getLocation().toOSString());
selected = new File((new StringBuilder(String.valueOf(projectFile.getParent()))).append(selected.toString()).toString());
}
return selected;
}
}