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.esofthead.mycollab.community.ui.chart.JFreeChartWrapper.java

License:Open Source License

@Override
public void attach() {
    super.attach();
    if (mode == RenderingMode.AUTO) {
        WebBrowser browser = Page.getCurrent().getWebBrowser();
        if (browser.isIE() && browser.getBrowserMajorVersion() < 9) {
            setRenderingMode(RenderingMode.PNG);
        } else {//from w w w  . j  a  va2 s  .c o m
            // all decent browsers support SVG
            setRenderingMode(RenderingMode.SVG);
        }
    }
    setResource("src", getSource());
}

From source file:com.esofthead.mycollab.mobile.MobileApplication.java

License:Open Source License

@Override
protected void init(VaadinRequest request) {
    LOG.debug("Init mycollab mobile application {}", this.toString());

    VaadinSession.getCurrent().setErrorHandler(new DefaultErrorHandler() {
        private static final long serialVersionUID = 1L;

        @Override//from  ww  w  . j av  a 2 s.  c om
        public void error(com.vaadin.server.ErrorEvent event) {
            Throwable e = event.getThrowable();
            IgnoreException ignoreException = (IgnoreException) getExceptionType(e, IgnoreException.class);
            if (ignoreException != null) {
                return;
            }

            SessionExpireException sessionExpireException = (SessionExpireException) getExceptionType(e,
                    SessionExpireException.class);
            if (sessionExpireException != null) {
                Page.getCurrent().getJavaScript().execute("window.location.reload();");
                return;
            }

            UserInvalidInputException invalidException = (UserInvalidInputException) getExceptionType(e,
                    UserInvalidInputException.class);
            if (invalidException != null) {
                NotificationUtil.showWarningNotification(AppContext
                        .getMessage(GenericI18Enum.ERROR_USER_INPUT_MESSAGE, invalidException.getMessage()));
            } else {

                UsageExceedBillingPlanException usageBillingException = (UsageExceedBillingPlanException) getExceptionType(
                        e, UsageExceedBillingPlanException.class);
                if (usageBillingException != null) {
                    if (AppContext.isAdmin()) {
                        ConfirmDialog.show(UI.getCurrent(),
                                AppContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_ADMIN),
                                AppContext.getMessage(GenericI18Enum.BUTTON_YES),
                                AppContext.getMessage(GenericI18Enum.BUTTON_NO),
                                new ConfirmDialog.CloseListener() {
                                    private static final long serialVersionUID = 1L;

                                    @Override
                                    public void onClose(ConfirmDialog dialog) {
                                        if (dialog.isConfirmed()) {
                                            Collection<Window> windowsList = UI.getCurrent().getWindows();
                                            for (Window window : windowsList) {
                                                window.close();
                                            }
                                            EventBusFactory.getInstance()
                                                    .post(new ShellEvent.GotoUserAccountModule(this,
                                                            new String[] { "billing" }));
                                        }
                                    }
                                });

                    } else {
                        NotificationUtil.showErrorNotification(
                                AppContext.getMessage(GenericI18Enum.EXCEED_BILLING_PLAN_MSG_FOR_USER));
                    }
                } else {
                    LOG.error("Error", e);
                    NotificationUtil.showErrorNotification(
                            AppContext.getMessage(GenericI18Enum.ERROR_USER_NOTICE_INFORMATION_MESSAGE));
                }
            }

        }
    });

    initialUrl = this.getPage().getUriFragment();
    MyCollabSession.putVariable(CURRENT_APP, this);
    currentContext = new AppContext();
    postSetupApp(request);
    try {
        currentContext.initDomain(initialSubDomain);
    } catch (Exception e) {
        // TODO: show content notice user there is no existing domain
        return;
    }

    this.getLoadingIndicatorConfiguration().setFirstDelay(0);
    this.getLoadingIndicatorConfiguration().setSecondDelay(300);
    this.getLoadingIndicatorConfiguration().setThirdDelay(500);

    final MobileNavigationManager manager = new MobileNavigationManager();
    manager.addNavigationListener(new NavigationManager.NavigationListener() {
        private static final long serialVersionUID = -2317588983851761998L;

        @SuppressWarnings("unchecked")
        @Override
        public void navigate(NavigationEvent event) {
            NavigationManager currentNavigator = (NavigationManager) event.getSource();
            if (event.getDirection() == Direction.BACK) {
                Component nextComponent = currentNavigator.getNextComponent();
                ViewState currentState = MobileHistoryViewManager.peak();

                if (!(currentState instanceof NullViewState)
                        && currentState.getPresenter().getView().equals(nextComponent)) {
                    ViewState viewState = MobileHistoryViewManager.pop();
                    while (!(viewState instanceof NullViewState)) {
                        if (viewState.getPresenter().getView().equals(currentNavigator.getCurrentComponent())) {
                            viewState.getPresenter().go(viewState.getContainer(), viewState.getParams());
                            break;
                        }
                        viewState = MobileHistoryViewManager.pop(false);
                    }
                }
                if (nextComponent instanceof NavigationView) {
                    ((NavigationView) nextComponent).setPreviousComponent(null);
                }
                currentNavigator.removeComponent(nextComponent);
                currentNavigator.getState().setNextComponent(null);

            }
        }
    });
    setContent(manager);

    registerControllers(manager);

    getPage().addUriFragmentChangedListener(new UriFragmentChangedListener() {

        private static final long serialVersionUID = -6410955178515535406L;

        @Override
        public void uriFragmentChanged(UriFragmentChangedEvent event) {
            setInitialUrl(event.getUriFragment());
            enter(event.getUriFragment());
        }
    });
    enter(initialUrl);
}

From source file:com.esofthead.mycollab.module.project.view.assignments.gantt.GanttExt.java

License:Open Source License

public GanttExt() {
    this.setTimeZone(TimeZone.getTimeZone("Atlantic/Reykjavik"));
    this.setImmediate(true);
    minDate = new LocalDate(2100, 1, 1);
    maxDate = new LocalDate(1970, 1, 1);
    this.setResizableSteps(true);
    this.setMovableSteps(true);
    this.setHeight((Page.getCurrent().getBrowserWindowHeight() - 270) + "px");
    beanContainer = new GanttItemContainer();

    this.addClickListener(new Gantt.ClickListener() {
        @Override/*ww w .j a va  2  s  .c  o  m*/
        public void onGanttClick(Gantt.ClickEvent event) {
            if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
                StepExt step = (StepExt) event.getStep();
                getUI().addWindow(new QuickEditGanttItemWindow(GanttExt.this, step.getGanttItemWrapper()));
            }
        }
    });

    this.addMoveListener(new Gantt.MoveListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void onGanttMove(MoveEvent event) {
            if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
                updateTasksInfoByResizeOrMove((StepExt) event.getStep(), event.getStartDate(),
                        event.getEndDate());
            }
        }
    });

    this.addResizeListener(new Gantt.ResizeListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void onGanttResize(ResizeEvent event) {
            if (CurrentProjectVariables.canWrite(ProjectRolePermissionCollections.TASKS)) {
                updateTasksInfoByResizeOrMove((StepExt) event.getStep(), event.getStartDate(),
                        event.getEndDate());
            }
        }
    });
}

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

License:Open Source License

AccountInfoChangeWindow() {
    super(AppContext.getMessage(AdminI18nEnum.OPT_CHANGE_ACCOUNT_INFO));
    this.setModal(true);
    this.setResizable(false);
    this.setWidth("700px");

    billingAccount = BeanUtility.deepClone(AppContext.getBillingAccount());
    MVerticalLayout content = new MVerticalLayout();
    this.setContent(content);
    editForm = new AdvancedEditBeanForm<>();
    editForm.setFormLayoutFactory(new AbstractFormLayoutFactory() {
        private GridFormLayoutHelper gridFormLayoutHelper = GridFormLayoutHelper.defaultFormLayoutHelper(1, 9,
                "200px");

        @Override//w w w  .  ja  v  a 2 s .c  o  m
        public ComponentContainer getLayout() {
            return gridFormLayoutHelper.getLayout();
        }

        @Override
        public Component onAttachField(Object propertyId, Field<?> field) {
            if (BillingAccount.Field.sitename.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_SITE_NAME), 0, 0);
            } else if (BillingAccount.Field.subdomain.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_SITE_ADDRESS), 0, 1);
            } else if (BillingAccount.Field.defaulttimezone.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_TIMEZONE), 0, 2);
            } else if (BillingAccount.Field.defaultcurrencyid.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_CURRENCY), 0, 3);
            } else if (BillingAccount.Field.defaultyymmddformat.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_YYMMDD_FORMAT),
                        AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 4);
            } else if (BillingAccount.Field.defaultmmddformat.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_MMDD_FORMAT),
                        AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 5);
            } else if (BillingAccount.Field.defaulthumandateformat.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_HUMAN_DATE_FORMAT),
                        AppContext.getMessage(GenericI18Enum.FORM_DATE_FORMAT_HELP), 0, 6);
            } else if (BillingAccount.Field.defaultlanguagetag.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_DEFAULT_LANGUAGE), 0, 7);
            } else if (BillingAccount.Field.displayemailpublicly.equalTo(propertyId)) {
                return gridFormLayoutHelper.addComponent(field,
                        AppContext.getMessage(AdminI18nEnum.FORM_SHOW_EMAIL_PUBLICLY),
                        AppContext.getMessage(AdminI18nEnum.FORM_SHOW_EMAIL_PUBLICLY_HELP), 0, 8);
            }
            return null;
        }
    });

    editForm.setBeanFormFieldFactory(
            new AbstractBeanFieldGroupEditFieldFactory<SimpleBillingAccount>(editForm) {
                @Override
                protected Field<?> onCreateField(Object propertyId) {
                    if (BillingAccount.Field.subdomain.equalTo(propertyId)) {
                        return new SubDomainField();
                    } else if (BillingAccount.Field.defaulttimezone.equalTo(propertyId)) {
                        return new TimeZoneSelectionField(false);
                    } else if (BillingAccount.Field.defaultcurrencyid.equalTo(propertyId)) {
                        return new CurrencyComboBoxField();
                    } else if (BillingAccount.Field.defaultyymmddformat.equalTo(propertyId)) {
                        return new DateFormatField(billingAccount.getDateFormatInstance());
                    } else if (BillingAccount.Field.defaultmmddformat.equalTo(propertyId)) {
                        return new DateFormatField(billingAccount.getShortDateFormatInstance());
                    } else if (BillingAccount.Field.defaulthumandateformat.equalTo(propertyId)) {
                        return new DateFormatField(billingAccount.getLongDateFormatInstance());
                    } else if (BillingAccount.Field.defaultlanguagetag.equalTo(propertyId)) {
                        return new LanguageSelectionField();
                    }
                    return null;
                }

            });

    editForm.setBean(billingAccount);

    MHorizontalLayout buttonControls = new MHorizontalLayout().withMargin(true);
    Button saveBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_SAVE), new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent clickEvent) {
            if (editForm.validateForm()) {
                BillingAccountService billingAccountService = AppContextUtil
                        .getSpringBean(BillingAccountService.class);
                billingAccountService.updateSelectiveWithSession(billingAccount, AppContext.getUsername());
                close();
                String siteUrl = SiteConfiguration.getSiteUrl(billingAccount.getSubdomain());
                String assignExec = String.format("window.location.assign(\'%s\');", siteUrl);
                Page.getCurrent().getJavaScript().execute(assignExec);
            }
        }
    });
    saveBtn.setIcon(FontAwesome.SAVE);
    saveBtn.setStyleName(UIConstants.BUTTON_ACTION);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    close();
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);
    buttonControls.with(cancelBtn, saveBtn);

    content.with(editForm, buttonControls).withAlign(buttonControls, Alignment.MIDDLE_RIGHT);
}

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

License:Open Source License

