Skip to content

Commit

Permalink
Table That Reads Export Data
Browse files Browse the repository at this point in the history
Table that reads and displays the export data present within the users VCell home directory.
  • Loading branch information
AvocadoMoon committed Jan 22, 2024
1 parent 14414a0 commit 12e4f71
Show file tree
Hide file tree
Showing 3 changed files with 148 additions and 65 deletions.
12 changes: 9 additions & 3 deletions src/main/java/org/vcell/vcellfiji/N5ImageHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ public class N5ImageHandler implements Command, ActionListener {
private AmazonS3 s3Client;
private String bucketName;
private String s3ObjectKey;
public static final String formatName = "N5";
@Parameter
private LogService logService;

private HashMap<DataType, Type> typeHashMap = new HashMap<DataType, Type>() {{
put(DataType.UINT8, UnsignedByteType.class);
}
};

@Override
public void actionPerformed(ActionEvent e) {
enableCriticalButtons(false);
Expand All @@ -79,8 +85,8 @@ protected ArrayList<String> doInBackground() throws Exception {
n5DataSetList = getS3N5DatasetList();
} else if (e.getSource() == vGui.mostRecentExport) {
ExportDataRepresentation jsonData = getJsonData();
if (jsonData != null && jsonData.formatData.containsKey("N5")) {
ExportDataRepresentation.FormatExportDataRepresentation formatExportDataRepresentation = jsonData.formatData.get("N5");
if (jsonData != null && jsonData.formatData.containsKey(formatName)) {
ExportDataRepresentation.FormatExportDataRepresentation formatExportDataRepresentation = jsonData.formatData.get(formatName);
Stack<String> formatJobIDs = formatExportDataRepresentation.formatJobIDs;
String jobID = formatJobIDs.isEmpty() ? null : formatJobIDs.peek();

Expand Down Expand Up @@ -162,7 +168,7 @@ private void enableCriticalButtons(boolean enable) {

@Override
public void run() {
this.vGui = new N5ViewerGUI();
this.vGui = new N5ViewerGUI(this);
this.vGui.localFileDialog.addActionListener(this);
this.vGui.okayButton.addActionListener(this);
// this.vGui.exportTableButton.addActionListener(this);
Expand Down
192 changes: 137 additions & 55 deletions src/main/java/org/vcell/vcellfiji/UI/N5ExportTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@
import org.vcell.vcellfiji.N5ImageHandler;

import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.AbstractTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;

public class N5ExportTable implements ActionListener {
private JDialog exportTableDialog;
private JPanel exportTablePanel;
private DefaultTableModel exportTableModel;
private N5ExportTableModel n5ExportTableModel;
private JButton open;
private JTable jTable;
@Parameter
private LogService logService;
private N5ImageHandler n5ImageHandler;

public N5ExportTable(N5ImageHandler n5ImageHandler){
initialize();
this.n5ImageHandler = n5ImageHandler;
}
public void updateTableModel(){
try{
ExportDataRepresentation jsonData = N5ImageHandler.getJsonData();
Expand All @@ -44,71 +52,145 @@ public void updateTableModel(){
}

public void initalizeTableData(){
// ExportDataRepresentation jsonData = null;
// try {
// jsonData = N5ImageHandler.getJsonData();
// if (jsonData != null){
// List<String> set = (ArrayList<String>) jsonData.get("jobIDs");
// for (String s : set) {
// addRowFromJson(jsonData, s);
// }
// }
// exportTableModel.fireTableDataChanged();
// } catch (FileNotFoundException e) {
// throw new RuntimeException(e);
// }
ExportDataRepresentation jsonData = null;
try {
jsonData = N5ImageHandler.getJsonData();
if (jsonData != null){
ExportDataRepresentation.FormatExportDataRepresentation formatExportData = jsonData.formatData.get(N5ImageHandler.formatName);
Stack<String> jobStack = formatExportData.formatJobIDs;
while (!jobStack.isEmpty()){
n5ExportTableModel.addRowData(formatExportData.simulationDataMap.get(jobStack.pop()));
}
}
n5ExportTableModel.fireTableDataChanged();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}

public void addRowFromJson(HashMap<String, Object> jsonData, String s){
exportTableModel.addRow(new Object[]{""});

private void initialize(){
exportTablePanel = new JPanel();

n5ExportTableModel = new N5ExportTableModel();

jTable = new JTable(n5ExportTableModel);
JScrollPane jScrollPane = new JScrollPane(jTable);

jScrollPane.setSize(500, 400);
jScrollPane.setPreferredSize(new Dimension(500, 400));
jScrollPane.setMinimumSize(new Dimension(500, 400));

JLabel jLabel = new JLabel("Recent Exports. List is volatile save important export metadata elsewhere.");
JButton refresh = new JButton("Refresh List");
open = new JButton("Open");

JPanel topBar = new JPanel();
topBar.setLayout(new FlowLayout());
refresh.addActionListener(this);
open.addActionListener(this);
topBar.add(jLabel);
topBar.add(open);
topBar.add(refresh);

exportTablePanel.setLayout(new BorderLayout());
exportTablePanel.add(topBar, BorderLayout.NORTH);
exportTablePanel.add(jScrollPane);

exportTablePanel.setPreferredSize(new Dimension(800, 500));
JOptionPane pane = new JOptionPane(exportTablePanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[]{"Close"});
exportTableDialog = pane.createDialog("VCell Exports");
exportTableDialog.setModal(false);
exportTableDialog.setResizable(true);
exportTableDialog.setVisible(true);

initalizeTableData();
}


public void displayExportTable() {
if (exportTableDialog == null) {
exportTablePanel = new JPanel();

DefaultTableModel defaultTableModel = new DefaultTableModel();
defaultTableModel.addColumn("Test");
defaultTableModel.addColumn("Test2");
Object[] testRow = {"k", "b"};
defaultTableModel.addRow(testRow);

JTable jTable = new JTable(defaultTableModel);
JScrollPane jScrollPane = new JScrollPane(jTable);

jScrollPane.setSize(500, 400);
jScrollPane.setPreferredSize(new Dimension(500, 400));
jScrollPane.setMinimumSize(new Dimension(500, 400));

JLabel jLabel = new JLabel("Recent Exports. List is volatile save important export metadata elsewhere.");
JButton refresh = new JButton("Refresh List");
JButton open = new JButton("Open");

JPanel topBar = new JPanel();
topBar.setLayout(new FlowLayout());
refresh.addActionListener(this);
open.addActionListener(this);
topBar.add(jLabel);
topBar.add(open);
topBar.add(refresh);

exportTablePanel.setLayout(new BorderLayout());
exportTablePanel.add(topBar, BorderLayout.NORTH);
exportTablePanel.add(jScrollPane);

exportTablePanel.setPreferredSize(new Dimension(800, 500));
JOptionPane pane = new JOptionPane(exportTablePanel, JOptionPane.PLAIN_MESSAGE, 0, null, new Object[]{"Close"});
exportTableDialog = pane.createDialog("VCell Exports");
exportTableDialog.setModal(false);
exportTableDialog.setResizable(true);
exportTableDialog.setVisible(true);
initialize();
} else {
exportTableDialog.setVisible(true);
}
}

@Override
public void actionPerformed(ActionEvent e) {
if(e.getSource().equals(open)){
int[] selectedRows = jTable.getSelectedRows();
for(int row: selectedRows){
String uri = n5ExportTableModel.getRowData(row).uri;
n5ImageHandler.createS3Client(uri);
n5ImageHandler.displayN5Results(n5ImageHandler.getS3N5DatasetList());
}
}
}

static class N5ExportTableModel extends AbstractTableModel {
public final ArrayList<String> headers = new ArrayList<String>(){{
add("BM Name");
add("App Name");
add("Sim Name");
add("Time Slice");
add("Variables");
add("Default Parameters");
add("Set Parameters");
add("Date Exported");
}};

private final List<ExportDataRepresentation.SimulationExportDataRepresentation> tableData = new ArrayList<>();

public N5ExportTableModel(){
}

@Override
public int getRowCount() {
return tableData.size();
}

@Override
public int getColumnCount() {
return headers.size();
}

@Override
public String getColumnName(int column) {
return headers.get(column);
}

@Override
public Object getValueAt(int rowIndex, int columnIndex) {
ExportDataRepresentation.SimulationExportDataRepresentation data = getRowData(rowIndex);
if (columnIndex == headers.indexOf("App Name")){
return data.applicationName;
} else if (columnIndex == headers.indexOf("BM Name")) {
return data.biomodelName;
} else if (columnIndex == headers.indexOf("Sim Name")) {
return data.simulationName;
} else if (columnIndex == headers.indexOf("Time Slice")) {
return data.startAndEndTime;
} else if (columnIndex == headers.indexOf("Variables")) {
return data.variables;
} else if (columnIndex == headers.indexOf("Date Exported")) {
return data.exportDate;
}
else if (columnIndex == headers.indexOf("Default Parameters")) {
return String.valueOf(data.defaultParameterValues);
}
else if (columnIndex == headers.indexOf("Set Parameters")) {
return String.valueOf(data.setParameterValues);
}
return null;
}

public ExportDataRepresentation.SimulationExportDataRepresentation getRowData(int rowIndex){
return tableData.get(rowIndex);
}

public void addRowData(ExportDataRepresentation.SimulationExportDataRepresentation rowData){
tableData.add(rowData);
}
}
}
9 changes: 2 additions & 7 deletions src/main/java/org/vcell/vcellfiji/UI/N5ViewerGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class N5ViewerGUI extends JFrame implements ActionListener {

public RemoteFileSelection remoteFileSelection;

public N5ViewerGUI() {
public N5ViewerGUI(N5ImageHandler n5ImageHandler) {
thisJFrame = this;
localFileDialog = new JFileChooser();
mainPanel = new JPanel();
Expand Down Expand Up @@ -128,7 +128,7 @@ public N5ViewerGUI() {
this.remoteFileSelection = new RemoteFileSelection(thisJFrame);


n5ExportTable = new N5ExportTable();
n5ExportTable = new N5ExportTable(n5ImageHandler);
}

public void updateDatasetList(ArrayList<String> arrayList){
Expand Down Expand Up @@ -156,10 +156,5 @@ public void actionPerformed(ActionEvent e) {
}
}

public void refreshDataList(){

}


}

0 comments on commit 12e4f71

Please sign in to comment.