diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java deleted file mode 100644 index a3bbe5b79..000000000 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKit.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.librecms.contenttypes; - - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * - * @author Jens Pelzetter - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Deprecated -public @interface AuthoringKit { - - Class createComponent(); - - AuthoringStep[] steps(); - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKitInfo.java b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKitInfo.java deleted file mode 100644 index 7b9ca9f7a..000000000 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringKitInfo.java +++ /dev/null @@ -1,129 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.librecms.contenttypes; - - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Objects; - -/** - * Encapsulates the informations about an authoring kit. - * - * @author Jens Pelzetter - */ -public class AuthoringKitInfo { - - /** - * The create component (the form used to collect the mandatory data for the - * content type). - */ - private Class createComponent; - - /** - * The authoring steps of the authoring kit. - */ - private List authoringSteps; - - protected AuthoringKitInfo() { - authoringSteps = new ArrayList<>(); - } - - public Class getCreateComponent() { - return createComponent; - } - - public void setCreateComponent( - final Class createComponent) { - - this.createComponent = createComponent; - } - - public List getAuthoringSteps() { - if (authoringSteps == null) { - return null; - } else { - return Collections.unmodifiableList(authoringSteps); - } - } - - protected void setAuthoringSteps( - final List authoringSteps) { - this.authoringSteps = authoringSteps; - } - - protected void addAuthoringStep(final AuthoringStepInfo authoringStep) { - authoringSteps.add(authoringStep); - } - - protected void removeAuthoringStep(final AuthoringStepInfo authoringStep) { - authoringSteps.remove(authoringStep); - } - - @Override - public int hashCode() { - int hash = 3; - hash = 59 * hash + Objects.hashCode(createComponent); - hash = 59 * hash + Objects.hashCode(authoringSteps); - return hash; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof AuthoringKitInfo)) { - return false; - } - final AuthoringKitInfo other = (AuthoringKitInfo) obj; - if (!other.canEqual(this)) { - return false; - } - if (!Objects.equals(createComponent, other.getCreateComponent())) { - return false; - } - return Objects.equals(authoringSteps, other.getAuthoringSteps()); - } - - public boolean canEqual(final Object obj) { - return obj instanceof AuthoringKitInfo; - } - - @Override - public final String toString() { - return toString(""); - } - - public String toString(final String data) { - return String.format("%s{ " - + "createComponent = \"%s\", " - + "authoringSteps = { %s }%s" - + " }", - super.toString(), - Objects.toString(createComponent), - Objects.toString(authoringSteps), - data); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStep.java b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStep.java deleted file mode 100644 index 4fe8e30ad..000000000 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStep.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.librecms.contenttypes; - -import com.arsdigita.bebop.Component; -import com.arsdigita.bebop.Form; - -/** - * Annotation used inside the {@link AuthoringKit} annotation to describe the - * authoring steps belonging to an authoring kit. - * - * @author Jens Pelzetter - */ -@Deprecated -public @interface AuthoringStep { - - /** - * Key of the label in the {@link #labelBundle()}. If blank (default) the - * simple name of the annotated class with the suffix {@code .label} is - * used. - * - * @return The label key of the authoring step. - */ - String labelKey() default ""; - - /** - * Bundle providing the localised label for the authoring step. If omitted - * the default bundle for the content type will be used. The default bundle - * is the fully qualified name of the content type class with the suffix - * {@code Bundle}. - * - * @return The bundle providing the label for the authoring step. - */ - String labelBundle() default ""; - - /** - * Key of the description in the {@link #descriptionBundle()}. If blank - * (default) the simple name of the annotated class with the suffix - * {@code .description} is used. - * - * @return The description key of the authoring step. - */ - String descriptionKey() default ""; - - /** - * Bundle providing the localised description for the authoring step. If - * omitted the default bundle for the content type will be used. The default - * bundle is the fully qualified name of the content type class with the - * suffix {@code Bundle}. - * - * @return The bundle providing the description for the authoring step. - */ - String descriptionBundle() default ""; - - /** - * The position of the authoring step. - * - * @return The position of the authoring step. - */ - int order(); - - /** - * The component (usually a {@link Form} providing the UI for the authoring - * step. - * - * @return The class providing the UI for the authoring step. - */ - Class component(); - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStepInfo.java b/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStepInfo.java deleted file mode 100644 index 6787c23fd..000000000 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/AuthoringStepInfo.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.librecms.contenttypes; - -import com.arsdigita.bebop.Component; - -import java.util.Objects; - -/** - * Encapsulates the information about an authoring step. - * - * @see AuthoringStep - * - * @author Jens Pelzetter - */ -public class AuthoringStepInfo { - - /** - * The bundle which provides the label for the authoring step. - */ - private String labelBundle; - /** - * The key of label for the authoring step in the {@link #labelBundle} - */ - private String labelKey; - /** - * The bundle which provides the description for the authoring step. - */ - private String descriptionBundle; - /** - * The key of the description for the authoring step in the - * {@link #descriptionBundle}. - */ - private String descriptionKey; - - private int order; - private Class component; - - protected AuthoringStepInfo() { - super(); - } - - public String getLabelBundle() { - return labelBundle; - } - - public void setLabelBundle(final String labelBundle) { - this.labelBundle = labelBundle; - } - - public String getLabelKey() { - return labelKey; - } - - public void setLabelKey(final String labelKey) { - this.labelKey = labelKey; - } - - public String getDescriptionBundle() { - return descriptionBundle; - } - - public void setDescriptionBundle(final String descriptionBundle) { - this.descriptionBundle = descriptionBundle; - } - - public String getDescriptionKey() { - return descriptionKey; - } - - public void setDescriptionKey(final String descriptionKey) { - this.descriptionKey = descriptionKey; - } - - public int getOrder() { - return order; - } - - public void setOrder(final int order) { - this.order = order; - } - - public Class getComponent() { - return component; - } - - public void setComponent(final Class component) { - this.component = component; - } - - @Override - public int hashCode() { - int hash = 5; - hash = 53 * hash + Objects.hashCode(labelBundle); - hash = 53 * hash + Objects.hashCode(labelKey); - hash = 53 * hash + Objects.hashCode(descriptionBundle); - hash = 53 * hash + Objects.hashCode(descriptionKey); - hash = 53 * hash + Objects.hashCode(order); - hash = 53 * hash + Objects.hashCode(component); - return hash; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof AuthoringStepInfo)) { - return false; - } - final AuthoringStepInfo other = (AuthoringStepInfo) obj; - if (!other.canEqual(this)) { - return false; - } - if (!Objects.equals(this.labelBundle, other.getLabelBundle())) { - return false; - } - if (!Objects.equals(this.labelKey, other.getLabelKey())) { - return false; - } - if (!Objects.equals(this.descriptionBundle, - other.getDescriptionBundle())) { - return false; - } - if (!Objects.equals(this.descriptionKey, other.getDescriptionKey())) { - return false; - } - - if (order != other.getOrder()) { - return false; - } - - return Objects.equals(this.component, other.getComponent()); - } - - public boolean canEqual(final Object obj) { - return obj instanceof AuthoringStepInfo; - } - - @Override - public final String toString() { - return toString(""); - } - - public String toString(final String data) { - return String.format("%s{ " - + "labelBundle = \"%s\", " - + "labelKey = \"%s\", " - + "descriptionBundle = \"%s\"," - + "descriptionKey = \"%s\"," - + "order = %d, " - + "component = \"%s\"%s }", - super.toString(), - labelBundle, - labelKey, - descriptionKey, - descriptionBundle, - order, - Objects.toString(component), - data); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeInfo.java b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeInfo.java index 8659430fc..9925955f2 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeInfo.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypeInfo.java @@ -48,7 +48,6 @@ public class ContentTypeInfo { private String descriptionKey; private Class contentItemClass; - private AuthoringKitInfo authoringKit; public String getLabelBundle() { return labelBundle; @@ -91,14 +90,7 @@ public class ContentTypeInfo { this.contentItemClass = contentItemClass; } - public AuthoringKitInfo getAuthoringKit() { - return authoringKit; - } - - public void setAuthoringKit(final AuthoringKitInfo authoringKit) { - this.authoringKit = authoringKit; - } - + @Override public int hashCode() { int hash = 3; @@ -107,7 +99,6 @@ public class ContentTypeInfo { hash = 97 * hash + Objects.hashCode(descriptionBundle); hash = 97 * hash + Objects.hashCode(descriptionKey); hash = 97 * hash + Objects.hashCode(contentItemClass); - hash = 97 * hash + Objects.hashCode(authoringKit); return hash; } @@ -139,11 +130,7 @@ public class ContentTypeInfo { return false; } - if (!Objects.equals(contentItemClass, other.getContentItemClass())) { - return false; - } - - return Objects.equals(authoringKit, other.getAuthoringKit()); + return Objects.equals(contentItemClass, other.getContentItemClass()); } public boolean canEqual(final Object obj) { @@ -162,7 +149,6 @@ public class ContentTypeInfo { + "descriptionBundle = \"%s\", " + "descriptionKey = \"%s\"," + "contentItemClass = \"%s\", " - + "authoringKit = { %s }%s" + " }", super.toString(), labelBundle, @@ -170,7 +156,6 @@ public class ContentTypeInfo { descriptionBundle, descriptionKey, Objects.toString(contentItemClass), - Objects.toString(authoringKit), data); } diff --git a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java index 605fcd2fb..819bc20c2 100644 --- a/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java +++ b/ccm-cms/src/main/java/org/librecms/contenttypes/ContentTypesManager.java @@ -44,6 +44,7 @@ import javax.transaction.Transactional; public class ContentTypesManager { private static final String DEFAULT_DESCRIPTION_KEY = "description"; + private static final String DEFAULT_LABEL_KEY = "label"; /** @@ -62,10 +63,10 @@ public class ContentTypesManager { .load(CcmModule.class); final SortedSet> contentTypes - = new TreeSet<>( + = new TreeSet<>( (type1, type2) -> { - return type1.getName().compareTo(type2.getName()); - } + return type1.getName().compareTo(type2.getName()); + } ); for (final CcmModule module : modules) { @@ -82,7 +83,6 @@ public class ContentTypesManager { availableContentTypes = contentTypes .stream() - .filter(type -> type.getAnnotation(AuthoringKit.class) != null) .map(contentTypeClass -> createContentTypeInfo(contentTypeClass)) .collect(Collectors.toList()); } @@ -96,8 +96,8 @@ public class ContentTypesManager { * @return A {@link ContentTypeInfo} object describing the content type. */ private ContentTypeInfo createContentTypeInfo( - final Class contentTypeClass) { - + final Class contentTypeClass + ) { Objects.requireNonNull(contentTypeClass); final ContentTypeInfo contentTypeInfo = new ContentTypeInfo(); @@ -141,87 +141,9 @@ public class ContentTypesManager { } } - final AuthoringKit authoringKit = contentTypeClass - .getAnnotation(AuthoringKit.class); - if (authoringKit != null) { - final AuthoringKitInfo authoringKitInfo = new AuthoringKitInfo(); - authoringKitInfo.setCreateComponent(authoringKit.createComponent()); - - final List steps = Arrays - .stream(authoringKit.steps()) - .map(step -> createAuthoringStepInfo(contentTypeClass, step)) - .collect(Collectors.toList()); - authoringKitInfo.setAuthoringSteps(steps); - steps.sort((step1, step2) -> Integer.compare(step1.getOrder(), - step2.getOrder())); - contentTypeInfo.setAuthoringKit(authoringKitInfo); - } - return contentTypeInfo; } - /** - * Helper method for creating an info object about an authoring step. - * - * @param contentTypeClass The class which provides the implementation of - * the content type. - * @param authoringStep The {@link AuthoringStep} annotation providing - * the information about the authoring step. - * - * @return An {@link AuthoringStepInfo} object describing the authoring - * step. - * - */ - private AuthoringStepInfo createAuthoringStepInfo( - final Class contentTypeClass, - final AuthoringStep authoringStep) { - - Objects.requireNonNull(contentTypeClass); - Objects.requireNonNull(authoringStep); - - final AuthoringStepInfo stepInfo = new AuthoringStepInfo(); - - stepInfo.setComponent(authoringStep.component()); - stepInfo.setOrder(authoringStep.order()); - - final String defaultBundleName = String.join( - "", - contentTypeClass.getClass().getName(), - "Bundle"); - - if (authoringStep.labelBundle().isEmpty()) { - stepInfo.setLabelBundle(defaultBundleName); - } else { - stepInfo.setLabelBundle(authoringStep.labelBundle()); - } - - if (authoringStep.labelKey().isEmpty()) { - stepInfo.setLabelKey( - String.join(".", - authoringStep.component().getSimpleName(), - DEFAULT_LABEL_KEY)); - } else { - stepInfo.setLabelKey(authoringStep.labelKey()); - } - - if (authoringStep.descriptionBundle().isEmpty()) { - stepInfo.setDescriptionBundle(defaultBundleName); - } else { - stepInfo.setDescriptionBundle(authoringStep.descriptionBundle()); - } - - if (authoringStep.descriptionKey().isEmpty()) { - stepInfo.setDescriptionKey( - String.join(".", - authoringStep.component().getSimpleName(), - DEFAULT_DESCRIPTION_KEY)); - } else { - stepInfo.setDescriptionKey(authoringStep.descriptionKey()); - } - - return stepInfo; - } - /** * Retrieves a list of all content types currently available on the system. * diff --git a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStep.java b/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStep.java deleted file mode 100644 index 474209fec..000000000 --- a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStep.java +++ /dev/null @@ -1,74 +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 org.librecms.ui.authoring; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * Provides meta information about an authoring step which is independent from - * the type of the content item. - * - * @author Jens Pelzetter - */ -@Target({ElementType.TYPE}) -@Retention(RetentionPolicy.RUNTIME) -public @interface ContentItemAuthoringStep { - - /** - * Key of the label in the {@link #labelBundle()}. If blank (default) the - * simple name of the annotated class with the suffix {@code .label} is - * used. - * - * @return The label key of the authoring step. - */ - String labelKey() default ""; - - /** - * Bundle providing the localised label for the authoring step. If omitted - * the default bundle will be used. The default bundle is the fully - * qualified name of the authoring step class with the suffix - * {@code Bundle}. - * - * @return The bundle providing the label for the authoring step. - */ - String labelBundle() default ""; - - /** - * Key of the description in the {@link #descriptionBundle()}. If blank - * (default) the simple name of the annotated class with the suffix - * {@code .description} is used. - * - * @return The description key of the authoring step. - */ - String descriptionKey() default ""; - - /** - * Bundle providing the localised description for the authoring step. If - * omitted the default bundle will be used. The default bundle is the fully - * qualified name of the authoring step class with the suffix - * {@code Bundle}. - * - * @return The bundle providing the description for the authoring step. - */ - String descriptionBundle() default ""; - -} diff --git a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepInfo.java b/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepInfo.java deleted file mode 100644 index 1c090ed54..000000000 --- a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepInfo.java +++ /dev/null @@ -1,161 +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 org.librecms.ui.authoring; - -import com.arsdigita.bebop.Component; - -import java.util.Objects; - -/** - * Information about a authoring step which is independent from the type of the - * content item. - * - * @author Jens Pelzetter - */ -public class ContentItemAuthoringStepInfo { - - private Class step; - - /** - * The bundle which provides the label for the authoring step. - */ - private String labelBundle; - /** - * The key of label for the authoring step in the {@link #labelBundle} - */ - private String labelKey; - /** - * The bundle which provides the description for the authoring step. - */ - private String descriptionBundle; - /** - * The key of the description for the authoring step in the - * {@link #descriptionBundle}. - */ - private String descriptionKey; - - public Class getStep() { - return step; - } - - public void setStep(Class step) { - this.step = step; - } - - public String getLabelBundle() { - return labelBundle; - } - - public void setLabelBundle(String labelBundle) { - this.labelBundle = labelBundle; - } - - public String getLabelKey() { - return labelKey; - } - - public void setLabelKey(String labelKey) { - this.labelKey = labelKey; - } - - public String getDescriptionBundle() { - return descriptionBundle; - } - - public void setDescriptionBundle(String descriptionBundle) { - this.descriptionBundle = descriptionBundle; - } - - public String getDescriptionKey() { - return descriptionKey; - } - - public void setDescriptionKey(String descriptionKey) { - this.descriptionKey = descriptionKey; - } - - @Override - public int hashCode() { - int hash = 7; - hash = 53 * hash + Objects.hashCode(step); - hash = 53 * hash + Objects.hashCode(labelBundle); - hash = 53 * hash + Objects.hashCode(labelKey); - hash = 53 * hash + Objects.hashCode(descriptionBundle); - hash = 53 * hash + Objects.hashCode(descriptionKey); - return hash; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof ContentItemAuthoringStepInfo)) { - return false; - } - final ContentItemAuthoringStepInfo other - = (ContentItemAuthoringStepInfo) obj; - if (!other.canEqual(this)) { - return false; - } - - if (!Objects.equals(labelBundle, other.getLabelBundle())) { - return false; - } - if (!Objects.equals(labelKey, other.getLabelKey())) { - return false; - } - if (!Objects.equals(descriptionBundle, other.getDescriptionBundle())) { - return false; - } - if (!Objects.equals(descriptionKey, other.getDescriptionKey())) { - return false; - } - return Objects.equals(step, other.getStep()); - } - - public boolean canEqual(final Object obj) { - return obj instanceof ContentItemAuthoringStep; - } - - @Override - public final String toString() { - return toString(""); - } - - public String toString(final String data) { - return String.format("%s{ " - + "labelBundle = \"%s\", " - + "labelKey = \"%s\", " - + "descriptionBundle = \"%s\", " - + "descriptionKey = \"%s\"," - + "step = \"%s\"%s }", - super.toString(), - labelBundle, - labelKey, - descriptionBundle, - descriptionKey, - Objects.toString(step), - data); - } - -} diff --git a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java b/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java deleted file mode 100644 index a6dcde46a..000000000 --- a/ccm-cms/src/main/java/org/librecms/ui/authoring/ContentItemAuthoringStepManager.java +++ /dev/null @@ -1,142 +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 org.librecms.ui.authoring; - -import com.arsdigita.bebop.Component; - -import org.libreccm.configuration.ConfigurationManager; -import org.libreccm.core.UnexpectedErrorException; -import org.librecms.contentsection.ContentSectionConfig; - -import java.util.Collections; -import java.util.List; -import java.util.Objects; -import java.util.stream.Collectors; - -import javax.annotation.PostConstruct; -import javax.enterprise.context.RequestScoped; -import javax.inject.Inject; - -/** - * Provides easy access to information about the default authoring step which - * are available for every content type. - * - * @author Jens Pelzetter - */ -@RequestScoped -public class ContentItemAuthoringStepManager { - - @Inject - private ConfigurationManager confManager; - - private List stepInfos; - - @PostConstruct - protected void initialize() { - - final ContentSectionConfig config = confManager - .findConfiguration(ContentSectionConfig.class); - final List classNames = Collections.emptyList(); - - stepInfos = classNames - .stream() - .map(className -> createStepInfo(className)) - .collect(Collectors.toList()); - } - - public List getContentItemAuthoringStepInfos() { - - return Collections.unmodifiableList(stepInfos); - } - - @SuppressWarnings("unchecked") - private ContentItemAuthoringStepInfo createStepInfo(final String className) { - - Objects.requireNonNull(className); - - if (className.isEmpty()) { - throw new IllegalArgumentException("The name of the authoring step " - + "class can't be empty."); - } - - final Class clazz; - try { - clazz = (Class) Class.forName(className); - } catch (ClassNotFoundException ex) { - throw new UnexpectedErrorException(String - .format("No class for class name \"%s\" available.", - className), - ex); - } - - return createStepInfo(clazz); - } - - private ContentItemAuthoringStepInfo createStepInfo( - final Class clazz) { - - final ContentItemAuthoringStepInfo stepInfo - = new ContentItemAuthoringStepInfo(); - - final ContentItemAuthoringStep step = clazz - .getAnnotation(ContentItemAuthoringStep.class); - - final String defaultBundleName = String - .join("", clazz.getName(), "Bundle"); - final String defaultLabelKey = String.join(".", - clazz.getSimpleName(), - "label"); - final String defaultDescKey = String.join(".", - clazz.getSimpleName(), - "description"); - - if (step == null) { - stepInfo.setLabelBundle(defaultBundleName); - stepInfo.setDescriptionBundle(defaultBundleName); - stepInfo.setLabelKey(defaultLabelKey); - stepInfo.setDescriptionKey(defaultDescKey); - } else { - if (step.labelBundle() == null || step.labelBundle().isEmpty()) { - stepInfo.setLabelBundle(defaultBundleName); - } else { - stepInfo.setLabelBundle(step.labelBundle()); - } - if (step.labelKey() == null || step.labelKey().isEmpty()) { - stepInfo.setLabelKey(defaultLabelKey); - } else { - stepInfo.setLabelKey(step.labelKey()); - } - if (step.descriptionBundle() == null - || step.descriptionBundle().isEmpty()) { - stepInfo.setDescriptionBundle(defaultBundleName); - } else { - stepInfo.setDescriptionBundle(step.descriptionBundle()); - } - if (step.descriptionKey() == null - || step.descriptionKey().isEmpty()) { - stepInfo.setDescriptionKey(defaultDescKey); - } - } - - stepInfo.setStep(clazz); - - return stepInfo; - } - -} diff --git a/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_33__remove_page_model.sql b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_33__remove_page_model.sql index da2f8c42f..fd82455dc 100644 --- a/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_33__remove_page_model.sql +++ b/ccm-cms/src/main/resources/db/migrations/org/librecms/ccm_cms/pgsql/V7_0_0_33__remove_page_model.sql @@ -1,8 +1,8 @@ -drop table CCM_CMS.CATEGORY_TREE_COMPONENTS; -drop table CCM_CMS.FIXED_CONTENT_ITEM_COMPONENTS; -drop table CCM_CMS.GREETING_ITEM_COMPONENTS; -drop table CCM_CMS.CATEGORIZED_ITEM_COMPONENTS; -drop table CCM_CMS.CONTENT_ITEM_COMPONENTS; +drop table if exists CCM_CMS.CATEGORY_TREE_COMPONENTS; +drop table if exists CCM_CMS.FIXED_CONTENT_ITEM_COMPONENTS; +drop table if exists CCM_CMS.GREETING_ITEM_COMPONENTS; +drop table if exists CCM_CMS.CATEGORIZED_ITEM_COMPONENTS; +drop table if exists CCM_CMS.CONTENT_ITEM_COMPONENTS; -drop table CCM_CMS.ITEM_LIST_ORDER; -drop table CCM_CMS.ITEM_LIST_COMPONENTS; +drop table if exists CCM_CMS.ITEM_LIST_ORDER; +drop table if exists CCM_CMS.ITEM_LIST_COMPONENTS; diff --git a/ccm-cms/src/test/java/org/librecms/contenttypes/EqualsAndHashCodeTest.java b/ccm-cms/src/test/java/org/librecms/contenttypes/EqualsAndHashCodeTest.java index a097ada32..799365248 100644 --- a/ccm-cms/src/test/java/org/librecms/contenttypes/EqualsAndHashCodeTest.java +++ b/ccm-cms/src/test/java/org/librecms/contenttypes/EqualsAndHashCodeTest.java @@ -37,8 +37,6 @@ public class EqualsAndHashCodeTest extends EqualsVerifier { @Parameterized.Parameters(name = "{0}") public static Collection> data() { return Arrays.asList(new Class[]{ - AuthoringKitInfo.class, - AuthoringStepInfo.class, ContentTypeInfo.class }); } diff --git a/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java b/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java index d31eaa438..0e73cfd07 100644 --- a/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java +++ b/ccm-core/src/main/java/org/libreccm/modules/CcmIntegrator.java @@ -336,7 +336,6 @@ public class CcmIntegrator implements Integrator { Connection connection = null; LOGGER.info("Removing schemas for modules scheduled for uninstall..."); try { - //Get JDBC connection final DataSource dataSource = (DataSource) sessionFactory .getProperties().get(DATASOURCE_PROPERTY); diff --git a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/Shortcuts.java b/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/Shortcuts.java index 2415c8f3d..b7148f9ae 100644 --- a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/Shortcuts.java +++ b/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/Shortcuts.java @@ -26,7 +26,6 @@ import org.libreccm.modules.Module; import org.libreccm.modules.RequiredModule; import org.libreccm.modules.ShutdownEvent; import org.libreccm.modules.UnInstallEvent; -import org.libreccm.shortcuts.ui.ShortcutsSettingsPane; import org.libreccm.ui.admin.applications.shortcuts.ShortcutsApplicationController; import org.libreccm.web.ApplicationType; @@ -45,7 +44,6 @@ import org.libreccm.web.ApplicationType; name = ShortcutsConstants.SHORTCUTS_APP_TYPE, descBundle = ShortcutsConstants.SHORTCUTS_BUNDLE, singleton = true, - settingsPane = ShortcutsSettingsPane.class, creator = ShortcutsApplicationCreator.class, applicationController = ShortcutsApplicationController.class )} diff --git a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutForm.java b/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutForm.java deleted file mode 100644 index 13dda26e2..000000000 --- a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutForm.java +++ /dev/null @@ -1,160 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.libreccm.shortcuts.ui; - -import com.arsdigita.bebop.Form; -import com.arsdigita.bebop.FormData; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.SaveCancelSection; -import com.arsdigita.bebop.form.TextField; -import com.arsdigita.globalization.GlobalizedMessage; - -import org.libreccm.cdi.utils.CdiUtil; -import org.libreccm.shortcuts.Shortcut; -import org.libreccm.shortcuts.ShortcutManager; -import org.libreccm.shortcuts.ShortcutRepository; -import org.libreccm.shortcuts.ShortcutsConstants; - -import java.util.Locale; -import java.util.regex.Pattern; - -/** - * For for creating and editing shortcuts. - * - * @author Jens Pelzetter - */ -public class ShortcutForm extends Form { - - - - private static final String URL_KEY = "urlKey"; - private static final String REDIRECT = "redirect"; - - private final TextField urlKeyField; - private final TextField redirectField; - - private final SaveCancelSection saveCancelSection; - - public ShortcutForm( - final ShortcutsSettingsPane shortcutsPane, - final ParameterSingleSelectionModel selectedShortcut) { - - super("shortcutForm"); - - urlKeyField = new TextField(URL_KEY); - urlKeyField.setLabel(new GlobalizedMessage( - "shortcuts.ui.admin.url_key.label", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - add(urlKeyField); - - redirectField = new TextField(REDIRECT); - redirectField.setLabel(new GlobalizedMessage( - "shortcuts.ui.admin.redirect.label", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - add(redirectField); - - saveCancelSection = new SaveCancelSection(); - add(saveCancelSection); - - addValidationListener(e -> { - final PageState state = e.getPageState(); - final FormData data = e.getFormData(); - - final String urlKey = data.getString(URL_KEY); - if (urlKey == null || urlKey.trim().isEmpty()) { - data.addError(URL_KEY, new GlobalizedMessage( - "shortcuts.ui.admin.url_key.error.not_empty", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - return; - } - - // The URL to redirect must start with a '/' and end with a '/'. - // Between the starting and the ending '/' only the characters - // 'a' to 'z', 'A' to 'Z', '0' to '9', '_', '-' and '.' may appear. - if (!Pattern.matches("^/[-a-zA-Z0-9_./]+/$", urlKey)) { - data.addError(URL_KEY, new GlobalizedMessage( - "shortcuts.ui.admin.url_key.error.invalid", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - return; - } - - if (data.getString(REDIRECT) == null - || data.getString(REDIRECT).trim().isEmpty()) { - data.addError(URL_KEY, new GlobalizedMessage( - "shortcuts.ui.admin.redirect.not_empty", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - return; - } - final String redirect = data.getString(REDIRECT).toLowerCase( - Locale.ROOT); - if (!redirect.startsWith("http://") - && !redirect.startsWith("https://") - && !redirect.startsWith("/")) { - data.addError(URL_KEY, new GlobalizedMessage( - "shortcuts.ui.admin.redirect.error.invalid", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - } - }); - - addInitListener(e -> { - final PageState state = e.getPageState(); - final FormData data = e.getFormData(); - - if (selectedShortcut.isSelected(state)) { - final ShortcutRepository repo = CdiUtil.createCdiUtil() - .findBean(ShortcutRepository.class); - final Shortcut shortcut = repo.findById(Long.parseLong( - selectedShortcut.getSelectedKey(state))).get(); - urlKeyField.setValue(state, shortcut.getUrlKey()); - redirectField.setValue(state, shortcut.getRedirect()); - } - }); - - addProcessListener(e -> { - final PageState state = e.getPageState(); - final FormData data = e.getFormData(); - - if (saveCancelSection.getSaveButton().isSelected(state)) { - - final Shortcut shortcut; - if (selectedShortcut.isSelected(state)) { - final ShortcutRepository repo = CdiUtil.createCdiUtil() - .findBean(ShortcutRepository.class); - shortcut = repo.findById(Long.parseLong(selectedShortcut - .getSelectedKey(state))).get(); - - shortcut.setUrlKey(data.getString(URL_KEY)); - shortcut.setRedirect(data.getString(REDIRECT)); - - repo.save(shortcut); - } else { - final ShortcutManager shortcutManager = CdiUtil - .createCdiUtil().findBean(ShortcutManager.class); - shortcutManager.createShortcut(data.getString(URL_KEY), - data.getString(REDIRECT)); - } - } - - selectedShortcut.clearSelection(state); - shortcutsPane.showShortcutsTable(state); - }); - } - -} diff --git a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsSettingsPane.java b/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsSettingsPane.java deleted file mode 100644 index d1a6d498d..000000000 --- a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsSettingsPane.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.libreccm.shortcuts.ui; - -import com.arsdigita.bebop.ActionLink; -import com.arsdigita.bebop.BoxPanel; -import com.arsdigita.bebop.Label; -import com.arsdigita.bebop.Page; -import com.arsdigita.bebop.PageState; -import com.arsdigita.bebop.ParameterSingleSelectionModel; -import com.arsdigita.bebop.parameters.StringParameter; -import com.arsdigita.globalization.GlobalizedMessage; -import com.arsdigita.ui.admin.applications.AbstractAppSettingsPane; - -import org.libreccm.shortcuts.ShortcutsConstants; - -/** - * Pane which is used in the {@code /ccm/admin/} application for providing - * an admininstration UI for shortcuts. - * - * @author Jens Pelzetter - */ -public class ShortcutsSettingsPane extends AbstractAppSettingsPane { - - /** - * Parameter for the selected shortcut. - */ - private final StringParameter selectedShortcutParam; - /** - * Selection model for the selected shortcut. - */ - private final ParameterSingleSelectionModel selectedShortcut; - /** - * Table listing all shortcuts. - */ - private final ShortcutsTable shortcutsTable; - /** - * Link for creating a new shortcut. - */ - private final ActionLink addShortcutLink; - /** - * Form for creating and editing shortcuts. - */ - private final ShortcutForm shortcutForm; - - public ShortcutsSettingsPane( - final ParameterSingleSelectionModel selectedAppType, - final ParameterSingleSelectionModel selectedAppInstance) { - - super(selectedAppType, selectedAppInstance); - - selectedShortcutParam = new StringParameter("selectedShortcut"); - selectedShortcut = new ParameterSingleSelectionModel<>( - selectedShortcutParam); - - final BoxPanel panel = new BoxPanel(BoxPanel.VERTICAL); - final Label heading = new Label(new GlobalizedMessage( - "shortcuts.ui.admin.heading", ShortcutsConstants.SHORTCUTS_BUNDLE)); - heading.setClassAttr("heading"); - panel.add(heading); - - shortcutsTable = new ShortcutsTable(this, selectedShortcut); - panel.add(shortcutsTable); - - shortcutForm = new ShortcutForm(this, selectedShortcut); - panel.add(shortcutForm); - - addShortcutLink = new ActionLink(new GlobalizedMessage( - "shortcuts.ui.admin.add_shortcut", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - addShortcutLink.addActionListener(e -> { - showShortcutForm(e.getPageState()); - }); - panel.add(addShortcutLink); - - add(panel); - } - - @Override - protected void createWidgets() { - - } - - @Override - public void register(final Page page) { - super.register(page); - - page.addGlobalStateParam(selectedShortcutParam); - - page.setVisibleDefault(shortcutsTable, true); - page.setVisibleDefault(shortcutForm, false); - page.setVisibleDefault(addShortcutLink, true); - - } - - void showShortcutForm(final PageState state) { - shortcutsTable.setVisible(state, false); - shortcutForm.setVisible(state, true); - addShortcutLink.setVisible(state, false); - } - - void showShortcutsTable(final PageState state) { - shortcutsTable.setVisible(state, true); - shortcutForm.setVisible(state, false); - addShortcutLink.setVisible(state, true); - } - -} diff --git a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsTable.java b/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsTable.java deleted file mode 100644 index c03bd4230..000000000 --- a/ccm-shortcuts/src/main/java/org/libreccm/shortcuts/ui/ShortcutsTable.java +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright (C) 2016 LibreCCM Foundation. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2.1 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, - * MA 02110-1301 USA - */ -package org.libreccm.shortcuts.ui; - -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.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 org.libreccm.shortcuts.Shortcut; -import org.libreccm.shortcuts.ShortcutRepository; -import org.libreccm.shortcuts.ShortcutsConstants; - -import java.util.List; - -/** - * Table which lists all shortcuts. - * - * @author Jens Pelzetter - */ -public class ShortcutsTable extends Table { - - private static final int COL_URL_KEY = 0; - private static final int COL_REDIRECT = 1; - private static final int COL_EDIT = 2; - private static final int COL_DELETE = 3; - - private final ShortcutsSettingsPane shortcutsPane; - - public ShortcutsTable( - final ShortcutsSettingsPane shortcutsPane, - final ParameterSingleSelectionModel selectedShortcut) { - - super(); - - this.shortcutsPane = shortcutsPane; - - final TableColumnModel columnModel = getColumnModel(); - columnModel.add(new TableColumn( - COL_URL_KEY, - new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.col_url_key.header", - ShortcutsConstants.SHORTCUTS_BUNDLE)) - )); - columnModel.add(new TableColumn( - COL_REDIRECT, - new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.col_redirect.header", - ShortcutsConstants.SHORTCUTS_BUNDLE)) - )); - columnModel.add(new TableColumn( - COL_EDIT, - new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.col_edit.header", - ShortcutsConstants.SHORTCUTS_BUNDLE)) - )); - columnModel.add(new TableColumn( - COL_DELETE, - new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.col_delete.header", - ShortcutsConstants.SHORTCUTS_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_DELETE).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); - } - - }); - - addTableActionListener(new TableActionListener() { - - @Override - public void cellSelected(final TableActionEvent event) { - final PageState state = event.getPageState(); - - switch (event.getColumn()) { - case COL_EDIT: - selectedShortcut.setSelectedKey(state, - event.getRowKey()); - shortcutsPane.showShortcutForm(state); - break; - case COL_DELETE: { - final ShortcutRepository repo = CdiUtil.createCdiUtil() - .findBean(ShortcutRepository.class); - final Shortcut shortcut = repo.findById(Long.parseLong( - (String) event.getRowKey())).get(); - repo.delete(shortcut); - break; - } - } - } - - @Override - public void headSelected(final TableActionEvent event) { - //nothing - } - - }); - - setModelBuilder(new ShortcutsTableModelBuilder()); - - setEmptyView(new Label(new GlobalizedMessage( - "shortcuts.ui.admin.table.empty", - ShortcutsConstants.SHORTCUTS_BUNDLE))); - - } - - private class ShortcutsTableModelBuilder extends LockableImpl implements - TableModelBuilder { - - @Override - public TableModel makeModel(final Table table, final PageState state) { - return new ShortcutsTableModel(); - } - - } - - private class ShortcutsTableModel implements TableModel { - - private final List shortcuts; - private int index = -1; - - public ShortcutsTableModel() { - final ShortcutRepository repo = CdiUtil.createCdiUtil().findBean( - ShortcutRepository.class); - shortcuts = repo.findAll(); - shortcuts.sort((s1, s2) -> { - return s1.getUrlKey().compareTo(s2.getUrlKey()); - }); - } - - @Override - public int getColumnCount() { - return 4; - } - - @Override - public boolean nextRow() { - index++; - return index < shortcuts.size(); - } - - @Override - public Object getElementAt(final int columnIndex) { - final Shortcut shortcut = shortcuts.get(index); - - switch (columnIndex) { - case COL_URL_KEY: - return shortcut.getUrlKey(); - case COL_REDIRECT: - return shortcut.getRedirect(); - case COL_EDIT: - return new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.edit", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - case COL_DELETE: - return new Label(new GlobalizedMessage( - "shortcuts.ui.admin.shortcuts_table.delete", - ShortcutsConstants.SHORTCUTS_BUNDLE)); - default: - throw new IllegalArgumentException( - "Not a valid column index"); - } - } - - @Override - public Object getKeyAt(final int columnIndex) { - return Long.toString(shortcuts.get(index).getShortcutId()); - } - - } - -}