de.decidr.ui.view.WorkflowModelsComponent.java Source code

Java tutorial

Introduction

Here is the source code for de.decidr.ui.view.WorkflowModelsComponent.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;

import com.vaadin.data.Property;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.ui.Button;
import com.vaadin.ui.Label;
import com.vaadin.ui.NativeSelect;

import de.decidr.model.annotations.Reviewed;
import de.decidr.model.annotations.Reviewed.State;
import de.decidr.ui.controller.show.ShowAppointWorkflowAdminAction;
import de.decidr.ui.controller.show.ShowModelDescription;
import de.decidr.ui.controller.show.ShowModelingToolAction;
import de.decidr.ui.controller.workflowmodel.ImportWorkflowModelAction;
import de.decidr.ui.controller.workflowmodel.LockWorkflowModelAction;
import de.decidr.ui.controller.workflowmodel.PublishWorkflowModelAction;
import de.decidr.ui.controller.workflowmodel.RemoveWorkflowModelsAction;
import de.decidr.ui.controller.workflowmodel.UnlockWorkflowModelsAction;
import de.decidr.ui.controller.workflowmodel.UnpublishWorkflowModelsAction;
import de.decidr.ui.data.PublicModelContainer;
import de.decidr.ui.data.WorkflowModelContainer;
import de.decidr.ui.view.tables.PublicModelTable;
import de.decidr.ui.view.tables.WorkflowModelTable;

/**
 * This component represents the workflow models. They are stored in a table.
 * Also the user is able to choose if he wants to show the public workflow
 * models or all workflow models. A tenant table is included, too. If the user
 * selects a model he can create, remove, lock, publish, unpublish, appoint or
 * import a model.
 * 
 * @author AT
 */
@Reviewed(reviewers = { "TK", "JS" }, lastRevision = "0", currentReviewState = State.NeedsReview)
public class WorkflowModelsComponent extends AbstractListComponent {

    private static final long serialVersionUID = -8284535233079548635L;

    private PublicModelContainer publicModelContainer = null;
    private WorkflowModelContainer workflowModelContainer = null;

    private WorkflowModelTable workflowModelTable = null;
    private PublicModelTable publicModelTable = null;

    private Label showModelsFromLabel = null;
    private NativeSelect viewSelect = null;

    private String[] models = new String[] { "Current Tenant", "Public models" };

    /**
     * Default constructor.
     */
    public WorkflowModelsComponent() {
        init();
    }

    /**
     * Changes the view if public models are selected.
     * 
     */
    private void initView() {
        verticalLayout.removeAllComponents();
        removeAllButtons();

        if (viewSelect.isSelected(models[0])) {
            /* Current Tenant view */
            if (workflowModelContainer == null) {
                workflowModelContainer = new WorkflowModelContainer();
                workflowModelTable = new WorkflowModelTable(workflowModelContainer);
            }

            initTenantView();
        } else {
            /* Public models view */
            if (publicModelContainer == null) {
                publicModelContainer = new PublicModelContainer();
                publicModelTable = new PublicModelTable(publicModelContainer);
            }
            initPublicModelView();
        }

    }

    /**
    * Set up public model view.
    *
    */
    private void initPublicModelView() {
        contentTable = publicModelTable;

        addButton("Edit workflow", new ShowModelingToolAction(publicModelTable), ButtonPolicy.ONE_SELECTED, true);
        addButton("Import", new ImportWorkflowModelAction(publicModelTable));
        addButton("Un-publish", new UnpublishWorkflowModelsAction(publicModelTable));

        super.init();

        searchPanel.getSearchHorizontalLayout().addComponent(showModelsFromLabel);
        searchPanel.getSearchHorizontalLayout().addComponent(viewSelect);

    }

    /**
     * Set up tenant view.
     *
     */
    private void initTenantView() {
        contentTable = workflowModelTable;

        viewSelect.setValue("Current Tenant");

        extraComponents = new Button[] {
                new Button("Create New Model", new ShowModelDescription(workflowModelTable)) };
        addButton("Edit Model", new ShowModelingToolAction(workflowModelTable), ButtonPolicy.ONE_SELECTED, true);
        addButton("Remove", new RemoveWorkflowModelsAction(workflowModelTable));
        addButton("Make non-executable", new LockWorkflowModelAction(workflowModelTable));
        addButton("Make executable", new UnlockWorkflowModelsAction(workflowModelTable));
        addButton("Publish", new PublishWorkflowModelAction(workflowModelTable));
        addButton("Appoint workflow admin", new ShowAppointWorkflowAdminAction(workflowModelTable));

        super.init();

        searchPanel.getSearchHorizontalLayout().addComponent(showModelsFromLabel);
        searchPanel.getSearchHorizontalLayout().addComponent(viewSelect);
    }

    /**
     * This method initializes the components for the workflow model component.
     */
    protected void init() {

        label = new Label("<h2> Workflow models </h2>");
        label.setContentMode(Label.CONTENT_XHTML);
        showModelsFromLabel = new Label("Show Models from: ");

        viewSelect = new NativeSelect();
        for (int i = 0; i < models.length; i++) {
            viewSelect.addItem(models[i]);
        }
        viewSelect.setNullSelectionAllowed(false);
        viewSelect.setValue(models[0]);
        viewSelect.setImmediate(true);
        viewSelect.addListener(new Property.ValueChangeListener() {

            /**
             * Serial version uid
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                initView();

            }

        });
        initView();
    }

}