Beispiel #1
0
 /** Download actual file */
 public void download() {
   StreamResource resource = new StreamResource(source, fileName);
   resource
       .getStream()
       .setParameter("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
   resource.setMIMEType("application/octet-stream");
   resource.setCacheTime(0);
   FileDownloader downloader = new FileDownloader(resource);
   downloader.extend(ui);
 }
Beispiel #2
0
  @Override
  protected void init(final VaadinRequest request) {
    final TabSheet tabLayout = new TabSheet();
    final VerticalLayout layout = new VerticalLayout();
    layout.addComponent(tabLayout);
    setContent(layout);

    final BinderCollection<MarathonData> binders = new BinderCollection<MarathonData>();

    binders.commitHandler();

    final FormLayout competitionParameters = new FormLayout();
    binders.appendBinder(showOverviewData(competitionParameters));
    tabLayout.addTab(competitionParameters, "Übersicht");

    final FormLayout phaseATabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseATabContent, Phase.A));
    tabLayout.addTab(phaseATabContent, "Phase A");

    final FormLayout phaseDTabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseDTabContent, Phase.D));
    tabLayout.addTab(phaseDTabContent, "Phase D");

    final FormLayout phaseETabContent = new FormLayout();
    binders.appendBinder(showPhaseData(phaseETabContent, Phase.E));
    tabLayout.addTab(phaseETabContent, "Phase E");

    final VerticalLayout outputLayout = new VerticalLayout();
    final FormLayout outputParameters = new FormLayout();

    final BeanItemContainer<String> driverDataSource = new BeanItemContainer<String>(String.class);
    final ComboBox selectDriverCombo = new ComboBox("Fahrer", driverDataSource);
    selectDriverCombo.setNewItemsAllowed(false);
    selectDriverCombo.setImmediate(true);
    outputLayout.addComponent(selectDriverCombo);
    binders.appendBinder(
        new DataBinder<MarathonData>() {

          private MarathonData data;

          @Override
          public void bindData(final MarathonData data) {
            this.data = data;
            driverDataSource.removeAllItems();
            driverDataSource.addAll(data.getDrivers().keySet());
          }

          @Override
          public void commitHandler() {}

          @Override
          public MarathonData getCurrentData() {
            return data;
          }
        });

    // new Button("Erstelle PDF");

    outputLayout.setSizeFull();
    outputLayout.addComponent(outputParameters);
    outputLayout.setExpandRatio(outputParameters, 0);

    final MarathonData marathonData = loadMarathonData("default");
    binders.bindData(marathonData);

    final StreamResource source =
        new StreamResource(
            new StreamSource() {

              @Override
              public InputStream getStream() {
                final ByteArrayOutputStream os = new ByteArrayOutputStream();
                new GeneratePdf()
                    .makePdf(os, binders.getCurrentData(), (String) selectDriverCombo.getValue());
                return new ByteArrayInputStream(os.toByteArray());
              }
            },
            makeOutputFilename());
    source.setMIMEType("application/pdf");
    final BrowserFrame pdf = new BrowserFrame("Output", source);
    pdf.setSizeFull();
    outputLayout.addComponent(pdf);
    outputLayout.setExpandRatio(pdf, 1);
    tabLayout.addTab(outputLayout, "Resultat");
    tabLayout.setSizeFull();
    layout.setExpandRatio(tabLayout, 1);

    layout.setSizeFull();

    selectDriverCombo.addValueChangeListener(
        new ValueChangeListener() {

          @Override
          public void valueChange(final ValueChangeEvent event) {
            binders.commitHandler();
            saveMarathonData(binders.getCurrentData());
            source.setFilename(makeOutputFilename());
            pdf.markAsDirty();
          }
        });

    final Button saveButton =
        new Button(
            "Übernehmen",
            new ClickListener() {
              @Override
              public void buttonClick(final ClickEvent event) {
                binders.commitHandler();
                saveMarathonData(binders.getCurrentData());
                source.setFilename(makeOutputFilename());
                pdf.markAsDirty();
              }
            });
    layout.addComponent(saveButton);
  }
  @Override
  public void execute() {
    List<ChangeRecord> historyList = view.getUi().getStockService().findChanges(good);
    Window subWindow = new Window();
    subWindow.setModal(true);
    subWindow.setHeight("650px");
    subWindow.setWidth("700px");
    subWindow.setClosable(true);
    view.getUi().addWindow(subWindow);

    final Button pdfButton = new Button(bundle.getString("pdf.export"));
    pdfButton.setIcon(new ThemeResource("img/pdf.png"));
    pdfButton.setWidth("150");
    StreamResource pdfStream = getPDFStream(view.getUi().getStockService().findChanges(good));
    pdfStream.setMIMEType("application/pdf");
    FileDownloader pdfDownloader = new FileDownloader(pdfStream);
    pdfDownloader.extend(pdfButton);

    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.addComponent(pdfButton);

    for (ChangeRecord record : historyList) {
      for (ChangeRecord.PropertyChange p : record.getChangeList()) {
        p.setName(bundle.getString(p.getName()));
      }
      Panel panel = new Panel();
      BeanItemContainer<ChangeRecord.PropertyChange> container =
          new BeanItemContainer<>(ChangeRecord.PropertyChange.class, record.getChangeList());
      Table table = new Table();
      table.setContainerDataSource(container);
      table.setVisibleColumns("name", "oldValue", "newValue");
      table.setColumnHeaders(
          bundle.getString("history.property"),
          bundle.getString("history.old"),
          bundle.getString("history.new"));
      table.setColumnExpandRatio("name", 0.33f);
      table.setColumnExpandRatio("oldValue", 0.33f);
      table.setColumnExpandRatio("newValue", 0.33f);
      table.setPageLength(0);
      table.setWidth("100%");

      VerticalLayout panelLayout = new VerticalLayout();
      panelLayout.addComponent(
          new Label(
              "<b>"
                  + new SimpleDateFormat("dd-MM-YYYY HH:mm").format(record.getDate())
                  + ": "
                  + record.getUser().getName()
                  + " "
                  + record.getUser().getSurname()
                  + "</b><br/>",
              ContentMode.HTML));
      panelLayout.addComponent(table);
      panel.setContent(panelLayout);
      layout.addComponent(panel);
    }

    subWindow.setContent(layout);
  }