You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2018/01/04 12:35:15 UTC

[isis] 03/03: ISIS-1747: adds hint-n-tip for wicket viewer

This is an automated email from the ASF dual-hosted git repository.

danhaywood pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git

commit 5c183f0db3d0aee5aff9775bcc5ecc26e27cefff
Author: Dan Haywood <da...@haywood-associates.co.uk>
AuthorDate: Thu Jan 4 12:34:58 2018 +0000

    ISIS-1747: adds hint-n-tip for wicket viewer
---
 .../asciidoc/guides/ugvw/_ugvw_hints-and-tips.adoc |  1 +
 ..._ugvw_hints-and-tips_highlight-current-row.adoc | 88 ++++++++++++++++++++++
 2 files changed, 89 insertions(+)

diff --git a/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips.adoc b/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips.adoc
index c856631..a6c2602 100644
--- a/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips.adoc
+++ b/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips.adoc
@@ -27,6 +27,7 @@ See also hints-n-tips chapters in the:
 
 include::_ugvw_hints-and-tips_per-user-themes.adoc[leveloffset=+1,lines=3..-1]
 include::_ugvw_hints-and-tips_i18n-label-in-wicket-viewer.adoc[leveloffset=+1,lines=3..-1]
+include::_ugvw_hints-and-tips_highlight-current-row.adoc[leveloffset=+1,lines=3..-1]
 include::_ugvw_hints-and-tips_svg-support.adoc[leveloffset=+1,lines=3..-1]
 
 
diff --git a/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips_highlight-current-row.adoc b/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips_highlight-current-row.adoc
new file mode 100644
index 0000000..2853ad5
--- /dev/null
+++ b/adocs/documentation/src/main/asciidoc/guides/ugvw/_ugvw_hints-and-tips_highlight-current-row.adoc
@@ -0,0 +1,88 @@
+:_basedir: ../../
+:_imagesdir: images/
+[[_ugvw_hints-and-tips_highlight-current-row]]
+= Highlight Current Row
+:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you 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 ag [...]
+
+
+Demo App: Highlighting Current
+As a by-the-by, the demo app has one further "trick up its sleeve".
+If you run the app you'll notice that the currently selected `DemoObject` is highlighted in the left-hand table of the `HomePageViewModel`.
+
+This is accomplished by having the view model collaborate with a subscribing domain service that configures a CSS class.
+
+We start by ensuring that the `DemoObject` emits an event for its CSS class:
+
+[source,java]
+.DemoObject.java
+----
+@DomainObjectLayout(
+...
+cssClassUiEvent = DemoObject.CssClassUiEvent.class
+)
+public class DemoObject ... {
+
+public static class CssClassUiEvent
+extends org.apache.isis.applib.services.eventbus.CssClassUiEvent<DemoObject> {}
+...
+}
+----
+
+Next, we define the domain service to act as the subscriber:
+
+[source,java]
+.HomePageViewModel.java
+----
+public class HomePageViewModel ... {
+    @DomainService(nature = NatureOfService.DOMAIN)
+    public static class CssHighlighter extends AbstractSubscriber {
+        @EventHandler
+        @Subscribe
+        public void on(DemoObject.CssClassUiEvent ev) {
+            if(getContext() == null) { return; }
+            if(ev.getSource() == getContext().getSelected()) {      // <1>
+                ev.setCssClass("selected");
+            }
+        }
+        private HomePageViewModel getContext() {                    // <2>
+            return (HomePageViewModel) scratchpad.get("context");
+        }
+        void setContext(final HomePageViewModel homePageViewModel) {
+            scratchpad.put("context", homePageViewModel);
+        }
+        @Inject
+        Scratchpad scratchpad;                                      // <3>
+    }
+}
+----
+<1> If the domain object is the currently selected then set the CSS class
+<2> Provide methods to set and get the current `HomePageViewModel` (acting as the context)
+<3> Store the context using the `Scratchpad` domain service (request-scoped so thread-safe).
+
+The `HomePageViewModel` is responsible for setting itself as the context for the domain service:
+
+[source,java]
+.HomePageViewModel.java
+----
+public class HomePageViewModel ... {
+    ...
+    public TranslatableString title() {
+        cssHighlighter.setContext(this);        // <1>
+        ...
+    }
+    ...
+    @javax.inject.Inject
+    CssHighlighter cssHighlighter;
+}
+----
+<1> set the context on the domain service
+
+Finally we just need some CSS, in the `application.css` file:
+
+[source,css]
+.application.css
+----
+.selected {
+    font-style: italic; font-weight: bolder;
+}
+----

-- 
To stop receiving notification emails like this one, please contact
"commits@isis.apache.org" <co...@isis.apache.org>.