svn-gvsig-desktop / 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 @ 47436
History | View | Annotate | Download (2.2 KB)
1 |
package org.gvsig.fmap.mapcontrol.dal.feature.swing.table; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Component; |
5 |
import javax.swing.JLabel; |
6 |
import javax.swing.JTable; |
7 |
import javax.swing.table.DefaultTableCellRenderer; |
8 |
import org.gvsig.fmap.dal.feature.Feature; |
9 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_BASIC; |
10 |
import static org.gvsig.fmap.dal.feature.Feature.CHECK_REQUIREDS; |
11 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author gvSIG Team
|
16 |
*/
|
17 |
@SuppressWarnings("UseSpecificCatch") |
18 |
public class FeatureAttributeCellRenderer extends DefaultTableCellRenderer { |
19 |
|
20 |
public FeatureAttributeCellRenderer() {
|
21 |
} |
22 |
|
23 |
@Override
|
24 |
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int 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){ |
31 |
try {
|
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 |
} |
46 |
} |
47 |
} |
48 |
} |
49 |
} catch (Exception ex) { |
50 |
return table.getBackground();
|
51 |
} |
52 |
return table.getBackground();
|
53 |
} |
54 |
|
55 |
|
56 |
public ConfigurableFeatureTableModel getTableModel(JTable table){ |
57 |
return (ConfigurableFeatureTableModel) table.getModel();
|
58 |
} |
59 |
|
60 |
} |