Project

General

Profile

« Previous | Next » 

Revision 218fbd04

Added by Cherian Mathew about 9 years ago

CdmProgressComponent : Component which indicates progress via text and a progress bar
NewTaxonBaseComposite, StatusComposite : Added taxon name field for synonym creation and using new operation and progress component objects
StatusComposite : Corrections
CdmSQLContainer, LeafNodeTaxonContainer : Moved non-generic methods from CdmSQLContainer to LeafNodeTaxonContainer
StatusPresenter, IStatusComposite : added id filter methods as well as methods to remove all dynamic filters and to refresh the synonym cache
SelectionService : using UI.access to update ui
CdmQueryFactory : removed rank inner join for taxon base query
CdmVaadinOperation : Class which handles async and sync operations
CdmVaadinUtilities : Added methods to run new CdmVaadinOperation objects and to recursively enable / disable components

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/NewTaxonBaseComposite.java
1 1
// $Id$
2 2
/**
3
* Copyright (C) 2015 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
3
 * Copyright (C) 2015 EDIT
4
 * European Distributed Institute of Taxonomy
5
 * http://www.e-taxonomy.eu
6
 *
7
 * The contents of this file are subject to the Mozilla Public License Version 1.1
8
 * See LICENSE.TXT at the top of this package for the full license terms.
9
 */
10 10
package eu.etaxonomy.cdm.vaadin.component;
11 11

  
12 12
import java.util.Arrays;
13 13

  
14
import org.apache.log4j.Logger;
15

  
14 16
import com.vaadin.annotations.AutoGenerated;
15 17
import com.vaadin.data.Validator.EmptyValueException;
16 18
import com.vaadin.data.util.sqlcontainer.RowId;
......
21 23
import com.vaadin.ui.ComboBox;
22 24
import com.vaadin.ui.CustomComponent;
23 25
import com.vaadin.ui.GridLayout;
26
import com.vaadin.ui.HorizontalLayout;
24 27
import com.vaadin.ui.Label;
25 28
import com.vaadin.ui.Notification;
26 29
import com.vaadin.ui.Notification.Type;
27 30
import com.vaadin.ui.TextField;
28 31
import com.vaadin.ui.UI;
32
import com.vaadin.ui.VerticalLayout;
29 33
import com.vaadin.ui.Window;
30 34

  
31 35
import eu.etaxonomy.cdm.vaadin.container.IdAndUuid;
32 36
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
33 37
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent.Action;
34
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
38
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
39
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
35 40
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComponentListener;
36 41
import eu.etaxonomy.cdm.vaadin.view.INewTaxonBaseComposite;
37 42

  
......
45 50
    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
46 51

  
47 52
    @AutoGenerated
48
    private GridLayout mainLayout;
53
    private VerticalLayout mainLayout;
54
    @AutoGenerated
55
    private CdmProgressComponent cdmProgressComponent;
56
    @AutoGenerated
57
    private HorizontalLayout horizontalLayout;
49 58
    @AutoGenerated
50 59
    private Button cancelButton;
51 60
    @AutoGenerated
52 61
    private Button saveButton;
53 62
    @AutoGenerated
63
    private GridLayout gridLayout;
64
    @AutoGenerated
65
    private Label accTaxonNameValue;
66
    @AutoGenerated
54 67
    private ComboBox secComboBox;
55 68
    @AutoGenerated
56 69
    private Label secLabel;
......
58 71
    private TextField nameTextField;
59 72
    @AutoGenerated
60 73
    private Label nameLabel;
74
    @AutoGenerated
75
    private Label accTaxonLabel;
61 76
    private INewTaxonBaseComponentListener listener;
62 77

  
63 78

  
......
65 80
    private final IdAndUuid accTaxonIdUuid;
66 81
    private final IdAndUuid classificationIdUuid;
67 82

  
83
    private static final Logger logger = Logger.getLogger(NewTaxonBaseComposite.class);
