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 = File and Folder Attributes
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.FileInfoAttributesMatcher"
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 (-12 / +36 lines)
Lines 53-68 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_downButtonLabel;
60
	public static String ResourceFilterPage_addNewFilterTitle;
61
	public static String ResourceFilterPage_columnFilterID;
62
	public static String ResourceFilterPage_columnFilterMode;
59
	public static String ResourceFilterPage_columnFilterMode;
63
	public static String ResourceFilterPage_columnFilterTargets;
60
	public static String ResourceFilterPage_columnFilterDescription;
64
	public static String ResourceFilterPage_columnFilterInheritable;
61
	public static String ResourceFilterPage_columnFilterTarget;
65
	public static String ResourceFilterPage_columnFilterArguments;
62
	public static String ResourceFilterPage_columnFilterPattern;
63
	public static String ResourceFilterPage_applyRecursivelyToFolderStructure;
64
	public static String ResourceFilterPage_condition;
65
	public static String ResourceFilterPage_caseSensitive;
66
	public static String ResourceFilterPage_regularExpression;
67
	public static String ResourceFilterPage_multiMatcher_Matcher;
68
	public static String ResourceFilterPage_multiMatcher_FileLength;
69
	public static String ResourceFilterPage_multiMatcher_TimeInterval;
70
	public static String ResourceFilterPage_multiMatcher_InvalidFileLength;
71
	public static String ResourceFilterPage_multiMatcher_InvalidTimeInterval;
66
	public static String ResourceFilterPage_includeOnly;
72
	public static String ResourceFilterPage_includeOnly;
67
	public static String ResourceFilterPage_excludeAll;
73
	public static String ResourceFilterPage_excludeAll;
68
	public static String ResourceFilterPage_includeOnlyColumn;
74
	public static String ResourceFilterPage_includeOnlyColumn;
Lines 70-82 Link Here
70
	public static String ResourceFilterPage_filesAndFolders;
76
	public static String ResourceFilterPage_filesAndFolders;
71
	public static String ResourceFilterPage_files;
77
	public static String ResourceFilterPage_files;
72
	public static String ResourceFilterPage_folders;
78
	public static String ResourceFilterPage_folders;
73
	public static String ResourceFilterPage_filesAndFoldersColumn;
74
	public static String ResourceFilterPage_filesColumn;
75
	public static String ResourceFilterPage_foldersColumn;
76
	public static String ResourceFilterPage_editFilterDialogTitle;
79
	public static String ResourceFilterPage_editFilterDialogTitle;
77
	public static String ResourceFilterPage_invalidFilterArgument;
80
	public static String ResourceFilterPage_newFilterDialogTitleIncludeOnly;
78
	public static String ResourceFilterPage_description;
81
	public static String ResourceFilterPage_newFilterDialogTitleExcludeAll;
79
	public static String ResourceFilterPage_addSubFilterActionLabel;
82
	public static String ResourceFilterPage_addSubFilterActionLabel;
83
	public static String ResourceFilterPage_addSubFilterGroupActionLabel;
84
	public static String ResourceFilterPage_removeFilterActionLabel;
85
	public static String ResourceFilterPage_editFilterActionLabel;
86
	public static String ResourceFilterPage_multiKeyName;
87
	public static String ResourceFilterPage_multiKeyProjectRelativePath;
88
	public static String ResourceFilterPage_multiKeyLocation;
89
	public static String ResourceFilterPage_multiKeyLastModified;
90
	public static String ResourceFilterPage_multiKeyCreated;
91
	public static String ResourceFilterPage_multiKeyLength;
92
	public static String ResourceFilterPage_multiKeyReadOnly;
93
	public static String ResourceFilterPage_multiKeySymLink;
94
	public static String ResourceFilterPage_multiEquals;
95
	public static String ResourceFilterPage_multiMatches;
96
	public static String ResourceFilterPage_multiLargerThan;
97
	public static String ResourceFilterPage_multiSmallerThan;
98
	public static String ResourceFilterPage_multiBefore;
99
	public static String ResourceFilterPage_multiAfter;
100
	public static String ResourceFilterPage_multiWithin;
101
	public static String ResourceFilterPage_true;
102
	public static String ResourceFilterPage_false;
103
	
80
	//
104
	//
81
	//
105
	//
82
	// Copies from org.eclipse.ui.workbench
106
	// Copies from org.eclipse.ui.workbench
(-)src/org/eclipse/ui/internal/ide/messages.properties (-19 / +42 lines)
Lines 570-602 Link Here
570
ResourceInfo_file = File
570
ResourceInfo_file = File
571
ResourceInfo_fileTypeFormat = File  ({0})
571
ResourceInfo_fileTypeFormat = File  ({0})
572
ResourceInfoPage_noResource=Resource information is not available for the current selection.
572
ResourceInfoPage_noResource=Resource information is not available for the current selection.
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=A file system object will be added to the workspace tree during the refresh operation\nif 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_columnFilterMode=Operation
579
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_columnFilterDescription=Description
580
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_columnFilterTarget=Applies to
581
ResourceFilterPage_columnFilterID=T&ype
582
ResourceFilterPage_columnFilterPattern=&Pattern
582
ResourceFilterPage_columnFilterMode=Mode
583
ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure
583
ResourceFilterPage_columnFilterTargets=Target
584
ResourceFilterPage_condition=Con&dition:
584
ResourceFilterPage_columnFilterInheritable=In&heritable
585
ResourceFilterPage_caseSensitive=&Case sensitive
585
ResourceFilterPage_columnFilterArguments=&Pattern
586
ResourceFilterPage_regularExpression=Re&gular expression
586
ResourceFilterPage_includeOnly=&Include
587
ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \)
587
ResourceFilterPage_excludeAll=&Exclude
588
ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes, *g = gigabytes)
588
ResourceFilterPage_includeOnlyColumn=Include
589
ResourceFilterPage_multiMatcher_TimeInterval= (*s = seconds, *m = minutes, *h = hours, *d = days)
589
ResourceFilterPage_excludeAllColumn=Exclude
590
ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0}
591
ResourceFilterPage_multiMatcher_InvalidTimeInterval=Invalid time interval syntax: {0}
592
ResourceFilterPage_includeOnly=&Include only
593
ResourceFilterPage_excludeAll=&Exclude all
594
ResourceFilterPage_includeOnlyColumn=Include only:
595
ResourceFilterPage_excludeAllColumn=Exclude all:
590
ResourceFilterPage_filesAndFolders=Files &and folders
596
ResourceFilterPage_filesAndFolders=Files &and folders
591
ResourceFilterPage_files=&Files
597
ResourceFilterPage_files=&Files
592
ResourceFilterPage_folders=F&olders
598
ResourceFilterPage_folders=F&olders
593
ResourceFilterPage_filesAndFoldersColumn=Files and folders
594
ResourceFilterPage_filesColumn=Files
595
ResourceFilterPage_foldersColumn=Folders
596
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
599
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
597
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
600
ResourceFilterPage_newFilterDialogTitleIncludeOnly=Add 'Include Only' Resource Filter
598
ResourceFilterPage_description=Description
601
ResourceFilterPage_newFilterDialogTitleExcludeAll=Add 'Exclude All' Resource Filter
599
ResourceFilterPage_addSubFilterActionLabel=Add Condition...
602
ResourceFilterPage_addSubFilterActionLabel=&Add...
603
ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group...
604
ResourceFilterPage_removeFilterActionLabel=&Remove
605
ResourceFilterPage_editFilterActionLabel=&Edit
606
ResourceFilterPage_multiKeyName=Name
607
ResourceFilterPage_multiKeyProjectRelativePath=Project Relative Path
608
ResourceFilterPage_multiKeyLocation=Location
609
ResourceFilterPage_multiKeyLastModified=Last Modified
610
ResourceFilterPage_multiKeyCreated=Date Created
611
ResourceFilterPage_multiKeyLength=File Length
612
ResourceFilterPage_multiKeyReadOnly=Read Only
613
ResourceFilterPage_multiKeySymLink=Symbolic Link
614
ResourceFilterPage_multiEquals=equals
615
ResourceFilterPage_multiMatches=matches
616
ResourceFilterPage_multiLargerThan=is larger than
617
ResourceFilterPage_multiSmallerThan=is smaller than
618
ResourceFilterPage_multiBefore=is before
619
ResourceFilterPage_multiAfter=is after
620
ResourceFilterPage_multiWithin=is within
621
ResourceFilterPage_true=true
622
ResourceFilterPage_false=false
600
ResourceInfo_folder = Folder
623
ResourceInfo_folder = Folder
601
ResourceInfo_project = Project
624
ResourceInfo_project = Project
602
ResourceInfo_linkedFile = Linked File
625
ResourceInfo_linkedFile = Linked File
(-)src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java (-541 / +1682 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.lang.reflect.Field;
20
import java.text.DateFormat;
21
import java.util.ArrayList;
19
import java.util.Arrays;
22
import java.util.Arrays;
23
import java.util.Calendar;
24
import java.util.Comparator;
25
import java.util.Date;
20
import java.util.Iterator;
26
import java.util.Iterator;
21
import java.util.LinkedList;
27
import java.util.LinkedList;
28
import java.util.TreeMap;
22
29
23
import org.eclipse.core.internal.resources.FilterDescriptor;
30
import org.eclipse.core.internal.resources.FilterDescriptor;
24
import org.eclipse.core.resources.FileInfoMatcherDescription;
31
import org.eclipse.core.resources.FileInfoMatcherDescription;
Lines 32-62 Link Here
32
import org.eclipse.core.runtime.Assert;
39
import org.eclipse.core.runtime.Assert;
33
import org.eclipse.core.runtime.CoreException;
40
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
41
import org.eclipse.core.runtime.IPath;
42
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.NullProgressMonitor;
43
import org.eclipse.core.runtime.NullProgressMonitor;
44
import org.eclipse.core.runtime.Platform;
45
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.action.Action;
46
import org.eclipse.jface.action.Action;
37
import org.eclipse.jface.action.MenuManager;
47
import org.eclipse.jface.action.MenuManager;
48
import org.eclipse.jface.action.Separator;
38
import org.eclipse.jface.dialogs.Dialog;
49
import org.eclipse.jface.dialogs.Dialog;
39
import org.eclipse.jface.dialogs.ErrorDialog;
50
import org.eclipse.jface.dialogs.ErrorDialog;
40
import org.eclipse.jface.dialogs.IDialogConstants;
51
import org.eclipse.jface.dialogs.IDialogConstants;
41
import org.eclipse.jface.dialogs.TrayDialog;
52
import org.eclipse.jface.dialogs.TrayDialog;
42
import org.eclipse.jface.fieldassist.TextContentAdapter;
53
import org.eclipse.jface.fieldassist.TextContentAdapter;
54
import org.eclipse.jface.layout.TreeColumnLayout;
55
import org.eclipse.jface.resource.CompositeImageDescriptor;
43
import org.eclipse.jface.resource.ImageDescriptor;
56
import org.eclipse.jface.resource.ImageDescriptor;
44
import org.eclipse.jface.resource.JFaceResources;
57
import org.eclipse.jface.resource.JFaceResources;
45
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
58
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
46
import org.eclipse.jface.viewers.CellEditor;
59
import org.eclipse.jface.viewers.CellEditor;
47
import org.eclipse.jface.viewers.CheckboxCellEditor;
60
import org.eclipse.jface.viewers.CheckboxCellEditor;
61
import org.eclipse.jface.viewers.ColumnWeightData;
48
import org.eclipse.jface.viewers.ComboBoxCellEditor;
62
import org.eclipse.jface.viewers.ComboBoxCellEditor;
49
import org.eclipse.jface.viewers.ICellModifier;
63
import org.eclipse.jface.viewers.ICellModifier;
50
import org.eclipse.jface.viewers.ILabelProviderListener;
51
import org.eclipse.jface.viewers.ISelection;
64
import org.eclipse.jface.viewers.ISelection;
52
import org.eclipse.jface.viewers.ISelectionChangedListener;
65
import org.eclipse.jface.viewers.ISelectionChangedListener;
53
import org.eclipse.jface.viewers.IStructuredSelection;
66
import org.eclipse.jface.viewers.IStructuredSelection;
54
import org.eclipse.jface.viewers.ITableLabelProvider;
55
import org.eclipse.jface.viewers.ITreeContentProvider;
67
import org.eclipse.jface.viewers.ITreeContentProvider;
56
import org.eclipse.jface.viewers.SelectionChangedEvent;
68
import org.eclipse.jface.viewers.SelectionChangedEvent;
69
import org.eclipse.jface.viewers.StructuredSelection;
70
import org.eclipse.jface.viewers.StyledCellLabelProvider;
71
import org.eclipse.jface.viewers.StyledString;
72
import org.eclipse.jface.viewers.StyledString.Styler;
57
import org.eclipse.jface.viewers.TextCellEditor;
73
import org.eclipse.jface.viewers.TextCellEditor;
58
import org.eclipse.jface.viewers.TreeViewer;
74
import org.eclipse.jface.viewers.TreeViewer;
59
import org.eclipse.jface.viewers.Viewer;
75
import org.eclipse.jface.viewers.Viewer;
76
import org.eclipse.jface.viewers.ViewerCell;
60
import org.eclipse.jface.viewers.ViewerDropAdapter;
77
import org.eclipse.jface.viewers.ViewerDropAdapter;
61
import org.eclipse.jface.window.Window;
78
import org.eclipse.jface.window.Window;
62
import org.eclipse.osgi.util.NLS;
79
import org.eclipse.osgi.util.NLS;
Lines 73-97 Link Here
73
import org.eclipse.swt.events.ModifyListener;
90
import org.eclipse.swt.events.ModifyListener;
74
import org.eclipse.swt.events.MouseEvent;
91
import org.eclipse.swt.events.MouseEvent;
75
import org.eclipse.swt.events.MouseListener;
92
import org.eclipse.swt.events.MouseListener;
93
import org.eclipse.swt.events.SelectionAdapter;
76
import org.eclipse.swt.events.SelectionEvent;
94
import org.eclipse.swt.events.SelectionEvent;
77
import org.eclipse.swt.events.SelectionListener;
78
import org.eclipse.swt.graphics.Color;
95
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.Font;
96
import org.eclipse.swt.graphics.Font;
97
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.FontMetrics;
98
import org.eclipse.swt.graphics.FontMetrics;
81
import org.eclipse.swt.graphics.GC;
99
import org.eclipse.swt.graphics.GC;
82
import org.eclipse.swt.graphics.Image;
100
import org.eclipse.swt.graphics.Image;
101
import org.eclipse.swt.graphics.Point;
102
import org.eclipse.swt.graphics.TextStyle;
83
import org.eclipse.swt.layout.GridData;
103
import org.eclipse.swt.layout.GridData;
84
import org.eclipse.swt.layout.GridLayout;
104
import org.eclipse.swt.layout.GridLayout;
85
import org.eclipse.swt.widgets.Button;
105
import org.eclipse.swt.widgets.Button;
86
import org.eclipse.swt.widgets.Combo;
106
import org.eclipse.swt.widgets.Combo;
87
import org.eclipse.swt.widgets.Composite;
107
import org.eclipse.swt.widgets.Composite;
88
import org.eclipse.swt.widgets.Control;
108
import org.eclipse.swt.widgets.Control;
109
import org.eclipse.swt.widgets.DateTime;
110
import org.eclipse.swt.widgets.Display;
111
import org.eclipse.swt.widgets.Event;
89
import org.eclipse.swt.widgets.Group;
112
import org.eclipse.swt.widgets.Group;
90
import org.eclipse.swt.widgets.Label;
113
import org.eclipse.swt.widgets.Label;
91
import org.eclipse.swt.widgets.Shell;
114
import org.eclipse.swt.widgets.Shell;
92
import org.eclipse.swt.widgets.TableItem;
115
import org.eclipse.swt.widgets.TableItem;
93
import org.eclipse.swt.widgets.Text;
116
import org.eclipse.swt.widgets.Text;
94
import org.eclipse.swt.widgets.TreeColumn;
117
import org.eclipse.swt.widgets.TreeColumn;
118
import org.eclipse.swt.widgets.Widget;
95
import org.eclipse.ui.IWorkbenchWindow;
119
import org.eclipse.ui.IWorkbenchWindow;
96
import org.eclipse.ui.PlatformUI;
120
import org.eclipse.ui.PlatformUI;
97
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
121
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
Lines 99-104 Link Here
99
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
123
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
100
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
124
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
101
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
125
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
126
import org.eclipse.ui.internal.ide.misc.FileInfoAttributesMatcher;
102
import org.eclipse.ui.plugin.AbstractUIPlugin;
127
import org.eclipse.ui.plugin.AbstractUIPlugin;
103
128
104
/**
129
/**
Lines 108-133 Link Here
108
public class ResourceFilterGroup {
133
public class ResourceFilterGroup {
109
134
110
	private Button addButton = null;
135
	private Button addButton = null;
136
	private Button addGroupButton = null;
111
	private Button removeButton = null;
137
	private Button removeButton = null;
112
	private Button upButton = null;
138
	private Button upButton = null;
113
	private Button downButton = null;
139
	private Button downButton = null;
114
	private Button editButton = null;
140
	private Button editButton = null;
115
141
116
	private TreeViewer filterView;
142
	private TreeViewer filterView;
143
	private TreeContentProvider filterViewContentProvider;
117
	private Filters filters;
144
	private Filters filters;
118
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
145
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
119
	private LabelProvider labelProvider;
146
	private LabelProvider labelProvider;
147
	private Font boldFont;
148
	private Font plainFont;
120
	private Image checkIcon = null;
149
	private Image checkIcon = null;
121
150
	private Image fileIcon = null;
151
	private Image folderIcon = null;
152
	private Image fileFolderIcon = null;
153
	private Image includeIcon = null;
154
	private Image excludeIcon = null;
155
	private Image inheritableIcon = null;
156
	private Image fileAloneIcon = null;
157
	private Image folderAloneIcon = null;
158
	private Image fileFolderAloneIcon = null;
159
	private Image fileInheritableIcon = null;
160
	private Image folderInheritableIcon = null;
161
	private Image fileFolderInheritableIcon = null;
122
	private boolean tableViewCellEditorAdequatlyUsable = false;
162
	private boolean tableViewCellEditorAdequatlyUsable = false;
123
	private boolean allowReordering = false;
124
125
	// parent shell
126
	private Shell shell;
163
	private Shell shell;
127
128
	private IContainer nonExistantResource = getNonExistantResource();
164
	private IContainer nonExistantResource = getNonExistantResource();
129
	private IContainer resource = nonExistantResource;
165
	private IContainer resource = nonExistantResource;
130
166
167
	// this is a work-around for the TreeView widget that does not draw the text according to each row's image width 
168
	private String textPrefix = new String();
169
	
131
	/**
170
	/**
132
	 * 
171
	 * 
133
	 */
172
	 */
Lines 137-142 Link Here
137
						"$nl$/icons/full/obj16/header_complete.gif"); //$NON-NLS-1$
