Project

General

Profile

Revision cb4029b0

IDcb4029b0c84a39860f81732db8573f0fb85ab530
Parent 092fd728
Child 75f20bed

Added by Patrick Plitzner over 4 years ago

ref #5458 Redesign navigation architecture

  • after login the user will be redirected directly to the table view and the settings dialog will be opened -made settings window implement ClickListener and ValueChangeListener
  • fixed possible NPEs due to redesign

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/DistributionTablePresenter.java
150 150

  
151 151
	public Set<NamedArea> getNamedAreas(){
152 152
	    Set<NamedArea> namedAreas = (Set<NamedArea>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
153
	    if(namedAreas.isEmpty()){
153
	    if(namedAreas!=null && namedAreas.isEmpty()){
154 154
	        return getTermSet();
155 155
	    }
156 156
        return namedAreas;
......
219 219
	public List<TaxonNode> getAllNodes(){
220 220
		TaxonNode taxonNode = getChosenTaxonNode();
221 221
		List<TaxonNode> nodes = new ArrayList<TaxonNode>();
222
		if(taxonNode.getTaxon()!=null){
223
			nodes.add(taxonNode);
222
		if(taxonNode!=null){
223
			if(taxonNode.getTaxon()!=null){
224
				nodes.add(taxonNode);
225
			}
226
			nodes.addAll(taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null));
224 227
		}
225
		nodes.addAll(taxonNodeService.loadChildNodesOfTaxonNode(taxonNode, null, true, null));
226 228
		return nodes;
227 229
	}
228 230

  
......
245 247
		for (TaxonNode taxonNode : getAllNodes()) {
246 248
			nodeIds.add(taxonNode.getId());
247 249
		}
248
		Set<NamedArea> namesAreas = getNamedAreas();
249
		CdmSQLContainer container = new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namesAreas));
250
		return container;
250
		Set<NamedArea> namedAreas = getNamedAreas();
251
		if(namedAreas!=null){
252
			return new CdmSQLContainer(CdmQueryFactory.generateTaxonDistributionQuery(nodeIds, namedAreas));
253
		}
254
		return null;
251 255
	}
252 256

  
253 257
	protected static final List<String> DESCRIPTION_INIT_STRATEGY = Arrays.asList(new String []{
src/main/java/eu/etaxonomy/cdm/vaadin/presenter/dbstatus/settings/SettingsPresenter.java
45 45

  
46 46

  
47 47
    public SettingsPresenter(){
48
        init();
49

  
50
    }
51

  
52
    private void init() {
53 48
        taxonNodeService = CdmSpringContextHelper.getTaxonNodeService();
54
        taxonNodeUuid = UUID.fromString(VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODE_UUID).toString());
55
        termUUID = UUID.fromString(VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID).toString());
56
        distributionContainer = new IndexedContainer(getNamedAreaList());
57
        distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
49
		Object taxonNodeUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_TAXON_NODE_UUID);
50
		Object selectedVocabularyUuidString = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_VOCABULARY_UUID);
51
		if(taxonNodeUuidString!=null){
52
			taxonNodeUuid = UUID.fromString(taxonNodeUuidString.toString());
53
		}
54
		if(selectedVocabularyUuidString!=null){
55
			termUUID = UUID.fromString(selectedVocabularyUuidString.toString());
56
		}
57
		distributionContainer = new IndexedContainer(getNamedAreaList());
58
		distributionStatusContainer = new IndexedContainer(getPresenceAbsenceVocabulary());
58 59
    }
