View | Details | Raw Unified | Return to bug 86973 | Differences between
and this patch

Collapse All | Expand All

(-)extensions/org/eclipse/ui/dialogs/FilteredResourcesSelectionDialog.java (-16 / +120 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2007 IBM Corporation and others.
2
 * Copyright (c) 2000, 2008 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 25-33 Link Here
25
import org.eclipse.core.resources.IWorkspace;
25
import org.eclipse.core.resources.IWorkspace;
26
import org.eclipse.core.resources.ResourcesPlugin;
26
import org.eclipse.core.resources.ResourcesPlugin;
27
import org.eclipse.core.runtime.CoreException;
27
import org.eclipse.core.runtime.CoreException;
28
import org.eclipse.core.runtime.IAdaptable;
29
import org.eclipse.core.runtime.IPath;
28
import org.eclipse.core.runtime.IProgressMonitor;
30
import org.eclipse.core.runtime.IProgressMonitor;
29
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
30
import org.eclipse.core.runtime.ListenerList;
32
import org.eclipse.core.runtime.ListenerList;
33
import org.eclipse.core.runtime.Path;
31
import org.eclipse.core.runtime.Status;
34
import org.eclipse.core.runtime.Status;
32
import org.eclipse.jface.action.Action;
35
import org.eclipse.jface.action.Action;
33
import org.eclipse.jface.action.IAction;
36
import org.eclipse.jface.action.IAction;
Lines 40-45 Link Here
40
import org.eclipse.jface.viewers.ILabelDecorator;
43
import org.eclipse.jface.viewers.ILabelDecorator;
41
import org.eclipse.jface.viewers.ILabelProviderListener;
44
import org.eclipse.jface.viewers.ILabelProviderListener;
42
import org.eclipse.jface.viewers.ISelection;
45
import org.eclipse.jface.viewers.ISelection;
46
import org.eclipse.jface.viewers.IStructuredSelection;
43
import org.eclipse.jface.viewers.LabelProvider;
47
import org.eclipse.jface.viewers.LabelProvider;
44
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
48
import org.eclipse.jface.viewers.LabelProviderChangedEvent;
45
import org.eclipse.jface.viewers.Viewer;
49
import org.eclipse.jface.viewers.Viewer;
Lines 95-102 Link Here
95
99
96
	private String title;
100
	private String title;
97
101
102
	protected ResourceFilter filter;
103
98
	private IContainer container;
104
	private IContainer container;
99
105
106
	/** The Container to use for searching for relative resources */
107
	private IContainer searchContainer;
108
100
	private int typeMask;
109
	private int typeMask;
101
110
102
	private boolean isDerived;
111
	private boolean isDerived;
Lines 123-128 Link Here
123
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
132
		PlatformUI.getWorkbench().getHelpSystem().setHelp(shell,
124
				IIDEHelpContextIds.OPEN_RESOURCE_DIALOG);
133
				IIDEHelpContextIds.OPEN_RESOURCE_DIALOG);
125
134
135
136
		/*
137
		 * Allow location of paths relative to "searchContainer"
138
		 *  - searchContainer is the container of the currently active editor
139
		 *  - or the first container found as a result of querying the selection service
140
		 */
141
		IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
142
		if (ww != null) {
143
			Object[] selection = new Object[0];
144
			ISelection isel = ww.getSelectionService().getSelection();
145
			// Search for an Active Editor
146
			if (ww.getActivePage() != null)
147
				if (ww.getActivePage().getActiveEditor() != null)
148
					selection = new Object[] {ww.getActivePage().getActiveEditor().getEditorInput()};
149
			// Else get active selection if IStructuredSelection
150
			if (selection.length == 0 && isel instanceof IStructuredSelection)
151
				selection = ((IStructuredSelection)isel).toArray();
152
153
			// Iterate over the Objects trying to adapt them to IResource
154
			for (int i = 0 ; i < selection.length ; ++i) {
155
				if (selection[i] instanceof IAdaptable) {
156
					IResource res = (IResource)((IAdaptable)selection[i]).getAdapter(IResource.class);
157
					if (res != null) {
158
						if (res instanceof IContainer) 
159
							searchContainer = (IContainer)res;
160
						else
161
							searchContainer = res.getParent();
162
						break;
163
					}
164
				}
165
			}
166
		}
