Revision 72a04ac6
Added by Patrick Plitzner over 6 years ago
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/workingSet/WorkingSetNavigator.java | ||
---|---|---|
9 | 9 |
*/ |
10 | 10 |
package eu.etaxonomy.taxeditor.editor.workingSet; |
11 | 11 |
|
12 |
import java.util.Collection; |
|
12 | 13 |
import java.util.List; |
14 |
import java.util.Map; |
|
13 | 15 |
|
14 | 16 |
import javax.annotation.PostConstruct; |
17 |
import javax.annotation.PreDestroy; |
|
15 | 18 |
import javax.inject.Inject; |
16 | 19 |
|
20 |
import org.eclipse.e4.ui.di.Focus; |
|
17 | 21 |
import org.eclipse.e4.ui.model.application.MApplication; |
18 | 22 |
import org.eclipse.e4.ui.services.EMenuService; |
19 | 23 |
import org.eclipse.e4.ui.workbench.modeling.EModelService; |
... | ... | |
28 | 32 |
import org.eclipse.jface.viewers.ListViewer; |
29 | 33 |
import org.eclipse.swt.widgets.Composite; |
30 | 34 |
|
35 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
|
36 |
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled; |
|
31 | 37 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService; |
38 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
32 | 39 |
import eu.etaxonomy.cdm.model.description.WorkingSet; |
33 | 40 |
import eu.etaxonomy.cdm.persistence.dto.UuidAndTitleCache; |
41 |
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap; |
|
34 | 42 |
import eu.etaxonomy.taxeditor.editor.EditorUtil; |
35 | 43 |
import eu.etaxonomy.taxeditor.model.AbstractUtility; |
44 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySession; |
|
45 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled; |
|
36 | 46 |
import eu.etaxonomy.taxeditor.store.CdmStore; |
37 | 47 |
import eu.etaxonomy.taxeditor.ui.UuidAndTitleCacheLabelProvider; |
38 | 48 |
|
... | ... | |
41 | 51 |
* @date 12.12.2017 |
42 | 52 |
* |
43 | 53 |
*/ |
44 |
public class WorkingSetNavigator { |
|
54 |
public class WorkingSetNavigator implements IConversationEnabled, ICdmEntitySessionEnabled{
|
|
45 | 55 |
|
46 | 56 |
private ListViewer viewer; |
47 | 57 |
|
... | ... | |
50 | 60 |
|
51 | 61 |
private ISelectionChangedListener selectionChangedListener; |
52 | 62 |
|
63 |
private ConversationHolder conversation; |
|
64 |
|
|
65 |
private ICdmEntitySession cdmEntitySession; |
|
66 |
|
|
67 |
private List<UuidAndTitleCache<WorkingSet>> workingSets; |
|
68 |
|
|
53 | 69 |
@PostConstruct |
54 | 70 |
public void create(Composite parent, EPartService partService, EModelService modelService, MApplication application, |
55 | 71 |
EMenuService menuService){ |
72 |
if (CdmStore.isActive()){ |
|
73 |
if(conversation == null){ |
|
74 |
conversation = CdmStore.createConversation(); |
|
75 |
} |
|
76 |
if(cdmEntitySession == null){ |
|
77 |
cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true); |
|
78 |
} |
|
79 |
} |
|
80 |
else{ |
|
81 |
return; |
|
82 |
} |
|
56 | 83 |
viewer = new ListViewer(parent); |
57 | 84 |
viewer.setContentProvider(new ArrayContentProvider()); |
58 | 85 |
viewer.setLabelProvider(new UuidAndTitleCacheLabelProvider()); |
59 |
List<UuidAndTitleCache<WorkingSet>> workingSets = CdmStore.getService(IWorkingSetService.class).getUuidAndTitleCache(null, null);
|
|
86 |
workingSets = CdmStore.getService(IWorkingSetService.class).getUuidAndTitleCache(null, null); |
|
60 | 87 |
viewer.setInput(workingSets); |
61 | 88 |
|
62 | 89 |
viewer.addDoubleClickListener(new IDoubleClickListener() { |
... | ... | |
79 | 106 |
menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.editor.popupmenu.workingSetNavigator"); |
80 | 107 |
} |
81 | 108 |
|
109 |
public void addWorkingSet(WorkingSet workingSet){ |
|
110 |
workingSets.add(new UuidAndTitleCache<>(workingSet.getUuid(), workingSet.getTitleCache())); |
|
111 |
refresh(); |
|
112 |
} |
|
113 |
|
|
114 |
public void removeWorkingSet(UuidAndTitleCache<WorkingSet> workingSet){ |
|
115 |
workingSets.remove(workingSet); |
|
116 |
refresh(); |
|
117 |
} |
|
118 |
|
|
119 |
public void refresh(){ |
|
120 |
viewer.setInput(workingSets); |
|
121 |
viewer.refresh(); |
|
122 |
} |
|
123 |
|
|
124 |
/** |
|
125 |
* {@inheritDoc} |
|
126 |
*/ |
|
127 |
@Override |
|
128 |
public void update(CdmDataChangeMap arg0) { |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* {@inheritDoc} |
|
133 |
*/ |
|
134 |
@Override |
|
135 |
public ICdmEntitySession getCdmEntitySession() { |
|
136 |
return cdmEntitySession; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* {@inheritDoc} |
|
141 |
*/ |
|
142 |
@Override |
|
143 |
public <T extends CdmBase> Collection<T> getRootEntities() { |
|
144 |
return null; |
|
145 |
} |
|
146 |
|
|
147 |
/** |
|
148 |
* {@inheritDoc} |
|
149 |
*/ |
|
150 |
@Override |
|
151 |
public Map<Object, List<String>> getPropertyPathsMap() { |
|
152 |
return null; |
|
153 |
} |
|
154 |
|
|
155 |
/** |
|
156 |
* {@inheritDoc} |
|
157 |
*/ |
|
158 |
@Override |
|
159 |
public ConversationHolder getConversationHolder() { |
|
160 |
return conversation; |
|
161 |
} |
|
162 |
|
|
163 |
/** {@inheritDoc} */ |
|
164 |
@PreDestroy |
|
165 |
public void dispose() { |
|
166 |
if (conversation != null) { |
|
167 |
conversation.close(); |
|
168 |
conversation = null; |
|
169 |
} |
|
170 |
if(cdmEntitySession != null) { |
|
171 |
cdmEntitySession.dispose(); |
|
172 |
cdmEntitySession = null; |
|
173 |
} |
|
174 |
} |
|
175 |
|
|
176 |
/** {@inheritDoc} */ |
|
177 |
@Focus |
|
178 |
public void setFocus() { |
|
179 |
if (getConversationHolder() != null) { |
|
180 |
getConversationHolder().bind(); |
|
181 |
} |
|
182 |
if(cdmEntitySession != null) { |
|
183 |
cdmEntitySession.bind(); |
|
184 |
} |
|
185 |
} |
|
186 |
|
|
82 | 187 |
} |
Also available in: Unified diff
ref #7086, #7095 Add create/delete handler to WS navigator