Line 19... |
Line 19... |
19 |
import org.openconcerto.sql.model.SQLName;
|
19 |
import org.openconcerto.sql.model.SQLName;
|
20 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
20 |
import org.openconcerto.sql.sqlobject.SQLTextCombo;
|
21 |
import org.openconcerto.sql.view.DropManager;
|
21 |
import org.openconcerto.sql.view.DropManager;
|
22 |
import org.openconcerto.sql.view.FileDropHandler;
|
22 |
import org.openconcerto.sql.view.FileDropHandler;
|
23 |
import org.openconcerto.sql.view.list.IListeAction;
|
23 |
import org.openconcerto.sql.view.list.IListeAction;
|
24 |
import org.openconcerto.sql.view.list.RowAction;
|
- |
|
25 |
import org.openconcerto.utils.CollectionMap;
|
24 |
import org.openconcerto.utils.ListMap;
|
26 |
|
25 |
|
27 |
import java.util.Set;
|
26 |
import java.util.Set;
|
28 |
|
27 |
|
29 |
import javax.swing.text.JTextComponent;
|
28 |
import javax.swing.text.JTextComponent;
|
30 |
|
29 |
|
Line 36... |
Line 35... |
36 |
|
35 |
|
37 |
public final class ComponentsContext extends ElementContext {
|
36 |
public final class ComponentsContext extends ElementContext {
|
38 |
|
37 |
|
39 |
private final Set<String> createdTables;
|
38 |
private final Set<String> createdTables;
|
40 |
// only for non-created tables
|
39 |
// only for non-created tables
|
41 |
private final CollectionMap<String, String> createdFields;
|
40 |
private final ListMap<String, String> createdFields;
|
42 |
// * module items
|
41 |
// * module items
|
43 |
private final CollectionMap<SQLElement, String> fields;
|
42 |
private final ListMap<SQLElement, String> fields;
|
44 |
private final CollectionMap<SQLElement, RowAction> rowActions;
|
43 |
private final ListMap<SQLElement, IListeAction> rowActions;
|
45 |
|
44 |
|
46 |
ComponentsContext(SQLElementDirectory dir, DBRoot root, final Set<String> tables, final Set<SQLName> fields) {
|
45 |
ComponentsContext(SQLElementDirectory dir, DBRoot root, final Set<String> tables, final Set<SQLName> fields) {
|
47 |
super(dir, root);
|
46 |
super(dir, root);
|
48 |
this.createdTables = tables;
|
47 |
this.createdTables = tables;
|
49 |
this.createdFields = new CollectionMap<String, String>();
|
48 |
this.createdFields = new ListMap<String, String>();
|
50 |
for (final SQLName f : fields) {
|
49 |
for (final SQLName f : fields) {
|
51 |
assert f.getItemCount() == 2;
|
50 |
assert f.getItemCount() == 2;
|
52 |
final String tableName = f.getFirst();
|
51 |
final String tableName = f.getFirst();
|
53 |
if (!this.createdTables.contains(tableName))
|
52 |
if (!this.createdTables.contains(tableName))
|
54 |
this.createdFields.put(tableName, f.getItem(1));
|
53 |
this.createdFields.add(tableName, f.getItem(1));
|
55 |
}
|
54 |
}
|
56 |
this.fields = new CollectionMap<SQLElement, String>();
|
55 |
this.fields = new ListMap<SQLElement, String>();
|
57 |
this.rowActions = new CollectionMap<SQLElement, RowAction>();
|
56 |
this.rowActions = new ListMap<SQLElement, IListeAction>();
|
58 |
}
|
57 |
}
|
59 |
|
58 |
|
60 |
private final SQLElement checkField(final String tableName, final String name) {
|
59 |
private final SQLElement checkField(final String tableName, final String name) {
|
61 |
if (this.createdTables.contains(tableName))
|
60 |
if (this.createdTables.contains(tableName))
|
62 |
throw new IllegalArgumentException("The table " + tableName + " was created by this module");
|
61 |
throw new IllegalArgumentException("The table " + tableName + " was created by this module");
|
Line 66... |
Line 65... |
66 |
}
|
65 |
}
|
67 |
|
66 |
|
68 |
public final void putAdditionalField(final String tableName, final String name) {
|
67 |
public final void putAdditionalField(final String tableName, final String name) {
|
69 |
final SQLElement elem = checkField(tableName, name);
|
68 |
final SQLElement elem = checkField(tableName, name);
|
70 |
if (elem.putAdditionalField(name)) {
|
69 |
if (elem.putAdditionalField(name)) {
|
71 |
this.fields.put(elem, name);
|
70 |
this.fields.add(elem, name);
|
72 |
} else {
|
71 |
} else {
|
73 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
72 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
74 |
}
|
73 |
}
|
75 |
}
|
74 |
}
|
76 |
|
75 |
|
77 |
public final void putAdditionalField(final String tableName, final String name, final JTextComponent comp) {
|
76 |
public final void putAdditionalField(final String tableName, final String name, final JTextComponent comp) {
|
78 |
final SQLElement elem = checkField(tableName, name);
|
77 |
final SQLElement elem = checkField(tableName, name);
|
79 |
if (elem.putAdditionalField(name, comp)) {
|
78 |
if (elem.putAdditionalField(name, comp)) {
|
80 |
this.fields.put(elem, name);
|
79 |
this.fields.add(elem, name);
|
81 |
} else {
|
80 |
} else {
|
82 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
81 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
83 |
}
|
82 |
}
|
84 |
}
|
83 |
}
|
85 |
|
84 |
|
86 |
public final void putAdditionalField(final String tableName, final String name, final SQLTextCombo comp) {
|
85 |
public final void putAdditionalField(final String tableName, final String name, final SQLTextCombo comp) {
|
87 |
final SQLElement elem = checkField(tableName, name);
|
86 |
final SQLElement elem = checkField(tableName, name);
|
88 |
if (elem.putAdditionalField(name, comp)) {
|
87 |
if (elem.putAdditionalField(name, comp)) {
|
89 |
this.fields.put(elem, name);
|
88 |
this.fields.add(elem, name);
|
90 |
} else {
|
89 |
} else {
|
91 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
90 |
throw new IllegalStateException("Already added " + name + " in " + elem);
|
92 |
}
|
91 |
}
|
93 |
}
|
92 |
}
|
94 |
|
93 |
|
95 |
final CollectionMap<SQLElement, String> getFields() {
|
94 |
final ListMap<SQLElement, String> getFields() {
|
96 |
return this.fields;
|
95 |
return this.fields;
|
97 |
}
|
96 |
}
|
98 |
|
97 |
|
99 |
// * actions
|
98 |
// * actions
|
100 |
|
99 |
|
101 |
public final void addListAction(final String tableName, final IListeAction action) {
|
100 |
public final void addListAction(final String tableName, final IListeAction action) {
|
102 |
final SQLElement elem = getElement(tableName);
|
101 |
final SQLElement elem = getElement(tableName);
|
103 |
this.rowActions.put(elem, action);
|
102 |
this.rowActions.add(elem, action);
|
104 |
elem.getRowActions().add(action);
|
103 |
elem.getRowActions().add(action);
|
105 |
}
|
104 |
}
|
106 |
|
105 |
|
107 |
final CollectionMap<SQLElement, RowAction> getRowActions() {
|
106 |
final ListMap<SQLElement, IListeAction> getRowActions() {
|
108 |
return this.rowActions;
|
107 |
return this.rowActions;
|
109 |
}
|
108 |
}
|
110 |
|
109 |
|
111 |
public final void addFileDropHandler(final String tableName, FileDropHandler handler) {
|
110 |
public final void addFileDropHandler(final String tableName, FileDropHandler handler) {
|
112 |
DropManager.getInstance().add(this.getRoot().getTable(tableName), handler);
|
111 |
DropManager.getInstance().add(this.getRoot().getTable(tableName), handler);
|