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 (+29 lines)
Lines 53-58 Link Here
53
	public static String ResourceFilterPage_title;
53
	public static String ResourceFilterPage_title;
54
	public static String ResourceFilterPage_noResource;
54
	public static String ResourceFilterPage_noResource;
55
	public static String ResourceFilterPage_addButtonLabel;
55
	public static String ResourceFilterPage_addButtonLabel;
56
	public static String ResourceFilterPage_addGroupButtonLabel;
56
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_upButtonLabel;
59
	public static String ResourceFilterPage_upButtonLabel;
Lines 63-68 Link Here
63
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterArguments;
66
	public static String ResourceFilterPage_columnFilterArguments;
67
	public static String ResourceFilterPage_applyRecursivelyToFolderStructure;
68
	public static String ResourceFilterPage_caseSensitive;
69
	public static String ResourceFilterPage_regularExpression;
70
	public static String ResourceFilterPage_multiMatcher_Matcher;
71
	public static String ResourceFilterPage_multiMatcher_FileLength;
72
	public static String ResourceFilterPage_multiMatcher_InvalidFileLength;
66
	public static String ResourceFilterPage_includeOnly;
73
	public static String ResourceFilterPage_includeOnly;
67
	public static String ResourceFilterPage_excludeAll;
74
	public static String ResourceFilterPage_excludeAll;
68
	public static String ResourceFilterPage_includeOnlyColumn;
75
	public static String ResourceFilterPage_includeOnlyColumn;
Lines 77-82 Link Here
77
	public static String ResourceFilterPage_invalidFilterArgument;
84
	public static String ResourceFilterPage_invalidFilterArgument;
78
	public static String ResourceFilterPage_description;
85
	public static String ResourceFilterPage_description;
79
	public static String ResourceFilterPage_addSubFilterActionLabel;
86
	public static String ResourceFilterPage_addSubFilterActionLabel;
87
	public static String ResourceFilterPage_addSubFilterGroupActionLabel;
88
	public static String ResourceFilterPage_removeFilterActionLabel;
89
	public static String ResourceFilterPage_editFilterActionLabel;
90
	public static String ResourceFilterPage_multiKeyName;
91
	public static String ResourceFilterPage_multiKeyWorkspacePath;
92
	public static String ResourceFilterPage_multiKeyLocation;
93
	public static String ResourceFilterPage_multiKeyLastModified;
94
	public static String ResourceFilterPage_multiKeyCreated;
95
	public static String ResourceFilterPage_multiKeyLength;
96
	public static String ResourceFilterPage_multiKeyReadOnly;
97
	public static String ResourceFilterPage_multiKeySymLink;
98
	public static String ResourceFilterPage_multiEquals;
99
	public static String ResourceFilterPage_multiMatches;
100
	public static String ResourceFilterPage_multiLargerThan;
101
	public static String ResourceFilterPage_multiSmallerThan;
102
	public static String ResourceFilterPage_multiBefore;
103
	public static String ResourceFilterPage_multiAfter;
104
	public static String ResourceFilterPage_multiWithin;
105
	public static String ResourceFilterPage_true;
106
	public static String ResourceFilterPage_false;
107
	public static String ResourceFilterPage_columnFilterTypeLabel;
108
	
80
	//
109
	//
81
	//
110
	//
82
	// Copies from org.eclipse.ui.workbench
111
	// Copies from org.eclipse.ui.workbench
(-)src/org/eclipse/ui/internal/ide/messages.properties (-2 / +30 lines)
Lines 573-588 Link Here
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
575
ResourceFilterPage_addButtonLabel=&Add...
575
ResourceFilterPage_addButtonLabel=&Add...
576
ResourceFilterPage_addGroupButtonLabel=Add &Group...
576
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_columnFilterID=T&ype
582
ResourceFilterPage_columnFilterID=T&ype
583
ResourceFilterPage_columnFilterTypeLabel=Match
582
ResourceFilterPage_columnFilterMode=Mode
584
ResourceFilterPage_columnFilterMode=Mode
583
ResourceFilterPage_columnFilterTargets=Target
585
ResourceFilterPage_columnFilterTargets=Applies To
584
ResourceFilterPage_columnFilterInheritable=In&heritable
586
ResourceFilterPage_columnFilterInheritable=In&heritable
585
ResourceFilterPage_columnFilterArguments=&Pattern
587
ResourceFilterPage_columnFilterArguments=&Pattern
588
ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure
589
ResourceFilterPage_caseSensitive=&Case sensitive
590
ResourceFilterPage_regularExpression=Re&gular expression
591
ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \)
592
ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes *g = gigabytes) 
593
ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0}
586
ResourceFilterPage_includeOnly=&Include
594
ResourceFilterPage_includeOnly=&Include
587
ResourceFilterPage_excludeAll=&Exclude
595
ResourceFilterPage_excludeAll=&Exclude
588
ResourceFilterPage_includeOnlyColumn=Include
596
ResourceFilterPage_includeOnlyColumn=Include
Lines 596-602 Link Here
596
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
604
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
597
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
605
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
598
ResourceFilterPage_description=Description
606
ResourceFilterPage_description=Description
599
ResourceFilterPage_addSubFilterActionLabel=Add Condition...
607
ResourceFilterPage_addSubFilterActionLabel=Add &Condition...
608
ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group...
609
ResourceFilterPage_removeFilterActionLabel=&Remove
610
ResourceFilterPage_editFilterActionLabel=&Edit
611
ResourceFilterPage_multiKeyName=Name
612
ResourceFilterPage_multiKeyWorkspacePath=Workspace Path
613
ResourceFilterPage_multiKeyLocation=Location
614
ResourceFilterPage_multiKeyLastModified=Last Modified
615
ResourceFilterPage_multiKeyCreated=Date Created
616
ResourceFilterPage_multiKeyLength=File Length
617
ResourceFilterPage_multiKeyReadOnly=Read Only
618
ResourceFilterPage_multiKeySymLink=Symbolic Link
619
ResourceFilterPage_multiEquals=equals
620
ResourceFilterPage_multiMatches=matches
621
ResourceFilterPage_multiLargerThan=is larger than
622
ResourceFilterPage_multiSmallerThan=is smaller than
623
ResourceFilterPage_multiBefore=is before
624
ResourceFilterPage_multiAfter=is after
625
ResourceFilterPage_multiWithin=is within
626
ResourceFilterPage_true=true
627
ResourceFilterPage_false=false
600
ResourceInfo_folder = Folder
628
ResourceInfo_folder = Folder
601
ResourceInfo_project = Project
629
ResourceInfo_project = Project
602
ResourceInfo_linkedFile = Linked File
630
ResourceInfo_linkedFile = Linked File
(-)src/org/eclipse/ui/internal/ide/dialogs/ConfigurationLogUpdateSection.java (-15 / +15 lines)
Lines 19-27 Link Here
19
19
20
import org.eclipse.equinox.p2.engine.IProfile;
20
import org.eclipse.equinox.p2.engine.IProfile;
21
import org.eclipse.equinox.p2.engine.IProfileRegistry;
21
import org.eclipse.equinox.p2.engine.IProfileRegistry;
22
import org.eclipse.equinox.p2.metadata.IInstallableUnit;
22
//import org.eclipse.equinox.p2.metadata.IInstallableUnit;
23
import org.eclipse.equinox.p2.query.IQueryResult;
23
//import org.eclipse.equinox.p2.query.IQueryResult;
24
import org.eclipse.equinox.p2.query.QueryUtil;
24
//import org.eclipse.equinox.p2.query.QueryUtil;
25
import org.eclipse.osgi.service.resolver.BundleDescription;
25
import org.eclipse.osgi.service.resolver.BundleDescription;
26
import org.eclipse.osgi.service.resolver.PlatformAdmin;
26
import org.eclipse.osgi.service.resolver.PlatformAdmin;
27
import org.eclipse.osgi.service.resolver.State;
27
import org.eclipse.osgi.service.resolver.State;
Lines 68-85 Link Here
68
			// Since this code is only called in the Help -> About -> Configuration Details case we
68
			// Since this code is only called in the Help -> About -> Configuration Details case we
69
			// won't worry too much about performance here and we will sort the query results
69
			// won't worry too much about performance here and we will sort the query results
70
			// afterwards, but before printing them out.
70
			// afterwards, but before printing them out.
71
			IQueryResult result = profile.available(QueryUtil.createIUAnyQuery(), null);
71
//			IQueryResult result = profile.available(QueryUtil.createIUAnyQuery(), null);
72
			SortedSet sorted = new TreeSet();
72
//			SortedSet sorted = new TreeSet();
73
			for (Iterator iter = result.iterator(); iter.hasNext();) {
73
//			for (Iterator iter = result.iterator(); iter.hasNext();) {
74
				IInstallableUnit unit = (IInstallableUnit) iter.next();
74
//				IInstallableUnit unit = (IInstallableUnit) iter.next();
75
				sorted.add(NLS.bind(IDEWorkbenchMessages.ConfigurationLogUpdateSection_IU, unit.getId(), unit.getVersion()));
75
//				sorted.add(NLS.bind(IDEWorkbenchMessages.ConfigurationLogUpdateSection_IU, unit.getId(), unit.getVersion()));
76
			}
76
//			}
77
			if (!sorted.isEmpty()) {
77
//			if (!sorted.isEmpty()) {
78
				writer.println(IDEWorkbenchMessages.ConfigurationLogUpdateSection_IUHeader);
78
//				writer.println(IDEWorkbenchMessages.ConfigurationLogUpdateSection_IUHeader);
79
				writer.println();
79
//				writer.println();
80
				for (Iterator iter = sorted.iterator(); iter.hasNext();)
80
//				for (Iterator iter = sorted.iterator(); iter.hasNext();)
81
					writer.println(iter.next());
81
//					writer.println(iter.next());
82
			}
82
//			}
83
		} finally {
83
		} finally {
84
			context.ungetService(reference);
84
			context.ungetService(reference);
85
		}
85
		}
(-)src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java (-301 / +1122 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.TreeMap;
22
28
23
import org.eclipse.core.internal.resources.FilterDescriptor;
29
import org.eclipse.core.internal.resources.FilterDescriptor;
24
import org.eclipse.core.resources.FileInfoMatcherDescription;
30
import org.eclipse.core.resources.FileInfoMatcherDescription;
Lines 32-62 Link Here
32
import org.eclipse.core.runtime.Assert;
38
import org.eclipse.core.runtime.Assert;
33
import org.eclipse.core.runtime.CoreException;
39
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
40
import org.eclipse.core.runtime.IPath;
41
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.NullProgressMonitor;
42
import org.eclipse.core.runtime.NullProgressMonitor;
43
import org.eclipse.core.runtime.Platform;
44
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.action.Action;
45
import org.eclipse.jface.action.Action;
37
import org.eclipse.jface.action.MenuManager;
46
import org.eclipse.jface.action.MenuManager;
47
import org.eclipse.jface.action.Separator;
38
import org.eclipse.jface.dialogs.Dialog;
48
import org.eclipse.jface.dialogs.Dialog;
39
import org.eclipse.jface.dialogs.ErrorDialog;
49
import org.eclipse.jface.dialogs.ErrorDialog;
40
import org.eclipse.jface.dialogs.IDialogConstants;
50
import org.eclipse.jface.dialogs.IDialogConstants;
41
import org.eclipse.jface.dialogs.TrayDialog;
51
import org.eclipse.jface.dialogs.TrayDialog;
42
import org.eclipse.jface.fieldassist.TextContentAdapter;
52
import org.eclipse.jface.fieldassist.TextContentAdapter;
53
import org.eclipse.jface.layout.TreeColumnLayout;
43
import org.eclipse.jface.resource.ImageDescriptor;
54
import org.eclipse.jface.resource.ImageDescriptor;
44
import org.eclipse.jface.resource.JFaceResources;
55
import org.eclipse.jface.resource.JFaceResources;
45
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
56
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
46
import org.eclipse.jface.viewers.CellEditor;
57
import org.eclipse.jface.viewers.CellEditor;
47
import org.eclipse.jface.viewers.CheckboxCellEditor;
58
import org.eclipse.jface.viewers.CheckboxCellEditor;
59
import org.eclipse.jface.viewers.ColumnWeightData;
48
import org.eclipse.jface.viewers.ComboBoxCellEditor;
60
import org.eclipse.jface.viewers.ComboBoxCellEditor;
49
import org.eclipse.jface.viewers.ICellModifier;
61
import org.eclipse.jface.viewers.ICellModifier;
50
import org.eclipse.jface.viewers.ILabelProviderListener;
51
import org.eclipse.jface.viewers.ISelection;
62
import org.eclipse.jface.viewers.ISelection;
52
import org.eclipse.jface.viewers.ISelectionChangedListener;
63
import org.eclipse.jface.viewers.ISelectionChangedListener;
53
import org.eclipse.jface.viewers.IStructuredSelection;
64
import org.eclipse.jface.viewers.IStructuredSelection;
54
import org.eclipse.jface.viewers.ITableLabelProvider;
55
import org.eclipse.jface.viewers.ITreeContentProvider;
65
import org.eclipse.jface.viewers.ITreeContentProvider;
56
import org.eclipse.jface.viewers.SelectionChangedEvent;
66
import org.eclipse.jface.viewers.SelectionChangedEvent;
67
import org.eclipse.jface.viewers.StyledCellLabelProvider;
68
import org.eclipse.jface.viewers.StyledString;
69
import org.eclipse.jface.viewers.StyledString.Styler;
57
import org.eclipse.jface.viewers.TextCellEditor;
70
import org.eclipse.jface.viewers.TextCellEditor;
58
import org.eclipse.jface.viewers.TreeViewer;
71
import org.eclipse.jface.viewers.TreeViewer;
59
import org.eclipse.jface.viewers.Viewer;
72
import org.eclipse.jface.viewers.Viewer;
73
import org.eclipse.jface.viewers.ViewerCell;
60
import org.eclipse.jface.viewers.ViewerDropAdapter;
74
import org.eclipse.jface.viewers.ViewerDropAdapter;
61
import org.eclipse.jface.window.Window;
75
import org.eclipse.jface.window.Window;
62
import org.eclipse.osgi.util.NLS;
76
import org.eclipse.osgi.util.NLS;
Lines 73-97 Link Here
73
import org.eclipse.swt.events.ModifyListener;
87
import org.eclipse.swt.events.ModifyListener;
74
import org.eclipse.swt.events.MouseEvent;
88
import org.eclipse.swt.events.MouseEvent;
75
import org.eclipse.swt.events.MouseListener;
89
import org.eclipse.swt.events.MouseListener;
90
import org.eclipse.swt.events.SelectionAdapter;
76
import org.eclipse.swt.events.SelectionEvent;
91
import org.eclipse.swt.events.SelectionEvent;
77
import org.eclipse.swt.events.SelectionListener;
78
import org.eclipse.swt.graphics.Color;
92
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.Font;
93
import org.eclipse.swt.graphics.Font;
94
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.FontMetrics;
95
import org.eclipse.swt.graphics.FontMetrics;
81
import org.eclipse.swt.graphics.GC;
96
import org.eclipse.swt.graphics.GC;
82
import org.eclipse.swt.graphics.Image;
97
import org.eclipse.swt.graphics.Image;
98
import org.eclipse.swt.graphics.TextStyle;
83
import org.eclipse.swt.layout.GridData;
99
import org.eclipse.swt.layout.GridData;
84
import org.eclipse.swt.layout.GridLayout;
100
import org.eclipse.swt.layout.GridLayout;
85
import org.eclipse.swt.widgets.Button;
101
import org.eclipse.swt.widgets.Button;
86
import org.eclipse.swt.widgets.Combo;
102
import org.eclipse.swt.widgets.Combo;
87
import org.eclipse.swt.widgets.Composite;
103
import org.eclipse.swt.widgets.Composite;
88
import org.eclipse.swt.widgets.Control;
104
import org.eclipse.swt.widgets.Control;
105
import org.eclipse.swt.widgets.DateTime;
106
import org.eclipse.swt.widgets.Display;
107
import org.eclipse.swt.widgets.Event;
89
import org.eclipse.swt.widgets.Group;
108
import org.eclipse.swt.widgets.Group;
90
import org.eclipse.swt.widgets.Label;
109
import org.eclipse.swt.widgets.Label;
91
import org.eclipse.swt.widgets.Shell;
110
import org.eclipse.swt.widgets.Shell;
92
import org.eclipse.swt.widgets.TableItem;
111
import org.eclipse.swt.widgets.TableItem;
93
import org.eclipse.swt.widgets.Text;
112
import org.eclipse.swt.widgets.Text;
94
import org.eclipse.swt.widgets.TreeColumn;
113
import org.eclipse.swt.widgets.TreeColumn;
114
import org.eclipse.swt.widgets.Widget;
95
import org.eclipse.ui.IWorkbenchWindow;
115
import org.eclipse.ui.IWorkbenchWindow;
96
import org.eclipse.ui.PlatformUI;
116
import org.eclipse.ui.PlatformUI;
97
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
117
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
Lines 99-104 Link Here
99
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
119
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
100
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
120
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
101
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
121
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
122
import org.eclipse.ui.internal.ide.misc.MultiMatcher;
102
import org.eclipse.ui.plugin.AbstractUIPlugin;
123
import org.eclipse.ui.plugin.AbstractUIPlugin;
103
124
104
/**
125
/**
Lines 108-113 Link Here
108
public class ResourceFilterGroup {
129
public class ResourceFilterGroup {
109
130
110
	private Button addButton = null;
131
	private Button addButton = null;
132
	private Button addGroupButton = null;
111
	private Button removeButton = null;
133
	private Button removeButton = null;
112
	private Button upButton = null;
134
	private Button upButton = null;
113
	private Button downButton = null;
135
	private Button downButton = null;
Lines 117-122 Link Here
117
	private Filters filters;
139
	private Filters filters;
118
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
140
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
119
	private LabelProvider labelProvider;
141
	private LabelProvider labelProvider;
142
	Font boldFont;
143
	Font plainFont;
120
	private Image checkIcon = null;
144
	private Image checkIcon = null;
121
145
122
	private boolean tableViewCellEditorAdequatlyUsable = false;
146
	private boolean tableViewCellEditorAdequatlyUsable = false;
Lines 312-322 Link Here
312
		}
336
		}
313
	}
337
	}
314
338
315
	class LabelProvider implements ITableLabelProvider {
339
	class LabelProvider extends StyledCellLabelProvider  {
340
		private final Styler fBoldStyler; 
341
		private final Styler fPlainStyler; 
316
		FilterTypeUtil util;
342
		FilterTypeUtil util;
317
343
318
		public LabelProvider() {
344
		public LabelProvider() {
319
			util = new FilterTypeUtil();
345
			util = new FilterTypeUtil();
346
			fBoldStyler= new Styler() {
347
				public void applyStyles(TextStyle textStyle) {
348
					textStyle.font= boldFont;
349
				}
350
			};
351
			fPlainStyler= new Styler() {
352
				public void applyStyles(TextStyle textStyle) {
353
					textStyle.font= plainFont;
354
				}
355
			};
320
		}
356
		}
321
357
322
		String getColumnID(int index) {
358
		String getColumnID(int index) {
Lines 328-436 Link Here
328
			return copy.isUnderAGroupFilter();
364
			return copy.isUnderAGroupFilter();
329
		}
365
		}
330
366
331
		public Image getColumnImage(Object element, int columnIndex) {
367
		public void update(ViewerCell cell) {
332
			if (!isPartialFilter(element)) {
368
			FilterCopy filter = (FilterCopy) cell.getElement();
333
				if (getColumnID(columnIndex).equals(FilterTypeUtil.ARGUMENTS)) {
369
			
334
					Object index = FilterTypeUtil.getValue(
370
			int columnIndex = cell.getColumnIndex();
335
							(FilterCopy) element, FilterTypeUtil.TARGET);
336
					return util.getImage(FilterTypeUtil.TARGET,
337
							((Integer) index).intValue());
338
				}
339
				if (getColumnID(columnIndex).equals(FilterTypeUtil.MODE)) {
340
					Object index = FilterTypeUtil.getValue(
341
							(FilterCopy) element, FilterTypeUtil.MODE);
342
					return util.getImage(FilterTypeUtil.MODE, ((Integer) index)
343
							.intValue());
344
				}
345
				if (getColumnID(columnIndex).equals(FilterTypeUtil.INHERITABLE)) {
346
					Object condition = FilterTypeUtil.getValue(
347
							(FilterCopy) element, FilterTypeUtil.INHERITABLE);
348
					if (((Boolean) condition).booleanValue())
349
						return checkIcon;
350
				}
351
			}
352
			return null;
353
		}
354
355
		public String getColumnText(Object element, int columnIndex) {
356
			FilterCopy filter = ((FilterCopy) element);
357
			String column = getColumnID(columnIndex);
371
			String column = getColumnID(columnIndex);
358
			return getValue(filter, column);
359
		}
360
372
361
		private String getValue(FilterCopy filter, String column) {
362
			if (column.equals(FilterTypeUtil.ID)) {
373
			if (column.equals(FilterTypeUtil.ID)) {
363
				String id = filter.getId();
374
				String id = filter.getId();
364
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
375
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
365
				if (descriptor != null)
376
				if (descriptor != null)
366
					return descriptor.getName();
377
					cell.setText(descriptor.getName());
367
			}
378
			}
368
			if (column.equals(FilterTypeUtil.MODE)) {
379
			if (column.equals(FilterTypeUtil.MODE)) {
369
				if (!isPartialFilter(filter)) {
380
				if (!isPartialFilter(filter)) {
370
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
381
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
371
						return NLS
382
						cell.setText(NLS
372
								.bind(
383
								.bind(
373
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
384
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
374
										null);
385
										null));
375
					return NLS
386
					else
387
						cell.setText(NLS
376
							.bind(
388
							.bind(
377
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
389
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
378
									null);
390
									null));
379
				}
391
				}
380
				return getFilterTypeName(filter);
392
				else
393
					cell.setText(getFilterTypeName(filter));
381
			}
394
			}
382
			if (column.equals(FilterTypeUtil.TARGET)) {
395
			if (column.equals(FilterTypeUtil.TARGET)) {
383
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
396
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
384
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
397
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
385
				if (includeFiles && includeFolders)
398
				if (includeFiles && includeFolders)
386
					return NLS
399
					cell.setText(NLS
387
							.bind(
400
							.bind(
388
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
401
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
389
									null);
402
									null));
403
				else
390
				if (includeFiles)
404
				if (includeFiles)
391
					return NLS
405
					cell.setText(NLS
392
							.bind(
406
							.bind(
393
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
407
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
394
									null);
408
									null));
409
				else
395
				if (includeFolders)
410
				if (includeFolders)
396
					return NLS
411
					cell.setText(NLS
397
							.bind(
412
							.bind(
398
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
413
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
399
									null);
414
									null));
400
			}
415
			}
401
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
416
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
402
				if (filter.hasStringArguments())
417
				StyledString styledString = getStyleColumnText(filter);
403
					return filter.getArguments() != null ? filter
418
				cell.setText(styledString.toString());
404
							.getArguments().toString() : ""; //$NON-NLS-1$
419
				cell.setStyleRanges(styledString.getStyleRanges());
405
				if ((filter.getChildrenLimit() > 0)
406
						&& !filter.isUnderAGroupFilter())
407
					return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$
408
			}
420
			}
409
			return null;
410
		}
411
421
412
		private String getFilterTypeName(FilterCopy filter) {
422
			if (!isPartialFilter(filter)) {
413
			IFilterMatcherDescriptor desc = FilterTypeUtil.getDescriptor(filter
423
				if (column.equals(FilterTypeUtil.ARGUMENTS)) {
414
					.getId());
424
					Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET);
415
			if (desc != null)
425
					cell.setImage(util.getImage(FilterTypeUtil.TARGET,
416
				return desc.getName();
426
							((Integer) index).intValue()));
417
			return ""; //$NON-NLS-1$
427
				}
418
		}
428
				if (column.equals(FilterTypeUtil.MODE)) {
429
					Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.MODE);
430
					cell.setImage(util.getImage(FilterTypeUtil.MODE, ((Integer) index)
431
							.intValue()));
432
				}
433
				if (column.equals(FilterTypeUtil.INHERITABLE)) {
434
					Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
435
					if (((Boolean) condition).booleanValue())
436
						cell.setImage(checkIcon);
437
				}
438
			}
419
439
420
		public void addListener(ILabelProviderListener listener) {
440
			super.update(cell);
441
		}
442
		
443
		private StyledString getStyleColumnText(FilterCopy filter) {
444
			if (filter.getId().equals(MultiMatcher.ID))
445
				return new StyledString(formatMultiMatcherArgument(filter), fPlainStyler);
446
			if (filter.hasStringArguments())
447
				return new StyledString(filter.getArguments() != null ? filter
448
						.getArguments().toString() : new String(), fPlainStyler);
449
			if (filter.getChildrenLimit() > 0) {
450
				String whiteSpace = " "; //$NON-NLS-1$;
451
				String expression = getFilterTypeName(filter);
452
				StyledString buffer = new StyledString("(", fBoldStyler); //$NON-NLS-1$
453
				FilterCopy[] children = filter.getChildren();
454
				for (int i = 0; i < children.length; i++) {
455
					buffer.append(getStyleColumnText(children[i]));
456
					if ((i + 1) < children.length) {
457
						buffer.append(whiteSpace, fPlainStyler);
458
						buffer.append(expression, fBoldStyler);
459
						buffer.append(whiteSpace, fPlainStyler);
460
					}
461
				}
462
				buffer.append(")", fBoldStyler); //$NON-NLS-1$
463
				return buffer;
464
			}
465
			return new StyledString(new String(), fPlainStyler);
421
		}
466
		}
422
467
423
		public void dispose() {
468
		protected void measure(Event event, Object element) {
469
			super.measure(event, element);
424
		}
470
		}
425
471
426
		public boolean isLabelProperty(Object element, String property) {
472
		private String formatMultiMatcherArgument(FilterCopy filter) {
427
			return false;
473
			String argumentString = (String) filter.getArguments();
474
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments(argumentString);
475
			
476
			StringBuilder builder = new StringBuilder();
477
			builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key));
478
			builder.append(' ');
479
			builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator));
480
			builder.append(' ');
481
			Class type = MultiMatcher.getTypeForKey(argument.key, argument.operator);
482
			if (type.equals(String.class))
483
				builder.append(argument.pattern);
484
			if (type.equals(Boolean.class))
485
				builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.pattern));
486
			if (type.equals(Integer.class))
487
				builder.append(argument.pattern);
488
			if (type.equals(Date.class))
489
				builder.append(DateFormat.getDateInstance().format(new Date(Long.parseLong(argument.pattern))));
490
			
491
			return builder.toString();
428
		}
492
		}
429
493
430
		public void removeListener(ILabelProviderListener listener) {
494
		private String getFilterTypeName(FilterCopy filter) {
495
			IFilterMatcherDescriptor desc = FilterTypeUtil.getDescriptor(filter
496
					.getId());
497
			if (desc != null)
498
				return desc.getName();
499
			return ""; //$NON-NLS-1$
431
		}
500
		}
432
	}
501
	}
433
502
	
434
	class CellModifier implements ICellModifier {
503
	class CellModifier implements ICellModifier {
435
		public boolean canModify(Object element, String property) {
504
		public boolean canModify(Object element, String property) {
436
			FilterCopy filter = (FilterCopy) element;
505
			FilterCopy filter = (FilterCopy) element;
Lines 506-519 Link Here
506
	}
575
	}
507
576
508
	private void createViewerGroup(Composite parent) {
577
	private void createViewerGroup(Composite parent) {
509
		filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
578
		Composite tableComposite = new Composite(parent, SWT.NONE);
510
				| SWT.H_SCROLL);
511
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
579
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
512
		data.grabExcessHorizontalSpace = true;
580
		data.grabExcessHorizontalSpace = true;
513
		data.grabExcessVerticalSpace = true;
581
		data.grabExcessVerticalSpace = true;
582
		tableComposite.setLayoutData(data);
583
584
		filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER
585
				| SWT.H_SCROLL);
586
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
587
		data.grabExcessHorizontalSpace = true;
588
		data.grabExcessVerticalSpace = true;
514
		filterView.getTree().setLayoutData(data);
589
		filterView.getTree().setLayoutData(data);
515
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
590
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
516
591
592
		plainFont = filterView.getTree().getFont();
593
		FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD);
594
		boldFont = new Font(Display.getCurrent(), boldFontData);
595
517
		filterView.setContentProvider(new TreeContentProvider());
596
		filterView.setContentProvider(new TreeContentProvider());
518
		filterView.setInput(filters);
597
		filterView.setInput(filters);
519
		filterView.getTree().setFont(parent.getFont());
598
		filterView.getTree().setFont(parent.getFont());
Lines 524-560 Link Here
524
			}
603
			}
525
		});
604
		});
526
605
527
		TreeColumn column = new TreeColumn(filterView.getTree(), 0);
606
		TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0);
528
		column
607
		modeColumn
529
				.setText(NLS
608
				.setText(NLS
530
						.bind(
609
						.bind(
531
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
610
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
532
								null));
611
								null));
533
		column.setData(FilterTypeUtil.MODE);
612
		modeColumn.setData(FilterTypeUtil.MODE);
534
		column.setResizable(true);
613
		modeColumn.setResizable(true);
535
		column.setMoveable(false);
614
		modeColumn.setMoveable(false);
536
		column.setWidth(getMinimumColumnWidth(column, 130));
615
		//column.setWidth(getMinimumColumnWidth(column, 130));
537
616
538
		column = new TreeColumn(filterView.getTree(), 0);
617
		TreeColumn argumentColumn = new TreeColumn(filterView.getTree(), 0);
539
		column.setText(NLS.bind(
618
		argumentColumn.setText(NLS.bind(
540
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
619
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
541
				null));
620
				null));
542
		column.setData(FilterTypeUtil.ARGUMENTS);
621
		argumentColumn.setData(FilterTypeUtil.ARGUMENTS);
543
		column.setResizable(true);
622
		argumentColumn.setResizable(true);
544
		column.setMoveable(true);
623
		argumentColumn.setMoveable(true);
545
		column.setWidth(getMinimumColumnWidth(column, 120));
624
	//	column.setWidth(getMinimumColumnWidth(column, 240));
546
625
547
		column = new TreeColumn(filterView.getTree(), 0);
626
		TreeColumn inheritableColumn = new TreeColumn(filterView.getTree(), 0);
548
		column
627
		inheritableColumn
549
				.setText(NLS
628
				.setText(NLS
550
						.bind(
629
						.bind(
551
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
630
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
552
								null));
631
								null));
553
		column.setData(FilterTypeUtil.INHERITABLE);
632
		inheritableColumn.setData(FilterTypeUtil.INHERITABLE);
554
		column.setResizable(true);
633
		inheritableColumn.setResizable(true);
555
		column.setMoveable(false);
634
		inheritableColumn.setMoveable(false);
556
		column.setAlignment(SWT.CENTER);
635
		inheritableColumn.setAlignment(SWT.CENTER);
557
		column.setWidth(getMinimumColumnWidth(column, 70));
636
//		column.setWidth(getMinimumColumnWidth(column, 70));
558
637
559
		filterView.getTree().setHeaderVisible(true);
638
		filterView.getTree().setHeaderVisible(true);
560
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
639
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
Lines 598-616 Link Here
598
			public void menuDetected(MenuDetectEvent e) {
677
			public void menuDetected(MenuDetectEvent e) {
599
				MenuManager mgr = new MenuManager();
678
				MenuManager mgr = new MenuManager();
600
				mgr.add(addSubFilterAction);
679
				mgr.add(addSubFilterAction);
680
				mgr.add(addSubGroupFilterAction);
681
				mgr.add(new Separator());
682
				mgr.add(new EditFilterAction());
683
				mgr.add(new RemoveFilterAction());
601
				filterView.getControl().setMenu(
684
				filterView.getControl().setMenu(
602
						mgr.createContextMenu(filterView.getControl()));
685
						mgr.createContextMenu(filterView.getControl()));
603
			}
686
			}
604
		});
687
		});
688
		TreeColumnLayout layout = new TreeColumnLayout();
689
		tableComposite.setLayout( layout );
690
		// 4
691
		layout.setColumnData( modeColumn, new ColumnWeightData( 130 ) );
692
		layout.setColumnData( argumentColumn, new ColumnWeightData( 400) );
693
		layout.setColumnData( inheritableColumn, new ColumnWeightData( 70 ) );
694
695
	}
696
697
	private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
698
		FontData[] styleData = new FontData[originalData.length];
699
		for (int i = 0; i < styleData.length; i++) {
700
			FontData base = originalData[i];
701
			styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle);
702
		}
703
       	return styleData;
704
    }
705
706
	class EditFilterAction extends Action {
707
708
		public EditFilterAction() {
709
			setText(NLS
710
					.bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel,
711
							null));
712
		}
713
714
		public void run() {
715
			handleEdit();
716
		}
717
		public boolean isEnabled() {
718
			ISelection selection = filterView.getSelection();
719
			if (selection instanceof IStructuredSelection) {
720
				return ((IStructuredSelection) selection).size() > 0;			}
721
			return false;
722
		}
723
	}
724
725
	class RemoveFilterAction extends Action {
726
727
		public RemoveFilterAction() {
728
			setText(NLS
729
					.bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel,
730
							null));
731
		}
732
733
		public void run() {
734
			handleRemove();
735
		}
736
		public boolean isEnabled() {
737
			ISelection selection = filterView.getSelection();
738
			if (selection instanceof IStructuredSelection) {
739
				return ((IStructuredSelection) selection).size() > 0;			}
740
			return false;
741
		}
605
	}
742
	}
606
743
607
	Action addSubFilterAction = new AddSubFilterAction();
744
	Action addSubFilterAction = new AddSubFilterAction(false);
608
745
609
	class AddSubFilterAction extends Action {
746
	class AddSubFilterAction extends Action {
610
747
611
		public AddSubFilterAction() {
748
		boolean createGroupOnly;
749
		
750
		public AddSubFilterAction(boolean createGroupOnly) {
751
			this.createGroupOnly = createGroupOnly;
612
			setText(NLS
752
			setText(NLS
613
					.bind(
753
					.bind(createGroupOnly ?
754
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel:
614
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
755
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
615
							null));
756
							null));
616
		}
757
		}
Lines 629-635 Link Here
629
					FilterCopy newFilter = new FilterCopy();
770
					FilterCopy newFilter = new FilterCopy();
630
					newFilter.setParent(filter);
771
					newFilter.setParent(filter);
631
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
772
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
632
							newFilter);
773
							newFilter, createGroupOnly);
633
					if (dialog.open() == Window.OK) {
774
					if (dialog.open() == Window.OK) {
634
						filter.addChild(newFilter);
775
						filter.addChild(newFilter);
635
						filterView.refresh();
776
						filterView.refresh();
Lines 654-659 Link Here
654
		}
795
		}
655
	}
796
	}
656
797
798
	Action addSubGroupFilterAction = new AddSubFilterAction(true);
799
657
	class FilterCopyDrop extends ViewerDropAdapter {
800
	class FilterCopyDrop extends ViewerDropAdapter {
658
		protected FilterCopyDrop(Viewer viewer) {
801
		protected FilterCopyDrop(Viewer viewer) {
659
			super(viewer);
802
			super(viewer);
Lines 749-768 Link Here
749
		}
892
		}
750
	}
893
	}
751
894
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) {
895
	private void createButtonGroup(Composite parent) {
767
		Composite composite = new Composite(parent, SWT.NONE);
896
		Composite composite = new Composite(parent, SWT.NONE);
768
		GridLayout layout = new GridLayout();
897
		GridLayout layout = new GridLayout();
Lines 780-793 Link Here
780
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
909
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
781
		addButton.setLayoutData(data);
910
		addButton.setLayoutData(data);
782
		setButtonDimensionHint(addButton);
911
		setButtonDimensionHint(addButton);
783
		addButton.addSelectionListener(new SelectionListener() {
912
		addButton.addSelectionListener(new SelectionAdapter() {
784
			public void widgetDefaultSelected(SelectionEvent e) {
913
			public void widgetSelected(SelectionEvent e) {
914
				handleAdd(false);
785
			}
915
			}
786
916
		});
917
		
918
		addGroupButton = new Button(composite, SWT.PUSH);
919
		addGroupButton.setText(NLS.bind(
920
				IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null));
921
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
922
		addGroupButton.setLayoutData(data);
923
		setButtonDimensionHint(addGroupButton);
924
		addGroupButton.addSelectionListener(new SelectionAdapter() {
787
			public void widgetSelected(SelectionEvent e) {
925
			public void widgetSelected(SelectionEvent e) {
788
				handleAdd();
926
				handleAdd(true);
789
			}
927
			}
790
		});
928
		});
929
		
791
930
792
		editButton = new Button(composite, SWT.PUSH);
931
		editButton = new Button(composite, SWT.PUSH);
793
		editButton.setText(NLS.bind(
932
		editButton.setText(NLS.bind(
Lines 795-804 Link Here
795
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
934
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
796
		editButton.setLayoutData(data);
935
		editButton.setLayoutData(data);
797
		setButtonDimensionHint(editButton);
936
		setButtonDimensionHint(editButton);
798
		editButton.addSelectionListener(new SelectionListener() {
937
		editButton.addSelectionListener(new SelectionAdapter() {
799
			public void widgetDefaultSelected(SelectionEvent e) {
800
			}
801
802
			public void widgetSelected(SelectionEvent e) {
938
			public void widgetSelected(SelectionEvent e) {
803
				handleEdit();
939
				handleEdit();
804
			}
940
			}
Lines 813-822 Link Here
813
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
949
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
814
		removeButton.setLayoutData(data);
950
		removeButton.setLayoutData(data);
815
		setButtonDimensionHint(removeButton);
951
		setButtonDimensionHint(removeButton);
816
		removeButton.addSelectionListener(new SelectionListener() {
952
		removeButton.addSelectionListener(new SelectionAdapter() {
817
			public void widgetDefaultSelected(SelectionEvent e) {
818
			}
819
820
			public void widgetSelected(SelectionEvent e) {
953
			public void widgetSelected(SelectionEvent e) {
821
				handleRemove();
954
				handleRemove();
822
			}
955
			}
Lines 832-841 Link Here
832
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
965
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
833
			upButton.setLayoutData(data);
966
			upButton.setLayoutData(data);
834
			setButtonDimensionHint(upButton);
967
			setButtonDimensionHint(upButton);
835
			upButton.addSelectionListener(new SelectionListener() {
968
			upButton.addSelectionListener(new SelectionAdapter() {
836
				public void widgetDefaultSelected(SelectionEvent e) {
837
				}
838
839
				public void widgetSelected(SelectionEvent e) {
969
				public void widgetSelected(SelectionEvent e) {
840
					handleUp();
970
					handleUp();
841
				}
971
				}
Lines 848-857 Link Here
848
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
978
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
849
			downButton.setLayoutData(data);
979
			downButton.setLayoutData(data);
850
			setButtonDimensionHint(downButton);
980
			setButtonDimensionHint(downButton);
851
			downButton.addSelectionListener(new SelectionListener() {
981
			downButton.addSelectionListener(new SelectionAdapter() {
852
				public void widgetDefaultSelected(SelectionEvent e) {
853
				}
854
855
				public void widgetSelected(SelectionEvent e) {
982
				public void widgetSelected(SelectionEvent e) {
856
					handleDown();
983
					handleDown();
857
				}
984
				}
Lines 887-895 Link Here
887
		return filters.isLast((FilterCopy) o);
1014
		return filters.isLast((FilterCopy) o);
888
	}
1015
	}
889
1016
890
	private void handleAdd() {
1017
	private void handleAdd(boolean createGroupOnly) {
891
		FilterCopy newFilter = new FilterCopy();
1018
		FilterCopy newFilter = new FilterCopy();
892
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter);
1019
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter, createGroupOnly);
893
		if (dialog.open() == Window.OK) {
1020
		if (dialog.open() == Window.OK) {
894
			filters.add(newFilter);
1021
			filters.add(newFilter);
895
			filterView.refresh();
1022
			filterView.refresh();
Lines 903-909 Link Here
903
					.getFirstElement();
1030
					.getFirstElement();
904
			FilterCopy copy = new FilterCopy(filter);
1031
			FilterCopy copy = new FilterCopy(filter);
905
			copy.setParent(filter.getParent());
1032
			copy.setParent(filter.getParent());
906
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy);
1033
			boolean isGroup = filter.getChildrenLimit() > 0;
1034
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy, isGroup);
907
			if (dialog.open() == Window.OK) {
1035
			if (dialog.open() == Window.OK) {
908
				if (copy.hasChanged()) {
1036
				if (copy.hasChanged()) {
909
					filter.copy(copy);
1037
					filter.copy(copy);
Lines 1263-1286 Link Here
1263
								null) };
1391
								null) };
1264
	}
1392
	}
1265
1393
1266
	static String[] getFilterNames(boolean childrenOnly) {
1394
	static String[] getFilterNames(boolean groupOnly) {
1267
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1395
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1268
				.getFilterMatcherDescriptors();
1396
				.getFilterMatcherDescriptors();
1397
		sortDescriptors(descriptors);
1269
		LinkedList names = new LinkedList();
1398
		LinkedList names = new LinkedList();
1270
		for (int i = 0; i < descriptors.length; i++) {
1399
		for (int i = 0; i < descriptors.length; i++) {
1271
			if (!childrenOnly
1400
			boolean isGroup = descriptors[i].getArgumentType().equals(
1401
					IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1272
					|| descriptors[i].getArgumentType().equals(
1402
					|| descriptors[i].getArgumentType().equals(
1273
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1403
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS);
1274
					|| descriptors[i].getArgumentType().equals(
1404
			if (isGroup == groupOnly) 
1275
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS))
1276
				names.add(descriptors[i].getName());
1405
				names.add(descriptors[i].getName());
1277
		}
1406
		}
1278
		return (String[]) names.toArray(new String[0]);
1407
		return (String[]) names.toArray(new String[0]);
1279
	}
1408
	}
1280
1409
1410
	/**
1411
	 * @param descriptors
1412
	 */
1413
	private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) {
1414
		Arrays.sort(descriptors, new Comparator() {
1415
			public int compare(Object arg0, Object arg1) {
1416
				if (((IFilterMatcherDescriptor) arg0).getId().equals(MultiMatcher.ID))
1417
					return -1;
1418
				if (((IFilterMatcherDescriptor) arg1).getId().equals(MultiMatcher.ID))
1419
					return 1;
1420
				return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId());
1421
			}
1422
		});
1423
	}
1424
1281
	static String getDefaultFilterID() {
1425
	static String getDefaultFilterID() {
1282
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1426
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1283
				.getFilterMatcherDescriptors();
1427
				.getFilterMatcherDescriptors();
1428
		sortDescriptors(descriptors);
1284
		for (int i = 0; i < descriptors.length; i++) {
1429
		for (int i = 0; i < descriptors.length; i++) {
1285
			if (descriptors[i].getArgumentType().equals(
1430
			if (descriptors[i].getArgumentType().equals(
1286
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
1431
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
Lines 1669-1700 Link Here
1669
	protected Button foldersButton;
1814
	protected Button foldersButton;
1670
	protected Button filesAndFoldersButton;
1815
	protected Button filesAndFoldersButton;
1671
	protected Combo idCombo;
1816
	protected Combo idCombo;
1817
	protected Composite idComposite;
1818
	protected Composite argumentComposite;
1672
	protected Button inherited;
1819
	protected Button inherited;
1673
	protected Text arguments;
1674
	protected Label argumentsLabel;
1675
	protected Label description;
1676
	protected FilterTypeUtil util;
1820
	protected FilterTypeUtil util;
1821
	protected boolean createGroupOnly;
1677
	protected IResource resource;
1822
	protected IResource resource;
1678
1823
1679
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$
1824
	TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
1680
	
1825
	ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() {
1681
	/**
1826
		public Object getID() {return "dummy";} //$NON-NLS-1$
1682
	 * Find and replace command adapters.
1827
		public void create(Composite argumentComposite, Font font) {}
1683
	 * @since 3.3
1828
		public void dispose() {}
1684
	 */
1829
		public void selectionChanged() {}
1685
	private ContentAssistCommandAdapter fContentAssistField;
1830
		public void validate() {}
1831
	};
1686
1832
1687
	/**
1833
	/**
1688
	 * Constructor for FilterEditDialog.
1834
	 * Constructor for FilterEditDialog.
1689
	 * 
1835
	 * 
1690
	 * @param parentShell
1836
	 * @param parentShell
1691
	 * @param filter
1837
	 * @param filter
1838
	 * @param createGroupOnly 
1692
	 */
1839
	 */
1693
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) {
1840
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter, boolean createGroupOnly) {
1694
		super(parentShell);
1841
		super(parentShell);
1695
		this.resource = resource;
1842
		this.resource = resource;
1696
		this.filter = filter;
1843
		this.filter = filter;
1844
		this.createGroupOnly = createGroupOnly;
1697
		util = new FilterTypeUtil();
1845
		util = new FilterTypeUtil();
1846
		ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter);
1847
		customfilterArgumentMap.put(ui.getID(), ui);
1848
		ui = new DefaultCustomFilterArgumentUI(parentShell, filter);
1849
		customfilterArgumentMap.put(ui.getID(), ui);
1698
	}
1850
	}
1699
1851
1700
	/*
1852
	/*
Lines 1728-1734 Link Here
1728
		if (!filter.isUnderAGroupFilter()) {
1880
		if (!filter.isUnderAGroupFilter()) {
1729
			Composite topComposite = new Composite(composite, SWT.NONE);
1881
			Composite topComposite = new Composite(composite, SWT.NONE);
1730
			layout = new GridLayout();
1882
			layout = new GridLayout();
1731
			layout.numColumns = 2;
1883
			layout.numColumns = 1;
1732
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1884
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1733
			layout.marginWidth = 0;
1885
			layout.marginWidth = 0;
1734
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1886
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
Lines 1739-1747 Link Here
1739
			topComposite.setFont(font);
1891
			topComposite.setFont(font);
1740
1892
1741
			createModeArea(font, topComposite);
1893
			createModeArea(font, topComposite);
1894
			createIdArea(font, topComposite);
1742
			createTargetArea(font, topComposite);
1895
			createTargetArea(font, topComposite);
1896
			createInheritableArea(font, topComposite);
1743
		}
1897
		}
1744
		createIdArea(font, composite);
1898
		else
1899
			createIdArea(font, composite);
1745
1900
1746
		return composite;
1901
		return composite;
1747
	}
1902
	}
Lines 1751-1772 Link Here
1751
	 * @param composite
1906
	 * @param composite
1752
	 */
1907
	 */
1753
	private void createInheritableArea(Font font, Composite composite) {
1908
	private void createInheritableArea(Font font, Composite composite) {
1909
		Composite inheritableComposite = createGroup(font, composite, NLS.bind(
1910
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
1911
				null), false, false, 1);
1912
1754
		GridData data;
1913
		GridData data;
1755
		inherited = new Button(composite, SWT.CHECK);
1914
		inherited = new Button(inheritableComposite, SWT.CHECK);
1756
		inherited
1915
		inherited
1757
				.setText(NLS
1916
				.setText(NLS
1758
						.bind(
1917
						.bind(
1759
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
1918
								IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure,
1760
								null));
1919
								null));
1761
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
1920
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
1762
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1921
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1763
		data.horizontalSpan = 1;
1922
		data.horizontalSpan = 1;
1764
		inherited.setLayoutData(data);
1923
		inherited.setLayoutData(data);
1765
		inherited.setFont(font);
1924
		inherited.setFont(font);
1766
		inherited.addSelectionListener(new SelectionListener() {
1925
		inherited.addSelectionListener(new SelectionAdapter() {
1767
			public void widgetDefaultSelected(SelectionEvent e) {
1768
			}
1769
1770
			public void widgetSelected(SelectionEvent e) {
1926
			public void widgetSelected(SelectionEvent e) {
1771
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1927
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1772
						new Boolean(inherited.getSelection()));
1928
						new Boolean(inherited.getSelection()));
Lines 1780-1884 Link Here
1780
	 * @param font
1936
	 * @param font
1781
	 * @param composite
1937
	 * @param composite
1782
	 */
1938
	 */
1783
	private void createArgumentsArea(Font font, Composite composite) {
1939
	private void createIdArea(Font font, Composite composite) {
1784
		GridData data;
1940
		GridData data;
1785
		argumentsLabel = addLabel(composite, NLS.bind(
1941
		if (createGroupOnly) {
1786
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
1942
			idComposite = createGroup(font, composite, new String(),
1787
				null));
1943
					true, true, 1);
1788
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
1944
			idCombo = new Combo(idComposite, SWT.READ_ONLY);
1789
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1945
			idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly));
1790
		arguments.setLayoutData(data);
1946
			data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1791
		arguments.setFont(font);
1947
			idCombo.setLayoutData(data);
1792
		arguments.addModifyListener(new ModifyListener() {
1948
			idCombo.setFont(font);
1793
			public void modifyText(ModifyEvent e) {
1949
			idCombo.addSelectionListener(new SelectionAdapter() {
1794
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
1950
				public void widgetSelected(SelectionEvent e) {
1795
						arguments.getText());
1951
					FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1796
			}
1952
							.getItem(idCombo.getSelectionIndex()));
1797
		});
1953
					if (filter.hasStringArguments())
1798
		if (filter.hasStringArguments())
1954
						filter.setArguments(new String());
1799
			arguments.setText((String) FilterTypeUtil.getValue(filter,
1955
					setupPatternLine();
1800
					FilterTypeUtil.ARGUMENTS));
1956
					currentCustomFilterArgumentUI.selectionChanged();
1801
		arguments.setEnabled(filter.hasStringArguments());
1957
				}
1802
		setArgumentLabelEnabled();
1958
			});
1803
1959
			idCombo.select(0);
1804
		TextContentAdapter contentAdapter= new TextContentAdapter();
1960
			selectComboItem(filter.getId());
1805
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
1961
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1806
		fContentAssistField= new ContentAssistCommandAdapter(
1962
					.getItem(idCombo.getSelectionIndex()));
1807
				arguments,
1963
		}
1808
				contentAdapter,
1964
		else {
1809
				findProposer, 
1965
			idComposite = createGroup(font, composite, new String(),
1810
				null,
1966
					true, true, 1);
1811
				new char[] {'\\', '[', '('},
1967
		}
1812
				true);
1968
		argumentComposite = new Composite(idComposite, SWT.NONE);
1813
	}
1969
		setupPatternLine();
1814
1815
	/**
1816
	 * 
1817
	 */
1818
	private void setArgumentLabelEnabled() {
1819
		Color color = argumentsLabel.getDisplay().getSystemColor(
1820
				filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
1821
		argumentsLabel.setForeground(color);
1822
	}
1970
	}
1971
	
1823
1972
1824
	/**
1973
	ICustomFilterArgumentUI getUI(String descriptorID) {
1825
	 * @param font
1974
		ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
1826
	 * @param composite
1975
		if (result == null)
1827
	 */
1976
			return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
1828
	private void createDescriptionArea(Font font, Composite composite) {
1977
		return result;
1829
		GridData data;
1830
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
1831
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
1832
				.getDescription());
1833
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
1834
		data.widthHint = 300;
1835
		data.heightHint = 40;
1836
		description.setLayoutData(data);
1837
		description.setFont(font);
1838
	}
1978
	}
1839
1979
	
1840
	/**
1980
	private void setupPatternLine() {
1841
	 * @param font
1981
		IFilterMatcherDescriptor descriptor;
1842
	 * @param composite
1982
		if (createGroupOnly) {
1843
	 */
1983
			String item = idCombo.getItem(idCombo.getSelectionIndex());
1844
	private void createIdArea(Font font, Composite composite) {
1984
			descriptor = FilterTypeUtil.getDescriptorByName(item);
1845
		GridData data;
1985
		}
1846
		Group idComposite = createGroup(font, composite, NLS.bind(
1986
		else
1847
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null),
1987
			descriptor = FilterTypeUtil.getDescriptor(filter.getId());
1848
				true);
1988
		Font font = idComposite.getFont();
1849
		idCombo = new Combo(idComposite, SWT.READ_ONLY);
1989
		ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId());
1850
		idCombo.setItems(FilterTypeUtil.getFilterNames(filter
1990
		if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) {
1851
				.getChildrenLimit() > 0));
1991
			currentCustomFilterArgumentUI.dispose();
1852
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1992
			currentCustomFilterArgumentUI = customFilterArgumentUI;
1853
		idCombo.setLayoutData(data);
1993
			currentCustomFilterArgumentUI.create(argumentComposite, font);
1854
		idCombo.setFont(font);
1994
			getShell().layout(true);
1855
		idCombo.addSelectionListener(new SelectionListener() {
1995
			getShell().redraw();
1856
			public void widgetDefaultSelected(SelectionEvent e) {
1996
		}
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
	}
1997
	}
1883
1998
1884
	/**
1999
	/**
Lines 1904-1923 Link Here
1904
	 */
2019
	 */
1905
	private void createModeArea(Font font, Composite composite) {
2020
	private void createModeArea(Font font, Composite composite) {
1906
		GridData data;
2021
		GridData data;
1907
		Group modeComposite = createGroup(font, composite, NLS.bind(
2022
		Composite modeComposite = createGroup(font, composite, new String(), false, true, 2);
1908
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
1909
				null), false);
1910
		String[] modes = FilterTypeUtil.getModes();
2023
		String[] modes = FilterTypeUtil.getModes();
1911
		includeButton = new Button(modeComposite, SWT.RADIO);
2024
		includeButton = new Button(modeComposite, SWT.RADIO);
1912
		includeButton.setText(modes[0]);
2025
		includeButton.setText(modes[0]);
1913
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
2026
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
1914
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2027
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1915
		includeButton.setLayoutData(data);
2028
		includeButton.setLayoutData(data);
1916
		includeButton.setFont(font);
2029
		includeButton.setFont(font);
1917
		includeButton.addSelectionListener(new SelectionListener() {
2030
		includeButton.addSelectionListener(new SelectionAdapter() {
1918
			public void widgetDefaultSelected(SelectionEvent e) {
1919
			}
1920
1921
			public void widgetSelected(SelectionEvent e) {
2031
			public void widgetSelected(SelectionEvent e) {
1922
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2032
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1923
						new Integer(0));
2033
						new Integer(0));
Lines 1928-1940 Link Here
1928
		excludeButton = new Button(modeComposite, SWT.RADIO);
2038
		excludeButton = new Button(modeComposite, SWT.RADIO);
1929
		excludeButton.setText(modes[1]);
2039
		excludeButton.setText(modes[1]);
1930
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
2040
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
1931
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2041
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1932
		excludeButton.setLayoutData(data);
2042
		excludeButton.setLayoutData(data);
1933
		excludeButton.setFont(font);
2043
		excludeButton.setFont(font);
1934
		excludeButton.addSelectionListener(new SelectionListener() {
2044
		excludeButton.addSelectionListener(new SelectionAdapter() {
1935
			public void widgetDefaultSelected(SelectionEvent e) {
1936
			}
1937
1938
			public void widgetSelected(SelectionEvent e) {
2045
			public void widgetSelected(SelectionEvent e) {
1939
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2046
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1940
						new Integer(1));
2047
						new Integer(1));
Lines 1942-1948 Link Here
1942
		});
2049
		});
1943
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
2050
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1944
				filter, FilterTypeUtil.MODE)).intValue() == 1);
2051
				filter, FilterTypeUtil.MODE)).intValue() == 1);
1945
		createInheritableArea(font, modeComposite);
1946
	}
2052
	}
1947
2053
1948
	/**
2054
	/**
Lines 1950-1967 Link Here
1950
	 * @param composite
2056
	 * @param composite
1951
	 * @return the group
2057
	 * @return the group
1952
	 */
2058
	 */
1953
	private Group createGroup(Font font, Composite composite, String text,
2059
	private Composite createGroup(Font font, Composite composite, String text,
1954
			boolean grabExcessVerticalSpace) {
2060
			boolean grabExcessVerticalSpace, boolean group, int columnCounts) {
1955
		GridLayout layout;
2061
		GridLayout layout;
1956
		GridData data;
2062
		GridData data;
1957
		Group modeComposite = new Group(composite, SWT.NONE);
2063
		Composite modeComposite;
1958
		modeComposite.setText(text);
2064
		if (group) { 
2065
			Group modeGroup = new Group(composite, SWT.NONE);
2066
			modeGroup.setText(text);
2067
			modeComposite = modeGroup;
2068
		} else {
2069
			modeComposite = new Composite(composite, SWT.NONE);
2070
		}
1959
		layout = new GridLayout();
2071
		layout = new GridLayout();
1960
		layout.numColumns = 1;
2072
		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);
2073
		modeComposite.setLayout(layout);
1966
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
2074
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
1967
		modeComposite.setLayoutData(data);
2075
		modeComposite.setLayoutData(data);
Lines 1975-2028 Link Here
1975
	 */
2083
	 */
1976
	private void createTargetArea(Font font, Composite composite) {
2084
	private void createTargetArea(Font font, Composite composite) {
1977
		GridData data;
2085
		GridData data;
1978
		Group targetComposite = createGroup(font, composite, NLS.bind(
2086
		Composite targetComposite = createGroup(font, composite, new String(), false, true, 3);
1979
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
1980
				null), false);
1981
2087
1982
		String[] targets = FilterTypeUtil.getTargets();
2088
		String[] targets = FilterTypeUtil.getTargets();
1983
		filesButton = new Button(targetComposite, SWT.RADIO);
2089
		filesButton = new Button(targetComposite, SWT.RADIO);
1984
		filesButton.setText(targets[0]);
2090
		filesButton.setText(targets[0]);
1985
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
2091
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
1986
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2092
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1987
		filesButton.setLayoutData(data);
2093
		filesButton.setLayoutData(data);
1988
		filesButton.setFont(font);
2094
		filesButton.setFont(font);
1989
2095
1990
		foldersButton = new Button(targetComposite, SWT.RADIO);
2096
		foldersButton = new Button(targetComposite, SWT.RADIO);
1991
		foldersButton.setText(targets[1]);
2097
		foldersButton.setText(targets[1]);
1992
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
2098
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
1993
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2099
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1994
		foldersButton.setLayoutData(data);
2100
		foldersButton.setLayoutData(data);
1995
		foldersButton.setFont(font);
2101
		foldersButton.setFont(font);
1996
2102
1997
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
2103
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
1998
		filesAndFoldersButton.setText(targets[2]);
2104
		filesAndFoldersButton.setText(targets[2]);
1999
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2105
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2000
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2106
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2001
		filesAndFoldersButton.setLayoutData(data);
2107
		filesAndFoldersButton.setLayoutData(data);
2002
		filesAndFoldersButton.setFont(font);
2108
		filesAndFoldersButton.setFont(font);
2003
2109
2004
		filesButton.addSelectionListener(new SelectionListener() {
2110
		filesButton.addSelectionListener(new SelectionAdapter() {
2005
			public void widgetDefaultSelected(SelectionEvent e) {
2006
			}
2007
2008
			public void widgetSelected(SelectionEvent e) {
2111
			public void widgetSelected(SelectionEvent e) {
2009
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2112
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2010
						new Integer(0));
2113
						new Integer(0));
2011
			}
2114
			}
2012
		});
2115
		});
2013
		foldersButton.addSelectionListener(new SelectionListener() {
2116
		foldersButton.addSelectionListener(new SelectionAdapter() {
2014
			public void widgetDefaultSelected(SelectionEvent e) {
2015
			}
2016
2017
			public void widgetSelected(SelectionEvent e) {
2117
			public void widgetSelected(SelectionEvent e) {
2018
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2118
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2019
						new Integer(1));
2119
						new Integer(1));
2020
			}
2120
			}
2021
		});
2121
		});
2022
		filesAndFoldersButton.addSelectionListener(new SelectionListener() {
2122
		filesAndFoldersButton.addSelectionListener(new SelectionAdapter() {
2023
			public void widgetDefaultSelected(SelectionEvent e) {
2024
			}
2025
2026
			public void widgetSelected(SelectionEvent e) {
2123
			public void widgetSelected(SelectionEvent e) {
2027
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2124
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2028
						new Integer(2));
2125
						new Integer(2));
Lines 2036-2053 Link Here
2036
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2133
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2037
	}
2134
	}
2038
2135
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) {
2136
	protected Control createContents(Composite parent) {
2052
		Control control = super.createContents(parent);
2137
		Control control = super.createContents(parent);
2053
		initialize();
2138
		initialize();
Lines 2082-2089 Link Here
2082
		if (filter.hasStringArguments()) {
2167
		if (filter.hasStringArguments()) {
2083
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2168
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2084
			if (desc != null) {
2169
			if (desc != null) {
2085
				AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2086
				try {
2170
				try {
2171
					currentCustomFilterArgumentUI.validate();
2172
					AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2087
					matcher.initialize(resource.getProject(), filter.getArguments());
2173
					matcher.initialize(resource.getProject(), filter.getArguments());
2088
				} catch (CoreException e) {
2174
				} catch (CoreException e) {
2089
					IWorkbenchWindow window = PlatformUI.getWorkbench()
2175
					IWorkbenchWindow window = PlatformUI.getWorkbench()
Lines 2099-2102 Link Here
2099
2185
2100
		super.okPressed();
2186
		super.okPressed();
2101
	}
2187
	}
2188
}
2189
2190
interface ICustomFilterArgumentUI {
2191
2192
	/**
2193
	 * @return the descriptor ID
2194
	 */
2195
	Object getID();
2196
2197
	/**
2198
	 * @throws CoreException 
2199
	 * 
2200
	 */
2201
	void validate() throws CoreException;
2202
2203
	/**
2204
	 * 
2205
	 */
2206
	void selectionChanged();
2207
2208
	/**
2209
	 * @param argumentComposite
2210
	 * @param font
2211
	 */
2212
	void create(Composite argumentComposite, Font font);
2213
2214
	/**
2215
	 * 
2216
	 */
2217
	void dispose();
2218
	
2219
}
2220
2221
class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2222
2223
	Shell shell;
2224
	FilterCopy filter;
2225
	protected Button argumentsCaseSensitive;
2226
	protected Button argumentsRegularExpresion;
2227
	protected Text arguments;
2228
	protected DateTime argumentsDate;
2229
	protected Combo argumentsBoolean;
2230
	protected Label argumentsLabel;
2231
	protected Label description;
2232
	protected ContentAssistCommandAdapter fContentAssistField;
2233
	protected Combo multiKey;
2234
	protected Combo multiOperator;
2235
	protected Composite multiArgumentComposite;
2236
	protected Composite stringArgumentComposite;
2237
	protected Composite attributeStringArgumentComposite;
2238
	protected Class intiantiatedKeyOperatorType = null;
2239
	
2240
	/**
2241
	 * @param parentShell
2242
	 * @param filter
2243
	 */
2244
	public MultiMatcherCustomFilterArgumentUI(Shell parentShell,
2245
			FilterCopy filter) {
2246
		this.shell = parentShell;
2247
		this.filter = filter;
2248
	}
2249
2250
	/* (non-Javadoc)
2251
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2252
	 */
2253
	public Object getID() {
2254
		return MultiMatcher.ID;
2255
	}
2256
2257
	/* (non-Javadoc)
2258
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2259
	 */
2260
	public void dispose() {
2261
		Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description};
2262
		for (int i = 0; i < list.length; i++) {
2263
			if (list[i] != null) {
2264
				list[i].dispose();
2265
			}
2266
		}
2267
		multiKey = null;
2268
		multiOperator = null;
2269
		multiArgumentComposite = null;
2270
		arguments = null;
2271
		argumentsLabel = null;
2272
		fContentAssistField = null;
2273
		intiantiatedKeyOperatorType = null;
2274
		stringArgumentComposite = null;
2275
		argumentsCaseSensitive = null;
2276
		argumentsRegularExpresion = null;
2277
		attributeStringArgumentComposite = null;
2278
		description = null;
2279
	}
2280
2281
	/* (non-Javadoc)
2282
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2283
	 */
2284
	public void create(Composite argumentComposite, Font font) {
2285
		GridLayout layout = new GridLayout();
2286
		layout.numColumns = 3;
2287
		layout.marginWidth = 0;
2288
		argumentComposite.setLayout(layout);
2289
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2290
		argumentComposite.setLayoutData(data);
2291
		argumentComposite.setFont(font);
2292
		createCustomArgumentsArea(font, argumentComposite);
2293
		argumentComposite.layout(true);
2294
		createDescriptionArea(font, argumentComposite);
2295
	}
2296
	
2297
	/**
2298
	 * @param font
2299
	 * @param composite
2300
	 */
2301
	private void createDescriptionArea(Font font, Composite composite) {
2302
		GridData data;
2303
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2304
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2305
		data.widthHint = 300;
2306
		data.heightHint = 40;
2307
		data.horizontalSpan = 3;
2308
		description.setLayoutData(data);
2309
		description.setFont(font);
2310
		setupDescriptionText();
2311
	}
2312
2313
	private void setupDescriptionText() {
2314
		if (description != null) {
2315
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2316
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2317
			Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2318
			description.setText(new String());
2319
			if (selectedKeyOperatorType.equals(String.class)) {
2320
				if (!argumentsRegularExpresion.getSelection())
2321
					description.setText(NLS.bind(
2322
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null));
2323
			}
2324
			if (selectedKeyOperatorType.equals(Integer.class)) {
2325
				description.setText(NLS.bind(
2326
						IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null));
2327
			}
2328
		}
2329
	}
2330
	
2331
	private void createCustomArgumentsArea(Font font, Composite composite) {
2332
		GridData data;
2333
		multiKey = new Combo(composite, SWT.READ_ONLY);
2334
		multiKey.setItems(getMultiMatcherKeys());
2335
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2336
		multiKey.setLayoutData(data);
2337
		multiKey.setFont(font);
2338
		multiKey.addSelectionListener(new SelectionAdapter() {
2339
			public void widgetSelected(SelectionEvent e) {
2340
				setupMultiOperatorAndField(true);
2341
				storeMultiSelection();
2342
			}
2343
		});
2344
2345
		multiOperator = new Combo(composite, SWT.READ_ONLY);
2346
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2347
		multiOperator.setLayoutData(data);
2348
		multiOperator.setFont(font);
2349
		multiOperator.addSelectionListener(new SelectionAdapter() {
2350
			public void widgetSelected(SelectionEvent e) {
2351
				setupMultiOperatorAndField(false);
2352
				storeMultiSelection();
2353
			}
2354
		});
2355
		
2356
		multiArgumentComposite = new Composite(composite, SWT.NONE);
2357
		
2358
		GridLayout layout = new GridLayout();
2359
		layout.numColumns = 1;
2360
		layout.marginWidth = 0;
2361
		layout.horizontalSpacing = 0;
2362
		layout.verticalSpacing = 0;
2363
		layout.marginBottom = 0;
2364
		layout.marginHeight = 0;
2365
		multiArgumentComposite.setLayout(layout);
2366
		data = new GridData(SWT.FILL, SWT.TOP, true, true);
2367
		multiArgumentComposite.setLayoutData(data);
2368
		multiArgumentComposite.setFont(font);
2369
2370
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2371
		String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key);
2372
		int index = multiKey.indexOf(local);
2373
		if (index != -1)
2374
			multiKey.select(index);
2375
		else
2376
			multiKey.select(0);
2377
		
2378
		setupMultiOperatorAndField(true);
2379
	}
2380
2381
	private void setupMultiOperatorAndField(boolean updateOperator) {
2382
		boolean isUsingRegularExpression = false;
2383
		String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2384
		if (updateOperator) {
2385
			String[] operators = getLocalOperatorsForKey(selectedKey);
2386
			multiOperator.setItems(operators);
2387
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2388
			String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
2389
			int index = multiOperator.indexOf(local);
2390
			if (index != -1)
2391
				multiOperator.select(index);
2392
			else
2393
				multiOperator.select(0);
2394
		}
2395
		String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2396
		
2397
		Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2398
		
2399
		if (intiantiatedKeyOperatorType != null) {
2400
			if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType))
2401
				return;
2402
			if (arguments != null) {
2403
				arguments.dispose();
2404
				arguments = null;
2405
			}
2406
			if (attributeStringArgumentComposite != null) {
2407
				attributeStringArgumentComposite.dispose();
2408
				attributeStringArgumentComposite = null;
2409
			}
2410
			if (stringArgumentComposite != null) {
2411
				stringArgumentComposite.dispose();
2412
				stringArgumentComposite = null;
2413
			}
2414
			if (argumentsBoolean != null) {
2415
				argumentsBoolean.dispose();
2416
				argumentsBoolean = null;
2417
			}
2418
			if (argumentsDate != null) {
2419
				argumentsDate.dispose();
2420
				argumentsDate = null;
2421
			}
2422
			if (argumentsRegularExpresion != null) {
2423
				argumentsRegularExpresion.dispose();
2424
				argumentsRegularExpresion = null;
2425
			}
2426
			if (argumentsCaseSensitive != null) {
2427
				argumentsCaseSensitive.dispose();
2428
				argumentsCaseSensitive = null;
2429
			}
2430
			fContentAssistField = null;
2431
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2432
			argument.pattern = new String();
2433
			filter.setArguments(MultiMatcher.encodeArguments(argument));
2434
		}
2435
		if (selectedKeyOperatorType.equals(String.class)) {
2436
			stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);
2437
			
2438
			GridData data;
2439
			GridLayout layout = new GridLayout();
2440
			layout.numColumns = 2;
2441
			layout.marginWidth = 0;
2442
			layout.horizontalSpacing = 0;
2443
			layout.verticalSpacing = 0;
2444
			layout.marginBottom = 0;
2445
			layout.marginHeight = 0;
2446
			stringArgumentComposite.setLayout(layout);
2447
			data = new GridData(SWT.FILL, SWT.TOP, true, true);
2448
			stringArgumentComposite.setLayoutData(data);
2449
			stringArgumentComposite.setFont(multiArgumentComposite.getFont());
2450
2451
			arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER);
2452
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2453
			data.minimumWidth = 100;
2454
			arguments.setLayoutData(data);
2455
			arguments.setFont(stringArgumentComposite.getFont());
2456
			arguments.addModifyListener(new ModifyListener() {
2457
				public void modifyText(ModifyEvent e) {
2458
					storeMultiSelection();
2459
				}
2460
			});
2461
			if (filter.hasStringArguments()) {
2462
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2463
				arguments.setText(argument.pattern);
2464
				isUsingRegularExpression = argument.regularExpression;
2465
			}
2466
	
2467
			attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE);
2468
			
2469
			layout = new GridLayout();
2470
			layout.numColumns = 1;
2471
			layout.marginWidth = 0;
2472
			layout.horizontalSpacing = 0;
2473
			layout.verticalSpacing = 0;
2474
			layout.marginBottom = 0;
2475
			layout.marginHeight = 0;
2476
			attributeStringArgumentComposite.setLayout(layout);
2477
			data = new GridData(SWT.FILL, SWT.TOP, false, true);
2478
			attributeStringArgumentComposite.setLayoutData(data);
2479
			attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont());
2480
2481
			argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK);
