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.jface.wizard.WizardDialog; 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.gui.wizard.LectureWizard; 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(""); } else { control.setText(content); } } }); newButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { new WizardDialog(mainShell, new LectureWizard(false)).open(); } }); 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 lectureList = LectureCache.get(false); tableViewer.setInput(lectureList); tableViewer.refresh(); return true; } @Override public boolean hide() { return true; } @Override public void show() { refreshList(); } }