Search in sources :

Example 1 with I_CmsDialogContext

use of org.opencms.ui.I_CmsDialogContext in project opencms-core by alkacon.

the class CmsSourceSearchApp method getComponentForState.

/**
 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#getComponentForState(java.lang.String)
 */
@Override
protected Component getComponentForState(String state) {
    m_rootLayout.setMainHeightFull(true);
    HorizontalSplitPanel sp = new HorizontalSplitPanel();
    sp.setSizeFull();
    m_searchForm = new CmsSourceSearchForm(this);
    sp.setFirstComponent(m_searchForm);
    VerticalLayout result = new VerticalLayout();
    result.setSizeFull();
    m_infoIntroLayout = CmsVaadinUtils.getInfoLayout(Messages.GUI_SOURCESEARCH_INTRO_0);
    m_infoEmptyResult = CmsVaadinUtils.getInfoLayout(Messages.GUI_SOURCESEARCH_EMPTY_0);
    m_resultTable = new CmsFileTable(null);
    result.addComponent(m_resultTable);
    result.addComponent(m_infoEmptyResult);
    result.addComponent(m_infoIntroLayout);
    m_resultTable.setVisible(false);
    m_infoEmptyResult.setVisible(false);
    m_infoIntroLayout.setVisible(true);
    m_resultTable.applyWorkplaceAppSettings();
    m_resultTable.setContextProvider(new I_CmsContextProvider() {

        /**
         * @see org.opencms.ui.apps.I_CmsContextProvider#getDialogContext()
         */
        public I_CmsDialogContext getDialogContext() {
            CmsFileTableDialogContext context = new CmsFileTableDialogContext(CmsProjectManagerConfiguration.APP_ID, ContextType.fileTable, m_resultTable, m_resultTable.getSelectedResources());
            storeCurrentFileSelection(m_resultTable.getSelectedResources());
            context.setEditableProperties(CmsFileExplorer.INLINE_EDIT_PROPERTIES);
            return context;
        }
    });
    m_resultTable.setSizeFull();
    if (m_resultTableFilter == null) {
        m_resultTableFilter = new TextField();
        m_resultTableFilter.setIcon(FontOpenCms.FILTER);
        m_resultTableFilter.setInputPrompt(Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0));
        m_resultTableFilter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
        m_resultTableFilter.setWidth("200px");
        m_resultTableFilter.addTextChangeListener(new TextChangeListener() {

            private static final long serialVersionUID = 1L;

            public void textChange(TextChangeEvent event) {
                m_resultTable.filterTable(event.getText());
            }
        });
        m_infoLayout.addComponent(m_resultTableFilter);
    }
    sp.setSecondComponent(result);
    sp.setSplitPosition(CmsFileExplorer.LAYOUT_SPLIT_POSITION, Unit.PIXELS);
    if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(state)) {
        CmsSearchReplaceSettings settings = getSettingsFromState(state);
        if (settings != null) {
            m_currentState = state;
            m_searchForm.initFormValues(settings);
            search(settings, false);
        }
    }
    return sp;
}
Also used : I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) CmsFileTableDialogContext(org.opencms.ui.components.CmsFileTableDialogContext) VerticalLayout(com.vaadin.v7.ui.VerticalLayout) I_CmsContextProvider(org.opencms.ui.apps.I_CmsContextProvider) TextField(com.vaadin.v7.ui.TextField) CmsFileTable(org.opencms.ui.components.CmsFileTable) TextChangeListener(com.vaadin.v7.event.FieldEvents.TextChangeListener)

Example 2 with I_CmsDialogContext

use of org.opencms.ui.I_CmsDialogContext in project opencms-core by alkacon.

the class CmsListManager method initUI.

/**
 * @see org.opencms.ui.apps.A_CmsWorkplaceApp#initUI(org.opencms.ui.apps.I_CmsAppUIContext)
 */
@Override
public void initUI(I_CmsAppUIContext uiContext) {
    super.initUI(uiContext);
    m_publishButton = CmsToolBar.createButton(FontOpenCms.PUBLISH, CmsVaadinUtils.getMessageText(Messages.GUI_PUBLISH_BUTTON_TITLE_0));
    if (CmsAppWorkplaceUi.isOnlineProject()) {
        // disable publishing in online project
        m_publishButton.setEnabled(false);
        m_publishButton.setDescription(CmsVaadinUtils.getMessageText(Messages.GUI_TOOLBAR_NOT_AVAILABLE_ONLINE_0));
    }
    m_publishButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            publish();
        }
    });
    uiContext.addToolbarButton(m_publishButton);
    m_editCurrentButton = CmsToolBar.createButton(FontOpenCms.PEN, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_EDIT_CONFIG_0));
    m_editCurrentButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            editListConfiguration(m_currentResource);
        }
    });
    uiContext.addToolbarButton(m_editCurrentButton);
    m_infoButton = CmsToolBar.createButton(FontOpenCms.INFO, CmsVaadinUtils.getMessageText(org.opencms.ui.Messages.GUI_RESOURCE_INFO_0));
    m_infoButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            DialogContext context = new DialogContext(CmsProjectManagerConfiguration.APP_ID, ContextType.fileTable, m_resultTable, Collections.singletonList(m_currentResource));
            CmsResourceInfoAction action = new CmsResourceInfoAction();
            action.openDialog(context, CmsResourceStatusTabId.tabRelationsTo.name());
        }
    });
    uiContext.addToolbarButton(m_infoButton);
    m_toggleSeriesButton = CmsToolBar.createButton(FontOpenCms.LIST, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_TOGGLE_SERIES_BUTTON_0));
    m_toggleSeriesButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            toggleDateSeries();
        }
    });
    uiContext.addToolbarButton(m_toggleSeriesButton);
    m_createNewButton = CmsToolBar.createButton(FontOpenCms.WAND, CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_CREATE_NEW_0));
    m_createNewButton.addClickListener(new ClickListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void buttonClick(ClickEvent event) {
            createNew();
        }
    });
    uiContext.addToolbarButton(m_createNewButton);
    m_rootLayout.setMainHeightFull(true);
    m_resultLayout = new HorizontalSplitPanel();
    m_resultLayout.setSizeFull();
    m_resultFacets = new CmsResultFacets(this);
    m_resultFacets.setWidth("100%");
    m_resultLayout.setFirstComponent(m_resultFacets);
    LinkedHashMap<CmsResourceTableProperty, Integer> tableColumns = new LinkedHashMap<CmsResourceTableProperty, Integer>();
    // insert columns a specific positions
    for (Map.Entry<CmsResourceTableProperty, Integer> columnsEntry : CmsFileTable.DEFAULT_TABLE_PROPERTIES.entrySet()) {
        if (columnsEntry.getKey().equals(CmsResourceTableProperty.PROPERTY_RESOURCE_NAME)) {
            tableColumns.put(INFO_PROPERTY_LABEL, Integer.valueOf(0));
        } else if (columnsEntry.getKey().equals(CmsResourceTableProperty.PROPERTY_RESOURCE_TYPE)) {
            tableColumns.put(INSTANCEDATE_PROPERTY, Integer.valueOf(0));
        }
        tableColumns.put(columnsEntry.getKey(), columnsEntry.getValue());
    }
    tableColumns.put(BLACKLISTED_PROPERTY, Integer.valueOf(CmsResourceTable.INVISIBLE));
    tableColumns.put(INFO_PROPERTY, Integer.valueOf(CmsResourceTable.INVISIBLE));
    m_resultTable = new CmsResultTable(null, tableColumns);
    m_resultTable.applyWorkplaceAppSettings();
    CmsResourceContextMenuBuilder menuBuilderOverView = new CmsResourceContextMenuBuilder();
    menuBuilderOverView.addMenuItemProvider(OpenCms.getWorkplaceAppManager().getMenuItemProvider());
    menuBuilderOverView.addMenuItemProvider(new I_CmsContextMenuItemProvider() {

        @Override
        public List<I_CmsContextMenuItem> getMenuItems() {
            return Arrays.<I_CmsContextMenuItem>asList(new CmsContextMenuActionItem(new CmsEditDialogAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    editListConfiguration(context.getResources().get(0));
                }
            }, null, 10, 1000));
        }
    });
    CmsResourceContextMenuBuilder menuBuilder = new CmsResourceContextMenuBuilder();
    menuBuilder.addMenuItemProvider(OpenCms.getWorkplaceAppManager().getMenuItemProvider());
    menuBuilder.addMenuItemProvider(new I_CmsContextMenuItemProvider() {

        @Override
        public List<I_CmsContextMenuItem> getMenuItems() {
            return Arrays.<I_CmsContextMenuItem>asList(new CmsContextMenuActionItem(new A_CmsWorkplaceAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    CmsUUID structureId = context.getResources().get(0).getStructureId();
                    m_currentConfig.getBlacklist().add(structureId);
                    saveBlacklist(m_currentConfig);
                    context.finish(Collections.singletonList(structureId));
                }

                @Override
                public String getId() {
                    return "hideresource";
                }

                @Override
                public String getTitleKey() {
                    return Messages.GUI_LISTMANAGER_BLACKLIST_MENU_ENTRY_0;
                }

                @Override
                public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
                    if ((m_currentConfig != null) && (resources != null) && (resources.size() == 1) && !m_currentConfig.getBlacklist().contains(resources.get(0).getStructureId())) {
                        return CmsEditDialogAction.VISIBILITY.getVisibility(cms, Collections.singletonList(m_currentResource));
                    } else {
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                }
            }, null, 10, 0), new CmsContextMenuActionItem(new A_CmsWorkplaceAction() {

                @Override
                public void executeAction(I_CmsDialogContext context) {
                    CmsUUID structureId = context.getResources().get(0).getStructureId();
                    m_currentConfig.getBlacklist().remove(structureId);
                    saveBlacklist(m_currentConfig);
                    context.finish(Collections.singletonList(structureId));
                }

                @Override
                public String getId() {
                    return "showresource";
                }

                @Override
                public String getTitleKey() {
                    return Messages.GUI_LISTMANAGER_REMOVE_FROM_BLACKLIST_MENU_ENTRY_0;
                }

                @Override
                public CmsMenuItemVisibilityMode getVisibility(CmsObject cms, List<CmsResource> resources) {
                    if ((m_currentConfig != null) && (resources != null) && (resources.size() == 1) && m_currentConfig.getBlacklist().contains(resources.get(0).getStructureId())) {
                        return CmsEditDialogAction.VISIBILITY.getVisibility(cms, Collections.singletonList(m_currentResource));
                    } else {
                        return CmsMenuItemVisibilityMode.VISIBILITY_INVISIBLE;
                    }
                }
            }, null, 10, 0), new CmsContextMenuActionItem(new EditAction(), null, 10, 1000), new CmsContextMenuActionItem(new DeleteAction(), null, 10, 1000));
        }
    });
    m_resultTable.setMenuBuilder(menuBuilder);
    m_resultTable.addAdditionalStyleGenerator(new CellStyleGenerator() {

        private static final long serialVersionUID = 1L;

        @Override
        public String getStyle(Table source, Object itemId, Object propertyId) {
            String style = "";
            Item item = source.getItem(itemId);
            Boolean blacklisted = (Boolean) item.getItemProperty(BLACKLISTED_PROPERTY).getValue();
            if (blacklisted.booleanValue()) {
                style += OpenCmsTheme.PROJECT_OTHER + " ";
            } else if (CmsResourceTableProperty.PROPERTY_TITLE.equals(propertyId) && ((item.getItemProperty(CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED) == null) || ((Boolean) item.getItemProperty(CmsResourceTableProperty.PROPERTY_RELEASED_NOT_EXPIRED).getValue()).booleanValue())) {
                style += OpenCmsTheme.IN_NAVIGATION + " ";
            }
            if (INFO_PROPERTY_LABEL.equals(propertyId)) {
                if (blacklisted.booleanValue()) {
                    style += OpenCmsTheme.TABLE_COLUMN_BOX_BLACK;
                } else {
                    Object value = item.getItemProperty(INFO_PROPERTY).getValue();
                    if (value == null) {
                        style += OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
                    } else {
                        I_CmsSerialDateValue.DateType type = I_CmsSerialDateValue.DateType.valueOf((String) value);
                        switch(type) {
                            case SERIES:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_BLUE_LIGHT;
                                break;
                            case SINGLE:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_GRAY;
                                break;
                            case EXTRACTED:
                                style += OpenCmsTheme.TABLE_COLUMN_BOX_ORANGE;
                                break;
                            default:
                                break;
                        }
                    }
                }
            }
            return style;
        }
    });
    final ItemDescriptionGenerator defaultDescriptionGenerator = new CmsResourceTable.DefaultItemDescriptionGenerator();
    m_resultTable.setsetItemDescriptionGenerator(new ItemDescriptionGenerator() {

        private static final long serialVersionUID = 1L;

        public String generateDescription(Component source, Object itemId, Object propertyId) {
            Item item = ((Table) source).getItem(itemId);
            if (INFO_PROPERTY_LABEL.equals(propertyId) && ((Boolean) item.getItemProperty(BLACKLISTED_PROPERTY).getValue()).booleanValue()) {
                return CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_COLUMN_BLACKLISTED_0);
            }
            return defaultDescriptionGenerator.generateDescription(source, itemId, propertyId);
        }
    });
    m_resultTable.setContextProvider(this);
    m_resultTable.addPropertyProvider(this);
    m_resultTable.setSizeFull();
    m_resultLayout.setSecondComponent(m_resultTable);
    m_overviewTable = new CmsFileTable(this);
    m_overviewTable.applyWorkplaceAppSettings();
    m_overviewTable.setMenuBuilder(menuBuilderOverView);
    m_overviewTable.setSizeFull();
    m_tableFilter = new TextField();
    m_tableFilter.setIcon(FontOpenCms.FILTER);
    m_tableFilter.setInputPrompt(Messages.get().getBundle(UI.getCurrent().getLocale()).key(Messages.GUI_EXPLORER_FILTER_0));
    m_tableFilter.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    m_tableFilter.setWidth("200px");
    m_tableFilter.addTextChangeListener(new TextChangeListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void textChange(TextChangeEvent event) {
            filterTable(event.getText());
        }
    });
    m_infoLayout.addComponent(m_tableFilter);
    m_localeSelect = new ComboBox();
    m_localeSelect.setNullSelectionAllowed(false);
    m_localeSelect.setWidth("100px");
    m_localeSelect.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            changeContentLocale((Locale) event.getProperty().getValue());
        }
    });
    m_infoLayout.addComponent(m_localeSelect);
    m_resultSorter = new ComboBox();
    m_resultSorter.setNullSelectionAllowed(false);
    m_resultSorter.setWidth("200px");
    for (int i = 0; i < SORT_OPTIONS[0].length; i++) {
        m_resultSorter.addItem(SORT_OPTIONS[0][i]);
        m_resultSorter.setItemCaption(SORT_OPTIONS[0][i], CmsVaadinUtils.getMessageText(SORT_OPTIONS[1][i]));
    }
    m_resultSorter.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            sortResult();
        }
    });
    m_infoLayout.addComponent(m_resultSorter);
    m_textSearch = new TextField();
    m_textSearch.setIcon(FontOpenCms.SEARCH);
    m_textSearch.setInputPrompt(CmsVaadinUtils.getMessageText(Messages.GUI_LISTMANAGER_SEARCH_0));
    m_textSearch.addStyleName(ValoTheme.TEXTFIELD_INLINE_ICON);
    m_textSearch.setWidth("200px");
    m_textSearch.addValueChangeListener(new ValueChangeListener() {

        /**
         * Serial version id.
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void valueChange(ValueChangeEvent event) {
            search((String) event.getProperty().getValue());
        }
    });
    m_infoLayout.addComponent(m_textSearch);
    m_resultLayout.setSecondComponent(m_resultTable);
    m_resultLayout.setSplitPosition(CmsFileExplorer.LAYOUT_SPLIT_POSITION, Unit.PIXELS);
}
Also used : CmsResourceTableProperty(org.opencms.ui.components.CmsResourceTableProperty) Locale(java.util.Locale) CmsMenuItemVisibilityMode(org.opencms.ui.contextmenu.CmsMenuItemVisibilityMode) CmsResourceInfoAction(org.opencms.ui.actions.CmsResourceInfoAction) ClickEvent(com.vaadin.ui.Button.ClickEvent) CellStyleGenerator(com.vaadin.v7.ui.Table.CellStyleGenerator) I_CmsContextMenuItemProvider(org.opencms.ui.contextmenu.I_CmsContextMenuItemProvider) LinkedHashMap(java.util.LinkedHashMap) CmsContextMenuActionItem(org.opencms.ui.actions.CmsContextMenuActionItem) Item(com.vaadin.v7.data.Item) I_CmsContextMenuItem(org.opencms.ui.contextmenu.I_CmsContextMenuItem) CmsContextMenuActionItem(org.opencms.ui.actions.CmsContextMenuActionItem) CmsObject(org.opencms.file.CmsObject) ValueChangeListener(com.vaadin.v7.data.Property.ValueChangeListener) TextField(com.vaadin.v7.ui.TextField) ArrayList(java.util.ArrayList) List(java.util.List) CmsSolrResultList(org.opencms.search.solr.CmsSolrResultList) CmsUUID(org.opencms.util.CmsUUID) Component(com.vaadin.ui.Component) TextChangeListener(com.vaadin.v7.event.FieldEvents.TextChangeListener) ClickListener(com.vaadin.ui.Button.ClickListener) CmsResourceContextMenuBuilder(org.opencms.ui.contextmenu.CmsResourceContextMenuBuilder) Table(com.vaadin.v7.ui.Table) CmsFileTable(org.opencms.ui.components.CmsFileTable) CmsResourceTable(org.opencms.ui.components.CmsResourceTable) CmsFileTableDialogContext(org.opencms.ui.components.CmsFileTableDialogContext) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) A_CmsWorkplaceAction(org.opencms.ui.actions.A_CmsWorkplaceAction) ComboBox(com.vaadin.v7.ui.ComboBox) ValueChangeEvent(com.vaadin.v7.data.Property.ValueChangeEvent) ItemDescriptionGenerator(com.vaadin.v7.ui.AbstractSelect.ItemDescriptionGenerator) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) CmsResource(org.opencms.file.CmsResource) TextChangeEvent(com.vaadin.v7.event.FieldEvents.TextChangeEvent) HorizontalSplitPanel(com.vaadin.ui.HorizontalSplitPanel) CmsEditDialogAction(org.opencms.ui.actions.CmsEditDialogAction) CmsObject(org.opencms.file.CmsObject) CmsFileTable(org.opencms.ui.components.CmsFileTable) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 3 with I_CmsDialogContext

use of org.opencms.ui.I_CmsDialogContext in project opencms-core by alkacon.

the class CmsListManager method getDialogContext.

/**
 * @see org.opencms.ui.apps.I_CmsContextProvider#getDialogContext()
 */
@Override
public I_CmsDialogContext getDialogContext() {
    CmsFileTable table = isOverView() ? m_overviewTable : m_resultTable;
    List<CmsResource> resources = table.getSelectedResources();
    DialogContext context = new DialogContext(CmsProjectManagerConfiguration.APP_ID, ContextType.fileTable, table, resources);
    if (!isOverView()) {
        context.setSelectedItems(m_resultTable.getSelectedItems());
    }
    return context;
}
Also used : CmsResource(org.opencms.file.CmsResource) CmsFileTableDialogContext(org.opencms.ui.components.CmsFileTableDialogContext) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) CmsFileTable(org.opencms.ui.components.CmsFileTable)

Example 4 with I_CmsDialogContext

use of org.opencms.ui.I_CmsDialogContext in project opencms-core by alkacon.

the class CmsMessageBundleEditorModel method publish.

/**
 * Publish the bundle resources directly.
 */
public void publish() {
    CmsDirectPublishDialogAction action = new CmsDirectPublishDialogAction();
    List<CmsResource> resources = getBundleResources();
    I_CmsDialogContext context = new A_CmsDialogContext("", ContextType.appToolbar, resources) {

        public void focus(CmsUUID structureId) {
        // Nothing to do.
        }

        public List<CmsUUID> getAllStructureIdsInView() {
            return null;
        }

        public void updateUserInfo() {
        // Nothing to do.
        }
    };
    action.executeAction(context);
    updateLockInformation();
}
Also used : CmsResource(org.opencms.file.CmsResource) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) CmsUUID(org.opencms.util.CmsUUID) A_CmsDialogContext(org.opencms.ui.A_CmsDialogContext) CmsDirectPublishDialogAction(org.opencms.ui.actions.CmsDirectPublishDialogAction)

