14 |
14 |
import java.util.HashMap;
|
15 |
15 |
import java.util.List;
|
16 |
16 |
import java.util.Map;
|
17 |
|
import java.util.UUID;
|
18 |
17 |
|
19 |
18 |
import javax.annotation.PostConstruct;
|
20 |
19 |
import javax.annotation.PreDestroy;
|
21 |
20 |
import javax.inject.Inject;
|
22 |
21 |
import javax.inject.Named;
|
23 |
22 |
|
|
23 |
import org.eclipse.e4.core.di.annotations.Optional;
|
24 |
24 |
import org.eclipse.e4.ui.di.Focus;
|
25 |
25 |
import org.eclipse.e4.ui.di.Persist;
|
26 |
26 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable;
|
... | ... | |
31 |
31 |
import org.eclipse.jface.viewers.IStructuredSelection;
|
32 |
32 |
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
33 |
33 |
import org.eclipse.jface.viewers.TreeSelection;
|
34 |
|
import org.eclipse.jface.viewers.TreeViewer;
|
35 |
34 |
import org.eclipse.swt.SWT;
|
36 |
35 |
import org.eclipse.swt.custom.SashForm;
|
37 |
|
import org.eclipse.swt.dnd.DND;
|
38 |
|
import org.eclipse.swt.dnd.Transfer;
|
39 |
36 |
import org.eclipse.swt.events.ModifyEvent;
|
40 |
37 |
import org.eclipse.swt.events.ModifyListener;
|
41 |
38 |
import org.eclipse.swt.events.SelectionAdapter;
|
... | ... | |
47 |
44 |
import org.eclipse.swt.widgets.Display;
|
48 |
45 |
import org.eclipse.swt.widgets.Label;
|
49 |
46 |
import org.eclipse.swt.widgets.Shell;
|
50 |
|
import org.eclipse.swt.widgets.Tree;
|
51 |
47 |
import org.eclipse.ui.forms.widgets.FormToolkit;
|
52 |
48 |
|
53 |
49 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
54 |
50 |
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
55 |
51 |
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
56 |
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
57 |
52 |
import eu.etaxonomy.cdm.model.description.Character;
|
58 |
53 |
import eu.etaxonomy.cdm.model.description.FeatureNode;
|
59 |
54 |
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
60 |
55 |
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeDragListener;
|
61 |
56 |
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeDropAdapter;
|
62 |
|
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer;
|
63 |
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider;
|
64 |
|
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider;
|
65 |
57 |
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditorComposite;
|
66 |
58 |
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
67 |
59 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
... | ... | |
77 |
69 |
public class CharacterEditor implements ICdmEntitySessionEnabled, ISelectionChangedListener, ModifyListener{
|
78 |
70 |
|
79 |
71 |
|
80 |
|
private FeatureTreeEditorComposite featureTreeEditorComposite;
|
81 |
|
private TreeViewer treeViewerProperties;
|
82 |
|
private TreeViewer treeViewerStructures;
|
|
72 |
private FeatureTreeEditorComposite characterTreeEditorComposite;
|
|
73 |
private FeatureTreeEditorComposite treeViewerProperties;
|
|
74 |
private FeatureTreeEditorComposite treeViewerStructures;
|
83 |
75 |
private final FormToolkit formToolkit = new FormToolkit(Display.getDefault());
|
84 |
76 |
private Button btnAddCharacter;
|
85 |
77 |
|
... | ... | |
89 |
81 |
@Inject
|
90 |
82 |
private MDirtyable dirty;
|
91 |
83 |
|
|
84 |
private Shell shell;
|
|
85 |
|
92 |
86 |
private ConversationHolder conversation;
|
93 |
87 |
|
94 |
88 |
private ICdmEntitySession cdmEntitySession;
|
95 |
89 |
|
96 |
|
private FeatureTree featureTree;
|
97 |
|
|
98 |
90 |
public CharacterEditor() {
|
99 |
|
if(conversation==null){
|
100 |
|
conversation = CdmStore.createConversation();
|
101 |
|
}
|
102 |
|
if (CdmStore.isActive()) {
|
103 |
|
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
104 |
|
}
|
105 |
91 |
}
|
106 |
92 |
|
107 |
93 |
/**
|
108 |
94 |
* Create contents of the view part.
|
109 |
95 |
*/
|
110 |
96 |
@PostConstruct
|
111 |
|
public void createControls(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
|
|
97 |
public void createControls(Composite parent) {
|
|
98 |
if (CdmStore.isActive()){
|
|
99 |
if(conversation == null){
|
|
100 |
conversation = CdmStore.createConversation();
|
|
101 |
}
|
|
102 |
if(cdmEntitySession!=null){
|
|
103 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
|
|
104 |
}
|
|
105 |
}
|
|
106 |
else{
|
|
107 |
return;
|
|
108 |
}
|
112 |
109 |
parent.setLayout(new GridLayout(1, false));
|
113 |
110 |
|
114 |
111 |
SashForm sashForm = new SashForm(parent, SWT.NONE);
|
... | ... | |
126 |
123 |
formToolkit.adapt(lblNewLabel, true, true);
|
127 |
124 |
lblNewLabel.setText("Structures");
|
128 |
125 |
|
129 |
|
treeViewerStructures = new TreeViewer(composite, SWT.BORDER);
|
130 |
|
Tree tree = treeViewerStructures.getTree();
|
131 |
|
tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
|
126 |
treeViewerStructures = addFeatureTreeEditor(composite);
|
|
127 |
initFeatureTreeComposite(treeViewerStructures, null, null);
|
132 |
128 |
|
133 |
129 |
Composite composite_1 = new Composite(sashForm, SWT.NONE);
|
134 |
130 |
formToolkit.adapt(composite_1);
|
... | ... | |
140 |
136 |
formToolkit.adapt(lblNewLabel_1, true, true);
|
141 |
137 |
lblNewLabel_1.setText("Properties");
|
142 |
138 |
|
143 |
|
treeViewerProperties = new TreeViewer(composite_1, SWT.BORDER);
|
144 |
|
Tree tree_1 = treeViewerProperties.getTree();
|
145 |
|
tree_1.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
|
139 |
treeViewerProperties = addFeatureTreeEditor(composite_1);
|
|
140 |
initFeatureTreeComposite(treeViewerProperties, new CharacterDragListener(treeViewerStructures.getViewer(), treeViewerProperties.getViewer()), null);
|
146 |
141 |
|
147 |
142 |
Composite composite_2 = new Composite(sashForm, SWT.NONE);
|
148 |
143 |
formToolkit.adapt(composite_2);
|
... | ... | |
159 |
154 |
formToolkit.paintBordersFor(composite_3);
|
160 |
155 |
composite_3.setLayout(new GridLayout(1, false));
|
161 |
156 |
|
162 |
|
featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.BORDER);
|
|
157 |
characterTreeEditorComposite = addFeatureTreeEditor(composite_3);
|
|
158 |
initFeatureTreeComposite(characterTreeEditorComposite, new FeatureNodeDragListener(characterTreeEditorComposite.getViewer()), new FeatureNodeDropAdapter(characterTreeEditorComposite.getViewer()));
|
|
159 |
|
|
160 |
sashForm.setWeights(new int[] {3, 3, 1, 3});
|
|
161 |
|
|
162 |
init();
|
|
163 |
}
|
|
164 |
|
|
165 |
private FeatureTreeEditorComposite addFeatureTreeEditor(Composite composite_3) {
|
|
166 |
FeatureTreeEditorComposite featureTreeEditorComposite = new FeatureTreeEditorComposite(composite_3, SWT.BORDER);
|
163 |
167 |
featureTreeEditorComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
|
164 |
168 |
featureTreeEditorComposite.getButton_add().setVisible(false);
|
165 |
169 |
featureTreeEditorComposite.getButton_remove().setVisible(false);
|
166 |
|
featureTreeEditorComposite.init(new FeatureNodeDragListener(featureTreeEditorComposite.getViewer()), new FeatureNodeDropAdapter(featureTreeEditorComposite.getViewer()), this, new SelectionAdapter() {
|
167 |
|
@Override
|
168 |
|
public void widgetSelected(SelectionEvent e) {
|
169 |
|
FeatureTree tree = FeatureTreeSelectionDialog.select(shell, conversation, null);
|
170 |
|
if(tree!=null){
|
171 |
|
setSelectedTree(tree);
|
172 |
|
}
|
173 |
|
}
|
174 |
|
}, new SelectionAdapter() {
|
175 |
|
}, new SelectionAdapter() {
|
176 |
|
});
|
177 |
|
sashForm.setWeights(new int[] {3, 3, 1, 3});
|
|
170 |
return featureTreeEditorComposite;
|
|
171 |
}
|
178 |
172 |
|
179 |
|
init();
|
|
173 |
private void initFeatureTreeComposite(FeatureTreeEditorComposite featureTreeEditorComposite,
|
|
174 |
FeatureNodeDragListener featureNodeDragListener, FeatureNodeDropAdapter featureNodeDropAdapter) {
|
|
175 |
featureTreeEditorComposite.init(featureNodeDragListener, featureNodeDropAdapter, this,
|
|
176 |
new FeatureTreeChooserListener(featureTreeEditorComposite), new SelectionAdapter() {
|
|
177 |
}, new SelectionAdapter() {
|
|
178 |
});
|
180 |
179 |
}
|
181 |
180 |
|
182 |
181 |
@Focus
|
183 |
|
public void focus(){
|
184 |
|
featureTreeEditorComposite.getViewer().getControl().setFocus();
|
|
182 |
public void focus(@Optional@Named(IServiceConstants.ACTIVE_SHELL)Shell shell){
|
|
183 |
this.shell = shell;
|
|
184 |
if(characterTreeEditorComposite!=null){
|
|
185 |
characterTreeEditorComposite.getViewer().getControl().setFocus();
|
|
186 |
}
|
185 |
187 |
if(conversation!=null && !conversation.isBound()){
|
186 |
188 |
conversation.bind();
|
187 |
189 |
}
|
... | ... | |
190 |
192 |
}
|
191 |
193 |
}
|
192 |
194 |
|
193 |
|
public void setSelectedTree(FeatureTree featureTree) {
|
194 |
|
this.featureTree = HibernateProxyHelper.deproxy(featureTree, FeatureTree.class);
|
195 |
|
this.featureTree.setRoot(HibernateProxyHelper.deproxy(featureTree.getRoot(), FeatureNode.class));
|
196 |
|
featureTreeEditorComposite.getViewer().setInput(featureTree);
|
197 |
|
|
198 |
|
featureTreeEditorComposite.getText_title().removeModifyListener(this);
|
199 |
|
featureTreeEditorComposite.getText_title().setText(featureTree.getTitleCache());
|
200 |
|
featureTreeEditorComposite.getText_title().addModifyListener(this);
|
201 |
|
}
|
202 |
|
|
203 |
195 |
private void init(){
|
204 |
|
int dndOperations = DND.DROP_COPY | DND.DROP_MOVE;
|
205 |
|
Transfer[] transfers = new Transfer[] { FeatureNodeTransfer.getInstance() };
|
206 |
|
|
207 |
|
FeatureTree structureFeatureTree = CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString("3a953dd1-2b5f-482f-9a33-664ee7ef6c68"));
|
208 |
|
treeViewerStructures.setContentProvider(new FeatureTreeContentProvider());
|
209 |
|
treeViewerStructures.setLabelProvider(new FeatureTreeLabelProvider());
|
210 |
|
treeViewerStructures.setInput(structureFeatureTree);
|
211 |
|
|
212 |
|
FeatureTree propertiesFeatureTree = CdmStore.getService(IFeatureTreeService.class).load(UUID.fromString("e283bbf5-bda3-449d-98de-3601ac8a8bbd"));
|
213 |
|
treeViewerProperties.setContentProvider(new FeatureTreeContentProvider());
|
214 |
|
treeViewerProperties.setLabelProvider(new FeatureTreeLabelProvider());
|
215 |
|
treeViewerProperties.addDragSupport(dndOperations, transfers, new CharacterDragListener(treeViewerStructures, treeViewerProperties));
|
216 |
|
treeViewerProperties.setInput(propertiesFeatureTree);
|
217 |
|
|
218 |
196 |
btnAddCharacter.addSelectionListener(new SelectionAdapter() {
|
219 |
197 |
/**
|
220 |
198 |
* {@inheritDoc}
|
221 |
199 |
*/
|
222 |
200 |
@Override
|
223 |
201 |
public void widgetSelected(SelectionEvent e) {
|
224 |
|
ISelection structureTreeSelection = treeViewerStructures.getSelection();
|
225 |
|
ISelection propertyTreeSelection = treeViewerProperties.getSelection();
|
226 |
|
if(structureTreeSelection==null || propertyTreeSelection==null || featureTree==null){
|
|
202 |
ISelection structureTreeSelection = treeViewerStructures.getViewer().getSelection();
|
|
203 |
ISelection propertyTreeSelection = treeViewerProperties.getViewer().getSelection();
|
|
204 |
if(structureTreeSelection==null || propertyTreeSelection==null || characterTreeEditorComposite.getFeatureTree()==null){
|
227 |
205 |
MessagingUtils.warningDialog("Cannot perform action", CharacterEditor.this,
|
228 |
206 |
"You have to select a structure, a property and a feature tree to perform this action.");
|
229 |
207 |
return;
|
... | ... | |
234 |
212 |
//create new Character
|
235 |
213 |
String label = structureNode.getFeature().toString()+" "+propertyNode.getFeature().toString();
|
236 |
214 |
Character character = Character.NewInstance(structureNode, propertyNode, null, label, label);
|
237 |
|
// CdmStore.getService(ITermService.class).saveOrUpdate(character);
|
238 |
215 |
|
239 |
216 |
//add new Character to feature tree
|
240 |
|
FeatureNode parent = ((FeatureTree) featureTreeEditorComposite.getViewer().getInput()).getRoot();
|
|
217 |
FeatureNode parent = ((FeatureTree) characterTreeEditorComposite.getViewer().getInput()).getRoot();
|
241 |
218 |
CdmStore.getService(IFeatureNodeService.class).addChildFeaturNode(parent.getUuid(), character.getUuid());
|
242 |
219 |
|
243 |
220 |
setDirty(true);
|
244 |
|
featureTreeEditorComposite.getViewer().refresh();
|
|
221 |
characterTreeEditorComposite.getViewer().refresh();
|
245 |
222 |
}
|
246 |
223 |
});
|
247 |
224 |
}
|
... | ... | |
255 |
232 |
// commit the conversation and start a new transaction immediately
|
256 |
233 |
conversation.commit(true);
|
257 |
234 |
|
258 |
|
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(featureTree);
|
|
235 |
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(characterTreeEditorComposite.getFeatureTree());
|
259 |
236 |
|
260 |
237 |
this.setDirty(false);
|
261 |
238 |
}
|
... | ... | |
289 |
266 |
@Override
|
290 |
267 |
public List<FeatureTree> getRootEntities() {
|
291 |
268 |
List<FeatureTree> root = new ArrayList<>();
|
292 |
|
root.add(featureTree);
|
|
269 |
root.add(characterTreeEditorComposite.getFeatureTree());
|
293 |
270 |
return root;
|
294 |
271 |
}
|
295 |
272 |
|
... | ... | |
305 |
282 |
}
|
306 |
283 |
}
|
307 |
284 |
|
308 |
|
public TreeViewer getTreeViewerProperties() {
|
309 |
|
return treeViewerProperties;
|
310 |
|
}
|
311 |
|
public TreeViewer getTreeViewerStructures() {
|
312 |
|
return treeViewerStructures;
|
313 |
|
}
|
314 |
|
|
315 |
285 |
/**
|
316 |
286 |
* {@inheritDoc}
|
317 |
287 |
*/
|
... | ... | |
322 |
292 |
selService.setSelection((isel.size() == 1 ? isel.getFirstElement() : isel.toArray()));
|
323 |
293 |
}
|
324 |
294 |
|
|
295 |
|
325 |
296 |
/**
|
326 |
297 |
* {@inheritDoc}
|
327 |
298 |
*/
|
328 |
299 |
@Override
|
329 |
300 |
public void modifyText(ModifyEvent e) {
|
330 |
|
featureTree.setTitleCache(featureTreeEditorComposite.getText_title().getText(), true);
|
|
301 |
characterTreeEditorComposite.getFeatureTree().setTitleCache(characterTreeEditorComposite.getText_title().getText(), true);
|
331 |
302 |
setDirty(true);
|
332 |
303 |
}
|
333 |
304 |
|
|
305 |
|
334 |
306 |
public void setDirty(boolean isDirty) {
|
335 |
307 |
dirty.setDirty(isDirty);
|
336 |
308 |
}
|
337 |
309 |
|
|
310 |
private class FeatureTreeChooserListener extends SelectionAdapter{
|
|
311 |
FeatureTreeEditorComposite featureTreeEditorComposite;
|
|
312 |
|
|
313 |
public FeatureTreeChooserListener(FeatureTreeEditorComposite featureTreeEditorComposite) {
|
|
314 |
super();
|
|
315 |
this.featureTreeEditorComposite = featureTreeEditorComposite;
|
|
316 |
}
|
|
317 |
|
|
318 |
@Override
|
|
319 |
public void widgetSelected(SelectionEvent e) {
|
|
320 |
FeatureTree tree = FeatureTreeSelectionDialog.select(shell, conversation, null);
|
|
321 |
if(tree!=null){
|
|
322 |
featureTreeEditorComposite.setSelectedTree(tree, CharacterEditor.this);
|
|
323 |
}
|
|
324 |
}
|
|
325 |
}
|
|
326 |
|
338 |
327 |
}
|
ref #6762 Use FeatureTreeEditorComposite for all tree viewers