167
		if (searchContainer == null)
168
			searchContainer = container;
169
126
		this.container = container;
170
		this.container = container;
127
		this.typeMask = typesMask;
171
		this.typeMask = typesMask;
128
172
Lines 375-381 Link Here
375
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
419
	 * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
376
	 */
420
	 */
377
	protected ItemsFilter createFilter() {
421
	protected ItemsFilter createFilter() {
378
		return new ResourceFilter(container, isDerived, typeMask);
422
		filter = new ResourceFilter(container, searchContainer, isDerived, typeMask);
423
		return filter;
379
	}
424
	}
380
425
381
	/* (non-Javadoc)
426
	/* (non-Javadoc)
Lines 405-415 Link Here
405
				IResource resource2 = (IResource) o2;
450
				IResource resource2 = (IResource) o2;
406
				String s1 = resource1.getName();
451
				String s1 = resource1.getName();
407
				String s2 = resource2.getName();
452
				String s2 = resource2.getName();
453
				// Compare their names
408
				int comparability = collator.compare(s1, s2);
454
				int comparability = collator.compare(s1, s2);
409
				if (comparability == 0) {
455
				if (comparability == 0) {
410
					s1 = resource1.getFullPath().toString();
456
411
					s2 = resource2.getFullPath().toString();
457
					// Sort resource relative first
412
					comparability = collator.compare(s1, s2);
458
					if ((filter.matchesResourceRelativeFilter(resource1) && 
459
							!filter.matchesResourceRelativeFilter(resource2)) ||
460
						(filter.matchesResourceRelativeFilter(resource2) && 
461
							!filter.matchesResourceRelativeFilter(resource1))) {
462
						if (filter.matchesResourceRelativeFilter(resource1))
463
							return -1;
464
						return 1;
465
					}
466
467
					// Finall compare fullpaths; shorter paths sorted first
468
					IPath p1 = resource1.getFullPath();
469
					IPath p2 = resource2.getFullPath();
470
					int c1 = p1.segmentCount();
471
					int c2 = p2.segmentCount();
472
					for (int i= 0; i < c1 && i < c2; i++) {
473
						comparability = collator.compare(p1.segment(i), p2.segment(i));
474
						if (comparability != 0)
475
							return comparability;
476
					}
477
					comparability = c2 - c1;
413
				}
478
				}
414
479
415
				return comparability;
480
				return comparability;
Lines 744-749 Link Here
744
809
745
		private IContainer filterContainer;
810
		private IContainer filterContainer;
746
811
812
		/** Search pattern for resource relative lookups */
813
		protected SearchPattern resourceRelativePattern = new SearchPattern();
814
747
		private int filterTypeMask;
815
		private int filterTypeMask;
748
816
749
		/**
817
		/**
Lines 754-775 Link Here
754
		 *            flag which determine showing derived elements
822
		 *            flag which determine showing derived elements
755
		 * @param typeMask
823
		 * @param typeMask
756
		 */
824
		 */
757
		public ResourceFilter(IContainer container, boolean showDerived,
825
		public ResourceFilter(IContainer container, IContainer searchContainer, 
758
				int typeMask) {
826
				boolean showDerived, int typeMask) {
759
			super();
827
			super();
760
			this.filterContainer = container;
828
			this.filterContainer = container;
761
			this.showDerived = showDerived;
829
			this.showDerived = showDerived;
762
			this.filterTypeMask = typeMask;
830
			this.filterTypeMask = typeMask;
831
832
			String stringPattern = getPattern();
833
834
			// If pattern looks relative then add path
835
			stringPattern = searchContainer.getFullPath()
836
								.append(stringPattern).toOSString();
837
			resourceRelativePattern.setPattern(stringPattern);
763
		}
838
		}
