Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 301820 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (-3 / +5 lines)
Lines 296-305 Link Here
296
296
297
filterProvider.description = * = any string, ? = any character, \\ = escape literals: * ? \\
297
filterProvider.description = * = any string, ? = any character, \\ = escape literals: * ? \\
298
filterProvider.name = String Matcher
298
filterProvider.name = String Matcher
299
orFilterProvider.name = OR group
299
orFilterProvider.name =OR
300
orFilterProvider.description = Allows grouping others filters with the OR logical preposition
300
orFilterProvider.description = Allows grouping others filters with the OR logical preposition
301
andFilterProvider.name = AND group
301
andFilterProvider.name =AND
302
andFilterProvider.description = Allows grouping others filters with the AND logical preposition
302
andFilterProvider.description = Allows grouping others filters with the AND logical preposition
303
notFilterProvider.name = NOT group
303
notFilterProvider.name =NOT
304
notFilterProvider.description = Allows grouping others filters with the NOT logical preposition
304
notFilterProvider.description = Allows grouping others filters with the NOT logical preposition
305
installationPage.feature.name = Features
305
installationPage.feature.name = Features
306
multiFilterProvider.name = Default
307
multiFilterProvider.description = Match many attributes of files and folders
(-)plugin.xml (+8 lines)
Lines 2328-2333 Link Here
2328
            name="%notFilterProvider.name"
2328
            name="%notFilterProvider.name"
2329
            ordering="first">
2329
            ordering="first">
2330
      </filterMatcher>
2330
      </filterMatcher>
2331
      <filterMatcher
2332
            argumentType="string"
2333
            class="org.eclipse.ui.internal.ide.misc.MultiMatcher"
2334
            description="%multiFilterProvider.description"
2335
            id="org.eclipse.ui.ide.multiFilter"
2336
            name="%multiFilterProvider.name"
2337
            ordering="first">
2338
      </filterMatcher>
2331
   </extension>
2339
   </extension>
2332
   <extension
2340
   <extension
2333
         point="org.eclipse.ui.installationPages">
2341
         point="org.eclipse.ui.installationPages">
(-)src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java (+34 lines)
Lines 53-58 Link Here
53
	public static String ResourceFilterPage_title;
53
	public static String ResourceFilterPage_title;
54
	public static String ResourceFilterPage_noResource;
54
	public static String ResourceFilterPage_noResource;
55
	public static String ResourceFilterPage_addButtonLabel;
55
	public static String ResourceFilterPage_addButtonLabel;
56
	public static String ResourceFilterPage_addGroupButtonLabel;
56
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_upButtonLabel;
59
	public static String ResourceFilterPage_upButtonLabel;
Lines 63-68 Link Here
63
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterArguments;
66
	public static String ResourceFilterPage_columnFilterArguments;
67
	public static String ResourceFilterPage_applyRecursivelyToFolderStructure;
68
	public static String ResourceFilterPage_customize;
69
	public static String ResourceFilterPage_customizeTitle;
70
	public static String ResourceFilterPage_customizeMessage;
71
	public static String ResourceFilterPage_caseSensitive;
72
	public static String ResourceFilterPage_regularExpression;
73
	public static String ResourceFilterPage_multiMatcher_Matcher;
74
	public static String ResourceFilterPage_multiMatcher_FileLength;
75
	public static String ResourceFilterPage_multiMatcher_TimeInterval;
76
	public static String ResourceFilterPage_multiMatcher_InvalidFileLength;
77
	public static String ResourceFilterPage_multiMatcher_InvalidTimeInterval;
66
	public static String ResourceFilterPage_includeOnly;
78
	public static String ResourceFilterPage_includeOnly;
67
	public static String ResourceFilterPage_excludeAll;
79
	public static String ResourceFilterPage_excludeAll;
68
	public static String ResourceFilterPage_includeOnlyColumn;
80
	public static String ResourceFilterPage_includeOnlyColumn;
Lines 77-82 Link Here
77
	public static String ResourceFilterPage_invalidFilterArgument;
89
	public static String ResourceFilterPage_invalidFilterArgument;
78
	public static String ResourceFilterPage_description;
90
	public static String ResourceFilterPage_description;
79
	public static String ResourceFilterPage_addSubFilterActionLabel;
91
	public static String ResourceFilterPage_addSubFilterActionLabel;
92
	public static String ResourceFilterPage_addSubFilterGroupActionLabel;
93
	public static String ResourceFilterPage_removeFilterActionLabel;
94
	public static String ResourceFilterPage_editFilterActionLabel;
95
	public static String ResourceFilterPage_multiKeyName;
96
	public static String ResourceFilterPage_multiKeyProjectRelativePath;
97
	public static String ResourceFilterPage_multiKeyLocation;
98
	public static String ResourceFilterPage_multiKeyLastModified;
99
	public static String ResourceFilterPage_multiKeyCreated;
100
	public static String ResourceFilterPage_multiKeyLength;
101
	public static String ResourceFilterPage_multiKeyReadOnly;
102
	public static String ResourceFilterPage_multiKeySymLink;
103
	public static String ResourceFilterPage_multiEquals;
104
	public static String ResourceFilterPage_multiMatches;
105
	public static String ResourceFilterPage_multiLargerThan;
106
	public static String ResourceFilterPage_multiSmallerThan;
107
	public static String ResourceFilterPage_multiBefore;
108
	public static String ResourceFilterPage_multiAfter;
109
	public static String ResourceFilterPage_multiWithin;
110
	public static String ResourceFilterPage_true;
111
	public static String ResourceFilterPage_false;
112
	public static String ResourceFilterPage_columnFilterTypeLabel;
113
	
80
	//
114
	//
81
	//
115
	//
82
	// Copies from org.eclipse.ui.workbench
116
	// Copies from org.eclipse.ui.workbench
