r250 - in trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing: config content/operation/catches/species content/operation/catches/species/frequency util/editor util/table
Author: kmorin Date: 2013-01-28 13:04:12 +0100 (Mon, 28 Jan 2013) New Revision: 250 Url: http://forge.codelutin.com/projects/tutti/repository/revisions/250 Log: closes #1853 [ERGO] - Gestion des champs commentaires Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java 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/frequency/FrequencyCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.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/config/TuttiConfig.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfig.java 2013-01-28 12:04:12 UTC (rev 250) @@ -187,6 +187,10 @@ public Color getColorRowReadOnly() { return applicationConfig.getOptionAsColor(TuttiConfigOption.COLOR_ROW_READ_ONLY.getKey()); } + + public Color getColorCellWithValue() { + return applicationConfig.getOptionAsColor(TuttiConfigOption.COLOR_CELL_WITH_VALUE.getKey()); + } public KeyStroke getShortcutClosePopup() { return applicationConfig.getOptionAsKeyStroke(TuttiConfigOption.SHORTCUT_CLOSE_POPUP.getKey()); Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigOption.java 2013-01-28 12:04:12 UTC (rev 250) @@ -141,6 +141,13 @@ new Color(255, 128, 128).toString(), Color.class ), + + COLOR_CELL_WITH_VALUE( + "tutti.ui.color.cellWithValue", + n_("tutti.config.ui.color.cellWithValue"), + new Color(128, 255, 128).toString(), + Color.class + ), SHORTCUT_CLOSE_POPUP( "tutti.ui.shortcut.closePopup", Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/config/TuttiConfigUI.java 2013-01-28 12:04:12 UTC (rev 250) @@ -108,6 +108,7 @@ CALLBACK_UI) .addOption(TuttiConfigOption.COLOR_ROW_INVALID) .addOption(TuttiConfigOption.COLOR_ROW_READ_ONLY) + .addOption(TuttiConfigOption.COLOR_CELL_WITH_VALUE) .addOption(TuttiConfigOption.DATE_FORMAT) .addOption(TuttiConfigOption.COORDINATE_EDITOR_TYPE); 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-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/SpeciesBatchUIHandler.java 2013-01-28 12:04:12 UTC (rev 250) @@ -58,6 +58,8 @@ import fr.ifremer.tutti.ui.swing.util.editor.LongTextCellComponent; import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import java.awt.Color; +import java.awt.Component; import jaxx.runtime.JAXXUtil; import jaxx.runtime.context.JAXXContextEntryDef; import jaxx.runtime.swing.ErrorDialogUI; @@ -77,6 +79,9 @@ import java.util.EnumMap; import java.util.List; import java.util.Set; +import org.jdesktop.swingx.decorator.ComponentAdapter; +import org.jdesktop.swingx.decorator.HighlightPredicate; +import org.jdesktop.swingx.decorator.Highlighter; import static org.nuiton.i18n.I18n._; import static org.nuiton.i18n.I18n.n_; @@ -621,6 +626,7 @@ getTable().setRowFilter(filter); } }); + } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/content/operation/catches/species/frequency/FrequencyCellComponent.java 2013-01-28 12:04:12 UTC (rev 250) @@ -37,7 +37,6 @@ import org.apache.commons.logging.LogFactory; import javax.swing.AbstractCellEditor; -import javax.swing.JButton; import javax.swing.JTable; import javax.swing.border.LineBorder; import javax.swing.table.TableCellEditor; @@ -49,6 +48,7 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import java.util.List; +import javax.swing.table.DefaultTableCellRenderer; import static org.nuiton.i18n.I18n._; @@ -58,7 +58,7 @@ * @author tchemit <chemit@codelutin.com> * @since 0.2 */ -public class FrequencyCellComponent extends JButton { +public class FrequencyCellComponent extends DefaultTableCellRenderer { private static final long serialVersionUID = 1L; @@ -69,8 +69,7 @@ LogFactory.getLog(FrequencyCellComponent.class); public FrequencyCellComponent() { - setContentAreaFilled(false); - setOpaque(false); + setHorizontalAlignment(CENTER); setIcon(SwingUtil.createActionIcon("show-frequency")); } @@ -271,16 +270,22 @@ int row, int column) { - String text; - if (value == null) { - text = " - "; - } else { - text = String.valueOf(value); + FrequencyCellComponent result = + (FrequencyCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + + if (table != null) { + String text; + if (value == null) { + text = " - "; + } else { + text = String.valueOf(value); + } + boolean editable = table.isCellEditable(row, column); + result.setEnabled(editable); + result.setText(text); } - boolean editable = table.isCellEditable(row, column); - component.setEnabled(editable); - component.setText(text); - return component; + + return result; } } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/AttachmentCellComponent.java 2013-01-28 12:04:12 UTC (rev 250) @@ -41,7 +41,6 @@ import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; -import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JTable; import javax.swing.border.LineBorder; @@ -57,6 +56,7 @@ import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.Collection; +import javax.swing.table.DefaultTableCellRenderer; import static org.nuiton.i18n.I18n._; @@ -66,7 +66,7 @@ * @author kmorin * @since 0.2 */ -public class AttachmentCellComponent extends JButton { +public class AttachmentCellComponent extends DefaultTableCellRenderer { /** Logger. */ private static final Log log = LogFactory.getLog(AttachmentCellComponent.class); @@ -74,11 +74,15 @@ private static final long serialVersionUID = 1L; public AttachmentCellComponent() { - setContentAreaFilled(false); - setOpaque(false); + setHorizontalAlignment(CENTER); setIcon(SwingUtil.createActionIcon("edit-attachment")); } + @Override + protected void setValue(Object value) { + // do nothing + } + public static TableCellRenderer newRender(Decorator<Attachment> decorator, String noneText) { return new AttachmentCellRenderer(decorator, noneText); } @@ -87,7 +91,6 @@ return new AttachmentCellEditor(ui); } - public static class AttachmentCellEditor extends AbstractCellEditor implements TableCellEditor { private static final long serialVersionUID = 1L; @@ -276,33 +279,38 @@ boolean hasFocus, int row, int column) { + AttachmentCellComponent result = + (AttachmentCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + + if (table != null) { + + String textValue; + if (value == null) { + if (propertyName == null) { + AbstractTuttiTableModel tableModel = + (AbstractTuttiTableModel) table.getModel(); + ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); + propertyName = columnIdentifier.getPropertyName(); + } + // use HTML to show the tooltip in italic + textValue = "<i>" + _(noneText) + "</i>"; - String textValue; - - if (value == null) { - if (propertyName == null) { - AbstractTuttiTableModel tableModel = - (AbstractTuttiTableModel) table.getModel(); - ColumnIdentifier columnIdentifier = tableModel.getPropertyName(column); - propertyName = columnIdentifier.getPropertyName(); + } else { + Collection<Attachment> attachments = (Collection<Attachment>) value; + StringBuilder sb = new StringBuilder(); + for (Attachment attachment : attachments) { + sb.append("<br/>").append(decorator.toString(attachment)); + } + // use html to display the tooltip on several lines + textValue = sb.substring(5); } - // use HTML to show the tooltip in italic - textValue = "<i>" + _(noneText) + "</i>"; - - } else { - Collection<Attachment> attachments = (Collection<Attachment>) value; - StringBuilder sb = new StringBuilder(); - for (Attachment attachment : attachments) { - sb.append("<br/>").append(decorator.toString(attachment)); - } - // use html to display the tooltip on several lines - textValue = sb.substring(5); + String text = String.format(TEXT_PATTERN, textValue); + boolean editable = table.isCellEditable(row, column); + result.setEnabled(editable); + result.setToolTipText(text); } - String text = String.format(TEXT_PATTERN, textValue); - boolean editable = table.isCellEditable(row, column); - component.setEnabled(editable); - component.setToolTipText(text); - return component; + + return result; } } } Modified: trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java =================================================================== --- trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2013-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/editor/LongTextCellComponent.java 2013-01-28 12:04:12 UTC (rev 250) @@ -32,6 +32,7 @@ import fr.ifremer.tutti.ui.swing.util.table.AbstractSelectTableAction; import fr.ifremer.tutti.ui.swing.util.table.AbstractTuttiTableModel; import fr.ifremer.tutti.ui.swing.util.table.ColumnIdentifier; +import java.awt.Color; import jaxx.runtime.JAXXUtil; import jaxx.runtime.SwingUtil; import org.apache.commons.lang3.StringUtils; @@ -40,13 +41,11 @@ import javax.swing.AbstractCellEditor; import javax.swing.BorderFactory; -import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JTable; import javax.swing.border.LineBorder; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; -import java.awt.Color; import java.awt.Component; import java.awt.Frame; import java.awt.event.KeyAdapter; @@ -55,6 +54,7 @@ import java.awt.event.MouseEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; +import javax.swing.table.DefaultTableCellRenderer; import static org.nuiton.i18n.I18n._; @@ -64,7 +64,7 @@ * @author kmorin * @since 0.2 */ -public class LongTextCellComponent extends JButton { +public class LongTextCellComponent extends DefaultTableCellRenderer { /** Logger. */ private static final Log log = LogFactory.getLog(LongTextCellComponent.class); @@ -72,11 +72,15 @@ private static final long serialVersionUID = 1L; public LongTextCellComponent() { - setContentAreaFilled(false); - setOpaque(false); + setHorizontalAlignment(CENTER); setIcon(SwingUtil.createActionIcon("edit-comment")); } + @Override + protected void setValue(Object value) { + // do nothing + } + public static TableCellRenderer newRender(String noneText) { return new LongTextCellRenderer(noneText); } @@ -274,30 +278,35 @@ int row, int column) { -// String text; - String textValue; - if (StringUtils.isBlank((String) value)) { - if (propertyName == null) { - AbstractTuttiTableModel tableModel = - (AbstractTuttiTableModel) table.getModel(); - ColumnIdentifier columnIdentifier = - tableModel.getPropertyName(column); - propertyName = columnIdentifier.getPropertyName(); + LongTextCellComponent result = + (LongTextCellComponent) component.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); + + if (table != null) { + String textValue; + if (StringUtils.isBlank((String) value)) { + if (propertyName == null) { + AbstractTuttiTableModel tableModel = + (AbstractTuttiTableModel) table.getModel(); + ColumnIdentifier columnIdentifier = + tableModel.getPropertyName(column); + propertyName = columnIdentifier.getPropertyName(); + } + // use HTML to show the tooltip in italic + textValue = "<i>" + _(noneText) + "</i>"; + + } else { + // use html to display the tooltip on several lines + textValue = String.valueOf(value).replace("\n", "<br/>"); } - // use HTML to show the tooltip in italic - textValue = "<i>" + _(noneText) + "</i>"; - } else { - // use html to display the tooltip on several lines - textValue = String.valueOf(value).replace("\n", "<br/>"); + String text = String.format(TEXT_PATTERN, textValue); + + boolean editable = table.isCellEditable(row, column); + result.setEnabled(editable); + result.setToolTipText(text); } - - String text = String.format(TEXT_PATTERN, textValue); - - boolean editable = table.isCellEditable(row, column); - component.setEnabled(editable); - component.setToolTipText(text); - return component; + + return result; } } } 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-01-28 11:26:25 UTC (rev 249) +++ trunk/tutti-ui-swing/src/main/java/fr/ifremer/tutti/ui/swing/util/table/AbstractTuttiTableUIHandler.java 2013-01-28 12:04:12 UTC (rev 250) @@ -31,6 +31,7 @@ import fr.ifremer.tutti.ui.swing.AbstractTuttiBeanUIModel; import fr.ifremer.tutti.ui.swing.AbstractTuttiUIHandler; import fr.ifremer.tutti.ui.swing.TuttiUIContext; +import fr.ifremer.tutti.ui.swing.content.operation.catches.species.SpeciesBatchTableModel; import fr.ifremer.tutti.ui.swing.util.TuttiBeanMonitor; import fr.ifremer.tutti.ui.swing.util.TuttiUIUtil; import jaxx.runtime.SwingUtil; @@ -292,6 +293,31 @@ Highlighter readOnlyHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( HighlightPredicate.READ_ONLY, getConfig().getColorRowReadOnly()); table.addHighlighter(readOnlyHighlighter); + + Color cellWithValueColor = getConfig().getColorCellWithValue(); + Highlighter commentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( + new HighlightPredicate.AndHighlightPredicate( + new HighlightPredicate.IdentifierHighlightPredicate(SpeciesBatchTableModel.COMMENT), + new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + boolean result = adapter.getValue() != null; + return result; + } + }), cellWithValueColor); + table.addHighlighter(commentHighlighter); + + Highlighter attachmentHighlighter = TuttiUIUtil.newBackgroundColorHighlighter( + new HighlightPredicate.AndHighlightPredicate( + new HighlightPredicate.IdentifierHighlightPredicate(SpeciesBatchTableModel.ATTACHMENTS), + new HighlightPredicate() { + @Override + public boolean isHighlighted(Component renderer, ComponentAdapter adapter) { + boolean result = adapter.getValue() != null; + return result; + } + }), cellWithValueColor); + table.addHighlighter(attachmentHighlighter); // paint in a special color inValid rows Highlighter validHighlighter = TuttiUIUtil.newBackgroundColorHighlighter(
participants (1)
-
kmorin@users.forge.codelutin.com