764
839
765
		/**
840
		/**
766
		 * Creates new ResourceFilter instance
841
		 * Creates new ResourceFilter instance
767
		 */
842
		 */
768
		public ResourceFilter() {
843
		public ResourceFilter() {
769
			super();
844
			this(container, searchContainer, isDerived, typeMask);
770
			this.filterContainer = container;
845
		}
771
			this.showDerived = isDerived;
846
772
			this.filterTypeMask = typeMask;
847
		/**
848
		 * Creates new Resource Filter which additionally filters
849
		 * on resource relative path
850
		 * 
851
		 * @param searchPattern
852
		 *            the pattern to be used when filtering
853
		 */
854
		public ResourceFilter(SearchPattern searchPattern) {
855
			super (searchPattern);
773
		}
856
		}
774
857
775
		/**
858
		/**
Lines 783-789 Link Here
783
				return false;
866
				return false;
784
			}
867
			}
785
			IResource resource = (IResource) item;
868
			IResource resource = (IResource) item;
786
			if (this.filterContainer.findMember(resource.getFullPath()) != null)
869
			if (this.filterContainer.getFullPath().isPrefixOf(resource.getFullPath()))
787
				return true;
870
				return true;
788
			return false;
871
			return false;
789
		}
872
		}
Lines 802-808 Link Here
802
			if ((!this.showDerived && resource.isDerived())
885
			if ((!this.showDerived && resource.isDerived())
803
					|| ((this.filterTypeMask & resource.getType()) == 0))
886
					|| ((this.filterTypeMask & resource.getType()) == 0))
804
				return false;
887
				return false;
805
			return matches(resource.getName());
888
889
			if (matches(resource.getName()) || 
890
					// Allow matching of full path
891
					matches (resource.getFullPath().toOSString()) ||
892
					// Allow matching of path relative to current selection
893
					matchesResourceRelativeFilter(resource))
894
				return true;
895
			
896
			return false;			
897
		}
898
899
		/**
900
		 * Return true if the passed in item matches the resource relative filter
901
		 * @param item
902
		 * @return
903
		 */
904
		public boolean matchesResourceRelativeFilter(IResource item) {
905
			return resourceRelativePattern.matches(item.getFullPath().toOSString());
806
		}
906
		}
807
907
808
		/*
908
		/*
Lines 813-821 Link Here
813
		public boolean isSubFilter(ItemsFilter filter) {
913
		public boolean isSubFilter(ItemsFilter filter) {
814
			if (!super.isSubFilter(filter))
914
			if (!super.isSubFilter(filter))
815
				return false;
915
				return false;
816
			if (filter instanceof ResourceFilter)
916
			if (filter instanceof ResourceFilter && 
817
				if (this.showDerived == ((ResourceFilter) filter).showDerived)
917
					this.showDerived == ((ResourceFilter) filter).showDerived) {
818
					return true;
918
				// super.isSubFilter checks whether this pattern is more general than 'filter' pattern
919
				// Also check that the resource relative filter. For relative paths ../../ etc.
920
				IPath otherPath = new Path(((ResourceFilter)filter).resourceRelativePattern.getPattern());
921
				return (otherPath.segmentCount() >= new Path(resourceRelativePattern.getPattern()).segmentCount());
922
			}
819
			return false;
923
			return false;
820
		}
924
		}
821
925
(-)extensions/org/eclipse/ui/actions/BuildAction.java (-2 / +1 lines)
Lines 279-286 Link Here
279
279
280
	    // Save all resources prior to doing build
280
	    // Save all resources prior to doing build
281
        BuildUtilities.saveEditors(projects);
281
        BuildUtilities.saveEditors(projects);
282
        runInBackground(ResourcesPlugin.getWorkspace().getRuleFactory()
282
        runInBackground(null, ResourcesPlugin.FAMILY_MANUAL_BUILD);
283
                .buildRule(), ResourcesPlugin.FAMILY_MANUAL_BUILD);
284
    }
283
    }
285
284
286
    /* (non-Javadoc)
285
    /* (non-Javadoc)

Return to bug 86973