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

Collapse All | Expand All

(-)plugin.properties (-3 / +5 lines)
Lines 296-305 Link Here
296
296
297
filterProvider.description = * = any string, ? = any character, \\ = escape literals: * ? \\
297
filterProvider.description = * = any string, ? = any character, \\ = escape literals: * ? \\
298
filterProvider.name = String Matcher
298
filterProvider.name = String Matcher
299
orFilterProvider.name = OR group
299
orFilterProvider.name =OR
300
orFilterProvider.description = Allows grouping others filters with the OR logical preposition
300
orFilterProvider.description = Allows grouping others filters with the OR logical preposition
301
andFilterProvider.name = AND group
301
andFilterProvider.name =AND
302
andFilterProvider.description = Allows grouping others filters with the AND logical preposition
302
andFilterProvider.description = Allows grouping others filters with the AND logical preposition
303
notFilterProvider.name = NOT group
303
notFilterProvider.name =NOT
304
notFilterProvider.description = Allows grouping others filters with the NOT logical preposition
304
notFilterProvider.description = Allows grouping others filters with the NOT logical preposition
305
installationPage.feature.name = Features
305
installationPage.feature.name = Features
306
multiFilterProvider.name = Default
307
multiFilterProvider.description = Match many attributes of files and folders
(-)plugin.xml (+8 lines)
Lines 2328-2333 Link Here
2328
            name="%notFilterProvider.name"
2328
            name="%notFilterProvider.name"
2329
            ordering="first">
2329
            ordering="first">
2330
      </filterMatcher>
2330
      </filterMatcher>
2331
      <filterMatcher
2332
            argumentType="string"
2333
            class="org.eclipse.ui.internal.ide.misc.MultiMatcher"
2334
            description="%multiFilterProvider.description"
2335
            id="org.eclipse.ui.ide.multiFilter"
2336
            name="%multiFilterProvider.name"
2337
            ordering="first">
2338
      </filterMatcher>
2331
   </extension>
2339
   </extension>
2332
   <extension
2340
   <extension
2333
         point="org.eclipse.ui.installationPages">
2341
         point="org.eclipse.ui.installationPages">
(-)src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java (-1 / +36 lines)
Lines 53-58 Link Here
53
	public static String ResourceFilterPage_title;
53
	public static String ResourceFilterPage_title;
54
	public static String ResourceFilterPage_noResource;
54
	public static String ResourceFilterPage_noResource;
55
	public static String ResourceFilterPage_addButtonLabel;
55
	public static String ResourceFilterPage_addButtonLabel;
56
	public static String ResourceFilterPage_addGroupButtonLabel;
56
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_editButtonLabel;
57
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_removeButtonLabel;
58
	public static String ResourceFilterPage_upButtonLabel;
59
	public static String ResourceFilterPage_upButtonLabel;
Lines 60-68 Link Here
60
	public static String ResourceFilterPage_addNewFilterTitle;
61
	public static String ResourceFilterPage_addNewFilterTitle;
61
	public static String ResourceFilterPage_columnFilterID;
62
	public static String ResourceFilterPage_columnFilterID;
62
	public static String ResourceFilterPage_columnFilterMode;
63
	public static String ResourceFilterPage_columnFilterMode;
64
	public static String ResourceFilterPage_columnFilterDescription;
63
	public static String ResourceFilterPage_columnFilterTargets;
65
	public static String ResourceFilterPage_columnFilterTargets;
64
	public static String ResourceFilterPage_columnFilterInheritable;
66
	public static String ResourceFilterPage_columnFilterInheritable;
65
	public static String ResourceFilterPage_columnFilterArguments;
67
	public static String ResourceFilterPage_columnFilterTarget;
68
	public static String ResourceFilterPage_applyRecursivelyToFolderStructure;
69
	public static String ResourceFilterPage_customize;
70
	public static String ResourceFilterPage_customizeTitle;
71
	public static String ResourceFilterPage_customizeMessage;
72
	public static String ResourceFilterPage_caseSensitive;
73
	public static String ResourceFilterPage_regularExpression;
74
	public static String ResourceFilterPage_multiMatcher_Matcher;
75
	public static String ResourceFilterPage_multiMatcher_FileLength;
76
	public static String ResourceFilterPage_multiMatcher_TimeInterval;
77
	public static String ResourceFilterPage_multiMatcher_InvalidFileLength;
78
	public static String ResourceFilterPage_multiMatcher_InvalidTimeInterval;
66
	public static String ResourceFilterPage_includeOnly;
79
	public static String ResourceFilterPage_includeOnly;
67
	public static String ResourceFilterPage_excludeAll;
80
	public static String ResourceFilterPage_excludeAll;
68
	public static String ResourceFilterPage_includeOnlyColumn;
81
	public static String ResourceFilterPage_includeOnlyColumn;
Lines 77-82 Link Here
77
	public static String ResourceFilterPage_invalidFilterArgument;
90
	public static String ResourceFilterPage_invalidFilterArgument;
78
	public static String ResourceFilterPage_description;
91
	public static String ResourceFilterPage_description;
79
	public static String ResourceFilterPage_addSubFilterActionLabel;
92
	public static String ResourceFilterPage_addSubFilterActionLabel;
93
	public static String ResourceFilterPage_addSubFilterGroupActionLabel;
94
	public static String ResourceFilterPage_removeFilterActionLabel;
95
	public static String ResourceFilterPage_editFilterActionLabel;
96
	public static String ResourceFilterPage_multiKeyName;
97
	public static String ResourceFilterPage_multiKeyProjectRelativePath;
98
	public static String ResourceFilterPage_multiKeyLocation;
99
	public static String ResourceFilterPage_multiKeyLastModified;
100
	public static String ResourceFilterPage_multiKeyCreated;
101
	public static String ResourceFilterPage_multiKeyLength;
102
	public static String ResourceFilterPage_multiKeyReadOnly;
103
	public static String ResourceFilterPage_multiKeySymLink;
104
	public static String ResourceFilterPage_multiEquals;
105
	public static String ResourceFilterPage_multiMatches;
106
	public static String ResourceFilterPage_multiLargerThan;
107
	public static String ResourceFilterPage_multiSmallerThan;
108
	public static String ResourceFilterPage_multiBefore;
109
	public static String ResourceFilterPage_multiAfter;
110
	public static String ResourceFilterPage_multiWithin;
111
	public static String ResourceFilterPage_true;
112
	public static String ResourceFilterPage_false;
113
	public static String ResourceFilterPage_columnFilterTypeLabel;
114
	
80
	//
115
	//
81
	//
116
	//
82
	// Copies from org.eclipse.ui.workbench
117
	// Copies from org.eclipse.ui.workbench
(-)src/org/eclipse/ui/internal/ide/messages.properties (-6 / +40 lines)
Lines 573-592 Link Here
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
573
ResourceFilterPage_title=Resource filters can be used to hide file system objects from the Eclipse resource tree.\nA file system object will be included if it matches any of the include filters and doesn't match any of the exclude filters. 
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
574
ResourceFilterPage_noResource=Resource information is not available for the current selection.
575
ResourceFilterPage_addButtonLabel=&Add...
575
ResourceFilterPage_addButtonLabel=&Add...
576
ResourceFilterPage_addGroupButtonLabel=Add &Group...
576
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_editButtonLabel=Edi&t...
577
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_removeButtonLabel=&Remove
578
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_upButtonLabel=Up
579
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_downButtonLabel=Down
580
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_addNewFilterTitle=Add new resource filter
581
ResourceFilterPage_columnFilterID=T&ype
582
ResourceFilterPage_columnFilterID=T&ype
583
ResourceFilterPage_columnFilterTypeLabel=Match
582
ResourceFilterPage_columnFilterMode=Mode
584
ResourceFilterPage_columnFilterMode=Mode
583
ResourceFilterPage_columnFilterTargets=Target
585
ResourceFilterPage_columnFilterDescription=Description
584
ResourceFilterPage_columnFilterInheritable=In&heritable
586
ResourceFilterPage_columnFilterTargets=Object
585
ResourceFilterPage_columnFilterArguments=&Pattern
587
ResourceFilterPage_columnFilterInheritable=Recursive
588
ResourceFilterPage_columnFilterTarget=&Pattern
589
ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure
590
ResourceFilterPage_customize=Advanced...
591
ResourceFilterPage_customizeTitle=Filter Matcher Selection
592
ResourceFilterPage_customizeMessage=Select resource filter matcher:
593
ResourceFilterPage_caseSensitive=&Case sensitive
594
ResourceFilterPage_regularExpression=Re&gular expression
595
ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \)
596
ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes, *g = gigabytes)
597
ResourceFilterPage_multiMatcher_TimeInterval= (*s = seconds, *m = minutes, *h = hours, *d = days)
598
ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0}
599
ResourceFilterPage_multiMatcher_InvalidTimeInterval=Invalid time interval syntax: {0}
586
ResourceFilterPage_includeOnly=&Include
600
ResourceFilterPage_includeOnly=&Include
587
ResourceFilterPage_excludeAll=&Exclude
601
ResourceFilterPage_excludeAll=&Exclude
588
ResourceFilterPage_includeOnlyColumn=Include
602
ResourceFilterPage_includeOnlyColumn=Include only:
589
ResourceFilterPage_excludeAllColumn=Exclude
603
ResourceFilterPage_excludeAllColumn=Exclude all:
590
ResourceFilterPage_filesAndFolders=Files &and folders
604
ResourceFilterPage_filesAndFolders=Files &and folders
591
ResourceFilterPage_files=&Files
605
ResourceFilterPage_files=&Files
592
ResourceFilterPage_folders=F&olders
606
ResourceFilterPage_folders=F&olders
Lines 596-602 Link Here
596
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
610
ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter
597
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
611
ResourceFilterPage_invalidFilterArgument=Invalid Pattern
598
ResourceFilterPage_description=Description
612
ResourceFilterPage_description=Description
599
ResourceFilterPage_addSubFilterActionLabel=Add Condition...
613
ResourceFilterPage_addSubFilterActionLabel=&Add...
614
ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group...
615
ResourceFilterPage_removeFilterActionLabel=&Remove
616
ResourceFilterPage_editFilterActionLabel=&Edit
617
ResourceFilterPage_multiKeyName=Name
618
ResourceFilterPage_multiKeyProjectRelativePath=Project Relative Path
619
ResourceFilterPage_multiKeyLocation=Location
620
ResourceFilterPage_multiKeyLastModified=Last Modified
621
ResourceFilterPage_multiKeyCreated=Date Created
622
ResourceFilterPage_multiKeyLength=File Length
623
ResourceFilterPage_multiKeyReadOnly=Read Only
624
ResourceFilterPage_multiKeySymLink=Symbolic Link
625
ResourceFilterPage_multiEquals=equals
626
ResourceFilterPage_multiMatches=matches
627
ResourceFilterPage_multiLargerThan=is larger than
628
ResourceFilterPage_multiSmallerThan=is smaller than
629
ResourceFilterPage_multiBefore=is before
630
ResourceFilterPage_multiAfter=is after
631
ResourceFilterPage_multiWithin=is within
632
ResourceFilterPage_true=true
633
ResourceFilterPage_false=false
600
ResourceInfo_folder = Folder
634
ResourceInfo_folder = Folder
601
ResourceInfo_project = Project
635
ResourceInfo_project = Project
602
ResourceInfo_linkedFile = Linked File
636
ResourceInfo_linkedFile = Linked File
(-)src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java (-477 / +1618 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.List;
29
import java.util.TreeMap;
22
30
23
import org.eclipse.core.internal.resources.FilterDescriptor;
31
import org.eclipse.core.internal.resources.FilterDescriptor;
24
import org.eclipse.core.resources.FileInfoMatcherDescription;
32
import org.eclipse.core.resources.FileInfoMatcherDescription;
Lines 32-62 Link Here
32
import org.eclipse.core.runtime.Assert;
40
import org.eclipse.core.runtime.Assert;
33
import org.eclipse.core.runtime.CoreException;
41
import org.eclipse.core.runtime.CoreException;
34
import org.eclipse.core.runtime.IPath;
42
import org.eclipse.core.runtime.IPath;
43
import org.eclipse.core.runtime.IStatus;
35
import org.eclipse.core.runtime.NullProgressMonitor;
44
import org.eclipse.core.runtime.NullProgressMonitor;
45
import org.eclipse.core.runtime.Platform;
46
import org.eclipse.core.runtime.Status;
36
import org.eclipse.jface.action.Action;
47
import org.eclipse.jface.action.Action;
37
import org.eclipse.jface.action.MenuManager;
48
import org.eclipse.jface.action.MenuManager;
49
import org.eclipse.jface.action.Separator;
38
import org.eclipse.jface.dialogs.Dialog;
50
import org.eclipse.jface.dialogs.Dialog;
39
import org.eclipse.jface.dialogs.ErrorDialog;
51
import org.eclipse.jface.dialogs.ErrorDialog;
40
import org.eclipse.jface.dialogs.IDialogConstants;
52
import org.eclipse.jface.dialogs.IDialogConstants;
41
import org.eclipse.jface.dialogs.TrayDialog;
53
import org.eclipse.jface.dialogs.TrayDialog;
42
import org.eclipse.jface.fieldassist.TextContentAdapter;
54
import org.eclipse.jface.fieldassist.TextContentAdapter;
55
import org.eclipse.jface.layout.TreeColumnLayout;
56
import org.eclipse.jface.resource.CompositeImageDescriptor;
43
import org.eclipse.jface.resource.ImageDescriptor;
57
import org.eclipse.jface.resource.ImageDescriptor;
44
import org.eclipse.jface.resource.JFaceResources;
58
import org.eclipse.jface.resource.JFaceResources;
45
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
59
import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider;
46
import org.eclipse.jface.viewers.CellEditor;
60
import org.eclipse.jface.viewers.CellEditor;
47
import org.eclipse.jface.viewers.CheckboxCellEditor;
61
import org.eclipse.jface.viewers.CheckboxCellEditor;
62
import org.eclipse.jface.viewers.ColumnWeightData;
48
import org.eclipse.jface.viewers.ComboBoxCellEditor;
63
import org.eclipse.jface.viewers.ComboBoxCellEditor;
49
import org.eclipse.jface.viewers.ICellModifier;
64
import org.eclipse.jface.viewers.ICellModifier;
50
import org.eclipse.jface.viewers.ILabelProviderListener;
51
import org.eclipse.jface.viewers.ISelection;
65
import org.eclipse.jface.viewers.ISelection;
52
import org.eclipse.jface.viewers.ISelectionChangedListener;
66
import org.eclipse.jface.viewers.ISelectionChangedListener;
67
import org.eclipse.jface.viewers.IStructuredContentProvider;
53
import org.eclipse.jface.viewers.IStructuredSelection;
68
import org.eclipse.jface.viewers.IStructuredSelection;
54
import org.eclipse.jface.viewers.ITableLabelProvider;
55
import org.eclipse.jface.viewers.ITreeContentProvider;
69
import org.eclipse.jface.viewers.ITreeContentProvider;
56
import org.eclipse.jface.viewers.SelectionChangedEvent;
70
import org.eclipse.jface.viewers.SelectionChangedEvent;
71
import org.eclipse.jface.viewers.StyledCellLabelProvider;
72
import org.eclipse.jface.viewers.StyledString;
73
import org.eclipse.jface.viewers.StyledString.Styler;
57
import org.eclipse.jface.viewers.TextCellEditor;
74
import org.eclipse.jface.viewers.TextCellEditor;
58
import org.eclipse.jface.viewers.TreeViewer;
75
import org.eclipse.jface.viewers.TreeViewer;
59
import org.eclipse.jface.viewers.Viewer;
76
import org.eclipse.jface.viewers.Viewer;
77
import org.eclipse.jface.viewers.ViewerCell;
60
import org.eclipse.jface.viewers.ViewerDropAdapter;
78
import org.eclipse.jface.viewers.ViewerDropAdapter;
61
import org.eclipse.jface.window.Window;
79
import org.eclipse.jface.window.Window;
62
import org.eclipse.osgi.util.NLS;
80
import org.eclipse.osgi.util.NLS;
Lines 73-104 Link Here
73
import org.eclipse.swt.events.ModifyListener;
91
import org.eclipse.swt.events.ModifyListener;
74
import org.eclipse.swt.events.MouseEvent;
92
import org.eclipse.swt.events.MouseEvent;
75
import org.eclipse.swt.events.MouseListener;
93
import org.eclipse.swt.events.MouseListener;
94
import org.eclipse.swt.events.SelectionAdapter;
76
import org.eclipse.swt.events.SelectionEvent;
95
import org.eclipse.swt.events.SelectionEvent;
77
import org.eclipse.swt.events.SelectionListener;
78
import org.eclipse.swt.graphics.Color;
96
import org.eclipse.swt.graphics.Color;
79
import org.eclipse.swt.graphics.Font;
97
import org.eclipse.swt.graphics.Font;
98
import org.eclipse.swt.graphics.FontData;
80
import org.eclipse.swt.graphics.FontMetrics;
99
import org.eclipse.swt.graphics.FontMetrics;
81
import org.eclipse.swt.graphics.GC;
100
import org.eclipse.swt.graphics.GC;
82
import org.eclipse.swt.graphics.Image;
101
import org.eclipse.swt.graphics.Image;
102
import org.eclipse.swt.graphics.Point;
103
import org.eclipse.swt.graphics.TextStyle;
83
import org.eclipse.swt.layout.GridData;
104
import org.eclipse.swt.layout.GridData;
84
import org.eclipse.swt.layout.GridLayout;
105
import org.eclipse.swt.layout.GridLayout;
85
import org.eclipse.swt.widgets.Button;
106
import org.eclipse.swt.widgets.Button;
86
import org.eclipse.swt.widgets.Combo;
107
import org.eclipse.swt.widgets.Combo;
87
import org.eclipse.swt.widgets.Composite;
108
import org.eclipse.swt.widgets.Composite;
88
import org.eclipse.swt.widgets.Control;
109
import org.eclipse.swt.widgets.Control;
110
import org.eclipse.swt.widgets.DateTime;
111
import org.eclipse.swt.widgets.Display;
112
import org.eclipse.swt.widgets.Event;
89
import org.eclipse.swt.widgets.Group;
113
import org.eclipse.swt.widgets.Group;
90
import org.eclipse.swt.widgets.Label;
114
import org.eclipse.swt.widgets.Label;
91
import org.eclipse.swt.widgets.Shell;
115
import org.eclipse.swt.widgets.Shell;
92
import org.eclipse.swt.widgets.TableItem;
116
import org.eclipse.swt.widgets.TableItem;
93
import org.eclipse.swt.widgets.Text;
117
import org.eclipse.swt.widgets.Text;
94
import org.eclipse.swt.widgets.TreeColumn;
118
import org.eclipse.swt.widgets.TreeColumn;
119
import org.eclipse.swt.widgets.Widget;
95
import org.eclipse.ui.IWorkbenchWindow;
120
import org.eclipse.ui.IWorkbenchWindow;
96
import org.eclipse.ui.PlatformUI;
121
import org.eclipse.ui.PlatformUI;
122
import org.eclipse.ui.dialogs.ListDialog;
97
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
123
import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter;
98
import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription;
124
import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription;
99
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
125
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
100
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
126
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
101
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
127
import org.eclipse.ui.internal.ide.IIDEHelpContextIds;
128
import org.eclipse.ui.internal.ide.misc.MultiMatcher;
102
import org.eclipse.ui.plugin.AbstractUIPlugin;
129
import org.eclipse.ui.plugin.AbstractUIPlugin;
103
130
104
/**
131
/**
Lines 108-133 Link Here
108
public class ResourceFilterGroup {
135
public class ResourceFilterGroup {
109
136
110
	private Button addButton = null;
137
	private Button addButton = null;
138
	private Button addGroupButton = null;
111
	private Button removeButton = null;
139
	private Button removeButton = null;
112
	private Button upButton = null;
140
	private Button upButton = null;
113
	private Button downButton = null;
141
	private Button downButton = null;
114
	private Button editButton = null;
142
	private Button editButton = null;
115
143
116
	private TreeViewer filterView;
144
	private TreeViewer filterView;
145
	private TreeContentProvider filterViewContentProvider;
117
	private Filters filters;
146
	private Filters filters;
118
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
147
	private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0];
119
	private LabelProvider labelProvider;
148
	private LabelProvider labelProvider;
149
	private Font boldFont;
150
	private Font plainFont;
120
	private Image checkIcon = null;
151
	private Image checkIcon = null;
121
152
	private Image fileIcon = null;
153
	private Image folderIcon = null;
154
	private Image fileFolderIcon = null;
155
	private Image includeIcon = null;
156
	private Image excludeIcon = null;
157
	private Image inheritableIcon = null;
158
	private Image fileAloneIcon = null;
159
	private Image folderAloneIcon = null;
160
	private Image fileFolderAloneIcon = null;
161
	private Image fileInheritableIcon = null;
162
	private Image folderInheritableIcon = null;
163
	private Image fileFolderInheritableIcon = null;
122
	private boolean tableViewCellEditorAdequatlyUsable = false;
164
	private boolean tableViewCellEditorAdequatlyUsable = false;
123
	private boolean allowReordering = false;
124
125
	// parent shell
126
	private Shell shell;
165
	private Shell shell;
127
128
	private IContainer nonExistantResource = getNonExistantResource();
166
	private IContainer nonExistantResource = getNonExistantResource();
129
	private IContainer resource = nonExistantResource;
167
	private IContainer resource = nonExistantResource;
130
168
169
	// this is a work-around for the TreeView widget that does not draw the text according to each row's image width 
170
	private String textPrefix = new String();
171
	
131
	/**
172
	/**
132
	 * 
173
	 * 
133
	 */
174
	 */
Lines 137-142 Link Here
137
						"$nl$/icons/full/obj16/header_complete.gif"); //$NON-NLS-1$
178
						"$nl$/icons/full/obj16/header_complete.gif"); //$NON-NLS-1$
138
		if (descriptor != null)
179
		if (descriptor != null)
139
			checkIcon = descriptor.createImage();
180
			checkIcon = descriptor.createImage();
181
		
182
		
183
		ImageDescriptor fileIconDescriptor = AbstractUIPlugin
184
		.imageDescriptorFromPlugin(IDEWorkbenchPlugin.IDE_WORKBENCH,
185
				"$nl$/icons/full/obj16/fileType_filter.gif"); //$NON-NLS-1$
186
		if (fileIconDescriptor != null)
187
			fileIcon = fileIconDescriptor.createImage();
188
		
189
		ImageDescriptor folderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
190
				IDEWorkbenchPlugin.IDE_WORKBENCH,
191
				"$nl$/icons/full/obj16/folderType_filter.gif"); //$NON-NLS-1$
192
		if (folderIconDescriptor != null)
193
			folderIcon = folderIconDescriptor.createImage();
194
		
195
		ImageDescriptor fileFolderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
196
				IDEWorkbenchPlugin.IDE_WORKBENCH,
197
				"$nl$/icons/full/obj16/fileFolderType_filter.gif"); //$NON-NLS-1$
198
		if (fileFolderIconDescriptor != null)
199
			fileFolderIcon = fileFolderIconDescriptor.createImage();
200
		
201
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
202
				IDEWorkbenchPlugin.IDE_WORKBENCH,
203
				"$nl$/icons/full/obj16/includeMode_filter.gif"); //$NON-NLS-1$
204
		if (descriptor != null)
205
			includeIcon = descriptor.createImage();
206
		
207
		descriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
208
				IDEWorkbenchPlugin.IDE_WORKBENCH,
209
				"$nl$/icons/full/obj16/excludeMode_filter.gif"); //$NON-NLS-1$
210
		if (descriptor != null)
211
			excludeIcon = descriptor.createImage();
212
		
213
		ImageDescriptor inheritableIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin(
214
				IDEWorkbenchPlugin.IDE_WORKBENCH,
215
				"$nl$/icons/full/obj16/inheritable_filter.gif"); //$NON-NLS-1$
216
		if (inheritableIconDescriptor != null)
217
			inheritableIcon = inheritableIconDescriptor.createImage();
218
219
		CompositeImageDescriptor desc = new AlignedCompositeImageDescriptor(null, fileIconDescriptor);
220
		fileAloneIcon = desc.createImage();
221
222
		desc = new AlignedCompositeImageDescriptor(null, folderIconDescriptor);
223
		folderAloneIcon = desc.createImage();
224
225
		desc = new AlignedCompositeImageDescriptor(null, fileFolderIconDescriptor);
226
		fileFolderAloneIcon = desc.createImage();
227
228
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileIconDescriptor);
229
		fileInheritableIcon = desc.createImage();
230
231
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, folderIconDescriptor);
232
		folderInheritableIcon = desc.createImage();
233
234
		desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileFolderIconDescriptor);
235
		fileFolderInheritableIcon = desc.createImage();
236
	}
237
238
	private static int AlignedCompositeImageDescriptor_SPACE = 4;
239
240
	private class AlignedCompositeImageDescriptor extends CompositeImageDescriptor {
241
242
		
243
		ImageDescriptor first, second;
244
		AlignedCompositeImageDescriptor(ImageDescriptor first, ImageDescriptor second) {
245
			this.first = first;
246
			this.second = second;
247
		}
248
		/* (non-Javadoc)
249
		 * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int)
250
		 */
251
		protected void drawCompositeImage(int width, int height) {
252
			if (first != null) {
253
				drawImage(first.getImageData(), 0, 0);
254
				drawImage(second.getImageData(), first.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0);
255
			}
256
			else
257
				drawImage(second.getImageData(), second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0);
258
		}
259
260
		/* (non-Javadoc)
261
		 * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize()
262
		 */
263
		protected Point getSize() {
264
			if (first != null)
265
				return new Point(first.getImageData().width + second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 
266
					Math.max(first.getImageData().height, second.getImageData().height));
267
			return new Point(second.getImageData().width * 2 + AlignedCompositeImageDescriptor_SPACE, second.getImageData().height);
268
		}
269
		
270
	}
