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