import java.util.List;
import java.util.Set;
import java.util.UUID;
+import java.util.regex.Pattern;
+import org.apache.commons.lang.StringUtils;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Cursor;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
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.service.dto.EntityDTOBase;
+import eu.etaxonomy.cdm.api.service.dto.IdentifiedEntityDTO;
+import eu.etaxonomy.cdm.common.CdmUtils;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.model.common.ICdmBase;
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
*
* @author n.hoffmann
* @created 04.06.2009
- * @version 1.0
*/
public abstract class AbstractFilteredCdmResourceSelectionDialog<T extends ICdmBase> extends
SearchDialog {//implements IConversationEnabled {
protected List<UuidAndTitleCache<T>> model;
private final Set<T> transientCdmObjects = new HashSet<T>();
private final String settings;
- protected final int limitOfInitialElements = 100;
+ protected final Integer limitOfInitialElements = null;
private T selectedObject;
- protected T cdmBaseToBeFiltered;
+ protected Set<UUID> cdmBaseToBeFiltered;
+
+ protected Job searchJob;
/**
*/
protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, //ConversationHolder conversation,
String title, boolean multi, String settings, T cdmObject) {
- super(shell, multi);
+ super(shell, title);
setShellStyle(SWT.DIALOG_TRIM);
- setTitle(title);
setMessage(Messages.SearchDialog_patternLabel);
this.settings = settings;
-
- this.cdmBaseToBeFiltered = cdmObject;
+ if (cdmObject != null){
+ this.cdmBaseToBeFiltered = new HashSet<>();
+ this.cdmBaseToBeFiltered.add(cdmObject.getUuid());
+ }
Cursor cursor = shell.getCursor();
shell.setCursor(shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT));
init();
* @return a TYPE object.
*/
protected static <TYPE extends CdmBase> TYPE getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog<TYPE> dialog) {
- int result = dialog.open();
+ UuidAndTitleCache result = getUuidAndTitleCacheSelectionFromDialog(dialog);
+ if (result != null){
+ return dialog.getCdmObjectByUuid(result.getUuid());
+ } else {
+ return null;
+ }
+ }
- if (result == Window.CANCEL) {
- return null;
- }
+ /**
+ * <p>getSelectionFromDialog</p>
+ *
+ * @param dialog a {@link eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog} object.
+ * @param <TYPE> a TYPE object.
+ * @return a TYPE object.
+ */
+ protected static UuidAndTitleCache getUuidAndTitleCacheSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog dialog) {
+ if (dialog == null){
+ return null;
+ }
+ int result = dialog.open();
- UuidAndTitleCache uuid = dialog.getSelectedUuidAndTitleCache();
- if(uuid == null){
- return null;
- }
- return dialog.getCdmObjectByUuid(uuid.getUuid());
- }
+ if (result == Window.CANCEL) {
+ return null;
+ }
+
+ UuidAndTitleCache uuid = dialog.getSelectedUuidAndTitleCache();
+
+ return uuid;
+ }
/**
* Check if object was created during the life of this dialog. If not,
UuidAndTitleCache<T> element;
while(iterator.hasNext()){
element = iterator.next();
- if (!element.equals(cdmBaseToBeFiltered)){
+
+ if (cdmBaseToBeFiltered == null || !cdmBaseToBeFiltered.contains(element.getUuid())){
contentProvider.add(element);
}
if (progressMonitor != null){
}
UuidAndTitleCache uuidAndTitleCache = (UuidAndTitleCache) element;
String titleCache = uuidAndTitleCache.getTitleCache();
- if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
+ if(PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_ID_IN_ENTITY_SELECTION_DIAOLOG)){
titleCache += " ["+uuidAndTitleCache.getId()+"]";
}
+ if (element instanceof EntityDTOBase){
+ titleCache += "(" + ((IdentifiedEntityDTO)element).getIdentifier().getTypeLabel() +": " + ((IdentifiedEntityDTO)element).getIdentifier().getIdentifier() + ")";
+ }
+
return titleCache;
}
};
@Override
protected void createButtonsForButtonBar(Composite parent) {
String[] newButtonText = getNewWizardText();
+
if (newButtonText!= null){
this.newButton1 = createButton(parent, this.new_id, newButtonText[0], false);
newButton1.addSelectionListener(getNewWizardButtonSelectionListener());
+
+
if (newButtonText.length > 1){
newButton2 = createButton(parent, this.new_id2, newButtonText[1], false);
newButton2.addSelectionListener(getNewWizardButtonSelectionListener());
+
}
+
+ }
+ Button space = createButton(parent, this.space_id, " ", false);
+ space.setEnabled(false);
+ space.setVisible(false);
+ GridData gridData = new GridData();
+ gridData.grabExcessHorizontalSpace = false;
+ gridData.widthHint = 3;
+ space.setLayoutData(gridData);
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.makeColumnsEqualWidth= false;
+ if (newButtonText != null){
+ gridLayout.numColumns=newButtonText.length+2;
+ }else{
+ gridLayout.numColumns=2;
}
- //Label label = new Label(parent, SWT.NONE);
+ parent.setLayout(gridLayout);
+
super.createButtonsForButtonBar(parent);
+ super.getButton(IDialogConstants.OK_ID).setEnabled(false);
}
protected SelectionListener getNewWizardButtonSelectionListener(){
return new SelectionAdapter() {
- /* (non-Javadoc)
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
@Override
public void widgetSelected(SelectionEvent e) {
Object source = e.getSource();
}
AbstractNewEntityWizard wizard = getNewEntityWizard(text);
if(wizard!=null){
- wizard.init(null, null);
+ if (wizard.getEntity() == null){
+ wizard.init(null, null);
+ }
if(wizard.getEntity() != null) {
WizardDialog dialog = new WizardDialog(getShell(), wizard);
int status = dialog.open();
T entity = (T) wizard.getEntity();
refresh();
setPattern(entity);
+
// if (getConversationHolder() != null){
// getConversationHolder().bind();
// }
UuidAndTitleCache uuidAndTitleCacheToRemove = null;
for (UuidAndTitleCache uuidAndTitleCache : model){
- if ((cdmBaseToBeFiltered.getUuid()).equals(uuidAndTitleCache.getUuid())) {
+ if (cdmBaseToBeFiltered != null && cdmBaseToBeFiltered.contains(uuidAndTitleCache.getUuid())) {
uuidAndTitleCacheToRemove = uuidAndTitleCache;
}
}
pattern = ((Text)control).getText();
if (pattern.equals("*") || pattern.equals("?")){
callService(null);
- }else if (pattern != null){
+ }else if (StringUtils.isNotBlank(pattern)){
+// callService(CdmUtils.replaceNonWordCharacters(pattern, "."));
callService(pattern);
}
fillContentProvider(null);