summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main
diff options
context:
space:
mode:
authorSimon Rettberg2015-08-14 17:36:06 +0200
committerSimon Rettberg2015-08-14 17:36:06 +0200
commit4908138a474579b263222be3644184f6c135fdbe (patch)
tree919ece302f4de9b9a676cd3b682cc6f2cd199f7f /dozentenmodul/src/main
parent[client] Support Ctrl-W shortcut (diff)
downloadtutor-module-4908138a474579b263222be3644184f6c135fdbe.tar.gz
tutor-module-4908138a474579b263222be3644184f6c135fdbe.tar.xz
tutor-module-4908138a474579b263222be3644184f6c135fdbe.zip
[client] Use GridManager in lecture details window
Diffstat (limited to 'dozentenmodul/src/main')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/GridManager.java38
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java49
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java6
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java122
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/permissions/LecturePerms.java4
6 files changed, 168 insertions, 59 deletions
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 766ab94c..0bf36c3a 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
@@ -157,6 +157,32 @@ public class GridManager {
}
/**
+ * Convenience method for adding an empty placeholder in the current cell.
+ */
+ public GBC skip() {
+ return add(Box.createGlue());
+ }
+
+ /**
+ * Convenience method for adding an empty placeholder in the current cell.
+ *
+ * @param spanX horizontal span
+ */
+ public GBC skip(int spanX) {
+ return add(Box.createGlue(), spanX);
+ }
+
+ /**
+ * Convenience method for adding an empty placeholder in the current cell.
+ *
+ * @param spanX horizontal span
+ * @param spanY vertical span
+ */
+ public GBC skip(int spanX, int spanY) {
+ return add(Box.createGlue(), spanX, spanY);
+ }
+
+ /**
* Advance to next row.
*
* @throws IllegalStateException if strict mode is enabled and the current
@@ -334,6 +360,18 @@ public class GridManager {
return this;
}
+ /**
+ * Set the anchor field of this {@link GridBagConstraints} instance.
+ *
+ * @param value
+ * @return
+ */
+ public GBC anchor(int value) {
+ checkValid();
+ this.anchor = value;
+ return this;
+ }
+
// Extend with more helpers as needed
private GBC(Component component, int spanX, int spanY) {
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 57866b98..d2746779 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
@@ -161,7 +161,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
versionTableScrollPane.addMouseListener(ma);
versionTable.addMouseListener(ma);
- btnIsTemplate.setEnabled(Session.isSuperUser());
+ chkIsTemplate.setEnabled(Session.isSuperUser());
makeEditable(false);
}
@@ -264,7 +264,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
tagsString = tagsString + ", " + tag;
}
txtTags.setText(tagsString);
- btnIsTemplate.setSelected(image.isTemplate);
+ chkIsTemplate.setSelected(image.isTemplate);
// set the versions of the image to the table
versionTable.setData(image.getVersions(), true);
@@ -301,7 +301,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
};
cboOperatingSystem.addItemListener(comboItemListener);
cboShareMode.addItemListener(comboItemListener);
- btnIsTemplate.addActionListener(new ActionListener() {
+ chkIsTemplate.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
@@ -370,7 +370,7 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout implements UiFe
changed = true;
} else if (newShareMode != null && !newShareMode.equals(image.shareMode)) {
changed = true;
- } else if (btnIsTemplate.isSelected() != image.isTemplate) {
+ } else if (chkIsTemplate.isSelected() != image.isTemplate) {
changed = true;
}
// TODO TAGS
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
index d901881f..400d7018 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/LectureDetailsWindow.java
@@ -10,14 +10,18 @@ import java.util.Date;
import java.util.List;
import javax.swing.DefaultComboBoxModel;
+import javax.swing.JOptionPane;
import org.apache.log4j.Logger;
import org.apache.thrift.TException;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.bwlp.thrift.iface.LectureRead;
+import org.openslx.bwlp.thrift.iface.UserInfo;
import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.MainWindow;
+import org.openslx.dozmod.gui.helper.MessageType;
+import org.openslx.dozmod.gui.window.UserListWindow.UserAddedCallback;
import org.openslx.dozmod.gui.window.layout.LectureDetailsWindowLayout;
import org.openslx.dozmod.permissions.LecturePerms;
import org.openslx.dozmod.thrift.Session;
@@ -56,6 +60,22 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout {
cboVersions.setEnabled(!btnAutoUpdate.isSelected());
}
});
+
+ 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();
+ setLectureOwner(user);
+ }
+
+ }, "Besitzer festlegen");
+ }
+ });
+ makeEditable(false);
}
/**
@@ -147,21 +167,45 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout {
endCal.get(Calendar.DATE));
endTime.getModel().setValue(endCal.getTime());
- makeEditable(LecturePerms.canEdit(lecture));
+ makeEditable(true);
pack();
MainWindow.centerShell(this);
setVisible(true);
}
+ private void setLectureOwner(final UserInfo user) {
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ try {
+ ThriftManager.getSatClient().setLectureOwner(Session.getSatelliteToken(),
+ lecture.getLectureId(), 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 lectureId = lecture.getLectureId();
+ synchronized (me) {
+ image = null;
+ lecture = null;
+ }
+ setLecture(lectureId);
+ }
+ });
+ }
+
/**
* Enables/disables the editable fields based on 'editable'
*
* @param editable true to make fields editable, false otherwise.
*/
private void makeEditable(boolean editable) {
+ editable = editable && LecturePerms.canEdit(lecture);
txtTitle.setEnabled(editable);
txtDescription.setEditable(editable);
- txtId.setEditable(editable);
// TODO functionality for changing dates still missing
// lblCreateTime.setText(FormatHelper.longDate(lecture.getCreateTime()));
@@ -174,6 +218,7 @@ public class LectureDetailsWindow extends LectureDetailsWindowLayout {
btnAutoUpdate.setEnabled(editable);
cboVersions.setEnabled(editable);
btnSaveChanges.setEnabled(editable);
+ btnChangeOwner.setEnabled(editable && LecturePerms.canAdmin(lecture));
}
/**
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 76875c74..5a2b799c 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
@@ -44,7 +44,7 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
protected final JComboBox<OperatingSystem> cboOperatingSystem;
protected final JLabel lblVirtualizer;
protected final JTextField txtTags;
- protected final JCheckBox btnIsTemplate;
+ protected final JCheckBox chkIsTemplate;
protected final JComboBox<ShareMode> cboShareMode;
protected final JTextField txtId;
@@ -153,9 +153,9 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
grid.nextRow();
// template
- btnIsTemplate = new JCheckBox("Vorlage");
+ chkIsTemplate = new JCheckBox("Vorlage");
grid.add(Box.createGlue());
- grid.add(btnIsTemplate, 2);
+ grid.add(chkIsTemplate, 2);
grid.nextRow();
// version
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
index ff6be78b..5ee23c01 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/LectureDetailsWindowLayout.java
@@ -4,7 +4,7 @@ import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Frame;
-import java.awt.GridBagLayout;
+import java.awt.GridBagConstraints;
import java.util.Calendar;
import java.util.Date;
import java.util.Properties;
@@ -33,7 +33,7 @@ import org.openslx.bwlp.thrift.iface.ImageVersionDetails;
import org.openslx.dozmod.gui.control.ComboBox;
import org.openslx.dozmod.gui.control.ComboBox.ComboBoxRenderer;
import org.openslx.dozmod.gui.control.PersonLabel;
-import org.openslx.dozmod.gui.helper.GridPos;
+import org.openslx.dozmod.gui.helper.GridManager;
import org.openslx.dozmod.util.DateLabelFormatter;
import org.openslx.dozmod.util.FormatHelper;
import org.openslx.thrifthelper.Comparators;
@@ -46,6 +46,7 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
protected final JLabel txtImageName;
protected final JButton btnLinkImage;
protected final PersonLabel lblOwner;
+ protected final JButton btnChangeOwner;
protected final JLabel lblCreateTime;
protected final PersonLabel lblUpdater;
protected final JLabel lblUpdateTime;
@@ -86,39 +87,36 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
// 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());
infoPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
-
- // helper for row index
- int row = 0;
+ GridManager grid = new GridManager(infoPanel, 3);
// -- name --
txtTitle = new JLabel();
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.setPreferredSize(new Dimension(450, 100));
- infoPanel.add(new JLabel("Beschreibung"), GridPos.get(0, row, false, false));
- infoPanel.add(new JScrollPane(txtDescription), GridPos.get(1, row++, true, true));
+ grid.add(new JLabel("Beschreibung")).anchor(GridBagConstraints.FIRST_LINE_START);
+ grid.add(new JScrollPane(txtDescription), 2).expand(true, true).fill(true, true);
+ grid.nextRow();
+
// linked image
- JPanel linkedImagePanel = new JPanel();
// name
txtImageName = new JLabel();
- infoPanel.add(new JLabel("Imagename"), GridPos.get(0, row, false, false));
- linkedImagePanel.add(txtImageName);
+ grid.add(new JLabel("Imagename"));
+ grid.add(txtImageName).expand(true, false);
// link button for image
- btnLinkImage = new JButton();
- btnLinkImage.setText("Link Image");
- linkedImagePanel.add(btnLinkImage);
- infoPanel.add(linkedImagePanel, GridPos.get(1, row++, false, false));
+ btnLinkImage = new JButton("Ändern");
+ grid.add(btnLinkImage);
+ grid.nextRow();
+
// image version handling
// auto update
btnAutoUpdate = new JCheckBox("Auto Update");
- infoPanel.add(new JLabel("Image Version"), GridPos.get(0, row, false, false));
- JPanel versionPanel = new JPanel();
- versionPanel.add(btnAutoUpdate);
// versions combo
cboVersions = new ComboBox<>(Comparators.imageVersionDetails,
new ComboBoxRenderer<ImageVersionDetails>() {
@@ -129,68 +127,92 @@ public abstract class LectureDetailsWindowLayout extends JDialog {
return FormatHelper.longDate(item.getCreateTime());
}
});
- versionPanel.add(cboVersions);
- infoPanel.add(versionPanel, GridPos.get(1, row++, false, false));
+ grid.add(new JLabel("Image Version"));
+ grid.add(cboVersions).expand(true, false);
+ grid.add(btnAutoUpdate);
+ grid.nextRow();
+
// start time of the lecture
- JPanel startTimePanel = new JPanel();
- startTimePanel.setLayout(new BorderLayout());
+ JPanel startTimePanel = new JPanel(new BorderLayout());
startDate = new JDatePickerImpl(new JDatePanelImpl(new UtilDateModel(new Date()), pickerStrings),
new DateLabelFormatter());
startTime = makeTimeSpinner(23, 59);
startTimePanel.add(startDate, BorderLayout.WEST);
startTimePanel.add(startTime, BorderLayout.CENTER);
lblStartTime = new JLabel();
- infoPanel.add(new JLabel("Startdatum"), GridPos.get(0, row, false, false));
- infoPanel.add(startTimePanel, GridPos.get(1, row++, false, false));
+ grid.add(new JLabel("Startdatum"));
+ grid.add(startTimePanel, 2);
+ grid.nextRow();
// end time of the lecture
- JPanel endTimePanel = new JPanel();
- endTimePanel.setLayout(new BorderLayout());
+ JPanel endTimePanel = new JPanel(new BorderLayout());
endDate = new JDatePickerImpl(new JDatePanelImpl(new UtilDateModel(new Date()), pickerStrings),
new DateLabelFormatter());
endTime = makeTimeSpinner(00, 59);
endTimePanel.add(endDate, BorderLayout.WEST);
endTimePanel.add(endTime, BorderLayout.CENTER);
lblEndTime = new JLabel();
- infoPanel.add(new JLabel("Enddatum"), GridPos.get(0, row, false, false));
- infoPanel.add(endTimePanel, GridPos.get(1, row++, false, false));
+ grid.add(new JLabel("Enddatum"));
+ grid.add(endTimePanel, 2);
+ grid.nextRow();
+
// owner
lblOwner = new PersonLabel();
- infoPanel.add(new JLabel("Besitzer"), GridPos.get(0, row, false, false));
- infoPanel.add(lblOwner, GridPos.get(1, row++, true, 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++, true, 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();
+
// is exam
- btnIsExam = new JCheckBox();
- infoPanel.add(new JLabel("Klausur"), GridPos.get(0, row, false, false));
- infoPanel.add(btnIsExam, GridPos.get(1, row++, true, false));
+ btnIsExam = new JCheckBox("Klausur");
+ grid.skip();
+ grid.add(btnIsExam, 2);
+ grid.nextRow();
+
+ btnHasInternetAccess = new JCheckBox("Internetzugriff");
+ grid.skip();
+ grid.add(btnHasInternetAccess, 2);
+ grid.nextRow();
- btnHasInternetAccess = new JCheckBox();
- infoPanel.add(new JLabel("Internetzugriff"), GridPos.get(0, row, false, false));
- infoPanel.add(btnHasInternetAccess, GridPos.get(1, row++, true, false));
+ btnIsActive = new JCheckBox("Aktiv");
+ grid.skip();
+ grid.add(btnIsActive, 2);
+ grid.nextRow();
- btnIsActive = new JCheckBox();
- infoPanel.add(new JLabel("Aktiv"), GridPos.get(0, row, false, false));
- infoPanel.add(btnIsActive, GridPos.get(1, row++, true, false));
// 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("ID"));
+ grid.add(txtId, 2).expand(true, false).fill(true, false);
+ grid.nextRow();
+
// use count
lblUseCount = new JLabel();
- infoPanel.add(new JLabel("useCount"), GridPos.get(0, row, false, false));
- infoPanel.add(lblUseCount, GridPos.get(1, row++, true, false));
+ grid.add(new JLabel("Aufrufe"));
+ grid.add(lblUseCount, 2);
+ grid.nextRow();
+
+ grid.finish(true);
+
// finally add the infoPanel itself to the main view
add(infoPanel, BorderLayout.CENTER);
// button panel on the bottom
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/LecturePerms.java b/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/LecturePerms.java
index 167a2b65..9f941610 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/LecturePerms.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/permissions/LecturePerms.java
@@ -9,4 +9,8 @@ public class LecturePerms {
public static boolean canEdit(LectureRead lecture) {
return lecture != null && lecture.userPermissions != null && lecture.userPermissions.edit;
}
+
+ public static boolean canAdmin(LectureRead lecture) {
+ return lecture != null && lecture.userPermissions != null && lecture.userPermissions.admin;
+ }
}