List of usage examples for javax.swing JPanel setPreferredSize
@BeanProperty(preferred = true, description = "The preferred size of the component.") public void setPreferredSize(Dimension preferredSize)
From source file:no.java.ems.client.swing.EmsClient.java
public void initLayout() { JPanel root = new JPanel(new BorderLayout()); root.add(new ApplicationHeader(), BorderLayout.NORTH); root.add(tabs, BorderLayout.CENTER); root.add(statusBar, BorderLayout.SOUTH); root.setPreferredSize(new Dimension(1200, 800)); FrameView view = getMainView();/*from w w w .j a v a 2 s . co m*/ view.setComponent(root); view.setMenuBar(createMenuBar()); show(view); }
From source file:op.care.nursingprocess.PnlNursingProcess.java
private JPanel getMenu(final NursingProcess np) { final JPanel pnlMenu = new JPanel(new VerticalLayout()); long numDFNs = DFNTools.getNumDFNs(np); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { /***/* ww w. j a va 2 s . c o m*/ * ____ _ * / ___| |__ __ _ _ __ __ _ ___ * | | | '_ \ / _` | '_ \ / _` |/ _ \ * | |___| | | | (_| | | | | (_| | __/ * \____|_| |_|\__,_|_| |_|\__, |\___| * |___/ */ JButton btnChange = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnchange.tooltip", SYSConst.icon22playerPlay, null); btnChange.setAlignmentX(Component.RIGHT_ALIGNMENT); btnChange.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { NursingProcess template = np.clone(); template.setTo(SYSConst.DATE_UNTIL_FURTHER_NOTICE); template.setUserOFF(null); template.setUserON(OPDE.getLogin().getUser()); template.setNextEval(new DateTime().plusWeeks(4).toDate()); new DlgNursingProcess(template, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); // Fetch the new Plan from the PAIR NursingProcess myNewNP = em.merge( ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o).getFirst()); NursingProcess myOldNP = em.merge(np); em.lock(myOldNP, LockModeType.OPTIMISTIC); // Close old NP myOldNP.setUserOFF(em.merge(OPDE.getLogin().getUser())); myOldNP.setTo(new DateTime().minusSeconds(1).toDate()); NPControl lastValidation = em .merge(new NPControl(myNewNP.getSituation(), myOldNP)); lastValidation.setLastValidation(true); myOldNP.getEvaluations().add(lastValidation); // Starts 1 second after the old one stopped myNewNP.setFrom(new DateTime(myOldNP.getTo()).plusSeconds(1).toDate()); // Create new DFNs according to plan DFNTools.generate(em, myNewNP.getInterventionSchedule(), new LocalDate(), true); em.getTransaction().commit(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); valuecache.get(myOldNP.getCategory()).add(myOldNP); valuecache.get(myNewNP.getCategory()).add(myNewNP); Collections.sort(valuecache.get(myNewNP.getCategory())); createCP4(myNewNP.getCategory()); boolean reloadSearch = false; for (Commontags ctag : myNewNP.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } buildPanel(); GUITools.flashBackground(contenPanelMap.get(myNewNP), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } // reloadTable(); } } }); } }); btnChange.setEnabled(!np.isClosed() && numDFNs != 0); pnlMenu.add(btnChange); /*** * ____ _ _ ____ _ * | __ ) _ _| |_| |_ ___ _ __ / ___|| |_ ___ _ __ * | _ \| | | | __| __/ _ \| '_ \ \___ \| __/ _ \| '_ \ * | |_) | |_| | |_| || (_) | | | | ___) | || (_) | |_) | * |____/ \__,_|\__|\__\___/|_| |_| |____/ \__\___/| .__/ * |_| */ final JButton btnStop = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnstop.tooltip", SYSConst.icon22stop, null); btnStop.setAlignmentX(Component.RIGHT_ALIGNMENT); btnStop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); JPanel dlg = new PnlEval(np, new Closure() { @Override public void execute(Object o) { if (o != null) { popup.hidePopup(); Pair<NursingProcess, String> result = (Pair<NursingProcess, String>) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NursingProcess myOldNP = em.merge(np); em.lock(myOldNP, LockModeType.OPTIMISTIC); myOldNP.setUserOFF(em.merge(OPDE.getLogin().getUser())); myOldNP.setTo(new Date()); NPControl lastValidation = em.merge(new NPControl(result.getSecond(), myOldNP)); lastValidation.setLastValidation(true); myOldNP.getEvaluations().add(lastValidation); em.getTransaction().commit(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); valuecache.get(myOldNP.getCategory()).add(myOldNP); Collections.sort(valuecache.get(myOldNP.getCategory())); createCP4(myOldNP.getCategory()); buildPanel(); // GUITools.flashBackground(contenPanelMap.get(myOldNP), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } OPDE.getDisplayManager() .addSubMessage(DisplayManager.getSuccessMessage(np.getTopic(), "closed")); reloadDisplay(); } } }, true); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.getContentPane().add(dlg); popup.setOwner(btnStop); popup.removeExcludedComponent(btnStop); popup.setDefaultFocusComponent(dlg); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnStop.setEnabled(!np.isClosed() && numDFNs != 0); pnlMenu.add(btnStop); /*** * ____ _ _ _____ _ _ _ * | __ ) _ _| |_| |_ ___ _ __ | ____|__| (_) |_ * | _ \| | | | __| __/ _ \| '_ \ | _| / _` | | __| * | |_) | |_| | |_| || (_) | | | | | |__| (_| | | |_ * |____/ \__,_|\__|\__\___/|_| |_| |_____\__,_|_|\__| * */ JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btnedit.tooltip", SYSConst.icon22edit, null); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgNursingProcess(np, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NursingProcess mynp = em.merge( ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o).getFirst()); em.lock(mynp, LockModeType.OPTIMISTIC); // Schedules to delete for (InterventionSchedule is : ((Pair<NursingProcess, ArrayList<InterventionSchedule>>) o) .getSecond()) { em.remove(em.merge(is)); } // No unused DFNs to delete Query delQuery = em.createQuery( "DELETE FROM DFN dfn WHERE dfn.nursingProcess = :nursingprocess "); delQuery.setParameter("nursingprocess", mynp); delQuery.executeUpdate(); // Create new DFNs according to plan DFNTools.generate(em, mynp.getInterventionSchedule(), new LocalDate(), true); em.getTransaction().commit(); boolean reloadSearch = false; for (Commontags ctag : mynp.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } // 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(); GUITools.flashBackground(contenPanelMap.get(mynp), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } // reloadTable(); } } }); } }); btnEdit.setEnabled(!np.isClosed() && numDFNs == 0); pnlMenu.add(btnEdit); } /*** * ____ _ _ ____ _ _ * | __ ) _ _| |_| |_ ___ _ __ | _ \ ___| | ___| |_ ___ * | _ \| | | | __| __/ _ \| '_ \ | | | |/ _ \ |/ _ \ __/ _ \ * | |_) | |_| | |_| || (_) | | | | | |_| | __/ | __/ || __/ * |____/ \__,_|\__|\__\___/|_| |_| |____/ \___|_|\___|\__\___| * */ if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { // => ACL_MATRIX JButton btnDelete = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btndelete.tooltip", SYSConst.icon22delete, null); btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/><b>" + np.getTopic() + "</b><br/>" + SYSTools.xx("misc.questions.delete2"), SYSConst.icon48delete, new Closure() { @Override public void execute(Object o) { if (o.equals(JOptionPane.YES_OPTION)) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NursingProcess myOldNP = em.merge(np); em.lock(myOldNP, LockModeType.OPTIMISTIC); // DFNs to delete Query delQuery = em.createQuery( "DELETE FROM DFN dfn WHERE dfn.nursingProcess = :nursingprocess "); delQuery.setParameter("nursingprocess", myOldNP); // delQuery.setParameter("status", DFNTools.STATE_OPEN); delQuery.executeUpdate(); em.remove(myOldNP); em.getTransaction().commit(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); createCP4(myOldNP.getCategory()); buildPanel(); OPDE.getDisplayManager().addSubMessage( DisplayManager.getSuccessMessage(np.getTopic(), "deleted")); } 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(); } } } }); } }); btnDelete.setEnabled(!np.isClosed() && numDFNs == 0); pnlMenu.add(btnDelete); } /*** * ____ _ _____ _ * | __ )| |_ _ __ | ____|_ ____ _| | * | _ \| __| '_ \| _| \ \ / / _` | | * | |_) | |_| | | | |___ \ V / (_| | | * |____/ \__|_| |_|_____| \_/ \__,_|_| * */ if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { final JButton btnEval = GUITools.createHyperlinkButton("nursingrecords.nursingprocess.btneval.tooltip", SYSConst.icon22redo, null); btnEval.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEval.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); JPanel dlg = new PnlEval(np, new Closure() { @Override public void execute(Object o) { if (o != null) { popup.hidePopup(); Pair<NursingProcess, String> result = (Pair<NursingProcess, String>) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NursingProcess evaluatedNP = em.merge(result.getFirst()); em.lock(evaluatedNP, LockModeType.OPTIMISTIC); NPControl newEvaluation = em .merge(new NPControl(result.getSecond(), evaluatedNP)); evaluatedNP.getEvaluations().add(newEvaluation); em.getTransaction().commit(); // Refresh Display valuecache.get(np.getCategory()).remove(np); contenPanelMap.remove(np); valuecache.get(evaluatedNP.getCategory()).add(evaluatedNP); Collections.sort(valuecache.get(evaluatedNP.getCategory())); createCP4(evaluatedNP.getCategory()); buildPanel(); GUITools.flashBackground(contenPanelMap.get(evaluatedNP), 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } OPDE.getDisplayManager().addSubMessage(new DisplayMessage( SYSTools.xx("nursingrecords.nursingprocess.success.neweval"))); reloadDisplay(); } } }, false); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.getContentPane().add(dlg); popup.setOwner(btnEval); popup.removeExcludedComponent(btnEval); popup.setDefaultFocusComponent(dlg); GUITools.showPopup(popup, SwingConstants.NORTH_WEST); } }); btnEval.setEnabled(!np.isClosed()); pnlMenu.add(btnEval); /*** * _ _ _____ _ ____ * | |__ | |_ _ _|_ _|/ \ / ___|___ * | '_ \| __| '_ \| | / _ \| | _/ __| * | |_) | |_| | | | |/ ___ \ |_| \__ \ * |_.__/ \__|_| |_|_/_/ \_\____|___/ * */ final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple, null); btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT); btnTAGs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); final JPanel pnl = new JPanel(new BorderLayout(5, 5)); final PnlCommonTags pnlCommonTags = new PnlCommonTags(np.getCommontags(), true, 3); pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER); JButton btnApply = new JButton(SYSConst.icon22apply); pnl.add(btnApply, BorderLayout.SOUTH); btnApply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NursingProcess myNP = em.merge(np); em.lock(myNP, LockModeType.OPTIMISTIC_FORCE_INCREMENT); myNP.getCommontags().clear(); for (Commontags commontag : pnlCommonTags.getListSelectedTags()) { myNP.getCommontags().add(em.merge(commontag)); } 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())); boolean reloadSearch = false; for (Commontags ctag : myNP.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } createCP4(myNP.getCategory()); buildPanel(); GUITools.flashBackground(contenPanelMap.get(myNP), Color.YELLOW, 2); } catch (OptimisticLockException ole) { OPDE.warn(ole); OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnTAGs); popup.removeExcludedComponent(btnTAGs); pnl.setPreferredSize(new Dimension(350, 150)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnTAGs.setEnabled(!np.isClosed()); pnlMenu.add(btnTAGs); pnlMenu.add(new JSeparator()); /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach, null); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); 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()); pnlMenu.add(btnFiles); /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip", SYSConst.icon22link, null); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); 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(!np.isClosed()); pnlMenu.add(btnProcess); } return pnlMenu; }
From source file:op.care.prescription.PnlPrescription.java
private JPanel getMenu(final Prescription prescription) { JPanel pnlMenu = new JPanel(new VerticalLayout()); long numBHPs = BHPTools.getConfirmedBHPs(prescription); final MedInventory inventory = prescription.shouldBeCalculated() ? TradeFormTools.getInventory4TradeForm(prescription.getResident(), prescription.getTradeForm()) : null;//from w ww. j a v a 2 s. c om final MedStock stockInUse = MedStockTools.getStockInUse(inventory); // checked for acls if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { /*** * ____ _ * / ___| |__ __ _ _ __ __ _ ___ * | | | '_ \ / _` | '_ \ / _` |/ _ \ * | |___| | | | (_| | | | | (_| | __/ * \____|_| |_|\__,_|_| |_|\__, |\___| * |___/ */ final JButton btnChange = GUITools.createHyperlinkButton( "nursingrecords.prescription.btnChange.tooltip", SYSConst.icon22playerPlay, null); btnChange.setAlignmentX(Component.RIGHT_ALIGNMENT); btnChange.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgRegular(prescription.clone(), DlgRegular.MODE_CHANGE, new Closure() { @Override public void execute(Object o) { if (o != null) { Pair<Prescription, java.util.List<PrescriptionSchedule>> returnPackage = (Pair<Prescription, List<PrescriptionSchedule>>) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); // Fetch the new prescription from the PAIR Prescription newPrescription = em.merge(returnPackage.getFirst()); Prescription oldPrescription = em.merge(prescription); em.lock(oldPrescription, LockModeType.OPTIMISTIC); // First close the old prescription DateTime now = new DateTime(); oldPrescription.setTo(now.toDate()); oldPrescription.setUserOFF(em.merge(OPDE.getLogin().getUser())); oldPrescription.setDocOFF(newPrescription.getDocON() == null ? null : em.merge(newPrescription.getDocON())); oldPrescription.setHospitalOFF(newPrescription.getHospitalON() == null ? null : em.merge(newPrescription.getHospitalON())); // the new prescription starts 1 second after the old one closes newPrescription.setFrom(now.plusSeconds(1).toDate()); // create new BHPs according to the prescription BHPTools.generate(em, newPrescription.getPrescriptionSchedule(), new LocalDate(), true); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(oldPrescription); lstPrescriptions.add(newPrescription); Collections.sort(lstPrescriptions); // Refresh Display createCP4(oldPrescription); final CollapsiblePane myNewCP = createCP4(newPrescription); buildPanel(); GUITools.flashBackground(myNewCP, 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } // buildPanel(); } } }); } }); btnChange.setEnabled(!prescription.isClosed() && !prescription.isOnDemand() && numBHPs != 0); pnlMenu.add(btnChange); /*** * ____ _ * / ___|| |_ ___ _ __ * \___ \| __/ _ \| '_ \ * ___) | || (_) | |_) | * |____/ \__\___/| .__/ * |_| */ final JButton btnStop = GUITools.createHyperlinkButton("nursingrecords.prescription.btnStop.tooltip", SYSConst.icon22playerStop, null); btnStop.setAlignmentX(Component.RIGHT_ALIGNMENT); btnStop.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgDiscontinue(prescription, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); Prescription myPrescription = (Prescription) em.merge(o); em.lock(myPrescription.getResident(), LockModeType.OPTIMISTIC); em.lock(myPrescription, LockModeType.OPTIMISTIC); myPrescription.setTo(new Date()); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GUITools.scroll2show(jspPrescription, myCP.getLocation().y - 100, new Closure() { @Override public void execute(Object o) { 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 (Exception e) { em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnStop.setEnabled(!prescription.isClosed()); // && numBHPs != 0 pnlMenu.add(btnStop); /*** * _____ _ _ _ * | ____|__| (_) |_ * | _| / _` | | __| * | |__| (_| | | |_ * |_____\__,_|_|\__/ * */ final JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.prescription.btnEdit.tooltip", SYSConst.icon22edit3, null); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { if (prescription.isOnDemand()) { new DlgOnDemand(prescription, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); Prescription myPrescription = em.merge((Prescription) o); em.lock(myPrescription, LockModeType.OPTIMISTIC); Query queryDELBHP = em.createQuery( "DELETE FROM BHP bhp WHERE bhp.prescription = :prescription"); queryDELBHP.setParameter("prescription", myPrescription); queryDELBHP.executeUpdate(); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myPrescription.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GUITools.scroll2show(jspPrescription, myCP.getLocation().y - 100, new Closure() { @Override public void execute(Object o) { 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } // buildPanel(); } } }); } else { new DlgRegular(prescription, DlgRegular.MODE_EDIT, new Closure() { @Override public void execute(Object o) { if (o != null) { Pair<Prescription, java.util.List<PrescriptionSchedule>> returnPackage = (Pair<Prescription, List<PrescriptionSchedule>>) o; EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); Prescription myPrescription = em.merge(returnPackage.getFirst()); em.lock(myPrescription, LockModeType.OPTIMISTIC); // delete whats not in the new prescription anymore for (PrescriptionSchedule schedule : returnPackage.getSecond()) { em.remove(em.merge(schedule)); } Query queryDELBHP = em.createQuery( "DELETE FROM BHP bhp WHERE bhp.prescription = :prescription"); queryDELBHP.setParameter("prescription", myPrescription); queryDELBHP.executeUpdate(); BHPTools.generate(em, myPrescription.getPrescriptionSchedule(), new LocalDate(), true); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myPrescription.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GUITools.scroll2show(jspPrescription, myCP.getLocation().y - 100, new Closure() { @Override public void execute(Object o) { 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } // buildPanel(); } } }); } } }); btnEdit.setEnabled(!prescription.isClosed() && numBHPs == 0); pnlMenu.add(btnEdit); /*** * _ _ _____ _ ____ * | |__ | |_ _ _|_ _|/ \ / ___|___ * | '_ \| __| '_ \| | / _ \| | _/ __| * | |_) | |_| | | | |/ ___ \ |_| \__ \ * |_.__/ \__|_| |_|_/_/ \_\____|___/ * */ final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple, null); btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT); btnTAGs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); final JPanel pnl = new JPanel(new BorderLayout(5, 5)); final PnlCommonTags pnlCommonTags = new PnlCommonTags(prescription.getCommontags(), true, 3); pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER); JButton btnApply = new JButton(SYSConst.icon22apply); pnl.add(btnApply, BorderLayout.SOUTH); btnApply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { 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); // merging is important, hence no addAll() for this one ArrayList<Commontags> listTags2Add = new ArrayList<Commontags>(); for (Commontags tag2add : pnlCommonTags.getListSelectedTags()) { listTags2Add.add(em.merge(tag2add)); } // Annotations need to be added, tooo // these are the remaining tags, that need to be disconnected myPrescription.getCommontags().addAll(listTags2Add); ArrayList<Commontags> listTags2Remove = new ArrayList<Commontags>( myPrescription.getCommontags()); listTags2Remove.removeAll(listTags2Add); myPrescription.getCommontags().removeAll(listTags2Remove); ArrayList<ResInfo> annotations2remove = new ArrayList<ResInfo>(); for (Commontags commontag : listTags2Remove) { for (ResInfo annotation : myPrescription.getAnnotations()) { if (CommontagsTools.getTagForAnnotation(annotation).equals(commontag)) { annotations2remove.add(annotation); em.remove(annotation); } } } myPrescription.getAnnotations().removeAll(annotations2remove); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myPrescription.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GUITools.scroll2show(jspPrescription, myCP.getLocation().y - 100, new Closure() { @Override public void execute(Object o) { GUITools.flashBackground(myCP, Color.YELLOW, 2); } }); } }); } catch (OptimisticLockException ole) { OPDE.warn(ole); OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); 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 (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnTAGs); popup.removeExcludedComponent(btnTAGs); pnl.setPreferredSize(new Dimension(350, 150)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnTAGs.setEnabled(!prescription.isClosed()); pnlMenu.add(btnTAGs); /*** * _ _ * __ _ _ __ _ __ ___ | |_ __ _| |_ ___ * / _` | '_ \| '_ \ / _ \| __/ _` | __/ _ \ * | (_| | | | | | | | (_) | || (_| | || __/ * \__,_|_| |_|_| |_|\___/ \__\__,_|\__\___| * */ final JButton btnAnnotation = GUITools.createHyperlinkButton( "nursingrecords.prescription.edit.annotations", SYSConst.icon22annotate, null); btnAnnotation.setAlignmentX(Component.RIGHT_ALIGNMENT); btnAnnotation.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { DlgAnnotations dlg = new DlgAnnotations(prescription, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); ResInfo annotation = em.merge((ResInfo) o); annotation.setHtml(ResInfoTools.getContentAsHTML(annotation)); Prescription myPrescription = em.merge(prescription); em.lock(myPrescription, LockModeType.OPTIMISTIC_FORCE_INCREMENT); myPrescription.getAnnotations().remove(annotation); // just in case, it was an EDIT rather than an ADD myPrescription.getAnnotations().add(annotation); em.lock(annotation, LockModeType.OPTIMISTIC); em.getTransaction().commit(); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); buildPanel(); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { GUITools.scroll2show(jspPrescription, myCP.getLocation().y - 100, new Closure() { @Override public void execute(Object o) { GUITools.flashBackground(myCP, Color.YELLOW, 2); } }); } }); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }); OPDE.debug(lstPrescriptions); dlg.setVisible(true); } }); btnAnnotation.setEnabled(!prescription.isClosed() && prescription.hasMed() && PrescriptionTools.isAnnotationNecessary(prescription)); pnlMenu.add(btnAnnotation); } // checked for acls if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.DELETE, internalClassID)) { /*** * ____ _ _ * | _ \ ___| | ___| |_ ___ * | | | |/ _ \ |/ _ \ __/ _ \ * | |_| | __/ | __/ || __/ * |____/ \___|_|\___|\__\___| * */ final JButton btnDelete = GUITools.createHyperlinkButton( "nursingrecords.prescription.btnDelete.tooltip", SYSConst.icon22delete, null); btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo(SYSTools.xx("misc.questions.delete1") + "<br/>" + PrescriptionTools.toPrettyString(prescription) + "</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(); Prescription myverordnung = em.merge(prescription); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); em.lock(myverordnung, LockModeType.OPTIMISTIC); em.remove(myverordnung); Query delQuery = em.createQuery( "DELETE FROM BHP b WHERE b.prescription = :prescription"); delQuery.setParameter("prescription", myverordnung); delQuery.executeUpdate(); em.getTransaction().commit(); OPDE.getDisplayManager().addSubMessage( new DisplayMessage(SYSTools.xx("misc.msg.Deleted") + ": " + PrescriptionTools.toPrettyString(myverordnung))); lstPrescriptions.remove(prescription); 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) { em.getTransaction().rollback(); OPDE.fatal(e); } finally { em.close(); } } } }); } }); btnDelete.setEnabled(numBHPs == 0 && !prescription.isClosed()); pnlMenu.add(btnDelete); } // checked for acls if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { pnlMenu.add(new JSeparator()); /*** * ____ _ _____ _ ____ _ * / ___| ___| |_| ____|_ ___ __ (_)_ __ _ _| _ \ __ _| |_ ___ * \___ \ / _ \ __| _| \ \/ / '_ \| | '__| | | | | | |/ _` | __/ _ \ * ___) | __/ |_| |___ > <| |_) | | | | |_| | |_| | (_| | || __/ * |____/ \___|\__|_____/_/\_\ .__/|_|_| \__, |____/ \__,_|\__\___| * |_| |___/ */ final JButton btnExpiry = GUITools.createHyperlinkButton( "nursingrecords.inventory.tooltip.btnSetExpiry", SYSConst.icon22gotoEnd, null); btnExpiry.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); popup.setMovable(false); PnlExpiry pnlExpiry = new PnlExpiry(stockInUse.getExpires(), SYSTools.xx("nursingrecords.inventory.pnlExpiry.title") + ": " + stockInUse.getID(), new Closure() { @Override public void execute(Object o) { popup.hidePopup(); EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedStock myStock = em.merge(stockInUse); em.lock(em.merge(myStock.getInventory().getResident()), LockModeType.OPTIMISTIC); em.lock(em.merge(myStock.getInventory()), LockModeType.OPTIMISTIC); myStock.setExpires((Date) o); em.getTransaction().commit(); createCP4(prescription); 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(); } } }); popup.setOwner(btnExpiry); popup.setContentPane(pnlExpiry); popup.removeExcludedComponent(pnlExpiry); popup.setDefaultFocusComponent(pnlExpiry); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnExpiry.setEnabled(inventory != null && stockInUse != null); pnlMenu.add(btnExpiry); /*** * ____ _ ____ _ _ * / ___| | ___ ___ ___/ ___|| |_ ___ ___| | __ * | | | |/ _ \/ __|/ _ \___ \| __/ _ \ / __| |/ / * | |___| | (_) \__ \ __/___) | || (_) | (__| < * \____|_|\___/|___/\___|____/ \__\___/ \___|_|\_\ * */ final JButton btnCloseStock = GUITools.createHyperlinkButton( "nursingrecords.inventory.stock.btnout.tooltip", SYSConst.icon22ledRedOn, null); btnCloseStock.setAlignmentX(Component.RIGHT_ALIGNMENT); btnCloseStock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgCloseStock(stockInUse, new Closure() { @Override public void execute(Object o) { if (o != null) { // The prescription itself is not changed, but the stock in question. // this information is requested by a single DB request every time // the CP is created for that particular prescription. // A new call to the createCP4 method will reuse the old // CollapsiblePane and set a new TextContent to it. // Now with the MedStock information. // If this current stock was valid until the end of package // it needs to be reread here. if (prescription.isUntilEndOfPackage()) { EntityManager em = OPDE.createEM(); Prescription myPrescription = em.merge(prescription); em.refresh(myPrescription); lstPrescriptions.remove(prescription); lstPrescriptions.add(myPrescription); Collections.sort(lstPrescriptions); final CollapsiblePane myCP = createCP4(myPrescription); } else { final CollapsiblePane myCP = createCP4(prescription); GUITools.flashBackground(myCP, Color.YELLOW, 2); } buildPanel(); } } }); } }); btnCloseStock.setEnabled(inventory != null && stockInUse != null && !stockInUse.isToBeClosedSoon()); pnlMenu.add(btnCloseStock); /*** * ___ ____ _ _ * / _ \ _ __ ___ _ __ / ___|| |_ ___ ___| | __ * | | | | '_ \ / _ \ '_ \\___ \| __/ _ \ / __| |/ / * | |_| | |_) | __/ | | |___) | || (_) | (__| < * \___/| .__/ \___|_| |_|____/ \__\___/ \___|_|\_\ * |_| */ final JButton btnOpenStock = GUITools.createHyperlinkButton( "nursingrecords.inventory.stock.btnopen.tooltip", SYSConst.icon22ledGreenOn, null); btnOpenStock.setAlignmentX(Component.RIGHT_ALIGNMENT); btnOpenStock.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgOpenStock(prescription.getTradeForm(), resident, new Closure() { @Override public void execute(Object o) { if (o != null) { final CollapsiblePane myCP = createCP4(prescription); GUITools.flashBackground(myCP, Color.YELLOW, 2); } } }); } }); btnOpenStock.setEnabled(inventory != null && stockInUse == null && !prescription.isClosed()); pnlMenu.add(btnOpenStock); /*** * ____ _ _ _____ __ __ _ * / ___|(_) __| | ___| ____|/ _|/ _| ___ ___| |_ ___ * \___ \| |/ _` |/ _ \ _| | |_| |_ / _ \/ __| __/ __| * ___) | | (_| | __/ |___| _| _| __/ (__| |_\__ \ * |____/|_|\__,_|\___|_____|_| |_| \___|\___|\__|___/ * */ final JButton btnEditSideEffects = GUITools.createHyperlinkButton( "nursingrecords.prescription.edit.sideeffects", SYSConst.icon22sideeffects, null); btnEditSideEffects.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEditSideEffects.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo(SYSConst.icon48sideeffects, new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); MedProducts myProduct = em.merge(prescription.getTradeForm().getMedProduct()); myProduct.setSideEffects(o.toString().trim()); 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(); reload(); } catch (Exception e) { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); } OPDE.fatal(e); } finally { em.close(); } } } }, "nursingrecords.prescription.edit.sideeffects", prescription.getTradeForm().getMedProduct().getSideEffects(), null); } }); // checked for acls btnEditSideEffects.setEnabled(prescription.hasMed() && OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, "opde.medication")); pnlMenu.add(btnEditSideEffects); pnlMenu.add(new JSeparator()); /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach, null); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Closure closure = null; if (!prescription.isClosed()) { closure = 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); } }; } btnFiles.setEnabled(OPDE.isFTPworking()); new DlgFiles(prescription, closure); } }); pnlMenu.add(btnFiles); /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip", SYSConst.icon22link, null); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); 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(); } } }); } }); btnProcess.setEnabled(!prescription.isClosed()); // if (!prescription.getAttachedProcessConnections().isEmpty()) { // JLabel lblNum = new JLabel(Integer.toString(prescription.getAttachedProcessConnections().size()), SYSConst.icon16redStar, SwingConstants.CENTER); // lblNum.setFont(SYSConst.ARIAL10BOLD); // lblNum.setForeground(Color.YELLOW); // lblNum.setHorizontalTextPosition(SwingConstants.CENTER); // DefaultOverlayable overlayableBtn = new DefaultOverlayable(btnProcess, lblNum, DefaultOverlayable.SOUTH_EAST); // overlayableBtn.setOpaque(false); // pnlMenu.add(overlayableBtn); // } else { pnlMenu.add(btnProcess); // } } return pnlMenu; }
From source file:op.care.reports.PnlReport.java
private JPanel getMenu(final NReport nreport) { JPanel pnlMenu = new JPanel(new VerticalLayout()); if (OPDE.getAppInfo().isAllowedTo(InternalClassACL.UPDATE, internalClassID)) { /***/*from ww w . ja va 2 s.co m*/ * _____ _ _ _ * | ____|__| (_) |_ * | _| / _` | | __| * | |__| (_| | | |_ * |_____\__,_|_|\__| * */ final JButton btnEdit = GUITools.createHyperlinkButton("nursingrecords.reports.btnEdit.tooltip", SYSConst.icon22edit3, null); btnEdit.setAlignmentX(Component.RIGHT_ALIGNMENT); btnEdit.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgReport(nreport.clone(), new Closure() { @Override public void execute(Object o) { if (o != null) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport newReport = em.merge((NReport) o); NReport oldReport = em.merge(nreport); em.lock(oldReport, LockModeType.OPTIMISTIC); newReport.setReplacementFor(oldReport); for (SYSNR2FILE oldAssignment : oldReport.getAttachedFilesConnections()) { em.remove(oldAssignment); } oldReport.getAttachedFilesConnections().clear(); for (SYSNR2PROCESS oldAssignment : oldReport.getAttachedQProcessConnections()) { em.remove(oldAssignment); } oldReport.getAttachedQProcessConnections().clear(); oldReport.setEditedBy(em.merge(OPDE.getLogin().getUser())); oldReport.setEditDate(new Date()); oldReport.setReplacedBy(newReport); em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance() .format(newReport.getPit()); final String keyOldDay = DateFormat.getDateInstance() .format(oldReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); contentmap.remove(keyOldDay); } synchronized (linemap) { linemap.remove(oldReport); } synchronized (valuecache) { valuecache.get(keyOldDay).remove(nreport); valuecache.get(keyOldDay).add(oldReport); Collections.sort(valuecache.get(keyOldDay)); if (valuecache.containsKey(keyNewDay)) { valuecache.get(keyNewDay).add(newReport); Collections.sort(valuecache.get(keyNewDay)); } } synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : newReport.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } if (minmax.isAfter(new DateTime(newReport.getPit()))) { minmax.setStart(new DateTime(newReport.getPit())); } if (minmax.isBefore(new DateTime(newReport.getPit()))) { minmax.setEnd(new DateTime(newReport.getPit())); } createCP4Day(new LocalDate(oldReport.getPit())); createCP4Day(new LocalDate(newReport.getPit())); buildPanel(); GUITools.scroll2show(jspReports, cpMap.get(keyNewDay), cpsReports, new Closure() { @Override public void execute(Object o) { GUITools.flashBackground(linemap.get(newReport), 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(); } } } }); } }); btnEdit.setEnabled(NReportTools.isChangeable(nreport)); pnlMenu.add(btnEdit); /*** * ____ _ _ * | _ \ ___| | ___| |_ ___ * | | | |/ _ \ |/ _ \ __/ _ \ * | |_| | __/ | __/ || __/ * |____/ \___|_|\___|\__\___| * */ final JButton btnDelete = GUITools.createHyperlinkButton("nursingrecords.reports.btnDelete.tooltip", SYSConst.icon22delete, null); btnDelete.setAlignmentX(Component.RIGHT_ALIGNMENT); btnDelete.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgYesNo( SYSTools.xx("misc.questions.delete1") + "<br/><i>" + DateFormat.getDateTimeInstance(DateFormat.DEFAULT, DateFormat.SHORT).format( nreport.getPit()) + "</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(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport delReport = em.merge(nreport); em.lock(delReport, LockModeType.OPTIMISTIC); delReport.setDeletedBy(em.merge(OPDE.getLogin().getUser())); for (SYSNR2FILE oldAssignment : delReport .getAttachedFilesConnections()) { em.remove(oldAssignment); } delReport.getAttachedFilesConnections().clear(); for (SYSNR2PROCESS oldAssignment : delReport .getAttachedQProcessConnections()) { em.remove(oldAssignment); } delReport.getAttachedQProcessConnections().clear(); em.getTransaction().commit(); final String keyDay = DateFormat.getDateInstance() .format(delReport.getPit()); synchronized (contentmap) { contentmap.remove(keyDay); } synchronized (linemap) { linemap.remove(delReport); } synchronized (valuecache) { valuecache.get(keyDay).remove(nreport); valuecache.get(keyDay).add(delReport); Collections.sort(valuecache.get(keyDay)); } createCP4Day(new LocalDate(delReport.getPit())); buildPanel(); if (tbShowReplaced.isSelected()) { GUITools.flashBackground(linemap.get(delReport), 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(); } } } }); } }); btnDelete.setEnabled(NReportTools.isChangeable(nreport)); pnlMenu.add(btnDelete); /*** * _ _ _____ _ ____ * | |__ | |_ _ _|_ _|/ \ / ___|___ * | '_ \| __| '_ \| | / _ \| | _/ __| * | |_) | |_| | | | |/ ___ \ |_| \__ \ * |_.__/ \__|_| |_|_/_/ \_\____|___/ * */ final JButton btnTAGs = GUITools.createHyperlinkButton("misc.msg.editTags", SYSConst.icon22tagPurple, null); btnTAGs.setAlignmentX(Component.RIGHT_ALIGNMENT); btnTAGs.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JidePopup popup = new JidePopup(); final JPanel pnl = new JPanel(new BorderLayout(5, 5)); final PnlCommonTags pnlCommonTags = new PnlCommonTags(nreport.getCommontags(), true, 3); pnl.add(new JScrollPane(pnlCommonTags), BorderLayout.CENTER); JButton btnApply = new JButton(SYSConst.icon22apply); pnl.add(btnApply, BorderLayout.SOUTH); btnApply.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); final NReport myReport = em.merge(nreport); em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT); myReport.getCommontags().clear(); for (Commontags commontag : pnlCommonTags.getListSelectedTags()) { myReport.getCommontags().add(em.merge(commontag)); } em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } synchronized (listUsedCommontags) { boolean reloadSearch = false; for (Commontags ctag : myReport.getCommontags()) { if (!listUsedCommontags.contains(ctag)) { listUsedCommontags.add(ctag); reloadSearch = true; } } if (reloadSearch) { prepareSearchArea(); } } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } catch (OptimisticLockException ole) { OPDE.warn(ole); OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage()); 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(); } } }); popup.setMovable(false); popup.getContentPane().setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnTAGs); popup.removeExcludedComponent(btnTAGs); pnl.setPreferredSize(new Dimension(350, 150)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); GUITools.showPopup(popup, SwingConstants.WEST); } }); btnTAGs.setEnabled(NReportTools.isChangeable(nreport) && NReportTools.isMine(nreport)); pnlMenu.add(btnTAGs); /*** * _ _ __ __ _ _ * | |__ | |_ _ __ | \/ (_)_ __ _ _| |_ ___ ___ * | '_ \| __| '_ \| |\/| | | '_ \| | | | __/ _ \/ __| * | |_) | |_| | | | | | | | | | | |_| | || __/\__ \ * |_.__/ \__|_| |_|_| |_|_|_| |_|\__,_|\__\___||___/ * */ final JButton btnMinutes = GUITools.createHyperlinkButton("nursingrecords.reports.btnminutes.tooltip", SYSConst.icon22clock, null); btnMinutes.setAlignmentX(Component.RIGHT_ALIGNMENT); btnMinutes.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { final JPopupMenu menu = SYSCalendar.getMinutesMenu( new int[] { 1, 2, 3, 4, 5, 10, 15, 20, 30, 45, 60, 120, 240, 360 }, new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); try { em.getTransaction().begin(); em.lock(em.merge(resident), LockModeType.OPTIMISTIC); NReport myReport = em.merge(nreport); em.lock(myReport, LockModeType.OPTIMISTIC); myReport.setMinutes((Integer) o); myReport.setEditDate(new Date()); em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance() .format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); 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(); } } }); menu.show(btnMinutes, 0, btnMinutes.getHeight()); } }); btnMinutes.setEnabled(!nreport.isObsolete() && NReportTools.isMine(nreport)); pnlMenu.add(btnMinutes); pnlMenu.add(new JSeparator()); /*** * _ _ _____ _ _ * | |__ | |_ _ __ | ___(_) | ___ ___ * | '_ \| __| '_ \| |_ | | |/ _ \/ __| * | |_) | |_| | | | _| | | | __/\__ \ * |_.__/ \__|_| |_|_| |_|_|\___||___/ * */ final JButton btnFiles = GUITools.createHyperlinkButton("misc.btnfiles.tooltip", SYSConst.icon22attach, null); btnFiles.setAlignmentX(Component.RIGHT_ALIGNMENT); btnFiles.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Closure fileHandleClosure = nreport.isObsolete() ? null : new Closure() { @Override public void execute(Object o) { EntityManager em = OPDE.createEM(); final NReport myReport = em.find(NReport.class, nreport.getID()); em.close(); final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); GUITools.flashBackground(linemap.get(myReport), Color.YELLOW, 2); } }; new DlgFiles(nreport, fileHandleClosure); } }); btnFiles.setEnabled(OPDE.isFTPworking()); pnlMenu.add(btnFiles); /*** * _ _ ____ * | |__ | |_ _ __ | _ \ _ __ ___ ___ ___ ___ ___ * | '_ \| __| '_ \| |_) | '__/ _ \ / __/ _ \/ __/ __| * | |_) | |_| | | | __/| | | (_) | (_| __/\__ \__ \ * |_.__/ \__|_| |_|_| |_| \___/ \___\___||___/___/ * */ final JButton btnProcess = GUITools.createHyperlinkButton("misc.btnprocess.tooltip", SYSConst.icon22link, null); btnProcess.setAlignmentX(Component.RIGHT_ALIGNMENT); btnProcess.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { new DlgProcessAssign(nreport, 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); NReport myReport = em.merge(nreport); em.lock(myReport, LockModeType.OPTIMISTIC_FORCE_INCREMENT); ArrayList<SYSNR2PROCESS> attached = new ArrayList<SYSNR2PROCESS>( myReport.getAttachedQProcessConnections()); for (SYSNR2PROCESS linkObject : attached) { if (unassigned.contains(linkObject.getQProcess())) { linkObject.getQProcess().getAttachedNReportConnections().remove(linkObject); linkObject.getNReport().getAttachedQProcessConnections().remove(linkObject); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_REMOVE_ELEMENT) + ": " + nreport.getTitle() + " ID: " + nreport.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(myReport)) { QProcess myQProcess = em.merge(qProcess); SYSNR2PROCESS myLinkObject = em .merge(new SYSNR2PROCESS(myQProcess, myReport)); em.merge(new PReport( SYSTools.xx(PReportTools.PREPORT_TEXT_ASSIGN_ELEMENT) + ": " + nreport.getTitle() + " ID: " + nreport.getID(), PReportTools.PREPORT_TYPE_ASSIGN_ELEMENT, myQProcess)); qProcess.getAttachedNReportConnections().add(myLinkObject); myReport.getAttachedQProcessConnections().add(myLinkObject); } } em.getTransaction().commit(); final String keyNewDay = DateFormat.getDateInstance().format(myReport.getPit()); synchronized (contentmap) { contentmap.remove(keyNewDay); } synchronized (linemap) { linemap.remove(nreport); } synchronized (valuecache) { valuecache.get(keyNewDay).remove(nreport); valuecache.get(keyNewDay).add(myReport); Collections.sort(valuecache.get(keyNewDay)); } createCP4Day(new LocalDate(myReport.getPit())); buildPanel(); 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 (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(); } } }); } }); pnlMenu.add(btnProcess); } return pnlMenu; }
From source file:org.apache.jmeter.protocol.http.control.gui.WebServiceSamplerGui.java
private final JPanel createMessagePanel() { JPanel msgPanel = new JPanel(); msgPanel.setLayout(new BorderLayout(5, 0)); msgPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), JMeterUtils.getResString("webservice_message_soap"))); // $NON-NLS-1$ JPanel soapXmlPane = new JPanel(); soapXmlPane.setLayout(new BorderLayout(5, 0)); soapXmlPane.setBorder(BorderFactory.createTitledBorder(JMeterUtils.getResString("soap_data_title"))); // $NON-NLS-1$ soapXmlPane.setPreferredSize(new Dimension(4, 4)); // Permit dynamic resize of TextArea soapXml = new JTextArea(); soapXml.setLineWrap(true);//from w w w .ja v a 2s. c om soapXml.setWrapStyleWord(true); soapXml.setTabSize(4); // improve xml display soapXmlPane.add(new JScrollPane(soapXml), BorderLayout.CENTER); msgPanel.add(soapXmlPane, BorderLayout.CENTER); JPanel southPane = new JPanel(); southPane.setLayout(new BoxLayout(southPane, BoxLayout.Y_AXIS)); southPane.add(soapXmlFile); JPanel randomXmlPane = new JPanel(); randomXmlPane.setLayout(new BorderLayout(5, 0)); randomXmlPane.setBorder( BorderFactory.createTitledBorder(JMeterUtils.getResString("webservice_get_xml_from_random_title"))); // $NON-NLS-1$ randomXmlPane.add(randomXmlFile, BorderLayout.CENTER); southPane.add(randomXmlPane); msgPanel.add(southPane, BorderLayout.SOUTH); return msgPanel; }
From source file:org.bimserver.client.Client.java
public Client() { SwingUtil.setLookAndFeelToNice();//from w w w . j av a 2s .c om try { setIconImage(ImageIO.read(getClass().getResource("logo_small.png"))); } catch (IOException e) { LOGGER.error("", e); } revisionPanel = new RevisionPanel(serviceHolder, this); revisionPanel.setMinimumSize(new Dimension(200, 150)); checkoutsPanel = new CheckoutsPanel(serviceHolder, this); checkoutsPanel.setMinimumSize(new Dimension(200, 150)); treePanel = new TreePanel(this, serviceHolder); JMenu auth = new JMenu("File"); JMenuItem changeAuth = new JMenuItem("(Re)connect"); changeAuth.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SettingsFrame settingsFrame = new SettingsFrame(Client.this); settingsFrame.setVisible(true); } }); auth.add(changeAuth); JMenuBar menuBar = new JMenuBar(); menuBar.add(auth); setJMenuBar(menuBar); setTitle(APP_NAME + " - Not connected"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JSplitPane right = new JSplitPane(JSplitPane.VERTICAL_SPLIT, revisionPanel, checkoutsPanel); JPanel topPanel = new JPanel(new BorderLayout()); topPanel.setPreferredSize(new Dimension(300, 300)); topPanel.add(treePanel, BorderLayout.WEST); topPanel.add(right, BorderLayout.CENTER); Console console = new Console(); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, console); getContentPane().add(splitPane, BorderLayout.CENTER); setVisible(true); ConsoleAppender.setLogHandler(console); setSize(640, 550); LOGGER.info("Application started"); }
From source file:org.broad.igv.hic.MainWindow.java
private void initComponents() { JPanel mainPanel = new JPanel(); JPanel toolbarPanel = new JPanel(); //======== this ======== Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); mainPanel.setLayout(new BorderLayout()); toolbarPanel.setBorder(null);/* w w w . j a v a2 s. c o m*/ toolbarPanel.setLayout(new GridLayout()); JPanel chrSelectionPanel = new JPanel(); chrSelectionPanel.setBorder(LineBorder.createGrayLineBorder()); chrSelectionPanel.setMinimumSize(new Dimension(130, 57)); chrSelectionPanel.setPreferredSize(new Dimension(130, 57)); chrSelectionPanel.setLayout(new BorderLayout()); JPanel panel10 = new JPanel(); panel10.setBackground(new Color(204, 204, 204)); panel10.setLayout(new BorderLayout()); JLabel label3 = new JLabel(); label3.setText("Chromosomes"); label3.setHorizontalAlignment(SwingConstants.CENTER); panel10.add(label3, BorderLayout.CENTER); chrSelectionPanel.add(panel10, BorderLayout.PAGE_START); JPanel panel9 = new JPanel(); panel9.setBackground(new Color(238, 238, 238)); panel9.setLayout(new BoxLayout(panel9, BoxLayout.X_AXIS)); //---- chrBox1 ---- chrBox1 = new JComboBox(); chrBox1.setModel(new DefaultComboBoxModel(new String[] { "All" })); chrBox1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chrBox1ActionPerformed(e); } }); panel9.add(chrBox1); //---- chrBox2 ---- chrBox2 = new JComboBox(); chrBox2.setModel(new DefaultComboBoxModel(new String[] { "All" })); chrBox2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { chrBox2ActionPerformed(e); } }); panel9.add(chrBox2); //---- refreshButton ---- JideButton refreshButton = new JideButton(); refreshButton .setIcon(new ImageIcon(getClass().getResource("/toolbarButtonGraphics/general/Refresh24.gif"))); refreshButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { refreshButtonActionPerformed(e); } }); panel9.add(refreshButton); chrSelectionPanel.add(panel9, BorderLayout.CENTER); toolbarPanel.add(chrSelectionPanel); //======== displayOptionPanel ======== JPanel displayOptionPanel = new JPanel(); JPanel panel1 = new JPanel(); displayOptionComboBox = new JComboBox(); displayOptionPanel.setBackground(new Color(238, 238, 238)); displayOptionPanel.setBorder(LineBorder.createGrayLineBorder()); displayOptionPanel.setLayout(new BorderLayout()); //======== panel14 ======== JPanel panel14 = new JPanel(); panel14.setBackground(new Color(204, 204, 204)); panel14.setLayout(new BorderLayout()); //---- label4 ---- JLabel label4 = new JLabel(); label4.setText("Show"); label4.setHorizontalAlignment(SwingConstants.CENTER); panel14.add(label4, BorderLayout.CENTER); displayOptionPanel.add(panel14, BorderLayout.PAGE_START); //======== panel1 ======== panel1.setBorder(new EmptyBorder(0, 10, 0, 10)); panel1.setLayout(new GridLayout(1, 0, 20, 0)); //---- comboBox1 ---- displayOptionComboBox .setModel(new DefaultComboBoxModel(new String[] { DisplayOption.OBSERVED.toString() })); displayOptionComboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { displayOptionComboBoxActionPerformed(e); } }); panel1.add(displayOptionComboBox); displayOptionPanel.add(panel1, BorderLayout.CENTER); toolbarPanel.add(displayOptionPanel); //======== colorRangePanel ======== JPanel colorRangePanel = new JPanel(); JLabel colorRangeLabel = new JLabel(); colorRangeSlider = new RangeSlider(); colorRangePanel.setBorder(LineBorder.createGrayLineBorder()); colorRangePanel.setMinimumSize(new Dimension(96, 70)); colorRangePanel.setPreferredSize(new Dimension(202, 70)); colorRangePanel.setMaximumSize(new Dimension(32769, 70)); colorRangePanel.setLayout(new BorderLayout()); //======== panel11 ======== JPanel colorLabelPanel = new JPanel(); colorLabelPanel.setBackground(new Color(204, 204, 204)); colorLabelPanel.setLayout(new BorderLayout()); //---- colorRangeLabel ---- colorRangeLabel.setText("Color Range"); colorRangeLabel.setHorizontalAlignment(SwingConstants.CENTER); colorRangeLabel.setToolTipText("Range of color scale in counts per mega-base squared."); colorRangeLabel.setHorizontalTextPosition(SwingConstants.CENTER); colorRangeLabel.addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (e.isPopupTrigger()) { ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider); rangeDialog.setVisible(true); } } @Override public void mouseClicked(MouseEvent e) { ColorRangeDialog rangeDialog = new ColorRangeDialog(MainWindow.this, colorRangeSlider); rangeDialog.setVisible(true); } }); colorLabelPanel.add(colorRangeLabel, BorderLayout.CENTER); colorRangePanel.add(colorLabelPanel, BorderLayout.PAGE_START); //---- colorRangeSlider ---- colorRangeSlider.setPaintTicks(true); colorRangeSlider.setPaintLabels(true); colorRangeSlider.setLowerValue(0); colorRangeSlider.setMajorTickSpacing(500); colorRangeSlider.setMaximumSize(new Dimension(32767, 52)); colorRangeSlider.setPreferredSize(new Dimension(200, 52)); colorRangeSlider.setMinimumSize(new Dimension(36, 52)); colorRangeSlider.setMaximum(2000); colorRangeSlider.setUpperValue(500); colorRangeSlider.setMinorTickSpacing(100); colorRangeSlider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { colorRangeSliderStateChanged(e); } }); colorRangePanel.add(colorRangeSlider, BorderLayout.PAGE_END); // JPanel colorRangeTextPanel = new JPanel(); // colorRangeTextPanel.setLayout(new FlowLayout()); // JTextField minField = new JTextField(); // minField.setPreferredSize(new Dimension(50, 15)); // colorRangeTextPanel.add(minField); // colorRangeTextPanel.add(new JLabel(" - ")); // JTextField maxField = new JTextField(); // maxField.setPreferredSize(new Dimension(50, 15)); // colorRangeTextPanel.add(maxField); // colorRangeTextPanel.setPreferredSize(new Dimension(200, 52)); // colorRangePanel.add(colorRangeTextPanel, BorderLayout.PAGE_END); toolbarPanel.add(colorRangePanel); //======== resolutionPanel ======== JLabel resolutionLabel = new JLabel(); JPanel resolutionPanel = new JPanel(); resolutionPanel.setBorder(LineBorder.createGrayLineBorder()); resolutionPanel.setLayout(new BorderLayout()); //======== panel12 ======== JPanel panel12 = new JPanel(); panel12.setBackground(new Color(204, 204, 204)); panel12.setLayout(new BorderLayout()); //---- resolutionLabel ---- resolutionLabel.setText("Resolution"); resolutionLabel.setHorizontalAlignment(SwingConstants.CENTER); resolutionLabel.setBackground(new Color(204, 204, 204)); panel12.add(resolutionLabel, BorderLayout.CENTER); resolutionPanel.add(panel12, BorderLayout.PAGE_START); //======== panel2 ======== JPanel panel2 = new JPanel(); panel2.setLayout(new BoxLayout(panel2, BoxLayout.X_AXIS)); //---- resolutionSlider ---- resolutionSlider = new JSlider(); resolutionSlider.setMaximum(8); resolutionSlider.setMajorTickSpacing(1); resolutionSlider.setPaintTicks(true); resolutionSlider.setSnapToTicks(true); resolutionSlider.setPaintLabels(true); resolutionSlider.setMinorTickSpacing(1); Dictionary<Integer, JLabel> resolutionLabels = new Hashtable<Integer, JLabel>(); Font f = FontManager.getFont(8); for (int i = 0; i < HiCGlobals.zoomLabels.length; i++) { if ((i + 1) % 2 == 0) { final JLabel tickLabel = new JLabel(HiCGlobals.zoomLabels[i]); tickLabel.setFont(f); resolutionLabels.put(i, tickLabel); } } resolutionSlider.setLabelTable(resolutionLabels); // Setting the zoom should always be done by calling resolutionSlider.setValue() so work isn't done twice. resolutionSlider.addChangeListener(new ChangeListener() { // Change zoom level while staying centered on current location. // Centering is relative to the bounds of the data, which might not be the bounds of the window public void stateChanged(ChangeEvent e) { if (!resolutionSlider.getValueIsAdjusting()) { int idx = resolutionSlider.getValue(); idx = Math.max(0, Math.min(idx, MAX_ZOOM)); if (hic.zd != null && idx == hic.zd.getZoom()) { // Nothing to do return; } if (hic.xContext != null) { int centerLocationX = (int) hic.xContext .getChromosomePosition(getHeatmapPanel().getWidth() / 2); int centerLocationY = (int) hic.yContext .getChromosomePosition(getHeatmapPanel().getHeight() / 2); hic.setZoom(idx, centerLocationX, centerLocationY, false); } //zoomInButton.setEnabled(newZoom < MAX_ZOOM); //zoomOutButton.setEnabled(newZoom > 0); } } }); panel2.add(resolutionSlider); resolutionPanel.add(panel2, BorderLayout.CENTER); toolbarPanel.add(resolutionPanel); mainPanel.add(toolbarPanel, BorderLayout.NORTH); //======== hiCPanel ======== final JPanel hiCPanel = new JPanel(); hiCPanel.setLayout(new HiCLayout()); //---- rulerPanel2 ---- rulerPanel2 = new HiCRulerPanel(hic); rulerPanel2.setMaximumSize(new Dimension(4000, 50)); rulerPanel2.setMinimumSize(new Dimension(1, 50)); rulerPanel2.setPreferredSize(new Dimension(1, 50)); rulerPanel2.setBorder(null); JPanel panel2_5 = new JPanel(); panel2_5.setLayout(new BorderLayout()); panel2_5.add(rulerPanel2, BorderLayout.SOUTH); trackPanel = new TrackPanel(hic); trackPanel.setMaximumSize(new Dimension(4000, 50)); trackPanel.setPreferredSize(new Dimension(1, 50)); trackPanel.setMinimumSize(new Dimension(1, 50)); trackPanel.setBorder(null); // trackPanelScrollpane = new JScrollPane(); // trackPanelScrollpane.getViewport().add(trackPanel); // trackPanelScrollpane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); // trackPanelScrollpane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); // trackPanelScrollpane.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(102, 102, 102))); // trackPanelScrollpane.setBackground(new java.awt.Color(237, 237, 237)); // trackPanelScrollpane.setVisible(false); // panel2_5.add(trackPanelScrollpane, BorderLayout.NORTH); // trackPanel.setVisible(false); panel2_5.add(trackPanel, BorderLayout.NORTH); hiCPanel.add(panel2_5, BorderLayout.NORTH); //---- rulerPanel1 ---- rulerPanel1 = new HiCRulerPanel(hic); rulerPanel1.setMaximumSize(new Dimension(50, 4000)); rulerPanel1.setPreferredSize(new Dimension(50, 500)); rulerPanel1.setBorder(null); rulerPanel1.setMinimumSize(new Dimension(50, 1)); hiCPanel.add(rulerPanel1, BorderLayout.WEST); //---- heatmapPanel ---- heatmapPanel = new HeatmapPanel(this, hic); heatmapPanel.setBorder(LineBorder.createBlackLineBorder()); heatmapPanel.setMaximumSize(new Dimension(500, 500)); heatmapPanel.setMinimumSize(new Dimension(500, 500)); heatmapPanel.setPreferredSize(new Dimension(500, 500)); heatmapPanel.setBackground(new Color(238, 238, 238)); hiCPanel.add(heatmapPanel, BorderLayout.CENTER); //======== panel8 ======== JPanel rightSidePanel = new JPanel(); rightSidePanel.setMaximumSize(new Dimension(120, 100)); rightSidePanel.setBorder(new EmptyBorder(0, 10, 0, 0)); rightSidePanel.setLayout(null); //---- thumbnailPanel ---- thumbnailPanel = new ThumbnailPanel(this, hic); thumbnailPanel.setMaximumSize(new Dimension(100, 100)); thumbnailPanel.setMinimumSize(new Dimension(100, 100)); thumbnailPanel.setPreferredSize(new Dimension(100, 100)); thumbnailPanel.setBorder(LineBorder.createBlackLineBorder()); thumbnailPanel.setPreferredSize(new Dimension(100, 100)); thumbnailPanel.setBounds(new Rectangle(new Point(20, 0), thumbnailPanel.getPreferredSize())); rightSidePanel.add(thumbnailPanel); //======== xPlotPanel ======== xPlotPanel = new JPanel(); xPlotPanel.setPreferredSize(new Dimension(250, 100)); xPlotPanel.setLayout(null); rightSidePanel.add(xPlotPanel); xPlotPanel.setBounds(10, 100, xPlotPanel.getPreferredSize().width, 228); //======== yPlotPanel ======== yPlotPanel = new JPanel(); yPlotPanel.setPreferredSize(new Dimension(250, 100)); yPlotPanel.setLayout(null); rightSidePanel.add(yPlotPanel); yPlotPanel.setBounds(10, 328, yPlotPanel.getPreferredSize().width, 228); // compute preferred size Dimension preferredSize = new Dimension(); for (int i = 0; i < rightSidePanel.getComponentCount(); i++) { Rectangle bounds = rightSidePanel.getComponent(i).getBounds(); preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width); preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height); } Insets insets = rightSidePanel.getInsets(); preferredSize.width += insets.right; preferredSize.height += insets.bottom; rightSidePanel.setMinimumSize(preferredSize); rightSidePanel.setPreferredSize(preferredSize); hiCPanel.add(rightSidePanel, BorderLayout.EAST); mainPanel.add(hiCPanel, BorderLayout.CENTER); contentPane.add(mainPanel, BorderLayout.CENTER); JMenuBar menuBar = createMenuBar(hiCPanel); contentPane.add(menuBar, BorderLayout.NORTH); // setup the glass pane to display a wait cursor when visible, and to grab all mouse events rootPane.getGlassPane().setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); rootPane.getGlassPane().addMouseListener(new MouseAdapter() { }); }
From source file:org.diyefi.openlogviewer.propertypanel.PropertiesPane.java
private JPanel createAcceptPanel() { final JPanel aPanel = new JPanel(); aPanel.setPreferredSize(new Dimension(500, 32)); aPanel.setLayout(new FlowLayout(FlowLayout.RIGHT, 2, 2)); final JButton ok = new JButton(labels.getString(Text.OK_BUTTON)); final JButton cancel = new JButton(labels.getString(Text.CANCEL_BUTTON)); ok.addActionListener(new ActionListener() { @Override//from w w w. ja va2s. c om public void actionPerformed(final ActionEvent e) { OpenLogViewer.getInstance().getPropertyPane().save(); OpenLogViewer.getInstance().getPropertyPane().setVisible(false); } }); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { OpenLogViewer.getInstance().getPropertyPane().resetProperties(); OpenLogViewer.getInstance().getPropertyPane().setVisible(false); } }); aPanel.add(cancel); aPanel.add(ok); return aPanel; }
From source file:org.docx4all.ui.main.WordMLEditor.java
JComponent createMainPanel() { _desktop = new JDesktopPane(); _desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE); _desktop.setBackground(Color.LIGHT_GRAY); JPanel toolbar = FxScriptUIHelper.getInstance().createToolBar(); JPanel panel = new JPanel(new BorderLayout()); panel.add(toolbar, BorderLayout.NORTH); panel.add(_desktop, BorderLayout.CENTER); panel.setBorder(new EmptyBorder(0, 2, 2, 2)); // top, left, bottom, right panel.setPreferredSize(new Dimension(640, 480)); return panel; }
From source file:org.eclipse.wb.internal.swing.utils.SwingScreenshotMaker.java
public SwingScreenshotMaker(AbstractComponentInfo rootModel, Component rootComponent) { m_root = rootModel;/*from w w w .j a v a 2 s .co m*/ SwingUtils.ensureQueueEmpty(); // fill images map with key m_componentImages.put(rootComponent, null); rootModel.accept(new ObjectInfoVisitor() { @Override public void endVisit(ObjectInfo objectInfo) throws Exception { if (objectInfo instanceof ComponentInfo) { m_componentImages.put(((ComponentInfo) objectInfo).getComponent(), null); } } }); // prepare component m_component = rootComponent; if (m_component instanceof Window) { m_window = (Window) m_component; } else { JFrame frame = new JFrame(); m_window = frame; // configure panel to have same size as given component JPanel panel; { panel = new JPanel(new BorderLayout()); panel.setPreferredSize(m_component.getSize()); frame.getContentPane().add(panel, BorderLayout.CENTER); } // add component if (m_component instanceof JInternalFrame) { JDesktopPane desktop = new JDesktopPane(); desktop.setLayout(new BorderLayout()); panel.add(desktop); desktop.add(m_component); m_component.setVisible(true); } else { panel.add(m_component); } frame.pack(); } }