summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
blob: 0f01fd61b54004fd600a71d77b893e561fe82b82 (plain) (blame)
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
package org.openslx.dozmod.gui.window.layout;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.util.Calendar;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JEditorPane;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSpinner;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.SpinnerDateModel;
import javax.swing.text.DateFormatter;
import javax.swing.text.StyledEditorKit;

import org.jdatepicker.JDatePicker;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.Branding;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.configurator.LdapFilterConfigurator;
import org.openslx.dozmod.gui.configurator.LecturePermissionConfigurator;
import org.openslx.dozmod.gui.configurator.NetrulesConfigurator;
import org.openslx.dozmod.gui.configurator.NetshareConfigurator;
import org.openslx.dozmod.gui.configurator.StartupConfigurator;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
import org.openslx.dozmod.gui.control.LocationSelector;
import org.openslx.dozmod.gui.control.PersonLabel;
import org.openslx.dozmod.gui.control.QDatePickerImpl;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.control.WordWrapLabel;
import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.thrift.Session;
import org.openslx.dozmod.thrift.cache.MetaDataCache;
import org.openslx.dozmod.util.FormatHelper;
import org.openslx.sat.thrift.version.Feature;
import org.openslx.thrifthelper.Comparators;

@SuppressWarnings("serial")
public abstract class LectureDetailsWindowLayout extends JDialog {

	// stuff ending in '...Info' are supposed to be the read-only labels for the information tab
	protected final QLabel lblTitleInfo;
	protected final JTextField txtTitle;
	protected final JEditorPane txtDescription;
	protected final QLabel lblImageNameInfo;
	protected final QLabel txtImageName;
	protected final JButton btnLinkImage;
	protected final PersonLabel lblOwnerInfo;
	protected final PersonLabel lblOwner;
	protected final JButton btnChangeOwner;
	protected final QLabel lblCreateTime;
	protected final PersonLabel lblUpdater;
	protected final QLabel lblUpdateTime;
	protected final QLabel lblStartTime;
	protected final QLabel lblEndTime;
	protected final JCheckBox chkAutoUpdate;
	protected final QLabel lblVersionInfo;
	protected final ComboBox<ImageVersionDetails> cboVersions;
	protected final JCheckBox chkIsExam;
	protected final JCheckBox chkHasInternetAccess;
	protected final JCheckBox chkHasUsbAccess;
	protected final JCheckBox chkIsActive;

	protected final JTextField txtId;
	protected final QLabel lblUseCount;

	protected final QLabel lblError;
	protected final JButton btnSaveChanges;
	protected final JButton btnClose;
	protected final JButton btnDownloadImage;

	protected final JDatePicker dtpStartDate;
	protected final JDatePicker dtpEndDate;
	protected final JSpinner spnStartTime;
	protected final JSpinner spnEndTime;

	protected final JTabbedPane pnlTabs;
	protected final LecturePermissionConfigurator ctlPermissionManager;
	protected final LocationSelector ctlLocationSelector;
	protected final StartupConfigurator ctlRunscriptConfigurator;
	protected final NetshareConfigurator ctlNetshareConfigurator;
	protected final LdapFilterConfigurator ctlLdapFilterConfigurator;
	protected final NetrulesConfigurator ctlNetrulesConfigurator;

	protected final JCheckBox chkCustomPermEdit;
	protected final JCheckBox chkCustomPermAdmin;
	protected final JPanel pnlTabGeneral;
	protected final JPanel pnlTabInfo;
	protected final JPanel pnlTabNetrules;
	protected final JPanel pnlTabRestrictions;
	protected final JPanel pnlTabPermissions;
	protected final JPanel pnlTabLocations;
	protected final JPanel pnlTabRunscript;
	protected final JPanel pnlTabNetshare;
	protected final JPanel pnlTabLdapFilter;

	protected final JButton btnBold;
	protected final JButton btnItalic;
	protected final JButton btnUnderline;


	public LectureDetailsWindowLayout(Frame modalParent) {
		super(modalParent, "Veranstaltungsdetails", ModalityType.APPLICATION_MODAL);
		setResizable(true);
		setPreferredSize(Gui.getScaledDimension(570, 650));
		setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
		setLayout(new BorderLayout());
		((JPanel) getContentPane()).setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

		pnlTabInfo = new JPanel();
		pnlTabInfo.setBorder(BorderFactory.createEmptyBorder(25, 25, 25, 25));
		GridManager grdInfo = new GridManager(pnlTabInfo, 3, true, new Insets(7, 7, 7, 7));

		// title
		lblTitleInfo = new QLabel();
		lblTitleInfo.setFont(lblTitleInfo.getFont().deriveFont(Font.BOLD,
				lblTitleInfo.getFont().getSize2D() * 1.5f));
		grdInfo.add(lblTitleInfo, 3);
		grdInfo.nextRow();
		// lblOwner
		lblOwnerInfo = new PersonLabel();
		grdInfo.add(new QLabel("Besitzer"));
		grdInfo.add(lblOwnerInfo, 2).expand(true, false);
		grdInfo.nextRow();
		// creation time
		lblCreateTime = new QLabel();
		grdInfo.add(new QLabel("Erstellt am"));
		grdInfo.add(lblCreateTime, 2);
		grdInfo.nextRow();

		// last updater
		lblUpdater = new PersonLabel();
		grdInfo.add(new QLabel("Geändert durch"));
		grdInfo.add(lblUpdater, 2);
		grdInfo.nextRow();

		// last updated
		lblUpdateTime = new QLabel();
		grdInfo.add(new QLabel("Geändert am"));
		grdInfo.add(lblUpdateTime, 2);
		grdInfo.nextRow();
		lblVersionInfo = new QLabel(); // UNUSED
		lblImageNameInfo = new QLabel();
		grdInfo.add(new QLabel("Verknüpfte VM"), 2);
		grdInfo.add(lblImageNameInfo);
		grdInfo.nextRow();
		lblStartTime = new QLabel();
		grdInfo.add(new QLabel("Startdatum"), 2);
		grdInfo.add(lblStartTime);
		grdInfo.nextRow();
		lblEndTime = new QLabel();
		grdInfo.add(new QLabel("Enddatum"), 2);
		grdInfo.add(lblEndTime);
		grdInfo.nextRow();
		lblUseCount = new QLabel();
		grdInfo.add(new QLabel("Aufrufe"));
		grdInfo.add(lblUseCount, 2);
		grdInfo.finish(true);

		// Make general tab
		pnlTabGeneral = new JPanel();
		pnlTabGeneral.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
		GridManager grdGeneral = new GridManager(pnlTabGeneral, 5, true, new Insets(3, 3, 3, 3));
		// lecture title
		txtTitle = new JTextField();
		grdGeneral.add(new QLabel("Name"));
		grdGeneral.add(txtTitle, 4).expand(true, false).fill(true, false);
		grdGeneral.nextRow();

		// buttons for text editing
		JPanel editingPanel = new JPanel();
		editingPanel.setLayout(new GridLayout(1,3));
		JPanel emptyPanel = new JPanel();
		grdGeneral.add(emptyPanel);
		btnBold = new JButton( new StyledEditorKit.BoldAction());
		btnBold.setIcon(Gui.getScaledIconResource("/img/bold.png", "B", 24, this));
		btnBold.setText("");
		btnItalic = new JButton(new StyledEditorKit.ItalicAction() );
		btnItalic.setIcon(Gui.getScaledIconResource("/img/italic.png", "B", 24, this));
		btnItalic.setText("");
		btnUnderline = new JButton(new StyledEditorKit.UnderlineAction() );
		btnUnderline.setIcon(Gui.getScaledIconResource("/img/underline.png", "B", 24, this));
		btnUnderline.setText("");
		grdGeneral.add(btnBold);
		grdGeneral.add(btnItalic);
		grdGeneral.add(btnUnderline);
		grdGeneral.add(editingPanel);
		
		grdGeneral.nextRow();
		
		// description
		txtDescription = new JEditorPane();
		txtDescription.setContentType("text/html");
		grdGeneral.add(new QLabel("Beschreibung")).anchor(GridBagConstraints.FIRST_LINE_START);
		JScrollPane jsp = new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
				JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
		jsp.setMinimumSize(Gui.getScaledDimension(450, 120));
		jsp.setPreferredSize(Gui.getScaledDimension(450, 120));
		grdGeneral.add(jsp, 4).expand(true, true).fill(true, true);
		grdGeneral.nextRow();

		// ID. NOTE: currently disabled
		txtId = new JTextField();
		txtId.setEditable(false);
		txtId.setFont(txtId.getFont().deriveFont(Font.BOLD, txtId.getFont().getSize2D() * 0.66f));
		grdGeneral.add(new QLabel("ID"));
		grdGeneral.add(txtId, 4).expand(true, false).fill(true, false);
		grdGeneral.nextRow();

		// owner
		lblOwner = new PersonLabel();
		btnChangeOwner = new JButton("Ändern");
		grdGeneral.add(new QLabel("Besitzer"));
		grdGeneral.add(lblOwner, 3).expand(true, false);
		grdGeneral.add(btnChangeOwner).fill(true, false);
		grdGeneral.nextRow();

		// linked image
		// name
		txtImageName = new QLabel();
		grdGeneral.add(new QLabel("Verknüpfte VM"));
		grdGeneral.add(txtImageName, 3).expand(true, false);

		// link button for image
		btnLinkImage = new JButton("Ändern");
		grdGeneral.add(btnLinkImage).fill(true, false);
		grdGeneral.nextRow();

		// image version handling
		// auto update
		chkAutoUpdate = new JCheckBox("Immer aktuellste Version verwenden");
		// versions combo
		cboVersions = new ComboBox<>(Comparators.imageVersionDetails,
				new ComboBoxRenderer<ImageVersionDetails>() {
					@Override
					public String renderItem(ImageVersionDetails item) {
						if (item == null)
							return null;
						if (item.isValid) {
							return FormatHelper.longDate(item.getCreateTime());
						} else {
							return FormatHelper.longDate(item.getCreateTime()) + " [ungültig]";
						}
					}
				});
		btnDownloadImage = new JButton("Download");
		btnDownloadImage.setToolTipText("Momentan verwendete Version herunterladen");
		JPanel versionPanel = new JPanel(new BorderLayout());
		versionPanel.add(cboVersions, BorderLayout.CENTER);
		versionPanel.add(chkAutoUpdate, BorderLayout.SOUTH);
		grdGeneral.add(new QLabel("VM-Version"));
		grdGeneral.add(versionPanel, 3);
		grdGeneral.add(btnDownloadImage).fill(true, false);
		grdGeneral.nextRow();

		// start time of the lecture
		JPanel startTimePanel = new JPanel();
		startTimePanel.setLayout(new BoxLayout(startTimePanel, BoxLayout.LINE_AXIS));
		dtpStartDate = new QDatePickerImpl();
		spnStartTime = makeTimeSpinner(23, 59);
		startTimePanel.add(dtpStartDate);
		startTimePanel.add(spnStartTime);
		startTimePanel.setMinimumSize(startTimePanel.getPreferredSize());
		startTimePanel.setMaximumSize(startTimePanel.getPreferredSize());
		grdGeneral.add(new QLabel("Startdatum"));
		grdGeneral.add(startTimePanel, 4);
		grdGeneral.nextRow();

		// end time of the lecture
		JPanel endTimePanel = new JPanel();
		endTimePanel.setLayout(new BoxLayout(endTimePanel, BoxLayout.LINE_AXIS));
		dtpEndDate = new QDatePickerImpl();
		spnEndTime = makeTimeSpinner(00, 59);
		endTimePanel.add(dtpEndDate);
		endTimePanel.add(spnEndTime);
		endTimePanel.setMinimumSize(endTimePanel.getPreferredSize());
		endTimePanel.setMaximumSize(endTimePanel.getPreferredSize());
		grdGeneral.add(new QLabel("Enddatum"));
		grdGeneral.add(endTimePanel, 4);
		grdGeneral.nextRow();

		// lecture active
		chkIsActive = new JCheckBox("Veranstaltung aktiv");
		grdGeneral.skip();
		grdGeneral.add(chkIsActive, 4);
		grdGeneral.nextRow();
		grdGeneral.finish(true);
		
		Insets descriptionInset = new Insets(2, 4, 2, 4);
		Insets firstInset = new Insets(12, 4, 2, 4);
		
		// Network rules
		pnlTabNetrules = new JPanel();
		GridManager grdNetrules = new GridManager(pnlTabNetrules, 1, true, new Insets(9, 4, 2, 4));
		// "restrictions": internet access / usb access / exam
		chkHasInternetAccess = new JCheckBox("Netzwerk-/Internetzugriff zulassen");
		grdNetrules.add(chkHasInternetAccess).expand(true, false).insets(firstInset);
		grdNetrules.nextRow();
		grdNetrules.add(
				new WordWrapLabel(
						"Legen Sie hier fest, ob die Veranstaltung Zugriff zum Internet haben soll."
								+ " In der Liste können Sie bestimmte Adressen und Services"
								+ " ein- oder ausschließen.", false, true))
				.fill(true, false)
				.expand(true, false)
				.insets(descriptionInset);
		grdNetrules.nextRow();
		ctlNetrulesConfigurator = new NetrulesConfigurator();
		grdNetrules.add(ctlNetrulesConfigurator).fill(true, true).expand(true, true);
		grdNetrules.nextRow();
		grdNetrules.finish(false);
		
		// Tab restrictions
		pnlTabRestrictions = new JPanel();
		GridManager grdRestrictions = new GridManager(pnlTabRestrictions, 2, true, new Insets(9, 4, 2, 4));
		
		chkHasUsbAccess = new JCheckBox("Externe Speichermedien zulassen");
		grdRestrictions.add(chkHasUsbAccess, 2);
		grdRestrictions.nextRow();
		grdRestrictions.add(
				new WordWrapLabel("Legen Sie hier fest, ob die Veranstaltung den Zugriff"
						+ " auf Speichermedien (CD, USB, ...) erlauben soll", false, true), 2)
				.fill(true, false)
				.expand(true, false)
				.insets(descriptionInset);
		grdRestrictions.nextRow();

		chkIsExam = new JCheckBox("Prüfungsmodus");
		grdRestrictions.add(chkIsExam, 2);
		grdRestrictions.nextRow();
		grdRestrictions.add(
				new WordWrapLabel(
						"Markieren Sie diese Veranstaltung als E-Prüfung.\n"
								+ "Die Veranstaltung wird nur dann startbar sein, wenn " + Branding.getServiceName() + " in den"
								+ " Prüfungsmodus versetzt wird. Kontaktieren Sie dazu Ihren lokalen " + Branding.getServiceName() + "-Administrator.",
						false, true), 2)
				.fill(true, false)
				.expand(true, false)
				.insets(descriptionInset);
		grdRestrictions.finish(true);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Permissions"
		 *
		 ********************************************************************************/
		ctlPermissionManager = new LecturePermissionConfigurator();
		pnlTabPermissions = new JPanel();
		GridManager grdPermissions = new GridManager(pnlTabPermissions, 1, false);
		JPanel defaultPermissionPane = new JPanel();
		defaultPermissionPane.setBorder(BorderFactory.createTitledBorder("Andere Nutzer"));
		chkCustomPermEdit = new JCheckBox("Bearbeiten");
		chkCustomPermAdmin = new JCheckBox("Admin");
		defaultPermissionPane.add(chkCustomPermEdit);
		defaultPermissionPane.add(chkCustomPermAdmin);
		grdPermissions.add(ctlPermissionManager).fill(true, true).expand(true, true);
		grdPermissions.nextRow();
		grdPermissions.add(defaultPermissionPane).fill(true, false).expand(true, false);
		grdPermissions.finish(false);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Locations"
		 *
		 ********************************************************************************/
		ctlLocationSelector = new LocationSelector();
		pnlTabLocations = new JPanel();
		GridManager grdLocations = new GridManager(pnlTabLocations, 1, false);
		grdLocations.add(ctlLocationSelector).fill(true, true).expand(true, true);
		grdLocations.finish(false);

		/* *******************************************************************************	
		 * 
		 *                        		Tab "Runscript"
		 *
		 ********************************************************************************/
		ctlRunscriptConfigurator = new StartupConfigurator();
		pnlTabRunscript = new JPanel();
		GridManager grdAdvanced = new GridManager(pnlTabRunscript, 1, false);
		grdAdvanced.add(ctlRunscriptConfigurator).fill(true, true).expand(true, true);
		grdAdvanced.finish(false);

		/* *******************************************************************************
		 *
		 *                        		Tab "Network-Shares"
		 *
		 ********************************************************************************/
		ctlNetshareConfigurator = new NetshareConfigurator();
		pnlTabNetshare = new JPanel();
		GridManager grdNetshare = new GridManager(pnlTabNetshare, 1, false, new Insets(8, 2, 8, 2));
		grdNetshare.add(ctlNetshareConfigurator).fill(true, true).expand(true, true);
		grdNetshare.finish(false);
		
		/* *******************************************************************************
		 *
		 *                        		Tab "LDAP-Filters"
		 *
		 ********************************************************************************/
		ctlLdapFilterConfigurator = new LdapFilterConfigurator();
		pnlTabLdapFilter = new JPanel();
		GridManager grdLdap = new GridManager(pnlTabLdapFilter, 1, false, new Insets(8, 2, 8, 2));
		grdLdap.add(ctlLdapFilterConfigurator).fill(true, true).expand(true, true);
		grdLdap.finish(false);
		
		/* *******************************************************************************	
		 * 
		 *                        Main panel containing the tabs 
		 *
		 ********************************************************************************/
		// finally build the tabbedPane and add it to the main view
		pnlTabs = new JTabbedPane();
		pnlTabs.addTab("Übersicht", pnlTabInfo);
		pnlTabs.addTab("Allgemein", pnlTabGeneral);
		if (Session.isLectureRestrictionsSupported()) {
			pnlTabs.addTab("Beschränkungen", pnlTabRestrictions);
			pnlTabs.addTab("Firewall", pnlTabNetrules);
		}
		if (MetaDataCache.getLocations() != null && !MetaDataCache.getLocations().isEmpty()) {
			pnlTabs.addTab("Raumauswahl", pnlTabLocations);
		}
		if (Session.isLectureRestrictionsSupported()) {
			pnlTabs.addTab("VM-Start", pnlTabRunscript);
		}
		pnlTabs.addTab("Berechtigungen", pnlTabPermissions);
		if (Session.hasFeature(Feature.NETWORK_SHARES)) {
			pnlTabs.addTab("Netzlaufwerke", pnlTabNetshare);
		}
		if (Session.hasFeature(Feature.LECTURE_FILTER_LDAP)) {
			pnlTabs.addTab("LDAP-Filter", pnlTabLdapFilter);
		}
		add(pnlTabs, BorderLayout.CENTER);
		// usage counter + button panel on the bottom
		JPanel buttonPanel = new JPanel();
		buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
		buttonPanel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
		btnClose = new JButton("Schließen");
		btnSaveChanges = new JButton("Speichern");
		lblError = new QLabel("");
		lblError.setForeground(Color.RED);
		buttonPanel.add(lblError);
		buttonPanel.add(Box.createGlue());
		buttonPanel.add(btnClose);
		buttonPanel.add(btnSaveChanges);
		// buttons at the end of the page
		add(buttonPanel, BorderLayout.SOUTH);
	}

	private JSpinner makeTimeSpinner(int h, int m) {
		Calendar calendar = Calendar.getInstance();
		calendar.set(Calendar.HOUR_OF_DAY, h);
		calendar.set(Calendar.MINUTE, m);
		calendar.set(Calendar.SECOND, 0);
		SpinnerDateModel model = new SpinnerDateModel();
		model.setValue(calendar.getTime());
		JSpinner spinner = new JSpinner(model);
		JSpinner.DateEditor editor = new JSpinner.DateEditor(spinner, "HH:mm");
		DateFormatter formatter = (DateFormatter) editor.getTextField().getFormatter();
		formatter.setAllowsInvalid(false);
		formatter.setOverwriteMode(true);
		spinner.setEditor(editor);
		return spinner;
	}
}