176
						"$nl$/icons/full/obj16/header_complete.gif"); //$NON-NLS-1$
138
		if (descriptor != null)
177
		if (descriptor != null)
139
			checkIcon = descriptor.createImage();
178
			checkIcon = descriptor.createImage();
179
		
180
		
181
		ImageDescriptor fileIconDescriptor = AbstractUIPlugin
182
		.imageDescriptorFromPlugin(IDEWorkbenchPlugin.IDE_WORKBENCH,
183
				"$nl$/icons/full/obj16/fileType_filter.gif"); //$NON-NLS-1$
184
		if (fileIconDescriptor != null)
185
			fileIcon = fileIconDescriptor.createImage();
186
		
187
		ImageDescriptor folderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
188
				IDEWorkbenchPlugin.IDE_WORKBENCH,
189
				"$nl$/icons/full/obj16/folderType_filter.gif"); //$NON-NLS-1$
190
		if (folderIconDescriptor != null)
191
			folderIcon = folderIconDescriptor.createImage();
192
		
193
		ImageDescriptor fileFolderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
194
				IDEWorkbenchPlugin.IDE_WORKBENCH,
195
				"$nl$/icons/full/obj16/fileFolderType_filter.gif"); //$NON-NLS-1$
196
		if (fileFolderIconDescriptor != null)
197
			fileFolderIcon = fileFolderIconDescriptor.createImage();
198
		
199
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
200
				IDEWorkbenchPlugin.IDE_WORKBENCH,
201
				"$nl$/icons/full/obj16/includeMode_filter.gif"); //$NON-NLS-1$
202
		if (descriptor != null)
203
			includeIcon = descriptor.createImage();
204
		
205
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
206
				IDEWorkbenchPlugin.IDE_WORKBENCH,
207
				"$nl$/icons/full/obj16/excludeMode_filter.gif"); //$NON-NLS-1$
208
		if (descriptor != null)
209
			excludeIcon = descriptor.createImage();
210
		
211
		ImageDescriptor inheritableIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
212
				IDEWorkbenchPlugin.IDE_WORKBENCH,
213
				"$nl$/icons/full/obj16/inheritable_filter.gif"); //$NON-NLS-1$
214
		if (inheritableIconDescriptor != null)
215
			inheritableIcon = inheritableIconDescriptor.createImage();
216
217
		CompositeImageDescriptor desc = new AlignedCompositeImageDescriptor(null, fileIconDescriptor);
218
		fileAloneIcon = desc.createImage();
219
220
		desc = new AlignedCompositeImageDescriptor(null, folderIconDescriptor);
221
		folderAloneIcon = desc.createImage();
222
223
		desc = new AlignedCompositeImageDescriptor(null, fileFolderIconDescriptor);
224
		fileFolderAloneIcon = desc.createImage();
225
226
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileIconDescriptor);
227
		fileInheritableIcon = desc.createImage();
228
229
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, folderIconDescriptor);
230
		folderInheritableIcon = desc.createImage();
231
232
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileFolderIconDescriptor);
233
		fileFolderInheritableIcon = desc.createImage();
234
	}
235
236
	private static int AlignedCompositeImageDescriptor_SPACE = 4;
237
238
	private class AlignedCompositeImageDescriptor extends CompositeImageDescriptor {
239
240
		
241
		ImageDescriptor first, second;
242
		AlignedCompositeImageDescriptor(ImageDescriptor first, ImageDescriptor second) {
243
			this.first = first;
244
			this.second = second;
245
		}
246
		/* (non-Javadoc)
247
		 * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
248
		 */
249
		protected void drawCompositeImage(int width, int height) {
250
			if (first != null) {
251
				drawImage(first.getImageData(), 0, 0);
252
				drawImage(second.getImageData(), first.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0);
253
			}
254
			else
255
				drawImage(second.getImageData(), second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0);
256
		}
257
258
		/* (non-Javadoc)
259
		 * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
260
		 */
261
		protected Point getSize() {
262
			if (first != null)
263
				return new Point(first.getImageData().width + second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 
264
					Math.max(first.getImageData().height, second.getImageData().height));
265
			return new Point(second.getImageData().width * 2 + AlignedCompositeImageDescriptor_SPACE, second.getImageData().height);
266
		}
267
		
268
	}
269
270
	Image getImage(String string, int i) {
271
		if (string.equals(FilterTypeUtil.MODE))
272
			return new Image[] { includeIcon, excludeIcon, inheritableIcon }[i];
273
		if (string.equals(FilterTypeUtil.TARGET))
274
			return new Image[] { fileIcon, folderIcon, fileFolderIcon }[i];
275
		return null;
140
	}
276
	}
