commits for the CDM Authority Composite and related widgets + drag/drop objects
authorCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Apr 2013 12:31:54 +0000 (12:31 +0000)
committerCherian Mathew <c.mathew@bgbm.org>
Tue, 9 Apr 2013 12:31:54 +0000 (12:31 +0000)
CdmAuthorityComposite : composite which contains a nebula CompositeTable widget
CdmAuthorityTableHeader : table header widget for the CompositeTable widget in CdmAuthorityComposite
CdmAuthorityRow : row widget for the CompositeTable widget in CdmAuthorityComposite
CRUDOperationChooser : CRUD update widget for CdmAuthorityRow
CdmAuthorityCompositeViewer : viewer for CdmAuthorityComposite containing the group object
TaxonNodeTransfer : drag/drop object for taxon nodes
CdmAuthorityTableDropTargetListener : drop listener for the CdmAuthorityComposite
MANIFEST.MF : now includes nebula jar for composite table widget

.gitattributes
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java [new file with mode: 0644]

index 979311d4106b81324a5b5bc1666e14c09caee393..81d8ea17a0002c62e33217ec2bab91d54dfd389f 100644 (file)
@@ -1057,6 +1057,8 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wiz
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceSQLServerWizardPage.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceWizard.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/ISecuredEditor.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/UsageTermCollection.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDragListener.java -text
@@ -1292,6 +1294,11 @@ eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/Tex
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ToggleableTextElement.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java -text
+eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/IOpenUrlEnabled.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlContentProvider.java -text
 eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlLabelProvider.java -text
index 110934d453caa69ec559aec9dea919db16a8f0d3..561ec4c0e0bd1626d67de1f4b003f4156def5ee9 100644 (file)
@@ -9,6 +9,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.cdm.database,
  eu.etaxonomy.taxeditor.datasource,
  eu.etaxonomy.taxeditor.datasource.wizard,
+ eu.etaxonomy.taxeditor.dnd.transfer,
  eu.etaxonomy.taxeditor.editor,
  eu.etaxonomy.taxeditor.editor.definedterm,
  eu.etaxonomy.taxeditor.featuretree,
@@ -33,6 +34,7 @@ Export-Package: eu.etaxonomy.cdm,
  eu.etaxonomy.taxeditor.ui.dialog,
  eu.etaxonomy.taxeditor.ui.dialog.selection,
  eu.etaxonomy.taxeditor.ui.element,
+ eu.etaxonomy.taxeditor.ui.group.grantedauthority,
  eu.etaxonomy.taxeditor.ui.section,
  eu.etaxonomy.taxeditor.ui.section.agent,
  eu.etaxonomy.taxeditor.ui.section.classification,
@@ -53,7 +55,8 @@ Require-Bundle: org.eclipse.osgi,
  org.eclipse.ui,
  org.eclipse.jface.text,
  org.eclipse.ui.forms,
- eu.etaxonomy.taxeditor.cdmlib
+ eu.etaxonomy.taxeditor.cdmlib,
+ org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0"
 Import-Package: org.eclipse.core.commands,
  org.eclipse.core.commands.operations,
  org.eclipse.core.expressions,
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java
new file mode 100644 (file)
index 0000000..5612ab4
--- /dev/null
@@ -0,0 +1,93 @@
+/**
+* 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.dnd;
+
+import java.awt.Cursor;
+import java.util.EnumSet;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.DropTargetEvent;
+import org.eclipse.swt.dnd.DropTargetListener;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
+import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
+import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityComposite;
+import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
+
+/**
+ * Drop listener for the {@link CdmAuthorityComposite}.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+public class CdmAuthorityTableDropTargetListener implements DropTargetListener {
+
+       private CdmAuthorityCompositeViewer viewer;
+       
+       
+       public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer) {
+               this.viewer = viewer;
+       }
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void dragEnter(DropTargetEvent event) {                          
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void dragLeave(DropTargetEvent arg0) {
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void dragOperationChanged(DropTargetEvent arg0) {
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void dragOver(DropTargetEvent arg0) {
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void drop(DropTargetEvent dtevent) {
+               if(TaxonNodeTransfer.getInstance().isSupportedType(dtevent.currentDataType)) {
+                       Object[] selectedCdmBases = (Object[])dtevent.data;
+                       
+                       for (Object cdmBase : selectedCdmBases){
+                               if(CdmBase.class.isAssignableFrom(cdmBase.getClass()) ) {
+                                       viewer.addCdmAuthority((CdmBase)cdmBase);                                       
+                               }
+                       }
+               }               
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclipse.swt.dnd.DropTargetEvent)
+        */
+       @Override
+       public void dropAccept(DropTargetEvent arg0) {
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java
new file mode 100644 (file)
index 0000000..528cb40
--- /dev/null
@@ -0,0 +1,62 @@
+
+//$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.dnd.transfer;
+
+import java.util.UUID;
+
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.model.CdmObjectTransfer;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+/**
+ * Drag / Drop Transfer object for Taxon Node 
+ * 
+ * @author c.mathew
+ * @created Mar 25, 2013
+ */
+public class TaxonNodeTransfer extends CdmObjectTransfer<TaxonNode> {
+
+       private static TaxonNodeTransfer instance = new TaxonNodeTransfer();
+       private static final String TYPE_NAME = "taxonNode-transfer-format";
+       private static final int TYPEID = registerType(TYPE_NAME);
+       
+       public static synchronized TaxonNodeTransfer getInstance(){
+               return instance;
+       }
+       
+       private TaxonNodeTransfer(){}
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.Transfer#getTypeIds()
+        */
+       @Override
+       protected int[] getTypeIds() {
+               return new int[] { TYPEID };
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.swt.dnd.Transfer#getTypeNames()
+        */
+       @Override
+       protected String[] getTypeNames() {
+               return new String[] { TYPE_NAME };
+       }
+
+       /* (non-Javadoc)
+        * @see eu.etaxonomy.taxeditor.model.CdmObjectTransfer#loadElement(java.util.UUID)
+        */
+       @Override
+       public TaxonNode loadElement(UUID uuid) {
+               return CdmStore.getService(ITaxonNodeService.class).load(uuid, null);
+       }
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java
new file mode 100644 (file)
index 0000000..228a42c
--- /dev/null
@@ -0,0 +1,200 @@
+/**
+* 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.ui.group.grantedauthority;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.RowLayout;
+
+import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
+
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+import org.eclipse.swt.events.MouseTrackAdapter;
+
+
+/**
+ * Widget for editing {@link Operation} objects, consisting of 4 checkboxes for CREATE, UPDATE, READ, DELETE operations.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+public class CRUDOperationChooser extends Composite {
+       
+       private Button createCheckButton;
+       private Button readCheckButton;
+       private Button deleteCheckButton;
+       private Button updateCheckButton;
+       
+       private CdmAuthorityRow caRow;
+       private GrantedAuthorityImpl grantedAuthorityI;
+       private CdmAuthority cdmAuthority;
+       private CdmAuthorityCompositeViewer viewer;
+       
+       /**
+        * Create the composite.
+        * @param parent
+        * @param style
+        */
+       public CRUDOperationChooser(final CdmAuthorityRow parent, int style) {
+               super(parent, style);
+               setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
+               RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
+               rowLayout.justify = true;
+               setLayout(rowLayout);
+               
+               
+               this.caRow = parent;
+               createCheckButton = new Button(this, SWT.CHECK);
+               createCheckButton.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
+               createCheckButton.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseUp(MouseEvent arg0) {
+                               if(cdmAuthority.getOperation() != null) {
+                                       if(createCheckButton.getSelection()) {
+                                               cdmAuthority.getOperation().add(CRUD.CREATE);
+                                       } else {
+                                               cdmAuthority.getOperation().remove(CRUD.CREATE);
+                                       }
+                                       if(viewer != null) {
+                                               viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
+                                               parent.setDirty(true);
+                                       }
+                                       
+                               }
+                       }
+               });
+               createCheckButton.setText("C");
+               
+               readCheckButton = new Button(this, SWT.CHECK);
+               readCheckButton.addMouseTrackListener(new MouseTrackAdapter() {
+                       @Override
+                       public void mouseHover(MouseEvent arg0) {
+                       }
+               });
+               readCheckButton.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseUp(MouseEvent arg0) {
+                               if(cdmAuthority.getOperation() != null) {
+                                       if(readCheckButton.getSelection()) {
+                                               cdmAuthority.getOperation().add(CRUD.READ);
+                                       } else {
+                                               cdmAuthority.getOperation().remove(CRUD.READ);
+                                       }
+                                       if(viewer != null) {
+                                               viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
+                                               parent.setDirty(true);
+                                       }
+                                       
+                               }
+                                       
+                       }
+               });
+               readCheckButton.setText("R");
+               
+               deleteCheckButton = new Button(this, SWT.CHECK);
+               deleteCheckButton.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseUp(MouseEvent arg0) {
+                               if(cdmAuthority.getOperation() != null) {
+                                       if(deleteCheckButton.getSelection()) {
+                                               cdmAuthority.getOperation().add(CRUD.DELETE);
+                                       } else {
+                                               cdmAuthority.getOperation().remove(CRUD.DELETE);
+                                       }
+                                       if(viewer != null) {
+                                               viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
+                                               parent.setDirty(true);
+                                       }
+                                       
+                               }
+                       }
+               });
+               deleteCheckButton.setText("D");
+               
+               updateCheckButton = new Button(this, SWT.CHECK);
+               updateCheckButton.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseUp(MouseEvent arg0) {
+                               if(cdmAuthority.getOperation() != null) {
+                                       if(updateCheckButton.getSelection()) {
+                                               cdmAuthority.getOperation().add(CRUD.UPDATE);
+                                       } else {
+                                               cdmAuthority.getOperation().remove(CRUD.UPDATE);
+                                       }
+                                       if(viewer != null) {
+                                               viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
+                                               parent.setDirty(true);
+                                       }
+                                       
+                               }
+                       }
+               });
+               updateCheckButton.setText("U");
+               updateView();
+       }
+
+       
+       @Override
+       protected void checkSubclass() {
+               // Disable the check that prevents subclassing of SWT components
+       }
+       
+       /**
+        * Set viewer, CDM Authority and corresponding GrantedAuthorityImpl object
+        * 
+        * @param viewer
+        * @param grantedAuthorityI
+        * @param cdmAuthority
+        */
+       public void setAuthority(CdmAuthorityCompositeViewer viewer, 
+                       GrantedAuthorityImpl grantedAuthorityI,
+                       CdmAuthority cdmAuthority) {
+               this.grantedAuthorityI = grantedAuthorityI;
+               this.cdmAuthority = cdmAuthority;
+               this.viewer = viewer;
+               updateView();
+       }
+       
+
+       
+       /**
+        * Update widget state.
+        */
+       private void updateView() {
+               createCheckButton.setSelection(false);
+               readCheckButton.setSelection(false);
+               deleteCheckButton.setSelection(false);
+               updateCheckButton.setSelection(false);
+               
+               
+               if(cdmAuthority!= null && cdmAuthority.getOperation() != null) {
+                       if(cdmAuthority.getOperation().contains(CRUD.CREATE)) {
+                               createCheckButton.setSelection(true);
+                       }
+                       if(cdmAuthority.getOperation().contains(CRUD.READ)) {
+                               readCheckButton.setSelection(true);
+                       }
+                       if(cdmAuthority.getOperation().contains(CRUD.DELETE)) {
+                               deleteCheckButton.setSelection(true);
+                       }
+                       if(cdmAuthority.getOperation().contains(CRUD.UPDATE)) {
+                               updateCheckButton.setSelection(true);
+                       }
+
+               }
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java
new file mode 100644 (file)
index 0000000..cc4210f
--- /dev/null
@@ -0,0 +1,123 @@
+/**
+* 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.ui.group.grantedauthority;
+
+import org.eclipse.nebula.widgets.compositetable.CompositeTable;
+import org.eclipse.nebula.widgets.compositetable.IRowContentProvider;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
+
+import eu.etaxonomy.taxeditor.dnd.CdmAuthorityTableDropTargetListener;
+import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
+
+import org.eclipse.swt.dnd.DropTarget;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.dnd.Transfer;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.layout.GridData;
+
+/**
+ * Composite class which consists of a {@link CompositeTable} built specifically
+ * for creating / editing CDM Authority objects
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+
+public class CdmAuthorityComposite extends Composite {
+
+       private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
+       private CompositeTable table;
+       
+       private int numOfInitialCdmAuthorities;
+
+       private Label lblDragEntityInto;
+       
+       private CdmAuthorityCompositeViewer viewer;
+       
+
+       /**
+        * Creates the composite using the given parent, style and associated viewer.
+        * 
+        * @param parent composite to use as parent of this composite
+        * @param style 
+        * @param viewer viewer representing the model
+        */
+       public CdmAuthorityComposite(Composite parent, int style, final CdmAuthorityCompositeViewer viewer) {
+               super(parent, style);
+               addDisposeListener(new DisposeListener() {
+                       public void widgetDisposed(DisposeEvent e) {
+                               toolkit.dispose();
+                       }
+               });
+               
+               this.viewer = viewer;
+                               
+               numOfInitialCdmAuthorities = viewer.getCdmAuthorities().size();
+               setLayout(new GridLayout(1, false));
+           Transfer[] transfers = new Transfer[] { TaxonNodeTransfer.getInstance() };     
+           
+           toolkit.adapt(this);
+               toolkit.paintBordersFor(this);          
+
+               lblDragEntityInto = new Label(this, SWT.NONE);
+               toolkit.adapt(lblDragEntityInto, true, true);
+               lblDragEntityInto.setText("Drag Entity into table to add ...");
+               table = new CompositeTable(this, SWT.BORDER);
+               GridData gd_table = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+               gd_table.widthHint = 750;
+               gd_table.heightHint = 400;
+               table.setLayoutData(gd_table);
+               new CdmAuthorityTableHeader(table, SWT.NULL); 
+               CdmAuthorityRow cdmAuthorityRow = new CdmAuthorityRow(table, SWT.NULL);
+               
+               table.setRunTime(true);
+               table.setNumRowsInCollection(numOfInitialCdmAuthorities);
+               table.setLinesVisible(true); 
+               
+               DropTarget dropTarget = new DropTarget(table, DND.DROP_MOVE);
+               dropTarget.setTransfer(transfers);
+               dropTarget.addDropListener(new CdmAuthorityTableDropTargetListener(viewer));
+               
+               
+               table.addRowContentProvider(new IRowContentProvider() {
+                       public void refresh(CompositeTable sender, int currentObjectOffset, Control rowControl) {
+                               CdmAuthorityRow row = (CdmAuthorityRow) rowControl;             
+                               // add the newly created authority objects first and then the already existing ones.
+                               // this ensures the newly 'dragged' in objects always remain at the top
+                               if(currentObjectOffset < viewer.getNewCdmAuthorities().size()) {                        
+                                       row.setRowCdmAuthority(viewer, 
+                                                       viewer.getNewCdmAuthorities().get(currentObjectOffset), 
+                                                       true);
+                               } else {
+                                       row.setRowCdmAuthority(viewer, 
+                                                       viewer.getCdmAuthorities().get(currentObjectOffset - viewer.getNewCdmAuthorities().size()), 
+                                                       false);
+                               }                                                                               
+                       }
+               });
+       }       
+
+       /**
+        * Refreshes the table with underlying data
+        */
+       public void refresh() {                 
+               numOfInitialCdmAuthorities = viewer.getNewCdmAuthorities().size() + viewer.getCdmAuthorities().size();                              
+           table.setNumRowsInCollection(numOfInitialCdmAuthorities);     
+           table.refreshAllRows();
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java
new file mode 100644 (file)
index 0000000..701b739
--- /dev/null
@@ -0,0 +1,267 @@
+/**
+* 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.ui.group.grantedauthority;
+
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jface.viewers.ContentViewer;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.springframework.security.core.GrantedAuthority;
+
+import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.common.Group;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
+
+
+
+/**
+ * Viewer class for the {@link CdmAuthorityComposite} used in the editing of CDM Authorities.
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+
+
+/**
+ * @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;
+       /**
+        * List which contains already existing authority objects.
+        */
+       private List<GrantedAuthorityImpl> cdmAuthorities;
+       /**
+        * List which contains newly added (unsaved) authority objects.
+        * Used to make sure that new authority objects are always added 
+        * to the top of the table.
+        */
+       private List<GrantedAuthorityImpl> newCdmAuthorities;
+       
+       
+       /**
+        * Creates a viewer with a {@link CdmAuthorityComposite} table, {@link Group} object as input 
+        * 
+        * @param composite parent of generated {@link CdmAuthorityComposite}
+        * @param dirtyMarkerEditor provider to mark as dirty
+        * @param group input data object
+        */
+       public CdmAuthorityCompositeViewer(Composite composite,
+                       IDirtyMarkableSelectionProvider dirtyMarkerEditor, 
+                       Group group) {
+               this.dirtyMarkerEditor = dirtyMarkerEditor;
+               this.group = group;
+               newCdmAuthorities = new ArrayList<GrantedAuthorityImpl>();              
+               updateAuthorities();
+               this.cdmAuthorityComposite = new CdmAuthorityComposite(composite, SWT.NONE, this);
+       }
+
+       /**
+        * Gets the {@link CdmAuthorityComposite}
+        * 
+        * @return {@link CdmAuthorityComposite} generated by this viewer
+        */
+       public CdmAuthorityComposite getCdmAuthorityComposite() {
+               return cdmAuthorityComposite;
+       }
+       
+       
+       /**
+        * Retrieves the {@link GrantedAuthorityImpl} objects of the group attached to this viewer
+        * creates a sub-list of only {@link CdmAuthority} objects.
+        * 
+        * @return list of {@link CdmAuthority} objects belonging to the input group
+        */
+       public List<GrantedAuthorityImpl> updateAuthorities()  {
+               // get all granted authorities
+               Set<GrantedAuthority> grantedAuthorities = group.getGrantedAuthorities();
+               cdmAuthorities = new ArrayList<GrantedAuthorityImpl>(); 
+               
+               Iterator<GrantedAuthority> itr = grantedAuthorities.iterator();         
+               while (itr.hasNext()) {
+                       GrantedAuthority grantedAuthority = itr.next();
+                       try {
+                               
+                               if(grantedAuthority != null && grantedAuthority instanceof GrantedAuthorityImpl) {                      
+                                       // create a cdm authority from a granted authority
+                                       // this could fail in which case an exception is thrown
+                                       CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthority);
+                                       cdmAuthorities.add((GrantedAuthorityImpl)grantedAuthority);                             
+                               }
+                       } catch (Exception e) {
+                               // not a CdmAuthority                           
+                               //e.printStackTrace();
+                       }                       
+               }
+               return cdmAuthorities;
+       }
+       
+       /**
+        * Adds a new {@link CdmAuthority} to the group attached to this viewer
+        * based on the input {@link CdmBase} object.
+        * 
+        * @param cb {@link CdmBase} object used to construct the cdm authority
+        */
+       public void addCdmAuthority(CdmBase cb) {
+               // Default permission is to READ
+               EnumSet<CRUD> defaultOperation = EnumSet.noneOf(CRUD.class);
+               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();
+               } catch (Exception e) {                 
+                       StoreUtil.warningDialog("Parsing Error", this, "Could not parse authority string");
+                       return;
+               }
+               //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)) {
+                       StoreUtil.warningDialog("Duplicate CDM Authority", this, "Chosen CDM Authority is already attached to current group");
+               } else {                                                                
+                       group.addGrantedAuthority(gai);
+                       newCdmAuthorities.add(gai);                             
+                       dirtyMarkerEditor.changed(group);               
+                       cdmAuthorityComposite.refresh();
+               }
+       }
+       
+       /**
+        * Removes the given {@link GrantedAuthorityImpl} object from the list of
+        * granted authorities belonging to the group attached to this viewer.
+        * 
+        * @param gai {@link GrantedAuthorityImpl} object to remove
+        */
+       public void removeCdmAuthority(GrantedAuthorityImpl gai) {
+               if(cdmAuthorities.contains(gai)) {
+                       group.removeGrantedAuthority(gai);
+                       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");
+               }
+       }
+       
+       /**
+        * Updates an existing {@link GrantedAuthorityImpl} object using a {@link CdmAuthority} object.
+        * 
+        * @param grantedAuthorityI to update.
+        * @param cdmAuthority to use in updating the granted authority object.
+        */
+       public void updateGrantedAuthority(GrantedAuthorityImpl grantedAuthorityI, CdmAuthority cdmAuthority) {
+               if(grantedAuthorityI.getAuthority().equals(cdmAuthority.getAuthority())) {
+                       
+               } else {
+                       try {
+                               // since granted authority is just a wrapper object around a string
+                               // we can't really 'update' the granted authority.
+                               // so we first add the new authority (hope no exception) is thrown
+                               // and then remove the old one.
+                               group.addGrantedAuthority(cdmAuthority.asNewGrantedAuthority());
+                               group.removeGrantedAuthority(grantedAuthorityI);
+                               dirtyMarkerEditor.changed(grantedAuthorityI);                           
+                       } catch(Exception e) {
+                               // Not a CDM Authority
+                               //e.printStackTrace();
+                       }
+               }               
+       }
+       
+       /**
+        * @return list of existing cdm authority objects
+        */
+       public List<GrantedAuthorityImpl> getCdmAuthorities() {
+               return cdmAuthorities;
+       }
+       
+       /**
+        * @return list of newly added cdm authority objects
+        */
+       public List<GrantedAuthorityImpl> getNewCdmAuthorities() {
+               return newCdmAuthorities;
+       }
+       
+
+       /**
+        * Empty the list of newly create autrity objects
+        */
+       public void clearNewCdmAuthorities() {
+               newCdmAuthorities.clear();
+       }
+
+       
+       /**
+        * 
+        * 
+        */
+       public void save() {
+               clearNewCdmAuthorities();               
+               refresh();
+               
+       }       
+       
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.Viewer#getControl()
+        */
+       @Override
+       public Control getControl() {
+               return cdmAuthorityComposite;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.Viewer#getSelection()
+        */
+       @Override
+       public ISelection getSelection() {
+               // TODO Auto-generated method stub
+               return null;
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.Viewer#refresh()
+        */
+       @Override
+       public void refresh() {
+               updateAuthorities();
+               cdmAuthorityComposite.refresh();
+               
+       }
+
+       /* (non-Javadoc)
+        * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
+        */
+       @Override
+       public void setSelection(ISelection selection, boolean reveal) {
+               // TODO Auto-generated method stub
+               
+       }
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java
new file mode 100644 (file)
index 0000000..9d545f0
--- /dev/null
@@ -0,0 +1,166 @@
+/**
+* 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.ui.group.grantedauthority;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.SWT;
+
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.layout.GridData;
+
+import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
+import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
+import eu.etaxonomy.taxeditor.model.ImageResources;
+
+import org.eclipse.swt.events.MouseAdapter;
+import org.eclipse.swt.events.MouseEvent;
+
+
+/**
+ * Row widget for editing a single CDM Authority
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+public class CdmAuthorityRow extends Composite {
+
+       private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
+       private Label lblEntity;
+       private Label lblUuid;
+       private CRUDOperationChooser operationChooser;
+       private Button btnDelete;
+       
+       private GrantedAuthorityImpl grantedAuthorityI;
+       private Label lblDirtyFlag;
+       
+       private CdmAuthorityCompositeViewer cdmaModel;
+       
+       /**
+        * Create the composite, made up of 5 elements :
+        * 1. '*' or depending on whether the row is being edited 
+        * 2. Classname of entity (e.g. TAXONNODE) 
+        * 3. Uuid of entity 
+        * 4. CRUD operations edit widget (this is essentially 4 checkboxes to select the 4 possible operations) 
+        * 5. Delete button (to delete the row) 
+        * 
+        * @param parent
+        * @param style
+        */
+       public CdmAuthorityRow(Composite parent, int style) {
+               super(parent, SWT.NONE);
+               addDisposeListener(new DisposeListener() {
+                       public void widgetDisposed(DisposeEvent e) {
+                               toolkit.dispose();
+                       }
+               });
+               toolkit.adapt(this);
+               toolkit.paintBordersFor(this);
+               setLayout(new GridLayout(5, false));
+               
+
+               
+               lblDirtyFlag = new Label(this, SWT.NONE);
+               lblDirtyFlag.setAlignment(SWT.CENTER);
+               GridData gd_lblDirtyFlag = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+               gd_lblDirtyFlag.widthHint = 15;
+               lblDirtyFlag.setLayoutData(gd_lblDirtyFlag);
+               toolkit.adapt(lblDirtyFlag, true, true);
+               lblDirtyFlag.setText("*");
+               
+               lblEntity = new Label(this, SWT.BORDER);
+               GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+               gd_lblEntity.heightHint = 30;
+               gd_lblEntity.widthHint = 200;
+               lblEntity.setLayoutData(gd_lblEntity);
+               lblEntity.setAlignment(SWT.CENTER);
+               toolkit.adapt(lblEntity, true, true);
+               lblEntity.setText("Entity");
+               
+               lblUuid = new Label(this, SWT.BORDER);
+               GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+               gd_lblUuid.heightHint = 30;
+               gd_lblUuid.widthHint = 270;
+               lblUuid.setLayoutData(gd_lblUuid);
+               lblUuid.setAlignment(SWT.CENTER);
+               toolkit.adapt(lblUuid, true, true);
+               lblUuid.setText("Uuid");
+               
+               operationChooser = new CRUDOperationChooser(this, SWT.BORDER);
+               operationChooser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+               toolkit.adapt(operationChooser);
+               toolkit.paintBordersFor(operationChooser);
+               
+               btnDelete = new Button(this, SWT.NONE);
+
+               btnDelete.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
+               btnDelete.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
+               btnDelete.addMouseListener(new MouseAdapter() {
+                       @Override
+                       public void mouseUp(MouseEvent arg0) {
+                               if(cdmaModel != null) {
+                                       cdmaModel.removeCdmAuthority(grantedAuthorityI);
+                               }
+                       }
+               });             
+               
+               toolkit.adapt(btnDelete, true, true);
+
+       }
+
+       /**
+        * Sets the dirty flag for this row
+        * 
+        * @param isDirty
+        */
+       public void setDirty(boolean isDirty) {
+               if(isDirty) {
+                       lblDirtyFlag.setText("*");
+               } else {
+                       lblDirtyFlag.setText(" ");
+               }
+       }
+       
+       /**
+        * Create a {@link CdmAuthority} from a {@link GrantedAuthorityImpl} and create a row from it.
+        * 
+        * @param cdmaModel
+        * @param grantedAuthorityI
+        * @param isDirty
+        */
+       public void setRowCdmAuthority(CdmAuthorityCompositeViewer cdmaModel, GrantedAuthorityImpl grantedAuthorityI, boolean isDirty) {
+               this.grantedAuthorityI = grantedAuthorityI;             
+               this.cdmaModel = cdmaModel;
+               
+               try {
+                       CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthorityI);
+
+                       setDirty(isDirty);
+
+                       String entityStr = (cdmAuthority.getPermissionClass() == null)?"":cdmAuthority.getPermissionClass().toString();
+                       lblEntity.setText(entityStr);
+                       String uuidStr = (cdmAuthority.getTargetUUID() == null)?"":cdmAuthority.getTargetUUID().toString();
+                       lblUuid.setText(uuidStr);
+
+                       operationChooser.setAuthority(cdmaModel, grantedAuthorityI, cdmAuthority);                              
+                       
+               } catch (Exception e) {
+                       // TODO Auto-generated catch block
+                       e.printStackTrace();
+               }
+
+       }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java
new file mode 100644 (file)
index 0000000..a47133b
--- /dev/null
@@ -0,0 +1,89 @@
+/**
+* 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.ui.group.grantedauthority;
+
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.custom.CLabel;
+
+/**
+ * Table header widget for {@link CdmAuthorityComposite}
+ * 
+ * @author cmathew
+ * @created Mar 28, 2013
+ *
+ */
+public class CdmAuthorityTableHeader extends Composite {
+
+       private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
+
+       /**
+        * Create the composite, with 5 header fields.
+        * 
+        * @param parent
+        * @param style
+        */
+       public CdmAuthorityTableHeader(Composite parent, int style) {
+               super(parent, SWT.NONE);
+               addDisposeListener(new DisposeListener() {
+                       public void widgetDisposed(DisposeEvent e) {
+                               toolkit.dispose();
+                       }
+               });
+               toolkit.adapt(this);
+               toolkit.paintBordersFor(this);
+               setLayout(new GridLayout(4, false));
+               
+               Label lblDirtyFlag = new Label(this, SWT.NONE);
+               GridData gd_lblDirtyFlag = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
+               gd_lblDirtyFlag.widthHint = 15;
+               lblDirtyFlag.setLayoutData(gd_lblDirtyFlag);
+               
+               toolkit.adapt(lblDirtyFlag, true, true);
+               
+               CLabel lblEntity = new CLabel(this, SWT.NONE);
+               lblEntity.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+               lblEntity.setAlignment(SWT.CENTER);
+               GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+               gd_lblEntity.widthHint = 200;
+               lblEntity.setLayoutData(gd_lblEntity);
+               toolkit.adapt(lblEntity);
+               toolkit.paintBordersFor(lblEntity);
+               lblEntity.setText("ENTITY");
+               
+               CLabel lblUuid = new CLabel(this, SWT.NONE);
+               lblUuid.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+               lblUuid.setAlignment(SWT.CENTER);
+               GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+               gd_lblUuid.widthHint = 270;
+               lblUuid.setLayoutData(gd_lblUuid);
+               toolkit.adapt(lblUuid);
+               toolkit.paintBordersFor(lblUuid);
+               lblUuid.setText("UUID");
+               
+               CLabel lblOperation = new CLabel(this, SWT.NONE);
+               lblOperation.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
+               lblOperation.setAlignment(SWT.CENTER);
+               GridData gd_lblOperation = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
+               gd_lblOperation.widthHint = 150;
+               lblOperation.setLayoutData(gd_lblOperation);
+               toolkit.adapt(lblOperation);
+               toolkit.paintBordersFor(lblOperation);
+               lblOperation.setText("OPERATION");
+
+       }
+
+}