All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ikasan.dashboard.ui.scheduler.component.JsonViewerDialog Maven / Gradle / Ivy

There is a newer version: 4.0.1
Show newest version
package org.ikasan.dashboard.ui.scheduler.component;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
import de.f0rce.ace.AceEditor;
import de.f0rce.ace.enums.AceMode;
import de.f0rce.ace.enums.AceTheme;
import org.ikasan.dashboard.ui.general.component.AbstractCloseableResizableDialog;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class JsonViewerDialog extends AbstractCloseableResizableDialog  {

    private Logger logger = LoggerFactory.getLogger(JsonViewerDialog.class);

    private VerticalLayout layout;

    private AceEditor aceEditor;

    private boolean initialised = false;

    private ObjectMapper objectMapper = new ObjectMapper();

    public JsonViewerDialog(Object contents, String header) {
        this(contents);

        super.title.setText(header);
    }

    public JsonViewerDialog(Object contents) {
        this.setHeight("90%");
        this.setWidth("90%");

        layout = new VerticalLayout();
        layout.setSizeFull();
        super.content.add(layout);
        init(contents);
    }

    private void init(Object contents) {
        if(!initialised) {
            this.initialiseEditor();
            this.layout.add(aceEditor);
            this.layout.expand(aceEditor);

            try {
                this.aceEditor.setValue(objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(contents));
            }
            catch (JsonProcessingException e) {
                e.printStackTrace();
            }
        }
    }

    protected void initialiseEditor()
    {
        aceEditor = new AceEditor();

        aceEditor.setTheme(AceTheme.dracula);
        aceEditor.setMode(AceMode.json);
        aceEditor.setFontSize(11);
        aceEditor.setTabSize(4);
        aceEditor.setSizeFull();
        aceEditor.setReadOnly(true);
        aceEditor.setWrap(false);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy