summaryrefslogtreecommitdiffstats
path: root/dozentenmodul
diff options
context:
space:
mode:
authorSimon Rettberg2015-07-31 18:10:15 +0200
committerSimon Rettberg2015-07-31 18:10:15 +0200
commita0c4a9c2c971a098550225a0401ae1838a0869d0 (patch)
tree1a04c19fc1c7957dbafd047106c8eb5e79752c10 /dozentenmodul
parent[client] Mostly finished Wizard implementation (diff)
parent[client] ImageDetailsWindow pretty much done (diff)
downloadtutor-module-a0c4a9c2c971a098550225a0401ae1838a0869d0.tar.gz
tutor-module-a0c4a9c2c971a098550225a0401ae1838a0869d0.tar.xz
tutor-module-a0c4a9c2c971a098550225a0401ae1838a0869d0.zip
Merge branch 'v1.1' of git.openslx.org:openslx-ng/tutor-module into v1.1
Conflicts: dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
Diffstat (limited to 'dozentenmodul')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java5
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java42
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageDetailsWindow.java85
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java8
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageDetailsWindowLayout.java115
5 files changed, 151 insertions, 104 deletions
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
index 8987f673..2279d3c1 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/MainWindow.java
@@ -259,9 +259,4 @@ public abstract class MainWindow {
});
}
- // hack TODO what to giev to a popup when we aren't in this class?
- public static JFrame getMainWin() {
- return mainWindow;
- }
-
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java
index 02f9a181..8b5b9da5 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/PersonLabel.java
@@ -1,12 +1,13 @@
package org.openslx.dozmod.gui.control;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Label;
+import java.awt.Color;
+import java.awt.SystemColor;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+
+import javax.swing.JLabel;
+
import org.openslx.bwlp.thrift.iface.UserInfo;
-import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.helper.SwtUtil;
import org.openslx.dozmod.util.FormatHelper;
@@ -14,21 +15,21 @@ import org.openslx.dozmod.util.FormatHelper;
* A label for displaying a {@link UserInfo} object. Supports a callback event
* for when the users clicks the label.
*/
-public class PersonLabel {
-
- private final Label label;
+public class PersonLabel extends JLabel {
private UserInfo user = null;
private PersonLabelClickEvent callback = null;
- public PersonLabel(Composite parent, int style) {
- label = new Label(parent, style);
- label.setForeground(Gui.display.getSystemColor(SWT.COLOR_LINK_FOREGROUND));
- label.addMouseListener(new MouseAdapter() {
+ public PersonLabel() {
+ // could not find a way to query the system-wide color for hyperlinks :(
+ setForeground(Color.BLUE.darker());
+ addMouseListener(new MouseAdapter() {
@Override
- public void mouseUp(MouseEvent e) {
- if (user != null && callback != null && e.button == 1 && label.getBounds().contains(e.x, e.y)) {
+ public void mouseClicked(MouseEvent e) {
+ if (user != null && callback != null
+ && e.getButton() == MouseEvent.BUTTON1
+ && getBounds().contains(e.getX(), e.getY())) {
callback.clicked(user);
}
}
@@ -46,21 +47,14 @@ public class PersonLabel {
}
/**
- * Set layout data of this label.
- */
- public void setLayoutData(Object layoutData) {
- label.setLayoutData(layoutData);
- }
-
- /**
* Set the user to display.
*/
public void setUser(UserInfo user) {
this.user = user;
if (user == null) {
- label.setText("");
+ setText("");
} else {
- label.setText(SwtUtil.replaceMnemonics(FormatHelper.userName(user)));
+ setText(SwtUtil.replaceMnemonics(FormatHelper.userName(user)));
}
}
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 8238f2a0..22d5f402 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
@@ -1,14 +1,16 @@
package org.openslx.dozmod.gui.window;
import java.awt.Frame;
-import java.util.List;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
import org.apache.log4j.Logger;
import org.openslx.bwlp.thrift.iface.ImageDetailsRead;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
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.SwtUtil;
import org.openslx.dozmod.gui.window.layout.ImageDetailsWindowLayout;
@@ -21,6 +23,7 @@ import org.openslx.thrifthelper.ThriftManager;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+@SuppressWarnings("serial")
public class ImageDetailsWindow extends ImageDetailsWindowLayout {
private static final Logger LOGGER = Logger.getLogger(ImageDetailsWindow.class);
@@ -31,17 +34,32 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout {
public ImageDetailsWindow(Frame modalParent) {
super(modalParent);
+ setVisible(false);
+ setFocusable(true);
+ // Close button closes window
+ btnClose.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ dispose();
+ }
+ });
+ // ESC closes this window
+ addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ LOGGER.debug("he");
+ if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
+ dispose();
+ }
+ }
+ });
-// // Close button closes window
-// btnClose.addSelectionListener(new SelectionAdapter() {
-// @Override
-// public void widgetSelected(SelectionEvent e) {
-// getShell().dispose();
-// }
-// });
}
-
+ /**
+ * @param imageBaseId the id of the image to be displayed
+ */
public void setImage(final String imageBaseId) {
+
QuickTimer.scheduleOnce(new Task() {
@Override
public void fire() {
@@ -76,47 +94,66 @@ public class ImageDetailsWindow extends ImageDetailsWindowLayout {
});
}
+ /**
+ * callback function when we received the image's details from the server
+ */
private void fill() {
if (image == null)
return;
txtTitle.setText(SwtUtil.replaceMnemonics(image.getImageName()));
txtDescription.setText(SwtUtil.replaceMnemonics(image.getDescription()));
- lblOwner.setText(FormatHelper.userName(UserCache.find(image.getOwnerId())));
- lblUpdater.setText(FormatHelper.userName(UserCache.find(image.getUpdaterId())));
+ lblOwner.setUser(UserCache.find(image.getOwnerId()));
+ lblUpdater.setUser(UserCache.find(image.getUpdaterId()));
lblCreateTime.setText(FormatHelper.longDate(image.getCreateTime()));
lblUpdateTime.setText(FormatHelper.longDate(image.getUpdateTime()));
- List<OperatingSystem> osList = MetaDataCache.getOperatingSystems();
-// cboOperatingSystem.setInput(osList);
+
+ for (OperatingSystem os : MetaDataCache.getOperatingSystems()) {
+ cboOperatingSystem.addItem(os);
+ }
OperatingSystem os = MetaDataCache.getOsById(image.getOsId());
if (os != null) {
-// cboOperatingSystem.setSelection(new StructuredSelection(os), true);
+ cboOperatingSystem.setSelectedItem(os);
}
+
Virtualizer virt = MetaDataCache.getVirtualizerById(image.getVirtId());
if (virt != null)
lblVirtualizer.setText(virt.getVirtName());
+
String tagsString = "";
for (String tag : image.getTags()) {
tagsString = tagsString + ", " + tag;
}
txtTags.setText(tagsString);
-// btnIsTemplate.setSelection(image.isTemplate);
+ btnIsTemplate.setSelected(image.isTemplate);
makeEditable(ImagePerms.canEdit(image));
-// getShell().layout(true, true);
-// MainWindow.centerShell(getShell());
+ pack();
+ Gui.centerShell(this);
+ setVisible(true);
}
-
- // make text fields editable if allowed
+ /**
+ * Enables/disables the editable fields based on 'editable'
+ *
+ * @param editable true to make fields editable, false otherwise.
+ */
private void makeEditable(boolean editable){
txtTitle.setEnabled(editable);
txtDescription.setEnabled(editable);
-// cboOperatingSystem.getCombo().setEnabled(editable);
txtTags.setEnabled(editable);
btnIsTemplate.setEnabled(editable);
+ // TODO fix combobox enabling stuff
}
- public static void open(Frame modalParent) {
+
+ /**
+ * 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
+ */
+ public static void open(Frame modalParent, String imageBaseId) {
ImageDetailsWindow win = new ImageDetailsWindow(modalParent);
- MainWindow.centerShell(win);
- win.setVisible(true);
+ Gui.centerShell(win);
+ win.setImage(imageBaseId);
}
}
diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
index 87923761..241c3172 100644
--- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/ImageListWindow.java
@@ -6,6 +6,7 @@ import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
+import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.event.DocumentEvent;
@@ -26,6 +27,7 @@ import org.openslx.dozmod.util.FormatHelper;
import org.openslx.util.QuickTimer;
import org.openslx.util.QuickTimer.Task;
+@SuppressWarnings("serial")
public class ImageListWindow extends ImageListWindowLayout {
private final static Logger LOGGER = Logger.getLogger(ImageListWindow.class);
@@ -98,8 +100,10 @@ public class ImageListWindow extends ImageListWindowLayout {
@Override
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
- // TODO open details popup
- ImageDetailsWindow.open(MainWindow.getMainWin());
+ ImageSummaryRead image = imageTable.getSelectedItem();
+ if (image == null)
+ return;
+ ImageDetailsWindow.open((JFrame)SwingUtilities.getWindowAncestor(me), image.getImageBaseId());
}
}
});
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 1d41a739..abc5d9a8 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
@@ -1,17 +1,24 @@
package org.openslx.dozmod.gui.window.layout;
import java.awt.BorderLayout;
+import java.awt.Component;
import java.awt.Font;
import java.awt.Frame;
+import java.awt.GridBagLayout;
+import javax.swing.BorderFactory;
+import javax.swing.Box;
import javax.swing.BoxLayout;
+import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
+import javax.swing.JList;
import javax.swing.JPanel;
+import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.openslx.bwlp.thrift.iface.OperatingSystem;
@@ -19,14 +26,15 @@ import org.openslx.bwlp.thrift.iface.ShareMode;
import org.openslx.dozmod.gui.control.PersonLabel;
import org.openslx.dozmod.gui.helper.GridPos;
+@SuppressWarnings("serial")
public abstract class ImageDetailsWindowLayout extends JDialog {
- protected final JTextField txtTitle;
- protected final JTextField txtDescription;
+ protected final JLabel txtTitle;
+ protected final JTextArea txtDescription;
- protected final JLabel lblOwner;
+ protected final PersonLabel lblOwner;
protected final JLabel lblCreateTime;
- protected final JLabel lblUpdater;
+ protected final PersonLabel lblUpdater;
protected final JLabel lblUpdateTime;
protected final JComboBox<OperatingSystem> cboOperatingSystem;
@@ -41,75 +49,84 @@ public abstract class ImageDetailsWindowLayout extends JDialog {
public ImageDetailsWindowLayout(Frame modalParent) {
super(modalParent, "der mit dem blub", ModalityType.APPLICATION_MODAL);
- setResizable(false);
+ setResizable(true);
setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
setLayout(new BorderLayout());
-
- // label panel on the west side of the borderlayout
- JPanel labelPanel = new JPanel();
- labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.PAGE_AXIS));
- labelPanel.add(new JLabel("Name"));
- labelPanel.add(new JLabel("Beschreibung"));
- labelPanel.add(new JLabel("Besitzer"));
- labelPanel.add(new JLabel("Erstellt"));
- labelPanel.add(new JLabel("Geändert durch"));
- labelPanel.add(new JLabel("Änderungszeitpunkt"));
- labelPanel.add(new JLabel("Betriebssystem"));
- labelPanel.add(new JLabel("Virtualizer"));
- labelPanel.add(new JLabel("Tags"));
- labelPanel.add(new JLabel("Freigabemodus"));
- labelPanel.add(new JLabel("Vorlage"));
- add(labelPanel, BorderLayout.WEST);
-
- // content panel on the center of the borderlayout (to auto grab space)
- JPanel contentPanel = new JPanel();
- contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));
- // name
- txtTitle = new JTextField();
+
+ // 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));
+ // -- name --
+ txtTitle = new JLabel();
txtTitle.setFont(txtTitle.getFont().deriveFont(Font.BOLD, txtTitle.getFont().getSize2D() * 2));
- contentPanel.add(txtTitle);
+ infoPanel.add(txtTitle, GridPos.get(0, 0, 2, 1, true, false));
+
// description
- txtDescription = new JTextField();
- contentPanel.add(txtDescription);
+ txtDescription = new JTextArea();
+ infoPanel.add(new JLabel("Beschreibung"), GridPos.get(0, 1, false, false));
+ infoPanel.add(txtDescription, GridPos.get(1, 1, true, false));
+
// owner
- lblOwner = new JLabel();
- contentPanel.add(lblOwner);
+ lblOwner = new PersonLabel();
+ infoPanel.add(new JLabel("Besitzer"), GridPos.get(0, 2, false, false));
+ infoPanel.add(lblOwner, GridPos.get(1, 2, true, false));
// creation time
lblCreateTime = new JLabel();
- contentPanel.add(lblCreateTime);
+ infoPanel.add(new JLabel("Erstellt"), GridPos.get(0, 3, false, false));
+ infoPanel.add(lblCreateTime, GridPos.get(1, 3, true, false));
// last updater
- lblUpdater = new JLabel();
- contentPanel.add(lblUpdater);
+ lblUpdater = new PersonLabel();
+ infoPanel.add(new JLabel("Geändert durch"), GridPos.get(0, 4, false, false));
+ infoPanel.add(lblUpdater, GridPos.get(1, 4, true, false));
// last updated
lblUpdateTime = new JLabel();
- contentPanel.add(lblUpdateTime);
+ infoPanel.add(new JLabel("Änderungszeitpunkt"), GridPos.get(0, 5, false, false));
+ infoPanel.add(lblUpdateTime, GridPos.get(1, 5, true, false));
// os
- cboOperatingSystem = new JComboBox<OperatingSystem>();
- contentPanel.add(cboOperatingSystem);
+ cboOperatingSystem = new JComboBox<>();
+ cboOperatingSystem.setEditable(false);
+ cboOperatingSystem.setRenderer(new DefaultListCellRenderer() {
+ @Override
+ public Component getListCellRendererComponent(JList<?> list, Object value, int index,
+ boolean isSelected, boolean cellHasFocus) {
+ if (value instanceof OperatingSystem) {
+ OperatingSystem org = (OperatingSystem) value;
+ setText(org.getOsName());
+ }
+ return this;
+ }
+ });
+ infoPanel.add(new JLabel("Betriebssystem"), GridPos.get(0, 6, false, false));
+ infoPanel.add(cboOperatingSystem, GridPos.get(1, 6, true, false));
// virtualizer
lblVirtualizer = new JLabel();
- contentPanel.add(lblVirtualizer);
+ infoPanel.add(new JLabel("Virtualizer"), GridPos.get(0, 7, false, false));
+ infoPanel.add(lblVirtualizer, GridPos.get(1, 7, true, false));
// tags
txtTags = new JTextField();
- contentPanel.add(txtTags);
+ infoPanel.add(new JLabel("Tags"), GridPos.get(0, 8, false, false));
+ infoPanel.add(txtTags, GridPos.get(1, 8, true, false));
// share mode
cboShareMode = new JComboBox<ShareMode>();
- contentPanel.add(cboShareMode);
+ infoPanel.add(new JLabel("Freigabemodus"), GridPos.get(0, 9, false, false));
+ infoPanel.add(cboShareMode, GridPos.get(1, 9, true, false));
// template
btnIsTemplate = new JCheckBox();
- contentPanel.add(btnIsTemplate);
- // finally add the content panel to the main frame
- add(contentPanel, BorderLayout.CENTER);
+ infoPanel.add(new JLabel("Vorlage"), GridPos.get(0, 10, false, false));
+ infoPanel.add(btnIsTemplate, GridPos.get(1, 10, true, false));
+ // finally add the infoPanel itself to the main view
+ add(infoPanel, BorderLayout.CENTER);
// button panel on the bottom
JPanel buttonPanel = new JPanel();
- buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.PAGE_AXIS));
- btnSaveChanges = new JButton();
- btnClose = new JButton();
+ buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
+ btnSaveChanges = new JButton("Speichern");
+ btnClose = new JButton("Schließen");
buttonPanel.add(btnSaveChanges);
+ buttonPanel.add(Box.createGlue());
buttonPanel.add(btnClose);
add(buttonPanel, BorderLayout.SOUTH);
- validate();
- pack();
}
}