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.SWT;
|
12
|
import org.eclipse.swt.events.DisposeEvent;
|
13
|
import org.eclipse.swt.events.DisposeListener;
|
14
|
import org.eclipse.swt.events.MouseAdapter;
|
15
|
import org.eclipse.swt.events.MouseEvent;
|
16
|
import org.eclipse.swt.layout.GridData;
|
17
|
import org.eclipse.swt.layout.GridLayout;
|
18
|
import org.eclipse.swt.widgets.Button;
|
19
|
import org.eclipse.swt.widgets.Composite;
|
20
|
import org.eclipse.swt.widgets.Display;
|
21
|
import org.eclipse.swt.widgets.Label;
|
22
|
import org.eclipse.ui.forms.widgets.FormToolkit;
|
23
|
|
24
|
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
|
25
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
|
26
|
import eu.etaxonomy.taxeditor.model.ImageResources;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityLabelTextProvider;
|
28
|
|
29
|
|
30
|
/**
|
31
|
* Row widget for editing a single CDM Authority
|
32
|
*
|
33
|
* @author cmathew
|
34
|
* @created Mar 28, 2013
|
35
|
*
|
36
|
*/
|
37
|
public class CdmAuthorityRow extends Composite {
|
38
|
|
39
|
private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
|
40
|
private Label lblEntity;
|
41
|
private Label lblUuid;
|
42
|
private CRUDOperationChooser operationChooser;
|
43
|
private Button btnDelete;
|
44
|
|
45
|
private GrantedAuthorityImpl grantedAuthorityI;
|
46
|
private Label lblDirtyFlag;
|
47
|
|
48
|
private CdmAuthorityCompositeViewer cdmaModel;
|
49
|
private Label lblType;
|
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(6, 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
|
lblType = new Label(this, SWT.BORDER);
|
84
|
GridData gd_lblType = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
|
85
|
gd_lblType.heightHint = 30;
|
86
|
gd_lblType.widthHint = 200;
|
87
|
lblType.setLayoutData(gd_lblType);
|
88
|
lblType.setText("Type");
|
89
|
lblType.setAlignment(SWT.CENTER);
|
90
|
toolkit.adapt(lblType, true, true);
|
91
|
|
92
|
lblEntity = new Label(this, SWT.BORDER | SWT.WRAP | SWT.CENTER);
|
93
|
GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
|
94
|
gd_lblEntity.heightHint = 30;
|
95
|
gd_lblEntity.widthHint = 200;
|
96
|
lblEntity.setLayoutData(gd_lblEntity);
|
97
|
lblEntity.setAlignment(SWT.CENTER);
|
98
|
toolkit.adapt(lblEntity, true, true);
|
99
|
lblEntity.setText("Entity");
|
100
|
|
101
|
|
102
|
operationChooser = new CRUDOperationChooser(this, SWT.BORDER);
|
103
|
operationChooser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
|
104
|
toolkit.adapt(operationChooser);
|
105
|
toolkit.paintBordersFor(operationChooser);
|
106
|
|
107
|
btnDelete = new Button(this, SWT.NONE);
|
108
|
|
109
|
btnDelete.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
|
110
|
btnDelete.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
|
111
|
btnDelete.addMouseListener(new MouseAdapter() {
|
112
|
@Override
|
113
|
public void mouseUp(MouseEvent arg0) {
|
114
|
if(cdmaModel != null) {
|
115
|
cdmaModel.removeCdmAuthority(grantedAuthorityI);
|
116
|
}
|
117
|
}
|
118
|
});
|
119
|
|
120
|
toolkit.adapt(btnDelete, true, true);
|
121
|
|
122
|
}
|
123
|
|
124
|
/**
|
125
|
* Sets the dirty flag for this row
|
126
|
*
|
127
|
* @param isDirty
|
128
|
*/
|
129
|
public void setDirty(boolean isDirty) {
|
130
|
if(isDirty) {
|
131
|
lblDirtyFlag.setText("*");
|
132
|
} else {
|
133
|
lblDirtyFlag.setText(" ");
|
134
|
}
|
135
|
}
|
136
|
|
137
|
/**
|
138
|
* Create a {@link CdmAuthority} from a {@link GrantedAuthorityImpl} and create a row from it.
|
139
|
*
|
140
|
* @param cdmaModel
|
141
|
* @param grantedAuthorityI
|
142
|
* @param isDirty
|
143
|
*/
|
144
|
public void setRowCdmAuthority(CdmAuthorityCompositeViewer cdmaModel, GrantedAuthorityImpl grantedAuthorityI, boolean isDirty, boolean showUuid) {
|
145
|
this.grantedAuthorityI = grantedAuthorityI;
|
146
|
this.cdmaModel = cdmaModel;
|
147
|
|
148
|
try {
|
149
|
CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthorityI);
|
150
|
|
151
|
setDirty(isDirty);
|
152
|
|
153
|
String entityStr = (cdmAuthority.getPermissionClass() == null)?"":cdmAuthority.getPermissionClass().toString();
|
154
|
lblType.setText(entityStr);
|
155
|
String targetLabelText = GrantedAuthorityLabelTextProvider.getTargetText(cdmAuthority);
|
156
|
lblEntity.setText(targetLabelText);
|
157
|
|
158
|
setUuidCellVisible(showUuid);
|
159
|
if(lblUuid != null) {
|
160
|
String targetUuid = cdmAuthority.getTargetUUID().toString();
|
161
|
lblUuid.setText(targetUuid);
|
162
|
}
|
163
|
|
164
|
operationChooser.setAuthority(cdmaModel, grantedAuthorityI, cdmAuthority);
|
165
|
|
166
|
} catch (Exception e) {
|
167
|
// TODO Auto-generated catch block
|
168
|
e.printStackTrace();
|
169
|
}
|
170
|
|
171
|
}
|
172
|
|
173
|
public void setUuidCellVisible(boolean visible) {
|
174
|
if(visible) {
|
175
|
if(lblUuid == null) {
|
176
|
createUuidCell();
|
177
|
}
|
178
|
lblUuid.moveAbove(operationChooser);
|
179
|
|
180
|
} else {
|
181
|
if(lblUuid != null) {
|
182
|
lblUuid.dispose();
|
183
|
}
|
184
|
lblUuid = null;
|
185
|
}
|
186
|
layout();
|
187
|
}
|
188
|
|
189
|
private void createUuidCell() {
|
190
|
lblUuid = new Label(this, SWT.BORDER | SWT.CENTER);
|
191
|
GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
|
192
|
gd_lblUuid.heightHint = 30;
|
193
|
gd_lblUuid.widthHint = 270;
|
194
|
lblUuid.setLayoutData(gd_lblUuid);
|
195
|
toolkit.adapt(lblUuid, true, true);
|
196
|
lblUuid.setText("Uuid");
|
197
|
}
|
198
|
|
199
|
}
|