141
277
142
	/**
278
	/**
Lines 277-301 Link Here
277
		}
413
		}
278
	}
414
	}
279
415
416
	static String includeOnlyGroup = "INCLUDE_ONLY_GROUP";  //$NON-NLS-1$
417
418
	static String excludeAllGroup = "EXCLUDE_ALL_GROUP";  //$NON-NLS-1$
419
280
	class TreeContentProvider implements ITreeContentProvider {
420
	class TreeContentProvider implements ITreeContentProvider {
421
		
281
		public Object[] getChildren(Object parentElement) {
422
		public Object[] getChildren(Object parentElement) {
423
			if (parentElement == filters)
424
				return new Object[] {includeOnlyGroup, excludeAllGroup};
425
			if (parentElement instanceof String) {
426
				ArrayList list = new ArrayList();
427
				int mask = parentElement.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
428
								IResourceFilterDescription.EXCLUDE_ALL;
429
				FilterCopy[] children = filters.getChildren();
430
				for (int i = 0; i < children.length; i++) {
431
					if ((children[i].getType() & mask) != 0)
432
						list.add(children[i]);
433
				}
434
				return list.toArray();
435
			}
282
			if (parentElement instanceof FilterCopy)
436
			if (parentElement instanceof FilterCopy)
283
				return ((FilterCopy) parentElement).getChildren();
437
				return ((FilterCopy) parentElement).getChildren();
284
			return null;
438
			return null;
285
		}
439
		}
286
440
287
		public Object getParent(Object element) {
441
		public Object getParent(Object element) {
288
			if (element instanceof FilterCopy) {
442
			if (element instanceof String)
289
				if (((FilterCopy) element).getParent() != null)
290
					return ((FilterCopy) element).getParent();
291
				return filters;
443
				return filters;
444
			if (element instanceof FilterCopy) {
445
				FilterCopy filterCopy = (FilterCopy) element;
446
				if (filterCopy.getParent() != null && filterCopy.getParent() != filters)
447
					return filterCopy.getParent();
448
				return ((filterCopy.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0) ? includeOnlyGroup: excludeAllGroup;
292
			}
449
			}
293
			return null;
450
			return null;
294
		}
451
		}
295
452
296
		public boolean hasChildren(Object element) {
453
		public boolean hasChildren(Object element) {
297
			if (element instanceof FilterCopy) {
454
			if (element instanceof FilterCopy || element instanceof String) {
298
				FilterCopy[] children = ((FilterCopy) element).getChildren();
455
				Object[] children = getChildren(element);
299
				return children != null && children.length > 0;
456
				return children != null && children.length > 0;
300
			}
457
			}
301
			return false;
458
			return false;
Lines 312-322 Link Here
312
		}
469
		}
313
	}
470
	}
314
471
315
	class LabelProvider implements ITableLabelProvider {
472
	class LabelProvider extends StyledCellLabelProvider  {
473
		private final Styler fBoldStyler; 
474
		private final Styler fPlainStyler; 
316
		FilterTypeUtil util;
475
		FilterTypeUtil util;
476
		TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
317
477
318
		public LabelProvider() {
478
		public LabelProvider() {
319
			util = new FilterTypeUtil();
479
			util = new FilterTypeUtil();
480
			fBoldStyler= new Styler() {
481
				public void applyStyles(TextStyle textStyle) {
482
					textStyle.font= boldFont;
483
				}
484
			};
485
			fPlainStyler= new Styler() {
486
				public void applyStyles(TextStyle textStyle) {
487
					textStyle.font= plainFont;
488
				}
489
			};
490
			ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(null, null);
491
			customfilterArgumentMap.put(ui.getID(), ui);
492
			ui = new DefaultCustomFilterArgumentUI(null, null);
493
			customfilterArgumentMap.put(ui.getID(), ui);
494
		}
495
496
		ICustomFilterArgumentUI getUI(String descriptorID) {
497
			ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
498
			if (result == null)
499
				return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
500
			return result;
320
		}
501
		}
321
502
322
		String getColumnID(int index) {
503
		String getColumnID(int index) {
Lines 328-412 Link Here
328
			return copy.isUnderAGroupFilter();
509
			return copy.isUnderAGroupFilter();
329
		}
510
		}
330
511
331
		public Image getColumnImage(Object element, int columnIndex) {
512
		public void update(ViewerCell cell) {
332
			if (!isPartialFilter(element)) {
513
			int columnIndex = cell.getColumnIndex();
333
				if (getColumnID(columnIndex).equals(FilterTypeUtil.ARGUMENTS)) {
334
					Object index = FilterTypeUtil.getValue(
335
							(FilterCopy) element, FilterTypeUtil.TARGET);
336
					return util.getImage(FilterTypeUtil.TARGET,
337
							((Integer) index).intValue());
338
				}
339
				if (getColumnID(columnIndex).equals(FilterTypeUtil.MODE)) {
340
					Object index = FilterTypeUtil.getValue(
341
							(FilterCopy) element, FilterTypeUtil.MODE);
342
					return util.getImage(FilterTypeUtil.MODE, ((Integer) index)
343
							.intValue());
344
				}
345
				if (getColumnID(columnIndex).equals(FilterTypeUtil.INHERITABLE)) {
346
					Object condition = FilterTypeUtil.getValue(
347
							(FilterCopy) element, FilterTypeUtil.INHERITABLE);
348
					if (((Boolean) condition).booleanValue())
349
						return checkIcon;
350
				}
351
			}
352
			return null;
353
		}
354
355
		public String getColumnText(Object element, int columnIndex) {
356
			FilterCopy filter = ((FilterCopy) element);
357
			String column = getColumnID(columnIndex);
514
			String column = getColumnID(columnIndex);
358
			return getValue(filter, column);
515
			FilterCopy filter = null;
359
		}
360
516
361
		private String getValue(FilterCopy filter, String column) {
517
			Object element = cell.getElement();
362
			if (column.equals(FilterTypeUtil.ID)) {
518
			if (element instanceof String) {
363
				String id = filter.getId();
519
				if (column.equals(FilterTypeUtil.MODE)) {
364
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
520
					cell.setImage(getImage(FilterTypeUtil.MODE, element.equals(includeOnlyGroup) ? 0:1));
365
				if (descriptor != null)
521
				}
366
					return descriptor.getName();
522
				if (column.equals(FilterTypeUtil.MODE)) {
367
			}
523
					if (element.equals(includeOnlyGroup))
368
			if (column.equals(FilterTypeUtil.MODE)) {
524
						cell.setText(NLS
369
				if (!isPartialFilter(filter)) {
370
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
371
						return NLS
372
								.bind(
525
								.bind(
373
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
526
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
374
										null);
527
										null));
375
					return NLS
528
					else
529
						cell.setText(NLS
376
							.bind(
530
							.bind(
377
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
531
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
378
									null);
532
									null));
379
				}
533
				}
380
				return getFilterTypeName(filter);
381
			}
382
			if (column.equals(FilterTypeUtil.TARGET)) {
383
				boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0;
384
				boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0;
385
				if (includeFiles && includeFolders)
386
					return NLS
387
							.bind(
388
									IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn,
389
									null);
390
				if (includeFiles)
391
					return NLS
392
							.bind(
393
									IDEWorkbenchMessages.ResourceFilterPage_filesColumn,
394
									null);
395
				if (includeFolders)
396
					return NLS
397
							.bind(
398
									IDEWorkbenchMessages.ResourceFilterPage_foldersColumn,
399
									null);
400
			}
534
			}
401
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
535
			else {
402
				if (filter.hasStringArguments())
536
				filter = (FilterCopy) element;
403
					return filter.getArguments() != null ? filter
537
	
404
							.getArguments().toString() : ""; //$NON-NLS-1$
538
				if (column.equals(FilterTypeUtil.ID)) {
405
				if ((filter.getChildrenLimit() > 0)
539
					String id = filter.getId();
406
						&& !filter.isUnderAGroupFilter())
540
					IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
407
					return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$
541
					if (descriptor != null)
542
						cell.setText(descriptor.getName());
543
				}
544
				if (!isPartialFilter(filter)) {
545
					if (column.equals(FilterTypeUtil.INHERITABLE)) {
546
						Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
547
						cell.setImage(((Boolean) condition).booleanValue() ? checkIcon: null);
548
					}
549
				}
550
				if (column.equals(FilterTypeUtil.MODE)) {
551
					StyledString styledString = new StyledString(textPrefix, fPlainStyler);
552
					styledString.append(getStyleColumnText(filter));
553
					cell.setText(styledString.toString());
554
					cell.setStyleRanges(styledString.getStyleRanges());
555
556
					if (!isPartialFilter(filter)) {
557
						Image[] images = { fileAloneIcon, folderAloneIcon, fileFolderAloneIcon };
558
						Image[] inheritableImages = {fileInheritableIcon, folderInheritableIcon, fileFolderInheritableIcon};
559
560
						Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET);
561
						Object isInheritable = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
562
						int intValue = ((Integer)index).intValue();
563
						if (((Boolean)isInheritable).booleanValue())
564
							cell.setImage(inheritableImages[intValue]);
565
						else
566
							cell.setImage(images[intValue]);
567
					}
568
				}
408
			}
569
			}
409
			return null;
570
571
			super.update(cell);
572
		}
573
		
574
		private StyledString getStyleColumnText(FilterCopy filter) {
575
			if ((filter.getChildrenLimit() > 0)) {
576
				String whiteSpace = " "; //$NON-NLS-1$;
577
				String expression = getFilterTypeName(filter);
578
				boolean isUnaryOperator = filter.getId().equals("org.eclipse.ui.ide.notFilterMatcher"); //$NON-NLS-1$
579
				StyledString buffer = new StyledString();
580
				if (isUnaryOperator) {
581
					buffer.append("NOT ", fBoldStyler); //$NON-NLS-1$
582
					expression = "OR"; //$NON-NLS-1$
583
				}
584
				buffer.append("(", fBoldStyler); //$NON-NLS-1$
585
				Object [] children = filterViewContentProvider.getChildren(filter);
586
				for (int i = 0; i < children.length; i++) {
587
					buffer.append(getStyleColumnText((FilterCopy) children[i]));
588
					if ((i + 1) < children.length) {
589
						buffer.append(whiteSpace, fPlainStyler);
590
						buffer.append(expression, fBoldStyler);
591
						buffer.append(whiteSpace, fPlainStyler);
592
					}
593
				}
594
				if (children.length < 2 && !isUnaryOperator) {
595
					if (children.length == 1)
596
						buffer.append(whiteSpace, fPlainStyler);
597
					buffer.append(expression, fBoldStyler);
598
				}
599
				buffer.append(")", fBoldStyler); //$NON-NLS-1$
600
				return buffer;
601
			} 
602
			ICustomFilterArgumentUI ui = getUI(filter.getId());
603
			return ui.formatStyledText(filter, fPlainStyler, fBoldStyler);
604
		}
605
606
		protected void measure(Event event, Object element) {
607
			super.measure(event, element);
410
		}
608
		}
411
609
412
		private String getFilterTypeName(FilterCopy filter) {
610
		private String getFilterTypeName(FilterCopy filter) {
Lines 416-436 Link Here
416
				return desc.getName();
614
				return desc.getName();
417
			return ""; //$NON-NLS-1$
615
			return ""; //$NON-NLS-1$
418
		}
616
		}
419
420
		public void addListener(ILabelProviderListener listener) {
421
		}
422
423
		public void dispose() {
424
		}
425
426
		public boolean isLabelProperty(Object element, String property) {
427
			return false;
428
		}
429
430
		public void removeListener(ILabelProviderListener listener) {
431
		}
432
	}
617
	}
433
618
	
434
	class CellModifier implements ICellModifier {
619
	class CellModifier implements ICellModifier {
435
		public boolean canModify(Object element, String property) {
620
		public boolean canModify(Object element, String property) {
436
			FilterCopy filter = (FilterCopy) element;
621
			FilterCopy filter = (FilterCopy) element;
Lines 506-520 Link Here
506
	}
691
	}
507
692
508
	private void createViewerGroup(Composite parent) {
693
	private void createViewerGroup(Composite parent) {
509
		filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
694
		
510
				| SWT.H_SCROLL);
695
		GC gc = new GC(parent);
696
		gc.setFont(plainFont);
697
		String whiteSpace = " "; //$NON-NLS-1$
698
		textPrefix = whiteSpace;
699
		int width = inheritableIcon.getImageData().width + AlignedCompositeImageDescriptor_SPACE;
700
		while (gc.stringExtent(textPrefix).x < width) {
701
			textPrefix += whiteSpace;
702
		}
703
		gc.dispose();
704
705
		Composite tableComposite = new Composite(parent, SWT.NONE);
511
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
706
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
512
		data.grabExcessHorizontalSpace = true;
707
		data.grabExcessHorizontalSpace = true;
513
		data.grabExcessVerticalSpace = true;
708
		data.grabExcessVerticalSpace = true;
709
		tableComposite.setLayoutData(data);
710
711
		filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER
712
				| SWT.H_SCROLL);
713
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
714
		data.grabExcessHorizontalSpace = true;
715
		data.grabExcessVerticalSpace = true;
514
		filterView.getTree().setLayoutData(data);
716
		filterView.getTree().setLayoutData(data);
515
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
717
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
516
718
517
		filterView.setContentProvider(new TreeContentProvider());
719
		plainFont = filterView.getTree().getFont();
720
		FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD);
721
		boldFont = new Font(Display.getCurrent(), boldFontData);
722
723
		filterView.setAutoExpandLevel(2);
724
		filterViewContentProvider = new TreeContentProvider();
725
		filterView.setContentProvider(filterViewContentProvider);
518
		filterView.setInput(filters);
726
		filterView.setInput(filters);
519
		filterView.getTree().setFont(parent.getFont());
727
		filterView.getTree().setFont(parent.getFont());
520
728
Lines 524-562 Link Here
524
			}
732
			}
525
		});
733
		});
526
734
527
		TreeColumn column = new TreeColumn(filterView.getTree(), 0);
735
		TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0);
528
		column
736
		modeColumn
529
				.setText(NLS
530
						.bind(
531
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
532
								null));
533
		column.setData(FilterTypeUtil.MODE);
534
		column.setResizable(true);
535
		column.setMoveable(false);
536
		column.setWidth(getMinimumColumnWidth(column, 130));
537
538
		column = new TreeColumn(filterView.getTree(), 0);
539
		column.setText(NLS.bind(
540
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
541
				null));
542
		column.setData(FilterTypeUtil.ARGUMENTS);
543
		column.setResizable(true);
544
		column.setMoveable(true);
545
		column.setWidth(getMinimumColumnWidth(column, 120));
546
547
		column = new TreeColumn(filterView.getTree(), 0);
548
		column
549
				.setText(NLS
737
				.setText(NLS
550
						.bind(
738
						.bind(
551
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
739
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterDescription,
552
								null));
740
								null));
553
		column.setData(FilterTypeUtil.INHERITABLE);
741
		modeColumn.setData(FilterTypeUtil.MODE);
554
		column.setResizable(true);
742
		modeColumn.setResizable(true);
555
		column.setMoveable(false);
743
		modeColumn.setMoveable(false);
556
		column.setAlignment(SWT.CENTER);
557
		column.setWidth(getMinimumColumnWidth(column, 70));
558
744
559
		filterView.getTree().setHeaderVisible(true);
745
		filterView.getTree().setHeaderVisible(false);
560
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
746
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
561
		labelProvider = new LabelProvider();
747
		labelProvider = new LabelProvider();
562
		filterView.setLabelProvider(labelProvider);
748
		filterView.setLabelProvider(labelProvider);
Lines 578-584 Link Here
578
764
579
		filterView.getTree().addMouseListener(new MouseListener() {
765
		filterView.getTree().addMouseListener(new MouseListener() {
580
			public void mouseDoubleClick(MouseEvent e) {
766
			public void mouseDoubleClick(MouseEvent e) {
581
				handleEdit();
767
				if (!handleEdit()) {
768
					ISelection selection = filterView.getSelection();
769
					if (selection instanceof IStructuredSelection) {
770
						if (((IStructuredSelection) selection).size() > 0) {
771
							Object firstElement = ((IStructuredSelection) selection).getFirstElement();
772
							filterView.setExpandedState(firstElement, !filterView.getExpandedState(firstElement));
773
						}
774
					}
775
				}
582
			}
776
			}
583
777
584
			public void mouseDown(MouseEvent e) {
778
			public void mouseDown(MouseEvent e) {
Lines 598-616 Link Here
598
			public void menuDetected(MenuDetectEvent e) {
792
			public void menuDetected(MenuDetectEvent e) {
599
				MenuManager mgr = new MenuManager();
793
				MenuManager mgr = new MenuManager();
600
				mgr.add(addSubFilterAction);
794
				mgr.add(addSubFilterAction);
795
				mgr.add(addSubGroupFilterAction);
796
				mgr.add(new Separator());
797
				mgr.add(new EditFilterAction());
798
				mgr.add(new RemoveFilterAction());
601
				filterView.getControl().setMenu(
799
				filterView.getControl().setMenu(
602
						mgr.createContextMenu(filterView.getControl()));
800
						mgr.createContextMenu(filterView.getControl()));
603
			}
801
			}
604
		});
802
		});
803
		TreeColumnLayout layout = new TreeColumnLayout();
804
		tableComposite.setLayout( layout );
805
806
		layout.setColumnData( modeColumn, new ColumnWeightData(100));
807
		filterView.setSelection(new StructuredSelection(includeOnlyGroup));
808
	}
809
810
	private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
811
		FontData[] styleData = new FontData[originalData.length];
812
		for (int i = 0; i < styleData.length; i++) {
813
			FontData base = originalData[i];
814
			styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle);
815
		}
816
       	return styleData;
817
    }
818
819
	class EditFilterAction extends Action {
820
821
		public EditFilterAction() {
822
			setText(NLS
823
					.bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel,
824
							null));
825
		}
826
827
		public void run() {
828
			handleEdit();
829
		}
830
		public boolean isEnabled() {
831
			ISelection selection = filterView.getSelection();
832
			if (selection instanceof IStructuredSelection) {
833
				if (((IStructuredSelection) selection).size() > 0) {
834
					Object firstElement = ((IStructuredSelection) selection)
835
					.getFirstElement();
836
					return firstElement instanceof FilterCopy;
837
				}
838
			}
839
			return false;
840
		}
841
	}
842
843
	class RemoveFilterAction extends Action {
844
845
		public RemoveFilterAction() {
846
			setText(NLS
847
					.bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel,
848
							null));
849
		}
850
851
		public void run() {
852
			handleRemove();
853
		}
854
		public boolean isEnabled() {
855
			ISelection selection = filterView.getSelection();
856
			if (selection instanceof IStructuredSelection) {
857
				return ((IStructuredSelection) selection).size() > 0;			}
858
			return false;
859
		}
605
	}
860
	}
606
861
607
	Action addSubFilterAction = new AddSubFilterAction();
862
	Action addSubFilterAction = new AddSubFilterAction(false);
608
863
609
	class AddSubFilterAction extends Action {
864
	class AddSubFilterAction extends Action {
610
865
611
		public AddSubFilterAction() {
866
		boolean createGroupOnly;
867
		
868
		public AddSubFilterAction(boolean createGroupOnly) {
869
			this.createGroupOnly = createGroupOnly;
612
			setText(NLS
870
			setText(NLS
613
					.bind(
871
					.bind(createGroupOnly ?
872
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel:
614
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
873
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
615
							null));
874
							null));
616
		}
875
		}
Lines 623-640 Link Here
623
		public void run() {
882
		public void run() {
624
			ISelection selection = filterView.getSelection();
883
			ISelection selection = filterView.getSelection();
625
			if (selection instanceof IStructuredSelection) {
884
			if (selection instanceof IStructuredSelection) {
626
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
885
				Object firstElement = ((IStructuredSelection) selection)
627
						.getFirstElement();
886
				.getFirstElement();
628
				if (filter.getChildrenLimit() > 0) {
887
				handleAdd(firstElement, createGroupOnly);
629
					FilterCopy newFilter = new FilterCopy();
630
					newFilter.setParent(filter);
631
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
632
							newFilter);
633
					if (dialog.open() == Window.OK) {
634
						filter.addChild(newFilter);
635
						filterView.refresh();
636
					}
637
				}
638
			}
888
			}
639
		}
889
		}
640
890
Lines 646-659 Link Here
646
		public boolean isEnabled() {
896
		public boolean isEnabled() {
647
			ISelection selection = filterView.getSelection();
897
			ISelection selection = filterView.getSelection();
648
			if (selection instanceof IStructuredSelection) {
898
			if (selection instanceof IStructuredSelection) {
649
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
899
				Object firstElement = ((IStructuredSelection) selection)
650
						.getFirstElement();
900
						.getFirstElement();
651
				return filter.getChildrenLimit() > 0;
901
				return isAddEnabled(firstElement);
902
			}
903
			return false;
904
		}
905
	}
906
907
	private void handleAdd(Object selection, boolean createGroupOnly) {
908
		if (selection instanceof FilterCopy) {
909
			FilterCopy filter = (FilterCopy) selection;
910
			if (filter.getChildrenLimit() > 0) {
911
				FilterCopy newFilter = new FilterCopy();
912
				newFilter.setParent(filter);
913
				FilterTypeUtil.setValue(newFilter, FilterTypeUtil.MODE, FilterTypeUtil.getValue(filter, FilterTypeUtil.MODE));
914
				FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell,
915
						newFilter, createGroupOnly, true);
916
				if (dialog.open() == Window.OK) {
917
					filter.addChild(newFilter);
918
					refreshAndSelect(newFilter);
919
				}
920
			}
921
		}
922
		if (selection instanceof String) {
923
			FilterCopy newFilter = new FilterCopy();
924
			FilterTypeUtil.setValue(newFilter, FilterTypeUtil.MODE, 
925
					new Integer(selection.equals(includeOnlyGroup) ? 0:1));
926
			FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell,
927
					newFilter, createGroupOnly, true);
928
			if (dialog.open() == Window.OK) {
929
				addToTopLevelFilters(newFilter);
930
				refreshAndSelect(newFilter);
652
			}
931
			}
932
		}
933
	}
934
935
	private void refreshAndSelect(FilterCopy newFilter) {
936
		filterView.refresh();
937
		filterView.reveal(newFilter);
938
	}
939
940
	private boolean isAddEnabled(Object selection) {
941
		if (selection == null)
653
			return false;
942
			return false;
943
		if (selection instanceof FilterCopy) {
944
			FilterCopy filter = (FilterCopy) selection;
945
			return filter.getChildrenLimit() > 0;
654
		}
946
		}
947
		if (selection instanceof String)
948
			return true;
949
		return false;
950
	}
951
952
	private void addToTopLevelFilters(FilterCopy newFilter) {
953
		int value = ((Integer) FilterTypeUtil.getValue(newFilter, FilterTypeUtil.MODE)).intValue();
954
		Object[] existingChildren = filterViewContentProvider.getChildren(value == 0? includeOnlyGroup:excludeAllGroup);
955
		filters.add(newFilter);
956
		filterView.refresh();
957
		if (existingChildren.length == 0)
958
			filterView.setExpandedState(newFilter, true);
655
	}
959
	}
656
960
961
	Action addSubGroupFilterAction = new AddSubFilterAction(true);
962
657
	class FilterCopyDrop extends ViewerDropAdapter {
963
	class FilterCopyDrop extends ViewerDropAdapter {
658
		protected FilterCopyDrop(Viewer viewer) {
964
		protected FilterCopyDrop(Viewer viewer) {
659
			super(viewer);
965
			super(viewer);
Lines 682-687 Link Here
682
			for (int i = 0; i < toDrop.length; i++) {
988
			for (int i = 0; i < toDrop.length; i++) {
683
				if (target instanceof Filters)
989
				if (target instanceof Filters)
684
					filters.add(toDrop[i]);
990
					filters.add(toDrop[i]);
991
				if (target instanceof String) {
992
					FilterTypeUtil.setValue(toDrop[i], FilterTypeUtil.MODE,
993
							new Integer(target.equals(includeOnlyGroup) ? 0:1));
994
					addToTopLevelFilters(toDrop[i]);
995
				}
685
				if (target instanceof FilterCopy)
996
				if (target instanceof FilterCopy)
686
					((FilterCopy) target).addChild(toDrop[i]);
997
					((FilterCopy) target).addChild(toDrop[i]);
687
				filterView.refresh();
998
				filterView.refresh();
Lines 749-768 Link Here
749
		}
1060
		}
750
	}
1061
	}
751
1062
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) {
1063
	private void createButtonGroup(Composite parent) {
767
		Composite composite = new Composite(parent, SWT.NONE);
1064
		Composite composite = new Composite(parent, SWT.NONE);
768
		GridLayout layout = new GridLayout();
1065
		GridLayout layout = new GridLayout();
Lines 780-793 Link Here
780
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1077
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
781
		addButton.setLayoutData(data);
1078
		addButton.setLayoutData(data);
782
		setButtonDimensionHint(addButton);
1079
		setButtonDimensionHint(addButton);
783
		addButton.addSelectionListener(new SelectionListener() {
1080
		addButton.addSelectionListener(new SelectionAdapter() {
784
			public void widgetDefaultSelected(SelectionEvent e) {
1081
			public void widgetSelected(SelectionEvent e) {
1082
				handleAdd(false);
785
			}
1083
			}
786
1084
		});
1085
		
1086
		addGroupButton = new Button(composite, SWT.PUSH);
1087
		addGroupButton.setText(NLS.bind(
1088
				IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null));
1089
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1090
		addGroupButton.setLayoutData(data);
1091
		setButtonDimensionHint(addGroupButton);
1092
		addGroupButton.addSelectionListener(new SelectionAdapter() {
787
			public void widgetSelected(SelectionEvent e) {
1093
			public void widgetSelected(SelectionEvent e) {
788
				handleAdd();
1094
				handleAdd(true);
789
			}
1095
			}
790
		});
1096
		});
1097
		
791
1098
792
		editButton = new Button(composite, SWT.PUSH);
1099
		editButton = new Button(composite, SWT.PUSH);
793
		editButton.setText(NLS.bind(
1100
		editButton.setText(NLS.bind(
Lines 795-804 Link Here
795
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1102
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
796
		editButton.setLayoutData(data);
1103
		editButton.setLayoutData(data);
797
		setButtonDimensionHint(editButton);
1104
		setButtonDimensionHint(editButton);
798
		editButton.addSelectionListener(new SelectionListener() {
1105
		editButton.addSelectionListener(new SelectionAdapter() {
799
			public void widgetDefaultSelected(SelectionEvent e) {
800
			}
801
802
			public void widgetSelected(SelectionEvent e) {
1106
			public void widgetSelected(SelectionEvent e) {
803
				handleEdit();
1107
				handleEdit();
804
			}
1108
			}
Lines 813-882 Link Here
813
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1117
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
814
		removeButton.setLayoutData(data);
1118
		removeButton.setLayoutData(data);
815
		setButtonDimensionHint(removeButton);
1119
		setButtonDimensionHint(removeButton);
816
		removeButton.addSelectionListener(new SelectionListener() {
1120
		removeButton.addSelectionListener(new SelectionAdapter() {
817
			public void widgetDefaultSelected(SelectionEvent e) {
818
			}
819
820
			public void widgetSelected(SelectionEvent e) {
1121
			public void widgetSelected(SelectionEvent e) {
821
				handleRemove();
1122
				handleRemove();
822
			}
1123
			}
823
		});
1124
		});
824
825
		if (allowReordering) {
826
			upButton = new Button(composite, SWT.PUSH);
827
			upButton
828
					.setText(NLS
829
							.bind(
830
									IDEWorkbenchMessages.ResourceFilterPage_upButtonLabel,
831
									null));
832
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
833
			upButton.setLayoutData(data);
834
			setButtonDimensionHint(upButton);
835
			upButton.addSelectionListener(new SelectionListener() {
836
				public void widgetDefaultSelected(SelectionEvent e) {
837
				}
838
839
				public void widgetSelected(SelectionEvent e) {
840
					handleUp();
841
				}
842
			});
843
844
			downButton = new Button(composite, SWT.PUSH);
845
			downButton.setText(NLS.bind(
846
					IDEWorkbenchMessages.ResourceFilterPage_downButtonLabel,
847
					null));
848
			data = new GridData(SWT.FILL, SWT.FILL, false, false);
849
			downButton.setLayoutData(data);
850
			setButtonDimensionHint(downButton);
851
			downButton.addSelectionListener(new SelectionListener() {
852
				public void widgetDefaultSelected(SelectionEvent e) {
853
				}
854
855
				public void widgetSelected(SelectionEvent e) {
856
					handleDown();
857
				}
858
			});
859
		}
860
	}
1125
	}
861
1126
862
	private void refreshEnablement() {
1127
	private void refreshEnablement() {
863
		addButton.setEnabled(true);
1128
		if (addButton != null) {
864
		ISelection selection = filterView.getSelection();
1129
			ISelection selection = filterView.getSelection();
865
		IStructuredSelection structuredSelection = null;
1130
			IStructuredSelection structuredSelection = null;
866
		if (selection instanceof IStructuredSelection)
1131
			if (selection instanceof IStructuredSelection)
867
			structuredSelection = ((IStructuredSelection) selection);
1132
				structuredSelection = ((IStructuredSelection) selection);
868
		removeButton.setEnabled(structuredSelection != null
1133
			addButton.setEnabled(isAddEnabled(structuredSelection != null ? structuredSelection.getFirstElement():null));
869
				&& structuredSelection.size() > 0);
1134
			addGroupButton.setEnabled(isAddEnabled(structuredSelection != null ? structuredSelection.getFirstElement():null));
870
		editButton.setEnabled(structuredSelection != null
1135
			removeButton.setEnabled(structuredSelection != null
871
				&& structuredSelection.size() == 1);
1136
					&& structuredSelection.size() > 0 && !(structuredSelection.getFirstElement() instanceof String));
872
		if (upButton != null)
1137
			editButton.setEnabled(structuredSelection != null
873
			upButton.setEnabled(structuredSelection != null
1138
					&& structuredSelection.size() == 1
874
					&& (structuredSelection.size() > 0)
1139
					&& (structuredSelection.getFirstElement() instanceof FilterCopy));
875
					&& !isFirst(structuredSelection.getFirstElement()));
1140
			if (upButton != null)
876
		if (downButton != null)
1141
				upButton.setEnabled(structuredSelection != null
877
			downButton.setEnabled(structuredSelection != null
1142
						&& (structuredSelection.size() > 0)
878
					&& (structuredSelection.size() > 0)
1143
						&& !isFirst(structuredSelection.getFirstElement()));
879
					&& !isLast(structuredSelection.getFirstElement()));
1144
			if (downButton != null)
1145
				downButton.setEnabled(structuredSelection != null
1146
						&& (structuredSelection.size() > 0)
1147
						&& !isLast(structuredSelection.getFirstElement()));
1148
		}
880
	}
1149
	}
881
1150
882
	private boolean isFirst(Object o) {
1151
	private boolean isFirst(Object o) {
Lines 887-916 Link Here
887
		return filters.isLast((FilterCopy) o);
1156
		return filters.isLast((FilterCopy) o);
888
	}
1157
	}
889
1158
890
	private void handleAdd() {
1159
	private void handleAdd(boolean createGroupOnly) {
891
		FilterCopy newFilter = new FilterCopy();
1160
		ISelection selection = filterView.getSelection();
892
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter);
1161
		if (selection instanceof IStructuredSelection) {
893
		if (dialog.open() == Window.OK) {
1162
			IStructuredSelection structuredSelection = ((IStructuredSelection) selection);
894
			filters.add(newFilter);
1163
			if (!structuredSelection.isEmpty())
895
			filterView.refresh();
1164
				handleAdd(structuredSelection.getFirstElement(), createGroupOnly);
896
		}
1165
		}
897
	}
1166
	}
898
1167
899
	private void handleEdit() {
1168
	private boolean handleEdit() {
900
		ISelection selection = filterView.getSelection();
1169
		ISelection selection = filterView.getSelection();
901
		if (selection instanceof IStructuredSelection) {
1170
		if (selection instanceof IStructuredSelection) {
902
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
1171
			Object firstElement = ((IStructuredSelection) selection)
903
					.getFirstElement();
1172
					.getFirstElement();
904
			FilterCopy copy = new FilterCopy(filter);
1173
			if (firstElement instanceof String)
905
			copy.setParent(filter.getParent());
1174
				return false;
906
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy);
1175
			if (firstElement instanceof FilterCopy) {
907
			if (dialog.open() == Window.OK) {
1176
				FilterCopy filter = (FilterCopy) firstElement;
908
				if (copy.hasChanged()) {
1177
				FilterCopy copy = new FilterCopy(filter);
909
					filter.copy(copy);
1178
				copy.setParent(filter.getParent());
910
					filterView.refresh();
1179
				boolean isGroup = filter.getChildrenLimit() > 0;
1180
				FilterEditDialog dialog = new FilterEditDialog(resource, this, shell, copy, isGroup, false);
1181
				if (dialog.open() == Window.OK) {
1182
					if (copy.hasChanged()) {
1183
						filter.copy(copy);
1184
						filterView.refresh();
1185
					}
911
				}
1186
				}
1187
				return true;
912
			}
1188
			}
913
		}
1189
		}
1190
		return false;
914
	}
1191
	}
915
1192
916
	private FilterCopy[] getFilterCopySelection() {
1193
	private FilterCopy[] getFilterCopySelection() {
Lines 933-973 Link Here
933
			structuredSelection = ((IStructuredSelection) selection);
1210
			structuredSelection = ((IStructuredSelection) selection);
934
			Iterator it = structuredSelection.iterator();
1211
			Iterator it = structuredSelection.iterator();
935
			while (it.hasNext()) {
1212
			while (it.hasNext()) {
936
				FilterCopy filter = (FilterCopy) it.next();
1213
				Object element = it.next();
937
				filter.getParent().removeChild(filter);
1214
				if (element instanceof FilterCopy) {
1215
					FilterCopy filter = (FilterCopy) element;
1216
					filter.getParent().removeChild(filter);
1217
				}
1218
				else {
1219
					int mask = element.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
1220
						IResourceFilterDescription.EXCLUDE_ALL;
1221
					FilterCopy[] children = filters.getChildren();
1222
					for (int i = 0; i < children.length; i++) {
1223
						if ((children[i].getType() & mask) != 0)
1224
							filters.removeChild(children[i]);
1225
					}
1226
				}
938
			}
1227
			}
939
			filterView.refresh();
1228
			filterView.refresh();
940
		}
1229
		}
941
	}
1230
	}
942
1231
943
	private void handleUp() {
1232
	private static void setButtonDimensionHint(Button button) {
944
		ISelection selection = filterView.getSelection();
1233
		Assert.isNotNull(button);
945
		if (selection instanceof IStructuredSelection) {
1234
		Object gd = button.getLayoutData();
946
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
1235
		if (gd instanceof GridData) {
947
					.getFirstElement();
1236
			((GridData) gd).widthHint = getButtonWidthHint(button);
948
			filters.moveUp(filter);
1237
			((GridData) gd).horizontalAlignment = GridData.FILL;
949
		}
950
		filterView.refresh();
951
		refreshEnablement();
952
	}
953
954
	private void handleDown() {
955
		ISelection selection = filterView.getSelection();
956
		if (selection instanceof IStructuredSelection) {
957
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
958
					.getFirstElement();
959
			filters.moveDown(filter);
960
		}
961
		filterView.refresh();
962
		refreshEnablement();
963
	}
964
965
	private static void setButtonDimensionHint(Button button) {
966
		Assert.isNotNull(button);
967
		Object gd = button.getLayoutData();
968
		if (gd instanceof GridData) {
969
			((GridData) gd).widthHint = getButtonWidthHint(button);
970
			((GridData) gd).horizontalAlignment = GridData.FILL;
971
		}
1238
		}
972
	}
1239
	}
973
1240
Lines 1066-1074 Link Here
1066
	 * Disposes the group's resources.
1333
	 * Disposes the group's resources.
1067
	 */
1334
	 */
1068
	public void dispose() {
1335
	public void dispose() {
1069
		if (checkIcon != null) {
1336
		disposeIcons();
1070
			checkIcon.dispose();
1337
	}
1071
			checkIcon = null;
1338
1339
	private void disposeIcons() {
1340
		Field[] fields = getClass().getFields();
1341
		for (int i = 0; i < fields.length; i++) {
1342
			if (fields[i].getClass().equals(Image.class)) {
1343
				Image img;
1344
				try {
1345
					img = (Image) fields[i].get(this);
1346
					if (img != null) {
1347
						img.dispose();
1348
						fields[i].set(this, null);
1349
					}
1350
				} catch (IllegalArgumentException e) {
1351
					e.printStackTrace();
1352
				} catch (IllegalAccessException e) {
1353
					e.printStackTrace();
1354
				}
1355
			}
1072
		}
1356
		}
1073
	}
1357
	}
1074
1358
Lines 1149-1155 Link Here
1149
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1433
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1150
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1434
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1151
1435
1152
	static String[] columnNames = new String[] { MODE, ARGUMENTS, INHERITABLE };
1436
	static String[] columnNames = new String[] { MODE, TARGET, INHERITABLE };
1153
1437
1154
	static String[] getModes() {
1438
	static String[] getModes() {
1155
		return new String[] {
1439
		return new String[] {
Lines 1263-1286 Link Here
1263
								null) };
1547
								null) };
1264
	}
1548
	}
1265
1549
1266
	static String[] getFilterNames(boolean childrenOnly) {
1550
	static String[] getFilterNames(boolean groupOnly) {
1267
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1551
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1268
				.getFilterMatcherDescriptors();
1552
				.getFilterMatcherDescriptors();
1553
		sortDescriptors(descriptors);
1269
		LinkedList names = new LinkedList();
1554
		LinkedList names = new LinkedList();
1270
		for (int i = 0; i < descriptors.length; i++) {
1555
		for (int i = 0; i < descriptors.length; i++) {
1271
			if (!childrenOnly
1556
			boolean isGroup = descriptors[i].getArgumentType().equals(
1272
					|| descriptors[i].getArgumentType().equals(
1557
					IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1273
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1274
					|| descriptors[i].getArgumentType().equals(
1558
					|| descriptors[i].getArgumentType().equals(
1275
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS))
1559
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS);
1560
			if (isGroup == groupOnly) 
1276
				names.add(descriptors[i].getName());
1561
				names.add(descriptors[i].getName());
1277
		}
1562
		}
1278
		return (String[]) names.toArray(new String[0]);
1563
		return (String[]) names.toArray(new String[0]);
1279
	}
1564
	}
1280
1565
1566
	/**
1567
	 * @param descriptors
1568
	 */
1569
	private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) {
1570
		Arrays.sort(descriptors, new Comparator() {
1571
			public int compare(Object arg0, Object arg1) {
1572
				if (((IFilterMatcherDescriptor) arg0).getId().equals(FileInfoAttributesMatcher.ID))
1573
					return -1;
1574
				if (((IFilterMatcherDescriptor) arg1).getId().equals(FileInfoAttributesMatcher.ID))
1575
					return 1;
1576
				return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId());
1577
			}
1578
		});
1579
	}
1580
1281
	static String getDefaultFilterID() {
1581
	static String getDefaultFilterID() {
1282
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1582
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1283
				.getFilterMatcherDescriptors();
1583
				.getFilterMatcherDescriptors();
1584
		sortDescriptors(descriptors);
1284
		for (int i = 0; i < descriptors.length; i++) {
1585
		for (int i = 0; i < descriptors.length; i++) {
1285
			if (descriptors[i].getArgumentType().equals(
1586
			if (descriptors[i].getArgumentType().equals(
1286
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
1587
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
Lines 1304-1362 Link Here
1304
		}
1605
		}
1305
		return null;
1606
		return null;
1306
	}
1607
	}
1307
1608
	FilterTypeUtil() {}
1308
	private Image fileIcon = null;
1309
	private Image folderIcon = null;
1310
	private Image fileFolderIcon = null;
1311
	private Image includeIcon = null;
1312
	private Image excludeIcon = null;
1313
	private Image inheritableIcon = null;
1314
1315
	FilterTypeUtil() {
1316
		ImageDescriptor descriptor = AbstractUIPlugin
1317
				.imageDescriptorFromPlugin(IDEWorkbenchPlugin.IDE_WORKBENCH,
1318
						"$nl$/icons/full/obj16/fileType_filter.gif"); //$NON-NLS-1$
1319
		if (descriptor != null)
1320
			fileIcon = descriptor.createImage();
1321
1322
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
1323
				IDEWorkbenchPlugin.IDE_WORKBENCH,
1324
				"$nl$/icons/full/obj16/folderType_filter.gif"); //$NON-NLS-1$
1325
		if (descriptor != null)
1326
			folderIcon = descriptor.createImage();
1327
1328
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
1329
				IDEWorkbenchPlugin.IDE_WORKBENCH,
1330
				"$nl$/icons/full/obj16/fileFolderType_filter.gif"); //$NON-NLS-1$
1331
		if (descriptor != null)
1332
			fileFolderIcon = descriptor.createImage();
1333
1334
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
1335
				IDEWorkbenchPlugin.IDE_WORKBENCH,
1336
				"$nl$/icons/full/obj16/includeMode_filter.gif"); //$NON-NLS-1$
1337
		if (descriptor != null)
1338
			includeIcon = descriptor.createImage();
1339
1340
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
1341
				IDEWorkbenchPlugin.IDE_WORKBENCH,
1342
				"$nl$/icons/full/obj16/excludeMode_filter.gif"); //$NON-NLS-1$
1343
		if (descriptor != null)
1344
			excludeIcon = descriptor.createImage();
1345
		
1346
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
1347
				IDEWorkbenchPlugin.IDE_WORKBENCH,
1348
				"$nl$/icons/full/obj16/inheritable_filter.gif"); //$NON-NLS-1$
1349
		if (descriptor != null)
1350
			inheritableIcon = descriptor.createImage();
1351
	}
1352
1353
	Image getImage(String string, int i) {
1354
		if (string.equals(MODE))
1355
			return new Image[] { includeIcon, excludeIcon, inheritableIcon }[i];
1356
		if (string.equals(TARGET))
1357
			return new Image[] { fileIcon, folderIcon, fileFolderIcon }[i];
1358
		return null;
1359
	}
1360
}
1609
}
1361
1610
1362
class FilterCopy extends UIResourceFilterDescription {
1611
class FilterCopy extends UIResourceFilterDescription {
Lines 1596-1602 Link Here
1596
		}
1845
		}
1597
	}
1846
	}
1598
1847
1599
	public void addChild(FilterCopy child) {
1848
	protected void addChild(FilterCopy child) {
1600
		initializeChildren();
1849
		initializeChildren();
1601
		if (child.getParent() != null)
1850
		if (child.getParent() != null)
1602
			child.getParent().removeChild(child);
1851
			child.getParent().removeChild(child);
Lines 1605-1611 Link Here
1605
		serializeChildren();
1854
		serializeChildren();
1606
	}
1855
	}
1607
1856
1608
	public void removeChild(FilterCopy child) {
1857
	protected void removeChild(FilterCopy child) {
1609
		initializeChildren();
1858
		initializeChildren();
1610
		children.remove(child);
1859
		children.remove(child);
1611
		if (child.parent == this)
1860
		if (child.parent == this)
Lines 1663-1700 Link Here
1663
1912
1664
	private FilterCopy filter;
1913
	private FilterCopy filter;
1665
1914
1666
	protected Button includeButton;
1667
	protected Button excludeButton;
1668
	protected Button filesButton;
1915
	protected Button filesButton;
1669
	protected Button foldersButton;
1916
	protected Button foldersButton;
1670
	protected Button filesAndFoldersButton;
1917
	protected Button filesAndFoldersButton;
1671
	protected Combo idCombo;
1918
	protected Combo idCombo;
1919
	protected Composite idComposite;
1920
	protected Button idButton;
1921
	protected Composite argumentComposite;
1672
	protected Button inherited;
1922
	protected Button inherited;
1673
	protected Text arguments;
1674
	protected Label argumentsLabel;
1675
	protected Label description;
1676
	protected FilterTypeUtil util;
1923
	protected FilterTypeUtil util;
1924
	protected boolean createGroupOnly;
1925
	protected boolean creatingNewFilter;
1926
	protected ResourceFilterGroup filterGroup;
1677
	protected IResource resource;
1927
	protected IResource resource;
1678
1928
1679
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$
1929
	TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
1680
	
1930
	ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() {
1681
	/**
1931
		public Object getID() {return "dummy";} //$NON-NLS-1$
1682
	 * Find and replace command adapters.
1932
		public void create(Composite argumentComposite, Font font) {}
1683
	 * @since 3.3
1933
		public void dispose() {}
1684
	 */
1934
		public void selectionChanged() {}
1685
	private ContentAssistCommandAdapter fContentAssistField;
1935
		public void validate() {}
1936
		public StyledString formatStyledText(FilterCopy filter,
1937
				Styler fPlainStyler, Styler fBoldStyler) {return null;}
1938
	};
1686
1939
1687
	/**
1940
	/**
1688
	 * Constructor for FilterEditDialog.
1941
	 * Constructor for FilterEditDialog.
1689
	 * 
1942
	 * @param resource 
1943
	 * @param filterGroup 
1690
	 * @param parentShell
1944
	 * @param parentShell
1691
	 * @param filter
1945
	 * @param filter
1946
	 * @param createGroupOnly 
1692
	 */
1947
	 */
1693
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) {
1948
	public FilterEditDialog(IResource resource, ResourceFilterGroup filterGroup, Shell parentShell, FilterCopy filter, boolean createGroupOnly, boolean creatingNewFilter) {
1694
		super(parentShell);
1949
		super(parentShell);
1695
		this.resource = resource;
1950
		this.resource = resource;
1951
		this.creatingNewFilter = creatingNewFilter;
1952
		this.filterGroup = filterGroup;
1696
		this.filter = filter;
1953
		this.filter = filter;
1954
		this.createGroupOnly = createGroupOnly;
1697
		util = new FilterTypeUtil();
1955
		util = new FilterTypeUtil();
1956
		ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter);
1957
		customfilterArgumentMap.put(ui.getID(), ui);
1958
		ui = new DefaultCustomFilterArgumentUI(parentShell, filter);
1959
		customfilterArgumentMap.put(ui.getID(), ui);
1698
	}
1960
	}
