From 70946cb42ed2b40203eb0eb47212405f524c1ccf Mon Sep 17 00:00:00 2001 From: Katja Luther Date: Wed, 4 Dec 2019 09:52:12 +0100 Subject: [PATCH] ref #8677: layout and labeling in aggregation config wizard --- .../definedterm/TermDtoContentProvider.java | 14 ++- .../wizard/AvailableDistributionPage.java | 3 + .../wizard/CheckBoxTreeComposite.java | 16 +++ .../combo/OriginalSourceTypeComparator.java | 101 ++++++++++++++++++ .../ui/dialog/SuperAreaSelectionWizard.java | 2 +- ...ributionAggregationConfiguratorWizard.java | 27 ++++- .../DistributionAggregationWizardPage.java | 13 +-- .../NamedAreaTermDtoContentProvider.java | 36 +++++++ .../configurator}/wizard/SuperAreaPage.java | 34 ++++-- .../AbstractOriginalSourceElement.java | 84 +-------------- 10 files changed, 229 insertions(+), 101 deletions(-) create mode 100755 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/OriginalSourceTypeComparator.java create mode 100755 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/NamedAreaTermDtoContentProvider.java rename eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/{preference => ui/dialog/configurator}/wizard/SuperAreaPage.java (61%) diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java index bb77dd5ee..53c2f15cf 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/TermDtoContentProvider.java @@ -88,16 +88,24 @@ public class TermDtoContentProvider extends TreeNodeContentProvider { } public Collection getChildTerms(TermVocabularyDto voc) { - Collection children = vocabularyToChildTermMap.get(voc); + Collection children = getVocabularyToChildTermMap().get(voc); if(children==null){ children = new ArrayList<>(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(voc)); - vocabularyToChildTermMap.put(voc, children); + getVocabularyToChildTermMap().put(voc, children); } return children; } public void removeVocabularyFromCache(TermVocabularyDto voc){ - vocabularyToChildTermMap.remove(voc); + getVocabularyToChildTermMap().remove(voc); + } + + public Map> getVocabularyToChildTermMap() { + return vocabularyToChildTermMap; + } + + public void setVocabularyToChildTermMap(Map> vocabularyToChildTermMap) { + this.vocabularyToChildTermMap = vocabularyToChildTermMap; } } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java index 81249ebcd..0748f4edf 100755 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/AvailableDistributionPage.java @@ -39,6 +39,8 @@ import eu.etaxonomy.taxeditor.store.CdmStore; */ public class AvailableDistributionPage extends AbstractTermSelectionWizardPage { + + public AvailableDistributionPage(String pageName) { super(pageName, TermType.NamedArea); this.localPref = true; @@ -46,6 +48,7 @@ public class AvailableDistributionPage extends AbstractTermSelectionWizardPage + * @param elements + */ + public void setGrayedElements(Object[] elements) { + viewer.setGrayedElements(elements); + for (Object element: elements) { + viewer.reveal(element); + } + TreeItem[] rootItems = viewer.getTree().getItems(); + for (TreeItem rootItem : rootItems) { + updateItem(rootItem); + } + + } + @Override public void widgetSelected(SelectionEvent e) { ITreeSelection structuredSelection = viewer.getStructuredSelection(); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/OriginalSourceTypeComparator.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/OriginalSourceTypeComparator.java new file mode 100755 index 000000000..f2f656efc --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/combo/OriginalSourceTypeComparator.java @@ -0,0 +1,101 @@ +/** +* Copyright (C) 2019 EDIT +* 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. +*/ +package eu.etaxonomy.taxeditor.ui.combo; + +import java.util.Comparator; + +import eu.etaxonomy.cdm.model.reference.OriginalSourceBase; +import eu.etaxonomy.cdm.model.reference.OriginalSourceType; + +/** + * @author pplitzner, k.luther + * @since 04.12.2019 + */ +/** + * Sorts source type combo alphabetically except for PrimaryTaxonomicSource resp. + * PrimaryMediaSource which are always on top depending on the IdentifiableSource; + *
+ * The last two are always "Other" followed by "Unknown" + * @author pplitzner + * @date Jan 6, 2017 + * + */ +public class OriginalSourceTypeComparator implements Comparator{ + + private OriginalSourceBase entity; + + public OriginalSourceTypeComparator(OriginalSourceBase entity) { + this.entity = entity; + } + + /** + * {@inheritDoc} + */ + @Override + public int compare(OriginalSourceType o1, OriginalSourceType o2) { + if(o1==null){ + if(o2==null){ + return 0; + } + else{ + return -1; + } + } + if(o2==null){ + return 1; + } + //both are either taxonomic or media + else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource) + && o2.equals(OriginalSourceType.PrimaryMediaSource)){ + if(entity != null && entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){ + return 1; + } + else{ + return -1; + } + } + else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource) + && o1.equals(OriginalSourceType.PrimaryMediaSource)){ + if(entity != null && entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){ + return -1; + } + else{ + return 1; + } + } + //one is not taxonomic or media + else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource) + ||o1.equals(OriginalSourceType.PrimaryMediaSource)){ + return -1; + + } + else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource) + || o2.equals(OriginalSourceType.PrimaryMediaSource)){ + return 1; + } + //The last two are always "Other" followed by "Unknown" + else if(o1.equals(OriginalSourceType.Other)){ + if(o2.equals(OriginalSourceType.Unknown)){ + return -11; + } + else{ + return 1; + } + } + if(o2.equals(OriginalSourceType.Other)){ + return 1; + } + else{ + String message1 = o1.getKey(); + String message2 = o2.getKey(); + return message1.compareTo(message2); + } + } + +} \ No newline at end of file diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/SuperAreaSelectionWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/SuperAreaSelectionWizard.java index ca0c5f6db..db7cf3737 100755 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/SuperAreaSelectionWizard.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/SuperAreaSelectionWizard.java @@ -20,7 +20,7 @@ import eu.etaxonomy.cdm.model.location.NamedAreaLevel; import eu.etaxonomy.cdm.persistence.dto.TermDto; import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; import eu.etaxonomy.taxeditor.l10n.Messages; -import eu.etaxonomy.taxeditor.preference.wizard.SuperAreaPage; +import eu.etaxonomy.taxeditor.ui.dialog.configurator.wizard.SuperAreaPage; /** * @author k.luther diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationConfiguratorWizard.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationConfiguratorWizard.java index 0c23c0fca..c3567a304 100755 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationConfiguratorWizard.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationConfiguratorWizard.java @@ -11,18 +11,22 @@ package eu.etaxonomy.taxeditor.ui.dialog.configurator; import java.util.UUID; import org.eclipse.jface.wizard.Wizard; +import org.eclipse.swt.widgets.Display; import eu.etaxonomy.cdm.api.application.CdmApplicationState; import eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration; import eu.etaxonomy.cdm.api.service.longrunningService.ILongRunningTasksService; +import eu.etaxonomy.cdm.common.monitor.IRemotingProgressMonitor; import eu.etaxonomy.cdm.filter.TaxonNodeFilter; import eu.etaxonomy.taxeditor.l10n.Messages; +import eu.etaxonomy.taxeditor.model.AbstractUtility; +import eu.etaxonomy.taxeditor.operation.IPostMoniteredOperationEnabled; /** * @author k.luther * @since 15.11.2019 */ -public class DistributionAggregationConfiguratorWizard extends Wizard { +public class DistributionAggregationConfiguratorWizard extends Wizard implements IPostMoniteredOperationEnabled { private final DistributionAggregationConfiguration configurator; private DistributionAggregationWizardPage page; private ILongRunningTasksService longRunningTaskService; @@ -55,6 +59,20 @@ public class DistributionAggregationConfiguratorWizard extends Wizard { UUID uuid = longRunningTaskService.invoke(configurator); + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + AbstractUtility.executeMoniteredOperation("Aggregate Distributions", + uuid, + 1000, + false, + DistributionAggregationConfiguratorWizard.this, + null, + true); + + } + + }); return true; } @@ -68,4 +86,11 @@ public class DistributionAggregationConfiguratorWizard extends Wizard { } + @Override + public void postOperation(IRemotingProgressMonitor monitor) { + // TODO Auto-generated method stub + + } + + } diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java index 7c38bc816..e558ca64a 100755 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/DistributionAggregationWizardPage.java @@ -106,7 +106,7 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis super("Set Publish Flag Configuration"); this.configurator = configurator; - this.setDescription(Messages.SetPublishConfiguration_Description_Configurator); + this.setDescription("Configure the aggregation"); } @@ -159,7 +159,7 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis }); } checkUseSelectedClassification= new Button(composite, SWT.RADIO); - checkUseSelectedClassification.setText("Export selected classification"); + checkUseSelectedClassification.setText("Aggregate selected classification"); checkUseSelectedClassification.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { @@ -228,12 +228,12 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis control.setLayoutData(new GridData(SWT.FILL, SWT.LEFT, true, true)); Label higherRankLabel = new Label(control, SWT.NULL); - higherRankLabel.setText("Higher rank"); + higherRankLabel.setText("Highest rank"); comboHigherRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY); updateHigherRankCombo(); comboHigherRank.addListener(SWT.Selection, this); Label lowerRankLabel = new Label(control, SWT.NULL); - lowerRankLabel.setText("Lower rank"); + lowerRankLabel.setText("Lowest rank"); comboLowerRank = new Combo(control, SWT.BORDER | SWT.READ_ONLY); updateLowerRankCombo(); comboLowerRank.addListener(SWT.Selection, this); @@ -254,10 +254,10 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis public String getText(Object element){ if (element instanceof AggregationMode){ if (((AggregationMode)element).equals(AggregationMode.ToParent)){ - return "from child to parent"; + return "From child to parent taxon"; } if (((AggregationMode)element).equals(AggregationMode.WithinTaxon)){ - return "from sub area to super area"; + return "From sub area to super area"; } } return null; @@ -350,6 +350,7 @@ public class DistributionAggregationWizardPage extends WizardPage implements Lis List typeStrings = new ArrayList<>(); Arrays.stream(OriginalSourceType.values()).forEach(p ->typeMap.put(p.getMessage(), p)); Arrays.stream(OriginalSourceType.values()).forEach(p ->typeStrings.add(p.getMessage())); +// typeStrings.sort(new OriginalSourceTypeComparator(null)); sourceTypeViewer.setInput(typeStrings); sourceTypeViewer.setChecked(OriginalSourceType.PrimaryMediaSource.getMessage(), true); sourceTypeViewer.setChecked(OriginalSourceType.PrimaryTaxonomicSource.getMessage(), true); diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/NamedAreaTermDtoContentProvider.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/NamedAreaTermDtoContentProvider.java new file mode 100755 index 000000000..0a80946d2 --- /dev/null +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/NamedAreaTermDtoContentProvider.java @@ -0,0 +1,36 @@ +/** +* Copyright (C) 2019 EDIT +* 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. +*/ +package eu.etaxonomy.taxeditor.ui.dialog.configurator.wizard; + +import java.util.ArrayList; +import java.util.Collection; + +import eu.etaxonomy.cdm.api.service.IVocabularyService; +import eu.etaxonomy.cdm.persistence.dto.TermDto; +import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto; +import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider; +import eu.etaxonomy.taxeditor.store.CdmStore; + +/** + * @author k.luther + * @since 03.12.2019 + */ +public class NamedAreaTermDtoContentProvider extends TermDtoContentProvider { + + @Override + public Collection getChildTerms(TermVocabularyDto voc) { + Collection children = getVocabularyToChildTermMap().get(voc); + if(children==null){ + children = new ArrayList<>(CdmStore.getService(IVocabularyService.class).getCompleteTermHierarchy(voc)); + getVocabularyToChildTermMap().put(voc, children); + } + return children; + } + +} diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/SuperAreaPage.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/SuperAreaPage.java similarity index 61% rename from eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/SuperAreaPage.java rename to eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/SuperAreaPage.java index a6fa041ac..7290e135c 100755 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/preference/wizard/SuperAreaPage.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/dialog/configurator/wizard/SuperAreaPage.java @@ -6,7 +6,7 @@ * 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. */ -package eu.etaxonomy.taxeditor.preference.wizard; +package eu.etaxonomy.taxeditor.ui.dialog.configurator.wizard; import java.util.ArrayList; import java.util.Collection; @@ -24,6 +24,8 @@ import eu.etaxonomy.cdm.persistence.dto.TermDto; import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter; import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider; import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider; +import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionPage; +import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite; import eu.etaxonomy.taxeditor.store.CdmStore; /** @@ -62,19 +64,37 @@ public class SuperAreaPage extends AvailableDistributionPage { */ private void setLevelChecked() { initialiseVocabularies(); - List areasWithLevel= new ArrayList(); - List uuidList = new ArrayList<>(); - getVocabularies().stream().forEach(p -> uuidList.add(p.getUuid())); - Collection terms = CdmStore.getService(IVocabularyService.class).getTerms(uuidList); + List areasChecked= new ArrayList(); + List areasGrayed = new ArrayList(); + List vocUuidList = new ArrayList<>(); + getVocabularies().stream().forEach(p -> vocUuidList.add(p.getUuid())); + Collection terms = CdmStore.getService(IVocabularyService.class).getNamedAreaTerms(vocUuidList); for (TermDto term: terms) { if (term.getLevel() != null && term.getLevel().equals(level)){ - areasWithLevel.add(term); + areasChecked.add(term); + }else if (term.getLevel() != null && term.getLevel().isHigher(level)){ + Object[] children = ((TermDtoContentProvider)this.getViewer().getContentProvider()).getChildren(term); + boolean checked = false; + if (children != null && children.length >0){ + for (Object o: children){ + if (o instanceof TermDto){ + TermDto dto = ((TermDto)o); + if (dto.getLevel() != null && dto.getLevel().equals(level)){ + checked = true; + } + } + } + } + if (checked){ + areasGrayed.add(term); + } } } treeComposite.getViewer().setInput(getVocabularies()); - treeComposite.setCheckedElements(areasWithLevel.toArray()); + treeComposite.setCheckedElements(areasChecked.toArray()); + treeComposite.setGrayedElements(areasGrayed.toArray()); } @Override diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java index 945089ad7..e3f666594 100644 --- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java +++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java @@ -9,8 +9,6 @@ package eu.etaxonomy.taxeditor.ui.section.supplemental; -import java.util.Comparator; - import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionListener; @@ -19,6 +17,7 @@ import eu.etaxonomy.cdm.model.reference.OriginalSourceBase; import eu.etaxonomy.cdm.model.reference.OriginalSourceType; import eu.etaxonomy.taxeditor.preference.PreferencesUtil; import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement; +import eu.etaxonomy.taxeditor.ui.combo.OriginalSourceTypeComparator; import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection; import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory; import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement; @@ -83,86 +82,5 @@ public abstract class AbstractOriginalSourceElementexcept for PrimaryTaxonomicSource resp. - * PrimaryMediaSource which are always on top depending on the IdentifiableSource; - *
- * The last two are always "Other" followed by "Unknown" - * @author pplitzner - * @date Jan 6, 2017 - * - */ - private class OriginalSourceTypeComparator implements Comparator{ - - private OriginalSourceBase entity; - public OriginalSourceTypeComparator(OriginalSourceBase entity) { - this.entity = entity; - } - - /** - * {@inheritDoc} - */ - @Override - public int compare(OriginalSourceType o1, OriginalSourceType o2) { - if(o1==null){ - if(o2==null){ - return 0; - } - else{ - return -1; - } - } - if(o2==null){ - return 1; - } - //both are either taxonomic or media - else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource) - && o2.equals(OriginalSourceType.PrimaryMediaSource)){ - if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){ - return 1; - } - else{ - return -1; - } - } - else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource) - && o1.equals(OriginalSourceType.PrimaryMediaSource)){ - if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){ - return -1; - } - else{ - return 1; - } - } - //one is not taxonomic or media - else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource) - ||o1.equals(OriginalSourceType.PrimaryMediaSource)){ - return -1; - - } - else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource) - || o2.equals(OriginalSourceType.PrimaryMediaSource)){ - return 1; - } - //The last two are always "Other" followed by "Unknown" - else if(o1.equals(OriginalSourceType.Other)){ - if(o2.equals(OriginalSourceType.Unknown)){ - return -11; - } - else{ - return 1; - } - } - if(o2.equals(OriginalSourceType.Other)){ - return 1; - } - else{ - String message1 = o1.getKey(); - String message2 = o2.getKey(); - return message1.compareTo(message2); - } - } - - } } -- 2.34.1