最近一个项目中,有两种数据来源:A和B,如果是A的话 所有视图都需要,如果是B的话 有一两个视图没有用处,但又占着好多的版面,于是去看workbenchpage的源码 发现了这么几个方法。
1.视图的最小化最大化和还原操作
WorkbenchPage:
/**
* Sets the state of the given part.
*
* @param ref part whose state should be modified (not null)
* @param newState one of the IStackPresentationSite.STATE_* constants
*/
public void setState(IWorkbenchPartReference ref, int newState) ;
这个可以方便的让我们的视图改变当前的状态 (最大化,最小化,还原等),相应的状态为:
WorkbenchPage.STATE_RESTORED : 还原
WorkbenchPage.STATE_MINIMIZED : 最小化
WorkbenchPage.STATE_MAXIMIZED : 最大化
2.视图的隐藏和显示
IWorkbenchPage 接口中提供了 视图的隐藏和显示方法
/**
* Shows the view identified by the given view id in this page and gives it
* focus. If there is a view identified by the given view id (and with no
* secondary id) already open in this page, it is given focus.
*
* @param viewId
* the id of the view extension to use
* @return the shown view
* @exception PartInitException
* if the view could not be initialized
*/
public IViewPart showView(String viewId) throws PartInitException;
/**
* Shows a view in this page with the given id and secondary id. The
* behaviour of this method varies based on the supplied mode. If
* <code>VIEW_ACTIVATE</code> is supplied, the view is given focus. If
* <code>VIEW_VISIBLE</code> is supplied, then it is made visible but not
* given focus. Finally, if <code>VIEW_CREATE</code> is supplied the view is
* created and will only be made visible if it is not created in a folder
* that already contains visible views.
*
* This allows multiple instances of a particular view to be created. They
* are disambiguated using the secondary id. If a secondary id is given, the
* view must allow multiple instances by having specified
* allowMultiple="true" in its extension.
*
*
* @param viewId
* the id of the view extension to use
* @param secondaryId
* the secondary id to use, or <code>null</code> for no secondary
* id
* @param mode
* the activation mode. Must be {@link #VIEW_ACTIVATE},
* {@link #VIEW_VISIBLE} or {@link #VIEW_CREATE}
* @return a view
* @exception PartInitException
* if the view could not be initialized
* @exception IllegalArgumentException
* if the supplied mode is not valid
* @since 3.0
*/
public IViewPart showView(String viewId, String secondaryId, int mode)
throws PartInitException;
1.视图的最小化最大化和还原操作
WorkbenchPage:
/**
* Sets the state of the given part.
*
* @param ref part whose state should be modified (not null)
* @param newState one of the IStackPresentationSite.STATE_* constants
*/
public void setState(IWorkbenchPartReference ref, int newState) ;
这个可以方便的让我们的视图改变当前的状态 (最大化,最小化,还原等),相应的状态为:
WorkbenchPage.STATE_RESTORED : 还原
WorkbenchPage.STATE_MINIMIZED : 最小化
WorkbenchPage.STATE_MAXIMIZED : 最大化
2.视图的隐藏和显示
IWorkbenchPage 接口中提供了 视图的隐藏和显示方法
/**
* Shows the view identified by the given view id in this page and gives it
* focus. If there is a view identified by the given view id (and with no
* secondary id) already open in this page, it is given focus.
*
* @param viewId
* the id of the view extension to use
* @return the shown view
* @exception PartInitException
* if the view could not be initialized
*/
public IViewPart showView(String viewId) throws PartInitException;
/**
* Shows a view in this page with the given id and secondary id. The
* behaviour of this method varies based on the supplied mode. If
* <code>VIEW_ACTIVATE</code> is supplied, the view is given focus. If
* <code>VIEW_VISIBLE</code> is supplied, then it is made visible but not
* given focus. Finally, if <code>VIEW_CREATE</code> is supplied the view is
* created and will only be made visible if it is not created in a folder
* that already contains visible views.
*
* This allows multiple instances of a particular view to be created. They
* are disambiguated using the secondary id. If a secondary id is given, the
* view must allow multiple instances by having specified
* allowMultiple="true" in its extension.
*
*
* @param viewId
* the id of the view extension to use
* @param secondaryId
* the secondary id to use, or <code>null</code> for no secondary
* id
* @param mode
* the activation mode. Must be {@link #VIEW_ACTIVATE},
* {@link #VIEW_VISIBLE} or {@link #VIEW_CREATE}
* @return a view
* @exception PartInitException
* if the view could not be initialized
* @exception IllegalArgumentException
* if the supplied mode is not valid
* @since 3.0
*/
public IViewPart showView(String viewId, String secondaryId, int mode)
throws PartInitException;