Project

General

Profile

Revision 32bf574c

ID32bf574c75f7cb4ab0e56b84e7578d0ab8971085
Parent bd46f97b
Child e11ccba6

Added by Patrick Plitzner about 5 years ago

ref #5458 Add support for setting distribution status filter in settings

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/container/PresenceAbsenceTermContainer.java
1 1
package eu.etaxonomy.cdm.vaadin.container;
2 2

  
3
import java.util.List;
3
import java.util.Collection;
4
import java.util.Set;
4 5

  
5 6
import com.vaadin.data.util.BeanItemContainer;
7
import com.vaadin.server.VaadinSession;
6 8

  
7 9
import eu.etaxonomy.cdm.model.common.TermType;
8 10
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
9 11
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
12
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
10 13
import eu.etaxonomy.cdm.vaadin.util.TermCacher;
11 14

  
12 15
public class PresenceAbsenceTermContainer extends BeanItemContainer<PresenceAbsenceTerm> {
13 16

  
14 17
	private static final long serialVersionUID = -7891310979870159325L;
15 18

  
16
	private static PresenceAbsenceTermContainer instance;
17

  
18
	private PresenceAbsenceTermContainer()
19
	public PresenceAbsenceTermContainer()
19 20
			throws IllegalArgumentException {
20 21
		super(PresenceAbsenceTerm.class);
21
		List<PresenceAbsenceTerm> terms = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
22
		Collection<PresenceAbsenceTerm> distributionStatus = (Set<PresenceAbsenceTerm>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
23
        if(distributionStatus==null || distributionStatus.isEmpty()){
24
            distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
25
        }
22 26
		TermCacher termCacher = TermCacher.getInstance();
23
		for (PresenceAbsenceTerm presenceAbsenceTerm : terms) {
27
		for (PresenceAbsenceTerm presenceAbsenceTerm : distributionStatus) {
24 28
			termCacher.addPresenceAbsenceTerm(presenceAbsenceTerm);
25 29
			addBean(presenceAbsenceTerm);
26 30
		}
27 31
	}
28 32

  
29
	public static PresenceAbsenceTermContainer getInstance(){
30
		if(instance==null){
31
			instance = new PresenceAbsenceTermContainer();
32
		}
33
		return instance;
34
	}
35

  
36

  
37 33
}
src/main/java/eu/etaxonomy/cdm/vaadin/util/DistributionEditorUtil.java
21 21

  
22 22
    public static final String SATTR_ABBREVIATED_LABELS = "abbreviatedLabels";
23 23

  
24
    public static final String SATTR_DISTRIBUTION_STATUS = "distributionStatus";
25

  
24 26
    public static final String SEPARATOR = ";;";
25 27

  
26 28
    public static void openDistributionView(TaxonNode taxonNode, TermVocabulary<NamedArea> term, Set<NamedArea> selectedAreas) {
......
31 33
	    //navigate to table view
32 34
	    UI.getCurrent().getNavigator().navigateTo(VIEW_TABLE);
33 35
	}
34
    
36

  
35 37
    public static boolean isAbbreviatedLabels(){
36 38
    	Object isAbbreviated = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_ABBREVIATED_LABELS);
37 39
		return (isAbbreviated==null || (boolean) isAbbreviated);
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/DistributionTableView.java
51 51

  
52 52
	private List<String> columnList;
53 53
	private ArrayList<String> headerList;
54
    private CdmSQLContainer container;
54 55

  
55 56
	/**
56 57
	 * The constructor should first build the main layout, set the
......
84 85
		table.setImmediate(false);
85 86
		table.setWidth("100.0%");
86 87
		table.setHeight("100.0%");
88

  
89
        table.setColumnReorderingAllowed(true);
90
        table.setSortEnabled(true);
91

  
92
        table.setColumnCollapsingAllowed(true);
93
        table.setSelectable(true);
94
        table.setPageLength(20);
95
        table.setFooterVisible(true);
96
        table.setCacheRate(20);
97

  
98
		table.addItemClickListener(new ItemClickListener() {
99
            private static final long serialVersionUID = 2743935539139014771L;
100
            @Override
101
            public void itemClick(ItemClickEvent event) {
102
                if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){
103
                    final Item item = event.getItem();
104
                    Property<?> itemProperty = item.getItemProperty("uuid");
105
                    UUID uuid = UUID.fromString(itemProperty.getValue().toString());
106
                    final Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
107
                    final String areaID = (String) event.getPropertyId();
108

  
109
                    //popup window
110
                    final Window popup = new Window("Choose distribution status");
111
                    final ListSelect termSelect = new ListSelect();
112
                    termSelect.setSizeFull();
113
                    termSelect.setContainerDataSource(new PresenceAbsenceTermContainer());
114
                    Button btnOk = new Button("OK", new ClickListener() {
115
                        private static final long serialVersionUID = -3732219609337335697L;
116
                        @Override
117
                        public void buttonClick(ClickEvent event) {
118
                            Object distributionStatus = termSelect.getValue();
119
                            listener.updateDistributionField(areaID, distributionStatus, taxon);
120
                            container.refresh();
121
                            popup.close();
122
                        }
123
                    });
124
                    VerticalLayout layout = new VerticalLayout(termSelect, btnOk);
125
                    layout.setComponentAlignment(btnOk, Alignment.BOTTOM_RIGHT);
126
                    popup.setContent(layout);
127
                    popup.setModal(true);
128
                    popup.center();
129
                    UI.getCurrent().addWindow(popup);
130
                }
131
            }
132
        });
133

  
134

  
87 135
		mainLayout.addComponent(table, "top:75px;right:0.0px;");
88 136
		return mainLayout;
89 137
	}
......
94 142

  
95 143
	@Override
96 144
	public void enter(ViewChangeEvent event) {
97
		final CdmSQLContainer container;
98 145
		try {
99 146
			container = listener.getSQLContainer();
100 147
		} catch (SQLException e) {
......
107 154
		}
108 155

  
109 156
		table.setContainerDataSource(container);
110
		table.setColumnReorderingAllowed(true);
111
		table.setSortEnabled(true);
112 157

  
113 158
		columnList = new ArrayList<String>(Arrays.asList(new String[]{CdmQueryFactory.TAXON_COLUMN,CdmQueryFactory.RANK_COLUMN}));
114 159
		List<String> namedAreas = listener.getNamedAreasLabels();
......
120 165
		String[] string = new String[headerList.size()];
121 166
		table.setColumnHeaders(headerList.toArray(string));
122 167

  
123
//		table.setColumnExpandRatio(propertyId, expandRatio);
124
		table.setColumnCollapsingAllowed(true);
125
		table.setSelectable(true);
126
		table.setPageLength(20);
127
		table.setFooterVisible(true);
128 168
		table.setColumnFooter(CdmQueryFactory.TAXON_COLUMN, "Total amount of Taxa displayed: " + container.size());
129
		table.setCacheRate(20);
130
		
131
		table.addItemClickListener(new ItemClickListener() {
132
			private static final long serialVersionUID = 2743935539139014771L;
133
			@Override
134
			public void itemClick(ItemClickEvent event) {
135
				if(!(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.TAXON_COLUMN)) && !(event.getPropertyId().toString().equalsIgnoreCase(CdmQueryFactory.RANK_COLUMN))){
136
					final Item item = event.getItem();
137
					Property<?> itemProperty = item.getItemProperty("uuid");
138
					UUID uuid = UUID.fromString(itemProperty.getValue().toString());
139
					final Taxon taxon = HibernateProxyHelper.deproxy(listener.getTaxonService().load(uuid), Taxon.class);
140
					final String areaID = (String) event.getPropertyId();
141

  
142
					//popup window
143
					final Window popup = new Window("Choose distribution status");
144
					final ListSelect termSelect = new ListSelect();
145
					termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance());
146
					Button btnOk = new Button("OK", new ClickListener() {
147
						private static final long serialVersionUID = -3732219609337335697L;
148
						@Override
149
						public void buttonClick(ClickEvent event) {
150
							Object distributionStatus = termSelect.getValue();
151
							listener.updateDistributionField(areaID, distributionStatus, taxon);
152
							container.refresh();
153
							popup.close();
154
						}
155
					});
156
					VerticalLayout layout = new VerticalLayout(termSelect, btnOk);
157
					layout.setComponentAlignment(btnOk, Alignment.BOTTOM_RIGHT);
158
					popup.setContent(layout);
159
					popup.setModal(true);
160
					popup.center();
161
					UI.getCurrent().addWindow(popup);
162
				}
163
			}
164
		});
169

  
170

  
165 171
	}
166 172

  
167 173
	private void createEditClickListener(){
......
202 208

  
203 209
		Button settingsButton = toolbar.getSettingsButton();
204 210
		settingsButton.addClickListener(new ClickListener() {
205
			
211

  
206 212
			private static final long serialVersionUID = -147703680580181544L;
207 213

  
208 214
			@Override
......
230 236
		});
231 237

  
232 238
	}
233
	
239

  
234 240
	public void openSettings() {
235 241
		SettingsConfigWindow cw = new SettingsConfigWindow(this);
236 242
		Window window  = cw.createWindow();
src/main/java/eu/etaxonomy/cdm/vaadin/view/dbstatus/SettingsConfigWindow.java
133 133
	public void buttonClick(ClickEvent event) {
134 134
		Object source = event.getSource();
135 135
		if(source==okButton){
136
			VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS, distStatusSelect.getValue());
136 137
			distributionTableView.enter(null);
137 138
			window.close();
138 139
		}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)