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

Collapse All | Expand All

(-)extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java (-16 / +87 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 18-41 Link Here
18
import java.util.Comparator;
18
import java.util.Comparator;
19
import java.util.List;
19
import java.util.List;
20
20
21
import org.eclipse.core.resources.IContainer;
21
import com.ibm.icu.text.Collator;
22
import org.eclipse.core.resources.IResource;
22
23
import org.eclipse.core.resources.IResourceProxy;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.core.resources.IResourceProxyVisitor;
24
import org.eclipse.swt.graphics.Font;
25
import org.eclipse.core.resources.IWorkspace;
25
import org.eclipse.swt.graphics.FontData;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.swt.graphics.Image;
27
import org.eclipse.swt.graphics.TextStyle;
28
import org.eclipse.swt.widgets.Composite;
29
import org.eclipse.swt.widgets.Control;
30
import org.eclipse.swt.widgets.Shell;
31
27
import org.eclipse.core.runtime.CoreException;
32
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IPath;
33
import org.eclipse.core.runtime.IPath;
29
import org.eclipse.core.runtime.IProgressMonitor;
34
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.ListenerList;
36
import org.eclipse.core.runtime.ListenerList;
32
import org.eclipse.core.runtime.Status;
37
import org.eclipse.core.runtime.Status;
38
39
import org.eclipse.core.resources.IContainer;
40
import org.eclipse.core.resources.IResource;
41
import org.eclipse.core.resources.IResourceProxy;
42
import org.eclipse.core.resources.IResourceProxyVisitor;
43
import org.eclipse.core.resources.IWorkspace;
44
import org.eclipse.core.resources.ResourcesPlugin;
45
33
import org.eclipse.jface.action.Action;
46
import org.eclipse.jface.action.Action;
34
import org.eclipse.jface.action.IAction;
47
import org.eclipse.jface.action.IAction;
35
import org.eclipse.jface.action.IMenuManager;
48
import org.eclipse.jface.action.IMenuManager;
36
import org.eclipse.jface.action.Separator;
49
import org.eclipse.jface.action.Separator;
37
import org.eclipse.jface.dialogs.IDialogSettings;
50
import org.eclipse.jface.dialogs.IDialogSettings;
38
import org.eclipse.jface.text.ITextSelection;
39
import org.eclipse.jface.util.IPropertyChangeListener;
51
import org.eclipse.jface.util.IPropertyChangeListener;
40
import org.eclipse.jface.util.PropertyChangeEvent;
52
import org.eclipse.jface.util.PropertyChangeEvent;
41
import org.eclipse.jface.viewers.ILabelProviderListener;
53
import org.eclipse.jface.viewers.ILabelProviderListener;
Lines 46-55 Link Here
46
import org.eclipse.jface.viewers.Viewer;
58
import org.eclipse.jface.viewers.Viewer;
47
import org.eclipse.jface.viewers.ViewerFilter;
59
import org.eclipse.jface.viewers.ViewerFilter;
48
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
60
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
49
import org.eclipse.swt.graphics.Image;
61
import org.eclipse.jface.viewers.StyledString.Styler;
50
import org.eclipse.swt.widgets.Composite;
62
51
import org.eclipse.swt.widgets.Control;
63
import org.eclipse.jface.text.ITextSelection;
52
import org.eclipse.swt.widgets.Shell;
64
53
import org.eclipse.ui.IMemento;
65
import org.eclipse.ui.IMemento;
54
import org.eclipse.ui.IWorkbenchPage;
66
import org.eclipse.ui.IWorkbenchPage;
55
import org.eclipse.ui.IWorkbenchWindow;
67
import org.eclipse.ui.IWorkbenchWindow;
Lines 68-75 Link Here
68
import org.eclipse.ui.model.WorkbenchLabelProvider;
80
import org.eclipse.ui.model.WorkbenchLabelProvider;
69
import org.eclipse.ui.statushandlers.StatusManager;
81
import org.eclipse.ui.statushandlers.StatusManager;
70
82
71
import com.ibm.icu.text.Collator;
72
73
/**
83
/**
74
 * Shows a list of resources to the user with a text entry field for a string
84
 * Shows a list of resources to the user with a text entry field for a string
75
 * pattern used to filter the list of resources.
85
 * pattern used to filter the list of resources.
Lines 103-108 Link Here
103
113
104
	private boolean isDerived;
114
	private boolean isDerived;
105
115
116
	private SearchPattern searchPattern;
117
106
	/**
118
	/**
107
	 * Creates a new instance of the class
119
	 * Creates a new instance of the class
108
	 * 
120
	 * 
Lines 377-383 Link Here
377
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
389
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
378
	 */
390
	 */
379
	protected ItemsFilter createFilter() {
391
	protected ItemsFilter createFilter() {
380
		return new ResourceFilter(container, isDerived, typeMask);
392
		ItemsFilter filter= new ResourceFilter(container, isDerived, typeMask);
393
		searchPattern= filter.getPatternMatcher();
394
		return filter;
381
	}
395
	}
382
396
383
	/* (non-Javadoc)
397
	/* (non-Javadoc)
Lines 478-489 Link Here
478
492
479
		WorkbenchLabelProvider provider = new WorkbenchLabelProvider();
493
		WorkbenchLabelProvider provider = new WorkbenchLabelProvider();
480
494
495
		private Font fBoldFont;
496
497
		private Styler boldStyler;
498
499
		private Styler boldQualifierStyler;
500
501
481
		/**
502
		/**
482
		 * Creates a new instance of the class
503
		 * Creates a new instance of the class
483
		 */
504
		 */
484
		public ResourceItemLabelProvider() {
505
		public ResourceItemLabelProvider() {
485
			super();
506
			super();
486
			provider.addListener(this);
507
			provider.addListener(this);
508
			boldStyler= createBoldStyler();
509
			boldQualifierStyler= createBoldQualifierStyler();
487
		}
510
		}
488
511
489
		/*
512
		/*
Lines 533-548 Link Here
533
556
534
			IResource res = (IResource) element;
557
			IResource res = (IResource) element;
535
558
559
			String name= res.getName();
536
			StyledString str = new StyledString(res.getName());
560
			StyledString str = new StyledString(res.getName());
561
			markMatchingRegions(str, 0, searchPattern.getMatchingRegions(name), boldStyler);
537
562
538
			// extra info for duplicates
563
			// extra info for duplicates
539
			if (isDuplicateElement(element)) {
564
			if (isDuplicateElement(element)) {
540
				str.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
565
				str.append(" - ", StyledString.QUALIFIER_STYLER); //$NON-NLS-1$
541
				str.append(res.getParent().getFullPath().makeRelative().toString(), StyledString.QUALIFIER_STYLER);
566
				final String fullPath= res.getParent().getFullPath().makeRelative().toString();
567
				int index= str.length();
568
				str.append(fullPath, StyledString.QUALIFIER_STYLER);
569
				markMatchingRegions(str, index, searchPattern.getMatchingRegions(fullPath), boldQualifierStyler);
542
			}
570
			}
543
			return str;
571
			return str;
544
		}
572
		}
545
573
574
		private void markMatchingRegions(StyledString string, int index, int[] matchingRegions, Styler styler) {
575
			if (matchingRegions != null) {
576
				for (int i= 0; i + 1 < matchingRegions.length; i= i + 2)
577
					string.setStyle(index + matchingRegions[i], matchingRegions[i + 1], styler);
578
			}
579
		}
580
581
		private Styler createBoldStyler() {
582
			return new Styler() {
583
				public void applyStyles(TextStyle textStyle) {
584
					textStyle.font= getBoldFont();
585
				}
586
			};
587
		}
588
589
		private Styler createBoldQualifierStyler() {
590
			return new Styler() {
591
				public void applyStyles(TextStyle textStyle) {
592
					StyledString.QUALIFIER_STYLER.applyStyles(textStyle);
593
					textStyle.font= getBoldFont();
594
				}
595
			};
596
		}
597
598
599
		/**
600
		 * Create the bold variant of the currently used font.
601
		 * 
602
		 * @return the bold font
603
		 * @since 3.5
604
		 */
605
		private Font getBoldFont() {
606
			if (fBoldFont == null) {
607
				Font font= getDialogArea().getFont();
608
				FontData[] data= font.getFontData();
609
				for (int i= 0; i < data.length; i++) {
610
					data[i].setStyle(SWT.BOLD);
611
				}
612
				fBoldFont= new Font(font.getDevice(), data);
613
			}
614
			return fBoldFont;
615
		}
616
546
		/*
617
		/*
547
		 * (non-Javadoc)
618
		 * (non-Javadoc)
548
		 * 
619
		 * 
(-)Eclipse UI/org/eclipse/ui/dialogs/FilteredItemsSelectionDialog.java (-35 / +48 lines)
Lines 28-33 Link Here
28
import java.util.List;
28
import java.util.List;
29
import java.util.Set;
29
import java.util.Set;
30
30
31
import org.eclipse.osgi.util.NLS;
32
33
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.accessibility.AccessibleAdapter;
35
import org.eclipse.swt.accessibility.AccessibleEvent;
36
import org.eclipse.swt.custom.CLabel;
37
import org.eclipse.swt.custom.ViewForm;
38
import org.eclipse.swt.events.KeyAdapter;
39
import org.eclipse.swt.events.KeyEvent;
40
import org.eclipse.swt.events.ModifyEvent;
41
import org.eclipse.swt.events.ModifyListener;
42
import org.eclipse.swt.events.MouseAdapter;
43
import org.eclipse.swt.events.MouseEvent;
44
import org.eclipse.swt.events.SelectionAdapter;
45
import org.eclipse.swt.events.SelectionEvent;
46
import org.eclipse.swt.events.TraverseEvent;
47
import org.eclipse.swt.events.TraverseListener;
48
import org.eclipse.swt.graphics.Color;
49
import org.eclipse.swt.graphics.Font;
50
import org.eclipse.swt.graphics.GC;
51
import org.eclipse.swt.graphics.Image;
52
import org.eclipse.swt.graphics.Point;
53
import org.eclipse.swt.graphics.Rectangle;
54
import org.eclipse.swt.layout.GridData;
55
import org.eclipse.swt.layout.GridLayout;
56
import org.eclipse.swt.widgets.Composite;
57
import org.eclipse.swt.widgets.Control;
58
import org.eclipse.swt.widgets.Display;
59
import org.eclipse.swt.widgets.Event;
60
import org.eclipse.swt.widgets.Label;
61
import org.eclipse.swt.widgets.Menu;
62
import org.eclipse.swt.widgets.Shell;
63
import org.eclipse.swt.widgets.Table;
64
import org.eclipse.swt.widgets.Text;
65
import org.eclipse.swt.widgets.ToolBar;
66
import org.eclipse.swt.widgets.ToolItem;
67
31
import org.eclipse.core.commands.AbstractHandler;
68
import org.eclipse.core.commands.AbstractHandler;
32
import org.eclipse.core.commands.ExecutionEvent;
69
import org.eclipse.core.commands.ExecutionEvent;
33
import org.eclipse.core.commands.IHandler;
70
import org.eclipse.core.commands.IHandler;
Lines 74-114 Link Here
74
import org.eclipse.jface.viewers.ViewerCell;
111
import org.eclipse.jface.viewers.ViewerCell;
75
import org.eclipse.jface.viewers.ViewerFilter;
112
import org.eclipse.jface.viewers.ViewerFilter;
76
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
113
import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
77
import org.eclipse.osgi.util.NLS;
114
78
import org.eclipse.swt.SWT;
79
import org.eclipse.swt.accessibility.AccessibleAdapter;
80
import org.eclipse.swt.accessibility.AccessibleEvent;
81
import org.eclipse.swt.custom.CLabel;
82
import org.eclipse.swt.custom.ViewForm;
83
import org.eclipse.swt.events.KeyAdapter;
84
import org.eclipse.swt.events.KeyEvent;
85
import org.eclipse.swt.events.ModifyEvent;
86
import org.eclipse.swt.events.ModifyListener;
87
import org.eclipse.swt.events.MouseAdapter;
88
import org.eclipse.swt.events.MouseEvent;
89
import org.eclipse.swt.events.SelectionAdapter;
90
import org.eclipse.swt.events.SelectionEvent;
91
import org.eclipse.swt.events.TraverseEvent;
92
import org.eclipse.swt.events.TraverseListener;
93
import org.eclipse.swt.graphics.Color;
94
import org.eclipse.swt.graphics.Font;
95
import org.eclipse.swt.graphics.GC;
96
import org.eclipse.swt.graphics.Image;
97
import org.eclipse.swt.graphics.Point;
98
import org.eclipse.swt.graphics.Rectangle;
99
import org.eclipse.swt.layout.GridData;
100
import org.eclipse.swt.layout.GridLayout;
101
import org.eclipse.swt.widgets.Composite;
102
import org.eclipse.swt.widgets.Control;
103
import org.eclipse.swt.widgets.Display;
104
import org.eclipse.swt.widgets.Event;
105
import org.eclipse.swt.widgets.Label;
106
import org.eclipse.swt.widgets.Menu;
107
import org.eclipse.swt.widgets.Shell;
108
import org.eclipse.swt.widgets.Table;
109
import org.eclipse.swt.widgets.Text;
110
import org.eclipse.swt.widgets.ToolBar;
111
import org.eclipse.swt.widgets.ToolItem;
112
import org.eclipse.ui.ActiveShellExpression;
115
import org.eclipse.ui.ActiveShellExpression;
113
import org.eclipse.ui.IMemento;
116
import org.eclipse.ui.IMemento;
114
import org.eclipse.ui.IWorkbenchPreferenceConstants;
117
import org.eclipse.ui.IWorkbenchPreferenceConstants;
Lines 2543-2548 Link Here
2543
		 */
2546
		 */
2544
		public abstract boolean isConsistentItem(Object item);
2547
		public abstract boolean isConsistentItem(Object item);
2545
2548
2549
		/**
2550
		 * Returns the search pattern patcher.
2551
		 * 
2552
		 * @return the search pattern matcher
2553
		 * @since 3.5
2554
		 */
2555
		public SearchPattern getPatternMatcher() {
2556
			return patternMatcher;
2557
		}
2558
2546
	}
