But there is no such provision available for the Eclipse Problems View. If you are planning to utilize the problems view in your product then this might be a big headache. I encountered the same thing and decided to contribute one of my own action for doing this job.
Extension Point Definition -
Extension Point Details -
The class DeleteLogsAction looks as follows -
public class DeleteLogsAction extends Action implements IViewActionDelegate {
private IViewPart view;
private final static String DIALOG_TITLE = "Confirm Delete";
private final static String DIALOG_MESSAGE = "Are you sure you want to delete all logged events?";
private final static String MARKER_TYPE = IMarker.PROBLEM;
private final static int DEPTH = IResource.DEPTH_INFINITE;
private final static boolean INCLUDE_SUB_TYPES = true;
public DeleteLogsAction() {
this.setImageDescriptor(Activator.getImageDescriptor("\\icons\\remove.gif"));
this.setDisabledImageDescriptor(Activator.getImageDescriptor("\\icons\\remove_disabled.gif"));
}
@Override
public void init(IViewPart view) {
this.view = view;
}
@Override
public void run(IAction action) {
try
{
if(ResourcesPlugin.getWorkspace() != null)
{
IWorkspace workSpace = ResourcesPlugin.getWorkspace();
if(workSpace.getRoot() != null)
{
IWorkspaceRoot root = workSpace.getRoot();
IMarker[] markers = root.findMarkers(MARKER_TYPE, INCLUDE_SUB_TYPES, DEPTH);
if(markers != null && markers.length > 0)
{
boolean confirm = MessageDialog.openConfirm(view.getSite().getShell(), DIALOG_TITLE,
DIALOG_MESSAGE);
if(confirm)
{
root.deleteMarkers(MARKER_TYPE, INCLUDE_SUB_TYPES, DEPTH);
}
else
{
return;
}
}
}
}
}
catch ( CoreException e )
{
PALogger.logError(Activator.PLUGIN_ID, "Failed to delete the problem markers.", e);
}
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
}
private IViewPart view;
private final static String DIALOG_TITLE = "Confirm Delete";
private final static String DIALOG_MESSAGE = "Are you sure you want to delete all logged events?";
private final static String MARKER_TYPE = IMarker.PROBLEM;
private final static int DEPTH = IResource.DEPTH_INFINITE;
private final static boolean INCLUDE_SUB_TYPES = true;
public DeleteLogsAction() {
this.setImageDescriptor(Activator.getImageDescriptor("\\icons\\remove.gif"));
this.setDisabledImageDescriptor(Activator.getImageDescriptor("\\icons\\remove_disabled.gif"));
}
@Override
public void init(IViewPart view) {
this.view = view;
}
@Override
public void run(IAction action) {
try
{
if(ResourcesPlugin.getWorkspace() != null)
{
IWorkspace workSpace = ResourcesPlugin.getWorkspace();
if(workSpace.getRoot() != null)
{
IWorkspaceRoot root = workSpace.getRoot();
IMarker[] markers = root.findMarkers(MARKER_TYPE, INCLUDE_SUB_TYPES, DEPTH);
if(markers != null && markers.length > 0)
{
boolean confirm = MessageDialog.openConfirm(view.getSite().getShell(), DIALOG_TITLE,
DIALOG_MESSAGE);
if(confirm)
{
root.deleteMarkers(MARKER_TYPE, INCLUDE_SUB_TYPES, DEPTH);
}
else
{
return;
}
}
}
}
}
catch ( CoreException e )
{
PALogger.logError(Activator.PLUGIN_ID, "Failed to delete the problem markers.", e);
}
}
@Override
public void selectionChanged(IAction action, ISelection selection) {
}
Once this part is done, You will be able to see the new action in the problems view -
0 comments:
Post a Comment