首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Eclipse开发 >

怎么获取Eclipse里view的id

2012-10-27 
如何获取Eclipse里view的id在制作eclipse插件的时候,时常需要对已经存在的视图做一些扩展,例如在project e

如何获取Eclipse里view的id

在制作eclipse插件的时候,时常需要对已经存在的视图做一些扩展,例如在project explorer中增加一个右键菜单,或者需要获取outline中当前选中项,等等。而这些操作的前提,是获取这些视图的id,然后通过获取视图的语句获取到视图,并进行下一步操作。

例如:如果是在view中:

怎么获取Eclipse里view的idIViewPart?part?=?getViewSite().getPage().findView("org.eclipse.ui.views.ContentOutline");
如果是在action中:

怎么获取Eclipse里view的idIViewPart?part?=?Plugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getActivePage().findView("org.eclipse.ui.views.ContentOutline");


可见获取到视图的id是很重要的。如何获取id呢,有很多方法,我觉得比较常用的是以下两种:

1.通过手动查找目标视图所在的插件的plugin.xml中对改视图的定义,获得视图id。

描述:我觉得这是最保险的办法,因为所有的视图都必定有一个plugin.xml定义,但是找到这个plugin.xml还是需要一些操作,可能会耗费一些时间。
步骤:
a.点击“工具栏”->“Search”->“Search”,或者热键“ctrl+h”。选“ Plugin Search”。
b.Search for 选"Extention Point",Limit to 选“References”,External Scope 选“Enabled Plug-ins only”。
c.下面的scope选“Worksapaces”。
d.上面的Search String框填入我们要搜索的插件的扩展点的名字,这里我们要找视图插件,所以填入:org.eclipse.ui.views
e.点击search以后,在底部Search视图内列出很多搜索结果,任意选中一个,双击,可以看到editor内打开了该plugin.xml,选中编辑器底部的Extentions,用图形化的方式来查看会更快捷。
f.可以看到该插件使用的扩展点已经以列表的形式列出,我们查找的org.eclipse.ui.views扩展点也已经选中,展开选中的扩展点,可以看到它实现了哪些view,点击某一个,可以在页面右边看到该视图的详细信息,第一项即是视图的id。

我们无法知道目标视图在搜索结果中的哪个plugin中,所以可能会耗费一些时间,建议在查看搜索结果时,通过对视图的分类分析,确定一个大概范围再进行查看。
同时,用这种方法也可以查找其他扩展点的实现插件。

2.通过代码直接读出该视图的id。

描述:通过这种方法,可以直接用鼠标点击某个你想知道的视图,控制台会打印出该视图的id和所属插件的id。
步骤:
a.通过插件向导新建一个插件,并使用Available Templates中的Plugin with a view模板,点finish。
b.对自动创建的SampleView代码进行修改,修改结果如下。其中主要步骤有三个:实现IPartListener2接口,编写isActivePart()方法,调用isActivePart()方法。

