Exemplo n.º 1
0
 private Component getPdfPanel() {
   if (pdfPanel == null) {
     pdfPanel = new BrowserFrame("Preview");
     pdfPanel.setSizeFull();
     pdfPanel.setStyleName("njadmin-hide-overflow-for-help");
   }
   return pdfPanel;
 }
Exemplo n.º 2
0
 public void showReport(String url) {
   ExternalResource source = new ExternalResource(url);
   // source.setMIMEType("application/pdf");
   if (pdfPanel == null) {
     layout.setSecondComponent(getPdfPanel());
   }
   pdfPanel.setSource(source);
 }
Exemplo n.º 3
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);
  }