private void buildLogoPanel() {
    FormContainer formContainer = new FormContainer();
    MHorizontalLayout layout = new MHorizontalLayout().withFullWidth().withMargin(true);
    MVerticalLayout leftPanel = new MVerticalLayout().withMargin(false);
    Label logoDesc = new Label(AppContext.getMessage(AdminI18nEnum.OPT_LOGO_FORMAT_DESCRIPTION));
    leftPanel.with(logoDesc).withWidth("250px");

    MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false);
    CustomLayout previewLayout = CustomLayoutExt.createLayout("topNavigation");
    previewLayout.setStyleName("example-block");
    previewLayout.setHeight("40px");
    previewLayout.setWidth("520px");

    Button currentLogo = AccountAssetsResolver.createAccountLogoImageComponent(billingAccount.getLogopath(),
            150);//from   w ww .j  a  v a2s  .  co m
    previewLayout.addComponent(currentLogo, "mainLogo");
    final ServiceMenu serviceMenu = new ServiceMenu();

    Button.ClickListener clickListener = new Button.ClickListener() {
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(final Button.ClickEvent event) {
            Iterator<Component> iterator = serviceMenu.iterator();

            while (iterator.hasNext()) {
                Component comp = iterator.next();
                if (comp != event.getButton()) {
                    comp.removeStyleName("selected");
                }
            }
            event.getButton().addStyleName("selected");
        }
    };

    serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_CRM), VaadinIcons.MONEY, clickListener);
    serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_PROJECT), VaadinIcons.TASKS,
            clickListener);
    serviceMenu.addService(AppContext.getMessage(GenericI18Enum.MODULE_DOCUMENT), VaadinIcons.SUITCASE,
            clickListener);
    serviceMenu.selectService(0);

    previewLayout.addComponent(serviceMenu, "serviceMenu");

    MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(true, false, false, false));
    buttonControls.setDefaultComponentAlignment(Alignment.TOP_LEFT);
    final UploadField logoUploadField = new UploadField() {
        private static final long serialVersionUID = 1L;

        @Override
        protected void updateDisplay() {
            byte[] imageData = (byte[]) this.getValue();
            String mimeType = this.getLastMimeType();
            if (mimeType.equals("image/jpeg")) {
                imageData = ImageUtil.convertJpgToPngFormat(imageData);
                if (imageData == null) {
                    throw new UserInvalidInputException(
                            AppContext.getMessage(FileI18nEnum.ERROR_INVALID_SUPPORTED_IMAGE_FORMAT));
                } else {
                    mimeType = "image/png";
                }
            }

            if (mimeType.equals("image/png")) {
                UI.getCurrent().addWindow(new LogoEditWindow(imageData));
            } else {
                throw new UserInvalidInputException(
                        AppContext.getMessage(FileI18nEnum.ERROR_UPLOAD_INVALID_SUPPORTED_IMAGE_FORMAT));
            }
        }
    };
    logoUploadField.setButtonCaption(AppContext.getMessage(GenericI18Enum.ACTION_CHANGE));
    logoUploadField.addStyleName("upload-field");
    logoUploadField.setSizeUndefined();
    logoUploadField.setFieldType(UploadField.FieldType.BYTE_ARRAY);
    logoUploadField.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));

    Button resetButton = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_RESET),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    BillingAccountService billingAccountService = AppContextUtil
                            .getSpringBean(BillingAccountService.class);
                    billingAccount.setLogopath(null);
                    billingAccountService.updateWithSession(billingAccount, AppContext.getUsername());
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                }
            });
    resetButton.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));
    resetButton.setStyleName(UIConstants.BUTTON_OPTION);
    buttonControls.with(logoUploadField, resetButton);
    rightPanel.with(previewLayout, buttonControls);
    layout.with(leftPanel, rightPanel).expand(rightPanel);
    formContainer.addSection("Logo", layout);
    this.with(formContainer);
}

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

License:Open Source License

private void buildShortcutIconPanel() {
    FormContainer formContainer = new FormContainer();
    MHorizontalLayout layout = new MHorizontalLayout().withFullWidth().withMargin(new MarginInfo(true));
    MVerticalLayout leftPanel = new MVerticalLayout().withMargin(false);
    Label logoDesc = new Label(AppContext.getMessage(FileI18nEnum.OPT_FAVICON_FORMAT_DESCRIPTION));
    leftPanel.with(logoDesc).withWidth("250px");
    MVerticalLayout rightPanel = new MVerticalLayout().withMargin(false);
    final Image favIconRes = new Image("", new ExternalResource(StorageFactory.getInstance()
            .getFavIconPath(billingAccount.getId(), billingAccount.getFaviconpath())));

    MHorizontalLayout buttonControls = new MHorizontalLayout()
            .withMargin(new MarginInfo(true, false, false, false));
    buttonControls.setDefaultComponentAlignment(Alignment.BOTTOM_LEFT);
    final UploadField favIconUploadField = new UploadField() {
        private static final long serialVersionUID = 1L;

        @Override/* w  w w  .  ja  v  a2 s .c o  m*/
        protected void updateDisplay() {
            byte[] imageData = (byte[]) this.getValue();
            String mimeType = this.getLastMimeType();
            if (mimeType.equals("image/jpeg")) {
                imageData = ImageUtil.convertJpgToPngFormat(imageData);
                if (imageData == null) {
                    throw new UserInvalidInputException(
                            AppContext.getMessage(FileI18nEnum.ERROR_INVALID_SUPPORTED_IMAGE_FORMAT));
                } else {
                    mimeType = "image/png";
                }
            }

            if (mimeType.equals("image/png")) {
                try {
                    AccountFavIconService favIconService = AppContextUtil
                            .getSpringBean(AccountFavIconService.class);
                    BufferedImage image = ImageIO.read(new ByteArrayInputStream(imageData));
                    String newFavIconPath = favIconService.upload(AppContext.getUsername(), image,
                            AppContext.getAccountId());
                    favIconRes.setSource(new ExternalResource(StorageFactory.getInstance()
                            .getFavIconPath(billingAccount.getId(), newFavIconPath)));
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                } catch (IOException e) {
                    throw new MyCollabException(e);
                }
            } else {
                throw new UserInvalidInputException(
                        AppContext.getMessage(FileI18nEnum.ERROR_UPLOAD_INVALID_SUPPORTED_IMAGE_FORMAT));
            }
        }
    };
    favIconUploadField.setButtonCaption(AppContext.getMessage(GenericI18Enum.ACTION_CHANGE));
    favIconUploadField.addStyleName("upload-field");
    favIconUploadField.setSizeUndefined();
    favIconUploadField.setFieldType(UploadField.FieldType.BYTE_ARRAY);
    favIconUploadField.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));

    Button resetButton = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_RESET),
            new Button.ClickListener() {
                @Override
                public void buttonClick(Button.ClickEvent clickEvent) {
                    BillingAccountService billingAccountService = AppContextUtil
                            .getSpringBean(BillingAccountService.class);
                    billingAccount.setFaviconpath(null);
                    billingAccountService.updateWithSession(billingAccount, AppContext.getUsername());
                    Page.getCurrent().getJavaScript().execute("window.location.reload();");
                }
            });
    resetButton.setEnabled(AppContext.canBeYes(RolePermissionCollections.ACCOUNT_THEME));
    resetButton.setStyleName(UIConstants.BUTTON_OPTION);

    buttonControls.with(favIconUploadField, resetButton);
    rightPanel.with(favIconRes, buttonControls);
    layout.with(leftPanel, rightPanel).expand(rightPanel);
    formContainer.addSection("Favicon", layout);
    this.with(formContainer);
}

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

License:Open Source License

