// Фильтрация классификаторов public void setClassifierFilter(String beginsWith) { TableRowSorter<AbstractTableModel> sorter = new TableRowSorter<>(table.getModel()); RowFilter<Object, Object> rf = RowFilter.regexFilter("^" + beginsWith, 0); table.setRowSorter(sorter); sorter.setRowFilter(rf); }
@Override public void onConnect(ru.nkz.ivcgzo.thriftCommon.kmiacServer.KmiacServer.Client conn) { super.onConnect(conn); if (conn instanceof ThriftViewSelect.Client) { tcl = thrClient; try { table.setData(tcl.getVSStringClassifierView("n_spr")); } catch (TException e) { e.printStackTrace(); conMan.reconnect(e); } } }
// Быстрый поиск по таблице private void search() { String target = tfSearch.getText(); for (int row = 0; row < table.getRowCount(); row++) for (int col = 0; col < table.getColumnCount(); col++) { String next = table.getValueAt(row, col).toString(); Pattern pt = Pattern.compile(target.toLowerCase()); Matcher mt = pt.matcher(next.toLowerCase()); if (mt.find()) { table.setRowSelectionInterval(row, row); table.setLocation(0, -((table.getRowHeight() * row) - 100)); return; } } }
/** Initialize the contents of the frame. */ private void initialize() { frame = new JFrame(); frame.setTitle("Нормативно-справочная информация"); frame.setBounds(100, 100, 750, 400); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ButtonGroup group = new ButtonGroup(); JMenuBar menuBar = new JMenuBar(); frame.setJMenuBar(menuBar); JMenu mnNewMenu = new JMenu("Показать"); menuBar.add(mnNewMenu); final JMenuItem rbMenuItemAll = new JRadioButtonMenuItem("Все"); mnNewMenu.add(rbMenuItemAll); group.add(rbMenuItemAll); rbMenuItemAll.setSelected(true); rbMenuItemAll.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (rbMenuItemAll.isSelected()) { table.setRowSorter(null); } } }); final JMenuItem rbMenuItemStat = new JRadioButtonMenuItem("Статические"); mnNewMenu.add(rbMenuItemStat); group.add(rbMenuItemStat); rbMenuItemStat.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (rbMenuItemStat.isSelected()) { table.setRowSorter(null); setClassifierFilter("n_"); } } }); final JMenuItem rbMenuItemDyn = new JRadioButtonMenuItem("Редактируемые"); mnNewMenu.add(rbMenuItemDyn); group.add(rbMenuItemDyn); rbMenuItemDyn.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (rbMenuItemDyn.isSelected()) { table.setRowSorter(null); setClassifierFilter("s_"); } } }); tfSearch = new JTextField(); frame.getContentPane().add(tfSearch, BorderLayout.NORTH); tfSearch.setColumns(10); tfSearch .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent documentEvent) { search(); } public void insertUpdate(DocumentEvent documentEvent) { search(); } public void removeUpdate(DocumentEvent documentEvent) { search(); } }); JScrollPane spClassifier = new JScrollPane(); frame.getContentPane().add(spClassifier, BorderLayout.CENTER); table = new CustomTable<>(false, true, StringClassifier.class, 0, "Код", 1, "Наименование"); table.setAutoCreateRowSorter(true); table.getRowSorter().toggleSortOrder(0); table.setFillsViewportHeight(true); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); table.getColumnModel().getColumn(0).setMaxWidth(100); spClassifier.setViewportView(table); table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { String className = table.getSelectedItem().pcod; try { if (className.equals("n_c00")) { conMan.showMkbTreeForm("Диагноз", ""); } else if (className.equals("n_nsipol")) { conMan.showPolpTreeForm("Поликлиники Кемеровской Области", -1, -1, -1); } else if (className.equals("n_z43")) { conMan.showMrabTreeForm("Место работы", -1); } else if (tcl.isClassifierPcodInteger(className)) { ViewTablePcodIntForm VSPIForm = new ViewTablePcodIntForm(); MainForm.instance.addChildFrame(VSPIForm); ViewTablePcodIntForm.tableFill(className); VSPIForm.setVisible(true); } else { ViewTablePcodStringForm VSPSForm = new ViewTablePcodStringForm(); MainForm.instance.addChildFrame(VSPSForm); ViewTablePcodStringForm.tableFill(className); VSPSForm.setVisible(true); } } catch (TException e1) { e1.printStackTrace(); conMan.reconnect(e1); } } } }); }