59 60

  
60 61
    public TaxonNode getChosenTaxonNode(){
......
68 69
    public Container getDistributionContainer() {
69 70
        return distributionContainer;
70 71
    }
72
    
71 73
    public void setDistributionContainer(Container distributionContainer) {
72 74
        this.distributionContainer = distributionContainer;
73 75
    }
76
    
74 77
    public Container getDistributionStatusContainer() {
75 78
        return distributionStatusContainer;
76 79
    }
80
    
77 81
    public void setDistributionStatusContainer(Container distributionStatusContainer) {
78 82
        this.distributionStatusContainer = distributionStatusContainer;
79 83
    }
80 84

  
81 85
    private List<TermVocabulary<DefinedTermBase>> getNamedAreaList() {
82

  
83 86
        vocabularyService = CdmSpringContextHelper.getVocabularyService();
84 87
        List<TermVocabulary<DefinedTermBase>> termList = vocabularyService.findByTermType(TermType.NamedArea);
85 88
        return termList;
86 89
    }
90
    
87 91
    private List<DefinedTermBase<?>> getPresenceAbsenceVocabulary(){
88 92
        termService = CdmSpringContextHelper.getTermService();
89 93
        return termService.listByTermType(TermType.PresenceAbsenceTerm, null, null, null, DESCRIPTION_INIT_STRATEGY);
......
98 102
    		"media",
99 103
    });
100 104

  
101

  
102 105
}
src/main/java/eu/etaxonomy/cdm/vaadin/ui/DbStatusUI.java
9 9
import com.vaadin.server.VaadinRequest;
10 10
import com.vaadin.ui.UI;
11 11

  
12
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionSelectionPresenter;
13 12
import eu.etaxonomy.cdm.vaadin.servlet.CdmVaadinConversationalServlet;
14
import eu.etaxonomy.cdm.vaadin.view.dbstatus.DistributionSelectionView;
13
import eu.etaxonomy.cdm.vaadin.view.dbstatus.RedirectAfterLoginView;
15 14

  
16 15
@Theme("macosx")
17 16
@Title("CDM Board")
18 17
@SuppressWarnings("serial")
19 18
public class DbStatusUI extends AbstractAuthenticatedUI{
20 19

  
21
	//    @WebServlet(value = "/*", asyncSupported = true, initParams = {
22
	//			@WebInitParam(name="org.atmosphere.cpr.asyncSupport", value="org.atmosphere.container.Jetty9AsyncSupportWithWebSocket")
23
	//	})
24

  
25
	private static final String FIRST_VIEW = "selection";
26

  
20
	private static final String FIRST_VIEW = "redirectDbStatus";
27 21

  
28 22
	@WebServlet(value = {"/app/dbstatus/*"}, asyncSupported = true)
29 23
	@VaadinServletConfiguration(productionMode = true, ui = DbStatusUI.class, widgetset = "eu.etaxonomy.cdm.vaadin.AppWidgetSet")
......
34 28
	@Override
35 29
	protected void doInit(VaadinRequest request) {
36 30
		Navigator navigator = UI.getCurrent().getNavigator();
37
		DistributionSelectionView dsv = new DistributionSelectionView();
38
		new DistributionSelectionPresenter(dsv);
39
		navigator.addView("selection", dsv);
40

  
41

  
31
		RedirectAfterLoginView view = new RedirectAfterLoginView();
32
		navigator.addView(getFirstViewName(), view);
42 33
	}
43 34

  
44 35
	@Override
......
46 37
		return FIRST_VIEW;
47 38
	}
48 39

  
49

  
50 40
}
src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
3 3
import java.util.Set;
4 4

  
5 5
import com.vaadin.server.VaadinSession;
6
import com.vaadin.ui.Notification;
7 6
import com.vaadin.ui.UI;
8 7

  
9 8
import eu.etaxonomy.cdm.model.common.TermVocabulary;
......
25 24
    public static final String SEPARATOR = ";;";
26 25

  
27 26
    public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
28
		if(taxonNode==null){
29
			Notification.show("Please choose a classification and/or taxon", Notification.Type.HUMANIZED_MESSAGE);
30
			return;
31
		}
32
		if(term==null){
33
			Notification.show("Please choose a distribution area", Notification.Type.HUMANIZED_MESSAGE);
34
			return;
35
		}
36 27
	    VaadinSession.getCurrent().setAttribute(SATTR_TAXON_NODE_UUID, taxonNode.getUuid());
37 28
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_VOCABULARY_UUID, term.getUuid());
38 29
	    VaadinSession.getCurrent().setAttribute(SATTR_SELECTED_AREAS, selectedAreas);
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
102 102
			e.printStackTrace();