Example 5 with I_CmsDialogContext

use of org.opencms.ui.I_CmsDialogContext in project opencms-core by alkacon.

the class CmsLoginController method onClickLogin.

/**
 * Called when the user clicks on the login button.<p>
 */
public void onClickLogin() {
    String user = m_ui.getUser();
    String password = m_ui.getPassword();
    CmsMessageContainer message = CmsLoginHelper.validateUserAndPasswordNotEmpty(user, password);
    CmsLoginMessage loginMessage = OpenCms.getLoginManager().getLoginMessage();
    String storedMessage = null;
    ContentMode messageMode = ContentMode.html;
    if ((loginMessage != null) && !loginMessage.isLoginCurrentlyForbidden() && loginMessage.isActive()) {
        storedMessage = loginMessage.getMessage();
    // If login is forbidden, we will get an error message anyway, so we don't need to store the message here
    }
    String ou = m_ui.getOrgUnit();
    if (CmsLoginOuSelector.OU_NONE.equals(ou)) {
        displayError(CmsVaadinUtils.getMessageText(Messages.GUI_LOGIN_NO_OU_SELECTED_WARNING_0) + "\n\n", false, false);
        return;
    }
    if (message != null) {
        String errorMessage = message.key(m_params.getLocale());
        // m_ui.displayError(errorMessage);
        displayError(errorMessage, true, false);
        return;
    }
    String realUser = CmsStringUtil.joinPaths(ou, user);
    String pcType = m_ui.getPcType();
    CmsObject currentCms = A_CmsUI.getCmsObject();
    CmsUser userObj = null;
    try {
        try {
            userObj = currentCms.readUser(realUser);
        } catch (CmsException e) {
            LOG.warn(e.getLocalizedMessage(), e);
            message = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_FAILED_0);
            displayError(message.key(m_params.getLocale()), true, true);
            CmsUserLog.logLoginFailure(currentCms, realUser);
            return;
        }
        if (OpenCms.getLoginManager().canLockBecauseOfInactivity(currentCms, userObj)) {
            boolean locked = null != userObj.getAdditionalInfo().get(KEY_ACCOUNT_LOCKED);
            if (locked) {
                displayError(CmsInactiveUserMessages.getLockoutText(A_CmsUI.get().getLocale()), false, false);
                CmsUserLog.logLoginFailure(currentCms, realUser);
                return;
            }
        }
        CmsObject cloneCms = OpenCms.initCmsObject(currentCms);
        cloneCms.loginUser(realUser, password);
        String messageToChange = "";
        if (OpenCms.getLoginManager().isPasswordReset(currentCms, userObj)) {
            messageToChange = CmsVaadinUtils.getMessageText(Messages.GUI_PWCHANGE_RESET_0);
        }
        if (OpenCms.getLoginManager().requiresPasswordChange(currentCms, userObj)) {
            messageToChange = getPasswordChangeMessage();
        }
        if (!CmsStringUtil.isEmptyOrWhitespaceOnly(messageToChange)) {
            CmsChangePasswordDialog passwordDialog = new CmsChangePasswordDialog(currentCms, userObj, A_CmsUI.get().getLocale());
            passwordDialog.setAdditionalMessage(messageToChange);
            A_CmsUI.get().setContentToDialog(Messages.get().getBundle(A_CmsUI.get().getLocale()).key(Messages.GUI_PWCHANGE_HEADER_0) + userObj.getSimpleName(), passwordDialog);
            return;
        }
        CmsWorkplaceSettings settings = CmsLoginHelper.initSiteAndProject(cloneCms);
        final String loginTarget = getLoginTarget(cloneCms, settings, m_params.getRequestedResource());
        // make sure we have a new session after login for security reasons
        HttpSession session = ((HttpServletRequest) VaadinService.getCurrentRequest()).getSession(false);
        if (session != null) {
            session.invalidate();
        }
        session = ((HttpServletRequest) VaadinService.getCurrentRequest()).getSession(true);
        // provisional login successful, now do for real
        currentCms.loginUser(realUser, password);
        CmsUserLog.logLogin(currentCms, realUser);
        if (LOG.isInfoEnabled()) {
            CmsRequestContext context = currentCms.getRequestContext();
            LOG.info(org.opencms.jsp.Messages.get().getBundle().key(org.opencms.jsp.Messages.LOG_LOGIN_SUCCESSFUL_3, context.getCurrentUser().getName(), "{workplace login dialog}", context.getRemoteAddress()));
        }
        settings = CmsLoginHelper.initSiteAndProject(currentCms);
        OpenCms.getSessionManager().updateSessionInfo(currentCms, (HttpServletRequest) VaadinService.getCurrentRequest());
        if ((loginMessage != null) && loginMessage.isLoginCurrentlyForbidden()) {
            if (loginMessage.getTimeEnd() == CmsLoginMessage.DEFAULT_TIME_END) {
                // we are an administrator
                storedMessage = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_WITHOUT_TIME_1, loginMessage.getMessage(), new Date(loginMessage.getTimeEnd())).key(A_CmsUI.get().getLocale());
                messageMode = ContentMode.html;
            } else {
                // we are an administrator
                storedMessage = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_SUCCESS_WITH_MESSAGE_2, loginMessage.getMessage(), new Date(loginMessage.getTimeEnd())).key(A_CmsUI.get().getLocale());
                messageMode = ContentMode.html;
            }
        }
        if (storedMessage != null) {
            OpenCms.getSessionManager().sendBroadcast(null, storedMessage, currentCms.getRequestContext().getCurrentUser(), messageMode);
        }
        CmsLoginHelper.setCookieData(pcType, user, ou, (VaadinServletRequest) (VaadinService.getCurrentRequest()), (VaadinServletResponse) (VaadinService.getCurrentResponse()));
        VaadinService.getCurrentRequest().getWrappedSession().setAttribute(CmsWorkplaceManager.SESSION_WORKPLACE_SETTINGS, settings);
        final boolean isPublicPC = CmsLoginForm.PC_TYPE_PUBLIC.equals(pcType);
        if (OpenCms.getLoginManager().requiresUserDataCheck(currentCms, userObj)) {
            I_CmsDialogContext context = new A_CmsDialogContext("", ContextType.appToolbar, null) {

                @Override
                public void finish(CmsProject project, String siteRoot) {
                    finish(null);
                }

                @Override
                public void finish(Collection<CmsUUID> result) {
                    m_ui.openLoginTarget(loginTarget, isPublicPC);
                }

                public void focus(CmsUUID structureId) {
                // nothing to do
                }

                public List<CmsUUID> getAllStructureIdsInView() {
                    return null;
                }

                @Override
                public void start(String title, Component dialog, DialogWidth style) {
                    if (dialog != null) {
                        m_window = CmsBasicDialog.prepareWindow(style);
                        m_window.setCaption(title);
                        m_window.setContent(dialog);
                        UI.getCurrent().addWindow(m_window);
                        if (dialog instanceof CmsBasicDialog) {
                            ((CmsBasicDialog) dialog).initActionHandler(m_window);
                        }
                    }
                }

                public void updateUserInfo() {
                // not supported
                }
            };
            CmsUser u = currentCms.readUser(userObj.getId());
            u.setAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_LAST_USER_DATA_CHECK, Long.toString(System.currentTimeMillis()));
            currentCms.writeUser(u);
            CmsUserDataDialog dialog = new CmsUserDataDialog(context, true);
            context.start(dialog.getTitle(UI.getCurrent().getLocale()), dialog);
        } else {
            m_ui.openLoginTarget(loginTarget, isPublicPC);
        }
    } catch (Exception e) {
        // there was an error during login
        if (e instanceof CmsException) {
            CmsMessageContainer exceptionMessage = ((CmsException) e).getMessageContainer();
            if (org.opencms.security.Messages.ERR_LOGIN_FAILED_DISABLED_2 == exceptionMessage.getKey()) {
                // the user account is disabled
                message = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_FAILED_DISABLED_0);
            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_TEMP_DISABLED_4 == exceptionMessage.getKey()) {
                // the user account is temporarily disabled because of too many login failures
                message = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_FAILED_TEMP_DISABLED_0);
            } else if (org.opencms.security.Messages.ERR_LOGIN_FAILED_WITH_MESSAGE_1 == exceptionMessage.getKey()) {
                // all logins have been disabled be the Administration
                CmsLoginMessage loginMessage2 = OpenCms.getLoginManager().getLoginMessage();
                if (loginMessage2 != null) {
                    message = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_FAILED_WITH_MESSAGE_1, loginMessage2.getMessage().replace("\n", ""));
                }
            }
        }
        if (message == null) {
            if (e instanceof CmsCustomLoginException) {
                message = ((CmsCustomLoginException) e).getMessageContainer();
            } else {
                // any other error - display default message
                message = org.opencms.workplace.Messages.get().container(org.opencms.workplace.Messages.GUI_LOGIN_FAILED_0);
                LOG.error(e.getLocalizedMessage(), e);
                displayError(message.key(m_params.getLocale()), true, true);
                return;
            }
        }
        if (e instanceof CmsException) {
            CmsJspLoginBean.logLoginException(currentCms.getRequestContext(), user, (CmsException) e);
            CmsUserLog.logLoginFailure(currentCms, user);
        } else {
            LOG.error(e.getLocalizedMessage(), e);
        }
        displayError(message.key(m_params.getLocale()), false, false);
        return;
    }
}
Also used : CmsUserDataDialog(org.opencms.ui.dialogs.CmsUserDataDialog) CmsLoginMessage(org.opencms.db.CmsLoginMessage) CmsCustomLoginException(org.opencms.security.CmsCustomLoginException) A_CmsDialogContext(org.opencms.ui.A_CmsDialogContext) HttpServletRequest(javax.servlet.http.HttpServletRequest) CmsObject(org.opencms.file.CmsObject) CmsRequestContext(org.opencms.file.CmsRequestContext) CmsUUID(org.opencms.util.CmsUUID) Component(com.vaadin.ui.Component) CmsBasicDialog(org.opencms.ui.components.CmsBasicDialog) DialogWidth(org.opencms.ui.components.CmsBasicDialog.DialogWidth) HttpSession(javax.servlet.http.HttpSession) ContentMode(org.opencms.main.CmsBroadcast.ContentMode) CmsUser(org.opencms.file.CmsUser) Date(java.util.Date) MissingResourceException(java.util.MissingResourceException) CmsException(org.opencms.main.CmsException) IOException(java.io.IOException) CmsCustomLoginException(org.opencms.security.CmsCustomLoginException) CmsMessageContainer(org.opencms.i18n.CmsMessageContainer) CmsWorkplaceSettings(org.opencms.workplace.CmsWorkplaceSettings) I_CmsDialogContext(org.opencms.ui.I_CmsDialogContext) CmsException(org.opencms.main.CmsException) Collection(java.util.Collection) CmsProject(org.opencms.file.CmsProject)

Aggregations

I_CmsDialogContext (org.opencms.ui.I_CmsDialogContext)10 CmsResource (org.opencms.file.CmsResource)6 CmsUUID (org.opencms.util.CmsUUID)5 CmsObject (org.opencms.file.CmsObject)4 CmsFileTable (org.opencms.ui.components.CmsFileTable)4 CmsFileTableDialogContext (org.opencms.ui.components.CmsFileTableDialogContext)4 Component (com.vaadin.ui.Component)3 CmsException (org.opencms.main.CmsException)3 HorizontalSplitPanel (com.vaadin.ui.HorizontalSplitPanel)2 TextChangeEvent (com.vaadin.v7.event.FieldEvents.TextChangeEvent)2 TextChangeListener (com.vaadin.v7.event.FieldEvents.TextChangeListener)2 TextField (com.vaadin.v7.ui.TextField)2 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Locale (java.util.Locale)2 Map (java.util.Map)2 CmsProject (org.opencms.file.CmsProject)2