private void createTable() {
   model = new ParametersTableModel();
   table = new JXTable(model);
   table.setSortable(false);
   // table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
   table.setRolloverEnabled(true);
   table.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));
 }
Ejemplo n.º 2
0
  public AttachmentsView(@Service ApplicationContext context, @Uses AttachmentsModel model) {
    setLayout(new BorderLayout());

    final ActionMap am = context.getActionMap(this);

    this.attachmentsModel = model;
    TableFormat tableFormat = new AttachmentsTableFormatter();
    tableModel = new EventJXTableModel<AttachmentDTO>(attachmentsModel.getEventList(), tableFormat);

    attachments = new JXTable(tableModel);

    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS));
    attachments.setFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        KeyboardFocusManager.getCurrentKeyboardFocusManager()
            .getDefaultFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS));

    attachments.getColumn(0).setPreferredWidth(20);
    attachments.getColumn(0).setMaxWidth(20);
    attachments.getColumn(0).setResizable(false);
    attachments.getColumn(2).setPreferredWidth(100);
    attachments.getColumn(2).setMaxWidth(100);
    attachments.getColumn(3).setPreferredWidth(100);
    attachments.getColumn(3).setMaxWidth(100);

    attachments.setAutoCreateColumnsFromModel(false);

    attachments.addHighlighter(HighlighterFactory.createAlternateStriping());

    attachments.setModel(tableModel);
    attachments.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    JPanel toolbar = new JPanel();
    StreamflowButton addButton = new StreamflowButton(am.get("add"));
    toolbar.add(addButton);
    StreamflowButton removeButton = new StreamflowButton(am.get("remove"));
    toolbar.add(removeButton);
    final StreamflowButton openButton = new StreamflowButton(am.get("open"));
    toolbar.add(openButton);
    attachments
        .getSelectionModel()
        .addListSelectionListener(new SelectionActionEnabler(am.get("open")));
    attachments
        .getSelectionModel()
        .addListSelectionListener(
            new SelectionActionEnabler(am.get("remove")) {

              @Override
              public boolean isSelectedValueValid(javax.swing.Action action) {
                return !attachments
                    .getValueAt(attachments.convertRowIndexToModel(attachments.getSelectedRow()), 0)
                    .equals(Icons.formSubmitted);
              }
            });

    attachmentsModel.addObserver(
        new RefreshComponents().visibleOn("createattachment", addButton, removeButton));

    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "open");
    attachments.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "remove");
    attachments.setActionMap(am);

    attachments.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent me) {
            int obj = attachments.getSelectedRow();
            if (obj == -1) return;
            if (me.getClickCount() == 2) {
              am.get("open")
                  .actionPerformed(
                      new ActionEvent(openButton, ActionEvent.ACTION_PERFORMED, "open"));
              me.consume();
            }
          }
        });

    attachments
        .getColumn(0)
        .setCellRenderer(
            new DefaultTableCellRenderer() {
              @Override
              public Component getTableCellRendererComponent(
                  JTable table,
                  Object value,
                  boolean isSelected,
                  boolean hasFocus,
                  int row,
                  int column) {

                JLabel iconLabel = new JLabel(" ");
                switch ((Icons) value) {
                  case attachments:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case conversations:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;

                  case formSubmitted:
                    iconLabel = new JLabel(i18n.icon((Icons) value, 11));
                    break;
                }

                iconLabel.setOpaque(true);

                if (isSelected) iconLabel.setBackground(attachments.getSelectionBackground());
                return iconLabel;
              }
            });

    JScrollPane attachmentsScrollPane = new JScrollPane(attachments);

    add(attachmentsScrollPane, BorderLayout.CENTER);
    add(toolbar, BorderLayout.SOUTH);

    new RefreshWhenShowing(this, attachmentsModel);
  }