1699
1961
1700
	/*
1962
	/*
Lines 1712-1718 Link Here
1712
		Composite composite = new Composite(parent, SWT.NONE);
1974
		Composite composite = new Composite(parent, SWT.NONE);
1713
		GridLayout layout = new GridLayout();
1975
		GridLayout layout = new GridLayout();
1714
		layout.numColumns = 1;
1976
		layout.numColumns = 1;
1715
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1977
		layout.marginHeight = 0;
1716
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1978
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1717
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1979
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1718
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1980
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
Lines 1728-1748 Link Here
1728
		if (!filter.isUnderAGroupFilter()) {
1990
		if (!filter.isUnderAGroupFilter()) {
1729
			Composite topComposite = new Composite(composite, SWT.NONE);
1991
			Composite topComposite = new Composite(composite, SWT.NONE);
1730
			layout = new GridLayout();
1992
			layout = new GridLayout();
1731
			layout.numColumns = 2;
1993
			layout.numColumns = 1;
1732
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1994
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1733
			layout.marginWidth = 0;
1995
			layout.marginWidth = 0;
1996
			layout.marginBottom = 0;
1734
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1997
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1735
			layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1998
			layout.horizontalSpacing = 0; // convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1736
			topComposite.setLayout(layout);
1999
			topComposite.setLayout(layout);
1737
			data = new GridData(SWT.FILL, SWT.FILL, true, false);
2000
			data = new GridData(SWT.FILL, SWT.FILL, true, false);
1738
			topComposite.setLayoutData(data);
2001
			topComposite.setLayoutData(data);
1739
			topComposite.setFont(font);
2002
			topComposite.setFont(font);
1740
2003
1741
			createModeArea(font, topComposite);
1742
			createTargetArea(font, topComposite);
2004
			createTargetArea(font, topComposite);
2005
			
2006
			createIdArea(font, topComposite);
2007
			createInheritableArea(font, topComposite);
2008
		}
2009
		else {
2010
			layout.marginHeight = convertHorizontalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
2011
			createIdArea(font, composite);
1743
		}
2012
		}
1744
		createIdArea(font, composite);
2013
		return composite;
2014
	}
2015
2016
	/* (non-Javadoc)
2017
	 * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
2018
	 */
2019
	protected Control createButtonBar(Composite parent) {
2020
		Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
2021
		label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
2022
2023
		Composite composite = new Composite(parent, SWT.NONE);
2024
    	GridLayout layout = new GridLayout();
2025
    	layout.marginWidth = 0;
2026
    	layout.marginHeight = 0;
2027
    	layout.horizontalSpacing = 0;
2028
    	composite.setLayout(layout);
2029
    	composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
2030
    	composite.setFont(parent.getFont());
2031
2032
		// create help control if needed
2033
        if (isHelpAvailable()) {
2034
        	Control helpControl = createHelpControl(composite);
2035
        	((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2036
		}
2037
       
2038
        Control buttonSection = dialogCreateButtonBar(composite);
2039
        ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
2040
        return composite;
2041
	}
1745
2042
2043
	private Control dialogCreateButtonBar(Composite parent) {
2044
		Composite composite = new Composite(parent, SWT.NONE);
2045
		// create a layout with spacing and margins appropriate for the font
2046
		// size.
2047
		GridLayout layout = new GridLayout();
2048
		layout.numColumns = 0; // this is incremented by createButton
2049
		layout.makeColumnsEqualWidth = true;
2050
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2051
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
2052
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
2053
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
2054
		composite.setLayout(layout);
2055
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END
2056
				| GridData.VERTICAL_ALIGN_CENTER);
2057
		composite.setLayoutData(data);
2058
		composite.setFont(parent.getFont());
2059
		
2060
		// Add the buttons to the button bar.
2061
		createButtonsForButtonBar(composite);
1746
		return composite;
2062
		return composite;
1747
	}
2063
	}
1748
2064
Lines 1751-1772 Link Here
1751
	 * @param composite
2067
	 * @param composite
1752
	 */
2068
	 */
1753
	private void createInheritableArea(Font font, Composite composite) {
2069
	private void createInheritableArea(Font font, Composite composite) {
2070
		Composite inheritableComposite = createGroup(font, composite, NLS.bind(
2071
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2072
				null), false, false, 1);
2073
		GridLayout layout = (GridLayout) inheritableComposite.getLayout();
2074
		layout.marginBottom = 0;
2075
		layout.marginTop = 0;
2076
		layout.marginHeight = 0;
2077
		layout.marginWidth = 0;
2078
		layout.verticalSpacing = 0;
2079
		layout.marginLeft = 0;
2080
		inheritableComposite.setLayout(layout);
2081
1754
		GridData data;
2082
		GridData data;
1755
		inherited = new Button(composite, SWT.CHECK);
2083
		inherited = new Button(inheritableComposite, SWT.CHECK);
1756
		inherited
2084
		inherited
1757
				.setText(NLS
2085
				.setText(NLS
1758
						.bind(
2086
						.bind(
1759
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
2087
								IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure,
1760
								null));
2088
								null));
1761
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
2089
		inherited.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 2));
1762
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2090
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1763
		data.horizontalSpan = 1;
2091
		data.horizontalSpan = 1;
1764
		inherited.setLayoutData(data);
2092
		inherited.setLayoutData(data);
1765
		inherited.setFont(font);
2093
		inherited.setFont(font);
1766
		inherited.addSelectionListener(new SelectionListener() {
2094
		inherited.addSelectionListener(new SelectionAdapter() {
1767
			public void widgetDefaultSelected(SelectionEvent e) {
1768
			}
1769
1770
			public void widgetSelected(SelectionEvent e) {
2095
			public void widgetSelected(SelectionEvent e) {
1771
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
2096
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1772
						new Boolean(inherited.getSelection()));
2097
						new Boolean(inherited.getSelection()));
Lines 1780-1884 Link Here
1780
	 * @param font
2105
	 * @param font
1781
	 * @param composite
2106
	 * @param composite
1782
	 */
2107
	 */
1783
	private void createArgumentsArea(Font font, Composite composite) {
2108
	private void createIdArea(Font font, Composite composite) {
1784
		GridData data;
2109
		if (createGroupOnly) {
1785
		argumentsLabel = addLabel(composite, NLS.bind(
2110
			idComposite = createGroup(font, composite, new String(),
1786
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
2111
					true, true, 1);
1787
				null));
2112
			createMatcherCombo(idComposite, font);
1788
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
2113
			GridData data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1789
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2114
			idCombo.setLayoutData(data);
1790
		arguments.setLayoutData(data);
2115
		}
1791
		arguments.setFont(font);
2116
		else {
1792
		arguments.addModifyListener(new ModifyListener() {
2117
			Composite superIdComposite = createGroup(font, composite, new String(),
1793
			public void modifyText(ModifyEvent e) {
2118
					true, false, 1);
1794
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
2119
			GridLayout layout = (GridLayout) superIdComposite.getLayout();
1795
						arguments.getText());
2120
			layout.marginBottom = 0;
1796
			}
2121
			layout.marginTop = 0;
1797
		});
2122
			layout.marginHeight = 0;
1798
		if (filter.hasStringArguments())
2123
			layout.marginWidth = 0;
1799
			arguments.setText((String) FilterTypeUtil.getValue(filter,
2124
			layout.verticalSpacing = 0;
1800
					FilterTypeUtil.ARGUMENTS));
2125
			layout.marginLeft = 0;
1801
		arguments.setEnabled(filter.hasStringArguments());
2126
			superIdComposite.setLayout(layout);
1802
		setArgumentLabelEnabled();
2127
			
1803
2128
			Composite labelComposite = createGroup(font, superIdComposite, new String(),
1804
		TextContentAdapter contentAdapter= new TextContentAdapter();
2129
					true, false, 2);
1805
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2130
			
1806
		fContentAssistField= new ContentAssistCommandAdapter(
2131
			layout = (GridLayout) labelComposite.getLayout();
1807
				arguments,
2132
			layout.marginBottom = 0;
1808
				contentAdapter,
2133
			layout.marginLeft = 0;
1809
				findProposer, 
2134
			layout.marginTop = 0;
1810
				null,
2135
			layout.marginHeight = 0;
1811
				new char[] {'\\', '[', '('},
2136
			layout.marginWidth = 0;
1812
				true);
2137
			layout.verticalSpacing = 0;
1813
	}
2138
			labelComposite.setLayout(layout);
1814
1815
	/**
1816
	 * 
1817
	 */
1818
	private void setArgumentLabelEnabled() {
1819
		Color color = argumentsLabel.getDisplay().getSystemColor(
1820
				filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
1821
		argumentsLabel.setForeground(color);
1822
	}
1823
2139
1824
	/**
2140
			Label label = new Label(labelComposite, SWT.NONE);
1825
	 * @param font
2141
			label.setText(NLS.bind(IDEWorkbenchMessages.ResourceFilterPage_condition, null));
1826
	 * @param composite
2142
			label.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
1827
	 */
2143
			label.setFont(font);
1828
	private void createDescriptionArea(Font font, Composite composite) {
2144
1829
		GridData data;
2145
			createMatcherCombo(labelComposite, font);
1830
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2146
1831
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
2147
			idComposite = createGroup(font, superIdComposite, new String(),
1832
				.getDescription());
2148
					true, true, 1);
1833
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2149
			layout = (GridLayout) idComposite.getLayout();
1834
		data.widthHint = 300;
2150
			layout.marginBottom = 0;
1835
		data.heightHint = 40;
2151
			layout.marginTop = 0;
1836
		description.setLayoutData(data);
2152
			layout.marginWidth = 0;
1837
		description.setFont(font);
2153
			layout.marginHeight = 0;
2154
			layout.verticalSpacing = 0;
2155
			idComposite.setLayout(layout);
2156
		}
2157
		argumentComposite = new Composite(idComposite, SWT.NONE);
2158
		setupPatternLine();
1838
	}
2159
	}
1839
2160
1840
	/**
2161
	private void createMatcherCombo(Composite composite, Font font) {
1841
	 * @param font
1842
	 * @param composite
1843
	 */
1844
	private void createIdArea(Font font, Composite composite) {
1845
		GridData data;
2162
		GridData data;
1846
		Group idComposite = createGroup(font, composite, NLS.bind(
2163
		idCombo = new Combo(composite, SWT.READ_ONLY);
1847
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null),
2164
		idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly));
1848
				true);
2165
		data = new GridData(SWT.LEFT, SWT.CENTER, true, false);
1849
		idCombo = new Combo(idComposite, SWT.READ_ONLY);
1850
		idCombo.setItems(FilterTypeUtil.getFilterNames(filter
1851
				.getChildrenLimit() > 0));
1852
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1853
		idCombo.setLayoutData(data);
2166
		idCombo.setLayoutData(data);
1854
		idCombo.setFont(font);
2167
		idCombo.setFont(font);
1855
		idCombo.addSelectionListener(new SelectionListener() {
2168
		idCombo.addSelectionListener(new SelectionAdapter() {
1856
			public void widgetDefaultSelected(SelectionEvent e) {
1857
			}
1858
1859
			public void widgetSelected(SelectionEvent e) {
2169
			public void widgetSelected(SelectionEvent e) {
1860
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
2170
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1861
						.getItem(idCombo.getSelectionIndex()));
2171
						.getItem(idCombo.getSelectionIndex()));
1862
				arguments.setEnabled(filter.hasStringArguments());
2172
				if (filter.hasStringArguments())
1863
				setArgumentLabelEnabled();
2173
					filter.setArguments(new String());
1864
				description.setText(FilterTypeUtil
2174
				setupPatternLine();
1865
						.getDescriptor(filter.getId()).getDescription());
2175
				currentCustomFilterArgumentUI.selectionChanged();
1866
				fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
1867
			}
2176
			}
1868
		});
2177
		});
2178
		idCombo.select(0);
1869
		selectComboItem(filter.getId());
2179
		selectComboItem(filter.getId());
1870
		Composite argumentComposite = new Composite(idComposite, SWT.NONE);
2180
		FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1871
		GridLayout layout = new GridLayout();
2181
				.getItem(idCombo.getSelectionIndex()));
1872
		layout.numColumns = 2;
2182
	}
1873
		layout.marginWidth = 0;
2183
	
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
2184
1880
		createDescriptionArea(font, idComposite);
2185
	ICustomFilterArgumentUI getUI(String descriptorID) {
1881
		fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
2186
		ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
2187
		if (result == null)
2188
			return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
2189
		return result;
2190
	}
2191
	
2192
	private void setupPatternLine() {
2193
		IFilterMatcherDescriptor descriptor;
2194
		if (createGroupOnly) {
2195
			String item = idCombo.getItem(idCombo.getSelectionIndex());
2196
			descriptor = FilterTypeUtil.getDescriptorByName(item);
2197
		}
2198
		else
2199
			descriptor = FilterTypeUtil.getDescriptor(filter.getId());
2200
		Font font = idComposite.getFont();
2201
		ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId());
2202
		if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) {
2203
			currentCustomFilterArgumentUI.dispose();
2204
			currentCustomFilterArgumentUI = customFilterArgumentUI;
2205
			currentCustomFilterArgumentUI.create(argumentComposite, font);
2206
			getShell().layout(true);
2207
			getShell().redraw();
2208
		}
1882
	}
2209
	}
1883
2210
1884
	/**
2211
	/**
Lines 1901-1967 Link Here
1901
	/**
2228
	/**
1902
	 * @param font
2229
	 * @param font
1903
	 * @param composite
2230
	 * @param composite
1904
	 */
1905
	private void createModeArea(Font font, Composite composite) {
1906
		GridData data;
1907
		Group modeComposite = createGroup(font, composite, NLS.bind(
1908
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
1909
				null), false);
1910
		String[] modes = FilterTypeUtil.getModes();
1911
		includeButton = new Button(modeComposite, SWT.RADIO);
1912
		includeButton.setText(modes[0]);
1913
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
1914
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1915
		includeButton.setLayoutData(data);
1916
		includeButton.setFont(font);
1917
		includeButton.addSelectionListener(new SelectionListener() {
1918
			public void widgetDefaultSelected(SelectionEvent e) {
1919
			}
1920
1921
			public void widgetSelected(SelectionEvent e) {
1922
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1923
						new Integer(0));
1924
			}
1925
		});
1926
		includeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1927
				filter, FilterTypeUtil.MODE)).intValue() == 0);
1928
		excludeButton = new Button(modeComposite, SWT.RADIO);
1929
		excludeButton.setText(modes[1]);
1930
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
1931
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1932
		excludeButton.setLayoutData(data);
1933
		excludeButton.setFont(font);
1934
		excludeButton.addSelectionListener(new SelectionListener() {
1935
			public void widgetDefaultSelected(SelectionEvent e) {
1936
			}
1937
1938
			public void widgetSelected(SelectionEvent e) {
1939
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1940
						new Integer(1));
1941
			}
1942
		});
1943
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1944
				filter, FilterTypeUtil.MODE)).intValue() == 1);
1945
		createInheritableArea(font, modeComposite);
1946
	}
1947
1948
	/**
1949
	 * @param font
1950
	 * @param composite
1951
	 * @return the group
2231
	 * @return the group
1952
	 */
2232
	 */
1953
	private Group createGroup(Font font, Composite composite, String text,
2233
	private Composite createGroup(Font font, Composite composite, String text,
1954
			boolean grabExcessVerticalSpace) {
2234
			boolean grabExcessVerticalSpace, boolean group, int columnCounts) {
1955
		GridLayout layout;
2235
		GridLayout layout;
1956
		GridData data;
2236
		GridData data;
1957
		Group modeComposite = new Group(composite, SWT.NONE);
2237
		Composite modeComposite;
1958
		modeComposite.setText(text);
2238
		if (group) { 
2239
			Group modeGroup = new Group(composite, SWT.NONE);
2240
			modeGroup.setText(text);
2241
			modeComposite = modeGroup;
2242
		} else {
2243
			modeComposite = new Composite(composite, SWT.NONE);
2244
		}
1959
		layout = new GridLayout();
2245
		layout = new GridLayout();
1960
		layout.numColumns = 1;
2246
		layout.verticalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1961
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
2247
		layout.marginLeft = 2;
1962
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2248
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1963
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
2249
		layout.numColumns = columnCounts;
1964
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1965
		modeComposite.setLayout(layout);
2250
		modeComposite.setLayout(layout);
1966
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
2251
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
1967
		modeComposite.setLayoutData(data);
2252
		modeComposite.setLayoutData(data);
Lines 1975-2028 Link Here
1975
	 */
2260
	 */
1976
	private void createTargetArea(Font font, Composite composite) {
2261
	private void createTargetArea(Font font, Composite composite) {
1977
		GridData data;
2262
		GridData data;
1978
		Group targetComposite = createGroup(font, composite, NLS.bind(
2263
		Composite targetComposite = createGroup(font, composite, 
1979
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
2264
				NLS.bind(IDEWorkbenchMessages.ResourceFilterPage_columnFilterTarget, null), false, true, 3);
1980
				null), false);
2265
		
1981
1982
		String[] targets = FilterTypeUtil.getTargets();
2266
		String[] targets = FilterTypeUtil.getTargets();
1983
		filesButton = new Button(targetComposite, SWT.RADIO);
2267
		filesButton = new Button(targetComposite, SWT.RADIO);
1984
		filesButton.setText(targets[0]);
2268
		filesButton.setText(targets[0]);
1985
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
2269
		filesButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 0));
1986
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2270
		data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
1987
		filesButton.setLayoutData(data);
2271
		filesButton.setLayoutData(data);
1988
		filesButton.setFont(font);
2272
		filesButton.setFont(font);
1989
2273
1990
		foldersButton = new Button(targetComposite, SWT.RADIO);
2274
		foldersButton = new Button(targetComposite, SWT.RADIO);
1991
		foldersButton.setText(targets[1]);
2275
		foldersButton.setText(targets[1]);
1992
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
2276
		foldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 1));
1993
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2277
		data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
1994
		foldersButton.setLayoutData(data);
2278
		foldersButton.setLayoutData(data);
1995
		foldersButton.setFont(font);
2279
		foldersButton.setFont(font);
1996
2280
1997
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
2281
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
1998
		filesAndFoldersButton.setText(targets[2]);
2282
		filesAndFoldersButton.setText(targets[2]);
1999
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2283
		filesAndFoldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 2));
2000
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2284
		data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
2001
		filesAndFoldersButton.setLayoutData(data);
2285
		filesAndFoldersButton.setLayoutData(data);
2002
		filesAndFoldersButton.setFont(font);
2286
		filesAndFoldersButton.setFont(font);
2003
2287
2004
		filesButton.addSelectionListener(new SelectionListener() {
2288
		filesButton.addSelectionListener(new SelectionAdapter() {
2005
			public void widgetDefaultSelected(SelectionEvent e) {
2006
			}
2007
2008
			public void widgetSelected(SelectionEvent e) {
2289
			public void widgetSelected(SelectionEvent e) {
2009
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2290
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2010
						new Integer(0));
2291
						new Integer(0));
2011
			}
2292
			}
2012
		});
2293
		});
2013
		foldersButton.addSelectionListener(new SelectionListener() {
2294
		foldersButton.addSelectionListener(new SelectionAdapter() {
2014
			public void widgetDefaultSelected(SelectionEvent e) {
2015
			}
2016
2017
			public void widgetSelected(SelectionEvent e) {
2295
			public void widgetSelected(SelectionEvent e) {
2018
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2296
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2019
						new Integer(1));
2297
						new Integer(1));
2020
			}
2298
			}
2021
		});
2299
		});
2022
		filesAndFoldersButton.addSelectionListener(new SelectionListener() {
2300
		filesAndFoldersButton.addSelectionListener(new SelectionAdapter() {
2023
			public void widgetDefaultSelected(SelectionEvent e) {
2024
			}
2025
2026
			public void widgetSelected(SelectionEvent e) {
2301
			public void widgetSelected(SelectionEvent e) {
2027
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2302
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2028
						new Integer(2));
2303
						new Integer(2));
Lines 2036-2053 Link Here
2036
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2311
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2037
	}
2312
	}
2038
2313
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) {
2314
	protected Control createContents(Composite parent) {
2052
		Control control = super.createContents(parent);
2315
		Control control = super.createContents(parent);
2053
		initialize();
2316
		initialize();
Lines 2065-2074 Link Here
2065
	}
2328
	}
2066
2329
2067
	protected void configureShell(Shell newShell) {
2330
	protected void configureShell(Shell newShell) {
2068
		newShell.setText(NLS.bind(
2331
		Integer index = (Integer) FilterTypeUtil.getValue(filter, FilterTypeUtil.MODE);
2069
				IDEWorkbenchMessages.ResourceFilterPage_editFilterDialogTitle,
2332
		String title = null;
2070
				null));
2333
		if (creatingNewFilter) {
2334
			if (index.intValue() == 0)
2335
				title = IDEWorkbenchMessages.ResourceFilterPage_newFilterDialogTitleIncludeOnly;
2336
			else
2337
				title = IDEWorkbenchMessages.ResourceFilterPage_newFilterDialogTitleExcludeAll;
2338
		}
2339
		else
2340
			title = IDEWorkbenchMessages.ResourceFilterPage_editFilterDialogTitle;
2341
		newShell.setText(title);
2071
		super.configureShell(newShell);
2342
		super.configureShell(newShell);
2343
		newShell.setImage(filterGroup.getImage(FilterTypeUtil.MODE, index.intValue()));
2072
	}
2344
	}
2073
2345
2074
	private void initialize() {
2346
	private void initialize() {
Lines 2082-2089 Link Here
2082
		if (filter.hasStringArguments()) {
2354
		if (filter.hasStringArguments()) {
2083
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2355
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2084
			if (desc != null) {
2356
			if (desc != null) {
2085
				AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2086
				try {
2357
				try {
2358
					currentCustomFilterArgumentUI.validate();
2359
					AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2087
					matcher.initialize(resource.getProject(), filter.getArguments());
2360
					matcher.initialize(resource.getProject(), filter.getArguments());
2088
				} catch (CoreException e) {
2361
				} catch (CoreException e) {
2089
					IWorkbenchWindow window = PlatformUI.getWorkbench()
2362
					IWorkbenchWindow window = PlatformUI.getWorkbench()
Lines 2099-2102 Link Here
2099
2372
2100
		super.okPressed();
2373
		super.okPressed();
2101
	}
2374
	}
2375
}
2376
2377
interface ICustomFilterArgumentUI {
2378
2379
	/**
2380
	 * @return the descriptor ID
2381
	 */
2382
	Object getID();
2383
2384
	/**
2385
	 * @param filter
2386
	 * @param fPlainStyler
2387
	 * @param fBoldStyler
2388
	 * @return the formatted StyledText
2389
	 */
2390
	StyledString formatStyledText(FilterCopy filter, Styler fPlainStyler,
2391
			Styler fBoldStyler);
2392
2393
	/**
2394
	 * @throws CoreException 
2395
	 * 
2396
	 */
2397
	void validate() throws CoreException;
2398
2399
	/**
2400
	 * 
2401
	 */
2402
	void selectionChanged();
2403
2404
	/**
2405
	 * @param argumentComposite
2406
	 * @param font
2407
	 */
2408
	void create(Composite argumentComposite, Font font);
2409
2410
	/**
2411
	 * 
2412
	 */
2413
	void dispose();
2414
	
2415
}
2416
2417
class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2418
2419
	Shell shell;
2420
	FilterCopy filter;
2421
	protected Button argumentsCaseSensitive;
2422
	protected Button argumentsRegularExpresion;
2423
	protected Text arguments;
2424
	protected DateTime argumentsDate;
2425
	protected Combo argumentsBoolean;
2426
	protected Label argumentsLabel;
2427
	protected Label description;
2428
	protected ContentAssistCommandAdapter fContentAssistField;
2429
	protected Combo multiKey;
2430
	protected Combo multiOperator;
2431
	protected Composite multiArgumentComposite;
2432
	protected Composite stringArgumentComposite;
2433
	protected Composite attributeStringArgumentComposite;
2434
	protected Class intiantiatedKeyOperatorType = null;
2435
	protected TreeMap/* <String, String>*/ valueCache = new TreeMap();
2436
	protected boolean initializationComplete = false;
2437
	
2438
	/**
2439
	 * @param parentShell
2440
	 * @param filter
2441
	 */
2442
	public MultiMatcherCustomFilterArgumentUI(Shell parentShell,
2443
			FilterCopy filter) {
2444
		this.shell = parentShell;
2445
		this.filter = filter;
2446
	}
2447
2448
	/* (non-Javadoc)
2449
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2450
	 */
2451
	public Object getID() {
2452
		return FileInfoAttributesMatcher.ID;
2453
	}
2454
2455
	/* (non-Javadoc)
2456
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2457
	 */
2458
	public void dispose() {
2459
		Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description};
2460
		for (int i = 0; i < list.length; i++) {
2461
			if (list[i] != null) {
2462
				list[i].dispose();
2463
			}
2464
		}
2465
		multiKey = null;
2466
		multiOperator = null;
2467
		multiArgumentComposite = null;
2468
		arguments = null;
2469
		argumentsLabel = null;
2470
		fContentAssistField = null;
2471
		intiantiatedKeyOperatorType = null;
2472
		stringArgumentComposite = null;
2473
		argumentsCaseSensitive = null;
2474
		argumentsRegularExpresion = null;
2475
		attributeStringArgumentComposite = null;
2476
		description = null;
2477
		initializationComplete = false;
2478
	}
2479
2480
	/* (non-Javadoc)
2481
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2482
	 */
2483
	public void create(Composite argumentComposite, Font font) {
2484
		shell = argumentComposite.getShell();
2485
		GridLayout layout = new GridLayout();
2486
		layout.numColumns = 3;
2487
		layout.marginWidth = 0;
2488
		argumentComposite.setLayout(layout);
2489
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2490
		argumentComposite.setLayoutData(data);
2491
		argumentComposite.setFont(font);
2492
		createCustomArgumentsArea(font, argumentComposite);
2493
		argumentComposite.layout(true);
2494
		createDescriptionArea(font, argumentComposite);
2495
		initializationComplete = true;
2496
	}
2497
	
2498
	/**
2499
	 * @param font
2500
	 * @param composite
2501
	 */
2502
	private void createDescriptionArea(Font font, Composite composite) {
2503
		GridData data;
2504
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2505
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2506
		data.widthHint = 300;
2507
		data.heightHint = 40;
2508
		data.horizontalSpan = 3;
2509
		description.setLayoutData(data);
2510
		description.setFont(font);
2511
		setupDescriptionText();
2512
	}
2513
2514
	private void setupDescriptionText() {
2515
		if (description != null) {
2516
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2517
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2518
			Class selectedKeyOperatorType = FileInfoAttributesMatcher.getTypeForKey(selectedKey, selectedOperator);
2519
			description.setText(new String());
2520
			if (selectedKeyOperatorType.equals(String.class)) {
2521
				if (!argumentsRegularExpresion.getSelection())
2522
					description.setText(NLS.bind(
2523
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null));
2524
			}
2525
			if (selectedKeyOperatorType.equals(Integer.class)) {
2526
				if (selectedKey.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(FileInfoAttributesMatcher.KEY_CREATED))
2527
					description.setText(NLS.bind(
2528
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_TimeInterval, null));
2529
				else
2530
				description.setText(NLS.bind(
2531
						IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null));
2532
			}
2533
		}
2534
	}
2535
	
2536
	private void createCustomArgumentsArea(Font font, Composite composite) {
2537
		GridData data;
2538
		multiKey = new Combo(composite, SWT.READ_ONLY);
2539
		multiKey.setItems(getMultiMatcherKeys());
2540
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2541
		multiKey.setLayoutData(data);
2542
		multiKey.setFont(font);
2543
		multiKey.addSelectionListener(new SelectionAdapter() {
2544
			public void widgetSelected(SelectionEvent e) {
2545
				setupMultiOperatorAndField(true);
2546
				storeMultiSelection();
2547
			}
2548
		});
2549
2550
		multiOperator = new Combo(composite, SWT.READ_ONLY);
2551
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2552
		multiOperator.setLayoutData(data);
2553
		multiOperator.setFont(font);
2554
		multiOperator.addSelectionListener(new SelectionAdapter() {
2555
			public void widgetSelected(SelectionEvent e) {
2556
				setupMultiOperatorAndField(false);
2557
				storeMultiSelection();
2558
			}
2559
		});
2560
		
2561
		multiArgumentComposite = new Composite(composite, SWT.NONE);
2562
		
2563
		GridLayout layout = new GridLayout();
2564
		layout.numColumns = 1;
2565
		layout.marginWidth = 0;
2566
		layout.horizontalSpacing = 0;
2567
		layout.verticalSpacing = 0;
2568
		layout.marginBottom = 0;
2569
		layout.marginHeight = 0;
2570
		multiArgumentComposite.setLayout(layout);
2571
		data = new GridData(SWT.FILL, SWT.TOP, true, true);
2572
		multiArgumentComposite.setLayoutData(data);
2573
		multiArgumentComposite.setFont(font);
2574
2575
		FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2576
		String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key);
2577
		int index = multiKey.indexOf(local);
2578
		if (index != -1)
2579
			multiKey.select(index);
2580
		else
2581
			multiKey.select(0);
2582
		
2583
		setupMultiOperatorAndField(true);
2584
	}
2585
2586
	private void setupMultiOperatorAndField(boolean updateOperator) {
2587
		boolean isUsingRegularExpression = false;
2588
		String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2589
		if (updateOperator) {
2590
			String[] operators = getLocalOperatorsForKey(selectedKey);
2591
			multiOperator.setItems(operators);
2592
			FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2593
			String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
2594
			int index = multiOperator.indexOf(local);
2595
			if (index != -1)
2596
				multiOperator.select(index);
2597
			else
2598
				multiOperator.select(0);
2599
		}
2600
		String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2601
		
2602
		Class selectedKeyOperatorType = FileInfoAttributesMatcher.getTypeForKey(selectedKey, selectedOperator);
2603
		
2604
		if (intiantiatedKeyOperatorType != null) {
2605
			if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType))
2606
				return;
2607
			if (arguments != null) {
2608
				arguments.dispose();
2609
				arguments = null;
2610
			}
2611
			if (attributeStringArgumentComposite != null) {
2612
				attributeStringArgumentComposite.dispose();
2613
				attributeStringArgumentComposite = null;
2614
			}
2615
			if (stringArgumentComposite != null) {
2616
				stringArgumentComposite.dispose();
2617
				stringArgumentComposite = null;
2618
			}
2619
			if (argumentsBoolean != null) {
2620
				argumentsBoolean.dispose();
2621
				argumentsBoolean = null;
2622
			}
2623
			if (argumentsDate != null) {
2624
				argumentsDate.dispose();
2625
				argumentsDate = null;
2626
			}
2627
			if (argumentsRegularExpresion != null) {
2628
				argumentsRegularExpresion.dispose();
2629
				argumentsRegularExpresion = null;
2630
			}
2631
			if (argumentsCaseSensitive != null) {
2632
				argumentsCaseSensitive.dispose();
2633
				argumentsCaseSensitive = null;
2634
			}
2635
			fContentAssistField = null;
2636
			FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2637
			valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern);
2638
			argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName());
2639
			if (argument.pattern == null)
2640
				argument.pattern = new String();
2641
			filter.setArguments(FileInfoAttributesMatcher.encodeArguments(argument));
2642
		}
2643
		if (selectedKeyOperatorType.equals(String.class)) {
2644
			stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);
2645
			
2646
			GridData data;
2647
			GridLayout layout = new GridLayout();
2648
			layout.numColumns = 2;
2649
			layout.marginWidth = 4;
2650
			layout.horizontalSpacing = 4;
2651
			layout.verticalSpacing = 0;
2652
			layout.marginBottom = 0;
2653
			layout.marginHeight = 0;
2654
			stringArgumentComposite.setLayout(layout);
2655
			data = new GridData(SWT.FILL, SWT.TOP, true, true);
2656
			stringArgumentComposite.setLayoutData(data);
2657
			stringArgumentComposite.setFont(multiArgumentComposite.getFont());
2658
2659
			arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER);
2660
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2661
			data.minimumWidth = 100;
2662
			arguments.setLayoutData(data);
2663
			arguments.setFont(stringArgumentComposite.getFont());
2664
	
2665
			attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE);
2666
			
2667
			layout = new GridLayout();
2668
			layout.numColumns = 1;
2669
			layout.marginWidth = 0;
2670
			layout.horizontalSpacing = 4;
2671
			layout.verticalSpacing = 0;
2672
			layout.marginBottom = 0;
2673
			layout.marginHeight = 0;
2674
			attributeStringArgumentComposite.setLayout(layout);
2675
			data = new GridData(SWT.FILL, SWT.TOP, false, true);
2676
			attributeStringArgumentComposite.setLayoutData(data);
2677
			attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont());
2678
2679
			argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK);
2680
			argumentsCaseSensitive.setText(NLS.bind(
2681
					IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
2682
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2683
			data.minimumWidth = 100;
2684
			argumentsCaseSensitive.setLayoutData(data);
2685
			argumentsCaseSensitive.setFont(stringArgumentComposite.getFont());
2686
2687
			argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK);
2688
			argumentsRegularExpresion.setText(NLS.bind(
2689
					IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
2690
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2691
			data.minimumWidth = 100;
2692
			argumentsRegularExpresion.setLayoutData(data);
2693
			argumentsRegularExpresion.setFont(stringArgumentComposite.getFont());
2694
2695
			if (filter.hasStringArguments()) {
2696
				FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2697
				arguments.setText(argument.pattern);
2698
				isUsingRegularExpression = argument.regularExpression;
2699
				argumentsCaseSensitive.setSelection(argument.caseSensitive);
2700
				argumentsRegularExpresion.setSelection(argument.regularExpression);
2701
			}
2702
2703
			arguments.addModifyListener(new ModifyListener() {
2704
				public void modifyText(ModifyEvent e) {
2705
					storeMultiSelection();
2706
				}
2707
			});
2708
			argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
2709
				public void widgetSelected(SelectionEvent e) {
2710
					setupDescriptionText();
2711
					storeMultiSelection();
2712
					if (fContentAssistField != null)
2713
						fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
2714
				}
2715
			});
2716
			argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
2717
				public void widgetSelected(SelectionEvent e) {
2718
					storeMultiSelection();
2719
				}
2720
			});
2721
2722
			TextContentAdapter contentAdapter= new TextContentAdapter();
2723
			FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2724
			fContentAssistField= new ContentAssistCommandAdapter(
2725
					arguments,
2726
					contentAdapter,
2727
					findProposer, 
2728
					null,
2729
					new char[] {'\\', '[', '('},
2730
					true);
2731
		}
2732
		if (selectedKeyOperatorType.equals(Integer.class)) {
2733
			GridData data;
2734
			arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
2735
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2736
			data.minimumWidth = 100;
2737
			arguments.setLayoutData(data);
2738
			arguments.setFont(multiArgumentComposite.getFont());
2739
2740
			if (filter.hasStringArguments()) {
2741
				FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2742
				if (selectedKey.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(FileInfoAttributesMatcher.KEY_CREATED))
2743
					arguments.setText(convertToEditableTimeInterval(argument.pattern));
2744
				else
2745
					arguments.setText(convertToEditableLength(argument.pattern));
2746
			}
2747
			
2748
			arguments.addModifyListener(new ModifyListener() {
2749
				public void modifyText(ModifyEvent e) {
2750
					storeMultiSelection();
2751
				}
2752
			});
2753
		}
