List of usage examples for javax.swing JTable setRowSelectionInterval
public void setRowSelectionInterval(int index0, int index1)
index0
to index1
, inclusive. From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
/** * @deprecated Move to ResultController hierarchy. *//*from ww w. j av a2 s. c om*/ private void cmdRestoreCurrentCollectableInDetails() { assert getCollectStateModel().getCollectState() .equals(new CollectState(CollectState.OUTERSTATE_DETAILS, CollectState.DETAILSMODE_VIEW)); if (stopEditingInDetails()) { final String sMessage = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.75", "Soll der angezeigte Datensatz ({0}) wirklich wiederhergestellt werden?", getSelectedCollectable().getIdentifierLabel()); final int iBtn = JOptionPane.showConfirmDialog(getTab(), sMessage, getSpringLocaleDelegate().getMessage( "GenericObjectCollectController.28", "Datensatz wiederherstellen"), JOptionPane.YES_NO_OPTION); if (iBtn == JOptionPane.OK_OPTION) UIUtils.runCommand(getTab(), new Runnable() { @Override public void run() { try { // try to find next or previous object: final JTable tblResult = getResultTable(); final int iSelectedRow = tblResult.getSelectedRow(); if (iSelectedRow < 0) throw new IllegalStateException(); final int iNewSelectedRow; if (iSelectedRow < tblResult.getRowCount() - 1) // the selected row is not the last row: select the next row iNewSelectedRow = iSelectedRow; else if (iSelectedRow > 0) // the selected row is not the first row: select the previous row iNewSelectedRow = iSelectedRow - 1; else { // the selected row is the single row: don't select a row assert tblResult.getRowCount() == 1; assert iSelectedRow == 0; iNewSelectedRow = -1; } checkedRestoreCollectable(getSelectedCollectable()); getResultTableModel().remove(getSelectedCollectable()); getSearchStrategy().search(true); if (iNewSelectedRow == -1) { tblResult.clearSelection(); // switch to new mode: getResultController().getSearchResultStrategy().refreshResult(); } else { tblResult.setRowSelectionInterval(iNewSelectedRow, iNewSelectedRow); // go into view mode again: cmdEnterViewMode(); } } catch (CommonPermissionException ex) { final String sErrorMessage = getSpringLocaleDelegate().getMessage( "GenericObjectCollectController.67", "Sie verf\u00fcgen nicht \u00fcber die ausreichenden Rechte, um diesen Datensatz wiederherzustellen."); Errors.getInstance().showExceptionDialog(getTab(), sErrorMessage, ex); } catch (CommonBusinessException ex) { Errors.getInstance().showExceptionDialog(getTab(), getSpringLocaleDelegate().getMessage("GenericObjectCollectController.33", "Der Datensatz konnte nicht wiederhergestellt werden."), ex); } } }); } setDeleteButtonToggleInDetails(); }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
/** * Delete the selected object physically. * This is mostly a copy from CollectController.cmdDelete; just the message and the called delete method are different. *///w ww. ja v a 2 s . c o m protected void cmdDeletePhysically() { assert getCollectStateModel().getCollectState() .equals(new CollectState(CollectState.OUTERSTATE_DETAILS, CollectState.DETAILSMODE_VIEW)); if (stopEditingInDetails()) { final String sMessage = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.73", "Soll der angezeigte Datensatz ({0}) wirklich endg\u00fcltig aus der Datenbank gel\u00f6scht werden?\nDieser Vorgang kann nicht r\u00fcckg\u00e4ngig gemacht werden! ", getSelectedCollectable().getIdentifierLabel()); final int iBtn = JOptionPane.showConfirmDialog(getTab(), sMessage, getSpringLocaleDelegate() .getMessage("GenericObjectCollectController.24", "Datensatz endg\u00fcltig l\u00f6schen"), JOptionPane.YES_NO_OPTION); if (iBtn == JOptionPane.OK_OPTION) UIUtils.runCommand(getTab(), new Runnable() { @Override public void run() { try { // try to find next or previous object: final JTable tblResult = getResultTable(); final int iSelectedRow = tblResult.getSelectedRow(); if (iSelectedRow < 0) throw new IllegalStateException(); final int iNewSelectedRow; if (iSelectedRow < tblResult.getRowCount() - 1) // the selected row is not the last row: select the next row iNewSelectedRow = iSelectedRow; else if (iSelectedRow > 0) // the selected row is not the first row: select the previous row iNewSelectedRow = iSelectedRow - 1; else { // the selected row is the single row: don't select a row assert tblResult.getRowCount() == 1; assert iSelectedRow == 0; iNewSelectedRow = -1; } checkedDeleteCollectablePhysically(getSelectedCollectable()); if (iNewSelectedRow == -1) { tblResult.clearSelection(); // switch to new mode: setCollectState(CollectState.OUTERSTATE_DETAILS, CollectState.DETAILSMODE_NEW); } else { tblResult.setRowSelectionInterval(iNewSelectedRow, iNewSelectedRow); // go into view mode again: setCollectState(CollectState.OUTERSTATE_DETAILS, CollectState.DETAILSMODE_VIEW); } } catch (CommonPermissionException ex) { final String sErrorMessage = getSpringLocaleDelegate().getMessage( "GenericObjectCollectController.70", "Sie verf\u00fcgen nicht \u00fcber die ausreichenden Rechte, um dieses Objekt zu l\u00f6schen."); Errors.getInstance().showExceptionDialog(getTab(), sErrorMessage, ex); } catch (CommonBusinessException ex) { if (!handlePointerException(ex)) Errors.getInstance().showExceptionDialog(getTab(), getSpringLocaleDelegate().getMessage("GenericObjectCollectController.18", "Das Objekt konnte nicht gel\u00f6scht werden."), ex); } } }); } }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * command: select columns/*w w w. j av a2 s . c o m*/ * Lets the user select the columns to show in the result list. */ public void cmdSelectColumns(final ChoiceEntityFieldList fields) { final SelectColumnsController ctl = new SelectColumnsController(clctctl.getTab()); // final List<CollectableEntityField> lstAvailable = (List<CollectableEntityField>) fields.getAvailableFields(); // final List<CollectableEntityField> lstSelected = (List<CollectableEntityField>) fields.getSelectedFields(); final ResultPanel<Clct> panel = getResultPanel(); final JTable tbl = panel.getResultTable(); final Map<String, Integer> mpWidths = panel.getVisibleColumnWidth(fields.getSelectedFields()); ctl.setModel(fields); final boolean bOK = ctl.run(getSpringLocaleDelegate().getMessage("SelectColumnsController.1", "Anzuzeigende Spalten ausw\u00e4hlen")); if (bOK) { UIUtils.runCommand(clctctl.getTab(), new CommonRunnable() { @Override public void run() throws CommonBusinessException { final int iSelectedRow = tbl.getSelectedRow(); fields.set(ctl.getAvailableObjects(), ctl.getSelectedObjects(), clctctl.getResultController().getCollectableEntityFieldComparator()); final List<? extends CollectableEntityField> lstSelectedNew = fields.getSelectedFields(); ((CollectableTableModel<?>) tbl.getModel()).setColumns(lstSelectedNew); panel.setupTableCellRenderers(tbl); Collection<CollectableEntityField> collNewlySelected = new ArrayList<CollectableEntityField>( lstSelectedNew); collNewlySelected.removeAll(fields.getSelectedFields()); if (!collNewlySelected.isEmpty()) { if (!clctctl.getSearchStrategy().getCollectablesInResultAreAlwaysComplete()) { // refresh the result: clctctl.getResultController().getSearchResultStrategy().refreshResult(); } } // reselect the previously selected row (which gets lost be refreshing the model) if (iSelectedRow != -1) { tbl.setRowSelectionInterval(iSelectedRow, iSelectedRow); } isIgnorePreferencesUpdate = true; panel.restoreColumnWidths(ctl.getSelectedObjects(), mpWidths); isIgnorePreferencesUpdate = false; // Set the newly added columns to optimal width for (CollectableEntityField clctef : collNewlySelected) { TableUtils.setOptimalColumnWidth(tbl, tbl.getColumnModel().getColumnIndex(clctef.getLabel())); } } }); } }
From source file:org.openconcerto.erp.core.humanresources.payroll.element.FichePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private FichePayeModel model; private ElementComboBox comboSelProfil, selSalCombo; private EditFrame edit = null; private ElementComboBox selMois; private int dernMois, dernAnnee; private JTextField textAnnee; JDate dateDu, dateAu;//from w ww. ja va 2 s. co m private JScrollPane paneTreeLeft; private JPanel pDate; private JButton buttonValider, buttonGenCompta; public void addViews() { this.dernMois = 0; this.dernAnnee = 0; this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); // Tree elt Fiche de Paye On the left c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridheight = GridBagConstraints.REMAINDER; final RubriquePayeTree tree = new RubriquePayeTree(); tree.expandRow(0); this.paneTreeLeft = new JScrollPane(tree); // this.add(this.paneTreeLeft, c); // Panel Fiche paye on the right // Salarie JPanel panelRight = new JPanel(); panelRight.setLayout(new GridBagLayout()); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 2; this.selSalCombo = new ElementComboBox(); // c.gridx++; panelRight.add(this.selSalCombo, c); // Mois c.gridy++; // c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1; c.weighty = 0; c.gridheight = 1; c.gridwidth = 3; JLabel labelMois = new JLabel("Fiche de paye du mois de"); this.selMois = new ElementComboBox(true, 20); // this.selMois.setEditable(true); // /this.selMois.setEnabled(true); JLabel labelDu = new JLabel("Du"); JLabel labelAu = new JLabel("Au"); this.dateDu = new JDate(); this.dateAu = new JDate(); // JTextField textMois = new JTextField(); JLabel labelAnnee = new JLabel("Anne"); this.textAnnee = new JTextField(); { this.pDate = new JPanel(); this.pDate.setOpaque(false); this.pDate.add(labelMois); this.pDate.add(this.selMois); this.pDate.add(labelAnnee); this.pDate.add(this.textAnnee); this.pDate.add(labelDu); this.pDate.add(this.dateDu); this.pDate.add(labelAu); this.pDate.add(this.dateAu); panelRight.add(this.pDate, c); } c.gridx += 2; c.weightx = 1; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; panelRight.add(new JPanel(), c); // Action Button c.gridx++; c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 0; c.weighty = 0; JPanel pButtons = new JPanel(); pButtons.setOpaque(false); JButton buttonUp = new JNiceButton(IListFrame.class.getResource("fleche_haut.png")); JButton buttonDown = new JNiceButton(IListFrame.class.getResource("fleche_bas.png")); JButton buttonRemove = new JNiceButton(SQLComponent.class.getResource("delete.png")); { pButtons.add(buttonUp); pButtons.add(buttonDown); pButtons.add(buttonRemove); } panelRight.add(pButtons, c); // Table c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; this.model = new FichePayeModel(1); final JTable table = new JTable(this.model); panelRight.add(new JScrollPane(table), c); FichePayeRenderer rend = new FichePayeRenderer(); table.setDefaultRenderer(String.class, rend); table.setDefaultRenderer(Float.class, rend); // Import profil c.gridx = 1; c.gridy++; c.weightx = 0; c.weighty = 0; c.gridwidth = 1; c.fill = GridBagConstraints.HORIZONTAL; JLabel labelProfil = new JLabel("Importer depuis un profil prdfini"); panelRight.add(labelProfil, c); c.gridwidth = 1; this.comboSelProfil = new ElementComboBox(); // this.comboSelProfil = new ElementComboBox(); this.comboSelProfil.setListIconVisible(false); c.gridx++; c.gridwidth = 1; // this.comboSelProfil.init(eltProfil.getTable().getField("NOM"), null); panelRight.add(this.comboSelProfil, c); JButton buttonImportProfil = new JButton("Importer"); c.gridx++; panelRight.add(buttonImportProfil, c); // Total Periode JPanel panelTotal = new JPanel(); panelTotal.setBorder(BorderFactory.createTitledBorder("Total priode")); panelTotal.setLayout(new GridBagLayout()); GridBagConstraints cPanel = new DefaultGridBagConstraints(); // Salaire brut JLabel labelBrut = new JLabel(getLabelFor("SAL_BRUT")); panelTotal.add(labelBrut, cPanel); JTextField textSalBrut = new JTextField(10); cPanel.gridx++; cPanel.weightx = 0; panelTotal.add(textSalBrut, cPanel); textSalBrut.setEditable(false); textSalBrut.setEnabled(false); // acompte cPanel.gridx++; JLabel labelAcompte = new JLabel(getLabelFor("ACOMPTE")); panelTotal.add(labelAcompte, cPanel); JTextField textAcompte = new JTextField(10); cPanel.gridx++; panelTotal.add(textAcompte, cPanel); // textAcompte.setEditable(false); // textAcompte.setEnabled(false); // Conges Acquis cPanel.gridx++; JLabel labelCongesAcquis = new JLabel(getLabelFor("CONGES_ACQUIS")); panelTotal.add(labelCongesAcquis, cPanel); JTextField textCongesAcquis = new JTextField(10); cPanel.gridx++; panelTotal.add(textCongesAcquis, cPanel); // cotisation salariale cPanel.gridx = 0; cPanel.gridy++; JLabel labelCotSal = new JLabel(getLabelFor("COT_SAL")); panelTotal.add(labelCotSal, cPanel); JTextField textCotSal = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotSal, cPanel); textCotSal.setEditable(false); textCotSal.setEnabled(false); // cotisation patronale cPanel.gridx++; JLabel labelCotPat = new JLabel(getLabelFor("COT_PAT")); panelTotal.add(labelCotPat, cPanel); JTextField textCotPat = new JTextField(10); cPanel.gridx++; panelTotal.add(textCotPat, cPanel); textCotPat.setEditable(false); textCotPat.setEnabled(false); JLabel labelCSG = new JLabel(getLabelFor("CSG")); cPanel.gridx++; panelTotal.add(labelCSG, cPanel); JTextField textCSG = new JTextField(10); cPanel.gridx++; panelTotal.add(textCSG, cPanel); textCSG.setEditable(false); textCSG.setEnabled(false); // net imposable cPanel.gridx = 0; cPanel.gridy++; JLabel labelNetImp = new JLabel(getLabelFor("NET_IMP")); panelTotal.add(labelNetImp, cPanel); JTextField textNetImp = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetImp, cPanel); textNetImp.setEditable(false); textNetImp.setEnabled(false); cPanel.gridx++; JLabel labelNetAPayer = new JLabel(getLabelFor("NET_A_PAYER")); panelTotal.add(labelNetAPayer, cPanel); JTextField textNetAPayer = new JTextField(10); cPanel.gridx++; panelTotal.add(textNetAPayer, cPanel); textNetAPayer.setEditable(false); textNetAPayer.setEnabled(false); c.gridx = 1; c.gridy++; c.gridwidth = GridBagConstraints.REMAINDER; panelRight.add(panelTotal, c); // Cumuls c.gridx = 1; c.gridy++; c.gridwidth = 1; c.fill = GridBagConstraints.NONE; this.buttonValider = new JButton("Valider"); // panelRight.add(buttonValider, c); c.gridx++; c.gridwidth = 1; this.buttonGenCompta = new JButton("Generer la comptabilit"); // panelRight.add(buttonGenCompta, c); c.gridx = 0; c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.fill = GridBagConstraints.BOTH; c.weightx = 1; c.weighty = 1; this.add(new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, this.paneTreeLeft, panelRight), c); // Listeners this.buttonGenCompta.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int[] i = new int[1]; i[0] = getSelectedID(); SQLRow rowMois = getTable().getBase().getTable("MOIS").getRow(selMois.getSelectedId()); new GenerationMvtFichePaye(i, rowMois.getString("NOM"), textAnnee.getText()); } }); this.buttonValider.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.err.println("Validation de la fiche de paye"); validationFiche(); } }); buttonUp.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.upRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonDown.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int newRowSelected = model.downRow(table.getSelectedRow()); if (newRowSelected >= 0) { table.setRowSelectionInterval(newRowSelected, newRowSelected); } } }); buttonRemove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.removeRow(table.getSelectedRow()); } }); tree.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent mE) { TreePath path = tree.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if (obj == null) { return; } if (mE.getClickCount() == 2 && mE.getButton() == MouseEvent.BUTTON1) { if (obj instanceof VariableRowTreeNode) { model.addRowAt(((VariableRowTreeNode) obj).getRow(), table.getSelectedRow()); } } else { if (mE.getButton() == 3) { if (obj instanceof VariableRowTreeNode) { final SQLRow row = ((VariableRowTreeNode) obj).getRow(); JPopupMenu menuDroit = new JPopupMenu(); menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable()), EditFrame.MODIFICATION); edit.selectionId(row.getID(), 0); edit.pack(); edit.setVisible(true); } }); menuDroit.add(new AbstractAction("Nouvelle rubrique") { public void actionPerformed(ActionEvent e) { if (edit != null) { edit.dispose(); } edit = new EditFrame(Configuration.getInstance().getDirectory() .getElement(row.getTable())); edit.pack(); edit.setVisible(true); } }); menuDroit.show(mE.getComponent(), mE.getPoint().x, mE.getPoint().y); } } } } }); this.dateDu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateDu.isEmpty()) { Date d = dateDu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); System.err.println("Du " + cal.getTime()); dateDu.setValue(cal.getTime()); } } } } }); this.dateAu.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { if (!dateAu.isEmpty()) { Date d = dateAu.getValue(); if (d != null) { Calendar cal = Calendar.getInstance(); cal.setTime(d); if (selMois.getSelectedId() > 1 && cal.get(Calendar.MONTH) + 2 != selMois.getSelectedId()) { // TODO checker l'annee // TODO ajouter dans le isValidated du au compris dans le mois // selectionne // Calendar.getInstance().set(Calendar.DAY_OF_MONTH, maxDay); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.MONTH, selMois.getSelectedId() - 2); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); System.err.println("Au " + cal.getTime()); dateAu.setValue(cal.getTime()); } } } } }); this.addRequiredSQLObject(this.textAnnee, "ANNEE"); this.addRequiredSQLObject(this.selMois, "ID_MOIS"); this.addSQLObject(this.comboSelProfil, "ID_PROFIL_PAYE"); this.addSQLObject(textCongesAcquis, "CONGES_ACQUIS"); this.addSQLObject(textCotPat, "COT_PAT"); this.addSQLObject(textCotSal, "COT_SAL"); this.addSQLObject(textCSG, "CSG"); this.addSQLObject(textNetAPayer, "NET_A_PAYER"); this.addSQLObject(textNetImp, "NET_IMP"); this.addSQLObject(textSalBrut, "SAL_BRUT"); this.addSQLObject(textAcompte, "ACOMPTE"); this.addSQLObject(this.selSalCombo, "ID_SALARIE"); this.addRequiredSQLObject(this.dateDu, "DU"); this.addRequiredSQLObject(this.dateAu, "AU"); this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selSalCombo.setButtonsVisible(false); // this.selSalCombo.setVisible(false); buttonImportProfil.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { model.loadFromProfil(comboSelProfil.getSelectedId()); } }); } private boolean isDateValid() { String yearS = this.textAnnee.getText().trim(); int annee = (yearS.length() == 0) ? 0 : Integer.parseInt(yearS); int mois = this.selMois.getSelectedId(); // System.err.println("anne " + annee + " dernAnnee " + this.dernAnnee + " mois " + // mois + " dernMois " + this.dernMois); return ((this.dernAnnee == 0) ? true : annee > this.dernAnnee) || ((this.dernMois == 0 || this.dernMois == 13) ? true : mois > this.dernMois); } @Override public synchronized ValidState getValidState() { // FIXME add fireValidChange() return super.getValidState().and(ValidState.createCached(isDateValid(), "Date invalide")); } public int insert(SQLRow order) { int id = super.insert(order); this.model.updateFields(id); return id; } @Override public void update() { super.update(); this.model.updateFields(this.getSelectedID()); } @Override public void select(SQLRowAccessor r) { // System.err.println("SELECT FICHE ID -> " + r.getID()); super.select(r); if (r != null && r.getID() > 1) { this.model.setFicheID(r.getID()); SQLTable tableSal = getTable().getBase().getTable("SALARIE"); SQLRow rowSal = tableSal.getRow(r.getInt("ID_SALARIE")); this.dernMois = rowSal.getInt("DERNIER_MOIS"); this.dernAnnee = rowSal.getInt("DERNIERE_ANNEE"); this.selSalCombo.setVisible(((Boolean) r.getObject("VALIDE")).booleanValue()); this.paneTreeLeft.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); this.buttonValider.setVisible(!((Boolean) r.getObject("VALIDE")).booleanValue()); setpDateEnabled(!((Boolean) r.getObject("VALIDE")).booleanValue()); } this.selSalCombo.setEditable(false); this.selSalCombo.setEnabled(false); this.selMois.setButtonsVisible(false); this.selSalCombo.setButtonsVisible(false); } private void setpDateEnabled(boolean b) { // System.err.println("Set date enable --> " + b); this.selMois.setEditable(b); // this.selMois.setEnabled(b); this.textAnnee.setEditable(b); this.textAnnee.setEnabled(b); this.dateDu.setEditable(b); this.dateDu.setEnabled(b); this.dateAu.setEditable(b); this.dateAu.setEnabled(b); } private void validationFiche() { this.update(); FichePayeSQLElement.validationFiche(this.getSelectedID()); } protected SQLRowValues createDefaults() { System.err.println("**********Set Defaults on FichePaye.date"); SQLRowValues rowVals = new SQLRowValues(getTable()); Calendar cal = Calendar.getInstance(); rowVals.put("ID_MOIS", cal.get(Calendar.MONTH) + 2); rowVals.put("ANNEE", cal.get(Calendar.YEAR)); cal.set(Calendar.DAY_OF_MONTH, 1); rowVals.put("DU", new java.sql.Date(cal.getTime().getTime())); cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH)); rowVals.put("AU", new java.sql.Date(cal.getTime().getTime())); return rowVals; } }; }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewer.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);/*w w w. j a v a 2 s .co m*/ // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewer.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tellervo.desktop.tridasv2.ui.ComponentViewerOld.java
private void setupTable() { tableModel = new ElementListTableModel(); table = new JXTable(tableModel); tableSorter = new ElementListTableSorter(tableModel, table); table.getTableHeader().addMouseListener(tableSorter); // add sorter & header renderer table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true);// w ww. ja v a2 s.com // set our column widths ElementListTableModel.setupColumnWidths(table); table.setDefaultRenderer(Object.class, new ElementListCellRenderer(this, false)); table.setDefaultRenderer(Boolean.class, new BooleanCellRenderer(this, false)); // hide irrelevent columns TableColumnModelExt colmodel = (TableColumnModelExt) table.getColumnModel(); table.setColumnControlVisible(true); colmodel.getColumnExt(I18n.getText("hidden.MostRecentVersion")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.n")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.rec")).setVisible(false); colmodel.getColumnExt(I18n.getText("dbbrowser.hash")).setVisible(false); // popup menu table.addMouseListener(new PopupListener() { @Override public void showPopup(MouseEvent e) { // only clicks on tables if (!(e.getSource() instanceof JTable)) return; JTable table = (JTable) e.getSource(); ElementListTableModel model = (ElementListTableModel) table.getModel(); // get the row and sanity check int row = table.rowAtPoint(e.getPoint()); if (row < 0 || row >= model.getRowCount()) return; // select it? table.setRowSelectionInterval(row, row); // get the element Element element = model.getElementAt(row); // create and show the menu JPopupMenu popup = new ElementListPopupMenu(element, ComponentViewerOld.this); popup.show(table, e.getX(), e.getY()); } }); }
From source file:org.tmpotter.ui.ActionHandler.java
public void onTableClicked(MouseEvent evt) { javax.swing.JTable table = (javax.swing.JTable) evt.getSource(); Point point = evt.getPoint(); int row = table.rowAtPoint(point); int col = table.columnAtPoint(point); table.setRowSelectionInterval(row, row); table.setColumnSelectionInterval(col, col); tmData.setPositionTextArea(0);/*from w w w . java2 s.co m*/ if (tmData.getIndexPrevious() < tmData.getDocumentOriginalSize()) { tmData.setOriginalDocumentAnt(restoreText(modelMediator.getLeftEdit())); tmData.setTranslationDocumentAnt(restoreText(modelMediator.getRightEdit())); } modelMediator.setLeftEdit(formatText(modelMediator.getLeftSegment(modelMediator.getTmViewSelectedRow()))); modelMediator.setRightEdit(formatText(modelMediator.getRightSegment(modelMediator.getTmViewSelectedRow()))); tmData.setBothIndex(modelMediator.getTmViewSelectedRow()); if (tmData.isIdentTop()) { modelMediator.setJoinEnabled(false); } else { modelMediator.setJoinEnabled(true); } modelMediator.updateTmView(); }
From source file:pcgen.gui2.tabs.EquipInfoTab.java
private List<Integer> getMenuTargets(JTable table, MouseEvent e) { int row = table.rowAtPoint(e.getPoint()); if (!table.isRowSelected(row)) { table.setRowSelectionInterval(row, row); }//from w ww . j a v a 2 s. c o m List<Integer> targets = new ArrayList<>(); for (int selRow : table.getSelectedRows()) { targets.add(selRow); } return targets; }
From source file:pl.otros.logview.api.gui.LogViewPanelWrapper.java
private void addRowAutoScroll() { dataTableModel.addTableModelListener(e -> { if (follow.isSelected() && e.getType() == TableModelEvent.INSERT) { final Runnable r = () -> { try { JTable table = logViewPanel.getTable(); int row = table.getRowCount() - 1; if (row > 0) { Rectangle rect = table.getCellRect(row, 0, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); }/*from w w w. ja va 2s. c o m*/ } catch (IllegalArgumentException iae) { // ignore..out of bounds iae.printStackTrace(); } }; // Wait for JViewPort size update // TODO Find way to invoke this listener after viewport is notified about changes Runnable r2 = () -> { try { Thread.sleep(300); } catch (InterruptedException ignore) { } SwingUtilities.invokeLater(r); }; new Thread(r2).start(); } }); }
From source file:pl.otros.logview.gui.actions.search.SearchAction.java
public void performSearch(String text, SearchDirection direction) { StatusObserver statusObserver = getOtrosApplication().getStatusObserver(); JTabbedPane jTabbedPane = getOtrosApplication().getJTabbedPane(); LogViewPanelWrapper lvPanel = (LogViewPanelWrapper) jTabbedPane.getSelectedComponent(); if (lvPanel == null) { return;//from w ww . j a v a 2s . c om } JTable table = lvPanel.getLogViewPanel().getTable(); NextRowProvider nextRowProvider = NextRowProviderFactory.getFilteredTableRow(table, direction); SearchContext context = new SearchContext(); context.setDataTableModel(lvPanel.getDataTableModel()); SearchMatcher searchMatcher = null; String confKey = null; if (SearchMode.STRING_CONTAINS.equals(searchMode)) { searchMatcher = new StringContainsSearchMatcher(text); confKey = ConfKeys.SEARCH_LAST_STRING; } else if (SearchMode.REGEX.equals(searchMode)) { try { searchMatcher = new RegexMatcher(text); confKey = ConfKeys.SEARCH_LAST_REGEX; } catch (Exception e) { statusObserver.updateStatus("Error in regular expression: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } else if (SearchMode.QUERY.equals(searchMode)) { QueryAcceptCondition acceptCondition; try { acceptCondition = new QueryAcceptCondition(text); searchMatcher = new AcceptConditionSearchMatcher(acceptCondition); confKey = ConfKeys.SEARCH_LAST_QUERY; } catch (RuleException e) { statusObserver.updateStatus("Wrong query rule: " + e.getMessage(), StatusObserver.LEVEL_ERROR); return; } } updateList(confKey, getOtrosApplication().getConfiguration(), text); DefaultComboBoxModel model = (DefaultComboBoxModel) getOtrosApplication().getSearchField().getModel(); model.removeElement(text); model.insertElementAt(text, 0); model.setSelectedItem(text); int maxCount = getOtrosApplication().getConfiguration().getInt(ConfKeys.SEARCH_LAST_COUNT, 30); while (model.getSize() > maxCount) { model.removeElementAt(model.getSize() - 1); } context.setSearchMatcher(searchMatcher); SearchResult searchNext = searchEngine.searchNext(context, nextRowProvider); if (searchNext.isFound()) { int row = table.convertRowIndexToView(searchNext.getRow()); Rectangle rect = table.getCellRect(row, 0, true); table.scrollRectToVisible(rect); table.clearSelection(); table.setRowSelectionInterval(row, row); statusObserver.updateStatus(String.format("Found at row %d", row), StatusObserver.LEVEL_NORMAL); if (markFound) { lvPanel.getDataTableModel().markRows(markerColors, table.convertRowIndexToModel(row)); } scrollToSearchResult( searchMatcher.getFoundTextFragments( lvPanel.getDataTableModel().getLogData(table.convertRowIndexToModel(row))), lvPanel.getLogViewPanel().getLogDetailTextArea()); } else { statusObserver.updateStatus(String.format("\"%s\" not found", text), StatusObserver.LEVEL_WARNING); } }