You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by ah...@apache.org on 2020/01/21 19:06:08 UTC
[isis] branch master updated: ISIS-2158: optimize wicket components
Brand*/Favicon (Serialization)
This is an automated email from the ASF dual-hosted git repository.
ahuber pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/isis.git
The following commit(s) were added to refs/heads/master by this push:
new 33ffc1d ISIS-2158: optimize wicket components Brand*/Favicon (Serialization)
33ffc1d is described below
commit 33ffc1df61775a27dc7fe67698debd79c54a9b5a
Author: Andi Huber <ah...@apache.org>
AuthorDate: Tue Jan 21 20:05:55 2020 +0100
ISIS-2158: optimize wicket components Brand*/Favicon (Serialization)
---
.../wicket/ui/components/WebComponentBase.java | 83 ++++++++++++++++++++++
.../ui/components/widgets/favicon/Favicon.java | 18 +++--
.../ui/components/widgets/navbar/BrandLogo.java | 17 +++--
.../ui/components/widgets/navbar/BrandName.java | 8 ++-
4 files changed, 105 insertions(+), 21 deletions(-)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java
new file mode 100644
index 0000000..db2d5fe
--- /dev/null
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/WebComponentBase.java
@@ -0,0 +1,83 @@
+/*
+ * 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 agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.isis.viewer.wicket.ui.components;
+
+import org.apache.wicket.markup.html.WebComponent;
+import org.apache.wicket.model.IModel;
+
+import org.apache.isis.core.config.IsisConfiguration;
+import org.apache.isis.core.config.viewer.wicket.WebAppContextPath;
+import org.apache.isis.core.webapp.context.IsisWebAppCommonContext;
+import org.apache.isis.viewer.wicket.model.common.CommonContextUtils;
+
+/**
+ * Provides all the system dependencies for sub-classes.
+ * @since 2.0
+ */
+public abstract class WebComponentBase
+extends WebComponent
+implements IsisWebAppCommonContext.Delegating {
+
+ public WebComponentBase(final String id) {
+ super(id);
+ }
+
+ public WebComponentBase(final String id, final IModel<?> model) {
+ super(id, model);
+ }
+
+ private static final long serialVersionUID = 1L;
+
+ private transient IsisConfiguration isisConfiguration;
+ private transient WebAppContextPath webAppContextPath;
+// private transient PageClassRegistry pageClassRegistry;
+ private transient IsisWebAppCommonContext commonContext;
+// private transient IsisSessionFactory isisSessionFactory;
+
+ @Override
+ public IsisWebAppCommonContext getCommonContext() {
+ return commonContext = CommonContextUtils.computeIfAbsent(commonContext);
+ }
+
+ public IsisConfiguration getIsisConfiguration() {
+ return isisConfiguration = computeIfAbsent(IsisConfiguration.class, isisConfiguration);
+ }
+
+ public WebAppContextPath getWebAppContextPath() {
+ return webAppContextPath = computeIfAbsent(WebAppContextPath.class, webAppContextPath);
+ }
+
+// public PageClassRegistry getPageClassRegistry() {
+// return pageClassRegistry = computeIfAbsent(PageClassRegistry.class, pageClassRegistry);
+// }
+//
+// public IsisSessionFactory getIsisSessionFactory() {
+// return isisSessionFactory = computeIfAbsent(IsisSessionFactory.class, isisSessionFactory);
+// }
+
+
+ // -- HELPER
+
+ private <X> X computeIfAbsent(Class<X> type, X existingIfAny) {
+ return existingIfAny!=null
+ ? existingIfAny
+ : getCommonContext().lookupServiceElseFail(type);
+ }
+
+}
\ No newline at end of file
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java
index 200abc8..59366ca 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/favicon/Favicon.java
@@ -18,25 +18,20 @@
*/
package org.apache.isis.viewer.wicket.ui.components.widgets.favicon;
-import javax.inject.Inject;
-
import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebComponent;
import org.apache.wicket.util.string.Strings;
-import org.apache.isis.core.config.IsisConfiguration;
-import org.apache.isis.core.config.viewer.wicket.WebAppContextPath;
+import org.apache.isis.viewer.wicket.ui.components.WebComponentBase;
+
+import lombok.val;
/**
* A component for application favorite icon
*/
-public class Favicon extends WebComponent {
+public class Favicon extends WebComponentBase {
private static final long serialVersionUID = 1L;
- @Inject private IsisConfiguration isisConfiguration; // serializable
- @Inject private WebAppContextPath webAppContextPath; // serializable
-
private String url = null;
private String contentType = null;
@@ -47,7 +42,10 @@ public class Favicon extends WebComponent {
@Override
protected void onConfigure() {
super.onConfigure();
-
+
+ val isisConfiguration = super.getIsisConfiguration();
+ val webAppContextPath = super.getWebAppContextPath();
+
url = isisConfiguration.getViewer().getWicket().getApplication().getFaviconUrl()
.filter(x -> !Strings.isEmpty(x))
.map(webAppContextPath::prependContextPathIfLocal)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandLogo.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandLogo.java
index de82097..a931745 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandLogo.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandLogo.java
@@ -18,26 +18,21 @@
*/
package org.apache.isis.viewer.wicket.ui.components.widgets.navbar;
-import javax.inject.Inject;
-
import org.apache.wicket.markup.ComponentTag;
-import org.apache.wicket.markup.html.WebComponent;
-import org.apache.isis.core.config.IsisConfiguration;
-import org.apache.isis.core.config.viewer.wicket.WebAppContextPath;
+import org.apache.isis.viewer.wicket.ui.components.WebComponentBase;
+
+import lombok.val;
/**
* A component used as a brand logo in the top-left corner of the navigation bar
*/
-public class BrandLogo extends WebComponent {
+public class BrandLogo extends WebComponentBase {
private static final long serialVersionUID = 1L;
private final Placement placement;
- @Inject private IsisConfiguration isisConfiguration; // serializable
- @Inject private WebAppContextPath webAppContextPath; // serializable
-
/**
* Constructor.
*
@@ -63,6 +58,10 @@ public class BrandLogo extends WebComponent {
}
private String url() {
+
+ val isisConfiguration = super.getIsisConfiguration();
+ val webAppContextPath = super.getWebAppContextPath();
+
final String logoHeaderUrl =
isisConfiguration.getViewer().getWicket().getApplication().getBrandLogoHeader()
.map(webAppContextPath::prependContextPathIfLocal)
diff --git a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandName.java b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandName.java
index 3638d04..f4213ae 100644
--- a/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandName.java
+++ b/viewers/wicket/ui/src/main/java/org/apache/isis/viewer/wicket/ui/components/widgets/navbar/BrandName.java
@@ -35,8 +35,8 @@ public class BrandName extends Label {
private final Placement placement;
- @Inject private IsisConfiguration isisConfiguration; // serializable
- @Inject private WebAppContextPath webAppContextPath; // serializable
+ @Inject private transient IsisConfiguration isisConfiguration;
+ @Inject private transient WebAppContextPath webAppContextPath;
private String logoHeaderUrl;
private String logoSigninUrl;
@@ -58,6 +58,10 @@ public class BrandName extends Label {
@Override
protected void onConfigure() {
super.onConfigure();
+
+ if(isisConfiguration==null) {
+ return; // simply skip when de-serializing, since (non-transient) fields are already populated
+ }
applicationName = isisConfiguration.getViewer().getWicket().getApplication().getName();
logoHeaderUrl =