271
272
	Image getImage(String string, int i) {
273
		if (string.equals(FilterTypeUtil.MODE))
274
			return new Image[] { includeIcon, excludeIcon, inheritableIcon }[i];
275
		if (string.equals(FilterTypeUtil.TARGET))
276
			return new Image[] { fileIcon, folderIcon, fileFolderIcon }[i];
277
		return null;
140
	}
278
	}
141
279
142
	/**
280
	/**
Lines 277-299 Link Here
277
		}
415
		}
278
	}
416
	}
279
417
418
	static String includeOnlyGroup = "INCLUDE_ONLY_GROUP";  //$NON-NLS-1$
419
420
	static String excludeAllGroup = "EXCLUDE_ALL_GROUP";  //$NON-NLS-1$
421
280
	class TreeContentProvider implements ITreeContentProvider {
422
	class TreeContentProvider implements ITreeContentProvider {
423
		
281
		public Object[] getChildren(Object parentElement) {
424
		public Object[] getChildren(Object parentElement) {
425
			if (parentElement == filters) {
426
				FilterCopy[] children = filters.getChildren();
427
				if (children.length > 0) {
428
					boolean includeOnly = false;
429
					boolean excludeAll = false;
430
					for (int i = 0; i < children.length; i++) {
431
						includeOnly |= (children[i].getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0;
432
						excludeAll |= (children[i].getType() & IResourceFilterDescription.EXCLUDE_ALL) != 0;
433
					}
434
					ArrayList list = new ArrayList();
435
					if (includeOnly)
436
						list.add(includeOnlyGroup);
437
					if (excludeAll)
438
						list.add(excludeAllGroup);
439
					return list.toArray();
440
				}
441
			}
442
			if (parentElement instanceof String) {
443
				ArrayList list = new ArrayList();
444
				int mask = parentElement.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
445
								IResourceFilterDescription.EXCLUDE_ALL;
446
				FilterCopy[] children = filters.getChildren();
447
				for (int i = 0; i < children.length; i++) {
448
					if ((children[i].getType() & mask) != 0)
449
						list.add(children[i]);
450
				}
451
				return list.toArray();
452
			}
282
			if (parentElement instanceof FilterCopy)
453
			if (parentElement instanceof FilterCopy)
283
				return ((FilterCopy) parentElement).getChildren();
454
				return ((FilterCopy) parentElement).getChildren();
284
			return null;
455
			return null;
285
		}
456
		}
286
457
287
		public Object getParent(Object element) {
458
		public Object getParent(Object element) {
288
			if (element instanceof FilterCopy) {
459
			if (element instanceof String)
289
				if (((FilterCopy) element).getParent() != null)
290
					return ((FilterCopy) element).getParent();
291
				return filters;
460
				return filters;
461
			if (element instanceof FilterCopy) {
462
				FilterCopy filterCopy = (FilterCopy) element;
463
				if (filterCopy.getParent() != null)
464
					return filterCopy.getParent();
465
				return ((filterCopy.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0) ? includeOnlyGroup: excludeAllGroup;
292
			}
466
			}
293
			return null;
467
			return null;
294
		}
468
		}
295
469
296
		public boolean hasChildren(Object element) {
470
		public boolean hasChildren(Object element) {
471
			if (element instanceof String)
472
				return true;
297
			if (element instanceof FilterCopy) {
473
			if (element instanceof FilterCopy) {
298
				FilterCopy[] children = ((FilterCopy) element).getChildren();
474
				FilterCopy[] children = ((FilterCopy) element).getChildren();
299
				return children != null && children.length > 0;
475
				return children != null && children.length > 0;
Lines 312-322 Link Here
312
		}
488
		}
313
	}
489
	}
314
490
315
	class LabelProvider implements ITableLabelProvider {
491
	class LabelProvider extends StyledCellLabelProvider  {
492
		private final Styler fBoldStyler; 
493
		private final Styler fPlainStyler; 
316
		FilterTypeUtil util;
494
		FilterTypeUtil util;
495
		TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
317
496
318
		public LabelProvider() {
497
		public LabelProvider() {
319
			util = new FilterTypeUtil();
498
			util = new FilterTypeUtil();
499
			fBoldStyler= new Styler() {
500
				public void applyStyles(TextStyle textStyle) {
501
					textStyle.font= boldFont;
502
				}
503
			};
504
			fPlainStyler= new Styler() {
505
				public void applyStyles(TextStyle textStyle) {
506
					textStyle.font= plainFont;
507
				}
508
			};
509
			ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(null, null);
510
			customfilterArgumentMap.put(ui.getID(), ui);
511
			ui = new DefaultCustomFilterArgumentUI(null, null);
512
			customfilterArgumentMap.put(ui.getID(), ui);
513
		}
514
515
		ICustomFilterArgumentUI getUI(String descriptorID) {
516
			ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
517
			if (result == null)
518
				return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
519
			return result;
320
		}
520
		}
321
521
322
		String getColumnID(int index) {
522
		String getColumnID(int index) {
Lines 328-412 Link Here
328
			return copy.isUnderAGroupFilter();
528
			return copy.isUnderAGroupFilter();
329
		}
529
		}
330
530
331
		public Image getColumnImage(Object element, int columnIndex) {
531
		public void update(ViewerCell cell) {
332
			if (!isPartialFilter(element)) {
532
			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);
533
			String column = getColumnID(columnIndex);
358
			return getValue(filter, column);
534
			FilterCopy filter = null;
359
		}
360
535
361
		private String getValue(FilterCopy filter, String column) {
536
			Object element = cell.getElement();
362
			if (column.equals(FilterTypeUtil.ID)) {
537
			if (element instanceof String) {
363
				String id = filter.getId();
538
				if (column.equals(FilterTypeUtil.MODE)) {
364
				IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
539
					cell.setImage(getImage(FilterTypeUtil.MODE, element.equals(includeOnlyGroup) ? 0:1));
365
				if (descriptor != null)
540
				}
366
					return descriptor.getName();
541
				if (column.equals(FilterTypeUtil.MODE)) {
367
			}
542
					if (element.equals(includeOnlyGroup))
368
			if (column.equals(FilterTypeUtil.MODE)) {
543
						cell.setText(NLS
369
				if (!isPartialFilter(filter)) {
370
					if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0)
371
						return NLS
372
								.bind(
544
								.bind(
373
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
545
										IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn,
374
										null);
546
										null));
375
					return NLS
547
					else
548
						cell.setText(NLS
376
							.bind(
549
							.bind(
377
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
550
									IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn,
378
									null);
551
									null));
379
				}
552
				}
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
			}
553
			}
401
			if (column.equals(FilterTypeUtil.ARGUMENTS)) {
554
			else {
402
				if (filter.hasStringArguments())
555
				filter = (FilterCopy) element;
403
					return filter.getArguments() != null ? filter
556
	
404
							.getArguments().toString() : ""; //$NON-NLS-1$
557
				if (column.equals(FilterTypeUtil.ID)) {
405
				if ((filter.getChildrenLimit() > 0)
558
					String id = filter.getId();
406
						&& !filter.isUnderAGroupFilter())
559
					IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id);
407
					return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$
560
					if (descriptor != null)
561
						cell.setText(descriptor.getName());
562
				}
563
				if (!isPartialFilter(filter)) {
564
					if (column.equals(FilterTypeUtil.INHERITABLE)) {
565
						Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
566
						cell.setImage(((Boolean) condition).booleanValue() ? checkIcon: null);
567
					}
568
				}
569
				if (column.equals(FilterTypeUtil.MODE)) {
570
					StyledString styledString = new StyledString(textPrefix, fPlainStyler);
571
					styledString.append(getStyleColumnText(filter));
572
					cell.setText(styledString.toString());
573
					cell.setStyleRanges(styledString.getStyleRanges());
574
575
					if (!isPartialFilter(filter)) {
576
						Image[] images = { fileAloneIcon, folderAloneIcon, fileFolderAloneIcon };
577
						Image[] inheritableImages = {fileInheritableIcon, folderInheritableIcon, fileFolderInheritableIcon};
578
579
						Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET);
580
						Object isInheritable = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE);
581
						int intValue = ((Integer)index).intValue();
582
						if (((Boolean)isInheritable).booleanValue())
583
							cell.setImage(inheritableImages[intValue]);
584
						else
585
							cell.setImage(images[intValue]);
586
					}
587
				}
408
			}
588
			}
409
			return null;
589
590
			super.update(cell);
591
		}
592
		
593
		private StyledString getStyleColumnText(FilterCopy filter) {
594
			if ((filter.getChildrenLimit() > 0)) {
595
				String whiteSpace = " "; //$NON-NLS-1$;
596
				String expression = getFilterTypeName(filter);
597
				boolean isUnaryOperator = filter.getId().equals("org.eclipse.ui.ide.notFilterMatcher"); //$NON-NLS-1$
598
				StyledString buffer = new StyledString();
599
				if (isUnaryOperator) {
600
					buffer.append("NOT ", fBoldStyler); //$NON-NLS-1$
601
					expression = "OR"; //$NON-NLS-1$
602
				}
603
				buffer.append("(", fBoldStyler); //$NON-NLS-1$
604
				Object [] children = filterViewContentProvider.getChildren(filter);
605
				for (int i = 0; i < children.length; i++) {
606
					buffer.append(getStyleColumnText((FilterCopy) children[i]));
607
					if ((i + 1) < children.length) {
608
						buffer.append(whiteSpace, fPlainStyler);
609
						buffer.append(expression, fBoldStyler);
610
						buffer.append(whiteSpace, fPlainStyler);
611
					}
612
				}
613
				if (children.length < 2 && !isUnaryOperator) {
614
					if (children.length == 1)
615
						buffer.append(whiteSpace, fPlainStyler);
616
					buffer.append(expression, fBoldStyler);
617
				}
618
				buffer.append(")", fBoldStyler); //$NON-NLS-1$
619
				return buffer;
620
			} 
621
			ICustomFilterArgumentUI ui = getUI(filter.getId());
622
			return ui.formatStyledText(filter, fPlainStyler, fBoldStyler);
623
		}
624
625
		protected void measure(Event event, Object element) {
626
			super.measure(event, element);
410
		}
627
		}
411
628
412
		private String getFilterTypeName(FilterCopy filter) {
629
		private String getFilterTypeName(FilterCopy filter) {
Lines 416-436 Link Here
416
				return desc.getName();
633
				return desc.getName();
417
			return ""; //$NON-NLS-1$
634
			return ""; //$NON-NLS-1$
418
		}
635
		}
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
	}
636
	}
433
637
	
434
	class CellModifier implements ICellModifier {
638
	class CellModifier implements ICellModifier {
435
		public boolean canModify(Object element, String property) {
639
		public boolean canModify(Object element, String property) {
436
			FilterCopy filter = (FilterCopy) element;
640
			FilterCopy filter = (FilterCopy) element;
Lines 506-520 Link Here
506
	}
710
	}
507
711
508
	private void createViewerGroup(Composite parent) {
712
	private void createViewerGroup(Composite parent) {
509
		filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER
713
		
510
				| SWT.H_SCROLL);
714
		GC gc = new GC(parent);
715
		gc.setFont(plainFont);
716
		String whiteSpace = " "; //$NON-NLS-1$
717
		textPrefix = whiteSpace;
718
		int width = inheritableIcon.getImageData().width + AlignedCompositeImageDescriptor_SPACE;
719
		while (gc.stringExtent(textPrefix).x < width) {
720
			textPrefix += whiteSpace;
721
		}
722
		gc.dispose();
723
724
		Composite tableComposite = new Composite(parent, SWT.NONE);
511
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
725
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
512
		data.grabExcessHorizontalSpace = true;
726
		data.grabExcessHorizontalSpace = true;
513
		data.grabExcessVerticalSpace = true;
727
		data.grabExcessVerticalSpace = true;
728
		tableComposite.setLayoutData(data);
729
730
		filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER
731
				| SWT.H_SCROLL);
732
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
733
		data.grabExcessHorizontalSpace = true;
734
		data.grabExcessVerticalSpace = true;
514
		filterView.getTree().setLayoutData(data);
735
		filterView.getTree().setLayoutData(data);
515
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
736
		filterView.setColumnProperties(FilterTypeUtil.columnNames);
516
737
517
		filterView.setContentProvider(new TreeContentProvider());
738
		plainFont = filterView.getTree().getFont();
739
		FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD);
740
		boldFont = new Font(Display.getCurrent(), boldFontData);
741
742
		filterView.setAutoExpandLevel(2);
743
		filterViewContentProvider = new TreeContentProvider();
744
		filterView.setContentProvider(filterViewContentProvider);
518
		filterView.setInput(filters);
745
		filterView.setInput(filters);
519
		filterView.getTree().setFont(parent.getFont());
746
		filterView.getTree().setFont(parent.getFont());
520
747
Lines 524-560 Link Here
524
			}
751
			}
525
		});
752
		});
526
753
527
		TreeColumn column = new TreeColumn(filterView.getTree(), 0);
754
		TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0);
528
		column
755
		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
756
				.setText(NLS
550
						.bind(
757
						.bind(
551
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
758
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterDescription,
552
								null));
759
								null));
553
		column.setData(FilterTypeUtil.INHERITABLE);
760
		modeColumn.setData(FilterTypeUtil.MODE);
554
		column.setResizable(true);
761
		modeColumn.setResizable(true);
555
		column.setMoveable(false);
762
		modeColumn.setMoveable(false);
556
		column.setAlignment(SWT.CENTER);
557
		column.setWidth(getMinimumColumnWidth(column, 70));
558
763
559
		filterView.getTree().setHeaderVisible(true);
764
		filterView.getTree().setHeaderVisible(true);
560
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
765
		filterView.getTree().showColumn(filterView.getTree().getColumn(0));
Lines 578-584 Link Here
578
783
579
		filterView.getTree().addMouseListener(new MouseListener() {
784
		filterView.getTree().addMouseListener(new MouseListener() {
580
			public void mouseDoubleClick(MouseEvent e) {
785
			public void mouseDoubleClick(MouseEvent e) {
581
				handleEdit();
786
				if (!handleEdit()) {
787
					ISelection selection = filterView.getSelection();
788
					if (selection instanceof IStructuredSelection) {
789
						if (((IStructuredSelection) selection).size() > 0) {
790
							Object firstElement = ((IStructuredSelection) selection).getFirstElement();
791
							filterView.setExpandedState(firstElement, !filterView.getExpandedState(firstElement));
792
						}
793
					}
794
				}
582
			}
795
			}
583
796
584
			public void mouseDown(MouseEvent e) {
797
			public void mouseDown(MouseEvent e) {
Lines 598-616 Link Here
598
			public void menuDetected(MenuDetectEvent e) {
811
			public void menuDetected(MenuDetectEvent e) {
599
				MenuManager mgr = new MenuManager();
812
				MenuManager mgr = new MenuManager();
600
				mgr.add(addSubFilterAction);
813
				mgr.add(addSubFilterAction);
814
				mgr.add(addSubGroupFilterAction);
815
				mgr.add(new Separator());
816
				mgr.add(new EditFilterAction());
817
				mgr.add(new RemoveFilterAction());
601
				filterView.getControl().setMenu(
818
				filterView.getControl().setMenu(
602
						mgr.createContextMenu(filterView.getControl()));
819
						mgr.createContextMenu(filterView.getControl()));
603
			}
820
			}
604
		});
821
		});
822
		TreeColumnLayout layout = new TreeColumnLayout();
823
		tableComposite.setLayout( layout );
824
825
		layout.setColumnData( modeColumn, new ColumnWeightData(100));
826
	}
827
828
	private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) {
829
		FontData[] styleData = new FontData[originalData.length];
830
		for (int i = 0; i < styleData.length; i++) {
831
			FontData base = originalData[i];
832
			styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle);
833
		}
834
       	return styleData;
835
    }
836
837
	class EditFilterAction extends Action {
838
839
		public EditFilterAction() {
840
			setText(NLS
841
					.bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel,
842
							null));
843
		}
844
845
		public void run() {
846
			handleEdit();
847
		}
848
		public boolean isEnabled() {
849
			ISelection selection = filterView.getSelection();
850
			if (selection instanceof IStructuredSelection) {
851
				if (((IStructuredSelection) selection).size() > 0) {
852
					Object firstElement = ((IStructuredSelection) selection)
853
					.getFirstElement();
854
					return firstElement instanceof FilterCopy;
855
				}
856
			}
857
			return false;
858
		}
859
	}
860
861
	class RemoveFilterAction extends Action {
862
863
		public RemoveFilterAction() {
864
			setText(NLS
865
					.bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel,
866
							null));
867
		}
868
869
		public void run() {
870
			handleRemove();
871
		}
872
		public boolean isEnabled() {
873
			ISelection selection = filterView.getSelection();
874
			if (selection instanceof IStructuredSelection) {
875
				return ((IStructuredSelection) selection).size() > 0;			}
876
			return false;
877
		}
605
	}
878
	}
606
879
607
	Action addSubFilterAction = new AddSubFilterAction();
880
	Action addSubFilterAction = new AddSubFilterAction(false);
608
881
609
	class AddSubFilterAction extends Action {
882
	class AddSubFilterAction extends Action {
610
883
611
		public AddSubFilterAction() {
884
		boolean createGroupOnly;
885
		
886
		public AddSubFilterAction(boolean createGroupOnly) {
887
			this.createGroupOnly = createGroupOnly;
612
			setText(NLS
888
			setText(NLS
613
					.bind(
889
					.bind(createGroupOnly ?
890
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel:
614
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
891
							IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel,
615
							null));
892
							null));
616
		}
893
		}
Lines 623-637 Link Here
623
		public void run() {
900
		public void run() {
624
			ISelection selection = filterView.getSelection();
901
			ISelection selection = filterView.getSelection();
625
			if (selection instanceof IStructuredSelection) {
902
			if (selection instanceof IStructuredSelection) {
626
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
903
				Object firstElement = ((IStructuredSelection) selection)
627
						.getFirstElement();
904
				.getFirstElement();
628
				if (filter.getChildrenLimit() > 0) {
905
				if (firstElement instanceof FilterCopy) {
906
					FilterCopy filter = (FilterCopy) firstElement;
907
					if (filter.getChildrenLimit() > 0) {
908
						FilterCopy newFilter = new FilterCopy();
909
						newFilter.setParent(filter);
910
						FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell,
911
								newFilter, createGroupOnly);
912
						if (dialog.open() == Window.OK) {
913
							filter.addChild(newFilter);
914
							filterView.refresh();
915
						}
916
					}
917
				}
918
				if (firstElement instanceof String) {
629
					FilterCopy newFilter = new FilterCopy();
919
					FilterCopy newFilter = new FilterCopy();
630
					newFilter.setParent(filter);
920
					FilterTypeUtil.setValue(newFilter, FilterTypeUtil.MODE, 
631
					FilterEditDialog dialog = new FilterEditDialog(resource, shell,
921
							new Integer(firstElement.equals(includeOnlyGroup) ? 0:1));
632
							newFilter);
922
					FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell,
923
							newFilter, createGroupOnly);
633
					if (dialog.open() == Window.OK) {
924
					if (dialog.open() == Window.OK) {
634
						filter.addChild(newFilter);
925
						filters.addChild(newFilter);
635
						filterView.refresh();
926
						filterView.refresh();
636
					}
927
					}
637
				}
928
				}
Lines 646-659 Link Here
646
		public boolean isEnabled() {
937
		public boolean isEnabled() {
647
			ISelection selection = filterView.getSelection();
938
			ISelection selection = filterView.getSelection();
648
			if (selection instanceof IStructuredSelection) {
939
			if (selection instanceof IStructuredSelection) {
649
				FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
940
				Object firstElement = ((IStructuredSelection) selection)
650
						.getFirstElement();
941
						.getFirstElement();
651
				return filter.getChildrenLimit() > 0;
942
				if (firstElement instanceof FilterCopy) {
943
					FilterCopy filter = (FilterCopy) firstElement;
944
					return filter.getChildrenLimit() > 0;
945
				}
946
				if (firstElement instanceof String)
947
					return true;
652
			}
948
			}
653
			return false;
949
			return false;
654
		}
950
		}
655
	}
951
	}
656
952
953
	Action addSubGroupFilterAction = new AddSubFilterAction(true);
954
657
	class FilterCopyDrop extends ViewerDropAdapter {
955
	class FilterCopyDrop extends ViewerDropAdapter {
658
		protected FilterCopyDrop(Viewer viewer) {
956
		protected FilterCopyDrop(Viewer viewer) {
659
			super(viewer);
957
			super(viewer);
Lines 682-687 Link Here
682
			for (int i = 0; i < toDrop.length; i++) {
980
			for (int i = 0; i < toDrop.length; i++) {
683
				if (target instanceof Filters)
981
				if (target instanceof Filters)
684
					filters.add(toDrop[i]);
982
					filters.add(toDrop[i]);
983
				if (target instanceof String) {
984
					FilterTypeUtil.setValue(toDrop[i], FilterTypeUtil.MODE,
985
							new Integer(target.equals(includeOnlyGroup) ? 0:1));
986
					filters.add(toDrop[i]);
987
				}
685
				if (target instanceof FilterCopy)
988
				if (target instanceof FilterCopy)
686
					((FilterCopy) target).addChild(toDrop[i]);
989
					((FilterCopy) target).addChild(toDrop[i]);
687
				filterView.refresh();
990
				filterView.refresh();
Lines 749-768 Link Here
749
		}
1052
		}
750
	}
1053
	}
751
1054
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) {
1055
	private void createButtonGroup(Composite parent) {
767
		Composite composite = new Composite(parent, SWT.NONE);
1056
		Composite composite = new Composite(parent, SWT.NONE);
768
		GridLayout layout = new GridLayout();
1057
		GridLayout layout = new GridLayout();
Lines 780-793 Link Here
780
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1069
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
781
		addButton.setLayoutData(data);
1070
		addButton.setLayoutData(data);
782
		setButtonDimensionHint(addButton);
1071
		setButtonDimensionHint(addButton);
783
		addButton.addSelectionListener(new SelectionListener() {
1072
		addButton.addSelectionListener(new SelectionAdapter() {
784
			public void widgetDefaultSelected(SelectionEvent e) {
1073
			public void widgetSelected(SelectionEvent e) {
1074
				handleAdd(false);
785
			}
1075
			}
786
1076
		});
1077
		
1078
		addGroupButton = new Button(composite, SWT.PUSH);
1079
		addGroupButton.setText(NLS.bind(
1080
				IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null));
1081
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1082
		addGroupButton.setLayoutData(data);
1083
		setButtonDimensionHint(addGroupButton);
1084
		addGroupButton.addSelectionListener(new SelectionAdapter() {
787
			public void widgetSelected(SelectionEvent e) {
1085
			public void widgetSelected(SelectionEvent e) {
788
				handleAdd();
1086
				handleAdd(true);
789
			}
1087
			}
790
		});
1088
		});
1089
		
791
1090
792
		editButton = new Button(composite, SWT.PUSH);
1091
		editButton = new Button(composite, SWT.PUSH);
793
		editButton.setText(NLS.bind(
1092
		editButton.setText(NLS.bind(
Lines 795-804 Link Here
795
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1094
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
796
		editButton.setLayoutData(data);
1095
		editButton.setLayoutData(data);
797
		setButtonDimensionHint(editButton);
1096
		setButtonDimensionHint(editButton);
798
		editButton.addSelectionListener(new SelectionListener() {
1097
		editButton.addSelectionListener(new SelectionAdapter() {
799
			public void widgetDefaultSelected(SelectionEvent e) {
800
			}
801
802
			public void widgetSelected(SelectionEvent e) {
1098
			public void widgetSelected(SelectionEvent e) {
803
				handleEdit();
1099
				handleEdit();
804
			}
1100
			}
Lines 813-862 Link Here
813
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
1109
		data = new GridData(SWT.FILL, SWT.FILL, false, false);
814
		removeButton.setLayoutData(data);
1110
		removeButton.setLayoutData(data);
815
		setButtonDimensionHint(removeButton);
1111
		setButtonDimensionHint(removeButton);
816
		removeButton.addSelectionListener(new SelectionListener() {
1112
		removeButton.addSelectionListener(new SelectionAdapter() {
817
			public void widgetDefaultSelected(SelectionEvent e) {
818
			}
819
820
			public void widgetSelected(SelectionEvent e) {
1113
			public void widgetSelected(SelectionEvent e) {
821
				handleRemove();
1114
				handleRemove();
822
			}
1115
			}
823
		});
1116
		});
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
	}
1117
	}
861
1118
862
	private void refreshEnablement() {
1119
	private void refreshEnablement() {
Lines 868-874 Link Here
868
		removeButton.setEnabled(structuredSelection != null
1125
		removeButton.setEnabled(structuredSelection != null
869
				&& structuredSelection.size() > 0);
1126
				&& structuredSelection.size() > 0);
870
		editButton.setEnabled(structuredSelection != null
1127
		editButton.setEnabled(structuredSelection != null
871
				&& structuredSelection.size() == 1);
1128
				&& structuredSelection.size() == 1
1129
				&& (structuredSelection.getFirstElement() instanceof FilterCopy));
872
		if (upButton != null)
1130
		if (upButton != null)
873
			upButton.setEnabled(structuredSelection != null
1131
			upButton.setEnabled(structuredSelection != null
874
					&& (structuredSelection.size() > 0)
1132
					&& (structuredSelection.size() > 0)
Lines 887-916 Link Here
887
		return filters.isLast((FilterCopy) o);
1145
		return filters.isLast((FilterCopy) o);
888
	}
1146
	}
889
1147
890
	private void handleAdd() {
1148
	private void handleAdd(boolean createGroupOnly) {
891
		FilterCopy newFilter = new FilterCopy();
1149
		FilterCopy newFilter = new FilterCopy();
892
		FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter);
1150
		FilterEditDialog dialog = new FilterEditDialog(resource, this, shell, newFilter, createGroupOnly);
893
		if (dialog.open() == Window.OK) {
1151
		if (dialog.open() == Window.OK) {
894
			filters.add(newFilter);
1152
			filters.add(newFilter);
895
			filterView.refresh();
1153
			filterView.refresh();
896
		}
1154
		}
897
	}
1155
	}
898
1156
899
	private void handleEdit() {
1157
	private boolean handleEdit() {
900
		ISelection selection = filterView.getSelection();
1158
		ISelection selection = filterView.getSelection();
901
		if (selection instanceof IStructuredSelection) {
1159
		if (selection instanceof IStructuredSelection) {
902
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
1160
			Object firstElement = ((IStructuredSelection) selection)
903
					.getFirstElement();
1161
					.getFirstElement();
904
			FilterCopy copy = new FilterCopy(filter);
1162
			if (firstElement instanceof String)
905
			copy.setParent(filter.getParent());
1163
				return false;
906
			FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy);
1164
			if (firstElement instanceof FilterCopy) {
907
			if (dialog.open() == Window.OK) {
1165
				FilterCopy filter = (FilterCopy) firstElement;
908
				if (copy.hasChanged()) {
1166
				FilterCopy copy = new FilterCopy(filter);
909
					filter.copy(copy);
1167
				copy.setParent(filter.getParent());
910
					filterView.refresh();
1168
				boolean isGroup = filter.getChildrenLimit() > 0;
1169
				FilterEditDialog dialog = new FilterEditDialog(resource, this, shell, copy, isGroup);
1170
				if (dialog.open() == Window.OK) {
1171
					if (copy.hasChanged()) {
1172
						filter.copy(copy);
1173
						filterView.refresh();
1174
					}
911
				}
1175
				}
1176
				return true;
912
			}
1177
			}
913
		}
1178
		}
1179
		return false;
914
	}
1180
	}
915
1181
916
	private FilterCopy[] getFilterCopySelection() {
1182
	private FilterCopy[] getFilterCopySelection() {
Lines 933-967 Link Here
933
			structuredSelection = ((IStructuredSelection) selection);
1199
			structuredSelection = ((IStructuredSelection) selection);
934
			Iterator it = structuredSelection.iterator();
1200
			Iterator it = structuredSelection.iterator();
935
			while (it.hasNext()) {
1201
			while (it.hasNext()) {
936
				FilterCopy filter = (FilterCopy) it.next();
1202
				Object element = it.next();
937
				filter.getParent().removeChild(filter);
1203
				if (element instanceof FilterCopy) {
1204
					FilterCopy filter = (FilterCopy) element;
1205
					filter.getParent().removeChild(filter);
1206
				}
1207
				else {
1208
					int mask = element.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY:
1209
						IResourceFilterDescription.EXCLUDE_ALL;
1210
					FilterCopy[] children = filters.getChildren();
1211
					for (int i = 0; i < children.length; i++) {
1212
						if ((children[i].getType() & mask) != 0)
1213
							filters.removeChild(children[i]);
1214
					}
1215
				}
938
			}
1216
			}
939
			filterView.refresh();
1217
			filterView.refresh();
940
		}
1218
		}
941
	}
1219
	}
942
1220
943
	private void handleUp() {
944
		ISelection selection = filterView.getSelection();
945
		if (selection instanceof IStructuredSelection) {
946
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
947
					.getFirstElement();
948
			filters.moveUp(filter);
949
		}
950
		filterView.refresh();
951
		refreshEnablement();
952
	}
953
954
	private void handleDown() {
955
		ISelection selection = filterView.getSelection();
956
		if (selection instanceof IStructuredSelection) {
957
			FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection)
958
					.getFirstElement();
959
			filters.moveDown(filter);
960
		}
961
		filterView.refresh();
962
		refreshEnablement();
963
	}
964
965
	private static void setButtonDimensionHint(Button button) {
1221
	private static void setButtonDimensionHint(Button button) {
966
		Assert.isNotNull(button);
1222
		Assert.isNotNull(button);
967
		Object gd = button.getLayoutData();
1223
		Object gd = button.getLayoutData();
Lines 1066-1074 Link Here
1066
	 * Disposes the group's resources.
1322
	 * Disposes the group's resources.
1067
	 */