怎么获取Eclipse里view的idpackage?com.raul.learn.sampleview.views;
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id
怎么获取Eclipse里view的idimport?org.eclipse.swt.widgets.Composite;
怎么获取Eclipse里view的idimport?org.eclipse.ui.part.*;
怎么获取Eclipse里view的idimport?org.eclipse.jface.viewers.*;
怎么获取Eclipse里view的idimport?org.eclipse.swt.graphics.Image;
怎么获取Eclipse里view的idimport?org.eclipse.jface.action.*;
怎么获取Eclipse里view的idimport?org.eclipse.jface.dialogs.MessageDialog;
怎么获取Eclipse里view的idimport?org.eclipse.ui.*;
怎么获取Eclipse里view的idimport?org.eclipse.swt.widgets.Menu;
怎么获取Eclipse里view的idimport?org.eclipse.swt.SWT;
怎么获取Eclipse里view的id
怎么获取Eclipse里view的idimport?com.raul.learn.sampleview.Activator;
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id/**
怎么获取Eclipse里view的id?*?This?sample?class?demonstrates?how?to?plug-in?a?new
怎么获取Eclipse里view的id?*?workbench?view.?The?view?shows?data?obtained?from?the
怎么获取Eclipse里view的id?*?model.?The?sample?creates?a?dummy?model?on?the?fly,
怎么获取Eclipse里view的id?*?but?a?real?implementation?would?connect?to?the?model
怎么获取Eclipse里view的id?*?available?either?in?this?or?another?plug-in?(e.g.?the?workspace).
怎么获取Eclipse里view的id?*?The?view?is?connected?to?the?model?using?a?content?provider.
怎么获取Eclipse里view的id?*?<p>
怎么获取Eclipse里view的id?*?The?view?uses?a?label?provider?to?define?how?model
怎么获取Eclipse里view的id?*?objects?should?be?presented?in?the?view.?Each
怎么获取Eclipse里view的id?*?view?can?present?the?same?model?objects?using
怎么获取Eclipse里view的id?*?different?labels?and?icons,?if?needed.?Alternatively,
怎么获取Eclipse里view的id?*?a?single?label?provider?can?be?shared?between?views
怎么获取Eclipse里view的id?*?in?order?to?ensure?that?objects?of?the?same?type?are
怎么获取Eclipse里view的id?*?presented?in?the?same?way?everywhere.
怎么获取Eclipse里view的id?*?<p>
怎么获取Eclipse里view的id?*/
怎么获取Eclipse里view的id
怎么获取Eclipse里view的idpublic?class?SampleView?extends?ViewPart?implements?IPartListener2{
怎么获取Eclipse里view的id????private?TableViewer?viewer;
怎么获取Eclipse里view的id????private?Action?action1;
怎么获取Eclipse里view的id????private?Action?action2;
怎么获取Eclipse里view的id????private?Action?doubleClickAction;
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????/*
怎么获取Eclipse里view的id?????*?The?content?provider?class?is?responsible?for
怎么获取Eclipse里view的id?????*?providing?objects?to?the?view.?It?can?wrap
怎么获取Eclipse里view的id?????*?existing?objects?in?adapters?or?simply?return
怎么获取Eclipse里view的id?????*?objects?as-is.?These?objects?may?be?sensitive
怎么获取Eclipse里view的id?????*?to?the?current?input?of?the?view,?or?ignore
怎么获取Eclipse里view的id?????*?it?and?always?show?the?same?content?
怎么获取Eclipse里view的id?????*?(like?Task?List,?for?example).
怎么获取Eclipse里view的id?????*/
怎么获取Eclipse里view的id?????
怎么获取Eclipse里view的id????class?ViewContentProvider?implements?IStructuredContentProvider?{
怎么获取Eclipse里view的id????????public?void?inputChanged(Viewer?v,?Object?oldInput,?Object?newInput)?{
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????????public?void?dispose()?{
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????????public?Object[]?getElements(Object?parent)?{
怎么获取Eclipse里view的id????????????return?new?String[]?{?"One",?"Two",?"Three"?};
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????class?ViewLabelProvider?extends?LabelProvider?implements?ITableLabelProvider?{
怎么获取Eclipse里view的id????????public?String?getColumnText(Object?obj,?int?index)?{
怎么获取Eclipse里view的id????????????return?getText(obj);
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????????public?Image?getColumnImage(Object?obj,?int?index)?{
怎么获取Eclipse里view的id????????????return?getImage(obj);
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????????public?Image?getImage(Object?obj)?{
怎么获取Eclipse里view的id????????????return?PlatformUI.getWorkbench().
怎么获取Eclipse里view的id????????????????????getSharedImages().getImage(ISharedImages.IMG_OBJ_ELEMENT);
怎么获取Eclipse里view的id????????}
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????class?NameSorter?extends?ViewerSorter?{
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????/**
怎么获取Eclipse里view的id?????*?The?constructor.
怎么获取Eclipse里view的id?????*/
怎么获取Eclipse里view的id????public?SampleView()?{
怎么获取Eclipse里view的id????????Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
怎么获取Eclipse里view的id????????.getActivePage().addPartListener(this);
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?dispose()?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????Activator.getDefault().getWorkbench().getActiveWorkbenchWindow()
怎么获取Eclipse里view的id????????.getActivePage().removePartListener(this);
怎么获取Eclipse里view的id????????super.dispose();
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????
怎么获取Eclipse里view的id????/**
怎么获取Eclipse里view的id?????*?This?is?a?callback?that?will?allow?us
怎么获取Eclipse里view的id?????*?to?create?the?viewer?and?initialize?it.
怎么获取Eclipse里view的id?????*/
怎么获取Eclipse里view的id????public?void?createPartControl(Composite?parent)?{
怎么获取Eclipse里view的id????????viewer?=?new?TableViewer(parent,?SWT.MULTI?|?SWT.H_SCROLL?|?SWT.V_SCROLL);
怎么获取Eclipse里view的id????????viewer.setContentProvider(new?ViewContentProvider());
怎么获取Eclipse里view的id????????viewer.setLabelProvider(new?ViewLabelProvider());
怎么获取Eclipse里view的id????????viewer.setSorter(new?NameSorter());
怎么获取Eclipse里view的id????????viewer.setInput(getViewSite());
怎么获取Eclipse里view的id????????makeActions();
怎么获取Eclipse里view的id????????hookContextMenu();
怎么获取Eclipse里view的id????????hookDoubleClickAction();
怎么获取Eclipse里view的id????????contributeToActionBars();
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?hookContextMenu()?{
怎么获取Eclipse里view的id????????MenuManager?menuMgr?=?new?MenuManager("#PopupMenu");
怎么获取Eclipse里view的id????????menuMgr.setRemoveAllWhenShown(true);
怎么获取Eclipse里view的id????????menuMgr.addMenuListener(new?IMenuListener()?{
怎么获取Eclipse里view的id????????????public?void?menuAboutToShow(IMenuManager?manager)?{
怎么获取Eclipse里view的id????????????????SampleView.this.fillContextMenu(manager);
怎么获取Eclipse里view的id????????????}
怎么获取Eclipse里view的id????????});
怎么获取Eclipse里view的id????????Menu?menu?=?menuMgr.createContextMenu(viewer.getControl());
怎么获取Eclipse里view的id????????viewer.getControl().setMenu(menu);
怎么获取Eclipse里view的id????????getSite().registerContextMenu(menuMgr,?viewer);
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?contributeToActionBars()?{
怎么获取Eclipse里view的id????????IActionBars?bars?=?getViewSite().getActionBars();
怎么获取Eclipse里view的id????????fillLocalPullDown(bars.getMenuManager());
怎么获取Eclipse里view的id????????fillLocalToolBar(bars.getToolBarManager());
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?fillLocalPullDown(IMenuManager?manager)?{
怎么获取Eclipse里view的id????????manager.add(action1);
怎么获取Eclipse里view的id????????manager.add(new?Separator());
怎么获取Eclipse里view的id????????manager.add(action2);
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?fillContextMenu(IMenuManager?manager)?{
怎么获取Eclipse里view的id????????manager.add(action1);
怎么获取Eclipse里view的id????????manager.add(action2);
怎么获取Eclipse里view的id????????//?Other?plug-ins?can?contribute?there?actions?here
怎么获取Eclipse里view的id????????manager.add(new?Separator(IWorkbenchActionConstants.MB_ADDITIONS));
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????
怎么获取Eclipse里view的id????private?void?fillLocalToolBar(IToolBarManager?manager)?{
怎么获取Eclipse里view的id????????manager.add(action1);
怎么获取Eclipse里view的id????????manager.add(action2);
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?makeActions()?{
怎么获取Eclipse里view的id????????action1?=?new?Action()?{
怎么获取Eclipse里view的id????????????public?void?run()?{
怎么获取Eclipse里view的id????????????????showMessage("Action?1?executed");
怎么获取Eclipse里view的id????????????}
怎么获取Eclipse里view的id????????};
怎么获取Eclipse里view的id????????action1.setText("Action?1");
怎么获取Eclipse里view的id????????action1.setToolTipText("Action?1?tooltip");
怎么获取Eclipse里view的id????????action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
怎么获取Eclipse里view的id????????????getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????????action2?=?new?Action()?{
怎么获取Eclipse里view的id????????????public?void?run()?{
怎么获取Eclipse里view的id????????????????showMessage("Action?2?executed");
怎么获取Eclipse里view的id????????????}
怎么获取Eclipse里view的id????????};
怎么获取Eclipse里view的id????????action2.setText("Action?2");
怎么获取Eclipse里view的id????????action2.setToolTipText("Action?2?tooltip");
怎么获取Eclipse里view的id????????action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
怎么获取Eclipse里view的id????????????????getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
怎么获取Eclipse里view的id????????doubleClickAction?=?new?Action()?{
怎么获取Eclipse里view的id????????????public?void?run()?{
怎么获取Eclipse里view的id????????????????ISelection?selection?=?viewer.getSelection();
怎么获取Eclipse里view的id????????????????Object?obj?=?((IStructuredSelection)selection).getFirstElement();
怎么获取Eclipse里view的id????????????????showMessage("Double-click?detected?on?"+obj.toString());
怎么获取Eclipse里view的id????????????}
怎么获取Eclipse里view的id????????};
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????private?void?hookDoubleClickAction()?{
怎么获取Eclipse里view的id????????viewer.addDoubleClickListener(new?IDoubleClickListener()?{
怎么获取Eclipse里view的id????????????public?void?doubleClick(DoubleClickEvent?event)?{
怎么获取Eclipse里view的id????????????????doubleClickAction.run();
怎么获取Eclipse里view的id????????????}
怎么获取Eclipse里view的id????????});
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????private?void?showMessage(String?message)?{
怎么获取Eclipse里view的id????????MessageDialog.openInformation(
怎么获取Eclipse里view的id????????????viewer.getControl().getShell(),
怎么获取Eclipse里view的id????????????"Sample?View",
怎么获取Eclipse里view的id????????????message);
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????/**
怎么获取Eclipse里view的id?????*?Passing?the?focus?request?to?the?viewer's?control.
怎么获取Eclipse里view的id?????*/
怎么获取Eclipse里view的id????public?void?setFocus()?{
怎么获取Eclipse里view的id????????viewer.getControl().setFocus();
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partActivated(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????isActivePart();
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partBroughtToTop(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partClosed(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partDeactivated(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partHidden(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partInputChanged(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partOpened(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id
怎么获取Eclipse里view的id????@Override
怎么获取Eclipse里view的id????public?void?partVisible(IWorkbenchPartReference?partRef)?{
怎么获取Eclipse里view的id????????//?TODO?Auto-generated?method?stub
怎么获取Eclipse里view的id????????
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id????
怎么获取Eclipse里view的id????private?void?isActivePart()?{
怎么获取Eclipse里view的id????????IWorkbenchPart?part?=?getViewSite().getPage().getActivePart();
怎么获取Eclipse里view的id????????//return?part?!=?null?&&?part.equals(this);????????
怎么获取Eclipse里view的id????????System.out.println(part.getSite().getId());
怎么获取Eclipse里view的id????????part.getSite().getPluginId();
怎么获取Eclipse里view的id????}
怎么获取Eclipse里view的id}


然后调插件,在运行环境中调出该视图,接着当你用鼠标点击你想知道的视图时,在开发环境中的控制台,就会打印出该视图的id以及所属插件的id。

热点排行