FilterDelete.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.filter.action;
00002
00003 import java.util.Map.Entry;
00004
00005 import org.eclipse.core.commands.AbstractHandler;
00006 import org.eclipse.core.commands.ExecutionEvent;
00007 import org.eclipse.core.commands.ExecutionException;
00008 import org.eclipse.jface.dialogs.MessageDialog;
00009 import org.eclipse.swt.widgets.Shell;
00010 import org.eclipse.ui.IWorkbenchWindow;
00011 import org.eclipse.ui.handlers.HandlerUtil;
00012 import org.eclipse.ui.services.ISourceProviderService;
00013
00014 import edu.rice.cs.hpc.filter.service.FilterMap;
00015 import edu.rice.cs.hpc.filter.service.FilterStateProvider;
00016
00017
00018
00019
00020
00021
00022 public class FilterDelete extends AbstractHandler
00023 {
00024
00025 @Override
00026 public Object execute(ExecutionEvent event) throws ExecutionException
00027 {
00028 IWorkbenchWindow winObj = HandlerUtil.getActiveWorkbenchWindow(event);
00029 ISourceProviderService sourceProviderService = (ISourceProviderService) winObj.getService(
00030 ISourceProviderService.class);
00031 final FilterStateProvider provider = (FilterStateProvider) sourceProviderService.getSourceProvider(
00032 FilterStateProvider.FILTER_STATE_PROVIDER);
00033
00034 Object []elements = provider.getSelections();
00035 if (elements != null && elements.length > 0)
00036 {
00037 final Shell shell = HandlerUtil.getActiveShell(event);
00038 if (MessageDialog.openQuestion(shell, "Remove a filter pattern",
00039 "Are you sure to delete the " + elements.length +
00040 " selected pattern(s) ?"))
00041 {
00042 final FilterMap map = FilterMap.getInstance();
00043 for (Object element : elements)
00044 {
00045 Entry<String, Boolean> item = (Entry<String, Boolean>) element;
00046 map.remove(item.getKey());
00047 }
00048 map.save();
00049
00050 provider.refresh();
00051 }
00052 }
00053 return null;
00054 }
00055 }