1323
	 */
1068
	public void dispose() {
1324
	public void dispose() {
1069
		if (checkIcon != null) {
1325
		disposeIcons();
1070
			checkIcon.dispose();
1326
	}
1071
			checkIcon = null;
1327
1328
	private void disposeIcons() {
1329
		Field[] fields = getClass().getFields();
1330
		for (int i = 0; i < fields.length; i++) {
1331
			if (fields[i].getClass().equals(Image.class)) {
1332
				Image img;
1333
				try {
1334
					img = (Image) fields[i].get(this);
1335
					if (img != null) {
1336
						img.dispose();
1337
						fields[i].set(this, null);
1338
					}
1339
				} catch (IllegalArgumentException e) {
1340
					e.printStackTrace();
1341
				} catch (IllegalAccessException e) {
1342
					e.printStackTrace();
1343
				}
1344
			}
1072
		}
1345
		}
1073
	}
1346
	}
1074
1347
Lines 1149-1155 Link Here
1149
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1422
	static String ARGUMENTS = "arguments"; //$NON-NLS-1$
1150
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1423
	static String INHERITABLE = "inheritable"; //$NON-NLS-1$
1151
1424
1152
	static String[] columnNames = new String[] { MODE, ARGUMENTS, INHERITABLE };
1425
	static String[] columnNames = new String[] { MODE, TARGET, INHERITABLE };
1153
1426
1154
	static String[] getModes() {
1427
	static String[] getModes() {
1155
		return new String[] {
1428
		return new String[] {
Lines 1263-1286 Link Here
1263
								null) };
1536
								null) };
1264
	}
1537
	}
1265
1538
1266
	static String[] getFilterNames(boolean childrenOnly) {
1539
	static String[] getFilterNames(boolean groupOnly) {
1267
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1540
		IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace()
1268
				.getFilterMatcherDescriptors();
1541
				.getFilterMatcherDescriptors();
1542
		sortDescriptors(descriptors);
1269
		LinkedList names = new LinkedList();
1543
		LinkedList names = new LinkedList();
1270
		for (int i = 0; i < descriptors.length; i++) {
1544
		for (int i = 0; i < descriptors.length; i++) {
1271
			if (!childrenOnly
1545
			boolean isGroup = descriptors[i].getArgumentType().equals(
1272
					|| descriptors[i].getArgumentType().equals(
1546
					IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1273
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER)
1274
					|| descriptors[i].getArgumentType().equals(
1547
					|| descriptors[i].getArgumentType().equals(
1275
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS))
1548
							IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS);
1549
			if (isGroup == groupOnly) 
1276
				names.add(descriptors[i].getName());
1550
				names.add(descriptors[i].getName());
1277
		}
1551
		}
1278
		return (String[]) names.toArray(new String[0]);
1552
		return (String[]) names.toArray(new String[0]);
1279
	}
1553
	}
1280
1554
1555
	/**
1556
	 * @param descriptors
1557
	 */
1558
	private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) {
1559
		Arrays.sort(descriptors, new Comparator() {
1560
			public int compare(Object arg0, Object arg1) {
1561
				if (((IFilterMatcherDescriptor) arg0).getId().equals(MultiMatcher.ID))
1562
					return -1;
1563
				if (((IFilterMatcherDescriptor) arg1).getId().equals(MultiMatcher.ID))
1564
					return 1;
1565
				return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId());
1566
			}
1567
		});
1568
	}
1569
1281
	static String getDefaultFilterID() {
1570
	static String getDefaultFilterID() {
1282
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1571
		IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace()
1283
				.getFilterMatcherDescriptors();
1572
				.getFilterMatcherDescriptors();
1573
		sortDescriptors(descriptors);
1284
		for (int i = 0; i < descriptors.length; i++) {
1574
		for (int i = 0; i < descriptors.length; i++) {
1285
			if (descriptors[i].getArgumentType().equals(
1575
			if (descriptors[i].getArgumentType().equals(
1286
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
1576
					IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING))
Lines 1304-1363 Link Here
1304
		}
1594
		}
1305
		return null;
1595
		return null;
1306
	}
1596
	}
1307
1597
	FilterTypeUtil() {}
1308
	private Image fileIcon = null;
1598
}
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
}
1361
1599
1362
class FilterCopy extends UIResourceFilterDescription {
1600
class FilterCopy extends UIResourceFilterDescription {
1363
	Object arguments = null;
1601
	Object arguments = null;
Lines 1669-1700 Link Here
1669
	protected Button foldersButton;
1907
	protected Button foldersButton;
1670
	protected Button filesAndFoldersButton;
1908
	protected Button filesAndFoldersButton;
1671
	protected Combo idCombo;
1909
	protected Combo idCombo;
1910
	protected Composite idComposite;
1911
	protected Composite argumentComposite;
1672
	protected Button inherited;
1912
	protected Button inherited;
1673
	protected Text arguments;
1674
	protected Label argumentsLabel;
1675
	protected Label description;
1676
	protected FilterTypeUtil util;
1913
	protected FilterTypeUtil util;
1914
	protected boolean createGroupOnly;
1915
	protected ResourceFilterGroup filterGroup;
1677
	protected IResource resource;
1916
	protected IResource resource;
1678
1917
1679
	private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$
1918
	TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap();
1680
	
1919
	ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() {
1681
	/**
1920
		public Object getID() {return "dummy";} //$NON-NLS-1$
1682
	 * Find and replace command adapters.
1921
		public void create(Composite argumentComposite, Font font) {}
1683
	 * @since 3.3
1922
		public void dispose() {}
1684
	 */
1923
		public void selectionChanged() {}
1685
	private ContentAssistCommandAdapter fContentAssistField;
1924
		public void validate() {}
1925
		public StyledString formatStyledText(FilterCopy filter,
1926
				Styler fPlainStyler, Styler fBoldStyler) {return null;}
1927
	};
1686
1928
1687
	/**
1929
	/**
1688
	 * Constructor for FilterEditDialog.
1930
	 * Constructor for FilterEditDialog.
1689
	 * 
1931
	 * @param resource 
1932
	 * @param filterGroup 
1690
	 * @param parentShell
1933
	 * @param parentShell
1691
	 * @param filter
1934
	 * @param filter
1935
	 * @param createGroupOnly 
1692
	 */
1936
	 */
1693
	public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) {
1937
	public FilterEditDialog(IResource resource, ResourceFilterGroup filterGroup, Shell parentShell, FilterCopy filter, boolean createGroupOnly) {
1694
		super(parentShell);
1938
		super(parentShell);
1695
		this.resource = resource;
1939
		this.resource = resource;
1940
		this.filterGroup = filterGroup;
1696
		this.filter = filter;
1941
		this.filter = filter;
1942
		this.createGroupOnly = createGroupOnly;
1697
		util = new FilterTypeUtil();
1943
		util = new FilterTypeUtil();
1944
		ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter);
1945
		customfilterArgumentMap.put(ui.getID(), ui);
1946
		ui = new DefaultCustomFilterArgumentUI(parentShell, filter);
1947
		customfilterArgumentMap.put(ui.getID(), ui);
1698
	}
1948
	}
1699
1949
1700
	/*
1950
	/*
Lines 1712-1718 Link Here
1712
		Composite composite = new Composite(parent, SWT.NONE);
1962
		Composite composite = new Composite(parent, SWT.NONE);
1713
		GridLayout layout = new GridLayout();
1963
		GridLayout layout = new GridLayout();
1714
		layout.numColumns = 1;
1964
		layout.numColumns = 1;
1715
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1965
		layout.marginHeight = 0;
1716
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1966
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1717
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1967
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1718
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1968
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
Lines 1728-1734 Link Here
1728
		if (!filter.isUnderAGroupFilter()) {
1978
		if (!filter.isUnderAGroupFilter()) {
1729
			Composite topComposite = new Composite(composite, SWT.NONE);
1979
			Composite topComposite = new Composite(composite, SWT.NONE);
1730
			layout = new GridLayout();
1980
			layout = new GridLayout();
1731
			layout.numColumns = 2;
1981
			layout.numColumns = 1;
1732
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1982
			layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1733
			layout.marginWidth = 0;
1983
			layout.marginWidth = 0;
1734
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1984
			layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
Lines 1739-1748 Link Here
1739
			topComposite.setFont(font);
1989
			topComposite.setFont(font);
1740
1990
1741
			createModeArea(font, topComposite);
1991
			createModeArea(font, topComposite);
1992
			createIdArea(font, topComposite);
1742
			createTargetArea(font, topComposite);
1993
			createTargetArea(font, topComposite);
1994
			createInheritableArea(font, topComposite);
1995
		}
1996
		else
1997
			createIdArea(font, composite);
1998
		return composite;
1999
	}
2000
2001
	/* (non-Javadoc)
2002
	 * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite)
2003
	 */
2004
	protected Control createButtonBar(Composite parent) {
2005
		Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL);
2006
		label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false));
2007
2008
		Composite composite = new Composite(parent, SWT.NONE);
2009
    	GridLayout layout = new GridLayout();
2010
    	layout.marginWidth = 0;
2011
    	layout.marginHeight = 0;
2012
    	layout.horizontalSpacing = 0;
2013
    	composite.setLayout(layout);
2014
    	composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
2015
    	composite.setFont(parent.getFont());
2016
2017
		// create help control if needed
2018
        if (isHelpAvailable()) {
2019
        	Control helpControl = createHelpControl(composite);
2020
        	((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2021
		}
2022
        if (!createGroupOnly) {
2023
    		((GridLayout) composite.getLayout()).numColumns++;
2024
	        Button customizeButton = new Button(composite, SWT.PUSH);
2025
	        customizeButton.setText(NLS.bind(
2026
					IDEWorkbenchMessages.ResourceFilterPage_customize,
2027
					null));
2028
	        customizeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
2029
	        customizeButton.addSelectionListener(new SelectionAdapter() {
2030
				public void widgetSelected(SelectionEvent e) {
2031
					selectOtherFilterMatcher();
2032
				}
2033
	        });
2034
        }
2035
        
2036
        Control buttonSection = dialogCreateButtonBar(composite);
2037
        ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true;
2038
        return composite;
2039
	}
2040
2041
	private void selectOtherFilterMatcher() {
2042
		ListDialog dlg =
2043
			   new ListDialog(getShell());
2044
		dlg.setAddCancelButton(true);
2045
		dlg.setInput(Arrays.asList(FilterTypeUtil.getFilterNames(createGroupOnly)));
2046
		dlg.setInitialElementSelections(Arrays.asList(new String[] {FilterTypeUtil.getDescriptor(filter.getId()).getName()}));
2047
		dlg.setContentProvider(new IStructuredContentProvider() {
2048
			public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
2049
			public void dispose() {}
2050
			public Object[] getElements(Object inputElement) {
2051
				if (inputElement instanceof List)
2052
					return ((List) inputElement).toArray();
2053
				return null;
2054
			}
2055
		});
2056
		dlg.setLabelProvider(new org.eclipse.jface.viewers.LabelProvider());
2057
		dlg.setTitle(NLS.bind(
2058
				IDEWorkbenchMessages.ResourceFilterPage_customizeTitle,
2059
				null));
2060
		dlg.setMessage(NLS.bind(
2061
					IDEWorkbenchMessages.ResourceFilterPage_customizeMessage,
2062
					null));
2063
		if (dlg.open() == Window.OK) {
2064
			Object[] result = dlg.getResult();
2065
			if (result.length > 0) {
2066
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, result[0]);
2067
				if (filter.hasStringArguments())
2068
					filter.setArguments(new String());
2069
				setupPatternLine();
2070
				currentCustomFilterArgumentUI.selectionChanged();
2071
			}
1743
		}
2072
		}
1744
		createIdArea(font, composite);
2073
	}
1745
2074
2075
	private Control dialogCreateButtonBar(Composite parent) {
2076
		Composite composite = new Composite(parent, SWT.NONE);
2077
		// create a layout with spacing and margins appropriate for the font
2078
		// size.
2079
		GridLayout layout = new GridLayout();
2080
		layout.numColumns = 0; // this is incremented by createButton
2081
		layout.makeColumnsEqualWidth = true;
2082
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
2083
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
2084
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
2085
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
2086
		composite.setLayout(layout);
2087
		GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END
2088
				| GridData.VERTICAL_ALIGN_CENTER);
2089
		composite.setLayoutData(data);
2090
		composite.setFont(parent.getFont());
2091
		
2092
		// Add the buttons to the button bar.
2093
		createButtonsForButtonBar(composite);
1746
		return composite;
2094
		return composite;
1747
	}
2095
	}
1748
2096
Lines 1751-1772 Link Here
1751
	 * @param composite
2099
	 * @param composite
1752
	 */
2100
	 */
1753
	private void createInheritableArea(Font font, Composite composite) {
2101
	private void createInheritableArea(Font font, Composite composite) {
2102
		Composite inheritableComposite = createGroup(font, composite, NLS.bind(
2103
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2104
				null), false, false, 1);
2105
1754
		GridData data;
2106
		GridData data;
1755
		inherited = new Button(composite, SWT.CHECK);
2107
		inherited = new Button(inheritableComposite, SWT.CHECK);
1756
		inherited
2108
		inherited
1757
				.setText(NLS
2109
				.setText(NLS
1758
						.bind(
2110
						.bind(
1759
								IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable,
2111
								IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure,
1760
								null));
2112
								null));
1761
		inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2));
2113
		inherited.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 2));
1762
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2114
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1763
		data.horizontalSpan = 1;
2115
		data.horizontalSpan = 1;
1764
		inherited.setLayoutData(data);
2116
		inherited.setLayoutData(data);
1765
		inherited.setFont(font);
2117
		inherited.setFont(font);
1766
		inherited.addSelectionListener(new SelectionListener() {
2118
		inherited.addSelectionListener(new SelectionAdapter() {
1767
			public void widgetDefaultSelected(SelectionEvent e) {
1768
			}
1769
1770
			public void widgetSelected(SelectionEvent e) {
2119
			public void widgetSelected(SelectionEvent e) {
1771
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
2120
				FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE,
1772
						new Boolean(inherited.getSelection()));
2121
						new Boolean(inherited.getSelection()));
Lines 1780-1884 Link Here
1780
	 * @param font
2129
	 * @param font
1781
	 * @param composite
2130
	 * @param composite
1782
	 */
2131
	 */
1783
	private void createArgumentsArea(Font font, Composite composite) {
2132
	private void createIdArea(Font font, Composite composite) {
1784
		GridData data;
2133
		GridData data;
1785
		argumentsLabel = addLabel(composite, NLS.bind(
2134
		if (createGroupOnly) {
1786
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments,
2135
			idComposite = createGroup(font, composite, new String(),
1787
				null));
2136
					true, true, 1);
1788
		arguments = new Text(composite, SWT.SINGLE | SWT.BORDER);
2137
			idCombo = new Combo(idComposite, SWT.READ_ONLY);
1789
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2138
			idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly));
1790
		arguments.setLayoutData(data);
2139
			data = new GridData(SWT.FILL, SWT.CENTER, true, false);
1791
		arguments.setFont(font);
2140
			idCombo.setLayoutData(data);
1792
		arguments.addModifyListener(new ModifyListener() {
2141
			idCombo.setFont(font);
1793
			public void modifyText(ModifyEvent e) {
2142
			idCombo.addSelectionListener(new SelectionAdapter() {
1794
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS,
2143
				public void widgetSelected(SelectionEvent e) {
1795
						arguments.getText());
2144
					FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1796
			}
2145
							.getItem(idCombo.getSelectionIndex()));
1797
		});
2146
					if (filter.hasStringArguments())
1798
		if (filter.hasStringArguments())
2147
						filter.setArguments(new String());
1799
			arguments.setText((String) FilterTypeUtil.getValue(filter,
2148
					setupPatternLine();
1800
					FilterTypeUtil.ARGUMENTS));
2149
					currentCustomFilterArgumentUI.selectionChanged();
1801
		arguments.setEnabled(filter.hasStringArguments());
2150
				}
1802
		setArgumentLabelEnabled();
2151
			});
1803
2152
			idCombo.select(0);
1804
		TextContentAdapter contentAdapter= new TextContentAdapter();
2153
			selectComboItem(filter.getId());
1805
		FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2154
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1806
		fContentAssistField= new ContentAssistCommandAdapter(
2155
					.getItem(idCombo.getSelectionIndex()));
1807
				arguments,
2156
		}
1808
				contentAdapter,
2157
		else {
1809
				findProposer, 
2158
			idComposite = createGroup(font, composite, new String(),
1810
				null,
2159
					true, true, 1);
1811
				new char[] {'\\', '[', '('},
2160
		}
1812
				true);
2161
		argumentComposite = new Composite(idComposite, SWT.NONE);
1813
	}
2162
		setupPatternLine();
1814
1815
	/**
1816
	 * 
1817
	 */
1818
	private void setArgumentLabelEnabled() {
1819
		Color color = argumentsLabel.getDisplay().getSystemColor(
1820
				filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY);
1821
		argumentsLabel.setForeground(color);
1822
	}
2163
	}
2164
	
1823
2165
1824
	/**
2166
	ICustomFilterArgumentUI getUI(String descriptorID) {
1825
	 * @param font
2167
		ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID);
1826
	 * @param composite
2168
		if (result == null)
1827
	 */
2169
			return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui
1828
	private void createDescriptionArea(Font font, Composite composite) {
2170
		return result;
1829
		GridData data;
1830
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
1831
		description.setText(FilterTypeUtil.getDescriptor(filter.getId())
1832
				.getDescription());
1833
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
1834
		data.widthHint = 300;
1835
		data.heightHint = 40;
1836
		description.setLayoutData(data);
1837
		description.setFont(font);
1838
	}
2171
	}
1839
2172
	
1840
	/**
2173
	private void setupPatternLine() {
1841
	 * @param font
2174
		IFilterMatcherDescriptor descriptor;
1842
	 * @param composite
2175
		if (createGroupOnly) {
1843
	 */
2176
			String item = idCombo.getItem(idCombo.getSelectionIndex());
1844
	private void createIdArea(Font font, Composite composite) {
2177
			descriptor = FilterTypeUtil.getDescriptorByName(item);
1845
		GridData data;
2178
		}
1846
		Group idComposite = createGroup(font, composite, NLS.bind(
2179
		else
1847
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null),
2180
			descriptor = FilterTypeUtil.getDescriptor(filter.getId());
1848
				true);
2181
		Font font = idComposite.getFont();
1849
		idCombo = new Combo(idComposite, SWT.READ_ONLY);
2182
		ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId());
1850
		idCombo.setItems(FilterTypeUtil.getFilterNames(filter
2183
		if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) {
1851
				.getChildrenLimit() > 0));
2184
			currentCustomFilterArgumentUI.dispose();
1852
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2185
			currentCustomFilterArgumentUI = customFilterArgumentUI;
1853
		idCombo.setLayoutData(data);
2186
			currentCustomFilterArgumentUI.create(argumentComposite, font);
1854
		idCombo.setFont(font);
2187
			getShell().layout(true);
1855
		idCombo.addSelectionListener(new SelectionListener() {
2188
			getShell().redraw();
1856
			public void widgetDefaultSelected(SelectionEvent e) {
2189
		}
1857
			}
1858
1859
			public void widgetSelected(SelectionEvent e) {
1860
				FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo
1861
						.getItem(idCombo.getSelectionIndex()));
1862
				arguments.setEnabled(filter.hasStringArguments());
1863
				setArgumentLabelEnabled();
1864
				description.setText(FilterTypeUtil
1865
						.getDescriptor(filter.getId()).getDescription());
1866
				fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
1867
			}
1868
		});
1869
		selectComboItem(filter.getId());
1870
		Composite argumentComposite = new Composite(idComposite, SWT.NONE);
1871
		GridLayout layout = new GridLayout();
1872
		layout.numColumns = 2;
1873
		layout.marginWidth = 0;
1874
		argumentComposite.setLayout(layout);
1875
		data = new GridData(SWT.FILL, SWT.FILL, true, true);
1876
		argumentComposite.setLayoutData(data);
1877
		argumentComposite.setFont(font);
1878
		createArgumentsArea(font, argumentComposite);
1879
1880
		createDescriptionArea(font, idComposite);
1881
		fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID));
1882
	}
2190
	}
1883
2191
1884
	/**
2192
	/**
Lines 1904-1923 Link Here
1904
	 */
2212
	 */
1905
	private void createModeArea(Font font, Composite composite) {
2213
	private void createModeArea(Font font, Composite composite) {
1906
		GridData data;
2214
		GridData data;
1907
		Group modeComposite = createGroup(font, composite, NLS.bind(
2215
		Composite modeComposite = createGroup(font, composite, NLS.bind(
1908
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode,
2216
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, null), false, true, 2);
1909
				null), false);
1910
		String[] modes = FilterTypeUtil.getModes();
2217
		String[] modes = FilterTypeUtil.getModes();
1911
		includeButton = new Button(modeComposite, SWT.RADIO);
2218
		includeButton = new Button(modeComposite, SWT.RADIO);
1912
		includeButton.setText(modes[0]);
2219
		includeButton.setText(modes[0]);
1913
		includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0));
