FilterAdd.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.filter.action;
00002 
00003 import org.eclipse.core.commands.AbstractHandler;
00004 import org.eclipse.core.commands.ExecutionEvent;
00005 import org.eclipse.core.commands.ExecutionException;
00006 import org.eclipse.jface.dialogs.InputDialog;
00007 import org.eclipse.jface.window.Window;
00008 import org.eclipse.swt.widgets.Shell;
00009 import org.eclipse.ui.IWorkbenchWindow;
00010 import org.eclipse.ui.handlers.HandlerUtil;
00011 import org.eclipse.ui.services.ISourceProviderService;
00012 
00013 import edu.rice.cs.hpc.data.filter.FilterAttribute;
00014 import edu.rice.cs.hpc.filter.pattern.PatternValidator;
00015 import edu.rice.cs.hpc.filter.service.FilterMap;
00016 import edu.rice.cs.hpc.filter.service.FilterStateProvider;
00017 
00018 /**********************************************
00019  * 
00020  * Command handler class to add a new filter
00021  * Currently it only asks for a new pattern with enabled pattern and 
00022  *  inclusive pattern type by default. 
00023  * User needs to change the default attributes if needed.
00024  *
00025  **********************************************/
00026 public class FilterAdd extends AbstractHandler 
00027 {
00028 
00029     @Override
00030     public Object execute(ExecutionEvent event) throws ExecutionException 
00031     {
00032         // Eclipse bug ? we need to keep this statement in the beginning of this routine because
00033         // HandlerUtil will remove all existing contexts when a new dialog show up
00034         
00035         IWorkbenchWindow winObj = HandlerUtil.getActiveWorkbenchWindow(event);
00036 
00037         // show a dialog to retrieve a new pattern
00038         
00039         final Shell shell = HandlerUtil.getActiveShell(event);
00040         final InputDialog dialog = new InputDialog(shell, "Add a pattern", 
00041                 "Use a glob pattern to define a filter. For instance, a MPI* will filter all MPI routines", 
00042                 "", new PatternValidator());
00043         
00044         if (dialog.open() == Window.OK)
00045         {
00046             // add a new filter with the default attribute
00047             FilterAttribute attribute = new FilterAttribute();
00048             final FilterMap filterMap = FilterMap.getInstance();
00049             filterMap.put(dialog.getValue(), attribute);
00050             
00051             // notify changes
00052             ISourceProviderService sourceProviderService = (ISourceProviderService) winObj.getService(
00053                     ISourceProviderService.class);
00054 
00055             final FilterStateProvider provider = (FilterStateProvider) sourceProviderService.getSourceProvider(
00056                     FilterStateProvider.FILTER_REFRESH_PROVIDER);
00057 
00058             provider.refresh();
00059         }
00060         return null;
00061     }
00062 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1