1 11 package org.eclipse.search2.internal.ui; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.jface.action.Action; 16 import org.eclipse.jface.action.IAction; 17 18 import org.eclipse.ui.texteditor.IUpdate; 19 20 import org.eclipse.search.ui.text.AbstractTextSearchResult; 21 import org.eclipse.search.ui.text.AbstractTextSearchViewPage; 22 import org.eclipse.search.ui.text.MatchFilter; 23 24 25 public class MatchFilterAction extends Action implements IUpdate { 26 27 private MatchFilter fFilter; 28 private AbstractTextSearchViewPage fPage; 29 30 public MatchFilterAction(AbstractTextSearchViewPage page, MatchFilter filter) { 31 super(filter.getActionLabel(), IAction.AS_CHECK_BOX); 32 fPage= page; 33 fFilter= filter; 34 setId("MatchFilterAction." + filter.getID()); setChecked(isActiveMatchFilter()); 36 } 37 38 public void run() { 39 AbstractTextSearchResult input= fPage.getInput(); 40 if (input == null) { 41 return; 42 } 43 ArrayList newFilters= new ArrayList (); 44 MatchFilter[] activeMatchFilters= input.getActiveMatchFilters(); 45 if (activeMatchFilters == null) { 46 return; 47 } 48 49 for (int i= 0; i < activeMatchFilters.length; i++) { 50 if (!activeMatchFilters[i].equals(fFilter)) { 51 newFilters.add(activeMatchFilters[i]); 52 } 53 } 54 boolean newState= isChecked(); 55 if (newState) { 56 newFilters.add(fFilter); 57 } 58 input.setActiveMatchFilters((MatchFilter[]) newFilters.toArray(new MatchFilter[newFilters.size()])); 59 } 60 61 public MatchFilter getFilter() { 62 return fFilter; 63 } 64 65 private boolean isActiveMatchFilter() { 66 AbstractTextSearchResult input= fPage.getInput(); 67 if (input != null) { 68 MatchFilter[] activeMatchFilters= input.getActiveMatchFilters(); 69 for (int i= 0; i < activeMatchFilters.length; i++) { 70 if (fFilter.equals(activeMatchFilters[i])) { 71 return true; 72 } 73 } 74 } 75 return false; 76 } 77 78 81 public void update() { 82 setChecked(isActiveMatchFilter()); 83 } 84 } | Popular Tags |