OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 101 → Rev 102

/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchDetailPanel.java
New file
0,0 → 1,87
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.Component;
import java.math.BigDecimal;
import java.util.Date;
 
import javax.swing.JComponent;
import javax.swing.JPanel;
 
import org.openconcerto.modules.common.batchprocessing.product.HTProcessor;
import org.openconcerto.modules.common.batchprocessing.product.PurchaseProcessor;
import org.openconcerto.modules.common.batchprocessing.product.TTCProcessor;
import org.openconcerto.modules.common.batchprocessing.product.TVAProcessor;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLType;
import org.openconcerto.ui.VFlowLayout;
 
public class BatchDetailPanel extends JPanel {
private BatchProcessor processor;
 
BatchDetailPanel() {
this.setLayout(new VFlowLayout());
}
 
public void setField(SQLField field) {
this.removeAll();
 
final SQLType type = field.getType();
final Class<?> javaType = type.getJavaType();
final String fName = field.getName();
if (fName.equals("PV_TTC")) {
final NumberProcessor p = new TTCProcessor(field);
this.add(p);
this.processor = p;
} else if (fName.equals("PV_HT")) {
final NumberProcessor p = new HTProcessor(field);
this.add(p);
this.processor = p;
} else if (fName.equals("ID_TAXE")) {
final ReferenceProcessor p = new TVAProcessor(field);
this.add(p);
this.processor = p;
} else if (fName.equals("PA_HT")) {
final NumberProcessor p = new PurchaseProcessor(field);
this.add(p);
this.processor = p;
} else if (javaType.equals(Boolean.class)) {
final BooleanProcessor p = new BooleanProcessor(field);
this.add(p);
this.processor = p;
} else if (field.isKey()) {
final ReferenceProcessor p = new ReferenceProcessor(field);
this.add(p);
this.processor = p;
} else if (javaType.equals(String.class)) {
final StringProcessor p = new StringProcessor(field);
this.add(p);
this.processor = p;
} else if (javaType.equals(Date.class)) {
final DateProcessor p = new DateProcessor(field);
this.add(p);
this.processor = p;
} else if (javaType.equals(BigDecimal.class) || javaType.equals(Float.class) || javaType.equals(Double.class) || javaType.equals(Integer.class) || javaType.equals(Long.class)) {
final NumberProcessor p = new NumberProcessor(field);
this.add(p);
this.processor = p;
}
 
revalidate();
repaint();
}
 
public BatchProcessor getProcessor() {
return processor;
}
 
@Override
public void setEnabled(boolean enabled) {
if (processor != null && processor instanceof JComponent) {
Component[] l = ((JComponent) processor).getComponents();
for (int i = 0; i < l.length; i++) {
l[i].setEnabled(false);
}
}
super.setEnabled(enabled);
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/Module.java
New file
0,0 → 1,100
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.List;
 
import javax.swing.AbstractAction;
import javax.swing.JFrame;
 
import org.openconcerto.erp.config.Gestion;
import org.openconcerto.erp.modules.AbstractModule;
import org.openconcerto.erp.modules.ComponentsContext;
import org.openconcerto.erp.modules.ModuleFactory;
import org.openconcerto.erp.modules.ModuleManager;
import org.openconcerto.erp.modules.ModulePackager;
import org.openconcerto.erp.modules.RuntimeModuleFactory;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRequestLog;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.ui.ConnexionPanel;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
import org.openconcerto.sql.view.list.RowAction;
import org.openconcerto.ui.FrameUtil;
 
public final class Module extends AbstractModule {
 
public Module(ModuleFactory f) throws IOException {
super(f);
}
 
@Override
protected void setupComponents(ComponentsContext ctxt) {
 
super.setupComponents(ctxt);
final SQLElement element = ctxt.getElement("ARTICLE");
final RowAction.PredicateRowAction editAction = new RowAction.PredicateRowAction(new AbstractAction("Traitement par lot...") {
 
@Override
public void actionPerformed(ActionEvent e) {
final List<SQLRowValues> rows = IListe.get(e).getSelectedRows();
final int size = rows.size();
if (size > 0) {
final JFrame f = new JFrame();
if (size > 1) {
f.setTitle("Traitement des " + size + " " + element.getPluralName());
} else {
f.setTitle("Traitement d'" + element.getSingularName());
}
FieldFilter filter = new FieldFilter() {
 
@Override
public boolean isFiltered(SQLField f) {
final String fieldName = f.getName();
return fieldName.contains("METRIQUE") || fieldName.equals("ID_STOCK");
}
 
};
 
f.setContentPane(new BatchEditorPanel(rows, filter));
f.pack();
f.setMinimumSize(new Dimension(400, 300));
f.setLocationRelativeTo(IListe.get(e));
FrameUtil.show(f);
}
}
}, false) {
};
editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
element.getRowActions().add(editAction);
 
}
 
@Override
protected void start() {
}
 
@Override
protected void stop() {
}
 
public static void main(String[] args) throws IOException {
System.setProperty(ConnexionPanel.QUICK_LOGIN, "true");
final File propsFile = new File("module.properties");
final ModuleFactory factory = new RuntimeModuleFactory(propsFile);
SQLRequestLog.setEnabled(true);
SQLRequestLog.showFrame();
// uncomment to create and use the jar
final ModulePackager modulePackager = new ModulePackager(propsFile, new File("bin/"));
modulePackager.writeToDir(new File("../OpenConcerto/Modules"));
// final ModuleFactory factory = new JarModuleFactory(jar);
ModuleManager.getInstance().addFactories(new File("../OpenConcerto/Modules"));
ModuleManager.getInstance().addFactoryAndStart(factory, false);
Gestion.main(args);
}
 
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/StringProcessor.java
New file
0,0 → 1,213
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.List;
 
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
public class StringProcessor extends JPanel implements BatchProcessor {
private final SQLField field;
// Editors
final JTextField tReplace = new JTextField();
private JRadioButton bReplace;
final JTextField tPrefix = new JTextField();
private JRadioButton bPrefix;
final JTextField tSuffix = new JTextField();
private JRadioButton bSuffix;
private JRadioButton bLower;
private JRadioButton bUpper;
 
public StringProcessor(SQLField field) {
this.field = field;
 
this.setLayout(new GridBagLayout());
bReplace = new JRadioButton("remplacer par");
bPrefix = new JRadioButton("préfixer par");
bSuffix = new JRadioButton("suffixer par");
bLower = new JRadioButton("mettre en minuscule");
bUpper = new JRadioButton("mettre en majuscule");
 
final ButtonGroup group = new ButtonGroup();
group.add(bReplace);
group.add(bPrefix);
group.add(bSuffix);
group.add(bLower);
group.add(bUpper);
 
GridBagConstraints c = new DefaultGridBagConstraints();
// replace
this.add(bReplace, c);
c.gridx++;
c.weightx = 1;
this.add(tReplace, c);
// prefix
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(bPrefix, c);
c.gridx++;
c.weightx = 1;
this.add(tPrefix, c);
// suffix
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(bSuffix, c);
c.gridx++;
c.weightx = 1;
this.add(tSuffix, c);
//
c.gridx = 0;
c.gridy++;
c.weightx = 0;
c.gridwidth = 2;
this.add(bLower, c);
c.gridy++;
this.add(bUpper, c);
 
tPrefix.setEnabled(false);
tSuffix.setEnabled(false);
group.setSelected(bReplace.getModel(), true);
 
bLower.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tPrefix.setEnabled(false);
tReplace.setEnabled(false);
tSuffix.setEnabled(false);
 
}
});
bUpper.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tPrefix.setEnabled(false);
tReplace.setEnabled(false);
tSuffix.setEnabled(false);
}
});
bPrefix.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tPrefix.setEnabled(true);
tReplace.setEnabled(false);
tSuffix.setEnabled(false);
 
}
});
bSuffix.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tPrefix.setEnabled(false);
tReplace.setEnabled(false);
tSuffix.setEnabled(true);
 
}
});
bReplace.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tPrefix.setEnabled(false);
tReplace.setEnabled(true);
tSuffix.setEnabled(false);
 
}
});
 
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
if (bReplace.isSelected()) {
final String t = ensureSize(tReplace.getText());
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), t);
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bPrefix.isSelected()) {
final String t = tPrefix.getText();
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
String str = sqlRowAccessor.asRow().getString(field.getName());
if (str == null)
str = "";
rowValues.put(field.getName(), ensureSize(t + str));
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bSuffix.isSelected()) {
final String t = tSuffix.getText();
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
String str = sqlRowAccessor.asRow().getString(field.getName());
if (str == null)
str = "";
rowValues.put(field.getName(), ensureSize(str + t));
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bLower.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
String str = sqlRowAccessor.asRow().getString(field.getName());
if (str == null)
str = "";
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), str.toLowerCase());
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bUpper.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
String str = sqlRowAccessor.asRow().getString(field.getName());
if (str == null)
str = "";
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), str.toUpperCase());
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
}
}
 
private String ensureSize(String text) {
if (text.length() < field.getType().getSize()) {
return text;
}
return text.substring(0, field.getType().getSize());
}
 
@Override
public boolean checkParameters() {
if (bReplace.isSelected()) {
return true;
} else if (bPrefix.isSelected()) {
return !tPrefix.getText().isEmpty();
} else if (bSuffix.isSelected()) {
return !bPrefix.getText().isEmpty();
}
return true;
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchEditorPanel.java
New file
0,0 → 1,162
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.Component;
import java.awt.FlowLayout;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
 
import javax.swing.DefaultListCellRenderer;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
 
import org.openconcerto.sql.Configuration;
import org.openconcerto.sql.PropsConfiguration;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.request.SQLFieldTranslator;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JLabelBold;
import org.openconcerto.ui.ReloadPanel;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.SwingWorker2;
 
public class BatchEditorPanel extends JPanel {
 
public BatchEditorPanel(final List<SQLRowValues> rows, FieldFilter filter) {
Configuration conf = PropsConfiguration.getInstance();
final SQLFieldTranslator translator = conf.getTranslator();
Set<SQLField> fields = rows.get(0).getTable().getFields();
List<SQLField> f = new ArrayList<SQLField>();
for (SQLField sqlField : fields) {
if (ForbiddenFieldName.isAllowed(sqlField.getName()) && translator.getLabelFor(sqlField) != null) {
if (filter == null || (filter != null && !filter.isFiltered(sqlField))) {
f.add(sqlField);
}
}
}
 
Collections.sort(f, new Comparator<SQLField>() {
 
@Override
public int compare(SQLField o1, SQLField o2) {
return translator.getLabelFor(o1).compareToIgnoreCase(translator.getLabelFor(o2));
}
});
this.setLayout(new GridBagLayout());
GridBagConstraints c = new DefaultGridBagConstraints();
this.add(new JLabel("Champ"), c);
 
final JComboBox combo = new JComboBox(f.toArray());
combo.setRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
value = translator.getLabelFor(((SQLField) value));
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
}
});
 
combo.setSelectedIndex(0);
 
c.gridx++;
c.weightx = 1;
c.fill = GridBagConstraints.NONE;
this.add(combo, c);
c.gridx = 0;
c.gridy++;
c.gridwidth = 2;
c.fill = GridBagConstraints.HORIZONTAL;
this.add(new JLabelBold("Action à appliquer"), c);
c.weightx = 1;
c.weighty = 1;
c.fill = GridBagConstraints.HORIZONTAL;
c.gridy++;
c.anchor = GridBagConstraints.NORTHWEST;
final BatchDetailPanel comp = new BatchDetailPanel();
comp.setField((SQLField) combo.getSelectedItem());
this.add(comp, c);
 
JPanel actions = new JPanel();
actions.setLayout(new FlowLayout(FlowLayout.RIGHT));
final JButton buttonProcess = new JButton("Lancer le traitement");
 
final JButton buttonCancel = new JButton("Annuler");
final ReloadPanel reload = new ReloadPanel();
actions.add(reload);
actions.add(buttonProcess);
 
actions.add(buttonCancel);
 
c.gridy++;
c.weighty = 0;
this.add(actions, c);
 
combo.addItemListener(new ItemListener() {
 
@Override
public void itemStateChanged(ItemEvent e) {
comp.setField((SQLField) combo.getSelectedItem());
 
}
});
buttonProcess.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
if (!comp.getProcessor().checkParameters()) {
JOptionPane.showMessageDialog(BatchEditorPanel.this, "Paramètres non valides");
return;
}
 
