co.edu.icesi.academ.client.perfiles.administrador.PanelAlcance.java Source code

Java tutorial

Introduction

Here is the source code for co.edu.icesi.academ.client.perfiles.administrador.PanelAlcance.java

Source

/**
* Copyright  2013 Universidad Icesi
* 
* This file is part of ACADEM.
* 
* ACADEM 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.
* 
* ACADEM 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 ACADEM.  If not, see <http://www.gnu.org/licenses/>.
**/

package co.edu.icesi.academ.client.perfiles.administrador;

import java.util.ArrayList;
import java.util.List;

import co.edu.icesi.academ.bo.BloqueBO;
import co.edu.icesi.academ.bo.CompetenciaBO;
import co.edu.icesi.academ.bo.MateriaBO;
import co.edu.icesi.academ.bo.ResultadoAprendizajeBO;

import com.vaadin.annotations.AutoGenerated;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.ui.AbsoluteLayout;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.ComboBox;
import com.vaadin.ui.CustomComponent;
import com.vaadin.ui.Label;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;
import com.vaadin.ui.Table;

//ESTE PANEL PERMITE ASOCIAR EL ALCANCE A UNA MATERIA

public class PanelAlcance extends CustomComponent {

    /*- VaadinEditorProperties={"grid":"RegularGrid,20","showGrid":true,"snapToGrid":true,"snapToObject":true,"movingGuides":false,"snappingDistance":10} */

    @AutoGenerated
    private AbsoluteLayout mainLayout;
    @AutoGenerated
    private Table tableCompetencias;
    @AutoGenerated
    private Table tableResultadoAlcance;
    @AutoGenerated
    private Table tableMaterias;
    @AutoGenerated
    private Table table_bloques;
    @AutoGenerated
    private Button button_guardarAlcance;
    @AutoGenerated
    private Label label_4;
    private List<BloqueBO> listBloqueBOs;
    private List<MateriaBO> listMatBOs;

    /**
     * (. Y .)
     */
    private static final long serialVersionUID = 1L;

