예제 #1
0
 protected final void export(ExportType type) {
   try {
     final AbstractExport createExport =
         type.createExport(ComptaPropsConfiguration.getInstanceCompta().getRootSociete());
     createExport.setNbCharCpt((Integer) this.spinNbChar.getValue());
     createExport.setNbCharLimitCpt((Integer) this.spinNbCharLimit.getValue());
     final Tuple2<File, Number> res =
         createExport.export(
             this.fileChooser.getSelectedFile(),
             this.du.getDate(),
             this.au.getDate(),
             this.boxJournal.getSelectedRow(),
             this.boxExport.isSelected());
     if (res.get1().intValue() == 0) {
       JOptionPane.showMessageDialog(
           this, "Aucune écriture trouvée. La période est-elle correcte ?");
     } else {
       // Notify
       JOptionPane.showMessageDialog(
           this,
           "L'export des "
               + res.get1()
               + " écritures est terminé.\nLe fichier créé est "
               + res.get0().getAbsolutePath());
       // Close frame
       SwingUtilities.getWindowAncestor(this).dispose();
     }
   } catch (final FileNotFoundException ex) {
     JOptionPane.showMessageDialog(this, "Création du fichier impossible : " + ex.getMessage());
   } catch (Exception e) {
     ExceptionHandler.handle(this, "Erreur d'export", e);
   }
 }
예제 #2
0
  public ExportPanel() {
    super(new GridBagLayout());
    final GridBagConstraints c = new DefaultGridBagConstraints();

    c.gridwidth = 4;
    this.add(new JLabelBold("Export des écritures comptables"), c);

    // Fichier de destination
    final JPanel panelFichier = new JPanel(new GridBagLayout());
    final GridBagConstraints cFic = new DefaultGridBagConstraints();
    cFic.insets.left = 0;
    cFic.insets.bottom = 0;
    cFic.gridx++;
    cFic.weightx = 1;
    panelFichier.add(this.textDestination, cFic);

    final JButton buttonChoose = new JButton("...");
    cFic.gridx++;
    cFic.weightx = 0;
    cFic.fill = GridBagConstraints.NONE;
    panelFichier.add(buttonChoose, cFic);

    this.buttonGen.setEnabled(false);
    this.textDestination.setEditable(false);

    this.fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    buttonChoose.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(final ActionEvent e) {
            final int answer = ExportPanel.this.fileChooser.showSaveDialog(ExportPanel.this);
            if (answer == JFileChooser.APPROVE_OPTION) {
              ExportPanel.this.textDestination.setText(
                  ExportPanel.this.fileChooser.getSelectedFile().getAbsolutePath());
            }
            ExportPanel.this.buttonGen.setEnabled(answer == JFileChooser.APPROVE_OPTION);
          }
        });
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 1;
    this.add(new JLabel("Dossier de destination", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    this.add(panelFichier, c);

    c.gridx = 0;
    c.gridwidth = 1;
    c.gridy++;
    c.weightx = 0;
    c.anchor = GridBagConstraints.EAST;
    this.add(new JLabel("Période du", SwingUtilities.RIGHT), c);

    c.gridx++;
    c.anchor = GridBagConstraints.WEST;
    c.fill = GridBagConstraints.NONE;
    this.du = new JDate(true);
    this.add(this.du, c);

    c.gridx++;
    this.add(new JLabel("au"), c);

    c.gridx++;
    this.au = new JDate(true);
    this.add(this.au, c);

    this.boxExport.setSelected(true);
    c.gridy++;
    c.gridx = 0;
    c.gridwidth = 3;
    this.add(this.boxExport, c);

    final SQLElement elt =
        Configuration.getInstance().getDirectory().getElement(JournalSQLElement.class);
    final ComboSQLRequest comboRequest = elt.getComboRequest(true);
    comboRequest.setUndefLabel("Tous");
    this.boxJournal.init(elt, comboRequest);
    c.gridy++;
    c.gridx = 0;
    c.weightx = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel("Ecritures du journal", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    c.fill = GridBagConstraints.NONE;
    this.boxJournal.setValue(JournalSQLElement.VENTES);
    this.add(this.boxJournal, c);

    c.gridy++;
    c.gridx = 0;
    c.weightx = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(new JLabel("Type d'export", SwingUtilities.RIGHT), c);
    c.gridx++;
    c.weightx = 1;
    c.gridwidth = 4;
    final JComboBox comboType = new JComboBox(ExportType.values());
    comboType.setRenderer(
        new DefaultListCellRenderer() {
          @Override
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return super.getListCellRendererComponent(
                list, ((ExportType) value).getLabel(), index, isSelected, cellHasFocus);
          }
        });
    c.fill = GridBagConstraints.NONE;
    comboType.setSelectedIndex(0);
    this.add(comboType, c);

    final JPanel p = new JPanel(new GridBagLayout());
    GridBagConstraints c2 = new DefaultGridBagConstraints();
    c2.gridx = 0;
    c2.weightx = 1;
    c2.gridwidth = GridBagConstraints.REMAINDER;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(new TitledSeparator("Option export relation expert", true), c2);

    c2.gridy++;
    c2.gridx = 0;
    c2.weightx = 0;
    c2.gridwidth = 3;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(
        new JLabel(
            "Formater les numéros de compte suivant le nombre de caractères suivants",
            SwingUtilities.RIGHT),
        c2);
    c2.gridx += 3;
    c2.weightx = 1;
    c2.gridwidth = 1;

    p.add(this.spinNbChar, c2);

    c2.gridy++;
    c2.gridx = 0;
    c2.weightx = 0;
    c2.gridwidth = 3;
    c2.fill = GridBagConstraints.HORIZONTAL;
    p.add(
        new JLabel("Limiter le nombre de caractéres des numéros compte à", SwingUtilities.RIGHT),
        c2);
    c2.gridx += 3;
    c2.weightx = 1;
    c2.gridwidth = 1;
    p.add(this.spinNbCharLimit, c2);

    c.gridy++;
    c.gridx = 0;
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.HORIZONTAL;
    this.add(p, c);

    c.gridy++;
    c.weightx = 1;
    c.gridx = 0;
    c.gridwidth = 1;
    final JPanel panelButton = new JPanel();
    panelButton.add(this.buttonGen);
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.SOUTHEAST;
    c.weightx = 0;
    c.weighty = 1;
    this.add(panelButton, c);
    this.buttonGen.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            export((ExportType) comboType.getSelectedItem());
          }
        });
    p.setVisible(false);
    comboType.addActionListener(
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent e) {
            p.setVisible((ExportType) comboType.getSelectedItem() == ExportType.RelationExpert);
          }
        });
  }