84

  
68 85
    /**
69 86
     * The constructor should first build the main layout, set the
70 87
     * composition root and then do any custom initialization.
......
75 92
    public NewTaxonBaseComposite(Window dialog,
76 93
            INewTaxonBaseComponentListener listener,
77 94
            IdAndUuid accTaxonIdUuid,
95
            String accTaxonName,
78 96
            IdAndUuid classificationIdUuid) {
79 97
        buildMainLayout();
80 98
        setCompositionRoot(mainLayout);
......
86 104

  
87 105
        addUIListeners();
88 106

  
107
        if(accTaxonName == null || accTaxonName.isEmpty()) {
108
            accTaxonLabel.setVisible(false);
109
            accTaxonNameValue.setVisible(false);
110
        } else {
111
            accTaxonNameValue.setValue(accTaxonName);
112
        }
89 113
        init();
90 114
    }
91 115

  
92 116
    public void init() {
93
        initNameTextField();
117

  
94 118
        initSecComboBox();
95
    }
96 119

  
97
    private void initNameTextField() {
98
        //nameTextField.addValidator(new StringLengthValidator("Name cannot be empty", 1,100, false));
99 120
    }
100 121

  
122

  
101 123
    private void initSecComboBox() {
102 124

  
103 125
        secComboBox.setNullSelectionAllowed(false);
......
118 140

  
119 141
            @Override
120 142
            public void buttonClick(ClickEvent event) {
143

  
144

  
121 145
                try {
122 146
                    nameTextField.validate();
123 147
                    secComboBox.validate();
124

  
125
                    IdAndUuid taxonIdUuid;
126
                    if(accTaxonIdUuid == null) {
127
                        taxonIdUuid = listener.newTaxon(nameTextField.getValue(),secComboBox.getValue(), classificationIdUuid.getUuid());
128
                    } else {
129
                        listener.newSynonym(nameTextField.getValue(),secComboBox.getValue(), accTaxonIdUuid.getUuid());
130
                        taxonIdUuid = accTaxonIdUuid;
131
                    }
132
                    Object rowId = new RowId(taxonIdUuid.getId());
133
                    CdmVaadinSessionUtilities.getCurrentCdmDataChangeService()
134
                        .fireChangeEvent(new CdmChangeEvent(Action.Create, Arrays.asList(rowId), NewTaxonBaseComposite.class), true);
135
                    UI.getCurrent().removeWindow(dialog);
136 148
                } catch (EmptyValueException e) {
137 149
                    Notification notification = new Notification("Invalid input", "Neither Name or Secundum can be empty", Type.WARNING_MESSAGE);
138 150
                    notification.setDelayMsec(2000);
139 151
                    notification.show(Page.getCurrent());
152
                    return;
140 153
                }
141
            }
142 154

  
155
                CdmVaadinUtilities.setEnabled(mainLayout, false, null);
156

  
157
                CdmVaadinUtilities.exec(new CdmVaadinOperation(1000, cdmProgressComponent) {
158
                    @Override
159
                    public boolean execute() {
160
                        setProgress("Saving Taxon " + nameTextField.getValue());
161
                        IdAndUuid taxonBaseIdUuid;
162
                        if(accTaxonIdUuid == null) {
163
                            taxonBaseIdUuid = listener.newTaxon(nameTextField.getValue(),secComboBox.getValue(), classificationIdUuid.getUuid());
164
                        } else {
165
                            taxonBaseIdUuid = listener.newSynonym(nameTextField.getValue(),secComboBox.getValue(), accTaxonIdUuid.getUuid());
166
                        }
167

  
168
                        Object rowId = new RowId(taxonBaseIdUuid.getId());
169
                        fireEvent(new CdmChangeEvent(Action.Create, Arrays.asList(rowId), NewTaxonBaseComposite.class));
170

  
171
                        return true;
172
                    }
173

  
174
                    @Override
175
                    public void postOpUIUpdate(boolean success) {
176
                        if(success) {
177
                            UI.getCurrent().removeWindow(dialog);
178
                        } else {
179
                            CdmVaadinUtilities.setEnabled(mainLayout, true, null);
180
                        }
181
                    }
182
                });
183
            }
143 184
        });
144 185
    }
145 186

  
......
148 189

  
149 190
            @Override
150 191
            public void buttonClick(ClickEvent event) {
151
               UI.getCurrent().removeWindow(dialog);
192
                UI.getCurrent().removeWindow(dialog);
152 193
            }
153 194

  
154 195
        });
......
164 205
    }
165 206

  
166 207
    @AutoGenerated
167
    private GridLayout buildMainLayout() {
208
    private VerticalLayout buildMainLayout() {
168 209
        // common part: create layout
169
        mainLayout = new GridLayout();
210
        mainLayout = new VerticalLayout();
170 211
        mainLayout.setImmediate(false);
171
        mainLayout.setWidth("320px");
172
        mainLayout.setHeight("120px");
212
        mainLayout.setWidth("340px");
213
        mainLayout.setHeight("200px");
173 214
        mainLayout.setMargin(true);
174
        mainLayout.setSpacing(true);
175
        mainLayout.setColumns(2);
176
        mainLayout.setRows(3);
177 215

  
178 216
        // top-level component properties
179
        setWidth("320px");
180
        setHeight("120px");
217
        setWidth("340px");
218
        setHeight("200px");
219

  
220
        // gridLayout
221
        gridLayout = buildGridLayout();
222
        mainLayout.addComponent(gridLayout);
223
        mainLayout.setExpandRatio(gridLayout, 1.0f);
224

  
225
        // horizontalLayout
226
        horizontalLayout = buildHorizontalLayout();
227
        mainLayout.addComponent(horizontalLayout);
228
        mainLayout.setComponentAlignment(horizontalLayout, new Alignment(20));
229

  
230
        // cdmProgressComponent
231
        cdmProgressComponent = new CdmProgressComponent();
232
        cdmProgressComponent.setImmediate(false);
233
        cdmProgressComponent.setWidth("-1px");
234
        cdmProgressComponent.setHeight("-1px");
235
        mainLayout.addComponent(cdmProgressComponent);
236
        mainLayout.setComponentAlignment(cdmProgressComponent, new Alignment(48));
237

  
238
        return mainLayout;
239
    }
240

  
241
    @AutoGenerated
242
    private GridLayout buildGridLayout() {
243
        // common part: create layout
244
        gridLayout = new GridLayout();
245
        gridLayout.setImmediate(false);
246
        gridLayout.setWidth("-1px");
247
        gridLayout.setHeight("-1px");
248
        gridLayout.setMargin(false);
249
        gridLayout.setSpacing(true);
250
        gridLayout.setColumns(2);
251
        gridLayout.setRows(4);
252

  
253
        // accTaxonLabel
254
        accTaxonLabel = new Label();
255
        accTaxonLabel.setImmediate(false);
256
        accTaxonLabel.setWidth("-1px");
257
        accTaxonLabel.setHeight("-1px");
258
        accTaxonLabel.setValue("Acc. Taxon : ");
259
        gridLayout.addComponent(accTaxonLabel, 0, 0);
260
        gridLayout.setComponentAlignment(accTaxonLabel, new Alignment(34));
181 261

  
182 262
        // nameLabel
183 263
        nameLabel = new Label();
......
185 265
        nameLabel.setWidth("-1px");
186 266
        nameLabel.setHeight("-1px");
187 267
        nameLabel.setValue("Name : ");
188
        mainLayout.addComponent(nameLabel, 0, 0);
189
        mainLayout.setComponentAlignment(nameLabel, new Alignment(34));
268
        gridLayout.addComponent(nameLabel, 0, 1);
269
        gridLayout.setComponentAlignment(nameLabel, new Alignment(34));
190 270

  
191 271
        // nameTextField
192 272
        nameTextField = new TextField();
......
195 275
        nameTextField.setHeight("-1px");
196 276
        nameTextField.setInvalidAllowed(false);
197 277
        nameTextField.setRequired(true);
198
        mainLayout.addComponent(nameTextField, 1, 0);
199
        mainLayout.setComponentAlignment(nameTextField, new Alignment(33));
278
        gridLayout.addComponent(nameTextField, 1, 1);
279
        gridLayout.setComponentAlignment(nameTextField, new Alignment(33));
200 280

  
201 281
        // secLabel
202 282
        secLabel = new Label();
......
204 284
        secLabel.setWidth("-1px");
205 285
        secLabel.setHeight("-1px");
206 286
        secLabel.setValue("Secundum : ");
207
        mainLayout.addComponent(secLabel, 0, 1);
208
        mainLayout.setComponentAlignment(secLabel, new Alignment(34));
287
        gridLayout.addComponent(secLabel, 0, 2);
288
        gridLayout.setComponentAlignment(secLabel, new Alignment(34));
209 289

  
210 290
        // secComboBox
211 291
        secComboBox = new ComboBox();
......
214 294
        secComboBox.setHeight("-1px");
215 295
        secComboBox.setInvalidAllowed(false);
216 296
        secComboBox.setRequired(true);
217
        mainLayout.addComponent(secComboBox, 1, 1);
218
        mainLayout.setComponentAlignment(secComboBox, new Alignment(33));
297
        gridLayout.addComponent(secComboBox, 1, 2);
298
        gridLayout.setComponentAlignment(secComboBox, new Alignment(33));
299

  
300
        // accTaxonNameValue
301
        accTaxonNameValue = new Label();
302
        accTaxonNameValue.setImmediate(false);
303
        accTaxonNameValue.setWidth("-1px");
304
        accTaxonNameValue.setHeight("-1px");
305
        accTaxonNameValue.setValue("Taxon Name");
306
        gridLayout.addComponent(accTaxonNameValue, 1, 0);
307
        gridLayout.setComponentAlignment(accTaxonNameValue, new Alignment(33));
308

  
309
        return gridLayout;
310
    }
311

  
312
    @AutoGenerated
313
    private HorizontalLayout buildHorizontalLayout() {
314
        // common part: create layout
315
        horizontalLayout = new HorizontalLayout();
316
        horizontalLayout.setImmediate(false);
317
        horizontalLayout.setWidth("-1px");
318
        horizontalLayout.setHeight("-1px");
319
        horizontalLayout.setMargin(false);
320
        horizontalLayout.setSpacing(true);
219 321

  
220 322
        // saveButton
221 323
        saveButton = new Button();
......
223 325
        saveButton.setImmediate(true);
224 326
        saveButton.setWidth("-1px");
225 327
        saveButton.setHeight("-1px");
226
        mainLayout.addComponent(saveButton, 0, 2);
227
        mainLayout.setComponentAlignment(saveButton, new Alignment(34));
328
        horizontalLayout.addComponent(saveButton);
329
        horizontalLayout.setComponentAlignment(saveButton, new Alignment(20));
228 330

  
229 331
        // cancelButton
230 332
        cancelButton = new Button();
......
232 334
        cancelButton.setImmediate(true);
233 335
        cancelButton.setWidth("-1px");
234 336
        cancelButton.setHeight("-1px");
235
        mainLayout.addComponent(cancelButton, 1, 2);
236
        mainLayout.setComponentAlignment(cancelButton, new Alignment(33));
337
        horizontalLayout.addComponent(cancelButton);
338
        horizontalLayout.setComponentAlignment(cancelButton, new Alignment(20));
237 339

  
238
        return mainLayout;
340
        return horizontalLayout;
239 341
    }
240 342

  
241 343

  

Also available in: Unified diff