All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.vectorpublish.desktop.vp.NodeSelectionChangeImpl Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2016, Peter Rader. All rights reserved.
 *  ___ ___               __                 ______         __     __  __         __
 * |   |   |.-----..----.|  |_ .-----..----.|   __ \.--.--.|  |--.|  ||__|.-----.|  |--.
 * |   |   ||  -__||  __||   _||  _  ||   _||    __/|  |  ||  _  ||  ||  ||__ --||     |
 *  \_____/ |_____||____||____||_____||__|  |___|   |_____||_____||__||__||_____||__|__|
 *
 * http://www.gnu.org/licenses/gpl-3.0.html
 */
package net.vectorpublish.desktop.vp;

import java.util.LinkedHashSet;
import java.util.Set;

import javax.inject.Named;
import javax.swing.event.TreeExpansionEvent;
import javax.swing.event.TreeExpansionListener;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;

import org.springframework.beans.factory.annotation.Autowired;

import net.vectorpublish.desktop.vp.api.vpd.VectorPublishNode;
import net.vectorpublish.desktop.vp.system.UnmodifiableSingleSet;

@Named
public class NodeSelectionChangeImpl implements TreeSelectionListener, TreeExpansionListener {

	@Autowired(required = false)
	private final NodeSelectionChangeListener[] listeners = new NodeSelectionChangeListener[0];

	@Autowired(required = false)
	private final NodeExpandedChangeListener[] expListeners = new NodeExpandedChangeListener[0];

	@Autowired(required = false)
	private final NodeCollapseChangeListener[] colListeners = new NodeCollapseChangeListener[0];

	private LinkedHashSet deferred;

	@Override
	public void valueChanged(TreeSelectionEvent e) {
		for (NodeSelectionChangeListener nodeSelectionChangeListener : listeners) {
			nodeSelectionChangeListener.changedNodeSelection();
		}
	}

	@Override
	public void treeExpanded(TreeExpansionEvent event) {
		VectorPublishNode node = (VectorPublishNode) event.getPath().getLastPathComponent();
		if (deferred != null) {
			deferred.add(node);
			return;
		}
		Set set = new UnmodifiableSingleSet(node);
		for (NodeExpandedChangeListener listener : expListeners) {
			listener.expanded(set);
		}
	}

	@Override
	public void treeCollapsed(TreeExpansionEvent event) {
		VectorPublishNode node = (VectorPublishNode) event.getPath().getLastPathComponent();
		Set set = new UnmodifiableSingleSet<>(node);
		for (NodeCollapseChangeListener listener : colListeners) {
			listener.collapse(set);
		}
	}

	public synchronized void startMassiveExpanding() {
		deferred = new LinkedHashSet();
	}

	public synchronized void finishMassiveExpanding() {
		for (NodeExpandedChangeListener listener : expListeners) {
			listener.expanded(deferred);
		}
		deferred = null;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy