View | Details | Raw Unified | Return to bug 118028 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/util/Util.java (+20 lines)
Lines 27-32 Link Here
27
import java.util.StringTokenizer;
27
import java.util.StringTokenizer;
28
import java.util.TreeMap;
28
import java.util.TreeMap;
29
import java.util.TreeSet;
29
import java.util.TreeSet;
30
import java.util.WeakHashMap;
30
31
31
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.Assert;
32
import org.eclipse.core.runtime.CoreException;
33
import org.eclipse.core.runtime.CoreException;
Lines 845-848 Link Here
845
		return loadedEE;
846
		return loadedEE;
846
	}
847
	}
847
	
848
	
849
	// this is a workaround to extend PatternFilter in 3.3 without 
850
	// adding API.  We need PatternFilter to *not* optimize its filter
851
	// if no pattern text is set.
852
	private static Map filterMap = null;
853
	static Map getFilterMap() {
854
		if (filterMap==null) {
855
			filterMap = new WeakHashMap();
856
		}
857
		return filterMap;
858
	}
859
	
860
	public static void setFilterOptimize(Object filter, boolean value) {
861
		getFilterMap().put(filter, new Boolean(value));
862
	}
863
	
864
	public static boolean getFilterOptimize(Object filter) {
865
		Boolean b = (Boolean) getFilterMap().get(filter);
866
		return b==null?true:b.booleanValue();
867
	}
848
}
868
}
(-)Eclipse UI/org/eclipse/ui/dialogs/PatternFilter.java (-1 / +4 lines)
Lines 23-28 Link Here
23
import org.eclipse.jface.viewers.Viewer;
23
import org.eclipse.jface.viewers.Viewer;
24
import org.eclipse.jface.viewers.ViewerFilter;
24
import org.eclipse.jface.viewers.ViewerFilter;
25
import org.eclipse.ui.internal.misc.StringMatcher;
25
import org.eclipse.ui.internal.misc.StringMatcher;
26
import org.eclipse.ui.internal.util.Util;
26
27
27
/**
28
/**
28
 * A filter used in conjunction with <code>FilteredTree</code>.  In order to 
29
 * A filter used in conjunction with <code>FilteredTree</code>.  In order to 
Lines 61-67 Link Here
61
     * @see org.eclipse.jface.viewers.ViewerFilter#filter(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object[])
62
     * @see org.eclipse.jface.viewers.ViewerFilter#filter(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object[])
62
     */
63
     */
