javax.swing.event.TableModelListener Java Examples

The following examples show how to use javax.swing.event.TableModelListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TraceTreeTableModelAdapter.java    From pega-tracerviewer with Apache License 2.0 7 votes vote down vote up
public void setTraceTableModel(TraceTableModel traceTableModel) {

        this.traceTableModel = traceTableModel;
        this.traceTableModel.addTableModelListener(new TableModelListener() {

            @Override
            public void tableChanged(TableModelEvent tableModelEvent) {

                DefaultTreeTableTree defaultTreeTableTree = getTree();

                AbstractTreeTableTreeModel abstractTreeTableTreeModel;
                abstractTreeTableTreeModel = (AbstractTreeTableTreeModel) defaultTreeTableTree.getModel();

                // in case of search action, just refresh. reload causes
                // collapsing of tree.
                if (tableModelEvent instanceof SearchTableModelEvent) {
                    abstractTreeTableTreeModel.nodeChanged(getRoot());
                } else {
                    if (tableModelEvent.getType() == TableModelEvent.UPDATE) {
                        abstractTreeTableTreeModel.reload();
                    }
                }
            }
        });
    }
 
Example #2
Source File: DataTableModel.java    From meka with GNU General Public License v3.0 7 votes vote down vote up
/**
 * notfies all listener of the change of the model
 *
 * @param e the event to send to the listeners
 */
public void notifyListener(TableModelEvent e) {
	Iterator<TableModelListener> iter;
	TableModelListener l;

	// is notification enabled?
	if (!isNotificationEnabled()) {
		return;
	}

	iter = m_Listeners.iterator();
	while (iter.hasNext()) {
		l = iter.next();
		l.tableChanged(e);
	}
}
 
Example #3
Source File: CorrelationTableController.java    From OpenDA with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
    * Update the Correlation model Parameters Table.
    */
private void updateCorrelationModelParametersTable() {
	// Populate the correlation model parameters table.
	FunctionParameterTableModel parameterTableModel = new FunctionParameterTableModel(this.currentAutoCorrelationFunctionContext);

	this.parentController.getMainPanel().getAutoCorrelationParameterAndGraphPanel().getParametersTable()
	        .setModel(parameterTableModel);

	//setup cell editor.
   	TableColumn columnValue = parentController.getMainPanel().getAutoCorrelationParameterAndGraphPanel()
   	    .getParametersTable().getColumnModel().getColumn(FunctionParameterTableModel.COLUMN_VALUE);
   	columnValue.setCellEditor(new TextCellEditor());

	parameterTableModel.addTableModelListener(new TableModelListener() {
		public void tableChanged(TableModelEvent e) {
			updateCorrelationModelGraph();
		}
	});
}
 
Example #4
Source File: EventBroadcaster.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Fires multiple table model events, setting the inMultiEvent flag
 * as appropriate. */
private void fireTableChange (TableModelEvent[] e) {
    //Event may be null for offscreen info, etc.
    if (e == null || e.length==0) {
        return;
    }
    
    TableModelListener[] listeners = getTableModelListeners();
    inMultiEvent = e.length > 1;
    //System.err.println("fireTableChange("+Arrays.toString(e)+")");
    try {
        for (int i=0; i < e.length; i++) {
            if (i == e.length-1) {
                inMultiEvent = false;
            }
            fireTableChange (e[i], listeners);
        }
    } finally {
        inMultiEvent = false;
    }
}
 
Example #5
Source File: JtableUtils.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * Adding column is done by creating new model by modifying older one.<p>
 *
 * Insert new column if column is outside the <code>limit</code> Adds new
 * column if selected column inside the <code>limit</code>table@param _table
 * target table
 *
 * @param limit the range to avoid inserting
 */
static void addcol(JTable table, int limit) {
    try {
        int sc = table.getSelectedColumn();
        if (sc < limit - 1) {
            sc = table.getColumnCount() - 1;
        }

        DefaultTableModel tableM = (DefaultTableModel) table.getModel();
        DefaultTableModel tableM1 = new DefaultTableModel();
        TableModelListener[] listeners = tableM.getTableModelListeners();

        tableM1.setDataVector(newvectoraddcol(tableM.getDataVector(), sc), getColumnIdentifiersaddcol(sc + 1, table));
        table.setModel(tableM1);
        for (TableModelListener l : listeners) {
            tableM1.addTableModelListener(l);
        }

    } catch (Exception ex) {
        Logger.getLogger(JtableUtils.class.getName()).log(Level.SEVERE, null, ex);
    }

}
 
