Example usage for com.vaadin.ui HorizontalLayout addComponent

List of usage examples for com.vaadin.ui HorizontalLayout addComponent

Introduction

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

Prototype

@Override
public void addComponent(Component c) 

Source Link

Document

Add a component into this container.

Usage

From source file:com.hack23.cia.web.impl.ui.application.views.admin.system.pagemode.AdminApplicationConfigurationPageModContentFactoryImpl.java

License:Apache License

@Secured({ "ROLE_ADMIN" })
@Override/*from   ww w  .  j a  v  a  2  s . c o m*/
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout content = createPanelContent();

    final String pageId = getPageId(parameters);
    final int pageNr = getPageNr(parameters);

    getMenuItemFactory().createMainPageMenuBar(menuBar);

    LabelFactory.createHeader2Label(content, ADMIN_APPLICATION_CONFIGURATION);

    final DataContainer<ApplicationConfiguration, Long> dataContainer = getApplicationManager()
            .getDataContainer(ApplicationConfiguration.class);

    final BeanItemContainer<ApplicationConfiguration> politicianDocumentDataSource = new BeanItemContainer<>(
            ApplicationConfiguration.class, dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE,
                    ApplicationConfiguration_.configurationGroup));

    createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);

    getGridFactory().createBasicBeanItemGrid(content, politicianDocumentDataSource, "ApplicationConfiguration",
            new String[] { "hjid", "configurationGroup", "component", "componentTitle", "configTitle",
                    "configDescription", "componentDescription", "propertyId", "propertyValue" },
            new String[] { "hjid", "modelObjectId", "modelObjectVersion", "createdDate", "updatedDate",
                    "propertyId", "componentDescription", "componentTitle" },
            new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_CONFIGURATION_VIEW_NAME, "hjid"),
            null, null);

    if (pageId != null && !pageId.isEmpty()) {

        final ApplicationConfiguration applicationConfiguration = dataContainer.load(Long.valueOf(pageId));

        if (applicationConfiguration != null) {

            final VerticalLayout leftLayout = new VerticalLayout();
            leftLayout.setSizeFull();
            final VerticalLayout rightLayout = new VerticalLayout();
            rightLayout.setSizeFull();
            final HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setWidth(ContentSize.FULL_SIZE);
            content.addComponent(horizontalLayout);
            horizontalLayout.addComponent(leftLayout);
            horizontalLayout.addComponent(rightLayout);

            getFormFactory().addFormPanelTextFields(leftLayout, new BeanItem<>(applicationConfiguration),
                    ApplicationConfiguration.class,
                    Arrays.asList(new String[] { "configurationGroup", "component", "configTitle",
                            "configDescription", "propertyValue", "createdDate", "updatedDate" }));

            final UpdateApplicationConfigurationRequest request = new UpdateApplicationConfigurationRequest();
            request.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
            request.setApplicationConfigurationId(applicationConfiguration.getHjid());

            request.setConfigTitle(applicationConfiguration.getConfigTitle());
            request.setConfigDescription(applicationConfiguration.getConfigDescription());

            request.setComponentTitle(applicationConfiguration.getConfigTitle());
            request.setComponentDescription(applicationConfiguration.getComponentDescription());

            request.setPropertyValue(applicationConfiguration.getPropertyValue());

            final ClickListener buttonListener = new UpdateApplicationConfigurationClickListener(request,
                    getApplicationManager());

            final Panel updateFormPanel = new Panel();
            updateFormPanel.setSizeFull();

            rightLayout.addComponent(updateFormPanel);

            final FormLayout updateFormContent = new FormLayout();
            updateFormPanel.setContent(updateFormContent);

            getFormFactory().addRequestInputFormFields(updateFormContent, new BeanItem<>(request),
                    UpdateApplicationConfigurationRequest.class, Arrays.asList(new String[] { "configTitle",
                            "configDescription", "componentTitle", "componentDescription", "propertyValue" }),
                    "Update Configuration", buttonListener);

        }
    }

    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_CONFIGURATION_VIEW,
            ApplicationEventGroup.ADMIN, NAME, null, pageId);

    return content;
}

From source file:com.hack23.cia.web.impl.ui.application.views.admin.system.pagemode.AdminApplicationSessionPageModContentFactoryImpl.java

