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 (-1 / +36 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 60-68 Link Here
60
	public static String ResourceFilterPage_addNewFilterTitle;
61
	public static String ResourceFilterPage_addNewFilterTitle;
61
	public static String ResourceFilterPage_columnFilterID;
62
	public static String ResourceFilterPage_columnFilterID;
62
	public static String ResourceFilterPage_columnFilterMode;
63
	public static String ResourceFilterPage_columnFilterMode;
64
	public static String ResourceFilterPage_columnFilterDescription;
63
	public static String ResourceFilterPage_columnFilterTargets;
65
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterInheritable;
66
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterArguments;
67
	public static String ResourceFilterPage_columnFilterTarget;
68
	public static String ResourceFilterPage_applyRecursivelyToFolderStructure;
69
	public static String ResourceFilterPage_customize;
70
	public static String ResourceFilterPage_customizeTitle;
71
	public static String ResourceFilterPage_customizeMessage;
72
	public static String ResourceFilterPage_caseSensitive;
73
	public static String ResourceFilterPage_regularExpression;
74
	public static String ResourceFilterPage_multiMatcher_Matcher;
75
	public static String ResourceFilterPage_multiMatcher_FileLength;
76
	public static String ResourceFilterPage_multiMatcher_TimeInterval;
77
	public static String ResourceFilterPage_multiMatcher_InvalidFileLength;
78
	public static String ResourceFilterPage_multiMatcher_InvalidTimeInterval;
66
	public static String ResourceFilterPage_includeOnly;
79
	public static String ResourceFilterPage_includeOnly;
67
	public static String ResourceFilterPage_excludeAll;
80
	public static String ResourceFilterPage_excludeAll;
68
	public static String ResourceFilterPage_includeOnlyColumn;
81
	public static String ResourceFilterPage_includeOnlyColumn;
Lines 77-82 Link Here
77
	public static String ResourceFilterPage_invalidFilterArgument;
90
	public static String ResourceFilterPage_invalidFilterArgument;
78
	public static String ResourceFilterPage_description;
91
	public static String ResourceFilterPage_description;
79
	public static String ResourceFilterPage_addSubFilterActionLabel;
92
	public static String ResourceFilterPage_addSubFilterActionLabel;
93
	public static String ResourceFilterPage_addSubFilterGroupActionLabel;
94
	public static String ResourceFilterPage_removeFilterActionLabel;
95
	public static String ResourceFilterPage_editFilterActionLabel;
96
	public static String ResourceFilterPage_multiKeyName;
97
	public static String ResourceFilterPage_multiKeyProjectRelativePath;
98
	public static String ResourceFilterPage_multiKeyLocation;
99
	public static String ResourceFilterPage_multiKeyLastModified;
100
	public static String ResourceFilterPage_multiKeyCreated;
101
	public static String ResourceFilterPage_multiKeyLength;
102
	public static String ResourceFilterPage_multiKeyReadOnly;
103
	public static String ResourceFilterPage_multiKeySymLink;
104
	public static String ResourceFilterPage_multiEquals;
105
	public static String ResourceFilterPage_multiMatches;
106
	public static String ResourceFilterPage_multiLargerThan;
107
	public static String ResourceFilterPage_multiSmallerThan;
108
	public static String ResourceFilterPage_multiBefore;
109
	public static String ResourceFilterPage_multiAfter;
110
	public static String ResourceFilterPage_multiWithin;
111
	public static String ResourceFilterPage_true;
112
	public static String ResourceFilterPage_false;
113
	public static String ResourceFilterPage_columnFilterTypeLabel;
114
	
80
	//
115
	//
81
	//
116
	//
82
	// Copies from org.eclipse.ui.workbench
117
	// Copies from org.eclipse.ui.workbench
(-)src/org/eclipse/ui/internal/ide/messages.properties (-6 / +40 lines)
Lines 573-592 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_columnFilterDescription=Description
584
ResourceFilterPage_columnFilterInheritable=In&heritable
586
ResourceFilterPage_columnFilterTargets=Object
585
ResourceFilterPage_columnFilterArguments=&Pattern
587
ResourceFilterPage_columnFilterInheritable=Recursive
588
ResourceFilterPage_columnFilterTarget=&Pattern
589
ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure
590
ResourceFilterPage_customize=Advanced...
591
ResourceFilterPage_customizeTitle=Filter Matcher Selection
592
ResourceFilterPage_customizeMessage=Select resource filter matcher:
593
ResourceFilterPage_caseSensitive=&Case sensitive
594
ResourceFilterPage_regularExpression=Re&gular expression
595
ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \)
596
ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes, *g = gigabytes)
597
ResourceFilterPage_multiMatcher_TimeInterval= (*s = seconds, *m = minutes, *h = hours, *d = days)
598
ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0}
599
ResourceFilterPage_multiMatcher_InvalidTimeInterval=Invalid time interval syntax: {0}
586
ResourceFilterPage_includeOnly=&Include
600
ResourceFilterPage_includeOnly=&Include
587
ResourceFilterPage_excludeAll=&Exclude
601
ResourceFilterPage_excludeAll=&Exclude
588
ResourceFilterPage_includeOnlyColumn=Include
602
ResourceFilterPage_includeOnlyColumn=Include only:
589
ResourceFilterPage_excludeAllColumn=Exclude
603
ResourceFilterPage_excludeAllColumn=Exclude all:
590
ResourceFilterPage_filesAndFolders=Files &and folders
604
ResourceFilterPage_filesAndFolders=Files &and folders
591
ResourceFilterPage_files=&Files
605
ResourceFilterPage_files=&Files
592
ResourceFilterPage_folders=F&olders
606
ResourceFilterPage_folders=F&olders
Lines 596-602 Link Here
596
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
610
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
597
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
611
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
598
ResourceFilterPage_description=Description
612
ResourceFilterPage_description=Description
599
ResourceFilterPage_addSubFilterActionLabel=Add Condition...
613
ResourceFilterPage_addSubFilterActionLabel=Add &Condition...
614
ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group...
615
ResourceFilterPage_removeFilterActionLabel=&Remove
616
ResourceFilterPage_editFilterActionLabel=&Edit
617
ResourceFilterPage_multiKeyName=Name
618
ResourceFilterPage_multiKeyProjectRelativePath=Project Relative Path
619
ResourceFilterPage_multiKeyLocation=Location
620
ResourceFilterPage_multiKeyLastModified=Last Modified
621
ResourceFilterPage_multiKeyCreated=Date Created
622
ResourceFilterPage_multiKeyLength=File Length
623
ResourceFilterPage_multiKeyReadOnly=Read Only
624
ResourceFilterPage_multiKeySymLink=Symbolic Link
625
ResourceFilterPage_multiEquals=equals
626
ResourceFilterPage_multiMatches=matches
627
ResourceFilterPage_multiLargerThan=is larger than
628
ResourceFilterPage_multiSmallerThan=is smaller than
629
ResourceFilterPage_multiBefore=is before
630
ResourceFilterPage_multiAfter=is after
631
ResourceFilterPage_multiWithin=is within
632
ResourceFilterPage_true=true
633
ResourceFilterPage_false=false
600
ResourceInfo_folder = Folder
634
ResourceInfo_folder = Folder
601
ResourceInfo_project = Project
635
ResourceInfo_project = Project
602
ResourceInfo_linkedFile = Linked File
636
ResourceInfo_linkedFile = Linked File
(-)src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java (-406 / +1510 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-130 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;
114
	private Button editButton = null;
139
	private Button editButton = null;
115
140
116
	private TreeViewer filterView;
141
	private TreeViewer filterView;
142
	private TreeContentProvider filterViewContentProvider;
117
	private Filters filters;
143
	private Filters filters;
118
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
144
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
119
	private LabelProvider labelProvider;
145
	private LabelProvider labelProvider;
146
	private Font boldFont;
147
	private Font plainFont;
120
	private Image checkIcon = null;
148
	private Image checkIcon = null;
121
122
	private boolean tableViewCellEditorAdequatlyUsable = false;
149
	private boolean tableViewCellEditorAdequatlyUsable = false;
123
	private boolean allowReordering = false;
124
125
	// parent shell
126
	private Shell shell;
150
	private Shell shell;
127
128
	private IContainer nonExistantResource = getNonExistantResource();
151
	private IContainer nonExistantResource = getNonExistantResource();
129
	private IContainer resource = nonExistantResource;
152
	private IContainer resource = nonExistantResource;
130
153
Lines 277-299 Link Here
277
		}
300
		}
278
	}
301
	}
279
302
303
	static String includeOnlyGroup = "INCLUDE_ONLY_GROUP";  //$NON-NLS-1$
304
305
	static String excludeAllGroup = "EXCLUDE_ALL_GROUP";  //$NON-NLS-1$
306
280
	class TreeContentProvider implements ITreeContentProvider {
307
	class TreeContentProvider implements ITreeContentProvider {
308
		
281
		public Object[] getChildren(Object parentElement) {
309
		public Object[] getChildren(Object parentElement) {
310
			if (parentElement == filters) {
311
				FilterCopy[] children = filters.getChildren();
312
				if (children.length > 0) {
313
					boolean includeOnly = false;
314
					boolean excludeAll = false;
315
					for (int i = 0; i < children.length; i++) {
316
						includeOnly |= (children[i].getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0;
317
						excludeAll |= (children[i].getType() & IResourceFilterDescription.EXCLUDE_ALL) != 0;
318
					}
319
					ArrayList list = new ArrayList();
320
					if (includeOnly)
321
						list.add(includeOnlyGroup);
322
					if (excludeAll)
323
						list.add(excludeAllGroup);
324
					return list.toArray();
325
				}
326
			}
327
			if (parentElement instanceof String) {
328
				ArrayList list = new ArrayList();
329
				int mask = parentElement.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
330
								IResourceFilterDescription.EXCLUDE_ALL;
331
				FilterCopy[] children = filters.getChildren();
332
				for (int i = 0; i < children.length; i++) {
333
					if ((children[i].getType() & mask) != 0)
334
						list.add(children[i]);
335
				}
336
				return list.toArray();
337
			}
282
			if (parentElement instanceof FilterCopy)
338
			if (parentElement instanceof FilterCopy)
283
				return ((FilterCopy) parentElement).getChildren();
339
				return ((FilterCopy) parentElement).getChildren();
284
			return null;
340
			return null;
285
		}
341
		}
286
342
287
		public Object getParent(Object element) {
343
		public Object getParent(Object element) {
288
			if (element instanceof FilterCopy) {
344
			if (element instanceof String)
289
				if (((FilterCopy) element).getParent() != null)
290
					return ((FilterCopy) element).getParent();
291
				return filters;
345
				return filters;
346
			if (element instanceof FilterCopy) {
347
				FilterCopy filterCopy = (FilterCopy) element;
348
				if (filterCopy.getParent() != null)
349
					return filterCopy.getParent();
350
				return ((filterCopy.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0) ? includeOnlyGroup: excludeAllGroup;
292
			}
351
			}
293
			return null;
352
			return null;
294
		}
353
		}
295
354
296
		public boolean hasChildren(Object element) {
355
		public boolean hasChildren(Object element) {
356
			if (element instanceof String)
357
				return true;
297
			if (element instanceof FilterCopy) {
358
			if (element instanceof FilterCopy) {
298
				FilterCopy[] children = ((FilterCopy) element).getChildren();
359
				FilterCopy[] children = ((FilterCopy) element).getChildren();
299
				return children != null && children.length > 0;
360
				return children != null && children.length > 0;
Lines 312-322 Link Here
312
		}
373
		}
313
	}
374
	}
314
375
315
	class LabelProvider implements ITableLabelProvider {
376
	class LabelProvider extends StyledCellLabelProvider  {
377
		/**
378
		 * 
379
		 */
380
		private static final String MIXED = "-"; //$NON-NLS-1$
381
		private final Styler fBoldStyler; 
382
		private final Styler fPlainStyler; 
316
		FilterTypeUtil util;
383
		FilterTypeUtil util;
384
		TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
317
385
318
		public LabelProvider() {
386
		public LabelProvider() {
319
			util = new FilterTypeUtil();
387
			util = new FilterTypeUtil();
388
			fBoldStyler= new Styler() {
389
				public void applyStyles(TextStyle textStyle) {
390
					textStyle.font= boldFont;
391
				}
392
			};
393
			fPlainStyler= new Styler() {
394
				public void applyStyles(TextStyle textStyle) {
395
					textStyle.font= plainFont;
396
				}
397
			};
398
			ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(null, null);
399
			customfilterArgumentMap.put(ui.getID(), ui);
400
			ui = new DefaultCustomFilterArgumentUI(null, null);
401
			customfilterArgumentMap.put(ui.getID(), ui);
402
		}
403
404
		ICustomFilterArgumentUI getUI(String descriptorID) {
405
			ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
406
			if (result == null)
407
				return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
408
			return result;
320
		}
409
		}
321
410
322
		String getColumnID(int index) {
411
		String getColumnID(int index) {
Lines 328-412 Link Here
328
			return copy.isUnderAGroupFilter();
417
			return copy.isUnderAGroupFilter();
329
		}
418
		}
330
419
331
		public Image getColumnImage(Object element, int columnIndex) {
420
		public void update(ViewerCell cell) {
332
			if (!isPartialFilter(element)) {
421
			int columnIndex = cell.getColumnIndex();
333
				if (getColumnID(columnIndex).equals(FilterTypeUtil.ARGUMENTS)) {
334
					Object index = FilterTypeUtil.getValue(
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);
422
			String column = getColumnID(columnIndex);
358
			return getValue(filter, column);
423
			FilterCopy filter = null;
359
		}
360
424
361
		private String getValue(FilterCopy filter, String column) {
425
			Object element = cell.getElement();
362
			if (column.equals(FilterTypeUtil.ID)) {
426
			if (element instanceof String) {
363
				String id = filter.getId();
427
				if (column.equals(FilterTypeUtil.MODE)) {
364
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
428
					cell.setImage(util.getImage(FilterTypeUtil.MODE, element.equals(includeOnlyGroup) ? 0:1));
365
				if (descriptor != null)
429
				}
366
					return descriptor.getName();
430
				if (column.equals(FilterTypeUtil.INHERITABLE)) {
431
					Object [] children = filterViewContentProvider.getChildren(element);
432
					boolean isConsistent = true;
433
					int value = -1;
434
					for (int i = 0; i < children.length; i++) {
435
						Object condition = FilterTypeUtil.getValue((FilterCopy) children[i], FilterTypeUtil.INHERITABLE);
436
						if (value == -1)
437
							value = ((Boolean) condition).booleanValue() ? 1:0;
438
						if (value != (((Boolean) condition).booleanValue() ? 1:0))
439
							isConsistent = false;
440
					}
441
					cell.setImage((value == 1 && isConsistent) ? checkIcon:null);
442
					cell.setText(isConsistent ? new String():MIXED);
443
				}
444
				if (column.equals(FilterTypeUtil.TARGET)) {
445
					Object [] children = filterViewContentProvider.getChildren(element);
446
					boolean isConsistent = true;
447
					int value = -1;
448
					for (int i = 0; i < children.length; i++) {
449
						Object index = FilterTypeUtil.getValue((FilterCopy) children[i], FilterTypeUtil.TARGET);
450
						if (value == -1)
451
							value = ((Integer) index).intValue();
452
						if (value != ((Integer) index).intValue())
453
							isConsistent = false;
454
					}
455
					cell.setImage(isConsistent ? util.getImage(FilterTypeUtil.TARGET, value): null);
456
					cell.setText(isConsistent ? new String():MIXED);
457
				}
367
			}
458
			}
368
			if (column.equals(FilterTypeUtil.MODE)) {
459
			else {
460
				filter = (FilterCopy) element;
461
	
462
				if (column.equals(FilterTypeUtil.ID)) {
463
					String id = filter.getId();
464
					IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
465
					if (descriptor != null)
466
						cell.setText(descriptor.getName());
467
				}
468
				if (column.equals(FilterTypeUtil.TARGET)) {
469
					Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET);
470
					cell.setImage(util.getImage(FilterTypeUtil.TARGET,
471
							((Integer) index).intValue()));
472
				}
369
				if (!isPartialFilter(filter)) {
473
				if (!isPartialFilter(filter)) {
370
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
474
					if (column.equals(FilterTypeUtil.INHERITABLE)) {
371
						return NLS
475
						Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
476
						cell.setImage(((Boolean) condition).booleanValue() ? checkIcon: null);
477
					}
478
				}
479
			}
480
			if (column.equals(FilterTypeUtil.MODE)) {
481
				StyledString styledString = getStyleColumnText(element);
482
				cell.setText(styledString.toString());
483
				cell.setStyleRanges(styledString.getStyleRanges());
484
			}
485
486
			super.update(cell);
487
		}
488
		
489
		private StyledString getStyleColumnText(Object element) {
490
			FilterCopy filter = (element instanceof FilterCopy) ? (FilterCopy) element: null;
491
			if ((filter == null) || (filter.getChildrenLimit() > 0)) {
492
				String whiteSpace = " "; //$NON-NLS-1$;
493
				boolean isUnaryOperator = false;
494
				String expression;
495
				if (element instanceof FilterCopy) {
496
					expression = getFilterTypeName(filter);
497
					isUnaryOperator = filter.getId().equals("org.eclipse.ui.ide.notFilterMatcher"); //$NON-NLS-1$
498
				}else
499
					expression = FilterTypeUtil.getDescriptor("org.eclipse.ui.ide.orFilterMatcher").getName(); //$NON-NLS-1$
500
				StyledString buffer = new StyledString();
501
				if (isUnaryOperator) {
502
					buffer.append("NOT ", fBoldStyler); //$NON-NLS-1$
503
					expression = "OR"; //$NON-NLS-1$
504
				}
505
				if (filter != null)
506
					buffer.append("(", fBoldStyler); //$NON-NLS-1$
507
				else {
508
					if (element.equals(includeOnlyGroup))
509
						buffer.append(NLS
372
								.bind(
510
								.bind(
373
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
511
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
374
										null);
512
										null), fPlainStyler);
375
					return NLS
513
					else
514
						buffer.append(NLS
376
							.bind(
515
							.bind(
377
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
516
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
378
									null);
517
									null), fPlainStyler);
518
					buffer.append(whiteSpace + whiteSpace + whiteSpace, fPlainStyler);
379
				}
519
				}
380
				return getFilterTypeName(filter);
520
				Object [] children = filterViewContentProvider.getChildren(element);
381
			}
521
				for (int i = 0; i < children.length; i++) {
382
			if (column.equals(FilterTypeUtil.TARGET)) {
522
					buffer.append(getStyleColumnText(children[i]));
383
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
523
					if ((i + 1) < children.length) {
384
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
524
						buffer.append(whiteSpace, fPlainStyler);
385
				if (includeFiles && includeFolders)
525
						buffer.append(expression, fBoldStyler);
386
					return NLS
526
						buffer.append(whiteSpace, fPlainStyler);
387
							.bind(
527
					}
388
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
528
				}
389
									null);
529
				if (children.length < 2 && !isUnaryOperator && filter != null) {
390
				if (includeFiles)
530
					if (children.length == 1)
391
					return NLS
531
						buffer.append(whiteSpace, fPlainStyler);
392
							.bind(
532
					buffer.append(expression, fBoldStyler);
393
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
533
				}
394
									null);
534
				if (filter != null)
395
				if (includeFolders)
535
					buffer.append(")", fBoldStyler); //$NON-NLS-1$
396
					return NLS
536
				return buffer;
397
							.bind(
537
			} 
398
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
538
			ICustomFilterArgumentUI ui = getUI(filter.getId());
399
									null);
539
			return ui.formatStyledText(filter, fPlainStyler, fBoldStyler);
400
			}
540
		}
401
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
541
402
				if (filter.hasStringArguments())
542
		protected void measure(Event event, Object element) {
403
					return filter.getArguments() != null ? filter
543
			super.measure(event, element);
404
							.getArguments().toString() : ""; //$NON-NLS-1$
405
				if ((filter.getChildrenLimit() > 0)
406
						&& !filter.isUnderAGroupFilter())
407
					return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$
408
			}
409
			return null;
410
		}
544
		}
411
545
412
		private String getFilterTypeName(FilterCopy filter) {
546
		private String getFilterTypeName(FilterCopy filter) {
Lines 416-436 Link Here
416
				return desc.getName();
550
				return desc.getName();
417
			return ""; //$NON-NLS-1$
551
			return ""; //$NON-NLS-1$
418
		}
552
		}
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
	}
553
	}
433
554
	
434
	class CellModifier implements ICellModifier {
555
	class CellModifier implements ICellModifier {
435
		public boolean canModify(Object element, String property) {
556
		public boolean canModify(Object element, String property) {
436
			FilterCopy filter = (FilterCopy) element;
557
			FilterCopy filter = (FilterCopy) element;
Lines 506-520 Link Here
506
	}
627
	}
507
628
508
	private void createViewerGroup(Composite parent) {
629
	private void createViewerGroup(Composite parent) {
509
		filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
630
		Composite tableComposite = new Composite(parent, SWT.NONE);
510
				| SWT.H_SCROLL);
511
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
631
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
512
		data.grabExcessHorizontalSpace = true;
632
		data.grabExcessHorizontalSpace = true;
513
		data.grabExcessVerticalSpace = true;
633
		data.grabExcessVerticalSpace = true;
634
		tableComposite.setLayoutData(data);
635
636
		filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER
637
				| SWT.H_SCROLL);
638
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
639
		data.grabExcessHorizontalSpace = true;
640
		data.grabExcessVerticalSpace = true;
514
		filterView.getTree().setLayoutData(data);
641
		filterView.getTree().setLayoutData(data);
515
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
642
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
516
643
517
		filterView.setContentProvider(new TreeContentProvider());
644
		plainFont = filterView.getTree().getFont();
645
		FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD);
646
		boldFont = new Font(Display.getCurrent(), boldFontData);
647
648
		filterViewContentProvider = new TreeContentProvider();
649
		filterView.setContentProvider(filterViewContentProvider);
518
		filterView.setInput(filters);
650
		filterView.setInput(filters);
519
		filterView.getTree().setFont(parent.getFont());
651
		filterView.getTree().setFont(parent.getFont());
520
652
Lines 524-560 Link Here
524
			}
656
			}
525
		});
657
		});
526
658
527
		TreeColumn column = new TreeColumn(filterView.getTree(), 0);
659
		TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0);
528
		column
660
		modeColumn
529
				.setText(NLS
661
				.setText(NLS
530
						.bind(
662
						.bind(
531
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
663
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterDescription,
532
								null));
664
								null));
533
		column.setData(FilterTypeUtil.MODE);
665
		modeColumn.setData(FilterTypeUtil.MODE);
534
		column.setResizable(true);
666
		modeColumn.setResizable(true);
535
		column.setMoveable(false);
667
		modeColumn.setMoveable(false);
536
		column.setWidth(getMinimumColumnWidth(column, 130));
668
537
669
		TreeColumn targetColumn = new TreeColumn(filterView.getTree(), 0);
538
		column = new TreeColumn(filterView.getTree(), 0);
670
		targetColumn.setText(NLS.bind(
539
		column.setText(NLS.bind(
671
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
540
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
541
				null));
672
				null));
542
		column.setData(FilterTypeUtil.ARGUMENTS);
673
		targetColumn.setData(FilterTypeUtil.TARGET);
543
		column.setResizable(true);
674
		targetColumn.setResizable(true);
544
		column.setMoveable(true);
675
		targetColumn.setMoveable(true);
545
		column.setWidth(getMinimumColumnWidth(column, 120));
676
		targetColumn.setAlignment(SWT.CENTER);
546
677
547
		column = new TreeColumn(filterView.getTree(), 0);
678
		TreeColumn inheritableColumn = new TreeColumn(filterView.getTree(), 0);
548
		column
679
		inheritableColumn
549
				.setText(NLS
680
				.setText(NLS
550
						.bind(
681
						.bind(
551
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
682
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
552
								null));
683
								null));
553
		column.setData(FilterTypeUtil.INHERITABLE);
684
		inheritableColumn.setData(FilterTypeUtil.INHERITABLE);
554
		column.setResizable(true);
685
		inheritableColumn.setResizable(true);
555
		column.setMoveable(false);
