Project

General

Profile

Download (5.81 KB) Statistics
| Branch: | Tag: | Revision:
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.permission.GrantedAuthorityImpl;
25
import eu.etaxonomy.cdm.persistence.permission.CdmAuthority;
26
import eu.etaxonomy.taxeditor.model.ImageResources;
27
import eu.etaxonomy.taxeditor.ui.section.grantedAuthority.GrantedAuthorityLabelTextProvider;
28

    
29
/**
30
 * Row widget for editing a single CDM Authority
31
 *
32
 * @author cmathew
33
 * @created Mar 28, 2013
34
 */
35
public class CdmAuthorityRow extends Composite {
36

    
37
	private final FormToolkit toolkit = new FormToolkit(Display.getCurrent());
38
	private Label lblEntity;
39
	private Label lblUuid;
40
	private CRUDOperationChooser operationChooser;
41
	private Button btnDelete;
42

    
43
	private GrantedAuthorityImpl grantedAuthorityI;
44
	private Label lblDirtyFlag;
45

    
46
	private CdmAuthorityCompositeViewer cdmaModel;
47
	private Label lblType;
48

    
49
	/**
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)
53
	 * 3. Uuid of entity
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)
56
	 *
57
	 * @param parent
58
	 * @param style
59
	 */
60
	public CdmAuthorityRow(Composite parent, int style) {
61
		super(parent, SWT.NONE);
62
		addDisposeListener(new DisposeListener() {
63
			@Override
64
            public void widgetDisposed(DisposeEvent e) {
65
				toolkit.dispose();
66
			}
67
		});
68
		toolkit.adapt(this);
69
		toolkit.paintBordersFor(this);
70
		setLayout(new GridLayout(6, false));
71

    
72

    
73

    
74
		lblDirtyFlag = new Label(this, SWT.NONE);
75
		lblDirtyFlag.setAlignment(SWT.CENTER);
76
		GridData gd_lblDirtyFlag = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
77
		gd_lblDirtyFlag.widthHint = 15;
78
		lblDirtyFlag.setLayoutData(gd_lblDirtyFlag);
79
		toolkit.adapt(lblDirtyFlag, true, true);
80
		lblDirtyFlag.setText("*");
81

    
82
		lblType = new Label(this, SWT.BORDER);
83
		GridData gd_lblType = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
84
		gd_lblType.heightHint = 30;
85
		gd_lblType.widthHint = 200;
86
		lblType.setLayoutData(gd_lblType);
87
		lblType.setText("Type");
88
		lblType.setAlignment(SWT.CENTER);
89
		toolkit.adapt(lblType, true, true);
90

    
91
		lblEntity = new Label(this, SWT.BORDER | SWT.WRAP | SWT.CENTER);
92
		GridData gd_lblEntity = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
93
		gd_lblEntity.heightHint = 30;
94
		gd_lblEntity.widthHint = 200;
95
		lblEntity.setLayoutData(gd_lblEntity);
96
		lblEntity.setAlignment(SWT.CENTER);
97
		toolkit.adapt(lblEntity, true, true);
98
		lblEntity.setText("Entity/Feature");
99

    
100

    
101
		operationChooser = new CRUDOperationChooser(this, SWT.BORDER);
102
		operationChooser.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
103
		toolkit.adapt(operationChooser);
104
		toolkit.paintBordersFor(operationChooser);
105

    
106
		btnDelete = new Button(this, SWT.NONE);
107

    
108
		btnDelete.setImage(ImageResources.getImage(ImageResources.TRASH_ICON));
109
		btnDelete.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1));
110
		btnDelete.addMouseListener(new MouseAdapter() {
111
			@Override
112
			public void mouseUp(MouseEvent arg0) {
113
				if(cdmaModel != null) {
114
					cdmaModel.removeCdmAuthority(grantedAuthorityI);
115
				}
116
			}
117
		});
118

    
119
		toolkit.adapt(btnDelete, true, true);
120

    
121
	}
122

    
123
	/**
124
	 * Sets the dirty flag for this row
125
	 *
126
	 * @param isDirty
127
	 */
128
	public void setDirty(boolean isDirty) {
129
		if(isDirty) {
130
			lblDirtyFlag.setText("*");
131
		} else {
132
			lblDirtyFlag.setText(" ");
133
		}
134
	}
135

    
136
	/**
137
	 * Create a {@link CdmAuthority} from a {@link GrantedAuthorityImpl} and create a row from it.
138
	 *
139
	 * @param cdmaModel
140
	 * @param grantedAuthorityI
141
	 * @param isDirty
142
	 */
143
	public void setRowCdmAuthority(CdmAuthorityCompositeViewer cdmaModel, GrantedAuthorityImpl grantedAuthorityI, boolean isDirty, boolean showUuid) {
144
		this.grantedAuthorityI = grantedAuthorityI;
145
		this.cdmaModel = cdmaModel;
146

    
147
		try {
148
			CdmAuthority cdmAuthority = CdmAuthority.fromGrantedAuthority(grantedAuthorityI);
149

    
150
			setDirty(isDirty);
151

    
152
			String entityStr = (cdmAuthority.getPermissionClass() == null)?"":cdmAuthority.getPermissionClass().toString();
153
			lblType.setText(entityStr);
154
			String targetLabelText = GrantedAuthorityLabelTextProvider.getTargetText(cdmAuthority);
155
			lblEntity.setText(targetLabelText);
156

    
157
			setUuidCellVisible(showUuid);
158
			if(lblUuid != null) {
159
				String targetUuid = cdmAuthority.getTargetUUID().toString();
160
				lblUuid.setText(targetUuid);
161
			}
162

    
163
			operationChooser.setAuthority(cdmaModel, grantedAuthorityI, cdmAuthority);
164

    
165
		} catch (Exception e) {
166
			// TODO Auto-generated catch block
167
			e.printStackTrace();
168
		}
169

    
170
	}
171

    
172
	public void setUuidCellVisible(boolean visible) {
173
		if(visible) {
174
			if(lblUuid == null) {
175
				createUuidCell();
176
			}
177
			lblUuid.moveAbove(operationChooser);
178

    
179
		} else {
180
			if(lblUuid != null) {
181
				lblUuid.dispose();
182
			}
183
			lblUuid = null;
184
		}
185
		layout();
186
	}
187

    
188
	private void createUuidCell() {
189
		lblUuid = new Label(this, SWT.BORDER | SWT.CENTER);
190
		GridData gd_lblUuid = new GridData(SWT.CENTER, SWT.CENTER, false, false, 1, 1);
191
		gd_lblUuid.heightHint = 30;
192
		gd_lblUuid.widthHint = 270;
193
		lblUuid.setLayoutData(gd_lblUuid);
194
		toolkit.adapt(lblUuid, true, true);
195
		lblUuid.setText("Uuid");
196
	}
197

    
198
}
(4-4/5)