License:Apache License

@Secured({ "ROLE_ADMIN" })
@Override//from w w  w . j ava  2  s .  co  m
public Layout createContent(final String parameters, final MenuBar menuBar, final Panel panel) {
    final VerticalLayout content = createPanelContent();

    final String pageId = getPageId(parameters);
    final int pageNr = getPageNr(parameters);

    getMenuItemFactory().createMainPageMenuBar(menuBar);

    LabelFactory.createHeader2Label(content, ADMIN_APPLICATION_SESSION);

    final DataContainer<ApplicationSession, Long> dataContainer = getApplicationManager()
            .getDataContainer(ApplicationSession.class);

    final BeanItemContainer<ApplicationSession> politicianDocumentDataSource = new BeanItemContainer<>(
            ApplicationSession.class,
            dataContainer.getPageOrderBy(pageNr, DEFAULT_RESULTS_PER_PAGE, ApplicationSession_.createdDate));

    createPagingControls(content, NAME, pageId, dataContainer.getSize(), pageNr, DEFAULT_RESULTS_PER_PAGE);

    getGridFactory().createBasicBeanItemGrid(content, politicianDocumentDataSource, "ApplicationSession",
            new String[] { "hjid", "createdDate", "sessionType", "userId", "events", "operatingSystem",
                    "locale", "ipInformation", "userAgentInformation", "sessionId" },
            new String[] { "hjid", "modelObjectId", "modelObjectVersion", "userAgentInformation", "sessionId",
                    "ipInformation" },
            new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_SESSION_VIEW_NAME, "hjid"), null,
            new ListPropertyConverter[] {
                    new ListPropertyConverter(List.class, "page", "events", "actionName") });

    if (pageId != null && !pageId.isEmpty()) {

        final ApplicationSession applicationSession = dataContainer.load(Long.valueOf(pageId));

        if (applicationSession != null) {

            final VerticalLayout rightLayout = new VerticalLayout();
            rightLayout.setSizeFull();
            final HorizontalLayout horizontalLayout = new HorizontalLayout();
            horizontalLayout.setWidth(ContentSize.FULL_SIZE);
            content.addComponent(horizontalLayout);
            content.setExpandRatio(horizontalLayout, ContentRatio.GRID);

            getFormFactory().addFormPanelTextFields(horizontalLayout, new BeanItem<>(applicationSession),
                    ApplicationSession.class,
                    Arrays.asList(new String[] { "createdDate", "sessionType", "userId", "sessionId",
                            "operatingSystem", "locale", "ipInformation", "userAgentInformation" }));

            horizontalLayout.addComponent(rightLayout);
            horizontalLayout.setExpandRatio(rightLayout, ContentRatio.GRID);

            final BeanItemContainer<ApplicationActionEvent> eventsItemContainer = new BeanItemContainer<>(
                    ApplicationActionEvent.class, applicationSession.getEvents());

            getGridFactory().createBasicBeanItemGrid(rightLayout, eventsItemContainer, "ApplicationActionEvent",
                    new String[] { "hjid", "createdDate", "eventGroup", "actionName", "applicationOperation",
                            "page", "pageMode", "elementId", "errorMessage", "applicationMessage",
                            "modelObjectVersion" },
                    new String[] { "hjid", "modelObjectId", "modelObjectVersion", "userId", "sessionId" },
                    new PageItemPropertyClickListener(AdminViews.ADMIN_APPLICATIONS_EVENTS_VIEW_NAME, "hjid"),
                    null, null);
        }

    }

    getPageActionEventHelper().createPageEvent(ViewAction.VISIT_ADMIN_APPLICATION_SESSION_VIEW,
            ApplicationEventGroup.ADMIN, NAME, null, pageId);

    return content;

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.AbstractView.java

License:Apache License

/**
 * Creates the basic layout with panel and footer.
 *
 * @param panelName/*w  w w  . ja va 2  s . c  o  m*/
 *            the panel name
 */
