Search in sources :

Example 61 with PropertyVetoException

use of java.beans.PropertyVetoException in project vcell by virtualcell.

the class ReactionRulePropertiesTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    Object o = getValueAt(rowIndex);
    if (!(o instanceof Parameter)) {
        return;
    }
    Parameter parameter = (Parameter) o;
    // try {
    switch(columnIndex) {
        case COLUMN_NAME:
            {
                try {
                    if (aValue instanceof String) {
                        String newName = (String) aValue;
                        if (!parameter.getName().equals(newName)) {
                            if (parameter instanceof LocalParameter) {
                                reactionRule.getKineticLaw().renameParameter(parameter.getName(), newName);
                            } else if (parameter instanceof LocalProxyParameter) {
                                parameter.setName(newName);
                            }
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                } catch (PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter name:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_IS_GLOBAL:
            {
                if (aValue.equals(Boolean.FALSE)) {
                    // check box has been <unset> (<true> to <false>) : change param from global to local
                    if ((parameter instanceof LocalProxyParameter) && ((((LocalProxyParameter) parameter).getTarget() instanceof Model.ReservedSymbol) || (((LocalProxyParameter) parameter).getTarget() instanceof SpeciesContext) || (((LocalProxyParameter) parameter).getTarget() instanceof ModelQuantity))) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a " + ((LocalProxyParameter) parameter).getTarget().getClass() + " in the model; cannot convert it to a local kinetic parameter.");
                    } else {
                        try {
                            reactionRule.getKineticLaw().convertParameterType(parameter, false);
                        } catch (PropertyVetoException pve) {
                            pve.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + pve.getMessage());
                        } catch (ExpressionBindingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, "Unable to convert parameter : \'" + parameter.getName() + "\' to local kinetics parameter : " + e.getMessage());
                        }
                    }
                } else {
                    // check box has been <set> (<false> to <true>) : change param from local to global
                    if ((parameter instanceof LocalParameter) && (((LocalParameter) parameter).getRole() != RbmKineticLaw.RbmKineticLawParameterType.UserDefined)) {
                        PopupGenerator.showErrorDialog(ownerTable, "Parameter : \'" + parameter.getName() + "\' is a pre-defined kinetics parameter (not user-defined); cannot convert it to a model level (global) parameter.");
                    } else {
                        ModelParameter mp = reactionRule.getModel().getModelParameter(parameter.getName());
                        // model already had the model parameter 'param', but check if 'param' value is different from
                        // model parameter with same name. If it is, the local value will be overridden by global (model) param
                        // value, and user should be warned.
                        String choice = "Ok";
                        if (mp != null && !(mp.getExpression().compareEqual(parameter.getExpression()))) {
                            String msgStr = "Model already has a global parameter named : \'" + parameter.getName() + "\'; with value = \'" + mp.getExpression().infix() + "\'; This local parameter \'" + parameter.getName() + "\' with value = \'" + parameter.getExpression().infix() + "\' will be overridden by the global value. \nPress \'Ok' to override " + "local value with global value of \'" + parameter.getName() + "\'. \nPress \'Cancel\' to retain new local value.";
                            choice = PopupGenerator.showWarningDialog(ownerTable, msgStr, new String[] { "Ok", "Cancel" }, "Ok");
                        }
                        if (choice.equals("Ok")) {
                            try {
                                // Now 'parameter' is a local kinetic parameter. If it is not numeric, and if its expression
                                // contains other local kinetic parameters, warn user that 'parameter' cannot be promoted because
                                // of its expression containing other local parameters.
                                boolean bPromoteable = true;
                                if (!parameter.getExpression().isNumeric()) {
                                    String[] symbols = parameter.getExpression().getSymbols();
                                    for (int i = 0; i < symbols.length; i++) {
                                        if (reactionRule.getKineticLaw().getLocalParameter(symbols[i]) != null) {
                                            PopupGenerator.showErrorDialog(ownerTable, "Parameter \'" + parameter.getName() + "\' contains other local kinetic parameters; Cannot convert it to global until the referenced parameters are global.");
                                            bPromoteable = false;
                                        }
                                    }
                                }
                                if (bPromoteable) {
                                    reactionRule.getKineticLaw().convertParameterType(parameter, true);
                                }
                            } catch (PropertyVetoException pve) {
                                pve.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + pve.getMessage());
                            } catch (ExpressionBindingException e) {
                                e.printStackTrace(System.out);
                                PopupGenerator.showErrorDialog(ownerTable, "Cannot convert parameter \'" + parameter.getName() + "\' to global parameter : " + e.getMessage());
                            }
                        }
                    }
                }
                fireTableRowsUpdated(rowIndex, rowIndex);
                break;
            }
        case COLUMN_VALUE:
            {
                try {
                    if (aValue instanceof ScopedExpression) {
                        // }
                        throw new RuntimeException("unexpected value type ScopedExpression");
                    } else if (aValue instanceof String) {
                        String newExpressionString = (String) aValue;
                        if (parameter instanceof LocalParameter) {
                            LocalParameter localParameter = (LocalParameter) parameter;
                            reactionRule.getKineticLaw().setParameterValue(localParameter, new Expression(newExpressionString), true);
                        } else if (parameter instanceof LocalProxyParameter) {
                            parameter.setExpression(new Expression(newExpressionString));
                        }
                    }
                    reactionRule.getKineticLaw().resolveUndefinedUnits();
                    fireTableRowsUpdated(rowIndex, rowIndex);
                } catch (java.beans.PropertyVetoException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error:\n" + e.getMessage());
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Expression error:\n" + e.getMessage());
                }
                break;
            }
        case COLUMN_UNITS:
            {
                try {
                    if (aValue instanceof String && parameter instanceof LocalParameter && ((LocalParameter) parameter).getRole() == RbmKineticLaw.RbmKineticLawParameterType.UserDefined) {
                        String newUnitString = (String) aValue;
                        LocalParameter kineticsParm = (LocalParameter) parameter;
                        ModelUnitSystem modelUnitSystem = reactionRule.getModel().getUnitSystem();
                        if (!kineticsParm.getUnitDefinition().getSymbol().equals(newUnitString)) {
                            kineticsParm.setUnitDefinition(modelUnitSystem.getInstance(newUnitString));
                            reactionRule.getKineticLaw().resolveUndefinedUnits();
                            fireTableRowsUpdated(rowIndex, rowIndex);
                        }
                    }
                } catch (VCUnitException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "Error changing parameter unit:\n" + e.getMessage());
                }
                break;
            }
    }
