Example usage for com.vaadin.server FileResource FileResource

List of usage examples for com.vaadin.server FileResource FileResource

Introduction

In this page you can find the example usage for com.vaadin.server FileResource FileResource.

Prototype

public FileResource(File sourceFile) 

Source Link

Document

Creates a new file resource for providing given file for client terminals.

Usage

From source file:com.cerebro.gorgone.landingpage.SignInWindow.java

private Component setFirstStep() {
    VerticalLayout firstStep = new VerticalLayout();
    firstStep.setMargin(true);/*from  ww  w . j ava2 s.co m*/
    // Body
    HorizontalLayout body = new HorizontalLayout();
    FormLayout datiIniziali = new FormLayout();
    TextField nomePG = new TextField("Nome del Personaggio");
    nomePG.setRequired(true);
    TextField cognomePG = new TextField("Cognome del Personaggio");
    cognomePG.setRequired(true);
    OptionGroup sessoPG = new OptionGroup("Sesso del Personaggio");
    sessoPG.setRequired(true);
    sessoPG.addItems("Maschio", "Femmina");
    ComboBox razzaPG = new ComboBox("Razza");
    razzaPG.setRequired(true);
    Slider age = new Slider("Et");
    age.setImmediate(true);
    age.setWidth("200px");
    age.setVisible(false);
    HorizontalLayout ageDescription = new HorizontalLayout();
    ageDescription.setHeight("250px");
    Label ageText = new Label("Valore dell'et: ");
    Label ageValue = new Label(age.getValue().toString());
    Label periodoVita = new Label("");
    ageDescription.addComponents(ageText, ageValue, periodoVita);
    age.addValueChangeListener((Property.ValueChangeEvent event) -> {
        System.out.println("Valore: " + age.getValue().toString());
        ageValue.setValue(age.getValue().toString());
        Double value = (100 * (age.getValue()) / (age.getMax()));
        if (value < 14) {
            periodoVita.setValue("Bambino");
        } else if (value > 14 && value < 24) {
            periodoVita.setValue("Adolescenza");
        } else if (value > 24 && value < 73) {
            periodoVita.setValue("Et adulta");
        } else if (value > 73) {
            periodoVita.setValue("Et anziana");
        }
    });
    ageDescription.addComponents(ageText, ageValue, periodoVita);
    ageDescription.setVisible(false);
    datiIniziali.addComponents(nomePG, cognomePG, sessoPG, razzaPG, age, ageDescription);
    Panel descrizioneRazza = new Panel();
    CssLayout descrizioneRazzaContent = new CssLayout();
    descrizioneRazza.setWidth("400px");
    descrizioneRazza.setHeight("500px");
    descrizioneRazza.setContent(descrizioneRazzaContent);
    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_races = new TableQuery(DatabaseTables.RACES_TABLE, connPool);
    tq_races.setVersionColumn(DatabaseTables.RACES_VERSION);
    SQLContainer container_races = null;
    try {
        container_races = new SQLContainer(tq_races);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    razzaPG.setContainerDataSource(container_races);
    razzaPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    razzaPG.setItemCaptionPropertyId(DatabaseTables.RACES_NAME);
    razzaPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (razzaPG.getValue() != null) {
                logger.info("Razza selezionata: " + razzaPG.getValue());
                age.setVisible(true);
                ageDescription.setVisible(true);
                descrizioneRazzaContent.removeAllComponents();
                Item item = razzaPG.getContainerDataSource().getItem(razzaPG.getValue());
                race = (String) item.getItemProperty(DatabaseTables.RACES_NAME).getValue();
                Label nameRace = new Label(race);
                FileResource imageSrc = new FileResource(
                        new File(MyUI.basePath + item.getItemProperty(DatabaseTables.RACES_IMAGE).getValue()));
                Image imageRace = new Image(null, imageSrc);
                imageRace.setWidth("200px");
                Label descriptionRace = new Label(
                        (String) item.getItemProperty(DatabaseTables.RACES_DESCRIPTION).getValue(),
                        ContentMode.HTML);
                min_age = (int) item.getItemProperty(DatabaseTables.RACES_MIN_AGE).getValue();
                max_age = (int) item.getItemProperty(DatabaseTables.RACES_MAX_AGE).getValue();
                age.setMin(min_age);
                age.setMax(max_age);
                strenght = (int) item.getItemProperty(DatabaseTables.RACES_STRENGHT).getValue();
                resistance = (int) item.getItemProperty(DatabaseTables.RACES_RESISTANCE).getValue();
                agility = (int) item.getItemProperty(DatabaseTables.RACES_AGILITY).getValue();
                intelligence = (int) item.getItemProperty(DatabaseTables.RACES_INTELLIGENCE).getValue();
                wisdom = (int) item.getItemProperty(DatabaseTables.RACES_WISDOM).getValue();
                charm = (int) item.getItemProperty(DatabaseTables.RACES_CHARM).getValue();
                Label min_ageL = new Label("Et minima: " + min_age);
                Label max_ageL = new Label("Et masima " + max_age);
                //                Panel levels = new Panel();
                //                VerticalLayout levelsContent = new VerticalLayout();
                //                levels.setContent(levelsContent);
                //                Label strenghtL = new Label("Forza: " + strenght);
                //                levelsContent.addComponents(strenghtL);

                String levelTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>"
                        + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght + "</td>" + "<td>"
                        + resistance + "</td>" + "<td>" + agility + "</td>" + "<td>" + intelligence + "</td>"
                        + "<td>" + wisdom + "</td>" + "<td>" + charm + "</td>" + "</tr></table>";
                Label levels = new Label(levelTable, ContentMode.HTML);

                descrizioneRazzaContent.addComponents(nameRace, imageRace, descriptionRace, min_ageL, max_ageL,
                        levels);
            }
        }
    });

    body.addComponents(datiIniziali, descrizioneRazza);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        user.setNomePG(nomePG.getValue());
        user.setCognomePG(cognomePG.getValue());
        user.setSessoPG(sessoPG.getValue().toString());
        user.setRazzaPG(race);
        user.setEtaPG(age.getValue().toString());
        user.setForzaPG(strenght);
        user.setResistenzaPG(resistance);
        user.setAgilitaPG(agility);
        user.setIntelligenzaPG(intelligence);
        user.setSaggezzaPG(wisdom);
        user.setCarismaPG(charm);
        this.setContent(setSecondStep());
    });
    footer.addComponents(next, createCancelButton());
    firstStep.addComponents(setHeader("2/4"), body, footer);
    return firstStep;
}

From source file:com.cerebro.gorgone.landingpage.SignInWindow.java

private Component setSecondStep() {
    VerticalLayout secondStep = new VerticalLayout();
    HorizontalLayout body = new HorizontalLayout();
    Panel sx = new Panel();
    VerticalLayout sxContent = new VerticalLayout();
    sx.setContent(sxContent);/*from www.  ja v  a2 s. c om*/
    Label welcome = null;
    if (user.getSessoPG().equals("Maschio")) {
        welcome = new Label("Benvenuto: " + user.getNomePG() + "!");
    } else if (user.getSessoPG().equals("Femmina")) {
        welcome = new Label("Benvenuta: " + user.getNomePG() + "!");
    }
    ComboBox carrieraPG = new ComboBox("Scegli la tua carriera:");
    carrieraPG.isRequired();
    Panel careerDescription = new Panel();
    CssLayout careerDescrContent = new CssLayout();
    careerDescription.setContent(careerDescrContent);
    sxContent.addComponents(welcome, carrieraPG, careerDescription);

    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_career = new TableQuery(DatabaseTables.CAREER_TABLE, connPool);
    tq_career.setVersionColumn(DatabaseTables.CAREER_VERSION);
    SQLContainer container_career = null;
    try {
        container_career = new SQLContainer(tq_career);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    carrieraPG.setContainerDataSource(container_career);
    carrieraPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    carrieraPG.setItemCaptionPropertyId(DatabaseTables.CAREER_NAME);
    carrieraPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (carrieraPG.getValue() != null) {
                logger.info("Carriera: " + carrieraPG.getValue().toString());
                careerDescrContent.removeAllComponents();
                Item item = (Item) carrieraPG.getContainerDataSource().getItem(carrieraPG.getValue());
                career = (String) item.getItemProperty(DatabaseTables.CAREER_NAME).getValue();
                Label careerName = new Label(career);
                FileResource imageSrc = new FileResource(
                        new File(MyUI.basePath + item.getItemProperty(DatabaseTables.CAREER_IMAGE).getValue()));
                Image imageCareer = new Image(null, imageSrc);
                imageCareer.setWidth("200px");
                Label careerDescription = new Label(item.getItemProperty(DatabaseTables.CAREER_DESCRIPTION),
                        ContentMode.HTML);
                strenght_car = (int) item.getItemProperty(DatabaseTables.CAREER_STRENGTH).getValue();
                resistance_car = (int) item.getItemProperty(DatabaseTables.CAREER_RESISTANCE).getValue();
                agility_car = (int) item.getItemProperty(DatabaseTables.CAREER_AGILITY).getValue();
                intelligence_car = (int) item.getItemProperty(DatabaseTables.CAREER_INTELLIGENCE).getValue();
                wisdom_car = (int) item.getItemProperty(DatabaseTables.CAREER_WISDOM).getValue();
                charm_car = (int) item.getItemProperty(DatabaseTables.CAREER_CHARM).getValue();
                String modsTable = "<table><tr><td>Forza</td><td>Resistenza</td><td>Agilit</td><td>Intelligenza</td>"
                        + "<td>Saggezza</td><td>Carisma</td></tr><tr>" + "<td>" + strenght_car + "</td>"
                        + "<td>" + resistance_car + "</td>" + "<td>" + agility_car + "</td>" + "<td>"
                        + intelligence_car + "</td>" + "<td>" + wisdom_car + "</td>" + "<td>" + charm_car
                        + "</td>" + "</tr></table>";
                Label mods = new Label(modsTable, ContentMode.HTML);
                careerDescrContent.addComponents(careerName, imageCareer, careerDescription, mods);
            }

        }

    });

    Panel dx = new Panel();
    VerticalLayout dxContent = new VerticalLayout();
    dx.setContent(dxContent);
    ComboBox orientamentoPG = new ComboBox("Scegli il tuo orientamento:");
    orientamentoPG.isRequired();
    Panel orientamentoDescription = new Panel();
    CssLayout orientamentoDescrContent = new CssLayout();
    orientamentoDescription.setContent(orientamentoDescrContent);
    dxContent.addComponents(orientamentoPG, orientamentoDescription);
    //  Dettagli di popolazione e comportamento ComboBox
    TableQuery tq_orientamento = new TableQuery(DatabaseTables.MORALCODE_TABLE, connPool);
    tq_orientamento.setVersionColumn(DatabaseTables.MORALCODE_VERSION);
    SQLContainer container_orientamento = null;
    try {
        container_orientamento = new SQLContainer(tq_orientamento);
    } catch (Exception ex) {
        logger.error(ex.getMessage());
    }
    orientamentoPG.setContainerDataSource(container_orientamento);
    orientamentoPG.setItemCaptionMode(AbstractSelect.ItemCaptionMode.PROPERTY);
    orientamentoPG.setItemCaptionPropertyId(DatabaseTables.MORALCODE_TENDENCY);
    orientamentoPG.addValueChangeListener(new Property.ValueChangeListener() {
        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            if (orientamentoPG.getValue() != null) {
                logger.info("Orientamento: " + orientamentoPG.getValue().toString());
                orientamentoDescrContent.removeAllComponents();
                Item item = (Item) orientamentoPG.getContainerDataSource().getItem(orientamentoPG.getValue());
                moralCode = (String) item.getItemProperty(DatabaseTables.MORALCODE_TENDENCY).getValue();
                Label orientamentoName = new Label(moralCode);
                FileResource imageSrc = new FileResource(new File(
                        MyUI.basePath + item.getItemProperty(DatabaseTables.MORALCODE_IMAGE).getValue()));
                Image imageTendency = new Image(null, imageSrc);
                imageTendency.setWidth("200px");
                Label orientamentoDescription = new Label(
                        item.getItemProperty(DatabaseTables.MORALCODE_DESCRIPTION), ContentMode.HTML);

                orientamentoDescrContent.addComponents(orientamentoName, imageTendency,
                        orientamentoDescription);
            }

        }

    });

    body.addComponents(sx, dx);
    CssLayout footer = new CssLayout();
    Button next = new Button("Avanti ->");
    next.addClickListener((Button.ClickEvent event) -> {
        user.setCarrieraPG(career);
        // Gestire modificatori
        user.setForzaPG(user.getForzaPG() + strenght_car);
        user.setResistenzaPG(user.getResistenzaPG() + resistance_car);
        user.setAgilitaPG(user.getAgilitaPG() + agility_car);
        user.setIntelligenzaPG(user.getIntelligenzaPG() + intelligence_car);
        user.setSaggezzaPG(user.getSaggezzaPG() + wisdom_car);
        user.setCarismaPG(user.getCarismaPG() + charm_car);
        user.setOrientamentoPG(moralCode);
        this.setContent(setThirdStep());
    });
    footer.addComponents(next, createCancelButton());
    secondStep.addComponents(setHeader("3/4"), body, footer);
    return secondStep;
}

From source file:com.cerebro.provevaadin.Equipment.java

public Equipment() {
    GridLayout contentSx = new GridLayout(15, 18);
    contentSx.setId("equip_body");
    contentSx.setHeight("600px");
    contentSx.setWidth("300px");

    FileResource helmetFile = new FileResource(new File(basepath + "red.png"));
    Image helmet = new Image("Helmet", helmetFile);
    helmet.setHeight("100px");
    contentSx.addComponent(helmet, 8, 0);

    sinistra.setContent(contentSx);//from  w w w.  j  av a2 s .c  o m
    //        root.setWidth("300px");
    //        root.setHeight("600px");
    //        
    //        FileResource bodyMaleFile = new FileResource(new File(basepath + "body-male.jpg"));
    //        FileResource helmetFile = new FileResource(new File(basepath + "red.png"));
    //        
    //        Image image = new Image("MaleBody", bodyMaleFile);
    //        image.setWidth(root.getWidth(), root.getWidthUnits());
    //        Image helmet = new Image("Helmet", helmetFile);
    //        helmet.setHeight("100px");
    //        
    //        root.addComponent(image, "left: 0px; top: 0px;");
    //        root.addComponent(helmet, "left: 50%; top: 100px");
    //        
    //        sinistra.setContent(root);
    //        
    //        
    //        destra.setContent(rootDx);
    //        
    this.addComponents(sinistra, destra);
}

From source file:com.cms.utils.DataUtil.java

License:Open Source License

/**
 *
 * @param file//from   w w  w .  j  av  a2  s .  co  m
 * @param iSheet
 * @param iBeginRow
 * @param iFromCol
 * @param iToCol
 * @param rowBack
 * @param lstValidateCells
 * @return
 */
public static List isValidExcells(String mimeType, File file, int iSheet, int iBeginRow, int iFromCol,
        int iToCol, int rowBack, List<ValidateCells> lstValidateCells) {
    String fileName = file.getName();
    fileName = removeDotInteger(fileName);
    boolean isCopySheet = true;
    File fileError = null;
    Map<String, String> mapsNameError = new HashMap<>();
    List lst = null;
    try {
        if (mimeType.equalsIgnoreCase(Constants.FORMATFILE.EXCEL_XLSX)) { // xlsx
            lst = ExcelReaderXLSX.importExcel(file, iSheet, iBeginRow, iFromCol, iToCol, rowBack);
        } else if (mimeType.equalsIgnoreCase(Constants.FORMATFILE.EXCEL_XLS)) { // xls
            lst = ExcelReader.importExcel(file, iSheet, iBeginRow, iFromCol, iToCol, rowBack);
        }
        //If lst null return
        if (lst == null) {
            return lst;
        }
        String error = "";
        ValidateCells validateCells = null;
        int index = 0;
        if (iBeginRow == 0) {
            index = 1;
        } else {
            index = 0;
        }
        int rowErr = 0;
        Object[] temp;
        List<String> lstReturn = Lists.newArrayList();
        for (int i = index, size = lst.size(); i < size; i++) {
            temp = (Object[]) lst.get(i);
            if (checkObjectNull(temp)) {
                //                    lst.remove(temp);
                //                    i--;
                //                    continue;
                if (i == 0) {
                    lst = Lists.newArrayList();
                }
                break;
            }
            error = "";
            for (int j = 0; j < lstValidateCells.size(); j++) {
                validateCells = lstValidateCells.get(j);
                if (validateCells.getPattern() != null) {
                    error += DataUtil.validCell(i, j, (String) temp[j], validateCells.getType(),
                            validateCells.isIsNotNull(), validateCells.getPattern());
                } else {
                    lstReturn = DataUtil.validCell(i, j, (String) temp[j], validateCells.getType(),
                            validateCells.isIsNotNull(), validateCells.getLength());
                    error += lstReturn.get(0);
                    temp[j] = lstReturn.get(1);
                }
            }
            if (!isStringNullOrEmpty(error)) {
                rowErr = i + iBeginRow;
                mapsNameError.put(rowErr + "", error);
            }
        }

        if (!mapsNameError.isEmpty()) {
            //
            FileInputStream flieInput = new FileInputStream(file);
            XSSFWorkbook workbookIp = null;
            String fileCreate = fileName + "_Error.xlsx";
            FileOutputStream fileOut = new FileOutputStream(fileCreate);
            XSSFWorkbook workbookEp = new XSSFWorkbook();
            XSSFSheet worksheetEp = workbookEp.createSheet("Thong_Tin_Loi");
            XSSFCellStyle cellStyle = null;
            //
            if (isCopySheet) {
                if (mimeType.equalsIgnoreCase(Constants.FORMATFILE.EXCEL_XLSX)) { // xlsx
                    workbookIp = new XSSFWorkbook(flieInput);
                } else if (mimeType.equalsIgnoreCase(Constants.FORMATFILE.EXCEL_XLS)) { // xls
                    HSSFWorkbook hSSFWorkbook = new HSSFWorkbook(flieInput);
                    workbookIp = ExcelReaderXLSX.convertWorkbookHSSFToXSSF(hSSFWorkbook);
                }
                XSSFSheet worksheetIp = workbookIp.getSheetAt(iSheet);
                ExcelReaderXLSX.copySheets(worksheetEp, worksheetIp, iToCol);
                //
                cellStyle = CommonUtils.styleCell(workbookEp);
                isCopySheet = false;
            }
            for (Map.Entry<String, String> entrySet : mapsNameError.entrySet()) {
                String key = entrySet.getKey();
                String value = entrySet.getValue();
                int row = Integer.valueOf(key);
                XSSFRow row5 = worksheetEp.getRow(row);
                if (row5 != null) {
                    XSSFCell cellB1 = row5.createCell(iToCol + 1);
                    cellB1.setCellValue(value);
                    cellB1.setCellStyle(cellStyle);
                }
            }
            workbookEp.write(fileOut);
            fileOut.flush();
            fileOut.close();
            fileError = new File(fileCreate);
            Resource resource = new FileResource(fileError);
            Page.getCurrent().open(resource, null, false);
            lst = null;
            fileError.deleteOnExit();
        }

    } catch (Exception e) {
        e.printStackTrace();
        ;
        lst = null;
    }
    return lst;
}

From source file:com.cms.view.ExportContractFromTaxCode.java

public void doExportExcel(List<CustomerTHAPDTO> lstCustomer) {
    if (!DataUtil.isListNullOrEmpty(lstCustomer)) {
        ExportExcell exportExcell = null;

        String fileName = Constants.PATH_EXPORT + "Danh sach khach hang" + ".xlsx";
        try {/*  w  w  w  .ja v a  2s .  co m*/
            exportExcell = new ExportExcell(fileName);
        } catch (FileNotFoundException ex) {
            ex.printStackTrace();
        }

        //Khoi tao dinh dang fomat cho cell
        List<FormatExcell> formatExcells = new ArrayList<>();

        formatExcells.add(
                new FormatExcell("receiveInfoDate", null, FormatExcell.CellAlign.ALIGN_CENTER, 3000, true));
        formatExcells.add(new FormatExcell("taxCode", null, FormatExcell.CellAlign.ALIGN_CENTER, 3000, true));
        formatExcells.add(new FormatExcell("name", null, FormatExcell.CellAlign.ALIGN_LEFT, 10000, true));
        formatExcells
                .add(new FormatExcell("officeAddress", null, FormatExcell.CellAlign.ALIGN_LEFT, 5000, true));
        formatExcells.add(new FormatExcell("email", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("contactName", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("contactPhone", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("deployAddress", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("priceInfoCode", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("provider", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("contractType", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("paymentAmount", null, FormatExcell.CellAlign.ALIGN_RIGHT, 3000,
                true, FormatExcell.DOUBLE_TYPE));
        formatExcells.add(new FormatExcell("discount", null, FormatExcell.CellAlign.ALIGN_RIGHT, 3000, true,
                FormatExcell.DOUBLE_TYPE));
        formatExcells.add(new FormatExcell("receivableBalance", null, FormatExcell.CellAlign.ALIGN_RIGHT, 3000,
                true, FormatExcell.DOUBLE_TYPE));
        formatExcells.add(new FormatExcell("discountedBack", null, FormatExcell.CellAlign.ALIGN_RIGHT, 3000,
                true, FormatExcell.DOUBLE_TYPE));
        formatExcells.add(new FormatExcell("payments", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("paymentStatus", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("fileStatus", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("codeCOD", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells
                .add(new FormatExcell("invoiceStatus", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));
        formatExcells.add(new FormatExcell("notes", null, FormatExcell.CellAlign.ALIGN_LEFT, 3000, true));

        exportExcell.buildSheet("Danh sach khach hang", lstCustomer, formatExcells, "customer.thap");

        exportExcell.writeFileOutputStream();
        File file = new File(fileName);
        Resource resource = new FileResource(file);
        Page.getCurrent().open(resource, null, false);
    }
}

From source file:com.esofthead.mycollab.vaadin.resources.file.VaadinFileResource.java

License:Open Source License

@Override
public Resource getImagePreviewResource(String documentPath, Resource failOverSource) {
    StorageConfiguration storageConfiguration = StorageManager.getConfiguration();
    File docFile = new File(storageConfiguration.getResourcePath(documentPath));
    return (docFile.exists()) ? new FileResource(docFile) : failOverSource;
}

From source file:com.esofthead.mycollab.vaadin.resources.file.VaadinFileResource.java

License:Open Source License

@Override
public Resource getLogoResource(String logoId, int size) {
    FileStorageConfiguration fileStorageConfiguration = (FileStorageConfiguration) StorageManager
            .getConfiguration();//from  ww  w.j a v a  2s  . c  o m
    File logoFile = fileStorageConfiguration.getLogoFile(logoId, size);
    return (logoFile != null) ? new FileResource(logoFile) : MyCollabResource.newResource("icons/logo.png");
}

From source file:com.esofthead.mycollab.vaadin.resources.file.VaadinFileResource.java

License:Open Source License

@Override
public Resource getAvatarResource(String avatarId, int size) {
    FileStorageConfiguration fileStorageConfiguration = (FileStorageConfiguration) StorageManager
            .getConfiguration();// www.ja  v a 2s  .  com
    File avatarFile = fileStorageConfiguration.getAvatarFile(avatarId, size);
    return (avatarFile != null) ? new FileResource(avatarFile)
            : MyCollabResource.newResource("icons/default_user_avatar_" + size + ".png");
}

From source file:com.github.carljmosca.ui.FramesView.java

private void displayFrame() {
    imageLayout = new HorizontalLayout(
            new Image(null, new FileResource(new File("/Users/moscac/Downloads/GetMedia.jpeg"))));
}

From source file:com.haulmont.cuba.web.gui.components.WebComponentsHelper.java

License:Apache License

public static Resource getResource(String resURL) {
    if (StringUtils.isEmpty(resURL))
        return null;

    if (resURL.startsWith("file:")) {
        return new FileResource(new File(resURL.substring("file:".length())));
    } else if (resURL.startsWith("jar:")) {
        return new ClassResource(resURL.substring("jar:".length()));
    } else if (resURL.startsWith("theme:")) {
        String resourceId = resURL.substring("theme:".length());

        Configuration configuration = AppBeans.get(Configuration.NAME);
        WebConfig webConfig = configuration.getConfig(WebConfig.class);

        if (webConfig.getUseFontIcons()) {
            String fontIcon;/*from   ww w .j  a  va2 s.  c om*/

            ThemeConstants themeConstants = App.getInstance().getThemeConstants();
            String iconKey = "cuba.web." + StringUtils.replace(resourceId, "/", ".");
            fontIcon = themeConstants.get(iconKey);

            try {
                Resource resource = getFontIconResource(fontIcon);
                if (resource != null) {
                    return resource;
                }
            } catch (NoSuchFieldException | IllegalAccessException e) {
                LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + fontIcon);
            }
        }

        return new VersionedThemeResource(resourceId);
    } else if (resURL.contains("icon:")) {
        try {
            return getFontIconResource(resURL);
        } catch (NoSuchFieldException | IllegalAccessException e) {
            LoggerFactory.getLogger(WebComponentsHelper.class).warn("Unable to use font icon " + resURL);
        }
        return null;
    } else {
        return new VersionedThemeResource(resURL);
    }
}