Project

General

Profile

« Previous | Next » 

Revision 98b72f8e

Added by Cherian Mathew over 8 years ago

ConceptRelationshipComposite : added methods to update controls
EditConceptRelationshipComposite : added bi-directional capability

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/ConceptRelationshipComposite.java
28 28
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
29 29
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree.Direction;
30 30
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter;
31
import eu.etaxonomy.cdm.vaadin.session.BasicEvent;
31 32
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
32 33
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent.Action;
34
import eu.etaxonomy.cdm.vaadin.session.IBasicEventListener;
33 35
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
34 36
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener;
35 37
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
......
42 44
 * @date 9 Apr 2015
43 45
 *
44 46
 */
45
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener {
47
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener, IBasicEventListener {
46 48

  
47 49
    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */
48 50

  
......
86 88

  
87 89
        CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
88 90
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
91
        CdmVaadinSessionUtilities.getCurrentBasicEventService().register(this);
89 92
        listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
90 93

  
91 94
        addUIListeners();
......
97 100
    }
98 101

  
99 102
    private void init() {
100
        editButton.setEnabled(false);
101
        deleteButton.setEnabled(false);
103
        enableControls(false);
102 104
        initD3ConceptRelationShipTree();
103 105
    }
104 106

  
......
169 171

  
170 172
    public void setSelectedTaxonRelUuid(UUID selectedTaxonRelUuid) {
171 173
        this.selectedTaxonRelUuid = selectedTaxonRelUuid;
172
        if(selectedTaxonRelUuid == null) {
173
            editButton.setEnabled(false);
174
            deleteButton.setEnabled(false);
175
        } else {
174
        updateControls();
175
    }
176

  
177
    private void enableControls(boolean enabled) {
178
        newButton.setEnabled(enabled);
179
        editButton.setEnabled(enabled);
180
        deleteButton.setEnabled(enabled);
181
    }
182

  
183
    private void updateControls() {
184
        enableControls(false);
185
        if(fromTaxonIun != null) {
186
            newButton.setEnabled(true);
187
        }
188
        if(selectedTaxonRelUuid != null) {
176 189
            editButton.setEnabled(true);
177 190
            deleteButton.setEnabled(true);
178 191
        }
......
187 200
            fromTaxonIun = (IdUuidName)event.getSelectedObjects().get(0);
188 201
            view.setPrimaryStatusCompositeUuid((UUID)event.getSelectedObjects().get(1));
189 202
            refreshRelationshipView(view.getDirection());
203
            updateControls();
190 204
        }
191 205
    }
192 206

  
......
215 229
            setSelectedTaxonRelUuid(null);
216 230
            refreshRelationshipView(view.getDirection());
217 231
        }
218

  
219 232
    }
220 233

  
221 234

  
......
230 243
        }
231 244

  
232 245
    }
246

  
247

  
248
    /* (non-Javadoc)
249
     * @see eu.etaxonomy.cdm.vaadin.session.IBasicEventListener#onAction(eu.etaxonomy.cdm.vaadin.session.BasicEvent)
250
     */
251
    @Override
252
    public void onAction(BasicEvent event) {
253
        if(ConceptRelationshipComposite.UPDATE_START_ID.equals(event.getEventId())) {
254
            enableControls(false);
255
        }
256
        if(ConceptRelationshipComposite.UPDATE_END_ID.equals(event.getEventId())) {
257
            updateControls();
258
        }
259

  
260
    }
261

  
233 262
    @AutoGenerated
234 263
    private VerticalLayout buildMainLayout() {
235 264
        // common part: create layout
......
299 328
    }
300 329

  
301 330

  
331

  
302 332
}
src/main/java/eu/etaxonomy/cdm/vaadin/component/EditConceptRelationshipComposite.java
31 31
import com.vaadin.ui.Button.ClickEvent;
32 32
import com.vaadin.ui.Button.ClickListener;
33 33
import com.vaadin.ui.ComboBox;
34
import com.vaadin.ui.Component;
34 35
import com.vaadin.ui.CustomComponent;
35 36
import com.vaadin.ui.DragAndDropWrapper;
36 37
import com.vaadin.ui.HorizontalLayout;
......
53 54
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinOperation;
54 55
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
55 56
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinUtilities;
57
;
56 58

  
57 59
/**
58 60
 * @author cmathew
......
85 87
    private Label typeLabel;
86 88
    @AutoGenerated
87 89
    private Label leftLabel;
88
    @AutoGenerated
89
    private VerticalLayout fromTaxonVLayout;
90
    @AutoGenerated
91
    private Label fromTaxonValue;
92
    @AutoGenerated
93
    private Label fromTaxonLabel;
94
    private VerticalLayout toTaxonVLayout;
95
    private Label toTaxonLabeL;
96
    private TextField toTaxonTextField;
97
    private DragAndDropWrapper toTaxonLayoutWrapper;
90
    private TextField leftTaxonTextField, rightTaxonTextField;
91

  
92
    private Component leftTaxonComponent, rightTaxonComponent;
93
    private TextField fromTaxonTextField, toTaxonTextField;
94
    private Label leftTaxonLabel, rightTaxonLabel;
95

  
98 96

  
99 97
    private final EditConceptRelationshipPresenter presenter;
100 98

  
......
114 112
            IdUuidName toTaxonIdUuidName,
115 113
            Action action,
116 114
            Direction direction) {
117
        this();
118
        this.direction = direction;
115
        this(direction);
116

  
119 117
        init(fromTaxonIdUuidName, taxonRTypeIdUuidName, toTaxonIdUuidName, action);
120 118

  
121 119
    }
......
124 122
            UUID relUuid,
125 123
            Action action,
126 124
            Direction direction) {
127
        this();
125
        this(direction);
128 126
        this.relUuid = relUuid;
129
        this.direction = direction;
127

  
130 128
        Map<String, IdUuidName> map = presenter.getRelTypeToTaxonIunMap(fromTaxonIun.getUuid(), relUuid);
131 129
        taxonRTypeIun = map.get(EditConceptRelationshipPresenter.REL_TYPE_KEY);
132 130
        toTaxonIun = map.get(EditConceptRelationshipPresenter.TO_TAXON_KEY);
133 131
        init(fromTaxonIun, taxonRTypeIun, toTaxonIun, action);
134 132

  
135 133
    }
134

  
135

  
136 136
    /**
137 137
     * The constructor should first build the main layout, set the
138 138
     * composition root and then do any custom initialization.
......
140 140
     * The constructor will not be automatically regenerated by the
141 141
     * visual editor.
142 142
     */
