Example usage for com.vaadin.ui Embedded Embedded

List of usage examples for com.vaadin.ui Embedded Embedded

Introduction

In this page you can find the example usage for com.vaadin.ui Embedded Embedded.

Prototype

public Embedded(String caption, Resource source) 

Source Link

Document

Creates a new Embedded object whose contents is loaded from given resource.

Usage

From source file:com.lizardtech.expresszip.vaadin.MapToolbarViewComponent.java

License:Apache License

public MapToolbarViewComponent() {
    hznToolbar.setMargin(true);// w  w w.  j  a  v a  2s. c  om
    hznToolbar.setSpacing(true);

    help = new ExpressZipButton("Help", Style.MENU, this);
    restart = new ExpressZipButton("Start Over", Style.MENU, this);

    txtZoomTo.setInputPrompt("Search...");
    txtZoomTo.setDescription("Geocoding courtesy of Open Street Map");
    txtZoomTo.addStyleName("searchbox");
    txtZoomTo.setWidth("260px");
    txtZoomTo.setImmediate(true);

    btnJobQueueStatus.setDescription("Job Manager");
    ThemeResource gear = new ThemeResource("img/JobManagementStandard23px.png");
    btnJobQueueStatus.setIcon(gear);
    btnJobQueueStatus.setStyleName(Button.STYLE_LINK);
    btnJobQueueStatus.addListener(this);

    Embedded logo = new Embedded(null, new ThemeResource("img/ExpZip_Logo161x33px.png"));
    hznToolbar.addComponent(logo);
    hznToolbar.setComponentAlignment(logo, Alignment.MIDDLE_LEFT);
    hznToolbar.setExpandRatio(logo, 0.35f);
    hznToolbar.addComponent(txtZoomTo);
    hznToolbar.setComponentAlignment(txtZoomTo, Alignment.MIDDLE_LEFT);
    hznToolbar.setExpandRatio(txtZoomTo, 0.25f);
    hznToolbar.addComponent(help);
    hznToolbar.setComponentAlignment(help, Alignment.MIDDLE_RIGHT);
    hznToolbar.setExpandRatio(help, 0.3f);
    hznToolbar.addComponent(restart);
    hznToolbar.setComponentAlignment(restart, Alignment.MIDDLE_LEFT);
    hznToolbar.setExpandRatio(restart, 0.15f);
    hznToolbar.addComponent(btnJobQueueStatus);
    hznToolbar.setComponentAlignment(btnJobQueueStatus, Alignment.MIDDLE_CENTER);
    hznToolbar.setExpandRatio(btnJobQueueStatus, 0.15f);

    hznToolbar.setSizeFull();

    hznToolbar.addStyleName("header");

    setCompositionRoot(hznToolbar);

    // textFieldListener puts a marker with given input
    txtZoomTo.addListener(new ValueChangeListener() {
        private static final long serialVersionUID = 8461586871780709805L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            String target = txtZoomTo.getValue().toString();
            markAddress(target);
        }
    });
}

From source file:com.lizardtech.expresszip.vaadin.SetupMapViewComponent.java

License:Apache License

