Example usage for com.vaadin.server Page getCurrent

List of usage examples for com.vaadin.server Page getCurrent

Introduction

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

Prototype

public static Page getCurrent() 

Source Link

Document

Gets the Page to which the current uI belongs.

Usage

From source file:com.anphat.customer.controller.CommonUploader.java

public void exportFileErr(String mess, String fileErrorName) {
    try {//from   w w  w  . j a  v a2 s. co  m
        workbookEp.write(fileOut);
        fileOut.close();
        fileOut.flush();
    } catch (IOException ex) {
        ex.printStackTrace();
    }
    File fileError = new File(fileErrorName);
    fileError.deleteOnExit();
    Resource resource = new FileResource(fileError);
    Page.getCurrent().open(resource, null, false);
    //            Notification.show(mess, Notification.Type.WARNING_MESSAGE);
    wp.close();
    UI.getCurrent().setPollInterval(-1);
}

From source file:com.anphat.customer.controller.ExportContractToDocController.java

private void buildFile() {
    try {/*www .j  av  a 2 s .  c o  m*/
        FileOutputStream out = new FileOutputStream(pathFileOuput);
        document.write(out);
        out.close();
        final File exportFile = new File(pathFileOuput);
        if (exportFile.exists()) {
            ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("delete.item.title"),
                    BundleUtils.getString("confirm.contract.doc"), BundleUtils.getString("yes"),
                    BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                        @Override
                        public void onClose(ConfirmDialog dialog) {
                            if (dialog.isConfirmed()) {
                                Resource res = new FileResource(exportFile);
                                Page.getCurrent().open(res, BundleUtils.getString("label.caption.download")
                                        .replace("@name", BundleUtils.getString("contract.doc.caption")), true);
                            }
                        }
                    });
        } else {
            //Thong bao khong the tai file
            CommonMessages.showExportFail("contract.doc.caption");
        }
        exportFile.deleteOnExit();
    } catch (IOException ex) {
        CommonMessages.showExportFail("contract.doc.caption");
        //            ex.printStackTrace();
    }
}

From source file:com.anphat.list.controller.ListDeptAndStaffController.java

public ListDeptAndStaffController(ListStaffDepartment mainUI) {

    this.listDepartmentsAndStaffUI = mainUI;
    commonTableDeptPanel = mainUI.getTblListDepartmentUI();
    //define button toolbar dept
    btnAddDept = commonTableDeptPanel.getAddButton();
    btnEditDept = commonTableDeptPanel.getEditButton();
    btnCopyDept = commonTableDeptPanel.getCoppyButton();
    btnDelDept = commonTableDeptPanel.getDeleteButton();
    btnDelDept.setEnabled(false);//from w ww.  j a  va  2  s. co m
    btnImportDept = commonTableDeptPanel.getImportButton();
    btnExportDept = commonTableDeptPanel.getExportButton();
    btnResetDept = mainUI.getBtnRefreshDept();
    //define button toolbar emp
    commonTableEmpPanel = mainUI.getTblListStaffUI();
    btnAddEmp = commonTableEmpPanel.getAddButton();
    btnEditEmp = commonTableEmpPanel.getEditButton();
    btnCopyEmp = commonTableEmpPanel.getCoppyButton();
    btnDelEmp = commonTableEmpPanel.getDeleteButton();
    btnDelEmp.setEnabled(false);
    //        btnImportEmp = commonTableEmpPanel.getImportButton();
    //        btnExportEmp = commonTableEmpPanel.getExportButton();
    btnResetEmp = mainUI.getBtnRefreshEmp();
    //NgocND6 160311
    btnTransferRole = listDepartmentsAndStaffUI.getBtnTransferRoleCusts();
    btnAddMapStaffCusts = mainUI.getBtnAddMapStaffCustomer();

    searchFormDeptController = new DepartmentSearchPanelController(mainUI.getSearchDepartmentForm());
    searchFormDeptController.init();
    listDepartmentController = new ListDepartmentController(listDepartmentsAndStaffUI.getTblListDepartmentUI());
    listDepartmentController.init();

    getData();

    searchFormStaffController = new StaffSearchPanelController(mainUI.getSearchStaffForm());
    searchFormStaffController.init();
    listStaffController = new ListStaffController(listDepartmentsAndStaffUI.getTblListStaffUI());
    listStaffController.setMapId2DeparmentDTO(searchFormStaffController.mapId2DepartmentDTO);
    staffForm = mainUI.getSearchStaffForm();
    //xu li cac nut tai day
    departmentDTO = new DepartmentDTO();
    staffDTO = new StaffDTO();
    searchFormDeptController.setNotRequired();
    deptActionListener();
    staffActionListener();

    //show table
    tblDepartment = listDepartmentsAndStaffUI.getTblListDepartmentUI().getMainTable();
    tblStaff = listDepartmentsAndStaffUI.getTblListStaffUI().getMainTable();
    //style cho notification
    Page.Styles styles = Page.getCurrent().getStyles();
    //        styles.add("*{font-family: tahoma; font-size: 13px;}");
    styles.add(".v-Notification {}\n" + "  .popupContent {}\n" + "    .gwt-HTML {}\n" + "      h1 {}\n"
            + "      p  {}");
    styles.add(".v-Notification.mystyle {\n" + "    background: #FFFF00;\n"
            + "    border: 10px solid #C00000;\n" + "    color: black;\n" + "}");
    //get data fill to next panel
    //        tblDepartment.setMultiSelect(false);
    tblDepartment.addItemClickListener(new ItemClickEvent.ItemClickListener() {

        @Override
        public void itemClick(ItemClickEvent event) {
            //                //open progress sdf
            value = new ArrayList<>();
            DepartmentDTO dept = (DepartmentDTO) event.getItemId();
            value.add(dept.copy());
            if (value.size() == 1) {//neu chon 1 row
                fillDataStaff(value.toArray()[0]);
                fillData2StaffForm(value.toArray()[0]);
            }
            if (value.isEmpty()) {
                deptId = null;
                searchFormStaffController.getCboDepartment().getNameCombo().setValue(null);
                searchFormStaffController.getCboDepartment().getCodeCombo().setValue(null);
            }
        }
    });
}

