TableToolbarDecorator(@NotNull JTable table, @Nullable final ElementProducer<?> producer) {
   myTable = table;
   myProducer = producer;
   myAddActionEnabled =
       myRemoveActionEnabled = myUpActionEnabled = myDownActionEnabled = isModelEditable();
   if (isModelEditable()) {
     createDefaultTableActions(producer);
   }
   myTable
       .getSelectionModel()
       .addListSelectionListener(
           new ListSelectionListener() {
             @Override
             public void valueChanged(ListSelectionEvent e) {
               updateButtons();
             }
           });
   myTable.addPropertyChangeListener(
       "enabled",
       new PropertyChangeListener() {
         @Override
         public void propertyChange(PropertyChangeEvent evt) {
           updateButtons();
         }
       });
 }
  /**
   * This method indicates whether changes to the model should cause the width to be dynamically
   * recalculated.
   *
   * @param isDynamicAdjustment Boolean value to determine if the width should be dynamically
   *     calculated
   */
  public void setDynamicAdjustment(boolean isDynamicAdjustment) {
    //  May need to add or remove the TableModelListener when changed

    if (this.isDynamicAdjustment != isDynamicAdjustment) {
      if (isDynamicAdjustment) {
        table.addPropertyChangeListener(this);
        table.getModel().addTableModelListener(this);
      } else {
        table.removePropertyChangeListener(this);
        table.getModel().removeTableModelListener(this);
      }
    }

    this.isDynamicAdjustment = isDynamicAdjustment;
  }
Пример #3
0
  public RowNumberTable(JTable table) {
    main = table;
    main.addPropertyChangeListener(this);
    main.getModel().addTableModelListener(this);

    setFocusable(false);
    setAutoCreateColumnsFromModel(false);
    setSelectionModel(main.getSelectionModel());

    TableColumn column = new TableColumn();
    column.setHeaderValue(" ");
    addColumn(column);
    column.setCellRenderer(new RowNumberRenderer());

    getColumnModel().getColumn(0).setPreferredWidth(50);
    setPreferredScrollableViewportSize(getPreferredSize());
  }
Пример #4
0
  /**
   * Initializes the layout of this pane.
   *
   * @return The container with all its widgets
   */
  protected void initializeLayout() {
    GridBagConstraints constraints = new GridBagConstraints();
    selectionModel = buildPropertySelectionModel();

    // Property table
    table =
        SwingComponentFactory.buildTable(
            this.buildPropertyTableAdapter(), this.buildTableColumnModel(), this.selectionModel);
    table.setAutoCreateColumnsFromModel(false);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    table.setAutoscrolls(true);
    table.setSurrendersFocusOnKeystroke(true);
    table.getTableHeader().setReorderingAllowed(false);
    table.addPropertyChangeListener("enabled", new PropertyChangeHandler());

    constraints.gridx = 0;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 3;
    constraints.weightx = 1;
    constraints.weighty = 1;
    constraints.fill = GridBagConstraints.BOTH;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = new Insets(0, 0, 0, 0);

    scrollPane = new JScrollPane(table);
    scrollPane.setMinimumSize(new Dimension(0, 0));
    scrollPane.setPreferredSize(new Dimension(0, 0));
    scrollPane.getViewport().setBackground(table.getBackground());

    add(scrollPane, constraints);

    // Add button
    addButton = buildButton("LOGIN_PROPERTY_ADD_BUTTON");
    addButton.addActionListener(buildAddActionListener());

    constraints.gridx = 1;
    constraints.gridy = 0;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = new Insets(0, 5, 0, 0);

    add(addButton, constraints);

    // Edit button
    editButton = buildButton("LOGIN_PROPERTY_EDIT_BUTTON");
    editButton.addActionListener(buildEditActionListener());
    editButton.setEnabled(false);

    constraints.gridx = 1;
    constraints.gridy = 1;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.CENTER;
    constraints.insets = new Insets(5, 5, 0, 0);

    add(editButton, constraints);
    buildEditButtonEnabler();

    // Remove button
    removeButton = buildButton("LOGIN_PROPERTY_REMOVE_BUTTON");
    removeButton.addActionListener(buildRemoveActionListener(selectionModel));
    removeButton.setEnabled(false);

    constraints.gridx = 1;
    constraints.gridy = 2;
    constraints.gridwidth = 1;
    constraints.gridheight = 1;
    constraints.weightx = 0;
    constraints.weighty = 0;
    constraints.fill = GridBagConstraints.HORIZONTAL;
    constraints.anchor = GridBagConstraints.PAGE_START;
    constraints.insets = new Insets(5, 5, 0, 0);

    add(removeButton, constraints);
    buildRemoveButtonEnabler();

    addHelpTopicId(this, "session.login.properties");
  }