/*
* Copyright (C) 2014 GG-Net GmbH - Oliver Günther
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package eu.ggnet.dwoss.redtape;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.Set;
import javax.swing.JOptionPane;
import eu.ggnet.dwoss.redtape.entity.Document;
import eu.ggnet.dwoss.redtape.entity.Document.Settlement;
import eu.ggnet.dwoss.util.CloseType;
import eu.ggnet.dwoss.util.IPreClose;
import eu.ggnet.dwoss.util.OkCancelDialog;
/**
* A UI to set the {@link Document#settlements} to a {@link Document}.
* @author pascal.perau
*/
public class SettlementViewCask extends javax.swing.JPanel implements IPreClose{
private Set<Settlement> settlements = new HashSet<>();
/** Creates new form SettlementViewCask */
public SettlementViewCask() {
initComponents();
cashButton.setText(Settlement.CASH.getName());
eCashButton.setText(Settlement.E_CASH.getName());
remittanceButton.setText(Settlement.REMITTANCE.getName());
splitButton.setText("Zahlung Splitten");
cashButton.setActionCommand(Settlement.CASH.getName());
eCashButton.setActionCommand(Settlement.E_CASH.getName());
remittanceButton.setActionCommand(Settlement.REMITTANCE.getName());
}
public Set<Settlement> getSettlements() {
return settlements;
}
@Override
public boolean pre(CloseType type) {
if(type == CloseType.OK && settlements.isEmpty()){
JOptionPane.showMessageDialog(this, "Mindestens eine Zahlungsart muss hinterlegt sein.");
return false;
}
return true;
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
buttonGroup1 = new javax.swing.ButtonGroup();
cashButton = new javax.swing.JRadioButton();
eCashButton = new javax.swing.JRadioButton();
remittanceButton = new javax.swing.JRadioButton();
splitButton = new javax.swing.JRadioButton();
buttonGroup1.add(cashButton);
cashButton.setText("jRadioButton1");
cashButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
settlementChangedAction(evt);
}
});
buttonGroup1.add(eCashButton);
eCashButton.setText("jRadioButton2");
eCashButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
settlementChangedAction(evt);
}
});
buttonGroup1.add(remittanceButton);
remittanceButton.setText("jRadioButton3");
remittanceButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
settlementChangedAction(evt);
}
});
buttonGroup1.add(splitButton);
splitButton.setText("jRadioButton4");
splitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
splitAction(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(cashButton)
.addComponent(eCashButton)
.addComponent(remittanceButton)
.addComponent(splitButton))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(cashButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(eCashButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(remittanceButton)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(splitButton)
.addContainerGap(14, Short.MAX_VALUE))
);
}// </editor-fold>//GEN-END:initComponents
private void settlementChangedAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_settlementChangedAction
settlements.clear();
for (Settlement settlement : Document.Settlement.values()) {
if(evt.getActionCommand().equals(settlement.getName()))settlements.add(settlement);
}
}//GEN-LAST:event_settlementChangedAction
private void splitAction(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_splitAction
settlements.clear();
settlements.addAll(EnumSet.of(Settlement.CASH, Settlement.E_CASH));
}//GEN-LAST:event_splitAction
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.ButtonGroup buttonGroup1;
private javax.swing.JRadioButton cashButton;
private javax.swing.JRadioButton eCashButton;
private javax.swing.JRadioButton remittanceButton;
private javax.swing.JRadioButton splitButton;
// End of variables declaration//GEN-END:variables
public static void main(String[] args) {
SettlementViewCask view = new SettlementViewCask();
OkCancelDialog<SettlementViewCask> dialog = new OkCancelDialog<>("Blub", view);
dialog.setVisible(true);
System.out.println(view.getSettlements());
}
}