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
.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
;
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
;
22 import org
.eclipse
.swt
.events
.MouseAdapter
;
23 import org
.eclipse
.swt
.events
.MouseEvent
;
24 import org
.eclipse
.swt
.events
.MouseTrackAdapter
;
28 * Widget for editing {@link Operation} objects, consisting of 4 checkboxes for CREATE, UPDATE, READ, DELETE operations.
31 * @created Mar 28, 2013
34 public class CRUDOperationChooser
extends Composite
{
36 private Button createCheckButton
;
37 private Button readCheckButton
;
38 private Button deleteCheckButton
;
39 private Button updateCheckButton
;
41 private CdmAuthorityRow caRow
;
42 private GrantedAuthorityImpl grantedAuthorityI
;
43 private CdmAuthority cdmAuthority
;
44 private CdmAuthorityCompositeViewer viewer
;
47 * Create the composite.
51 public CRUDOperationChooser(final CdmAuthorityRow parent
, int style
) {
53 setBackground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WHITE
));
54 RowLayout rowLayout
= new RowLayout(SWT
.HORIZONTAL
);
55 rowLayout
.justify
= true;
60 createCheckButton
= new Button(this, SWT
.CHECK
);
61 createCheckButton
.setForeground(Display
.getCurrent().getSystemColor(SWT
.COLOR_WIDGET_DARK_SHADOW
));
62 createCheckButton
.addMouseListener(new MouseAdapter() {
64 public void mouseUp(MouseEvent arg0
) {
65 if(cdmAuthority
.getOperation() != null) {
66 if(createCheckButton
.getSelection()) {
67 cdmAuthority
.getOperation().add(CRUD
.CREATE
);
69 cdmAuthority
.getOperation().remove(CRUD
.CREATE
);
72 viewer
.updateGrantedAuthority(grantedAuthorityI
, cdmAuthority
);
73 parent
.setDirty(true);
79 createCheckButton
.setText("C");
81 readCheckButton
= new Button(this, SWT
.CHECK
);
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 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 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 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(false);
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);