summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-13 15:45:10 +0200
committerSimon Rettberg2015-08-13 15:45:10 +0200
commit9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7 (patch)
treefc32e08b30d5643cf1bbd1753ec6f1cc076a8217 /dozentenmodul/src/main/java/org
parent[client] Fix positioning of Wizard (diff)
downloadtutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.tar.gz
tutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.tar.xz
tutor-module-9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7.zip
[client] Layout tweaks, Change owner feature
Diffstat (limited to 'dozentenmodul/src/main/java/org')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java27
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ListTable.java61
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java27
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java72
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/MainMenuWindow.java2
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java46
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java119
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java16
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java22
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/permissions/ImagePerms.java25
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java64
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java62
14 files changed, 388 insertions, 165 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java
index 08656cd5..4fa33798 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/ImageTable.java
@@ -1,5 +1,7 @@
package org.openslx.dozmod.gui.control.table;
+import java.util.Comparator;
+
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.dozmod.thrift.MetaDataCache;
import org.openslx.dozmod.thrift.UserCache;
@@ -8,15 +10,26 @@ import org.openslx.dozmod.util.FormatHelper;
@SuppressWarnings("serial")
public class ImageTable extends ListTable<ImageSummaryRead> {
- private static String[] columnNames =
- { "Name", "OS", "Besitzer", "Letztes Update", "Größe", "Version", "Vorlage" };
+ private static String[] columnNames = { "Name", "OS", "Besitzer", "Letztes Update", "Größe", "Version",
+ "Vorlage" };
+
+ private static Class<?>[] columnClasses = { String.class, String.class, String.class, String.class,
+ String.class, String.class, Boolean.class };
- private static Class<?>[] columnClasses =
- { String.class, String.class, String.class, String.class, String.class, String.class, Boolean.class };
-
public ImageTable() {
- super(columnNames, columnClasses);
-
+ super(columnNames, columnClasses, new Comparator<ImageSummaryRead>() {
+ @Override
+ public int compare(ImageSummaryRead o1, ImageSummaryRead o2) {
+ if (o1 == null && o2 == null)
+ return 0;
+ if (o1 == null)
+ return 1;
+ if (o2 == null)
+ return -1;
+ return o1.imageBaseId.compareTo(o2.imageBaseId);
+ }
+ });
+
// sort with correct time and not lexicographic
getRowSorter().setComparator(3, timeComparator);
}
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
index e6176a2c..09bf1e00 100644
--- 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
@@ -23,6 +23,8 @@ import org.openslx.dozmod.gui.helper.TableColumnAdjuster;
@SuppressWarnings("serial")
public abstract class ListTable<T> extends JTable {
+ private final static Logger LOGGER = Logger.getLogger(ListTable.class);
+
private final ListModel model;
private final TableRowSorter<ListModel> sorter;
@@ -33,13 +35,26 @@ public abstract class ListTable<T> extends JTable {
protected final Comparator<Object> timeComparator;
- private final static Logger LOGGER = Logger.getLogger(ListTable.class);
+ private final Comparator<T> itemComparator;
+
+ public ListTable(String[] columnNames) {
+ this(columnNames, null, null);
+ }
+
+ public ListTable(String[] columnNames, Comparator<T> itemComparator) {
+ this(columnNames, null, itemComparator);
+ }
public ListTable(String[] columnNames, Class<?>[] columnClasses) {
+ this(columnNames, columnClasses, null);
+ }
+
+ public ListTable(String[] columnNames, Class<?>[] columnClasses, Comparator<T> itemComparator) {
super();
this.model = new ListModel(columnNames, columnClasses);
this.sorter = new TableRowSorter<ListModel>(model);
this.adjuster = new TableColumnAdjuster(this, 5);
+ this.itemComparator = itemComparator;
this.setModel(model);
this.setRowSorter(sorter);
this.setShowGrid(false);
@@ -89,11 +104,40 @@ public abstract class ListTable<T> extends JTable {
return getViewRow(rowIndex);
}
+ public boolean setSelectedItem(T item) {
+ int selectionIndex = -1;
+ for (int i = 0; i < model.data.size(); ++i) {
+ T rowItem = model.data.get(i);
+ if (itemComparator == null) {
+ if (rowItem.equals(item)) {
+ selectionIndex = i;
+ break;
+ }
+ } else {
+ if (itemComparator.compare(item, rowItem) == 0) {
+ selectionIndex = i;
+ break;
+ }
+ }
+ }
+ if (selectionIndex != -1) {
+ selectionIndex = convertRowIndexToView(selectionIndex);
+ }
+ if (selectionIndex == -1) {
+ getSelectionModel().clearSelection();
+ return false;
+ }
+ setRowSelectionInterval(selectionIndex, selectionIndex);
+ return true;
+ }
+
public void setData(List<T> data, boolean sort) {
+ T oldSelection = getSelectedItem();
model.setData(data);
adjuster.adjustColumns();
// handle sorting
- if (!sort) return;
+ if (!sort)
+ return;
if (sortKeys.isEmpty()) {
// sort by the first column by default
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
@@ -101,7 +145,11 @@ public abstract class ListTable<T> extends JTable {
}
// always sort
sorter.sort();
+ if (oldSelection != null) {
+ setSelectedItem(oldSelection);
+ }
}
+
@Override
public TableRowSorter<ListModel> getRowSorter() {
return sorter;
@@ -116,7 +164,7 @@ public abstract class ListTable<T> extends JTable {
private final Class<?>[] columnClasses;
- protected List<T> data = null;
+ protected ArrayList<T> data = null;
public ListModel(String[] columnNames, Class<?>[] columnClasses) {
@@ -163,14 +211,17 @@ public abstract class ListTable<T> extends JTable {
}
}
+
/**
* This renderer simply removes the default dotted border when
* a cell is selected
- *
+ *
*/
+@SuppressWarnings("serial")
class TableRenderer extends DefaultTableCellRenderer {
@Override
- public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
+ public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
+ boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
setBorder(noFocusBorder);
return this;
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java
index 05431827..99eac35b 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java
@@ -9,7 +9,7 @@ public class UserTable extends ListTable<UserInfo> {
private static String[] columnNames = { "Name", "Mail" };
public UserTable() {
- super(columnNames, null);
+ super(columnNames);
}
@Override
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java
index 8b941f6a..ef0bedef 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java
@@ -2,13 +2,13 @@ package org.openslx.dozmod.gui.helper;
import java.awt.Color;
import java.awt.Component;
+import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.util.ArrayList;
import javax.swing.Box;
-import javax.swing.JComponent;
import javax.swing.JPanel;
/**
@@ -22,7 +22,7 @@ public class GridManager {
*/
public static boolean debugEmptyCells = false;
- private final JComponent container;
+ private final Container container;
private final Insets defaultInsets;
private final int columnCount;
private final boolean strict;
@@ -47,7 +47,7 @@ public class GridManager {
* @param container The component to apply the layout to
* @param columnCount The number of columns per row
*/
- public GridManager(JComponent container, int columnCount) {
+ public GridManager(Container container, int columnCount) {
this(container, columnCount, true);
}
@@ -64,7 +64,7 @@ public class GridManager {
* row is full, and will ignore calls to {@link #nextRow()} if
* the current row is empty
*/
- public GridManager(JComponent container, int columnCount, boolean strict) {
+ public GridManager(Container container, int columnCount, boolean strict) {
this(container, columnCount, strict, new Insets(1, 1, 1, 1));
}
@@ -83,7 +83,7 @@ public class GridManager {
* @param defaultInsets an {@link Insets} instance to use for every cell by
* default
*/
- public GridManager(JComponent container, int columnCount, boolean strict, Insets defaultInsets) {
+ public GridManager(Container container, int columnCount, boolean strict, Insets defaultInsets) {
this.defaultInsets = defaultInsets;
this.container = container;
this.columnCount = columnCount;
@@ -109,6 +109,23 @@ public class GridManager {
/**
* Add the given component to the next free grid cell, applying the given
+ * horizontal cell-span.
+ *
+ * @param component Component to add
+ * @param spanX horizontal span
+ * @return A {@link GBC} instance that can be used to further influence the
+ * behavior of this component
+ * @throws IllegalArgumentException If there aren't enough columns left in
+ * the current row to add the given component with the desired
+ * horizontal span, or if one of the span parameters is
+ * <code>&lt; 1</code>
+ */
+ public GBC add(Component component, int spanX) {
+ return add(component, spanX, 1);
+ }
+
+ /**
+ * Add the given component to the next free grid cell, applying the given
* horizontal and vertical cell-span.
*
* @param component Component to add
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
index 3c9ccf56..0937d09d 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java
@@ -12,26 +12,31 @@ import java.util.Comparator;
import java.util.List;
import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImageSummaryRead;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.ShareMode;
+import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.bwlp.thrift.iface.Virtualizer;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.helper.MessageType;
import org.openslx.dozmod.gui.helper.PopupMenu;
import org.openslx.dozmod.gui.helper.UiFeedback;
+import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout;
import org.openslx.dozmod.gui.wizard.LectureWizard;
import org.openslx.dozmod.permissions.ImagePerms;
import org.openslx.dozmod.thrift.MetaDataCache;
import org.openslx.dozmod.thrift.Session;
+import org.openslx.dozmod.thrift.ThriftError;
import org.openslx.dozmod.thrift.UserCache;
import org.openslx.dozmod.util.FormatHelper;
import org.openslx.thrifthelper.ThriftManager;
@@ -80,6 +85,21 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
}
});
+ btnChangeOwner.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ UserListWindow.open(JOptionPane.getFrameForComponent(btnChangeOwner),
+ new UserAddedCallback() {
+ @Override
+ public void userAdded(UserInfo user, UserListWindow window) {
+ window.dispose();
+ setImageOwner(user);
+ }
+
+ }, "Besitzer festlegen");
+ }
+ });
+
// Setup popup menu for the right panel
final PopupMenu pop = new PopupMenu(new ActionListener() {
public void actionPerformed(ActionEvent e) {
@@ -140,11 +160,12 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
versionTableScrollPane.addMouseListener(ma);
versionTable.addMouseListener(ma);
+ btnIsTemplate.setEnabled(Session.isSuperUser());
+ makeEditable(false);
}
/**
- * @param imageBaseId
- * the id of the image to be displayed
+ * @param imageBaseId the id of the image to be displayed
*/
public void setImage(final String imageBaseId) {
@@ -182,6 +203,29 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
});
}
+ private void setImageOwner(final UserInfo user) {
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ try {
+ ThriftManager.getSatClient().setImageOwner(Session.getSatelliteToken(),
+ image.getImageBaseId(), user.getUserId());
+ } catch (TException e) {
+ ThriftError.showMessage(me, LOGGER, e, "Fehler beim Übertragen der Besitzrechte");
+ return;
+ }
+ Gui.showMessageBox(me, "Besitzrechte übertragen an " + FormatHelper.userName(user),
+ MessageType.INFO, null, null);
+ makeEditable(false);
+ String baseId = image.getImageBaseId();
+ synchronized (me) {
+ image = null;
+ }
+ setImage(baseId);
+ }
+ });
+ }
+
/**
* callback function when we received the image's details from the server
*/
@@ -266,38 +310,44 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
}
});
// make fields editable is allowed
- makeEditable(ImagePerms.canEdit(image));
+ makeEditable(true);
// finally do show it all
pack();
- MainWindow.centerShell(this);
setVisible(true);
}
+ @Override
+ public void show() {
+ if (!isVisible()) {
+ pack();
+ MainWindow.centerShell(this);
+ }
+ super.show();
+ }
+
/**
* Enables/disables the editable fields based on 'editable'
*
- * @param editable
- * true to make fields editable, false otherwise.
+ * @param editable true to make fields editable, false otherwise.
*/
private void makeEditable(boolean editable) {
+ editable = editable && ImagePerms.canEdit(image);
txtTitle.setEditable(editable);
txtDescription.setEditable(editable);
txtTags.setEditable(editable);
txtVersion.setEditable(editable);
txtId.setEditable(editable);
- btnIsTemplate.setEnabled(editable);
cboOperatingSystem.setEnabled(editable);
cboShareMode.setEnabled(editable);
+ btnChangeOwner.setEnabled(editable && ImagePerms.canAdmin(image));
}
/**
* Opens a new ImageDetailsWindow showing the details of the image with ID =
* imageBaseId
*
- * @param modalParent
- * parent of this window
- * @param imageBaseId
- * id of the image to set the details of
+ * @param modalParent parent of this window
+ * @param imageBaseId id of the image to set the details of
*/
public static void open(Frame modalParent, String imageBaseId) {
ImageDetailsWindow win = new ImageDetailsWindow(modalParent);
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 9569801d..2cd29a8d 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
@@ -5,6 +5,7 @@ import java.awt.event.ActionListener;
import org.openslx.dozmod.gui.MainWindow;
import org.openslx.dozmod.gui.window.layout.MainMenuWindowLayout;
+import org.openslx.dozmod.thrift.Session;
@SuppressWarnings("serial")
public class MainMenuWindow extends MainMenuWindowLayout {
@@ -35,6 +36,7 @@ public class MainMenuWindow extends MainMenuWindowLayout {
@Override
public void requestShow() {
+ vmButton.setEnabled(Session.canListImages());
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java
index f7399beb..188eb3cd 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java
@@ -28,8 +28,14 @@ public class UserListWindow extends UserListWindowLayout {
private final static Logger LOGGER = Logger.getLogger(UserListWindow.class);
- public UserListWindow(final Frame modalParent, final UserAddedCallback callback) {
- super(modalParent);
+ private final UserListWindow me = this;
+
+ public interface UserAddedCallback {
+ public void userAdded(UserInfo user, UserListWindow window);
+ }
+
+ public UserListWindow(final Frame modalParent, final UserAddedCallback callback, String actionCaption) {
+ super(modalParent, actionCaption);
addWindowListener(new WindowAdapter() {
@Override
@@ -70,32 +76,28 @@ public class UserListWindow extends UserListWindowLayout {
RowFilter.regexFilter("(?i)" + searchUserField.getText()));
searchUserField.setForeground(UIManager.getColor("TextField.foreground"));
} catch (IllegalArgumentException ex) {
- // TODO set background color of search field to something redish
searchUserField.setForeground(Color.RED);
}
}
});
- // ActionListener for the two buttons
- final ActionListener al = new ActionListener() {
+ setButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- if ("Set".equals(e.getActionCommand())) {
- final UserInfo user = userTable.getSelectedItem();
- if (user == null)
- return;
- callback.userAdded(user);
- }
- if ("Cancel".equals(e.getActionCommand())) {
- setVisible(false);
- dispose();
- }
+ final UserInfo user = userTable.getSelectedItem();
+ if (user == null)
+ return;
+ callback.userAdded(user, me);
+ }
+ });
+
+ cancelButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
}
- };
- setButton.setActionCommand("Set");
- setButton.addActionListener(al);
- cancelButton.setActionCommand("Cancel");
- cancelButton.addActionListener(al);
+ });
+
getRootPane().setDefaultButton(setButton);
userTable.addMouseListener(new MouseAdapter() {
@@ -109,7 +111,7 @@ public class UserListWindow extends UserListWindowLayout {
this.setLocationRelativeTo(modalParent);
}
- public static void open(Frame modalParent, final UserAddedCallback callback) {
- new UserListWindow(modalParent, callback).setVisible(true);
+ public static void open(Frame modalParent, UserAddedCallback callback, String actionCaption) {
+ new UserListWindow(modalParent, callback, actionCaption).setVisible(true);
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
index 4debfc90..daa63d9a 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java
@@ -5,7 +5,6 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
-import java.awt.GridBagLayout;
import javax.swing.BorderFactory;
import javax.swing.Box;
@@ -28,7 +27,7 @@ import org.openslx.bwlp.thrift.iface.OperatingSystem;
import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.dozmod.gui.control.PersonLabel;
import org.openslx.dozmod.gui.control.table.ImageVersionTable;
-import org.openslx.dozmod.gui.helper.GridPos;
+import org.openslx.dozmod.gui.helper.GridManager;
@SuppressWarnings("serial")
public abstract class ImageDetailsWindowLayout extends JDialog {
@@ -37,6 +36,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
protected final JTextArea txtDescription;
protected final PersonLabel lblOwner;
+ protected final JButton btnChangeOwner;
protected final JLabel lblCreateTime;
protected final PersonLabel lblUpdater;
protected final JLabel lblUpdateTime;
@@ -63,46 +63,59 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
setResizable(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
- // helper for row index
- int row = 0;
-
// create left panel for info and buttons and right panel for the table and add
// them to split pane
// use panel to put every info related widget in it
// then we will set the panel in BorderLayout.CENTER
JPanel infoPanel = new JPanel();
- infoPanel.setLayout(new GridBagLayout());
+ GridManager grid = new GridManager(infoPanel, 3);
infoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// -- name --
txtTitle = new JTextField();
txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 2));
- infoPanel.add(txtTitle, GridPos.get(0, row++, 2, 1, true, false));
+ grid.add(txtTitle, 3).expand(true, false).fill(true, false);
+ grid.nextRow();
// description
txtDescription = new JTextArea();
txtDescription.setLineWrap(true);
txtDescription.setWrapStyleWord(true);
txtDescription.setMinimumSize(new Dimension(0, 100));
- infoPanel.add(new JLabel("Beschreibung"), GridPos.get(0, row, false, false));
- infoPanel.add(new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
- JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), GridPos.get(1, row++, true, true));
+ grid.add(new JLabel("Beschreibung"));
+ grid.add(
+ new JScrollPane(txtDescription, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
+ JScrollPane.HORIZONTAL_SCROLLBAR_NEVER), 2)
+ .expand(true, true)
+ .fill(true, true);
+ grid.nextRow();
+
// owner
lblOwner = new PersonLabel();
- infoPanel.add(new JLabel("Besitzer"), GridPos.get(0, row, false, false));
- infoPanel.add(lblOwner, GridPos.get(1, row++, false, false));
+ btnChangeOwner = new JButton("Ändern");
+ grid.add(new JLabel("Besitzer"));
+ grid.add(lblOwner).expand(true, false);
+ grid.add(btnChangeOwner);
+ grid.nextRow();
+
// creation time
lblCreateTime = new JLabel();
- infoPanel.add(new JLabel("Erstellt"), GridPos.get(0, row, false, false));
- infoPanel.add(lblCreateTime, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Erstellt"));
+ grid.add(lblCreateTime, 2);
+ grid.nextRow();
+
// last updater
lblUpdater = new PersonLabel();
- infoPanel.add(new JLabel("Geändert durch"), GridPos.get(0, row, false, false));
- infoPanel.add(lblUpdater, GridPos.get(1, row++, false, false));
+ grid.add(new JLabel("Geändert durch"));
+ grid.add(lblUpdater, 2);
+ grid.nextRow();
+
// last updated
lblUpdateTime = new JLabel();
- infoPanel.add(new JLabel("Änderungszeitpunkt"), GridPos.get(0, row, false, false));
- infoPanel.add(lblUpdateTime, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Änderungszeitpunkt"));
+ grid.add(lblUpdateTime, 2);
+ grid.nextRow();
+
// os
cboOperatingSystem = new JComboBox<>();
cboOperatingSystem.setEditable(false);
@@ -111,55 +124,70 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
public Component getListCellRendererComponent(JList<?> list, Object value, int index,
boolean isSelected, boolean cellHasFocus) {
if (value instanceof OperatingSystem) {
- OperatingSystem org = (OperatingSystem) value;
- setText(org.getOsName());
+ value = ((OperatingSystem) value).getOsName();
}
- return this;
+ return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
- infoPanel.add(new JLabel("Betriebssystem"), GridPos.get(0, row, false, false));
- infoPanel.add(cboOperatingSystem, GridPos.get(1, row++, true, false));
+
+ grid.add(new JLabel("Betriebssystem"));
+ grid.add(cboOperatingSystem, 2).expand(true, false).fill(true, false);
+ grid.nextRow();
+
// virtualizer
lblVirtualizer = new JLabel();
- infoPanel.add(new JLabel("Virtualizer"), GridPos.get(0, row, false, false));
- infoPanel.add(lblVirtualizer, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Virtualisierer"));
+ grid.add(lblVirtualizer, 2);
+ grid.nextRow();
+
// tags
txtTags = new JTextField();
- infoPanel.add(new JLabel("Tags"), GridPos.get(0, row, false, false));
- infoPanel.add(txtTags, GridPos.get(1, row++, true, false));
+ /* TODO
+ grid.add(new JLabel("Tags"), GridPos.get(0, row, false, false));
+ grid.add(txtTags, GridPos.get(1, row++, true, false));
+ grid.nextRow();
+ */
+
// share mode
- cboShareMode = new JComboBox<ShareMode>();
- infoPanel.add(new JLabel("Freigabemodus"), GridPos.get(0, row, false, false));
- infoPanel.add(cboShareMode, GridPos.get(1, row++, true, false));
+ cboShareMode = new JComboBox<>();
+ grid.add(new JLabel("Freigabemodus"));
+ grid.add(cboShareMode, 2).expand(true, false).fill(true, false);
+ grid.nextRow();
+
// template
- btnIsTemplate = new JCheckBox();
- infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, row, false, false));
- infoPanel.add(btnIsTemplate, GridPos.get(1, row++, true, false));
+ btnIsTemplate = new JCheckBox("Vorlage");
+ grid.add(Box.createGlue());
+ grid.add(btnIsTemplate, 2);
+ grid.nextRow();
+
// version
txtVersion = new JTextField();
- infoPanel.add(new JLabel("Version"), GridPos.get(0, row, false, false));
- infoPanel.add(txtVersion, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Versions-UUID"));
+ grid.add(txtVersion, 2).expand(true, false).fill(true, false);
+ grid.nextRow();
+
// id
txtId = new JTextField();
txtId.setEditable(false);
- infoPanel.add(new JLabel("ID"), GridPos.get(0, row, false, false));
- infoPanel.add(txtId, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Image-UUID"));
+ grid.add(txtId, 2).expand(true, false).fill(true, false);
+ grid.nextRow();
+
+ grid.finish(true);
+
infoPanel.setPreferredSize(new Dimension(500, 400));
+ infoPanel.setMinimumSize(new Dimension(350, 300));
// finally add the infoPanel itself to the left panel
- JPanel leftPanel = new JPanel();
- leftPanel.setLayout(new BorderLayout());
- leftPanel.add(infoPanel, BorderLayout.CENTER);
// button panel at the bottom
JPanel buttonPanel = new JPanel();
buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
- buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
+ buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
btnSaveChanges = new JButton("Speichern");
btnClose = new JButton("Schließen");
buttonPanel.add(btnSaveChanges);
buttonPanel.add(Box.createGlue());
buttonPanel.add(btnClose);
- leftPanel.add(buttonPanel, BorderLayout.PAGE_END);
// --- Version table on the right (EAST) side
JPanel versionTablePanel = new JPanel();
@@ -180,9 +208,10 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
rightPanel.add(versionTablePanel, BorderLayout.CENTER);
// add left and right panel to the split pane
- JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, leftPanel, rightPanel);
- splitPane.setOpaque(false);
+ JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, infoPanel, rightPanel);
+ splitPane.setResizeWeight(0.5);
// add the split pane
- add(splitPane);
+ add(splitPane, BorderLayout.CENTER);
+ add(buttonPanel, BorderLayout.PAGE_END);
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java
index c3c5e228..626b8180 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java
@@ -34,10 +34,6 @@ public class UserListWindowLayout extends JDialog {
private static final Logger LOGGER = Logger.getLogger(UserListWindowLayout.class);
- public interface UserAddedCallback {
- void userAdded(final UserInfo user);
- }
-
protected final UserTable userTable;
protected final JButton setButton;
@@ -46,12 +42,12 @@ public class UserListWindowLayout extends JDialog {
private static String title = "Benutzerliste";
- protected UserListWindowLayout(Frame modalParent) {
+ protected UserListWindowLayout(Frame modalParent, String actionCaption) {
super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL
: ModalityType.MODELESS);
cancelButton = new JButton("Schließen");
- setButton = new JButton("Hinzufügen");
+ setButton = new JButton(actionCaption);
userTable = new UserTable();
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java
index 106a7299..852710e6 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java
@@ -4,7 +4,6 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.Iterator;
import javax.swing.JOptionPane;
@@ -13,7 +12,7 @@ import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.control.table.ImagePermissionTable.UserImagePermissions;
import org.openslx.dozmod.gui.window.UserListWindow;
-import org.openslx.dozmod.gui.window.layout.UserListWindowLayout.UserAddedCallback;
+import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ImageCustomPermissionPageLayout;
import org.openslx.dozmod.state.UploadWizardState;
@@ -46,14 +45,11 @@ public class ImageCustomPermissionPage extends ImageCustomPermissionPageLayout {
// TODO again: which frame to giev? JOptionPane.getFrameForComponent(me) sounds cool at least :)
UserListWindow.open(JOptionPane.getFrameForComponent(me), new UserAddedCallback() {
@Override
- public void userAdded(final UserInfo newUser) {
+ public void userAdded(final UserInfo newUser, UserListWindow window) {
- // looks if we have this user already
- Iterator<UserImagePermissions> it = permissionList.iterator();
- while (it.hasNext()) {
- UserImagePermissions current = it.next();
- if (current.userId == newUser.userId) {
- // user already in the list, skip it
+ // check if we have this user already
+ for (UserImagePermissions current : permissionList) {
+ if (current.userId.equals(newUser.userId)) {
LOGGER.debug("User already present in the list, skipping!");
return;
}
@@ -69,7 +65,7 @@ public class ImageCustomPermissionPage extends ImageCustomPermissionPageLayout {
LOGGER.debug("User added: " + newUser);
permissionTable.setData(permissionList, false);
}
- });
+ }, "Hinzufügen");
}
});
// delete user button adapter
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
index 94bd8f72..f19563c2 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/LectureCustomPermissionPage.java
@@ -3,22 +3,18 @@ package org.openslx.dozmod.gui.wizard.page;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
-import java.util.Iterator;
import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
-import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.UserInfo;
-import org.openslx.dozmod.gui.control.table.ImagePermissionTable.UserImagePermissions;
import org.openslx.dozmod.gui.control.table.LecturePermissionTable.UserLecturePermissions;
import org.openslx.dozmod.gui.window.UserListWindow;
-import org.openslx.dozmod.gui.window.layout.UserListWindowLayout.UserAddedCallback;
+import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.LectureCustomPermissionPageLayout;
import org.openslx.dozmod.state.LectureWizardState;
-import org.openslx.dozmod.state.UploadWizardState;
@SuppressWarnings("serial")
public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayout {
@@ -30,6 +26,7 @@ public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayo
private final LectureCustomPermissionPage me = this;
private ArrayList<UserLecturePermissions> permissionList = new ArrayList<>();
+
/**
* Page for setting custom permissions of a lecture
*/
@@ -43,24 +40,23 @@ public class LectureCustomPermissionPage extends LectureCustomPermissionPageLayo
// TODO again: which frame to giev? JOptionPane.getFrameForComponent(me) sounds cool at least :)
UserListWindow.open(JOptionPane.getFrameForComponent(me), new UserAddedCallback() {
@Override
- public void userAdded(final UserInfo newUser) {
+ public void userAdded(final UserInfo newUser, UserListWindow window) {
- // looks if we have this user already
- Iterator<UserLecturePermissions> it = permissionList.iterator();
- while (it.hasNext()) {
- UserLecturePermissions current = it.next();
- if (current.userId == newUser.userId) {
+ // check if we have this user already
+ for (UserLecturePermissions current : permissionList) {
+ if (current.userId.equals(newUser.userId)) {
// user already in the list, skip it
LOGGER.debug("User already present in the list, skipping!");
return;
}
}
// add it to the list with either default permissions if set, or none
- permissionList.add(new UserLecturePermissions(newUser.userId, new LecturePermissions(true, false)));
+ permissionList.add(new UserLecturePermissions(newUser.userId, new LecturePermissions(
+ true, false)));
LOGGER.debug("User added: " + newUser);
permissionTableViewer.setData(permissionList, false);
}
- });
+ }, "Hinzufügen");
}
});
// delete user button adapter
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/ImagePerms.java b/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/ImagePerms.java
index e53abbc8..198de7cd 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/ImagePerms.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/ImagePerms.java
@@ -2,8 +2,6 @@ package org.openslx.dozmod.permissions;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
-import org.openslx.bwlp.thrift.iface.ImagePermissions;
-import org.openslx.dozmod.thrift.Session;
/**
* Class for checking, whether user can edit given image
@@ -12,21 +10,12 @@ public class ImagePerms {
private final static Logger LOGGER = Logger.getLogger(ImagePerms.class);
- public static boolean canEdit(final ImageDetailsRead image){
- // check if we are the owner of the image
- if(image.getOwnerId().equals(Session.getUserId()))
- return true;
- // we are not, lets see which permissions we have
- ImagePermissions perms = image.getUserPermissions();
- if(perms != null) {
- LOGGER.debug("You can: " + perms);
- } else {
- // no user specific permissions, check defaults
- perms = image.getDefaultPermissions();
- if (perms != null) {
- LOGGER.debug("Everybody can: " + perms);
- }
- }
- return perms != null && (perms.admin || perms.edit);
+ public static boolean canEdit(final ImageDetailsRead image) {
+ return image != null && image.userPermissions != null
+ && (image.userPermissions.admin || image.userPermissions.edit);
+ }
+
+ public static boolean canAdmin(ImageDetailsRead image) {
+ return image != null && image.userPermissions != null && image.userPermissions.admin;
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java
index 0ff7cf76..2f5059b5 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/Session.java
@@ -5,7 +5,6 @@ import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImagePermissions;
import org.openslx.bwlp.thrift.iface.LecturePermissions;
import org.openslx.bwlp.thrift.iface.SatelliteConfig;
-import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.bwlp.thrift.iface.WhoamiInfo;
import org.openslx.thrifthelper.ThriftManager;
@@ -13,15 +12,7 @@ public class Session {
private static final Logger LOGGER = Logger.getLogger(Session.class);
- private static String firstName = null;
-
- private static String lastName = null;
-
- private static String eMail = null;
-
- private static String userId = null;
-
- private static String organizationId = null;
+ private static WhoamiInfo data = null;
private static String satelliteToken = null;
@@ -30,16 +21,15 @@ public class Session {
private static String satelliteAddress = null;
public static void initialize(WhoamiInfo whoami, String satAddress, String satToken, String masToken) {
- UserInfo ui = whoami.getUser();
- if (userId != null && !userId.equals(ui.userId))
+ if (whoami == null || whoami.user == null || whoami.user.userId == null) {
+ throw new IllegalArgumentException(
+ "Cannot initialize session: whoami-Information from satellite incomplete");
+ }
+ if (data != null && !data.user.userId.equals(whoami.user.userId))
throw new IllegalArgumentException("Cannot set new session data with different user id");
if (satelliteAddress != null && !satelliteAddress.equals(satAddress))
throw new IllegalArgumentException("Cannot set new session data with different satellite address");
- firstName = ui.firstName;
- lastName = ui.lastName;
- eMail = ui.eMail;
- userId = ui.userId;
- organizationId = ui.organizationId;
+ data = whoami;
masterToken = masToken;
satelliteToken = satToken;
satelliteAddress = satAddress;
@@ -49,35 +39,65 @@ public class Session {
* @return the first name
*/
public static String getFirstName() {
- return firstName;
+ if (data == null)
+ return null;
+ return data.user.firstName;
}
/**
* @return the last name
*/
public static String getLastName() {
- return lastName;
+ if (data == null)
+ return null;
+ return data.user.lastName;
}
/**
* @return the eMail
*/
public static String getEMail() {
- return eMail;
+ if (data == null)
+ return null;
+ return data.user.eMail;
}
/**
* @return the user id
*/
public static String getUserId() {
- return userId;
+ if (data == null)
+ return null;
+ return data.user.userId;
}
/**
* @return the organization id
*/
public static String getOrganizationId() {
- return organizationId;
+ if (data == null)
+ return null;
+ return data.user.organizationId;
+ }
+
+ /**
+ * @return whether user is superuser (has all permissions on everything, can
+ * declare an image a template)
+ */
+ public static boolean isSuperUser() {
+ if (data == null)
+ return false;
+ return data.isSuperUser;
+ }
+
+ /**
+ * @return whether user can see list of images. students will only be able
+ * to list lectures
+ */
+ public static boolean canListImages() {
+ if (data == null)
+ return false;
+ return data.canListImages;
}
/**
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java
new file mode 100644
index 00000000..fcee1448
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/thrift/ThriftError.java
@@ -0,0 +1,62 @@
+package org.openslx.dozmod.thrift;
+
+import java.awt.Component;
+
+import org.apache.log4j.Logger;
+import org.apache.thrift.TException;
+import org.openslx.bwlp.thrift.iface.AuthorizationError;
+import org.openslx.bwlp.thrift.iface.TAuthorizationException;
+import org.openslx.bwlp.thrift.iface.TInternalServerError;
+import org.openslx.bwlp.thrift.iface.TNotFoundException;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.helper.MessageType;
+
+public class ThriftError {
+
+ public static void showMessage(Component parent, Logger logger, TException ex, String messageText) {
+ if (ex instanceof TNotFoundException) {
+ messageText += "\n\nNicht gefunden";
+ } else if (ex instanceof TAuthorizationException) {
+ String reason = getString(((TAuthorizationException) ex).getNumber());
+ messageText += "\n\nZugriff verweigert: " + reason + "\n" + ex.getMessage();
+ } else if (ex instanceof TInternalServerError) {
+ messageText += "\n\nEin serverseitiger Fehler ist aufgetreten. Bitte kontaktieren Sie den lokalen Support.";
+ } else {
+ messageText += "\n\nUnerwartete Ausnahme " + ex.getClass().getSimpleName() + " ist aufgetreten.";
+ }
+ logger.warn("A thrift call raised an exception", ex);
+ Gui.showMessageBox(parent, messageText, MessageType.ERROR, null, null);
+ }
+
+ public static String getString(AuthorizationError error) {
+ if (error == null)
+ return "(AuthorizationError=null)";
+ switch (error) {
+ case ACCOUNT_SUSPENDED:
+ return "Das Benutzerkonto ist gesperrt";
+ case BANNED_NETWORK:
+ return "Das Netzwerk, aus dem Sie operieren, ist gesperrt";
+ case CHALLENGE_FAILED:
+ return "Challenge fehlgeschlagen";
+ case GENERIC_ERROR:
+ return "Generischer Fehler";
+ case INVALID_CREDENTIALS:
+ return "Ungültige Zugangsdaten";
+ case INVALID_KEY:
+ return "Ungültiger Schlüssel";
+ case INVALID_ORGANIZATION:
+ return "Ungültige oder unbekannte Organisation";
+ case INVALID_TOKEN:
+ return "Ungültiges Sitzungstoken";
+ case NOT_AUTHENTICATED:
+ return "Nicht authentifiziert";
+ case NO_PERMISSION:
+ return "Keine ausreichenden Berechtigungen";
+ case ORGANIZATION_SUSPENDED:
+ return "Ihre zugehörige Organisation ist gesperrt";
+ default:
+ return "Unbekannter Fehlercode: " + error.toString();
+ }
+ }
+
+}