2754
		if (selectedKeyOperatorType.equals(Date.class)) {
2755
			GridData data;
2756
			argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM);
2757
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2758
			argumentsDate.setLayoutData(data);
2759
			argumentsDate.setFont(multiArgumentComposite.getFont());
2760
			argumentsDate.addSelectionListener(new SelectionAdapter() {
2761
				public void widgetSelected(SelectionEvent e) {
2762
					storeMultiSelection();
2763
				}
2764
			});
2765
			if (filter.hasStringArguments()) {
2766
				FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2767
				Date date; 
2768
				Calendar calendar = Calendar.getInstance();
2769
				try {
2770
					date = new Date(Long.parseLong(argument.pattern));
2771
					calendar.setTime(date);
2772
				} catch (NumberFormatException e1) {
2773
					date = new Date();
2774
					calendar.setTime(date);
2775
					argument.pattern = Long.toString(calendar.getTimeInMillis());
2776
				}
2777
				argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
2778
				argumentsDate.setMonth(calendar.get(Calendar.MONTH));
2779
				argumentsDate.setYear(calendar.get(Calendar.YEAR));
2780
			}
2781
		}
2782
		if (selectedKeyOperatorType.equals(Boolean.class)) {
2783
			GridData data;
2784
			argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
2785
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2786
			argumentsBoolean.setLayoutData(data);
2787
			argumentsBoolean.setFont(multiArgumentComposite.getFont());
2788
			argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())});
2789
			argumentsBoolean.addSelectionListener(new SelectionAdapter() {
2790
				public void widgetSelected(SelectionEvent e) {
2791
					storeMultiSelection();
2792
				}
2793
			});
2794
			if (filter.hasStringArguments()) {
2795
				FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments((String) filter.getArguments());
2796
				if (argument.pattern.length() == 0)
2797
					argumentsBoolean.select(0);
2798
				else
2799
					argumentsBoolean.select(Boolean.valueOf(argument.pattern).booleanValue() ? 0:1);
2800
			}
2801
		}
2802
		multiArgumentComposite.layout(true);
2803
		intiantiatedKeyOperatorType = selectedKeyOperatorType;
2804
		
2805
		if (fContentAssistField != null)
2806
			fContentAssistField.setEnabled(isUsingRegularExpression);
2807
2808
		shell.layout(true);
2809
		if (initializationComplete) {
2810
			Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
2811
			shell.setSize(size);
2812
		}
2813
		shell.redraw();
2814
		setupDescriptionText();
2815
	}
2816
2817
	private String[] timeIntervalPrefixes = {"s", "m", "h", "d"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
2818
	private double[] timeIntervalScale = {60, 60, 24};
2819
2820
	private String convertToEditableTimeInterval(String string) {
2821
		if (string.length() == 0)
2822
			return string;
2823
		long value;
2824
		try {
2825
			value = Long.parseLong(string);
2826
		} catch (NumberFormatException e) {
2827
			value = 0;
2828
		}
2829
		if (value == 0)
2830
			return Long.toString(0);
2831
		for (int i = 0; i < timeIntervalPrefixes.length - 1; i++) {
2832
			if (value % timeIntervalScale[i] != 0)
2833
				return Long.toString(value) + timeIntervalPrefixes[i];
2834
			value /= timeIntervalScale[i];
2835
		}
2836
		return Long.toString(value) + timeIntervalPrefixes[timeIntervalPrefixes.length - 1];
2837
	}
2838
2839
	private String convertFromEditableTimeInterval(String string) {
2840
		if (string.length() == 0)
2841
			return string;
2842
		for (int i = 1; i < timeIntervalPrefixes.length; i++) {
2843
			if (string.endsWith(timeIntervalPrefixes[i])) {
2844
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2845
				for (int j = 0; j < i; j++)
2846
					value *= timeIntervalScale[j];
2847
				return Long.toString(value);
2848
			}
2849
		}
2850
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2851
		return Long.toString(Long.parseLong(string));
2852
	}
2853
2854
2855
	private String[] lengthPrefixes = {new String(), "k", "m", "g"};    //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
2856
2857
	// converts "32768" to "32k"
2858
	private String convertToEditableLength(String string) {
2859
		if (string.length() == 0)
2860
			return string;
2861
		long value;
2862
		try {
2863
			value = Long.parseLong(string);
2864
		} catch (NumberFormatException e) {
2865
			value = 0;
2866
		}
2867
		if (value == 0)
2868
			return Long.toString(0);
2869
		for (int i = 0; i < lengthPrefixes.length; i++) {
2870
			if (value % 1024 != 0)
2871
				return Long.toString(value) + lengthPrefixes[i];
2872
			if ((i + 1) < lengthPrefixes.length)
2873
				value /= 1024;
2874
		}
2875
		return Long.toString(value) + lengthPrefixes[lengthPrefixes.length - 1];
2876
	}
2877
	
2878
	// converts "32k" to "32768"
2879
	private String convertFromEditableLength(String string) throws NumberFormatException {
2880
		if (string.length() == 0)
2881
			return string;
2882
		for (int i = 1; i < lengthPrefixes.length; i++) {
2883
			if (string.endsWith(lengthPrefixes[i])) {
2884
				long value = Long.parseLong(string.substring(0, string.length() - 1));
2885
				value *= Math.pow(1024, i);
2886
				return Long.toString(value);
2887
			}
2888
		}
2889
		// seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number
2890
		return Long.toString(Long.parseLong(string));
2891
	}
2892
	
2893
	private void storeMultiSelection() {
2894
		if (intiantiatedKeyOperatorType != null) {
2895
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2896
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2897
	
2898
			FileInfoAttributesMatcher.Argument argument = new FileInfoAttributesMatcher.Argument();
2899
			argument.key = selectedKey;
2900
			argument.operator = selectedOperator;
2901
			
2902
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2903
				Calendar calendar = Calendar.getInstance();
2904
				calendar.set(argumentsDate.getYear(), argumentsDate.getMonth(), argumentsDate.getDay());
2905
				argument.pattern = Long.toString(calendar.getTimeInMillis());
2906
			}
2907
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2908
				argument.pattern = arguments.getText();
2909
				if (argumentsRegularExpresion != null)
2910
					argument.regularExpression = argumentsRegularExpresion.getSelection();
2911
				if (argumentsCaseSensitive != null)
2912
					argument.caseSensitive = argumentsCaseSensitive.getSelection();
2913
			}
2914
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2915
				try {
2916
					if (selectedKey.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(FileInfoAttributesMatcher.KEY_CREATED))
2917
						argument.pattern = convertFromEditableTimeInterval(arguments.getText());
2918
					else
2919
						argument.pattern = convertFromEditableLength(arguments.getText());
2920
				} catch (NumberFormatException e) {
2921
					argument.pattern = arguments.getText();
2922
				}
2923
			}
2924
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null)
2925
				argument.pattern = MultiMatcherLocalization.getMultiMatcherKey(argumentsBoolean.getText());
2926
			String encodedArgument = FileInfoAttributesMatcher.encodeArguments(argument);
2927
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument);
2928
		}
2929
	}
2930
2931
	private String[] getLocalOperatorsForKey(String key) {
2932
		String [] operators = FileInfoAttributesMatcher.getOperatorsForKey(key);
2933
		String[] result = new String[operators.length];
2934
		for (int i = 0; i < operators.length; i++)
2935
			result[i] = MultiMatcherLocalization.getLocalMultiMatcherKey(operators[i]);
2936
		return result;
2937
	}
2938
2939
	private String[] getMultiMatcherKeys() {
2940
		ArrayList list = new ArrayList();
2941
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_NAME));
2942
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_PROPJECT_RELATIVE_PATH));
2943
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_LOCATION));
2944
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_LAST_MODIFIED));
2945
		if (FileInfoAttributesMatcher.supportCreatedKey())
2946
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_CREATED));
2947
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_LENGTH));
2948
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_IS_READONLY));
2949
		if (!Platform.getOS().equals(Platform.OS_WIN32))
2950
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(FileInfoAttributesMatcher.KEY_IS_SYMLINK));
2951
		return (String []) list.toArray(new String[0]);
2952
	}
2953
2954
	/* (non-Javadoc)
2955
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
2956
	 */
2957
	public void selectionChanged() {
2958
	}
2959
2960
	/**
2961
	 * @throws CoreException  
2962
	 */
2963
	/* (non-Javadoc)
2964
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
2965
	 */
2966
	public void validate() throws CoreException {
2967
		if (intiantiatedKeyOperatorType != null) {
2968
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2969
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2970
	
2971
			FileInfoAttributesMatcher.Argument argument = new FileInfoAttributesMatcher.Argument();
2972
			argument.key = selectedKey;
2973
			argument.operator = selectedOperator;
2974
			
2975
			if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) {
2976
			}
2977
			if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) {
2978
			}
2979
			if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) {
2980
				if (selectedKey.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(FileInfoAttributesMatcher.KEY_CREATED)) {
2981
					try {
2982
						convertFromEditableTimeInterval(arguments.getText());
2983
					} catch (NumberFormatException e) {
2984
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2985
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidTimeInterval, arguments.getText()), e));
2986
					}
2987
				}
2988
				else {
2989
					try {
2990
						convertFromEditableLength(arguments.getText());
2991
					} catch (NumberFormatException e) {
2992
						throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind(
2993
								IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidFileLength, arguments.getText()), e));
2994
					}
2995
				}
2996
			}
2997
			if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) {
2998
				
2999
			}
3000
		}
3001
	}
3002
3003
	/* (non-Javadoc)
3004
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#formatStyledText(org.eclipse.ui.internal.ide.dialogs.FilterCopy, org.eclipse.jface.viewers.StyledString.Styler, org.eclipse.jface.viewers.StyledString.Styler)
3005
	 */
3006
	public StyledString formatStyledText(FilterCopy filter,
3007
			Styler fPlainStyler, Styler fBoldStyler) {
3008
		return new StyledString(formatMultiMatcherArgument(filter), fPlainStyler);
3009
	}
3010
3011
	private String formatMultiMatcherArgument(FilterCopy filter) {
3012
		String argumentString = (String) filter.getArguments();
3013
		FileInfoAttributesMatcher.Argument argument = FileInfoAttributesMatcher.decodeArguments(argumentString);
3014
		
3015
		StringBuffer builder = new StringBuffer();
3016
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key));
3017
		builder.append(' ');
3018
		builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator));
3019
		builder.append(' ');
3020
		Class type = FileInfoAttributesMatcher.getTypeForKey(argument.key, argument.operator);
3021
		if (type.equals(String.class))
3022
			builder.append(argument.pattern);
3023
		if (type.equals(Boolean.class))
3024
			builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.pattern));
3025
		if (type.equals(Integer.class)) {
3026
			if (argument.key.equals(FileInfoAttributesMatcher.KEY_LAST_MODIFIED) || argument.key.equals(FileInfoAttributesMatcher.KEY_CREATED))
3027
				builder.append(convertToEditableTimeInterval(argument.pattern));
3028
			else
3029
				builder.append(convertToEditableLength(argument.pattern));
3030
		}
3031
		if (type.equals(Date.class))
3032
			builder.append(DateFormat.getDateInstance().format(new Date(Long.parseLong(argument.pattern))));
3033
		
3034
		return builder.toString();
3035
	}
3036
}
3037
3038
class DefaultCustomFilterArgumentUI implements ICustomFilterArgumentUI {
3039
3040
	Shell shell;
3041
	FilterCopy filter;
3042
	protected Text arguments;
3043
	protected Label argumentsLabel;
3044
	protected Label description;
3045
	protected ContentAssistCommandAdapter fContentAssistField;
3046
3047
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilterMatcher"; //$NON-NLS-1$
3048
3049
	/**
3050
	 * @param parentShell
3051
	 * @param filter
3052
	 */
3053
	public DefaultCustomFilterArgumentUI(Shell parentShell, FilterCopy filter) {
3054
		this.shell = parentShell;
3055
		this.filter = filter;
3056
	}
3057
3058
	/* (non-Javadoc)
3059
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
3060
	 */
3061
	public Object getID() {
3062
		return new String();
3063
	}
3064
3065
	/* (non-Javadoc)
3066
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
3067
	 */
3068
	public void dispose() {
3069
		Widget list[] = new Widget[] {arguments, argumentsLabel, description};
3070
		for (int i = 0; i < list.length; i++) {
3071
			if (list[i] != null) {
3072
				list[i].dispose();
3073
			}
3074
		}
3075
		arguments = null;
3076
		argumentsLabel = null;
3077
		fContentAssistField = null;
3078
		description = null;
3079
	}
3080
3081
	/* (non-Javadoc)
3082
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
3083
	 */
3084
	public void create(Composite argumentComposite, Font font) {
3085
		shell = argumentComposite.getShell();
3086
		GridLayout layout = new GridLayout();
3087
		layout.numColumns = 2;
3088
		layout.marginWidth = 0;
3089
		argumentComposite.setLayout(layout);
3090
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
3091
		argumentComposite.setLayoutData(data);
3092
		argumentComposite.setFont(font);
3093
		if (filter.hasStringArguments())
3094
			createArgumentsArea(font, argumentComposite);
3095
3096
		createDescriptionArea(font, argumentComposite);
3097
3098
		if (fContentAssistField != null)
3099
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3100
		argumentComposite.layout(true);
3101
	}
3102
	
3103
	private void createArgumentsArea(Font font, Composite composite) {
3104
		GridData data;
3105
		argumentsLabel = addLabel(composite, NLS.bind(
3106
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterPattern,
3107
				null));
3108
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
3109
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
3110
		arguments.setLayoutData(data);
3111
		arguments.setFont(font);
3112
		arguments.addModifyListener(new ModifyListener() {
3113
			public void modifyText(ModifyEvent e) {
3114
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
3115
						arguments.getText());
3116
			}
3117
		});
3118
		if (filter.hasStringArguments())
3119
			arguments.setText((String) FilterTypeUtil.getValue(filter,
3120
					FilterTypeUtil.ARGUMENTS));
3121
		arguments.setEnabled(filter.hasStringArguments());
3122
		setArgumentLabelEnabled();
3123
3124
		TextContentAdapter contentAdapter= new TextContentAdapter();
3125
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
3126
		fContentAssistField= new ContentAssistCommandAdapter(
3127
				arguments,
3128
				contentAdapter,
3129
				findProposer, 
3130
				null,
3131
				new char[] {'\\', '[', '('},
3132
				true);
3133
	}
3134
3135
	private void setArgumentLabelEnabled() {
3136
		if (argumentsLabel != null) {
3137
			Color color = argumentsLabel.getDisplay().getSystemColor(
3138
					filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
3139
			argumentsLabel.setForeground(color);
3140
		}
3141
	}
3142
3143
	Label addLabel(Composite composite, String text) {
3144
		String delimiter = ":"; //$NON-NLS-1$
3145
3146
		Font font = composite.getFont();
3147
		Label label = new Label(composite, SWT.LEFT);
3148
		label.setText(text + delimiter);
3149
		GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false);
3150
		label.setLayoutData(data);
3151
		label.setFont(font);
3152
		return label;
3153
	}
3154
3155
	/* (non-Javadoc)
3156
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged()
3157
	 */
3158
	public void selectionChanged() {
3159
		if (arguments != null)
3160
			arguments.setEnabled(filter.hasStringArguments());
3161
		setArgumentLabelEnabled();
3162
		if (fContentAssistField != null)
3163
			fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
3164
		description.setText(FilterTypeUtil
3165
				.getDescriptor(filter.getId()).getDescription());
3166
	}
3167
3168
	/**
3169
	 * @param font
3170
	 * @param composite
3171
	 */
3172
	private void createDescriptionArea(Font font, Composite composite) {
3173
		GridData data;
3174
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
3175
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
3176
				.getDescription());
3177
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
3178
		data.widthHint = 300;
3179
		data.heightHint = 40;
3180
		data.horizontalSpan = 2;
3181
		description.setLayoutData(data);
3182
		description.setFont(font);
3183
	}
3184
3185
	/**
3186
	 * @throws CoreException  
3187
	 */
3188
	/* (non-Javadoc)
3189
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData()
3190
	 */
3191
	public void validate() throws CoreException {
3192
		// nothing
3193
	}
3194
3195
	/* (non-Javadoc)
3196
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#formatStyledText(org.eclipse.ui.internal.ide.dialogs.FilterCopy, org.eclipse.jface.viewers.StyledString.Styler, org.eclipse.jface.viewers.StyledString.Styler)
3197
	 */
3198
	public StyledString formatStyledText(FilterCopy filter,
3199
			Styler fPlainStyler, Styler fBoldStyler) {
3200
		return new StyledString(filter.getArguments() != null ? filter
3201
					.getArguments().toString() : new String(), fPlainStyler);
3202
	}
