-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add noColor checkbox to ColorPickerField
- Loading branch information
eschleb
committed
Nov 21, 2024
1 parent
205aeff
commit dcc4024
Showing
5 changed files
with
77 additions
and
9 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
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
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
29 changes: 27 additions & 2 deletions
29
...n/java/com/merkle/oss/magnolia/definition/custom/colorpicker/ColorPickerFieldFactory.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 |
---|---|---|
@@ -1,19 +1,44 @@ | ||
package com.merkle.oss.magnolia.definition.custom.colorpicker; | ||
|
||
import com.vaadin.ui.Component; | ||
|
||
import info.magnolia.i18nsystem.FixedLocaleProvider; | ||
import info.magnolia.i18nsystem.TranslationService; | ||
import info.magnolia.objectfactory.ComponentProvider; | ||
import info.magnolia.ui.editor.LocaleContext; | ||
import info.magnolia.ui.field.factory.AbstractFieldFactory; | ||
|
||
import java.util.Optional; | ||
|
||
import javax.inject.Inject; | ||
|
||
public class ColorPickerFieldFactory extends AbstractFieldFactory<Integer, ColorPickerFieldDefinition> { | ||
final ColorPickerFieldDefinition definition; | ||
private final LocaleContext localeContext; | ||
private final TranslationService translationService; | ||
|
||
public ColorPickerFieldFactory(final ColorPickerFieldDefinition definition, final ComponentProvider componentProvider) { | ||
@Inject | ||
public ColorPickerFieldFactory( | ||
final ColorPickerFieldDefinition definition, | ||
final ComponentProvider componentProvider, | ||
final LocaleContext localeContext, | ||
final TranslationService translationService | ||
) { | ||
super(definition, componentProvider); | ||
this.definition = definition; | ||
this.localeContext = localeContext; | ||
this.translationService = translationService; | ||
} | ||
|
||
@Override | ||
protected Component createFieldComponent() { | ||
return new ColorPickerField(definition); | ||
return new ColorPickerField(definition, getLabel()); | ||
} | ||
|
||
private String getLabel() { | ||
final String key = Optional | ||
.ofNullable(definition.getNoColorCheckboxLabelKey()) | ||
.orElse("merkle.customDefinitions.colorpicker.noColorCheckbox.fallbackLabel"); | ||
return translationService.translate(new FixedLocaleProvider(localeContext.getCurrent()), new String[] { key }); | ||
} | ||
} |
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