Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package com.exadel.aem.toolkit.api.annotations.widgets.autocomplete3;
package com.exadel.aem.toolkit.api.annotations.widgets.?.autocomplete;


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;
}
Original file line number Diff line number Diff line change
@@ -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 <a href="https://developer.adobe.com/experience-manager/reference-materials/6-5/coral-ui/coralui3/Coral.Autocomplete.html">
* Autocomplete</a> 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;
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
}
Original file line number Diff line number Diff line change
@@ -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<Option> options = new ArrayList<>();

@ValueMapValue
private String placeholder;

@ValueMapValue
private String matchMode;

@ValueMapValue
private String icon;

@ValueMapValue
private boolean disabled;

@ValueMapValue
private boolean invalid;

@ValueMapValue
private boolean loading;

@ValueMapValue
private boolean multiple;

/**
* Retrieves the list of {@link Option} objects
* @return List of {@link Option} objects
*/
public List<Option> getOptions() {
return options;
}

/**
* Retrieves the specified placeholder value of the autocomplete
* @return String value
*/
public String getPlaceholder() {
return placeholder;
}

/**
* Retrieves the specification of the autocomplete match mode
* @return String value
*/
public String getMatchMode() {
return matchMode;
}

/**
* Retrieves the specified icon value of the autocomplete
* @return String
*/
public String getIcon() {
return icon;
}

/**
* Retrieves the specification of the autocomplete if it is disabled or not
* @return True or False
*/
public boolean isDisabled() {
return disabled;
}

/**
* Retrieves the specification of the autocomplete if it is invalid or not
* @return True or False
*/
public boolean isInvalid() {
return invalid;
}

/**
* Retrieves whether the {@code Autocomplete} shows the loading spinner while preparing options.
* @return True or False
*/
public boolean isLoading() {
return loading;
}

/**
* Retrieves the specification of the autocomplete if it is support multiple values or not
* @return True or False
*/
public boolean isMultiple() {
return multiple;
}

/**
* Initializes this model per Sling Model standard
*/
@PostConstruct
private void init() {
List<Option> optionsModels = optionProvider
.getOptions(request)
.stream()
.map(option -> modelFactory.createModel(option, Option.class))
.collect(Collectors.toList());
this.options.addAll(optionsModels);
}

@Override
public Object getDefaultValue() {
return defaultValue;
}
}
Loading