Example #6
Source File: ValueTableModel.java    From Digital with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void hasChanged() {
    SwingUtilities.invokeLater(() -> {
        TableModelEvent tme = new TableModelEvent(this);
        for (TableModelListener l : listeners)
            l.tableChanged(tme);
    });
}
 
Example #7
Source File: CSharpChangeSignatureDialog.java    From consulo-csharp with Apache License 2.0 5 votes vote down vote up
@Override
protected void customizeParametersTable(TableView<CSharpParameterTableModelItem> table)
{
	final JTable t = table.getComponent();
	final TableColumn defaultValue = t.getColumnModel().getColumn(2);
	final TableColumn varArg = t.getColumnModel().getColumn(3);
	t.removeColumn(defaultValue);
	t.removeColumn(varArg);
	t.getModel().addTableModelListener(new TableModelListener()
	{
		@Override
		public void tableChanged(TableModelEvent e)
		{
			if(e.getType() == TableModelEvent.INSERT)
			{
				t.getModel().removeTableModelListener(this);
				final TableColumnAnimator animator = new TableColumnAnimator(t);
				animator.setStep(48);
				animator.addColumn(defaultValue, (t.getWidth() - 48) / 3);
				animator.addColumn(varArg, 48);
				animator.startAndDoWhenDone(new Runnable()
				{
					@Override
					public void run()
					{
						t.editCellAt(t.getRowCount() - 1, 0);
					}
				});
				animator.start();
			}
		}
	});
}
 
Example #8
Source File: SwingInterop.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData().get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}
 
Example #9
Source File: TablePanel.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Creates a new {@link TablePanel} instance.
 *
 * @param model
 * @param useScrollPane
 *            if set to <code>true</code>, will add a scrollpane around the GUI.
 * @param hideUnavailableContentAssist
 *            if <code>true</code>, the content assist button will be hidden if no content
 *            assist is available for the given field
 */
public TablePanel(final TablePanelModel model, boolean useScrollPane, boolean hideUnavailableContentAssist) {
	this.mapOfComponents = new HashMap<>();
	this.useScrollPane = useScrollPane;
	this.hideUnavailableContentAssist = hideUnavailableContentAssist;
	this.listener = new TableModelListener() {

		@Override
		public void tableChanged(TableModelEvent e) {
			// table structure changed, re-create it
			if (e.getFirstRow() == TableModelEvent.HEADER_ROW) {
				createGUI();
			} else {
				updateComponent(e.getFirstRow(), e.getColumn());
			}
		}
	};

	SwingUtilities.invokeLater(new Runnable() {

		@Override
		public void run() {
			initGUI();
			setModel(model);
		}

	});
}
 
Example #10
Source File: KeyShortCutEditPanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private void updateCurrentSelectedForKey (final KeyEvent evt) {
  final int index = this.tableKeyShortcuts.getSelectedRow();
  if (index>=0){
    final KeyShortcut oldShortcut = this.listOfKeys.get(index);
    final int keyCode = evt.getKeyCode();
    final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK);
    final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(),keyCode,modifiers);
    this.listOfKeys.set(index, newShortCut);
    for(final TableModelListener l:this.listeners){
      l.tableChanged(new TableModelEvent(this,index));
    }
  }
  
  updateForSelected();
}
 
Example #11
Source File: RunPortBindingsVisual.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Creates new form RunNetworkVisual
 */
public RunPortBindingsVisual(DockerImageDetail info) {
    initComponents();
    this.info = info;

    addExposedButton.setEnabled(info != null && !info.getExposedPorts().isEmpty());
    portMappingTable.setModel(model);
    UiUtils.configureRowHeight(portMappingTable);

    TableColumn typeColumn = portMappingTable.getColumnModel().getColumn(0);
    JComboBox typeCombo = new JComboBox(ExposedPort.Type.values());
    typeColumn.setCellEditor(new DefaultCellEditor(typeCombo));
    typeColumn.setPreferredWidth(typeColumn.getPreferredWidth() / 2);

    TableColumn portColumn = portMappingTable.getColumnModel().getColumn(2);
    portColumn.setCellRenderer(new CellRenderer("<random>", false));

    TableColumn addressColumn = portMappingTable.getColumnModel().getColumn(3);
    JComboBox addressCombo = new JComboBox(UiUtils.getAddresses(false, false).toArray());
    addressCombo.setEditable(true);
    addressColumn.setCellEditor(new DefaultCellEditor(addressCombo));
    addressColumn.setCellRenderer(new CellRenderer("<any>", false));
    addressColumn.setPreferredWidth(addressColumn.getPreferredWidth() * 2);

    portMappingTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    model.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            changeSupport.fireChange();
        }
    });
}
 
