use of edu.cmu.tetradapp.app.hpc.editor.LoadHpcGraphJsonTableModel in project tetrad by cmu-phil.
the class LoadHpcGraphJsonAction method buildHpcJsonChooserComponent.
private JComponent buildHpcJsonChooserComponent(final TetradDesktop desktop) {
final HpcAccountManager hpcAccountManager = desktop.getHpcAccountManager();
final HpcJobManager hpcJobManager = desktop.getHpcJobManager();
// Get ComputingAccount from DB
final DefaultListModel<HpcAccount> listModel = new DefaultListModel<HpcAccount>();
for (HpcAccount account : hpcAccountManager.getHpcAccounts()) {
listModel.addElement(account);
}
// JSplitPane
final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
// Left pane -> JList (parent pane)
JPanel leftPanel = new JPanel(new BorderLayout());
// Right pane -> ComputingAccountResultList
final JPanel jsonResultListPanel = new JPanel(new BorderLayout());
int minWidth = 800;
int minHeight = 600;
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int frameWidth = screenWidth * 3 / 4;
int frameHeight = screenHeight * 3 / 4;
final int paneWidth = minWidth > frameWidth ? minWidth : frameWidth;
final int paneHeight = minHeight > frameHeight ? minHeight : frameHeight;
// JTable
final Vector<String> columnNames = new Vector<>();
columnNames.addElement("Name");
columnNames.addElement("Created");
columnNames.addElement("Last Modified");
columnNames.addElement("Size");
Vector<Vector<String>> rowData = new Vector<>();
final DefaultTableModel tableModel = new LoadHpcGraphJsonTableModel(rowData, columnNames);
final JTable jsonResultTable = new JTable(tableModel);
jsonResultTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
// Resize table's column width
jsonResultTable.getColumnModel().getColumn(0).setPreferredWidth(paneWidth * 2 / 5);
jsonResultTable.getColumnModel().getColumn(1).setPreferredWidth(paneWidth * 2 / 15);
jsonResultTable.getColumnModel().getColumn(2).setPreferredWidth(paneWidth * 2 / 15);
jsonResultTable.getColumnModel().getColumn(3).setPreferredWidth(paneWidth * 2 / 15);
ListSelectionModel selectionModel = jsonResultTable.getSelectionModel();
selectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
int row = jsonResultTable.getSelectedRow();
if (row >= 0) {
DefaultTableModel model = (DefaultTableModel) jsonResultTable.getModel();
jsonFileName = (String) model.getValueAt(row, 0);
}
}
});
final JScrollPane scrollTablePane = new JScrollPane(jsonResultTable);
jsonResultListPanel.add(scrollTablePane, BorderLayout.CENTER);
splitPane.setLeftComponent(leftPanel);
splitPane.setRightComponent(jsonResultListPanel);
// Center Panel
final JList<HpcAccount> accountList = new JList<>(listModel);
accountList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
accountList.setLayoutOrientation(JList.VERTICAL);
accountList.setSelectedIndex(-1);
accountList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (e.getValueIsAdjusting())
return;
int selectedIndex = ((JList<?>) e.getSource()).getSelectedIndex();
// Show or remove the json list
if (selectedIndex > -1) {
jsonFileName = null;
hpcAccount = listModel.get(selectedIndex);
TableColumnModel columnModel = jsonResultTable.getColumnModel();
List<Integer> columnWidthList = new ArrayList<>();
for (int i = 0; i < columnModel.getColumnCount(); i++) {
int width = columnModel.getColumn(i).getPreferredWidth();
columnWidthList.add(width);
}
jsonResultTable.clearSelection();
try {
HpcAccountService hpcAccountService = hpcJobManager.getHpcAccountService(hpcAccount);
ResultService resultService = hpcAccountService.getResultService();
Set<ResultFile> results = resultService.listAlgorithmResultFiles(HpcAccountUtils.getJsonWebToken(hpcAccountManager, hpcAccount));
Vector<Vector<String>> jsonFiles = new Vector<>();
for (ResultFile resultFile : results) {
if (resultFile.getName().endsWith(".json")) {
Vector<String> rowData = new Vector<>();
rowData.addElement(resultFile.getName());
rowData.addElement(FilePrint.fileTimestamp(resultFile.getCreationTime().getTime()));
rowData.addElement(FilePrint.fileTimestamp(resultFile.getLastModifiedTime().getTime()));
rowData.addElement(FilePrint.humanReadableSize(resultFile.getFileSize(), false));
jsonFiles.add(rowData);
}
}
tableModel.setDataVector(jsonFiles, columnNames);
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// Resize table's column width
for (int i = 0; i < columnModel.getColumnCount(); i++) {
jsonResultTable.getColumnModel().getColumn(i).setPreferredWidth(columnWidthList.get(i).intValue());
}
}
}
});
// Left Panel
JScrollPane accountListScroller = new JScrollPane(accountList);
leftPanel.add(accountListScroller, BorderLayout.CENTER);
splitPane.setDividerLocation(paneWidth / 5);
accountListScroller.setPreferredSize(new Dimension(paneWidth / 5, paneHeight));
jsonResultListPanel.setPreferredSize(new Dimension(paneWidth * 4 / 5, paneHeight));
return splitPane;
}
Aggregations