View | Details | Raw Unified | Return to bug 332502
Collapse All | Expand All

(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java (+7 lines)
Lines 9-14 Link Here
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
10
 *     Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
11
 *     Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
11
 *     Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
12
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
12
 *******************************************************************************/
13
 *******************************************************************************/
13
package org.eclipse.search.internal.ui;
14
package org.eclipse.search.internal.ui;
14
15
Lines 209-212 Link Here
209
	public static String TextSearchEngineRegistry_defaulttextsearch_label;
210
	public static String TextSearchEngineRegistry_defaulttextsearch_label;
210
	public static String FileSearchQuery_singularPatternWithFileExt;
211
	public static String FileSearchQuery_singularPatternWithFileExt;
211
	public static String FileSearchQuery_pluralPatternWithFileExt;
212
	public static String FileSearchQuery_pluralPatternWithFileExt;
213
	
214
	// added for bug 332502
215
	/*public static String FileSearchPageLocationColumn_label;*/
216
	public static String FileSearchPageMatchColumn_label;
217
	public static String FileSearchPageFilenameColumn_label;
218
	/*public static String FileSearchPageLineNumberColumn_label;*/
212
}
219
}
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties (+6 lines)
Lines 9-14 Link Here
9
#     IBM Corporation - initial API and implementation
9
#     IBM Corporation - initial API and implementation
10
#     Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
10
#     Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search
11
#     Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
11
#     Marco Descher <marco@descher.at> - Open Search dialog with previous page instead of using the current selection to detect the page - http://bugs.eclipse.org/33710
12
#     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
12
###############################################################################
13
###############################################################################
13
14
14
SearchDialog_title= Search
15
SearchDialog_title= Search
Lines 244-246 Link Here
244
245
245
OpenWithMenu_label= Open Wit&h
246
OpenWithMenu_label= Open Wit&h
246
247
248
# added for bug 332502
249
#FileSearchPageLocationColumn_label= Location
250
FileSearchPageMatchColumn_label= Match
251
#FileSearchPageLineNumberColumn_label= Line Number
252
FileSearchPageFilenameColumn_label= File Name
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchLabelProvider.java (+197 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014, Juniper Networks, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Juniper Networks - initial API and implementation
10
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
11
 *******************************************************************************/
12
package org.eclipse.search.internal.ui.text;
13
14
import java.util.Arrays;
15
import java.util.Comparator;
16
17
import org.eclipse.swt.SWT;
18
19
import org.eclipse.core.resources.IResource;
20
21
import org.eclipse.jface.viewers.StyledCellLabelProvider;
22
import org.eclipse.jface.viewers.StyledString;
23
24
import org.eclipse.search.internal.ui.Messages;
25
import org.eclipse.search.internal.ui.SearchMessages;
26
import org.eclipse.search.ui.text.AbstractTextSearchViewPage;
27
import org.eclipse.search.ui.text.Match;
28
29
public class FileSearchLabelProvider extends FileLabelProvider {
30
31
	private static final String fgSeparatorFormat= "{0} - {1}"; //$NON-NLS-1$
32
33
	private static final String fgEllipses= " ... "; //$NON-NLS-1$
34
35
	private final AbstractTextSearchViewPage fPage;
36
	private final Comparator fMatchComparator;
37
38
	private int fOrder;
39
40
	public FileSearchLabelProvider(AbstractTextSearchViewPage page, int orderFlag) {
41
		super(page, orderFlag);
42
		fOrder= orderFlag;
43
		fPage= page;
44
		fMatchComparator= new Comparator() {
45
			public int compare(Object o1, Object o2) {
46
				return ((FileMatch) o1).getOriginalOffset() - ((FileMatch) o2).getOriginalOffset();
47
			}
48
		};
49
	}
50
51
	public void setOrder(int orderFlag) {
52
		super.setOrder(orderFlag);
53
		fOrder= orderFlag;
54
	}
55
56
	public int getOrder() {
57
		return fOrder;
58
	}
59
60
	/* (non-Javadoc)
61
	 * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object)
62
	 */
63
	public String getText(Object object) {
64
		return getStyledText(object).getString();
65
	}
66
67
	public StyledString getStyledText(Object element) {
68
		if (element instanceof LineElement)
69
			return getLineElementLabel((LineElement) element);
70
71
		if (!(element instanceof IResource))
72
			return new StyledString();
73
74
		IResource resource= (IResource) element;
75
		if (!resource.exists())
76
			new StyledString(SearchMessages.FileLabelProvider_removed_resource_label);
77
78
		
79
		String name= BasicElementLabels.getResourceName(resource);
80
		if (fOrder == SHOW_LABEL) {
81
			return new StyledString(name);
82
		}
83
84
		String pathString= BasicElementLabels.getPathLabel(resource.getParent().getFullPath(), false);
85
		if (fOrder == SHOW_LABEL_PATH) {
86
			StyledString str= new StyledString(name);
87
			String decorated= Messages.format(fgSeparatorFormat, new String[] { str.getString(), pathString });
88
89
			StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, str);
90
			return str;
91
		}
92
93
		StyledString str= new StyledString(Messages.format(fgSeparatorFormat, new String[] { pathString, name }));
94
		return str;
95
	}
96
97
	private StyledString getLineElementLabel(LineElement lineElement) {
98
		int lineNumber= lineElement.getLine();
99
		String lineNumberString= Messages.format(SearchMessages.FileLabelProvider_line_number, new Integer(lineNumber));
100
101
		StyledString str= new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER);
102
103
		Match[] matches= lineElement.getMatches(fPage.getInput());
104
		Arrays.sort(matches, fMatchComparator);
105
106
		String content= lineElement.getContents();
107
108
		int pos= evaluateLineStart(matches, content, lineElement.getOffset());
109
110
		int length= content.length();
111
112
		int charsToCut= getCharsToCut(length, matches); // number of characters to leave away if the line is too long
113
		for (int i= 0; i < matches.length; i++) {
114
			FileMatch match= (FileMatch) matches[i];
115
			int start= Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0);
116
			// append gap between last match and the new one
117
			if (pos < start) {
118
				if (charsToCut > 0) {
119
					charsToCut= appendShortenedGap(content, pos, start, charsToCut, i == 0, str);
120
				} else {
121
					str.append(content.substring(pos, start));
122
				}
123
			}
124
			// append match
125
			int end= Math.min(match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(), lineElement.getLength());
126
			str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE);
