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.MouseAdapter;
|
13
|
import org.eclipse.swt.events.MouseEvent;
|
14
|
import org.eclipse.swt.events.MouseTrackAdapter;
|
15
|
import org.eclipse.swt.layout.RowLayout;
|
16
|
import org.eclipse.swt.widgets.Button;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
import org.eclipse.swt.widgets.Display;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.GrantedAuthorityImpl;
|
21
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CRUD;
|
22
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmAuthority;
|
23
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.Operation;
|
24
|
|
25
|
|
26
|
/**
|
27
|
* Widget for editing {@link Operation} objects, consisting of 4 checkboxes for CREATE, UPDATE, READ, DELETE operations.
|
28
|
*
|
29
|
* @author cmathew
|
30
|
* @created Mar 28, 2013
|
31
|
*
|
32
|
*/
|
33
|
public class CRUDOperationChooser extends Composite {
|
34
|
|
35
|
private Button createCheckButton;
|
36
|
private Button readCheckButton;
|
37
|
private Button deleteCheckButton;
|
38
|
private Button updateCheckButton;
|
39
|
|
40
|
private CdmAuthorityRow caRow;
|
41
|
private GrantedAuthorityImpl grantedAuthorityI;
|
42
|
private CdmAuthority cdmAuthority;
|
43
|
private CdmAuthorityCompositeViewer viewer;
|
44
|
|
45
|
/**
|
46
|
* Create the composite.
|
47
|
* @param parent
|
48
|
* @param style
|
49
|
*/
|
50
|
public CRUDOperationChooser(final CdmAuthorityRow parent, int style) {
|
51
|
super(parent, style);
|
52
|
setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
|
53
|
RowLayout rowLayout = new RowLayout(SWT.HORIZONTAL);
|
54
|
rowLayout.justify = true;
|
55
|
setLayout(rowLayout);
|
56
|
|
57
|
|
58
|
this.caRow = parent;
|
59
|
createCheckButton = new Button(this, SWT.CHECK);
|
60
|
createCheckButton.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
|
61
|
createCheckButton.addMouseListener(new MouseAdapter() {
|
62
|
@Override
|
63
|
public void mouseUp(MouseEvent arg0) {
|
64
|
if(cdmAuthority.getOperation() != null) {
|
65
|
if(createCheckButton.getSelection()) {
|
66
|
cdmAuthority.getOperation().add(CRUD.CREATE);
|
67
|
} else {
|
68
|
cdmAuthority.getOperation().remove(CRUD.CREATE);
|
69
|
}
|
70
|
if(viewer != null) {
|
71
|
grantedAuthorityI = viewer.updateGrantedAuthority(grantedAuthorityI, cdmAuthority);
|
72
|
parent.setDirty(true);
|
73
|
}
|
74
|
|
75
|
}
|
76
|
}
|
77
|
});
|
78
|
createCheckButton.setText("C");
|
79
|
|
80
|
readCheckButton = new Button(this, SWT.CHECK);
|
81
|
readCheckButton.setEnabled(false);
|
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
|
grantedAuthorityI = 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
|
grantedAuthorityI = 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
|
grantedAuthorityI = 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(true);
|
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
|
}
|