80 |
ilm |
1 |
/*
|
|
|
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
|
|
|
3 |
*
|
|
|
4 |
* Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
|
|
|
5 |
*
|
|
|
6 |
* The contents of this file are subject to the terms of the GNU General Public License Version 3
|
|
|
7 |
* only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
|
|
|
8 |
* copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
|
|
|
9 |
* language governing permissions and limitations under the License.
|
|
|
10 |
*
|
|
|
11 |
* When distributing the software, include this License Header Notice in each file.
|
|
|
12 |
*/
|
|
|
13 |
|
|
|
14 |
package org.openconcerto.erp.modules;
|
|
|
15 |
|
|
|
16 |
import org.openconcerto.erp.core.common.element.ComptaSQLConfElement;
|
132 |
ilm |
17 |
import org.openconcerto.utils.ListMap;
|
80 |
ilm |
18 |
|
|
|
19 |
import java.util.Collections;
|
|
|
20 |
import java.util.List;
|
|
|
21 |
|
|
|
22 |
public abstract class ModuleElement extends ComptaSQLConfElement {
|
|
|
23 |
|
|
|
24 |
private final AbstractModule module;
|
|
|
25 |
|
|
|
26 |
public ModuleElement(AbstractModule module, String tableName) {
|
|
|
27 |
// needs DEFERRED since createCode() uses module
|
|
|
28 |
super(tableName, DEFERRED_CODE);
|
|
|
29 |
this.module = module;
|
|
|
30 |
// allow to access labels right away (see ModuleManager.registerSQLElements())
|
|
|
31 |
for (final String id : this.getAdditionalIDsForMDPath()) {
|
|
|
32 |
this.addToMDPath(ModuleManager.getMDVariant(new ModuleReference(id, null)));
|
|
|
33 |
}
|
|
|
34 |
this.addToMDPath(ModuleManager.getMDVariant(this.getFactory()));
|
|
|
35 |
}
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Additional modules to use for #getMDPath(). For this method to be useful, the returned
|
|
|
39 |
* modules must contain an element with same {@link #getCode() code} than this. E.g. this
|
|
|
40 |
* element adds some fields and modify some labels, but still want the default labels for other
|
|
|
41 |
* fields.
|
|
|
42 |
*
|
|
|
43 |
* @return module IDs.
|
|
|
44 |
*/
|
|
|
45 |
protected List<String> getAdditionalIDsForMDPath() {
|
|
|
46 |
return Collections.emptyList();
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
public final ModuleFactory getFactory() {
|
|
|
50 |
return this.module.getFactory();
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
// This implementation returns a unique code to allow for different modules to use the same
|
|
|
54 |
// table differently (at different times of course). Not final to allow subclasses to define a
|
|
|
55 |
// code following some rules (https://code.google.com/p/openconcerto/wiki/Modules) or to share
|
|
|
56 |
// code, see SQLElement#getCode()
|
|
|
57 |
@Override
|
|
|
58 |
protected String createCode() {
|
|
|
59 |
return this.module.getFactory().getID() + '/' + createCodeSuffix();
|
|
|
60 |
}
|
|
|
61 |
|
|
|
62 |
protected String createCodeSuffix() {
|
|
|
63 |
return getTable().getName();
|
|
|
64 |
}
|
132 |
ilm |
65 |
|
|
|
66 |
@Override
|
|
|
67 |
public ListMap<String, String> getShowAs() {
|
|
|
68 |
return ListMap.singleton(null, getComboFields());
|
|
|
69 |
}
|
80 |
ilm |
70 |
}
|