127
			pos= end;
128
		}
129
		// append rest of the line
130
		if (charsToCut > 0) {
131
			appendShortenedGap(content, pos, length, charsToCut, false, str);
132
		} else {
133
			str.append(content.substring(pos));
134
		}
135
		return str;
136
	}
137
138
	private static final int MIN_MATCH_CONTEXT= 10; // minimal number of characters shown after and before a match
139
140
	private int appendShortenedGap(String content, int start, int end, int charsToCut, boolean isFirst, StyledString str) {
141
		int gapLength= end - start;
142
		if (!isFirst) {
143
			gapLength-= MIN_MATCH_CONTEXT;
144
		}
145
		if (end < content.length()) {
146
			gapLength-= MIN_MATCH_CONTEXT;
147
		}
148
		if (gapLength < MIN_MATCH_CONTEXT) { // don't cut, gap is too small
149
			str.append(content.substring(start, end));
150
			return charsToCut;
151
		}
152
153
		int context= MIN_MATCH_CONTEXT;
154
		if (gapLength > charsToCut) {
155
			context+= gapLength - charsToCut;
156
		}
157
158
		if (!isFirst) {
159
			str.append(content.substring(start, start + context)); // give all extra context to the right side of a match
160
			context= MIN_MATCH_CONTEXT;
161
		}
162
163
		str.append(fgEllipses, StyledString.QUALIFIER_STYLER);
164
165
		if (end < content.length()) {
166
			str.append(content.substring(end - context, end));
167
		}
168
		return charsToCut - gapLength + fgEllipses.length();
169
	}
170
171
172
	private int getCharsToCut(int contentLength, Match[] matches) {
173
		if (contentLength <= 256 || !"win32".equals(SWT.getPlatform()) || matches.length == 0) { //$NON-NLS-1$
174
			return 0; // no shortening required
175
		}
176
		// XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=38519
177
		return contentLength - 256 + Math.max(matches.length * fgEllipses.length(), 100);
178
	}
