SCViewer/plugins/com.minres.scviewer.database/src/com/minres/scviewer/database/HierNode.java

180 lines
3.3 KiB
Java
Raw Normal View History

/*******************************************************************************
2021-01-09 14:26:49 +01:00
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
2015-01-06 17:14:16 +01:00
package com.minres.scviewer.database;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.ArrayList;
2021-01-09 20:10:58 +01:00
import java.util.Collections;
import java.util.List;
/**
* The Class HierNode.
*/
2015-01-06 17:14:16 +01:00
public class HierNode implements IHierNode {
/** The name. */
protected String name;
/** The parent. */
2020-11-28 19:41:00 +01:00
protected IHierNode parent = null;
/** The childs. */
2021-01-09 20:10:58 +01:00
protected List<IHierNode> childNodes = Collections.synchronizedList(new ArrayList<>());
/** The pcs. */
2021-01-09 20:10:58 +01:00
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
/**
* Instantiates a new hier node.
*
* @param name the name
*/
public HierNode(String name) {
this.name = name;
}
/**
* Instantiates a new hier node.
*
* @param name the name
* @param parent the parent
*/
2020-11-28 19:41:00 +01:00
public HierNode(String name, IHierNode parent) {
this.name = name;
this.parent = parent;
}
2021-01-09 20:10:58 +01:00
/**
* Instantiates a new hier node.
*/
public HierNode() {
}
/**
* Adds the property change listener.
*
* @param l the l
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}
/**
* Removes the property change listener.
*
* @param l the l
*/
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}
/**
* Gets the full name.
*
* @return the full name
*/
@Override
public String getFullName() {
if (parent != null)
return parent.getFullName() + "." + name;
else
return name;
}
/**
* Gets the name.
*
* @return the name
*/
@Override
public String getName() {
return name;
}
/**
* Sets the name.
*
* @param name the new name
*/
@Override
public void setName(String name) {
this.name = name;
}
2021-01-09 20:10:58 +01:00
/**
* Gets the parent.
*
* @return the parent
*/
@Override
public IHierNode getParent() {
return parent;
}
/**
* Sets the parent.
*
* @param parent the new parent
*/
@Override
2020-11-28 19:41:00 +01:00
public void setParent(IHierNode parent) {
this.parent = parent;
}
/**
* Gets the child nodes.
*
* @return the child nodes
*/
@Override
2015-01-06 17:14:16 +01:00
public List<IHierNode> getChildNodes() {
2021-01-09 20:10:58 +01:00
return Collections.unmodifiableList(childNodes);
}
/**
* Adds the child.
*
* @param child the child
*/
2021-01-09 20:10:58 +01:00
@Override
public void addChild(IHierNode child) {
2021-01-09 20:10:58 +01:00
if (!childNodes.contains(child)) {
childNodes.add(child);
child.setParent(this);
}
}
/**
* Compare to.
*
* @param o the o
* @return the int
*/
@Override
public int compareTo(IHierNode o) {
2020-11-28 19:41:00 +01:00
return getFullName().compareTo(o.getFullName());
}
/**
* Derive waveform.
*
* @return the i derived waveform
*/
@Override
public IDerivedWaveform deriveWaveform() {
return null;
}
}