Revision 2ba67e3f
Added by Cherian Mathew about 9 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/ConceptRelationshipComposite.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.cdm.vaadin.component; |
11 | 11 |
|
12 |
import java.util.UUID; |
|
13 |
|
|
14 | 12 |
import org.json.JSONException; |
15 | 13 |
|
16 | 14 |
import com.vaadin.annotations.AutoGenerated; |
17 | 15 |
import com.vaadin.ui.Alignment; |
18 | 16 |
import com.vaadin.ui.Button; |
17 |
import com.vaadin.ui.Button.ClickEvent; |
|
18 |
import com.vaadin.ui.Button.ClickListener; |
|
19 | 19 |
import com.vaadin.ui.CustomComponent; |
20 | 20 |
import com.vaadin.ui.HorizontalLayout; |
21 | 21 |
import com.vaadin.ui.Notification; |
22 | 22 |
import com.vaadin.ui.Notification.Type; |
23 |
import com.vaadin.ui.UI; |
|
23 | 24 |
import com.vaadin.ui.VerticalLayout; |
25 |
import com.vaadin.ui.Window; |
|
24 | 26 |
|
27 |
import eu.etaxonomy.cdm.vaadin.container.IdUuidName; |
|
25 | 28 |
import eu.etaxonomy.cdm.vaadin.jscomponent.D3ConceptRelationshipTree; |
26 | 29 |
import eu.etaxonomy.cdm.vaadin.presenter.ConceptRelationshipPresenter; |
30 |
import eu.etaxonomy.cdm.vaadin.session.CdmChangeEvent; |
|
31 |
import eu.etaxonomy.cdm.vaadin.session.ICdmChangeListener; |
|
27 | 32 |
import eu.etaxonomy.cdm.vaadin.session.ISelectionListener; |
28 | 33 |
import eu.etaxonomy.cdm.vaadin.session.SelectionEvent; |
29 | 34 |
import eu.etaxonomy.cdm.vaadin.util.CdmVaadinSessionUtilities; |
... | ... | |
34 | 39 |
* @date 9 Apr 2015 |
35 | 40 |
* |
36 | 41 |
*/ |
37 |
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener { |
|
42 |
public class ConceptRelationshipComposite extends CustomComponent implements ISelectionListener, ICdmChangeListener {
|
|
38 | 43 |
|
39 | 44 |
/*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */ |
40 | 45 |
|
... | ... | |
53 | 58 |
|
54 | 59 |
private final IConceptRelationshipComponentListener listener; |
55 | 60 |
|
56 |
private UUID currentFromTaxonUuid; |
|
61 |
private IdUuidName fromTaxonIun; |
|
62 |
|
|
63 |
private static final String CREATE_NEW_CR_TITLE = "Create New Concept Relationship"; |
|
57 | 64 |
|
58 | 65 |
/** |
59 | 66 |
* The constructor should first build the main layout, set the |
... | ... | |
67 | 74 |
setCompositionRoot(mainLayout); |
68 | 75 |
|
69 | 76 |
CdmVaadinSessionUtilities.getCurrentSelectionService().register(this); |
77 |
CdmVaadinSessionUtilities.getCurrentCdmDataChangeService().register(this); |
|
70 | 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() { |
|
71 | 91 |
d3ConceptRelationShipTree.setImmediate(true); |
92 |
} |
|
72 | 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 |
} |
|
73 | 127 |
} |
74 | 128 |
|
75 | 129 |
/* (non-Javadoc) |
... | ... | |
78 | 132 |
@Override |
79 | 133 |
public void onSelect(SelectionEvent event) { |
80 | 134 |
if(event.getSourceType().equals(StatusComposite.class)) { |
81 |
currentFromTaxonUuid = (UUID)event.getSelectedObjects().get(0); |
|
82 |
try { |
|
83 |
listener.refreshRelationshipView(currentFromTaxonUuid); |
|
84 |
} catch (JSONException e) { |
|
85 |
Notification.show("Error generating concept relation JSON", e.getMessage(), Type.WARNING_MESSAGE); |
|
86 |
} |
|
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(); |
|
87 | 150 |
} |
88 | 151 |
|
89 | 152 |
} |
90 | 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 |
} |
|
91 | 173 |
@AutoGenerated |
92 | 174 |
private VerticalLayout buildMainLayout() { |
93 | 175 |
// common part: create layout |
... | ... | |
156 | 238 |
return updateHorizontalLayout; |
157 | 239 |
} |
158 | 240 |
|
241 |
|
|
159 | 242 |
} |
Also available in: Unified diff
EditConceptRelationshipComposite : updated ui, added save + cancel + drag&drop functionality
ConceptRelationshipComposite : using the EditConceptRelationshipComposite
StatusComposite : set drag&drop mode
ConceptRelationshipPresenter, EditConceptRelationshipPresenter : moved create, update, edit methods to EditConceptRelationshipPresenter
ConceptRelationshipPresenterTest, EditConceptRelationshipPresenterTest(xml) : moved tests to EditConceptRelationshipPresenterTest