ref #6774 session handling and minor refactoring
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / featuretree / e4 / FeatureTreeEditor.java
index 158f1c29a812feb702e131795a67358d56e7b239..206c69e65dceb781f00d4b3557b0f8146ab3e173 100644 (file)
@@ -77,19 +77,23 @@ public class FeatureTreeEditor implements ICdmEntitySessionEnabled,
     private FeatureTreeEditorComposite composite;
 
     @Inject
-    public FeatureTreeEditor(@Named(IServiceConstants.ACTIVE_SHELL)Shell shell) {
-        this.shell = shell;
-        if(conversation==null){
-            conversation = CdmStore.createConversation();
-        }
-        if (CdmStore.isActive()) {
-            cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
-        }
+    public FeatureTreeEditor() {
     }
 
        /** {@inheritDoc} */
     @PostConstruct
-    public void createControl(Composite parent, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
+    public void createControl(Composite parent) {
+        if (CdmStore.isActive()){
+            if(conversation == null){
+                conversation = CdmStore.createConversation();
+            }
+            if(cdmEntitySession!=null){
+                cdmEntitySession = CdmStore.getCurrentSessionManager().newSession(this, true);
+            }
+        }
+        else{
+            return;
+        }
         composite = new FeatureTreeEditorComposite(parent, SWT.NULL);
         composite.init(new FeatureNodeDragListener(composite.getViewer()),
                 new FeatureNodeDropAdapter(this, composite.getViewer()), this, new SelectionAdapter() {
@@ -129,15 +133,18 @@ public class FeatureTreeEditor implements ICdmEntitySessionEnabled,
                IStructuredSelection selection = (IStructuredSelection) event
                                .getSelection();
 
-               composite.getButton_add().setEnabled(selection.size() <= 1);
-               composite.getButton_remove().setEnabled(selection.size() > 0);
+               composite.getBtnAdd().setEnabled(selection.size() <= 1);
+               composite.getBtnRemove().setEnabled(selection.size() > 0);
                //propagate selection
                selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event));
        }
 
        @Focus
-       public void focus(){
-           composite.getViewer().getControl().setFocus();
+       public void focus(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell){
+           this.shell = shell;
+           if(composite!=null){
+               composite.getViewer().getControl().setFocus();
+           }
         if(conversation!=null && !conversation.isBound()){
             conversation.bind();
         }