public SetupMapViewComponent() {

    listeners = new ArrayList<SetupMapViewListener>();
    cmbProjection = new ComboBox();
    cmbProjection.setTextInputAllowed(false);
    HorizontalLayout projectionLayout = new HorizontalLayout();
    projectionLayout.addComponent(cmbProjection);
    projectionLayout.setWidth(100f, UNITS_PERCENTAGE);

    setSizeFull();/*from  w  ww . j  a  v  a  2s . c om*/

    // main layout
    VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSizeFull();

    // instruction banner
    Label step = new Label("Step 2: Select Export Region");
    step.addStyleName("step");
    layout.addComponent(step);

    //
    // setup tree data source
    //
    treeHier = new HierarchicalContainer();
    treeHier.addContainerProperty(ExpressZipTreeTable.LAYER, ExpressZipLayer.class, null);
    treeHier.addContainerProperty(DRAG_PROPERTY, Embedded.class, null);

    // table holding layers
    treeTable = new ExpressZipTreeTable();
    treeTable.setContainerDataSource(treeHier);

    treeTable.setDragMode(TableDragMode.ROW);
    treeTable.setColumnHeaders(new String[] { ExpressZipTreeTable.LAYER, "" });
    treeTable.setColumnExpandRatio(ExpressZipTreeTable.LAYER, 1);
    treeTable.setColumnWidth(DRAG_PROPERTY, 23);

    // upload shape file
    btnUploadShapeFile.setFieldType(FieldType.BYTE_ARRAY);
    btnUploadShapeFile.setButtonCaption("");
    btnUploadShapeFile.setSizeUndefined();
    btnUploadShapeFile.addStyleName("shapefile");

    // remove shape file
    btnRemoveShapeFile.addListener(this);
    btnRemoveShapeFile.setSizeUndefined();
    btnRemoveShapeFile.setVisible(false);
    btnRemoveShapeFile.setIcon(new ThemeResource("img/RemoveShapefileStandard23px.png"));
    btnRemoveShapeFile.setStyleName(BaseTheme.BUTTON_LINK);
    btnRemoveShapeFile.addStyleName("shapefile");
    HorizontalLayout hznUpload = new HorizontalLayout();

    Panel coordPanel = new Panel("Export Extent");

    layout.addComponent(treeTable);
    layout.addComponent(new Panel(PROJECTION, projectionLayout));
    layout.addComponent(new Panel(SHAPEFILE_UPLOAD, hznUpload));
    layout.addComponent(coordPanel);

    layout.setSpacing(true);

    hznUpload.addComponent(btnUploadShapeFile);
    hznUpload.addComponent(btnRemoveShapeFile);
    hznUpload.addComponent(lblCurrentShapeFile);
    hznUpload.setExpandRatio(lblCurrentShapeFile, 1f);
    hznUpload.setComponentAlignment(lblCurrentShapeFile, Alignment.MIDDLE_LEFT);
    hznUpload.setWidth("100%");

    cmbProjection.setWidth("100%");

    topTextField.setWidth(150, UNITS_PIXELS);
    topTextField.setImmediate(true);
    topTextField.setRequired(true);
    topTextField.addListener(topListener);

    leftTextField.setWidth(150, UNITS_PIXELS);
    leftTextField.setImmediate(true);
    leftTextField.setRequired(true);
    leftTextField.addListener(leftListener);

    bottomTextField.setWidth(150, UNITS_PIXELS);
    bottomTextField.setImmediate(true);
    bottomTextField.setRequired(true);
    bottomTextField.addListener(bottomListener);

    rightTextField.setWidth(150, UNITS_PIXELS);
    rightTextField.setImmediate(true);
    rightTextField.setRequired(true);
    rightTextField.addListener(rightListener);

    VerticalLayout coordLayout = new VerticalLayout();
    coordLayout.setSizeFull();
    coordPanel.setContent(coordLayout);
    coordLayout.addComponent(topTextField);

    HorizontalLayout leftRightLayout = new HorizontalLayout();
    leftRightLayout.setWidth("100%");
    leftRightLayout.addComponent(leftTextField);
    leftRightLayout.addComponent(rightTextField);
    leftRightLayout.setComponentAlignment(leftTextField, Alignment.MIDDLE_LEFT);
    leftRightLayout.setComponentAlignment(rightTextField, Alignment.MIDDLE_RIGHT);
    coordLayout.addComponent(leftRightLayout);

    coordLayout.addComponent(bottomTextField);
    coordLayout.setComponentAlignment(topTextField, Alignment.TOP_CENTER);
    coordLayout.setComponentAlignment(bottomTextField, Alignment.BOTTOM_CENTER);

    btnNext = new ExpressZipButton("Next", Style.STEP, this);
    btnBack = new ExpressZipButton("Back", Style.STEP, this);

    HorizontalLayout backNextLayout = new HorizontalLayout();
    backNextLayout.addComponent(btnBack);
    backNextLayout.addComponent(btnNext);
    btnNext.setEnabled(false);

    backNextLayout.setComponentAlignment(btnBack, Alignment.BOTTOM_LEFT);
    backNextLayout.setComponentAlignment(btnNext, Alignment.BOTTOM_RIGHT);
    backNextLayout.setWidth("100%");

    VerticalLayout navLayout = new VerticalLayout();
    navLayout.addComponent(backNextLayout);
    navLayout.setSpacing(true);

    ThemeResource banner = new ThemeResource("img/ProgressBar2.png");
    navLayout.addComponent(new Embedded(null, banner));

    layout.addComponent(navLayout);
    layout.setComponentAlignment(navLayout, Alignment.BOTTOM_CENTER);

    layout.setExpandRatio(treeTable, 1.0f);
    setCompositionRoot(layout);

    // notify when selection changes
    treeTable.addListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            for (SetupMapViewListener listener : listeners) {
                listener.layersSelectedEvent((Set<ExpressZipLayer>) treeTable.getValue());
            }

        }
    });
    treeTable.addActionHandler(this);
    treeHier.removeAllItems();

    //
    // drag n' drop behavior
    //
    treeTable.setDropHandler(new DropHandler() {
        public AcceptCriterion getAcceptCriterion() {
            return AcceptAll.get();
        }

        // Make sure the drag source is the same tree
        public void drop(DragAndDropEvent event) {
            // Wrapper for the object that is dragged
            Transferable t = event.getTransferable();

            // Make sure the drag source is the same tree
            if (t.getSourceComponent() != treeTable)
                return;

            AbstractSelectTargetDetails target = (AbstractSelectTargetDetails) event.getTargetDetails();

            // Get ids of the dragged item and the target item
            Object sourceItemId = t.getData("itemId");
            Object targetItemId = target.getItemIdOver();

            // if we drop on ourselves, ignore
            if (sourceItemId == targetItemId)
                return;

            // On which side of the target the item was dropped
            VerticalDropLocation location = target.getDropLocation();

            // place source after target
            treeHier.moveAfterSibling(sourceItemId, targetItemId);

            // if top, switch them
            if (location == VerticalDropLocation.TOP) {
                treeHier.moveAfterSibling(targetItemId, sourceItemId);
            }

            Collection<ExpressZipLayer> layers = (Collection<ExpressZipLayer>) treeHier.rootItemIds();
            for (SetupMapViewListener listener : listeners)
                listener.layerMovedEvent(layers);
        }
    });

    cmbProjection.setImmediate(true);
    cmbProjection.setNullSelectionAllowed(false);
    cmbProjection.addListener(new Property.ValueChangeListener() {
        private static final long serialVersionUID = -5188369735622627751L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            if (cmbProjection.getValue() != null) {
                selectedEpsg = (String) cmbProjection.getValue();
                String currentProjection = ((ExpressZipWindow) getApplication().getMainWindow())
                        .getExportProps().getMapProjection();
                if (!selectedEpsg.equals(currentProjection))
                    for (SetupMapViewListener listener : new ArrayList<SetupMapViewListener>(listeners))
                        listener.projectionChangedEvent(selectedEpsg);
            }
        }
    });
}

From source file:com.lizardtech.expresszip.vaadin.SetupMapViewComponent.java

License:Apache License

