/*
 * PEnetration TEsting Proxy (PETEP)
 *
 * Copyright (C) 2020 Michal Válka
 *
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU General Public License as published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program. If
 * not, see <https://www.gnu.org/licenses/>.
 */
package com.warxim.petep.extension.internal.tagger.gui.subrule;

import com.warxim.petep.extension.internal.tagger.factory.TagSubrule;
import com.warxim.petep.extension.internal.tagger.factory.TagSubruleFactoryManager;

import java.io.IOException;

/**
 * Edit tag subrule dialog.
 */
public final class EditTagSubruleDialog extends TagSubruleDialog {
    /**
     * Constructs tag subrule dialog for editing.
     * @param factoryManager Manager of tag subrule factories
     * @param subrule Subrule to be edited
     * @throws IOException If the dialog template could not be loaded
     */
    public EditTagSubruleDialog(TagSubruleFactoryManager factoryManager, TagSubrule subrule) throws IOException {
        super("Edit tag subrule", "Save", factoryManager);

        factoryInput.getSelectionModel().select(subrule.getFactory());

        // Load config pane.
        var pane = createFactoryPane();
        if (pane == null) {
            return;
        }
        setFactoryPane(pane);

        // Get configuration from instance.
        var data = subrule.getData();
        if (data == null) {
            return;
        }

        // Set config to pane.
        pane.setConfig(data);
    }
}
