All Downloads are FREE. Search and download functionalities are using the official Maven repository.

convex.gui.components.DefaultReceiveAction Maven / Gradle / Ivy

There is a newer version: 0.7.15
Show newest version
package convex.gui.components;

import java.util.function.Consumer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.JComponent;

import convex.core.Result;
import convex.core.lang.RT;
import convex.core.util.Utils;

public class DefaultReceiveAction implements Consumer {

	public static final Logger log = LoggerFactory.getLogger(DefaultReceiveAction.class.getName());

	private JComponent parent;

	public DefaultReceiveAction(JComponent parent) {
		this.parent = parent;
	}
	
	@Override
	public void accept(Result t) {
		if (t.isError()) {
			handleError(RT.jvm(t.getID()),t.getErrorCode(),t.getValue());
		} else {
			handleResult(t.getValue());
		}
	}

	protected void handleResult(Object m) {
		showResult(m);
	}

	protected void handleError(long id, Object code, Object msg) {
		showError(code,msg);
	}

	private void showError(Object code, Object msg) {
		String resultString = "Error executing transaction: " + code + " "+msg; 
		log.info(resultString);
		Toast.display(parent, resultString, Toast.FAIL);
	}

	private void showResult(Object v) {
		String resultString = "Transaction executed successfully\n" + "Result: " + Utils.toString(v);
		log.info(resultString);
		Toast.display(parent, resultString, Toast.SUCCESS);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy