Project

General

Profile

Revision ca7ac329

IDca7ac329e59529dd672b9d0df1274acb6d512f0e
Parent 3902bd1a
Child 19fa310b

Added by Cherian Mathew about 8 years ago

commits for the CDM Authority Composite and related widgets + drag/drop objects

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

View differences:

.gitattributes
1057 1057
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceSQLServerWizardPage.java -text
1058 1058
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceTypeSelectionWizardPage.java -text
1059 1059
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/datasource/wizard/CdmDataSourceWizard.java -text
1060
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java -text
1061
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java -text
1060 1062
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/ISecuredEditor.java -text
1061 1063
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/UsageTermCollection.java -text
1062 1064
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/editor/definedterm/DefinedTermDragListener.java -text
......
1292 1294
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/TimePeriodElement.java -text
1293 1295
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/ToggleableTextElement.java -text
1294 1296
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/UriWithLabelElement.java -text
1297
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java -text
1298
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java -text
1299
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java -text
1300
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java -text
1301
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java -text
1295 1302
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/IOpenUrlEnabled.java -text
1296 1303
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlContentProvider.java -text
1297 1304
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/openurl/OpenUrlLabelProvider.java -text
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
9 9
 eu.etaxonomy.cdm.database,
10 10
 eu.etaxonomy.taxeditor.datasource,
11 11
 eu.etaxonomy.taxeditor.datasource.wizard,
12
 eu.etaxonomy.taxeditor.dnd.transfer,
12 13
 eu.etaxonomy.taxeditor.editor,
13 14
 eu.etaxonomy.taxeditor.editor.definedterm,
14 15
 eu.etaxonomy.taxeditor.featuretree,
......
33 34
 eu.etaxonomy.taxeditor.ui.dialog,
34 35
 eu.etaxonomy.taxeditor.ui.dialog.selection,
35 36
 eu.etaxonomy.taxeditor.ui.element,
37
 eu.etaxonomy.taxeditor.ui.group.grantedauthority,
36 38
 eu.etaxonomy.taxeditor.ui.section,
37 39
 eu.etaxonomy.taxeditor.ui.section.agent,
38 40
 eu.etaxonomy.taxeditor.ui.section.classification,
......
53 55
 org.eclipse.ui,
54 56
 org.eclipse.jface.text,
55 57
 org.eclipse.ui.forms,
56
 eu.etaxonomy.taxeditor.cdmlib
58
 eu.etaxonomy.taxeditor.cdmlib,
59
 org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0"
57 60
Import-Package: org.eclipse.core.commands,
58 61
 org.eclipse.core.commands.operations,
59 62
 org.eclipse.core.expressions,
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/CdmAuthorityTableDropTargetListener.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.dnd;
10

  
11
import java.awt.Cursor;
12
import java.util.EnumSet;
13

  
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.dnd.DND;
16
import org.eclipse.swt.dnd.DropTargetEvent;
17
import org.eclipse.swt.dnd.DropTargetListener;
18

  
19
import eu.etaxonomy.cdm.model.common.CdmBase;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
22
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
23
import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
24
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityComposite;
25
import eu.etaxonomy.taxeditor.ui.group.grantedauthority.CdmAuthorityCompositeViewer;
26

  
27
/**
28
 * Drop listener for the {@link CdmAuthorityComposite}.
29
 * 
30
 * @author cmathew
31
 * @created Mar 28, 2013
32
 *
33
 */
