List of usage examples for com.vaadin.server FileResource FileResource
public FileResource(File sourceFile)
From source file:edu.nps.moves.mmowgli.utility.MediaLocator.java
License:Open Source License
public Resource locate(Media m, Integer sz) { String url = m.getUrl();//from w ww .j a va 2 s .c o m if (sz != null) { url = mangleUrl(url, sz); } switch (m.getSource()) { case USER_UPLOADS_REPOSITORY: // used to be CLASSPATH try { if (url.indexOf(':') == -1) return new ExternalResource(new URL(getUserImagesUrl(), url)); return new ExternalResource(new URL(url)); } catch (MalformedURLException ex) { System.err.println(ex.getClass().getSimpleName() + " " + ex.getLocalizedMessage() + " in MediaLocator.locate()"); return new ExternalResource(gameImagesUrl); // anything } case GAME_IMAGES_REPOSITORY: String path = url; if (m.getType() == MediaType.AVATARIMAGE) path = "avatars/" + path; else if (m.getType() == MediaType.VIDEO) path = "mov/" + path; try { if (path.indexOf(':') == -1) return new ExternalResource(new URL(gameImagesUrl, path)); return new ExternalResource(new URL(path)); } catch (MalformedURLException ex) { System.err.println(ex.getClass().getSimpleName() + " " + ex.getLocalizedMessage() + " in MediaLocator.locate()"); return new ExternalResource(gameImagesUrl); // anything } case WEB_FULL_URL: try { return new ExternalResource(new URL(url)); } catch (MalformedURLException e) { System.err.println( e.getClass().getSimpleName() + " " + e.getLocalizedMessage() + " in MediaLocator.locate()"); return new ExternalResource(gameImagesUrl); // anything } case FILESYSTEM_PATH: return new FileResource(new File(url)); case DATABASE: try { return new ExternalResource(new URL(ImageServlet.getBaseImageUrl(), url)); } catch (MalformedURLException e) { System.err.println("Bad URL, type DATABASE, in " + e.getClass().getSimpleName() + " " + e.getLocalizedMessage() + " in MediaLocator.locate()"); return new ExternalResource(gameImagesUrl); // anything } default: System.err.println("Program error in MediaLocator.locate"); return null; } }
From source file:eu.eco2clouds.portal.component.PictureWindow.java
License:Apache License
private void render() { VerticalLayout content = new VerticalLayout(); content.setSpacing(true);//from w w w . j ava 2 s. c o m content.setMargin(true); content.setSizeFull(); Image image = new Image(); //image.setSource(new ThemeResource("img/applicationsample.png")); image.setSource(new FileResource( new File(Configuration.propertiesDir + File.separator + "sample_applicationprofile.png"))); //image.setHeight("300px"); content.addComponent(image); Button btnClose = new Button("Close"); btnClose.addClickListener(new Button.ClickListener() { @Override public void buttonClick(ClickEvent event) { close(); } }); content.addComponent(btnClose); content.setExpandRatio(image, 1.0f); content.setComponentAlignment(btnClose, Alignment.BOTTOM_CENTER); this.setContent(content); this.setHeight("450px"); this.setWidth("900px"); this.center(); this.setModal(true); }
From source file:eu.fp7.eagle.portal.ui.dashboard.design.impl.BadgesDesignImpl.java
License:Apache License
private void initImages(Map<String, Boolean> greyParams) { basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resourceImageBadgeOC = null; FileResource resourceImageBadgeStar1OC = null; FileResource resourceImageBadgeStar2OC = null; FileResource resourceImageBadgeStar3OC = null; FileResource resourceImageBadgeFlagOC = null; FileResource resourceImageBadgeRev = null; FileResource resourceImageBadgeStar1Rev = null; FileResource resourceImageBadgeStar2Rev = null; FileResource resourceImageBadgeStar3Rev = null; FileResource resourceImageBadgeFlagRev = null; FileResource resourceImageBadgeNet = null; FileResource resourceImageBadgeStar1Net = null; FileResource resourceImageBadgeStar2Net = null; FileResource resourceImageBadgeStar3Net = null; FileResource resourceImageBadgeFlagNet = null; if (greyParams.get("OER_CREATOR")) { resourceImageBadgeOC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/badge2.png")); resourceImageBadgeStar1OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/1star_orange.png")); resourceImageBadgeStar2OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/2star_orange.png")); resourceImageBadgeStar3OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/3star_orange.png")); resourceImageBadgeFlagOC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/orange_flag.png")); }//from w w w.j av a 2 s . c om else { resourceImageBadgeOC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/badge2.png")); resourceImageBadgeStar1OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/1star_green.png")); resourceImageBadgeStar2OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/2star_green.png")); resourceImageBadgeStar3OC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/3star_green.png")); resourceImageBadgeFlagOC = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/green_flag.png")); } if (greyParams.get("REVIEWER")) { resourceImageBadgeRev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/badge1.png")); resourceImageBadgeStar1Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/1star_orange.png")); resourceImageBadgeStar2Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/2star_orange.png")); resourceImageBadgeStar3Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/3star_orange.png")); resourceImageBadgeFlagRev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/orange_flag.png")); } else { resourceImageBadgeRev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/badge1.png")); resourceImageBadgeStar1Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/1star_orange.png")); resourceImageBadgeStar2Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/2star_orange.png")); resourceImageBadgeStar3Rev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/3star_orange.png")); resourceImageBadgeFlagRev = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/orange_flag.png")); } if (greyParams.get("NETWORKER")) { resourceImageBadgeNet = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/badge3.png")); resourceImageBadgeStar1Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/1star_orange.png")); resourceImageBadgeStar2Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/2star_orange.png")); resourceImageBadgeStar3Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/3star_orange.png")); resourceImageBadgeFlagNet = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/grey/39l38h/orange_flag.png")); } else { resourceImageBadgeNet = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/badge3.png")); resourceImageBadgeStar1Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/1star_blue.png")); resourceImageBadgeStar2Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/2star_blue.png")); resourceImageBadgeStar3Net = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/3star_blue.png")); resourceImageBadgeFlagNet = new FileResource( new File(basepath + "/VAADIN/themes/eagle/images/color/39l38h/blue_flag.png")); } imageBadgeOC = new Image(null, resourceImageBadgeOC); imageBadgeStar1OC = new Image(null, resourceImageBadgeStar1OC); imageBadgeStar2OC = new Image(null, resourceImageBadgeStar2OC); imageBadgeStar3OC = new Image(null, resourceImageBadgeStar3OC); imageBadgeFlagOC = new Image(null, resourceImageBadgeFlagOC); imageBadgeRev = new Image(null, resourceImageBadgeRev); imageBadgeStar1Rev = new Image(null, resourceImageBadgeStar1Rev); imageBadgeStar2Rev = new Image(null, resourceImageBadgeStar2Rev); imageBadgeStar3Rev = new Image(null, resourceImageBadgeStar3Rev); imageBadgeFlagRev = new Image(null, resourceImageBadgeFlagRev); imageBadgeNet = new Image(null, resourceImageBadgeNet); imageBadgeStar1Net = new Image(null, resourceImageBadgeStar1Net); imageBadgeStar2Net = new Image(null, resourceImageBadgeStar2Net); imageBadgeStar3Net = new Image(null, resourceImageBadgeStar3Net); imageBadgeFlagNet = new Image(null, resourceImageBadgeFlagNet); }
From source file:facs.components.Statistics.java
License:Open Source License
private Component initialGrid() { VerticalLayout gridLayout = new VerticalLayout(); createInvoice.setEnabled(false);//from w w w .ja va 2 s . com downloadInvoice.setEnabled(false); String buttonRefreshTitle = "Refresh"; Button refresh = new Button(buttonRefreshTitle); refresh.setIcon(FontAwesome.REFRESH); refresh.setDescription("Click here to reload the data from the database!"); refresh.addStyleName(ValoTheme.BUTTON_FRIENDLY); refresh.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496269L; @Override public void buttonClick(ClickEvent event) { refreshDataSources(); } }); Date dNow = new Date(); SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy hh:mm:ss"); System.out.println(ft.format(dNow) + " INFO Statistics accessed! - User: " + LiferayAndVaadinUtils.getUser().getScreenName()); // Add some generated properties IndexedContainer container = getEmptyContainer(); gpcontainer = new GeneratedPropertyContainer(container); Grid grid = new Grid(gpcontainer); grid.setWidth("100%"); setRenderers(grid); fillRows(grid); // compute total costs float totalCosts = 0.0f; for (Object itemId : gpcontainer.getItemIds()) totalCosts += ((Number) gpcontainer.getContainerProperty(itemId, costCaption).getValue()).floatValue(); // compute total time in milliseconds long total = 0; for (Object itemId : gpcontainer.getItemIds()) { long s = ((Date) gpcontainer.getContainerProperty(itemId, startCaption).getValue()).getTime(); long e = ((Date) gpcontainer.getContainerProperty(itemId, endCaption).getValue()).getTime(); total += e - s; } // set footer to contain total cost and time in hours:minutes FooterRow footer = grid.appendFooterRow(); FooterCell footerCellCost = footer.getCell(costCaption); footerCellCost.setText(String.format("%1$.2f total", totalCosts)); FooterCell footerCellEnd = footer.getCell(endCaption); footerCellEnd.setText(Formatter.toHoursAndMinutes(total)); // "%1$.0f hours" // Set up a filter for all columns HeaderRow filterRow = grid.appendHeaderRow(); addRowFilter(filterRow, deviceCaption, container, footer, gpcontainer); addRowFilter(filterRow, kostenstelleCaption, container, footer, gpcontainer); Label infoLabel = new Label( DBManager.getDatabaseInstance().getUserNameByUserID(LiferayAndVaadinUtils.getUser().getScreenName()) + " " + LiferayAndVaadinUtils.getUser().getScreenName()); infoLabel.addStyleName("h4"); // createInvoice.setSizeFull(); // downloadInvoice.setSizeFull(); gridLayout.setWidth("100%"); gridLayout.setCaption("Statistics"); // add components to the grid layout // gridLayout.addComponent(infoLabel, 0, 0, 3, 0); // gridLayout.addComponent(grid, 0, 1, 5, 1); // gridLayout.addComponent(createInvoice, 0, 3); // gridLayout.addComponent(downloadInvoice, 1, 3); gridLayout.addComponent(grid); gridLayout.addComponent(refresh); gridLayout.addComponent(createInvoice); gridLayout.addComponent(downloadInvoice); gridLayout.setMargin(true); gridLayout.setSpacing(true); // grid.setEditorEnabled(true); grid.setSelectionMode(SelectionMode.SINGLE); grid.addSelectionListener(new SelectionListener() { /** * */ private static final long serialVersionUID = -2683274060620429050L; @Override public void select(SelectionEvent event) { // Notification.show("Select row: " + grid.getSelectedRow() + " Name: " // + gpcontainer.getContainerProperty(grid.getSelectedRow(), nameCaption).getValue()); downloadInvoice.setEnabled(false); ReceiverPI = (String) gpcontainer.getContainerProperty(grid.getSelectedRow(), nameCaption) .getValue(); createInvoice.setEnabled(true); } }); createInvoice.addClickListener(new ClickListener() { /** * */ private static final long serialVersionUID = 5512585967145932560L; private File bill; private FileDownloader fileDownloader; @Override public void buttonClick(ClickEvent event) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); Paths.get(basepath, "WEB-INF/billingTemplates"); // System.out.println("Basepath: " + basepath); try { int setUserId = DBManager.getDatabaseInstance().findUserByFullName(ReceiverPI); if (setUserId > 0) { Billing billing = new Billing(Paths.get(basepath, "WEB-INF/billingTemplates").toFile(), "Angebot.tex"); UserBean user = setUserId > 0 ? DBManager.getDatabaseInstance().getUserById(setUserId) : null; billing.setReceiverPI(ReceiverPI); billing.setReceiverInstitution(user.getInstitute()); billing.setReceiverStreet(user.getStreet()); billing.setReceiverPostalCode(user.getPostcode()); billing.setReceiverCity(user.getCity()); billing.setSenderName("Dr. rer. nat. Stella Autenrieth"); billing.setSenderFunction("Leiterin"); billing.setSenderPostalCode("72076"); billing.setSenderCity("Tbingen"); billing.setSenderStreet("Otfried-Mller-Strae 10"); billing.setSenderPhone("+49 (0) 7071 29-83156"); billing.setSenderEmail("stella.autenrieth@med.uni-tuebingen.de"); billing.setSenderUrl("www.medizin.uni-tuebingen.de"); billing.setSenderFaculty("Medizinischen Fakultt"); if (user.getKostenstelle() != null) billing.setProjectDescription("Kostenstelle: " + user.getKostenstelle()); else billing.setProjectDescription("Keine kostenstelle verfgbar."); billing.setProjectShortDescription("Dieses Angebot beinhaltet jede Menge Extras."); if (user.getProject() != null) billing.setProjectNumber("Kostenstelle: " + user.getKostenstelle()); else billing.setProjectNumber("Keine project nummer verfgbar."); float cost = ((Number) gpcontainer.getContainerProperty(grid.getSelectedRow(), costCaption) .getValue()).floatValue(); long s = ((Date) gpcontainer.getContainerProperty(grid.getSelectedRow(), startCaption) .getValue()).getTime(); long e = ((Date) gpcontainer.getContainerProperty(grid.getSelectedRow(), endCaption) .getValue()).getTime(); long timeFrame = e - s; Date start = ((Date) gpcontainer.getContainerProperty(grid.getSelectedRow(), startCaption) .getValue()); SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy"); String date = ft.format(start); String description = "No Description is Available"; String time_frame = Formatter.toHoursAndMinutes(timeFrame); ArrayList<CostEntry> entries = new ArrayList<CostEntry>(); entries.add(billing.new CostEntry(date, time_frame, description, cost)); billing.setCostEntries(entries); float totalCosts = 0.0f; // calculates the total cost of items // for (Object itemId : gpcontainer.getItemIds()) { // totalCosts += // ((Number) gpcontainer.getContainerProperty(itemId, costCaption).getValue()) // .floatValue(); // } totalCosts = ((Number) gpcontainer.getContainerProperty(grid.getSelectedRow(), costCaption) .getValue()).floatValue(); billing.setTotalCost(String.format("%1$.2f", totalCosts)); bill = billing.createPdf(); // System.out.println(bill.getAbsolutePath()); if (fileDownloader != null) downloadInvoice.removeExtension(fileDownloader); fileDownloader = new FileDownloader(new FileResource(bill)); fileDownloader.extend(downloadInvoice); downloadInvoice.setEnabled(true); showSuccessfulNotification("Congratulations!", "Invoice is created and available for download."); downloadInvoice.setEnabled(true); } else { createInvoice.setEnabled(false); downloadInvoice.setEnabled(false); showErrorNotification("No such user found!", "An error occured while trying to create the invoice. The common problem occurs to be: this no such user in the database."); } } catch (Exception e) { showErrorNotification("What the heck!", "An error occured while trying to create the invoice. The common problem occurs to be: this no such user or it can not run program 'pdflatex'."); e.printStackTrace(); } // for all entries /* * try { Billing billing = new Billing(Paths.get(basepath, * "WEB-INF/billingTemplates").toFile(), "Angebot.tex"); * billing.setRecieverInstitution("BER - Berliner Flughafen"); * billing.setRecieverPI("Klaus Something"); * billing.setRecieverStreet("am berliner flughafen 12"); * billing.setRecieverPostalCode("D-12345"); billing.setRecieverCity("Berlin"); * * billing.setSenderName("Dr. rer. nat. Stella Autenrieth"); * billing.setSenderFunction("Leiterin"); billing.setSenderPostalCode("72076"); * billing.setSenderCity("Tbingen"); billing.setSenderStreet("Otfried-Mller-Strae 10"); * billing.setSenderPhone("+49 (0) 7071 29-83156"); * billing.setSenderEmail("stella.autenrieth@med.uni-tuebingen.de"); * billing.setSenderUrl("www.medizin.uni-tuebingen.de"); * billing.setSenderFaculty("Medizinischen Fakultt"); * * billing.setProjectDescription("Dieses Angebot beinhaltet jede Menge Extras."); * billing.setProjectShortDescription("jede Menge Extras."); * billing.setProjectNumber("QA2014016"); * * ArrayList<CostEntry> entries = new ArrayList<CostEntry>(); for (Object itemId : * gpcontainer.getItemIds()) { float cost = ((Number) * gpcontainer.getContainerProperty(itemId, costCaption).getValue()) .floatValue(); long s = * ((Date) gpcontainer.getContainerProperty(itemId, startCaption).getValue()) .getTime(); * long e = ((Date) gpcontainer.getContainerProperty(itemId, * endCaption).getValue()).getTime(); long timeFrame = e - s; Date start = ((Date) * gpcontainer.getContainerProperty(itemId, startCaption).getValue()); SimpleDateFormat ft = * new SimpleDateFormat("dd.MM.yyyy"); String date = ft.format(start); String description = * "No Description is Available"; String time_frame = * Formatter.toHoursAndMinutes(timeFrame); entries.add(billing.new CostEntry(date, * time_frame, description, cost)); } billing.setCostEntries(entries); float totalCosts = * 0.0f; for (Object itemId : gpcontainer.getItemIds()) { totalCosts += ((Number) * gpcontainer.getContainerProperty(itemId, costCaption).getValue()) .floatValue(); } * * billing.setTotalCost(String.format("%1$.2f", totalCosts)); * * bill = billing.createPdf(); System.out.println(bill.getAbsolutePath()); if * (fileDownloader != null) downloadBill.removeExtension(fileDownloader); fileDownloader = * new FileDownloader(new FileResource(bill)); fileDownloader.extend(downloadBill); * downloadBill.setEnabled(true); showSuccessfulNotification("Congratulations!", * "Invoice is created and available for download."); } catch (Exception e) { * showErrorNotification( "What the heck!", * "An error occured while trying to create the invoice. The common problem occurs to be: cannot run program 'pdflatex'" * ); e.printStackTrace(); } */ } }); return gridLayout; }
From source file:facs.components.Statistics.java
License:Open Source License
private Component newMatchedGrid() { Button createInvoiceMatched = new Button("Create Invoice"); Button downloadInvoiceMatched = new Button("Download Invoice"); String buttonRefreshTitle = "Refresh"; Button refreshMatched = new Button(buttonRefreshTitle); refreshMatched.setIcon(FontAwesome.REFRESH); refreshMatched.setDescription("Click here to reload the data from the database!"); refreshMatched.addStyleName(ValoTheme.BUTTON_FRIENDLY); createInvoiceMatched.setEnabled(false); downloadInvoiceMatched.setEnabled(false); Grid matchedGrid;//from w w w .j a v a2 s .co m refreshMatched.addClickListener(new ClickListener() { private static final long serialVersionUID = -3610721151565496269L; @Override public void buttonClick(ClickEvent event) { refreshDataSources(); } }); IndexedContainer mcontainer = getEmptyContainer(); GeneratedPropertyContainer mpc = new GeneratedPropertyContainer(mcontainer); VerticalLayout matchedLayout = new VerticalLayout(); matchedGrid = new Grid(mpc); setRenderers(matchedGrid); fillMatchedRows(matchedGrid); // compute total costs float totalCosts = 0.0f; for (Object itemId : mpc.getItemIds()) totalCosts += ((Number) mpc.getContainerProperty(itemId, costCaption).getValue()).floatValue(); // compute total time in milliseconds long total = 0; for (Object itemId : mpc.getItemIds()) { long s = ((Date) mpc.getContainerProperty(itemId, startCaption).getValue()).getTime(); long e = ((Date) mpc.getContainerProperty(itemId, endCaption).getValue()).getTime(); total += e - s; } // set footer to contain total cost and time in hours:minutes FooterRow footer = matchedGrid.appendFooterRow(); FooterCell footerCellCost = footer.getCell(costCaption); footerCellCost.setText(String.format("%1$.2f total", totalCosts)); FooterCell footerCellEnd = footer.getCell(endCaption); footerCellEnd.setText(Formatter.toHoursAndMinutes(total)); // "%1$.0f hours" // Set up a filter for all columns HeaderRow filterRow = matchedGrid.appendHeaderRow(); addRowFilter(filterRow, deviceCaption, mcontainer, footer, mpc); addRowFilter(filterRow, kostenstelleCaption, mcontainer, footer, mpc); matchedLayout.setMargin(true); matchedLayout.setSpacing(true); // devicesGrid.setWidth("100%"); matchedGrid.setSizeFull(); matchedGrid.setSelectionMode(SelectionMode.SINGLE); matchedLayout.addComponent(matchedGrid); matchedGrid.setSelectionMode(SelectionMode.SINGLE); matchedGrid.addSelectionListener(new SelectionListener() { /** * */ private static final long serialVersionUID = -2683274060620429050L; @Override public void select(SelectionEvent event) { // Notification.show("Select row: " + grid.getSelectedRow() + " Name: " // + gpcontainer.getContainerProperty(grid.getSelectedRow(), nameCaption).getValue()); downloadInvoiceMatched.setEnabled(false); ReceiverPI = (String) mpc.getContainerProperty(matchedGrid.getSelectedRow(), nameCaption) .getValue(); createInvoiceMatched.setEnabled(true); } }); createInvoiceMatched.addClickListener(new ClickListener() { private File bill; private FileDownloader fileDownloader; @Override public void buttonClick(ClickEvent event) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); Paths.get(basepath, "WEB-INF/billingTemplates"); // System.out.println("Basepath: " + basepath); try { int setUserId = DBManager.getDatabaseInstance().findUserByFullName(ReceiverPI); if (setUserId > 0) { Billing billing = new Billing(Paths.get(basepath, "WEB-INF/billingTemplates").toFile(), "Angebot.tex"); UserBean user = setUserId > 0 ? DBManager.getDatabaseInstance().getUserById(setUserId) : null; billing.setReceiverPI(ReceiverPI); billing.setReceiverInstitution(user.getInstitute()); billing.setReceiverStreet(user.getStreet()); billing.setReceiverPostalCode(user.getPostcode()); billing.setReceiverCity(user.getCity()); billing.setSenderName("Dr. rer. nat. Stella Autenrieth"); billing.setSenderFunction("Leiterin"); billing.setSenderPostalCode("72076"); billing.setSenderCity("Tbingen"); billing.setSenderStreet("Otfried-Mller-Strae 10"); billing.setSenderPhone("+49 (0) 7071 29-83156"); billing.setSenderEmail("stella.autenrieth@med.uni-tuebingen.de"); billing.setSenderUrl("www.medizin.uni-tuebingen.de"); billing.setSenderFaculty("Medizinischen Fakultt"); if (user.getKostenstelle() != null) billing.setProjectDescription("Kostenstelle: " + user.getKostenstelle()); else billing.setProjectDescription("Keine kostenstelle verfgbar."); billing.setProjectShortDescription("Dieses Angebot beinhaltet jede Menge Extras."); if (user.getProject() != null) billing.setProjectNumber("Kostenstelle: " + user.getKostenstelle()); else billing.setProjectNumber("Keine project nummer verfgbar."); float cost = ((Number) mpc.getContainerProperty(matchedGrid.getSelectedRow(), costCaption) .getValue()).floatValue(); long s = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), startCaption) .getValue()).getTime(); long e = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), endCaption) .getValue()).getTime(); long timeFrame = e - s; Date start = ((Date) mpc.getContainerProperty(matchedGrid.getSelectedRow(), startCaption) .getValue()); SimpleDateFormat ft = new SimpleDateFormat("dd.MM.yyyy"); String date = ft.format(start); String description = "No Description is Available"; String time_frame = Formatter.toHoursAndMinutes(timeFrame); ArrayList<CostEntry> entries = new ArrayList<CostEntry>(); entries.add(billing.new CostEntry(date, time_frame, description, cost)); billing.setCostEntries(entries); float totalCosts = 0.0f; totalCosts = ((Number) mpc.getContainerProperty(matchedGrid.getSelectedRow(), costCaption) .getValue()).floatValue(); billing.setTotalCost(String.format("%1$.2f", totalCosts)); bill = billing.createPdf(); // System.out.println(bill.getAbsolutePath()); if (fileDownloader != null) downloadInvoiceMatched.removeExtension(fileDownloader); fileDownloader = new FileDownloader(new FileResource(bill)); fileDownloader.extend(downloadInvoiceMatched); downloadInvoiceMatched.setEnabled(true); showSuccessfulNotification("Congratulations!", "Invoice is created and available for download."); downloadInvoiceMatched.setEnabled(true); } else { createInvoiceMatched.setEnabled(false); downloadInvoiceMatched.setEnabled(false); showErrorNotification("No such user found!", "An error occured while trying to create the invoice. The common problem occurs to be: this no such user in the database."); } } catch (Exception e) { showErrorNotification("What the heck!", "An error occured while trying to create the invoice. The common problem occurs to be: this no such user or it can not run program 'pdflatex'."); e.printStackTrace(); } } }); matchedLayout.addComponent(refreshMatched); matchedLayout.addComponent(createInvoiceMatched); matchedLayout.addComponent(downloadInvoiceMatched); return matchedLayout; }
From source file:fi.aalto.drumbeat.drumbeatUI.DrumbeatinterfaceUI.java
License:Open Source License
@Override protected void init(VaadinRequest request) { String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/drumbeat_banner.jpg")); // Show the image in the application Image drumbeat_logo = new Image("Aalto University Drumbeat User Interface", resource); final VerticalLayout layout = new VerticalLayout(); setContent(layout);/* w ww . j a va 2s . c o m*/ layout.addComponent(drumbeat_logo); layout.setMargin(true); layout.addComponent(tabsheet); createTab_Sites(); createTab_Datasets(); createTab_Queries(); createTab_Links(); creatTab_Resources(); updateData(); listSites(); }
From source file:fi.semantum.strategia.Main.java
License:Open Source License
@Override protected void init(VaadinRequest request) { getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() { public void uriFragmentChanged(UriFragmentChangedEvent source) { applyFragment(source.getUriFragment(), true); }//from ww w .ja va2s .c o m }); String pathInfo = request.getPathInfo(); if (pathInfo.startsWith("/")) pathInfo = pathInfo.substring(1); if (pathInfo.endsWith("/")) pathInfo = pathInfo.substring(0, pathInfo.length() - 1); String databaseId = validatePathInfo(pathInfo); setWindowWidth(Page.getCurrent().getBrowserWindowWidth(), Page.getCurrent().getBrowserWindowHeight()); // Find the application directory String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); // Image as a file resource redResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_red.png")); greenResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_green.png")); blackResource = new FileResource(new File(basepath + "/WEB-INF/images/bullet_black.png")); mapMagnify = new FileResource(new File(basepath + "/WEB-INF/images/map_magnify.png")); abs = new AbsoluteLayout(); final VerticalLayout vs = new VerticalLayout(); vs.setSizeFull(); abs.addComponent(vs); setContent(abs); // This will set the login cookie Wiki.login(this); // Make sure that the printing directory exists new File(Main.baseDirectory(), "printing").mkdirs(); database = Database.load(this, databaseId); database.getOrCreateTag("Tavoite"); database.getOrCreateTag("Painopiste"); for (Strategiakartta map : Strategiakartta.enumerate(database)) { Strategiakartta parent = map.getPossibleParent(database); if (parent == null) uiState.setCurrentMap(parent); } if (uiState.getCurrentMap() == null) uiState.setCurrentMap(database.getRoot()); uiState.currentPosition = uiState.getCurrentMap(); uiState.currentItem = uiState.getCurrentMap(); setPollInterval(10000); addPollListener(new PollListener() { @Override public void poll(PollEvent event) { if (database.checkChanges()) { String curr = uiState.getCurrentMap().uuid; database = Database.load(Main.this, database.getDatabaseId()); uiState.setCurrentMap((Strategiakartta) database.find(curr)); Updates.updateJS(Main.this, false); } } }); js.addListener(new MapListener(this, false)); js2.addListener(new MapListener(this, true)); browser_.addListener(new BrowserListener() { @Override public void select(double x, double y, String uuid) { Base b = database.find(uuid); Actions.selectAction(Main.this, x, y, null, b); } @Override public void save(String name, Map<String, BrowserNodeState> states) { UIState state = getUIState().duplicate(name); state.browserStates = states; account.uiStates.add(state); Updates.update(Main.this, true); } }); Page.getCurrent().addBrowserWindowResizeListener(new BrowserWindowResizeListener() { @Override public void browserWindowResized(BrowserWindowResizeEvent event) { setWindowWidth(event.getWidth(), event.getHeight()); Updates.updateJS(Main.this, false); } }); modeLabel = new Label("Katselutila"); modeLabel.setWidth("95px"); modeLabel.addStyleName("viewMode"); mode = new Button(); mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); mode.addStyleName(ValoTheme.BUTTON_TINY); mode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Siirry tiedon sytttilaan".equals(mode.getDescription())) { mode.setDescription("Siirry katselutilaan"); mode.setIcon(FontAwesome.PENCIL); modeLabel.setValue("Sytttila"); modeLabel.removeStyleName("viewMode"); modeLabel.addStyleName("editMode"); UIState s = uiState.duplicate(Main.this); s.input = true; setFragment(s, true); } else { mode.setDescription("Siirry tiedon sytttilaan"); mode.setIcon(FontAwesome.EYE); modeLabel.setValue("Katselutila"); modeLabel.removeStyleName("editMode"); modeLabel.addStyleName("viewMode"); UIState s = uiState.duplicate(Main.this); s.input = false; setFragment(s, true); } } }); meterMode = new Button(); meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); meterMode.addStyleName(ValoTheme.BUTTON_TINY); meterMode.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if ("Vaihda toteumamittareihin".equals(meterMode.getDescription())) { meterMode.setDescription("Vaihda ennustemittareihin"); meterMode.setCaption("Toteuma"); UIState s = uiState.duplicate(Main.this); s.setActualMeters(); setFragment(s, true); } else { meterMode.setDescription("Vaihda toteumamittareihin"); meterMode.setCaption("Ennuste"); UIState s = uiState.duplicate(Main.this); s.setForecastMeters(); setFragment(s, true); } } }); pdf = new PDFButton(); pdf.setDescription("Tallenna kartta PDF-muodossa"); pdf.setIcon(FontAwesome.PRINT); pdf.addStyleName(ValoTheme.BUTTON_TINY); pdf.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.print(Main.this); } }); propertyExcelButton = new Button(); propertyExcelButton.setDescription("Tallenna tiedot Excel-tiedostona"); propertyExcelButton.setIcon(FontAwesome.PRINT); propertyExcelButton.addStyleName(ValoTheme.BUTTON_TINY); OnDemandFileDownloader dl = new OnDemandFileDownloader(new OnDemandStreamSource() { private static final long serialVersionUID = 981769438054780731L; File f; Date date = new Date(); @Override public InputStream getStream() { String uuid = UUID.randomUUID().toString(); File printing = new File(Main.baseDirectory(), "printing"); f = new File(printing, uuid + ".xlsx"); Workbook w = new XSSFWorkbook(); Sheet sheet = w.createSheet("Sheet1"); int row = 1; for (List<String> cells : propertyCells) { Row r = sheet.createRow(row++); for (int i = 0; i < cells.size(); i++) { String value = cells.get(i); r.createCell(i).setCellValue(value); } } try { FileOutputStream s = new FileOutputStream(f); w.write(s); s.close(); } catch (Exception e) { e.printStackTrace(); } try { return new FileInputStream(f); } catch (FileNotFoundException e) { e.printStackTrace(); } throw new IllegalStateException(); } @Override public void onRequest() { } @Override public long getFileSize() { return f.length(); } @Override public String getFileName() { return "Strategiakartta_" + Utils.dateString(date) + ".xlsx"; } }); dl.getResource().setCacheTime(0); dl.extend(propertyExcelButton); states = new ComboBox(); states.setWidth("250px"); states.addStyleName(ValoTheme.COMBOBOX_TINY); states.setInvalidAllowed(false); states.setNullSelectionAllowed(false); states.addValueChangeListener(statesListener); saveState = new Button(); saveState.setEnabled(false); saveState.setDescription("Tallenna nykyinen nkym"); saveState.setIcon(FontAwesome.BOOKMARK); saveState.addStyleName(ValoTheme.BUTTON_TINY); saveState.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { Utils.saveCurrentState(Main.this); } }); class SearchTextField extends TextField { public boolean hasFocus = false; } final SearchTextField search = new SearchTextField(); search.setWidth("100%"); search.addStyleName(ValoTheme.TEXTFIELD_TINY); search.addStyleName(ValoTheme.TEXTFIELD_BORDERLESS); search.setInputPrompt("hae vapaasanahaulla valitun asian alta"); search.setId("searchTextField"); search.addShortcutListener(new ShortcutListener("Shortcut Name", ShortcutAction.KeyCode.ENTER, null) { @Override public void handleAction(Object sender, Object target) { if (!search.hasFocus) return; String text = search.getValue().toLowerCase(); try { Map<String, String> content = new HashMap<String, String>(); List<String> hits = Lucene.search(database.getDatabaseId(), text + "*"); for (String uuid : hits) { Base b = database.find(uuid); if (b != null) { String report = ""; Map<String, String> map = b.searchMap(database); for (Map.Entry<String, String> e : map.entrySet()) { if (e.getValue().contains(text)) { if (!report.isEmpty()) report += ", "; report += e.getKey(); } } if (!report.isEmpty()) content.put(uuid, report); } } uiState.setCurrentFilter(new SearchFilter(Main.this, content)); Updates.updateJS(Main.this, false); switchToBrowser(); } catch (IOException e) { e.printStackTrace(); } } }); search.addFocusListener(new FocusListener() { @Override public void focus(FocusEvent event) { search.hasFocus = true; } }); search.addBlurListener(new BlurListener() { @Override public void blur(BlurEvent event) { search.hasFocus = false; } }); hallinnoi = new Button("Hallinnoi"); hallinnoi.setWidthUndefined(); hallinnoi.setVisible(false); hallinnoi.addStyleName(ValoTheme.BUTTON_TINY); hallinnoi.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { if (account.isAdmin()) { Utils.manage(Main.this); } } } }); tili = new Button("Kyttjtili"); tili.setWidthUndefined(); tili.setVisible(false); tili.addStyleName(ValoTheme.BUTTON_TINY); tili.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { Utils.modifyAccount(Main.this); } } }); duplicate = new Button("Avaa ikkunassa"); duplicate2 = new Button("Avaa alas"); duplicate.setWidthUndefined(); duplicate.addStyleName(ValoTheme.BUTTON_TINY); duplicate.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); if (model == null) { UIState s = uiState.duplicate(Main.this); s.reference = s.current; mapDialog = new Window(s.reference.getText(database), new VerticalLayout()); mapDialog.setWidth(dialogWidth()); mapDialog.setHeight(dialogHeight()); mapDialog.setResizable(true); mapDialog.setContent(js2Container); mapDialog.setVisible(true); mapDialog.setResizeLazy(false); mapDialog.addCloseListener(new CloseListener() { @Override public void windowClose(CloseEvent e) { duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); UIState s = uiState.duplicate(Main.this); mapDialog.close(); mapDialog = null; s.reference = null; setFragment(s, true); } }); mapDialog.addResizeListener(new ResizeListener() { @Override public void windowResized(ResizeEvent e) { Updates.updateJS(Main.this, false); } }); setFragment(s, true); addWindow(mapDialog); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } else { UIState s = uiState.duplicate(Main.this); if (mapDialog != null) { mapDialog.close(); mapDialog = null; } panelLayout.removeComponent(js2Container); s.reference = null; setFragment(s, true); duplicate.setCaption("Avaa ikkunassa"); duplicate2.setVisible(true); } } }); duplicate2.setWidthUndefined(); duplicate2.addStyleName(ValoTheme.BUTTON_TINY); duplicate2.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { MapVis model = js2.getModel(); assert (model == null); UIState s = uiState.duplicate(Main.this); s.reference = s.current; setFragment(s, true); panelLayout.addComponent(js2Container); duplicate.setCaption("Sulje referenssi"); duplicate2.setVisible(false); } }); login = new Button("Kirjaudu"); login.setWidthUndefined(); login.addStyleName(ValoTheme.BUTTON_TINY); login.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (account != null) { account = null; hallinnoi.setVisible(false); tili.setVisible(false); Updates.update(Main.this, true); login.setCaption("Kirjaudu"); } else { Login.login(Main.this); } } }); times = new ComboBox(); times.setWidth("130px"); times.addStyleName(ValoTheme.COMBOBOX_SMALL); times.addItem(Property.AIKAVALI_KAIKKI); times.addItem("2016"); times.addItem("2017"); times.addItem("2018"); times.addItem("2019"); times.select("2016"); times.setInvalidAllowed(false); times.setNullSelectionAllowed(false); times.addValueChangeListener(timesListener); final HorizontalLayout hl0 = new HorizontalLayout(); hl0.setWidth("100%"); hl0.setHeight("32px"); hl0.setSpacing(true); hl0.addComponent(pdf); hl0.setComponentAlignment(pdf, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(pdf, 0.0f); hl0.addComponent(propertyExcelButton); hl0.setComponentAlignment(propertyExcelButton, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(propertyExcelButton, 0.0f); hl0.addComponent(states); hl0.setComponentAlignment(states, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(states, 0.0f); hl0.addComponent(saveState); hl0.setComponentAlignment(saveState, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(saveState, 0.0f); hl0.addComponent(times); hl0.setComponentAlignment(times, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(times, 0.0f); hl0.addComponent(search); hl0.setComponentAlignment(search, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(search, 1.0f); hl0.addComponent(modeLabel); hl0.setComponentAlignment(modeLabel, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(modeLabel, 0.0f); hl0.addComponent(mode); hl0.setComponentAlignment(mode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(mode, 0.0f); hl0.addComponent(meterMode); hl0.setComponentAlignment(meterMode, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(meterMode, 0.0f); hl0.addComponent(hallinnoi); hl0.setComponentAlignment(hallinnoi, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(hallinnoi, 0.0f); hl0.addComponent(tili); hl0.setComponentAlignment(tili, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(tili, 0.0f); hl0.addComponent(duplicate); hl0.setComponentAlignment(duplicate, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate, 0.0f); hl0.addComponent(duplicate2); hl0.setComponentAlignment(duplicate2, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(duplicate2, 0.0f); hl0.addComponent(login); hl0.setComponentAlignment(login, Alignment.MIDDLE_LEFT); hl0.setExpandRatio(login, 0.0f); propertiesPanel = new Panel(); propertiesPanel.setSizeFull(); properties = new VerticalLayout(); properties.setSpacing(true); properties.setMargin(true); propertiesPanel.setContent(properties); propertiesPanel.setVisible(false); tags = new VerticalLayout(); tags.setSpacing(true); Updates.updateTags(this); AbsoluteLayout tabs = new AbsoluteLayout(); tabs.setSizeFull(); { panel = new Panel(); panel.addStyleName(ValoTheme.PANEL_BORDERLESS); panel.setSizeFull(); panel.setId("mapContainer1"); panelLayout = new VerticalLayout(); panelLayout.addComponent(js); panelLayout.setHeight("100%"); js2Container = new VerticalLayout(); js2Container.setHeight("100%"); js2Container.addComponent(new Label("<hr />", ContentMode.HTML)); js2Container.addComponent(js2); panel.setContent(panelLayout); tabs.addComponent(panel); } wiki = new BrowserFrame(); wiki.setSource(new ExternalResource(Wiki.wikiAddress() + "/")); wiki.setWidth("100%"); wiki.setHeight("100%"); { wiki_ = new VerticalLayout(); wiki_.setSizeFull(); Button b = new Button("Palaa sovellukseen"); b.setWidth("100%"); b.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { applyFragment(backFragment, true); String content = Wiki.get(wikiPage); if (content == null) return; int first = content.indexOf("<rev contentformat"); if (first == -1) return; content = content.substring(first); int term = content.indexOf(">"); content = content.substring(term + 1); int end = content.indexOf("</rev>"); content = content.substring(0, end); if (wikiBase.modifyMarkup(Main.this, content)) { Updates.update(Main.this, true); } } }); wiki_.addComponent(b); wiki_.addComponent(wiki); wiki_.setVisible(false); wiki_.setExpandRatio(b, 0.0f); wiki_.setExpandRatio(wiki, 1.0f); tabs.addComponent(wiki_); } hs = new HorizontalSplitPanel(); hs.setSplitPosition(0, Unit.PIXELS); hs.setHeight("100%"); hs.setWidth("100%"); browser = new VerticalLayout(); browser.setSizeFull(); HorizontalLayout browserWidgets = new HorizontalLayout(); browserWidgets.setWidth("100%"); hori = new Button(); hori.setDescription("Nyt asiat taulukkona"); hori.setEnabled(true); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.addStyleName(ValoTheme.BUTTON_TINY); hori.addClickListener(new ClickListener() { boolean right = false; @Override public void buttonClick(ClickEvent event) { if (right) { hs.setSplitPosition(0, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_RIGHT); hori.setDescription("Nyt asiat taulukkona"); right = false; } else { hs.setSplitPosition(windowWidth / 2, Unit.PIXELS); hori.setIcon(FontAwesome.ARROW_LEFT); hori.setDescription("Piilota taulukko"); right = true; } } }); more = new Button(); more.setDescription("Laajenna nytettvien asioiden joukkoa"); more.setIcon(FontAwesome.PLUS_SQUARE); more.addStyleName(ValoTheme.BUTTON_TINY); more.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { uiState.level++; Updates.updateJS(Main.this, false); if (uiState.level >= 2) less.setEnabled(true); } }); less = new Button(); less.setDescription("Supista nytettvien asioiden joukkoa"); less.setIcon(FontAwesome.MINUS_SQUARE); less.addStyleName(ValoTheme.BUTTON_TINY); less.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.level > 1) { uiState.level--; Updates.updateJS(Main.this, false); } if (uiState.level <= 1) less.setEnabled(false); } }); reportAllButton = new Button(); reportAllButton.setCaption("Nkyvt tulokset"); reportAllButton.addStyleName(ValoTheme.BUTTON_TINY); reportAllButton.addClickListener(new ClickListener() { @Override public void buttonClick(ClickEvent event) { if (uiState.reportAll) { reportAllButton.setCaption("Nkyvt tulokset"); uiState.reportAll = false; } else { reportAllButton.setCaption("Kaikki tulokset"); uiState.reportAll = true; } Updates.updateJS(Main.this, false); } }); reportStatus = new Label("0 tulosta."); reportStatus.setWidth("100px"); filter = new ComboBox(); filter.setWidth("100%"); filter.addStyleName(ValoTheme.COMBOBOX_SMALL); filter.setInvalidAllowed(false); filter.setNullSelectionAllowed(false); filter.addValueChangeListener(filterListener); browserWidgets.addComponent(hori); browserWidgets.setComponentAlignment(hori, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(hori, 0.0f); browserWidgets.addComponent(more); browserWidgets.setComponentAlignment(more, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(more, 0.0f); browserWidgets.addComponent(less); browserWidgets.setComponentAlignment(less, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(less, 0.0f); browserWidgets.addComponent(reportAllButton); browserWidgets.setComponentAlignment(reportAllButton, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportAllButton, 0.0f); browserWidgets.addComponent(reportStatus); browserWidgets.setComponentAlignment(reportStatus, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(reportStatus, 0.0f); browserWidgets.addComponent(filter); browserWidgets.setComponentAlignment(filter, Alignment.MIDDLE_LEFT); browserWidgets.setExpandRatio(filter, 1.0f); browser.addComponent(browserWidgets); browser.addComponent(hs); browser.setExpandRatio(browserWidgets, 0.0f); browser.setExpandRatio(hs, 1.0f); browser.setVisible(false); tabs.addComponent(browser); { gridPanelLayout = new VerticalLayout(); gridPanelLayout.setMargin(false); gridPanelLayout.setSpacing(false); gridPanelLayout.setSizeFull(); hs.addComponent(gridPanelLayout); } CssLayout browserLayout = new CssLayout(); browserLayout.setSizeFull(); browserLayout.addComponent(browser_); hs.addComponent(browserLayout); tabs.addComponent(propertiesPanel); vs.addComponent(hl0); vs.addComponent(tabs); vs.setExpandRatio(hl0, 0.0f); vs.setExpandRatio(tabs, 1.0f); // Ground state fragments.put("", uiState); setCurrentItem(uiState.currentItem, (Strategiakartta) uiState.currentItem); }
From source file:foo.MyVaadinApplication.java
License:Apache License
/** * Initializes the top banner// w ww . ja va 2 s. com * * @return initialized top banner */ private Panel initTopBanner() { Panel topBanner = new Panel(); topBanner.setWidth("100%"); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resource = new FileResource(new File(basepath + "/WEB-INF/images/topBannerPlaceholder.png")); Embedded image = new Embedded("", resource); VerticalLayout v = new VerticalLayout(); v.addComponent(image); topBanner.setContent(v); return topBanner; }
From source file:foo.MyVaadinApplication.java
License:Apache License
/** * Initializes the bottom banner/* w w w . ja v a 2 s. co m*/ * * @return initialized bottom banner */ private Panel initBottomBanner() { Panel bottomBanner = new Panel(); bottomBanner.setWidth("100%"); String basepath = VaadinService.getCurrent().getBaseDirectory().getAbsolutePath(); FileResource resource = new FileResource( new File(basepath + "/WEB-INF/images/bottomBannerPlaceholder.png")); Embedded image = new Embedded("", resource); VerticalLayout v = new VerticalLayout(); v.addComponent(image); bottomBanner.setContent(v); return bottomBanner; }
From source file:io.mateu.ui.vaadin.framework.MyUI.java
License:Apache License
/** * abre el dilogo para cambiar la foto/*from ww w . j a va2 s. c o m*/ * * */ private void uploadFoto() { // Create a sub-window and set the content Window subWindow = new Window("My photo"); subWindow.setWidth("475px"); FormLayout f = new FormLayout(); f.setMargin(true); Label e = new Label(); Image image = new Image(); class MyUploader implements Upload.Receiver, Upload.SucceededListener { File file; public File getFile() { return file; } public OutputStream receiveUpload(String fileName, String mimeType) { // Create and return a file output stream System.out.println("receiveUpload(" + fileName + "," + mimeType + ")"); FileOutputStream os = null; if (fileName != null && !"".equals(fileName)) { long id = fileId++; String extension = ".tmp"; if (fileName == null || "".equals(fileName.trim())) fileName = "" + id + extension; if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")); } File temp = null; try { temp = File.createTempFile(fileName, extension); os = new FileOutputStream(file = temp); } catch (IOException e) { e.printStackTrace(); } } return os; } public void uploadSucceeded(Upload.SucceededEvent event) { // Show the uploaded file in the image viewer image.setSource(new FileResource(file)); System.out.println("uploadSucceeded(" + file.getAbsolutePath() + ")"); } public FileLocator getFileLocator() throws IOException { String extension = ".tmp"; String fileName = file.getName(); if (file.getName() == null || "".equals(file.getName().trim())) fileName = "" + getId(); if (fileName.lastIndexOf(".") < fileName.length() - 1) { extension = fileName.substring(fileName.lastIndexOf(".")); fileName = fileName.substring(0, fileName.lastIndexOf(".")).replaceAll(" ", "_"); } java.io.File temp = (System.getProperty("tmpdir") == null) ? java.io.File.createTempFile(fileName, extension) : new java.io.File(new java.io.File(System.getProperty("tmpdir")), fileName + extension); System.out.println("java.io.tmpdir=" + System.getProperty("java.io.tmpdir")); System.out.println("Temp file : " + temp.getAbsolutePath()); if (System.getProperty("tmpdir") == null || !temp.exists()) { System.out.println("writing temp file to " + temp.getAbsolutePath()); Files.copy(file, temp); } else { System.out.println("temp file already exists"); } String baseUrl = System.getProperty("tmpurl"); URL url = null; try { if (baseUrl == null) { url = file.toURI().toURL(); } else url = new URL(baseUrl + "/" + file.getName()); } catch (MalformedURLException e) { e.printStackTrace(); } return new FileLocator(0, file.getName(), url.toString(), file.getAbsolutePath()); } } ; MyUploader receiver = new MyUploader(); Upload upload = new Upload(null, receiver); //upload.setImmediateMode(false); upload.addSucceededListener(receiver); f.addComponent(image); f.addComponent(upload); f.addComponent(e); VerticalLayout v = new VerticalLayout(); v.addComponent(f); HorizontalLayout footer = new HorizontalLayout(); footer.setWidth("100%"); footer.setSpacing(true); footer.addStyleName(ValoTheme.WINDOW_BOTTOM_TOOLBAR); Label footerText = new Label(""); footerText.setSizeUndefined(); Button ok = new Button("Change it!", new ClickListener() { @Override public void buttonClick(ClickEvent clickEvent) { e.setValue("Changing photo..."); try { FileLocator loc = receiver.getFileLocator(); io.mateu.ui.core.client.app.MateuUI.getBaseService() .updateFoto(getApp().getUserData().getLogin(), loc, new AsyncCallback<Void>() { @Override public void onFailure(Throwable caught) { e.setValue("" + caught.getClass().getName() + ": " + caught.getMessage()); } @Override public void onSuccess(Void result) { e.setValue("OK!"); getApp().getUserData().setPhoto(loc.getUrl()); foto = (getApp().getUserData().getPhoto() != null) ? new ExternalResource(getApp().getUserData().getPhoto()) : new ClassResource("profile-pic-300px.jpg"); subWindow.close(); refreshSettings(); } }); } catch (IOException e1) { e1.printStackTrace(); io.mateu.ui.core.client.app.MateuUI.alert("" + e1.getClass().getName() + ":" + e1.getMessage()); } } }); ok.addStyleName(ValoTheme.BUTTON_PRIMARY); ok.setClickShortcut(ShortcutAction.KeyCode.ENTER); Button cancel = new Button("Cancel"); footer.addComponents(footerText, ok); //, cancel); footer.setExpandRatio(footerText, 1); v.addComponent(footer); subWindow.setContent(v); // Center it in the browser window subWindow.center(); subWindow.setModal(true); // Open it in the UI UI.getCurrent().addWindow(subWindow); upload.focus(); }