@Override
public void updateTree(List<ExpressZipLayer> chosenLayers, Set<String> supportedProjections) {
    treeHier.removeAllItems();/*  w  w  w.  j  a va 2 s. c om*/
    for (ExpressZipLayer layer : chosenLayers) {
        Item item = treeHier.addItem(layer);
        item.getItemProperty(ExpressZipTreeTable.LAYER).setValue(layer);
        Embedded dragImg = new Embedded("", new ThemeResource("img/MoveUpDown23px.png"));
        dragImg.setDescription("Drag to change layer order");
        item.getItemProperty(DRAG_PROPERTY).setValue(dragImg);

        // using treetable just for drag-drop, no children
        treeTable.setChildrenAllowed(layer, false);
    }

    // update the EPSG combo box with the union of supported projections from the enabled layers
    cmbProjection.removeAllItems();
    for (String epsg : supportedProjections) {
        String displayName = epsg;
        final String EPSG = "EPSG:";
        try {
            CoordinateReferenceSystem sourceCRS = CRS.decode(epsg);
            displayName = sourceCRS.getName().toString();
            if (displayName.startsWith(EPSG))
                displayName = displayName.substring(EPSG.length());
            ReferenceIdentifier id = (ReferenceIdentifier) sourceCRS.getIdentifiers().iterator().next();
            displayName = String.format("%s (%s)", displayName, id.getCode());
        } catch (NoSuchAuthorityCodeException e) {
        } catch (FactoryException e) {
        }
        cmbProjection.addItem(epsg);
        cmbProjection.setItemCaption(epsg, displayName);
    }

    if (supportedProjections.size() > 0) {
        if (selectedEpsg == null || !cmbProjection.containsId(selectedEpsg)) {
            selectedEpsg = supportedProjections.iterator().next();
        }
        cmbProjection.select(selectedEpsg);
    }
}

From source file:com.lst.deploymentautomation.vaadin.page.TodoListView.java

License:Open Source License

@SuppressWarnings("serial")
private void createView() {
    final LspsUI ui = (LspsUI) getUI();

    setTitle(ui.getMessage(TITLE));//from w  w w.  j  a  va  2 s.  c  o  m

    VerticalLayout layout = new VerticalLayout();
    setContent(layout);

    table = new Table();
    table.setSizeFull();
    table.setSelectable(true);
    table.setMultiSelectMode(MultiSelectMode.SIMPLE);
    table.setSortEnabled(false);
    table.setColumnReorderingAllowed(true);
    table.setColumnCollapsingAllowed(true);

    table.addValueChangeListener(new Property.ValueChangeListener() {

        @Override
        public void valueChange(ValueChangeEvent event) {
            final Object sel = event.getProperty().getValue();
            if (sel instanceof Set) {
                selection = (Set<Long>) sel;
            } else if (sel instanceof Long) {
                selection = Collections.singleton((Long) sel);
            } else {
                selection = Collections.emptySet();
            }

            //enable todo actions only if the sel is non-empty
            actionBtn.setEnabled(selection.size() > 0);
        }
    });
    table.addItemClickListener(new ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) {
            if (table.isMultiSelect()) {
                return; //don't do anything if in selection mode
            }
            if (event.getButton() != MouseButton.LEFT || event.isDoubleClick()) {
                return; //ignore right-clicks
            }

            final Item item = event.getItem();
            final Long todoId = (Long) item.getItemProperty("id").getValue();
            try {
                ((LspsUI) getUI()).openTodo(todoId);
            } catch (Exception e) {
                Utils.log(e, "could not open to-do " + todoId, log);
                final LspsUI ui = (LspsUI) getUI();
                ui.showErrorMessage("app.unknownErrorOccurred", e); //todo.openFailed?
            }
        }
    });

    table.setContainerDataSource(container);

    Object[] defaultColumns = new Object[] { "title", "notes", "priority", "authorization", "modelInstanceId",
            "issuedDate" };
    //load table settings
    String settings = ui.getUser().getSettingString(SETTINGS_KEY, null);
    if (settings == null) {
        table.setVisibleColumns(defaultColumns);
        originalSettings = getColumnSettings();
    } else {
        originalSettings = settings;
        try {
            applyTableSettings(settings);
        } catch (Exception e) {
            table.setVisibleColumns(defaultColumns);
            Utils.log(e, "could not load todo list settings", log);
        }
    }

    table.setColumnHeader("title", ui.getMessage("todo.title"));
    table.setColumnHeader("notes", ui.getMessage("todo.notes"));
    table.setColumnHeader("priority", ui.getMessage("todo.priority"));
    table.setColumnHeader("authorization", ui.getMessage("todo.authorizationShort"));
    table.setColumnHeader("modelInstanceId", ui.getMessage("todo.process"));
    table.setColumnHeader("issuedDate", ui.getMessage("todo.issued"));

    table.setColumnAlignment("modelInstanceId", Table.Align.CENTER);
    table.setColumnExpandRatio("title", 2);
    table.setColumnExpandRatio("notes", 1);

    //localize todo titles
    table.addGeneratedColumn("title", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            @SuppressWarnings("unchecked")
            BeanItem<Todo> item = (BeanItem<Todo>) source.getItem(itemId);
            return ui.localizeEngineText(item.getBean().getTitle());
        }
    });

    //show icons for authorization
    table.addGeneratedColumn("authorization", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            @SuppressWarnings("unchecked")
            BeanItem<Todo> item = (BeanItem<Todo>) source.getItem(itemId);
            String icon;
            String text;
            switch (item.getBean().getAuthorization()) {
            case INITIAL_PERFORMER:
                icon = "auth_performer.gif";
                text = ui.getMessage("todo.authorizationPerformer");
                break;
            case DELEGATE:
                icon = "auth_delegate.gif";
                text = ui.getMessage("todo.authorizationDelegate");
                break;
            case SUBSTITUTE:
                icon = "auth_substitute.gif";
                text = ui.getMessage("todo.authorizationSubstitute");
                break;
            case NOT_PERMITTED:
            default:
                icon = "auth_unknown.gif";
                text = ui.getMessage("todo.authorizationUnknown");
                break;
            }
            Embedded authIcon = new Embedded(null, new ThemeResource("../icons/" + icon));
            authIcon.setDescription(text);

            if (item.getBean().getAllocatedTo() != null) {
                HorizontalLayout layout = new HorizontalLayout();
                layout.setSpacing(true);

                layout.addComponent(authIcon);

                Embedded lockedIcon = new Embedded(null, new ThemeResource("../icons/lock.gif"));
                lockedIcon.setDescription(
                        ui.getMessage("todo.lockedBy", item.getBean().getAllocatedToFullName()));
                layout.addComponent(lockedIcon);
                return layout;
            } else {
                return authIcon;
            }
        }
    });

    //format date
    final SimpleDateFormat df = new SimpleDateFormat(ui.getMessage("app.dateTimeFormat"));
    table.addGeneratedColumn("issuedDate", new ColumnGenerator() {

        @Override
        public Object generateCell(Table source, Object itemId, Object columnId) {
            @SuppressWarnings("unchecked")
            BeanItem<Todo> item = (BeanItem<Todo>) source.getItem(itemId);
            return df.format(item.getBean().getIssuedDate());
        }
    });

    layout.addComponent(table);
    layout.setExpandRatio(table, 1);
}

