From 59782784a3e6ce52d3db84d569fa9e2da10a65cd Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 29 Jul 2015 17:07:10 +0200 Subject: [client] ImageTable now with proper column labeling, finalized ImageListLayout based on BorderLayout --- .../dozmod/gui/control/table/ImageTable.java | 10 +- .../openslx/dozmod/gui/helper/ImageTableModel.java | 69 ------ .../openslx/dozmod/gui/window/ImageListWindow.java | 259 ++++++++------------- .../gui/window/layout/ImageListWindowLayout.java | 51 ++-- .../java/org/openslx/dozmod/util/FormatHelper.java | 13 ++ 5 files changed, 139 insertions(+), 263 deletions(-) delete mode 100644 dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageTableModel.java (limited to 'dozentenmodul/src/main/java') 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 adf548f1..4ad6472d 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 @@ -2,13 +2,15 @@ package org.openslx.dozmod.gui.control.table; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.bwlp.thrift.iface.LectureSummary; +import org.openslx.dozmod.thrift.MetaDataCache; import org.openslx.dozmod.thrift.UserCache; import org.openslx.dozmod.util.FormatHelper; @SuppressWarnings("serial") public class ImageTable extends ListTable { - private static String[] columnNames = { "Name", "Verantwortlicher" }; + private static String[] columnNames = + { "Name", "OS", "Verantwortlicher", "Letztes Update", "Größe" }; public ImageTable() { super(columnNames); @@ -20,7 +22,13 @@ public class ImageTable extends ListTable { if (columnIndex == 0) return row.getImageName(); if (columnIndex == 1) + return FormatHelper.osName(MetaDataCache.getOsById(row.getOsId())); + if (columnIndex == 2) return FormatHelper.userName(UserCache.find(row.getOwnerId())); + if (columnIndex == 3) + return FormatHelper.longDate(row.getUpdateTime()); + if (columnIndex == 4) + return row.getCurrentVersionId() == null ? "-" : FormatHelper.bytes(row.getFileSize(), false); throw new IndexOutOfBoundsException(); } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageTableModel.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageTableModel.java deleted file mode 100644 index 443bb4c6..00000000 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/helper/ImageTableModel.java +++ /dev/null @@ -1,69 +0,0 @@ -package org.openslx.dozmod.gui.helper; - -import java.util.List; - -import javax.swing.table.AbstractTableModel; - -import org.openslx.bwlp.thrift.iface.ImageSummaryRead; -import org.openslx.bwlp.thrift.iface.OperatingSystem; -import org.openslx.bwlp.thrift.iface.UserInfo; -import org.openslx.dozmod.thrift.MetaDataCache; -import org.openslx.dozmod.thrift.UserCache; -import org.openslx.dozmod.util.FormatHelper; - -public class ImageTableModel extends AbstractTableModel { - - private static final long serialVersionUID = 3335684645951493805L; - protected String[] columnNames = new String[] { - "Name", "OS", "Verantwortlicher", "Letztes Update", "Größe" - }; - protected Class[] columnClasses = new Class[] { - String.class, String.class, String.class, String.class, String.class - }; - private List items = null; - - public ImageSummaryRead get(int index) { - return items.get(index); - } - public void setItems(List items) { - this.items = items; - fireTableDataChanged(); - } - @Override - public int getColumnCount() { - return columnNames.length; - } - - public boolean isCellEditable(int row, int col) - { return false; } - - @Override - public int getRowCount() { - if (items == null) { - return 0; - } - return items.size(); - } - public Class getColumnClass(int c) { - - return columnClasses[c]; - } - public String getColumnName(int c) { - - return columnNames[c]; - } - @Override - public Object getValueAt(int rowIndex, int columnIndex) { - ImageSummaryRead item = items.get(rowIndex); - OperatingSystem os = MetaDataCache.getOsById(item.getOsId()); - UserInfo user = UserCache.find(item.getOwnerId()); - switch(columnIndex) { - case 0: return item.getImageName(); - case 1: return os == null ? "Unknown" : os.getOsName(); - case 2: return FormatHelper.userName(user); - case 3: return FormatHelper.shortDate(item.getUpdateTime()); - case 4: return item.getCurrentVersionId() == null ? "-" : FormatHelper.bytes(item.getFileSize(), false); - default: return null; - } - } -} 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 0e3aa56c..8257f8b2 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 @@ -1,155 +1,148 @@ package org.openslx.dozmod.gui.window; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.util.ArrayList; +import java.util.List; -import javax.swing.RowSorter; -import javax.swing.RowSorter.SortKey; -import javax.swing.SortOrder; -import javax.swing.SwingUtilities; +import javax.swing.JTextField; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableRowSorter; import org.apache.log4j.Logger; +import org.openslx.bwlp.thrift.iface.ImagePermissions; import org.openslx.bwlp.thrift.iface.ImageSummaryRead; import org.openslx.dozmod.gui.Gui; -import org.openslx.dozmod.gui.helper.ImageTableModel; -import org.openslx.dozmod.gui.helper.TableColumnAdjuster; +import org.openslx.dozmod.gui.MainWindow; import org.openslx.dozmod.gui.window.layout.ImageListWindowLayout; import org.openslx.dozmod.thrift.ImageCache; +import org.openslx.dozmod.thrift.UserCache; +import org.openslx.dozmod.util.FormatHelper; +import org.openslx.util.QuickTimer; +import org.openslx.util.QuickTimer.Task; public class ImageListWindow extends ImageListWindowLayout { private final static Logger LOGGER = Logger.getLogger(ImageListWindow.class); - TableRowSorter sorter = new TableRowSorter(); + public final ImageListWindow me = this; public ImageListWindow() { super(); - ImageTableModel itm = new ImageTableModel(); - sorter.setSortsOnUpdates(true); - sorter.setModel(itm); - ArrayList list = new ArrayList(); - list.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); - sorter.setSortKeys(list); - imageTable.setRowSorter(sorter); - imageTable.setModel(itm); - // SWING TABLE STUFF + // filter the objects in the table depending on the search field + searchTextField.getDocument().addDocumentListener(new DocumentListener() { + @Override + public void removeUpdate(DocumentEvent e) { + changedUpdate(e); + } + + @Override + public void insertUpdate(DocumentEvent e) { + changedUpdate(e); + } + + @Override + public void changedUpdate(DocumentEvent e) { + // TODO: Set filter + } + }); + + // Selection listener for the table to update the details panel when an image is clicked imageTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { - int rowIndex = imageTable.getSelectedRow(); - if (rowIndex == -1) - return; - ImageTableModel model = (ImageTableModel) imageTable.getModel(); - final ImageSummaryRead image = model.get(imageTable.convertRowIndexToModel(rowIndex)); - LOGGER.debug(image); + ImageSummaryRead image = imageTable.getSelectedItem(); if (image == null) return; - Gui.asyncExec(new Runnable() { - public void run() { - // updateDetailPane(image); - } - }); + // Fill detail information fields + // Image name + setFieldText(imageSelectedNameLabel, image.getImageName()); + // id of the lecture + setFieldText(idInfo, image.getImageBaseId()); + // version of the image TODO last? current? + setFieldText(versionInfo, image.getCurrentVersionId()); + // last update of image + setFieldText(lastUpdateInfo, FormatHelper.longDate(image.getUpdateTime())); + // permissions of this image + ImagePermissions perms = image.getUserPermissions(); + if (perms == null) + perms = image.getDefaultPermissions(); + if (perms != null) + setFieldText(permissionInfo, perms.toString()); + // the owner of the selected lecture + setFieldText(ownerInfo, FormatHelper.userName(UserCache.find(image.getOwnerId()))); + // is it a template? + if (image.isTemplate) + templateInfo.setText("Ja"); + else + templateInfo.setText("Nein"); + + me.invalidate(); + me.validate(); + } + private void setFieldText(JTextField control, String content) { + if (content == null) { + control.setText(""); + } else { + control.setText(content); + } } }); imageTable.addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent me) { if (me.getClickCount() == 2) { - int rowIndex = imageTable.getSelectedRow(); - if (rowIndex == -1) - return; - ImageTableModel model = (ImageTableModel) imageTable.getModel(); - final ImageSummaryRead image = model.get(imageTable.convertRowIndexToModel(rowIndex)); - LOGGER.debug(image); - if (image == null) - return; - // Gui.asyncExec(new Runnable() { - // public void run() { - // ImageDetailsWindow popup = - // MainWindow.showPage(ImageDetailsWindow.class); - // if (popup != null) - // popup.setImage(image.getImageBaseId()); - // } - // }); + // TODO open details popup } } }); + newButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO open wizard for image creation + } + }); + + downloadButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO open download popup + } + }); - // // filter the objects in the table depending on the search field - // searchTextField.addKeyListener(new KeyAdapter() { - // @Override - // public void keyReleased(KeyEvent ke) { - // final String term = searchTextField.getText(); - // SwingUtilities.invokeLater(new Runnable() { - // @Override - // public void run() { - // RowFilter filter = null; - // try { - // filter = RowFilter.regexFilter(".*" + term + ".*"); - // } catch (java.util.regex.PatternSyntaxException e) { - // return; - // } - // sorter.setRowFilter(filter); - // }}); - // } - // }); - // - // newButton.addSelectionListener(new SelectionAdapter() { - // @Override - // public void widgetSelected(SelectionEvent e) { - // ImageWizard wizard = new ImageWizard(false); - // WizardDialog wd = new WizardDialog(getShell(), wizard); - // refreshList(wd.open() == Window.OK); - // } - // }); - // - //// editButton.addSelectionListener(new SelectionAdapter() { - //// @Override - //// public void widgetSelected(SelectionEvent e) { - //// ImageWizard wizard = new ImageWizard(true); - //// WizardDialog wd = new WizardDialog(getShell(), wizard); - //// refreshList(wd.open() == Window.OK); - //// } - //// }); - // - // - // // return to mainMenu - // backButton.addSelectionListener(new SelectionAdapter() { - // @Override - // public void widgetSelected(SelectionEvent e) { - //// MainWindow.showPage(MainMenuWindow.class); - // refreshList(true); - // } - // }); + // delete lecture + deleteButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + // TODO delete the image + } + }); + // return to mainMenu + backButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + MainWindow.showPage(MainMenuWindow.class); + } + }); + } private void refreshList(final boolean forceRefresh) { - SwingUtilities.invokeLater(new Runnable() { + QuickTimer.scheduleOnce(new Task() { @Override - public void run() { - ImageTableModel itm = (ImageTableModel) imageTable.getModel(); - itm.setItems(ImageCache.get(forceRefresh)); - itm.fireTableDataChanged(); - - if (sorter.getSortKeys().isEmpty()) { - ArrayList list = new ArrayList(); - list.add(new RowSorter.SortKey(0, SortOrder.ASCENDING)); - sorter.setSortKeys(list); - LOGGER.debug("Sortkeys: " + sorter.getSortKeys().get(0).getColumn()); - } else { - LOGGER.debug("Existing: " + sorter.getSortKeys().get(0).getColumn()); - } - - sorter.sort(); - TableColumnAdjuster tca = new TableColumnAdjuster(imageTable); - tca.adjustColumns(); - + public void fire() { + final List imageList = ImageCache.get(forceRefresh); + Gui.asyncExec(new Runnable() { + @Override + public void run() { + imageTable.setData(imageList); + } + }); } }); } @@ -163,50 +156,4 @@ public class ImageListWindow extends ImageListWindowLayout { public void requestShow() { refreshList(false); } - - // private void deleteCallback(ImageSummaryRead image, Throwable t) { - // if (t == null) { - // Gui.showMessageBox("Deleted image with UUID '" + image + "'.", - // MessageType.INFO, - // LOGGER, t); - // } else { - // Gui.showMessageBox("Failed to delete image!", MessageType.ERROR, LOGGER, - // t); - // } - // } - // - // private void updateDetailPane(ImageSummaryRead image) { - // // -- Set details -- - // // set the image name - // setFieldText(imageSelectedNameLabel, image.getImageName()); - // // set the image - // setFieldText(idInfo, image.getImageBaseId()); - // // set the current version of the image - // setFieldText(versionInfo, image.getCurrentVersionId()); - // // set the time, the image has last been updated - // lastUpdateInfo.setText(FormatHelper.shortDate(image.getUpdateTime())); - // // info about the image permissions - // ImagePermissions perms = image.getUserPermissions(); - // if (perms == null) - // perms = image.getDefaultPermissions(); - // if (perms != null) - // setFieldText(permissionInfo, perms.toString()); - // // the owner id of the selected image - // UserInfo user = UserCache.find(image.getOwnerId()); - // setFieldText(ownerInfo, FormatHelper.userName(user)); - // // set the template info - // if (image.isTemplate) { - // templateInfo.setText("ja"); - // } else { - // templateInfo.setText("Nein"); - // } - // } - // - // private void setFieldText(Text control, String content) { - // if (content == null) { - // control.setText(""); - // } else { - // control.setText(content); - // } - // } } diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java index e7ff4242..8c0c4cb3 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/gui/window/layout/ImageListWindowLayout.java @@ -11,22 +11,20 @@ import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSplitPane; -import javax.swing.JTable; import javax.swing.JTextField; -import javax.swing.ListSelectionModel; import javax.swing.border.TitledBorder; import org.apache.log4j.Logger; import org.openslx.dozmod.gui.control.table.ImageTable; import org.openslx.dozmod.gui.helper.CompositePage; import org.openslx.dozmod.gui.helper.GridPos; -import org.openslx.dozmod.gui.helper.ResizeColumnListener; public abstract class ImageListWindowLayout extends CompositePage { private final static Logger LOGGER = Logger.getLogger(ImageListWindowLayout.class); + protected final static String infoTextString = "Hier können Sie Virtuelle Maschinen hochladen, herunterladen, bearbeiten und löschen."; protected final static String infoTitleString = "Übersicht Virtuelle Maschinen"; protected final static String newButtonLabel = "Neu"; protected final static String editButtonLabel = "Bearbeiten"; @@ -37,13 +35,17 @@ public abstract class ImageListWindowLayout extends CompositePage { protected final static String vmInfoGroupLabel = "Detailinformationen"; protected final static String filterGroupLabel = "Filter"; - // buttons + // -------------------------------------- + // Left panel: search field, table and buttons + protected JTextField searchTextField; + protected ImageTable imageTable; protected JButton newButton; protected JButton deleteButton; protected JButton downloadButton; protected JButton backButton; - // imageDetail texts + // -------------------------------------- + // Right panel: image details information protected JTextField imageSelectedNameLabel; protected JTextField idInfo; protected JTextField versionInfo; @@ -52,12 +54,6 @@ public abstract class ImageListWindowLayout extends CompositePage { protected JTextField ownerInfo; protected JTextField templateInfo; - protected JTextField searchTextField; - - protected ImageTable imageTable; - - protected String infoTextString = "Hier können Sie Virtuelle Maschinen hochladen, herunterladen, bearbeiten und löschen."; - public ImageListWindowLayout() { super(new BorderLayout()); @@ -69,7 +65,7 @@ public abstract class ImageListWindowLayout extends CompositePage { add(infoPanel, BorderLayout.NORTH); // -------------------------------------- - // List panel with the list of the images + // LEFT: List panel with the list of the images JPanel listPanel = new JPanel(new BorderLayout()); // the search field searchTextField = new JTextField(); @@ -91,7 +87,7 @@ public abstract class ImageListWindowLayout extends CompositePage { listPanel.add(buttonPanel, BorderLayout.PAGE_END); // -------------------------------------- - // Details panel on the right side + // RIGHT: Details panel for the selected image final JPanel detailsPane = new JPanel(); detailsPane.setLayout(new GridBagLayout()); detailsPane.setBorder(new TitledBorder(vmInfoGroupLabel)); @@ -110,35 +106,16 @@ public abstract class ImageListWindowLayout extends CompositePage { // For some reason without this the controls above are centered vertically detailsPane.add(new JPanel(), GridPos.get(0, row++, 2, 1, true, true)); // the actual layout of the whole window - JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, listPanel, detailsPane); + JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); + splitPane.setLeftComponent(listPanel); + splitPane.setRightComponent(detailsPane); + // make the left panel grab the excess space + splitPane.setResizeWeight(1); GridBagLayout bag = new GridBagLayout(); GridBagConstraints con = new GridBagConstraints(); con.fill = GridBagConstraints.BOTH; bag.setConstraints(splitPane, con); add(splitPane); - - - } - public JPanel newLabelToTextField(final String labelName, JTextField textField, GridBagConstraints con) { - JPanel newPanel = new JPanel(); - con.gridwidth = 1; - con.gridx = 0; - con.weightx = 0.1; - con.anchor = GridBagConstraints.WEST; - con.fill = GridBagConstraints.BOTH; - newPanel.add(new JLabel(labelName), con); - con.gridx = 1; - con.weightx = 1.; - con.anchor = GridBagConstraints.EAST; - con.fill = GridBagConstraints.HORIZONTAL; - if (textField == null) { - textField = new JTextField(); - } - newPanel.add(textField, con); - - // finally update "row number" - con.gridy++; - return newPanel; } public JTextField createCaptionAndTextfield(String captionString, JPanel group, int row) { JLabel caption = new JLabel(captionString); diff --git a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java index c3251276..26c7071a 100644 --- a/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java +++ b/dozentenmodul/src/main/java/org/openslx/dozmod/util/FormatHelper.java @@ -2,6 +2,7 @@ package org.openslx.dozmod.util; import org.joda.time.format.DateTimeFormat; import org.joda.time.format.DateTimeFormatter; +import org.openslx.bwlp.thrift.iface.OperatingSystem; import org.openslx.bwlp.thrift.iface.UserInfo; public class FormatHelper { @@ -47,6 +48,18 @@ public class FormatHelper { return user.getLastName() + ", " + user.getFirstName(); } + /** + * Format the given OS's name. + * + * @param OS a {@link OperatingSystem} instance + * @return "LastName, FirstName" + */ + public static String osName(OperatingSystem os) { + if (os == null) + return "Unknown"; + return os.getOsName(); + } + /** * Format bytes using suitable unit prefix. * -- cgit v1.2.3-55-g7522