List of usage examples for javax.swing JTable getSelectedRow
@BeanProperty(bound = false) public int getSelectedRow()
From source file:org.eclipse.jubula.rc.swing.listener.RecordActions.java
/** * select cell/*w ww. j av a 2s. co m*/ * @param jtbl JTable * @param id IComponentIdentifier * @param clickcount int * @param a Action * @param mouseButton the mouse button used */ protected void selectTableCell(JTable jtbl, IComponentIdentifier id, int clickcount, Action a, int mouseButton) { int row = jtbl.getSelectedRow(); int column = jtbl.getSelectedColumn(); int count = clickcount; if (count < 1) { count = 1; } String clCount = (new Integer(count).toString()); String rowStr = (new Integer(row + 1)).toString(); String columnStr = (new Integer(column + 1)).toString(); List tblValues = new LinkedList(); tblValues.add(rowStr); tblValues.add(MatchUtil.EQUALS); tblValues.add(columnStr); tblValues.add(MatchUtil.EQUALS); tblValues.add(clCount); tblValues.add("50"); //$NON-NLS-1$ tblValues.add("percent"); //$NON-NLS-1$ tblValues.add("50"); //$NON-NLS-1$ tblValues.add("percent"); //$NON-NLS-1$ tblValues.add(Constants.REC_EXT_SELECTION); tblValues.add(String.valueOf(mouseButton)); String logName = createLogicalName(jtbl, id); createCAP(a, id, tblValues, logName); }
From source file:org.isatools.isacreator.gui.formelements.SubForm.java
protected void setupTableTabBehaviour() { InputMap im = scrollTable.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = scrollTable.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { int rowSel = scrollTable.getSelectedRow(); int colSel = scrollTable.getSelectedColumn(); if (rowSel == (scrollTable.getRowCount() - 1)) { scrollTable.setRowSelectionInterval(0, 0); if ((colSel + 1) == scrollTable.getColumnCount()) { scrollTable.setColumnSelectionInterval(0, 0); } else { scrollTable.setColumnSelectionInterval(colSel + 1, colSel + 1); }// w w w. j av a2 s . c o m } else { rowSel = rowSel + 1; scrollTable.setRowSelectionInterval(rowSel, rowSel); if (colSel > -1) { scrollTable.setColumnSelectionInterval(colSel, colSel); } } scrollTable.scrollRectToVisible(scrollTable.getCellRect(rowSel, colSel, true)); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; scrollTable.getActionMap().put(im.get(tab), newTabAction); }
From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java
/** * Setup the JTable with its desired characteristics *///from w ww. jav a 2s . c o m private void setupTable() { table = new CustomTable(spreadsheetModel); table.setShowGrid(true); table.setGridColor(Color.BLACK); table.setShowVerticalLines(true); table.setShowHorizontalLines(true); table.setGridColor(UIHelper.LIGHT_GREEN_COLOR); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(true); table.setAutoCreateColumnsFromModel(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.getSelectionModel().addListSelectionListener(this); table.getColumnModel().getSelectionModel().addListSelectionListener(this); table.getTableHeader().setReorderingAllowed(true); table.getColumnModel().addColumnModelListener(this); try { table.setDefaultRenderer(Class.forName("java.lang.Object"), new SpreadsheetCellRenderer()); } catch (ClassNotFoundException e) { // ignore this error } table.addMouseListener(this); table.getTableHeader().addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent event) { } public void mouseMoved(MouseEvent event) { // display a tooltip when user hovers over a column. tooltip is derived // from the description of a field from the TableReferenceObject. JTable table = ((JTableHeader) event.getSource()).getTable(); TableColumnModel colModel = table.getColumnModel(); int colIndex = colModel.getColumnIndexAtX(event.getX()); // greater than 1 to account for the row no. being the first col if (colIndex >= 1) { TableColumn tc = colModel.getColumn(colIndex); if (tc != null) { try { table.getTableHeader().setToolTipText(getFieldDescription(tc)); } catch (Exception e) { // ignore this error } } } } }); //table.getColumnModel().addColumnModelListener(this); InputMap im = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); KeyStroke tab = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0); // Override the default tab behaviour // Tab to the next editable cell. When no editable cells goto next cell. final Action previousTabAction = table.getActionMap().get(im.get(tab)); Action newTabAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { // maintain previous tab action procedure previousTabAction.actionPerformed(e); JTable table = (JTable) e.getSource(); int row = table.getSelectedRow(); int originalRow = row; int column = table.getSelectedColumn(); int originalColumn = column; while (!table.isCellEditable(row, column)) { previousTabAction.actionPerformed(e); row = table.getSelectedRow(); column = table.getSelectedColumn(); // Back to where we started, get out. if ((row == originalRow) && (column == originalColumn)) { break; } } if (table.editCellAt(row, column)) { table.getEditorComponent().requestFocusInWindow(); } } }; table.getActionMap().put(im.get(tab), newTabAction); TableColumnModel model = table.getColumnModel(); String previousColumnName = null; for (int columnIndex = 0; columnIndex < tableReferenceObject.getHeaders().size(); columnIndex++) { if (!model.getColumn(columnIndex).getHeaderValue().toString() .equals(TableReferenceObject.ROW_NO_TEXT)) { model.getColumn(columnIndex).setHeaderRenderer(columnRenderer); model.getColumn(columnIndex).setPreferredWidth(spreadsheetFunctions .calcColWidths(model.getColumn(columnIndex).getHeaderValue().toString())); // add appropriate cell editor for cell. spreadsheetFunctions.addCellEditor(model.getColumn(columnIndex), previousColumnName); previousColumnName = model.getColumn(columnIndex).getHeaderValue().toString(); } else { model.getColumn(columnIndex).setHeaderRenderer(new RowNumberCellRenderer()); } } JTableHeader header = table.getTableHeader(); header.setBackground(UIHelper.BG_COLOR); header.addMouseListener(new HeaderListener(header, columnRenderer)); table.addNotify(); }
From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java
/** * @deprecated Move to ResultController hierarchy. *///w w w . ja v a2 s . com 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. *//*from www.java 2 s .c om*/ 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.CollectController.java
/** * command: delete current collectable in details<br> * Deletes the current collectable in Details mode. * * @deprecated Move to DetailsController and make private. *///from w w w .j a va 2 s .c o m public void cmdDeleteCurrentCollectableInDetailsImpl() { 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; } checkedDeleteSelectedCollectable(); getSearchStrategy().search(true); if (iNewSelectedRow == -1) { tblResult.getSelectionModel().clearSelection(); // switch to new mode: getResultController().getSearchResultStrategy().refreshResult(); } else { tblResult.getSelectionModel().setSelectionInterval(iNewSelectedRow, iNewSelectedRow); // go into view mode again: enterViewMode(); } } catch (CommonPermissionException ex) { final String sErrorMessage = getSpringLocaleDelegate().getMessage("GenericObjectCollectController.69", "Sie verf\u00fcgen nicht \u00fcber die ausreichenden Rechte, um diesen Datensatz zu l\u00f6schen."); Errors.getInstance().showExceptionDialog(getTab(), sErrorMessage, ex); } catch (CommonBusinessException ex) { if (!handleSpecialException(ex)) { Errors.getInstance().showExceptionDialog(getTab(), getSpringLocaleDelegate().getMessage("GenericObjectCollectController.31", "Der Datensatz konnte nicht gel\u00f6scht werden."), ex); } } }
From source file:org.nuclos.client.ui.collect.result.ResultController.java
/** * command: select columns//from w ww .j av a 2 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.finance.accounting.ui.PlanComptableGPanel.java
public JTable creerJTable(ClasseCompte ccTmp) { // NO_UCD final PlanComptableGModel model; if (this.radioCompteDeveloppe.isSelected()) { model = new PlanComptableGModel(ccTmp, 3); } else if (this.radioCompteAbrege.isSelected()) { model = new PlanComptableGModel(ccTmp, 2); } else {//from w w w. j a v a2 s . com model = new PlanComptableGModel(ccTmp, 1); } final JTable table = new JTable(model) { public JToolTip createToolTip() { JMultiLineToolTip t = new JMultiLineToolTip(); t.setFixedWidth(500); return t; } }; table.getColumnModel().getColumn(0).setCellRenderer(new PlanComptableCellRenderer(0)); table.getColumnModel().getColumn(1).setCellRenderer(new PlanComptableCellRenderer(0)); // TODO calcul de la taille de la colone numero de compte table.getColumnModel().getColumn(0).setMaxWidth(90); table.getTableHeader().setReorderingAllowed(false); table.addMouseMotionListener(new MouseMotionAdapter() { int lastRow = -1; public void mouseMoved(final MouseEvent e) { final Point p = new Point(e.getX(), e.getY()); SwingUtilities.invokeLater(new Runnable() { public void run() { final int row = table.rowAtPoint(p); if (lastRow != row) { lastRow = row; String strTmp = ((Compte) (model.getComptes().get(lastRow))).getInfos(); if (strTmp.length() != 0) { table.setToolTipText(strTmp); } else { table.setToolTipText(null); } } } }); } }); if (this.actionClickDroit != null) { // System.out.println("Ajout menu droit"); table.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { actionDroitTable(e, table); } } }); } // Enable row selection (default) /** * table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); * * table.setSelectionMode(table.getSelectionModel().MULTIPLE_INTERVAL_SELECTION); */ table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { int selectedRow = table.getSelectedRow(); if (selectedRow < 0) { // Pas de selection textInfos.setText("Pas de compte slctionn"); } else { textInfos.setText(((Compte) (model.getComptes().get(selectedRow))).getInfos()); } } }); return table; }
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;// w w w . j a v a 2s . c om 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.openconcerto.task.TodoListPanel.java
void initPopUp() { TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() { @Override//from w ww . jav a 2s .c o m public JPopupMenu transformChecked(MouseEvent evt) { final JTable table = (JTable) evt.getSource(); final int modelIndex = TodoListPanel.this.sorter.modelIndex(table.getSelectedRow()); final JPopupMenu res = new JPopupMenu(); // Avancer d'un jour Action act = new AbstractAction() { public void actionPerformed(ActionEvent e) { final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex); if (element != null) { final Date ts = element.getExpectedDate(); final Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(ts.getTime()); cal.add(Calendar.DAY_OF_YEAR, 1); SwingUtilities.invokeLater(new Runnable() { public void run() { ts.setTime(cal.getTimeInMillis()); element.setExpectedDate(ts); element.commitChangesAndWait(); table.repaint(); } }); } } }; act.putValue(Action.NAME, TM.tr("moveOneDay")); res.add(act); // Marquer comme ralis act = new AbstractAction() { public void actionPerformed(ActionEvent e) { TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex); if (element != null) { element.setDone(true); element.commitChangesAndWait(); table.repaint(); } } }; act.putValue(Action.NAME, TM.tr("markDone")); res.add(act); // Suppression act = new AbstractAction() { public void actionPerformed(ActionEvent e) { TodoListPanel.this.model.deleteTaskAtIndex(modelIndex); table.repaint(); } }; act.putValue(Action.NAME, TM.tr("delete")); res.add(act); final TodoListElement element = TodoListPanel.this.model.getTaskAtRow(modelIndex); SQLRowValues rowTache = element.getRowValues(); List<AbstractAction> actions = TacheActionManager.getInstance().getActionsForTaskRow(rowTache); for (AbstractAction abstractAction : actions) { res.add(abstractAction); } return res; } }); }