Class JsonSchemaOutputComponent
- java.lang.Object
-
- javax.faces.component.UIComponent
-
- javax.faces.component.UIComponentBase
-
- javax.faces.component.UINamingContainer
-
- de.xima.fc.prompt.service.support.gui.component.JsonSchemaOutputComponent
-
- All Implemented Interfaces:
EventListener,javax.faces.component.NamingContainer,javax.faces.component.PartialStateHolder,javax.faces.component.StateHolder,javax.faces.component.TransientStateHolder,javax.faces.component.UniqueIdVendor,javax.faces.event.ComponentSystemEventListener,javax.faces.event.FacesListener,javax.faces.event.SystemEventListenerHolder
public class JsonSchemaOutputComponent extends javax.faces.component.UINamingContainer
-
-
Field Summary
-
Fields inherited from class javax.faces.component.UINamingContainer
COMPONENT_FAMILY, COMPONENT_TYPE, SEPARATOR_CHAR_PARAM_NAME
-
-
Constructor Summary
Constructors Constructor Description JsonSchemaOutputComponent()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PromptFancySelectItemgetDefinitionType()Finds thePromptFancySelectItemcorresponding to the currently selected definition type.List<PromptFancySelectItem>getDefinitionTypeOptions()Gets the localizedselect itemoptions with the possible values for thedefinition typeselect field that lets the user choose how they want to define the JSON schema.org.primefaces.extensions.model.monacoeditor.EditorOptionsgetJsonEditorOptionsForExampleInput()Gets theEditorOptionsfor the monaco editor used to edit the JSON example when the user chooses to define the JSON schema by providing a JSON example.org.primefaces.extensions.model.monacoeditor.EditorOptionsgetJsonEditorOptionsForManualInput()Gets theEditorOptionsfor the monaco editor used to edit the JSON schema when the user chooses to enter a JSON schema manually.StringgetPreviewSchema()Gets the generated JSON schema for previewing.List<javax.faces.model.SelectItem>getPropertyTypeOptions()StringgetSchemaTextEditorExtenderOptions()Get the options for creating the monaco editor extender that lets the user enter a JSON schema manually.booleanisAllowSchemaAdjustments()Gets whether schema adjustments are allowed.StringlocalizePropertyRequiredDisplayName(JsonSchemaOutputObjectProperty property)StringlocalizePropertyTypeDisplayName(JsonSchemaOutputObjectProperty property)voidonAddProperty(javax.faces.event.ActionEvent event)Callback invoked when the user clicks the "Add Property" button to add a new property to the list of properties.voidonConvertToManualInput()Callback invoked when the user presses the button to convert configuration to the manual schema input.voidonConvertToPropertyList()Callback invoked when the user presses the button to convert configuration to a list of properties.voidonConvertToVisualEditor()Callback invoked when the user presses the button to convert configuration to the visual editor configuration.voidonPreview()Callback invoked when the user clicks the "Preview" button to preview the generated JSON schema.voidonRemoveProperty(javax.faces.event.ActionEvent event)Callback invoked when the user clicks the "Remove" button next to a property in the list of properties.voidonTogglePropertyRequired(javax.faces.event.ActionEvent event)voidsetAllowSchemaAdjustments(boolean allowSchemaAdjustments)Sets whether schema adjustments are allowed.voidsetDefinitionType(PromptFancySelectItem item)Sets the selected task from the givenPromptFancySelectItem.-
Methods inherited from class javax.faces.component.UINamingContainer
createUniqueId, getFamily, getSeparatorChar, visitTree
-
Methods inherited from class javax.faces.component.UIComponentBase
addClientBehavior, addFacesListener, broadcast, clearInitialState, decode, encodeBegin, encodeChildren, encodeEnd, findComponent, getAttributes, getChildCount, getChildren, getClientBehaviors, getClientId, getDefaultEventName, getEventNames, getFacesContext, getFacesListeners, getFacet, getFacetCount, getFacets, getFacetsAndChildren, getId, getListenersForEventClass, getParent, getPassThroughAttributes, getRenderer, getRendererType, getRendersChildren, getValueBinding, invokeOnComponent, isRendered, isTransient, markInitialState, processDecodes, processRestoreState, processSaveState, processUpdates, processValidators, queueEvent, removeFacesListener, restoreAttachedState, restoreState, saveAttachedState, saveState, setId, setParent, setRendered, setRendererType, setTransient, setValueBinding, subscribeToEvent, unsubscribeFromEvent
-
Methods inherited from class javax.faces.component.UIComponent
encodeAll, getClientId, getCompositeComponentParent, getContainerClientId, getCurrentComponent, getCurrentCompositeComponent, getNamingContainer, getPassThroughAttributes, getResourceBundleMap, getStateHelper, getStateHelper, getTransientStateHelper, getTransientStateHelper, getValueExpression, initialStateMarked, isCompositeComponent, isInView, isVisitable, popComponentFromEL, processEvent, pushComponentToEL, restoreTransientState, saveTransientState, setInView, setValueExpression
-
-
-
-
Method Detail
-
getDefinitionType
public PromptFancySelectItem getDefinitionType()
Finds thePromptFancySelectItemcorresponding to the currently selected definition type.Access the
cc.attrs.valueattribute of the closestTaskComponentcomponent; which must be aJsonSchemaOutputinstance. Then, finds theoptionwhosevaluematches the selected value, and returns that option.This is a workaround for the
<p:selectOneMenu>component. We want to use a custom UI for each option, but PrimeFaces only makes the select item value available as an EL variable (which is a string). We need to access the entirePromptFancySelectItemthat contains the label and description to display.- Returns:
- The selected
PromptFancySelectItem, ornullif no option is selected.
-
setDefinitionType
public void setDefinitionType(PromptFancySelectItem item)
Sets the selected task from the givenPromptFancySelectItem.Access the
cc.attrs.valueattribute of the closestTaskComponentcomponent; which must be aJsonSchemaOutputinstance. Then writes thevalueof the given item to thedefinition typeproperty.This is a workaround for the
<p:selectOneMenu>component. We want to use a custom UI for each option, but PrimeFaces only makes the select item value available as an EL variable (which is a string). We need to access the entirePromptFancySelectItemthat contains the label and description to display.- Parameters:
item- The selectedPromptFancySelectItem, ornullto clear the selection.
-
getDefinitionTypeOptions
public List<PromptFancySelectItem> getDefinitionTypeOptions()
Gets the localizedselect itemoptions with the possible values for thedefinition typeselect field that lets the user choose how they want to define the JSON schema.- Returns:
- The select item options.
-
getJsonEditorOptionsForExampleInput
public org.primefaces.extensions.model.monacoeditor.EditorOptions getJsonEditorOptionsForExampleInput()
Gets theEditorOptionsfor the monaco editor used to edit the JSON example when the user chooses to define the JSON schema by providing a JSON example.- Returns:
- The editor options.
-
getJsonEditorOptionsForManualInput
public org.primefaces.extensions.model.monacoeditor.EditorOptions getJsonEditorOptionsForManualInput()
Gets theEditorOptionsfor the monaco editor used to edit the JSON schema when the user chooses to enter a JSON schema manually.- Returns:
- The editor options.
-
getPreviewSchema
public String getPreviewSchema()
Gets the generated JSON schema for previewing. This is set when the user clicks the "Preview" button, seeonPreview().- Returns:
- The generated JSON schema, or
nullif preview has not been generated yet.
-
getPropertyTypeOptions
public List<javax.faces.model.SelectItem> getPropertyTypeOptions()
-
getSchemaTextEditorExtenderOptions
public String getSchemaTextEditorExtenderOptions()
Get the options for creating the monaco editor extender that lets the user enter a JSON schema manually.- Returns:
- The options as a serialized JSON string.
-
isAllowSchemaAdjustments
public boolean isAllowSchemaAdjustments()
Gets whether schema adjustments are allowed. This is the inverse of the model'sforbidSchemaAdjustmentsproperty.- Returns:
- True if schema adjustments are allowed, false if they are forbidden.
-
setAllowSchemaAdjustments
public void setAllowSchemaAdjustments(boolean allowSchemaAdjustments)
Sets whether schema adjustments are allowed. This is the inverse of the model'sforbidSchemaAdjustmentsproperty.- Parameters:
allowSchemaAdjustments- True to allow schema adjustments, false to forbid them.
-
localizePropertyRequiredDisplayName
public String localizePropertyRequiredDisplayName(JsonSchemaOutputObjectProperty property)
-
localizePropertyTypeDisplayName
public String localizePropertyTypeDisplayName(JsonSchemaOutputObjectProperty property)
-
onAddProperty
public void onAddProperty(javax.faces.event.ActionEvent event)
Callback invoked when the user clicks the "Add Property" button to add a new property to the list of properties. Creates a newJsonSchemaOutputObjectPropertyinstance with default values and adds it to the list of properties in theJsonSchemaOutputByPropertyListinstance.- Parameters:
event- The action event from the button click.
-
onConvertToManualInput
public void onConvertToManualInput()
Callback invoked when the user presses the button to convert configuration to the manual schema input. Extracts the JSON schema from theJsonSchemaOutputinstance and sets it as the active configuration.
-
onConvertToPropertyList
public void onConvertToPropertyList()
Callback invoked when the user presses the button to convert configuration to a list of properties. Extracts the JSON schema from theJsonSchemaOutputinstance, converts it to a list of properties, and sets it as the active configuration.
-
onConvertToVisualEditor
public void onConvertToVisualEditor()
Callback invoked when the user presses the button to convert configuration to the visual editor configuration. Extracts the JSON schema from theJsonSchemaOutputinstance, converts it the visual editor format, and sets it as the active configuration.
-
onPreview
public void onPreview()
Callback invoked when the user clicks the "Preview" button to preview the generated JSON schema. Generates the JSON schema from the current configuration and shows it in a dialog.
-
onRemoveProperty
public void onRemoveProperty(javax.faces.event.ActionEvent event)
Callback invoked when the user clicks the "Remove" button next to a property in the list of properties. Removes the property at the current index from the list of properties in theJsonSchemaOutputByPropertyListinstance.- Parameters:
event- The action event from the button click.
-
onTogglePropertyRequired
public void onTogglePropertyRequired(javax.faces.event.ActionEvent event)
-
-