Search in sources :

Example 1 with Change

use of org.jlibsedml.Change in project vcell by virtualcell.

the class SEDMLChooserPanel method initialize.

private void initialize() {
    Set<String> issues = new HashSet<>();
    setLayout(new GridBagLayout());
    int gridy = 0;
    // (incompatibility with vCell for example) and for them we create a list of problems which we show to the user
    for (AbstractTask at : sedml.getTasks()) {
        String text = "";
        String tooltip = "";
        boolean issueFound = false;
        if (at instanceof Task) {
            Task t = (Task) at;
            text = " Simple task '" + t.getId() + "' - " + sedml.getModelWithId(t.getModelReference()).getClass().getSimpleName() + // model class
            " '" + SEDMLUtil.getName(sedml.getModelWithId(t.getModelReference())) + "' : " + sedml.getSimulation(t.getSimulationReference()).getClass().getSimpleName() + // simulation class
            " '" + SEDMLUtil.getName(sedml.getSimulation(t.getSimulationReference())) + "' ";
            tooltip = "The model has " + sedml.getModelWithId(t.getModelReference()).getListOfChanges().size() + " changes.";
        } else if (at instanceof RepeatedTask) {
            RepeatedTask rt = (RepeatedTask) at;
            // TODO: we issue warning that importing repeated task is not implemented yet
            // but we have still can import it as simple task, so we don't set issueFound to true
            issues.add("Importing a RepeatedTask is not implemented yet, '" + SEDMLUtil.getName(rt) + "' may be imported as SimpleTask.");
            // add an error message to the list of errors and skip the task
            for (Change c : rt.getChanges()) {
                if (!c.getChangeKind().equals(SEDMLTags.SET_VALUE_KIND)) {
                    issues.add("The '" + c.getChangeKind() + "' change kind is not supported.");
                    issueFound = true;
                }
            }
            switch(rt.getSubTasks().size()) {
                case 0:
                    issues.add("At least one subtask is required within a repeated task: " + rt.getId());
                    issueFound = true;
                case 1:
                    // first (and only) element
                    SubTask st = rt.getSubTasks().entrySet().iterator().next().getValue();
                    String taskId = st.getTaskId();
                    AbstractTask t = sedml.getTaskWithId(taskId);
                    text = " Repeated task '" + rt.getId() + "' - " + sedml.getModelWithId(t.getModelReference()).getClass().getSimpleName() + // model class
                    " '" + SEDMLUtil.getName(sedml.getModelWithId(t.getModelReference())) + "' : " + sedml.getSimulation(t.getSimulationReference()).getClass().getSimpleName() + // simulation class
                    " '" + SEDMLUtil.getName(sedml.getSimulation(t.getSimulationReference())) + "' ";
                    tooltip = "The repeated task has " + rt.getChanges().size() + " changes and " + rt.getRanges().size() + " ranges.";
                    break;
                default:
                    issues.add("Multiple subtasks within a repeated task '" + rt.getId() + "' are not supported.");
                    issueFound = true;
            }
        } else {
            issues.add("The task class '" + SEDMLUtil.getName(at) + "' is not supported.");
            issueFound = true;
        }
        if (issueFound) {
            // we skip the tasks we don't know how to import in vCell
            continue;
        }
        JRadioButton rb = new JRadioButton(text);
        rb.setToolTipText(tooltip);
        SEDMLRadioButtonModel bm = new SEDMLRadioButtonModel(at);
        rb.setModel(bm);
        if (gridy == 0) {
            rb.setSelected(true);
        }
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 4, 2, 4);
        group.add(rb);
        add(rb, gbc);
        gridy++;
    }
    // we display the issues (but no more than a certain number)
    final int MAX_ISSUES = 10;
    int issueIndex = 0;
    for (String issue : issues) {
        if (issueIndex >= MAX_ISSUES) {
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.gridx = 0;
            gbc.gridy = gridy;
            gbc.anchor = GridBagConstraints.WEST;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.insets = new Insets(2, 4, 2, 4);
            add(new JLabel("<html><font color = \"#8B0000\">" + "...More" + "</font></html>"), gbc);
            gridy++;
            break;
        }
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = gridy;
        gbc.anchor = GridBagConstraints.WEST;
        gbc.fill = GridBagConstraints.HORIZONTAL;
        gbc.insets = new Insets(2, 4, 2, 4);
        add(new JLabel("<html><font color = \"#8B0000\">" + issue + "</font></html>"), gbc);
        gridy++;
        issueIndex++;
    }
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = gridy;
    gbc.gridwidth = 2;
    gbc.weightx = 1;
    // fake cell used for filling all the vertical empty space
    gbc.weighty = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.insets = new Insets(4, 4, 4, 10);
    add(new JLabel(""), gbc);
}
Also used : RepeatedTask(org.jlibsedml.RepeatedTask) SubTask(org.jlibsedml.SubTask) AbstractTask(org.jlibsedml.AbstractTask) Task(org.jlibsedml.Task) GridBagConstraints(java.awt.GridBagConstraints) AbstractTask(org.jlibsedml.AbstractTask) JRadioButton(javax.swing.JRadioButton) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) JLabel(javax.swing.JLabel) Change(org.jlibsedml.Change) RepeatedTask(org.jlibsedml.RepeatedTask) SubTask(org.jlibsedml.SubTask) HashSet(java.util.HashSet)

Aggregations

GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 Insets (java.awt.Insets)1 HashSet (java.util.HashSet)1 JLabel (javax.swing.JLabel)1 JRadioButton (javax.swing.JRadioButton)1 AbstractTask (org.jlibsedml.AbstractTask)1 Change (org.jlibsedml.Change)1 RepeatedTask (org.jlibsedml.RepeatedTask)1 SubTask (org.jlibsedml.SubTask)1 Task (org.jlibsedml.Task)1