de.decidr.ui.view.windows.StartConfigurationWindow.java Source code

Java tutorial

Introduction

Here is the source code for de.decidr.ui.view.windows.StartConfigurationWindow.java

Source

/*
 * The DecidR Development Team licenses this file to you under
 * the Apache License, Version 2.0 (the "License"); you may
 * not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package de.decidr.ui.view.windows;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.CheckBox;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.SplitPanel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

import de.decidr.model.annotations.Reviewed;
import de.decidr.model.annotations.Reviewed.State;
import de.decidr.model.logging.DefaultLogger;
import de.decidr.model.schema.decidrtypes.TConfiguration;
import de.decidr.model.schema.dwdl.TWorkflow;
import de.decidr.ui.controller.HideDialogWindowAction;
import de.decidr.ui.controller.SaveStartConfigurationAction;
import de.decidr.ui.view.ConfigRoles;
import de.decidr.ui.view.ConfigVariableForm;

@Reviewed(reviewers = { "unknown" }, lastRevision = "0", currentReviewState = State.NeedsReview)
public class StartConfigurationWindow extends Window {
    private static final long serialVersionUID = 1L;
    private ConfigRoles configRoles = null;
    private TConfiguration tConfiguration;
    private Long workflowModelId;
    private TWorkflow workflow;
    private ConfigVariableForm configVariableForm = null;
    private CheckBox checkBox;
    private Button okButton;
    private Button cancelButton;

    /**
     * Constructor with TConfiguration as parameter.<br>
     */
    public StartConfigurationWindow(TConfiguration tConfiguration, Long workflowModelId, TWorkflow workflow) {
        this.tConfiguration = tConfiguration;
        this.workflowModelId = workflowModelId;
        this.workflow = workflow;
        DefaultLogger.getLogger(StartConfigurationWindow.class)
                .debug("StartConfigurationWindow initialized, setting up ui components");
        init();
    }

    private void init() {
        VerticalLayout mainVerticalLayout = new VerticalLayout();
        HorizontalLayout buttonHorizontalLayout = new HorizontalLayout();
        checkBox = new CheckBox();

        this.setContent(mainVerticalLayout);

        this.setCaption("Start configuration window");
        this.setModal(true);
        this.setWidth("800px");
        this.setHeight("500px");
        this.setResizable(false);

        mainVerticalLayout.setSpacing(true);
        mainVerticalLayout.setMargin(true);

        if (workflow.getVariables() != null && workflow.getVariables().getVariable().size() > 0) {
            configVariableForm = new ConfigVariableForm(workflow.getVariables());
            configVariableForm.setCaption("Configuration variables");
            configVariableForm.setWriteThrough(false);
            configVariableForm.setInvalidCommitted(false);
        }

        if (workflow.getRoles() != null) {
            configRoles = new ConfigRoles(workflow.getRoles());
        }

        if (configRoles != null && configVariableForm != null) {
            // Set up split panel.
            SplitPanel splitPanel = new SplitPanel();
            splitPanel.setOrientation(SplitPanel.ORIENTATION_HORIZONTAL);
            splitPanel.setSplitPosition(450, Sizeable.UNITS_PIXELS);
            splitPanel.setHeight("400px");
            splitPanel.setLocked(true);

            splitPanel.setFirstComponent(configRoles);
            splitPanel.setSecondComponent(configVariableForm);

            mainVerticalLayout.addComponent(splitPanel);
        } else {
            // At least one of the components is unneeded, so no split panel
            this.setWidth("600px");
            if (configRoles != null) {
                mainVerticalLayout.addComponent(configRoles);
            } else if (configVariableForm != null) {
                mainVerticalLayout.addComponent(configVariableForm);
            }
        }

        okButton = new Button("OK", new SaveStartConfigurationAction(configRoles, configVariableForm,
                tConfiguration, workflowModelId, checkBox.booleanValue()));
        cancelButton = new Button("Cancel", new HideDialogWindowAction());
        mainVerticalLayout.addComponent(buttonHorizontalLayout);

        buttonHorizontalLayout.setSpacing(true);
        buttonHorizontalLayout.addComponent(checkBox);
        checkBox.setCaption("Start Immediately");
        buttonHorizontalLayout.setComponentAlignment(checkBox, Alignment.MIDDLE_RIGHT);
        buttonHorizontalLayout.addComponent(okButton);
        buttonHorizontalLayout.addComponent(cancelButton);
    }

}