Skip to content

Commit

Permalink
implementing issue JPPF-578
Browse files Browse the repository at this point in the history
- all images and css are used as shared resources from the classpath
  • Loading branch information
lolocohen committed Feb 24, 2019
1 parent 272b085 commit fa1902e
Show file tree
Hide file tree
Showing 90 changed files with 229 additions and 18 deletions.
5 changes: 1 addition & 4 deletions admin-web/src/java/org/jppf/admin/web/HeaderPanel.html
Expand Up @@ -29,10 +29,7 @@
<td align="right" style="white-space: nowrap">
<h4 wicket:id="jppf.header.user" style="margin: 0px"></h4>
<form wicket:id="login.signout.form">
<a wicket:id="login.signout.link" href="" style="text-decoration: underline; color: #6D78B6">
<img src="images/exit.png" style="margin-right: 5px"/>
<wicket:message key="jppf.header.sign_out.label"></wicket:message>
</a><br>
<a wicket:id="login.signout.link" href="" style="text-decoration: underline; color: #6D78B6"><img src="images/exit.png" style="margin-right: 5px"/><wicket:message key="jppf.header.sign_out.label"></wicket:message></a><br>
<input type="checkbox" wicket:id="jppf.header.show.ip"/>
<wicket:message key="jppf.header.show.ip.label"></wicket:message>
</form>
Expand Down
2 changes: 1 addition & 1 deletion admin-web/src/java/org/jppf/admin/web/HeaderPanel.java
Expand Up @@ -46,7 +46,6 @@ public class HeaderPanel extends Panel {
public HeaderPanel() {
super("jppf.header");
final String user = JPPFWebSession.getSignedInUser();
//String user = JPPFWebSession.get().getUserName();
final Locale locale = Session.get().getLocale();
final String s = (user != null)
? LocalizationUtils.getLocalized(getClass().getName(), "jppf.header.user.label", locale) + " " + user
Expand All @@ -62,6 +61,7 @@ protected void onSubmit(final AjaxRequestTarget target, final Form<?> form) {
setResponsePage(getApplication().getHomePage());
}
};

form.add(link);
showIPCheckBox = new CheckBox("jppf.header.show.ip", Model.of(JPPFWebSession.get().isShowIP())) {
@Override
Expand Down
Expand Up @@ -26,11 +26,14 @@
import org.apache.wicket.page.*;
import org.apache.wicket.pageStore.*;
import org.apache.wicket.pageStore.memory.*;
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.resource.*;
import org.jppf.admin.web.admin.*;
import org.jppf.admin.web.auth.LoginPage;
import org.jppf.admin.web.settings.*;
import org.jppf.admin.web.stats.StatsUpdater;
import org.jppf.admin.web.topology.TopologyPage;
import org.jppf.admin.web.utils.ClasspathResource;
import org.jppf.client.JPPFClient;
import org.jppf.client.monitoring.jobs.*;
import org.jppf.client.monitoring.topology.TopologyManager;
Expand Down Expand Up @@ -88,6 +91,15 @@ public JPPFWebConsoleApplication() {
@Override
protected void init() {
super.init();
mountImageResource("images/exit.png");
mountImageResource("images/logo.gif");
mountImageResource("images/logo-small.gif");
mountImageResource("images/toolbar/upload.png");
mountImageResource("jppf.css");
mountImageResource("images/arrow-right-double-2.png");
mountImageResource("images/arrow-left-double-2.png");
mountImageResource("images/arrow-up-double-2.png");
mountImageResource("images/arrow-down-double-2.png");
String name = getInitParameter("jppfPersistenceClassName");
if (debugEnabled) log.debug("read persistence class name '{}' from init parameter", name);
if (name == null) {
Expand Down Expand Up @@ -219,9 +231,7 @@ private static final class MyPageManagerProvider extends DefaultPageManagerProvi

@Override protected IDataStore newDataStore() {
// keep everything in memory
return new HttpSessionDataStore(new DefaultPageManagerContext(), new IDataStoreEvictionStrategy() {
@Override public void evict(final PageTable pageTable) { }
});
return new HttpSessionDataStore(new DefaultPageManagerContext(), pageTable -> {});
}

@Override protected IPageStore newPageStore(final IDataStore dataStore) { return new NullPageStore(); }
Expand All @@ -240,4 +250,41 @@ private static class NullPageStore implements IPageStore {
@Override public Object restoreAfterSerialization(final Serializable serializable) { return null; }
@Override public IManageablePage convertToPage(final Object page) { return null; }
}

/**
*
* @param key the resource key.
* @return a {@link ResourceReference} pointing to the image.
*/
public ResourceReference getSharedImageResource(final String key) {
ResourceReference ref = getSharedResources().get(key);
if (ref == null) {
final ClasspathResource resource = new ClasspathResource(key);
getSharedResources().add(key, resource);
ref = getSharedResources().get(key);
}
return ref;
}

/**
*
* @param key the resource key.
* @return the url of the shared image.
*/
public String getSharedImageURL(final String key) {
final ResourceReference ref = getSharedImageResource(key);
if (ref == null) return null;
String resourceURL = RequestCycle.get().urlFor(ref, null).toString();
if (resourceURL.startsWith("./")) resourceURL = resourceURL.substring(1);
return resourceURL;
}

/**
* Mount the resource with the specified key.
* @param key the resource key.
*/
public void mountImageResource(final String key) {
final ResourceReference ref = getSharedImageResource(key);
mountResource("/" + key, ref);
}
}
Expand Up @@ -23,6 +23,8 @@
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.image.ContextImage;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.request.cycle.RequestCycle;
import org.jppf.admin.web.JPPFWebConsoleApplication;

/**
* A panel that associates a label with an icon.
Expand All @@ -38,8 +40,11 @@ public class NodeContent extends Panel {
*/
public NodeContent(final String id, final DefaultMutableTreeNode treeNode, final TreeNodeRenderer renderer, final boolean showIP) {
super(id);
final String contextPath = RequestCycle.get().getRequest().getContextPath();
final String iconPath = renderer.getIconPath(treeNode);
add(new ContextImage("icon", (iconPath != null) ? iconPath : ""));
final String resourceURL = (iconPath != null) ? JPPFWebConsoleApplication.get().getSharedImageURL(iconPath) : null;
//if (debugEnabled) log.debug("resourceURL for key = {}: {}", iconPath, resourceURL);
add(new ContextImage("icon", (resourceURL != null) ? contextPath + resourceURL : ""));
final String text = renderer.getText(treeNode, showIP);
add(new Label("text", (text != null) ? text : ""));
}
Expand Down
Expand Up @@ -23,15 +23,24 @@
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.model.*;
import org.apache.wicket.request.cycle.RequestCycle;
import org.jppf.admin.web.AbstractJPPFPage;
import org.jppf.admin.web.*;
import org.jppf.admin.web.tabletree.*;
import org.jppf.utils.*;
import org.slf4j.*;

/**
*
* @author Laurent Cohen
*/
public abstract class AbstractActionLink extends AjaxLink<String> {
/**
* Logger for this class.
*/
private static final Logger log = LoggerFactory.getLogger(AbstractActionLink.class);
/**
* Determines whether the debug level is enabled in the log configuration, without the cost of a method call.
*/
private static final boolean debugEnabled = log.isDebugEnabled();
/**
* Determines whether this link is enabled and/or authorized.
*/
Expand Down Expand Up @@ -74,12 +83,20 @@ public AbstractActionLink(final String id, final IModel<String> model, final Str
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
final Pair<String, String> pair = FileUtils.getFileNameAndExtension(imageName);
final String format = "<img src='" + RequestCycle.get().getRequest().getContextPath() + "/images/toolbar/%s.%s'/>";
final String contextPath = RequestCycle.get().getRequest().getContextPath();
String imageKey = null;
if ((action != null) && (!action.isEnabled() || !action.isAuthorized())) {
tag.getAttributes().put("class", "button_link_disabled");
if (pair != null) setBody(Model.of(String.format(format, pair.first() + "-disabled", pair.second())));
if (pair != null) imageKey = pair.first() + "-disabled";
} else {
if (pair != null) setBody(Model.of(String.format(format, pair.first(), pair.second())));
if (pair != null) imageKey = pair.first();
}
if (imageKey != null) {
imageKey = "images/toolbar/" + imageKey + "." + pair.second();
final String resourceURL = JPPFWebConsoleApplication.get().getSharedImageURL(imageKey);
final String html = "<img src='" + contextPath + resourceURL + "'/>";
setBody(Model.of(html));
if (debugEnabled) log.debug("image html for key = {}, contextPath = {}: {}", imageKey, contextPath, html);
}
setEscapeModelStrings(false);
}
Expand Down
Expand Up @@ -22,7 +22,7 @@
import org.apache.wicket.markup.ComponentTag;
import org.apache.wicket.model.*;
import org.apache.wicket.request.cycle.RequestCycle;
import org.jppf.admin.web.AbstractJPPFPage;
import org.jppf.admin.web.*;
import org.jppf.utils.*;

/**
Expand Down Expand Up @@ -102,12 +102,19 @@ protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
final Pair<String, String> pair = FileUtils.getFileNameAndExtension(imageName);
final StringBuilder style = new StringBuilder();
final String format = "background-image: url(" + RequestCycle.get().getRequest().getContextPath() + "/images/toolbar/%s.%s)";

final String contextPath = RequestCycle.get().getRequest().getContextPath();
String imageKey = null;
if ((action != null) && (!action.isEnabled() || !action.isAuthorized())) {
tag.getAttributes().put("class", "button_link_disabled");
if (pair != null) style.append(String.format(format, pair.first() + "-disabled", pair.second()));
if (pair != null) imageKey = pair.first() + "-disabled";
} else {
if (pair != null) style.append(String.format(format, pair.first(), pair.second()));
if (pair != null) imageKey = pair.first();
}
if (imageKey != null) {
imageKey = "images/toolbar/" + imageKey + "." + pair.second();
final String resourceURL = JPPFWebConsoleApplication.get().getSharedImageURL(imageKey);
style.append("background-image: url(" + contextPath + resourceURL + ")");
}
tag.getAttributes().put("style", style.append(FIXED_STYLE).toString());
}
Expand Down
92 changes: 92 additions & 0 deletions admin-web/src/java/org/jppf/admin/web/utils/ClasspathResource.java
@@ -0,0 +1,92 @@
/*
* JPPF.
* Copyright (C) 2005-2018 JPPF Team.
* http://www.jppf.org
*
* Licensed 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.jppf.admin.web.utils;

import java.io.*;

import org.apache.wicket.request.resource.ResourceStreamResource;
import org.apache.wicket.request.resource.caching.IResourceCachingStrategy;
import org.apache.wicket.util.resource.*;
import org.apache.wicket.util.time.Time;

/**
* A resource loaded from the classpath.
* @author Laurent Cohen
*/
public class ClasspathResource extends ResourceStreamResource {
/**
* Path to the resource in the classpath.
*/
private final String path;

/**
* @param path the path to the resource in the classpath.
*/
public ClasspathResource(final String path) {
this.path = path;
setFileName(new File(path).getName());
}

@Override
protected IResourceStream getResourceStream() {
return new ClasspathResourceStream(path);
}

@Override
protected IResourceCachingStrategy getCachingStrategy() {
return super.getCachingStrategy();
}

/**
* Resource stream associated with a {@link ClasspathResource}.
*/
public static class ClasspathResourceStream extends AbstractResourceStream {
/**
* Path to the resource in the classpath.
*/
private final String path;
/**
* Last modified date, equal to the creation date.
*/
private final Time lastModified = Time.millis(System.currentTimeMillis());

/**
* @param path the path to the resource in the classpath.
*/
public ClasspathResourceStream(final String path) {
this.path = path;
}

@Override
public InputStream getInputStream() throws ResourceStreamNotFoundException {
final InputStream is = getClass().getClassLoader().getResourceAsStream(path);
if (is == null) throw new ResourceStreamNotFoundException();
return is;
}

@Override
public void close() throws IOException {
}

@Override
public Time lastModifiedTime() {
return lastModified;
}
}
}
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
48 changes: 47 additions & 1 deletion admin-web/webapp/jppf.css → admin-web/src/resources/jppf.css
Expand Up @@ -638,4 +638,50 @@ scrollable, div.scrollable {
white-space: nowrap;
width: 100%;
overflow: scroll;
}
}

.palette-theme-default .palette-buttons {
float: left;
text-align: center;
padding-left: 10px;
padding-right: 10px;
}

.palette-theme-default .palette-buttons button {
display: block;
padding: 0px;
}
.palette-theme-default .palette-buttons button div {
height: 16px;
width: 16px;
}

.palette-theme-default .palette-buttons button.palette-add div {
content: none;
background: transparent url(images/arrow-right-double-2.png) no-repeat scroll center center;
}
.palette-theme-default .palette-buttons button.palette-remove div {
content: none;
background: transparent url(images/arrow-left-double-2.png) no-repeat scroll center center;
}
.palette-theme-default .palette-buttons button.palette-up div {
content: none;
background: transparent url(images/arrow-up-double-2.png) no-repeat scroll center center;
}
.palette-theme-default .palette-buttons button.palette-down div {
content: none;
background: transparent url(images/arrow-down-double-2.png) no-repeat scroll center center;
}

.palette-theme-default .palette-buttons button.palette-add div:after {
content: none;
}
.palette-theme-default .palette-buttons button.palette-remove div:after {
content: none;
}
.palette-theme-default .palette-buttons button.palette-up div:after {
content: none;
}
.palette-theme-default .palette-buttons button.palette-down div:after {
content: none;
}

0 comments on commit fa1902e

Please sign in to comment.