This repository has been archived by the owner on Jun 26, 2020. It is now read-only.
/
AccessControlFormPage.java
224 lines (206 loc) · 8.4 KB
/
AccessControlFormPage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/**
* Copyright 2011 The University of North Carolina at Chapel Hill
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package unc.lib.cdr.workbench.acl;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import javax.xml.datatype.XMLGregorianCalendar;
import org.eclipse.emf.common.command.Command;
import org.eclipse.emf.ecore.xml.type.XMLTypeFactory;
import org.eclipse.emf.edit.command.SetCommand;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.DateTime;
import org.eclipse.ui.forms.IManagedForm;
import org.eclipse.ui.forms.editor.FormPage;
import org.eclipse.ui.forms.widgets.FormToolkit;
import org.eclipse.ui.forms.widgets.ScrolledForm;
import org.eclipse.ui.forms.widgets.Section;
import org.eclipse.ui.forms.widgets.TableWrapData;
import org.eclipse.ui.forms.widgets.TableWrapLayout;
import unc.lib.cdr.workbench.project.MetsProjectNature;
import edu.unc.lib.schemas.acl.AccessControlType;
import edu.unc.lib.schemas.acl.AclPackage;
/**
* @author Gregory Jansen
*
*/
public class AccessControlFormPage extends FormPage {
private ScrolledPropertiesBlock block;
protected AccessControlType model;
private Button inheritFlag;
private Button discoverableFlag;
private Button embargoFlag;
private DateTime untilDate;
private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
private AccessControlFormEditor acleditor = null;
public AccessControlFormPage(AccessControlFormEditor editor) {
super(editor, "fourth", "Access Controls");
block = new ScrolledPropertiesBlock(this);
model = editor.model;
this.acleditor = editor;
}
@Override
protected void createFormContent(final IManagedForm managedForm) {
final ScrolledForm form = managedForm.getForm();
FormToolkit toolkit = managedForm.getToolkit();
form.setText("Edit Access Controls"); //$NON-NLS-1$
Composite parent = form.getBody();
TableWrapLayout layout = new TableWrapLayout();
layout.numColumns = 1;
parent.setLayout(layout);
// first block
createInheritContent(parent, toolkit);
createDiscoverableContent(parent, toolkit);
createEmbargoContent(parent, toolkit);
// form.setBackgroundImage(FormArticlePlugin.getDefault().getImage(
// FormArticlePlugin.IMG_FORM_BG));
Composite masterBlock = toolkit.createComposite(parent);
TableWrapData mbtd = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.FILL_GRAB);
masterBlock.setLayoutData(mbtd);
block.createContent(managedForm, masterBlock);
}
/**
* @param parent
* @param toolkit
*/
private void createEmbargoContent(Composite parent, FormToolkit toolkit) {
TableWrapData gd = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE);
Section s1 = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
s1.setText("Embargo"); //$NON-NLS-1$
s1.setDescription("You may embargo this object (and its contents) until a specified date."); //$NON-NLS-1$
s1.marginWidth = 10;
s1.marginHeight = 5;
s1.setLayoutData(gd);
Composite client = toolkit.createComposite(s1);
TableWrapLayout twl = new TableWrapLayout();
twl.numColumns = 2;
client.setLayout(twl);
TableWrapData twd = new TableWrapData(TableWrapData.RIGHT, TableWrapData.MIDDLE, 1, 1);
embargoFlag = toolkit.createButton(client, "Yes, embargo until", SWT.CHECK); //$NON-NLS-1$
embargoFlag.setSelection(model.isSetEmbargoUntil());
embargoFlag.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
untilDate.setEnabled(embargoFlag.getSelection());
updateEmbargo();
}
});
embargoFlag.setLayoutData(twd);
untilDate = new DateTime(client, SWT.DATE | SWT.BORDER);
if (model.isSetEmbargoUntil() && model.getEmbargoUntil() != null) {
XMLGregorianCalendar cal = model.getEmbargoUntil();
untilDate.setYear(cal.getYear());
untilDate.setMonth(cal.getMonth() - 1);
untilDate.setDay(cal.getDay());
} else {
// default 3 years from current day
Calendar cal = GregorianCalendar.getInstance();
cal.add(Calendar.YEAR, 3);
untilDate.setYear(cal.get(Calendar.YEAR));
untilDate.setMonth(cal.get(Calendar.MONTH));
untilDate.setDay(cal.get(Calendar.DAY_OF_MONTH));
}
untilDate.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
updateEmbargo();
}
});
s1.setClient(client);
}
/**
*
*/
protected void updateEmbargo() {
Command cmd = null;
if (embargoFlag.getSelection()) {
Date dt = new Date(untilDate.getYear() - 1900, untilDate.getMonth(), untilDate.getDay());
XMLGregorianCalendar fromDate = XMLTypeFactory.eINSTANCE.createDate(sdf.format(dt));
cmd = SetCommand.create(MetsProjectNature.getEditingDomain(model), model, AclPackage.eINSTANCE.getAccessControlType_EmbargoUntil(), fromDate);
} else { // no embargo
cmd = SetCommand.create(MetsProjectNature.getEditingDomain(model), model, AclPackage.eINSTANCE.getAccessControlType_EmbargoUntil(), null);
}
if(cmd.canExecute()) {
MetsProjectNature.getNatureForMetsObject(model).getCommandStack().execute(cmd);
}
}
/**
* @param parent
* @param toolkit
*/
private void createInheritContent(Composite parent, FormToolkit toolkit) {
TableWrapData gd = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE);
Section s1 = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
s1.setText("Inherited Roles"); //$NON-NLS-1$
s1.setDescription("Roles may have been granted to groups above this object. Do you want those groups to retain roles inherited in this way?"); //$NON-NLS-1$
s1.marginWidth = 10;
s1.marginHeight = 5;
s1.setLayoutData(gd);
inheritFlag = toolkit.createButton(s1, "Yes, groups may retain roles granted above this level.", SWT.CHECK); //$NON-NLS-1$
inheritFlag.setSelection(model.isInherit());
inheritFlag.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (model != null) {
Command cmd = SetCommand.create(MetsProjectNature.getEditingDomain(model), model, AclPackage.eINSTANCE.getAccessControlType_Inherit(), inheritFlag.getSelection());
if(cmd.canExecute()) {
MetsProjectNature.getNatureForMetsObject(model).getCommandStack().execute(cmd);
}
}
}
});
gd = new TableWrapData(TableWrapData.FILL, TableWrapData.MIDDLE);
// gd.heightHint
inheritFlag.setLayoutData(gd);
s1.setClient(inheritFlag);
}
/**
* @param parent
* @param toolkit
*/
private void createDiscoverableContent(Composite parent, FormToolkit toolkit) {
TableWrapData gd = new TableWrapData(TableWrapData.FILL_GRAB, TableWrapData.MIDDLE);
Section s1 = toolkit.createSection(parent, Section.DESCRIPTION | Section.TITLE_BAR);
s1.setText("Allow Discovery"); //$NON-NLS-1$
s1.setDescription("Do you want this object to be discovered by repository search and browse functions?"); //$NON-NLS-1$
s1.marginWidth = 10;
s1.marginHeight = 5;
s1.setLayoutData(gd);
discoverableFlag = toolkit.createButton(s1, "Yes, allow discovery via search and browse.", SWT.CHECK); //$NON-NLS-1$
discoverableFlag.setSelection(model.isDiscoverable());
discoverableFlag.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
if (model != null) {
Command cmd = SetCommand.create(MetsProjectNature.getEditingDomain(model), model, AclPackage.eINSTANCE.getAccessControlType_Discoverable(), discoverableFlag.getSelection());
if(cmd.canExecute()) {
MetsProjectNature.getNatureForMetsObject(model).getCommandStack().execute(cmd);
}
}
}
});
gd = new TableWrapData(TableWrapData.FILL, TableWrapData.MIDDLE);
// gd.heightHint
discoverableFlag.setLayoutData(gd);
s1.setClient(discoverableFlag);
}
}