import java.text.Collator;
import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
-import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
import eu.etaxonomy.cdm.api.service.IReferenceService;
+import eu.etaxonomy.cdm.api.service.dto.EntityDTOBase.CdmEntity;
+import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
import eu.etaxonomy.cdm.model.reference.Reference;
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache;
+import eu.etaxonomy.cdm.persistence.query.MatchMode;
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.store.CdmStore;
private TeamOrPersonBase author;
private boolean firstCall = true;
- protected NomenclaturalReferenceSelectionDialog(Shell shell,
- ConversationHolder conversation, String title, boolean multi,
+ protected NomenclaturalReferenceSelectionDialog(Shell shell,//ConversationHolder conversation,
+ String title, boolean multi,
Reference reference, boolean inReference, TeamOrPersonBase author) {
- super(shell, conversation, title, multi, reference);
+ super(shell, //conversation,
+ title, multi, reference);
this.author = author;
firstCall = true;
}
/* (non-Javadoc)
- * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#initModel()
+ * @see eu.etaxonomy.taxeditor.dialogs.AbstractFilteredCdmResourceSelectionDialog#search
*/
/** {@inheritDoc} */
@Override
- protected void initModel() {
- Control control = getPatternControl();
- String pattern = null;
- if (control != null){
- pattern = ((Text)control).getText();
+ protected void callService(String pattern) {
+ Control control =getSearchField();
- }
if (firstCall && author != null){
pattern = author.getNomenclaturalTitle();
if (control!= null){
firstCall = false;
- ((Text)control).setText(pattern);
- }
+ model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCacheForAuthor(null, pattern, null);
- }
+ }
- if (pattern == null || pattern.equals("?")){
- model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCache(null, null);
}else{
- model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCache(limitOfInitialElements, pattern);
+
+ if (isUseIdentifier() && PreferencesUtil.getBooleanValue(IPreferenceKeys.SEARCH_FOR_IDENTIFIER_AND_TITLECACHE)){
+ List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAndTitleCacheAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
+ if (model!= null){
+ model.clear();
+ }
+ identifierMap = new HashMap();
+ for (IdentifiedEntityDTO dto: list){
+ if (dto.getIdentifier() != null){
+ identifierMap.put(dto.getCdmEntity().getUuid(), dto.getIdentifier());
+ }
+ model.add(dto.getCdmEntity());
+
+ }
+ }else if (isUseIdentifier() ){
+ List<IdentifiedEntityDTO<Reference>> list = CdmStore.getService(IReferenceService.class).listByIdentifierAbbrev(pattern, null, MatchMode.BEGINNING, limitOfInitialElements);
+ if (model!= null){
+ model.clear();
+ }
+ identifierMap = new HashMap();
+ for (IdentifiedEntityDTO dto: list){
+ identifierMap.put(dto.getCdmEntity().getUuid(), dto.getIdentifier());
+ model.add(dto.getCdmEntity());
+ }
+
+ }else{
+ model = CdmStore.getService(IReferenceService.class).getUuidAndAbbrevTitleCache(null, pattern);
+ }
+
}
- System.out.println("2");
+
+
+
+
}
/**
protected ILabelProvider createListLabelProvider() {
return new FilteredCdmResourceAbbrevLabelProvider();
}
+ @Override
+ protected void addIdentifierCheckButton(Composite searchAndFilter) {
+ Button btnCheckButton = new Button(searchAndFilter, SWT.CHECK);
+ btnCheckButton.setText("Use Identifier");
+ btnCheckButton.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ useIdentifier = btnCheckButton.getSelection();
+ }
+ });
+ }
/**
* <p>select</p>
* @return a {@link eu.etaxonomy.cdm.model.reference.ReferenceBase} object.
*/
- public static Reference select(Shell shell, ConversationHolder conversation, Reference reference, TeamOrPersonBase author) {
- NomenclaturalReferenceSelectionDialog dialog = new NomenclaturalReferenceSelectionDialog(shell, conversation,
+ public static Reference select(Shell shell, //ConversationHolder conversation,
+ Reference reference, TeamOrPersonBase author) {
+ NomenclaturalReferenceSelectionDialog dialog = new NomenclaturalReferenceSelectionDialog(shell,// conversation,
"Choose a reference", isInReference, reference, false, author);
return getSelectionFromDialog(dialog);
}
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#createFilter()
*/
/** {@inheritDoc} */
- @Override
- protected ItemsFilter createFilter() {
- return new ItemsFilter() {
-
- /**
- * Always returns false to enforce refiltering even if the pattern is equal
- */
- @Override
- public boolean equalsFilter(ItemsFilter filter) {
- return false;
- }
-
- @Override
- public boolean isConsistentItem(Object item) {
- return false;
- }
-
- @Override
- public boolean matchItem(Object item) {
- return true;
-// String text = null;
-// if(item instanceof UuidAndTitleCache){
-// if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
-// text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
-// } else{
-// text = ((UuidAndTitleCache) item).getTitleCache();
-// }
-// }else if(item instanceof String){
-// text = (String) item;
-// }
-// return text != null ? matches(text) : false;
- }
-
- };
- }
+// @Override
+// protected ItemsFilter createFilter() {
+// return new ItemsFilter() {
+//
+// /**
+// * Always returns false to enforce refiltering even if the pattern is equal
+// */
+// @Override
+// public boolean equalsFilter(ItemsFilter filter) {
+// return false;
+// }
+//
+// @Override
+// public boolean isConsistentItem(Object item) {
+// return false;
+// }
+//
+// @Override
+// public boolean matchItem(Object item) {
+// return true;
+//// String text = null;
+//// if(item instanceof UuidAndTitleCache){
+//// if (((UuidAndTitleCache) item).getAbbrevTitleCache() != null){
+//// text = ((UuidAndTitleCache) item).getAbbrevTitleCache();
+//// } else{
+//// text = ((UuidAndTitleCache) item).getTitleCache();
+//// }
+//// }else if(item instanceof String){
+//// text = (String) item;
+//// }
+//// return text != null ? matches(text) : false;
+// }
+//
+// };
+// }
if (element == null) {
return null;
}
- UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
+ UuidAndTitleCache uuidAndTitleCache;
+ if (element instanceof CdmEntity){
+ uuidAndTitleCache = (CdmEntity)element;
+ }else{
+ uuidAndTitleCache = (UuidAndTitleCache) element;
+ }
String titleCache = uuidAndTitleCache.getTitleCache();
String abbrevTitleCache = uuidAndTitleCache.getAbbrevTitleCache();
if (!abbrevTitleCache.equals(titleCache)){
abbrevTitleCache += " - " + titleCache;
}
- if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
+ if(PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
abbrevTitleCache += " ["+uuidAndTitleCache.getId()+"]";
}
return abbrevTitleCache;
}
+ @Override
+ protected void search() {
+ Control control =getSearchField();
+ String pattern = null;
+ if (control != null){
+ pattern = ((Text)control).getText();
+ if (pattern.equals("*") || pattern.equals("?")){
+ callService(null);
+ }else if (StringUtils.isNotBlank(pattern)){
+ callService(pattern);
+ } else if (firstCall){
+ callService(null);
+ }
+ fillContentProvider(null);
+ }
+ }
+