From source file:com.mycollab.module.user.accountsettings.customize.view.LogoEditWindow.java

License:Open Source License

private void editPhoto(byte[] imageData) {
    try {//  w  ww  .  j  a v a  2 s .c o  m
        originalImage = ImageIO.read(new ByteArrayInputStream(imageData));
    } catch (IOException e) {
        throw new UserInvalidInputException("Invalid image type");
    }
    originalImage = ImageUtil.scaleImage(originalImage, 650, 650);

    MHorizontalLayout previewBox = new MHorizontalLayout().withMargin(new MarginInfo(false, true, true, false))
            .withFullWidth();

    final String logoPath = MyCollabUI.getBillingAccount().getLogopath();
    Resource defaultPhoto = AccountAssetsResolver.createLogoResource(logoPath, 150);
    previewImage = new Embedded(null, defaultPhoto);
    previewImage.setWidth("100px");
    previewBox.addComponent(previewImage);
    previewBox.setComponentAlignment(previewImage, Alignment.TOP_LEFT);

    MVerticalLayout previewBoxRight = new MVerticalLayout().withSpacing(false)
            .withMargin(new MarginInfo(false, true, false, true));

    previewBoxRight
            .addComponent(ELabel.html(UserUIContext.getMessage(ShellI18nEnum.OPT_IMAGE_EDIT_INSTRUCTION)));

    MButton cancelBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            clickEvent -> EventBusFactory.getInstance()
                    .post(new SettingEvent.GotoGeneralSetting(LogoEditWindow.this, null)))
                            .withStyleName(WebThemes.BUTTON_OPTION);

    MButton acceptBtn = new MButton(UserUIContext.getMessage(GenericI18Enum.BUTTON_ACCEPT), clickEvent -> {
        if (scaleImageData != null && scaleImageData.length > 0) {
            try {
                BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                AccountLogoService accountLogoService = AppContextUtil.getSpringBean(AccountLogoService.class);
                accountLogoService.upload(UserUIContext.getUsername(), image, MyCollabUI.getAccountId());
                Page.getCurrent().getJavaScript().execute("window.location.reload();");
            } catch (IOException e) {
                throw new MyCollabException("Error when saving account logo", e);
            }
        }
    }).withStyleName(WebThemes.BUTTON_ACTION).withIcon(FontAwesome.SAVE)
            .withClickShortcut(ShortcutAction.KeyCode.ENTER);

    MHorizontalLayout controlBtns = new MHorizontalLayout(acceptBtn, cancelBtn);
    previewBoxRight.with(controlBtns).withAlign(controlBtns, Alignment.TOP_LEFT);
    previewBox.with(previewBoxRight).expand(previewBoxRight);
    content.addComponent(previewBox);

    CssLayout cropBox = new CssLayout();
    cropBox.setWidth("100%");
    VerticalLayout currentPhotoBox = new VerticalLayout();
    Resource resource = new ByteArrayImageResource(ImageUtil.convertImageToByteArray(originalImage),
            "image/png");
    CropField cropField = new CropField(resource);
    cropField.setImmediate(true);
    cropField.setSelectionAspectRatio(150 / 28);
    cropField.addValueChangeListener(valueChangeEvent -> {
        VCropSelection newSelection = (VCropSelection) valueChangeEvent.getProperty().getValue();
        int x1 = newSelection.getXTopLeft();
        int y1 = newSelection.getYTopLeft();
        int x2 = newSelection.getXBottomRight();
        int y2 = newSelection.getYBottomRight();
        if (x2 > x1 && y2 > y1) {
            BufferedImage subImage = originalImage.getSubimage(x1, y1, (x2 - x1), (y2 - y1));
            ByteArrayOutputStream outStream = new ByteArrayOutputStream();
            try {
                ImageIO.write(subImage, "png", outStream);
                scaleImageData = outStream.toByteArray();
                displayPreviewImage();
            } catch (IOException e) {
                LOG.error("Error while scale image: ", e);
            }
        }
    });
    currentPhotoBox.setWidth("650px");
    currentPhotoBox.setHeight("650px");
    currentPhotoBox.addComponent(cropField);
    cropBox.addComponent(currentPhotoBox);

    content.with(previewBox, ELabel.hr(), cropBox);
}

