diff --git a/src/SwingPresenter.java b/src/SwingPresenter.java index dc2ae25..3ff70ef 100644 --- a/src/SwingPresenter.java +++ b/src/SwingPresenter.java @@ -1,8 +1,11 @@ import javax.swing.*; -import java.awt.*; +import javax.swing.table.DefaultTableModel; +import java.awt.Component; +import java.awt.FlowLayout; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.util.HashMap; +import java.util.List; import java.util.Map; public class SwingPresenter { @@ -101,7 +104,58 @@ } }); } else if (type.equals("table")) { - + Map> data = (Map>) ((Map) widgets.get(key)).get("data"); + List columns = (List) ((Map) widgets.get(key)).get("columns"); + String primaryKeyName = (String) ((Map) widgets.get(key)).get("primaryKeyName"); + boolean primaryKeyVisible = !primaryKeyName.equals(""); + int colNum = columns.size() + (primaryKeyVisible ? 1 : 0); + String[] columnsData = new String[colNum]; + String[][] tableData = new String[data.keySet().size()][colNum]; + if(primaryKeyVisible) { + columnsData[0] = primaryKeyName; + for(int i = 1; i < colNum; i++) { + columnsData[i] = columns.get(i - 1); + } + } else { + for(int i = 0; i < colNum; i++) { + columnsData[i] = columns.get(i); + } + } + int rowCount = 0; + for(String dataKey : data.keySet()) { + Map rowData = data.get(dataKey); + if(primaryKeyVisible) { + tableData[rowCount][0] = dataKey; + for(int j = 1; j < columnsData.length; j++) { + Object cellValue = rowData.get(columnsData[j]); + if(cellValue == null) { + tableData[rowCount][j] = "error"; + } else { + tableData[rowCount][j] = rowData.get(columnsData[j]).toString(); + } + } + } else { + for(int j = 0; j < columnsData.length; j++) { + Object cellValue = rowData.get(columnsData[j]); + if(cellValue == null) { + tableData[rowCount][j] = "error"; + } else { + tableData[rowCount][j] = rowData.get(columnsData[j]).toString(); + } + } + } + rowCount++; + } + DefaultTableModel tableModel = new DefaultTableModel(tableData, columnsData); + JTable table = new JTable(tableModel) { + @Override + public boolean isCellEditable(int row, int col) { + return false; + } + }; + JScrollPane scroll = new JScrollPane(table); + mainPanel.add(scroll); + components.put(key, scroll); } } } else { @@ -191,7 +245,60 @@ } }); } else if (type.equals("table")) { - + Map> data = (Map>) ((Map) widgets.get(key)).get("data"); + List columns = (List) ((Map) widgets.get(key)).get("columns"); + String primaryKeyName = (String) ((Map) widgets.get(key)).get("primaryKeyName"); + boolean primaryKeyVisible = !primaryKeyName.equals(""); + int colNum = columns.size() + (primaryKeyVisible ? 1 : 0); + String[] columnsData = new String[colNum]; + String[][] tableData = new String[data.keySet().size()][colNum]; + if(primaryKeyVisible) { + columnsData[0] = primaryKeyName; + for(int i = 1; i < colNum; i++) { + columnsData[i] = columns.get(i - 1); + } + } else { + for(int i = 0; i < colNum; i++) { + columnsData[i] = columns.get(i); + } + } + int rowCount = 0; + for(String dataKey : data.keySet()) { + Map rowData = data.get(dataKey); + if(primaryKeyVisible) { + tableData[rowCount][0] = dataKey; + for(int j = 1; j < columnsData.length; j++) { + Object cellValue = rowData.get(columnsData[j]); + if(cellValue == null) { + tableData[rowCount][j] = "error"; + } else { + tableData[rowCount][j] = rowData.get(columnsData[j]).toString(); + } + } + } else { + for(int j = 0; j < columnsData.length; j++) { + Object cellValue = rowData.get(columnsData[j]); + if(cellValue == null) { + tableData[rowCount][j] = "error"; + } else { + tableData[rowCount][j] = rowData.get(columnsData[j]).toString(); + } + } + } + rowCount++; + } + DefaultTableModel tableModel = new DefaultTableModel(tableData, columnsData); + JTable table = new JTable(tableModel) { + @Override + public boolean isCellEditable(int row, int col) { + return false; + } + }; + JScrollPane scroll = new JScrollPane(table); + scroll.setLocation(x, y); + scroll.setSize(width, height); + mainPanel.add(scroll); + components.put(key, scroll); } } } diff --git a/src/Widget.java b/src/Widget.java index 52eb97f..fd160d5 100644 --- a/src/Widget.java +++ b/src/Widget.java @@ -16,19 +16,21 @@ private CurScreen curScreen; private ScreenTemplates screenTemplates; private SwingPresenter presenter; - public Widget(String type, String text, boolean visible, int x, int y, int width, int height, int state, Map> data, ScreenTemplates screenTemplates, SwingPresenter presenter) { - this.type = type; - this.text = text; - this.visible = visible; - this.x = x; - this.y = y; - this.width = width; - this.height = height; - this.state = state; - this.data = data; - this.screenTemplates = screenTemplates; - this.presenter = presenter; - } + public Widget(String type, String text, boolean visible, int x, int y, int width, int height, int state, Map> data, List columns, String primaryKeyName, ScreenTemplates screenTemplates, SwingPresenter presenter) { + this.type = type; + this.text = text; + this.visible = visible; + this.x = x; + this.y = y; + this.width = width; + this.height = height; + this.state = state; + this.data = data; + this.columns = columns; + this.primaryKeyName = primaryKeyName; + this.screenTemplates = screenTemplates; + this.presenter = presenter; + } public Map getValue() { Map temp_nil3 = new HashMap<>(); temp_nil3.put("type",this.getType()); @@ -39,7 +41,11 @@ temp_nil3.put("width",this.getWidth()); temp_nil3.put("height",this.getHeight()); temp_nil3.put("state",this.getState()); - temp_nil3.put("data",this.getData()); + if (this.getType().equals("table")) { + temp_nil3.put("data",this.getData()); + temp_nil3.put("columns",this.getColumns()); + temp_nil3.put("primaryKeyName",this.getPrimaryKeyName()); + } return temp_nil3; } public String getType() { @@ -69,6 +75,12 @@ public Map> getData() { return this.data; } + public List getColumns() { + return this.columns; + } + public String getPrimaryKeyName() { + return this.primaryKeyName; + } public void changeX(String wid, int x) { this.x = x; this.presenter.setX(wid, x); diff --git a/src/Widget1.java b/src/Widget1.java index 7ddd1a4..c78f2eb 100644 --- a/src/Widget1.java +++ b/src/Widget1.java @@ -45,7 +45,7 @@ private Search6 search6; private Result result; - public Widget1(String type, String text, boolean visible, int x, int y, int width, int height, int state, Map> data, SwingPresenter presenter) { + public Widget1(String type, String text, boolean visible, int x, int y, int width, int height, int state, Map> data, List columns, String primaryKeyName, SwingPresenter presenter) { this.type = type; this.text = text; this.visible = visible; @@ -55,6 +55,8 @@ this.height = height; this.state = state; this.data = data; + this.columns = columns; + this.primaryKeyName = primaryKeyName; this.presenter = presenter; } public Map getValue() { @@ -67,7 +69,11 @@ temp_nil2.put("width",this.getWidth()); temp_nil2.put("height",this.getHeight()); temp_nil2.put("state",this.getState()); - temp_nil2.put("data",this.getData()); + if (this.getType().equals("table")) { + temp_nil2.put("data", this.getData()); + temp_nil2.put("columns", this.getColumns()); + temp_nil2.put("primaryKeyName", this.getPrimaryKeyName()); + } return temp_nil2; } public String getType() { @@ -94,6 +100,15 @@ public int getState() { return this.state; } + public Map> getData() { + return this.data; + } + public List getColumns() { + return this.columns; + } + public String getPrimaryKeyName() { + return primaryKeyName; + } public void updateTextFromText(String self, String self2, String wid, String text, String curScreen) { this.text = text; } @@ -109,9 +124,6 @@ this.data = businessCardManagement; this.presenter.setTable(scId, wid, businessCardManagement); } - public Map> getData() { - return this.data; - } public void updateStateFromState(String self, String self2, String wid, int state, String curScreen) { this.state = state; if ((curScreen.equals("検索画面")&&wid.equals("w7de33900c55f4379983056aee325c057"))) { diff --git a/src/Widgets.java b/src/Widgets.java index 499c825..e78c8e7 100644 --- a/src/Widgets.java +++ b/src/Widgets.java @@ -30,44 +30,60 @@ if (((Map) value.get(key)) != null) height = (int) ((Map) value.get(key)).get("height"); int state = 0; if (((Map) value.get(key)) != null) state = (int) ((Map) value.get(key)).get("state"); - Widget widget = new Widget(type, text, visible, x, y, width, height, state, null, screenTemplates, presenter); - widget.setCurScreen(curScreen); - this.value.put(key, widget); + Map> data = null; + if (((Map) value.get(key)) != null) data = (Map>) ((Map) value.get(key)).get("data"); + List columns = null; + if (((Map) value.get(key)) != null) columns = (List) ((Map) value.get(key)).get("columns"); + String primaryKeyName = null; + if (((Map) value.get(key)) != null) primaryKeyName = (String) ((Map) 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 text, int x, int y, int width, int height, String wid) { - Widget widget = new Widget("button", text, true, x, y, width, height, 0, null, screenTemplates, presenter); + 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(int x, int y, int width, int height, String wid) { - Widget widget = new Widget("textInput", "", true, x, y, width, height, 0, null, screenTemplates, presenter); + 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 text, int x, int y, int width, int height, String wid) { - Widget widget = new Widget("label", text, true, x, y, width, height, 0, null, screenTemplates, presenter); + 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 addButton(String text, String wid) { - Widget widget = new Widget("button", text, true, 0, 0, 0, 0, 0, null, screenTemplates, presenter); + public void addMovableTable(String wid, String text, int x, int y, int width, int height, Map> data, List 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, screenTemplates, presenter); + 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 text, String wid) { - Widget widget = new Widget("label", text, true, 0, 0, 0, 0, 0, null, screenTemplates, presenter); + 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> data, List 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()) { diff --git a/src/Widgets1.java b/src/Widgets1.java index 451c3f9..b22232d 100644 --- a/src/Widgets1.java +++ b/src/Widgets1.java @@ -30,7 +30,13 @@ if (((Map) value.get(key)).get("width") != null) width = (int) ((Map) value.get(key)).get("width"); int state = 0; if (((Map) value.get(key)).get("state") != null) state = (int) ((Map) value.get(key)).get("state"); - this.value.put(key, new Widget1(type, text, visible, x, y, width, height, 0, null, presenter)); + Map> data = null; + if (((Map) value.get(key)).get("data") != null) data = (Map>) ((Map) value.get(key)).get("data"); + List columns = null; + if (((Map) value.get(key)).get("columns") != null) columns = (List) ((Map) value.get(key)).get("columns"); + String primaryKeyName = null; + if (((Map) value.get(key)).get("primaryKeyName") != null) primaryKeyName = (String) ((Map) value.get(key)).get("primaryKeyName"); + this.value.put(key, new Widget1(type, text, visible, x, y, width, height, 0, data, columns, primaryKeyName, presenter)); } } public Widget1 getWidget1(String wid) {