(-)src/org/eclipse/ui/internal/ide/messages.properties (-3 / +36 lines)
Lines 573-588 Link Here
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
575
ResourceFilterPage_addButtonLabel=&Add...
575
ResourceFilterPage_addButtonLabel=&Add...
576
ResourceFilterPage_addGroupButtonLabel=Add &Group...
576
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_columnFilterID=T&ype
582
ResourceFilterPage_columnFilterID=T&ype
583
ResourceFilterPage_columnFilterTypeLabel=Match
582
ResourceFilterPage_columnFilterMode=Mode
584
ResourceFilterPage_columnFilterMode=Mode
583
ResourceFilterPage_columnFilterTargets=Target
585
ResourceFilterPage_columnFilterTargets=Applies To
584
ResourceFilterPage_columnFilterInheritable=In&heritable
586
ResourceFilterPage_columnFilterInheritable=Recursive
585
ResourceFilterPage_columnFilterArguments=&Pattern
587
ResourceFilterPage_columnFilterArguments=&Pattern
588
ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure
589
ResourceFilterPage_customize=Advanced...
590
ResourceFilterPage_customizeTitle=Filter Matcher Selection
591
ResourceFilterPage_customizeMessage=Select resource filter matcher:
592
ResourceFilterPage_caseSensitive=&Case sensitive
593
ResourceFilterPage_regularExpression=Re&gular expression
594
ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \)
595
ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes, *g = gigabytes)
596
ResourceFilterPage_multiMatcher_TimeInterval= (*s = seconds, *m = minutes, *h = hours, *d = days)
597
ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0}
598
ResourceFilterPage_multiMatcher_InvalidTimeInterval=Invalid time interval syntax: {0}
586
ResourceFilterPage_includeOnly=&Include
599
ResourceFilterPage_includeOnly=&Include
587
ResourceFilterPage_excludeAll=&Exclude
600
ResourceFilterPage_excludeAll=&Exclude
588
ResourceFilterPage_includeOnlyColumn=Include
601
ResourceFilterPage_includeOnlyColumn=Include
Lines 596-602 Link Here
596
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
609
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
597
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
610
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
598
ResourceFilterPage_description=Description
611
ResourceFilterPage_description=Description
599
ResourceFilterPage_addSubFilterActionLabel=Add Condition...
612
ResourceFilterPage_addSubFilterActionLabel=Add &Condition...
613
ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group...
614
ResourceFilterPage_removeFilterActionLabel=&Remove
615
ResourceFilterPage_editFilterActionLabel=&Edit
616
ResourceFilterPage_multiKeyName=Name
617
ResourceFilterPage_multiKeyProjectRelativePath=Project Relative Path
618
ResourceFilterPage_multiKeyLocation=Location
619
ResourceFilterPage_multiKeyLastModified=Last Modified
620
ResourceFilterPage_multiKeyCreated=Date Created
621
ResourceFilterPage_multiKeyLength=File Length
622
ResourceFilterPage_multiKeyReadOnly=Read Only
623
ResourceFilterPage_multiKeySymLink=Symbolic Link
624
ResourceFilterPage_multiEquals=equals
625
ResourceFilterPage_multiMatches=matches
626
ResourceFilterPage_multiLargerThan=is larger than
627
ResourceFilterPage_multiSmallerThan=is smaller than
628
ResourceFilterPage_multiBefore=is before
629
ResourceFilterPage_multiAfter=is after
630
ResourceFilterPage_multiWithin=is within
631
ResourceFilterPage_true=true
632
ResourceFilterPage_false=false
600
ResourceInfo_folder = Folder
633
ResourceInfo_folder = Folder
601
ResourceInfo_project = Project
634
ResourceInfo_project = Project
602
ResourceInfo_linkedFile = Linked File
635
ResourceInfo_linkedFile = Linked File
(-)src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java (-301 / +1343 lines)
Lines 16-24 Link Here
16
import java.io.DataInputStream;
16
import java.io.DataInputStream;
17
import java.io.DataOutputStream;
17
import java.io.DataOutputStream;
18
import java.io.IOException;
18
import java.io.IOException;
19
import java.text.DateFormat;
20
import java.util.ArrayList;
19
import java.util.Arrays;
21
import java.util.Arrays;
22
import java.util.Calendar;
23
import java.util.Comparator;
24
import java.util.Date;
20
import java.util.Iterator;
25
import java.util.Iterator;
21
import java.util.LinkedList;
26
import java.util.LinkedList;
27
import java.util.List;
28
import java.util.TreeMap;
22
29
23
import org.eclipse.core.internal.resources.FilterDescriptor;
30
import org.eclipse.core.internal.resources.FilterDescriptor;
24
import org.eclipse.core.resources.FileInfoMatcherDescription;
31
import org.eclipse.core.resources.FileInfoMatcherDescription;
Lines 32-62 Link Here
32
import org.eclipse.core.runtime.Assert;
39
import org.eclipse.core.runtime.Assert;
33
import org.eclipse.core.runtime.CoreException;
40
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
41
import org.eclipse.core.runtime.IPath;
42
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.NullProgressMonitor;
43
import org.eclipse.core.runtime.NullProgressMonitor;
44
import org.eclipse.core.runtime.Platform;
45
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.action.Action;
46
import org.eclipse.jface.action.Action;
37
import org.eclipse.jface.action.MenuManager;
47
import org.eclipse.jface.action.MenuManager;
48
import org.eclipse.jface.action.Separator;
38
import org.eclipse.jface.dialogs.Dialog;
49
import org.eclipse.jface.dialogs.Dialog;
39
import org.eclipse.jface.dialogs.ErrorDialog;
50
import org.eclipse.jface.dialogs.ErrorDialog;
40
import org.eclipse.jface.dialogs.IDialogConstants;
51
import org.eclipse.jface.dialogs.IDialogConstants;
41
import org.eclipse.jface.dialogs.TrayDialog;
52
import org.eclipse.jface.dialogs.TrayDialog;
42
import org.eclipse.jface.fieldassist.TextContentAdapter;
53
import org.eclipse.jface.fieldassist.TextContentAdapter;
54
import org.eclipse.jface.layout.TreeColumnLayout;
43
import org.eclipse.jface.resource.ImageDescriptor;
55
import org.eclipse.jface.resource.ImageDescriptor;
44
import org.eclipse.jface.resource.JFaceResources;
56
import org.eclipse.jface.resource.JFaceResources;
45
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
57
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
46
import org.eclipse.jface.viewers.CellEditor;
58
import org.eclipse.jface.viewers.CellEditor;
47
import org.eclipse.jface.viewers.CheckboxCellEditor;
59
import org.eclipse.jface.viewers.CheckboxCellEditor;
60
import org.eclipse.jface.viewers.ColumnWeightData;
48
import org.eclipse.jface.viewers.ComboBoxCellEditor;
61
import org.eclipse.jface.viewers.ComboBoxCellEditor;
49
import org.eclipse.jface.viewers.ICellModifier;
62
import org.eclipse.jface.viewers.ICellModifier;
50
import org.eclipse.jface.viewers.ILabelProviderListener;
51
import org.eclipse.jface.viewers.ISelection;
63
import org.eclipse.jface.viewers.ISelection;
52
import org.eclipse.jface.viewers.ISelectionChangedListener;
64
import org.eclipse.jface.viewers.ISelectionChangedListener;
65
import org.eclipse.jface.viewers.IStructuredContentProvider;
53
import org.eclipse.jface.viewers.IStructuredSelection;
66
import org.eclipse.jface.viewers.IStructuredSelection;
54
import org.eclipse.jface.viewers.ITableLabelProvider;
55
import org.eclipse.jface.viewers.ITreeContentProvider;
67
import org.eclipse.jface.viewers.ITreeContentProvider;
56
import org.eclipse.jface.viewers.SelectionChangedEvent;
68
import org.eclipse.jface.viewers.SelectionChangedEvent;
69
import org.eclipse.jface.viewers.StyledCellLabelProvider;
70
import org.eclipse.jface.viewers.StyledString;
71
import org.eclipse.jface.viewers.StyledString.Styler;
57
import org.eclipse.jface.viewers.TextCellEditor;
72
import org.eclipse.jface.viewers.TextCellEditor;
58
import org.eclipse.jface.viewers.TreeViewer;
73
import org.eclipse.jface.viewers.TreeViewer;
59
import org.eclipse.jface.viewers.Viewer;
74
import org.eclipse.jface.viewers.Viewer;
75
import org.eclipse.jface.viewers.ViewerCell;
60
import org.eclipse.jface.viewers.ViewerDropAdapter;
76
import org.eclipse.jface.viewers.ViewerDropAdapter;
61
import org.eclipse.jface.window.Window;
77
import org.eclipse.jface.window.Window;
62
import org.eclipse.osgi.util.NLS;
78
import org.eclipse.osgi.util.NLS;
Lines 73-104 Link Here
73
import org.eclipse.swt.events.ModifyListener;
89
import org.eclipse.swt.events.ModifyListener;
74
import org.eclipse.swt.events.MouseEvent;
90
import org.eclipse.swt.events.MouseEvent;
75
import org.eclipse.swt.events.MouseListener;
91
import org.eclipse.swt.events.MouseListener;
92
import org.eclipse.swt.events.SelectionAdapter;
76
import org.eclipse.swt.events.SelectionEvent;
93
import org.eclipse.swt.events.SelectionEvent;
77
import org.eclipse.swt.events.SelectionListener;
78
import org.eclipse.swt.graphics.Color;
94
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.Font;
95
import org.eclipse.swt.graphics.Font;
96
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.FontMetrics;
97
import org.eclipse.swt.graphics.FontMetrics;
81
import org.eclipse.swt.graphics.GC;
98
import org.eclipse.swt.graphics.GC;
82
import org.eclipse.swt.graphics.Image;
99
import org.eclipse.swt.graphics.Image;
100
import org.eclipse.swt.graphics.TextStyle;
83
import org.eclipse.swt.layout.GridData;
101
import org.eclipse.swt.layout.GridData;
84
import org.eclipse.swt.layout.GridLayout;
102
import org.eclipse.swt.layout.GridLayout;
85
import org.eclipse.swt.widgets.Button;
103
import org.eclipse.swt.widgets.Button;
86
import org.eclipse.swt.widgets.Combo;
104
import org.eclipse.swt.widgets.Combo;
87
import org.eclipse.swt.widgets.Composite;
105
import org.eclipse.swt.widgets.Composite;
88
import org.eclipse.swt.widgets.Control;
106
import org.eclipse.swt.widgets.Control;
107
import org.eclipse.swt.widgets.DateTime;
108
import org.eclipse.swt.widgets.Display;
109
import org.eclipse.swt.widgets.Event;
89
import org.eclipse.swt.widgets.Group;
110
import org.eclipse.swt.widgets.Group;
90
import org.eclipse.swt.widgets.Label;
111
import org.eclipse.swt.widgets.Label;
91
import org.eclipse.swt.widgets.Shell;
112
import org.eclipse.swt.widgets.Shell;
92
import org.eclipse.swt.widgets.TableItem;
113
import org.eclipse.swt.widgets.TableItem;
93
import org.eclipse.swt.widgets.Text;
114
import org.eclipse.swt.widgets.Text;
94
import org.eclipse.swt.widgets.TreeColumn;
115
import org.eclipse.swt.widgets.TreeColumn;
116
import org.eclipse.swt.widgets.Widget;
95
import org.eclipse.ui.IWorkbenchWindow;
117
import org.eclipse.ui.IWorkbenchWindow;
96
import org.eclipse.ui.PlatformUI;
118
import org.eclipse.ui.PlatformUI;
119
import org.eclipse.ui.dialogs.ListDialog;
97
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
120
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
98
import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription;
121
import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription;
99
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
122
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
100
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
123
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
101
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
124
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
125
import org.eclipse.ui.internal.ide.misc.MultiMatcher;
102
import org.eclipse.ui.plugin.AbstractUIPlugin;
126
import org.eclipse.ui.plugin.AbstractUIPlugin;
103
127
104
/**
128
/**
Lines 108-113 Link Here
108
public class ResourceFilterGroup {
132
public class ResourceFilterGroup {
109
133
110
	private Button addButton = null;
134
	private Button addButton = null;
135
	private Button addGroupButton = null;
111
	private Button removeButton = null;
136
	private Button removeButton = null;
112
	private Button upButton = null;
137
	private Button upButton = null;
113
	private Button downButton = null;
138
	private Button downButton = null;
Lines 117-122 Link Here
117
	private Filters filters;
142
	private Filters filters;
118
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
143
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
119
	private LabelProvider labelProvider;
144
	private LabelProvider labelProvider;
145
	Font boldFont;
146
	Font plainFont;
120
	private Image checkIcon = null;
147
	private Image checkIcon = null;
121
148
122
	private boolean tableViewCellEditorAdequatlyUsable = false;
149
	private boolean tableViewCellEditorAdequatlyUsable = false;
Lines 312-322 Link Here
312
		}
339
		}
313
	}
340
	}
314
341
315
	class LabelProvider implements ITableLabelProvider {
342
	class LabelProvider extends StyledCellLabelProvider  {
343
		private final Styler fBoldStyler; 
344
		private final Styler fPlainStyler; 
316
		FilterTypeUtil util;
345
		FilterTypeUtil util;
346
		TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
317
347
318
		public LabelProvider() {
348
		public LabelProvider() {
319
			util = new FilterTypeUtil();
349
			util = new FilterTypeUtil();
350
			fBoldStyler= new Styler() {
351
				public void applyStyles(TextStyle textStyle) {
352
					textStyle.font= boldFont;
353
				}
354
			};
355
			fPlainStyler= new Styler() {
356
				public void applyStyles(TextStyle textStyle) {
357
					textStyle.font= plainFont;
358
				}
359
			};
360
			ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(null, null);
361
			customfilterArgumentMap.put(ui.getID(), ui);
362
			ui = new DefaultCustomFilterArgumentUI(null, null);
363
			customfilterArgumentMap.put(ui.getID(), ui);
364
		}
365
366
		ICustomFilterArgumentUI getUI(String descriptorID) {
367
			ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
368
			if (result == null)
369
				return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
370
			return result;
320
		}
371
		}
321
372
322
		String getColumnID(int index) {
373
		String getColumnID(int index) {
Lines 328-412 Link Here
328
			return copy.isUnderAGroupFilter();
379
			return copy.isUnderAGroupFilter();
329
		}
380
		}
330
381
331
		public Image getColumnImage(Object element, int columnIndex) {
382
		public void update(ViewerCell cell) {
332
			if (!isPartialFilter(element)) {
383
			FilterCopy filter = (FilterCopy) cell.getElement();
333
				if (getColumnID(columnIndex).equals(FilterTypeUtil.ARGUMENTS)) {
384
			
334
					Object index = FilterTypeUtil.getValue(
385
			int columnIndex = cell.getColumnIndex();
335
							(FilterCopy) element, FilterTypeUtil.TARGET);
336
					return util.getImage(FilterTypeUtil.TARGET,
337
							((Integer) index).intValue());
338
				}
339
				if (getColumnID(columnIndex).equals(FilterTypeUtil.MODE)) {
340
					Object index = FilterTypeUtil.getValue(
341
							(FilterCopy) element, FilterTypeUtil.MODE);
342
					return util.getImage(FilterTypeUtil.MODE, ((Integer) index)
343
							.intValue());
344
				}
345
				if (getColumnID(columnIndex).equals(FilterTypeUtil.INHERITABLE)) {
346
					Object condition = FilterTypeUtil.getValue(
347
							(FilterCopy) element, FilterTypeUtil.INHERITABLE);
348
					if (((Boolean) condition).booleanValue())
349
						return checkIcon;
350
				}
351
			}
352
			return null;
353
		}
354
355
		public String getColumnText(Object element, int columnIndex) {
356
			FilterCopy filter = ((FilterCopy) element);
357
			String column = getColumnID(columnIndex);
386
			String column = getColumnID(columnIndex);
358
			return getValue(filter, column);
359
		}
360
387
361
		private String getValue(FilterCopy filter, String column) {
362
			if (column.equals(FilterTypeUtil.ID)) {
388
			if (column.equals(FilterTypeUtil.ID)) {
363
				String id = filter.getId();
389
				String id = filter.getId();
364
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
390
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
365
				if (descriptor != null)
391
				if (descriptor != null)
366
					return descriptor.getName();
392
					cell.setText(descriptor.getName());
367
			}
393
			}
368
			if (column.equals(FilterTypeUtil.MODE)) {
394
			if (column.equals(FilterTypeUtil.MODE)) {
369
				if (!isPartialFilter(filter)) {
395
				if (!isPartialFilter(filter)) {
370
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
396
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
371
						return NLS
397
						cell.setText(NLS
372
								.bind(
398
								.bind(
373
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
399
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
374
										null);
400
										null));
375
					return NLS
401
					else
402
						cell.setText(NLS
376
							.bind(
403
							.bind(
377
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
404
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
378
									null);
405
									null));
379
				}
406
				}
380
				return getFilterTypeName(filter);
407
				else
408
					cell.setText(getFilterTypeName(filter));
381
			}
409
			}
382
			if (column.equals(FilterTypeUtil.TARGET)) {
410
			if (column.equals(FilterTypeUtil.TARGET)) {
383
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
411
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
384
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
412
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
385
				if (includeFiles && includeFolders)
413
				if (includeFiles && includeFolders)
386
					return NLS
414
					cell.setText(NLS
387
							.bind(
415
							.bind(
388
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
416
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
389
									null);
417
									null));
418
				else
390
				if (includeFiles)
419
				if (includeFiles)
391
					return NLS
420
					cell.setText(NLS
392
							.bind(
421
							.bind(
393
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
422
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
394
									null);
423
									null));
424
				else
395
				if (includeFolders)
425
				if (includeFolders)
396
					return NLS
426
					cell.setText(NLS
397
							.bind(
427
							.bind(
398
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
428
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
399
									null);
429
									null));
400
			}
430
			}
401
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
431
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
402
				if (filter.hasStringArguments())
432
				StyledString styledString = getStyleColumnText(filter);
403
					return filter.getArguments() != null ? filter
433
				cell.setText(styledString.toString());
404
							.getArguments().toString() : ""; //$NON-NLS-1$
434
				cell.setStyleRanges(styledString.getStyleRanges());
405
				if ((filter.getChildrenLimit() > 0)
406
						&& !filter.isUnderAGroupFilter())
407
					return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$
408
			}
435
			}
409
			return null;
436
437
			if (!isPartialFilter(filter)) {
438
				if (column.equals(FilterTypeUtil.ARGUMENTS)) {
439
					Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET);
440
					cell.setImage(util.getImage(FilterTypeUtil.TARGET,
441
							((Integer) index).intValue()));
442
				}
443
				if (column.equals(FilterTypeUtil.MODE)) {
444
					Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.MODE);
445
					cell.setImage(util.getImage(FilterTypeUtil.MODE, ((Integer) index)
446
							.intValue()));
447
				}
448
				if (column.equals(FilterTypeUtil.INHERITABLE)) {
449
					Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
450
					if (((Boolean) condition).booleanValue())
451
						cell.setImage(checkIcon);
452
				}
453
			}
454
455
			super.update(cell);
456
		}
457
		
458
		private StyledString getStyleColumnText(FilterCopy filter) {
459
			if (filter.getChildrenLimit() > 0) {
460
				String whiteSpace = " "; //$NON-NLS-1$;
461
				String expression = getFilterTypeName(filter);
462
				boolean isUnaryOperator = filter.getId().equals("org.eclipse.ui.ide.notFilterMatcher"); //$NON-NLS-1$
463
				StyledString buffer = new StyledString();
464
				if (isUnaryOperator) {
465
					buffer.append("NOT ", fBoldStyler); //$NON-NLS-1$
466
					expression = "OR"; //$NON-NLS-1$
467
				}
468
				buffer.append("(", fBoldStyler); //$NON-NLS-1$
469
				FilterCopy[] children = filter.getChildren();
470
				for (int i = 0; i < children.length; i++) {
471
					buffer.append(getStyleColumnText(children[i]));
472
					if ((i + 1) < children.length) {
473
						buffer.append(whiteSpace, fPlainStyler);
474
						buffer.append(expression, fBoldStyler);
475
						buffer.append(whiteSpace, fPlainStyler);
476
					}
477
				}
478
				if (children.length == 0 && !isUnaryOperator)
479
					buffer.append(expression, fBoldStyler);
480
				buffer.append(")", fBoldStyler); //$NON-NLS-1$
481
				return buffer;
482
			} 
483
			ICustomFilterArgumentUI ui = getUI(filter.getId());
484
			return ui.formatStyledText(filter, fPlainStyler, fBoldStyler);
485
		}
486
487
		protected void measure(Event event, Object element) {
488
			super.measure(event, element);
410
		}
489
		}
411
490
412
		private String getFilterTypeName(FilterCopy filter) {
491
		private String getFilterTypeName(FilterCopy filter) {
Lines 416-436 Link Here
416
				return desc.getName();
495
				return desc.getName();
417
			return ""; //$NON-NLS-1$
496
			return ""; //$NON-NLS-1$
418
		}
497
		}
419
420
		public void addListener(ILabelProviderListener listener) {
421
		}
422
423
		public void dispose() {
424
		}
425
426
		public boolean isLabelProperty(Object element, String property) {
427
			return false;
428
		}
429
430
		public void removeListener(ILabelProviderListener listener) {
431
		}
432
	}
498
	}
433
499
	
434
	class CellModifier implements ICellModifier {
500
	class CellModifier implements ICellModifier {
435
		public boolean canModify(Object element, String property) {
501
		public boolean canModify(Object element, String property) {
436
			FilterCopy filter = (FilterCopy) element;
502
			FilterCopy filter = (FilterCopy) element;
Lines 506-519 Link Here
506
	}
572
	}
507
573
508
	private void createViewerGroup(Composite parent) {
574
	private void createViewerGroup(Composite parent) {
509
		filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
575
		Composite tableComposite = new Composite(parent, SWT.NONE);
510
				| SWT.H_SCROLL);
511
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
576
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
512
		data.grabExcessHorizontalSpace = true;
577
		data.grabExcessHorizontalSpace = true;
513
		data.grabExcessVerticalSpace = true;
578
		data.grabExcessVerticalSpace = true;
579
		tableComposite.setLayoutData(data);
580
581
		filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER
582
				| SWT.H_SCROLL);
583
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
584
		data.grabExcessHorizontalSpace = true;
585
		data.grabExcessVerticalSpace = true;
514
		filterView.getTree().setLayoutData(data);
586
		filterView.getTree().setLayoutData(data);
515
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
587
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
516
588
589
		plainFont = filterView.getTree().getFont();
590
		FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD);
591
		boldFont = new Font(Display.getCurrent(), boldFontData);
592
517
		filterView.setContentProvider(new TreeContentProvider());
593
		filterView.setContentProvider(new TreeContentProvider());
518
		filterView.setInput(filters);
594
		filterView.setInput(filters);
519
		filterView.getTree().setFont(parent.getFont());
595
		filterView.getTree().setFont(parent.getFont());
Lines 524-560 Link Here
524
			}
600
			}
525
		});
601
		});
526
602
527
		TreeColumn column = new TreeColumn(filterView.getTree(), 0);
603
		TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0);
528
		column
604
		modeColumn
529
				.setText(NLS
605
				.setText(NLS
530
						.bind(
606
						.bind(
531
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
607
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
532
								null));
608
								null));
533
		column.setData(FilterTypeUtil.MODE);
609
		modeColumn.setData(FilterTypeUtil.MODE);
534
		column.setResizable(true);
610
		modeColumn.setResizable(true);
535
		column.setMoveable(false);
611
		modeColumn.setMoveable(false);
536
		column.setWidth(getMinimumColumnWidth(column, 130));
612
		//column.setWidth(getMinimumColumnWidth(column, 130));
537
613
538
		column = new TreeColumn(filterView.getTree(), 0);
614
		TreeColumn argumentColumn = new TreeColumn(filterView.getTree(), 0);
539
		column.setText(NLS.bind(
615
		argumentColumn.setText(NLS.bind(
540
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
616
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
541
				null));
617
				null));
542
		column.setData(FilterTypeUtil.ARGUMENTS);
618
		argumentColumn.setData(FilterTypeUtil.ARGUMENTS);
543
		column.setResizable(true);
619
		argumentColumn.setResizable(true);
544
		column.setMoveable(true);
620
		argumentColumn.setMoveable(true);
545
		column.setWidth(getMinimumColumnWidth(column, 120));
621
	//	column.setWidth(getMinimumColumnWidth(column, 240));
546
622
547
		column = new TreeColumn(filterView.getTree(), 0);
623
		TreeColumn inheritableColumn = new TreeColumn(filterView.getTree(), 0);
548
		column
624
		inheritableColumn
549
				.setText(NLS
625
				.setText(NLS
550
						.bind(
626
						.bind(
551
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
627
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
552
								null));
628
								null));
553
		column.setData(FilterTypeUtil.INHERITABLE);
629
		inheritableColumn.setData(FilterTypeUtil.INHERITABLE);
554
		column.setResizable(true);
630
		inheritableColumn.setResizable(true);
555
		column.setMoveable(false);
631
		inheritableColumn.setMoveable(false);
556
		column.setAlignment(SWT.CENTER);
632
		inheritableColumn.setAlignment(SWT.CENTER);
557
		column.setWidth(getMinimumColumnWidth(column, 70));
633
//		column.setWidth(getMinimumColumnWidth(column, 70));
558
634
559
		filterView.getTree().setHeaderVisible(true);
635
		filterView.getTree().setHeaderVisible(true);
560
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
636
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
Lines 598-616 Link Here
598
			public void menuDetected(MenuDetectEvent e) {
674
			public void menuDetected(MenuDetectEvent e) {
599
				MenuManager mgr = new MenuManager();
675
				MenuManager mgr = new MenuManager();
600
				mgr.add(addSubFilterAction);
676
				mgr.add(addSubFilterAction);
677
				mgr.add(addSubGroupFilterAction);
678
				mgr.add(new Separator());
679
				mgr.add(new EditFilterAction());
680
				mgr.add(new RemoveFilterAction());
601
				filterView.getControl().setMenu(
681
				filterView.getControl().setMenu(
602
						mgr.createContextMenu(filterView.getControl()));
682
						mgr.createContextMenu(filterView.getControl()));
603
			}
683
			}
604
		});
684
		});
685
		TreeColumnLayout layout = new TreeColumnLayout();
686
		tableComposite.setLayout( layout );
687
		// 4
688
		layout.setColumnData( modeColumn, new ColumnWeightData( 130 ) );
689
		layout.setColumnData( argumentColumn, new ColumnWeightData( 400) );
690
		layout.setColumnData( inheritableColumn, new ColumnWeightData( 70 ) );
691
692
	}
693
694
	private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
695
		FontData[] styleData = new FontData[originalData.length];
696
		for (int i = 0; i < styleData.length; i++) {
697
			FontData base = originalData[i];
698
			styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle);
699
		}
700
       	return styleData;
701
    }
702
703
	class EditFilterAction extends Action {
704
705
		public EditFilterAction() {
706
			setText(NLS
707
					.bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel,
708
							null));
709
		}
710
711
		public void run() {
712
			handleEdit();
713
		}
714
		public boolean isEnabled() {
715
			ISelection selection = filterView.getSelection();
716
			if (selection instanceof IStructuredSelection) {
717
				return ((IStructuredSelection) selection).size() > 0;			}
718
			return false;
719
		}
720
	}
721
722
	class RemoveFilterAction extends Action {
723
724
		public RemoveFilterAction() {
725
			setText(NLS
726
					.bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel,
727
							null));
728
		}
729
730
		public void run() {
731
			handleRemove();
732
		}
733
		public boolean isEnabled() {
734
			ISelection selection = filterView.getSelection();
735
			if (selection instanceof IStructuredSelection) {
736
				return ((IStructuredSelection) selection).size() > 0;			}
737
			return false;
738
		}
605
	}
739
	}
606
740
607
	Action addSubFilterAction = new AddSubFilterAction();
741
	Action addSubFilterAction = new AddSubFilterAction(false);
608
742
609
	class AddSubFilterAction extends Action {
743
	class AddSubFilterAction extends Action {
610
744
611
		public AddSubFilterAction() {
745
		boolean createGroupOnly;
746
		
747
		public AddSubFilterAction(boolean createGroupOnly) {
748
			this.createGroupOnly = createGroupOnly;
612
			setText(NLS
749
			setText(NLS
613
					.bind(
750
					.bind(createGroupOnly ?
751
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel:
614
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
752
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
615
							null));
753
							null));
616
		}
754
		}
Lines 629-635 Link Here
629
					FilterCopy newFilter = new FilterCopy();
767
					FilterCopy newFilter = new FilterCopy();
630
					newFilter.setParent(filter);
768
					newFilter.setParent(filter);
631
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
769
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
632
							newFilter);
770
							newFilter, createGroupOnly);
633
					if (dialog.open() == Window.OK) {
771
					if (dialog.open() == Window.OK) {
634
						filter.addChild(newFilter);
772
						filter.addChild(newFilter);
635
						filterView.refresh();
773
						filterView.refresh();
Lines 654-659 Link Here
654
		}
792
		}
655
	}
793
	}
656
794
795
	Action addSubGroupFilterAction = new AddSubFilterAction(true);
796
657
	class FilterCopyDrop extends ViewerDropAdapter {
797
	class FilterCopyDrop extends ViewerDropAdapter {
658
		protected FilterCopyDrop(Viewer viewer) {
798
		protected FilterCopyDrop(Viewer viewer) {
659
			super(viewer);
799
			super(viewer);
Lines 749-768 Link Here
749
		}
889
		}
750
	}
890
	}
751
891
752
	private static int getMinimumColumnWidth(TreeColumn column, int hint) {
753
		Assert.isNotNull(column);
754
		FontMetrics fontMetrics;
755
		GC gc = new GC(column.getParent());
756
		try {
757
			gc.setFont(column.getParent().getFont());
758
			fontMetrics = gc.getFontMetrics();
759
		} finally {
760
			gc.dispose();
761
		}
762
		return Math.max(hint, fontMetrics.getAverageCharWidth()
763
				* column.getText().length());
764
	}
765
766
	private void createButtonGroup(Composite parent) {
892
	private void createButtonGroup(Composite parent) {
767
		Composite composite = new Composite(parent, SWT.NONE);
893
		Composite composite = new Composite(parent, SWT.NONE);
768
		GridLayout layout = new GridLayout();
894
		GridLayout layout = new GridLayout();
Lines 780-793 Link Here
780
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
906
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
781
		addButton.setLayoutData(data);
907
		addButton.setLayoutData(data);
782
		setButtonDimensionHint(addButton);
908
		setButtonDimensionHint(addButton);
783
		addButton.addSelectionListener(new SelectionListener() {
909
		addButton.addSelectionListener(new SelectionAdapter() {
784
			public void widgetDefaultSelected(SelectionEvent e) {
910
			public void widgetSelected(SelectionEvent e) {
911
				handleAdd(false);
785
			}
912
			}
786
913
		});
914
		
915
		addGroupButton = new Button(composite, SWT.PUSH);
916
		addGroupButton.setText(NLS.bind(
917
				IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null));
918
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
919
		addGroupButton.setLayoutData(data);
920
		setButtonDimensionHint(addGroupButton);
921
		addGroupButton.addSelectionListener(new SelectionAdapter() {
787
			public void widgetSelected(SelectionEvent e) {
922
			public void widgetSelected(SelectionEvent e) {
788
				handleAdd();
923
				handleAdd(true);
789
			}
924
			}
790
		});
925
		});
926
		
791
927
792
		editButton = new Button(composite, SWT.PUSH);
928
		editButton = new Button(composite, SWT.PUSH);
793
		editButton.setText(NLS.bind(
929
		editButton.setText(NLS.bind(
Lines 795-804 Link Here
795
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
931
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
796
		editButton.setLayoutData(data);
932
		editButton.setLayoutData(data);
797
		setButtonDimensionHint(editButton);
933
		setButtonDimensionHint(editButton);
798
		editButton.addSelectionListener(new SelectionListener() {
934
		editButton.addSelectionListener(new SelectionAdapter() {
799
			public void widgetDefaultSelected(SelectionEvent e) {
800
			}
801
802
			public void widgetSelected(SelectionEvent e) {
935
			public void widgetSelected(SelectionEvent e) {
803
				handleEdit();
936
				handleEdit();
804
			}
937
			}
Lines 813-822 Link Here
813
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
946
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
814
		removeButton.setLayoutData(data);
947
		removeButton.setLayoutData(data);
815
		setButtonDimensionHint(removeButton);
948
		setButtonDimensionHint(removeButton);
816
		removeButton.addSelectionListener(new SelectionListener() {
949
		removeButton.addSelectionListener(new SelectionAdapter() {
817
			public void widgetDefaultSelected(SelectionEvent e) {
818
			}
819
820
			public void widgetSelected(SelectionEvent e) {
950
			public void widgetSelected(SelectionEvent e) {
821
				handleRemove();
951
				handleRemove();
822
			}
952
			}
Lines 832-841 Link Here
832
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
962
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
833
			upButton.setLayoutData(data);
963
			upButton.setLayoutData(data);
834
			setButtonDimensionHint(upButton);
964
			setButtonDimensionHint(upButton);
835
			upButton.addSelectionListener(new SelectionListener() {
965
			upButton.addSelectionListener(new SelectionAdapter() {
836
				public void widgetDefaultSelected(SelectionEvent e) {
837
				}
838
839
				public void widgetSelected(SelectionEvent e) {
966
				public void widgetSelected(SelectionEvent e) {
840
					handleUp();
967
					handleUp();
841
				}
968
				}
Lines 848-857 Link Here
848
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
975
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
849
			downButton.setLayoutData(data);
976
			downButton.setLayoutData(data);
850
			setButtonDimensionHint(downButton);
977
			setButtonDimensionHint(downButton);
851
			downButton.addSelectionListener(new SelectionListener() {
978
			downButton.addSelectionListener(new SelectionAdapter() {
852
				public void widgetDefaultSelected(SelectionEvent e) {
853
				}
854
855
				public void widgetSelected(SelectionEvent e) {
979
				public void widgetSelected(SelectionEvent e) {
856
					handleDown();
980
					handleDown();
857
				}
981
				}
Lines 887-895 Link Here
887
		return filters.isLast((FilterCopy) o);
1011
		return filters.isLast((FilterCopy) o);
888
	}
1012
	}
889
1013
890
	private void handleAdd() {
1014
	private void handleAdd(boolean createGroupOnly) {
891
		FilterCopy newFilter = new FilterCopy();
1015
		FilterCopy newFilter = new FilterCopy();
892
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter);
1016
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter, createGroupOnly);
893
		if (dialog.open() == Window.OK) {
1017
		if (dialog.open() == Window.OK) {
894
			filters.add(newFilter);
1018
			filters.add(newFilter);
895
			filterView.refresh();
1019
			filterView.refresh();
Lines 903-909 Link Here
903
					.getFirstElement();
1027
					.getFirstElement();
904
			FilterCopy copy = new FilterCopy(filter);
1028
			FilterCopy copy = new FilterCopy(filter);
905
			copy.setParent(filter.getParent());
1029
			copy.setParent(filter.getParent());
906
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy);
1030
			boolean isGroup = filter.getChildrenLimit() > 0;
1031
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy, isGroup);
907
			if (dialog.open() == Window.OK) {
1032
			if (dialog.open() == Window.OK) {
908
				if (copy.hasChanged()) {
1033
				if (copy.hasChanged()) {
909
					filter.copy(copy);
1034
					filter.copy(copy);
Lines 1263-1286 Link Here
1263
								null) };
1388
								null) };
1264
	}
1389
	}
1265
1390
1266
	static String[] getFilterNames(boolean childrenOnly) {
1391
	static String[] getFilterNames(boolean groupOnly) {
1267
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1392
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1268
				.getFilterMatcherDescriptors();
1393
				.getFilterMatcherDescriptors();
1394
		sortDescriptors(descriptors);
1269
		LinkedList names = new LinkedList();
1395
		LinkedList names = new LinkedList();
1270
		for (int i = 0; i < descriptors.length; i++) {
1396
		for (int i = 0; i < descriptors.length; i++) {
1271
			if (!childrenOnly
1397
			boolean isGroup = descriptors[i].getArgumentType().equals(
1272
					|| descriptors[i].getArgumentType().equals(
1398
					IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1273
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1274
					|| descriptors[i].getArgumentType().equals(
1399
					|| descriptors[i].getArgumentType().equals(
1275
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS))
1400
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS);
1401
			if (isGroup == groupOnly) 
1276
				names.add(descriptors[i].getName());
1402
				names.add(descriptors[i].getName());
1277
		}
1403
		}
1278
		return (String[]) names.toArray(new String[0]);
1404
		return (String[]) names.toArray(new String[0]);
1279
	}
1405
	}
1280
1406
1407
	/**
1408
	 * @param descriptors
1409
	 */
1410
	private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) {
1411
		Arrays.sort(descriptors, new Comparator() {
1412
			public int compare(Object arg0, Object arg1) {
1413
				if (((IFilterMatcherDescriptor) arg0).getId().equals(MultiMatcher.ID))
1414
					return -1;
1415
				if (((IFilterMatcherDescriptor) arg1).getId().equals(MultiMatcher.ID))
1416
					return 1;
1417
				return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId());
1418
			}
1419
		});
1420
	}
1421
1281
	static String getDefaultFilterID() {
1422
	static String getDefaultFilterID() {
1282
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1423
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1283
				.getFilterMatcherDescriptors();
1424
				.getFilterMatcherDescriptors();
1425
		sortDescriptors(descriptors);
1284
		for (int i = 0; i < descriptors.length; i++) {
1426
		for (int i = 0; i < descriptors.length; i++) {
1285
			if (descriptors[i].getArgumentType().equals(
1427
			if (descriptors[i].getArgumentType().equals(
1286
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
1428
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
Lines 1669-1700 Link Here
1669
	protected Button foldersButton;
1811
	protected Button foldersButton;
1670
	protected Button filesAndFoldersButton;
1812
	protected Button filesAndFoldersButton;
1671
	protected Combo idCombo;
1813
	protected Combo idCombo;
1814
	protected Composite idComposite;
1815
	protected Composite argumentComposite;
1672
	protected Button inherited;
1816
	protected Button inherited;
1673
	protected Text arguments;
1674
	protected Label argumentsLabel;
1675
	protected Label description;
1676
	protected FilterTypeUtil util;
1817
	protected FilterTypeUtil util;
1818
	protected boolean createGroupOnly;
1677
	protected IResource resource;
1819
	protected IResource resource;
1678
1820
1679
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$
1821
	TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
1680
	
1822
	ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() {
1681
	/**
1823
		public Object getID() {return "dummy";} //$NON-NLS-1$
1682
	 * Find and replace command adapters.
1824
		public void create(Composite argumentComposite, Font font) {}
1683
	 * @since 3.3
1825
		public void dispose() {}
1684
	 */
1826
		public void selectionChanged() {}
1685
	private ContentAssistCommandAdapter fContentAssistField;
1827
		public void validate() {}
1828
		public StyledString formatStyledText(FilterCopy filter,
1829
				Styler fPlainStyler, Styler fBoldStyler) {return null;}
1830
	};
1686
1831
1687
	/**
1832
	/**
1688
	 * Constructor for FilterEditDialog.
1833
	 * Constructor for FilterEditDialog.
1689
	 * 
1834
	 * 
1690
	 * @param parentShell
1835
	 * @param parentShell
1691
	 * @param filter
1836
	 * @param filter
1837
	 * @param createGroupOnly 
1692
	 */
1838
	 */
1693
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) {
1839
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter, boolean createGroupOnly) {
1694
		super(parentShell);
1840
		super(parentShell);
1695
		this.resource = resource;
1841
		this.resource = resource;
1696
		this.filter = filter;
1842
		this.filter = filter;
1843
		this.createGroupOnly = createGroupOnly;
1697
		util = new FilterTypeUtil();
1844
		util = new FilterTypeUtil();
1845
		ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter);
1846
		customfilterArgumentMap.put(ui.getID(), ui);
1847
		ui = new DefaultCustomFilterArgumentUI(parentShell, filter);
1848
		customfilterArgumentMap.put(ui.getID(), ui);
1698
	}
1849
	}
1699
1850
1700
	/*
1851
	/*
Lines 1728-1734 Link Here
1728
		if (!filter.isUnderAGroupFilter()) {
1879
		if (!filter.isUnderAGroupFilter()) {
1729
			Composite topComposite = new Composite(composite, SWT.NONE);
1880
			Composite topComposite = new Composite(composite, SWT.NONE);
1730
			layout = new GridLayout();
1881
			layout = new GridLayout();
1731
			layout.numColumns = 2;
1882
			layout.numColumns = 1;
1732
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1883
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1733
			layout.marginWidth = 0;
1884
			layout.marginWidth = 0;
1734
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1885
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
Lines 1739-1748 Link Here
1739
			topComposite.setFont(font);
1890
			topComposite.setFont(font);
1740
1891
1741
			createModeArea(font, topComposite);
1892
			createModeArea(font, topComposite);
1893
			createIdArea(font, topComposite);
1742
			createTargetArea(font, topComposite);
1894
			createTargetArea(font, topComposite);
1895
			createInheritableArea(font, topComposite);
1896
		}
1897
		else
1898
			createIdArea(font, composite);
1899
1900
		Label label = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL);
1901
		data = new GridData(SWT.FILL, SWT.TOP, true, false);
1902
		label.setLayoutData(data);
1903
		return composite;
1904
	}
1905
1906
	/* (non-Javadoc)
1907
	 * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
1908
	 */
1909
	protected Control createButtonBar(Composite parent) {
1910
    	Composite composite = new Composite(parent, SWT.NONE);
1911
    	GridLayout layout = new GridLayout();
1912
    	layout.marginWidth = 0;
1913
    	layout.marginHeight = 0;
1914
    	layout.horizontalSpacing = 0;
1915
    	composite.setLayout(layout);
1916
    	composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1917
    	composite.setFont(parent.getFont());
1918
1919
		// create help control if needed
1920
        if (isHelpAvailable()) {
1921
        	Control helpControl = createHelpControl(composite);
1922
        	((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1923
		}
1924
        if (!createGroupOnly) {
1925
    		((GridLayout) composite.getLayout()).numColumns++;
1926
	        Button customizeButton = new Button(composite, SWT.PUSH);
1927
	        customizeButton.setText(NLS.bind(
1928
					IDEWorkbenchMessages.ResourceFilterPage_customize,
1929
					null));
1930
	        customizeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1931
	        customizeButton.addSelectionListener(new SelectionAdapter() {
1932
				public void widgetSelected(SelectionEvent e) {
1933
					selectOtherFilterMatcher();
1934
				}
1935
	        });
1936
        }
1937
        
1938
        Control buttonSection = dialogCreateButtonBar(composite);
1939
        ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
1940
        return composite;
1941
	}
1942
1943
	private void selectOtherFilterMatcher() {
1944
		ListDialog dlg =
1945
			   new ListDialog(getShell());
1946
		dlg.setAddCancelButton(true);
1947
		dlg.setInput(Arrays.asList(FilterTypeUtil.getFilterNames(createGroupOnly)));
1948
		dlg.setInitialElementSelections(Arrays.asList(new String[] {FilterTypeUtil.getDescriptor(filter.getId()).getName()}));
1949
		dlg.setContentProvider(new IStructuredContentProvider() {
1950
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
1951
			public void dispose() {}
1952
			public Object[] getElements(Object inputElement) {
1953
				if (inputElement instanceof List)
1954
					return ((List) inputElement).toArray();
1955
				return null;
1956
			}
1957
		});
1958
		dlg.setLabelProvider(new org.eclipse.jface.viewers.LabelProvider());
1959
		dlg.setTitle(NLS.bind(
1960
				IDEWorkbenchMessages.ResourceFilterPage_customizeTitle,
1961
				null));
1962
		dlg.setMessage(NLS.bind(
1963
					IDEWorkbenchMessages.ResourceFilterPage_customizeMessage,
1964
					null));
1965
		if (dlg.open() == Window.OK) {
1966
			Object[] result = dlg.getResult();
1967
			if (result.length > 0) {
1968
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, result[0]);
1969
				if (filter.hasStringArguments())
1970
					filter.setArguments(new String());
1971
				setupPatternLine();
1972
				currentCustomFilterArgumentUI.selectionChanged();
1973
			}
1743
		}
1974
		}
1744
		createIdArea(font, composite);
1975
	}
1745
1976
1977
	private Control dialogCreateButtonBar(Composite parent) {
1978
		Composite composite = new Composite(parent, SWT.NONE);
1979
		// create a layout with spacing and margins appropriate for the font
1980
		// size.
1981
		GridLayout layout = new GridLayout();
1982
		layout.numColumns = 0; // this is incremented by createButton
1983
		layout.makeColumnsEqualWidth = true;
1984
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1985
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1986
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1987
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1988
		composite.setLayout(layout);
1989
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END
1990
				| GridData.VERTICAL_ALIGN_CENTER);
1991
		composite.setLayoutData(data);
1992
		composite.setFont(parent.getFont());
1993
		
1994
		// Add the buttons to the button bar.
1995
		createButtonsForButtonBar(composite);
1746
		return composite;
1996
		return composite;
1747
	}
1997
	}
1748
1998
Lines 1751-1772 Link Here
1751
	 * @param composite
2001
	 * @param composite
1752
	 */
2002
	 */
1753
	private void createInheritableArea(Font font, Composite composite) {
2003
	private void createInheritableArea(Font font, Composite composite) {
2004
		Composite inheritableComposite = createGroup(font, composite, NLS.bind(
2005
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2006
				null), false, false, 1);
2007
1754
		GridData data;
2008
		GridData data;
1755
		inherited = new Button(composite, SWT.CHECK);
2009
		inherited = new Button(inheritableComposite, SWT.CHECK);
1756
		inherited
2010
		inherited
1757
				.setText(NLS
2011
				.setText(NLS
1758
						.bind(
2012
						.bind(
1759
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
2013
								IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure,
1760
								null));
2014
								null));
1761
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
2015
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
1762
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2016
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1763
		data.horizontalSpan = 1;
2017
		data.horizontalSpan = 1;
1764
		inherited.setLayoutData(data);
2018
		inherited.setLayoutData(data);
1765
		inherited.setFont(font);
2019
		inherited.setFont(font);
1766
		inherited.addSelectionListener(new SelectionListener() {
2020
		inherited.addSelectionListener(new SelectionAdapter() {
1767
			public void widgetDefaultSelected(SelectionEvent e) {
1768
			}
1769
1770
			public void widgetSelected(SelectionEvent e) {
2021
			public void widgetSelected(SelectionEvent e) {
1771
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
2022
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1772
						new Boolean(inherited.getSelection()));
2023
						new Boolean(inherited.getSelection()));
Lines 1780-1884 Link Here
1780
	 * @param font
2031
	 * @param font
1781
	 * @param composite
2032
	 * @param composite
1782
	 */
2033
	 */
1783
	private void createArgumentsArea(Font font, Composite composite) {
2034
	private void createIdArea(Font font, Composite composite) {
1784
		GridData data;
2035
		GridData data;
1785
		argumentsLabel = addLabel(composite, NLS.bind(
2036
		if (createGroupOnly) {
1786
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
2037
			idComposite = createGroup(font, composite, new String(),
1787
				null));
2038
					true, true, 1);
1788
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
2039
			idCombo = new Combo(idComposite, SWT.READ_ONLY);
1789
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2040
			idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly));
1790
		arguments.setLayoutData(data);
2041
			data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1791
		arguments.setFont(font);
2042
			idCombo.setLayoutData(data);
1792
		arguments.addModifyListener(new ModifyListener() {
2043
			idCombo.setFont(font);
1793
			public void modifyText(ModifyEvent e) {
2044
			idCombo.addSelectionListener(new SelectionAdapter() {
1794
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
2045
				public void widgetSelected(SelectionEvent e) {
1795
						arguments.getText());
2046
					FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1796
			}
2047
							.getItem(idCombo.getSelectionIndex()));
1797
		});
2048
					if (filter.hasStringArguments())
1798
		if (filter.hasStringArguments())
2049
						filter.setArguments(new String());
1799
			arguments.setText((String) FilterTypeUtil.getValue(filter,
2050
					setupPatternLine();
1800
					FilterTypeUtil.ARGUMENTS));
2051
					currentCustomFilterArgumentUI.selectionChanged();
1801
		arguments.setEnabled(filter.hasStringArguments());
2052
				}
1802
		setArgumentLabelEnabled();
2053
			});
1803
2054
			idCombo.select(0);
1804
		TextContentAdapter contentAdapter= new TextContentAdapter();
2055
			selectComboItem(filter.getId());
1805
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2056
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1806
		fContentAssistField= new ContentAssistCommandAdapter(
2057
					.getItem(idCombo.getSelectionIndex()));
1807
				arguments,
2058
		}
1808
				contentAdapter,
2059
		else {
1809
				findProposer, 
2060
			idComposite = createGroup(font, composite, new String(),
1810
				null,
2061
					true, true, 1);
1811
				new char[] {'\\', '[', '('},
2062
		}
1812
				true);
2063
		argumentComposite = new Composite(idComposite, SWT.NONE);
1813
	}
2064
		setupPatternLine();
1814
1815
	/**
1816
	 * 
1817
	 */
1818
	private void setArgumentLabelEnabled() {
1819
		Color color = argumentsLabel.getDisplay().getSystemColor(
1820
				filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
1821
		argumentsLabel.setForeground(color);
1822
	}
2065
	}
2066
	
1823
2067
1824
	/**
2068
	ICustomFilterArgumentUI getUI(String descriptorID) {
1825
	 * @param font
2069
		ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
1826
	 * @param composite
2070
		if (result == null)
1827
	 */
2071
			return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
1828
	private void createDescriptionArea(Font font, Composite composite) {
2072
		return result;
1829
		GridData data;
1830
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
1831
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
1832
				.getDescription());
1833
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
1834
		data.widthHint = 300;
1835
		data.heightHint = 40;
1836
		description.setLayoutData(data);
1837
		description.setFont(font);
1838
	}
2073
	}
1839
2074
	
1840
	/**
2075
	private void setupPatternLine() {
1841
	 * @param font
2076
		IFilterMatcherDescriptor descriptor;
1842
	 * @param composite
2077
		if (createGroupOnly) {
1843
	 */
2078
			String item = idCombo.getItem(idCombo.getSelectionIndex());
1844
	private void createIdArea(Font font, Composite composite) {
2079
			descriptor = FilterTypeUtil.getDescriptorByName(item);
1845
		GridData data;
2080
		}
1846
		Group idComposite = createGroup(font, composite, NLS.bind(
2081
		else
1847
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null),
2082
			descriptor = FilterTypeUtil.getDescriptor(filter.getId());
1848
				true);
2083
		Font font = idComposite.getFont();
1849
		idCombo = new Combo(idComposite, SWT.READ_ONLY);
2084
		ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId());
1850
		idCombo.setItems(FilterTypeUtil.getFilterNames(filter
2085
		if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) {
1851
				.getChildrenLimit() > 0));
2086
			currentCustomFilterArgumentUI.dispose();
1852
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2087
			currentCustomFilterArgumentUI = customFilterArgumentUI;
1853
		idCombo.setLayoutData(data);
2088
			currentCustomFilterArgumentUI.create(argumentComposite, font);
1854
		idCombo.setFont(font);
2089
			getShell().layout(true);
1855
		idCombo.addSelectionListener(new SelectionListener() {
2090
			getShell().redraw();
1856
			public void widgetDefaultSelected(SelectionEvent e) {
2091
		}
1857
			}
1858
1859
			public void widgetSelected(SelectionEvent e) {
1860
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1861
						.getItem(idCombo.getSelectionIndex()));
1862
				arguments.setEnabled(filter.hasStringArguments());
1863
				setArgumentLabelEnabled();
1864
				description.setText(FilterTypeUtil
1865
						.getDescriptor(filter.getId()).getDescription());
1866
				fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
1867
			}
1868
		});
1869
		selectComboItem(filter.getId());
1870
		Composite argumentComposite = new Composite(idComposite, SWT.NONE);
1871
		GridLayout layout = new GridLayout();
1872
		layout.numColumns = 2;
1873
		layout.marginWidth = 0;
1874
		argumentComposite.setLayout(layout);
1875
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
1876
		argumentComposite.setLayoutData(data);
1877
		argumentComposite.setFont(font);
1878
		createArgumentsArea(font, argumentComposite);
1879
1880
		createDescriptionArea(font, idComposite);
1881
		fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
1882
	}
2092
	}
1883
2093
1884
	/**
2094
	/**
Lines 1904-1923 Link Here
1904
	 */
2114
	 */
1905
	private void createModeArea(Font font, Composite composite) {
2115
	private void createModeArea(Font font, Composite composite) {
1906
		GridData data;
2116
		GridData data;
1907
		Group modeComposite = createGroup(font, composite, NLS.bind(
2117
		Composite modeComposite = createGroup(font, composite, new String(), false, true, 2);
1908
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
1909
				null), false);
1910
		String[] modes = FilterTypeUtil.getModes();
2118
		String[] modes = FilterTypeUtil.getModes();
1911
		includeButton = new Button(modeComposite, SWT.RADIO);
2119
		includeButton = new Button(modeComposite, SWT.RADIO);
1912
		includeButton.setText(modes[0]);
2120
		includeButton.setText(modes[0]);
1913
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
2121
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
1914
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2122
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1915
		includeButton.setLayoutData(data);
2123
		includeButton.setLayoutData(data);
1916
		includeButton.setFont(font);
2124
		includeButton.setFont(font);
1917
		includeButton.addSelectionListener(new SelectionListener() {
2125
		includeButton.addSelectionListener(new SelectionAdapter() {
1918
			public void widgetDefaultSelected(SelectionEvent e) {
1919
			}
1920
1921
			public void widgetSelected(SelectionEvent e) {
2126
			public void widgetSelected(SelectionEvent e) {
1922
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2127
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1923
						new Integer(0));
2128
						new Integer(0));
Lines 1928-1940 Link Here
1928
		excludeButton = new Button(modeComposite, SWT.RADIO);
2133
		excludeButton = new Button(modeComposite, SWT.RADIO);
1929
		excludeButton.setText(modes[1]);
2134
		excludeButton.setText(modes[1]);
1930
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
2135
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
1931
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2136
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1932
		excludeButton.setLayoutData(data);
2137
		excludeButton.setLayoutData(data);
1933
		excludeButton.setFont(font);
2138
		excludeButton.setFont(font);
1934
		excludeButton.addSelectionListener(new SelectionListener() {
2139
		excludeButton.addSelectionListener(new SelectionAdapter() {
1935
			public void widgetDefaultSelected(SelectionEvent e) {
1936
			}
1937
1938
			public void widgetSelected(SelectionEvent e) {
2140
			public void widgetSelected(SelectionEvent e) {
1939
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2141
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1940
						new Integer(1));
2142
						new Integer(1));
Lines 1942-1948 Link Here
1942
		});
2144
		});
1943
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
2145
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1944
				filter, FilterTypeUtil.MODE)).intValue() == 1);
2146
				filter, FilterTypeUtil.MODE)).intValue() == 1);
