diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java index efc69df9b3..a75717a2a3 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/AbstractSessionView.java @@ -191,7 +191,7 @@ public abstract class AbstractSessionView extends CaveFloatingView { } }); messagesComp.addKeyListener(searchComp.getSearchKeyListener()); - searchComp.setDefaultSearchView(messagesText); + searchComp.setSearchText(messagesText); } protected void createComposeComp(Composite parent) { diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SearchComposite.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SearchComposite.java index ce2f16b6a9..941a436180 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SearchComposite.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SearchComposite.java @@ -66,17 +66,17 @@ public class SearchComposite extends Composite { private boolean searchFWD = true; - private String searchText; + private String search; private List results = new ArrayList(); private ListIterator resultIter; - private SearchView searchView; + private SearchText searchText; private KeyListener searchKeyListener; - private Text searchTextBox; + private Text searchBox; private Button bck; @@ -97,7 +97,7 @@ public class SearchComposite extends Composite { // } // } - public static interface SearchView { + public static interface SearchText { void select(int start, int end); @@ -110,10 +110,10 @@ public class SearchComposite extends Composite { } - public class DefaultSearchView implements SearchView { + public class DefaultSearchText implements SearchText { private StyledText searchView; - public DefaultSearchView(StyledText searchView) { + public DefaultSearchText(StyledText searchView) { this.searchView = searchView; } @@ -146,18 +146,18 @@ public class SearchComposite extends Composite { // ranges[i] = new StyleRange(sel.start, sel.length, // FOREGROUND_COLOR, HIGHLIGHT_COLOR); // } - // searchView.setStyleRanges(ranges); + // searchText.setStyleRanges(ranges); // } // // @Override // public void removeHighlights() { - // StyleRange[] ranges = searchView.getStyleRanges(); + // StyleRange[] ranges = searchText.getStyleRanges(); // for (StyleRange style : ranges) { // if (style.background == HIGHLIGHT_COLOR) { - // style.background = searchView.getBackground(); + // style.background = searchText.getBackground(); // } // } - // searchView.setStyleRanges(ranges); + // searchText.setStyleRanges(ranges); // } } @@ -171,12 +171,12 @@ public class SearchComposite extends Composite { this.setLayout(new GridLayout(6, false)); this.setLayoutData(gd); - searchTextBox = new Text(this, SWT.RESIZE); - searchTextBox.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, - false)); + searchBox = new Text(this, SWT.RESIZE); + searchBox + .setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false)); gd = new GridData(SWT.FILL, SWT.FILL, true, false); - searchTextBox.setLayoutData(gd); - searchTextBox.addKeyListener(new KeyListener() { + searchBox.setLayoutData(gd); + searchBox.addKeyListener(new KeyListener() { @Override public void keyReleased(KeyEvent e) { } @@ -198,7 +198,7 @@ public class SearchComposite extends Composite { result = resultIter.previous(); } if (result != null) { - searchView.select(result.start(), result.end()); + searchText.select(result.start(), result.end()); } if (result == null && resultIter.hasNext()) { result = resultIter.next(); @@ -217,6 +217,10 @@ public class SearchComposite extends Composite { @Override public void widgetSelected(SelectionEvent e) { searchFWD = false; + if (search == null || !search.equals(searchBox.getText())) { + search = searchBox.getText(); + updateMatches(); + } nextSearchMatch(); } @@ -232,6 +236,10 @@ public class SearchComposite extends Composite { @Override public void widgetSelected(SelectionEvent e) { searchFWD = true; + if (search == null || !search.equals(searchBox.getText())) { + search = searchBox.getText(); + updateMatches(); + } nextSearchMatch(); } @@ -255,7 +263,7 @@ public class SearchComposite extends Composite { result = resultIter.previous(); } if (result != null) { - searchView.select(result.start(), result.end()); + searchText.select(result.start(), result.end()); } } @@ -278,9 +286,8 @@ public class SearchComposite extends Composite { public void keyPressed(KeyEvent e) { if (search(e)) { } else if (e.keyCode == SWT.KEYPAD_CR || e.keyCode == SWT.CR) { - if (searchText == null - || !searchText.equals(searchTextBox.getText())) { - searchText = searchTextBox.getText(); + if (search == null || !search.equals(searchBox.getText())) { + search = searchBox.getText(); updateMatches(); } if (searchFWD) { @@ -290,13 +297,13 @@ public class SearchComposite extends Composite { } nextSearchMatch(); } else { - searchTextBox.setFocus(); + searchBox.setFocus(); } } }; this.addKeyListener(searchKeyListener); - searchTextBox.addKeyListener(searchKeyListener); + searchBox.addKeyListener(searchKeyListener); bck.addKeyListener(searchKeyListener); fwd.addKeyListener(searchKeyListener); caseSensitive.addKeyListener(searchKeyListener); @@ -319,9 +326,13 @@ public class SearchComposite extends Composite { if (((e.stateMask & SWT.CTRL) == SWT.CTRL)) { if (e.keyCode == 'f' || e.keyCode == 'b' || e.keyCode == 'B') { searchFWD = e.keyCode == 'f' ? true : false; + if (search == null || !search.equals(searchBox.getText())) { + search = searchBox.getText(); + updateMatches(); + } hide(false); // redraw(); - searchTextBox.setFocus(); + searchBox.setFocus(); if (searchFWD) { fwd.setFocus(); } else { @@ -330,11 +341,6 @@ public class SearchComposite extends Composite { if (text == null) { reachedLimit(); } - if (searchText == null - || !searchText.equals(searchTextBox.getText())) { - searchText = searchTextBox.getText(); - updateMatches(); - } nextSearchMatch(); result = true; } @@ -349,8 +355,8 @@ public class SearchComposite extends Composite { public void hide(boolean isHidden) { ((GridData) getLayoutData()).exclude = isHidden; setVisible(!isHidden); - // if (searchView != null) { - // searchView.removeHighlights(); + // if (searchText != null) { + // searchText.removeHighlights(); // } getParent().layout(); } @@ -373,7 +379,7 @@ public class SearchComposite extends Composite { if (hasNextInSequence) { MatchResult current = searchFWD ? resultIter.next() : resultIter .previous(); - searchView.select(current.start(), current.end()); + searchText.select(current.start(), current.end()); } else { reachedLimit(); } @@ -389,8 +395,8 @@ public class SearchComposite extends Composite { reachedLimit(); } - if (searchText != null) { - Pattern pattern = Pattern.compile(searchText, patternFlags); + if (search != null) { + Pattern pattern = Pattern.compile(search, patternFlags); Matcher matcher = pattern.matcher(text); while (matcher.find()) { @@ -407,7 +413,7 @@ public class SearchComposite extends Composite { // highlights[index] = new HighlightSelection(mr.start(), mr.end() // - mr.start()); // } - // searchView.setHighlights(highlights); + // searchText.setHighlights(highlights); int index = searchFWD ? 0 : results.size(); resultIter = results.listIterator(index); @@ -416,18 +422,26 @@ public class SearchComposite extends Composite { private void reachedLimit() { if (searchFWD) { - searchView.reachedLast(); + searchText.reachedLast(); } else { - searchView.reachedFirst(); + searchText.reachedFirst(); } } /** - * @param searchView - * the SearchView to set + * @param searchText + * the SearchText to set */ - public void setSearchView(SearchView searchView) { - this.searchView = searchView; + public void setSearchText(SearchText searchText) { + this.searchText = searchText; + } + + /** + * @param styledText + */ + public void setSearchText(StyledText styledText) { + setText(styledText.getText()); + setSearchText(new DefaultSearchText(styledText)); } /** @@ -457,11 +471,6 @@ public class SearchComposite extends Composite { return searchKeyListener; } - public void setDefaultSearchView(StyledText styledText) { - setText(styledText.getText()); - setSearchView(new DefaultSearchView(styledText)); - } - public void appendText(String newText) { this.text.append(newText); updateMatches(); diff --git a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionMsgArchiveBrowser.java b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionMsgArchiveBrowser.java index d942de6df4..dfe94645d9 100644 --- a/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionMsgArchiveBrowser.java +++ b/cave/com.raytheon.uf.viz.collaboration.ui/src/com/raytheon/uf/viz/collaboration/ui/session/SessionMsgArchiveBrowser.java @@ -56,7 +56,7 @@ import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.viz.collaboration.comm.provider.user.UserId; import com.raytheon.uf.viz.collaboration.data.CollaborationDataManager; -import com.raytheon.uf.viz.collaboration.ui.session.SearchComposite.SearchView; +import com.raytheon.uf.viz.collaboration.ui.session.SearchComposite.SearchText; /** * Browse, view, and search messages in the archive. @@ -75,7 +75,7 @@ import com.raytheon.uf.viz.collaboration.ui.session.SearchComposite.SearchView; * @version 1.0 */ -public class SessionMsgArchiveBrowser extends Composite implements SearchView { +public class SessionMsgArchiveBrowser extends Composite implements SearchText { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(SessionMsgArchiveBrowser.class); @@ -194,7 +194,7 @@ public class SessionMsgArchiveBrowser extends Composite implements SearchView { logView.setEditable(false); searchComp = new SearchComposite(logViewPart, SWT.BORDER); - searchComp.setSearchView(this); + searchComp.setSearchText(this); searchComp.hide(true); tree.addKeyListener(searchComp.getSearchKeyListener());