Package clips.report.panels

Source Code of clips.report.panels.DiseaseLinesPanel

/*
* DiseaseReportPanel.java
*
* Created on August 19, 2008, 4:20 PM
*/

package clips.report.panels;

import beans.directory.mkb10.MKBCode;
import beans.directory.mkb10.MKBParser;
import beans.report.selectors.disease.DiseaseTable;
import beans.report.SelectorIndefiner;
import beans.report.selectors.baseSelectors.BaseReportLine.ChangeType;
import beans.report.selectors.data.ValidLineSex;
import cli_fmw.delegate.DelegateLine2;
import clips.delegate.directory.complex.DirectoryMKB10Item;
import clips.delegate.report.DiseaseReportLocal;
import cli_fmw.main.ContentStateListener;
import cli_fmw.main.PageContainer;
import beans.report.selectors.disease.DiseaseLine;
import cli_fmw.delegate.directory.complex.DirectoryLocator;
import cli_fmw.main.ClipsException;
import cli_fmw.main.PageGeneric;
import cli_fmw.report.panels.model.notifer.NotiferItemsComboboxModel;
import cli_fmw.report.panels.model.notifer.NotiferItemsListModel;
import cli_fmw.report.panels.model.notifer.NotiferTextModel;
import cli_fmw.utils.Disposable;
import cli_fmw.utils.MessageBox;
import cli_fmw.utils.table_config_states.StateSaver;
import clips.delegate.directory.complex.DirectoryMKB10;
import clips.directory.editors.mkb10.MKbSelector;
import clips.report.panels.utils.DirectoryTreeSellectPanel;
import java.awt.EventQueue;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import javax.swing.event.ChangeEvent;
import framework.utils.events.TypedChangeEvent;
import framework.utils.events.TypedChangeListener;
import java.awt.BorderLayout;
import javax.swing.JTabbedPane;

/**
*
* @author  finder
*/
public class DiseaseLinesPanel extends PageGeneric implements ContentStateListener, Disposable, TypedChangeListener<DiseaseLine.ChangeType> {
  static final long                      serialVersionUID = 1L;
  static final String[]                    VALID_SEX_TEXT = new String[] {"всех", "мужчин", "женщин"};
 
  private DirectoryTreeSellectPanel                  treePanel;
 
  private DiseaseTable                      table;
  private SelectorIndefiner                      tableIndefiner;

  private DiseaseLine                          curLine;

  private NotiferItemsListModel<DiseaseTable.TableChangeTypes, DiseaseTable> lineListModel;
  private NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>    rowTextModel;
  private NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>    extraTitleTextModel;
  private NotiferItemsComboboxModel<DiseaseLine.ChangeType, DiseaseLine>  lineForModel;
  private NotiferItemsComboboxModel<DiseaseLine.ChangeType, DiseaseLine>  lineTypeModel;
  private NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>    altMkbModel;
  private static final String[]                    LINES = {"всех", "мужчин", "женщин"};
     
  private static int                          reportCount = 1;
  private static int                          lineCount = 1;
 
 
  public DiseaseLinesPanel(PageContainer container, DiseaseTable lines) throws ClipsException {
    super(container);
    initComponents();
    treePanel = new DirectoryTreeSellectPanel(DirectoryLocator.getDirectory(DirectoryMKB10.class));
    pnMkb.add(treePanel, BorderLayout.CENTER);
    initModels();
    setPanelLines(lines);
    StateSaver.attachTo(this);
  }

  void initModels(){
//    try {
      lineListModel = new NotiferItemsListModel<DiseaseTable.TableChangeTypes, DiseaseTable>(lineList, true, DiseaseTable.TableChangeTypes.lines, null) {
        static final long              serialVersionUID = 1L;
        @Override
        public Object getElementAtImp(int index) throws ClipsException {
          return getObject().getLines().get(index);
        }

        @Override
        public int getSizeImp() throws ClipsException {
          return getObject().getLines().size();
        }
      };
     
      rowTextModel = new NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>(rowTextField, DiseaseLine.ChangeType.title, curLine) {
        static final long              serialVersionUID = 1L;
       
        @Override
        protected void setModelTextChecked(String text) throws ClipsException {
          if (text != null){
            getObject().setLineTitle(text);
            getObject().setAutoGenerated(false);
          }
          else{
            getObject().setAutoGenerated(true);
            DiseaseReportLocal.resoveName(getObject());
          }
        }
       
        @Override
        protected String getModelTextChecked() {
          return getObject().getLineTitle();
        }
      };
     
      extraTitleTextModel = new NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>(taExtraTitle, DiseaseLine.ChangeType.extraTitle, curLine) {
        static final long              serialVersionUID = 1L;
        @Override
        protected void setModelTextChecked(String text) throws ClipsException {
          getObject().setExtraTitle(text);
        }
       
        @Override
        protected String getModelTextChecked() {
          return getObject().getExtraTitle();
        }
      };
     
      lineForModel = new NotiferItemsComboboxModel<DiseaseLine.ChangeType, DiseaseLine>(cbLineFor, false, ChangeType.validSex) {
        static final long              serialVersionUID = 1L;
        @Override
        public Object getElementAtImp(int index) throws ClipsException {
          return VALID_SEX_TEXT[index];
        }

        @Override
        public int getSizeImp() throws ClipsException {
          return VALID_SEX_TEXT.length;
        }
       
        @Override
        public Object getSelectedItemImp() throws ClipsException {
          return getElementAtImp(getObject().getValidLineSex().ordinal());
        }

        @Override
        public void setSelectedItemImp(Object anId) throws ClipsException {
          getObject().setValidLineSex(ValidLineSex.values()[getid(anId)]);
        }
       
       
      };
     
      lineTypeModel = new NotiferItemsComboboxModel<DiseaseLine.ChangeType, DiseaseLine>(lineTypeComboBox, true, DiseaseLine.ChangeType.extraData) {
        static final long              serialVersionUID = 1L;

        @Override
        public boolean isEnabled() {
          return super.isEnabled() && tableIndefiner != null;
        }


        @Override
        public Object getElementAtImp(int index) throws ClipsException {
          return tableIndefiner.getExtraLines()[index];
        }

        @Override
        public int getSizeImp() throws ClipsException {
          return tableIndefiner.getExtraLines().length;
        }

        @Override
        public Object getSelectedItemImp() throws ClipsException {
          String[]          el = tableIndefiner.getExtraLines();
          if (getObject().getSpecialLineTypeID() > el.length) {
            return "<Нет>";
          }
          else {
            return el[getObject().getSpecialLineTypeID()];
          }
        }

        @Override
        public void setSelectedItemImp(Object anItem) throws ClipsException {
          String[]          el = tableIndefiner.getExtraLines();
          for (int i = 0; i < el.length; i++) {
            String string = el[i];
            if (string == anItem) {
              getObject().setSpecialLineTypeID(i);
              return;
            }
          }
          getObject().setSpecialLineTypeID(0);
        }
      };
     
      altMkbModel = new NotiferTextModel<DiseaseLine.ChangeType, DiseaseLine>(altMkbTextArea, DiseaseLine.ChangeType.extraTitle, curLine) {
        static final long              serialVersionUID = 1L;
        @Override
        protected void setModelTextChecked(String text) throws ClipsException {
          getObject().setAlternativeMkbCode(text);
        }

        @Override
        protected String getModelTextChecked() throws ClipsException {
          return getObject().getAlternativeMkbCode();
        }
      };
           
/*    }
    catch (ClipsException ex) {
      MessageBox.showException(ex);
    }*/
  }

