OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 112 | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 112 Rev 150
Line 1... Line 1...
1
package org.openconcerto.modules.operation;
1
package org.openconcerto.modules.operation;
2
 
2
 
3
import java.awt.BorderLayout;
3
import java.awt.BorderLayout;
4
import java.awt.Dimension;
-
 
5
import java.awt.FlowLayout;
4
import java.awt.FlowLayout;
6
import java.awt.GridBagConstraints;
-
 
7
import java.awt.GridBagLayout;
-
 
8
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionEvent;
9
import java.awt.event.ActionListener;
6
import java.awt.event.ActionListener;
10
import java.awt.event.ItemEvent;
7
import java.util.Date;
11
import java.awt.event.ItemListener;
-
 
12
import java.beans.PropertyChangeEvent;
-
 
13
import java.beans.PropertyChangeListener;
-
 
14
import java.util.List;
8
import java.util.List;
15
 
9
 
16
import javax.swing.JButton;
10
import javax.swing.JButton;
17
import javax.swing.JCheckBox;
11
import javax.swing.JCheckBox;
18
import javax.swing.JLabel;
-
 
19
import javax.swing.JPanel;
12
import javax.swing.JPanel;
20
import javax.swing.JScrollPane;
-
 
21
 
13
 
22
import org.jopencalendar.model.JCalendarItemPart;
-
 
23
import org.jopencalendar.ui.ItemPartHoverListener;
-
 
24
import org.jopencalendar.ui.MultipleDayView;
14
import org.jopencalendar.ui.MultipleDayView;
25
import org.openconcerto.erp.config.ComptaPropsConfiguration;
15
import org.openconcerto.erp.config.ComptaPropsConfiguration;
26
import org.openconcerto.sql.element.SQLElement;
16
import org.openconcerto.sql.element.SQLElement;
27
import org.openconcerto.sql.model.SQLRowAccessor;
17
import org.openconcerto.sql.model.SQLRowAccessor;
28
import org.openconcerto.sql.model.SQLTableEvent;
18
import org.openconcerto.sql.model.SQLTableEvent;
29
import org.openconcerto.sql.model.SQLTableModifiedListener;
19
import org.openconcerto.sql.model.SQLTableModifiedListener;
30
import org.openconcerto.sql.users.User;
20
import org.openconcerto.sql.users.User;
31
import org.openconcerto.sql.view.EditFrame;
21
import org.openconcerto.sql.view.EditFrame;
32
import org.openconcerto.sql.view.EditPanel.EditMode;
22
import org.openconcerto.sql.view.EditPanel.EditMode;
33
import org.openconcerto.ui.DefaultGridBagConstraints;
-
 
34
import org.openconcerto.ui.FrameUtil;
23
import org.openconcerto.ui.FrameUtil;
35
 
24
 
36
/**
25
/**
37
 * Planning d'un jour, pour chaque personne
26
 * Planning d'un jour, pour chaque personne
38
 */
27
 */
Line 40... Line 29...
40
 
29
 
41
    private MultipleDayCalendarWithToolBar calendar;
30
    private MultipleDayCalendarWithToolBar calendar;
42
 
31
 
43
    private OperationDayView mDayView;
32
    private OperationDayView mDayView;
44
 
33
 
