2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.group
.grantedauthority
;
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
;
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
;
27 * Widget for editing {@link Operation} objects, consisting of 4 checkboxes for CREATE, UPDATE, READ, DELETE operations.
30 * @created Mar 28, 2013
33 public class CRUDOperationChooser
extends Composite
{
35 private Button createCheckButton
;
36 private Button readCheckButton
;
37 private Button deleteCheckButton
;
38 private Button updateCheckButton
;
40 private CdmAuthorityRow caRow
;
41 private GrantedAuthorityImpl grantedAuthorityI
;
42 private CdmAuthority cdmAuthority
;
43 private CdmAuthorityCompositeViewer viewer
;
46 * Create the composite.
50 public CRUDOperationChooser(final CdmAuthorityRow parent
, int style
) {
52 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
53 RowLayout rowLayout
= new RowLayout(SWT
.HORIZONTAL
);
54 rowLayout
.justify
= true;
59 createCheckButton
= new Button(this, SWT
.CHECK
);
60 createCheckButton
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_DARK_SHADOW
));
61 createCheckButton
.addMouseListener(new MouseAdapter() {
63 public void mouseUp(MouseEvent arg0
) {
64 if(cdmAuthority
.getOperation() != null) {
65 if(createCheckButton
.getSelection()) {
66 cdmAuthority
.getOperation().add(CRUD
.CREATE
);
68 cdmAuthority
.getOperation().remove(CRUD
.CREATE
);
71 grantedAuthorityI
= viewer
.updateGrantedAuthority(grantedAuthorityI
, cdmAuthority
);
72 parent
.setDirty(true);
78 createCheckButton
.setText("C");
80 readCheckButton
= new Button(this, SWT
.CHECK
);
81 readCheckButton
.setEnabled(false);
82 readCheckButton
.addMouseTrackListener(new MouseTrackAdapter() {
84 public void mouseHover(MouseEvent arg0
) {
87 readCheckButton
.addMouseListener(new MouseAdapter() {
89 public void mouseUp(MouseEvent arg0
) {
90 if(cdmAuthority
.getOperation() != null) {
91 if(readCheckButton
.getSelection()) {
92 cdmAuthority
.getOperation().add(CRUD
.READ
);
94 cdmAuthority
.getOperation().remove(CRUD
.READ
);
97 grantedAuthorityI
= viewer
.updateGrantedAuthority(grantedAuthorityI
, cdmAuthority
);
98 parent
.setDirty(true);
105 readCheckButton
.setText("R");
107 deleteCheckButton
= new Button(this, SWT
.CHECK
);
108 deleteCheckButton
.addMouseListener(new MouseAdapter() {
110 public void mouseUp(MouseEvent arg0
) {
111 if(cdmAuthority
.getOperation() != null) {
112 if(deleteCheckButton
.getSelection()) {
113 cdmAuthority
.getOperation().add(CRUD
.DELETE
);
115 cdmAuthority
.getOperation().remove(CRUD
.DELETE
);
118 grantedAuthorityI
= viewer
.updateGrantedAuthority(grantedAuthorityI
, cdmAuthority
);
119 parent
.setDirty(true);
125 deleteCheckButton
.setText("D");
127 updateCheckButton
= new Button(this, SWT
.CHECK
);
128 updateCheckButton
.addMouseListener(new MouseAdapter() {
130 public void mouseUp(MouseEvent arg0
) {
131 if(cdmAuthority
.getOperation() != null) {
132 if(updateCheckButton
.getSelection()) {
133 cdmAuthority
.getOperation().add(CRUD
.UPDATE
);
135 cdmAuthority
.getOperation().remove(CRUD
.UPDATE
);
138 grantedAuthorityI
= viewer
.updateGrantedAuthority(grantedAuthorityI
, cdmAuthority
);
139 parent
.setDirty(true);
145 updateCheckButton
.setText("U");
151 protected void checkSubclass() {
152 // Disable the check that prevents subclassing of SWT components
156 * Set viewer, CDM Authority and corresponding GrantedAuthorityImpl object
159 * @param grantedAuthorityI
160 * @param cdmAuthority
162 public void setAuthority(CdmAuthorityCompositeViewer viewer
,
163 GrantedAuthorityImpl grantedAuthorityI
,
164 CdmAuthority cdmAuthority
) {
165 this.grantedAuthorityI
= grantedAuthorityI
;
166 this.cdmAuthority
= cdmAuthority
;
167 this.viewer
= viewer
;
174 * Update widget state.
176 private void updateView() {
177 createCheckButton
.setSelection(false);
178 readCheckButton
.setSelection(true);
179 deleteCheckButton
.setSelection(false);
180 updateCheckButton
.setSelection(false);
183 if(cdmAuthority
!= null && cdmAuthority
.getOperation() != null) {
184 if(cdmAuthority
.getOperation().contains(CRUD
.CREATE
)) {
185 createCheckButton
.setSelection(true);
187 if(cdmAuthority
.getOperation().contains(CRUD
.READ
)) {
188 readCheckButton
.setSelection(true);
190 if(cdmAuthority
.getOperation().contains(CRUD
.DELETE
)) {
191 deleteCheckButton
.setSelection(true);
193 if(cdmAuthority
.getOperation().contains(CRUD
.UPDATE
)) {
194 updateCheckButton
.setSelection(true);