commit fda2cb065a3a17ab4700be0f18fc64f915f79568
Author: Patrick Plitzner
Date: Thu Oct 13 08:43:49 2016 +0200
ref #5458 Add toggle button for abbreviations to settings menu
- extract constants for session attributes
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java b/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
index cb3bed04..5961c458 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
@@ -115,7 +115,7 @@ public class DistributionTablePresenter {
public Set getChosenTerms() {
VaadinSession session = VaadinSession.getCurrent();
- UUID termUUID = (UUID) session.getAttribute("selectedTerm");
+ UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
TermVocabulary term = vocabularyService.load(termUUID);
term = CdmBase.deproxy(term, TermVocabulary.class);
return term.getTerms();
@@ -140,14 +140,14 @@ public class DistributionTablePresenter {
return namedAreas;
}
- public List getNamedAreasLabels(boolean abbreviated){
+ public List getNamedAreasLabels(){
Set selectedAreas = getNamedAreas();
List namedAreaTitles = new ArrayList<>();
for (NamedArea namedArea : selectedAreas) {
String title = null;
Representation representation = namedArea.getRepresentation(Language.DEFAULT());
if(representation!=null){
- if(abbreviated){
+ if(DistributionEditorUtil.isAbbreviatedLabels()){
title = representation.getAbbreviatedLabel();
}
else{
@@ -164,7 +164,7 @@ public class DistributionTablePresenter {
private Set getTermSet(){
VaadinSession session = VaadinSession.getCurrent();
- UUID termUUID = (UUID) session.getAttribute("selectedTerm");
+ UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
TermVocabulary vocabulary = vocabularyService.load(termUUID);
vocabulary = CdmBase.deproxy(vocabulary, TermVocabulary.class);
return vocabulary.getTermsOrderedByLabels(Language.DEFAULT());
@@ -213,7 +213,7 @@ public class DistributionTablePresenter {
public TaxonNode getChosenTaxonNode() {
VaadinSession session = VaadinSession.getCurrent();
- UUID taxonNodeUUID = (UUID) session.getAttribute("taxonNodeUUID");
+ UUID taxonNodeUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_TAXON_NODE_UUID);
TaxonNode classificationNode = taxonNodeService.load(taxonNodeUUID);
return classificationNode;
}
@@ -230,7 +230,7 @@ public class DistributionTablePresenter {
nodeIds.add(taxonNode.getId());
}
Set namesAreas = getNamedAreas();
- CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreas, true));
+ CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreas));
return container;
}
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java b/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
index 75301e28..fa132b65 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmQueryFactory.java
@@ -63,7 +63,7 @@ public class CdmQueryFactory {
return generateQueryDelegate(SELECT_QUERY, COUNT_QUERY, CONTAINS_QUERY);
}
- public static QueryDelegate generateTaxonDistributionQuery(List taxonNodeIds, Collection namedAreas, boolean abbreviatedLabels) throws SQLException {
+ public static QueryDelegate generateTaxonDistributionQuery(List taxonNodeIds, Collection namedAreas) throws SQLException {
String idString = "";
Iterator nodeIterator = taxonNodeIds.iterator();
@@ -101,7 +101,7 @@ public class CdmQueryFactory {
String label = null;
Representation representation = namedArea.getRepresentation(Language.DEFAULT());
if(representation!=null){
- if(abbreviatedLabels){
+ if(DistributionEditorUtil.isAbbreviatedLabels()){
label = representation.getAbbreviatedLabel();
}
else{
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java b/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
index b6f46dee..454bcdc2 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
@@ -40,6 +40,11 @@ public class DistributionEditorUtil {
//navigate to table view
UI.getCurrent().getNavigator().navigateTo(VIEW_TABLE);
}
+
+ public static boolean isAbbreviatedLabels(){
+ Object isAbbreviated = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS);
+ return (isAbbreviated==null || (boolean) isAbbreviated);
+ }
public static final String SATTR_CONVERSATION = "conversation";
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
index 14549ef3..97516e79 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
@@ -10,6 +10,10 @@ import java.util.UUID;
import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.event.ContextClickEvent;
+import com.vaadin.event.ContextClickEvent.ContextClickListener;
+import com.vaadin.event.ItemClickEvent;
+import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.event.ShortcutAction.KeyCode;
import com.vaadin.event.ShortcutAction.ModifierKey;
import com.vaadin.navigator.View;
@@ -110,12 +114,12 @@ public class DistributionTableView extends CustomComponent implements View{
table.setSortEnabled(true);
columnList = new ArrayList(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
- List namedAreas = listener.getNamedAreasLabels(true);
+ List namedAreas = listener.getNamedAreasLabels();
columnList.addAll(namedAreas);
table.setVisibleColumns(columnList.toArray());
headerList = new ArrayList(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,"Rang"}));
- headerList.addAll(listener.getNamedAreasLabels(true));
+ headerList.addAll(listener.getNamedAreasLabels());
String[] string = new String[headerList.size()];
table.setColumnHeaders(headerList.toArray(string));
@@ -127,7 +131,7 @@ public class DistributionTableView extends CustomComponent implements View{
table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size());
table.setCacheRate(20);
-
+
//add generated columns for NamedAreas
Collection> containerPropertyIds = table.getContainerPropertyIds();
for (Object object : containerPropertyIds) {
@@ -217,7 +221,7 @@ public class DistributionTableView extends CustomComponent implements View{
String itemCaption = null;
Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT());
if(representation!=null){
- if((Boolean)VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS)){
+ if(DistributionEditorUtil.isAbbreviatedLabels()){
itemCaption = representation.getAbbreviatedLabel();
}
else{
diff --git a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
index 847db623..60badac7 100644
--- a/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
+++ b/src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
@@ -14,11 +14,13 @@ import java.util.HashSet;
import com.vaadin.data.Container;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.server.VaadinSession;
import com.vaadin.ui.AbstractLayout;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
+import com.vaadin.ui.CheckBox;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.HorizontalLayout;
@@ -47,6 +49,7 @@ public class SettingsConfigWindow extends CustomComponent {
private ComboBox classificationBox;
private ComboBox distAreaBox;
private Tree taxonTree;
+ private CheckBox boxToggleAbbreviatedLabels;
private Button okButton;
private Button cancelButton;
private final SettingsPresenter presenter;
@@ -73,6 +76,8 @@ public class SettingsConfigWindow extends CustomComponent {
classificationBox.setContainerDataSource(taxonNodeContainer);
classificationBox.setValue(presenter.getChosenTaxonNode().getClassification().getRootNode());
classificationBox.addValueChangeListener(new ValueChangeListener() {
+ private static final long serialVersionUID = -8159622506131474118L;
+
@Override
public void valueChange(ValueChangeEvent event) {
TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
@@ -84,10 +89,22 @@ public class SettingsConfigWindow extends CustomComponent {
taxonTree.setValue(presenter.getChosenTaxonNode());
distAreaBox.setContainerDataSource(distributionContainer);
distAreaBox.setValue(chosenArea);
+ boxToggleAbbreviatedLabels.addValueChangeListener(new ValueChangeListener() {
+
+ private static final long serialVersionUID = 5734502056399266546L;
+
+ @Override
+ public void valueChange(ValueChangeEvent event) {
+ VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
+
+ }
+ });
distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
okButton.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = -2554281233796070939L;
+
@Override
public void buttonClick(ClickEvent event) {
TaxonNode taxonNode;
@@ -103,6 +120,8 @@ public class SettingsConfigWindow extends CustomComponent {
});
cancelButton.addClickListener(new ClickListener() {
+ private static final long serialVersionUID = -99532405408235383L;
+
@Override
public void buttonClick(ClickEvent event) {
window.close();
@@ -149,6 +168,10 @@ public class SettingsConfigWindow extends CustomComponent {
distStatusSelect = new TwinColSelect("Distribution Status:");
distStatusSelect.setImmediate(false);
distStatusSelect.setWidth("100%");
+
+ //toggle abbreviated labels
+ boxToggleAbbreviatedLabels = new CheckBox("Show abbreviated labels", DistributionEditorUtil.isAbbreviatedLabels());
+ boxToggleAbbreviatedLabels.setImmediate(true);
//taxonomy
taxonTree = new Tree("Taxonomy");
@@ -156,6 +179,7 @@ public class SettingsConfigWindow extends CustomComponent {
verticalLayout.addComponent(classificationBox);
verticalLayout.addComponent(distAreaBox);
+ verticalLayout.addComponent(boxToggleAbbreviatedLabels);
verticalLayout.addComponent(distStatusSelect);
verticalLayout.setExpandRatio(distStatusSelect, 1);
verticalLayout.setSizeFull();