private void initPanel() { startDay = new LocalDate(); lblLeft.setText(SYSTools.xx("nursingrecords.liquidbalances.summary")); lblRight.setText(SYSTools.xx("nursingrecords.liquidbalances.details")); lblLimits.setText(null); df = DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT); nf = DecimalFormat.getNumberInstance(); }
private void prepareSearchArea() { searchPanes = new CollapsiblePanes(); searchPanes.setLayout(new JideBoxLayout(searchPanes, JideBoxLayout.Y_AXIS)); jspSearch.setViewportView(searchPanes); JPanel mypanel = new JPanel(); mypanel.setLayout(new VerticalLayout(3)); mypanel.setBackground(Color.WHITE); CollapsiblePane searchPane = new CollapsiblePane(SYSTools.xx(internalClassID)); searchPane.setStyle(CollapsiblePane.PLAIN_STYLE); searchPane.setCollapsible(false); try { searchPane.setCollapsed(false); } catch (PropertyVetoException e) { OPDE.error(e); } GUITools.addAllComponents(mypanel, addCommands()); searchPane.setContentPane(mypanel); searchPanes.add(searchPane); searchPanes.addExpansion(); }
private java.util.List<Component> addCommands() { java.util.List<Component> list = new ArrayList<Component>(); /** * _ _ | \ | | _____ __ | \| |/ _ \ \ /\ / / | |\ | __/\ V V / |_| \_|\___| \_/\_/ */ JideButton addButton = GUITools.createHyperlinkButton( SYSTools.xx("misc.commands.new"), new ImageIcon(getClass().getResource("/artwork/22x22/bw/add.png")), new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (!resident.isActive()) { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage("misc.msg.cantChangeInactiveResident")); return; } new DlgValue( new ResValue(resident, LIQUIDBALANCE), DlgValue.MODE_NEW, new Closure() { @Override public void execute(Object o) { ResValue myValue = null; if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); myValue = em.merge((ResValue) o); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); em.getTransaction().commit(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } startDay = new LocalDate(myValue.getPit()); loadLeftTable(); loadRightTable(startDay, startDay); } } }); } }); list.add(addButton); JideButton controlButton = GUITools.createHyperlinkButton( SYSTools.xx("nursingrecords.vitalparameters.btnControlling.tooltip"), SYSConst.icon22magnify1, new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (!resident.isActive()) { OPDE.getDisplayManager() .addSubMessage(new DisplayMessage("misc.msg.cantChangeInactiveResident")); return; } new DlgValueControl( resident, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Resident myResident = em.merge(resident); em.lock(myResident, LockModeType.OPTIMISTIC); myResident.setControlling((Properties) o); em.getTransaction().commit(); resident = myResident; } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } parseControlling(); loadLeftTable(); } } }); } }); list.add(controlButton); return list; }
void loadRightTable(final LocalDate from, final LocalDate to) { if (listValues != null) { listValues.clear(); } listValues = ResValueTools.getResValuesNoEdits(resident, ResValueTypesTools.LIQUIDBALANCE, from, to); Object[][] data = new Object[listValues.size()][5]; int row = 0; for (ResValue val : listValues) { data[row][0] = df.format(val.getPit()); data[row][1] = nf.format(val.getVal1()); data[row][2] = val.getText(); data[row][3] = SYSTools.anonymizeUser(val.getUser().getUID()); data[row][4] = SYSConst.icon22delete; row++; } Object[] headers = new Object[] { SYSTools.xx("misc.msg.Date"), SYSTools.xx("misc.msg.amount"), SYSTools.xx("misc.msg.Text"), SYSTools.xx("misc.msg.user"), SYSTools.xx("misc.msg.delete") }; final DefaultTableModel tmRight = new DefaultTableModel(data, headers) { @Override public boolean isCellEditable(int row, int column) { return column == 4; // only the del-button } }; tmRight.setColumnCount(5); tblRight.setModel(tmRight); tblRight.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); tblRight.getColumnModel().getColumn(1).setCellRenderer(rightRenderer); TableUtils.autoResizeAllColumns( tblRight, null, new int[] {200, 200, 200, 200, 100}, true, false); TableUtils.autoResizeAllRows(tblRight); /** * * ____ _ _ | _ \ ___| | ___| |_ ___ | | | |/ _ \ |/ _ \ __/ _ \ | |_| | __/ | __/ || __/ * |____/ \___|_|\___|\__\___| */ ButtonColumn bc = new ButtonColumn( tblRight, new AbstractAction() { @Override public void actionPerformed(ActionEvent ae) { final int row = Integer.parseInt(ae.getActionCommand()); final ResValue val2Delete = listValues.get(row); new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><i>" + "<br/><i>" + df.format(val2Delete.getPit()) + "<br/>" + nf.format(val2Delete.getVal1()) + " ml<br/>" + val2Delete.getUser().toString() + "</i><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object answer) { if (answer.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); ResValue myValue = em.merge(val2Delete); em.lock(myValue, LockModeType.OPTIMISTIC); myValue.setDeletedBy(em.merge(OPDE.getLogin().getUser())); for (SYSVAL2FILE file : myValue.getAttachedFilesConnections()) { em.remove(file); } myValue.getAttachedFilesConnections().clear(); for (SYSVAL2PROCESS connObj : myValue.getAttachedProcessConnections()) { em.remove(connObj); } myValue.getAttachedProcessConnections().clear(); myValue.getAttachedProcesses().clear(); em.getTransaction().commit(); listValues.remove(row); tmRight.removeRow(row); loadLeftTable(); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) { OPDE.getMainframe().emptyFrame(); OPDE.getMainframe().afterLogin(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }, 4); bc.setMnemonic(KeyEvent.VK_DELETE); }
void loadLeftTable() { Vector<Vector> dataLeft = new Vector<>(); listSummaries = ResValueTools.getLiquidBalances(resident, startDay, 20); for (Object[] obj : listSummaries) { Vector line = new Vector(); line.add(new LocalDate(((java.sql.Date) obj[0]).getTime())); BigDecimal liquidin = (BigDecimal) obj[1]; line.add(liquidin); line.add(obj[2]); BigDecimal liquidresult = (BigDecimal) obj[3]; line.add(liquidresult); if (highIn != null || lowIn != null) { String evaluation = ""; if (lowIn != null && liquidin.compareTo(lowIn) < 0) { evaluation = SYSConst.html_color(Color.blue, SYSConst.html_bold("misc.msg.too.less")); } else if (highIn != null && liquidin.compareTo(highIn) > 0) { evaluation = SYSConst.html_color(Color.red, SYSConst.html_bold("misc.msg.too.much")); } else { evaluation = SYSConst.html_color(Color.green.darker(), SYSConst.html_bold("misc.msg.ok")); } line.add(evaluation); } dataLeft.add(line); } Vector<String> headerLeft = new Vector<>(); headerLeft.add(SYSTools.xx("misc.msg.Date")); headerLeft.add(SYSTools.xx("misc.msg.ingestion")); headerLeft.add(SYSTools.xx("misc.msg.egestion")); headerLeft.add(SYSTools.xx("misc.msg.liquid.result")); if (highIn != null || lowIn != null) { headerLeft.add(SYSTools.xx("misc.msg.evaluation")); } DefaultTableModel tmLeft = new DefaultTableModel(dataLeft, headerLeft) { @Override public boolean isCellEditable(int row, int column) { return false; } }; tblLeft.setModel(tmLeft); tblLeft .getSelectionModel() .addListSelectionListener( new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) return; ListSelectionModel lsm = (ListSelectionModel) e.getSource(); int minIndex = lsm.getMinSelectionIndex(); int maxIndex = lsm.getMaxSelectionIndex(); if (minIndex < 0 || maxIndex < 0) return; cleanup(); loadRightTable( (LocalDate) tblLeft.getModel().getValueAt(maxIndex, 0), (LocalDate) tblLeft.getModel().getValueAt(minIndex, 0)); } }); tblLeft .getColumnModel() .getColumn(0) .setCellRenderer( new TableCellRenderer() { @Override public Component getTableCellRendererComponent( JTable table, Object o, boolean isSelected, boolean hasFocus, int row, int column) { String text; if (o == null) { text = SYSTools.xx("misc.commands.>>noselection<<"); } else if (o instanceof LocalDate) { text = ((LocalDate) o).toString("dd.MM.yyyy"); } else { text = o.toString(); } return new DefaultTableCellRenderer() .getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column); } }); DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer(); rightRenderer.setHorizontalAlignment(JLabel.RIGHT); tblLeft.getColumnModel().getColumn(1).setCellRenderer(rightRenderer); tblLeft.getColumnModel().getColumn(2).setCellRenderer(rightRenderer); tblLeft.getColumnModel().getColumn(3).setCellRenderer(rightRenderer); if (highIn != null || lowIn != null) { tblLeft.getColumnModel().getColumn(4).setCellRenderer(new RNDHTML()); } scrlLeftComponentResized(null); }