List of usage examples for javax.persistence LockModeType OPTIMISTIC
LockModeType OPTIMISTIC
To view the source code for javax.persistence LockModeType OPTIMISTIC.
Click Source Link
From source file:op.care.med.structure.DlgProduct.java
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed if (!saveOK()) return;//from w w w . j a v a2 s . co m EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedProducts myProduct = em.merge(product); myProduct.setText(txtName.getText().trim()); myProduct.setSideEffects(txtSideEffects.getText().trim()); myProduct.setACME(em.merge((ACME) cmbAcme.getSelectedItem())); for (TradeForm tf : myProduct.getTradeforms()) { em.lock(em.merge(tf), LockModeType.OPTIMISTIC_FORCE_INCREMENT); for (MedPackage mp : tf.getPackages()) { em.lock(em.merge(mp), LockModeType.OPTIMISTIC_FORCE_INCREMENT); } } em.lock(myProduct, LockModeType.OPTIMISTIC); em.getTransaction().commit(); product = myProduct; } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } dispose(); //hier gehts weiter. prf auch die anderen locks bei den anderen editoren }
From source file:org.key2gym.business.services.OrdersServiceBean.java
@Override public void addPurchase(Integer orderId, Integer itemId, Integer discountId, Integer quantity) throws BusinessException, ValidationException, SecurityViolationException { /*/* w ww .j av a 2s. c o m*/ * Checks the caller's roles. */ if (!callerHasAnyRole(SecurityRoles.JUNIOR_ADMINISTRATOR, SecurityRoles.SENIOR_ADMINISTRATOR, SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } if (orderId == null) { throw new NullPointerException("The orderId is null."); } if (itemId == null) { throw new NullPointerException("The itemId is null."); //NOI18N } if (quantity == null) { throw new NullPointerException("The quantity is null."); } OrderEntity order; Item item; Discount discount; order = em.find(OrderEntity.class, orderId, LockModeType.OPTIMISTIC); if (order == null) { throw new ValidationException(getString("Invalid.Order.ID")); } /* * Performs additional roles checks. */ Boolean managerRoleRequired = (order.getAttendance() != null && !order.getAttendance().isOpen()) || !isToday(order.getDate()); if (managerRoleRequired && !callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } if (quantity <= 0) { throw new ValidationException(getString("Invalid.OrderLine.Quantity")); } item = em.find(Item.class, itemId); if (item == null) { throw new ValidationException(getString("Invalid.Item.ID")); } if (item.getItemSubscription() != null && order.getClient() == null) { throw new BusinessException(getString("BusinessRule.Order.Casual.CanNotPurchaseSubscriptions")); } if (discountId == null) { discount = null; } else { discount = em.find(Discount.class, discountId); if (discount == null) { throw new ValidationException(getString("Invalid.Discount.ID")); } } /* * Frozen items can not be ordered. */ if (item.isFrozen()) { throw new ValidationException(getString("BusinessRule.Order.ItemFrozen")); } /* * Checks the item's quantity, if it's countable. */ Integer currentQuantity = item.getQuantity(); if (currentQuantity != null) { /* * If the item is not in stock, throws a BusinessException. * The item's quantity will be decreased after all checks are performed. */ if (currentQuantity == 0) { throw new BusinessException(getString("BusinessRule.Order.ItemNotInStock")); } } /* * Business logic specific to orders associated with clients. */ if (order.getClient() != null) { Client client = order.getClient(); client.charge(item, quantity, discount); if (item.getItemSubscription() != null) { client.activate(item.getItemSubscription()); } } /* * The change should be here, because we have to change the date after * all checks have been performed. */ if (currentQuantity != null) { item.setQuantity(currentQuantity - quantity); } /* * Attempts to find an appropriate order line. */ OrderLine orderLine; Query query; if (discount == null) { query = em.createNamedQuery("OrderLine.findByOrderAndItemAndNoDiscount"); } else { query = em.createNamedQuery("OrderLine.findByOrderAndItemAndDiscount").setParameter("discount", discount); } query.setParameter("order", order).setParameter("item", item); try { orderLine = (OrderLine) query.setMaxResults(1).getSingleResult(); } catch (NoResultException ex) { orderLine = null; } /* * Creates a new order line, if none was found. */ if (orderLine == null) { orderLine = new OrderLine(); orderLine.setItem(item); orderLine.setOrder(order); orderLine.setQuantity(quantity); orderLine.setDiscount(discount); em.persist(orderLine); List<OrderLine> orderLines = order.getOrderLines(); if (orderLines == null) { orderLines = new LinkedList<>(); order.setOrderLines(orderLines); } orderLines.add(orderLine); } else { orderLine.setQuantity(orderLine.getQuantity() + quantity); } }
From source file:op.users.PnlUser.java
private java.util.List<Component> addCommands() { java.util.List<Component> list = new ArrayList<Component>(); /***/*from w ww . j ava2 s .c o m*/ * _ _ _ _ _ * / \ __| | __| | | | |___ ___ _ __ * / _ \ / _` |/ _` | | | / __|/ _ \ '__| * / ___ \ (_| | (_| | |_| \__ \ __/ | * /_/ \_\__,_|\__,_|\___/|___/\___|_| * */ final JideButton btnAddUser = GUITools.createHyperlinkButton(SYSTools.xx("opde.users.btnAddUser"), SYSConst.icon22addUser, null); btnAddUser.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (tabMain.getSelectedIndex() != TAB_USER) { tabMain.setSelectedIndex(TAB_USER); } new DlgUser(new Users(), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users user = em.merge((Users) o); // Put everyone into >>everyone<< Groups everyone = em.find(Groups.class, "everyone"); em.lock(everyone, LockModeType.OPTIMISTIC); user.getGroups().add(everyone); everyone.getMembers().add(user); em.getTransaction().commit(); lstUsers.add(user); reloadDisplay(); } catch (Exception e) { em.getTransaction().rollback(); } finally { em.close(); } } } }); } }); list.add(btnAddUser); /*** * _ _ _ ____ * / \ __| | __| |/ ___|_ __ ___ _ _ _ __ * / _ \ / _` |/ _` | | _| '__/ _ \| | | | '_ \ * / ___ \ (_| | (_| | |_| | | | (_) | |_| | |_) | * /_/ \_\__,_|\__,_|\____|_| \___/ \__,_| .__/ * |_| */ final JideButton btnAddGroup = GUITools.createHyperlinkButton(SYSTools.xx("opde.users.btnAddGroup"), SYSConst.icon22addGroup, null); btnAddGroup.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (tabMain.getSelectedIndex() != TAB_GROUPS) { tabMain.setSelectedIndex(TAB_GROUPS); } new DlgGroup(new Groups(), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Groups myGroup = em.merge((Groups) o); em.getTransaction().commit(); createCP4(myGroup); lstGroups.add(myGroup); Collections.sort(lstGroups); buildPanel(); } catch (Exception e) { // em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } } }); } }); list.add(btnAddGroup); /*** * _ _ ____ _ _ * | |__ | |_ _ __ | _ \ _ __(_)_ __ | |_ * | '_ \| __| '_ \| |_) | '__| | '_ \| __| * | |_) | |_| | | | __/| | | | | | | |_ * |_.__/ \__|_| |_|_| |_| |_|_| |_|\__| * */ // JideButton btnPrint = GUITools.createHyperlinkButton(SYSTools.xx("misc.commands.print"), SYSConst.icon22print2, new ActionListener() { // @Override // public void actionPerformed(ActionEvent actionEvent) { // // } // }); // list.add(btnPrint); return list; }
From source file:op.care.med.structure.DlgTradeForm.java
private void btnOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnOKActionPerformed EntityManager em = OPDE.createEM();//from ww w . jav a 2 s . co m try { em.getTransaction().begin(); TradeForm myTradeForm = em.merge(tradeForm); em.lock(myTradeForm, LockModeType.OPTIMISTIC); myTradeForm.setSubtext(txtZusatz.getText()); DosageForm dosageForm = em.merge((DosageForm) cmbForm.getSelectedItem()); em.lock(dosageForm, LockModeType.OPTIMISTIC); myTradeForm.setDosageForm(dosageForm); em.getTransaction().commit(); tradeForm = myTradeForm; } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } dispose(); }
From source file:op.care.reports.PnlReport.java
private java.util.List<Component> addCommands() { java.util.List<Component> list = new ArrayList<Component>(); /***/* w ww . ja v a 2 s . c o m*/ * _ _ * | \ | | _____ __ * | \| |/ _ \ \ /\ / / * | |\ | __/\ V V / * |_| \_|\___| \_/\_/ * */ if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { 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 DlgReport(new NReport(resident), new Closure() { @Override public void execute(Object report) { if (report != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport myReport = (NReport) em.merge(report); em.getTransaction().commit(); final String keyYear = Integer .toString(new DateTime(myReport.getPit()).getYear()) + ".year"; if (!cpMap.containsKey(keyYear)) { reloadDisplay(); } else { final String keyDay = DateFormat.getDateInstance() .format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyDay); } synchronized (valuecache) { if (valuecache.containsKey(keyDay)) { valuecache.get(keyDay).add(myReport); Collections.sort(valuecache.get(keyDay)); } } synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myReport.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } if (minmax.isAfter(new DateTime(myReport.getPit()))) { minmax.setStart(new DateTime(myReport.getPit())); } if (minmax.isBefore(new DateTime(myReport.getPit()))) { minmax.setEnd(new DateTime(myReport.getPit())); } createCP4Day(new LocalDate(myReport.getPit())); expandDay(new LocalDate(myReport.getPit())); buildPanel(); GUITools.scroll2show(jspReports, cpMap.get(keyDay), cpsReports, new Closure() { @Override public void execute(Object o) { GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } }); } } 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(); } else { reloadDisplay(true); } } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); } }); list.add(addButton); } return list; }
From source file:op.care.med.inventory.DlgCloseStock.java
private void save() { EntityManager em = OPDE.createEM();// w w w . j a v a2 s . com try { em.getTransaction().begin(); final MedStock myStock = em.merge(medStock); em.lock(myStock, LockModeType.OPTIMISTIC); em.lock(em.merge(myStock.getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(em.merge(myStock.getInventory()), LockModeType.OPTIMISTIC); OPDE.important("StockID: " + myStock.getID() + " " + SYSTools.xx("misc.msg.closed")); OPDE.important("UID: " + OPDE.getLogin().getUser().getUID()); MedStock nextBest = null; if (cmbBestID.getSelectedIndex() > 0) { nextBest = em.merge((MedStock) cmbBestID.getSelectedItem()); OPDE.important(SYSTools.xx("nursingrecords.prescription.dlgCloseStock.LOG.STATE_EDIT_EMPTY_SOON1") + ": " + nextBest.getID()); em.lock(nextBest, LockModeType.OPTIMISTIC); myStock.setNextStock(nextBest); } if (rbStellen.isSelected()) { BigDecimal inhalt = new BigDecimal(Double.parseDouble(txtLetzte.getText().replace(",", "."))); MedStockTools.setStockTo(em, myStock, inhalt, SYSTools.xx("nursingrecords.prescription.dlgCloseStock.TX.STATE_EDIT_EMPTY_SOON"), MedStockTransactionTools.STATE_EDIT_EMPTY_SOON); myStock.setState(MedStockTools.STATE_WILL_BE_CLOSED_SOON); OPDE.important(SYSTools.xx("nursingrecords.prescription.dlgCloseStock.LOG.STATE_EDIT_EMPTY_SOON1") + ": " + inhalt); } else { if (rbGefallen.isSelected()) { MedStockTools.close(em, myStock, SYSTools.xx( "nursingrecords.prescription.dlgCloseStock.TX.STATE_EDIT_EMPTY_BROKEN_OR_LOST"), MedStockTransactionTools.STATE_EDIT_EMPTY_BROKEN_OR_LOST); OPDE.important(SYSTools .xx("nursingrecords.prescription.dlgCloseStock.LOG.STATE_EDIT_EMPTY_BROKEN_OR_LOST")); } else if (rbAbgelaufen.isSelected()) { MedStockTools.close(em, myStock, SYSTools.xx( "nursingrecords.prescription.dlgCloseStock.TX.STATE_EDIT_EMPTY_PAST_EXPIRY"), MedStockTransactionTools.STATE_EDIT_EMPTY_PAST_EXPIRY); OPDE.important(SYSTools .xx("nursingrecords.prescription.dlgCloseStock.LOG.STATE_EDIT_EMPTY_PAST_EXPIRY")); } else { MedStockTools.close(em, myStock, SYSTools.xx("nursingrecords.prescription.dlgCloseStock.TX.STATE_EDIT_EMPTY_NOW"), MedStockTransactionTools.STATE_EDIT_EMPTY_NOW); OPDE.important( SYSTools.xx("nursingrecords.prescription.dlgCloseStock.LOG.STATE_EDIT_EMPTY_NOW")); } } em.getTransaction().commit(); medStock = myStock; } catch (javax.persistence.OptimisticLockException 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(); } dispose(); }
From source file:op.care.prescription.PnlPrescription.java
private CollapsiblePane createCP4(final Prescription prescription) { /***//from w w w.j a v a2s .com * _ ____ ____ _ _ ______ _ _ _ __ * ___ _ __ ___ __ _| |_ ___ / ___| _ \| || | / / _ \ _ __ ___ ___ ___ _ __(_)_ __ | |_(_) ___ _ __\ \ * / __| '__/ _ \/ _` | __/ _ \ | | |_) | || |_| || |_) | '__/ _ \/ __|/ __| '__| | '_ \| __| |/ _ \| '_ \| | * | (__| | | __/ (_| | || __/ |___| __/|__ _| || __/| | | __/\__ \ (__| | | | |_) | |_| | (_) | | | | | * \___|_| \___|\__,_|\__\___|\____|_| |_| | ||_| |_| \___||___/\___|_| |_| .__/ \__|_|\___/|_| |_| | * \_\ |_| /_/ */ final String key = prescription.getID() + ".xprescription"; if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try { cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } final CollapsiblePane cpPres = cpMap.get(key); String title = "<html><table border=\"0\">" + "<tr valign=\"top\">" + "<td width=\"280\" align=\"left\">" + prescription.getPITAsHTML() + "</td>" + "<td width=\"380\" align=\"left\">" + "<font size=+1>" + PrescriptionTools.getShortDescription(prescription) + "</font>" + PrescriptionTools.getDoseAsHTML(prescription) + PrescriptionTools.getInventoryInformationAsHTML(prescription) + "</td>" + "<td width=\"200\" align=\"left\">" + PrescriptionTools.getOriginalPrescription(prescription) + PrescriptionTools.getRemark(prescription) + "</td>"; if (!prescription.getCommontags().isEmpty()) { title += "<tr>" + " <td colspan=\"3\">" + CommontagsTools.getAsHTML(prescription.getCommontags(), SYSConst.html_16x16_tagPurple_internal) + "</td>" + " </tr>"; } if (PrescriptionTools.isAnnotationNecessary(prescription)) { title += "<tr>" + " <td colspan=\"3\">" + PrescriptionTools.getAnnontationsAsHTML(prescription) + "</td>" + " </tr>"; } title += "</table>" + "</html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, null); cpPres.setCollapsible(false); cptitle.getButton().setIcon(getIcon(prescription)); cpPres.setTitleLabelComponent(cptitle.getMain()); cpPres.setSlidingDirection(SwingConstants.SOUTH); if (!prescription.getAttachedFilesConnections().isEmpty()) { /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = new JButton( Integer.toString(prescription.getAttachedFilesConnections().size()), SYSConst.icon22greenStar); btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip")); btnFiles.setForeground(Color.BLUE); btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER); btnFiles.setFont(SYSConst.ARIAL18BOLD); btnFiles.setPressedIcon(SYSConst.icon22Pressed); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.setAlignmentY(Component.TOP_ALIGNMENT); btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnFiles.setContentAreaFilled(false); btnFiles.setBorder(null); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { // checked for acls Closure fileHandleClosure = OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID) ? null : new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final Prescription myPrescription = em.find(Prescription.class, prescription.getID()); em.close(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); GUITools.flashBackground(myCP, Color.YELLOW, 2); } }; new DlgFiles(prescription, fileHandleClosure); } }); btnFiles.setEnabled(OPDE.isFTPworking()); cptitle.getRight().add(btnFiles); } if (!prescription.getAttachedProcessConnections().isEmpty()) { /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = new JButton( Integer.toString(prescription.getAttachedProcessConnections().size()), SYSConst.icon22redStar); btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip")); btnProcess.setForeground(Color.YELLOW); btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER); btnProcess.setFont(SYSConst.ARIAL18BOLD); btnProcess.setPressedIcon(SYSConst.icon22Pressed); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.setAlignmentY(Component.TOP_ALIGNMENT); btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnProcess.setContentAreaFilled(false); btnProcess.setBorder(null); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(prescription, new Closure() { @Override public void execute(Object o) { if (o == null) { return; } Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o; ArrayList<QProcess> assigned = result.getFirst(); ArrayList<QProcess> unassigned = result.getSecond(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); Prescription myPrescription = em.merge(prescription); em.lock(myPrescription, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSPRE2PROCESS> attached = new ArrayList<SYSPRE2PROCESS>( prescription.getAttachedProcessConnections()); for (SYSPRE2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections().remove(linkObject); linkObject.getPrescription().getAttachedProcessConnections() .remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + myPrescription.getTitle() + " ID: " + myPrescription.getID(), PReportTools.PREPORT_TYPE_REMOVE_ELEMENT, linkObject.getQProcess())); em.remove(linkObject); } } attached.clear(); for (QProcess qProcess : assigned) { List<QProcessElement> listElements = qProcess.getElements(); if (!listElements.contains(myPrescription)) { QProcess myQProcess = em.merge(qProcess); SYSPRE2PROCESS myLinkObject = em .merge(new SYSPRE2PROCESS(myQProcess, myPrescription)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + myPrescription.getTitle() + " ID: " + myPrescription.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedPrescriptionConnections().add(myLinkObject); myPrescription.getAttachedProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); GUITools.flashBackground(myCP, Color.YELLOW, 2); } 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 (RollbackException 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(); } } }); } }); // checked for acls btnProcess.setEnabled(OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)); cptitle.getRight().add(btnProcess); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(prescription); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); cptitle.getRight().add(btnMenu); cpPres.setHorizontalAlignment(SwingConstants.LEADING); cpPres.setOpaque(false); return cpPres; }
From source file:op.users.PnlUser.java
private CollapsiblePane createCP4(final Users user) { final String key = user.getUID() + ".xusers"; if (!cpMap.containsKey(key)) { cpMap.put(key, new CollapsiblePane()); try {/*from w ww .j a v a2s . co m*/ cpMap.get(key).setCollapsed(true); } catch (PropertyVetoException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } } final CollapsiblePane cp = cpMap.get(key); DefaultCPTitle cptitle = new DefaultCPTitle("<html><font size=+1>" + user.toString() + (UsersTools.isQualified(user) ? ", " + SYSTools.xx("opde.users.qualifiedNurse") : "") + "</font></html>", new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { cp.setCollapsed(!cp.isCollapsed()); } catch (PropertyVetoException pve) { // BAH! } } }); /*** * ____ _ ______ __ * / ___| |__ __ _ _ __ __ _ ___| _ \ \ / / * | | | '_ \ / _` | '_ \ / _` |/ _ \ |_) \ \ /\ / / * | |___| | | | (_| | | | | (_| | __/ __/ \ V V / * \____|_| |_|\__,_|_| |_|\__, |\___|_| \_/\_/ * |___/ */ final JButton btnChangePW = new JButton(SYSConst.icon22password); btnChangePW.setPressedIcon(SYSConst.icon22passwordPressed); btnChangePW.setAlignmentX(Component.RIGHT_ALIGNMENT); btnChangePW.setContentAreaFilled(false); btnChangePW.setBorder(null); btnChangePW.setToolTipText(SYSTools.xx("opde.users.btnChangePW.tooltip")); btnChangePW.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users myUser = em.merge(usermap.get(user.getUID())); String newpw = SYSTools.generatePassword(myUser.getVorname(), myUser.getName()); em.lock(myUser, LockModeType.OPTIMISTIC); myUser.setMd5pw(SYSTools.hashword(newpw)); em.getTransaction().commit(); lstUsers.remove(user); lstUsers.add(myUser); usermap.put(key, myUser); Collections.sort(lstUsers); SYSTools.printpw(newpw, myUser); OPDE.getDisplayManager().addSubMessage(new DisplayMessage(SYSTools.xx("opde.users.pwchanged"))); } catch (OptimisticLockException ole) { OPDE.warn(ole); if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); btnChangePW.setEnabled(user.isActive()); cptitle.getRight().add(btnChangePW); /*** * _ _ _ _ _ ___ _ _ * | |__ | |_ _ __ / \ ___| |_(_)_ _____|_ _|_ __ __ _ ___| |_(_)_ _____ * | '_ \| __| '_ \ / _ \ / __| __| \ \ / / _ \| || '_ \ / _` |/ __| __| \ \ / / _ \ * | |_) | |_| | | |/ ___ \ (__| |_| |\ V / __/| || | | | (_| | (__| |_| |\ V / __/ * |_.__/ \__|_| |_/_/ \_\___|\__|_| \_/ \___|___|_| |_|\__,_|\___|\__|_| \_/ \___| * */ final JButton btnActiveInactive = new JButton( user.isActive() ? SYSConst.icon22stop : SYSConst.icon22playerPlay); btnActiveInactive .setPressedIcon(user.isActive() ? SYSConst.icon22stopPressed : SYSConst.icon22playerPlayPressed); btnActiveInactive.setAlignmentX(Component.RIGHT_ALIGNMENT); btnActiveInactive.setContentAreaFilled(false); btnActiveInactive.setBorder(null); btnActiveInactive.setToolTipText(SYSTools .xx(internalClassID + (user.isActive() ? ".btnActiveInactive.stop" : ".btnActiveInactive.play"))); btnActiveInactive.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users myUser = em.merge(usermap.get(user.getUID())); em.lock(myUser, LockModeType.OPTIMISTIC); myUser.setStatus(myUser.isActive() ? UsersTools.STATUS_INACTIVE : UsersTools.STATUS_ACTIVE); em.getTransaction().commit(); lstUsers.remove(user); lstUsers.add(myUser); usermap.put(myUser.getUID(), myUser); Collections.sort(lstUsers); CollapsiblePane cp = createCP4(myUser); boolean wasCollapsed = cpMap.get(key).isCollapsed(); cpMap.put(key, cp); cp.setCollapsed(myUser.isActive() ? wasCollapsed : true); buildPanel(); } 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(); } } }); cptitle.getRight().add(btnActiveInactive); /*** * _ _ _ * ___ __| (_) |_ * / _ \/ _` | | __| * | __/ (_| | | |_ * \___|\__,_|_|\__| * */ final JButton btnEdit = new JButton(SYSConst.icon22edit3); btnEdit.setPressedIcon(SYSConst.icon22edit3Pressed); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.setContentAreaFilled(false); btnEdit.setBorder(null); btnEdit.setToolTipText(SYSTools.xx("opde.users.btnEdit")); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgUser(user, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Users myUser = em.merge((Users) o); em.lock(myUser, LockModeType.OPTIMISTIC); em.getTransaction().commit(); lstUsers.remove(user); lstUsers.add(myUser); usermap.put(myUser.getUID(), myUser); Collections.sort(lstUsers); CollapsiblePane cp = createCP4(myUser); boolean wasCollapsed = cpMap.get(key).isCollapsed(); cpMap.put(key, cp); cp.setCollapsed(myUser.isActive() ? wasCollapsed : true); buildPanel(); } 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(); } } } }); } }); cptitle.getRight().add(btnEdit); cp.setTitleLabelComponent(cptitle.getMain()); cp.setSlidingDirection(SwingConstants.SOUTH); /*** * ___ ___ _ _ _____ ___ _ _ _____ * / __/ _ \| \| |_ _| __| \| |_ _| * | (_| (_) | .` | | | | _|| .` | | | * \___\___/|_|\_| |_| |___|_|\_| |_| * */ cp.addCollapsiblePaneListener(new CollapsiblePaneAdapter() { @Override public void paneExpanded(CollapsiblePaneEvent collapsiblePaneEvent) { if (!contentMap.containsKey(key)) { contentMap.put(key, new PnlEditMemberships(user, lstGroups)); } cp.setContentPane(contentMap.get(key)); cp.setOpaque(false); } } ); cp.setBackground(UsersTools.getBG1(user)); cp.setCollapsible(user.isActive()); cp.setHorizontalAlignment(SwingConstants.LEADING); cp.setOpaque(false); return cp; }
From source file:org.key2gym.business.services.OrdersServiceBean.java
@Override public void addPayment(Integer orderId, BigDecimal amount) throws BusinessException, ValidationException, SecurityViolationException { /*/* w ww .jav a2s . c o m*/ * Checks the caller's roles. */ if (!callerHasAnyRole(SecurityRoles.JUNIOR_ADMINISTRATOR, SecurityRoles.SENIOR_ADMINISTRATOR, SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } if (amount == null) { throw new NullPointerException("The amount is null."); //NOI18N } OrderEntity order = em.find(OrderEntity.class, orderId, LockModeType.OPTIMISTIC); if (order == null) { throw new ValidationException(getString("Invalid.Order.ID")); } Boolean managerRoleRequired = (order.getAttendance() != null && !order.getAttendance().isOpen()) || !isToday(order.getDate()); if (managerRoleRequired && !callerHasRole(SecurityRoles.MANAGER)) { throw new SecurityViolationException(getString("Security.Operation.Denied")); } order.recordPayment(amount); /* * If the order is associted with a client, * transfers the money to or from the client's * account. */ if (order.getClient() != null) { Client client = order.getClient(); client.transfer(new scala.math.BigDecimal(amount)); } }
From source file:op.care.nursingprocess.PnlNursingProcess.java
private JPanel createNPPanel(final NursingProcess np) { /***//ww w. j a va 2 s. c o m * _ ____ ____ _ _ _ _ ____ * ___ _ __ ___ __ _| |_ ___ / ___| _ \| || | | \ | | _ \ * / __| '__/ _ \/ _` | __/ _ \ | | |_) | || |_ | \| | |_) | * | (__| | | __/ (_| | || __/ |___| __/|__ _| | |\ | __/ * \___|_| \___|\__,_|\__\___|\____|_| |_| |_| \_|_| * */ if (!contenPanelMap.containsKey(np)) { String title = "<html><table border=\"0\">"; if (!np.getCommontags().isEmpty()) { title += "<tr>" + " <td colspan=\"2\">" + CommontagsTools.getAsHTML(np.getCommontags(), SYSConst.html_16x16_tagPurple_internal) + "</td>" + " </tr>"; } title += "<tr valign=\"top\">" + "<td width=\"280\" align=\"left\">" + np.getPITAsHTML() + "</td>" + "<td width=\"500\" align=\"left\">" + (np.isClosed() ? "<s>" : "") + np.getContentAsHTML() + (np.isClosed() ? "</s>" : "") + "</td></tr>"; title += "</table>" + "</html>"; DefaultCPTitle cptitle = new DefaultCPTitle(title, null); cptitle.getButton().setVerticalTextPosition(SwingConstants.TOP); if (!np.getAttachedFilesConnections().isEmpty()) { /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = new JButton(Integer.toString(np.getAttachedFilesConnections().size()), SYSConst.icon22greenStar); btnFiles.setToolTipText(SYSTools.xx("misc.btnfiles.tooltip")); btnFiles.setForeground(Color.BLUE); btnFiles.setHorizontalTextPosition(SwingUtilities.CENTER); btnFiles.setFont(SYSConst.ARIAL18BOLD); btnFiles.setPressedIcon(SYSConst.icon22Pressed); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.setAlignmentY(Component.TOP_ALIGNMENT); btnFiles.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnFiles.setContentAreaFilled(false); btnFiles.setBorder(null); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Closure fileHandleClosure = np.isClosed() ? null : new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final NursingProcess myNP = em.find(NursingProcess.class, np.getID()); em.close(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); valuecache.get(myNP.getCategory()).add(myNP); Collections.sort(valuecache.get(myNP.getCategory())); createCP4(myNP.getCategory()); buildPanel(); } }; new DlgFiles(np, fileHandleClosure); } }); btnFiles.setEnabled(OPDE.isFTPworking()); cptitle.getRight().add(btnFiles); } if (!np.getAttachedQProcessConnections().isEmpty()) { /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = new JButton(Integer.toString(np.getAttachedQProcessConnections().size()), SYSConst.icon22redStar); btnProcess.setToolTipText(SYSTools.xx("misc.btnprocess.tooltip")); btnProcess.setForeground(Color.YELLOW); btnProcess.setHorizontalTextPosition(SwingUtilities.CENTER); btnProcess.setFont(SYSConst.ARIAL18BOLD); btnProcess.setPressedIcon(SYSConst.icon22Pressed); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.setAlignmentY(Component.TOP_ALIGNMENT); btnProcess.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnProcess.setContentAreaFilled(false); btnProcess.setBorder(null); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(np, new Closure() { @Override public void execute(Object o) { if (o == null) { return; } Pair<ArrayList<QProcess>, ArrayList<QProcess>> result = (Pair<ArrayList<QProcess>, ArrayList<QProcess>>) o; ArrayList<QProcess> assigned = result.getFirst(); ArrayList<QProcess> unassigned = result.getSecond(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NursingProcess myNP = em.merge(np); em.lock(myNP, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSNP2PROCESS> attached = new ArrayList<SYSNP2PROCESS>( myNP.getAttachedQProcessConnections()); for (SYSNP2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections() .remove(linkObject); linkObject.getNursingProcess().getAttachedQProcessConnections() .remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + myNP.getTitle() + " ID: " + myNP.getID(), PReportTools.PREPORT_TYPE_REMOVE_ELEMENT, linkObject.getQProcess())); em.remove(linkObject); } } attached.clear(); for (QProcess qProcess : assigned) { java.util.List<QProcessElement> listElements = qProcess.getElements(); if (!listElements.contains(myNP)) { QProcess myQProcess = em.merge(qProcess); SYSNP2PROCESS myLinkObject = em .merge(new SYSNP2PROCESS(myQProcess, myNP)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + myNP.getTitle() + " ID: " + myNP.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedNursingProcessesConnections().add(myLinkObject); myNP.getAttachedQProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); valuecache.get(myNP.getCategory()).add(myNP); Collections.sort(valuecache.get(myNP.getCategory())); createCP4(myNP.getCategory()); buildPanel(); } 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(); } else { reloadDisplay(); } } catch (RollbackException 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(); } } }); } }); btnProcess.setEnabled(OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)); cptitle.getRight().add(btnProcess); } if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.PRINT, internalClassID)) { /*** * _ _ ____ _ _ * | |__ | |_ _ __ | _ \ _ __(_)_ __ | |_ * | '_ \| __| '_ \| |_) | '__| | '_ \| __| * | |_) | |_| | | | __/| | | | | | | |_ * |_.__/ \__|_| |_|_| |_| |_|_| |_|\__| * */ JButton btnPrint = new JButton(SYSConst.icon22print2); btnPrint.setContentAreaFilled(false); btnPrint.setBorder(null); btnPrint.setPressedIcon(SYSConst.icon22print2Pressed); btnPrint.setAlignmentX(Component.RIGHT_ALIGNMENT); btnPrint.setAlignmentY(Component.TOP_ALIGNMENT); btnPrint.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { SYSFilesTools.print(NursingProcessTools.getAsHTML(np, true, true, true, true), true); } }); cptitle.getRight().add(btnPrint); // cptitle.getTitleButton().setVerticalTextPosition(SwingConstants.TOP); } /*** * __ __ * | \/ | ___ _ __ _ _ * | |\/| |/ _ \ '_ \| | | | * | | | | __/ | | | |_| | * |_| |_|\___|_| |_|\__,_| * */ final JButton btnMenu = new JButton(SYSConst.icon22menu); btnMenu.setPressedIcon(SYSConst.icon22Pressed); btnMenu.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMenu.setAlignmentY(Component.TOP_ALIGNMENT); btnMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); btnMenu.setContentAreaFilled(false); btnMenu.setBorder(null); btnMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JidePopup popup = new JidePopup(); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnMenu); popup.removeExcludedComponent(btnMenu); JPanel pnl = getMenu(np); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnMenu.setEnabled(!np.isClosed()); cptitle.getButton().setIcon(getIcon(np)); cptitle.getRight().add(btnMenu); cptitle.getMain().setBackground(getColor(np.getCategory())[SYSConst.light2]); cptitle.getMain().setOpaque(true); contenPanelMap.put(np, cptitle.getMain()); } return contenPanelMap.get(np); }