2482
			argumentsCaseSensitive.setText(NLS.bind(
2483
					IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
2484
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2485
			argumentsCaseSensitive.setLayoutData(data);
2486
			argumentsCaseSensitive.setFont(stringArgumentComposite.getFont());
2487
			argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
2488
				public void widgetSelected(SelectionEvent e) {
2489
					storeMultiSelection();
2490
				}
2491
			});
2492
2493
			argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK);
2494
			argumentsRegularExpresion.setText(NLS.bind(
2495
					IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
2496
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2497
			argumentsRegularExpresion.setLayoutData(data);
2498
			argumentsRegularExpresion.setFont(stringArgumentComposite.getFont());
2499
			argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
2500
				public void widgetSelected(SelectionEvent e) {
2501
					setupDescriptionText();
2502
					storeMultiSelection();
2503
					if (fContentAssistField != null)
2504
						fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
2505
				}
2506
			});
2507
2508
			TextContentAdapter contentAdapter= new TextContentAdapter();
2509
			FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2510
			fContentAssistField= new ContentAssistCommandAdapter(
2511
					arguments,
2512
					contentAdapter,
2513
					findProposer, 
2514
					null,
2515
					new char[] {'\\', '[', '('},
2516
					true);
2517
		}
2518
		if (selectedKeyOperatorType.equals(Integer.class)) {
2519
			GridData data;
2520
			arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
2521
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2522
			data.minimumWidth = 100;
2523
			arguments.setLayoutData(data);
2524
			arguments.setFont(multiArgumentComposite.getFont());
2525
			arguments.addModifyListener(new ModifyListener() {
2526
				public void modifyText(ModifyEvent e) {
2527
					storeMultiSelection();
2528
				}
2529
			});
2530
			if (filter.hasStringArguments()) {
2531
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2532
				arguments.setText(convertToEditableLength(argument.pattern));
2533
			}
2534
		}
2535
		if (selectedKeyOperatorType.equals(Date.class)) {
2536
			GridData data;
2537
			argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM);
2538
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2539
			argumentsDate.setLayoutData(data);
2540
			argumentsDate.setFont(multiArgumentComposite.getFont());
2541
			argumentsDate.addSelectionListener(new SelectionAdapter() {
2542
				public void widgetSelected(SelectionEvent e) {
2543
					storeMultiSelection();
2544
				}
2545
			});
2546
			if (filter.hasStringArguments()) {
2547
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2548
				Date date; 
2549
				Calendar calendar = Calendar.getInstance();
2550
				try {
2551
					date = new Date(Long.parseLong(argument.pattern));
2552
					calendar.setTime(date);
2553
				} catch (NumberFormatException e1) {
2554
					date = new Date();
2555
					calendar.setTime(date);
2556
					argument.pattern = Long.toString(calendar.getTimeInMillis());
2557
				}
2558
				argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
2559
				argumentsDate.setMonth(calendar.get(Calendar.MONTH));
2560
				argumentsDate.setYear(calendar.get(Calendar.YEAR));
2561
			}
2562
		}
2563
		if (selectedKeyOperatorType.equals(Boolean.class)) {
2564
			GridData data;
2565
			argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
2566
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2567
			argumentsBoolean.setLayoutData(data);
2568
			argumentsBoolean.setFont(multiArgumentComposite.getFont());
2569
			argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())});
