* sync with branches/adempiere341 revision 6510
This commit is contained in:
parent
1878089641
commit
27da57bddf
|
@ -58,11 +58,7 @@ public class WEditorPopupMenu extends Menupopup implements EventListener
|
|||
|
||||
public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences)
|
||||
{
|
||||
super();
|
||||
this.zoomEnabled = zoom;
|
||||
this.requeryEnabled = requery;
|
||||
this.preferencesEnabled = preferences;
|
||||
init();
|
||||
this(zoom, requery, preferences, false);
|
||||
}
|
||||
|
||||
public WEditorPopupMenu(boolean zoom, boolean requery, boolean preferences, boolean newRecord)
|
||||
|
|
|
@ -18,17 +18,21 @@
|
|||
package org.adempiere.webui.editor;
|
||||
|
||||
import org.adempiere.webui.ValuePreference;
|
||||
import org.adempiere.webui.apps.form.WCreateFromStatement;
|
||||
import org.adempiere.webui.component.Textbox;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.event.ContextMenuEvent;
|
||||
import org.adempiere.webui.event.ContextMenuListener;
|
||||
import org.adempiere.webui.event.ValueChangeEvent;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.window.WTextEditorDialog;
|
||||
import org.compiere.model.GridField;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.util.DisplayType;
|
||||
import org.compiere.util.Env;
|
||||
import org.compiere.util.Msg;
|
||||
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.Menuitem;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -38,6 +42,8 @@ import org.zkoss.zk.ui.event.Events;
|
|||
*/
|
||||
public class WStringEditor extends WEditor implements ContextMenuListener
|
||||
{
|
||||
private static final String EDITOR_EVENT = "EDITOR";
|
||||
|
||||
private static final String[] LISTENER_EVENTS = {Events.ON_CHANGE};
|
||||
|
||||
private String oldText;
|
||||
|
@ -124,6 +130,12 @@ public class WStringEditor extends WEditor implements ContextMenuListener
|
|||
getComponent().setObscureType(obscureType);
|
||||
|
||||
popupMenu = new WEditorPopupMenu(false, false, true);
|
||||
Menuitem editor = new Menuitem(Msg.getMsg(Env.getCtx(), "Editor"), "images/Editor16.gif");
|
||||
editor.setAttribute("EVENT", EDITOR_EVENT);
|
||||
editor.addEventListener(Events.ON_CLICK, popupMenu);
|
||||
popupMenu.appendChild(editor);
|
||||
|
||||
getComponent().setContext(popupMenu.getId());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,5 +207,19 @@ public class WStringEditor extends WEditor implements ContextMenuListener
|
|||
ValuePreference.start (this.getGridField(), getValue());
|
||||
return;
|
||||
}
|
||||
else if (EDITOR_EVENT.equals(evt.getContextEvent()))
|
||||
{
|
||||
WTextEditorDialog dialog = new WTextEditorDialog(this.getColumnName(), getDisplay(),
|
||||
isReadWrite(), gridField.getFieldLength());
|
||||
dialog.setAttribute(Window.MODE_KEY, Window.MODE_MODAL);
|
||||
SessionManager.getAppDesktop().showWindow(dialog);
|
||||
if (!dialog.isCancelled()) {
|
||||
getComponent().setText(dialog.getText());
|
||||
String newText = getComponent().getValue();
|
||||
ValueChangeEvent changeEvent = new ValueChangeEvent(this, this.getColumnName(), oldText, newText);
|
||||
super.fireValueChange(changeEvent);
|
||||
oldText = newText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,203 @@
|
|||
/******************************************************************************
|
||||
* Copyright (C) 2008 Low Heng Sin *
|
||||
* This program is free software; you can redistribute it and/or modify it *
|
||||
* under the terms version 2 of the GNU General Public License as published *
|
||||
* by the Free Software Foundation. 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 General Public License along *
|
||||
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||
*****************************************************************************/
|
||||
package org.adempiere.webui.window;
|
||||
|
||||
import org.adempiere.webui.component.ConfirmPanel;
|
||||
import org.adempiere.webui.component.Label;
|
||||
import org.adempiere.webui.component.Tab;
|
||||
import org.adempiere.webui.component.Tabbox;
|
||||
import org.adempiere.webui.component.Tabpanel;
|
||||
import org.adempiere.webui.component.Tabpanels;
|
||||
import org.adempiere.webui.component.Tabs;
|
||||
import org.adempiere.webui.component.Textbox;
|
||||
import org.adempiere.webui.component.VerticalBox;
|
||||
import org.adempiere.webui.component.Window;
|
||||
import org.zkforge.fckez.FCKeditor;
|
||||
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;
|
||||
import org.zkoss.zul.Separator;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Low Heng Sin
|
||||
*
|
||||
*/
|
||||
public class WTextEditorDialog extends Window implements EventListener{
|
||||
|
||||
private boolean editable;
|
||||
private int maxSize;
|
||||
private String text;
|
||||
private boolean cancelled;
|
||||
private Tabbox tabbox;
|
||||
private Textbox textBox;
|
||||
private FCKeditor editor;
|
||||
private Label status;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param title
|
||||
* @param text
|
||||
* @param editable
|
||||
* @param maxSize
|
||||
*/
|
||||
public WTextEditorDialog(String title, String text, boolean editable, int maxSize) {
|
||||
super();
|
||||
setTitle(title);
|
||||
this.editable = editable;
|
||||
this.maxSize = maxSize;
|
||||
this.text = text;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
private void init() {
|
||||
setBorder("normal");
|
||||
|
||||
VerticalBox vbox = new VerticalBox();
|
||||
appendChild(vbox);
|
||||
|
||||
tabbox = new Tabbox();
|
||||
vbox.appendChild(tabbox);
|
||||
Tabs tabs = new Tabs();
|
||||
tabbox.appendChild(tabs);
|
||||
Tabpanels tabPanels = new Tabpanels();
|
||||
tabbox.appendChild(tabPanels);
|
||||
|
||||
Tab tab = new Tab("Text");
|
||||
tabs.appendChild(tab);
|
||||
|
||||
Tabpanel tabPanel = new Tabpanel();
|
||||
tabPanels.appendChild(tabPanel);
|
||||
textBox = new Textbox(text);
|
||||
textBox.setCols(80);
|
||||
textBox.setRows(30);
|
||||
textBox.setEnabled(editable);
|
||||
textBox.setWidth("700px");
|
||||
textBox.setHeight("500px");
|
||||
tabPanel.appendChild(textBox);
|
||||
|
||||
tab = new Tab("HTML");
|
||||
tabs.appendChild(tab);
|
||||
|
||||
tabPanel = new Tabpanel();
|
||||
tabPanels.appendChild(tabPanel);
|
||||
if (editable) {
|
||||
editor = new FCKeditor();
|
||||
tabPanel.appendChild(editor);
|
||||
editor.setWidth("700px");
|
||||
editor.setHeight("500px");
|
||||
editor.setValue(text);
|
||||
} else {
|
||||
Div div = new Div();
|
||||
div.setHeight("500px");
|
||||
div.setWidth("700px");
|
||||
div.setStyle("overflow: auto; border: 1px solid");
|
||||
tabPanel.appendChild(div);
|
||||
Html html = new Html();
|
||||
div.appendChild(html);
|
||||
html.setContent(text);
|
||||
}
|
||||
|
||||
vbox.appendChild(new Separator());
|
||||
|
||||
ConfirmPanel confirmPanel = new ConfirmPanel(true);
|
||||
vbox.appendChild(confirmPanel);
|
||||
confirmPanel.addButton(confirmPanel.createButton(ConfirmPanel.A_RESET));
|
||||
confirmPanel.addActionListener(this);
|
||||
|
||||
if (maxSize > 0) {
|
||||
status = new Label();
|
||||
appendChild(status);
|
||||
updateStatus(text.length());
|
||||
|
||||
status.setStyle("margin-top:10px;");
|
||||
textBox.addEventListener(Events.ON_CHANGE, this);
|
||||
editor.addEventListener(Events.ON_CHANGE, this);
|
||||
}
|
||||
|
||||
tabbox.addEventListener(Events.ON_SELECT, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param event
|
||||
*/
|
||||
public void onEvent(Event event) throws Exception {
|
||||
if (event.getTarget().getId().equals(ConfirmPanel.A_CANCEL)) {
|
||||
cancelled = true;
|
||||
detach();
|
||||
} else if (event.getTarget().getId().equals(ConfirmPanel.A_OK)) {
|
||||
if (editable) {
|
||||
if (tabbox.getSelectedIndex() == 0)
|
||||
text = textBox.getText();
|
||||
else
|
||||
text = editor.getValue();
|
||||
}
|
||||
detach();
|
||||
} else if (event.getTarget().getId().equals(ConfirmPanel.A_RESET)) {
|
||||
textBox.setText(text);
|
||||
editor.setValue(text);
|
||||
} else if (event.getName().equals(Events.ON_SELECT)) {
|
||||
if (editable) {
|
||||
if (tabbox.getSelectedIndex() == 0) {
|
||||
textBox.setText(editor.getValue());
|
||||
updateStatus(textBox.getText().length());
|
||||
} else {
|
||||
editor.setValue(textBox.getText());
|
||||
updateStatus(editor.getValue().length());
|
||||
}
|
||||
}
|
||||
} else if (event.getName().equals(Events.ON_CHANGE)) {
|
||||
if (event.getTarget() == textBox) {
|
||||
updateStatus(textBox.getText().length());
|
||||
} else if (event.getTarget() == editor) {
|
||||
updateStatus(editor.getValue().length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStatus(int newLength) {
|
||||
if (status != null && maxSize > 0) {
|
||||
StringBuffer msg = new StringBuffer();
|
||||
msg.append(newLength);
|
||||
if (newLength == maxSize)
|
||||
msg.append(" = ");
|
||||
else if (newLength < maxSize)
|
||||
msg.append(" < ");
|
||||
else
|
||||
msg.append(" > ");
|
||||
msg.append(maxSize);
|
||||
|
||||
status.setValue(msg.toString());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return text
|
||||
*/
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue