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 if(descriptiveDataSetUuid
!=null){
100 EditorUtil
.openDescriptiveDataSetEditor(descriptiveDataSetUuid
.getUuid(), modelService
, partService
, application
);
106 //propagate selection
107 selectionChangedListener
= (event
-> selService
.setSelection(event
.getSelection()));
108 viewer
.addSelectionChangedListener(selectionChangedListener
);
110 //create context menu
111 menuService
.registerContextMenu(viewer
.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.descriptiveDataSetNavigator"); //$NON-NLS-1$
117 if (CdmStore
.isActive()){
118 if(conversation
== null) {
119 conversation
= CdmStore
.createConversation();
121 if(cdmEntitySession
== null){
122 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
124 descriptiveDataSets
= CdmStore
.getService(IDescriptiveDataSetService
.class).list(DescriptiveDataSet
.class, null, null, null, null);
125 viewer
.setInput(descriptiveDataSets
);
129 public void addDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet
){
130 descriptiveDataSets
.add(descriptiveDataSetSet
);
134 public void removeDescriptiveDataSet(DescriptiveDataSet descriptiveDataSetSet
){
135 descriptiveDataSets
.remove(descriptiveDataSetSet
);
139 public void refresh(){
143 public void refresh(boolean reloadDescriptiveDataSets
){
144 if(reloadDescriptiveDataSets
){
145 cdmEntitySession
.dispose();
146 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
147 IDescriptiveDataSetService service
= CdmStore
.getService(IDescriptiveDataSetService
.class);
148 descriptiveDataSets
= service
.list(DescriptiveDataSet
.class, null, null, null, null);
150 viewer
.setInput(descriptiveDataSets
);
158 public void update(CdmDataChangeMap arg0
) {
165 public ICdmEntitySession
getCdmEntitySession() {
166 return cdmEntitySession
;
173 public <T
extends CdmBase
> Collection
<T
> getRootEntities() {
181 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
189 public ConversationHolder
getConversationHolder() {
195 public void dispose() {
196 if (conversation
!= null) {
197 conversation
.close();
200 if(cdmEntitySession
!= null) {
201 cdmEntitySession
.dispose();
202 cdmEntitySession
= null;
208 public void setFocus() {
209 if (getConversationHolder() != null) {
210 getConversationHolder().bind();
212 if(cdmEntitySession
!= null) {
213 cdmEntitySession
.bind();
221 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
222 // TODO Auto-generated method stub
230 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
237 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
238 if(viewer
!=null && viewer
.getControl()!=null && !viewer
.getControl().isDisposed()){
247 public void contextRefresh(IProgressMonitor monitor
) {
254 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {