Proof-Of-Concept TabbedPropertySheet implementation
authorn.hoffmann <n.hoffmann@localhost>
Thu, 11 Jun 2009 15:01:14 +0000 (15:01 +0000)
committern.hoffmann <n.hoffmann@localhost>
Thu, 11 Jun 2009 15:01:14 +0000 (15:01 +0000)
.gitattributes
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/AbstractTaxonEditor.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/GroupedComposite.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/editor/name/NameComposite.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/AbstractNamePropertySection.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/AuthorSection.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/EditorTabbedPropertySheetPage.java [new file with mode: 0644]
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NameOverviewSection.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NamePropertySection.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NomRefPropertySection.java
taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/TabbedPropertyPageLabelProvider.java

index a3fd018080251eb2f60461e36ea7ec0a1fe3c636..5398fe771e45a16ffbf394b6cda401d43619a712 100644 (file)
@@ -792,6 +792,7 @@ taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/Abstr
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/AnnotationSection.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/AuthorSection.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/CreatedSection.java -text
+taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/EditorTabbedPropertySheetPage.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NameOverviewSection.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NamePropertySection.java -text
 taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/NameRelationsSection.java -text
index e91eaa5f9fcc21b922c0d0535ddea457c83a4921..7b21fe6fd3dc0f492f682f52e3197fa02b04e736 100644 (file)
@@ -190,8 +190,8 @@ public abstract class AbstractTaxonEditor extends EditorPart implements IAdaptab
                        provider.setSelection(new StructuredSelection(propertySource));\r
                }\r
                \r
-               // TabbedPropertySheet stuff \r
-//             provider.setSelection(new StructuredSelection(this.selectedData));\r
+//             // FIXME TabbedPropertySheet stuff \r
+//             provider.setSelection(new StructuredSelection(this.selectedObject));\r
                \r
        }\r
        \r
@@ -264,8 +264,8 @@ public abstract class AbstractTaxonEditor extends EditorPart implements IAdaptab
                \r
                return page;\r
                \r
-               // TabbedPropertySheet stuff\r
-//             TabbedPropertySheetPage page = new TabbedPropertySheetPage(this);\r
+//             // FIXME TabbedPropertySheet stuff\r
+//             EditorTabbedPropertySheetPage page = new EditorTabbedPropertySheetPage(this);\r
 //             return page;            \r
            }\r
            \r
@@ -280,8 +280,14 @@ public abstract class AbstractTaxonEditor extends EditorPart implements IAdaptab
                managedForm.dirtyStateChanged();\r
        }\r
        \r
+       \r
+       \r
+       /*\r
+        * (non-Javadoc)\r
+        * @see org.eclipse.ui.part.WorkbenchPart#setFocus()\r
+        */\r
+       @Override\r
        public void setFocus(){\r
-\r
                Object selection;\r
                \r
                if(selectedData == null){\r
@@ -386,8 +392,19 @@ public abstract class AbstractTaxonEditor extends EditorPart implements IAdaptab
        \r
        /**\r
         * Redraws this editor\r
+        * return true on success\r
         */\r
-       public boolean redraw() {\r
+       public boolean redraw(){\r
+               return redraw(true);\r
+       }\r
+       \r
+       /**\r
+        * Redraws the editor controls\r
+        * \r
+        * @param focus if set to true the focus is set on the editor\r
+        * @return true on success\r
+        */\r
+       public boolean redraw(boolean focus) {\r
                \r
                isRedrawing = true;\r
                \r
@@ -402,7 +419,7 @@ public abstract class AbstractTaxonEditor extends EditorPart implements IAdaptab
                return true;\r
                \r
        }\r
-\r
+       \r
        public boolean getIsRedrawing() {\r
                return isRedrawing;\r
        }\r
index c84935422d1e9b0af159822d63c78764fa7a904a..341c17cde1efc3bac89e323556c5b344cc1fe7ee 100644 (file)
@@ -621,4 +621,9 @@ abstract public class GroupedComposite extends Composite implements IHasProperty
                        }\r
                }\r
        }\r
+       \r
+       public void refresh(){\r
+               // empty default implementation \r
+               // make this abstract\r
+       }\r
 } 
