diff --git a/src/BusinessCardManagement.java b/src/BusinessCardManagement.java index 24c217b..8d8ee08 100644 --- a/src/BusinessCardManagement.java +++ b/src/BusinessCardManagement.java @@ -33,6 +33,14 @@ return this.value.get(companyName); } public void updateFromState(String scId, String wid, int state, String company_, String company, String representative_, String representative, String position_, String position, String establishment_, String establishment, String address1_, String address1, String address2_, String address2, String businessdescription1_, String businessdescription1, String businessdescription2_, String businessdescription2, String companyoverview_, String companyoverview, String URL_, String URL) { + Map temp_if15; + if ((((state==0)&&!company_.equals(""))&&!(this.value.containsKey(company_)))) { + this.value.put(company_,new BusinessCardManagementElement(representative_, position_, establishment_, address1_, address2_, businessdescription1_, businessdescription2_, companyoverview_, URL_)); + temp_if15 = this.value; + } else { + temp_if15 = this.value; + } + this.value = temp_if15; String searchCriteriaScreen = this.searchCriteriaScreen.getValue(); String result = this.result.getValue(); this.widget = screenTemplates.getScreenTemplate(searchCriteriaScreen).getWidgets1().getWidget1(result); @@ -45,16 +53,16 @@ String searchScreen = this.searchScreen.getValue(); this.widget = screenTemplates.getScreenTemplate(searchScreen).getWidgets1().getWidget1(w4ca84254d30c423ab8e449171a5b5123); this.widget.updateDataFromBusinessCardManagement2(scId, wid, this.getValue(), w4ca84254d30c423ab8e449171a5b5123, searchScreen); - Map temp_if15; - if ((((state==0)&&!company_.equals(""))&&!(this.value.containsKey(company_)))) { - this.value.put(company_,new BusinessCardManagementElement(address2_, address1_, establishment_, position_, businessdescription1_, representative_, URL_, companyoverview_, businessdescription2_)); - temp_if15 = this.value; - } else { - temp_if15 = this.value; - } - this.value = temp_if15; } public void updateFromState2(String scId, String wid, int state, String company_, String representative_, String position_, String establishment_, String address1_, String address2_, String businessdescription1_, String businessdescription2_, String companyoverview_, String URL_) { + Map temp_if14; + if ((((state==0)&&!company_.equals(""))&&!(this.value.containsKey(company_)))) { + this.value.put(company_,new BusinessCardManagementElement(representative_, position_, establishment_, address1_, address2_, businessdescription1_, businessdescription2_, companyoverview_, URL_)); + temp_if14 = this.value; + } else { + temp_if14 = this.value; + } + this.value = temp_if14; String searchCriteriaScreen = this.searchCriteriaScreen.getValue(); String result = this.result.getValue(); this.widget = screenTemplates.getScreenTemplate(searchCriteriaScreen).getWidgets1().getWidget1(result); @@ -67,16 +75,16 @@ String searchScreen = this.searchScreen.getValue(); this.widget = screenTemplates.getScreenTemplate(searchScreen).getWidgets1().getWidget1(w4ca84254d30c423ab8e449171a5b5123); this.widget.updateDataFromBusinessCardManagement2(scId, wid, this.getValue(), w4ca84254d30c423ab8e449171a5b5123, searchScreen); - Map temp_if14; - if ((((state==0)&&!company_.equals(""))&&!(this.value.containsKey(company_)))) { - this.value.put(company_,new BusinessCardManagementElement(address2_, address1_, establishment_, position_, "", representative_, URL_, "", "")); - temp_if14 = this.value; - } else { - temp_if14 = this.value; - } - this.value = temp_if14; } public void updateFromState3(String scId, String wid, int state, String editcompany_, String editcompany, String editrepresentative_, String editrepresentative, String editposition_, String editposition, String editestablish_, String editestablish, String editaddress1_, String editaddress1, String editaddress2_, String editaddress2, String editbusiness1_, String editbusiness1, String editbusiness2_, String editbusiness2, String editcompanydetail_, String editcompanydetail, String editURL_, String editURL) { + Map temp_if16; + if ((((state==0)&&!editcompany_.equals(""))&&this.value.containsKey(editcompany_))) { + this.value.put(editcompany_,new BusinessCardManagementElement(editrepresentative_, editposition_, editestablish_, editaddress1_, editaddress2_, editbusiness1_, editbusiness2_, editcompanydetail_, editURL_)); + temp_if16 = this.value; + } else { + temp_if16 = this.value; + } + this.value = temp_if16; String searchCriteriaScreen = this.searchCriteriaScreen.getValue(); String result = this.result.getValue(); this.widget = screenTemplates.getScreenTemplate(searchCriteriaScreen).getWidgets1().getWidget1(result); @@ -89,16 +97,9 @@ String searchScreen = this.searchScreen.getValue(); this.widget = screenTemplates.getScreenTemplate(searchScreen).getWidgets1().getWidget1(w4ca84254d30c423ab8e449171a5b5123); this.widget.updateDataFromBusinessCardManagement2(scId, wid, this.getValue(), w4ca84254d30c423ab8e449171a5b5123, searchScreen); - Map temp_if16; - if ((((state==0)&&!editcompany_.equals(""))&&this.value.containsKey(editcompany_))) { - this.value.put(editcompany_,new BusinessCardManagementElement(editaddress2_, editaddress1_, editestablish_, editposition_, editbusiness1_, editrepresentative_, editURL_, editcompanydetail_, editbusiness2_)); - temp_if16 = this.value; - } else { - temp_if16 = this.value; - } - this.value = temp_if16; } public void addBusinessCardManagement(String scId, String wid, String representative, String position, String establishment, String address1, String address2, String businessDescription1, String businessDescription2, String companyOverview, String URL, String companyName) { + this.value.put(companyName,new BusinessCardManagementElement(representative, position, establishment, address1, address2, businessDescription1, businessDescription2, companyOverview, URL)); String searchCriteriaScreen = this.searchCriteriaScreen.getValue(); String result = this.result.getValue(); this.widget = screenTemplates.getScreenTemplate(searchCriteriaScreen).getWidgets1().getWidget1(result); @@ -111,6 +112,5 @@ String searchScreen = this.searchScreen.getValue(); this.widget = screenTemplates.getScreenTemplate(searchScreen).getWidgets1().getWidget1(w4ca84254d30c423ab8e449171a5b5123); this.widget.updateDataFromBusinessCardManagement2(scId, wid, this.getValue(), w4ca84254d30c423ab8e449171a5b5123, searchScreen); - this.value.put(companyName,new BusinessCardManagementElement(address2, address1, establishment, position, businessDescription1, representative, URL, companyOverview, businessDescription2)); } } \ No newline at end of file diff --git a/src/BusinessCardManagementElement.java b/src/BusinessCardManagementElement.java index 354b98a..f6f651f 100644 --- a/src/BusinessCardManagementElement.java +++ b/src/BusinessCardManagementElement.java @@ -2,25 +2,36 @@ public class BusinessCardManagementElement { private String representative; - private String URL; - private String address1; - private String companyOverview; + private String position; + private String establishment; + private String address1; private String address2; - private String position; private String businessDescription2; private String businessDescription1; - private String establishment; + private String companyOverview; + private String URL; + public BusinessCardManagementElement(String representative, String position, String establishment, String address1, String address2, String businessDescription1, String businessDescription2, String companyOverview, String URL) { + this.representative = representative; + this.position = position; + this.establishment = establishment; + this.address1 = address1; + this.address2 = address2; + this.businessDescription1 = businessDescription1; + this.businessDescription2 = businessDescription2; + this.companyOverview = companyOverview; + this.URL = URL; + } public Map getValue() { Map temp_nil0 = new HashMap<>(); - temp_nil0.put("address2",this.getAddress2()); - temp_nil0.put("businessDescription1",this.getBusinessDescription1()); - temp_nil0.put("companyOverview",this.getCompanyOverview()); - temp_nil0.put("establishment",this.getEstablishment()); - temp_nil0.put("businessDescription2",this.getBusinessDescription2()); + temp_nil0.put("代表者",this.getRepresentative()); + temp_nil0.put("役職",this.getPosition()); + temp_nil0.put("設立",this.getEstablishment()); + temp_nil0.put("住所1",this.getAddress1()); + temp_nil0.put("住所2",this.getAddress2()); + temp_nil0.put("事業内容1",this.getBusinessDescription1()); + temp_nil0.put("事業内容2",this.getBusinessDescription2()); + temp_nil0.put("会社概要",this.getCompanyOverview()); temp_nil0.put("URL",this.getURL()); - temp_nil0.put("address1",this.getAddress1()); - temp_nil0.put("position",this.getPosition()); - temp_nil0.put("representative",this.getRepresentative()); return temp_nil0; } public String getRepresentative() { @@ -29,63 +40,52 @@ public void changeRepresentativeOfBusinessCardManagement(String companyName, String newRepresentative) { this.representative = newRepresentative; } - public String getURL() { - return this.URL; - } - public void changeURLOfBusinessCardManagement(String companyName, String newURL) { - this.URL = newURL; - } + public String getPosition() { + return this.position; + } + public void changePositionOfBusinessCardManagement(String companyName, String newPosition) { + this.position = newPosition; + } + public String getEstablishment() { + return this.establishment; + } + public void changeEstablishmentOfBusinessCardManagement(String companyName, String newEstablishment) { + this.establishment = newEstablishment; + } public String getAddress1() { return this.address1; } public void changeAddress1OfBusinessCardManagement(String companyName, String newAddress1) { this.address1 = newAddress1; } - public String getCompanyOverview() { - return this.companyOverview; - } - public void changeCompanyOverviewOfBusinessCardManagement(String companyName, String newCompanyOverview) { - this.companyOverview = newCompanyOverview; - } public String getAddress2() { return this.address2; } public void changeAddress2OfBusinessCardManagement(String companyName, String newAddress2) { this.address2 = newAddress2; } - public String getPosition() { - return this.position; - } - public void changePositionOfBusinessCardManagement(String companyName, String newPosition) { - this.position = newPosition; - } + public String getBusinessDescription1() { + return this.businessDescription1; + } + public void changeBusinessDescription1OfBusinessCardManagement(String companyName, String newBusinessDescription1) { + this.businessDescription1 = newBusinessDescription1; + } public String getBusinessDescription2() { return this.businessDescription2; } public void changeBusinessDescription2OfBusinessCardManagement(String companyName, String newBusinessDescription2) { this.businessDescription2 = newBusinessDescription2; } - public String getBusinessDescription1() { - return this.businessDescription1; - } - public void changeBusinessDescription1OfBusinessCardManagement(String companyName, String newBusinessDescription1) { - this.businessDescription1 = newBusinessDescription1; - } - public String getEstablishment() { - return this.establishment; - } - public void changeEstablishmentOfBusinessCardManagement(String companyName, String newEstablishment) { - this.establishment = newEstablishment; - } - public BusinessCardManagementElement(String address2, String address1, String establishment, String position, String businessDescription1, String representative, String uRL, String companyOverview, String businessDescription2) { - this.address2 = address2; - this.address1 = address1; - this.establishment = establishment; - this.position = position; - this.businessDescription1 = businessDescription1; - this.representative = representative; - this.URL = uRL; - this.companyOverview = companyOverview; - this.businessDescription2 = businessDescription2; - } + public String getCompanyOverview() { + return this.companyOverview; + } + public void changeCompanyOverviewOfBusinessCardManagement(String companyName, String newCompanyOverview) { + this.companyOverview = newCompanyOverview; + } + public String getURL() { + return this.URL; + } + public void changeURLOfBusinessCardManagement(String companyName, String newURL) { + this.URL = newURL; + } } \ No newline at end of file diff --git a/src/CurScreen.java b/src/CurScreen.java index 5304da1..b898928 100644 --- a/src/CurScreen.java +++ b/src/CurScreen.java @@ -76,11 +76,11 @@ String temp_if9; if ((state==0)) { String temp_if8; - if ((!company.equals("")&&!(businessCardManagement.containsKey(company)))) { - temp_if8 = "企業一覧"; - } else { - temp_if8 = "企業一覧"; - } + if ((!company.equals("")&&!(businessCardManagement.containsKey(company)))) { + temp_if8 = "企業一覧"; + } else { + temp_if8 = "企業一覧"; + } temp_if9 = temp_if8; } else { temp_if9 = this.value; diff --git a/src/Screen.java b/src/Screen.java index 8c45171..e9312a5 100644 --- a/src/Screen.java +++ b/src/Screen.java @@ -42,6 +42,8 @@ } public void updateFromCurScreen(String curScreen, Map screenTemplate) { this.presenter.screenUpdate(getValue(), screenTemplate); - setValue(screenTemplate); + if (screenId == null || !screenId.equals(curScreen)) { + setValue(screenTemplate); + } } } \ No newline at end of file diff --git a/src/ScreenTemplates.java b/src/ScreenTemplates.java index 38a3b0e..a7535ae 100644 --- a/src/ScreenTemplates.java +++ b/src/ScreenTemplates.java @@ -6,31 +6,31 @@ private Map value = new HashMap<>(); { Map temp_json5 = new HashMap<>(); - temp_json5.put("representative", "_"); - temp_json5.put("担当者1", "_"); - temp_json5.put("position", "_"); - temp_json5.put("address2", "_"); - temp_json5.put("address1", "_"); - temp_json5.put("電話番号1", "_"); - temp_json5.put("establishment", "_"); - temp_json5.put("businessDescription1", "_"); - temp_json5.put("companyOverview", "_"); - temp_json5.put("URL", "_"); - temp_json5.put("businessDescription2", "_"); + temp_json5.put("代表者", "_"); + temp_json5.put("役職", "_"); + temp_json5.put("設立", "_"); + temp_json5.put("住所1", "_"); + temp_json5.put("住所2", "_"); + temp_json5.put("事業内容1", "_"); + temp_json5.put("事業内容2", "_"); + temp_json5.put("会社概要", "_"); + temp_json5.put("URL", "_"); + temp_json5.put("担当者1", "_"); + temp_json5.put("電話番号1", "_"); Map temp_json4 = new HashMap<>(); temp_json4.put("_", temp_json5); List temp_list1 = new ArrayList<>(); + temp_list1.add("代表者"); + temp_list1.add("役職"); + temp_list1.add("設立"); + temp_list1.add("住所1"); + temp_list1.add("住所2"); + temp_list1.add("事業内容1"); + temp_list1.add("事業内容2"); + temp_list1.add("会社概要"); + temp_list1.add("URL"); + temp_list1.add("担当者1"); temp_list1.add("電話番号1"); - temp_list1.add("担当者1"); - temp_list1.add("URL"); - temp_list1.add("会社概要"); - temp_list1.add("事業内容2"); - temp_list1.add("事業内容1"); - temp_list1.add("住所2"); - temp_list1.add("住所1"); - temp_list1.add("設立"); - temp_list1.add("役職"); - temp_list1.add("代表者"); Map temp_json3 = new HashMap<>(); temp_json3.put("type", "table"); temp_json3.put("text", ""); @@ -122,27 +122,27 @@ temp_json17.put("width", 70); temp_json17.put("height", 20); Map temp_json20 = new HashMap<>(); - temp_json20.put("address2", "_"); - temp_json20.put("address1", "_"); - temp_json20.put("establishment", "_"); - temp_json20.put("position", "_"); - temp_json20.put("businessDescription1", "_"); - temp_json20.put("representative", "_"); - temp_json20.put("companyOverview", "_"); + temp_json20.put("代表者", "_"); + temp_json20.put("役職", "_"); + temp_json20.put("設立", "_"); + temp_json20.put("住所1", "_"); + temp_json20.put("住所2", "_"); + temp_json20.put("事業内容1", "_"); + temp_json20.put("事業内容2", "_"); + temp_json20.put("会社概要", "_"); temp_json20.put("URL", "_"); - temp_json20.put("businessDescription2", "_"); Map temp_json19 = new HashMap<>(); temp_json19.put("_", temp_json20); List temp_list2 = new ArrayList<>(); + temp_list2.add("代表者"); + temp_list2.add("役職"); + temp_list2.add("設立"); + temp_list2.add("住所1"); + temp_list2.add("住所2"); + temp_list2.add("事業内容1"); + temp_list2.add("事業内容2"); + temp_list2.add("会社概要"); temp_list2.add("URL"); - temp_list2.add("会社概要"); - temp_list2.add("事業内容2"); - temp_list2.add("事業内容1"); - temp_list2.add("住所2"); - temp_list2.add("住所1"); - temp_list2.add("設立"); - temp_list2.add("役職"); - temp_list2.add("代表者"); Map temp_json18 = new HashMap<>(); temp_json18.put("type", "table"); temp_json18.put("text", "table"); @@ -501,27 +501,27 @@ temp_json61.put("width", 110); temp_json61.put("height", 55); Map temp_json64 = new HashMap<>(); - temp_json64.put("address2", "_"); - temp_json64.put("address1", "_"); - temp_json64.put("establishment", "_"); - temp_json64.put("position", "_"); - temp_json64.put("businessDescription1", "_"); - temp_json64.put("representative", "_"); - temp_json64.put("companyOverview", "_"); + temp_json64.put("代表者", "_"); + temp_json64.put("役職", "_"); + temp_json64.put("設立", "_"); + temp_json64.put("住所1", "_"); + temp_json64.put("住所2", "_"); + temp_json64.put("事業内容1", "_"); + temp_json64.put("事業内容2", "_"); + temp_json64.put("会社概要", "_"); temp_json64.put("URL", "_"); - temp_json64.put("businessDescription2", "_"); Map temp_json63 = new HashMap<>(); temp_json63.put("_", temp_json64); List temp_list3 = new ArrayList<>(); + temp_list3.add("代表者"); + temp_list3.add("役職"); + temp_list3.add("設立"); + temp_list3.add("住所1"); + temp_list3.add("住所2"); + temp_list3.add("事業内容1"); + temp_list3.add("事業内容2"); + temp_list3.add("会社概要"); temp_list3.add("URL"); - temp_list3.add("会社概要"); - temp_list3.add("事業内容2"); - temp_list3.add("事業内容1"); - temp_list3.add("住所2"); - temp_list3.add("住所1"); - temp_list3.add("設立"); - temp_list3.add("役職"); - temp_list3.add("代表者"); Map temp_json62 = new HashMap<>(); temp_json62.put("type", "table"); temp_json62.put("text", ""); diff --git a/src/SwingPresenter.java b/src/SwingPresenter.java index dc2ae25..dab6412 100644 --- a/src/SwingPresenter.java +++ b/src/SwingPresenter.java @@ -1,14 +1,23 @@ import javax.swing.*; -import java.awt.*; +import javax.swing.event.DocumentEvent; +import javax.swing.event.DocumentListener; +import javax.swing.table.DefaultTableModel; +import javax.swing.table.TableModel; +import javax.swing.text.BadLocationException; +import javax.swing.text.Document; +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 { private Main main; private JPanel mainPanel; private Map components = new HashMap<>(); + private String curScreenId; public SwingPresenter(Main main, JPanel mainPanel) { this.main = main; @@ -19,8 +28,8 @@ Map widgets = (Map) value.get("widgets"); boolean layout = (boolean) value.get("layout"); String prevScreenId = (String) prevValue.get("screenId"); - String screenId = (String) value.get("screenId"); - if (screenId.equals(prevScreenId)) { + curScreenId = (String) value.get("screenId"); + if (curScreenId.equals(prevScreenId)) { return; } mainPanel.removeAll(); @@ -35,23 +44,36 @@ JTextField textField = new JTextField(10); mainPanel.add(textField); components.put(key, textField); - textField.addMouseListener(new MouseListener() { + textField.getDocument().addDocumentListener(new DocumentListener() { @Override - public void mouseClicked(MouseEvent e) { + public void insertUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mousePressed(MouseEvent e) { - main.mouseEvent(key, 1); + public void removeUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mouseReleased(MouseEvent e) { - main.mouseEvent(key, 0); - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { + public void changedUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } }); } else if (type.equals("label")) { @@ -101,7 +123,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 { @@ -121,23 +194,36 @@ textField.setSize(width, height); mainPanel.add(textField); components.put(key, textField); - textField.addMouseListener(new MouseListener() { + textField.getDocument().addDocumentListener(new DocumentListener() { @Override - public void mouseClicked(MouseEvent e) { + public void insertUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } + } + @Override + public void removeUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } @Override - public void mousePressed(MouseEvent e) { - main.mouseEvent(key, 1); - } - @Override - public void mouseReleased(MouseEvent e) { - main.mouseEvent(key, 0); - } - @Override - public void mouseEntered(MouseEvent e) { - } - @Override - public void mouseExited(MouseEvent e) { + public void changedUpdate(DocumentEvent e) { + Document d = e.getDocument(); + try { + String text = d.getText(0, d.getLength()); + main.textEvent(key, text); + } catch (BadLocationException ex) { + throw new RuntimeException(ex); + } } }); } else if (type.equals("label")) { @@ -191,7 +277,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); } } } @@ -226,7 +365,22 @@ } public void setTable(String scId, String wid, Map> data) { - } + if (!curScreenId.equals(scId)) return; + if (!(components.get(wid) instanceof JTable)) return; + JTable table = (JTable) components.get(wid); + TableModel tableModel = table.getModel(); + int i = 0; + for(String dataKey : data.keySet()) { + Map rowData = data.get(dataKey); + int j = 0; + for(String cellvalue : rowData.keySet()) { + tableModel.setValueAt(rowData.get(cellvalue), i, j); + j++; + } + i++; + } + table.setModel(tableModel); + } public void setLayout(boolean layout) { if (layout) { 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) {