From 76cd5c88c33b161725758b8c300b6bcd74dc52d9 Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Mon, 25 Nov 2024 10:15:03 -0500 Subject: [PATCH] Format Files to Follow Spacing Rules --- .../vcell/client/FieldDataWindowManager.java | 1297 +++--- .../vcell/field/gui/FieldDataGUIPanel.java | 3481 ++++++++--------- .../field/db/FieldDataDBOperationDriver.java | 1017 ++--- 3 files changed, 2870 insertions(+), 2925 deletions(-) diff --git a/vcell-client/src/main/java/cbit/vcell/client/FieldDataWindowManager.java b/vcell-client/src/main/java/cbit/vcell/client/FieldDataWindowManager.java index 135110202e..5bac904246 100644 --- a/vcell-client/src/main/java/cbit/vcell/client/FieldDataWindowManager.java +++ b/vcell-client/src/main/java/cbit/vcell/client/FieldDataWindowManager.java @@ -10,40 +10,6 @@ package cbit.vcell.client; -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.event.ActionEvent; -import java.beans.PropertyChangeEvent; -import java.beans.PropertyChangeListener; -import java.beans.PropertyVetoException; -import java.lang.reflect.Field; -import java.util.Hashtable; -import java.util.List; -import java.util.Map; -import java.util.Vector; - -import javax.swing.JPanel; -import javax.swing.ListSelectionModel; - -import cbit.vcell.solver.*; -import org.vcell.util.DataAccessException; -import org.vcell.util.Issue; -import org.vcell.util.IssueContext; -import org.vcell.util.Matchable; -import org.vcell.util.UserCancelException; -import org.vcell.util.document.BioModelInfo; -import org.vcell.util.document.ExternalDataIdentifier; -import org.vcell.util.document.KeyValue; -import org.vcell.util.document.MathModelInfo; -import org.vcell.util.document.ReferenceQueryResult; -import org.vcell.util.document.ReferenceQuerySpec; -import org.vcell.util.document.User; -import org.vcell.util.document.VCDocument; -import org.vcell.util.document.Version; -import org.vcell.util.document.VersionableRelationship; -import org.vcell.util.document.VersionableType; -import org.vcell.util.document.VersionableTypeVersion; - import cbit.image.VCImageUncompressed; import cbit.rmi.event.DataJobEvent; import cbit.rmi.event.DataJobListenerHolder; @@ -71,638 +37,645 @@ import cbit.vcell.math.MathDescription; import cbit.vcell.math.VariableType; import cbit.vcell.math.VolVariable; -import cbit.vcell.simdata.ClientPDEDataContext; -import cbit.vcell.simdata.DataIdentifier; -import cbit.vcell.simdata.DataListener; -import cbit.vcell.simdata.OutputContext; -import cbit.vcell.simdata.PDEDataContext; -import cbit.vcell.simdata.PDEDataManager; +import cbit.vcell.simdata.*; +import cbit.vcell.solver.*; import cbit.vcell.solvers.CartesianMesh; +import org.vcell.util.*; +import org.vcell.util.document.*; -public class FieldDataWindowManager - extends TopLevelWindowManager - implements PropertyChangeListener,FieldDataDBEventListener,DataJobListenerHolder{ - - public interface DataSymbolCallBack { - void createDataSymbol(ExternalDataIdentifier dataSetID,String fieldDataVarName,VariableType fieldDataVarType,double fieldDataVarTime); - } - - private FieldDataGUIPanel fieldDataGUIPanel; - private ExternalDataIdentifier currentlyViewedEDI; - private OutputFunctionViewer currentlyViewedOutputFunctionViewer; - - - public FieldDataWindowManager(FieldDataGUIPanel fdgp, RequestManager requestManager){ - super(requestManager); - fieldDataGUIPanel = fdgp; - requestManager.getDocumentManager().addFieldDataDBListener(this); - } - public FieldDataGUIPanel getFieldDataGUIPanel(){ - return fieldDataGUIPanel; - } - @Override - public Component getComponent() { - return fieldDataGUIPanel; - } - - @Override - public String getManagerID() { - return ClientMDIManager.FIELDDATA_WINDOW_ID; - } - - @Override - public boolean isRecyclable() { - return true; - } - - public void deleteExternalDataIdentifier(ExternalDataIdentifier deleteExtDataID) throws DataAccessException{ - getRequestManager().getDocumentManager().fieldDataDBOperation( - FieldDataDBOperationSpec.createDeleteExtDataIDSpec(deleteExtDataID)); - if(deleteExtDataID.equals(currentlyViewedEDI)){ - viewData(null); - } - } - public RequestManager getLocalRequestManager(){ - return getRequestManager(); - } - public void updateJTree(){ - fieldDataGUIPanel.updateJTree(getRequestManager()); - } - - - public ClientPDEDataContext getPDEDataContext(ExternalDataIdentifier eDI,OutputContext outputContext) throws DataAccessException{ - return - ((PDEDataManager)getRequestManager().getDataManager(outputContext, eDI, true)).getPDEDataContext(); - } - -public void viewData(final ExternalDataIdentifier eDI){ - - ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent()); - if(eDI != null && eDI.equals(currentlyViewedEDI) && childWindowManager != null && childWindowManager.getChildWindowFromContext(eDI) != null){ - childWindowManager.getChildWindowFromContext(eDI).show(); - } else { - if(currentlyViewedOutputFunctionViewer != null){ - if(getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null){ - getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer()); - } - if(currentlyViewedOutputFunctionViewer != null){ - currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(this); - } - } - if(currentlyViewedOutputFunctionViewer != null){ - ChildWindow childWindow = childWindowManager.getChildWindowFromContext(eDI); - if (childWindow!=null){ - childWindow.close(); - } - } - currentlyViewedEDI = null; - currentlyViewedOutputFunctionViewer = null; - if(eDI == null){ - return; - } - - AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - - @Override - public void run(Hashtable hashTable) throws Exception { - ClientPDEDataContext newPDEDataContext = getPDEDataContext(eDI,new OutputContext(new AnnotatedFunction[0])/*(currentlyViewedOutputFunctionViewer==null?null:currentlyViewedOutputFunctionViewer.getOutputContext())*/); - hashTable.put("newPDEDataContext", newPDEDataContext); - } - }; - AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - - @Override - public void run(Hashtable hashTable) throws Exception { - try{ - PDEDataViewer currentlyViewedPDEDV = new PDEDataViewer(); - ClientPDEDataContext newPDEDataContext = (ClientPDEDataContext)hashTable.get("newPDEDataContext"); - currentlyViewedPDEDV.setPdeDataContext(newPDEDataContext); - newPDEDataContext.addPropertyChangeListener(FieldDataWindowManager.this); - getLocalRequestManager().getAsynchMessageManager().addDataJobListener(currentlyViewedPDEDV); - currentlyViewedOutputFunctionViewer = new OutputFunctionViewer(currentlyViewedPDEDV, FieldDataWindowManager.this,eDI); - - DataViewerManager dvm = new DataViewerManager(){ - public void dataJobMessage(DataJobEvent event){ - } - public void exportMessage(ExportEvent event){ - } - public void addDataListener(DataListener newListener){ - } - public UserPreferences getUserPreferences(){ - return getRequestManager().getUserPreferences(); - } - public void removeDataListener(DataListener newListener){ - } - public void startExport(Component requester,OutputContext outputContext,ExportSpecs exportSpecs){ - getLocalRequestManager().startExport(outputContext, requester, exportSpecs); - } - public void simStatusChanged(SimStatusEvent simStatusEvent) { - } - public User getUser() { - return getRequestManager().getDocumentManager().getUser(); - } - public RequestManager getRequestManager() { - return FieldDataWindowManager.this.getRequestManager(); - } - }; - - try { - currentlyViewedPDEDV.setDataViewerManager(dvm); - } catch (PropertyVetoException e) { - e.printStackTrace(); - } - - ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent()); - currentlyViewedEDI = eDI; - ChildWindow childWindow = childWindowManager.addChildWindow(currentlyViewedOutputFunctionViewer, currentlyViewedEDI, "Field Data Viewer ("+eDI.getName()+")"); - childWindow.setSize(600,500); - childWindow.setIsCenteredOnParent(); - childWindow.show(); - - } catch (Exception e){ - if(currentlyViewedOutputFunctionViewer != null){ - if(getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null){ - getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer()); - } - if(currentlyViewedOutputFunctionViewer != null){ - currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(FieldDataWindowManager.this); - } - } - throw e; - } - } - }; - ClientTaskDispatcher.dispatch(this.getComponent(), new Hashtable(), new AsynchClientTask[] {task1, task2}, false); - } -} -private static class OutputFunctionViewer extends JPanel{ - private PDEDataViewer pdeDataViewer; - private OutputFunctionsPanel outputFunctionsPanel; - private Geometry geom; - private MathDescription mathDescription; - private ExternalDataIdentifier edi; - private FieldDataWindowManager fieldDataWindowManager; - public OutputFunctionViewer(final PDEDataViewer pdeDataViewer,FieldDataWindowManager fieldDataWindowManager,ExternalDataIdentifier edi) throws Exception{ - this.pdeDataViewer = pdeDataViewer; - this.edi = edi; - this.fieldDataWindowManager = fieldDataWindowManager; - this.outputFunctionsPanel = new OutputFunctionsPanel(); - CartesianMesh cartesianMesh = pdeDataViewer.getPdeDataContext().getCartesianMesh(); - VCImageUncompressed vcImage = new VCImageUncompressed(null, new byte[cartesianMesh.getNumVolumeElements()], cartesianMesh.getExtent(), cartesianMesh.getSizeX(),cartesianMesh.getSizeY(),cartesianMesh.getSizeZ()); - this.geom = new Geometry("temp",vcImage); - this.mathDescription = new MathDescription("temp"); - mathDescription.setGeometry(geom); - setMathDescVariables(); - this.pdeDataViewer.setSimNameSimDataID(new SimNameSimDataID("temp", new VCSimulationIdentifier(edi.getKey(), edi.getOwner()),null)); - this.pdeDataViewer.setSimulationModelInfo(new SimulationModelInfo() { - - @Override - public String getVolumeNamePhysiology(int subVolumeID) { - // TODO Auto-generated method stub - return "volPhysiology"; - } - - @Override - public String getVolumeNameGeometry(int subVolumeID) { - // TODO Auto-generated method stub - return "volGeometry"; - } - - @Override - public String getSimulationName() { - // TODO Auto-generated method stub - return "simName"; - } - - @Override - public String getMembraneName(int subVolumeIdIn, int subVolumeIdOut, boolean bFromGeometry) { - // TODO Auto-generated method stub - return "membraneName"; - } - - @Override - public String getContextName() { - // TODO Auto-generated method stub - return "contextName"; - } - - @Override - public DataSymbolMetadataResolver getDataSymbolMetadataResolver(){ - return pdeDataViewer.getSimulationModelInfo().getDataSymbolMetadataResolver(); - } - }); - - SimulationOwner simulationOwner = new SimulationOwner.FieldDataSimOwner() { - private OutputFunctionContext outputFunctionContext = new OutputFunctionContext(this); - { - outputFunctionContext.addPropertyChangeListener(new PropertyChangeListener() { - @Override - public void propertyChange(PropertyChangeEvent evt) { - final String PDEDC_KEY = "PDEDC_KEY"; - AsynchClientTask task1 = new AsynchClientTask("getPDEDataContext...",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - @Override - public void run(Hashtable hashTable) throws Exception { - OutputContext outputContext = OutputFunctionViewer.this.getOutputContext(); - ClientPDEDataContext pdeDataContext = OutputFunctionViewer.this.fieldDataWindowManager.getPDEDataContext(OutputFunctionViewer.this.edi,outputContext); - hashTable.put(PDEDC_KEY, pdeDataContext); - } - }; - AsynchClientTask task2 = new AsynchClientTask("setPDEDataContext...",AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - @Override - public void run(Hashtable hashTable) throws Exception { - OutputFunctionViewer.this.pdeDataViewer.setPdeDataContext((ClientPDEDataContext)hashTable.get(PDEDC_KEY)); - setMathDescVariables(); - } - }; - ClientTaskDispatcher.dispatch(OutputFunctionViewer.this, new Hashtable(), new AsynchClientTask[] {task1,task2},true,false,false,null,true); - } - }); - } - - @Override - public void removePropertyChangeListener(PropertyChangeListener listener) { - // TODO Auto-generated method stub - System.out.println("somebody remove mysimowner listener "+listener); - } - - @Override - public Geometry getGeometry() { - // TODO Auto-generated method stub - return geom; - } - - @Override - public void addPropertyChangeListener(PropertyChangeListener listener) { - // TODO Auto-generated method stub - System.out.println("somebody add mysimowner listener "+listener); - - } - - @Override - public void removeSimulation(Simulation simulation) - throws PropertyVetoException { - // TODO Auto-generated method stub - - } - - @Override - public Simulation[] getSimulations() { - // TODO Auto-generated method stub - return null; - } - - @Override - public OutputFunctionContext getOutputFunctionContext() { - // TODO Auto-generated method stub - return outputFunctionContext; - } - - @Override - public MathOverridesResolver getMathOverridesResolver() { - return null; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return "temp"; - } - - @Override - public MathDescription getMathDescription() { - // TODO Auto-generated method stub - return mathDescription; - } - - @Override - public Simulation copySimulation(Simulation simulation) - throws PropertyVetoException { - // TODO Auto-generated method stub - return null; - } - @Override - public Issue gatherIssueForMathOverride(IssueContext issueContext, Simulation simulation, String name) { - // TODO Auto-generated method stub - return null; - } - - /** - * @throws UnsupportedOperationException (always) - */ - @Override - public UnitInfo getUnitInfo() throws UnsupportedOperationException { - throw new UnsupportedOperationException(); - } - }; - VCDocument fakeVCDocument = new VCDocument(){ - - @Override - public boolean compareEqual(Matchable obj) { - // TODO Auto-generated method stub - return false; - } - - @Override - public String getDescription() { - // TODO Auto-generated method stub - return null; - } - - @Override - public VCDocumentType getDocumentType() { - // TODO Auto-generated method stub - return null; - } - - @Override - public String getName() { - // TODO Auto-generated method stub - return null; - } - - @Override - public Version getVersion() { - // TODO Auto-generated method stub - return null; - } - - @Override - public void refreshDependencies() { - // TODO Auto-generated method stub - - } - - @Override - public void setDescription(String description) - throws PropertyVetoException { - // TODO Auto-generated method stub - - } - - @Override - public void setName(String newName) throws PropertyVetoException { - // TODO Auto-generated method stub - - } - - @Override - public void gatherIssues(IssueContext issueContext, List issueList) { - // TODO Auto-generated method stub - - } - - }; - DocumentWindowManager documentWindowManager = new DocumentWindowManager(pdeDataViewer, fieldDataWindowManager.getRequestManager(), fakeVCDocument){ - - @Override - public void actionPerformed(ActionEvent e) { - // TODO Auto-generated method stub - - } - - @Override - public void simStatusChanged(SimStatusEvent simStatusEvent) { - // TODO Auto-generated method stub - - } - - @Override - public void addResultsFrame(SimulationWindow simWindow) { - // TODO Auto-generated method stub - - } - - @Override - public VCDocument getVCDocument() { - // TODO Auto-generated method stub - return null; - } - - @Override - SimulationWindow haveSimulationWindow( - VCSimulationIdentifier vcSimulationIdentifier) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void resetDocument(VCDocument newDocument) { - // TODO Auto-generated method stub - - } - - @Override - public void updateConnectionStatus(ConnectionStatus connStatus) { - // TODO Auto-generated method stub - - } - - @Override - public boolean isRecyclable() { - // TODO Auto-generated method stub - return false; - } - - @Override - public RequestManager getRequestManager() { - // TODO Auto-generated method stub - return OutputFunctionViewer.this.fieldDataWindowManager.getRequestManager(); - } - - @Override - public DocumentEditor getDocumentEditor() { - return null; - } - - }; - - SimulationWorkspace simulationWorkspace = new SimulationWorkspace(documentWindowManager, simulationOwner); - this.pdeDataViewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(simulationOwner, "temp")); - - setLayout(new BorderLayout()); - add(pdeDataViewer,BorderLayout.CENTER); - add(outputFunctionsPanel,BorderLayout.SOUTH); - outputFunctionsPanel.setSimulationWorkspace(simulationWorkspace); - } - public PDEDataViewer getPDEDataViewer(){ - return pdeDataViewer; - } - public OutputContext getOutputContext() throws Exception{ - Field outputfunctioncontextField = OutputFunctionsPanel.class.getDeclaredField("outputFunctionContext"); - outputfunctioncontextField.setAccessible(true); - OutputFunctionContext outputFunctionContext = (OutputFunctionContext)outputfunctioncontextField.get(outputFunctionsPanel); - OutputContext outputContext = new OutputContext(outputFunctionContext.getOutputFunctionsList().toArray(new AnnotatedFunction[0])); - return outputContext; - } - private void setMathDescVariables() throws Exception{ - AnnotatedFunction[] functions = this.pdeDataViewer.getPdeDataContext().getFunctions(); - for (int i = 0; i < functions.length; i++) { - if(functions[i].getFunctionType().equals(VariableType.VOLUME) && mathDescription.getVariable(functions[i].getName()) == null){ - mathDescription.addVariable(functions[i]); - } - } - DataIdentifier[] dataIds = this.pdeDataViewer.getPdeDataContext().getDataIdentifiers(); - for (int i = 0; i < dataIds.length; i++) { - if(dataIds[i].getVariableType().equals(VariableType.VOLUME) && mathDescription.getVariable(dataIds[i].getName()) == null){ - if(!dataIds[i].isFunction()){ - mathDescription.addVariable(new VolVariable(dataIds[i].getName(), dataIds[i].getDomain())); - } - } - } - } -} - -public void propertyChange(PropertyChangeEvent evt) { - if(evt.getSource() == currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext() && - ( - evt.getPropertyName().equals(PDEDataContext.PROP_CHANGE_FUNC_ADDED) || - evt.getPropertyName().equals(PDEDataContext.PROP_CHANGE_FUNC_REMOVED) - )){ - getFieldDataGUIPanel().refreshExternalDataIdentifierNode(currentlyViewedEDI); - } -} +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.PropertyVetoException; +import java.lang.reflect.Field; +import java.util.Hashtable; +import java.util.List; +import java.util.Vector; +public class FieldDataWindowManager + extends TopLevelWindowManager + implements PropertyChangeListener, FieldDataDBEventListener, DataJobListenerHolder { + + public interface DataSymbolCallBack { + void createDataSymbol(ExternalDataIdentifier dataSetID, String fieldDataVarName, VariableType fieldDataVarType, double fieldDataVarTime); + } + + private FieldDataGUIPanel fieldDataGUIPanel; + private ExternalDataIdentifier currentlyViewedEDI; + private OutputFunctionViewer currentlyViewedOutputFunctionViewer; + + + public FieldDataWindowManager(FieldDataGUIPanel fdgp, RequestManager requestManager) { + super(requestManager); + fieldDataGUIPanel = fdgp; + requestManager.getDocumentManager().addFieldDataDBListener(this); + } + + public FieldDataGUIPanel getFieldDataGUIPanel() { + return fieldDataGUIPanel; + } + + @Override + public Component getComponent() { + return fieldDataGUIPanel; + } + + @Override + public String getManagerID() { + return ClientMDIManager.FIELDDATA_WINDOW_ID; + } + + @Override + public boolean isRecyclable() { + return true; + } + + public void deleteExternalDataIdentifier(ExternalDataIdentifier deleteExtDataID) throws DataAccessException { + getRequestManager().getDocumentManager().fieldDataDBOperation( + FieldDataDBOperationSpec.createDeleteExtDataIDSpec(deleteExtDataID)); + if (deleteExtDataID.equals(currentlyViewedEDI)) { + viewData(null); + } + } + + public RequestManager getLocalRequestManager() { + return getRequestManager(); + } + + public void updateJTree() { + fieldDataGUIPanel.updateJTree(getRequestManager()); + } + + + public ClientPDEDataContext getPDEDataContext(ExternalDataIdentifier eDI, OutputContext outputContext) throws DataAccessException { + return + ((PDEDataManager) getRequestManager().getDataManager(outputContext, eDI, true)).getPDEDataContext(); + } + + public void viewData(final ExternalDataIdentifier eDI) { + + ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent()); + if (eDI != null && eDI.equals(currentlyViewedEDI) && childWindowManager != null && childWindowManager.getChildWindowFromContext(eDI) != null) { + childWindowManager.getChildWindowFromContext(eDI).show(); + } else { + if (currentlyViewedOutputFunctionViewer != null) { + if (getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null) { + getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer()); + } + if (currentlyViewedOutputFunctionViewer != null) { + currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(this); + } + } + if (currentlyViewedOutputFunctionViewer != null) { + ChildWindow childWindow = childWindowManager.getChildWindowFromContext(eDI); + if (childWindow != null) { + childWindow.close(); + } + } + currentlyViewedEDI = null; + currentlyViewedOutputFunctionViewer = null; + if (eDI == null) { + return; + } + + AsynchClientTask task1 = new AsynchClientTask("retrieve data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + ClientPDEDataContext newPDEDataContext = getPDEDataContext(eDI, new OutputContext(new AnnotatedFunction[0])/*(currentlyViewedOutputFunctionViewer==null?null:currentlyViewedOutputFunctionViewer.getOutputContext())*/); + hashTable.put("newPDEDataContext", newPDEDataContext); + } + }; + AsynchClientTask task2 = new AsynchClientTask("show data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + try { + PDEDataViewer currentlyViewedPDEDV = new PDEDataViewer(); + ClientPDEDataContext newPDEDataContext = (ClientPDEDataContext) hashTable.get("newPDEDataContext"); + currentlyViewedPDEDV.setPdeDataContext(newPDEDataContext); + newPDEDataContext.addPropertyChangeListener(FieldDataWindowManager.this); + getLocalRequestManager().getAsynchMessageManager().addDataJobListener(currentlyViewedPDEDV); + currentlyViewedOutputFunctionViewer = new OutputFunctionViewer(currentlyViewedPDEDV, FieldDataWindowManager.this, eDI); + + DataViewerManager dvm = new DataViewerManager() { + public void dataJobMessage(DataJobEvent event) { + } + + public void exportMessage(ExportEvent event) { + } + + public void addDataListener(DataListener newListener) { + } + + public UserPreferences getUserPreferences() { + return getRequestManager().getUserPreferences(); + } + + public void removeDataListener(DataListener newListener) { + } + + public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) { + getLocalRequestManager().startExport(outputContext, requester, exportSpecs); + } + + public void simStatusChanged(SimStatusEvent simStatusEvent) { + } + + public User getUser() { + return getRequestManager().getDocumentManager().getUser(); + } + + public RequestManager getRequestManager() { + return FieldDataWindowManager.this.getRequestManager(); + } + }; + + try { + currentlyViewedPDEDV.setDataViewerManager(dvm); + } catch (PropertyVetoException e) { + e.printStackTrace(); + } + + ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(getComponent()); + currentlyViewedEDI = eDI; + ChildWindow childWindow = childWindowManager.addChildWindow(currentlyViewedOutputFunctionViewer, currentlyViewedEDI, "Field Data Viewer (" + eDI.getName() + ")"); + childWindow.setSize(600, 500); + childWindow.setIsCenteredOnParent(); + childWindow.show(); + + } catch (Exception e) { + if (currentlyViewedOutputFunctionViewer != null) { + if (getLocalRequestManager() != null && getLocalRequestManager().getAsynchMessageManager() != null) { + getLocalRequestManager().getAsynchMessageManager().removeDataJobListener(currentlyViewedOutputFunctionViewer.getPDEDataViewer()); + } + if (currentlyViewedOutputFunctionViewer != null) { + currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext().removePropertyChangeListener(FieldDataWindowManager.this); + } + } + throw e; + } + } + }; + ClientTaskDispatcher.dispatch(this.getComponent(), new Hashtable(), new AsynchClientTask[]{task1, task2}, false); + } + } + + private static class OutputFunctionViewer extends JPanel { + private PDEDataViewer pdeDataViewer; + private OutputFunctionsPanel outputFunctionsPanel; + private Geometry geom; + private MathDescription mathDescription; + private ExternalDataIdentifier edi; + private FieldDataWindowManager fieldDataWindowManager; + + public OutputFunctionViewer(final PDEDataViewer pdeDataViewer, FieldDataWindowManager fieldDataWindowManager, ExternalDataIdentifier edi) throws Exception { + this.pdeDataViewer = pdeDataViewer; + this.edi = edi; + this.fieldDataWindowManager = fieldDataWindowManager; + this.outputFunctionsPanel = new OutputFunctionsPanel(); + CartesianMesh cartesianMesh = pdeDataViewer.getPdeDataContext().getCartesianMesh(); + VCImageUncompressed vcImage = new VCImageUncompressed(null, new byte[cartesianMesh.getNumVolumeElements()], cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ()); + this.geom = new Geometry("temp", vcImage); + this.mathDescription = new MathDescription("temp"); + mathDescription.setGeometry(geom); + setMathDescVariables(); + this.pdeDataViewer.setSimNameSimDataID(new SimNameSimDataID("temp", new VCSimulationIdentifier(edi.getKey(), edi.getOwner()), null)); + this.pdeDataViewer.setSimulationModelInfo(new SimulationModelInfo() { + + @Override + public String getVolumeNamePhysiology(int subVolumeID) { + return "volPhysiology"; + } + + @Override + public String getVolumeNameGeometry(int subVolumeID) { + return "volGeometry"; + } + + @Override + public String getSimulationName() { + return "simName"; + } + + @Override + public String getMembraneName(int subVolumeIdIn, int subVolumeIdOut, boolean bFromGeometry) { + return "membraneName"; + } + + @Override + public String getContextName() { + return "contextName"; + } + + @Override + public DataSymbolMetadataResolver getDataSymbolMetadataResolver() { + return pdeDataViewer.getSimulationModelInfo().getDataSymbolMetadataResolver(); + } + }); + + SimulationOwner simulationOwner = new SimulationOwner.FieldDataSimOwner() { + private OutputFunctionContext outputFunctionContext = new OutputFunctionContext(this); + + { + outputFunctionContext.addPropertyChangeListener(new PropertyChangeListener() { + @Override + public void propertyChange(PropertyChangeEvent evt) { + final String PDEDC_KEY = "PDEDC_KEY"; + AsynchClientTask task1 = new AsynchClientTask("getPDEDataContext...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + @Override + public void run(Hashtable hashTable) throws Exception { + OutputContext outputContext = OutputFunctionViewer.this.getOutputContext(); + ClientPDEDataContext pdeDataContext = OutputFunctionViewer.this.fieldDataWindowManager.getPDEDataContext(OutputFunctionViewer.this.edi, outputContext); + hashTable.put(PDEDC_KEY, pdeDataContext); + } + }; + AsynchClientTask task2 = new AsynchClientTask("setPDEDataContext...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + @Override + public void run(Hashtable hashTable) throws Exception { + OutputFunctionViewer.this.pdeDataViewer.setPdeDataContext((ClientPDEDataContext) hashTable.get(PDEDC_KEY)); + setMathDescVariables(); + } + }; + ClientTaskDispatcher.dispatch(OutputFunctionViewer.this, new Hashtable(), new AsynchClientTask[]{task1, task2}, true, false, false, null, true); + } + }); + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener listener) { + System.out.println("somebody remove mysimowner listener " + listener); + } + + @Override + public Geometry getGeometry() { + return geom; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener listener) { + System.out.println("somebody add mysimowner listener " + listener); + + } + + @Override + public void removeSimulation(Simulation simulation) + throws PropertyVetoException { + } + + @Override + public Simulation[] getSimulations() { + return null; + } + + @Override + public OutputFunctionContext getOutputFunctionContext() { + return outputFunctionContext; + } + + @Override + public MathOverridesResolver getMathOverridesResolver() { + return null; + } + + @Override + public String getName() { + return "temp"; + } + + @Override + public MathDescription getMathDescription() { + return mathDescription; + } + + @Override + public Simulation copySimulation(Simulation simulation) + throws PropertyVetoException { + return null; + } + + @Override + public Issue gatherIssueForMathOverride(IssueContext issueContext, Simulation simulation, String name) { + return null; + } + + /** + * @throws UnsupportedOperationException (always) + */ + @Override + public UnitInfo getUnitInfo() throws UnsupportedOperationException { + throw new UnsupportedOperationException(); + } + }; + VCDocument fakeVCDocument = new VCDocument() { + + @Override + public boolean compareEqual(Matchable obj) { + return false; + } + + @Override + public String getDescription() { + return null; + } + + @Override + public VCDocumentType getDocumentType() { + return null; + } + + @Override + public String getName() { + return null; + } + + @Override + public Version getVersion() { + return null; + } + + @Override + public void refreshDependencies() { + + } + + @Override + public void setDescription(String description) + throws PropertyVetoException { + // TODO Auto-generated method stub + + } + + @Override + public void setName(String newName) throws PropertyVetoException { + // TODO Auto-generated method stub + + } + + @Override + public void gatherIssues(IssueContext issueContext, List issueList) { + // TODO Auto-generated method stub + + } + + }; + DocumentWindowManager documentWindowManager = new DocumentWindowManager(pdeDataViewer, fieldDataWindowManager.getRequestManager(), fakeVCDocument) { + + @Override + public void actionPerformed(ActionEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void simStatusChanged(SimStatusEvent simStatusEvent) { + // TODO Auto-generated method stub + + } + + @Override + public void addResultsFrame(SimulationWindow simWindow) { + // TODO Auto-generated method stub + + } + + @Override + public VCDocument getVCDocument() { + // TODO Auto-generated method stub + return null; + } + + @Override + SimulationWindow haveSimulationWindow( + VCSimulationIdentifier vcSimulationIdentifier) { + // TODO Auto-generated method stub + return null; + } + + @Override + public void resetDocument(VCDocument newDocument) { + // TODO Auto-generated method stub + + } + + @Override + public void updateConnectionStatus(ConnectionStatus connStatus) { + // TODO Auto-generated method stub + + } + + @Override + public boolean isRecyclable() { + // TODO Auto-generated method stub + return false; + } + + @Override + public RequestManager getRequestManager() { + // TODO Auto-generated method stub + return OutputFunctionViewer.this.fieldDataWindowManager.getRequestManager(); + } + + @Override + public DocumentEditor getDocumentEditor() { + return null; + } + + }; + + SimulationWorkspace simulationWorkspace = new SimulationWorkspace(documentWindowManager, simulationOwner); + this.pdeDataViewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(simulationOwner, "temp")); + + setLayout(new BorderLayout()); + add(pdeDataViewer, BorderLayout.CENTER); + add(outputFunctionsPanel, BorderLayout.SOUTH); + outputFunctionsPanel.setSimulationWorkspace(simulationWorkspace); + } + + public PDEDataViewer getPDEDataViewer() { + return pdeDataViewer; + } + + public OutputContext getOutputContext() throws Exception { + Field outputfunctioncontextField = OutputFunctionsPanel.class.getDeclaredField("outputFunctionContext"); + outputfunctioncontextField.setAccessible(true); + OutputFunctionContext outputFunctionContext = (OutputFunctionContext) outputfunctioncontextField.get(outputFunctionsPanel); + OutputContext outputContext = new OutputContext(outputFunctionContext.getOutputFunctionsList().toArray(new AnnotatedFunction[0])); + return outputContext; + } + + private void setMathDescVariables() throws Exception { + AnnotatedFunction[] functions = this.pdeDataViewer.getPdeDataContext().getFunctions(); + for (int i = 0; i < functions.length; i++) { + if (functions[i].getFunctionType().equals(VariableType.VOLUME) && mathDescription.getVariable(functions[i].getName()) == null) { + mathDescription.addVariable(functions[i]); + } + } + DataIdentifier[] dataIds = this.pdeDataViewer.getPdeDataContext().getDataIdentifiers(); + for (int i = 0; i < dataIds.length; i++) { + if (dataIds[i].getVariableType().equals(VariableType.VOLUME) && mathDescription.getVariable(dataIds[i].getName()) == null) { + if (!dataIds[i].isFunction()) { + mathDescription.addVariable(new VolVariable(dataIds[i].getName(), dataIds[i].getDomain())); + } + } + } + } + } + + public void propertyChange(PropertyChangeEvent evt) { + if (evt.getSource() == currentlyViewedOutputFunctionViewer.getPDEDataViewer().getPdeDataContext() && + ( + evt.getPropertyName().equals(PDEDataContext.PROP_CHANGE_FUNC_ADDED) || + evt.getPropertyName().equals(PDEDataContext.PROP_CHANGE_FUNC_REMOVED) + )) { + getFieldDataGUIPanel().refreshExternalDataIdentifierNode(currentlyViewedEDI); + } + } + + + public boolean findReferencingModels(final ExternalDataIdentifier targetExtDataID, boolean bShowReferencingModelsList) + throws DataAccessException, UserCancelException { + + ReferenceQuerySpec rqs = new ReferenceQuerySpec(targetExtDataID); + + ReferenceQueryResult rqr = getRequestManager().getDocumentManager().findReferences(rqs); + VersionableTypeVersion[] dependants = null; + Hashtable choices = new Hashtable(); + boolean bDanglingReferences = false; + + VersionableType bioModelType = VersionableType.BioModelMetaData; + VersionableType mathModelType = VersionableType.MathModelMetaData; + + if (rqr != null) { + dependants = (rqr.getVersionableFamily().bDependants() ? rqr.getVersionableFamily().getUniqueDependants() : null); + if (dependants != null) { + for (int i = 0; i < dependants.length; i += 1) { + boolean isBioModel = dependants[i].getVType().equals(bioModelType); + boolean isTop = isBioModel || dependants[i].getVType().equals(mathModelType); + if (isTop) { + VersionableRelationship[] vrArr2 = rqr.getVersionableFamily().getDependantRelationships(); + for (int j = 0; j < vrArr2.length; j += 1) { + if ((vrArr2[j].from() == dependants[i]) && + vrArr2[j].to().getVType().equals((isBioModel ? VersionableType.SimulationContext : VersionableType.MathDescription))) { + for (int k = 0; k < vrArr2.length; k += 1) { + boolean bAdd = false; + if (k == j && vrArr2[k].from().getVType().equals(mathModelType)) { + bAdd = true; + } + if ((vrArr2[k].from() == vrArr2[j].to()) && + vrArr2[k].to().getVType().equals(VersionableType.MathDescription)) { + bAdd = true; + } + if (bAdd) { + choices.put(dependants[i], + new String[]{ + dependants[i].getVersion().getName(), + (isBioModel ? bioModelType.getTypeName() : mathModelType.getTypeName()), + (isBioModel ? vrArr2[k].from().getVersion().getName() : ""), + dependants[i].getVersion().getVersionKey().toString() + } + ); + } + } + } + } + } + } + bDanglingReferences = (choices.size() == 0); + } else { + bDanglingReferences = true; + } + } -public boolean findReferencingModels(final ExternalDataIdentifier targetExtDataID,boolean bShowReferencingModelsList) - throws DataAccessException,UserCancelException{ - - ReferenceQuerySpec rqs = new ReferenceQuerySpec(targetExtDataID); - - ReferenceQueryResult rqr = getRequestManager().getDocumentManager().findReferences(rqs); - VersionableTypeVersion[] dependants = null; - Hashtable choices = new Hashtable(); - boolean bDanglingReferences = false; - - VersionableType bioModelType = VersionableType.BioModelMetaData; - VersionableType mathModelType = VersionableType.MathModelMetaData; - - if(rqr != null){ - dependants = (rqr.getVersionableFamily().bDependants()?rqr.getVersionableFamily().getUniqueDependants():null); - if(dependants != null){ - for(int i=0;i 0 || fdfor != null){ - bHasReferences = true; - if(bShowReferencingModelsList){ - String[] columnNames = new String[] {"Model","Type","Description"}; - Vector varTypeV = new Vector(); - Vector keyValV = new Vector(); - Vector choicesV= new Vector(); - String[][] modelListData = choices.values().toArray(new String[0][0]); - for (int i = 0; i < modelListData.length; i++) { - choicesV.add(new String[]{modelListData[i][0], modelListData[i][1], - "Model Variable - "+(modelListData[i][2].length() == 0?"":"App='"+modelListData[i][2]+"'")+" version["+modelListData[i][3]+"]" - } - ); - varTypeV.add((modelListData[i][1].equals(bioModelType.getTypeName())?bioModelType:mathModelType)); - keyValV.add(new KeyValue(modelListData[i][3])); - } - for (int i = 0; fdfor != null && i < fdfor.dependantFunctionInfo.length; i++) { - String functionNames = ""; - for (int j = 0; j < fdfor.dependantFunctionInfo[i].funcNames.length; j++) { - functionNames+=(j>0?",":"")+fdfor.dependantFunctionInfo[i].funcNames[j]; - } - choicesV.add(new String[] { - fdfor.dependantFunctionInfo[i].referenceSourceName, - fdfor.dependantFunctionInfo[i].referenceSourceType, - "Data Viewer Function(s) '"+functionNames+"' - "+ - (fdfor.dependantFunctionInfo[i].applicationName == null?"":"App='"+fdfor.dependantFunctionInfo[i].applicationName+"' ")+ - (fdfor.dependantFunctionInfo[i].simulationName == null?"":"Sim='"+fdfor.dependantFunctionInfo[i].simulationName+"' ")+ - "version["+fdfor.dependantFunctionInfo[i].refSourceVersionDate+"]" - } - ); - if(fdfor.dependantFunctionInfo[i].referenceSourceType.equals(FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME)){ - varTypeV.add(null); - }else if(fdfor.dependantFunctionInfo[i].referenceSourceType.equals(bioModelType.getTypeName())){ - varTypeV.add(bioModelType); - }else if(fdfor.dependantFunctionInfo[i].referenceSourceType.equals(mathModelType.getTypeName())){ - varTypeV.add(mathModelType); - }else{ - throw new IllegalArgumentException("Unknown reference source type "+fdfor.dependantFunctionInfo[i].referenceSourceType); - } - keyValV.add(fdfor.dependantFunctionInfo[i].refSourceVersionKey); - } - int[] selectionArr = PopupGenerator.showComponentOKCancelTableList( - getComponent(), "References to Field Data (Select To Open) "+targetExtDataID.getName(), - columnNames, choicesV.toArray(new String[0][0]), ListSelectionModel.SINGLE_SELECTION); - if(selectionArr != null && selectionArr.length > 0){ - if(varTypeV.elementAt(selectionArr[0]) != null){ - if(varTypeV.elementAt(selectionArr[0]).equals(bioModelType)){ - BioModelInfo bmi = getRequestManager().getDocumentManager().getBioModelInfo(keyValV.elementAt(selectionArr[0])); - getRequestManager().openDocument(bmi,FieldDataWindowManager.this,true); - }else if(varTypeV.elementAt(selectionArr[0]).equals(mathModelType)){ - MathModelInfo mmi = getRequestManager().getDocumentManager().getMathModelInfo(keyValV.elementAt(selectionArr[0])); - getRequestManager().openDocument(mmi,FieldDataWindowManager.this,true); - }else{ - throw new IllegalArgumentException("Not expecting varType "+varTypeV.elementAt(selectionArr[0])); - } - }else{ - PopupGenerator.showInfoDialog(this, "use FiledDataManager to view FieldData '" + choicesV.elementAt(selectionArr[0])[0]+"'"); - } - } - } - }else{ - if(!bDanglingReferences){ - bHasReferences = false; - if(bShowReferencingModelsList){ - PopupGenerator.showInfoDialog(this, "No Model references found for Field Data "+targetExtDataID.getName()); - } - }else{ - bHasReferences = true; - if(bShowReferencingModelsList){ - PopupGenerator.showInfoDialog(this, "No current Model references found.\n"+ - "Field Data has internal database references from\n"+ - "previously linked Model(s) that have been deleted.\n"+ - "Note: Field Data '"+targetExtDataID.getName()+"' is not deletable\n"+ - "until database is culled (daily)."); - } - } - } - return bHasReferences; -} -public void fieldDataDBEvent(FieldDataDBEvent fieldDataDBEvent) { - updateJTree(); - -} + FieldDataFileOperationResults fdfor = null; + + boolean bHasReferences = false; + if (choices.size() > 0 || fdfor != null) { + bHasReferences = true; + if (bShowReferencingModelsList) { + String[] columnNames = new String[]{"Model", "Type", "Description"}; + Vector varTypeV = new Vector(); + Vector keyValV = new Vector(); + Vector choicesV = new Vector(); + String[][] modelListData = choices.values().toArray(new String[0][0]); + for (int i = 0; i < modelListData.length; i++) { + choicesV.add(new String[]{modelListData[i][0], modelListData[i][1], + "Model Variable - " + (modelListData[i][2].length() == 0 ? "" : "App='" + modelListData[i][2] + "'") + " version[" + modelListData[i][3] + "]" + } + ); + varTypeV.add((modelListData[i][1].equals(bioModelType.getTypeName()) ? bioModelType : mathModelType)); + keyValV.add(new KeyValue(modelListData[i][3])); + } + for (int i = 0; fdfor != null && i < fdfor.dependantFunctionInfo.length; i++) { + String functionNames = ""; + for (int j = 0; j < fdfor.dependantFunctionInfo[i].funcNames.length; j++) { + functionNames += (j > 0 ? "," : "") + fdfor.dependantFunctionInfo[i].funcNames[j]; + } + choicesV.add(new String[]{ + fdfor.dependantFunctionInfo[i].referenceSourceName, + fdfor.dependantFunctionInfo[i].referenceSourceType, + "Data Viewer Function(s) '" + functionNames + "' - " + + (fdfor.dependantFunctionInfo[i].applicationName == null ? "" : "App='" + fdfor.dependantFunctionInfo[i].applicationName + "' ") + + (fdfor.dependantFunctionInfo[i].simulationName == null ? "" : "Sim='" + fdfor.dependantFunctionInfo[i].simulationName + "' ") + + "version[" + fdfor.dependantFunctionInfo[i].refSourceVersionDate + "]" + } + ); + if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME)) { + varTypeV.add(null); + } else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(bioModelType.getTypeName())) { + varTypeV.add(bioModelType); + } else if (fdfor.dependantFunctionInfo[i].referenceSourceType.equals(mathModelType.getTypeName())) { + varTypeV.add(mathModelType); + } else { + throw new IllegalArgumentException("Unknown reference source type " + fdfor.dependantFunctionInfo[i].referenceSourceType); + } + keyValV.add(fdfor.dependantFunctionInfo[i].refSourceVersionKey); + } + int[] selectionArr = PopupGenerator.showComponentOKCancelTableList( + getComponent(), "References to Field Data (Select To Open) " + targetExtDataID.getName(), + columnNames, choicesV.toArray(new String[0][0]), ListSelectionModel.SINGLE_SELECTION); + if (selectionArr != null && selectionArr.length > 0) { + if (varTypeV.elementAt(selectionArr[0]) != null) { + if (varTypeV.elementAt(selectionArr[0]).equals(bioModelType)) { + BioModelInfo bmi = getRequestManager().getDocumentManager().getBioModelInfo(keyValV.elementAt(selectionArr[0])); + getRequestManager().openDocument(bmi, FieldDataWindowManager.this, true); + } else if (varTypeV.elementAt(selectionArr[0]).equals(mathModelType)) { + MathModelInfo mmi = getRequestManager().getDocumentManager().getMathModelInfo(keyValV.elementAt(selectionArr[0])); + getRequestManager().openDocument(mmi, FieldDataWindowManager.this, true); + } else { + throw new IllegalArgumentException("Not expecting varType " + varTypeV.elementAt(selectionArr[0])); + } + } else { + PopupGenerator.showInfoDialog(this, "use FiledDataManager to view FieldData '" + choicesV.elementAt(selectionArr[0])[0] + "'"); + } + } + } + } else { + if (!bDanglingReferences) { + bHasReferences = false; + if (bShowReferencingModelsList) { + PopupGenerator.showInfoDialog(this, "No Model references found for Field Data " + targetExtDataID.getName()); + } + } else { + bHasReferences = true; + if (bShowReferencingModelsList) { + PopupGenerator.showInfoDialog(this, "No current Model references found.\n" + + "Field Data has internal database references from\n" + + "previously linked Model(s) that have been deleted.\n" + + "Note: Field Data '" + targetExtDataID.getName() + "' is not deletable\n" + + "until database is culled (daily)."); + } + } + } + return bHasReferences; + } + + public void fieldDataDBEvent(FieldDataDBEvent fieldDataDBEvent) { + updateJTree(); + + } } diff --git a/vcell-client/src/main/java/cbit/vcell/field/gui/FieldDataGUIPanel.java b/vcell-client/src/main/java/cbit/vcell/field/gui/FieldDataGUIPanel.java index b9e264192f..cf8f6356d1 100644 --- a/vcell-client/src/main/java/cbit/vcell/field/gui/FieldDataGUIPanel.java +++ b/vcell-client/src/main/java/cbit/vcell/field/gui/FieldDataGUIPanel.java @@ -81,1781 +81,1726 @@ import cbit.vcell.solver.SimulationInfo; import cbit.vcell.solvers.CartesianMesh; -public class FieldDataGUIPanel extends JPanel{ - - private static final String FIELD_DATA_INFO = "Field Data Info"; - public static final String FIELD_NAME = "fieldName"; - public static final String USER_DEFINED_FDOS = "userDefinedFDOS"; - final int modePslidExperimentalData = 0; - final int modePslidGeneratedModel = 1; - // - public static final String LIST_NODE_VAR_LABEL = "Variables"; - // - private JPopupMenu jPopupMenu = new JPopupMenu(); - private static final int COPY_CSV = 0; - private static final int COPY_NL = 1; - private static final int COPY_CRNL = 2; - private static final int COPY_SPACE = 3; - // - private class InitializedRootNode { - private String rootNodeString; - public InitializedRootNode(String argRNS){ - rootNodeString = argRNS; - } - public String toString(){ - return rootNodeString; - } - } - - private static class FieldDataMainList { - public ExternalDataIdentifier externalDataIdentifier; - public String extDataAnnot; - public FieldDataMainList(ExternalDataIdentifier argExternalDataIdentifier,String argExtDataAnnot){ - externalDataIdentifier = argExternalDataIdentifier; - extDataAnnot = argExtDataAnnot; - } - public String toString(){ - return externalDataIdentifier.getName(); - } - } - - private static class FieldDataVarMainList { - public FieldDataVarMainList(){ - } - public String toString(){ - return LIST_NODE_VAR_LABEL; - } - } - - private class FieldDataVarList { - public DataIdentifier dataIdentifier; - private String descr; - public FieldDataVarList(DataIdentifier argDataIdentifier){ - dataIdentifier = argDataIdentifier; - if(dataIdentifier.getVariableType().compareEqual(VariableType.VOLUME)|| - dataIdentifier.getVariableType().compareEqual(VariableType.VOLUME_REGION)){ - descr = "(Vol"+(dataIdentifier.isFunction()?"Fnc":"")+") "+dataIdentifier.getName(); - }else if(dataIdentifier.getVariableType().compareEqual(VariableType.MEMBRANE) || - dataIdentifier.getVariableType().compareEqual(VariableType.MEMBRANE_REGION)){ - descr = "(Mem"+(dataIdentifier.isFunction()?"Fnc":"")+") "+dataIdentifier.getName(); - }else{ - descr = "(---"+(dataIdentifier.isFunction()?"Fnc":"")+") "+dataIdentifier.getName(); - } - } - public String toString(){ - return descr; - } - } - - private class FieldDataTimeList { - public double[] times; - private String descr; - public FieldDataTimeList(double[] argTimes){ - times = argTimes; - descr = - "Times ( "+times.length+" ) Begin="+times[0]+ - " End="+times[times.length-1]; - } - public String toString(){ - return descr; - } - } - - private class FieldDataIDList { -// public KeyValue key = null; - private String descr; - public FieldDataIDList(KeyValue k){ +public class FieldDataGUIPanel extends JPanel { + + private static final String FIELD_DATA_INFO = "Field Data Info"; + public static final String FIELD_NAME = "fieldName"; + public static final String USER_DEFINED_FDOS = "userDefinedFDOS"; + // + public static final String LIST_NODE_VAR_LABEL = "Variables"; + // + private final JPopupMenu jPopupMenu = new JPopupMenu(); + private static final int COPY_CSV = 0; + private static final int COPY_NL = 1; + private static final int COPY_CRNL = 2; + private static final int COPY_SPACE = 3; + + // + private static class InitializedRootNode { + private final String rootNodeString; + + public InitializedRootNode(String argRNS) { + rootNodeString = argRNS; + } + + public String toString() { + return rootNodeString; + } + } + + private static class FieldDataMainList { + public ExternalDataIdentifier externalDataIdentifier; + public String extDataAnnot; + + public FieldDataMainList(ExternalDataIdentifier argExternalDataIdentifier, String argExtDataAnnot) { + externalDataIdentifier = argExternalDataIdentifier; + extDataAnnot = argExtDataAnnot; + } + + public String toString() { + return externalDataIdentifier.getName(); + } + } + + private static class FieldDataVarMainList { + public FieldDataVarMainList() { + } + + public String toString() { + return LIST_NODE_VAR_LABEL; + } + } + + private static class FieldDataVarList { + public DataIdentifier dataIdentifier; + private final String descr; + + public FieldDataVarList(DataIdentifier argDataIdentifier) { + dataIdentifier = argDataIdentifier; + if (dataIdentifier.getVariableType().compareEqual(VariableType.VOLUME) || + dataIdentifier.getVariableType().compareEqual(VariableType.VOLUME_REGION)) { + descr = "(Vol" + (dataIdentifier.isFunction() ? "Fnc" : "") + ") " + dataIdentifier.getName(); + } else if (dataIdentifier.getVariableType().compareEqual(VariableType.MEMBRANE) || + dataIdentifier.getVariableType().compareEqual(VariableType.MEMBRANE_REGION)) { + descr = "(Mem" + (dataIdentifier.isFunction() ? "Fnc" : "") + ") " + dataIdentifier.getName(); + } else { + descr = "(---" + (dataIdentifier.isFunction() ? "Fnc" : "") + ") " + dataIdentifier.getName(); + } + } + + public String toString() { + return descr; + } + } + + private static class FieldDataTimeList { + public double[] times; + private final String descr; + + public FieldDataTimeList(double[] argTimes) { + times = argTimes; + descr = + "Times ( " + times.length + " ) Begin=" + times[0] + + " End=" + times[times.length - 1]; + } + + public String toString() { + return descr; + } + } + + private static class FieldDataIDList { + // public KeyValue key = null; + private final String descr; + + public FieldDataIDList(KeyValue k) { // this.key = k; - this.descr ="Key (" + k + ")"; - } - public String toString(){ - return descr; - } - } - - private class FieldDataISizeList { - public ISize isize; - private String descr; - public FieldDataISizeList(ISize arg){ - isize = arg; - descr ="Size ( "+ - isize.getX()+" , "+ - isize.getY()+" , "+ - isize.getZ()+" )"; - } - public String toString(){ - return descr; - } - } - - private class FieldDataOriginList { - public Origin origin; - private String descr; - public FieldDataOriginList(Origin arg){ - origin = arg; - descr ="Origin ( "+ - origin.getX()+" , "+ - origin.getY()+" , "+ - origin.getZ()+" )"; - } - public String toString(){ - return descr; - } - } - - private class FieldDataExtentList { - public Extent extent; - private String descr; - public FieldDataExtentList(Extent arg){ - extent = arg; - descr ="Extent ( "+ - extent.getX()+" , "+ - extent.getY()+" , "+ - extent.getZ()+" )"; - } - public String toString(){ - return descr; - } - } - - - private FieldDataWindowManager fieldDataWindowManager; - // - private javax.swing.JButton ivjJButtonFDDelete = null; - private javax.swing.JPanel ivjJPanel1 = null; - private javax.swing.JPanel normalTopPanel = null; - private javax.swing.JButton ivjJButtonFDView = null; - private javax.swing.JTree ivjJTree1 = null; - IvjEventHandler ivjEventHandler = new IvjEventHandler(); - private javax.swing.JScrollPane ivjJScrollPane1 = null; - private javax.swing.JButton ivjJButtonFDCopyRef = null; - private JButton jButtonFindRefModel = null; - private JPanel jPanel = null; - private JButton jButtonCreateGeom = null; - private JPanel jPanel1 = null; - private JButton jButtonViewAnnot = null; - class IvjEventHandler implements ActionListener,TreeExpansionListener, javax.swing.event.TreeSelectionListener { - public void actionPerformed(java.awt.event.ActionEvent e) { - if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDDelete()) - connEtoC7(e); - if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDCopyRef()) - connEtoC8(e); - if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDView()) - connEtoC10(e); - if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDCreate()) - if(getCreateJComboBox().getSelectedItem().equals(FROM_SIM)){ - jButtonFDFromSim_ActionPerformed(e); - }else if(getCreateJComboBox().getSelectedItem().equals(FROM_FILE)){ - jButtonFDFromFile_ActionPerformed(e); - } + this.descr = "Key (" + k + ")"; + } + + public String toString() { + return descr; + } + } + + private static class FieldDataISizeList { + public ISize isize; + private final String descr; + + public FieldDataISizeList(ISize arg) { + isize = arg; + descr = "Size ( " + + isize.getX() + " , " + + isize.getY() + " , " + + isize.getZ() + " )"; + } + + public String toString() { + return descr; + } + } + + private static class FieldDataOriginList { + public Origin origin; + private final String descr; + + public FieldDataOriginList(Origin arg) { + origin = arg; + descr = "Origin ( " + + origin.getX() + " , " + + origin.getY() + " , " + + origin.getZ() + " )"; + } + + public String toString() { + return descr; + } + } + + private static class FieldDataExtentList { + public Extent extent; + private final String descr; + + public FieldDataExtentList(Extent arg) { + extent = arg; + descr = "Extent ( " + + extent.getX() + " , " + + extent.getY() + " , " + + extent.getZ() + " )"; + } + + public String toString() { + return descr; + } + } + + + private FieldDataWindowManager fieldDataWindowManager; + // + private javax.swing.JButton ivjJButtonFDDelete = null; + private javax.swing.JPanel ivjJPanel1 = null; + private javax.swing.JPanel normalTopPanel = null; + private javax.swing.JButton ivjJButtonFDView = null; + private javax.swing.JTree ivjJTree1 = null; + IvjEventHandler ivjEventHandler = new IvjEventHandler(); + private javax.swing.JScrollPane ivjJScrollPane1 = null; + private javax.swing.JButton ivjJButtonFDCopyRef = null; + private JButton jButtonFindRefModel = null; + private JPanel jPanel = null; + private JButton jButtonCreateGeom = null; + private JPanel jPanel1 = null; + private JButton jButtonViewAnnot = null; + + class IvjEventHandler implements ActionListener, TreeExpansionListener, javax.swing.event.TreeSelectionListener { + public void actionPerformed(java.awt.event.ActionEvent e) { + if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDDelete()) + connEtoC7(e); + if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDCopyRef()) + connEtoC8(e); + if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDView()) + connEtoC10(e); + if (e.getSource() == FieldDataGUIPanel.this.getJButtonFDCreate()) + if (getCreateJComboBox().getSelectedItem().equals(FROM_SIM)) { + jButtonFDFromSim_ActionPerformed(e); + } else if (getCreateJComboBox().getSelectedItem().equals(FROM_FILE)) { + jButtonFDFromFile_ActionPerformed(e); + } // else if(getCreateJComboBox().getSelectedItem().equals(FROM_IMAGEJ)){ // fromImageJ(); // } - }; - public void treeCollapsed(javax.swing.event.TreeExpansionEvent event) {}; - public void treeExpanded(javax.swing.event.TreeExpansionEvent event) { - if (event.getSource() == FieldDataGUIPanel.this.getJTree1()) - connEtoC6(event); - }; - public void valueChanged(javax.swing.event.TreeSelectionEvent e) { - if (e.getSource() == FieldDataGUIPanel.this.getJTree1()) - connEtoC2(e); - }; - }; - -/** - * FieldDataGUIPanel constructor comment. - */ -public FieldDataGUIPanel() { - super(); - initialize(); -} - -/** - * connEtoC1: (FieldDataGUIPanel.initialize() --> FieldDataGUIPanel.fieldDataGUIPanel_Initialize()V) - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private void connEtoC1() { - try { - // user code begin {1} - // user code end - this.fieldDataGUIPanel_Initialize(); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - - -/** - * connEtoC2: (JTree1.treeSelection.valueChanged(javax.swing.event.TreeSelectionEvent) --> FieldDataGUIPanel.jTree1_ValueChanged(Ljavax.swing.event.TreeSelectionEvent;)V) - * @param arg1 javax.swing.event.TreeSelectionEvent - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private void connEtoC2(javax.swing.event.TreeSelectionEvent arg1) { - try { - // user code begin {1} - // user code end - this.jTree1_ValueChanged(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - - -private void connEtoC6(javax.swing.event.TreeExpansionEvent arg1) { - try { - // user code begin {1} - // user code end - this.jTree1_TreeExpanded(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -private void connEtoC7(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.jButtonFDDelete_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -private void connEtoC8(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.jButtonFDCopyRef_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -private void copyMethod(int copyMode){ - String delimiter = ""; - if(copyMode == COPY_NL){ - delimiter = "\n"; - }else if(copyMode == COPY_CRNL){ - delimiter = "\r\n"; - }else if(copyMode == COPY_CSV){ - delimiter = ","; - }else if(copyMode == COPY_SPACE){ - delimiter = " "; - } - String copyString = ""; - javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); - if(selPath != null){ - javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); - if(lastPathComponent.equals(getJTree1().getModel().getRoot())){ - int childCount = lastPathComponent.getChildCount(); - for(int i=0;i 0 ){ - VCellTransferable.sendToClipboard(copyString); - } - } -} - -private void connEtoC10(java.awt.event.ActionEvent arg1) { - try { - // user code begin {1} - // user code end - this.jButtonFDView_ActionPerformed(arg1); - // user code begin {2} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {3} - // user code end - handleException(ivjExc); - } -} - -/** - * Comment - */ -private void fieldDataGUIPanel_Initialize() { - - getJTree1().getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION); - - JMenuItem copyMenuItem = new JMenuItem("Copy"); - copyMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - copyMethod(COPY_SPACE); - } - }); - JMenuItem copyCSVMenuItem = new JMenuItem("Copy w/ Commas"); - copyCSVMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - copyMethod(COPY_CSV); - } - }); - JMenuItem copyNewLineMenuItem = new JMenuItem("Copy w/ LF"); - copyNewLineMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - copyMethod(COPY_NL); - } - }); - JMenuItem copyReturnNewLineMenuItem = new JMenuItem("Copy w/ CRLF"); - copyReturnNewLineMenuItem.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - copyMethod(COPY_CRNL); - } - }); - -} - -public void updateJTree(final RequestManager clientRequestManager){ - - if(clientRequestManager == null){ - DefaultMutableTreeNode emptyNode = new DefaultMutableTreeNode("No Info Available"); - getJTree1().setModel(new DefaultTreeModel(emptyNode)); - }else{ - DefaultMutableTreeNode startupNode = new DefaultMutableTreeNode("Gathering Field Data Information... (Please wait)"); - getJTree1().setModel(new DefaultTreeModel(startupNode)); - AsynchClientTask gatherInfo = new AsynchClientTask("gatherInfo", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - - @Override - public void run(Hashtable hashTable) throws Exception { - try { - DocumentManager documentManager = clientRequestManager.getDocumentManager(); - FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser()); - FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos); - - ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr; - String[] extDataAnnotArr = fieldDataDBOperationResults.extDataAnnotArr; - - TreeMap sortedExtDataIDTreeMap = new TreeMap( - new Comparator() { - public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); - } - } - ); - for(int i=0;i> sortIter = sortedExtDataIDTreeMap.entrySet().iterator(); - while(sortIter.hasNext()){ - Entry entry = sortIter.next(); - DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(entry.getKey(),entry.getValue())); - mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList())); - rootNode.add(mainNode); - } - hashTable.put("rootNode", rootNode); - }catch(Exception e){ - DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode("Error Getting Field Data Information"); - hashTable.put("rootNode", errorNode); - throw e; - } - } - }; - AsynchClientTask updateTree = new AsynchClientTask("updateTree", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - - @Override - public void run(Hashtable hashTable) throws Exception { - DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)hashTable.get("rootNode"); - getJTree1().setModel(new DefaultTreeModel(rootNode)); - } - }; - ClientTaskDispatcher.dispatch(this, new Hashtable(), new AsynchClientTask[] {gatherInfo, updateTree}); - } -} - - -/** - * Return the JButtonFDCopyRef property value. - * @return javax.swing.JButton - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JButton getJButtonFDCopyRef() { - if (ivjJButtonFDCopyRef == null) { - try { - ivjJButtonFDCopyRef = new javax.swing.JButton(); - ivjJButtonFDCopyRef.setName("JButtonFDCopyRef"); - ivjJButtonFDCopyRef.setText("Copy Func"); - ivjJButtonFDCopyRef.setEnabled(false); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJButtonFDCopyRef; -} - -/** - * Return the JButtonFDDelete property value. - * @return javax.swing.JButton - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JButton getJButtonFDDelete() { - if (ivjJButtonFDDelete == null) { - try { - ivjJButtonFDDelete = new javax.swing.JButton(); - ivjJButtonFDDelete.setName("JButtonFDDelete"); - ivjJButtonFDDelete.setText("Delete"); - ivjJButtonFDDelete.setEnabled(false); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJButtonFDDelete; -} - -private JButton ivjJButtonFDCreate; -/** - * Return the JButtonFDFromFile property value. - * @return javax.swing.JButton - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private JButton getJButtonFDCreate() { - if (ivjJButtonFDCreate == null) { - try { - ivjJButtonFDCreate = new javax.swing.JButton(); - ivjJButtonFDCreate.setName("JButtonFDFromCreate"); - ivjJButtonFDCreate.setText("Create..."); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJButtonFDCreate; -} - -private JComboBox jComboBoxCreate; -private static final String FROM_FILE = "from File"; -private static final String FROM_SIM = "from Simulation"; -//private static final String FROM_IMAGEJ = "from ImageJ"; -private JComboBox getCreateJComboBox(){ - if(jComboBoxCreate == null){ - jComboBoxCreate = new JComboBox(new Object[] {FROM_FILE,FROM_SIM/*,FROM_IMAGEJ*/}); - } - return jComboBoxCreate; -} - -/** - * Return the JButtonFDView property value. - * @return javax.swing.JButton - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JButton getJButtonFDView() { - if (ivjJButtonFDView == null) { - try { - ivjJButtonFDView = new javax.swing.JButton(); - ivjJButtonFDView.setName("JButtonFDView"); - ivjJButtonFDView.setText("View..."); - ivjJButtonFDView.setEnabled(false); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJButtonFDView; -} - -/** - * Return the JPanel1 property value. - * @return javax.swing.JPanel - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JPanel getJPanel1() { - if (ivjJPanel1 == null) { - try { - org.vcell.util.gui.TitledBorderBean ivjLocalBorder; - ivjLocalBorder = new org.vcell.util.gui.TitledBorderBean(); - ivjLocalBorder.setTitleFont(new java.awt.Font("Arial", 1, 14)); - ivjLocalBorder.setTitle("Create New Field Data"); - ivjJPanel1 = new javax.swing.JPanel(); - ivjJPanel1.setName("JPanel1"); - ivjJPanel1.setBorder(ivjLocalBorder); - final java.awt.GridBagLayout gridBagLayout = new java.awt.GridBagLayout(); - gridBagLayout.rowHeights = new int[] {0,0,7}; - ivjJPanel1.setLayout(gridBagLayout); - - java.awt.GridBagConstraints constraintsJButtonFDFromFile = new java.awt.GridBagConstraints(); - constraintsJButtonFDFromFile.gridx = 1; constraintsJButtonFDFromFile.gridy = 1; - constraintsJButtonFDFromFile.fill = java.awt.GridBagConstraints.HORIZONTAL; - constraintsJButtonFDFromFile.weightx = 1.0; - constraintsJButtonFDFromFile.insets = new java.awt.Insets(4, 4, 4, 4); - getJPanel1().add(getJButtonFDCreate(), constraintsJButtonFDFromFile); - - java.awt.GridBagConstraints constraintsJButtonFDFromSim = new java.awt.GridBagConstraints(); - constraintsJButtonFDFromSim.gridx = 2; constraintsJButtonFDFromSim.gridy = 1; - constraintsJButtonFDFromSim.fill = java.awt.GridBagConstraints.HORIZONTAL; - constraintsJButtonFDFromSim.weightx = 1.0; - constraintsJButtonFDFromSim.insets = new java.awt.Insets(4, 4, 4, 4); - getJPanel1().add(getCreateJComboBox(), constraintsJButtonFDFromSim); - - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJPanel1; -} - - -/** - * Return the JPanel2 property value. - * @return javax.swing.JPanel - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JPanel getNormalTopPanel() { - if (normalTopPanel == null) { - try { - GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); - gridBagConstraints4.gridx = 2; - gridBagConstraints4.gridy = 1; - GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); - gridBagConstraints21.gridx = 2; - gridBagConstraints21.gridy = 0; - normalTopPanel = new javax.swing.JPanel(); - normalTopPanel.setName("normalTopPanel"); - normalTopPanel.setLayout(new java.awt.GridBagLayout()); - - java.awt.GridBagConstraints constraintsJPanel1 = new java.awt.GridBagConstraints(); - constraintsJPanel1.gridx = 0; constraintsJPanel1.gridy = 0; -constraintsJPanel1.gridheight = 2; - constraintsJPanel1.fill = java.awt.GridBagConstraints.BOTH; - constraintsJPanel1.insets = new java.awt.Insets(4, 4, 4, 4); - getNormalTopPanel().add(getJPanel1(), constraintsJPanel1); - - java.awt.GridBagConstraints constraintsJButtonFDDelete = new java.awt.GridBagConstraints(); - constraintsJButtonFDDelete.gridx = 1; constraintsJButtonFDDelete.gridy = 0; - constraintsJButtonFDDelete.fill = java.awt.GridBagConstraints.HORIZONTAL; - constraintsJButtonFDDelete.weightx = 0.0; - constraintsJButtonFDDelete.insets = new java.awt.Insets(4, 4, 4, 4); - java.awt.GridBagConstraints constraintsJButtonFDView = new java.awt.GridBagConstraints(); - constraintsJButtonFDView.gridx = 1; constraintsJButtonFDView.gridy = 1; - constraintsJButtonFDView.gridwidth = 1; - constraintsJButtonFDView.fill = java.awt.GridBagConstraints.HORIZONTAL; - constraintsJButtonFDView.insets = new java.awt.Insets(4, 4, 4, 4); - normalTopPanel.add(getJButtonFDDelete(), constraintsJButtonFDDelete); - normalTopPanel.add(getJButtonFDView(), constraintsJButtonFDView); - normalTopPanel.add(getJPanel(), gridBagConstraints21); - normalTopPanel.add(getJPanel12(), gridBagConstraints4); - } catch (java.lang.Throwable ivjExc) { - handleException(ivjExc); - } - } - return normalTopPanel; -} - -public static final int DISPLAY_NORMAL = 0; -public static final int DISPLAY_DATASYMBOLS = 1; -private int displayMode = DISPLAY_NORMAL; -private JPanel dataSymbolsJPanel = null; -private JButton dsAnnotButton = new JButton(); -private JButton dsViewButton = new JButton(); -private JButton dsDataSymbolButton = new JButton(); -public int getDisplayMode(){ - return displayMode; -} -private void setDisplayMode(int newDisplayMode){ - displayMode = newDisplayMode; - if(newDisplayMode == DISPLAY_DATASYMBOLS){ - for (int i = 0; i < getComponentCount(); i++) { - if(getComponent(i) == getNormalTopPanel()){ - remove(getComponent(i)); - break; - }else if(getComponent(i) == dataSymbolsJPanel){ - return; - } - } - if(dataSymbolsJPanel == null){ - dataSymbolsJPanel = new JPanel(); - dataSymbolsJPanel.setName("dataSymbolsPanel"); - //View Button - //JButton viewButton = new JButton(); - dsViewButton.setText("View..."); - dsViewButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - jButtonFDView_ActionPerformed(e); - } - }); - dsViewButton.setEnabled(false); - dataSymbolsJPanel.add(dsViewButton); - //view Annotation - //JButton annotButton = new JButton(); - dsAnnotButton.setText("View Annot..."); - dsAnnotButton.addActionListener(viewAnnotAction); - dsAnnotButton.setEnabled(false); - dataSymbolsJPanel.add(dsAnnotButton); - //datasymbol Callback button - //JButton dataSymbolButton = new JButton(); - dsDataSymbolButton.setText("Create Data Symbol..."); - dsDataSymbolButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - jButtonFDCopyRef_ActionPerformed(e); - } - }); - dsDataSymbolButton.setEnabled(false); - dataSymbolsJPanel.add(dsDataSymbolButton); - } - java.awt.GridBagConstraints gbc_datasymbolsPanel = new java.awt.GridBagConstraints(); - gbc_datasymbolsPanel.gridx = 0; gbc_datasymbolsPanel.gridy = 0; - gbc_datasymbolsPanel.fill = java.awt.GridBagConstraints.BOTH; - gbc_datasymbolsPanel.insets = new java.awt.Insets(4, 4, 4, 4); - add(dataSymbolsJPanel, gbc_datasymbolsPanel); - - }else{ - for (int i = 0; i < getComponentCount(); i++) { - if(getComponent(i) == dataSymbolsJPanel){ - remove(getComponent(i)); - break; - }else if(getComponent(i) == getNormalTopPanel()){ - return; - } - } - java.awt.GridBagConstraints gbc_normalTopPanel = new java.awt.GridBagConstraints(); - gbc_normalTopPanel.gridx = 0; gbc_normalTopPanel.gridy = 0; - gbc_normalTopPanel.fill = java.awt.GridBagConstraints.BOTH; - gbc_normalTopPanel.insets = new java.awt.Insets(4, 4, 4, 4); - add(getNormalTopPanel(), gbc_normalTopPanel); - } -} -private FieldDataWindowManager.DataSymbolCallBack dataSymbolCallBack = null; -public void setCreateDataSymbolCallBack(FieldDataWindowManager.DataSymbolCallBack dataSymbolCallBack){ - this.dataSymbolCallBack = dataSymbolCallBack; - setDisplayMode((dataSymbolCallBack==null?FieldDataGUIPanel.DISPLAY_NORMAL:FieldDataGUIPanel.DISPLAY_DATASYMBOLS)); -} -/** - * Return the JScrollPane1 property value. - * @return javax.swing.JScrollPane - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JScrollPane getJScrollPane1() { - if (ivjJScrollPane1 == null) { - try { - ivjJScrollPane1 = new javax.swing.JScrollPane(); - ivjJScrollPane1.setName("JScrollPane1"); - getJScrollPane1().setViewportView(getJTree1()); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - } - } - return ivjJScrollPane1; -} - -/** - * Return the JTree1 property value. - * @return javax.swing.JTree - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private javax.swing.JTree getJTree1() { - if (ivjJTree1 == null) { - try { - ivjJTree1 = new javax.swing.JTree(); - ivjJTree1.setName("JTree1"); - ivjJTree1.setBounds(0, 0, 516, 346); - // user code begin {1} - // user code end - } catch (java.lang.Throwable ivjExc) { - // user code begin {2} - // user code end - handleException(ivjExc); - ivjJTree1.addMouseListener(new java.awt.event.MouseAdapter() { - public void mousePressed(MouseEvent e) { - maybeShowPopup(e); - } - - public void mouseReleased(MouseEvent e) { - maybeShowPopup(e); - } - private void maybeShowPopup(MouseEvent e) { - if (e.isPopupTrigger()) { - jPopupMenu.show(e.getComponent(), - e.getX(), e.getY()); - } - } - }); - } - } - return ivjJTree1; -} - -/** - * Called whenever the part throws an exception. - * @param exception java.lang.Throwable - */ -private void handleException(java.lang.Throwable exception) { - - /* Uncomment the following lines to print uncaught exceptions to stdout */ - System.out.println("--------- UNCAUGHT EXCEPTION ---------"); - exception.printStackTrace(System.out); -} - - -/** - * Initializes connections - * @exception java.lang.Exception The exception description. - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private void initConnections() throws java.lang.Exception { - // user code begin {1} - // user code end - getJTree1().addTreeSelectionListener(ivjEventHandler); - getJTree1().addTreeExpansionListener(ivjEventHandler); - getJButtonFDDelete().addActionListener(ivjEventHandler); - getJButtonFDCopyRef().addActionListener(ivjEventHandler); - getJButtonFDCreate().addActionListener(ivjEventHandler); - getJButtonFDView().addActionListener(ivjEventHandler); -} - -/** - * Initialize the class. - */ -/* WARNING: THIS METHOD WILL BE REGENERATED. */ -private void initialize() { - try { - // user code begin {1} - // user code end - setName("FieldDataGUIPanel"); - setLayout(new java.awt.GridBagLayout()); - setSize(676, 430); - - java.awt.GridBagConstraints gbc_normalTopPanel = new java.awt.GridBagConstraints(); - gbc_normalTopPanel.gridx = 0; gbc_normalTopPanel.gridy = 0; - gbc_normalTopPanel.fill = java.awt.GridBagConstraints.BOTH; - gbc_normalTopPanel.insets = new java.awt.Insets(4, 4, 4, 4); - add(getNormalTopPanel(), gbc_normalTopPanel); - - java.awt.GridBagConstraints constraintsJScrollPane1 = new java.awt.GridBagConstraints(); - constraintsJScrollPane1.gridx = 0; constraintsJScrollPane1.gridy = 1; - constraintsJScrollPane1.fill = java.awt.GridBagConstraints.BOTH; - constraintsJScrollPane1.weightx = 1.0; - constraintsJScrollPane1.weighty = 1.0; - constraintsJScrollPane1.insets = new java.awt.Insets(4, 4, 4, 4); - add(getJScrollPane1(), constraintsJScrollPane1); - initConnections(); - connEtoC1(); - } catch (java.lang.Throwable ivjExc) { - handleException(ivjExc); - } - // user code begin {2} - // user code end -} - - -public boolean isInitialized(){ - DefaultMutableTreeNode rootNode = - (DefaultMutableTreeNode)getJTree1().getModel().getRoot(); - if(rootNode == null){ - return false; - } - return (rootNode.getUserObject() instanceof InitializedRootNode); -} -/** - * Comment - */ -private void jTree1_ValueChanged(javax.swing.event.TreeSelectionEvent treeSelectionEvent) { - getJButtonFDDelete().setEnabled(false); - getJButtonFDView().setEnabled(false);dsViewButton.setEnabled(false); - getJButtonFDCopyRef().setEnabled(false);dsDataSymbolButton.setEnabled(false); - getJButtonFindRefModel().setEnabled(false); - getJButtonViewAnnot().setEnabled(false);dsAnnotButton.setEnabled(false); - getJButtonCreateGeom().setEnabled(false); - javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); - if(selPath != null){ - javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); + } + + ; + + public void treeCollapsed(javax.swing.event.TreeExpansionEvent event) { + } + + ; + + public void treeExpanded(javax.swing.event.TreeExpansionEvent event) { + if (event.getSource() == FieldDataGUIPanel.this.getFieldDataTree()) + connEtoC6(event); + } + + ; + + public void valueChanged(javax.swing.event.TreeSelectionEvent e) { + if (e.getSource() == FieldDataGUIPanel.this.getFieldDataTree()) + connEtoC2(e); + } + + ; + } + + ; + + /** + * FieldDataGUIPanel constructor comment. + */ + public FieldDataGUIPanel() { + super(); + initialize(); + } + + /** + * connEtoC1: (FieldDataGUIPanel.initialize() --> FieldDataGUIPanel.fieldDataGUIPanel_Initialize()V) + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private void connEtoC1() { + try { + // user code begin {1} + // user code end + this.fieldDataGUIPanel_Initialize(); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + + /** + * connEtoC2: (JTree1.treeSelection.valueChanged(javax.swing.event.TreeSelectionEvent) --> FieldDataGUIPanel.jTree1_ValueChanged(Ljavax.swing.event.TreeSelectionEvent;)V) + * + * @param arg1 javax.swing.event.TreeSelectionEvent + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private void connEtoC2(javax.swing.event.TreeSelectionEvent arg1) { + try { + // user code begin {1} + // user code end + this.jTree1_ValueChanged(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + + private void connEtoC6(javax.swing.event.TreeExpansionEvent arg1) { + try { + // user code begin {1} + // user code end + this.jTree1_TreeExpanded(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + private void connEtoC7(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.jButtonFDDelete_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + private void connEtoC8(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.jButtonFDCopyRef_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + private void copyMethod(int copyMode) { + String delimiter = ""; + if (copyMode == COPY_NL) { + delimiter = "\n"; + } else if (copyMode == COPY_CRNL) { + delimiter = "\r\n"; + } else if (copyMode == COPY_CSV) { + delimiter = ","; + } else if (copyMode == COPY_SPACE) { + delimiter = " "; + } + String copyString = ""; + javax.swing.tree.TreePath selPath = getFieldDataTree().getSelectionPath(); + if (selPath != null) { + javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent(); + if (lastPathComponent.equals(getFieldDataTree().getModel().getRoot())) { + int childCount = lastPathComponent.getChildCount(); + for (int i = 0; i < childCount; i += 1) { + if (i != 0) { + copyString += delimiter; + } + copyString += + ((FieldDataMainList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).externalDataIdentifier.getName(); + } + } else if (lastPathComponent.getUserObject() instanceof FieldDataOriginList) { + Origin origin = ((FieldDataOriginList) lastPathComponent.getUserObject()).origin; + copyString = origin.getX() + delimiter + origin.getY() + delimiter + origin.getZ(); + } else if (lastPathComponent.getUserObject() instanceof FieldDataExtentList) { + Extent extent = ((FieldDataExtentList) lastPathComponent.getUserObject()).extent; + copyString = extent.getX() + delimiter + extent.getY() + delimiter + extent.getZ(); + } else if (lastPathComponent.getUserObject() instanceof FieldDataISizeList) { + ISize isize = ((FieldDataISizeList) lastPathComponent.getUserObject()).isize; + copyString = isize.getX() + delimiter + isize.getY() + delimiter + isize.getZ(); + } else if (lastPathComponent.getUserObject() instanceof FieldDataTimeList) { + double[] times = ((FieldDataTimeList) lastPathComponent.getUserObject()).times; + for (int i = 0; i < times.length; i += 1) { + if (i != 0) { + copyString += delimiter; + } + copyString += times[i] + ""; + } + } else if (lastPathComponent.getUserObject() instanceof FieldDataMainList) { + ExternalDataIdentifier extDataID = + ((FieldDataMainList) lastPathComponent.getUserObject()).externalDataIdentifier; + copyString = extDataID.getName(); + } else if (lastPathComponent.getUserObject() instanceof FieldDataVarList) { + DataIdentifier dataIdentifier = + ((FieldDataVarList) lastPathComponent.getUserObject()).dataIdentifier; + copyString = dataIdentifier.getName(); + } else if (lastPathComponent.getUserObject() instanceof FieldDataVarMainList) { + int childCount = lastPathComponent.getChildCount(); + for (int i = 0; i < childCount; i += 1) { + if (i != 0) { + copyString += delimiter; + } + copyString += + ((FieldDataVarList) ((DefaultMutableTreeNode) lastPathComponent.getChildAt(i)).getUserObject()).dataIdentifier.getName(); + } + } + if (copyString.length() > 0) { + VCellTransferable.sendToClipboard(copyString); + } + } + } + + private void connEtoC10(java.awt.event.ActionEvent arg1) { + try { + // user code begin {1} + // user code end + this.jButtonFDView_ActionPerformed(arg1); + // user code begin {2} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {3} + // user code end + handleException(ivjExc); + } + } + + /** + * Comment + */ + private void fieldDataGUIPanel_Initialize() { + + getFieldDataTree().getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.SINGLE_TREE_SELECTION); + + JMenuItem copyMenuItem = new JMenuItem("Copy"); + copyMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + copyMethod(COPY_SPACE); + } + }); + JMenuItem copyCSVMenuItem = new JMenuItem("Copy w/ Commas"); + copyCSVMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + copyMethod(COPY_CSV); + } + }); + JMenuItem copyNewLineMenuItem = new JMenuItem("Copy w/ LF"); + copyNewLineMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + copyMethod(COPY_NL); + } + }); + JMenuItem copyReturnNewLineMenuItem = new JMenuItem("Copy w/ CRLF"); + copyReturnNewLineMenuItem.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + copyMethod(COPY_CRNL); + } + }); + + } + + public void updateJTree(final RequestManager clientRequestManager) { + + if (clientRequestManager == null) { + DefaultMutableTreeNode emptyNode = new DefaultMutableTreeNode("No Info Available"); + getFieldDataTree().setModel(new DefaultTreeModel(emptyNode)); + } else { + DefaultMutableTreeNode startupNode = new DefaultMutableTreeNode("Gathering Field Data Information... (Please wait)"); + getFieldDataTree().setModel(new DefaultTreeModel(startupNode)); + AsynchClientTask gatherInfo = new AsynchClientTask("gatherInfo", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + try { + DocumentManager documentManager = clientRequestManager.getDocumentManager(); + FieldDataDBOperationSpec fdos = FieldDataDBOperationSpec.createGetExtDataIDsSpec(documentManager.getUser()); + FieldDataDBOperationResults fieldDataDBOperationResults = documentManager.fieldDataDBOperation(fdos); + + ExternalDataIdentifier[] externalDataIdentifierArr = fieldDataDBOperationResults.extDataIDArr; + String[] extDataAnnotArr = fieldDataDBOperationResults.extDataAnnotArr; + + TreeMap sortedExtDataIDTreeMap = new TreeMap( + new Comparator() { + public int compare(ExternalDataIdentifier o1, ExternalDataIdentifier o2) { + return o1.getName().compareToIgnoreCase(o2.getName()); + } + } + ); + for (int i = 0; i < externalDataIdentifierArr.length; i += 1) { + sortedExtDataIDTreeMap.put(externalDataIdentifierArr[i], extDataAnnotArr[i]); + } + DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(new InitializedRootNode( + FIELD_DATA_INFO + (externalDataIdentifierArr.length == 0 ? " (None Defined)" : ""))); + + Iterator> sortIter = sortedExtDataIDTreeMap.entrySet().iterator(); + while (sortIter.hasNext()) { + Entry entry = sortIter.next(); + DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(entry.getKey(), entry.getValue())); + mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList())); + rootNode.add(mainNode); + } + hashTable.put("rootNode", rootNode); + } catch (Exception e) { + DefaultMutableTreeNode errorNode = new DefaultMutableTreeNode("Error Getting Field Data Information"); + hashTable.put("rootNode", errorNode); + throw e; + } + } + }; + AsynchClientTask updateTree = new AsynchClientTask("updateTree", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) hashTable.get("rootNode"); + getFieldDataTree().setModel(new DefaultTreeModel(rootNode)); + } + }; + ClientTaskDispatcher.dispatch(this, new Hashtable(), new AsynchClientTask[]{gatherInfo, updateTree}); + } + } + + + /** + * Return the JButtonFDCopyRef property value. + * + * @return javax.swing.JButton + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private javax.swing.JButton getJButtonFDCopyRef() { + if (ivjJButtonFDCopyRef == null) { + try { + ivjJButtonFDCopyRef = new javax.swing.JButton(); + ivjJButtonFDCopyRef.setName("JButtonFDCopyRef"); + ivjJButtonFDCopyRef.setText("Copy Func"); + ivjJButtonFDCopyRef.setEnabled(false); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJButtonFDCopyRef; + } + + /** + * Return the JButtonFDDelete property value. + * + * @return javax.swing.JButton + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private javax.swing.JButton getJButtonFDDelete() { + if (ivjJButtonFDDelete == null) { + try { + ivjJButtonFDDelete = new javax.swing.JButton(); + ivjJButtonFDDelete.setName("JButtonFDDelete"); + ivjJButtonFDDelete.setText("Delete"); + ivjJButtonFDDelete.setEnabled(false); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJButtonFDDelete; + } + + private JButton ivjJButtonFDCreate; + + /** + * Return the JButtonFDFromFile property value. + * + * @return javax.swing.JButton + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private JButton getJButtonFDCreate() { + if (ivjJButtonFDCreate == null) { + try { + ivjJButtonFDCreate = new javax.swing.JButton(); + ivjJButtonFDCreate.setName("JButtonFDFromCreate"); + ivjJButtonFDCreate.setText("Create..."); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJButtonFDCreate; + } + + private JComboBox jComboBoxCreate; + private static final String FROM_FILE = "from File"; + private static final String FROM_SIM = "from Simulation"; + + //private static final String FROM_IMAGEJ = "from ImageJ"; + private JComboBox getCreateJComboBox() { + if (jComboBoxCreate == null) { + jComboBoxCreate = new JComboBox(new Object[]{FROM_FILE, FROM_SIM/*,FROM_IMAGEJ*/}); + } + return jComboBoxCreate; + } + + /** + * Return the JButtonFDView property value. + * + * @return javax.swing.JButton + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private javax.swing.JButton getJButtonFDView() { + if (ivjJButtonFDView == null) { + try { + ivjJButtonFDView = new javax.swing.JButton(); + ivjJButtonFDView.setName("JButtonFDView"); + ivjJButtonFDView.setText("View..."); + ivjJButtonFDView.setEnabled(false); + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJButtonFDView; + } + + /** + * Return the JPanel1 property value. + * + * @return javax.swing.JPanel + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private javax.swing.JPanel getJPanel1() { + if (ivjJPanel1 == null) { + try { + org.vcell.util.gui.TitledBorderBean ivjLocalBorder; + ivjLocalBorder = new org.vcell.util.gui.TitledBorderBean(); + ivjLocalBorder.setTitleFont(new java.awt.Font("Arial", 1, 14)); + ivjLocalBorder.setTitle("Create New Field Data"); + ivjJPanel1 = new javax.swing.JPanel(); + ivjJPanel1.setName("JPanel1"); + ivjJPanel1.setBorder(ivjLocalBorder); + final java.awt.GridBagLayout gridBagLayout = new java.awt.GridBagLayout(); + gridBagLayout.rowHeights = new int[]{0, 0, 7}; + ivjJPanel1.setLayout(gridBagLayout); + + java.awt.GridBagConstraints constraintsJButtonFDFromFile = new java.awt.GridBagConstraints(); + constraintsJButtonFDFromFile.gridx = 1; + constraintsJButtonFDFromFile.gridy = 1; + constraintsJButtonFDFromFile.fill = java.awt.GridBagConstraints.HORIZONTAL; + constraintsJButtonFDFromFile.weightx = 1.0; + constraintsJButtonFDFromFile.insets = new java.awt.Insets(4, 4, 4, 4); + getJPanel1().add(getJButtonFDCreate(), constraintsJButtonFDFromFile); + + java.awt.GridBagConstraints constraintsJButtonFDFromSim = new java.awt.GridBagConstraints(); + constraintsJButtonFDFromSim.gridx = 2; + constraintsJButtonFDFromSim.gridy = 1; + constraintsJButtonFDFromSim.fill = java.awt.GridBagConstraints.HORIZONTAL; + constraintsJButtonFDFromSim.weightx = 1.0; + constraintsJButtonFDFromSim.insets = new java.awt.Insets(4, 4, 4, 4); + getJPanel1().add(getCreateJComboBox(), constraintsJButtonFDFromSim); + + // user code begin {1} + // user code end + } catch (java.lang.Throwable ivjExc) { + // user code begin {2} + // user code end + handleException(ivjExc); + } + } + return ivjJPanel1; + } + + + /** + * Return the JPanel2 property value. + * + * @return javax.swing.JPanel + */ + /* WARNING: THIS METHOD WILL BE REGENERATED. */ + private javax.swing.JPanel getNormalTopPanel() { + if (normalTopPanel == null) { + try { + GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); + gridBagConstraints4.gridx = 2; + gridBagConstraints4.gridy = 1; + GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); + gridBagConstraints21.gridx = 2; + gridBagConstraints21.gridy = 0; + normalTopPanel = new javax.swing.JPanel(); + normalTopPanel.setName("normalTopPanel"); + normalTopPanel.setLayout(new java.awt.GridBagLayout()); + + java.awt.GridBagConstraints constraintsJPanel1 = new java.awt.GridBagConstraints(); + constraintsJPanel1.gridx = 0; + constraintsJPanel1.gridy = 0; + constraintsJPanel1.gridheight = 2; + constraintsJPanel1.fill = java.awt.GridBagConstraints.BOTH; + constraintsJPanel1.insets = new java.awt.Insets(4, 4, 4, 4); + getNormalTopPanel().add(getJPanel1(), constraintsJPanel1); + + java.awt.GridBagConstraints constraintsJButtonFDDelete = new java.awt.GridBagConstraints(); + constraintsJButtonFDDelete.gridx = 1; + constraintsJButtonFDDelete.gridy = 0; + constraintsJButtonFDDelete.fill = java.awt.GridBagConstraints.HORIZONTAL; + constraintsJButtonFDDelete.weightx = 0.0; + constraintsJButtonFDDelete.insets = new java.awt.Insets(4, 4, 4, 4); + java.awt.GridBagConstraints constraintsJButtonFDView = new java.awt.GridBagConstraints(); + constraintsJButtonFDView.gridx = 1; + constraintsJButtonFDView.gridy = 1; + constraintsJButtonFDView.gridwidth = 1; + constraintsJButtonFDView.fill = java.awt.GridBagConstraints.HORIZONTAL; + constraintsJButtonFDView.insets = new java.awt.Insets(4, 4, 4, 4); + normalTopPanel.add(getJButtonFDDelete(), constraintsJButtonFDDelete); + normalTopPanel.add(getJButtonFDView(), constraintsJButtonFDView); + normalTopPanel.add(getJPanel(), gridBagConstraints21); + normalTopPanel.add(getJPanel12(), gridBagConstraints4); + } catch (java.lang.Throwable ivjExc) { + handleException(ivjExc); + } + } + return normalTopPanel; + } + + public static final int DISPLAY_NORMAL = 0; + public static final int DISPLAY_DATASYMBOLS = 1; + private int displayMode = DISPLAY_NORMAL; + private JPanel dataSymbolsJPanel = null; + private JButton dsAnnotButton = new JButton(); + private JButton dsViewButton = new JButton(); + private JButton dsDataSymbolButton = new JButton(); + + public int getDisplayMode() { + return displayMode; + } + + private void setDisplayMode(int newDisplayMode) { + displayMode = newDisplayMode; + if (newDisplayMode == DISPLAY_DATASYMBOLS) { + for (int i = 0; i < getComponentCount(); i++) { + if (getComponent(i) == getNormalTopPanel()) { + remove(getComponent(i)); + break; + } else if (getComponent(i) == dataSymbolsJPanel) { + return; + } + } + if (dataSymbolsJPanel == null) { + dataSymbolsJPanel = new JPanel(); + dataSymbolsJPanel.setName("dataSymbolsPanel"); + //View Button + //JButton viewButton = new JButton(); + dsViewButton.setText("View..."); + dsViewButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + jButtonFDView_ActionPerformed(e); + } + }); + dsViewButton.setEnabled(false); + dataSymbolsJPanel.add(dsViewButton); + //view Annotation + //JButton annotButton = new JButton(); + dsAnnotButton.setText("View Annot..."); + dsAnnotButton.addActionListener(viewAnnotAction); + dsAnnotButton.setEnabled(false); + dataSymbolsJPanel.add(dsAnnotButton); + //datasymbol Callback button + //JButton dataSymbolButton = new JButton(); + dsDataSymbolButton.setText("Create Data Symbol..."); + dsDataSymbolButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + jButtonFDCopyRef_ActionPerformed(e); + } + }); + dsDataSymbolButton.setEnabled(false); + dataSymbolsJPanel.add(dsDataSymbolButton); + } + java.awt.GridBagConstraints gbc_datasymbolsPanel = new java.awt.GridBagConstraints(); + gbc_datasymbolsPanel.gridx = 0; + gbc_datasymbolsPanel.gridy = 0; + gbc_datasymbolsPanel.fill = java.awt.GridBagConstraints.BOTH; + gbc_datasymbolsPanel.insets = new java.awt.Insets(4, 4, 4, 4); + add(dataSymbolsJPanel, gbc_datasymbolsPanel); + + } else { + for (int i = 0; i < getComponentCount(); i++) { + if (getComponent(i) == dataSymbolsJPanel) { + remove(getComponent(i)); + break; + } else if (getComponent(i) == getNormalTopPanel()) { + return; + } + } + java.awt.GridBagConstraints gbc_normalTopPanel = new java.awt.GridBagConstraints(); + gbc_normalTopPanel.gridx = 0; + gbc_normalTopPanel.gridy = 0; + gbc_normalTopPanel.fill = java.awt.GridBagConstraints.BOTH; + gbc_normalTopPanel.insets = new java.awt.Insets(4, 4, 4, 4); + add(getNormalTopPanel(), gbc_normalTopPanel); + } + } + + private FieldDataWindowManager.DataSymbolCallBack dataSymbolCallBack = null; + + public void setCreateDataSymbolCallBack(FieldDataWindowManager.DataSymbolCallBack dataSymbolCallBack) { + this.dataSymbolCallBack = dataSymbolCallBack; + setDisplayMode((dataSymbolCallBack == null ? FieldDataGUIPanel.DISPLAY_NORMAL : FieldDataGUIPanel.DISPLAY_DATASYMBOLS)); + } + + + private javax.swing.JScrollPane getMainScrollPanel() { + if (ivjJScrollPane1 == null) { + try { + ivjJScrollPane1 = new javax.swing.JScrollPane(); + ivjJScrollPane1.setName("JScrollPane1"); + getMainScrollPanel().setViewportView(getFieldDataTree()); + } catch (java.lang.Throwable ivjExc) { + handleException(ivjExc); + } + } + return ivjJScrollPane1; + } + + private javax.swing.JTree getFieldDataTree() { + if (ivjJTree1 == null) { + try { + ivjJTree1 = new javax.swing.JTree(); + ivjJTree1.setName("JTree1"); + ivjJTree1.setBounds(0, 0, 516, 346); + } catch (java.lang.Throwable ivjExc) { + handleException(ivjExc); + ivjJTree1.addMouseListener(new java.awt.event.MouseAdapter() { + public void mousePressed(MouseEvent e) { + maybeShowPopup(e); + } + + public void mouseReleased(MouseEvent e) { + maybeShowPopup(e); + } + + private void maybeShowPopup(MouseEvent e) { + if (e.isPopupTrigger()) { + jPopupMenu.show(e.getComponent(), + e.getX(), e.getY()); + } + } + }); + } + } + return ivjJTree1; + } + + private void handleException(java.lang.Throwable exception) { + + /* Uncomment the following lines to print uncaught exceptions to stdout */ + System.out.println("--------- UNCAUGHT EXCEPTION ---------"); + exception.printStackTrace(System.out); + } + + + private void initConnections() throws java.lang.Exception { + getFieldDataTree().addTreeSelectionListener(ivjEventHandler); + getFieldDataTree().addTreeExpansionListener(ivjEventHandler); + getJButtonFDDelete().addActionListener(ivjEventHandler); + getJButtonFDCopyRef().addActionListener(ivjEventHandler); + getJButtonFDCreate().addActionListener(ivjEventHandler); + getJButtonFDView().addActionListener(ivjEventHandler); + } + + + private void initialize() { + try { + // user code begin {1} + // user code end + setName("FieldDataGUIPanel"); + setLayout(new java.awt.GridBagLayout()); + setSize(676, 430); + + java.awt.GridBagConstraints gbc_normalTopPanel = new java.awt.GridBagConstraints(); + gbc_normalTopPanel.gridx = 0; + gbc_normalTopPanel.gridy = 0; + gbc_normalTopPanel.fill = java.awt.GridBagConstraints.BOTH; + gbc_normalTopPanel.insets = new java.awt.Insets(4, 4, 4, 4); + add(getNormalTopPanel(), gbc_normalTopPanel); + + java.awt.GridBagConstraints constraintsJScrollPane1 = new java.awt.GridBagConstraints(); + constraintsJScrollPane1.gridx = 0; + constraintsJScrollPane1.gridy = 1; + constraintsJScrollPane1.fill = java.awt.GridBagConstraints.BOTH; + constraintsJScrollPane1.weightx = 1.0; + constraintsJScrollPane1.weighty = 1.0; + constraintsJScrollPane1.insets = new java.awt.Insets(4, 4, 4, 4); + add(getMainScrollPanel(), constraintsJScrollPane1); + initConnections(); + connEtoC1(); + } catch (java.lang.Throwable ivjExc) { + handleException(ivjExc); + } + } + + + public boolean isInitialized() { + DefaultMutableTreeNode rootNode = + (DefaultMutableTreeNode) getFieldDataTree().getModel().getRoot(); + if (rootNode == null) { + return false; + } + return (rootNode.getUserObject() instanceof InitializedRootNode); + } + + + private void jTree1_ValueChanged(javax.swing.event.TreeSelectionEvent treeSelectionEvent) { + getJButtonFDDelete().setEnabled(false); + getJButtonFDView().setEnabled(false); + dsViewButton.setEnabled(false); + getJButtonFDCopyRef().setEnabled(false); + dsDataSymbolButton.setEnabled(false); + getJButtonFindRefModel().setEnabled(false); + getJButtonViewAnnot().setEnabled(false); + dsAnnotButton.setEnabled(false); + getJButtonCreateGeom().setEnabled(false); + javax.swing.tree.TreePath selPath = getFieldDataTree().getSelectionPath(); + if (selPath != null) { + javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent(); // System.out.println("count="+selPath.getPathCount()+" "+(lastPathComponent != null?lastPathComponent.toString():"null")); - if(lastPathComponent.getUserObject() instanceof FieldDataMainList){ - getJButtonFDDelete().setEnabled(true); - getJButtonFDView().setEnabled(fieldDataWindowManager != null);dsViewButton.setEnabled(fieldDataWindowManager != null); - getJButtonFindRefModel().setEnabled(true); - getJButtonViewAnnot().setEnabled(true);dsAnnotButton.setEnabled(true); - }else if (lastPathComponent.getUserObject() instanceof FieldDataVarList){ - getJButtonFDCopyRef().setEnabled(true);dsDataSymbolButton.setEnabled(true); - getJButtonCreateGeom().setEnabled(true); - } - } -} - -private void jButtonFDFromSim_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - try{ - final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); - - final FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = FieldDataWindowManager.selectOpenModelsFromDesktop(this,fieldDataWindowManager.getRequestManager(),true,"Select Simulation for Field Data",true); - if(simInfoHolder == null){ - PopupGenerator.showErrorDialog(this, "Please open a Bio or Math model containing the spatial (non-compartmental) simulation you wish to use to create a new Field Data"); - return; - } - //Check that the sim is in a state that can be copied - final SimulationInfo simInfo = simInfoHolder.getSimInfo(); - if(simInfo == null){ - throw new Exception("Selected sim '"+simInfoHolder.getSimName()+"' has no simInfo (save your model and retry)."); - } - SimulationStatus simStatus = clientRequestManager.getServerSimulationStatus(simInfo); - if(simStatus != null && (simStatus.isRunning() || simStatus.isStartRequested())){ - throw new Exception("Can't copy 'running' simulation data from sim '"+simInfo.getName()+"'"); - } - - final FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createCopySimFieldDataFileOperationSpec( null, - (simInfo.getParentSimulationReference() != null?simInfo.getParentSimulationReference(): simInfo.getSimulationVersion().getVersionKey()), - simInfo.getOwner(), simInfoHolder.getJobIndex(), clientRequestManager.getDocumentManager().getUser()); - - AsynchClientTask[] addTasks = addNewExternalData(this,this,true); - AsynchClientTask[] taskArray = new AsynchClientTask[1 + addTasks.length]; - System.arraycopy(addTasks, 0, taskArray, 1, addTasks.length); // add to the end - - taskArray[0] = new AsynchClientTask("Create Field Data from Simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - public void run(Hashtable hashTable) throws Exception { - FieldDataFileOperationResults fdor = - clientRequestManager.getDocumentManager().fieldDataFileOperation( - FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec( - (simInfo.getParentSimulationReference() != null? - simInfo.getParentSimulationReference(): - simInfo.getSimulationVersion().getVersionKey() - ), - simInfo.getOwner(), - simInfoHolder.getJobIndex())); - //Create (non-editable) info for display - fdos.origin = fdor.origin; - fdos.extent = fdor.extent; - fdos.isize = fdor.iSize; - fdos.times = fdor.times; - fdos.varNames = new String[fdor.dataIdentifierArr.length]; - for(int i=0;i hash = new Hashtable(); - ClientTaskDispatcher.dispatch(this,hash,taskArray,false); - - }catch(UserCancelException e){ - return; - }catch(Exception e){ - PopupGenerator.showErrorDialog(this, "Error creating Field Data from simulation\n"+e.getMessage(), e); - } -} - -private void jButtonFDView_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - if(fieldDataWindowManager == null){ - System.out.println("No FieldDataViewManager available for View action"); - return; - } - javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); - if(selPath != null){ - javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); - if(lastPathComponent.getUserObject() instanceof FieldDataMainList){ - ExternalDataIdentifier edi = ((FieldDataMainList)lastPathComponent.getUserObject()).externalDataIdentifier; - fieldDataWindowManager.viewData(edi); - } - } -} - - -private void jButtonFDFromFile_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - Hashtable hash = new Hashtable(); - - AsynchClientTask[] tasks = fdFromFile(); - ClientTaskDispatcher.dispatch(this, hash, tasks, false, true, null); - -} - -//private void fromImageJ(){ -// //windows debug port in use, netstat -anob | findstr "5000", tasklist | findstr "LISTENER from netstat query" -// AsynchClientTask imageJTask = new AsynchClientTask("contact ImageJ...",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { -// @Override -// public void run(Hashtable hashTable) throws Exception { -// File imageJFile = ImageJHelper.vcellWantImage(getClientTaskStatusSupport(),"image for new FieldData"); -// hashTable.put(IMAGE_FILE_KEY, imageJFile); -// } -// }; -// AsynchClientTask[] tasks = fdFromFile(); -// tasks = BeanUtils.addElements(new AsynchClientTask[] {imageJTask}, tasks); -// ClientTaskDispatcher.dispatch(this, new Hashtable<>(), tasks, false, true, null); -//} - -String IMAGE_FILE_KEY = "imageFile"; -private AsynchClientTask[] fdFromFile() { - final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); - AsynchClientTask[] addTasks = addNewExternalData(this,this,false); - AsynchClientTask[] taskArray = new AsynchClientTask[2 + addTasks.length]; - System.arraycopy(addTasks, 0, taskArray, 2, addTasks.length); // add to the end - - taskArray[0] = new AsynchClientTask("select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - public void run(Hashtable hashTable) throws Exception { - FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec)hashTable.get("argfdos"); - if (argfdos == null && hashTable.get(IMAGE_FILE_KEY) == null) { - File imageFile = DatabaseWindowManager.showFileChooserDialog( - fieldDataWindowManager.getComponent(), FileFilters.FILE_FILTER_FIELDIMAGES, - clientRequestManager.getUserPreferences(),JFileChooser.FILES_AND_DIRECTORIES); - hashTable.put(IMAGE_FILE_KEY, imageFile); - } - } - }; - taskArray[1] = new AsynchClientTask("Import image", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - public void run(Hashtable hashTable) throws Exception { - FieldDataFileOperationSpec fdos = null; - String initFDName = null; - - FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec)hashTable.get("argfdos"); - String arginitFDName = (String)hashTable.get("arginitFDName"); - if (argfdos == null) { - File imageFile = (File)hashTable.get(IMAGE_FILE_KEY); - if (imageFile == null) { - return; - } - initFDName = imageFile.getName(); - if(initFDName.indexOf(".vfrap") > -1) - { -/* //read the image dataset from Virtual FRAP xml file - System.out.println("Loading " + initFDName + " ..."); - - AnnotatedImageDataset annotatedImages = null; - String xmlString; - try { - xmlString = XmlUtil.getXMLString(imageFile.getAbsolutePath()); - MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true); - annotatedImages = xmlReader.getAnnotatedImageDataset(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport()); - OverlayEditorPanelJAI overlayPanel = new OverlayEditorPanelJAI(); - overlayPanel.setImages(annotatedImages.getImageDataset(), 1, 0, new OverlayEditorPanelJAI.AllPixelValuesRange(1, 200) ); - DialogUtils.showComponentCloseDialog(FieldDataGUIPanel.this, overlayPanel, "this is it"); - } catch (Exception e) { - e.printStackTrace(System.out); - } */ - } - else //not a .vfrap file - { - try { - fdos = ClientRequestManager.createFDOSFromImageFile(imageFile,false,null); - } catch (DataFormatException ex) { - throw new Exception("Cannot read image " + imageFile.getAbsolutePath()+"\n"+ex.getMessage()); - } - } - }else{ - fdos = argfdos; - initFDName = arginitFDName; - } - - fdos.owner = clientRequestManager.getDocumentManager().getUser(); - fdos.opType = FieldDataFileOperationSpec.FDOS_ADD; - hashTable.put("fdos", fdos); - hashTable.put("initFDName", initFDName); - //addNewExternalData(clientRequestManager, fdos, initFDName, false); - } - }; - return taskArray; -} - -private void jButtonFDDelete_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - - final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); - - - TreePath selPath = getJTree1().getSelectionPath(); - final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)selPath.getLastPathComponent(); - final FieldDataMainList fieldDataMainList = (FieldDataMainList)mainNode.getUserObject(); - - if(!fieldDataMainList.externalDataIdentifier.getOwner().equals( - clientRequestManager.getDocumentManager().getUser())){ - DialogUtils.showErrorDialog(this, "Delete failed: User "+clientRequestManager.getDocumentManager().getUser().getName()+ - "does not own FieldData '"+fieldDataMainList.externalDataIdentifier.getName()+"'"); - } - if(PopupGenerator.showComponentOKCancelDialog( - this, new JLabel("Delete "+fieldDataMainList.externalDataIdentifier.getName()+"?"), - "Confirm Delete") != JOptionPane.OK_OPTION){ - return; - - } - AsynchClientTask CheckRemoveFromDBTask = new AsynchClientTask("Check Field Data references in DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - public void run(Hashtable hash) throws Exception { - if(fieldDataWindowManager.findReferencingModels(fieldDataMainList.externalDataIdentifier, false)){ - throw new Exception("Cannot delete Field Data '"+fieldDataMainList.externalDataIdentifier.getName()+ - "' because it is referenced in a Model(s) or Function(s) file."); - } - } - }; - AsynchClientTask RemoveNodeTreeTask = new AsynchClientTask("Remove FieldData tree node", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - public void run(Hashtable hash) throws Exception { - ((DefaultTreeModel)getJTree1().getModel()).removeNodeFromParent(mainNode); - if(((DefaultMutableTreeNode)getJTree1().getModel().getRoot()).getChildCount() == 0){ - updateJTree(clientRequestManager); - } - } - }; - AsynchClientTask RemoveFromDiskAndDBTask = new AsynchClientTask("Remove Field Data from Disk and DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - public void run(Hashtable hash) throws Exception { - //Remove from Disk - FieldDataMainList fieldDataMainList = (FieldDataMainList)mainNode.getUserObject(); - FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createDeleteFieldDataFileOperationSpec( - fieldDataMainList.externalDataIdentifier); - clientRequestManager.getDocumentManager().fieldDataFileOperation(fdos); - //Remove from DB - fieldDataWindowManager.deleteExternalDataIdentifier(fieldDataMainList.externalDataIdentifier); - } - }; - // - //Execute Field Data Info - JTree tasks - // - AsynchClientTask tasks[] = new AsynchClientTask[] { CheckRemoveFromDBTask,RemoveFromDiskAndDBTask,RemoveNodeTreeTask}; - Hashtable hash = new Hashtable(); - ClientTaskDispatcher.dispatch(this,hash,tasks,false); - -} - private class SelectedTimes{ - private double[] times; - private int selectedIndex; - public SelectedTimes(double[] times, int selectedIndex) { - super(); - this.times = times; - this.selectedIndex = selectedIndex; - } - public double[] getTimes() { - return times; - } - public int getSelectedIndex() { - return selectedIndex; - } - - } -private SelectedTimes selectTimeFromNode(DefaultMutableTreeNode mainNode){ - Enumeration children = mainNode.children(); - double[] times = null; - while(children.hasMoreElements()){ - DefaultMutableTreeNode child = (DefaultMutableTreeNode)children.nextElement(); - if(child.getUserObject() instanceof FieldDataTimeList){ - times = ((FieldDataTimeList)child.getUserObject()).times; - break; - } - } - - if(times != null && times.length > 1){ - String[] timesStr = new String[times.length]; - for(int i=0;i jcBeg = new JComboBox(Arrays.asList(timesStr).toArray(new Object[0])); - jp.add(jcBeg); - - if(PopupGenerator.showComponentOKCancelDialog(this, jp,"Select Field Data timepoint") ==JOptionPane.OK_OPTION){ - return new SelectedTimes(times, jcBeg.getSelectedIndex()); - } - throw UserCancelException.CANCEL_GENERIC; - } - return new SelectedTimes(new double[] {0.0}, 0); -} -private void jButtonFDCopyRef_ActionPerformed(java.awt.event.ActionEvent actionEvent) { - if(actionEvent.getSource() == getJButtonCreateGeom()){ - DocumentWindow.showGeometryCreationWarning(FieldDataGUIPanel.this); - return; - } - TreePath selPath = getJTree1().getSelectionPath(); - final DefaultMutableTreeNode varNode = (DefaultMutableTreeNode)selPath.getLastPathComponent(); - final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)varNode.getParent().getParent(); - - SelectedTimes selectedTimes = null; - try{ - selectedTimes = selectTimeFromNode(mainNode); - }catch(UserCancelException e){ - return; - } - double selectedTime = selectedTimes.getTimes()[selectedTimes.getSelectedIndex()]; - - if(actionEvent.getSource() == getJButtonFDCopyRef()){ - String fieldFunctionReference = - SimulationData.createCanonicalFieldFunctionSyntax( - ((FieldDataMainList)mainNode.getUserObject()).externalDataIdentifier.getName(), - ((FieldDataVarList)varNode.getUserObject()).dataIdentifier.getName(), - selectedTime,((FieldDataVarList)varNode.getUserObject()).dataIdentifier.getVariableType().getTypeName()); - - VCellTransferable.sendToClipboard(fieldFunctionReference); - }else if(actionEvent.getSource() == dsDataSymbolButton && dataSymbolCallBack != null){ - dataSymbolCallBack.createDataSymbol( - ((FieldDataMainList)mainNode.getUserObject()).externalDataIdentifier, - ((FieldDataVarList)varNode.getUserObject()).dataIdentifier.getName(), - ((FieldDataVarList)varNode.getUserObject()).dataIdentifier.getVariableType(), - selectedTime); - } - -} - -private void jTree1_TreeExpanded(final javax.swing.event.TreeExpansionEvent treeExpansionEvent) { - if(fieldDataWindowManager == null){ - return; - } - // - //Determine if we need to get Info - // - javax.swing.tree.TreePath expPath = null; - try{ - expPath = treeExpansionEvent.getPath(); - if(expPath != null){ - DefaultMutableTreeNode mainNode = (javax.swing.tree.DefaultMutableTreeNode)expPath.getLastPathComponent(); + if (lastPathComponent.getUserObject() instanceof FieldDataMainList) { + getJButtonFDDelete().setEnabled(true); + getJButtonFDView().setEnabled(fieldDataWindowManager != null); + dsViewButton.setEnabled(fieldDataWindowManager != null); + getJButtonFindRefModel().setEnabled(true); + getJButtonViewAnnot().setEnabled(true); + dsAnnotButton.setEnabled(true); + } else if (lastPathComponent.getUserObject() instanceof FieldDataVarList) { + getJButtonFDCopyRef().setEnabled(true); + dsDataSymbolButton.setEnabled(true); + getJButtonCreateGeom().setEnabled(true); + } + } + } + + private void jButtonFDFromSim_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + try { + final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); + + final FieldDataWindowManager.OpenModelInfoHolder simInfoHolder = FieldDataWindowManager.selectOpenModelsFromDesktop(this, fieldDataWindowManager.getRequestManager(), true, "Select Simulation for Field Data", true); + if (simInfoHolder == null) { + PopupGenerator.showErrorDialog(this, "Please open a Bio or Math model containing the spatial (non-compartmental) simulation you wish to use to create a new Field Data"); + return; + } + //Check that the sim is in a state that can be copied + final SimulationInfo simInfo = simInfoHolder.getSimInfo(); + if (simInfo == null) { + throw new Exception("Selected sim '" + simInfoHolder.getSimName() + "' has no simInfo (save your model and retry)."); + } + SimulationStatus simStatus = clientRequestManager.getServerSimulationStatus(simInfo); + if (simStatus != null && (simStatus.isRunning() || simStatus.isStartRequested())) { + throw new Exception("Can't copy 'running' simulation data from sim '" + simInfo.getName() + "'"); + } + + final FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createCopySimFieldDataFileOperationSpec(null, + (simInfo.getParentSimulationReference() != null ? simInfo.getParentSimulationReference() : simInfo.getSimulationVersion().getVersionKey()), + simInfo.getOwner(), simInfoHolder.getJobIndex(), clientRequestManager.getDocumentManager().getUser()); + + AsynchClientTask[] addTasks = addNewExternalData(this, this, true); + AsynchClientTask[] taskArray = new AsynchClientTask[1 + addTasks.length]; + System.arraycopy(addTasks, 0, taskArray, 1, addTasks.length); // add to the end + + taskArray[0] = new AsynchClientTask("Create Field Data from Simulation", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + public void run(Hashtable hashTable) throws Exception { + FieldDataFileOperationResults fdor = + clientRequestManager.getDocumentManager().fieldDataFileOperation( + FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec( + (simInfo.getParentSimulationReference() != null ? + simInfo.getParentSimulationReference() : + simInfo.getSimulationVersion().getVersionKey() + ), + simInfo.getOwner(), + simInfoHolder.getJobIndex())); + //Create (non-editable) info for display + fdos.origin = fdor.origin; + fdos.extent = fdor.extent; + fdos.isize = fdor.iSize; + fdos.times = fdor.times; + fdos.varNames = new String[fdor.dataIdentifierArr.length]; + for (int i = 0; i < fdor.dataIdentifierArr.length; i += 1) { + fdos.varNames[i] = + (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.VOLUME) ? "(vol) " : "") + + (fdor.dataIdentifierArr[i].getVariableType().equals(VariableType.MEMBRANE) ? "(mbr) " : "") + + fdor.dataIdentifierArr[i].getName(); + } + hashTable.put("fdos", fdos); + hashTable.put("initFDName", simInfo.getName()); + //addNewExternalData(clientRequestManager, fdos, simInfoHolder.simInfo.getName(), true); + } + }; + + Hashtable hash = new Hashtable(); + ClientTaskDispatcher.dispatch(this, hash, taskArray, false); + + } catch (UserCancelException e) { + return; + } catch (Exception e) { + PopupGenerator.showErrorDialog(this, "Error creating Field Data from simulation\n" + e.getMessage(), e); + } + } + + private void jButtonFDView_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + if (fieldDataWindowManager == null) { + System.out.println("No FieldDataViewManager available for View action"); + return; + } + javax.swing.tree.TreePath selPath = getFieldDataTree().getSelectionPath(); + if (selPath != null) { + javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent(); + if (lastPathComponent.getUserObject() instanceof FieldDataMainList) { + ExternalDataIdentifier edi = ((FieldDataMainList) lastPathComponent.getUserObject()).externalDataIdentifier; + fieldDataWindowManager.viewData(edi); + } + } + } + + + private void jButtonFDFromFile_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + Hashtable hash = new Hashtable(); + + AsynchClientTask[] tasks = fdFromFile(); + ClientTaskDispatcher.dispatch(this, hash, tasks, false, true, null); + + } + + String IMAGE_FILE_KEY = "imageFile"; + + private AsynchClientTask[] fdFromFile() { + final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); + AsynchClientTask[] addTasks = addNewExternalData(this, this, false); + AsynchClientTask[] taskArray = new AsynchClientTask[2 + addTasks.length]; + System.arraycopy(addTasks, 0, taskArray, 2, addTasks.length); // add to the end + + taskArray[0] = new AsynchClientTask("select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + public void run(Hashtable hashTable) throws Exception { + FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec) hashTable.get("argfdos"); + if (argfdos == null && hashTable.get(IMAGE_FILE_KEY) == null) { + File imageFile = DatabaseWindowManager.showFileChooserDialog( + fieldDataWindowManager.getComponent(), FileFilters.FILE_FILTER_FIELDIMAGES, + clientRequestManager.getUserPreferences(), JFileChooser.FILES_AND_DIRECTORIES); + hashTable.put(IMAGE_FILE_KEY, imageFile); + } + } + }; + taskArray[1] = new AsynchClientTask("Import image", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + public void run(Hashtable hashTable) throws Exception { + FieldDataFileOperationSpec fdos = null; + String initFDName = null; + + FieldDataFileOperationSpec argfdos = (FieldDataFileOperationSpec) hashTable.get("argfdos"); + String arginitFDName = (String) hashTable.get("arginitFDName"); + if (argfdos == null) { + File imageFile = (File) hashTable.get(IMAGE_FILE_KEY); + if (imageFile == null) { + return; + } + initFDName = imageFile.getName(); + if (initFDName.indexOf(".vfrap") > -1) { + } else //not a .vfrap file + { + try { + fdos = ClientRequestManager.createFDOSFromImageFile(imageFile, false, null); + } catch (DataFormatException ex) { + throw new Exception("Cannot read image " + imageFile.getAbsolutePath() + "\n" + ex.getMessage()); + } + } + } else { + fdos = argfdos; + initFDName = arginitFDName; + } + + fdos.owner = clientRequestManager.getDocumentManager().getUser(); + fdos.opType = FieldDataFileOperationSpec.FDOS_ADD; + hashTable.put("fdos", fdos); + hashTable.put("initFDName", initFDName); + //addNewExternalData(clientRequestManager, fdos, initFDName, false); + } + }; + return taskArray; + } + + private void jButtonFDDelete_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + + final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); + + + TreePath selPath = getFieldDataTree().getSelectionPath(); + final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) selPath.getLastPathComponent(); + final FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject(); + + if (!fieldDataMainList.externalDataIdentifier.getOwner().equals( + clientRequestManager.getDocumentManager().getUser())) { + DialogUtils.showErrorDialog(this, "Delete failed: User " + clientRequestManager.getDocumentManager().getUser().getName() + + "does not own FieldData '" + fieldDataMainList.externalDataIdentifier.getName() + "'"); + } + if (PopupGenerator.showComponentOKCancelDialog( + this, new JLabel("Delete " + fieldDataMainList.externalDataIdentifier.getName() + "?"), + "Confirm Delete") != JOptionPane.OK_OPTION) { + return; + + } + AsynchClientTask CheckRemoveFromDBTask = new AsynchClientTask("Check Field Data references in DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + public void run(Hashtable hash) throws Exception { + if (fieldDataWindowManager.findReferencingModels(fieldDataMainList.externalDataIdentifier, false)) { + throw new Exception("Cannot delete Field Data '" + fieldDataMainList.externalDataIdentifier.getName() + + "' because it is referenced in a Model(s) or Function(s) file."); + } + } + }; + AsynchClientTask RemoveNodeTreeTask = new AsynchClientTask("Remove FieldData tree node", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + public void run(Hashtable hash) throws Exception { + ((DefaultTreeModel) getFieldDataTree().getModel()).removeNodeFromParent(mainNode); + if (((DefaultMutableTreeNode) getFieldDataTree().getModel().getRoot()).getChildCount() == 0) { + updateJTree(clientRequestManager); + } + } + }; + AsynchClientTask RemoveFromDiskAndDBTask = new AsynchClientTask("Remove Field Data from Disk and DB", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + public void run(Hashtable hash) throws Exception { + //Remove from Disk + FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject(); + FieldDataFileOperationSpec fdos = FieldDataFileOperationSpec.createDeleteFieldDataFileOperationSpec( + fieldDataMainList.externalDataIdentifier); + clientRequestManager.getDocumentManager().fieldDataFileOperation(fdos); + //Remove from DB + fieldDataWindowManager.deleteExternalDataIdentifier(fieldDataMainList.externalDataIdentifier); + } + }; + // + //Execute Field Data Info - JTree tasks + // + AsynchClientTask tasks[] = new AsynchClientTask[]{CheckRemoveFromDBTask, RemoveFromDiskAndDBTask, RemoveNodeTreeTask}; + Hashtable hash = new Hashtable(); + ClientTaskDispatcher.dispatch(this, hash, tasks, false); + + } + + private class SelectedTimes { + private double[] times; + private int selectedIndex; + + public SelectedTimes(double[] times, int selectedIndex) { + super(); + this.times = times; + this.selectedIndex = selectedIndex; + } + + public double[] getTimes() { + return times; + } + + public int getSelectedIndex() { + return selectedIndex; + } + + } + + private SelectedTimes selectTimeFromNode(DefaultMutableTreeNode mainNode) { + Enumeration children = mainNode.children(); + double[] times = null; + while (children.hasMoreElements()) { + DefaultMutableTreeNode child = (DefaultMutableTreeNode) children.nextElement(); + if (child.getUserObject() instanceof FieldDataTimeList) { + times = ((FieldDataTimeList) child.getUserObject()).times; + break; + } + } + + if (times != null && times.length > 1) { + String[] timesStr = new String[times.length]; + for (int i = 0; i < times.length; i += 1) { + timesStr[i] = times[i] + ""; + } + JPanel jp = new JPanel(); + BoxLayout bl = new BoxLayout(jp, BoxLayout.X_AXIS); + jp.setLayout(bl); + JComboBox jcBeg = new JComboBox(Arrays.asList(timesStr).toArray(new Object[0])); + jp.add(jcBeg); + + if (PopupGenerator.showComponentOKCancelDialog(this, jp, "Select Field Data timepoint") == JOptionPane.OK_OPTION) { + return new SelectedTimes(times, jcBeg.getSelectedIndex()); + } + throw UserCancelException.CANCEL_GENERIC; + } + return new SelectedTimes(new double[]{0.0}, 0); + } + + private void jButtonFDCopyRef_ActionPerformed(java.awt.event.ActionEvent actionEvent) { + if (actionEvent.getSource() == getJButtonCreateGeom()) { + DocumentWindow.showGeometryCreationWarning(FieldDataGUIPanel.this); + return; + } + TreePath selPath = getFieldDataTree().getSelectionPath(); + final DefaultMutableTreeNode varNode = (DefaultMutableTreeNode) selPath.getLastPathComponent(); + final DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) varNode.getParent().getParent(); + + SelectedTimes selectedTimes = null; + try { + selectedTimes = selectTimeFromNode(mainNode); + } catch (UserCancelException e) { + return; + } + double selectedTime = selectedTimes.getTimes()[selectedTimes.getSelectedIndex()]; + + if (actionEvent.getSource() == getJButtonFDCopyRef()) { + String fieldFunctionReference = + SimulationData.createCanonicalFieldFunctionSyntax( + ((FieldDataMainList) mainNode.getUserObject()).externalDataIdentifier.getName(), + ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getName(), + selectedTime, ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getVariableType().getTypeName()); + + VCellTransferable.sendToClipboard(fieldFunctionReference); + } else if (actionEvent.getSource() == dsDataSymbolButton && dataSymbolCallBack != null) { + dataSymbolCallBack.createDataSymbol( + ((FieldDataMainList) mainNode.getUserObject()).externalDataIdentifier, + ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getName(), + ((FieldDataVarList) varNode.getUserObject()).dataIdentifier.getVariableType(), + selectedTime); + } + + } + + private void jTree1_TreeExpanded(final javax.swing.event.TreeExpansionEvent treeExpansionEvent) { + if (fieldDataWindowManager == null) { + return; + } + // + //Determine if we need to get Info + // + javax.swing.tree.TreePath expPath = null; + try { + expPath = treeExpansionEvent.getPath(); + if (expPath != null) { + DefaultMutableTreeNode mainNode = (javax.swing.tree.DefaultMutableTreeNode) expPath.getLastPathComponent(); // if(mainNode.equals(getJTree1().getModel().getRoot())){ // System.out.println("Root Node expanded"); // } - if(mainNode.getUserObject() instanceof FieldDataMainList){ - if(mainNode.getChildCount() > 1){//Already populated - return; - } - refreshMainNode(mainNode); - }else{ - return; - } - }else{ - return; - } - }catch(Exception e){ - PopupGenerator.showErrorDialog(this, "Error getting Field Data Info\n"+e.getMessage(), e); - return; - } - -} - -public void refreshExternalDataIdentifierNode(ExternalDataIdentifier refreshEDI){ - DefaultMutableTreeNode root = (DefaultMutableTreeNode)getJTree1().getModel().getRoot(); - if(root != null){ - int childCount = root.getChildCount(); - for(int i=0;i hash) throws Exception { - FieldDataMainList fieldDataMainList = (FieldDataMainList)mainNode.getUserObject(); - final FieldDataFileOperationResults fieldDataFileOperationResults = - clientRequestManager.getDocumentManager(). - fieldDataFileOperation( - FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec( - fieldDataMainList.externalDataIdentifier.getKey(), - clientRequestManager.getDocumentManager().getUser(), - FieldDataFileOperationSpec.JOBINDEX_DEFAULT) - ); - hash.put(FDOR_INFO,fieldDataFileOperationResults); - } - }; - - AsynchClientTask FieldDataInfoTreeUpdate = new AsynchClientTask("Update Field Data GUI", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - public void run(Hashtable hash){ - try{ - FieldDataFileOperationResults fieldDataFileOperationResults = - (FieldDataFileOperationResults)hash.get(FDOR_INFO); - Arrays.sort(fieldDataFileOperationResults.dataIdentifierArr, - new Comparator(){ - public int compare(DataIdentifier o1, DataIdentifier o2) { - return o1.getName().compareToIgnoreCase(o2.getName()); - } - } - ); - FieldDataMainList fieldDataMainList = (FieldDataMainList)mainNode.getUserObject(); - final DefaultMutableTreeNode isizeNode = - new DefaultMutableTreeNode(new FieldDataISizeList(fieldDataFileOperationResults.iSize)); - final DefaultMutableTreeNode originNode = - new DefaultMutableTreeNode(new FieldDataOriginList(fieldDataFileOperationResults.origin)); - final DefaultMutableTreeNode extentNode = - new DefaultMutableTreeNode(new FieldDataExtentList(fieldDataFileOperationResults.extent)); - final DefaultMutableTreeNode timeNode = - new DefaultMutableTreeNode(new FieldDataTimeList(fieldDataFileOperationResults.times)); - final DefaultMutableTreeNode idNode = - new DefaultMutableTreeNode(new FieldDataIDList(fieldDataMainList.externalDataIdentifier.getKey())); - ((DefaultTreeModel)getJTree1().getModel()).insertNodeInto(isizeNode,mainNode,0); - ((DefaultTreeModel)getJTree1().getModel()).insertNodeInto(originNode,mainNode,1); - ((DefaultTreeModel)getJTree1().getModel()).insertNodeInto(extentNode,mainNode,2); - ((DefaultTreeModel)getJTree1().getModel()).insertNodeInto(timeNode,mainNode,3); - ((DefaultTreeModel)getJTree1().getModel()).insertNodeInto(idNode,mainNode,4); - for(int i=0;i hash = new Hashtable(); - ClientTaskDispatcher.dispatch(this,hash,tasks,false); -} - -/** - * main entrypoint - starts the part when it is run as an application - * @param args java.lang.String[] - */ -public static void main(java.lang.String[] args) { - try { - javax.swing.JFrame frame = new javax.swing.JFrame(); - FieldDataGUIPanel aFieldDataGUIPanel; - aFieldDataGUIPanel = new FieldDataGUIPanel(); - frame.setContentPane(aFieldDataGUIPanel); - frame.setSize(aFieldDataGUIPanel.getSize()); - frame.addWindowListener(new java.awt.event.WindowAdapter() { - public void windowClosing(java.awt.event.WindowEvent e) { - System.exit(0); - }; - }); - frame.setVisible(true); - java.awt.Insets insets = frame.getInsets(); - frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom); - frame.setVisible(true); - } catch (Throwable exception) { - System.err.println("Exception occurred in main() of javax.swing.JPanel"); - exception.printStackTrace(System.out); - } -} - -public void setFieldDataWindowManager(FieldDataWindowManager fdwm){ - fieldDataWindowManager = fdwm; -} - -public void checkFieldDataName(String fieldDataName) throws Exception{ - if(fieldDataName == null || fieldDataName.length() == 0 || - !fieldDataName.equals(TokenMangler.fixTokenStrict(fieldDataName))){ - throw new Exception("Field Data names can contain only letters,digits and underscores"); - } - //Check to see if this name is already used - DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode)this.getJTree1().getModel().getRoot(); - if(!rootNode.getUserObject().toString().startsWith(FIELD_DATA_INFO)) { - updateJTree(fieldDataWindowManager.getLocalRequestManager()); - rootNode = (DefaultMutableTreeNode)this.getJTree1().getModel().getRoot(); - } - for(int i=0;i hashTable) throws Exception { - //Check if this is ImageJ op, if so, this task unnecessary - if(hashTable.get(USER_DEFINED_FDOS) != null && hashTable.get(FIELD_NAME) != null) { - return; - } - //Allow user to review/change info about fielddata - FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec)hashTable.get("fdos"); - String initialExtDataName = (String)hashTable.get("initFDName"); - - fdos.specEDI = null; - - FieldDataInfoPanel fdip = new FieldDataInfoPanel(); - fdip.setSimulationMode(isFromSimulation); - fdip.initISize(fdos.isize); - fdip.initIOrigin(fdos.origin); - fdip.initIExtent(fdos.extent); - fdip.initTimes(fdos.times); - fdip.initNames(TokenMangler.fixTokenStrict(initialExtDataName), fdos.varNames); - fdip.setAnnotation(fdos.annotation); - - FieldDataFileOperationSpec userDefinedFDOS = new FieldDataFileOperationSpec(); - while(true) { - int choice = PopupGenerator.showComponentOKCancelDialog(requester, fdip, "Create new field data"); - if (choice == JOptionPane.OK_OPTION){ - //Check values - try{ - userDefinedFDOS.extent = fdip.getExtent(); - }catch(Exception e){ - PopupGenerator.showErrorDialog(requester, "Problem with Extent values. Please re-enter.\n"+e.getMessage()+"\nTry Again.", e); - continue; - } - try{ - userDefinedFDOS.origin = fdip.getOrigin(); - }catch(Exception e){ - PopupGenerator.showErrorDialog(requester, "Problem with Origin values. Please re-enter.\n"+e.getMessage()+"\nTry Again.", e); - continue; - } - try{ - userDefinedFDOS.varNames = fdip.getVariableNames(); - }catch(Exception e){ - PopupGenerator.showErrorDialog(requester, "Problem with Variable names. Please re-enter.\n"+e.getMessage()+"\nTry Again.", e); - continue; - } - userDefinedFDOS.annotation = fdip.getAnnotation(); - userDefinedFDOS.times = fdip.getTimes(); - try{ - fieldDataGUIPanel.checkFieldDataName(fdip.getFieldName()); - }catch(Exception e){ - PopupGenerator.showErrorDialog(requester, "Error saving Field Data Name to Database. Try again.\n"+e.getMessage(), e); - continue; - } - hashTable.put(USER_DEFINED_FDOS, userDefinedFDOS); - hashTable.put(FIELD_NAME, fdip.getFieldName()); - break; - } else { - throw UserCancelException.CANCEL_GENERIC; - } - } - } - }; - - AsynchClientTask task2 = new AsynchClientTask("saving field data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - @Override - public void run(Hashtable hashTable) throws Exception { - //Add to Server Disk - //save Database - FieldDataFileOperationSpec tempFDOS = (FieldDataFileOperationSpec)hashTable.get(USER_DEFINED_FDOS); - String fieldName = (String)hashTable.get(FIELD_NAME); - - FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec)hashTable.get("fdos"); - DocumentManager documentManager = clientRequestManager.getDocumentManager(); - FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(),fieldName,tempFDOS.annotation); - tempFDOS.specEDI = documentManager.fieldDataDBOperation(newExtDataIDSpec).extDataID; - fdos.specEDI = tempFDOS.specEDI; - fdos.annotation = tempFDOS.annotation; - - try{ - if(!isFromSimulation){ - fdos.extent = tempFDOS.extent; - fdos.origin = tempFDOS.origin; - fdos.varNames = tempFDOS.varNames; - fdos.times = tempFDOS.times; - // - //Subvolumes and Regions NOT implemented now - // - fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, - new RegionImage(new VCImageUncompressed(null, new byte[fdos.isize.getXYZ()],//empty regions - fdos.extent, fdos.isize.getX(),fdos.isize.getY(),fdos.isize.getZ()), - 0,null,null,RegionImage.NO_SMOOTHING)); - } - - //Add to Server Disk - documentManager.fieldDataFileOperation(fdos); - } catch (Exception e) { - try{ - //try to cleanup new ExtDataID - documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI)); - }catch(Exception e2){ - //ignore - } - fdos.specEDI = null; - throw e; - } - } - }; - - AsynchClientTask task3 = new AsynchClientTask("refreshing field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - @Override - public void run(Hashtable hashTable) throws Exception { - FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec)hashTable.get("fdos"); - - DefaultMutableTreeNode root = ((DefaultMutableTreeNode)fieldDataGUIPanel.getJTree1().getModel().getRoot()); - if (root.getChildCount() == 0) { - fieldDataGUIPanel.updateJTree(clientRequestManager); - } else { - int alphabeticalIndex = -1; - for(int i=0;i 0){ - alphabeticalIndex = i; - break; - } - } - if (alphabeticalIndex == -1){ - alphabeticalIndex = root.getChildCount(); - } - DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(fdos.specEDI,fdos.annotation)); - mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList())); - ((DefaultTreeModel)fieldDataGUIPanel.getJTree1().getModel()).insertNodeInto(mainNode, root, alphabeticalIndex); - } - } - }; - - return new AsynchClientTask[] { task1, task2, task3 }; -} - -/** - * This method initializes jButtonFindRefModel - * - * @return javax.swing.JButton - */ -private JButton getJButtonFindRefModel() { - if (jButtonFindRefModel == null) { - jButtonFindRefModel = new JButton(); - jButtonFindRefModel.setText("Model Refs..."); - jButtonFindRefModel.setEnabled(false); - jButtonFindRefModel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - TreePath selPath = getJTree1().getSelectionPath(); - DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode)selPath.getLastPathComponent(); - if(mainNode.getUserObject() instanceof FieldDataMainList){ - final ExternalDataIdentifier extDataID = ((FieldDataMainList)mainNode.getUserObject()).externalDataIdentifier; - - AsynchClientTask task1 = new AsynchClientTask("find model references", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { - - @Override - public void run(Hashtable hashTable) throws Exception { - fieldDataWindowManager.findReferencingModels(extDataID,true); - } - }; - ClientTaskDispatcher.dispatch(FieldDataGUIPanel.this, new Hashtable(), new AsynchClientTask[] { task1 }, false); - } - } - }); - } - return jButtonFindRefModel; -} - -/** - * This method initializes jPanel - * - * @return javax.swing.JPanel - */ -private JPanel getJPanel() { - if (jPanel == null) { - GridBagConstraints gridBagConstraints = new GridBagConstraints(); - gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; - gridBagConstraints.gridx = 1; - gridBagConstraints.gridy = 0; - gridBagConstraints.weightx = 1.0; - gridBagConstraints.insets = new Insets(4, 4, 4, 4); - GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); - gridBagConstraints2.gridx = 0; - gridBagConstraints2.insets = new Insets(4, 4, 4, 4); - gridBagConstraints2.gridy = 0; - jPanel = new JPanel(); - jPanel.setLayout(new GridBagLayout()); - jPanel.add(getJButtonCreateGeom(), gridBagConstraints2); - jPanel.add(getJButtonFindRefModel(), gridBagConstraints); - } - return jPanel; -} - -/** - * This method initializes jButtonCopyInfo - * - * @return javax.swing.JButton - */ -private JButton getJButtonCreateGeom() { - if (jButtonCreateGeom == null) { - jButtonCreateGeom = new JButton(); - jButtonCreateGeom.setEnabled(false); - jButtonCreateGeom.setText("Create Geom"); - jButtonCreateGeom.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - try { - RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); - javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); - javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); - if(lastPathComponent.getUserObject() instanceof FieldDataVarList){ - DataIdentifier dataIdentifier = - ((FieldDataVarList)lastPathComponent.getUserObject()).dataIdentifier; - - TreePath ppPath = selPath.getParentPath().getParentPath(); - javax.swing.tree.DefaultMutableTreeNode ppLastPathComp = (javax.swing.tree.DefaultMutableTreeNode)ppPath.getLastPathComponent(); - if(ppLastPathComp.getUserObject() instanceof FieldDataMainList){ - ExternalDataIdentifier extDataID = - ((FieldDataMainList)ppLastPathComp.getUserObject()).externalDataIdentifier; - - final OpenModelInfoHolder openModelInfoHolder = - FieldDataWindowManager.selectOpenModelsFromDesktop(FieldDataGUIPanel.this,fieldDataWindowManager.getRequestManager(),false,"Select BioModel or MathModel to receive new geometry",false); - if(openModelInfoHolder == null){ - DialogUtils.showErrorDialog(FieldDataGUIPanel.this, - "Before proceeding, please open a Biomodel application or Mathmodel you wish to apply a new Field Data Geometry to"); - return; - } - - AsynchClientTask applyGeomTask = new AsynchClientTask("apply geometry",AsynchClientTask.TASKTYPE_SWING_BLOCKING) { - @Override - public void run(Hashtable hashTable) throws Exception { - Geometry newGeom = (Geometry)hashTable.get("doc"); - final String OK_OPTION = "Ok"; - if(openModelInfoHolder instanceof FDSimMathModelInfo){ - Version version = ((FDSimMathModelInfo)openModelInfoHolder).getMathModelVersion(); - String modelName = (version==null?"NoName":version.getName()); - if(newGeom.getName() == null){ - newGeom.setName(modelName+"_"+BeanUtils.generateDateTimeString()); - } - String message = "Confirm Setting new FieldData derived geometry on MathModel '"+modelName+"'"; - if(DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[] {OK_OPTION,"Cancel"}, OK_OPTION).equals(OK_OPTION)){ - ((FDSimMathModelInfo)openModelInfoHolder).getMathDescription().setGeometry(newGeom); - } - }else if(openModelInfoHolder instanceof FDSimBioModelInfo){ - Version version = ((FDSimBioModelInfo)openModelInfoHolder).getBioModelVersion(); - String modelName = (version==null?"NoName":version.getName()); - String simContextName = ((FDSimBioModelInfo)openModelInfoHolder).getSimulationContext().getName(); - if(newGeom.getName() == null){ - newGeom.setName(modelName+"_"+simContextName+"_"+BeanUtils.generateDateTimeString()); - } - String message = "Confirm Setting new FieldData derived geometry on BioModel '"+modelName+"' , Application '"+simContextName+"'"; - if(DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[] {OK_OPTION,"Cancel"}, OK_OPTION).equals(OK_OPTION)){ - ((FDSimBioModelInfo)openModelInfoHolder).getSimulationContext().setGeometry(newGeom); - } - } - } - }; - VCDocument.GeomFromFieldDataCreationInfo geomFromFieldDataCreationInfo = - new VCDocument.GeomFromFieldDataCreationInfo( - extDataID,dataIdentifier.getName()); - AsynchClientTask[] createGeomTask = clientRequestManager.createNewGeometryTasks(fieldDataWindowManager, - geomFromFieldDataCreationInfo, - new AsynchClientTask[] {applyGeomTask}, - "Apply Geometry"); - - Hashtable hash = new Hashtable(); - hash.put(ClientRequestManager.GUI_PARENT, fieldDataWindowManager.getComponent()); - ClientTaskDispatcher.dispatch(FieldDataGUIPanel.this, hash, - createGeomTask, false,false,null,true); - - } - - } - }catch (UserCancelException e1) { - //ignore - }catch (Exception e1) { - e1.printStackTrace(); - DialogUtils.showErrorDialog(FieldDataGUIPanel.this, e1.getMessage()); - } - -// jButtonFDCopyRef_ActionPerformed(e); - - - - //fieldDataWindowManager.newDocument(VCDocument.GEOMETRY_DOC, option); -// copyMethod(COPY_CRNL); -//// javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); -//// if(selPath != null){ -//// javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); -//// copyMethod(lastPathComponent, copyMode); -//// } -//// String copyString = ""; -//// javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); -//// if(lastPathComponent.equals(getJTree1().getModel().getRoot())){ -//// int childCount = lastPathComponent.getChildCount(); -//// for(int i=0;i 0 ){ -//// VCellTransferable.sendToClipboard(copyString); -//// } -//// } - } - }); - } - return jButtonCreateGeom; -} - -/** - * This method initializes jPanel1 - * - * @return javax.swing.JPanel - */ -private JPanel getJPanel12() { - if (jPanel1 == null) { - GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); - gridBagConstraints3.gridx = 1; - gridBagConstraints3.insets = new Insets(4, 4, 4, 4); - gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL; - gridBagConstraints3.weightx = 1.0; - gridBagConstraints3.gridy = 0; - GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); - gridBagConstraints1.fill = GridBagConstraints.NONE; - gridBagConstraints1.gridx = 0; - gridBagConstraints1.gridy = 0; - gridBagConstraints1.insets = new Insets(4, 4, 4, 4); - jPanel1 = new JPanel(); - jPanel1.setLayout(new GridBagLayout()); - jPanel1.add(getJButtonFDCopyRef(), gridBagConstraints1); - jPanel1.add(getJButtonViewAnnot(), gridBagConstraints3); - } - return jPanel1; -} - -/** - * This method initializes jButtonViewAnnot - * - * @return javax.swing.JButton - */ -ActionListener viewAnnotAction = new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent e) { - javax.swing.tree.TreePath selPath = getJTree1().getSelectionPath(); - if(selPath != null){ - javax.swing.tree.DefaultMutableTreeNode lastPathComponent = - (javax.swing.tree.DefaultMutableTreeNode)selPath.getLastPathComponent(); - if(lastPathComponent.getUserObject() instanceof FieldDataMainList){ - PopupGenerator.showInfoDialog(FieldDataGUIPanel.this, - ((FieldDataMainList)(lastPathComponent.getUserObject())).extDataAnnot); - } - } - } -}; -private JButton getJButtonViewAnnot() { - if (jButtonViewAnnot == null) { - jButtonViewAnnot = new JButton(); - jButtonViewAnnot.setText("View Annot..."); - jButtonViewAnnot.setEnabled(false); - jButtonViewAnnot.addActionListener(viewAnnotAction); - } - return jButtonViewAnnot; -} + if (mainNode.getUserObject() instanceof FieldDataMainList) { + if (mainNode.getChildCount() > 1) {//Already populated + return; + } + refreshMainNode(mainNode); + } else { + return; + } + } else { + return; + } + } catch (Exception e) { + PopupGenerator.showErrorDialog(this, "Error getting Field Data Info\n" + e.getMessage(), e); + return; + } + + } + + public void refreshExternalDataIdentifierNode(ExternalDataIdentifier refreshEDI) { + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getFieldDataTree().getModel().getRoot(); + if (root != null) { + int childCount = root.getChildCount(); + for (int i = 0; i < childCount; i += 1) { + DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) root.getChildAt(i); + FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject(); + if (fieldDataMainList.externalDataIdentifier.equals(refreshEDI)) { + refreshMainNode(mainNode); + return; + } + } + } + } + + private void refreshMainNode(final DefaultMutableTreeNode mainNode) { + final boolean isMainExpanded = getFieldDataTree().isExpanded(new TreePath(mainNode.getPath())); + final boolean isVarExpanded = getFieldDataTree().isExpanded( + new TreePath(((DefaultMutableTreeNode) mainNode.getLastChild()).getPath())); + //Remove all children from Main node in a Tree safe way + DefaultMutableTreeNode root = (DefaultMutableTreeNode) getFieldDataTree().getModel().getRoot(); + int mainNodeIndex = + ((DefaultTreeModel) getFieldDataTree().getModel()).getIndexOfChild(root, mainNode); + ((DefaultTreeModel) getFieldDataTree().getModel()).removeNodeFromParent(mainNode); + mainNode.removeAllChildren(); + final DefaultMutableTreeNode varNode = new DefaultMutableTreeNode(new FieldDataVarMainList()); + mainNode.add(varNode); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(mainNode, root, mainNodeIndex); + // + //Create thread-safe tasks to get Field Data Info and update JTree + // + final String FDOR_INFO = "FDOR_INFO"; + final RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); + + AsynchClientTask FieldDataInfoTask = new AsynchClientTask("Gather Field Data info", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + public void run(Hashtable hash) throws Exception { + FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject(); + final FieldDataFileOperationResults fieldDataFileOperationResults = + clientRequestManager.getDocumentManager(). + fieldDataFileOperation( + FieldDataFileOperationSpec.createInfoFieldDataFileOperationSpec( + fieldDataMainList.externalDataIdentifier.getKey(), + clientRequestManager.getDocumentManager().getUser(), + FieldDataFileOperationSpec.JOBINDEX_DEFAULT) + ); + hash.put(FDOR_INFO, fieldDataFileOperationResults); + } + }; + + AsynchClientTask FieldDataInfoTreeUpdate = new AsynchClientTask("Update Field Data GUI", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + public void run(Hashtable hash) { + try { + FieldDataFileOperationResults fieldDataFileOperationResults = + (FieldDataFileOperationResults) hash.get(FDOR_INFO); + Arrays.sort(fieldDataFileOperationResults.dataIdentifierArr, + new Comparator() { + public int compare(DataIdentifier o1, DataIdentifier o2) { + return o1.getName().compareToIgnoreCase(o2.getName()); + } + } + ); + FieldDataMainList fieldDataMainList = (FieldDataMainList) mainNode.getUserObject(); + final DefaultMutableTreeNode isizeNode = + new DefaultMutableTreeNode(new FieldDataISizeList(fieldDataFileOperationResults.iSize)); + final DefaultMutableTreeNode originNode = + new DefaultMutableTreeNode(new FieldDataOriginList(fieldDataFileOperationResults.origin)); + final DefaultMutableTreeNode extentNode = + new DefaultMutableTreeNode(new FieldDataExtentList(fieldDataFileOperationResults.extent)); + final DefaultMutableTreeNode timeNode = + new DefaultMutableTreeNode(new FieldDataTimeList(fieldDataFileOperationResults.times)); + final DefaultMutableTreeNode idNode = + new DefaultMutableTreeNode(new FieldDataIDList(fieldDataMainList.externalDataIdentifier.getKey())); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(isizeNode, mainNode, 0); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(originNode, mainNode, 1); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(extentNode, mainNode, 2); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(timeNode, mainNode, 3); + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto(idNode, mainNode, 4); + for (int i = 0; i < fieldDataFileOperationResults.dataIdentifierArr.length; i += 1) { + ((DefaultTreeModel) getFieldDataTree().getModel()).insertNodeInto( + new DefaultMutableTreeNode( + new FieldDataVarList(fieldDataFileOperationResults.dataIdentifierArr[i])), + varNode, varNode.getChildCount()); + } + if (isMainExpanded) { + getFieldDataTree().expandPath(new TreePath(mainNode.getPath())); + } + if (isVarExpanded) { + getFieldDataTree().expandPath(new TreePath(varNode.getPath())); + } + } catch (Throwable e) { + hash.put(ClientTaskDispatcher.TASK_ABORTED_BY_ERROR, e); + } + } + }; + + // + //Execute Field Data Info - JTree tasks + // + AsynchClientTask tasks[] = new AsynchClientTask[]{FieldDataInfoTask, FieldDataInfoTreeUpdate}; + Hashtable hash = new Hashtable(); + ClientTaskDispatcher.dispatch(this, hash, tasks, false); + } + + /** + * main entrypoint - starts the part when it is run as an application + * + * @param args java.lang.String[] + */ + public static void main(java.lang.String[] args) { + try { + javax.swing.JFrame frame = new javax.swing.JFrame(); + FieldDataGUIPanel aFieldDataGUIPanel; + aFieldDataGUIPanel = new FieldDataGUIPanel(); + frame.setContentPane(aFieldDataGUIPanel); + frame.setSize(aFieldDataGUIPanel.getSize()); + frame.addWindowListener(new java.awt.event.WindowAdapter() { + public void windowClosing(java.awt.event.WindowEvent e) { + System.exit(0); + } + + ; + }); + frame.setVisible(true); + java.awt.Insets insets = frame.getInsets(); + frame.setSize(frame.getWidth() + insets.left + insets.right, frame.getHeight() + insets.top + insets.bottom); + frame.setVisible(true); + } catch (Throwable exception) { + System.err.println("Exception occurred in main() of javax.swing.JPanel"); + exception.printStackTrace(System.out); + } + } + + public void setFieldDataWindowManager(FieldDataWindowManager fdwm) { + fieldDataWindowManager = fdwm; + } + + public void checkFieldDataName(String fieldDataName) throws Exception { + if (fieldDataName == null || fieldDataName.length() == 0 || + !fieldDataName.equals(TokenMangler.fixTokenStrict(fieldDataName))) { + throw new Exception("Field Data names can contain only letters,digits and underscores"); + } + //Check to see if this name is already used + DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) this.getFieldDataTree().getModel().getRoot(); + if (!rootNode.getUserObject().toString().startsWith(FIELD_DATA_INFO)) { + updateJTree(fieldDataWindowManager.getLocalRequestManager()); + rootNode = (DefaultMutableTreeNode) this.getFieldDataTree().getModel().getRoot(); + } + for (int i = 0; i < rootNode.getChildCount(); i += 1) { + ExternalDataIdentifier extDataID = + ((FieldDataMainList) ((DefaultMutableTreeNode) rootNode.getChildAt(i)).getUserObject()).externalDataIdentifier; + if (fieldDataName.equals(extDataID.getName())) { + throw new Exception("New Field Data name " + fieldDataName + " already used."); + } + } + } + + public static AsynchClientTask[] addNewExternalData(final Component requester, final FieldDataGUIPanel fieldDataGUIPanel, final boolean isFromSimulation) { + + final RequestManager clientRequestManager = fieldDataGUIPanel.fieldDataWindowManager.getLocalRequestManager(); + + AsynchClientTask task1 = new AsynchClientTask("creating field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + //Check if this is ImageJ op, if so, this task unnecessary + if (hashTable.get(USER_DEFINED_FDOS) != null && hashTable.get(FIELD_NAME) != null) { + return; + } + //Allow user to review/change info about fielddata + FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos"); + String initialExtDataName = (String) hashTable.get("initFDName"); + + fdos.specEDI = null; + + FieldDataInfoPanel fdip = new FieldDataInfoPanel(); + fdip.setSimulationMode(isFromSimulation); + fdip.initISize(fdos.isize); + fdip.initIOrigin(fdos.origin); + fdip.initIExtent(fdos.extent); + fdip.initTimes(fdos.times); + fdip.initNames(TokenMangler.fixTokenStrict(initialExtDataName), fdos.varNames); + fdip.setAnnotation(fdos.annotation); + + FieldDataFileOperationSpec userDefinedFDOS = new FieldDataFileOperationSpec(); + while (true) { + int choice = PopupGenerator.showComponentOKCancelDialog(requester, fdip, "Create new field data"); + if (choice == JOptionPane.OK_OPTION) { + //Check values + try { + userDefinedFDOS.extent = fdip.getExtent(); + } catch (Exception e) { + PopupGenerator.showErrorDialog(requester, "Problem with Extent values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e); + continue; + } + try { + userDefinedFDOS.origin = fdip.getOrigin(); + } catch (Exception e) { + PopupGenerator.showErrorDialog(requester, "Problem with Origin values. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e); + continue; + } + try { + userDefinedFDOS.varNames = fdip.getVariableNames(); + } catch (Exception e) { + PopupGenerator.showErrorDialog(requester, "Problem with Variable names. Please re-enter.\n" + e.getMessage() + "\nTry Again.", e); + continue; + } + userDefinedFDOS.annotation = fdip.getAnnotation(); + userDefinedFDOS.times = fdip.getTimes(); + try { + fieldDataGUIPanel.checkFieldDataName(fdip.getFieldName()); + } catch (Exception e) { + PopupGenerator.showErrorDialog(requester, "Error saving Field Data Name to Database. Try again.\n" + e.getMessage(), e); + continue; + } + hashTable.put(USER_DEFINED_FDOS, userDefinedFDOS); + hashTable.put(FIELD_NAME, fdip.getFieldName()); + break; + } else { + throw UserCancelException.CANCEL_GENERIC; + } + } + } + }; + + AsynchClientTask task2 = new AsynchClientTask("saving field data", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + @Override + public void run(Hashtable hashTable) throws Exception { + //Add to Server Disk + //save Database + FieldDataFileOperationSpec tempFDOS = (FieldDataFileOperationSpec) hashTable.get(USER_DEFINED_FDOS); + String fieldName = (String) hashTable.get(FIELD_NAME); + + FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos"); + DocumentManager documentManager = clientRequestManager.getDocumentManager(); + FieldDataDBOperationSpec newExtDataIDSpec = FieldDataDBOperationSpec.createSaveNewExtDataIDSpec(documentManager.getUser(), fieldName, tempFDOS.annotation); + tempFDOS.specEDI = documentManager.fieldDataDBOperation(newExtDataIDSpec).extDataID; + fdos.specEDI = tempFDOS.specEDI; + fdos.annotation = tempFDOS.annotation; + + try { + if (!isFromSimulation) { + fdos.extent = tempFDOS.extent; + fdos.origin = tempFDOS.origin; + fdos.varNames = tempFDOS.varNames; + fdos.times = tempFDOS.times; + // + //Subvolumes and Regions NOT implemented now + // + fdos.cartesianMesh = CartesianMesh.createSimpleCartesianMesh(fdos.origin, fdos.extent, fdos.isize, + new RegionImage(new VCImageUncompressed(null, new byte[fdos.isize.getXYZ()],//empty regions + fdos.extent, fdos.isize.getX(), fdos.isize.getY(), fdos.isize.getZ()), + 0, null, null, RegionImage.NO_SMOOTHING)); + } + + //Add to Server Disk + documentManager.fieldDataFileOperation(fdos); + } catch (Exception e) { + try { + //try to cleanup new ExtDataID + documentManager.fieldDataDBOperation(FieldDataDBOperationSpec.createDeleteExtDataIDSpec(fdos.specEDI)); + } catch (Exception e2) { + //ignore + } + fdos.specEDI = null; + throw e; + } + } + }; + + AsynchClientTask task3 = new AsynchClientTask("refreshing field data", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + @Override + public void run(Hashtable hashTable) throws Exception { + FieldDataFileOperationSpec fdos = (FieldDataFileOperationSpec) hashTable.get("fdos"); + + DefaultMutableTreeNode root = ((DefaultMutableTreeNode) fieldDataGUIPanel.getFieldDataTree().getModel().getRoot()); + if (root.getChildCount() == 0) { + fieldDataGUIPanel.updateJTree(clientRequestManager); + } else { + int alphabeticalIndex = -1; + for (int i = 0; i < root.getChildCount(); i += 1) { + if ((((FieldDataMainList) ((DefaultMutableTreeNode) root.getChildAt(i)).getUserObject())).externalDataIdentifier.getName(). + compareToIgnoreCase(fdos.specEDI.getName()) > 0) { + alphabeticalIndex = i; + break; + } + } + if (alphabeticalIndex == -1) { + alphabeticalIndex = root.getChildCount(); + } + DefaultMutableTreeNode mainNode = new DefaultMutableTreeNode(new FieldDataMainList(fdos.specEDI, fdos.annotation)); + mainNode.add(new DefaultMutableTreeNode(new FieldDataVarMainList())); + ((DefaultTreeModel) fieldDataGUIPanel.getFieldDataTree().getModel()).insertNodeInto(mainNode, root, alphabeticalIndex); + } + } + }; + + return new AsynchClientTask[]{task1, task2, task3}; + } + + /** + * This method initializes jButtonFindRefModel + * + * @return javax.swing.JButton + */ + private JButton getJButtonFindRefModel() { + if (jButtonFindRefModel == null) { + jButtonFindRefModel = new JButton(); + jButtonFindRefModel.setText("Model Refs..."); + jButtonFindRefModel.setEnabled(false); + jButtonFindRefModel.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + TreePath selPath = getFieldDataTree().getSelectionPath(); + DefaultMutableTreeNode mainNode = (DefaultMutableTreeNode) selPath.getLastPathComponent(); + if (mainNode.getUserObject() instanceof FieldDataMainList) { + final ExternalDataIdentifier extDataID = ((FieldDataMainList) mainNode.getUserObject()).externalDataIdentifier; + + AsynchClientTask task1 = new AsynchClientTask("find model references", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) { + + @Override + public void run(Hashtable hashTable) throws Exception { + fieldDataWindowManager.findReferencingModels(extDataID, true); + } + }; + ClientTaskDispatcher.dispatch(FieldDataGUIPanel.this, new Hashtable(), new AsynchClientTask[]{task1}, false); + } + } + }); + } + return jButtonFindRefModel; + } + + /** + * This method initializes jPanel + * + * @return javax.swing.JPanel + */ + private JPanel getJPanel() { + if (jPanel == null) { + GridBagConstraints gridBagConstraints = new GridBagConstraints(); + gridBagConstraints.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints.gridx = 1; + gridBagConstraints.gridy = 0; + gridBagConstraints.weightx = 1.0; + gridBagConstraints.insets = new Insets(4, 4, 4, 4); + GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); + gridBagConstraints2.gridx = 0; + gridBagConstraints2.insets = new Insets(4, 4, 4, 4); + gridBagConstraints2.gridy = 0; + jPanel = new JPanel(); + jPanel.setLayout(new GridBagLayout()); + jPanel.add(getJButtonCreateGeom(), gridBagConstraints2); + jPanel.add(getJButtonFindRefModel(), gridBagConstraints); + } + return jPanel; + } + + /** + * This method initializes jButtonCopyInfo + * + * @return javax.swing.JButton + */ + private JButton getJButtonCreateGeom() { + if (jButtonCreateGeom == null) { + jButtonCreateGeom = new JButton(); + jButtonCreateGeom.setEnabled(false); + jButtonCreateGeom.setText("Create Geom"); + jButtonCreateGeom.addActionListener(new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + try { + RequestManager clientRequestManager = fieldDataWindowManager.getLocalRequestManager(); + javax.swing.tree.TreePath selPath = getFieldDataTree().getSelectionPath(); + javax.swing.tree.DefaultMutableTreeNode lastPathComponent = (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent(); + if (lastPathComponent.getUserObject() instanceof FieldDataVarList) { + DataIdentifier dataIdentifier = + ((FieldDataVarList) lastPathComponent.getUserObject()).dataIdentifier; + + TreePath ppPath = selPath.getParentPath().getParentPath(); + javax.swing.tree.DefaultMutableTreeNode ppLastPathComp = (javax.swing.tree.DefaultMutableTreeNode) ppPath.getLastPathComponent(); + if (ppLastPathComp.getUserObject() instanceof FieldDataMainList) { + ExternalDataIdentifier extDataID = + ((FieldDataMainList) ppLastPathComp.getUserObject()).externalDataIdentifier; + + final OpenModelInfoHolder openModelInfoHolder = + FieldDataWindowManager.selectOpenModelsFromDesktop(FieldDataGUIPanel.this, fieldDataWindowManager.getRequestManager(), false, "Select BioModel or MathModel to receive new geometry", false); + if (openModelInfoHolder == null) { + DialogUtils.showErrorDialog(FieldDataGUIPanel.this, + "Before proceeding, please open a Biomodel application or Mathmodel you wish to apply a new Field Data Geometry to"); + return; + } + + AsynchClientTask applyGeomTask = new AsynchClientTask("apply geometry", AsynchClientTask.TASKTYPE_SWING_BLOCKING) { + @Override + public void run(Hashtable hashTable) throws Exception { + Geometry newGeom = (Geometry) hashTable.get("doc"); + final String OK_OPTION = "Ok"; + if (openModelInfoHolder instanceof FDSimMathModelInfo) { + Version version = ((FDSimMathModelInfo) openModelInfoHolder).getMathModelVersion(); + String modelName = (version == null ? "NoName" : version.getName()); + if (newGeom.getName() == null) { + newGeom.setName(modelName + "_" + BeanUtils.generateDateTimeString()); + } + String message = "Confirm Setting new FieldData derived geometry on MathModel '" + modelName + "'"; + if (DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[]{OK_OPTION, "Cancel"}, OK_OPTION).equals(OK_OPTION)) { + ((FDSimMathModelInfo) openModelInfoHolder).getMathDescription().setGeometry(newGeom); + } + } else if (openModelInfoHolder instanceof FDSimBioModelInfo) { + Version version = ((FDSimBioModelInfo) openModelInfoHolder).getBioModelVersion(); + String modelName = (version == null ? "NoName" : version.getName()); + String simContextName = ((FDSimBioModelInfo) openModelInfoHolder).getSimulationContext().getName(); + if (newGeom.getName() == null) { + newGeom.setName(modelName + "_" + simContextName + "_" + BeanUtils.generateDateTimeString()); + } + String message = "Confirm Setting new FieldData derived geometry on BioModel '" + modelName + "' , Application '" + simContextName + "'"; + if (DialogUtils.showWarningDialog(FieldDataGUIPanel.this, message, new String[]{OK_OPTION, "Cancel"}, OK_OPTION).equals(OK_OPTION)) { + ((FDSimBioModelInfo) openModelInfoHolder).getSimulationContext().setGeometry(newGeom); + } + } + } + }; + VCDocument.GeomFromFieldDataCreationInfo geomFromFieldDataCreationInfo = + new VCDocument.GeomFromFieldDataCreationInfo( + extDataID, dataIdentifier.getName()); + AsynchClientTask[] createGeomTask = clientRequestManager.createNewGeometryTasks(fieldDataWindowManager, + geomFromFieldDataCreationInfo, + new AsynchClientTask[]{applyGeomTask}, + "Apply Geometry"); + + Hashtable hash = new Hashtable(); + hash.put(ClientRequestManager.GUI_PARENT, fieldDataWindowManager.getComponent()); + ClientTaskDispatcher.dispatch(FieldDataGUIPanel.this, hash, + createGeomTask, false, false, null, true); + + } + + } + } catch (UserCancelException e1) { + //ignore + } catch (Exception e1) { + e1.printStackTrace(); + DialogUtils.showErrorDialog(FieldDataGUIPanel.this, e1.getMessage()); + } + } + }); + } + return jButtonCreateGeom; + } + + /** + * This method initializes jPanel1 + * + * @return javax.swing.JPanel + */ + private JPanel getJPanel12() { + if (jPanel1 == null) { + GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); + gridBagConstraints3.gridx = 1; + gridBagConstraints3.insets = new Insets(4, 4, 4, 4); + gridBagConstraints3.fill = GridBagConstraints.HORIZONTAL; + gridBagConstraints3.weightx = 1.0; + gridBagConstraints3.gridy = 0; + GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); + gridBagConstraints1.fill = GridBagConstraints.NONE; + gridBagConstraints1.gridx = 0; + gridBagConstraints1.gridy = 0; + gridBagConstraints1.insets = new Insets(4, 4, 4, 4); + jPanel1 = new JPanel(); + jPanel1.setLayout(new GridBagLayout()); + jPanel1.add(getJButtonFDCopyRef(), gridBagConstraints1); + jPanel1.add(getJButtonViewAnnot(), gridBagConstraints3); + } + return jPanel1; + } + + /** + * This method initializes jButtonViewAnnot + * + * @return javax.swing.JButton + */ + ActionListener viewAnnotAction = new java.awt.event.ActionListener() { + public void actionPerformed(java.awt.event.ActionEvent e) { + javax.swing.tree.TreePath selPath = getFieldDataTree().getSelectionPath(); + if (selPath != null) { + javax.swing.tree.DefaultMutableTreeNode lastPathComponent = + (javax.swing.tree.DefaultMutableTreeNode) selPath.getLastPathComponent(); + if (lastPathComponent.getUserObject() instanceof FieldDataMainList) { + PopupGenerator.showInfoDialog(FieldDataGUIPanel.this, + ((FieldDataMainList) (lastPathComponent.getUserObject())).extDataAnnot); + } + } + } + }; + + private JButton getJButtonViewAnnot() { + if (jButtonViewAnnot == null) { + jButtonViewAnnot = new JButton(); + jButtonViewAnnot.setText("View Annot..."); + jButtonViewAnnot.setEnabled(false); + jButtonViewAnnot.addActionListener(viewAnnotAction); + } + return jButtonViewAnnot; + } } diff --git a/vcell-server/src/main/java/cbit/vcell/field/db/FieldDataDBOperationDriver.java b/vcell-server/src/main/java/cbit/vcell/field/db/FieldDataDBOperationDriver.java index b4ec52db3f..7325e4054b 100644 --- a/vcell-server/src/main/java/cbit/vcell/field/db/FieldDataDBOperationDriver.java +++ b/vcell-server/src/main/java/cbit/vcell/field/db/FieldDataDBOperationDriver.java @@ -52,455 +52,476 @@ import cbit.vcell.resource.PropertyLoader; import cbit.vcell.simdata.SimulationData; -public class FieldDataDBOperationDriver{ - private final static Logger lg = LogManager.getLogger(FieldDataDBOperationDriver.class); - - private static String DATE_FORMAT_STRING = "'DD-MON-YYYY HH24:MI:SS'"; - - private static Connection liveConnection = null; - private static Timer liveConnectionTimer = null; - - private static synchronized void restartLiveConnectionTimer(){ - if(liveConnectionTimer == null){ - liveConnectionTimer = - new Timer(5*60*1000, - new ActionListener(){ - public void actionPerformed(ActionEvent e) { - closeConnection(); - }} - ); - liveConnectionTimer.setRepeats(false); - } - liveConnectionTimer.restart(); - } - private static synchronized void closeConnection(){ +public class FieldDataDBOperationDriver { + private final static Logger lg = LogManager.getLogger(FieldDataDBOperationDriver.class); + + private static String DATE_FORMAT_STRING = "'DD-MON-YYYY HH24:MI:SS'"; + + private static Connection liveConnection = null; + private static Timer liveConnectionTimer = null; + + private static synchronized void restartLiveConnectionTimer() { + if (liveConnectionTimer == null) { + liveConnectionTimer = + new Timer(5 * 60 * 1000, + new ActionListener() { + public void actionPerformed(ActionEvent e) { + closeConnection(); + } + } + ); + liveConnectionTimer.setRepeats(false); + } + liveConnectionTimer.restart(); + } + + private static synchronized void closeConnection() { // System.err.println("connection Closed"); - if(liveConnection != null){ - try{liveConnection.close();}catch(Exception e){lg.error(e.getMessage(), e);} - liveConnection = null; - } - } - private static synchronized Connection getConnection() throws Exception{ - - restartLiveConnectionTimer(); - - if(liveConnection != null){ + if (liveConnection != null) { + try { + liveConnection.close(); + } catch (Exception e) { + lg.error(e.getMessage(), e); + } + liveConnection = null; + } + } + + private static synchronized Connection getConnection() throws Exception { + + restartLiveConnectionTimer(); + + if (liveConnection != null) { // System.err.println("connection Re-used"); - return liveConnection; - } + return liveConnection; + } // System.err.println("connection Created"); - String dbDriverName = PropertyLoader.getProperty(PropertyLoader.dbDriverName, null); - String dbConnectURL = PropertyLoader.getProperty(PropertyLoader.dbConnectURL, null); - String dbSchemaUser = PropertyLoader.getProperty(PropertyLoader.dbUserid, null); - String dbPassword = PropertyLoader.getSecretValue(PropertyLoader.dbPasswordValue, PropertyLoader.dbPasswordFile); - try{ - Class.forName(dbDriverName); - liveConnection = java.sql.DriverManager.getConnection(dbConnectURL,dbSchemaUser,dbPassword); - liveConnection.setReadOnly(true); - return liveConnection; - }catch(Exception e){ - throw new Exception("FieldDataDBOperationDriver: Couldn't get database connection",e); - } - - } - public static FieldDataDBOperationResults fieldDataDBOperation(Connection con, KeyFactory keyFactory, User user, - FieldDataDBOperationSpec fieldDataDBOperationSpec) throws SQLException, DataAccessException { - - if(fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_COPY_NO_CONFLICT){ - //get all current ExtDataIDs - ExternalDataIdentifier[] existingExtDataIDArr = - FieldDataDBOperationDriver.fieldDataDBOperation( - con, keyFactory, user,FieldDataDBOperationSpec.createGetExtDataIDsSpec(user)).extDataIDArr; - //Rename FieldFunc names if necessary - Hashtable newNameOrigNameHash = new Hashtable(); - for(int i=0;i oldNameNewIDHash = - new Hashtable(); - Hashtable oldNameOldExtDataIDKey = - new Hashtable(); - String[] newFieldFuncNamesArr = newNameOrigNameHash.keySet().toArray(new String[0]); - for(int i=0;i newNameOrigNameHash = new Hashtable(); + for (int i = 0; i < fieldDataDBOperationSpec.sourceNames.length; i += 1) { + String newFieldFuncName = fieldDataDBOperationSpec.sourceNames[i]; + while (true) { + boolean bNameConflictExists = false; + for (int j = 0; j < existingExtDataIDArr.length; j += 1) { + if (existingExtDataIDArr[j].getName().equals(newFieldFuncName)) { + bNameConflictExists = true; + break; + } + } + bNameConflictExists = + bNameConflictExists || newNameOrigNameHash.containsKey(newFieldFuncName); + if (!bNameConflictExists) { + newNameOrigNameHash.put(newFieldFuncName, fieldDataDBOperationSpec.sourceNames[i]); + break; + } + newFieldFuncName = TokenMangler.getNextEnumeratedToken(newFieldFuncName); + } + } + //Add new ExternalDataIdentifier (FieldData ID) to DB + //Copy source annotation + FieldDataDBOperationResults sourceUserExtDataInfo = + fieldDataDBOperation(con, keyFactory, user, + FieldDataDBOperationSpec.createGetExtDataIDsSpec( + fieldDataDBOperationSpec.sourceOwner.getVersion().getOwner())); + ExternalDataIdentifier[] sourceUserExtDataIDArr = sourceUserExtDataInfo.extDataIDArr; + Hashtable oldNameNewIDHash = + new Hashtable(); + Hashtable oldNameOldExtDataIDKey = + new Hashtable(); + String[] newFieldFuncNamesArr = newNameOrigNameHash.keySet().toArray(new String[0]); + for (int i = 0; i < newFieldFuncNamesArr.length; i += 1) { + //find orig annotation + String origAnnotation = + "Copy Field Data name used Field Data function\r\n" + + "Source type: " + fieldDataDBOperationSpec.sourceOwner.getVType().getTypeName() + "\r\n" + + "Source owner: " + fieldDataDBOperationSpec.sourceOwner.getVersion().getOwner().getName() + "\r\n" + + "Source name: " + fieldDataDBOperationSpec.sourceOwner.getVersion().getName() + "\r\n" + + "Original Field Data name: " + newNameOrigNameHash.get(newFieldFuncNamesArr[i]) + "\r\n" + + "New Field Data name: " + newFieldFuncNamesArr[i] + "\r\n" + + "Source Annotation: " + newFieldFuncNamesArr[i] + "\r\n"; + for (int j = 0; j < sourceUserExtDataInfo.extDataAnnotArr.length; j += 1) { + String originalName = newNameOrigNameHash.get(newFieldFuncNamesArr[i]); + if (sourceUserExtDataIDArr[j].getName().equals(originalName)) { + oldNameOldExtDataIDKey.put(originalName, sourceUserExtDataInfo.extDataIDArr[j].getKey()); + origAnnotation += sourceUserExtDataInfo.extDataAnnotArr[j]; + break; + } + } + // + FieldDataDBOperationResults fieldDataDBOperationResults = + fieldDataDBOperation(con, keyFactory, user, + FieldDataDBOperationSpec.createSaveNewExtDataIDSpec( + user, newFieldFuncNamesArr[i], origAnnotation)); // errorCleanupExtDataIDV.add(fieldDataDBOperationResults.extDataID); - String origFieldFuncName = - newNameOrigNameHash.get(fieldDataDBOperationResults.extDataID.getName()); - if(origFieldFuncName == null){ - throw new DataAccessException("couldn't find original FieldFuncName using new ExternalDataId"); - } - oldNameNewIDHash.put(origFieldFuncName,fieldDataDBOperationResults.extDataID); - } - - FieldDataDBOperationResults fieldDataDBOperationResults = - new FieldDataDBOperationResults(); - fieldDataDBOperationResults.oldNameNewIDHash = oldNameNewIDHash; - fieldDataDBOperationResults.oldNameOldExtDataIDKeyHash = oldNameOldExtDataIDKey; - return fieldDataDBOperationResults; - }else if(fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_GETEXTDATAIDS){ - String sql; - ResultSet rset; - if(fieldDataDBOperationSpec.bIncludeSimRefs){ - sql = "SELECT "+ - ExternalDataTable.table.id.getQualifiedColName()+","+ - ExternalDataTable.table.externalDataName.getQualifiedColName()+","+ - ExternalDataTable.table.ownerRef.getQualifiedColName()+","+ - UserTable.table.userid.getQualifiedColName()+ ","+ - SimulationTable.table.id.getQualifiedColName() + - " FROM " + - ExternalDataTable.table.getTableName() + ","+ - MathDescTable.table.getTableName() + ","+ - SimulationTable.table.getTableName() + ","+ - MathDescExternalDataLinkTable.table.getTableName() + ","+ - UserTable.table.getTableName()+ - " WHERE " + - UserTable.table.id.getQualifiedColName() + " = " + - fieldDataDBOperationSpec.owner.getID() + - " AND "+ - UserTable.table.id.getQualifiedColName() + " = " + - ExternalDataTable.table.ownerRef.getQualifiedColName() + - " AND "+ - ExternalDataTable.table.id.getQualifiedColName() + " = " + - MathDescExternalDataLinkTable.table.extDataRef.getQualifiedColName() + - " AND "+ - MathDescTable.table.id.getQualifiedColName() + " = " + - MathDescExternalDataLinkTable.table.mathDescRef.getQualifiedColName() + - " AND "+ - MathDescTable.table.id.getQualifiedColName() + " = " + - SimulationTable.table.mathRef.getQualifiedColName(); - }else{ - sql = "SELECT "+ - ExternalDataTable.table.getTableName()+".*"+","+ - UserTable.table.userid.getQualifiedColName()+ - " FROM " + - ExternalDataTable.table.getTableName() + ","+ - UserTable.table.getTableName()+ - " WHERE " + - ExternalDataTable.table.ownerRef + "=" +fieldDataDBOperationSpec.owner.getID() + - " AND "+ - UserTable.table.id.getQualifiedColName() + " = " + - ExternalDataTable.table.ownerRef.getQualifiedColName(); - } - - Statement stmt = con.createStatement(); - Vector extDataIDV = new Vector(); - Vector extDataAnnotV = new Vector(); - HashMap> extDataIDSimRefsH = null; - try { - rset = stmt.executeQuery(sql); - while (rset.next()) { - ExternalDataIdentifier extDataID = - ExternalDataTable.table.getExternalDataIdentifier(rset); - if( !fieldDataDBOperationSpec.bIncludeSimRefs && - !extDataIDV.contains(extDataID)){ - extDataIDV.add(extDataID); - extDataAnnotV.add(ExternalDataTable.table.getExternalDataAnnot(rset)); - } - if(fieldDataDBOperationSpec.bIncludeSimRefs){ - if(extDataIDSimRefsH == null){ - extDataIDSimRefsH = - new HashMap>(); - } - Vector simRefV = - extDataIDSimRefsH.get(extDataID); - if(simRefV == null){ - simRefV = new Vector(); - extDataIDSimRefsH.put(extDataID, simRefV); - } - simRefV.add( - new KeyValue( - rset.getBigDecimal(SimulationTable.table.id.getUnqualifiedColName()))); - } - } - } finally { - stmt.close(); - } - FieldDataDBOperationResults fieldDataDBOperationResults = new FieldDataDBOperationResults(); - fieldDataDBOperationResults.extDataIDArr = extDataIDV.toArray(new ExternalDataIdentifier[extDataIDV.size()]); - fieldDataDBOperationResults.extDataAnnotArr = extDataAnnotV.toArray(new String[extDataAnnotV.size()]); - fieldDataDBOperationResults.extdataIDAndSimRefH = extDataIDSimRefsH; - return fieldDataDBOperationResults; - - }else if(fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_SAVEEXTDATAID){ - - if(!fieldDataDBOperationSpec.newExtDataIDName.equals( - TokenMangler.fixTokenStrict(fieldDataDBOperationSpec.newExtDataIDName))){ - throw new DataAccessException("Error inserting Field Data name "+ - fieldDataDBOperationSpec.newExtDataIDName+"\n"+ - "Field Data names can contain only letters,digits and underscores"); - } - - KeyValue newKey = keyFactory.getNewKey(con); - String sql = - "INSERT INTO "+ExternalDataTable.table.getTableName()+" "+ - ExternalDataTable.table.getSQLColumnList()+ - " VALUES "+ - ExternalDataTable.table.getSQLValueList( - newKey,user, - fieldDataDBOperationSpec.newExtDataIDName, - fieldDataDBOperationSpec.annotation); - - DbDriver.updateCleanSQL(con,sql); - ExternalDataIdentifier[] fdiArr = - FieldDataDBOperationDriver.fieldDataDBOperation( - con, keyFactory, user,FieldDataDBOperationSpec.createGetExtDataIDsSpec(user)).extDataIDArr; - for (int i = 0; i < fdiArr.length; i++) { - if(fdiArr[i].getName().equals(fieldDataDBOperationSpec.newExtDataIDName)){ - FieldDataDBOperationResults fieldDataDBOperationResults = new FieldDataDBOperationResults(); - fieldDataDBOperationResults.extDataID = fdiArr[i];; - return fieldDataDBOperationResults; - } - } - throw new DataAccessException( - "Unable to retrieve inserted ExternalDataIdentifier "+ - fieldDataDBOperationSpec.newExtDataIDName); - - - }else if(fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_DELETE){ - String sql = - "DELETE" + " FROM " + ExternalDataTable.table.getTableName() + - " WHERE " + - ExternalDataTable.table.ownerRef + " = " + user.getID() + - " AND " + - ExternalDataTable.table.id + " = " + fieldDataDBOperationSpec.specEDI.getKey().toString(); - - DbDriver.updateCleanSQL(con,sql); - - return new FieldDataDBOperationResults(); - } - - throw new DataAccessException("Unknown FieldDataDBOperation "+fieldDataDBOperationSpec.opType); - } - - public static synchronized HashMap> getAllExternalDataIdentifiers() throws DataAccessException{ - - String sql = - "SELECT "+ - ExternalDataTable.table.getTableName()+".*"+","+ - UserTable.table.userid.getQualifiedColName()+ - " FROM " + - ExternalDataTable.table.getTableName() + ","+ - UserTable.table.getTableName()+ - " WHERE " + - UserTable.table.id.getQualifiedColName() + " = " + - ExternalDataTable.table.ownerRef.getQualifiedColName(); - Statement stmt = null; - HashMap> allUserExtDataIDH = - new HashMap>(); - try { - stmt = getConnection().createStatement(); - ResultSet rset = stmt.executeQuery(sql); - while (rset.next()) { - ExternalDataIdentifier extDataID = - ExternalDataTable.table.getExternalDataIdentifier(rset); - Vector userExtDataIDV = - allUserExtDataIDH.get(extDataID.getOwner()); - if(userExtDataIDV == null){ - userExtDataIDV = new Vector(); - allUserExtDataIDH.put(extDataID.getOwner(), userExtDataIDV); - } - userExtDataIDV.add(extDataID); - } - }catch(Exception e){ - lg.error(e.getMessage(), e); - throw new DataAccessException("Error: getAllExternalDataIdentifiers",e); - }finally { - if(stmt != null){try{stmt.close();}catch(Exception e){lg.error(e.getMessage(), e);}} - } - return allUserExtDataIDH; - } - - public static synchronized HashMap getFunctionFileNamesAndSimKeys(User user) - throws DataAccessException{ - - String sql = - "SELECT "+ - SimulationJobTable.table.simRef.getQualifiedColName()+","+ - SimulationJobTable.table.jobIndex.getQualifiedColName()+ - " FROM " + - SimulationJobTable.table.getTableName()+","+ - SimulationTable.table.getTableName()+ - " WHERE " + - SimulationTable.table.ownerRef.getQualifiedColName() +" = " + user.getID() + - " AND "+ - SimulationTable.table.id.getQualifiedColName()+ " = " +SimulationJobTable.table.simRef.getQualifiedColName()+ - " UNION " + - " SELECT " + - SimulationTable.table.id.getQualifiedColName()+","+ - "TO_NUMBER(NULL) "+//SimulationJobTable.table.jobIndex.getUnqualifiedColName()+ - " FROM " + - SimulationTable.table.getTableName()+ - " WHERE " + - SimulationTable.table.ownerRef.getQualifiedColName()+ "=" +user.getID()+ - " AND " + - SimulationTable.table.id.getQualifiedColName()+ - " NOT IN (SELECT " +SimulationJobTable.table.simRef.getQualifiedColName()+ - " FROM " +SimulationJobTable.table.getTableName()+" )"+ - " UNION " + - " SELECT " + - ExternalDataTable.table.id.getQualifiedColName()+","+ - "TO_NUMBER(0) "+ - " FROM " + - ExternalDataTable.table.getTableName()+ - " WHERE " + - ExternalDataTable.table.ownerRef.getQualifiedColName()+ "=" +user.getID(); - - - Statement stmt = null; - HashMap functionNamesH = new HashMap(); - try { - stmt = getConnection().createStatement(); - ResultSet rset = stmt.executeQuery(sql); - while (rset.next()) { - KeyValue simKey = new KeyValue(rset.getBigDecimal(1)); - BigDecimal jobIndex = rset.getBigDecimal(2); - boolean isOldStyle = rset.wasNull(); - functionNamesH.put( - SimulationData.createCanonicalFunctionsFileName( - simKey, (isOldStyle?0:jobIndex.intValue()), isOldStyle), - simKey - ); - } - }catch(Exception e){ - lg.error(e.getMessage(), e); - throw new DataAccessException("Error: getFunctionFileNamesAndSimKeys",e); - }finally { - if(stmt != null){try{stmt.close();}catch(Exception e){lg.error(e.getMessage(), e);}} - } - return functionNamesH; -} + String origFieldFuncName = + newNameOrigNameHash.get(fieldDataDBOperationResults.extDataID.getName()); + if (origFieldFuncName == null) { + throw new DataAccessException("couldn't find original FieldFuncName using new ExternalDataId"); + } + oldNameNewIDHash.put(origFieldFuncName, fieldDataDBOperationResults.extDataID); + } + + FieldDataDBOperationResults fieldDataDBOperationResults = + new FieldDataDBOperationResults(); + fieldDataDBOperationResults.oldNameNewIDHash = oldNameNewIDHash; + fieldDataDBOperationResults.oldNameOldExtDataIDKeyHash = oldNameOldExtDataIDKey; + return fieldDataDBOperationResults; + } else if (fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_GETEXTDATAIDS) { + String sql; + ResultSet rset; + if (fieldDataDBOperationSpec.bIncludeSimRefs) { + sql = "SELECT " + + ExternalDataTable.table.id.getQualifiedColName() + "," + + ExternalDataTable.table.externalDataName.getQualifiedColName() + "," + + ExternalDataTable.table.ownerRef.getQualifiedColName() + "," + + UserTable.table.userid.getQualifiedColName() + "," + + SimulationTable.table.id.getQualifiedColName() + + " FROM " + + ExternalDataTable.table.getTableName() + "," + + MathDescTable.table.getTableName() + "," + + SimulationTable.table.getTableName() + "," + + MathDescExternalDataLinkTable.table.getTableName() + "," + + UserTable.table.getTableName() + + " WHERE " + + UserTable.table.id.getQualifiedColName() + " = " + + fieldDataDBOperationSpec.owner.getID() + + " AND " + + UserTable.table.id.getQualifiedColName() + " = " + + ExternalDataTable.table.ownerRef.getQualifiedColName() + + " AND " + + ExternalDataTable.table.id.getQualifiedColName() + " = " + + MathDescExternalDataLinkTable.table.extDataRef.getQualifiedColName() + + " AND " + + MathDescTable.table.id.getQualifiedColName() + " = " + + MathDescExternalDataLinkTable.table.mathDescRef.getQualifiedColName() + + " AND " + + MathDescTable.table.id.getQualifiedColName() + " = " + + SimulationTable.table.mathRef.getQualifiedColName(); + } else { + sql = "SELECT " + + ExternalDataTable.table.getTableName() + ".*" + "," + + UserTable.table.userid.getQualifiedColName() + + " FROM " + + ExternalDataTable.table.getTableName() + "," + + UserTable.table.getTableName() + + " WHERE " + + ExternalDataTable.table.ownerRef + "=" + fieldDataDBOperationSpec.owner.getID() + + " AND " + + UserTable.table.id.getQualifiedColName() + " = " + + ExternalDataTable.table.ownerRef.getQualifiedColName(); + } + + Statement stmt = con.createStatement(); + Vector extDataIDV = new Vector(); + Vector extDataAnnotV = new Vector(); + HashMap> extDataIDSimRefsH = null; + try { + rset = stmt.executeQuery(sql); + while (rset.next()) { + ExternalDataIdentifier extDataID = + ExternalDataTable.table.getExternalDataIdentifier(rset); + if (!fieldDataDBOperationSpec.bIncludeSimRefs && + !extDataIDV.contains(extDataID)) { + extDataIDV.add(extDataID); + extDataAnnotV.add(ExternalDataTable.table.getExternalDataAnnot(rset)); + } + if (fieldDataDBOperationSpec.bIncludeSimRefs) { + if (extDataIDSimRefsH == null) { + extDataIDSimRefsH = + new HashMap>(); + } + Vector simRefV = + extDataIDSimRefsH.get(extDataID); + if (simRefV == null) { + simRefV = new Vector(); + extDataIDSimRefsH.put(extDataID, simRefV); + } + simRefV.add( + new KeyValue( + rset.getBigDecimal(SimulationTable.table.id.getUnqualifiedColName()))); + } + } + } finally { + stmt.close(); + } + FieldDataDBOperationResults fieldDataDBOperationResults = new FieldDataDBOperationResults(); + fieldDataDBOperationResults.extDataIDArr = extDataIDV.toArray(new ExternalDataIdentifier[extDataIDV.size()]); + fieldDataDBOperationResults.extDataAnnotArr = extDataAnnotV.toArray(new String[extDataAnnotV.size()]); + fieldDataDBOperationResults.extdataIDAndSimRefH = extDataIDSimRefsH; + return fieldDataDBOperationResults; + + } else if (fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_SAVEEXTDATAID) { + + if (!fieldDataDBOperationSpec.newExtDataIDName.equals( + TokenMangler.fixTokenStrict(fieldDataDBOperationSpec.newExtDataIDName))) { + throw new DataAccessException("Error inserting Field Data name " + + fieldDataDBOperationSpec.newExtDataIDName + "\n" + + "Field Data names can contain only letters,digits and underscores"); + } + + KeyValue newKey = keyFactory.getNewKey(con); + String sql = + "INSERT INTO " + ExternalDataTable.table.getTableName() + " " + + ExternalDataTable.table.getSQLColumnList() + + " VALUES " + + ExternalDataTable.table.getSQLValueList( + newKey, user, + fieldDataDBOperationSpec.newExtDataIDName, + fieldDataDBOperationSpec.annotation); - public static synchronized FieldDataFileOperationResults.FieldDataReferenceInfo getModelDescriptionForSimulation(User user,KeyValue simulationKey) - throws DataAccessException{ - - String sqlMathModel = - "SELECT "+ - MathModelTable.table.name.getQualifiedColName()+","+ - SimulationTable.table.name.getQualifiedColName() +","+ - "TO_CHAR("+MathModelTable.table.versionDate.getQualifiedColName()+","+DATE_FORMAT_STRING+")"+","+ - MathModelTable.table.id.getQualifiedColName()+ - " FROM " + - SimulationTable.table.getTableName()+","+ - MathModelSimulationLinkTable.table.getTableName()+","+ - MathModelTable.table.getTableName() + - " WHERE " + - SimulationTable.table.ownerRef.getQualifiedColName() +" = " + user.getID() + - " AND ("+ - SimulationTable.table.id.getQualifiedColName()+ " = " +simulationKey.toString()+ - " AND "+ - SimulationTable.table.id.getQualifiedColName()+ " = " + - MathModelSimulationLinkTable.table.simRef.getQualifiedColName()+ - " AND "+ - MathModelSimulationLinkTable.table.mathModelRef.getQualifiedColName()+" = "+ - MathModelTable.table.id.getQualifiedColName()+ - ") OR ("+ - SimulationTable.table.versionParentSimRef.getQualifiedColName()+" IS NOT NULL"+ - " AND "+ - SimulationTable.table.versionParentSimRef.getQualifiedColName()+" = "+simulationKey.toString()+ - " AND "+ - SimulationTable.table.id.getQualifiedColName()+ " = " + - MathModelSimulationLinkTable.table.simRef.getQualifiedColName()+ - " AND "+ - MathModelSimulationLinkTable.table.mathModelRef.getQualifiedColName()+" = "+ - MathModelTable.table.id.getQualifiedColName()+ - ")"; - - String sqlBioModel = - "SELECT "+ - BioModelTable.table.name.getQualifiedColName()+","+ - SimContextTable.table.name.getQualifiedColName()+","+ - SimulationTable.table.name.getQualifiedColName() +","+ - "TO_CHAR("+BioModelTable.table.versionDate.getQualifiedColName()+","+DATE_FORMAT_STRING+")"+","+ - BioModelTable.table.id.getQualifiedColName()+ - " FROM " + - SimulationTable.table.getTableName()+","+ - BioModelSimulationLinkTable.table.getTableName()+","+ - SimContextTable.table.getTableName()+","+ - BioModelSimContextLinkTable.table.getTableName()+","+ - BioModelTable.table.getTableName() + - " WHERE " + - SimulationTable.table.ownerRef.getQualifiedColName() +" = " + user.getID() + - " AND ("+ - SimulationTable.table.id.getQualifiedColName()+ " = " +simulationKey.toString()+ - " AND "+ - SimulationTable.table.id.getQualifiedColName()+ " = " + - BioModelSimulationLinkTable.table.simRef.getQualifiedColName()+ - " AND "+ - BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName()+" = "+ - BioModelTable.table.id.getQualifiedColName()+ - " AND "+ - BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName()+" = "+ - BioModelTable.table.id.getQualifiedColName() + - " AND "+ - SimContextTable.table.id.getQualifiedColName()+ " = " + - BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName()+ - " AND "+ - SimContextTable.table.mathRef.getQualifiedColName()+" = "+ - SimulationTable.table.mathRef.getQualifiedColName()+ - ") OR ("+ - SimulationTable.table.versionParentSimRef.getQualifiedColName()+" IS NOT NULL"+ - " AND "+ - SimulationTable.table.versionParentSimRef.getQualifiedColName()+" = "+simulationKey.toString()+ - " AND "+ - SimulationTable.table.id.getQualifiedColName()+ " = " + - BioModelSimulationLinkTable.table.simRef.getQualifiedColName()+ - " AND "+ - BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName()+" = "+ - BioModelTable.table.id.getQualifiedColName()+ - " AND "+ - BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName()+" = "+ - BioModelTable.table.id.getQualifiedColName() + - " AND "+ - SimContextTable.table.id.getQualifiedColName()+ " = " + - BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName()+ - " AND "+ - SimContextTable.table.mathRef.getQualifiedColName()+" = "+ - SimulationTable.table.mathRef.getQualifiedColName()+ - ")"; + DbDriver.updateCleanSQL(con, sql); + ExternalDataIdentifier[] fdiArr = + FieldDataDBOperationDriver.fieldDataDBOperation( + con, keyFactory, user, FieldDataDBOperationSpec.createGetExtDataIDsSpec(user)).extDataIDArr; + for (int i = 0; i < fdiArr.length; i++) { + if (fdiArr[i].getName().equals(fieldDataDBOperationSpec.newExtDataIDName)) { + FieldDataDBOperationResults fieldDataDBOperationResults = new FieldDataDBOperationResults(); + fieldDataDBOperationResults.extDataID = fdiArr[i]; + ; + return fieldDataDBOperationResults; + } + } + throw new DataAccessException( + "Unable to retrieve inserted ExternalDataIdentifier " + + fieldDataDBOperationSpec.newExtDataIDName); + + + } else if (fieldDataDBOperationSpec.opType == FieldDataDBOperationSpec.FDDBOS_DELETE) { + String sql = + "DELETE" + " FROM " + ExternalDataTable.table.getTableName() + + " WHERE " + + ExternalDataTable.table.ownerRef + " = " + user.getID() + + " AND " + + ExternalDataTable.table.id + " = " + fieldDataDBOperationSpec.specEDI.getKey().toString(); + + DbDriver.updateCleanSQL(con, sql); + + return new FieldDataDBOperationResults(); + } + + throw new DataAccessException("Unknown FieldDataDBOperation " + fieldDataDBOperationSpec.opType); + } + + public static synchronized HashMap> getAllExternalDataIdentifiers() throws DataAccessException { + + String sql = + "SELECT " + + ExternalDataTable.table.getTableName() + ".*" + "," + + UserTable.table.userid.getQualifiedColName() + + " FROM " + + ExternalDataTable.table.getTableName() + "," + + UserTable.table.getTableName() + + " WHERE " + + UserTable.table.id.getQualifiedColName() + " = " + + ExternalDataTable.table.ownerRef.getQualifiedColName(); + Statement stmt = null; + HashMap> allUserExtDataIDH = + new HashMap>(); + try { + stmt = getConnection().createStatement(); + ResultSet rset = stmt.executeQuery(sql); + while (rset.next()) { + ExternalDataIdentifier extDataID = + ExternalDataTable.table.getExternalDataIdentifier(rset); + Vector userExtDataIDV = + allUserExtDataIDH.get(extDataID.getOwner()); + if (userExtDataIDV == null) { + userExtDataIDV = new Vector(); + allUserExtDataIDH.put(extDataID.getOwner(), userExtDataIDV); + } + userExtDataIDV.add(extDataID); + } + } catch (Exception e) { + lg.error(e.getMessage(), e); + throw new DataAccessException("Error: getAllExternalDataIdentifiers", e); + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (Exception e) { + lg.error(e.getMessage(), e); + } + } + } + return allUserExtDataIDH; + } + + public static synchronized HashMap getFunctionFileNamesAndSimKeys(User user) + throws DataAccessException { + + String sql = + "SELECT " + + SimulationJobTable.table.simRef.getQualifiedColName() + "," + + SimulationJobTable.table.jobIndex.getQualifiedColName() + + " FROM " + + SimulationJobTable.table.getTableName() + "," + + SimulationTable.table.getTableName() + + " WHERE " + + SimulationTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + " = " + SimulationJobTable.table.simRef.getQualifiedColName() + + " UNION " + + " SELECT " + + SimulationTable.table.id.getQualifiedColName() + "," + + "TO_NUMBER(NULL) " +//SimulationJobTable.table.jobIndex.getUnqualifiedColName()+ + " FROM " + + SimulationTable.table.getTableName() + + " WHERE " + + SimulationTable.table.ownerRef.getQualifiedColName() + "=" + user.getID() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + + " NOT IN (SELECT " + SimulationJobTable.table.simRef.getQualifiedColName() + + " FROM " + SimulationJobTable.table.getTableName() + " )" + + " UNION " + + " SELECT " + + ExternalDataTable.table.id.getQualifiedColName() + "," + + "TO_NUMBER(0) " + + " FROM " + + ExternalDataTable.table.getTableName() + + " WHERE " + + ExternalDataTable.table.ownerRef.getQualifiedColName() + "=" + user.getID(); + + + Statement stmt = null; + HashMap functionNamesH = new HashMap(); + try { + stmt = getConnection().createStatement(); + ResultSet rset = stmt.executeQuery(sql); + while (rset.next()) { + KeyValue simKey = new KeyValue(rset.getBigDecimal(1)); + BigDecimal jobIndex = rset.getBigDecimal(2); + boolean isOldStyle = rset.wasNull(); + functionNamesH.put( + SimulationData.createCanonicalFunctionsFileName( + simKey, (isOldStyle ? 0 : jobIndex.intValue()), isOldStyle), + simKey + ); + } + } catch (Exception e) { + lg.error(e.getMessage(), e); + throw new DataAccessException("Error: getFunctionFileNamesAndSimKeys", e); + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (Exception e) { + lg.error(e.getMessage(), e); + } + } + } + return functionNamesH; + } + + public static synchronized FieldDataFileOperationResults.FieldDataReferenceInfo getModelDescriptionForSimulation(User user, KeyValue simulationKey) + throws DataAccessException { + + String sqlMathModel = + "SELECT " + + MathModelTable.table.name.getQualifiedColName() + "," + + SimulationTable.table.name.getQualifiedColName() + "," + + "TO_CHAR(" + MathModelTable.table.versionDate.getQualifiedColName() + "," + DATE_FORMAT_STRING + ")" + "," + + MathModelTable.table.id.getQualifiedColName() + + " FROM " + + SimulationTable.table.getTableName() + "," + + MathModelSimulationLinkTable.table.getTableName() + "," + + MathModelTable.table.getTableName() + + " WHERE " + + SimulationTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + + " AND (" + + SimulationTable.table.id.getQualifiedColName() + " = " + simulationKey.toString() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + " = " + + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + + " AND " + + MathModelSimulationLinkTable.table.mathModelRef.getQualifiedColName() + " = " + + MathModelTable.table.id.getQualifiedColName() + + ") OR (" + + SimulationTable.table.versionParentSimRef.getQualifiedColName() + " IS NOT NULL" + + " AND " + + SimulationTable.table.versionParentSimRef.getQualifiedColName() + " = " + simulationKey.toString() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + " = " + + MathModelSimulationLinkTable.table.simRef.getQualifiedColName() + + " AND " + + MathModelSimulationLinkTable.table.mathModelRef.getQualifiedColName() + " = " + + MathModelTable.table.id.getQualifiedColName() + + ")"; + + String sqlBioModel = + "SELECT " + + BioModelTable.table.name.getQualifiedColName() + "," + + SimContextTable.table.name.getQualifiedColName() + "," + + SimulationTable.table.name.getQualifiedColName() + "," + + "TO_CHAR(" + BioModelTable.table.versionDate.getQualifiedColName() + "," + DATE_FORMAT_STRING + ")" + "," + + BioModelTable.table.id.getQualifiedColName() + + " FROM " + + SimulationTable.table.getTableName() + "," + + BioModelSimulationLinkTable.table.getTableName() + "," + + SimContextTable.table.getTableName() + "," + + BioModelSimContextLinkTable.table.getTableName() + "," + + BioModelTable.table.getTableName() + + " WHERE " + + SimulationTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + + " AND (" + + SimulationTable.table.id.getQualifiedColName() + " = " + simulationKey.toString() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + " = " + + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + + " AND " + + BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName() + " = " + + BioModelTable.table.id.getQualifiedColName() + + " AND " + + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " = " + + BioModelTable.table.id.getQualifiedColName() + + " AND " + + SimContextTable.table.id.getQualifiedColName() + " = " + + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + + " AND " + + SimContextTable.table.mathRef.getQualifiedColName() + " = " + + SimulationTable.table.mathRef.getQualifiedColName() + + ") OR (" + + SimulationTable.table.versionParentSimRef.getQualifiedColName() + " IS NOT NULL" + + " AND " + + SimulationTable.table.versionParentSimRef.getQualifiedColName() + " = " + simulationKey.toString() + + " AND " + + SimulationTable.table.id.getQualifiedColName() + " = " + + BioModelSimulationLinkTable.table.simRef.getQualifiedColName() + + " AND " + + BioModelSimulationLinkTable.table.bioModelRef.getQualifiedColName() + " = " + + BioModelTable.table.id.getQualifiedColName() + + " AND " + + BioModelSimContextLinkTable.table.bioModelRef.getQualifiedColName() + " = " + + BioModelTable.table.id.getQualifiedColName() + + " AND " + + SimContextTable.table.id.getQualifiedColName() + " = " + + BioModelSimContextLinkTable.table.simContextRef.getQualifiedColName() + + " AND " + + SimContextTable.table.mathRef.getQualifiedColName() + " = " + + SimulationTable.table.mathRef.getQualifiedColName() + + ")"; // OR // (vc_simulation.parentsimref is not null @@ -512,55 +533,61 @@ public static synchronized FieldDataFileOperationResults.FieldDataReferenceInfo // AND vc_simcontext.mathref = vc_simulation.mathref // ) - String sqlFieldData = - "SELECT "+ - ExternalDataTable.table.externalDataName.getQualifiedColName()+ - " FROM " + - ExternalDataTable.table.getTableName()+ - " WHERE " + - ExternalDataTable.table.ownerRef.getQualifiedColName() +" = " + user.getID() + - " AND "+ - ExternalDataTable.table.id.getQualifiedColName()+ " = " +simulationKey.toString(); - - Statement stmt = null; - FieldDataFileOperationResults.FieldDataReferenceInfo fieldDataRefInfo = null; - try { - stmt = getConnection().createStatement(); - ResultSet rset = stmt.executeQuery(sqlMathModel); - if(rset.next()){ - fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); - fieldDataRefInfo.referenceSourceType = VersionableType.MathModelMetaData.getTypeName(); - fieldDataRefInfo.referenceSourceName = rset.getString(1); - fieldDataRefInfo.simulationName = rset.getString(2); - fieldDataRefInfo.refSourceVersionDate = rset.getString(3); - fieldDataRefInfo.refSourceVersionKey = new KeyValue(rset.getBigDecimal(4)); - }else{ - rset.close(); - rset = stmt.executeQuery(sqlBioModel); - if(rset.next()){ - fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); - fieldDataRefInfo.referenceSourceType = VersionableType.BioModelMetaData.getTypeName(); - fieldDataRefInfo.referenceSourceName = rset.getString(1); - fieldDataRefInfo.applicationName = rset.getString(2); - fieldDataRefInfo.simulationName = rset.getString(3); - fieldDataRefInfo.refSourceVersionDate = rset.getString(4); - fieldDataRefInfo.refSourceVersionKey = new KeyValue(rset.getBigDecimal(5)); - }else{ - rset.close(); - rset = stmt.executeQuery(sqlFieldData); - if(rset.next()){ - fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); - fieldDataRefInfo.referenceSourceType = FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME; - fieldDataRefInfo.referenceSourceName = rset.getString(1); - } - } - } - }catch(Exception e){ - lg.error(e.getMessage(), e); - throw new DataAccessException("Error: getModelDescriptionForSimulation",e); - }finally { - if(stmt != null){try{stmt.close();}catch(Exception e){lg.error(e.getMessage(), e);}} - } - return fieldDataRefInfo; -} + String sqlFieldData = + "SELECT " + + ExternalDataTable.table.externalDataName.getQualifiedColName() + + " FROM " + + ExternalDataTable.table.getTableName() + + " WHERE " + + ExternalDataTable.table.ownerRef.getQualifiedColName() + " = " + user.getID() + + " AND " + + ExternalDataTable.table.id.getQualifiedColName() + " = " + simulationKey.toString(); + + Statement stmt = null; + FieldDataFileOperationResults.FieldDataReferenceInfo fieldDataRefInfo = null; + try { + stmt = getConnection().createStatement(); + ResultSet rset = stmt.executeQuery(sqlMathModel); + if (rset.next()) { + fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); + fieldDataRefInfo.referenceSourceType = VersionableType.MathModelMetaData.getTypeName(); + fieldDataRefInfo.referenceSourceName = rset.getString(1); + fieldDataRefInfo.simulationName = rset.getString(2); + fieldDataRefInfo.refSourceVersionDate = rset.getString(3); + fieldDataRefInfo.refSourceVersionKey = new KeyValue(rset.getBigDecimal(4)); + } else { + rset.close(); + rset = stmt.executeQuery(sqlBioModel); + if (rset.next()) { + fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); + fieldDataRefInfo.referenceSourceType = VersionableType.BioModelMetaData.getTypeName(); + fieldDataRefInfo.referenceSourceName = rset.getString(1); + fieldDataRefInfo.applicationName = rset.getString(2); + fieldDataRefInfo.simulationName = rset.getString(3); + fieldDataRefInfo.refSourceVersionDate = rset.getString(4); + fieldDataRefInfo.refSourceVersionKey = new KeyValue(rset.getBigDecimal(5)); + } else { + rset.close(); + rset = stmt.executeQuery(sqlFieldData); + if (rset.next()) { + fieldDataRefInfo = new FieldDataFileOperationResults.FieldDataReferenceInfo(); + fieldDataRefInfo.referenceSourceType = FieldDataFileOperationResults.FieldDataReferenceInfo.FIELDDATATYPENAME; + fieldDataRefInfo.referenceSourceName = rset.getString(1); + } + } + } + } catch (Exception e) { + lg.error(e.getMessage(), e); + throw new DataAccessException("Error: getModelDescriptionForSimulation", e); + } finally { + if (stmt != null) { + try { + stmt.close(); + } catch (Exception e) { + lg.error(e.getMessage(), e); + } + } + } + return fieldDataRefInfo; + } }