Commit 5d1a4295 authored by PECQUOT's avatar PECQUOT

[enh] Move comment editor to quadrige3-ui-swing-common

ready to release 3.7.3
Signed-off-by: PECQUOT's avatarlp1ee9d <ludovic.pecquot@e-is.pro>
parent cd46b0af
......@@ -171,7 +171,7 @@
<maven.compiler.debug>true</maven.compiler.debug>
<!-- Quadrige3 Core version -->
<quadrige3-core.version>3.5.3</quadrige3-core.version>
<quadrige3-core.version>3.5.4</quadrige3-core.version>
<!-- Last ReefDb launcher version -->
<launcherVersion>3.0.3</launcherVersion>
......@@ -208,6 +208,8 @@
<!-- gitflow release plugin -->
<gitflowPluginVersion>1.12.0-EIS</gitflowPluginVersion>
<!-- to deploy with scpexe for maven 3 -->
<wagonSshVersion>3.3.3</wagonSshVersion>
<!--license-maven-plugin config -->
<maven.license.file>${project.basedir}/LICENSE.txt</maven.license.file>
......
......@@ -25,10 +25,10 @@ package fr.ifremer.reefdb.ui.swing.content.observation.shared;
import com.google.common.collect.Lists;
import fr.ifremer.quadrige3.core.dao.technical.factorization.pmfm.AllowedQualitativeValuesMap;
import fr.ifremer.reefdb.dto.CommentAware;
import fr.ifremer.quadrige3.ui.core.dto.CommentAware;
import fr.ifremer.quadrige3.ui.core.dto.QuadrigeBean;
import fr.ifremer.reefdb.dto.ErrorAware;
import fr.ifremer.reefdb.dto.ErrorDTO;
import fr.ifremer.quadrige3.ui.core.dto.QuadrigeBean;
import fr.ifremer.reefdb.dto.data.measurement.MeasurementAware;
import fr.ifremer.reefdb.dto.data.measurement.MeasurementDTO;
import fr.ifremer.reefdb.dto.referential.DepartmentDTO;
......
......@@ -24,7 +24,6 @@ package fr.ifremer.reefdb.ui.swing.util.table;
*/
import fr.ifremer.quadrige3.ui.swing.table.AbstractTableModel;
import fr.ifremer.reefdb.dto.CommentAware;
import org.jdesktop.swingx.table.TableColumnModelExt;
/**
......@@ -46,20 +45,4 @@ public abstract class AbstractReefDbTableModel<R extends AbstractReefDbRowUIMode
super(columnModel, createNewRow, createEmptyRowIsEmpty);
}
/**
* {@inheritDoc}
*/
@Override
public boolean isCellEditable(int rowIndex, int columnIndex, org.nuiton.jaxx.application.swing.table.ColumnIdentifier<R> propertyName) {
R row = getEntry(rowIndex);
// "comment" property on a CommentAware row is editable even if the row is not editable
if ((row instanceof CommentAware) && "comment".equals(propertyName.getPropertyName())) {
return true;
}
return super.isCellEditable(rowIndex, columnIndex, propertyName);
}
}
......@@ -39,8 +39,6 @@ import fr.ifremer.reefdb.dto.referential.pmfm.QualitativeValueDTO;
import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
import fr.ifremer.reefdb.ui.swing.util.ReefDbUIs;
import fr.ifremer.reefdb.ui.swing.util.table.comment.CommentCellEditor;
import fr.ifremer.reefdb.ui.swing.util.table.comment.CommentCellRenderer;
import fr.ifremer.reefdb.ui.swing.util.table.export.ExportToCSVAction;
import jaxx.runtime.SwingUtil;
import org.apache.commons.collections4.CollectionUtils;
......@@ -562,24 +560,6 @@ public abstract class AbstractReefDbTableUIHandler<R extends AbstractReefDbRowUI
return null;
}
protected TableColumnExt addCommentColumn(ReefDbColumnIdentifier<R> identifier) {
return addCommentColumn(identifier, true);
}
protected TableColumnExt addCommentColumn(ReefDbColumnIdentifier<R> identifier, boolean editable) {
return addCommentColumn(identifier, null, editable);
}
protected TableColumnExt addCommentColumn(ReefDbColumnIdentifier<R> identifier, String propertyName, boolean editable) {
TableColumnExt column = addColumn(
CommentCellEditor.newEditor(getUI(), propertyName, editable),
CommentCellRenderer.newRenderer(),
identifier);
column.setSortable(false);
fixColumnWidth(column, 112); // is a correct width for fr_FR
return column;
}
private class BoldFontHighlighter extends AbstractHighlighter {
BoldFontHighlighter(HighlightPredicate predicate) {
......
package fr.ifremer.reefdb.ui.swing.util.table.comment;
/*
* #%L
* Reef DB :: UI
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2014 - 2015 Ifremer
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import fr.ifremer.reefdb.dto.CommentAware;
import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
import jaxx.runtime.SwingUtil;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.HierarchyBoundsAdapter;
import java.awt.event.HierarchyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import static org.nuiton.i18n.I18n.t;
/**
* A toggleButton to show (or hide) comment editor.
*/
public class ButtonComment extends JToggleButton {
private static final long serialVersionUID = 1L;
protected final CommentEditorUI popup;
protected boolean popupMoving;
/**
* <p>Constructor for ButtonComment.</p>
*
* @param context a {@link fr.ifremer.reefdb.ui.swing.ReefDbUIContext} object.
* @param model a {@link fr.ifremer.reefdb.dto.CommentAware} object.
* @param property a {@link java.lang.String} object.
*/
public ButtonComment(ReefDbUIContext context, CommentAware model, String property) {
setIcon(SwingUtil.createActionIcon("edit-no-comment"));
setToolTipText(t("reefdb.commentEditor.action.tip"));
popup = new CommentEditorUI(context);
popup.addWindowListener(new WindowAdapter() {
@Override
public void windowOpened(WindowEvent e) {
setSelected(true);
}
@Override
public void windowClosing(WindowEvent e) {
setSelected(false);
}
@Override
public void windowClosed(WindowEvent e) {
setSelected(false);
}
});
addChangeListener(e -> {
if (isSelected()) {
popup.openEditor(ButtonComment.this);
} else {
popup.closeEditor();
}
});
addHierarchyBoundsListener(new HierarchyBoundsAdapter() {
@Override
public void ancestorMoved(HierarchyEvent e) {
if (popup.isShowing()) {
// place dialog just under the button
Point point = new Point(getLocationOnScreen());
point.translate(-popup.getWidth() + getWidth(), getHeight());
popupMoving = true;
try {
popup.setLocation(point);
} finally {
popupMoving = false;
}
}
}
});
// set the property, if null, 'comment' will be used (default behaviour of a CommentAware bean)
popup.setProperty(property);
setBean(model);
}
/**
* <p>init.</p>
*
* @param model a {@link fr.ifremer.reefdb.dto.CommentAware} object.
* @param editable a boolean.
*/
public void init(CommentAware model, boolean editable) {
setBean(model);
popup.getHandler().init(editable);
}
/**
* <p>onCloseUI.</p>
*/
public void onCloseUI() {
setSelected(false);
}
/**
* <p>getBean.</p>
*
* @return a {@link fr.ifremer.reefdb.dto.CommentAware} object.
*/
public CommentAware getBean() {
return popup.getBean();
}
/**
* <p>setBean.</p>
*
* @param model a {@link fr.ifremer.reefdb.dto.CommentAware} object.
*/
protected void setBean(CommentAware model) {
popup.setBean(model);
}
/**
* <p>getProperty.</p>
*
* @return a {@link java.lang.String} object.
*/
public String getProperty() {
return popup.getProperty();
}
}
package fr.ifremer.reefdb.ui.swing.util.table.comment;
/*
* #%L
* Reef DB :: UI
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2014 - 2015 Ifremer
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import fr.ifremer.quadrige3.core.dao.technical.Assert;
import fr.ifremer.reefdb.dto.CommentAware;
import fr.ifremer.reefdb.ui.swing.ReefDbUIContext;
import fr.ifremer.reefdb.ui.swing.util.ReefDbUI;
import fr.ifremer.reefdb.ui.swing.util.table.AbstractReefDbRowUIModel;
import jaxx.runtime.SwingUtil;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.nuiton.jaxx.application.bean.JavaBeanObjectUtil;
import org.nuiton.jaxx.application.swing.table.AbstractApplicationTableModel;
import javax.swing.AbstractCellEditor;
import javax.swing.JTable;
import javax.swing.border.LineBorder;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.TableCellEditor;
import java.awt.Color;
import java.awt.Component;
import java.util.EventObject;
/**
* To edit a comment in a table cell using a nice dialog for this.
*/
public class CommentCellEditor extends AbstractCellEditor implements TableCellEditor {
private static final long serialVersionUID = 1L;
/**
* Logger.
*/
private static final Log LOG = LogFactory.getLog(CommentCellEditor.class);
/**
* <p>newEditor.</p>
*
* @param ui a {@link fr.ifremer.reefdb.ui.swing.util.ReefDbUI} object.
* @param property a {@link java.lang.String} object.
* @return a {@link javax.swing.table.TableCellEditor} object.
*/
public static TableCellEditor newEditor(ReefDbUI<?, ?> ui, String property, boolean editable) {
return new CommentCellEditor((ReefDbUIContext) ui.getHandler().getContext(), property, editable);
}
/**
* <p>newEditor.</p>
*
* @param ui a {@link fr.ifremer.reefdb.ui.swing.util.ReefDbUI} object.
* @return a {@link javax.swing.table.TableCellEditor} object.
*/
public static TableCellEditor newEditor(ReefDbUI<?, ?> ui) {
return new CommentCellEditor((ReefDbUIContext) ui.getHandler().getContext());
}
protected JTable table;
protected AbstractApplicationTableModel<AbstractReefDbRowUIModel<?, ?>> tableModel;
protected Integer rowIndex;
protected Integer columnIndex;
protected final ButtonComment editorButton;
private final boolean editable;
/**
* <p>Constructor for CommentCellEditor.</p>
*
* @param context a {@link fr.ifremer.reefdb.ui.swing.ReefDbUIContext} object.
*/
public CommentCellEditor(ReefDbUIContext context) {
this(context, null, true);
}
/**
* <p>Constructor for CommentCellEditor.</p>
* @param context a {@link ReefDbUIContext} object.
* @param property a {@link String} object.
* @param editable
*/
public CommentCellEditor(ReefDbUIContext context, String property, boolean editable) {
this.editorButton = new ButtonComment(context, null, property);
this.editorButton.setBorder(new LineBorder(Color.BLACK));
addCellEditorListener(new CellEditorListener() {
@Override
public void editingStopped(ChangeEvent e) {
editorButton.setSelected(false);
}
@Override
public void editingCanceled(ChangeEvent e) {
editorButton.setSelected(false);
}
});
this.editable = editable;
}
/** {@inheritDoc} */
@Override
@SuppressWarnings("unchecked")
public Component getTableCellEditorComponent(JTable table,
Object value,
boolean isSelected,
int row,
int column) {
this.table = table;
this.tableModel = (AbstractApplicationTableModel<AbstractReefDbRowUIModel<?, ?>>) table.getModel();
rowIndex = row;
columnIndex = column;
String comment = (String) value;
AbstractReefDbRowUIModel rowModel = tableModel.getEntry(table.convertRowIndexToModel(row));
boolean isEditable = editable && rowModel.isEditable();
CommentAware commentAwareModel = null;
if (rowModel instanceof CommentAware) {
commentAwareModel = (CommentAware) rowModel;
}
editorButton.init(commentAwareModel, isEditable);
if (StringUtils.isEmpty(StringUtils.trim(comment))) {
this.editorButton.setIcon(SwingUtil.createActionIcon("edit-no-comment"));
} else {
this.editorButton.setIcon(SwingUtil.createActionIcon("edit-comment"));
}
return editorButton;
}
/** {@inheritDoc} */
@Override
public boolean shouldSelectCell(EventObject anEvent) {
return true;
}
/** {@inheritDoc} */
@Override
public Object getCellEditorValue() {
CommentAware model = editorButton.getBean();
Assert.notNull(model, "No model found in editor.");
Object result = editorButton.getProperty() == null ? model.getComment() : JavaBeanObjectUtil.getProperty(model, editorButton.getProperty());
if (LOG.isDebugEnabled()) {
LOG.debug("editor value: " + result);
}
return result;
}
/** {@inheritDoc} */
@Override
public boolean stopCellEditing() {
boolean b = super.stopCellEditing();
if (b) {
editorButton.setBean(null);
}
editorButton.setSelected(false);
return b;
}
/** {@inheritDoc} */
@Override
public void cancelCellEditing() {
editorButton.setBean(null);
editorButton.setSelected(false);
super.cancelCellEditing();
}
}
package fr.ifremer.reefdb.ui.swing.util.table.comment;
/*
* #%L
* Reef DB :: UI
* $Id:$
* $HeadURL:$
* %%
* Copyright (C) 2014 - 2015 Ifremer
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* #L%
*/
import jaxx.runtime.SwingUtil;
import org.apache.commons.lang3.StringUtils;
import javax.swing.*;
import javax.swing.border.LineBorder;
import javax.swing.table.DefaultTableCellRenderer;
import java.awt.*;
import static org.nuiton.i18n.I18n.n;
import static org.nuiton.i18n.I18n.t;
/**
* To render a comment in a table cell.
*/
public class CommentCellRenderer extends DefaultTableCellRenderer {
/** Constant <code>TEXT_PATTERN="<html><body>%s</body></html>"</code> */
public static final String TEXT_PATTERN = "<html><body>%s</body></html>";
private static final long serialVersionUID = 1L;
private final String noneText;
protected Font defaulfFont;
protected Font selectedFont;
/**
* <p>newRenderer.</p>
*
* @return a {@link fr.ifremer.reefdb.ui.swing.util.table.comment.CommentCellRenderer} object.
*/
public static CommentCellRenderer newRenderer() {
return new CommentCellRenderer();
}
/**
* <p>Constructor for CommentCellRenderer.</p>
*/
protected CommentCellRenderer() {
setHorizontalAlignment(CENTER);
setIcon(SwingUtil.createActionIcon("edit-no-comment"));
this.noneText = n("reefdb.commentEditor.none.tip");
}
/** {@inheritDoc} */
@Override
protected void setValue(Object value) {
// do nothing
}
/** {@inheritDoc} */
@Override
public JComponent getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
String comment = (String) value;
String toolTipTextValue;
if (StringUtils.isBlank(comment)) {
// use HTML to show the tooltip in italic
toolTipTextValue = "<i>" + t(noneText) + "</i>";
this.setIcon(SwingUtil.createActionIcon("edit-no-comment"));
} else {
// use html to display the tooltip on several lines
toolTipTextValue = String.valueOf(value).replace("\n", "<br/>");
this.setIcon(SwingUtil.createActionIcon("edit-comment"));
}
toolTipTextValue = String.format(TEXT_PATTERN, toolTipTextValue);
setToolTipText(toolTipTextValue);
setBackground(null);
setBorder(hasFocus ? new LineBorder(Color.BLACK) : null);
if (defaulfFont == null) {
defaulfFont = UIManager.getFont("Table.font");
selectedFont = defaulfFont.deriveFont(Font.BOLD);
}
if (isSelected) {
setFont(selectedFont);
} else {
setFont(defaulfFont);
}
return this;
}
}
<!--
#%L
Reef DB :: UI
$Id:$
$HeadURL:$
%%
Copyright (C) 2014 - 2015 Ifremer
%%
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
#L%
-->
<JDialog id='commentDialog' layout='{new BorderLayout()}'>
<import>
fr.ifremer.reefdb.dto.CommentAware
fr.ifremer.reefdb.ui.swing.ReefDbUIContext
fr.ifremer.quadrige3.ui.swing.ApplicationUI
fr.ifremer.quadrige3.ui.swing.ApplicationUIUtil
org.jdesktop.swingx.JXTitledPanel
javax.swing.JComponent
</import>
<script><![CDATA[
public CommentEditorUI(ReefDbUIContext context) {
super(context.getMainUI());
ApplicationUIUtil.setApplicationContext(this, context);
}
public void openEditor(JComponent component) {
handler.openEditor(component);
}
public void closeEditor() {
handler.closeEditor();
}
]]></script>
<!-- bean property -->
<CommentAware id='bean' javaBean='null'/>
<String id='property' javaBean='null'/>
<JXTitledPanel id='commentEditorTopPanel' constraints='BorderLayout.CENTER'>
<JScrollPane id="textScrollPane">
<JTextArea id='textContent'
onKeyReleased='handler.setText(((JTextArea)event.getSource()).getText())'/>
</JScrollPane>
</JXTitledPanel>
</JDialog>