/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
public class ReferenceSortProvider extends AbstractSortProvider<Reference> {
/**
- *
+ *
*/
public ReferenceSortProvider() {
comparators.put("Type", new ReferenceTypeComparator());
}
private class ReferenceYearComparator implements Comparator<Reference> {
-
+
/**
* @param o1
* @return
*/
private String getYearString(Reference o) {
- TimePeriod datePublished = o == null ? null : o.getDatePublished();
+ TimePeriod datePublished = o == null ? null : o.getDatePublished();
return datePublished == null? null : datePublished.toString();
}
-
+
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- public int compare(Reference o1, Reference o2) {
+ @Override
+ public int compare(Reference o1, Reference o2) {
String yearString1 = getYearString(o1);
String yearString2 = getYearString(o2);
if (yearString1 == null) {
}
int returnVal = yearString1.compareToIgnoreCase(yearString2);
if (returnVal == 0) {
- return new TitleCacheComparator<Reference>().compare(o1, o2);
- } else {
- return returnVal;
+ returnVal = new TitleCacheComparator<Reference>().compare(o1, o2);
+
}
- }
+ return returnVal;
+
+ }
}
-
+
private class ReferenceTypeComparator implements Comparator<Reference> {
-
+
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
- public int compare(Reference o1, Reference o2) {
+ @Override
+ public int compare(Reference o1, Reference o2) {
String typeString1 = o1.getClass().toString();
String typeString2 = o2.getClass().toString();
if (typeString1 == null) {
}
int returnVal = typeString1.compareToIgnoreCase(typeString2);
if (returnVal == 0) {
+ //the TitleCacheComparator already fulfills the comparator contract
return new TitleCacheComparator<Reference>().compare(o1, o2);
} else {
return returnVal;
}
- }
+ }
}
-
+
}
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
* @version 1.0
*/
public class TitleCacheComparator<T extends IIdentifiableEntity> implements Comparator<T> {
-
+
private boolean fIgnoreCase;
private String getTitleCache(T o) {
return o == null ? null : o.getTitleCache();
}
-
+
/* (non-Javadoc)
* @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
*/
/** {@inheritDoc} */
- public int compare(T o1, T o2) {
+ @Override
+ public int compare(T o1, T o2) {
String titleCache1 = getTitleCache(o1);
String titleCache2 = getTitleCache(o2);
if (titleCache1 == null && titleCache2 == null) {
}
if (titleCache2 == null) {
return 1;
- }
- return fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) :
+ }
+ int result = fIgnoreCase ? titleCache1.compareToIgnoreCase(titleCache2) :
titleCache1.compareTo(titleCache2);
+
+ if (result == 0){
+ result = o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
}
}
- class ReferencingClassComparator implements Comparator<CdmBase> {
+ class ReferencingClassComparator implements Comparator<CdmBase> {
@Override
public int compare(CdmBase o1, CdmBase o2) {
String string1 = o1.getClass().getSimpleName();
String string2 = o2.getClass().getSimpleName();
- int classCompare = string1.compareToIgnoreCase(string2);
- if (classCompare == 0) {
+ int result = string1.compareToIgnoreCase(string2);
+ if (result == 0) {
string1 = DescriptionHelper.getObjectDescription(o1);
string2 = DescriptionHelper.getObjectDescription(o2);
- return string1.compareToIgnoreCase(string2);
- } else {
- return classCompare;
+ result = string1.compareToIgnoreCase(string2);
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
}
+ return result;
}
}
private class SortByTermTypeMessage implements Comparator<TermType> {
@Override
public int compare(TermType t1, TermType t2) {
- return t1.getMessage().compareTo(t2.getMessage());
+ if (t1.equals(t2)){
+ return 0;
+ }
+ int result = t1.getMessage().compareTo(t2.getMessage());
+ if (result == 0){
+ return t1.compareTo(t2);
+ }
+ return result;
}
}
public static final String XML = "xml";
public static final String CSV = "csv";
-
-
+
+
public static final String ZIP = "zip";
private static boolean csvExport = false;
-
+
private static boolean csvNameExport = false;
private static String CSV_PRINT_EXPORT ="CSV_PRINT_EXPORT";
private final String extension;
private Combo classificationSelectionCombo;
-
+
private List<Classification> classifications;
-
+
private Classification selectedClassification;
/**
"Export the contents of the currently selected database into Comma Separated Value format.",
CSV);
}
-
+
/**
* @return
*/
"Export the names of the currently selected database into Semicolon Separated Value format.",
CSV);
}
-
+
/**
* @return
*/
@Override
public int compare(Classification o1, Classification o2) {
- return o1.getTitleCache().compareTo(o2.getTitleCache());
+ if (o1.equals(o2)){
+ return 0;
+ }
+ int result = o1.getTitleCache().compareTo(o2.getTitleCache());
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
});
-
+
selectedClassification = classifications.iterator().next();
}
if(csvExport || csvPrintExport){
Label comboBoxLabel = new Label(composite, SWT.NONE);
comboBoxLabel.setText("Classification");
-
+
createClassificationSelectionCombo(composite);
classificationSelectionCombo.setLayoutData(new GridData(SWT.FILL, SWT.FILL,
true, false, 2, 1));
}
-
-
+
+
Label fileLabel = new Label(composite, SWT.NONE);
@Override
public void widgetSelected(SelectionEvent e) {
selectedClassification = classifications.get(classificationSelectionCombo.getSelectionIndex());
-
+
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
//not needed here
-
+
}
public UUID getSelectedClassificationUUID() {
-
+
return selectedClassification.getUuid();
}
*/
@Override
public int compare(Method o1, Method o2) {
+ if (o1.equals(o2)){
+ return 0;
+ }
if(o1.getName()==null && o2.getName()!=null){
return -1;
}
return 1;
}
if(o1.getName()==null && o2.getName()==null){
- return 0;
+ return o1.toString().compareTo(o1.toString());
+ }
+ int result = o1.getName().compareTo(o2.getName());
+ if (result == 0){
+ return o1.toString().compareTo(o1.toString());
}
- return o1.getName().compareTo(o2.getName());
+ return result;
}
});
/**
* Copyright (C) 2009 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
* Implements a {@link Comparator} for {@link DefinedTermBase} objects based on the term's label.
* The compare algorithm compares a term's label. Example: If used on an unsorted list of terms, the
* list will be alphabetically sorted by label afterwards.
- *
+ *
* @author n.hoffmann
* @date Jan 18, 2012
*
}
String label1 = o1.getLabel(CdmStore.getDefaultLanguage()) != null ? o1.getLabel(CdmStore.getDefaultLanguage()) : o1.getTitleCache();
String label2 = o2.getLabel(CdmStore.getDefaultLanguage()) != null ? o2.getLabel(CdmStore.getDefaultLanguage()) : o2.getTitleCache();
- return label1.compareTo(label2);
+ int result = label1.compareTo(label2);
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
};
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
@Override
public int compare(DescriptionElementBase o1, DescriptionElementBase o2) {
- return DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+ if (o1.equals(o2)){
+ return 0;
+ }
+ int result = DescriptionHelper.getLabel(o1).compareTo(DescriptionHelper.getLabel(o2));
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
};
-
+
private Set<FeatureNodeContainer> featureNodeContainers = new HashSet<FeatureNodeContainer>();
-
+
private FeatureNodeContainer root;
private DescriptionBase description;
private FeatureTree featureTree;
-
+
public FeatureNodeContainerTree(DescriptionBase description, FeatureTree featureTree){
this.description = description;
this.featureTree = featureTree;
-
+
root = new FeatureNodeContainer(this);
-
+
buildTree();
}
-
+
/**
* Traverses the given {@link FeatureNode} and computes a FeatureNodeContainer branch if the
* given {@link TaxonDescription} has elements for the given feature node or any of its children
*/
public void buildTree(){
List<FeatureNode> children = featureTree.getRootChildren();
-
+
// if(description.getElements().isEmpty()){
// return;
// }
-
+
for(FeatureNode featureNode : children){
root.findLeaves(featureNode);
}
}
-
+
/**
* <p>getFeatureNodeContainerForDescriptionElement</p>
*
*/
public FeatureNodeContainer getFeatureNodeContainerForDescriptionElement (DescriptionElementBase descriptionElement) {
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getDescriptionElements().contains(descriptionElement)){
return container;
}
return null;
}
-
+
/**
* Returns all elements contained in the given {@link DescriptionBase description} that have the given {@link Feature feature}.
- *
+ *
* @param description
* @param feature
* @return a list of description elements with the given feature alphabetically sorted by {@link DescriptionHelper#getLabel(Object)}
*/
public List<DescriptionElementBase> getDescriptionsElementsForFeature(Feature feature) {
List<DescriptionElementBase> featureElements = new ArrayList<DescriptionElementBase>();
-
+
Set<DescriptionElementBase> elements = description.getElements();
-
+
if (elements != null) {
for (DescriptionElementBase element : elements) {
- Feature elementFeature = (Feature) HibernateProxyHelper.deproxy(element.getFeature());
-
+ Feature elementFeature = HibernateProxyHelper.deproxy(element.getFeature());
+
if (feature.equals(elementFeature)) {
featureElements.add(element);
}
}
}
-
+
if(featureElements.size() != 0){
Collections.sort(featureElements, comparator);
}
-
+
return featureElements;
}
-
-
- public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
+
+
+ public FeatureNodeContainer getFeatureNodeContainer(Feature feature) {
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getFeature().equals(feature)){
return container;
}
return null;
}
-
+
public FeatureNodeContainer getFeatureNodeContainer(FeatureNode featureNode){
List<FeatureNodeContainer> leafs = root.getLeafs();
-
+
for(FeatureNodeContainer container : leafs){
if(container.getFeatureNode().equals(featureNode)){
return container;
}
return null;
}
-
+
public void addContainer(FeatureNodeContainer container){
featureNodeContainers.add(container);
}
/**
- *
+ *
*/
public void removeContainer(FeatureNodeContainer container) {
featureNodeContainers.remove(container);
}
-
+
public FeatureNodeContainer getRoot() {
return root;
}
public FeatureTree getFeatureTree() {
return featureTree;
}
-
+
}
private ConversationHolder conversation;
- protected List<T> model;
- private String settings;
-
-
-
+ protected List<T> model;
+ private String settings;
+
+
+
/**
* <p>Constructor for AbstractFilteredCdmResourceSelectionDialog.</p>
*
* @param shell a {@link org.eclipse.swt.widgets.Shell} object.
- * @param conversation
+ * @param conversation
* @param title a {@link java.lang.String} object.
* @param multi a boolean.
* @param settings a {@link java.lang.String} object.
* @param cdmEnum a T object.
* @param <T> a T object.
*/
- protected AbstractFilteredCdmEnumSelectionDialog(Shell shell,
- ConversationHolder conversation,
- String title,
- boolean multi,
+ protected AbstractFilteredCdmEnumSelectionDialog(Shell shell,
+ ConversationHolder conversation,
+ String title,
+ boolean multi,
String settings,
T cdmEnum) {
super(shell, multi);
setTitle(title);
setMessage("Use * for wildcard, or ? to see all entries");
this.settings = settings;
-
+
this.conversation = conversation;
-
+
init();
-
+
initModel();
-
+
String objectTitle = getTitle(cdmEnum);
if (objectTitle != null) {
setInitialPattern(objectTitle);
}
-
+
setListLabelProvider(createListLabelProvider());
setDetailsLabelProvider(createDetailsLabelProvider());
-
+
setSelectionHistory(new ResourceSelectionHistory());
}
-
+
/**
* By default, we are returning the standard list label provider
- *
- * Override in subclasses if you want different behavior
- *
+ *
+ * Override in subclasses if you want different behavior
+ *
* @return
*/
protected ILabelProvider createDetailsLabelProvider() {
}
/**
- *
+ *
* @return
*/
protected ILabelProvider createListLabelProvider() {
* Will run before initModel()
*/
protected void init() {
-
+
}
-
+
/**
* <p>getSelectionFromDialog</p>
*
* @return a TYPE object.
*/
protected static <TYPE extends IEnumTerm> TYPE getSelectionFromDialog(AbstractFilteredCdmEnumSelectionDialog<TYPE> dialog) {
-
+
int result = dialog.open();
-
+
if (result == Window.CANCEL) {
return null;
}
-
+
return dialog.getSelectedEnumTerm();
}
protected String getTitle(T cdmEnum) {
return cdmEnum.getMessage();
}
-
+
/** {@inheritDoc} */
@Override
public void refresh() {
- initModel();
+ initModel();
super.refresh();
}
-
+
/**
* <p>initModel</p>
*/
public boolean equalsFilter(ItemsFilter filter) {
return false;
}
-
+
@Override
public boolean isConsistentItem(Object item) {
return false;
}
return text != null ? matches(text) : false;
}
-
+
};
}
-
+
/**
* Set the filter input to the Agent's title cache
* @param cdmObject a T object.
*/
protected void setPattern(T cdmObject) {
- // FilteredSelection does some very tricky caching to make sure it
- // runs with high performance.
+ // FilteredSelection does some very tricky caching to make sure it
+ // runs with high performance.
// This works for most use cases, but we want to change the model while the dialog is open
// and all the clever caching prevents the content provider from knowing that the model has changed
- // I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient
+ // I am aware, that this is a hack, but the FilteredSelectionDialog API does not offer a convenient
// way to solve the problem.
try {
Field lastCompletedFilter = this.getClass().getSuperclass().getSuperclass().getDeclaredField("lastCompletedFilter");
} catch (IllegalAccessException e) {
MessagingUtils.error(getClass(), e);
}
-
- // this also is not the nicest way to do it.
+
+ // this also is not the nicest way to do it.
// I am still amazed, that FilteredSelectionDialog does not offer any methods to change its data
// once it was opened. Am I doing it wrong?
String pattern = getTitle(cdmObject);
((Text) getPatternControl()).setText(pattern);
}
-
+
/* (non-Javadoc)
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog#fillContentProvider(org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.AbstractContentProvider, org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.ItemsFilter, org.eclipse.core.runtime.IProgressMonitor)
*/
ItemsFilter itemsFilter, IProgressMonitor progressMonitor)
throws CoreException {
try {
- if(model != null){
+ if(model != null){
progressMonitor.beginTask("Looking for entities", model.size());
for(T element : model){
contentProvider.add(element, itemsFilter);
@Override
protected Comparator getItemsComparator() {
return new Comparator<IEnumTerm>() {
- public int compare(IEnumTerm entity1,
+ @Override
+ public int compare(IEnumTerm entity1,
IEnumTerm entity2) {
- Collator collator = Collator.getInstance();
- return collator.compare(entity1.getMessage(), entity2.getMessage());
+ if (entity1.equals(entity2)){
+ return 0;
+ }
+ Collator collator = Collator.getInstance();
+
+ int result = collator.compare(entity1.getMessage(), entity2.getMessage());
+ if (result == 0){
+ return entity1.getUuid().compareTo(entity2.getUuid());
+ }
+ return result;
}
};
}
protected IStatus validateItem(Object item) {
return Status.OK_STATUS;
}
-
+
/**
* <p>getSelectedUuidAndTitleCache</p>
*
Object[] result = getResult();
return result[0] == null ? null : (T) result[0];
}
-
+
/**
* <p>Getter for the field <code>settings</code>.</p>
*
}
return settings;
}
-
+
/**
- *
+ *
* @author n.hoffmann
* @created Oct 19, 2009
* @version 1.0
/*
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#restoreItemFromMemento(org.eclipse.ui.IMemento)
*/
- protected Object restoreItemFromMemento(IMemento element) {
+ @Override
+ protected Object restoreItemFromMemento(IMemento element) {
return element.getString("resource"); //$NON-NLS-1$
}
/*
* @see org.eclipse.ui.dialogs.FilteredItemsSelectionDialog.SelectionHistory#storeItemToMemento(java.lang.Object,
* org.eclipse.ui.IMemento)
*/
- protected void storeItemToMemento(Object item, IMemento element) {
+ @Override
+ protected void storeItemToMemento(Object item, IMemento element) {
element.putString("resource", item.toString()); //$NON-NLS-1$
}
}
-
+
/**
* <p>getNewWizardLinkText</p>
*
* @return a {@link java.lang.String} object.
*/
protected abstract String getNewWizardLinkText();
-
+
/**
* <p>getNewEntityWizard</p>
- * @param parameter
+ * @param parameter
* @return a {@link eu.etaxonomy.taxeditor.newWizard.AbstractNewEntityWizard} object.
*/
protected abstract AbstractNewEntityWizard getNewEntityWizard(String parameter);
-
+
public class FilteredCdmResourceLabelProvider extends LabelProvider {
- public String getText(Object element) {
+ @Override
+ public String getText(Object element) {
if (element == null) {
return null;
}
return ((IEnumTerm) element).getMessage();
- }
+ }
};
/* (non-Javadoc)
}
return null;
}
-
+
protected SelectionListener getNewWizardLinkSelectionListener(){
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);
WizardDialog dialog = new WizardDialog(getShell(), wizard);
int status = dialog.open();
-
+
if (status == IStatus.OK) {
-
+
T entity = (T) wizard.getEntity();
refresh();
}
};
}
-
+
/**
* <p>getConversationHolder</p>
*
* @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
*/
- public ConversationHolder getConversationHolder() {
+ @Override
+ public ConversationHolder getConversationHolder() {
return conversation;
}
-
+
/** {@inheritDoc} */
- public void update(CdmDataChangeMap changeEvents) {}
+ @Override
+ public void update(CdmDataChangeMap changeEvents) {}
}
@Override
public int compare(Classification o1, Classification o2) {
- return o1.getTitleCache().compareTo(o2.getTitleCache());
+ if (o1.equals(o2)){
+ return 0;
+ }
+ int result = o1.getTitleCache().compareTo(o2.getTitleCache());
+ if (result == 0){
+ return o1.getUuid().compareTo(o2.getUuid());
+ }
+ return result;
}
});
if (this.cdmBaseToBeFiltered == null){