当前位置: 代码迷 >> Eclipse >> eclipse ecp 开发札记
  详细解决方案

eclipse ecp 开发札记

热度:98   发布时间:2016-04-23 12:31:55.0
eclipse ecp 开发笔记

本文是eclipse rcp开发中遇到的一些问题,现记录下来


1、定位java代码 Marker

这里需要实现的功能是打开一个java文件,并定位到相应的行,常见的findbug中可见类似的功能。当然这里的例子只是最简单的定位到该java代码的行。更多信息见这里

在接口IResource中提供了如下API:

IMarker createMarker(String type)throws CoreException

其中type类型在接口IMarker中有定义,如常见的IMarker.BOOKMARK 、 IMarker.LINE_NUMBER、 IMarker.PROBLEM等,我们这里就需要用IMarker.LINE_NUMBER
这里思路是得到IResource的实现接口,通过查看可以发现有IFile, IProject等子接口,而我们又可以通过文件的相对路径获得这些相应接口的实例对象

               //retrive a file                IPath path = new Path(filePath);                IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);                String relativePath = path.toString().substring(project.getLocation().toString().length() + 1);                IFile file = project.getFile(relativePath);                //set marker info                IMarker marker = file.createMarker(IMarker.LINE_NUMBER);                marker.setAttribute(IMarker.LINE_NUMBER, cp.getProblemLine());

?

?

?

2、打开浏览器

很简单几句话搞定

        try {            IWorkbenchBrowserSupport support = PlatformUI.getWorkbench().getBrowserSupport();            //这里是打开外部浏览器,将调用系统默认设置的浏览器?           IWebBrowser browser = support.getExternalBrowser();            //这里将在eclipse中打开SWT浏览器           //IWebBrowser browser = support.createBrowser("id");?          browser.openURL(new URL("url.."));        } catch (PartInitException e) {            LOG.error("exception when open a browser: ", e);        } catch (MalformedURLException e) {            LOG.error("exception when open a browser: ", e);        }
  相关解决方案