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 241620 Details for
Bug 332502
List view in Search pane does not show all found results as does the Tree view
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
patch
eclipse_search_patch (text/plain), 26.52 KB, created by
vishal
on 2014-04-04 12:43:09 EDT
(
hide
)
Description:
patch
Filename:
MIME Type:
Creator:
vishal
Created:
2014-04-04 12:43:09 EDT
Size:
26.52 KB
patch
obsolete
>diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java >index 2c0f9c6..c9bf0ad 100644 >--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.java >@@ -9,6 +9,7 @@ > * IBM Corporation - initial API and implementation > * Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search > * 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 >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 > *******************************************************************************/ > package org.eclipse.search.internal.ui; > >@@ -209,4 +210,10 @@ > public static String TextSearchEngineRegistry_defaulttextsearch_label; > public static String FileSearchQuery_singularPatternWithFileExt; > public static String FileSearchQuery_pluralPatternWithFileExt; >+ >+ // added for bug 332502 >+ /*public static String FileSearchPageLocationColumn_label;*/ >+ public static String FileSearchPageMatchColumn_label; >+ public static String FileSearchPageFilenameColumn_label; >+ /*public static String FileSearchPageLineNumberColumn_label;*/ > } >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties >index 4eee867..1c9d9fe 100644 >--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties >@@ -9,6 +9,7 @@ > # IBM Corporation - initial API and implementation > # Christian Walther (Indel AG) - Bug 399094: Add whole word option to file search > # 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 >+# Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 > ############################################################################### > > SearchDialog_title= Search >@@ -244,3 +245,8 @@ > > OpenWithMenu_label= Open Wit&h > >+# added for bug 332502 >+#FileSearchPageLocationColumn_label= Location >+FileSearchPageMatchColumn_label= Match >+#FileSearchPageLineNumberColumn_label= Line Number >+FileSearchPageFilenameColumn_label= File Name >\ No newline at end of file >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchLabelProvider.java >new file mode 100644 >index 0000000..b026d02 >--- /dev/null >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchLabelProvider.java >@@ -0,0 +1,197 @@ >+/******************************************************************************* >+ * Copyright (c) 2014, Juniper Networks, Inc. >+ * 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: >+ * Juniper Networks - initial API and implementation >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 >+ *******************************************************************************/ >+package org.eclipse.search.internal.ui.text; >+ >+import java.util.Arrays; >+import java.util.Comparator; >+ >+import org.eclipse.swt.SWT; >+ >+import org.eclipse.core.resources.IResource; >+ >+import org.eclipse.jface.viewers.StyledCellLabelProvider; >+import org.eclipse.jface.viewers.StyledString; >+ >+import org.eclipse.search.internal.ui.Messages; >+import org.eclipse.search.internal.ui.SearchMessages; >+import org.eclipse.search.ui.text.AbstractTextSearchViewPage; >+import org.eclipse.search.ui.text.Match; >+ >+public class FileSearchLabelProvider extends FileLabelProvider { >+ >+ private static final String fgSeparatorFormat= "{0} - {1}"; //$NON-NLS-1$ >+ >+ private static final String fgEllipses= " ... "; //$NON-NLS-1$ >+ >+ private final AbstractTextSearchViewPage fPage; >+ private final Comparator fMatchComparator; >+ >+ private int fOrder; >+ >+ public FileSearchLabelProvider(AbstractTextSearchViewPage page, int orderFlag) { >+ super(page, orderFlag); >+ fOrder= orderFlag; >+ fPage= page; >+ fMatchComparator= new Comparator() { >+ public int compare(Object o1, Object o2) { >+ return ((FileMatch) o1).getOriginalOffset() - ((FileMatch) o2).getOriginalOffset(); >+ } >+ }; >+ } >+ >+ public void setOrder(int orderFlag) { >+ super.setOrder(orderFlag); >+ fOrder= orderFlag; >+ } >+ >+ public int getOrder() { >+ return fOrder; >+ } >+ >+ /* (non-Javadoc) >+ * @see org.eclipse.jface.viewers.LabelProvider#getText(java.lang.Object) >+ */ >+ public String getText(Object object) { >+ return getStyledText(object).getString(); >+ } >+ >+ public StyledString getStyledText(Object element) { >+ if (element instanceof LineElement) >+ return getLineElementLabel((LineElement) element); >+ >+ if (!(element instanceof IResource)) >+ return new StyledString(); >+ >+ IResource resource= (IResource) element; >+ if (!resource.exists()) >+ new StyledString(SearchMessages.FileLabelProvider_removed_resource_label); >+ >+ >+ String name= BasicElementLabels.getResourceName(resource); >+ if (fOrder == SHOW_LABEL) { >+ return new StyledString(name); >+ } >+ >+ String pathString= BasicElementLabels.getPathLabel(resource.getParent().getFullPath(), false); >+ if (fOrder == SHOW_LABEL_PATH) { >+ StyledString str= new StyledString(name); >+ String decorated= Messages.format(fgSeparatorFormat, new String[] { str.getString(), pathString }); >+ >+ StyledCellLabelProvider.styleDecoratedString(decorated, StyledString.QUALIFIER_STYLER, str); >+ return str; >+ } >+ >+ StyledString str= new StyledString(Messages.format(fgSeparatorFormat, new String[] { pathString, name })); >+ return str; >+ } >+ >+ private StyledString getLineElementLabel(LineElement lineElement) { >+ int lineNumber= lineElement.getLine(); >+ String lineNumberString= Messages.format(SearchMessages.FileLabelProvider_line_number, new Integer(lineNumber)); >+ >+ StyledString str= new StyledString(lineNumberString, StyledString.QUALIFIER_STYLER); >+ >+ Match[] matches= lineElement.getMatches(fPage.getInput()); >+ Arrays.sort(matches, fMatchComparator); >+ >+ String content= lineElement.getContents(); >+ >+ int pos= evaluateLineStart(matches, content, lineElement.getOffset()); >+ >+ int length= content.length(); >+ >+ int charsToCut= getCharsToCut(length, matches); // number of characters to leave away if the line is too long >+ for (int i= 0; i < matches.length; i++) { >+ FileMatch match= (FileMatch) matches[i]; >+ int start= Math.max(match.getOriginalOffset() - lineElement.getOffset(), 0); >+ // append gap between last match and the new one >+ if (pos < start) { >+ if (charsToCut > 0) { >+ charsToCut= appendShortenedGap(content, pos, start, charsToCut, i == 0, str); >+ } else { >+ str.append(content.substring(pos, start)); >+ } >+ } >+ // append match >+ int end= Math.min(match.getOriginalOffset() + match.getOriginalLength() - lineElement.getOffset(), lineElement.getLength()); >+ str.append(content.substring(start, end), DecoratingFileSearchLabelProvider.HIGHLIGHT_STYLE); >+ pos= end; >+ } >+ // append rest of the line >+ if (charsToCut > 0) { >+ appendShortenedGap(content, pos, length, charsToCut, false, str); >+ } else { >+ str.append(content.substring(pos)); >+ } >+ return str; >+ } >+ >+ private static final int MIN_MATCH_CONTEXT= 10; // minimal number of characters shown after and before a match >+ >+ private int appendShortenedGap(String content, int start, int end, int charsToCut, boolean isFirst, StyledString str) { >+ int gapLength= end - start; >+ if (!isFirst) { >+ gapLength-= MIN_MATCH_CONTEXT; >+ } >+ if (end < content.length()) { >+ gapLength-= MIN_MATCH_CONTEXT; >+ } >+ if (gapLength < MIN_MATCH_CONTEXT) { // don't cut, gap is too small >+ str.append(content.substring(start, end)); >+ return charsToCut; >+ } >+ >+ int context= MIN_MATCH_CONTEXT; >+ if (gapLength > charsToCut) { >+ context+= gapLength - charsToCut; >+ } >+ >+ if (!isFirst) { >+ str.append(content.substring(start, start + context)); // give all extra context to the right side of a match >+ context= MIN_MATCH_CONTEXT; >+ } >+ >+ str.append(fgEllipses, StyledString.QUALIFIER_STYLER); >+ >+ if (end < content.length()) { >+ str.append(content.substring(end - context, end)); >+ } >+ return charsToCut - gapLength + fgEllipses.length(); >+ } >+ >+ >+ private int getCharsToCut(int contentLength, Match[] matches) { >+ if (contentLength <= 256 || !"win32".equals(SWT.getPlatform()) || matches.length == 0) { //$NON-NLS-1$ >+ return 0; // no shortening required >+ } >+ // XXX: workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=38519 >+ return contentLength - 256 + Math.max(matches.length * fgEllipses.length(), 100); >+ } >+ >+ private int evaluateLineStart(Match[] matches, String lineContent, int lineOffset) { >+ int max= lineContent.length(); >+ if (matches.length > 0) { >+ FileMatch match= (FileMatch) matches[0]; >+ max= match.getOriginalOffset() - lineOffset; >+ if (max < 0) { >+ return 0; >+ } >+ } >+ for (int i= 0; i < max; i++) { >+ char ch= lineContent.charAt(i); >+ if (!Character.isWhitespace(ch) || ch == '\n' || ch == '\r') { >+ return i; >+ } >+ } >+ return max; >+ } >+} >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchListLabelProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchListLabelProvider.java >new file mode 100644 >index 0000000..23d31a1 >--- /dev/null >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchListLabelProvider.java >@@ -0,0 +1,81 @@ >+/******************************************************************************* >+ * Copyright (c) 2014, Juniper Networks, Inc. >+ * 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: >+ * Juniper Networks - initial API and implementation >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 >+ *******************************************************************************/ >+package org.eclipse.search.internal.ui.text; >+ >+import java.util.Arrays; >+ >+import org.eclipse.swt.custom.StyleRange; >+ >+import org.eclipse.core.resources.IResource; >+ >+import org.eclipse.jface.viewers.StyledString; >+import org.eclipse.jface.viewers.ViewerCell; >+ >+public class FileSearchListLabelProvider extends >+ DecoratingFileSearchLabelProvider { >+ >+ private final int fColumnIndex; >+ >+ public FileSearchListLabelProvider(FileLabelProvider provider, int columnIndex) { >+ super(provider); >+ fColumnIndex = columnIndex; >+ } >+ >+ public void update(ViewerCell cell) { >+ LineElement element = (LineElement)cell.getElement(); >+ IResource res = element.getParent(); >+ switch (fColumnIndex) { >+ case FileSearchPage.FILE_NAME_COLUMN_INDEX: >+ updateCell(cell, res); >+ break; >+/* case FileSearchPage.LOCATION_COLUMN_INDEX: >+ //cell.setText(getText(res.getParent())); >+ updateCell(cell, res.getParent()); >+ break; >+ case FileSearchPage.LINE_NUMBER_COLUMN_INDEX: >+ cell.setText("Line " + ((LineElement)element).getLine()); >+ //updateCell(cell, res); >+ break;*/ >+ case FileSearchPage.MATCH_COLUMN_INDEX: >+ updateCell(cell, element); >+ break; >+ default: >+ cell.setText(""); //$NON-NLS-1$ >+ break; >+ } >+ } >+ >+ public void updateCell(ViewerCell cell, Object element) { >+ StyledString styledString = getStyledText(element); >+ String newText= styledString.toString(); >+ >+ StyleRange[] oldStyleRanges= cell.getStyleRanges(); >+ StyleRange[] newStyleRanges= isOwnerDrawEnabled() ? styledString.getStyleRanges() : null; >+ >+ if (!Arrays.equals(oldStyleRanges, newStyleRanges)) { >+ cell.setStyleRanges(newStyleRanges); >+ if (cell.getText().equals(newText)) { >+ // make sure there will be a refresh from a change >+ cell.setText(""); //$NON-NLS-1$ >+ } >+ } >+ >+ cell.setText(newText); >+ cell.setImage(getImage(element)); >+ cell.setFont(getFont(element)); >+ cell.setForeground(getForeground(element)); >+ cell.setBackground(getBackground(element)); >+ >+ // no super call required. changes on item will trigger the refresh. >+ } >+ >+} >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java >index 2e8c660..b7002f3 100644 >--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchPage.java >@@ -10,6 +10,7 @@ > * Juerg Billeter, juergbi@ethz.ch - 47136 Search view should show match objects > * Ulrich Etter, etteru@ethz.ch - 47136 Search view should show match objects > * Roman Fuchs, fuchsro@ethz.ch - 47136 Search view should show match objects >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 > *******************************************************************************/ > package org.eclipse.search.internal.ui.text; > >@@ -18,8 +19,14 @@ > import java.util.Iterator; > import java.util.Set; > >+import org.eclipse.swt.SWT; > import org.eclipse.swt.dnd.DND; > import org.eclipse.swt.dnd.Transfer; >+import org.eclipse.swt.events.SelectionAdapter; >+import org.eclipse.swt.events.SelectionEvent; >+import org.eclipse.swt.widgets.Composite; >+import org.eclipse.swt.widgets.Table; >+import org.eclipse.swt.widgets.TableColumn; > > import org.eclipse.core.runtime.IAdaptable; > >@@ -38,6 +45,7 @@ > import org.eclipse.jface.viewers.StructuredSelection; > import org.eclipse.jface.viewers.StructuredViewer; > import org.eclipse.jface.viewers.TableViewer; >+import org.eclipse.jface.viewers.TableViewerColumn; > import org.eclipse.jface.viewers.TreeViewer; > import org.eclipse.jface.viewers.Viewer; > import org.eclipse.jface.viewers.ViewerComparator; >@@ -127,7 +135,23 @@ > return SHOW_IN_TARGETS; > } > }; >+ >+ // modified for bug 332502 >+ public static final int FILE_NAME_COLUMN_INDEX = 0; >+/* public static final int LOCATION_COLUMN_INDEX = 1; >+ public static final int LINE_NUMBER_COLUMN_INDEX = 2;*/ >+ public static final int MATCH_COLUMN_INDEX = 1; > >+ private static final String[] fColumnLabels = new String[] { >+ SearchMessages.FileSearchPageFilenameColumn_label, >+/* SearchMessages.FileSearchPageLocationColumn_label, >+ SearchMessages.FileSearchPageLineNumberColumn_label,*/ >+ SearchMessages.FileSearchPageMatchColumn_label >+ }; >+ >+ private final int[] fColumnWidths = { /*150,*/ 300, /*100,*/ 300 }; >+ private FileSearchTableViewerComparator comparator; >+ > public FileSearchPage() { > fSortByNameAction= new SortAction(SearchMessages.FileSearchPage_sort_name_label, this, FileLabelProvider.SHOW_LABEL_PATH); > fSortByPathAction= new SortAction(SearchMessages.FileSearchPage_sort_path_label, this, FileLabelProvider.SHOW_PATH_LABEL); >@@ -153,10 +177,14 @@ > > protected void configureTableViewer(TableViewer viewer) { > viewer.setUseHashlookup(true); >- FileLabelProvider innerLabelProvider= new FileLabelProvider(this, fCurrentSortOrder); >- viewer.setLabelProvider(new DecoratingFileSearchLabelProvider(innerLabelProvider)); >+ // modified for bug 332502 >+ FileLabelProvider innerLabelProvider= new FileSearchLabelProvider(this, FileLabelProvider.SHOW_LABEL_PATH); >+ FileSearchListLabelProvider labelProvider = new FileSearchListLabelProvider(innerLabelProvider, 0); >+ viewer.setLabelProvider(labelProvider); >+ createColumns(viewer, innerLabelProvider); > viewer.setContentProvider(new FileTableContentProvider(this)); >- viewer.setComparator(new DecoratorIgnoringViewerSorter(innerLabelProvider)); >+ comparator = new FileSearchTableViewerComparator(innerLabelProvider); >+ viewer.setComparator(comparator); > fContentProvider= (IFileSearchContentProvider) viewer.getContentProvider(); > addDragAdapters(viewer); > } >@@ -195,6 +223,19 @@ > } > } > } >+ // modified for bug 332502 >+ if(getLayout() == FLAG_LAYOUT_FLAT){ >+ Object firstElement= ((IStructuredSelection)event.getSelection()).getFirstElement(); >+ if (firstElement instanceof LineElement) { >+ IFile file = (IFile) ((LineElement)firstElement).getParent(); >+ try { >+ open(getSite().getPage(), file, false); >+ } catch (PartInitException e) { >+ ErrorDialog.openError(getSite().getShell(), SearchMessages.FileSearchPage_open_file_dialog_title, SearchMessages.FileSearchPage_open_file_failed, e.getStatus()); >+ } >+ return; >+ } >+ } > super.handleOpen(event); > } > >@@ -372,6 +413,11 @@ > } > return new Match[0]; > } >+ // modified for bug 332502 >+ if (element instanceof LineElement) { >+ LineElement lineEntry= (LineElement) element; >+ return lineEntry.getMatches(getInput()); >+ } > return super.getDisplayedMatches(element); > } > >@@ -381,7 +427,11 @@ > changedElements.add(((FileMatch) matches[i]).getLineElement()); > } > } else { >- super.evaluateChangedElements(matches, changedElements); >+ // modified for bug 332502 >+ for (int i = 0; i < matches.length; i++) { >+ changedElements.add(((FileMatch) matches[i]).getLineElement()); >+ } >+ //super.evaluateChangedElements(matches, changedElements); > } > } > >@@ -389,5 +439,43 @@ > AbstractTextSearchResult input= getInput(); > return getLayout() == FLAG_LAYOUT_TREE && input != null && !((FileSearchQuery) input.getQuery()).isFileNameSearch(); > } >+ >+ // added for bug 332502 >+ protected TableViewer createTableViewer(Composite parent) { >+ TableViewer tableViewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION); >+ return tableViewer; >+ } >+ >+ // added for bug 332502 >+ private void createColumns(TableViewer viewer, FileLabelProvider innerLabelProvider) { >+ for (int i = 0; i < fColumnLabels.length; i++) { >+ TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE); >+ viewerColumn.setLabelProvider(new FileSearchListLabelProvider(innerLabelProvider, i)); >+ TableColumn tableColumn = viewerColumn.getColumn(); >+ tableColumn.setText(fColumnLabels[i]); >+ tableColumn.setWidth(fColumnWidths[i]); >+ tableColumn.setResizable(true); >+ tableColumn.setMoveable(false); >+ tableColumn.addSelectionListener(getSelectionAdapter(viewer, tableColumn, i)); >+ } >+ Table table = viewer.getTable(); >+ table.setHeaderVisible(true); >+ table.setLinesVisible(true); >+ } >+ >+ // added for bug 332502 >+ private SelectionAdapter getSelectionAdapter(final TableViewer viewer, >+ final TableColumn column, final int index) { >+ SelectionAdapter selectionAdapter = new SelectionAdapter() { >+ public void widgetSelected(SelectionEvent e) { >+ comparator.setColumn(index); >+ int dir = comparator.getDirection(); >+ viewer.getTable().setSortDirection(dir); >+ viewer.getTable().setSortColumn(column); >+ viewer.refresh(); >+ } >+ }; >+ return selectionAdapter; >+ } > > } >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchTableViewerComparator.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchTableViewerComparator.java >new file mode 100644 >index 0000000..bda0da1 >--- /dev/null >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileSearchTableViewerComparator.java >@@ -0,0 +1,109 @@ >+/******************************************************************************* >+ * Copyright (c) 2014, Juniper Networks, Inc. >+ * 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: >+ * Juniper Networks - initial API and implementation >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 >+ *******************************************************************************/ >+package org.eclipse.search.internal.ui.text; >+ >+import org.eclipse.core.resources.IContainer; >+import org.eclipse.core.resources.IResource; >+import org.eclipse.jface.viewers.Viewer; >+import org.eclipse.jface.viewers.ViewerComparator; >+import org.eclipse.swt.SWT; >+ >+public class FileSearchTableViewerComparator extends ViewerComparator { >+ private int columnIndex = 0; >+ private static final int DESC = 1; >+ private static final int ASC = 0; >+ private int fSortDirection = ASC; >+ private FileLabelProvider fLabelProvider; >+ >+ public FileSearchTableViewerComparator(FileLabelProvider innerLabelProvider) { >+ fLabelProvider = innerLabelProvider; >+ } >+ >+ public int getDirection() { >+ return fSortDirection == 1 ? SWT.DOWN : SWT.UP; >+ } >+ >+ public void setColumn(int column) { >+ // if the column is same as the last sorted column >+ if (column == this.columnIndex) { >+ // toggle the direction >+ if(fSortDirection == DESC) >+ fSortDirection = ASC; >+ else >+ fSortDirection = DESC; >+ } else { >+ // if its a new column, then do an ascending sort >+ this.columnIndex = column; >+ fSortDirection = ASC; >+ } >+ } >+ >+ public int category(Object element) { >+ if (element instanceof IContainer) { >+ return 1; >+ } >+ return 2; >+ } >+ >+ public int compare(Viewer viewer, Object e1, Object e2) { >+ int result = 0; >+ int cat1 = category(e1); >+ int cat2 = category(e2); >+ >+ if (cat1 != cat2) { >+ return cat1 - cat2; >+ } >+ >+ if (e1 instanceof LineElement && e2 instanceof LineElement) { >+ LineElement m1 = (LineElement) e1; >+ LineElement m2 = (LineElement) e2; >+ IResource res1 = m1.getParent(); >+ IResource res2 = m2.getParent(); >+ >+ switch (columnIndex) { >+ case FileSearchPage.FILE_NAME_COLUMN_INDEX: >+ result = compareObject(res1, res2); >+ break; >+/* case FileSearchPage.LOCATION_COLUMN_INDEX: >+ result = res1.getFullPath().toString() >+ .compareTo(res2.getFullPath().toString()); >+ break; >+ case FileSearchPage.LINE_NUMBER_COLUMN_INDEX: >+ result = new Integer(m1.getLine()).compareTo(new Integer(m2 >+ .getLine())); >+ break;*/ >+ case FileSearchPage.MATCH_COLUMN_INDEX: >+ result = compareObject(m1, m2); >+ break; >+ default: >+ result = 0; >+ } >+ // If the sorted direction is descending then change the direction >+ if (fSortDirection == DESC) { >+ result = -1*result; >+ } >+ } >+ return result; >+ } >+ >+ private int compareObject(Object obj1, Object obj2) { >+ String name1= fLabelProvider.getText(obj1); >+ String name2= fLabelProvider.getText(obj2); >+ int result; >+ if (name1 == null) >+ name1 = "";//$NON-NLS-1$ >+ if (name2 == null) >+ name2 = "";//$NON-NLS-1$ >+ result = getComparator().compare(name1, name2); >+ return result; >+ } >+} >diff --git a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTableContentProvider.java b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTableContentProvider.java >index 84d60a7..39567b0 100644 >--- a/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTableContentProvider.java >+++ b/org.eclipse.search/search/org/eclipse/search/internal/ui/text/FileTableContentProvider.java >@@ -7,14 +7,18 @@ > * > * Contributors: > * IBM Corporation - initial API and implementation >+ * Vishal Gupta (Juniper Networks) - Show all the matches also in the List Mode https://bugs.eclipse.org/bugs/show_bug.cgi?id=332502 > *******************************************************************************/ > package org.eclipse.search.internal.ui.text; >+ >+import java.util.ArrayList; >+import java.util.List; > > import org.eclipse.jface.viewers.IStructuredContentProvider; > import org.eclipse.jface.viewers.TableViewer; > import org.eclipse.jface.viewers.Viewer; >- > import org.eclipse.search.ui.text.AbstractTextSearchResult; >+import org.eclipse.search.ui.text.Match; > > public class FileTableContentProvider implements IStructuredContentProvider, IFileSearchContentProvider { > >@@ -34,13 +38,24 @@ > public Object[] getElements(Object inputElement) { > if (inputElement instanceof FileSearchResult) { > int elementLimit= getElementLimit(); >- Object[] elements= ((FileSearchResult)inputElement).getElements(); >- if (elementLimit != -1 && elements.length > elementLimit) { >+ // modified for bug 332502 >+ Object[] result = ((FileSearchResult)inputElement).getElements(); >+ List elements = new ArrayList(); >+ for (int i = 0; i < result.length; i++) { >+ Match[] matches = ((FileSearchResult)inputElement).getMatches(result[i]); >+ for (int j = 0; j < matches.length; j++) { >+ if(matches[j] instanceof FileMatch){ >+ elements.add(((FileMatch)matches[j]).getLineElement()); >+ } >+ } >+ } >+ >+ if (elementLimit != -1 && elements.size() > elementLimit) { > Object[] shownElements= new Object[elementLimit]; > System.arraycopy(elements, 0, shownElements, 0, elementLimit); > return shownElements; > } >- return elements; >+ return elements.toArray(); > } > return EMPTY_ARR; > } >@@ -56,12 +71,30 @@ > int elementLimit= getElementLimit(); > boolean tableLimited= elementLimit != -1; > for (int i= 0; i < updatedElements.length; i++) { >- if (fResult.getMatchCount(updatedElements[i]) > 0) { >- if (viewer.testFindItem(updatedElements[i]) != null) >- viewer.update(updatedElements[i], null); >- else { >- if (!tableLimited || viewer.getTable().getItemCount() < elementLimit) >- viewer.add(updatedElements[i]); >+ // modified for bug 332502 >+ LineElement lineElement = (LineElement) updatedElements[i]; >+ if (fResult.getMatchCount(lineElement.getParent()) > 0) { >+ boolean remove = true; >+ Match[] matches = fResult.getMatches(lineElement.getParent()); >+ for (int j = 0; j < matches.length; j++) { >+ if (matches[j] instanceof FileMatch) { >+ LineElement element = ((FileMatch) matches[j]).getLineElement(); >+ if(element.equals(lineElement)){ >+ remove = false; >+ break; >+ } >+ } >+ } >+ if(!remove){ >+ if (viewer.testFindItem(lineElement) != null){ >+ viewer.update(lineElement, null); >+ } else { >+ if (!tableLimited || viewer.getTable().getItemCount() < elementLimit) { >+ viewer.add(lineElement); >+ } >+ } >+ }else{ >+ viewer.remove(updatedElements[i]); > } > } else > viewer.remove(updatedElements[i]);
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
Flags:
vishal.vit
:
review?
Actions:
View
|
Diff
Attachments on
bug 332502
: 241620