Revision 82ef24f3
Added by Patrick Plitzner over 8 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/DerivateView.java | ||
---|---|---|
17 | 17 |
import org.eclipse.jface.viewers.AbstractTreeViewer; |
18 | 18 |
import org.eclipse.jface.viewers.ISelection; |
19 | 19 |
import org.eclipse.jface.viewers.ISelectionChangedListener; |
20 |
import org.eclipse.jface.viewers.IStructuredSelection; |
|
20 | 21 |
import org.eclipse.jface.viewers.SelectionChangedEvent; |
21 | 22 |
import org.eclipse.jface.viewers.StructuredSelection; |
22 | 23 |
import org.eclipse.jface.viewers.TreeNode; |
... | ... | |
31 | 32 |
import org.eclipse.swt.widgets.Control; |
32 | 33 |
import org.eclipse.swt.widgets.Menu; |
33 | 34 |
import org.eclipse.swt.widgets.Tree; |
34 |
import org.eclipse.ui.IEditorInput; |
|
35 | 35 |
import org.eclipse.ui.IEditorPart; |
36 |
import org.eclipse.ui.IEditorSite; |
|
37 |
import org.eclipse.ui.PartInitException; |
|
38 |
import org.eclipse.ui.part.EditorPart; |
|
36 |
import org.eclipse.ui.ISaveablePart2; |
|
37 |
import org.eclipse.ui.IWorkbenchPart; |
|
39 | 38 |
|
40 | 39 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
41 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
42 | 40 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
43 | 41 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
44 | 42 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
... | ... | |
46 | 44 |
import eu.etaxonomy.cdm.model.molecular.SingleRead; |
47 | 45 |
import eu.etaxonomy.cdm.model.occurrence.FieldUnit; |
48 | 46 |
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase; |
47 |
import eu.etaxonomy.cdm.model.taxon.Taxon; |
|
49 | 48 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
50 | 49 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
51 | 50 |
import eu.etaxonomy.taxeditor.editor.Messages; |
52 | 51 |
import eu.etaxonomy.taxeditor.editor.view.derivate.searchFilter.DerivateSearchCompositeController; |
53 |
import eu.etaxonomy.taxeditor.model.IDirtyMarkable; |
|
54 | 52 |
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails; |
55 | 53 |
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData; |
56 | 54 |
import eu.etaxonomy.taxeditor.model.IPartContentHasMedia; |
... | ... | |
59 | 57 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
60 | 58 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
61 | 59 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
60 |
import eu.etaxonomy.taxeditor.view.AbstractCdmViewPart; |
|
62 | 61 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateContentProvider; |
63 | 62 |
import eu.etaxonomy.taxeditor.view.derivateSearch.DerivateLabelProvider; |
64 | 63 |
|
... | ... | |
66 | 65 |
* Displays the derivate hierarchy of the specimen specified in the editor input. |
67 | 66 |
* |
68 | 67 |
*/ |
69 |
public class DerivateView extends EditorPart implements IPartContentHasFactualData, IDirtyMarkable,
|
|
70 |
IConversationEnabled, IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia,
|
|
68 |
public class DerivateView extends AbstractCdmViewPart implements IPartContentHasFactualData, ISaveablePart2,
|
|
69 |
IPartContentHasDetails, IPartContentHasSupplementalData, IPartContentHasMedia, |
|
71 | 70 |
|
72 | 71 |
ISelectionChangedListener, IPostOperationEnabled, ICdmEntitySessionEnabled{ |
73 | 72 |
public static final String ID = "eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView"; //$NON-NLS-1$ |
... | ... | |
123 | 122 |
|
124 | 123 |
private ICdmEntitySession cdmEntitySession; |
125 | 124 |
|
125 |
/** |
|
126 |
* <code>true</code> if this view is listening to selection changes |
|
127 |
*/ |
|
128 |
private boolean listenToSelectionChange; |
|
129 |
|
|
126 | 130 |
/** |
127 | 131 |
* Default constructor |
128 | 132 |
*/ |
129 | 133 |
public DerivateView() { |
134 |
this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>(); |
|
135 |
this.rootElements = new HashSet<SpecimenOrObservationBase<?>>(); |
|
136 |
|
|
137 |
if (CdmStore.isActive() && conversation == null) { |
|
138 |
conversation = CdmStore.createConversation(); |
|
139 |
} |
|
140 |
if (CdmStore.isActive()) { |
|
141 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
142 |
} |
|
130 | 143 |
} |
131 | 144 |
|
132 | 145 |
@Override |
... | ... | |
173 | 186 |
labelProvider.setMultiLinkSingleReads(multiLinkSingleReads); |
174 | 187 |
|
175 | 188 |
//init tree |
176 |
DerivateViewEditorInput editorInput = (DerivateViewEditorInput) getEditorInput(); |
|
177 |
if(editorInput.getDerivativeUUIDs()!=null){ |
|
178 |
updateRootEntities(editorInput.getDerivativeUUIDs()); |
|
179 |
} |
|
180 |
else{ |
|
181 |
updateRootEntities(); |
|
182 |
} |
|
189 |
updateRootEntities(); |
|
183 | 190 |
|
184 | 191 |
//add drag'n'drop support |
185 | 192 |
Transfer[] transfers = new Transfer[] {LocalSelectionTransfer.getTransfer(),}; |
... | ... | |
221 | 228 |
@Override |
222 | 229 |
public void doSave(IProgressMonitor monitor) { |
223 | 230 |
String taskName = Messages.DerivateView_SAVING_HIERARCHY; |
224 |
if(getEditorInput() instanceof DerivateViewEditorInput){ |
|
225 |
DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput(); |
|
226 |
taskName += " "+derivateViewEditorInput.getName(); //$NON-NLS-1$ |
|
227 |
} |
|
228 | 231 |
monitor.beginTask(taskName, 3); |
229 | 232 |
if (!conversation.isBound()) { |
230 | 233 |
conversation.bind(); |
... | ... | |
256 | 259 |
|
257 | 260 |
@Override |
258 | 261 |
public String getTitleToolTip() { |
259 |
if(getEditorInput() instanceof DerivateViewEditorInput){ |
|
260 |
DerivateViewEditorInput derivateViewEditorInput = (DerivateViewEditorInput) getEditorInput(); |
|
261 |
return derivateViewEditorInput.getName(); |
|
262 |
} |
|
263 | 262 |
return Messages.DerivateView_DERIVATIVE_EDITOR; |
264 | 263 |
} |
265 | 264 |
|
266 |
@Override |
|
267 |
public void init(IEditorSite site, IEditorInput input) throws PartInitException { |
|
268 |
setSite(site); |
|
269 |
setInput(input); |
|
270 |
this.derivateToRootEntityMap = new HashMap<SpecimenOrObservationBase<?>, SpecimenOrObservationBase<?>>(); |
|
271 |
this.rootElements = new HashSet<SpecimenOrObservationBase<?>>(); |
|
272 |
|
|
273 |
if (CdmStore.isActive() && conversation == null) { |
|
274 |
conversation = CdmStore.createConversation(); |
|
275 |
} |
|
276 |
if (CdmStore.isActive()) { |
|
277 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 | 265 |
@Override |
282 | 266 |
public boolean isDirty() { |
283 | 267 |
return isDirty; |
... | ... | |
319 | 303 |
/** |
320 | 304 |
* @return the viewer |
321 | 305 |
*/ |
306 |
@Override |
|
322 | 307 |
public TreeViewer getViewer() { |
323 | 308 |
return viewer; |
324 | 309 |
} |
... | ... | |
335 | 320 |
changed(null); |
336 | 321 |
} |
337 | 322 |
|
338 |
@Override |
|
339 |
public Set<SpecimenOrObservationBase<?>> getRootEntities() { |
|
340 |
return rootElements; |
|
341 |
} |
|
342 |
|
|
343 | 323 |
@Override |
344 | 324 |
public Map<Object, List<String>> getPropertyPathsMap() { |
345 | 325 |
List<String> specimenPropertyPaths = Arrays.asList(new String[] { |
... | ... | |
462 | 442 |
cdmEntitySession.dispose(); |
463 | 443 |
} |
464 | 444 |
} |
445 |
|
|
446 |
@Override |
|
447 |
public void selectionChanged(IWorkbenchPart part, ISelection selection) { |
|
448 |
if(listenToSelectionChange && selection instanceof IStructuredSelection){ |
|
449 |
Object selectedElement = ((IStructuredSelection) selection).getFirstElement(); |
|
450 |
if(selectedElement instanceof Taxon){ |
|
451 |
Collection<SpecimenOrObservationBase> fieldUnits = CdmStore.getService(IOccurrenceService.class).listFieldUnitsByAssociatedTaxon((Taxon) selectedElement, null, null); |
|
452 |
viewer.setInput(fieldUnits); |
|
453 |
} |
|
454 |
} |
|
455 |
} |
|
456 |
|
|
457 |
@Override |
|
458 |
public void createViewer(Composite parent) { |
|
459 |
// TODO Auto-generated method stub |
|
460 |
|
|
461 |
} |
|
462 |
|
|
463 |
@Override |
|
464 |
public boolean isSaveOnCloseNeeded() { |
|
465 |
return isDirty(); |
|
466 |
} |
|
467 |
|
|
468 |
@Override |
|
469 |
public int promptToSaveOnClose() { |
|
470 |
return ISaveablePart2.DEFAULT; |
|
471 |
} |
|
472 |
|
|
473 |
public void toggleListenToSelectionChange() { |
|
474 |
listenToSelectionChange = !listenToSelectionChange; |
|
475 |
} |
|
465 | 476 |
} |
Also available in: Unified diff
Listen to selection changes in DerivativeEditor