OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 181 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 ilm 1
package org.openconcerto.modules.common.batchprocessing;
2
 
3
import java.awt.Dimension;
4
import java.awt.event.ActionEvent;
5
import java.io.IOException;
6
import java.util.List;
7
 
8
import javax.swing.AbstractAction;
9
import javax.swing.JFrame;
10
 
11
import org.openconcerto.erp.modules.AbstractModule;
12
import org.openconcerto.erp.modules.ComponentsContext;
13
import org.openconcerto.erp.modules.ModuleFactory;
14
import org.openconcerto.sql.element.SQLElement;
15
import org.openconcerto.sql.model.SQLField;
183 ilm 16
import org.openconcerto.sql.model.SQLRowAccessor;
102 ilm 17
import org.openconcerto.sql.model.SQLRowValues;
18
import org.openconcerto.sql.view.list.IListe;
19
import org.openconcerto.sql.view.list.IListeAction.IListeEvent;
20
import org.openconcerto.sql.view.list.RowAction;
21
import org.openconcerto.ui.FrameUtil;
22
 
23
public final class Module extends AbstractModule {
24
 
183 ilm 25
	public Module(ModuleFactory f) throws IOException {
26
		super(f);
27
	}
102 ilm 28
 
183 ilm 29
	@Override
30
	protected void setupComponents(final ComponentsContext ctxt) {
102 ilm 31
 
183 ilm 32
		super.setupComponents(ctxt);
33
		final SQLElement element = ctxt.getElement("ARTICLE");
34
		final RowAction.PredicateRowAction editAction = new RowAction.PredicateRowAction(
35
				new AbstractAction("Traitement par lot...") {
102 ilm 36
 
183 ilm 37
					@Override
38
					public void actionPerformed(ActionEvent e) {
39
						final List<SQLRowAccessor> rows = IListe.get(e).getSelectedRowAccessors();
40
						final int size = rows.size();
41
						if (size > 0) {
42
							final JFrame f = new JFrame();
43
							if (size > 1) {
44
								f.setTitle("Traitement des " + size + " " + element.getPluralName());
45
							} else {
46
								f.setTitle("Traitement d'" + element.getSingularName());
47
							}
48
							FieldFilter filter = new FieldFilter() {
102 ilm 49
 
183 ilm 50
								@Override
51
								public boolean isFiltered(SQLField f) {
52
									final String fieldName = f.getName();
53
									return fieldName.contains("METRIQUE") || fieldName.equals("ID_STOCK");
54
								}
102 ilm 55
 
183 ilm 56
							};
102 ilm 57
 
183 ilm 58
							f.setContentPane(
59
									new BatchEditorPanel(ctxt.getElement("ARTICLE").getDirectory(), rows, filter));
60
							f.pack();
61
							f.setMinimumSize(new Dimension(400, 300));
62
							f.setLocationRelativeTo(IListe.get(e));
63
							FrameUtil.show(f);
64
						}
65
					}
66
				}, false) {
67
		};
68
		editAction.setPredicate(IListeEvent.getNonEmptySelectionPredicate());
69
		element.getRowActions().add(editAction);
102 ilm 70
 
183 ilm 71
	}
102 ilm 72
 
183 ilm 73
	@Override
74
	protected void start() {
75
	}
102 ilm 76
 
183 ilm 77
	@Override
78
	protected void stop() {
79
	}
102 ilm 80
 
81
}