3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
;
12 import java
.util
.Collection
;
13 import java
.util
.List
;
16 import javax
.annotation
.PostConstruct
;
17 import javax
.annotation
.PreDestroy
;
18 import javax
.inject
.Inject
;
20 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
21 import org
.eclipse
.e4
.ui
.di
.Focus
;
22 import org
.eclipse
.e4
.ui
.model
.application
.MApplication
;
23 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
24 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EModelService
;
25 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
26 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
27 import org
.eclipse
.jface
.viewers
.ArrayContentProvider
;
28 import org
.eclipse
.jface
.viewers
.DoubleClickEvent
;
29 import org
.eclipse
.jface
.viewers
.IDoubleClickListener
;
30 import org
.eclipse
.jface
.viewers
.ISelection
;
31 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
32 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
33 import org
.eclipse
.jface
.viewers
.LabelProvider
;
34 import org
.eclipse
.jface
.viewers
.ListViewer
;
35 import org
.eclipse
.swt
.widgets
.Composite
;
36 import org
.eclipse
.ui
.IMemento
;
38 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
39 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
40 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptiveDataSetService
;
41 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
43 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
44 import eu
.etaxonomy
.taxeditor
.editor
.EditorUtil
;
45 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
46 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
47 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
48 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
55 public class DescriptiveDataSetNavigator
implements IConversationEnabled
, ICdmEntitySessionEnabled
, IContextListener
{
57 private ListViewer viewer
;
60 private ESelectionService selService
;
62 private ISelectionChangedListener selectionChangedListener
;
64 private ConversationHolder conversation
;
66 private ICdmEntitySession cdmEntitySession
;
68 private List
<DescriptiveDataSet
> descriptiveDataSets
;
70 public DescriptiveDataSetNavigator() {
71 CdmStore
.getContextManager().addContextListener(this);
75 public void create(Composite parent
, EPartService partService
, EModelService modelService
, MApplication application
,
76 EMenuService menuService
){
77 viewer
= new ListViewer(parent
);
78 viewer
.setContentProvider(new ArrayContentProvider());
79 viewer
.setLabelProvider(new LabelProvider(){
84 public String
getText(Object element
) {
85 if(element
instanceof DescriptiveDataSet
){
86 return ((DescriptiveDataSet
) element
).getLabel();
88 return super.getText(element
);
92 viewer
.addDoubleClickListener(new IDoubleClickListener() {
95 public void doubleClick(DoubleClickEvent event
) {
96 ISelection selection
= event
.getSelection();
97 if(selection
instanceof IStructuredSelection
){
98 DescriptiveDataSet descriptiveDataSetUuid
= (DescriptiveDataSet
) ((IStructuredSelection
) selection
).getFirstElement();
99 EditorUtil
.openDescriptiveDataSetEditor(descriptiveDataSetUuid
.getUuid(), modelService
, partService
, application
);
104 //propagate selection
105 selectionChangedListener
= (event
-> selService
.setSelection(event
.getSelection()));
106 viewer
.addSelectionChangedListener(selectionChangedListener
);
108 //create context menu
109 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.descriptiveDataSetNavigator"); //$NON-NLS-1$
115 if (CdmStore
.isActive()){
116 if(conversation
== null) {
117 conversation
= CdmStore
.createConversation();
119 if(cdmEntitySession
== null){
120 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
122 descriptiveDataSets
= CdmStore
.getService(IDescriptiveDataSetService
.class).list(DescriptiveDataSet
.class, null, null, null, null);
123 viewer
.setInput(descriptiveDataSets
);
127 public void addDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet
){
128 descriptiveDataSets
.add(descriptiveDataSetSet
);
132 public void removeDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet
){
133 descriptiveDataSets
.remove(descriptiveDataSetSet
);
137 public void refresh(){
141 public void refresh(boolean reloadDescriptiveDataSets
){
142 if(reloadDescriptiveDataSets
){
143 cdmEntitySession
.dispose();
144 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
145 IDescriptiveDataSetService service
= CdmStore
.getService(IDescriptiveDataSetService
.class);
146 descriptiveDataSets
= service
.list(DescriptiveDataSet
.class, null, null, null, null);
148 viewer
.setInput(descriptiveDataSets
);
156 public void update(CdmDataChangeMap arg0
) {
163 public ICdmEntitySession
getCdmEntitySession() {
164 return cdmEntitySession
;
171 public <T
extends CdmBase
> Collection
<T
> getRootEntities() {
179 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
187 public ConversationHolder
getConversationHolder() {
193 public void dispose() {
194 if (conversation
!= null) {
195 conversation
.close();
198 if(cdmEntitySession
!= null) {
199 cdmEntitySession
.dispose();
200 cdmEntitySession
= null;
206 public void setFocus() {
207 if (getConversationHolder() != null) {
208 getConversationHolder().bind();
210 if(cdmEntitySession
!= null) {
211 cdmEntitySession
.bind();
219 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
220 // TODO Auto-generated method stub
228 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
235 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
236 if(viewer
!=null && viewer
.getControl()!=null && !viewer
.getControl().isDisposed()){
245 public void contextRefresh(IProgressMonitor monitor
) {
252 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {