Removed depcrecated package com.arsdigita.ui.admin.sites from ccm-core
parent
8d7cbea03b
commit
b92a41b85f
|
|
@ -1,110 +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 org.libreccm.sites.Site;
|
|
||||||
import org.libreccm.sites.SiteRepository;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import javax.enterprise.context.RequestScoped;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.transaction.Transactional;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Controller for the Admin UI for {@link Site}s.
|
|
||||||
*
|
|
||||||
* @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;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Find all sites and transform into {@link SitesTableRow} objects. Also takes
|
|
||||||
* care of loading are required lazily fetched properties.
|
|
||||||
*
|
|
||||||
* @return A list with the data about all available {@link Site}s.
|
|
||||||
*/
|
|
||||||
@Transactional(Transactional.TxType.REQUIRED)
|
|
||||||
protected List<SitesTableRow> findSites() {
|
|
||||||
|
|
||||||
return sitesRepo
|
|
||||||
.findAll()
|
|
||||||
.stream()
|
|
||||||
.map(this::buildRow)
|
|
||||||
.sorted()
|
|
||||||
.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,295 +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.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.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.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form for editing/creating a {@link Site}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
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 static final String IS_DEFAULT = "isDefault";
|
|
||||||
|
|
||||||
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));
|
|
||||||
super.add(domainOfSiteField);
|
|
||||||
|
|
||||||
defaultSiteCheckbox = new CheckboxGroup(DEFAULT_SITE);
|
|
||||||
defaultSiteCheckbox
|
|
||||||
.addOption(new Option(IS_DEFAULT,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.is_default_site",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
super.add(defaultSiteCheckbox);
|
|
||||||
|
|
||||||
defaultThemeSelect = new SingleSelect(THEME_SELECT);
|
|
||||||
defaultThemeSelect.setLabel(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.default_theme",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
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 String selectedSiteIdStr = selectedSiteId
|
|
||||||
.getSelectedKey(state);
|
|
||||||
final boolean domainEditedOrNewSite;
|
|
||||||
|
|
||||||
if (selectedSiteIdStr == null || selectedSiteIdStr.isEmpty()) {
|
|
||||||
domainEditedOrNewSite = true;
|
|
||||||
} else {
|
|
||||||
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 in the database.",
|
|
||||||
selectedSiteIdStr)));
|
|
||||||
|
|
||||||
domainEditedOrNewSite = !site
|
|
||||||
.getDomainOfSite()
|
|
||||||
.equals(domainOfSite);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (domainEditedOrNewSite) {
|
|
||||||
if (domainOfSite == null
|
|
||||||
|| domainOfSite.isEmpty()
|
|
||||||
|| domainOfSite.matches("\\s*")) {
|
|
||||||
|
|
||||||
data.addError(
|
|
||||||
DOMAIN_OF_SITE,
|
|
||||||
new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.domain_of_site.error.empty",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
}
|
|
||||||
|
|
||||||
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());
|
|
||||||
if (site.isDefaultSite()) {
|
|
||||||
defaultSiteCheckbox.setValue(state,
|
|
||||||
new String[]{IS_DEFAULT});
|
|
||||||
}
|
|
||||||
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 String[] defaultSite = ((String[]) 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();
|
|
||||||
} else {
|
|
||||||
site = siteRepo
|
|
||||||
.findById(Long.parseLong(selectedSiteIdStr))
|
|
||||||
.orElseThrow(() -> new IllegalArgumentException(String
|
|
||||||
.format("No Site with ID %s in in the database.",
|
|
||||||
selectedSiteIdStr)));
|
|
||||||
}
|
|
||||||
site.setDomainOfSite(domainOfSite);
|
|
||||||
if (defaultSite == null || defaultSite.length == 0) {
|
|
||||||
site.setDefaultSite(false);
|
|
||||||
} else {
|
|
||||||
site.setDefaultSite(defaultSite[0].equals(IS_DEFAULT));
|
|
||||||
}
|
|
||||||
site.setDefaultTheme(defaultTheme);
|
|
||||||
siteRepo.save(site);
|
|
||||||
}
|
|
||||||
|
|
||||||
selectedSiteId.clearSelection(state);
|
|
||||||
sitesTab.hideSiteForm(state);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,98 +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.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.parameters.StringParameter;
|
|
||||||
import com.arsdigita.globalization.GlobalizedMessage;
|
|
||||||
import com.arsdigita.toolbox.ui.LayoutPanel;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tab for {@code /ccm/admin} containing the Admin UI for {@link Site}s.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
public class SitesTab extends LayoutPanel {
|
|
||||||
|
|
||||||
private final ParameterSingleSelectionModel<String> selectedSiteId;
|
|
||||||
private final ActionLink addNewSite;
|
|
||||||
private final SitesTable sitesTable;
|
|
||||||
private final SitesForm sitesForm;
|
|
||||||
|
|
||||||
public SitesTab() {
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.setClassAttr("sidebarNavPanel");
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
addNewSite = new ActionLink(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.add_new_site_link",
|
|
||||||
ADMIN_BUNDLE));
|
|
||||||
addNewSite
|
|
||||||
.addActionListener(event -> {
|
|
||||||
showSiteForm(event.getPageState());
|
|
||||||
});
|
|
||||||
|
|
||||||
final BoxPanel right = new BoxPanel(BoxPanel.VERTICAL);
|
|
||||||
right.add(addNewSite);
|
|
||||||
right.add(sitesTable);
|
|
||||||
right.add(sitesForm);
|
|
||||||
|
|
||||||
setLeft(left);
|
|
||||||
setRight(right);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void register(final Page page) {
|
|
||||||
|
|
||||||
super.register(page);
|
|
||||||
|
|
||||||
page.addGlobalStateParam(selectedSiteId.getStateParameter());
|
|
||||||
|
|
||||||
page.setVisibleDefault(addNewSite, true);
|
|
||||||
page.setVisibleDefault(sitesTable, true);
|
|
||||||
page.setVisibleDefault(sitesForm, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void showSiteForm(final PageState state) {
|
|
||||||
addNewSite.setVisible(state, false);
|
|
||||||
sitesTable.setVisible(state, false);
|
|
||||||
sitesForm.setVisible(state, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void hideSiteForm(final PageState state) {
|
|
||||||
addNewSite.setVisible(state, true);
|
|
||||||
sitesTable.setVisible(state, true);
|
|
||||||
sitesForm.setVisible(state, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
@ -1,254 +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.Component;
|
|
||||||
import com.arsdigita.bebop.ControlLink;
|
|
||||||
import com.arsdigita.bebop.FormProcessException;
|
|
||||||
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.cdi.utils.CdiUtil;
|
|
||||||
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import static com.arsdigita.ui.admin.AdminUiConstants.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Table which displays data about all available {@link Site}s and provides
|
|
||||||
* links for editing and deleting them.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class SitesTable extends Table {
|
|
||||||
|
|
||||||
public static final int COL_SITE_DOMAIN = 0;
|
|
||||||
public static final int COL_IS_DEFAULT_SITE = 1;
|
|
||||||
public static final int COL_DEFAULT_THEME = 2;
|
|
||||||
public static final int COL_APPLICATIONS = 3;
|
|
||||||
public static final int COL_REMOVE = 4;
|
|
||||||
|
|
||||||
public SitesTable(
|
|
||||||
final SitesTab parent,
|
|
||||||
final ParameterSingleSelectionModel<String> selectedSiteId) {
|
|
||||||
|
|
||||||
super();
|
|
||||||
|
|
||||||
super.setIdAttr("sitesTable");
|
|
||||||
super.setStyleAttr("width: 30em");
|
|
||||||
|
|
||||||
setEmptyView(new Label(new GlobalizedMessage("ui.admin.sites.no_sites",
|
|
||||||
ADMIN_BUNDLE)));
|
|
||||||
|
|
||||||
final TableColumnModel columnModel = getColumnModel();
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_SITE_DOMAIN,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.table.columns.domain.header",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_IS_DEFAULT_SITE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.table.columns.default_site.header",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_DEFAULT_THEME,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.table.columns.default_theme.header",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_APPLICATIONS,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.table.columns.applications.header",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
columnModel.add(new TableColumn(
|
|
||||||
COL_REMOVE,
|
|
||||||
new Label(new GlobalizedMessage(
|
|
||||||
"ui.admin.sites.table.columns.delete.header",
|
|
||||||
ADMIN_BUNDLE))));
|
|
||||||
|
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
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.getDomainOfSite();
|
|
||||||
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,108 +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 java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains all data for one row of the {@link SitesTable}.
|
|
||||||
*
|
|
||||||
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
|
|
||||||
*/
|
|
||||||
class SitesTableRow implements Comparable<SitesTableRow>, 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(final SitesTableRow other) {
|
|
||||||
return domainOfSite.compareTo(other.getDomainOfSite());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue