1.得到某PLUGIN的路徑:
Platform.getBundle("mypluginid").getLocation().
eclipse采用osgi后好像還可以:
Activator.getDefault().getBundle().getLocation().(前提是這個插件有Activator這個類.這個類繼承了ECLIPSE的Plugin類)
eclipse采用osgi前好像好像是:
MyPlugin.getDefault().getBundle().getLocation().(前提是這個插件有MyPlugin這個類.這個類繼承了ECLIPSE的Plugin類)
2.得到工作區(qū)路徑:
Platform.getocation();或
ResourcesPlugin.getWorkspace();好像
Platform.getInstanceLocation()也可行
3.得到ECLIPSE安裝路徑
Platform.getInstallLocation();
4 ECLIPSE相關(guān)參數(shù)(我用過的).
在命令行或ECLIPSE.INI文件中可以設(shè)置一些ECLIPSE啟動時用的參數(shù):
-data myworkspace可以指定自己的工作區(qū)
-vm javapath 可以指定用哪個JAVA VM
-nl locale 定義語言環(huán)境
設(shè)置VM參數(shù)時,要放在-vmargs之后:
-vmargs -Djava.util.logging.config.file=mylog.properties 設(shè)置日志文件位置.調(diào)試狀態(tài)下可以在CONSOLE視圖中看到日志.
-vmargs -Xms
-vmargs -Xmx
-vmargs -Xss
-vmargs -XX:MaxPermSize 設(shè)置Permanent Generation使用的最大內(nèi)存.
-vmargs -XX:PermSize 設(shè)置程序Permanent Generation內(nèi)存大小.
一兩句話說不清上面兩個參數(shù)的概念.關(guān)于PERM概念可以參考http://www.totodotnet.net/category/technology/java-tech/
更多的參數(shù)可以參考http://www.cnblogs.com/sunsonbaby/archive/2005/02/02/101112.html
還要干活,先寫這點,以后碰到了再增加.
加一個!!
5 用代碼來關(guān)閉DIALOG。
開發(fā)ECLIPSE插件,經(jīng)常會寫JUNIT測試,但當測試界面元素時,有一個大問題:就是用代碼打開一個界面元素,比如說 DIALOG之后,因為這時候系統(tǒng)運行的線程變成了這個DIALOG,這樣我們就無法在程序中用代碼來關(guān)閉這個DIALOG.
解決方法就是:
dialog.open();
在DIALOG開發(fā)的代碼之后加入這樣一個方法:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()
.getDisplay().asyncExec(new Runnable() {
public void run() {
Button cancel = null;
Shell shell = Display.getCurrent().getActiveShell();
cancel = shell.getDefaultButton();
if (cancel != null && !cancel.isDisposed()) {
cancel.notifyListeners(SWT.Selection, new Event());
}
}
});
6 創(chuàng)建臨時文件
在開發(fā)插件的時候,有時候需要創(chuàng)建臨時文件.這個臨時文件會被創(chuàng)建到系統(tǒng)的臨時文件目錄.
給一個輸入流:InputStream content,則可以這么創(chuàng)建臨時文件:
File tempFile = File.createTempFile("tempFile", ".txt");
第一個參數(shù)是文件名,第二個參數(shù)是后綴名
OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile));
InputStreamReader reader = new InputStreamReader(content);
for (int currentchar = reader.read(); currentchar != -1; currentchar = reader.read()) {
writer.write(currentchar);
}
writer.flush();
writer.close();
reader.close();
創(chuàng)建臨時目錄,可以這么做:
getTempDir() {
File tempdir = new File(System.getProperty("java.io.tmpdir"));
File tmpdir = new File(tempdir
if (tmpdir.exists()) {
LOG.fine("This dir is exist");
}
tmpdir.mkdirs();
return tmpdir;
}
安徽新華電腦學(xué)校專業(yè)職業(yè)規(guī)劃師為你提供更多幫助【在線咨詢】