X-Git-Url: https://dev.e-taxonomy.eu/gitweb/taxeditor.git/blobdiff_plain/667025a545eb8a1553ec97e1bd3d4fe3a0101f36..071232d5824aea2e5e0d6fd6a1b7c3e5de89a1cf:/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java index e48ae2775..564face00 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/selection/AbstractFilteredCdmResourceSelectionDialog.java @@ -1,4 +1,3 @@ -// $Id$ /** * Copyright (C) 2007 EDIT * European Distributed Institute of Taxonomy @@ -10,43 +9,49 @@ package eu.etaxonomy.taxeditor.ui.dialog.selection; -import java.lang.reflect.Field; import java.text.Collator; +import java.util.ArrayList; +import java.util.Collections; import java.util.Comparator; import java.util.HashSet; +import java.util.Iterator; import java.util.List; import java.util.Set; import java.util.UUID; +import java.util.regex.Pattern; -import org.eclipse.core.runtime.CoreException; +import org.apache.commons.lang.StringUtils; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.OperationCanceledException; -import org.eclipse.core.runtime.Status; +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.jface.viewers.StructuredSelection; import org.eclipse.jface.window.Window; import org.eclipse.jface.wizard.WizardDialog; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionAdapter; 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.Link; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; -import org.eclipse.ui.IMemento; -import org.eclipse.ui.dialogs.FilteredItemsSelectionDialog; -import eu.etaxonomy.cdm.api.conversation.ConversationHolder; -import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; +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; import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; -import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; +import eu.etaxonomy.taxeditor.l10n.Messages; import eu.etaxonomy.taxeditor.model.MessagingUtils; import eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard; import eu.etaxonomy.taxeditor.preference.IPreferenceKeys; @@ -58,18 +63,22 @@ import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin; * * @author n.hoffmann * @created 04.06.2009 - * @version 1.0 */ public abstract class AbstractFilteredCdmResourceSelectionDialog extends - FilteredItemsSelectionDialog implements IConversationEnabled { + SearchDialog {//implements IConversationEnabled { - private final ConversationHolder conversation; +// private final ConversationHolder conversation = null; protected List> model; private final Set transientCdmObjects = new HashSet(); private final String settings; + protected final Integer limitOfInitialElements = null; - protected T cdmBaseToBeFiltered; + private T selectedObject; + + protected Set cdmBaseToBeFiltered; + + protected Job searchJob; /** @@ -83,27 +92,22 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog a T object. */ - protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, ConversationHolder conversation, String title, boolean multi, String settings, T cdmObject) { - super(shell, multi); - setTitle(title); - setMessage("Use * for wildcard, or ? to see all entries"); + protected AbstractFilteredCdmResourceSelectionDialog(Shell shell, //ConversationHolder conversation, + String title, boolean multi, String settings, T cdmObject) { + super(shell, title); + setShellStyle(SWT.DIALOG_TRIM); + setMessage(Messages.SearchDialog_patternLabel); this.settings = settings; - - this.conversation = conversation; - + 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(); - - initModel(); - - String objectTitle = getTitle(cdmObject); - if (objectTitle != null) { - setInitialPattern(objectTitle); - } - + shell.setCursor(cursor); setListLabelProvider(createListLabelProvider()); - setDetailsLabelProvider(createDetailsLabelProvider()); - setSelectionHistory(new ResourceSelectionHistory()); } /** @@ -141,20 +145,36 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog TYPE getSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog dialog) { - //dialog.setInitialPattern(""); - int result = dialog.open(); - - if (result == Window.CANCEL) { - return null; - } - - UUID uuid = dialog.getSelectedUuidAndTitleCache().getUuid(); - if(uuid == null){ - return null; - } - return dialog.getCdmObjectByUuid(uuid); + UuidAndTitleCache result = getUuidAndTitleCacheSelectionFromDialog(dialog); + if (result != null){ + return dialog.getCdmObjectByUuid(result.getUuid()); + } else { + return null; + } } + /** + *

getSelectionFromDialog

