Skip to content

Commit

Permalink
Merge pull request #1215 from virtualcell/dan-export-monitor
Browse files Browse the repository at this point in the history
Dan export monitor
  • Loading branch information
danv61 committed Apr 8, 2024
2 parents f26e897 + 8e9f963 commit c80ec97
Show file tree
Hide file tree
Showing 4 changed files with 149 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2522,9 +2522,9 @@ public static void downloadExportedData(final Component requester, final UserPre
if (exportsRecord.contains(evt.getJobID() + "")) {
return;
}
if (evt.getLocation().toLowerCase().endsWith("." + N5Specs.n5Suffix)){
return;
}
// if (evt.getLocation().toLowerCase().endsWith("." + N5Specs.n5Suffix)){
// return;
// }
AsynchClientTask task1 = new AsynchClientTask("Retrieving data from '" + evt.getLocation() + "'",
AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

Expand Down
161 changes: 138 additions & 23 deletions vcell-client/src/main/java/cbit/vcell/export/gui/ExportMonitorPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.StringSelection;
import java.awt.event.ActionEvent;
import java.io.File;
import java.nio.file.Paths;
import java.util.Enumeration;
import java.util.Optional;

import javax.swing.*;
import javax.swing.event.ListSelectionEvent;
Expand All @@ -23,8 +26,11 @@
import javax.swing.table.TableCellRenderer;
import javax.swing.table.TableColumn;

import cbit.vcell.client.data.ExportedDataTableModel;
import cbit.vcell.resource.PropertyLoader;
import org.apache.xalan.trace.SelectionEvent;
import org.vcell.util.gui.DefaultScrollTableActionManager;
import org.vcell.util.gui.DialogUtils;
import org.vcell.util.gui.ScrollTable;

import cbit.rmi.event.ExportEvent;
Expand All @@ -41,6 +47,10 @@ public class ExportMonitorPanel extends JPanel {
private boolean fieldHasJobs = false;
private javax.swing.JMenuItem ivjJMenuItemCopyLocation = null;

private JButton copyButton = null;
private JButton helpButton = null;
private JButton imagejButton = null;

class IvjEventHandler implements java.awt.event.ActionListener, java.beans.PropertyChangeListener, ListSelectionListener {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() == ExportMonitorPanel.this.getScrollPaneTable() && (evt.getPropertyName().equals("model")))
Expand All @@ -51,8 +61,15 @@ public void propertyChange(java.beans.PropertyChangeEvent evt) {

@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == ExportMonitorPanel.this.getJMenuItemCopyLocation()) {
JMenuItemCopyLocation_ActionPerformed(e);
// if (e.getSource() == ExportMonitorPanel.this.getJMenuItemCopyLocation()) {
// JMenuItemCopyLocation_ActionPerformed(e);
// } else
if(e.getSource() == getCopyButton()) {
CopyButton_ActionPerformed();
// } else if(e.getSource() == getImagejButton()) {
// ImagejButton_ActionPerformed();
} else if(e.getSource() == getHelpButton()) {
HelpButton_ActionPerformed();
}
}

Expand All @@ -63,10 +80,8 @@ public void valueChanged(ListSelectionEvent e) {
}
if(e.getSource() == getScrollPaneTable().getSelectionModel()) {
int row = getScrollPaneTable().getSelectedRow();
/*
TODO: we may like to automatically copy to clipboard the file location on row selection
instead of inserting the Copy Location menu on right click
*/
getCopyButton().setEnabled(row == -1 ? false : true);
//getImagejButton().setEnabled(row == -1 ? false : true);
}
}

Expand Down Expand Up @@ -202,14 +217,15 @@ private ScrollTable getScrollPaneTable() {
ivjScrollPaneTable.setScrollTableActionManager(new DefaultScrollTableActionManager(getScrollPaneTable()) {
@Override
protected void constructPopupMenu() {
if(popupMenu == null) {
//super.constructPopupMenu();
popupMenu = new JPopupMenu();
popupLabel = new javax.swing.JLabel();
popupLabel.setText(" Popup Menu");
popupMenu.insert(getJMenuItemCopyLocation(), 0);
}
popupMenu.show(ivjScrollPaneTable, ownerTable.getX(), ownerTable.getY());
// uncomment to enable "Copy to clipboard" popup menu
// if(popupMenu == null) {
// //super.constructPopupMenu();
// popupMenu = new JPopupMenu();
// popupLabel = new javax.swing.JLabel();
// popupLabel.setText(" Popup Menu");
// popupMenu.insert(getJMenuItemCopyLocation(), 0);
// }
// popupMenu.show(ivjScrollPaneTable, ownerTable.getX(), ownerTable.getY());
}

});
Expand Down Expand Up @@ -262,13 +278,39 @@ private void initialize() {
setLayout(new java.awt.GridBagLayout());
setSize(638, 241);

java.awt.GridBagConstraints constraintsJScrollPane1 = new java.awt.GridBagConstraints();
constraintsJScrollPane1.gridx = 0; constraintsJScrollPane1.gridy = 0;
constraintsJScrollPane1.gridwidth = 2;
constraintsJScrollPane1.fill = java.awt.GridBagConstraints.BOTH;
constraintsJScrollPane1.weightx = 1.0;
constraintsJScrollPane1.weighty = 1.0;
add(getScrollPaneTable().getEnclosingScrollPane(), constraintsJScrollPane1);
GridBagConstraints gbc = new java.awt.GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.gridheight = 7;
gbc.fill = java.awt.GridBagConstraints.BOTH;
gbc.weightx = 1.0;
gbc.weighty = 1.0;
add(getScrollPaneTable().getEnclosingScrollPane(), gbc);

gbc = new java.awt.GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.insets = new Insets(1, 6, 7, 4);
add(getCopyButton(), gbc);

gbc = new java.awt.GridBagConstraints();
gbc.gridx = 2;
gbc.gridy = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.anchor = GridBagConstraints.NORTHEAST;
gbc.insets = new Insets(1, 6, 7, 4);
add(getHelpButton(), gbc);

// gbc = new java.awt.GridBagConstraints();
// gbc.gridx = 2;
// gbc.gridy = 2;
// gbc.fill = GridBagConstraints.HORIZONTAL;
// gbc.anchor = GridBagConstraints.NORTHEAST;
// gbc.insets = new Insets(1, 6, 7, 4);
// add(getImagejButton(), gbc);

initConnections();
} catch (java.lang.Throwable ivjExc) {
Expand Down Expand Up @@ -347,13 +389,86 @@ private JMenuItem getJMenuItemCopyLocation() {
return ivjJMenuItemCopyLocation;
}
private void JMenuItemCopyLocation_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
// int[] rows = getScrollPaneTable().getSelectedRows();
// String str = (String)getScrollPaneTable().getModel().getValueAt(rows[0], 4);
// Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
// StringSelection stringSelection = new StringSelection(str);
// clipboard.setContents(stringSelection, null);
}

private JButton getCopyButton() {
if(copyButton == null) {
copyButton = new JButton("Copy Link");
copyButton.setName("CopyButton");
copyButton.addActionListener(ivjEventHandler);
copyButton.setEnabled(false);
}
return copyButton;
}
private JButton getHelpButton() {
if(helpButton == null) {
helpButton = new JButton("Help");
helpButton.setName("HelpButton");
helpButton.addActionListener(ivjEventHandler);
helpButton.setEnabled(true);
}
return helpButton;
}
private JButton getImagejButton() {
if(imagejButton == null) {
imagejButton = new JButton("Launch Imagej");
imagejButton.setName("ImagejButton");
imagejButton.addActionListener(ivjEventHandler);
String command = PropertyLoader.getProperty(PropertyLoader.imageJ, "");
if(command == null || command.isEmpty()) {
imagejButton.setEnabled(false);
} else {
File imageJExe = new File(command);
if(imageJExe.exists() && !imageJExe.isDirectory() && imageJExe.canExecute()) {
imagejButton.setEnabled(true);
} else {
imagejButton.setEnabled(false);
}
}
}
return imagejButton;
}

private void CopyButton_ActionPerformed() {
int[] rows = getScrollPaneTable().getSelectedRows();
String str = (String)getScrollPaneTable().getModel().getValueAt(rows[0], 4);
String str = (String)getScrollPaneTable().getModel().getValueAt(rows[0], 3);
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection stringSelection = new StringSelection(str);
clipboard.setContents(stringSelection, null);
}

private void HelpButton_ActionPerformed() {
String message = "The simulation results of spatial applications may be exported to ImageJ for further ";
message += "processing using the compatible N5 format.\n";
message += "Use the 'Copy Link' button above to copy the exported data location to the clipboard.\n";
message += "Use the vcell macro in ImageJ to download the file within ImageJ for further processing.";
DialogUtils.showInfoDialog(ExportMonitorPanel.this, "ImageJ Export Help", message);
}
private void ImagejButton_ActionPerformed() {
try {
// String command = Paths.get(System.getenv("windir"), "system32", "tree.com /A").toString();
String command = PropertyLoader.getProperty(PropertyLoader.imageJ, "");
if(command == null || command.isEmpty()) {
System.out.println("Property 'vcell.imageJ' not set");
return;
}
ProcessHandle.allProcesses().forEach(process -> {
Optional<String> proc = process.info().command();
System.out.println(proc);
if(proc.toString().toLowerCase().contains("imagej")) {
System.out.println(proc);
//DialogUtils.showInfoDialog(ExportMonitorPanel.this, "Information", "ImageJ already running.");
}
});
Process p = Runtime.getRuntime().exec(command);
} catch(Exception ex) {
ex.printStackTrace();
}
}
/**
* Sets the hasJobs property (boolean) value.
* @param hasJobs The new value for the property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public class ExportMonitorTableModel extends AbstractTableModel {
public static final String ID_COLUMN_NAME = "Job ID";
public static final String FORMAT_COLUMN_NAME = "Format";
public static final String PROGRESS_COLUMN_NAME = "Export Progress";
public static final String STATUS_COLUMN_NAME = "Completed ?";
// public static final String STATUS_COLUMN_NAME = "Completed ?";
public static final String DESTINATION_COLUMN_NAME = "File Location";
public static final String RESULT_ID_COLUMN_NAME = "Simulation";
private String[] columnNames = null;
Expand All @@ -38,7 +38,7 @@ public class ExportMonitorTableModel extends AbstractTableModel {
*/
public ExportMonitorTableModel() {
super();
columnNames = new String[] {ID_COLUMN_NAME, FORMAT_COLUMN_NAME, PROGRESS_COLUMN_NAME, STATUS_COLUMN_NAME, DESTINATION_COLUMN_NAME, RESULT_ID_COLUMN_NAME};
columnNames = new String[] {ID_COLUMN_NAME, FORMAT_COLUMN_NAME, PROGRESS_COLUMN_NAME, /*STATUS_COLUMN_NAME,*/ DESTINATION_COLUMN_NAME, RESULT_ID_COLUMN_NAME};
rows = new Vector();
}
/**
Expand Down Expand Up @@ -143,9 +143,9 @@ public Class getColumnClass(int columnIndex) {
case 0: return Long.class;
case 1: return String.class;
case 2: return JProgressBar.class;
case 3: return Boolean.class;
// case 3: return Boolean.class;
case 3: return String.class;
case 4: return String.class;
case 5: return String.class;
default: return Object.class;
}
}
Expand Down Expand Up @@ -204,8 +204,8 @@ public Object getValueAt(int row, int column) {
return es.getJobID();
} else if (columnName.equals(FORMAT_COLUMN_NAME)) {
return es.getFormat();
} else if (columnName.equals(STATUS_COLUMN_NAME)) {
return es.getComplete();
// } else if (columnName.equals(STATUS_COLUMN_NAME)) {
// return es.getComplete();
} else if (columnName.equals(PROGRESS_COLUMN_NAME)) {
return es.getProgressBar();
} else if (columnName.equals(DESTINATION_COLUMN_NAME)) {
Expand Down Expand Up @@ -247,6 +247,6 @@ public synchronized void removePropertyChangeListener(java.lang.String propertyN
private void setMinRowHeight(int minRowHeight) {
int oldValue = fieldMinRowHeight;
fieldMinRowHeight = minRowHeight;
firePropertyChange("minRowHeight", new Integer(oldValue), new Integer(minRowHeight));
firePropertyChange("minRowHeight", oldValue, minRowHeight);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public static void setConfigProvider(VCellConfigProvider configProvider) {
public static final String cliWorkingDir = record("cli.workingDir", ValueType.DIR);
public static final String vtkPythonDir = record("vcell.vtk.pythonDir", ValueType.DIR);


public static final String imageJ = record("vcell.imageJ", ValueType.EXE);
public static final String enableSpringSaLaD = record("vcell.enableSpringSaLaD", ValueType.BOOL);
public static final boolean enableSpringSalad_default_value=true;

Expand Down

0 comments on commit c80ec97

Please sign in to comment.