1945
		createInheritableArea(font, modeComposite);
1946
	}
2147
	}
1947
2148
1948
	/**
2149
	/**
Lines 1950-1967 Link Here
1950
	 * @param composite
2151
	 * @param composite
1951
	 * @return the group
2152
	 * @return the group
1952
	 */
2153
	 */
1953
	private Group createGroup(Font font, Composite composite, String text,
2154
	private Composite createGroup(Font font, Composite composite, String text,
1954
			boolean grabExcessVerticalSpace) {
2155
			boolean grabExcessVerticalSpace, boolean group, int columnCounts) {
1955
		GridLayout layout;
2156
		GridLayout layout;
1956
		GridData data;
2157
		GridData data;
1957
		Group modeComposite = new Group(composite, SWT.NONE);
2158
		Composite modeComposite;
1958
		modeComposite.setText(text);
2159
		if (group) { 
2160
			Group modeGroup = new Group(composite, SWT.NONE);
2161
			modeGroup.setText(text);
2162
			modeComposite = modeGroup;
2163
		} else {
2164
			modeComposite = new Composite(composite, SWT.NONE);
2165
		}
1959
		layout = new GridLayout();
2166
		layout = new GridLayout();
1960
		layout.numColumns = 1;
2167
		layout.numColumns = columnCounts;
1961
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1962
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1963
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1964
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1965
		modeComposite.setLayout(layout);
2168
		modeComposite.setLayout(layout);
1966
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
2169
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
1967
		modeComposite.setLayoutData(data);
2170
		modeComposite.setLayoutData(data);
Lines 1975-2028 Link Here
1975
	 */
2178
	 */
1976
	private void createTargetArea(Font font, Composite composite) {
2179
	private void createTargetArea(Font font, Composite composite) {
1977
		GridData data;
2180
		GridData data;
1978
		Group targetComposite = createGroup(font, composite, NLS.bind(
2181
		Composite targetComposite = createGroup(font, composite, new String(), false, true, 3);
1979
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
1980
				null), false);
1981
2182
1982
		String[] targets = FilterTypeUtil.getTargets();
2183
		String[] targets = FilterTypeUtil.getTargets();
1983
		filesButton = new Button(targetComposite, SWT.RADIO);
2184
		filesButton = new Button(targetComposite, SWT.RADIO);
1984
		filesButton.setText(targets[0]);
2185
		filesButton.setText(targets[0]);
1985
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
2186
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
1986
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2187
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1987
		filesButton.setLayoutData(data);
2188
		filesButton.setLayoutData(data);
1988
		filesButton.setFont(font);
2189
		filesButton.setFont(font);
1989
2190
1990
		foldersButton = new Button(targetComposite, SWT.RADIO);
2191
		foldersButton = new Button(targetComposite, SWT.RADIO);
1991
		foldersButton.setText(targets[1]);
2192
		foldersButton.setText(targets[1]);
1992
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
2193
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
1993
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2194
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1994
		foldersButton.setLayoutData(data);
2195
		foldersButton.setLayoutData(data);
1995
		foldersButton.setFont(font);
2196
		foldersButton.setFont(font);
1996
2197
1997
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
2198
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
1998
		filesAndFoldersButton.setText(targets[2]);
2199
		filesAndFoldersButton.setText(targets[2]);
1999
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2200
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2000
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2201
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2001
		filesAndFoldersButton.setLayoutData(data);
2202
		filesAndFoldersButton.setLayoutData(data);
2002
		filesAndFoldersButton.setFont(font);
2203
		filesAndFoldersButton.setFont(font);
2003
2204
2004
		filesButton.addSelectionListener(new SelectionListener() {
2205
		filesButton.addSelectionListener(new SelectionAdapter() {
2005
			public void widgetDefaultSelected(SelectionEvent e) {
2006
			}
2007
2008
			public void widgetSelected(SelectionEvent e) {
2206
			public void widgetSelected(SelectionEvent e) {
2009
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2207
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2010
						new Integer(0));
2208
						new Integer(0));
2011
			}
2209
			}
2012
		});
2210
		});
2013
		foldersButton.addSelectionListener(new SelectionListener() {
2211
		foldersButton.addSelectionListener(new SelectionAdapter() {
2014
			public void widgetDefaultSelected(SelectionEvent e) {
2015
			}
2016
2017
			public void widgetSelected(SelectionEvent e) {
2212
			public void widgetSelected(SelectionEvent e) {
2018
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2213
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2019
						new Integer(1));
2214
						new Integer(1));
2020
			}
2215
			}
2021
		});
2216
		});
