1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package net.sourceforge.phpdt.ui.actions;
13 import java.util.ArrayList;
14 import java.util.Arrays;
15 import java.util.HashMap;
16 import java.util.HashSet;
17 import java.util.Iterator;
18 import java.util.List;
21 import java.util.SortedSet;
22 import java.util.Stack;
23 import java.util.StringTokenizer;
24 import java.util.TreeSet;
26 import net.sourceforge.phpdt.core.IJavaModel;
27 import net.sourceforge.phpdt.internal.ui.PHPUiImages;
28 import net.sourceforge.phpdt.internal.ui.filters.CustomFiltersDialog;
29 import net.sourceforge.phpdt.internal.ui.filters.FilterDescriptor;
30 import net.sourceforge.phpdt.internal.ui.filters.FilterMessages;
31 import net.sourceforge.phpdt.internal.ui.filters.NamePatternFilter;
32 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
34 import org.eclipse.jface.action.Action;
35 import org.eclipse.jface.action.ContributionItem;
36 import org.eclipse.jface.action.GroupMarker;
37 import org.eclipse.jface.action.IContributionItem;
38 import org.eclipse.jface.action.IMenuListener;
39 import org.eclipse.jface.action.IMenuManager;
40 import org.eclipse.jface.action.IToolBarManager;
41 import org.eclipse.jface.action.Separator;
42 import org.eclipse.jface.preference.IPreferenceStore;
43 import org.eclipse.jface.util.Assert;
44 import org.eclipse.jface.viewers.IContentProvider;
45 import org.eclipse.jface.viewers.ITreeContentProvider;
46 import org.eclipse.jface.viewers.StructuredViewer;
47 import org.eclipse.jface.viewers.ViewerFilter;
48 import org.eclipse.jface.window.Window;
49 import org.eclipse.swt.SWT;
50 import org.eclipse.swt.events.SelectionAdapter;
51 import org.eclipse.swt.events.SelectionEvent;
52 import org.eclipse.swt.widgets.Menu;
53 import org.eclipse.swt.widgets.MenuItem;
54 import org.eclipse.ui.IActionBars;
55 import org.eclipse.ui.IMemento;
56 import org.eclipse.ui.IViewPart;
57 import org.eclipse.ui.actions.ActionGroup;
60 * Action group to add the filter action to a view part's tool bar menu.
62 * This class may be instantiated; it is not intended to be subclassed.
67 public class CustomFiltersActionGroup extends ActionGroup {
69 class ShowFilterDialogAction extends Action {
70 ShowFilterDialogAction() {
71 setText(FilterMessages
72 .getString("OpenCustomFiltersDialogAction.text")); //$NON-NLS-1$
73 setImageDescriptor(PHPUiImages.DESC_ELCL_FILTER);
74 setDisabledImageDescriptor(PHPUiImages.DESC_DLCL_FILTER);
83 * Menu contribution item which shows and lets check and uncheck filters.
87 class FilterActionMenuContributionItem extends ContributionItem {
89 private int fItemNumber;
91 private boolean fState;
93 private String fFilterId;
95 private String fFilterName;
97 private CustomFiltersActionGroup fActionGroup;
100 * Constructor for FilterActionMenuContributionItem.
105 * the id of the filter
107 * the name of the filter
109 * the initial state of the filter
111 * the menu item index
113 public FilterActionMenuContributionItem(
114 CustomFiltersActionGroup actionGroup, String filterId,
115 String filterName, boolean state, int itemNumber) {
117 Assert.isNotNull(actionGroup);
118 Assert.isNotNull(filterId);
119 Assert.isNotNull(filterName);
120 fActionGroup = actionGroup;
121 fFilterId = filterId;
122 fFilterName = filterName;
124 fItemNumber = itemNumber;
128 * Overrides method from ContributionItem.
130 public void fill(Menu menu, int index) {
131 MenuItem mi = new MenuItem(menu, SWT.CHECK, index);
132 mi.setText("&" + fItemNumber + " " + fFilterName); //$NON-NLS-1$ //$NON-NLS-2$
134 * XXX: Don't set the image - would look bad because other menu
135 * items don't provide image XXX: Get working set specific image
136 * name from XML - would need to cache icons
138 // mi.setImage(JavaPluginImages.get(JavaPluginImages.IMG_OBJS_JAVA_WORKING_SET));
139 mi.setSelection(fState);
140 mi.addSelectionListener(new SelectionAdapter() {
141 public void widgetSelected(SelectionEvent e) {
143 fActionGroup.setFilter(fFilterId, fState);
149 * @see org.eclipse.jface.action.IContributionItem#isDynamic()
151 public boolean isDynamic() {
156 private static final String TAG_CUSTOM_FILTERS = "customFilters"; //$NON-NLS-1$
158 private static final String TAG_USER_DEFINED_PATTERNS_ENABLED = "userDefinedPatternsEnabled"; //$NON-NLS-1$
160 private static final String TAG_USER_DEFINED_PATTERNS = "userDefinedPatterns"; //$NON-NLS-1$
162 private static final String TAG_XML_DEFINED_FILTERS = "xmlDefinedFilters"; //$NON-NLS-1$
164 private static final String TAG_LRU_FILTERS = "lastRecentlyUsedFilters"; //$NON-NLS-1$
166 private static final String TAG_CHILD = "child"; //$NON-NLS-1$
168 private static final String TAG_PATTERN = "pattern"; //$NON-NLS-1$
170 private static final String TAG_FILTER_ID = "filterId"; //$NON-NLS-1$
172 private static final String TAG_IS_ENABLED = "isEnabled"; //$NON-NLS-1$
174 private static final String SEPARATOR = ","; //$NON-NLS-1$
176 private static final int MAX_FILTER_MENU_ENTRIES = 3;
178 private static final String RECENT_FILTERS_GROUP_NAME = "recentFiltersGroup"; //$NON-NLS-1$
180 private StructuredViewer fViewer;
182 private NamePatternFilter fPatternFilter;
184 private Map fInstalledBuiltInFilters;
186 private Map fEnabledFilterIds;
188 private boolean fUserDefinedPatternsEnabled;
190 private String[] fUserDefinedPatterns;
193 * Recently changed filter Ids stack with oldest on top (i.e. at the end).
197 private Stack fLRUFilterIdsStack;
200 * Handle to menu manager to dynamically update the last recently used
205 private IMenuManager fMenuManager;
208 * The menu listener which dynamically updates the last recently used
213 private IMenuListener fMenuListener;
216 * Filter Ids used in the last view menu invocation.
220 private String[] fFilterIdsUsedInLastViewMenu;
222 private HashMap fFilterDescriptorMap;
224 private String fTargetId;
227 * Creates a new <code>CustomFiltersActionGroup</code>.
230 * the view part that owns this action group
232 * the viewer to be filtered
234 public CustomFiltersActionGroup(IViewPart part, StructuredViewer viewer) {
235 this(part.getViewSite().getId(), viewer);
239 * Creates a new <code>CustomFiltersActionGroup</code>.
242 * the id of this action group's owner
244 * the viewer to be filtered
246 public CustomFiltersActionGroup(String ownerId, StructuredViewer viewer) {
247 Assert.isNotNull(ownerId);
248 Assert.isNotNull(viewer);
252 fLRUFilterIdsStack = new Stack();
254 initializeWithPluginContributions();
255 initializeWithViewDefaults();
261 * Method declared on ActionGroup.
263 public void fillActionBars(IActionBars actionBars) {
264 fillToolBar(actionBars.getToolBarManager());
265 fillViewMenu(actionBars.getMenuManager());
268 public String[] removeFiltersFor(Object parent, Object element,
269 IContentProvider contentProvider) {
270 String[] enabledFilters = getEnabledFilterIds();
271 Set newFilters = new HashSet();
272 for (int i = 0; i < enabledFilters.length; i++) {
273 String filterName = enabledFilters[i];
274 ViewerFilter filter = (ViewerFilter) fInstalledBuiltInFilters
277 newFilters.add(filterName);
278 else if (isSelected(parent, element, contentProvider, filter))
279 newFilters.add(filterName);
281 if (newFilters.size() == enabledFilters.length)
282 return new String[0];
283 return (String[]) newFilters.toArray(new String[newFilters.size()]);
286 public void setFilters(String[] newFilters) {
287 setEnabledFilterIds(newFilters);
288 updateViewerFilters(true);
291 private boolean isSelected(Object parent, Object element,
292 IContentProvider contentProvider, ViewerFilter filter) {
293 if (contentProvider instanceof ITreeContentProvider) {
294 // the element and all its parents have to be selected
295 ITreeContentProvider provider = (ITreeContentProvider) contentProvider;
296 while (element != null && !(element instanceof IJavaModel)) {
297 if (!filter.select(fViewer, parent, element))
299 element = provider.getParent(element);
303 return filter.select(fViewer, parent, element);
307 * Sets the enable state of the given filter.
310 * the id of the filter
314 private void setFilter(String filterId, boolean state) {
315 // Renew filter id in LRU stack
316 fLRUFilterIdsStack.remove(filterId);
317 fLRUFilterIdsStack.add(0, filterId);
319 fEnabledFilterIds.put(filterId, new Boolean(state));
322 updateViewerFilters(true);
325 private String[] getEnabledFilterIds() {
326 Set enabledFilterIds = new HashSet(fEnabledFilterIds.size());
327 Iterator iter = fEnabledFilterIds.entrySet().iterator();
328 while (iter.hasNext()) {
329 Map.Entry entry = (Map.Entry) iter.next();
330 String id = (String) entry.getKey();
331 boolean isEnabled = ((Boolean) entry.getValue()).booleanValue();
333 enabledFilterIds.add(id);
335 return (String[]) enabledFilterIds.toArray(new String[enabledFilterIds
339 private void setEnabledFilterIds(String[] enabledIds) {
340 Iterator iter = fEnabledFilterIds.keySet().iterator();
341 while (iter.hasNext()) {
342 String id = (String) iter.next();
343 fEnabledFilterIds.put(id, Boolean.FALSE);
345 for (int i = 0; i < enabledIds.length; i++)
346 fEnabledFilterIds.put(enabledIds[i], Boolean.TRUE);
349 private void setUserDefinedPatterns(String[] patterns) {
350 fUserDefinedPatterns = patterns;
351 cleanUpPatternDuplicates();
355 * Sets the recently changed filters.
357 * @param changeHistory
361 private void setRecentlyChangedFilters(Stack changeHistory) {
362 Stack oldestFirstStack = new Stack();
364 int length = Math.min(changeHistory.size(), MAX_FILTER_MENU_ENTRIES);
365 for (int i = 0; i < length; i++)
366 oldestFirstStack.push(((FilterDescriptor) changeHistory.pop())
369 length = Math.min(fLRUFilterIdsStack.size(), MAX_FILTER_MENU_ENTRIES
370 - oldestFirstStack.size());
372 for (int i = 0; i < length; i++) {
373 Object filter = fLRUFilterIdsStack.remove(NEWEST);
374 if (!oldestFirstStack.contains(filter))
375 oldestFirstStack.push(filter);
377 fLRUFilterIdsStack = oldestFirstStack;
380 private boolean areUserDefinedPatternsEnabled() {
381 return fUserDefinedPatternsEnabled;
384 private void setUserDefinedPatternsEnabled(boolean state) {
385 fUserDefinedPatternsEnabled = state;
388 private void fillToolBar(IToolBarManager tooBar) {
392 * Fills the given view menu with the entries managed by the group.
397 public void fillViewMenu(IMenuManager viewMenu) {
399 * Don't change the separator group name. Using this name ensures that
400 * other filters get contributed to the same group.
402 viewMenu.add(new Separator("filters")); //$NON-NLS-1$
403 viewMenu.add(new GroupMarker(RECENT_FILTERS_GROUP_NAME));
404 viewMenu.add(new ShowFilterDialogAction());
406 fMenuManager = viewMenu;
407 fMenuListener = new IMenuListener() {
408 public void menuAboutToShow(IMenuManager manager) {
409 removePreviousLRUFilterActions(manager);
410 addLRUFilterActions(manager);
413 fMenuManager.addMenuListener(fMenuListener);
416 private void removePreviousLRUFilterActions(IMenuManager mm) {
417 if (fFilterIdsUsedInLastViewMenu == null)
420 for (int i = 0; i < fFilterIdsUsedInLastViewMenu.length; i++)
421 mm.remove(fFilterIdsUsedInLastViewMenu[i]);
424 private void addLRUFilterActions(IMenuManager mm) {
425 if (fLRUFilterIdsStack.isEmpty()) {
426 fFilterIdsUsedInLastViewMenu = null;
430 SortedSet sortedFilters = new TreeSet(fLRUFilterIdsStack);
431 String[] recentlyChangedFilterIds = (String[]) sortedFilters
432 .toArray(new String[sortedFilters.size()]);
434 fFilterIdsUsedInLastViewMenu = new String[recentlyChangedFilterIds.length];
435 for (int i = 0; i < recentlyChangedFilterIds.length; i++) {
436 String id = recentlyChangedFilterIds[i];
437 fFilterIdsUsedInLastViewMenu[i] = id;
438 boolean state = fEnabledFilterIds.containsKey(id)
439 && ((Boolean) fEnabledFilterIds.get(id)).booleanValue();
440 FilterDescriptor filterDesc = (FilterDescriptor) fFilterDescriptorMap
442 if (filterDesc != null) {
443 IContributionItem item = new FilterActionMenuContributionItem(
444 this, id, filterDesc.getName(), state, i + 1);
445 mm.insertBefore(RECENT_FILTERS_GROUP_NAME, item);
451 * Method declared on ActionGroup.
453 public void dispose() {
454 if (fMenuManager != null)
455 fMenuManager.removeMenuListener(fMenuListener);
459 private void initializeWithPluginContributions() {
460 fUserDefinedPatterns = new String[0];
461 fUserDefinedPatternsEnabled = false;
463 FilterDescriptor[] filterDescs = FilterDescriptor
464 .getFilterDescriptors(fTargetId);
465 fFilterDescriptorMap = new HashMap(filterDescs.length);
466 fEnabledFilterIds = new HashMap(filterDescs.length);
467 for (int i = 0; i < filterDescs.length; i++) {
468 String id = filterDescs[i].getId();
469 Boolean isEnabled = new Boolean(filterDescs[i].isEnabled());
470 if (fEnabledFilterIds.containsKey(id))
472 .logErrorMessage("WARNING: Duplicate id for extension-point \"net.sourceforge.phpdt.ui.javaElementFilters\""); //$NON-NLS-1$
473 fEnabledFilterIds.put(id, isEnabled);
474 fFilterDescriptorMap.put(id, filterDescs[i]);
478 // ---------- viewer filter handling ----------
480 private void installFilters() {
481 fInstalledBuiltInFilters = new HashMap(fEnabledFilterIds.size());
482 fPatternFilter = new NamePatternFilter();
483 fPatternFilter.setPatterns(getUserAndBuiltInPatterns());
484 fViewer.addFilter(fPatternFilter);
485 updateBuiltInFilters();
488 private void updateViewerFilters(boolean refresh) {
489 String[] patterns = getUserAndBuiltInPatterns();
490 fPatternFilter.setPatterns(patterns);
491 fViewer.getControl().setRedraw(false);
492 updateBuiltInFilters();
495 fViewer.getControl().setRedraw(true);
498 private void updateBuiltInFilters() {
499 Set installedFilters = fInstalledBuiltInFilters.keySet();
500 Set filtersToAdd = new HashSet(fEnabledFilterIds.size());
501 Set filtersToRemove = new HashSet(fEnabledFilterIds.size());
502 Iterator iter = fEnabledFilterIds.entrySet().iterator();
503 while (iter.hasNext()) {
504 Map.Entry entry = (Map.Entry) iter.next();
505 String id = (String) entry.getKey();
506 boolean isEnabled = ((Boolean) entry.getValue()).booleanValue();
507 if (isEnabled && !installedFilters.contains(id))
508 filtersToAdd.add(id);
509 else if (!isEnabled && installedFilters.contains(id))
510 filtersToRemove.add(id);
513 // Install the filters
514 FilterDescriptor[] filterDescs = FilterDescriptor
515 .getFilterDescriptors(fTargetId);
516 for (int i = 0; i < filterDescs.length; i++) {
517 String id = filterDescs[i].getId();
518 // just to double check - id should denote a custom filter anyway
519 boolean isCustomFilter = filterDescs[i].isCustomFilter();
520 if (isCustomFilter) {
521 if (filtersToAdd.contains(id)) {
522 ViewerFilter filter = filterDescs[i].createViewerFilter();
523 if (filter != null) {
524 fViewer.addFilter(filter);
525 fInstalledBuiltInFilters.put(id, filter);
528 if (filtersToRemove.contains(id)) {
530 .removeFilter((ViewerFilter) fInstalledBuiltInFilters
532 fInstalledBuiltInFilters.remove(id);
538 private String[] getUserAndBuiltInPatterns() {
539 List patterns = new ArrayList(fUserDefinedPatterns.length);
540 if (areUserDefinedPatternsEnabled())
541 patterns.addAll(Arrays.asList(fUserDefinedPatterns));
542 FilterDescriptor[] filterDescs = FilterDescriptor
543 .getFilterDescriptors(fTargetId);
544 for (int i = 0; i < filterDescs.length; i++) {
545 String id = filterDescs[i].getId();
546 boolean isPatternFilter = filterDescs[i].isPatternFilter();
547 Object isEnabled = fEnabledFilterIds.get(id);
548 if (isEnabled != null && isPatternFilter
549 && ((Boolean) isEnabled).booleanValue())
550 patterns.add(filterDescs[i].getPattern());
552 return (String[]) patterns.toArray(new String[patterns.size()]);
555 // ---------- view kind/defaults persistency ----------
557 private void initializeWithViewDefaults() {
558 // get default values for view
559 IPreferenceStore store = PHPeclipsePlugin.getDefault()
560 .getPreferenceStore();
562 // XXX: can be removed once bug 22533 is fixed.
563 if (!store.contains(getPreferenceKey("TAG_DUMMY_TO_TEST_EXISTENCE")))//$NON-NLS-1$
566 // XXX: Uncomment once bug 22533 is fixed.
568 // (!store.contains(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED)))
571 fUserDefinedPatternsEnabled = store
572 .getBoolean(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED));
573 setUserDefinedPatterns(CustomFiltersDialog.convertFromString(store
574 .getString(getPreferenceKey(TAG_USER_DEFINED_PATTERNS)),
577 Iterator iter = fEnabledFilterIds.keySet().iterator();
578 while (iter.hasNext()) {
579 String id = (String) iter.next();
580 Boolean isEnabled = new Boolean(store.getBoolean(id));
581 fEnabledFilterIds.put(id, isEnabled);
584 fLRUFilterIdsStack.clear();
585 String lruFilterIds = store.getString(TAG_LRU_FILTERS);
586 StringTokenizer tokenizer = new StringTokenizer(lruFilterIds, SEPARATOR);
587 while (tokenizer.hasMoreTokens()) {
588 String id = tokenizer.nextToken();
589 if (fFilterDescriptorMap.containsKey(id)
590 && !fLRUFilterIdsStack.contains(id))
591 fLRUFilterIdsStack.push(id);
595 private void storeViewDefaults() {
596 // get default values for view
597 IPreferenceStore store = PHPeclipsePlugin.getDefault()
598 .getPreferenceStore();
600 // XXX: can be removed once bug 22533 is fixed.
603 getPreferenceKey("TAG_DUMMY_TO_TEST_EXISTENCE"), "storedViewPreferences");//$NON-NLS-1$//$NON-NLS-2$
605 store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS_ENABLED),
606 fUserDefinedPatternsEnabled);
607 store.setValue(getPreferenceKey(TAG_USER_DEFINED_PATTERNS),
608 CustomFiltersDialog.convertToString(fUserDefinedPatterns,
611 Iterator iter = fEnabledFilterIds.entrySet().iterator();
612 while (iter.hasNext()) {
613 Map.Entry entry = (Map.Entry) iter.next();
614 String id = (String) entry.getKey();
615 boolean isEnabled = ((Boolean) entry.getValue()).booleanValue();
616 store.setValue(id, isEnabled);
619 StringBuffer buf = new StringBuffer(fLRUFilterIdsStack.size() * 20);
620 iter = fLRUFilterIdsStack.iterator();
621 while (iter.hasNext()) {
622 buf.append((String) iter.next());
623 buf.append(SEPARATOR);
625 store.setValue(TAG_LRU_FILTERS, buf.toString());
628 private String getPreferenceKey(String tag) {
629 return "CustomFiltersActionGroup." + fTargetId + '.' + tag; //$NON-NLS-1$
632 // ---------- view instance persistency ----------
635 * Saves the state of the custom filters in a memento.
638 * the memento into which the state is saved
640 public void saveState(IMemento memento) {
641 IMemento customFilters = memento.createChild(TAG_CUSTOM_FILTERS);
642 customFilters.putString(TAG_USER_DEFINED_PATTERNS_ENABLED, new Boolean(
643 fUserDefinedPatternsEnabled).toString());
644 saveUserDefinedPatterns(customFilters);
645 saveXmlDefinedFilters(customFilters);
646 saveLRUFilters(customFilters);
649 private void saveXmlDefinedFilters(IMemento memento) {
650 if (fEnabledFilterIds != null && !fEnabledFilterIds.isEmpty()) {
651 IMemento xmlDefinedFilters = memento
652 .createChild(TAG_XML_DEFINED_FILTERS);
653 Iterator iter = fEnabledFilterIds.entrySet().iterator();
654 while (iter.hasNext()) {
655 Map.Entry entry = (Map.Entry) iter.next();
656 String id = (String) entry.getKey();
657 Boolean isEnabled = (Boolean) entry.getValue();
658 IMemento child = xmlDefinedFilters.createChild(TAG_CHILD);
659 child.putString(TAG_FILTER_ID, id);
660 child.putString(TAG_IS_ENABLED, isEnabled.toString());
666 * Stores the last recently used filter Ids into the given memento
669 * the memento into which to store the LRU filter Ids
672 private void saveLRUFilters(IMemento memento) {
673 if (fLRUFilterIdsStack != null && !fLRUFilterIdsStack.isEmpty()) {
674 IMemento lruFilters = memento.createChild(TAG_LRU_FILTERS);
675 Iterator iter = fLRUFilterIdsStack.iterator();
676 while (iter.hasNext()) {
677 String id = (String) iter.next();
678 IMemento child = lruFilters.createChild(TAG_CHILD);
679 child.putString(TAG_FILTER_ID, id);
684 private void saveUserDefinedPatterns(IMemento memento) {
685 if (fUserDefinedPatterns != null && fUserDefinedPatterns.length > 0) {
686 IMemento userDefinedPatterns = memento
687 .createChild(TAG_USER_DEFINED_PATTERNS);
688 for (int i = 0; i < fUserDefinedPatterns.length; i++) {
689 IMemento child = userDefinedPatterns.createChild(TAG_CHILD);
690 child.putString(TAG_PATTERN, fUserDefinedPatterns[i]);
696 * Restores the state of the filter actions from a memento.
698 * Note: This method does not refresh the viewer.
702 * the memento from which the state is restored
704 public void restoreState(IMemento memento) {
707 IMemento customFilters = memento.getChild(TAG_CUSTOM_FILTERS);
708 if (customFilters == null)
710 String userDefinedPatternsEnabled = customFilters
711 .getString(TAG_USER_DEFINED_PATTERNS_ENABLED);
712 if (userDefinedPatternsEnabled == null)
715 fUserDefinedPatternsEnabled = Boolean.valueOf(
716 userDefinedPatternsEnabled).booleanValue();
717 restoreUserDefinedPatterns(customFilters);
718 restoreXmlDefinedFilters(customFilters);
719 restoreLRUFilters(customFilters);
721 updateViewerFilters(false);
724 private void restoreUserDefinedPatterns(IMemento memento) {
725 IMemento userDefinedPatterns = memento
726 .getChild(TAG_USER_DEFINED_PATTERNS);
727 if (userDefinedPatterns != null) {
728 IMemento children[] = userDefinedPatterns.getChildren(TAG_CHILD);
729 String[] patterns = new String[children.length];
730 for (int i = 0; i < children.length; i++)
731 patterns[i] = children[i].getString(TAG_PATTERN);
733 setUserDefinedPatterns(patterns);
735 setUserDefinedPatterns(new String[0]);
738 private void restoreXmlDefinedFilters(IMemento memento) {
739 IMemento xmlDefinedFilters = memento.getChild(TAG_XML_DEFINED_FILTERS);
740 if (xmlDefinedFilters != null) {
741 IMemento[] children = xmlDefinedFilters.getChildren(TAG_CHILD);
742 for (int i = 0; i < children.length; i++) {
743 String id = children[i].getString(TAG_FILTER_ID);
744 Boolean isEnabled = new Boolean(children[i]
745 .getString(TAG_IS_ENABLED));
746 fEnabledFilterIds.put(id, isEnabled);
751 private void restoreLRUFilters(IMemento memento) {
752 IMemento lruFilters = memento.getChild(TAG_LRU_FILTERS);
753 fLRUFilterIdsStack.clear();
754 if (lruFilters != null) {
755 IMemento[] children = lruFilters.getChildren(TAG_CHILD);
756 for (int i = 0; i < children.length; i++) {
757 String id = children[i].getString(TAG_FILTER_ID);
758 if (fFilterDescriptorMap.containsKey(id)
759 && !fLRUFilterIdsStack.contains(id))
760 fLRUFilterIdsStack.push(id);
765 private void cleanUpPatternDuplicates() {
766 if (!areUserDefinedPatternsEnabled())
768 List userDefinedPatterns = new ArrayList(Arrays
769 .asList(fUserDefinedPatterns));
770 FilterDescriptor[] filters = FilterDescriptor
771 .getFilterDescriptors(fTargetId);
773 for (int i = 0; i < filters.length; i++) {
774 if (filters[i].isPatternFilter()) {
775 String pattern = filters[i].getPattern();
776 if (userDefinedPatterns.contains(pattern)) {
777 fEnabledFilterIds.put(filters[i].getId(), Boolean.TRUE);
778 boolean hasMore = true;
780 hasMore = userDefinedPatterns.remove(pattern);
784 fUserDefinedPatterns = (String[]) userDefinedPatterns
785 .toArray(new String[userDefinedPatterns.size()]);
786 setUserDefinedPatternsEnabled(fUserDefinedPatternsEnabled
787 && fUserDefinedPatterns.length > 0);
790 // ---------- dialog related code ----------
792 private void openDialog() {
793 CustomFiltersDialog dialog = new CustomFiltersDialog(fViewer
794 .getControl().getShell(), fTargetId,
795 areUserDefinedPatternsEnabled(), fUserDefinedPatterns,
796 getEnabledFilterIds());
798 if (dialog.open() == Window.OK) {
799 setEnabledFilterIds(dialog.getEnabledFilterIds());
800 setUserDefinedPatternsEnabled(dialog
801 .areUserDefinedPatternsEnabled());
802 setUserDefinedPatterns(dialog.getUserDefinedPatterns());
803 setRecentlyChangedFilters(dialog.getFilterDescriptorChangeHistory());
807 updateViewerFilters(true);