Merge branch 'LibrAlign' of https://dev.e-taxonomy.eu/git/taxeditor into LibrAlign
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / view / AbstractCdmDataViewer.java
index 4fe8d8a1f358830281bff7ac53f94e096048f556..d1cef126d665a1d085788db71f32fe28535b235d 100644 (file)
@@ -1,16 +1,15 @@
 // $Id$
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* European Distributed Institute of Taxonomy
 * http://www.e-taxonomy.eu
-* 
+*
 * The contents of this file are subject to the Mozilla Public License Version 1.1
 * See LICENSE.TXT at the top of this package for the full license terms.
 */
 
 package eu.etaxonomy.taxeditor.view;
 
-import org.eclipse.jface.viewers.ISelectionProvider;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.viewers.Viewer;
 import org.eclipse.swt.widgets.Composite;
@@ -22,70 +21,57 @@ import org.eclipse.ui.forms.widgets.ScrolledForm;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
-import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
 import eu.etaxonomy.taxeditor.ui.element.RootElement;
 import eu.etaxonomy.taxeditor.view.detail.CdmSectionPart;
 
 /**
- * <p>Abstract AbstractCdmDataViewer class.</p>
- *
  * @author n.hoffmann
  * @created Feb 9, 2010
  * @version 1.0
  */
-public abstract class AbstractCdmDataViewer extends Viewer implements ISelectionProvider, IConversationEnabled{
-       
+public abstract class AbstractCdmDataViewer extends Viewer implements IConversationEnabled{
+
        protected ManagedForm managedForm;
 
        protected CdmFormFactory formFactory;
 
        protected ScrolledForm scrolledForm;
-       
-       private Composite body;
-       
+
+       private final Composite body;
+
        protected RootElement rootElement;
 
+       //TODO: create a super class for this?
        private Object input;
 
-       private AbstractCdmViewPart viewPart;
+       private final AbstractCdmViewPart viewPart;
+
 
-       
-       /**
-        * <p>Constructor for AbstractCdmDataViewer.</p>
-        *
-        * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
-        * @param viewPart a {@link eu.etaxonomy.taxeditor.view.AbstractCdmViewPart} object.
-        */
        public AbstractCdmDataViewer(Composite parent, AbstractCdmViewPart viewPart) {
                this.viewPart = viewPart;
-               
+
                managedForm = new ManagedForm(parent){
-                       
-                       /* (non-Javadoc)
-                        * @see org.eclipse.ui.forms.ManagedForm#dirtyStateChanged()
-                        */
+
                        @Override
                        public void dirtyStateChanged() {
                                markViewPartDirty();
                        }
                };
-               
+
                createFormFactory();
-               
+
                scrolledForm = managedForm.getForm();
-               
+
                body = scrolledForm.getBody();
-               
-               body.setLayout(CdmFormFactory.LAYOUT());
-               
+
+               body.setLayout(LayoutConstants.LAYOUT());
+
                rootElement = new RootElement(formFactory, body);
        }
-       
-       /**
-        * <p>createFormFactory</p>
-        */
+
        protected void createFormFactory() {
                if(formFactory != null){
                        formFactory.dispose();
@@ -97,104 +83,76 @@ public abstract class AbstractCdmDataViewer extends Viewer implements ISelection
        protected void markViewPartDirty(){
                viewPart.changed(input);
        }
-       
-       
-       /**
-        * @return
-        */
+
        protected AbstractCdmViewPart getViewPart() {
                return viewPart;
        }
 
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.Viewer#getControl()
-        */
        /** {@inheritDoc} */
        @Override
        public Control getControl() {
+               if(body.isDisposed()){
+                       return null;
+               }
                for(Control child : body.getChildren()){
                        return child;
                }
-               
+
                return body;
        }
        
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
-        */
        /** {@inheritDoc} */
        @Override
        public void setInput(Object input) {
-               this.input = input;     
+               this.input = input;
                // reset selection
                setSelection(new StructuredSelection(input));
                refresh();
        }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.Viewer#getInput()
-        */
+
        /** {@inheritDoc} */
        @Override
        public Object getInput() {
                return input;
        }
-       
-       /* (non-Javadoc)
-        * @see org.eclipse.jface.viewers.Viewer#refresh()
-        */
+
        /** {@inheritDoc} */
        @Override
        public void refresh() {
                showParts();
-               
+
                managedForm.setInput(input);
-               
+
                managedForm.refresh();
-               
+
                managedForm.reflow(true);
        }
 
-       
-       /**
-        * <p>layout</p>
-        */
        public void layout(){
                body.layout();
        }
-       
-       /**
-        * <p>showParts</p>
-        */
+
        protected abstract void showParts();
-       
-       
-       /**
-        * <p>destroySections</p>
-        */
-       protected void destroySections() {      
+
+       protected void destroySections() {
                for (IFormPart formPart : managedForm.getParts()){
-                       removePart((CdmSectionPart) formPart);
-               }       
-               
+                       removePart((CdmSectionPart<?>) formPart);
+               }
+
                managedForm.setInput(null);
-                               
+
                formFactory.destroyElement(rootElement);
-               
+
                createFormFactory();
-               
+
                rootElement = new RootElement(formFactory, body);
-               
+
                for(Control control : body.getChildren()){
                        control.dispose();
                        control = null;
                }
        }
-       
-       
-       /**
-        * <p>setFocus</p>
-        */
+
        public void setFocus(){
                // we have to set focus to a control of this viewer
                // otherwise, after opening a dialog from the details, the focus will not be
@@ -204,45 +162,25 @@ public abstract class AbstractCdmDataViewer extends Viewer implements ISelection
                        break;
                }
        }
-       
-       /**
-        * <p>reflow</p>
-        */
+
        public void reflow(){
                managedForm.reflow(true);
        }
-       
-       /**
-        * <p>removePart</p>
-        *
-        * @param sectionPart a {@link eu.etaxonomy.taxeditor.view.detail.CdmSectionPart} object.
-        */
-       protected void removePart(CdmSectionPart sectionPart){
+
+       protected void removePart(CdmSectionPart<?> sectionPart){
                managedForm.removePart(sectionPart);
                formFactory.removePropertyChangeListener(sectionPart);
        }
-       
-       /**
-        * <p>addPart</p>
-        *
-        * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
-        */
-       protected void addPart(AbstractFormSection section){
-               CdmSectionPart sectionPart = new CdmSectionPart(section);
+
+       protected void addPart(AbstractFormSection<?> section){
+               CdmSectionPart<?> sectionPart = new CdmSectionPart<>(section);
                managedForm.addPart(sectionPart);
                formFactory.addPropertyChangeListener(sectionPart);
        }
-       
-       /**
-        * <p>getConversationHolder</p>
-        *
-        * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
-        */
-       public ConversationHolder getConversationHolder() {
+
+       @Override
+    public ConversationHolder getConversationHolder() {
                return viewPart.getConversationHolder();
        }
-       
-       /** {@inheritDoc} */
-       public void update(CdmDataChangeMap changeEvents) {}
 
 }