protected final void createBasicLayoutWithPanelAndFooter(final String panelName) {
    final VerticalLayout layout = new VerticalLayout();
    layout.setMargin(true);
    layout.setSpacing(true);
    layout.setWidth(100, Unit.PERCENTAGE);
    layout.setHeight(100, Unit.PERCENTAGE);

    final VerticalLayout pageModeContent = new VerticalLayout();
    pageModeContent.setMargin(true);
    pageModeContent.setSpacing(true);
    pageModeContent.setWidth(100, Unit.PERCENTAGE);
    pageModeContent.setHeight(100, Unit.PERCENTAGE);

    layout.addComponent(pageModeContent);

    final ThemeResource ciaLogoResource = new ThemeResource("cia-logo.png");

    final Image ciaLogoImage = new Image(null, ciaLogoResource);

    final HorizontalLayout topHeader = new HorizontalLayout();

    topHeader.addComponent(ciaLogoImage);
    ciaLogoImage.setWidth("75px");
    ciaLogoImage.setHeight("75px");
    topHeader.setComponentAlignment(ciaLogoImage, Alignment.MIDDLE_LEFT);
    topHeader.setExpandRatio(ciaLogoImage, ContentRatio.SMALL);

    final HorizontalLayout topTitleHeadertPanel = new HorizontalLayout();

    final Label titleLabel = new Label("Citizen Intelligence Agency");
    titleLabel.setStyleName("Header");
    topTitleHeadertPanel.addComponent(titleLabel);
    topTitleHeadertPanel.setComponentAlignment(titleLabel, Alignment.MIDDLE_LEFT);

    final Label sloganLabel = new Label("// Tracking politicians like bugs!");
    sloganLabel.setStyleName("HeaderSlogan");
    topTitleHeadertPanel.addComponent(sloganLabel);
    topTitleHeadertPanel.setComponentAlignment(sloganLabel, Alignment.MIDDLE_RIGHT);

    topHeader.addComponent(topTitleHeadertPanel);
    topHeader.setComponentAlignment(topTitleHeadertPanel, Alignment.MIDDLE_LEFT);
    topHeader.setExpandRatio(topTitleHeadertPanel, ContentRatio.GRID);

    topHeaderRightPanel.removeAllComponents();
    topHeader.addComponent(topHeaderRightPanel);
    topHeader.setComponentAlignment(topHeaderRightPanel, Alignment.MIDDLE_RIGHT);
    topHeader.setExpandRatio(topHeaderRightPanel, ContentRatio.LARGE);

    if (UserContextUtil.allowRoleInSecurityContext(ROLE_ADMIN)
            || UserContextUtil.allowRoleInSecurityContext(ROLE_USER)) {

        final Link userHomePageLink = pageLinkFactory.createUserHomeViewPageLink();
        topHeaderRightPanel.addComponent(userHomePageLink);
        topHeaderRightPanel.setComponentAlignment(userHomePageLink, Alignment.MIDDLE_RIGHT);

        final Button logoutButton = new Button(LOGOUT, FontAwesome.SIGN_OUT);

        final LogoutRequest logoutRequest = new LogoutRequest();
        logoutRequest.setSessionId(RequestContextHolder.currentRequestAttributes().getSessionId());
        logoutButton.addClickListener(new LogoutClickListener(logoutRequest, applicationManager));

        topHeaderRightPanel.addComponent(logoutButton);
        topHeaderRightPanel.setComponentAlignment(logoutButton, Alignment.MIDDLE_RIGHT);

    } else {
        final Link createRegisterPageLink = pageLinkFactory.createRegisterPageLink();
        topHeaderRightPanel.addComponent(createRegisterPageLink);
        topHeaderRightPanel.setComponentAlignment(createRegisterPageLink, Alignment.MIDDLE_RIGHT);

        final Link createLoginPageLink = pageLinkFactory.createLoginPageLink();
        topHeaderRightPanel.addComponent(createLoginPageLink);
        topHeaderRightPanel.setComponentAlignment(createLoginPageLink, Alignment.MIDDLE_RIGHT);
    }

    topHeaderRightPanel.setWidth("100%");
    topHeaderRightPanel.setHeight("60px");

    topHeader.setWidth("100%");
    topHeader.setHeight("60px");

    pageModeContent.addComponent(topHeader);
    pageModeContent.setComponentAlignment(topHeader, Alignment.TOP_CENTER);

    pageModeContent.addComponent(getBarmenu());
    pageModeContent.setComponentAlignment(getBarmenu(), Alignment.TOP_CENTER);

    panel = new Panel(panelName);

    panel.setSizeFull();
    pageModeContent.addComponent(panel);
    pageModeContent.setExpandRatio(panel, ContentRatio.FULL_SIZE);

    pageModeContent.addComponent(pageLinkFactory.createMainViewPageLink());
    setContent(layout);

    setWidth(100, Unit.PERCENTAGE);
    setHeight(100, Unit.PERCENTAGE);
    setSizeFull();

}