private void editPhoto(byte[] imageData) {
    try {/*from w ww.j a v a2 s .c om*/
        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 = AppContext.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));

    Label lbPreview = new Label(
            "<p style='margin: 0px;'><strong>To the below is what your logo will look like.</strong></p><p "
                    + "style='margin-top: 0px;'>To make adjustment, you can drag around and resize the selection square below. "
                    + "When you are happy with your photo, click the <strong>Accept</strong> button.</p>",
            ContentMode.HTML);
    previewBoxRight.addComponent(lbPreview);

    MHorizontalLayout controlBtns = new MHorizontalLayout();
    controlBtns.setSizeUndefined();
    controlBtns.setDefaultComponentAlignment(Alignment.MIDDLE_LEFT);

    Button cancelBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_CANCEL),
            new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    EventBusFactory.getInstance()
                            .post(new SettingEvent.GotoGeneralSetting(LogoEditWindow.this, null));
                }
            });
    cancelBtn.setStyleName(UIConstants.BUTTON_OPTION);
    controlBtns.with(cancelBtn);

    Button acceptBtn = new Button(AppContext.getMessage(GenericI18Enum.BUTTON_ACCEPT),
            new Button.ClickListener() {
                @Override
                public void buttonClick(ClickEvent event) {
                    if (scaleImageData != null && scaleImageData.length > 0) {
                        try {
                            BufferedImage image = ImageIO.read(new ByteArrayInputStream(scaleImageData));
                            AccountLogoService accountLogoService = AppContextUtil
                                    .getSpringBean(AccountLogoService.class);
                            accountLogoService.upload(AppContext.getUsername(), image,
                                    AppContext.getAccountId());
                            Page.getCurrent().getJavaScript().execute("window.location.reload();");
                        } catch (IOException e) {
                            throw new MyCollabException("Error when saving account logo", e);
                        }

                    }

                }
            });
    acceptBtn.setStyleName(UIConstants.BUTTON_ACTION);
    controlBtns.with(acceptBtn);

    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(new Property.ValueChangeListener() {

        @Override
        public void valueChange(Property.ValueChangeEvent event) {
            VCropSelection newSelection = (VCropSelection) event.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.esofthead.mycollab.module.user.accountsettings.profile.view.AdvancedInfoChangeWindow.java

License:Open Source License

private void changeInfo() {
    this.user.setWebsite(this.txtWebsite.getValue());
    this.user.setCompany(this.txtCompany.getValue());
    this.user.setCountry((String) this.cboCountry.getValue());

    final UserService userService = ApplicationContextUtil.getSpringBean(UserService.class);
    userService.updateWithSession(this.user, AppContext.getUsername());

    EventBusFactory.getInstance().post(new ProfileEvent.GotoProfileView(AdvancedInfoChangeWindow.this, null));
    AdvancedInfoChangeWindow.this.close();

    Page.getCurrent().getJavaScript().execute("window.location.reload();");
}

From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.BasicInfoChangeWindow.java

License:Open Source License

private void changeUserInfo() {

    this.txtLastName.removeStyleName("errorField");
    this.txtEmail.removeStyleName("errorField");

    if (this.txtLastName.getValue().equals("")) {
        NotificationUtil.showErrorNotification("The last name must be not null!");
        this.txtLastName.addStyleName("errorField");
        return;// w w w . ja v a 2  s . c  om
    }

    if (this.txtEmail.getValue().equals("")) {
        NotificationUtil.showErrorNotification("The email must be not null!");
        this.txtLastName.addStyleName("errorField");
        return;
    }

    this.user.setFirstname(this.txtFirstName.getValue());
    this.user.setLastname(this.txtLastName.getValue());
    this.user.setEmail(this.txtEmail.getValue());
    this.user.setDateofbirth(this.birthdayField.getDate());
    this.user.setLanguage((String) this.languageBox.getValue());
    this.user.setTimezone(this.timeZoneField.getTimeZone().getId());

    MyCollabSession.removeVariable(USER_TIMEZONE);
    MyCollabSession.putVariable(USER_TIMEZONE, this.timeZoneField.getTimeZone().getTimezone());

    final UserService userService = ApplicationContextUtil.getSpringBean(UserService.class);
    userService.updateWithSession(this.user, AppContext.getUsername());

    EventBusFactory.getInstance().post(new ProfileEvent.GotoProfileView(BasicInfoChangeWindow.this, null));
    BasicInfoChangeWindow.this.close();
    Page.getCurrent().getJavaScript().execute("window.location.reload();");

}

From source file:com.esofthead.mycollab.module.user.accountsettings.profile.view.ContactInfoChangeWindow.java

License:Open Source License

private void changeUserInfo() {

    this.txtWorkPhone.removeStyleName("errorField");
    this.txtHomePhone.removeStyleName("errorField");

    this.user.setWorkphone(this.txtWorkPhone.getValue());
    this.user.setHomephone(this.txtHomePhone.getValue());
    this.user.setFacebookaccount(this.txtFaceBook.getValue());
    this.user.setTwitteraccount(this.txtTwitter.getValue());
    this.user.setSkypecontact(this.txtSkype.getValue());

    if (this.validateForm(this.user)) {
        final UserService userService = ApplicationContextUtil.getSpringBean(UserService.class);
        userService.updateWithSession(this.user, AppContext.getUsername());

        EventBusFactory.getInstance()//  w w  w  .j  a v  a2 s  . com
                .post(new ProfileEvent.GotoProfileView(ContactInfoChangeWindow.this, null));
        ContactInfoChangeWindow.this.close();
        Page.getCurrent().getJavaScript().execute("window.location.reload();");
    }

}