Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 164341 Details for
Bug 301820
Resource Filters UI is not intuitive
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Patch
patch.txt (text/plain), 123.62 KB, created by
Serge Beauchamp
on 2010-04-09 03:57:36 EDT
(
hide
)
Description:
Patch
Filename:
MIME Type:
Creator:
Serge Beauchamp
Created:
2010-04-09 03:57:36 EDT
Size:
123.62 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.ui.ide >Index: plugin.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.properties,v >retrieving revision 1.155 >diff -u -r1.155 plugin.properties >--- plugin.properties 4 Feb 2010 19:44:08 -0000 1.155 >+++ plugin.properties 9 Apr 2010 07:53:42 -0000 >@@ -296,10 +296,12 @@ > > filterProvider.description = * = any string, ? = any character, \\ = escape literals: * ? \\ > filterProvider.name = String Matcher >-orFilterProvider.name = OR group >+orFilterProvider.name =OR > orFilterProvider.description = Allows grouping others filters with the OR logical preposition >-andFilterProvider.name = AND group >+andFilterProvider.name =AND > andFilterProvider.description = Allows grouping others filters with the AND logical preposition >-notFilterProvider.name = NOT group >+notFilterProvider.name =NOT > notFilterProvider.description = Allows grouping others filters with the NOT logical preposition > installationPage.feature.name = Features >+multiFilterProvider.name = Default >+multiFilterProvider.description = Match many attributes of files and folders >Index: plugin.xml >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/plugin.xml,v >retrieving revision 1.302 >diff -u -r1.302 plugin.xml >--- plugin.xml 8 Mar 2010 21:48:22 -0000 1.302 >+++ plugin.xml 9 Apr 2010 07:53:44 -0000 >@@ -2328,6 +2328,14 @@ > name="%notFilterProvider.name" > ordering="first"> > </filterMatcher> >+ <filterMatcher >+ argumentType="string" >+ class="org.eclipse.ui.internal.ide.misc.MultiMatcher" >+ description="%multiFilterProvider.description" >+ id="org.eclipse.ui.ide.multiFilter" >+ name="%multiFilterProvider.name" >+ ordering="first"> >+ </filterMatcher> > </extension> > <extension > point="org.eclipse.ui.installationPages"> >Index: src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java,v >retrieving revision 1.82 >diff -u -r1.82 IDEWorkbenchMessages.java >--- src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 17 Mar 2010 20:24:53 -0000 1.82 >+++ src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java 9 Apr 2010 07:53:44 -0000 >@@ -53,6 +53,7 @@ > public static String ResourceFilterPage_title; > public static String ResourceFilterPage_noResource; > public static String ResourceFilterPage_addButtonLabel; >+ public static String ResourceFilterPage_addGroupButtonLabel; > public static String ResourceFilterPage_editButtonLabel; > public static String ResourceFilterPage_removeButtonLabel; > public static String ResourceFilterPage_upButtonLabel; >@@ -60,9 +61,21 @@ > public static String ResourceFilterPage_addNewFilterTitle; > public static String ResourceFilterPage_columnFilterID; > public static String ResourceFilterPage_columnFilterMode; >+ public static String ResourceFilterPage_columnFilterDescription; > public static String ResourceFilterPage_columnFilterTargets; > public static String ResourceFilterPage_columnFilterInheritable; >- public static String ResourceFilterPage_columnFilterArguments; >+ public static String ResourceFilterPage_columnFilterTarget; >+ public static String ResourceFilterPage_applyRecursivelyToFolderStructure; >+ public static String ResourceFilterPage_customize; >+ public static String ResourceFilterPage_customizeTitle; >+ public static String ResourceFilterPage_customizeMessage; >+ public static String ResourceFilterPage_caseSensitive; >+ public static String ResourceFilterPage_regularExpression; >+ public static String ResourceFilterPage_multiMatcher_Matcher; >+ public static String ResourceFilterPage_multiMatcher_FileLength; >+ public static String ResourceFilterPage_multiMatcher_TimeInterval; >+ public static String ResourceFilterPage_multiMatcher_InvalidFileLength; >+ public static String ResourceFilterPage_multiMatcher_InvalidTimeInterval; > public static String ResourceFilterPage_includeOnly; > public static String ResourceFilterPage_excludeAll; > public static String ResourceFilterPage_includeOnlyColumn; >@@ -77,6 +90,28 @@ > public static String ResourceFilterPage_invalidFilterArgument; > public static String ResourceFilterPage_description; > public static String ResourceFilterPage_addSubFilterActionLabel; >+ public static String ResourceFilterPage_addSubFilterGroupActionLabel; >+ public static String ResourceFilterPage_removeFilterActionLabel; >+ public static String ResourceFilterPage_editFilterActionLabel; >+ public static String ResourceFilterPage_multiKeyName; >+ public static String ResourceFilterPage_multiKeyProjectRelativePath; >+ public static String ResourceFilterPage_multiKeyLocation; >+ public static String ResourceFilterPage_multiKeyLastModified; >+ public static String ResourceFilterPage_multiKeyCreated; >+ public static String ResourceFilterPage_multiKeyLength; >+ public static String ResourceFilterPage_multiKeyReadOnly; >+ public static String ResourceFilterPage_multiKeySymLink; >+ public static String ResourceFilterPage_multiEquals; >+ public static String ResourceFilterPage_multiMatches; >+ public static String ResourceFilterPage_multiLargerThan; >+ public static String ResourceFilterPage_multiSmallerThan; >+ public static String ResourceFilterPage_multiBefore; >+ public static String ResourceFilterPage_multiAfter; >+ public static String ResourceFilterPage_multiWithin; >+ public static String ResourceFilterPage_true; >+ public static String ResourceFilterPage_false; >+ public static String ResourceFilterPage_columnFilterTypeLabel; >+ > // > // > // Copies from org.eclipse.ui.workbench >Index: src/org/eclipse/ui/internal/ide/messages.properties >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties,v >retrieving revision 1.197 >diff -u -r1.197 messages.properties >--- src/org/eclipse/ui/internal/ide/messages.properties 7 Apr 2010 15:31:12 -0000 1.197 >+++ src/org/eclipse/ui/internal/ide/messages.properties 9 Apr 2010 07:53:45 -0000 >@@ -573,20 +573,34 @@ > 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. > ResourceFilterPage_noResource=Resource information is not available for the current selection. > ResourceFilterPage_addButtonLabel=&Add... >+ResourceFilterPage_addGroupButtonLabel=Add &Group... > ResourceFilterPage_editButtonLabel=Edi&t... > ResourceFilterPage_removeButtonLabel=&Remove > ResourceFilterPage_upButtonLabel=Up > ResourceFilterPage_downButtonLabel=Down > ResourceFilterPage_addNewFilterTitle=Add new resource filter > ResourceFilterPage_columnFilterID=T&ype >+ResourceFilterPage_columnFilterTypeLabel=Match > ResourceFilterPage_columnFilterMode=Mode >-ResourceFilterPage_columnFilterTargets=Target >-ResourceFilterPage_columnFilterInheritable=In&heritable >-ResourceFilterPage_columnFilterArguments=&Pattern >+ResourceFilterPage_columnFilterDescription=Description >+ResourceFilterPage_columnFilterTargets=Object >+ResourceFilterPage_columnFilterInheritable=Recursive >+ResourceFilterPage_columnFilterTarget=&Pattern >+ResourceFilterPage_applyRecursivelyToFolderStructure=Apply &recursively to folder structure >+ResourceFilterPage_customize=Advanced... >+ResourceFilterPage_customizeTitle=Filter Matcher Selection >+ResourceFilterPage_customizeMessage=Select resource filter matcher: >+ResourceFilterPage_caseSensitive=&Case sensitive >+ResourceFilterPage_regularExpression=Re&gular expression >+ResourceFilterPage_multiMatcher_Matcher=(* = any string, ? = any character, \ = escape for literals: * ? \) >+ResourceFilterPage_multiMatcher_FileLength=(* = bytes, *k = kilobytes, *m = megabytes, *g = gigabytes) >+ResourceFilterPage_multiMatcher_TimeInterval= (*s = seconds, *m = minutes, *h = hours, *d = days) >+ResourceFilterPage_multiMatcher_InvalidFileLength=Invalid file length syntax: {0} >+ResourceFilterPage_multiMatcher_InvalidTimeInterval=Invalid time interval syntax: {0} > ResourceFilterPage_includeOnly=&Include > ResourceFilterPage_excludeAll=&Exclude >-ResourceFilterPage_includeOnlyColumn=Include >-ResourceFilterPage_excludeAllColumn=Exclude >+ResourceFilterPage_includeOnlyColumn=Include only: >+ResourceFilterPage_excludeAllColumn=Exclude all: > ResourceFilterPage_filesAndFolders=Files &and folders > ResourceFilterPage_files=&Files > ResourceFilterPage_folders=F&olders >@@ -596,7 +610,27 @@ > ResourceFilterPage_editFilterDialogTitle=Edit Resource Filter > ResourceFilterPage_invalidFilterArgument=Invalid Pattern > ResourceFilterPage_description=Description >-ResourceFilterPage_addSubFilterActionLabel=Add Condition... >+ResourceFilterPage_addSubFilterActionLabel=&Add... >+ResourceFilterPage_addSubFilterGroupActionLabel=Add &Group... >+ResourceFilterPage_removeFilterActionLabel=&Remove >+ResourceFilterPage_editFilterActionLabel=&Edit >+ResourceFilterPage_multiKeyName=Name >+ResourceFilterPage_multiKeyProjectRelativePath=Project Relative Path >+ResourceFilterPage_multiKeyLocation=Location >+ResourceFilterPage_multiKeyLastModified=Last Modified >+ResourceFilterPage_multiKeyCreated=Date Created >+ResourceFilterPage_multiKeyLength=File Length >+ResourceFilterPage_multiKeyReadOnly=Read Only >+ResourceFilterPage_multiKeySymLink=Symbolic Link >+ResourceFilterPage_multiEquals=equals >+ResourceFilterPage_multiMatches=matches >+ResourceFilterPage_multiLargerThan=is larger than >+ResourceFilterPage_multiSmallerThan=is smaller than >+ResourceFilterPage_multiBefore=is before >+ResourceFilterPage_multiAfter=is after >+ResourceFilterPage_multiWithin=is within >+ResourceFilterPage_true=true >+ResourceFilterPage_false=false > ResourceInfo_folder = Folder > ResourceInfo_project = Project > ResourceInfo_linkedFile = Linked File >Index: src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java,v >retrieving revision 1.21 >diff -u -r1.21 ResourceFilterGroup.java >--- src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java 30 Mar 2010 19:48:32 -0000 1.21 >+++ src/org/eclipse/ui/internal/ide/dialogs/ResourceFilterGroup.java 9 Apr 2010 07:53:46 -0000 >@@ -16,9 +16,17 @@ > import java.io.DataInputStream; > import java.io.DataOutputStream; > import java.io.IOException; >+import java.lang.reflect.Field; >+import java.text.DateFormat; >+import java.util.ArrayList; > import java.util.Arrays; >+import java.util.Calendar; >+import java.util.Comparator; >+import java.util.Date; > import java.util.Iterator; > import java.util.LinkedList; >+import java.util.List; >+import java.util.TreeMap; > > import org.eclipse.core.internal.resources.FilterDescriptor; > import org.eclipse.core.resources.FileInfoMatcherDescription; >@@ -32,31 +40,41 @@ > import org.eclipse.core.runtime.Assert; > import org.eclipse.core.runtime.CoreException; > import org.eclipse.core.runtime.IPath; >+import org.eclipse.core.runtime.IStatus; > import org.eclipse.core.runtime.NullProgressMonitor; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; > import org.eclipse.jface.action.Action; > import org.eclipse.jface.action.MenuManager; >+import org.eclipse.jface.action.Separator; > import org.eclipse.jface.dialogs.Dialog; > import org.eclipse.jface.dialogs.ErrorDialog; > import org.eclipse.jface.dialogs.IDialogConstants; > import org.eclipse.jface.dialogs.TrayDialog; > import org.eclipse.jface.fieldassist.TextContentAdapter; >+import org.eclipse.jface.layout.TreeColumnLayout; >+import org.eclipse.jface.resource.CompositeImageDescriptor; > import org.eclipse.jface.resource.ImageDescriptor; > import org.eclipse.jface.resource.JFaceResources; > import org.eclipse.jface.text.FindReplaceDocumentAdapterContentProposalProvider; > import org.eclipse.jface.viewers.CellEditor; > import org.eclipse.jface.viewers.CheckboxCellEditor; >+import org.eclipse.jface.viewers.ColumnWeightData; > import org.eclipse.jface.viewers.ComboBoxCellEditor; > import org.eclipse.jface.viewers.ICellModifier; >-import org.eclipse.jface.viewers.ILabelProviderListener; > import org.eclipse.jface.viewers.ISelection; > import org.eclipse.jface.viewers.ISelectionChangedListener; >+import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.IStructuredSelection; >-import org.eclipse.jface.viewers.ITableLabelProvider; > import org.eclipse.jface.viewers.ITreeContentProvider; > import org.eclipse.jface.viewers.SelectionChangedEvent; >+import org.eclipse.jface.viewers.StyledCellLabelProvider; >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.StyledString.Styler; > import org.eclipse.jface.viewers.TextCellEditor; > import org.eclipse.jface.viewers.TreeViewer; > import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerCell; > import org.eclipse.jface.viewers.ViewerDropAdapter; > import org.eclipse.jface.window.Window; > import org.eclipse.osgi.util.NLS; >@@ -73,32 +91,41 @@ > import org.eclipse.swt.events.ModifyListener; > import org.eclipse.swt.events.MouseEvent; > import org.eclipse.swt.events.MouseListener; >+import org.eclipse.swt.events.SelectionAdapter; > import org.eclipse.swt.events.SelectionEvent; >-import org.eclipse.swt.events.SelectionListener; > import org.eclipse.swt.graphics.Color; > import org.eclipse.swt.graphics.Font; >+import org.eclipse.swt.graphics.FontData; > import org.eclipse.swt.graphics.FontMetrics; > import org.eclipse.swt.graphics.GC; > import org.eclipse.swt.graphics.Image; >+import org.eclipse.swt.graphics.Point; >+import org.eclipse.swt.graphics.TextStyle; > import org.eclipse.swt.layout.GridData; > import org.eclipse.swt.layout.GridLayout; > import org.eclipse.swt.widgets.Button; > import org.eclipse.swt.widgets.Combo; > import org.eclipse.swt.widgets.Composite; > import org.eclipse.swt.widgets.Control; >+import org.eclipse.swt.widgets.DateTime; >+import org.eclipse.swt.widgets.Display; >+import org.eclipse.swt.widgets.Event; > import org.eclipse.swt.widgets.Group; > import org.eclipse.swt.widgets.Label; > import org.eclipse.swt.widgets.Shell; > import org.eclipse.swt.widgets.TableItem; > import org.eclipse.swt.widgets.Text; > import org.eclipse.swt.widgets.TreeColumn; >+import org.eclipse.swt.widgets.Widget; > import org.eclipse.ui.IWorkbenchWindow; > import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.dialogs.ListDialog; > import org.eclipse.ui.fieldassist.ContentAssistCommandAdapter; > import org.eclipse.ui.ide.dialogs.UIResourceFilterDescription; > import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; > import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; > import org.eclipse.ui.internal.ide.IIDEHelpContextIds; >+import org.eclipse.ui.internal.ide.misc.MultiMatcher; > import org.eclipse.ui.plugin.AbstractUIPlugin; > > /** >@@ -108,26 +135,40 @@ > public class ResourceFilterGroup { > > private Button addButton = null; >+ private Button addGroupButton = null; > private Button removeButton = null; > private Button upButton = null; > private Button downButton = null; > private Button editButton = null; > > private TreeViewer filterView; >+ private TreeContentProvider filterViewContentProvider; > private Filters filters; > private UIResourceFilterDescription[] initialFilters = new UIResourceFilterDescription[0]; > private LabelProvider labelProvider; >+ private Font boldFont; >+ private Font plainFont; > private Image checkIcon = null; >- >+ private Image fileIcon = null; >+ private Image folderIcon = null; >+ private Image fileFolderIcon = null; >+ private Image includeIcon = null; >+ private Image excludeIcon = null; >+ private Image inheritableIcon = null; >+ private Image fileAloneIcon = null; >+ private Image folderAloneIcon = null; >+ private Image fileFolderAloneIcon = null; >+ private Image fileInheritableIcon = null; >+ private Image folderInheritableIcon = null; >+ private Image fileFolderInheritableIcon = null; > private boolean tableViewCellEditorAdequatlyUsable = false; >- private boolean allowReordering = false; >- >- // parent shell > private Shell shell; >- > private IContainer nonExistantResource = getNonExistantResource(); > private IContainer resource = nonExistantResource; > >+ // this is a work-around for the TreeView widget that does not draw the text according to each row's image width >+ private String textPrefix = new String(); >+ > /** > * > */ >@@ -137,6 +178,103 @@ > "$nl$/icons/full/obj16/header_complete.gif"); //$NON-NLS-1$ > if (descriptor != null) > checkIcon = descriptor.createImage(); >+ >+ >+ ImageDescriptor fileIconDescriptor = AbstractUIPlugin >+ .imageDescriptorFromPlugin(IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/fileType_filter.gif"); //$NON-NLS-1$ >+ if (fileIconDescriptor != null) >+ fileIcon = fileIconDescriptor.createImage(); >+ >+ ImageDescriptor folderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >+ IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/folderType_filter.gif"); //$NON-NLS-1$ >+ if (folderIconDescriptor != null) >+ folderIcon = folderIconDescriptor.createImage(); >+ >+ ImageDescriptor fileFolderIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >+ IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/fileFolderType_filter.gif"); //$NON-NLS-1$ >+ if (fileFolderIconDescriptor != null) >+ fileFolderIcon = fileFolderIconDescriptor.createImage(); >+ >+ descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >+ IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/includeMode_filter.gif"); //$NON-NLS-1$ >+ if (descriptor != null) >+ includeIcon = descriptor.createImage(); >+ >+ descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >+ IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/excludeMode_filter.gif"); //$NON-NLS-1$ >+ if (descriptor != null) >+ excludeIcon = descriptor.createImage(); >+ >+ ImageDescriptor inheritableIconDescriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >+ IDEWorkbenchPlugin.IDE_WORKBENCH, >+ "$nl$/icons/full/obj16/inheritable_filter.gif"); //$NON-NLS-1$ >+ if (inheritableIconDescriptor != null) >+ inheritableIcon = inheritableIconDescriptor.createImage(); >+ >+ CompositeImageDescriptor desc = new AlignedCompositeImageDescriptor(null, fileIconDescriptor); >+ fileAloneIcon = desc.createImage(); >+ >+ desc = new AlignedCompositeImageDescriptor(null, folderIconDescriptor); >+ folderAloneIcon = desc.createImage(); >+ >+ desc = new AlignedCompositeImageDescriptor(null, fileFolderIconDescriptor); >+ fileFolderAloneIcon = desc.createImage(); >+ >+ desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileIconDescriptor); >+ fileInheritableIcon = desc.createImage(); >+ >+ desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, folderIconDescriptor); >+ folderInheritableIcon = desc.createImage(); >+ >+ desc = new AlignedCompositeImageDescriptor(inheritableIconDescriptor, fileFolderIconDescriptor); >+ fileFolderInheritableIcon = desc.createImage(); >+ } >+ >+ private static int AlignedCompositeImageDescriptor_SPACE = 4; >+ >+ private class AlignedCompositeImageDescriptor extends CompositeImageDescriptor { >+ >+ >+ ImageDescriptor first, second; >+ AlignedCompositeImageDescriptor(ImageDescriptor first, ImageDescriptor second) { >+ this.first = first; >+ this.second = second; >+ } >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.resource.CompositeImageDescriptor#drawCompositeImage(int, int) >+ */ >+ protected void drawCompositeImage(int width, int height) { >+ if (first != null) { >+ drawImage(first.getImageData(), 0, 0); >+ drawImage(second.getImageData(), first.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0); >+ } >+ else >+ drawImage(second.getImageData(), second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, 0); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.resource.CompositeImageDescriptor#getSize() >+ */ >+ protected Point getSize() { >+ if (first != null) >+ return new Point(first.getImageData().width + second.getImageData().width + AlignedCompositeImageDescriptor_SPACE, >+ Math.max(first.getImageData().height, second.getImageData().height)); >+ return new Point(second.getImageData().width * 2 + AlignedCompositeImageDescriptor_SPACE, second.getImageData().height); >+ } >+ >+ } >+ >+ Image getImage(String string, int i) { >+ if (string.equals(FilterTypeUtil.MODE)) >+ return new Image[] { includeIcon, excludeIcon, inheritableIcon }[i]; >+ if (string.equals(FilterTypeUtil.TARGET)) >+ return new Image[] { fileIcon, folderIcon, fileFolderIcon }[i]; >+ return null; > } > > /** >@@ -277,23 +415,61 @@ > } > } > >+ static String includeOnlyGroup = "INCLUDE_ONLY_GROUP"; //$NON-NLS-1$ >+ >+ static String excludeAllGroup = "EXCLUDE_ALL_GROUP"; //$NON-NLS-1$ >+ > class TreeContentProvider implements ITreeContentProvider { >+ > public Object[] getChildren(Object parentElement) { >+ if (parentElement == filters) { >+ FilterCopy[] children = filters.getChildren(); >+ if (children.length > 0) { >+ boolean includeOnly = false; >+ boolean excludeAll = false; >+ for (int i = 0; i < children.length; i++) { >+ includeOnly |= (children[i].getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0; >+ excludeAll |= (children[i].getType() & IResourceFilterDescription.EXCLUDE_ALL) != 0; >+ } >+ ArrayList list = new ArrayList(); >+ if (includeOnly) >+ list.add(includeOnlyGroup); >+ if (excludeAll) >+ list.add(excludeAllGroup); >+ return list.toArray(); >+ } >+ } >+ if (parentElement instanceof String) { >+ ArrayList list = new ArrayList(); >+ int mask = parentElement.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY: >+ IResourceFilterDescription.EXCLUDE_ALL; >+ FilterCopy[] children = filters.getChildren(); >+ for (int i = 0; i < children.length; i++) { >+ if ((children[i].getType() & mask) != 0) >+ list.add(children[i]); >+ } >+ return list.toArray(); >+ } > if (parentElement instanceof FilterCopy) > return ((FilterCopy) parentElement).getChildren(); > return null; > } > > public Object getParent(Object element) { >- if (element instanceof FilterCopy) { >- if (((FilterCopy) element).getParent() != null) >- return ((FilterCopy) element).getParent(); >+ if (element instanceof String) > return filters; >+ if (element instanceof FilterCopy) { >+ FilterCopy filterCopy = (FilterCopy) element; >+ if (filterCopy.getParent() != null) >+ return filterCopy.getParent(); >+ return ((filterCopy.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0) ? includeOnlyGroup: excludeAllGroup; > } > return null; > } > > public boolean hasChildren(Object element) { >+ if (element instanceof String) >+ return true; > if (element instanceof FilterCopy) { > FilterCopy[] children = ((FilterCopy) element).getChildren(); > return children != null && children.length > 0; >@@ -312,11 +488,35 @@ > } > } > >- class LabelProvider implements ITableLabelProvider { >+ class LabelProvider extends StyledCellLabelProvider { >+ private final Styler fBoldStyler; >+ private final Styler fPlainStyler; > FilterTypeUtil util; >+ TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap(); > > public LabelProvider() { > util = new FilterTypeUtil(); >+ fBoldStyler= new Styler() { >+ public void applyStyles(TextStyle textStyle) { >+ textStyle.font= boldFont; >+ } >+ }; >+ fPlainStyler= new Styler() { >+ public void applyStyles(TextStyle textStyle) { >+ textStyle.font= plainFont; >+ } >+ }; >+ ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(null, null); >+ customfilterArgumentMap.put(ui.getID(), ui); >+ ui = new DefaultCustomFilterArgumentUI(null, null); >+ customfilterArgumentMap.put(ui.getID(), ui); >+ } >+ >+ ICustomFilterArgumentUI getUI(String descriptorID) { >+ ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID); >+ if (result == null) >+ return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui >+ return result; > } > > String getColumnID(int index) { >@@ -328,85 +528,102 @@ > return copy.isUnderAGroupFilter(); > } > >- public Image getColumnImage(Object element, int columnIndex) { >- if (!isPartialFilter(element)) { >- if (getColumnID(columnIndex).equals(FilterTypeUtil.ARGUMENTS)) { >- Object index = FilterTypeUtil.getValue( >- (FilterCopy) element, FilterTypeUtil.TARGET); >- return util.getImage(FilterTypeUtil.TARGET, >- ((Integer) index).intValue()); >- } >- if (getColumnID(columnIndex).equals(FilterTypeUtil.MODE)) { >- Object index = FilterTypeUtil.getValue( >- (FilterCopy) element, FilterTypeUtil.MODE); >- return util.getImage(FilterTypeUtil.MODE, ((Integer) index) >- .intValue()); >- } >- if (getColumnID(columnIndex).equals(FilterTypeUtil.INHERITABLE)) { >- Object condition = FilterTypeUtil.getValue( >- (FilterCopy) element, FilterTypeUtil.INHERITABLE); >- if (((Boolean) condition).booleanValue()) >- return checkIcon; >- } >- } >- return null; >- } >- >- public String getColumnText(Object element, int columnIndex) { >- FilterCopy filter = ((FilterCopy) element); >+ public void update(ViewerCell cell) { >+ int columnIndex = cell.getColumnIndex(); > String column = getColumnID(columnIndex); >- return getValue(filter, column); >- } >+ FilterCopy filter = null; > >- private String getValue(FilterCopy filter, String column) { >- if (column.equals(FilterTypeUtil.ID)) { >- String id = filter.getId(); >- IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id); >- if (descriptor != null) >- return descriptor.getName(); >- } >- if (column.equals(FilterTypeUtil.MODE)) { >- if (!isPartialFilter(filter)) { >- if ((filter.getType() & IResourceFilterDescription.INCLUDE_ONLY) != 0) >- return NLS >+ Object element = cell.getElement(); >+ if (element instanceof String) { >+ if (column.equals(FilterTypeUtil.MODE)) { >+ cell.setImage(getImage(FilterTypeUtil.MODE, element.equals(includeOnlyGroup) ? 0:1)); >+ } >+ if (column.equals(FilterTypeUtil.MODE)) { >+ if (element.equals(includeOnlyGroup)) >+ cell.setText(NLS > .bind( > IDEWorkbenchMessages.ResourceFilterPage_includeOnlyColumn, >- null); >- return NLS >+ null)); >+ else >+ cell.setText(NLS > .bind( > IDEWorkbenchMessages.ResourceFilterPage_excludeAllColumn, >- null); >+ null)); > } >- return getFilterTypeName(filter); >- } >- if (column.equals(FilterTypeUtil.TARGET)) { >- boolean includeFiles = (filter.getType() & IResourceFilterDescription.FILES) != 0; >- boolean includeFolders = (filter.getType() & IResourceFilterDescription.FOLDERS) != 0; >- if (includeFiles && includeFolders) >- return NLS >- .bind( >- IDEWorkbenchMessages.ResourceFilterPage_filesAndFoldersColumn, >- null); >- if (includeFiles) >- return NLS >- .bind( >- IDEWorkbenchMessages.ResourceFilterPage_filesColumn, >- null); >- if (includeFolders) >- return NLS >- .bind( >- IDEWorkbenchMessages.ResourceFilterPage_foldersColumn, >- null); > } >- if (column.equals(FilterTypeUtil.ARGUMENTS)) { >- if (filter.hasStringArguments()) >- return filter.getArguments() != null ? filter >- .getArguments().toString() : ""; //$NON-NLS-1$ >- if ((filter.getChildrenLimit() > 0) >- && !filter.isUnderAGroupFilter()) >- return "< " + getFilterTypeName(filter) + " >"; //$NON-NLS-1$ //$NON-NLS-2$ >+ else { >+ filter = (FilterCopy) element; >+ >+ if (column.equals(FilterTypeUtil.ID)) { >+ String id = filter.getId(); >+ IFilterMatcherDescriptor descriptor = FilterTypeUtil.getDescriptor(id); >+ if (descriptor != null) >+ cell.setText(descriptor.getName()); >+ } >+ if (!isPartialFilter(filter)) { >+ if (column.equals(FilterTypeUtil.INHERITABLE)) { >+ Object condition = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE); >+ cell.setImage(((Boolean) condition).booleanValue() ? checkIcon: null); >+ } >+ } >+ if (column.equals(FilterTypeUtil.MODE)) { >+ StyledString styledString = new StyledString(textPrefix, fPlainStyler); >+ styledString.append(getStyleColumnText(filter)); >+ cell.setText(styledString.toString()); >+ cell.setStyleRanges(styledString.getStyleRanges()); >+ >+ if (!isPartialFilter(filter)) { >+ Image[] images = { fileAloneIcon, folderAloneIcon, fileFolderAloneIcon }; >+ Image[] inheritableImages = {fileInheritableIcon, folderInheritableIcon, fileFolderInheritableIcon}; >+ >+ Object index = FilterTypeUtil.getValue(filter, FilterTypeUtil.TARGET); >+ Object isInheritable = FilterTypeUtil.getValue(filter, FilterTypeUtil.INHERITABLE); >+ int intValue = ((Integer)index).intValue(); >+ if (((Boolean)isInheritable).booleanValue()) >+ cell.setImage(inheritableImages[intValue]); >+ else >+ cell.setImage(images[intValue]); >+ } >+ } > } >- return null; >+ >+ super.update(cell); >+ } >+ >+ private StyledString getStyleColumnText(FilterCopy filter) { >+ if ((filter.getChildrenLimit() > 0)) { >+ String whiteSpace = " "; //$NON-NLS-1$; >+ String expression = getFilterTypeName(filter); >+ boolean isUnaryOperator = filter.getId().equals("org.eclipse.ui.ide.notFilterMatcher"); //$NON-NLS-1$ >+ StyledString buffer = new StyledString(); >+ if (isUnaryOperator) { >+ buffer.append("NOT ", fBoldStyler); //$NON-NLS-1$ >+ expression = "OR"; //$NON-NLS-1$ >+ } >+ buffer.append("(", fBoldStyler); //$NON-NLS-1$ >+ Object [] children = filterViewContentProvider.getChildren(filter); >+ for (int i = 0; i < children.length; i++) { >+ buffer.append(getStyleColumnText((FilterCopy) children[i])); >+ if ((i + 1) < children.length) { >+ buffer.append(whiteSpace, fPlainStyler); >+ buffer.append(expression, fBoldStyler); >+ buffer.append(whiteSpace, fPlainStyler); >+ } >+ } >+ if (children.length < 2 && !isUnaryOperator) { >+ if (children.length == 1) >+ buffer.append(whiteSpace, fPlainStyler); >+ buffer.append(expression, fBoldStyler); >+ } >+ buffer.append(")", fBoldStyler); //$NON-NLS-1$ >+ return buffer; >+ } >+ ICustomFilterArgumentUI ui = getUI(filter.getId()); >+ return ui.formatStyledText(filter, fPlainStyler, fBoldStyler); >+ } >+ >+ protected void measure(Event event, Object element) { >+ super.measure(event, element); > } > > private String getFilterTypeName(FilterCopy filter) { >@@ -416,21 +633,8 @@ > return desc.getName(); > return ""; //$NON-NLS-1$ > } >- >- public void addListener(ILabelProviderListener listener) { >- } >- >- public void dispose() { >- } >- >- public boolean isLabelProperty(Object element, String property) { >- return false; >- } >- >- public void removeListener(ILabelProviderListener listener) { >- } > } >- >+ > class CellModifier implements ICellModifier { > public boolean canModify(Object element, String property) { > FilterCopy filter = (FilterCopy) element; >@@ -506,15 +710,38 @@ > } > > private void createViewerGroup(Composite parent) { >- filterView = new TreeViewer(parent, SWT.FULL_SELECTION | SWT.BORDER >- | SWT.H_SCROLL); >+ >+ GC gc = new GC(parent); >+ gc.setFont(plainFont); >+ String whiteSpace = " "; //$NON-NLS-1$ >+ textPrefix = whiteSpace; >+ int width = inheritableIcon.getImageData().width + AlignedCompositeImageDescriptor_SPACE; >+ while (gc.stringExtent(textPrefix).x < width) { >+ textPrefix += whiteSpace; >+ } >+ gc.dispose(); >+ >+ Composite tableComposite = new Composite(parent, SWT.NONE); > GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); > data.grabExcessHorizontalSpace = true; > data.grabExcessVerticalSpace = true; >+ tableComposite.setLayoutData(data); >+ >+ filterView = new TreeViewer(tableComposite, SWT.FULL_SELECTION | SWT.BORDER >+ | SWT.H_SCROLL); >+ data = new GridData(SWT.FILL, SWT.FILL, true, true); >+ data.grabExcessHorizontalSpace = true; >+ data.grabExcessVerticalSpace = true; > filterView.getTree().setLayoutData(data); > filterView.setColumnProperties(FilterTypeUtil.columnNames); > >- filterView.setContentProvider(new TreeContentProvider()); >+ plainFont = filterView.getTree().getFont(); >+ FontData[] boldFontData= getModifiedFontData(plainFont.getFontData(), SWT.BOLD); >+ boldFont = new Font(Display.getCurrent(), boldFontData); >+ >+ filterView.setAutoExpandLevel(2); >+ filterViewContentProvider = new TreeContentProvider(); >+ filterView.setContentProvider(filterViewContentProvider); > filterView.setInput(filters); > filterView.getTree().setFont(parent.getFont()); > >@@ -524,37 +751,15 @@ > } > }); > >- TreeColumn column = new TreeColumn(filterView.getTree(), 0); >- column >- .setText(NLS >- .bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, >- null)); >- column.setData(FilterTypeUtil.MODE); >- column.setResizable(true); >- column.setMoveable(false); >- column.setWidth(getMinimumColumnWidth(column, 130)); >- >- column = new TreeColumn(filterView.getTree(), 0); >- column.setText(NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments, >- null)); >- column.setData(FilterTypeUtil.ARGUMENTS); >- column.setResizable(true); >- column.setMoveable(true); >- column.setWidth(getMinimumColumnWidth(column, 120)); >- >- column = new TreeColumn(filterView.getTree(), 0); >- column >+ TreeColumn modeColumn = new TreeColumn(filterView.getTree(), 0); >+ modeColumn > .setText(NLS > .bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable, >+ IDEWorkbenchMessages.ResourceFilterPage_columnFilterDescription, > null)); >- column.setData(FilterTypeUtil.INHERITABLE); >- column.setResizable(true); >- column.setMoveable(false); >- column.setAlignment(SWT.CENTER); >- column.setWidth(getMinimumColumnWidth(column, 70)); >+ modeColumn.setData(FilterTypeUtil.MODE); >+ modeColumn.setResizable(true); >+ modeColumn.setMoveable(false); > > filterView.getTree().setHeaderVisible(true); > filterView.getTree().showColumn(filterView.getTree().getColumn(0)); >@@ -578,7 +783,15 @@ > > filterView.getTree().addMouseListener(new MouseListener() { > public void mouseDoubleClick(MouseEvent e) { >- handleEdit(); >+ if (!handleEdit()) { >+ ISelection selection = filterView.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ if (((IStructuredSelection) selection).size() > 0) { >+ Object firstElement = ((IStructuredSelection) selection).getFirstElement(); >+ filterView.setExpandedState(firstElement, !filterView.getExpandedState(firstElement)); >+ } >+ } >+ } > } > > public void mouseDown(MouseEvent e) { >@@ -598,19 +811,83 @@ > public void menuDetected(MenuDetectEvent e) { > MenuManager mgr = new MenuManager(); > mgr.add(addSubFilterAction); >+ mgr.add(addSubGroupFilterAction); >+ mgr.add(new Separator()); >+ mgr.add(new EditFilterAction()); >+ mgr.add(new RemoveFilterAction()); > filterView.getControl().setMenu( > mgr.createContextMenu(filterView.getControl())); > } > }); >+ TreeColumnLayout layout = new TreeColumnLayout(); >+ tableComposite.setLayout( layout ); >+ >+ layout.setColumnData( modeColumn, new ColumnWeightData(100)); >+ } >+ >+ private static FontData[] getModifiedFontData(FontData[] originalData, int additionalStyle) { >+ FontData[] styleData = new FontData[originalData.length]; >+ for (int i = 0; i < styleData.length; i++) { >+ FontData base = originalData[i]; >+ styleData[i] = new FontData(base.getName(), base.getHeight(), base.getStyle() | additionalStyle); >+ } >+ return styleData; >+ } >+ >+ class EditFilterAction extends Action { >+ >+ public EditFilterAction() { >+ setText(NLS >+ .bind(IDEWorkbenchMessages.ResourceFilterPage_editFilterActionLabel, >+ null)); >+ } >+ >+ public void run() { >+ handleEdit(); >+ } >+ public boolean isEnabled() { >+ ISelection selection = filterView.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ if (((IStructuredSelection) selection).size() > 0) { >+ Object firstElement = ((IStructuredSelection) selection) >+ .getFirstElement(); >+ return firstElement instanceof FilterCopy; >+ } >+ } >+ return false; >+ } >+ } >+ >+ class RemoveFilterAction extends Action { >+ >+ public RemoveFilterAction() { >+ setText(NLS >+ .bind(IDEWorkbenchMessages.ResourceFilterPage_removeFilterActionLabel, >+ null)); >+ } >+ >+ public void run() { >+ handleRemove(); >+ } >+ public boolean isEnabled() { >+ ISelection selection = filterView.getSelection(); >+ if (selection instanceof IStructuredSelection) { >+ return ((IStructuredSelection) selection).size() > 0; } >+ return false; >+ } > } > >- Action addSubFilterAction = new AddSubFilterAction(); >+ Action addSubFilterAction = new AddSubFilterAction(false); > > class AddSubFilterAction extends Action { > >- public AddSubFilterAction() { >+ boolean createGroupOnly; >+ >+ public AddSubFilterAction(boolean createGroupOnly) { >+ this.createGroupOnly = createGroupOnly; > setText(NLS >- .bind( >+ .bind(createGroupOnly ? >+ IDEWorkbenchMessages.ResourceFilterPage_addSubFilterGroupActionLabel: > IDEWorkbenchMessages.ResourceFilterPage_addSubFilterActionLabel, > null)); > } >@@ -623,15 +900,29 @@ > public void run() { > ISelection selection = filterView.getSelection(); > if (selection instanceof IStructuredSelection) { >- FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection) >- .getFirstElement(); >- if (filter.getChildrenLimit() > 0) { >+ Object firstElement = ((IStructuredSelection) selection) >+ .getFirstElement(); >+ if (firstElement instanceof FilterCopy) { >+ FilterCopy filter = (FilterCopy) firstElement; >+ if (filter.getChildrenLimit() > 0) { >+ FilterCopy newFilter = new FilterCopy(); >+ newFilter.setParent(filter); >+ FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell, >+ newFilter, createGroupOnly); >+ if (dialog.open() == Window.OK) { >+ filter.addChild(newFilter); >+ filterView.refresh(); >+ } >+ } >+ } >+ if (firstElement instanceof String) { > FilterCopy newFilter = new FilterCopy(); >- newFilter.setParent(filter); >- FilterEditDialog dialog = new FilterEditDialog(resource, shell, >- newFilter); >+ FilterTypeUtil.setValue(newFilter, FilterTypeUtil.MODE, >+ new Integer(firstElement.equals(includeOnlyGroup) ? 0:1)); >+ FilterEditDialog dialog = new FilterEditDialog(resource, ResourceFilterGroup.this, shell, >+ newFilter, createGroupOnly); > if (dialog.open() == Window.OK) { >- filter.addChild(newFilter); >+ filters.addChild(newFilter); > filterView.refresh(); > } > } >@@ -646,14 +937,21 @@ > public boolean isEnabled() { > ISelection selection = filterView.getSelection(); > if (selection instanceof IStructuredSelection) { >- FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection) >+ Object firstElement = ((IStructuredSelection) selection) > .getFirstElement(); >- return filter.getChildrenLimit() > 0; >+ if (firstElement instanceof FilterCopy) { >+ FilterCopy filter = (FilterCopy) firstElement; >+ return filter.getChildrenLimit() > 0; >+ } >+ if (firstElement instanceof String) >+ return true; > } > return false; > } > } > >+ Action addSubGroupFilterAction = new AddSubFilterAction(true); >+ > class FilterCopyDrop extends ViewerDropAdapter { > protected FilterCopyDrop(Viewer viewer) { > super(viewer); >@@ -682,6 +980,11 @@ > for (int i = 0; i < toDrop.length; i++) { > if (target instanceof Filters) > filters.add(toDrop[i]); >+ if (target instanceof String) { >+ FilterTypeUtil.setValue(toDrop[i], FilterTypeUtil.MODE, >+ new Integer(target.equals(includeOnlyGroup) ? 0:1)); >+ filters.add(toDrop[i]); >+ } > if (target instanceof FilterCopy) > ((FilterCopy) target).addChild(toDrop[i]); > filterView.refresh(); >@@ -749,20 +1052,6 @@ > } > } > >- private static int getMinimumColumnWidth(TreeColumn column, int hint) { >- Assert.isNotNull(column); >- FontMetrics fontMetrics; >- GC gc = new GC(column.getParent()); >- try { >- gc.setFont(column.getParent().getFont()); >- fontMetrics = gc.getFontMetrics(); >- } finally { >- gc.dispose(); >- } >- return Math.max(hint, fontMetrics.getAverageCharWidth() >- * column.getText().length()); >- } >- > private void createButtonGroup(Composite parent) { > Composite composite = new Composite(parent, SWT.NONE); > GridLayout layout = new GridLayout(); >@@ -780,14 +1069,24 @@ > data = new GridData(SWT.FILL, SWT.FILL, false, false); > addButton.setLayoutData(data); > setButtonDimensionHint(addButton); >- addButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >+ addButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ handleAdd(false); > } >- >+ }); >+ >+ addGroupButton = new Button(composite, SWT.PUSH); >+ addGroupButton.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_addGroupButtonLabel, null)); >+ data = new GridData(SWT.FILL, SWT.FILL, false, false); >+ addGroupButton.setLayoutData(data); >+ setButtonDimensionHint(addGroupButton); >+ addGroupButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { >- handleAdd(); >+ handleAdd(true); > } > }); >+ > > editButton = new Button(composite, SWT.PUSH); > editButton.setText(NLS.bind( >@@ -795,10 +1094,7 @@ > data = new GridData(SWT.FILL, SWT.FILL, false, false); > editButton.setLayoutData(data); > setButtonDimensionHint(editButton); >- editButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ editButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > handleEdit(); > } >@@ -813,50 +1109,11 @@ > data = new GridData(SWT.FILL, SWT.FILL, false, false); > removeButton.setLayoutData(data); > setButtonDimensionHint(removeButton); >- removeButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ removeButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > handleRemove(); > } > }); >- >- if (allowReordering) { >- upButton = new Button(composite, SWT.PUSH); >- upButton >- .setText(NLS >- .bind( >- IDEWorkbenchMessages.ResourceFilterPage_upButtonLabel, >- null)); >- data = new GridData(SWT.FILL, SWT.FILL, false, false); >- upButton.setLayoutData(data); >- setButtonDimensionHint(upButton); >- upButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >- public void widgetSelected(SelectionEvent e) { >- handleUp(); >- } >- }); >- >- downButton = new Button(composite, SWT.PUSH); >- downButton.setText(NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_downButtonLabel, >- null)); >- data = new GridData(SWT.FILL, SWT.FILL, false, false); >- downButton.setLayoutData(data); >- setButtonDimensionHint(downButton); >- downButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >- public void widgetSelected(SelectionEvent e) { >- handleDown(); >- } >- }); >- } > } > > private void refreshEnablement() { >@@ -868,7 +1125,8 @@ > removeButton.setEnabled(structuredSelection != null > && structuredSelection.size() > 0); > editButton.setEnabled(structuredSelection != null >- && structuredSelection.size() == 1); >+ && structuredSelection.size() == 1 >+ && (structuredSelection.getFirstElement() instanceof FilterCopy)); > if (upButton != null) > upButton.setEnabled(structuredSelection != null > && (structuredSelection.size() > 0) >@@ -887,30 +1145,38 @@ > return filters.isLast((FilterCopy) o); > } > >- private void handleAdd() { >+ private void handleAdd(boolean createGroupOnly) { > FilterCopy newFilter = new FilterCopy(); >- FilterEditDialog dialog = new FilterEditDialog(resource, shell, newFilter); >+ FilterEditDialog dialog = new FilterEditDialog(resource, this, shell, newFilter, createGroupOnly); > if (dialog.open() == Window.OK) { > filters.add(newFilter); > filterView.refresh(); > } > } > >- private void handleEdit() { >+ private boolean handleEdit() { > ISelection selection = filterView.getSelection(); > if (selection instanceof IStructuredSelection) { >- FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection) >+ Object firstElement = ((IStructuredSelection) selection) > .getFirstElement(); >- FilterCopy copy = new FilterCopy(filter); >- copy.setParent(filter.getParent()); >- FilterEditDialog dialog = new FilterEditDialog(resource, shell, copy); >- if (dialog.open() == Window.OK) { >- if (copy.hasChanged()) { >- filter.copy(copy); >- filterView.refresh(); >+ if (firstElement instanceof String) >+ return false; >+ if (firstElement instanceof FilterCopy) { >+ FilterCopy filter = (FilterCopy) firstElement; >+ FilterCopy copy = new FilterCopy(filter); >+ copy.setParent(filter.getParent()); >+ boolean isGroup = filter.getChildrenLimit() > 0; >+ FilterEditDialog dialog = new FilterEditDialog(resource, this, shell, copy, isGroup); >+ if (dialog.open() == Window.OK) { >+ if (copy.hasChanged()) { >+ filter.copy(copy); >+ filterView.refresh(); >+ } > } >+ return true; > } > } >+ return false; > } > > private FilterCopy[] getFilterCopySelection() { >@@ -933,35 +1199,25 @@ > structuredSelection = ((IStructuredSelection) selection); > Iterator it = structuredSelection.iterator(); > while (it.hasNext()) { >- FilterCopy filter = (FilterCopy) it.next(); >- filter.getParent().removeChild(filter); >+ Object element = it.next(); >+ if (element instanceof FilterCopy) { >+ FilterCopy filter = (FilterCopy) element; >+ filter.getParent().removeChild(filter); >+ } >+ else { >+ int mask = element.equals(includeOnlyGroup) ? IResourceFilterDescription.INCLUDE_ONLY: >+ IResourceFilterDescription.EXCLUDE_ALL; >+ FilterCopy[] children = filters.getChildren(); >+ for (int i = 0; i < children.length; i++) { >+ if ((children[i].getType() & mask) != 0) >+ filters.removeChild(children[i]); >+ } >+ } > } > filterView.refresh(); > } > } > >- private void handleUp() { >- ISelection selection = filterView.getSelection(); >- if (selection instanceof IStructuredSelection) { >- FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection) >- .getFirstElement(); >- filters.moveUp(filter); >- } >- filterView.refresh(); >- refreshEnablement(); >- } >- >- private void handleDown() { >- ISelection selection = filterView.getSelection(); >- if (selection instanceof IStructuredSelection) { >- FilterCopy filter = (FilterCopy) ((IStructuredSelection) selection) >- .getFirstElement(); >- filters.moveDown(filter); >- } >- filterView.refresh(); >- refreshEnablement(); >- } >- > private static void setButtonDimensionHint(Button button) { > Assert.isNotNull(button); > Object gd = button.getLayoutData(); >@@ -1066,9 +1322,26 @@ > * Disposes the group's resources. > */ > public void dispose() { >- if (checkIcon != null) { >- checkIcon.dispose(); >- checkIcon = null; >+ disposeIcons(); >+ } >+ >+ private void disposeIcons() { >+ Field[] fields = getClass().getFields(); >+ for (int i = 0; i < fields.length; i++) { >+ if (fields[i].getClass().equals(Image.class)) { >+ Image img; >+ try { >+ img = (Image) fields[i].get(this); >+ if (img != null) { >+ img.dispose(); >+ fields[i].set(this, null); >+ } >+ } catch (IllegalArgumentException e) { >+ e.printStackTrace(); >+ } catch (IllegalAccessException e) { >+ e.printStackTrace(); >+ } >+ } > } > } > >@@ -1149,7 +1422,7 @@ > static String ARGUMENTS = "arguments"; //$NON-NLS-1$ > static String INHERITABLE = "inheritable"; //$NON-NLS-1$ > >- static String[] columnNames = new String[] { MODE, ARGUMENTS, INHERITABLE }; >+ static String[] columnNames = new String[] { MODE, TARGET, INHERITABLE }; > > static String[] getModes() { > return new String[] { >@@ -1263,24 +1536,41 @@ > null) }; > } > >- static String[] getFilterNames(boolean childrenOnly) { >+ static String[] getFilterNames(boolean groupOnly) { > IFilterMatcherDescriptor[] descriptors = ResourcesPlugin.getWorkspace() > .getFilterMatcherDescriptors(); >+ sortDescriptors(descriptors); > LinkedList names = new LinkedList(); > for (int i = 0; i < descriptors.length; i++) { >- if (!childrenOnly >- || descriptors[i].getArgumentType().equals( >- IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER) >+ boolean isGroup = descriptors[i].getArgumentType().equals( >+ IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHER) > || descriptors[i].getArgumentType().equals( >- IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS)) >+ IFilterMatcherDescriptor.ARGUMENT_TYPE_FILTER_MATCHERS); >+ if (isGroup == groupOnly) > names.add(descriptors[i].getName()); > } > return (String[]) names.toArray(new String[0]); > } > >+ /** >+ * @param descriptors >+ */ >+ private static void sortDescriptors(IFilterMatcherDescriptor[] descriptors) { >+ Arrays.sort(descriptors, new Comparator() { >+ public int compare(Object arg0, Object arg1) { >+ if (((IFilterMatcherDescriptor) arg0).getId().equals(MultiMatcher.ID)) >+ return -1; >+ if (((IFilterMatcherDescriptor) arg1).getId().equals(MultiMatcher.ID)) >+ return 1; >+ return ((IFilterMatcherDescriptor) arg0).getId().compareTo(((IFilterMatcherDescriptor) arg1).getId()); >+ } >+ }); >+ } >+ > static String getDefaultFilterID() { > IFilterMatcherDescriptor descriptors[] = ResourcesPlugin.getWorkspace() > .getFilterMatcherDescriptors(); >+ sortDescriptors(descriptors); > for (int i = 0; i < descriptors.length; i++) { > if (descriptors[i].getArgumentType().equals( > IFilterMatcherDescriptor.ARGUMENT_TYPE_STRING)) >@@ -1304,60 +1594,8 @@ > } > return null; > } >- >- private Image fileIcon = null; >- private Image folderIcon = null; >- private Image fileFolderIcon = null; >- private Image includeIcon = null; >- private Image excludeIcon = null; >- private Image inheritableIcon = null; >- >- FilterTypeUtil() { >- ImageDescriptor descriptor = AbstractUIPlugin >- .imageDescriptorFromPlugin(IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/fileType_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- fileIcon = descriptor.createImage(); >- >- descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >- IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/folderType_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- folderIcon = descriptor.createImage(); >- >- descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >- IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/fileFolderType_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- fileFolderIcon = descriptor.createImage(); >- >- descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >- IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/includeMode_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- includeIcon = descriptor.createImage(); >- >- descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >- IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/excludeMode_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- excludeIcon = descriptor.createImage(); >- >- descriptor = AbstractUIPlugin.imageDescriptorFromPlugin( >- IDEWorkbenchPlugin.IDE_WORKBENCH, >- "$nl$/icons/full/obj16/inheritable_filter.gif"); //$NON-NLS-1$ >- if (descriptor != null) >- inheritableIcon = descriptor.createImage(); >- } >- >- Image getImage(String string, int i) { >- if (string.equals(MODE)) >- return new Image[] { includeIcon, excludeIcon, inheritableIcon }[i]; >- if (string.equals(TARGET)) >- return new Image[] { fileIcon, folderIcon, fileFolderIcon }[i]; >- return null; >- } >-} >+ FilterTypeUtil() {} >+} > > class FilterCopy extends UIResourceFilterDescription { > Object arguments = null; >@@ -1669,32 +1907,44 @@ > protected Button foldersButton; > protected Button filesAndFoldersButton; > protected Combo idCombo; >+ protected Composite idComposite; >+ protected Composite argumentComposite; > protected Button inherited; >- protected Text arguments; >- protected Label argumentsLabel; >- protected Label description; > protected FilterTypeUtil util; >+ protected boolean createGroupOnly; >+ protected ResourceFilterGroup filterGroup; > protected IResource resource; > >- private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilter"; //$NON-NLS-1$ >- >- /** >- * Find and replace command adapters. >- * @since 3.3 >- */ >- private ContentAssistCommandAdapter fContentAssistField; >+ TreeMap/*<String, ICustomFilterArgumentUI */ customfilterArgumentMap = new TreeMap(); >+ ICustomFilterArgumentUI currentCustomFilterArgumentUI = new ICustomFilterArgumentUI() { >+ public Object getID() {return "dummy";} //$NON-NLS-1$ >+ public void create(Composite argumentComposite, Font font) {} >+ public void dispose() {} >+ public void selectionChanged() {} >+ public void validate() {} >+ public StyledString formatStyledText(FilterCopy filter, >+ Styler fPlainStyler, Styler fBoldStyler) {return null;} >+ }; > > /** > * Constructor for FilterEditDialog. >- * >+ * @param resource >+ * @param filterGroup > * @param parentShell > * @param filter >+ * @param createGroupOnly > */ >- public FilterEditDialog(IResource resource, Shell parentShell, FilterCopy filter) { >+ public FilterEditDialog(IResource resource, ResourceFilterGroup filterGroup, Shell parentShell, FilterCopy filter, boolean createGroupOnly) { > super(parentShell); > this.resource = resource; >+ this.filterGroup = filterGroup; > this.filter = filter; >+ this.createGroupOnly = createGroupOnly; > util = new FilterTypeUtil(); >+ ICustomFilterArgumentUI ui = new MultiMatcherCustomFilterArgumentUI(parentShell, filter); >+ customfilterArgumentMap.put(ui.getID(), ui); >+ ui = new DefaultCustomFilterArgumentUI(parentShell, filter); >+ customfilterArgumentMap.put(ui.getID(), ui); > } > > /* >@@ -1712,7 +1962,7 @@ > Composite composite = new Composite(parent, SWT.NONE); > GridLayout layout = new GridLayout(); > layout.numColumns = 1; >- layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); >+ layout.marginHeight = 0; > layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); > layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); > layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); >@@ -1728,7 +1978,7 @@ > if (!filter.isUnderAGroupFilter()) { > Composite topComposite = new Composite(composite, SWT.NONE); > layout = new GridLayout(); >- layout.numColumns = 2; >+ layout.numColumns = 1; > layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); > layout.marginWidth = 0; > layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); >@@ -1739,10 +1989,108 @@ > topComposite.setFont(font); > > createModeArea(font, topComposite); >+ createIdArea(font, topComposite); > createTargetArea(font, topComposite); >+ createInheritableArea(font, topComposite); >+ } >+ else >+ createIdArea(font, composite); >+ return composite; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.dialogs.TrayDialog#createButtonBar(org.eclipse.swt.widgets.Composite) >+ */ >+ protected Control createButtonBar(Composite parent) { >+ Label label = new Label(parent, SWT.SEPARATOR | SWT.HORIZONTAL); >+ label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, false)); >+ >+ Composite composite = new Composite(parent, SWT.NONE); >+ GridLayout layout = new GridLayout(); >+ layout.marginWidth = 0; >+ layout.marginHeight = 0; >+ layout.horizontalSpacing = 0; >+ composite.setLayout(layout); >+ composite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); >+ composite.setFont(parent.getFont()); >+ >+ // create help control if needed >+ if (isHelpAvailable()) { >+ Control helpControl = createHelpControl(composite); >+ ((GridData) helpControl.getLayoutData()).horizontalIndent = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); >+ } >+ if (!createGroupOnly) { >+ ((GridLayout) composite.getLayout()).numColumns++; >+ Button customizeButton = new Button(composite, SWT.PUSH); >+ customizeButton.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_customize, >+ null)); >+ customizeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false)); >+ customizeButton.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ selectOtherFilterMatcher(); >+ } >+ }); >+ } >+ >+ Control buttonSection = dialogCreateButtonBar(composite); >+ ((GridData) buttonSection.getLayoutData()).grabExcessHorizontalSpace = true; >+ return composite; >+ } >+ >+ private void selectOtherFilterMatcher() { >+ ListDialog dlg = >+ new ListDialog(getShell()); >+ dlg.setAddCancelButton(true); >+ dlg.setInput(Arrays.asList(FilterTypeUtil.getFilterNames(createGroupOnly))); >+ dlg.setInitialElementSelections(Arrays.asList(new String[] {FilterTypeUtil.getDescriptor(filter.getId()).getName()})); >+ dlg.setContentProvider(new IStructuredContentProvider() { >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {} >+ public void dispose() {} >+ public Object[] getElements(Object inputElement) { >+ if (inputElement instanceof List) >+ return ((List) inputElement).toArray(); >+ return null; >+ } >+ }); >+ dlg.setLabelProvider(new org.eclipse.jface.viewers.LabelProvider()); >+ dlg.setTitle(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_customizeTitle, >+ null)); >+ dlg.setMessage(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_customizeMessage, >+ null)); >+ if (dlg.open() == Window.OK) { >+ Object[] result = dlg.getResult(); >+ if (result.length > 0) { >+ FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, result[0]); >+ if (filter.hasStringArguments()) >+ filter.setArguments(new String()); >+ setupPatternLine(); >+ currentCustomFilterArgumentUI.selectionChanged(); >+ } > } >- createIdArea(font, composite); >+ } > >+ private Control dialogCreateButtonBar(Composite parent) { >+ Composite composite = new Composite(parent, SWT.NONE); >+ // create a layout with spacing and margins appropriate for the font >+ // size. >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 0; // this is incremented by createButton >+ layout.makeColumnsEqualWidth = true; >+ layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); >+ layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); >+ layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); >+ layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); >+ composite.setLayout(layout); >+ GridData data = new GridData(GridData.HORIZONTAL_ALIGN_END >+ | GridData.VERTICAL_ALIGN_CENTER); >+ composite.setLayoutData(data); >+ composite.setFont(parent.getFont()); >+ >+ // Add the buttons to the button bar. >+ createButtonsForButtonBar(composite); > return composite; > } > >@@ -1751,22 +2099,23 @@ > * @param composite > */ > private void createInheritableArea(Font font, Composite composite) { >+ Composite inheritableComposite = createGroup(font, composite, NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, >+ null), false, false, 1); >+ > GridData data; >- inherited = new Button(composite, SWT.CHECK); >+ inherited = new Button(inheritableComposite, SWT.CHECK); > inherited > .setText(NLS > .bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterInheritable, >+ IDEWorkbenchMessages.ResourceFilterPage_applyRecursivelyToFolderStructure, > null)); >- inherited.setImage(util.getImage(FilterTypeUtil.MODE, 2)); >+ inherited.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 2)); > data = new GridData(SWT.FILL, SWT.CENTER, true, false); > data.horizontalSpan = 1; > inherited.setLayoutData(data); > inherited.setFont(font); >- inherited.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ inherited.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.INHERITABLE, > new Boolean(inherited.getSelection())); >@@ -1780,105 +2129,64 @@ > * @param font > * @param composite > */ >- private void createArgumentsArea(Font font, Composite composite) { >+ private void createIdArea(Font font, Composite composite) { > GridData data; >- argumentsLabel = addLabel(composite, NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterArguments, >- null)); >- arguments = new Text(composite, SWT.SINGLE | SWT.BORDER); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >- arguments.setLayoutData(data); >- arguments.setFont(font); >- arguments.addModifyListener(new ModifyListener() { >- public void modifyText(ModifyEvent e) { >- FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, >- arguments.getText()); >- } >- }); >- if (filter.hasStringArguments()) >- arguments.setText((String) FilterTypeUtil.getValue(filter, >- FilterTypeUtil.ARGUMENTS)); >- arguments.setEnabled(filter.hasStringArguments()); >- setArgumentLabelEnabled(); >- >- TextContentAdapter contentAdapter= new TextContentAdapter(); >- FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true); >- fContentAssistField= new ContentAssistCommandAdapter( >- arguments, >- contentAdapter, >- findProposer, >- null, >- new char[] {'\\', '[', '('}, >- true); >- } >- >- /** >- * >- */ >- private void setArgumentLabelEnabled() { >- Color color = argumentsLabel.getDisplay().getSystemColor( >- filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY); >- argumentsLabel.setForeground(color); >+ if (createGroupOnly) { >+ idComposite = createGroup(font, composite, new String(), >+ true, true, 1); >+ idCombo = new Combo(idComposite, SWT.READ_ONLY); >+ idCombo.setItems(FilterTypeUtil.getFilterNames(createGroupOnly)); >+ data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ idCombo.setLayoutData(data); >+ idCombo.setFont(font); >+ idCombo.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo >+ .getItem(idCombo.getSelectionIndex())); >+ if (filter.hasStringArguments()) >+ filter.setArguments(new String()); >+ setupPatternLine(); >+ currentCustomFilterArgumentUI.selectionChanged(); >+ } >+ }); >+ idCombo.select(0); >+ selectComboItem(filter.getId()); >+ FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo >+ .getItem(idCombo.getSelectionIndex())); >+ } >+ else { >+ idComposite = createGroup(font, composite, new String(), >+ true, true, 1); >+ } >+ argumentComposite = new Composite(idComposite, SWT.NONE); >+ setupPatternLine(); > } >+ > >- /** >- * @param font >- * @param composite >- */ >- private void createDescriptionArea(Font font, Composite composite) { >- GridData data; >- description = new Label(composite, SWT.LEFT | SWT.WRAP); >- description.setText(FilterTypeUtil.getDescriptor(filter.getId()) >- .getDescription()); >- data = new GridData(SWT.FILL, SWT.BEGINNING, true, true); >- data.widthHint = 300; >- data.heightHint = 40; >- description.setLayoutData(data); >- description.setFont(font); >+ ICustomFilterArgumentUI getUI(String descriptorID) { >+ ICustomFilterArgumentUI result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(descriptorID); >+ if (result == null) >+ return result = (ICustomFilterArgumentUI) customfilterArgumentMap.get(new String()); // default ui >+ return result; > } >- >- /** >- * @param font >- * @param composite >- */ >- private void createIdArea(Font font, Composite composite) { >- GridData data; >- Group idComposite = createGroup(font, composite, NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterID, null), >- true); >- idCombo = new Combo(idComposite, SWT.READ_ONLY); >- idCombo.setItems(FilterTypeUtil.getFilterNames(filter >- .getChildrenLimit() > 0)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >- idCombo.setLayoutData(data); >- idCombo.setFont(font); >- idCombo.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >- public void widgetSelected(SelectionEvent e) { >- FilterTypeUtil.setValue(filter, FilterTypeUtil.ID, idCombo >- .getItem(idCombo.getSelectionIndex())); >- arguments.setEnabled(filter.hasStringArguments()); >- setArgumentLabelEnabled(); >- description.setText(FilterTypeUtil >- .getDescriptor(filter.getId()).getDescription()); >- fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID)); >- } >- }); >- selectComboItem(filter.getId()); >- Composite argumentComposite = new Composite(idComposite, SWT.NONE); >- GridLayout layout = new GridLayout(); >- layout.numColumns = 2; >- layout.marginWidth = 0; >- argumentComposite.setLayout(layout); >- data = new GridData(SWT.FILL, SWT.FILL, true, true); >- argumentComposite.setLayoutData(data); >- argumentComposite.setFont(font); >- createArgumentsArea(font, argumentComposite); >- >- createDescriptionArea(font, idComposite); >- fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID)); >+ >+ private void setupPatternLine() { >+ IFilterMatcherDescriptor descriptor; >+ if (createGroupOnly) { >+ String item = idCombo.getItem(idCombo.getSelectionIndex()); >+ descriptor = FilterTypeUtil.getDescriptorByName(item); >+ } >+ else >+ descriptor = FilterTypeUtil.getDescriptor(filter.getId()); >+ Font font = idComposite.getFont(); >+ ICustomFilterArgumentUI customFilterArgumentUI = getUI(descriptor.getId()); >+ if (!currentCustomFilterArgumentUI.getID().equals(customFilterArgumentUI.getID())) { >+ currentCustomFilterArgumentUI.dispose(); >+ currentCustomFilterArgumentUI = customFilterArgumentUI; >+ currentCustomFilterArgumentUI.create(argumentComposite, font); >+ getShell().layout(true); >+ getShell().redraw(); >+ } > } > > /** >@@ -1904,20 +2212,16 @@ > */ > private void createModeArea(Font font, Composite composite) { > GridData data; >- Group modeComposite = createGroup(font, composite, NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, >- null), false); >+ Composite modeComposite = createGroup(font, composite, NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_columnFilterMode, null), false, true, 2); > String[] modes = FilterTypeUtil.getModes(); > includeButton = new Button(modeComposite, SWT.RADIO); > includeButton.setText(modes[0]); >- includeButton.setImage(util.getImage(FilterTypeUtil.MODE, 0)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ includeButton.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 0)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); > includeButton.setLayoutData(data); > includeButton.setFont(font); >- includeButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ includeButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE, > new Integer(0)); >@@ -1927,14 +2231,11 @@ > filter, FilterTypeUtil.MODE)).intValue() == 0); > excludeButton = new Button(modeComposite, SWT.RADIO); > excludeButton.setText(modes[1]); >- excludeButton.setImage(util.getImage(FilterTypeUtil.MODE, 1)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ excludeButton.setImage(filterGroup.getImage(FilterTypeUtil.MODE, 1)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); > excludeButton.setLayoutData(data); > excludeButton.setFont(font); >- excludeButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ excludeButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.MODE, > new Integer(1)); >@@ -1942,7 +2243,6 @@ > }); > excludeButton.setSelection(((Integer) FilterTypeUtil.getValue( > filter, FilterTypeUtil.MODE)).intValue() == 1); >- createInheritableArea(font, modeComposite); > } > > /** >@@ -1950,18 +2250,20 @@ > * @param composite > * @return the group > */ >- private Group createGroup(Font font, Composite composite, String text, >- boolean grabExcessVerticalSpace) { >+ private Composite createGroup(Font font, Composite composite, String text, >+ boolean grabExcessVerticalSpace, boolean group, int columnCounts) { > GridLayout layout; > GridData data; >- Group modeComposite = new Group(composite, SWT.NONE); >- modeComposite.setText(text); >+ Composite modeComposite; >+ if (group) { >+ Group modeGroup = new Group(composite, SWT.NONE); >+ modeGroup.setText(text); >+ modeComposite = modeGroup; >+ } else { >+ modeComposite = new Composite(composite, SWT.NONE); >+ } > layout = new GridLayout(); >- layout.numColumns = 1; >- layout.marginHeight = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_MARGIN); >- layout.marginWidth = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN); >- layout.verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); >- layout.horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); >+ layout.numColumns = columnCounts; > modeComposite.setLayout(layout); > data = new GridData(SWT.FILL, SWT.FILL, true, grabExcessVerticalSpace); > modeComposite.setLayoutData(data); >@@ -1975,54 +2277,43 @@ > */ > private void createTargetArea(Font font, Composite composite) { > GridData data; >- Group targetComposite = createGroup(font, composite, NLS.bind( >- IDEWorkbenchMessages.ResourceFilterPage_columnFilterTargets, >- null), false); >+ Composite targetComposite = createGroup(font, composite, new String(), false, true, 3); > > String[] targets = FilterTypeUtil.getTargets(); > filesButton = new Button(targetComposite, SWT.RADIO); > filesButton.setText(targets[0]); >- filesButton.setImage(util.getImage(FilterTypeUtil.TARGET, 0)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ filesButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 0)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); > filesButton.setLayoutData(data); > filesButton.setFont(font); > > foldersButton = new Button(targetComposite, SWT.RADIO); > foldersButton.setText(targets[1]); >- foldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 1)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ foldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 1)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); > foldersButton.setLayoutData(data); > foldersButton.setFont(font); > > filesAndFoldersButton = new Button(targetComposite, SWT.RADIO); > filesAndFoldersButton.setText(targets[2]); >- filesAndFoldersButton.setImage(util.getImage(FilterTypeUtil.TARGET, 2)); >- data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ filesAndFoldersButton.setImage(filterGroup.getImage(FilterTypeUtil.TARGET, 2)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); > filesAndFoldersButton.setLayoutData(data); > filesAndFoldersButton.setFont(font); > >- filesButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ filesButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET, > new Integer(0)); > } > }); >- foldersButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ foldersButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET, > new Integer(1)); > } > }); >- filesAndFoldersButton.addSelectionListener(new SelectionListener() { >- public void widgetDefaultSelected(SelectionEvent e) { >- } >- >+ filesAndFoldersButton.addSelectionListener(new SelectionAdapter() { > public void widgetSelected(SelectionEvent e) { > FilterTypeUtil.setValue(filter, FilterTypeUtil.TARGET, > new Integer(2)); >@@ -2036,18 +2327,6 @@ > filter, FilterTypeUtil.TARGET)).intValue() == 2); > } > >- Label addLabel(Composite composite, String text) { >- String delimiter = ":"; //$NON-NLS-1$ >- >- Font font = composite.getFont(); >- Label label = new Label(composite, SWT.LEFT); >- label.setText(text + delimiter); >- GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false); >- label.setLayoutData(data); >- label.setFont(font); >- return label; >- } >- > protected Control createContents(Composite parent) { > Control control = super.createContents(parent); > initialize(); >@@ -2082,8 +2361,9 @@ > if (filter.hasStringArguments()) { > IFilterMatcherDescriptor desc = resource.getWorkspace().getFilterMatcherDescriptor(filter.getId()); > if (desc != null) { >- AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter(); > try { >+ currentCustomFilterArgumentUI.validate(); >+ AbstractFileInfoMatcher matcher = ((FilterDescriptor) desc).createFilter(); > matcher.initialize(resource.getProject(), filter.getArguments()); > } catch (CoreException e) { > IWorkbenchWindow window = PlatformUI.getWorkbench() >@@ -2099,4 +2379,865 @@ > > super.okPressed(); > } >+} >+ >+interface ICustomFilterArgumentUI { >+ >+ /** >+ * @return the descriptor ID >+ */ >+ Object getID(); >+ >+ /** >+ * @param filter >+ * @param fPlainStyler >+ * @param fBoldStyler >+ * @return the formatted StyledText >+ */ >+ StyledString formatStyledText(FilterCopy filter, Styler fPlainStyler, >+ Styler fBoldStyler); >+ >+ /** >+ * @throws CoreException >+ * >+ */ >+ void validate() throws CoreException; >+ >+ /** >+ * >+ */ >+ void selectionChanged(); >+ >+ /** >+ * @param argumentComposite >+ * @param font >+ */ >+ void create(Composite argumentComposite, Font font); >+ >+ /** >+ * >+ */ >+ void dispose(); >+ >+} >+ >+class MultiMatcherCustomFilterArgumentUI implements ICustomFilterArgumentUI { >+ >+ Shell shell; >+ FilterCopy filter; >+ protected Button argumentsCaseSensitive; >+ protected Button argumentsRegularExpresion; >+ protected Text arguments; >+ protected DateTime argumentsDate; >+ protected Combo argumentsBoolean; >+ protected Label argumentsLabel; >+ protected Label description; >+ protected ContentAssistCommandAdapter fContentAssistField; >+ protected Combo multiKey; >+ protected Combo multiOperator; >+ protected Composite multiArgumentComposite; >+ protected Composite stringArgumentComposite; >+ protected Composite attributeStringArgumentComposite; >+ protected Class intiantiatedKeyOperatorType = null; >+ protected TreeMap/* <String, String>*/ valueCache = new TreeMap(); >+ >+ /** >+ * @param parentShell >+ * @param filter >+ */ >+ public MultiMatcherCustomFilterArgumentUI(Shell parentShell, >+ FilterCopy filter) { >+ this.shell = parentShell; >+ this.filter = filter; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID() >+ */ >+ public Object getID() { >+ return MultiMatcher.ID; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose() >+ */ >+ public void dispose() { >+ Widget list[] = new Widget[] {multiKey, multiOperator, multiArgumentComposite, stringArgumentComposite, arguments, argumentsLabel, argumentsCaseSensitive, argumentsRegularExpresion, attributeStringArgumentComposite, description}; >+ for (int i = 0; i < list.length; i++) { >+ if (list[i] != null) { >+ list[i].dispose(); >+ } >+ } >+ multiKey = null; >+ multiOperator = null; >+ multiArgumentComposite = null; >+ arguments = null; >+ argumentsLabel = null; >+ fContentAssistField = null; >+ intiantiatedKeyOperatorType = null; >+ stringArgumentComposite = null; >+ argumentsCaseSensitive = null; >+ argumentsRegularExpresion = null; >+ attributeStringArgumentComposite = null; >+ description = null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font) >+ */ >+ public void create(Composite argumentComposite, Font font) { >+ shell = argumentComposite.getShell(); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 3; >+ layout.marginWidth = 0; >+ argumentComposite.setLayout(layout); >+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); >+ argumentComposite.setLayoutData(data); >+ argumentComposite.setFont(font); >+ createCustomArgumentsArea(font, argumentComposite); >+ argumentComposite.layout(true); >+ createDescriptionArea(font, argumentComposite); >+ } >+ >+ /** >+ * @param font >+ * @param composite >+ */ >+ private void createDescriptionArea(Font font, Composite composite) { >+ GridData data; >+ description = new Label(composite, SWT.LEFT | SWT.WRAP); >+ data = new GridData(SWT.FILL, SWT.BEGINNING, true, true); >+ data.widthHint = 300; >+ data.heightHint = 40; >+ data.horizontalSpan = 3; >+ description.setLayoutData(data); >+ description.setFont(font); >+ setupDescriptionText(); >+ } >+ >+ private void setupDescriptionText() { >+ if (description != null) { >+ String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText()); >+ String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText()); >+ Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator); >+ description.setText(new String()); >+ if (selectedKeyOperatorType.equals(String.class)) { >+ if (!argumentsRegularExpresion.getSelection()) >+ description.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_Matcher, null)); >+ } >+ if (selectedKeyOperatorType.equals(Integer.class)) { >+ if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) >+ description.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_TimeInterval, null)); >+ else >+ description.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_FileLength, null)); >+ } >+ } >+ } >+ >+ private void createCustomArgumentsArea(Font font, Composite composite) { >+ GridData data; >+ multiKey = new Combo(composite, SWT.READ_ONLY); >+ multiKey.setItems(getMultiMatcherKeys()); >+ data = new GridData(SWT.LEFT, SWT.TOP, false, false); >+ multiKey.setLayoutData(data); >+ multiKey.setFont(font); >+ multiKey.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ setupMultiOperatorAndField(true); >+ storeMultiSelection(); >+ } >+ }); >+ >+ multiOperator = new Combo(composite, SWT.READ_ONLY); >+ data = new GridData(SWT.LEFT, SWT.TOP, false, false); >+ multiOperator.setLayoutData(data); >+ multiOperator.setFont(font); >+ multiOperator.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ setupMultiOperatorAndField(false); >+ storeMultiSelection(); >+ } >+ }); >+ >+ multiArgumentComposite = new Composite(composite, SWT.NONE); >+ >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 1; >+ layout.marginWidth = 0; >+ layout.horizontalSpacing = 0; >+ layout.verticalSpacing = 0; >+ layout.marginBottom = 0; >+ layout.marginHeight = 0; >+ multiArgumentComposite.setLayout(layout); >+ data = new GridData(SWT.FILL, SWT.TOP, true, true); >+ multiArgumentComposite.setLayoutData(data); >+ multiArgumentComposite.setFont(font); >+ >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key); >+ int index = multiKey.indexOf(local); >+ if (index != -1) >+ multiKey.select(index); >+ else >+ multiKey.select(0); >+ >+ setupMultiOperatorAndField(true); >+ } >+ >+ private void setupMultiOperatorAndField(boolean updateOperator) { >+ boolean isUsingRegularExpression = false; >+ String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText()); >+ if (updateOperator) { >+ String[] operators = getLocalOperatorsForKey(selectedKey); >+ multiOperator.setItems(operators); >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ String local = MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator); >+ int index = multiOperator.indexOf(local); >+ if (index != -1) >+ multiOperator.select(index); >+ else >+ multiOperator.select(0); >+ } >+ String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText()); >+ >+ Class selectedKeyOperatorType = MultiMatcher.getTypeForKey(selectedKey, selectedOperator); >+ >+ if (intiantiatedKeyOperatorType != null) { >+ if (intiantiatedKeyOperatorType.equals(selectedKeyOperatorType)) >+ return; >+ if (arguments != null) { >+ arguments.dispose(); >+ arguments = null; >+ } >+ if (attributeStringArgumentComposite != null) { >+ attributeStringArgumentComposite.dispose(); >+ attributeStringArgumentComposite = null; >+ } >+ if (stringArgumentComposite != null) { >+ stringArgumentComposite.dispose(); >+ stringArgumentComposite = null; >+ } >+ if (argumentsBoolean != null) { >+ argumentsBoolean.dispose(); >+ argumentsBoolean = null; >+ } >+ if (argumentsDate != null) { >+ argumentsDate.dispose(); >+ argumentsDate = null; >+ } >+ if (argumentsRegularExpresion != null) { >+ argumentsRegularExpresion.dispose(); >+ argumentsRegularExpresion = null; >+ } >+ if (argumentsCaseSensitive != null) { >+ argumentsCaseSensitive.dispose(); >+ argumentsCaseSensitive = null; >+ } >+ fContentAssistField = null; >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ valueCache.put(intiantiatedKeyOperatorType.getName(), argument.pattern); >+ argument.pattern = (String) valueCache.get(selectedKeyOperatorType.getName()); >+ if (argument.pattern == null) >+ argument.pattern = new String(); >+ filter.setArguments(MultiMatcher.encodeArguments(argument)); >+ } >+ if (selectedKeyOperatorType.equals(String.class)) { >+ stringArgumentComposite = new Composite(multiArgumentComposite, SWT.NONE); >+ >+ GridData data; >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 2; >+ layout.marginWidth = 0; >+ layout.horizontalSpacing = 0; >+ layout.verticalSpacing = 0; >+ layout.marginBottom = 0; >+ layout.marginHeight = 0; >+ stringArgumentComposite.setLayout(layout); >+ data = new GridData(SWT.FILL, SWT.TOP, true, true); >+ stringArgumentComposite.setLayoutData(data); >+ stringArgumentComposite.setFont(multiArgumentComposite.getFont()); >+ >+ arguments = new Text(stringArgumentComposite, SWT.SINGLE | SWT.BORDER); >+ data = new GridData(SWT.FILL, SWT.TOP, true, false); >+ data.minimumWidth = 100; >+ arguments.setLayoutData(data); >+ arguments.setFont(stringArgumentComposite.getFont()); >+ >+ attributeStringArgumentComposite = new Composite(stringArgumentComposite, SWT.NONE); >+ >+ layout = new GridLayout(); >+ layout.numColumns = 1; >+ layout.marginWidth = 0; >+ layout.horizontalSpacing = 0; >+ layout.verticalSpacing = 0; >+ layout.marginBottom = 0; >+ layout.marginHeight = 0; >+ attributeStringArgumentComposite.setLayout(layout); >+ data = new GridData(SWT.FILL, SWT.TOP, false, true); >+ attributeStringArgumentComposite.setLayoutData(data); >+ attributeStringArgumentComposite.setFont(stringArgumentComposite.getFont()); >+ >+ argumentsCaseSensitive = new Button(attributeStringArgumentComposite, SWT.CHECK); >+ argumentsCaseSensitive.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_caseSensitive, null)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); >+ data.minimumWidth = 100; >+ argumentsCaseSensitive.setLayoutData(data); >+ argumentsCaseSensitive.setFont(stringArgumentComposite.getFont()); >+ >+ argumentsRegularExpresion = new Button(attributeStringArgumentComposite, SWT.CHECK); >+ argumentsRegularExpresion.setText(NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_regularExpression, null)); >+ data = new GridData(SWT.FILL, SWT.CENTER, false, false); >+ data.minimumWidth = 100; >+ argumentsRegularExpresion.setLayoutData(data); >+ argumentsRegularExpresion.setFont(stringArgumentComposite.getFont()); >+ >+ if (filter.hasStringArguments()) { >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ arguments.setText(argument.pattern); >+ isUsingRegularExpression = argument.regularExpression; >+ argumentsCaseSensitive.setSelection(argument.caseSensitive); >+ argumentsRegularExpresion.setSelection(argument.regularExpression); >+ } >+ >+ arguments.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ storeMultiSelection(); >+ } >+ }); >+ argumentsRegularExpresion.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ setupDescriptionText(); >+ storeMultiSelection(); >+ if (fContentAssistField != null) >+ fContentAssistField.setEnabled(argumentsRegularExpresion.getSelection()); >+ } >+ }); >+ argumentsCaseSensitive.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ storeMultiSelection(); >+ } >+ }); >+ >+ TextContentAdapter contentAdapter= new TextContentAdapter(); >+ FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true); >+ fContentAssistField= new ContentAssistCommandAdapter( >+ arguments, >+ contentAdapter, >+ findProposer, >+ null, >+ new char[] {'\\', '[', '('}, >+ true); >+ } >+ if (selectedKeyOperatorType.equals(Integer.class)) { >+ GridData data; >+ arguments = new Text(multiArgumentComposite, SWT.SINGLE | SWT.BORDER); >+ data = new GridData(SWT.FILL, SWT.TOP, true, false); >+ data.minimumWidth = 100; >+ arguments.setLayoutData(data); >+ arguments.setFont(multiArgumentComposite.getFont()); >+ >+ if (filter.hasStringArguments()) { >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) >+ arguments.setText(convertToEditableTimeInterval(argument.pattern)); >+ else >+ arguments.setText(convertToEditableLength(argument.pattern)); >+ } >+ >+ arguments.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ storeMultiSelection(); >+ } >+ }); >+ } >+ if (selectedKeyOperatorType.equals(Date.class)) { >+ GridData data; >+ argumentsDate = new DateTime(multiArgumentComposite, SWT.DATE | SWT.MEDIUM); >+ data = new GridData(SWT.FILL, SWT.TOP, true, false); >+ argumentsDate.setLayoutData(data); >+ argumentsDate.setFont(multiArgumentComposite.getFont()); >+ argumentsDate.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ storeMultiSelection(); >+ } >+ }); >+ if (filter.hasStringArguments()) { >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ Date date; >+ Calendar calendar = Calendar.getInstance(); >+ try { >+ date = new Date(Long.parseLong(argument.pattern)); >+ calendar.setTime(date); >+ } catch (NumberFormatException e1) { >+ date = new Date(); >+ calendar.setTime(date); >+ argument.pattern = Long.toString(calendar.getTimeInMillis()); >+ } >+ argumentsDate.setDay(calendar.get(Calendar.DAY_OF_MONTH)); >+ argumentsDate.setMonth(calendar.get(Calendar.MONTH)); >+ argumentsDate.setYear(calendar.get(Calendar.YEAR)); >+ } >+ } >+ if (selectedKeyOperatorType.equals(Boolean.class)) { >+ GridData data; >+ argumentsBoolean = new Combo(multiArgumentComposite, SWT.READ_ONLY); >+ data = new GridData(SWT.FILL, SWT.TOP, true, false); >+ argumentsBoolean.setLayoutData(data); >+ argumentsBoolean.setFont(multiArgumentComposite.getFont()); >+ argumentsBoolean.setItems(new String[] {MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.TRUE.toString()), MultiMatcherLocalization.getLocalMultiMatcherKey(Boolean.FALSE.toString())}); >+ argumentsBoolean.addSelectionListener(new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ storeMultiSelection(); >+ } >+ }); >+ if (filter.hasStringArguments()) { >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments((String) filter.getArguments()); >+ if (argument.pattern.length() == 0) >+ argumentsBoolean.select(0); >+ else >+ argumentsBoolean.select(Boolean.valueOf(argument.pattern).booleanValue() ? 0:1); >+ } >+ } >+ multiArgumentComposite.layout(true); >+ intiantiatedKeyOperatorType = selectedKeyOperatorType; >+ >+ if (fContentAssistField != null) >+ fContentAssistField.setEnabled(isUsingRegularExpression); >+ >+ shell.layout(true); >+ shell.redraw(); >+ setupDescriptionText(); >+ } >+ >+ private String[] timeIntervalPrefixes = {"s", "m", "h", "d"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ >+ private double[] timeIntervalScale = {60, 60, 24}; >+ >+ private String convertToEditableTimeInterval(String string) { >+ if (string.length() == 0) >+ return string; >+ long value; >+ try { >+ value = Long.parseLong(string); >+ } catch (NumberFormatException e) { >+ value = 0; >+ } >+ if (value == 0) >+ return Long.toString(0); >+ for (int i = 0; i < timeIntervalPrefixes.length - 1; i++) { >+ if (value % timeIntervalScale[i] != 0) >+ return Long.toString(value) + timeIntervalPrefixes[i]; >+ value /= timeIntervalScale[i]; >+ } >+ return Long.toString(value) + timeIntervalPrefixes[timeIntervalPrefixes.length - 1]; >+ } >+ >+ private String convertFromEditableTimeInterval(String string) { >+ if (string.length() == 0) >+ return string; >+ for (int i = 1; i < timeIntervalPrefixes.length; i++) { >+ if (string.endsWith(timeIntervalPrefixes[i])) { >+ long value = Long.parseLong(string.substring(0, string.length() - 1)); >+ for (int j = 0; j < i; j++) >+ value *= timeIntervalScale[j]; >+ return Long.toString(value); >+ } >+ } >+ // seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number >+ return Long.toString(Long.parseLong(string)); >+ } >+ >+ >+ private String[] lengthPrefixes = {new String(), "k", "m", "g"}; //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ >+ >+ // converts "32768" to "32k" >+ private String convertToEditableLength(String string) { >+ if (string.length() == 0) >+ return string; >+ long value; >+ try { >+ value = Long.parseLong(string); >+ } catch (NumberFormatException e) { >+ value = 0; >+ } >+ if (value == 0) >+ return Long.toString(0); >+ for (int i = 0; i < lengthPrefixes.length; i++) { >+ if (value % 1024 != 0) >+ return Long.toString(value) + lengthPrefixes[i]; >+ if ((i + 1) < lengthPrefixes.length) >+ value /= 1024; >+ } >+ return Long.toString(value) + lengthPrefixes[lengthPrefixes.length - 1]; >+ } >+ >+ // converts "32k" to "32768" >+ private String convertFromEditableLength(String string) throws NumberFormatException { >+ if (string.length() == 0) >+ return string; >+ for (int i = 1; i < lengthPrefixes.length; i++) { >+ if (string.endsWith(lengthPrefixes[i])) { >+ long value = Long.parseLong(string.substring(0, string.length() - 1)); >+ value *= Math.pow(1024, i); >+ return Long.toString(value); >+ } >+ } >+ // seems equivalent to "return string", but it throws an exception if the string doesn't contain a valid number >+ return Long.toString(Long.parseLong(string)); >+ } >+ >+ private void storeMultiSelection() { >+ if (intiantiatedKeyOperatorType != null) { >+ String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText()); >+ String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText()); >+ >+ MultiMatcher.Argument argument = new MultiMatcher.Argument(); >+ argument.key = selectedKey; >+ argument.operator = selectedOperator; >+ >+ if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) { >+ Calendar calendar = Calendar.getInstance(); >+ calendar.set(argumentsDate.getYear(), argumentsDate.getMonth(), argumentsDate.getDay()); >+ argument.pattern = Long.toString(calendar.getTimeInMillis()); >+ } >+ if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) { >+ argument.pattern = arguments.getText(); >+ if (argumentsRegularExpresion != null) >+ argument.regularExpression = argumentsRegularExpresion.getSelection(); >+ if (argumentsCaseSensitive != null) >+ argument.caseSensitive = argumentsCaseSensitive.getSelection(); >+ } >+ if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) { >+ try { >+ if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) >+ argument.pattern = convertFromEditableTimeInterval(arguments.getText()); >+ else >+ argument.pattern = convertFromEditableLength(arguments.getText()); >+ } catch (NumberFormatException e) { >+ argument.pattern = arguments.getText(); >+ } >+ } >+ if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) >+ argument.pattern = MultiMatcherLocalization.getMultiMatcherKey(argumentsBoolean.getText()); >+ String encodedArgument = MultiMatcher.encodeArguments(argument); >+ FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, encodedArgument); >+ } >+ } >+ >+ private String[] getLocalOperatorsForKey(String key) { >+ String [] operators = MultiMatcher.getOperatorsForKey(key); >+ String[] result = new String[operators.length]; >+ for (int i = 0; i < operators.length; i++) >+ result[i] = MultiMatcherLocalization.getLocalMultiMatcherKey(operators[i]); >+ return result; >+ } >+ >+ private String[] getMultiMatcherKeys() { >+ ArrayList list = new ArrayList(); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_NAME)); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_PROPJECT_RELATIVE_PATH)); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LOCATION)); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LAST_MODIFIED)); >+ if (MultiMatcher.supportCreatedKey()) >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_CREATED)); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_LENGTH)); >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_READONLY)); >+ if (!Platform.getOS().equals(Platform.OS_WIN32)) >+ list.add(MultiMatcherLocalization.getLocalMultiMatcherKey(MultiMatcher.KEY_IS_SYMLINK)); >+ return (String []) list.toArray(new String[0]); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged() >+ */ >+ public void selectionChanged() { >+ } >+ >+ /** >+ * @throws CoreException >+ */ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData() >+ */ >+ public void validate() throws CoreException { >+ if (intiantiatedKeyOperatorType != null) { >+ String selectedKey = MultiMatcherLocalization.getMultiMatcherKey(multiKey.getText()); >+ String selectedOperator = MultiMatcherLocalization.getMultiMatcherKey(multiOperator.getText()); >+ >+ MultiMatcher.Argument argument = new MultiMatcher.Argument(); >+ argument.key = selectedKey; >+ argument.operator = selectedOperator; >+ >+ if (intiantiatedKeyOperatorType.equals(Date.class) && argumentsDate != null) { >+ } >+ if (intiantiatedKeyOperatorType.equals(String.class) && arguments != null) { >+ } >+ if (intiantiatedKeyOperatorType.equals(Integer.class) && arguments != null) { >+ if (selectedKey.equals(MultiMatcher.KEY_LAST_MODIFIED) || selectedKey.equals(MultiMatcher.KEY_CREATED)) { >+ try { >+ convertFromEditableTimeInterval(arguments.getText()); >+ } catch (NumberFormatException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidTimeInterval, arguments.getText()), e)); >+ } >+ } >+ else { >+ try { >+ convertFromEditableLength(arguments.getText()); >+ } catch (NumberFormatException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_multiMatcher_InvalidFileLength, arguments.getText()), e)); >+ } >+ } >+ } >+ if (intiantiatedKeyOperatorType.equals(Boolean.class) && argumentsBoolean != null) { >+ >+ } >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @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) >+ */ >+ public StyledString formatStyledText(FilterCopy filter, >+ Styler fPlainStyler, Styler fBoldStyler) { >+ return new StyledString(formatMultiMatcherArgument(filter), fPlainStyler); >+ } >+ >+ private String formatMultiMatcherArgument(FilterCopy filter) { >+ String argumentString = (String) filter.getArguments(); >+ MultiMatcher.Argument argument = MultiMatcher.decodeArguments(argumentString); >+ >+ StringBuffer builder = new StringBuffer(); >+ builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.key)); >+ builder.append(' '); >+ builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.operator)); >+ builder.append(' '); >+ Class type = MultiMatcher.getTypeForKey(argument.key, argument.operator); >+ if (type.equals(String.class)) >+ builder.append(argument.pattern); >+ if (type.equals(Boolean.class)) >+ builder.append(MultiMatcherLocalization.getLocalMultiMatcherKey(argument.pattern)); >+ if (type.equals(Integer.class)) { >+ if (argument.key.equals(MultiMatcher.KEY_LAST_MODIFIED) || argument.key.equals(MultiMatcher.KEY_CREATED)) >+ builder.append(convertToEditableTimeInterval(argument.pattern)); >+ else >+ builder.append(convertToEditableLength(argument.pattern)); >+ } >+ if (type.equals(Date.class)) >+ builder.append(DateFormat.getDateInstance().format(new Date(Long.parseLong(argument.pattern)))); >+ >+ return builder.toString(); >+ } >+} >+ >+class DefaultCustomFilterArgumentUI implements ICustomFilterArgumentUI { >+ >+ Shell shell; >+ FilterCopy filter; >+ protected Text arguments; >+ protected Label argumentsLabel; >+ protected Label description; >+ protected ContentAssistCommandAdapter fContentAssistField; >+ >+ private static final String REGEX_FILTER_ID = "org.eclipse.core.resources.regexFilterMatcher"; //$NON-NLS-1$ >+ >+ /** >+ * @param parentShell >+ * @param filter >+ */ >+ public DefaultCustomFilterArgumentUI(Shell parentShell, FilterCopy filter) { >+ this.shell = parentShell; >+ this.filter = filter; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#getID() >+ */ >+ public Object getID() { >+ return new String(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#dispose() >+ */ >+ public void dispose() { >+ Widget list[] = new Widget[] {arguments, argumentsLabel, description}; >+ for (int i = 0; i < list.length; i++) { >+ if (list[i] != null) { >+ list[i].dispose(); >+ } >+ } >+ arguments = null; >+ argumentsLabel = null; >+ fContentAssistField = null; >+ description = null; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#create(org.eclipse.swt.widgets.Composite, org.eclipse.swt.graphics.Font) >+ */ >+ public void create(Composite argumentComposite, Font font) { >+ shell = argumentComposite.getShell(); >+ GridLayout layout = new GridLayout(); >+ layout.numColumns = 2; >+ layout.marginWidth = 0; >+ argumentComposite.setLayout(layout); >+ GridData data = new GridData(SWT.FILL, SWT.FILL, true, true); >+ argumentComposite.setLayoutData(data); >+ argumentComposite.setFont(font); >+ if (filter.hasStringArguments()) >+ createArgumentsArea(font, argumentComposite); >+ >+ createDescriptionArea(font, argumentComposite); >+ >+ if (fContentAssistField != null) >+ fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID)); >+ argumentComposite.layout(true); >+ } >+ >+ private void createArgumentsArea(Font font, Composite composite) { >+ GridData data; >+ argumentsLabel = addLabel(composite, NLS.bind( >+ IDEWorkbenchMessages.ResourceFilterPage_columnFilterTarget, >+ null)); >+ arguments = new Text(composite, SWT.SINGLE | SWT.BORDER); >+ data = new GridData(SWT.FILL, SWT.CENTER, true, false); >+ arguments.setLayoutData(data); >+ arguments.setFont(font); >+ arguments.addModifyListener(new ModifyListener() { >+ public void modifyText(ModifyEvent e) { >+ FilterTypeUtil.setValue(filter, FilterTypeUtil.ARGUMENTS, >+ arguments.getText()); >+ } >+ }); >+ if (filter.hasStringArguments()) >+ arguments.setText((String) FilterTypeUtil.getValue(filter, >+ FilterTypeUtil.ARGUMENTS)); >+ arguments.setEnabled(filter.hasStringArguments()); >+ setArgumentLabelEnabled(); >+ >+ TextContentAdapter contentAdapter= new TextContentAdapter(); >+ FindReplaceDocumentAdapterContentProposalProvider findProposer= new FindReplaceDocumentAdapterContentProposalProvider(true); >+ fContentAssistField= new ContentAssistCommandAdapter( >+ arguments, >+ contentAdapter, >+ findProposer, >+ null, >+ new char[] {'\\', '[', '('}, >+ true); >+ } >+ >+ private void setArgumentLabelEnabled() { >+ if (argumentsLabel != null) { >+ Color color = argumentsLabel.getDisplay().getSystemColor( >+ filter.hasStringArguments() ? SWT.COLOR_BLACK : SWT.COLOR_GRAY); >+ argumentsLabel.setForeground(color); >+ } >+ } >+ >+ Label addLabel(Composite composite, String text) { >+ String delimiter = ":"; //$NON-NLS-1$ >+ >+ Font font = composite.getFont(); >+ Label label = new Label(composite, SWT.LEFT); >+ label.setText(text + delimiter); >+ GridData data = new GridData(SWT.LEFT, SWT.CENTER, false, false); >+ label.setLayoutData(data); >+ label.setFont(font); >+ return label; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#selectionChanged() >+ */ >+ public void selectionChanged() { >+ if (arguments != null) >+ arguments.setEnabled(filter.hasStringArguments()); >+ setArgumentLabelEnabled(); >+ if (fContentAssistField != null) >+ fContentAssistField.setEnabled(filter.getId().equals(REGEX_FILTER_ID)); >+ description.setText(FilterTypeUtil >+ .getDescriptor(filter.getId()).getDescription()); >+ } >+ >+ /** >+ * @param font >+ * @param composite >+ */ >+ private void createDescriptionArea(Font font, Composite composite) { >+ GridData data; >+ description = new Label(composite, SWT.LEFT | SWT.WRAP); >+ description.setText(FilterTypeUtil.getDescriptor(filter.getId()) >+ .getDescription()); >+ data = new GridData(SWT.FILL, SWT.BEGINNING, true, true); >+ data.widthHint = 300; >+ data.heightHint = 40; >+ data.horizontalSpan = 2; >+ description.setLayoutData(data); >+ description.setFont(font); >+ } >+ >+ /** >+ * @throws CoreException >+ */ >+ /* (non-Javadoc) >+ * @see org.eclipse.ui.internal.ide.dialogs.ICustomFilterArgumentUI#verifyData() >+ */ >+ public void validate() throws CoreException { >+ // nothing >+ } >+ >+ /* (non-Javadoc) >+ * @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) >+ */ >+ public StyledString formatStyledText(FilterCopy filter, >+ Styler fPlainStyler, Styler fBoldStyler) { >+ return new StyledString(filter.getArguments() != null ? filter >+ .getArguments().toString() : new String(), fPlainStyler); >+ } >+} >+ >+class MultiMatcherLocalization { >+ >+ static String[][] multiMatcherKey = { >+ {MultiMatcher.KEY_NAME, IDEWorkbenchMessages.ResourceFilterPage_multiKeyName}, >+ {MultiMatcher.KEY_PROPJECT_RELATIVE_PATH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyProjectRelativePath}, >+ {MultiMatcher.KEY_LOCATION, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLocation}, >+ {MultiMatcher.KEY_LAST_MODIFIED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLastModified}, >+ {MultiMatcher.KEY_CREATED, IDEWorkbenchMessages.ResourceFilterPage_multiKeyCreated}, >+ {MultiMatcher.KEY_LENGTH, IDEWorkbenchMessages.ResourceFilterPage_multiKeyLength}, >+ {MultiMatcher.KEY_IS_READONLY, IDEWorkbenchMessages.ResourceFilterPage_multiKeyReadOnly}, >+ {MultiMatcher.KEY_IS_SYMLINK, IDEWorkbenchMessages.ResourceFilterPage_multiKeySymLink}, >+ {MultiMatcher.OPERATOR_AFTER, IDEWorkbenchMessages.ResourceFilterPage_multiAfter}, >+ {MultiMatcher.OPERATOR_BEFORE, IDEWorkbenchMessages.ResourceFilterPage_multiBefore}, >+ {MultiMatcher.OPERATOR_EQUALS, IDEWorkbenchMessages.ResourceFilterPage_multiEquals}, >+ {MultiMatcher.OPERATOR_MATCHES, IDEWorkbenchMessages.ResourceFilterPage_multiMatches}, >+ {MultiMatcher.OPERATOR_LARGER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiLargerThan}, >+ {MultiMatcher.OPERATOR_SMALLER_THAN, IDEWorkbenchMessages.ResourceFilterPage_multiSmallerThan}, >+ {MultiMatcher.OPERATOR_WITHIN, IDEWorkbenchMessages.ResourceFilterPage_multiWithin}, >+ {Boolean.TRUE.toString(), IDEWorkbenchMessages.ResourceFilterPage_true}, >+ {Boolean.FALSE.toString(), IDEWorkbenchMessages.ResourceFilterPage_false} >+ }; >+ >+ static public String getLocalMultiMatcherKey(String key) { >+ for (int i = 0; i < multiMatcherKey.length; i++) { >+ if (multiMatcherKey[i][0].equals(key)) >+ return multiMatcherKey[i][1]; >+ } >+ return null; >+ } >+ >+ static public String getMultiMatcherKey(String local) { >+ for (int i = 0; i < multiMatcherKey.length; i++) { >+ if (multiMatcherKey[i][1].equals(local)) >+ return multiMatcherKey[i][0]; >+ } >+ return null; >+ } >+ > } >\ No newline at end of file >Index: src/org/eclipse/ui/internal/ide/misc/MultiMatcher.java >=================================================================== >RCS file: src/org/eclipse/ui/internal/ide/misc/MultiMatcher.java >diff -N src/org/eclipse/ui/internal/ide/misc/MultiMatcher.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/ui/internal/ide/misc/MultiMatcher.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,420 @@ >+/******************************************************************************* >+ * Copyright (c) 2008, 2009 Freescale Semiconductor and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * Serge Beauchamp (Freescale Semiconductor) - [252996] initial API and implementation >+ * IBM Corporation - ongoing implementation >+ *******************************************************************************/ >+package org.eclipse.ui.internal.ide.misc; >+ >+import java.lang.reflect.Array; >+import java.lang.reflect.InvocationTargetException; >+import java.lang.reflect.Method; >+import java.util.Calendar; >+import java.util.Date; >+import java.util.GregorianCalendar; >+import java.util.regex.Matcher; >+import java.util.regex.Pattern; >+import java.util.regex.PatternSyntaxException; >+ >+import org.eclipse.core.filesystem.EFS; >+import org.eclipse.core.filesystem.IFileInfo; >+import org.eclipse.core.filesystem.IFileStore; >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IProject; >+import org.eclipse.core.resources.filtermatchers.AbstractFileInfoMatcher; >+import org.eclipse.core.runtime.CoreException; >+import org.eclipse.core.runtime.IStatus; >+import org.eclipse.core.runtime.Platform; >+import org.eclipse.core.runtime.Status; >+import org.eclipse.ui.PlatformUI; >+import org.eclipse.ui.internal.ide.StringMatcher; >+ >+/** >+ * A file info filter that matches different file and folder attributes. >+ */ >+public class MultiMatcher extends AbstractFileInfoMatcher { >+ >+ public static String ID = "org.eclipse.ui.ide.multiFilter"; //$NON-NLS-1$ >+ >+ public static String KEY_NAME = "name"; //$NON-NLS-1$ >+ public static String KEY_PROPJECT_RELATIVE_PATH = "projectRelativePath"; //$NON-NLS-1$ >+ public static String KEY_LOCATION = "location"; //$NON-NLS-1$ >+ public static String KEY_LAST_MODIFIED = "lastModified"; //$NON-NLS-1$ >+ public static String KEY_LENGTH = "length"; //$NON-NLS-1$ >+ public static String KEY_CREATED = "created"; //$NON-NLS-1$ >+ public static String KEY_IS_SYMLINK = "isSymLink"; //$NON-NLS-1$ >+ public static String KEY_IS_READONLY = "isReadOnly"; //$NON-NLS-1$ >+ >+ public static String OPERATOR_NONE = "none"; //$NON-NLS-1$ >+ public static String OPERATOR_LARGER_THAN = "largerThan"; //$NON-NLS-1$ >+ public static String OPERATOR_SMALLER_THAN = "smallerThan"; //$NON-NLS-1$ >+ public static String OPERATOR_EQUALS = "equals"; //$NON-NLS-1$ >+ public static String OPERATOR_BEFORE = "before"; //$NON-NLS-1$ >+ public static String OPERATOR_AFTER = "after"; //$NON-NLS-1$ >+ public static String OPERATOR_WITHIN = "within"; //$NON-NLS-1$ >+ public static String OPERATOR_MATCHES = "matches"; //$NON-NLS-1$ >+ >+ >+ /** >+ * @param key >+ * @return >+ */ >+ public static String[] getOperatorsForKey(String key) { >+ if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION)) >+ return new String[] {OPERATOR_MATCHES}; >+ if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY)) >+ return new String[] {OPERATOR_EQUALS}; >+ if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED)) >+ return new String[] {OPERATOR_EQUALS, OPERATOR_BEFORE, OPERATOR_AFTER, OPERATOR_WITHIN}; >+ if (key.equals(KEY_LENGTH)) >+ return new String[] {OPERATOR_EQUALS, OPERATOR_LARGER_THAN, OPERATOR_SMALLER_THAN}; >+ >+ return new String[] {OPERATOR_NONE}; >+ } >+ >+ /** >+ * @param key >+ * @param operator >+ * @return >+ */ >+ public static Class getTypeForKey(String key, String operator) { >+ if (key.equals(KEY_NAME) || key.equals(KEY_PROPJECT_RELATIVE_PATH) || key.equals(KEY_LOCATION)) >+ return String.class; >+ if (key.equals(KEY_IS_SYMLINK) || key.equals(KEY_IS_READONLY)) >+ return Boolean.class; >+ if (key.equals(KEY_LAST_MODIFIED) || key.equals(KEY_CREATED)) { >+ if (operator.equals(OPERATOR_WITHIN)) >+ return Integer.class; >+ return Date.class; >+ } >+ if (key.equals(KEY_LENGTH)) >+ return Integer.class; >+ return String.class; >+ } >+ >+ /** >+ * @return >+ */ >+ public static boolean supportCreatedKey() { >+ if (Platform.getOS().equals(Platform.OS_WIN32) || Platform.getOS().equals(Platform.OS_MACOSX)) { >+ String system = System.getProperty("java.version"); //$NON-NLS-1$ >+ double versionNumber = 0.0; >+ int index = system.indexOf('.'); >+ if (index != -1) { >+ versionNumber = Integer.decode(system.substring(0, index)).doubleValue(); >+ system = system.substring(index + 1); >+ index = system.indexOf('.'); >+ if (index != -1) { >+ versionNumber += Double.parseDouble(system.substring(0, index)) / 10.0; >+ } >+ } >+ return versionNumber >= 1.7; >+ } >+ return false; >+ } >+ >+ /** >+ * @since 3.6 >+ * >+ */ >+ public static class Argument { >+ public String key = KEY_NAME; >+ public String pattern = new String(); >+ public String operator = OPERATOR_EQUALS; >+ public boolean caseSensitive = false; >+ public boolean regularExpression = false; >+ } >+ >+ /** >+ * @param argument >+ * @return >+ */ >+ public static String encodeArguments(Argument argument) { >+ return VERSION_IMPLEMENTATION + DELIMITER + >+ argument.key + DELIMITER + >+ argument.operator + DELIMITER + >+ Boolean.toString(argument.caseSensitive) + DELIMITER + >+ Boolean.toString(argument.regularExpression) + DELIMITER + >+ argument.pattern; >+ >+ } >+ >+ /** >+ * @param argument >+ * @return >+ */ >+ public static Argument decodeArguments(String argument) { >+ Argument result = new Argument(); >+ if (argument == null) >+ return result; >+ >+ int index = argument.indexOf(DELIMITER); >+ if (index == -1) >+ return result; >+ >+ String version = argument.substring(0, index); >+ argument = argument.substring(index + 1); >+ >+ if (!version.equals(VERSION_IMPLEMENTATION)) >+ return result; >+ >+ index = argument.indexOf(DELIMITER); >+ if (index == -1) >+ return result; >+ >+ result.key = argument.substring(0, index); >+ argument = argument.substring(index + 1); >+ >+ index = argument.indexOf(DELIMITER); >+ if (index == -1) >+ return result; >+ >+ result.operator = argument.substring(0, index); >+ argument = argument.substring(index + 1); >+ >+ index = argument.indexOf(DELIMITER); >+ if (index == -1) >+ return result; >+ >+ result.caseSensitive = Boolean.valueOf(argument.substring(0, index)).booleanValue(); >+ argument = argument.substring(index + 1); >+ >+ index = argument.indexOf(DELIMITER); >+ if (index == -1) >+ return result; >+ >+ result.regularExpression = Boolean.valueOf(argument.substring(0, index)).booleanValue(); >+ result.pattern = argument.substring(index + 1); >+ >+ return result; >+ } >+ >+ >+ static private String DELIMITER = "-"; //$NON-NLS-1$ >+ static private String VERSION_IMPLEMENTATION = "1.0"; //$NON-NLS-1$ >+ >+ /* >+ * return value in milliseconds since epoch(1970-01-01T00:00:00Z) >+ */ >+ private static long getFileCreationTime(String fullPath) { >+ /* >+ java.nio.file.FileSystem fs = java.nio.file.FileSystems.getDefault(); >+ java.nio.file.FileRef fileRef = fs.getPath(file); >+ java.nio.file.attribute.BasicFileAttributes attributes = java.nio.file.attribute.Attributes.readBasicFileAttributes(fileRef, new java.nio.file.LinkOption[0]); >+ return attributes.creationTime(); >+ */ >+ >+ try { >+ Class fileSystems = Class.forName("java.nio.file.FileSystems"); //$NON-NLS-1$ >+ Method getDefault = fileSystems.getMethod("getDefault", null); //$NON-NLS-1$ >+ Object fs = getDefault.invoke(null, null); >+ >+ Class fileRef = Class.forName("java.nio.file.FileRef"); //$NON-NLS-1$ >+ >+ Class fileSystem = Class.forName("java.nio.file.FileSystem"); //$NON-NLS-1$ >+ Method getPath = fileSystem.getMethod("getPath", new Class[] {String.class}); //$NON-NLS-1$ >+ Object fileRefObj = getPath.invoke(fs, new Object[] {fullPath}); >+ >+ Class attributes = Class.forName("java.nio.file.attribute.Attributes"); //$NON-NLS-1$ >+ Class linkOptions = Class.forName("java.nio.file.LinkOption"); //$NON-NLS-1$ >+ Object linkOptionsEmptyArray = Array.newInstance(linkOptions, 0); >+ Method readBasicFileAttributes = attributes.getMethod("readBasicFileAttributes", new Class[] {fileRef, linkOptionsEmptyArray.getClass()}); //$NON-NLS-1$ >+ Object attributesObj = readBasicFileAttributes.invoke(null, new Object[] {fileRefObj, linkOptionsEmptyArray}); >+ >+ Class basicAttributes = Class.forName("java.nio.file.attribute.BasicFileAttributes"); //$NON-NLS-1$ >+ Method creationTime = basicAttributes.getMethod("creationTime", null); //$NON-NLS-1$ >+ Object time = creationTime.invoke(attributesObj, null); >+ >+ Class fileTime = Class.forName("java.nio.file.attribute.FileTime"); //$NON-NLS-1$ >+ Method toMillis = fileTime.getMethod("toMillis", null); //$NON-NLS-1$ >+ Object result = toMillis.invoke(time, null); >+ >+ if (result instanceof Long) >+ return ((Long) result).longValue(); >+ } catch (ClassNotFoundException e) { >+ e.printStackTrace(); >+ } catch (IllegalArgumentException e) { >+ e.printStackTrace(); >+ } catch (IllegalAccessException e) { >+ e.printStackTrace(); >+ } catch (InvocationTargetException e) { >+ e.printStackTrace(); >+ } catch (SecurityException e) { >+ e.printStackTrace(); >+ } catch (NoSuchMethodException e) { >+ e.printStackTrace(); >+ } >+ return 0; >+ } >+ >+ MatcherCache matcher = null; >+ private boolean fSupportsCreatedKey; >+ >+ class MatcherCache { >+ public MatcherCache(String arguments) { >+ argument = decodeArguments(arguments); >+ type = getTypeForKey(argument.key, argument.operator); >+ if (type.equals(String.class)) { >+ if (argument.regularExpression == false) >+ stringMatcher = new StringMatcher(argument.pattern, argument.caseSensitive == false, false); >+ else >+ regExPattern = Pattern.compile(argument.pattern, argument.caseSensitive ? 0:Pattern.CASE_INSENSITIVE); >+ } >+ } >+ >+ >+ Argument argument; >+ Class type; >+ StringMatcher stringMatcher = null; >+ Pattern regExPattern = null; >+ >+ public boolean match(IContainer parent, IFileInfo fileInfo) { >+ if (type.equals(String.class)) { >+ String value = new String(); >+ if (argument.key.equals(KEY_NAME)) >+ value = fileInfo.getName(); >+ if (argument.key.equals(KEY_PROPJECT_RELATIVE_PATH)) >+ value = parent.getProjectRelativePath().append(fileInfo.getName()).toPortableString(); >+ if (argument.key.equals(KEY_LOCATION)) >+ value = parent.getLocation().append(fileInfo.getName()).toOSString(); >+ >+ if (stringMatcher != null) >+ return stringMatcher.match(value); >+ if (regExPattern != null) { >+ Matcher m = regExPattern.matcher(value); >+ return m.matches(); >+ } >+ } >+ if (type.equals(Integer.class)) { >+ int amount; >+ try { >+ amount = Integer.parseInt(argument.pattern); >+ } catch (NumberFormatException e) { >+ amount = 0; >+ } >+ if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) { >+ // OPERATOR_WITHIN >+ long time = 0; >+ if (argument.key.equals(KEY_LAST_MODIFIED)) { >+ IFileInfo info = fetchInfo(parent, fileInfo); >+ if (!info.exists()) >+ return false; >+ time = info.getLastModified(); >+ } >+ if (argument.key.equals(KEY_CREATED)) { >+ if (!fSupportsCreatedKey) >+ return false; >+ time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString()); >+ } >+ GregorianCalendar gc = new GregorianCalendar(); >+ gc.add(Calendar.SECOND,-amount); >+ Date when = gc.getTime(); >+ Date then = new Date(time); >+ return then.after(when); >+ } >+ if (argument.key.equals(KEY_LENGTH)) { >+ IFileInfo info = fetchInfo(parent, fileInfo); >+ if (!info.exists()) >+ return false; >+ if (argument.operator.equals(OPERATOR_EQUALS)) >+ return info.getLength() == amount; >+ if (argument.operator.equals(OPERATOR_LARGER_THAN)) >+ return info.getLength() > amount; >+ if (argument.operator.equals(OPERATOR_SMALLER_THAN)) >+ return info.getLength() < amount; >+ } >+ } >+ if (type.equals(Date.class)) { >+ long parameter = Long.parseLong(argument.pattern); >+ if (argument.key.equals(KEY_LAST_MODIFIED) || argument.key.equals(KEY_CREATED)) { >+ long time = 0; >+ if (argument.key.equals(KEY_LAST_MODIFIED)) { >+ IFileInfo info = fetchInfo(parent, fileInfo); >+ if (!info.exists()) >+ return false; >+ time = info.getLastModified(); >+ } >+ if (argument.key.equals(KEY_CREATED)) { >+ if (!fSupportsCreatedKey) >+ return false; >+ time = getFileCreationTime(parent.getLocation().append(fileInfo.getName()).toOSString()); >+ } >+ Date when = new Date(parameter); >+ Date then = new Date(time); >+ if (argument.operator.equals(OPERATOR_EQUALS)) >+ return roundToOneDay(time) == roundToOneDay(parameter); >+ if (argument.operator.equals(OPERATOR_BEFORE)) >+ return then.before(when); >+ if (argument.operator.equals(OPERATOR_AFTER)) >+ return then.after(when); >+ } >+ } >+ if (type.equals(Boolean.class)) { >+ boolean parameter = Boolean.valueOf(argument.pattern).booleanValue(); >+ if (argument.key.equals(KEY_IS_READONLY)) { >+ IFileInfo info = fetchInfo(parent, fileInfo); >+ if (!info.exists()) >+ return false; >+ return info.getAttribute(EFS.ATTRIBUTE_READ_ONLY) == parameter; >+ } >+ if (argument.key.equals(KEY_IS_SYMLINK)) { >+ IFileInfo info = fetchInfo(parent, fileInfo); >+ if (!info.exists()) >+ return false; >+ return info.getAttribute(EFS.ATTRIBUTE_SYMLINK) == parameter; >+ } >+ } >+ return false; >+ } >+ >+ private long roundToOneDay(long parameter) { >+ 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 >+ } >+ >+ private IFileInfo fetchInfo(IContainer parent, IFileInfo fileInfo) { >+ IFileStore fileStore; >+ try { >+ fileStore = EFS.getStore(parent.getLocationURI()); >+ } catch (CoreException e) { >+ return fileInfo; >+ } >+ IFileStore store = fileStore.getChild(fileInfo.getName()); >+ return store.fetchInfo(); >+ } >+ } >+ /** >+ * Creates a new factory for this filter type. >+ */ >+ public MultiMatcher() { >+ fSupportsCreatedKey = supportCreatedKey(); >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.core.resources.AbstractFileInfoMatcher#initialize(org.eclipse.core.resources.IProject, java.lang.Object) >+ */ >+ public void initialize(IProject project, Object arguments) throws CoreException { >+ try { >+ if ((arguments instanceof String) && ((String) arguments).length() > 0) >+ matcher = new MatcherCache((String) arguments); >+ } catch (PatternSyntaxException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e)); >+ } catch (NumberFormatException e) { >+ throw new CoreException(new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, Platform.PLUGIN_ERROR, e.getMessage(), e)); >+ } >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.core.resources.AbstractFileInfoMatcher#matches(org.eclipse.core.filesystem.IFileInfo) >+ */ >+ public boolean matches(IContainer parent, IFileInfo fileInfo) throws CoreException { >+ if (matcher != null) { >+ return matcher.match(parent, fileInfo); >+ } >+ return false; >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 301820
:
161429
|
163828
|
163829
|
163830
|
163831
|
163922
|
163923
|
163924
|
163925
|
163927
|
164035
|
164040
|
164141
|
164142
|
164143
|
164211
|
164212
|
164341
|
164343
|
164363
|
164439
|
164567
|
164582
|
164809
|
164836
|
164837