2570
			argumentsBoolean.addSelectionListener(new SelectionAdapter() {
2571
				public void widgetSelected(SelectionEvent e) {
2572
					storeMultiSelection();
2573
				}
2574
			});
2575
			if (filter.hasStringArguments()) {
2576
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2577
				if (argument.pattern.length() == 0)
2578
					argumentsBoolean.select(0);
2579
				else
2580
					argumentsBoolean.select(Boolean.parseBoolean(argument.pattern) ? 0:1);
2581
			}
2582
		}
2583
		multiArgumentComposite.layout(true);
2584
		intiantiatedKeyOperatorType = selectedKeyOperatorType;
2585
		
2586
		if (fContentAssistField != null)
2587
			fContentAssistField.setEnabled(isUsingRegularExpression);
2588
2589
		shell.layout(true);
2590
		shell.redraw();
2591
		setupDescriptionText();
2592
	}
2593
2594
	private String[] lengthPrefixes = {new String(), "k", "m", "g"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
2595
2596
	// converts "32768" to "32k"
2597
	private String convertToEditableLength(String string) {
2598
		if (string.length() == 0)
2599
			return string;
2600
		long value;
2601
		try {
2602
			value = Long.parseLong(string);
2603
		} catch (NumberFormatException e) {
2604
			value = 0;
2605
		}
2606
		if (value == 0)
2607
			return Long.toString(0);
2608
		for (int i = 0; i < lengthPrefixes.length; i++) {
2609
			if (value % 1024 != 0)
2610
				return Long.toString(value) + lengthPrefixes[i];
2611
			if ((i + 1) < lengthPrefixes.length)
2612
				value /= 1024;
2613
		}
2614
		return Long.toString(value) + lengthPrefixes[lengthPrefixes.length - 1];
2615
	}
2616
	
2617
	// converts "32k" to "32768"
2618
	private String convertFromEditableLength(String string) throws NumberFormatException {
2619
		if (string.length() == 0)
2620
			return string;
2621
		for (int i = 1; i < lengthPrefixes.length; i++) {
2622
			if (string.endsWith(lengthPrefixes[i])) {
2623
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2624
				value *= Math.pow(1024, i);
2625
				return Long.toString(value);
2626
			}
2627
		}
2628
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2629
		return Long.toString(Long.parseLong(string));
2630
	}
2631
	
2632
	private void storeMultiSelection() {
2633
		if (intiantiatedKeyOperatorType != null) {
2634
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2635
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2636
	
2637
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2638
			argument.key = selectedKey;
2639
			argument.operator = selectedOperator;
2640
			
2641
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2642
				Calendar calendar = Calendar.getInstance();
2643
				calendar.set(argumentsDate.getYear(), argumentsDate.getMonth(), argumentsDate.getDay());
2644
				argument.pattern = Long.toString(calendar.getTimeInMillis());
2645
			}
2646
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2647
				argument.pattern = arguments.getText();
2648
				argument.regularExpression = argumentsRegularExpresion.getSelection();
2649
				argument.caseSensitive = argumentsCaseSensitive.getSelection();
2650
			}
2651
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2652
				try {
2653
					argument.pattern = convertFromEditableLength(arguments.getText());
2654
				} catch (NumberFormatException e) {
2655
					argument.pattern = arguments.getText();
2656
				}
2657
			}
2658
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null)
2659
				argument.pattern = MultiMatcherLocalization.getMultiMatcherKey(argumentsBoolean.getText());
2660
			String encodedArgument = MultiMatcher.encodeArguments(argument);
2661
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument);
2662
		}
2663
	}
2664
2665
	private String[] getLocalOperatorsForKey(String key) {
2666
		String [] operators = MultiMatcher.getOperatorsForKey(key);
2667
		String[] result = new String[operators.length];
2668
		for (int i = 0; i < operators.length; i++)
2669
			result[i] = MultiMatcherLocalization.getLocalMultiMatcherKey(operators[i]);
2670
		return result;
2671
	}
2672
2673
	private String[] getMultiMatcherKeys() {
2674
		ArrayList list = new ArrayList();
2675
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_NAME));
2676
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_WORKSPACE_PATH));
2677
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LOCATION));
2678
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LAST_MODIFIED));
2679
		if (MultiMatcher.supportCreatedKey())
2680
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_CREATED));
2681
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LENGTH));
2682
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_READONLY));
2683
		if (!Platform.getOS().equals(Platform.OS_WIN32))
2684
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_SYMLINK));
2685
		return (String []) list.toArray(new String[0]);
2686
	}
2687
2688
	/* (non-Javadoc)
2689
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
2690
	 */
2691
	public void selectionChanged() {
2692
	}
2693
2694
	/**
2695
	 * @throws CoreException  
2696
	 */
2697
	/* (non-Javadoc)
2698
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
2699
	 */
2700
	public void validate() throws CoreException {
2701
		if (intiantiatedKeyOperatorType != null) {
2702
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2703
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2704
	
2705
			MultiMatcher.Argument argument = new MultiMatcher.Argument();
2706
			argument.key = selectedKey;
2707
			argument.operator = selectedOperator;
2708
			
2709
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2710
			}
2711
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2712
			}
2713
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2714
				try {
2715
					convertFromEditableLength(arguments.getText());
2716
				} catch (NumberFormatException e) {
2717
					throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2718
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidFileLength, arguments.getText()), e));
2719
				}
2720
			}
2721
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) {
2722
				
2723
			}
2724
		}
2725
	}
2726
}
2727
2728
class DefaultCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2729
2730
	Shell shell;
2731
	FilterCopy filter;
2732
	protected Text arguments;
2733
	protected Label argumentsLabel;
2734
	protected Label description;
2735
	protected ContentAssistCommandAdapter fContentAssistField;
2736
2737
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilterMatcher"; //$NON-NLS-1$
2738
2739
	/**
2740
	 * @param parentShell
2741
	 * @param filter
2742
	 */
2743
	public DefaultCustomFilterArgumentUI(Shell parentShell, FilterCopy filter) {
2744
		this.shell = parentShell;
2745
		this.filter = filter;
2746
	}
2747
2748
	/* (non-Javadoc)
2749
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2750
	 */
2751
	public Object getID() {
2752
		return new String();
2753
	}
2754
2755
	/* (non-Javadoc)
2756
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2757
	 */
2758
	public void dispose() {
2759
		Widget list[] = new Widget[] {arguments, argumentsLabel, description};
2760
		for (int i = 0; i < list.length; i++) {
2761
			if (list[i] != null) {
2762
				list[i].dispose();
2763
			}
2764
		}
2765
		arguments = null;
2766
		argumentsLabel = null;
2767
		fContentAssistField = null;
2768
		description = null;
2769
	}
2770
2771
	/* (non-Javadoc)
2772
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2773
	 */
