RCP:如何保存TaskList及如何获取TaskList
如果我们在Eclipse RCP程序中添加TaskList View,用来管理Task或者TODO项,如下代码:
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.ui.views.TaskList");
我们发现,创建的Task,在重启之后无法保存,而在Eclipse IDE中却不会有这个问题. 在阅读org.eclipse.ui.internal.views.markers.TasksView的代码后,我发现TasksView在程序退出时,只负责保存TasksView的布局信息。那么,需要怎么保存添加的Task呢?
如何保存TaskList
原来Task的本质是Marker,并不是保存在TasksView中,而是和Resource相关联,保存在IResource对象中。在RCP程序中,保存Marker需要调用IWorkspace的save方法,可以在preShutdown中调用,如下代码:
@Override
public boolean preShutdown() { /* Save workspace before closing the application */
final MultiStatus status = new MultiStatus(
"com.voxana.vuidesigner.diagram", 0, "Saving Workspace....",
null);
IRunnableWithProgress runnable = new IRunnableWithProgress() { @Override
public void run(final IProgressMonitor monitor) {
try {
IWorkspace ws = ResourcesPlugin.getWorkspace();
status.merge(ws.save(true, monitor));
} catch (CoreException e) {
status.merge(e.getStatus());
}
}
};
try {
new ProgressMonitorDialog(null).run(false, false, runnable);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
if (!status.isOK()) {
ErrorDialog.openError(Display.getDefault().getActiveShell(),
"Error...", "Error while saving workspace", status);
return true;
}
return true;
}
获取TaskList
如前面所说,Task(Marker的其中一种类型)是和Resource关联,保存在IResource中的。我们可以通过以下代码来获取所有Task:
IResource root = ResourcesPlugin.getWorkspace().getRoot();
String TypeId = "org.eclipse.core.resources.taskmarker";
IMarker[] markers = resource.findMarkers(TypeId, true, IResource.DEPTH_INFINITE);
其中,第一个参数TypeId指定要获取的Marker类型;第二个参数指定是否搜索子节点的Marker;第三个参数指定搜索的深度。
在获取了IMarker后,即可通过getAttribute或者getAttributes方法来获取参数
参考
http://www.eclipse.org/forums/index.php/t/106705/
http://wiki.eclipse.org/FAQ_How_and_when_do_I_save_the_workspace%3F
org.eclipse.ui.internal.views.markers.MarkerContentGenerator class internalGatherMarkers method
RCP:如何保存TaskList及如何获取TaskList的更多相关文章
- C#操作office进行Excel图表创建,保存本地,word获取
,新建C#控制台应用程序(Excel创建图表) using System; using System.Collections.Generic; using System.Linq; using Sys ...
- cookie保存中文登录账号获取时乱码问题
登录成功后写入cookie的代码 Response.Cookies["account"].Value = account;//"管理员" Response.Co ...
- .net Core 2.1 后 Session保存,新页面获取不到值
https://blog.csdn.net/kuui_chiu/article/details/81060051 https://blog.csdn.net/niunan/article/detail ...
- DOS tasklist 命令(转)
Dos命令之Tasklist用法及参数函义 2012-10-24 14:44:34| 分类: Windows |字号 订阅 TASKLIST [/S system [/U username [/ ...
- Tasklist and TaskKill
C:\Users\Administrator>tasklist /? TASKLIST [/S system [/U username [/P [password]]]] [/M ...
- (转)tasklist命令参数应用详细图解
原文:https://blog.csdn.net/bcbobo21cn/article/details/51759521 一 操作实例不带参数: /svc参数: /SVC 显示每个进程中的服务信息,当 ...
- CMD命令利用tasklist与taskkill关闭程序
昨天远程服务器后,服务器无故卡住了,鼠标各种延迟与无反应,想在进程管理器里关闭程序也卡住,想点击重启系统也卡死无反应.纠结后win+R打开了cmd用shutdown重启才算搞定.重启期间思考了下,如何 ...
- C# -- 优先获取电脑C盘之外的磁盘来保存数据
C# -- 优先获取电脑C盘之外的磁盘来保存数据 1. 优先获取电脑C盘之外的磁盘来保存数据.没有其他盘则使用C盘. public string GetSaveDataDiskPath() { str ...
- Windows ----tasklist/taskkill
1) Tasklist命令详解 “Tasklist”命令是一个用来显示运行在本地或远程计算机上的所有进程的命令行工具,带有多个执行参数. 作用:结束一个或多个任务或进程.可以根据进程 ID 或图像名来 ...
随机推荐
- form表单提交controller层接收到的值为乱码的问题
今天遇到个中文乱码问题,大体情况是这样的:前台有一个form表单,其中有几个input的控件,值是带中文的,form表单只设置了id='form1' method='post' action='xx ...
- SQL异常:ORA-00936: missing expression
select * from t_user where id in()当条件in的内容为空时抛 java.sql.SQLException: ORA-00936: missing expression ...
- decode 函数将字符串从某种编码转为 unicode 字符
环境:Ubuntu, Python 2.7 基础知识 这个程序涉及到的知识点有几个,在这里列出来,不详细讲,有疑问的直接百度会有一堆的. 1.urllib2 模块的 request 对像来设置 HTT ...
- 关于Random类产生随机数的一些问题
package test2; import java.util.Random; /** * @author cy * * @date 2015年7月28日 上午8:47:52 * * @Descrip ...
- php一些特殊函数的使用实例详解
<?php /* * PHP Array 函数大全 * * array() 创建数组. 3 array_change_key_case() 返回其键均为大写或小写的数组. 4 array_chu ...
- Visual Studio中删除所有空行
解决方法如下: 使用快捷键Ctrl+H,显示查找和替换视图菜单 Find what(查找内容):^:b*$\n Replace with(替换为):[Empty] (空字符串,什么都不用填) Look ...
- 孟加拉央行SWIFT攻击事件恶意木马分析(转)
第一章 分析概述 该恶意木马样本为运行于winodws平台上的PE文件(名称:evtdiag.exe).文件大小为64KB,编译时间是2016年2月5日. 经分析,该样本为定制的攻击SWIFT客户端程 ...
- Wordpress实现站搜索
wordpress内置的搜索表单如下 <form role="search" method="get" id="searchform" ...
- libgdx 常见问题
libgdx assets file not found Select Run -> Edit Configurations from the menu In the "Working ...
- 安装LNMP之后出现 Access denied.解决方法
权限问题, 执行 sudo chown -R www:www /home/wwwroot