2220
		includeButton.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 0));
1914
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2221
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1915
		includeButton.setLayoutData(data);
2222
		includeButton.setLayoutData(data);
1916
		includeButton.setFont(font);
2223
		includeButton.setFont(font);
1917
		includeButton.addSelectionListener(new SelectionListener() {
2224
		includeButton.addSelectionListener(new SelectionAdapter() {
1918
			public void widgetDefaultSelected(SelectionEvent e) {
1919
			}
1920
1921
			public void widgetSelected(SelectionEvent e) {
2225
			public void widgetSelected(SelectionEvent e) {
1922
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2226
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1923
						new Integer(0));
2227
						new Integer(0));
Lines 1927-1940 Link Here
1927
				filter, FilterTypeUtil.MODE)).intValue() == 0);
2231
				filter, FilterTypeUtil.MODE)).intValue() == 0);
1928
		excludeButton = new Button(modeComposite, SWT.RADIO);
2232
		excludeButton = new Button(modeComposite, SWT.RADIO);
1929
		excludeButton.setText(modes[1]);
2233
		excludeButton.setText(modes[1]);
1930
		excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1));
2234
		excludeButton.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 1));
1931
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2235
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1932
		excludeButton.setLayoutData(data);
2236
		excludeButton.setLayoutData(data);
1933
		excludeButton.setFont(font);
2237
		excludeButton.setFont(font);
1934
		excludeButton.addSelectionListener(new SelectionListener() {
2238
		excludeButton.addSelectionListener(new SelectionAdapter() {
1935
			public void widgetDefaultSelected(SelectionEvent e) {
1936
			}
1937
1938
			public void widgetSelected(SelectionEvent e) {
2239
			public void widgetSelected(SelectionEvent e) {
1939
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
2240
				FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE,
1940
						new Integer(1));
2241
						new Integer(1));
Lines 1942-1948 Link Here
1942
		});
2243
		});
1943
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
2244
		excludeButton.setSelection(((Integer) FilterTypeUtil.getValue(
1944
				filter, FilterTypeUtil.MODE)).intValue() == 1);
2245
				filter, FilterTypeUtil.MODE)).intValue() == 1);
1945
		createInheritableArea(font, modeComposite);
1946
	}
2246
	}
1947
2247
1948
	/**
2248
	/**
Lines 1950-1967 Link Here
1950
	 * @param composite
2250
	 * @param composite
1951
	 * @return the group
2251
	 * @return the group
1952
	 */
2252
	 */
1953
	private Group createGroup(Font font, Composite composite, String text,
2253
	private Composite createGroup(Font font, Composite composite, String text,
1954
			boolean grabExcessVerticalSpace) {
2254
			boolean grabExcessVerticalSpace, boolean group, int columnCounts) {
1955
		GridLayout layout;
2255
		GridLayout layout;
1956
		GridData data;
2256
		GridData data;
1957
		Group modeComposite = new Group(composite, SWT.NONE);
2257
		Composite modeComposite;
1958
		modeComposite.setText(text);
2258
		if (group) { 
2259
			Group modeGroup = new Group(composite, SWT.NONE);
2260
			modeGroup.setText(text);
2261
			modeComposite = modeGroup;
2262
		} else {
2263
			modeComposite = new Composite(composite, SWT.NONE);
2264
		}
1959
		layout = new GridLayout();
2265
		layout = new GridLayout();
1960
		layout.numColumns = 1;
2266
		layout.numColumns = columnCounts;
1961
		layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN);
1962
		layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
1963
		layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING);
1964
		layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING);
1965
		modeComposite.setLayout(layout);
2267
		modeComposite.setLayout(layout);
1966
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
2268
		data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace);
1967
		modeComposite.setLayoutData(data);
2269
		modeComposite.setLayoutData(data);
Lines 1975-2028 Link Here
1975
	 */
2277
	 */
1976
	private void createTargetArea(Font font, Composite composite) {
2278
	private void createTargetArea(Font font, Composite composite) {
1977
		GridData data;
2279
		GridData data;
1978
		Group targetComposite = createGroup(font, composite, NLS.bind(
2280
		Composite targetComposite = createGroup(font, composite, new String(), false, true, 3);
1979
				IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets,
1980
				null), false);
1981
2281
1982
		String[] targets = FilterTypeUtil.getTargets();
2282
		String[] targets = FilterTypeUtil.getTargets();
1983
		filesButton = new Button(targetComposite, SWT.RADIO);
2283
		filesButton = new Button(targetComposite, SWT.RADIO);
1984
		filesButton.setText(targets[0]);
2284
		filesButton.setText(targets[0]);
1985
		filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0));
2285
		filesButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 0));
1986
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2286
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1987
		filesButton.setLayoutData(data);
2287
		filesButton.setLayoutData(data);
1988
		filesButton.setFont(font);
2288
		filesButton.setFont(font);
1989
2289
1990
		foldersButton = new Button(targetComposite, SWT.RADIO);
2290
		foldersButton = new Button(targetComposite, SWT.RADIO);
1991
		foldersButton.setText(targets[1]);
2291
		foldersButton.setText(targets[1]);
1992
		foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1));
2292
		foldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 1));
1993
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2293
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
1994
		foldersButton.setLayoutData(data);
2294
		foldersButton.setLayoutData(data);
1995
		foldersButton.setFont(font);
2295
		foldersButton.setFont(font);
1996
2296
1997
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
2297
		filesAndFoldersButton = new Button(targetComposite, SWT.RADIO);
1998
		filesAndFoldersButton.setText(targets[2]);
2298
		filesAndFoldersButton.setText(targets[2]);
1999
		filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2));
2299
		filesAndFoldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 2));
2000
		data = new GridData(SWT.FILL, SWT.CENTER, true, false);
2300
		data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2001
		filesAndFoldersButton.setLayoutData(data);
2301
		filesAndFoldersButton.setLayoutData(data);
2002
		filesAndFoldersButton.setFont(font);
2302
		filesAndFoldersButton.setFont(font);
2003
2303
2004
		filesButton.addSelectionListener(new SelectionListener() {
2304
		filesButton.addSelectionListener(new SelectionAdapter() {
2005
			public void widgetDefaultSelected(SelectionEvent e) {
2006
			}
2007
2008
			public void widgetSelected(SelectionEvent e) {
2305
			public void widgetSelected(SelectionEvent e) {
2009
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2306
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2010
						new Integer(0));
2307
						new Integer(0));
2011
			}
2308
			}
2012
		});
2309
		});
2013
		foldersButton.addSelectionListener(new SelectionListener() {
2310
		foldersButton.addSelectionListener(new SelectionAdapter() {
2014
			public void widgetDefaultSelected(SelectionEvent e) {
2015
			}
2016
2017
			public void widgetSelected(SelectionEvent e) {
2311
			public void widgetSelected(SelectionEvent e) {
2018
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2312
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2019
						new Integer(1));
2313
						new Integer(1));
2020
			}
2314
			}
2021
		});
2315
		});
2022
		filesAndFoldersButton.addSelectionListener(new SelectionListener() {
2316
		filesAndFoldersButton.addSelectionListener(new SelectionAdapter() {
2023
			public void widgetDefaultSelected(SelectionEvent e) {
2024
			}
2025
2026
			public void widgetSelected(SelectionEvent e) {
2317
			public void widgetSelected(SelectionEvent e) {
2027
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2318
				FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET,
2028
						new Integer(2));
2319
						new Integer(2));
Lines 2036-2053 Link Here
2036
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2327
				filter, FilterTypeUtil.TARGET)).intValue() == 2);
2037
	}
2328
	}
2038
2329
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) {
2330
	protected Control createContents(Composite parent) {
2052
		Control control = super.createContents(parent);
2331
		Control control = super.createContents(parent);
2053
		initialize();
2332
		initialize();
Lines 2082-2089 Link Here
2082
		if (filter.hasStringArguments()) {
2361
		if (filter.hasStringArguments()) {
2083
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2362
			IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId());
2084
			if (desc != null) {
2363
			if (desc != null) {
2085
				AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2086
				try {
2364
				try {
2365
					currentCustomFilterArgumentUI.validate();
2366
					AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter();
2087
					matcher.initialize(resource.getProject(), filter.getArguments());
2367
					matcher.initialize(resource.getProject(), filter.getArguments());
2088
				} catch (CoreException e) {
2368
				} catch (CoreException e) {
2089
					IWorkbenchWindow window = PlatformUI.getWorkbench()
2369
					IWorkbenchWindow window = PlatformUI.getWorkbench()
Lines 2099-2102 Link Here
2099
2379
2100
		super.okPressed();
2380
		super.okPressed();
2101
	}
2381
	}
2382
}
2383
2384
interface ICustomFilterArgumentUI {
2385
2386
	/**
2387
	 * @return the descriptor ID
2388
	 */
2389
	Object getID();
2390
2391
	/**
2392
	 * @param filter
2393
	 * @param fPlainStyler
2394
	 * @param fBoldStyler
2395
	 * @return the formatted StyledText
2396
	 */
2397
	StyledString formatStyledText(FilterCopy filter, Styler fPlainStyler,
2398
			Styler fBoldStyler);
2399
2400
	/**
2401
	 * @throws CoreException 
2402
	 * 
2403
	 */
2404
	void validate() throws CoreException;
2405
2406
	/**
2407
	 * 
2408
	 */
2409
	void selectionChanged();
2410
2411
	/**
2412
	 * @param argumentComposite
2413
	 * @param font
2414
	 */
2415
	void create(Composite argumentComposite, Font font);
2416
2417
	/**
2418
	 * 
2419
	 */
2420
	void dispose();
2421
	
2422
}
2423
2424
class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI {
2425
2426
	Shell shell;
2427
	FilterCopy filter;
2428
	protected Button argumentsCaseSensitive;
2429
	protected Button argumentsRegularExpresion;
2430
	protected Text arguments;
2431
	protected DateTime argumentsDate;
2432
	protected Combo argumentsBoolean;
2433
	protected Label argumentsLabel;
2434
	protected Label description;
2435
	protected ContentAssistCommandAdapter fContentAssistField;
2436
	protected Combo multiKey;
2437
	protected Combo multiOperator;
2438
	protected Composite multiArgumentComposite;
2439
	protected Composite stringArgumentComposite;
2440
	protected Composite attributeStringArgumentComposite;
2441
	protected Class intiantiatedKeyOperatorType = null;
2442
	protected TreeMap/* <String, String>*/ valueCache = new TreeMap();
2443
	
2444
	/**
2445
	 * @param parentShell
2446
	 * @param filter
2447
	 */
2448
	public MultiMatcherCustomFilterArgumentUI(Shell parentShell,
2449
			FilterCopy filter) {
2450
		this.shell = parentShell;
2451
		this.filter = filter;
2452
	}
2453
2454
	/* (non-Javadoc)
2455
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID()
2456
	 */
2457
	public Object getID() {
2458
		return MultiMatcher.ID;
2459
	}
2460
2461
	/* (non-Javadoc)
2462
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose()
2463
	 */
2464
	public void dispose() {
2465
		Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description};
2466
		for (int i = 0; i < list.length; i++) {
2467
			if (list[i] != null) {
2468
				list[i].dispose();
2469
			}
2470
		}
2471
		multiKey = null;
2472
		multiOperator = null;
2473
		multiArgumentComposite = null;
2474
		arguments = null;
2475
		argumentsLabel = null;
2476
		fContentAssistField = null;
2477
		intiantiatedKeyOperatorType = null;
2478
		stringArgumentComposite = null;
2479
		argumentsCaseSensitive = null;
2480
		argumentsRegularExpresion = null;
2481
		attributeStringArgumentComposite = null;
2482
		description = null;
2483
	}
2484
2485
	/* (non-Javadoc)
2486
	 * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font)
2487
	 */
2488
	public void create(Composite argumentComposite, Font font) {
2489
		shell = argumentComposite.getShell();
2490
		GridLayout layout = new GridLayout();
2491
		layout.numColumns = 3;
2492
		layout.marginWidth = 0;
2493
		argumentComposite.setLayout(layout);
2494
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
2495
		argumentComposite.setLayoutData(data);
2496
		argumentComposite.setFont(font);
2497
		createCustomArgumentsArea(font, argumentComposite);
2498
		argumentComposite.layout(true);
2499
		createDescriptionArea(font, argumentComposite);
2500
	}
2501
	
2502
	/**
2503
	 * @param font
2504
	 * @param composite
2505
	 */
2506
	private void createDescriptionArea(Font font, Composite composite) {
2507
		GridData data;
2508
		description = new Label(composite, SWT.LEFT | SWT.WRAP);
2509
		data = new GridData(SWT.FILL, SWT.BEGINNING, true, true);
2510
		data.widthHint = 300;
2511
		data.heightHint = 40;
2512
		data.horizontalSpan = 3;
2513
		description.setLayoutData(data);
2514
		description.setFont(font);
2515
		setupDescriptionText();
2516
	}
2517
2518
	private void setupDescriptionText() {
2519
		if (description != null) {
2520
			String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2521
			String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2522
			Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2523
			description.setText(new String());
2524
			if (selectedKeyOperatorType.equals(String.class)) {
2525
				if (!argumentsRegularExpresion.getSelection())
2526
					description.setText(NLS.bind(
2527
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null));
2528
			}
2529
			if (selectedKeyOperatorType.equals(Integer.class)) {
2530
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2531
					description.setText(NLS.bind(
2532
							IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_TimeInterval, null));
2533
				else
2534
				description.setText(NLS.bind(
2535
						IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null));
2536
			}
2537
		}
2538
	}
2539
	
2540
	private void createCustomArgumentsArea(Font font, Composite composite) {
2541
		GridData data;
2542
		multiKey = new Combo(composite, SWT.READ_ONLY);
2543
		multiKey.setItems(getMultiMatcherKeys());
2544
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2545
		multiKey.setLayoutData(data);
2546
		multiKey.setFont(font);
2547
		multiKey.addSelectionListener(new SelectionAdapter() {
2548
			public void widgetSelected(SelectionEvent e) {
2549
				setupMultiOperatorAndField(true);
2550
				storeMultiSelection();
2551
			}
2552
		});
2553
2554
		multiOperator = new Combo(composite, SWT.READ_ONLY);
2555
		data = new GridData(SWT.LEFT, SWT.TOP, false, false);
2556
		multiOperator.setLayoutData(data);
2557
		multiOperator.setFont(font);
2558
		multiOperator.addSelectionListener(new SelectionAdapter() {
2559
			public void widgetSelected(SelectionEvent e) {
2560
				setupMultiOperatorAndField(false);
2561
				storeMultiSelection();
2562
			}
2563
		});
2564
		
2565
		multiArgumentComposite = new Composite(composite, SWT.NONE);
2566
		
2567
		GridLayout layout = new GridLayout();
2568
		layout.numColumns = 1;
2569
		layout.marginWidth = 0;
2570
		layout.horizontalSpacing = 0;
2571
		layout.verticalSpacing = 0;
2572
		layout.marginBottom = 0;
2573
		layout.marginHeight = 0;
2574
		multiArgumentComposite.setLayout(layout);
2575
		data = new GridData(SWT.FILL, SWT.TOP, true, true);
2576
		multiArgumentComposite.setLayoutData(data);
2577
		multiArgumentComposite.setFont(font);
2578
2579
		MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2580
		String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key);
2581
		int index = multiKey.indexOf(local);
2582
		if (index != -1)
2583
			multiKey.select(index);
2584
		else
2585
			multiKey.select(0);
2586
		
2587
		setupMultiOperatorAndField(true);
2588
	}
2589
2590
	private void setupMultiOperatorAndField(boolean updateOperator) {
2591
		boolean isUsingRegularExpression = false;
2592
		String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText());
2593
		if (updateOperator) {
2594
			String[] operators = getLocalOperatorsForKey(selectedKey);
2595
			multiOperator.setItems(operators);
2596
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2597
			String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator);
2598
			int index = multiOperator.indexOf(local);
2599
			if (index != -1)
2600
				multiOperator.select(index);
2601
			else
2602
				multiOperator.select(0);
2603
		}
2604
		String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText());
2605
		
2606
		Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator);
2607
		
2608
		if (intiantiatedKeyOperatorType != null) {
2609
			if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType))
2610
				return;
2611
			if (arguments != null) {
2612
				arguments.dispose();
2613
				arguments = null;
2614
			}
2615
			if (attributeStringArgumentComposite != null) {
2616
				attributeStringArgumentComposite.dispose();
2617
				attributeStringArgumentComposite = null;
2618
			}
2619
			if (stringArgumentComposite != null) {
2620
				stringArgumentComposite.dispose();
2621
				stringArgumentComposite = null;
2622
			}
2623
			if (argumentsBoolean != null) {
2624
				argumentsBoolean.dispose();
2625
				argumentsBoolean = null;
2626
			}
2627
			if (argumentsDate != null) {
2628
				argumentsDate.dispose();
2629
				argumentsDate = null;
2630
			}
2631
			if (argumentsRegularExpresion != null) {
2632
				argumentsRegularExpresion.dispose();
2633
				argumentsRegularExpresion = null;
2634
			}
2635
			if (argumentsCaseSensitive != null) {
2636
				argumentsCaseSensitive.dispose();
2637
				argumentsCaseSensitive = null;
2638
			}
2639
			fContentAssistField = null;
2640
			MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2641
			valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern);
2642
			argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName());
2643
			if (argument.pattern == null)
2644
				argument.pattern = new String();
2645
			filter.setArguments(MultiMatcher.encodeArguments(argument));
2646
		}
2647
		if (selectedKeyOperatorType.equals(String.class)) {
2648
			stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE);
2649
			
2650
			GridData data;
2651
			GridLayout layout = new GridLayout();
2652
			layout.numColumns = 2;
2653
			layout.marginWidth = 0;
2654
			layout.horizontalSpacing = 0;
2655
			layout.verticalSpacing = 0;
2656
			layout.marginBottom = 0;
2657
			layout.marginHeight = 0;
2658
			stringArgumentComposite.setLayout(layout);
2659
			data = new GridData(SWT.FILL, SWT.TOP, true, true);
2660
			stringArgumentComposite.setLayoutData(data);
2661
			stringArgumentComposite.setFont(multiArgumentComposite.getFont());
2662
2663
			arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER);
2664
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2665
			data.minimumWidth = 100;
2666
			arguments.setLayoutData(data);
2667
			arguments.setFont(stringArgumentComposite.getFont());
2668
	
2669
			attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE);
2670
			
2671
			layout = new GridLayout();
2672
			layout.numColumns = 1;
2673
			layout.marginWidth = 0;
2674
			layout.horizontalSpacing = 0;
2675
			layout.verticalSpacing = 0;
2676
			layout.marginBottom = 0;
2677
			layout.marginHeight = 0;
2678
			attributeStringArgumentComposite.setLayout(layout);
2679
			data = new GridData(SWT.FILL, SWT.TOP, false, true);
2680
			attributeStringArgumentComposite.setLayoutData(data);
2681
			attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont());
2682
2683
			argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK);
2684
			argumentsCaseSensitive.setText(NLS.bind(
2685
					IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null));
2686
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2687
			data.minimumWidth = 100;
2688
			argumentsCaseSensitive.setLayoutData(data);
2689
			argumentsCaseSensitive.setFont(stringArgumentComposite.getFont());
2690
2691
			argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK);
2692
			argumentsRegularExpresion.setText(NLS.bind(
2693
					IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null));
2694
			data = new GridData(SWT.FILL, SWT.CENTER, false, false);
2695
			data.minimumWidth = 100;
2696
			argumentsRegularExpresion.setLayoutData(data);
2697
			argumentsRegularExpresion.setFont(stringArgumentComposite.getFont());
2698
2699
			if (filter.hasStringArguments()) {
2700
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2701
				arguments.setText(argument.pattern);
2702
				isUsingRegularExpression = argument.regularExpression;
2703
				argumentsCaseSensitive.setSelection(argument.caseSensitive);
2704
				argumentsRegularExpresion.setSelection(argument.regularExpression);
2705
			}
2706
2707
			arguments.addModifyListener(new ModifyListener() {
2708
				public void modifyText(ModifyEvent e) {
2709
					storeMultiSelection();
2710
				}
2711
			});
2712
			argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() {
2713
				public void widgetSelected(SelectionEvent e) {
2714
					setupDescriptionText();
2715
					storeMultiSelection();
2716
					if (fContentAssistField != null)
2717
						fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection());
2718
				}
2719
			});
2720
			argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() {
2721
				public void widgetSelected(SelectionEvent e) {
2722
					storeMultiSelection();
2723
				}
2724
			});
2725
2726
			TextContentAdapter contentAdapter= new TextContentAdapter();
2727
			FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true);
2728
			fContentAssistField= new ContentAssistCommandAdapter(
2729
					arguments,
2730
					contentAdapter,
2731
					findProposer, 
2732
					null,
2733
					new char[] {'\\', '[', '('},
2734
					true);
2735
		}
2736
		if (selectedKeyOperatorType.equals(Integer.class)) {
2737
			GridData data;
2738
			arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER);
2739
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2740
			data.minimumWidth = 100;
2741
			arguments.setLayoutData(data);
2742
			arguments.setFont(multiArgumentComposite.getFont());
2743
2744
			if (filter.hasStringArguments()) {
2745
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2746
				if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED))
2747
					arguments.setText(convertToEditableTimeInterval(argument.pattern));
2748
				else
2749
					arguments.setText(convertToEditableLength(argument.pattern));
2750
			}
2751
			
2752
			arguments.addModifyListener(new ModifyListener() {
2753
				public void modifyText(ModifyEvent e) {
2754
					storeMultiSelection();
2755
				}
2756
			});
2757
		}
2758
		if (selectedKeyOperatorType.equals(Date.class)) {
2759
			GridData data;
2760
			argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM);
2761
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2762
			argumentsDate.setLayoutData(data);
2763
			argumentsDate.setFont(multiArgumentComposite.getFont());
2764
			argumentsDate.addSelectionListener(new SelectionAdapter() {
2765
				public void widgetSelected(SelectionEvent e) {
2766
					storeMultiSelection();
2767
				}
2768
			});
2769
			if (filter.hasStringArguments()) {
2770
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2771
				Date date; 
2772
				Calendar calendar = Calendar.getInstance();
2773
				try {
2774
					date = new Date(Long.parseLong(argument.pattern));
2775
					calendar.setTime(date);
2776
				} catch (NumberFormatException e1) {
2777
					date = new Date();
2778
					calendar.setTime(date);
2779
					argument.pattern = Long.toString(calendar.getTimeInMillis());
2780
				}
2781
				argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH));
2782
				argumentsDate.setMonth(calendar.get(Calendar.MONTH));
2783
				argumentsDate.setYear(calendar.get(Calendar.YEAR));
2784
			}
2785
		}
2786
		if (selectedKeyOperatorType.equals(Boolean.class)) {
2787
			GridData data;
2788
			argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY);
2789
			data = new GridData(SWT.FILL, SWT.TOP, true, false);
2790
			argumentsBoolean.setLayoutData(data);
2791
			argumentsBoolean.setFont(multiArgumentComposite.getFont());
2792
			argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())});
2793
			argumentsBoolean.addSelectionListener(new SelectionAdapter() {
2794
				public void widgetSelected(SelectionEvent e) {
2795
					storeMultiSelection();
2796
				}
2797
			});
2798
			if (filter.hasStringArguments()) {
2799
				MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments());
2800
				if (argument.pattern.length() == 0)
2801
					argumentsBoolean.select(0);
2802
				else
2803
					argumentsBoolean.select(Boolean.valueOf(argument.pattern).booleanValue() ? 0:1);
2804
			}
2805
		}
2806
		multiArgumentComposite.layout(true);
2807
		intiantiatedKeyOperatorType = selectedKeyOperatorType;
2808
		
2809
		if (fContentAssistField != null)
2810
			fContentAssistField.setEnabled(isUsingRegularExpression);
2811
2812
		shell.layout(true);
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
			MultiMatcher.Argument argument = new MultiMatcher.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(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.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 = MultiMatcher.encodeArguments(argument);
2927
			FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument);
2928
		}
2929
	}
2930
2931
	private String[] getLocalOperatorsForKey(String key) {
2932
		String [] operators = MultiMatcher.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(MultiMatcher.KEY_NAME));
2942
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_PROPJECT_RELATIVE_PATH));
2943
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LOCATION));
2944
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LAST_MODIFIED));
2945
		if (MultiMatcher.supportCreatedKey())
2946
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_CREATED));
2947
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LENGTH));
2948
		list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_READONLY));
2949
		if (!Platform.getOS().equals(Platform.OS_WIN32))
2950
			list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.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
			MultiMatcher.Argument argument = new MultiMatcher.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(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.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
		MultiMatcher.Argument argument = MultiMatcher.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 = MultiMatcher.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(MultiMatcher.KEY_LAST_MODIFIED) || argument.key.equals(MultiMatcher.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_columnFilterTarget,
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
			{MultiMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName},
3209
			{MultiMatcher.KEY_PROPJECT_RELATIVE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyProjectRelativePath},
3210
			{MultiMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation},
3211
			{MultiMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified},
3212
			{MultiMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated},
3213
			{MultiMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength},
3214
			{MultiMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly},
3215
			{MultiMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink},
3216
			{MultiMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter},
3217
			{MultiMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore},
3218
			{MultiMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals},
3219
			{MultiMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches},
3220
			{MultiMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan},
3221
			{MultiMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan},
3222
			{MultiMatcher.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/MultiMatcher.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 MultiMatcher 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 MultiMatcher() {
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