<commit_before>/***
 * Copyright (c) 2008, <NAME>.
 * All rights reserved.
 *
 * The OBDA-API is licensed under the terms of the Lesser General Public
 * License v.3 (see OBDAAPI_LICENSE.txt for details). The components of this
 * work include:
 * 
 * a) The OBDA-API developed by the author and licensed under the LGPL; and, 
 * b) third-party components licensed under terms that may be different from 
 *   those of the LGPL.  Information about such licenses can be found in the 
 *   file named OBDAAPI_3DPARTY-LICENSES.txt.
 */
package inf.unibz.it.obda.gui.swing.datasource;

import inf.unibz.it.obda.api.controller.DatasourcesControllerListener;
import inf.unibz.it.obda.domain.DataSource;

import java.net.URI;
import java.util.Enumeration;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class DatasourceTreeModel extends DefaultTreeModel implements DatasourcesControllerListener {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= 6283495101253307672L;

	private URI					currentOntologyURI	= null;

	public DatasourceTreeModel() {
		super(new DefaultMutableTreeNode());
	}

	public void datasourceAdded(DataSource source) {
//		if (URI.create(source.getUri()).equals(currentOntologyURI)) {
//			System.out.println("add "+ source.getName());
			insertNodeInto(new DefaultMutableTreeNode(source.getSourceID()), (DefaultMutableTreeNode) root, root.getChildCount());
//		}
	}

	public void datasourceDeleted(DataSource source) {
//		if (URI.create(source.getUri()).equals(currentOntologyURI)) {
			DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
			Enumeration<DefaultMutableTreeNode> children = root.children();
			DefaultMutableTreeNode affectedchild = null;
			while (children.hasMoreElements()) {
				DefaultMutableTreeNode current = children.nextElement();
				if (current.getUserObject().toString().equals(source.getSourceID().toString())) {
					affectedchild = current;
					break;
				}
			}
			removeNodeFromParent(affectedchild);
			nodeStructureChanged(root);
//		}
	}

	public void datasourceUpdated(String oldname, DataSource currendata) {
//		if (URI.create(currendata.getUri()).equals(currentOntologyURI)) {
			DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
			Enumeration<DefaultMutableTreeNode> children = root.children();
			DefaultMutableTreeNode affectedchild = null;
			while (children.hasMoreElements()) {
				DefaultMutableTreeNode current = children.nextElement();
				if (current.getUserObject().toString().equals(oldname)) {
					affectedchild = current;
					break;
				}
			}
			if(affectedchild != null){
				affectedchild.setUserObject(currendata.getSourceID());
				nodeChanged(affectedchild);
			}
//		}
	}

	public void alldatasourcesDeleted() {
		DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
		root.removeAllChildren();
		nodeStructureChanged(root);
	}

	/***************************************************************************
	 * Does nothing.
	 */
	public void currentDatasourceChange(DataSource previousdatasource, DataSource currentsource) {

	}

	/***
	 * <commit_msg>Remove unused code, comments and variables.<commit_after>/***
 * Copyright (c) 2008, <NAME>.
 * All rights reserved.
 *
 * The OBDA-API is licensed under the terms of the Lesser General Public
 * License v.3 (see OBDAAPI_LICENSE.txt for details). The components of this
 * work include:
 * 
 * a) The OBDA-API developed by the author and licensed under the LGPL; and, 
 * b) third-party components licensed under terms that may be different from 
 *   those of the LGPL.  Information about such licenses can be found in the 
 *   file named OBDAAPI_3DPARTY-LICENSES.txt.
 */
package inf.unibz.it.obda.gui.swing.datasource;

import inf.unibz.it.obda.api.controller.DatasourcesControllerListener;
import inf.unibz.it.obda.domain.DataSource;

import java.net.URI;
import java.util.Enumeration;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class DatasourceTreeModel extends DefaultTreeModel implements DatasourcesControllerListener {

	private static final long	serialVersionUID	= 6283495101253307672L;

	private URI					currentOntologyURI	= null;

	public DatasourceTreeModel() {
		super(new DefaultMutableTreeNode());
	}

	public void datasourceAdded(DataSource source) {
			insertNodeInto(new DefaultMutableTreeNode(source.getSourceID()), (DefaultMutableTreeNode) root, root.getChildCount());
	}

	public void datasourceDeleted(DataSource source) {
			DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
			Enumeration<DefaultMutableTreeNode> children = root.children();
			DefaultMutableTreeNode affectedchild = null;
			while (children.hasMoreElements()) {
				DefaultMutableTreeNode current = children.nextElement();
				if (current.getUserObject().toString().equals(source.getSourceID().toString())) {
					affectedchild = current;
					break;
				}
			}
			removeNodeFromParent(affectedchild);
			nodeStructureChanged(root);
	}

	public void datasourceUpdated(String oldname, DataSource currendata) {
			DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
			Enumeration<DefaultMutableTreeNode> children = root.children();
			DefaultMutableTreeNode affectedchild = null;
			while (children.hasMoreElements()) {
				DefaultMutableTreeNode current = children.nextElement();
				if (current.getUserObject().toString().equals(oldname)) {
					affectedchild = current;
					break;
				}
			}
			if(affectedchild != null){
				affectedchild.setUserObject(currendata.getSourceID());
				nodeChanged(affectedchild);
			}
	}

	public void alldatasourcesDeleted() {
		DefaultMutableTreeNode root = (DefaultMutableTreeNode) this.root;
		root.removeAllChildren();
		nodeStructureChanged(root);
	}

	public void currentDatasourceChange(DataSource previousdatasource, DataSource currentsource) {

	}

	/***
	 * 
{'fraction_non_alphanumeric': 0.11278068546344758, 'fraction_numerical': 0.008441668073611346, 'mean_word_length': 4.859545004945598, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1896386', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1675, 'n_words': 389}