List of usage examples for javax.swing.event TableModelListener TableModelListener
TableModelListener
From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipPanel.java
protected void rebuildTable(ObjEntity entity) { final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this); model.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (table.getSelectedRow() >= 0) { ObjRelationship rel = model.getRelationship(table.getSelectedRow()); enabledResolve = rel.getSourceEntity().getDbEntity() != null; resolveMenu.setEnabled(enabledResolve); }//from ww w . j a va 2 s . c om } }); table.setModel(model); table.setRowHeight(25); table.setRowMargin(3); TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET_PATH); col.setCellEditor(new DbRelationshipPathComboBoxEditor()); col.setCellRenderer(new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); setToolTipText( "To choose relationship press enter two times.To choose next relationship press dot."); return this; } }); col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETE_RULE); JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(DELETE_RULES, false); deleteRulesCombo.setFocusable(false); deleteRulesCombo.setEditable(true); ((JComponent) deleteRulesCombo.getEditor().getEditorComponent()).setBorder(null); deleteRulesCombo.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 0)); deleteRulesCombo.setSelectedIndex(0); // Default to the first value col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo)); tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true); }
From source file:org.apache.cayenne.modeler.editor.ObjEntityRelationshipTab.java
protected void rebuildTable(ObjEntity entity) { final ObjRelationshipTableModel model = new ObjRelationshipTableModel(entity, mediator, this); model.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (table.getSelectedRow() >= 0) { ObjRelationship rel = model.getRelationship(table.getSelectedRow()); if (((ObjEntity) rel.getSourceEntity()).getDbEntity() != null) { resolve.setEnabled(true); } else resolve.setEnabled(false); resolveMenu.setEnabled(resolve.isEnabled()); }//from ww w. ja v a 2 s . c o m } }); table.setModel(model); table.setRowHeight(25); table.setRowMargin(3); TableColumn col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_TARGET); JComboBox targetCombo = Application.getWidgetFactory().createComboBox(createObjEntityComboModel(), false); AutoCompletion.enable(targetCombo); targetCombo.setRenderer(CellRenderers.entityListRendererWithIcons(entity.getDataMap())); targetCombo.setSelectedIndex(-1); col.setCellEditor(Application.getWidgetFactory().createCellEditor(targetCombo)); col = table.getColumnModel().getColumn(ObjRelationshipTableModel.REL_DELETERULE); JComboBox deleteRulesCombo = Application.getWidgetFactory().createComboBox(deleteRules, false); deleteRulesCombo.setEditable(false); deleteRulesCombo.setSelectedIndex(0); // Default to the first value col.setCellEditor(Application.getWidgetFactory().createCellEditor(deleteRulesCombo)); tablePreferences.bind(table, null, null, null, ObjRelationshipTableModel.REL_NAME, true); }
From source file:org.esa.nest.dat.toolviews.productlibrary.model.SortingDecorator.java
public SortingDecorator(final ProductEntryTableModel tableModel, final JTableHeader tableHeader) { Guardian.assertNotNull("tableModel", tableModel); Guardian.assertNotNull("tableHeader", tableHeader); this.tableModel = tableModel; this.tableModel.addTableModelListener(new TableModelListener() { public void tableChanged(final TableModelEvent e) { initViewToModel();//from w w w . java 2s . c o m fireTableChanged(e); } }); _tableHeader = tableHeader; _tableHeader.addMouseListener(new MouseHandler()); _tableHeader.setDefaultRenderer(new SortableHeaderRenderer(_tableHeader.getDefaultRenderer())); }
From source file:org.hibernate.search.demo.SearchDemo.java
private void initWidgets() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setDefaultLookAndFeelDecorated(true); BorderLayout borderLayout = new BorderLayout(); getContentPane().setLayout(borderLayout); // the main table model = new DefaultTableModel(headers, 0) { public boolean isCellEditable(int row, int column) { // at the moment only allows the editing of the title return column == 2; }/* w ww . j av a 2 s. com*/ }; modelListener = new TableModelListener() { public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int column = e.getColumn(); TableModel model = (TableModel) e.getSource(); Object data = model.getValueAt(row, column); EntityManager em = emf.createEntityManager(); updateTitle((Long) model.getValueAt(row, 0), (String) data); log.info("new value: {}", data); } }; model.addTableModelListener(modelListener); final JTable table = new JTable(model); table.setFont(new Font("Courier New", Font.PLAIN, 14)); getContentPane().add(new JScrollPane(table), BorderLayout.CENTER); // build the controls JPanel controlPanel = new JPanel(); controlPanel.setLayout(new FlowLayout()); final JTextField searchField = new JTextField(30); controlPanel.add(searchField); JButton searchButton = new JButton("Search"); searchButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { List<Product> products; try { products = search(searchField.getText()); } catch (ParseException pe) { JOptionPane.showMessageDialog(null, pe.getMessage(), "alert", JOptionPane.ERROR_MESSAGE); return; } DefaultTableModel model = (DefaultTableModel) table.getModel(); model.removeTableModelListener(modelListener); model.setRowCount(0); for (int i = 0; i < products.size(); i++) { Object[] data = new Object[headers.length]; Product p = products.get(i); data[0] = p.getProductId(); data[1] = p.getASIN(); data[2] = p.getTitle(); //data[3] = p.getDescription(); String actors = ""; for (Actor actor : p.getActors()) { actors = actors + actor.getName() + ", "; } data[3] = actors.length() == 0 ? actors : actors.substring(0, actors.length() - 2); String categories = ""; for (Category category : p.getCategories()) { categories = categories + category.getName() + ", "; } data[4] = categories.length() == 0 ? categories : categories.substring(0, categories.length() - 2); model.insertRow(i, data); } model.addTableModelListener(modelListener); } }); controlPanel.add(searchButton); JButton indexButton = new JButton("Index"); indexButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { index(); } }); controlPanel.add(indexButton); JButton purgeButton = new JButton("Purge"); purgeButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { purge(); } }); controlPanel.add(purgeButton); getContentPane().add(controlPanel, BorderLayout.NORTH); getRootPane().setDefaultButton(searchButton); setSize(800, 200); setVisible(true); }
From source file:org.monkeys.gui.matcher.MatcherPanel.java
private void wireEvents() { this.modifyPanel.addModifyMatchesListener(new ModifyMatchesListener() { @Override/* w w w .j a va2 s .co m*/ public void searchAndReplace(final Pattern search, final String replace) { searchAndReplaceSelected(search, replace); } @Override public void appendSuffix(final String text) { appendSuffixSelected(text); } @Override public void preappendPrefix(final String text) { preappendPrefixSelected(text); } }); this.matchingList.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(final ListSelectionEvent event) { if (!event.getValueIsAdjusting()) { matchingListSelected(event); } } }); this.matchingList.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { matchingListTableChanged(e); } }); }
From source file:org.nuclos.client.ui.collect.SubForm.java
public void setupTableModelListener() { this.tblmdllistener = new TableModelListener() { @Override/*from www .j a v a 2s. c om*/ public void tableChanged(TableModelEvent ev) { // recalculate the optimal column widths when custom column widths are not used yet and // a row is inserted (the first time): //@todo: this here is entered not only the first time a row is entered but also on startup (sort fires a tableDataChanged) if (!useCustomColumnWidths) { // Now this is an example for an API that sucks :( final boolean bRowsInserted = (ev.getType() == TableModelEvent.INSERT) || // @todo: The first condition (INSERT) is clear, but what for the second (complete UPDATE)? (ev.getType() == TableModelEvent.UPDATE && ev.getColumn() == TableModelEvent.ALL_COLUMNS && ev.getLastRow() == Integer.MAX_VALUE); if (bRowsInserted) { resetDefaultColumnWidths(); LOG.debug("Custom column widths should be used here."); // Setting them manually."); } } // TableModelEvents caused by sorting don't change the subform state: if (!(ev instanceof SortableTableModelEvent)) { fireStateChanged(); } } }; subformtbl.getModel().addTableModelListener(this.tblmdllistener); }
From source file:org.openconcerto.erp.core.sales.order.component.CommandeClientSQLComponent.java
public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Numero du commande c.gridx = 0;// ww w . j av a2 s. co m this.add(new JLabel(getLabelFor("NUMERO"), SwingConstants.RIGHT), c); this.numeroUniqueCommande = new JUniqueTextField(16); c.fill = GridBagConstraints.NONE; c.gridx++; c.weightx = 1; this.add(this.numeroUniqueCommande, c); // Date JLabel labelDate = new JLabel(getLabelFor("DATE")); labelDate.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 2; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; this.add(labelDate, c); JDate dateCommande = new JDate(true); c.gridx++; c.fill = GridBagConstraints.NONE; this.add(dateCommande, c); // Champ Module c.gridx = 0; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); this.setAdditionalFieldsPanel(new FormLayouter(addP, 2)); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; this.add(addP, c); c.gridy++; c.gridwidth = 1; this.comboDevis = new ElementComboBox(); // Reference c.gridx = 0; c.gridy++; c.gridwidth = 1; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelObjet = new JLabel(getLabelFor("NOM")); labelObjet.setHorizontalAlignment(SwingConstants.RIGHT); c.weightx = 0; this.add(labelObjet, c); c.gridx++; c.weightx = 1; c.fill = GridBagConstraints.BOTH; this.add(this.textObjet, c); String field; field = "ID_COMMERCIAL"; c.fill = GridBagConstraints.HORIZONTAL; // Commercial JLabel labelCommercial = new JLabel(getLabelFor(field)); labelCommercial.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx++; c.weightx = 0; this.add(labelCommercial, c); this.comboCommercial = new ElementComboBox(false, 25); this.comboCommercial.setListIconVisible(false); c.gridx++; c.fill = GridBagConstraints.NONE; c.weightx = 1; this.add(this.comboCommercial, c); addRequiredSQLObject(this.comboCommercial, field); // Ligne 3: Client c.gridx = 0; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("ID_CLIENT"), SwingConstants.RIGHT), c); this.comboClient = new ElementComboBox(); c.gridx = GridBagConstraints.RELATIVE; c.gridwidth = 3; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(this.comboClient, c); final ElementComboBox boxTarif = new ElementComboBox(); this.comboClient.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { if (!isFilling() && comboClient.getValue() != null) { Integer id = comboClient.getValue(); if (id > 1) { SQLRow row = comboClient.getElement().getTable().getRow(id); if (comboClient.getElement().getTable().getFieldsName().contains("ID_TARIF")) { SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); if (!foreignRow.isUndefined() && (boxTarif.getSelectedRow() == null || boxTarif.getSelectedId() != foreignRow.getID()) && JOptionPane.showConfirmDialog(null, "Appliquer les tarifs associs au client?") == JOptionPane.YES_OPTION) { boxTarif.setValue(foreignRow.getID()); // SaisieVenteFactureSQLComponent.this.tableFacture.setTarif(foreignRow, // true); } else { boxTarif.setValue(foreignRow.getID()); } // SQLRowAccessor foreignRow = row.getForeignRow("ID_TARIF"); // if (foreignRow.isUndefined() && // !row.getForeignRow("ID_DEVISE").isUndefined()) { // SQLRowValues rowValsD = new SQLRowValues(foreignRow.getTable()); // rowValsD.put("ID_DEVISE", row.getObject("ID_DEVISE")); // foreignRow = rowValsD; // // } // table.setTarif(foreignRow, true); } } } } }); // tarif if (this.getTable().getFieldsName().contains("ID_TARIF")) { // TARIF c.gridy++; c.gridx = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; this.add(new JLabel("Tarif appliquer"), c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; this.add(boxTarif, c); this.addView(boxTarif, "ID_TARIF"); boxTarif.addModelListener("wantedID", new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { SQLRow selectedRow = boxTarif.getRequest().getPrimaryTable().getRow(boxTarif.getWantedID()); table.setTarif(selectedRow, false); } }); } // Table d'lment this.table = new CommandeClientItemTable(); c.fill = GridBagConstraints.BOTH; c.gridy++; c.gridx = 0; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.table, c); DeviseField textPortHT = new DeviseField(); DeviseField textRemiseHT = new DeviseField(); // INfos c.gridx = 0; c.gridy++; c.gridheight = 1; c.weighty = 0; c.weightx = 1; c.anchor = GridBagConstraints.WEST; c.gridwidth = 2; this.add(new TitledSeparator(getLabelFor("INFOS")), c); c.gridy++; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.BOTH; final JScrollPane scrollPane = new JScrollPane(this.infos); scrollPane.setBorder(null); this.add(scrollPane, c); // Poids c.gridwidth = 1; DefaultProps props = DefaultNXProps.getInstance(); Boolean b = props.getBooleanValue("ArticleShowPoids"); final JTextField textPoidsTotal = new JTextField(8); if (b) { JPanel panel = new JPanel(); panel.add(new JLabel(getLabelFor("T_POIDS")), c); textPoidsTotal.setEnabled(false); textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT); textPoidsTotal.setDisabledTextColor(Color.BLACK); panel.add(textPoidsTotal, c); panel.setOpaque(false); DefaultGridBagConstraints.lockMinimumSize(panel); c.gridx = 2; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHEAST; this.add(panel, c); } // Total DeviseField fieldHT = new DeviseField(); DeviseField fieldTVA = new DeviseField(); DeviseField fieldTTC = new DeviseField(); DeviseField fieldDevise = new DeviseField(); DeviseField fieldService = new DeviseField(); DeviseField fieldHA = new DeviseField(); fieldHT.setOpaque(false); fieldHA.setOpaque(false); fieldTVA.setOpaque(false); fieldTTC.setOpaque(false); fieldService.setOpaque(false); addSQLObject(fieldDevise, "T_DEVISE"); addRequiredSQLObject(fieldHT, "T_HT"); addRequiredSQLObject(fieldTVA, "T_TVA"); addRequiredSQLObject(fieldTTC, "T_TTC"); addRequiredSQLObject(fieldService, "T_SERVICE"); if (getTable().contains("PREBILAN")) { addSQLObject(fieldHA, "PREBILAN"); } else if (getTable().contains("T_HA")) { addSQLObject(fieldHA, "T_HA"); } JTextField poids = new JTextField(); // addSQLObject(poids, "T_POIDS"); final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, fieldHA, fieldDevise, poids, null); c.gridx = GridBagConstraints.RELATIVE; c.gridy--; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 2; c.anchor = GridBagConstraints.NORTHEAST; c.fill = GridBagConstraints.NONE; c.weighty = 0; this.add(totalTTC, c); this.panelOO = new PanelOOSQLComponent(this); c.gridwidth = 1; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; c.gridx = 0; c.gridy += 3; c.weightx = 0; c.gridwidth = GridBagConstraints.REMAINDER; this.add(this.panelOO, c); textPortHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); textRemiseHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); addRequiredSQLObject(this.comboClient, "ID_CLIENT"); addSQLObject(this.textObjet, "NOM"); addSQLObject(textPoidsTotal, "T_POIDS"); addRequiredSQLObject(dateCommande, "DATE"); // addRequiredSQLObject(radioEtat, "ID_ETAT_DEVIS"); addRequiredSQLObject(this.numeroUniqueCommande, "NUMERO"); addSQLObject(this.infos, "INFOS"); addSQLObject(this.comboDevis, "ID_DEVIS"); this.numeroUniqueCommande .setText(NumerotationAutoSQLElement.getNextNumero(CommandeClientSQLElement.class, new Date())); this.table.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { textPoidsTotal.setText(String.valueOf(CommandeClientSQLComponent.this.table.getPoidsTotal())); } }); DefaultGridBagConstraints.lockMinimumSize(comboClient); DefaultGridBagConstraints.lockMinimumSize(comboCommercial); DefaultGridBagConstraints.lockMinimumSize(comboDevis); DefaultGridBagConstraints.lockMinimumSize(totalTTC); DefaultGridBagConstraints.lockMaximumSize(totalTTC); DefaultGridBagConstraints.lockMinimumSize(numeroUniqueCommande); }
From source file:org.openconcerto.erp.core.supplychain.order.component.CommandeSQLComponent.java
private JPanel getBottomPanel() { final JPanel panel = new JPanel(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Colonne 1 : Infos c.gridx = 0;//from ww w . ja v a2 s. c o m c.weightx = 1; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; panel.add(new TitledSeparator(getLabelFor("INFOS")), c); c.gridy++; c.weighty = 0; c.weightx = 1; c.fill = GridBagConstraints.BOTH; final JScrollPane scrollPane = new JScrollPane(this.infos); scrollPane.setBorder(null); panel.add(scrollPane, c); // Colonne 2 : Poids & autres DefaultProps props = DefaultNXProps.getInstance(); Boolean b = props.getBooleanValue("ArticleShowPoids"); final JTextField textPoidsTotal = new JTextField(8); JTextField poids = new JTextField(); if (b) { final JPanel panelPoids = new JPanel(); panelPoids.add(new JLabel(getLabelFor("T_POIDS")), c); textPoidsTotal.setEnabled(false); textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT); textPoidsTotal.setDisabledTextColor(Color.BLACK); panelPoids.add(textPoidsTotal, c); c.gridx++; c.gridy = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.gridheight = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHEAST; panel.add(panelPoids, c); DefaultGridBagConstraints.lockMinimumSize(panelPoids); addSQLObject(textPoidsTotal, "T_POIDS"); } else { addSQLObject(poids, "T_POIDS"); } DeviseField textPortHT = new DeviseField(); ElementComboBox comboTaxePort = new ElementComboBox(); if (getTable().contains("PORT_HT")) { addRequiredSQLObject(textPortHT, "PORT_HT"); final JPanel panelPoids = new JPanel(new GridBagLayout()); GridBagConstraints cPort = new DefaultGridBagConstraints(); cPort.gridx = 0; cPort.weightx = 0; panelPoids.add(new JLabel(getLabelFor("PORT_HT")), cPort); textPortHT.setHorizontalAlignment(JTextField.RIGHT); cPort.gridx++; cPort.weightx = 1; panelPoids.add(textPortHT, cPort); cPort.gridy++; cPort.gridx = 0; cPort.weightx = 0; addRequiredSQLObject(comboTaxePort, "ID_TAXE_PORT"); panelPoids.add(new JLabel(getLabelFor("ID_TAXE_PORT")), cPort); cPort.gridx++; cPort.weightx = 0; panelPoids.add(comboTaxePort, cPort); c.gridx++; c.gridy = 0; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.gridheight = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHEAST; panel.add(panelPoids, c); DefaultGridBagConstraints.lockMinimumSize(panelPoids); } // Total DeviseField textRemiseHT = new DeviseField(); DeviseField fieldHT = new DeviseField(); DeviseField fieldTVA = new DeviseField(); DeviseField fieldTTC = new DeviseField(); DeviseField fieldDevise = new DeviseField(); DeviseField fieldService = new DeviseField(); fieldHT.setOpaque(false); fieldTVA.setOpaque(false); fieldTTC.setOpaque(false); fieldService.setOpaque(false); addRequiredSQLObject(fieldDevise, "T_DEVISE"); addRequiredSQLObject(fieldHT, "T_HT"); addRequiredSQLObject(fieldTVA, "T_TVA"); addRequiredSQLObject(fieldTTC, "T_TTC"); addRequiredSQLObject(fieldService, "T_SERVICE"); final TotalPanel totalTTC = new TotalPanel(this.table, fieldHT, fieldTVA, fieldTTC, textPortHT, textRemiseHT, fieldService, null, fieldDevise, null, null, (getTable().contains("ID_TAXE_PORT") ? comboTaxePort : null)); c.gridx++; c.gridy--; c.gridwidth = GridBagConstraints.REMAINDER; c.gridheight = 2; c.anchor = GridBagConstraints.NORTHEAST; c.fill = GridBagConstraints.BOTH; c.weighty = 0; DefaultGridBagConstraints.lockMinimumSize(totalTTC); panel.add(totalTTC, c); c.gridy += 3; c.gridheight = 2; c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.EAST; panel.add(getModuleTotalPanel(), c); table.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { textPoidsTotal.setText(String.valueOf(table.getPoidsTotal())); } }); textPortHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); comboTaxePort.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { // TODO Raccord de mthode auto-gnr totalTTC.updateTotal(); } }); textRemiseHT.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void removeUpdate(DocumentEvent e) { totalTTC.updateTotal(); } public void insertUpdate(DocumentEvent e) { totalTTC.updateTotal(); } }); return panel; }
From source file:org.openconcerto.erp.core.supplychain.receipt.component.BonReceptionSQLComponent.java
public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Champ Module c.gridx = 0;//from w w w . j a v a 2 s . com c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; final JPanel addP = ComptaSQLConfElement.createAdditionalPanel(); this.setAdditionalFieldsPanel(new FormLayouter(addP, 1)); this.add(addP, c); c.gridy++; c.gridwidth = 1; this.textTotalHT.setOpaque(false); this.textTotalTVA.setOpaque(false); this.textTotalTTC.setOpaque(false); this.selectCommande = new ElementComboBox(); // Numero JLabel labelNum = new JLabel(getLabelFor("NUMERO")); labelNum.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelNum, c); this.textNumeroUnique = new JUniqueTextField(16); c.gridx++; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; DefaultGridBagConstraints.lockMinimumSize(this.textNumeroUnique); this.add(this.textNumeroUnique, c); // Date JLabel labelDate = new JLabel(getLabelFor("DATE")); labelDate.setHorizontalAlignment(SwingConstants.RIGHT); c.fill = GridBagConstraints.HORIZONTAL; c.gridx++; c.weightx = 0; this.add(labelDate, c); JDate date = new JDate(true); c.gridx++; c.weightx = 0; c.weighty = 0; this.add(date, c); // Reference c.gridy++; c.gridx = 0; final JLabel labelNom = new JLabel(getLabelFor("NOM")); labelNom.setHorizontalAlignment(SwingConstants.RIGHT); this.add(labelNom, c); c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; DefaultGridBagConstraints.lockMinimumSize(this.textReference); this.add(this.textReference, c); // Fournisseur JLabel labelFournisseur = new JLabel(getLabelFor("ID_FOURNISSEUR")); labelFournisseur.setHorizontalAlignment(SwingConstants.RIGHT); c.gridx = 0; c.gridy++; c.weightx = 0; c.weighty = 0; this.add(labelFournisseur, c); this.fournisseur = new ElementComboBox(); c.gridx++; c.weightx = 0; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(this.fournisseur, c); // Devise c.gridx = 0; c.gridy++; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.add(new JLabel(getLabelFor("ID_DEVISE"), SwingConstants.RIGHT), c); final ElementComboBox boxDevise = new ElementComboBox(); c.gridx = GridBagConstraints.RELATIVE; c.gridwidth = 1; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.NONE; this.add(boxDevise, c); this.addView(boxDevise, "ID_DEVISE"); // Element du bon this.tableBonItem = new BonReceptionItemTable(); c.gridx = 0; c.gridy++; c.weightx = 1; c.weighty = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.fill = GridBagConstraints.BOTH; this.add(this.tableBonItem, c); this.fournisseur.addValueListener(new PropertyChangeListener() { @Override public void propertyChange(PropertyChangeEvent evt) { tableBonItem.setFournisseur(fournisseur.getSelectedRow()); } }); c.anchor = GridBagConstraints.EAST; // Totaux reconfigure(this.textTotalHT); reconfigure(this.textTotalTVA); reconfigure(this.textTotalTTC); // Poids Total c.gridy++; c.gridx = 1; c.weightx = 0; c.weighty = 0; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; DefaultProps props = DefaultNXProps.getInstance(); Boolean b = props.getBooleanValue("ArticleShowPoids"); if (b) { JPanel panelPoids = new JPanel(new GridBagLayout()); GridBagConstraints c2 = new DefaultGridBagConstraints(); c2.fill = GridBagConstraints.NONE; panelPoids.add(new JLabel(getLabelFor("TOTAL_POIDS")), c2); // Necessaire pour ne pas avoir de saut de layout DefaultGridBagConstraints.lockMinimumSize(this.textPoidsTotal); this.textPoidsTotal.setEnabled(false); this.textPoidsTotal.setHorizontalAlignment(JTextField.RIGHT); this.textPoidsTotal.setDisabledTextColor(Color.BLACK); c2.gridx++; c2.weightx = 1; c2.fill = GridBagConstraints.HORIZONTAL; panelPoids.add(this.textPoidsTotal, c2); this.add(panelPoids, c); } c.gridx = 2; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; c.weighty = 0; c.anchor = GridBagConstraints.EAST; c.fill = GridBagConstraints.HORIZONTAL; final GridBagConstraints cTotalPan = new DefaultGridBagConstraints(); JPanel panelTotalHT = new JPanel(); panelTotalHT.setLayout(new GridBagLayout()); cTotalPan.gridx = 0; cTotalPan.weightx = 0; cTotalPan.fill = GridBagConstraints.HORIZONTAL; cTotalPan.anchor = GridBagConstraints.WEST; final JLabelBold labelTotalHT = new JLabelBold(getLabelFor("TOTAL_HT")); panelTotalHT.add(labelTotalHT, cTotalPan); cTotalPan.anchor = GridBagConstraints.EAST; cTotalPan.gridx++; cTotalPan.weightx = 1; this.textTotalHT.setFont(labelTotalHT.getFont()); DefaultGridBagConstraints.lockMinimumSize(this.textTotalHT); panelTotalHT.add(this.textTotalHT, cTotalPan); this.add(panelTotalHT, c); JPanel panelTotalTVA = new JPanel(); panelTotalTVA.setLayout(new GridBagLayout()); cTotalPan.gridx = 0; cTotalPan.weightx = 0; cTotalPan.anchor = GridBagConstraints.WEST; cTotalPan.fill = GridBagConstraints.HORIZONTAL; panelTotalTVA.add(new JLabelBold(getLabelFor("TOTAL_TVA")), cTotalPan); cTotalPan.anchor = GridBagConstraints.EAST; cTotalPan.gridx++; cTotalPan.weightx = 1; DefaultGridBagConstraints.lockMinimumSize(this.textTotalTVA); panelTotalTVA.add(this.textTotalTVA, cTotalPan); c.gridy++; c.fill = GridBagConstraints.HORIZONTAL; this.add(panelTotalTVA, c); JPanel panelTotalTTC = new JPanel(); panelTotalTTC.setLayout(new GridBagLayout()); cTotalPan.gridx = 0; cTotalPan.anchor = GridBagConstraints.WEST; cTotalPan.gridwidth = GridBagConstraints.REMAINDER; cTotalPan.fill = GridBagConstraints.BOTH; cTotalPan.weightx = 1; panelTotalTTC.add(new JSeparator(), cTotalPan); cTotalPan.gridwidth = 1; cTotalPan.fill = GridBagConstraints.NONE; cTotalPan.weightx = 0; cTotalPan.gridy++; panelTotalTTC.add(new JLabelBold(getLabelFor("TOTAL_TTC")), cTotalPan); cTotalPan.anchor = GridBagConstraints.EAST; cTotalPan.gridx++; this.textTotalTTC.setFont(labelTotalHT.getFont()); DefaultGridBagConstraints.lockMinimumSize(this.textTotalTTC); panelTotalTTC.add(this.textTotalTTC, cTotalPan); c.gridy++; // probleme de tremblement vertical this.add(panelTotalTTC, c); c.anchor = GridBagConstraints.WEST; /******************************************************************************************* * * INFORMATIONS COMPLEMENTAIRES ******************************************************************************************/ c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy++; TitledSeparator sep = new TitledSeparator("Informations complmentaires"); c.insets = new Insets(10, 2, 1, 2); this.add(sep, c); c.insets = new Insets(2, 2, 1, 2); c.gridx = 0; c.gridy++; c.gridheight = 1; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; c.fill = GridBagConstraints.BOTH; final ITextArea textInfos = new ITextArea(4, 4); JScrollPane scrollPane = new JScrollPane(textInfos); DefaultGridBagConstraints.lockMinimumSize(scrollPane); this.add(textInfos, c); this.addRequiredSQLObject(date, "DATE"); this.addSQLObject(textInfos, "INFOS"); this.addSQLObject(this.textReference, "NOM"); this.addSQLObject(this.selectCommande, "ID_COMMANDE"); this.addRequiredSQLObject(this.textNumeroUnique, "NUMERO"); this.addSQLObject(this.textPoidsTotal, "TOTAL_POIDS"); this.addRequiredSQLObject(this.textTotalHT, "TOTAL_HT"); this.addRequiredSQLObject(this.textTotalTVA, "TOTAL_TVA"); this.addRequiredSQLObject(this.textTotalTTC, "TOTAL_TTC"); this.addRequiredSQLObject(this.fournisseur, "ID_FOURNISSEUR"); this.textNumeroUnique.setText(NumerotationAutoSQLElement.getNextNumero(BonReceptionSQLElement.class)); // Listeners this.tableBonItem.getModel().addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { int columnIndexHT = BonReceptionSQLComponent.this.tableBonItem.getModel().getColumnIndexForElement( BonReceptionSQLComponent.this.tableBonItem.getPrixTotalHTElement()); int columnIndexTTC = BonReceptionSQLComponent.this.tableBonItem.getModel().getColumnIndexForElement( BonReceptionSQLComponent.this.tableBonItem.getPrixTotalTTCElement()); int columnIndexPoids = BonReceptionSQLComponent.this.tableBonItem.getModel() .getColumnIndexForElement( BonReceptionSQLComponent.this.tableBonItem.getPoidsTotalElement()); if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == columnIndexHT || e.getColumn() == columnIndexTTC) { updateTotal(); } if (e.getColumn() == TableModelEvent.ALL_COLUMNS || e.getColumn() == columnIndexPoids) { BonReceptionSQLComponent.this.textPoidsTotal.setText(String .valueOf(Math.round(BonReceptionSQLComponent.this.tableBonItem.getPoidsTotal() * 1000) / 1000.0)); } } }); // Lock UI DefaultGridBagConstraints.lockMinimumSize(this.fournisseur); }
From source file:org.piraso.ui.base.ExportDialog.java
protected void addButtonRefreshListeners() { jtable.getSelectionModel().addListSelectionListener(REFRESH_BUTTON_LIST_SELECTION_LISTENER); tableModel.addTableModelListener(new TableModelListener() { @Override/* w w w. jav a2 s .c o m*/ public void tableChanged(TableModelEvent e) { refreshButtons(); } }); }