34
public class CdmAuthorityTableDropTargetListener implements DropTargetListener {
35

  
36
	private CdmAuthorityCompositeViewer viewer;
37
	
38
	
39
	public CdmAuthorityTableDropTargetListener(CdmAuthorityCompositeViewer viewer) {
40
		this.viewer = viewer;
41
	}
42
	/* (non-Javadoc)
43
	 * @see org.eclipse.swt.dnd.DropTargetListener#dragEnter(org.eclipse.swt.dnd.DropTargetEvent)
44
	 */
45
	@Override
46
	public void dragEnter(DropTargetEvent event) {				
47
	}
48

  
49
	/* (non-Javadoc)
50
	 * @see org.eclipse.swt.dnd.DropTargetListener#dragLeave(org.eclipse.swt.dnd.DropTargetEvent)
51
	 */
52
	@Override
53
	public void dragLeave(DropTargetEvent arg0) {
54
	}
55

  
56
	/* (non-Javadoc)
57
	 * @see org.eclipse.swt.dnd.DropTargetListener#dragOperationChanged(org.eclipse.swt.dnd.DropTargetEvent)
58
	 */
59
	@Override
60
	public void dragOperationChanged(DropTargetEvent arg0) {
61
	}
62

  
63
	/* (non-Javadoc)
64
	 * @see org.eclipse.swt.dnd.DropTargetListener#dragOver(org.eclipse.swt.dnd.DropTargetEvent)
65
	 */
66
	@Override
67
	public void dragOver(DropTargetEvent arg0) {
68
	}
69

  
70
	/* (non-Javadoc)
71
	 * @see org.eclipse.swt.dnd.DropTargetListener#drop(org.eclipse.swt.dnd.DropTargetEvent)
72
	 */
73
	@Override
74
	public void drop(DropTargetEvent dtevent) {
75
		if(TaxonNodeTransfer.getInstance().isSupportedType(dtevent.currentDataType)) {
76
			Object[] selectedCdmBases = (Object[])dtevent.data;
77
			
78
			for (Object cdmBase : selectedCdmBases){
79
				if(CdmBase.class.isAssignableFrom(cdmBase.getClass()) ) {
80
					viewer.addCdmAuthority((CdmBase)cdmBase);					
81
				}
82
			}
83
		}		
84
	}
85

  
86
	/* (non-Javadoc)
87
	 * @see org.eclipse.swt.dnd.DropTargetListener#dropAccept(org.eclipse.swt.dnd.DropTargetEvent)
88
	 */
89
	@Override
90
	public void dropAccept(DropTargetEvent arg0) {
91
	}
92

  
93
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/dnd/transfer/TaxonNodeTransfer.java
1

  
2
//$Id$
3
/**
4
* Copyright (C) 2007 EDIT
5
* European Distributed Institute of Taxonomy 
6
* http://www.e-taxonomy.eu
7
* 
8
* The contents of this file are subject to the Mozilla Public License Version 1.1
9
* See LICENSE.TXT at the top of this package for the full license terms.
10
*/
11

  
12
package eu.etaxonomy.taxeditor.dnd.transfer;
13

  
14
import java.util.UUID;
15

  
16
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
18
import eu.etaxonomy.taxeditor.model.CdmObjectTransfer;
19
import eu.etaxonomy.taxeditor.store.CdmStore;
20

  
21
/**
22
 * Drag / Drop Transfer object for Taxon Node 
23
 * 
24
 * @author c.mathew
25
 * @created Mar 25, 2013
26
 */
27
public class TaxonNodeTransfer extends CdmObjectTransfer<TaxonNode> {
28

  
29
	private static TaxonNodeTransfer instance = new TaxonNodeTransfer();
30
	private static final String TYPE_NAME = "taxonNode-transfer-format";
31
	private static final int TYPEID = registerType(TYPE_NAME);
32
	
33
	public static synchronized TaxonNodeTransfer getInstance(){
34
		return instance;
35
	}
36
	
37
	private TaxonNodeTransfer(){}
38
	
39
	/* (non-Javadoc)
40
	 * @see org.eclipse.swt.dnd.Transfer#getTypeIds()
41
	 */
42
	@Override
43
	protected int[] getTypeIds() {
44
		return new int[] { TYPEID };
45
	}
46

  
47
	/* (non-Javadoc)
48
	 * @see org.eclipse.swt.dnd.Transfer#getTypeNames()
49
	 */
50
	@Override
51
	protected String[] getTypeNames() {
52
		return new String[] { TYPE_NAME };
53
	}
54

  
55
	/* (non-Javadoc)
56
	 * @see eu.etaxonomy.taxeditor.model.CdmObjectTransfer#loadElement(java.util.UUID)
57
	 */
58
	@Override
59
	public TaxonNode loadElement(UUID uuid) {
60
		return CdmStore.getService(ITaxonNodeService.class).load(uuid, null);
61
	}
62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CRUDOperationChooser.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
10

  
11
import org.eclipse.swt.widgets.Composite;
12
import org.eclipse.swt.widgets.Button;
13
import org.eclipse.swt.widgets.Display;
14
import org.eclipse.swt.SWT;
15
import org.eclipse.swt.layout.RowLayout;
16

  
17
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
18
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
19
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
20
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
21

  
22
import org.eclipse.swt.events.MouseAdapter;
23
import org.eclipse.swt.events.MouseEvent;
24
import org.eclipse.swt.events.MouseTrackAdapter;
25

  
26

  
27
/**
28
 * Widget for editing {@link Operation} objects, consisting of 4 checkboxes for CREATE, UPDATE, READ, DELETE operations.
29
 * 
30
 * @author cmathew
31
 * @created Mar 28, 2013
32
 *
33
 */
34
public class CRUDOperationChooser extends Composite {
35
	
36
	private Button createCheckButton;
37
	private Button readCheckButton;
38
	private Button deleteCheckButton;
39
	private Button updateCheckButton;
40
	
41
	private CdmAuthorityRow caRow;
42
	private GrantedAuthorityImpl grantedAuthorityI;
43
	private CdmAuthority cdmAuthority;
44
	private CdmAuthorityCompositeViewer viewer;
45
	
46
	/**
47
	 * Create the composite.
48
	 * @param parent
49
	 * @param style
50
	 */
51
	public CRUDOperationChooser(final CdmAuthorityRow parent, int style) {
52
		super(parent, style);
53
		setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
54
		RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
55
		rowLayout.justify = true;
56
		setLayout(rowLayout);
57
		
58
		
59
		this.caRow = parent;
60
		createCheckButton = new Button(this, SWT.CHECK);
61
		createCheckButton.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
62
		createCheckButton.addMouseListener(new MouseAdapter() {
63
			@Override
64
			public void mouseUp(MouseEvent arg0) {
65
				if(cdmAuthority.getOperation() != null) {
66
					if(createCheckButton.getSelection()) {
67
						cdmAuthority.getOperation().add(CRUD.CREATE);
68
					} else {
69
						cdmAuthority.getOperation().remove(CRUD.CREATE);
70
					}
71
					if(viewer != null) {
72
						viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
73
						parent.setDirty(true);
74
					}
75
					
76
				}
77
			}
78
		});
79
		createCheckButton.setText("C");
80
		
81
		readCheckButton = new Button(this, SWT.CHECK);
82
		readCheckButton.addMouseTrackListener(new MouseTrackAdapter() {
83
			@Override
84
			public void mouseHover(MouseEvent arg0) {
85
			}
86
		});
87
		readCheckButton.addMouseListener(new MouseAdapter() {
88
			@Override
89
			public void mouseUp(MouseEvent arg0) {
90
				if(cdmAuthority.getOperation() != null) {
91
					if(readCheckButton.getSelection()) {
92
						cdmAuthority.getOperation().add(CRUD.READ);
93
					} else {
94
						cdmAuthority.getOperation().remove(CRUD.READ);
95
					}
96
					if(viewer != null) {
97
						viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
98
						parent.setDirty(true);
99
					}
100
					
101
				}
102
					
103
			}
104
		});
105
		readCheckButton.setText("R");
106
		
107
		deleteCheckButton = new Button(this, SWT.CHECK);
108
		deleteCheckButton.addMouseListener(new MouseAdapter() {
109
			@Override
110
			public void mouseUp(MouseEvent arg0) {
111
				if(cdmAuthority.getOperation() != null) {
112
					if(deleteCheckButton.getSelection()) {
113
						cdmAuthority.getOperation().add(CRUD.DELETE);
114
					} else {
115
						cdmAuthority.getOperation().remove(CRUD.DELETE);
116
					}
117
					if(viewer != null) {
118
						viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
119
						parent.setDirty(true);
120
					}
121
					
122
				}
123
			}
124
		});
125
		deleteCheckButton.setText("D");
126
		
127
		updateCheckButton = new Button(this, SWT.CHECK);
128
		updateCheckButton.addMouseListener(new MouseAdapter() {
129
			@Override
130
			public void mouseUp(MouseEvent arg0) {
131
				if(cdmAuthority.getOperation() != null) {
132
					if(updateCheckButton.getSelection()) {
133
						cdmAuthority.getOperation().add(CRUD.UPDATE);
134
					} else {
135
						cdmAuthority.getOperation().remove(CRUD.UPDATE);
136
					}
137
					if(viewer != null) {
138
						viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
139
						parent.setDirty(true);
140
					}
141
					
142
				}
143
			}
144
		});
145
		updateCheckButton.setText("U");
146
		updateView();
147
	}
148

  
149
	
150
	@Override
151
	protected void checkSubclass() {
152
		// Disable the check that prevents subclassing of SWT components
153
	}
154
	
155
	/**
156
	 * Set viewer, CDM Authority and corresponding GrantedAuthorityImpl object
157
	 * 
158
	 * @param viewer
159
	 * @param grantedAuthorityI
160
	 * @param cdmAuthority
161
	 */
162
	public void setAuthority(CdmAuthorityCompositeViewer viewer, 
163
			GrantedAuthorityImpl grantedAuthorityI,
164
			CdmAuthority cdmAuthority) {
165
		this.grantedAuthorityI = grantedAuthorityI;
166
		this.cdmAuthority = cdmAuthority;
167
		this.viewer = viewer;
168
		updateView();
169
	}
170
	
171

  
172
	
173
	/**
174
	 * Update widget state.
175
	 */
176
	private void updateView() {
177
		createCheckButton.setSelection(false);
178
		readCheckButton.setSelection(false);
179
		deleteCheckButton.setSelection(false);
180
		updateCheckButton.setSelection(false);
181
		
182
		
183
		if(cdmAuthority!= null && cdmAuthority.getOperation() != null) {
184
			if(cdmAuthority.getOperation().contains(CRUD.CREATE)) {
185
				createCheckButton.setSelection(true);
186
			}
187
			if(cdmAuthority.getOperation().contains(CRUD.READ)) {
188
				readCheckButton.setSelection(true);
189
			}
190
			if(cdmAuthority.getOperation().contains(CRUD.DELETE)) {
191
				deleteCheckButton.setSelection(true);
192
			}
193
			if(cdmAuthority.getOperation().contains(CRUD.UPDATE)) {
194
				updateCheckButton.setSelection(true);
195
			}
196

  
197
		}
198
	}
199

  
200
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityComposite.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
10

  
11
import org.eclipse.nebula.widgets.compositetable.CompositeTable;
12
import org.eclipse.nebula.widgets.compositetable.IRowContentProvider;
13

  
14
import org.eclipse.swt.events.DisposeEvent;
15
import org.eclipse.swt.events.DisposeListener;
16
import org.eclipse.swt.widgets.Composite;
17
import org.eclipse.swt.widgets.Display;
18
import org.eclipse.ui.forms.widgets.FormToolkit;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Control;
21

  
22
import eu.etaxonomy.taxeditor.dnd.CdmAuthorityTableDropTargetListener;
23
import eu.etaxonomy.taxeditor.dnd.transfer.TaxonNodeTransfer;
24

  
25
import org.eclipse.swt.dnd.DropTarget;
26
import org.eclipse.swt.dnd.DND;
27
import org.eclipse.swt.dnd.Transfer;
28
import org.eclipse.swt.layout.GridLayout;
29
import org.eclipse.swt.widgets.Label;
30
import org.eclipse.swt.layout.GridData;
31

  
32
/**
33
 * Composite class which consists of a {@link CompositeTable} built specifically
34
 * for creating / editing CDM Authority objects
35
 * 
36
 * @author cmathew
37
 * @created Mar 28, 2013
38
 *
39
 */
40

  
41
public class CdmAuthorityComposite extends Composite {
42

  
43
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
44
	private CompositeTable table;
45
	
46
	private int numOfInitialCdmAuthorities;
47

  
48
	private Label lblDragEntityInto;
49
	
50
	private CdmAuthorityCompositeViewer viewer;
51
	
52

  
53
	/**
54
	 * Creates the composite using the given parent, style and associated viewer.
55
	 * 
56
	 * @param parent composite to use as parent of this composite
57
	 * @param style 
58
	 * @param viewer viewer representing the model
59
	 */
60
	public CdmAuthorityComposite(Composite parent, int style, final CdmAuthorityCompositeViewer viewer) {
61
		super(parent, style);
62
		addDisposeListener(new DisposeListener() {
63
			public void widgetDisposed(DisposeEvent e) {
64
				toolkit.dispose();
65
			}
66
		});
67
		
68
		this.viewer = viewer;
69
				
70
		numOfInitialCdmAuthorities = viewer.getCdmAuthorities().size();
71
		setLayout(new GridLayout(1, false));
72
	    Transfer[] transfers = new Transfer[] { TaxonNodeTransfer.getInstance() };	   
73
	    
74
	    toolkit.adapt(this);
75
		toolkit.paintBordersFor(this);		
76

  
77
		lblDragEntityInto = new Label(this, SWT.NONE);
78
		toolkit.adapt(lblDragEntityInto, true, true);
79
		lblDragEntityInto.setText("Drag Entity into table to add ...");
80
		table = new CompositeTable(this, SWT.BORDER);
81
		GridData gd_table = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
82
		gd_table.widthHint = 750;
83
		gd_table.heightHint = 400;
84
		table.setLayoutData(gd_table);
85
		new CdmAuthorityTableHeader(table, SWT.NULL); 
86
		CdmAuthorityRow cdmAuthorityRow = new CdmAuthorityRow(table, SWT.NULL);
87
		
88
		table.setRunTime(true);
89
		table.setNumRowsInCollection(numOfInitialCdmAuthorities);
90
		table.setLinesVisible(true); 
91
		
92
		DropTarget dropTarget = new DropTarget(table, DND.DROP_MOVE);
93
		dropTarget.setTransfer(transfers);
94
		dropTarget.addDropListener(new CdmAuthorityTableDropTargetListener(viewer));
95
		
96
		
97
		table.addRowContentProvider(new IRowContentProvider() {
98
			public void refresh(CompositeTable sender, int currentObjectOffset, Control rowControl) {
99
				CdmAuthorityRow row = (CdmAuthorityRow) rowControl;		
100
				// add the newly created authority objects first and then the already existing ones.
101
				// this ensures the newly 'dragged' in objects always remain at the top
102
				if(currentObjectOffset < viewer.getNewCdmAuthorities().size()) {			
103
					row.setRowCdmAuthority(viewer, 
104
							viewer.getNewCdmAuthorities().get(currentObjectOffset), 
105
							true);
106
				} else {
107
					row.setRowCdmAuthority(viewer, 
108
							viewer.getCdmAuthorities().get(currentObjectOffset - viewer.getNewCdmAuthorities().size()), 
109
							false);
110
				}										
111
			}
112
		});
113
	}	
114

  
115
	/**
116
	 * Refreshes the table with underlying data
117
	 */
118
	public void refresh() {			
119
		numOfInitialCdmAuthorities = viewer.getNewCdmAuthorities().size() + viewer.getCdmAuthorities().size();			    	    
120
	    table.setNumRowsInCollection(numOfInitialCdmAuthorities);	  
121
	    table.refreshAllRows();
122
	}
123
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityCompositeViewer.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
11

  
12
import java.util.ArrayList;
13
import java.util.EnumSet;
14
import java.util.Iterator;
15
import java.util.List;
16
import java.util.Set;
17

  
18
import org.eclipse.jface.viewers.ContentViewer;
19
import org.eclipse.jface.viewers.ISelection;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.springframework.security.core.GrantedAuthority;
24

  
25
import eu.etaxonomy.cdm.model.common.CdmBase;
26
import eu.etaxonomy.cdm.model.common.Group;
27
import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
28
import eu.etaxonomy.taxeditor.store.StoreUtil;
29
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
30
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
31
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
32

  
33

  
34

  
35
/**
36
 * Viewer class for the {@link CdmAuthorityComposite} used in the editing of CDM Authorities.
37
 * 
38
 * @author cmathew
39
 * @created Mar 28, 2013
40
 *
41
 */
42

  
43

  
44
/**
45
 * @author cmathew
46
 * @date Apr 5, 2013
47
 *
48
 */
49

  
50
//FIXME:move warning dialogs to the table class
51
public class CdmAuthorityCompositeViewer extends ContentViewer {
52
	
53
	private IDirtyMarkableSelectionProvider dirtyMarkerEditor;	
54
	private CdmAuthorityComposite cdmAuthorityComposite;
55
	private Group group;
56
	/**
57
	 * List which contains already existing authority objects.
58
	 */
59
	private List<GrantedAuthorityImpl> cdmAuthorities;
60
	/**
61
	 * List which contains newly added (unsaved) authority objects.
62
	 * Used to make sure that new authority objects are always added 
63
	 * to the top of the table.
64
	 */
65
	private List<GrantedAuthorityImpl> newCdmAuthorities;
66
	
67
	
68
	/**
69
	 * Creates a viewer with a {@link CdmAuthorityComposite} table, {@link Group} object as input 
70
	 * 
71
	 * @param composite parent of generated {@link CdmAuthorityComposite}
72
	 * @param dirtyMarkerEditor provider to mark as dirty
73
	 * @param group input data object
74
	 */
75
	public CdmAuthorityCompositeViewer(Composite composite,
76
			IDirtyMarkableSelectionProvider dirtyMarkerEditor, 
77
			Group group) {
78
		this.dirtyMarkerEditor = dirtyMarkerEditor;
79
		this.group = group;
80
		newCdmAuthorities = new ArrayList<GrantedAuthorityImpl>();		
81
		updateAuthorities();
82
		this.cdmAuthorityComposite = new CdmAuthorityComposite(composite, SWT.NONE, this);
83
	}
84

  
85
	/**
86
	 * Gets the {@link CdmAuthorityComposite}
87
	 * 
88
	 * @return {@link CdmAuthorityComposite} generated by this viewer
89
	 */
90
	public CdmAuthorityComposite getCdmAuthorityComposite() {
91
		return cdmAuthorityComposite;
92
	}
93
	
94
	
95
	/**
96
	 * Retrieves the {@link GrantedAuthorityImpl} objects of the group attached to this viewer
97
	 * creates a sub-list of only {@link CdmAuthority} objects.
98
	 * 
99
	 * @return list of {@link CdmAuthority} objects belonging to the input group
100
	 */
101
	public List<GrantedAuthorityImpl> updateAuthorities()  {
102
		// get all granted authorities
103
		Set<GrantedAuthority> grantedAuthorities = group.getGrantedAuthorities();
104
		cdmAuthorities = new ArrayList<GrantedAuthorityImpl>();	
105
		
106
		Iterator<GrantedAuthority> itr = grantedAuthorities.iterator();		
107
		while (itr.hasNext()) {
108
			GrantedAuthority grantedAuthority = itr.next();
109
			try {
110
				
111
				if(grantedAuthority != null && grantedAuthority instanceof GrantedAuthorityImpl) {			
112
					// create a cdm authority from a granted authority
113
					// this could fail in which case an exception is thrown
114
					CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthority);
115
					cdmAuthorities.add((GrantedAuthorityImpl)grantedAuthority);				
116
				}
117
			} catch (Exception e) {
118
				// not a CdmAuthority				
119
				//e.printStackTrace();
120
			}			
121
		}
122
		return cdmAuthorities;
123
	}
124
	
125
	/**
126
	 * Adds a new {@link CdmAuthority} to the group attached to this viewer
127
	 * based on the input {@link CdmBase} object.
128
	 * 
129
	 * @param cb {@link CdmBase} object used to construct the cdm authority
130
	 */
131
	public void addCdmAuthority(CdmBase cb) {
132
		// Default permission is to READ
133
		EnumSet<CRUD> defaultOperation = EnumSet.noneOf(CRUD.class);
134
		defaultOperation.add(CRUD.READ);
135
		CdmAuthority cdma = new CdmAuthority(cb, defaultOperation, cb.getUuid());
136
		GrantedAuthorityImpl gai;
137
		try {
138
			// create a granted authrity from a cdm authority 
139
			gai = cdma.asNewGrantedAuthority();
140
		} catch (Exception e) {			
141
			StoreUtil.warningDialog("Parsing Error", this, "Could not parse authority string");
142
			return;
143
		}
144
		//FIXME : this contains call will allow users to add authorities which differ only in CRUD operation choice.
145
		//        need to have a comparator which only checks permission class and uuid
146
		if(cdmAuthorities.contains(gai)) {
147
			StoreUtil.warningDialog("Duplicate CDM Authority", this, "Chosen CDM Authority is already attached to current group");
148
		} else {								
149
			group.addGrantedAuthority(gai);
150
			newCdmAuthorities.add(gai);				
151
			dirtyMarkerEditor.changed(group);		
152
			cdmAuthorityComposite.refresh();
153
		}
154
	}
155
	
156
	/**
157
	 * Removes the given {@link GrantedAuthorityImpl} object from the list of
158
	 * granted authorities belonging to the group attached to this viewer.
159
	 * 
160
	 * @param gai {@link GrantedAuthorityImpl} object to remove
161
	 */
162
	public void removeCdmAuthority(GrantedAuthorityImpl gai) {
163
		if(cdmAuthorities.contains(gai)) {
164
			group.removeGrantedAuthority(gai);
165
			newCdmAuthorities.remove(gai);
166
			cdmAuthorities.remove(gai);
167
			dirtyMarkerEditor.changed(group);	
168
			cdmAuthorityComposite.refresh();
169
		} else {
170
			StoreUtil.warningDialog("Unknown CDM Authority", this, "Chosen CDM Authority does not exist in  current group");
171
		}
172
	}
173
	
174
	/**
175
	 * Updates an existing {@link GrantedAuthorityImpl} object using a {@link CdmAuthority} object.
176
	 * 
177
	 * @param grantedAuthorityI to update.
178
	 * @param cdmAuthority to use in updating the granted authority object.
179
	 */
180
	public void updateGrantedAuthority(GrantedAuthorityImpl grantedAuthorityI, CdmAuthority cdmAuthority) {
181
		if(grantedAuthorityI.getAuthority().equals(cdmAuthority.getAuthority())) {
182
			
183
		} else {
184
			try {
185
				// since granted authority is just a wrapper object around a string
186
				// we can't really 'update' the granted authority.
187
				// so we first add the new authority (hope no exception) is thrown
188
				// and then remove the old one.
189
				group.addGrantedAuthority(cdmAuthority.asNewGrantedAuthority());
190
				group.removeGrantedAuthority(grantedAuthorityI);
191
				dirtyMarkerEditor.changed(grantedAuthorityI);				
192
			} catch(Exception e) {
193
				// Not a CDM Authority
194
				//e.printStackTrace();
195
			}
196
		}		
197
	}
198
	
199
	/**
200
	 * @return list of existing cdm authority objects
201
	 */
202
	public List<GrantedAuthorityImpl> getCdmAuthorities() {
203
		return cdmAuthorities;
204
	}
205
	
206
	/**
207
	 * @return list of newly added cdm authority objects
208
	 */
209
	public List<GrantedAuthorityImpl> getNewCdmAuthorities() {
210
		return newCdmAuthorities;
211
	}
212
	
213

  
214
	/**
215
	 * Empty the list of newly create autrity objects
216
	 */
217
	public void clearNewCdmAuthorities() {
218
		newCdmAuthorities.clear();
219
	}
220

  
221
	
222
	/**
223
	 * 
224
	 * 
225
	 */
226
	public void save() {
227
		clearNewCdmAuthorities();		
228
		refresh();
229
		
230
	}	
231
	
232
	/* (non-Javadoc)
233
	 * @see org.eclipse.jface.viewers.Viewer#getControl()
234
	 */
235
	@Override
236
	public Control getControl() {
237
		return cdmAuthorityComposite;
238
	}
239

  
240
	/* (non-Javadoc)
241
	 * @see org.eclipse.jface.viewers.Viewer#getSelection()
242
	 */
243
	@Override
244
	public ISelection getSelection() {
245
		// TODO Auto-generated method stub
246
		return null;
247
	}
248

  
249
	/* (non-Javadoc)
250
	 * @see org.eclipse.jface.viewers.Viewer#refresh()
251
	 */
252
	@Override
253
	public void refresh() {
254
		updateAuthorities();
255
		cdmAuthorityComposite.refresh();
256
		
257
	}
258

  
259
	/* (non-Javadoc)
260
	 * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
261
	 */
262
	@Override
263
	public void setSelection(ISelection selection, boolean reveal) {
264
		// TODO Auto-generated method stub
265
		
266
	}
267
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityRow.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
10

  
11
import org.eclipse.swt.events.DisposeEvent;
12
import org.eclipse.swt.events.DisposeListener;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Display;
15
import org.eclipse.ui.forms.widgets.FormToolkit;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.SWT;
19

  
20
import org.eclipse.swt.widgets.Button;
21
import org.eclipse.swt.layout.GridData;
22

  
23
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
24
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
25
import eu.etaxonomy.taxeditor.model.ImageResources;
26

  
27
import org.eclipse.swt.events.MouseAdapter;
28
import org.eclipse.swt.events.MouseEvent;
29

  
30

  
31
/**
32
 * Row widget for editing a single CDM Authority
33
 * 
34
 * @author cmathew
35
 * @created Mar 28, 2013
36
 *
37
 */
38
public class CdmAuthorityRow extends Composite {
39

  
40
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
41
	private Label lblEntity;
42
	private Label lblUuid;
43
	private CRUDOperationChooser operationChooser;
44
	private Button btnDelete;
45
	
46
	private GrantedAuthorityImpl grantedAuthorityI;
47
	private Label lblDirtyFlag;
48
	
49
	private CdmAuthorityCompositeViewer cdmaModel;
50
	
51
	/**
52
	 * Create the composite, made up of 5 elements :
53
	 * 1. '*' or depending on whether the row is being edited 
54
	 * 2. Classname of entity (e.g. TAXONNODE) 
55
	 * 3. Uuid of entity 
56
	 * 4. CRUD operations edit widget (this is essentially 4 checkboxes to select the 4 possible operations) 
57
	 * 5. Delete button (to delete the row) 
58
	 * 
59
	 * @param parent
60
	 * @param style
61
	 */
62
	public CdmAuthorityRow(Composite parent, int style) {
63
		super(parent, SWT.NONE);
64
		addDisposeListener(new DisposeListener() {
65
			public void widgetDisposed(DisposeEvent e) {
66
				toolkit.dispose();
67
			}
68
		});
69
		toolkit.adapt(this);
70
		toolkit.paintBordersFor(this);
71
		setLayout(new GridLayout(5, false));
72
		
73

  
74
		
75
		lblDirtyFlag = new Label(this, SWT.NONE);
76
		lblDirtyFlag.setAlignment(SWT.CENTER);
77
		GridData gd_lblDirtyFlag = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
78
		gd_lblDirtyFlag.widthHint = 15;
79
		lblDirtyFlag.setLayoutData(gd_lblDirtyFlag);
80
		toolkit.adapt(lblDirtyFlag, true, true);
81
		lblDirtyFlag.setText("*");
82
		
83
		lblEntity = new Label(this, SWT.BORDER);
84
		GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
85
		gd_lblEntity.heightHint = 30;
86
		gd_lblEntity.widthHint = 200;
87
		lblEntity.setLayoutData(gd_lblEntity);
88
		lblEntity.setAlignment(SWT.CENTER);
89
		toolkit.adapt(lblEntity, true, true);
90
		lblEntity.setText("Entity");
91
		
92
		lblUuid = new Label(this, SWT.BORDER);
93
		GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
94
		gd_lblUuid.heightHint = 30;
95
		gd_lblUuid.widthHint = 270;
96
		lblUuid.setLayoutData(gd_lblUuid);
97
		lblUuid.setAlignment(SWT.CENTER);
98
		toolkit.adapt(lblUuid, true, true);
99
		lblUuid.setText("Uuid");
100
		
101
		operationChooser = new CRUDOperationChooser(this, SWT.BORDER);
102
		operationChooser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
103
		toolkit.adapt(operationChooser);
104
		toolkit.paintBordersFor(operationChooser);
105
		
106
		btnDelete = new Button(this, SWT.NONE);
107

  
108
		btnDelete.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
109
		btnDelete.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
110
		btnDelete.addMouseListener(new MouseAdapter() {
111
			@Override
112
			public void mouseUp(MouseEvent arg0) {
113
				if(cdmaModel != null) {
114
					cdmaModel.removeCdmAuthority(grantedAuthorityI);
115
				}
116
			}
117
		});		
118
		
119
		toolkit.adapt(btnDelete, true, true);
120

  
121
	}
122

  
123
	/**
124
	 * Sets the dirty flag for this row
125
	 * 
126
	 * @param isDirty
127
	 */
128
	public void setDirty(boolean isDirty) {
129
		if(isDirty) {
130
			lblDirtyFlag.setText("*");
131
		} else {
132
			lblDirtyFlag.setText(" ");
133
		}
134
	}
135
	
136
	/**
137
	 * Create a {@link CdmAuthority} from a {@link GrantedAuthorityImpl} and create a row from it.
138
	 * 
139
	 * @param cdmaModel
140
	 * @param grantedAuthorityI
141
	 * @param isDirty
142
	 */
143
	public void setRowCdmAuthority(CdmAuthorityCompositeViewer cdmaModel, GrantedAuthorityImpl grantedAuthorityI, boolean isDirty) {
144
		this.grantedAuthorityI = grantedAuthorityI;		
145
		this.cdmaModel = cdmaModel;
146
		
147
		try {
148
			CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthorityI);
149

  
150
			setDirty(isDirty);
151

  
152
			String entityStr = (cdmAuthority.getPermissionClass() == null)?"":cdmAuthority.getPermissionClass().toString();
153
			lblEntity.setText(entityStr);
154
			String uuidStr = (cdmAuthority.getTargetUUID() == null)?"":cdmAuthority.getTargetUUID().toString();
155
			lblUuid.setText(uuidStr);
156

  
157
			operationChooser.setAuthority(cdmaModel, grantedAuthorityI, cdmAuthority);				
158
			
159
		} catch (Exception e) {
160
			// TODO Auto-generated catch block
161
			e.printStackTrace();
162
		}
163

  
164
	}
165

  
166
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/group/grantedauthority/CdmAuthorityTableHeader.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy 
4
* http://www.e-taxonomy.eu
5
* 
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.ui.group.grantedauthority;
10

  
11
import org.eclipse.swt.events.DisposeEvent;
12
import org.eclipse.swt.events.DisposeListener;
13
import org.eclipse.swt.widgets.Composite;
14
import org.eclipse.swt.widgets.Display;
15
import org.eclipse.ui.forms.widgets.FormToolkit;
16
import org.eclipse.swt.layout.GridLayout;
17
import org.eclipse.swt.widgets.Label;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.layout.GridData;
20
import org.eclipse.swt.custom.CLabel;
21

  
22
/**
23
 * Table header widget for {@link CdmAuthorityComposite}
24
 * 
25
 * @author cmathew
26
 * @created Mar 28, 2013
27
 *
28
 */
29
public class CdmAuthorityTableHeader extends Composite {
30

  
31
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
32

  
33
	/**
34
	 * Create the composite, with 5 header fields.
35
	 * 
36
	 * @param parent
37
	 * @param style
38
	 */
39
	public CdmAuthorityTableHeader(Composite parent, int style) {
40
		super(parent, SWT.NONE);
41
		addDisposeListener(new DisposeListener() {
42
			public void widgetDisposed(DisposeEvent e) {
43
				toolkit.dispose();
44
			}
45
		});
46
		toolkit.adapt(this);
47
		toolkit.paintBordersFor(this);
48
		setLayout(new GridLayout(4, false));
49
		
50
		Label lblDirtyFlag = new Label(this, SWT.NONE);
51
		GridData gd_lblDirtyFlag = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
52
		gd_lblDirtyFlag.widthHint = 15;
53
		lblDirtyFlag.setLayoutData(gd_lblDirtyFlag);
54
		
55
		toolkit.adapt(lblDirtyFlag, true, true);
56
		
57
		CLabel lblEntity = new CLabel(this, SWT.NONE);
58
		lblEntity.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
59
		lblEntity.setAlignment(SWT.CENTER);
60
		GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
61
		gd_lblEntity.widthHint = 200;
62
		lblEntity.setLayoutData(gd_lblEntity);
63
		toolkit.adapt(lblEntity);
64
		toolkit.paintBordersFor(lblEntity);
65
		lblEntity.setText("ENTITY");
66
		
67
		CLabel lblUuid = new CLabel(this, SWT.NONE);
68
		lblUuid.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
69
		lblUuid.setAlignment(SWT.CENTER);
70
		GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
71
		gd_lblUuid.widthHint = 270;
72
		lblUuid.setLayoutData(gd_lblUuid);
73
		toolkit.adapt(lblUuid);
74
		toolkit.paintBordersFor(lblUuid);
75
		lblUuid.setText("UUID");
76
		
77
		CLabel lblOperation = new CLabel(this, SWT.NONE);
78
		lblOperation.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
79
		lblOperation.setAlignment(SWT.CENTER);
80
		GridData gd_lblOperation = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
81
		gd_lblOperation.widthHint = 150;
82
		lblOperation.setLayoutData(gd_lblOperation);
83
		toolkit.adapt(lblOperation);
84
		toolkit.paintBordersFor(lblOperation);
85
		lblOperation.setText("OPERATION");
86

  
87
	}
88

  
89
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)