143
    public EditConceptRelationshipComposite() {
143
    private EditConceptRelationshipComposite(Direction direction) {
144
        this.direction = direction;
144 145

  
145 146
        buildMainLayout();
146
        buildToTaxon();
147
        initDirectionComponents();
147 148
        setCompositionRoot(mainLayout);
148 149

  
149
        direction = Direction.LEFT_RIGHT;
150 150
        this.presenter = new EditConceptRelationshipPresenter();
151 151
        addUIListeners();
152

  
153 152
    }
154 153

  
154

  
155 155
    public void init(IdUuidName fromTaxonIdUuidName,
156 156
            IdUuidName taxonRTypeIdUuidName,
157 157
            IdUuidName toTaxonIdUuidName,
......
162 162
        this.toTaxonIun = toTaxonIdUuidName;
163 163
        this.action = action;
164 164

  
165
        initFromTaxonLabel();
165
        initFromTaxon();
166 166
        initConceptRComboBox();
167
        initToTaxon();
168
        initDirectionLabels();
169 167
    }
170 168

  
171 169
    public void setWindow(Window window) {
172 170
        this.window = window;
173 171
    }
174
    private void initFromTaxonLabel() {
175
        fromTaxonValue.setValue(fromTaxonIun.getName());
172

  
173
    private void initFromTaxon() {
174
        if(fromTaxonIun != null) {
175
            fromTaxonTextField.setReadOnly(false);
176
            fromTaxonTextField.setValue(fromTaxonIun.getName());
177
            fromTaxonTextField.setReadOnly(true);
178
        }
179
        if(toTaxonIun != null) {
180
            toTaxonTextField.setReadOnly(false);
181
            toTaxonTextField.setValue(toTaxonIun.getName());
182
            toTaxonTextField.setReadOnly(true);
183
        }
176 184
    }
177 185

  
178
    private void initDirectionLabels() {
186
    private void initDirectionComponents() {
187

  
188
        initTaxonComponents();
179 189

  
180 190
        leftLabel.addStyleName("cr-arrow");
181 191
        leftLabel.setContentMode(ContentMode.HTML);
......
183 193
        rightLabel.addStyleName("cr-arrow");
184 194
        rightLabel.setContentMode(ContentMode.HTML);
185 195

  
196
        rightTaxonTextField.setReadOnly(false);
197
        leftTaxonTextField.setReadOnly(false);
186 198
        switch(direction) {
187 199
        case LEFT_RIGHT:
188
            leftLabel.setValue(FontAwesome.LONG_ARROW_RIGHT.getHtml());
189
            rightLabel.setValue(FontAwesome.LONG_ARROW_RIGHT.getHtml());
200
            leftLabel.setValue(FontAwesome.CARET_RIGHT.getHtml());
201
            rightLabel.setValue(FontAwesome.CARET_RIGHT.getHtml());
202
            leftTaxonLabel.setValue("From Taxon");
203
            rightTaxonLabel.setValue("To Taxon");
204
            fromTaxonTextField = leftTaxonTextField;
205
            toTaxonTextField = rightTaxonTextField;
206
            rightTaxonTextField.setValue(DRAG_TAXON_HINT);
207
            rightTaxonComponent = intiDragDropWrapper(rightTaxonComponent, rightTaxonTextField);
190 208
            break;
191 209
        case RIGHT_LEFT:
192
            leftLabel.setValue(FontAwesome.LONG_ARROW_LEFT.getHtml());
193
            rightLabel.setValue(FontAwesome.LONG_ARROW_LEFT.getHtml());
210
            leftLabel.setValue(FontAwesome.CARET_LEFT.getHtml());
211
            rightLabel.setValue(FontAwesome.CARET_LEFT.getHtml());
212
            leftTaxonLabel.setValue("To Taxon");
213
            rightTaxonLabel.setValue("From Taxon");
214
            leftTaxonTextField.setValue(DRAG_TAXON_HINT);
215
            fromTaxonTextField = rightTaxonTextField;
216
            toTaxonTextField = leftTaxonTextField;
217
            leftTaxonComponent = intiDragDropWrapper(leftTaxonComponent, leftTaxonTextField);
194 218
            break;
195 219
        }
220

  
221
        rightTaxonTextField.setReadOnly(true);
222
        leftTaxonTextField.setReadOnly(true);
223

  
224
        horizontalLayout.addComponent(leftTaxonComponent,0);
225
        horizontalLayout.setComponentAlignment(leftTaxonComponent, new Alignment(48));
226

  
227

  
228
        horizontalLayout.addComponent(rightTaxonComponent);
229
        horizontalLayout.setComponentAlignment(rightTaxonComponent, new Alignment(48));
230

  
231
        leftLabel.setSizeUndefined();
232
        rightLabel.setSizeUndefined();
233

  
196 234
    }
197 235

  
198 236
    private void initConceptRComboBox() {
......
216 254
        }
217 255
    }
218 256

  
219
    private void buildToTaxon() {
220
        toTaxonVLayout = buildToTaxonVLayout();
221
        toTaxonLayoutWrapper = new DragAndDropWrapper(toTaxonVLayout);
257
    private void initTaxonComponents() {
258
        // init left taxon layout
259
        leftTaxonLabel = new Label();
260
        leftTaxonTextField = new TextField();
261
        leftTaxonComponent = buildTaxonVLayout(leftTaxonLabel, leftTaxonTextField);
262

  
263
        // init right taxon layout
264
        rightTaxonLabel = new Label();
265
        rightTaxonTextField = new TextField();
266
        rightTaxonComponent = buildTaxonVLayout(rightTaxonLabel, rightTaxonTextField);
267
    }
268

  
269
    private DragAndDropWrapper intiDragDropWrapper(Component toTaxonLayout, final TextField toTaxonTextField) {
270

  
271
        DragAndDropWrapper toTaxonLayoutWrapper = new DragAndDropWrapper(toTaxonLayout);
222 272
        toTaxonLayoutWrapper.setImmediate(false);
223 273
        toTaxonLayoutWrapper.setWidth("-1px");
224 274
        toTaxonLayoutWrapper.setHeight("-1px");
225
        toTaxonTextField.setReadOnly(true);
226 275

  
227 276
        toTaxonLayoutWrapper.setDropHandler(new DropHandler() {
228 277

  
......
254 303
                }
255 304
            }
256 305
        });
257
        horizontalLayout.addComponent(toTaxonLayoutWrapper);
258
        horizontalLayout.setComponentAlignment(toTaxonLayoutWrapper, new Alignment(48));
306
        return toTaxonLayoutWrapper;
259 307

  
260 308
    }
261 309

  
262
    private void initToTaxon() {
263
        toTaxonTextField.setReadOnly(false);
264
        if(toTaxonIun == null) {
265
            toTaxonTextField.setValue(DRAG_TAXON_HINT);
266
        } else {
267
            toTaxonTextField.setValue(toTaxonIun.getName());
268
        }
269
        toTaxonTextField.setReadOnly(true);
270
    }
271 310

  
272 311
    private void addUIListeners() {
273 312
        addSaveButtonListener();
......
284 323

  
285 324
                try {
286 325
                    conceptRComboBox.validate();
287
                    toTaxonTextField.validate();
326
                    rightTaxonTextField.validate();
288 327
                    if(toTaxonIun == null) {
289 328
                        // FIXME: Not efficient - figure out a way
290 329
                        // of validation including the null check
......
392 431
        showInDialog(windowTitle, ecrc);
393 432
    }
394 433

  
395
    private VerticalLayout buildToTaxonVLayout() {
434

  
435
    private VerticalLayout buildTaxonVLayout(Label taxonDirLabel, TextField taxonTextField) {
396 436
        // common part: create layout
397
        toTaxonVLayout = new VerticalLayout();
398
        toTaxonVLayout.setImmediate(false);
399
        toTaxonVLayout.setWidth("-1px");
400
        toTaxonVLayout.setHeight("-1px");
401
        toTaxonVLayout.setMargin(false);
402
        toTaxonVLayout.setSpacing(true);
403

  
404
        // toTaxonLabeL
405
        toTaxonLabeL = new Label();
406
        toTaxonLabeL.setImmediate(false);
407
        toTaxonLabeL.setWidth("-1px");
408
        toTaxonLabeL.setHeight("-1px");
409
        toTaxonLabeL.setValue("To Taxon");
410
        toTaxonVLayout.addComponent(toTaxonLabeL);
411
        toTaxonVLayout.setComponentAlignment(toTaxonLabeL, new Alignment(48));
412

  
413
        // toTaxonTextField
414
        toTaxonTextField = new TextField();
415
        toTaxonTextField.setImmediate(false);
416
        toTaxonTextField.setWidth("-1px");
417
        toTaxonTextField.setHeight("-1px");
418
        toTaxonTextField.setInvalidAllowed(false);
419
        toTaxonTextField.setRequired(true);
420
        toTaxonTextField.setInputPrompt("Drag Taxon here ...");
421
        toTaxonVLayout.addComponent(toTaxonTextField);
422
        toTaxonVLayout.setComponentAlignment(toTaxonTextField, new Alignment(48));
423

  
424
        return toTaxonVLayout;
437
        VerticalLayout vLayout = new VerticalLayout();
438
        vLayout.setImmediate(false);
439
        vLayout.setWidth("-1px");
440
        vLayout.setHeight("-1px");
441
        vLayout.setMargin(false);
442
        vLayout.setSpacing(true);
443

  
444

  
445
        taxonDirLabel.setImmediate(false);
446
        taxonDirLabel.setWidth("-1px");
447
        taxonDirLabel.setHeight("-1px");
448

  
449
        vLayout.addComponent(taxonDirLabel);
450
        vLayout.setComponentAlignment(taxonDirLabel, new Alignment(48));
451

  
452

  
453
        taxonTextField.setImmediate(false);
454
        taxonTextField.setWidth("-1px");
455
        taxonTextField.setHeight("-1px");
456
        taxonTextField.setInvalidAllowed(false);
457
        taxonTextField.setRequired(true);
458
        taxonTextField.setReadOnly(true);
459
        vLayout.addComponent(taxonTextField);
460
        vLayout.setComponentAlignment(taxonTextField, new Alignment(48));
461

  
462
        return vLayout;
425 463
    }
426 464

  
427 465
    @AutoGenerated
......
429 467
        // common part: create layout
430 468
        mainLayout = new VerticalLayout();
431 469
        mainLayout.setImmediate(false);
432
        mainLayout.setWidth("700px");
470
        mainLayout.setWidth("740px");
433 471
        mainLayout.setHeight("170px");
434 472
        mainLayout.setMargin(false);
435 473
        mainLayout.setSpacing(true);
436 474

  
437 475
        // top-level component properties
438
        setWidth("700px");
476
        setWidth("740px");
439 477
        setHeight("170px");
440 478

  
441 479
        // horizontalLayout
......
470 508
        horizontalLayout.setMargin(true);
471 509
        horizontalLayout.setSpacing(true);
472 510

  
473
        // fromTaxonVLayout
474
        fromTaxonVLayout = buildFromTaxonVLayout();
475
        horizontalLayout.addComponent(fromTaxonVLayout);
476
        horizontalLayout.setComponentAlignment(fromTaxonVLayout, new Alignment(48));
477

  
478 511
        // leftLabel
479 512
        leftLabel = new Label();
480 513
        leftLabel.setImmediate(false);
481 514
        leftLabel.setWidth("-1px");
482
        leftLabel.setHeight("-1px");
515
        leftLabel.setHeight("30px");
483 516
        leftLabel.setValue("Label");
484 517
        horizontalLayout.addComponent(leftLabel);
485 518
        horizontalLayout.setComponentAlignment(leftLabel, new Alignment(24));
......
487 520
        // typeVLayout
488 521
        typeVLayout = buildTypeVLayout();
489 522
        horizontalLayout.addComponent(typeVLayout);
523
        horizontalLayout.setExpandRatio(typeVLayout, 1.0f);
490 524
        horizontalLayout.setComponentAlignment(typeVLayout, new Alignment(48));
491 525

  
492 526
        // rightLabel
493 527
        rightLabel = new Label();
494 528
        rightLabel.setImmediate(false);
495 529
        rightLabel.setWidth("-1px");
496
        rightLabel.setHeight("-1px");
530
        rightLabel.setHeight("30px");
497 531
        rightLabel.setValue("Label");
498 532
        horizontalLayout.addComponent(rightLabel);
499 533
        horizontalLayout.setComponentAlignment(rightLabel, new Alignment(24));
......
501 535
        return horizontalLayout;
502 536
    }
503 537

  
504
    @AutoGenerated
505
    private VerticalLayout buildFromTaxonVLayout() {
506
        // common part: create layout
507
        fromTaxonVLayout = new VerticalLayout();
508
        fromTaxonVLayout.setImmediate(false);
509
        fromTaxonVLayout.setWidth("-1px");
510
        fromTaxonVLayout.setHeight("-1px");
511
        fromTaxonVLayout.setMargin(false);
512
        fromTaxonVLayout.setSpacing(true);
513

  
514
        // fromTaxonLabel
515
        fromTaxonLabel = new Label();
516
        fromTaxonLabel.setImmediate(false);
517
        fromTaxonLabel.setWidth("-1px");
518
        fromTaxonLabel.setHeight("-1px");
519
        fromTaxonLabel.setValue("From Taxon");
520
        fromTaxonVLayout.addComponent(fromTaxonLabel);
521
        fromTaxonVLayout.setComponentAlignment(fromTaxonLabel, new Alignment(48));
522

  
523
        // fromTaxonValue
524
        fromTaxonValue = new Label();
525
        fromTaxonValue.setImmediate(false);
526
        fromTaxonValue.setWidth("-1px");
527
        fromTaxonValue.setHeight("-1px");
528
        fromTaxonValue.setValue("Taxon Name");
529
        fromTaxonVLayout.addComponent(fromTaxonValue);
530
        fromTaxonVLayout.setComponentAlignment(fromTaxonValue, new Alignment(48));
531

  
532
        return fromTaxonVLayout;
533
    }
534

  
535 538
    @AutoGenerated
536 539
    private VerticalLayout buildTypeVLayout() {
537 540
        // common part: create layout
......
554 557
        // conceptRComboBox
555 558
        conceptRComboBox = new ComboBox();
556 559
        conceptRComboBox.setImmediate(false);
557
        conceptRComboBox.setWidth("-1px");
560
        conceptRComboBox.setWidth("260px");
558 561
        conceptRComboBox.setHeight("-1px");
559 562
        conceptRComboBox.setRequired(true);
560 563
        typeVLayout.addComponent(conceptRComboBox);
564
        typeVLayout.setExpandRatio(conceptRComboBox, 1.0f);
561 565
        typeVLayout.setComponentAlignment(conceptRComboBox, new Alignment(48));
562 566

  
563 567
        return typeVLayout;

Also available in: Unified diff