Eclipse RCP program if we add TaskList View, or used to manage the Task TODO items , the following code :
PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.showView("org.eclipse.ui.views.TaskList");
We found that created Task, can not be saved after the restart , but in the Eclipse IDE does not have this problem . org.eclipse.ui.internal.views.markers.TasksView read the code , I found TasksView when the program exits , only responsible for keeping TasksView layout information . So , you need to add the Task how to save it ?
How to save TaskList
the nature of the original TaskMarker, not stored in TasksView , but instead , and Resource associated with the object stored in the IResource . In the RCP program, you need to call IWorkspace Marker save the save method, you can call in preShutdown , the following code :
@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;
}
Get TaskList
As stated earlier , Task (Marker of one type ) and Resource association is stored in the IResource . We can pass the following code to get all Task:
IResource root = ResourcesPlugin.getWorkspace().getRoot();
String TypeId = "org.eclipse.core.resources.taskmarker";
IMarker[] markers = resource.findMarkers(TypeId, true, IResource.DEPTH_INFINITE);
where the first parameter specifies obtain Marker TypeId type ; second parameter specifies whether to search child nodes Marker; third parameter specifies the depth of the search .
in obtaining a IMarker , you can through the getAttribute method to get the parameters or getAttributes
Reference
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
没有评论:
发表评论