import org.eclipse.nebula.widgets.nattable.freeze.FreezeHelper;
import org.eclipse.nebula.widgets.nattable.freeze.FreezeLayer;
import org.eclipse.nebula.widgets.nattable.grid.GridRegion;
+import org.eclipse.nebula.widgets.nattable.grid.command.ClientAreaResizeCommand;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultCornerDataProvider;
import org.eclipse.nebula.widgets.nattable.grid.data.DefaultRowHeaderDataProvider;
import eu.etaxonomy.cdm.api.service.IVocabularyService;
import eu.etaxonomy.cdm.api.service.dto.TaxonDescriptionDTO;
import eu.etaxonomy.cdm.api.service.dto.TaxonDistributionDTO;
-import eu.etaxonomy.cdm.model.common.DefinedTermBase;
import eu.etaxonomy.cdm.model.common.Language;
-import eu.etaxonomy.cdm.model.common.OrderedTermBase;
-import eu.etaxonomy.cdm.model.common.OrderedTermComparator;
-import eu.etaxonomy.cdm.model.common.Representation;
-import eu.etaxonomy.cdm.model.common.TermIdInVocabularyComparator;
-import eu.etaxonomy.cdm.model.common.TermLanguageComparator;
-import eu.etaxonomy.cdm.model.common.TermVocabulary;
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.Distribution;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.location.NamedArea;
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.cdm.model.term.DefinedTermBase;
+import eu.etaxonomy.cdm.model.term.OrderedTermBase;
+import eu.etaxonomy.cdm.model.term.OrderedTermComparator;
+import eu.etaxonomy.cdm.model.term.Representation;
+import eu.etaxonomy.cdm.model.term.TermIdInVocabularyComparator;
+import eu.etaxonomy.cdm.model.term.TermLanguageComparator;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.cdm.model.term.TermVocabulary;
import eu.etaxonomy.taxeditor.editor.EditorUtil;
import eu.etaxonomy.taxeditor.editor.l10n.Messages;
import eu.etaxonomy.taxeditor.model.AbstractUtility;
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
import eu.etaxonomy.taxeditor.preference.Resources;
+import eu.etaxonomy.taxeditor.preference.TermOrder;
import eu.etaxonomy.taxeditor.preference.wizard.AvailableDistributionWizard;
import eu.etaxonomy.taxeditor.store.CdmStore;
import eu.etaxonomy.taxeditor.store.StoreUtil;
public class DistributionEditor extends Composite {
- private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
+ private static final String DISTRIBUTION_EDITOR = "Distribution Editor"; //$NON-NLS-1$
private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
private static final String UNKNOWN = Messages.ChecklistEditor_UNKNOWN;
private static final String ELEMENT_COUNT = Messages.ChecklistEditor_ELEMENT_COUNT;
private ListDataProvider<TaxonDistributionDTO> bodyDataProvider;
private LinkedMap<String, String> propertyToLabelMap = new LinkedMap<>();
- private boolean isShowRank;
+ private boolean isShowRank = false;
private Integer countNodes;
private Text searchText;
EventList<TaxonDistributionDTO> taxonList;
- Map<UUID,Map<NamedArea,Set<DescriptionElementBase>>> taxonDistributionMap = new HashMap();
+ Map<UUID,Map<NamedArea,Set<DescriptionElementBase>>> taxonDistributionMap = new HashMap<>();
- List<TaxonDistributionDTO> descriptionsToSave = new ArrayList();
+ List<TaxonDistributionDTO> descriptionsToSave = new ArrayList<>();
SortedSet<DefinedTermBase> areas;
*/
public DistributionEditor(Composite parent, DistributionEditorPart part) {
super(parent, SWT.NULL);
+ isShowRank = PreferencesUtil.getBooleanValue(PreferencePredicate.ShowRankInDistributionEditor.getKey());
this.part = part;
this.setLayout(new GridLayout());
GridLayoutFactory.fillDefaults().applyTo(parent);
Composite topComposite = new Composite(parent, SWT.NONE);
createTopComposite(topComposite);
- Composite bottomComposite = new Composite(parent, SWT.NONE);
- GridLayoutFactory.fillDefaults().applyTo(bottomComposite);
+
natTable = new NatTable(parent, false);
parent.pack();
-
-// // natTable = new NatTable(parent, viewportLayer);
-// natTable = new NatTable(parent, false);
-
- createStatusBar(parent);
+ Composite bottomComposite = new Composite(parent, SWT.NONE);
+ GridLayoutFactory.fillDefaults().applyTo(bottomComposite);
+ createStatusBar(bottomComposite);
}
public boolean isShowRank() {
private void createStatusBar(Composite composite) {
GridData gridData = new GridData();
+ gridData.horizontalSpan = 2;
+ gridData.grabExcessHorizontalSpace = true;
+ gridData.horizontalAlignment = GridData.FILL;
+ GridLayout gridLayout = new GridLayout();
+ gridLayout.numColumns = 2;
+ composite.setLayoutData(gridData);
+ composite.setLayout(gridLayout);
+
+
+ gridData = new GridData();
gridData.horizontalSpan = 1;
gridData.grabExcessHorizontalSpace = true;
gridData.horizontalAlignment = GridData.FILL;
statusLabelSourceReference.setLayoutData(gridData);
if (defaultSource != null){
- statusLabelSourceReference.setText("Default Source Reference: " + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
+ statusLabelSourceReference.setText(Messages.DistributionEditor_defaultSource + defaultSource.getAbbrevTitle() != null? defaultSource.getAbbrevTitle() : defaultSource.getAbbrevTitleCache());
}
}
//add default configuration because autoconfigure is set to false in constructor
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
+
+
// override the default sort configuration and change the mouse bindings
// to sort on a single click
GridDataFactory.fillDefaults().grab(true, true).applyTo(natTable);
this.layout();
+ natTable.doCommand(new ClientAreaResizeCommand(natTable));
// boolean ok = natTable.doCommand(new ClientAreaResizeCommand(natTable));
- // System.out.println(ok);
+
}
GridData gridData2 = new GridData();
gridData2.horizontalSpan = 1;
gridData2.horizontalAlignment = SWT.RIGHT;
+
button1.setLayoutData(gridData2);
@Override
public void widgetSelected(SelectionEvent event) {
- defaultSource = part.getCdmEntitySession().load(ReferenceSelectionDialog.select(AbstractUtility.getShell(), null), true);
+ defaultSource = ReferenceSelectionDialog.select(AbstractUtility.getShell(), null);
- String defaultSourceStr = (defaultSource == null) ? "" : "Default Source Reference: " + defaultSource.getTitleCache();
+ String defaultSourceStr = (defaultSource == null) ? "" : Messages.DistributionEditor_defaultSource + defaultSource.getTitleCache(); //$NON-NLS-1$
if (defaultSourceStr.length()> 100){
- defaultSourceStr = defaultSourceStr.substring(0, 98) + "...";
+ defaultSourceStr = defaultSourceStr.substring(0, 98) + "..."; //$NON-NLS-1$
}
statusLabelSourceReference.setText(defaultSourceStr);
});
+ Button button3 = new Button(parent, SWT.PUSH );
+
+ button3.setLayoutData(gridData3);
+ button3.setText(Messages.ChecklistEditor_REMOVE_DEFAULT_SOURCE);
+ button2.setToolTipText(Messages.ChecklistEditor_REMOVE_DEFAULT_SOURCE_TOOLTIP);
+ button3.addSelectionListener(new SelectionAdapter() {
+
+ @Override
+ public void widgetSelected(SelectionEvent event) {
+ defaultSource = null;
+
+ String defaultSourceStr = (defaultSource == null) ? "" : Messages.DistributionEditor_defaultSource + defaultSource.getTitleCache(); //$NON-NLS-1$
+ if (defaultSourceStr.length()> 100){
+ defaultSourceStr = defaultSourceStr.substring(0, 98) + "..."; //$NON-NLS-1$
+ }
+ statusLabelSourceReference.setText(defaultSourceStr);
+
+ button3.setBackground(EditorUtil.getColor(Resources.COLOR_CONTROL_SELECTED));
+ }
+
+ });
+
parent.pack();
return searchText;
}
GridLayout gridLayout = new GridLayout(3, false);
gridLayout.marginWidth = 0;
gridLayout.marginHeight = 0;
+ GridData gridData2 = new GridData();
+ gridData2.horizontalSpan = 1;
+ gridData2.horizontalAlignment = SWT.RIGHT;
+ gridData2.horizontalIndent = 3;
+ parent.setLayoutData(gridData2);
parent.setLayout(gridLayout);
searchText = createSearchBar(parent);
}
loadNamedAreas();
+ if (areas == null){
+ areas = new TreeSet<>();
+ }
for (DefinedTermBase area: areas) {
this.areaToColumnIndexMap.put(index++, (NamedArea)area);
String areaLabel;
//String areaLabel = area.getLabel();
- String property = areaLabel;
+ String property = area.getUuid().toString();
propertyToLabelMap.put(property, areaLabel);
}
+
}
private SortedSet<DefinedTermBase> loadNamedAreas() {
//IPreferenceStore preferenceStore = PreferencesUtil.getPreferenceStore();
- String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
+ String valuesAreas = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), true);
String values = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
+ Set<UUID> uuidList = new HashSet<UUID>();
+ String[] split;
+ List<String> listValue;
+ List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
if (values != null && values != "") { //$NON-NLS-1$
- String[] split = values.split(";"); //$NON-NLS-1$
- List<String> listValue = Arrays.asList(split);
- List<DefinedTermBase> termlist = new ArrayList<DefinedTermBase>();
- Set<UUID> uuidList = new HashSet<UUID>();
+ split = values.split(";"); //$NON-NLS-1$
+ listValue = Arrays.asList(split);
+
+
UUID uuid;
for(String s : listValue){
uuid = UUID.fromString(s);
uuidList.add(uuid);
}
- IVocabularyService service = CdmStore.getService(IVocabularyService.class);
- List<TermVocabulary> vocs = service.find(uuidList);
- split = valuesAreas.split(";");
+ }
+
+ List<TermVocabulary> vocs = new ArrayList<>();
+ IVocabularyService service = CdmStore.getService(IVocabularyService.class);
+ if (uuidList.isEmpty()){
+ List<TermVocabulary<DefinedTermBase>> vocList = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
+ vocs.addAll(vocList);
+ }else{
+ vocs= service.find(uuidList);
+ }
+ for (TermVocabulary voc: vocs){
+ termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
+ }
+ List<DefinedTermBase> filteredList = new ArrayList();
+ if (valuesAreas != null && valuesAreas != "") {
+ split = valuesAreas.split(";"); //$NON-NLS-1$
listValue = Arrays.asList(split);
- for (TermVocabulary voc: vocs){
- termlist.addAll(service.getTerms(voc, null, null, null, null).getRecords());
- }
- List<DefinedTermBase> filteredList = new ArrayList();
+
for (DefinedTermBase area: termlist){
if (listValue.contains(area.getUuid().toString())) {
filteredList.add(area);
}
}
+ }else{
+ filteredList.addAll(termlist);
+ }
- if (PreferencesUtil.isSortNamedAreaByOrderInVocabulary()){
- areas = getTermsOrderedByVocabularyOrder(filteredList);
- } else if (PreferencesUtil.isShowIdInVocabularyInChecklistEditor()){
- areas = getTermsOrderedByIdInVocabulary(filteredList);
- }else{
- areas = getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
- }
+
+ String sortOrder = PreferencesUtil.getSortNamedAreasInDistributionEditor();
+ if (sortOrder.equals(TermOrder.Natural.getKey())){
+ areas = getTermsOrderedByVocabularyOrder(filteredList);
+ } else if (sortOrder.equals(TermOrder.IdInVoc.getKey())){
+ areas = getTermsOrderedByIdInVocabulary(filteredList);
+ }else{
+ areas = getTermsOrderedByLabels(filteredList, CdmStore.getDefaultLanguage());
}
+
return null;
}
if(listTerm != null){
result.addAll(listTerm);
}
+
return result;
}
return defaultSource;
}
- /**
- * @param result
- */
- public void reloadDistributions() {
- loadDistributions(taxonList);
-
- }
+// /**
+// * @param result
+// */
+// public void reloadDistributions() {
+// loadDistributions(taxonList);
+//
+// }