From fed84e92e1e9abc9aa4407edfb8b846d0c66623c Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Tue, 24 Jul 2018 18:31:00 +0200 Subject: [PATCH] IDEMPIERE-2310 Improve description field with inline Html editor and html rendering --- .../org/adempiere/webui/editor/WEditor.java | 4 +- .../adempiere/webui/editor/WHtmlEditor.java | 73 +++++++++++-------- .../webui/window/WTextEditorDialog.java | 3 +- 3 files changed, 46 insertions(+), 34 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java index 28118f43c1..a725ebbc15 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java @@ -756,14 +756,14 @@ public abstract class WEditor implements EventListener, PropertyChangeLis * @return boolean */ protected boolean isShowPreference() { - return MRole.getDefault().isShowPreference() && gridField != null && !gridField.isEncrypted() && !gridField.isEncryptedColumn(); + return MRole.getDefault().isShowPreference() && gridField != null && !gridField.isEncrypted() && !gridField.isEncryptedColumn() && !gridField.isVirtualColumn(); } /** * @param popupMenu */ protected void addChangeLogMenu(WEditorPopupMenu popupMenu) { - if (popupMenu != null && gridField != null && gridField.getGridTab() != null) + if (popupMenu != null && gridField != null && gridField.getGridTab() != null && !gridField.isVirtualColumn()) { WFieldRecordInfo.addMenu(popupMenu); } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WHtmlEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WHtmlEditor.java index 2647d3bf50..4dea40686c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WHtmlEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WHtmlEditor.java @@ -35,6 +35,7 @@ import org.compiere.util.CLogger; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; +import org.zkoss.zk.ui.event.Events; import org.zkoss.zul.Div; import org.zkoss.zul.Html; @@ -82,9 +83,13 @@ public class WHtmlEditor extends WEditor implements ContextMenuListener if (gridField != null) { Div div = (Div) getComponent(); - div.setHeight("100px"); + if (gridField.getNumLines() > 1) { + int height = 24 * gridField.getNumLines(); + div.setHeight(height + "px"); + } div.setWidth("100%"); LayoutUtils.addSclass("html-field", div); + div.addEventListener(Events.ON_DOUBLE_CLICK, this); box = new Html(); box.setParent(div); @@ -170,35 +175,7 @@ public class WHtmlEditor extends WEditor implements ContextMenuListener } else if (WEditorPopupMenu.EDITOR_EVENT.equals(evt.getContextEvent())) { - adwindowContent = findADWindowContent(); - final WTextEditorDialog dialog = new WTextEditorDialog(gridField.getVO().Header, getDisplay(), - isReadWrite(), gridField.getFieldLength(), true); - dialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { - @Override - public void onEvent(Event event) throws Exception { - if (adwindowContent != null) { - adwindowContent.hideBusyMask(); - } - if (!dialog.isCancelled()) { - box.setContent(dialog.getText()); - String newText = box.getContent(); - ValueChangeEvent changeEvent = new ValueChangeEvent(WHtmlEditor.this, WHtmlEditor.this.getColumnName(), oldValue, newText); - WHtmlEditor.super.fireValueChange(changeEvent); - oldValue = newText; - } - } - }); - if (adwindowContent != null) - { - adwindowContent.getComponent().getParent().appendChild(dialog); - adwindowContent.showBusyMask(dialog); - LayoutUtils.openOverlappedWindow(adwindowContent.getComponent().getParent(), dialog, "middle_center"); - } - else - { - SessionManager.getAppDesktop().showWindow(dialog); - } - dialog.focus(); + editorEvent(); } else if (WEditorPopupMenu.CHANGE_LOG_EVENT.equals(evt.getContextEvent())) { @@ -206,6 +183,38 @@ public class WHtmlEditor extends WEditor implements ContextMenuListener } } + private void editorEvent() { + adwindowContent = findADWindowContent(); + final WTextEditorDialog dialog = new WTextEditorDialog(gridField.getVO().Header, getDisplay(), + isReadWrite(), gridField.getFieldLength(), true); + dialog.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { + @Override + public void onEvent(Event event) throws Exception { + if (adwindowContent != null) { + adwindowContent.hideBusyMask(); + } + if (!dialog.isCancelled()) { + box.setContent(dialog.getText()); + String newText = box.getContent(); + ValueChangeEvent changeEvent = new ValueChangeEvent(WHtmlEditor.this, WHtmlEditor.this.getColumnName(), oldValue, newText); + WHtmlEditor.super.fireValueChange(changeEvent); + oldValue = newText; + } + } + }); + if (adwindowContent != null) + { + adwindowContent.getComponent().getParent().appendChild(dialog); + adwindowContent.showBusyMask(dialog); + LayoutUtils.openOverlappedWindow(adwindowContent.getComponent().getParent(), dialog, "middle_center"); + } + else + { + SessionManager.getAppDesktop().showWindow(dialog); + } + dialog.focus(); + } + private AbstractADWindowContent findADWindowContent() { Component parent = getComponent().getParent(); while(parent != null) { @@ -220,7 +229,9 @@ public class WHtmlEditor extends WEditor implements ContextMenuListener @Override public void onEvent(Event event) throws Exception { - + if (Events.ON_DOUBLE_CLICK.equals(event.getName()) && readwrite) { + editorEvent(); + } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WTextEditorDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WTextEditorDialog.java index f8f4e7ef7c..3ee0513e6c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WTextEditorDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/WTextEditorDialog.java @@ -211,7 +211,8 @@ public class WTextEditorDialog extends Window implements EventListener{ } } else if (event.getTarget().getId().equals(ConfirmPanel.A_RESET)) { textBox.setText(text); - editor.setValue(text); + if (editor != null) + editor.setValue(text); } else if (event.getName().equals(Events.ON_SELECT)) { if (editable) { if (tabbox.getSelectedIndex() == 0) {