OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev 149 Rev 156
Line 157... Line 157...
157
            nounClass = null;
157
            nounClass = null;
158
            base = singular;
158
            base = singular;
159
        }
159
        }
160
        final Phrase res = new Phrase(Grammar_fr.getInstance(), base, nounClass);
160
        final Phrase res = new Phrase(Grammar_fr.getInstance(), base, nounClass);
161
        if (nounClass != null)
161
        if (nounClass != null)
162
            res.putVariant(Grammar.INDEFINITE_ARTICLE_SINGULAR, singular);
162
            res.putVariantIfDifferent(Grammar.INDEFINITE_ARTICLE_SINGULAR, singular);
163
        res.putVariant(Grammar.PLURAL, plural);
163
        res.putVariantIfDifferent(Grammar.PLURAL, plural);
164
        return res;
164
        return res;
165
    }
165
    }
166
 
166
 
167
    // from the most loss of information to the least.
167
    // from the most loss of information to the least.
168
    public static enum ReferenceAction {
168
    public static enum ReferenceAction {
Line 182... Line 182...
182
     */
182
     */
183
    static final public String DEFERRED_CODE = new String("deferred code");
183
    static final public String DEFERRED_CODE = new String("deferred code");
184
 
184
 
185
    @GuardedBy("this")
185
    @GuardedBy("this")
186
    private SQLElementDirectory directory;
186
    private SQLElementDirectory directory;
187
    private String l18nPkgName;
-
 
188
    private Class<?> l18nClass;
-
 
189
    private Phrase name;
187
    private Phrase defaultName;
190
    private final SQLTable primaryTable;
188
    private final SQLTable primaryTable;
191
    // used as a key in SQLElementDirectory so it should be immutable
189
    // used as a key in SQLElementDirectory so it should be immutable
192
    private String code;
190
    private String code;
193
    private ComboSQLRequest combo;
191
    private ComboSQLRequest combo;
194
    private ListSQLRequest list;
192
    private ListSQLRequest list;
Line 231... Line 229...
231
        super();
229
        super();
232
        if (primaryTable == null) {
230
        if (primaryTable == null) {
233
            throw new DBStructureItemNotFound("table is null for " + this.getClass());
231
            throw new DBStructureItemNotFound("table is null for " + this.getClass());
234
        }
232
        }
235
        this.primaryTable = primaryTable;
233
        this.primaryTable = primaryTable;
236
        this.setL18nPackageName(null);
-
 
237
        this.setDefaultName(name);
234
        this.setDefaultName(name);
238
        this.code = code == null ? createCode() : code;
235
        this.code = code == null ? createCode() : code;
239
        this.combo = null;
236
        this.combo = null;
240
        this.list = null;
237
        this.list = null;
241
        this.rowActions = new ListChangeRecorder<IListeAction>(new ArrayList<IListeAction>());
238
        this.rowActions = new ListChangeRecorder<IListeAction>(new ArrayList<IListeAction>());
Line 254... Line 251...
254
    public void destroy() {
251
    public void destroy() {
255
    }
252
    }
256
 
253
 
257
    /**
254
    /**
258
     * Should return the code for this element. This method is only called if the <code>code</code>
255
     * Should return the code for this element. This method is only called if the <code>code</code>
-
 
256
     * parameter of the constructor is <code>null</code>. This implementation returns a string
-
 
257
     * containing the {@link Class#getName() full name} of the class and the {@link #getTable()
-
 
258
     * table} name to handle a single class being used for multiple tables. NOTE: this method is
-
 
259
     * also needed, since a subclass constructor cannot pass <code>this.getClass().getName()</code>
259
     * parameter of the constructor is <code>null</code>.
260
     * as the code parameter to <code>super</code>.
260
     * 
261
     * 
261
     * @return the default code for this element.
262
     * @return the default code for this element.
262
     */
263
     */
263
    protected String createCode() {
264
    protected String createCode() {
264
        return getClass().getName() + "-" + getTable().getName();
265
        return getClass().getName() + "-" + getTable().getName();
Line 596... Line 597...
596
        return this.ownedLinks != null;
597
        return this.ownedLinks != null;
597
    }
598
    }
598
 
599
 
599
    // return Path from owner to owned
600
    // return Path from owner to owned
600
    private final Set<Path> createPaths(final boolean wantedOwned) {
601
    private final Set<Path> createPaths(final boolean wantedOwned) {
-
 
602
        // joins cannot have SQLElementLink
601
        assert !(this instanceof JoinSQLElement) : "joins cannot have SQLElementLink : " + this;
603
        if (this instanceof JoinSQLElement)
-
 
604
            return Collections.emptySet();
-
 
605
 
602
        final SQLTable thisTable = this.getTable();
606
        final SQLTable thisTable = this.getTable();
603
        final Set<Link> allLinks = thisTable.getDBSystemRoot().getGraph().getAllLinks(getTable());
607
        final Set<Link> allLinks = thisTable.getDBSystemRoot().getGraph().getAllLinks(getTable());
604
        final Set<Path> res = new HashSet<Path>();
608
        final Set<Path> res = new HashSet<Path>();
605
        for (final Link l : allLinks) {
609
        for (final Link l : allLinks) {
606
            final boolean owned;
610
            final boolean owned;
Line 752... Line 756...
752
    }
756
    }
753
 
757
 
754
    private synchronized void initRF() {
758
    private synchronized void initRF() {
755
        if (this.otherLinks != null)
759
        if (this.otherLinks != null)
756
            return;
760
            return;
-
 
761
 
757
        final Set<Path> otherPaths = this.createPaths(false);
762
        final Set<Path> otherPaths = this.createPaths(false);
-
 
763
        if (otherPaths.isEmpty()) {
-
 
764
            this.otherLinks = SQLElementLinks.empty();
-
 
765
        } else {
758
        final SetMap<LinkType, SQLElementLink> tmp = new SetMap<LinkType, SQLElementLink>();
766
            final SetMap<LinkType, SQLElementLink> tmp = new SetMap<LinkType, SQLElementLink>();
759
        for (final Path p : otherPaths) {
767
            for (final Path p : otherPaths) {
760
            final SQLElement refElem = this.getElementLenient(p.getFirst());
768
                final SQLElement refElem = this.getElementLenient(p.getFirst());
761
            final SQLElementLink elementLink;
769
                final SQLElementLink elementLink;
762
            if (refElem == null) {
770
                if (refElem == null) {
Line 768... Line 776...
768
            }
776
                }
769
            tmp.add(elementLink.getLinkType(), elementLink);
777
                tmp.add(elementLink.getLinkType(), elementLink);
770
        }
778
            }
771
        this.otherLinks = new SQLElementLinks(tmp);
779
            this.otherLinks = new SQLElementLinks(tmp);
772
    }
780
        }
-
 
781
    }
773
 
782
 
774
    final void setDirectory(final SQLElementDirectory directory) {
783
    final void setDirectory(final SQLElementDirectory directory) {
775
        // since this method should only be called at the end of SQLElementDirectory.addSQLElement()
784
        // since this method should only be called at the end of SQLElementDirectory.addSQLElement()
776
        assert directory == null || directory.getElement(this.getTable()) == this;
785
        assert directory == null || directory.getElement(this.getTable()) == this;
777
        synchronized (this) {
786
        synchronized (this) {
Line 810... Line 819...
810
 
819
 
811
    private final SQLTable getForeignTable(String foreignField) {
820
    private final SQLTable getForeignTable(String foreignField) {
812
        return this.getTable().getBase().getGraph().getForeignTable(this.getTable().getField(foreignField));
821
        return this.getTable().getBase().getGraph().getForeignTable(this.getTable().getField(foreignField));
813
    }
822
    }
814
 
823
 
815
    public final synchronized String getL18nPackageName() {
-
 
816
        return this.l18nPkgName;
-
 
817
    }
-
 
818
 
-
 
819
    public final synchronized Class<?> getL18nClass() {
-
 
820
        return this.l18nClass;
-
 
821
    }
-
 
822
 
-
 
823
    public final void setL18nLocation(Class<?> clazz) {
-
 
824
        this.setL18nLocation(clazz.getPackage().getName(), clazz);
-
 
825
    }
-
 
826
 
-
 
827
    public final void setL18nPackageName(String name) {
-
 
828
        this.setL18nLocation(name, null);
-
 
829
    }
-
 
830
 
-
 
831
    /**
-
 
832
     * Set the location for the localized name.
-
 
833
     * 
-
 
834
     * @param name a package name, can be <code>null</code> :
-
 
835
     *        {@link SQLElementDirectory#getL18nPackageName()} will be used.
-
 
836
     * @param ctxt the class loader to load the resource, <code>null</code> meaning this class.
-
 
837
     * @see SQLElementDirectory#getName(SQLElement)
-
 
838
     */
-
 
839
    public final synchronized void setL18nLocation(final String name, final Class<?> ctxt) {
-
 
840
        this.l18nPkgName = name;
-
 
841
        this.l18nClass = ctxt == null ? this.getClass() : ctxt;
-
 
842
    }
-
 
843
 
-
 
844
    /**
824
    /**
845
     * Set the default name, used if no translations could be found.
825
     * Set the default name, used if no translations could be found.
846
     * 
826
     * 
847
     * @param name the default name, if <code>null</code> the {@link #getTable() table} name will be
827
     * @param name the default name, if <code>null</code> the {@link #getTable() table} name will be
848
     *        used.
828
     *        used.
849
     */
829
     */
850
    public final synchronized void setDefaultName(Phrase name) {
830
    public final synchronized void setDefaultName(Phrase name) {
851
        this.name = name != null ? name : Phrase.getInvariant(getTable().getName());
831
        this.defaultName = name != null ? name : Phrase.getInvariant(getTable().getName());
852
    }
832
    }
853
 
833
 
854
    /**
834
    /**
855
     * The default name.
835
     * The default name.
856
     * 
836
     * 
857
     * @return the default name, never <code>null</code>.
837
     * @return the default name, never <code>null</code>.
858
     */
838
     */
859
    public final synchronized Phrase getDefaultName() {
839
    public final synchronized Phrase getDefaultName() {
860
        return this.name;
840
        return this.defaultName;
861
    }
841
    }
862
 
842
 
863
    /**
843
    /**
864
     * The name of this element in the current locale.
844
     * The name of this element in the current locale.
865
     * 
845
     * 
Line 867... Line 847...
867
     *         directory} or if it hasn't a name for this.
847
     *         directory} or if it hasn't a name for this.
868
     * @see SQLElementDirectory#getName(SQLElement)
848
     * @see SQLElementDirectory#getName(SQLElement)
869
     */
849
     */
870
    public final Phrase getName() {
850
    public final Phrase getName() {
871
        final SQLElementDirectory dir = this.getDirectory();
851
        final SQLElementDirectory dir = this.getDirectory();
-
 
852
        final SQLFieldTranslator trns = dir == null ? null : dir.getTranslator();
872
        final Phrase res = dir == null ? null : dir.getName(this);
853
        final Phrase res = trns == null ? null : trns.getElementName(this);
873
        return res == null ? this.getDefaultName() : res;
854
        return res == null ? this.getDefaultName() : res;
874
    }
855
    }
875
 
856
 
876
    public String getPluralName() {
857
    public String getPluralName() {
877
        return this.getName().getVariant(Grammar.PLURAL);
858
        return this.getName().getVariant(Grammar.PLURAL);