OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Compare Revisions

Regard whitespace Rev 182 → Rev 183

/trunk/Modules/Module Customer Support/src/org/openconcerto/modules/customersupport/CustomerSupportTicketSQLElement.java
92,7 → 92,7
addHistoriqueAction.setPredicate(IListeEvent.createSelectionCountPredicate(0, Integer.MAX_VALUE));
getRowActions().add(addHistoriqueAction);
 
MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(CustomerSupportTicketSheetXML.class);
MouseSheetXmlListeListener l = new MouseSheetXmlListeListener(this, CustomerSupportTicketSheetXML.class);
 
getRowActions().addAll(l.getRowActions());
}
/trunk/Modules/Module Customer Support/src/org/openconcerto/modules/customersupport/CustomerSupportTicketSQLComponent.java
49,7 → 49,7
}
SQLRowValues rowValsHisto = new SQLRowValues(getTable().getTable(Module.TABLE_CUSTOMER_SUPPORT_TICKET_HISTORY));
rowValsHisto.put("INFORMATION", "Ouverture du ticket");
rowValsHisto.put("DATE", row.getObject("DATE"));
// rowValsHisto.put("DATE", row.getObject("DATE"));
rowValsHisto.put("ID_USER_COMMON", row.getForeignID("ID_USER_COMMON"));
rowValsHisto.put("ID_" + getTable().getName(), createEmptyUpdateRow);
createEmptyUpdateRow.commit();
/trunk/Modules/Module Customer Support/src/org/openconcerto/modules/customersupport/CustomerSupportTicketSheetXML.java
10,7 → 10,7
 
