Update of /cvsroot/easystruts/org.sf.easyexplore/src/org/sf/easyexplore/actions
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29857/src/org/sf/easyexplore/actions
Modified Files:
EasyExploreAction.java
Added Files:
EasyCommandAction.java EasyBaseAction.java
Log Message:
A small upgrade to run also a comamnd and get the right default command on windows... I use it all the time.
Index: EasyExploreAction.java
===================================================================
RCS file: /cvsroot/easystruts/org.sf.easyexplore/src/org/sf/easyexplore/actions/EasyExploreAction.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** EasyExploreAction.java 26 Jan 2006 20:37:56 -0000 1.1
--- EasyExploreAction.java 27 Jan 2006 02:31:11 -0000 1.2
***************
*** 1,125 ****
package org.sf.easyexplore.actions;
- import java.io.File;
- import java.text.MessageFormat;
-
- import org.sf.easyexplore.EasyExplorePlugin;
- import org.eclipse.core.resources.IFile;
- import org.eclipse.core.resources.IResource;
- import org.eclipse.core.runtime.IAdaptable;
- import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
- import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jface.action.IAction;
! import org.eclipse.jface.dialogs.MessageDialog;
! import org.eclipse.jface.viewers.ISelection;
! import org.eclipse.jface.viewers.IStructuredSelection;
! import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IObjectActionDelegate;
! import org.eclipse.ui.IWorkbenchPart;
!
! public class EasyExploreAction implements IObjectActionDelegate {
!
! private Object selected=null;
! private Class selectedClass=null;
! /**
! * Constructor for EasyExploreAction.
! */
! public EasyExploreAction() {
! super();
! }
! /**
! * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
! */
! public void setActivePart(IAction action, IWorkbenchPart targetPart) {
! }
! /**
! * @see IActionDelegate#run(IAction)
! */
! public void run(IAction action) {
try {
- if ( "unknown".equals(selected) ) {
- MessageDialog.openInformation(new Shell(),"Easy Explore","Unable to explore " + selectedClass.getName());
- EasyExplorePlugin.log("Unable to explore " + selectedClass);
- return;
- }
- File directory = null;
- if ( selected instanceof IResource ) {
- directory= new File(((IResource)selected).getLocation().toOSString());
- } else if ( selected instanceof File ) {
- directory= (File) selected;
- }
- if ( selected instanceof IFile ) {
- directory = directory.getParentFile();
- }
- if ( selected instanceof File ) {
- directory = directory.getParentFile();
- }
String target = EasyExplorePlugin.getDefault().getTarget();
!
! if (!EasyExplorePlugin.getDefault().isSupported()) {
! MessageDialog.openInformation(new Shell(),"Easy Explore",
! "This platform (" +
! System.getProperty("os.name") +
! ") is currently unsupported.\n" +
! "You can try to provide the correct command to execute in the Preference dialog.\n" +
! "If you succeed, please be kind to post your discovery on EasyExplore website http://sourceforge.net/projects/easystruts,\n" +
! "or by email far...@us.... Thanks !");
! return;
! }
!
! if ( target.indexOf("{0}") == -1 ) {
! target = target.trim() + " {0}";
! }
!
! target = MessageFormat.format(target, new String[]{directory.toString()});
!
! try {
! EasyExplorePlugin.log("running: "+target);
! Runtime.getRuntime().exec(target);
! } catch ( Throwable t ) {
! MessageDialog.openInformation(new Shell(),"Easy Explore","Unable to execute " +target);
! EasyExplorePlugin.log(t);
! }
! } catch (Throwable e) {
! EasyExplorePlugin.log(e);
! }
! }
!
! /**
! * @see IActionDelegate#selectionChanged(IAction, ISelection)
! */
! public void selectionChanged(IAction action, ISelection selection) {
! try {
! IAdaptable adaptable = null;
! this.selected = "unknown";
! if ( selection instanceof IStructuredSelection ) {
! adaptable = (IAdaptable) ((IStructuredSelection)selection).getFirstElement();
! this.selectedClass = adaptable.getClass();
! if ( adaptable instanceof IResource ) {
! this.selected = (IResource) adaptable;
! } else if ( adaptable instanceof PackageFragment && ((PackageFragment)adaptable).getPackageFragmentRoot() instanceof JarPackageFragmentRoot ) {
! this.selected = getJarFile(((PackageFragment)adaptable).getPackageFragmentRoot());
! } else if ( adaptable instanceof JarPackageFragmentRoot ) {
! this.selected = getJarFile(adaptable);
! } else {
! this.selected = (IResource) adaptable.getAdapter(IResource.class);
! }
! }
} catch (Throwable e) {
EasyExplorePlugin.log(e);
}
}
-
- protected File getJarFile(IAdaptable adaptable) {
- JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable;
- File selected = (File) jpfr.getPath().makeAbsolute().toFile();
- if ( !((File)selected).exists() ) {
- File projectFile = new File(jpfr.getJavaProject().getProject().getLocation().toOSString());
- selected = new File( projectFile.getParent() + selected.toString() );
- }
- return selected;
- }
-
}
--- 1,18 ----
package org.sf.easyexplore.actions;
import org.eclipse.jface.action.IAction;
! import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
! import org.sf.easyexplore.EasyExplorePlugin;
! public class EasyExploreAction extends EasyBaseAction {
! public void runAction(IAction action) {
try {
String target = EasyExplorePlugin.getDefault().getTarget();
! run(action, target);
} catch (Throwable e) {
EasyExplorePlugin.log(e);
}
}
}
--- NEW FILE: EasyBaseAction.java ---
package org.sf.easyexplore.actions;
import java.io.File;
import java.text.MessageFormat;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jdt.internal.core.JarPackageFragmentRoot;
import org.eclipse.jdt.internal.core.PackageFragment;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.sf.easyexplore.EasyExplorePlugin;
public abstract class EasyBaseAction implements
IObjectActionDelegate {
private Object selected = null;
private Class selectedClass = null;
/**
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
*/
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
}
/**
* @see IActionDelegate#run(IAction)
*/
public void run(IAction action) {
runAction(action);
}
public abstract void runAction(IAction action) ;
public void run(IAction action, String target) {
try {
if ("unknown".equals(selected)) {
MessageDialog.openInformation(new Shell(), "EasyExplore",
"Unable to run command " + selectedClass.getName());
EasyExplorePlugin.log("Unable to run command " + selectedClass);
return;
}
File directory = null;
if (selected instanceof IResource) {
directory = new File(((IResource) selected).getLocation()
.toOSString());
} else if (selected instanceof File) {
directory = (File) selected;
}
if (selected instanceof IFile) {
directory = directory.getParentFile();
}
if (selected instanceof File) {
directory = directory.getParentFile();
}
if (!EasyExplorePlugin.getDefault().isSupported()) {
MessageDialog
.openInformation(
new Shell(),
"EasyExplore",
"This platform ("
+ System.getProperty("os.name")
+ ") is currently unsupported.\n"
+ "You can try to provide the correct explorer and command to execute in the Preference dialog.\n"
+ "If you succeed, please be kind to post your discovery on EasyExplore website http://sourceforge.net/projects/easystruts,\n"
+ "or by email far...@us.... Thanks !");
}
if (target.indexOf("{0}") == -1) {
target = target.trim() + " {0}";
}
target = MessageFormat.format(target, new String[] { directory
.toString() });
try {
EasyExplorePlugin.log("running: " + target);
Runtime.getRuntime().exec(target);
} catch (Throwable t) {
MessageDialog.openInformation(new Shell(), "EasyExplore",
"Unable to execute " + target);
EasyExplorePlugin.log(t);
}
} catch (Throwable e) {
EasyExplorePlugin.log(e);
}
}
/**
* @see IActionDelegate#selectionChanged(IAction, ISelection)
*/
public void selectionChanged(IAction action, ISelection selection) {
try {
IAdaptable adaptable = null;
this.selected = "unknown";
if (selection instanceof IStructuredSelection) {
adaptable = (IAdaptable) ((IStructuredSelection) selection)
.getFirstElement();
this.selectedClass = adaptable.getClass();
if (adaptable instanceof IResource) {
this.selected = (IResource) adaptable;
} else if (adaptable instanceof PackageFragment
&& ((PackageFragment) adaptable)
.getPackageFragmentRoot() instanceof JarPackageFragmentRoot) {
this.selected = getJarFile(((PackageFragment) adaptable)
.getPackageFragmentRoot());
} else if (adaptable instanceof JarPackageFragmentRoot) {
this.selected = getJarFile(adaptable);
} else {
this.selected = (IResource) adaptable
.getAdapter(IResource.class);
}
}
} catch (Throwable e) {
EasyExplorePlugin.log(e);
}
}
protected File getJarFile(IAdaptable adaptable) {
JarPackageFragmentRoot jpfr = (JarPackageFragmentRoot) adaptable;
File selected = (File) jpfr.getPath().makeAbsolute().toFile();
if (!((File) selected).exists()) {
File projectFile = new File(jpfr.getJavaProject().getProject()
.getLocation().toOSString());
selected = new File(projectFile.getParent() + selected.toString());
}
return selected;
}
}
--- NEW FILE: EasyCommandAction.java ---
package org.sf.easyexplore.actions;
import org.eclipse.jface.action.IAction;
import org.eclipse.ui.IActionDelegate;
import org.sf.easyexplore.EasyExplorePlugin;
public class EasyCommandAction extends EasyBaseAction {
/**
* @see IActionDelegate#run(IAction)
*/
public void runAction(IAction action) {
try {
String target = EasyExplorePlugin.getDefault().getCommand();
run(action, target);
} catch (Throwable e) {
EasyExplorePlugin.log(e);
}
}
}
|