Example #12
Source File: TestTableModel.java    From ghidra with Apache License 2.0 5 votes vote down vote up
@Override
public void fireTableDataChanged() {
	TableModelEvent event = new TableModelEvent(this);
	for (TableModelListener listener : listeners) {
		listener.tableChanged(event);
	}
}
 
Example #13
Source File: FmtImports.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void separateStaticImportsCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_separateStaticImportsCheckBoxActionPerformed
    TableModel oldModel = importLayoutTable.getModel();
    TableModel newModel = (DefaultTableModel)createTableModel(importGroupsOrder, preferences);
    importLayoutTable.setModel(newModel);
    setImportLayoutTableColumnsWidth();
    for (TableModelListener l : ((DefaultTableModel)oldModel).getTableModelListeners()) {
        oldModel.removeTableModelListener(l);
        newModel.addTableModelListener(l);
        l.tableChanged(null);
    }
}
 
Example #14
Source File: CorrelationTableController.java    From OpenDA with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void setupTableModelListener() {
//add listener which responds to tableChanged that is fired
//by correlationTableModel.setValueAt().
      this.correlationTableModel.addTableModelListener(new TableModelListener() {
      	public void tableChanged(TableModelEvent e) {
      		//(re)select row after setValueAt was called.

      		//select row of currentCorrelationContext.
      		int selectedRowIndex = correlationTableModel.getCurrentRow();
      		setSelectedRow(selectedRowIndex);
      	}
      });
  }
 
Example #15
Source File: TableDemo.java    From beautyeye with Apache License 2.0 5 votes vote down vote up
protected Container createStatusBar() {
	statusLabelString = getString("TableDemo.rowCountLabel", "Showing ");
	searchLabelString = getString("TableDemo.searchCountLabel",
			"Search found ");

	Box statusBar = Box.createHorizontalBox();

	// Left status area
	statusBar.add(Box.createRigidArea(new Dimension(10, 22)));
	statusBarLeft = Box.createHorizontalBox();
	statusBar.add(statusBarLeft);
	actionStatus = new JLabel(getString("TableDemo.noDataStatusLabel",
			"No data loaded"));
	actionStatus.setHorizontalAlignment(JLabel.LEADING);
	statusBarLeft.add(actionStatus);

	// Middle (should stretch)
	statusBar.add(Box.createHorizontalGlue());
	statusBar.add(Box.createHorizontalGlue());
	statusBar.add(Box.createVerticalGlue());

	// Right status area
	tableStatus = new JLabel(statusLabelString + "0");
	statusBar.add(tableStatus);
	statusBar.add(Box.createHorizontalStrut(12));

	// <snip>Track number of rows currently displayed
	oscarModel.addTableModelListener(new TableModelListener() {
		public void tableChanged(TableModelEvent e) {
			// Get rowCount from *table*, not model, as the view row count
			// may be different from the model row count due to filtering
			tableStatus.setText((hasFilterString() ? searchLabelString
					: statusLabelString) + oscarTable.getRowCount());
		}
	});
	// </snip>

	return statusBar;
}
 
Example #16
Source File: SwingInterop.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private BarChart createBarChart() {
    CategoryAxis xAxis = new CategoryAxis();
    xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames()));
    xAxis.setLabel("Year");

    double tickUnit = tableModel.getTickUnit();

    NumberAxis yAxis = new NumberAxis();
    yAxis.setTickUnit(tickUnit);
    yAxis.setLabel("Units Sold");

    final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData());
    tableModel.addTableModelListener(new TableModelListener() {

        public void tableChanged(TableModelEvent e) {
            if (e.getType() == TableModelEvent.UPDATE) {
                final int row = e.getFirstRow();
                final int column = e.getColumn();
                final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column);

                Platform.runLater(new Runnable() {
                    public void run() {
                        XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData().get(row);
                        BarChart.Data data = s.getData().get(column);
                        data.setYValue(value);
                    }
                });
            }
        }
    });
    return chart;
}
 
