CCM NG: Forms for editing categories for /ccm/admin
git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4082 8810af33-2d31-482b-a856-94f89814c4dfpull/2/head
parent
c6746eb5e9
commit
1111e644c1
|
|
@ -44,8 +44,12 @@ public class CategoriesTab extends LayoutPanel {
|
|||
protected static final String DOMAINS_FILTER = "domainsFilter";
|
||||
|
||||
private final StringParameter domainIdParameter;
|
||||
private final StringParameter languageParameter;
|
||||
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;
|
||||
|
|
@ -67,12 +71,16 @@ public class CategoriesTab extends LayoutPanel {
|
|||
setClassAttr("sidebarNavPanel");
|
||||
|
||||
domainIdParameter = new StringParameter("selected_domain_id");
|
||||
selectedDomainId
|
||||
= new ParameterSingleSelectionModel<>(domainIdParameter);
|
||||
selectedDomainId = new ParameterSingleSelectionModel<>(
|
||||
domainIdParameter);
|
||||
|
||||
categoryIdParameter = new StringParameter("selected_category_id");
|
||||
selectedCategoryId = new ParameterSingleSelectionModel<>(
|
||||
categoryIdParameter);
|
||||
|
||||
languageParameter = new StringParameter("selected_language");
|
||||
selectedLanguage
|
||||
= new ParameterSingleSelectionModel<>(languageParameter);
|
||||
selectedLanguage = new ParameterSingleSelectionModel<>(
|
||||
languageParameter);
|
||||
|
||||
final SegmentedPanel left = new SegmentedPanel();
|
||||
|
||||
|
|
@ -104,7 +112,7 @@ public class CategoriesTab extends LayoutPanel {
|
|||
|
||||
});
|
||||
final ActionLink backToDomain = new ActionLink(new GlobalizedMessage(
|
||||
"ui.admin.categories.tree.back",
|
||||
"ui.admin.categories.tree.back",
|
||||
ADMIN_BUNDLE));
|
||||
backToDomain.addActionListener(e -> {
|
||||
final PageState state = e.getPageState();
|
||||
|
|
@ -160,6 +168,7 @@ public class CategoriesTab extends LayoutPanel {
|
|||
super.register(page);
|
||||
|
||||
page.addGlobalStateParam(domainIdParameter);
|
||||
page.addGlobalStateParam(categoryIdParameter);
|
||||
page.addGlobalStateParam(languageParameter);
|
||||
|
||||
page.setVisibleDefault(domainsFilterFormHeader, true);
|
||||
|
|
@ -277,4 +286,42 @@ public class CategoriesTab extends LayoutPanel {
|
|||
showDomainDetails(state);
|
||||
}
|
||||
|
||||
protected void showCategoryDetails(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void hideCategoryDetails(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void showCategoryCreateForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void hideCategoryCreateForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void showCategoryEditForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void hideCategoryEditForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void showCategoryTitleForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void hideCategoryTitleForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void showCategoryDescriptionForm(final PageState state) {
|
||||
|
||||
}
|
||||
|
||||
protected void hideCategoryDescriptionForm(final PageState state) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,175 @@
|
|||
/*
|
||||
* 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.categorization.Domain;
|
||||
import org.libreccm.categorization.DomainRepository;
|
||||
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)));
|
||||
|
||||
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.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.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 CategoryRepository categoryRepository = CdiUtil.
|
||||
createCdiUtil().findBean(CategoryRepository.class);
|
||||
final Category selectedCategory = categoryRepository.findById(
|
||||
Long.parseLong(selectedCategoryId.getSelectedKey(state)));
|
||||
|
||||
final Locale selectedLocale = new Locale(selectedLanguage
|
||||
.getSelectedKey(state));
|
||||
|
||||
if (selectedCategory.getTitle().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)));
|
||||
|
||||
final Locale selectedLocale = new Locale(selectedLanguage
|
||||
.getSelectedKey(state));
|
||||
|
||||
final String titleData = e.getFormData().getString(
|
||||
LOCALIZED_CATEGORY_DESC);
|
||||
|
||||
selectedCategory.getDescription().addValue(selectedLocale,
|
||||
titleData);
|
||||
categoryRepository.save(selectedCategory);
|
||||
}
|
||||
|
||||
categoriesTab.hideCategoryDescriptionForm(state);
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
/*
|
||||
* 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_del",
|
||||
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)));
|
||||
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)));
|
||||
|
||||
locales = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,293 @@
|
|||
/*
|
||||
* 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;
|
||||
|
||||
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 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);
|
||||
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,
|
||||
selectedDomainId,
|
||||
selectedLanguage));
|
||||
categoryTitleAddForm = new CategoryTitleAddForm();
|
||||
titlesPanel.add(categoryTitleAddForm);
|
||||
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 CategoryDescriptionTable(categoriesTab,
|
||||
selectedCategoryId,
|
||||
selectedLanguage));
|
||||
categoryDescriptionAddForm = new CategoryDescriptionAddForm();
|
||||
descPanel.add(categoryDescriptionAddForm);
|
||||
addSegment(
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.category_details.description",
|
||||
ADMIN_BUNDLE)),
|
||||
descPanel);
|
||||
}
|
||||
|
||||
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)));
|
||||
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)));
|
||||
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)));
|
||||
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)));
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,92 @@
|
|||
/*
|
||||
* 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
|
||||
}
|
||||
|
||||
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();
|
||||
default:
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,67 @@
|
|||
/*
|
||||
* 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.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 (Strings.isBlank(categoryIdStr)) {
|
||||
selectedCategory = null;
|
||||
} else {
|
||||
final CategoryRepository categoryRepository = CdiUtil.
|
||||
createCdiUtil().findBean(CategoryRepository.class);
|
||||
selectedCategory = categoryRepository.findById(Long.parseLong(
|
||||
categoryIdStr));
|
||||
}
|
||||
|
||||
return new CategoryPropertySheetModel(selectedCategory);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,166 @@
|
|||
/*
|
||||
* 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)));
|
||||
|
||||
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)));
|
||||
|
||||
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)));
|
||||
|
||||
final Locale selectedLocale = new Locale(selectedLanguage
|
||||
.getSelectedKey(state));
|
||||
|
||||
final String titleData = e.getFormData().getString(
|
||||
LOCALIZED_CATEGORY_TITLE);
|
||||
|
||||
selectedCategory.getTitle().addValue(selectedLocale, titleData);
|
||||
categoryRepository.save(selectedCategory);
|
||||
}
|
||||
|
||||
categoriesTab.hideCategoryTitleForm(state);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,250 @@
|
|||
/*
|
||||
* 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)));
|
||||
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)));
|
||||
|
||||
locales = new ArrayList<>();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -53,16 +53,17 @@ class DomainDescriptionTable extends Table {
|
|||
|
||||
private static final int COL_LOCALE = 0;
|
||||
private static final int COL_VALUE = 1;
|
||||
private static final int COL_DEL = 2;
|
||||
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) {
|
||||
final CategoriesTab categoriesTab,
|
||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
||||
|
||||
super();
|
||||
|
||||
|
|
@ -73,27 +74,32 @@ class DomainDescriptionTable extends Table {
|
|||
setIdAttr("domainDescriptionTable");
|
||||
|
||||
setEmptyView(new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description.none",
|
||||
ADMIN_BUNDLE)));
|
||||
"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))));
|
||||
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))));
|
||||
COL_VALUE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description.col_value",
|
||||
ADMIN_BUNDLE))));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_DEL,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description.col_del",
|
||||
ADMIN_BUNDLE))));
|
||||
COL_EDIT,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description.col_del",
|
||||
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_LOCALE).setCellRenderer(new TableCellRenderer() {
|
||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
|
|
@ -103,7 +109,7 @@ class DomainDescriptionTable extends Table {
|
|||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
return new ControlLink((String) value);
|
||||
return new ControlLink((Component) value);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -123,9 +129,9 @@ class DomainDescriptionTable extends Table {
|
|||
} else {
|
||||
final ControlLink link = new ControlLink((Component) value);
|
||||
link.setConfirmation(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description"
|
||||
+ ".del_confirm",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_details.description"
|
||||
+ ".del_confirm",
|
||||
ADMIN_BUNDLE));
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
|
@ -139,19 +145,20 @@ class DomainDescriptionTable extends Table {
|
|||
final PageState state = event.getPageState();
|
||||
|
||||
switch (event.getColumn()) {
|
||||
case COL_LOCALE:
|
||||
case COL_EDIT:
|
||||
selectedLanguage.setSelectedKey(state,
|
||||
event.getRowKey());
|
||||
categoriesTab.showDomainDescriptionForm(state);
|
||||
break;
|
||||
case COL_DEL:
|
||||
final Locale locale = new Locale((String) event
|
||||
.getRowKey());
|
||||
.getRowKey());
|
||||
final DomainRepository domainRepository = CdiUtil
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
.createCdiUtil().
|
||||
findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(
|
||||
Long.parseLong(selectedDomainId
|
||||
.getSelectedKey(state)));
|
||||
Long.parseLong(selectedDomainId
|
||||
.getSelectedKey(state)));
|
||||
domain.getDescription().removeValue(locale);
|
||||
|
||||
domainRepository.save(domain);
|
||||
|
|
@ -172,8 +179,8 @@ class DomainDescriptionTable extends Table {
|
|||
}
|
||||
|
||||
private class DomainDescriptionTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table,
|
||||
|
|
@ -193,13 +200,13 @@ class DomainDescriptionTable extends Table {
|
|||
|
||||
public DomainDescriptionTableModel(final PageState state) {
|
||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
||||
.findBean(DomainRepository.class);
|
||||
.findBean(DomainRepository.class);
|
||||
selectedDomain = domainRepository.findById(
|
||||
Long.parseLong(selectedDomainId.getSelectedKey(state)));
|
||||
Long.parseLong(selectedDomainId.getSelectedKey(state)));
|
||||
|
||||
locales = new ArrayList<>();
|
||||
locales.addAll(selectedDomain.getDescription()
|
||||
.getAvailableLocales());
|
||||
.getAvailableLocales());
|
||||
locales.sort((l1, l2) -> {
|
||||
return l1.toString().compareTo(l2.toString());
|
||||
});
|
||||
|
|
@ -207,7 +214,7 @@ class DomainDescriptionTable extends Table {
|
|||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -225,13 +232,17 @@ class DomainDescriptionTable extends Table {
|
|||
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));
|
||||
"ui.admin.categories.domain_details.description.del",
|
||||
ADMIN_BUNDLE));
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Not a valid column index");
|
||||
"Not a valid column index");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -58,16 +58,16 @@ class DomainDetails extends SegmentedPanel {
|
|||
private final DomainDescriptionAddForm domainDescriptionAddForm;
|
||||
|
||||
public DomainDetails(
|
||||
final CategoriesTab categoriesTab,
|
||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
||||
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));
|
||||
"ui.admin.categories.domain_details.back", ADMIN_BUNDLE));
|
||||
backLink.addActionListener(e -> {
|
||||
final PageState state = e.getPageState();
|
||||
categoriesTab.hideDomainDetails(state);
|
||||
|
|
@ -76,21 +76,21 @@ class DomainDetails extends SegmentedPanel {
|
|||
|
||||
final BoxPanel propertiesPanel = new BoxPanel(BoxPanel.VERTICAL);
|
||||
propertiesPanel.add(new PropertySheet(
|
||||
new DomainPropertySheetModelBuilder(selectedDomainId)));
|
||||
new DomainPropertySheetModelBuilder(selectedDomainId)));
|
||||
final ActionLink editBasicPropertiesLink = new ActionLink(
|
||||
new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.basic_properties.edit",
|
||||
ADMIN_BUNDLE));
|
||||
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);
|
||||
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,
|
||||
|
|
@ -99,10 +99,10 @@ class DomainDetails extends SegmentedPanel {
|
|||
domainTitleAddForm = new DomainTitleAddForm();
|
||||
titlesPanel.add(domainTitleAddForm);
|
||||
addSegment(
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.domain_title",
|
||||
ADMIN_BUNDLE)),
|
||||
titlesPanel);
|
||||
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,
|
||||
|
|
@ -111,20 +111,20 @@ class DomainDetails extends SegmentedPanel {
|
|||
domainDescriptionAddForm = new DomainDescriptionAddForm();
|
||||
descPanel.add(domainDescriptionAddForm);
|
||||
addSegment(
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.description",
|
||||
ADMIN_BUNDLE)),
|
||||
descPanel);
|
||||
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);
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.mappings",
|
||||
ADMIN_BUNDLE)),
|
||||
mappingsPanel);
|
||||
}
|
||||
|
||||
private class DomainTitleAddForm extends Form {
|
||||
|
|
@ -135,22 +135,21 @@ class DomainDetails extends SegmentedPanel {
|
|||
super("domainAddTitleLang", new BoxPanel(BoxPanel.HORIZONTAL));
|
||||
|
||||
final SingleSelect titleSelectLang = new SingleSelect(
|
||||
TITLE_SELECT_LANG);
|
||||
TITLE_SELECT_LANG);
|
||||
titleSelectLang.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.domain_title.add.label",
|
||||
ADMIN_BUNDLE));
|
||||
"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);
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(Long
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
.parseLong(selectedDomainId.getSelectedKey(state)));
|
||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||
final Set<String> supportedLanguages = kernelConfig
|
||||
.getSupportedLanguages();
|
||||
.getSupportedLanguages();
|
||||
final Set<String> assignedLanguages = new HashSet<>();
|
||||
domain.getTitle().getAvailableLocales().forEach(l -> {
|
||||
assignedLanguages.add(l.toString());
|
||||
|
|
@ -172,8 +171,8 @@ class DomainDetails extends SegmentedPanel {
|
|||
|
||||
add(titleSelectLang);
|
||||
add(new Submit(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.domain_title.add.submit",
|
||||
ADMIN_BUNDLE)));
|
||||
"ui.admin.categories.domain_details.domain_title.add.submit",
|
||||
ADMIN_BUNDLE)));
|
||||
|
||||
addProcessListener(e -> {
|
||||
final PageState state = e.getPageState();
|
||||
|
|
@ -189,15 +188,14 @@ class DomainDetails extends SegmentedPanel {
|
|||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
if (super.isVisible(state)) {
|
||||
|
||||
final DomainRepository domainRepository = CdiUtil
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(Long
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||
final Set<String> supportedLanguages = kernelConfig
|
||||
.getSupportedLanguages();
|
||||
.getSupportedLanguages();
|
||||
final Set<String> assignedLanguages = new HashSet<>();
|
||||
domain.getTitle().getAvailableLocales().forEach(l -> {
|
||||
assignedLanguages.add(l.toString());
|
||||
|
|
@ -206,7 +204,6 @@ class DomainDetails extends SegmentedPanel {
|
|||
//If all supported languages are assigned the form is not
|
||||
//visible
|
||||
return !assignedLanguages.equals(supportedLanguages);
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -222,22 +219,22 @@ class DomainDetails extends SegmentedPanel {
|
|||
super("domainAddDescLang", new BoxPanel(BoxPanel.HORIZONTAL));
|
||||
|
||||
final SingleSelect descSelectLang = new SingleSelect(
|
||||
DESC_SELECT_LANG);
|
||||
DESC_SELECT_LANG);
|
||||
descSelectLang.setLabel(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.domain_desc.add.label",
|
||||
ADMIN_BUNDLE));
|
||||
"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);
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(Long
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||
final Set<String> supportedLanguages = kernelConfig
|
||||
.getSupportedLanguages();
|
||||
.getSupportedLanguages();
|
||||
final Set<String> assignedLanguages = new HashSet<>();
|
||||
domain.getDescription().getAvailableLocales().forEach(l -> {
|
||||
assignedLanguages.add(l.toString());
|
||||
|
|
@ -259,8 +256,8 @@ class DomainDetails extends SegmentedPanel {
|
|||
|
||||
add(descSelectLang);
|
||||
add(new Submit(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.domain_desc.add.submit",
|
||||
ADMIN_BUNDLE)));
|
||||
"ui.admin.categories.domain_details.domain_desc.add.submit",
|
||||
ADMIN_BUNDLE)));
|
||||
|
||||
addProcessListener(e -> {
|
||||
final PageState state = e.getPageState();
|
||||
|
|
@ -273,19 +270,18 @@ class DomainDetails extends SegmentedPanel {
|
|||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isVisible(final PageState state) {
|
||||
if (super.isVisible(state)) {
|
||||
|
||||
final DomainRepository domainRepository = CdiUtil
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(Long
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
.parseLong(
|
||||
selectedDomainId.getSelectedKey(state)));
|
||||
final KernelConfig kernelConfig = KernelConfig.getConfig();
|
||||
final Set<String> supportedLanguages = kernelConfig
|
||||
.getSupportedLanguages();
|
||||
.getSupportedLanguages();
|
||||
final Set<String> assignedLanguages = new HashSet<>();
|
||||
domain.getDescription().getAvailableLocales().forEach(l -> {
|
||||
assignedLanguages.add(l.toString());
|
||||
|
|
|
|||
|
|
@ -53,16 +53,17 @@ class DomainTitleTable extends Table {
|
|||
|
||||
private static final int COL_LOCALE = 0;
|
||||
private static final int COL_VALUE = 1;
|
||||
private static final int COL_DEL = 2;
|
||||
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) {
|
||||
final CategoriesTab categoriesTab,
|
||||
final ParameterSingleSelectionModel<String> selectedDomainId,
|
||||
final ParameterSingleSelectionModel<String> selectedLanguage) {
|
||||
|
||||
super();
|
||||
|
||||
|
|
@ -73,26 +74,31 @@ class DomainTitleTable extends Table {
|
|||
setIdAttr("domainTitleTable");
|
||||
|
||||
setEmptyView(new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.title.none", ADMIN_BUNDLE)));
|
||||
"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))));
|
||||
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))));
|
||||
COL_VALUE,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.title.col_value",
|
||||
ADMIN_BUNDLE))));
|
||||
columnModel.add(new TableColumn(
|
||||
COL_DEL,
|
||||
new Label(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.title.col_del",
|
||||
ADMIN_BUNDLE))));
|
||||
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_LOCALE).setCellRenderer(new TableCellRenderer() {
|
||||
columnModel.get(COL_EDIT).setCellRenderer(new TableCellRenderer() {
|
||||
|
||||
@Override
|
||||
public Component getComponent(final Table table,
|
||||
|
|
@ -102,7 +108,7 @@ class DomainTitleTable extends Table {
|
|||
final Object key,
|
||||
final int row,
|
||||
final int column) {
|
||||
return new ControlLink((String) value);
|
||||
return new ControlLink((Component) value);
|
||||
}
|
||||
|
||||
});
|
||||
|
|
@ -122,8 +128,8 @@ class DomainTitleTable extends Table {
|
|||
} else {
|
||||
final ControlLink link = new ControlLink((Component) value);
|
||||
link.setConfirmation(new GlobalizedMessage(
|
||||
"ui.admin.categories.domain_details.title.del_confirm",
|
||||
ADMIN_BUNDLE));
|
||||
"ui.admin.categories.domain_details.title.del_confirm",
|
||||
ADMIN_BUNDLE));
|
||||
return link;
|
||||
}
|
||||
}
|
||||
|
|
@ -137,23 +143,24 @@ class DomainTitleTable extends Table {
|
|||
final PageState state = event.getPageState();
|
||||
|
||||
switch (event.getColumn()) {
|
||||
case COL_LOCALE:
|
||||
case COL_EDIT:
|
||||
selectedLanguage.setSelectedKey(state,
|
||||
event.getRowKey());
|
||||
categoriesTab.showDomainTitleForm(state);
|
||||
break;
|
||||
case COL_DEL:
|
||||
final Locale locale = new Locale((String) event
|
||||
.getRowKey());
|
||||
.getRowKey());
|
||||
final DomainRepository domainRepository = CdiUtil
|
||||
.createCdiUtil().findBean(DomainRepository.class);
|
||||
.createCdiUtil().
|
||||
findBean(DomainRepository.class);
|
||||
final Domain domain = domainRepository.findById(
|
||||
Long.parseLong(selectedDomainId
|
||||
.getSelectedKey(state)));
|
||||
Long.parseLong(selectedDomainId
|
||||
.getSelectedKey(state)));
|
||||
domain.getTitle().removeValue(locale);
|
||||
|
||||
|
||||
domainRepository.save(domain);
|
||||
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -169,8 +176,8 @@ class DomainTitleTable extends Table {
|
|||
}
|
||||
|
||||
private class DomainTitleTableModelBuilder
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
extends LockableImpl
|
||||
implements TableModelBuilder {
|
||||
|
||||
@Override
|
||||
public TableModel makeModel(final Table table, final PageState state) {
|
||||
|
|
@ -189,9 +196,9 @@ class DomainTitleTable extends Table {
|
|||
|
||||
public DomainTitleTableModel(final PageState state) {
|
||||
final DomainRepository domainRepository = CdiUtil.createCdiUtil()
|
||||
.findBean(DomainRepository.class);
|
||||
.findBean(DomainRepository.class);
|
||||
selectedDomain = domainRepository.findById(
|
||||
Long.parseLong(selectedDomainId.getSelectedKey(state)));
|
||||
Long.parseLong(selectedDomainId.getSelectedKey(state)));
|
||||
|
||||
locales = new ArrayList<>();
|
||||
locales.addAll(selectedDomain.getTitle().getAvailableLocales());
|
||||
|
|
@ -202,7 +209,7 @@ class DomainTitleTable extends Table {
|
|||
|
||||
@Override
|
||||
public int getColumnCount() {
|
||||
return 3;
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -214,20 +221,25 @@ class DomainTitleTable extends Table {
|
|||
@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
|
||||
"ui.admin.categories.domain_details.title.del",
|
||||
ADMIN_BUNDLE
|
||||
));
|
||||
default:
|
||||
throw new IllegalArgumentException(
|
||||
"Not a valid column index");
|
||||
"Not a valid column index");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue