List of usage examples for javax.swing JPopupMenu add
public JMenuItem add(Action a)
Action
object. From source file:org.nuclos.client.ui.collect.component.CollectableOptionGroup.java
@Override public JPopupMenu newJPopupMenu() { // Note that the default entries (as specified in AbstractCollectableComponent) are ignored. final JPopupMenu result = new JPopupMenu(); final JMenuItem miClear = CollectableOptionGroup.this.newClearEntry(); if (CollectableOptionGroup.this.isSearchComponent()) { miClear.setText(SpringLocaleDelegate.getInstance().getMessage("RootNode.2", "<Alle>")); }//from www. ja va 2 s . c o m result.add(miClear); return result; }
From source file:org.nuclos.client.ui.collect.SubForm.java
/** * @Deprecated Never use this directly, instead use {@link #addToolbarMenuItems(List)}. *//*from w w w .j a v a 2 s .com*/ private MouseListener newToolbarContextMenuListener(final JComponent parent, final JTable table) { MouseListener res = new MouseAdapter() { @Override public void mouseClicked(MouseEvent mev) { if (SwingUtilities.isRightMouseButton(mev)) { List<JComponent> items = new ArrayList<JComponent>(); addToolbarMenuItems(items); if (items.isEmpty()) return; JPopupMenu popup = new JPopupMenu(); for (JComponent c : items) popup.add(c); popup.show(parent, mev.getX(), mev.getY()); } if (SwingUtilities.isLeftMouseButton(mev) && mev.getClickCount() == 2) { int row = table.rowAtPoint(mev.getPoint()); int column = table.columnAtPoint(mev.getPoint()); LOG.info(StringUtils.concat("Doubleclick on subform: column=", column, ",row=", row)); if (row == -1 || column == -1) { if (toolbarMenuItems.get(ToolbarFunction.NEW.name()).isEnabled()) { actionPerformed(ToolbarFunction.NEW.name()); } } } } }; return res; }
From source file:org.omegat.gui.properties.SegmentPropertiesArea.java
private void populateLocalContextMenuOptions(JPopupMenu contextMenu, Point p) { final String key = viewImpl.getKeyAtPoint(p); if (key == null) { return;/*from ww w.j av a 2s.c o m*/ } String displayKey = key; if (!Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)) { try { displayKey = OStrings .getString(ISegmentPropertiesView.PROPERTY_TRANSLATION_KEY + key.toUpperCase()); } catch (MissingResourceException ignore) { // If this is not a known key then we can't translate it, // so use the "raw" key instead. } } String label = StringUtil.format(OStrings.getString("SEGPROP_CONTEXTMENU_NOTIFY_ON_PROP"), displayKey); final JMenuItem notifyOnItem = new JCheckBoxMenuItem(label); notifyOnItem.setSelected(getKeysToNotify().contains(key)); notifyOnItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setKeyToNotify(key, notifyOnItem.isSelected()); } }); contextMenu.add(notifyOnItem); }
From source file:org.omegat.gui.properties.SegmentPropertiesArea.java
@Override public void populatePaneMenu(JPopupMenu contextMenu) { JMenuItem tableModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_TABLE_MODE")); tableModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesTableView.class)); tableModeItem.addActionListener(new ActionListener() { @Override//from w w w.jav a2 s . c o m public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesTableView.class); } }); JMenuItem listModeItem = new JCheckBoxMenuItem(OStrings.getString("SEGPROP_CONTEXTMENU_LIST_MODE")); listModeItem.setSelected(viewImpl.getClass().equals(SegmentPropertiesListView.class)); listModeItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { toggleMode(SegmentPropertiesListView.class); } }); ButtonGroup group = new ButtonGroup(); group.add(tableModeItem); group.add(listModeItem); contextMenu.add(tableModeItem); contextMenu.add(listModeItem); contextMenu.addSeparator(); final JMenuItem toggleKeyTranslationItem = new JCheckBoxMenuItem( OStrings.getString("SEGPROP_CONTEXTMENU_RAW_KEYS")); toggleKeyTranslationItem.setSelected(Preferences.isPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS)); toggleKeyTranslationItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Preferences.setPreference(Preferences.SEGPROPS_SHOW_RAW_KEYS, toggleKeyTranslationItem.isSelected()); viewImpl.update(); } }); contextMenu.add(toggleKeyTranslationItem); }
From source file:org.omegat.gui.scripting.ScriptingWindow.java
private void setupRunButtons(JPanel panel) { m_btnRunScript = new JButton(); Mnemonics.setLocalizedText(m_btnRunScript, OStrings.getString("SCW_RUN_SCRIPT")); m_btnRunScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnRunScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnRunScript.addActionListener(new ActionListener() { @Override/*from ww w . j a v a 2s . co m*/ public void actionPerformed(ActionEvent a) { runScript(); } }); panel.add(m_btnRunScript); m_btnCancelScript = new JButton(); Mnemonics.setLocalizedText(m_btnCancelScript, OStrings.getString("SCW_CANCEL_SCRIPT")); m_btnCancelScript.setToolTipText(OStrings.getString("SCW_CANCEL_BUTTON_TOOLTIP")); m_btnCancelScript.setAlignmentX(Component.LEFT_ALIGNMENT); m_btnCancelScript.setHorizontalAlignment(SwingConstants.LEFT); m_btnCancelScript.addActionListener(e -> cancelCurrentScript()); panel.add(m_btnCancelScript); for (int i = 0; i < NUMBERS_OF_QUICK_SCRIPTS; i++) { final int index = i; final int scriptKey = scriptKey(index); m_quickScriptButtons[i] = new JButton(String.valueOf(scriptKey)); // Run a script from the quick button bar m_quickScriptButtons[i].addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent a) { if (Preferences.existsPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey)) { runQuickScript(index); } else { logResult(StringUtil.format(OStrings.getString("SCW_NO_SCRIPT_BOUND"), scriptKey)); } } }); JPopupMenu quickScriptPopup = new JPopupMenu(); // Add a script to the quick script button bar final JMenuItem addQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_ADD_SCRIPT")); addQuickScriptMenuItem.addActionListener(new QuickScriptUpdater(index)); quickScriptPopup.add(addQuickScriptMenuItem); // Remove a script from the button bar final JMenuItem removeQuickScriptMenuItem = new JMenuItem(OStrings.getString("SCW_REMOVE_SCRIPT")); removeQuickScriptMenuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent evt) { String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, "(unknown)"); logResult(StringUtil.format(OStrings.getString("SCW_REMOVED_QUICK_SCRIPT"), scriptName, scriptKey)); Preferences.setPreference(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, ""); m_quickScriptButtons[index].setToolTipText(OStrings.getString("SCW_NO_SCRIPT_SET")); m_quickScriptButtons[index].setText(" " + scriptKey + " "); unsetQuickScriptMenu(index); } }); quickScriptPopup.add(removeQuickScriptMenuItem); quickScriptPopup.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { // Disable add a script command if script selection empty addQuickScriptMenuItem.setEnabled(!m_scriptList.isSelectionEmpty()); // Disable remove a script command if the quick run button is not bounded String scriptName = Preferences .getPreferenceDefault(Preferences.SCRIPTS_QUICK_PREFIX + scriptKey, null); removeQuickScriptMenuItem.setEnabled(!StringUtil.isEmpty(scriptName)); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { // do nothing } @Override public void popupMenuCanceled(PopupMenuEvent e) { // do nothing } }); m_quickScriptButtons[i].setComponentPopupMenu(quickScriptPopup); panel.add(m_quickScriptButtons[i]); } }
From source file:org.openconcerto.erp.core.finance.accounting.element.AnalytiqueSQLElement.java
private void actionDroitOnglet(final int index, final MouseEvent e) { JPopupMenu pop = new JPopupMenu(); pop.add(new AbstractAction("Ajouter un axe") { public void actionPerformed(ActionEvent e) { if (ajoutAxeFrame == null) { ajoutAxeFrame = new AjouterAxeAnalytiqueFrame(a); }/*from ww w . jav a2 s. co m*/ ajoutAxeFrame.pack(); ajoutAxeFrame.setVisible(true); } }); // si un onglet est selectionn if (index != -1) { pop.add(new AbstractAction("Supprimer l'axe") { public void actionPerformed(ActionEvent e) { supprimerAxe(index); } }); pop.add(new AbstractAction("Modifier le nom") { public void actionPerformed(ActionEvent aE) { actionModifierAxe(e, index); } }); } pop.show(e.getComponent(), e.getX(), e.getY()); System.out.println("Click droit onglet"); }
From source file:org.openconcerto.erp.core.finance.accounting.ui.EtatJournauxPanel.java
private JPanel creerJournalMoisPanel(final Date date, long debit, long credit, final Journal jrnl) { final JPanel panelMoisCompte = new JPanel(); panelMoisCompte.setLayout(new GridBagLayout()); final GridBagConstraints c = new GridBagConstraints(); c.insets = new Insets(2, 2, 1, 2); c.fill = GridBagConstraints.HORIZONTAL; c.anchor = GridBagConstraints.NORTHWEST; c.gridx = 0;/*from www . j ava 2s . co m*/ c.gridy = 0; c.gridwidth = 1; c.gridheight = 1; c.weightx = 1; c.weighty = 0; panelMoisCompte.setBorder(BorderFactory.createTitledBorder(dateFormat.format(date))); // Date du mois panelMoisCompte.add(new JLabel(dateFormat.format(date)), c); // Totaux du mois c.gridx++; panelMoisCompte.add(new JLabel(" dbit : " + GestionDevise.currencyToString(debit)), c); c.gridx++; panelMoisCompte.add(new JLabel(" crdit : " + GestionDevise.currencyToString(credit)), c); // Bouton dtails JButton boutonShow = new JButton("+/-"); boutonShow.setOpaque(false); boutonShow.setHorizontalAlignment(SwingConstants.LEFT); c.weightx = 0; c.gridx++; panelMoisCompte.add(boutonShow, c); boutonShow.addActionListener(new ActionListener() { private boolean isShow = false; private ListPanelEcritures listEcriture; public void actionPerformed(ActionEvent e) { System.err.println(this.isShow); // Afficher la JTable du compte if (!this.isShow) { final SQLElement element = Configuration.getInstance().getDirectory().getElement("ECRITURE"); final SQLTable ecrTable = element.getTable(); Calendar cal = Calendar.getInstance(); cal.setTime(date); cal.set(Calendar.DATE, 1); Date inf = cal.getTime(); cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE)); Date sup = cal.getTime(); System.out.println("Inf : " + inf + " Sup : " + sup); Where w = new Where(ecrTable.getField("ID_JOURNAL"), "=", jrnl.getId()); Where w2 = new Where(ecrTable.getField("DATE"), inf, sup); if (!UserManager.getInstance().getCurrentUser().getRights() .haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) { // TODO Show Restricted acces in UI w = w.and(new Where(ecrTable.getField("COMPTE_NUMERO"), "LIKE", "411%")); } this.listEcriture = new ListPanelEcritures(element, w.and(w2)); this.listEcriture.setModificationVisible(false); this.listEcriture.setAjoutVisible(false); this.listEcriture.setSuppressionVisible(false); this.listEcriture.getListe().setSQLEditable(false); Dimension d; // Taille limite 200 maximum if (this.listEcriture.getListe().getPreferredSize().height > 200) { d = new Dimension(this.listEcriture.getListe().getPreferredSize().width, 200); } else { d = new Dimension(this.listEcriture.getListe().getPreferredSize().width, this.listEcriture.getListe().getPreferredSize().height + 30); } this.listEcriture.getListe().setPreferredSize(d); // c.gridy = 2; c.gridx = 0; c.gridy = 1; c.gridwidth = 4; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; this.listEcriture.getListe().setSQLEditable(false); panelMoisCompte.add(this.listEcriture, c); this.listEcriture.getListe().getJTable().addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { JPopupMenu menu = new JPopupMenu(); menu.add(new AbstractAction("Voir la source") { public void actionPerformed(ActionEvent e) { SQLRow row = base.getTable("ECRITURE") .getRow(listEcriture.getListe().getSelectedId()); MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT")); } }); menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y); } } }); } else { panelMoisCompte.remove(this.listEcriture); System.out.println("Hide ListEcriture"); panelMoisCompte.repaint(); panelMoisCompte.revalidate(); } this.isShow = !this.isShow; SwingUtilities.getRoot(panelMoisCompte).repaint(); } }); return panelMoisCompte; }
From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java
/** * Cree un JTable contenant les ecritures du compte pass en argument * //from w w w. j a v a 2s.c o m * @param compte * @return null si aucune ecriture */ private JTable createJTableCompte(Compte compte) { // on cree la JTable final JTable tableTmp = creerJTable(compte); if (tableTmp != null) { // On met en place le renderer EcritureGrandLivreRenderer ecritureRenderer = new EcritureGrandLivreRenderer( ((TableSorter) tableTmp.getModel())); for (int j = 0; j < tableTmp.getColumnCount(); j++) { tableTmp.getColumnModel().getColumn(j).setCellRenderer(ecritureRenderer); } // Gestion de la souris sur la JTable tableTmp.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); menuDroit.add(new AbstractAction("Voir la source") { public void actionPerformed(ActionEvent e) { int row = tableTmp.rowAtPoint(mE.getPoint()); TableSorter s = (TableSorter) tableTmp.getModel(); int modelIndex = s.modelIndex(row); ConsultCompteModel consultCompteModel = ((ConsultCompteModel) s.getTableModel()); Ecriture ecriture = consultCompteModel.getEcritures().get(modelIndex); MouvementSQLElement.showSource(ecriture.getIdMvt()); } }); menuDroit.show(mE.getComponent(), mE.getX(), mE.getY()); } } }); } return tableTmp; }
From source file:org.openconcerto.erp.core.finance.accounting.ui.PlanComptableGPanel.java
private void actionDroitTable(MouseEvent e, final JTable table) { JPopupMenu menuDroit = new JPopupMenu(); for (int i = 0; i < this.actionClickDroit.size(); i++) { menuDroit.add((AbstractAction) this.actionClickDroit.get(i)); }// w ww . j ava2 s.c om menuDroit.add(new AbstractAction("Tout slectionner") { public void actionPerformed(ActionEvent e) { table.selectAll(); } }); menuDroit.show(e.getComponent(), e.getX(), e.getY()); System.out.println("Click droit sur JTable"); }
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 w w.j a va 2s . 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; } }; }