/*
* DolgozoForm.java
*
* Created on 2009. okt�ber 28., 10:46
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package swing.dolgozo;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.EventObject;
import java.util.Vector;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import swing.button.Button;
import swing.form.Form;
import swing.form.FormUtil;
import swing.panel.TextFieldPanel;
import system.dolgozo.Dolgozo;
import system.dolgozo.DolgozoUtil;
import system.util.LogUtil;
import system.util.Login;
/**
*
* @author laci
*/
public class DolgozoForm extends Form{
// <editor-fold defaultstate="collapsed" desc="konstruktor">
/** Creates a new instance of DolgozoForm */
public DolgozoForm(Login login) {
super(login);
initialize();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Inicializalas">
// TODO: getFocusOrder hasznalata a fokusz beallitasara
public void initialize() {
setContentTitle(getFormResource("DolgozoForm.ContentTitle"));
initialize(getFormResource("DolgozoForm.Name"), getFormResource("DolgozoForm.Title"), getMainFrame(), true, null);
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="valid">
public boolean valid() {
return getDolgozoNevPanel().getText() != null;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="enabler">
/** Formon levo mezok tiltasara, engedelyezesere szolgal. */
@Override
protected void enabler(EventObject e) {
boolean tkod = getTkod() != null;
getModositButton().setEnabled(tkod);
getFelveszButton().setEnabled(!tkod && valid());
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="RUN">
public boolean run() {
getCancelButton().addActionListener(getDeactiveListener());
return activate();
}
// TODO listenereket csin�lni a kil�p�shez ... ha deactive akkor deactivot h�v ha exit akkor system.exit-et
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="Objektum">
public void setTkod(Integer tkod) {
if (tkod == null) {
setValue(null);
} else {
setValue(DolgozoUtil.getByTkod(getLogin(), tkod));
}
fill();
}
public Integer getTkod() {
if (getValue() != null) {
return ((Dolgozo)getValue()).getTkod();
}
return null;
}
public Dolgozo getDolgozo() {
return (Dolgozo)getValue();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="reszet">
public void reset() {
setTkod(null);
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="kitolt">
public void fill() {
fillTkodPanel();
fillDolgozoNev();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="getFocusOrder">
public Vector getFocusOrder() {
return new Vector();
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="LoginNev">
private TextFieldPanel dolgozoNev;
public TextFieldPanel getDolgozoNevPanel() {
if (dolgozoNev == null) {
dolgozoNev = createDolgozoNevPanel();
}
return dolgozoNev;
}
protected TextFieldPanel createDolgozoNevPanel() {
TextFieldPanel temp = new TextFieldPanel(getLogin(),getFormResource("DolgozoForm.DolgozoNevCimke"));
temp.addDocumentListener(getDocListener());
return temp;
}
protected String getDolgozoNev() {
return getDolgozoNevPanel().getText();
}
protected void fillDolgozoNev() {
if (getTkod() != null) {
getDolgozoNevPanel().setText(getDolgozo().getNev());
} else {
getDolgozoNevPanel().setText(null);
}
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="modositGomb">
private Button modositButton;
protected Button getModositButton() {
if (modositButton == null) {
modositButton = createModositButton();
}
return modositButton;
}
protected Button createModositButton() {
Button temp = new Button(getFormResource("Button.Modosit"));
temp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
DolgozoUtil.update(getLogin(), getDolgozo(), getDolgozoNev());
fill();
} catch (Exception ex) {
LogUtil.log("Felv�tel nem siker�lt.",this.getClass() , ex, LogUtil.FATAL);
}
}
});
return temp;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="modositGomb">
private Button felveszButton;
protected Button getFelveszButton() {
if (felveszButton == null) {
felveszButton = createFelveszButton();
}
return felveszButton;
}
protected Button createFelveszButton() {
Button temp = new Button(getFormResource("Button.Felvesz"));
temp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
Dolgozo d = DolgozoUtil.insert(getLogin(), getDolgozoNev());
setTkod(d.getTkod());
} catch (Exception ex) {
LogUtil.log("M�dos�t�s nem siker�lt.",this.getClass() , ex, LogUtil.FATAL);
}
}
});
return temp;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="torolGomb">
private Button torolButton;
protected Button getTorolButton() {
if (torolButton == null) {
torolButton = createTorolButton();
}
return torolButton;
}
protected Button createTorolButton() {
Button temp = new Button(getFormResource("Button.Torol"));
temp.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
DolgozoUtil.delete(getLogin(), getDolgozo());
reset();
} catch (Exception ex) {
LogUtil.log("T�rl�s nem siker�lt.",this.getClass() , ex, LogUtil.FATAL);
}
}
});
return temp;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="createMainFrame">
@Override
protected JScrollPane createMainFrame() {
JScrollPane temp = super.createMainFrame();
JPanel foPanel = new JPanel(new GridBagLayout());
JPanel gombPanel = new JPanel(new FlowLayout());
getContent().add(getContentTitle(),FormUtil.newGBConstraints(0, 0, 1, 1, FormUtil.ANCHOR_CENTER, FormUtil.FILL_NONE, null));
getContent().add(getTkodPanel(),FormUtil.newGBConstraints(1, 0, 1, 1, FormUtil.ANCHOR_CENTER, FormUtil.FILL_NONE, null));
getContent().add(foPanel,FormUtil.newGBConstraints(0, 1, 2, 1, FormUtil.ANCHOR_CENTER, FormUtil.FILL_NONE, null));
foPanel.add(getDolgozoNevPanel(),FormUtil.newGBConstraints(0, 0, 1, 1, FormUtil.ANCHOR_CENTER, FormUtil.FILL_NONE, null));
getContent().add(gombPanel,FormUtil.newGBConstraints(0, 2, 2, 1, FormUtil.ANCHOR_CENTER, FormUtil.FILL_NONE, null));
gombPanel.add(getFelveszButton());
gombPanel.add(getModositButton());
gombPanel.add(getTorolButton());
gombPanel.add(getOkButton());
gombPanel.add(getCancelButton());
gombPanel.add(getResetButton());
return temp;
}
// </editor-fold>
// <editor-fold defaultstate="collapsed" desc="TESZT">
public static void main(String[] args) {
DolgozoForm form = new DolgozoForm(new Login());
System.out.println(form.run());
}
// </editor-fold>
}