\ No newline at end of file
index 49d7cfff0589f618f9bc40891fd99cda80eb4e60..40ef693d7a58491cd14aa739286e9b8d03a55602 100644 (file)
@@ -261,4 +261,28 @@ public abstract class NameComposite extends GroupedComposite{
                \r
                return null;\r
        }\r
+\r
+       /* (non-Javadoc)\r
+        * @see eu.etaxonomy.taxeditor.editor.GroupedComposite#refresh()\r
+        */\r
+       @Override\r
+       public void refresh() {\r
+               super.refresh();\r
+//             initTextViewer((TaxonBase) getData());\r
+               \r
+               // FIXME this is copied from initTextViewer().\r
+               \r
+               showNameRelations();\r
+               \r
+               String text = NameUtil.getDisplayNameWithRef((TaxonBase) getData());\r
+               \r
+               if (text.length() == 0) {\r
+                       initEmptyText();\r
+               } else {\r
+                       textViewer.getTextWidget().setText(text);\r
+//                     textViewer.setCursorToEOL();\r
+               }\r
+//             calculateErrors();\r
+//             activateParser();\r
+       }       \r
 }
\ No newline at end of file
index 3a871d6da80ad4d584ef2a6ce3445165bcb96bab..93f71ee00c5dd6505e7e540d110141ee510ba1ef 100644 (file)
@@ -16,7 +16,8 @@ import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.events.MouseAdapter;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.layout.GridData;
@@ -30,9 +31,15 @@ import org.eclipse.ui.forms.widgets.Section;
 import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
 
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.GroupedComposite;
+import eu.etaxonomy.taxeditor.editor.Page;
 
 /**
  * @author n.hoffmann
@@ -40,10 +47,13 @@ import eu.etaxonomy.cdm.model.taxon.TaxonBase;
  * @version 1.0
  */
 public abstract class AbstractNamePropertySection extends
-               AbstractPropertySection {
+               AbstractPropertySection implements IConversationEnabled{
        private static final Logger logger = Logger
                        .getLogger(AbstractNamePropertySection.class);
        
+       private EditorTabbedPropertySheetPage editorPropertySheetPage;
+       
+       protected GroupedComposite groupedComposite;
        protected TaxonBase<?> taxonBase;
        protected NonViralName<?> name;
        
@@ -57,33 +67,76 @@ public abstract class AbstractNamePropertySection extends
        protected GridData layoutData;
 
 
+       /**
+        * 
+        */
+    protected ModifyListener listener = new ModifyListener() {
+        
+        public void modifyText(ModifyEvent arg0) {
+               logger.warn("element modified");
+               // TODO refresh the editor
+               EditorUtil.getActiveEditorPage(Page.NAME).setDirty();
+        }
+    };
 
+       
 
-       /* (non-Javadoc)
-        * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
+    /*
+     * (non-Javadoc)
+     * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
+     */
+    @Override
+    public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage){
+       this.createControls(parent, (EditorTabbedPropertySheetPage) tabbedPropertySheetPage);
+    }
+    
+
+       /**
+        * 
+        * @param parent
+        * @param editorPropertySheetPage
         */
-       @Override
-       public void createControls(Composite parent,
-                       TabbedPropertySheetPage tabbedPropertySheetPage) {
-               super.createControls(parent, tabbedPropertySheetPage);
+       public void createControls(Composite parent, EditorTabbedPropertySheetPage editorPropertySheetPage) {
+               // reference to the editor
+               this.editorPropertySheetPage = editorPropertySheetPage;
+               
+               super.createControls(parent, editorPropertySheetPage);
                
                layoutData = new GridData(SWT.FILL, SWT.TOP, true, false);
                
                section = getWidgetFactory().createSection(parent, ExpandableComposite.EXPANDED | ExpandableComposite.TREE_NODE | ExpandableComposite.CLIENT_INDENT);
 
-        composite = getWidgetFactory().createComposite(section);
-        section.setClient(composite);
+        Composite layoutComposite = getWidgetFactory().createComposite(section);
+        section.setClient(layoutComposite);
         
-        composite.setLayout(new GridLayout(2, false));
+        layoutComposite.setLayout(new GridLayout(1, false));
+
+               
+               Composite cacheComposite = getWidgetFactory().createComposite(layoutComposite);
+               cacheComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
+               cacheComposite.setLayout(new GridLayout(2, false));
                
-               CLabel cacheLabel = getWidgetFactory().createCLabel(composite, "Cache");
-               cacheText = getWidgetFactory().createText(composite, "");
+               cacheText = getWidgetFactory().createText(cacheComposite, "");
                cacheText.setEditable(false);
                cacheText.setLayoutData(layoutData);
                
-               CLabel editCacheButtonLabel = getWidgetFactory().createCLabel(composite, "Make Cache Editable");
-               editCacheButton = getWidgetFactory().createButton(composite, "Make Cache Editable", SWT.TOGGLE);
+               editCacheButton = getWidgetFactory().createButton(cacheComposite, "Cache Editable", SWT.TOGGLE);
                
+               editCacheButton.addMouseListener(new MouseAdapter(){
+
+                       /* (non-Javadoc)
+                        * @see org.eclipse.swt.events.MouseAdapter#mouseUp(org.eclipse.swt.events.MouseEvent)
+                        */
+                       @Override
+                       public void mouseUp(MouseEvent e) {
+                               toggleCacheEditing();
+                       }
+                       
+               });
+               
+               composite = getWidgetFactory().createComposite(layoutComposite);
+               composite.setLayoutData(layoutData);
+        composite.setLayout(new GridLayout(2, false));
        }
 
        /* (non-Javadoc)
@@ -104,20 +157,31 @@ public abstract class AbstractNamePropertySection extends
         super.setInput(part, selection);
         Assert.isTrue(selection instanceof IStructuredSelection);
         Object input = ((IStructuredSelection) selection).getFirstElement();
-        Assert.isTrue(input instanceof TaxonBase);
-        taxonBase = (TaxonBase) input;
-        name = HibernateProxyHelper.deproxy( taxonBase.getName(), NonViralName.class); 
+        Assert.isTrue(input instanceof GroupedComposite);
+
+        groupedComposite = (GroupedComposite) input;
+        taxonBase = (TaxonBase) groupedComposite.getData();
+        
+        name = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class);
        }
 
+       /**
+        * 
+        * @param parent
+        * @return
+        */
        protected Button createSearchButton(Composite parent){
-               
                Button button = getWidgetFactory().createButton(parent, "Browse", SWT.PUSH); 
-               
                button.addMouseListener( new SearchButtonListener());
-               
                return button;
        }
        
+       /**
+        * 
+        * @author n.hoffmann
+        * @created 11.06.2009
+        * @version 1.0
+        */
        class SearchButtonListener extends MouseAdapter{
 
                /* (non-Javadoc)
@@ -128,4 +192,31 @@ public abstract class AbstractNamePropertySection extends
                }
 
        }
+       
+       /**
+        * 
+        */
+       protected void toggleCacheEditing() {
+               if(cacheText.getEditable()){
+                       cacheText.setEditable(false);
+               }else{
+                       cacheText.setEditable(true);
+               }
+               refresh();
+       }
+       
+       /*
+        * (non-Javadoc)
+        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+        */
+       public ConversationHolder getConversationHolder(){
+               return editorPropertySheetPage.getConversationHolder();
+       }
+       
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       public void update(CdmDataChangeMap changeEvents) {
+               // TODO 
+       }
 }
index b8790abc7d41e54a47b0d333e7e2f6cdb252a02b..86ee7477992d9eeabd3704d218b292d82bd61e56 100644 (file)
@@ -22,6 +22,7 @@ import org.eclipse.ui.forms.widgets.Section;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
 
 import eu.etaxonomy.cdm.model.agent.INomenclaturalAuthor;
+import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
 
 /**
  * @author n.hoffmann
@@ -57,18 +58,12 @@ public class AuthorSection extends AbstractNamePropertySection {
        private Object sectionLayoutData;
 
 
-       
-       /**
-        * 
-        */
-       public AuthorSection() {}
-
        /* (non-Javadoc)
         * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
         */
        @Override
        public void createControls(Composite parent,
-                       TabbedPropertySheetPage tabbedPropertySheetPage) {
+                       EditorTabbedPropertySheetPage tabbedPropertySheetPage) {
                super.createControls(parent, tabbedPropertySheetPage);
 
                sectionLayoutData = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
@@ -104,7 +99,9 @@ public class AuthorSection extends AbstractNamePropertySection {
                
                section.setText("Author");
                
+               cacheText.removeModifyListener(listener);
                cacheText.setText(name.getAuthorshipCache());
+               cacheText.addModifyListener(listener);
                editCacheButton.setSelection(name.isProtectedAuthorshipCache());
                
                authorship.setText("Authorship");
@@ -126,6 +123,18 @@ public class AuthorSection extends AbstractNamePropertySection {
                exBasionymAuthorTeam = name.getExBasionymAuthorTeam();
        }
 
-       
-       
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.propertysheet.tabbed.AbstractNamePropertySection#toggleCacheEditing()
+        */
+       @Override
+       protected void toggleCacheEditing() {
+               super.toggleCacheEditing();
+               
+               if(name.isProtectedAuthorshipCache()){
+                       name.setProtectedAuthorshipCache(false);
+               }else{
+                       name.setProtectedAuthorshipCache(true);
+               }
+       }       
 }
diff --git a/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/EditorTabbedPropertySheetPage.java b/taxeditor-editor/src/main/java/eu/etaxonomy/taxeditor/propertysheet/tabbed/EditorTabbedPropertySheetPage.java
new file mode 100644 (file)
index 0000000..6af85b4
--- /dev/null
@@ -0,0 +1,74 @@
+// $Id$
+/**
+* Copyright (C) 2007 EDIT
+* 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.propertysheet.tabbed;
+
+import org.apache.log4j.Logger;
+import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
+
+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.editor.AbstractTaxonEditor;
+
+/**
+ * @author n.hoffmann
+ * @created 11.06.2009
+ * @version 1.0
+ */
+public class EditorTabbedPropertySheetPage extends TabbedPropertySheetPage implements IConversationEnabled{
+
+       private static final Logger logger = Logger
+                       .getLogger(EditorTabbedPropertySheetPage.class);
+       
+       private AbstractTaxonEditor editor;
+       
+       /**
+        * @param tabbedPropertySheetPageContributor
+        */
+       public EditorTabbedPropertySheetPage(AbstractTaxonEditor tabbedPropertySheetPageContributor) {
+               super(tabbedPropertySheetPageContributor);
+               
+               editor = tabbedPropertySheetPageContributor;
+
+       }
+       
+
+       /* (non-Javadoc)
+        * @see org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage#setFocus()
+        */
+       @Override
+       public void setFocus() {
+               super.setFocus();
+               getConversationHolder().bind();
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.api.conversation.IConversationEnabled#getConversationHolder()
+        */
+       public ConversationHolder getConversationHolder() {
+               return editor.getConversationHolder();
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.cdm.persistence.hibernate.ICdmPostDataChangeObserver#update(eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap)
+        */
+       public void update(CdmDataChangeMap changeEvents) {
+               // TODO 
+       }
+
+       /**
+        * @return the editor
+        */
+       public AbstractTaxonEditor getEditor() {
+               return editor;
+       }
+
+}
index 922b16dde0792c8f81249e794bef872d21d43148..c0d145bfc2a094c462b9eaeabfefa2a5adca7427 100644 (file)
@@ -25,6 +25,7 @@ import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.editor.GroupedComposite;
 
 /**
  * @author n.hoffmann
@@ -40,6 +41,7 @@ public class NameOverviewSection extends AbstractPropertySection {
        
        private CLabel parsingStatus;
        private Composite composite;
+       private GroupedComposite groupedComposite;
 
        /**
         * 
@@ -79,12 +81,16 @@ public class NameOverviewSection extends AbstractPropertySection {
         */
        @Override
        public void setInput(IWorkbenchPart part, ISelection selection) {
+               // FIXME this is copied from AbstractNamePropertySection. We do not want duplicated code
         super.setInput(part, selection);
         Assert.isTrue(selection instanceof IStructuredSelection);
         Object input = ((IStructuredSelection) selection).getFirstElement();
-        Assert.isTrue(input instanceof TaxonBase);
-        taxonBase = (TaxonBase) input;
-        name = HibernateProxyHelper.deproxy( taxonBase.getName(), NonViralName.class); 
+        Assert.isTrue(input instanceof GroupedComposite);
+
+        groupedComposite = (GroupedComposite) input;
+        taxonBase = (TaxonBase) groupedComposite.getData();
+        
+        name = HibernateProxyHelper.deproxy(taxonBase.getName(), NonViralName.class);
        }
 
        
index 7f1c3f959470b53233f82fdf92d92f0c17bf2a7b..882bd5a4a4362ec28bce01c84d076ba6cb602cf3 100644 (file)
 package eu.etaxonomy.taxeditor.propertysheet.tabbed;
 
 import org.apache.log4j.Logger;
-import org.eclipse.core.runtime.Assert;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.custom.CLabel;
 import org.eclipse.swt.events.ModifyEvent;
 import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Group;
 import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.forms.widgets.ExpandableComposite;
-import org.eclipse.ui.forms.widgets.Form;
-import org.eclipse.ui.forms.widgets.Section;
-import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
 
 import eu.etaxonomy.cdm.common.CdmUtils;
-import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.name.NomenclaturalStatusType;
-import eu.etaxonomy.cdm.model.name.NonViralName;
 import eu.etaxonomy.cdm.model.name.Rank;
-import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -59,68 +45,76 @@ public class NamePropertySection extends AbstractNamePropertySection {
        private Text appendedPhraseText;
 
        private CCombo nomenclaturalStatusCombo;
-
        
-
-       /**
-        * 
-        */
-       public NamePropertySection() {}
-
-    private ModifyListener listener = new ModifyListener() {
+    protected ModifyListener listener = new ModifyListener() {
         
         public void modifyText(ModifyEvent arg0) {
-//             TaxonBasePropertySource properties = (TaxonBasePropertySource) taxonBase
-//                .getAdapter(IPropertySource.class);
-//            properties.setPropertyValue(TaxonBasePropertySource.P_ID_TAXONNAME,
-//                labelText.getText());
-//             labelText.setText(taxonBase.getName().getTitleCache());
+               logger.warn("element modified");
+               
+               // FIXME this is a workaround because cache do not get generated on change of underlying data
+               // remove once this is fixed in library
+               name.setAuthorshipCache(null,false);
+               name.setNameCache(null, false);
+               // workaround end
+               
+               
+               
+               name.setGenusOrUninomial(uninomialText.getText());
+               
+               // TODO refresh the editor
+               //EditorUtil.getActiveEditorPage(Page.NAME).setDirty();
+               //EditorUtil.getActiveEditorPage(Page.NAME).redraw(false);
+               groupedComposite.refresh();
         }
     };
+       
 
-
-       public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage){
-               super.createControls(parent, tabbedPropertySheetPage);
+    @Override
+       public void createControls(Composite parent, TabbedPropertySheetPage editorPropertySheetPage){
+               super.createControls(parent, editorPropertySheetPage);
+//     super.createControls(parent, tabbedPropertySheetPage);
+               
+               GridData textFieldLayout = new GridData(SWT.FILL, SWT.FILL, true, true);
+               GridData comboLayout = new GridData(SWT.FILL, SWT.FILL, true, false);
                
-
                // rank
                CLabel rankComboLabel = getWidgetFactory().createCLabel(composite, "Rank:");
                rankCombo = getWidgetFactory().createCCombo(composite);
-               rankCombo.setLayoutData(layoutData);
+               rankCombo.setLayoutData(comboLayout);
                
-               for (Rank rank : CdmStore.getRanks()){
+               for (Rank rank : CdmStore.getPreferredRanks()){
                        rankCombo.add(rank.getLabel(CdmStore.getDefaultLanguage())); 
                }
 
                // uninomial
                CLabel uninomialLabel = getWidgetFactory().createCLabel(composite, "Uninomial");
                uninomialText = getWidgetFactory().createText(composite, "");
-               uninomialText.setLayoutData(layoutData);
+               uninomialText.setLayoutData(textFieldLayout);
                
                // infrageneric epithet
                CLabel  infragenericEpithetLabel = getWidgetFactory().createCLabel(composite, "Infrageneric Epithet");
                infragenericEpithetText = getWidgetFactory().createText(composite, "");
-               infragenericEpithetText.setLayoutData(layoutData);
+               infragenericEpithetText.setLayoutData(textFieldLayout);
                
                // specific epithet
                CLabel  specificEpithetLabel = getWidgetFactory().createCLabel(composite, "Specific Epithet");
                specificEpithetText = getWidgetFactory().createText(composite, "");
-               specificEpithetText.setLayoutData(layoutData);
+               specificEpithetText.setLayoutData(textFieldLayout);
                
                // infraspecific epithet
                CLabel  infraspecificEpithetLabel = getWidgetFactory().createCLabel(composite, "Infraspecific Epithet");
                infraSpecificEpithetText = getWidgetFactory().createText(composite, "");
-               infraSpecificEpithetText.setLayoutData(layoutData);
+               infraSpecificEpithetText.setLayoutData(textFieldLayout);
                
                // appended phrase
                CLabel  appendedPhraseLabel = getWidgetFactory().createCLabel(composite, "Appended Phrase");
                appendedPhraseText = getWidgetFactory().createText(composite, "");
-               appendedPhraseText.setLayoutData(layoutData);
+               appendedPhraseText.setLayoutData(textFieldLayout);
                
                // nomenclatural status
                CLabel nomenclaturalStatusLabel = getWidgetFactory().createCLabel(composite, "Nomenclatural Status", SWT.NO_BACKGROUND);
                nomenclaturalStatusCombo = getWidgetFactory().createCCombo(composite);
-               nomenclaturalStatusCombo.setLayoutData(layoutData);
+               nomenclaturalStatusCombo.setLayoutData(comboLayout);
                
                for(NomenclaturalStatusType nomenclaturalStatusType : CdmStore.getNomenclaturalStatusTypes()){
                        nomenclaturalStatusCombo.add(nomenclaturalStatusType.getLabel(CdmStore.getDefaultLanguage()));
@@ -137,11 +131,16 @@ public class NamePropertySection extends AbstractNamePropertySection {
                
                section.setText("Name");
                
-               cacheText.setText(name.getNameCache());
+               cacheText.removeModifyListener(listener);
+               cacheText.setText(CdmUtils.Nz(name.getNameCache()));
+               cacheText.addModifyListener(listener);
                
                editCacheButton.setSelection(name.isProtectedNameCache());
                
+               uninomialText.removeModifyListener(listener);
                uninomialText.setText(CdmUtils.Nz(name.getGenusOrUninomial()));
+               uninomialText.addModifyListener(listener);
+               
                infragenericEpithetText.setText(CdmUtils.Nz(name.getInfraGenericEpithet()));
                specificEpithetText.setText(CdmUtils.Nz(name.getSpecificEpithet()));
                infraSpecificEpithetText.setText(CdmUtils.Nz(name.getInfraSpecificEpithet()));
@@ -149,4 +148,18 @@ public class NamePropertySection extends AbstractNamePropertySection {
                appendedPhraseText.setText(CdmUtils.Nz(name.getAppendedPhrase()));
                
        }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.propertysheet.tabbed.AbstractNamePropertySection#toggleCacheEditing()
+        */
+       @Override
+       protected void toggleCacheEditing() {
+               super.toggleCacheEditing();
+               
+               if(name.isProtectedNameCache()){
+                       name.setProtectedNameCache(false);
+               }else{
+                       name.setProtectedNameCache(true);
+               }
+       }
 }
index 3596aa32c23d196172206deff5b51320cee997ca..007d3ef170ea8ee645c26db51538269442beaf12 100644 (file)
@@ -14,15 +14,18 @@ import org.apache.log4j.Logger;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.swt.custom.CCombo;
 import org.eclipse.swt.custom.CLabel;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
 import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Text;
 import org.eclipse.ui.IWorkbenchPart;
 import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
 
+import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.model.reference.ReferenceBase;
-import eu.etaxonomy.taxeditor.propertysheet.name.ScientificNamePropertySource;
-import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.Page;
 
 /**
  * @author n.hoffmann
@@ -55,25 +58,31 @@ public class NomRefPropertySection extends AbstractNamePropertySection {
        private Text microReferenceText;
 
        private Button searchButton;
-       
-       /**
-        * 
-        */
-       public NomRefPropertySection() {}
 
+    protected ModifyListener listener = new ModifyListener() {
+        
+        public void modifyText(ModifyEvent arg0) {
+               logger.warn("element modified");
+               
+               reference.setTitleCache(cacheText.getText());
+               
+               // TODO refresh the editor
+               EditorUtil.getActiveEditorPage(Page.NAME).setDirty();
+        }
+    };
        
        /* (non-Javadoc)
         * @see org.eclipse.ui.views.properties.tabbed.AbstractPropertySection#createControls(org.eclipse.swt.widgets.Composite, org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage)
         */
        @Override
-       public void createControls(Composite parent, TabbedPropertySheetPage tabbedPropertySheetPage) {
+       public void createControls(Composite parent, EditorTabbedPropertySheetPage tabbedPropertySheetPage) {
                
         super.createControls(parent, tabbedPropertySheetPage);
         
         CLabel empty = getWidgetFactory().createCLabel(composite, "");
         searchButton = createSearchButton(composite);
         
-        
+        /*
         CLabel referenceTypeLabel = getWidgetFactory().createCLabel(composite, "Reference Type");
         referenceTypeCombo = getWidgetFactory().createCCombo(composite);
         referenceTypeCombo.setLayoutData(layoutData);
@@ -126,6 +135,7 @@ public class NomRefPropertySection extends AbstractNamePropertySection {
         editionText = getWidgetFactory().createText(composite, "");
         editionText.setLayoutData(layoutData);
         
+        */
         CLabel microReferenceLabel = getWidgetFactory().createCLabel(composite, "Reference Detail");
         microReferenceText = getWidgetFactory().createText(composite, "");
         microReferenceText.setLayoutData(layoutData);
@@ -142,10 +152,17 @@ public class NomRefPropertySection extends AbstractNamePropertySection {
                
                section.setText("Nomenclatural Reference");
                
-               cacheText.setText(reference.getTitleCache());
-               editCacheButton.setSelection(reference.isProtectedTitleCache());
+               if(reference != null){
+                       cacheText.removeModifyListener(listener);
+                       cacheText.setText(CdmUtils.Nz(reference.getTitleCache()));
+                       cacheText.addModifyListener(listener);
+       
+                       editCacheButton.setSelection(reference.isProtectedTitleCache());
+                       cacheText.setEnabled(reference.isProtectedTitleCache());
+               }
+               
+               microReferenceText.setText(CdmUtils.Nz(microReference));
                
-               microReferenceText.setText(microReference);
        }
 
        /* (non-Javadoc)
@@ -157,4 +174,18 @@ public class NomRefPropertySection extends AbstractNamePropertySection {
         reference = name.getNomenclaturalReference();
         microReference = name.getNomenclaturalMicroReference();
        }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.propertysheet.tabbed.AbstractNamePropertySection#toggleCacheEditing()
+        */
+       @Override
+       protected void toggleCacheEditing() {
+               if(reference.isProtectedTitleCache()){
+                       reference.setProtectedTitleCache(false);
+               }else{
+                       reference.setProtectedTitleCache(true);
+               }
+               
+               super.toggleCacheEditing();
+       }
 }
index 0c8fd82e589a2f97b7cfb1744a512a2130f31a81..acc4098c680bc847ea3f60fc951b5c14ef98a33f 100644 (file)
 package eu.etaxonomy.taxeditor.propertysheet.tabbed;
 
 import org.apache.log4j.Logger;
+import org.eclipse.core.runtime.Assert;
 import org.eclipse.jface.viewers.ILabelProvider;
 import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+import eu.etaxonomy.taxeditor.editor.GroupedComposite;
 
 /**
  * @author n.hoffmann
@@ -29,9 +33,12 @@ public class TabbedPropertyPageLabelProvider extends LabelProvider implements
         */
        @Override
        public String getText(Object element) {
-               return super.getText(element);
+               Assert.isTrue(element instanceof StructuredSelection, "Given element is not a StructuredSelection");
+               StructuredSelection selection = (StructuredSelection) element;
+               
+               Assert.isTrue(selection.getFirstElement() instanceof GroupedComposite, "Selection is not a grouped composite");
+               GroupedComposite groupedComposite = (GroupedComposite) selection.getFirstElement();
+               
+               return super.getText(groupedComposite.getData());
        }
-       
-       
-       
 }