summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-29 15:13:31 +0200
committerSimon Rettberg2015-07-29 15:13:31 +0200
commit6df96bae8fa1fad04293e35a19df4edb9c4ff5f5 (patch)
treedb24e7ce96ec8d80353de782f5c3550aee354cdd /dozentenmodul/src/main/java/org/openslx/dozmod/gui/control
parent[server] Fix canLogin logic for Organization (diff)
downloadtutor-module-6df96bae8fa1fad04293e35a19df4edb9c4ff5f5.tar.gz
tutor-module-6df96bae8fa1fad04293e35a19df4edb9c4ff5f5.tar.xz
tutor-module-6df96bae8fa1fad04293e35a19df4edb9c4ff5f5.zip
[client] Add JTable helper class ListTable
Use it for lecture list
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java26
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java99
2 files changed, 125 insertions, 0 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java
new file mode 100644
index 00000000..dc2c93f8
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureTable.java
@@ -0,0 +1,26 @@
+package org.openslx.dozmod.gui.control.table;
+
+import org.openslx.bwlp.thrift.iface.LectureSummary;
+import org.openslx.dozmod.thrift.UserCache;
+import org.openslx.dozmod.util.FormatHelper;
+
+@SuppressWarnings("serial")
+public class LectureTable extends ListTable<LectureSummary> {
+
+ private static String[] columnNames = { "Name", "Verantwortlicher" };
+
+ public LectureTable() {
+ super(columnNames);
+ }
+
+ @Override
+ protected Object getValueAtInternal(int rowIndex, int columnIndex) {
+ LectureSummary row = get(rowIndex);
+ if (columnIndex == 0)
+ return row.getLectureName();
+ if (columnIndex == 1)
+ return FormatHelper.userName(UserCache.find(row.getOwnerId()));
+ throw new IndexOutOfBoundsException();
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java
new file mode 100644
index 00000000..9e6262f3
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java
@@ -0,0 +1,99 @@
+package org.openslx.dozmod.gui.control.table;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.swing.JTable;
+import javax.swing.ListSelectionModel;
+import javax.swing.table.AbstractTableModel;
+import javax.swing.table.TableRowSorter;
+
+@SuppressWarnings("serial")
+public abstract class ListTable<T> extends JTable {
+
+ private final ListModel model;
+
+ private final TableRowSorter<ListModel> sorter;
+
+ public ListTable(String[] columnNames) {
+ super();
+ this.model = new ListModel(columnNames);
+ this.sorter = new TableRowSorter<>(model);
+ this.setModel(model);
+ this.setRowSorter(sorter);
+ this.setShowGrid(false);
+ this.setCellSelectionEnabled(false);
+ this.createDefaultColumnsFromModel();
+ //this.setAutoCreateRowSorter(true);
+ this.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
+ this.getTableHeader().setReorderingAllowed(false);
+ //this.setDefaultRenderer(Object.class, new TableRenderer());
+ this.setRowSelectionAllowed(true);
+ this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
+ }
+
+ protected abstract Object getValueAtInternal(int rowIndex, int columnIndex);
+
+ public T get(int rowIndex) {
+ if (rowIndex < 0 || rowIndex >= getRowCount())
+ throw new IndexOutOfBoundsException();
+ return model.data.get(rowIndex);
+ }
+
+ public T getSelectedItem() {
+ int rowIndex = getSelectedRow();
+ if (rowIndex == -1)
+ return null;
+ return get(convertRowIndexToModel(rowIndex));
+ }
+
+ public void setData(List<T> data) {
+ model.setData(data);
+ }
+
+ /**
+ * Model for our table
+ */
+ private class ListModel extends AbstractTableModel {
+
+ private final String[] columnNames;
+
+ protected List<T> data = null;
+
+ public ListModel(String[] columnNames) {
+ this.columnNames = columnNames;
+ }
+
+ public void setData(List<T> list) {
+ this.data = new ArrayList<>(list);
+ fireTableDataChanged();
+ }
+
+ @Override
+ public int getRowCount() {
+ return data == null ? 0 : data.size();
+ }
+
+ @Override
+ public int getColumnCount() {
+ return columnNames.length;
+ }
+
+ @Override
+ public String getColumnName(int col) {
+ return columnNames[col];
+ }
+
+ @Override
+ public Class<?> getColumnClass(int c) {
+ return String.class;
+ }
+
+ @Override
+ public Object getValueAt(int rowIndex, int columnIndex) {
+ return getValueAtInternal(rowIndex, columnIndex);
+ }
+
+ }
+
+}