Example #17
Source File: KeyShortCutEditPanel.java    From netbeans-mmd-plugin with Apache License 2.0 5 votes vote down vote up
private void updateCurrentSelectedForKey (final KeyEvent evt) {
  final int index = this.tableKeyShortcuts.getSelectedRow();
  if (index>=0){
    final KeyShortcut oldShortcut = this.listOfKeys.get(index);
    final int keyCode = evt.getKeyCode();
    final int modifiers = evt.getModifiers() & (KeyEvent.META_MASK | KeyEvent.SHIFT_MASK | KeyEvent.CTRL_MASK | KeyEvent.ALT_MASK);
    final KeyShortcut newShortCut = new KeyShortcut(oldShortcut.getID(),keyCode,modifiers);
    this.listOfKeys.set(index, newShortCut);
    for(final TableModelListener l:this.listeners){
      l.tableChanged(new TableModelEvent(this,index));
    }
  }
  
  updateForSelected();
}
 
Example #18
Source File: Example_8_View.java    From Java_MVVM_with_Swing_and_RxJava_Examples with Apache License 2.0 5 votes vote down vote up
public Example_8_View() {
    super();
    setTitle(getClass().getSimpleName() + " " + ManagementFactory.getRuntimeMXBean().getName());

    setBounds(100, 100, 700, 500);
    setDefaultCloseOperation(StrictThreadingJFrame.EXIT_ON_CLOSE);
    getContentPane().setLayout(new BorderLayout(0, 0));

    final JXTable table = new JXTable(myTableModel);
    table.setHighlighters(HighlighterFactory.createSimpleStriping());
    table.setSortable(false);
    table.getTableHeader().setReorderingAllowed(false);

    myTableModel.addTableModelListener(new TableModelListener() {

        int lastRowCountScrolledTo = -1;

        @Override
        public void tableChanged(final TableModelEvent e) {
            if (TableUtilities.isInsert(e)) {
                final int currentRowCount = myTableModel.getRowCount();
                if (currentRowCount != lastRowCountScrolledTo) {
                    lastRowCountScrolledTo = currentRowCount;
                    SwingUtilities.invokeLater(() -> table.scrollRectToVisible(table.getCellRect(myTableModel.getRowCount() - 1, 0, false)));
                }
            }
        }
    });

    JScrollPane scrollPane = new JScrollPane(table);
    getContentPane().add(scrollPane, BorderLayout.CENTER);
}
 
Example #19
Source File: TableSorter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
public TableSorter() {
    super();
    evtListenerList = new Vector<TableModelListener>();
}
 
Example #20
Source File: MobileORObject.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 4 votes vote down vote up
@JsonIgnore
@Override
public TableModelListener[] getTableModelListeners() {
    return super.getTableModelListeners();
}
 
Example #21
Source File: DefaultOutlineModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public final synchronized void removeTableModelListener(TableModelListener l) {
    broadcaster.removeTableModelListener(l);
}
 
Example #22
Source File: TableSorter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private void restoreListeners() {
    for(TableModelListener tnl : evtListenerList)
        super.addTableModelListener(tnl);
}
 
Example #23
Source File: CardsLegalityTableModel.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void removeTableModelListener(final TableModelListener l) {
    listeners.remove(l);
}
 
Example #24
Source File: TableSorter.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void addTableModelListener(TableModelListener l) {
    evtListenerList.add(l);
    super.addTableModelListener(l);
}
 
Example #25
Source File: SecurityAddPrincipalPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void addTableModelListener(TableModelListener l) {
    realModel.addTableModelListener(l);
}
 
Example #26
Source File: CloudResourcesWizardComponent.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void addTableModelListener(TableModelListener l) {
}
 
Example #27
Source File: KeyShortCutEditPanel.java    From netbeans-mmd-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void removeTableModelListener (TableModelListener l) {
  this.listeners.remove(l);
}
 
Example #28
Source File: TableSorter.java    From hottub with GNU General Public License v2.0 4 votes vote down vote up
public TableSorter(Object[] columnNames, int numRows) {
    super(columnNames,numRows);
    evtListenerList = new Vector<TableModelListener>();
}
 
Example #29
Source File: AttrTable.java    From Logisim with GNU General Public License v3.0 4 votes vote down vote up
TableModelAdapter(Window parent, AttrTableModel attrModel) {
	this.parent = parent;
	this.listeners = new LinkedList<TableModelListener>();
	this.attrModel = attrModel;
}
 
Example #30
Source File: TableSorter.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void removeTableModelListener(TableModelListener l) {
    evtListenerList.remove(l);
    super.removeTableModelListener(l);
}