Revision f3bb4cae
Added by Andreas Kohlbecker about 7 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/editor/reference/ReferencePopupEditor.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.editor.reference; |
|
10 |
|
|
11 |
import org.springframework.context.annotation.Scope; |
|
12 |
|
|
13 |
import com.vaadin.data.fieldgroup.FieldGroup.CommitException; |
|
14 |
import com.vaadin.spring.annotation.SpringComponent; |
|
15 |
import com.vaadin.ui.TextField; |
|
16 |
|
|
17 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
18 |
import eu.etaxonomy.vaadin.ui.view.AbstractPopupEditor; |
|
19 |
|
|
20 |
/** |
|
21 |
* @author a.kohlbecker |
|
22 |
* @since Apr 4, 2017 |
|
23 |
* |
|
24 |
*/ |
|
25 |
|
|
26 |
@SpringComponent |
|
27 |
@Scope("prototype") |
|
28 |
public class ReferencePopupEditor extends AbstractPopupEditor<Reference> { |
|
29 |
|
|
30 |
private static final long serialVersionUID = -4347633563800758815L; |
|
31 |
|
|
32 |
private TextField titleField; |
|
33 |
|
|
34 |
/** |
|
35 |
* @param layout |
|
36 |
* @param dtoType |
|
37 |
*/ |
|
38 |
public ReferencePopupEditor() { |
|
39 |
super(Reference.class); |
|
40 |
/* |
|
41 |
"type", |
|
42 |
"uri", |
|
43 |
"abbrevTitleCache", |
|
44 |
"protectedAbbrevTitleCache", |
|
45 |
"nomenclaturallyRelevant", |
|
46 |
"authorship", |
|
47 |
"referenceAbstract", |
|
48 |
"title", |
|
49 |
"abbrevTitle", |
|
50 |
"editor", |
|
51 |
"volume", |
|
52 |
"pages", |
|
53 |
"edition", |
|
54 |
"isbn", |
|
55 |
"issn", |
|
56 |
"doi", |
|
57 |
"seriesPart", |
|
58 |
"datePublished", |
|
59 |
"publisher", |
|
60 |
"placePublished", |
|
61 |
"institution", |
|
62 |
"school", |
|
63 |
"organization", |
|
64 |
"inReference" |
|
65 |
*/ |
|
66 |
addTextField("Reference cache", "titleCache"); |
|
67 |
addTextField("Abbrev. cache", "abbrevTitleCache"); |
|
68 |
titleField = addTextField("Title", "title"); |
|
69 |
titleField.setRequired(true); |
|
70 |
addTextField("NomenclaturalTitle", "abbrevTitle"); |
|
71 |
// addTextField("Author(s)", "authorship").setRequired(true); |
|
72 |
addTextField("Editor", "editor"); |
|
73 |
addTextField("Series", "seriesPart"); |
|
74 |
addTextField("Volume", "volume"); |
|
75 |
addTextField("Pages", "pages"); |
|
76 |
addTextField("Place published", "placePublished"); |
|
77 |
addTextField("Publisher", "publisher").setRequired(true); |
|
78 |
// TODO implement a TimePeriod component addDateField("DatePublished", "datePublished") // .setConverter(new JodaDateTimeConverter()); |
|
79 |
addTextField("ISSN", "issn"); |
|
80 |
addTextField("ISBN", "isbn"); |
|
81 |
addTextField("DOI", "doi"); |
|
82 |
|
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* {@inheritDoc} |
|
87 |
*/ |
|
88 |
@Override |
|
89 |
public String getWindowCaption() { |
|
90 |
return "Reference editor"; |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* {@inheritDoc} |
|
95 |
*/ |
|
96 |
@Override |
|
97 |
public void focusFirst() { |
|
98 |
titleField.focus(); |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* {@inheritDoc} |
|
103 |
*/ |
|
104 |
@Override |
|
105 |
public void storeDto(Reference bean) throws CommitException { |
|
106 |
//TODO this should happen in the AbstractPopupEditor! |
|
107 |
getRepsitory().getReferenceService().saveOrUpdate(bean); |
|
108 |
} |
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
} |
src/main/java/eu/etaxonomy/cdm/vaadin/view/registration/RegistrationWorkflowPresenter.java | ||
---|---|---|
23 | 23 |
import eu.etaxonomy.cdm.mock.RegistrationService; |
24 | 24 |
import eu.etaxonomy.cdm.model.name.Rank; |
25 | 25 |
import eu.etaxonomy.cdm.model.name.TaxonNameFactory; |
26 |
import eu.etaxonomy.cdm.model.reference.Reference; |
|
27 |
import eu.etaxonomy.cdm.model.reference.ReferenceFactory; |
|
28 |
import eu.etaxonomy.cdm.vaadin.editor.reference.ReferencePopupEditor; |
|
26 | 29 |
import eu.etaxonomy.cdm.vaadin.event.ReferenceEvent; |
27 | 30 |
import eu.etaxonomy.cdm.vaadin.event.ShowDetailsEvent; |
28 | 31 |
import eu.etaxonomy.cdm.vaadin.event.registration.RegistrationWorkflowEvent; |
... | ... | |
83 | 86 |
} |
84 | 87 |
} |
85 | 88 |
|
86 |
// @EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EventType).ADD") |
|
87 |
// public void onReferenceAddEvent(ReferenceEvent event) { |
|
88 |
// getView().openReferenceEditor(null); |
|
89 |
// } |
|
89 |
@EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EntityEventType).ADD") |
|
90 |
public void onReferenceAddEvent(ReferenceEvent event) { |
|
91 |
Reference reference = ReferenceFactory.newGeneric(); |
|
92 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class); |
|
93 |
popup.showInEditor(reference); |
|
94 |
} |
|
90 | 95 |
|
91 | 96 |
@EventListener(condition = "#event.eventType ==T(eu.etaxonomy.cdm.vaadin.event.EntityEventType).EDIT") |
92 | 97 |
public void onReferenceEditEvent(ReferenceEvent event) { |
93 |
getView().openReferenceEditor(null); |
|
98 |
Reference reference = getRepo().getReferenceService().find(event.getEntityId()); |
|
99 |
ReferencePopupEditor popup = getNavigationManager().showInPopup(ReferencePopupEditor.class); |
|
100 |
popup.showInEditor(reference); |
|
94 | 101 |
} |
95 | 102 |
|
96 | 103 |
|
src/main/java/eu/etaxonomy/vaadin/mvp/AbstractPresenter.java | ||
---|---|---|
8 | 8 |
import com.vaadin.spring.annotation.ViewScope; |
9 | 9 |
|
10 | 10 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
11 |
import eu.etaxonomy.vaadin.ui.NavigationManager; |
|
11 | 12 |
|
12 | 13 |
/** |
13 | 14 |
* AbstractPresenter is the base class of all presenter components. Presenter's |
... | ... | |
36 | 37 |
@Qualifier("cdmRepository") |
37 | 38 |
private CdmRepository repo; |
38 | 39 |
|
40 |
@Autowired |
|
41 |
private NavigationManager navigationManager; |
|
42 |
|
|
39 | 43 |
/** |
40 | 44 |
* @return the repo |
41 | 45 |
*/ |
... | ... | |
75 | 79 |
|
76 | 80 |
} |
77 | 81 |
|
82 |
/** |
|
83 |
* @return the navigationManager |
|
84 |
*/ |
|
85 |
public NavigationManager getNavigationManager() { |
|
86 |
return navigationManager; |
|
87 |
} |
|
88 |
|
|
78 | 89 |
} |
src/main/java/eu/etaxonomy/vaadin/ui/navigation/NavigationManagerBean.java | ||
---|---|---|
1 | 1 |
package eu.etaxonomy.vaadin.ui.navigation; |
2 | 2 |
|
3 |
import java.util.Collection; |
|
3 | 4 |
import java.util.HashMap; |
4 | 5 |
import java.util.Map; |
5 | 6 |
|
... | ... | |
41 | 42 |
popupMap = new HashMap<>(); |
42 | 43 |
} |
43 | 44 |
|
44 |
@Autowired(required=false) |
|
45 |
private Map<String, PopupView> popupViews = null; |
|
45 |
private Map<String, PopupView> popupViews = new HashMap<>(); |
|
46 |
|
|
47 |
@Autowired(required=false) |
|
48 |
private void popUpViews(Collection<PopupView> popupViews){ |
|
49 |
popupViews.forEach(view -> this.popupViews.put(view.getClass().getSimpleName(), view)); |
|
50 |
} |
|
46 | 51 |
|
47 | 52 |
/* |
48 | 53 |
* Why UriFragmentManager must be initialized lazily: |
src/main/java/eu/etaxonomy/vaadin/ui/view/AbstractPopupEditor.java | ||
---|---|---|
24 | 24 |
import com.vaadin.ui.VerticalLayout; |
25 | 25 |
import com.vaadin.ui.themes.ValoTheme; |
26 | 26 |
|
27 |
import eu.etaxonomy.cdm.api.application.CdmRepository; |
|
27 | 28 |
import eu.etaxonomy.vaadin.ui.view.DoneWithPopupEvent.Reason; |
28 | 29 |
|
29 |
public abstract class AbstractPopupEditor<DTO extends Object> extends CustomComponent
|
|
30 |
implements PopupView {
|
|
30 |
//FIXME this pop editor is not following the MVP pattern, the com.vaadin.devday.mvp.ui.AbstractPopupView is designed better in this sense!!
|
|
31 |
public abstract class AbstractPopupEditor<DTO extends Object> extends CustomComponent implements PopupView {
|
|
31 | 32 |
|
32 | 33 |
private static final long serialVersionUID = 1441816620197127918L; |
33 | 34 |
|
... | ... | |
40 | 41 |
@Autowired |
41 | 42 |
ApplicationEventPublisher eventBus; |
42 | 43 |
|
44 |
@Autowired |
|
45 |
CdmRepository cdmRepository; |
|
46 |
|
|
43 | 47 |
private HorizontalLayout buttonLayout; |
44 | 48 |
|
45 | 49 |
private Button save; |
... | ... | |
64 | 68 |
} |
65 | 69 |
} |
66 | 70 |
|
71 |
protected CdmRepository getRepsitory() { |
|
72 |
return cdmRepository; |
|
73 |
} |
|
74 |
|
|
67 | 75 |
public abstract void storeDto(DTO bean) throws CommitException; |
68 | 76 |
|
69 | 77 |
public AbstractPopupEditor(Class<DTO> dtoType) { |
src/main/java/eu/etaxonomy/vaadin/ui/view/ViewAreaBean.java | ||
---|---|---|
49 | 49 |
addComponentAsFirst(this.mainMenu.asComponent()); |
50 | 50 |
} |
51 | 51 |
|
52 |
// TODO was this needed to avoid bean loading probelms? Otherwise remove it
|
|
52 |
// TODO was this needed to avoid bean loading problems? Otherwise remove it
|
|
53 | 53 |
// private MainMenu mainMenuInstantiator; |
54 | 54 |
// @PostConstruct |
55 | 55 |
// protected void initialize() { |
Also available in: Unified diff
ref #6169 very basic Reference editor experiment