001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.wicket.devutils.debugbar; 018 019import org.apache.wicket.Component; 020import org.apache.wicket.Page; 021import org.apache.wicket.devutils.pagestore.PageStorePage; 022import org.apache.wicket.model.IModel; 023import org.apache.wicket.pageStore.IPersistentPageStore; 024import org.apache.wicket.request.resource.PackageResourceReference; 025import org.apache.wicket.request.resource.ResourceReference; 026 027/** 028 * A panel that adds a link to persisted pages to the debug bar. 029 */ 030public class PageStoreDebugPanel extends StandardDebugPanel 031{ 032 private static final long serialVersionUID = 1L; 033 034 /** */ 035 public static final IDebugBarContributor DEBUG_BAR_CONTRIB = new IDebugBarContributor() 036 { 037 private static final long serialVersionUID = 1L; 038 039 @Override 040 public Component createComponent(final String id, final DebugBar debugBar) 041 { 042 return new PageStoreDebugPanel(id); 043 } 044 }; 045 046 /** 047 * Construct. 048 * 049 * @param id 050 * The component id 051 */ 052 public PageStoreDebugPanel(final String id) 053 { 054 super(id); 055 } 056 057 @Override 058 protected Class<? extends Page> getLinkPageClass() 059 { 060 return PageStorePage.class; 061 } 062 063 @Override 064 protected ResourceReference getImageResourceReference() 065 { 066 return new PackageResourceReference(PageStoreDebugPanel.class, "harddrive.png"); 067 } 068 069 @Override 070 protected IModel<String> getDataModel() 071 { 072 return new IModel<String>() 073 { 074 private static final long serialVersionUID = 1L; 075 076 @Override 077 public String getObject() 078 { 079 IPersistentPageStore store = PageStorePage.getPersistentPageStore(); 080 return String.format("Persisted pages: %s", store == null ? "N/A" : store.getTotalSize()); 081 } 082 }; 083 } 084}