Newer
Older
StartupManagement / src / Widgets.java
import java.util.*;

public class Widgets {
	private Map<String, Widget> value = new HashMap<>();
	ScreenTemplates screenTemplates;
	CurScreen curScreen;
	SwingPresenter presenter;
	public Widgets(ScreenTemplates screenTemplates, SwingPresenter presenter) {
		this.screenTemplates = screenTemplates;
		this.presenter = presenter;
	}
	public Map<String, Widget> getValue() {
		return new HashMap<>(this.value);
	}
	public void setValue(Map<String, Object> value) {
		for (String key: value.keySet()) {
			String type = "";
			if (((Map<String, Object>) value.get(key)) != null) type = (String) ((Map<String, Object>) value.get(key)).get("type");
			String text = "";
			if (((Map<String, Object>) value.get(key)) != null) text = (String) ((Map<String, Object>) value.get(key)).get("text");
			boolean visible = true;
			if (((Map<String, Object>) value.get(key)) != null) visible = (boolean) ((Map<String, Object>) value.get(key)).get("visible");
			int x = 0;
			if (((Map<String, Object>) value.get(key)) != null) x = (int) ((Map<String, Object>) value.get(key)).get("x");
			int y = 0;
			if (((Map<String, Object>) value.get(key)) != null) y = (int) ((Map<String, Object>) value.get(key)).get("y");
			int width = 0;
			if (((Map<String, Object>) value.get(key)) != null) width = (int) ((Map<String, Object>) value.get(key)).get("width");
			int height = 0;
			if (((Map<String, Object>) value.get(key)) != null) height = (int) ((Map<String, Object>) value.get(key)).get("height");
			int state = 0;
			if (((Map<String, Object>) value.get(key)) != null) state = (int) ((Map<String, Object>) value.get(key)).get("state");
            Map<String, Map<String, Object>> data = null;
            if (((Map<String, Object>) value.get(key)) != null) data = (Map<String, Map<String, Object>>) ((Map<String, Object>) value.get(key)).get("data");
            List<String> columns = null;
            if (((Map<String, Object>) value.get(key)) != null) columns = (List<String>) ((Map<String, Object>) value.get(key)).get("columns");
            String primaryKeyName = null;
            if (((Map<String, Object>) value.get(key)) != null) primaryKeyName = (String) ((Map<String, Object>) value.get(key)).get("primaryKeyName");
            Widget widget = new Widget(type, text, visible, x, y, width, height, state, data, columns, primaryKeyName, screenTemplates, presenter);
            widget.setCurScreen(curScreen);
            this.value.put(key, widget);
		}
	}
	public Widget getWidget(String editbusiness2) {
		return this.value.get(editbusiness2);
	}
	public void addMovableButton(String wid, String text, int x, int y, int width, int height) {
		Widget widget = new Widget("button", text, true, x, y, width, height, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
	public void addMovableTextInput(String wid, int x, int y, int width, int height) {
		Widget widget = new Widget("textInput", "", true, x, y, width, height, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
	public void addMovableLabel(String wid, String text, int x, int y, int width, int height) {
		Widget widget = new Widget("label", text, true, x, y, width, height, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
    public void addMovableTable(String wid, String text, int x, int y, int width, int height, Map<String, Map<String, Object>> data, List<String> columns, String primaryKeyName) {
        Widget widget = new Widget("table", text, true, x, y, width, height, 0, data, columns, primaryKeyName, screenTemplates, presenter);
        widget.setCurScreen(curScreen);
        this.value.put(wid, widget);
    }
	public void addButton(String wid, String text) {
		Widget widget = new Widget("button", text, true, 0, 0, 0, 0, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
	public void addTextInput(String wid) {
		Widget widget = new Widget("textInput", "", true, 0, 0, 0, 0, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
	public void addLabel(String wid, String text) {
		Widget widget = new Widget("label", text, true, 0, 0, 0, 0, 0, null, null, null, screenTemplates, presenter);
		widget.setCurScreen(curScreen);
		this.value.put(wid, widget);
	}
    public void addTable(String wid, String text, Map<String, Map<String, Object>> data, List<String> columns, String primaryKeyName) {
        Widget widget = new Widget("table", text, true, 0, 0, 0, 0, 0, data, columns, primaryKeyName, screenTemplates, presenter);
        widget.setCurScreen(curScreen);
        this.value.put(wid, widget);
    }
	public void setCurScreen(CurScreen curScreen) {
		this.curScreen = curScreen;
		for (Widget widget: value.values()) {
			widget.setCurScreen(curScreen);
		}
	}
}