org.ocsoft.olivia.core.OliviaFinalizer.java Source code

Java tutorial

Introduction

Here is the source code for org.ocsoft.olivia.core.OliviaFinalizer.java

Source

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package org.ocsoft.olivia.core;

import java.io.IOException;

import org.ocsoft.olivia.logger.OliviaLogger;
import org.ocsoft.olivia.models.JsonStorable;
import org.ocsoft.olivia.models.contents.config.def.BasicUserConfigDef;
import org.ocsoft.olivia.models.scene.OliviaScene;

import com.fasterxml.jackson.databind.JsonNode;

/**
 * Olivia?????.
 * @author tohhy
 */
public class OliviaFinalizer {

    private OliviaFinalizer() {
    }

    static void doFinalize() {
        storeOpennedProjects();
        storeAssociations();
        storeComponentState();
        storeSceneState();
        storeTabState();
        storeConfig();
    }

    private static void storeComponentState() {
        storeState("components-window", Olivia.getView().getComponents().getWindow());
    }

    private static void storeSceneState() {
        for (OliviaScene scene : Olivia.getScene().getAvailableScenes().values()) {
            //???state?????????
            JsonStorable state = scene.getStorableState();
            if (state != null) {
                try {
                    JsonNode json = state.storeStateAsJson();
                    Olivia.getConfig().getUser().setJsonNode(scene.getID(), json);
                } catch (IOException e) {
                    OliviaLogger.catchException(e);
                }
            }
        }
    }

    private static void storeState(String key, JsonStorable store) {
        try {
            JsonNode json = store.storeStateAsJson();
            Olivia.getConfig().getUser().setJson(key, json.toString());
        } catch (IOException e) {
            OliviaLogger.catchException(e);
        }
    }

    private static void storeAssociations() {
        storeState(BasicUserConfigDef.ASSOCITAITONS.getConfigKey(), Olivia.getAssociation());
    }

    private static void storeOpennedProjects() {
        try {
            JsonNode json = Olivia.getProjects().storeStateAsJson();
            Olivia.getConfig().getUser().setJsonNode("projects", json);
        } catch (IOException e) {
            OliviaLogger.catchException(e);
        }
    }

    private static void storeTabState() {
        try {
            JsonNode node = Olivia.getTabs().storeStateAsJson();
            Olivia.getConfig().getUser().setJsonNode("tabs", node);
        } catch (IOException e) {
            OliviaLogger.catchException(e);
        }
    }

    private static void storeConfig() {
        try {
            Olivia.getConfig().store();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}