Class MarkdownDisplayConlet
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
Instances may be used as a kind of note, i.e. created and configured by a user himself. A typical use case, however, is to create an instance during startup by a web console policy.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
The web console component’s model.Nested classes/interfaces inherited from class org.jgrapes.webconsole.base.AbstractConlet
AbstractConlet.ConletTrackingInfo
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Property for forcing a conlet id (used for singleton instances).static final String
Boolean property that controls if the preview is deletable.static final String
Property of typeSet<Principal>
for restricting who can edit the content.protected static final com.fasterxml.jackson.databind.ObjectMapper
The mapper.static final String
Property for setting the preview source.static final String
Property for setting a title.static final String
Property for setting the view source.Fields inherited from class org.jgrapes.webconsole.base.AbstractConlet
TYPE_INSTANCE_SEPARATOR
-
Constructor Summary
ConstructorDescriptionMarkdownDisplayConlet
(Channel componentChannel) Creates a new component with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptioncreateNewState
(AddConletRequest event, ConsoleConnection session, String conletId) Creates a new model for the conlet.createStateRepresentation
(Event<?> event, ConsoleConnection channel, String conletId) Creates an instance of the type that represents the conlet’s state, initialized with default values.protected void
doConletDeleted
(ConletDeleted event, ConsoleConnection channel, String conletId, MarkdownDisplayConlet.MarkdownDisplayModel retrievedState) Called byAbstractConlet.onConletDeleted(org.jgrapes.webconsole.base.events.ConletDeleted, org.jgrapes.webconsole.base.ConsoleConnection)
to propagate the event to derived classes.protected Set
<Conlet.RenderMode> doRenderConlet
(RenderConletRequestBase<?> event, ConsoleConnection consoleConnection, String conletId, MarkdownDisplayConlet.MarkdownDisplayModel model) Called byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)
andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)
to complete rendering the web console component.protected void
doUpdateConletState
(NotifyConletModel event, ConsoleConnection connection, MarkdownDisplayConlet.MarkdownDisplayModel conletState) Called byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)
to complete handling the notification.protected String
generateInstanceId
(AddConletRequest event, ConsoleConnection session) Generates a new component instance id or uses the one stored in the event’s properties asCONLET_ID
(seeAddConletRequest.properties()
)void
onConsoleReady
(ConsoleReady event, ConsoleConnection connection) OnConsoleReady
, fire theAddConletType
.void
onUpdateConletModel
(UpdateConletModel event, ConsoleConnection connection) Stores the modified properties using aKeyValueStoreUpdate
event and updates the view with aNotifyConletView
.recreateState
(Event<?> event, ConsoleConnection channel, String conletId) Called when a previously created conlet (with associated state) is rendered in a new browser session for the first time.Methods inherited from class org.jgrapes.webconsole.base.freemarker.FreeMarkerConlet
doGetResource, fmConletModel, fmModel, fmModel, fmSessionModel, fmTypeModel, freemarkerConfig, processTemplate, processTemplate
Methods inherited from class org.jgrapes.webconsole.base.AbstractConlet
afterOnClosed, conletIds, conletIdsByConsoleConnection, conletViews, doRemoveConletType, doSetLocale, l10nBundles, localizations, onAddConletRequest, onClosed, onConletDeleted, onConletResourceRequest, onDetached, onNotifyConletModel, onRenderConletRequest, onSetLocale, putInSession, readContent, readContent, removeState, resourceBundle, setPeriodicRefresh, stateFromSession, statesFromSession, supportedLocales, trackConlet, trackedConnections, type, typeFromId
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
mapper
The mapper. -
CONLET_ID
Property for forcing a conlet id (used for singleton instances).- See Also:
-
TITLE
Property for setting a title.- See Also:
-
PREVIEW_SOURCE
Property for setting the preview source.- See Also:
-
VIEW_SOURCE
Property for setting the view source.- See Also:
-
DELETABLE
Boolean property that controls if the preview is deletable.- See Also:
-
EDITABLE_BY
Property of typeSet<Principal>
for restricting who can edit the content.- See Also:
-
-
Constructor Details
-
MarkdownDisplayConlet
Creates a new component with its channel set to the given channel.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to
-
-
Method Details
-
onConsoleReady
@Handler public void onConsoleReady(ConsoleReady event, ConsoleConnection connection) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException OnConsoleReady
, fire theAddConletType
.- Parameters:
event
- the eventconnection
- the console connection- Throws:
TemplateNotFoundException
- the template not found exceptionMalformedTemplateNameException
- the malformed template name exceptionParseException
- the parse exceptionIOException
- Signals that an I/O exception has occurred.
-
generateInstanceId
Generates a new component instance id or uses the one stored in the event’s properties asCONLET_ID
(seeAddConletRequest.properties()
)- Overrides:
generateInstanceId
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the event that triggered the creation of a new conlet, which may contain required information (seeAddConletRequest.properties()
)session
- the console connection; usually not required but provided as context- Returns:
- the web console component id
-
createStateRepresentation
protected Optional<MarkdownDisplayConlet.MarkdownDisplayModel> createStateRepresentation(Event<?> event, ConsoleConnection channel, String conletId) throws Exception Description copied from class:AbstractConlet
Creates an instance of the type that represents the conlet’s state, initialized with default values.The default implementation returns
Optional.isEmpty()
, thus indicating that no state information is needed or available.This method should always be overridden if conlet instances have associated state.
- Overrides:
createStateRepresentation
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the event, which may contain required information (seeAddConletRequest.properties()
)channel
- the console connection, sometimes required to send events to components that provide a backing storeconletId
- the conlet id calculated astype() + TYPE_INSTANCE_SEPARATOR + generateInstanceId(...)
- Returns:
- the state representation or
Optional.empty()
if none is required - Throws:
Exception
- if an exception occurs
-
createNewState
protected Optional<MarkdownDisplayConlet.MarkdownDisplayModel> createNewState(AddConletRequest event, ConsoleConnection session, String conletId) throws Exception Creates a new model for the conlet.The following properties are copied from the
AddConletRequest
event (seeAddConletRequest.properties()
:-
CONLET_ID
(String): The web console component id. -
TITLE
(String): The web console component title. -
PREVIEW_SOURCE
(String): The markdown source that is rendered in the web console component preview. -
VIEW_SOURCE
(String): The markdown source that is rendered in the web console component view. -
DELETABLE
(Boolean): Indicates that the web console component may be deleted from the overview page. -
EDITABLE_BY
(Set<Principal>): The principals that may edit the web console component instance.
- Overrides:
createNewState
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the eventsession
- the console connectionconletId
- the conlet id- Returns:
- the state representation or
Optional.empty()
if none is required - Throws:
Exception
- if an exception occurs
-
-
recreateState
protected Optional<MarkdownDisplayConlet.MarkdownDisplayModel> recreateState(Event<?> event, ConsoleConnection channel, String conletId) throws Exception Description copied from class:AbstractConlet
Called when a previously created conlet (with associated state) is rendered in a new browser session for the first time.The default implementation simply invokes
createStateRepresentation
and returns its result. Conlets with long-term state should retrieve their state from some storage. If state is returned, it is put in the browser session by the invoker.- Overrides:
recreateState
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the eventchannel
- the console connectionconletId
- the conlet id- Returns:
- the state representation or
Optional.empty()
if none is required - Throws:
Exception
- if an exception occurs
-
doRenderConlet
protected Set<Conlet.RenderMode> doRenderConlet(RenderConletRequestBase<?> event, ConsoleConnection consoleConnection, String conletId, MarkdownDisplayConlet.MarkdownDisplayModel model) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)
andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)
to complete rendering the web console component.The
- Specified by:
doRenderConlet
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the eventconsoleConnection
- the channelconletId
- the component idmodel
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Returns:
- the rendered modes
- Throws:
Exception
- the exception
-
doConletDeleted
protected void doConletDeleted(ConletDeleted event, ConsoleConnection channel, String conletId, MarkdownDisplayConlet.MarkdownDisplayModel retrievedState) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onConletDeleted(org.jgrapes.webconsole.base.events.ConletDeleted, org.jgrapes.webconsole.base.ConsoleConnection)
to propagate the event to derived classes.- Overrides:
doConletDeleted
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the eventchannel
- the channelconletId
- the web console component idretrievedState
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Throws:
Exception
- if a problem occurs
-
doUpdateConletState
protected void doUpdateConletState(NotifyConletModel event, ConsoleConnection connection, MarkdownDisplayConlet.MarkdownDisplayModel conletState) throws Exception Description copied from class:AbstractConlet
Called byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)
to complete handling the notification.The default implementation does nothing.
- Overrides:
doUpdateConletState
in classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>
- Parameters:
event
- the eventconnection
- the channelconletState
- the conlet’s state; may benull
if the conlet doesn’t have associated state information- Throws:
Exception
-
onUpdateConletModel
Stores the modified properties using aKeyValueStoreUpdate
event and updates the view with aNotifyConletView
.- Parameters:
event
- the eventconnection
- the console connection
-