001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.gwt.client.ui.tree; 029 030import com.google.gwt.event.logical.shared.OpenEvent; 031import com.google.gwt.user.client.Timer; 032 033/** 034 * Lazy list tree open handler abstract implementation.<p> 035 * 036 * @param <I> the specific lazy tree item implementation 037 * 038 * @since 8.0.0 039 * 040 * @see org.opencms.gwt.client.ui.tree.CmsLazyTree 041 * @see org.opencms.gwt.client.ui.tree.CmsLazyTreeItem 042 * @see org.opencms.gwt.client.ui.tree.I_CmsLazyOpenHandler 043 */ 044public abstract class A_CmsLazyOpenHandler<I extends CmsLazyTreeItem> implements I_CmsLazyOpenHandler<I> { 045 046 /** 047 * Timer for showing the loading message.<p> 048 */ 049 private final class OpenTimer extends Timer { 050 051 /** The tree item to open. */ 052 private I m_target; 053 054 /** 055 * Default constructor.<p> 056 * 057 * @param target the tree item to open 058 */ 059 public OpenTimer(I target) { 060 061 m_target = target; 062 } 063 064 /** 065 * @see com.google.gwt.user.client.Timer#run() 066 */ 067 @Override 068 public void run() { 069 070 m_target.setOpen(true, false); 071 onFinishOpen(m_target); 072 } 073 074 } 075 076 /** 077 * Called when the opening process has finished and the children (if any) are visible. 078 * 079 * @param target the target tree item 080 */ 081 public void onFinishOpen(I target) { 082 083 // do nothing 084 085 } 086 087 /** 088 * @see org.opencms.gwt.client.ui.tree.I_CmsLazyOpenHandler#onOpen(com.google.gwt.event.logical.shared.OpenEvent) 089 */ 090 public void onOpen(OpenEvent<I> event) { 091 092 I target = event.getTarget(); 093 if (target.getLoadState() != CmsLazyTreeItem.LoadState.UNLOADED) { 094 return; 095 } 096 final OpenTimer timer = new OpenTimer(target); 097 timer.schedule(500); 098 target.onStartLoading(); 099 target.setOpen(false, false); 100 load(target, () -> { 101 timer.cancel(); 102 timer.run(); 103 }); 104 } 105}