From source file:com.hack23.cia.web.impl.ui.application.views.common.chartfactory.impl.AbstractChartDataManagerImpl.java

License:Apache License

/**
 * Adds the chart./*from www  . j a  v a2 s  . c  o  m*/
 *
 * @param content
 *            the content
 * @param caption
 *            the caption
 * @param chart
 *            the chart
 */
protected final void addChart(final AbstractOrderedLayout content, final String caption, final DCharts chart) {
    final HorizontalLayout horizontalLayout = new HorizontalLayout();

    final int browserWindowWidth = Page.getCurrent().getBrowserWindowWidth() - 50;
    final int browserWindowHeight = Page.getCurrent().getBrowserWindowHeight() - 200;

    horizontalLayout.setWidth(browserWindowWidth, Unit.PIXELS);
    horizontalLayout.setHeight(browserWindowHeight, Unit.PIXELS);

    final Panel formPanel = new Panel();
    formPanel.setSizeFull();
    formPanel.setContent(horizontalLayout);

    content.addComponent(formPanel);
    content.setExpandRatio(formPanel, ContentRatio.LARGE);

    chart.setWidth(browserWindowWidth - 50, Unit.PIXELS);
    chart.setHeight(browserWindowHeight - 100, Unit.PIXELS);
    chart.setMarginRight(5);
    chart.setMarginLeft(5);
    chart.setMarginBottom(5);
    chart.setMarginTop(5);

    chart.setEnableDownload(true);
    chart.setChartImageFormat(ChartImageFormat.PNG);

    horizontalLayout.addComponent(chart);
    chart.setCaption(caption);
}

From source file:com.hack23.cia.web.impl.ui.application.views.user.politician.pagemode.PoliticianOverviewPageModContentFactoryImpl.java

License:Apache License

/**
 * Creates the overview content./* w  w  w  .ja v  a2  s.com*/
 *
 * @param panelContent
 *            the panel content
 * @param personData
 *            the person data
 * @param viewRiksdagenPolitician
 *            the view riksdagen politician
 * @param pageId
 */
private void createOverviewContent(final VerticalLayout panelContent, final PersonData personData,
        final ViewRiksdagenPolitician viewRiksdagenPolitician, final String pageId) {
    LabelFactory.createHeader2Label(panelContent, OVERVIEW);

    final VerticalLayout overviewLayout = new VerticalLayout();
    overviewLayout.setSizeFull();

    panelContent.addComponent(overviewLayout);
    panelContent.setExpandRatio(overviewLayout, ContentRatio.LARGE_FORM);

    getPoliticianMenuItemFactory().createOverviewPage(overviewLayout, pageId);

    final Link createPoliticianPageLink = getPageLinkFactory().createPoliticianPageLink(personData);
    panelContent.addComponent(createPoliticianPageLink);

    final Image image = new Image("",
            new ExternalResource(personData.getImageUrl192().replace("http://", "https://")));

    final HorizontalLayout horizontalLayout = new HorizontalLayout();
    horizontalLayout.setSizeFull();

    panelContent.addComponent(horizontalLayout);

    horizontalLayout.addComponent(image);

    getFormFactory().addFormPanelTextFields(horizontalLayout, new BeanItem<>(viewRiksdagenPolitician),
            ViewRiksdagenPolitician.class,
            Arrays.asList(new String[] { "firstName", "lastName", "gender", "bornYear", "party", "active",
                    "firstAssignmentDate", "lastAssignmentDate", "currentAssignments",
                    "currentMinistryAssignments", "currentSpeakerAssignments", "currentCommitteeAssignments",
                    "currentPartyAssignments", "totalMinistryAssignments", "totalCommitteeAssignments",
                    "totalSpeakerAssignments", "totalPartyAssignments", "totalAssignments", "totalDaysServed",
                    "activeEu", "totalDaysServedEu", "activeGovernment", "totalDaysServedGovernment",
                    "activeSpeaker", "totalDaysServedSpeaker", "activeCommittee", "totalDaysServedCommittee",
                    "activeParliament", "totalDaysServedParliament", "activeParty", "totalDaysServedParty" }));

    getGridFactory().createBasicBeanItemGrid(panelContent,
            new BeanItemContainer<>(DetailData.class, personData.getPersonDetailData().getDetailList()),
            "Detail", new String[] { "code", "detail" }, new String[] { "hjid", "intressentId", "detailType" },
            null, null, null);

    panelContent.setExpandRatio(createPoliticianPageLink, ContentRatio.SMALL);
    panelContent.setExpandRatio(horizontalLayout, ContentRatio.GRID);

}

From source file:com.haulmont.cuba.web.app.folders.CubaFoldersPane.java

License:Apache License

protected Component addFoldersLabel(AbstractLayout layout, Label label) {
    HorizontalLayout l = new HorizontalLayout();
    l.setMargin(new MarginInfo(false, true, false, true));
    l.addComponent(label);
    l.setWidth("100%");
    layout.addComponent(l);// w  w w  .  j  a v a  2s. com
    return l;
}

From source file:com.haulmont.cuba.web.app.folders.FolderEditWindow.java

License:Apache License

public FolderEditWindow(boolean adding, Folder folder, Presentations presentations, Runnable commitHandler) {
    this.folder = folder;
    this.commitHandler = commitHandler;

    messages = AppBeans.get(Messages.NAME);
    messagesPack = AppConfig.getMessagesPack();
    userSessionSource = AppBeans.get(UserSessionSource.NAME);
    Configuration configuration = AppBeans.get(Configuration.NAME);
    clientConfig = configuration.getConfig(ClientConfig.class);

    setCaption(adding ? getMessage("folders.folderEditWindow.adding") : getMessage("folders.folderEditWindow"));

    ThemeConstants theme = App.getInstance().getThemeConstants();
    setWidthUndefined();/*from   w  w w  .  ja va 2s.co m*/
    setResizable(false);

    int[] modifiers = { ShortcutAction.ModifierKey.CTRL };
    addAction(new ShortcutListener("commit", com.vaadin.event.ShortcutAction.KeyCode.ENTER, modifiers) {
        @Override
        public void handleAction(Object sender, Object target) {
            commit();
        }
    });

    layout = new VerticalLayout();
    layout.setWidthUndefined();
    layout.setSpacing(true);

    setContent(layout);
    setModal(true);
    center();

    String fieldWidth = theme.get("cuba.web.FolderEditWindow.field.width");

    nameField = new TextField();
    nameField.setRequired(true);
    nameField.setCaption(getMessage("folders.folderEditWindow.nameField"));
    nameField.setWidth(fieldWidth);
    nameField.setValue(folder.getName());
    nameField.focus();
    layout.addComponent(nameField);

    tabNameField = new TextField();
    tabNameField.setCaption(getMessage("folders.folderEditWindow.tabNameField"));
    tabNameField.setWidth(fieldWidth);
    tabNameField.setValue(StringUtils.trimToEmpty(folder.getTabName()));
    layout.addComponent(tabNameField);

    parentSelect = new ComboBox();
    parentSelect.setCaption(getMessage("folders.folderEditWindow.parentSelect"));
    parentSelect.setWidth(fieldWidth);
    parentSelect.setNullSelectionAllowed(true);
    fillParentSelect();
    parentSelect.setValue(folder.getParent());
    layout.addComponent(parentSelect);

    if (folder instanceof SearchFolder) {
        if (presentations != null) {
            presentation = new ComboBox();
            presentation.setCaption(getMessage("folders.folderEditWindow.presentation"));
            presentation.setWidth(fieldWidth);
            presentation.setNullSelectionAllowed(true);
            fillPresentations(presentations);
            presentation.setValue(((SearchFolder) folder).getPresentation());
            layout.addComponent(presentation);
        } else if (((SearchFolder) folder).getPresentation() != null) {
            selectedPresentationField = new TextField();
            selectedPresentationField.setWidth(fieldWidth);
            selectedPresentationField.setCaption(getMessage("folders.folderEditWindow.presentation"));
            selectedPresentationField.setValue(((SearchFolder) folder).getPresentation().getName());
            selectedPresentationField.setEnabled(false);
            layout.addComponent(selectedPresentationField);
        }
    }

    sortOrderField = new TextField();
    sortOrderField.setCaption(getMessage("folders.folderEditWindow.sortOrder"));
    sortOrderField.setWidth(fieldWidth);
    sortOrderField.setValue(folder.getSortOrder() == null ? "" : folder.getSortOrder().toString());
    layout.addComponent(sortOrderField);

    if (userSessionSource.getUserSession().isSpecificPermitted("cuba.gui.searchFolder.global")
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet())) {
        globalCb = new CubaCheckBox(getMessage("folders.folderEditWindow.global"));
        globalCb.setValue(((SearchFolder) folder).getUser() == null);
        layout.addComponent(globalCb);
    }

    applyDefaultCb = new CubaCheckBox(getMessage("folders.folderEditWindow.applyDefault"));
    applyDefaultCb.setValue(BooleanUtils.isTrue(((AbstractSearchFolder) folder).getApplyDefault()));
    applyDefaultCb.setVisible(clientConfig.getGenericFilterManualApplyRequired()
            && folder instanceof SearchFolder && BooleanUtils.isNotTrue(((SearchFolder) folder).getIsSet()));
    layout.addComponent(applyDefaultCb);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setMargin(new MarginInfo(true, false, false, false));
    buttonsLayout.setSpacing(true);
    layout.addComponent(buttonsLayout);

    okBtn = new CubaButton(getMessage("actions.Ok"));
    okBtn.setIcon(WebComponentsHelper.getIcon("icons/ok.png"));
    okBtn.addStyleName(WebButton.ICON_STYLE);

    initButtonOkListener();
    buttonsLayout.addComponent(okBtn);

    cancelBtn = new CubaButton(getMessage("actions.Cancel"));
    cancelBtn.setIcon(WebComponentsHelper.getIcon("icons/cancel.png"));
    cancelBtn.addStyleName(WebButton.ICON_STYLE);
    cancelBtn.addClickListener(new Button.ClickListener() {
        @Override
        public void buttonClick(Button.ClickEvent event) {
            close();
        }
    });
    buttonsLayout.addComponent(cancelBtn);

    if (AppUI.getCurrent().isTestMode()) {
        setCubaId("folderEditWindow");

        nameField.setCubaId("nameField");
        tabNameField.setCubaId("tabNameField");
        parentSelect.setCubaId("parentSelect");
        if (presentation != null) {
            presentation.setCubaId("presentationSelect");
        }
        sortOrderField.setCubaId("sortOrderField");
        if (selectedPresentationField != null) {
            selectedPresentationField.setCubaId("selectedPresentationField");
        }
        if (globalCb != null) {
            globalCb.setCubaId("globalCb");
        }
        applyDefaultCb.setCubaId("applyDefaultCb");
        okBtn.setCubaId("okBtn");
        cancelBtn.setCubaId("cancelBtn");
    }
}