2774
	public void create(Composite argumentComposite, Font font) {
2775
		GridLayout layout = new GridLayout();
2776
		layout.numColumns = 2;
2777
		layout.marginWidth = 0;
2778
		argumentComposite.setLayout(layout);
2779
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2780
		argumentComposite.setLayoutData(data);
2781
		argumentComposite.setFont(font);
2782
		if (filter.hasStringArguments())
2783
			createArgumentsArea(font, argumentComposite);
2784
2785
		createDescriptionArea(font, argumentComposite);
2786
2787
		if (fContentAssistField != null)
2788
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
2789
		argumentComposite.layout(true);
2790
	}
2791
	
2792
	private void createArgumentsArea(Font font, Composite composite) {
2793
		GridData data;
2794
		argumentsLabel = addLabel(composite, NLS.bind(
2795
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
2796
				null));
2797
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
2798
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2799
		arguments.setLayoutData(data);
2800
		arguments.setFont(font);
2801
		arguments.addModifyListener(new ModifyListener() {
2802
			public void modifyText(ModifyEvent e) {
2803
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
2804
						arguments.getText());
2805
			}
2806
		});
2807
		if (filter.hasStringArguments())
2808
			arguments.setText((String) FilterTypeUtil.getValue(filter,
2809
					FilterTypeUtil.ARGUMENTS));
2810
		arguments.setEnabled(filter.hasStringArguments());
2811
		setArgumentLabelEnabled();
2812
2813
		TextContentAdapter contentAdapter= new TextContentAdapter();
2814
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2815
		fContentAssistField= new ContentAssistCommandAdapter(
2816
				arguments,
2817
				contentAdapter,
2818
				findProposer, 
2819
				null,
2820
				new char[] {'\\', '[', '('},
2821
				true);
2822
	}
2823
2824
	private void setArgumentLabelEnabled() {
2825
		if (argumentsLabel != null) {
2826
			Color color = argumentsLabel.getDisplay().getSystemColor(
2827
					filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
2828
			argumentsLabel.setForeground(color);
2829
		}
2830
	}
2831
2832
	Label addLabel(Composite composite, String text) {
2833
		String delimiter = ":"; //$NON-NLS-1$
2834
2835
		Font font = composite.getFont();
2836
		Label label = new Label(composite, SWT.LEFT);
2837
		label.setText(text + delimiter);
2838
		GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
2839
		label.setLayoutData(data);
2840
		label.setFont(font);
2841
		return label;
2842
	}
2843
2844
	/* (non-Javadoc)
2845
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
2846
	 */
2847
	public void selectionChanged() {
2848
		if (arguments != null)
2849
			arguments.setEnabled(filter.hasStringArguments());
2850
		setArgumentLabelEnabled();
2851
		if (fContentAssistField != null)
2852
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
2853
		description.setText(FilterTypeUtil
2854
				.getDescriptor(filter.getId()).getDescription());
2855
	}
2856
2857
	/**
2858
	 * @param font
2859
	 * @param composite
2860
	 */
2861
	private void createDescriptionArea(Font font, Composite composite) {
2862
		GridData data;
2863
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2864
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
2865
				.getDescription());
2866
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2867
		data.widthHint = 300;
2868
		data.heightHint = 40;
2869
		data.horizontalSpan = 2;
2870
		description.setLayoutData(data);
2871
		description.setFont(font);
2872
	}
2873
2874
	/**
2875
	 * @throws CoreException  
2876
	 */
2877
	/* (non-Javadoc)
2878
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
2879
	 */
2880
	public void validate() throws CoreException {
2881
		// nothing
2882
	}
2883
}
2884
2885
class MultiMatcherLocalization {
2886
	
2887
	static String[][] multiMatcherKey = {
2888
			{MultiMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName},
2889
			{MultiMatcher.KEY_WORKSPACE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyWorkspacePath},
2890
			{MultiMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation},
2891
			{MultiMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified},
2892
			{MultiMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated},
2893
			{MultiMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength},
2894
			{MultiMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly},
2895
			{MultiMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink},
2896
			{MultiMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter},
2897
			{MultiMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore},
2898
			{MultiMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals},
2899
			{MultiMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches},
2900
			{MultiMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan},
2901
			{MultiMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan},
2902
			{MultiMatcher.OPERATOR_WITHIN, IDEWorkbenchMessages.ResourceFilterPage_multiWithin},
2903
			{Boolean.TRUE.toString(), IDEWorkbenchMessages.ResourceFilterPage_true},
2904
			{Boolean.FALSE.toString(), IDEWorkbenchMessages.ResourceFilterPage_false}
2905
	};
2906
	
2907
	static public String getLocalMultiMatcherKey(String key) {
2908
		for (int i = 0; i < multiMatcherKey.length; i++) {
2909
			if (multiMatcherKey[i][0].equals(key))
2910
				return multiMatcherKey[i][1];
2911
		}
2912
		return null;
2913
	}
2914
	
2915
	static public String getMultiMatcherKey(String local) {
2916
		for (int i = 0; i < multiMatcherKey.length; i++) {
2917
			if (multiMatcherKey[i][1].equals(local))
2918
				return multiMatcherKey[i][0];
2919
		}
2920
		return null;
2921
	}
2922
	
2102
}
2923
}
(-)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_WORKSPACE_PATH = "workspacePath"; //$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_WORKSPACE_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_WORKSPACE_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.parseBoolean(argument.substring(0, index));
184
		argument = argument.substring(index + 1);
185
		
186
		index = argument.indexOf(DELIMITER);
187
		if (index == -1)
188
			return result;
189
190
		result.regularExpression = Boolean.parseBoolean(argument.substring(0, index));
191
		result.pattern = argument.substring(index + 1);
192
193
		return result;
194
	}
195
196
197
	static private String DELIMITER = "-"; //$NON-NLS-1$
198
	static private String VERSION_IMPLEMENTATION = "1.0"; //$NON-NLS-1$
199
200
	/*
201
	 * return value in milliseconds since epoch(1970-01-01T00:00:00Z)
202
	 */
203
	private static long getFileCreationTime(String fullPath) {
204
		/*
205
		java.nio.file.FileSystem fs = java.nio.file.FileSystems.getDefault();
206
		java.nio.file.FileRef fileRef = fs.getPath(file);
207
		java.nio.file.attribute.BasicFileAttributes attributes = java.nio.file.attribute.Attributes.readBasicFileAttributes(fileRef);
208
		return attributes.creationTime();
209
        */
210
211
		try {
212
			Class fileSystems = Class.forName("java.nio.file.FileSystems"); //$NON-NLS-1$
213
			Method getDefault = fileSystems.getMethod("getDefault", null); //$NON-NLS-1$
214
			Object fs = getDefault.invoke(null, null);
215
	
216
			Class fileRef = Class.forName("java.nio.file.FileRef"); //$NON-NLS-1$
217
			Method getPath = fileRef.getMethod("getPath", new Class[] {String.class}); //$NON-NLS-1$
218
			Object fileRefObj = getPath.invoke(fs, new Object[] {fullPath});
219
			
220
			Class attributes = Class.forName("java.nio.file.attribute.Attributes"); //$NON-NLS-1$
221
			Method readBasicFileAttributes = attributes.getMethod("readBasicFileAttributes", new Class[] {fileRef}); //$NON-NLS-1$
222
			Object attributesObj = readBasicFileAttributes.invoke(null, new Object[] {fileRefObj});
223
	
224
			Class basicAttributes = Class.forName("java.nio.file.attribute.BasicFileAttributes"); //$NON-NLS-1$
225
			Method creationTime = basicAttributes.getMethod("creationTime", null); //$NON-NLS-1$
226
			Object time = creationTime.invoke(attributesObj, null);
227
	
228
			Class fileTime = Class.forName("java.nio.file.attribute.FileTime"); //$NON-NLS-1$
229
			Method toMillis = fileTime.getMethod("toMillis", null); //$NON-NLS-1$
230
			Object result = toMillis.invoke(time, null);
231
			
232
			if (result instanceof Long)
233
				return ((Long) result).longValue();
234
		} catch (ClassNotFoundException e) {
235
			e.printStackTrace();
236
		} catch (IllegalArgumentException e) {
237
			e.printStackTrace();
238
		} catch (IllegalAccessException e) {
239
			e.printStackTrace();
240
		} catch (InvocationTargetException e) {
241
			e.printStackTrace();
242
		} catch (SecurityException e) {
243
			e.printStackTrace();
244
		} catch (NoSuchMethodException e) {
245
			e.printStackTrace();
246
		} 
247
		return 0;
248
	}
249
	
250
	MatcherCache matcher = null;
251
	private boolean fSupportsCreatedKey;
252
253
	class MatcherCache {
254
		public MatcherCache(String arguments) {
255
			argument = decodeArguments(arguments);
256
			type = getTypeForKey(argument.key, argument.operator);
257
			if (type.equals(String.class)) {
258
				if (argument.regularExpression == false)
259
					stringMatcher = new StringMatcher(argument.pattern, argument.caseSensitive == false, false);
260
				else
261
					regExPattern = Pattern.compile(argument.pattern, argument.caseSensitive ? 0:Pattern.CASE_INSENSITIVE);
262
			}
263
		}
264
		
265
266
		Argument argument;
267
		Class type;
268
		StringMatcher stringMatcher = null;
269
		Pattern regExPattern = null;
270
271
		public boolean match(IContainer parent, IFileInfo fileInfo) {
272
			if (type.equals(String.class)) {
273
				String value = new String();
274
				if (argument.key.equals(KEY_NAME))
275
					value = fileInfo.getName();
276
				if (argument.key.equals(KEY_WORKSPACE_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.DATE,-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.parseBoolean(argument.pattern);
354
				if (argument.key.equals(KEY_IS_READONLY)) {
355
					IFileInfo info = fetchInfo(parent, fileInfo);
356
					if (!info.exists())
357
						return false;
358
					return info.getAttribute(EFS.ATTRIBUTE_READ_ONLY) == parameter;
359
				}
360
				if (argument.key.equals(KEY_IS_SYMLINK)) {
361
					IFileInfo info = fetchInfo(parent, fileInfo);
362
					if (!info.exists())
363
						return false;
364
					return info.getAttribute(EFS.ATTRIBUTE_SYMLINK) == parameter;
365
				}
366
			}
367
			return false;
368
		}
369
370
		private long roundToOneDay(long parameter) {
371
			return parameter / (1000 * 60 * 60 * 24); // 1000 ms in 1 sec, 60 sec in 1 min, 60 min in 1 hour, 24 hours in 1 day 
372
		}
373
374
		private IFileInfo fetchInfo(IContainer parent, IFileInfo fileInfo) {
375
			IFileStore fileStore;
376
			try {
377
				fileStore = EFS.getStore(parent.getLocationURI());
378
			} catch (CoreException e) {
379
				return fileInfo;
380
			}
381
			IFileStore store = fileStore.getChild(fileInfo.getName());
382
			return store.fetchInfo();
383
		}
384
	}
385
	/**
386
	 * Creates a new factory for this filter type.
387
	 */
388
	public MultiMatcher() {
389
		fSupportsCreatedKey = supportCreatedKey();
390
	}
391
392
	/* (non-Javadoc)
393
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#initialize(org.eclipse.core.resources.IProject, java.lang.Object)
394
	 */
395
	public void initialize(IProject project, Object arguments) throws CoreException {
396
		try {
397
			if ((arguments instanceof String) && ((String) arguments).length() > 0)
398
				matcher = new MatcherCache((String) arguments);
399
		} catch (PatternSyntaxException e) {
400
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
401
		} catch (NumberFormatException e) {
402
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
403
		}
404
	}
405
406
	/* (non-Javadoc)
407
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#matches(org.eclipse.core.filesystem.IFileInfo)
408
	 */
409
	public boolean matches(IContainer parent, IFileInfo fileInfo) throws CoreException {
410
		if (matcher != null) {
411
			return matcher.match(parent, fileInfo);
412
		}
413
		return false;
414
	}
415
}

Return to bug 301820