    /** 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() {

        rowsPanel = new javax.swing.JPanel();
        jSplitPane2 = new javax.swing.JSplitPane();
        pnMkb = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jPanel2 = new javax.swing.JPanel();
        jPanel6 = new javax.swing.JPanel();
        removeLineButton = new javax.swing.JButton();
        addLineButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        lineList = new javax.swing.JList();
        jPanel7 = new javax.swing.JPanel();
        moveUp = new javax.swing.JButton();
        moveDownButton = new javax.swing.JButton();
        btTrim = new javax.swing.JButton();
        jPanel14 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        jPanel16 = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        altMkbTextArea = new javax.swing.JTextArea();
        jLabel9 = new javax.swing.JLabel();
        lineTypeComboBox = new javax.swing.JComboBox();
        jLabel10 = new javax.swing.JLabel();
        cbLineFor = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        btParseMkb = new javax.swing.JButton();
        jPanel15 = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        rowTextField = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        taExtraTitle = new javax.swing.JTextArea();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();

        setBorder(javax.swing.BorderFactory.createEmptyBorder(5, 5, 5, 5));
        setLayout(new java.awt.BorderLayout());

        rowsPanel.setLayout(new java.awt.BorderLayout());

        jSplitPane2.setDividerLocation(250);
        jSplitPane2.setResizeWeight(0.5);

        pnMkb.setLayout(new java.awt.BorderLayout());

        jLabel3.setText("Заболевания соответствующие выбранной линии:");
        pnMkb.add(jLabel3, java.awt.BorderLayout.PAGE_START);

        jSplitPane2.setRightComponent(pnMkb);

        jPanel2.setLayout(new java.awt.BorderLayout());

        removeLineButton.setText("Удалить");
        removeLineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                removeLineButtonActionPerformed(evt);
            }
        });

        addLineButton.setText("Добавить");
        addLineButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                addLineButtonActionPerformed(evt);
            }
        });

        jLabel4.setText("Список линий отчета:");

        javax.swing.GroupLayout jPanel6Layout = new javax.swing.GroupLayout(jPanel6);
        jPanel6.setLayout(jPanel6Layout);
        jPanel6Layout.setHorizontalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(addLineButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(removeLineButton)
                .addContainerGap(94, Short.MAX_VALUE))
            .addComponent(jLabel4, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
        );
        jPanel6Layout.setVerticalGroup(
            jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel6Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(addLineButton)
                    .addComponent(removeLineButton)))
        );

        jPanel2.add(jPanel6, java.awt.BorderLayout.NORTH);

        lineList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                lineListValueChanged(evt);
            }
        });
        jScrollPane3.setViewportView(lineList);

        jPanel2.add(jScrollPane3, java.awt.BorderLayout.CENTER);

        moveUp.setText("Вверх");
        moveUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moveUpActionPerformed(evt);
            }
        });

        moveDownButton.setText("Вниз");
        moveDownButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                moveDownButtonActionPerformed(evt);
            }
        });

        btTrim.setText("Trim");
        btTrim.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btTrimActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addComponent(moveUp)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(moveDownButton)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 108, Short.MAX_VALUE)
                .addComponent(btTrim))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(moveUp)
                .addComponent(moveDownButton)
                .addComponent(btTrim))
        );

        jPanel2.add(jPanel7, java.awt.BorderLayout.PAGE_END);

        jSplitPane2.setLeftComponent(jPanel2);

        rowsPanel.add(jSplitPane2, java.awt.BorderLayout.CENTER);

        jPanel14.setBorder(javax.swing.BorderFactory.createTitledBorder("Свойства выбранной линии отчета"));
        jPanel14.setLayout(new java.awt.BorderLayout(3, 3));

        jPanel4.setLayout(new java.awt.BorderLayout(3, 3));

        altMkbTextArea.setColumns(10);
        altMkbTextArea.setLineWrap(true);
        altMkbTextArea.setRows(3);
        jScrollPane4.setViewportView(altMkbTextArea);

        jLabel9.setText("Тип линии");

        lineTypeComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel10.setText("Альтернативный текст кода МКБ");

        cbLineFor.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        jLabel1.setText("Линя для:");

        btParseMkb.setText("Распознать");
        btParseMkb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btParseMkbActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel16Layout = new javax.swing.GroupLayout(jPanel16);
        jPanel16.setLayout(jPanel16Layout);
        jPanel16Layout.setHorizontalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addComponent(jLabel10)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                .addComponent(btParseMkb))
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbLineFor, 0, 282, Short.MAX_VALUE))
            .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 362, Short.MAX_VALUE)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lineTypeComboBox, 0, 283, Short.MAX_VALUE))
        );
        jPanel16Layout.setVerticalGroup(
            jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel16Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(cbLineFor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(lineTypeComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel16Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel10)
                    .addComponent(btParseMkb))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 107, Short.MAX_VALUE))
        );

        jPanel4.add(jPanel16, java.awt.BorderLayout.LINE_END);

        jPanel15.setPreferredSize(new java.awt.Dimension(160, 87));
        jPanel15.setLayout(new java.awt.BorderLayout());

        jScrollPane6.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);

        rowTextField.setColumns(15);
        rowTextField.setLineWrap(true);
        rowTextField.setRows(5);
        jScrollPane6.setViewportView(rowTextField);

        jPanel15.add(jScrollPane6, java.awt.BorderLayout.CENTER);

        jPanel1.setLayout(new java.awt.BorderLayout());

        taExtraTitle.setColumns(20);
        taExtraTitle.setLineWrap(true);
        taExtraTitle.setRows(2);
        jScrollPane1.setViewportView(taExtraTitle);

        jPanel1.add(jScrollPane1, java.awt.BorderLayout.CENTER);

        jLabel2.setText("Дополнительный заголовок:");
        jPanel1.add(jLabel2, java.awt.BorderLayout.PAGE_START);

        jPanel15.add(jPanel1, java.awt.BorderLayout.SOUTH);

        jLabel5.setText("Заголовок линии");
        jPanel15.add(jLabel5, java.awt.BorderLayout.PAGE_START);

        jPanel4.add(jPanel15, java.awt.BorderLayout.CENTER);

        jPanel14.add(jPanel4, java.awt.BorderLayout.CENTER);

        rowsPanel.add(jPanel14, java.awt.BorderLayout.SOUTH);

        add(rowsPanel, java.awt.BorderLayout.CENTER);
    }// </editor-fold>//GEN-END:initComponents



private void moveDownButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveDownButtonActionPerformed
    moveLines(false);
}//GEN-LAST:event_moveDownButtonActionPerformed

private void moveUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_moveUpActionPerformed
    moveLines(true);
}//GEN-LAST:event_moveUpActionPerformed

private void lineListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_lineListValueChanged
    onLineSelectionChange();
}//GEN-LAST:event_lineListValueChanged

private void addLineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addLineButtonActionPerformed

    if (table != null){
      DiseaseLine      line = new DiseaseLine();
      line.setLineTitle("Ноавя линия (" + (lineCount++) + ")");
      int      idx = lineList.getSelectedIndex();
      if (idx >= 0) {
        idx++;
      }
      if (table.getLines().size() < idx){
        idx = table.getLines().size();
      }
      table.addLine(idx, line);
      lineList.setSelectedValue(line, true);
    }
}//GEN-LAST:event_addLineButtonActionPerformed

private void removeLineButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeLineButtonActionPerformed
    Object[]      vals = lineList.getSelectedValues();
    for (Object object : vals) {
      table.removeLine((DiseaseLine)object);
    }
    onLineSelectionChange();
}//GEN-LAST:event_removeLineButtonActionPerformed

private void btTrimActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btTrimActionPerformed
  String        str = rowTextField.getText().trim();
  StringBuffer    buf = new StringBuffer(str.length());
  boolean        returnFound = false;
  boolean        spaseFound = false;
  for (int i = 0; i < str.length(); i++){
    char        ch = str.charAt(i);
    if (ch == '\n' || ch == '\r'){
      returnFound = true;
    }
    else if (ch == ' ' || ch == '\t'){
      spaseFound = true;
    }
    else {
      if (returnFound){
        returnFound = false;
        spaseFound = false;
        buf.append('\n');
      }
      else if (spaseFound){
        spaseFound = false;
        buf.append(' ');
      }
      buf.append(ch);
    }
  }
  rowTextField.setText(buf.toString());
}//GEN-LAST:event_btTrimActionPerformed

private void btParseMkbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btParseMkbActionPerformed
    if (curLine == null){
      return;
    }
    if (curLine.getAlternativeMkbCode() == null || curLine.getAlternativeMkbCode().trim().isEmpty()){
      curLine.setItems(new int[0]);
      return;
    }
    MKBParser      parser = new MKBParser(MKBParser.ParseLevel.soft);
    try {
      ArrayList<MKBCode>        codes = parser.parse(curLine.getAlternativeMkbCode());
      DirectoryMKB10          mkbDir = DirectoryLocator.getDirectory(DirectoryMKB10.class);
      MKbSelector            selector = new MKbSelector(mkbDir, MKbSelector.SelectType.single);
      ArrayList<DirectoryMKB10Item>  mkbItems = selector.getSelectedItem(codes);
      int[]              ids = new int[mkbItems.size()];
      for (int i = 0; i < ids.length; i++) {
        ids[i] = mkbItems.get(i).getID();
      }
      curLine.setItems(ids);
    }
    catch (ParseException ex) {
      MessageBox.showExceptionOnly(ex);
      return;
    }
    catch (ClipsException ex) {
      MessageBox.showException(ex);
      return;
    }
}//GEN-LAST:event_btParseMkbActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addLineButton;
    private javax.swing.JTextArea altMkbTextArea;
    private javax.swing.JButton btParseMkb;
    private javax.swing.JButton btTrim;
    private javax.swing.JComboBox cbLineFor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel14;
    private javax.swing.JPanel jPanel15;
    private javax.swing.JPanel jPanel16;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JList lineList;
    private javax.swing.JComboBox lineTypeComboBox;
    private javax.swing.JButton moveDownButton;
    private javax.swing.JButton moveUp;
    private javax.swing.JPanel pnMkb;
    private javax.swing.JButton removeLineButton;
    private javax.swing.JTextArea rowTextField;
    private javax.swing.JPanel rowsPanel;
    private javax.swing.JTextArea taExtraTitle;
    // End of variables declaration//GEN-END:variables

 
  private boolean setPanelLines(DiseaseTable newTable){
    if (newTable != table){
      table = newTable;
      /*if (lines != null){
        lines.removeContentStateListener(this);
      }
     
      if (lines != null){
        lines.addContentStateListener(this);
      }*/
    }
    if (table != null){
      tableIndefiner = table.getType();
    }
    else{
      tableIndefiner = null;
    }
    lineTypeModel.contentStateChanged();
    lineListModel.setObject(table);
    updateButtons();
    setCurLine(null);
    return true;
  }
   
  @Override
  public void contentStateChanged() {
    EventQueue.invokeLater(new Runnable() {
      @Override
      public void run() {
        updateButtons();
        contentStateChanged();
      }
    });
  }
 
  private void updateButtons(){
    boolean      addRowButtonEn = false,
            removeButtonEn = false,
            moveUpButtonEn = false,     
            moveDownButtonEn = false,
            trimButtonEn = false,
            autoButtonEn = false;

    if (table != null){
      addRowButtonEn = true;
      removeButtonEn = lineList.getSelectedIndex() >= 0;
      trimButtonEn = curLine != null;
      autoButtonEn = curLine != null;
      moveUpButtonEn = canMoveLines(true);
      moveDownButtonEn = canMoveLines(false);
    }
   
    addLineButton.setEnabled(addRowButtonEn);
    removeLineButton.setEnabled(removeButtonEn);
    moveUp.setEnabled(moveUpButtonEn);
    moveDownButton.setEnabled(moveDownButtonEn);
    btTrim.setEnabled(trimButtonEn);
    btParseMkb.setEnabled(autoButtonEn);
  }
 
   
  private void setCurLine(DiseaseLine  newLine){
    if (curLine != null) {
      curLine.removeChangeListener(this);
    }
    curLine = newLine;
    treePanel.setObject(newLine);
    if (curLine != null) {
      curLine.addChangeListener(this);
    }
    stateChanged(null);
    rowTextModel.setObject(newLine);
    extraTitleTextModel.setObject(newLine);
    lineForModel.setObject(newLine);
    lineTypeModel.setObject(newLine);
    altMkbModel.setObject(newLine);
    updateButtons();
  }
 
  private boolean moveLines(int[] ids, boolean moveUp, boolean aply){
    if (ids == null) {
      return false;
    }
    int[]            sorted = ids.clone();
    Arrays.sort(sorted);
    boolean            resould = false;
    int              limit;
    ArrayList<DiseaseLine>    lines = new ArrayList<DiseaseLine>(table.getLines());
    if (moveUp){
      limit = 0;
      for (int i = 0; i < sorted.length; i++) {
        int id = sorted[i];
        if (id > limit && id < lineListModel.getSize()){
          resould = true;
          if (aply){
            DiseaseLine    tmp = lines.get(id - 1);
            lines.set(id - 1, lines.get(id));
            lines.set(id, tmp);
          }
        }
        else{
          limit = id + 1;
        }
      }
    }
    else{
      limit = lineListModel.getSize() - 1;
      for (int i = sorted.length - 1; i >= 0; i--) {
        int id = sorted[i];
        if (id >= 0 && id < limit){
          resould = true;
          if (aply){
            DiseaseLine    tmp = lines.get(id + 1);
            lines.set(id + 1, lines.get(id));
            lines.set(id, tmp);
          }
        }
        else{
          limit = id - 1;
        }
      }
    }
    if (aply){
      table.setLines(lines);
    }
    return resould;
  }
 
  private boolean canMoveLines(boolean moveUp){
    return moveLines(lineList.getSelectedIndices(), moveUp, false);
  }
 
  private void moveLines(boolean moveUp){
    Object[] val = lineList.getSelectedValues();
    if (val == null) {
      return;
    }
    moveLines(lineList.getSelectedIndices(), moveUp, true);
    int[]    idx = new int[val.length];
    for (int i = 0; i < val.length; i++) {
      idx[i] = table.getLines().indexOf(val[i]);
    }
    lineList.setSelectedIndices(idx);
  }

  private void onLineSelectionChange(){
    Object[] vals = lineList.getSelectedValues();
    if (vals != null && vals.length == 1){
      setCurLine((DiseaseLine) vals[0]);
    }
    else{
      setCurLine(null);
    }
  }
 
  @Override
  public void dispose() {
    setPanelLines(null);
  }

  @Override
  public void stateChanged(ChangeEvent e) {
    if (e != null && e instanceof TypedChangeEvent){
      @SuppressWarnings("unchecked")
      DiseaseLine.ChangeType      type = ((TypedChangeEvent<DiseaseLine.ChangeType>)e).getEventType();
      if (type == DiseaseLine.ChangeType.data || type == null){
        try {
          treePanel.onTreeUpdated();
          DiseaseReportLocal.resoveName(curLine);
        }
        catch (ClipsException ex) {
          MessageBox.showException(ex);
        }
      }
    }
    else{
      treePanel.onTreeUpdated();
    }
  }

  @Override
  public DiseaseLine.ChangeType getType() {
    return null;
  }

  @Override
  public String getPageTitle() {
    return "Линии таблицы по МКБ";
  }

  @Override
  public DelegateLine2 getDelegate() {
    throw new UnsupportedOperationException("Not supported yet.");
  }
}
TOP

Related Classes of clips.report.panels.DiseaseLinesPanel

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.