kitaev@213: /* kitaev@213: * Copyright (c) 2011 TMate Software Ltd kitaev@213: * kitaev@213: * This program is free software; you can redistribute it and/or modify kitaev@213: * it under the terms of the GNU General Public License as published by kitaev@213: * the Free Software Foundation; version 2 of the License. kitaev@213: * kitaev@213: * This program is distributed in the hope that it will be useful, kitaev@213: * but WITHOUT ANY WARRANTY; without even the implied warranty of kitaev@213: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the kitaev@213: * GNU General Public License for more details. kitaev@213: * kitaev@213: * For information on how to redistribute this software under kitaev@213: * the terms of a license other than GNU General Public License kitaev@213: * contact TMate Software at support@hg4j.com kitaev@213: */ kitaev@213: package org.tmatesoft.hg.util; kitaev@213: kitaev@213: /** kitaev@213: * Mix-in to report progress of a long-running operation kitaev@213: * kitaev@213: * @author Artem Tikhomirov kitaev@213: * @author TMate Software Ltd. kitaev@213: */ kitaev@213: public interface ProgressSupport { kitaev@213: kitaev@213: public void start(long totalUnits); kitaev@213: public void worked(int units); kitaev@213: public void done(); kitaev@213: kitaev@213: static class Factory { kitaev@213: kitaev@213: /** kitaev@213: * @param target object that might be capable to report progress. Can be null kitaev@213: * @return support object extracted from target or an empty, no-op implementation kitaev@213: */ kitaev@213: public static ProgressSupport get(Object target) { kitaev@213: if (target instanceof ProgressSupport) { kitaev@213: return (ProgressSupport) target; kitaev@213: } kitaev@213: if (target instanceof Adaptable) { kitaev@213: ProgressSupport ps = ((Adaptable) target).getAdapter(ProgressSupport.class); kitaev@213: if (ps != null) { kitaev@213: return ps; kitaev@213: } kitaev@213: } kitaev@213: return new ProgressSupport() { kitaev@213: public void start(long totalUnits) { kitaev@213: } kitaev@213: public void worked(int units) { kitaev@213: } kitaev@213: public void done() { kitaev@213: } kitaev@213: }; kitaev@213: } kitaev@213: } kitaev@213: }