Package com.example.vaadin

Source Code of com.example.vaadin.MyVaadinApplication

/*
* Copyright 2009 IT Mill Ltd.
*
* Licensed 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 com.example.vaadin;

import java.io.OutputStream;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import com.vaadin.Application;
import com.vaadin.data.Property.ValueChangeEvent;
import com.vaadin.data.Property.ValueChangeListener;
import com.vaadin.data.util.BeanItem;
import com.vaadin.terminal.ThemeResource;
import com.vaadin.terminal.UserError;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.DateField;
import com.vaadin.ui.Form;
import com.vaadin.ui.GridLayout;
import com.vaadin.ui.HorizontalLayout;
import com.vaadin.ui.HorizontalSplitPanel;
import com.vaadin.ui.InlineDateField;
import com.vaadin.ui.Label;
import com.vaadin.ui.LoginForm;
import com.vaadin.ui.Panel;
import com.vaadin.ui.Table;
import com.vaadin.ui.TextField;
import com.vaadin.ui.Upload.Receiver;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window;

/**
* The Application's "main" class
*/
@SuppressWarnings("serial")
public class MyVaadinApplication extends Application implements Receiver {
  private Window window;

  @Override
  public void init() {
    window = new Window("My Vaadin Application 2");
    setMainWindow(window);
    Panel panel = new Panel("nazwa panelu");
    panel.setSizeUndefined();
    LoginForm loginForm = new LoginForm();
    loginForm.setCaption("ralala");
    loginForm.setComponentError(new UserError("adasd"));
    panel.addComponent(loginForm);
    window.addComponent(panel);

    HorizontalLayout horizontalLayout = new HorizontalLayout();
    window.addComponent(horizontalLayout);
    horizontalLayout.setSizeFull();
    Button a = new Button("a");
    a.setSizeFull();
    horizontalLayout.addComponent(a);
    horizontalLayout.addComponent(new Button("b dsfsddsfds"));
    horizontalLayout.addComponent(new Button("csdfds sdfsdfds fsdfsfds"));
    addSUmarryView();

    // addLoginForm(window2);

    // HorizontalSplitPanel verticalLayout = new HorizontalSplitPanel();
    // verticalLayout.setSizeFull();
    // window.addComponent(verticalLayout);
    //
    // GridLayout gridLayout = new GridLayout();
    // addTestField(verticalLayout);
    //
    // addDateFIeld();
    //
    // addActionButton();
    //
    // // addTable();
    //
    // addButtonWithTextFieldGenerator(verticalLayout);

  }

  private void addSUmarryView() {
    final VerticalLayout verticalLayout = new VerticalLayout();
    window.addComponent(verticalLayout);
    final InlineDateField dateField = new InlineDateField();
    dateField.setResolution(DateField.RESOLUTION_MONTH);
    dateField.setImmediate(true);
    final GridLayout days = new GridLayout(7, 7);
    verticalLayout.addComponent(dateField);
    verticalLayout.addComponent(days);
    days.setSizeFull();
    dateField.addListener(new ValueChangeListener() {

      public void valueChange(ValueChangeEvent event) {
        Date value = (Date) dateField.getValue();
        addDays(days, value.getMonth());
      }
    });

  }

  private void addDays(GridLayout days, int month) {
    days.removeAllComponents();
    GregorianCalendar calendar = new GregorianCalendar(2011, month, 1);
    int minimalDaysInFirstWeek = calendar.get(Calendar.DAY_OF_WEEK);
    System.out.println(minimalDaysInFirstWeek);
    int actualMaximum = calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    int actualMinimum = calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
    days.addComponent(new Label("PoniedziaƂek"));
    days.addComponent(new Label("Wtorek"));
    days.addComponent(new Label("Sroda"));
    days.addComponent(new Label("Czwartek"));
    days.addComponent(new Label("Piatek"));
    days.addComponent(new Label("Sobota"));
    days.addComponent(new Label("Niedziela"));
    for (int i = 1; i < minimalDaysInFirstWeek - 1; i++) {
      days.addComponent(new Label(""));
    }
    for (int i = actualMinimum; i <= actualMaximum; i++) {
      Button component = new Button(i + "");
      component.setSizeFull();
      days.addComponent(component);
      int column2 = days.getComponentArea(component).getColumn2();
      if ((column2 % 5 == 0 || column2 % 6 == 0) && (column2 != 0)) {
        component.setEnabled(false);
      }
    }
  }

