summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table
diff options
context:
space:
mode:
authorSimon Rettberg2018-11-26 15:51:31 +0100
committerSimon Rettberg2018-11-26 15:51:31 +0100
commita06c4dcb0ae2d829350c035d67b603c831088940 (patch)
treea23d632a9aa0af9861a2e844d13b28bc91caa04a /dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table
parent[client] Add edit support to ListTable (diff)
downloadtutor-module-a06c4dcb0ae2d829350c035d67b603c831088940.tar.gz
tutor-module-a06c4dcb0ae2d829350c035d67b603c831088940.tar.xz
tutor-module-a06c4dcb0ae2d829350c035d67b603c831088940.zip
[client] Support predefined filters in LDAP editor
Diffstat (limited to 'dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/CheckListTable.java157
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java39
2 files changed, 193 insertions, 3 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/CheckListTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/CheckListTable.java
new file mode 100644
index 00000000..d9527612
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/CheckListTable.java
@@ -0,0 +1,157 @@
+package org.openslx.dozmod.gui.control.table;
+
+import java.awt.Component;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
+import javax.swing.Box;
+
+import org.apache.log4j.Logger;
+
+public abstract class CheckListTable<T> extends ListTable<CheckListTable.Wrapper<T>> {
+
+ private static final long serialVersionUID = 5667297891670398732L;
+
+ private static final Logger LOGGER = Logger.getLogger(CheckListTable.class);
+
+ public static final ListTableColumn COL_CHECKBOX = new ListTableColumn("", Boolean.class, null, true);
+
+ private static final Component LBL_EMPTY_CELL = Box.createHorizontalGlue();
+
+ public CheckListTable(ListTableColumn... columns) {
+ this(null, columns);
+ }
+
+ public CheckListTable(final Comparator<T> itemComparator, ListTableColumn... columns) {
+ super(new Comparator<Wrapper<T>>() {
+ @Override
+ public int compare(Wrapper<T> o1, Wrapper<T> o2) {
+ if (o1 == null && o2 == null)
+ return 0;
+ if (o1 == null)
+ return -1;
+ if (o2 == null)
+ return 1;
+ return itemComparator.compare(o1.item, o2.item);
+ }
+
+ }, copyColumns(columns));
+ /*
+ this.setDefaultEditor(Boolean.class, new DefaultCellEditor {
+ public DefaultCellEditor(new JCheckBox()) {
+ JCheckBox checkBox = (JCheckBox)getComponent();
+ checkBox.setHorizontalAlignment(JCheckBox.CENTER);
+ }
+ });
+ /*
+ addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ int column = getSelectedColumn();
+ if (column != 0)
+ return;
+ int row = getSelectedRow();
+ if (row < 0 || row >= getRowCount())
+ return;
+ getce
+ }
+ });
+ */
+ }
+
+ private static ListTableColumn[] copyColumns(ListTableColumn[] columns) {
+ final ListTableColumn ncolumns[] = new ListTableColumn[columns.length + 1];
+ ncolumns[0] = COL_CHECKBOX;
+ System.arraycopy(columns, 0, ncolumns, 1, columns.length);
+ return ncolumns;
+ }
+
+ @Override
+ public void setValueAt(Object newValue, Wrapper<T> row, ListTableColumn column) {
+ if (column == COL_CHECKBOX && newValue != null && newValue.getClass() == Boolean.class) {
+ row.isChecked = (Boolean)newValue;
+ }
+ }
+
+ @Override
+ protected final Object getValueAtInternal(Wrapper<T> row, ListTableColumn columnIndex) {
+ if (row.item == null)
+ return null;
+ if (columnIndex == COL_CHECKBOX) {
+ return row.isChecked;
+ }
+ return getValueAtInternal2(row.item, columnIndex);
+ }
+
+ protected abstract Object getValueAtInternal2(T row, ListTableColumn columnIndex);
+
+ @Override
+ public final Component prepareRenderHook(Component component, Wrapper<T> row,
+ ListTableColumn listTableColumn, boolean isSelected) {
+ if (listTableColumn == COL_CHECKBOX) {
+ if (row == null || row.item == null || !isItemCheckable(row.item)) {
+ return LBL_EMPTY_CELL;
+ }
+ } else if (row.item != null) {
+ component = prepareRenderHook2(component, row.item, listTableColumn, isSelected);
+ }
+ return component;
+ }
+
+ public Component prepareRenderHook2(Component component, T row,
+ ListTableColumn listTableColumn, boolean isSelected) {
+ // Nothing
+ return component;
+ }
+
+ public void setData(List<T> data, Set<T> preChecked, boolean sort) {
+ List<Wrapper<T>> list = new ArrayList<>(data.size());
+ for (T item : data) {
+ list.add(new Wrapper<T>(item, preChecked != null && preChecked.contains(item)));
+ }
+ super.setData(list, sort);
+ }
+
+ protected abstract boolean isItemCheckable(T item);
+
+ public T getSelectedItem2() {
+ Wrapper<T> ret = getSelectedItem();
+ if (ret == null)
+ return null;
+ return ret.item;
+ }
+
+ public static class Wrapper<S> {
+
+ protected boolean isChecked;
+ public final S item;
+
+ public Wrapper(S item, boolean checked) {
+ this.item = item;
+ this.isChecked = checked;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ return item.equals(obj);
+ }
+
+ @Override
+ public int hashCode() {
+ return item.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return "(" + item.hashCode() + "=" + isChecked + ")";
+ }
+
+ public boolean isChecked() {
+ return isChecked;
+ }
+
+ }
+
+}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
index ac5e8e0f..70d0291e 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/LectureLdapFilterTable.java
@@ -1,24 +1,57 @@
package org.openslx.dozmod.gui.control.table;
+import java.awt.Color;
+import java.awt.Component;
+
+import javax.swing.UIManager;
+
import org.openslx.bwlp.thrift.iface.LdapFilter;
+import org.openslx.dozmod.gui.helper.ColorUtil;
@SuppressWarnings("serial")
-public class LectureLdapFilterTable extends ListTable<LdapFilter> {
+public class LectureLdapFilterTable extends CheckListTable<LdapFilter> {
+ public static final ListTableColumn COL_TITLE = new ListTableColumn("Name");
public static final ListTableColumn COL_ATTRIBUTE = new ListTableColumn("Attribut");
public static final ListTableColumn COL_VALUE = new ListTableColumn("Wert");
+
+ private final Color invalidColor;
public LectureLdapFilterTable() {
- super(COL_ATTRIBUTE, COL_VALUE);
+ super(COL_TITLE, COL_ATTRIBUTE, COL_VALUE);
+ Color fg = UIManager.getColor("Table.foreground");
+ Color bg = UIManager.getColor("Table.background");
+ invalidColor = ColorUtil.blend(fg, bg, .66f);
}
@Override
- protected Object getValueAtInternal(LdapFilter item, ListTableColumn columnIndex) {
+ protected Object getValueAtInternal2(LdapFilter item, ListTableColumn columnIndex) {
+ if (columnIndex == COL_TITLE) {
+ if (item.filterId == 0)
+ return "";
+ return item.title;
+ }
if (columnIndex == COL_ATTRIBUTE)
return item.attribute;
if (columnIndex == COL_VALUE)
return item.value;
throw new IndexOutOfBoundsException();
}
+
+ @Override
+ public Component prepareRenderHook2(Component component, LdapFilter row,
+ ListTableColumn listTableColumn, boolean isSelected) {
+ if (row.filterId == 0) {
+ component.setForeground(isSelected ? getSelectionForeground() : getForeground());
+ } else {
+ component.setForeground(invalidColor);
+ }
+ return component;
+ }
+
+ @Override
+ protected boolean isItemCheckable(LdapFilter item) {
+ return item.filterId > 0;
+ }
}