+ * + * @param dialog a {@link eu.etaxonomy.taxeditor.ui.dialog.selection.AbstractFilteredCdmResourceSelectionDialog} object. + * @param a TYPE object. + * @return a TYPE object. + */ + protected static UuidAndTitleCache getUuidAndTitleCacheSelectionFromDialog(AbstractFilteredCdmResourceSelectionDialog dialog) { + if (dialog == null){ + return null; + } + int result = dialog.open(); + + 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, * retrieve it from the CdmStore. @@ -179,13 +199,6 @@ public abstract class AbstractFilteredCdmResourceSelectionDialogisObjectTransient

@@ -218,54 +231,6 @@ public abstract class AbstractFilteredCdmResourceSelectionDialoginitModel

- */ - abstract protected void initModel(); - - /* (non-Javadoc) - * @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) { - String text = null; - if(item instanceof UuidAndTitleCache){ - text = ((UuidAndTitleCache) item).getTitleCache(); - }else if(item instanceof String){ - text = (String) item; - } - return text != null ? matches(text) : false; - } - - }; - } - /** * Set the filter input to the Agent's title cache @@ -273,65 +238,69 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog>(); + } if(model != null){ - progressMonitor.beginTask("Looking for entities", model.size()); - for(UuidAndTitleCache element : model){ - contentProvider.add(element, itemsFilter); - if (progressMonitor.isCanceled()) { - throw new OperationCanceledException(); - } - progressMonitor.worked(1); + if (progressMonitor != null){ + progressMonitor.beginTask("Looking for entities", model.size()); + } + sort(); + + contentProvider.reset(); + Iterator> iterator = model.iterator(); + UuidAndTitleCache element; + while(iterator.hasNext()){ + element = iterator.next(); + + if (cdmBaseToBeFiltered == null || !cdmBaseToBeFiltered.contains(element.getUuid())){ + contentProvider.add(element); + } + if (progressMonitor != null){ + if (progressMonitor.isCanceled()) { + return; + } + progressMonitor.worked(1); + } } + this.refresh(); }else{ + MessagingUtils.warn(getClass(), "Model for Filtered Selection is null:" + this.getClass().getSimpleName()); } } finally { - progressMonitor.done(); + if (progressMonitor != null) { + progressMonitor.done(); + } } } - /* (non-Javadoc) + + protected void sort() { + Collections.sort(model, getItemsComparator()); + } + + /* (non-Javadoc) * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#getDialogSettings() */ /** {@inheritDoc} */ - @Override + protected IDialogSettings getDialogSettings() { IDialogSettings settings = TaxeditorStorePlugin.getDefault().getDialogSettings().getSection(getSettings()); @@ -345,7 +314,7 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog() { @Override public int compare(UuidAndTitleCache entity1, UuidAndTitleCache entity2) { Collator collator = Collator.getInstance(); - return collator.compare(entity1.getTitleCache(), entity2.getTitleCache()); + if (entity1 == entity2){ + return 0; + } + + if (entity1 == null && entity2 != null){ + return -1; + } + if (entity2 == null && entity1 != null){ + return 1; + } + if (entity1.getUuid().equals(entity2.getUuid())){ + return 0; + } + if (entity1.getTitleCache() == null && entity2.getTitleCache() != null){ + return -1; + } + if (entity2.getTitleCache() == null){ + return 1; + } + int result = collator.compare(entity1.getTitleCache(), entity2.getTitleCache()); + if (result == 0){ + result = entity1.getUuid().compareTo(entity2.getUuid()); + } + return result; } }; } - /* (non-Javadoc) - * @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#validateItem(java.lang.Object) - */ - /** {@inheritDoc} */ - @Override - protected IStatus validateItem(Object item) { - return Status.OK_STATUS; - } /** *

getSelectedUuidAndTitleCache

@@ -381,11 +366,25 @@ public abstract class AbstractFilteredCdmResourceSelectionDialogGetter for the field settings.

* * @return a {@link java.lang.String} object. @@ -397,36 +396,14 @@ public abstract class AbstractFilteredCdmResourceSelectionDialoggetNewWizardLinkText

* * @return a {@link java.lang.String} object. */ - protected abstract String getNewWizardLinkText(); + protected abstract String[] getNewWizardText(); /** *

getNewEntityWizard

@@ -443,9 +420,13 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog 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; + } + 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) { - - AbstractNewEntityWizard wizard = getNewEntityWizard(e.text); - - wizard.init(null, null); - if(wizard.getEntity() != null) { - WizardDialog dialog = new WizardDialog(getShell(), wizard); - int status = dialog.open(); - - if (status == IStatus.OK) { - - T entity = (T) wizard.getEntity(); - model.add(new UuidAndTitleCache(entity.getUuid(), - entity.getId(), - getTitle(entity))); - refresh(); - setPattern(entity); - getConversationHolder().bind(); - } - //FIXME : Need to make sure this is a stable fix (ticket 3822) - getConversationHolder().commit(); - } + Object source = e.getSource(); + String text = null; + if (source instanceof Button){ + Button sourceButton = (Button) source; + text = sourceButton.getText(); + } + AbstractNewEntityWizard wizard = getNewEntityWizard(text); + if(wizard!=null){ + if (wizard.getEntity() == null){ + wizard.init(null, null); + } + if(wizard.getEntity() != null) { + WizardDialog dialog = new WizardDialog(getShell(), wizard); + int status = dialog.open(); + + if (status == IStatus.OK) { + + T entity = (T) wizard.getEntity(); + refresh(); + setPattern(entity); + +// if (getConversationHolder() != null){ +// getConversationHolder().bind(); +// } + } + //FIXME : Need to make sure this is a stable fix (ticket 3822) +// if (getConversationHolder() != null){ +// getConversationHolder().commit(); +// } + } + } } }; } @@ -503,15 +528,15 @@ public abstract class AbstractFilteredCdmResourceSelectionDialoggetConversationHolder

* * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object. - */ - @Override - public ConversationHolder getConversationHolder() { - return conversation; - } +// */ +// @Override +// public ConversationHolder getConversationHolder() { +// return conversation; +// } /** {@inheritDoc} */ - @Override - public void update(CdmDataChangeMap changeEvents) {} +// @Override +// public void update(CdmDataChangeMap changeEvents) {} /** * Don't want to add for example a taxon or synonym to itself @@ -525,11 +550,41 @@ public abstract class AbstractFilteredCdmResourceSelectionDialog