List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". 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;// ww w . j a v a 2 s .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.erp.core.humanresources.payroll.element.VariablePayeSQLElement.java
public SQLComponent createComponent() { return new BaseSQLComponent(this) { private ValidState validVarName; private JRadioButton radioVal = new JRadioButton("Valeur"); private JRadioButton radioFormule = new JRadioButton("Formule"); private final JTextField textValeur = new JTextField(); // private final ITextArea textFormule = new ITextArea(); private final VariableTree treeVariable = new VariableTree(); private final JTextField textNom = new JTextField(); private final JLabel labelWarningBadVar = new JLabelWarning(); private ElementComboBox comboSelSal; private EditFrame edit = null; private final SQLJavaEditor textFormule = new SQLJavaEditor(getMapTree()); public void addViews() { this.setLayout(new GridBagLayout()); final GridBagConstraints c = new DefaultGridBagConstraints(); this.validVarName = null; this.textFormule.setEditable(false); // Arbre des variables JScrollPane sc = new JScrollPane(this.treeVariable); sc.setPreferredSize(new Dimension(150, sc.getPreferredSize().height)); this.treeVariable.addMouseListener(new MouseAdapter() { public void mousePressed(final MouseEvent mE) { if (mE.getButton() == MouseEvent.BUTTON3) { JPopupMenu menuDroit = new JPopupMenu(); TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); final Object obj = path.getLastPathComponent(); if ((obj == null) || !(obj instanceof VariableRowTreeNode)) { return; }//from ww w . j a v a2s . co m menuDroit.add(new AbstractAction("Editer") { public void actionPerformed(ActionEvent e) { if (edit == null) { edit = new EditFrame(getElement(), EditFrame.MODIFICATION); } System.err.println("Action performed"); if (obj != null) { System.err.println("Object not null --> " + obj.toString()); if (obj instanceof VariableRowTreeNode) { System.err.println("Object VariableRowTreeNode"); VariableRowTreeNode varNode = (VariableRowTreeNode) obj; edit.selectionId(varNode.getID(), 1); edit.setVisible(true); } } } }); menuDroit.show((Component) mE.getSource(), mE.getPoint().x, mE.getPoint().y); } else { if (mE.getClickCount() == 2) { TreePath path = treeVariable.getClosestPathForLocation(mE.getPoint().x, mE.getPoint().y); Object obj = path.getLastPathComponent(); if (obj != null) { if (obj instanceof FormuleTreeNode) { final FormuleTreeNode n = (FormuleTreeNode) obj; int start = textFormule.getSelectionStart(); String tmp = textFormule.getText(); textFormule.setText(tmp.substring(0, start) + n.getTextValue() + tmp.substring(start, tmp.length())); } } } } } }); JPanel panelDroite = new JPanel(); panelDroite.setLayout(new GridBagLayout()); // Categorie JTextField textCategorie = new JTextField(); c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy = 0; JLabel labelCategorie = new JLabel("Catgorie"); panelDroite.add(labelCategorie, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(textCategorie, c); c.gridwidth = 1; // Nom c.fill = GridBagConstraints.HORIZONTAL; c.gridheight = 1; c.gridx = 1; c.gridy++; JLabel labelNom = new JLabel("Nom"); panelDroite.add(labelNom, c); c.gridx++; c.weightx = 1; panelDroite.add(this.textNom, c); this.textNom.getDocument().addDocumentListener(new SimpleDocumentListener() { @Override public void update(DocumentEvent e) { updateValidVarName(); } }); c.gridx++; c.weightx = 0; panelDroite.add(this.labelWarningBadVar, c); // Description JLabel labelInfos = new JLabel(getLabelFor("INFOS")); ITextArea textInfos = new ITextArea(); c.gridy++; c.gridx = 1; c.gridwidth = 1; c.weightx = 0; panelDroite.add(labelInfos, c); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 1; c.weighty = 0; panelDroite.add(textInfos, c); // Valeur c.gridx = 1; c.gridy++; c.gridwidth = 1; c.weightx = 0; panelDroite.add(this.radioVal, c); c.gridx++; c.weightx = 1; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textValeur, c); c.gridwidth = 1; c.gridx = 1; c.gridy++; panelDroite.add(this.radioFormule, c); c.gridx++; c.weightx = 1; c.weighty = 1; c.fill = GridBagConstraints.BOTH; c.gridwidth = GridBagConstraints.REMAINDER; panelDroite.add(this.textFormule, c); c.gridwidth = 1; ButtonGroup group = new ButtonGroup(); group.add(this.radioVal); group.add(this.radioFormule); this.radioVal.setSelected(true); setFormuleEnabled(false); this.radioVal.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(false); } }); this.radioFormule.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setFormuleEnabled(true); } }); c.gridy++; c.gridx = 1; c.weighty = 0; c.weightx = 0; c.fill = GridBagConstraints.HORIZONTAL; this.comboSelSal = new ElementComboBox(false); this.comboSelSal.init(getDirectory().getElement(SalarieSQLElement.class)); c.gridx++; c.gridwidth = GridBagConstraints.REMAINDER; c.weightx = 0; panelDroite.add(this.comboSelSal, c); c.gridwidth = 1; JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, sc, panelDroite); c.fill = GridBagConstraints.BOTH; c.gridx = 0; c.gridy = 0; c.weightx = 1; c.weighty = 1; this.add(split, c); this.addRequiredSQLObject(this.textNom, "NOM"); this.addSQLObject(this.textValeur, "VALEUR"); this.addSQLObject(this.textFormule, "FORMULE"); this.addSQLObject(textCategorie, "CATEGORIE"); this.addSQLObject(textInfos, "INFOS"); this.comboSelSal.addValueListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { // TODO Auto-generated method stub textFormule.setSalarieID(comboSelSal.getSelectedId()); } }); } @Override public synchronized ValidState getValidState() { return super.getValidState().and(this.validVarName); } private void setFormuleEnabled(boolean b) { if (b) { this.textValeur.setText(""); } else { this.textFormule.setText(""); } this.textValeur.setEditable(!b); this.textValeur.setEnabled(!b); this.textFormule.setEditable(b); this.textFormule.setEnabled(b); this.treeVariable.setEnabled(b); this.treeVariable.setEditable(b); } private void setValidVarName(ValidState s) { if (!s.equals(this.validVarName)) { this.validVarName = s; final boolean warningVisible = !s.isValid(); if (warningVisible) this.labelWarningBadVar.setText(s.getValidationText()); this.labelWarningBadVar.setVisible(warningVisible); this.fireValidChange(); } } private void updateValidVarName() { this.setValidVarName(this.computeValidVarName()); } private ValidState computeValidVarName() { // on vrifie si la syntaxe de la variable est correct (chiffre lettre et _) final String varName = this.textNom.getText().trim(); System.err.println("Verification de la validit du nom de la variable."); if (varName.length() == 0) { return VAR_NO_NAME; } // ne contient que des chiffre lettre et _ et ne commence pas par un chiffre if (!isJavaVar(varName)) { return VAR_NAME_NOT_CORRECT; } // on vrifie que la variable n'existe pas dja SQLSelect selAllVarName = new SQLSelect(getTable().getBase()); selAllVarName.addSelect(VariablePayeSQLElement.this.getTable().getField("ID")); Where w = new Where(VariablePayeSQLElement.this.getTable().getField("NOM"), "=", varName); w = w.and(new Where(VariablePayeSQLElement.this.getTable().getKey(), "!=", getSelectedID())); selAllVarName.setWhere(w); String reqAllVarName = selAllVarName.asString();// + " AND '" + varName.trim() + "' // REGEXP VARIABLE_PAYE.NOM"; Object[] objKeysRowName = ((List) getTable().getBase().getDataSource().execute(reqAllVarName, new ArrayListHandler())).toArray(); if (objKeysRowName.length > 0) { return VAR_ALREADY_EXIST; } else { // Impossible de crer une variable du meme nom qu'un champ du salarie if (isForbidden(varName)) return VAR_ALREADY_EXIST; this.textFormule.setVarAssign(varName); return ValidState.getTrueInstance(); } } private boolean isJavaVar(String s) { if ((s.charAt(0) >= '0') && ((s.charAt(0) <= '9'))) { System.err.println("Erreur la variable commence par un chiffre!!"); return false; } else { for (int i = 0; i < s.length(); i++) { if (!(((s.charAt(i) >= '0') && (s.charAt(i) <= '9')) || (s.charAt(i) >= 'a') && (s.charAt(i) <= 'z') || (s.charAt(i) >= 'A') && (s.charAt(i) <= 'Z') || (s.charAt(i) == '_'))) { System.err.println("Erreur la variable contient un caractere incorrect!!"); return false; } } return (!CTokenMarker.getKeywords().isExisting(s)); } } @Override public void select(SQLRowAccessor r) { super.select(r); // System.err.println("Select RowAccess -------> " + r.getID() + " For Object " + // this.hashCode()); if (r != null) { if (r.getString("FORMULE").trim().length() == 0) { this.radioVal.setSelected(true); setFormuleEnabled(false); } else { this.radioFormule.setSelected(true); setFormuleEnabled(true); } this.textFormule.setVarAssign(r.getString("NOM")); } this.updateValidVarName(); } }; }
From source file:org.openconcerto.erp.model.FamilleArticleTree.java
public void mousePressed(MouseEvent e) { Object o = this.getSelectionPath().getLastPathComponent(); int id = 1;/*from w w w.j ava 2 s. c om*/ if (e.getButton() == MouseEvent.BUTTON3) { if (o instanceof FamilleTreeNode) { final FamilleTreeNode nodeSelect = (FamilleTreeNode) o; id = nodeSelect.getId(); } final int idSelect = id; // Ajouter, supprimer, modifier une famille JPopupMenu menu = new JPopupMenu(); menu.add(new AbstractAction("Ajouter une famille") { public void actionPerformed(ActionEvent e) { EditFrame frameAddFamille = new EditFrame(familleElt, EditFrame.CREATION); SQLRowValues rowVals = new SQLRowValues(familleElt.getTable()); rowVals.put("ID_FAMILLE_ARTICLE_PERE", idSelect); frameAddFamille.getSQLComponent().select(rowVals); frameAddFamille.setVisible(true); } }); if (idSelect > 1) { menu.add(new AbstractAction("Modifier") { public void actionPerformed(ActionEvent e) { EditFrame frameModFamille = new EditFrame(familleElt, EditFrame.MODIFICATION); frameModFamille.selectionId(idSelect, 1); frameModFamille.setVisible(true); } }); menu.add(new AbstractAction("Supprimer") { public void actionPerformed(ActionEvent e) { try { familleElt.archive(idSelect); } catch (SQLException e1) { e1.printStackTrace(); } } }); } menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y); } }
From source file:org.openconcerto.erp.panel.ITreeSelection.java
public void mousePressed(MouseEvent e) { TreePath path = this.getSelectionPath(); if (path != null) { Object o = path.getLastPathComponent(); int id = 1; if (e.getButton() == MouseEvent.BUTTON3) { final int idSelect = getSelectedID(); // Ajouter, supprimer, modifier un lment dans l'arbre JPopupMenu menu = new JPopupMenu(); menu.add(new AbstractAction("Ajouter un lment") { public void actionPerformed(ActionEvent e) { addElement(idSelect); }// w w w . j a va2 s. c om }); if (idSelect > 1) { menu.add(new AbstractAction("Modifier") { public void actionPerformed(ActionEvent e) { modifyElement(idSelect); } }); menu.add(new AbstractAction("Supprimer") { public void actionPerformed(ActionEvent e) { removeElement(idSelect); } }); } menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y); } } }
From source file:org.openconcerto.map.ui.ITextComboVilleViewer.java
public ITextComboVilleViewer() { this.setOpaque(false); this.setLayout(new BorderLayout()); this.supp = new ValueChangeSupport<String>(this); this.emptyHelper = new EmptyObjectHelper(this, new Predicate() { public boolean evaluate(final Object object) { // object: le getUncheckedValue() return ITextComboVilleViewer.this.getValue() == null || ITextComboVilleViewer.this.getValue().trim().length() == 0; }/* ww w . ja v a 2 s . com*/ }); this.text.addValueListener(new PropertyChangeListener() { public void propertyChange(final PropertyChangeEvent evt) { ITextComboVilleViewer.this.supp.fireValueChange(); } }); this.cache = new ITextComboCacheVille(); this.text.initCache(this.cache); this.add(this.text, BorderLayout.CENTER); this.add(this.button, BorderLayout.EAST); this.button.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final JFrame f = new JFrame(); final MapViewerPanel mapViewerPanel = new MapViewerPanel(true); f.setContentPane(mapViewerPanel); f.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); f.setSize(600, 500); f.setMinimumSize(new Dimension(600, 500)); final File conf = new File(System.getProperty("user.home"), ".java" + File.separator + "ilm" + File.separator + "map" + File.separator); new WindowStateManager(f, new File(conf, "Configuration" + File.separator + "MapFrame.properties"), true).loadState(); f.setVisible(true); if (ITextComboVilleViewer.this.currentVille != null) { final long x = ITextComboVilleViewer.this.currentVille.getXLambert(); final long y = ITextComboVilleViewer.this.currentVille.getYLambert(); f.setTitle(ITextComboVilleViewer.this.currentVille.getName()); mapViewerPanel.getVilleRendererPanel().centerScreenXYLambert(x, y); mapViewerPanel.getVilleRendererPanel().setHighlight(ITextComboVilleViewer.this.currentVille); mapViewerPanel.getVilleRendererPanel().setAlwayVisible(ITextComboVilleViewer.this.currentVille); } } }); this.text.getDocument().addDocumentListener(new DocumentListener() { public void changedUpdate(final DocumentEvent e) { ITextComboVilleViewer.this.currentVille = Ville .getVilleFromVilleEtCode(ITextComboVilleViewer.this.text.getValue()); ITextComboVilleViewer.this.button.setEnabled( ITextComboVilleViewer.this.currentVille != null && ITextComboVilleViewer.this.isEnabled()); } public void insertUpdate(final DocumentEvent e) { this.changedUpdate(e); } public void removeUpdate(final DocumentEvent e) { this.changedUpdate(e); } }); final JPopupMenu popupMenu = new JPopupMenu(); // FIXME ajouter la possibilit de supprimer une ville prcdemment enregistre final JMenuItem menuItem = new JMenuItem("Enregistrer cette ville"); menuItem.addActionListener(new ActionListener() { public void actionPerformed(final ActionEvent e) { final String t = ITextComboVilleViewer.this.text.getTextComp().getText(); ITextComboVilleViewer.this.cache.addToCache(t); final Ville createVilleFrom = ITextComboVilleViewer.this.cache.createVilleFrom(t); if (createVilleFrom != null) { final String villeEtCode = createVilleFrom.getVilleEtCode(); ITextComboVilleViewer.this.setValue(villeEtCode); ITextComboVilleViewer.this.firePropertyChange("value", null, villeEtCode); } } }); popupMenu.add(menuItem); this.text.getTextComp().addMouseListener(new PopupMouseListener(popupMenu)); }
From source file:org.openconcerto.task.TodoListPanel.java
void initPopUp() { TablePopupMouseListener.add(this.t, new ITransformer<MouseEvent, JPopupMenu>() { @Override//from w w w .java 2s .co 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; } }); }
From source file:org.openehealth.coms.cc.consent_applet.applet.ConsentApplet.java
/** * MouseListener used to select items from the list of Rule descriptions, allows for deletion of Rules * /*from w w w .j a va 2 s .c o m*/ * @return */ private MouseListener getRuleListMouseAdapter() { return new MouseListener() { private JList list; public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e)) { list = ((JList) e.getSource()); list.setSelectedIndex(getRow(e.getPoint())); JPopupMenu menu = new JPopupMenu(); menu.add(new RemoveRule(list)); Point pt = SwingUtilities.convertPoint(e.getComponent(), e.getPoint(), list); menu.show(list, pt.x, pt.y); } } private int getRow(Point point) { return list.locationToIndex(point); } public void mouseClicked(MouseEvent arg0) { } public void mouseEntered(MouseEvent arg0) { } public void mouseExited(MouseEvent arg0) { } public void mouseReleased(MouseEvent arg0) { } }; }
From source file:org.openestate.tool.helloworld.HelloWorldFrameSidebarExtension.java
private JPopupMenu createActionMenu(final DbHelloWorldObject object) { // create a popup menu for the Hello World sidebar final JPopupMenu popup = new JPopupMenu(); // add action into the popup menu for sidebar refresh popup.add(new JMenuItem(new HelloWorldPlugin.SidebarRefreshAction())); // add action into the popup menu for a new object popup.add(new JMenuItem(new HelloWorldPlugin.ObjectFormAction())); // no object is selected in the sidebar //noinspection StatementWithEmptyBody if (object == null) { }/*from w w w . ja v a2 s. c om*/ // add further actions for the selected sidebar entry else { String title = StringUtils.abbreviate(StringUtils.trimToEmpty(object.name), 30); popup.add( ImmoToolUtils.createMenuSeparator("<html>" + StringEscapeUtils.escapeHtml4(title) + "</html>")); // add action into the popup menu for editing the selected object popup.add(new HelloWorldPlugin.ObjectFormAction(object.id)); // add action into the popup menu for removing the selected object popup.add(new HelloWorldPlugin.ObjectRemoveAction(object.id)); } // return the created popup menu return popup; }
From source file:org.openestate.tool.helloworld.HelloWorldObjectViewPanel.java
@Override protected void doShowActions(Component component, int x, int y) { JPopupMenu popup = new JPopupMenu(); popup.add(createDefaultCopyAction(currentObject != null && currentObject.id > 0 && HelloWorldPlugin.isUserAllowedTo(HelloWorldPermission.OBJECTS_EDIT))); popup.add(createDefaultRemoveAction(currentObject != null && currentObject.id > 0 && mayRemoveObject)); boolean addonItemAdded = false; for (ObjectViewExtension addon : addons) { JMenuItem[] items = addon.createActionMenuItems(currentObject); if (ArrayUtils.isEmpty(items)) continue; for (JMenuItem item : items) { if (!addonItemAdded) { addonItemAdded = true;/*ww w . j a v a 2s .c o m*/ popup.addSeparator(); } popup.add(item); } } popup.show(component, x, y); }
From source file:org.openmicroscopy.shoola.agents.fsimporter.util.FileImportComponent.java
/** * Creates or recycles the menu corresponding to the import status. * /*from ww w. ja va 2 s . c o m*/ * @return See above. */ private JPopupMenu createActionMenu() { if (menu != null) return menu; menu = new JPopupMenu(); JMenuItem item; String logText = "View Import Log"; String checksumText = "View Checksum"; String exceptionText = "View Exception"; Object result = statusLabel.getImportResult(); switch (resultIndex) { case FAILURE_LIBRARY: menu.add(new JMenuItem(new AbstractAction(exceptionText) { public void actionPerformed(ActionEvent e) { viewError(); } })); break; case FAILURE: menu.add(new JMenuItem(new AbstractAction("Submit") { public void actionPerformed(ActionEvent e) { submitError(); } })); menu.add(new JMenuItem(new AbstractAction(exceptionText) { public void actionPerformed(ActionEvent e) { viewError(); } })); break; case UPLOAD_FAILURE: menu.add(new JMenuItem(new AbstractAction("Retry") { public void actionPerformed(ActionEvent e) { retry(); } })); break; case SUCCESS: logText = "Import Log"; checksumText = "Checksum"; item = new JMenuItem(new AbstractAction("In Full Viewer") { public void actionPerformed(ActionEvent e) { launchFullViewer(); } }); boolean b = false; if (result instanceof Collection) b = ((Collection) result).size() == 1; item.setEnabled(b && !statusLabel.isHCS()); menu.add(item); item = new JMenuItem(new AbstractAction("In Data Browser") { public void actionPerformed(ActionEvent e) { browse(); } }); item.setEnabled(browsable); menu.add(item); } item = new JMenuItem(new AbstractAction(logText) { public void actionPerformed(ActionEvent e) { displayLogFile(); } }); item.setEnabled(statusLabel.getLogFileID() > 0 || statusLabel.getFileset() != null); menu.add(item); item = new JMenuItem(new AbstractAction(checksumText) { public void actionPerformed(ActionEvent e) { showChecksumDetails(); } }); item.setEnabled(statusLabel.hasChecksum()); menu.add(item); return menu; }