2022
		filesAndFoldersButton.addSelectionListener(new SelectionListener() {
2217
		filesAndFoldersButton.addSelectionListener(new SelectionAdapter() {
2023
			public void widgetDefaultSelected(SelectionEvent e) {
2024
			}
2025
2026
			public void widgetSelected(SelectionEvent e) {
2218
			public void widgetSelected(SelectionEvent e) {
2027
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2219
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2028
						new Integer(2));
2220
						new Integer(2));
Lines 2036-2053 Link Here
2036
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2228
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2037
	}
2229
	}
2038
2230
2039
	Label addLabel(Composite composite, String text) {
2040
		String delimiter = ":"; //$NON-NLS-1$
2041
2042
		Font font = composite.getFont();
2043
		Label label = new Label(composite, SWT.LEFT);
2044
		label.setText(text + delimiter);
2045
		GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
2046
		label.setLayoutData(data);
2047
		label.setFont(font);
2048
		return label;
2049
	}
2050
2051
	protected Control createContents(Composite parent) {
2231
	protected Control createContents(Composite parent) {
2052
		Control control = super.createContents(parent);
2232
		Control control = super.createContents(parent);
2053
		initialize();
2233
		initialize();
Lines 2082-2089 Link Here
2082
		if (filter.hasStringArguments()) {
2262
		if (filter.hasStringArguments()) {
2083
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2263
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2084
			if (desc != null) {
2264
			if (desc != null) {
2085
				AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2086
				try {
2265
				try {
2266
					currentCustomFilterArgumentUI.validate();
2267
					AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2087
					matcher.initialize(resource.getProject(), filter.getArguments());
2268
					matcher.initialize(resource.getProject(), filter.getArguments());
2088
				} catch (CoreException e) {
2269
				} catch (CoreException e) {
2089
					IWorkbenchWindow window = PlatformUI.getWorkbench()
2270
					IWorkbenchWindow window = PlatformUI.getWorkbench()
Lines 2099-2102 Link Here
2099
2280
2100
		super.okPressed();
2281
		super.okPressed();
2101
	}
2282
	}
2283
}
2284
2285
interface ICustomFilterArgumentUI {
2286
2287
	/**
2288
	 * @return the descriptor ID
2289
	 */
2290
	Object getID();
2291
2292
	/**
2293
	 * @param filter
2294
	 * @param fPlainStyler
2295
	 * @param fBoldStyler
2296
	 * @return
2297
	 */
2298
	StyledString formatStyledText(FilterCopy filter, Styler fPlainStyler,
2299
			Styler fBoldStyler);
2300
2301
	/**
2302
	 * @throws CoreException 
2303
	 * 
2304
	 */
2305
	void validate() throws CoreException;
2306
2307
	/**
2308
	 * 
2309
	 */
2310
	void selectionChanged();
2311
2312
	/**
2313
	 * @param argumentComposite
2314
	 * @param font
2315
	 */
2316
	void create(Composite argumentComposite, Font font);
2317
2318
	/**
2319
	 * 
2320
	 */
2321
	void dispose();
2322
	
2323
}
2324
2325
class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2326
2327
	Shell shell;
2328
	FilterCopy filter;
2329
	protected Button argumentsCaseSensitive;
2330
	protected Button argumentsRegularExpresion;
2331
	protected Text arguments;
2332
	protected DateTime argumentsDate;
2333
	protected Combo argumentsBoolean;
2334
	protected Label argumentsLabel;
2335
	protected Label description;
2336
	protected ContentAssistCommandAdapter fContentAssistField;
2337
	protected Combo multiKey;
2338
	protected Combo multiOperator;
2339
	protected Composite multiArgumentComposite;
2340
	protected Composite stringArgumentComposite;
2341
	protected Composite attributeStringArgumentComposite;
2342
	protected Class intiantiatedKeyOperatorType = null;
2343
	protected TreeMap/* <String, String>*/ valueCache = new TreeMap();
2344
	
2345
	/**
2346
	 * @param parentShell
2347
	 * @param filter
2348
	 */
2349
	public MultiMatcherCustomFilterArgumentUI(Shell parentShell,
2350
			FilterCopy filter) {
2351
		this.shell = parentShell;
2352
		this.filter = filter;
2353
	}
2354
2355
	/* (non-Javadoc)
2356
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2357
	 */
2358
	public Object getID() {
2359
		return MultiMatcher.ID;
2360
	}
2361
2362
	/* (non-Javadoc)
2363
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2364
	 */
2365
	public void dispose() {
2366
		Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description};
2367
		for (int i = 0; i < list.length; i++) {
2368
			if (list[i] != null) {
2369
				list[i].dispose();
2370
			}
2371
		}
2372
		multiKey = null;
2373
		multiOperator = null;
2374
		multiArgumentComposite = null;
2375
		arguments = null;
2376
		argumentsLabel = null;
2377
		fContentAssistField = null;
2378
		intiantiatedKeyOperatorType = null;
2379
		stringArgumentComposite = null;
2380
		argumentsCaseSensitive = null;
2381
		argumentsRegularExpresion = null;
2382
		attributeStringArgumentComposite = null;
2383
		description = null;
2384
	}
2385
2386
	/* (non-Javadoc)
2387
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2388
	 */
2389
	public void create(Composite argumentComposite, Font font) {
2390
		shell = argumentComposite.getShell();
2391
		GridLayout layout = new GridLayout();
2392
		layout.numColumns = 3;
2393
		layout.marginWidth = 0;
2394
		argumentComposite.setLayout(layout);
2395
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2396
		argumentComposite.setLayoutData(data);
2397
		argumentComposite.setFont(font);
2398
		createCustomArgumentsArea(font, argumentComposite);
2399
		argumentComposite.layout(true);
2400
		createDescriptionArea(font, argumentComposite);
2401
	}
2402
	
2403
	/**
2404
	 * @param font
2405
	 * @param composite
2406
	 */
2407
	private void createDescriptionArea(Font font, Composite composite) {
2408
		GridData data;
2409
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2410
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2411
		data.widthHint = 300;
2412
		data.heightHint = 40;
2413
		data.horizontalSpan = 3;
2414
		description.setLayoutData(data);
2415
		description.setFont(font);
2416
		setupDescriptionText();
2417
	}
2418
2419
	private void setupDescriptionText() {
2420
		if (description != null) {
2421
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2422
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2423
			Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2424
			description.setText(new String());
2425
			if (selectedKeyOperatorType.equals(String.class)) {
2426
				if (!argumentsRegularExpresion.getSelection())
2427
					description.setText(NLS.bind(
2428
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null));
2429
			}
2430
			if (selectedKeyOperatorType.equals(Integer.class)) {
2431
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2432
					description.setText(NLS.bind(
2433
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_TimeInterval, null));
2434
				else
2435
				description.setText(NLS.bind(
2436
						IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null));
2437
			}
2438
		}
2439
	}
2440
	
2441
	private void createCustomArgumentsArea(Font font, Composite composite) {
2442
		GridData data;
2443
		multiKey = new Combo(composite, SWT.READ_ONLY);
2444
		multiKey.setItems(getMultiMatcherKeys());
2445
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2446
		multiKey.setLayoutData(data);
2447
		multiKey.setFont(font);
2448
		multiKey.addSelectionListener(new SelectionAdapter() {
2449
			public void widgetSelected(SelectionEvent e) {
2450
				setupMultiOperatorAndField(true);
2451
				storeMultiSelection();
2452
			}
2453
		});
2454
2455
		multiOperator = new Combo(composite, SWT.READ_ONLY);
2456
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2457
		multiOperator.setLayoutData(data);
2458
		multiOperator.setFont(font);
2459
		multiOperator.addSelectionListener(new SelectionAdapter() {
2460
			public void widgetSelected(SelectionEvent e) {
2461
				setupMultiOperatorAndField(false);
2462
				storeMultiSelection();
2463
			}
2464
		});
2465
		
2466
		multiArgumentComposite = new Composite(composite, SWT.NONE);
2467
		
2468
		GridLayout layout = new GridLayout();
2469
		layout.numColumns = 1;
2470
		layout.marginWidth = 0;
2471
		layout.horizontalSpacing = 0;
2472
		layout.verticalSpacing = 0;
2473
		layout.marginBottom = 0;
2474
		layout.marginHeight = 0;
2475
		multiArgumentComposite.setLayout(layout);
2476
		data = new GridData(SWT.FILL, SWT.TOP, true, true);
2477
		multiArgumentComposite.setLayoutData(data);
2478
		multiArgumentComposite.setFont(font);
2479
2480
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2481
		String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key);
2482
		int index = multiKey.indexOf(local);
2483
		if (index != -1)
2484
			multiKey.select(index);
2485
		else
2486
			multiKey.select(0);
2487
		
2488
		setupMultiOperatorAndField(true);
2489
	}
2490
2491
	private void setupMultiOperatorAndField(boolean updateOperator) {
2492
		boolean isUsingRegularExpression = false;
2493
		String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2494
		if (updateOperator) {
2495
			String[] operators = getLocalOperatorsForKey(selectedKey);
2496
			multiOperator.setItems(operators);
2497
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2498
			String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
2499
			int index = multiOperator.indexOf(local);
2500
			if (index != -1)
2501
				multiOperator.select(index);
2502
			else
2503
				multiOperator.select(0);
2504
		}
2505
		String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2506
		
2507
		Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2508
		
2509
		if (intiantiatedKeyOperatorType != null) {
2510
			if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType))
2511
				return;
2512
			if (arguments != null) {
2513
				arguments.dispose();
2514
				arguments = null;
2515
			}
2516
			if (attributeStringArgumentComposite != null) {
2517
				attributeStringArgumentComposite.dispose();
2518
				attributeStringArgumentComposite = null;
2519
			}
2520
			if (stringArgumentComposite != null) {
2521
				stringArgumentComposite.dispose();
2522
				stringArgumentComposite = null;
2523
			}
2524
			if (argumentsBoolean != null) {
2525
				argumentsBoolean.dispose();
2526
				argumentsBoolean = null;
2527
			}
2528
			if (argumentsDate != null) {
2529
				argumentsDate.dispose();
2530
				argumentsDate = null;
2531
			}
2532
			if (argumentsRegularExpresion != null) {
2533
				argumentsRegularExpresion.dispose();
2534
				argumentsRegularExpresion = null;
2535
			}
2536
			if (argumentsCaseSensitive != null) {
2537
				argumentsCaseSensitive.dispose();
2538
				argumentsCaseSensitive = null;
2539
			}
2540
			fContentAssistField = null;
2541
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2542
			valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern);
2543
			argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName());
2544
			if (argument.pattern == null)
2545
				argument.pattern = new String();
2546
			filter.setArguments(MultiMatcher.encodeArguments(argument));
2547
		}
2548
		if (selectedKeyOperatorType.equals(String.class)) {
2549
			stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);
2550
			
2551
			GridData data;
2552
			GridLayout layout = new GridLayout();
2553
			layout.numColumns = 2;
2554
			layout.marginWidth = 0;
2555
			layout.horizontalSpacing = 0;
2556
			layout.verticalSpacing = 0;
2557
			layout.marginBottom = 0;
2558
			layout.marginHeight = 0;
2559
			stringArgumentComposite.setLayout(layout);
2560
			data = new GridData(SWT.FILL, SWT.TOP, true, true);
2561
			stringArgumentComposite.setLayoutData(data);
2562
			stringArgumentComposite.setFont(multiArgumentComposite.getFont());
2563
2564
			arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER);
2565
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2566
			data.minimumWidth = 100;
2567
			arguments.setLayoutData(data);
2568
			arguments.setFont(stringArgumentComposite.getFont());
2569
	
2570
			attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE);
2571
			
2572
			layout = new GridLayout();
2573
			layout.numColumns = 1;
2574
			layout.marginWidth = 0;
2575
			layout.horizontalSpacing = 0;
2576
			layout.verticalSpacing = 0;
2577
			layout.marginBottom = 0;
2578
			layout.marginHeight = 0;
2579
			attributeStringArgumentComposite.setLayout(layout);
2580
			data = new GridData(SWT.FILL, SWT.TOP, false, true);
2581
			attributeStringArgumentComposite.setLayoutData(data);
2582
			attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont());
2583
2584
			argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK);
2585
			argumentsCaseSensitive.setText(NLS.bind(
2586
					IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
2587
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2588
			data.minimumWidth = 100;
2589
			argumentsCaseSensitive.setLayoutData(data);
2590
			argumentsCaseSensitive.setFont(stringArgumentComposite.getFont());
2591
2592
			argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK);
2593
			argumentsRegularExpresion.setText(NLS.bind(
2594
					IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
2595
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2596
			data.minimumWidth = 100;
2597
			argumentsRegularExpresion.setLayoutData(data);
2598
			argumentsRegularExpresion.setFont(stringArgumentComposite.getFont());
2599
2600
			if (filter.hasStringArguments()) {
2601
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2602
				arguments.setText(argument.pattern);
2603
				isUsingRegularExpression = argument.regularExpression;
2604
				argumentsCaseSensitive.setSelection(argument.caseSensitive);
2605
				argumentsRegularExpresion.setSelection(argument.regularExpression);
2606
			}
2607
2608
			arguments.addModifyListener(new ModifyListener() {
2609
				public void modifyText(ModifyEvent e) {
2610
					storeMultiSelection();
2611
				}
2612
			});
2613
			argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
2614
				public void widgetSelected(SelectionEvent e) {
2615
					setupDescriptionText();
2616
					storeMultiSelection();
2617
					if (fContentAssistField != null)
2618
						fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
2619
				}
2620
			});
2621
			argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
2622
				public void widgetSelected(SelectionEvent e) {
2623
					storeMultiSelection();
2624
				}
2625
			});
2626
2627
			TextContentAdapter contentAdapter= new TextContentAdapter();
2628
			FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2629
			fContentAssistField= new ContentAssistCommandAdapter(
2630
					arguments,
2631
					contentAdapter,
2632
					findProposer, 
2633
					null,
2634
					new char[] {'\\', '[', '('},
2635
					true);
2636
		}
2637
		if (selectedKeyOperatorType.equals(Integer.class)) {
2638
			GridData data;
2639
			arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
2640
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2641
			data.minimumWidth = 100;
2642
			arguments.setLayoutData(data);
2643
			arguments.setFont(multiArgumentComposite.getFont());
2644
2645
			if (filter.hasStringArguments()) {
2646
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2647
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2648
					arguments.setText(convertToEditableTimeInterval(argument.pattern));
2649
				else
2650
					arguments.setText(convertToEditableLength(argument.pattern));
2651
			}
2652
			
2653
			arguments.addModifyListener(new ModifyListener() {
2654
				public void modifyText(ModifyEvent e) {
2655
					storeMultiSelection();
2656
				}
2657
			});
2658
		}
2659
		if (selectedKeyOperatorType.equals(Date.class)) {
2660
			GridData data;
2661
			argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM);
2662
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2663
			argumentsDate.setLayoutData(data);
2664
			argumentsDate.setFont(multiArgumentComposite.getFont());
2665
			argumentsDate.addSelectionListener(new SelectionAdapter() {
2666
				public void widgetSelected(SelectionEvent e) {
2667
					storeMultiSelection();
2668
				}
2669
			});
2670
			if (filter.hasStringArguments()) {
2671
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2672
				Date date; 
2673
				Calendar calendar = Calendar.getInstance();
2674
				try {
2675
					date = new Date(Long.parseLong(argument.pattern));
2676
					calendar.setTime(date);
2677
				} catch (NumberFormatException e1) {
2678
					date = new Date();
2679
					calendar.setTime(date);
2680
					argument.pattern = Long.toString(calendar.getTimeInMillis());
2681
				}
2682
				argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
2683
				argumentsDate.setMonth(calendar.get(Calendar.MONTH));
2684
				argumentsDate.setYear(calendar.get(Calendar.YEAR));
2685
			}
2686
		}
2687
		if (selectedKeyOperatorType.equals(Boolean.class)) {
2688
			GridData data;
2689
			argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
2690
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2691
			argumentsBoolean.setLayoutData(data);
2692
			argumentsBoolean.setFont(multiArgumentComposite.getFont());
2693
			argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())});
2694
			argumentsBoolean.addSelectionListener(new SelectionAdapter() {
2695
				public void widgetSelected(SelectionEvent e) {
2696
					storeMultiSelection();
2697
				}
2698
			});
2699
			if (filter.hasStringArguments()) {
2700
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2701
				if (argument.pattern.length() == 0)
2702
					argumentsBoolean.select(0);
2703
				else
2704
					argumentsBoolean.select(Boolean.getBoolean(argument.pattern) ? 0:1);
2705
			}
2706
		}
2707
		multiArgumentComposite.layout(true);
2708
		intiantiatedKeyOperatorType = selectedKeyOperatorType;
2709
		
2710
		if (fContentAssistField != null)
2711
			fContentAssistField.setEnabled(isUsingRegularExpression);
2712
2713
		shell.layout(true);
2714
		shell.redraw();
2715
		setupDescriptionText();
2716
	}
2717
2718
	private String[] timeIntervalPrefixes = {"s", "m", "h", "d"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
2719
	private double[] timeIntervalScale = {60, 60, 24};
2720
2721
	private String convertToEditableTimeInterval(String string) {
2722
		if (string.length() == 0)
2723
			return string;
2724
		long value;
2725
		try {
2726
			value = Long.parseLong(string);
2727
		} catch (NumberFormatException e) {
2728
			value = 0;
2729
		}
2730
		if (value == 0)
2731
			return Long.toString(0);
2732
		for (int i = 0; i < timeIntervalPrefixes.length - 1; i++) {
2733
			if (value % timeIntervalScale[i] != 0)
2734
				return Long.toString(value) + timeIntervalPrefixes[i];
2735
			value /= timeIntervalScale[i];
2736
		}
2737
		return Long.toString(value) + timeIntervalPrefixes[timeIntervalPrefixes.length - 1];
2738
	}
2739
2740
	private String convertFromEditableTimeInterval(String string) {
2741
		if (string.length() == 0)
2742
			return string;
2743
		for (int i = 1; i < timeIntervalPrefixes.length; i++) {
2744
			if (string.endsWith(timeIntervalPrefixes[i])) {
2745
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2746
				for (int j = 0; j < i; j++)
2747
					value *= timeIntervalScale[j];
2748
				return Long.toString(value);
2749
			}
2750
		}
2751
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2752
		return Long.toString(Long.parseLong(string));
2753
	}
2754
2755
2756
	private String[] lengthPrefixes = {new String(), "k", "m", "g"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
2757
2758
	// converts "32768" to "32k"
2759
	private String convertToEditableLength(String string) {
2760
		if (string.length() == 0)
2761
			return string;
2762
		long value;
2763
		try {
2764
			value = Long.parseLong(string);
2765
		} catch (NumberFormatException e) {
2766
			value = 0;
2767
		}
2768
		if (value == 0)
2769
			return Long.toString(0);
2770
		for (int i = 0; i < lengthPrefixes.length; i++) {
2771
			if (value % 1024 != 0)
2772
				return Long.toString(value) + lengthPrefixes[i];
2773
			if ((i + 1) < lengthPrefixes.length)
2774
				value /= 1024;
2775
		}
2776
		return Long.toString(value) + lengthPrefixes[lengthPrefixes.length - 1];
2777
	}
2778
	
2779
	// converts "32k" to "32768"
2780
	private String convertFromEditableLength(String string) throws NumberFormatException {
2781
		if (string.length() == 0)
2782
			return string;
2783
		for (int i = 1; i < lengthPrefixes.length; i++) {
2784
			if (string.endsWith(lengthPrefixes[i])) {
2785
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2786
				value *= Math.pow(1024, i);
2787
				return Long.toString(value);
2788
			}
2789
		}
2790
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2791
		return Long.toString(Long.parseLong(string));
2792
	}
2793
	
2794
	private void storeMultiSelection() {
2795
		if (intiantiatedKeyOperatorType != null) {
2796
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2797
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2798
	
2799
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2800
			argument.key = selectedKey;
2801
			argument.operator = selectedOperator;
2802
			
2803
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2804
				Calendar calendar = Calendar.getInstance();
2805
				calendar.set(argumentsDate.getYear(), argumentsDate.getMonth(), argumentsDate.getDay());
2806
				argument.pattern = Long.toString(calendar.getTimeInMillis());
2807
			}
2808
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2809
				argument.pattern = arguments.getText();
2810
				if (argumentsRegularExpresion != null)
2811
					argument.regularExpression = argumentsRegularExpresion.getSelection();
2812
				if (argumentsCaseSensitive != null)
2813
					argument.caseSensitive = argumentsCaseSensitive.getSelection();
2814
			}
2815
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2816
				try {
2817
					if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2818
						argument.pattern = convertFromEditableTimeInterval(arguments.getText());
2819
					else
2820
						argument.pattern = convertFromEditableLength(arguments.getText());
2821
				} catch (NumberFormatException e) {
2822
					argument.pattern = arguments.getText();
2823
				}
2824
			}
2825
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null)
2826
				argument.pattern = MultiMatcherLocalization.getMultiMatcherKey(argumentsBoolean.getText());
2827
			String encodedArgument = MultiMatcher.encodeArguments(argument);
2828
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument);
2829
		}
2830
	}
2831
2832
	private String[] getLocalOperatorsForKey(String key) {
2833
		String [] operators = MultiMatcher.getOperatorsForKey(key);
2834
		String[] result = new String[operators.length];
2835
		for (int i = 0; i < operators.length; i++)
2836
			result[i] = MultiMatcherLocalization.getLocalMultiMatcherKey(operators[i]);
2837
		return result;
2838
	}
2839
2840
	private String[] getMultiMatcherKeys() {
2841
		ArrayList list = new ArrayList();
2842
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_NAME));
2843
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_PROPJECT_RELATIVE_PATH));
2844
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LOCATION));
2845
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LAST_MODIFIED));
2846
		if (MultiMatcher.supportCreatedKey())
2847
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_CREATED));
2848
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LENGTH));
2849
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_READONLY));
2850
		if (!Platform.getOS().equals(Platform.OS_WIN32))
2851
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_SYMLINK));
2852
		return (String []) list.toArray(new String[0]);
2853
	}
2854
2855
	/* (non-Javadoc)
2856
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
2857
	 */
2858
	public void selectionChanged() {
2859
	}
2860
2861
	/**
2862
	 * @throws CoreException  
2863
	 */
2864
	/* (non-Javadoc)
2865
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
2866
	 */
2867
	public void validate() throws CoreException {
2868
		if (intiantiatedKeyOperatorType != null) {
2869
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2870
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2871
	
2872
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2873
			argument.key = selectedKey;
2874
			argument.operator = selectedOperator;
2875
			
2876
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2877
			}
2878
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2879
			}
2880
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2881
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) {
2882
					try {
2883
						convertFromEditableTimeInterval(arguments.getText());
2884
					} catch (NumberFormatException e) {
2885
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2886
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidTimeInterval, arguments.getText()), e));
2887
					}
2888
				}
2889
				else {
2890
					try {
2891
						convertFromEditableLength(arguments.getText());
2892
					} catch (NumberFormatException e) {
2893
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2894
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidFileLength, arguments.getText()), e));
2895
					}
2896
				}
2897
			}
2898
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) {
2899
				
2900
			}
2901
		}
2902
	}
2903
2904
	/* (non-Javadoc)
2905
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#formatStyledText(org.eclipse.ui.internal.ide.dialogs.FilterCopy, org.eclipse.jface.viewers.StyledString.Styler, org.eclipse.jface.viewers.StyledString.Styler)
2906
	 */
2907
	public StyledString formatStyledText(FilterCopy filter,
2908
			Styler fPlainStyler, Styler fBoldStyler) {
2909
		return new StyledString(formatMultiMatcherArgument(filter), fPlainStyler);
2910
	}
2911
2912
	private String formatMultiMatcherArgument(FilterCopy filter) {
2913
		String argumentString = (String) filter.getArguments();
2914
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments(argumentString);
2915
		
2916
		StringBuffer builder = new StringBuffer();
2917
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key));
2918
		builder.append(' ');
2919
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator));
2920
		builder.append(' ');
2921
		Class type = MultiMatcher.getTypeForKey(argument.key, argument.operator);
2922
		if (type.equals(String.class))
2923
			builder.append(argument.pattern);
2924
		if (type.equals(Boolean.class))
2925
			builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.pattern));
2926
		if (type.equals(Integer.class)) {
2927
			if (argument.key.equals(MultiMatcher.KEY_LAST_MODIFIED) || argument.key.equals(MultiMatcher.KEY_CREATED))
2928
				builder.append(convertToEditableTimeInterval(argument.pattern));
2929
			else
2930
				builder.append(convertToEditableLength(argument.pattern));
2931
		}
2932
		if (type.equals(Date.class))
2933
			builder.append(DateFormat.getDateInstance().format(new Date(Long.parseLong(argument.pattern))));
2934
		
2935
		return builder.toString();
2936
	}
2937
}
2938
2939
class DefaultCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2940
2941
	Shell shell;
2942
	FilterCopy filter;
2943
	protected Text arguments;
2944
	protected Label argumentsLabel;
2945
	protected Label description;
2946
	protected ContentAssistCommandAdapter fContentAssistField;
2947
2948
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilterMatcher"; //$NON-NLS-1$
2949
2950
	/**
2951
	 * @param parentShell
2952
	 * @param filter
2953
	 */
2954
	public DefaultCustomFilterArgumentUI(Shell parentShell, FilterCopy filter) {
2955
		this.shell = parentShell;
2956
		this.filter = filter;
2957
	}
2958
2959
	/* (non-Javadoc)
2960
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2961
	 */
2962
	public Object getID() {
2963
		return new String();
2964
	}
2965
2966
	/* (non-Javadoc)
2967
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2968
	 */
2969
	public void dispose() {
2970
		Widget list[] = new Widget[] {arguments, argumentsLabel, description};
2971
		for (int i = 0; i < list.length; i++) {
2972
			if (list[i] != null) {
2973
				list[i].dispose();
2974
			}
2975
		}
2976
		arguments = null;
2977
		argumentsLabel = null;
2978
		fContentAssistField = null;
2979
		description = null;
2980
	}
2981
2982
	/* (non-Javadoc)
2983
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2984
	 */
2985
	public void create(Composite argumentComposite, Font font) {
2986
		shell = argumentComposite.getShell();
2987
		GridLayout layout = new GridLayout();
2988
		layout.numColumns = 2;
2989
		layout.marginWidth = 0;
2990
		argumentComposite.setLayout(layout);
2991
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2992
		argumentComposite.setLayoutData(data);
2993
		argumentComposite.setFont(font);
2994
		if (filter.hasStringArguments())
2995
			createArgumentsArea(font, argumentComposite);
2996
2997
		createDescriptionArea(font, argumentComposite);
2998
2999
		if (fContentAssistField != null)
3000
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3001
		argumentComposite.layout(true);
3002
	}
3003
	
3004
	private void createArgumentsArea(Font font, Composite composite) {
3005
		GridData data;
3006
		argumentsLabel = addLabel(composite, NLS.bind(
3007
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
3008
				null));
3009
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
3010
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
3011
		arguments.setLayoutData(data);
3012
		arguments.setFont(font);
3013
		arguments.addModifyListener(new ModifyListener() {
3014
			public void modifyText(ModifyEvent e) {
3015
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
3016
						arguments.getText());
3017
			}
3018
		});
3019
		if (filter.hasStringArguments())
3020
			arguments.setText((String) FilterTypeUtil.getValue(filter,
3021
					FilterTypeUtil.ARGUMENTS));
3022
		arguments.setEnabled(filter.hasStringArguments());
3023
		setArgumentLabelEnabled();
3024
3025
		TextContentAdapter contentAdapter= new TextContentAdapter();
3026
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
3027
		fContentAssistField= new ContentAssistCommandAdapter(
3028
				arguments,
3029
				contentAdapter,
3030
				findProposer, 
3031
				null,
3032
				new char[] {'\\', '[', '('},
3033
				true);
3034
	}
3035
3036
	private void setArgumentLabelEnabled() {
3037
		if (argumentsLabel != null) {
3038
			Color color = argumentsLabel.getDisplay().getSystemColor(
3039
					filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
3040
			argumentsLabel.setForeground(color);
3041
		}
3042
	}
3043
3044
	Label addLabel(Composite composite, String text) {
3045
		String delimiter = ":"; //$NON-NLS-1$
3046
3047
		Font font = composite.getFont();
3048
		Label label = new Label(composite, SWT.LEFT);
3049
		label.setText(text + delimiter);
3050
		GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
3051
		label.setLayoutData(data);
3052
		label.setFont(font);
3053
		return label;
3054
	}
3055
3056
	/* (non-Javadoc)
3057
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
3058
	 */
3059
	public void selectionChanged() {
3060
		if (arguments != null)
3061
			arguments.setEnabled(filter.hasStringArguments());
3062
		setArgumentLabelEnabled();
3063
		if (fContentAssistField != null)
3064
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3065
		description.setText(FilterTypeUtil
3066
				.getDescriptor(filter.getId()).getDescription());
3067
	}
3068
3069
	/**
3070
	 * @param font
3071
	 * @param composite
3072
	 */
3073
	private void createDescriptionArea(Font font, Composite composite) {
3074
		GridData data;
3075
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
3076
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
3077
				.getDescription());
3078
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
3079
		data.widthHint = 300;
3080
		data.heightHint = 40;
3081
		data.horizontalSpan = 2;
3082
		description.setLayoutData(data);
3083
		description.setFont(font);
3084
	}
3085
3086
	/**
3087
	 * @throws CoreException  
3088
	 */
3089
	/* (non-Javadoc)
3090
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
3091
	 */
3092
	public void validate() throws CoreException {
3093
		// nothing
3094
	}
3095
3096
	/* (non-Javadoc)
3097
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#formatStyledText(org.eclipse.ui.internal.ide.dialogs.FilterCopy, org.eclipse.jface.viewers.StyledString.Styler, org.eclipse.jface.viewers.StyledString.Styler)
3098
	 */
3099
	public StyledString formatStyledText(FilterCopy filter,
3100
			Styler fPlainStyler, Styler fBoldStyler) {
3101
		return new StyledString(filter.getArguments() != null ? filter
3102
					.getArguments().toString() : new String(), fPlainStyler);
3103
	}
3104
}
3105
3106
class MultiMatcherLocalization {
3107
	
3108
	static String[][] multiMatcherKey = {
3109
			{MultiMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName},
3110
			{MultiMatcher.KEY_PROPJECT_RELATIVE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyProjectRelativePath},
3111
			{MultiMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation},
3112
			{MultiMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified},
3113
			{MultiMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated},
3114
			{MultiMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength},
3115
			{MultiMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly},
3116
			{MultiMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink},
3117
			{MultiMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter},
3118
			{MultiMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore},
3119
			{MultiMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals},
3120
			{MultiMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches},
3121
			{MultiMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan},
3122
			{MultiMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan},
3123
			{MultiMatcher.OPERATOR_WITHIN, IDEWorkbenchMessages.ResourceFilterPage_multiWithin},
3124
			{Boolean.TRUE.toString(), IDEWorkbenchMessages.ResourceFilterPage_true},
3125
			{Boolean.FALSE.toString(), IDEWorkbenchMessages.ResourceFilterPage_false}
3126
	};
3127
	
3128
	static public String getLocalMultiMatcherKey(String key) {
3129
		for (int i = 0; i < multiMatcherKey.length; i++) {
3130
			if (multiMatcherKey[i][0].equals(key))
3131
				return multiMatcherKey[i][1];
3132
		}
3133
		return null;
3134
	}
3135
	
3136
	static public String getMultiMatcherKey(String local) {
3137
		for (int i = 0; i < multiMatcherKey.length; i++) {
3138
			if (multiMatcherKey[i][1].equals(local))
3139
				return multiMatcherKey[i][0];
3140
		}
3141
		return null;
3142
	}
3143
	
2102
}
3144
}
(-)src/org/eclipse/ui/internal/ide/misc/MultiMatcher.java (+415 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2008, 2009 Freescale Semiconductor 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
 *     Serge Beauchamp (Freescale Semiconductor) - [252996] initial API and implementation
10
 *     IBM Corporation - ongoing implementation
11
 *******************************************************************************/
12
package org.eclipse.ui.internal.ide.misc;
13
14
import java.lang.reflect.InvocationTargetException;
15
import java.lang.reflect.Method;
16
import java.util.Calendar;
17
import java.util.Date;
18
import java.util.GregorianCalendar;
19
import java.util.regex.Matcher;
20
import java.util.regex.Pattern;
21
import java.util.regex.PatternSyntaxException;
22
23
import org.eclipse.core.filesystem.EFS;
24
import org.eclipse.core.filesystem.IFileInfo;
25
import org.eclipse.core.filesystem.IFileStore;
26
import org.eclipse.core.resources.IContainer;
27
import org.eclipse.core.resources.IProject;
28
import org.eclipse.core.resources.filtermatchers.AbstractFileInfoMatcher;
29
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.Platform;
32
import org.eclipse.core.runtime.Status;
33
import org.eclipse.ui.PlatformUI;
34
import org.eclipse.ui.internal.ide.StringMatcher;
35
36
/**
37
 * A file info filter that matches different file and folder attributes.
38
 */
39
public class MultiMatcher extends AbstractFileInfoMatcher {
40
41
	public static String ID = "org.eclipse.ui.ide.multiFilter"; //$NON-NLS-1$
42
43
	public static String KEY_NAME 					= "name"; //$NON-NLS-1$
44
	public static String KEY_PROPJECT_RELATIVE_PATH = "projectRelativePath"; //$NON-NLS-1$
45
	public static String KEY_LOCATION 				= "location"; //$NON-NLS-1$
46
	public static String KEY_LAST_MODIFIED 			= "lastModified"; //$NON-NLS-1$
47
	public static String KEY_LENGTH 				= "length"; //$NON-NLS-1$
48
	public static String KEY_CREATED 				= "created"; //$NON-NLS-1$
49
	public static String KEY_IS_SYMLINK				= "isSymLink"; //$NON-NLS-1$
50
	public static String KEY_IS_READONLY			= "isReadOnly"; //$NON-NLS-1$
51
52
	public static String OPERATOR_NONE			= "none"; //$NON-NLS-1$
53
	public static String OPERATOR_LARGER_THAN	= "largerThan"; //$NON-NLS-1$
54
	public static String OPERATOR_SMALLER_THAN	= "smallerThan"; //$NON-NLS-1$
55
	public static String OPERATOR_EQUALS		= "equals"; //$NON-NLS-1$
56
	public static String OPERATOR_BEFORE		= "before"; //$NON-NLS-1$
57
	public static String OPERATOR_AFTER			= "after"; //$NON-NLS-1$
58
	public static String OPERATOR_WITHIN		= "within"; //$NON-NLS-1$
59
	public static String OPERATOR_MATCHES		= "matches"; //$NON-NLS-1$
60
	
61
62
	/**
63
	 * @param key
64
	 * @return
65
	 */
66
	public static String[] getOperatorsForKey(String key) {
67
		if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION))
68
				return new String[] {OPERATOR_MATCHES};
69
		if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY))
70
			return new String[] {OPERATOR_EQUALS};
71
		if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED))
72
			return new String[] {OPERATOR_EQUALS, OPERATOR_BEFORE, OPERATOR_AFTER, OPERATOR_WITHIN};
73
		if (key.equals(KEY_LENGTH))
74
			return new String[] {OPERATOR_EQUALS, OPERATOR_LARGER_THAN, OPERATOR_SMALLER_THAN};
75
		
76
		return new String[] {OPERATOR_NONE};
77
	}
78
	
79
	/**
80
	 * @param key
81
	 * @param operator
82
	 * @return
83
	 */
84
	public static  Class getTypeForKey(String key, String operator) {
85
		if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION))
86
			return String.class;
87
		if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY))
88
			return Boolean.class;
89
		if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED)) {
90
			if (operator.equals(OPERATOR_WITHIN))
91
				return Integer.class;
92
			return Date.class;
93
		}
94
		if (key.equals(KEY_LENGTH))
95
			return Integer.class;
96
		return String.class;
97
	}
98
	
99
	/**
100
	 * @return
101
	 */
102
	public static boolean supportCreatedKey() {
103
		if (Platform.getOS().equals(Platform.OS_WIN32) || Platform.getOS().equals(Platform.OS_MACOSX)) {
104
			String system = System.getProperty("java.version"); //$NON-NLS-1$
105
			double versionNumber = 0.0;
106
			int index = system.indexOf('.');
107
			if (index != -1) {
108
				versionNumber = Integer.decode(system.substring(0, index)).doubleValue();
109
				system = system.substring(index + 1);
110
				index = system.indexOf('.');
111
				if (index != -1) {
112
					versionNumber += Double.parseDouble(system.substring(0, index)) / 10.0;
113
				}
114
			}
115
			return versionNumber >= 1.7;
116
		}
117
		return false;
118
	}
119
	
120
	/**
121
	 * @since 3.6
122
	 *
123
	 */
124
	public static class Argument {
125
		public String key = KEY_NAME;
126
		public String pattern = new String();
127
		public String operator = OPERATOR_EQUALS;
128
		public boolean caseSensitive = false; 
129
		public boolean regularExpression = false;
130
	}
131
	
132
	/**
133
	 * @param argument
134
	 * @return
135
	 */
136
	public static String encodeArguments(Argument argument)  {
137
		return VERSION_IMPLEMENTATION + DELIMITER + 
138
				argument.key + DELIMITER + 
139
				argument.operator + DELIMITER + 
140
				Boolean.toString(argument.caseSensitive) + DELIMITER + 
141
				Boolean.toString(argument.regularExpression) + DELIMITER + 
142
				argument.pattern;
143
				
144
	}
145
146
	/**
147
	 * @param argument
148
	 * @return
149
	 */
150
	public static Argument decodeArguments(String argument)  {
151
		Argument result = new Argument();
152
		if (argument == null)
153
			return result;
154
		
155
		int index = argument.indexOf(DELIMITER);
156
		if (index == -1)
157
			return result;
158
		
159
		String version = argument.substring(0, index);
160
		argument = argument.substring(index + 1);
161
		
162
		if (!version.equals(VERSION_IMPLEMENTATION))
163
			return result;
164
		
165
		index = argument.indexOf(DELIMITER);
166
		if (index == -1)
167
			return result;
168
169
		result.key = argument.substring(0, index);
170
		argument = argument.substring(index + 1);
171
172
		index = argument.indexOf(DELIMITER);
173
		if (index == -1)
174
			return result;
175
176
		result.operator = argument.substring(0, index);
177
		argument = argument.substring(index + 1);
178
179
		index = argument.indexOf(DELIMITER);
180
		if (index == -1)
181
			return result;
182
183
		result.caseSensitive = Boolean.getBoolean(argument.substring(0, index));
184
		argument = argument.substring(index + 1);
185
		
186
		index = argument.indexOf(DELIMITER);
187
		if (index == -1)
188
			return result;
189
190
		result.regularExpression = Boolean.getBoolean(argument.substring(0, index));
191
		result.pattern = argument.substring(index + 1);
192
193
		return result;
194
	}
195
196
197
	static private String DELIMITER = "-"; //$NON-NLS-1$
198
	static private String VERSION_IMPLEMENTATION = "1.0"; //$NON-NLS-1$
199
200
	/*
201
	 * return value in milliseconds since epoch(1970-01-01T00:00:00Z)
202
	 */
203
	private static long getFileCreationTime(String fullPath) {
204
		/*
205
		java.nio.file.FileSystem fs = java.nio.file.FileSystems.getDefault();
206
		java.nio.file.FileRef fileRef = fs.getPath(file);
207
		java.nio.file.attribute.BasicFileAttributes attributes = java.nio.file.attribute.Attributes.readBasicFileAttributes(fileRef);
208
		return attributes.creationTime();
209
        */
210
211
		try {
212
			Class fileSystems = Class.forName("java.nio.file.FileSystems"); //$NON-NLS-1$
213
			Method getDefault = fileSystems.getMethod("getDefault", null); //$NON-NLS-1$
214
			Object fs = getDefault.invoke(null, null);
215
	
216
			Class fileRef = Class.forName("java.nio.file.FileRef"); //$NON-NLS-1$
217
			Method getPath = fileRef.getMethod("getPath", new Class[] {String.class}); //$NON-NLS-1$
218
			Object fileRefObj = getPath.invoke(fs, new Object[] {fullPath});
219
			
220
			Class attributes = Class.forName("java.nio.file.attribute.Attributes"); //$NON-NLS-1$
221
			Method readBasicFileAttributes = attributes.getMethod("readBasicFileAttributes", new Class[] {fileRef}); //$NON-NLS-1$
222
			Object attributesObj = readBasicFileAttributes.invoke(null, new Object[] {fileRefObj});
223
	
224
			Class basicAttributes = Class.forName("java.nio.file.attribute.BasicFileAttributes"); //$NON-NLS-1$
225
			Method creationTime = basicAttributes.getMethod("creationTime", null); //$NON-NLS-1$
226
			Object time = creationTime.invoke(attributesObj, null);
227
	
228
			Class fileTime = Class.forName("java.nio.file.attribute.FileTime"); //$NON-NLS-1$
229
			Method toMillis = fileTime.getMethod("toMillis", null); //$NON-NLS-1$
230
			Object result = toMillis.invoke(time, null);
231
			
232
			if (result instanceof Long)
233
				return ((Long) result).longValue();
234
		} catch (ClassNotFoundException e) {
235
			e.printStackTrace();
236
		} catch (IllegalArgumentException e) {
237
			e.printStackTrace();
238
		} catch (IllegalAccessException e) {
239
			e.printStackTrace();
240
		} catch (InvocationTargetException e) {
241
			e.printStackTrace();
242
		} catch (SecurityException e) {
243
			e.printStackTrace();
244
		} catch (NoSuchMethodException e) {
245
			e.printStackTrace();
246
		} 
247
		return 0;
248
	}
249
	
250
	MatcherCache matcher = null;
251
	private boolean fSupportsCreatedKey;
252
253
	class MatcherCache {
254
		public MatcherCache(String arguments) {
255
			argument = decodeArguments(arguments);
256
			type = getTypeForKey(argument.key, argument.operator);
257
			if (type.equals(String.class)) {
258
				if (argument.regularExpression == false)
259
					stringMatcher = new StringMatcher(argument.pattern, argument.caseSensitive == false, false);
260
				else
261
					regExPattern = Pattern.compile(argument.pattern, argument.caseSensitive ? 0:Pattern.CASE_INSENSITIVE);
262
			}
263
		}
264
		
265
266
		Argument argument;
267
		Class type;
268
		StringMatcher stringMatcher = null;
269
		Pattern regExPattern = null;
270
271
		public boolean match(IContainer parent, IFileInfo fileInfo) {
272
			if (type.equals(String.class)) {
273
				String value = new String();
274
				if (argument.key.equals(KEY_NAME))
275
					value = fileInfo.getName();
276
				if (argument.key.equals(KEY_PROPJECT_RELATIVE_PATH))
277
					value = parent.getProjectRelativePath().append(fileInfo.getName()).toPortableString();
278
				if (argument.key.equals(KEY_LOCATION))
279
					value = parent.getLocation().append(fileInfo.getName()).toOSString();
280
				
281
				if (stringMatcher != null)
282
					return stringMatcher.match(value);
283
				if (regExPattern != null) {
284
					Matcher m = regExPattern.matcher(value);
285
					return m.matches();
286
				}
287
			}
288
			if (type.equals(Integer.class)) {
289
				int amount;
290
				try {
291
					amount = Integer.parseInt(argument.pattern);
292
				} catch (NumberFormatException e) {
293
					amount = 0;
294
				}
295
				if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) {
296
					// OPERATOR_WITHIN
297
					long time = 0;
298
					if (argument.key.equals(KEY_LAST_MODIFIED)) {
299
						IFileInfo info = fetchInfo(parent, fileInfo);
300
						if (!info.exists())
301
							return false;
302
						time = info.getLastModified();
303
					}
304
					if (argument.key.equals(KEY_CREATED)) {
305
						if (!fSupportsCreatedKey)
306
							return false;
307
						time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString());
308
					}
309
					GregorianCalendar gc = new GregorianCalendar();
310
					gc.add(Calendar.SECOND,-amount);
311
					Date when = gc.getTime();
312
					Date then = new Date(time);
313
					return then.after(when);
314
				}
315
				if (argument.key.equals(KEY_LENGTH)) {
316
					IFileInfo info = fetchInfo(parent, fileInfo);
317
					if (!info.exists())
318
						return false;
319
					if (argument.operator.equals(OPERATOR_EQUALS))
320
						return info.getLength() == amount;
321
					if (argument.operator.equals(OPERATOR_LARGER_THAN))
322
						return info.getLength() > amount;
323
					if (argument.operator.equals(OPERATOR_SMALLER_THAN))
324
						return info.getLength() < amount;
325
				}
326
			}
327
			if (type.equals(Date.class)) {
328
				long parameter = Long.parseLong(argument.pattern);
329
				if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) {
330
					long time = 0;
331
					if (argument.key.equals(KEY_LAST_MODIFIED)) {
332
						IFileInfo info = fetchInfo(parent, fileInfo);
333
						if (!info.exists())
334
							return false;
335
						time = info.getLastModified();
336
					}
337
					if (argument.key.equals(KEY_CREATED)) {
338
						if (!fSupportsCreatedKey)
339
							return false;
340
						time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString());
341
					}
342
					Date when = new Date(parameter);
343
					Date then = new Date(time);
344
					if (argument.operator.equals(OPERATOR_EQUALS))
345
						return roundToOneDay(time) == roundToOneDay(parameter); 
346
					if (argument.operator.equals(OPERATOR_BEFORE))
347
						return then.before(when);
348
					if (argument.operator.equals(OPERATOR_AFTER))
349
						return then.after(when);
350
				}
351
			}
352
			if (type.equals(Boolean.class)) {
353
				boolean parameter = Boolean.getBoolean(argument.pattern);
354
				if (argument.key.equals(KEY_IS_READONLY)) {
355
					IFileInfo info = fetchInfo(parent, fileInfo);
356
					if (!info.exists())
357
						return false;
358
					return info.getAttribute(EFS.ATTRIBUTE_READ_ONLY) == parameter;
359
				}
360
				if (argument.key.equals(KEY_IS_SYMLINK)) {
361
					IFileInfo info = fetchInfo(parent, fileInfo);
362
					if (!info.exists())
363
						return false;
364
					return info.getAttribute(EFS.ATTRIBUTE_SYMLINK) == parameter;
365
				}
366
			}
367
			return false;
368
		}
369
370
		private long roundToOneDay(long parameter) {
371
			return parameter / (1000 * 60 * 60 * 24); // 1000 ms in 1 sec, 60 sec in 1 min, 60 min in 1 hour, 24 hours in 1 day 
372
		}
373
374
		private IFileInfo fetchInfo(IContainer parent, IFileInfo fileInfo) {
375
			IFileStore fileStore;
376
			try {
377
				fileStore = EFS.getStore(parent.getLocationURI());
378
			} catch (CoreException e) {
379
				return fileInfo;
380
			}
381
			IFileStore store = fileStore.getChild(fileInfo.getName());
382
			return store.fetchInfo();
383
		}
384
	}
385
	/**
386
	 * Creates a new factory for this filter type.
387
	 */
388
	public MultiMatcher() {
389
		fSupportsCreatedKey = supportCreatedKey();
390
	}
391
392
	/* (non-Javadoc)
393
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#initialize(org.eclipse.core.resources.IProject, java.lang.Object)
394
	 */
395
	public void initialize(IProject project, Object arguments) throws CoreException {
396
		try {
397
			if ((arguments instanceof String) && ((String) arguments).length() > 0)
398
				matcher = new MatcherCache((String) arguments);
399
		} catch (PatternSyntaxException e) {
400
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
401
		} catch (NumberFormatException e) {
402
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
403
		}
404
	}
405
406
	/* (non-Javadoc)
407
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#matches(org.eclipse.core.filesystem.IFileInfo)
408
	 */
409
	public boolean matches(IContainer parent, IFileInfo fileInfo) throws CoreException {
410
		if (matcher != null) {
411
			return matcher.match(parent, fileInfo);
412
		}
413
		return false;
414
	}
415
}

Return to bug 301820