103 103
			return;
104 104
		}
105
		if(container==null){
106
			return;
107
		}
105 108

  
106 109
		table.setContainerDataSource(container);
107 110
		table.setColumnReorderingAllowed(true);
......
192 195

  
193 196
			@Override
194 197
            public void buttonClick(ClickEvent event) {
195
                SettingsConfigWindow cw = new SettingsConfigWindow();
196
                Window window  = cw.createWindow();
197
                getUI().addWindow(window);
198
                openSettings();
198 199
            }
199 200
        });
200 201

  
......
217 218
		});
218 219

  
219 220
	}
221
	
222
	public void openSettings() {
223
		SettingsConfigWindow cw = new SettingsConfigWindow();
224
        Window window  = cw.createWindow();
225
        getUI().addWindow(window);
226
	}
220 227

  
221 228
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/RedirectAfterLoginView.java
1
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
2

  
3
import com.vaadin.navigator.View;
4
import com.vaadin.navigator.ViewChangeListener.ViewChangeEvent;
5
import com.vaadin.ui.CustomComponent;
6
import com.vaadin.ui.UI;
7

  
8
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.DistributionTablePresenter;
9
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
10

  
11
public class RedirectAfterLoginView extends CustomComponent implements View{
12

  
13
	private static final long serialVersionUID = 7678509076808950380L;
14

  
15
	@Override
16
	public void enter(ViewChangeEvent event) {
17
	    //navigate to table view
18
		DistributionTableView distributionTableView = new DistributionTableView();
19
		new DistributionTablePresenter(distributionTableView);
20
		UI.getCurrent().getNavigator().addView(DistributionEditorUtil.VIEW_TABLE, distributionTableView);
21
	    UI.getCurrent().getNavigator().navigateTo(DistributionEditorUtil.VIEW_TABLE);
22

  
23
	    distributionTableView.openSettings();
24
	}
25

  
26
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
9 9
*/
10 10
package eu.etaxonomy.cdm.vaadin.view.dbstatus;
11 11

  
12
import java.util.HashSet;
12
import java.util.Set;
13 13

  
14 14
import com.vaadin.data.Container;
15
import com.vaadin.data.Property;
15 16
import com.vaadin.data.Property.ValueChangeEvent;
16 17
import com.vaadin.data.Property.ValueChangeListener;
17 18
import com.vaadin.server.VaadinSession;
......
24 25
import com.vaadin.ui.ComboBox;
25 26
import com.vaadin.ui.CustomComponent;
26 27
import com.vaadin.ui.HorizontalLayout;
28
import com.vaadin.ui.Label;
29
import com.vaadin.ui.ListSelect;
30
import com.vaadin.ui.Notification;
27 31
import com.vaadin.ui.Tree;
28 32
import com.vaadin.ui.TwinColSelect;
29 33
import com.vaadin.ui.VerticalLayout;
......
32 36
import eu.etaxonomy.cdm.model.common.TermVocabulary;
33 37
import eu.etaxonomy.cdm.model.location.NamedArea;
34 38
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
39
import eu.etaxonomy.cdm.vaadin.container.NamedAreaContainer;
35 40
import eu.etaxonomy.cdm.vaadin.container.TaxonNodeContainer;
36 41
import eu.etaxonomy.cdm.vaadin.presenter.dbstatus.settings.SettingsPresenter;
37 42
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
......
41 46
 * @date 22.04.2015
42 47
 *
43 48
 */
44
public class SettingsConfigWindow extends CustomComponent {
49
public class SettingsConfigWindow extends CustomComponent implements ValueChangeListener, ClickListener{
45 50

  
46 51
	private static final long serialVersionUID = -8220442386869594032L;
47 52
    private VerticalLayout mainLayout;
48 53
    private TwinColSelect distStatusSelect;
49 54
    private ComboBox classificationBox;
50 55
    private ComboBox distAreaBox;
56
    private ListSelect namedAreaList;
51 57
    private Tree taxonTree;
58
    private Label labelNoClassification;
52 59
    private CheckBox boxToggleAbbreviatedLabels;
53 60
    private Button okButton;
54 61
    private Button cancelButton;
......
69 76
    }
70 77

  
71 78
    private void init() {
72
        Container taxonNodeContainer = new TaxonNodeContainer(null);
73 79
        Container distributionContainer = presenter.getDistributionContainer();
74
        TermVocabulary<?> chosenArea = presenter.getChosenArea();
80
        TermVocabulary<NamedArea> chosenArea = presenter.getChosenArea();
81
        
75 82
        classificationBox.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
76
        classificationBox.setContainerDataSource(taxonNodeContainer);
77
        classificationBox.setValue(presenter.getChosenTaxonNode().getClassification().getRootNode());
78
        classificationBox.addValueChangeListener(new ValueChangeListener() {
79
			private static final long serialVersionUID = -8159622506131474118L;
80

  
81
			@Override
82
			public void valueChange(ValueChangeEvent event) {
83
				TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
84
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
85
			}
86
		});
87
        taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue()));
83
        classificationBox.setContainerDataSource(new TaxonNodeContainer(null));
84
		classificationBox.setImmediate(true);
85
        TaxonNode chosenTaxonNode = presenter.getChosenTaxonNode();
86
		classificationBox.addValueChangeListener(this);
87
        if(chosenTaxonNode!=null){
88
        	classificationBox.setValue(chosenTaxonNode.getClassification().getRootNode());
89
        	taxonTree.setContainerDataSource(new TaxonNodeContainer((TaxonNode) classificationBox.getValue()));
90
        	taxonTree.setValue(chosenTaxonNode);
91
        }
88 92
        taxonTree.setItemCaptionPropertyId(TaxonNodeContainer.LABEL);
89
        taxonTree.setValue(presenter.getChosenTaxonNode());
90 93
        distAreaBox.setContainerDataSource(distributionContainer);
91 94
        distAreaBox.setValue(chosenArea);
92
        boxToggleAbbreviatedLabels.addValueChangeListener(new ValueChangeListener() {
93
			
94
			private static final long serialVersionUID = 5734502056399266546L;
95

  
96
			@Override
97
			public void valueChange(ValueChangeEvent event) {
98
				VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
99
				
100
			}
101
		});
95
        distAreaBox.addValueChangeListener(this);
96
        
97
        if(chosenArea!=null){
98
        	NamedAreaContainer container = new NamedAreaContainer(chosenArea);
99
        	namedAreaList.setContainerDataSource(container);
100
        }
101
        Object selectedAreas = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS);
102
        namedAreaList.setValue(selectedAreas);
103
        
104
        boxToggleAbbreviatedLabels.addValueChangeListener(this);
102 105
        distStatusSelect.setContainerDataSource(presenter.getDistributionStatusContainer());
103 106

  
104
        okButton.addClickListener(new ClickListener() {
105

  
106
			private static final long serialVersionUID = -2554281233796070939L;
107

  
108
			@Override
109
			public void buttonClick(ClickEvent event) {
110
				TaxonNode taxonNode;
111
				TermVocabulary<NamedArea> term = null;
112
				taxonNode = (TaxonNode) taxonTree.getValue();
113
				if(taxonNode==null){
114
					taxonNode = (TaxonNode) classificationBox.getValue();
115
				}
116
				term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
117
				DistributionEditorUtil.openDistributionView(taxonNode, term, new HashSet<NamedArea>());
118
				window.close();
119
			}
120
		});
121
        cancelButton.addClickListener(new ClickListener() {
122

  
123
			private static final long serialVersionUID = -99532405408235383L;
124

  
125
			@Override
126
			public void buttonClick(ClickEvent event) {
127
				window.close();
128
			}
129
		});
107
        okButton.addClickListener(this);
108
        cancelButton.addClickListener(this);
130 109
    }
131 110

  
132 111
    public Window createWindow(){
......
160 139
        classificationBox.setImmediate(true);
161 140
        classificationBox.setWidth("100%");
162 141

  
142
        //distribution area box
163 143
        distAreaBox = new ComboBox("Distribution Area:");
164
        distAreaBox.setImmediate(false);
144
        distAreaBox.setImmediate(true);
165 145
        distAreaBox.setWidth("100%");
166 146

  
147
        // named areas
148
        namedAreaList = new ListSelect();
149
        namedAreaList.setCaption("Areas");
150
        namedAreaList.setWidth("100%");
151
        namedAreaList.setMultiSelect(true);
152

  
167 153
        //distribution status
168 154
        distStatusSelect = new TwinColSelect("Distribution Status:");
169 155
        distStatusSelect.setImmediate(false);
......
176 162
        //taxonomy
177 163
        taxonTree = new Tree("Taxonomy");
178 164
        taxonTree.setImmediate(false);
165
        
166
        //no classification selected label
167
        labelNoClassification = new Label(" - Please select a classification - ");
179 168

  
180 169
        verticalLayout.addComponent(classificationBox);
181 170
        verticalLayout.addComponent(distAreaBox);
171
        verticalLayout.addComponent(namedAreaList);
182 172
        verticalLayout.addComponent(boxToggleAbbreviatedLabels);
183 173
        verticalLayout.addComponent(distStatusSelect);
184 174
        verticalLayout.setExpandRatio(distStatusSelect, 1);
......
187 177
        topContainer.addComponent(verticalLayout);
188 178
        topContainer.addComponent(taxonTree);
189 179
        topContainer.setExpandRatio(taxonTree, 1);
180
        topContainer.addComponent(labelNoClassification);
181
        topContainer.setComponentAlignment(labelNoClassification, Alignment.BOTTOM_RIGHT);
190 182
        topContainer.setExpandRatio(verticalLayout, 1);
191 183

  
192 184
        //button toolbar
......
210 202
        return mainLayout;
211 203
    }