686
		inheritableColumn.setMoveable(false);
556
		column.setAlignment(SWT.CENTER);
687
		inheritableColumn.setAlignment(SWT.CENTER);
557
		column.setWidth(getMinimumColumnWidth(column, 70));
558
688
559
		filterView.getTree().setHeaderVisible(true);
689
		filterView.getTree().setHeaderVisible(true);
560
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
690
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
Lines 578-584 Link Here
578
708
579
		filterView.getTree().addMouseListener(new MouseListener() {
709
		filterView.getTree().addMouseListener(new MouseListener() {
580
			public void mouseDoubleClick(MouseEvent e) {
710
			public void mouseDoubleClick(MouseEvent e) {
581
				handleEdit();
711
				if (!handleEdit()) {
712
					ISelection selection = filterView.getSelection();
713
					if (selection instanceof IStructuredSelection) {
714
						if (((IStructuredSelection) selection).size() > 0) {
715
							Object firstElement = ((IStructuredSelection) selection).getFirstElement();
716
							filterView.setExpandedState(firstElement, !filterView.getExpandedState(firstElement));
717
						}
718
					}
719
				}
582
			}
720
			}
583
721
584
			public void mouseDown(MouseEvent e) {
722
			public void mouseDown(MouseEvent e) {
Lines 598-616 Link Here
598
			public void menuDetected(MenuDetectEvent e) {
736
			public void menuDetected(MenuDetectEvent e) {
599
				MenuManager mgr = new MenuManager();
737
				MenuManager mgr = new MenuManager();
600
				mgr.add(addSubFilterAction);
738
				mgr.add(addSubFilterAction);
739
				mgr.add(addSubGroupFilterAction);
740
				mgr.add(new Separator());
741
				mgr.add(new EditFilterAction());
742
				mgr.add(new RemoveFilterAction());
601
				filterView.getControl().setMenu(
743
				filterView.getControl().setMenu(
602
						mgr.createContextMenu(filterView.getControl()));
744
						mgr.createContextMenu(filterView.getControl()));
603
			}
745
			}
604
		});
746
		});
747
		TreeColumnLayout layout = new TreeColumnLayout();
748
		tableComposite.setLayout( layout );
749
		// 4
750
		layout.setColumnData( modeColumn, new ColumnWeightData(380));
751
		layout.setColumnData( targetColumn, new ColumnWeightData(50));
752
		layout.setColumnData( inheritableColumn, new ColumnWeightData(70));
753
754
	}
755
756
	private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
757
		FontData[] styleData = new FontData[originalData.length];
758
		for (int i = 0; i < styleData.length; i++) {
759
			FontData base = originalData[i];
760
			styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle);
761
		}
762
       	return styleData;
763
    }
764
765
	class EditFilterAction extends Action {
766
767
		public EditFilterAction() {
768
			setText(NLS
769
					.bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel,
770
							null));
771
		}
772
773
		public void run() {
774
			handleEdit();
775
		}
776
		public boolean isEnabled() {
777
			ISelection selection = filterView.getSelection();
778
			if (selection instanceof IStructuredSelection) {
779
				if (((IStructuredSelection) selection).size() > 0) {
780
					Object firstElement = ((IStructuredSelection) selection)
781
					.getFirstElement();
782
					return firstElement instanceof FilterCopy;
783
				}
784
			}
785
			return false;
786
		}
787
	}
788
789
	class RemoveFilterAction extends Action {
790
791
		public RemoveFilterAction() {
792
			setText(NLS
793
					.bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel,
794
							null));
795
		}
796
797
		public void run() {
798
			handleRemove();
799
		}
800
		public boolean isEnabled() {
801
			ISelection selection = filterView.getSelection();
802
			if (selection instanceof IStructuredSelection) {
803
				return ((IStructuredSelection) selection).size() > 0;			}
804
			return false;
805
		}
605
	}
806
	}
606
807
607
	Action addSubFilterAction = new AddSubFilterAction();
808
	Action addSubFilterAction = new AddSubFilterAction(false);
608
809
609
	class AddSubFilterAction extends Action {
810
	class AddSubFilterAction extends Action {
610
811
611
		public AddSubFilterAction() {
812
		boolean createGroupOnly;
813
		
814
		public AddSubFilterAction(boolean createGroupOnly) {
815
			this.createGroupOnly = createGroupOnly;
612
			setText(NLS
816
			setText(NLS
613
					.bind(
817
					.bind(createGroupOnly ?
818
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel:
614
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
819
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
615
							null));
820
							null));
616
		}
821
		}
Lines 623-637 Link Here
623
		public void run() {
828
		public void run() {
624
			ISelection selection = filterView.getSelection();
829
			ISelection selection = filterView.getSelection();
625
			if (selection instanceof IStructuredSelection) {
830
			if (selection instanceof IStructuredSelection) {
626
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
831
				Object firstElement = ((IStructuredSelection) selection)
627
						.getFirstElement();
832
				.getFirstElement();
628
				if (filter.getChildrenLimit() > 0) {
833
				if (firstElement instanceof FilterCopy) {
834
					FilterCopy filter = (FilterCopy) firstElement;
835
					if (filter.getChildrenLimit() > 0) {
836
						FilterCopy newFilter = new FilterCopy();
837
						newFilter.setParent(filter);
838
						FilterEditDialog dialog = new FilterEditDialog(resource, shell,
839
								newFilter, createGroupOnly);
840
						if (dialog.open() == Window.OK) {
841
							filter.addChild(newFilter);
842
							filterView.refresh();
843
						}
844
					}
845
				}
846
				if (firstElement instanceof String) {
629
					FilterCopy newFilter = new FilterCopy();
847
					FilterCopy newFilter = new FilterCopy();
630
					newFilter.setParent(filter);
848
					FilterTypeUtil.setValue(newFilter, FilterTypeUtil.MODE, 
849
							new Integer(firstElement.equals(includeOnlyGroup) ? 0:1));
631
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
850
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
632
							newFilter);
851
							newFilter, createGroupOnly);
633
					if (dialog.open() == Window.OK) {
852
					if (dialog.open() == Window.OK) {
634
						filter.addChild(newFilter);
853
						filters.addChild(newFilter);
635
						filterView.refresh();
854
						filterView.refresh();
636
					}
855
					}
637
				}
856
				}
Lines 646-659 Link Here
646
		public boolean isEnabled() {
865
		public boolean isEnabled() {
647
			ISelection selection = filterView.getSelection();
866
			ISelection selection = filterView.getSelection();
648
			if (selection instanceof IStructuredSelection) {
867
			if (selection instanceof IStructuredSelection) {
649
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
868
				Object firstElement = ((IStructuredSelection) selection)
650
						.getFirstElement();
869
						.getFirstElement();
651
				return filter.getChildrenLimit() > 0;
870
				if (firstElement instanceof FilterCopy) {
871
					FilterCopy filter = (FilterCopy) firstElement;
872
					return filter.getChildrenLimit() > 0;
873
				}
874
				if (firstElement instanceof String)
875
					return true;
652
			}
876
			}
653
			return false;
877
			return false;
654
		}
878
		}
655
	}
879
	}
656
880
881
	Action addSubGroupFilterAction = new AddSubFilterAction(true);
882
657
	class FilterCopyDrop extends ViewerDropAdapter {
883
	class FilterCopyDrop extends ViewerDropAdapter {
658
		protected FilterCopyDrop(Viewer viewer) {
884
		protected FilterCopyDrop(Viewer viewer) {
659
			super(viewer);
885
			super(viewer);
Lines 682-687 Link Here
682
			for (int i = 0; i < toDrop.length; i++) {
908
			for (int i = 0; i < toDrop.length; i++) {
683
				if (target instanceof Filters)
909
				if (target instanceof Filters)
684
					filters.add(toDrop[i]);
910
					filters.add(toDrop[i]);
911
				if (target instanceof String) {
912
					FilterTypeUtil.setValue(toDrop[i], FilterTypeUtil.MODE,
913
							new Integer(target.equals(includeOnlyGroup) ? 0:1));
914
					filters.add(toDrop[i]);
915
				}
685
				if (target instanceof FilterCopy)
916
				if (target instanceof FilterCopy)
686
					((FilterCopy) target).addChild(toDrop[i]);
917
					((FilterCopy) target).addChild(toDrop[i]);
687
				filterView.refresh();
918
				filterView.refresh();
Lines 749-768 Link Here
749
		}
980
		}
750
	}
981
	}
751
982
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) {
983
	private void createButtonGroup(Composite parent) {
767
		Composite composite = new Composite(parent, SWT.NONE);
984
		Composite composite = new Composite(parent, SWT.NONE);
768
		GridLayout layout = new GridLayout();
985
		GridLayout layout = new GridLayout();
Lines 780-793 Link Here
780
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
997
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
781
		addButton.setLayoutData(data);
998
		addButton.setLayoutData(data);
782
		setButtonDimensionHint(addButton);
999
		setButtonDimensionHint(addButton);
783
		addButton.addSelectionListener(new SelectionListener() {
1000
		addButton.addSelectionListener(new SelectionAdapter() {
784
			public void widgetDefaultSelected(SelectionEvent e) {
1001
			public void widgetSelected(SelectionEvent e) {
1002
				handleAdd(false);
785
			}
1003
			}
786
1004
		});
1005
		
1006
		addGroupButton = new Button(composite, SWT.PUSH);
1007
		addGroupButton.setText(NLS.bind(
1008
				IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null));
1009
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1010
		addGroupButton.setLayoutData(data);
1011
		setButtonDimensionHint(addGroupButton);
1012
		addGroupButton.addSelectionListener(new SelectionAdapter() {
787
			public void widgetSelected(SelectionEvent e) {
1013
			public void widgetSelected(SelectionEvent e) {
788
				handleAdd();
1014
				handleAdd(true);
789
			}
1015
			}
790
		});
1016
		});
1017
		
791
1018
792
		editButton = new Button(composite, SWT.PUSH);
1019
		editButton = new Button(composite, SWT.PUSH);
793
		editButton.setText(NLS.bind(
1020
		editButton.setText(NLS.bind(
Lines 795-804 Link Here
795
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1022
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
796
		editButton.setLayoutData(data);
1023
		editButton.setLayoutData(data);
797
		setButtonDimensionHint(editButton);
1024
		setButtonDimensionHint(editButton);
798
		editButton.addSelectionListener(new SelectionListener() {
1025
		editButton.addSelectionListener(new SelectionAdapter() {
799
			public void widgetDefaultSelected(SelectionEvent e) {
800
			}
801
802
			public void widgetSelected(SelectionEvent e) {
1026
			public void widgetSelected(SelectionEvent e) {
803
				handleEdit();
1027
				handleEdit();
804
			}
1028
			}
Lines 813-862 Link Here
813
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1037
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
814
		removeButton.setLayoutData(data);
1038
		removeButton.setLayoutData(data);
815
		setButtonDimensionHint(removeButton);
1039
		setButtonDimensionHint(removeButton);
816
		removeButton.addSelectionListener(new SelectionListener() {
1040
		removeButton.addSelectionListener(new SelectionAdapter() {
817
			public void widgetDefaultSelected(SelectionEvent e) {
818
			}
819
820
			public void widgetSelected(SelectionEvent e) {
1041
			public void widgetSelected(SelectionEvent e) {
821
				handleRemove();
1042
				handleRemove();
822
			}
1043
			}
823
		});
1044
		});
824
825
		if (allowReordering) {
826
			upButton = new Button(composite, SWT.PUSH);
827
			upButton
828
					.setText(NLS
829
							.bind(
830
									IDEWorkbenchMessages.ResourceFilterPage_upButtonLabel,
831
									null));
832
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
833
			upButton.setLayoutData(data);
834
			setButtonDimensionHint(upButton);
835
			upButton.addSelectionListener(new SelectionListener() {
836
				public void widgetDefaultSelected(SelectionEvent e) {
837
				}
838
839
				public void widgetSelected(SelectionEvent e) {
840
					handleUp();
841
				}
842
			});
843
844
			downButton = new Button(composite, SWT.PUSH);
845
			downButton.setText(NLS.bind(
846
					IDEWorkbenchMessages.ResourceFilterPage_downButtonLabel,
847
					null));
848
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
849
			downButton.setLayoutData(data);
850
			setButtonDimensionHint(downButton);
851
			downButton.addSelectionListener(new SelectionListener() {
852
				public void widgetDefaultSelected(SelectionEvent e) {
853
				}
854
855
				public void widgetSelected(SelectionEvent e) {
856
					handleDown();
857
				}
858
			});
859
		}
860
	}
1045
	}
861
1046
862
	private void refreshEnablement() {
1047
	private void refreshEnablement() {
Lines 868-874 Link Here
868
		removeButton.setEnabled(structuredSelection != null
1053
		removeButton.setEnabled(structuredSelection != null
869
				&& structuredSelection.size() > 0);
1054
				&& structuredSelection.size() > 0);
870
		editButton.setEnabled(structuredSelection != null
1055
		editButton.setEnabled(structuredSelection != null
871
				&& structuredSelection.size() == 1);
1056
				&& structuredSelection.size() == 1
1057
				&& (structuredSelection.getFirstElement() instanceof FilterCopy));
872
		if (upButton != null)
1058
		if (upButton != null)
873
			upButton.setEnabled(structuredSelection != null
1059
			upButton.setEnabled(structuredSelection != null
874
					&& (structuredSelection.size() > 0)
1060
					&& (structuredSelection.size() > 0)
Lines 887-916 Link Here
887
		return filters.isLast((FilterCopy) o);
1073
		return filters.isLast((FilterCopy) o);
888
	}
1074
	}
889
1075
890
	private void handleAdd() {
1076
	private void handleAdd(boolean createGroupOnly) {
891
		FilterCopy newFilter = new FilterCopy();
1077
		FilterCopy newFilter = new FilterCopy();
892
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter);
1078
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter, createGroupOnly);
893
		if (dialog.open() == Window.OK) {
1079
		if (dialog.open() == Window.OK) {
894
			filters.add(newFilter);
1080
			filters.add(newFilter);
895
			filterView.refresh();
1081
			filterView.refresh();
896
		}
1082
		}
897
	}
1083
	}
898
1084
899
	private void handleEdit() {
1085
	private boolean handleEdit() {
900
		ISelection selection = filterView.getSelection();
1086
		ISelection selection = filterView.getSelection();
901
		if (selection instanceof IStructuredSelection) {
1087
		if (selection instanceof IStructuredSelection) {
902
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
1088
			Object firstElement = ((IStructuredSelection) selection)
903
					.getFirstElement();
1089
					.getFirstElement();
904
			FilterCopy copy = new FilterCopy(filter);
1090
			if (firstElement instanceof String) { // if there's only 1 child, we edit it instead of expanding the tree
905
			copy.setParent(filter.getParent());
1091
				Object [] children = filterViewContentProvider.getChildren(firstElement);
906
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy);
1092
				if (children.length == 1)
907
			if (dialog.open() == Window.OK) {
1093
					firstElement = children[0]; 
908
				if (copy.hasChanged()) {
1094
			}
909
					filter.copy(copy);
1095
			if (firstElement instanceof FilterCopy) {
910
					filterView.refresh();
1096
				FilterCopy filter = (FilterCopy) firstElement;
1097
				FilterCopy copy = new FilterCopy(filter);
1098
				copy.setParent(filter.getParent());
1099
				boolean isGroup = filter.getChildrenLimit() > 0;
1100
				FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy, isGroup);
1101
				if (dialog.open() == Window.OK) {
1102
					if (copy.hasChanged()) {
1103
						filter.copy(copy);
1104
						filterView.refresh();
1105
					}
911
				}
1106
				}
1107
				return true;
912
			}
1108
			}
913
		}
1109
		}
1110
		return false;
914
	}
1111
	}
915
1112
916
	private FilterCopy[] getFilterCopySelection() {
1113
	private FilterCopy[] getFilterCopySelection() {
Lines 933-967 Link Here
933
			structuredSelection = ((IStructuredSelection) selection);
1130
			structuredSelection = ((IStructuredSelection) selection);
934
			Iterator it = structuredSelection.iterator();
1131
			Iterator it = structuredSelection.iterator();
935
			while (it.hasNext()) {
1132
			while (it.hasNext()) {
936
				FilterCopy filter = (FilterCopy) it.next();
1133
				Object element = it.next();
937
				filter.getParent().removeChild(filter);
1134
				if (element instanceof FilterCopy) {
1135
					FilterCopy filter = (FilterCopy) element;
1136
					filter.getParent().removeChild(filter);
1137
				}
1138
				else {
1139
					int mask = element.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
1140
						IResourceFilterDescription.EXCLUDE_ALL;
1141
					FilterCopy[] children = filters.getChildren();
1142
					for (int i = 0; i < children.length; i++) {
1143
						if ((children[i].getType() & mask) != 0)
1144
							filters.removeChild(children[i]);
1145
					}
1146
				}
938
			}
1147
			}
939
			filterView.refresh();
1148
			filterView.refresh();
940
		}
1149
		}
941
	}
1150
	}
942
1151
943
	private void handleUp() {
944
		ISelection selection = filterView.getSelection();
945
		if (selection instanceof IStructuredSelection) {
946
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
947
					.getFirstElement();
948
			filters.moveUp(filter);
949
		}
950
		filterView.refresh();
951
		refreshEnablement();
952
	}
953
954
	private void handleDown() {
955
		ISelection selection = filterView.getSelection();
956
		if (selection instanceof IStructuredSelection) {
957
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
958
					.getFirstElement();
959
			filters.moveDown(filter);
960
		}
961
		filterView.refresh();
962
		refreshEnablement();
963
	}
964
965
	private static void setButtonDimensionHint(Button button) {
1152
	private static void setButtonDimensionHint(Button button) {
966
		Assert.isNotNull(button);
1153
		Assert.isNotNull(button);
967
		Object gd = button.getLayoutData();
1154
		Object gd = button.getLayoutData();
Lines 1149-1155 Link Here
1149
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1336
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1150
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1337
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1151
1338
1152
	static String[] columnNames = new String[] { MODE, ARGUMENTS, INHERITABLE };
1339
	static String[] columnNames = new String[] { MODE, TARGET, INHERITABLE };
1153
1340
1154
	static String[] getModes() {
1341
	static String[] getModes() {
1155
		return new String[] {
1342
		return new String[] {
Lines 1263-1286 Link Here
1263
								null) };
1450
								null) };
1264
	}
1451
	}
1265
1452
1266
	static String[] getFilterNames(boolean childrenOnly) {
1453
	static String[] getFilterNames(boolean groupOnly) {
1267
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1454
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1268
				.getFilterMatcherDescriptors();
1455
				.getFilterMatcherDescriptors();
1456
		sortDescriptors(descriptors);
1269
		LinkedList names = new LinkedList();
1457
		LinkedList names = new LinkedList();
1270
		for (int i = 0; i < descriptors.length; i++) {
1458
		for (int i = 0; i < descriptors.length; i++) {
1271
			if (!childrenOnly
1459
			boolean isGroup = descriptors[i].getArgumentType().equals(
1272
					|| descriptors[i].getArgumentType().equals(
1460
					IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1273
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1274
					|| descriptors[i].getArgumentType().equals(
1461
					|| descriptors[i].getArgumentType().equals(
1275
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS))
1462
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS);
1463
			if (isGroup == groupOnly) 
1276
				names.add(descriptors[i].getName());
1464
				names.add(descriptors[i].getName());
1277
		}
1465
		}
1278
		return (String[]) names.toArray(new String[0]);
1466
		return (String[]) names.toArray(new String[0]);
1279
	}
1467
	}
1280
1468
1469
	/**
1470
	 * @param descriptors
1471
	 */
1472
	private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) {
1473
		Arrays.sort(descriptors, new Comparator() {
1474
			public int compare(Object arg0, Object arg1) {
1475
				if (((IFilterMatcherDescriptor) arg0).getId().equals(MultiMatcher.ID))
1476
					return -1;
1477
				if (((IFilterMatcherDescriptor) arg1).getId().equals(MultiMatcher.ID))
1478
					return 1;
1479
				return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId());
1480
			}
1481
		});
1482
	}
1483
1281
	static String getDefaultFilterID() {
1484
	static String getDefaultFilterID() {
1282
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1485
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1283
				.getFilterMatcherDescriptors();
1486
				.getFilterMatcherDescriptors();
1487
		sortDescriptors(descriptors);
1284
		for (int i = 0; i < descriptors.length; i++) {
1488
		for (int i = 0; i < descriptors.length; i++) {
1285
			if (descriptors[i].getArgumentType().equals(
1489
			if (descriptors[i].getArgumentType().equals(
1286
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
1490
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
Lines 1669-1700 Link Here
1669
	protected Button foldersButton;
1873
	protected Button foldersButton;
1670
	protected Button filesAndFoldersButton;
1874
	protected Button filesAndFoldersButton;
1671
	protected Combo idCombo;
1875
	protected Combo idCombo;
1876
	protected Composite idComposite;
1877
	protected Composite argumentComposite;
1672
	protected Button inherited;
1878
	protected Button inherited;
1673
	protected Text arguments;
1674
	protected Label argumentsLabel;
1675
	protected Label description;
1676
	protected FilterTypeUtil util;
1879
	protected FilterTypeUtil util;
1880
	protected boolean createGroupOnly;
1677
	protected IResource resource;
1881
	protected IResource resource;
1678
1882
1679
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$
1883
	TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
1680
	
1884
	ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() {
1681
	/**
1885
		public Object getID() {return "dummy";} //$NON-NLS-1$
1682
	 * Find and replace command adapters.
1886
		public void create(Composite argumentComposite, Font font) {}
1683
	 * @since 3.3
1887
		public void dispose() {}
1684
	 */
1888
		public void selectionChanged() {}
1685
	private ContentAssistCommandAdapter fContentAssistField;
1889
		public void validate() {}
1890
		public StyledString formatStyledText(FilterCopy filter,
1891
				Styler fPlainStyler, Styler fBoldStyler) {return null;}
1892
	};
1686
1893
1687
	/**
1894
	/**
1688
	 * Constructor for FilterEditDialog.
1895
	 * Constructor for FilterEditDialog.
1689
	 * 
1896
	 * 
1690
	 * @param parentShell
1897
	 * @param parentShell
1691
	 * @param filter
1898
	 * @param filter
1899
	 * @param createGroupOnly 
1692
	 */
1900
	 */
1693
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) {
1901
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter, boolean createGroupOnly) {
1694
		super(parentShell);
1902
		super(parentShell);
1695
		this.resource = resource;
1903
		this.resource = resource;
1696
		this.filter = filter;
1904
		this.filter = filter;
1905
		this.createGroupOnly = createGroupOnly;
1697
		util = new FilterTypeUtil();
1906
		util = new FilterTypeUtil();
1907
		ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter);
1908
		customfilterArgumentMap.put(ui.getID(), ui);
1909
		ui = new DefaultCustomFilterArgumentUI(parentShell, filter);
1910
		customfilterArgumentMap.put(ui.getID(), ui);
1698
	}
1911
	}
1699
1912
1700
	/*
1913
	/*
Lines 1728-1734 Link Here
1728
		if (!filter.isUnderAGroupFilter()) {
1941
		if (!filter.isUnderAGroupFilter()) {
1729
			Composite topComposite = new Composite(composite, SWT.NONE);
1942
			Composite topComposite = new Composite(composite, SWT.NONE);
1730
			layout = new GridLayout();
1943
			layout = new GridLayout();
1731
			layout.numColumns = 2;
1944
			layout.numColumns = 1;
1732
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1945
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1733
			layout.marginWidth = 0;
1946
			layout.marginWidth = 0;
1734
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1947
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
Lines 1739-1748 Link Here
1739
			topComposite.setFont(font);
1952
			topComposite.setFont(font);
1740
1953
1741
			createModeArea(font, topComposite);
1954
			createModeArea(font, topComposite);
1955
			createIdArea(font, topComposite);
1742
			createTargetArea(font, topComposite);
1956
			createTargetArea(font, topComposite);
1957
			createInheritableArea(font, topComposite);
1958
		}
1959
		else
1960
			createIdArea(font, composite);
1961
		return composite;
1962
	}
1963
1964
	/* (non-Javadoc)
1965
	 * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
1966
	 */
1967
	protected Control createButtonBar(Composite parent) {
1968
		Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
1969
		label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
1970
1971
		Composite composite = new Composite(parent, SWT.NONE);
1972
    	GridLayout layout = new GridLayout();
1973
    	layout.marginWidth = 0;
1974
    	layout.marginHeight = 0;
1975
    	layout.horizontalSpacing = 0;
1976
    	composite.setLayout(layout);
1977
    	composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1978
    	composite.setFont(parent.getFont());
1979
1980
		// create help control if needed
1981
        if (isHelpAvailable()) {
1982
        	Control helpControl = createHelpControl(composite);
1983
        	((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1984
		}
1985
        if (!createGroupOnly) {
1986
    		((GridLayout) composite.getLayout()).numColumns++;
1987
	        Button customizeButton = new Button(composite, SWT.PUSH);
1988
	        customizeButton.setText(NLS.bind(
1989
					IDEWorkbenchMessages.ResourceFilterPage_customize,
1990
					null));
1991
	        customizeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
1992
	        customizeButton.addSelectionListener(new SelectionAdapter() {
1993
				public void widgetSelected(SelectionEvent e) {
1994
					selectOtherFilterMatcher();
1995
				}
1996
	        });
1997
        }
1998
        
1999
        Control buttonSection = dialogCreateButtonBar(composite);
2000
        ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
2001
        return composite;
2002
	}
2003
2004
	private void selectOtherFilterMatcher() {
2005
		ListDialog dlg =
2006
			   new ListDialog(getShell());
2007
		dlg.setAddCancelButton(true);
2008
		dlg.setInput(Arrays.asList(FilterTypeUtil.getFilterNames(createGroupOnly)));
2009
		dlg.setInitialElementSelections(Arrays.asList(new String[] {FilterTypeUtil.getDescriptor(filter.getId()).getName()}));
2010
		dlg.setContentProvider(new IStructuredContentProvider() {
2011
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
2012
			public void dispose() {}
2013
			public Object[] getElements(Object inputElement) {
2014
				if (inputElement instanceof List)
2015
					return ((List) inputElement).toArray();
2016
				return null;
2017
			}
2018
		});
2019
		dlg.setLabelProvider(new org.eclipse.jface.viewers.LabelProvider());
2020
		dlg.setTitle(NLS.bind(
2021
				IDEWorkbenchMessages.ResourceFilterPage_customizeTitle,
2022
				null));
2023
		dlg.setMessage(NLS.bind(
2024
					IDEWorkbenchMessages.ResourceFilterPage_customizeMessage,
2025
					null));
2026
		if (dlg.open() == Window.OK) {
2027
			Object[] result = dlg.getResult();
2028
			if (result.length > 0) {
2029
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, result[0]);
2030
				if (filter.hasStringArguments())
2031
					filter.setArguments(new String());
2032
				setupPatternLine();
2033
				currentCustomFilterArgumentUI.selectionChanged();
2034
			}
1743
		}
2035
		}
1744
		createIdArea(font, composite);
2036
	}
1745
2037
2038
	private Control dialogCreateButtonBar(Composite parent) {
2039
		Composite composite = new Composite(parent, SWT.NONE);
2040
		// create a layout with spacing and margins appropriate for the font
2041
		// size.
2042
		GridLayout layout = new GridLayout();
2043
		layout.numColumns = 0; // this is incremented by createButton
2044
		layout.makeColumnsEqualWidth = true;
2045
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2046
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
2047
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
2048
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
2049
		composite.setLayout(layout);
2050
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END
2051
				| GridData.VERTICAL_ALIGN_CENTER);
2052
		composite.setLayoutData(data);
2053
		composite.setFont(parent.getFont());
2054
		
2055
		// Add the buttons to the button bar.
2056
		createButtonsForButtonBar(composite);
1746
		return composite;
2057
		return composite;
1747
	}
2058
	}
1748
2059
Lines 1751-1772 Link Here
1751
	 * @param composite
2062
	 * @param composite
1752
	 */
2063
	 */
1753
	private void createInheritableArea(Font font, Composite composite) {
2064
	private void createInheritableArea(Font font, Composite composite) {
2065
		Composite inheritableComposite = createGroup(font, composite, NLS.bind(
2066
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2067
				null), false, false, 1);
2068
1754
		GridData data;
2069
		GridData data;
1755
		inherited = new Button(composite, SWT.CHECK);
2070
		inherited = new Button(inheritableComposite, SWT.CHECK);
1756
		inherited
2071
		inherited
1757
				.setText(NLS
2072
				.setText(NLS
1758
						.bind(
2073
						.bind(
1759
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
2074
								IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure,
1760
								null));
2075
								null));
1761
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
2076
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
1762
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2077
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1763
		data.horizontalSpan = 1;
2078
		data.horizontalSpan = 1;
1764
		inherited.setLayoutData(data);
2079
		inherited.setLayoutData(data);
1765
		inherited.setFont(font);
2080
		inherited.setFont(font);
1766
		inherited.addSelectionListener(new SelectionListener() {
2081
		inherited.addSelectionListener(new SelectionAdapter() {
1767
			public void widgetDefaultSelected(SelectionEvent e) {
1768
			}
1769
1770
			public void widgetSelected(SelectionEvent e) {
2082
			public void widgetSelected(SelectionEvent e) {
1771
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
2083
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1772
						new Boolean(inherited.getSelection()));
2084
						new Boolean(inherited.getSelection()));
Lines 1780-1884 Link Here
1780
	 * @param font
2092
	 * @param font
1781
	 * @param composite
2093
	 * @param composite
1782
	 */
2094
	 */
1783
	private void createArgumentsArea(Font font, Composite composite) {
2095
	private void createIdArea(Font font, Composite composite) {
1784
		GridData data;
2096
		GridData data;
1785
		argumentsLabel = addLabel(composite, NLS.bind(
2097
		if (createGroupOnly) {
1786
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
2098
			idComposite = createGroup(font, composite, new String(),
1787
				null));
2099
					true, true, 1);
1788
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
2100
			idCombo = new Combo(idComposite, SWT.READ_ONLY);
1789
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2101
			idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly));
1790
		arguments.setLayoutData(data);
2102
			data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1791
		arguments.setFont(font);
2103
			idCombo.setLayoutData(data);
1792
		arguments.addModifyListener(new ModifyListener() {
2104
			idCombo.setFont(font);
1793
			public void modifyText(ModifyEvent e) {
2105
			idCombo.addSelectionListener(new SelectionAdapter() {
1794
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
2106
				public void widgetSelected(SelectionEvent e) {
1795
						arguments.getText());
2107
					FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1796
			}
2108
							.getItem(idCombo.getSelectionIndex()));
1797
		});
2109
					if (filter.hasStringArguments())
1798
		if (filter.hasStringArguments())
2110
						filter.setArguments(new String());
1799
			arguments.setText((String) FilterTypeUtil.getValue(filter,
2111
					setupPatternLine();
1800
					FilterTypeUtil.ARGUMENTS));
2112
					currentCustomFilterArgumentUI.selectionChanged();
1801
		arguments.setEnabled(filter.hasStringArguments());
2113
				}
1802
		setArgumentLabelEnabled();
2114
			});
2115
			idCombo.select(0);
2116
			selectComboItem(filter.getId());
2117
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
2118
					.getItem(idCombo.getSelectionIndex()));
2119
		}
2120
		else {
2121
			idComposite = createGroup(font, composite, new String(),
2122
					true, true, 1);
2123
		}
2124
		argumentComposite = new Composite(idComposite, SWT.NONE);
2125
		setupPatternLine();
2126
	}
2127
	
1803
2128
1804
		TextContentAdapter contentAdapter= new TextContentAdapter();
2129
	ICustomFilterArgumentUI getUI(String descriptorID) {
1805
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2130
		ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
1806
		fContentAssistField= new ContentAssistCommandAdapter(
2131
		if (result == null)
1807
				arguments,
2132
			return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
1808
				contentAdapter,
2133
		return result;
1809
				findProposer, 
1810
				null,
1811
				new char[] {'\\', '[', '('},
1812
				true);
1813
	}
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
	}
1823
1824
	/**
1825
	 * @param font
1826
	 * @param composite
1827
	 */
1828
	private void createDescriptionArea(Font font, Composite composite) {
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
	}
2134
	}
1839
2135
	
1840
	/**
2136
	private void setupPatternLine() {
1841
	 * @param font
2137
		IFilterMatcherDescriptor descriptor;
1842
	 * @param composite
2138
		if (createGroupOnly) {
1843
	 */
2139
			String item = idCombo.getItem(idCombo.getSelectionIndex());
1844
	private void createIdArea(Font font, Composite composite) {
2140
			descriptor = FilterTypeUtil.getDescriptorByName(item);
1845
		GridData data;
2141
		}
1846
		Group idComposite = createGroup(font, composite, NLS.bind(
2142
		else
1847
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null),
2143
			descriptor = FilterTypeUtil.getDescriptor(filter.getId());
1848
				true);
2144
		Font font = idComposite.getFont();
1849
		idCombo = new Combo(idComposite, SWT.READ_ONLY);
2145
		ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId());
1850
		idCombo.setItems(FilterTypeUtil.getFilterNames(filter
2146
		if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) {
1851
				.getChildrenLimit() > 0));
2147
			currentCustomFilterArgumentUI.dispose();
1852
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2148
			currentCustomFilterArgumentUI = customFilterArgumentUI;
1853
		idCombo.setLayoutData(data);
2149
			currentCustomFilterArgumentUI.create(argumentComposite, font);
1854
		idCombo.setFont(font);
2150
			getShell().layout(true);
1855
		idCombo.addSelectionListener(new SelectionListener() {
2151
			getShell().redraw();
1856
			public void widgetDefaultSelected(SelectionEvent e) {
2152
		}
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
	}
2153
	}
1883
2154
1884
	/**
2155
	/**
Lines 1904-1923 Link Here
1904
	 */
2175
	 */
1905
	private void createModeArea(Font font, Composite composite) {
2176
	private void createModeArea(Font font, Composite composite) {
1906
		GridData data;
2177
		GridData data;
1907
		Group modeComposite = createGroup(font, composite, NLS.bind(
2178
		Composite modeComposite = createGroup(font, composite, NLS.bind(
1908
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2179
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, null), false, true, 2);
1909
				null), false);
1910
		String[] modes = FilterTypeUtil.getModes();
2180
		String[] modes = FilterTypeUtil.getModes();
1911
		includeButton = new Button(modeComposite, SWT.RADIO);
2181
		includeButton = new Button(modeComposite, SWT.RADIO);
1912
		includeButton.setText(modes[0]);
2182
		includeButton.setText(modes[0]);
1913
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
2183
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
1914
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2184
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1915
		includeButton.setLayoutData(data);
2185
		includeButton.setLayoutData(data);
1916
		includeButton.setFont(font);
2186
		includeButton.setFont(font);
1917
		includeButton.addSelectionListener(new SelectionListener() {
2187
		includeButton.addSelectionListener(new SelectionAdapter() {
1918
			public void widgetDefaultSelected(SelectionEvent e) {
1919
			}
1920
1921
			public void widgetSelected(SelectionEvent e) {
2188
			public void widgetSelected(SelectionEvent e) {
1922
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2189
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1923
						new Integer(0));
2190
						new Integer(0));
Lines 1928-1940 Link Here
1928
		excludeButton = new Button(modeComposite, SWT.RADIO);
2195
		excludeButton = new Button(modeComposite, SWT.RADIO);
1929
		excludeButton.setText(modes[1]);
2196
		excludeButton.setText(modes[1]);
1930
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
2197
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
1931
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2198
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1932
		excludeButton.setLayoutData(data);
2199
		excludeButton.setLayoutData(data);
1933
		excludeButton.setFont(font);
2200
		excludeButton.setFont(font);
1934
		excludeButton.addSelectionListener(new SelectionListener() {
2201
		excludeButton.addSelectionListener(new SelectionAdapter() {
1935
			public void widgetDefaultSelected(SelectionEvent e) {
1936
			}
1937
1938
			public void widgetSelected(SelectionEvent e) {
2202
			public void widgetSelected(SelectionEvent e) {
1939
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2203
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1940
						new Integer(1));
2204
						new Integer(1));
Lines 1942-1948 Link Here
1942
		});
2206
		});
1943
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
2207
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1944
				filter, FilterTypeUtil.MODE)).intValue() == 1);
2208
				filter, FilterTypeUtil.MODE)).intValue() == 1);
1945
		createInheritableArea(font, modeComposite);
1946
	}
2209
	}
1947
2210
1948
	/**
2211
	/**
Lines 1950-1967 Link Here
1950
	 * @param composite
2213
	 * @param composite
1951
	 * @return the group
2214
	 * @return the group
1952
	 */
2215
	 */
1953
	private Group createGroup(Font font, Composite composite, String text,
2216
	private Composite createGroup(Font font, Composite composite, String text,
1954
			boolean grabExcessVerticalSpace) {
2217
			boolean grabExcessVerticalSpace, boolean group, int columnCounts) {
1955
		GridLayout layout;
2218
		GridLayout layout;
1956
		GridData data;
2219
		GridData data;
1957
		Group modeComposite = new Group(composite, SWT.NONE);
2220
		Composite modeComposite;
1958
		modeComposite.setText(text);
2221
		if (group) { 
2222
			Group modeGroup = new Group(composite, SWT.NONE);
2223
			modeGroup.setText(text);
2224
			modeComposite = modeGroup;
2225
		} else {
2226
			modeComposite = new Composite(composite, SWT.NONE);
2227
		}
1959
		layout = new GridLayout();
2228
		layout = new GridLayout();
1960
		layout.numColumns = 1;
2229
		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);
2230
		modeComposite.setLayout(layout);
1966
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
2231
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
1967
		modeComposite.setLayoutData(data);
2232
		modeComposite.setLayoutData(data);
Lines 1975-2028 Link Here
1975
	 */
2240
	 */
1976
	private void createTargetArea(Font font, Composite composite) {
2241
	private void createTargetArea(Font font, Composite composite) {
1977
		GridData data;
2242
		GridData data;
1978
		Group targetComposite = createGroup(font, composite, NLS.bind(
2243
		Composite targetComposite = createGroup(font, composite, new String(), false, true, 3);
1979
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
1980
				null), false);
1981
2244
1982
		String[] targets = FilterTypeUtil.getTargets();
2245
		String[] targets = FilterTypeUtil.getTargets();
1983
		filesButton = new Button(targetComposite, SWT.RADIO);
2246
		filesButton = new Button(targetComposite, SWT.RADIO);
1984
		filesButton.setText(targets[0]);
2247
		filesButton.setText(targets[0]);
1985
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
2248
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
1986
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2249
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1987
		filesButton.setLayoutData(data);
2250
		filesButton.setLayoutData(data);
1988
		filesButton.setFont(font);
2251
		filesButton.setFont(font);
1989
2252
1990
		foldersButton = new Button(targetComposite, SWT.RADIO);
2253
		foldersButton = new Button(targetComposite, SWT.RADIO);
1991
		foldersButton.setText(targets[1]);
2254
		foldersButton.setText(targets[1]);
1992
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
2255
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
1993
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2256
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1994
		foldersButton.setLayoutData(data);
2257
		foldersButton.setLayoutData(data);
1995
		foldersButton.setFont(font);
2258
		foldersButton.setFont(font);
1996
2259
1997
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
2260
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
1998
		filesAndFoldersButton.setText(targets[2]);
2261
		filesAndFoldersButton.setText(targets[2]);
1999
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2262
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2000
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2263
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2001
		filesAndFoldersButton.setLayoutData(data);
2264
		filesAndFoldersButton.setLayoutData(data);
2002
		filesAndFoldersButton.setFont(font);
2265
		filesAndFoldersButton.setFont(font);
2003
2266
2004
		filesButton.addSelectionListener(new SelectionListener() {
2267
		filesButton.addSelectionListener(new SelectionAdapter() {
2005
			public void widgetDefaultSelected(SelectionEvent e) {
2006
			}
2007
2008
			public void widgetSelected(SelectionEvent e) {
2268
			public void widgetSelected(SelectionEvent e) {
2009
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2269
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2010
						new Integer(0));
2270
						new Integer(0));
2011
			}
2271
			}
2012
		});
2272
		});
2013
		foldersButton.addSelectionListener(new SelectionListener() {
2273
		foldersButton.addSelectionListener(new SelectionAdapter() {
2014
			public void widgetDefaultSelected(SelectionEvent e) {
2015
			}
2016
2017
			public void widgetSelected(SelectionEvent e) {
2274
			public void widgetSelected(SelectionEvent e) {
2018
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2275
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2019
						new Integer(1));
2276
						new Integer(1));
2020
			}
2277
			}
2021
		});
2278
		});
2022
		filesAndFoldersButton.addSelectionListener(new SelectionListener() {
2279
		filesAndFoldersButton.addSelectionListener(new SelectionAdapter() {
2023
			public void widgetDefaultSelected(SelectionEvent e) {
2024
			}
2025
2026
			public void widgetSelected(SelectionEvent e) {
2280
			public void widgetSelected(SelectionEvent e) {
2027
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2281
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2028
						new Integer(2));
2282
						new Integer(2));
Lines 2036-2053 Link Here
2036
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2290
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2037
	}
2291
	}
2038
2292
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) {
2293
	protected Control createContents(Composite parent) {
2052
		Control control = super.createContents(parent);
2294
		Control control = super.createContents(parent);
2053
		initialize();
2295
		initialize();
Lines 2082-2089 Link Here
2082
		if (filter.hasStringArguments()) {
2324
		if (filter.hasStringArguments()) {
2083
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2325
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2084
			if (desc != null) {
2326
			if (desc != null) {
2085
				AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2086
				try {
2327
				try {
2328
					currentCustomFilterArgumentUI.validate();
2329
					AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2087
					matcher.initialize(resource.getProject(), filter.getArguments());
2330
					matcher.initialize(resource.getProject(), filter.getArguments());
2088
				} catch (CoreException e) {
2331
				} catch (CoreException e) {
2089
					IWorkbenchWindow window = PlatformUI.getWorkbench()
2332
					IWorkbenchWindow window = PlatformUI.getWorkbench()
Lines 2099-2102 Link Here
2099
2342
2100
		super.okPressed();
2343
		super.okPressed();
2101
	}
2344
	}
2345
}
2346
2347
interface ICustomFilterArgumentUI {
2348
2349
	/**
2350
	 * @return the descriptor ID
2351
	 */
2352
	Object getID();
2353
2354
	/**
2355
	 * @param filter
2356
	 * @param fPlainStyler
2357
	 * @param fBoldStyler
2358
	 * @return
2359
	 */
2360
	StyledString formatStyledText(FilterCopy filter, Styler fPlainStyler,
2361
			Styler fBoldStyler);
2362
2363
	/**
2364
	 * @throws CoreException 
2365
	 * 
2366
	 */
2367
	void validate() throws CoreException;
2368
2369
	/**
2370
	 * 
2371
	 */
2372
	void selectionChanged();
2373
2374
	/**
2375
	 * @param argumentComposite
2376
	 * @param font
2377
	 */
2378
	void create(Composite argumentComposite, Font font);
2379
2380
	/**
2381
	 * 
2382
	 */
2383
	void dispose();
2384
	
2385
}
2386
2387
class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2388
2389
	Shell shell;
2390
	FilterCopy filter;
2391
	protected Button argumentsCaseSensitive;
2392
	protected Button argumentsRegularExpresion;
2393
	protected Text arguments;
2394
	protected DateTime argumentsDate;
2395
	protected Combo argumentsBoolean;
2396
	protected Label argumentsLabel;
2397
	protected Label description;
2398
	protected ContentAssistCommandAdapter fContentAssistField;
2399
	protected Combo multiKey;
2400
	protected Combo multiOperator;
2401
	protected Composite multiArgumentComposite;
2402
	protected Composite stringArgumentComposite;
2403
	protected Composite attributeStringArgumentComposite;
2404
	protected Class intiantiatedKeyOperatorType = null;
2405
	protected TreeMap/* <String, String>*/ valueCache = new TreeMap();
2406
	
2407
	/**
2408
	 * @param parentShell
2409
	 * @param filter
2410
	 */
2411
	public MultiMatcherCustomFilterArgumentUI(Shell parentShell,
2412
			FilterCopy filter) {
2413
		this.shell = parentShell;
2414
		this.filter = filter;
2415
	}
2416
2417
	/* (non-Javadoc)
2418
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2419
	 */
2420
	public Object getID() {
2421
		return MultiMatcher.ID;
2422
	}
2423
2424
	/* (non-Javadoc)
2425
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2426
	 */
2427
	public void dispose() {
2428
		Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description};
2429
		for (int i = 0; i < list.length; i++) {
2430
			if (list[i] != null) {
2431
				list[i].dispose();
2432
			}
2433
		}
2434
		multiKey = null;
2435
		multiOperator = null;
2436
		multiArgumentComposite = null;
2437
		arguments = null;
2438
		argumentsLabel = null;
2439
		fContentAssistField = null;
2440
		intiantiatedKeyOperatorType = null;
2441
		stringArgumentComposite = null;
2442
		argumentsCaseSensitive = null;
2443
		argumentsRegularExpresion = null;
2444
		attributeStringArgumentComposite = null;
2445
		description = null;
2446
	}
2447
2448
	/* (non-Javadoc)
2449
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2450
	 */
2451
	public void create(Composite argumentComposite, Font font) {
2452
		shell = argumentComposite.getShell();
2453
		GridLayout layout = new GridLayout();
2454
		layout.numColumns = 3;
2455
		layout.marginWidth = 0;
2456
		argumentComposite.setLayout(layout);
2457
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2458
		argumentComposite.setLayoutData(data);
2459
		argumentComposite.setFont(font);
2460
		createCustomArgumentsArea(font, argumentComposite);
2461
		argumentComposite.layout(true);
2462
		createDescriptionArea(font, argumentComposite);
2463
	}
2464
	
2465
	/**
2466
	 * @param font
2467
	 * @param composite
2468
	 */
2469
	private void createDescriptionArea(Font font, Composite composite) {
2470
		GridData data;
2471
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2472
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2473
		data.widthHint = 300;
2474
		data.heightHint = 40;
2475
		data.horizontalSpan = 3;
2476
		description.setLayoutData(data);
2477
		description.setFont(font);
2478
		setupDescriptionText();
2479
	}
2480
2481
	private void setupDescriptionText() {
2482
		if (description != null) {
2483
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2484
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2485
			Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2486
			description.setText(new String());
2487
			if (selectedKeyOperatorType.equals(String.class)) {
2488
				if (!argumentsRegularExpresion.getSelection())
2489
					description.setText(NLS.bind(
2490
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null));
2491
			}
2492
			if (selectedKeyOperatorType.equals(Integer.class)) {
2493
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2494
					description.setText(NLS.bind(
2495
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_TimeInterval, null));
2496
				else
2497
				description.setText(NLS.bind(
2498
						IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null));
2499
			}
2500
		}
2501
	}
2502
	
2503
	private void createCustomArgumentsArea(Font font, Composite composite) {
2504
		GridData data;
2505
		multiKey = new Combo(composite, SWT.READ_ONLY);
2506
		multiKey.setItems(getMultiMatcherKeys());
2507
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2508
		multiKey.setLayoutData(data);
2509
		multiKey.setFont(font);
2510
		multiKey.addSelectionListener(new SelectionAdapter() {
2511
			public void widgetSelected(SelectionEvent e) {
2512
				setupMultiOperatorAndField(true);
2513
				storeMultiSelection();
2514
			}
2515
		});
2516
2517
		multiOperator = new Combo(composite, SWT.READ_ONLY);
2518
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2519
		multiOperator.setLayoutData(data);
2520
		multiOperator.setFont(font);
2521
		multiOperator.addSelectionListener(new SelectionAdapter() {
2522
			public void widgetSelected(SelectionEvent e) {
2523
				setupMultiOperatorAndField(false);
2524
				storeMultiSelection();
2525
			}
2526
		});
2527
		
2528
		multiArgumentComposite = new Composite(composite, SWT.NONE);
2529
		
2530
		GridLayout layout = new GridLayout();
2531
		layout.numColumns = 1;
2532
		layout.marginWidth = 0;
2533
		layout.horizontalSpacing = 0;
2534
		layout.verticalSpacing = 0;
2535
		layout.marginBottom = 0;
2536
		layout.marginHeight = 0;
2537
		multiArgumentComposite.setLayout(layout);
2538
		data = new GridData(SWT.FILL, SWT.TOP, true, true);
2539
		multiArgumentComposite.setLayoutData(data);
2540
		multiArgumentComposite.setFont(font);
2541
2542
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2543
		String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key);
2544
		int index = multiKey.indexOf(local);
2545
		if (index != -1)
2546
			multiKey.select(index);
2547
		else
2548
			multiKey.select(0);
2549
		
2550
		setupMultiOperatorAndField(true);
2551
	}
2552
2553
	private void setupMultiOperatorAndField(boolean updateOperator) {
2554
		boolean isUsingRegularExpression = false;
2555
		String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2556
		if (updateOperator) {
2557
			String[] operators = getLocalOperatorsForKey(selectedKey);
2558
			multiOperator.setItems(operators);
2559
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2560
			String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
2561
			int index = multiOperator.indexOf(local);
2562
			if (index != -1)
2563
				multiOperator.select(index);
2564
			else
2565
				multiOperator.select(0);
2566
		}
2567
		String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2568
		
2569
		Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2570
		
2571
		if (intiantiatedKeyOperatorType != null) {
2572
			if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType))
2573
				return;
2574
			if (arguments != null) {
2575
				arguments.dispose();
2576
				arguments = null;
2577
			}
2578
			if (attributeStringArgumentComposite != null) {
2579
				attributeStringArgumentComposite.dispose();
2580
				attributeStringArgumentComposite = null;
2581
			}
2582
			if (stringArgumentComposite != null) {
2583
				stringArgumentComposite.dispose();
2584
				stringArgumentComposite = null;
2585
			}
2586
			if (argumentsBoolean != null) {
2587
				argumentsBoolean.dispose();
2588
				argumentsBoolean = null;
2589
			}
2590
			if (argumentsDate != null) {
2591
				argumentsDate.dispose();
2592
				argumentsDate = null;
2593
			}
2594
			if (argumentsRegularExpresion != null) {
2595
				argumentsRegularExpresion.dispose();
2596
				argumentsRegularExpresion = null;
2597
			}
2598
			if (argumentsCaseSensitive != null) {
2599
				argumentsCaseSensitive.dispose();
2600
				argumentsCaseSensitive = null;
2601
			}
2602
			fContentAssistField = null;
2603
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2604
			valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern);
2605
			argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName());
2606
			if (argument.pattern == null)
2607
				argument.pattern = new String();
2608
			filter.setArguments(MultiMatcher.encodeArguments(argument));
2609
		}
2610
		if (selectedKeyOperatorType.equals(String.class)) {
2611
			stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);
2612
			
2613
			GridData data;
2614
			GridLayout layout = new GridLayout();
2615
			layout.numColumns = 2;
2616
			layout.marginWidth = 0;
2617
			layout.horizontalSpacing = 0;
2618
			layout.verticalSpacing = 0;
2619
			layout.marginBottom = 0;
2620
			layout.marginHeight = 0;
2621
			stringArgumentComposite.setLayout(layout);
2622
			data = new GridData(SWT.FILL, SWT.TOP, true, true);
2623
			stringArgumentComposite.setLayoutData(data);
2624
			stringArgumentComposite.setFont(multiArgumentComposite.getFont());
2625
2626
			arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER);
2627
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2628
			data.minimumWidth = 100;
2629
			arguments.setLayoutData(data);
2630
			arguments.setFont(stringArgumentComposite.getFont());
2631
	
2632
			attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE);
2633
			
2634
			layout = new GridLayout();
2635
			layout.numColumns = 1;
2636
			layout.marginWidth = 0;
2637
			layout.horizontalSpacing = 0;
2638
			layout.verticalSpacing = 0;
2639
			layout.marginBottom = 0;
2640
			layout.marginHeight = 0;
2641
			attributeStringArgumentComposite.setLayout(layout);
2642
			data = new GridData(SWT.FILL, SWT.TOP, false, true);
2643
			attributeStringArgumentComposite.setLayoutData(data);
2644
			attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont());
2645
2646
			argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK);
2647
			argumentsCaseSensitive.setText(NLS.bind(
2648
					IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
2649
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2650
			data.minimumWidth = 100;
2651
			argumentsCaseSensitive.setLayoutData(data);
2652
			argumentsCaseSensitive.setFont(stringArgumentComposite.getFont());
2653
2654
			argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK);
2655
			argumentsRegularExpresion.setText(NLS.bind(
2656
					IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
2657
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2658
			data.minimumWidth = 100;
2659
			argumentsRegularExpresion.setLayoutData(data);
2660
			argumentsRegularExpresion.setFont(stringArgumentComposite.getFont());
2661
2662
			if (filter.hasStringArguments()) {
2663
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2664
				arguments.setText(argument.pattern);
2665
				isUsingRegularExpression = argument.regularExpression;
2666
				argumentsCaseSensitive.setSelection(argument.caseSensitive);
2667
				argumentsRegularExpresion.setSelection(argument.regularExpression);
2668
			}
2669
2670
			arguments.addModifyListener(new ModifyListener() {
2671
				public void modifyText(ModifyEvent e) {
2672
					storeMultiSelection();
2673
				}
2674
			});
2675
			argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
2676
				public void widgetSelected(SelectionEvent e) {
2677
					setupDescriptionText();
2678
					storeMultiSelection();
2679
					if (fContentAssistField != null)
2680
						fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
2681
				}
2682
			});
2683
			argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
2684
				public void widgetSelected(SelectionEvent e) {
2685
					storeMultiSelection();
2686
				}
2687
			});
2688
2689
			TextContentAdapter contentAdapter= new TextContentAdapter();
2690
			FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2691
			fContentAssistField= new ContentAssistCommandAdapter(
2692
					arguments,
2693
					contentAdapter,
2694
					findProposer, 
2695
					null,
2696
					new char[] {'\\', '[', '('},
2697
					true);
2698
		}
2699
		if (selectedKeyOperatorType.equals(Integer.class)) {
2700
			GridData data;
2701
			arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
2702
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2703
			data.minimumWidth = 100;
2704
			arguments.setLayoutData(data);
2705
			arguments.setFont(multiArgumentComposite.getFont());
2706
2707
			if (filter.hasStringArguments()) {
2708
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2709
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2710
					arguments.setText(convertToEditableTimeInterval(argument.pattern));
2711
				else
2712
					arguments.setText(convertToEditableLength(argument.pattern));
2713
			}
2714
			
2715
			arguments.addModifyListener(new ModifyListener() {
2716
				public void modifyText(ModifyEvent e) {
2717
					storeMultiSelection();
2718
				}
2719
			});
2720
		}
2721
		if (selectedKeyOperatorType.equals(Date.class)) {
2722
			GridData data;
2723
			argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM);
2724
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2725
			argumentsDate.setLayoutData(data);
2726
			argumentsDate.setFont(multiArgumentComposite.getFont());
2727
			argumentsDate.addSelectionListener(new SelectionAdapter() {
2728
				public void widgetSelected(SelectionEvent e) {
2729
					storeMultiSelection();
2730
				}
2731
			});
2732
			if (filter.hasStringArguments()) {
2733
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2734
				Date date; 
2735
				Calendar calendar = Calendar.getInstance();
2736
				try {
2737
					date = new Date(Long.parseLong(argument.pattern));
2738
					calendar.setTime(date);
2739
				} catch (NumberFormatException e1) {
2740
					date = new Date();
2741
					calendar.setTime(date);
2742
					argument.pattern = Long.toString(calendar.getTimeInMillis());
2743
				}
2744
				argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
2745
				argumentsDate.setMonth(calendar.get(Calendar.MONTH));
2746
				argumentsDate.setYear(calendar.get(Calendar.YEAR));
2747
			}
2748
		}
