summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java
blob: 026057fd8bc7fabae54ce2c149089b4145f5f4b5 (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
package org.openslx.dozmod.gui.window;

import java.util.List;

import org.apache.log4j.Logger;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.swt.events.KeyAdapter;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.openslx.bwlp.thrift.iface.LectureSummary;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.helper.LectureListComparator;
import org.openslx.dozmod.gui.helper.LectureListFilter;
import org.openslx.dozmod.gui.helper.TableHelper;
import org.openslx.dozmod.gui.window.layout.LectureListWindowLayout;
import org.openslx.dozmod.thrift.LectureCache;
import org.openslx.dozmod.thrift.UserCache;
import org.openslx.dozmod.util.FormatHelper;

public class LectureListWindow extends LectureListWindowLayout {

	private final static Logger LOGGER = Logger.getLogger(LectureListWindow.class);

	public final LectureListWindow me = this;

	public LectureListWindow(final Shell mainShell) {
		super(mainShell);

		// Comparator for column sorting
		LectureListComparator comparator = new LectureListComparator();
		tableViewer.setComparator(comparator);
		// creating the columns with sorting functionality through comparator
		TableHelper.createLectureTableColumns(tableViewer);

		// filter the objects in the table depending on the search field
		searchTextField.addKeyListener(new KeyAdapter() {
			public void keyReleased(KeyEvent ke) {
				filter.setSearchText(searchTextField.getText());
				tableViewer.refresh();
			}
		});

		// apply object filtering
		filter = new LectureListFilter();
		tableViewer.addFilter(filter);

		// the listeners to set the detailed info of the selected lecture
		tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
				LectureSummary lecture = (LectureSummary) selection.getFirstElement();
				if (lecture == null)
					return;
				// Fill detail information fields
				// Lecture name
				setFieldText(lectureName, lecture.getLectureName());
				// id of the lecture
				setFieldText(idInfo, lecture.getLectureId());
				// id of the image linked to the lecture
				setFieldText(imageBaseId, lecture.getImageBaseId());
				// the owner of the selected lecture
				setFieldText(ownerInfo, FormatHelper.userName(UserCache.find(lecture.getOwnerId())));
				// set the time, the lecture has last been used
				lastusedInfo.setText(FormatHelper.longDate(lecture.getLastUsed()));
				// set the start time of the lecture
				startTime.setText(FormatHelper.longDate(lecture.getStartTime()));
				// set the end time of the lecture
				endTime.setText(FormatHelper.longDate(lecture.getEndTime()));
			}

			private void setFieldText(Text control, String content) {
				if (content == null) {
					control.setText("<null>");
				} else {
					control.setText(content);
				}
			}
		});

		newButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
			}
		});

		editButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {

			}
		});

		// delete lecture
		deleteButton.addSelectionListener(new SelectionAdapter() {
		});

		// return to mainMenu
		backButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				MainWindow.showPage(MainMenuWindow.class);
			}
		});
	}

	private boolean refreshList() {
		List<LectureSummary> lectureList = LectureCache.get(false);
		tableViewer.setInput(lectureList);
		tableViewer.refresh();
		return true;
	}

	@Override
	public boolean hide() {
		return true;
	}

	@Override
	public void show() {
		refreshList();
	}

}