Project

General

Profile

Download (7.78 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
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
*/
10
package eu.etaxonomy.cdm.vaadin.component;
11

    
12
import org.json.JSONException;
13

    
14
import com.vaadin.annotations.AutoGenerated;
15
import com.vaadin.ui.Alignment;
16
import com.vaadin.ui.Button;
17
import com.vaadin.ui.Button.ClickEvent;
18
import com.vaadin.ui.Button.ClickListener;
19
import com.vaadin.ui.CustomComponent;
20
import com.vaadin.ui.HorizontalLayout;
21
import com.vaadin.ui.Notification;
22
import com.vaadin.ui.Notification.Type;
23
import com.vaadin.ui.UI;
24
import com.vaadin.ui.VerticalLayout;
25
import com.vaadin.ui.Window;
26

    
27
import eu.etaxonomy.cdm.vaadin.container.IdUuidName;
28
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree;
29
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter;
30
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent;
31
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener;
32
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener;
33
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent;
34
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities;
35
import eu.etaxonomy.cdm.vaadin.view.IConceptRelationshipComponentListener;
36

    
37
/**
38
 * @author cmathew
39
 * @date 9 Apr 2015
40
 *
41
 */
42
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener {
43

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

    
46
    @AutoGenerated
47
    private VerticalLayout mainLayout;
48
    @AutoGenerated
49
    private D3ConceptRelationshipTree d3ConceptRelationShipTree;
50
    @AutoGenerated
51
    private HorizontalLayout updateHorizontalLayout;
52
    @AutoGenerated
53
    private Button deleteButton;
54
    @AutoGenerated
55
    private Button editButton;
56
    @AutoGenerated
57
    private Button newButton;
58

    
59
    private final IConceptRelationshipComponentListener listener;
60

    
61
    private IdUuidName fromTaxonIun;
62

    
63
    private static final String CREATE_NEW_CR_TITLE = "Create New Concept Relationship";
64

    
65
    /**
66
     * The constructor should first build the main layout, set the
67
     * composition root and then do any custom initialization.
68
     *
69
     * The constructor will not be automatically regenerated by the
70
     * visual editor.
71
     */
72
    public ConceptRelationshipComposite() {
73
        buildMainLayout();
74
        setCompositionRoot(mainLayout);
75

    
76
        CdmVaadinSessionUtilities.getCurrentSelectionService().register(this);
77
        CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this);
78
        listener = new ConceptRelationshipPresenter(d3ConceptRelationShipTree);
79

    
80
        addUIListeners();
81
        init();
82

    
83
    }
84

    
85

    
86
    private void init() {
87
        initD3ConceptRelationShipTree();
88
    }
89

    
90
    private void initD3ConceptRelationShipTree() {
91
        d3ConceptRelationShipTree.setImmediate(true);
92
    }
93

    
94
    private void addUIListeners() {
95
        addNewButtonListener();
96
    }
97

    
98
    private void addNewButtonListener() {
99
        newButton.addClickListener(new ClickListener() {
100

    
101
            @Override
102
            public void buttonClick(ClickEvent event) {
103
                showEditConceptRelationshipWindow(CREATE_NEW_CR_TITLE);
104
            }
105
        });
106
    }
107

    
108
    private void showEditConceptRelationshipWindow(String windowTitle) {
109
        Window dialog = new Window(windowTitle);
110
        dialog.setModal(false);
111
        dialog.setClosable(false);
112
        dialog.setResizable(false);
113
        UI.getCurrent().addWindow(dialog);
114

    
115
        EditConceptRelationshipComposite ecrc = new EditConceptRelationshipComposite(dialog,fromTaxonIun, null, null);
116
        dialog.setContent(ecrc);
117
    }
118

    
119
    private void refreshRelationshipView() {
120
        if(fromTaxonIun != null) {
121
            try {
122
                listener.refreshRelationshipView(fromTaxonIun);
123
            } catch (JSONException e) {
124
                Notification.show("Error generating concept relation JSON",  e.getMessage(), Type.WARNING_MESSAGE);
125
            }
126
        }
127
    }
128

    
129
    /* (non-Javadoc)
130
     * @see eu.etaxonomy.cdm.vaadin.session.ISelectionListener#onSelect(eu.etaxonomy.cdm.vaadin.session.SelectionEvent)
131
     */
132
    @Override
133
    public void onSelect(SelectionEvent event) {
134
        if(event.getSourceType().equals(StatusComposite.class)) {
135
            fromTaxonIun = (IdUuidName)event.getSelectedObjects().get(0);
136
            refreshRelationshipView();
137
        }
138

    
139
    }
140

    
141

    
142

    
143
    /* (non-Javadoc)
144
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onCreate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
145
     */
146
    @Override
147
    public void onCreate(CdmChangeEvent event) {
148
        if(event.getSourceType().equals(EditConceptRelationshipComposite.class)) {
149
            refreshRelationshipView();
150
        }
151

    
152
    }
153

    
154

    
155
    /* (non-Javadoc)
156
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onUpdate(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
157
     */
158
    @Override
159
    public void onUpdate(CdmChangeEvent event) {
160
        // TODO Auto-generated method stub
161

    
162
    }
163

    
164

    
165
    /* (non-Javadoc)
166
     * @see eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener#onDelete(eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent)
167
     */
168
    @Override
169
    public void onDelete(CdmChangeEvent event) {
170
        // TODO Auto-generated method stub
171

    
172
    }
173
    @AutoGenerated
174
    private VerticalLayout buildMainLayout() {
175
        // common part: create layout
176
        mainLayout = new VerticalLayout();
177
        mainLayout.setImmediate(false);
178
        mainLayout.setWidth("100%");
179
        mainLayout.setHeight("100%");
180
        mainLayout.setMargin(true);
181
        mainLayout.setSpacing(true);
182

    
183
        // top-level component properties
184
        setWidth("100.0%");
185
        setHeight("100.0%");
186

    
187
        // updateHorizontalLayout
188
        updateHorizontalLayout = buildUpdateHorizontalLayout();
189
        mainLayout.addComponent(updateHorizontalLayout);
190
        mainLayout.setComponentAlignment(updateHorizontalLayout, new Alignment(20));
191

    
192
        // d3ConceptRelationShipTree
193
        d3ConceptRelationShipTree = new D3ConceptRelationshipTree();
194
        d3ConceptRelationShipTree.setImmediate(false);
195
        d3ConceptRelationShipTree.setWidth("-1px");
196
        d3ConceptRelationShipTree.setHeight("-1px");
197
        mainLayout.addComponent(d3ConceptRelationShipTree);
198
        mainLayout.setExpandRatio(d3ConceptRelationShipTree, 1.0f);
199
        mainLayout.setComponentAlignment(d3ConceptRelationShipTree, new Alignment(20));
200

    
201
        return mainLayout;
202
    }
203

    
204
    @AutoGenerated
205
    private HorizontalLayout buildUpdateHorizontalLayout() {
206
        // common part: create layout
207
        updateHorizontalLayout = new HorizontalLayout();
208
        updateHorizontalLayout.setImmediate(false);
209
        updateHorizontalLayout.setWidth("-1px");
210
        updateHorizontalLayout.setHeight("-1px");
211
        updateHorizontalLayout.setMargin(true);
212
        updateHorizontalLayout.setSpacing(true);
213

    
214
        // newButton
215
        newButton = new Button();
216
        newButton.setCaption("new");
217
        newButton.setImmediate(true);
218
        newButton.setWidth("-1px");
219
        newButton.setHeight("-1px");
220
        updateHorizontalLayout.addComponent(newButton);
221

    
222
        // editButton
223
        editButton = new Button();
224
        editButton.setCaption("edit");
225
        editButton.setImmediate(true);
226
        editButton.setWidth("-1px");
227
        editButton.setHeight("-1px");
228
        updateHorizontalLayout.addComponent(editButton);
229

    
230
        // deleteButton
231
        deleteButton = new Button();
232
        deleteButton.setCaption("delete");
233
        deleteButton.setImmediate(true);
234
        deleteButton.setWidth("-1px");
235
        deleteButton.setHeight("-1px");
236
        updateHorizontalLayout.addComponent(deleteButton);
237

    
238
        return updateHorizontalLayout;
239
    }
240

    
241

    
242
}
(2-2/6)