Revision 47436 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.fmap.control/src/main/java/org/gvsig/fmap/mapcontrol/dal/feature/swing/table/FeatureAttributeCellRenderer.java

View differences:

FeatureAttributeCellRenderer.java
2 2

  
3 3
import java.awt.Color;
4 4
import java.awt.Component;
5
import javax.swing.JLabel;
5 6
import javax.swing.JTable;
6
import javax.swing.UIManager;
7 7
import javax.swing.table.DefaultTableCellRenderer;
8 8
import org.gvsig.fmap.dal.feature.Feature;
9 9
import static org.gvsig.fmap.dal.feature.Feature.CHECK_BASIC;
10 10
import static org.gvsig.fmap.dal.feature.Feature.CHECK_REQUIREDS;
11 11
import org.gvsig.tools.swing.api.ToolsSwingLocator;
12
import org.gvsig.tools.swing.api.ToolsSwingManager;
13 12

  
14 13
/**
15 14
 *
......
18 17
@SuppressWarnings("UseSpecificCatch")
19 18
public class FeatureAttributeCellRenderer extends DefaultTableCellRenderer {
20 19

  
21
    protected ConfigurableFeatureTableModel tableModel;
22
    protected final Color backgroundColorOk;
23
    protected final Color backgroundColorWarning;
24

  
25
    public FeatureAttributeCellRenderer(ConfigurableFeatureTableModel tableModel) {
26
        this.tableModel = tableModel;
27
        this.backgroundColorOk = UIManager.getColor(ToolsSwingManager.COLOR_TABLE_BACKGROUND);
28
        this.backgroundColorWarning = ToolsSwingLocator.getToolsSwingManager().getWarningBackgroundColor();
20
    public FeatureAttributeCellRenderer() {
29 21
    }
30 22

  
31 23
    @Override
32 24
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
33
        super.getTableCellRendererComponent(table,value, isSelected, hasFocus,row, column);
25
        JLabel c = (JLabel) super.getTableCellRendererComponent(table,value, isSelected, hasFocus,row, column);
26
        c.setBackground(getBackgroundColor(table, isSelected, row, column));
27
        return c;
28
    }
29
    
30
    protected Color getBackgroundColor(JTable table, boolean isSelected, int row, int column){
34 31
        try {
35
            if( !isSelected ) {
36
                Feature feature = this.tableModel.getFeatureAt(row);
37
                this.setBackground(this.backgroundColorOk);
38
                if( tableModel.getFeatureStore().isFeatureModified(feature) ) {
39
                    try {
40
                        feature.validate(Feature.CHECK_RULES_AT_FINISH|CHECK_REQUIREDS|CHECK_BASIC);
41
                    } catch(Exception ex) {
42
                        this.setBackground(this.backgroundColorWarning);
32
            if( isSelected ) {
33
                return table.getSelectionBackground();
34
            } else {
35
                FeatureTableModel tableModel = getTableModel(table);
36
                Feature feature = tableModel.getFeatureAt(row);
37
                if(feature.isBroken()){
38
                    return ToolsSwingLocator.getToolsSwingManager().getWarningBackgroundColor();
39
                } else {
40
                    if( tableModel.getFeatureStore().isFeatureModified(feature) ) {
41
                        try {
42
                            feature.validate(Feature.CHECK_RULES_AT_FINISH|CHECK_REQUIREDS|CHECK_BASIC);
43
                        } catch(Exception ex) {
44
                            return ToolsSwingLocator.getToolsSwingManager().getWarningBackgroundColor();
45
                        }
43 46
                    }
44 47
                }
45 48
            }
46 49
        } catch (Exception ex) {
47
            // Do nothing, use values from default renderer
50
            return table.getBackground();
48 51
        }
49
        return this;
52
        return table.getBackground();
50 53
    }
54
    
55
    
56
    public ConfigurableFeatureTableModel getTableModel(JTable table){
57
        return (ConfigurableFeatureTableModel) table.getModel();
58
    }
51 59

  
52 60
}

Also available in: Unified diff