Revision 6ba01b22
Added by Patrick Plitzner about 6 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/FeatureTreeEditor.java | ||
---|---|---|
9 | 9 |
|
10 | 10 |
package eu.etaxonomy.taxeditor.featuretree.e4; |
11 | 11 |
|
12 |
import java.util.ArrayList; |
|
13 | 12 |
import java.util.Arrays; |
14 | 13 |
import java.util.HashMap; |
15 | 14 |
import java.util.List; |
... | ... | |
20 | 19 |
import javax.inject.Inject; |
21 | 20 |
|
22 | 21 |
import org.eclipse.core.runtime.IProgressMonitor; |
23 |
import org.eclipse.core.runtime.NullProgressMonitor; |
|
24 | 22 |
import org.eclipse.e4.ui.di.Focus; |
25 | 23 |
import org.eclipse.e4.ui.di.Persist; |
26 | 24 |
import org.eclipse.e4.ui.model.application.ui.MDirtyable; |
... | ... | |
28 | 26 |
import org.eclipse.e4.ui.services.EMenuService; |
29 | 27 |
import org.eclipse.e4.ui.workbench.modeling.EPartService; |
30 | 28 |
import org.eclipse.e4.ui.workbench.modeling.ESelectionService; |
31 |
import org.eclipse.jface.dialogs.IDialogConstants; |
|
32 |
import org.eclipse.jface.dialogs.MessageDialog; |
|
33 | 29 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
34 | 30 |
import org.eclipse.jface.viewers.IStructuredSelection; |
35 | 31 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
36 | 32 |
import org.eclipse.jface.viewers.TreeViewer; |
37 |
import org.eclipse.swt.SWT; |
|
38 |
import org.eclipse.swt.events.ModifyEvent; |
|
39 |
import org.eclipse.swt.events.ModifyListener; |
|
40 |
import org.eclipse.swt.events.SelectionAdapter; |
|
41 |
import org.eclipse.swt.events.SelectionEvent; |
|
33 |
import org.eclipse.swt.dnd.DND; |
|
34 |
import org.eclipse.swt.dnd.Transfer; |
|
35 |
import org.eclipse.swt.layout.FillLayout; |
|
42 | 36 |
import org.eclipse.swt.widgets.Composite; |
43 |
import org.eclipse.swt.widgets.Text; |
|
44 | 37 |
import org.eclipse.ui.IMemento; |
45 | 38 |
|
46 | 39 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
... | ... | |
49 | 42 |
import eu.etaxonomy.cdm.model.description.FeatureNode; |
50 | 43 |
import eu.etaxonomy.cdm.model.description.FeatureTree; |
51 | 44 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
45 |
import eu.etaxonomy.taxeditor.editor.definedterm.TermTransfer; |
|
46 |
import eu.etaxonomy.taxeditor.featuretree.FeatureNodeTransfer; |
|
47 |
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeContentProvider; |
|
48 |
import eu.etaxonomy.taxeditor.featuretree.FeatureTreeLabelProvider; |
|
52 | 49 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
53 | 50 |
import eu.etaxonomy.taxeditor.model.IContextListener; |
51 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
54 | 52 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
55 | 53 |
import eu.etaxonomy.taxeditor.model.IPartContentHasSupplementalData; |
56 | 54 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
57 | 55 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
58 | 56 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
59 |
import eu.etaxonomy.taxeditor.ui.dialog.selection.FeatureTreeSelectionDialog; |
|
60 | 57 |
import eu.etaxonomy.taxeditor.workbench.part.IE4SavablePart; |
61 | 58 |
import eu.etaxonomy.taxeditor.workbench.part.IE4ViewerPart; |
62 | 59 |
|
... | ... | |
66 | 63 |
* @date 06.06.2017 |
67 | 64 |
* |
68 | 65 |
*/ |
69 |
public class FeatureTreeEditor implements ICdmEntitySessionEnabled, ModifyListener, ISelectionChangedListener, |
|
70 |
IE4ViewerPart, IE4SavablePart, IPartContentHasDetails, IPartContentHasSupplementalData, IContextListener, IConversationEnabled { |
|
66 |
public class FeatureTreeEditor implements ICdmEntitySessionEnabled, ISelectionChangedListener, |
|
67 |
IE4ViewerPart, IE4SavablePart, IPartContentHasDetails, IPartContentHasSupplementalData, |
|
68 |
IContextListener, IConversationEnabled, IDirtyMarkable { |
|
71 | 69 |
|
72 | 70 |
private ConversationHolder conversation; |
73 | 71 |
|
... | ... | |
79 | 77 |
@Inject |
80 | 78 |
private MDirtyable dirty; |
81 | 79 |
|
82 |
private FeatureTreeEditorComposite composite; |
|
80 |
// private FeatureTreeEditorComposite composite;
|
|
83 | 81 |
|
84 | 82 |
@Inject |
85 | 83 |
private MPart thisPart; |
86 | 84 |
|
85 |
private TreeViewer viewer; |
|
86 |
|
|
87 | 87 |
@Inject |
88 | 88 |
public FeatureTreeEditor() { |
89 | 89 |
CdmStore.getContextManager().addContextListener(this); |
... | ... | |
98 | 98 |
else{ |
99 | 99 |
return; |
100 | 100 |
} |
101 |
composite = new FeatureTreeEditorComposite(parent, SWT.NULL); |
|
102 |
composite.init(new FeatureNodeDragListener(composite.getViewer()), |
|
103 |
new FeatureNodeDropAdapter(dirty, composite.getViewer()), this, new SelectionAdapter() { |
|
104 |
@Override |
|
105 |
public void widgetSelected(SelectionEvent e) { |
|
106 |
if(isDirty()){ |
|
107 |
MessageDialog dialog; |
|
108 |
String[] buttonLables = {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; |
|
109 |
dialog = new MessageDialog(null, "Unsaved changes", null, "You have unsaved changes. Do you want to save?", |
|
110 |
MessageDialog.QUESTION_WITH_CANCEL, 0, buttonLables); |
|
111 |
int returnCode = dialog.open(); |
|
112 |
|
|
113 |
if (returnCode == 0){ |
|
114 |
//YES |
|
115 |
save(new NullProgressMonitor()); |
|
116 |
} else if (returnCode == 1){ |
|
117 |
//NO |
|
118 |
if(CdmStore.isActive()){ |
|
119 |
clearSession(); |
|
120 |
initSession(); |
|
121 |
composite.setSelectedTree(null); |
|
122 |
} |
|
123 |
} else if (returnCode == 2){ |
|
124 |
//CANCEL |
|
125 |
return; |
|
126 |
} |
|
127 |
} |
|
128 |
FeatureTree tree = FeatureTreeSelectionDialog.select(composite.getDisplay().getActiveShell(), //conversation, |
|
129 |
null); |
|
130 |
if (tree != null) { |
|
131 |
composite.setSelectedTree(tree); |
|
132 |
} |
|
133 |
} |
|
134 |
}, this); |
|
101 |
parent.setLayout(new FillLayout()); |
|
102 |
viewer = new TreeViewer(parent); |
|
103 |
viewer.setContentProvider(new FeatureTreeContentProvider()); |
|
104 |
viewer.setLabelProvider(new FeatureTreeLabelProvider()); |
|
105 |
|
|
106 |
int ops = DND.DROP_COPY | DND.DROP_MOVE; |
|
107 |
Transfer[] transfers = new Transfer[] { FeatureNodeTransfer |
|
108 |
.getInstance(), TermTransfer.getInstance() }; |
|
109 |
viewer.addDragSupport(ops, transfers, new FeatureNodeDragListener(viewer)); |
|
110 |
viewer.addDropSupport(ops, transfers, new FeatureNodeDropAdapter(dirty, viewer)); |
|
111 |
viewer.addSelectionChangedListener(this); |
|
112 |
|
|
113 |
List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null); |
|
114 |
viewer.setInput(trees); |
|
115 |
|
|
116 |
// composite = new FeatureTreeEditorComposite(parent, SWT.NULL); |
|
117 |
// composite.init(new FeatureNodeDragListener(composite.getViewer()), |
|
118 |
// new FeatureNodeDropAdapter(dirty, composite.getViewer()), this, new SelectionAdapter() { |
|
119 |
// @Override |
|
120 |
// public void widgetSelected(SelectionEvent e) { |
|
121 |
// if(isDirty()){ |
|
122 |
// MessageDialog dialog; |
|
123 |
// String[] buttonLables = {IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL}; |
|
124 |
// dialog = new MessageDialog(null, "Unsaved changes", null, "You have unsaved changes. Do you want to save?", |
|
125 |
// MessageDialog.QUESTION_WITH_CANCEL, 0, buttonLables); |
|
126 |
// int returnCode = dialog.open(); |
|
127 |
// |
|
128 |
// if (returnCode == 0){ |
|
129 |
// //YES |
|
130 |
// save(new NullProgressMonitor()); |
|
131 |
// } else if (returnCode == 1){ |
|
132 |
// //NO |
|
133 |
// if(CdmStore.isActive()){ |
|
134 |
// clearSession(); |
|
135 |
// initSession(); |
|
136 |
// composite.setSelectedTree(null); |
|
137 |
// } |
|
138 |
// } else if (returnCode == 2){ |
|
139 |
// //CANCEL |
|
140 |
// return; |
|
141 |
// } |
|
142 |
// } |
|
143 |
// FeatureTree tree = FeatureTreeSelectionDialog.select(composite.getDisplay().getActiveShell(), //conversation, |
|
144 |
// null); |
|
145 |
// if (tree != null) { |
|
146 |
// composite.setSelectedTree(tree); |
|
147 |
// } |
|
148 |
// } |
|
149 |
// }, this); |
|
135 | 150 |
|
136 | 151 |
//create context menu |
137 |
menuService.registerContextMenu(composite.getViewer().getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor");
|
|
152 |
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor");
|
|
138 | 153 |
} |
139 | 154 |
|
140 | 155 |
private void initSession(){ |
... | ... | |
166 | 181 |
return dirty.isDirty(); |
167 | 182 |
} |
168 | 183 |
|
169 |
public FeatureTree getSelectedFeatureTree(){ |
|
170 |
return composite.getFeatureTree(); |
|
171 |
} |
|
172 |
|
|
173 |
/** {@inheritDoc} */ |
|
174 |
@Override |
|
175 |
public void modifyText(ModifyEvent e) { |
|
176 |
composite.getFeatureTree().setTitleCache(((Text) e.widget).getText(), true); |
|
177 |
setDirty(true); |
|
178 |
} |
|
179 |
|
|
180 | 184 |
/** {@inheritDoc} */ |
181 | 185 |
@Override |
182 | 186 |
public void selectionChanged(SelectionChangedEvent event) { |
... | ... | |
186 | 190 |
|
187 | 191 |
@Focus |
188 | 192 |
public void focus(){ |
189 |
if(composite!=null){
|
|
190 |
composite.getViewer().getControl().setFocus();
|
|
193 |
if(viewer!=null){
|
|
194 |
viewer.getControl().setFocus();
|
|
191 | 195 |
} |
192 | 196 |
if(conversation!=null && !conversation.isBound()){ |
193 | 197 |
conversation.bind(); |
... | ... | |
199 | 203 |
|
200 | 204 |
@Override |
201 | 205 |
public void refresh(){ |
202 |
composite.getViewer().refresh();
|
|
206 |
viewer.refresh();
|
|
203 | 207 |
} |
204 | 208 |
|
205 | 209 |
public TreeViewer getViewer(){ |
206 |
return composite.getViewer();
|
|
210 |
return viewer;
|
|
207 | 211 |
} |
208 | 212 |
|
209 | 213 |
/** |
... | ... | |
211 | 215 |
*/ |
212 | 216 |
@Override |
213 | 217 |
public IStructuredSelection getSelection() { |
214 |
return (IStructuredSelection) composite.getViewer().getSelection();
|
|
218 |
return (IStructuredSelection) viewer.getSelection();
|
|
215 | 219 |
} |
216 | 220 |
|
217 | 221 |
/** |
... | ... | |
232 | 236 |
// commit the conversation and start a new transaction immediately |
233 | 237 |
conversation.commit(true); |
234 | 238 |
|
235 |
CdmStore.getService(IFeatureTreeService.class).saveOrUpdate(composite.getFeatureTree()); |
|
239 |
List<FeatureTree> trees = (List<FeatureTree>) viewer.getInput(); |
|
240 |
CdmStore.getService(IFeatureTreeService.class).merge(trees); |
|
236 | 241 |
|
237 | 242 |
this.setDirty(false); |
238 | 243 |
} |
... | ... | |
265 | 270 |
*/ |
266 | 271 |
@Override |
267 | 272 |
public List<FeatureTree> getRootEntities() { |
268 |
List<FeatureTree> root = new ArrayList<>(); |
|
269 |
root.add(composite.getFeatureTree()); |
|
270 |
return root; |
|
273 |
return (List<FeatureTree>) viewer.getInput(); |
|
271 | 274 |
} |
272 | 275 |
|
273 | 276 |
/** |
... | ... | |
319 | 322 |
public void update(CdmDataChangeMap arg0) { |
320 | 323 |
} |
321 | 324 |
|
325 |
/** |
|
326 |
* {@inheritDoc} |
|
327 |
*/ |
|
328 |
@Override |
|
329 |
public void changed(Object element) { |
|
330 |
dirty.setDirty(true); |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* {@inheritDoc} |
|
335 |
*/ |
|
336 |
@Override |
|
337 |
public void forceDirty() { |
|
338 |
dirty.setDirty(true); |
|
339 |
} |
|
340 |
|
|
322 | 341 |
} |
Also available in: Unified diff
ref #6746 Add details view for feature tree and feature node