public void preserveValues(final Widget widget) {
   JITVisualizationWidget vWidget = (JITVisualizationWidget) widget;
   ControlLCAUtil.preserveValues(vWidget);
   IWidgetAdapter adapter = WidgetUtil.getAdapter(vWidget);
   adapter.preserve(PROP_VISIBLE, String.valueOf(vWidget.isVisible()));
   adapter.preserve(WIDGET_DATA, new JSVar(vWidget.getJSONData()));
   // only needed for custom variants (theming)
   WidgetLCAUtil.preserveCustomVariant(vWidget);
 }
  public void renderChanges(final Widget widget) throws IOException {
    JITVisualizationWidget vWidget = (JITVisualizationWidget) widget;
    JSWriter writer = JSWriter.getWriterFor(vWidget);
    writer.set(PROP_VISIBLE, PROP_VISIBLE, String.valueOf(vWidget.isVisible()));
    // We compare the JSON text directly because JSVar does not override Object.equals();
    IWidgetAdapter adapter = WidgetUtil.getAdapter(vWidget);
    JSVar oldValue = (JSVar) adapter.getPreserved(WIDGET_DATA);
    String jsonData = vWidget.getJSONData();
    if (jsonData != null && (oldValue == null || !jsonData.equals(oldValue.toString()))) {
      writer.set(WIDGET_DATA, WIDGET_DATA, new JSVar(jsonData));
    }
    ControlLCAUtil.writeChanges(vWidget);

    WidgetCommandQueue cmdQueue = (WidgetCommandQueue) vWidget.getAdapter(WidgetCommandQueue.class);
    if (cmdQueue != null) {
      while (cmdQueue.peek() != null) {
        Object[] functionCall = (Object[]) cmdQueue.poll();
        writer.call((String) functionCall[0], (Object[]) functionCall[1]);
      }
    }
  }