diff options
author | Stephan Schwaer | 2015-07-16 16:19:07 +0200 |
---|---|---|
committer | Stephan Schwaer | 2015-07-16 16:19:07 +0200 |
commit | 83ec934d4b1734006488bf203e21dcc5ddb8071d (patch) | |
tree | 21bc54d1ad85a90f62a465242d8c7702e193231c /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java | |
parent | [client] Resolve user ids to names in image list window. (diff) | |
download | tutor-module-83ec934d4b1734006488bf203e21dcc5ddb8071d.tar.gz tutor-module-83ec934d4b1734006488bf203e21dcc5ddb8071d.tar.xz tutor-module-83ec934d4b1734006488bf203e21dcc5ddb8071d.zip |
[client] Added lecture list window with table, sorting and filter. Added back button for lecture and image window.
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java | 173 |
1 files changed, 173 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java new file mode 100644 index 00000000..2f3aa76b --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureListWindow.java @@ -0,0 +1,173 @@ +package org.openslx.dozmod.gui.window; + +import java.text.SimpleDateFormat; +import java.util.Date; +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.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.bwlp.thrift.iface.UserInfo; +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; + +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; + String leName = lecture.getLectureName(); + if (leName == null) { + lectureName.setText("Unknown"); + } else { + lectureName.setText(leName); + } + + + // id of the lecture + String lectureBaseId = lecture.getLectureId(); + if (lectureBaseId == null) { + idInfo.setText("Unknown"); + } else { + idInfo.setText(lectureBaseId); + } + + // id of the image linked to the lecture + String baseId = lecture.getImageBaseId(); + if (baseId == null) { + imageBaseId.setText("Unknown"); + } else { + imageBaseId.setText(baseId); + } + + // set the time, the lecture has last been used + long lastUsedTimestamp = lecture.getLastUsed(); + if (lastUsedTimestamp == 0) { + lastusedInfo.setText("Unknown"); + } else { + Date date = new Date(lastUsedTimestamp * 1000L); + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); + String formattedDate = sdf.format(date); + lastusedInfo.setText(formattedDate); + } + + // set the start time of the lecture + long startTimestamp = lecture.getStartTime(); + if (startTimestamp == 0) { + startTime.setText("Unknown"); + } else { + Date date = new Date(startTimestamp * 1000L); + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); + String formattedDate = sdf.format(date); + startTime.setText(formattedDate); + } + + // set the end time of the lecture + long endTimestamp = lecture.getEndTime(); + if (endTimestamp == 0) { + endTime.setText("Unknown"); + } else { + Date date = new Date(endTimestamp * 1000L); + SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); + String formattedDate = sdf.format(date); + endTime.setText(formattedDate); + } + + // the owner id of the selected lecture + String ownerId = lecture.getOwnerId(); + UserInfo user = UserCache.find(ownerId); + if (user != null) { + ownerInfo.setText(user.getLastName() + ", " + user.getFirstName()); + } else { + ownerInfo.setText("Unknown"); + } + + } + }); + + 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(); + } + +} |