/*
 * Copyright (c) 2008-2013 Haulmont. All rights reserved.
 * Use is subject to license terms, see http://www.cuba-platform.com/license for details.
 */

package com.haulmont.cuba.web.toolkit.ui;

import com.haulmont.cuba.web.toolkit.ui.client.resizabletextarea.CubaResizableTextAreaState;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * @author artamonov
 * @version $Id$
 */
public class CubaResizableTextArea extends CubaTextArea {

    protected boolean resizable = false;
    protected List<ResizeListener> listeners = new ArrayList<>();

    public static interface ResizeListener {
        public void onResize(String oldWidth, String oldHeight, String width, String height);
    }

    @Override
    protected CubaResizableTextAreaState getState() {
        return (CubaResizableTextAreaState) super.getState();
    }

    @Override
    protected CubaResizableTextAreaState getState(boolean markAsDirty) {
        return (CubaResizableTextAreaState) super.getState(markAsDirty);
    }

    public boolean isResizable() {
        return getState(false).resizable;
    }

    public void setResizable(boolean resizable) {
        getState().resizable = resizable;
    }


    @Override
    public void beforeClientResponse(boolean initial) {
        super.beforeClientResponse(initial);

        if (getState(false).resizable &&
                getState(false).rows > 0 &&
                getState(false).columns > 0) {
            LogFactory.getLog(getClass()).warn("TextArea with fixed rows or cols can not be resizable");
            getState().resizable = false;
        }
    }

    public void addResizeListener(ResizeListener resizeListener) {
        if (!listeners.contains(resizeListener)) {
            listeners.add(resizeListener);
        }
    }

    public void removeResizeListener(ResizeListener resizeListener) {
        listeners.remove(resizeListener);
    }
}
@@ -382,16 +382,38 @@
 il.List;
+%0Aimport java.util.Map;
 %0A%0A/**%0A *
@@ -1252,16 +1252,565 @@
 %0A    %7D%0A%0A
+    @Override%0A    public void changeVariables(Object source, Map%3CString, Object%3E variables) %7B%0A        super.changeVariables(source, variables);%0A%0A        if (variables.containsKey(%22width%22) && variables.containsKey(%22height%22)) %7B%0A            this.setWidth((String) variables.get(%22width%22));%0A            this.setHeight((String) variables.get(%22height%22));%0A%0A            for (ResizeListener listener : listeners) %7B%0A                listener.onResize(null, null, (String) variables.get(%22width%22), (String) variables.get(%22height%22));%0A            %7D%0A        %7D%0A    %7D%0A
 %0A    @Ov

Update size of ResizableTextArea on server after change on client #PL-2808