diff options
author | Simon Rettberg | 2015-08-13 15:45:10 +0200 |
---|---|---|
committer | Simon Rettberg | 2015-08-13 15:45:10 +0200 |
commit | 9693e1a8484cc7ab05e6d62bad7bfa561d4aa3d7 (patch) | |
tree | fc32e08b30d5643cf1bbd1753ec6f1cc076a8217 /dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java | |
parent | [client] Fix positioning of Wizard (diff) | |
download | tutor-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/openslx/dozmod/gui/window/ImageDetailsWindow.java')
-rw-r--r-- | dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java | 72 |
1 files changed, 61 insertions, 11 deletions
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); |