2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.featuretree
.e4
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Arrays
;
14 import java
.util
.HashMap
;
15 import java
.util
.List
;
18 import javax
.annotation
.PostConstruct
;
19 import javax
.annotation
.PreDestroy
;
20 import javax
.inject
.Inject
;
22 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
23 import org
.eclipse
.core
.runtime
.NullProgressMonitor
;
24 import org
.eclipse
.e4
.ui
.di
.Focus
;
25 import org
.eclipse
.e4
.ui
.di
.Persist
;
26 import org
.eclipse
.e4
.ui
.model
.application
.ui
.MDirtyable
;
27 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
28 import org
.eclipse
.e4
.ui
.services
.EMenuService
;
29 import org
.eclipse
.e4
.ui
.workbench
.modeling
.EPartService
;
30 import org
.eclipse
.e4
.ui
.workbench
.modeling
.ESelectionService
;
31 import org
.eclipse
.jface
.viewers
.ISelectionChangedListener
;
32 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
33 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
34 import org
.eclipse
.jface
.viewers
.TreeViewer
;
35 import org
.eclipse
.swt
.SWT
;
36 import org
.eclipse
.swt
.events
.ModifyEvent
;
37 import org
.eclipse
.swt
.events
.ModifyListener
;
38 import org
.eclipse
.swt
.events
.SelectionAdapter
;
39 import org
.eclipse
.swt
.events
.SelectionEvent
;
40 import org
.eclipse
.swt
.widgets
.Composite
;
41 import org
.eclipse
.ui
.IMemento
;
43 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
44 import eu
.etaxonomy
.cdm
.api
.conversation
.IConversationEnabled
;
45 import eu
.etaxonomy
.cdm
.api
.service
.IFeatureTreeService
;
46 import eu
.etaxonomy
.cdm
.model
.description
.FeatureNode
;
47 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
48 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.CdmDataChangeMap
;
49 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
50 import eu
.etaxonomy
.taxeditor
.model
.IContextListener
;
51 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasDetails
;
52 import eu
.etaxonomy
.taxeditor
.model
.IPartContentHasSupplementalData
;
53 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
54 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySession
;
55 import eu
.etaxonomy
.taxeditor
.session
.ICdmEntitySessionEnabled
;
56 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
57 import eu
.etaxonomy
.taxeditor
.ui
.dialog
.selection
.FeatureTreeSelectionDialog
;
58 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4SavablePart
;
59 import eu
.etaxonomy
.taxeditor
.workbench
.part
.IE4ViewerPart
;
67 public class FeatureTreeEditor
implements ICdmEntitySessionEnabled
, ModifyListener
, ISelectionChangedListener
,
68 IE4ViewerPart
, IE4SavablePart
, IPartContentHasDetails
, IPartContentHasSupplementalData
, IContextListener
, IConversationEnabled
{
70 private ConversationHolder conversation
;
72 private ICdmEntitySession cdmEntitySession
;
75 private ESelectionService selService
;
78 private MDirtyable dirty
;
80 private FeatureTreeEditorComposite composite
;
83 private MPart thisPart
;
86 public FeatureTreeEditor() {
87 CdmStore
.getContextManager().addContextListener(this);
92 public void createControl(Composite parent
, EMenuService menuService
){
93 if (CdmStore
.isActive()){
94 if(conversation
== null){
95 conversation
= CdmStore
.createConversation();
97 if(cdmEntitySession
!=null){
98 cdmEntitySession
= CdmStore
.getCurrentSessionManager().newSession(this, true);
104 composite
= new FeatureTreeEditorComposite(parent
, SWT
.NULL
);
105 composite
.init(new FeatureNodeDragListener(composite
.getViewer()),
106 new FeatureNodeDropAdapter(dirty
, composite
.getViewer()), this, new SelectionAdapter() {
108 public void widgetSelected(SelectionEvent e
) {
110 if(MessagingUtils
.confirmDialog("Editor has to be saved", "You have to save before loading another feature tree. Save now?")){
111 save(new NullProgressMonitor());
118 FeatureTree tree
= FeatureTreeSelectionDialog
.select(composite
.getDisplay().getActiveShell(), conversation
, null);
120 composite
.setSelectedTree(tree
, FeatureTreeEditor
.this);
125 //create context menu
126 menuService
.registerContextMenu(composite
.getViewer().getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor");
129 public void setDirty(boolean isDirty
){
130 this.dirty
.setDirty(isDirty
);
133 public boolean isDirty(){
134 return dirty
.isDirty();
137 public FeatureTree
getSelectedFeatureTree(){
138 return composite
.getFeatureTree();
143 public void modifyText(ModifyEvent e
) {
144 composite
.getFeatureTree().setTitleCache(composite
.getText_title().getText(), true);
150 public void selectionChanged(SelectionChangedEvent event
) {
151 //propagate selection
152 selService
.setSelection(AbstractUtility
.getElementsFromSelectionChangedEvent(event
));
158 composite
.getViewer().getControl().setFocus();
160 if(conversation
!=null && !conversation
.isBound()){
163 if(cdmEntitySession
!= null) {
164 cdmEntitySession
.bind();
169 public void refresh(){
170 composite
.getViewer().refresh();
173 public TreeViewer
getViewer(){
174 return composite
.getViewer();
181 public IStructuredSelection
getSelection() {
182 return (IStructuredSelection
) composite
.getViewer().getSelection();
189 public ConversationHolder
getConversationHolder() {
195 public void save(IProgressMonitor monitor
){
196 if (!conversation
.isBound()) {
200 // commit the conversation and start a new transaction immediately
201 conversation
.commit(true);
203 CdmStore
.getService(IFeatureTreeService
.class).saveOrUpdate(composite
.getFeatureTree());
205 this.setDirty(false);
209 public void dispose(){
210 if(conversation
!=null){
211 conversation
.close();
213 if(cdmEntitySession
!= null) {
214 cdmEntitySession
.dispose();
219 public ICdmEntitySession
getCdmEntitySession() {
220 return cdmEntitySession
;
224 public Map
<Object
, List
<String
>> getPropertyPathsMap() {
225 List
<String
> propertyPaths
= Arrays
.asList(new String
[] {
226 "children", //$NON-NLS-1$
227 "feature", //$NON-NLS-1$
228 "featureTree", //$NON-NLS-1$
230 Map
<Object
, List
<String
>> propertyPathMap
=
231 new HashMap
<Object
, List
<String
>>();
232 propertyPathMap
.put(FeatureNode
.class,propertyPaths
);
233 return propertyPathMap
;
240 public List
<FeatureTree
> getRootEntities() {
241 List
<FeatureTree
> root
= new ArrayList
<>();
242 root
.add(composite
.getFeatureTree());
250 public void contextAboutToStop(IMemento memento
, IProgressMonitor monitor
) {
257 public void contextStop(IMemento memento
, IProgressMonitor monitor
) {
258 //close view when workbench closes
260 thisPart
.getContext().get(EPartService
.class).hidePart(thisPart
);
271 public void contextStart(IMemento memento
, IProgressMonitor monitor
) {
278 public void contextRefresh(IProgressMonitor monitor
) {
285 public void workbenchShutdown(IMemento memento
, IProgressMonitor monitor
) {
292 public void update(CdmDataChangeMap arg0
) {