Package com.es.app.customs

Source Code of com.es.app.customs.cstMenu

package com.es.app.customs;

import com.es.app.data.GstFormat;
import com.vaadin.server.ThemeResource;
import com.vaadin.shared.Position;
import com.vaadin.ui.Button;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Notification;
import com.vaadin.ui.Notification.Type;

public class cstMenu extends HorizontalLayout {

  /**
   *
   */
  private static final long serialVersionUID = -6618790055772308273L;

  private Button btnSave;
  private Button btnEdit;
  private Button btnCancel;
  private Button btnDele;
  private cstButtonValue btnRefresh;
  private String[] lsCapBut = new String[] { "save", "edit", "cancel",
      "delete", "refresh" };
  private String[] lsIcons = new String[] { ".gif", ".png", ".png", ".png",
      ".png" };
  private String[] lsCapt = new String[] { "Guardar", "Editar", "Cancelar",
      "Eliminar", "Refrescar" };
  private String[] lsDescr = new String[] { "Grabe el contenido actual",
      "Edite informacion del contenido actual",
      "Detener modificacion de contenido actual",
      "Elimine el contenido actual",
      "Volver a cargar el contenido actual" };
  private Button[] lsButCom;
  private String styleBtn = "";
  private boolean viewcap = false;

  public cstMenu() {
    buildMenu();
    buildIcons();
    actCanDel();
  }

  private void buildIcons() {
    int i = 0;
    for (String caption : lsCapBut) {
      if (isViewcap())
        lsButCom[i].setCaption(lsCapt[i].toUpperCase());
      else
        lsButCom[i].setCaption("");

      lsButCom[i].setIcon(new ThemeResource("../factelect/icons/"
          + caption + lsIcons[i]));
      lsButCom[i].setDescription(GstFormat.description(lsCapt[i],
          lsDescr[i]));
      if (!getStyleBtn().isEmpty())
        lsButCom[i].setStyleName(getStyleBtn());
      i++;
    }
  }

  private void buildMenu() {
    setWidth("-1px");
    setHeight("-1px");
    setSpacing(true);

    btnSave = new Button();
    btnSave.setWidth("-1px");
    btnSave.setHeight("-1px");
    btnSave.addClickListener(new Button.ClickListener() {

      /**
       *
       */
      private static final long serialVersionUID = 812750122135440314L;

      @Override
      public void buttonClick(ClickEvent event) {
        // TODO Auto-generated method stub
        actSave();
      }
    });
    addComponent(btnSave);

    btnEdit = new Button();
    btnEdit.setWidth("-1px");
    btnEdit.setHeight("-1px");
    btnEdit.addClickListener(new Button.ClickListener() {

      /**
       *
       */
      private static final long serialVersionUID = 812750122135440314L;

      @Override
      public void buttonClick(ClickEvent event) {
        // TODO Auto-generated method stub
        actEdit();
      }
    });
    addComponent(btnEdit);

    btnCancel = new Button();
    btnCancel.setWidth("-1px");
    btnCancel.setHeight("-1px");
    btnCancel.addClickListener(new Button.ClickListener() {

      /**
       *
       */
      private static final long serialVersionUID = 812750122135440314L;

      @Override
      public void buttonClick(ClickEvent event) {
        // TODO Auto-generated method stub
        actCanDel();
      }
    });

    addComponent(btnCancel);

    btnDele = new Button();
    btnDele.setWidth("-1px");
    btnDele.setHeight("-1px");
    btnDele.addClickListener(new Button.ClickListener() {

      /**
       *
       */
      private static final long serialVersionUID = 812750122135440314L;

      @Override
      public void buttonClick(ClickEvent event) {
        // TODO Auto-generated method stub
        actCanDel();
      }
    });

    addComponent(btnDele);

    btnRefresh = new cstButtonValue();
    btnRefresh.setWidth("-1px");
    btnRefresh.setHeight("-1px");
    btnRefresh.addClickListener(new Button.ClickListener() {

      /**
       *
       */
      private static final long serialVersionUID = 812750122135440314L;

      @Override
      public void buttonClick(ClickEvent event) {
        // TODO Auto-generated method stub
        Notification nota = new Notification("", Type.TRAY_NOTIFICATION);
        nota.setPosition(Position.BOTTOM_LEFT);
        nota.setDescription("Refrescando contenido...");
        nota.setIcon(event.getButton().getIcon());
        nota.setDelayMsec(Notification.DELAY_NONE);
        nota.show(getUI().getPage());
      }
    });

    addComponent(btnRefresh);

    lsButCom = new Button[] { btnSave, btnEdit, btnCancel, btnDele,
        btnRefresh };
  }

  private void actSave() {
    btnSave.setEnabled(false);
    btnEdit.setEnabled(true);
    btnCancel.setEnabled(false);
    btnDele.setEnabled(true);
    btnRefresh.setEnabled(true);
  }

  private void actEdit() {
    btnSave.setEnabled(true);
    btnEdit.setEnabled(false);
    btnCancel.setEnabled(true);
    btnDele.setEnabled(false);
    btnRefresh.setEnabled(false);
  }

  private void actCanDel() {
    btnSave.setEnabled(false);
    btnEdit.setEnabled(true);
    btnCancel.setEnabled(false);
    btnDele.setEnabled(true);
    btnRefresh.setEnabled(true);
  }

  /** Mostrar unicamente un boton de la lista del menu */
  public void showOnly(Button button) {
    for (Button s : lsButCom)
      if (s != button)
        s.setVisible(false);
  }

  public Button getBtnSave() {
    return btnSave;
  }

  public void setBtnSave(Button btnSave) {
    this.btnSave = btnSave;
  }

  public Button getBtnEdit() {
    return btnEdit;
  }

  public void setBtnEdit(Button btnEdit) {
    this.btnEdit = btnEdit;
  }

  public Button getBtnCancel() {
    return btnCancel;
  }

  public void setBtnCancel(Button btnCancel) {
    this.btnCancel = btnCancel;
  }

  public Button getBtnDele() {
    return btnDele;
  }

  public void setBtnDele(Button btnDele) {
    this.btnDele = btnDele;
  }

  public cstButtonValue getBtnRefresh() {
    return btnRefresh;
  }

  public void setBtnRefresh(cstButtonValue btnRefresh) {
    this.btnRefresh = btnRefresh;
  }

  public String getStyleBtn() {
    return styleBtn;
  }

  public void setStyleBtn(String style) {
    this.styleBtn = style;
  }

  public boolean isViewcap() {
    return viewcap;
  }

  public void setViewcap(boolean viewcap) {
    this.viewcap = viewcap;
  }
}
TOP

Related Classes of com.es.app.customs.cstMenu

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.