CCM NG: Some things for the application tab of /ccm/admin

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4154 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-06-10 16:52:02 +00:00
parent 7691377674
commit 08df95a744
10 changed files with 423 additions and 11 deletions

View File

@ -54,7 +54,7 @@ LibreCCM Bundle for Wildfly
** Profile generic
mvn -Djboss-as.home=/home/jensp/java-ee-servers/wildfly/wildfly-10.0.0.Final_ccm-runtime package wildfly:run -pl ccm-bundle-devel-wildfly -am -Pgeneric
mvn -Djboss-as.home=/home/mustermann/java-ee-servers/wildfly/wildfly-10.0.0.Final package wildfly:run -pl ccm-bundle-devel-wildfly -am -Pgeneric
** Additional options

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2016 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.ui.admin.applications;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.web.ApplicationRepository;
import org.libreccm.web.ApplicationType;
import org.libreccm.web.CcmApplication;
import java.util.Optional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public abstract class AbstractAppInstanceForm extends Form {
private final ParameterSingleSelectionModel<String> selectedAppType;
private final ParameterSingleSelectionModel<String> selectedAppInstance;
public AbstractAppInstanceForm(
final String name,
final ParameterSingleSelectionModel<String> selectedAppType,
final ParameterSingleSelectionModel<String> selectedAppInstance) {
super(name);
this.selectedAppType = selectedAppType;
this.selectedAppInstance = selectedAppInstance;
createWidgets();
}
protected abstract void createWidgets();
protected ApplicationType getSelectedAppType(final PageState state) {
final org.libreccm.web.ApplicationManager appManager = CdiUtil
.createCdiUtil().findBean(org.libreccm.web.ApplicationManager.class);
return appManager.getApplicationTypes().get(selectedAppType
.getSelectedKey(state));
}
protected Optional<CcmApplication> getSelectedAppInstance(
final PageState state) {
if (selectedAppInstance.getSelectedKey(state) == null
|| selectedAppInstance.getSelectedKey(state).isEmpty()) {
return Optional.empty();
} else {
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
.findBean(ApplicationRepository.class);
final CcmApplication result = appRepo.findById(Long.parseLong(
selectedAppInstance.getSelectedKey(state)));
return Optional.of(result);
}
}
}

View File

@ -0,0 +1,79 @@
/*
* Copyright (C) 2016 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.ui.admin.applications;
import com.arsdigita.bebop.PageState;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.SimpleContainer;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.web.ApplicationRepository;
import org.libreccm.web.ApplicationType;
import org.libreccm.web.CcmApplication;
import java.util.Optional;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public abstract class AbstractAppSettingsPane extends SimpleContainer {
private final ParameterSingleSelectionModel<String> selectedAppType;
private final ParameterSingleSelectionModel<String> selectedAppInstance;
public AbstractAppSettingsPane(
final ParameterSingleSelectionModel<String> selectedAppType,
final ParameterSingleSelectionModel<String> selectedAppInstance) {
super();
this.selectedAppType = selectedAppType;
this.selectedAppInstance = selectedAppInstance;
createWidgets();
}
protected abstract void createWidgets();
protected ApplicationType getSelectedAppType(final PageState state) {
final org.libreccm.web.ApplicationManager appManager = CdiUtil
.createCdiUtil().findBean(org.libreccm.web.ApplicationManager.class);
return appManager.getApplicationTypes().get(selectedAppType
.getSelectedKey(state));
}
protected Optional<CcmApplication> getSelectedAppInstance(
final PageState state) {
if (selectedAppInstance.getSelectedKey(state) == null
|| selectedAppInstance.getSelectedKey(state).isEmpty()) {
return Optional.empty();
} else {
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
.findBean(ApplicationRepository.class);
final CcmApplication result = appRepo.findById(Long.parseLong(
selectedAppInstance.getSelectedKey(state)));
return Optional.of(result);
}
}
}

View File

@ -20,6 +20,7 @@ package com.arsdigita.ui.admin.applications;
import com.arsdigita.bebop.ActionLink;
import com.arsdigita.bebop.BoxPanel;
import com.arsdigita.bebop.Form;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;
import com.arsdigita.bebop.PageState;
@ -30,10 +31,18 @@ import com.arsdigita.bebop.Tree;
import com.arsdigita.bebop.parameters.StringParameter;
import com.arsdigita.globalization.GlobalizedMessage;
import com.arsdigita.toolbox.ui.LayoutPanel;
import com.arsdigita.util.UncheckedWrapperException;
import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.web.ApplicationType;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import static com.arsdigita.ui.admin.AdminUiConstants.*;
/**
@ -54,6 +63,9 @@ public class ApplicationsTab extends LayoutPanel {
private final Text placeholderSingletonSettings;
private final BoxPanel appInfo;
private final Map<String, AbstractAppInstanceForm> instanceForms;
private final Map<String, AbstractAppSettingsPane> settingsPanes;
public ApplicationsTab() {
super();
@ -67,6 +79,9 @@ public class ApplicationsTab extends LayoutPanel {
selectedAppInstance = new ParameterSingleSelectionModel<>(
selectedAppInstanceParam);
instanceForms = new HashMap<>();
settingsPanes = new HashMap<>();
applicationTree = new Tree(new ApplicationTreeModelBuilder());
applicationTree.addChangeListener(e -> {
final PageState state = e.getPageState();
@ -155,6 +170,39 @@ public class ApplicationsTab extends LayoutPanel {
appInfo.add(appInfoSheet);
managementPanel.add(appInfo);
final org.libreccm.web.ApplicationManager appManager = CdiUtil
.createCdiUtil().findBean(org.libreccm.web.ApplicationManager.class);
final Map<String, ApplicationType> appTypes = appManager
.getApplicationTypes();
appTypes.entrySet().forEach(e -> {
final String appTypeName = e.getKey();
final Class<? extends AbstractAppInstanceForm> instanceFormClass
= e
.getValue().instanceForm();
final Class<? extends AbstractAppSettingsPane> settingsPaneClass
= e
.getValue().settingsPane();
final boolean singleton = e.getValue().singleton();
if (singleton) {
final AbstractAppSettingsPane settingsPane = createSettingsPane(
settingsPaneClass);
managementPanel.add(settingsPane);
settingsPanes.put(appTypeName, settingsPane);
} else {
final AbstractAppInstanceForm instanceForm = createInstanceForm(
instanceFormClass);
managementPanel.add(instanceForm);
instanceForms.put(appTypeName, instanceForm);
final AbstractAppSettingsPane settingsPane = createSettingsPane(
settingsPaneClass);
managementPanel.add(settingsPane);
settingsPanes.put(appTypeName, settingsPane);
}
});
setBody(managementPanel);
}
@ -175,23 +223,33 @@ public class ApplicationsTab extends LayoutPanel {
protected void showManagementLinks(final PageState state) {
managementLinks.setVisible(state, true);
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
}
protected void hideManagementLinks(final PageState state) {
managementLinks.setVisible(state, false);
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
}
protected void showInstances(final PageState state) {
placeholderInstances.setVisible(state, true);
placeholderSingletonSettings.setVisible(state, false);
appInfo.setVisible(state, false);
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
}
protected void hideInstances(final PageState state) {
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
placeholderInstances.setVisible(state, false);
}
protected void showSingletonAppSettings(final PageState state) {
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
placeholderInstances.setVisible(state, false);
placeholderSingletonSettings.setVisible(state, true);
appInfo.setVisible(state, false);
@ -199,18 +257,80 @@ public class ApplicationsTab extends LayoutPanel {
protected void hideSingletonAppSettings(final PageState state) {
placeholderSingletonSettings.setVisible(state, false);
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
}
protected void showAppInfo(final PageState state) {
placeholderInstances.setVisible(state, false);
placeholderSingletonSettings.setVisible(state, false);
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
appInfo.setVisible(state, true);
}
protected void hideAppInfo(final PageState state) {
hideAllInstanceForms(state);
hideAllSettingsPanes(state);
appInfo.setVisible(state, false);
}
private void hideAllInstanceForms(final PageState state) {
instanceForms.values().forEach(f -> {
f.setVisible(state, false);
});
}
private void hideAllSettingsPanes(final PageState state) {
settingsPanes.values().forEach(p -> {
p.setVisible(state, false);
});
}
private AbstractAppInstanceForm createInstanceForm(
Class<? extends AbstractAppInstanceForm> instanceFormClass) {
try {
final Constructor<? extends AbstractAppInstanceForm> constructor
= instanceFormClass
.getConstructor(ParameterSingleSelectionModel.class,
ParameterSingleSelectionModel.class);
return constructor.newInstance(selectedAppType,
selectedAppInstance);
} catch (NoSuchMethodException |
SecurityException |
InstantiationException |
IllegalAccessException |
IllegalArgumentException |
InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
}
}
private AbstractAppSettingsPane createSettingsPane(
Class<? extends AbstractAppSettingsPane> settingsPaneClass) {
try {
final Constructor<? extends AbstractAppSettingsPane> constructor
= settingsPaneClass
.getDeclaredConstructor(ParameterSingleSelectionModel.class,
ParameterSingleSelectionModel.class);
return constructor.newInstance(selectedAppType,
selectedAppInstance);
} catch (NoSuchMethodException |
SecurityException |
InstantiationException |
IllegalAccessException |
IllegalArgumentException |
InvocationTargetException ex) {
throw new UncheckedWrapperException(ex);
}
}
private class SingletonAppSettingsLink extends ActionLink {
public SingletonAppSettingsLink(final GlobalizedMessage label) {

View File

@ -0,0 +1,47 @@
/*
* Copyright (C) 2016 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.ui.admin.applications;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Text;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class DefaultApplicationInstanceForm
extends AbstractAppInstanceForm {
public DefaultApplicationInstanceForm(
final String name,
final ParameterSingleSelectionModel<String> selectedAppType,
final ParameterSingleSelectionModel<String> selectedAppInstance) {
super(name, selectedAppType, selectedAppInstance);
}
@Override
protected void createWidgets() {
add(new Text("placeholder"));
}
}

View File

@ -0,0 +1,45 @@
/*
* Copyright (C) 2016 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.ui.admin.applications;
import com.arsdigita.bebop.ParameterSingleSelectionModel;
import com.arsdigita.bebop.Text;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public class DefaultApplicationSettingsPane
extends AbstractAppSettingsPane {
public DefaultApplicationSettingsPane(
final ParameterSingleSelectionModel<String> selectedAppType,
final ParameterSingleSelectionModel<String> selectedAppInstance) {
super(selectedAppType, selectedAppInstance);
}
@Override
protected void createWidgets() {
add(new Text(""));
}
}

View File

@ -18,6 +18,10 @@
*/
package org.libreccm.web;
import com.arsdigita.ui.admin.applications.AbstractAppInstanceForm;
import com.arsdigita.ui.admin.applications.AbstractAppSettingsPane;
import com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm;
import com.arsdigita.ui.admin.applications.DefaultApplicationSettingsPane;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@ -58,11 +62,11 @@ public @interface ApplicationType {
* bundle. Defaults to {@code application_title}
*
* @return
*
* @return
*
* @return
*/
String titleKey() default "application_title";
/**
* The (optional) key for the description of the application in its resource
* bundle. Defaults to {@code application_desc}
@ -70,7 +74,7 @@ public @interface ApplicationType {
* @return
*/
String descKey() default "application_desc";
/**
* The application type class. Default is {@link CcmApplication}. Most
* application types will no need to extend these class and can leave the
@ -111,9 +115,9 @@ public @interface ApplicationType {
* @return
*/
Class<? extends ApplicationCreator> creator();
//Class<? extends AbstractApplicationTypePane> appTypePane default com.arsdigita.ui.admin.applications.DefaultApplicationTypePane.class;
Class<? extends AbstractAppInstanceForm> instanceForm() default DefaultApplicationInstanceForm.class;
Class<? extends AbstractAppSettingsPane> settingsPane() default DefaultApplicationSettingsPane.class;
}

View File

@ -40,8 +40,7 @@ import org.libreccm.web.ApplicationType;
@ApplicationType(name = ShortcutsConstants.SHORTCUTS_APP_TYPE,
descBundle = "org.libreccm.shortcuts.ShortcutsResources",
singleton = true,
creator = ShortcutsApplicationCreator.class)}
)
creator = ShortcutsApplicationCreator.class)})
public class Shortcuts implements CcmModule {
@Override

View File

@ -0,0 +1,19 @@
# Copyright (C) 2016 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
application_title=Shortcuts
application_desc=Manage short URLs for internal and external redirects.

View File

@ -0,0 +1,19 @@
# Copyright (C) 2016 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
application_title=Shortcuts
application_desc=Manage short URLs for internal and external redirects.