CCM NG: Admin UI for sites
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@5086 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
90c7f1a858
commit
ef84e1a029
|
|
@ -0,0 +1,104 @@
|
||||||
|
/*
|
||||||
|
* 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.sites;
|
||||||
|
|
||||||
|
import org.libreccm.sites.Site;
|
||||||
|
import org.libreccm.sites.SiteRepository;
|
||||||
|
import org.libreccm.web.CcmApplication;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
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 SitesController implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -7758130361475180380L;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private SiteRepository sitesRepo;
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected List<SitesTableRow> findSites() {
|
||||||
|
|
||||||
|
return sitesRepo
|
||||||
|
.findAll()
|
||||||
|
.stream()
|
||||||
|
.map(this::buildRow)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if there no site with the provided domain.
|
||||||
|
*
|
||||||
|
* @param domainOfSite
|
||||||
|
*
|
||||||
|
* @return {@code true} if there is no site with the provided domain,
|
||||||
|
* {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected boolean isUnique(final String domainOfSite) {
|
||||||
|
|
||||||
|
return sitesRepo.findByDomain(domainOfSite).isPresent();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Transactional(Transactional.TxType.REQUIRED)
|
||||||
|
protected void deleteSite(final long siteId) {
|
||||||
|
|
||||||
|
final Site site = sitesRepo
|
||||||
|
.findById(siteId)
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Site with ID %d in the database.",
|
||||||
|
siteId)));
|
||||||
|
|
||||||
|
sitesRepo.delete(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
private SitesTableRow buildRow(final Site site) {
|
||||||
|
|
||||||
|
final SitesTableRow row = new SitesTableRow();
|
||||||
|
|
||||||
|
row.setSiteId(Long.toString(site.getObjectId()));
|
||||||
|
row.setDomainOfSite(site.getDomainOfSite());
|
||||||
|
row.setDefaultSite(site.isDefaultSite());
|
||||||
|
row.setDefaultTheme(site.getDefaultTheme());
|
||||||
|
row.setDeletable(site.getApplications().isEmpty());
|
||||||
|
|
||||||
|
final List<String> applications = site
|
||||||
|
.getApplications()
|
||||||
|
.stream()
|
||||||
|
.map(application -> application.getPrimaryUrl())
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
|
||||||
|
row.setApplications(applications);
|
||||||
|
|
||||||
|
return row;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,252 @@
|
||||||
|
/*
|
||||||
|
* 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.sites;
|
||||||
|
|
||||||
|
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.Text;
|
||||||
|
import com.arsdigita.bebop.event.FormInitListener;
|
||||||
|
import com.arsdigita.bebop.event.FormProcessListener;
|
||||||
|
import com.arsdigita.bebop.event.FormSectionEvent;
|
||||||
|
import com.arsdigita.bebop.event.FormValidationListener;
|
||||||
|
import com.arsdigita.bebop.form.CheckboxGroup;
|
||||||
|
import com.arsdigita.bebop.form.Option;
|
||||||
|
import com.arsdigita.bebop.form.SingleSelect;
|
||||||
|
import com.arsdigita.bebop.form.TextField;
|
||||||
|
import com.arsdigita.bebop.parameters.NotEmptyValidationListener;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
import org.libreccm.core.UnexpectedErrorException;
|
||||||
|
import org.libreccm.sites.Site;
|
||||||
|
import org.libreccm.sites.SiteRepository;
|
||||||
|
import org.libreccm.theming.ThemeInfo;
|
||||||
|
import org.libreccm.theming.Themes;
|
||||||
|
|
||||||
|
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>
|
||||||
|
*/
|
||||||
|
public class SitesForm extends Form {
|
||||||
|
|
||||||
|
private static final String DOMAIN_OF_SITE = "domainOfSite";
|
||||||
|
private static final String DEFAULT_SITE = "defaultSite";
|
||||||
|
private static final String THEME_SELECT = "themeSelect";
|
||||||
|
|
||||||
|
private final SitesTab sitesTab;
|
||||||
|
private final ParameterSingleSelectionModel<String> selectedSiteId;
|
||||||
|
|
||||||
|
private final TextField domainOfSiteField;
|
||||||
|
private final CheckboxGroup defaultSiteCheckbox;
|
||||||
|
private final SingleSelect defaultThemeSelect;
|
||||||
|
private final SaveCancelSection saveCancelSection;
|
||||||
|
|
||||||
|
public SitesForm(
|
||||||
|
final SitesTab sitesTab,
|
||||||
|
final ParameterSingleSelectionModel<String> selectedSiteId) {
|
||||||
|
|
||||||
|
super("sitesform");
|
||||||
|
|
||||||
|
this.sitesTab = sitesTab;
|
||||||
|
this.selectedSiteId = selectedSiteId;
|
||||||
|
|
||||||
|
final Label heading = new Label(event -> {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final Label target = (Label) event.getTarget();
|
||||||
|
|
||||||
|
final String selectedSiteIdStr = selectedSiteId
|
||||||
|
.getSelectedKey(state);
|
||||||
|
if (selectedSiteIdStr == null || selectedSiteIdStr.isEmpty()) {
|
||||||
|
target.setLabel(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.create_new",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
} else {
|
||||||
|
target.setLabel(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.edit",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
heading.setClassAttr("heading");
|
||||||
|
super.add(heading);
|
||||||
|
|
||||||
|
domainOfSiteField = new TextField(DOMAIN_OF_SITE);
|
||||||
|
domainOfSiteField.setLabel(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.domain_of_site",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
domainOfSiteField
|
||||||
|
.addValidationListener(new NotEmptyValidationListener());
|
||||||
|
super.add(domainOfSiteField);
|
||||||
|
|
||||||
|
defaultSiteCheckbox = new CheckboxGroup(DEFAULT_SITE);
|
||||||
|
defaultSiteCheckbox.addOption(new Option("isDefault",
|
||||||
|
new Label(
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.is_default_site",
|
||||||
|
ADMIN_BUNDLE))));
|
||||||
|
super.add(defaultSiteCheckbox);
|
||||||
|
|
||||||
|
defaultThemeSelect = new SingleSelect(THEME_SELECT);
|
||||||
|
try {
|
||||||
|
defaultThemeSelect.addPrintListener(event -> {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final Themes themes = cdiUtil.findBean(Themes.class);
|
||||||
|
|
||||||
|
final SingleSelect target = (SingleSelect) event.getTarget();
|
||||||
|
target.clearOptions();
|
||||||
|
|
||||||
|
final List<ThemeInfo> availableThemes = themes
|
||||||
|
.getAvailableThemes();
|
||||||
|
for (final ThemeInfo info : availableThemes) {
|
||||||
|
target.addOption(new Option(info.getName(),
|
||||||
|
new Text(info.getName())));
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
} catch (TooManyListenersException ex) {
|
||||||
|
throw new UnexpectedErrorException(ex);
|
||||||
|
}
|
||||||
|
super.add(defaultThemeSelect);
|
||||||
|
|
||||||
|
saveCancelSection = new SaveCancelSection();
|
||||||
|
super.add(saveCancelSection);
|
||||||
|
|
||||||
|
super.addValidationListener(new ValidationListener());
|
||||||
|
super.addInitListener(new InitListener());
|
||||||
|
super.addProcessListener(new ProcessListener());
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ValidationListener implements FormValidationListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void validate(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
|
||||||
|
final String domainOfSite = data.getString(DOMAIN_OF_SITE);
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SitesController controller = cdiUtil
|
||||||
|
.findBean(SitesController.class);
|
||||||
|
if (!controller.isUnique(domainOfSite)) {
|
||||||
|
data.addError(
|
||||||
|
DOMAIN_OF_SITE,
|
||||||
|
new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.domain_of_site.error.not:unique",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class InitListener implements FormInitListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
final String selectedSiteIdStr = selectedSiteId
|
||||||
|
.getSelectedKey(state);
|
||||||
|
|
||||||
|
if (selectedSiteIdStr != null && !selectedSiteIdStr.isEmpty()) {
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SiteRepository siteRepo = cdiUtil
|
||||||
|
.findBean(SiteRepository.class);
|
||||||
|
|
||||||
|
final Site site = siteRepo.findById(Long
|
||||||
|
.parseLong(selectedSiteIdStr))
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Site with ID %s in the database.",
|
||||||
|
selectedSiteIdStr)));
|
||||||
|
|
||||||
|
domainOfSiteField.setValue(state, site.getDomainOfSite());
|
||||||
|
defaultSiteCheckbox
|
||||||
|
.setValue(state, new Boolean[]{site.isDefaultSite()});
|
||||||
|
defaultThemeSelect.setValue(state, site.getDefaultTheme());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class ProcessListener implements FormProcessListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void process(final FormSectionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
|
||||||
|
if (saveCancelSection.getSaveButton().isSelected(state)) {
|
||||||
|
|
||||||
|
final FormData data = event.getFormData();
|
||||||
|
|
||||||
|
final String domainOfSite = data.getString(DOMAIN_OF_SITE);
|
||||||
|
final Boolean[] defaultSite = ((Boolean[]) data
|
||||||
|
.get(DEFAULT_SITE));
|
||||||
|
final String defaultTheme = data.getString(THEME_SELECT);
|
||||||
|
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SiteRepository siteRepo = cdiUtil
|
||||||
|
.findBean(SiteRepository.class);
|
||||||
|
|
||||||
|
final String selectedSiteIdStr = selectedSiteId
|
||||||
|
.getSelectedKey(state);
|
||||||
|
|
||||||
|
final Site site;
|
||||||
|
if (selectedSiteIdStr == null || selectedSiteIdStr.isEmpty()) {
|
||||||
|
site = new Site();
|
||||||
|
site.setDomainOfSite(domainOfSite);
|
||||||
|
site.setDefaultSite(defaultSite[0]);
|
||||||
|
site.setDefaultTheme(defaultTheme);
|
||||||
|
} else {
|
||||||
|
site = siteRepo
|
||||||
|
.findById(Long.parseLong(selectedSiteIdStr))
|
||||||
|
.orElseThrow(() -> new IllegalArgumentException(String
|
||||||
|
.format("No Site with ID %s in in the database.",
|
||||||
|
selectedSiteIdStr)));
|
||||||
|
}
|
||||||
|
siteRepo.save(site);
|
||||||
|
}
|
||||||
|
|
||||||
|
sitesTab.hideSiteForm(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -18,30 +18,72 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.ui.admin.sites;
|
package com.arsdigita.ui.admin.sites;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.ActionLink;
|
||||||
import com.arsdigita.bebop.BoxPanel;
|
import com.arsdigita.bebop.BoxPanel;
|
||||||
import com.arsdigita.bebop.Text;
|
import com.arsdigita.bebop.Page;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
|
import com.arsdigita.bebop.parameters.StringParameter;
|
||||||
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
import com.arsdigita.toolbox.ui.LayoutPanel;
|
||||||
|
|
||||||
|
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
*/
|
*/
|
||||||
public class SitesTab extends LayoutPanel {
|
public class SitesTab extends LayoutPanel {
|
||||||
|
|
||||||
|
private final ParameterSingleSelectionModel<String> selectedSiteId;
|
||||||
|
private final SitesTable sitesTable;
|
||||||
|
private final SitesForm sitesForm;
|
||||||
|
|
||||||
public SitesTab() {
|
public SitesTab() {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
super.setClassAttr("sidebarNavPanel");
|
super.setClassAttr("sidebarNavPanel");
|
||||||
|
|
||||||
final BoxPanel left = new BoxPanel(BoxPanel.VERTICAL);
|
final BoxPanel left = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
|
||||||
|
selectedSiteId = new ParameterSingleSelectionModel<>(
|
||||||
|
new StringParameter("selected_site_id"));
|
||||||
|
|
||||||
|
sitesTable = new SitesTable(this, selectedSiteId);
|
||||||
|
sitesForm = new SitesForm(this, selectedSiteId);
|
||||||
|
|
||||||
|
final ActionLink addNewSite = new ActionLink(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.add_new_site_link",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
|
||||||
final BoxPanel right = new BoxPanel(BoxPanel.VERTICAL);
|
final BoxPanel right = new BoxPanel(BoxPanel.VERTICAL);
|
||||||
|
right.add(addNewSite);
|
||||||
right.add(new Text("Sites placeholder"));
|
right.add(sitesTable);
|
||||||
|
right.add(sitesForm);
|
||||||
|
|
||||||
setLeft(left);
|
setLeft(left);
|
||||||
setRight(right);
|
setRight(right);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void register(final Page page) {
|
||||||
|
|
||||||
|
super.register(page);
|
||||||
|
|
||||||
|
page.addGlobalStateParam(selectedSiteId.getStateParameter());
|
||||||
|
|
||||||
|
page.setVisibleDefault(sitesTable, true);
|
||||||
|
page.setVisibleDefault(sitesForm, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void showSiteForm(final PageState state) {
|
||||||
|
sitesTable.setVisible(state, false);
|
||||||
|
sitesForm.setVisible(state, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void hideSiteForm(final PageState state) {
|
||||||
|
sitesTable.setVisible(state, true);
|
||||||
|
sitesForm.setVisible(state, false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -18,11 +18,28 @@
|
||||||
*/
|
*/
|
||||||
package com.arsdigita.ui.admin.sites;
|
package com.arsdigita.ui.admin.sites;
|
||||||
|
|
||||||
|
import com.arsdigita.bebop.Component;
|
||||||
|
import com.arsdigita.bebop.ControlLink;
|
||||||
|
import com.arsdigita.bebop.FormProcessException;
|
||||||
import com.arsdigita.bebop.Label;
|
import com.arsdigita.bebop.Label;
|
||||||
|
import com.arsdigita.bebop.PageState;
|
||||||
|
import com.arsdigita.bebop.ParameterSingleSelectionModel;
|
||||||
import com.arsdigita.bebop.Table;
|
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.TableColumn;
|
||||||
import com.arsdigita.bebop.table.TableColumnModel;
|
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.globalization.GlobalizedMessage;
|
||||||
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
|
|
||||||
|
|
@ -35,8 +52,12 @@ public class SitesTable extends Table {
|
||||||
public static final int COL_SITE_DOMAIN = 0;
|
public static final int COL_SITE_DOMAIN = 0;
|
||||||
public static final int COL_IS_DEFAULT_SITE = 1;
|
public static final int COL_IS_DEFAULT_SITE = 1;
|
||||||
public static final int COL_DEFAULT_THEME = 2;
|
public static final int COL_DEFAULT_THEME = 2;
|
||||||
|
public static final int COL_APPLICATIONS = 3;
|
||||||
|
public static final int COL_REMOVE = 4;
|
||||||
|
|
||||||
public SitesTable() {
|
public SitesTable(
|
||||||
|
final SitesTab parent,
|
||||||
|
final ParameterSingleSelectionModel<String> selectedSiteId) {
|
||||||
|
|
||||||
super();
|
super();
|
||||||
|
|
||||||
|
|
@ -49,15 +70,178 @@ public class SitesTable extends Table {
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
final TableColumnModel columnModel = getColumnModel();
|
||||||
columnModel.add(new TableColumn(
|
columnModel.add(new TableColumn(
|
||||||
COL_SITE_DOMAIN,
|
COL_SITE_DOMAIN,
|
||||||
new Label(new GlobalizedMessage("ui.admin.sites.table.domain"))));
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.domain.header"))));
|
||||||
columnModel.add(new TableColumn(
|
columnModel.add(new TableColumn(
|
||||||
COL_IS_DEFAULT_SITE,
|
COL_IS_DEFAULT_SITE,
|
||||||
new Label(new GlobalizedMessage("ui.admin.sites.table.default_site"))));
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.default_site.header"))));
|
||||||
columnModel.add(new TableColumn(
|
columnModel.add(new TableColumn(
|
||||||
COL_DEFAULT_THEME,
|
COL_DEFAULT_THEME,
|
||||||
new Label(new GlobalizedMessage("ui.admin.sites.table.default_theme"))));
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.default_theme.header"))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_APPLICATIONS,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.applications.header"))));
|
||||||
|
columnModel.add(new TableColumn(
|
||||||
|
COL_APPLICATIONS,
|
||||||
|
new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.delete.header"))));
|
||||||
|
|
||||||
|
columnModel
|
||||||
|
.get(COL_SITE_DOMAIN)
|
||||||
|
.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_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.sites.delete.confirm", ADMIN_BUNDLE));
|
||||||
|
return link;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
super.addTableActionListener(new TableActionListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void cellSelected(final TableActionEvent event)
|
||||||
|
throws FormProcessException {
|
||||||
|
|
||||||
|
final PageState state = event.getPageState();
|
||||||
|
final String key = (String) event.getRowKey();
|
||||||
|
|
||||||
|
switch (event.getColumn()) {
|
||||||
|
case COL_SITE_DOMAIN:
|
||||||
|
selectedSiteId.setSelectedKey(state, key);
|
||||||
|
parent.showSiteForm(state);
|
||||||
|
break;
|
||||||
|
case COL_REMOVE:
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SitesController controller = cdiUtil
|
||||||
|
.findBean(SitesController.class);
|
||||||
|
controller.deleteSite(Long.parseLong(key));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Invalid value for column.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void headSelected(final TableActionEvent event) {
|
||||||
|
|
||||||
|
//Nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
super.setModelBuilder(new SitesTableModelBuilder());
|
super.setModelBuilder(new SitesTableModelBuilder());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class SitesTableModelBuilder
|
||||||
|
extends LockableImpl
|
||||||
|
implements TableModelBuilder {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TableModel makeModel(final Table table,
|
||||||
|
final PageState state) {
|
||||||
|
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
||||||
|
final SitesController controller = cdiUtil
|
||||||
|
.findBean(SitesController.class);
|
||||||
|
return new SitesTableModel(controller.findSites());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private class SitesTableModel implements TableModel {
|
||||||
|
|
||||||
|
private final Iterator<SitesTableRow> iterator;
|
||||||
|
private SitesTableRow currentRow;
|
||||||
|
|
||||||
|
public SitesTableModel(final List<SitesTableRow> rows) {
|
||||||
|
iterator = rows.iterator();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getColumnCount() {
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean nextRow() {
|
||||||
|
if (iterator.hasNext()) {
|
||||||
|
currentRow = iterator.next();
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getElementAt(final int columnIndex) {
|
||||||
|
|
||||||
|
switch (columnIndex) {
|
||||||
|
case COL_SITE_DOMAIN:
|
||||||
|
return currentRow.getSiteId();
|
||||||
|
case COL_IS_DEFAULT_SITE:
|
||||||
|
return currentRow.isDefaultSite();
|
||||||
|
case COL_DEFAULT_THEME:
|
||||||
|
return currentRow.getDefaultTheme();
|
||||||
|
case COL_APPLICATIONS:
|
||||||
|
final String apps = String
|
||||||
|
.join(",\n",
|
||||||
|
currentRow
|
||||||
|
.getApplications()
|
||||||
|
.toArray(new String[]{}));
|
||||||
|
return new Label(apps, false);
|
||||||
|
case COL_REMOVE:
|
||||||
|
if (currentRow.isDeletable()) {
|
||||||
|
return new Label(new GlobalizedMessage(
|
||||||
|
"ui.admin.sites.table.columns.remove.label",
|
||||||
|
ADMIN_BUNDLE));
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
throw new IllegalArgumentException(
|
||||||
|
"Not a valid column index");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getKeyAt(final int columnIndex) {
|
||||||
|
return currentRow.getSiteId();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,80 +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.sites;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
|
||||||
import org.libreccm.sites.Site;
|
|
||||||
import org.libreccm.sites.SiteRepository;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class SitesTableModel implements TableModel {
|
|
||||||
|
|
||||||
private final Iterator<Site> iterator;
|
|
||||||
private Site current;
|
|
||||||
|
|
||||||
public SitesTableModel() {
|
|
||||||
|
|
||||||
final CdiUtil cdiUtil = CdiUtil.createCdiUtil();
|
|
||||||
final SiteRepository siteRepo = cdiUtil.findBean(SiteRepository.class);
|
|
||||||
iterator = siteRepo.findAll().iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getColumnCount() {
|
|
||||||
return 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean nextRow() {
|
|
||||||
if (iterator.hasNext()) {
|
|
||||||
current = iterator.next();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getElementAt(final int columnIndex) {
|
|
||||||
|
|
||||||
switch (columnIndex) {
|
|
||||||
case SitesTable.COL_SITE_DOMAIN:
|
|
||||||
return current.getDomainOfSite();
|
|
||||||
case SitesTable.COL_IS_DEFAULT_SITE:
|
|
||||||
return current.isDefaultSite();
|
|
||||||
case SitesTable.COL_DEFAULT_THEME:
|
|
||||||
return current.getDefaultTheme();
|
|
||||||
default:
|
|
||||||
throw new IllegalArgumentException("Illegal column index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object getKeyAt(final int columnIndex) {
|
|
||||||
return current.getObjectId();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,41 +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.sites;
|
|
||||||
|
|
||||||
import com.arsdigita.bebop.PageState;
|
|
||||||
import com.arsdigita.bebop.Table;
|
|
||||||
import com.arsdigita.bebop.table.TableModel;
|
|
||||||
import com.arsdigita.bebop.table.TableModelBuilder;
|
|
||||||
import com.arsdigita.util.LockableImpl;
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class SitesTableModelBuilder
|
|
||||||
extends LockableImpl
|
|
||||||
implements TableModelBuilder {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TableModel makeModel(final Table table, final PageState state) {
|
|
||||||
|
|
||||||
return new SitesTableModel();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,102 @@
|
||||||
|
/*
|
||||||
|
* 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.sites;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
||||||
|
*/
|
||||||
|
class SitesTableRow implements Serializable {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -8913595737414248135L;
|
||||||
|
|
||||||
|
private String siteId;
|
||||||
|
|
||||||
|
private String domainOfSite;
|
||||||
|
|
||||||
|
private boolean defaultSite;
|
||||||
|
|
||||||
|
private String defaultTheme;
|
||||||
|
|
||||||
|
private boolean deletable;
|
||||||
|
|
||||||
|
private List<String> applications;
|
||||||
|
|
||||||
|
protected SitesTableRow() {
|
||||||
|
applications = new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSiteId() {
|
||||||
|
return siteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSiteId(final String siteId) {
|
||||||
|
this.siteId = siteId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDomainOfSite() {
|
||||||
|
return domainOfSite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDomainOfSite(final String domainOfSite) {
|
||||||
|
this.domainOfSite = domainOfSite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultSite() {
|
||||||
|
return defaultSite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultSite(final boolean defaultSite) {
|
||||||
|
this.defaultSite = defaultSite;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDefaultTheme() {
|
||||||
|
return defaultTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDefaultTheme(final String defaultTheme) {
|
||||||
|
this.defaultTheme = defaultTheme;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDeletable() {
|
||||||
|
return deletable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeletable(final boolean deletable) {
|
||||||
|
this.deletable = deletable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getApplications() {
|
||||||
|
return Collections.unmodifiableList(applications);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setApplications(final List<String> applications) {
|
||||||
|
this.applications = new ArrayList<>(applications);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void addApplication(final String application) {
|
||||||
|
applications.add(application);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -34,7 +34,6 @@ import com.arsdigita.bebop.table.TableModelBuilder;
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
import com.arsdigita.globalization.GlobalizedMessage;
|
||||||
import com.arsdigita.util.LockableImpl;
|
import com.arsdigita.util.LockableImpl;
|
||||||
|
|
||||||
import org.libreccm.admin.ui.UsersGroupsRolesTab;
|
|
||||||
import org.libreccm.cdi.utils.CdiUtil;
|
import org.libreccm.cdi.utils.CdiUtil;
|
||||||
import org.libreccm.security.Group;
|
import org.libreccm.security.Group;
|
||||||
import org.libreccm.security.Party;
|
import org.libreccm.security.Party;
|
||||||
|
|
@ -44,7 +43,6 @@ import org.libreccm.security.RoleManager;
|
||||||
import org.libreccm.security.RoleRepository;
|
import org.libreccm.security.RoleRepository;
|
||||||
import org.libreccm.security.User;
|
import org.libreccm.security.User;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue