![]() 本文介绍如何利用Eclipse插件EasyExplorer在Eclipse中的使用。 Eclipse是目前非常流行的开发平台,开放扩展的架构让很多程序员找到了自己个性化的工作环境。 问题提出: 解决方法: 安装JDK:1.5.0 从http://java.上去下载安装 技巧Eclipse使用技巧之插件管理 提示:新下载的插件PlugIn一定不要都放在原始的Eclipse目录下去,一大堆,累死你:(
使用EasyExplorer插件安装方法采用上一节的《Eclipse使用技巧之插件管理》 重新启动Eclipse后,在Package Explorer、Outline、Naviagtor、Problems、文件编辑等等窗口中右键,可以看到多个一个带有文件夹图标Easy Explore…菜单。 在Package Explorer窗口中右键,如下图所示: 在Naviagtor窗口中右键中右键,如下图所示:
在Outline窗口中右键中右键,如下图所示:
在Problems窗口中右键中右键,如下图所示: 在文件编辑窗口中右键中右键,如下图所示: 利用EasyExplorer插件可以在Eclipse用Explorer打开资源文件所在的文件夹。其它配置是在这里Windows => Preferences => Easy Explore => Target => explorer.exe {0} 可以看到在Windows平台上是用explorer.exe {0}来打开的,{0}是用来传递参数的。 技巧:我习惯以资源管理器的方式来打开文件夹,方便进行拖动操作,即左边带文件树,那么在这里你可以设置成为explorer.exe /e,{0}即可,这样用EasyExplore打开文件夹时就是以这种方式来打开的,而且左边的文件树里,直接定位到文件夹上面,很是方便。 Explorer.exe的参数如下:大家可以根据自己的喜好进行设定: 参数说明 通过对以上explorer.exe的参数分析,我们可能会有个希望就是实现既显示左边的文件树,又同时右边也定位到的选定的文件或文件夹上面。 你可以自己修改源代码来实现。 打开这个插件包,我们可以看到easyexplore.jar里面只有三个文件,我们就用jad反编译过来看看,是怎么实现的。 不过,我们可以从EasyExplorePlugin.java里面代码知道,EasyExplore支持Windows和Mac两种操作系统,关键代码如下: protected void initializeDefaultPreferences(IPreferenceStore store) { String defaultTarget = "shell_open_command {0}"; String osName = System.getProperty("os.name"); if(osName.indexOf("Windows") != -1) defaultTarget = "explorer.exe {0}"; else if(osName.indexOf("Mac") != -1) defaultTarget = "open {0}"; store.setDefault("org.sf.easyexplore.targetPreference", defaultTarget); } 执行文件EasyExploreAction.java代码的关键分析: 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:///projects/easystruts,\n" + "or by email farialima@users.. 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); } } 使用Runtime.getRuntime().exec(target);执行资源文件所在的文件夹target参数,就可以打开文件夹了。 总结此插件的功能很简单,但是很有用的小插件。如果你经常需要打开相关资源文件所在的文件夹,比较麻烦,要右键,属性,在Location一栏中把所在的文件夹拷贝一下,然后再去资源管理器里输入这个路径,回车,打开它。现在有了这个插件就很方便了呀。 从下载的网址我们可以知道,这个EasyExplore是由EasyStruts项目组开发的。在开发基本Struts应用程序时,相信很多人都曾经用过EasyStruts的,不过EasyStruts已经很久没有更新了,它的最新版本只支持到Eclipse 2.1。 不过,从网站上面可以得知,他们正在往3.0上面迁移,支持Eclipse3.x,相信到时又有新的EasyStruts可以用了:) |
|