Author: tchemit Date: 2013-02-28 10:03:00 +0100 (Thu, 28 Feb 2013) New Revision: 499 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/499 Log: refs #2025: change highlighter (for tests only) Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-28 08:57:24 UTC (rev 498) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-02-28 09:03:00 UTC (rev 499) @@ -83,7 +83,6 @@ import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.Serializable; -import java.util.Collection; import java.util.EnumMap; import java.util.List; import java.util.Map; @@ -392,7 +391,7 @@ List<Caracteristic> lengthCaracterics; - TuttiProtocol protocol = null; + TuttiProtocol protocol; if (context.isProtocolFilled()) { @@ -438,7 +437,7 @@ List<SampleCategoryType> samplingOrder; - List<Species> speciesUniverse = + List<Species> speciesUniverse = SPECIES_REFERENT_CONTEXT_ENTRY.getContextValue(ui); List<Species> allSpecies; @@ -463,7 +462,7 @@ SampleCategoryType.sex, SampleCategoryType.maturity, SampleCategoryType.age); - + // fill available species from protocol allSpecies = Lists.newArrayList(); @@ -476,7 +475,7 @@ String taxonId = String.valueOf(protocolSpecy.getSpeciesReferenceTaxonId()); Species species = map.get(taxonId); allSpecies.add(species); - + speciesSampleCategories.put(species, SampleCategoryType.sortedUnsorted); speciesSampleCategories.put(species, SampleCategoryType.size); speciesSampleCategories.put(species, SampleCategoryType.sex); @@ -484,7 +483,7 @@ speciesSampleCategories.put(species, SampleCategoryType.age); } } - + } else { // no protocol, use default values @@ -628,7 +627,7 @@ table.setModel(tableModel); table.setColumnModel(columnModel); - + Color toConfirmColor = getConfig().getColorRowToConfirm(); // paint the cell in orange if the row is to confirm Highlighter attachmentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( @@ -636,7 +635,7 @@ public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { int rowIndex = adapter.convertRowIndexToModel(adapter.row); - SpeciesBatchRowModel row = getTableModel().getEntry(rowIndex); + SpeciesBatchRowModel row = getTableModel().getEntry(adapter.row); return row.getSpeciesToConfirm(); } @@ -651,7 +650,7 @@ public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { int rowIndex = adapter.convertRowIndexToModel(adapter.row); - SpeciesBatchRowModel row = getTableModel().getEntry(rowIndex); + SpeciesBatchRowModel row = getTableModel().getEntry(adapter.row); return row.getSpeciesToConfirm() && !adapter.isEditable(); } @@ -674,7 +673,7 @@ getTable().setRowFilter(filter); } }); - + } @Override Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-02-28 08:57:24 UTC (rev 498) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-02-28 09:03:00 UTC (rev 499) @@ -291,22 +291,26 @@ // by default do not authorize to change column orders table.getTableHeader().setReorderingAllowed(false); - // paint in a special color read only cells + // paint in a special color for read only cells Highlighter readOnlyHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( HighlightPredicate.READ_ONLY, getConfig().getColorRowReadOnly()); table.addHighlighter(readOnlyHighlighter); + // paint in a special color for comment cell (with not null value) Color cellWithValueColor = getConfig().getColorCellWithValue(); Highlighter commentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( - new HighlightPredicate.IdentifierHighlightPredicate(SpeciesBatchTableModel.COMMENT), + new MyIdentifierHighlightPredicate(SpeciesBatchTableModel.COMMENT), + // for not null value new HighlightPredicate.NotHighlightPredicate(new HighlightPredicate.EqualsHighlightPredicate()) ), cellWithValueColor); table.addHighlighter(commentHighlighter); + // paint in a special color for attachment cell (with not null value) Highlighter attachmentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( new HighlightPredicate.AndHighlightPredicate( - new HighlightPredicate.IdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENTS), + new MyIdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENTS), + // for not null value new HighlightPredicate.NotHighlightPredicate(new HighlightPredicate.EqualsHighlightPredicate()) ), cellWithValueColor); table.addHighlighter(attachmentHighlighter); @@ -319,8 +323,7 @@ boolean result = false; if (adapter.isEditable()) { - int rowIndex = adapter.convertRowIndexToModel(adapter.row); - R row = getTableModel().getEntry(rowIndex); + R row = getTableModel().getEntry(adapter.row); result = !row.isValid(); } return result; Added: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java (rev 0) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java 2013-02-28 09:03:00 UTC (rev 499) @@ -0,0 +1,53 @@ +package fr.ifremer.tutti.ui.swing.util.table; + +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; + +import java.awt.Component; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +/** + * While using the swingX HighlightPredicate.IdentifierHighlightPredicate, it does not works very well with + * + * @author tchemit <chemit@codelutin.com> + * @since 1.0.2 + */ +public class MyIdentifierHighlightPredicate implements HighlightPredicate { + protected List<Object> columnList; + + /** + * Instantiates a predicate which returns true for the + * given column identifiers. + * + * @param columns the identitiers of the columns to highlight. + */ + public MyIdentifierHighlightPredicate(Object... columns) { + columnList = new ArrayList<Object>(); + Collections.addAll(columnList, columns); + } + + /** + * {@inheritDoc} + * <p/> + * This implementation returns true if the adapter's column + * is contained in this predicates list. + */ + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { +// int modelIndex = adapter.convertColumnIndexToModel(adapter.column); + Object identifier = adapter.getColumnIdentifierAt(adapter.column); + return identifier != null && columnList.contains(identifier); + } + + /** @return the identifiers */ + public Object[] getIdentifiers() { + if (columnList.isEmpty()) { + return EMPTY_OBJECT_ARRAY; + } else { + return columnList.toArray(new Object[0]); + } + } + +} \ No newline at end of file Property changes on: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/MyIdentifierHighlightPredicate.java ___________________________________________________________________ Added: svn:keywords + Author Date Id Revision Added: svn:eol-style + native