-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Gulshan Mishra
committed
Sep 27, 2023
1 parent
df12bc8
commit 2dcbaae
Showing
46 changed files
with
2,044 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
.../src/main/java/com/adobe/cq/forms/core/components/internal/models/v1/form/SwitchImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2023 Adobe | ||
~ | ||
~ 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.adobe.cq.forms.core.components.internal.models.v1.form; | ||
|
||
import javax.annotation.PostConstruct; | ||
|
||
import org.apache.sling.api.SlingHttpServletRequest; | ||
import org.apache.sling.api.resource.Resource; | ||
import org.apache.sling.models.annotations.Exporter; | ||
import org.apache.sling.models.annotations.Model; | ||
import org.apache.sling.models.annotations.injectorspecific.InjectionStrategy; | ||
import org.apache.sling.models.annotations.injectorspecific.ValueMapValue; | ||
|
||
import com.adobe.cq.export.json.ComponentExporter; | ||
import com.adobe.cq.export.json.ExporterConstants; | ||
import com.adobe.cq.forms.core.components.internal.form.FormConstants; | ||
import com.adobe.cq.forms.core.components.models.form.Switch; | ||
import com.adobe.cq.forms.core.components.util.AbstractOptionsFieldImpl; | ||
|
||
@Model( | ||
adaptables = { SlingHttpServletRequest.class, Resource.class }, | ||
adapters = { Switch.class, | ||
ComponentExporter.class }, | ||
resourceType = { FormConstants.RT_FD_FORM_SWITCH_V1 }) | ||
@Exporter(name = ExporterConstants.SLING_MODEL_EXPORTER_NAME, extensions = ExporterConstants.SLING_MODEL_EXTENSION) | ||
public class SwitchImpl extends AbstractOptionsFieldImpl implements Switch { | ||
|
||
// when a checkbox is not checked, it will still have a value representing its unchecked state, rather than having | ||
// a null value. This configuration allows for a distinct value when the checkbox is in an unchecked state. | ||
@ValueMapValue(injectionStrategy = InjectionStrategy.OPTIONAL, name = "enableUncheckedValue") | ||
private Boolean enableUncheckedValue; | ||
|
||
@PostConstruct | ||
private void initSwitchModel() { | ||
String[] enumNameArray = this.getEnumNames(); | ||
if (!Type.BOOLEAN.equals(type)) { | ||
if (Boolean.TRUE.equals(enableUncheckedValue)) { | ||
enums = new String[] { this.getEnums()[0].toString(), this.getEnums()[1].toString() }; | ||
enumNames = new String[] { this.getEnumNames()[0], this.getEnumNames()[1] }; | ||
} else { | ||
enums = new String[] { this.getEnums()[0].toString() }; | ||
enumNames = new String[] { enumNameArray[0] }; | ||
} | ||
} else { | ||
if (Boolean.TRUE.equals(enableUncheckedValue)) { | ||
enums = new String[] { "true", "false" }; | ||
enumNames = new String[] { "true", "false" }; | ||
} else { | ||
enums = new String[] { "true" }; | ||
enumNames = new String[] { "true" }; | ||
} | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
bundles/af-core/src/main/java/com/adobe/cq/forms/core/components/models/form/Switch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
~ Copyright 2023 Adobe | ||
~ | ||
~ 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.adobe.cq.forms.core.components.models.form; | ||
|
||
import org.osgi.annotation.versioning.ConsumerType; | ||
|
||
/** | ||
* Defines the {@code Switch} Sling Model used for the {@code /apps/core/fd/components/form/switch} component. | ||
* | ||
* @since com.adobe.cq.forms.core.components.models 4.5.1 | ||
*/ | ||
@ConsumerType | ||
public interface Switch extends CheckBox {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.