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

convex.gui.models.OracleTableModel Maven / Gradle / Ivy

The newest version!
package convex.gui.models;

import javax.swing.table.TableModel;

import convex.core.State;
import convex.core.data.ACell;
import convex.core.data.AMap;
import convex.core.data.AccountStatus;
import convex.core.data.Address;
import convex.core.data.Keyword;
import convex.core.data.MapEntry;
import convex.core.data.Symbol;
import convex.core.util.Utils;

/**
 * Model for the Oracle table
 */
@SuppressWarnings("serial")
public class OracleTableModel extends BaseTableModel implements TableModel {

	private State state;
	private Address oracle;
	
	Symbol LIST_S=Symbol.create("*list*");
	Symbol RESULTS_S=Symbol.create("*results*");
	
	Keyword DESC_K=Keyword.create("desc");

	public OracleTableModel(State state, Address oracle) {
		this.state = state;
		this.oracle=oracle;
	}
	
	private static final String[] FIXED_COLS=new String[] {
			"Key","Description", "Finalised?","Value"
	};

	public String getColumnName(int col) {
		if (col list=as.getEnvironmentValue(LIST_S); 
		if (list==null) {
			System.err.println("OracleTableModel missing oracle list? in "+oracle);
			return 0;
		}
		return Utils.checkedInt(list.count());
	}

	@Override
	public int getColumnCount() {
		return FIXED_COLS.length;
	}

	@Override
	public boolean isCellEditable(int row, int col) {
		return false;
	}
	
	@SuppressWarnings("unchecked")
	public AMap getList() {
		AMap env=state.getAccount(oracle).getEnvironment();
		AMap list=(AMap) env.get(LIST_S); 
		return list;
	}

	@SuppressWarnings("unchecked")
	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		AMap env=state.getAccount(oracle).getEnvironment();
		AMap list=(AMap) env.get(LIST_S); 
		MapEntry me=list.entryAt(rowIndex);
		ACell key=me.getKey();
		switch (columnIndex) {
			case 0: return key.toString();
			case 1: {
				AMap data=(AMap) me.getValue();
				return data.get(DESC_K);
			}
			case 2: {
				boolean done=((AMap) env.get(RESULTS_S)).containsKey(key);
				return done?"Yes":"No";
			}
			case 3: {
				AMap results=((AMap) env.get(RESULTS_S));
				MapEntry rme=results.getEntry(key);
				return (rme==null)?"":rme.getValue();
			}
			
			default: return "";
		}
	}

	public void setState(State newState) {
		if (state!=newState) {
			state=newState;
			fireTableDataChanged();
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy