过滤RCP(富客户端)透视图
关键字: RCP,perspective switcherRCP的访问控制在应用中非常的有必要,因为大多数的应用都是多用户多极别。
客户端至少需要在三个层次上进行控制:
一是SWT组件级别,包括按钮、快捷菜单等等。
二是视图级别的控制,这个比较容易,只要在透视图中控制视图就可以了。
三是透视图的控制。
在透视图中包含视图。可以通过Open perspective对话框选择打开透视图,但是这里有这样一个问题,Open perspective对话框中显示的是RCP系统中所有的透视图,而且无法进行配置。在工具栏上可以显示透视图工具栏,非常的方便于用户的使用,一般都需要显示出来。但是这个工具栏带有一个other按钮,打开就是Open perspective对话框。有一个方法是从透视图注册器中删除不可访问的透视图,但是这样会弹出一个错误提示框,据说式Eclipse老的版本的一个虫子。或者Eclipse开发者就是这样设定的,不允许二次开发者操作内部方法。其方法如下:
1
/** *//**
2
* 在RCP程序的ApplicationWorkbenchWindowAdvisor类的postWindowCreate()方法中调用,用于删除无权限操作的Perspective
3
* @param pr
4
*/
5
public static void perspectiveFiltration(PerspectiveRegistry pr)
{
6
IPerspectiveDescriptor[] _ipd = pr.getPerspectives();
7
Object [] _objs = new Object[_ipd.length];
8
for(int i=0; i<_ipd.length; i++)
{
9
if(!isSecurityPerspective(_ipd[i].getId()))
{
10
_objs[i] = _ipd[i];
11
}
12
}
13
log.debug("从已注册的Perspective列表中删除Perspectives为: " + _objs.toString());
14
pr.removeExtension(null, _objs);
15
log.debug("需要重新注册新的默认Perspective页");
16
setDefautlPerspectice(pr);
17
}
尝试了很多方法,最后决定到Eclipse的源码中查一查,看看能不能找到行得通的方法。终于找到了一种过滤透视图的方法,修改的代码不多,几行的样子。
在org.eclipse.ui.workbench_3.2.2.M20070119-0800包中加入了一个类FunctionFilter:
package org.eclipse.ui.internal;
import org.eclipse.ui.PlatformUI;
/**
*
* @author Administrator
*
*/
public class FunctionFilter {
public final static String FILETERED_PERSPECTIVES = "FILETERED_PERSPECTIVES";
public static Object[] fileteredPerpectives() {
return (Object[]) PlatformUI.getWorkbench().getDisplay().getData(
FILETERED_PERSPECTIVES);
}
}
你可能已经注意到,使用了Display保存过滤了的透视图。
然后在eclipse内部类PerspContentProvider修改了几行代码:
/*******************************************************************************
* Copyright (c) 2000, 2005 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.ui.internal.dialogs;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.ui.IPerspectiveRegistry;
import org.eclipse.ui.internal.FunctionFilter;
public class PerspContentProvider implements IStructuredContentProvider {
/**
* Create a new PerspContentProvider.
*/
public PerspContentProvider() {
//no-op
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IContentProvider#dispose()
*/
public void dispose() {
//no-op
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IStructuredContentProvider#getElements(java.lang.Object)
*/
public Object[] getElements(Object element) {
if (element instanceof IPerspectiveRegistry) {
// return ((IPerspectiveRegistry) element).getPerspectives();
return FunctionFilter.fileteredPerpectives();
}
return null;
}
/*
* (non-Javadoc)
*
* @see org.eclipse.jface.viewers.IContentProvider#inputChanged(org.eclipse.jface.viewers.Viewer,
* java.lang.Object, java.lang.Object)
*/
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
//no-op
}
}
这样就过滤了不需要的透视图。
- 13:04
- 浏览 (532)
- 评论 (0)
- 分类: Eclipse/plugin/rcp
- 进入论坛
- 相关推荐
- 浏览: 54576 次
- 性别:

- 来自: 北京

- 详细资料
搜索本博客
我的相册
共 6 张
最新评论
-
一个数据库连接Java工具类 ...
不错,加油,能写成工具类就好了。
-- by dd2086 -
Hibernate和Access
我指的是方法一
-- by 黑暗浪子 -
Hibernate和Access
我测试一下,如果连接的是*.asa文件,好像就报"can't open conn ...
-- by 黑暗浪子 -
计算机/软件领域中的名人
Bruce Eckel和其他几位根本不是一个层次的人物。Marin Fowler ...
-- by turing -
《夜袭》和战争
电影拍的不好,有辱历史!
-- by ken1984






评论排行榜