2559
	}
2547
2560
2548
	/**
2561
	/**
(-)Eclipse UI/org/eclipse/ui/dialogs/SearchPattern.java (-1 / +32 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
2
 * Copyright (c) 2000, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 183-188 Link Here
183
		}
183
		}
184
	}
184
	}
185
185
186
	/**
187
	 * Answers all the regions in a given name matching a given pattern using a specified match
188
	 * rule.
189
	 * 
190
	 * !!! FIXME: more Javadoc needed !!!
191
	 * 
192
	 * @param string the string for which to compute the match regions
193
	 * @return an array of <code>int</code> having two slots per returned regions (the first one is
194
	 *         the region starting index and the second one is the region length or
195
	 *         <code>null</code> if the given name does not match the given pattern).
196
	 *         <p>
197
	 *         The returned regions may be empty (<code>new int[0]</code>) if the pattern is
198
	 *         <code>null</code> (whatever the match rule is). The returned regions will also be
199
	 *         empty if the pattern is only made of <code>'?'</code> and/or <code>'*'</code>
200
	 *         character(s) (e.g. <code>'*'</code>, <code>'?*'</code>, <code>'???'</code>, etc.) when using a pattern match
201
	 *         rule.
202
	 *         </p>
203
	 * @since 3.5
204
	 */
205
	public int[] getMatchingRegions(String string) {
206
207
		// !!! FIXME: to be implemented correctly !!!
208
209
		if (string == null || stringPattern == null)
210
			return null;
211
		int i= string.toLowerCase().indexOf(stringPattern.toLowerCase());
212
		if (i == -1)
213
			return null;
214
		return new int[] { i, stringPattern.length() };
215
	}
216
186
	private void initializePatternAndMatchRule(String pattern) {
217
	private void initializePatternAndMatchRule(String pattern) {
187
		int length = pattern.length();
218
		int length = pattern.length();
188
		if (length == 0) {
219
		if (length == 0) {

Return to bug 264840