// }catch (java.beans.PropertyVetoException e){
// e.printStackTrace(System.out);
// }
}
Also used : LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) SpeciesContext(cbit.vcell.model.SpeciesContext) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) ExpressionException(cbit.vcell.parser.ExpressionException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) VCUnitException(cbit.vcell.units.VCUnitException) ModelParameter(cbit.vcell.model.Model.ModelParameter) ScopedExpression(cbit.gui.ScopedExpression) ModelQuantity(cbit.vcell.model.ModelQuantity) ScopedExpression(cbit.gui.ScopedExpression) Expression(cbit.vcell.parser.Expression) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) ModelParameter(cbit.vcell.model.Model.ModelParameter) Parameter(cbit.vcell.model.Parameter) LocalProxyParameter(cbit.vcell.mapping.ParameterContext.LocalProxyParameter) UnresolvedParameter(cbit.vcell.mapping.ParameterContext.UnresolvedParameter) ModelUnitSystem(cbit.vcell.model.ModelUnitSystem)

Example 62 with PropertyVetoException

use of java.beans.PropertyVetoException in project vcell by virtualcell.

the class DisplayTimeSeriesOp method displayImageTimeSeries.

public void displayImageTimeSeries(final ImageTimeSeries<? extends Image> imageTimeSeries, final String title, final WindowListener windowListener) throws ImageException, IOException {
    try {
        System.out.println("starting to prepare data for time series viewing");
        final PDEDataViewer pdeDataViewer = new PDEDataViewer();
        DataSetControllerProvider dataSetControllerProvider;
        try {
            dataSetControllerProvider = getDataSetControllerProvider(imageTimeSeries, pdeDataViewer);
        } catch (ImageException | IOException e1) {
            e1.printStackTrace();
            throw new RuntimeException(e1.getMessage(), e1);
        }
        VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
        OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
        final VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

            public User getOwner() {
                return new User("nouser", null);
            }

            public KeyValue getDataKey() {
                return null;
            }

            public String getID() {
                return "mydata";
            }
        };
        PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
        final ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
        final RequestManager requestManager = new RequestManagerAdapter() {
        };
        final DataViewerManager dataViewerManager = new DataViewerManager() {

            public void dataJobMessage(DataJobEvent event) {
            }

            public void exportMessage(ExportEvent event) {
            }

            public void addDataListener(DataListener newListener) {
            }

            public UserPreferences getUserPreferences() {
                // getRequestManager().getUserPreferences();
                return null;
            }

            public void removeDataListener(DataListener newListener) {
            }

            public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) {
            // getLocalRequestManager().startExport(outputContext, FieldDataWindowManager.this, exportSpecs);
            }

            public void simStatusChanged(SimStatusEvent simStatusEvent) {
            }

            public User getUser() {
                return new User("dummy", new KeyValue("123"));
            // return getRequestManager().getDocumentManager().getUser();
            }

            public RequestManager getRequestManager() {
                return requestManager;
            }
        };
        System.out.println("ready to display time series");
        SwingUtilities.invokeAndWait(new Runnable() {

            @Override
            public void run() {
                JFrame jframe = new TopLevelFrame();
                jframe.setTitle(title);
                jframe.getContentPane().add(pdeDataViewer);
                jframe.setSize(1000, 600);
                jframe.setVisible(true);
                if (windowListener != null) {
                    jframe.addWindowListener(windowListener);
                }
                try {
                    pdeDataViewer.setDataViewerManager(dataViewerManager);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
                pdeDataViewer.setPdeDataContext(myPdeDataContext);
            }
        });
    } catch (InvocationTargetException | InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : ImageException(cbit.image.ImageException) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) ExportEvent(cbit.rmi.event.ExportEvent) ExportSpecs(cbit.vcell.export.server.ExportSpecs) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) RequestManager(cbit.vcell.client.RequestManager) JFrame(javax.swing.JFrame) Component(java.awt.Component) VCDataManager(cbit.vcell.simdata.VCDataManager) IOException(java.io.IOException) OutputContext(cbit.vcell.simdata.OutputContext) InvocationTargetException(java.lang.reflect.InvocationTargetException) PropertyVetoException(java.beans.PropertyVetoException) RequestManagerAdapter(cbit.vcell.client.RequestManagerAdapter) DataViewerManager(cbit.vcell.client.DataViewerManager) DataJobEvent(cbit.rmi.event.DataJobEvent) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimStatusEvent(cbit.vcell.client.server.SimStatusEvent) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) DataListener(cbit.vcell.simdata.DataListener) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 63 with PropertyVetoException

use of java.beans.PropertyVetoException in project vcell by virtualcell.

the class BioModelEditorApplicationsPanel method deleteButtonPressed.

protected void deleteButtonPressed() {
    int[] rows = table.getSelectedRows();
    if (rows == null || rows.length == 0) {
        return;
    }
    String confirm = PopupGenerator.showOKCancelWarningDialog(this, "Deleting application(s)", "Are you sure you want to delete selected application(s)?");
    if (confirm.equals(UserMessage.OPTION_CANCEL)) {
        return;
    }
    ArrayList<SimulationContext> deleteList = new ArrayList<SimulationContext>();
    for (int r : rows) {
        SimulationContext simContext = tableModel.getValueAt(r);
        if (simContext != null) {
            deleteList.add(simContext);
        }
    }
    try {
        for (SimulationContext sc : deleteList) {
            deleteApplication(sc);
        }
    } catch (PropertyVetoException ex) {
        ex.printStackTrace();
        DialogUtils.showErrorDialog(BioModelEditorApplicationsPanel.this, ex.getMessage());
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 64 with PropertyVetoException

use of java.beans.PropertyVetoException in project vcell by virtualcell.

the class SimulationListPanel method quickRun.

/*
	private void particleView() {
		int row = getScrollPaneTable().getSelectedRow();
		if (row < 0) {
			return;
		}
		Simulation selectedSim = getSimulationListTableModel1().getValueAt(row);
		getSimulationWorkspace().getClientSimManager().runSmoldynParticleView(selectedSim);
	}
	*/
private void quickRun(ViewerType viewerType) {
    int row = getScrollPaneTable().getSelectedRow();
    if (row < 0) {
        return;
    }
    activateConsole();
    Simulation selectedSim = getSimulationListTableModel1().getValueAt(row);
    SolverDescription solverDescription = selectedSim.getSolverTaskDescription().getSolverDescription();
    if (solverDescription.equals(SolverDescription.FiniteVolume)) {
        if (getSimulationWorkspace().getSimulationOwner() instanceof SimulationContext) {
            String option = DialogUtils.showOKCancelWarningDialog(SimulationListPanel.this, "Deprecated Solver", VCellErrorMessages.getSemiFVSolverCompiledSolverDeprecated(selectedSim));
            if (option.equals(SimpleUserMessage.OPTION_CANCEL)) {
                return;
            }
            try {
                selectedSim.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
                selectedSim.setIsDirty(true);
            } catch (PropertyVetoException e) {
                e.printStackTrace();
            }
        }
    }
    getSimulationWorkspace().getClientSimManager().runQuickSimulation(selectedSim, viewerType);
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) SolverDescription(cbit.vcell.solver.SolverDescription) Simulation(cbit.vcell.solver.Simulation) SimulationContext(cbit.vcell.mapping.SimulationContext)

Example 65 with PropertyVetoException

use of java.beans.PropertyVetoException in project vcell by virtualcell.

the class SimulationListPanel method runSimulations.

/**
 * Comment
 */
private void runSimulations() {
    final ArrayList<Simulation> simList = new ArrayList<Simulation>();
    int[] selections = getScrollPaneTable().getSelectedRows();
    for (int i = 0; i < selections.length; i++) {
        Simulation sim = (Simulation) (ivjSimulationListTableModel1.getValueAt(selections[i]));
        if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.FiniteVolume)) {
            if (getSimulationWorkspace().getSimulationOwner() instanceof SimulationContext) {
                String option = DialogUtils.showOKCancelWarningDialog(SimulationListPanel.this, "Deprecated Solver", VCellErrorMessages.getSemiFVSolverCompiledSolverDeprecated(sim));
                if (option.equals(SimpleUserMessage.OPTION_CANCEL)) {
                    return;
                }
                try {
                    sim.getSolverTaskDescription().setSolverDescription(SolverDescription.FiniteVolumeStandalone);
                    sim.setIsDirty(true);
                } catch (PropertyVetoException e) {
                    e.printStackTrace();
                }
            }
        }
        simList.add(sim);
    }
    if (simList.size() > 0) {
        activateConsole();
        Simulation[] toRun = simList.toArray(new Simulation[0]);
        getSimulationWorkspace().runSimulations(toRun, this);
    }
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) Simulation(cbit.vcell.solver.Simulation) ArrayList(java.util.ArrayList) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

PropertyVetoException (java.beans.PropertyVetoException)342 TransactionFailure (org.jvnet.hk2.config.TransactionFailure)118 ActionReport (org.glassfish.api.ActionReport)64 Expression (cbit.vcell.parser.Expression)41 ExpressionException (cbit.vcell.parser.ExpressionException)40 ArrayList (java.util.ArrayList)40 Config (com.sun.enterprise.config.serverbeans.Config)31 ModelException (cbit.vcell.model.ModelException)26 Structure (cbit.vcell.model.Structure)25 Property (org.jvnet.hk2.config.types.Property)25 ModelVetoException (com.sun.jdo.api.persistence.model.ModelVetoException)24 List (java.util.List)24 Model (cbit.vcell.model.Model)22 DataAccessException (org.vcell.util.DataAccessException)19 SpeciesContext (cbit.vcell.model.SpeciesContext)18 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)18 Resources (com.sun.enterprise.config.serverbeans.Resources)18 Element (org.jdom.Element)18 MathException (cbit.vcell.math.MathException)16 IOException (java.io.IOException)16