212 204

  
205
	@Override
206
	public void valueChange(ValueChangeEvent event) {
207
		Property property = event.getProperty();
208
		if(property==classificationBox){
209
			TaxonNode parentNode = (TaxonNode) event.getProperty().getValue();
210
			if(parentNode!=null){
211
				taxonTree.setContainerDataSource(new TaxonNodeContainer(parentNode));
212
			}
213
			else{
214
				taxonTree.setContainerDataSource(null);
215
			}
216
			labelNoClassification.setVisible(parentNode==null);
217
		}
218

  
219
		else if(property==distAreaBox){
220
			TermVocabulary<NamedArea> vocabulary = (TermVocabulary<NamedArea>) event.getProperty().getValue();
221
			NamedAreaContainer container = new NamedAreaContainer(vocabulary);
222
			namedAreaList.setContainerDataSource(container);
223
		}
224
		else if(property==boxToggleAbbreviatedLabels){
225
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS, event.getProperty().getValue());
226
		}
227
	}
228

  
229
	@Override
230
	public void buttonClick(ClickEvent event) {
231
		Object source = event.getSource();
232
		if(source==okButton){
233
			TaxonNode taxonNode;
234
			TermVocabulary<NamedArea> term = null;
235
			taxonNode = (TaxonNode) taxonTree.getValue();
236
			if(taxonNode==null){
237
				taxonNode = (TaxonNode) classificationBox.getValue();
238
			}
239
			term = (TermVocabulary<NamedArea>) distAreaBox.getValue();
240
			Set<NamedArea> selectedAreas = (Set<NamedArea>) namedAreaList.getValue();
241
			if(taxonNode==null){
242
				Notification.show("Please choose a classification and/or taxon", Notification.Type.HUMANIZED_MESSAGE);
243
				return;
244
			}
245
			if(term==null){
246
				Notification.show("Please choose a distribution area", Notification.Type.HUMANIZED_MESSAGE);
247
				return;
248
			}
249
			DistributionEditorUtil.openDistributionView(taxonNode, term, selectedAreas);
250
			window.close();
251
		}
252
		else if(source==cancelButton){
253
			window.close();
254
		}
255
	}
256

  
213 257
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)