Revision b1fe8acf
Added by Fabian Reimeier over 6 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/DistributionToolbar.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.vaadin.component; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
import javax.annotation.PostConstruct; |
|
6 |
|
|
7 |
import org.springframework.beans.factory.annotation.Autowired; |
|
8 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
9 |
import org.springframework.context.ApplicationEventPublisher; |
|
10 |
import org.springframework.context.event.EventListener; |
|
11 |
|
|
12 |
import com.vaadin.server.FontAwesome; |
|
13 |
import com.vaadin.server.ThemeResource; |
|
14 |
import com.vaadin.spring.annotation.SpringComponent; |
|
15 |
import com.vaadin.spring.annotation.UIScope; |
|
16 |
import com.vaadin.ui.Alignment; |
|
17 |
import com.vaadin.ui.Button; |
|
18 |
import com.vaadin.ui.HorizontalLayout; |
|
19 |
|
|
20 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
21 |
import eu.etaxonomy.cdm.service.CdmUserHelper; |
|
22 |
import eu.etaxonomy.cdm.vaadin.event.AuthenticationSuccessEvent; |
|
23 |
import eu.etaxonomy.vaadin.ui.navigation.NavigationEvent; |
|
24 |
import eu.etaxonomy.vaadin.ui.navigation.NavigationManager; |
|
25 |
|
|
26 |
@SpringComponent("distributionToolbar") |
|
27 |
@UIScope |
|
28 |
public class DistributionToolbar extends HorizontalLayout implements Serializable{ |
|
29 |
|
|
30 |
/** |
|
31 |
* automatically generated ID |
|
32 |
*/ |
|
33 |
private static final long serialVersionUID = 5344340511582993289L; |
|
34 |
|
|
35 |
@Autowired |
|
36 |
protected ApplicationEventPublisher eventBus; |
|
37 |
|
|
38 |
@Autowired |
|
39 |
@Qualifier("cdmRepository") |
|
40 |
private CdmRepository repo; |
|
41 |
|
|
42 |
@Autowired |
|
43 |
private NavigationManager navigationManager; |
|
44 |
|
|
45 |
@Autowired |
|
46 |
private CdmUserHelper userHelper; |
|
47 |
|
|
48 |
private final Button loginButton = new Button("Login"); |
|
49 |
|
|
50 |
private final Button logoutButton = new Button("Logout"); |
|
51 |
|
|
52 |
private final Button userButton = new Button(FontAwesome.USER); |
|
53 |
|
|
54 |
private final Button editButton = new Button("Edit"); |
|
55 |
|
|
56 |
private final Button saveButton = new Button("Save"); |
|
57 |
|
|
58 |
private final Button detailButton = new Button("Detail"); |
|
59 |
|
|
60 |
private final Button distributionSettingsButton = new Button("Areas and Taxa"); |
|
61 |
|
|
62 |
private final Button settingsButton = new Button("Status"); |
|
63 |
|
|
64 |
// private final Authentication authentication; |
|
65 |
// private ExcelExporter exporter = new ExcelExporter(); |
|
66 |
|
|
67 |
@PostConstruct |
|
68 |
public void init() { |
|
69 |
setMargin(true); |
|
70 |
setSpacing(true); |
|
71 |
setStyleName("toolbar"); |
|
72 |
setWidth("100%"); |
|
73 |
setHeight("75px"); |
|
74 |
|
|
75 |
// exporter.setCaption("Export"); |
|
76 |
// exporter.setIcon(new ThemeResource("icons/32/document-xsl.png")); |
|
77 |
loginButton.addClickListener(e -> performLogin()); |
|
78 |
logoutButton.addClickListener(e -> performLogout()); |
|
79 |
saveButton.setIcon(new ThemeResource("icons/32/document-save.png")); |
|
80 |
editButton.setIcon(new ThemeResource("icons/32/document-edit.png")); |
|
81 |
detailButton.setIcon(new ThemeResource("icons/32/document-txt.png")); |
|
82 |
settingsButton.setIcon(new ThemeResource("icons/32/settings_1.png")); |
|
83 |
distributionSettingsButton.setIcon(new ThemeResource("icons/32/settings_1.png")); |
|
84 |
|
|
85 |
HorizontalLayout leftLayout = new HorizontalLayout(); |
|
86 |
leftLayout.addComponent(detailButton); |
|
87 |
leftLayout.addComponent(settingsButton); |
|
88 |
leftLayout.addComponent(distributionSettingsButton); |
|
89 |
|
|
90 |
HorizontalLayout rightLayout = new HorizontalLayout(); |
|
91 |
rightLayout.addComponent(loginButton); |
|
92 |
rightLayout.addComponent(logoutButton); |
|
93 |
rightLayout.addComponent(userButton); |
|
94 |
|
|
95 |
addComponent(leftLayout); |
|
96 |
setComponentAlignment(leftLayout, Alignment.MIDDLE_LEFT); |
|
97 |
addComponent(rightLayout); |
|
98 |
setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT); |
|
99 |
setExpandRatio(rightLayout, 1); |
|
100 |
updateAuthenticationButtons(); |
|
101 |
} |
|
102 |
|
|
103 |
@EventListener |
|
104 |
public void onAuthenticationSuccessEvent(AuthenticationSuccessEvent event){ |
|
105 |
boolean isInitialized = userButton != null; |
|
106 |
// The RegistrationToolbar is being initialize even if not needed only because it is a EventListener |
|
107 |
// which causes Spring to initialize it. |
|
108 |
// TODO After switching to an other event bus this check can be removed |
|
109 |
if(isInitialized){ |
|
110 |
updateAuthenticationButtons(); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* @param event |
|
116 |
*/ |
|
117 |
protected void updateAuthenticationButtons() { |
|
118 |
if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()){ |
|
119 |
userButton.setCaption(userHelper.userName()); |
|
120 |
userButton.setVisible(true); |
|
121 |
logoutButton.setVisible(true); |
|
122 |
loginButton.setVisible(false); |
|
123 |
saveButton.setVisible(true); |
|
124 |
editButton.setVisible(true); |
|
125 |
detailButton.setVisible(true); |
|
126 |
settingsButton.setVisible(true); |
|
127 |
distributionSettingsButton.setVisible(true); |
|
128 |
} else { |
|
129 |
userButton.setCaption(null); |
|
130 |
userButton.setVisible(false); |
|
131 |
logoutButton.setVisible(false); |
|
132 |
loginButton.setVisible(true); |
|
133 |
saveButton.setVisible(false); |
|
134 |
editButton.setVisible(false); |
|
135 |
detailButton.setVisible(false); |
|
136 |
settingsButton.setVisible(false); |
|
137 |
distributionSettingsButton.setVisible(false); |
|
138 |
} |
|
139 |
} |
|
140 |
|
|
141 |
/** |
|
142 |
* @return |
|
143 |
*/ |
|
144 |
private void performLogin() { |
|
145 |
eventBus.publishEvent(new NavigationEvent("login", navigationManager.getCurrentViewName())); |
|
146 |
} |
|
147 |
|
|
148 |
|
|
149 |
private void performLogout() { |
|
150 |
userHelper.logout(); |
|
151 |
updateAuthenticationButtons(); |
|
152 |
navigationManager.reloadCurrentView(); |
|
153 |
} |
|
154 |
|
|
155 |
public Button getSettingsButton(){ |
|
156 |
return settingsButton; |
|
157 |
} |
|
158 |
|
|
159 |
public Button getDistributionSettingsButton() { |
|
160 |
return distributionSettingsButton; |
|
161 |
} |
|
162 |
|
|
163 |
public Button getEditButton() { |
|
164 |
return editButton; |
|
165 |
} |
|
166 |
|
|
167 |
public Button getSaveButton() { |
|
168 |
return saveButton; |
|
169 |
} |
|
170 |
|
|
171 |
public Button getDetailButton() { |
|
172 |
return detailButton; |
|
173 |
} |
|
174 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/component/HorizontalToolbar.java | ||
---|---|---|
1 |
package eu.etaxonomy.cdm.vaadin.component; |
|
2 |
|
|
3 |
import java.io.Serializable; |
|
4 |
|
|
5 |
import com.vaadin.server.ThemeResource; |
|
6 |
import com.vaadin.ui.Alignment; |
|
7 |
import com.vaadin.ui.Button; |
|
8 |
import com.vaadin.ui.HorizontalLayout; |
|
9 |
|
|
10 |
import eu.etaxonomy.cdm.vaadin.security.UserHelper; |
|
11 |
|
|
12 |
public class HorizontalToolbar extends HorizontalLayout implements Serializable{ |
|
13 |
|
|
14 |
|
|
15 |
/** |
|
16 |
* automatically generated ID |
|
17 |
*/ |
|
18 |
private static final long serialVersionUID = 5344340511582993289L; |
|
19 |
|
|
20 |
|
|
21 |
private final Button editButton = new Button("Edit"); |
|
22 |
|
|
23 |
private final Button saveButton = new Button("Save"); |
|
24 |
|
|
25 |
private final Button detailButton = new Button("Detail"); |
|
26 |
|
|
27 |
private final Button distributionSettingsButton = new Button("Distribution Settings"); |
|
28 |
|
|
29 |
private final Button settingsButton = new Button("Settings"); |
|
30 |
|
|
31 |
// private final Authentication authentication; |
|
32 |
// private ExcelExporter exporter = new ExcelExporter(); |
|
33 |
|
|
34 |
public HorizontalToolbar() { |
|
35 |
// authentication = (Authentication) VaadinSession.getCurrent().getAttribute("authentication"); |
|
36 |
// CdmVaadinAuthentication authentication = (CdmVaadinAuthentication) VaadinSession.getCurrent().getAttribute(CdmVaadinAuthentication.KEY); |
|
37 |
// this.authentication = authentication.getAuthentication(Page.getCurrent().getLocation(), VaadinServlet.getCurrent().getServletContext().getContextPath()); |
|
38 |
init(); |
|
39 |
} |
|
40 |
|
|
41 |
public void init() { |
|
42 |
if(UserHelper.fromSession().userIsAutheticated()){ |
|
43 |
setMargin(true); |
|
44 |
setSpacing(true); |
|
45 |
setStyleName("toolbar"); |
|
46 |
setWidth("100%"); |
|
47 |
setHeight("75px"); |
|
48 |
|
|
49 |
// addComponent(editButton); |
|
50 |
// addComponent(saveButton); |
|
51 |
addComponent(detailButton); |
|
52 |
// addComponent(exporter); |
|
53 |
|
|
54 |
// exporter.setCaption("Export"); |
|
55 |
// exporter.setIcon(new ThemeResource("icons/32/document-xsl.png")); |
|
56 |
|
|
57 |
saveButton.setIcon(new ThemeResource("icons/32/document-save.png")); |
|
58 |
editButton.setIcon(new ThemeResource("icons/32/document-edit.png")); |
|
59 |
detailButton.setIcon(new ThemeResource("icons/32/document-txt.png")); |
|
60 |
settingsButton.setIcon(new ThemeResource("icons/32/settings_1.png")); |
|
61 |
distributionSettingsButton.setIcon(new ThemeResource("icons/32/settings_1.png")); |
|
62 |
|
|
63 |
// SecurityContext context = (SecurityContext)VaadinService.getCurrentRequest().getWrappedSession().getAttribute("context"); |
|
64 |
// SecurityContext context = SecurityContextHolder.getContext(); |
|
65 |
|
|
66 |
HorizontalLayout rightLayout = new HorizontalLayout(); |
|
67 |
rightLayout.addComponent(settingsButton); |
|
68 |
rightLayout.addComponent(distributionSettingsButton); |
|
69 |
|
|
70 |
addComponent(rightLayout); |
|
71 |
setComponentAlignment(rightLayout, Alignment.MIDDLE_RIGHT); |
|
72 |
setExpandRatio(rightLayout, 1); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
public Button getSettingsButton(){ |
|
77 |
return settingsButton; |
|
78 |
} |
|
79 |
|
|
80 |
public Button getDistributionSettingsButton() { |
|
81 |
return distributionSettingsButton; |
|
82 |
} |
|
83 |
|
|
84 |
public Button getEditButton() { |
|
85 |
return editButton; |
|
86 |
} |
|
87 |
|
|
88 |
public Button getSaveButton() { |
|
89 |
return saveButton; |
|
90 |
} |
|
91 |
|
|
92 |
public Button getDetailButton() { |
|
93 |
return detailButton; |
|
94 |
} |
|
95 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/CdmSpringContextHelper.java | ||
---|---|---|
96 | 96 |
return connPool; |
97 | 97 |
} |
98 | 98 |
|
99 |
|
|
99 | 100 |
// public static JDBCConnectionPool createConnectionPool() { |
100 | 101 |
// return new J2EEConnectionPool(getCurrent().getDataSource()); |
101 | 102 |
// } |
... | ... | |
159 | 160 |
} |
160 | 161 |
|
161 | 162 |
|
162 |
|
|
163 | 163 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java | ||
---|---|---|
19 | 19 |
|
20 | 20 |
public static final String SATTR_SELECTED_AREAS = "selectedAreas"; |
21 | 21 |
|
22 |
public static final String SATTR_SELECTED_VOCABULARY_UUID = "selectedVocabularyUuid"; |
|
22 |
public static final String SATTR_SELECTED_AREA_VOCABULARY_UUID = "selectedVocabularyUuid";
|
|
23 | 23 |
|
24 | 24 |
public static final String SATTR_TAXON_NODES_UUID = "taxonNodesUUID"; |
25 | 25 |
|
... | ... | |
31 | 31 |
|
32 | 32 |
public static final String SEPARATOR = ";;"; |
33 | 33 |
|
34 |
public static void updateDistributionView(DistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas, UUID classificationUuid) {
|
|
34 |
public static void updateDistributionView(DistributionTableView distributionTableView, List<UUID> taxonNodes, TermVocabulary<NamedArea> areaVoc, Set<NamedArea> selectedAreas, UUID classificationUuid) {
|
|
35 | 35 |
VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, taxonNodes); |
36 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, term.getUuid());
|
|
36 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, areaVoc.getUuid());
|
|
37 | 37 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas); |
38 | 38 |
VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, classificationUuid); |
39 | 39 |
distributionTableView.update(); |
... | ... | |
41 | 41 |
|
42 | 42 |
public static void clearSessionAttributes(){ |
43 | 43 |
VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODES_UUID, null); |
44 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, null); |
|
44 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREA_VOCABULARY_UUID, null);
|
|
45 | 45 |
VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, null); |
46 | 46 |
VaadinSession.getCurrent().setAttribute(SATTR_CLASSIFICATION, null); |
47 | 47 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/AbstractSettingsDialogWindow.java | ||
---|---|---|
46 | 46 |
return buttonToolBar; |
47 | 47 |
} |
48 | 48 |
|
49 |
public Window createWindow() { |
|
49 |
public Window createWindow(String caption) {
|
|
50 | 50 |
window = new Window(); |
51 | 51 |
window.setModal(true); |
52 | 52 |
window.setWidth("60%"); |
53 | 53 |
window.setHeight("80%"); |
54 |
window.setCaption("Distribution Settings");
|
|
54 |
window.setCaption(caption);
|
|
55 | 55 |
window.setContent(mainLayout); |
56 | 56 |
return window; |
57 | 57 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionSettingsConfigWindow.java | ||
---|---|---|
105 | 105 |
taxonFilter.addValueChangeListener(this); |
106 | 106 |
taxonTree.addExpandListener(this); |
107 | 107 |
|
108 |
TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea(); |
|
108 |
//init areas |
|
109 |
TermVocabulary<NamedArea> chosenAreaVoc = presenter.getChosenAreaVoc(); |
|
109 | 110 |
distAreaBox.setContainerDataSource(presenter.getDistributionContainer()); |
110 |
distAreaBox.setValue(chosenArea); |
|
111 |
distAreaBox.setValue(chosenAreaVoc);
|
|
111 | 112 |
distAreaBox.addValueChangeListener(this); |
112 | 113 |
|
113 |
if(chosenArea!=null){ |
|
114 |
NamedAreaContainer container = new NamedAreaContainer(chosenArea); |
|
114 |
if(chosenAreaVoc!=null){
|
|
115 |
NamedAreaContainer container = new NamedAreaContainer(chosenAreaVoc);
|
|
115 | 116 |
namedAreaList.setContainerDataSource(container); |
116 | 117 |
} |
117 | 118 |
Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS); |
... | ... | |
261 | 262 |
Object source = event.getSource(); |
262 | 263 |
if(source==okButton){ |
263 | 264 |
List<UUID> taxonNodes = new ArrayList<>(); |
264 |
TermVocabulary<NamedArea> term = null;
|
|
265 |
TermVocabulary<NamedArea> areaVoc = null;
|
|
265 | 266 |
String uuidString = (String) classificationBox.getContainerProperty(classificationBox.getValue(),"uuid").getValue(); |
266 | 267 |
UUID classificationUuid = UUID.fromString(uuidString); |
267 | 268 |
Set<UuidAndTitleCache<TaxonNode>> treeSelection = (Set<UuidAndTitleCache<TaxonNode>>) taxonTree.getValue(); |
... | ... | |
270 | 271 |
taxonNodes.add(uuidAndTitleCache.getUuid()); |
271 | 272 |
} |
272 | 273 |
} |
273 |
term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
|
|
274 |
areaVoc = (TermVocabulary<NamedArea>) distAreaBox.getValue();
|
|
274 | 275 |
Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue(); |
275 |
DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, term, selectedAreas, classificationUuid);
|
|
276 |
DistributionEditorUtil.updateDistributionView(distributionTableView, taxonNodes, areaVoc, selectedAreas, classificationUuid);
|
|
276 | 277 |
window.close(); |
277 | 278 |
} |
278 | 279 |
else if(source==cancelButton){ |
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java | ||
---|---|---|
19 | 19 |
import java.util.Set; |
20 | 20 |
import java.util.UUID; |
21 | 21 |
|
22 |
import org.springframework.beans.factory.annotation.Autowired; |
|
23 |
import org.springframework.beans.factory.annotation.Qualifier; |
|
24 |
import org.springframework.transaction.TransactionStatus; |
|
25 |
|
|
22 | 26 |
import com.vaadin.server.VaadinSession; |
23 | 27 |
import com.vaadin.spring.annotation.SpringComponent; |
24 | 28 |
import com.vaadin.spring.annotation.ViewScope; |
25 | 29 |
import com.vaadin.ui.Notification; |
26 | 30 |
|
31 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
27 | 32 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
28 | 33 |
import eu.etaxonomy.cdm.model.common.DefinedTermBase; |
29 | 34 |
import eu.etaxonomy.cdm.model.common.Language; |
30 | 35 |
import eu.etaxonomy.cdm.model.common.Representation; |
31 | 36 |
import eu.etaxonomy.cdm.model.common.TermVocabulary; |
37 |
import eu.etaxonomy.cdm.model.description.DescriptionBase; |
|
32 | 38 |
import eu.etaxonomy.cdm.model.description.DescriptionElementBase; |
33 | 39 |
import eu.etaxonomy.cdm.model.description.Distribution; |
34 | 40 |
import eu.etaxonomy.cdm.model.description.Feature; |
... | ... | |
38 | 44 |
import eu.etaxonomy.cdm.model.taxon.Classification; |
39 | 45 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
40 | 46 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
47 |
import eu.etaxonomy.cdm.service.CdmUserHelper; |
|
41 | 48 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
42 | 49 |
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory; |
43 | 50 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
... | ... | |
55 | 62 |
|
56 | 63 |
private static final long serialVersionUID = 3313043335587777217L; |
57 | 64 |
|
65 |
@Autowired |
|
66 |
private CdmUserHelper userHelper; |
|
67 |
|
|
68 |
@Autowired |
|
69 |
@Qualifier("cdmRepository") |
|
70 |
private CdmRepository repo; |
|
71 |
|
|
58 | 72 |
public int updateDistributionField(String distributionAreaString, Object comboValue, Taxon taxon) { |
73 |
TransactionStatus tx = repo.startTransaction(); |
|
74 |
taxon = (Taxon)getRepo().getTaxonService().find(taxon.getUuid()); |
|
59 | 75 |
Set<DefinedTermBase> chosenTerms = getChosenTerms(); |
60 |
Set<NamedArea> termSet = getTermSet(); |
|
61 | 76 |
NamedArea namedArea = null; |
62 | 77 |
for(DefinedTermBase term:chosenTerms){ |
63 | 78 |
Representation representation = term.getRepresentation(Language.DEFAULT()); |
... | ... | |
82 | 97 |
} |
83 | 98 |
if(namedArea==null){ |
84 | 99 |
Notification.show("Error during update of distribution term!"); |
100 |
repo.commitTransaction(tx); |
|
85 | 101 |
return -1; |
86 | 102 |
} |
87 | 103 |
List<Distribution> distributions = getDistributions(taxon); |
... | ... | |
100 | 116 |
for (TaxonDescription desc : descriptions) { |
101 | 117 |
// add to first taxon description |
102 | 118 |
desc.addElement(distribution); |
103 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
|
|
119 |
repo.commitTransaction(tx);
|
|
104 | 120 |
return 0; |
105 | 121 |
} |
106 | 122 |
} else {// there are no TaxonDescription yet. |
107 | 123 |
TaxonDescription taxonDescription = TaxonDescription.NewInstance(taxon); |
108 | 124 |
taxonDescription.addElement(distribution); |
109 |
taxon.addDescription(taxonDescription); |
|
110 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon); |
|
125 |
repo.commitTransaction(tx); |
|
111 | 126 |
return 0; |
112 | 127 |
} |
113 | 128 |
} |
114 | 129 |
else if(comboValue == null){//delete descriptionElementBase |
115 |
distribution.getInDescription().removeElement(distribution); |
|
116 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon); |
|
130 |
DescriptionBase<?> desc = distribution.getInDescription(); |
|
131 |
desc.removeElement(distribution); |
|
132 |
repo.commitTransaction(tx); |
|
117 | 133 |
return 1; |
118 | 134 |
} |
119 |
else{ |
|
135 |
else{//update distribution
|
|
120 | 136 |
distribution.setStatus((PresenceAbsenceTerm)comboValue); |
121 |
CdmSpringContextHelper.getTaxonService().saveOrUpdate(taxon);
|
|
137 |
repo.commitTransaction(tx);
|
|
122 | 138 |
return 0; |
123 | 139 |
} |
140 |
repo.commitTransaction(tx); |
|
124 | 141 |
return -1; |
125 | 142 |
} |
126 | 143 |
|
127 | 144 |
public Set<DefinedTermBase> getChosenTerms() { |
128 | 145 |
VaadinSession session = VaadinSession.getCurrent(); |
129 |
UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
|
|
146 |
UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
|
130 | 147 |
getConversationHolder().getSession(); |
131 |
TermVocabulary<DefinedTermBase> term = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
|
|
132 |
term = CdmBase.deproxy(term);
|
|
133 |
return term.getTerms();
|
|
148 |
TermVocabulary<DefinedTermBase> voc = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
|
|
149 |
voc = CdmBase.deproxy(voc);
|
|
150 |
return voc.getTerms();
|
|
134 | 151 |
} |
135 | 152 |
|
136 | 153 |
public List<String> getAbbreviatedTermList() { |
137 | 154 |
Set<NamedArea> terms = getTermSet(); |
138 |
List<String> list = new ArrayList<String>();
|
|
139 |
for(DefinedTermBase dtb: terms){ |
|
155 |
List<String> list = new ArrayList<>(); |
|
156 |
for(DefinedTermBase<?> dtb: terms){
|
|
140 | 157 |
for(Representation r : dtb.getRepresentations()){ |
141 | 158 |
list.add(r.getAbbreviatedLabel()); |
142 | 159 |
} |
... | ... | |
154 | 171 |
|
155 | 172 |
private Set<NamedArea> getTermSet(){ |
156 | 173 |
VaadinSession session = VaadinSession.getCurrent(); |
157 |
UUID termUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
|
|
158 |
TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(termUUID, Arrays.asList("terms.representations"));
|
|
174 |
UUID vocUUID = (UUID) session.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
|
175 |
TermVocabulary<NamedArea> vocabulary = CdmSpringContextHelper.getVocabularyService().load(vocUUID, Arrays.asList("terms.representations"));
|
|
159 | 176 |
vocabulary = CdmBase.deproxy(vocabulary, TermVocabulary.class); |
160 | 177 |
return vocabulary.getTermsOrderedByLabels(Language.DEFAULT()); |
161 | 178 |
} |
... | ... | |
185 | 202 |
|
186 | 203 |
public List<Distribution> getDistributions(Taxon taxon) { |
187 | 204 |
Set<Feature> setFeature = new HashSet<>(Arrays.asList(Feature.DISTRIBUTION())); |
188 |
List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService().listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
205 |
List<Distribution> listTaxonDescription = CdmSpringContextHelper.getDescriptionService() |
|
206 |
.listDescriptionElementsForTaxon(taxon, setFeature, null, null, null, DESCRIPTION_INIT_STRATEGY); |
|
189 | 207 |
return listTaxonDescription; |
190 | 208 |
|
191 | 209 |
} |
... | ... | |
254 | 272 |
"name.$", |
255 | 273 |
"name.rank.representations", |
256 | 274 |
"name.status.type.representations", |
257 |
"taxon2.name" |
|
275 |
"taxon2.name",
|
|
258 | 276 |
}); |
259 | 277 |
|
260 | 278 |
/**Helper Methods*/ |
... | ... | |
274 | 292 |
} |
275 | 293 |
}); |
276 | 294 |
} |
295 |
|
|
296 |
/** |
|
297 |
* |
|
298 |
* {@inheritDoc} |
|
299 |
*/ |
|
300 |
@Override |
|
301 |
protected void onPresenterReady() { |
|
302 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID, taxonNodes); |
|
303 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID, voc.getUuid()); |
|
304 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS, selectedAreas); |
|
305 |
// VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION, classificationUuid); |
|
306 |
if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()) { |
|
307 |
getView().openDistributionSettings(); |
|
308 |
} |
|
309 |
} |
|
277 | 310 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java | ||
---|---|---|
15 | 15 |
import java.util.List; |
16 | 16 |
import java.util.UUID; |
17 | 17 |
|
18 |
import org.springframework.beans.factory.annotation.Autowired; |
|
18 | 19 |
import org.springframework.security.core.GrantedAuthority; |
19 | 20 |
|
20 | 21 |
import com.vaadin.data.Item; |
... | ... | |
39 | 40 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
40 | 41 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
41 | 42 |
import eu.etaxonomy.cdm.vaadin.component.DetailWindow; |
42 |
import eu.etaxonomy.cdm.vaadin.component.HorizontalToolbar;
|
|
43 |
import eu.etaxonomy.cdm.vaadin.component.DistributionToolbar;
|
|
43 | 44 |
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer; |
44 | 45 |
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer; |
45 | 46 |
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView; |
... | ... | |
60 | 61 |
private static final long serialVersionUID = 1L; |
61 | 62 |
public static final String NAME = "distTable"; |
62 | 63 |
|
63 |
private HorizontalToolbar toolbar; |
|
64 |
@Autowired |
|
65 |
private DistributionToolbar toolbar; |
|
66 |
|
|
64 | 67 |
private Table table; |
65 | 68 |
private Grid grid; |
66 | 69 |
|
... | ... | |
81 | 84 |
setHeight("100.0%"); |
82 | 85 |
|
83 | 86 |
//Horizontal Toolbar |
84 |
toolbar = new HorizontalToolbar(); |
|
85 | 87 |
mainLayout.addComponent(toolbar, "top:0.0px;right:0.0px;"); |
86 | 88 |
|
87 | 89 |
// table + formatting |
... | ... | |
166 | 168 |
} |
167 | 169 |
}); |
168 | 170 |
|
169 |
mainLayout.addComponent(table, "top:75px;right:0.0px;"); |
|
171 |
mainLayout.addComponent(table, "top:75px;right:10.0px;left:10.0px;");
|
|
170 | 172 |
|
171 | 173 |
return mainLayout; |
172 | 174 |
} |
... | ... | |
215 | 217 |
Button detailButton = toolbar.getDetailButton(); |
216 | 218 |
detailButton.setCaption("Detail View"); |
217 | 219 |
detailButton.addClickListener(event -> { |
218 |
Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow(); |
|
220 |
Object selectedItemId = DistributionTableViewBean.this.table.getValue(); |
|
221 |
// Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow(); |
|
219 | 222 |
if(selectedItemId!=null){ |
220 |
final UUID uuid = UUID.fromString(grid.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString()); |
|
223 |
final UUID uuid = UUID.fromString(table.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString()); |
|
224 |
// final UUID uuid = UUID.fromString(grid.getContainerDataSource().getItem(selectedItemId).getItemProperty("uuid").getValue().toString()); |
|
221 | 225 |
Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService().load(uuid), Taxon.class); |
222 | 226 |
List<DescriptionElementBase> listDescriptions = getPresenter().listDescriptionElementsForTaxon(taxon, null); |
223 | 227 |
DetailWindow detailWindow = new DetailWindow(taxon, listDescriptions); |
... | ... | |
244 | 248 |
@Override |
245 | 249 |
public void openSettings() { |
246 | 250 |
SettingsConfigWindow cw = new SettingsConfigWindow(this); |
247 |
Window window = cw.createWindow(); |
|
251 |
Window window = cw.createWindow("Status");
|
|
248 | 252 |
UI.getCurrent().addWindow(window); |
249 | 253 |
} |
250 | 254 |
|
... | ... | |
256 | 260 |
if(distributionSettingConfigWindow==null){ |
257 | 261 |
distributionSettingConfigWindow = new DistributionSettingsConfigWindow(this); |
258 | 262 |
} |
259 |
Window window = distributionSettingConfigWindow.createWindow(); |
|
263 |
Window window = distributionSettingConfigWindow.createWindow("Areas and Taxa");
|
|
260 | 264 |
UI.getCurrent().addWindow(window); |
261 | 265 |
} |
262 | 266 |
|
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/NoCommitFieldGroup.java | ||
---|---|---|
1 |
/** |
|
2 |
* Copyright (C) 2017 EDIT |
|
3 |
* European Distributed Institute of Taxonomy |
|
4 |
* http://www.e-taxonomy.eu |
|
5 |
* |
|
6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
|
7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
|
8 |
*/ |
|
9 |
package eu.etaxonomy.cdm.vaadin.view.distributionStatus; |
|
10 |
|
|
11 |
import com.vaadin.data.fieldgroup.FieldGroup; |
|
12 |
|
|
13 |
/** |
|
14 |
* @author freimeier |
|
15 |
* @since 18.10.2017 |
|
16 |
* |
|
17 |
*/ |
|
18 |
public class NoCommitFieldGroup extends FieldGroup{ |
|
19 |
@Override |
|
20 |
public boolean isReadOnly() { |
|
21 |
return false; |
|
22 |
} |
|
23 |
|
|
24 |
@Override |
|
25 |
public void commit() {} |
|
26 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/SettingsPresenter.java | ||
---|---|---|
24 | 24 |
import eu.etaxonomy.cdm.model.taxon.TaxonNode; |
25 | 25 |
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper; |
26 | 26 |
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil; |
27 |
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.DistributionSettingsConfigWindow; |
|
28 |
import eu.etaxonomy.cdm.vaadin.view.distributionStatus.SettingsConfigWindow; |
|
27 | 29 |
|
28 | 30 |
/** |
31 |
* Note: This presenter is used for {@link SettingsConfigWindow} AND {@link DistributionSettingsConfigWindow} |
|
32 |
* |
|
29 | 33 |
* @author alex |
30 | 34 |
* @date 22.04.2015 |
31 | 35 |
* |
36 |
* |
|
32 | 37 |
*/ |
33 | 38 |
public class SettingsPresenter { |
34 | 39 |
|
35 | 40 |
private Container distributionContainer; |
36 | 41 |
private Container distributionStatusContainer; |
37 |
private UUID termUUID;
|
|
42 |
private UUID vocUUID;
|
|
38 | 43 |
|
39 | 44 |
|
40 | 45 |
|
41 | 46 |
public SettingsPresenter(){ |
42 |
Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID); |
|
47 |
Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
|
43 | 48 |
if(selectedVocabularyUuidString!=null){ |
44 |
termUUID = UUID.fromString(selectedVocabularyUuidString.toString());
|
|
49 |
vocUUID = UUID.fromString(selectedVocabularyUuidString.toString());
|
|
45 | 50 |
} |
46 | 51 |
distributionContainer = new IndexedContainer(getNamedAreaList()); |
47 | 52 |
distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary()); |
... | ... | |
63 | 68 |
return null; |
64 | 69 |
} |
65 | 70 |
|
66 |
public TermVocabulary getChosenArea(){ |
|
67 |
return CdmSpringContextHelper.getVocabularyService().load(termUUID);
|
|
71 |
public TermVocabulary getChosenAreaVoc(){
|
|
72 |
return CdmSpringContextHelper.getVocabularyService().load(vocUUID);
|
|
68 | 73 |
} |
69 | 74 |
|
70 | 75 |
public Container getDistributionContainer() { |
Also available in: Unified diff
ref #6903