Removed depcrecated package com.arsdigita.ui.admin.applications and several other depcrecated classes from ccm-core
parent
edba4c3ec2
commit
50be17c101
|
|
@ -1,63 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 org.librecms.contentsection.ui.admin;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.ui.admin.applications.DefaultApplicationInstanceForm;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.librecms.contentsection.ContentSectionManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationInstanceForm extends DefaultApplicationInstanceForm {
|
|
||||||
|
|
||||||
public ApplicationInstanceForm(
|
|
||||||
final String name,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppInstance) {
|
|
||||||
|
|
||||||
super(name, selectedAppType, selectedAppInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected FormProcessListener createProcessListener() {
|
|
||||||
return (FormSectionEvent e) -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
if (getSaveCancelSection().getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String primaryUrlData = data.getString(
|
|
||||||
"new_instance_primary_url");
|
|
||||||
|
|
||||||
final ContentSectionManager manager = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ContentSectionManager.class);
|
|
||||||
|
|
||||||
manager.createContentSection(primaryUrlData);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,72 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 org.librecms.contentsection.ui.admin;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Link;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.ui.admin.applications.AbstractAppSettingsPane;
|
|
||||||
import com.arsdigita.web.RedirectSignal;
|
|
||||||
import com.arsdigita.web.URL;
|
|
||||||
|
|
||||||
import org.librecms.CmsConstants;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class SettingsPane extends AbstractAppSettingsPane {
|
|
||||||
|
|
||||||
public SettingsPane(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppInstance) {
|
|
||||||
super(selectedAppType, selectedAppInstance);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void createWidgets() {
|
|
||||||
final Label label = new Label(new GlobalizedMessage(
|
|
||||||
"contentsection.ui.admin.app_note", CmsConstants.CMS_BUNDLE));
|
|
||||||
add(label);
|
|
||||||
|
|
||||||
final ActionLink link = new ActionLink(new GlobalizedMessage(
|
|
||||||
"contentsection.ui.admin.link_app", CmsConstants.CMS_BUNDLE));
|
|
||||||
link.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final String primaryUrl;
|
|
||||||
if (getSelectedAppInstance(state).get().getPrimaryUrl().startsWith(
|
|
||||||
"/")) {
|
|
||||||
primaryUrl = getSelectedAppInstance(state).get().getPrimaryUrl();
|
|
||||||
} else {
|
|
||||||
primaryUrl = String.format(
|
|
||||||
"/%s",
|
|
||||||
getSelectedAppInstance(state).get().getPrimaryUrl());
|
|
||||||
}
|
|
||||||
throw new RedirectSignal(
|
|
||||||
URL.there(state.getRequest(), primaryUrl, null),
|
|
||||||
false);
|
|
||||||
});
|
|
||||||
add(link);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,324 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2012 Peter Boy <pb@zes.uni-bremen.de> All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin;
|
|
||||||
|
|
||||||
import com.arsdigita.ui.admin.usersgroupsroles.UsersGroupsRolesTab;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageFactory;
|
|
||||||
import com.arsdigita.bebop.TabbedPane;
|
|
||||||
import com.arsdigita.dispatcher.AccessDeniedException;
|
|
||||||
import com.arsdigita.dispatcher.DispatcherHelper;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.templating.Templating;
|
|
||||||
import com.arsdigita.ui.SiteBanner;
|
|
||||||
import com.arsdigita.ui.UserBanner;
|
|
||||||
import com.arsdigita.ui.admin.applications.ApplicationsTab;
|
|
||||||
import com.arsdigita.ui.admin.categories.CategoriesTab;
|
|
||||||
import com.arsdigita.ui.admin.configuration.ConfigurationTab;
|
|
||||||
import com.arsdigita.ui.admin.importexport.ImportExportTab;
|
|
||||||
import com.arsdigita.ui.admin.pagemodels.PageModelsTab;
|
|
||||||
import com.arsdigita.ui.admin.sites.SitesTab;
|
|
||||||
import com.arsdigita.web.BaseApplicationServlet;
|
|
||||||
import com.arsdigita.web.LoginSignal;
|
|
||||||
import com.arsdigita.xml.Document;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.shiro.subject.Subject;
|
|
||||||
import org.libreccm.security.PermissionChecker;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import javax.enterprise.inject.spi.CDI;
|
|
||||||
import javax.servlet.ServletContext;
|
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
|
||||||
import javax.servlet.annotation.WebServlet;
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Web Developer Support Application Servlet class, central entry point to
|
|
||||||
* create and process the applications UI.
|
|
||||||
*
|
|
||||||
* We should have subclassed BebopApplicationServlet but couldn't overwrite
|
|
||||||
* doService() method to add permission checking. So we use our own page
|
|
||||||
* mapping. The general logic is the same as for BebopApplicationServlet.
|
|
||||||
*
|
|
||||||
* {
|
|
||||||
*
|
|
||||||
* @see com.arsdigita.bebop.page.BebopApplicationServlet}
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
* @author pb
|
|
||||||
*/
|
|
||||||
@WebServlet(urlPatterns = {ADMIN_SERVLET_PATH})
|
|
||||||
public class AdminServlet extends BaseApplicationServlet {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3912367600768871630L;
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager
|
|
||||||
.getLogger(AdminServlet.class);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Logger instance for debugging
|
|
||||||
*/
|
|
||||||
//private static final Logger LOGGER = Logger.getLogger(AdminServlet.class.getName());
|
|
||||||
/**
|
|
||||||
* URL (pathinfo) -> Page object mapping. Based on it (and the http request
|
|
||||||
* url) the doService method to selects a page to display
|
|
||||||
*/
|
|
||||||
// private final Map<String, Page> pages = new HashMap<String, Page>();
|
|
||||||
private Page adminPage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* User extension point, overwrite this method to setup a URL - page mapping
|
|
||||||
*
|
|
||||||
* @throws ServletException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void doInit() throws ServletException {
|
|
||||||
//addPage("/", buildAdminIndexPage()); // index page at address ~/ds
|
|
||||||
// addPage("/index.jsp", buildIndexPage()); // index page at address ~/ds
|
|
||||||
|
|
||||||
adminPage = PageFactory.buildPage("admin", "LibreCCM NG Admin");
|
|
||||||
// adminPage.addGlobalStateParam(USER_ID_PARAM);
|
|
||||||
// adminPage.addGlobalStateParam(GROUP_ID_PARAM);
|
|
||||||
// adminPage.addGlobalStateParam(APPLICATIONS_ID_PARAM);
|
|
||||||
|
|
||||||
adminPage.add(new UserBanner());
|
|
||||||
adminPage.add(new SiteBanner());
|
|
||||||
|
|
||||||
//Create tab bar
|
|
||||||
final TabbedPane tabbedPane = new TabbedPane();
|
|
||||||
tabbedPane.setIdAttr("page-body");
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.applications",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new ApplicationsTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.sites.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new SitesTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(new Label(new GlobalizedMessage("ui.admin.tab.pagemodels.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new PageModelsTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.tab.users_groups_roles.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new UsersGroupsRolesTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.categories.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new CategoriesTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.configuration.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new ConfigurationTab());
|
|
||||||
|
|
||||||
// tabbedPane.addTab(
|
|
||||||
// new Label(new GlobalizedMessage("ui.admin.tab.workflows.title",
|
|
||||||
// ADMIN_BUNDLE)),
|
|
||||||
// new WorkflowAdminTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.importexport.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new ImportExportTab());
|
|
||||||
|
|
||||||
tabbedPane.addTab(
|
|
||||||
new Label(new GlobalizedMessage("ui.admin.tab.sysinfo.title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
new SystemInformationTab());
|
|
||||||
|
|
||||||
final ServletContext servletContext = getServletContext();
|
|
||||||
final String develMode = servletContext
|
|
||||||
.getInitParameter("ccm.develmode");
|
|
||||||
if (develMode != null && "true".equals(develMode.toLowerCase())) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//page.add(new Label("admin"));
|
|
||||||
adminPage.add(tabbedPane);
|
|
||||||
|
|
||||||
adminPage.lock();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Central service method, checks for required permission, determines the
|
|
||||||
* requested page and passes the page object to PresentationManager.
|
|
||||||
*
|
|
||||||
* @param sreq
|
|
||||||
* @param sresp
|
|
||||||
* @param app
|
|
||||||
*
|
|
||||||
* @throws ServletException
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public final void doService(final HttpServletRequest sreq,
|
|
||||||
final HttpServletResponse sresp,
|
|
||||||
final CcmApplication app) throws
|
|
||||||
ServletException, IOException {
|
|
||||||
// /////// Some preparational steps ///////////////
|
|
||||||
/* Determine access privilege: only logged in users may access */
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final Subject subject = cdiUtil.findBean(Subject.class);
|
|
||||||
final PermissionChecker permissionChecker = cdiUtil.findBean(
|
|
||||||
PermissionChecker.class);
|
|
||||||
|
|
||||||
final ConfigurationManager confManager = CDI.current().select(
|
|
||||||
ConfigurationManager.class).get();
|
|
||||||
if (confManager == null) {
|
|
||||||
throw new IllegalStateException();
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.debug("Checking if subject {} is authenticated...",
|
|
||||||
subject.toString());
|
|
||||||
LOGGER.debug("Current session is: {}", sreq.getSession().getId());
|
|
||||||
LOGGER.debug("Current Shiro session is {}",
|
|
||||||
subject.getSession().getId().toString());
|
|
||||||
if (!subject.isAuthenticated()) {
|
|
||||||
LOGGER.debug(
|
|
||||||
"Subject {} is not authenticated, redirecting to login...",
|
|
||||||
subject.toString());
|
|
||||||
throw new LoginSignal(sreq);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Determine access privilege: Admin privileges must be granted */
|
|
||||||
LOGGER.debug(
|
|
||||||
"Subject is loggedin, checking if subject has required permissions...");
|
|
||||||
if (!permissionChecker.isPermitted("admin")) {
|
|
||||||
LOGGER.debug("Subject does *not* have required permissions. "
|
|
||||||
+ "Access denied.");
|
|
||||||
throw new AccessDeniedException("User is not an administrator");
|
|
||||||
}
|
|
||||||
|
|
||||||
LOGGER.debug("Serving admin page...");
|
|
||||||
/* Want admin to always show the latest stuff... */
|
|
||||||
DispatcherHelper.cacheDisable(sresp);
|
|
||||||
|
|
||||||
// /////// Everything OK here - DO IT ///////////////
|
|
||||||
// String pathInfo = sreq.getPathInfo();
|
|
||||||
// Assert.exists(pathInfo, "String pathInfo");
|
|
||||||
// if (pathInfo.length() > 1 && pathInfo.endsWith("/")) {
|
|
||||||
// /* NOTE: ServletAPI specifies, pathInfo may be empty or will
|
|
||||||
// * start with a '/' character. It currently carries a
|
|
||||||
// * trailing '/' if a "virtual" page, i.e. not a real jsp, but
|
|
||||||
// * result of a servlet mapping. But Application requires url
|
|
||||||
// * NOT to end with a trailing '/' for legacy free applications. */
|
|
||||||
// pathInfo = pathInfo.substring(0, pathInfo.length() - 1);
|
|
||||||
// }
|
|
||||||
// final Page page = pages.get(pathInfo);
|
|
||||||
// if (page == null) {
|
|
||||||
// sresp.sendError(404, "No such page for path " + pathInfo);
|
|
||||||
// } else {
|
|
||||||
// final Document doc = page.buildDocument(sreq, sresp);
|
|
||||||
// Templating.getPresentationManager().servePage(doc, sreq, sresp);
|
|
||||||
// }
|
|
||||||
final Document doc = adminPage.buildDocument(sreq, sresp);
|
|
||||||
Templating.getPresentationManager().servePage(doc, sreq, sresp);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds one pair of Url - Page to the internal hash map, used as a cache.
|
|
||||||
*
|
|
||||||
* @param pathInfo url stub for a page to display
|
|
||||||
* @param page Page object to display
|
|
||||||
*/
|
|
||||||
// private void addPage(final String pathInfo, final Page page) {
|
|
||||||
// Assert.exists(pathInfo, String.class);
|
|
||||||
// Assert.exists(page, Page.class);
|
|
||||||
// // Current Implementation requires pathInfo to start with a leading '/'
|
|
||||||
// // SUN Servlet API specifies: "PathInfo *may be empty* or will start
|
|
||||||
// // with a '/' character."
|
|
||||||
// Assert.isTrue(pathInfo.charAt(0) == '/', "path starts not with '/'");
|
|
||||||
//
|
|
||||||
// pages.put(pathInfo, page);
|
|
||||||
// }
|
|
||||||
/**
|
|
||||||
* Index page for the admin section
|
|
||||||
*/
|
|
||||||
// private Page buildAdminIndexPage() {
|
|
||||||
//
|
|
||||||
// final Page page = PageFactory.buildPage("admin", PAGE_TITLE_LABEL);
|
|
||||||
// page.addGlobalStateParam(USER_ID_PARAM);
|
|
||||||
// page.addGlobalStateParam(GROUP_ID_PARAM);
|
|
||||||
// page.addGlobalStateParam(APPLICATIONS_ID_PARAM);
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * Create User split panel.
|
|
||||||
// * Note: Will change soon.
|
|
||||||
// */
|
|
||||||
// //final AdminSplitPanel userSplitPanel = new AdminSplitPanel(USER_NAVBAR_TITLE);
|
|
||||||
//// final UserBrowsePane browsePane = new UserBrowsePane();
|
|
||||||
//// userSplitPanel.addTab(USER_TAB_SUMMARY, new UserSummaryPane(userSplitPanel, browsePane));
|
|
||||||
//// userSplitPanel.addTab(USER_TAB_BROWSE, browsePane);
|
|
||||||
//// userSplitPanel.addTab(USER_TAB_SEARCH, new UserSearchPane(userSplitPanel, browsePane));
|
|
||||||
//// userSplitPanel.addTab(USER_TAB_CREATE_USER, new CreateUserPane(userSplitPanel));
|
|
||||||
// // Create the Admin's page tab bar
|
|
||||||
// final TabbedPane tabbedPane = new TabbedPane();
|
|
||||||
// tabbedPane.setIdAttr("page-body");
|
|
||||||
//
|
|
||||||
// /**
|
|
||||||
// * Create and add info tab
|
|
||||||
// */
|
|
||||||
// //tabbedPane.addTab(INFO_TAB_TITLE, new AdminInfoTab());
|
|
||||||
// /*
|
|
||||||
// * Create and add the user and group tabs.
|
|
||||||
// */
|
|
||||||
// //tabbedPane.addTab(USER_TAB_TITLE, userSplitPanel);
|
|
||||||
// final GroupAdministrationTab groupAdminTab
|
|
||||||
// = new GroupAdministrationTab();
|
|
||||||
// tabbedPane.addTab(USER_TAB_TITLE, new UserAdministrationTab(tabbedPane,
|
|
||||||
// groupAdminTab));
|
|
||||||
// tabbedPane.addTab(GROUP_TAB_TITLE, groupAdminTab);
|
|
||||||
//
|
|
||||||
// /*
|
|
||||||
// * Create application administration panel
|
|
||||||
// */
|
|
||||||
// tabbedPane.addTab(APPLICATIONS_TAB_TITLE,
|
|
||||||
// new ApplicationsAdministrationTab());
|
|
||||||
//
|
|
||||||
//// browsePane.setTabbedPane(tabbedPane);
|
|
||||||
//// browsePane.setGroupAdministrationTab(groupAdminTab);
|
|
||||||
// //Add System information tab
|
|
||||||
// tabbedPane.addTab(SYSINFO_TAB_TITLE, new SystemInformationTab());
|
|
||||||
//
|
|
||||||
// page.add(tabbedPane);
|
|
||||||
// page.lock();
|
|
||||||
//
|
|
||||||
// return page;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin;
|
|
||||||
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Globalization Util for admin classes
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class GlobalizationUtil {
|
|
||||||
|
|
||||||
private static final String BUNDLE_NAME = "com.arsdigita.ui.admin.AdminResources";
|
|
||||||
|
|
||||||
public static GlobalizedMessage globalize(final String key) {
|
|
||||||
return new GlobalizedMessage(key, BUNDLE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GlobalizedMessage globalize(final String key, final Object[] args) {
|
|
||||||
return new GlobalizedMessage(key, BUNDLE_NAME, args);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,168 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 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;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.bebop.SimpleComponent;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.xml.Element;
|
|
||||||
import java.beans.IntrospectionException;
|
|
||||||
import java.beans.Introspector;
|
|
||||||
import java.beans.PropertyDescriptor;
|
|
||||||
import java.lang.reflect.Method;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Set;
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class JpqlConsole extends LayoutPanel {
|
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(JpqlConsole.class);
|
|
||||||
|
|
||||||
private final Form queryForm;
|
|
||||||
private final TextArea queryArea;
|
|
||||||
|
|
||||||
public JpqlConsole() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
final SegmentedPanel panel = new SegmentedPanel();
|
|
||||||
|
|
||||||
queryForm = new Form("jpql-console-query-form");
|
|
||||||
|
|
||||||
queryArea = new TextArea("jpql-console-query-area");
|
|
||||||
queryArea.setCols(132);
|
|
||||||
queryArea.setRows(42);
|
|
||||||
|
|
||||||
final BoxPanel hpanel = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
hpanel.add(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.jpqlconsole.query.label",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)));
|
|
||||||
hpanel.add(queryArea);
|
|
||||||
|
|
||||||
final BoxPanel vpanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
vpanel.add(hpanel);
|
|
||||||
final SaveCancelSection saveCancelSection = new SaveCancelSection();
|
|
||||||
saveCancelSection.getSaveButton().setLabel(
|
|
||||||
new GlobalizedMessage("ui.admin.jpqlconsole.query.execute",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
saveCancelSection.getCancelButton().setLabel(
|
|
||||||
new GlobalizedMessage("ui.admin.jpqlconsole.query.clear",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
vpanel.add(saveCancelSection);
|
|
||||||
|
|
||||||
queryForm.add(hpanel);
|
|
||||||
|
|
||||||
panel.addSegment(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.jpqlconsole.query.segment.title",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE)),
|
|
||||||
queryForm);
|
|
||||||
|
|
||||||
setBody(panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class QueryResults extends SimpleComponent {
|
|
||||||
|
|
||||||
private List<?> results;
|
|
||||||
|
|
||||||
public List<?> getResults() {
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setResults(final List<?> results) {
|
|
||||||
this.results = results;
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<PropertyDescriptor> getProperties(final List<?> results)
|
|
||||||
throws IntrospectionException {
|
|
||||||
|
|
||||||
final Set<PropertyDescriptor> propertyDescriptors = new HashSet<>();
|
|
||||||
|
|
||||||
for (final Object obj : results) {
|
|
||||||
final PropertyDescriptor[] properties = Introspector
|
|
||||||
.getBeanInfo(obj.getClass()).getPropertyDescriptors();
|
|
||||||
|
|
||||||
for (final PropertyDescriptor property : properties) {
|
|
||||||
propertyDescriptors.add(property);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
final List<PropertyDescriptor> propertiesList
|
|
||||||
= new ArrayList<>(propertyDescriptors);
|
|
||||||
propertiesList.sort((prop1, prop2) -> {
|
|
||||||
return prop1.getName().compareTo(prop2.getName());
|
|
||||||
});
|
|
||||||
|
|
||||||
return propertiesList;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void generateXML(final PageState state,
|
|
||||||
final Element parent) {
|
|
||||||
|
|
||||||
final Element queryResults = parent
|
|
||||||
.newChildElement("bebop:query-results", BEBOP_XML_NS);
|
|
||||||
|
|
||||||
// Find all properties in the results
|
|
||||||
final List<PropertyDescriptor> properties;
|
|
||||||
try {
|
|
||||||
properties = getProperties(results);
|
|
||||||
} catch (IntrospectionException ex) {
|
|
||||||
queryArea.addError(new GlobalizedMessage(
|
|
||||||
"ui.admin.jpqlconsole.failed_to_render_results",
|
|
||||||
AdminUiConstants.ADMIN_BUNDLE));
|
|
||||||
LOGGER.error("Failed to render results.", ex);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Element columns = queryResults
|
|
||||||
.newChildElement("bebop:query-result-columns", BEBOP_XML_NS);
|
|
||||||
for (final PropertyDescriptor property : properties) {
|
|
||||||
final Element column = columns
|
|
||||||
.newChildElement("bebop:query-result-column", BEBOP_XML_NS);
|
|
||||||
column.setText(property.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
final Element resultList = queryResults
|
|
||||||
.newChildElement("bebop:query-result-list", BEBOP_XML_NS);
|
|
||||||
for(final Object obj : results) {
|
|
||||||
for(final PropertyDescriptor property : properties) {
|
|
||||||
final Method readMethod = property.getReadMethod();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,320 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/package com.arsdigita.ui.admin;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import com.arsdigita.util.SystemInformation;
|
|
||||||
|
|
||||||
import java.util.Enumeration;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Properties;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
|
||||||
import javax.xml.transform.TransformerConfigurationException;
|
|
||||||
import javax.xml.transform.TransformerFactory;
|
|
||||||
|
|
||||||
import org.xml.sax.SAXException;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
*/
|
|
||||||
public class SystemInformationTab extends LayoutPanel {
|
|
||||||
|
|
||||||
public SystemInformationTab() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
final SegmentedPanel panel = new SegmentedPanel();
|
|
||||||
|
|
||||||
panel.addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.appinfo")),
|
|
||||||
new PropertySheet(
|
|
||||||
new CCMSysInfoPropertySheetModelBuilder()));
|
|
||||||
|
|
||||||
panel.addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.java_system_properties")),
|
|
||||||
new PropertySheet(
|
|
||||||
new JavaSystemPropertiesSheetModelBuilder()));
|
|
||||||
|
|
||||||
panel.addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.xml_config")),
|
|
||||||
new PropertySheet(new XMLConfigSheetModelBuilder()));
|
|
||||||
|
|
||||||
setRight(panel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CCMSysInfoPropertySheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
public CCMSysInfoPropertySheetModelBuilder() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
return new CCMSysInfoPropertySheetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CCMSysInfoPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private final SystemInformation sysInfo;
|
|
||||||
private final Iterator<Map.Entry<String, String>> sysInfoIterator;
|
|
||||||
private Map.Entry<String, String> currentProperty;
|
|
||||||
|
|
||||||
public CCMSysInfoPropertySheetModel() {
|
|
||||||
sysInfo = SystemInformation.getInstance();
|
|
||||||
sysInfoIterator = sysInfo.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
final boolean result = sysInfoIterator.hasNext();
|
|
||||||
if (result) {
|
|
||||||
currentProperty = sysInfoIterator.next();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
if (currentProperty == null) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return currentProperty.getKey();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return GlobalizationUtil.globalize(currentProperty.getKey());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return currentProperty.getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JavaSystemPropertiesSheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
public JavaSystemPropertiesSheetModelBuilder() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
return new JavaSystemPropertiesSheetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class JavaSystemPropertiesSheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private final Properties systemProperties;
|
|
||||||
private final Enumeration<?> enumeration;
|
|
||||||
private Object currentElement;
|
|
||||||
|
|
||||||
public JavaSystemPropertiesSheetModel() {
|
|
||||||
systemProperties = System.getProperties();
|
|
||||||
enumeration = systemProperties.propertyNames();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
final boolean result = enumeration.hasMoreElements();
|
|
||||||
if (result) {
|
|
||||||
currentElement = enumeration.nextElement();
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentElement.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return GlobalizationUtil.globalize(currentElement.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
return systemProperties.getProperty(currentElement.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class XMLConfigSheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
public XMLConfigSheetModelBuilder() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
return new XMLConfigSheetModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class XMLConfigSheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static final int TRANSFORMER_FACTORY_INDEX = 0;
|
|
||||||
private static final int TRANSFORMER_INDEX = 1;
|
|
||||||
private static final int DOCUMENT_BUILDER_FACTORY_INDEX = 2;
|
|
||||||
private static final int DOCUMENT_BUILDER_INDEX = 3;
|
|
||||||
private static final int SAX_PARSER_FACTORY_INDEX = 4;
|
|
||||||
private static final int SAX_PARSER_INDEX = 5;
|
|
||||||
private int currentIndex = -1;
|
|
||||||
|
|
||||||
public XMLConfigSheetModel() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
currentIndex++;
|
|
||||||
return currentIndex <= SAX_PARSER_INDEX;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case TRANSFORMER_FACTORY_INDEX:
|
|
||||||
return "XML Transformer Factory";
|
|
||||||
case TRANSFORMER_INDEX:
|
|
||||||
return "XML Transformer";
|
|
||||||
case DOCUMENT_BUILDER_FACTORY_INDEX:
|
|
||||||
return "XML Document Builder Factory";
|
|
||||||
case DOCUMENT_BUILDER_INDEX:
|
|
||||||
return "XML Document Builder";
|
|
||||||
case SAX_PARSER_FACTORY_INDEX:
|
|
||||||
return "SAX Parser Factory";
|
|
||||||
case SAX_PARSER_INDEX:
|
|
||||||
return "SAX Parser";
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case TRANSFORMER_FACTORY_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.xml_transformer_factory");
|
|
||||||
case TRANSFORMER_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.xml_transformer");
|
|
||||||
case DOCUMENT_BUILDER_FACTORY_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.xml_document_builder_factory");
|
|
||||||
case DOCUMENT_BUILDER_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.xml_document_builder");
|
|
||||||
case SAX_PARSER_FACTORY_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.sax_parser_factory");
|
|
||||||
case SAX_PARSER_INDEX:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.sysinfo.sax_parser");
|
|
||||||
default:
|
|
||||||
return GlobalizationUtil.globalize("unknown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case TRANSFORMER_FACTORY_INDEX:
|
|
||||||
return TransformerFactory
|
|
||||||
.newInstance()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
case TRANSFORMER_INDEX:
|
|
||||||
try {
|
|
||||||
return TransformerFactory
|
|
||||||
.newInstance()
|
|
||||||
.newTransformer()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
} catch (TransformerConfigurationException ex) {
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
case DOCUMENT_BUILDER_FACTORY_INDEX:
|
|
||||||
return DocumentBuilderFactory
|
|
||||||
.newInstance()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
case DOCUMENT_BUILDER_INDEX:
|
|
||||||
try {
|
|
||||||
return DocumentBuilderFactory
|
|
||||||
.newInstance()
|
|
||||||
.newDocumentBuilder()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
} catch (ParserConfigurationException ex) {
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
case SAX_PARSER_FACTORY_INDEX:
|
|
||||||
return SAXParserFactory
|
|
||||||
.newInstance()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
case SAX_PARSER_INDEX:
|
|
||||||
try {
|
|
||||||
return SAXParserFactory
|
|
||||||
.newInstance()
|
|
||||||
.newSAXParser()
|
|
||||||
.getClass()
|
|
||||||
.getName();
|
|
||||||
} catch (ParserConfigurationException | SAXException ex) {
|
|
||||||
return "???";
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,84 +0,0 @@
|
||||||
/*
|
|
||||||
* 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 com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
|
|
||||||
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();
|
|
||||||
|
|
||||||
addProcessListener(createProcessListener());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void createWidgets();
|
|
||||||
|
|
||||||
protected abstract FormProcessListener createProcessListener();
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
return appRepo.findById(Long.parseLong(
|
|
||||||
selectedAppInstance.getSelectedKey(state)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,78 +0,0 @@
|
||||||
/*
|
|
||||||
* 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);
|
|
||||||
|
|
||||||
return appRepo.findById(Long.parseLong(
|
|
||||||
selectedAppInstance.getSelectedKey(state)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractApplicationTypeInstancesPane extends BoxPanel {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppType;
|
|
||||||
|
|
||||||
private final Form instanceForm;
|
|
||||||
|
|
||||||
public AbstractApplicationTypeInstancesPane(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType) {
|
|
||||||
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
this.selectedAppType = selectedAppType;
|
|
||||||
|
|
||||||
instanceForm = createInstanceForm();
|
|
||||||
add(instanceForm);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract Form createInstanceForm();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
|
|
||||||
page.setVisibleDefault(instanceForm, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InstanceTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_TITLE = 0;
|
|
||||||
private static final int COL_URL = 1;
|
|
||||||
private static final int COL_EDIT = 2;
|
|
||||||
|
|
||||||
private final AbstractApplicationTypeInstancesPane instancesPane;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppType;
|
|
||||||
|
|
||||||
public InstanceTable(
|
|
||||||
final AbstractApplicationTypeInstancesPane instancesPane,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.instancesPane = instancesPane;
|
|
||||||
this.selectedAppType = selectedAppType;
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_TITLE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.instances.col_title",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_URL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.instances.col_url",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.instances.col_edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public abstract class AbstractApplicationTypePane extends BoxPanel {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppType;
|
|
||||||
|
|
||||||
private final SimpleContainer pane;
|
|
||||||
private final PropertySheet propertySheet;
|
|
||||||
|
|
||||||
public AbstractApplicationTypePane(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType) {
|
|
||||||
|
|
||||||
super(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
this.selectedAppType = selectedAppType;
|
|
||||||
|
|
||||||
final BoxPanel links = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
final ActionLink paneLink = new ActionLink(getPaneLabel());
|
|
||||||
paneLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
showPane(state);
|
|
||||||
});
|
|
||||||
links.add(paneLink);
|
|
||||||
final ActionLink propertySheetLink = new ActionLink(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.appliations.type_pane.info_sheet",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
propertySheetLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
showPropertySheet(state);
|
|
||||||
});
|
|
||||||
links.add(propertySheetLink);
|
|
||||||
add(links);
|
|
||||||
|
|
||||||
pane = createPane();
|
|
||||||
add(pane);
|
|
||||||
|
|
||||||
propertySheet = new PropertySheet(
|
|
||||||
new ApplicationTypePropertySheetModelBuilder(selectedAppType));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract SimpleContainer createPane();
|
|
||||||
|
|
||||||
protected abstract GlobalizedMessage getPaneLabel();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.setVisibleDefault(pane, true);
|
|
||||||
page.setVisibleDefault(propertySheet, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showPane(final PageState state) {
|
|
||||||
pane.setVisible(state, true);
|
|
||||||
propertySheet.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showPropertySheet(final PageState state) {
|
|
||||||
pane.setVisible(state, false);
|
|
||||||
propertySheet.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* An abstract class providing a default implementation of
|
|
||||||
* {@link ApplicationManager#getApplicationCreateForm()}.
|
|
||||||
*
|
|
||||||
* @param <T> Type of the application for which this ApplicationManager provides
|
|
||||||
* the administration forms.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: AbstractSingletonApplicationManager.java 3703 2015-10-21
|
|
||||||
* 08:52:39Z jensp $
|
|
||||||
*/
|
|
||||||
public abstract class AbstractSingletonApplicationManager<T extends CcmApplication>
|
|
||||||
implements ApplicationManager<T> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementation of {@link ApplicationManager#getApplicationCreateForm()}
|
|
||||||
* for singleton applications.
|
|
||||||
*
|
|
||||||
* @return {@code} null because it is not possible to create instances of
|
|
||||||
* singleton applications.
|
|
||||||
*/
|
|
||||||
@SuppressWarnings("PMD.EmptyMethodInAbstractClassShouldBeAbstract")
|
|
||||||
@Override
|
|
||||||
public final Form getApplicationCreateForm() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: ApplicationInstanceAwareContainer.java 2234 2013-06-29 12:41:57Z jensp $
|
|
||||||
*/
|
|
||||||
public class ApplicationInstanceAwareContainer extends SimpleContainer {
|
|
||||||
|
|
||||||
private CcmApplication appInstance;
|
|
||||||
|
|
||||||
public CcmApplication getAppInstance() {
|
|
||||||
return appInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAppInstance(final CcmApplication appInstance) {
|
|
||||||
this.appInstance = appInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2021 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.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
class ApplicationInstanceTreeCdiUtil implements Serializable {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ApplicationRepository applicationRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private ConfigurationManager confManager;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private GlobalizationHelper globalizationHelper;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
public String getTitle(final CcmApplication ofApplication) {
|
|
||||||
final CcmApplication application = applicationRepo
|
|
||||||
.findById(ofApplication.getObjectId())
|
|
||||||
.orElseThrow(
|
|
||||||
() -> new IllegalArgumentException(
|
|
||||||
String.format(
|
|
||||||
"No CcmApplication with ID %d available.",
|
|
||||||
ofApplication.getObjectId()
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
KernelConfig.class);
|
|
||||||
final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
if (application.getTitle().hasValue(globalizationHelper
|
|
||||||
.getNegotiatedLocale())) {
|
|
||||||
title = application.getTitle().getValue(globalizationHelper
|
|
||||||
.getNegotiatedLocale());
|
|
||||||
} else if (application.getTitle().hasValue(defaultLocale)) {
|
|
||||||
title = application.getTitle().getValue(defaultLocale);
|
|
||||||
} else if (application.getTitle().hasValue(Locale.getDefault())) {
|
|
||||||
title = application.getTitle().getValue(Locale.getDefault());
|
|
||||||
} else {
|
|
||||||
title = application.getPrimaryUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,85 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.tree.TreeNode;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.configuration.ConfigurationManager;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationInstanceTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
protected static final String INSTANCE_NODE_KEY_PREFIX = "appinstance_";
|
|
||||||
|
|
||||||
private final CcmApplication application;
|
|
||||||
|
|
||||||
public ApplicationInstanceTreeNode(final CcmApplication application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return String.format("%s%d",
|
|
||||||
INSTANCE_NODE_KEY_PREFIX,
|
|
||||||
application.getObjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
// final GlobalizationHelper globalizationHelper = cdiUtil
|
|
||||||
// .findBean(GlobalizationHelper.class);
|
|
||||||
final ConfigurationManager confManager = cdiUtil
|
|
||||||
.findBean(ConfigurationManager.class);
|
|
||||||
// final KernelConfig kernelConfig = confManager.findConfiguration(
|
|
||||||
// KernelConfig.class);
|
|
||||||
// final Locale defaultLocale = kernelConfig.getDefaultLocale();
|
|
||||||
final ApplicationInstanceTreeCdiUtil util = cdiUtil
|
|
||||||
.findBean(ApplicationInstanceTreeCdiUtil.class);
|
|
||||||
|
|
||||||
// final String title;
|
|
||||||
// if (application.getTitle().hasValue(globalizationHelper
|
|
||||||
// .getNegotiatedLocale())) {
|
|
||||||
// title = application.getTitle().getValue(globalizationHelper
|
|
||||||
// .getNegotiatedLocale());
|
|
||||||
// } else if (application.getTitle().hasValue(defaultLocale)) {
|
|
||||||
// title = application.getTitle().getValue(defaultLocale);
|
|
||||||
// } else if (application.getTitle().hasValue(Locale.getDefault())) {
|
|
||||||
// title = application.getTitle().getValue(Locale.getDefault());
|
|
||||||
// } else {
|
|
||||||
// title = application.getPrimaryUrl();
|
|
||||||
// }
|
|
||||||
// return title;
|
|
||||||
return util.getTitle(application);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CcmApplication getApplication() {
|
|
||||||
return application;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,82 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
|
|
||||||
import java.util.ServiceLoader;
|
|
||||||
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Implementations of this class are used by the new
|
|
||||||
* {@link ApplicationsAdministrationTab} to get the forms for editing the
|
|
||||||
* configuration of an application and for creating new instances of an
|
|
||||||
* application.
|
|
||||||
*
|
|
||||||
* The {@link ApplicationsAdministrationTab} uses the {@link ServiceLoader}
|
|
||||||
* from the Java Standard Library to find all implementations of this interface.
|
|
||||||
* To make implementations of this interface known add an file named
|
|
||||||
* {@code com.arsdigita.ui.admin.applications.ApplicationManager} to the
|
|
||||||
* {@code META-INF/services} directory of the module which provides the
|
|
||||||
* application. In this file add a line with the full qualified class name
|
|
||||||
* of each implementations of this interface provided by the module.
|
|
||||||
*
|
|
||||||
* There a two abstract classes to help you with implementing this class.
|
|
||||||
* {@link AbstractSingletonApplicationManager} is suitable for singleton
|
|
||||||
* applications. {@link AbstractApplicationManager} is for multi-instance
|
|
||||||
* applications.
|
|
||||||
*
|
|
||||||
* @param <T> Type of the application for which this ApplicationManager
|
|
||||||
* provides the administration forms.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: ApplicationManager.java 2275 2013-07-26 14:20:28Z jensp $
|
|
||||||
*/
|
|
||||||
public interface ApplicationManager<T extends CcmApplication> {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Used to determine the Applications class for which this
|
|
||||||
* manager provides the administration forms.
|
|
||||||
*
|
|
||||||
* @return The class of the application for which this
|
|
||||||
* manager provides the administration forms.
|
|
||||||
*/
|
|
||||||
Class<T> getApplication();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a pane with administration forms for the application or for an
|
|
||||||
* instance of the application if the application is not a singleton.
|
|
||||||
*
|
|
||||||
* @return A container containing one or more forms for managing instances
|
|
||||||
* of an application.
|
|
||||||
*/
|
|
||||||
ApplicationInstanceAwareContainer getApplicationAdminForm();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Provides a form for creating new instances of applications. For
|
|
||||||
* singleton applications an implementation of this method will return
|
|
||||||
* {@code null}.
|
|
||||||
*
|
|
||||||
* @return A form for creating new instances of applications or
|
|
||||||
* {@code null} if the is a singleton.
|
|
||||||
*/
|
|
||||||
Form getApplicationCreateForm();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2010 Jens Pelzetter, ScientificCMS.org team
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Helper class for managing the implementations of the {@link ApplicationManager} interface
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: ApplicationManagers.java 2294 2013-08-05 18:39:46Z jensp $
|
|
||||||
*/
|
|
||||||
public class ApplicationManagers {
|
|
||||||
|
|
||||||
private Map<String, ApplicationManager<?>> appManagers = new HashMap<String, ApplicationManager<?>>();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The one and only instance of this class. The pattern used here ensures that
|
|
||||||
* the instance is created at the first access, but not earlier.
|
|
||||||
*/
|
|
||||||
private static class Instance {
|
|
||||||
private static final ApplicationManagers INSTANCE = new ApplicationManagers();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Private constructor to ensure that no instances of this class can be created.
|
|
||||||
*/
|
|
||||||
private ApplicationManagers() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return The instance of this class.
|
|
||||||
*/
|
|
||||||
public static ApplicationManagers getInstance() {
|
|
||||||
return Instance.INSTANCE;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void register(final ApplicationManager<?> appManager) {
|
|
||||||
getInstance().registerApplicationManager(appManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void registerApplicationManager(final ApplicationManager<?> appManager) {
|
|
||||||
appManagers.put(appManager.getApplication().getName(), appManager);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Map<String, ApplicationManager<?>> getApplicationManagers() {
|
|
||||||
return Collections.unmodifiableMap(appManagers);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ApplicationManager<?> getApplicationManager(final String appClassName) {
|
|
||||||
return appManagers.get(appClassName);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,160 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTreeModel implements TreeModel {
|
|
||||||
|
|
||||||
public ApplicationTreeModel() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeNode getRoot(final PageState state) {
|
|
||||||
return new RootTreeNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasChildren(final TreeNode node,
|
|
||||||
final PageState state) {
|
|
||||||
if (node instanceof RootTreeNode) {
|
|
||||||
return true;
|
|
||||||
} else if (node instanceof ApplicationTypeTreeNode) {
|
|
||||||
final ApplicationTypeTreeNode typeNode
|
|
||||||
= (ApplicationTypeTreeNode) node;
|
|
||||||
final ApplicationType appType = typeNode.getApplicationType();
|
|
||||||
if (appType.singleton()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ApplicationRepository appRepo = cdiUtil.findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
final List<CcmApplication> apps = appRepo.findByType(appType
|
|
||||||
.name());
|
|
||||||
return !apps.isEmpty();
|
|
||||||
}
|
|
||||||
} else if (node instanceof ApplicationInstanceTreeNode) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The ApplicationTreeModel can only work with "
|
|
||||||
+ "ApplicationTypeTreeNodes and "
|
|
||||||
+ "ApplicationInstanceTreeNodes.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator getChildren(final TreeNode node,
|
|
||||||
final PageState state) {
|
|
||||||
if (node instanceof RootTreeNode) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = cdiUtil
|
|
||||||
.findBean(org.libreccm.web.ApplicationManager.class);
|
|
||||||
return new AppTypesIterator(appManager.getApplicationTypes()
|
|
||||||
.values());
|
|
||||||
} else if (node instanceof ApplicationTypeTreeNode) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ApplicationRepository appRepo = cdiUtil.findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
return new AppIterator(appRepo.findByType(
|
|
||||||
((ApplicationTypeTreeNode) node).getApplicationType().name()));
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"ApplicationTreeModel#getChildren can only process "
|
|
||||||
+ "the RootTreeNode and the instances of "
|
|
||||||
+ "ApplicationTypeTreeNode.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RootTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
public RootTreeNode() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return "-1";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppTypesIterator
|
|
||||||
implements Iterator<ApplicationTypeTreeNode> {
|
|
||||||
|
|
||||||
private final Iterator<ApplicationType> appTypes;
|
|
||||||
|
|
||||||
public AppTypesIterator(final Collection<ApplicationType> appTypes) {
|
|
||||||
this.appTypes = appTypes.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return appTypes.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationTypeTreeNode next() {
|
|
||||||
return new ApplicationTypeTreeNode(appTypes.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppIterator implements Iterator<ApplicationInstanceTreeNode> {
|
|
||||||
|
|
||||||
private final Iterator<CcmApplication> applications;
|
|
||||||
|
|
||||||
public AppIterator(final Collection<CcmApplication> applications) {
|
|
||||||
this.applications = applications.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return applications.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ApplicationInstanceTreeNode next() {
|
|
||||||
return new ApplicationInstanceTreeNode(applications.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,43 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.Tree;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTreeModelBuilder
|
|
||||||
extends LockableImpl implements TreeModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeModel makeModel(final Tree tree,
|
|
||||||
final PageState state) {
|
|
||||||
tree.expand("-1", state);
|
|
||||||
return new ApplicationTreeModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,133 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.databind.deser.CreatorProperty;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTypePropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static enum AppTypeProperty {
|
|
||||||
NAME,
|
|
||||||
TITLE,
|
|
||||||
DESC,
|
|
||||||
APP_CLASS,
|
|
||||||
CREATOR,
|
|
||||||
SINGLETON,
|
|
||||||
SERVLET_CLASS,
|
|
||||||
SERVLET_PATH,
|
|
||||||
}
|
|
||||||
|
|
||||||
private final ApplicationType applicationType;
|
|
||||||
private final Iterator<AppTypeProperty> propertyIterator;
|
|
||||||
private AppTypeProperty currentProperty;
|
|
||||||
|
|
||||||
public ApplicationTypePropertySheetModel(
|
|
||||||
final ApplicationType applicationType) {
|
|
||||||
|
|
||||||
this.applicationType = applicationType;
|
|
||||||
propertyIterator = Arrays.asList(AppTypeProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (applicationType == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generateGlobalizedLabel(
|
|
||||||
final AppTypeProperty property) {
|
|
||||||
|
|
||||||
final String key = String.join(
|
|
||||||
"",
|
|
||||||
"ui.admin.applications.type.property_sheet.",
|
|
||||||
property.toString().toLowerCase());
|
|
||||||
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generateGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch(currentProperty) {
|
|
||||||
case NAME:
|
|
||||||
return applicationType.name();
|
|
||||||
case TITLE:
|
|
||||||
return getAppTypeTitle();
|
|
||||||
case DESC:
|
|
||||||
return getAppTypeDesc();
|
|
||||||
case APP_CLASS:
|
|
||||||
return applicationType.applicationClass().getName();
|
|
||||||
case CREATOR:
|
|
||||||
return applicationType.creator().getName();
|
|
||||||
case SINGLETON:
|
|
||||||
return Boolean.toString(applicationType.singleton());
|
|
||||||
case SERVLET_CLASS:
|
|
||||||
return applicationType.servlet().getName();
|
|
||||||
case SERVLET_PATH:
|
|
||||||
return applicationType.servletPath();
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAppTypeTitle() {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
|
|
||||||
return appManager.getApplicationTypeTitle(applicationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getAppTypeDesc() {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
|
|
||||||
return appManager.getApplicationTypeDescription(applicationType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTypePropertySheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppType;
|
|
||||||
|
|
||||||
public ApplicationTypePropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType) {
|
|
||||||
|
|
||||||
this.selectedAppType = selectedAppType;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String selectedAppTypeStr = selectedAppType.getSelectedKey(state);
|
|
||||||
final ApplicationType applicationType;
|
|
||||||
|
|
||||||
if (selectedAppTypeStr == null || selectedAppTypeStr.isEmpty()) {
|
|
||||||
applicationType = null;
|
|
||||||
} else {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil
|
|
||||||
.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
applicationType = appManager.getApplicationTypes().get(
|
|
||||||
selectedAppTypeStr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return new ApplicationTypePropertySheetModel(applicationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,57 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.tree.TreeNode;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationTypeTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
protected final static String TYPE_NODE_KEY_PREFIX = "apptype_";
|
|
||||||
|
|
||||||
private final ApplicationType applicationType;
|
|
||||||
|
|
||||||
public ApplicationTypeTreeNode(final ApplicationType applicationType) {
|
|
||||||
this.applicationType = applicationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return String.join("", TYPE_NODE_KEY_PREFIX, applicationType.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil
|
|
||||||
.createCdiUtil().findBean(org.libreccm.web.ApplicationManager.class);
|
|
||||||
|
|
||||||
return appManager.getApplicationTypeTitle(applicationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
public ApplicationType getApplicationType() {
|
|
||||||
return applicationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,252 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.event.ChangeEvent;
|
|
||||||
import com.arsdigita.bebop.event.ChangeListener;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
import com.arsdigita.ui.admin.applications.tree.LegacyApplicationTreeModelBuilder;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
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;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A tab for managing CcmApplication and application instances.
|
|
||||||
*
|
|
||||||
* @author pb
|
|
||||||
* @author Jens Pelzetter
|
|
||||||
*/
|
|
||||||
public class ApplicationsAdministrationTab extends LayoutPanel {
|
|
||||||
|
|
||||||
private final Tree applicationTree;
|
|
||||||
private final Map<String, LegacyBaseApplicationPane> appPanes
|
|
||||||
= new HashMap<>();
|
|
||||||
private final Map<String, LegacyApplicationInstancePane> instancePanes
|
|
||||||
= new HashMap<>();
|
|
||||||
private final BoxPanel appPanel;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*/
|
|
||||||
public ApplicationsAdministrationTab() {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
setClassAttr("sidebarNavPanel");
|
|
||||||
setAttribute("navbar-title", "Sitemap");
|
|
||||||
|
|
||||||
applicationTree = new Tree(new LegacyApplicationTreeModelBuilder());
|
|
||||||
applicationTree.addChangeListener(new TreeStateChangeListener());
|
|
||||||
|
|
||||||
setClassAttr("navbar");
|
|
||||||
|
|
||||||
setLeft(applicationTree);
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = cdiUtil.findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
|
|
||||||
final Collection<ApplicationType> applicationTypes = appManager.
|
|
||||||
getApplicationTypes().values();
|
|
||||||
|
|
||||||
final Map<String, ApplicationManager<?>> appManagers
|
|
||||||
= ApplicationManagers.
|
|
||||||
getInstance().
|
|
||||||
getApplicationManagers();
|
|
||||||
|
|
||||||
for (ApplicationType appType : applicationTypes) {
|
|
||||||
if (appType.singleton()) {
|
|
||||||
createSingletonAppPane(appType, appManagers);
|
|
||||||
} else {
|
|
||||||
createAppPane(appType, appManagers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
appPanel = new BoxPanel();
|
|
||||||
appPanel.setClassAttr("main");
|
|
||||||
for (Map.Entry<String, LegacyBaseApplicationPane> entry : appPanes.entrySet()) {
|
|
||||||
appPanel.add(entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
for (Map.Entry<String, LegacyApplicationInstancePane> entry : instancePanes.
|
|
||||||
entrySet()) {
|
|
||||||
appPanel.add(entry.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
//setRight(appPanel);
|
|
||||||
setBody(appPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createSingletonAppPane(final ApplicationType applicationType,
|
|
||||||
final Map<String, ApplicationManager<?>> appManagers) {
|
|
||||||
final String appObjectType = applicationType.name();
|
|
||||||
|
|
||||||
final ApplicationManager<?> manager = appManagers.get(appObjectType);
|
|
||||||
final LegacySingletonApplicationPane pane;
|
|
||||||
if (manager == null) {
|
|
||||||
pane = new LegacySingletonApplicationPane(applicationType, null);
|
|
||||||
} else {
|
|
||||||
pane = new LegacySingletonApplicationPane(
|
|
||||||
applicationType, appManagers.get(appObjectType).
|
|
||||||
getApplicationAdminForm());
|
|
||||||
}
|
|
||||||
appPanes.put(appObjectType, pane);
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
|
||||||
private void createAppPane(
|
|
||||||
final ApplicationType applicationType,
|
|
||||||
final Map<String, ApplicationManager<?>> appManagers) {
|
|
||||||
final ApplicationManager<?> appManager = appManagers.get(
|
|
||||||
applicationType.name());
|
|
||||||
final Form createForm;
|
|
||||||
if (appManager == null) {
|
|
||||||
createForm = null;
|
|
||||||
} else {
|
|
||||||
createForm = appManager.getApplicationCreateForm();
|
|
||||||
}
|
|
||||||
|
|
||||||
final LegacyMultiInstanceApplicationPane<?> appPane
|
|
||||||
= new LegacyMultiInstanceApplicationPane(
|
|
||||||
applicationType, createForm);
|
|
||||||
appPanes.put(applicationType.name(), appPane);
|
|
||||||
createInstancePane(applicationType, appManagers);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createInstancePane(
|
|
||||||
final ApplicationType applicationType,
|
|
||||||
final Map<String, ApplicationManager<?>> managementForms) {
|
|
||||||
final ApplicationManager<?> manager = managementForms.get(
|
|
||||||
applicationType.name());
|
|
||||||
final LegacyApplicationInstancePane instPane;
|
|
||||||
if (manager == null) {
|
|
||||||
instPane = new LegacyApplicationInstancePane(new Placeholder());
|
|
||||||
} else {
|
|
||||||
instPane = new LegacyApplicationInstancePane(managementForms.get(
|
|
||||||
applicationType.name()).
|
|
||||||
getApplicationAdminForm());
|
|
||||||
}
|
|
||||||
|
|
||||||
instancePanes.put(applicationType.name(), instPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
for (Map.Entry<String, LegacyBaseApplicationPane> entry : appPanes.entrySet()) {
|
|
||||||
page.setVisibleDefault(entry.getValue(), false);
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, LegacyApplicationInstancePane> entry : instancePanes.
|
|
||||||
entrySet()) {
|
|
||||||
page.setVisibleDefault(entry.getValue(), false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setPaneVisible(final SimpleContainer pane,
|
|
||||||
final PageState state) {
|
|
||||||
for (Map.Entry<String, LegacyBaseApplicationPane> entry : appPanes.entrySet()) {
|
|
||||||
entry.getValue().setVisible(state, false);
|
|
||||||
}
|
|
||||||
for (Map.Entry<String, LegacyApplicationInstancePane> entry : instancePanes.
|
|
||||||
entrySet()) {
|
|
||||||
entry.getValue().setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
pane.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class TreeStateChangeListener implements ChangeListener {
|
|
||||||
|
|
||||||
public TreeStateChangeListener() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void stateChanged(final ChangeEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
final String selectedKey = (String) applicationTree.getSelectedKey(
|
|
||||||
state);
|
|
||||||
if (selectedKey != null) {
|
|
||||||
if (selectedKey.contains(".")) {
|
|
||||||
// Selected key is a classname and therefore the key of an ApplicationPane
|
|
||||||
final LegacyBaseApplicationPane pane = appPanes.get(selectedKey);
|
|
||||||
if (pane != null) {
|
|
||||||
setPaneVisible(pane, state);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// Selected key is the name of a instance pane
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ApplicationRepository appRepo = cdiUtil.findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
|
|
||||||
final Optional<CcmApplication> application = appRepo
|
|
||||||
.retrieveApplicationForPath(selectedKey);
|
|
||||||
|
|
||||||
final LegacyApplicationInstancePane pane;
|
|
||||||
if (application.isPresent()) {
|
|
||||||
pane = instancePanes.get(application.getClass().
|
|
||||||
getName());
|
|
||||||
if (pane != null) {
|
|
||||||
pane.setApplication(application.get());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pane = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (pane != null) {
|
|
||||||
setPaneVisible(pane, state);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class Placeholder extends ApplicationInstanceAwareContainer {
|
|
||||||
|
|
||||||
public Placeholder() {
|
|
||||||
super();
|
|
||||||
final Label label = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.placeholder", ADMIN_BUNDLE));
|
|
||||||
add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,470 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
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.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
|
||||||
import java.lang.reflect.InvocationTargetException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class ApplicationsTab extends LayoutPanel {
|
|
||||||
|
|
||||||
private final StringParameter selectedAppTypeParam;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppType;
|
|
||||||
|
|
||||||
private final StringParameter selectedAppInstanceParam;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedAppInstance;
|
|
||||||
|
|
||||||
private final Tree applicationTree;
|
|
||||||
private final BoxPanel managementLinks;
|
|
||||||
private final Text placeholderInstances;
|
|
||||||
private final Text placeholderSingletonSettings;
|
|
||||||
private final BoxPanel appInfo;
|
|
||||||
|
|
||||||
private final Map<String, AbstractAppInstanceForm> instanceForms;
|
|
||||||
private final Map<String, AbstractAppSettingsPane> settingsPanes;
|
|
||||||
|
|
||||||
public ApplicationsTab() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
setClassAttr("sidebarNavPanel");
|
|
||||||
|
|
||||||
selectedAppTypeParam = new StringParameter("selectedAppType");
|
|
||||||
selectedAppType = new ParameterSingleSelectionModel<>(
|
|
||||||
selectedAppTypeParam);
|
|
||||||
|
|
||||||
selectedAppInstanceParam = new StringParameter("selectedAppInstance");
|
|
||||||
selectedAppInstance = new ParameterSingleSelectionModel<>(
|
|
||||||
selectedAppInstanceParam);
|
|
||||||
|
|
||||||
instanceForms = new HashMap<>();
|
|
||||||
settingsPanes = new HashMap<>();
|
|
||||||
|
|
||||||
applicationTree = new Tree(new ApplicationTreeModelBuilder());
|
|
||||||
applicationTree.addChangeListener(e -> {
|
|
||||||
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final String key = (String) applicationTree.getSelectedKey(state);
|
|
||||||
|
|
||||||
if (key.startsWith(
|
|
||||||
ApplicationInstanceTreeNode.INSTANCE_NODE_KEY_PREFIX)) {
|
|
||||||
|
|
||||||
//Instance is selected
|
|
||||||
final String instanceId = key.substring(
|
|
||||||
ApplicationInstanceTreeNode.INSTANCE_NODE_KEY_PREFIX
|
|
||||||
.length());
|
|
||||||
selectedAppInstance.setSelectedKey(state, instanceId);
|
|
||||||
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
final Optional<CcmApplication> application = appRepo.findById(
|
|
||||||
Long.parseLong(instanceId));
|
|
||||||
if (application.isPresent()) {
|
|
||||||
selectedAppType.setSelectedKey(
|
|
||||||
state, application.get().getApplicationType());
|
|
||||||
}
|
|
||||||
|
|
||||||
showAppSettings(state);
|
|
||||||
|
|
||||||
} else if (key.startsWith(
|
|
||||||
ApplicationTypeTreeNode.TYPE_NODE_KEY_PREFIX)) {
|
|
||||||
|
|
||||||
//ApplicationType node is selected
|
|
||||||
showManagementLinks(state);
|
|
||||||
final String appTypeKey = key.substring(
|
|
||||||
ApplicationTypeTreeNode.TYPE_NODE_KEY_PREFIX.length());
|
|
||||||
|
|
||||||
selectedAppType.setSelectedKey(state, appTypeKey);
|
|
||||||
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil
|
|
||||||
.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
final ApplicationType appType = appManager.getApplicationTypes()
|
|
||||||
.get(appTypeKey);
|
|
||||||
|
|
||||||
if (appType == null) {
|
|
||||||
hideAllInstanceForms(state);
|
|
||||||
hideAllSettingsPanes(state);
|
|
||||||
hideAppInfo(state);
|
|
||||||
hideInstances(state);
|
|
||||||
hideManagementLinks(state);
|
|
||||||
hideSingletonAppSettings(state);
|
|
||||||
} else if (appType.singleton()) {
|
|
||||||
showSingletonAppSettings(state);
|
|
||||||
} else {
|
|
||||||
showInstances(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The key of the selected must be Long or a String");
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setLeft(applicationTree);
|
|
||||||
|
|
||||||
final BoxPanel managementPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
managementLinks = new BoxPanel(BoxPanel.HORIZONTAL);
|
|
||||||
|
|
||||||
final ActionLink singletonAppSettingsLink
|
|
||||||
= new SingletonAppSettingsLink(
|
|
||||||
new GlobalizedMessage("ui.admin.applications.singleton.link",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
singletonAppSettingsLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
showSingletonAppSettings(state);
|
|
||||||
});
|
|
||||||
managementLinks.add(singletonAppSettingsLink);
|
|
||||||
|
|
||||||
final ActionLink instancesLink = new InstancesLink(
|
|
||||||
new GlobalizedMessage("ui.admin.applications.instances.link",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
instancesLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
showInstances(state);
|
|
||||||
});
|
|
||||||
managementLinks.add(instancesLink);
|
|
||||||
|
|
||||||
final ActionLink infoLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.info.link", ADMIN_BUNDLE));
|
|
||||||
infoLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
showAppInfo(state);
|
|
||||||
});
|
|
||||||
managementLinks.add(infoLink);
|
|
||||||
|
|
||||||
managementPanel.add(managementLinks);
|
|
||||||
|
|
||||||
placeholderInstances = new Text("placeholder instances");
|
|
||||||
managementPanel.add(placeholderInstances);
|
|
||||||
|
|
||||||
placeholderSingletonSettings
|
|
||||||
= new Text("placeholder singleton settings");
|
|
||||||
managementPanel.add(placeholderSingletonSettings);
|
|
||||||
|
|
||||||
appInfo = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final Label appInfoHeading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.info.heading", ADMIN_BUNDLE));
|
|
||||||
appInfoHeading.setClassAttr("heading");
|
|
||||||
appInfo.add(appInfoHeading);
|
|
||||||
|
|
||||||
final PropertySheet appInfoSheet = new PropertySheet(
|
|
||||||
new ApplicationTypePropertySheetModelBuilder(selectedAppType));
|
|
||||||
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(
|
|
||||||
String.format("%s_instance_form", appTypeName),
|
|
||||||
instanceFormClass);
|
|
||||||
managementPanel.add(instanceForm);
|
|
||||||
instanceForms.put(appTypeName, instanceForm);
|
|
||||||
final AbstractAppSettingsPane settingsPane = createSettingsPane(
|
|
||||||
settingsPaneClass);
|
|
||||||
managementPanel.add(settingsPane);
|
|
||||||
settingsPanes.put(appTypeName, settingsPane);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setBody(managementPanel);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(selectedAppTypeParam);
|
|
||||||
page.addGlobalStateParam(selectedAppInstanceParam);
|
|
||||||
|
|
||||||
page.setVisibleDefault(managementLinks, false);
|
|
||||||
page.setVisibleDefault(placeholderInstances, false);
|
|
||||||
page.setVisibleDefault(placeholderSingletonSettings, false);
|
|
||||||
page.setVisibleDefault(appInfo, false);
|
|
||||||
|
|
||||||
settingsPanes.forEach((k, v) -> {
|
|
||||||
page.setVisibleDefault(v, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
instanceForms.forEach((k, v) -> {
|
|
||||||
page.setVisibleDefault(v, false);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
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) {
|
|
||||||
|
|
||||||
hideAllInstanceForms(state);
|
|
||||||
hideAllSettingsPanes(state);
|
|
||||||
|
|
||||||
//placeholderInstances.setVisible(state, true);
|
|
||||||
final String appType = selectedAppType.getSelectedKey(state);
|
|
||||||
if (instanceForms.containsKey(appType)) {
|
|
||||||
instanceForms.get(appType).setVisible(state, true);
|
|
||||||
}
|
|
||||||
placeholderSingletonSettings.setVisible(state, false);
|
|
||||||
appInfo.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
final String appType = selectedAppType.getSelectedKey(state);
|
|
||||||
if (settingsPanes.containsKey(appType)) {
|
|
||||||
settingsPanes.get(appType).setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
appInfo.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showAppSettings(final PageState state) {
|
|
||||||
hideAllInstanceForms(state);
|
|
||||||
hideAllSettingsPanes(state);
|
|
||||||
hideManagementLinks(state);
|
|
||||||
placeholderInstances.setVisible(state, false);
|
|
||||||
placeholderSingletonSettings.setVisible(state, false);
|
|
||||||
|
|
||||||
if (settingsPanes.containsKey(selectedAppType.getSelectedKey(state))) {
|
|
||||||
settingsPanes.get(selectedAppType.getSelectedKey(state)).setVisible(
|
|
||||||
state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
// final String appId = selectedAppInstance.getSelectedKey(state);
|
|
||||||
// final ApplicationRepository appRepo = CdiUtil.createCdiUtil().findBean(
|
|
||||||
// ApplicationRepository.class);
|
|
||||||
// final CcmApplication application = appRepo.findById(Long
|
|
||||||
// .parseLong(appId));
|
|
||||||
// if (application != null) {
|
|
||||||
// final String appType = application.getApplicationType();
|
|
||||||
// if (settingsPanes.containsKey(appType)) {
|
|
||||||
// settingsPanes.get(appType).setVisible(state, true);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
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(
|
|
||||||
final String name,
|
|
||||||
final Class<? extends AbstractAppInstanceForm> instanceFormClass) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
final Constructor<? extends AbstractAppInstanceForm> constructor
|
|
||||||
= instanceFormClass
|
|
||||||
.getConstructor(String.class,
|
|
||||||
ParameterSingleSelectionModel.class,
|
|
||||||
ParameterSingleSelectionModel.class);
|
|
||||||
|
|
||||||
return constructor.newInstance(name,
|
|
||||||
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) {
|
|
||||||
super(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
if (selectedAppType.getSelectedKey(state) == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager
|
|
||||||
= CdiUtil
|
|
||||||
.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
final ApplicationType appType = appManager
|
|
||||||
.getApplicationTypes().get(selectedAppType
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
return appType.singleton();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InstancesLink extends ActionLink {
|
|
||||||
|
|
||||||
public InstancesLink(final GlobalizedMessage label) {
|
|
||||||
super(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
if (selectedAppType.getSelectedKey(state) == null) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
final org.libreccm.web.ApplicationManager appManager
|
|
||||||
= CdiUtil
|
|
||||||
.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
final ApplicationType appType = appManager
|
|
||||||
.getApplicationTypes().get(selectedAppType
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
return !appType.singleton();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,228 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.FormData;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.FormProcessListener;
|
|
||||||
import com.arsdigita.bebop.event.FormSectionEvent;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationCreateException;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.logging.Level;
|
|
||||||
import java.util.logging.Logger;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class DefaultApplicationInstanceForm extends AbstractAppInstanceForm {
|
|
||||||
|
|
||||||
private static final int COL_PRIMARY_URL = 0;
|
|
||||||
|
|
||||||
private SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public DefaultApplicationInstanceForm(
|
|
||||||
final String name,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppType,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedAppInstance) {
|
|
||||||
|
|
||||||
super(name, selectedAppType, selectedAppInstance);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void createWidgets() {
|
|
||||||
|
|
||||||
addInstanceTable();
|
|
||||||
|
|
||||||
final Label newInstanceFormHeading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.new_instance_form.title", ADMIN_BUNDLE));
|
|
||||||
newInstanceFormHeading.setClassAttr("heading");
|
|
||||||
add(newInstanceFormHeading);
|
|
||||||
|
|
||||||
final TextField primaryUrl = new TextField("new_instance_primary_url");
|
|
||||||
primaryUrl.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.new_instance.primary_url", ADMIN_BUNDLE));
|
|
||||||
primaryUrl.addValidationListener(new NotEmptyValidationListener(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.new_instance.primary_url.error.not_empty",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
add(primaryUrl);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
//add(new Text("placeholder"));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected SaveCancelSection getSaveCancelSection() {
|
|
||||||
return saveCancelSection;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void addInstanceTable() {
|
|
||||||
final Label tableHeading = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.instance_table.heading", ADMIN_BUNDLE));
|
|
||||||
tableHeading.setClassAttr("heading");
|
|
||||||
add(tableHeading);
|
|
||||||
|
|
||||||
final Table instanceTable = new Table();
|
|
||||||
final TableColumnModel colModel = instanceTable.getColumnModel();
|
|
||||||
colModel.add(new TableColumn(
|
|
||||||
COL_PRIMARY_URL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.instances_table.col_primary_url",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
instanceTable.setModelBuilder(new InstanceTableModelBuilder(this));
|
|
||||||
add(instanceTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
protected FormProcessListener createProcessListener() {
|
|
||||||
return (FormSectionEvent e) -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String primaryUrlData = data.getString(
|
|
||||||
"new_instance_primary_url");
|
|
||||||
|
|
||||||
final org.libreccm.web.ApplicationManager appManager = CdiUtil
|
|
||||||
.createCdiUtil().findBean(
|
|
||||||
org.libreccm.web.ApplicationManager.class);
|
|
||||||
try {
|
|
||||||
appManager.createInstance(
|
|
||||||
getSelectedAppType(state),
|
|
||||||
primaryUrlData,
|
|
||||||
(Class<CcmApplication>) getSelectedAppType(state)
|
|
||||||
.applicationClass());
|
|
||||||
} catch (ApplicationCreateException ex) {
|
|
||||||
throw new UncheckedWrapperException(
|
|
||||||
"Failed to create new application instance.", ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
final Class<?> clazz = getSelectedAppType(state)
|
|
||||||
.applicationClass();
|
|
||||||
if (!clazz.isAssignableFrom(CcmApplication.class)) {
|
|
||||||
throw new UncheckedWrapperException(String.format(
|
|
||||||
"Application class \"%s\" is not a sub class of "
|
|
||||||
+ "class \"%s\". Something is wrong...",
|
|
||||||
clazz.getName(), CcmApplication.class.getName()));
|
|
||||||
}
|
|
||||||
final CcmApplication application;
|
|
||||||
try {
|
|
||||||
application = (CcmApplication) clazz.newInstance();
|
|
||||||
} catch (InstantiationException | IllegalAccessException ex) {
|
|
||||||
throw new UncheckedWrapperException(
|
|
||||||
String.format("Failed to create object of "
|
|
||||||
+ "class \"%s\".",
|
|
||||||
clazz.getName()),
|
|
||||||
ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
application.setPrimaryUrl(primaryUrlData);
|
|
||||||
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
appRepo.save(application);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InstanceTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
private final AbstractAppInstanceForm instanceForm;
|
|
||||||
|
|
||||||
public InstanceTableModelBuilder(
|
|
||||||
final AbstractAppInstanceForm instanceForm) {
|
|
||||||
this.instanceForm = instanceForm;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
return new InstanceTableModel(instanceForm.getSelectedAppType(state));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class InstanceTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<CcmApplication> instances;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public InstanceTableModel(final ApplicationType appType) {
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
instances = appRepo.findByType(appType.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < instances.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_PRIMARY_URL:
|
|
||||||
return instances.get(index).getPrimaryUrl();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Illegal columnIndex");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return Long.toString(instances.get(index).getObjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,97 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @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);
|
|
||||||
|
|
||||||
final Label label = new Label();
|
|
||||||
label.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final ApplicationType appType = getSelectedAppType(state);
|
|
||||||
|
|
||||||
final GlobalizedMessage message;
|
|
||||||
if (appType.singleton()) {
|
|
||||||
message = new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.settings.singleton.no_setting_for",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{appType.name()});
|
|
||||||
} else {
|
|
||||||
message = new GlobalizedMessage(
|
|
||||||
"ui.admin.applications.settings.instance.no_setting_for",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{appType.name()});
|
|
||||||
}
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
target.setLabel(message);
|
|
||||||
});
|
|
||||||
|
|
||||||
add(label);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void createWidgets() {
|
|
||||||
|
|
||||||
// final Label label = new Label();
|
|
||||||
// label.addPrintListener(e -> {
|
|
||||||
// final PageState state = e.getPageState();
|
|
||||||
// final ApplicationType appType = getSelectedAppType(state);
|
|
||||||
//
|
|
||||||
// final GlobalizedMessage message;
|
|
||||||
// if (appType.singleton()) {
|
|
||||||
// message = new GlobalizedMessage(
|
|
||||||
// "ui.admin.applications.settings.singleton.no_setting_for",
|
|
||||||
// ADMIN_BUNDLE,
|
|
||||||
// new String[]{appType.name()});
|
|
||||||
// } else {
|
|
||||||
// message = new GlobalizedMessage(
|
|
||||||
// "ui.admin.applications.settings.instance.no_setting_for",
|
|
||||||
// ADMIN_BUNDLE,
|
|
||||||
// new String[]{appType.name()});
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// final Label target = (Label) e.getTarget();
|
|
||||||
// target.setLabel(message);
|
|
||||||
// });
|
|
||||||
//
|
|
||||||
// add(label);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,157 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A property sheet model for displaying informations about an
|
|
||||||
* {@link ApplicationType} using a {@link PropertySheet}.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationInfoPropertySheetModel.java 2220 2013-06-19
|
|
||||||
15:26:58Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInfoPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static final int APP_TITLE = 0;
|
|
||||||
private static final int APP_CLASS = 1;
|
|
||||||
private static final int APP_SINGLETON = 2;
|
|
||||||
private static final int APP_DESC = 3;
|
|
||||||
private static final int SINGLETON_PATH = 4;
|
|
||||||
private final ApplicationType applicationType;
|
|
||||||
private int currentIndex = -1;
|
|
||||||
|
|
||||||
public LegacyApplicationInfoPropertySheetModel(
|
|
||||||
final ApplicationType applicationType) {
|
|
||||||
this.applicationType = applicationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (applicationType.singleton() && currentIndex < SINGLETON_PATH) {
|
|
||||||
currentIndex++;
|
|
||||||
return true;
|
|
||||||
} else if (!applicationType.singleton() && currentIndex < APP_DESC) {
|
|
||||||
currentIndex++;
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
currentIndex = -1;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case APP_TITLE:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.title.label").
|
|
||||||
localize();
|
|
||||||
case APP_CLASS:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.app_class.label")
|
|
||||||
.localize();
|
|
||||||
case APP_SINGLETON:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton.label")
|
|
||||||
.localize();
|
|
||||||
case APP_DESC:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.desc.label").
|
|
||||||
localize();
|
|
||||||
case SINGLETON_PATH:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label")
|
|
||||||
.localize();
|
|
||||||
default:
|
|
||||||
return "unknown";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case APP_TITLE:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.title.label");
|
|
||||||
case APP_CLASS:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.app_class.label");
|
|
||||||
case APP_SINGLETON:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton.label");
|
|
||||||
case APP_DESC:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.desc.label");
|
|
||||||
case SINGLETON_PATH:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton_instance.path.label");
|
|
||||||
default:
|
|
||||||
return GlobalizationUtil.globalize("unknown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case APP_TITLE:
|
|
||||||
return applicationType.name();
|
|
||||||
case APP_CLASS:
|
|
||||||
return applicationType.name();
|
|
||||||
case APP_SINGLETON:
|
|
||||||
if (applicationType.singleton()) {
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton.yes")
|
|
||||||
.localize();
|
|
||||||
} else {
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.singleton.no")
|
|
||||||
.localize();
|
|
||||||
}
|
|
||||||
case APP_DESC:
|
|
||||||
return applicationType.descKey();
|
|
||||||
case SINGLETON_PATH:
|
|
||||||
final String path;
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
final List<CcmApplication> instances
|
|
||||||
= appRepo.findByType(
|
|
||||||
applicationType.name());
|
|
||||||
if (instances.isEmpty()) {
|
|
||||||
path = "";
|
|
||||||
} else {
|
|
||||||
path = instances.get(0).getPrimaryUrl();
|
|
||||||
}
|
|
||||||
|
|
||||||
return path;
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,51 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link PropertySheetModelBuilder} implementation for the the {@link LegacyApplicationInfoPropertySheetModel}.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationInfoPropertySheetModelBuilder.java 2219 2013-06-19 08:16:11Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInfoPropertySheetModelBuilder
|
|
||||||
extends LockableImpl implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ApplicationType applicationType;
|
|
||||||
|
|
||||||
public LegacyApplicationInfoPropertySheetModelBuilder(
|
|
||||||
final ApplicationType applicationType) {
|
|
||||||
super();
|
|
||||||
this.applicationType = applicationType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
return new LegacyApplicationInfoPropertySheetModel(applicationType);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,90 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.bebop.event.PrintEvent;
|
|
||||||
import com.arsdigita.bebop.event.PrintListener;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This pane shows informations about a specific instance of a multi instance application, like
|
|
||||||
* title, parent application (if any) and the path. Also it contains a form for editing settings
|
|
||||||
* specific to the instance.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInstancePane extends SegmentedPanel {
|
|
||||||
|
|
||||||
private CcmApplication application;
|
|
||||||
private final ApplicationInstanceAwareContainer appAdminPane;
|
|
||||||
private final LegacyApplicationInstancePropertySheetModelBuilder modelBuilder;
|
|
||||||
|
|
||||||
public LegacyApplicationInstancePane(
|
|
||||||
final ApplicationInstanceAwareContainer appAdminPane) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
this.appAdminPane = appAdminPane;
|
|
||||||
|
|
||||||
modelBuilder = new LegacyApplicationInstancePropertySheetModelBuilder();
|
|
||||||
final PropertySheet appInstInfoPanel = new PropertySheet(modelBuilder);
|
|
||||||
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInstancePane.info.heading")),
|
|
||||||
appInstInfoPanel);
|
|
||||||
|
|
||||||
if (appAdminPane == null) {
|
|
||||||
|
|
||||||
final Label noAdminPaneLabel = new Label();
|
|
||||||
noAdminPaneLabel.addPrintListener(new PrintListener() {
|
|
||||||
@Override
|
|
||||||
public void prepare(final PrintEvent event) {
|
|
||||||
final Label target = (Label) event.getTarget();
|
|
||||||
|
|
||||||
target.setLabel(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstancePane.manage.no_instance_admin_pane_found",
|
|
||||||
new String[]{application.getApplicationType()}));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstanceApplicationPane.manage.heading")),
|
|
||||||
noAdminPaneLabel);
|
|
||||||
} else {
|
|
||||||
//appAdminPane.setAppInstance(appInstance);
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInstancePane.manage.heading")),
|
|
||||||
appAdminPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplication(final CcmApplication application) {
|
|
||||||
this.application = application;
|
|
||||||
appAdminPane.setAppInstance(application);
|
|
||||||
modelBuilder.setApplication(application);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,111 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link PropertySheetModel} implementation for displaying informations about an instance of an application
|
|
||||||
* using a {@link PropertySheet}.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationInstancePropertySheetModel.java 2923 2014-10-27 18:55:26Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInstancePropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static final int INST_TITLE = 0;
|
|
||||||
private static final int INST_PARENT = 1;
|
|
||||||
private static final int INST_PATH = 2;
|
|
||||||
private static final int INST_DESC = 3;
|
|
||||||
private final CcmApplication application;
|
|
||||||
private int currentIndex = -1;
|
|
||||||
|
|
||||||
|
|
||||||
public LegacyApplicationInstancePropertySheetModel(final CcmApplication application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
currentIndex++;
|
|
||||||
return currentIndex <= INST_DESC;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case INST_TITLE:
|
|
||||||
return (String) GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.title.label").
|
|
||||||
localize();
|
|
||||||
case INST_PARENT:
|
|
||||||
return (String) GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInstancePane.parent_app.label").localize();
|
|
||||||
case INST_PATH:
|
|
||||||
return (String) GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.path.label").
|
|
||||||
localize();
|
|
||||||
case INST_DESC:
|
|
||||||
return (String) GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.desc.label").
|
|
||||||
localize();
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case INST_TITLE:
|
|
||||||
return GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.title.label");
|
|
||||||
case INST_PARENT:
|
|
||||||
return GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInstancePane.parent_app.label");
|
|
||||||
case INST_PATH:
|
|
||||||
return GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.path.label");
|
|
||||||
case INST_DESC:
|
|
||||||
return GlobalizationUtil.globalize("ui.admin.applications.ApplicationInstancePane.desc.label");
|
|
||||||
default:
|
|
||||||
return GlobalizationUtil.globalize("unknown");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentIndex) {
|
|
||||||
case INST_TITLE:
|
|
||||||
return application.getTitle().getValue();
|
|
||||||
case INST_PARENT:
|
|
||||||
if (application.getParent() == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return application.getParent().getTitle().getValue();
|
|
||||||
}
|
|
||||||
case INST_PATH:
|
|
||||||
return application.getPrimaryUrl();
|
|
||||||
case INST_DESC:
|
|
||||||
return application.getDescription().getValue();
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,52 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* {@link PropertySheetModelBuilder} implementation for the {@link LegacyApplicationInstancePropertySheetModel}.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationInstancePropertySheetModelBuilder.java 2293 2013-08-05 11:00:18Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInstancePropertySheetModelBuilder
|
|
||||||
extends LockableImpl implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private CcmApplication application;
|
|
||||||
|
|
||||||
public LegacyApplicationInstancePropertySheetModelBuilder() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet, final PageState state) {
|
|
||||||
return new LegacyApplicationInstancePropertySheetModel(application);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setApplication(final CcmApplication application) {
|
|
||||||
this.application = application;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,47 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Basic application pane containing the parts common for singleton and multi instance applications types. Shows
|
|
||||||
* informations about a specific application type.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LegacyBaseApplicationPane extends SegmentedPanel {
|
|
||||||
|
|
||||||
public LegacyBaseApplicationPane(final ApplicationType applicationType) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
final PropertySheet appInfoPanel = new PropertySheet(
|
|
||||||
new LegacyApplicationInfoPropertySheetModelBuilder(
|
|
||||||
applicationType));
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applications.ApplicationInfoSection.heading")),
|
|
||||||
appInfoPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,223 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pane for multi instance applications. Additional to the data provided by
|
|
||||||
* {@link LegacyBaseApplicationPane} it shows a table of all instances of the
|
|
||||||
* application type and a form for creating new instances of the application
|
|
||||||
* type.
|
|
||||||
*
|
|
||||||
* @param <T>
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LegacyMultiInstanceApplicationPane<T extends CcmApplication>
|
|
||||||
extends LegacyBaseApplicationPane {
|
|
||||||
|
|
||||||
private final static int COL_TITLE = 0;
|
|
||||||
private final static int COL_URL = 1;
|
|
||||||
private final static int COL_DESC = 2;
|
|
||||||
|
|
||||||
public LegacyMultiInstanceApplicationPane(final ApplicationType applicationType,
|
|
||||||
final Form createForm) {
|
|
||||||
super(applicationType);
|
|
||||||
|
|
||||||
//final ApplicationCollection applications = Application.retrieveAllApplications(applicationType.
|
|
||||||
// getApplicationObjectType());
|
|
||||||
//applications.rewind();
|
|
||||||
final Table table = new Table();
|
|
||||||
table.getColumnModel().add(
|
|
||||||
new TableColumn(COL_TITLE,
|
|
||||||
new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.applicationsMultiInstanceApplicationPane.instances.table.col_title.header"))));
|
|
||||||
table.getColumnModel().add(
|
|
||||||
new TableColumn(COL_URL,
|
|
||||||
new Label(GlobalizationUtil.
|
|
||||||
globalize(
|
|
||||||
"ui.admin.applicationsMultiInstanceApplicationPane.instances.table.col_url.header"))));
|
|
||||||
table.getColumnModel().add(
|
|
||||||
new TableColumn(COL_DESC,
|
|
||||||
new Label(GlobalizationUtil.
|
|
||||||
globalize(
|
|
||||||
"ui.admin.applicationsMultiInstanceApplicationPane.instances.table.col_desc.header"))));
|
|
||||||
|
|
||||||
//table.setModelBuilder(new ApplicationInstancesTableModelBuilder(applications));
|
|
||||||
table.setModelBuilder(new ApplicationInstancesTableModelBuilder(
|
|
||||||
applicationType.name()));
|
|
||||||
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstanceApplicationPane.instances")),
|
|
||||||
table);
|
|
||||||
|
|
||||||
if (createForm == null) {
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstanceApplicationPane.manage_instances.heading")),
|
|
||||||
new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstancePane.manage.no_create_form_found",
|
|
||||||
new String[]{applicationType.name()})));
|
|
||||||
} else {
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.MultiInstanceApplicationPane.create_instance")),
|
|
||||||
createForm);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ApplicationInstancesTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
//private final ApplicationCollection applications;
|
|
||||||
private final String appType;
|
|
||||||
|
|
||||||
//public ApplicationInstancesTableModelBuilder(final ApplicationCollection applications) {
|
|
||||||
// super();
|
|
||||||
//
|
|
||||||
// this.applications = applications;
|
|
||||||
//}
|
|
||||||
public ApplicationInstancesTableModelBuilder(final String appType) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
//this.applications = Application.retrieveAllApplications(appType);
|
|
||||||
this.appType = appType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
return new ApplicationInstancesTableModel(table, appType);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class ApplicationInstancesTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Table table;
|
|
||||||
//private final ApplicationCollection applications;
|
|
||||||
private final List<AppData> appData = new ArrayList<>();
|
|
||||||
private int currentIndex = -1;
|
|
||||||
|
|
||||||
//public ApplicationInstancesTableModel(final Table table, final ApplicationCollection applications) {
|
|
||||||
// this.table = table;
|
|
||||||
// this.applications = applications;
|
|
||||||
//}
|
|
||||||
public ApplicationInstancesTableModel(final Table table,
|
|
||||||
final String appType) {
|
|
||||||
this.table = table;
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
final List<CcmApplication> applications = appRepo.
|
|
||||||
findByType(appType);
|
|
||||||
for (CcmApplication application : applications) {
|
|
||||||
addAppData(application);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addAppData(final CcmApplication application) {
|
|
||||||
appData.add(new AppData(application.getTitle().getValue(),
|
|
||||||
application.getDescription().getValue(),
|
|
||||||
application.getPrimaryUrl()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return table.getColumnModel().size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
currentIndex++;
|
|
||||||
return currentIndex < appData.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_TITLE:
|
|
||||||
//return applications.getApplication().getTitle();
|
|
||||||
return appData.get(currentIndex).getTitle();
|
|
||||||
case COL_DESC:
|
|
||||||
//return applications.getApplication().getDescription();
|
|
||||||
return appData.get(currentIndex).getDescription();
|
|
||||||
case COL_URL:
|
|
||||||
//return applications.getApplication().getPath();
|
|
||||||
return appData.get(currentIndex).getPath();
|
|
||||||
default:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
//if (SessionManager.getSession().getTransactionContext().inTxn()) {
|
|
||||||
// SessionManager.getSession().getTransactionContext().commitTxn();
|
|
||||||
//}
|
|
||||||
//return applications.getApplication().getPath();
|
|
||||||
return appData.get(currentIndex).getPath();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppData {
|
|
||||||
|
|
||||||
private final String title;
|
|
||||||
private final String description;
|
|
||||||
private final String path;
|
|
||||||
|
|
||||||
public AppData() {
|
|
||||||
title = "";
|
|
||||||
description = "";
|
|
||||||
path = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
public AppData(final String title, final String description,
|
|
||||||
final String path) {
|
|
||||||
this.title = title;
|
|
||||||
this.description = description;
|
|
||||||
this.path = path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,50 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.SimpleContainer;
|
|
||||||
import com.arsdigita.ui.admin.GlobalizationUtil;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Pane for managing singleton applications. Shows a form to edit application specific settings.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id$
|
|
||||||
*/
|
|
||||||
public class LegacySingletonApplicationPane extends LegacyBaseApplicationPane {
|
|
||||||
|
|
||||||
public LegacySingletonApplicationPane(final ApplicationType applicationType, final SimpleContainer appAdminPane) {
|
|
||||||
super(applicationType);
|
|
||||||
|
|
||||||
if (appAdminPane == null) {
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.SingletonApplicationPane.manage.heading")),
|
|
||||||
new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.SingletonApplicationPane.manage.no_admin_pane_found",
|
|
||||||
new String[]{applicationType.name()})));
|
|
||||||
} else {
|
|
||||||
addSegment(new Label(GlobalizationUtil.globalize(
|
|
||||||
"ui.admin.SingletonApplicationPane.manage.heading")),
|
|
||||||
appAdminPane);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,96 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications.tree;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
import com.arsdigita.ui.admin.applications.ApplicationsAdministrationTab;
|
|
||||||
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tree Node for the application tree representing an instance of a application.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationInstanceTreeNode.java 2282 2013-08-01 10:45:42Z jensp $
|
|
||||||
*
|
|
||||||
* @see ApplicationTreeModel
|
|
||||||
* @see ApplicationTreeModelBuilder
|
|
||||||
* @see ApplicationTypeTreeNode
|
|
||||||
* @see ApplicationsAdministrationTab
|
|
||||||
* @see TreeNode
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationInstanceTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The application instance represented by this {@code TreeNode}
|
|
||||||
*/
|
|
||||||
//private final Application application;
|
|
||||||
private final String path;
|
|
||||||
private final String title;
|
|
||||||
private final String appType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor
|
|
||||||
*
|
|
||||||
* @param application The application instance to represent by this {@code TreeNode}
|
|
||||||
*/
|
|
||||||
public LegacyApplicationInstanceTreeNode(final CcmApplication application) {
|
|
||||||
//this.application = application;
|
|
||||||
path = application.getPrimaryUrl();
|
|
||||||
title = application.getTitle().getValue();
|
|
||||||
appType = application.getClass().getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPath() {
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getAppType() {
|
|
||||||
return appType;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the key for this {@link TreeNode}.
|
|
||||||
*
|
|
||||||
* @return The path of the application instance.
|
|
||||||
* @see TreeNode#getKey()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
//return application.getPath();
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Data to show in the tree for this node.
|
|
||||||
*
|
|
||||||
* @return The title of the application instance
|
|
||||||
* @see TreeNode#getElement()
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
//return application.getTitle();
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,196 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications.tree;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
import com.arsdigita.ui.admin.applications.ApplicationsAdministrationTab;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationManager;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A {@link TreeModel} for the tree of applications in
|
|
||||||
* {@link ApplicationsAdministrationTab}. The tree consists of two different
|
|
||||||
* types of nodes: Nodes for {@link ApplicationTypes} and nodes for
|
|
||||||
* {@link CCmApplication} instances.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationTreeModel.java 2406 2013-10-31 19:52:22Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationTreeModel implements TreeModel {
|
|
||||||
|
|
||||||
public LegacyApplicationTreeModel() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeNode getRoot(final PageState state) {
|
|
||||||
return new RootTreeNode();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasChildren(final TreeNode node, final PageState state) {
|
|
||||||
if (node instanceof RootTreeNode) {
|
|
||||||
return true;
|
|
||||||
} else if (node instanceof LegacyApplicationTypeTreeNode) {
|
|
||||||
final LegacyApplicationTypeTreeNode typeTreeNode
|
|
||||||
= (LegacyApplicationTypeTreeNode) node;
|
|
||||||
|
|
||||||
//if (typeTreeNode.getApplicationType().isSingleton()) {
|
|
||||||
if (typeTreeNode.isSingleton()) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
//return !retrieveApplicationInstances(typeTreeNode.getApplicationType()).isEmpty();
|
|
||||||
//return !retrieveApplicationInstances(typeTreeNode.getApplicationType()).isEmpty();
|
|
||||||
return !retrieveApplicationInstances(typeTreeNode.getObjecType())
|
|
||||||
.isEmpty();
|
|
||||||
}
|
|
||||||
} else if (node instanceof LegacyApplicationInstanceTreeNode) {
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and"
|
|
||||||
+ "ApplicationInstanceTreeNodes.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator getChildren(final TreeNode node, final PageState state) {
|
|
||||||
if (node instanceof RootTreeNode) {
|
|
||||||
final ApplicationManager appManager = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationManager.class);
|
|
||||||
|
|
||||||
final Collection<ApplicationType> appTypes = appManager
|
|
||||||
.getApplicationTypes().values();
|
|
||||||
|
|
||||||
return new AppTypesIterator(appTypes);
|
|
||||||
} else if (node instanceof LegacyApplicationTypeTreeNode) {
|
|
||||||
final LegacyApplicationTypeTreeNode typeTreeNode
|
|
||||||
= (LegacyApplicationTypeTreeNode) node;
|
|
||||||
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
|
|
||||||
final List<CcmApplication> applications = appRepo.findByType(
|
|
||||||
typeTreeNode.getObjecType());
|
|
||||||
|
|
||||||
return new AppIterator(applications);
|
|
||||||
} else if (node instanceof LegacyApplicationInstanceTreeNode) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"The ApplicationTreeModel can only work with ApplicationTypeTreeNodes and"
|
|
||||||
+ "ApplicationInstanceTreeNodes.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<CcmApplication> retrieveApplicationInstances(
|
|
||||||
final ApplicationType applicationType) {
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil().findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
|
|
||||||
return appRepo.findByType(applicationType.name());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<CcmApplication> retrieveApplicationInstances(
|
|
||||||
final String appObjectType) {
|
|
||||||
final ApplicationRepository appRepo = CdiUtil.createCdiUtil().findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
|
|
||||||
return appRepo.findByType(appObjectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class RootTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
public RootTreeNode() {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return "-1";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return "/";
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppTypesIterator implements Iterator<LegacyApplicationTypeTreeNode> {
|
|
||||||
|
|
||||||
private final Iterator<ApplicationType> appTypes;
|
|
||||||
|
|
||||||
public AppTypesIterator(final Collection<ApplicationType> appTypes) {
|
|
||||||
this.appTypes = appTypes.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return appTypes.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LegacyApplicationTypeTreeNode next() {
|
|
||||||
return new LegacyApplicationTypeTreeNode(appTypes.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class AppIterator implements Iterator<LegacyApplicationInstanceTreeNode> {
|
|
||||||
|
|
||||||
private final Iterator<CcmApplication> applications;
|
|
||||||
|
|
||||||
public AppIterator(final Collection<CcmApplication> applications) {
|
|
||||||
this.applications = applications.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return applications.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public LegacyApplicationInstanceTreeNode next() {
|
|
||||||
return new LegacyApplicationInstanceTreeNode(applications.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void remove() {
|
|
||||||
throw new UnsupportedOperationException("Not supported.");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications.tree;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
|
||||||
import com.arsdigita.ui.admin.applications.ApplicationsAdministrationTab;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The {@link TreeModelBuilder} creating the {@link TreeModel} for the
|
|
||||||
* applications tree used in {@link ApplicationsAdministrationTab}.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationTreeModelBuilder.java 2294 2013-08-05 18:39:46Z
|
|
||||||
jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationTreeModelBuilder extends LockableImpl
|
|
||||||
implements TreeModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeModel makeModel(final Tree tree, final PageState state) {
|
|
||||||
tree.expand("-1", state);
|
|
||||||
return new LegacyApplicationTreeModel();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,73 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013 Jens Pelzetter
|
|
||||||
*
|
|
||||||
* 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
package com.arsdigita.ui.admin.applications.tree;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
import java.math.BigDecimal;
|
|
||||||
import org.libreccm.web.ApplicationType;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tree Node implementation for the Application Tree in the Application admin tab.
|
|
||||||
*
|
|
||||||
* @author Jens Pelzetter <jens@jp-digital.de>
|
|
||||||
* @version $Id: LegacyApplicationTypeTreeNode.java 2282 2013-08-01 10:45:42Z jensp $
|
|
||||||
*/
|
|
||||||
public class LegacyApplicationTypeTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
private final String name;
|
|
||||||
private final String objectType;
|
|
||||||
private final boolean singleton;
|
|
||||||
private final String description;
|
|
||||||
// Needed:
|
|
||||||
// isSingleton
|
|
||||||
// getObjectType
|
|
||||||
|
|
||||||
public LegacyApplicationTypeTreeNode(final ApplicationType applicationType) {
|
|
||||||
//this.applicationType = applicationType;
|
|
||||||
name = applicationType.name();
|
|
||||||
objectType = applicationType.name();
|
|
||||||
singleton = applicationType.singleton();
|
|
||||||
description = applicationType.descKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getObjecType() {
|
|
||||||
return objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isSingleton() {
|
|
||||||
return singleton;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDescription() {
|
|
||||||
return description;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getKey() {
|
|
||||||
//return applicationType.getApplicationObjectType();
|
|
||||||
return objectType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Object getElement() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,86 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2017 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.categories;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Categorization;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
@RequestScoped
|
|
||||||
class CategoriesController {
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private CategoryRepository categoryRepo;
|
|
||||||
|
|
||||||
@Inject
|
|
||||||
private CategoryManager categoryManager;
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<Category> getSubCategories(final Category ofCategory) {
|
|
||||||
|
|
||||||
final Category category = categoryRepo
|
|
||||||
.findById(ofCategory.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Category with ID %d in the database.",
|
|
||||||
ofCategory.getObjectId())));
|
|
||||||
|
|
||||||
return new ArrayList<>(category.getSubCategories());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected boolean hasChildren(final Category category) {
|
|
||||||
|
|
||||||
final Category categoryToCheck = categoryRepo
|
|
||||||
.findById(category.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Category with ID %d in the database.",
|
|
||||||
category.getObjectId())));
|
|
||||||
|
|
||||||
return categoryManager.hasSubCategories(categoryToCheck);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected boolean isDeletable(final Category category) {
|
|
||||||
|
|
||||||
final Category categoryToCheck = categoryRepo
|
|
||||||
.findById(category.getObjectId())
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Category with ID %d in the database.",
|
|
||||||
category.getObjectId())));
|
|
||||||
|
|
||||||
final List<Category> subCats = categoryToCheck.getSubCategories();
|
|
||||||
final List<Categorization> objects = categoryToCheck.getObjects();
|
|
||||||
|
|
||||||
return (subCats == null || subCats.isEmpty())
|
|
||||||
&& (objects == null || objects.isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,552 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
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;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.parameters.StringParameter;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoriesTab extends LayoutPanel {
|
|
||||||
|
|
||||||
protected static final String DOMAINS_FILTER = "domainsFilter";
|
|
||||||
|
|
||||||
private final StringParameter domainIdParameter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
|
|
||||||
private final StringParameter categoryIdParameter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
private final StringParameter languageParameter;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
|
|
||||||
private final Label domainsFilterFormHeader;
|
|
||||||
private final Form domainsFilterForm;
|
|
||||||
private final BoxPanel domainsTablePanel;
|
|
||||||
|
|
||||||
private final DomainForm domainForm;
|
|
||||||
|
|
||||||
private final DomainDetails domainDetails;
|
|
||||||
private final DomainTitleForm domainTitleForm;
|
|
||||||
private final DomainDescriptionForm domainDescriptionForm;
|
|
||||||
|
|
||||||
private final Label categoriesTreeHeader;
|
|
||||||
private final BoxPanel categoriesTreePanel;
|
|
||||||
|
|
||||||
private final CategoryDetails categoryDetails;
|
|
||||||
private final CategoryTitleForm categoryTitleForm;
|
|
||||||
private final CategoryDescriptionForm categoryDescriptionForm;
|
|
||||||
private final CategoryCreateForm categoryCreateForm;
|
|
||||||
private final CategoryEditForm categoryEditForm;
|
|
||||||
private final CategoryMover categoryMover;
|
|
||||||
|
|
||||||
public CategoriesTab() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
setClassAttr("sidebarNavPanel");
|
|
||||||
|
|
||||||
domainIdParameter = new StringParameter("selected_domain_id");
|
|
||||||
selectedDomainId = new ParameterSingleSelectionModel<>(
|
|
||||||
domainIdParameter);
|
|
||||||
|
|
||||||
categoryIdParameter = new StringParameter("selected_category_id");
|
|
||||||
selectedCategoryId = new ParameterSingleSelectionModel<>(
|
|
||||||
categoryIdParameter);
|
|
||||||
|
|
||||||
languageParameter = new StringParameter("selected_language");
|
|
||||||
selectedLanguage = new ParameterSingleSelectionModel<>(
|
|
||||||
languageParameter);
|
|
||||||
|
|
||||||
final SegmentedPanel left = new SegmentedPanel();
|
|
||||||
|
|
||||||
domainsFilterFormHeader = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.table.filter.header",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
domainsFilterForm = new Form("domainFilterForm");
|
|
||||||
final TextField domainsFilter = new TextField(DOMAINS_FILTER);
|
|
||||||
domainsFilterForm.add(domainsFilter);
|
|
||||||
domainsFilterForm.add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.table.filter", ADMIN_BUNDLE)));
|
|
||||||
final ActionLink clearLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.table.filter.clear",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
clearLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
domainsFilter.setValue(state, null);
|
|
||||||
});
|
|
||||||
domainsFilterForm.add(clearLink);
|
|
||||||
left.addSegment(domainsFilterFormHeader, domainsFilterForm);
|
|
||||||
|
|
||||||
categoriesTreeHeader = new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.tree.header",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
categoriesTreePanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
final Tree categoriesTree = new Tree(new CategoriesTreeModelBuilder(
|
|
||||||
selectedDomainId));
|
|
||||||
categoriesTree.addChangeListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
selectedCategoryId.setSelectedKey(
|
|
||||||
state, (String) categoriesTree.getSelectedKey(state));
|
|
||||||
|
|
||||||
showCategoryDetails(state);
|
|
||||||
});
|
|
||||||
selectedCategoryId.addChangeListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
categoriesTree.setSelectedKey(state, selectedCategoryId
|
|
||||||
.getSelectedKey(state));
|
|
||||||
});
|
|
||||||
|
|
||||||
final ActionLink backToDomain = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.tree.back",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
backToDomain.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTree.getSelectionModel().clearSelection(state);
|
|
||||||
showDomainDetails(state);
|
|
||||||
});
|
|
||||||
categoriesTreePanel.add(backToDomain);
|
|
||||||
categoriesTreePanel.add(categoriesTree);
|
|
||||||
left.addSegment(categoriesTreeHeader, categoriesTreePanel);
|
|
||||||
|
|
||||||
setLeft(left);
|
|
||||||
|
|
||||||
final BoxPanel body = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
|
|
||||||
final DomainsTable domainsTable = new DomainsTable(
|
|
||||||
this, selectedDomainId, domainsFilter);
|
|
||||||
domainsTable.setStyleAttr("min-width: 30em;");
|
|
||||||
domainsTablePanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
domainsTablePanel.add(domainsTable);
|
|
||||||
final ActionLink addDomain = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.create_new", ADMIN_BUNDLE));
|
|
||||||
addDomain.addActionListener(e -> {
|
|
||||||
showDomainForm(e.getPageState());
|
|
||||||
});
|
|
||||||
domainsTablePanel.add(addDomain);
|
|
||||||
|
|
||||||
body.add(domainsTablePanel);
|
|
||||||
|
|
||||||
domainForm = new DomainForm(this, selectedDomainId);
|
|
||||||
body.add(domainForm);
|
|
||||||
|
|
||||||
domainDetails = new DomainDetails(this,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(domainDetails);
|
|
||||||
|
|
||||||
domainTitleForm = new DomainTitleForm(this,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(domainTitleForm);
|
|
||||||
|
|
||||||
domainDescriptionForm = new DomainDescriptionForm(this,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(domainDescriptionForm);
|
|
||||||
|
|
||||||
categoryDetails = new CategoryDetails(this,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedCategoryId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(categoryDetails);
|
|
||||||
|
|
||||||
categoryTitleForm = new CategoryTitleForm(this,
|
|
||||||
selectedCategoryId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(categoryTitleForm);
|
|
||||||
|
|
||||||
categoryDescriptionForm = new CategoryDescriptionForm(this,
|
|
||||||
selectedCategoryId,
|
|
||||||
selectedLanguage);
|
|
||||||
body.add(categoryDescriptionForm);
|
|
||||||
|
|
||||||
categoryCreateForm = new CategoryCreateForm(this, selectedCategoryId);
|
|
||||||
body.add(categoryCreateForm);
|
|
||||||
|
|
||||||
categoryEditForm = new CategoryEditForm(this, selectedCategoryId);
|
|
||||||
body.add(categoryEditForm);
|
|
||||||
|
|
||||||
categoryMover = new CategoryMover(this,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedCategoryId);
|
|
||||||
body.add(categoryMover);
|
|
||||||
|
|
||||||
setBody(body);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(domainIdParameter);
|
|
||||||
page.addGlobalStateParam(categoryIdParameter);
|
|
||||||
page.addGlobalStateParam(languageParameter);
|
|
||||||
|
|
||||||
page.setVisibleDefault(domainsFilterFormHeader, true);
|
|
||||||
page.setVisibleDefault(domainsFilterForm, true);
|
|
||||||
page.setVisibleDefault(domainsTablePanel, true);
|
|
||||||
page.setVisibleDefault(domainForm, false);
|
|
||||||
page.setVisibleDefault(domainDetails, false);
|
|
||||||
page.setVisibleDefault(domainTitleForm, false);
|
|
||||||
page.setVisibleDefault(domainDescriptionForm, false);
|
|
||||||
|
|
||||||
page.setVisibleDefault(categoriesTreeHeader, false);
|
|
||||||
page.setVisibleDefault(categoriesTreePanel, false);
|
|
||||||
|
|
||||||
page.setVisibleDefault(categoryDetails, false);
|
|
||||||
page.setVisibleDefault(categoryTitleForm, false);
|
|
||||||
page.setVisibleDefault(categoryDescriptionForm, false);
|
|
||||||
page.setVisibleDefault(categoryCreateForm, false);
|
|
||||||
page.setVisibleDefault(categoryEditForm, false);
|
|
||||||
page.setVisibleDefault(categoryMover, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDomainsTable(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, true);
|
|
||||||
domainsFilterForm.setVisible(state, true);
|
|
||||||
domainsTablePanel.setVisible(state, true);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDomainForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, true);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideDomainForm(final PageState state) {
|
|
||||||
if (selectedDomainId.getSelectedKey(state) == null) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, true);
|
|
||||||
domainsFilterForm.setVisible(state, true);
|
|
||||||
domainsTablePanel.setVisible(state, true);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
} else {
|
|
||||||
showDomainDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDomainDetails(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, true);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, true);
|
|
||||||
categoriesTreePanel.setVisible(state, true);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideDomainDetails(final PageState state) {
|
|
||||||
selectedDomainId.clearSelection(state);
|
|
||||||
|
|
||||||
domainsFilterFormHeader.setVisible(state, true);
|
|
||||||
domainsFilterForm.setVisible(state, true);
|
|
||||||
domainsTablePanel.setVisible(state, true);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDomainTitleForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, true);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideDomainTitleForm(final PageState state) {
|
|
||||||
selectedLanguage.clearSelection(state);
|
|
||||||
|
|
||||||
showDomainDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showDomainDescriptionForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, true);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideDomainDescriptionForm(final PageState state) {
|
|
||||||
selectedLanguage.clearSelection(state);
|
|
||||||
|
|
||||||
showDomainDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryDetails(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, true);
|
|
||||||
categoriesTreePanel.setVisible(state, true);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, true);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryDetails(final PageState state) {
|
|
||||||
selectedCategoryId.clearSelection(state);
|
|
||||||
|
|
||||||
showDomainDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryCreateForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, true);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryCreateForm(final PageState state) {
|
|
||||||
//Show category details of new category (or the selected category if
|
|
||||||
//creation was canceled
|
|
||||||
showCategoryDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryEditForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, true);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryEditForm(final PageState state) {
|
|
||||||
//We want to go back to the details of the selected category, therefore
|
|
||||||
//we don't reset the selection.
|
|
||||||
showCategoryDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryTitleForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, true);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryTitleForm(final PageState state) {
|
|
||||||
selectedLanguage.clearSelection(state);
|
|
||||||
|
|
||||||
showCategoryDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryDescriptionForm(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, true);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryDescriptionForm(final PageState state) {
|
|
||||||
selectedLanguage.clearSelection(state);
|
|
||||||
|
|
||||||
showCategoryDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showCategoryMover(final PageState state) {
|
|
||||||
domainsFilterFormHeader.setVisible(state, false);
|
|
||||||
domainsFilterForm.setVisible(state, false);
|
|
||||||
domainsTablePanel.setVisible(state, false);
|
|
||||||
domainForm.setVisible(state, false);
|
|
||||||
domainDetails.setVisible(state, false);
|
|
||||||
domainTitleForm.setVisible(state, false);
|
|
||||||
domainDescriptionForm.setVisible(state, false);
|
|
||||||
|
|
||||||
categoriesTreeHeader.setVisible(state, false);
|
|
||||||
categoriesTreePanel.setVisible(state, false);
|
|
||||||
|
|
||||||
categoryDetails.setVisible(state, false);
|
|
||||||
categoryTitleForm.setVisible(state, false);
|
|
||||||
categoryDescriptionForm.setVisible(state, false);
|
|
||||||
categoryCreateForm.setVisible(state, false);
|
|
||||||
categoryEditForm.setVisible(state, false);
|
|
||||||
categoryMover.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideCategoryMover(final PageState state) {
|
|
||||||
showCategoryDetails(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,135 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A reusable implementation of {@link TreeModel} for creating category trees.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoriesTreeModel implements TreeModel {
|
|
||||||
|
|
||||||
private final Tree tree;
|
|
||||||
private final Domain domain;
|
|
||||||
|
|
||||||
public CategoriesTreeModel(final Tree tree, final Domain domain) {
|
|
||||||
this.tree = tree;
|
|
||||||
this.domain = domain;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeNode getRoot(final PageState state) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(domain.getRoot()
|
|
||||||
.getObjectId()).get();
|
|
||||||
|
|
||||||
tree.expand(Long.toString(category.getObjectId()), state);
|
|
||||||
|
|
||||||
return new CategoryTreeNode(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasChildren(final TreeNode node,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
final CategoriesController controller = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(CategoriesController.class);
|
|
||||||
return controller.hasChildren(((CategoryTreeNode) node).getCategory());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator getChildren(final TreeNode node,
|
|
||||||
final PageState state) {
|
|
||||||
|
|
||||||
if (node.getKey().equals(getRoot(state).getKey())
|
|
||||||
&& tree.isCollapsed(node.getKey().toString(), state)) {
|
|
||||||
|
|
||||||
tree.expand(node.getKey().toString(), state);
|
|
||||||
}
|
|
||||||
|
|
||||||
final CategoriesController controller = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(CategoriesController.class);
|
|
||||||
final List<Category> subCategories = controller
|
|
||||||
.getSubCategories(((CategoryTreeNode) node).getCategory());
|
|
||||||
|
|
||||||
return new SubCategoryNodesIterator(subCategories);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryTreeNode implements TreeNode {
|
|
||||||
|
|
||||||
private final Category category;
|
|
||||||
|
|
||||||
public CategoryTreeNode(final Category category) {
|
|
||||||
this.category = category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Category getCategory() {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return Long.toString(category.getObjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return category.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SubCategoryNodesIterator
|
|
||||||
implements Iterator<CategoryTreeNode> {
|
|
||||||
|
|
||||||
private final Iterator<Category> subCategoriesIterator;
|
|
||||||
|
|
||||||
public SubCategoryNodesIterator(final List<Category> subCategories) {
|
|
||||||
subCategoriesIterator = subCategories.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return subCategoriesIterator.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CategoryTreeNode next() {
|
|
||||||
return new CategoryTreeNode(subCategoriesIterator.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class CategoriesTreeModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TreeModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
|
|
||||||
public CategoriesTreeModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
|
||||||
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeModel makeModel(final Tree tree,
|
|
||||||
final PageState state) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil().
|
|
||||||
findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
return new CategoriesTreeModel(tree, domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,132 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryCreateForm extends Form {
|
|
||||||
|
|
||||||
private static final String CATEGORY_NAME = "categoryName";
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
private final TextField categoryName;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public CategoryCreateForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
super("categoryCreateForm");
|
|
||||||
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(Long
|
|
||||||
.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.create_new_subcategory",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{category.getName()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
categoryName = new TextField(CATEGORY_NAME);
|
|
||||||
categoryName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.label", ADMIN_BUNDLE));
|
|
||||||
add(categoryName);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String categoryNameData = data.getString(CATEGORY_NAME);
|
|
||||||
|
|
||||||
if (Strings.isBlank(categoryNameData)) {
|
|
||||||
data.addError(
|
|
||||||
CATEGORY_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.errors.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final CategoryManager categoryManager = cdiUtil.findBean(
|
|
||||||
CategoryManager.class);
|
|
||||||
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String categoryNameData = data.getString(CATEGORY_NAME);
|
|
||||||
|
|
||||||
final Category category = new Category();
|
|
||||||
category.setName(categoryNameData);
|
|
||||||
|
|
||||||
categoryRepository.save(category);
|
|
||||||
categoryManager.addSubCategoryToCategory(category,
|
|
||||||
selectedCategory);
|
|
||||||
|
|
||||||
selectedCategoryId.setSelectedKey(
|
|
||||||
state, Long.toString(category.getObjectId()));
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideCategoryCreateForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,175 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryDescriptionForm extends Form {
|
|
||||||
|
|
||||||
private static final String LOCALIZED_CATEGORY_DESC = "description";
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
|
|
||||||
private final TextArea description;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public CategoryDescriptionForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super("categoryDescriptionForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.description.edit.back",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
categoriesTab.hideDomainTitleForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
if (selectedCategory.getDescription().hasValue(selectedLocale)) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.description.edit_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedCategory.getName(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.description.add_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedCategory.getName(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
description = new TextArea(LOCALIZED_CATEGORY_DESC);
|
|
||||||
description.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.description.label", ADMIN_BUNDLE));
|
|
||||||
description.setCols(60);
|
|
||||||
description.setRows(10);
|
|
||||||
add(description);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
if (selectedCategory.getDescription().hasValue(selectedLocale)) {
|
|
||||||
description.setValue(state, selectedCategory.getDescription()
|
|
||||||
.getValue(selectedLocale));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(
|
|
||||||
e.getPageState())) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String titleData = data.getString(LOCALIZED_CATEGORY_DESC);
|
|
||||||
|
|
||||||
if (Strings.isBlank(titleData)) {
|
|
||||||
data.addError(
|
|
||||||
LOCALIZED_CATEGORY_DESC,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.description.error.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final String titleData = e.getFormData().getString(
|
|
||||||
LOCALIZED_CATEGORY_DESC);
|
|
||||||
|
|
||||||
selectedCategory.getDescription().putValue(selectedLocale,
|
|
||||||
titleData);
|
|
||||||
categoryRepository.save(selectedCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideCategoryDescriptionForm(state);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,256 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryDescriptionTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_LOCALE = 0;
|
|
||||||
private static final int COL_VALUE = 1;
|
|
||||||
private static final int COL_EDIT = 2;
|
|
||||||
private static final int COL_DEL = 3;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
|
|
||||||
public CategoryDescriptionTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
setIdAttr("categoryDescriptionTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.none",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_LOCALE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.col_lang",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_VALUE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.col_value",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.col_edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.col_del",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description"
|
|
||||||
+ ".del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_EDIT:
|
|
||||||
selectedLanguage.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showCategoryDescriptionForm(state);
|
|
||||||
break;
|
|
||||||
case COL_DEL:
|
|
||||||
final Locale locale = new Locale((String) event
|
|
||||||
.getRowKey());
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.
|
|
||||||
getSelectedKey(state))).get();
|
|
||||||
category.getDescription().removeValue(locale);
|
|
||||||
|
|
||||||
categoryRepository.save(category);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new CategoryDescriptionTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryDescriptionTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new CategoryDescriptionTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryDescriptionTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Category selectedCategory;
|
|
||||||
private final List<Locale> locales;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public CategoryDescriptionTableModel(final PageState state) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
selectedCategory = categoryRepository.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
locales = new ArrayList<>();
|
|
||||||
if (selectedCategory.getDescription() != null) {
|
|
||||||
locales.addAll(
|
|
||||||
selectedCategory.getDescription().getAvailableLocales());
|
|
||||||
}
|
|
||||||
locales.sort((l1, l2) -> {
|
|
||||||
return l1.toString().compareTo(l2.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < locales.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Locale locale = locales.get(index);
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LOCALE:
|
|
||||||
return locale.toString();
|
|
||||||
case COL_VALUE:
|
|
||||||
return selectedCategory.getDescription().getValue(locale);
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_DEL:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description.del",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return locales.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,359 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class CategoryDetails extends SegmentedPanel {
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
private final CategoryTitleAddForm categoryTitleAddForm;
|
|
||||||
private final CategoryDescriptionAddForm categoryDescriptionAddForm;
|
|
||||||
private final SubCategoriesTable subCategoriesTable;
|
|
||||||
|
|
||||||
public CategoryDetails(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.back", ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTab.hideCategoryDetails(state);
|
|
||||||
});
|
|
||||||
addSegment("category-details-back", backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{category.getName()}));
|
|
||||||
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final BoxPanel propertiesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
propertiesPanel.add(new PropertySheet(
|
|
||||||
new CategoryPropertySheetModelBuilder(selectedCategoryId)));
|
|
||||||
final ActionLink editBasicPropertiesLink = new ActionLink(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.basic_properties.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
editBasicPropertiesLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTab.showCategoryEditForm(state);
|
|
||||||
});
|
|
||||||
propertiesPanel.add(editBasicPropertiesLink);
|
|
||||||
final ActionLink moveLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.move_category", ADMIN_BUNDLE)) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
final CategoryRepository categoryRepo = CdiUtil
|
|
||||||
.createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(Long
|
|
||||||
.parseLong(selectedCategoryId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
//If the category has no parent category it is the root
|
|
||||||
//category of a domain and can't be moved
|
|
||||||
return category.getParentCategory() != null;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
};
|
|
||||||
moveLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTab.showCategoryMover(state);
|
|
||||||
});
|
|
||||||
propertiesPanel.add(moveLink);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.basic_properties",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
propertiesPanel
|
|
||||||
);
|
|
||||||
|
|
||||||
final BoxPanel titlesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
titlesPanel.add(new CategoryTitleTable(categoriesTab,
|
|
||||||
selectedCategoryId,
|
|
||||||
selectedLanguage));
|
|
||||||
categoryTitleAddForm = new CategoryTitleAddForm();
|
|
||||||
titlesPanel.add(categoryTitleAddForm);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.category_title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
titlesPanel);
|
|
||||||
|
|
||||||
final BoxPanel descPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
descPanel.add(new CategoryDescriptionTable(categoriesTab,
|
|
||||||
selectedCategoryId,
|
|
||||||
selectedLanguage));
|
|
||||||
categoryDescriptionAddForm = new CategoryDescriptionAddForm();
|
|
||||||
descPanel.add(categoryDescriptionAddForm);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.description",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
descPanel);
|
|
||||||
|
|
||||||
final BoxPanel subCategoriesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
subCategoriesTable = new SubCategoriesTable(categoriesTab,
|
|
||||||
selectedCategoryId);
|
|
||||||
subCategoriesPanel.add(subCategoriesTable);
|
|
||||||
final ActionLink addSubCategory = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.subcategories.add",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
addSubCategory.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
categoriesTab.showCategoryCreateForm(state);
|
|
||||||
});
|
|
||||||
subCategoriesPanel.add(addSubCategory);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.subcategories.header",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
subCategoriesPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryTitleAddForm extends Form {
|
|
||||||
|
|
||||||
private static final String TITLE_SELECT_LANG = "titleSelectLang";
|
|
||||||
|
|
||||||
public CategoryTitleAddForm() {
|
|
||||||
super("categoryTitleAddForm", new BoxPanel(BoxPanel.HORIZONTAL));
|
|
||||||
|
|
||||||
final SingleSelect titleSelectLang = new SingleSelect(
|
|
||||||
TITLE_SELECT_LANG);
|
|
||||||
titleSelectLang.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.category_title.add.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
try {
|
|
||||||
titleSelectLang.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig.
|
|
||||||
getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
category.getTitle().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
final SingleSelect target = (SingleSelect) e.getTarget();
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
supportedLanguages.forEach(l -> {
|
|
||||||
if (!assignedLanguages.contains(l)) {
|
|
||||||
target.addOption(new Option(l, new Text(l)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(titleSelectLang);
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.category_title.add.submit",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String language = data.getString(TITLE_SELECT_LANG);
|
|
||||||
selectedLanguage.setSelectedKey(state, language);
|
|
||||||
|
|
||||||
categoriesTab.showCategoryTitleForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig.
|
|
||||||
getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
category.getTitle().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
//If all supported languages are assigned the form is not
|
|
||||||
//visible
|
|
||||||
return !assignedLanguages.equals(supportedLanguages);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryDescriptionAddForm extends Form {
|
|
||||||
|
|
||||||
private static final String DESC_SELECT_LANG = "descSelectLang";
|
|
||||||
|
|
||||||
public CategoryDescriptionAddForm() {
|
|
||||||
super("categoryAddDescLang", new BoxPanel(BoxPanel.HORIZONTAL));
|
|
||||||
|
|
||||||
final SingleSelect descSelectLang = new SingleSelect(
|
|
||||||
DESC_SELECT_LANG);
|
|
||||||
descSelectLang.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.category_desc.add.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
try {
|
|
||||||
descSelectLang.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig.
|
|
||||||
getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
category.getDescription().getAvailableLocales().forEach(
|
|
||||||
l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
final SingleSelect target = (SingleSelect) e.getTarget();
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
supportedLanguages.forEach(l -> {
|
|
||||||
if (!assignedLanguages.contains(l)) {
|
|
||||||
target.addOption(new Option(l, new Text(l)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(descSelectLang);
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.category_desc.add.submit",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String language = data.getString(DESC_SELECT_LANG);
|
|
||||||
selectedLanguage.setSelectedKey(state, language);
|
|
||||||
|
|
||||||
categoriesTab.showCategoryDescriptionForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig.
|
|
||||||
getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
category.getDescription().getAvailableLocales().forEach(
|
|
||||||
l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
//If all supported languages are assigned the form is not
|
|
||||||
//visible
|
|
||||||
return !assignedLanguages.equals(supportedLanguages);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,186 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.CheckboxGroup;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryEditForm extends Form {
|
|
||||||
|
|
||||||
private static final String CATEGORY_NAME = "categoryName";
|
|
||||||
private static final String CATEGORY_PROPERTIES = "categoryProperties";
|
|
||||||
|
|
||||||
private static final String ENABLED = "enabled";
|
|
||||||
private static final String VISIBLE = "visible";
|
|
||||||
private static final String ABSTRACT = "abstract";
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
private final TextField categoryName;
|
|
||||||
private final CheckboxGroup properties;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public CategoryEditForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
super("categoryEditForm");
|
|
||||||
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(Long
|
|
||||||
.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.edit_category",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{category.getName()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
categoryName = new TextField(CATEGORY_NAME);
|
|
||||||
categoryName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.label", ADMIN_BUNDLE));
|
|
||||||
add(categoryName);
|
|
||||||
|
|
||||||
properties = new CheckboxGroup(CATEGORY_PROPERTIES);
|
|
||||||
properties.addOption(new Option(
|
|
||||||
ENABLED,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.enabled",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
properties.addOption(new Option(
|
|
||||||
VISIBLE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.visible",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
properties.addOption(new Option(
|
|
||||||
ABSTRACT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.abstract",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
add(properties);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(Long
|
|
||||||
.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
categoryName.setValue(state, category.getName());
|
|
||||||
final List<String> props = new ArrayList<>();
|
|
||||||
if (category.isEnabled()) {
|
|
||||||
props.add(ENABLED);
|
|
||||||
}
|
|
||||||
if (category.isVisible()) {
|
|
||||||
props.add(VISIBLE);
|
|
||||||
}
|
|
||||||
if (category.isAbstractCategory()) {
|
|
||||||
props.add(ABSTRACT);
|
|
||||||
}
|
|
||||||
properties.setValue(state, props.toArray(new String[props.size()]));
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String categoryNameData = data.getString(CATEGORY_NAME);
|
|
||||||
|
|
||||||
if (Strings.isBlank(categoryNameData)) {
|
|
||||||
data.addError(
|
|
||||||
CATEGORY_NAME,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.name.errors.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final CategoryManager categoryManager = cdiUtil.findBean(
|
|
||||||
CategoryManager.class);
|
|
||||||
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String categoryNameData = data.getString(CATEGORY_NAME);
|
|
||||||
|
|
||||||
category.setName(categoryNameData);
|
|
||||||
|
|
||||||
final List<String> propertiesData = Arrays.asList(
|
|
||||||
(String[]) data.get(
|
|
||||||
CATEGORY_PROPERTIES));
|
|
||||||
category.setEnabled(propertiesData.contains(ENABLED));
|
|
||||||
category.setVisible(propertiesData.contains(VISIBLE));
|
|
||||||
category.setAbstractCategory(propertiesData.contains(ABSTRACT));
|
|
||||||
|
|
||||||
categoryRepository.save(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideCategoryEditForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,110 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryMover extends Form {
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
private final Tree categoryTree;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public CategoryMover(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
super("categoryMover", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepo = CdiUtil
|
|
||||||
.createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.move.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{category.getName()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
categoryTree = new Tree(new CategoryMoverModelBuilder(
|
|
||||||
selectedDomainId, selectedCategoryId));
|
|
||||||
add(categoryTree);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepo = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final CategoryManager categoryManager = cdiUtil.findBean(
|
|
||||||
CategoryManager.class);
|
|
||||||
|
|
||||||
final Category category = categoryRepo.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
final Category parent = category.getParentCategory();
|
|
||||||
final Category target = categoryRepo.findById(Long.parseLong(
|
|
||||||
(String) categoryTree.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
categoryManager.removeSubCategoryFromCategory(category, parent);
|
|
||||||
categoryManager.addSubCategoryToCategory(category, target);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideCategoryMover(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,142 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeNode;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryMoverModel implements TreeModel {
|
|
||||||
|
|
||||||
private final Domain domain;
|
|
||||||
private final Category selectedCategory;
|
|
||||||
|
|
||||||
public CategoryMoverModel(final Domain domain,
|
|
||||||
final Category selectedCategory) {
|
|
||||||
this.domain = domain;
|
|
||||||
this.selectedCategory = selectedCategory;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeNode getRoot(final PageState data) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(domain.getRoot()
|
|
||||||
.getObjectId()).get();
|
|
||||||
return new CategoryMoverNode(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a list of the sub categories of the provided node
|
|
||||||
* <em>without</em>
|
|
||||||
* the selected category. This prevents the selected category and its sub
|
|
||||||
* categories from be added to tree. Therefore the user can't move a
|
|
||||||
* category beneath itself.
|
|
||||||
*
|
|
||||||
* @param node The current node.
|
|
||||||
*
|
|
||||||
* @return A list of the subcategories of the category managed by the
|
|
||||||
* provided node.
|
|
||||||
*/
|
|
||||||
private List<Category> getSubCategories(final TreeNode node) {
|
|
||||||
final CategoryRepository categoryRepo = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(
|
|
||||||
((CategoryMoverNode) node).getCategory().getObjectId()).get();
|
|
||||||
|
|
||||||
final List<Category> subCategories = new ArrayList<>();
|
|
||||||
category.getSubCategories().forEach(c -> {
|
|
||||||
if (!c.equals(selectedCategory)) {
|
|
||||||
subCategories.add(c);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return subCategories;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasChildren(final TreeNode node, final PageState state) {
|
|
||||||
final List<Category> subCategories = getSubCategories(node);
|
|
||||||
return (subCategories != null && !subCategories.isEmpty()) ;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Iterator getChildren(final TreeNode node, final PageState state) {
|
|
||||||
return new SubCategoryNodesIterator(getSubCategories(node));
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryMoverNode implements TreeNode {
|
|
||||||
|
|
||||||
private final Category category;
|
|
||||||
|
|
||||||
public CategoryMoverNode(final Category category) {
|
|
||||||
this.category = category;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Category getCategory() {
|
|
||||||
return category;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKey() {
|
|
||||||
return Long.toString(category.getObjectId());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElement() {
|
|
||||||
return category.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SubCategoryNodesIterator
|
|
||||||
implements Iterator<CategoryMoverNode> {
|
|
||||||
|
|
||||||
private final Iterator<Category> subCategoriesIterator;
|
|
||||||
|
|
||||||
public SubCategoryNodesIterator(final List<Category> subCategories) {
|
|
||||||
subCategoriesIterator = subCategories.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasNext() {
|
|
||||||
return subCategoriesIterator.hasNext();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public CategoryMoverNode next() {
|
|
||||||
return new CategoryMoverNode(subCategoriesIterator.next());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,71 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Tree;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModel;
|
|
||||||
import com.arsdigita.bebop.tree.TreeModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryMoverModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TreeModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
public CategoryMoverModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeModel makeModel(final Tree tree, final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = cdiUtil.findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
return new CategoryMoverModel(domain, category);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,101 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static enum CategoryProperty {
|
|
||||||
NAME,
|
|
||||||
ENABLED,
|
|
||||||
VISIBLE,
|
|
||||||
ABSTRACT
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Category selectedCategory;
|
|
||||||
private final Iterator<CategoryProperty> propertyIterator;
|
|
||||||
private CategoryProperty currentProperty;
|
|
||||||
|
|
||||||
public CategoryPropertySheetModel(final Category selectedCategory) {
|
|
||||||
this.selectedCategory = selectedCategory;
|
|
||||||
propertyIterator = Arrays.asList(CategoryProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (selectedCategory == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generatedGlobalizedLabel(
|
|
||||||
final CategoryProperty property) {
|
|
||||||
|
|
||||||
final String key = String.join(
|
|
||||||
"",
|
|
||||||
"ui.admin.categories.category.property_sheet.",
|
|
||||||
property.toString().toLowerCase());
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generatedGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentProperty) {
|
|
||||||
case NAME:
|
|
||||||
return selectedCategory.getName();
|
|
||||||
case ENABLED:
|
|
||||||
return Boolean.toString(selectedCategory.isEnabled());
|
|
||||||
case VISIBLE:
|
|
||||||
return Boolean.toString(selectedCategory.isVisible());
|
|
||||||
case ABSTRACT:
|
|
||||||
return Boolean.toString(selectedCategory.isAbstractCategory());
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryPropertySheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
public CategoryPropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String categoryIdStr = selectedCategoryId.getSelectedKey(state);
|
|
||||||
final Category selectedCategory;
|
|
||||||
|
|
||||||
if (categoryIdStr == null || categoryIdStr.isEmpty()) {
|
|
||||||
selectedCategory = null;
|
|
||||||
} else {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
selectedCategory = categoryRepository.findById(Long.parseLong(
|
|
||||||
categoryIdStr)).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new CategoryPropertySheetModel(selectedCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,167 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryTitleForm extends Form {
|
|
||||||
|
|
||||||
private static final String LOCALIZED_CATEGORY_TITLE = "title";
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
|
|
||||||
private final TextField title;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public CategoryTitleForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super("categoryTitleForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.title.edit.back", ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
categoriesTab.hideDomainTitleForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil()
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
if (selectedCategory.getTitle().hasValue(selectedLocale)) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.title.edit_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedCategory.getName(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.title.add_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedCategory.getName(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
title = new TextField(LOCALIZED_CATEGORY_TITLE);
|
|
||||||
title.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.title.label", ADMIN_BUNDLE));
|
|
||||||
add(title);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
if (selectedCategory.getTitle().hasValue(selectedLocale)) {
|
|
||||||
title.setValue(state, selectedCategory.getTitle().getValue(
|
|
||||||
selectedLocale));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(e.getPageState())) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String titleData = data.
|
|
||||||
getString(LOCALIZED_CATEGORY_TITLE);
|
|
||||||
|
|
||||||
if (Strings.isBlank(titleData)) {
|
|
||||||
data.addError(
|
|
||||||
LOCALIZED_CATEGORY_TITLE,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.title.error.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category selectedCategory = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final String titleData = e.getFormData().getString(
|
|
||||||
LOCALIZED_CATEGORY_TITLE);
|
|
||||||
|
|
||||||
selectedCategory.getTitle().putValue(selectedLocale, titleData);
|
|
||||||
categoryRepository.save(selectedCategory);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideCategoryTitleForm(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,255 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class CategoryTitleTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_LOCALE = 0;
|
|
||||||
private static final int COL_VALUE = 1;
|
|
||||||
private static final int COL_EDIT = 2;
|
|
||||||
private static final int COL_DEL = 3;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
|
|
||||||
public CategoryTitleTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
setIdAttr("categoryTitleTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_LOCALE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.col_lang",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_VALUE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.col_value",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.col_edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.col_del",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_EDIT:
|
|
||||||
selectedLanguage.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showCategoryTitleForm(state);
|
|
||||||
break;
|
|
||||||
case COL_DEL:
|
|
||||||
final Locale locale = new Locale((String) event.
|
|
||||||
getRowKey());
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(
|
|
||||||
CategoryRepository.class);
|
|
||||||
final Category category = categoryRepository.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.
|
|
||||||
getSelectedKey(state))).get();
|
|
||||||
category.getTitle().removeValue(locale);
|
|
||||||
|
|
||||||
categoryRepository.save(category);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new CategoryTitleTableModelBuilder());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryTitleTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new CategoryTitleTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class CategoryTitleTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Category selectedCategory;
|
|
||||||
private final List<Locale> locales;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public CategoryTitleTableModel(final PageState state) {
|
|
||||||
final CategoryRepository categoryRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
selectedCategory = categoryRepository.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
locales = new ArrayList<>();
|
|
||||||
if (selectedCategory.getTitle() != null) {
|
|
||||||
locales.addAll(
|
|
||||||
selectedCategory.getTitle().getAvailableLocales());
|
|
||||||
}
|
|
||||||
locales.sort((l1, l2) -> {
|
|
||||||
return l1.toString().compareTo(l2.toString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < locales.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Locale locale = locales.get(index);
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LOCALE:
|
|
||||||
return locale.toString();
|
|
||||||
case COL_VALUE:
|
|
||||||
return selectedCategory.getTitle().getValue(locale);
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.edit",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
case COL_DEL:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category_details.title.del",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return locales.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,173 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextArea;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainDescriptionForm extends Form {
|
|
||||||
|
|
||||||
private static final String LOCALIZED_DOMAIN_DESC = "description";
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
|
|
||||||
private final TextArea description;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public DomainDescriptionForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super("domainDescriptionForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.description.edit.back", ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
categoriesTab.hideDomainTitleForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
if (selectedDomain.getTitle().hasValue(selectedLocale)) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.description.edit_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedDomain.getDomainKey(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.description.add_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedDomain.getDomainKey(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
description = new TextArea(LOCALIZED_DOMAIN_DESC);
|
|
||||||
description.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.description.label", ADMIN_BUNDLE));
|
|
||||||
description.setCols(60);
|
|
||||||
description.setRows(10);
|
|
||||||
add(description);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
if (selectedDomain.getTitle().hasValue(selectedLocale)) {
|
|
||||||
description.setValue(state, selectedDomain.getDescription()
|
|
||||||
.getValue(selectedLocale));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(
|
|
||||||
e.getPageState())) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String titleData = data.getString(LOCALIZED_DOMAIN_DESC);
|
|
||||||
|
|
||||||
if (Strings.isBlank(titleData)) {
|
|
||||||
data.addError(
|
|
||||||
LOCALIZED_DOMAIN_DESC,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.description.error.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final String titleData = e.getFormData().getString(
|
|
||||||
LOCALIZED_DOMAIN_DESC);
|
|
||||||
|
|
||||||
selectedDomain.getDescription().putValue(selectedLocale,
|
|
||||||
titleData);
|
|
||||||
domainRepository.save(selectedDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideDomainDescriptionForm(state);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,256 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainDescriptionTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_LOCALE = 0;
|
|
||||||
private static final int COL_VALUE = 1;
|
|
||||||
private static final int COL_EDIT = 2;
|
|
||||||
private static final int COL_DEL = 3;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
|
|
||||||
public DomainDescriptionTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
setIdAttr("domainDescriptionTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.none",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_LOCALE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.col_lang",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_VALUE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.col_value",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.col_edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.col_del",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description"
|
|
||||||
+ ".del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_EDIT:
|
|
||||||
selectedLanguage.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showDomainDescriptionForm(state);
|
|
||||||
break;
|
|
||||||
case COL_DEL:
|
|
||||||
final Locale locale = new Locale((String) event
|
|
||||||
.getRowKey());
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().
|
|
||||||
findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId
|
|
||||||
.getSelectedKey(state))).get();
|
|
||||||
domain.getDescription().removeValue(locale);
|
|
||||||
|
|
||||||
domainRepository.save(domain);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new DomainDescriptionTableModelBuilder());
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainDescriptionTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new DomainDescriptionTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainDescriptionTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Domain selectedDomain;
|
|
||||||
private final List<Locale> locales;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public DomainDescriptionTableModel(final PageState state) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
locales = new ArrayList<>();
|
|
||||||
locales.addAll(selectedDomain.getDescription()
|
|
||||||
.getAvailableLocales());
|
|
||||||
locales.sort((l1, l2) -> {
|
|
||||||
return l1.toString().compareTo(l2.toString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < locales.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Locale locale = locales.get(index);
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LOCALE:
|
|
||||||
return locale.toString();
|
|
||||||
case COL_VALUE:
|
|
||||||
return selectedDomain.getDescription().getValue(locale);
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_DEL:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description.del",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return locales.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,317 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.SegmentedPanel;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.kernel.KernelConfig;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainDetails extends SegmentedPanel {
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
private final DomainTitleAddForm domainTitleAddForm;
|
|
||||||
private final DomainDescriptionAddForm domainDescriptionAddForm;
|
|
||||||
|
|
||||||
public DomainDetails(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.back", ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTab.hideDomainDetails(state);
|
|
||||||
});
|
|
||||||
addSegment("domain-details-back", backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.details.heading",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{domain.getDomainKey()}));
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
final BoxPanel propertiesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
propertiesPanel.add(new PropertySheet(
|
|
||||||
new DomainPropertySheetModelBuilder(selectedDomainId)));
|
|
||||||
final ActionLink editBasicPropertiesLink = new ActionLink(
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.basic_properties.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
editBasicPropertiesLink.addActionListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
categoriesTab.showDomainForm(state);
|
|
||||||
});
|
|
||||||
propertiesPanel.add(editBasicPropertiesLink);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.basic_properties",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
propertiesPanel);
|
|
||||||
|
|
||||||
final BoxPanel titlesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
titlesPanel.add(new DomainTitleTable(categoriesTab,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedLanguage));
|
|
||||||
domainTitleAddForm = new DomainTitleAddForm();
|
|
||||||
titlesPanel.add(domainTitleAddForm);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.domain_title",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
titlesPanel);
|
|
||||||
|
|
||||||
final BoxPanel descPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
descPanel.add(new DomainDescriptionTable(categoriesTab,
|
|
||||||
selectedDomainId,
|
|
||||||
selectedLanguage));
|
|
||||||
domainDescriptionAddForm = new DomainDescriptionAddForm();
|
|
||||||
descPanel.add(domainDescriptionAddForm);
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.description",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
descPanel);
|
|
||||||
|
|
||||||
final BoxPanel mappingsPanel = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
mappingsPanel.add(new DomainMappingsTable(categoriesTab,
|
|
||||||
selectedDomainId));
|
|
||||||
mappingsPanel.add(new DomainMappingAddForm(selectedDomainId));
|
|
||||||
addSegment(
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings",
|
|
||||||
ADMIN_BUNDLE)),
|
|
||||||
mappingsPanel);
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainTitleAddForm extends Form {
|
|
||||||
|
|
||||||
private static final String TITLE_SELECT_LANG = "titleSelectLang";
|
|
||||||
|
|
||||||
public DomainTitleAddForm() {
|
|
||||||
super("domainAddTitleLang", new BoxPanel(BoxPanel.HORIZONTAL));
|
|
||||||
|
|
||||||
final SingleSelect titleSelectLang = new SingleSelect(
|
|
||||||
TITLE_SELECT_LANG);
|
|
||||||
titleSelectLang.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.domain_title.add.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
try {
|
|
||||||
titleSelectLang.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long
|
|
||||||
.parseLong(selectedDomainId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig
|
|
||||||
.getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
domain.getTitle().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
final SingleSelect target = (SingleSelect) e.getTarget();
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
supportedLanguages.forEach(l -> {
|
|
||||||
if (!assignedLanguages.contains(l)) {
|
|
||||||
target.addOption(new Option(l, new Text(l)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(titleSelectLang);
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.domain_title.add.submit",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String language = data.getString(TITLE_SELECT_LANG);
|
|
||||||
selectedLanguage.setSelectedKey(state, language);
|
|
||||||
|
|
||||||
categoriesTab.showDomainTitleForm(state);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long
|
|
||||||
.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig
|
|
||||||
.getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
domain.getTitle().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
//If all supported languages are assigned the form is not
|
|
||||||
//visible
|
|
||||||
return !assignedLanguages.equals(supportedLanguages);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainDescriptionAddForm extends Form {
|
|
||||||
|
|
||||||
private static final String DESC_SELECT_LANG = "descSelectLang";
|
|
||||||
|
|
||||||
public DomainDescriptionAddForm() {
|
|
||||||
super("domainAddDescLang", new BoxPanel(BoxPanel.HORIZONTAL));
|
|
||||||
|
|
||||||
final SingleSelect descSelectLang = new SingleSelect(
|
|
||||||
DESC_SELECT_LANG);
|
|
||||||
descSelectLang.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.domain_desc.add.label",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
try {
|
|
||||||
descSelectLang.addPrintListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long
|
|
||||||
.parseLong(selectedDomainId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig
|
|
||||||
.getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
domain.getDescription().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
final SingleSelect target = (SingleSelect) e.getTarget();
|
|
||||||
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
supportedLanguages.forEach(l -> {
|
|
||||||
if (!assignedLanguages.contains(l)) {
|
|
||||||
target.addOption(new Option(l, new Text(l)));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
add(descSelectLang);
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.domain_desc.add.submit",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String language = data.getString(DESC_SELECT_LANG);
|
|
||||||
selectedLanguage.setSelectedKey(state, language);
|
|
||||||
|
|
||||||
categoriesTab.showDomainDescriptionForm(state);
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisible(final PageState state) {
|
|
||||||
if (super.isVisible(state)) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long
|
|
||||||
.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
|
||||||
final Set<String> supportedLanguages = kernelConfig
|
|
||||||
.getSupportedLanguages();
|
|
||||||
final Set<String> assignedLanguages = new HashSet<>();
|
|
||||||
domain.getDescription().getAvailableLocales().forEach(l -> {
|
|
||||||
assignedLanguages.add(l.toString());
|
|
||||||
});
|
|
||||||
|
|
||||||
//If all supported languages are assigned the form is not
|
|
||||||
//visible
|
|
||||||
return !assignedLanguages.equals(supportedLanguages);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,230 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.Page;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.Date;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainManager;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.time.LocalDate;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainForm extends Form {
|
|
||||||
|
|
||||||
private static final String RELEASED = "released";
|
|
||||||
private static final String VERSION = "version";
|
|
||||||
private static final String DOMAIN_URI = "domainUri";
|
|
||||||
private static final String DOMAIN_KEY = "domainKey";
|
|
||||||
private static final String ROOT_CATEGORY_NAME = "rootCategoryName";
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
|
|
||||||
private final TextField domainKey;
|
|
||||||
private final TextField domainUri;
|
|
||||||
private final TextField version;
|
|
||||||
private final Date released;
|
|
||||||
private final TextField rootCategoryName;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public DomainForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
|
||||||
|
|
||||||
super("domainForm");
|
|
||||||
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
if (selectedDomainId.getSelectedKey(state) == null) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.heading.create_new",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.
|
|
||||||
createCdiUtil().findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.heading.edit",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{domain.getDomainKey()}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
domainKey = new TextField(DOMAIN_KEY);
|
|
||||||
domainKey.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.fields.domain_key",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(domainKey);
|
|
||||||
|
|
||||||
domainUri = new TextField(DOMAIN_URI);
|
|
||||||
domainUri.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.fields.domain_uri",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(domainUri);
|
|
||||||
|
|
||||||
version = new TextField(VERSION);
|
|
||||||
version.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.fields.version",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(version);
|
|
||||||
|
|
||||||
released = new Date(RELEASED);
|
|
||||||
released.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.fields.released",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(released);
|
|
||||||
|
|
||||||
rootCategoryName = new TextField(ROOT_CATEGORY_NAME);
|
|
||||||
rootCategoryName.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.fields.root_category_name",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
add(rootCategoryName);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (selectedDomainId.getSelectedKey(state) == null) {
|
|
||||||
rootCategoryName.setVisible(state, true);
|
|
||||||
} else {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
domainKey.setValue(state, domain.getDomainKey());
|
|
||||||
domainUri.setValue(state, domain.getUri());
|
|
||||||
version.setValue(state, domain.getVersion());
|
|
||||||
released.setValue(state, domain.getReleased());
|
|
||||||
|
|
||||||
rootCategoryName.setVisible(state, false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String domainKeyData = data.getString(DOMAIN_KEY);
|
|
||||||
final String versionData = data.getString(VERSION);
|
|
||||||
|
|
||||||
if (Strings.isBlank(domainKeyData)) {
|
|
||||||
data.addError(
|
|
||||||
DOMAIN_KEY,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.errors.domain_key_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Strings.isBlank(versionData)) {
|
|
||||||
data.addError(
|
|
||||||
DOMAIN_KEY,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_form.errors.version_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
final DomainManager domainManager = cdiUtil.findBean(
|
|
||||||
DomainManager.class);
|
|
||||||
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
final String domainKeyData = data.getString(DOMAIN_KEY);
|
|
||||||
final String domainUriData;
|
|
||||||
if (Strings.isBlank(data.getString(DOMAIN_URI))) {
|
|
||||||
domainUriData = null;
|
|
||||||
} else {
|
|
||||||
domainUriData = data.getString(DOMAIN_URI);
|
|
||||||
}
|
|
||||||
final String versionData = data.getString(VERSION);
|
|
||||||
final java.util.Date releasedData = (java.util.Date) data.get(
|
|
||||||
RELEASED
|
|
||||||
);
|
|
||||||
final String rootCategoryNameData = data.getString(
|
|
||||||
ROOT_CATEGORY_NAME);
|
|
||||||
|
|
||||||
final Domain domain;
|
|
||||||
if (selectedDomainId.getSelectedKey(state) == null) {
|
|
||||||
if (Strings.isBlank(rootCategoryNameData)) {
|
|
||||||
domain = domainManager.createDomain(domainKeyData,
|
|
||||||
domainKeyData);
|
|
||||||
} else {
|
|
||||||
domain = domainManager.createDomain(
|
|
||||||
domainKeyData, rootCategoryNameData);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
domain = domainRepository.findById(Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
}
|
|
||||||
domain.setDomainKey(domainKeyData);
|
|
||||||
domain.setUri(domainUriData);
|
|
||||||
domain.setVersion(versionData);
|
|
||||||
domain.setReleased(LocalDate.from(releasedData.toInstant()));
|
|
||||||
|
|
||||||
domainRepository.save(domain);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideDomainForm(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.setVisibleDefault(rootCategoryName, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,142 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.form.Option;
|
|
||||||
import com.arsdigita.bebop.form.SingleSelect;
|
|
||||||
import com.arsdigita.bebop.form.Submit;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.UncheckedWrapperException;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainManager;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TooManyListenersException;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainMappingAddForm extends Form {
|
|
||||||
|
|
||||||
private static final String DOMAIN_MAPPING_OWNER = "domainMappingOwner";
|
|
||||||
|
|
||||||
public DomainMappingAddForm(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
|
||||||
|
|
||||||
super("domainMappingAddForm", new BoxPanel(BoxPanel.HORIZONTAL));
|
|
||||||
//
|
|
||||||
// final Label heading = new Label(new GlobalizedMessage(
|
|
||||||
// "ui.admin.categories.domain_details.mappings.add", ADMIN_BUNDLE));
|
|
||||||
// heading.setClassAttr("heading");
|
|
||||||
// add(heading);
|
|
||||||
|
|
||||||
final SingleSelect appSelect = new SingleSelect(DOMAIN_MAPPING_OWNER);
|
|
||||||
appSelect.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.add", ADMIN_BUNDLE));
|
|
||||||
try {
|
|
||||||
appSelect.addPrintListener(e -> {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final ApplicationRepository appRepository = cdiUtil.findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
final DomainManager domainManager = cdiUtil.findBean(
|
|
||||||
DomainManager.class);
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(
|
|
||||||
selectedDomainId.getSelectedKey(e.getPageState())),
|
|
||||||
"Domain.withOwners").get();
|
|
||||||
|
|
||||||
final List<CcmApplication> applications = appRepository
|
|
||||||
.findAll();
|
|
||||||
|
|
||||||
final SingleSelect target = (SingleSelect) e.getTarget();
|
|
||||||
target.clearOptions();
|
|
||||||
|
|
||||||
target.addOption(new Option("0", new Text("")));
|
|
||||||
|
|
||||||
applications.forEach(a -> {
|
|
||||||
if (!domainManager.isDomainOwner(a, domain)) {
|
|
||||||
target.addOption(new Option(Long.toString(a
|
|
||||||
.getObjectId()),
|
|
||||||
new Text(a.getPrimaryUrl())));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
} catch (TooManyListenersException ex) {
|
|
||||||
throw new UncheckedWrapperException(ex);
|
|
||||||
}
|
|
||||||
add(appSelect);
|
|
||||||
|
|
||||||
add(new Submit(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.create", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String appId = data.getString(DOMAIN_MAPPING_OWNER);
|
|
||||||
if ("0".equals(appId)) {
|
|
||||||
data.addError(
|
|
||||||
DOMAIN_MAPPING_OWNER,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.doamin_details.mappings.error"
|
|
||||||
+ ".please_select_app",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
final DomainManager domainManager = cdiUtil.findBean(
|
|
||||||
DomainManager.class);
|
|
||||||
final ApplicationRepository appRepository = cdiUtil.findBean(
|
|
||||||
ApplicationRepository.class);
|
|
||||||
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state)),
|
|
||||||
"Domain.withOwners").get();
|
|
||||||
final CcmApplication application = appRepository.findById(
|
|
||||||
Long.parseLong(data.getString(DOMAIN_MAPPING_OWNER)),
|
|
||||||
"CcmApplication.withDomains").get();
|
|
||||||
|
|
||||||
domainManager.addDomainOwner(application, domain);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,219 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainManager;
|
|
||||||
import org.libreccm.categorization.DomainOwnership;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.web.ApplicationRepository;
|
|
||||||
import org.libreccm.web.CcmApplication;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainMappingsTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_APPLICATION = 0;
|
|
||||||
private static final int COL_REMOVE = 1;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
|
|
||||||
public DomainMappingsTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
|
|
||||||
setIdAttr("domainMappingsTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.none",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_APPLICATION,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.col_app",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
// columnModel.add(new TableColumn(
|
|
||||||
// COL_CONTEXT,
|
|
||||||
// new Label(new GlobalizedMessage(
|
|
||||||
// "ui.admin.categories.domain_details.mappings.col_context",
|
|
||||||
// ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_REMOVE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.col_remove",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_REMOVE).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.remove.confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_REMOVE:
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final DomainRepository domainRepository = cdiUtil
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final DomainManager domainManager = cdiUtil.findBean(
|
|
||||||
DomainManager.class);
|
|
||||||
final ApplicationRepository appRepository = cdiUtil
|
|
||||||
.findBean(ApplicationRepository.class);
|
|
||||||
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(event
|
|
||||||
.getPageState()))).get();
|
|
||||||
|
|
||||||
final CcmApplication owner = appRepository.findById(
|
|
||||||
Long.parseLong((String)event.getRowKey())).get();
|
|
||||||
|
|
||||||
domainManager.removeDomainOwner(owner, domain);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new DomainMappingsTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainMappingsTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new DomainMappingsTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainMappingsTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<DomainOwnership> domainOwnerships;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public DomainMappingsTableModel(final PageState state) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state)),
|
|
||||||
"Domain.withOwners").get();
|
|
||||||
|
|
||||||
domainOwnerships = new ArrayList<>(domain.getOwners());
|
|
||||||
|
|
||||||
domainOwnerships.sort((o1, o2) -> {
|
|
||||||
return ((Long)o1.getOwnerOrder()).compareTo(o2.getOwnerOrder());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < domainOwnerships.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
switch(columnIndex) {
|
|
||||||
case COL_APPLICATION:
|
|
||||||
return domainOwnerships.get(index).getOwner().getPrimaryUrl();
|
|
||||||
case COL_REMOVE:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.mappings.remove",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return domainOwnerships.get(index).getOwner().getObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1,108 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainPropertySheetModel implements PropertySheetModel {
|
|
||||||
|
|
||||||
private static enum DomainProperty {
|
|
||||||
DOMAIN_KEY,
|
|
||||||
URI,
|
|
||||||
VERSION,
|
|
||||||
RELEASED
|
|
||||||
}
|
|
||||||
|
|
||||||
private final Domain selectedDomain;
|
|
||||||
private final Iterator<DomainProperty> propertyIterator;
|
|
||||||
private DomainProperty currentProperty;
|
|
||||||
|
|
||||||
public DomainPropertySheetModel(final Domain selectedDomain) {
|
|
||||||
this.selectedDomain = selectedDomain;
|
|
||||||
propertyIterator = Arrays.asList(DomainProperty.values()).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (selectedDomain == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (propertyIterator.hasNext()) {
|
|
||||||
currentProperty = propertyIterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getLabel() {
|
|
||||||
return currentProperty.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private GlobalizedMessage generatedGlobalizedLabel(
|
|
||||||
final DomainProperty property) {
|
|
||||||
|
|
||||||
final String key = String.join(
|
|
||||||
"",
|
|
||||||
"ui.admin.categories.domain.property_sheet.",
|
|
||||||
property.toString().toLowerCase());
|
|
||||||
return new GlobalizedMessage(key, ADMIN_BUNDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public GlobalizedMessage getGlobalizedLabel() {
|
|
||||||
return generatedGlobalizedLabel(currentProperty);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getValue() {
|
|
||||||
switch (currentProperty) {
|
|
||||||
case DOMAIN_KEY:
|
|
||||||
return selectedDomain.getDomainKey();
|
|
||||||
case URI:
|
|
||||||
return selectedDomain.getUri();
|
|
||||||
case VERSION:
|
|
||||||
return selectedDomain.getVersion();
|
|
||||||
case RELEASED:
|
|
||||||
if (selectedDomain.getReleased() == null) {
|
|
||||||
return "";
|
|
||||||
} else {
|
|
||||||
return String.format("%tY-%<tm-%<td",
|
|
||||||
selectedDomain.getReleased());
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheet;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModel;
|
|
||||||
import com.arsdigita.bebop.PropertySheetModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainPropertySheetModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements PropertySheetModelBuilder {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
|
|
||||||
public DomainPropertySheetModelBuilder(
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId) {
|
|
||||||
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public PropertySheetModel makeModel(final PropertySheet sheet,
|
|
||||||
final PageState state) {
|
|
||||||
final String domainIdStr = selectedDomainId.getSelectedKey(state);
|
|
||||||
final Domain selectedDomain;
|
|
||||||
if (Strings.isBlank(domainIdStr)) {
|
|
||||||
selectedDomain = null;
|
|
||||||
} else {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
selectedDomain = domainRepository.findById(Long.parseLong(
|
|
||||||
domainIdStr)).get();
|
|
||||||
}
|
|
||||||
|
|
||||||
return new DomainPropertySheetModel(selectedDomain);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,169 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.ActionLink;
|
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
|
||||||
import com.arsdigita.bebop.Form;
|
|
||||||
import com.arsdigita.bebop.FormData;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.SaveCancelSection;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainTitleForm extends Form {
|
|
||||||
|
|
||||||
private static final String LOCALIZED_DOMAIN_TITLE = "title";
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
|
|
||||||
private final TextField title;
|
|
||||||
private final SaveCancelSection saveCancelSection;
|
|
||||||
|
|
||||||
public DomainTitleForm(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super("domainTitleForm", new BoxPanel(BoxPanel.VERTICAL));
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
|
|
||||||
final ActionLink backLink = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.title.edit.back", ADMIN_BUNDLE));
|
|
||||||
backLink.addActionListener(e -> {
|
|
||||||
categoriesTab.hideDomainTitleForm(e.getPageState());
|
|
||||||
});
|
|
||||||
add(backLink);
|
|
||||||
|
|
||||||
final Label heading = new Label(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final Label target = (Label) e.getTarget();
|
|
||||||
|
|
||||||
if (selectedDomain.getTitle().hasValue(selectedLocale)) {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.title.edit_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedDomain.getDomainKey(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
} else {
|
|
||||||
target.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.title.add_for_lang",
|
|
||||||
ADMIN_BUNDLE,
|
|
||||||
new String[]{selectedDomain.getDomainKey(),
|
|
||||||
selectedLocale.toString()}));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
heading.setClassAttr("heading");
|
|
||||||
add(heading);
|
|
||||||
|
|
||||||
title = new TextField(LOCALIZED_DOMAIN_TITLE);
|
|
||||||
title.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.title.label", ADMIN_BUNDLE));
|
|
||||||
add(title);
|
|
||||||
|
|
||||||
saveCancelSection = new SaveCancelSection();
|
|
||||||
add(saveCancelSection);
|
|
||||||
|
|
||||||
addInitListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
if (selectedDomain.getTitle().hasValue(selectedLocale)) {
|
|
||||||
title.setValue(state, selectedDomain.getTitle().getValue(
|
|
||||||
selectedLocale));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addValidationListener(e -> {
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(
|
|
||||||
e.getPageState())) {
|
|
||||||
final FormData data = e.getFormData();
|
|
||||||
|
|
||||||
final String titleData = data.getString(LOCALIZED_DOMAIN_TITLE);
|
|
||||||
|
|
||||||
if (Strings.isBlank(titleData)) {
|
|
||||||
data.addError(
|
|
||||||
LOCALIZED_DOMAIN_TITLE,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain.title.error.not_blank",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
addProcessListener(e -> {
|
|
||||||
final PageState state = e.getPageState();
|
|
||||||
|
|
||||||
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
final Domain selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state)))
|
|
||||||
.get();
|
|
||||||
|
|
||||||
final Locale selectedLocale = new Locale(selectedLanguage
|
|
||||||
.getSelectedKey(state));
|
|
||||||
|
|
||||||
final String titleData = e.getFormData().getString(
|
|
||||||
LOCALIZED_DOMAIN_TITLE);
|
|
||||||
|
|
||||||
selectedDomain.getTitle().putValue(selectedLocale, titleData);
|
|
||||||
domainRepository.save(selectedDomain);
|
|
||||||
}
|
|
||||||
|
|
||||||
categoriesTab.hideDomainTitleForm(state);
|
|
||||||
});
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,253 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainTitleTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_LOCALE = 0;
|
|
||||||
private static final int COL_VALUE = 1;
|
|
||||||
private static final int COL_EDIT = 2;
|
|
||||||
private static final int COL_DEL = 3;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedLanguage;
|
|
||||||
|
|
||||||
public DomainTitleTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.selectedLanguage = selectedLanguage;
|
|
||||||
|
|
||||||
setIdAttr("domainTitleTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.none", ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_LOCALE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.col_lang",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_VALUE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.col_value",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.col_edit",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.col_del",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_EDIT:
|
|
||||||
selectedLanguage.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showDomainTitleForm(state);
|
|
||||||
break;
|
|
||||||
case COL_DEL:
|
|
||||||
final Locale locale = new Locale((String) event
|
|
||||||
.getRowKey());
|
|
||||||
final DomainRepository domainRepository = CdiUtil
|
|
||||||
.createCdiUtil().
|
|
||||||
findBean(DomainRepository.class);
|
|
||||||
final Domain domain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId
|
|
||||||
.getSelectedKey(state))).get();
|
|
||||||
domain.getTitle().removeValue(locale);
|
|
||||||
|
|
||||||
domainRepository.save(domain);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent e) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new DomainTitleTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainTitleTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new DomainTitleTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainTitleTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Domain selectedDomain;
|
|
||||||
private final List<Locale> locales;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public DomainTitleTableModel(final PageState state) {
|
|
||||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
|
||||||
.findBean(DomainRepository.class);
|
|
||||||
selectedDomain = domainRepository.findById(
|
|
||||||
Long.parseLong(selectedDomainId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
locales = new ArrayList<>();
|
|
||||||
locales.addAll(selectedDomain.getTitle().getAvailableLocales());
|
|
||||||
locales.sort((l1, l2) -> {
|
|
||||||
return l1.toString().compareTo(l2.toString());
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < locales.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Locale locale = locales.get(index);
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_LOCALE:
|
|
||||||
return locale.toString();
|
|
||||||
case COL_VALUE:
|
|
||||||
return selectedDomain.getTitle().getValue(locale);
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.edit",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
case COL_DEL:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domain_details.title.del",
|
|
||||||
ADMIN_BUNDLE
|
|
||||||
));
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return locales.get(index);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,282 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.form.TextField;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
|
||||||
import org.apache.logging.log4j.Logger;
|
|
||||||
import org.apache.logging.log4j.util.Strings;
|
|
||||||
import org.libreccm.categorization.Domain;
|
|
||||||
import org.libreccm.categorization.DomainRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.l10n.GlobalizationHelper;
|
|
||||||
import org.libreccm.l10n.LocalizedString;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class DomainsTable extends Table {
|
|
||||||
|
|
||||||
private final static Logger LOGGER = LogManager.getLogger(
|
|
||||||
DomainsTable.class);
|
|
||||||
|
|
||||||
private static final int COL_DOMAIN_KEY = 0;
|
|
||||||
private static final int COL_DOMAIN_URI = 1;
|
|
||||||
private static final int COL_DOMAIN_TITLE = 2;
|
|
||||||
private static final int COL_DOMAIN_DEL = 3;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedDomainId;
|
|
||||||
private final TextField domainsFilter;
|
|
||||||
|
|
||||||
public DomainsTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
|
||||||
final TextField domainsFilter) {
|
|
||||||
super();
|
|
||||||
|
|
||||||
setIdAttr("domainsTable");
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedDomainId = selectedDomainId;
|
|
||||||
this.domainsFilter = domainsFilter;
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.none",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DOMAIN_KEY,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui,admin.categories.domains.table.col_key",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DOMAIN_URI,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui,admin.categories.domains.table.col_uri",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DOMAIN_TITLE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui,admin.categories.domains.table.col_title",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DOMAIN_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui,admin.categories.domains.table.col_del",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
columnModel.get(COL_DOMAIN_KEY).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((String) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DOMAIN_TITLE).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
final LocalizedString title = (LocalizedString) value;
|
|
||||||
final GlobalizationHelper globalizationHelper = CdiUtil.
|
|
||||||
createCdiUtil().findBean(GlobalizationHelper.class);
|
|
||||||
return new Text(title.getValue(globalizationHelper.
|
|
||||||
getNegotiatedLocale()));
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DOMAIN_DEL).setCellRenderer(
|
|
||||||
new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.table.del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_DOMAIN_KEY:
|
|
||||||
selectedDomainId.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showDomainDetails(state);
|
|
||||||
break;
|
|
||||||
case COL_DOMAIN_DEL:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new DomainsTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainsTableModelBuilder extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table,
|
|
||||||
final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new DomainsTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DomainsTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Domain> domains;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public DomainsTableModel(final PageState state) {
|
|
||||||
LOGGER.debug("Creating DomainsTableModel");
|
|
||||||
final String filterTerm = (String) domainsFilter.getValue(state);
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final DomainRepository domainRepository = cdiUtil.findBean(
|
|
||||||
DomainRepository.class);
|
|
||||||
if (Strings.isBlank(filterTerm)) {
|
|
||||||
domains = domainRepository.findAll("Domain.withOwners");
|
|
||||||
LOGGER.debug("Found {} domains in the database.",
|
|
||||||
domains.size());
|
|
||||||
} else {
|
|
||||||
domains = domainRepository.search(filterTerm);
|
|
||||||
LOGGER.debug("Found {} domain which match the "
|
|
||||||
+ "filter \"{}\".",
|
|
||||||
domains.size(),
|
|
||||||
filterTerm);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 4;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < domains.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
LOGGER.debug("Getting element for index {}, column {}...",
|
|
||||||
index,
|
|
||||||
columnIndex);
|
|
||||||
final Domain domain = domains.get(index);
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_DOMAIN_KEY:
|
|
||||||
return domain.getDomainKey();
|
|
||||||
case COL_DOMAIN_URI:
|
|
||||||
return domain.getUri();
|
|
||||||
case COL_DOMAIN_TITLE:
|
|
||||||
return domain.getTitle();
|
|
||||||
case COL_DOMAIN_DEL:
|
|
||||||
if (isDeleteable(domain)) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.domains.table.del",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return domains.get(index).getObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isDeleteable(final Domain domain) {
|
|
||||||
return !(domain.getOwners() != null && !domain.getOwners().isEmpty());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,354 +0,0 @@
|
||||||
/*
|
|
||||||
* 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.categories;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.Label;
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.Text;
|
|
||||||
import com.arsdigita.bebop.event.TableActionEvent;
|
|
||||||
import com.arsdigita.bebop.event.TableActionListener;
|
|
||||||
import com.arsdigita.bebop.table.TableCellRenderer;
|
|
||||||
import com.arsdigita.bebop.table.TableColumn;
|
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
import org.libreccm.categorization.Categorization;
|
|
||||||
import org.libreccm.categorization.Category;
|
|
||||||
import org.libreccm.categorization.CategoryManager;
|
|
||||||
import org.libreccm.categorization.CategoryRepository;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class SubCategoriesTable extends Table {
|
|
||||||
|
|
||||||
private static final int COL_NAME = 0;
|
|
||||||
private static final int COL_UP = 1;
|
|
||||||
private static final int COL_DOWN = 2;
|
|
||||||
private static final int COL_EDIT = 3;
|
|
||||||
private static final int COL_DEL = 4;
|
|
||||||
|
|
||||||
private final CategoriesTab categoriesTab;
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedCategoryId;
|
|
||||||
|
|
||||||
public SubCategoriesTable(
|
|
||||||
final CategoriesTab categoriesTab,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedCategoryId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
this.categoriesTab = categoriesTab;
|
|
||||||
this.selectedCategoryId = selectedCategoryId;
|
|
||||||
|
|
||||||
setIdAttr("subCategoriesTable");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.no_subcategories",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_NAME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.col_name",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_UP,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.col_up",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DOWN,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.col_down",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_EDIT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.col_edit",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEL,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.col_del",
|
|
||||||
ADMIN_BUNDLE))
|
|
||||||
));
|
|
||||||
|
|
||||||
columnModel.get(COL_UP).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DOWN).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
return new ControlLink((Component) value);
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
columnModel.get(COL_DEL).setCellRenderer(new TableCellRenderer() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Component getComponent(final Table table,
|
|
||||||
final PageState state,
|
|
||||||
final Object value,
|
|
||||||
final boolean isSelected,
|
|
||||||
final Object key,
|
|
||||||
final int row,
|
|
||||||
final int column) {
|
|
||||||
if (value == null) {
|
|
||||||
return new Text("");
|
|
||||||
} else {
|
|
||||||
final ControlLink link = new ControlLink((Component) value);
|
|
||||||
link.setConfirmation(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.del_confirm",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
return link;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
addTableActionListener(new TableActionListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void cellSelected(final TableActionEvent event) {
|
|
||||||
final PageState state = event.getPageState();
|
|
||||||
|
|
||||||
switch (event.getColumn()) {
|
|
||||||
case COL_UP: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepo = cdiUtil
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final CategoryManager categoryManager = cdiUtil
|
|
||||||
.findBean(CategoryManager.class);
|
|
||||||
final Category parentCategory = categoryRepo.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final Category subCategory = categoryRepo.findById(Long
|
|
||||||
.parseLong((String) event.getRowKey())).get();
|
|
||||||
categoryManager.decreaseCategoryOrder(subCategory,
|
|
||||||
parentCategory);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COL_DOWN: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepo = cdiUtil
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final CategoryManager categoryManager = cdiUtil
|
|
||||||
.findBean(CategoryManager.class);
|
|
||||||
final Category parentCategory = categoryRepo.findById(
|
|
||||||
Long.parseLong(selectedCategoryId.getSelectedKey(
|
|
||||||
state))).get();
|
|
||||||
final Category subCategory = categoryRepo.findById(Long
|
|
||||||
.parseLong((String) event.getRowKey())).get();
|
|
||||||
categoryManager.increaseCategoryOrder(subCategory,
|
|
||||||
parentCategory);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COL_EDIT: {
|
|
||||||
selectedCategoryId.setSelectedKey(state,
|
|
||||||
event.getRowKey());
|
|
||||||
categoriesTab.showCategoryEditForm(state);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case COL_DEL: {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoryRepository categoryRepo = cdiUtil
|
|
||||||
.findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(Long
|
|
||||||
.parseLong((String) event.getRowKey())).get();
|
|
||||||
categoryRepo.delete(category);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void headSelected(final TableActionEvent event) {
|
|
||||||
//Nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
setModelBuilder(new SubCategoriesTableModelBuilder());
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SubCategoriesTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
table.getRowSelectionModel().clearSelection(state);
|
|
||||||
|
|
||||||
return new SubCategoriesTableModel(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private class SubCategoriesTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final List<Category> subCategories;
|
|
||||||
private int index = -1;
|
|
||||||
|
|
||||||
public SubCategoriesTableModel(final PageState state) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoriesController controller = cdiUtil
|
|
||||||
.findBean(CategoriesController.class);
|
|
||||||
final CategoryRepository categoryRepo = CdiUtil.
|
|
||||||
createCdiUtil().findBean(CategoryRepository.class);
|
|
||||||
final Category category = categoryRepo.findById(Long.parseLong(
|
|
||||||
selectedCategoryId.getSelectedKey(state))).get();
|
|
||||||
|
|
||||||
subCategories = controller.getSubCategories(category);
|
|
||||||
|
|
||||||
// subCategories.sort((c1, c2) -> {
|
|
||||||
// return Long.compare(c1.getCategoryOrder(),
|
|
||||||
// c2.getCategoryOrder());
|
|
||||||
// });
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 5;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
index++;
|
|
||||||
return index < subCategories.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
final Category subCategory = subCategories.get(index);
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case COL_NAME:
|
|
||||||
return subCategory.getName();
|
|
||||||
case COL_UP:
|
|
||||||
if (index == 0) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.up",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
case COL_DOWN:
|
|
||||||
if (index == subCategories.size() - 1) {
|
|
||||||
return null;
|
|
||||||
} else {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.down",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
case COL_EDIT:
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.edit",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
case COL_DEL:
|
|
||||||
if (isDeletable(subCategory)) {
|
|
||||||
return new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.categories.category.subcategories.del",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
} else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException(
|
|
||||||
"Not a valid column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isDeletable(final Category category) {
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final CategoriesController controller = cdiUtil
|
|
||||||
.findBean(CategoriesController.class);
|
|
||||||
|
|
||||||
return controller.isDeletable(category);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return subCategories.get(index).getObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -18,18 +18,15 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.core;
|
package org.libreccm.core;
|
||||||
|
|
||||||
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;
|
||||||
import com.arsdigita.ui.admin.applications.AdminApplicationSetup;
|
import com.arsdigita.ui.admin.applications.AdminApplicationSetup;
|
||||||
import com.arsdigita.ui.login.LoginApplicationCreator;
|
import com.arsdigita.ui.login.LoginApplicationCreator;
|
||||||
import com.arsdigita.ui.login.LoginApplicationSetup;
|
import com.arsdigita.ui.login.LoginApplicationSetup;
|
||||||
import com.arsdigita.ui.login.LoginConstants;
|
import com.arsdigita.ui.login.LoginConstants;
|
||||||
import com.arsdigita.ui.login.LoginServlet;
|
|
||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.libreccm.admin.ui.AdminJsfApplicationCreator;
|
|
||||||
import org.libreccm.admin.ui.AdminJsfApplicationSetup;
|
import org.libreccm.admin.ui.AdminJsfApplicationSetup;
|
||||||
import org.libreccm.modules.CcmModule;
|
import org.libreccm.modules.CcmModule;
|
||||||
import org.libreccm.modules.InitEvent;
|
import org.libreccm.modules.InitEvent;
|
||||||
|
|
@ -52,24 +49,21 @@ import java.util.Properties;
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
@Module(applicationTypes = {
|
@Module(
|
||||||
@ApplicationType(name = LoginConstants.LOGIN_APP_TYPE,
|
applicationTypes = {
|
||||||
|
@ApplicationType(
|
||||||
|
name = LoginConstants.LOGIN_APP_TYPE,
|
||||||
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),
|
),
|
||||||
@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),
|
)
|
||||||
@ApplicationType(name = "org.libreccm.ui.admin.AdminFaces",
|
|
||||||
descBundle = "com.arsdigita.ui.admin.AdminResources",
|
|
||||||
singleton = true,
|
|
||||||
creator = AdminJsfApplicationCreator.class,
|
|
||||||
servletPath = "/admin-jsf/admin.xhtml")
|
|
||||||
},
|
},
|
||||||
pageModelComponentModels = {},
|
|
||||||
configurations = {
|
configurations = {
|
||||||
com.arsdigita.bebop.BebopConfig.class,
|
com.arsdigita.bebop.BebopConfig.class,
|
||||||
com.arsdigita.dispatcher.DispatcherConfig.class,
|
com.arsdigita.dispatcher.DispatcherConfig.class,
|
||||||
|
|
@ -88,7 +82,9 @@ import java.util.Properties;
|
||||||
org.libreccm.files.CcmFilesConfiguration.class,
|
org.libreccm.files.CcmFilesConfiguration.class,
|
||||||
org.libreccm.search.SearchConfig.class,
|
org.libreccm.search.SearchConfig.class,
|
||||||
org.libreccm.security.EmailTemplates.class,
|
org.libreccm.security.EmailTemplates.class,
|
||||||
org.libreccm.security.OneTimeAuthConfig.class,})
|
org.libreccm.security.OneTimeAuthConfig.class
|
||||||
|
}
|
||||||
|
)
|
||||||
public class CcmCore implements CcmModule {
|
public class CcmCore implements CcmModule {
|
||||||
|
|
||||||
private static final Logger LOGGER = LogManager.getLogger(CcmCore.class);
|
private static final Logger LOGGER = LogManager.getLogger(CcmCore.class);
|
||||||
|
|
|
||||||
|
|
@ -18,10 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.libreccm.web;
|
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 org.libreccm.ui.admin.applications.ApplicationController;
|
import org.libreccm.ui.admin.applications.ApplicationController;
|
||||||
import org.libreccm.ui.admin.applications.DefaultApplicationController;
|
import org.libreccm.ui.admin.applications.DefaultApplicationController;
|
||||||
|
|
@ -118,12 +114,6 @@ public @interface ApplicationType {
|
||||||
@SuppressWarnings("rawtypes") // Can't specify type here, otherwise problems in using classes.
|
@SuppressWarnings("rawtypes") // Can't specify type here, otherwise problems in using classes.
|
||||||
Class<? extends ApplicationCreator> creator();
|
Class<? extends ApplicationCreator> creator();
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Class<? extends AbstractAppInstanceForm> instanceForm() default DefaultApplicationInstanceForm.class;
|
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
Class<? extends AbstractAppSettingsPane> settingsPane() default DefaultApplicationSettingsPane.class;
|
|
||||||
|
|
||||||
Class<? extends ApplicationController> applicationController() default DefaultApplicationController.class;
|
Class<? extends ApplicationController> applicationController() default DefaultApplicationController.class;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue