add dynamic update of waveform list
This commit is contained in:
@ -13,6 +13,7 @@ package com.minres.scviewer.database;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.beans.PropertyChangeSupport;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -27,18 +28,10 @@ public class HierNode implements IHierNode {
|
||||
protected IHierNode parent = null;
|
||||
|
||||
/** The childs. */
|
||||
protected ArrayList<IHierNode> childs;
|
||||
protected List<IHierNode> childNodes = Collections.synchronizedList(new ArrayList<>());
|
||||
|
||||
/** The pcs. */
|
||||
protected PropertyChangeSupport pcs;
|
||||
|
||||
/**
|
||||
* Instantiates a new hier node.
|
||||
*/
|
||||
public HierNode() {
|
||||
childs = new ArrayList<>();
|
||||
pcs = new PropertyChangeSupport(this);
|
||||
}
|
||||
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
|
||||
|
||||
/**
|
||||
* Instantiates a new hier node.
|
||||
@ -46,7 +39,6 @@ public class HierNode implements IHierNode {
|
||||
* @param name the name
|
||||
*/
|
||||
public HierNode(String name) {
|
||||
this();
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ -57,11 +49,16 @@ public class HierNode implements IHierNode {
|
||||
* @param parent the parent
|
||||
*/
|
||||
public HierNode(String name, IHierNode parent) {
|
||||
this();
|
||||
this.name = name;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new hier node.
|
||||
*/
|
||||
public HierNode() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the property change listener.
|
||||
*
|
||||
@ -115,6 +112,16 @@ public class HierNode implements IHierNode {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the parent.
|
||||
*
|
||||
* @return the parent
|
||||
*/
|
||||
@Override
|
||||
public IHierNode getParent() {
|
||||
return parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the parent.
|
||||
*
|
||||
@ -132,7 +139,7 @@ public class HierNode implements IHierNode {
|
||||
*/
|
||||
@Override
|
||||
public List<IHierNode> getChildNodes() {
|
||||
return childs;
|
||||
return Collections.unmodifiableList(childNodes);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -140,9 +147,10 @@ public class HierNode implements IHierNode {
|
||||
*
|
||||
* @param child the child
|
||||
*/
|
||||
@Override
|
||||
public void addChild(IHierNode child) {
|
||||
if (!childs.contains(child)) {
|
||||
childs.add(child);
|
||||
if (!childNodes.contains(child)) {
|
||||
childNodes.add(child);
|
||||
child.setParent(this);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,15 @@ import java.util.List;
|
||||
*/
|
||||
public interface IHierNode extends Comparable<IHierNode> {
|
||||
|
||||
/** The Constant WAVEFORMS. */
|
||||
static final String WAVEFORMS = "Waveforms";
|
||||
|
||||
/** The Constant CHILDS. */
|
||||
static final String CHILDS = "Childs";
|
||||
|
||||
/** The Constant LOADING_FINISHED. */
|
||||
static final String LOADING_FINISHED = "LoadingFinished";
|
||||
|
||||
/**
|
||||
* Attach a non-null PropertyChangeListener to this object.
|
||||
*
|
||||
@ -61,6 +70,13 @@ public interface IHierNode extends Comparable<IHierNode> {
|
||||
*/
|
||||
public void setParent(IHierNode parent);
|
||||
|
||||
/**
|
||||
* Gets the parent.
|
||||
*
|
||||
* @return the parent
|
||||
*/
|
||||
public IHierNode getParent();
|
||||
|
||||
/**
|
||||
* Gets the child nodes.
|
||||
*
|
||||
@ -68,6 +84,12 @@ public interface IHierNode extends Comparable<IHierNode> {
|
||||
*/
|
||||
public List<IHierNode> getChildNodes();
|
||||
|
||||
/**
|
||||
* Adds the child.
|
||||
*
|
||||
* @param child the child
|
||||
*/
|
||||
public void addChild(IHierNode child);
|
||||
/**
|
||||
* Derive waveform.
|
||||
*
|
||||
|
@ -10,6 +10,7 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
|
||||
@ -17,38 +18,51 @@ import java.util.Collection;
|
||||
* The Interface IWaveformDbLoader.
|
||||
*/
|
||||
public interface IWaveformDbLoader {
|
||||
// static final String STREAM_ADDED = "StreamAdded";
|
||||
//
|
||||
// static final String GENERATOR_ADDED = "GeneratorAdded";
|
||||
//
|
||||
// static final String LOADING_FINISHED = "LoadingFinished";
|
||||
// /**
|
||||
// * Attach a non-null PropertyChangeListener to this object.
|
||||
// *
|
||||
// * @param l
|
||||
// * a non-null PropertyChangeListener instance
|
||||
// * @throws IllegalArgumentException
|
||||
// * if the parameter is null
|
||||
// */
|
||||
// public void addPropertyChangeListener(PropertyChangeListener l);
|
||||
//
|
||||
// /**
|
||||
// * Remove a PropertyChangeListener from this component.
|
||||
// *
|
||||
// * @param l
|
||||
// * a PropertyChangeListener instance
|
||||
// */
|
||||
// public void removePropertyChangeListener(PropertyChangeListener l) ;
|
||||
|
||||
/** The Constant STREAM_ADDED. */
|
||||
static final String STREAM_ADDED = "StreamAdded";
|
||||
|
||||
/** The Constant STREAM_ADDED. */
|
||||
static final String SIGNAL_ADDED = "SignalAdded";
|
||||
|
||||
/** The Constant GENERATOR_ADDED. */
|
||||
static final String GENERATOR_ADDED = "GeneratorAdded";
|
||||
|
||||
/** The Constant LOADING_FINISHED. */
|
||||
static final String LOADING_FINISHED = "LoadingFinished";
|
||||
/**
|
||||
* Attach a non-null PropertyChangeListener to this object.
|
||||
*
|
||||
* @param l
|
||||
* a non-null PropertyChangeListener instance
|
||||
* @throws IllegalArgumentException
|
||||
* if the parameter is null
|
||||
*/
|
||||
public void addPropertyChangeListener(PropertyChangeListener l);
|
||||
|
||||
/**
|
||||
* Remove a PropertyChangeListener from this component.
|
||||
*
|
||||
* @param l
|
||||
* a PropertyChangeListener instance
|
||||
*/
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) ;
|
||||
|
||||
/**
|
||||
* Can load the given file.
|
||||
*
|
||||
* @param inputFile the input file
|
||||
* @return true, if successful
|
||||
*/
|
||||
public boolean canLoad(File inputFile);
|
||||
/**
|
||||
* Load.
|
||||
*
|
||||
* @param db the db
|
||||
* @param inp the inp
|
||||
* @return true, if successful
|
||||
* @param inputFile the input file
|
||||
* @throws InputFormatException the input format exception
|
||||
*/
|
||||
public boolean load(IWaveformDb db, File inp) throws InputFormatException;
|
||||
public void load(IWaveformDb db, File inputFile) throws InputFormatException;
|
||||
|
||||
/**
|
||||
* Gets the max time.
|
||||
|
@ -10,6 +10,8 @@
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.database.internal;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -28,7 +30,7 @@ import com.minres.scviewer.database.RelationType;
|
||||
/**
|
||||
* The Class WaveformDb.
|
||||
*/
|
||||
public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
public class WaveformDb extends HierNode implements IWaveformDb, PropertyChangeListener {
|
||||
|
||||
/** The loaders. */
|
||||
private static List<IWaveformDbLoader> loaders = new LinkedList<>();
|
||||
@ -122,8 +124,11 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
@Override
|
||||
public boolean load(File inp) {
|
||||
for (IWaveformDbLoader loader : loaders) {
|
||||
try {
|
||||
if (loader.load(this, inp)) {
|
||||
if(loader.canLoad(inp)) {
|
||||
try {
|
||||
loader.addPropertyChangeListener(this);
|
||||
loader.load(this, inp);
|
||||
loader.removePropertyChangeListener(this);
|
||||
for (IWaveform w : loader.getAllWaves()) {
|
||||
waveforms.put(w.getFullName(), w);
|
||||
}
|
||||
@ -134,13 +139,12 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
name = getFileBasename(inp.getName());
|
||||
buildHierarchyNodes();
|
||||
relationTypes.addAll(loader.getAllRelationTypes());
|
||||
pcs.firePropertyChange("WAVEFORMS", null, waveforms);
|
||||
pcs.firePropertyChange("CHILDS", null, childs);
|
||||
pcs.firePropertyChange(IHierNode.LOADING_FINISHED, null, null);
|
||||
loaded = true;
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
@ -167,7 +171,7 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
@Override
|
||||
public void clear() {
|
||||
waveforms.clear();
|
||||
childs.clear();
|
||||
childNodes.clear();
|
||||
loaded = false;
|
||||
}
|
||||
|
||||
@ -180,49 +184,60 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
return loaded;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if(IWaveformDbLoader.SIGNAL_ADDED.equals(evt.getPropertyName()) ||
|
||||
IWaveformDbLoader.STREAM_ADDED.equals(evt.getPropertyName())) {
|
||||
IWaveform waveform = (IWaveform) evt.getNewValue();
|
||||
putInHierarchy(waveform);
|
||||
pcs.firePropertyChange(IHierNode.WAVEFORMS, null, waveforms);
|
||||
pcs.firePropertyChange(IHierNode.CHILDS, null, childNodes);
|
||||
} else if(IWaveformDbLoader.GENERATOR_ADDED.equals(evt.getPropertyName())) {
|
||||
pcs.firePropertyChange(IHierNode.CHILDS, null, childNodes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds the hierarchy nodes.
|
||||
*/
|
||||
private void buildHierarchyNodes() {
|
||||
boolean needsSorting=false;
|
||||
for (IWaveform stream : getAllWaves()) {
|
||||
String[] hier = stream.getName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for (int i = 0; i < hier.length - 1; ++i) {
|
||||
String name = hier[i];
|
||||
IHierNode childNode = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
childNode = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (childNode != null) {
|
||||
node = childNode;
|
||||
break;
|
||||
}
|
||||
HierNode newNode = new HierNode(name, node);
|
||||
node.getChildNodes().add(newNode);
|
||||
node = newNode;
|
||||
|
||||
if(stream.getParent()==null) {
|
||||
putInHierarchy(stream);
|
||||
needsSorting=true;
|
||||
}
|
||||
node.getChildNodes().add(stream);
|
||||
stream.setParent(node);
|
||||
stream.setName(hier[hier.length - 1]);
|
||||
}
|
||||
sortRecursive(this);
|
||||
if(needsSorting) {
|
||||
pcs.firePropertyChange(IHierNode.WAVEFORMS, null, waveforms);
|
||||
pcs.firePropertyChange(IHierNode.CHILDS, null, childNodes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort recursive.
|
||||
*
|
||||
* @param node the node
|
||||
*/
|
||||
private void sortRecursive(IHierNode node) {
|
||||
Collections.sort(node.getChildNodes(), (IHierNode o1, IHierNode o2) -> o1.getName().compareTo(o2.getName()));
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (!n.getChildNodes().isEmpty())
|
||||
sortRecursive(n);
|
||||
private synchronized void putInHierarchy(IWaveform waveform) {
|
||||
String[] hier = waveform.getName().split("\\.");
|
||||
IHierNode node = this;
|
||||
for (int i = 0; i < hier.length - 1; ++i) {
|
||||
String name = hier[i];
|
||||
IHierNode childNode = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
childNode = n;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (childNode != null) {
|
||||
node = childNode;
|
||||
break;
|
||||
}
|
||||
HierNode newNode = new HierNode(name, node);
|
||||
node.addChild(newNode);
|
||||
node = newNode;
|
||||
|
||||
}
|
||||
node.addChild(waveform);
|
||||
waveform.setParent(node);
|
||||
waveform.setName(hier[hier.length - 1]);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -234,4 +249,5 @@ public class WaveformDb extends HierNode implements IWaveformDb {
|
||||
public List<RelationType> getAllRelationTypes() {
|
||||
return relationTypes;
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user