179
180
	private int evaluateLineStart(Match[] matches, String lineContent, int lineOffset) {
181
		int max= lineContent.length();
182
		if (matches.length > 0) {
183
			FileMatch match= (FileMatch) matches[0];
184
			max= match.getOriginalOffset() - lineOffset;
185
			if (max < 0) {
186
				return 0;
187
			}
188
		}
189
		for (int i= 0; i < max; i++) {
190
			char ch= lineContent.charAt(i);
191
			if (!Character.isWhitespace(ch) || ch == '\n' || ch == '\r') {
192
				return i;
193
			}
194
		}
195
		return max;
196
	}
197
}
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchListLabelProvider.java (+81 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014, Juniper Networks, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Juniper Networks - initial API and implementation
10
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
11
 *******************************************************************************/
12
package org.eclipse.search.internal.ui.text;
13
14
import java.util.Arrays;
15
16
import org.eclipse.swt.custom.StyleRange;
17
18
import org.eclipse.core.resources.IResource;
19
20
import org.eclipse.jface.viewers.StyledString;
21
import org.eclipse.jface.viewers.ViewerCell;
22
23
public class FileSearchListLabelProvider extends
24
		DecoratingFileSearchLabelProvider {
25
26
	private final int fColumnIndex;
27
	
28
	public FileSearchListLabelProvider(FileLabelProvider provider, int columnIndex) {
29
		super(provider);
30
		fColumnIndex = columnIndex;
31
	}
32
	
33
	public void update(ViewerCell cell) {
34
		LineElement element = (LineElement)cell.getElement();
35
		IResource res = element.getParent();
36
		switch (fColumnIndex) {
37
		case FileSearchPage.FILE_NAME_COLUMN_INDEX:
38
			updateCell(cell, res);
39
			break;
40
/*		case FileSearchPage.LOCATION_COLUMN_INDEX:
41
			//cell.setText(getText(res.getParent()));
42
			updateCell(cell, res.getParent());
43
			break;
44
		case FileSearchPage.LINE_NUMBER_COLUMN_INDEX:
45
			cell.setText("Line " + ((LineElement)element).getLine());
46
			//updateCell(cell, res);
47
			break;*/
48
		case FileSearchPage.MATCH_COLUMN_INDEX:
49
			updateCell(cell, element);
50
			break;
51
		default:
52
			cell.setText(""); //$NON-NLS-1$
53
			break;
54
		}
55
	}
56
	
57
	public void updateCell(ViewerCell cell, Object element) {
58
		StyledString styledString = getStyledText(element);
59
		String newText= styledString.toString();
60
		
61
		StyleRange[] oldStyleRanges= cell.getStyleRanges();
62
		StyleRange[] newStyleRanges= isOwnerDrawEnabled() ? styledString.getStyleRanges() : null;
63
		
64
		if (!Arrays.equals(oldStyleRanges, newStyleRanges)) {
65
			cell.setStyleRanges(newStyleRanges);
66
			if (cell.getText().equals(newText)) {
67
				// make sure there will be a refresh from a change
68
				cell.setText(""); //$NON-NLS-1$
69
			}
70
		}
71
		
72
		cell.setText(newText);
73
		cell.setImage(getImage(element));
74
		cell.setFont(getFont(element));
75
		cell.setForeground(getForeground(element));
76
		cell.setBackground(getBackground(element));
77
		
78
		// no super call required. changes on item will trigger the refresh.
79
	}
80
81
}
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java (-4 / +92 lines)
Lines 10-15 Link Here
10
 *     Juerg Billeter, juergbi@ethz.ch - 47136 Search view should show match objects
10
 *     Juerg Billeter, juergbi@ethz.ch - 47136 Search view should show match objects
11
 *     Ulrich Etter, etteru@ethz.ch - 47136 Search view should show match objects
11
 *     Ulrich Etter, etteru@ethz.ch - 47136 Search view should show match objects
12
 *     Roman Fuchs, fuchsro@ethz.ch - 47136 Search view should show match objects
12
 *     Roman Fuchs, fuchsro@ethz.ch - 47136 Search view should show match objects
13
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
13
 *******************************************************************************/
14
 *******************************************************************************/
14
package org.eclipse.search.internal.ui.text;
15
package org.eclipse.search.internal.ui.text;
15
16
Lines 18-25 Link Here
18
import java.util.Iterator;
19
import java.util.Iterator;
19
import java.util.Set;
20
import java.util.Set;
20
21
22
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.dnd.DND;
23
import org.eclipse.swt.dnd.DND;
22
import org.eclipse.swt.dnd.Transfer;
24
import org.eclipse.swt.dnd.Transfer;
25
import org.eclipse.swt.events.SelectionAdapter;
26
import org.eclipse.swt.events.SelectionEvent;
27
import org.eclipse.swt.widgets.Composite;
28
import org.eclipse.swt.widgets.Table;
29
import org.eclipse.swt.widgets.TableColumn;
23
30
24
import org.eclipse.core.runtime.IAdaptable;
31
import org.eclipse.core.runtime.IAdaptable;
25
32
Lines 38-43 Link Here
38
import org.eclipse.jface.viewers.StructuredSelection;
45
import org.eclipse.jface.viewers.StructuredSelection;
39
import org.eclipse.jface.viewers.StructuredViewer;
46
import org.eclipse.jface.viewers.StructuredViewer;
40
import org.eclipse.jface.viewers.TableViewer;
47
import org.eclipse.jface.viewers.TableViewer;
48
import org.eclipse.jface.viewers.TableViewerColumn;
41
import org.eclipse.jface.viewers.TreeViewer;
49
import org.eclipse.jface.viewers.TreeViewer;
42
import org.eclipse.jface.viewers.Viewer;
50
import org.eclipse.jface.viewers.Viewer;
43
import org.eclipse.jface.viewers.ViewerComparator;
51
import org.eclipse.jface.viewers.ViewerComparator;
Lines 127-133 Link Here
127
			return SHOW_IN_TARGETS;
135
			return SHOW_IN_TARGETS;
128
		}
136
		}
129
	};
137
	};
138
	
139
	// modified for bug 332502
140
	public static final int FILE_NAME_COLUMN_INDEX = 0;
141
/*	public static final int LOCATION_COLUMN_INDEX = 1;
142
	public static final int LINE_NUMBER_COLUMN_INDEX = 2;*/
143
	public static final int MATCH_COLUMN_INDEX = 1;
130
144
145
	private static final String[] fColumnLabels = new String[] { 
146
		SearchMessages.FileSearchPageFilenameColumn_label,
147
/*		SearchMessages.FileSearchPageLocationColumn_label,
148
		SearchMessages.FileSearchPageLineNumberColumn_label,*/
149
		SearchMessages.FileSearchPageMatchColumn_label
150
	};
151
	
152
	private final int[] fColumnWidths = { /*150,*/ 300, /*100,*/ 300 };
153
	private FileSearchTableViewerComparator comparator;
154
	
131
	public FileSearchPage() {
155
	public FileSearchPage() {
132
		fSortByNameAction= new SortAction(SearchMessages.FileSearchPage_sort_name_label, this, FileLabelProvider.SHOW_LABEL_PATH);
156
		fSortByNameAction= new SortAction(SearchMessages.FileSearchPage_sort_name_label, this, FileLabelProvider.SHOW_LABEL_PATH);
133
		fSortByPathAction= new SortAction(SearchMessages.FileSearchPage_sort_path_label, this, FileLabelProvider.SHOW_PATH_LABEL);
157
		fSortByPathAction= new SortAction(SearchMessages.FileSearchPage_sort_path_label, this, FileLabelProvider.SHOW_PATH_LABEL);
Lines 153-162 Link Here
153
177
154
	protected void configureTableViewer(TableViewer viewer) {
178
	protected void configureTableViewer(TableViewer viewer) {
155
		viewer.setUseHashlookup(true);
179
		viewer.setUseHashlookup(true);
156
		FileLabelProvider innerLabelProvider= new FileLabelProvider(this, fCurrentSortOrder);
180
		// modified for bug 332502
157
		viewer.setLabelProvider(new DecoratingFileSearchLabelProvider(innerLabelProvider));
181
		FileLabelProvider innerLabelProvider= new FileSearchLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH);
182
		FileSearchListLabelProvider labelProvider = new FileSearchListLabelProvider(innerLabelProvider, 0);
183
		viewer.setLabelProvider(labelProvider);
184
		createColumns(viewer, innerLabelProvider);
158
		viewer.setContentProvider(new FileTableContentProvider(this));
185
		viewer.setContentProvider(new FileTableContentProvider(this));
159
		viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider));
186
		comparator = new FileSearchTableViewerComparator(innerLabelProvider);
187
		viewer.setComparator(comparator);
160
		fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
188
		fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider();
161
		addDragAdapters(viewer);
189
		addDragAdapters(viewer);
162
	}