From source file:com.haulmont.cuba.web.exception.ExceptionDialog.java

License:Apache License

public ExceptionDialog(Throwable throwable, @Nullable String caption, @Nullable String message) {
    final AppUI ui = AppUI.getCurrent();

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction(
            "closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    addActionHandler(new com.vaadin.event.Action.Handler() {
        @Override/*from   w  w w .ja va 2 s  .  co  m*/
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });

    setCaption(caption != null ? caption : messages.getMainMessage("exceptionDialog.caption"));

    ThemeConstants theme = ui.getApp().getThemeConstants();
    setWidth(theme.get("cuba.web.ExceptionDialog.width"));
    center();

    final String text = message != null ? message : getText(throwable);
    Throwable exception = removeRemoteException(throwable);
    final String stackTrace = getStackTrace(exception);

    mainLayout = new VerticalLayout();
    mainLayout.setSpacing(true);

    TextArea textArea = new TextArea();
    textArea.setHeight(theme.get("cuba.web.ExceptionDialog.textArea.height"));
    textArea.setWidth(100, Unit.PERCENTAGE);

    boolean showExceptionDetails = userSessionSource.getUserSession() != null
            && security.isSpecificPermitted("cuba.gui.showExceptionDetails");

    if (showExceptionDetails) {
        textArea.setValue(text);
    } else {
        textArea.setValue(messages.getMainMessage("exceptionDialog.contactAdmin"));
    }
    textArea.setReadOnly(true);

    mainLayout.addComponent(textArea);

    HorizontalLayout buttonsLayout = new HorizontalLayout();
    buttonsLayout.setSpacing(true);
    buttonsLayout.setWidth("100%");
    mainLayout.addComponent(buttonsLayout);

    Button closeButton = new CubaButton(messages.getMainMessage("exceptionDialog.closeBtn"));
    closeButton.addClickListener((Button.ClickListener) event -> this.close());
    buttonsLayout.addComponent(closeButton);

    showStackTraceButton = new CubaButton(messages.getMainMessage("exceptionDialog.showStackTrace"));
    showStackTraceButton
            .addClickListener((Button.ClickListener) event -> setStackTraceVisible(!isStackTraceVisible));
    buttonsLayout.addComponent(showStackTraceButton);
    showStackTraceButton.setVisible(showExceptionDetails);

    Label spacer = new Label();
    buttonsLayout.addComponent(spacer);
    buttonsLayout.setExpandRatio(spacer, 1);

    String cubaLogContentClass = "c-exception-dialog-log-content";
    String cubaCopyLogContentClass = cubaLogContentClass + "-" + UUID.randomUUID();

    if (browserSupportCopy()) {
        copyButton = new CubaButton(messages.getMainMessage("exceptionDialog.copyStackTrace"));
        copyButton.setVisible(false);
        CubaCopyButtonExtension copyExtension = CubaCopyButtonExtension.copyWith(copyButton,
                cubaCopyLogContentClass);
        copyExtension
                .addCopyListener(
                        event -> Notification.show(
                                messages.getMainMessage(event.isSuccess() ? "exceptionDialog.copingSuccessful"
                                        : "exceptionDialog.copingFailed"),
                                Notification.Type.TRAY_NOTIFICATION));
        buttonsLayout.addComponent(copyButton);
    }

    if (userSessionSource.getUserSession() != null) {
        if (!StringUtils.isBlank(clientConfig.getSupportEmail())) {
            Button reportButton = new CubaButton(messages.getMainMessage("exceptionDialog.reportBtn"));
            reportButton.addClickListener((Button.ClickListener) event -> {
                sendSupportEmail(text, stackTrace);
                reportButton.setEnabled(false);
            });
            buttonsLayout.addComponent(reportButton);

            if (ui.isTestMode()) {
                reportButton.setCubaId("errorReportButton");
            }
        }
    }

    Button logoutButton = new CubaButton(messages.getMainMessage("exceptionDialog.logout"));
    logoutButton.addClickListener((Button.ClickListener) event -> logoutPrompt());
    buttonsLayout.addComponent(logoutButton);

    stackTraceTextArea = new TextArea();
    stackTraceTextArea.setSizeFull();
    stackTraceTextArea.setWordwrap(false);
    stackTraceTextArea.setValue(stackTrace);
    stackTraceTextArea.setStyleName(cubaLogContentClass);
    stackTraceTextArea.addStyleName(cubaCopyLogContentClass);
    stackTraceTextArea.setReadOnly(true);

    setContent(mainLayout);
    setResizable(false);

    if (ui.isTestMode()) {
        setId(ui.getTestIdManager().getTestId("exceptionDialog"));
        setCubaId("exceptionDialog");

        closeButton.setCubaId("closeButton");
        if (copyButton != null) {
            copyButton.setCubaId("copyStackTraceButton");
        }
        showStackTraceButton.setCubaId("showStackTraceButton");
        stackTraceTextArea.setCubaId("stackTraceTextArea");
        logoutButton.setCubaId("logoutButton");
    }
}

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

License:Apache License

protected void initLayout() {
    ThemeConstants theme = App.getInstance().getThemeConstants();

    VerticalLayout root = new VerticalLayout();
    root.setWidthUndefined();//ww  w  . j  av a  2  s. c o  m
    root.setSpacing(true);
    setContent(root);

    messages = AppBeans.get(Messages.class);

    nameField = new TextField(messages.getMainMessage("PresentationsEditor.name"));
    nameField.setWidth(theme.get("cuba.web.PresentationEditor.name.width"));
    nameField.setValue(getPresentationCaption());
    root.addComponent(nameField);

    autoSaveField = new CheckBox();
    autoSaveField.setCaption(messages.getMainMessage("PresentationsEditor.autoSave"));
    autoSaveField.setValue(BooleanUtils.isTrue(presentation.getAutoSave()));
    root.addComponent(autoSaveField);

    defaultField = new CheckBox();
    defaultField.setCaption(messages.getMainMessage("PresentationsEditor.default"));
    defaultField.setValue(presentation.getId().equals(component.getDefaultPresentationId()));
    root.addComponent(defaultField);

    if (allowGlobalPresentations) {
        globalField = new CheckBox();
        globalField.setCaption(messages.getMainMessage("PresentationsEditor.global"));
        globalField.setValue(!isNew && presentation.getUser() == null);
        root.addComponent(globalField);
    }

    HorizontalLayout buttons = new HorizontalLayout();
    buttons.setSpacing(true);
    buttons.setWidthUndefined();
    root.addComponent(buttons);
    root.setComponentAlignment(buttons, Alignment.MIDDLE_LEFT);

    Button commitButton = new CubaButton(messages.getMainMessage("PresentationsEditor.save"));
    commitButton.addClickListener(event -> {
        if (validate()) {
            commit();
            close();
        }
    });
    buttons.addComponent(commitButton);

    Button closeButton = new CubaButton(messages.getMainMessage("PresentationsEditor.close"));
    closeButton.addClickListener(event -> {
        close();
    });
    buttons.addComponent(closeButton);

    nameField.focus();
}

