5: DesignBrowser should indicate loading of database

Task-Url: https://github.com/eyck/txviewer/issues/issue/5
This commit is contained in:
Eyck Jentzsch 2015-11-22 16:38:00 +01:00
parent 0007ab9322
commit 31ed3e4858
6 changed files with 106 additions and 10 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 698 B

View File

@ -363,7 +363,7 @@ public class DesignBrowser {
if(db==database) return; // do nothing if old and new daabase is the same
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(treeViewerPCL);
}
treeViewer.setInput(database.isLoaded()?Arrays.asList(new IWaveformDb[]{database}):null);
treeViewer.setInput(Arrays.asList(database.isLoaded()?new IWaveformDb[]{database}:new IWaveformDb[]{new LoadingWaveformDb()}));
Object state=this.waveformViewerPart.retrieveDesignBrowerState();
if(state!=null && state instanceof DBState)
((DBState)state).apply();

View File

@ -0,0 +1,88 @@
package com.minres.scviewer.e4.application.parts;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformEvent;
import com.minres.scviewer.database.RelationType;
public class LoadingWaveformDb implements IWaveformDb {
private final String label = "Database loading...";
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
}
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
}
@Override
public String getFullName() {
return label;
}
@Override
public String getName() {
return label;
}
@Override
public void setName(String name) {
}
@Override
public void setParentName(String name) {
}
@Override
public List<IHierNode> getChildNodes() {
return new ArrayList<IHierNode>();
}
@Override
public int compareTo(IHierNode o) {
return 0;
}
@Override
public Long getMaxTime() {
return new Long(0);
}
@Override
public IWaveform<? extends IWaveformEvent> getStreamByName(String name) {
return null;
}
@Override
public List<IWaveform<?>> getAllWaves() {
return new ArrayList<IWaveform<?>>();
}
@Override
public List<RelationType> getAllRelationTypes() {
return new ArrayList<RelationType>();
}
@Override
public boolean load(File inp) throws Exception {
return false;
}
@Override
public boolean isLoaded() {
return false;
}
@Override
public void clear() {
}
}

View File

@ -297,22 +297,21 @@ public class WaveformViewer implements IFileChangeListener, IPreferenceChangeLis
*/
protected void loadDatabase(final Map<String, String> state) {
fileMonitor.removeFileChangeListener(this);
Job job = new Job(" My Job") {
Job job = new Job("Database Load Job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// convert to SubMonitor and set total number of work units
SubMonitor subMonitor = SubMonitor.convert(monitor, filesToLoad.size());
subMonitor.setTaskName("Loading database");
SubMonitor subMonitor = SubMonitor.convert(monitor, filesToLoad.size()+1);
try {
subMonitor.worked(1);
for (File file : filesToLoad) {
// TimeUnit.SECONDS.sleep(2);
subMonitor.setTaskName("Loading "+file.getName());
database.load(file);
database.addPropertyChangeListener(waveformPane);
subMonitor.worked(1);
if (monitor.isCanceled())
return Status.CANCEL_STATUS;
}
// sleep a second
} catch (Exception e) {
database = null;
e.printStackTrace();

View File

@ -20,6 +20,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
/**
* The Class TxDbContentProvider providing the tree content of a database for the respective viewer.
@ -79,9 +80,11 @@ public class TxDbContentProvider implements ITreeContentProvider {
}
});
return res.toArray();
}else if(inputElement instanceof List<?>)
}else if(inputElement instanceof List<?>){
return ((List<?>)inputElement).toArray();
else
}else if(inputElement instanceof IWaveformDb){
return new Object[]{};
} else
return null;
}

View File

@ -23,6 +23,7 @@ import com.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.ISignalChangeMulti;
import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.e4.application.parts.LoadingWaveformDb;
/**
* The Class TxDbLabelProvider providing the labels for the respective viewers.
@ -33,7 +34,7 @@ public class TxDbLabelProvider implements ILabelProvider {
private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>();
/** The wave. */
private Image database, stream, signal, folder, wave;
private Image loadinDatabase, database, stream, signal, folder, wave;
/**
@ -41,6 +42,7 @@ public class TxDbLabelProvider implements ILabelProvider {
*/
public TxDbLabelProvider() {
super();
loadinDatabase=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/database_go.png");
database=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/database.png");
stream=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/stream.png");
folder=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/folder.png");
@ -61,6 +63,7 @@ public class TxDbLabelProvider implements ILabelProvider {
*/
@Override
public void dispose() {
if(loadinDatabase!=null) database.dispose();
if(database!=null) database.dispose();
if(stream!=null) stream.dispose();
if(folder!=null) folder.dispose();
@ -90,7 +93,10 @@ public class TxDbLabelProvider implements ILabelProvider {
@Override
public Image getImage(Object element) {
if(element instanceof IWaveformDb){
return database;
if(element instanceof LoadingWaveformDb)
return loadinDatabase;
else
return database;
}else if(element instanceof ITxStream){
return stream;
}else if(element instanceof ISignal<?>){