190
	}
Lines 195-200 Link Here
195
				}
223
				}
196
			}
224
			}
197
		}
225
		}
226
		// modified for bug 332502
227
		if(getLayout() == FLAG_LAYOUT_FLAT){
228
			Object firstElement= ((IStructuredSelection)event.getSelection()).getFirstElement();
229
			if (firstElement instanceof LineElement) {
230
				IFile file = (IFile) ((LineElement)firstElement).getParent();
231
				try {
232
					open(getSite().getPage(), file, false);
233
				} catch (PartInitException e) {
234
					ErrorDialog.openError(getSite().getShell(), SearchMessages.FileSearchPage_open_file_dialog_title, SearchMessages.FileSearchPage_open_file_failed, e.getStatus());
235
				}
236
				return;
237
			}
238
		}			
198
		super.handleOpen(event);
239
		super.handleOpen(event);
199
	}
240
	}
200
241
Lines 372-377 Link Here
372
			}
413
			}
373
			return new Match[0];
414
			return new Match[0];
374
		}
415
		}
416
		// modified for bug 332502
417
		if (element instanceof LineElement) {
418
			LineElement lineEntry= (LineElement) element;
419
			return lineEntry.getMatches(getInput());
420
		}
375
		return super.getDisplayedMatches(element);
421
		return super.getDisplayedMatches(element);
376
	}
422
	}
377
423
Lines 381-387 Link Here
381
				changedElements.add(((FileMatch) matches[i]).getLineElement());
427
				changedElements.add(((FileMatch) matches[i]).getLineElement());
382
			}
428
			}
383
		} else {
429
		} else {
384
			super.evaluateChangedElements(matches, changedElements);
430
			// modified for bug 332502
431
			for (int i = 0; i < matches.length; i++) {
432
				changedElements.add(((FileMatch) matches[i]).getLineElement());
433
			}
434
			//super.evaluateChangedElements(matches, changedElements);
385
		}
435
		}
386
	}
436
	}
387
437
Lines 389-393 Link Here
389
		AbstractTextSearchResult input= getInput();
439
		AbstractTextSearchResult input= getInput();
390
		return getLayout() == FLAG_LAYOUT_TREE && input != null && !((FileSearchQuery) input.getQuery()).isFileNameSearch();
440
		return getLayout() == FLAG_LAYOUT_TREE && input != null && !((FileSearchQuery) input.getQuery()).isFileNameSearch();
391
	}
441
	}
442
	
443
	// added for bug 332502
444
	protected TableViewer createTableViewer(Composite parent) {
445
		TableViewer tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
446
		return tableViewer;
447
	}
448
	
449
	// added for bug 332502
450
	private void createColumns(TableViewer viewer, FileLabelProvider innerLabelProvider) {
451
		for (int i = 0; i < fColumnLabels.length; i++) {
452
			TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
453
			viewerColumn.setLabelProvider(new FileSearchListLabelProvider(innerLabelProvider, i));
454
			TableColumn tableColumn = viewerColumn.getColumn();
455
			tableColumn.setText(fColumnLabels[i]);
456
			tableColumn.setWidth(fColumnWidths[i]);
457
			tableColumn.setResizable(true);
458
			tableColumn.setMoveable(false);
459
			tableColumn.addSelectionListener(getSelectionAdapter(viewer, tableColumn, i));
460
		}
461
		Table table = viewer.getTable();
462
		table.setHeaderVisible(true);
463
		table.setLinesVisible(true);
464
	}
465
	
466
	// added for bug 332502
467
	private SelectionAdapter getSelectionAdapter(final TableViewer viewer,
468
			final TableColumn column, final int index) {
469
		SelectionAdapter selectionAdapter = new SelectionAdapter() {
470
			public void widgetSelected(SelectionEvent e) {
471
				comparator.setColumn(index);
472
				int dir = comparator.getDirection();
473
				viewer.getTable().setSortDirection(dir);
474
				viewer.getTable().setSortColumn(column);
475
				viewer.refresh();
476
			}
477
		};
478
		return selectionAdapter;
479
	}
392
480
393
}
481
}
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchTableViewerComparator.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2014, Juniper Networks, Inc.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Juniper Networks - initial API and implementation
10
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
11
 *******************************************************************************/
12
package org.eclipse.search.internal.ui.text;
13
14
import org.eclipse.core.resources.IContainer;
15
import org.eclipse.core.resources.IResource;
16
import org.eclipse.jface.viewers.Viewer;
17
import org.eclipse.jface.viewers.ViewerComparator;
18
import org.eclipse.swt.SWT;
19
20
public class FileSearchTableViewerComparator extends ViewerComparator {
21
	private int columnIndex = 0;
22
	private static final int DESC = 1;
23
	private static final int ASC = 0;
24
	private int fSortDirection = ASC;
25
	private FileLabelProvider fLabelProvider;
26
27
	public FileSearchTableViewerComparator(FileLabelProvider innerLabelProvider) {
28
		fLabelProvider = innerLabelProvider;
29
	}
30
31
	public int getDirection() {
32
		return fSortDirection == 1 ? SWT.DOWN : SWT.UP;
33
	}
34
35
	public void setColumn(int column) {
36
		// if the column is same as the last sorted column
37
		if (column == this.columnIndex) {
38
			// toggle the direction
39
			if(fSortDirection == DESC)
40
				fSortDirection = ASC;
41
			else
42
				fSortDirection = DESC;
43
		} else {
44
			// if its a new column, then do an ascending sort
45
			this.columnIndex = column;
46
			fSortDirection = ASC;
47
		}
48
	}
49
50
	public int category(Object element) {
51
		if (element instanceof IContainer) {
52
			return 1;
53
		}
54
		return 2;
55
	}
56
57
	public int compare(Viewer viewer, Object e1, Object e2) {
58
		int result = 0;
59
		int cat1 = category(e1);
60
		int cat2 = category(e2);
61
62
		if (cat1 != cat2) {
63
			return cat1 - cat2;
64
		}
65
66
		if (e1 instanceof LineElement && e2 instanceof LineElement) {
67
			LineElement m1 = (LineElement) e1;
68
			LineElement m2 = (LineElement) e2;
69
			IResource res1 = m1.getParent();
70
			IResource res2 = m2.getParent();
71
72
			switch (columnIndex) {
73
			case FileSearchPage.FILE_NAME_COLUMN_INDEX:		        
74
		        result = compareObject(res1, res2);
75
				break;
76
/*			case FileSearchPage.LOCATION_COLUMN_INDEX:
77
				result = res1.getFullPath().toString()
78
						.compareTo(res2.getFullPath().toString());
79
				break;
80
			case FileSearchPage.LINE_NUMBER_COLUMN_INDEX:
81
				result = new Integer(m1.getLine()).compareTo(new Integer(m2
82
						.getLine()));
83
				break;*/
84
			case FileSearchPage.MATCH_COLUMN_INDEX:
85
		        result = compareObject(m1, m2);
86
				break;
87
			default:
88
				result = 0;
89
			}
90
			// If the sorted direction is descending then change the direction
91
			if (fSortDirection == DESC) {
92
				result = -1*result;
93
			}
94
		}
95
		return result;
96
	}
97
98
	private int compareObject(Object obj1, Object obj2) {
99
		String name1= fLabelProvider.getText(obj1);
100
        String name2= fLabelProvider.getText(obj2);
101
		int result;
102
		if (name1 == null)
103
		    name1 = "";//$NON-NLS-1$
104
		if (name2 == null)
105
		    name2 = "";//$NON-NLS-1$
106
		result = getComparator().compare(name1, name2);
107
		return result;
108
	}
109
}
(-)a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTableContentProvider.java (-10 / +43 lines)
Lines 7-20 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.search.internal.ui.text;
12
package org.eclipse.search.internal.ui.text;
13
14
import java.util.ArrayList;
15
import java.util.List;
12
16
13
import org.eclipse.jface.viewers.IStructuredContentProvider;
17
import org.eclipse.jface.viewers.IStructuredContentProvider;
14
import org.eclipse.jface.viewers.TableViewer;
18
import org.eclipse.jface.viewers.TableViewer;
15
import org.eclipse.jface.viewers.Viewer;
19
import org.eclipse.jface.viewers.Viewer;
16
17
import org.eclipse.search.ui.text.AbstractTextSearchResult;
20
import org.eclipse.search.ui.text.AbstractTextSearchResult;
21
import org.eclipse.search.ui.text.Match;
18
22
19
public class FileTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider {
23
public class FileTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider {
20
24
Lines 34-46 Link Here
34
	public Object[] getElements(Object inputElement) {
38
	public Object[] getElements(Object inputElement) {
35
		if (inputElement instanceof FileSearchResult) {
39
		if (inputElement instanceof FileSearchResult) {
36
			int elementLimit= getElementLimit();
40
			int elementLimit= getElementLimit();
37
			Object[] elements= ((FileSearchResult)inputElement).getElements();
41
			// modified for bug 332502
38
			if (elementLimit != -1 && elements.length > elementLimit) {
42
			Object[] result = ((FileSearchResult)inputElement).getElements();
43
			List elements = new ArrayList();
44
			for (int i = 0; i < result.length; i++) {
45
				Match[] matches = ((FileSearchResult)inputElement).getMatches(result[i]);
46
					for (int j = 0; j < matches.length; j++) {
47
						if(matches[j] instanceof FileMatch){
48
							elements.add(((FileMatch)matches[j]).getLineElement());
49
						}
50
					}
51
			}
52
			
53
			if (elementLimit != -1 && elements.size() > elementLimit) {
39
				Object[] shownElements= new Object[elementLimit];
54
				Object[] shownElements= new Object[elementLimit];
40
				System.arraycopy(elements, 0, shownElements, 0, elementLimit);
55
				System.arraycopy(elements, 0, shownElements, 0, elementLimit);
41
				return shownElements;
56
				return shownElements;
42
			}
57
			}
43
			return elements;
58
			return elements.toArray();
44
		}
59
		}
45
		return EMPTY_ARR;
60
		return EMPTY_ARR;
46
	}
61
	}
Lines 56-67 Link Here
56
		int elementLimit= getElementLimit();
71
		int elementLimit= getElementLimit();
57
		boolean tableLimited= elementLimit != -1;
72
		boolean tableLimited= elementLimit != -1;
58
		for (int i= 0; i < updatedElements.length; i++) {
73
		for (int i= 0; i < updatedElements.length; i++) {
59
			if (fResult.getMatchCount(updatedElements[i]) > 0) {
74
			// modified for bug 332502
60
				if (viewer.testFindItem(updatedElements[i]) != null)
75
			LineElement lineElement = (LineElement) updatedElements[i];
61
					viewer.update(updatedElements[i], null);
76
			if (fResult.getMatchCount(lineElement.getParent()) > 0) {
62
				else {
77
				boolean remove = true;
63
					if (!tableLimited || viewer.getTable().getItemCount() < elementLimit)
78
				Match[] matches = fResult.getMatches(lineElement.getParent());
64
						viewer.add(updatedElements[i]);
79
				for (int j = 0; j < matches.length; j++) {
80
					if (matches[j] instanceof FileMatch) {
81
						LineElement element = ((FileMatch) matches[j]).getLineElement();
82
						if(element.equals(lineElement)){
83
							remove = false;
84
							break;
85
						}
86
					}
87
				}
88
				if(!remove){
89
					if (viewer.testFindItem(lineElement) != null){
90
						viewer.update(lineElement, null);
91
					} else {
92
						if (!tableLimited || viewer.getTable().getItemCount() < elementLimit) {
93
							viewer.add(lineElement);
94
						}
95
					}
96
				}else{
97
					viewer.remove(updatedElements[i]);
65
				}
98
				}
66
			} else
99
			} else
67
				viewer.remove(updatedElements[i]);
100
				viewer.remove(updatedElements[i]);

Return to bug 332502