Index: api/apichanges.xml =================================================================== RCS file: /cvs/openidex/api/apichanges.xml,v retrieving revision 1.3 diff -r1.3 apichanges.xml 78a79,103 > > > > Added ADD_TO_HISTORYfield > > > > > >

> It is necessary to fire further > PropertyChangeEvent to fix it. (Details in the > issue #54028)It is event ADD_TO_HISTORY, that will > be fired after adding new SearchPattern to > history. Old value of event would be null, new > value would be added pattern. > Also pattern checking before adding to history is > a subject of the API change. >

>
> > > >
> Index: src/org/openidex/search/SearchHistory.java =================================================================== RCS file: /cvs/openidex/src/org/openidex/search/SearchHistory.java,v retrieving revision 1.3 diff -r1.3 SearchHistory.java 56c56,60 < /** Property name for last selected search pattern */ --- > /** Property name for last selected search pattern > * Firing: > * oldValue - old selected pattern > * newValue - new selected pattern > */ 58a63,69 > /** Property name for adding pattern to history > * Firing: > * oldValue - null > * newValue - added pattern > */ > public final static String ADD_TO_HISTORY = "add-to-history"; //NOI18N > 118a130,135 > if (pattern == null || pattern.getSearchExpression() == null || pattern.getSearchExpression().length() == 0){ > return; > } > if (searchPatternsList.size()>0 && pattern.equals(searchPatternsList.get(0))){ > return; > } 122a140,142 > if (pcs != null){ > pcs.firePropertyChange(ADD_TO_HISTORY, null, pattern); > } Index: test/unit/src/org/openidex/search/SearchHistoryTest.java =================================================================== RCS file: /cvs/openidex/test/unit/src/org/openidex/search/SearchHistoryTest.java,v retrieving revision 1.1 diff -r1.1 SearchHistoryTest.java 56c56 < public void testSearchHistoryListener() throws Exception{ --- > public void testLastSelectedListener() throws Exception{ 61c61,63 < fired[0] = true; --- > if (evt!=null && SearchHistory.LAST_SELECTED.equals(evt.getPropertyName())){ > fired[0] = true; > } 67a70,125 > } > > public void testAddToSearchHistoryListener() throws Exception{ > final boolean fired[] = new boolean[1]; > fired[0] = false; > PropertyChangeListener pcl = new PropertyChangeListener(){ > public void propertyChange(PropertyChangeEvent evt){ > if (evt!=null && SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())){ > fired[0] = true; > } > } > }; > SearchHistory.getDefault().addPropertyChangeListener(pcl); > SearchHistory.getDefault().add(SearchPattern.create("searchtext",true,true,false)); > SearchHistory.getDefault().removePropertyChangeListener(pcl); > assertTrue(fired[0]); > } > > public void testAddIncorrectItemToSearchHistoryListener() throws Exception{ > final boolean fired[] = new boolean[1]; > > PropertyChangeListener pcl = new PropertyChangeListener(){ > public void propertyChange(PropertyChangeEvent evt){ > if (evt!=null && SearchHistory.ADD_TO_HISTORY.equals(evt.getPropertyName())){ > fired[0] = true; > } > } > }; > SearchHistory.getDefault().addPropertyChangeListener(pcl); > > // add valid pattern > fired[0] = false; > SearchHistory.getDefault().add(SearchPattern.create("searchtext2",true,true,false)); > assertTrue(fired[0]); > > // add the same pattern, it shouldn't be added > fired[0] = false; > SearchHistory.getDefault().add(SearchPattern.create("searchtext2",true,true,false)); > assertTrue(!fired[0]); > > // add null pattern > fired[0] = false; > SearchHistory.getDefault().add(null); > assertTrue(!fired[0]); > > // add pattern with null searchExpression > fired[0] = false; > SearchHistory.getDefault().add(SearchPattern.create(null,true,true,false)); > assertTrue(!fired[0]); > > // add pattern with empty searchExpression > fired[0] = false; > SearchHistory.getDefault().add(SearchPattern.create("",true,true,false)); > assertTrue(!fired[0]); > > SearchHistory.getDefault().removePropertyChangeListener(pcl); 68a127 >