45
    public DailyOperationCalendarPanel() {
34
    public DailyOperationCalendarPanel(final ComptaPropsConfiguration conf) {
46
 
-
 
47
        this.setLayout(new BorderLayout());
35
        this.setLayout(new BorderLayout());
48
        JPanel toolbar = new JPanel();
36
        JPanel toolbar = new JPanel();
49
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
37
        toolbar.setLayout(new FlowLayout(FlowLayout.LEFT));
50
        toolbar.setOpaque(false);
38
        toolbar.setOpaque(false);
51
 
39
 
52
        //
40
        //
53
        final JButton bCreate = new JButton("Ajouter une intervention");
41
        final JButton bCreate = new JButton("Ajouter une intervention");
54
        bCreate.setOpaque(false);
42
        bCreate.setOpaque(false);
55
        toolbar.add(bCreate);
43
        toolbar.add(bCreate);
56
        //
44
        //
57
        final JButton bPlan = new JButton("Plannifier des interventions");
45
        final JButton bPlan = new JButton("Planifier des interventions");
58
        bPlan.setOpaque(false);
46
        bPlan.setOpaque(false);
59
        toolbar.add(bPlan);
47
        toolbar.add(bPlan);
60
        //
48
        //
61
        this.add(toolbar, BorderLayout.NORTH);
49
        this.add(toolbar, BorderLayout.NORTH);
62
 
50
 
63
        final JPanel filters = createFilterPanel();
-
 
64
        split.setLeftComponent(filters);
-
 
65
        mDayView = new OperationDayView();
51
        mDayView = new OperationDayView();
66
        calendar = new MultipleDayCalendarWithToolBar(mDayView);
52
        calendar = new MultipleDayCalendarWithToolBar(mDayView);
67
        final MultipleDayView w = calendar.getWeekView();
53
        final MultipleDayView w = calendar.getWeekView();
68
        w.setHourRange(HOUR_START, HOUR_STOP);
-
 
69
        w.addItemPartHoverListener(new ItemPartHoverListener() {
-
 
70
 
54
 
71
            @Override
-
 
72
            public void mouseOn(JCalendarItemPart newSelection) {
-
 
73
                if (newSelection == null) {
-
 
74
                    final int location = split.getDividerLocation();
55
        final JPanel filters = createFilterPanel(conf, w);
75
                    split.setLeftComponent(filters);
56
        split.setLeftComponent(filters);
76
                    split.setDividerLocation(location);
-
 
77
                } else {
-
 
78
 
-
 
79
                    final int location = split.getDividerLocation();
-
 
80
                    final JCalendarItemInfoPanel comp = new JCalendarItemInfoPanel(newSelection.getItem());
-
 
81
                    split.setLeftComponent(comp);
57
        w.setHourRange(HOUR_START, HOUR_STOP);
82
                    split.setDividerLocation(location);
-
 
83
                }
-
 
84
 
-
 
85
            }
-
 
86
        });
-
 
87
 
58
 
88
        split.setRightComponent(calendar);
59
        split.setRightComponent(calendar);
89
        split.setDividerLocation(250);
60
        split.setDividerLocation(250);
90
        this.add(split, BorderLayout.CENTER);
61
        this.add(split, BorderLayout.CENTER);
91
        ComptaPropsConfiguration.getInstanceCompta().getRootSociete().getTable("CALENDAR_ITEM").addTableModifiedListener(new SQLTableModifiedListener() {
62
        conf.getRootSociete().getTable("CALENDAR_ITEM").addTableModifiedListener(new SQLTableModifiedListener() {
92
 
63
 
93
            @Override
64
            @Override
94
            public void tableModified(SQLTableEvent evt) {
65
            public void tableModified(SQLTableEvent evt) {
95
                calendar.reload();
66
                calendar.reload();
96
            }
67
            }
97
 
68
 
98
        });
69
        });
99
 
70
 
100
        final SQLElement element = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElement(ModuleOperation.TABLE_OPERATION);
71
        final SQLElement element = conf.getDirectory().getElement(ModuleOperation.TABLE_OPERATION);
101
        // Create a new operation
72
        // Create a new operation
102
        bCreate.addActionListener(new ActionListener() {
73
        bCreate.addActionListener(new ActionListener() {
103
 
74
 
104
            @Override
75
            @Override
105
            public void actionPerformed(ActionEvent e) {
76
            public void actionPerformed(ActionEvent e) {
Line 120... Line 91...
120
 
91
 
121
            @Override
92
            @Override
122
            public void actionPerformed(ActionEvent e) {
93
            public void actionPerformed(ActionEvent e) {
123
                final MultiOperationSQLComponent comp = new MultiOperationSQLComponent(element);
94
                final MultiOperationSQLComponent comp = new MultiOperationSQLComponent(element);
124
                final EditFrame f = new EditFrame(comp, EditMode.CREATION);
95
                final EditFrame f = new EditFrame(comp, EditMode.CREATION);
125
                f.setTitle("Plannication d'interventions");
96
                f.setTitle("Planification d'interventions");
126
                FrameUtil.show(f);
97
                FrameUtil.show(f);
127
            }
98
            }
128
        });
99
        });
129
        calendar.scrollTo(8);
100
        calendar.scrollTo(8);
130
        registerCalendarItemListener(calendar.getWeekView());
-
 
131
 
101
 
132
        calendar.getWeekView().setPopupMenuProvider(new OperationMenuProvider());
102
        w.setPopupMenuProvider(new OperationMenuProvider());
-
 
103
        this.beginStateSaving(conf.getConfDir(), w);
133
    }
104
    }
134
 
105
 
135
    public void reload() {
106
    public void reload() {
136
        this.mDayView.reload();
107
        this.mDayView.reload();
137
    }
108
    }
138
 
109
 
139
    protected JPanel createFilterPanel() {
-
 
140
 
-
 
141
        final JPanel p = new JPanel();
-
 
142
        p.setLayout(new GridBagLayout());
-
 
143
        final GridBagConstraints c = new DefaultGridBagConstraints();
-
 
144
        c.fill = GridBagConstraints.BOTH;
-
 
145
        c.weightx = 1;
-
 
146
        p.add(new JLabel("Etats"), c);
-
 
147
        c.gridy++;
110
    @Override
148
        c.weighty = 1;
-
 
149
        final OperationStateListModel statesModel = new OperationStateListModel();
-
 
150
        statesList = new CheckList<String>(statesModel);
-
 
151
        p.add(new JScrollPane(statesList), c);
-
 
152
        c.gridy++;
-
 
153
        c.weighty = 0;
-
 
154
        p.add(new JLabel("Employés"), c);
-
 
155
        c.gridy++;
-
 
156
        c.weighty = 1;
-
 
157
        usersModel = new UserOperationListModel(this);
-
 
158
        usesrList = new CheckList<User>(usersModel);
-
 
159
        p.add(new JScrollPane(usesrList), c);
-
 
160
        c.gridy++;
-
 
161
        c.weighty = 0;
-
 
162
        final JCheckBox check1 = new JCheckBox("masquer les verrouillés");
111
    protected void setFilter(final JCheckBox check1, final JCheckBox check2, List<User> users, List<String> states) {
163
        p.add(check1, c);
-
 
164
        c.gridy++;
-
 
165
        final JCheckBox check2 = new JCheckBox("masquer les déverrouillés");
-
 
166
        p.add(check2, c);
-
 
167
        statesModel.loadContent();
-
 
168
        usersModel.loadContent();
-
 
169
 
-
 
170
        p.setMinimumSize(new Dimension(200, 200));
-
 
171
        p.setPreferredSize(new Dimension(200, 200));
-
 
172
 
-
 
173
        final PropertyChangeListener listener = new PropertyChangeListener() {
-
 
174
 
-
 
175
            @Override
-
 
176
            public void propertyChange(PropertyChangeEvent evt) {
-
 
177
                List<User> users = null;
-
 
178
                if (!usesrList.isAllSelected()) {
-
 
179
                    users = getSelectedUsers();
-
 
180
                }
-
 
181
                List<String> states = null;
-
 
182
                if (!statesList.isAllSelected()) {
-
 
183
                    states = getSelectedStates();
-
 
184
                }
-
 
185
                mDayView.setFilter(users, states, check1.isSelected(), check2.isSelected());
112
        mDayView.setFilter(users, states, check1.isSelected(), check2.isSelected());
186
                calendar.reload();
-
 
187
 
-
 
188
            }
113
    }
189
        };
114
 
190
        statesList.addPropertyChangeListener("checked", listener);
-
 
191
        usesrList.addPropertyChangeListener("checked", listener);
-
 
192
        check1.addItemListener(new ItemListener() {
-
 
193
            public void itemStateChanged(ItemEvent e) {
-
 
194
                listener.propertyChange(null);
-
 
195
            }
115
    @Override
196
        });
-
 
197
        check2.addItemListener(new ItemListener() {
116
    protected Date getViewDate() {
198
            public void itemStateChanged(ItemEvent e) {
-
 
199
                listener.propertyChange(null);
117
        return this.calendar.getDate();
200
            }
118
    }
-
 
119
 
201
        });
120
    @Override
-
 
121
    protected void setViewDate(Date d) {
202
        return p;
122
        this.calendar.setDate(d);
203
    }
123
    }
204
}
124
}