From 3f2528d1c65cc6830d86f6e9d77904cc87da45a0 Mon Sep 17 00:00:00 2001 From: Paul Withers Date: Wed, 11 Feb 2015 13:36:24 +0000 Subject: [PATCH] Adding searchType to NAB picker Amending "match" search option so everything shows if no search value is entered (previously nothing showed) No changes to AbstractDominoViewPickerData --- .../data/AbstractDominoViewPickerData.java | 512 +++++++++--------- .../picker/data/DominoNABNamePickerData.java | 23 +- .../config/extlib-domino-picker.xsp-config | 20 + .../raw-extlib-domino-picker.xsp-config | 40 ++ 4 files changed, 352 insertions(+), 243 deletions(-) diff --git a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/AbstractDominoViewPickerData.java b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/AbstractDominoViewPickerData.java index 8b35945..5f41525 100644 --- a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/AbstractDominoViewPickerData.java +++ b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/AbstractDominoViewPickerData.java @@ -33,253 +33,281 @@ import com.ibm.xsp.model.domino.DominoUtils; import com.ibm.xsp.model.domino.wrapped.DominoViewEntry; - /** * Abstract data provider for a picker that reads the data from a Domino view. *

- * This class does not preclude how the + * This class does not preclude how the *

*/ public abstract class AbstractDominoViewPickerData extends ValueBindingObjectImpl implements IPickerData { - public static final String SEARCH_STARTFROM = "startFrom"; // default //$NON-NLS-1$ - public static final String SEARCH_MATCH = "match"; //$NON-NLS-1$ - public static final String SEARCH_FTSEARCH = "ftSearch"; //$NON-NLS-1$ - - public AbstractDominoViewPickerData() { - } - - protected abstract EntryMetaData createEntryMetaData(IPickerOptions options) throws NotesException; - - public String getSearchType() { - return null; - } - - - // ==================================================================== - // Data access implementation - // ==================================================================== - - public abstract static class EntryMetaData { - private View view; - private IPickerOptions options; - protected EntryMetaData(IPickerOptions options) throws NotesException { - this.options = options; - this.view = openView(); - } - public View getView() { - return view; - } - public IPickerOptions getOptions() { - return options; - } - protected int findSortColumnIndex(Vector vc) throws NotesException { - int fc = -1; - // Find the first sorted column - int nc = vc.size(); - for(int i=0; i vc, String name) throws NotesException { - int nc = vc.size(); - // Look for a programmatic name first - for(int i=0; i columnValues = ve.getColumnValues(); - - // Read the value - this.value = readValue(ve, columnValues); - - // Read the label - this.label = readLabel(ve, columnValues); - - // Read the extra attributes - this.attributes = readAttributes(ve, columnValues); - } - public EntryMetaData getMetaData() { - return metaData; - } - public Object getValue() { - return value; - } - public Object getLabel() { - return label; - } - public int getAttributeCount() { - return 0; - } - public String getAttributeName(int index) { - return null; - } - public Object getAttributeValue(int index) { - return attributes[index]; - } - protected abstract Object readValue(ViewEntry ve, Vector columnValues) throws NotesException; - protected abstract Object readLabel(ViewEntry ve, Vector columnValues) throws NotesException; - protected abstract Object[] readAttributes(ViewEntry ve, Vector columnValues) throws NotesException; - } - public static class Result implements IPickerResult { - private List entries; - private int count; - protected Result(List entries, int count) { - this.entries = entries; - this.count = count; - } - public List getEntries() { - return entries; - } - public int getTotalCount() { - return count; - } - } - - public boolean hasCapability(int capability) { - if(capability==CAPABILITY_MULTIPLESOURCES) { - return false; - } - return true; - } - - public IPickerResult readEntries(IPickerOptions options) { - try { - EntryMetaData meta = createEntryMetaData(options); - View view = meta.getView(); - view.setAutoUpdate(false); - try { - ArrayList entries = new ArrayList(); - - int start = options.getStart(); - int count = options.getCount(); - String key = options.getKey(); - String _startKey = options.getStartKey(); - if(StringUtil.isNotEmpty(_startKey)) { - key = _startKey; - } - - String searchType = getSearchType(); - if(StringUtil.isEmpty(searchType)) { - searchType = SEARCH_STARTFROM; - } - - if(StringUtil.equals(searchType, SEARCH_MATCH)) { - ViewEntryCollection vc = view.getAllEntriesByKey(key); - ViewEntry ve = start>0 ? vc.getNthEntry(start) : vc.getFirstEntry(); - for(int i=0; i0 ? vc.getNthEntry(start) : vc.getFirstEntry(); - for(int i=0; i0) { - if(nav.skip(start)!=start) { - // ok not all of them are skipped, stop the process - count = 0; - } - } - for(int i=0; i loadEntries(Object[] ids, String[] attributeNames) { - try { - EntryMetaData meta = createEntryMetaData(null); - View view = meta.getView(); - view.setAutoUpdate(false); - try { - // TODO: use the options here? - ArrayList entries = new ArrayList(ids.length); - for(int i=0; i vc) throws NotesException { + int fc = -1; + // Find the first sorted column + int nc = vc.size(); + for (int i = 0; i < nc; i++) { + ViewColumn c = vc.get(i); + if (c.isSorted()) { + return i; + } + if (fc < 0 && c.getColumnValuesIndex() != DominoViewEntry.VC_NOT_PRESENT) { + fc = i; + } + } + // Else, return the first column + return fc; + } + + protected int findColumnIndex(Vector vc, String name) throws NotesException { + int nc = vc.size(); + // Look for a programmatic name first + for (int i = 0; i < nc; i++) { + if (StringUtil.equalsIgnoreCase(vc.get(i).getItemName(), name)) { + return i; + } + } + // Then default to the title + for (int i = 0; i < nc; i++) { + if (StringUtil.equalsIgnoreCase(vc.get(i).getTitle(), name)) { + return i; + } + } + return -1; + } + + protected abstract View openView() throws NotesException; + + protected abstract Entry createEntry(ViewEntry ve) throws NotesException; + } + + public abstract static class Entry implements IPickerEntry { + private EntryMetaData metaData; + private Object value; + private Object label; + private Object[] attributes; + + @SuppressWarnings("unchecked") + // $NON-NLS-1$ + protected Entry(EntryMetaData metaData, ViewEntry ve) throws NotesException { + this.metaData = metaData; + // Read the values from the view entry + Vector columnValues = ve.getColumnValues(); + + // Read the value + this.value = readValue(ve, columnValues); + + // Read the label + this.label = readLabel(ve, columnValues); + + // Read the extra attributes + this.attributes = readAttributes(ve, columnValues); + } + + public EntryMetaData getMetaData() { + return metaData; + } + + public Object getValue() { + return value; + } + + public Object getLabel() { + return label; + } + + public int getAttributeCount() { + return 0; + } + + public String getAttributeName(int index) { + return null; + } + + public Object getAttributeValue(int index) { + return attributes[index]; + } + + protected abstract Object readValue(ViewEntry ve, Vector columnValues) throws NotesException; + + protected abstract Object readLabel(ViewEntry ve, Vector columnValues) throws NotesException; + + protected abstract Object[] readAttributes(ViewEntry ve, Vector columnValues) throws NotesException; + } + + public static class Result implements IPickerResult { + private List entries; + private int count; + + protected Result(List entries, int count) { + this.entries = entries; + this.count = count; + } + + public List getEntries() { + return entries; + } + + public int getTotalCount() { + return count; + } + } + + public boolean hasCapability(int capability) { + if (capability == CAPABILITY_MULTIPLESOURCES) { + return false; + } + return true; + } + + public IPickerResult readEntries(IPickerOptions options) { + try { + EntryMetaData meta = createEntryMetaData(options); + View view = meta.getView(); + view.setAutoUpdate(false); + try { + ArrayList entries = new ArrayList(); + + int start = options.getStart(); + int count = options.getCount(); + String key = options.getKey(); + String _startKey = options.getStartKey(); + if (StringUtil.isNotEmpty(_startKey)) { + key = _startKey; + } + + String searchType = getSearchType(); + if (StringUtil.isEmpty(searchType)) { + searchType = SEARCH_STARTFROM; + } + + if (StringUtil.equals(searchType, SEARCH_MATCH)) { + ViewEntryCollection vc; + if (!StringUtil.isEmpty(key)) { + vc = view.getAllEntriesByKey(key); + } else { + vc = view.getAllEntries(); + } + ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry(); + for (int i = 0; i < count && ve != null; i++) { + entries.add(meta.createEntry(ve)); + ve = vc.getNextEntry(ve); + } + int nEntries = vc.getCount(); + return new Result(entries, nEntries); + } + if (StringUtil.equals(searchType, SEARCH_FTSEARCH)) { + applyFTSearch(options, view, key); + ViewEntryCollection vc = view.getAllEntries(); + ViewEntry ve = start > 0 ? vc.getNthEntry(start) : vc.getFirstEntry(); + for (int i = 0; i < count && ve != null; i++) { + entries.add(meta.createEntry(ve)); + ve = vc.getNextEntry(ve); + } + int nEntries = vc.getCount(); + return new Result(entries, nEntries); + } else { + ViewNavigator nav = view.createViewNav(); + try { + ViewEntry ve = null; + if (key != null) { + int searchOptions = DominoUtils.FIND_GREATER_THAN | DominoUtils.FIND_EQUAL | DominoUtils.FIND_PARTIAL + | DominoUtils.FIND_CASE_INSENSITIVE; + ve = DominoUtils.getViewEntryByKeyWithOptions(view, key, searchOptions); + } else { + ve = nav.getCurrent(); + } + if (start > 0) { + if (nav.skip(start) != start) { + // ok not all of them are skipped, stop the + // process + count = 0; + } + } + for (int i = 0; i < count && ve != null; i++) { + entries.add(meta.createEntry(ve)); + ve = nav.getNext(ve); + } + + int nEntries = -1; + return new Result(entries, nEntries); + } finally { + nav.recycle(); + } + } + } finally { + // Recycle the view? + } + } catch (Exception ex) { + Platform.getInstance().log(ex); + // Swallow the exception for the end user and return an empty picker + return new EmptyPickerResult(); + } + } + + protected void applyFTSearch(IPickerOptions options, View view, String key) throws NotesException { + if (StringUtil.isNotEmpty(key)) { + view.FTSearch(key); + } + } + + public List loadEntries(Object[] ids, String[] attributeNames) { + try { + EntryMetaData meta = createEntryMetaData(null); + View view = meta.getView(); + view.setAutoUpdate(false); + try { + // TODO: use the options here? + ArrayList entries = new ArrayList(ids.length); + for (int i = 0; i < ids.length; i++) { + ViewEntry ve = view.getEntryByKey(ids[i], true); + if (ve != null) { + Entry e = meta.createEntry(ve); + entries.add(e); + } else { + entries.add(null); + } + // ve.recycle(); + } + return entries; + } finally { + // Recycle the view? + } + } catch (NotesException ex) { + throw new FacesExceptionEx(ex, "Error while loading entry"); // $NLX-AbstractDominoViewPickerData.Errorwhileloadingentry-1$ + } + } } \ No newline at end of file diff --git a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/DominoNABNamePickerData.java b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/DominoNABNamePickerData.java index 878113a..b488000 100644 --- a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/DominoNABNamePickerData.java +++ b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/component/picker/data/DominoNABNamePickerData.java @@ -48,6 +48,8 @@ public class DominoNABNamePickerData extends AbstractDominoViewPickerData implem public static final String NAB_FIRSTPUBLIC = "first-public"; // $NON-NLS-1$ public static final String NAB_DATABASENAME = "db-name"; // $NON-NLS-1$ + public String searchType; + private static enum NameFormat { ABBREVIATED("Abbreviated"), COMMON("Common"), CANONICAL("Canonical"); @@ -221,7 +223,7 @@ public void setReturnNameFormatAsNameFormat(NameFormat returnNameFormatAsNameFor @Override public Object saveState(FacesContext context) { - Object[] state = new Object[7]; + Object[] state = new Object[8]; state[0] = super.saveState(context); state[1] = addressBookSel; state[2] = addressBookDb; @@ -229,6 +231,7 @@ public Object saveState(FacesContext context) { state[4] = people; state[5] = groups; state[6] = returnNameFormat; + state[7] = searchType; return state; } @@ -242,6 +245,7 @@ public void restoreState(FacesContext context, Object value) { this.people = (Boolean) state[4]; this.groups = (Boolean) state[5]; this.returnNameFormat = (String) state[6]; + this.searchType = (String) state[7]; } // ==================================================================== @@ -775,4 +779,21 @@ protected Object readLabel(ViewEntry ve, Vector columnValues) throws Not return b.toString(); } } + + @Override + public String getSearchType() { + if (searchType != null) { + return searchType; + } + ValueBinding vb = getValueBinding("searchType"); //$NON-NLS-1$ + if (vb != null) { + return (String) vb.getValue(getFacesContext()); + } + + return null; + } + + public void setSearchType(String searchType) { + this.searchType = searchType; + } } \ No newline at end of file diff --git a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/extlib-domino-picker.xsp-config b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/extlib-domino-picker.xsp-config index 841892f..5de8e84 100644 --- a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/extlib-domino-picker.xsp-config +++ b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/extlib-domino-picker.xsp-config @@ -159,6 +159,26 @@ + + %property.searchType.descr% + %property.searchType.name% + searchType + java.lang.String + + 8.5.32003 + + + not-localizable + + com.ibm.workplace.designer.property.editors.comboParameterEditor + + startFrom + match + ftSearch + + + + com.ibm.xsp.extlib.component.picker.data.INamePickerData dominoNABNamePicker diff --git a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/raw-extlib-domino-picker.xsp-config b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/raw-extlib-domino-picker.xsp-config index 96de026..5426b9f 100644 --- a/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/raw-extlib-domino-picker.xsp-config +++ b/extlib/lwp/product/runtime/eclipse/plugins/com.ibm.xsp.extlib.domino/src/com/ibm/xsp/extlib/config/raw-extlib-domino-picker.xsp-config @@ -169,6 +169,46 @@ + + %property.returnNameFormat.descr% + %property.returnNameFormat.name% + returnNameFormat + java.lang.String + + 9.0.12015 + + com.ibm.workplace.designer.property.editors.comboParameterEditor + + Abbreviated + Common + Canonical + + + + + + + Define the type of search to be applied. The options are "match", meaning the search value is matched to a key or keys in the view, "ftSearch" meaning the value is found in a full text search of the entry and "startFrom", the default search type, which matches the value as a key and then returns that entry and all subsequent entries. + Type of Search + searchType + java.lang.String + + 9.0.12015 + + + + not-localizable + + com.ibm.workplace.designer.property.editors.comboParameterEditor + + startFrom + match + ftSearch + + + + com.ibm.xsp.extlib.component.picker.data.INamePickerData