  private void addLoginForm() {
    Window window2 = new Window("Dane");
    window2.setModal(true);
    window.addWindow(window2);
    LoginForm loginForm = new LoginForm();
    loginForm.setUsernameCaption("Imie i nazwisko");
    window2.addComponent(loginForm);
  }

  private void addButtonWithTextFieldGenerator(HorizontalSplitPanel verticalLayout) {
    Button button = new Button("Pokaz");
    button.setSizeFull();
    verticalLayout.addComponent(button);

    button.addListener(new ClickListener() {

      public void buttonClick(ClickEvent event) {
        GridLayout gridLayout = new GridLayout(10, 10);
        gridLayout.setSizeFull();
        ThemeResource icon = new ThemeResource("../runo/icons/16/ok.png");
        window.addComponent(gridLayout);
        for (int i = 0; i < 100; i++) {
          TextField button2 = new TextField(i + "");
          button2.setIcon(icon);
          button2.setValue(i + "");
          button2.setDescription("Opis: " + i);
          button2.setEnabled(i % 2 == 0);
          button2.setWidth("100px");
          gridLayout.addComponent(button2);
        }
        window.showNotification("hahahah " + new Date(),
            Window.Notification.TYPE_TRAY_NOTIFICATION);
      }
    });
  }

  private void addTable() {
    Table table = new Table("asd");
    table.addContainerProperty("Id", Integer.class, null);
    table.addContainerProperty("Imie", String.class, null);
    table.addContainerProperty("Nazwisko", String.class, null);

    table.setColumnHeader("Id", "Idik");
    table.setSizeFull();

    for (Integer i = 0; i < 50; i++) {
      table.addItem(new Object[] { i, "Imie" + i, "Nazwisko" + 1 }, i + 500);
    }
    table.setColumnCollapsingAllowed(true);
    table.setColumnReorderingAllowed(true);

    window.addComponent(table);
  }

  private void addActionButton() {
    Button dodaj = new Button("Dodaj");
    window.addComponent(dodaj);
    dodaj.addListener(new ClickListener() {

      public void buttonClick(ClickEvent event) {
        Window dodajWindow = new Window("Dodaj");
        dodajWindow.setWidth(400, Form.UNITS_PIXELS);
        dodajWindow.center();
        final Form form = new Form();
        form.setCaption("asdas");
        dodajWindow.addComponent(form);
        form.setItemDataSource(new BeanItem(new Customer()));
        Button button = new Button("Zapisz", form, "commit");
        button.addListener(new ClickListener() {

          public void buttonClick(ClickEvent event) {
            System.out.println("klik");
            Object data = form.getItemDataSource();
            System.out.println(data);
          }
        });
        form.getFooter().addComponent(button);
        form.getField("id").setRequired(true);
        form.getField("id").setRequiredError("przypisz");
        window.addWindow(dodajWindow);
      }
    });
  }

  private void addDateFIeld() {
    DateField dateField = new DateField("A");
    dateField.setDateFormat("yyyy");
    dateField.setResolution(DateField.RESOLUTION_MONTH);
    window.addComponent(dateField);
  }

  private void addTestField(HorizontalSplitPanel verticalLayout) {
    final TextField textField = new TextField();
    textField.setImmediate(true);
    textField.setSizeFull();
    textField.setComponentError(new UserError("sdfds"));
    textField.setMaxLength(10);
    verticalLayout.addComponent(textField);
  }

  //
  // @Override
  // public void terminalError(com.vaadin.terminal.Terminal.ErrorEvent event)
  // {
  // getMainWindow().showNotification(event.getThrowable().toString(),
  // Window.Notification.TYPE_ERROR_MESSAGE);
  // }

  public OutputStream receiveUpload(String filename, String mimeType) {
    System.out.println(filename + " " + mimeType);
    return null;
  }
}
TOP

Related Classes of com.example.vaadin.MyVaadinApplication

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.