3203
}
3204
3205
class MultiMatcherLocalization {
3206
	
3207
	static String[][] multiMatcherKey = {
3208
			{FileInfoAttributesMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName},
3209
			{FileInfoAttributesMatcher.KEY_PROPJECT_RELATIVE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyProjectRelativePath},
3210
			{FileInfoAttributesMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation},
3211
			{FileInfoAttributesMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified},
3212
			{FileInfoAttributesMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated},
3213
			{FileInfoAttributesMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength},
3214
			{FileInfoAttributesMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly},
3215
			{FileInfoAttributesMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink},
3216
			{FileInfoAttributesMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter},
3217
			{FileInfoAttributesMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore},
3218
			{FileInfoAttributesMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals},
3219
			{FileInfoAttributesMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches},
3220
			{FileInfoAttributesMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan},
3221
			{FileInfoAttributesMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan},
3222
			{FileInfoAttributesMatcher.OPERATOR_WITHIN, IDEWorkbenchMessages.ResourceFilterPage_multiWithin},
3223
			{Boolean.TRUE.toString(), IDEWorkbenchMessages.ResourceFilterPage_true},
3224
			{Boolean.FALSE.toString(), IDEWorkbenchMessages.ResourceFilterPage_false}
3225
	};
3226
	
3227
	static public String getLocalMultiMatcherKey(String key) {
3228
		for (int i = 0; i < multiMatcherKey.length; i++) {
3229
			if (multiMatcherKey[i][0].equals(key))
3230
				return multiMatcherKey[i][1];
3231
		}
3232
		return null;
3233
	}
3234
	
3235
	static public String getMultiMatcherKey(String local) {
3236
		for (int i = 0; i < multiMatcherKey.length; i++) {
3237
			if (multiMatcherKey[i][1].equals(local))
3238
				return multiMatcherKey[i][0];
3239
		}
3240
		return null;
3241
	}
3242
	
2102
}
3243
}
(-)src/org/eclipse/ui/internal/ide/misc/FileInfoAttributesMatcher.java (+420 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.Array;
15
import java.lang.reflect.InvocationTargetException;
16
import java.lang.reflect.Method;
17
import java.util.Calendar;
18
import java.util.Date;
19
import java.util.GregorianCalendar;
20
import java.util.regex.Matcher;
21
import java.util.regex.Pattern;
22
import java.util.regex.PatternSyntaxException;
23
24
import org.eclipse.core.filesystem.EFS;
25
import org.eclipse.core.filesystem.IFileInfo;
26
import org.eclipse.core.filesystem.IFileStore;
27
import org.eclipse.core.resources.IContainer;
28
import org.eclipse.core.resources.IProject;
29
import org.eclipse.core.resources.filtermatchers.AbstractFileInfoMatcher;
30
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.core.runtime.Platform;
33
import org.eclipse.core.runtime.Status;
34
import org.eclipse.ui.PlatformUI;
35
import org.eclipse.ui.internal.ide.StringMatcher;
36
37
/**
38
 * A file info filter that matches different file and folder attributes.
39
 */
40
public class FileInfoAttributesMatcher extends AbstractFileInfoMatcher {
41
42
	public static String ID = "org.eclipse.ui.ide.multiFilter"; //$NON-NLS-1$
43
44
	public static String KEY_NAME 					= "name"; //$NON-NLS-1$
45
	public static String KEY_PROPJECT_RELATIVE_PATH = "projectRelativePath"; //$NON-NLS-1$
46
	public static String KEY_LOCATION 				= "location"; //$NON-NLS-1$
47
	public static String KEY_LAST_MODIFIED 			= "lastModified"; //$NON-NLS-1$
48
	public static String KEY_LENGTH 				= "length"; //$NON-NLS-1$
49
	public static String KEY_CREATED 				= "created"; //$NON-NLS-1$
50
	public static String KEY_IS_SYMLINK				= "isSymLink"; //$NON-NLS-1$
51
	public static String KEY_IS_READONLY			= "isReadOnly"; //$NON-NLS-1$
52
53
	public static String OPERATOR_NONE			= "none"; //$NON-NLS-1$
54
	public static String OPERATOR_LARGER_THAN	= "largerThan"; //$NON-NLS-1$
55
	public static String OPERATOR_SMALLER_THAN	= "smallerThan"; //$NON-NLS-1$
56
	public static String OPERATOR_EQUALS		= "equals"; //$NON-NLS-1$
57
	public static String OPERATOR_BEFORE		= "before"; //$NON-NLS-1$
58
	public static String OPERATOR_AFTER			= "after"; //$NON-NLS-1$
59
	public static String OPERATOR_WITHIN		= "within"; //$NON-NLS-1$
60
	public static String OPERATOR_MATCHES		= "matches"; //$NON-NLS-1$
61
	
62
63
	/**
64
	 * @param key
65
	 * @return
66
	 */
67
	public static String[] getOperatorsForKey(String key) {
68
		if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION))
69
				return new String[] {OPERATOR_MATCHES};
70
		if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY))
71
			return new String[] {OPERATOR_EQUALS};
72
		if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED))
73
			return new String[] {OPERATOR_EQUALS, OPERATOR_BEFORE, OPERATOR_AFTER, OPERATOR_WITHIN};
74
		if (key.equals(KEY_LENGTH))
75
			return new String[] {OPERATOR_EQUALS, OPERATOR_LARGER_THAN, OPERATOR_SMALLER_THAN};
76
		
77
		return new String[] {OPERATOR_NONE};
78
	}
79
	
80
	/**
81
	 * @param key
82
	 * @param operator
83
	 * @return
84
	 */
85
	public static  Class getTypeForKey(String key, String operator) {
86
		if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION))
87
			return String.class;
88
		if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY))
89
			return Boolean.class;
90
		if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED)) {
91
			if (operator.equals(OPERATOR_WITHIN))
92
				return Integer.class;
93
			return Date.class;
94
		}
95
		if (key.equals(KEY_LENGTH))
96
			return Integer.class;
97
		return String.class;
98
	}
99
	
100
	/**
101
	 * @return
102
	 */
103
	public static boolean supportCreatedKey() {
104
		if (Platform.getOS().equals(Platform.OS_WIN32) || Platform.getOS().equals(Platform.OS_MACOSX)) {
105
			String system = System.getProperty("java.version"); //$NON-NLS-1$
106
			double versionNumber = 0.0;
107
			int index = system.indexOf('.');
108
			if (index != -1) {
109
				versionNumber = Integer.decode(system.substring(0, index)).doubleValue();
110
				system = system.substring(index + 1);
111
				index = system.indexOf('.');
112
				if (index != -1) {
113
					versionNumber += Double.parseDouble(system.substring(0, index)) / 10.0;
114
				}
115
			}
116
			return versionNumber >= 1.7;
117
		}
118
		return false;
119
	}
120
	
121
	/**
122
	 * @since 3.6
123
	 *
124
	 */
125
	public static class Argument {
126
		public String key = KEY_NAME;
127
		public String pattern = new String();
128
		public String operator = OPERATOR_EQUALS;
129
		public boolean caseSensitive = false; 
130
		public boolean regularExpression = false;
131
	}
132
	
133
	/**
134
	 * @param argument
135
	 * @return
136
	 */
137
	public static String encodeArguments(Argument argument)  {
138
		return VERSION_IMPLEMENTATION + DELIMITER + 
139
				argument.key + DELIMITER + 
140
				argument.operator + DELIMITER + 
141
				Boolean.toString(argument.caseSensitive) + DELIMITER + 
142
				Boolean.toString(argument.regularExpression) + DELIMITER + 
143
				argument.pattern;
144
				
145
	}
146
147
	/**
148
	 * @param argument
149
	 * @return
150
	 */
151
	public static Argument decodeArguments(String argument)  {
152
		Argument result = new Argument();
153
		if (argument == null)
154
			return result;
155
		
156
		int index = argument.indexOf(DELIMITER);
157
		if (index == -1)
158
			return result;
159
		
160
		String version = argument.substring(0, index);
161
		argument = argument.substring(index + 1);
162
		
163
		if (!version.equals(VERSION_IMPLEMENTATION))
164
			return result;
165
		
166
		index = argument.indexOf(DELIMITER);
167
		if (index == -1)
168
			return result;
169
170
		result.key = argument.substring(0, index);
171
		argument = argument.substring(index + 1);
172
173
		index = argument.indexOf(DELIMITER);
174
		if (index == -1)
175
			return result;
176
177
		result.operator = argument.substring(0, index);
178
		argument = argument.substring(index + 1);
179
180
		index = argument.indexOf(DELIMITER);
181
		if (index == -1)
182
			return result;
183
184
		result.caseSensitive = Boolean.valueOf(argument.substring(0, index)).booleanValue();
185
		argument = argument.substring(index + 1);
186
		
187
		index = argument.indexOf(DELIMITER);
188
		if (index == -1)
189
			return result;
190
191
		result.regularExpression = Boolean.valueOf(argument.substring(0, index)).booleanValue();
192
		result.pattern = argument.substring(index + 1);
193
194
		return result;
195
	}
196
197
198
	static private String DELIMITER = "-"; //$NON-NLS-1$
199
	static private String VERSION_IMPLEMENTATION = "1.0"; //$NON-NLS-1$
200
201
	/*
202
	 * return value in milliseconds since epoch(1970-01-01T00:00:00Z)
203
	 */
204
	private static long getFileCreationTime(String fullPath) {
205
		/*
206
		java.nio.file.FileSystem fs = java.nio.file.FileSystems.getDefault();
207
		java.nio.file.FileRef fileRef = fs.getPath(file);
208
		java.nio.file.attribute.BasicFileAttributes attributes = java.nio.file.attribute.Attributes.readBasicFileAttributes(fileRef, new java.nio.file.LinkOption[0]);
209
		return attributes.creationTime();
210
        */
211
212
		try {
213
			Class fileSystems = Class.forName("java.nio.file.FileSystems"); //$NON-NLS-1$
214
			Method getDefault = fileSystems.getMethod("getDefault", null); //$NON-NLS-1$
215
			Object fs = getDefault.invoke(null, null);
216
	
217
			Class fileRef = Class.forName("java.nio.file.FileRef"); //$NON-NLS-1$
218
219
			Class fileSystem = Class.forName("java.nio.file.FileSystem"); //$NON-NLS-1$
220
			Method getPath = fileSystem.getMethod("getPath", new Class[] {String.class}); //$NON-NLS-1$
221
			Object fileRefObj = getPath.invoke(fs, new Object[] {fullPath});
222
			
223
			Class attributes = Class.forName("java.nio.file.attribute.Attributes"); //$NON-NLS-1$
224
			Class linkOptions = Class.forName("java.nio.file.LinkOption"); //$NON-NLS-1$
225
			Object linkOptionsEmptyArray = Array.newInstance(linkOptions, 0);
226
			Method readBasicFileAttributes = attributes.getMethod("readBasicFileAttributes", new Class[] {fileRef, linkOptionsEmptyArray.getClass()}); //$NON-NLS-1$
227
			Object attributesObj = readBasicFileAttributes.invoke(null, new Object[] {fileRefObj, linkOptionsEmptyArray});
228
	
229
			Class basicAttributes = Class.forName("java.nio.file.attribute.BasicFileAttributes"); //$NON-NLS-1$
230
			Method creationTime = basicAttributes.getMethod("creationTime", null); //$NON-NLS-1$
231
			Object time = creationTime.invoke(attributesObj, null);
232
	
233
			Class fileTime = Class.forName("java.nio.file.attribute.FileTime"); //$NON-NLS-1$
234
			Method toMillis = fileTime.getMethod("toMillis", null); //$NON-NLS-1$
235
			Object result = toMillis.invoke(time, null);
236
			
237
			if (result instanceof Long)
238
				return ((Long) result).longValue();
239
		} catch (ClassNotFoundException e) {
240
			e.printStackTrace();
241
		} catch (IllegalArgumentException e) {
242
			e.printStackTrace();
243
		} catch (IllegalAccessException e) {
244
			e.printStackTrace();
245
		} catch (InvocationTargetException e) {
246
			e.printStackTrace();
247
		} catch (SecurityException e) {
248
			e.printStackTrace();
249
		} catch (NoSuchMethodException e) {
250
			e.printStackTrace();
251
		} 
252
		return 0;
253
	}
254
	
255
	MatcherCache matcher = null;
256
	private boolean fSupportsCreatedKey;
257
258
	class MatcherCache {
259
		public MatcherCache(String arguments) {
260
			argument = decodeArguments(arguments);
261
			type = getTypeForKey(argument.key, argument.operator);
262
			if (type.equals(String.class)) {
263
				if (argument.regularExpression == false)
264
					stringMatcher = new StringMatcher(argument.pattern, argument.caseSensitive == false, false);
265
				else
266
					regExPattern = Pattern.compile(argument.pattern, argument.caseSensitive ? 0:Pattern.CASE_INSENSITIVE);
267
			}
268
		}
269
		
270
271
		Argument argument;
272
		Class type;
273
		StringMatcher stringMatcher = null;
274
		Pattern regExPattern = null;
275
276
		public boolean match(IContainer parent, IFileInfo fileInfo) {
277
			if (type.equals(String.class)) {
278
				String value = new String();
279
				if (argument.key.equals(KEY_NAME))
280
					value = fileInfo.getName();
281
				if (argument.key.equals(KEY_PROPJECT_RELATIVE_PATH))
282
					value = parent.getProjectRelativePath().append(fileInfo.getName()).toPortableString();
283
				if (argument.key.equals(KEY_LOCATION))
284
					value = parent.getLocation().append(fileInfo.getName()).toOSString();
285
				
286
				if (stringMatcher != null)
287
					return stringMatcher.match(value);
288
				if (regExPattern != null) {
289
					Matcher m = regExPattern.matcher(value);
290
					return m.matches();
291
				}
292
			}
293
			if (type.equals(Integer.class)) {
294
				int amount;
295
				try {
296
					amount = Integer.parseInt(argument.pattern);
297
				} catch (NumberFormatException e) {
298
					amount = 0;
299
				}
300
				if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) {
301
					// OPERATOR_WITHIN
302
					long time = 0;
303
					if (argument.key.equals(KEY_LAST_MODIFIED)) {
304
						IFileInfo info = fetchInfo(parent, fileInfo);
305
						if (!info.exists())
306
							return false;
307
						time = info.getLastModified();
308
					}
309
					if (argument.key.equals(KEY_CREATED)) {
310
						if (!fSupportsCreatedKey)
311
							return false;
312
						time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString());
313
					}
314
					GregorianCalendar gc = new GregorianCalendar();
315
					gc.add(Calendar.SECOND,-amount);
316
					Date when = gc.getTime();
317
					Date then = new Date(time);
318
					return then.after(when);
319
				}
320
				if (argument.key.equals(KEY_LENGTH)) {
321
					IFileInfo info = fetchInfo(parent, fileInfo);
322
					if (!info.exists())
323
						return false;
324
					if (argument.operator.equals(OPERATOR_EQUALS))
325
						return info.getLength() == amount;
326
					if (argument.operator.equals(OPERATOR_LARGER_THAN))
327
						return info.getLength() > amount;
328
					if (argument.operator.equals(OPERATOR_SMALLER_THAN))
329
						return info.getLength() < amount;
330
				}
331
			}
332
			if (type.equals(Date.class)) {
333
				long parameter = Long.parseLong(argument.pattern);
334
				if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) {
335
					long time = 0;
336
					if (argument.key.equals(KEY_LAST_MODIFIED)) {
337
						IFileInfo info = fetchInfo(parent, fileInfo);
338
						if (!info.exists())
339
							return false;
340
						time = info.getLastModified();
341
					}
342
					if (argument.key.equals(KEY_CREATED)) {
343
						if (!fSupportsCreatedKey)
344
							return false;
345
						time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString());
346
					}
347
					Date when = new Date(parameter);
348
					Date then = new Date(time);
349
					if (argument.operator.equals(OPERATOR_EQUALS))
350
						return roundToOneDay(time) == roundToOneDay(parameter); 
351
					if (argument.operator.equals(OPERATOR_BEFORE))
352
						return then.before(when);
353
					if (argument.operator.equals(OPERATOR_AFTER))
354
						return then.after(when);
355
				}
356
			}
357
			if (type.equals(Boolean.class)) {
358
				boolean parameter = Boolean.valueOf(argument.pattern).booleanValue();
359
				if (argument.key.equals(KEY_IS_READONLY)) {
360
					IFileInfo info = fetchInfo(parent, fileInfo);
361
					if (!info.exists())
362
						return false;
363
					return info.getAttribute(EFS.ATTRIBUTE_READ_ONLY) == parameter;
364
				}
365
				if (argument.key.equals(KEY_IS_SYMLINK)) {
366
					IFileInfo info = fetchInfo(parent, fileInfo);
367
					if (!info.exists())
368
						return false;
369
					return info.getAttribute(EFS.ATTRIBUTE_SYMLINK) == parameter;
370
				}
371
			}
372
			return false;
373
		}
374
375
		private long roundToOneDay(long parameter) {
376
			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 
377
		}
378
379
		private IFileInfo fetchInfo(IContainer parent, IFileInfo fileInfo) {
380
			IFileStore fileStore;
381
			try {
382
				fileStore = EFS.getStore(parent.getLocationURI());
383
			} catch (CoreException e) {
384
				return fileInfo;
385
			}
386
			IFileStore store = fileStore.getChild(fileInfo.getName());
387
			return store.fetchInfo();
388
		}
389
	}
390
	/**
391
	 * Creates a new factory for this filter type.
392
	 */
393
	public FileInfoAttributesMatcher() {
394
		fSupportsCreatedKey = supportCreatedKey();
395
	}
396
397
	/* (non-Javadoc)
398
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#initialize(org.eclipse.core.resources.IProject, java.lang.Object)
399
	 */
400
	public void initialize(IProject project, Object arguments) throws CoreException {
401
		try {
402
			if ((arguments instanceof String) && ((String) arguments).length() > 0)
403
				matcher = new MatcherCache((String) arguments);
404
		} catch (PatternSyntaxException e) {
405
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
406
		} catch (NumberFormatException e) {
407
			throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e));
408
		}
409
	}
410
411
	/* (non-Javadoc)
412
	 * @see org.eclipse.core.resources.AbstractFileInfoMatcher#matches(org.eclipse.core.filesystem.IFileInfo)
413
	 */
414
	public boolean matches(IContainer parent, IFileInfo fileInfo) throws CoreException {
415
		if (matcher != null) {
416
			return matcher.match(parent, fileInfo);
417
		}
418
		return false;
419
	}
420
}

Return to bug 301820