2749
		if (selectedKeyOperatorType.equals(Boolean.class)) {
2750
			GridData data;
2751
			argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
2752
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2753
			argumentsBoolean.setLayoutData(data);
2754
			argumentsBoolean.setFont(multiArgumentComposite.getFont());
2755
			argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())});
2756
			argumentsBoolean.addSelectionListener(new SelectionAdapter() {
2757
				public void widgetSelected(SelectionEvent e) {
2758
					storeMultiSelection();
2759
				}
2760
			});
2761
			if (filter.hasStringArguments()) {
2762
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2763
				if (argument.pattern.length() == 0)
2764
					argumentsBoolean.select(0);
2765
				else
2766
					argumentsBoolean.select(Boolean.valueOf(argument.pattern).booleanValue() ? 0:1);
2767
			}
2768
		}
2769
		multiArgumentComposite.layout(true);
2770
		intiantiatedKeyOperatorType = selectedKeyOperatorType;
2771
		
2772
		if (fContentAssistField != null)
2773
			fContentAssistField.setEnabled(isUsingRegularExpression);
2774
2775
		shell.layout(true);
2776
		shell.redraw();
2777
		setupDescriptionText();
2778
	}
2779
2780
	private String[] timeIntervalPrefixes = {"s", "m", "h", "d"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
2781
	private double[] timeIntervalScale = {60, 60, 24};
2782
2783
	private String convertToEditableTimeInterval(String string) {
2784
		if (string.length() == 0)
2785
			return string;
2786
		long value;
2787
		try {
2788
			value = Long.parseLong(string);
2789
		} catch (NumberFormatException e) {
2790
			value = 0;
2791
		}
2792
		if (value == 0)
2793
			return Long.toString(0);
2794
		for (int i = 0; i < timeIntervalPrefixes.length - 1; i++) {
2795
			if (value % timeIntervalScale[i] != 0)
2796
				return Long.toString(value) + timeIntervalPrefixes[i];
2797
			value /= timeIntervalScale[i];
2798
		}
2799
		return Long.toString(value) + timeIntervalPrefixes[timeIntervalPrefixes.length - 1];
2800
	}
2801
2802
	private String convertFromEditableTimeInterval(String string) {
2803
		if (string.length() == 0)
2804
			return string;
2805
		for (int i = 1; i < timeIntervalPrefixes.length; i++) {
2806
			if (string.endsWith(timeIntervalPrefixes[i])) {
2807
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2808
				for (int j = 0; j < i; j++)
2809
					value *= timeIntervalScale[j];
2810
				return Long.toString(value);
2811
			}
2812
		}
2813
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2814
		return Long.toString(Long.parseLong(string));
2815
	}
2816
2817
2818
	private String[] lengthPrefixes = {new String(), "k", "m", "g"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
2819
2820
	// converts "32768" to "32k"
2821
	private String convertToEditableLength(String string) {
2822
		if (string.length() == 0)
2823
			return string;
2824
		long value;
2825
		try {
2826
			value = Long.parseLong(string);
2827
		} catch (NumberFormatException e) {
2828
			value = 0;
2829
		}
2830
		if (value == 0)
2831
			return Long.toString(0);
2832
		for (int i = 0; i < lengthPrefixes.length; i++) {
2833
			if (value % 1024 != 0)
2834
				return Long.toString(value) + lengthPrefixes[i];
2835
			if ((i + 1) < lengthPrefixes.length)
2836
				value /= 1024;
2837
		}
2838
		return Long.toString(value) + lengthPrefixes[lengthPrefixes.length - 1];
2839
	}
2840
	
2841
	// converts "32k" to "32768"
2842
	private String convertFromEditableLength(String string) throws NumberFormatException {
2843
		if (string.length() == 0)
2844
			return string;
2845
		for (int i = 1; i < lengthPrefixes.length; i++) {
2846
			if (string.endsWith(lengthPrefixes[i])) {
2847
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2848
				value *= Math.pow(1024, i);
2849
				return Long.toString(value);
2850
			}
2851
		}
2852
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2853
		return Long.toString(Long.parseLong(string));
2854
	}
2855
	
2856
	private void storeMultiSelection() {
2857
		if (intiantiatedKeyOperatorType != null) {
2858
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2859
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2860
	
2861
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2862
			argument.key = selectedKey;
2863
			argument.operator = selectedOperator;
2864
			
2865
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2866
				Calendar calendar = Calendar.getInstance();
2867
				calendar.set(argumentsDate.getYear(), argumentsDate.getMonth(), argumentsDate.getDay());
2868
				argument.pattern = Long.toString(calendar.getTimeInMillis());
2869
			}
2870
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2871
				argument.pattern = arguments.getText();
2872
				if (argumentsRegularExpresion != null)
2873
					argument.regularExpression = argumentsRegularExpresion.getSelection();
2874
				if (argumentsCaseSensitive != null)
2875
					argument.caseSensitive = argumentsCaseSensitive.getSelection();
2876
			}
2877
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2878
				try {
2879
					if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2880
						argument.pattern = convertFromEditableTimeInterval(arguments.getText());
2881
					else
2882
						argument.pattern = convertFromEditableLength(arguments.getText());
2883
				} catch (NumberFormatException e) {
2884
					argument.pattern = arguments.getText();
2885
				}
2886
			}
2887
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null)
2888
				argument.pattern = MultiMatcherLocalization.getMultiMatcherKey(argumentsBoolean.getText());
2889
			String encodedArgument = MultiMatcher.encodeArguments(argument);
2890
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument);
2891
		}
2892
	}
2893
2894
	private String[] getLocalOperatorsForKey(String key) {
2895
		String [] operators = MultiMatcher.getOperatorsForKey(key);
2896
		String[] result = new String[operators.length];
2897
		for (int i = 0; i < operators.length; i++)
2898
			result[i] = MultiMatcherLocalization.getLocalMultiMatcherKey(operators[i]);
2899
		return result;
2900
	}
2901
2902
	private String[] getMultiMatcherKeys() {
2903
		ArrayList list = new ArrayList();
2904
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_NAME));
2905
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_PROPJECT_RELATIVE_PATH));
2906
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LOCATION));
2907
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LAST_MODIFIED));
2908
		if (MultiMatcher.supportCreatedKey())
2909
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_CREATED));
2910
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LENGTH));
2911
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_READONLY));
2912
		if (!Platform.getOS().equals(Platform.OS_WIN32))
2913
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_SYMLINK));
2914
		return (String []) list.toArray(new String[0]);
2915
	}
2916
2917
	/* (non-Javadoc)
2918
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
2919
	 */
2920
	public void selectionChanged() {
2921
	}
2922
2923
	/**
2924
	 * @throws CoreException  
2925
	 */
2926
	/* (non-Javadoc)
2927
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
2928
	 */
2929
	public void validate() throws CoreException {
2930
		if (intiantiatedKeyOperatorType != null) {
2931
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2932
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2933
	
2934
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2935
			argument.key = selectedKey;
2936
			argument.operator = selectedOperator;
2937
			
2938
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2939
			}
2940
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2941
			}
2942
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2943
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) {
2944
					try {
2945
						convertFromEditableTimeInterval(arguments.getText());
2946
					} catch (NumberFormatException e) {
2947
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2948
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidTimeInterval, arguments.getText()), e));
2949
					}
2950
				}
2951
				else {
2952
					try {
2953
						convertFromEditableLength(arguments.getText());
2954
					} catch (NumberFormatException e) {
2955
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2956
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidFileLength, arguments.getText()), e));
2957
					}
2958
				}
2959
			}
2960
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) {
2961
				
2962
			}
2963
		}
2964
	}
2965
2966
	/* (non-Javadoc)
2967
	 * @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)
2968
	 */
2969
	public StyledString formatStyledText(FilterCopy filter,
2970
			Styler fPlainStyler, Styler fBoldStyler) {
2971
		return new StyledString(formatMultiMatcherArgument(filter), fPlainStyler);
2972
	}
2973
2974
	private String formatMultiMatcherArgument(FilterCopy filter) {
2975
		String argumentString = (String) filter.getArguments();
2976
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments(argumentString);
2977
		
2978
		StringBuffer builder = new StringBuffer();
2979
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key));
2980
		builder.append(' ');
2981
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator));
2982
		builder.append(' ');
2983
		Class type = MultiMatcher.getTypeForKey(argument.key, argument.operator);
2984
		if (type.equals(String.class))
2985
			builder.append(argument.pattern);
2986
		if (type.equals(Boolean.class))
2987
			builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.pattern));
2988
		if (type.equals(Integer.class)) {
2989
			if (argument.key.equals(MultiMatcher.KEY_LAST_MODIFIED) || argument.key.equals(MultiMatcher.KEY_CREATED))
2990
				builder.append(convertToEditableTimeInterval(argument.pattern));
2991
			else
2992
				builder.append(convertToEditableLength(argument.pattern));
2993
		}
2994
		if (type.equals(Date.class))
2995
			builder.append(DateFormat.getDateInstance().format(new Date(Long.parseLong(argument.pattern))));
2996
		
2997
		return builder.toString();
2998
	}
2999
}
3000
3001
class DefaultCustomFilterArgumentUI implements ICustomFilterArgumentUI {
3002
3003
	Shell shell;
3004
	FilterCopy filter;
3005
	protected Text arguments;
3006
	protected Label argumentsLabel;
3007
	protected Label description;
3008
	protected ContentAssistCommandAdapter fContentAssistField;
3009
3010
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilterMatcher"; //$NON-NLS-1$
3011
3012
	/**
3013
	 * @param parentShell
3014
	 * @param filter
3015
	 */
3016
	public DefaultCustomFilterArgumentUI(Shell parentShell, FilterCopy filter) {
3017
		this.shell = parentShell;
3018
		this.filter = filter;
3019
	}
3020
3021
	/* (non-Javadoc)
3022
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
3023
	 */
3024
	public Object getID() {
3025
		return new String();
3026
	}
3027
3028
	/* (non-Javadoc)
3029
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
3030
	 */
3031
	public void dispose() {
3032
		Widget list[] = new Widget[] {arguments, argumentsLabel, description};
3033
		for (int i = 0; i < list.length; i++) {
3034
			if (list[i] != null) {
3035
				list[i].dispose();
3036
			}
3037
		}
3038
		arguments = null;
3039
		argumentsLabel = null;
3040
		fContentAssistField = null;
3041
		description = null;
3042
	}
3043
3044
	/* (non-Javadoc)
3045
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
3046
	 */
3047
	public void create(Composite argumentComposite, Font font) {
3048
		shell = argumentComposite.getShell();
3049
		GridLayout layout = new GridLayout();
3050
		layout.numColumns = 2;
3051
		layout.marginWidth = 0;
3052
		argumentComposite.setLayout(layout);
3053
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
3054
		argumentComposite.setLayoutData(data);
3055
		argumentComposite.setFont(font);
3056
		if (filter.hasStringArguments())
3057
			createArgumentsArea(font, argumentComposite);
3058
3059
		createDescriptionArea(font, argumentComposite);
3060
3061
		if (fContentAssistField != null)
3062
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3063
		argumentComposite.layout(true);
3064
	}
3065
	
3066
	private void createArgumentsArea(Font font, Composite composite) {
3067
		GridData data;
3068
		argumentsLabel = addLabel(composite, NLS.bind(
3069
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTarget,
3070
				null));
3071
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
3072
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
3073
		arguments.setLayoutData(data);
3074
		arguments.setFont(font);
3075
		arguments.addModifyListener(new ModifyListener() {
3076
			public void modifyText(ModifyEvent e) {
3077
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
3078
						arguments.getText());
3079
			}
3080
		});
3081
		if (filter.hasStringArguments())
3082
			arguments.setText((String) FilterTypeUtil.getValue(filter,
3083
					FilterTypeUtil.ARGUMENTS));
3084
		arguments.setEnabled(filter.hasStringArguments());
3085
		setArgumentLabelEnabled();
3086
3087
		TextContentAdapter contentAdapter= new TextContentAdapter();
3088
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
3089
		fContentAssistField= new ContentAssistCommandAdapter(
3090
				arguments,
3091
				contentAdapter,
3092
				findProposer, 
3093
				null,
3094
				new char[] {'\\', '[', '('},
3095
				true);
3096
	}
3097
3098
	private void setArgumentLabelEnabled() {
3099
		if (argumentsLabel != null) {
3100
			Color color = argumentsLabel.getDisplay().getSystemColor(
3101
					filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
3102
			argumentsLabel.setForeground(color);
3103
		}
3104
	}
3105
3106
	Label addLabel(Composite composite, String text) {
3107
		String delimiter = ":"; //$NON-NLS-1$
3108
3109
		Font font = composite.getFont();
3110
		Label label = new Label(composite, SWT.LEFT);
3111
		label.setText(text + delimiter);
3112
		GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
3113
		label.setLayoutData(data);
3114
		label.setFont(font);
3115
		return label;
3116
	}
3117
3118
	/* (non-Javadoc)
3119
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
3120
	 */
3121
	public void selectionChanged() {
3122
		if (arguments != null)
3123
			arguments.setEnabled(filter.hasStringArguments());
3124
		setArgumentLabelEnabled();
3125
		if (fContentAssistField != null)
3126
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3127
		description.setText(FilterTypeUtil
3128
				.getDescriptor(filter.getId()).getDescription());
3129
	}
3130
3131
	/**
3132
	 * @param font
3133
	 * @param composite
3134
	 */
3135
	private void createDescriptionArea(Font font, Composite composite) {
3136
		GridData data;
3137
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
3138
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
3139
				.getDescription());
3140
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
3141
		data.widthHint = 300;
3142
		data.heightHint = 40;
3143
		data.horizontalSpan = 2;
3144
		description.setLayoutData(data);
3145
		description.setFont(font);
3146
	}
3147
3148
	/**
3149
	 * @throws CoreException  
3150
	 */
3151
	/* (non-Javadoc)
3152
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
3153
	 */
3154
	public void validate() throws CoreException {
3155
		// nothing
3156
	}
3157
3158
	/* (non-Javadoc)
3159
	 * @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)
3160
	 */
3161
	public StyledString formatStyledText(FilterCopy filter,
3162
			Styler fPlainStyler, Styler fBoldStyler) {
3163
		return new StyledString(filter.getArguments() != null ? filter
3164
					.getArguments().toString() : new String(), fPlainStyler);
3165
	}
3166
}
3167
3168
class MultiMatcherLocalization {
3169
	
3170
	static String[][] multiMatcherKey = {
3171
			{MultiMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName},
3172
			{MultiMatcher.KEY_PROPJECT_RELATIVE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyProjectRelativePath},
3173
			{MultiMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation},
3174
			{MultiMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified},
3175
			{MultiMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated},
3176
			{MultiMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength},
3177
			{MultiMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly},
3178
			{MultiMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink},
3179
			{MultiMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter},
3180
			{MultiMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore},
3181
			{MultiMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals},
3182
			{MultiMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches},
3183
			{MultiMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan},
3184
			{MultiMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan},
3185
			{MultiMatcher.OPERATOR_WITHIN, IDEWorkbenchMessages.ResourceFilterPage_multiWithin},
3186
			{Boolean.TRUE.toString(), IDEWorkbenchMessages.ResourceFilterPage_true},
3187
			{Boolean.FALSE.toString(), IDEWorkbenchMessages.ResourceFilterPage_false}
3188
	};
3189
	
3190
	static public String getLocalMultiMatcherKey(String key) {
3191
		for (int i = 0; i < multiMatcherKey.length; i++) {
3192
			if (multiMatcherKey[i][0].equals(key))
3193
				return multiMatcherKey[i][1];
3194
		}
3195
		return null;
3196
	}
3197
	
3198
	static public String getMultiMatcherKey(String local) {
3199
		for (int i = 0; i < multiMatcherKey.length; i++) {
3200
			if (multiMatcherKey[i][1].equals(local))
3201
				return multiMatcherKey[i][0];
3202
		}
3203
		return null;
3204
	}
3205
	
2102
}
3206
}
(-)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.valueOf(argument.substring(0, index)).booleanValue();
184
		argument = argument.substring(index + 1);
185
		
186
		index = argument.indexOf(DELIMITER);
187
		if (index == -1)
188
			return result;
189
190
		result.regularExpression = Boolean.valueOf(argument.substring(0, index)).booleanValue();
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.valueOf(argument.pattern).booleanValue();
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