public Component getDemoPanel() {
    TableModel model = new SampleTableModel();

    _sortableTable = new SortableTable(model);
    _sortableTable.setAutoResizeMode(JideTable.AUTO_RESIZE_FILL);
    _sortableTable.setNestedTableHeader(true);
    _sortableTable.setFillsGrids(false);
    TableColumnGroup longText =
        new TableColumnGroup(
            "This is a very long column header title. You can resize the table header column and see how this long text automatically wraps according to the column width. "
                + "The current configuration specified {minimum two rows:f:red} and {maximum five rows:f:blue}. You could take a look at StyledLabelBuilderDemo to see what other annotations are available in the text.@r:3:2:5");
    longText.add(_sortableTable.getColumnModel().getColumn(0));
    longText.add(_sortableTable.getColumnModel().getColumn(1));
    longText.add(_sortableTable.getColumnModel().getColumn(2));
    longText.add(_sortableTable.getColumnModel().getColumn(3));
    longText.add(_sortableTable.getColumnModel().getColumn(4));
    longText.add(_sortableTable.getColumnModel().getColumn(5));
    longText.add(_sortableTable.getColumnModel().getColumn(6));

    if (_sortableTable.getTableHeader() instanceof NestedTableHeader) {
      NestedTableHeader header = (NestedTableHeader) _sortableTable.getTableHeader();
      header.addColumnGroup(longText);
    }
    TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(_sortableTable);
    installer.addTableHeaderPopupMenuCustomizer(new TableColumnChooserPopupMenuCustomizer());

    TableUtils.autoResizeAllColumns(_sortableTable);

    return new JScrollPane(_sortableTable);
  }
예제 #2
0
  void loadRightTable(final LocalDate from, final LocalDate to) {

    if (listValues != null) {
      listValues.clear();
    }
    listValues =
        ResValueTools.getResValuesNoEdits(resident, ResValueTypesTools.LIQUIDBALANCE, from, to);

    Object[][] data = new Object[listValues.size()][5];
    int row = 0;
    for (ResValue val : listValues) {
      data[row][0] = df.format(val.getPit());
      data[row][1] = nf.format(val.getVal1());
      data[row][2] = val.getText();
      data[row][3] = SYSTools.anonymizeUser(val.getUser().getUID());
      data[row][4] = SYSConst.icon22delete;
      row++;
    }

    Object[] headers =
        new Object[] {
          SYSTools.xx("misc.msg.Date"),
          SYSTools.xx("misc.msg.amount"),
          SYSTools.xx("misc.msg.Text"),
          SYSTools.xx("misc.msg.user"),
          SYSTools.xx("misc.msg.delete")
        };

    final DefaultTableModel tmRight =
        new DefaultTableModel(data, headers) {
          @Override
          public boolean isCellEditable(int row, int column) {
            return column == 4; // only the del-button
          }
        };

    tmRight.setColumnCount(5);
    tblRight.setModel(tmRight);

    tblRight.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    DefaultTableCellRenderer rightRenderer = new DefaultTableCellRenderer();
    rightRenderer.setHorizontalAlignment(JLabel.RIGHT);
    tblRight.getColumnModel().getColumn(1).setCellRenderer(rightRenderer);

    TableUtils.autoResizeAllColumns(
        tblRight, null, new int[] {200, 200, 200, 200, 100}, true, false);
    TableUtils.autoResizeAllRows(tblRight);

    /**
     * * ____ _ _ | _ \ ___| | ___| |_ ___ | | | |/ _ \ |/ _ \ __/ _ \ | |_| | __/ | __/ || __/
     * |____/ \___|_|\___|\__\___|
     */
    ButtonColumn bc =
        new ButtonColumn(
            tblRight,
            new AbstractAction() {
              @Override
              public void actionPerformed(ActionEvent ae) {
                final int row = Integer.parseInt(ae.getActionCommand());
                final ResValue val2Delete = listValues.get(row);
                new DlgYesNo(
                    SYSTools.xx("misc.questions.delete1")
                        + "<br/><i>"
                        + "<br/><i>"
                        + df.format(val2Delete.getPit())
                        + "<br/>"
                        + nf.format(val2Delete.getVal1())
                        + " ml<br/>"
                        + val2Delete.getUser().toString()
                        + "</i><br/>"
                        + SYSTools.xx("misc.questions.delete2"),
                    SYSConst.icon48delete,
                    new Closure() {
                      @Override
                      public void execute(Object answer) {
                        if (answer.equals(JOptionPane.YES_OPTION)) {

                          EntityManager em = OPDE.createEM();
                          try {
                            em.getTransaction().begin();
                            ResValue myValue = em.merge(val2Delete);
                            em.lock(myValue, LockModeType.OPTIMISTIC);
                            myValue.setDeletedBy(em.merge(OPDE.getLogin().getUser()));
                            for (SYSVAL2FILE file : myValue.getAttachedFilesConnections()) {
                              em.remove(file);
                            }
                            myValue.getAttachedFilesConnections().clear();
                            for (SYSVAL2PROCESS connObj : myValue.getAttachedProcessConnections()) {
                              em.remove(connObj);
                            }
                            myValue.getAttachedProcessConnections().clear();
                            myValue.getAttachedProcesses().clear();
                            em.getTransaction().commit();
                            listValues.remove(row);
                            tmRight.removeRow(row);
                            loadLeftTable();
                          } catch (OptimisticLockException ole) {
                            OPDE.warn(ole);
                            if (em.getTransaction().isActive()) {
                              em.getTransaction().rollback();
                            }
                            if (ole.getMessage().indexOf("Class> entity.info.Resident") > -1) {
                              OPDE.getMainframe().emptyFrame();
                              OPDE.getMainframe().afterLogin();
                            }
                            OPDE.getDisplayManager().addSubMessage(DisplayManager.getLockMessage());
                          } catch (Exception e) {
                            if (em.getTransaction().isActive()) {
                              em.getTransaction().rollback();
                            }
                            OPDE.fatal(e);
                          } finally {
                            em.close();
                          }
                        }
                      }
                    });
              }
            },
            4);
    bc.setMnemonic(KeyEvent.VK_DELETE);
  }