buttonProcess.setEnabled(false);
buttonCancel.setEnabled(false);
comp.setEnabled(false);
 
combo.setEnabled(false);
reload.setMode(ReloadPanel.MODE_ROTATE);
SwingWorker2<Object, Object> w = new SwingWorker2<Object, Object>() {
 
@Override
protected Object doInBackground() throws Exception {
try {
final BatchProcessor processor = comp.getProcessor();
processor.process(rows);
} catch (Exception e) {
ExceptionHandler.handle("Echec du traitement", e);
}
return null;
}
 
@Override
protected void done() {
reload.setMode(ReloadPanel.MODE_EMPTY);
JOptionPane.showMessageDialog(BatchEditorPanel.this, "Traitement terminé");
SwingUtilities.getWindowAncestor(BatchEditorPanel.this).dispose();
}
 
};
w.execute();
}
});
buttonCancel.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
SwingUtilities.getWindowAncestor(BatchEditorPanel.this).dispose();
}
});
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/NumberProcessor.java
New file
0,0 → 1,207
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.math.BigDecimal;
import java.sql.SQLException;
import java.util.List;
 
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
public class NumberProcessor extends JPanel implements BatchProcessor {
 
private final SQLField field;
// Editors
final JTextField tReplace = new JTextField();
private JRadioButton bReplace;
final JTextField tAdd = new JTextField();
private JRadioButton bAdd;
 
final JTextField tRemove = new JTextField();
private JRadioButton bRemove;
 
public NumberProcessor(SQLField field) {
this.field = field;
 
this.setLayout(new GridBagLayout());
bReplace = new JRadioButton("remplacer par");
bAdd = new JRadioButton("augmenter de");
bRemove = new JRadioButton("diminuer de");
 
final ButtonGroup group = new ButtonGroup();
group.add(bReplace);
group.add(bAdd);
group.add(bRemove);
 
GridBagConstraints c = new DefaultGridBagConstraints();
// replace
this.add(bReplace, c);
c.gridx++;
c.weightx = 1;
this.add(tReplace, c);
// add
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(bAdd, c);
c.gridx++;
c.weightx = 1;
this.add(tAdd, c);
// remove
c.gridx = 0;
c.gridy++;
c.weightx = 0;
this.add(bRemove, c);
c.gridx++;
c.weightx = 1;
this.add(tRemove, c);
//
tAdd.setEnabled(false);
tRemove.setEnabled(false);
 
tAdd.setInputVerifier(new DecimalOrPercentVerifier());
tRemove.setInputVerifier(new DecimalOrPercentVerifier());
 
group.setSelected(bReplace.getModel(), true);
 
bReplace.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tReplace.setEnabled(true);
tAdd.setEnabled(false);
tRemove.setEnabled(false);
}
});
bAdd.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tReplace.setEnabled(false);
tAdd.setEnabled(true);
tRemove.setEnabled(false);
 
}
});
bRemove.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
tReplace.setEnabled(false);
tAdd.setEnabled(false);
tRemove.setEnabled(true);
 
}
});
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
if (bReplace.isSelected()) {
BigDecimal v = new BigDecimal(this.tReplace.getText().trim());
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), decimalToFieldType(v));
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bAdd.isSelected()) {
 
String t = this.tAdd.getText().trim();
boolean isPercent = false;
if (t.endsWith("%")) {
t = t.substring(0, t.length() - 1);
isPercent = true;
}
 
BigDecimal v = new BigDecimal(t);
 
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
final BigDecimal value = sqlRowAccessor.asRow().getBigDecimal(field.getName());
if (value != null) {
if (isPercent) {
rowValues.put(field.getName(), decimalToFieldType(value.multiply(v.divide(new BigDecimal(100)).add(BigDecimal.ONE))));
} else {
rowValues.put(field.getName(), decimalToFieldType(value.add(v)));
}
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
}
} else if (bRemove.isSelected()) {
String t = this.tRemove.getText().trim();
boolean isPercent = false;
if (t.endsWith("%")) {
t = t.substring(0, t.length() - 1);
isPercent = true;
}
 
BigDecimal v = new BigDecimal(t);
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
 
final BigDecimal value = sqlRowAccessor.asRow().getBigDecimal(field.getName());
if (value != null) {
if (isPercent) {
rowValues.put(field.getName(), decimalToFieldType(value.multiply(v.divide(new BigDecimal(-100)).add(BigDecimal.ONE))));
} else {
rowValues.put(field.getName(), decimalToFieldType(value.add(v)));
}
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
}
}
}
 
private Object decimalToFieldType(BigDecimal v) {
final Class<?> javaType = field.getType().getJavaType();
if (javaType.equals(BigDecimal.class)) {
return v;
} else if (javaType.equals(Float.class)) {
return v.floatValue();
} else if (javaType.equals(Double.class)) {
return v.doubleValue();
} else if (javaType.equals(Integer.class)) {
return v.intValue();
} else if (javaType.equals(Long.class)) {
return v.longValue();
}
return v;
}
 
@Override
public boolean checkParameters() {
if (bReplace.isSelected()) {
try {
BigDecimal v = new BigDecimal(this.tReplace.getText().trim());
return v != null;
} catch (Exception e) {
return false;
}
} else if (bAdd.isSelected()) {
return tAdd.getInputVerifier().verify(tAdd);
 
} else if (bRemove.isSelected()) {
return tRemove.getInputVerifier().verify(tRemove);
}
return false;
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
// TODO Auto-generated method stub
 
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/FieldFilter.java
New file
0,0 → 1,7
package org.openconcerto.modules.common.batchprocessing;
 
import org.openconcerto.sql.model.SQLField;
 
public interface FieldFilter {
boolean isFiltered(SQLField f);
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ModuleResources.properties
New file
0,0 → 1,2
name=Batch processing
description=Change values of multiple items at a time
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/DecimalOrPercentVerifier.java
New file
0,0 → 1,33
package org.openconcerto.modules.common.batchprocessing;
 
import java.math.BigDecimal;
 
import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JTextField;
 
public class DecimalOrPercentVerifier extends InputVerifier {
 
@Override
public boolean verify(JComponent input) {
String text = ((JTextField) input).getText().trim();
if (text.isEmpty()) {
return false;
}
 
if (text.endsWith("%")) {
text = text.substring(0, text.length() - 1).trim();
 
}
 
try {
BigDecimal value = new BigDecimal(text);
 
return value != null;
} catch (NumberFormatException e) {
return false;
}
 
}
 
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/DateProcessor.java
New file
0,0 → 1,52
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.FlowLayout;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.ui.JDate;
 
public class DateProcessor extends JPanel implements BatchProcessor {
private final JDate d = new JDate(true);
private final SQLField field;
 
public DateProcessor(SQLField field) {
this.field = field;
this.setLayout(new FlowLayout());
this.add(new JLabel("forcer la date au "));
this.add(d);
 
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
final Date date = d.getDate();
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), date);
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
 
}
 
@Override
public boolean checkParameters() {
final Date date = d.getDate();
if (date == null && !field.isNullable()) {
return false;
}
return true;
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ReferenceProcessor.java
New file
0,0 → 1,64
package org.openconcerto.modules.common.batchprocessing;
 
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.sql.SQLException;
import java.util.List;
 
import javax.swing.JLabel;
import javax.swing.JPanel;
 
import org.openconcerto.erp.config.ComptaPropsConfiguration;
import org.openconcerto.sql.element.SQLElement;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.sqlobject.ElementComboBox;
import org.openconcerto.ui.warning.JLabelWarning;
 
public class ReferenceProcessor extends JPanel implements BatchProcessor {
 
private final SQLField field;
final SQLElement element;
private ElementComboBox combo;
 
public ReferenceProcessor(SQLField field) {
this.field = field;
this.element = ComptaPropsConfiguration.getInstanceCompta().getDirectory().getElement(field.getForeignTable());
 
if (element != null) {
this.setLayout(new BorderLayout());
this.add(new JLabel("remplacer par "), BorderLayout.WEST);
combo = new ElementComboBox(true, 200);
combo.setMinimal();
combo.setAddIconVisible(false);
combo.init(element);
this.add(combo, BorderLayout.CENTER);
} else {
this.setLayout(new FlowLayout());
this.add(new JLabelWarning("No element for table " + field.getTable().getName()));
}
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
 
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), combo.getSelectedId());
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
 
}
 
@Override
public boolean checkParameters() {
return this.element != null;
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
 
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BooleanProcessor.java
New file
0,0 → 1,75
package org.openconcerto.modules.common.batchprocessing;
 
import java.sql.SQLException;
import java.util.List;
 
import javax.swing.ButtonGroup;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
 
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.ui.VFlowLayout;
 
public class BooleanProcessor extends JPanel implements BatchProcessor {
private final SQLField field;
 
private JRadioButton bTrue;
private JRadioButton bFalse;
private JRadioButton bInvert;
 
public BooleanProcessor(SQLField field) {
this.field = field;
this.setLayout(new VFlowLayout());
bTrue = new JRadioButton("forcer à vrai");
bFalse = new JRadioButton("forcer à faux");
bInvert = new JRadioButton("inverser");
final ButtonGroup group = new ButtonGroup();
group.add(bTrue);
group.add(bFalse);
group.add(bInvert);
this.add(bTrue);
this.add(bFalse);
this.add(bInvert);
group.setSelected(bTrue.getModel(), true);
 
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
if (bTrue.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), Boolean.TRUE);
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bFalse.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(field.getName(), Boolean.FALSE);
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
} else if (bInvert.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
final Boolean boolean1 = sqlRowAccessor.asRow().getBoolean(field.getName());
if (boolean1 != null) {
rowValues.put(field.getName(), boolean1.equals(Boolean.FALSE));
processBeforeUpdate(sqlRowAccessor, rowValues);
rowValues.update();
}
}
}
}
 
@Override
public boolean checkParameters() {
return true;
}
 
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/product/HTProcessor.java
New file
0,0 → 1,29
package org.openconcerto.modules.common.batchprocessing.product;
 
import java.math.BigDecimal;
 
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.utils.ConvertDevise;
import org.openconcerto.modules.common.batchprocessing.NumberProcessor;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
 
public class HTProcessor extends NumberProcessor {
 
public HTProcessor(SQLField field) {
super(field);
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
// M.A.J. du TTC et du HT métrique
final SQLRow r = from.asRow();
final BigDecimal taux = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(r.getForeignID("ID_TAXE")));
final BigDecimal ht = to.getBigDecimal("PV_HT");
final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, from.getTable().getField("PV_TTC").getType().getDecimalDigits());
to.put("PV_TTC", ttc);
to.put("PRIX_METRIQUE_VT_1", ht);
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/product/PurchaseProcessor.java
New file
0,0 → 1,21
package org.openconcerto.modules.common.batchprocessing.product;
 
import java.math.BigDecimal;
 
import org.openconcerto.modules.common.batchprocessing.NumberProcessor;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
 
public class PurchaseProcessor extends NumberProcessor {
 
public PurchaseProcessor(SQLField field) {
super(field);
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
final BigDecimal ht = to.getBigDecimal("PA_HT");
to.put("PRIX_METRIQUE_HA_1", ht);
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/product/TTCProcessor.java
New file
0,0 → 1,29
package org.openconcerto.modules.common.batchprocessing.product;
 
import java.math.BigDecimal;
 
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.utils.ConvertDevise;
import org.openconcerto.modules.common.batchprocessing.NumberProcessor;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
 
public class TTCProcessor extends NumberProcessor {
 
public TTCProcessor(SQLField field) {
super(field);
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
// M.A.J. du HT et du HT métrique
final SQLRow r = from.asRow();
final BigDecimal taux = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(r.getForeignID("ID_TAXE")));
final BigDecimal ttc = to.getBigDecimal("PV_TTC");
final BigDecimal ht = ConvertDevise.getHtFromTtc(ttc, taux, from.getTable().getField("PV_HT").getType().getDecimalDigits());
to.put("PV_HT", ht);
to.put("PRIX_METRIQUE_VT_1", ht);
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/product/TVAProcessor.java
New file
0,0 → 1,28
package org.openconcerto.modules.common.batchprocessing.product;
 
import java.math.BigDecimal;
 
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.utils.ConvertDevise;
import org.openconcerto.modules.common.batchprocessing.ReferenceProcessor;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
 
public class TVAProcessor extends ReferenceProcessor {
 
public TVAProcessor(SQLField field) {
super(field);
}
 
@Override
public void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to) {
// M.A.J. du TTC
final SQLRow r = from.asRow();
final BigDecimal taux = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(to.getForeignID("ID_TAXE")));
final BigDecimal ht = r.getBigDecimal("PV_HT");
final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, r.getTable().getField("PV_TTC").getType().getDecimalDigits());
to.put("PV_TTC", ttc);
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchProcessor.java
New file
0,0 → 1,17
package org.openconcerto.modules.common.batchprocessing;
 
import java.sql.SQLException;
import java.util.List;
 
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
 
public interface BatchProcessor {
 
boolean checkParameters();
 
void process(List<SQLRowValues> r) throws SQLException;
 
void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to);
 
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ForbiddenFieldName.java
New file
0,0 → 1,9
package org.openconcerto.modules.common.batchprocessing;
 
public class ForbiddenFieldName {
public static boolean isAllowed(String field) {
String f = field.toUpperCase();
return !(f.equals("ARCHIVE") || f.equals("ORDRE") || f.equals("ID_USER_CREATE") || f.equals("ID_USER_COMMON_CREATE") || f.equals("ID_USER_MODIFY") || f.equals("ID_USER_COMMON_MODIFY")
|| f.equals("MODIFICATION_DATE") || f.equals("CREATION_DATE"));
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ModuleResources_fr.properties
New file
0,0 → 1,2
name=Traitements par lot
description=Modification d'éléments par lot
/trunk/Modules/Module Batch Processing/.classpath
New file
0,0 → 1,7
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/OpenConcerto"/>
<classpathentry kind="output" path="bin"/>
</classpath>
/trunk/Modules/Module Batch Processing/module.properties
New file
0,0 → 1,6
# [\p{Alnum}_.]{3,}
id=org.openconcerto.modules.common.batchprocessing
# \p{Digit}(\.\p{Digit}+)?
version=1.0
contact=ILM Informatique
/trunk/Modules/Module Batch Processing/.project
New file
0,0 → 1,17
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Module Batch Processing</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>