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
Nested ClassesModifier and TypeClassDescriptionstatic classThe web console component’s model.Nested classes/interfaces inherited from class org.jgrapes.webconsole.base.AbstractConlet
AbstractConlet.ConletTrackingInfoNested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty for forcing a conlet id (used for singleton instances).static final StringBoolean property that controls if the preview is deletable.static final StringProperty of typeSet<Principal>for restricting who can edit the content.protected static final com.fasterxml.jackson.databind.ObjectMapperThe mapper.static final StringProperty for setting the preview source.static final StringProperty for setting a title.static final StringProperty for setting the view source.Fields inherited from class org.jgrapes.webconsole.base.AbstractConlet
TYPE_INSTANCE_SEPARATOR -
Constructor Summary
ConstructorsConstructorDescriptionMarkdownDisplayConlet(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 voiddoConletDeleted(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 voiddoUpdateConletState(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 StringgenerateInstanceId(AddConletRequest event, ConsoleConnection session) Generates a new component instance id or uses the one stored in the event’s properties asCONLET_ID(seeAddConletRequest.properties())voidonConsoleReady(ConsoleReady event, ConsoleConnection connection) OnConsoleReady, fire theAddConletType.voidonUpdateConletModel(UpdateConletModel event, ConsoleConnection connection) Stores the modified properties using aKeyValueStoreUpdateevent 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, processTemplateMethods 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, typeFromIdMethods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods 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, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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:
generateInstanceIdin 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:AbstractConletCreates 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:
createStateRepresentationin 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
AddConletRequestevent (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:
createNewStatein 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:AbstractConletCalled when a previously created conlet (with associated state) is rendered in a new browser session for the first time.The default implementation simply invokes
createStateRepresentationand 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:
recreateStatein 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:AbstractConletCalled byAbstractConlet.onAddConletRequest(AddConletRequest, ConsoleConnection)andAbstractConlet.onRenderConletRequest(RenderConletRequest, ConsoleConnection)to complete rendering the web console component.The
- Specified by:
doRenderConletin classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>- Parameters:
event- the eventconsoleConnection- the channelconletId- the component idmodel- the conlet’s state; may benullif 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:AbstractConletCalled byAbstractConlet.onConletDeleted(org.jgrapes.webconsole.base.events.ConletDeleted, org.jgrapes.webconsole.base.ConsoleConnection)to propagate the event to derived classes.- Overrides:
doConletDeletedin classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>- Parameters:
event- the eventchannel- the channelconletId- the web console component idretrievedState- the conlet’s state; may benullif 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:AbstractConletCalled byAbstractConlet.onNotifyConletModel(org.jgrapes.webconsole.base.events.NotifyConletModel, org.jgrapes.webconsole.base.ConsoleConnection)to complete handling the notification.The default implementation does nothing.
- Overrides:
doUpdateConletStatein classAbstractConlet<MarkdownDisplayConlet.MarkdownDisplayModel>- Parameters:
event- the eventconnection- the channelconletState- the conlet’s state; may benullif the conlet doesn’t have associated state information- Throws:
Exception
-
onUpdateConletModel
Stores the modified properties using aKeyValueStoreUpdateevent and updates the view with aNotifyConletView.- Parameters:
event- the eventconnection- the console connection
-