From source file:com.haulmont.cuba.web.log.LogWindow.java

License:Apache License

private void initUI() {
    ClientConfig clientConfig = AppBeans.<Configuration>get(Configuration.NAME).getConfig(ClientConfig.class);

    String closeShortcut = clientConfig.getCloseShortcut();
    KeyCombination closeCombination = KeyCombination.create(closeShortcut);

    com.vaadin.event.ShortcutAction closeShortcutAction = new com.vaadin.event.ShortcutAction(
            "closeShortcutAction", closeCombination.getKey().getCode(),
            KeyCombination.Modifier.codes(closeCombination.getModifiers()));

    addActionHandler(new com.vaadin.event.Action.Handler() {
        @Override//from w w w  .  ja v a 2  s. c  o m
        public com.vaadin.event.Action[] getActions(Object target, Object sender) {
            return new com.vaadin.event.Action[] { closeShortcutAction };
        }

        @Override
        public void handleAction(com.vaadin.event.Action action, Object sender, Object target) {
            if (Objects.equals(action, closeShortcutAction)) {
                close();
            }
        }
    });

    VerticalLayout layout = new VerticalLayout();
    layout.setSpacing(true);
    layout.setSizeFull();
    setContent(layout);

    Panel scrollablePanel = new Panel();
    scrollablePanel.setSizeFull();
    VerticalLayout scrollContent = new VerticalLayout();
    scrollContent.setSizeUndefined();
    scrollablePanel.setContent(scrollContent);

    final Label label = new Label();
    label.setContentMode(ContentMode.HTML);
    label.setValue(writeLog());
    label.setSizeUndefined();
    label.setStyleName("c-log-content");

    ((Layout) scrollablePanel.getContent()).addComponent(label);

    HorizontalLayout topLayout = new HorizontalLayout();
    topLayout.setWidth("100%");
    topLayout.setHeightUndefined();

    Messages messages = AppBeans.get(Messages.NAME);
    Button refreshBtn = new CubaButton(messages.getMessage(getClass(), "logWindow.refreshBtn"),
            (Button.ClickListener) event -> label.setValue(writeLog()));

    topLayout.addComponent(refreshBtn);

    layout.addComponent(topLayout);
    layout.addComponent(scrollablePanel);

    layout.setExpandRatio(scrollablePanel, 1.0f);
}