corrected behaviour when adding / saving new authorites
authorCherian Mathew <c.mathew@bgbm.org>
Thu, 7 Aug 2014 09:27:08 +0000 (09:27 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Thu, 7 Aug 2014 09:27:08 +0000 (09:27 +0000)
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/group/authority/CdmAuthorityEditor.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java

index 0d952767afbcee9295a446f43c814d204f316f15..b82a717a45b728aee16a7a65a07264b68cb1d4fa 100644 (file)
@@ -134,7 +134,7 @@ public class CdmAuthorityEditor extends EditorPart implements IConversationEnabl
        public void changed(Object element) {
                //FIXME : should be optimised to split changes into adding / removing authorities 
                //        vs updating authorites
-               dirty=true;
+               dirty = viewer.isDirty();
                firePropertyChange(PROP_DIRTY);
                // if the change has happened on the group then refresh the table
                if(element instanceof Group) {
index e1cab9bef2730c53de590bf817d493323a527df6..e3e07a2ea8b9a5fbb05520f91ed5c7c06bbdab3b 100644 (file)
@@ -78,6 +78,7 @@ public class CRUDOperationChooser extends Composite {
                createCheckButton.setText("C");
                
                readCheckButton = new Button(this, SWT.CHECK);
+               readCheckButton.setEnabled(false);
                readCheckButton.addMouseTrackListener(new MouseTrackAdapter() {
                        @Override
                        public void mouseHover(MouseEvent arg0) {
@@ -174,7 +175,7 @@ public class CRUDOperationChooser extends Composite {
         */
        private void updateView() {
                createCheckButton.setSelection(false);
-               readCheckButton.setSelection(false);
+               readCheckButton.setSelection(true);
                deleteCheckButton.setSelection(false);
                updateCheckButton.setSelection(false);
                
index cb910b32c9960407c9c3ae5f7c7b6c3c5b05f61a..0ea4dc32ceca4e33f30e2b3110247c8bbcb59052 100644 (file)
@@ -41,18 +41,13 @@ import eu.etaxonomy.taxeditor.store.StoreUtil;
  */
 
 
-/**
- * @author cmathew
- * @date Apr 5, 2013
- *
- */
-
 //FIXME:move warning dialogs to the table class
 public class CdmAuthorityCompositeViewer extends ContentViewer {
        
        private IDirtyMarkableSelectionProvider dirtyMarkerEditor;      
        private CdmAuthorityComposite cdmAuthorityComposite;
        private Group group;
+       private boolean isDirty = false;
        /**
         * List which contains already existing authority objects.
         */
@@ -122,6 +117,9 @@ public class CdmAuthorityCompositeViewer extends ContentViewer {
                return cdmAuthorities;
        }
        
+       public boolean isDirty() {
+               return isDirty;
+       }
        /**
         * Adds a new {@link CdmAuthority} to the group attached to this viewer
         * based on the input {@link CdmBase} object.
@@ -134,6 +132,7 @@ public class CdmAuthorityCompositeViewer extends ContentViewer {
                defaultOperation.add(CRUD.READ);
                CdmAuthority cdma = new CdmAuthority(cb, defaultOperation, cb.getUuid());
                GrantedAuthorityImpl gai;
+               
                try {
                        // create a granted authrity from a cdm authority 
                        gai = cdma.asNewGrantedAuthority();
@@ -143,11 +142,12 @@ public class CdmAuthorityCompositeViewer extends ContentViewer {
                }
                //FIXME : this contains call will allow users to add authorities which differ only in CRUD operation choice.
                //        need to have a comparator which only checks permission class and uuid
-               if(cdmAuthorities.contains(gai)) {
+               if(cdmAuthorities.contains(gai) || newCdmAuthorities.contains(gai)) {
                        StoreUtil.warningDialog("Duplicate CDM Authority", this, "Chosen CDM Authority is already attached to current group");
                } else {                                                                
                        group.addGrantedAuthority(gai);
-                       newCdmAuthorities.add(gai);                             
+                       newCdmAuthorities.add(gai);
+                       isDirty = true;
                        dirtyMarkerEditor.changed(group);               
                        cdmAuthorityComposite.refresh();
                }
@@ -160,15 +160,19 @@ public class CdmAuthorityCompositeViewer extends ContentViewer {
         * @param gai {@link GrantedAuthorityImpl} object to remove
         */
        public void removeCdmAuthority(GrantedAuthorityImpl gai) {
-               if(cdmAuthorities.contains(gai)) {
-                       group.removeGrantedAuthority(gai);
+               
+               if(cdmAuthorities.contains(gai)) {                                      
+                       cdmAuthorities.remove(gai);             
+                       isDirty = true;
+               } else {                                                
                        newCdmAuthorities.remove(gai);
-                       cdmAuthorities.remove(gai);
-                       dirtyMarkerEditor.changed(group);       
-                       cdmAuthorityComposite.refresh();
-               } else {
-                       StoreUtil.warningDialog("Unknown CDM Authority", this, "Chosen CDM Authority does not exist in  current group");
+                       if(newCdmAuthorities.isEmpty() && !isDirty) {
+                               isDirty = false;
+                       }
                }
+               group.removeGrantedAuthority(gai);              
+               dirtyMarkerEditor.changed(group);               
+               cdmAuthorityComposite.refresh();
        }
        
        /**
@@ -189,6 +193,7 @@ public class CdmAuthorityCompositeViewer extends ContentViewer {
                                GrantedAuthorityImpl gai = cdmAuthority.asNewGrantedAuthority();
                                group.addGrantedAuthority(gai);
                                group.removeGrantedAuthority(grantedAuthorityI);
+                               isDirty = true;
                                dirtyMarkerEditor.changed(grantedAuthorityI);
                                return gai;
                        } catch(Exception e) {