mirror of
https://gitee.com/jmix/cuba.git
synced 2024-12-04 20:28:00 +08:00
Save width/height of resizable text area as user settings #PL-5887
This commit is contained in:
parent
8c47e4e7e3
commit
8b87185f58
@ -7,6 +7,7 @@ package com.haulmont.cuba.desktop.gui.components;
|
||||
|
||||
import com.haulmont.cuba.gui.components.ResizableTextArea;
|
||||
import com.haulmont.cuba.gui.components.ResizeListener;
|
||||
import org.dom4j.Element;
|
||||
|
||||
/**
|
||||
* @author subbotin
|
||||
@ -33,4 +34,24 @@ public class DesktopResizableTextArea extends DesktopTextArea implements Resizab
|
||||
public void removeResizeListener(ResizeListener resizeListener) {
|
||||
//Do nothing, because desktop text area is not resizable
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySettings(Element element) {
|
||||
//Do nothing, because desktop text area is not resizable
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveSettings(Element element) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSettingsEnabled() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSettingsEnabled(boolean settingsEnabled) {
|
||||
//Do nothing, because desktop text area is not resizable
|
||||
}
|
||||
}
|
@ -9,7 +9,7 @@ package com.haulmont.cuba.gui.components;
|
||||
* @author subbotin
|
||||
* @version $Id$
|
||||
*/
|
||||
public interface ResizableTextArea extends TextArea {
|
||||
public interface ResizableTextArea extends TextArea, Component.HasSettings {
|
||||
|
||||
String NAME = TextArea.NAME;
|
||||
|
||||
@ -17,6 +17,6 @@ public interface ResizableTextArea extends TextArea {
|
||||
void setResizable(boolean resizable);
|
||||
boolean isResizable();
|
||||
|
||||
public void addResizeListener(ResizeListener resizeListener);
|
||||
public void removeResizeListener(ResizeListener resizeListener);
|
||||
void addResizeListener(ResizeListener resizeListener);
|
||||
void removeResizeListener(ResizeListener resizeListener);
|
||||
}
|
@ -13,6 +13,8 @@ import com.vaadin.data.Property;
|
||||
import com.vaadin.server.ErrorMessage;
|
||||
import com.vaadin.server.UserError;
|
||||
import com.vaadin.ui.Component;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.dom4j.Element;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -30,6 +32,7 @@ public class WebResizableTextArea
|
||||
protected List<ResizeListener> resizeListeners = new ArrayList<>();
|
||||
|
||||
protected CubaResizableTextAreaWrapper wrapper;
|
||||
protected boolean settingsEnabled = true;
|
||||
|
||||
public WebResizableTextArea() {
|
||||
wrapper = new CubaResizableTextAreaWrapper(component);
|
||||
@ -145,4 +148,40 @@ public class WebResizableTextArea
|
||||
public void setCursorPosition(int position) {
|
||||
component.setCursorPosition(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applySettings(Element element) {
|
||||
if (isSettingsEnabled() && isResizable()) {
|
||||
String width = element.attributeValue("width");
|
||||
String height = element.attributeValue("height");
|
||||
if (StringUtils.isNotEmpty(width) && StringUtils.isNotEmpty(height)) {
|
||||
setWidth(width);
|
||||
setHeight(height);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean saveSettings(Element element) {
|
||||
if (!isSettingsEnabled() || !isResizable()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
String width = String.valueOf(getWidth()) + wrapper.getWidthUnits().toString();
|
||||
String height = String.valueOf(getHeight()) + wrapper.getHeightUnits().toString();
|
||||
element.addAttribute("width", width);
|
||||
element.addAttribute("height", height);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSettingsEnabled() {
|
||||
return settingsEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSettingsEnabled(boolean settingsEnabled) {
|
||||
this.settingsEnabled = settingsEnabled;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user