Search in sources :

Example 71 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method isCellEditable.

public boolean isCellEditable(int row, int columnIndex) {
    Column col = Column.values()[columnIndex];
    if (col == Column.name) {
        return true;
    }
    RbmObservable o = getValueAt(row);
    if (o == null) {
        return false;
    }
    if (col == Column.structure) {
        return false;
    }
    if (col == Column.type) {
        return true;
    }
    if (col == Column.depiction) {
        return false;
    }
    final List<SpeciesPattern> spList = o.getSpeciesPatternList();
    for (SpeciesPattern sp : spList) {
        final List<MolecularTypePattern> mtpList = sp.getMolecularTypePatterns();
        for (MolecularTypePattern mtp : mtpList) {
            MolecularType mt = mtp.getMolecularType();
            if (mt.getComponentList().size() != 0) {
                return false;
            }
        }
    }
    return true;
}
Also used : MolecularType(org.vcell.model.rbm.MolecularType) RbmObservable(cbit.vcell.model.RbmObservable) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 72 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method propertyChange.

@Override
public void propertyChange(PropertyChangeEvent evt) {
    super.propertyChange(evt);
    Object source = evt.getSource();
    // if (source == getModel().getRbmModelContainer()) {
    if (source == getModel()) {
        if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST)) {
            refreshData();
            List<RbmObservable> oldValue = (List<RbmObservable>) evt.getOldValue();
            if (oldValue != null) {
                for (RbmObservable observable : oldValue) {
                    observable.removePropertyChangeListener(this);
                    SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
                    RbmUtils.removePropertyChangeListener(speciesPattern, this);
                }
            }
            List<RbmObservable> newValue = (List<RbmObservable>) evt.getNewValue();
            if (newValue != null) {
                for (RbmObservable observable : newValue) {
                    observable.addPropertyChangeListener(this);
                    SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
                    RbmUtils.addPropertyChangeListener(speciesPattern, this);
                }
            }
        } else if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST)) {
            // we need this?
            refreshData();
        }
    } else if (source instanceof RbmObservable) {
        RbmObservable mt = (RbmObservable) source;
        int changeRow = getRowIndex(mt);
        if (changeRow >= 0) {
            fireTableRowsUpdated(changeRow, changeRow);
        }
    // if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
    // SpeciesPattern oldValue = (SpeciesPattern) evt.getOldValue();
    // if (oldValue != null) {
    // RbmUtils.removePropertyChangeListener(oldValue, this);
    // }
    // SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
    // if (newValue != null) {
    // RbmUtils.addPropertyChangeListener(newValue, this);
    // }
    // }
    } else if (source instanceof SpeciesPattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
            List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
            if (oldValue != null) {
                for (MolecularTypePattern mtp : oldValue) {
                    RbmUtils.removePropertyChangeListener(mtp, this);
                }
            }
            List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
            if (newValue != null) {
                for (MolecularTypePattern mtp : newValue) {
                    RbmUtils.addPropertyChangeListener(mtp, this);
                }
            }
        }
    } else if (source instanceof MolecularTypePattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
            List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
            if (oldValue != null) {
                for (MolecularComponentPattern mcp : oldValue) {
                    RbmUtils.removePropertyChangeListener(mcp, this);
                }
            }
            List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
            if (newValue != null) {
                for (MolecularComponentPattern mcp : newValue) {
                    RbmUtils.addPropertyChangeListener(mcp, this);
                }
            }
        }
    } else if (source instanceof MolecularComponentPattern) {
        fireTableRowsUpdated(0, getRowCount() - 1);
        if (source.equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
            ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
            if (oldValue != null) {
                oldValue.removePropertyChangeListener(this);
            }
            ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
            if (newValue != null) {
                newValue.addPropertyChangeListener(this);
            }
        }
    } else if (evt.getSource() instanceof MolecularComponent) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    } else if (evt.getSource() instanceof ComponentStateDefinition) {
        fireTableRowsUpdated(0, getRowCount() - 1);
    }
// updateStructureComboBox();
}
Also used : MolecularComponentPattern(org.vcell.model.rbm.MolecularComponentPattern) MolecularComponent(org.vcell.model.rbm.MolecularComponent) RbmObservable(cbit.vcell.model.RbmObservable) ArrayList(java.util.ArrayList) JList(javax.swing.JList) List(java.util.List) MolecularTypePattern(org.vcell.model.rbm.MolecularTypePattern) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern) ComponentStateDefinition(org.vcell.model.rbm.ComponentStateDefinition)

Example 73 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method getValueAt.

public Object getValueAt(int rowIndex, int columnIndex) {
    RbmObservable observable = getValueAt(rowIndex);
    Column col = Column.values()[columnIndex];
    if (observable == null) {
        if (col == Column.name) {
            return ADD_NEW_HERE_TEXT;
        }
    } else {
        switch(col) {
            case name:
                return observable.getName();
            case species_pattern:
                if (!observable.getSpeciesPatternList().isEmpty()) {
                    String speciesPatterns = "";
                    for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
                        speciesPatterns += sp.toString() + " ";
                    }
                    return speciesPatterns;
                } else {
                    return ("");
                }
            case type:
                return observable.getType();
            case structure:
                return observable.getStructure();
        }
    }
    return null;
}
Also used : RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 74 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method bioModelChange.

@Override
protected void bioModelChange(PropertyChangeEvent evt) {
    super.bioModelChange(evt);
    BioModel oldValue = (BioModel) evt.getOldValue();
    if (oldValue != null) {
        RbmModelContainer rbmModelContainer = (RbmModelContainer) (oldValue.getModel().getRbmModelContainer());
        // TODO: listen to something ???  	rbmModelContainer.removePropertyChangeListener(this);
        for (RbmObservable observable : rbmModelContainer.getObservableList()) {
            observable.removePropertyChangeListener(this);
            for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
                RbmUtils.removePropertyChangeListener(speciesPattern, this);
            }
        }
    }
    BioModel newValue = (BioModel) evt.getNewValue();
    if (newValue != null) {
        RbmModelContainer rbmModelContainer = (RbmModelContainer) (newValue.getModel().getRbmModelContainer());
        // TODO:			rbmModelContainer.addPropertyChangeListener(this);
        for (RbmObservable observable : rbmModelContainer.getObservableList()) {
            observable.addPropertyChangeListener(this);
            for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
                RbmUtils.addPropertyChangeListener(speciesPattern, this);
            }
        }
    }
}
Also used : RbmModelContainer(cbit.vcell.model.Model.RbmModelContainer) BioModel(cbit.vcell.biomodel.BioModel) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Example 75 with SpeciesPattern

use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.

the class ObservableTableModel method checkInputValue.

public String checkInputValue(String inputValue, int row, int column) {
    String errMsg = null;
    final Column col = Column.values()[column];
    RbmObservable selectedObservable = getValueAt(row);
    switch(col) {
        case name:
            inputValue = inputValue.trim();
            if (inputValue.length() > 0) {
                String mangled = TokenMangler.fixTokenStrict(inputValue);
                if (!mangled.equals(inputValue)) {
                    errMsg = RbmObservable.typeName + " '" + inputValue + "' not legal identifier, try '" + mangled + "'";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
                RbmObservable o = getModel().getRbmModelContainer().getObservable(inputValue);
                if (o != null && o != selectedObservable) {
                    errMsg = "Observable '" + inputValue + "' already exists!";
                    errMsg += VCellErrorMessages.PressEscToUndo;
                    errMsg = "<html>" + errMsg + "</html>";
                    return errMsg;
                }
            }
            break;
        case species_pattern:
            try {
                inputValue = inputValue.trim();
                if (inputValue.length() > 0) {
                    StringTokenizer tokens = new StringTokenizer(inputValue);
                    while (tokens.hasMoreTokens()) {
                        String token = tokens.nextToken();
                        // parsing will throw appropriate exception if molecular type or component don't exist
                        SpeciesPattern speciesPattern = RbmUtils.parseSpeciesPattern(token, bioModel.getModel());
                    }
                }
            } catch (Exception ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
        case type:
            try {
                inputValue = inputValue.trim();
                RbmObservable.ObservableType ot = RbmObservable.ObservableType.valueOf((String) inputValue);
            } catch (IllegalArgumentException e) {
                e.printStackTrace(System.out);
                errMsg = "";
                for (int i = 0; i < RbmObservable.ObservableType.values().length; i++) {
                    errMsg += RbmObservable.ObservableType.values()[i].toString();
                    if (i < RbmObservable.ObservableType.values().length - 1) {
                        errMsg += " or ";
                    }
                }
                errMsg = "Type may only be " + errMsg;
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            } catch (Exception ex) {
                errMsg = ex.getMessage();
                errMsg += VCellErrorMessages.PressEscToUndo;
                errMsg = "<html>" + errMsg + "</html>";
                return errMsg;
            }
            break;
    }
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) ObservableType(cbit.vcell.model.RbmObservable.ObservableType) RbmObservable(cbit.vcell.model.RbmObservable) SpeciesPattern(org.vcell.model.rbm.SpeciesPattern)

Aggregations

SpeciesPattern (org.vcell.model.rbm.SpeciesPattern)93 MolecularTypePattern (org.vcell.model.rbm.MolecularTypePattern)39 MolecularComponentPattern (org.vcell.model.rbm.MolecularComponentPattern)30 MolecularType (org.vcell.model.rbm.MolecularType)25 RbmObservable (cbit.vcell.model.RbmObservable)22 SpeciesContext (cbit.vcell.model.SpeciesContext)22 Structure (cbit.vcell.model.Structure)22 Point (java.awt.Point)18 ReactionRule (cbit.vcell.model.ReactionRule)16 ArrayList (java.util.ArrayList)16 ComponentStatePattern (org.vcell.model.rbm.ComponentStatePattern)16 Graphics (java.awt.Graphics)13 PropertyVetoException (java.beans.PropertyVetoException)13 SpeciesPatternLargeShape (cbit.vcell.graph.SpeciesPatternLargeShape)12 ProductPattern (cbit.vcell.model.ProductPattern)12 ReactantPattern (cbit.vcell.model.ReactantPattern)12 Dimension (java.awt.Dimension)12 ComponentStateDefinition (org.vcell.model.rbm.ComponentStateDefinition)12 Model (cbit.vcell.model.Model)11 ModelException (cbit.vcell.model.ModelException)11