CCM NG: First part of Admin UI for FlexLayout component
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5355 8810af33-2d31-482b-a856-94f89814c4df
parent
58c5c3336d
commit
7f0386413a
|
|
@ -0,0 +1,71 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package com.arsdigita.pagemodel.layout.ui;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.BoxPanel;
|
||||||
|
import com.arsdigita.bebop.FormData;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
|
import com.arsdigita.ui.admin.pagemodels.AbstractComponentModelForm;
|
||||||
|
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
||||||
|
|
||||||
|
import org.libreccm.pagemodel.layout.FlexLayout;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
public class FlexLayoutComponentForm
|
||||||
|
extends AbstractComponentModelForm<FlexLayout> {
|
||||||
|
|
||||||
|
public FlexLayoutComponentForm(
|
||||||
|
final PageModelsTab pageModelsTab,
|
||||||
|
final ParameterSingleSelectionModel<String> selectedModelId,
|
||||||
|
final ParameterSingleSelectionModel<String> selectedComponentId) {
|
||||||
|
|
||||||
|
|
||||||
|
super("FlexLayoutComponentForm",
|
||||||
|
pageModelsTab,
|
||||||
|
selectedModelId,
|
||||||
|
selectedComponentId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void addWidgets() {
|
||||||
|
|
||||||
|
final BoxPanel horizontalPanel = new BoxPanel(BoxPanel.HORIZONTAL);
|
||||||
|
|
||||||
|
add(horizontalPanel);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected FlexLayout createComponentModel() {
|
||||||
|
return new FlexLayout();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void updateComponentModel(final FlexLayout componentModel,
|
||||||
|
final PageState state,
|
||||||
|
final FormData data) {
|
||||||
|
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,6 +18,7 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
|
import com.arsdigita.pagemodel.layout.ui.FlexLayoutComponentForm;
|
||||||
import com.arsdigita.ui.admin.AdminServlet;
|
import com.arsdigita.ui.admin.AdminServlet;
|
||||||
import com.arsdigita.ui.admin.AdminUiConstants;
|
import com.arsdigita.ui.admin.AdminUiConstants;
|
||||||
import com.arsdigita.ui.admin.applications.AdminApplicationCreator;
|
import com.arsdigita.ui.admin.applications.AdminApplicationCreator;
|
||||||
|
|
@ -37,6 +38,8 @@ import org.libreccm.modules.InstallEvent;
|
||||||
import org.libreccm.modules.Module;
|
import org.libreccm.modules.Module;
|
||||||
import org.libreccm.modules.ShutdownEvent;
|
import org.libreccm.modules.ShutdownEvent;
|
||||||
import org.libreccm.modules.UnInstallEvent;
|
import org.libreccm.modules.UnInstallEvent;
|
||||||
|
import org.libreccm.pagemodel.PageModelComponentModel;
|
||||||
|
import org.libreccm.pagemodel.layout.FlexLayout;
|
||||||
|
|
||||||
import org.libreccm.security.SystemUsersSetup;
|
import org.libreccm.security.SystemUsersSetup;
|
||||||
import org.libreccm.web.ApplicationType;
|
import org.libreccm.web.ApplicationType;
|
||||||
|
|
@ -47,6 +50,8 @@ import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
|
@ -56,17 +61,28 @@ import java.util.Properties;
|
||||||
descBundle = "com.arsdigita.ui.login.LoginResources",
|
descBundle = "com.arsdigita.ui.login.LoginResources",
|
||||||
singleton = true,
|
singleton = true,
|
||||||
creator = LoginApplicationCreator.class,
|
creator = LoginApplicationCreator.class,
|
||||||
servlet = LoginServlet.class),
|
servlet = LoginServlet.class)
|
||||||
|
,
|
||||||
@ApplicationType(name = AdminUiConstants.ADMIN_APP_TYPE,
|
@ApplicationType(name = AdminUiConstants.ADMIN_APP_TYPE,
|
||||||
descBundle = "com.arsdigita.ui.admin.AdminResources",
|
descBundle = "com.arsdigita.ui.admin.AdminResources",
|
||||||
singleton = true,
|
singleton = true,
|
||||||
creator = AdminApplicationCreator.class,
|
creator = AdminApplicationCreator.class,
|
||||||
servlet = AdminServlet.class),
|
servlet = AdminServlet.class)
|
||||||
|
,
|
||||||
@ApplicationType(name = "org.libreccm.ui.admin.AdminFaces",
|
@ApplicationType(name = "org.libreccm.ui.admin.AdminFaces",
|
||||||
descBundle = "com.arsdigita.ui.admin.AdminResources",
|
descBundle = "com.arsdigita.ui.admin.AdminResources",
|
||||||
singleton = true,
|
singleton = true,
|
||||||
creator = AdminJsfApplicationCreator.class,
|
creator = AdminJsfApplicationCreator.class,
|
||||||
servletPath = "/admin-jsf/admin.xhtml")},
|
servletPath = "/admin-jsf/admin.xhtml")},
|
||||||
|
pageModelComponentModels = {
|
||||||
|
@PageModelComponentModel(
|
||||||
|
modelClass = FlexLayout.class,
|
||||||
|
editor = FlexLayoutComponentForm.class,
|
||||||
|
descBundle = ADMIN_BUNDLE,
|
||||||
|
titleKey = "ui.pagemodel.components.flexlayout.title",
|
||||||
|
descKey = "ui.pagemodel.components.flexlayout.desc"
|
||||||
|
)
|
||||||
|
},
|
||||||
configurations = {
|
configurations = {
|
||||||
com.arsdigita.bebop.BebopConfig.class,
|
com.arsdigita.bebop.BebopConfig.class,
|
||||||
com.arsdigita.dispatcher.DispatcherConfig.class,
|
com.arsdigita.dispatcher.DispatcherConfig.class,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2018 LibreCCM Foundation.
|
||||||
|
*
|
||||||
|
* This library is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU Lesser General Public
|
||||||
|
* License as published by the Free Software Foundation; either
|
||||||
|
* version 2.1 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This library is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* Lesser General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Lesser General Public
|
||||||
|
* License along with this library; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||||||
|
* MA 02110-1301 USA
|
||||||
|
*/
|
||||||
|
package org.libreccm.pagemodel.layout;
|
||||||
|
|
||||||
|
import org.libreccm.pagemodel.ComponentModel;
|
||||||
|
import org.libreccm.pagemodel.ComponentRenderer;
|
||||||
|
import org.libreccm.pagemodel.ComponentRendererManager;
|
||||||
|
import org.libreccm.pagemodel.RendersComponent;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Optional;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import javax.enterprise.context.RequestScoped;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
@RequestScoped
|
||||||
|
@RendersComponent(componentModel = FlexLayout.class)
|
||||||
|
public class FlexLayoutRenderer implements ComponentRenderer<FlexLayout> {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private ComponentRendererManager componentRendererManager;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> renderComponent(
|
||||||
|
final FlexLayout componentModel,
|
||||||
|
final Map<String, Object> parameters) {
|
||||||
|
|
||||||
|
Objects.requireNonNull(componentModel);
|
||||||
|
Objects.requireNonNull(parameters);
|
||||||
|
|
||||||
|
final Map<String, Object> result = new HashMap<>();
|
||||||
|
result.put("type", FlexLayout.class.getName());
|
||||||
|
result.put("direction", componentModel.getDirection().toString());
|
||||||
|
|
||||||
|
result.put("boxes",
|
||||||
|
componentModel
|
||||||
|
.getBoxes()
|
||||||
|
.stream()
|
||||||
|
.map(this::renderBox)
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Map<String, Object> renderBox(
|
||||||
|
final FlexBox box,
|
||||||
|
final Map<String, Object> parameters) {
|
||||||
|
|
||||||
|
final Map<String, Object> result = new HashMap<>();
|
||||||
|
|
||||||
|
result.put("order", box.getOrder());
|
||||||
|
result.put("size", box.getSize());
|
||||||
|
|
||||||
|
result.put("component",
|
||||||
|
renderComponent(box.getComponent(),
|
||||||
|
box.getComponent().getClass(),
|
||||||
|
parameters));
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private <M extends ComponentModel> Object renderComponent(
|
||||||
|
final ComponentModel componentModel,
|
||||||
|
final Class<M> componentModelClass,
|
||||||
|
final Map<String, Object> parameters) {
|
||||||
|
|
||||||
|
final Optional<ComponentRenderer<M>> renderer = componentRendererManager
|
||||||
|
.findComponentRenderer(componentModelClass);
|
||||||
|
|
||||||
|
if (renderer.isPresent()) {
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
final M model = (M) componentModel;
|
||||||
|
return renderer.get().renderComponent(model, parameters);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue