diff --git a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/ResourceTypes.java b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/ResourceTypes.java index 6d187b418..c1003b566 100644 --- a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/ResourceTypes.java +++ b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/meta/ResourceTypes.java @@ -24,6 +24,7 @@ public class ResourceTypes { public static final String ALERT = "granite/ui/components/coral/foundation/alert"; public static final String ANCHOR_BUTTON = "granite/ui/components/coral/foundation/anchorbutton"; public static final String AUTOCOMPLETE = "granite/ui/components/coral/foundation/form/autocomplete"; + public static final String AUTOCOMPLETE_EAK = "etoolbox-authoring-kit/components/authoring/autocomplete"; public static final String AUTOCOMPLETE_LIST = "granite/ui/components/coral/foundation/form/autocomplete/list"; public static final String AUTOCOMPLETE_TAG = "granite/ui/components/coral/foundation/form/autocomplete/tags"; public static final String BUTTON = "granite/ui/components/coral/foundation/button"; diff --git a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/Autocomplete.java b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/Autocomplete.java new file mode 100644 index 000000000..9f86ec114 --- /dev/null +++ b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/Autocomplete.java @@ -0,0 +1,93 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.apache.commons.lang3.StringUtils; + +import com.exadel.aem.toolkit.api.annotations.meta.AnnotationRendering; +import com.exadel.aem.toolkit.api.annotations.meta.ResourceType; +import com.exadel.aem.toolkit.api.annotations.meta.ResourceTypes; +import com.exadel.aem.toolkit.api.annotations.widgets.common.OptionProvider; + +@Target({ElementType.FIELD, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ResourceType(ResourceTypes.AUTOCOMPLETE_EAK) +@AnnotationRendering(properties = "all") +public @interface Autocomplete { + + /** + * Used to specify the collection of {@link AutocompleteItem}s within this Autocomplete + * @return Single {@code AutocompleteItem} annotation, or an array of AutocompleteItem + */ + AutocompleteItem[] items() default {}; + + /** + * Used to specify the source for options handled by the ToolKit's {@code OptionProvider} mechanism + * @return {@link OptionProvider} instance, or an empty {@code OptionProvider} if not needed + */ + OptionProvider optionProvider() default @OptionProvider; + + /** + * When set to a non-blank string, maps to the {@code placeholder} attribute of this Granite UI component's node. + * Used to define the text hint for an empty Autocomplete + * @return String value + */ + String placeholder() default StringUtils.EMPTY; + + /** + * Maps to the {@code match} attribute of this Granite UI component's node. + * Used to define Autocomplete match mode + * @return One of {@code MatchMode} values + * @see MatchMode + */ + MatchMode matchMode() default MatchMode.CONTAINS; + + /** + * When set to a non-blank string, maps to the {@code icon} attribute of this Granite UI component's node. + * Used to define the component's icon + * @return String value + */ + String icon() default StringUtils.EMPTY; + + /** + * When set to true, maps to the {@code disabled} attribute of this Granite UI component's node. + * Changing the state of the autocomplete widget + * @return True or false + */ + boolean disabled() default false; + + /** + * When set to true, maps to the {@code invalid} attribute of this Granite UI component's node. + * @return True or false + */ + boolean invalid() default false; + + /** + * When set to true, maps to the {@code loading} attribute of this Granite UI component's node. + * Used to show the loading spinner while preparing options + * @return True or false + */ + boolean loading() default false; + + /** + * Indicates if the user is able to select multiple options + * @return True or false + */ + boolean multiple() default false; +} diff --git a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/AutocompleteItem.java b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/AutocompleteItem.java new file mode 100644 index 000000000..4ef6c74ad --- /dev/null +++ b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/AutocompleteItem.java @@ -0,0 +1,75 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; + +import com.exadel.aem.toolkit.api.annotations.meta.AnnotationRendering; +import com.exadel.aem.toolkit.api.annotations.meta.PropertyRendering; +import com.exadel.aem.toolkit.api.annotations.meta.ResourceType; +import com.exadel.aem.toolkit.api.annotations.meta.ResourceTypes; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * Used to define an option within the {@link Autocomplete#items()} set + * See documentation on + * Autocomplete component + */ +@Target({ElementType.FIELD, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@ResourceType(ResourceTypes.AUTOCOMPLETE_EAK) +@AnnotationRendering(properties = "all") +public @interface AutocompleteItem { + + /** + * Maps to the {@code text} attribute of this Coral UI component's node. + * Used to define the text displayed beside the option box + * @return String value + */ + String text(); + + /** + * Maps to the {@code value} attribute of this Coral UI component's node. + * Used to define the value to be stored when this option is checked + * @return String value + */ + @PropertyRendering(allowBlank = true) + String value(); + + /** + * When set to true, maps to the {@code disabled} attribute of this Granite UI component's node. + * Changing the state of the autocomplete item + * @return True or false + */ + @PropertyRendering(ignoreValues = "false") + boolean disabled() default false; + + /** + * When set to true, maps to the {@code hidden} attribute of this Granite UI component's node. + * Changing the state of the autocomplete item + * @return True or false + */ + @PropertyRendering(ignoreValues = "false") + boolean hidden() default false; + + /** + * When set to true, maps to the {@code selected} attribute of this Granite UI component's node. + * Defines that the current option is selected by default + * @return True or false + */ + @PropertyRendering(ignoreValues = "false") + boolean selected() default false; +} diff --git a/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/MatchMode.java b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/MatchMode.java new file mode 100644 index 000000000..b4404de3f --- /dev/null +++ b/core/src/main/java/com/exadel/aem/toolkit/api/annotations/widgets/autocomplete3/MatchMode.java @@ -0,0 +1,18 @@ +package com.exadel.aem.toolkit.api.annotations.widgets.autocomplete3; + +import org.apache.commons.lang3.StringUtils; + +public enum MatchMode { + STARTS_WITH { + @Override + public String toString() { + return "startswith"; + } + }, + CONTAINS { + @Override + public String toString() { + return StringUtils.EMPTY; + } + } +} diff --git a/core/src/main/java/com/exadel/aem/toolkit/core/authoring/models/Autocomplete.java b/core/src/main/java/com/exadel/aem/toolkit/core/authoring/models/Autocomplete.java new file mode 100644 index 000000000..f5ba25c85 --- /dev/null +++ b/core/src/main/java/com/exadel/aem/toolkit/core/authoring/models/Autocomplete.java @@ -0,0 +1,165 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exadel.aem.toolkit.core.authoring.models; + +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import javax.annotation.PostConstruct; +import javax.inject.Named; + +import com.exadel.aem.toolkit.core.CoreConstants; + +import org.apache.sling.api.SlingHttpServletRequest; +import org.apache.sling.models.annotations.DefaultInjectionStrategy; +import org.apache.sling.models.annotations.Model; +import org.apache.sling.models.annotations.injectorspecific.ChildResource; +import org.apache.sling.models.annotations.injectorspecific.OSGiService; +import org.apache.sling.models.annotations.injectorspecific.SlingObject; +import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; +import org.apache.sling.models.factory.ModelFactory; + +import com.exadel.aem.toolkit.api.annotations.main.AemComponent; +import com.exadel.aem.toolkit.core.optionprovider.services.OptionProviderService; + +/** + * Represents the back-end part of the {@code Autocomplete} component for Granite UI dialogs. + * This Sling model is responsible for retrieving the properties of the component's node. + */ +@Model(adaptables = SlingHttpServletRequest.class, defaultInjectionStrategy = DefaultInjectionStrategy.OPTIONAL) +@AemComponent( + path = "components/authoring/autocomplete", + title = "Autocomplete", + resourceSuperType = "etoolbox-authoring-kit/components/authoring/base" +) +public class Autocomplete extends BaseModel { + + @SlingObject + private SlingHttpServletRequest request; + + @OSGiService + private OptionProviderService optionProvider; + + @OSGiService + private ModelFactory modelFactory; + + @ValueMapValue(name = CoreConstants.PN_VALUE) + private String defaultValue; + + @ChildResource(name = "items") + private List