/* * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2013, Geomatys * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; * version 2.1 of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ package org.geotoolkit.storage; import java.util.HashSet; import java.util.Set; import org.apache.sis.util.collection.DefaultTreeTable; import org.apache.sis.util.collection.TableColumn; import org.geotoolkit.gui.swing.tree.Trees; import javax.xml.bind.annotation.XmlTransient; /** * * @author Johann Sorel (Geomatys) */ @XmlTransient public class DefaultDataNode extends DefaultTreeTable.Node implements DataNode { protected final Set<StorageListener> listeners = new HashSet<>(); public DefaultDataNode() { super(""); } @Override public void addStorageListener(final StorageListener listener) { synchronized (listeners) { listeners.add(listener); } } @Override public void removeStorageListener(final StorageListener listener) { synchronized (listeners) { listeners.remove(listener); } } /** * Forward a structure event to all listeners. * @param event , event to send to listeners. */ protected void sendStructureEvent(final StorageEvent event){ final StorageListener[] lst; synchronized (listeners) { lst = listeners.toArray(new StorageListener[listeners.size()]); } for(final StorageListener listener : lst){ listener.structureChanged(event); } } /** * Forward a data event to all listeners. * @param event , event to send to listeners. */ protected void sendContentEvent(final StorageEvent event){ final StorageListener[] lst; synchronized (listeners) { lst = listeners.toArray(new StorageListener[listeners.size()]); } for(final StorageListener listener : lst){ listener.contentChanged(event); } } /** * Forward given event, changing the source by this object. * For implementation use only. * @param event */ public void forwardStructureEvent(StorageEvent event){ sendStructureEvent(event.copy(this)); } /** * Forward given event, changing the source by this object. * For implementation use only. * @param event */ public void forwardContentEvent(StorageEvent event){ sendContentEvent(event.copy(this)); } @Override public String toString() { final CharSequence name = getValue(TableColumn.NAME); return Trees.toString(name.toString(), getChildren()); } }