Search in sources :

Example 1 with ProgressDialogListener

use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.

the class DocumentWindow method startVCellVisIt.

private void startVCellVisIt() {
    AsynchClientTask findVisitTask = new AsynchClientTask("Searching for VisIt...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            try {
                VisitSupport.launchVisTool(VCellConfiguration.getFileProperty(PropertyLoader.visitExe));
            } catch (Exception e) {
                e.printStackTrace();
                OperatingSystemInfo osi = OperatingSystemInfo.getInstance();
                String executableName = ResourceUtil.getExecutableName(VisitSupport.VISIT_EXEC_NAME, false, osi);
                File executableLocation = new ExecutableFinderDialog(DocumentWindow.this, "If VisIt is installed (from " + "https://wci.llnl.gov/codes/visit/" + ") but not in the system path, then press press '" + ExecutableFinderDialog.FIND + "' and navigate to '" + executableName + "'.\nElse please install VisIt, restart VCell, and try again").find(executableName);
                VisitSupport.launchVisTool(executableLocation);
            }
        }
    };
    ProgressDialogListener progressDialogListener = new ProgressDialogListener() {

        @Override
        public void cancelButton_actionPerformed(EventObject newEvent) {
            System.out.println(newEvent);
        }
    };
    // ClientTaskDispatcher.dispatch(requester,           hash,              tasks,                                  customDialog, bShowProgressPopup, bKnowProgress, cancelable, progressDialogListener, bInputBlocking);
    ClientTaskDispatcher.dispatch(DocumentWindow.this, new Hashtable<>(), new AsynchClientTask[] { findVisitTask }, null, true, false, true, progressDialogListener, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ProgressDialogListener(org.vcell.util.ProgressDialogListener) ExecutableFinderDialog(org.vcell.util.gui.ExecutableFinderDialog) Hashtable(java.util.Hashtable) OperatingSystemInfo(cbit.vcell.resource.OperatingSystemInfo) File(java.io.File) UtilCancelException(org.vcell.util.UtilCancelException) EventObject(java.util.EventObject)

Example 2 with ProgressDialogListener

use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.

the class ClientSimManager method runSmoldynParticleView.

public void runSmoldynParticleView(final Simulation originalSimulation) {
    SimulationOwner simulationOwner = simWorkspace.getSimulationOwner();
    Collection<AsynchClientTask> tasks;
    if (simulationOwner instanceof SimulationContext) {
        tasks = ClientRequestManager.updateMath(documentWindowManager.getComponent(), (SimulationContext) simulationOwner, false, NetworkGenerationRequirements.ComputeFullStandardTimeout);
    } else {
        tasks = new ArrayList<>();
    }
    AsynchClientTask pv = new AsynchClientTask("starting particle view", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            File[] exes = SolverUtilities.getExes(SolverDescription.Smoldyn);
            assert exes.length == 1 : "one and only one smoldyn solver expected";
            File smoldynExe = exes[0];
            Simulation simulation = new TempSimulation(originalSimulation, false);
            SimulationTask simTask = new SimulationTask(new SimulationJob(simulation, 0, null), 0);
            File inputFile = new File(ResourceUtil.getLocalSimDir(User.tempUser.getName()), simTask.getSimulationJobID() + SimDataConstants.SMOLDYN_INPUT_FILE_EXTENSION);
            inputFile.deleteOnExit();
            PrintWriter pw = new PrintWriter(inputFile);
            SmoldynFileWriter smf = new SmoldynFileWriter(pw, true, null, simTask, false);
            smf.write();
            pw.close();
            String[] cmd = new String[] { smoldynExe.getAbsolutePath(), inputFile.getAbsolutePath() };
            StringBuilder commandLine = new StringBuilder();
            for (int i = 0; i < cmd.length; i++) {
                if (i > 0) {
                    commandLine.append(" ");
                }
                commandLine.append(TokenMangler.getEscapedPathName(cmd[i]));
            }
            System.out.println(commandLine);
            char[] charArrayOut = new char[10000];
            char[] charArrayErr = new char[10000];
            ProcessBuilder processBuilder = new ProcessBuilder(cmd);
            final Process process = processBuilder.start();
            getClientTaskStatusSupport().addProgressDialogListener(new ProgressDialogListener() {

                public void cancelButton_actionPerformed(EventObject newEvent) {
                    process.destroy();
                }
            });
            InputStream errorStream = process.getErrorStream();
            InputStreamReader errisr = new InputStreamReader(errorStream);
            InputStream outputStream = process.getInputStream();
            InputStreamReader outisr = new InputStreamReader(outputStream);
            StringBuilder sb = new StringBuilder();
            boolean running = true;
            while (running) {
                try {
                    process.exitValue();
                    running = false;
                } catch (IllegalThreadStateException e) {
                // process didn't exit yet, do nothing
                }
                if (outputStream.available() > 0) {
                    outisr.read(charArrayOut, 0, charArrayOut.length);
                }
                if (errorStream.available() > 0) {
                    errisr.read(charArrayErr, 0, charArrayErr.length);
                    sb.append(new String(charArrayErr));
                }
            }
            if (sb.length() > 0) {
                throw new RuntimeException(sb.toString());
            }
        }
    };
    tasks.add(pv);
    ClientTaskDispatcher.dispatchColl(documentWindowManager.getComponent(), new Hashtable<String, Object>(), tasks, false, true, null);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SimulationTask(cbit.vcell.messaging.server.SimulationTask) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) SimulationOwner(cbit.vcell.solver.SimulationOwner) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SimulationJob(cbit.vcell.solver.SimulationJob) PrintWriter(java.io.PrintWriter) InputStreamReader(java.io.InputStreamReader) Hashtable(java.util.Hashtable) InputStream(java.io.InputStream) TempSimulation(cbit.vcell.solver.TempSimulation) SimulationContext(cbit.vcell.mapping.SimulationContext) EventObject(java.util.EventObject) TempSimulation(cbit.vcell.solver.TempSimulation) Simulation(cbit.vcell.solver.Simulation) EventObject(java.util.EventObject) File(java.io.File)

Example 3 with ProgressDialogListener

use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.

the class BNGWindowManager method runBioNetGen.

/**
 * Gets the bngOutputPanel property (cbit.vcell.client.bionetgen.BNGOutputPanel) value.
 * @return The bngOutputPanel property value.
 */
public void runBioNetGen(BNGInput bngInput) {
    // Create a hash and put in the details required to run the ClientTaskDispatcher
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    hash.put(BNG_OUTPUT_PANEL, getBngOutputPanel());
    final BNGExecutorService bngService = BNGExecutorService.getInstance(bngInput, NetworkGenerationRequirements.NoTimeoutMS);
    // Create the AsynchClientTasks : in this case, running the BioNetGen (non-swing) and then displaying the output (swing) tasks.
    AsynchClientTask[] tasksArray = new AsynchClientTask[2];
    tasksArray[0] = new RunBioNetGen(bngService);
    tasksArray[1] = new DisplayBNGOutput();
    // Dispatch the tasks using the ClientTaskDispatcher.
    ClientTaskDispatcher.dispatch(getBngOutputPanel(), hash, tasksArray, false, true, new ProgressDialogListener() {

        public void cancelButton_actionPerformed(EventObject newEvent) {
            try {
                bngService.stopBNG();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ProgressDialogListener(org.vcell.util.ProgressDialogListener) Hashtable(java.util.Hashtable) DisplayBNGOutput(cbit.vcell.client.task.DisplayBNGOutput) EventObject(java.util.EventObject) BNGExecutorService(cbit.vcell.server.bionetgen.BNGExecutorService) RunBioNetGen(cbit.vcell.client.task.RunBioNetGen) EventObject(java.util.EventObject) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException)

Example 4 with ProgressDialogListener

use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.

the class ViewJobsPanel method stopJob.

private void stopJob() {
    Hashtable<String, Object> hash = new Hashtable<String, Object>();
    AsynchClientTask[] tasksArray = new AsynchClientTask[3];
    tasksArray[0] = new RunStopTaskQuery();
    tasksArray[1] = new RunRefreshQuery();
    tasksArray[2] = new DisplayRefreshResults();
    ClientTaskDispatcher.dispatch(this, hash, tasksArray, false, true, new ProgressDialogListener() {

        @Override
        public void cancelButton_actionPerformed(EventObject newEvent) {
            try {
                getRefreshAllButton().setEnabled(true);
                getStopJobButton().setEnabled(model.isStoppable(table.getSelectedRow()));
                System.out.println("...user cancelled.");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) BigString(org.vcell.util.BigString) EventObject(java.util.EventObject) RemoteProxyException(cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException) DataAccessException(org.vcell.util.DataAccessException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) EventObject(java.util.EventObject)

Example 5 with ProgressDialogListener

use of org.vcell.util.ProgressDialogListener in project vcell by virtualcell.

the class VCDocumentDbTreePanel method search.

public void search(final boolean bShowAll) {
    final Object[] status = new Object[] { null };
    class SearchCancel implements ProgressDialogListener {

        public void cancelButton_actionPerformed(EventObject newEvent) {
            status[0] = UserCancelException.CANCEL_GENERIC;
        }
    }
    final SearchCancel searchCancel = new SearchCancel();
    final ArrayList<SearchCriterion> searchCriterionListFinal = new ArrayList<DatabaseSearchPanel.SearchCriterion>();
    AsynchClientTask searchCriteriaTask = new AsynchClientTask("Creating search criteria...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, true) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (bShowAll) {
                return;
            }
            new Thread(new Runnable() {

                public void run() {
                    try {
                        ArrayList<SearchCriterion> searchCriterionList = getDatabaseSearchPanel().getSearchCriterionList(getDocumentManager());
                        if (status[0] == null) {
                            // update status only if no one else has
                            if (searchCriterionList != null && searchCriterionList.size() > 0) {
                                searchCriterionListFinal.addAll(searchCriterionList);
                            }
                            status[0] = "OK";
                            return;
                        } else {
                            return;
                        }
                    } catch (Exception e) {
                        status[0] = e;
                    }
                }
            }).start();
            long startTime = System.currentTimeMillis();
            while ((System.currentTimeMillis() - startTime) < 60000) {
                if (status[0] != null) {
                    if (status[0] instanceof Exception) {
                        // User cancelled or there was an exception in search criteria thread
                        throw (Exception) status[0];
                    }
                    // search criteria thread completed with 'OK'
                    return;
                }
                try {
                    Thread.sleep(100);
                } catch (InterruptedException ie) {
                // ignore
                }
            }
            throw new Exception("getSearchCriterionList timed out");
        }
    };
    AsynchClientTask refreshTask = new AsynchClientTask("Refreshing tree...", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (searchCriterionListFinal.size() > 0) {
                // show with search criteria
                refresh(searchCriterionListFinal);
            } else {
                if (bSpatialMode) {
                    ArrayList searchCrit = new ArrayList();
                    searchCrit.add(getDatabaseSearchPanel().getSpatialOnlyCriteria());
                    // show all
                    refresh(searchCrit);
                } else {
                    // show all
                    refresh(null);
                }
            }
        }
    };
    Hashtable<String, Object> hashTable = new Hashtable<String, Object>();
    if (!bShowAll && getDatabaseSearchPanel().hasRemoteDatabaseSearchDefined()) {
        ClientTaskDispatcher.dispatch(this, hashTable, new AsynchClientTask[] { searchCriteriaTask, refreshTask }, true, false, true, searchCancel, true);
    } else {
        try {
            searchCriteriaTask.run(hashTable);
            refreshTask.run(hashTable);
        } catch (Exception e) {
            e.printStackTrace();
            DialogUtils.showErrorDialog(this, e.getMessage());
        }
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) DatabaseSearchPanel(cbit.vcell.client.desktop.DatabaseSearchPanel) EventObject(java.util.EventObject) DataAccessException(org.vcell.util.DataAccessException) UserCancelException(org.vcell.util.UserCancelException) ProgressDialogListener(org.vcell.util.ProgressDialogListener) SearchCriterion(cbit.vcell.client.desktop.DatabaseSearchPanel.SearchCriterion) EventObject(java.util.EventObject)

Aggregations

ProgressDialogListener (org.vcell.util.ProgressDialogListener)16 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)9 Hashtable (java.util.Hashtable)9 File (java.io.File)8 EventObject (java.util.EventObject)8 ClientTaskStatusSupport (org.vcell.util.ClientTaskStatusSupport)8 IOException (java.io.IOException)4 UserCancelException (org.vcell.util.UserCancelException)4 LocalWorkspace (org.vcell.vmicro.workflow.data.LocalWorkspace)4 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)3 DataAccessException (org.vcell.util.DataAccessException)3 ImportRawTimeSeriesFromVFrapOp (org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp)3 RunBioNetGen (cbit.vcell.client.task.RunBioNetGen)2 RemoteProxyException (cbit.vcell.message.server.bootstrap.client.RemoteProxyVCellConnectionFactory.RemoteProxyException)2 Parameter (cbit.vcell.opt.Parameter)2 BNGExecutorService (cbit.vcell.server.bionetgen.BNGExecutorService)2 PrintWriter (java.io.PrintWriter)2 BigString (org.vcell.util.BigString)2 ImageException (cbit.image.ImageException)1 ROI (cbit.vcell.VirtualMicroscopy.ROI)1