63
    public final Object[] filter(Viewer viewer, Object parent, Object[] elements) {
64
    public final Object[] filter(Viewer viewer, Object parent, Object[] elements) {
64
        if (matcher == null) {
65
    	// we don't want to optimize if we've extended the filter ... this
66
    	// needs to be addressed in 3.4
67
        if (matcher == null && Util.getFilterOptimize(this)) {
65
			return elements;
68
			return elements;
66
		}
69
		}
67
70
(-)Eclipse UI/org/eclipse/ui/internal/keys/KeysPreferenceFiltersDialog.java (+16 lines)
Lines 31-39 Link Here
31
31
32
	private Button actionSetFilterCheckBox;
32
	private Button actionSetFilterCheckBox;
33
	private Button internalFilterCheckBox;
33
	private Button internalFilterCheckBox;
34
	private Button uncategorizedFilterCheckBox;
34
35
35
	private boolean filterActionSet;
36
	private boolean filterActionSet;
36
	private boolean filterInternal;
37
	private boolean filterInternal;
38
	private boolean filterUncategorized;
37
39
38
	void setFilterActionSet(boolean b) {
40
	void setFilterActionSet(boolean b) {
39
		filterActionSet = b;
41
		filterActionSet = b;
Lines 42-47 Link Here
42
	void setFilterInternal(boolean b) {
44
	void setFilterInternal(boolean b) {
43
		filterInternal = b;
45
		filterInternal = b;
44
	}
46
	}
47
	
48
	void setFilterUncategorized(boolean b) {
49
		filterUncategorized = b;
50
	}
45
51
46
	boolean getFilterActionSet() {
52
	boolean getFilterActionSet() {
47
		return filterActionSet;
53
		return filterActionSet;
Lines 50-55 Link Here
50
	boolean getFilterInternal() {
56
	boolean getFilterInternal() {
51
		return filterInternal;
57
		return filterInternal;
52
	}
58
	}
59
	
60
	boolean getFilterUncategorized() {
61
		return filterUncategorized;
62
	}
53
63
54
	/**
64
	/**
55
	 * @param parentShell
65
	 * @param parentShell
Lines 66-71 Link Here
66
	protected void performDefaults() {
76
	protected void performDefaults() {
67
		actionSetFilterCheckBox.setSelection(true);
77
		actionSetFilterCheckBox.setSelection(true);
68
		internalFilterCheckBox.setSelection(true);
78
		internalFilterCheckBox.setSelection(true);
79
		uncategorizedFilterCheckBox.setSelection(true);
69
		super.performDefaults();
80
		super.performDefaults();
70
	}
81
	}
71
82
Lines 85-93 Link Here
85
		internalFilterCheckBox = new Button(topComposite, SWT.CHECK);
96
		internalFilterCheckBox = new Button(topComposite, SWT.CHECK);
86
		internalFilterCheckBox
97
		internalFilterCheckBox
87
				.setText(NewKeysPreferenceMessages.InternalFilterCheckBox_Text);
98
				.setText(NewKeysPreferenceMessages.InternalFilterCheckBox_Text);
99
		uncategorizedFilterCheckBox = new Button(topComposite, SWT.CHECK);
100
		uncategorizedFilterCheckBox
101
				.setText(NewKeysPreferenceMessages.UncategorizedFilterCheckBox_Text);
88
102
89
		actionSetFilterCheckBox.setSelection(filterActionSet);
103
		actionSetFilterCheckBox.setSelection(filterActionSet);
90
		internalFilterCheckBox.setSelection(filterInternal);
104
		internalFilterCheckBox.setSelection(filterInternal);
105
		uncategorizedFilterCheckBox.setSelection(filterUncategorized);
91
		applyDialogFont(topComposite);
106
		applyDialogFont(topComposite);
92
107
93
		return topComposite;
108
		return topComposite;
Lines 101-106 Link Here
101
	protected void okPressed() {
116
	protected void okPressed() {
102
		filterActionSet = actionSetFilterCheckBox.getSelection();
117
		filterActionSet = actionSetFilterCheckBox.getSelection();
103
		filterInternal = internalFilterCheckBox.getSelection();
118
		filterInternal = internalFilterCheckBox.getSelection();
119
		filterUncategorized = uncategorizedFilterCheckBox.getSelection();
104
		super.okPressed();
120
		super.okPressed();
105
	}
121
	}
106
122
(-)Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.java (-68 / +32 lines)
Lines 115-121 Link Here
115
import org.eclipse.ui.commands.ICommandService;
115
import org.eclipse.ui.commands.ICommandService;
116
import org.eclipse.ui.contexts.IContextService;
116
import org.eclipse.ui.contexts.IContextService;
117
import org.eclipse.ui.dialogs.FilteredTree;
117
import org.eclipse.ui.dialogs.FilteredTree;
118
import org.eclipse.ui.dialogs.PatternFilter;
119
import org.eclipse.ui.internal.WorkbenchPlugin;
118
import org.eclipse.ui.internal.WorkbenchPlugin;
120
import org.eclipse.ui.internal.commands.ICommandImageService;
119
import org.eclipse.ui.internal.commands.ICommandImageService;
121
import org.eclipse.ui.internal.misc.Policy;
120
import org.eclipse.ui.internal.misc.Policy;
Lines 399-478 Link Here
399
	 * display elements in the tree according to the selected criteria.
398
	 * display elements in the tree according to the selected criteria.
400
	 * 
399
	 * 
401
	 */
400
	 */
402
	protected class GroupedFilteredTree extends FilteredTree {
401
	protected class CategoryFilterTree extends FilteredTree {
402
403
		private CategoryPatternFilter filter;
403
404
404
		/**
405
		/**
405
		 * Constructor for GroupedFilteredTree.
406
		 * Constructor for PatternFilteredTree.
406
		 * 
407
		 * 
407
		 * @param parent
408
		 * @param parent
408
		 * @param treeStyle
409
		 * @param treeStyle
409
		 * @param filter
410
		 * @param filter
410
		 */
411
		 */
411
		protected GroupedFilteredTree(Composite parent, int treeStyle,
412
		protected CategoryFilterTree(Composite parent, int treeStyle,
412
				PatternFilter filter) {
413
				CategoryPatternFilter filter) {
413
			super(parent, treeStyle, filter);
414
			super(parent, treeStyle, filter);
415
			this.filter = filter;
414
		}
416
		}
415
417
416
		protected void createControl(final Composite parent, final int treeStyle) {
418
		public void filterCategories(boolean b) {
417
			GridData gridData;
419
			filter.filterCategories(b);
418
			GridLayout layout;
420
			textChanged();
419
420
			layout = new GridLayout();
421
			// Why doesn't this seem to be working??
422
			layout.marginHeight = 0;
423
			layout.marginWidth = 0;
424
			setLayout(layout);
425
			setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
426
			setFont(parent.getFont());
427
428
			// Create the filter controls
429
			filterComposite = new Composite(this, SWT.NONE);
430
			GridLayout filterLayout = new GridLayout(2, false);
431
			filterLayout.marginHeight = 0;
432
			filterLayout.marginWidth = 0;
433
			filterComposite.setLayout(filterLayout);
434
			filterComposite.setFont(parent.getFont());
435
436
			createFilterControls(filterComposite);
437
			filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
438
					true, false));
439
440
			// Create a table tree viewer.
441
			final Control treeControl = createTreeControl(this, treeStyle);
442
			gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
443
			gridData.horizontalSpan = 3;
444
			treeControl.setLayoutData(gridData);
445
		}
421
		}
446
422
447
		/**
423
		public boolean isFilteringCategories() {
448
		 * <p>
424
			return filter.isFilteringCategories();
449
		 * Creates the grouping controls that will appear in the top-right in
450
		 * the default layout. The default grouping controls are a label and a
451
		 * combo box.
452
		 * </p>
453
		 * <p>
454
		 * Subclasses may extend or override this method. Before this method
455
		 * completes, <code>groupingCombo</code> should be initialized.
456
		 * Subclasses must create a combo box which contains the possible
457
		 * groupings.
458
		 * </p>
459
		 * 
460
		 * @param parent
461
		 *            The composite in which the grouping control should be
462
		 *            placed; must not be <code>null</code>.
463
		 * @return The composite containing the grouping controls, or the
464
		 *         grouping control itself (if there is only one control).
465
		 */
466
		protected Control createGroupingControl(final Composite parent) {
467
			// Create the composite that will contain the grouping controls.
468
			Composite groupingControl = new Composite(parent, SWT.NONE);
469
			GridLayout layout = new GridLayout(2, false);
470
			layout.marginWidth = 0;
471
			layout.marginHeight = 0;
472
			groupingControl.setLayout(layout);
473
			groupingControl.setFont(parent.getFont());
474
475
			return groupingControl;
476
		}
425
		}
477
	}
426
	}
478
427
Lines 834-839 Link Here
834
783
835
	private static final String TAG_FILTER_INTERNAL = "internalFilter"; //$NON-NLS-1$
784
	private static final String TAG_FILTER_INTERNAL = "internalFilter"; //$NON-NLS-1$
836
785
786
	private static final String TAG_FILTER_UNCAT = "uncategorizedFilter"; //$NON-NLS-1$
787
837
	/**
788
	/**
838
	 * Sorts the given array of <code>NamedHandleObject</code> instances based
789
	 * Sorts the given array of <code>NamedHandleObject</code> instances based
839
	 * on their name. This is generally useful if they will be displayed to an
790
	 * on their name. This is generally useful if they will be displayed to an
Lines 896-902 Link Here
896
	/**
847
	/**
897
	 * The filtered tree containing the list of commands and bindings to edit.
848
	 * The filtered tree containing the list of commands and bindings to edit.
898
	 */
849
	 */
899
	private GroupedFilteredTree filteredTree;
850
	private CategoryFilterTree filteredTree;
851
	
852
	private CategoryPatternFilter patternFilter;
900
853
901
	/**
854
	/**
902
	 * The grouping for the bindings tree. Either there should be no group
855
	 * The grouping for the bindings tree. Either there should be no group
Lines 1165-1173 Link Here
1165
						getShell());
1118
						getShell());
1166
				dialog.setFilterActionSet(filterActionSetContexts);
1119
				dialog.setFilterActionSet(filterActionSetContexts);
1167
				dialog.setFilterInternal(filterInternalContexts);
1120
				dialog.setFilterInternal(filterInternalContexts);
1121
				dialog.setFilterUncategorized(filteredTree.isFilteringCategories());
1168
				if (dialog.open() == Window.OK) {
1122
				if (dialog.open() == Window.OK) {
1169
					filterActionSetContexts = dialog.getFilterActionSet();
1123
					filterActionSetContexts = dialog.getFilterActionSet();
1170
					filterInternalContexts = dialog.getFilterInternal();
1124
					filterInternalContexts = dialog.getFilterInternal();
1125
					filteredTree.filterCategories(dialog
1126
							.getFilterUncategorized());
1171
					whenCombo.setInput(getContexts());
1127
					whenCombo.setInput(getContexts());
1172
					updateDataControls();
1128
					updateDataControls();
1173
				}
1129
				}
Lines 1197-1202 Link Here
1197
		if (settings.get(TAG_FILTER_INTERNAL) != null) {
1153
		if (settings.get(TAG_FILTER_INTERNAL) != null) {
1198
			filterInternalContexts = settings.getBoolean(TAG_FILTER_INTERNAL);
1154
			filterInternalContexts = settings.getBoolean(TAG_FILTER_INTERNAL);
1199
		}
1155
		}
1156
		patternFilter = new CategoryPatternFilter(
1157
				true, commandService.getCategory(null));
1158
		if (settings.get(TAG_FILTER_UNCAT) != null) {
1159
			patternFilter.filterCategories(settings
1160
					.getBoolean(TAG_FILTER_UNCAT));
1161
		}
1200
1162
1201
		// Creates a composite to hold all of the page contents.
1163
		// Creates a composite to hold all of the page contents.
1202
		final Composite page = new Composite(parent, SWT.NONE);
1164
		final Composite page = new Composite(parent, SWT.NONE);
Lines 1466-1474 Link Here
1466
	private final Control createTree(final Composite parent) {
1428
	private final Control createTree(final Composite parent) {
1467
		GridData gridData;
1429
		GridData gridData;
1468
1430
1469
		filteredTree = new GroupedFilteredTree(parent, SWT.SINGLE
1431
		filteredTree = new CategoryFilterTree(parent, SWT.SINGLE
1470
				| SWT.FULL_SELECTION | SWT.BORDER, new PatternFilter());
1432
				| SWT.FULL_SELECTION | SWT.BORDER, patternFilter);
1471
		final GridLayout layout = new GridLayout(2, false);
1433
		final GridLayout layout = new GridLayout(1, false);
1472
		layout.marginWidth = 0;
1434
		layout.marginWidth = 0;
1473
		filteredTree.setLayout(layout);
1435
		filteredTree.setLayout(layout);
1474
		gridData = new GridData();
1436
		gridData = new GridData();
Lines 1509-1515 Link Here
1509
		triggerSequenceColumn
1471
		triggerSequenceColumn
1510
				.setText(NewKeysPreferenceMessages.TriggerSequenceColumn_Text);
1472
				.setText(NewKeysPreferenceMessages.TriggerSequenceColumn_Text);
1511
		triggerSequenceColumn.addSelectionListener(new ResortColumn(comparator,
1473
		triggerSequenceColumn.addSelectionListener(new ResortColumn(comparator,
1512
				triggerSequenceColumn, tree, BindingLabelProvider.COLUMN_TRIGGER_SEQUENCE));
1474
				triggerSequenceColumn, tree,
1475
				BindingLabelProvider.COLUMN_TRIGGER_SEQUENCE));
1513
1476
1514
		final TreeColumn whenColumn = new TreeColumn(tree, SWT.LEFT,
1477
		final TreeColumn whenColumn = new TreeColumn(tree, SWT.LEFT,
1515
				BindingLabelProvider.COLUMN_WHEN);
1478
				BindingLabelProvider.COLUMN_WHEN);
Lines 2247-2252 Link Here
2247
		dialogSettings.put(TAG_FIELD, showAllCheckBox.getSelection());
2210
		dialogSettings.put(TAG_FIELD, showAllCheckBox.getSelection());
2248
		dialogSettings.put(TAG_FILTER_ACTION_SETS, filterActionSetContexts);
2211
		dialogSettings.put(TAG_FILTER_ACTION_SETS, filterActionSetContexts);
2249
		dialogSettings.put(TAG_FILTER_INTERNAL, filterInternalContexts);
2212
		dialogSettings.put(TAG_FILTER_INTERNAL, filterInternalContexts);
2213
		dialogSettings.put(TAG_FILTER_UNCAT, filteredTree.isFilteringCategories());
2250
	}
2214
	}
2251
2215
2252
	protected IDialogSettings getDialogSettings() {
2216
	protected IDialogSettings getDialogSettings() {
(-)Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferenceMessages.java (+1 lines)
Lines 58-63 Link Here
58
	public static String KeysPreferenceFilterDialog_Title;
58
	public static String KeysPreferenceFilterDialog_Title;
59
	public static String ActionSetFilterCheckBox_Text;
59
	public static String ActionSetFilterCheckBox_Text;
60
	public static String InternalFilterCheckBox_Text;
60
	public static String InternalFilterCheckBox_Text;
61
	public static String UncategorizedFilterCheckBox_Text;
61
	
62
	
62
	static {
63
	static {
63
		// load message values from bundle file
64
		// load message values from bundle file
(-)Eclipse UI/org/eclipse/ui/internal/keys/NewKeysPreferencePage.properties (+1 lines)
Lines 45-49 Link Here
45
45
46
ActionSetFilterCheckBox_Text= Filter &action set contexts
46
ActionSetFilterCheckBox_Text= Filter &action set contexts
47
InternalFilterCheckBox_Text = Filter &internal contexts
47
InternalFilterCheckBox_Text = Filter &internal contexts
48
UncategorizedFilterCheckBox_Text = Filter &uncategorized commands
48
KeysPreferenceFilterDialog_Title= When Context Filters
49
KeysPreferenceFilterDialog_Title= When Context Filters
49
50
(-)Eclipse (+70 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.ui.internal.keys;
13
14
import org.eclipse.core.commands.Category;
15
import org.eclipse.core.commands.ParameterizedCommand;
16
import org.eclipse.core.commands.common.NotDefinedException;
17
import org.eclipse.jface.bindings.Binding;
18
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.ui.dialogs.PatternFilter;
20
import org.eclipse.ui.internal.util.Util;
21
22
class CategoryPatternFilter extends PatternFilter {
23
	private boolean filterCategories;
24
	final Category uncategorized;
25
26
	public CategoryPatternFilter(boolean filterCategories, Category c) {
27
		uncategorized = c;
28
		filterCategories(filterCategories);
29
	}
30
31
	public void filterCategories(boolean b) {
32
		filterCategories = b;
33
		Util.setFilterOptimize(this, !b);
34
	}
35
	
36
	public boolean isFilteringCategories() {
37
		return filterCategories;
38
	}
39
40
	/*
41
	 * (non-Javadoc)
42
	 * 
43
	 * @see org.eclipse.ui.dialogs.PatternFilter#isLeafMatch(org.eclipse.jface.viewers.Viewer,
44
	 *      java.lang.Object)
45
	 */
46
	protected boolean isLeafMatch(Viewer viewer, Object element) {
47
		if (filterCategories) {
48
			final ParameterizedCommand cmd = getCommand(element);
49
			try {
50
				if (cmd != null
51
						&& cmd.getCommand().getCategory() == uncategorized) {
52
					return false;
53
				}
54
			} catch (NotDefinedException e) {
55
				return false;
56
			}
57
		}
58
		return super.isLeafMatch(viewer, element);
59
	}
60
61
	private ParameterizedCommand getCommand(Object element) {
62
		if (element instanceof ParameterizedCommand) {
63
			return (ParameterizedCommand) element;
64
		}
65
		if (element instanceof Binding) {
66
			return ((Binding) element).getParameterizedCommand();
67
		}
68
		return null;
69
	}
70
}

Return to bug 118028