OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 149 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 149 Rev 156
Line 11... Line 11...
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.erp.core.common.element;
14
 package org.openconcerto.erp.core.common.element;
15
 
15
 
16
import org.openconcerto.erp.config.Gestion;
-
 
17
import org.openconcerto.sql.Configuration;
16
import org.openconcerto.sql.Configuration;
18
import org.openconcerto.sql.PropsConfiguration;
17
import org.openconcerto.sql.PropsConfiguration;
19
import org.openconcerto.sql.element.SQLElement;
18
import org.openconcerto.sql.element.SQLElement;
20
import org.openconcerto.sql.model.FieldPath;
19
import org.openconcerto.sql.model.FieldPath;
21
import org.openconcerto.sql.model.SQLField;
20
import org.openconcerto.sql.model.SQLField;
Line 73... Line 72...
73
 */
72
 */
74
public abstract class SocieteSQLConfElement extends SQLElement {
73
public abstract class SocieteSQLConfElement extends SQLElement {
75
    public static final String ACTION_ID_ADD = "add";
74
    public static final String ACTION_ID_ADD = "add";
76
    public static final String ACTION_ID_MODIFY = "modify";
75
    public static final String ACTION_ID_MODIFY = "modify";
77
    public static final String ACTION_ID_REMOVE = "remove";
76
    public static final String ACTION_ID_REMOVE = "remove";
78
    {
-
 
79
        this.setL18nLocation(Gestion.class);
-
 
80
    }
-
 
81
 
77
 
82
    public SocieteSQLConfElement(SQLTable table, String singular, String plural) {
78
    public SocieteSQLConfElement(SQLTable table, String singular, String plural) {
83
        super(singular, plural, table);
79
        super(singular, plural, table);
84
    }
80
    }
85
 
81
 
Line 109... Line 105...
109
        return AutoHideListener.listen(new JPanel());
105
        return AutoHideListener.listen(new JPanel());
110
    }
106
    }
111
 
107
 
112
    @Override
108
    @Override
113
    protected String createCode() {
109
    protected String createCode() {
-
 
110
        final String suffix = this.createCodeSuffix();
-
 
111
        if (suffix.indexOf(' ') >= 0)
-
 
112
            throw new IllegalStateException("Suffix contains space : '" + suffix + "'");
-
 
113
        if (suffix.length() < 2)
-
 
114
            throw new IllegalStateException("Suffix too short : '" + suffix + "'");
114
        return createCodeFromPackage();
115
        return createCodeOfPackage() + suffix;
-
 
116
    }
-
 
117
 
-
 
118
    protected String createCodeSuffix() {
-
 
119
        return this.createCodeSuffixFromTable();
-
 
120
    }
-
 
121
 
-
 
122
    protected final String createCodeSuffixFromTable() {
-
 
123
        return '.' + this.getTable().getName();
115
    }
124
    }
116
 
125
 
117
    /**
126
    /**
118
     * Return a code that doesn't change when subclassing to allow to easily change a SQLElement
127
     * Return a code that doesn't change when subclassing to allow to easily change a SQLElement
119
     * while keeping the same code. To achieve that, the code isn't
128
     * while keeping the same code. To achieve that, the code isn't
120
     * {@link #createCodeFromPackage(Class) computed} with <code>this.getClass()</code>. We iterate
129
     * {@link #createCodeOfPackage(Class) computed} with <code>this.getClass()</code>. We iterate up
121
     * up through our superclass chain, and as soon as we find an abstract class, we stop and use
130
     * through our superclass chain, and as soon as we find an abstract class, we stop and use the
122
     * the previous class (i.e. non abstract). E.g. any direct subclass of
131
     * previous class (i.e. non abstract). E.g. any direct subclass of {@link ComptaSQLConfElement}
123
     * {@link ComptaSQLConfElement} will still use <code>this.getClass()</code>, but so is one of
132
     * will still use <code>this.getClass()</code>, but so is one of its subclass.
124
     * its subclass.
-
 
125
     * 
133
     * 
126
     * @return a code computed from the superclass just under the first abstract superclass.
134
     * @return a code computed from the superclass just under the first abstract superclass.
127
     * @see #createCodeFromPackage(Class)
135
     * @see #createCodeOfPackage(Class)
128
     */
136
     */
129
    protected final String createCodeFromPackage() {
137
    protected final String createCodeOfPackage() {
130
        return createCodeFromPackage(getLastNonAbstractClass());
138
        return createCodeOfPackage(getLastNonAbstractClass());
131
    }
139
    }
132
 
140
 
133
    private final Class<? extends SocieteSQLConfElement> getLastNonAbstractClass() {
141
    private final Class<? extends SocieteSQLConfElement> getLastNonAbstractClass() {
134
        return getLastNonAbstractClass(this.getClass(), SocieteSQLConfElement.class);
142
        return getLastNonAbstractClass(this.getClass(), SocieteSQLConfElement.class);
135
    }
143
    }
Line 148... Line 156...
148
            cl = cl.getSuperclass();
156
            cl = cl.getSuperclass();
149
        }
157
        }
150
        return prev.asSubclass(superClass);
158
        return prev.asSubclass(superClass);
151
    }
159
    }
152
 
160
 
-
 
161
    static private final String ERP_CORE = ".erp.core.";
-
 
162
    static private final String ERP_ELEMENT = ".erp.element.";
-
 
163
 
153
    static protected String createCodeFromPackage(final Class<? extends SQLElement> cl) {
164
    static protected String createCodeOfPackage(final Class<? extends SQLElement> cl) {
154
        String canonicalName = cl.getName();
165
        String canonicalName = cl.getPackage().getName();
155
        if (canonicalName.contains("erp.core") && canonicalName.contains(".element")) {
166
        if (canonicalName.contains(ERP_CORE) && canonicalName.contains(".element")) {
156
            int i = canonicalName.indexOf("erp.core") + 9;
167
            int i = canonicalName.indexOf(ERP_CORE) + ERP_CORE.length();
157
            int j = canonicalName.indexOf(".element");
168
            int j = canonicalName.indexOf(".element");
158
            canonicalName = canonicalName.substring(i, j);
169
            canonicalName = canonicalName.substring(i, j);
-
 
170
        } else if (canonicalName.contains(ERP_ELEMENT)) {
-
 
171
            canonicalName = canonicalName.substring(canonicalName.indexOf(ERP_ELEMENT) + ERP_ELEMENT.length());
159
        }
172
        }
160
        return canonicalName;
173
        return canonicalName;
161
    }
174
    }
162
 
175
 
163
    @Override
176
    @Override