Revision 44259 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.expressionevaluator/org.gvsig.expressionevaluator.swing/org.gvsig.expressionevaluator.swing.api/src/main/java/org/gvsig/expressionevaluator/swing/spi/AbstractElement.java

View differences:

AbstractElement.java
1 1
package org.gvsig.expressionevaluator.swing.spi;
2 2

  
3
import java.util.Objects;
3 4
import javax.swing.ImageIcon;
4 5
import org.gvsig.expressionevaluator.swing.Element;
5 6
import org.gvsig.expressionevaluator.swing.ExpressionBuilderConfig;
......
18 19

  
19 20
    protected static final Logger LOGGER = LoggerFactory.getLogger(AbstractElement.class);
20 21
    
21
    final String name;
22
    final Object value;
22 23
    final String iconName;
23 24
    final ImageIcon icon;
25
    private final String name;
26
    private ExpressionBuilderConfig config;
24 27

  
25 28
    protected AbstractElement(String name) {
26
        this(name,null);
29
        this(name, name, null);
27 30
    }
28 31
    
29
    protected AbstractElement(String name, String iconName) {
30
        this.name = name;
32
    protected AbstractElement(String name, Object value) {
33
        this(name, value, null);
34
    }
35
    
36
    protected AbstractElement(String name, Object value, String iconName) {
37
        if( name == null ) {
38
            this.name = Objects.toString(value);
39
        } else {
40
            this.name = name;
41
        }
42
        if( value == null ) {
43
            this.value = name;
44
        } else {
45
            this.value = value;
46
        }
31 47
        this.iconName = iconName;
32 48
        IconTheme theme = ToolsSwingLocator.getIconThemeManager().getCurrent();
33 49
        if( theme.exists(iconName) ) {
......
38 54
            this.icon = theme.get("expressionbuilder-element");
39 55
        }
40 56
    }
57

  
58
    @Override
59
    public Element setConfig(ExpressionBuilderConfig config) {
60
        this.config = config;
61
        return this;
62
    }
41 63
    
42 64
    @Override
65
    public ExpressionBuilderConfig getConfig() {
66
        return this.config;
67
    }
68
    
69
    @Override
43 70
    public String getName() {
44 71
        return this.name;
45 72
    }
73
    
74
    @Override
75
    public Object getValue() {
76
        return this.value;
77
    }
46 78

  
47 79
    @Override
80
    public String getRenderedValue() {
81
        return Objects.toString(this.value);
82
    }
83

  
84
    @Override
48 85
    public String getDescription() {
49 86
        return null;
50 87
    }
51 88

  
52 89
    @Override
90
    public String getLabel() {
91
        return Objects.toString(this.value, "");
92
    }
93

  
94
    @Override
95
    @SuppressWarnings("StringEquality")
96
    public int compareTo(Object other) {
97
        String otherLabel = null;
98
        if( other!=null ) {
99
            otherLabel = other.toString();
100
        }
101
        String thisLabel = this.getLabel();
102
        if (thisLabel== otherLabel) {
103
            return 0;
104
        } else if (thisLabel== null) {
105
            return -1;
106
        } else if (otherLabel == null) {
107
            return 1;
108
        }
109
        return thisLabel.compareTo(otherLabel);        
110
    }
111
    
112
    @Override
53 113
    public String getIconName() {
54 114
        return iconName;
55 115
    }
......
58 118
    public ImageIcon getIcon() {
59 119
        return this.icon;
60 120
    }
121

  
122
    @Override
123
    public void used() {
124
    }
61 125
    
62 126
    @Override
63 127
    public Component getAditionalPanel(JExpressionBuilder expressionBuilder) {
......
66 130

  
67 131
    @Override
68 132
    public String toString() {
69
        return this.getName();
133
        return this.getLabel();
70 134
    }
71 135

  
72 136
    @Override

Also available in: Unified diff