Project

General

Profile

Revision fc53e2e8

IDfc53e2e89bebb9299a21071162e34661da28ca21
Parent ff1f0352
Child 450785be

Added by Andreas Müller almost 3 years ago

ref #6903 preload status from preferences in dialog

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.Arrays;
3 4
import java.util.Collection;
4 5
import java.util.HashSet;
6
import java.util.List;
5 7
import java.util.Set;
8
import java.util.UUID;
6 9

  
7 10
import com.vaadin.data.util.BeanItemContainer;
8 11
import com.vaadin.server.VaadinSession;
9 12

  
10 13
import eu.etaxonomy.cdm.model.common.TermType;
11 14
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
15
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
16
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
12 17
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
13 18
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
14 19
import eu.etaxonomy.cdm.vaadin.util.TermCacher;
......
28 33
	}
29 34

  
30 35
    private void initDataModel() {
31
        Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
32
        distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
36
        Collection<PresenceAbsenceTerm> distributionStatus = getDistributionStatusList(TERMS_INIT_STRATEGY);
37

  
33 38
        defaultDistributionStatus = distributionStatus;
34 39
		TermCacher termCacher = TermCacher.getInstance();
35 40
		addAll(distributionStatus);
......
39 44
    }
40 45

  
41 46
	public static PresenceAbsenceTermContainer getInstance(){
42
	    if(instance==null){
47
	    if(instance == null){
43 48
	        instance = new PresenceAbsenceTermContainer();
44 49
	    }
45 50
        Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
46 51
        Object attribute = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
47
        if(attribute!=null){
52
        if(attribute != null){
48 53
            distributionStatus = (Set<PresenceAbsenceTerm>) attribute;
49 54
        }
50 55
        if(!distributionStatus.isEmpty() && !distributionStatus.equals(defaultDistributionStatus)){
......
55 60
	    return instance;
56 61
	}
57 62

  
63
    public static List<PresenceAbsenceTerm> getDistributionStatusList(List<String> propertyPath){
64
        CdmPreference statusPref = CdmSpringContextHelper.getPreferenceService().findVaadin(PreferencePredicate.AvailableDistributionStatus);
65
        if (statusPref != null){
66
            List<UUID> uuidList = statusPref.getValueUuidList();
67
            return (List)CdmSpringContextHelper.getTermService().load(uuidList, propertyPath);
68
        }else{
69
            return CdmSpringContextHelper.getTermService().listByTermType(
70
                    TermType.PresenceAbsenceTerm, null, null, null, propertyPath);
71
        }
72
    }
73

  
74
    protected static final List<String> TERMS_INIT_STRATEGY = Arrays.asList(new String []{
75
            "$",
76
            "representations",
77
    });
78

  
58 79
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTablePresenter.java
305 305
//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_SELECTED_AREAS, selectedAreas);
306 306
//        VaadinSession.getCurrent().setAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION, classificationUuid);
307 307
	    if(userHelper.userIsAutheticated() && !userHelper.userIsAnnonymous()) {
308
            getView().openDistributionSettings();
308
            getView().openAreaAndTaxonSettings();
309 309
        }
310 310
    }
311 311
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/DistributionTableViewBean.java
34 34
import com.vaadin.ui.Window;
35 35

  
36 36
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
37
import eu.etaxonomy.cdm.model.common.CdmBase;
37 38
import eu.etaxonomy.cdm.model.common.Language;
38 39
import eu.etaxonomy.cdm.model.common.Representation;
39 40
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
......
100 101
				if(value instanceof String){
101 102
					presenceAbsenceTerm = TermCacher.getInstance().getPresenceAbsenceTerm((String) value);
102 103
				}
103
				if(presenceAbsenceTerm!=null){
104
				if(presenceAbsenceTerm != null){
104 105
					Representation representation = presenceAbsenceTerm.getRepresentation(Language.DEFAULT());
105 106
					if(representation!=null){
106 107
						if(DistributionEditorUtil.isAbbreviatedLabels()){
......
137 138
                final Item item = event.getItem();
138 139
                Property<?> itemProperty = item.getItemProperty("uuid");
139 140
                UUID uuid = UUID.fromString(itemProperty.getValue().toString());
140
                final Taxon taxon = HibernateProxyHelper.deproxy(CdmSpringContextHelper.getTaxonService()
141
                final Taxon taxon = CdmBase.deproxy(CdmSpringContextHelper.getTaxonService()
141 142
                		.load(uuid,Arrays.asList("descriptions.descriptionElements","name.taxonBases","updatedBy")), Taxon.class);
142
                final String areaID = (String) event.getPropertyId();
143
                final String areaID = (String)event.getPropertyId();
143 144
                PresenceAbsenceTerm presenceAbsenceTerm = null;
144 145
                Object statusValue = item.getItemProperty(areaID).getValue();
145 146
                if(statusValue instanceof String){
......
150 151
                final ListSelect termSelect = new ListSelect();
151 152
                termSelect.setSizeFull();
152 153
                termSelect.setContainerDataSource(PresenceAbsenceTermContainer.getInstance());
153
                termSelect.setNullSelectionAllowed(presenceAbsenceTerm!=null);
154
                if(presenceAbsenceTerm!=null){
154
                termSelect.setNullSelectionAllowed(presenceAbsenceTerm != null);
155
                if(presenceAbsenceTerm != null){
155 156
                	termSelect.setNullSelectionItemId("[no status]");
157
                }else{
158
                    logger.debug("No distribution status exists yet for area");
156 159
                }
157 160
                termSelect.setValue(presenceAbsenceTerm);
158 161
                termSelect.addValueChangeListener(valueChangeEvent -> {
159
						System.out.println(valueChangeEvent);
162
//						System.out.println(valueChangeEvent);
160 163
						Object distributionStatus = valueChangeEvent.getProperty().getValue();
161 164
						getPresenter().updateDistributionField(areaID, distributionStatus, taxon);
162 165
						container.refresh();
......
216 219
	}
217 220

  
218 221
	private void createEditClickListener(){
219
		Button detailButton = toolbar.getDetailButton();
220
		detailButton.setCaption("Detail View");
222
		//details
223
	    Button detailButton = toolbar.getDetailButton();
224
		detailButton.setCaption("Taxon Details");
221 225
		detailButton.addClickListener(event -> {
222 226
				Object selectedItemId = DistributionTableViewBean.this.table.getValue();
223 227
//				Object selectedItemId = DistributionTableViewBean.this.grid.getSelectedRow();
......
237 241
			}
238 242
		);
239 243

  
240
		Button distributionSettingsButton = toolbar.getDistributionSettingsButton();
241
		distributionSettingsButton.addClickListener(event -> openDistributionSettings());
244
		//area and taxon
245
		Button areaAndTaxonSettingsButton = toolbar.getDistributionSettingsButton();
246
		areaAndTaxonSettingsButton.addClickListener(event -> openAreaAndTaxonSettings());
242 247

  
243
		Button settingsButton = toolbar.getSettingsButton();
244
		settingsButton.addClickListener(event -> openSettings());
248
		//distr status
249
		Button distrStatusButton = toolbar.getSettingsButton();
250
		distrStatusButton.addClickListener(event -> openStatusSettings());
245 251
	}
246 252

  
247 253
    /**
248 254
     * {@inheritDoc}
249 255
     */
250 256
	@Override
251
	public void openSettings() {
257
	public void openStatusSettings() {
252 258
		DistributionStatusSettingsConfigWindow cw = new DistributionStatusSettingsConfigWindow(this);
253 259
		Window window  = cw.createWindow("Status");
254 260
		UI.getCurrent().addWindow(window);
......
258 264
     * {@inheritDoc}
259 265
     */
260 266
	@Override
261
	public void openDistributionSettings() {
267
	public void openAreaAndTaxonSettings() {
262 268
		if(distributionSettingConfigWindow==null){
263 269
			distributionSettingConfigWindow = new AreaAndTaxonSettingsConfigWindow(this);
264 270
		}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/IDistributionTableView.java
25 25
	public void update();
26 26

  
27 27
	/**
28
	 * Opens the setting window to change available distribution status.
28
	 * Opens the status setting window to change available distribution status.
29 29
	 */
30
	public void openSettings();
30
	public void openStatusSettings();
31 31

  
32 32
	/**
33
	 * Opens the distribution-setting window to change available areas and chose classification.
33
	 * Opens the area and taxon setting window to change available areas and chose classification.
34 34
	 */
35
	public void openDistributionSettings();
35
	public void openAreaAndTaxonSettings();
36 36

  
37 37
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/distributionStatus/settings/DistributionStatusSettingsPresenter.java
10 10

  
11 11
import java.util.Arrays;
12 12
import java.util.List;
13
import java.util.UUID;
14 13

  
15 14
import com.vaadin.data.Container;
16 15
import com.vaadin.data.util.IndexedContainer;
17 16

  
18
import eu.etaxonomy.cdm.model.common.TermType;
19 17
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm;
20
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
21
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
22
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
18
import eu.etaxonomy.cdm.vaadin.container.PresenceAbsenceTermContainer;
23 19

  
24 20
/**
25 21
 * @author a.mueller
......
39 35
    }
40 36

  
41 37
    private List<PresenceAbsenceTerm> getDistributionStatusList(){
42
        CdmPreference statusPref = CdmSpringContextHelper.getPreferenceService().findVaadin(PreferencePredicate.AvailableDistributionStatus);
43
        if (statusPref != null){
44
            List<UUID> uuidList = statusPref.getValueUuidList();
45
            return (List)CdmSpringContextHelper.getTermService().load(uuidList, TERMS_INIT_STRATEGY);
46
        }else{
47
            return CdmSpringContextHelper.getTermService().listByTermType(
48
                    TermType.PresenceAbsenceTerm, null, null, null, TERMS_INIT_STRATEGY);
49
        }
38
        return PresenceAbsenceTermContainer.getDistributionStatusList(TERMS_INIT_STRATEGY);
50 39
    }
51 40

  
52 41

  

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)