/*
* PanelRecomendation.java
*
* Created on 3 Март 2008 г., 16:29
*/
package clips.doctor.recommedation;
import clips.delegate.doctor.RecommendationLocal;
import cli_fmw.delegate.DelegateLine2;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PrintCreators;
import cli_fmw.main.PageContainer;
import cli_fmw.main.PageGeneric;
import cli_fmw.main.Persistentable;
import cli_fmw.main.Printable;
import cli_fmw.report.CombinedReportCreator;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.intelliwriter.IntelliWriter;
import cli_fmw.utils.table_config_states.StateSaver;
import java.awt.event.FocusEvent;
import java.awt.event.FocusListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Document;
/**
*Панель для отображения рекомендации
* @author lacoste
*/
public class PanelRecomendation extends PageGeneric implements Persistentable, Printable {
private RecommendationLocal recommedation;
private boolean canBeEdit;
/** Creates new form PanelRecomendation
* @param container
* @param rl
* @throws ClipsException
*/
public PanelRecomendation(PageContainer container, RecommendationLocal rl) throws ClipsException {
super(container);
initComponents();
this.canBeEdit = rl.getSerrenLocal().canReadMedicalData();
this.recommedation = rl;
taRegimen.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setRegimen(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
taFood.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setFood(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
taPhysical.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setPhysical(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
taImmune.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setImmune(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
taDispensary.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setDispensary(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
taExtracheckup.getDocument().addDocumentListener(new DocumentListener() {
@Override
public void insertUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void removeUpdate(DocumentEvent arg0) {
setField(arg0.getDocument());
}
@Override
public void changedUpdate(DocumentEvent arg0) {
}
private void setField(Document doc) {
try {
recommedation.setExtracheckup(doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
MessageBox.showException(ex);
} catch (ClipsException ex) {
MessageBox.showException(ex);
}
}
});
setScreenFields();
StateSaver.attachTo(this);
}
public void setScreenFields() throws ClipsException {
taRegimen.setText(recommedation.getRegimen());
taFood.setText(recommedation.getFood());
taPhysical.setText(recommedation.getPhysical());
taImmune.setText(recommedation.getImmune());
taDispensary.setText(recommedation.getDispensary());
taExtracheckup.setText(recommedation.getExtracheckup());
chooserDate.setDate(recommedation.getDate());
setEnableComponents();
}
private void setEnableComponents() {
chooserDate.setEnabled(false);
taRegimen.setEditable(canBeEdit);
taFood.setEditable(canBeEdit);
taPhysical.setEditable(canBeEdit);
taImmune.setEditable(canBeEdit);
taDispensary.setEditable(canBeEdit);
taExtracheckup.setEditable(canBeEdit);
}
/** 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.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel4 = new javax.swing.JPanel();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jPanel3 = new javax.swing.JPanel();
chooserDate = new org.infotechservice.ICalendar.components.ICDateChooser();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel2 = new javax.swing.JPanel();
jScrollPane2 = new javax.swing.JScrollPane();
taRegimen = new javax.swing.JTextArea();
jScrollPane3 = new javax.swing.JScrollPane();
taFood = new javax.swing.JTextArea();
jScrollPane4 = new javax.swing.JScrollPane();
taPhysical = new javax.swing.JTextArea();
jScrollPane5 = new javax.swing.JScrollPane();
taImmune = new javax.swing.JTextArea();
jScrollPane6 = new javax.swing.JScrollPane();
taDispensary = new javax.swing.JTextArea();
jScrollPane7 = new javax.swing.JScrollPane();
taExtracheckup = new javax.swing.JTextArea();
jPanel4.setLayout(new java.awt.BorderLayout(5, 5));
jPanel1.setLayout(new java.awt.BorderLayout(5, 5));
jLabel1.setText("Дата выписки:");
jPanel1.add(jLabel1, java.awt.BorderLayout.WEST);
jPanel3.setLayout(new java.awt.BorderLayout());
chooserDate.setEnabled(false);
jPanel3.add(chooserDate, java.awt.BorderLayout.WEST);
jPanel1.add(jPanel3, java.awt.BorderLayout.CENTER);
jPanel4.add(jPanel1, java.awt.BorderLayout.PAGE_START);
jPanel2.setLayout(new java.awt.GridLayout(0, 1, 0, 5));
jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder("Режим"));
taRegimen.setColumns(20);
taRegimen.setLineWrap(true);
taRegimen.setRows(4);
taRegimen.setWrapStyleWord(true);
jScrollPane2.setViewportView(taRegimen);
jPanel2.add(jScrollPane2);
jScrollPane3.setBorder(javax.swing.BorderFactory.createTitledBorder("Питание"));
taFood.setColumns(20);
taFood.setLineWrap(true);
taFood.setRows(4);
taFood.setWrapStyleWord(true);
jScrollPane3.setViewportView(taFood);
jPanel2.add(jScrollPane3);
jScrollPane4.setBorder(javax.swing.BorderFactory.createTitledBorder("Физические нагрузки"));
taPhysical.setColumns(20);
taPhysical.setLineWrap(true);
taPhysical.setRows(4);
taPhysical.setWrapStyleWord(true);
jScrollPane4.setViewportView(taPhysical);
jPanel2.add(jScrollPane4);
jScrollPane5.setBorder(javax.swing.BorderFactory.createTitledBorder("Рекомендации по иммунопрофилактике"));
taImmune.setColumns(20);
taImmune.setLineWrap(true);
taImmune.setRows(4);
taImmune.setWrapStyleWord(true);
jScrollPane5.setViewportView(taImmune);
jPanel2.add(jScrollPane5);
jScrollPane6.setBorder(javax.swing.BorderFactory.createTitledBorder("Рекомендации по диспансерному наблюдению"));
taDispensary.setColumns(20);
taDispensary.setLineWrap(true);
taDispensary.setRows(4);
taDispensary.setWrapStyleWord(true);
jScrollPane6.setViewportView(taDispensary);
jPanel2.add(jScrollPane6);
jScrollPane7.setBorder(javax.swing.BorderFactory.createTitledBorder("Рекомендации по дополнительному обследованию"));
taExtracheckup.setColumns(20);
taExtracheckup.setLineWrap(true);
taExtracheckup.setRows(4);
taExtracheckup.setWrapStyleWord(true);
jScrollPane7.setViewportView(taExtracheckup);
jPanel2.add(jScrollPane7);
jScrollPane1.setViewportView(jPanel2);
jPanel4.add(jScrollPane1, java.awt.BorderLayout.CENTER);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 551, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, 671, Short.MAX_VALUE)
.addContainerGap())
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private org.infotechservice.ICalendar.components.ICDateChooser chooserDate;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JPanel jPanel3;
private javax.swing.JPanel jPanel4;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JScrollPane jScrollPane5;
private javax.swing.JScrollPane jScrollPane6;
private javax.swing.JScrollPane jScrollPane7;
private javax.swing.JTextArea taDispensary;
private javax.swing.JTextArea taExtracheckup;
private javax.swing.JTextArea taFood;
private javax.swing.JTextArea taImmune;
private javax.swing.JTextArea taPhysical;
private javax.swing.JTextArea taRegimen;
// End of variables declaration//GEN-END:variables
@Override
public String getPageTitle() {
return "Рекомендация";
}
@Override
public boolean isDirty() {
return recommedation == null ? false : recommedation.isDirty();
}
@Override
public void save() throws ClipsException {
recommedation.save1();
}
@Override
public void restore() {
try {
if (recommedation.isNewlyCreated()) {
getContainer().removePage(this, true);
} else {
recommedation.restore();
setScreenFields();
}
} catch (Exception ex) {
MessageBox.showException(ex);
}
}
@Override
public boolean readyForPrint() {
return !isDirty();
}
@Override
public void print() {
try {
if (readyForPrint()) {
CombinedReportCreator parCreator = PrintCreators.createCombinedReportHeader(getClass());
recommedation.print(parCreator);
parCreator.finish();
}
} catch (ClipsException ex) {
MessageBox.showExceptionOnly(ex);
}
}
@Override
public DelegateLine2 getDelegate() {
return recommedation;
}
}
class IntelliWriterFocusListener implements FocusListener {
IntelliWriter intelliWriter;
public IntelliWriterFocusListener(IntelliWriter intelliWriter) {
this.intelliWriter = intelliWriter;
}
@Override
public void focusGained(FocusEvent e) {
//do nothing
}
@Override
public void focusLost(FocusEvent e) {
intelliWriter.hideMenu();
}
}