|
本文介紹如何利用Eclipse插件EasyExplorer在Eclipse中的使用。 Eclipse是目前非常流行的開發(fā)平臺,開放擴(kuò)展的架構(gòu)讓很多程序員找到了自己個性化的工作環(huán)境。 問題提出: 解決方法: 安裝JDK:1.5.0 從http://java.上去下載安裝 技巧Eclipse使用技巧之插件管理 提示:新下載的插件PlugIn一定不要都放在原始的Eclipse目錄下去,一大堆,累死你:(
使用EasyExplorer插件安裝方法采用上一節(jié)的《Eclipse使用技巧之插件管理》 重新啟動Eclipse后,在Package Explorer、Outline、Naviagtor、Problems、文件編輯等等窗口中右鍵,可以看到多個一個帶有文件夾圖標(biāo)Easy Explore…菜單。 在Package Explorer窗口中右鍵,如下圖所示: 在Naviagtor窗口中右鍵中右鍵,如下圖所示:
在Outline窗口中右鍵中右鍵,如下圖所示:
在Problems窗口中右鍵中右鍵,如下圖所示: 在文件編輯窗口中右鍵中右鍵,如下圖所示: 利用EasyExplorer插件可以在Eclipse用Explorer打開資源文件所在的文件夾。其它配置是在這里Windows => Preferences => Easy Explore => Target => explorer.exe {0} 可以看到在Windows平臺上是用explorer.exe {0}來打開的,{0}是用來傳遞參數(shù)的。 技巧:我習(xí)慣以資源管理器的方式來打開文件夾,方便進(jìn)行拖動操作,即左邊帶文件樹,那么在這里你可以設(shè)置成為explorer.exe /e,{0}即可,這樣用EasyExplore打開文件夾時就是以這種方式來打開的,而且左邊的文件樹里,直接定位到文件夾上面,很是方便。 Explorer.exe的參數(shù)如下:大家可以根據(jù)自己的喜好進(jìn)行設(shè)定: 參數(shù)說明 通過對以上explorer.exe的參數(shù)分析,我們可能會有個希望就是實(shí)現(xiàn)既顯示左邊的文件樹,又同時右邊也定位到的選定的文件或文件夾上面。 你可以自己修改源代碼來實(shí)現(xiàn)。 打開這個插件包,我們可以看到easyexplore.jar里面只有三個文件,我們就用jad反編譯過來看看,是怎么實(shí)現(xiàn)的。 不過,我們可以從EasyExplorePlugin.java里面代碼知道,EasyExplore支持Windows和Mac兩種操作系統(tǒng),關(guān)鍵代碼如下: 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);
}
執(zhí)行文件EasyExploreAction.java代碼的關(guān)鍵分析:
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);執(zhí)行資源文件所在的文件夾target參數(shù),就可以打開文件夾了。 總結(jié)此插件的功能很簡單,但是很有用的小插件。如果你經(jīng)常需要打開相關(guān)資源文件所在的文件夾,比較麻煩,要右鍵,屬性,在Location一欄中把所在的文件夾拷貝一下,然后再去資源管理器里輸入這個路徑,回車,打開它?,F(xiàn)在有了這個插件就很方便了呀。 從下載的網(wǎng)址我們可以知道,這個EasyExplore是由EasyStruts項(xiàng)目組開發(fā)的。在開發(fā)基本Struts應(yīng)用程序時,相信很多人都曾經(jīng)用過EasyStruts的,不過EasyStruts已經(jīng)很久沒有更新了,它的最新版本只支持到Eclipse 2.1。 不過,從網(wǎng)站上面可以得知,他們正在往3.0上面遷移,支持Eclipse3.x,相信到時又有新的EasyStruts可以用了:) |
|
|