OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

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

Rev Author Line No. Line
74 ilm 1
package org.openconcerto.modules.extensionbuilder.table;
2
 
3
public class FieldDescriptor {
4
    public static final String TYPE_STRING = "string";
5
    public static final String TYPE_INTEGER = "integer";
6
    public static final String TYPE_DECIMAL = "decimal";
7
    public static final String TYPE_BOOLEAN = "boolean";
8
    public static final String TYPE_DATE = "date";
9
    public static final String TYPE_TIME = "time";
10
    public static final String TYPE_DATETIME = "dateAndTime";
11
    public static final String TYPE_REF = "ref";
12
    private final String table;
13
 
14
    private String name;
15
    private String type;
16
    private String defaultValue;
17
    private String length;
18
    private FieldDescriptor link;
19
    private String foreignTable;
20
 
21
    public FieldDescriptor(String table, String name, String type, String defaultValue, String length, String foreingTable) {
22
        this.table = table;
23
        this.name = name;
24
        this.type = type;
25
        this.defaultValue = defaultValue;
26
        this.length = length;
27
        this.foreignTable = foreingTable;
28
    }
29
 
30
    public FieldDescriptor(FieldDescriptor f) {
31
        this.name = f.name;
32
        this.type = f.type;
33
        this.defaultValue = f.defaultValue;
34
        this.length = f.length;
35
        this.table = f.table;
36
        this.foreignTable = f.foreignTable;
37
    }
38
 
39
    @Override
40
    public String toString() {
41
        String string = this.table + " " + this.name + " type:" + this.type + " default:" + this.defaultValue + " l:" + this.length + " t:" + this.foreignTable;
181 ilm 42
        if (this.link != null) {
43
            string += " => " + this.link.toString();
74 ilm 44
        }
45
        return string;
46
    }
47
 
48
    public String getName() {
181 ilm 49
        return this.name;
74 ilm 50
    }
51
 
52
    public void setName(String name) {
53
        this.name = name;
54
    }
55
 
56
    public String getType() {
181 ilm 57
        return this.type;
74 ilm 58
    }
59
 
60
    public void setType(String type) {
61
        this.type = type;
62
    }
63
 
64
    public String getDefaultValue() {
181 ilm 65
        return this.defaultValue;
74 ilm 66
    }
67
 
68
    public void setDefaultValue(String defaultValue) {
69
        this.defaultValue = defaultValue;
70
    }
71
 
72
    public String getLength() {
181 ilm 73
        return this.length;
74 ilm 74
    }
75
 
76
    public void setLength(String length) {
77
        this.length = length;
78
    }
79
 
80
    public String getTable() {
181 ilm 81
        return this.table;
74 ilm 82
    }
83
 
84
    public void setLink(FieldDescriptor fieldDescriptor) {
85
        this.link = fieldDescriptor;
86
    }
87
 
88
    public FieldDescriptor getLink() {
181 ilm 89
        return this.link;
74 ilm 90
    }
91
 
92
    public void setForeignTable(String foreignTable) {
93
        this.foreignTable = foreignTable;
94
    }
95
 
96
    public String getForeignTable() {
181 ilm 97
        return this.foreignTable;
74 ilm 98
    }
99
 
100
    public String getExtendedLabel() {
101
        FieldDescriptor f = this;
102
        String label = f.getName();
103
        while (f.getLink() != null) {
104
            label += " / " + f.getLink().getName();
105
            f = f.getLink();
106
        }
107
        return label;
108
    }
109
 
110
    @Override
111
    public boolean equals(Object obj) {
112
        if (obj instanceof FieldDescriptor) {
113
            FieldDescriptor f = (FieldDescriptor) obj;
181 ilm 114
            if (getTable().equals(f.getTable()) && getName().equals(f.getName())) {
115
                return (getLink() == null && f.getLink() == null) || (getLink() != null && getLink().equals(f.getLink()));
74 ilm 116
            } else {
117
                return false;
118
            }
119
        }
120
        return false;
121
    }
122
 
123
    @Override
124
    public int hashCode() {
125
        return this.table.hashCode();
126
    }
127
 
128
    public String getPath() {
129
        FieldDescriptor f = this;
130
        String label = f.getName();
131
        while (f.getLink() != null) {
132
            label += "." + f.getLink().getName();
133
            f = f.getLink();
134
        }
135
        return label;
136
    }
137
}