From source file:com.anphat.list.controller.ListDeptAndStaffController.java

public void deptActionListener() {

    ShortcutUtils.setShortcutKey(listDepartmentsAndStaffUI.getBtnSearchDept());
    ShortcutUtils.doTextChangeUppercase(searchFormDeptController.getSearchDepartmentForm().getTxtDeptCode());
    listDepartmentsAndStaffUI.getBtnSearchDept().addClickListener(new Button.ClickListener() {

        @Override//from www. ja  v a2s  . c  om
        public void buttonClick(Button.ClickEvent event) {
            doSearchDepartments();
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnResetDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            doResetInputDept();
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnAddDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            DialogCreateDepartment dialogCreateDepartment = new DialogCreateDepartment(
                    BundleUtils.getString("department.management.panel.addDepartment"), new DepartmentDTO());
            dialogCreateDepartmentController = new DialogCreateDepartmentController(dialogCreateDepartment,
                    Constants.ADD, tblDepartment, tblStaff, staffForm.getF9Departments());
            dialogCreateDepartmentController.init(new DepartmentDTO());
            UI.getCurrent().addWindow(dialogCreateDepartment);
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnEditDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Set<DepartmentDTO> selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
            if (selectedValues != null) {
                List<DepartmentDTO> lstDepartment = Lists.newArrayList();
                for (DepartmentDTO departmentDTO : selectedValues) {
                    lstDepartment.add(departmentDTO);
                }
                if (selectedValues.size() == 1) {
                    DepartmentDTO departmentDTO;
                    departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                    DialogCreateDepartment dialogCreateContract = new DialogCreateDepartment(
                            BundleUtils.getString("department.management.panel.updateDepartment"),
                            departmentDTO);
                    dialogCreateDepartmentController = new DialogCreateDepartmentController(
                            dialogCreateContract, Constants.EDIT, tblDepartment, tblStaff,
                            staffForm.getF9Departments());
                    dialogCreateDepartmentController.init(departmentDTO);
                    UI.getCurrent().addWindow(dialogCreateContract);
                } else {
                    Notification.show(BundleUtils.getString("dept.staff.alert.message.pleasechoose"));
                }
            } else {
                CommonUtils.showChoseOne();
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    btnCopyDept.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            //                DepartmentDTO selectedValues = (DepartmentDTO) tblDepartment.getValue();
            Set<DepartmentDTO> selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
            if (selectedValues != null) {
                List<DepartmentDTO> lstDepartment = Lists.newArrayList();
                for (DepartmentDTO departmentDTO : selectedValues) {
                    lstDepartment.add(departmentDTO);
                }
                if (selectedValues.size() == 1) {
                    DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                    DialogCreateDepartment dialogCreateContract = new DialogCreateDepartment(
                            BundleUtils.getString("department.management.panel.copyDepartment"), departmentDTO);
                    dialogCreateDepartmentController = new DialogCreateDepartmentController(
                            dialogCreateContract, Constants.COPY, tblDepartment, tblStaff,
                            staffForm.getF9Departments());
                    dialogCreateDepartmentController.init(departmentDTO);
                    UI.getCurrent().addWindow(dialogCreateContract);
                } else {
                    Notification.show(BundleUtils.getString("dept.staff.alert.message.pleasechoose"));
                }
            } else {
                CommonUtils.showChoseOne();
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });

    listDepartmentController.getBtnDel().addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();

            if (selectedValues.isEmpty()) {
                CommonUtils.showChoseOne();
            } else {
                final DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues.toArray()[0];
                ConfirmDialog.show(UI.getCurrent(), BundleUtils.getString("titleMessage") + "",
                        BundleUtils.getString("bodyMessage"), BundleUtils.getString("yes"),
                        BundleUtils.getString("no"), new ConfirmDialog.Listener() {
                            @Override
                            public void onClose(ConfirmDialog dialog) {
                                // tiepnv6 edit 16h 15/07/15
                                // check neu phong ban la cha thi khong xoa
                                if (deptIsParent(departmentDTO)) {
                                    Notification.show(
                                            BundleUtils.getString("dept.staff.required.delete.staff.1"),
                                            Notification.Type.HUMANIZED_MESSAGE);
                                    return;
                                }
                                //check neu bang phong ban co nhan vien thi xoa phong ban fai xoa het nv
                                if (!checkHasValue(departmentDTO)) {
                                    if (dialog.isConfirmed()) {
                                        List<DepartmentDTO> lstDeptDel = Lists.newArrayList();
                                        lstDeptDel.addAll(selectedValues);
                                        if (selectedValues.size() > 1) {
                                            //neu dept khong co dept cap con thi xoa
                                            List<DepartmentDTO> listChildOfDept = Lists.newArrayList();
                                            DepartmentDTO deptDTODel = new DepartmentDTO();
                                            deptDTODel = lstDeptDel.get(0);
                                            listChildOfDept = getChildDepartment(deptDTODel);
                                            if (listChildOfDept != null) {
                                                // Notification with default settings for a warning
                                                String showDepartmentChild = "";
                                                for (DepartmentDTO listChildOfDept1 : listChildOfDept) {
                                                    listChildOfDept1.getName();
                                                    showDepartmentChild += listChildOfDept1.getName() + ", ";
                                                }
                                                Notification notif = new Notification(
                                                        BundleUtils.getString("Warning"),
                                                        BundleUtils
                                                                .getString("message.required.deleteDepartment")
                                                                + "<br/>" + showDepartmentChild,
                                                        Notification.Type.TRAY_NOTIFICATION);
                                                notif.setDelayMsec(20000);
                                                notif.setPosition(Position.BOTTOM_RIGHT);
                                                notif.setStyleName("mystyle");
                                                notif.show(Page.getCurrent());
                                                //
                                            } else {
                                                message = doDeleteLstDept(lstDeptDel);
                                            }
                                            if (message.contains(Constants.SUCCESS)) {
                                                for (DepartmentDTO deptDTO : lstDeptDel) {
                                                    tblDepartment.removeItem(deptDTO);
                                                }
                                                tblDepartment.refreshRowCache();
                                                tblDepartment.resetPage();
                                                CommonUtils
                                                        .showDeleteSuccess(BundleUtils.getString("department"));
                                            } else {
                                                CommonUtils.showDeleteFail(BundleUtils.getString("department"));
                                            }
                                        } else {
                                            //                                                tblDepartment = listDepartmentsAndStaffUI.getTblListDepartmentUI().getMainTable();
                                            List<DepartmentDTO> listDepartment = Lists.newArrayList();
                                            selectedValues = (Set<DepartmentDTO>) tblDepartment.getValue();
                                            DepartmentDTO departmentDTO = (DepartmentDTO) selectedValues
                                                    .toArray()[0];
                                            //                                                departmentDTO.setUserNameLogging("Username");
                                            listDepartment.add(departmentDTO);
                                            message = doDeleteLstDept(listDepartment);
                                            if (message.contains(Constants.SUCCESS)) {

                                                tblDepartment.removeItem(departmentDTO);
                                                tblDepartment.resetPage();
                                                CommonUtils
                                                        .showDeleteSuccess(BundleUtils.getString("department"));
                                            } else {
                                                CommonUtils.showDeleteFail(BundleUtils.getString("department"));
                                            }
                                        }
                                    }
                                } else {
                                    Notification.show(BundleUtils.getString("dept.staff.required.delete.staff"),
                                            Notification.Type.HUMANIZED_MESSAGE);
                                }
                            }
                        });
            }
            CommonFunction.enableButtonAfterClick(event);
        }

    });
    btnAddMapStaffCusts.setDisableOnClick(true);
    btnAddMapStaffCusts.addClickListener(new Button.ClickListener() {

        @Override
        public void buttonClick(Button.ClickEvent event) {
            Set<StaffDTO> selectedValues = (Set<StaffDTO>) tblStaff.getValue();
            if (!DataUtil.isListNullOrEmpty(Lists.newArrayList(selectedValues))) {
                MapStaffCustomerDialog dialogAddMapStaffGoods = new MapStaffCustomerDialog();
                MapStaffCustomerController mapStaffCustomerController = new MapStaffCustomerController(
                        dialogAddMapStaffGoods, Lists.newArrayList(selectedValues), lstAllAppParams);
                DataUtil.reloadWindow(dialogAddMapStaffGoods);
                UI.getCurrent().addWindow(dialogAddMapStaffGoods);
            } else {
                CommonMessages.showWarningMessage(BundleUtils.getString("notification.staff.customer.choice"));
            }
            CommonFunction.enableButtonAfterClick(event);
        }
    });
}

