package brn.gui.actions;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.util.IPropertyChangeListener;
import org.eclipse.jface.util.PropertyChangeEvent;

import brn.gui.commands.ICommandIds;
import brn.gui.datasource.Provider;

public class RunSimAction extends Action implements IPropertyChangeListener {
	private final static String IMAGE = "/icons/run.gif";

	private Provider provider;

	public RunSimAction(String label, Provider provider) {
		super();
		this.provider = provider;

		setText(label);
		// The id is used to refer to the action in a menu or toolbar
		setId(ICommandIds.CMD_RUN_SIM);
		// Associate the action with a pre-defined command, to allow key bindings.
		setActionDefinitionId(ICommandIds.CMD_RUN_SIM);
		setImageDescriptor(brn.gui.Activator.getImageDescriptor(IMAGE));

    setEnabled(null != provider.getDataSource()
        &&provider.getDataSource().isRunPossible());
    provider.addPropertyChangeListener(this);
	}

  @Override
	public void run() {
    provider.getDataSource().runSim();
	}

	public void propertyChange(PropertyChangeEvent event) {
    setEnabled(null != provider.getDataSource()
        &&provider.getDataSource().isRunPossible());
	}

}
