/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.opensim.tracking.tools;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import org.openide.awt.ActionRegistration;
import org.openide.awt.ActionReference;
import org.openide.awt.ActionReferences;
import org.openide.awt.ActionID;
import org.openide.util.Exceptions;
import org.openide.util.NbBundle.Messages;
import org.opensim.tracking.ForwardToolModel;
import org.opensim.view.pub.OpenSimDB;

@ActionID(category = "Edit",
id = "org.opensim.tracking.tools.ToolbarRunAction")
@ActionRegistration(iconBase = "org/opensim/tracking/tools/run.png",
displayName = "#CTL_ToolbarRunAction")
@ActionReferences({
    @ActionReference(path = "Toolbars/UndoRedo", position = 600),
    @ActionReference(path = "Shortcuts", name = "O-R")
})
@Messages("CTL_ToolbarRunAction=Run Forward Simulation")
public final class ToolbarRunAction implements ActionListener {

    boolean running = false;
    ForwardToolModel toolModel=null;
    public void actionPerformed(ActionEvent e) {
        if (!running) {
            try {
                // TODO implement action body
                toolModel = new ForwardToolModel(OpenSimDB.getInstance().getCurrentModel());
                toolModel.setSolveForEquilibrium(true);
                toolModel.execute();
                running = true;
                // Change 
            } catch (IOException ex) {
                Exceptions.printStackTrace(ex);
            }
        } else {
            if (toolModel!=null){ 
                toolModel.cancel();
                running = false;
            }
        }
        }
}

@@ -1012,37 +1012,8 @@
  %7B%0A%0A
-    boolean running = false;%0A
     
@@ -1110,16 +1110,53 @@
 if (
-!runn
+toolModel == null %7C%7C !toolModel.isExecut
 ing
+()
 ) %7B%0A
@@ -1409,40 +1409,8 @@
 ();%0A
-                running = true;%0A
     
@@ -1579,17 +1579,19 @@
 odel
+ 
 !=
+ 
 null)
-%7B
  
+%7B
 %0A   
@@ -1627,41 +1627,8 @@
 ();%0A
-                running = false;%0A
     
@@ -1643,24 +1643,20 @@
 %7D%0A        %7D%0A
-    
     %7D%0A%7D%0A

Make sure tool actually runs if not already running when using the toolbar button. Fixes issue reported by Jen.