OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 21 Rev 25
Line 33... Line 33...
33
import javax.swing.JButton;
33
import javax.swing.JButton;
34
import javax.swing.JOptionPane;
34
import javax.swing.JOptionPane;
35
import javax.swing.JPanel;
35
import javax.swing.JPanel;
36
import javax.swing.JSeparator;
36
import javax.swing.JSeparator;
37
import javax.swing.SwingConstants;
37
import javax.swing.SwingConstants;
-
 
38
import javax.swing.UIManager;
38
 
39
 
39
/**
40
/**
40
 * A default ElementSQLObject that displays a button to create, and when created a button to delete
41
 * A default ElementSQLObject that displays a button to create, and when created a button to delete
41
 * and a button to hide/expand.
42
 * and a button to hide/expand.
42
 * 
43
 * 
Line 59... Line 60...
59
 
60
 
60
    public DefaultElementSQLObject(SQLComponent parent, SQLComponent comp) {
61
    public DefaultElementSQLObject(SQLComponent parent, SQLComponent comp) {
61
        super(parent, comp);
62
        super(parent, comp);
62
 
63
 
63
        this.addValidListener(new ValidListener() {
64
        this.addValidListener(new ValidListener() {
-
 
65
            @Override
64
            public void validChange(ValidObject src, ValidState newValue) {
66
            public void validChange(ValidObject src, ValidState newValue) {
65
                compChanged();
67
                compChanged();
66
            }
68
            }
67
        });
69
        });
68
    }
70
    }
69
 
71
 
70
    public void showSeparator(boolean visible) {
72
    public void showSeparator(boolean visible) {
71
        this.isSeparatorVisible = visible;
73
        this.isSeparatorVisible = visible;
72
        if (separator != null)
74
        if (this.separator != null)
73
            this.separator.setVisible(visible);
75
            this.separator.setVisible(visible);
74
    }
76
    }
75
 
77
 
76
    public void setDecorated(boolean decorated) {
78
    public void setDecorated(boolean decorated) {
77
        this.isDecorated = decorated;
79
        this.isDecorated = decorated;
78
        if (expandBtn != null)
80
        if (this.expandBtn != null)
79
            this.expandBtn.setVisible(decorated);
81
            this.expandBtn.setVisible(decorated);
80
        if (supprBtn != null)
82
        if (this.supprBtn != null)
81
            this.supprBtn.setVisible(decorated);
83
            this.supprBtn.setVisible(decorated);
82
        if (createBtn != null)
84
        if (this.createBtn != null)
83
            this.createBtn.setVisible(decorated);
85
            this.createBtn.setVisible(decorated);
84
    }
86
    }
85
 
87
 
-
 
88
    @Override
86
    protected void uiInit() {
89
    protected void uiInit() {
-
 
90
        final boolean isPlastic = UIManager.getLookAndFeel().getClass().getName().startsWith("com.jgoodies.plaf.plastic");
-
 
91
 
87
        this.expandBtn = new JButton("+/-");
92
        this.expandBtn = new JButton("+/-");
88
        this.expandBtn.setEnabled(false);
93
        this.expandBtn.setEnabled(false);
-
 
94
        this.expandBtn.setOpaque(false);
89
        this.expandBtn.addActionListener(new ActionListener() {
95
        this.expandBtn.addActionListener(new ActionListener() {
-
 
96
            @Override
90
            public void actionPerformed(ActionEvent e) {
97
            public void actionPerformed(ActionEvent e) {
91
                toggleExpand();
98
                toggleExpand();
92
            }
99
            }
93
        });
100
        });
94
 
101
 
95
        this.supprBtn = new JButton(new ImageIcon(this.getClass().getResource("delete.png")));
102
        this.supprBtn = new JButton(new ImageIcon(this.getClass().getResource("delete.png")));
96
        this.supprBtn.setToolTipText("Supprimer");
103
        this.supprBtn.setToolTipText("Supprimer");
97
        this.supprBtn.setOpaque(false);
104
        this.supprBtn.setOpaque(false);
-
 
105
        if (isPlastic)
98
        this.supprBtn.setBorder(null);
106
            this.supprBtn.setBorder(null);
99
        this.supprBtn.addActionListener(new ActionListener() {
107
        this.supprBtn.addActionListener(new ActionListener() {
-
 
108
            @Override
100
            public void actionPerformed(ActionEvent e) {
109
            public void actionPerformed(ActionEvent e) {
101
                if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 || this.confirm())
110
                if ((e.getModifiers() & ActionEvent.SHIFT_MASK) != 0 || this.confirm())
102
                    setCreated(false);
111
                    setCreated(false);
103
            }
112
            }
104
 
113
 
105
            private boolean confirm() {
114
            private boolean confirm() {
106
                return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(DefaultElementSQLObject.this, "Voulez-vous vraiment supprimer cet élément ?", "Suppression", JOptionPane.YES_NO_OPTION);
115
                return JOptionPane.YES_OPTION == JOptionPane.showConfirmDialog(DefaultElementSQLObject.this, "Voulez-vous vraiment supprimer cet élément ?", "Suppression", JOptionPane.YES_NO_OPTION);
107
            }
116
            }
108
        });
117
        });
109
        this.createBtn = new JButton("Créer " + this.getSQLChild().getElement().getSingularName());
118
        this.createBtn = new JButton("Créer " + this.getSQLChild().getElement().getSingularName());
-
 
119
        // false leaves only a line for the button under Plastic3DLookAndFeel
-
 
120
        this.createBtn.setOpaque(isPlastic);
110
        this.createBtn.addActionListener(new ActionListener() {
121
        this.createBtn.addActionListener(new ActionListener() {
-
 
122
            @Override
111
            public void actionPerformed(ActionEvent e) {
123
            public void actionPerformed(ActionEvent e) {
112
                setCreated(true);
124
                setCreated(true);
113
            }
125
            }
114
        });
126
        });
115
 
127
 
116
        this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
128
        this.setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
117
    }
129
    }
118
 
130
 
-
 
131
    @Override
119
    protected final void setCreatePanel() {
132
    protected final void setCreatePanel() {
120
        if (this.editP != null)
133
        if (this.editP != null)
121
            this.editP.setVisible(false);
134
            this.editP.setVisible(false);
122
        this.getCreatePanel().setVisible(true);
135
        this.getCreatePanel().setVisible(true);
123
        // don't call setCurrentID() otherwise, when updating we won't know
136
        // don't call setCurrentID() otherwise, when updating we won't know
Line 136... Line 149...
136
            this.add(this.createP);
149
            this.add(this.createP);
137
        }
150
        }
138
        return this.createP;
151
        return this.createP;
139
    }
152
    }
140
 
153
 
-
 
154
    @Override
141
    protected final void setEditPanel() {
155
    protected final void setEditPanel() {
142
        this.supprBtn.setVisible(!this.required && this.isDecorated);
156
        this.supprBtn.setVisible(!this.required && this.isDecorated);
143
        if (this.createP != null)
157
        if (this.createP != null)
144
            this.createP.setVisible(false);
158
            this.createP.setVisible(false);
145
        this.getEditPanel().setVisible(true);
159
        this.getEditPanel().setVisible(true);
Line 193... Line 207...
193
            this.add(this.editP);
207
            this.add(this.editP);
194
        }
208
        }
195
        return this.editP;
209
        return this.editP;
196
    }
210
    }
197
 
211
 
-
 
212
    @Override
198
    protected void compChanged() {
213
    protected void compChanged() {
199
        this.expandBtn.setEnabled(this.getCurrentID() != SQLRow.NONEXISTANT_ID && this.getValidState().isValid());
214
        this.expandBtn.setEnabled(this.getCurrentID() != SQLRow.NONEXISTANT_ID && this.getValidState().isValid());
200
    }
215
    }
201
 
216
 
202
    private final boolean isExpanded() {
217
    private final boolean isExpanded() {
Line 217... Line 232...
217
 
232
 
218
    private void toggleExpand() {
233
    private void toggleExpand() {
219
        this.expand(!this.isExpanded());
234
        this.expand(!this.isExpanded());
220
    }
235
    }
221
 
236
 
-
 
237
    @Override
222
    public void setEditable(boolean enabled) {
238
    public void setEditable(boolean enabled) {
223
        super.setEditable(enabled);
239
        super.setEditable(enabled);
224
        this.createBtn.setEnabled(enabled);
240
        this.createBtn.setEnabled(enabled);
225
        this.supprBtn.setEnabled(enabled);
241
        this.supprBtn.setEnabled(enabled);
226
    }
242
    }