Example usage for com.vaadin.client LayoutManager get

List of usage examples for com.vaadin.client LayoutManager get

Introduction

In this page you can find the example usage for com.vaadin.client LayoutManager get.

Prototype

public static LayoutManager get(ApplicationConnection connection) 

Source Link

Document

Gets the layout manager associated with the given ApplicationConnection .

Usage

From source file:com.ejt.vaadin.sizereporter.shared.SizeReporterConnector.java

License:Apache License

@Override
protected void extend(ServerConnector target) {
    if (target instanceof ComponentConnector) {
        widget = ((ComponentConnector) target).getWidget();

        if (widget.getOffsetWidth() > 0 && widget.getOffsetHeight() > 0) {
            reportSize(); // for widgets already in the layout
        }/*from  w  w w  .  jav a2 s  .  co m*/

        // ElementResizeListener does not work for widgets that are 'loaded' (e.g. Image...)
        if (widget instanceof HasLoadHandlers) {
            ((HasLoadHandlers) widget).addLoadHandler(new LoadHandler() {
                @Override
                public void onLoad(LoadEvent event) {
                    reportSize();
                }
            });
        } else {
            LayoutManager.get(getConnection()).addElementResizeListener(widget.getElement(),
                    new ElementResizeListener() {
                        @Override
                        public void onElementResize(ElementResizeEvent event) {
                            reportSize();
                        }
                    });
        }
    }
}

From source file:org.dussan.vaadin.dcharts.client.connector.DChartsConnector.java

License:Apache License

@Override
protected void init() {
    super.init();

    registerRpc(DChartsClientRPC.class, new DChartsClientRPC() {
        private static final long serialVersionUID = -3966553309119744743L;

        @Override/* w w w .  j  av a 2 s.c o m*/
        public void setChartId(String id) {
            getWidget().setChartId(id);
        }

        @Override
        public void setChartData(Map<Integer, String> chartData) {
            getWidget().processChartData(chartData);
        }
    });

    LayoutManager.get(getConnection()).addElementResizeListener(getWidget().getElement(),
            new ElementResizeListener() {
                @Override
                public void onElementResize(ElementResizeEvent e) {
                    if (!getWidget().isChartPrepared()) {
                        getWidget().prepareChart();
                    }
                }
            });
    getWidget().addValueChangeHandler(this);
}

From source file:org.vaadin.alump.ckeditor.client.VCKEditorTextField.java

License:Apache License

/**
 * Called whenever an update is received from the server
 *///from w w w .ja  v a2s.c o  m
@Override
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
    clientToServer = client;
    paintableId = uidl.getId();
    boolean needsDataUpdate = false;
    boolean needsProtectedBodyUpdate = false;
    boolean readOnlyModeChanged = false;

    // This call should be made first.
    // It handles sizes, captions, tooltips, etc. automatically.
    // If clientToServer.updateComponent returns true there have been no changes
    // and we do not need to update anything.
    if (clientToServer.updateComponent(this, uidl, true)) {
        return;
    }

    if (!resizeListenerInPlace) {
        LayoutManager.get(client).addElementResizeListener(getElement(), new ElementResizeListener() {

            @Override
            public void onElementResize(ElementResizeEvent e) {
                doResize();
            }

        });
        resizeListenerInPlace = true;
    }

    if (uidl.hasAttribute(ATTR_IMMEDIATE)) {
        immediate = uidl.getBooleanAttribute(ATTR_IMMEDIATE);
    }
    if (uidl.hasAttribute(ATTR_READONLY)) {
        boolean newReadOnly = uidl.getBooleanAttribute(ATTR_READONLY);
        readOnlyModeChanged = newReadOnly != readOnly;
        readOnly = newReadOnly;
    }
    if (uidl.hasAttribute(ATTR_VIEW_WITHOUT_EDITOR)) {
        viewWithoutEditor = uidl.getBooleanAttribute(ATTR_VIEW_WITHOUT_EDITOR);
    }
    if (uidl.hasAttribute(ATTR_PROTECTED_BODY)) {
        boolean state = uidl.getBooleanAttribute(ATTR_PROTECTED_BODY);
        if (protectedBody != state) {
            protectedBody = state;
            needsProtectedBodyUpdate = true;
        }
    }
    if (uidl.hasVariable(VAR_TEXT)) {
        String data = uidl.getStringVariable(VAR_TEXT);
        if (ckEditor != null)
            dataBeforeEdit = ckEditor.getData();
        needsDataUpdate = !data.equals(dataBeforeEdit);
        dataBeforeEdit = data;
    }

    // Save the client side identifier (paintable id) for the widget
    if (!paintableId.equals(getElement().getId())) {
        getElement().setId(paintableId);
    }

    if (viewWithoutEditor) {
        if (ckEditor != null) {
            // may update the data and change to viewWithoutEditor at the same time 
            if (!needsDataUpdate) {
                dataBeforeEdit = ckEditor.getData();
            }
            ckEditor.destroy(true);
            ckEditorIsReady = false;
            ckEditor = null;
        }
        getElement().setInnerHTML(dataBeforeEdit);
    } else if (ckEditor == null) {
        getElement().setInnerHTML(""); // in case we put contents in there while in viewWithoutEditor mode

        final String inPageConfig = uidl.hasAttribute(ATTR_INPAGECONFIG)
                ? uidl.getStringAttribute(ATTR_INPAGECONFIG)
                : null;

        writerIndentationChars = uidl.hasAttribute(ATTR_WRITER_INDENTATIONCHARS)
                ? uidl.getStringAttribute(ATTR_WRITER_INDENTATIONCHARS)
                : null;

        if (uidl.hasAttribute(ATTR_FOCUS)) {
            setFocus(uidl.getBooleanAttribute(ATTR_FOCUS));
        }

        // See if we have any writer rules
        int i = 0;
        while (true) {
            if (!uidl.hasAttribute(ATTR_WRITERRULES_TAGNAME + i)) {
                break;
            }
            // Save the rules until our instance is ready
            String tagName = uidl.getStringAttribute(ATTR_WRITERRULES_TAGNAME + i);
            String jsRule = uidl.getStringAttribute(ATTR_WRITERRULES_JSRULE + i);
            if (writerRules == null) {
                writerRules = new HashMap<String, String>();
            }
            writerRules.put(tagName, jsRule);
            ++i;
        }

        // See if we have any keystrokes
        i = 0;
        while (true) {
            if (!uidl.hasAttribute(ATTR_KEYSTROKES_KEYSTROKE + i)) {
                break;
            }
            // Save the keystrokes until our instance is ready
            int keystroke = uidl.getIntAttribute(ATTR_KEYSTROKES_KEYSTROKE + i);
            String command = uidl.getStringAttribute(ATTR_KEYSTROKES_COMMAND + i);
            if (keystrokeMappings == null) {
                keystrokeMappings = new HashMap<Integer, String>();
            }
            keystrokeMappings.put(keystroke, command);
            ++i;
        }

        // See if we have any protected source regexs
        i = 0;
        while (true) {
            if (!uidl.hasAttribute(ATTR_PROTECTED_SOURCE + i)) {
                break;
            }
            // Save the regex until our instance is ready
            String regex = uidl.getStringAttribute(ATTR_PROTECTED_SOURCE + i);
            if (protectedSourceList == null) {
                protectedSourceList = new LinkedList<String>();
            }
            protectedSourceList.add(regex);
            ++i;
        }

        ScheduledCommand scE = new ScheduledCommand() {
            @Override
            public void execute() {
                ckEditor = (CKEditor) CKEditorService.loadEditor(paintableId, VCKEditorTextField.this,
                        inPageConfig, VCKEditorTextField.super.getOffsetWidth(),
                        VCKEditorTextField.super.getOffsetHeight());

            }
        };

        CKEditorService.loadLibrary(scE);

        // editor data and some options are set when the instance is ready....
    } else if (ckEditorIsReady) {
        if (needsDataUpdate) {
            ckEditor.setData(dataBeforeEdit);
        }

        if (needsProtectedBodyUpdate) {
            ckEditor.protectBody(protectedBody);
        }

        if (uidl.hasAttribute(ATTR_INSERT_HTML)) {
            ckEditor.insertHtml(uidl.getStringAttribute(ATTR_INSERT_HTML));
        }

        if (uidl.hasAttribute(ATTR_INSERT_TEXT)) {
            ckEditor.insertText(uidl.getStringAttribute(ATTR_INSERT_TEXT));
        }

        if (uidl.hasAttribute(ATTR_FOCUS)) {
            setFocus(uidl.getBooleanAttribute(ATTR_FOCUS));
        }

        if (readOnlyModeChanged) {
            ckEditor.setReadOnly(readOnly);
        }
    }

}