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
.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
;
24 import eu
.etaxonomy
.cdm
.model
.common
.GrantedAuthorityImpl
;
25 import eu
.etaxonomy
.cdm
.persistence
.hibernate
.permission
.CdmAuthority
;
26 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
30 * Row widget for editing a single CDM Authority
33 * @created Mar 28, 2013
36 public class CdmAuthorityRow
extends Composite
{
38 private final FormToolkit toolkit
= new FormToolkit(Display
.getCurrent());
39 private Label lblEntity
;
40 private Label lblUuid
;
41 private CRUDOperationChooser operationChooser
;
42 private Button btnDelete
;
44 private GrantedAuthorityImpl grantedAuthorityI
;
45 private Label lblDirtyFlag
;
47 private CdmAuthorityCompositeViewer cdmaModel
;
50 * Create the composite, made up of 5 elements :
51 * 1. '*' or depending on whether the row is being edited
52 * 2. Classname of entity (e.g. TAXONNODE)
54 * 4. CRUD operations edit widget (this is essentially 4 checkboxes to select the 4 possible operations)
55 * 5. Delete button (to delete the row)
60 public CdmAuthorityRow(Composite parent
, int style
) {
61 super(parent
, SWT
.NONE
);
62 addDisposeListener(new DisposeListener() {
63 public void widgetDisposed(DisposeEvent e
) {
68 toolkit
.paintBordersFor(this);
69 setLayout(new GridLayout(5, false));
73 lblDirtyFlag
= new Label(this, SWT
.NONE
);
74 lblDirtyFlag
.setAlignment(SWT
.CENTER
);
75 GridData gd_lblDirtyFlag
= new GridData(SWT
.LEFT
, SWT
.CENTER
, false, false, 1, 1);
76 gd_lblDirtyFlag
.widthHint
= 15;
77 lblDirtyFlag
.setLayoutData(gd_lblDirtyFlag
);
78 toolkit
.adapt(lblDirtyFlag
, true, true);
79 lblDirtyFlag
.setText("*");
81 lblEntity
= new Label(this, SWT
.BORDER
);
82 GridData gd_lblEntity
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1);
83 gd_lblEntity
.heightHint
= 30;
84 gd_lblEntity
.widthHint
= 200;
85 lblEntity
.setLayoutData(gd_lblEntity
);
86 lblEntity
.setAlignment(SWT
.CENTER
);
87 toolkit
.adapt(lblEntity
, true, true);
88 lblEntity
.setText("Entity");
90 lblUuid
= new Label(this, SWT
.BORDER
);
91 GridData gd_lblUuid
= new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1);
92 gd_lblUuid
.heightHint
= 30;
93 gd_lblUuid
.widthHint
= 270;
94 lblUuid
.setLayoutData(gd_lblUuid
);
95 lblUuid
.setAlignment(SWT
.CENTER
);
96 toolkit
.adapt(lblUuid
, true, true);
97 lblUuid
.setText("Uuid");
99 operationChooser
= new CRUDOperationChooser(this, SWT
.BORDER
);
100 operationChooser
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
101 toolkit
.adapt(operationChooser
);
102 toolkit
.paintBordersFor(operationChooser
);
104 btnDelete
= new Button(this, SWT
.NONE
);
106 btnDelete
.setImage(ImageResources
.getImage(ImageResources
.TRASH_ICON
));
107 btnDelete
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false, 1, 1));
108 btnDelete
.addMouseListener(new MouseAdapter() {
110 public void mouseUp(MouseEvent arg0
) {
111 if(cdmaModel
!= null) {
112 cdmaModel
.removeCdmAuthority(grantedAuthorityI
);
117 toolkit
.adapt(btnDelete
, true, true);
122 * Sets the dirty flag for this row
126 public void setDirty(boolean isDirty
) {
128 lblDirtyFlag
.setText("*");
130 lblDirtyFlag
.setText(" ");
135 * Create a {@link CdmAuthority} from a {@link GrantedAuthorityImpl} and create a row from it.
138 * @param grantedAuthorityI
141 public void setRowCdmAuthority(CdmAuthorityCompositeViewer cdmaModel
, GrantedAuthorityImpl grantedAuthorityI
, boolean isDirty
) {
142 this.grantedAuthorityI
= grantedAuthorityI
;
143 this.cdmaModel
= cdmaModel
;
146 CdmAuthority cdmAuthority
= CdmAuthority
.fromGrantedAuthority(grantedAuthorityI
);
150 String entityStr
= (cdmAuthority
.getPermissionClass() == null)?
"":cdmAuthority
.getPermissionClass().toString();
151 lblEntity
.setText(entityStr
);
152 String uuidStr
= (cdmAuthority
.getTargetUUID() == null)?
"":cdmAuthority
.getTargetUUID().toString();
153 lblUuid
.setText(uuidStr
);
155 operationChooser
.setAuthority(cdmaModel
, grantedAuthorityI
, cdmAuthority
);
157 } catch (Exception e
) {
158 // TODO Auto-generated catch block