public class CustomerSupportTicketSheetXML extends AbstractSheetXMLWithDate {
 
public static String TEMPLATE_ID = "CustomerSupportTicket";
public static String TEMPLATE_ID = "TicketSupport";
public static String TEMPLATE_PROPERTY_NAME = "LocationCmd";
 
// private static final Tuple2<String, String> tuple = Tuple2.create("LocationDmd",
22,7 → 22,7
 
@Override
public String getReference() {
return this.row.getString("NUMERO");
return this.row.getString("NUMBER");
}
 
// FIXME Prefs printer location
/trunk/Modules/Module Customer Support/src/org/openconcerto/modules/customersupport/SuiviTicketPanel.java
179,6 → 179,12
Collections.sort(histoRowsOrder, new Comparator<SQLRowAccessor>() {
@Override
public int compare(SQLRowAccessor o1, SQLRowAccessor o2) {
if (o1.getObject("DATE") == null) {
return -1;
}
if (o2.getObject("DATE") == null) {
return 1;
}
return o2.getDate("DATE").compareTo(o1.getDate("DATE"));
}
});
/trunk/Modules/Module Operation/src/org/openconcerto/modules/operation/ModuleOperation.java
34,6 → 34,7
import org.openconcerto.sql.utils.SQLCreateTable;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.RowAction;
import org.openconcerto.sql.view.list.action.ListEvent;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.utils.i18n.TranslationManager;
 
112,7 → 113,7
}
}, true) {
@Override
public boolean enabledFor(IListeEvent evt) {
public boolean enabledFor(List<SQLRowValues> values) {
return true;
}
 
/trunk/Modules/Module Project/src/org/openconcerto/modules/project/Module.java
86,6 → 86,7
import org.openconcerto.sql.view.list.BaseSQLTableModelColumn;
import org.openconcerto.sql.view.list.IListe;
import org.openconcerto.sql.view.list.RowAction;
import org.openconcerto.sql.view.list.action.ListEvent;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.FrameUtil;
import org.openconcerto.ui.PanelFrame;
243,7 → 244,7
RowAction cloneAction = eltDevis.getCloneAction();
eltDevis.getRowActions().add(cloneAction);
 
MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(DevisXmlSheet.class);
MouseSheetXmlListeListener mouseSheetXmlListeListener = new MouseSheetXmlListeListener(eltDevis, DevisXmlSheet.class);
mouseSheetXmlListeListener.setGenerateHeader(true);
mouseSheetXmlListeListener.setShowHeader(true);
eltDevis.getRowActions().addAll(mouseSheetXmlListeListener.getRowActions());
313,9 → 314,9
}, false) {
 
@Override
public boolean enabledFor(IListeEvent evt) {
if (evt.getSelectedRows().size() == 1) {
SQLRowAccessor r = evt.getSelectedRow();
public boolean enabledFor(List<SQLRowValues> evt) {
if (evt.size() == 1) {
SQLRowAccessor r = evt.get(0);
return !r.isForeignEmpty("ID_AFFAIRE");
}
return false;
357,9 → 358,9
}, false) {
 
@Override
public boolean enabledFor(IListeEvent evt) {
if (evt.getSelectedRows().size() == 1) {
SQLRowAccessor r = evt.getSelectedRow();
public boolean enabledFor(List<SQLRowValues> evt) {
if (evt.size() == 1) {
SQLRowAccessor r = evt.get(0);
Collection<? extends SQLRowAccessor> l = r.getReferentRows(r.getTable().getTable("AFFAIRE"));
return l.size() > 0;
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchProcessor.java
10,7 → 10,7
 
boolean checkParameters();
 
void process(List<SQLRowValues> r) throws SQLException;
void process(List<SQLRowAccessor> r) throws SQLException;
 
void processBeforeUpdate(SQLRowAccessor from, SQLRowValues to);
 
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchField.java
18,9 → 18,11
private final SQLRowAccessor foreignLinkRow;
private final SQLFieldTranslator translator;
private final SQLElement elementLink;
private final SQLElementDirectory dir;
 
public BatchField(SQLElementDirectory dir, SQLField field, SQLRowAccessor foreignLinkRow) {
this.field = field;
this.dir = dir;
this.foreignLinkRow = foreignLinkRow;
 
this.translator = dir.getTranslator();
31,6 → 33,14
}
}
 
private SQLField fieldToMatch;
private Object matchingValue;
 
public void setDefaultMatchingValue(SQLField fieldToMatch, Object value) {
this.fieldToMatch = fieldToMatch;
this.matchingValue = value;
}
 
public SQLField getField() {
return field;
}
39,8 → 49,18
return foreignLinkRow;
}
 
public SQLField getFieldToMatch() {
return fieldToMatch;
}
public Object getMatchingValue() {
return matchingValue;
}
 
public String getComboName() {
if (this.foreignLinkRow == null) {
if (this.fieldToMatch != null) {
return this.dir.getElement(this.fieldToMatch.getTable()).getPluralName() + " " + this.translator.getLabelFor(this.field) + " " + this.matchingValue;
} else if (this.foreignLinkRow == null) {
return this.translator.getLabelFor(this.field);
} else {
return this.elementLink.getPluralName() + " " + this.foreignLinkRow.getString("NOM") + " " + this.translator.getLabelFor(this.field);
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/Module.java
13,6 → 13,7
import org.openconcerto.erp.modules.ModuleFactory;
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.view.list.IListe;
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
30,11 → 31,12
 
super.setupComponents(ctxt);
final SQLElement element = ctxt.getElement("ARTICLE");
final RowAction.PredicateRowAction editAction = new RowAction.PredicateRowAction(new AbstractAction("Traitement par lot...") {
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 List<SQLRowAccessor> rows = IListe.get(e).getSelectedRowAccessors();
final int size = rows.size();
if (size > 0) {
final JFrame f = new JFrame();
53,7 → 55,8
 
};
 
f.setContentPane(new BatchEditorPanel(ctxt.getElement("ARTICLE").getDirectory(), rows, filter));
f.setContentPane(
new BatchEditorPanel(ctxt.getElement("ARTICLE").getDirectory(), rows, filter));
f.pack();
f.setMinimumSize(new Dimension(400, 300));
f.setLocationRelativeTo(IListe.get(e));
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/NumberProcessor.java
13,9 → 13,14
import javax.swing.JRadioButton;
import javax.swing.JTextField;
 
import org.openconcerto.erp.core.finance.tax.model.TaxeCache;
import org.openconcerto.erp.utils.ConvertDevise;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.request.UpdateBuilder;
import org.openconcerto.ui.DefaultGridBagConstraints;
 
public class NumberProcessor extends JPanel implements BatchProcessor {
106,20 → 111,51
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
public void process(List<SQLRowAccessor> r) throws SQLException {
if (bReplace.isSelected()) {
BigDecimal v = new BigDecimal(this.tReplace.getText().trim());
final SQLField fieldToMatch = batchfield.getFieldToMatch();
if (fieldToMatch != null) {
 
UpdateBuilder build = new UpdateBuilder(fieldToMatch.getTable());
build.setObject(batchfield.getField().getName(), (BigDecimal) decimalToFieldType(v));
build.setWhere(
Where.inValues(fieldToMatch.getTable().getField("ID_" + r.get(0).getTable().getName()), SQLRow.getIDs(r)).and(new Where(fieldToMatch, "=", batchfield.getMatchingValue())));
fieldToMatch.getTable().getDBSystemRoot().getDataSource().execute(build.asString());
 
} else {
for (SQLRowAccessor sqlRowAccessor : r) {
 
if (batchfield.getForeignLinkRow() != null) {
 
final List<SQLRow> referentRow = batchfield.getReferentRows(sqlRowAccessor);
if (referentRow.isEmpty()) {
SQLRowValues rowVals = new SQLRowValues(batchfield.getField().getTable());
rowVals.put("ID_" + sqlRowAccessor.getTable().getName(), sqlRowAccessor.getID());
rowVals.put("ID_" + batchfield.getForeignLinkRow().getTable().getName(), batchfield.getForeignLinkRow().getID());
rowVals.put(batchfield.getField().getName(), decimalToFieldType(v));
final BigDecimal taux = BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowAccessor.getForeignID("ID_TAXE")));
final BigDecimal ht = (BigDecimal) decimalToFieldType(v);
final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, rowVals.getTable().getField("PV_TTC").getType().getDecimalDigits());
rowVals.put("PV_TTC", ttc);
rowVals.put("PRIX_METRIQUE_VT_1", decimalToFieldType(v));
rowVals.commit();
} else {
for (SQLRow sqlRowT : referentRow) {
SQLRowValues rowValues = sqlRowT.createEmptyUpdateRow();
rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
processBeforeUpdate(sqlRowT, rowValues);
if (!batchfield.getField().getName().equals("QTE_MIN") && !batchfield.getField().getName().equals("POURCENT_REMISE")) {
// processBeforeUpdate(sqlRowT, rowValues);
final BigDecimal taux = sqlRowT.isForeignEmpty("ID_TAXE") ? BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowAccessor.getForeignID("ID_TAXE")))
: BigDecimal.valueOf(TaxeCache.getCache().getTauxFromId(sqlRowT.getForeignID("ID_TAXE")));
final BigDecimal ht = rowValues.getBigDecimal("PV_HT");
final BigDecimal ttc = ConvertDevise.getTtcFromHt(ht, taux, rowValues.getTable().getField("PV_TTC").getType().getDecimalDigits());
rowValues.put("PV_TTC", ttc);
rowValues.put("PRIX_METRIQUE_VT_1", ht);
}
rowValues.update();
}
}
} else {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
rowValues.put(batchfield.getField().getName(), decimalToFieldType(v));
127,6 → 163,7
rowValues.update();
}
}
}
} else if (bAdd.isSelected()) {
 
String t = this.tAdd.getText().trim();
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ReferenceProcessor.java
41,7 → 41,7
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
public void process(List<SQLRowAccessor> r) throws SQLException {
 
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/ForbiddenFieldName.java
4,6 → 4,6
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"));
|| f.equals("MODIFICATION_DATE") || f.equals("CREATION_DATE")|| f.equals("QTE_MIN"));
}
}
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/StringProcessor.java
134,7 → 134,7
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
public void process(List<SQLRowAccessor> r) throws SQLException {
if (bReplace.isSelected()) {
final String t = ensureSize(tReplace.getText());
for (SQLRowAccessor sqlRowAccessor : r) {
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BatchEditorPanel.java
8,9 → 8,11
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
 
27,10 → 29,11
import org.openconcerto.sql.element.SQLElementDirectory;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowListRSH;
import org.openconcerto.sql.model.SQLRowValues;
import org.openconcerto.sql.model.SQLSelect;
import org.openconcerto.sql.model.SQLTable;
import org.openconcerto.sql.model.Where;
import org.openconcerto.sql.request.SQLFieldTranslator;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JLabelBold;
39,7 → 42,7
 
public class BatchEditorPanel extends JPanel {
 
public BatchEditorPanel(final SQLElementDirectory dir, final List<SQLRowValues> rows, FieldFilter filter) {
public BatchEditorPanel(final SQLElementDirectory dir, final List<SQLRowAccessor> rows, FieldFilter filter) {
SQLFieldTranslator translator = dir.getTranslator();
Set<SQLField> fields = rows.get(0).getTable().getFields();
List<BatchField> f = new ArrayList<BatchField>();
50,6 → 53,8
}
}
}
 
// Tarif
SQLTable tableTarif = rows.get(0).getTable().getTable("TARIF");
SQLTable tableArticleTarif = rows.get(0).getTable().getTable("ARTICLE_TARIF");
SQLSelect sel = new SQLSelect();
62,6 → 67,47
}
}
 
// Tarif Promo
SQLTable tableTarifPromo = rows.get(0).getTable().getTable("TARIF_PROMOTION");
SQLTable tableArticleTarifPromo = rows.get(0).getTable().getTable("ARTICLE_TARIF_PROMOTION");
SQLSelect selT = new SQLSelect();
selT.addSelectStar(tableTarifPromo);
List<SQLRow> rowTarifP = SQLRowListRSH.execute(selT);
for (SQLRow sqlRow : rowTarifP) {
f.add(new BatchField(dir, tableArticleTarifPromo.getField("PV_HT"), sqlRow));
}
 
// Tarif quantite
SQLTable tableTarifQte = rows.get(0).getTable().getTable("TARIF_QUANTITE");
SQLSelect selQ = new SQLSelect();
selQ.addSelectStar(tableTarifQte);
Where w = Where.inValues(tableTarifQte.getField("ID_" + rows.get(0).getTable().getName()), SQLRow.getIDs(rows));
selQ.setWhere(w);
List<SQLRow> rowTarifQ = SQLRowListRSH.execute(selQ);
Set<BigDecimal> qtes = new HashSet<>();
for (SQLRow sqlRow : rowTarifQ) {
final BigDecimal qte = sqlRow.getBigDecimal("QUANTITE");
if (!qtes.contains(qte)) {
qtes.add(qte);
final BatchField batchFieldQte = new BatchField(dir, sqlRow.getTable().getField("PRIX_METRIQUE_VT_1"), null);
batchFieldQte.setDefaultMatchingValue(sqlRow.getTable().getField("QUANTITE"), qte);
f.add(batchFieldQte);
final BatchField batchFieldRemise = new BatchField(dir, sqlRow.getTable().getField("POURCENT_REMISE"), null);
batchFieldRemise.setDefaultMatchingValue(sqlRow.getTable().getField("QUANTITE"), qte);
f.add(batchFieldRemise);
}
}
 
// Stock
SQLTable tableDepotStock = rows.get(0).getTable().getTable("DEPOT_STOCK");
SQLTable tableStock = tableDepotStock.getTable("STOCK");
SQLSelect selDepot = new SQLSelect();
selDepot.addSelectStar(tableDepotStock);
List<SQLRow> rowDepot = SQLRowListRSH.execute(selDepot);
for (SQLRow sqlRow : rowDepot) {
f.add(new BatchField(dir, tableStock.getField("QTE_MIN"), sqlRow));
}
 
Collections.sort(f, new Comparator<BatchField>() {
 
@Override
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/DateProcessor.java
26,7 → 26,7
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
public void process(List<SQLRowAccessor> r) throws SQLException {
final Date date = d.getDate();
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
/trunk/Modules/Module Batch Processing/src/org/openconcerto/modules/common/batchprocessing/BooleanProcessor.java
37,7 → 37,7
}
 
@Override
public void process(List<SQLRowValues> r) throws SQLException {
public void process(List<SQLRowAccessor> r) throws SQLException {
if (bTrue.isSelected()) {
for (SQLRowAccessor sqlRowAccessor : r) {
final SQLRowValues rowValues = sqlRowAccessor.createEmptyUpdateRow();
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/ModuleLabel.java
8,8 → 8,10
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.TreeMap;
 
21,6 → 23,7
import org.openconcerto.erp.modules.AbstractModule;
import org.openconcerto.erp.modules.ComponentsContext;
import org.openconcerto.erp.modules.ModuleFactory;
import org.openconcerto.sql.model.SQLField;
import org.openconcerto.sql.model.SQLRow;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.sql.model.SQLRowValues;
37,6 → 40,8
 
public final class ModuleLabel extends AbstractModule {
final LinkedHashMap<String, String> zplTemplates = new LinkedHashMap<String, String>();
final LinkedHashMap<String, String> gplTemplates = new LinkedHashMap<String, String>();
private Map<String, File> dirMap = new HashMap<>();
 
public ModuleLabel(ModuleFactory f) throws IOException {
super(f);
54,7 → 59,7
public void actionPerformed(ActionEvent arg0) {
final IListe list = IListe.get(arg0);
final List<Integer> selectedIDs = list.getSelection().getSelectedIDs();
final SQLTable tArticle = list.getSelectedRows().get(0).getTable();
final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
final SwingWorker<List<RowValuesLabel>, String> wworker = new SwingWorker<List<RowValuesLabel>, String>() {
 
@Override
214,12 → 219,68
final JFrame f = new JFrame();
final IListe list = IListe.get(arg0);
final int idProduct = list.getSelection().getSelectedID();
final SQLTable tArticle = list.getSelectedRows().get(0).getTable();
final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
 
final SwingWorker<SQLRowValues, String> wworker = new SwingWorker<SQLRowValues, String>() {
 
@Override
protected SQLRowValues doInBackground() throws Exception {
SQLRowValues rArticle = new SQLRowValues(tArticle);
rArticle.putNulls(tArticle.getFieldsName());
for (SQLField f : tArticle.getFields()) {
if (f.getName().startsWith("ID_ARTICLE_DECLINAISON_")) {
SQLRowValues rowValsDecl = rArticle.putRowValues(f.getName());
rowValsDecl.putNulls(f.getForeignTable().getFieldsName());
}
}
 
final List<SQLRowValues> fetchRow = SQLRowValuesListFetcher.create(rArticle).fetch(new Where(tArticle.getKey(), "=", idProduct));
return fetchRow.get(0);
}
 
@Override
protected void done() {
try {
final SQLRowValues values = get();
p.initUI(values);
f.setTitle(entry.getKey());
f.setContentPane(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
 
} catch (Exception e) {
ExceptionHandler.handle("Erreur d'impression", e);
}
}
};
wworker.execute();
 
}
}, true, false);
 
action.setPredicate(IListeEvent.createSelectionCountPredicate(1, 1));
ctxt.getElement("ARTICLE").getRowActions().add(action);
}
}
 
if (!gplTemplates.isEmpty()) {
for (final Entry<String, String> entry : gplTemplates.entrySet()) {
final String gpl = entry.getValue();
final PredicateRowAction action = new PredicateRowAction(new AbstractAction("Imprimer l'étiquette " + entry.getKey()) {
 
@Override
public void actionPerformed(ActionEvent arg0) {
final GPLPrinterPanel p = new GPLPrinterPanel(gpl, getDir(entry.getKey()));
final JFrame f = new JFrame();
final IListe list = IListe.get(arg0);
final int idProduct = list.getSelection().getSelectedID();
final SQLTable tArticle = list.getSelectedRowAccessors().get(0).getTable();
 
final SwingWorker<SQLRowValues, String> wworker = new SwingWorker<SQLRowValues, String>() {
 
@Override
protected SQLRowValues doInBackground() throws Exception {
final SQLRow row = tArticle.getRow(idProduct);
row.fetchValues();
return row.asRowValues();
253,6 → 314,10
 
}
 
protected File getDir(String value) {
return dirMap.get(value);
}
 
@Override
protected void start() {
 
264,23 → 329,44
System.err.println("ModuleLabel.readTemplates() " + templatesDir.getAbsolutePath());
File[] files = templatesDir.listFiles();
if (files != null) {
LinkedHashMap<String, String> map = new LinkedHashMap<>();
LinkedHashMap<String, String> zmap = new LinkedHashMap<>();
LinkedHashMap<String, String> gmap = new LinkedHashMap<>();
for (File f : files) {
if (f.getName().endsWith(".zpl")) {
try {
String zpl = FileUtils.read(f, StandardCharsets.UTF_8);
String name = f.getName().substring(0, f.getName().length() - 4).trim();
map.put(name, zpl);
 
zmap.put(name, zpl);
dirMap.put(name, templatesDir);
 
System.err.println("ModuleLabel.readTemplates() add " + name);
 
} catch (Exception e) {
System.err.println(this.getClass().getCanonicalName() + "start() cannot read zpl template : " + f.getAbsolutePath() + " : " + e.getMessage());
}
} else if (f.getName().endsWith(".graphicspl")) {
try {
String zpl = FileUtils.read(f, StandardCharsets.UTF_8);
String name = f.getName().substring(0, f.getName().length() - ".graphicspl".length()).trim();
gmap.put(name, zpl);
dirMap.put(name, templatesDir);
 
} catch (Exception e) {
System.err.println(this.getClass().getCanonicalName() + "start() cannot read graphicspl template : " + f.getAbsolutePath() + " : " + e.getMessage());
}
}
}
// Tri de la map par clef
final TreeMap<String, String> copy = new TreeMap<>(map);
this.zplTemplates.clear();
this.zplTemplates.putAll(copy);
final TreeMap<String, String> copy1 = new TreeMap<>(zmap);
 
zplTemplates.clear();
zplTemplates.putAll(copy1);
 
final TreeMap<String, String> copy2 = new TreeMap<>(gmap);
gplTemplates.clear();
gplTemplates.putAll(copy2);
 
}
 
} else {
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/ZPLPrinterPanel.java
13,6 → 13,7
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.math.BigDecimal;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
89,25 → 90,26
public ZPLPrinterPanel(String zpl) {
this.zpl = zpl;
this.variables = getVariables(zpl);
knownVariables.add("product.code");
knownVariables.add("product.name");
knownVariables.add("product.material");
 
knownVariables.add("product.ean13");
knownVariables.add("product.price");
knownVariables.add("product.pricewithtax");
this.knownVariables.add("product.code");
this.knownVariables.add("product.name");
this.knownVariables.add("product.material");
this.knownVariables.add("product.color");
this.knownVariables.add("product.size");
this.knownVariables.add("product.ean13");
this.knownVariables.add("product.price");
this.knownVariables.add("product.pricewithtax");
//
mapName.put("product.name", "Nom");
mapName.put("product.code", "Code");
mapName.put("product.ean13", "Code à barres");
mapName.put("product.price", "Prix HT");
mapName.put("product.pricewithtax", "Prix TTC");
mapName.put("product.treatment", "Traitement");
mapName.put("product.origin", "Origine");
mapName.put("product.batch", "Lot");
mapName.put("product.size", "Taille");
mapName.put("product.color", "Couleur");
mapName.put("product.material", "Matière");
this.mapName.put("product.name", "Nom");
this.mapName.put("product.code", "Code");
this.mapName.put("product.ean13", "Code à barres");
this.mapName.put("product.price", "Prix HT");
this.mapName.put("product.pricewithtax", "Prix TTC");
this.mapName.put("product.treatment", "Traitement");
this.mapName.put("product.origin", "Origine");
this.mapName.put("product.batch", "Lot");
this.mapName.put("product.size", "Taille");
this.mapName.put("product.color", "Couleur");
this.mapName.put("product.material", "Matière");
}
 
private final File getPrefFile() {
128,7 → 130,7
System.out.println(file.getAbsolutePath());
if (file.exists()) {
try {
properties.load(new FileInputStream(file));
this.properties.load(new FileInputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
143,7 → 145,7
 
Set<String> added = new HashSet<>();
for (String v : this.knownVariables) {
if (variables.contains(v)) {
if (this.variables.contains(v)) {
// Non editable
String label = getName(v);
c.gridx = 0;
158,7 → 160,7
txt.setText(value);
txt.setEditable(false);
}
editorMap.put(v, txt);
this.editorMap.put(v, txt);
this.add(txt, c);
added.add(v);
c.gridy++;
174,7 → 176,7
c.gridx++;
c.weightx = 1;
JTextField txt = new JTextField(20);
editorMap.put(v, txt);
this.editorMap.put(v, txt);
this.add(txt, c);
added.add(v);
c.gridy++;
233,15 → 235,15
c.anchor = GridBagConstraints.SOUTHEAST;
 
// Restore state from properties
if (properties.getOrDefault("printerType", "local").equals("local")) {
if (this.properties.getOrDefault("printerType", "local").equals("local")) {
radioLocalPrinter.setSelected(true);
} else {
radioNetworkPrinter.setSelected(true);
}
textPrinterIP.setText(properties.getOrDefault("printerIp", "").toString());
portZPL.setValue(Long.parseLong(properties.getOrDefault("printerPort", "9100").toString()));
nbLabels.setValue(Long.parseLong(properties.getOrDefault("nbLabels", "1").toString()));
delayLabels.setValue(Long.parseLong(properties.getOrDefault("delay", "800").toString()));
textPrinterIP.setText(this.properties.getOrDefault("printerIp", "").toString());
portZPL.setValue(Long.parseLong(this.properties.getOrDefault("printerPort", "9100").toString()));
nbLabels.setValue(Long.parseLong(this.properties.getOrDefault("nbLabels", "1").toString()));
delayLabels.setValue(Long.parseLong(this.properties.getOrDefault("delay", "800").toString()));
// Print
 
JButton printButton = new JButton("Imprimer");
252,16 → 254,16
public void actionPerformed(ActionEvent e) {
try {
if (radioLocalPrinter.isSelected()) {
properties.put("printerType", "local");
ZPLPrinterPanel.this.properties.put("printerType", "local");
} else {
properties.put("printerType", "network");
properties.put("printerIp", textPrinterIP.getText());
properties.put("printerPort", portZPL.getValue().toString());
ZPLPrinterPanel.this.properties.put("printerType", "network");
ZPLPrinterPanel.this.properties.put("printerIp", textPrinterIP.getText());
ZPLPrinterPanel.this.properties.put("printerPort", portZPL.getValue().toString());
}
properties.put("nbLabels", nbLabels.getValue().toString());
properties.put("delay", delayLabels.getValue().toString());
ZPLPrinterPanel.this.properties.put("nbLabels", nbLabels.getValue().toString());
ZPLPrinterPanel.this.properties.put("delay", delayLabels.getValue().toString());
// Save Prefs
properties.store(new FileOutputStream(getPrefFile()), "");
ZPLPrinterPanel.this.properties.store(new FileOutputStream(getPrefFile()), "");
} catch (Exception e1) {
ExceptionHandler.handle("Erreur de sauvegarde de " + getPrefFile().getAbsolutePath(), e1);
}
296,10 → 298,10
final PrinterJob pj1 = PrinterJob.getPrinterJob();
if (pj1.printDialog()) {
final PrintService ps = pj1.getPrintService();
final int nb = ((Number) nbLabels.getValue()).intValue();
for (int i = 0; i < nb; i++) {
final DocPrintJob pj = ps.createPrintJob();
final SimpleDoc doc = new SimpleDoc(data, DocFlavor.BYTE_ARRAY.AUTOSENSE, null);
final int nb = ((Number) nbLabels.getValue()).intValue();
for (int i = 0; i < nb; i++) {
pj.print(doc, null);
Thread.sleep(((Number) delayLabels.getValue()).intValue());
}
357,6 → 359,7
if (row == null) {
return null;
}
System.err.println("ZPLPrinterPanel.getValueAsString()" + variableName + " : " + row);
if (variableName.equals("product.code")) {
return row.getString("CODE");
} else if (variableName.equals("product.name")) {
364,17 → 367,31
} else if (variableName.equals("product.ean13")) {
return row.getString("CODE_BARRE");
} else if (variableName.equals("product.price")) {
return new DecimalFormat("#0.00").format(row.getBigDecimal("PV_HT"));
final BigDecimal bigDecimal = row.getBigDecimal("PV_HT");
return new DecimalFormat("#0.00").format(bigDecimal);
} else if (variableName.equals("product.pricewithtax")) {
return new DecimalFormat("#0.00").format(row.getBigDecimal("PV_TTC"));
final BigDecimal bigDecimal = row.getBigDecimal("PV_TTC");
return new DecimalFormat("#0.00").format(bigDecimal);
} else if (variableName.equals("product.material")) {
return row.getString("MATIERE");
} else if (variableName.equals("product.color")) {
if (row.getTable().contains("ID_ARTICLE_DECLINAISON_COULEUR")) {
if (row.getObject("ID_ARTICLE_DECLINAISON_COULEUR") != null && !row.isForeignEmpty("ID_ARTICLE_DECLINAISON_COULEUR")) {
return row.getForeign("ID_ARTICLE_DECLINAISON_COULEUR").getString("NOM");
}
}
} else if (variableName.equals("product.size")) {
if (row.getTable().contains("ID_ARTICLE_DECLINAISON_TAILLE")) {
if (row.getObject("ID_ARTICLE_DECLINAISON_TAILLE") != null && !row.isForeignEmpty("ID_ARTICLE_DECLINAISON_TAILLE")) {
return row.getForeign("ID_ARTICLE_DECLINAISON_TAILLE").getString("NOM");
}
}
}
return "";
}
 
public String getName(String variableName) {
String n = mapName.get(variableName);
String n = this.mapName.get(variableName);
if (n == null) {
return variableName;
}
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/GPLPrinterPanel.java
New file
0,0 → 1,454
package org.openconcerto.modules.label;
 
import java.awt.Desktop;
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.image.BufferedImage;
import java.awt.print.PrinterJob;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.StringReader;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
 
import javax.imageio.ImageIO;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.JTextField;
import javax.swing.SpinnerNumberModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.xml.parsers.ParserConfigurationException;
 
import org.openconcerto.modules.label.graphicspl.GraphicsPL;
import org.openconcerto.sql.model.SQLRowAccessor;
import org.openconcerto.ui.DefaultGridBagConstraints;
import org.openconcerto.ui.JLabelBold;
import org.openconcerto.utils.BaseDirs;
import org.openconcerto.utils.ExceptionHandler;
import org.openconcerto.utils.FileUtils;
import org.openconcerto.utils.ProductInfo;
import org.xml.sax.SAXException;
 
public class GPLPrinterPanel extends JPanel {
private final HashMap<String, String> mapName = new HashMap<>();
private final List<String> variables;
private final List<String> knownVariables = new ArrayList<>();
private Map<String, JTextField> editorMap = new HashMap<>();
private String gpl;
private final Properties properties = new Properties();
private File imageDir;
 
public static void main(String[] args) throws IOException {
// final File f = new File("Templates/Labels", "50x50.zpl");
final File file = new File("Template/Labels", "rouquette.graphicspl");
String gpl = FileUtils.read(file);
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
GPLPrinterPanel p = new GPLPrinterPanel(gpl, file.getParentFile());
p.initUI(null);
JFrame f = new JFrame();
f.setTitle(file.getName());
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setContentPane(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
});
 
}
 
public GPLPrinterPanel(String gpl, File imageDir) {
this.gpl = gpl;
this.imageDir = imageDir;
this.variables = getVariables(gpl);
knownVariables.add("product.code");
knownVariables.add("product.name");
knownVariables.add("product.material");
 
knownVariables.add("product.ean13");
knownVariables.add("product.price");
knownVariables.add("product.pricewithtax");
//
mapName.put("product.name", "Nom");
mapName.put("product.code", "Code");
mapName.put("product.ean13", "Code à barres");
mapName.put("product.price", "Prix HT");
mapName.put("product.pricewithtax", "Prix TTC");
mapName.put("product.treatment", "Traitement");
mapName.put("product.origin", "Origine");
mapName.put("product.batch", "Lot");
mapName.put("product.size", "Taille");
mapName.put("product.color", "Couleur");
mapName.put("product.material", "Matière");
}
 
private final File getPrefFile() {
final File prefsFolder = BaseDirs.create(ProductInfo.getInstance()).getPreferencesFolder();
if (!prefsFolder.exists()) {
prefsFolder.mkdirs();
}
return new File(prefsFolder, "labels.properties");
}
 
protected void initUI(SQLRowAccessor row) {
final File prefsFolder = BaseDirs.create(ProductInfo.getInstance()).getPreferencesFolder();
if (!prefsFolder.exists()) {
prefsFolder.mkdirs();
}
 
final File file = getPrefFile();
System.out.println(file.getAbsolutePath());
if (file.exists()) {
try {
properties.load(new FileInputStream(file));
} catch (IOException e) {
e.printStackTrace();
}
}
 
this.setLayout(new GridBagLayout());
GridBagConstraints c = new DefaultGridBagConstraints();
c.fill = GridBagConstraints.HORIZONTAL;
this.removeAll();
 
// Fields
 
Set<String> added = new HashSet<>();
for (String v : this.knownVariables) {
if (variables.contains(v)) {
// Non editable
String label = getName(v);
c.gridx = 0;
c.weightx = 0;
this.add(new JLabel(label, SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1;
 
String value = getValueAsString(row, v);
JTextField txt = new JTextField(20);
if (value != null) {
txt.setText(value);
txt.setEditable(false);
}
editorMap.put(v, txt);
this.add(txt, c);
added.add(v);
c.gridy++;
}
}
for (String v : this.variables) {
if (!added.contains(v)) {
// Editable
String label = getName(v);
c.gridx = 0;
c.weightx = 0;
this.add(new JLabel(label, SwingConstants.RIGHT), c);
c.gridx++;
c.weightx = 1;
JTextField txt = new JTextField(20);
editorMap.put(v, txt);
this.add(txt, c);
added.add(v);
c.gridy++;
}
 
}
 
c.gridwidth = 2;
c.gridx = 0;
this.add(new JLabelBold("Paramètres d'impression"), c);
// Printer selector
c.gridx = 0;
c.gridy++;
final JPanel l1 = new JPanel();
l1.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
 
l1.add(new JLabel("Nombre d'étiquettes"));
final JSpinner nbLabels = new JSpinner(new SpinnerNumberModel(1, 1, 1000, 10));
l1.add(nbLabels);
this.add(l1, c);
// Delay
l1.add(new JLabel(" Pause entre chaque impression"));
final JSpinner delayLabels = new JSpinner(new SpinnerNumberModel(800, 100, 10000, 100));
l1.add(delayLabels);
this.add(l1, c);
l1.add(new JLabel("ms"));
 
c.gridy++;
 
final JPanel lPrintNetwork = new JPanel();
lPrintNetwork.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
JRadioButton radioNetworkPrinter = new JRadioButton("imprimante réseau ZPL IP :");
lPrintNetwork.add(radioNetworkPrinter);
JTextField textPrinterIP = new JTextField(16);
lPrintNetwork.add(textPrinterIP);
lPrintNetwork.add(new JLabel(" Port :"));
JSpinner portZPL = new JSpinner(new SpinnerNumberModel(9100, 24, 10000, 1));
lPrintNetwork.add(portZPL);
this.add(lPrintNetwork, c);
 
c.gridy++;
final JPanel lPrintLocal = new JPanel();
lPrintLocal.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
JRadioButton radioLocalPrinter = new JRadioButton("imprimante locale");
lPrintLocal.add(radioLocalPrinter);
radioLocalPrinter.setSelected(true);
this.add(lPrintLocal, c);
 
final ButtonGroup gr = new ButtonGroup();
gr.add(radioLocalPrinter);
gr.add(radioNetworkPrinter);
c.gridy++;
c.weighty = 1;
c.gridx = 1;
c.fill = GridBagConstraints.NONE;
c.anchor = GridBagConstraints.SOUTHEAST;
 
// Restore state from properties
if (properties.getOrDefault("printerType", "local").equals("local")) {
radioLocalPrinter.setSelected(true);
} else {
radioNetworkPrinter.setSelected(true);
}
textPrinterIP.setText(properties.getOrDefault("printerIp", "").toString());
portZPL.setValue(Long.parseLong(properties.getOrDefault("printerPort", "9100").toString()));
nbLabels.setValue(Long.parseLong(properties.getOrDefault("nbLabels", "1").toString()));
delayLabels.setValue(Long.parseLong(properties.getOrDefault("delay", "800").toString()));
// Print
 
JPanel actions = new JPanel();
actions.setLayout(new FlowLayout(FlowLayout.LEFT));
 
this.add(actions, c);
 
JButton exportButton = new JButton("Export PNG");
actions.add(exportButton);
JButton printButton = new JButton("Imprimer");
actions.add(printButton);
 
exportButton.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
final String code = createFilledCode();
GraphicsPL g = new GraphicsPL();
try {
g.load(code, GPLPrinterPanel.this.imageDir);
 
BufferedImage img = g.createImage(1);
 
JFileChooser fileChooser = new JFileChooser();
fileChooser.setDialogTitle("Export de l'etiquette");
 
final File dir = new File(System.getProperties().getProperty("user.home"));
fileChooser.setCurrentDirectory(dir);
fileChooser.setSelectedFile(new File(dir, "etiquette.png"));
int userSelection = fileChooser.showSaveDialog(GPLPrinterPanel.this);
 
if (userSelection == JFileChooser.APPROVE_OPTION) {
File fileToSave = fileChooser.getSelectedFile();
System.out.println("Save as file: " + fileToSave.getAbsolutePath());
ImageIO.write(img, "png", fileToSave);
Desktop.getDesktop().open(fileToSave);
}
 
} catch (ParserConfigurationException | SAXException | IOException e1) {
e1.printStackTrace();
JOptionPane.showMessageDialog(GPLPrinterPanel.this, "Erreur lors de l'export\n" + e1.getMessage());
}
}
});
 
printButton.addActionListener(new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
try {
if (radioLocalPrinter.isSelected()) {
properties.put("printerType", "local");
} else {
properties.put("printerType", "network");
properties.put("printerIp", textPrinterIP.getText());
properties.put("printerPort", portZPL.getValue().toString());
}
properties.put("nbLabels", nbLabels.getValue().toString());
properties.put("delay", delayLabels.getValue().toString());
// Save Prefs
properties.store(new FileOutputStream(getPrefFile()), "");
} catch (Exception e1) {
ExceptionHandler.handle("Erreur de sauvegarde de " + getPrefFile().getAbsolutePath(), e1);
}
final String code = createFilledCode();
System.out.println("GraphicsPL:");
System.out.println(code);
 
if (radioNetworkPrinter.isSelected()) {
Socket socket = null;
try {
 
GraphicsPL g = new GraphicsPL();
g.load(code, imageDir);
String zpl = g.getZPL();
byte[] data = zpl.getBytes(StandardCharsets.UTF_8);
socket = new Socket(textPrinterIP.getText(), ((Number) portZPL.getValue()).intValue());
final DataOutputStream out = new DataOutputStream(socket.getOutputStream());
final int nb = ((Number) nbLabels.getValue()).intValue();
for (int i = 0; i < nb; i++) {
out.write(data);
}
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(printButton, "Erreur d'impression réseau : " + ex.getMessage());
} finally {
if (socket != null) {
try {
socket.close();
} catch (IOException e1) {
e1.printStackTrace();
}
}
 
}
} else {
try {
final PrinterJob pj1 = PrinterJob.getPrinterJob();
GraphicsPL g = new GraphicsPL();
g.load(code, imageDir);
 
if (pj1.printDialog()) {
final int nb = ((Number) nbLabels.getValue()).intValue();
for (int i = 0; i < nb; i++) {
pj1.setPrintable(g.createPrintable());
pj1.print();
Thread.sleep(((Number) delayLabels.getValue()).intValue());
}
}
} catch (Exception ex) {
ex.printStackTrace();
JOptionPane.showMessageDialog(printButton, "Erreur d'impression locale : " + ex.getMessage());
}
}
 
}
});
 
}
 
private String createFilledCode() {
 
final BufferedReader reader = new BufferedReader(new StringReader(this.gpl));
final StringBuilder builder = new StringBuilder();
 
try {
String line = reader.readLine();
while (line != null) {
if (line.contains("${")) {
 
for (String v : this.editorMap.keySet()) {
if (line.contains("${" + v + "}")) {
final String value = this.editorMap.get(v).getText();
line = line.replace("${" + v + "}", value);
 
}
}
 
}
builder.append(line);
builder.append("\n");
line = reader.readLine();
}
 
} catch (Exception e) {
e.printStackTrace();
}
 
return builder.toString();
}
 
public String getValueAsString(SQLRowAccessor row, String variableName) {
if (row == null) {
return null;
}
if (variableName.equals("product.code")) {
return row.getString("CODE");
} else if (variableName.equals("product.name")) {
return row.getString("NOM");
} else if (variableName.equals("product.ean13")) {
return row.getString("CODE_BARRE");
} else if (variableName.equals("product.price")) {
return new DecimalFormat("#0.00").format(row.getBigDecimal("PV_HT"));
} else if (variableName.equals("product.pricewithtax")) {
return new DecimalFormat("#0.00").format(row.getBigDecimal("PV_TTC"));
} else if (variableName.equals("product.material")) {
return row.getString("MATIERE");
}
return "";
}
 
public String getName(String variableName) {
String n = mapName.get(variableName);
if (n == null) {
return variableName;
}
return n;
}
 
public List<String> getVariables(String str) {
final List<String> result = new ArrayList<>();
if (str == null || str.length() < 4) {
return result;
}
final int l = str.length() - 1;
int start = 0;
boolean inName = false;
for (int i = 0; i < l; i++) {
char c1 = str.charAt(i);
char c2 = str.charAt(i + 1);
if (!inName) {
if (c1 == '$' && c2 == '{') {
start = i + 2;
inName = true;
}
} else if (c2 == '}') {
final int stop = i + 1;
String v = str.substring(start, stop);
result.add(v);
inName = false;
}
}
return result;
}
}
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/gs1/GS1Util.java
21,6 → 21,7
// character.
// ]d2 : GS1 DataMatrix : Standard AI element strings
private static final String GS1_DATAMATRIX_SCANNER_PREFIX = "]d2";
private static final String GS1_DATAMATRIX_SCANNER_PREFIX_2 = "]D2";
// ]Q3 : GS1 QR Code : Standard AI element strings
private static final String GS1_QRCODE_SCANNER_PREFIX = "]Q3";
// ]J1 : GS1 DotCode : Standard AI element strings
51,7 → 52,8
}
 
public GS1AIElements parseFromScanner(String scan) throws GS1ParseException {
if (scan.startsWith(GS1_DATAMATRIX_SCANNER_PREFIX) || scan.startsWith(GS1_128_SCANNER_PREFIX) || scan.startsWith(GS1_DATABAR_SCANNER_PREFIX) || scan.startsWith(GS1_QRCODE_SCANNER_PREFIX)) {
if (scan.startsWith(GS1_DATAMATRIX_SCANNER_PREFIX) || scan.startsWith(GS1_DATAMATRIX_SCANNER_PREFIX_2) || scan.startsWith(GS1_128_SCANNER_PREFIX) || scan.startsWith(GS1_DATABAR_SCANNER_PREFIX)
|| scan.startsWith(GS1_QRCODE_SCANNER_PREFIX)) {
return parse(scan.substring(3));
}
return parse(scan);
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/graphicspl/GPLDemoFrame.java
New file
0,0 → 1,140
package org.openconcerto.modules.label.graphicspl;
 
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.datatransfer.DataFlavor;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.List;
 
import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.xml.parsers.ParserConfigurationException;
 
import org.xml.sax.SAXException;
 
public class GPLDemoFrame extends JFrame {
public GPLDemoFrame() {
JPanel p = new JPanel();
 
p.add(new JLabel("Drop your graphicspl file here"));
p.setDropTarget(new DropTarget() {
public synchronized void drop(DropTargetDropEvent evt) {
try {
evt.acceptDrop(DnDConstants.ACTION_COPY);
List<File> droppedFiles = (List<File>) evt.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
for (File file : droppedFiles) {
System.out.println("GPLDemoFrame.GPLDemoFrame().new DropTarget() {...}.drop()" + file.getAbsolutePath());
if (file.getName().endsWith(".graphicspl")) {
open(file);
break;
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
this.setContentPane(p);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
 
long last;
 
protected void open(File file) throws Exception {
loadFile(file);
last = file.lastModified();
Timer timer = new Timer(1000, new ActionListener() {
 
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("check");
long l = file.lastModified();
if (l != last) {
last = l;
// reload
System.out.println("check reload");
try {
loadFile(file);
} catch (ParserConfigurationException | SAXException | IOException e1) {
e1.printStackTrace();
}
 
}
 
}
});
timer.setRepeats(true);
timer.start();
 
}
 
public void loadFile(File file) throws ParserConfigurationException, SAXException, IOException {
GraphicsPL g = new GraphicsPL();
g.load(file);
BufferedImage img = g.createImage(1);
ImageIO.write(img, "png", new File(file.getParent(), file.getName() + ".png"));
System.out.println("GPLDemoFrame.loadFile() " + img.getWidth() + " x " + img.getHeight());
final Dimension dimension = new Dimension(img.getWidth(), img.getHeight());
JPanel iPanel = new JPanel() {
@Override
public Dimension getMinimumSize() {
 
return dimension;
}
 
@Override
public Dimension getPreferredSize() {
return new Dimension(img.getWidth(), img.getHeight());
}
 
@Override
public Dimension getMaximumSize() {
return new Dimension(img.getWidth(), img.getHeight());
}
 
@Override
public void paint(Graphics g) {
g.drawImage(img, 0, 0, null);
}
 
};
this.invalidate();
this.setContentPane(iPanel);
this.setSize(dimension);
this.revalidate();
this.repaint();
}
 
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
 
@Override
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
 
GPLDemoFrame f = new GPLDemoFrame();
f.setSize(300, 200);
f.setVisible(true);
f.setLocationRelativeTo(null);
}
});
 
}
 
}
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/graphicspl/GPLRenderer.java
96,7 → 96,9
String fileName = element.getAttribute("file");
int x = Math.round(ratio * Integer.parseInt(element.getAttribute("x")));
int y = Math.round(ratio * Integer.parseInt(element.getAttribute("y")));
BufferedImage img = ImageIO.read(new File(graphicsPL.getImageDir(), fileName));
final File input = new File(graphicsPL.getImageDir(), fileName);
if (input.exists()) {
BufferedImage img = ImageIO.read(input);
int w = Math.round(ratio * img.getWidth());
int h = Math.round(ratio * img.getHeight());
if (element.hasAttribute("width")) {
106,6 → 108,9
h = Math.round(ratio * Integer.parseInt(element.getAttribute("height")));
}
drawImage(x, y, w, h, img);
} else {
throw new IllegalStateException(input.getAbsolutePath() + " not found");
}
 
} else if (name.equals("barcode")) {
int x = Math.round(ratio * Integer.parseInt(element.getAttribute("x")));
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/graphicspl/GraphicsPL.java
24,8 → 24,8
import org.xml.sax.SAXException;
 
public class GraphicsPL {
String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><graphicspl height=\"400\" width=\"600\"/>";
Document doc;
private String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><graphicspl height=\"400\" width=\"600\"/>";
private Document doc;
private File imgDir;
 
public static void main(String[] args) throws Exception {
75,6 → 75,7
final BufferedImage img = createImage(ratio);
g2d.drawImage(img, (int) Math.round(pf.getImageableX()), (int) Math.round(pf.getImageableY()), width, height, null);
} catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace();
throw new PrinterException(e.getMessage());
}
return PAGE_EXISTS;
82,13 → 83,13
};
}
 
private String getZPL() throws IOException {
public String getZPL() throws IOException {
final ZPLRenderer renderer = new ZPLRenderer();
renderer.render(this);
return renderer.getZPL();
}
 
private BufferedImage createImage(float ratio) throws ParserConfigurationException, SAXException, IOException {
public BufferedImage createImage(float ratio) throws ParserConfigurationException, SAXException, IOException {
final Element root = this.doc.getDocumentElement();
final int width = Math.round(ratio * Integer.parseInt(root.getAttribute("width")));
final int height = Math.round(ratio * Integer.parseInt(root.getAttribute("height")));
106,7 → 107,7
return this.doc;
}
 
private void load(File file) throws ParserConfigurationException, SAXException, IOException {
public void load(File file) throws ParserConfigurationException, SAXException, IOException {
this.xml = new String(Files.readAllBytes(file.toPath()));
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
117,6 → 118,17
this.imgDir = file.getParentFile();
}
 
public void load(String str, File imageDir) throws ParserConfigurationException, SAXException, IOException {
this.xml = str;
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
// factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
final DocumentBuilder builder = factory.newDocumentBuilder();
final ByteArrayInputStream input = new ByteArrayInputStream(this.xml.getBytes(StandardCharsets.UTF_8));
this.doc = builder.parse(input);
this.doc.getDocumentElement().normalize();
this.imgDir = imageDir;
}
 
public File getImageDir() {
return this.imgDir;
}
/trunk/Modules/Module Label/src/org/openconcerto/modules/label/ImagePrintable.java
New file
0,0 → 1,46
package org.openconcerto.modules.label;
 
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.awt.print.PageFormat;
import java.awt.print.Printable;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
 
public class ImagePrintable implements Printable {
 
private double x, y, width;
 
private int orientation;
 
private BufferedImage image;
 
public ImagePrintable(PrinterJob printJob, BufferedImage image) {
PageFormat pageFormat = printJob.defaultPage();
this.x = pageFormat.getImageableX();
this.y = pageFormat.getImageableY();
this.width = pageFormat.getImageableWidth();
this.orientation = pageFormat.getOrientation();
this.image = image;
}
 
@Override
public int print(Graphics g, PageFormat pageFormat, int pageIndex) throws PrinterException {
if (pageIndex == 0) {
int pWidth = 0;
int pHeight = 0;
if (orientation == PageFormat.PORTRAIT) {
pWidth = (int) Math.min(width, (double) image.getWidth());
pHeight = pWidth * image.getHeight() / image.getWidth();
} else {
pHeight = (int) Math.min(width, (double) image.getHeight());
pWidth = pHeight * image.getWidth() / image.getHeight();
}
g.drawImage(image, (int) x, (int) y, pWidth, pHeight, null);
return PAGE_EXISTS;
} else {
return NO_SUCH_PAGE;
}
}
 
}
/trunk/Modules/Module Subscription/src/org/openconcerto/modules/subscription/panel/FacturesAboPanel.java
134,7 → 134,7
 
@Override
protected List<RowAction> getAdditionnalRowActions() {
return new MouseSheetXmlListeListener(VenteFactureXmlSheet.class).getRowActions();
return new MouseSheetXmlListeListener(this.eltFact, VenteFactureXmlSheet.class).getRowActions();
}
 
}
/trunk/Modules/Module Subscription/src/org/openconcerto/modules/subscription/panel/BonCommandeAboPanel.java
50,7 → 50,7
 
@Override
protected List<RowAction> getAdditionnalRowActions() {
return new MouseSheetXmlListeListener(CommandeClientXmlSheet.class).getRowActions();
return new MouseSheetXmlListeListener(this.eltCmd, CommandeClientXmlSheet.class).getRowActions();
}
 
}