summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java
diff options
context:
space:
mode:
authorJonathan Bauer2015-08-05 15:59:03 +0200
committerJonathan Bauer2015-08-05 15:59:03 +0200
commit6b6985ee3cfbdb2d93032a078a2986de90362bf3 (patch)
tree915b425e08b0a87332d610e22828b90f1592a528 /dozentenmodul/src/main/java
parent[client] pointed to a small bug in wizard (diff)
downloadtutor-module-6b6985ee3cfbdb2d93032a078a2986de90362bf3.tar.gz
tutor-module-6b6985ee3cfbdb2d93032a078a2986de90362bf3.tar.xz
tutor-module-6b6985ee3cfbdb2d93032a078a2986de90362bf3.zip
[client] first draft at UserListWindow
Used a one-column table since we already have a lot to get from our ListTable. Currently used a double-click control scheme, to be discussed... TODO: filtering users and in general a way to query the existing users without UserCache.getAll()
Diffstat (limited to 'dozentenmodul/src/main/java')
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java26
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java82
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java87
-rw-r--r--dozentenmodul/src/main/java/org/openslx/dozmod/gui/wizard/page/ImageCustomPermissionPage.java64
4 files changed, 238 insertions, 21 deletions
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
new file mode 100644
index 00000000..2dd9122f
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/control/table/UserTable.java
@@ -0,0 +1,26 @@
+package org.openslx.dozmod.gui.control.table;
+
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.util.FormatHelper;
+
+@SuppressWarnings("serial")
+public class UserTable extends ListTable<UserInfo> {
+
+ private static String[] columnNames =
+ { "Name" };
+
+ private static Class<?>[] columnClasses =
+ { String.class };
+
+ public UserTable() {
+ super(columnNames, columnClasses);
+ }
+
+ @Override
+ protected Object getValueAtInternal(int rowIndex, int columnIndex) {
+ UserInfo row = getModelRow(rowIndex);
+ if (columnIndex == 0)
+ return FormatHelper.userName(row);
+ throw new IndexOutOfBoundsException();
+ }
+}
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
new file mode 100644
index 00000000..a6df2332
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/UserListWindow.java
@@ -0,0 +1,82 @@
+package org.openslx.dozmod.gui.window;
+
+import java.awt.Frame;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.window.layout.UserListWindowLayout;
+import org.openslx.dozmod.thrift.UserCache;
+import org.openslx.util.QuickTimer;
+import org.openslx.util.QuickTimer.Task;
+
+@SuppressWarnings("serial")
+public class UserListWindow extends UserListWindowLayout {
+
+ private final static Logger LOGGER = Logger.getLogger(UserListWindow.class);
+
+ public UserListWindow(final Frame modalParent, final UserAddedCallback callback) {
+ super(modalParent);
+
+ addWindowListener(new WindowAdapter() {
+ @Override
+ public void windowOpened(WindowEvent e) {
+ // load the user cache async
+ QuickTimer.scheduleOnce(new Task() {
+ @Override
+ public void fire() {
+ final List<UserInfo> userList = UserCache.getAll();
+ Gui.asyncExec(new Runnable() {
+ @Override
+ public void run() {
+ userTable.setData(userList, true);
+ }
+ });
+ }
+ });
+
+ }
+ });
+
+ // ActionListener for the two buttons
+ final ActionListener al = 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();
+ }
+ }
+ };
+ setButton.setActionCommand("Set");
+ setButton.addActionListener(al);
+ cancelButton.setActionCommand("Cancel");
+ cancelButton.addActionListener(al);
+ getRootPane().setDefaultButton(setButton);
+
+ userTable.addMouseListener(new MouseAdapter() {
+ @Override
+ public void mouseClicked(MouseEvent e) {
+ if (e.getClickCount() == 2) {
+ setButton.doClick();
+ }
+ }
+ });
+ }
+
+ public static void open(Frame modalParent, final UserAddedCallback callback) {
+ new UserListWindow(modalParent, callback).setVisible(true);
+ }
+}
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
new file mode 100644
index 00000000..85dd2545
--- /dev/null
+++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/UserListWindowLayout.java
@@ -0,0 +1,87 @@
+package org.openslx.dozmod.gui.window.layout;
+
+import java.awt.BorderLayout;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Frame;
+import java.awt.GridBagLayout;
+
+import javax.swing.BorderFactory;
+import javax.swing.Box;
+import javax.swing.BoxLayout;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextField;
+
+import org.apache.log4j.Logger;
+import org.openslx.bwlp.thrift.iface.UserInfo;
+import org.openslx.dozmod.gui.Gui;
+import org.openslx.dozmod.gui.control.table.UserTable;
+import org.openslx.dozmod.gui.helper.GridPos;
+
+/**
+ * Credits for the first steps:
+ * https://docs.oracle.com/javase/tutorial/uiswing/examples/components/ListDialogRunnerProject/src/components/ListDialog.java
+ *
+ * Adapted to use our UserInfo class
+ */
+
+@SuppressWarnings("serial")
+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;
+ protected final JButton cancelButton;
+ protected final JTextField filterField;
+
+ private static String title = "Benutzerliste";
+
+ protected UserListWindowLayout(Frame modalParent) {
+ super(modalParent, title, modalParent != null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
+
+ cancelButton = new JButton("Schliessen");
+ setButton = new JButton("Hinzufügen");
+
+ userTable = new UserTable();
+
+ JPanel listPane = new JPanel();
+ listPane.setLayout(new BoxLayout(listPane, BoxLayout.PAGE_AXIS));
+ listPane.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
+ listPane.add(new JScrollPane(userTable));
+
+ // spaced buttons
+ JPanel buttonPane = new JPanel();
+ buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
+ buttonPane.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
+ buttonPane.add(Box.createHorizontalGlue());
+ buttonPane.add(cancelButton);
+ buttonPane.add(Box.createRigidArea(new Dimension(10, 0)));
+ buttonPane.add(setButton);
+
+ // filter stuff
+ JPanel filterPanel = new JPanel(new GridBagLayout());
+ filterField = new JTextField();
+ filterPanel.setBorder(BorderFactory.createEmptyBorder(10,10,0,10));
+ filterPanel.add(new JLabel("Suchen: "), GridPos.get(0, 0, false, false));
+ filterPanel.add(filterField, GridPos.get(1, 0, true, true));
+
+ // pack it all
+ Container contentPane = getContentPane();
+ contentPane.add(filterPanel, BorderLayout.NORTH);
+ contentPane.add(listPane, BorderLayout.CENTER);
+ contentPane.add(buttonPane, BorderLayout.PAGE_END);
+ setPreferredSize(new Dimension(200, 300));
+ pack();
+ Gui.centerShellOverShell(modalParent, this);
+ }
+}
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 f7c7f270..106a7299 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,23 +4,30 @@ 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;
import org.apache.log4j.Logger;
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.wizard.Wizard;
import org.openslx.dozmod.gui.wizard.layout.ImageCustomPermissionPageLayout;
import org.openslx.dozmod.state.UploadWizardState;
-import org.openslx.dozmod.thrift.UserCache;
@SuppressWarnings("serial")
public class ImageCustomPermissionPage extends ImageCustomPermissionPageLayout {
private final static Logger LOGGER = Logger.getLogger(ImageCustomPermissionPage.class);
+ private final ImageCustomPermissionPage me = this;
+
private UploadWizardState state = null;
- private ArrayList<UserImagePermissions> permissionList = null;
+
+ private ArrayList<UserImagePermissions> permissionList = new ArrayList<>();
/**
* wizard page for setting custom permissions
@@ -36,36 +43,51 @@ public class ImageCustomPermissionPage extends ImageCustomPermissionPageLayout {
addUser.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
- LOGGER.debug("addUser clicked"); // TODO
+ // 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) {
+
+ // 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
+ LOGGER.debug("User already present in the list, skipping!");
+ return;
+ }
+ }
+ // add it to the list with either default permissions if set, or none
+ ImagePermissions newUserPerms = null;
+ if (state.permissions == null) {
+ newUserPerms = new ImagePermissions(false, false, false, false);
+ } else {
+ newUserPerms = state.permissions;
+ }
+ permissionList.add(new UserImagePermissions(newUser.userId, newUserPerms));
+ LOGGER.debug("User added: " + newUser);
+ permissionTable.setData(permissionList, false);
+ }
+ });
}
});
// delete user button adapter
removeUser.addActionListener(new ActionListener() {
+
@Override
public void actionPerformed(ActionEvent e) {
- LOGGER.debug("removeUser clicked"); // TODO
+ final UserImagePermissions selected = permissionTable.getSelectedItem();
+ LOGGER.debug("Removing: " + selected);
+ if (!permissionList.remove(selected)) {
+ LOGGER.debug("Could not remove: " + selected);
+ }
+ permissionTable.setData(permissionList, false);
}
});
}
@Override
- protected void onPageEnter() {
- // setup permission list for the table
- permissionList = new ArrayList<>();
- // TODO do not do this for all users :)
- for (UserInfo user : UserCache.getAll()) {
- LOGGER.debug(user);
- // check if we have a default permission
- if (state.permissions != null) {
- LOGGER.debug("adding");
- permissionList.add(new UserImagePermissions(user.getUserId(), state.permissions));
- } else
- LOGGER.debug("skip");
- }
- permissionTable.setData(permissionList, true);
-
- }
- @Override
protected void onPageLeave() {
LOGGER.debug("Saving permissions to state ...");
// save the table stuff to our upload wizard state