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 | |
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.
12 files changed, 627 insertions, 66 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java index 2c50bc2e..c7def177 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java @@ -22,6 +22,7 @@ import org.openslx.dozmod.gui.helper.CompositePage; import org.openslx.dozmod.gui.helper.MessageType; import org.openslx.dozmod.gui.window.DisclaimerWindow; import org.openslx.dozmod.gui.window.ImageListWindow; +import org.openslx.dozmod.gui.window.LectureListWindow; import org.openslx.dozmod.gui.window.LoginWindow; import org.openslx.dozmod.gui.window.MainMenuWindow; import org.openslx.dozmod.gui.window.VirtualizerNoticeWindow; @@ -188,6 +189,7 @@ public abstract class MainWindow { // register all pages of the main window registerPage(new MainMenuWindow(mainShell)); registerPage(new ImageListWindow(mainShell)); + registerPage(new LectureListWindow(mainShell)); // Show main menu by default showPage(MainMenuWindow.class); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListComparator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListComparator.java index 75031beb..b684b61f 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListComparator.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListComparator.java @@ -6,11 +6,12 @@ import org.eclipse.swt.SWT; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.dozmod.thrift.MetaDataCache; +import org.openslx.dozmod.thrift.UserCache; public class ImageListComparator extends ViewerComparator{ private int tableColumn; private static final int DESCENDING = 1; - + // possible columns private static final int IMAGENAME = 0; private static final int OS = 1; @@ -58,7 +59,9 @@ public class ImageListComparator extends ViewerComparator{ comparisonResult = os1.getOsName().compareTo(os2.getOsName()); break; case OWNER: - comparisonResult = i1.getOwnerId().compareTo(i2.getOwnerId()); + String owner1 = UserCache.find(i1.getOwnerId()).getLastName() + ", " + UserCache.find(i1.getOwnerId()).getFirstName(); + String owner2 = UserCache.find(i2.getOwnerId()).getLastName() + ", " + UserCache.find(i2.getOwnerId()).getFirstName(); + comparisonResult = owner1.compareTo(owner2); break; case UPDATETIME: comparisonResult = Long.compare(i1.getUpdateTime(),i2.getUpdateTime()); @@ -72,7 +75,7 @@ public class ImageListComparator extends ViewerComparator{ } catch (Exception e) { // Don't order if something went wrong (field not set) - return -100; + return 0; } // If descending order, flip the direction if (direction == DESCENDING) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListFilter.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListFilter.java index 2e3860cb..c98fc791 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListFilter.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageListFilter.java @@ -4,7 +4,9 @@ import org.eclipse.jface.viewers.Viewer; import org.eclipse.jface.viewers.ViewerFilter; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.OperatingSystem; +import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.thrift.MetaDataCache; +import org.openslx.dozmod.thrift.UserCache; /** @@ -31,8 +33,9 @@ public class ImageListFilter extends ViewerFilter { return true; } - // TODO fix when resolving owner id in table - if (i.getOwnerId().toLowerCase().matches(searchString.toLowerCase())) { + UserInfo user = UserCache.find(i.getOwnerId()); + if (user.getFirstName().toLowerCase().matches(searchString.toLowerCase()) + || user.getLastName().toLowerCase().matches(searchString.toLowerCase())) { return true; } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListComparator.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListComparator.java new file mode 100644 index 00000000..170bcac4 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListComparator.java @@ -0,0 +1,70 @@ +package org.openslx.dozmod.gui.helper; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerComparator; +import org.eclipse.swt.SWT; +import org.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.dozmod.thrift.UserCache; + +public class LectureListComparator extends ViewerComparator{ + private int tableColumn; + private static final int DESCENDING = 1; + + // possible columns + private static final int LECTURENAME = 0; + private static final int OWNER = 1; + + private int direction; + + public LectureListComparator() { + this.tableColumn = 0; + this.direction = DESCENDING; + } + + public int getDirection() { + return direction == 1 ? SWT.DOWN : SWT.UP; + } + + public void setColumn(int column) { + if (column == this.tableColumn) { + // Same column as last sort; toggle the direction + direction = 1 - direction; + } else { + // New column; do an ascending sort + this.tableColumn = column; + direction = DESCENDING; + } + } + + @Override + public int compare(Viewer viewer, Object e1, Object e2) { + LectureSummary l1 = (LectureSummary) e1; + LectureSummary l2 = (LectureSummary) e2; + + int comparisonResult = 0; + try { + // Decide how to compare depending on the column index + switch (tableColumn) { + case LECTURENAME: + comparisonResult = l1.getLectureName().compareTo(l2.getLectureName()); + break; + case OWNER: + String owner1 = UserCache.find(l1.getOwnerId()).getLastName() + ", " + UserCache.find(l1.getOwnerId()).getFirstName(); + String owner2 = UserCache.find(l2.getOwnerId()).getLastName() + ", " + UserCache.find(l2.getOwnerId()).getFirstName(); + comparisonResult = owner1.compareTo(owner2); + break; + default: + comparisonResult = 0; + } + + } catch (Exception e) { + // Don't order if something went wrong (field not set) + return 0; + } + // If descending order, flip the direction + if (direction == DESCENDING) { + comparisonResult = -comparisonResult; + } + return comparisonResult; + } +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListFilter.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListFilter.java new file mode 100644 index 00000000..025d2744 --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/LectureListFilter.java @@ -0,0 +1,48 @@ +package org.openslx.dozmod.gui.helper; + +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.viewers.ViewerFilter; +import org.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.bwlp.thrift.iface.UserInfo; +import org.openslx.dozmod.thrift.UserCache; + + +/** + * Filter for the lecture list + */ +public class LectureListFilter extends ViewerFilter { + + private String searchString; + + public void setSearchText(String s) { + // ensure that the value can be used for matching + this.searchString = ".*" + s + ".*"; + } + + // Determine whether to select the element depending on search string + @Override + public boolean select(Viewer viewer, Object parentElement, Object element) { + try { + if (searchString == null || searchString.length() == 0) { + return true; + } + LectureSummary i = (LectureSummary) element; + if (i.getLectureName().toLowerCase().matches(searchString.toLowerCase())) { + return true; + } + + UserInfo user = UserCache.find(i.getOwnerId()); + if (user.getFirstName().toLowerCase().matches(searchString.toLowerCase()) + || user.getLastName().toLowerCase().matches(searchString.toLowerCase())) { + return true; + } + + } catch (Exception e) { + // Don't show if something went wrong -> field probably not set + return false; + } + return false; + } +} + + diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java index a599cd4c..96bc18dc 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/TableHelper.java @@ -2,7 +2,6 @@ package org.openslx.dozmod.gui.helper; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.List; import org.eclipse.jface.viewers.ColumnLabelProvider; import org.eclipse.jface.viewers.TableViewer; @@ -12,6 +11,7 @@ import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; +import org.openslx.bwlp.thrift.iface.LectureSummary; import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.UserInfo; import org.openslx.dozmod.thrift.MetaDataCache; @@ -22,53 +22,32 @@ public final class TableHelper { } /** - * Create a column with the ability to be sorted - * - * @param tableViewer - * @param colName - * @param width column width - * @param colNumber index of the column - * @param provider the column label provider - */ - private static void createSortedColumn(TableViewer tableViewer, String colName, int width, int colNumber, - ColumnLabelProvider provider) { - TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE); - col.getColumn().setWidth(width); - col.getColumn().setText(colName); - col.setLabelProvider(provider); - // for column sorting - col.getColumn().addSelectionListener(getSelectionAdapter(col, colNumber, tableViewer)); - } - - /** - * Create a column for the given table viewer without sorting functionality - * @param tableViewer - * @param colName - * @param width - * @param provider + * Create the columns for the table in the lecture main window. + * Comparator has to be set beforehand. + * @param table the tableViewer */ - private static void createUnsortedColumn(TableViewer tableViewer, String colName, int width, ColumnLabelProvider provider) { - TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE); - col.getColumn().setWidth(width); - col.getColumn().setText(colName); - col.setLabelProvider(provider); - } + public static void createLectureTableColumns(TableViewer table) { + createSortedColumn(table, "Name", 150, 0, new ColumnLabelProvider() { + @Override + public String getText(Object element) { + LectureSummary lecture = (LectureSummary) element; + return lecture.getLectureName(); + } + }); - // selection listener for column sorting - private static SelectionListener getSelectionAdapter(final TableViewerColumn col, - final int colNumber, final TableViewer table) { - SelectionAdapter selectionAdapter = new SelectionAdapter() { + createSortedColumn(table, "Verantwortlicher", 130, 1, new ColumnLabelProvider() { @Override - public void widgetSelected(SelectionEvent e) { - ImageListComparator comparator = (ImageListComparator) table.getComparator(); - comparator.setColumn(colNumber); - int dir = comparator.getDirection(); - table.getTable().setSortDirection(dir); - table.getTable().setSortColumn(col.getColumn()); - table.refresh(); + public String getText(Object element) { + LectureSummary lecture = (LectureSummary) element; + String ownerId = lecture.getOwnerId(); + UserInfo user = UserCache.find(ownerId); + if (user == null){ + return "Unknown"; + }else { + return user.getLastName() + ", " + user.getFirstName(); + } } - }; - return selectionAdapter; + }); } /** @@ -86,7 +65,7 @@ public final class TableHelper { } }); - createSortedColumn(table, "OS", 130, 1, new ColumnLabelProvider() { + createSortedColumn(table, "OS", 150, 1, new ColumnLabelProvider() { @Override public String getText(Object element) { ImageSummaryRead image = (ImageSummaryRead) element; @@ -109,10 +88,9 @@ public final class TableHelper { if (user == null){ return "Unknown"; }else { - return user.firstName + " " + user.getLastName(); + return user.getLastName() + ", " + user.getFirstName(); } } - }); createSortedColumn(table, "Letztes Update", 110, 3, new ColumnLabelProvider() { @@ -184,4 +162,61 @@ public final class TableHelper { }); }; + + /** + * Create a column with the ability to be sorted + * + * @param tableViewer + * @param colName + * @param width column width + * @param colNumber index of the column + * @param provider the column label provider + */ + private static void createSortedColumn(TableViewer tableViewer, String colName, int width, int colNumber, + ColumnLabelProvider provider) { + TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE); + col.getColumn().setWidth(width); + col.getColumn().setText(colName); + col.setLabelProvider(provider); + // for column sorting + col.getColumn().addSelectionListener(getSelectionAdapter(col, colNumber, tableViewer)); + } + + /** + * Create a column for the given table viewer without sorting functionality + * @param tableViewer + * @param colName + * @param width + * @param provider + */ + private static void createUnsortedColumn(TableViewer tableViewer, String colName, int width, ColumnLabelProvider provider) { + TableViewerColumn col = new TableViewerColumn(tableViewer, SWT.NONE); + col.getColumn().setWidth(width); + col.getColumn().setText(colName); + col.setLabelProvider(provider); + } + + // selection listener for column sorting + private static SelectionListener getSelectionAdapter(final TableViewerColumn col, + final int colNumber, final TableViewer table) { + SelectionAdapter selectionAdapter = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + int dir = 0; + if (table.getComparator() instanceof ImageListComparator) { + ImageListComparator comparator = (ImageListComparator) table.getComparator(); + comparator.setColumn(colNumber); + dir = comparator.getDirection(); + } else if (table.getComparator() instanceof LectureListComparator) { + LectureListComparator comparator = (LectureListComparator) table.getComparator(); + comparator.setColumn(colNumber); + dir = comparator.getDirection(); + } + table.getTable().setSortDirection(dir); + table.getTable().setSortColumn(col.getColumn()); + table.refresh(); + } + }; + return selectionAdapter; + } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java index 81a89205..0e097720 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java @@ -118,7 +118,7 @@ public class ImageListWindow extends ImageListWindowLayout { String ownerId = selectedElement.getOwnerId(); UserInfo user = UserCache.find(ownerId); if (user != null) { - ownerInfo.setText(user.getFirstName() + " " + user.getLastName()); + ownerInfo.setText(user.getLastName() + ", " + user.getFirstName()); } else { ownerInfo.setText("Unknown"); } @@ -149,6 +149,7 @@ public class ImageListWindow extends ImageListWindowLayout { wd.open(); } }); + //deleteImageVersion deleteButton.addSelectionListener(new SelectionAdapter() { @Override @@ -185,6 +186,14 @@ public class ImageListWindow extends ImageListWindowLayout { }); } }); + + // return to mainMenu + backButton.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + MainWindow.showPage(MainMenuWindow.class); + } + }); } private boolean refreshList() { @@ -212,7 +221,7 @@ public class ImageListWindow extends ImageListWindowLayout { Gui.showMessageBox(getShell(), "Failed to delete image!", MessageType.ERROR, LOGGER, t); } } - + public ImageSummaryRead getCurrentImageSummaryRead() { IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection(); return (ImageSummaryRead) selection.getFirstElement(); 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(); + } + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java index 7b2fa94b..f36b85e2 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java @@ -22,8 +22,7 @@ public class MainMenuWindow extends MainMenuWindowLayout { lecturesButton.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { - // - } + MainWindow.showPage(LectureListWindow.class); } }); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java index aa50a425..be0f74ca 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java @@ -25,6 +25,7 @@ public abstract class ImageListWindowLayout extends CompositePage { protected String editButtonLabel = "Bearbeiten"; protected String deleteButtonLabel = "Löschen"; protected String downloadButtonLabel = "Download"; + protected String backButtonLabel = "Zurück"; protected String tableGroupLabel = "Images"; protected String vmInfoGroupLabel = "Detailinformationen"; protected String filterGroupLabel = "Filter"; @@ -34,7 +35,8 @@ public abstract class ImageListWindowLayout extends CompositePage { protected Button deleteButton; protected Button editButton; protected Button downloadButton; - + protected Button backButton; + // imageDetail texts protected Text imageSelectedNameLabel; @@ -44,7 +46,7 @@ public abstract class ImageListWindowLayout extends CompositePage { protected Text permissionInfo; protected Text ownerInfo; protected Text templateInfo; - + protected final Text searchTextField; protected final TableViewer tableViewer; @@ -79,7 +81,7 @@ public abstract class ImageListWindowLayout extends CompositePage { infoText.setText(infoTextString); // -- end group of title -- - + // -- group for the table -- Group tableGroup = new Group(this, SWT.BORDER); tableGroup.setText(tableGroupLabel); @@ -88,7 +90,7 @@ public abstract class ImageListWindowLayout extends CompositePage { tgLayoutData.widthHint = 800; tableGroup.setLayoutData(tgLayoutData); tableGroup.setLayout(new GridLayout()); - + // -- group for the filter -- Group filterGroup = new Group(tableGroup, SWT.BORDER); filterGroup.setText(filterGroupLabel); @@ -98,12 +100,12 @@ public abstract class ImageListWindowLayout extends CompositePage { fgGridData.horizontalSpan = 2; filterGroup.setLayoutData(fgGridData); filterGroup.setLayout(new GridLayout()); - + // filter text field searchTextField = new Text(filterGroup, SWT.BORDER); searchTextField.setMessage("Name, Verantwortlicher, OS"); // -- end group of filter -- - + // table Table vmTable = new Table(tableGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true); @@ -114,8 +116,8 @@ public abstract class ImageListWindowLayout extends CompositePage { // TableViewer on the table tableViewer = new TableViewer(vmTable); tableViewer.setContentProvider(ArrayContentProvider.getInstance()); - - + + // create, modify, download and delete buttons Composite buttonComposite = new Composite(tableGroup, SWT.NONE); @@ -135,6 +137,9 @@ public abstract class ImageListWindowLayout extends CompositePage { downloadButton = new Button(buttonComposite, SWT.PUSH); downloadButton.setText(downloadButtonLabel); + + backButton = new Button(buttonComposite, SWT.PUSH); + backButton.setText(backButtonLabel); // -- end group for table -- // -- group for details of selected image -- @@ -148,12 +153,14 @@ public abstract class ImageListWindowLayout extends CompositePage { // image name info imageSelectedNameLabel = createCaptionAndTextfield("Image Name:", vmInfoGroup); idInfo = createCaptionAndTextfield("ID:", vmInfoGroup); - versionInfo = createCaptionAndTextfield("Version", vmInfoGroup); + versionInfo = createCaptionAndTextfield("Version:", vmInfoGroup); lastUpdateInfo = createCaptionAndTextfield("Letztes Update:", vmInfoGroup); permissionInfo = createCaptionAndTextfield("Berechtigungen:", vmInfoGroup); - ownerInfo = createCaptionAndTextfield("Besitzer ID", vmInfoGroup); + ownerInfo = createCaptionAndTextfield("Besitzer:", vmInfoGroup); templateInfo = createCaptionAndTextfield("Vorlage:", vmInfoGroup); // -- end group of details -- + + } public Text createCaptionAndTextfield(String captionString, Group group) { diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java new file mode 100644 index 00000000..9bfbe3ee --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureListWindowLayout.java @@ -0,0 +1,172 @@ +package org.openslx.dozmod.gui.window.layout; + +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.Text; +import org.openslx.dozmod.gui.Gui; +import org.openslx.dozmod.gui.helper.CompositePage; +import org.openslx.dozmod.gui.helper.LectureListFilter; + +public abstract class LectureListWindowLayout extends CompositePage { + + protected String infoTitleString = "Übersicht Veranstaltungen"; + protected String newButtonLabel = "Neu"; + protected String editButtonLabel = "Bearbeiten"; + protected String deleteButtonLabel = "Löschen"; + protected String backButtonLabel = "Zurück"; + protected String tableGroupLabel = "Veranstaltungen"; + protected String vmInfoGroupLabel = "Detailinformationen"; + protected String filterGroupLabel = "Filter"; + + // buttons + protected Button newButton; + protected Button deleteButton; + protected Button editButton; + protected Button backButton; + + + // imageDetail texts + protected Text lectureName; + protected Text idInfo; + protected Text imageBaseId; + protected Text lastusedInfo; + protected Text permissionInfo; + protected Text ownerInfo; + protected Text startTime; + protected Text endTime; + + protected final Text searchTextField; + + protected final TableViewer tableViewer; + protected LectureListFilter filter; + + protected String infoTextString = "Hier können Sie Veranstaltungen anlegen, bearbeiten und löschen."; + + public LectureListWindowLayout(final Composite mainShell) { + super(mainShell, SWT.NONE); + + // the layout and layoutData of the LectureListWindow + this.setLayout(new GridLayout(2, false)); + this.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + // -- info group with title and text -- + Composite infoComposite = new Composite(this, SWT.BORDER); + GridData infoGridData = new GridData(SWT.FILL, SWT.FILL, true, false); + infoGridData.horizontalSpan = 2; + infoComposite.setLayoutData(infoGridData); + // layout for the items of the group + infoComposite.setLayout(new GridLayout(1, false)); + + // title of the info group in bold + Label infoTitle = new Label(infoComposite, SWT.NONE); + infoTitle.setText(infoTitleString); + // set the fond + FontData fontData = infoTitle.getFont().getFontData()[0]; + Font font = new Font(Gui.display, new FontData(fontData.getName(), fontData.getHeight(), SWT.BOLD)); + infoTitle.setFont(font); + // the infotext + Label infoText = new Label(infoComposite, SWT.NONE); + infoText.setText(infoTextString); + // -- end group of title -- + + + // -- group for the table -- + Group tableGroup = new Group(this, SWT.BORDER); + tableGroup.setText(tableGroupLabel); + GridData tgLayoutData = new GridData(SWT.FILL, SWT.FILL, true, true); + tgLayoutData.minimumWidth = 400; + tgLayoutData.widthHint = 800; + tableGroup.setLayoutData(tgLayoutData); + tableGroup.setLayout(new GridLayout()); + + // -- group for the filter -- + Group filterGroup = new Group(tableGroup, SWT.BORDER); + filterGroup.setText(filterGroupLabel); + GridData fgGridData = new GridData(SWT.FILL, SWT.TOP, true, false); + fgGridData.minimumWidth = 400; + fgGridData.widthHint = 800; + fgGridData.horizontalSpan = 2; + filterGroup.setLayoutData(fgGridData); + filterGroup.setLayout(new GridLayout()); + + // filter text field + searchTextField = new Text(filterGroup, SWT.BORDER); + searchTextField.setMessage("Name, Verantwortlicher"); + // -- end group of filter -- + + // table + Table vmTable = new Table(tableGroup, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL); + GridData tableGridData = new GridData(SWT.FILL, SWT.FILL, true, true); + vmTable.setLayoutData(tableGridData); + vmTable.setHeaderVisible(true); + vmTable.setLinesVisible(true); + + // TableViewer on the table + tableViewer = new TableViewer(vmTable); + tableViewer.setContentProvider(ArrayContentProvider.getInstance()); + + + + // create, modify and delete buttons + Composite buttonComposite = new Composite(tableGroup, SWT.NONE); + GridData buttonCompositeGridData = new GridData(SWT.FILL, SWT.FILL, true, false); + buttonCompositeGridData.minimumWidth = 200; + buttonComposite.setLayoutData(buttonCompositeGridData); + buttonComposite.setLayout(new RowLayout()); + + newButton = new Button(buttonComposite, SWT.PUSH); + newButton.setText(newButtonLabel); + + editButton = new Button(buttonComposite, SWT.PUSH); + editButton.setText(editButtonLabel); + + deleteButton = new Button(buttonComposite, SWT.PUSH); + deleteButton.setText(deleteButtonLabel); + + backButton = new Button(buttonComposite, SWT.PUSH); + backButton.setText(backButtonLabel); + // -- end group for table -- + + // -- group for details of selected lecture -- + final Group vmInfoGroup = new Group(this, SWT.BORDER); + vmInfoGroup.setText(vmInfoGroupLabel); + final GridData igGridData = new GridData(SWT.FILL, SWT.FILL, true, false); + igGridData.widthHint = 300; + vmInfoGroup.setLayoutData(igGridData); + vmInfoGroup.setLayout(new GridLayout(2, false)); + + // image name info + lectureName = createCaptionAndTextfield("Name:", vmInfoGroup); + idInfo = createCaptionAndTextfield("Id:", vmInfoGroup); + imageBaseId = createCaptionAndTextfield("Image Id:", vmInfoGroup); + lastusedInfo = createCaptionAndTextfield("Zuletzt genutzt:", vmInfoGroup); + permissionInfo = createCaptionAndTextfield("Berechtigungen:", vmInfoGroup); + startTime = createCaptionAndTextfield("Startzeit:", vmInfoGroup); + endTime = createCaptionAndTextfield("Endzeit:", vmInfoGroup); + ownerInfo = createCaptionAndTextfield("Besitzer:", vmInfoGroup); + // -- end group of details -- + } + + public Text createCaptionAndTextfield(String captionString, Group group) { + Label caption = new Label(group, SWT.NONE); + Text textField = new Text(group, SWT.READ_ONLY); + caption.setText(captionString); + caption.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false)); + GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false); + gridData.minimumWidth = 180; + textField.setLayoutData(gridData); + return textField; + } + +} diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/LectureCache.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/LectureCache.java new file mode 100644 index 00000000..eb80b61e --- /dev/null +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/LectureCache.java @@ -0,0 +1,40 @@ +package org.openslx.dozmod.thrift; + +import java.util.List; + +import org.apache.thrift.TException; +import org.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.bwlp.thrift.iface.TAuthorizationException; +import org.openslx.bwlp.thrift.iface.TInternalServerError; +import org.openslx.thrifthelper.ThriftManager; +import org.openslx.util.GenericDataCache; +import org.openslx.util.GenericDataCache.CacheMode; + +public class LectureCache { + + private static final int CACHE_TIME_LIST_MS = 2 * 60 * 1000; + + private static final GenericDataCache<List<LectureSummary>> listCache = new GenericDataCache<List<LectureSummary>>(CACHE_TIME_LIST_MS) { + @Override + protected List<LectureSummary> update() throws TAuthorizationException, TInternalServerError, TException { + List<LectureSummary> result = null; + int pageSize = ThriftManager.getSatClient().getPageSize(); + for (int i = 0;; ++i) { + List<LectureSummary> page = ThriftManager.getSatClient().getLectureList(Session.getSatelliteToken(), i); + if (result == null) { + result = page; + } else { + result.addAll(page); + } + if (page.size() < pageSize) + break; + } + return result; + } + }; + + public static List<LectureSummary> get(boolean forceRefresh) { + return listCache.get(forceRefresh ? CacheMode.NEVER_CACHED : CacheMode.DEFAULT); + } + +} |