From source file:com.openhris.employee.EmployeePersonalInformation.java

public ComponentContainer layout() {
    glayout = new GridLayout(4, 19);
    glayout.setSpacing(true);/*from  w w  w . ja va  2s.  c  o  m*/
    glayout.setWidth("600px");
    glayout.setHeight("100%");

    final Panel imagePanel = new Panel();
    imagePanel.setStyleName("light");
    AbstractLayout panelLayout = (AbstractLayout) imagePanel.getContent();
    panelLayout.setMargin(false);
    imagePanel.setWidth("100px");

    avatar = new Embedded(null, new ThemeResource("../myTheme/img/fnc.jpg"));
    avatar.setImmediate(true);
    avatar.setWidth(90, Sizeable.UNITS_PIXELS);
    avatar.setHeight(90, Sizeable.UNITS_PIXELS);
    avatar.addStyleName("logo-img");
    imagePanel.addComponent(avatar);
    glayout.addComponent(avatar, 0, 0, 0, 1);
    glayout.setComponentAlignment(imagePanel, Alignment.MIDDLE_CENTER);

    Button uploadPhotoBtn = new Button("Upload..");
    uploadPhotoBtn.setWidth("100%");
    uploadPhotoBtn.setStyleName(Reindeer.BUTTON_SMALL);
    uploadPhotoBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (getEmployeeId() == null) {
                getWindow().showNotification("You did not select and Employee!",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window uploadImage = new UploadImage(imagePanel, avatar, getEmployeeId());
            uploadImage.setWidth("450px");
            if (uploadImage.getParent() == null) {
                getWindow().addWindow(uploadImage);
            }
            uploadImage.setModal(true);
            uploadImage.center();
        }
    });
    glayout.addComponent(uploadPhotoBtn, 0, 2);
    glayout.setComponentAlignment(uploadPhotoBtn, Alignment.MIDDLE_CENTER);

    fnField = createTextField("Firstname: ");
    glayout.addComponent(fnField, 1, 0);
    glayout.setComponentAlignment(fnField, Alignment.MIDDLE_LEFT);

    mnField = createTextField("Middlename: ");
    glayout.addComponent(mnField, 2, 0);
    glayout.setComponentAlignment(mnField, Alignment.MIDDLE_LEFT);

    lnField = createTextField("Lastname: ");
    glayout.addComponent(lnField, 3, 0);
    glayout.setComponentAlignment(lnField, Alignment.MIDDLE_LEFT);

    companyIdField = createTextField("Employee ID: ");
    companyIdField.setEnabled(false);
    glayout.addComponent(companyIdField, 1, 1, 2, 1);
    glayout.setComponentAlignment(companyIdField, Alignment.MIDDLE_LEFT);

    dobField = new PopupDateField("Date of Birth: ");
    dobField.addStyleName("mydate");
    dobField.setDateFormat("MM/dd/yyyy");
    dobField.setWidth("100%");
    dobField.setResolution(DateField.RESOLUTION_DAY);
    glayout.addComponent(dobField, 1, 2);
    glayout.setComponentAlignment(dobField, Alignment.MIDDLE_LEFT);

    pobField = createTextField("Birth Place: ");
    pobField.setValue("N/A");
    glayout.addComponent(pobField, 2, 2, 3, 2);
    glayout.setComponentAlignment(pobField, Alignment.MIDDLE_LEFT);

    genderBox = dropDownComponent.populateGenderList(new ComboBox());
    genderBox.setWidth("100%");
    glayout.addComponent(genderBox, 1, 3);
    glayout.setComponentAlignment(genderBox, Alignment.MIDDLE_LEFT);

    civilStatusBox = dropDownComponent.populateCivilStatusList(new ComboBox());
    civilStatusBox.setWidth("100%");
    glayout.addComponent(civilStatusBox, 2, 3);
    glayout.setComponentAlignment(civilStatusBox, Alignment.MIDDLE_LEFT);

    citizenshipField = createTextField("Citizenship: ");
    citizenshipField.setValue("N/A");
    glayout.addComponent(citizenshipField, 3, 3);
    glayout.setComponentAlignment(citizenshipField, Alignment.MIDDLE_LEFT);

    heightField = createTextField("Height(cm):");
    heightField.setValue(0.0);
    glayout.addComponent(heightField, 1, 4);
    glayout.setComponentAlignment(heightField, Alignment.MIDDLE_LEFT);

    weightField = createTextField("Weight(kg): ");
    weightField.setValue(0.0);
    glayout.addComponent(weightField, 2, 4);
    glayout.setComponentAlignment(weightField, Alignment.MIDDLE_LEFT);

    religionField = createTextField("Religion: ");
    religionField.setValue("N/A");
    glayout.addComponent(religionField, 3, 4);
    glayout.setComponentAlignment(religionField, Alignment.MIDDLE_LEFT);

    spouseNameField = createTextField("Spouse Name: ");
    spouseNameField.setValue("N/A");
    glayout.addComponent(spouseNameField, 1, 5, 2, 5);
    glayout.setComponentAlignment(spouseNameField, Alignment.MIDDLE_LEFT);

    spouseOccupationField = createTextField("Spouse Occupation: ");
    spouseOccupationField.setValue("N/A");
    glayout.addComponent(spouseOccupationField, 3, 5);
    glayout.setComponentAlignment(spouseOccupationField, Alignment.MIDDLE_LEFT);

    spouseOfficeAddressField = createTextField("Spouse Office Address: ");
    spouseOfficeAddressField.setValue("N/A");
    glayout.addComponent(spouseOfficeAddressField, 1, 6, 3, 6);
    glayout.setComponentAlignment(spouseOfficeAddressField, Alignment.MIDDLE_LEFT);

    fathersNameField = createTextField("Father's Name: ");
    fathersNameField.setValue("N/A");
    glayout.addComponent(fathersNameField, 1, 7, 2, 7);
    glayout.setComponentAlignment(fathersNameField, Alignment.MIDDLE_LEFT);

    fathersOccupationField = createTextField("Father's Occupation: ");
    fathersOccupationField.setValue("N/A");
    glayout.addComponent(fathersOccupationField, 3, 7);
    glayout.setComponentAlignment(fathersOccupationField, Alignment.MIDDLE_LEFT);

    mothersNameField = createTextField("Mother's Maiden Name: ");
    mothersNameField.setValue("N/A");
    glayout.addComponent(mothersNameField, 1, 8, 2, 8);
    glayout.setComponentAlignment(mothersNameField, Alignment.MIDDLE_LEFT);

    mothersOccupationField = createTextField("Mother's Occupation: ");
    mothersOccupationField.setValue("N/A");
    glayout.addComponent(mothersOccupationField, 3, 8);
    glayout.setComponentAlignment(mothersOccupationField, Alignment.MIDDLE_LEFT);

    parentsAddressField = createTextField("Parents Address");
    parentsAddressField.setValue("N/A");
    glayout.addComponent(parentsAddressField, 1, 9, 3, 9);
    glayout.setComponentAlignment(parentsAddressField, Alignment.MIDDLE_LEFT);

    dialectSpeakWriteField = createTextField("Language or Dialect you can speak or write: ");
    dialectSpeakWriteField.setValue("N/A");
    glayout.addComponent(dialectSpeakWriteField, 1, 10, 3, 10);
    glayout.setComponentAlignment(dialectSpeakWriteField, Alignment.MIDDLE_LEFT);

    contactPersonNameField = createTextField("Contact Person: ");
    contactPersonNameField.setValue("N/A");
    glayout.addComponent(contactPersonNameField, 1, 11);
    glayout.setComponentAlignment(contactPersonNameField, Alignment.MIDDLE_LEFT);

    contactPersonAddressField = createTextField("Contact Person's Address: ");
    contactPersonAddressField.setValue("N/A");
    glayout.addComponent(contactPersonAddressField, 2, 11, 3, 11);
    glayout.setComponentAlignment(contactPersonAddressField, Alignment.MIDDLE_LEFT);

    contactPersonNoField = createTextField("Contact Person's Tel No: ");
    contactPersonNoField.setValue("N/A");
    glayout.addComponent(contactPersonNoField, 1, 12);
    glayout.setComponentAlignment(contactPersonNoField, Alignment.MIDDLE_LEFT);

    skillsField = createTextField("Skills: ");
    skillsField.setValue("N/A");
    glayout.addComponent(skillsField, 2, 12);
    glayout.setComponentAlignment(skillsField, Alignment.MIDDLE_LEFT);

    hobbyField = createTextField("Hobbies");
    hobbyField.setValue("N/A");
    glayout.addComponent(hobbyField, 3, 12);
    glayout.setComponentAlignment(hobbyField, Alignment.MIDDLE_LEFT);

    if (employeeId != null) {
        personalInformation = piService.getPersonalInformationData(employeeId);
        final byte[] image = personalInformation.getImage();
        if (image != null) {
            StreamResource.StreamSource imageSource = new StreamResource.StreamSource() {

                @Override
                public InputStream getStream() {
                    return new ByteArrayInputStream(image);
                }

            };

            StreamResource imageResource = new StreamResource(imageSource,
                    personalInformation.getFirstname() + ".jpg", getThisApplication());
            imageResource.setCacheTime(0);
            avatar.setSource(imageResource);
        }
        fnField.setValue(personalInformation.getFirstname().toUpperCase());
        mnField.setValue(personalInformation.getMiddlename().toUpperCase());
        lnField.setValue(personalInformation.getLastname().toUpperCase());
        companyIdField.setValue(employeeId);
        dobField.setValue(personalInformation.getDob());
        pobField.setValue(personalInformation.getPob());

        if (personalInformation.getCivilStatus() != null) {
            Object civilStatusId = civilStatusBox.addItem();
            civilStatusBox.setItemCaption(civilStatusId, personalInformation.getCivilStatus());
            civilStatusBox.setValue(civilStatusId);
        }

        if (personalInformation.getGender() != null) {
            Object genderId = genderBox.addItem();
            genderBox.setItemCaption(genderId, personalInformation.getGender());
            genderBox.setValue(genderId);
        }

        citizenshipField.setValue(personalInformation.getCitizenship());
        heightField.setValue(personalInformation.getHeight());
        weightField.setValue(personalInformation.getWeight());
        religionField.setValue(personalInformation.getReligion());
        spouseNameField.setValue(personalInformation.getSpouseName());
        spouseOccupationField.setValue(personalInformation.getSpouseOccupation());
        spouseOfficeAddressField.setValue(personalInformation.getSpouseOfficeAddress());
        fathersNameField.setValue(personalInformation.getFathersName());
        fathersOccupationField.setValue(personalInformation.getFathersOccupation());
        mothersNameField.setValue(personalInformation.getMothersName());
        mothersOccupationField.setValue(personalInformation.getMothersOccupation());
        parentsAddressField.setValue(personalInformation.getParentsAddress());
        dialectSpeakWriteField.setValue(personalInformation.getDialectSpeakWrite());
        contactPersonNameField.setValue(personalInformation.getContactPersonName());
        contactPersonAddressField.setValue(personalInformation.getContactPersonAddress());
        contactPersonNoField.setValue(personalInformation.getContactPersonNo());
        skillsField.setValue(personalInformation.getSkills());
        hobbyField.setValue(personalInformation.getHobby());
    }

    Button removeBtn = new Button("REMOVE EMPLOYEE");
    removeBtn.setWidth("100%");
    boolean visible = false;
    if (GlobalVariables.getUserRole() == null) {
        visible = false;
    } else if (GlobalVariables.getUserRole().equals("hr")
            || GlobalVariables.getUserRole().equals("administrator")) {
        visible = true;
    }
    removeBtn.setVisible(visible);
    removeBtn.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (!GlobalVariables.getUserRole().equals("administrator")) {
                getWindow().showNotification("You need to an ADMINISTRATOR to perform this ACTION.",
                        Window.Notification.TYPE_WARNING_MESSAGE);
                return;
            }

            Window window = getRemoveWindow(getEmployeeId());
            window.setModal(true);
            if (window.getParent() == null) {
                getWindow().addWindow(window);
            }
            window.center();
        }
    });
    glayout.addComponent(removeBtn, 1, 13);

    Button saveButton = new Button("UPDATE EMPLOYEE's INFORMATION");
    saveButton.setWidth("100%");
    saveButton.addListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            if (dobField.getValue() == null || dobField.getValue().toString().isEmpty()) {
                getWindow().showNotification("Date of Birth Required!", Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            if (heightField.getValue() == null || heightField.getValue().toString().isEmpty()) {
                getWindow().showNotification("Null/Empty Value for Height is not ALLOWED!",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            } else {
                if (!convertionUtilities.checkInputIfDouble(heightField.getValue().toString())) {
                    getWindow().showNotification("Enter a numeric format for Height!",
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
            }

            if (weightField.getValue() == null || weightField.getValue().toString().isEmpty()) {
                getWindow().showNotification("Null/Empty Value for Weight is not ALLOWED!",
                        Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            } else {
                if (!convertionUtilities.checkInputIfDouble(weightField.getValue().toString())) {
                    getWindow().showNotification("Enter a numeric format for Weight!",
                            Window.Notification.TYPE_ERROR_MESSAGE);
                    return;
                }
            }

            if (genderBox.getValue() == null || genderBox.getValue().toString().isEmpty()) {
                getWindow().showNotification("Select a Gender!", Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            if (civilStatusBox.getValue() == null || civilStatusBox.getValue().toString().isEmpty()) {
                getWindow().showNotification("Select Civil Status!", Window.Notification.TYPE_ERROR_MESSAGE);
                return;
            }

            PersonalInformation pi = new PersonalInformation();
            pi.setFirstname(fnField.getValue().toString().toLowerCase().trim());
            pi.setMiddlename(mnField.getValue().toString().toLowerCase().trim());
            pi.setLastname(lnField.getValue().toString().toLowerCase().trim());
            pi.setEmployeeId(employeeId);
            pi.setDob((Date) dobField.getValue());
            pi.setPob((pobField.getValue() == null) ? "N/A"
                    : pobField.getValue().toString().toLowerCase().trim());
            pi.setHeight(convertionUtilities.convertStringToDouble(heightField.getValue().toString()));
            pi.setWeight(convertionUtilities.convertStringToDouble(weightField.getValue().toString()));

            if (convertionUtilities.checkInputIfInteger(genderBox.getValue().toString())) {
                pi.setGender(genderBox.getItemCaption(genderBox.getValue()));
            } else {
                pi.setGender(genderBox.getValue().toString());
            }

            if (convertionUtilities.checkInputIfInteger(civilStatusBox.getValue().toString())) {
                pi.setCivilStatus(civilStatusBox.getItemCaption(civilStatusBox.getValue()));
            } else {
                pi.setCivilStatus(civilStatusBox.getValue().toString());
            }

            pi.setCitizenship(
                    (citizenshipField.getValue() == null) ? "N/A" : citizenshipField.getValue().toString());
            pi.setReligion((religionField.getValue() == null) ? "N/A" : religionField.getValue().toString());
            pi.setSpouseName(
                    (spouseNameField.getValue() == null) ? "N/A" : spouseNameField.getValue().toString());
            pi.setSpouseOccupation((spouseOccupationField.getValue() == null) ? "N/A"
                    : spouseOccupationField.getValue().toString());
            pi.setSpouseOfficeAddress((spouseOfficeAddressField.getValue() == null) ? "N/A"
                    : spouseOfficeAddressField.getValue().toString());
            pi.setFathersName(
                    (fathersNameField.getValue() == null) ? "N/A" : fathersNameField.getValue().toString());
            pi.setFathersOccupation((fathersOccupationField.getValue() == null) ? "N/A"
                    : fathersOccupationField.getValue().toString());
            pi.setMothersName(
                    (mothersNameField.getValue() == null) ? "N/A" : mothersNameField.getValue().toString());
            pi.setMothersOccupation((mothersOccupationField.getValue() == null) ? "N/A"
                    : mothersOccupationField.getValue().toString());
            pi.setParentsAddress((parentsAddressField.getValue() == null) ? "N/A"
                    : parentsAddressField.getValue().toString());
            pi.setDialectSpeakWrite((dialectSpeakWriteField.getValue() == null) ? "N/A"
                    : dialectSpeakWriteField.getValue().toString());
            pi.setContactPersonName((contactPersonNameField.getValue() == null) ? "N/A"
                    : contactPersonNameField.getValue().toString());
            pi.setContactPersonAddress((contactPersonAddressField.getValue() == null) ? "N/A"
                    : contactPersonAddressField.getValue().toString());
            pi.setContactPersonNo((contactPersonNoField.getValue() == null) ? "N/A"
                    : contactPersonNoField.getValue().toString());
            pi.setSkills((skillsField.getValue() == null) ? "N/A" : skillsField.getValue().toString());
            pi.setHobby((hobbyField.getValue() == null) ? "N/A" : hobbyField.getValue().toString());
            pi.setEmployeeId(getEmployeeId());

            //                boolean result = piService.updatePersonalInformation(pi, "UPDATE PERSONAL INFORMATION");
            Window window = updatePersonalInformationConfirmation(pi);
            window.setModal(true);
            if (window.getParent() == null) {
                getWindow().addWindow(window);
            }
            window.center();

            //      if(result){
            //          getWindow().showNotification("Information Updated", Window.Notification.TYPE_TRAY_NOTIFICATION);
            //      } else {
            //          getWindow().showNotification("SQL Error", Window.Notification.TYPE_ERROR_MESSAGE);
            //      }
        }
    });
    if (GlobalVariables.getUserRole().equals("administrator") || GlobalVariables.getUserRole().equals("hr")) {
        saveButton.setEnabled(true);
    } else {
        saveButton.setEnabled(false);
    }
    glayout.addComponent(saveButton, 2, 13, 3, 13);

    glayout.setColumnExpandRatio(1, .10f);
    glayout.setColumnExpandRatio(2, .10f);
    glayout.setColumnExpandRatio(3, .10f);

    return glayout;
}

From source file:com.openhris.payroll.reports.PayrollRegisterReport.java

public PayrollRegisterReport(int branchId, String payrollDate, Application payrollApplication) {
    this.branchId = branchId;
    this.payrollDate = payrollDate;
    this.payrollApplication = payrollApplication;

    setCaption("Payroll Register Report");
    setSizeFull();//from w  ww .  j  av  a  2s . com
    center();

    Connection conn = getConnection.connection();
    //        URL url = this.getClass().getResource("/com/openhris/reports/payrollRegisterReport.jasper");
    File reportFile = new File("C:/reportsJasper/payrollRegisterReport.jasper");
    //        File reportFile = new File(jasperUrl.getPath());

    final HashMap hm = new HashMap();
    hm.put("BRANCH_ID", getBranchId());
    hm.put("PAYROLL_DATE", getPayrollDate());

    try {
        JasperPrint jpReport = JasperFillManager.fillReport(reportFile.getPath(), hm, conn);
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String timestamp = df.format(new Date());
        //            file = File.createTempFile("payrollRegisterReport_"+timestamp, ".pdf");
        file = "C:/reportsPdf/payrollRegisterReport_" + timestamp + ".pdf";
        JasperExportManager.exportReportToPdfFile(jpReport, file);
    } catch (JRException ex) {
        Logger.getLogger(PayrollRegisterReport.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            if (conn != null || !conn.isClosed()) {
                conn.close();
            }
        } catch (SQLException ex) {
            Logger.getLogger(PayrollRegisterReport.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    StreamResource.StreamSource source = new StreamResource.StreamSource() {
        @Override
        public InputStream getStream() {
            try {
                File f = new File(file);
                FileInputStream fis = new FileInputStream(f);
                return fis;
            } catch (Exception e) {
                e.getMessage();
                return null;
            }
        }
    };

    StreamResource resource = new StreamResource(source, file, getPayrollApplication());
    resource.setMIMEType("application/pdf");

    VerticalLayout vlayout = new VerticalLayout();
    vlayout.setSizeFull();
    Embedded e = new Embedded("", new FileResource(new File(resource.getFilename()), getPayrollApplication()));
    //        e.setMimeType("application/pdf");
    //        e.setType(Embedded.TYPE_OBJECT);
    e.setSizeFull();
    e.setType(Embedded.TYPE_BROWSER);
    //        e.setSource(resource);
    //        e.setParameter("Content-Disposition", "attachment; filename=" + resource.getFilename());
    vlayout.addComponent(e);

    addComponent(vlayout);

    //        getPayrollApplication().getMainWindow().addWindow(this);
    getPayrollApplication().getMainWindow().open(resource, "_blank");
}

From source file:com.rdonasco.common.vaadin.view.utils.EmbeddedResourceBuilder.java

License:Apache License

private Embedded createUsingStreamSource() {
    StreamResource.StreamSource streamSource = new StreamResource.StreamSource() {
        private static final long serialVersionUID = 1L;

        @Override// w  w w .  ja  v  a2 s. com
        public InputStream getStream() {
            return new ByteArrayInputStream(bytes);
        }
    };
    StreamResource resource = new StreamResource(streamSource, name, application);
    Embedded embedded = new Embedded(caption, resource);

    return embedded;
}

From source file:com.rdonasco.common.vaadin.view.utils.EmbeddedResourceBuilder.java

License:Apache License

private Embedded createUsingResourceId() {
    return new Embedded(caption, new ThemeResource(resourceId));
}

From source file:com.rdonasco.datamanager.listeditor.controller.ListEditorViewPanelController.java

License:Apache License

private Embedded createDeleteIcon() {
    Embedded icon;//from  w w  w . j av  a 2  s.  com
    icon = new Embedded(null,
            new StreamResourceBuilder().setReferenceClass(ListEditorView.class)
                    .setRelativeResourcePath("images/delete.png")
                    .setApplication(getEditorViewPanel().getApplication()).createStreamResource());
    return icon;
}