    /**
     * The constructor should first build the main layout, set the composition
     * root and then do any custom initialization.
     * 
     * The constructor will not be automatically regenerated by the visual
     * editor.
     */
    public PanelAlcance() {
        buildMainLayout();
        setCompositionRoot(mainLayout);

        tableResultadoAlcance.addContainerProperty("Resultado de aprendizaje", String.class, null);
        tableResultadoAlcance.addContainerProperty("Alcance", ComboBox.class, null);
        tableResultadoAlcance.setSelectable(true);
        tableResultadoAlcance.setImmediate(true);

        table_bloques.addContainerProperty("Bloques", BloqueBO.class, null);
        table_bloques.setSelectable(true);
        table_bloques.setImmediate(true);
        table_bloques.setNullSelectionAllowed(false);
        table_bloques.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                try {
                    int i = Integer.parseInt(table_bloques.getValue().toString());
                    ControladorAdministrador.getInstance().cargarMateriasAlcance(listBloqueBOs.get(i));
                    ControladorAdministrador.getInstance().cargarCompetencias(listBloqueBOs.get(i));
                } catch (Exception e) {
                    Notification.show(e.getMessage(), Type.ERROR_MESSAGE);
                }
            }
        });

        tableMaterias.addContainerProperty("Cdigo", String.class, null);
        tableMaterias.addContainerProperty("Materia", MateriaBO.class, null);
        tableMaterias.setSelectable(true);
        tableMaterias.setImmediate(true);
        tableMaterias.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {
                try {
                    int i = Integer.parseInt(tableMaterias.getValue().toString());
                    ControladorAdministrador.getInstance().getAcademUI().mostrarNotificacion("Tabla Materias",
                            listMatBOs.get(i) + " materia");
                } catch (Exception e) {
                    // ControladorAdministrador.getInstance().cargarMateriasAlcance((BloqueBO)table_bloques.getValue());               
                }
            }
        });

        button_guardarAlcance.addClickListener(new ClickListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void buttonClick(ClickEvent event) {

            }
        });

        tableCompetencias.addContainerProperty("Competencia", CompetenciaBO.class, null);
        tableCompetencias.setSelectable(true);
        tableCompetencias.setImmediate(true);
        tableCompetencias.addValueChangeListener(new ValueChangeListener() {
            private static final long serialVersionUID = 1L;

            @Override
            public void valueChange(ValueChangeEvent event) {

            }
        });
    }

    // waiting for BD Object = Comptencia
    /**
     * Mtodo que permite agregarCompetencias
     * 
     * @param competencias
     */
    public void agregarCompetencias(List<Object> competencias) {
        for (Object compe : competencias) {
            //         comboBox_Competencias.addItem(compe);
        }
    }

    public void cargarBloques(List<BloqueBO> bloques) {
        this.listBloqueBOs = new ArrayList<>();
        table_bloques.removeAllItems();
        this.listBloqueBOs = bloques;
        for (int i = 0; i < bloques.size(); i++) {
            BloqueBO bloqueBO = bloques.get(i);
            table_bloques.addItem(new Object[] { bloqueBO }, new Integer(i));
        }
    }

    public void cargarResultadosAlcances(List<ResultadoAprendizajeBO> list) {
        tableResultadoAlcance.removeAllItems();
        for (int i = 1; i < list.size(); i++) {
            ComboBox box = new ComboBox();
            box.addItem("Introduce");
            box.addItem("Ensea");
            box.addItem("Aplica");
            box.setNullSelectionAllowed(false);
            box.setTextInputAllowed(false);
            tableResultadoAlcance.addItem(
                    new Object[] { list.get(i).getNivelDeConocimiento().getDescripcion(), box }, new Integer(i));
        }
    }

    public void cargarMaterias(List<MateriaBO> listMat) {
        this.listMatBOs = new ArrayList<>();
        this.listMatBOs = listMat;
        tableMaterias.removeAllItems();
        for (int i = 0; i < listMat.size(); i++) {
            MateriaBO mat = listMat.get(i);
            tableMaterias.addItem(new Object[] { mat.getCodigo(), mat }, new Integer(i));
        }
    }

    public void cargarCompetencias(List<CompetenciaBO> listCompetenciaBOs) {
        tableCompetencias.removeAllItems();
        for (CompetenciaBO compBO : listCompetenciaBOs) {
            tableCompetencias.addItem(new Object[] { compBO }, compBO);
        }
    }

    @AutoGenerated
    private AbsoluteLayout buildMainLayout() {
        // common part: create layout
        mainLayout = new AbsoluteLayout();
        mainLayout.setImmediate(false);
        mainLayout.setWidth("840px");
        mainLayout.setHeight("440px");

        // top-level component properties
        setWidth("840px");
        setHeight("440px");

        // label_4
        label_4 = new Label();
        label_4.setImmediate(false);
        label_4.setWidth("-1px");
        label_4.setHeight("-1px");
        label_4.setValue("Competencias");
        mainLayout.addComponent(label_4, "top:220.0px;left:23.0px;");

        // button_guardarAlcance
        button_guardarAlcance = new Button();
        button_guardarAlcance.setCaption("Guardar Alcance");
        button_guardarAlcance.setImmediate(true);
        button_guardarAlcance.setWidth("-1px");
        button_guardarAlcance.setHeight("-1px");
        mainLayout.addComponent(button_guardarAlcance, "top:20.0px;left:20.0px;");

        // table_bloques
        table_bloques = new Table();
        table_bloques.setImmediate(false);
        table_bloques.setWidth("260px");
        table_bloques.setHeight("120px");
        mainLayout.addComponent(table_bloques, "top:60.0px;left:20.0px;");

        // tableMaterias
        tableMaterias = new Table();
        tableMaterias.setImmediate(false);
        tableMaterias.setWidth("520px");
        tableMaterias.setHeight("120px");
        mainLayout.addComponent(tableMaterias, "top:60.0px;left:300.0px;");

        // tableResultadoAlcance
        tableResultadoAlcance = new Table();
        tableResultadoAlcance.setImmediate(false);
        tableResultadoAlcance.setWidth("800px");
        tableResultadoAlcance.setHeight("140px");
        mainLayout.addComponent(tableResultadoAlcance, "top:300.0px;left:20.0px;");

        // tableCompetencias
        tableCompetencias = new Table();
        tableCompetencias.setCaption("Resultados aprendizaje");
        tableCompetencias.setImmediate(false);
        tableCompetencias.setWidth("700px");
        tableCompetencias.setHeight("80px");
        mainLayout.addComponent(tableCompetencias, "top:200.0px;left:120.0px;");

        return mainLayout;
    }
}