From source file:com.anphat.list.controller.ListStaffController.java

private void addActionListener() {

    btnExcelExport.addClickListener(new Button.ClickListener() {

        @Override//from   w  ww . j a  v  a  2  s  .  co  m
        public void buttonClick(Button.ClickEvent event) {
            List<StaffDTO> lstStaffInfo = new ArrayList<>();
            Collection collection = (Collection) tblStaffs.getItemIds();
            lstStaffInfo.addAll(collection);
            if (!DataUtil.isListNullOrEmpty(lstStaffInfo)) {
                File fileExport = exportFile(lstStaffInfo);
                Resource res = new FileResource(fileExport);
                Page.getCurrent().open(res, BundleUtils.getString("label.caption.download").replace("@name",
                        BundleUtils.getString("staff.department.listStaff")), true);
            } else {
                //Thong bao khong co du lieu xuat file
                CommonMessages.showWarningMessage(BundleUtils.getString("common.warning.export.noData"));
            }
        }
    });

}

From source file:com.cavisson.gui.dashboard.components.controls.CommonParts.java

License:Apache License

Panel notifications() {
    Panel p = new Panel("Notifications");
    VerticalLayout content = new VerticalLayout() {
        Notification notification = new Notification("");
        TextField title = new TextField("Title");
        TextArea description = new TextArea("Description");
        MenuBar style = new MenuBar();
        MenuBar type = new MenuBar();
        String typeString = "";
        String styleString = "";
        TextField delay = new TextField();
        {/*from ww  w  .  j  a va  2 s  . c om*/
            setSpacing(true);
            setMargin(true);

            title.setInputPrompt("Title for the notification");
            title.addValueChangeListener(new ValueChangeListener() {
                @Override
                public void valueChange(final ValueChangeEvent event) {
                    if (title.getValue() == null || title.getValue().length() == 0) {
                        notification.setCaption(null);
                    } else {
                        notification.setCaption(title.getValue());
                    }
                }
            });
            title.setValue("Notification Title");
            title.setWidth("100%");
            addComponent(title);

            description.setInputPrompt("Description for the notification");
            description.addStyleName("small");
            description.addValueChangeListener(new ValueChangeListener() {
                @Override
                public void valueChange(final ValueChangeEvent event) {
                    if (description.getValue() == null || description.getValue().length() == 0) {
                        notification.setDescription(null);
                    } else {
                        notification.setDescription(description.getValue());
                    }
                }
            });
            description.setValue(
                    "A more informative message about what has happened. Nihil hic munitissimus habendi senatus locus, nihil horum? Inmensae subtilitatis, obscuris et malesuada fames. Hi omnes lingua, institutis, legibus inter se differunt.");
            description.setWidth("100%");
            addComponent(description);

            Command typeCommand = new Command() {
                @Override
                public void menuSelected(final MenuItem selectedItem) {
                    if (selectedItem.getText().equals("Humanized")) {
                        typeString = "";
                        notification.setStyleName(styleString.trim());
                    } else {
                        typeString = selectedItem.getText().toLowerCase();
                        notification.setStyleName((typeString + " " + styleString.trim()).trim());
                    }
                    for (MenuItem item : type.getItems()) {
                        item.setChecked(false);
                    }
                    selectedItem.setChecked(true);
                }
            };

            type.setCaption("Type");
            MenuItem humanized = type.addItem("Humanized", typeCommand);
            humanized.setCheckable(true);
            humanized.setChecked(true);
            type.addItem("Tray", typeCommand).setCheckable(true);
            type.addItem("Warning", typeCommand).setCheckable(true);
            type.addItem("Error", typeCommand).setCheckable(true);
            type.addItem("System", typeCommand).setCheckable(true);
            addComponent(type);
            type.addStyleName("small");

            Command styleCommand = new Command() {
                @Override
                public void menuSelected(final MenuItem selectedItem) {
                    styleString = "";
                    for (MenuItem item : style.getItems()) {
                        if (item.isChecked()) {
                            styleString += " " + item.getText().toLowerCase();
                        }
                    }
                    if (styleString.trim().length() > 0) {
                        notification.setStyleName((typeString + " " + styleString.trim()).trim());
                    } else if (typeString.length() > 0) {
                        notification.setStyleName(typeString.trim());
                    } else {
                        notification.setStyleName(null);
                    }
                }
            };

            style.setCaption("Additional style");
            style.addItem("Dark", styleCommand).setCheckable(true);
            style.addItem("Success", styleCommand).setCheckable(true);
            style.addItem("Failure", styleCommand).setCheckable(true);
            style.addItem("Bar", styleCommand).setCheckable(true);
            style.addItem("Small", styleCommand).setCheckable(true);
            style.addItem("Closable", styleCommand).setCheckable(true);
            addComponent(style);
            style.addStyleName("small");

            CssLayout group = new CssLayout();
            group.setCaption("Fade delay");
            group.addStyleName("v-component-group");
            addComponent(group);

            delay.setInputPrompt("Infinite");
            delay.addStyleName("align-right");
            delay.addStyleName("small");
            delay.setWidth("7em");
            delay.addValueChangeListener(new ValueChangeListener() {
                @Override
                public void valueChange(final ValueChangeEvent event) {
                    try {
                        notification.setDelayMsec(Integer.parseInt(delay.getValue()));
                    } catch (Exception e) {
                        notification.setDelayMsec(-1);
                        delay.setValue("");
                    }

                }
            });
            delay.setValue("1000");
            group.addComponent(delay);

            Button clear = new Button(null, new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    delay.setValue("");
                }
            });
            clear.setIcon(FontAwesome.TIMES_CIRCLE);
            clear.addStyleName("last");
            clear.addStyleName("small");
            clear.addStyleName("icon-only");
            group.addComponent(clear);
            group.addComponent(new Label("&nbsp; msec", ContentMode.HTML));

            GridLayout grid = new GridLayout(3, 3);
            grid.setCaption("Show in position");
            addComponent(grid);
            grid.setSpacing(true);

            Button pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.TOP_LEFT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.TOP_CENTER);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.TOP_RIGHT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.MIDDLE_LEFT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.MIDDLE_CENTER);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.MIDDLE_RIGHT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.BOTTOM_LEFT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.BOTTOM_CENTER);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

            pos = new Button("", new ClickListener() {
                @Override
                public void buttonClick(final ClickEvent event) {
                    notification.setPosition(Position.BOTTOM_RIGHT);
                    notification.show(Page.getCurrent());
                }
            });
            pos.addStyleName("small");
            grid.addComponent(pos);

        }
    };
    p.setContent(content);

    return p;
}

From source file:com.cavisson.gui.dashboard.components.controls.ValoThemeUI.java

License:Apache License

@Override
protected void init(final VaadinRequest request) {
    if (request.getParameter("test") != null) {
        testMode = true;//from   www.j av  a  2s  .c  o m

        if (browserCantRenderFontsConsistently()) {
            getPage().getStyles().add(".v-app.v-app.v-app {font-family: Sans-Serif;}");
        }
    }

    if (getPage().getWebBrowser().isIE() && getPage().getWebBrowser().getBrowserMajorVersion() == 9) {
        menu.setWidth("320px");
    }
    // Show .v-app-loading valo-menu-badge
    // try {
    // Thread.sleep(2000);
    // } catch (InterruptedException e) {
    // e.printStackTrace();
    // }

    if (!testMode) {
        Responsive.makeResponsive(this);
    }

    getPage().setTitle("Valo Theme Test");
    setContent(root);
    root.setWidth("100%");

    root.addMenu(buildMenu());

    navigator = new Navigator(this, viewDisplay);

    navigator.addView("common", CommonParts.class);
    navigator.addView("labels", Labels.class);
    navigator.addView("buttons-and-links", ButtonsAndLinks.class);
    navigator.addView("textfields", TextFields.class);
    navigator.addView("datefields", DateFields.class);
    navigator.addView("comboboxes", ComboBoxes.class);
    navigator.addView("checkboxes", CheckBoxes.class);
    navigator.addView("sliders", Sliders.class);
    navigator.addView("menubars", MenuBars.class);
    navigator.addView("panels", Panels.class);
    navigator.addView("trees", Trees.class);
    navigator.addView("tables", Tables.class);
    navigator.addView("splitpanels", SplitPanels.class);
    navigator.addView("tabs", Tabsheets.class);
    navigator.addView("accordions", Accordions.class);
    navigator.addView("colorpickers", ColorPickers.class);
    navigator.addView("selects", NativeSelects.class);
    navigator.addView("calendar", CalendarTest.class);
    navigator.addView("forms", Forms.class);
    navigator.addView("popupviews", PopupViews.class);
    navigator.addView("dragging", Dragging.class);

    final String f = Page.getCurrent().getUriFragment();
    if (f == null || f.equals("")) {
        navigator.navigateTo("common");
    }

    navigator.setErrorView(CommonParts.class);

    navigator.addViewChangeListener(new ViewChangeListener() {

        @Override
        public boolean beforeViewChange(final ViewChangeEvent event) {
            return true;
        }

        @Override
        public void afterViewChange(final ViewChangeEvent event) {
            for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) {
                it.next().removeStyleName("selected");
            }
            for (final Entry<String, String> item : menuItems.entrySet()) {
                if (event.getViewName().equals(item.getKey())) {
                    for (final Iterator<Component> it = menuItemsLayout.iterator(); it.hasNext();) {
                        final Component c = it.next();
                        if (c.getCaption() != null && c.getCaption().startsWith(item.getValue())) {
                            c.addStyleName("selected");
                            break;
                        }
                    }
                    break;
                }
            }
            menu.removeStyleName("valo-menu-visible");
        }
    });

}

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

License:Open Source License

/**
 *
 * @param file/*  w w  w  .  j  a  va 2  s .  com*/
 * @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 {/*  ww  w.  j a 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.community.shell.view.components.AboutWindow.java

License:Open Source License

public AboutWindow() {

    MHorizontalLayout content = new MHorizontalLayout().withMargin(true).withFullWidth();
    this.setContent(content);

    Image about = new Image("", new AssetResource(WebResourceIds._about));
    MVerticalLayout rightPanel = new MVerticalLayout();
    ELabel versionLbl = ELabel.h2(String.format("MyCollab Community Edition %s", MyCollabVersion.getVersion()));
    Label javaNameLbl = new Label(String.format("%s, %s", System.getProperty("java.vm.name"),
            System.getProperty("java.runtime.version")));
    Label homeFolderLbl = new Label("Home folder: " + FileUtils.getHomeFolder().getAbsolutePath());
    WebBrowser browser = Page.getCurrent().getWebBrowser();
    Label osLbl = new Label(
            String.format("%s, %s", System.getProperty("os.name"), browser.getBrowserApplication()));
    osLbl.addStyleName(UIConstants.LABEL_WORD_WRAP);
    Div licenseDiv = new Div().appendChild(new Text("Powered by: "))
            .appendChild(new A("https://www.mycollab.com").appendText("MyCollab"))
            .appendChild(new Text(". Open source under GPL license"));
    Label licenseLbl = new Label(licenseDiv.write(), ContentMode.HTML);
    Label copyRightLbl = new Label(String.format("&copy; %s - %s MyCollab Ltd. All rights reserved", "2011",
            new GregorianCalendar().get(Calendar.YEAR) + ""), ContentMode.HTML);
    rightPanel.with(versionLbl, javaNameLbl, osLbl, homeFolderLbl, licenseLbl, copyRightLbl)
            .withAlign(copyRightLbl, Alignment.BOTTOM_LEFT);
    content.with(about, rightPanel).expand(rightPanel);
}