OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 156 | Rev 177 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 156 Rev 174
Line 46... Line 46...
46
import org.openconcerto.sql.model.SQLTable;
46
import org.openconcerto.sql.model.SQLTable;
47
import org.openconcerto.sql.model.Where;
47
import org.openconcerto.sql.model.Where;
48
import org.openconcerto.sql.model.graph.Path;
48
import org.openconcerto.sql.model.graph.Path;
49
import org.openconcerto.sql.preferences.SQLPreferences;
49
import org.openconcerto.sql.preferences.SQLPreferences;
50
import org.openconcerto.sql.request.ListSQLRequest;
50
import org.openconcerto.sql.request.ListSQLRequest;
-
 
51
import org.openconcerto.sql.ui.light.CustomRowEditor;
51
import org.openconcerto.sql.users.UserManager;
52
import org.openconcerto.sql.users.UserManager;
52
import org.openconcerto.sql.users.rights.UserRightsManager;
53
import org.openconcerto.sql.users.rights.UserRightsManager;
53
import org.openconcerto.sql.view.EditFrame;
54
import org.openconcerto.sql.view.EditFrame;
54
import org.openconcerto.sql.view.EditPanel;
55
import org.openconcerto.sql.view.EditPanel;
55
import org.openconcerto.sql.view.EditPanel.EditMode;
56
import org.openconcerto.sql.view.EditPanel.EditMode;
Line 61... Line 62...
61
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
62
import org.openconcerto.sql.view.list.RowAction.PredicateRowAction;
62
import org.openconcerto.sql.view.list.SQLTableModelSource;
63
import org.openconcerto.sql.view.list.SQLTableModelSource;
63
import org.openconcerto.ui.light.ActivationOnSelectionControler;
64
import org.openconcerto.ui.light.ActivationOnSelectionControler;
64
import org.openconcerto.ui.light.ColumnSpec;
65
import org.openconcerto.ui.light.ColumnSpec;
65
import org.openconcerto.ui.light.ColumnsSpec;
66
import org.openconcerto.ui.light.ColumnsSpec;
66
import org.openconcerto.ui.light.CustomEditorProvider;
-
 
67
import org.openconcerto.ui.light.LightController;
67
import org.openconcerto.ui.light.LightController;
68
import org.openconcerto.ui.light.LightUIButtonUnmanaged;
68
import org.openconcerto.ui.light.LightUIButtonUnmanaged;
69
import org.openconcerto.ui.light.LightUIComboBox;
69
import org.openconcerto.ui.light.LightUIComboBox;
70
import org.openconcerto.ui.light.LightUIElement;
70
import org.openconcerto.ui.light.LightUIElement;
71
import org.openconcerto.ui.light.LightUILine;
71
import org.openconcerto.ui.light.LightUILine;
Line 97... Line 97...
97
import java.util.Calendar;
97
import java.util.Calendar;
98
import java.util.Collections;
98
import java.util.Collections;
99
import java.util.Date;
99
import java.util.Date;
100
import java.util.HashSet;
100
import java.util.HashSet;
101
import java.util.List;
101
import java.util.List;
102
import java.util.Map;
-
 
103
import java.util.Set;
102
import java.util.Set;
104
 
103
 
105
import javax.swing.AbstractAction;
104
import javax.swing.AbstractAction;
106
import javax.swing.ImageIcon;
105
import javax.swing.ImageIcon;
107
import javax.swing.JFrame;
106
import javax.swing.JFrame;
Line 765... Line 764...
765
        editFactureFrame.setState(JFrame.NORMAL);
764
        editFactureFrame.setState(JFrame.NORMAL);
766
        editFactureFrame.setVisible(true);
765
        editFactureFrame.setVisible(true);
767
    }
766
    }
768
 
767
 
769
    @Override
768
    @Override
770
    protected Map<String, CustomEditorProvider> _getDefaultCustomEditorProvider(final Configuration configuration, final SQLRowAccessor sqlRow, final String sessionSecurityToken)
769
    public List<CustomRowEditor> getCustomRowEditors(Configuration configuration, String sessionToken) {
771
            throws IllegalArgumentException {
-
 
772
        final Map<String, CustomEditorProvider> map = super._getDefaultCustomEditorProvider(configuration, sqlRow, sessionSecurityToken);
770
        List<CustomRowEditor> map = super.getCustomRowEditors(configuration, sessionToken);
773
        map.put("sales.quote.items.list", new CustomEditorProvider() {
771
        map.add(new CustomRowEditor("sales.quote.items.list") {
774
 
772
 
775
            @Override
773
            @Override
776
            public LightUIElement createUIElement(final String id) {
774
            public LightUIElement createUIElement() {
777
 
-
 
778
                final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style"));
775
                final ColumnSpec c1 = new ColumnSpec("sales.quote.item.style", StringWithId.class, "Style", new StringWithId(2, "Normal"), true, new LightUIComboBox("sales.quote.item.style"));
779
                final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code"));
776
                final ColumnSpec c2 = new ColumnSpec("sales.quote.item.code", String.class, "Code", "", true, new LightUITextField("sales.quote.item.code"));
780
                final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name"));
777
                final ColumnSpec c3 = new ColumnSpec("sales.quote.item.label", String.class, "Nom", "", true, new LightUITextField("sales.quote.item.name"));
781
                final ColumnSpec c4 = new ColumnSpec("sales.quote.item.description", String.class, "Descriptif", "", true, new LightUITextField("sales.quote.item.description"));
778
                final ColumnSpec c4 = new ColumnSpec("sales.quote.item.description", String.class, "Descriptif", "", true, new LightUITextField("sales.quote.item.description"));
782
                final ColumnSpec c5 = new ColumnSpec("sales.quote.item.purchase.unit.price", BigDecimal.class, "P.U. Achat HT", new BigDecimal(0), true,
779
                final ColumnSpec c5 = new ColumnSpec("sales.quote.item.purchase.unit.price", BigDecimal.class, "P.U. Achat HT", new BigDecimal(0), true,
Line 862... Line 859...
862
                    }
859
                    }
863
                }
860
                }
864
                final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null);
861
                final ColumnsSpec cSpec = new ColumnsSpec(lId, columnsSpec, possibleColumnIds, null);
865
                cSpec.setAllowMove(true);
862
                cSpec.setAllowMove(true);
866
                cSpec.setAllowResize(true);
863
                cSpec.setAllowResize(true);
867
                final RowSelectionSpec selectionSpec = new RowSelectionSpec(id);
864
                final RowSelectionSpec selectionSpec = new RowSelectionSpec(getItemId());
868
                final TableSpec tSpec = new TableSpec(id, selectionSpec, cSpec);
865
                final TableSpec tSpec = new TableSpec(getItemId(), selectionSpec, cSpec);
869
                tSpec.setColumns(cSpec);
866
                tSpec.setColumns(cSpec);
870
 
867
 
871
                if (sqlRow != null) {
-
 
872
                    // send: id,value
-
 
873
                    final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT");
-
 
874
                    final SQLTable table = elem.getTable();
-
 
875
                    final List<String> fieldsToFetch = new ArrayList<>();
-
 
876
                    for (ColumnSpec cs : columnsSpec) {
-
 
877
                        String colId = cs.getId();
868
                String id = getItemId();
878
                        SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
-
 
879
                        if (f != null) {
-
 
880
                            fieldsToFetch.add(f.getName());
-
 
881
                        } else {
-
 
882
                            throw new IllegalStateException("No field in " + table + " for column id " + colId);
-
 
883
                        }
-
 
884
                    }
-
 
885
 
-
 
886
                    final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID());
-
 
887
                    final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs());
-
 
888
                    List<SQLRowValues> fetchedRows = req.getValues();
-
 
889
 
-
 
890
                    List<Row> rows = new ArrayList<>();
-
 
891
                    for (final SQLRowValues vals : fetchedRows) {
-
 
892
                        Row r = new Row(vals.getID(), columnsSpec.size());
-
 
893
                        List<Object> values = new ArrayList<>();
-
 
894
                        for (ColumnSpec cs : columnsSpec) {
-
 
895
                            String colId = cs.getId();
-
 
896
                            SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
-
 
897
                            if (f != null) {
-
 
898
                                Object object = vals.getObject(f.getName());
-
 
899
                                if (object instanceof SQLRowValues) {
-
 
900
                                    SQLRowValues sqlRowValues = (SQLRowValues) object;
-
 
901
                                    long rowId = sqlRowValues.getIDNumber().longValue();
-
 
902
                                    List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable());
-
 
903
                                    final StringBuilder b = new StringBuilder();
-
 
904
                                    for (SQLField sqlField : fieldsToExpand) {
-
 
905
                                        b.append(sqlRowValues.getObject(sqlField.getName()).toString());
-
 
906
                                        b.append(' ');
-
 
907
                                    }
-
 
908
                                    object = new StringWithId(rowId, b.toString().trim());
-
 
909
                                }
-
 
910
                                values.add(object);
-
 
911
                            } else {
-
 
912
                                throw new IllegalStateException("No field in " + table + " for column id " + colId);
-
 
913
                            }
-
 
914
                        }
-
 
915
                        r.setValues(values);
-
 
916
                        rows.add(r);
-
 
917
                    }
-
 
918
 
-
 
919
                    TableContent tableContent = new TableContent();
-
 
920
                    tableContent.setRows(rows);
-
 
921
                    // tableContent.setSpec(new RowSpec());
-
 
922
                    tSpec.setContent(tableContent);
-
 
923
 
-
 
924
                }
-
 
925
 
-
 
926
                final LightUITable eList = new LightUITable(id);
869
                final LightUITable eList = new LightUITable(id);
927
                eList.setTableSpec(tSpec);
870
                eList.setTableSpec(tSpec);
928
 
871
 
929
                LightUIPanel panel = new LightUIPanel("sales.quote.items.list");
872
                LightUIPanel panel = new LightUIPanel("sales.quote.items.list");
930
                panel.setGridWidth(1);
873
                panel.setGridWidth(1);
Line 972... Line 915...
972
 
915
 
973
                //
916
                //
974
                panel.addChild(listLine);
917
                panel.addChild(listLine);
975
 
918
 
976
                return panel;
919
                return panel;
-
 
920
 
-
 
921
            }
-
 
922
 
-
 
923
            @Override
-
 
924
            public void fillFrom(LightUIElement uiElement, SQLRowAccessor sqlRow) {
-
 
925
                LightUIPanel p = (LightUIPanel) uiElement;
-
 
926
                LightUITable ltable = p.getFirstChild(LightUITable.class);
-
 
927
                TableSpec tSpec = ltable.getTableSpec();
-
 
928
                ColumnsSpec columnsSpec = tSpec.getColumns();
-
 
929
                // send: id,value
-
 
930
                final SQLElement elem = configuration.getDirectory().getElement("DEVIS_ELEMENT");
-
 
931
                final SQLTable table = elem.getTable();
-
 
932
                final List<String> fieldsToFetch = new ArrayList<>();
-
 
933
                for (ColumnSpec cs : columnsSpec.getColumns()) {
-
 
934
                    String colId = cs.getId();
-
 
935
                    SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
-
 
936
                    if (f != null) {
-
 
937
                        fieldsToFetch.add(f.getName());
-
 
938
                    } else {
-
 
939
                        throw new IllegalStateException("No field in " + table + " for column id " + colId);
-
 
940
                    }
-
 
941
                }
-
 
942
 
-
 
943
                final Where where = new Where(table.getField("ID_DEVIS"), "=", sqlRow.getID());
-
 
944
                final ListSQLRequest req = elem.createListRequest(fieldsToFetch, where, configuration.getShowAs());
-
 
945
                List<SQLRowValues> fetchedRows = req.getValues();
-
 
946
 
-
 
947
                List<Row> rows = new ArrayList<>();
-
 
948
                for (final SQLRowValues vals : fetchedRows) {
-
 
949
                    Row r = new Row(vals.getID(), columnsSpec.getColumns().size());
-
 
950
                    List<Object> values = new ArrayList<>();
-
 
951
                    for (ColumnSpec cs : columnsSpec.getColumns()) {
-
 
952
                        String colId = cs.getId();
-
 
953
                        SQLField f = configuration.getFieldMapper().getSQLFieldForItem(colId);
-
 
954
                        if (f != null) {
-
 
955
                            Object object = vals.getObject(f.getName());
-
 
956
                            if (object instanceof SQLRowValues) {
-
 
957
                                SQLRowValues sqlRowValues = (SQLRowValues) object;
-
 
958
                                long rowId = sqlRowValues.getIDNumber().longValue();
-
 
959
                                List<SQLField> fieldsToExpand = configuration.getShowAs().getFieldExpand(sqlRowValues.getTable());
-
 
960
                                final StringBuilder b = new StringBuilder();
-
 
961
                                for (SQLField sqlField : fieldsToExpand) {
-
 
962
                                    b.append(sqlRowValues.getObject(sqlField.getName()).toString());
-
 
963
                                    b.append(' ');
-
 
964
                                }
-
 
965
                                object = new StringWithId(rowId, b.toString().trim());
-
 
966
                            }
-
 
967
                            values.add(object);
-
 
968
                        } else {
-
 
969
                            throw new IllegalStateException("No field in " + table + " for column id " + colId);
-
 
970
                        }
-
 
971
                    }
-
 
972
                    r.setValues(values);
-
 
973
                    rows.add(r);
-
 
974
                }
-
 
975
 
-
 
976
                TableContent tableContent = new TableContent();
-
 
977
                tableContent.setRows(rows);
-
 
978
                tSpec.setContent(tableContent);
-
 
979
 
-
 
980
            }
-
 
981
 
-
 
982
            @Override
-
 
983
            public void store(LightUIElement uiElement, SQLRowValues row) {
-
 
984
                // TODO Auto-generated method stub
-
 
985
 
977
            }
986
            }
978
 
987
 
979
        });
988
        });
980
        return map;
989
        return map;
981
    }
990
    }