commit d62e0f63a74baafb7f30c53ce5b3cb5b545c7b6c Author: Eyck Jentzsch Date: Sun Jun 17 19:53:05 2012 +0200 Initial version diff --git a/com.itjw.txviewer.database.text/.classpath b/com.itjw.txviewer.database.text/.classpath new file mode 100644 index 0000000..4519f55 --- /dev/null +++ b/com.itjw.txviewer.database.text/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/com.itjw.txviewer.database.text/.project b/com.itjw.txviewer.database.text/.project new file mode 100644 index 0000000..ee5281e --- /dev/null +++ b/com.itjw.txviewer.database.text/.project @@ -0,0 +1,29 @@ + + + com.itjw.txviewer.database.text + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.groovy.core.groovyNature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.itjw.txviewer.database.text/.settings/org.eclipse.jdt.core.prefs b/com.itjw.txviewer.database.text/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c537b63 --- /dev/null +++ b/com.itjw.txviewer.database.text/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/com.itjw.txviewer.database.text/.settings/org.eclipse.pde.core.prefs b/com.itjw.txviewer.database.text/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000..f29e940 --- /dev/null +++ b/com.itjw.txviewer.database.text/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/com.itjw.txviewer.database.text/META-INF/MANIFEST.MF b/com.itjw.txviewer.database.text/META-INF/MANIFEST.MF new file mode 100644 index 0000000..83a6192 --- /dev/null +++ b/com.itjw.txviewer.database.text/META-INF/MANIFEST.MF @@ -0,0 +1,13 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Textual transaction database +Bundle-SymbolicName: com.itjw.txviewer.database.text +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.itjw.txviewer.database.text.Activator +Bundle-Vendor: ITJW +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Import-Package: com.itjw.txviewer.database, + org.osgi.framework;version="1.3.0" +Require-Bundle: com.itjw.txviewer.database;bundle-version="1.0.0", + org.codehaus.groovy;bundle-version="1.8.6", + org.eclipse.ui.views;bundle-version="3.6.0" diff --git a/com.itjw.txviewer.database.text/build.properties b/com.itjw.txviewer.database.text/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/com.itjw.txviewer.database.text/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/Activator.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/Activator.groovy new file mode 100644 index 0000000..5ae8b1a --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/Activator.groovy @@ -0,0 +1,37 @@ +package com.itjw.txviewer.database.text; + +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import java.util.Dictionary +import java.util.Hashtable +import com.itjw.txviewer.database.ITrDb; + +public class Activator implements BundleActivator { + + private static BundleContext context; + + static BundleContext getContext() { + return context; + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext bundleContext) throws Exception { + Activator.context = bundleContext; + Dictionary dict = new Hashtable(); + dict.putAt(Constants.SERVICE_RANKING, 1); + context.registerService(ITrDb.class, new TrTextDb(), dict); + } + + /* + * (non-Javadoc) + * @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext bundleContext) throws Exception { + Activator.context = null; + } + +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrType.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrType.groovy new file mode 100644 index 0000000..0dfb150 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrType.groovy @@ -0,0 +1,17 @@ +package com.itjw.txviewer.database.text + +import com.itjw.txviewer.database.ITrAttrType; + +class TrAttrType implements ITrAttrType { + String name + String type + + static TrAttrType getAttrType(String name, String type){ + TrAttrTypeFactory.instance.getAttrType(name, type) + } + + TrAttrType(String name, String type){ + this.name=name + this.type=type + } +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrTypeFactory.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrTypeFactory.groovy new file mode 100644 index 0000000..1133206 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttrTypeFactory.groovy @@ -0,0 +1,26 @@ +package com.itjw.txviewer.database.text + +import com.itjw.txviewer.database.ITrAttrType +import com.itjw.txviewer.database.ITrAttribute + +class TrAttrTypeFactory { + private static final instance = new TrAttrTypeFactory() + + def attributes = [:] + + private TrAttrTypeFactory() { + TrAttrTypeFactory.metaClass.constructor = {-> instance } + } + + ITrAttrType getAttrType(String name, String type){ + def key = name+":"+type + ITrAttrType res + if(attributes.containsKey(key)){ + res=attributes[key] + } else { + res=new TrAttrType(name, type) + attributes[key]=res + } + return res + } +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttribute.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttribute.groovy new file mode 100644 index 0000000..6dddab1 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrAttribute.groovy @@ -0,0 +1,40 @@ +package com.itjw.txviewer.database.text + +import com.itjw.txviewer.database.ITrAttribute + +class TrAttribute implements ITrAttribute{ + + TrAttrType attributeType + def value + + TrAttribute(String name, String type, value){ + attributeType = TrAttrTypeFactory.instance.getAttrType(name, type) + switch(type){ + case "STRING": + case "ENUMERATION": + this.value=value[1..-2] + break; + default: + this.value=value + } + } + + TrAttribute(TrAttrType other){ + attributeType=other + } + + TrAttribute(TrAttrType other, value){ + this(other.name, other.type, value) + } + + @Override + public String getName() { + return attributeType.getName(); + } + + @Override + public String getType() { + return attributeType.getType(); + } + +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrGenerator.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrGenerator.groovy new file mode 100644 index 0000000..4471602 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrGenerator.groovy @@ -0,0 +1,40 @@ +package com.itjw.txviewer.database.text + +import java.util.ArrayList; +import java.util.List; + +import com.itjw.txviewer.database.ITrAttrType +import com.itjw.txviewer.database.ITrAttribute; +import com.itjw.txviewer.database.ITrGenerator; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.ITransaction; + +class TrGenerator implements ITrGenerator{ + Long id + TrStream stream + String name + Boolean active = false + ArrayList transactions=[] + + ArrayList begin_attrs = [] + int begin_attrs_idx = 0 + ArrayList end_attrs= [] + int end_attrs_idx = 0 + + TrGenerator(int id, TrStream stream, name){ + this.id=id + this.stream=stream + this.name=name + } + + ITrStream getStream(){ + return stream; + } + + List getTransactions(){ + return transactions + } + + Boolean isActive() {return active}; + +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrHierNode.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrHierNode.groovy new file mode 100644 index 0000000..8ae68d1 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrHierNode.groovy @@ -0,0 +1,44 @@ +package com.itjw.txviewer.database.text; + +import java.beans.PropertyChangeListener; +import java.util.List; +import java.util.Map; + +import com.itjw.txviewer.database.ITrHierNode; + +class TrHierNode implements ITrHierNode { + + String name + def childs = [] + + public TrHierNode(){ + } + + public TrHierNode(String name){ + this.name=name + } + + @Override + public List getChildNodes() { + return childs.sort{it.name} + } + + @Override + public String getFullName() { + // TODO Auto-generated method stub + return name; + } + + @Override + public void addPropertyChangeListener(PropertyChangeListener l) { + // TODO Auto-generated method stub + + } + + @Override + public void removePropertyChangeListener(PropertyChangeListener l) { + // TODO Auto-generated method stub + + } + +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrStream.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrStream.groovy new file mode 100644 index 0000000..f74944a --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrStream.groovy @@ -0,0 +1,72 @@ +package com.itjw.txviewer.database.text + +import java.beans.PropertyChangeListener; +import java.util.List; +import java.util.Map; + +import com.itjw.txviewer.database.ITrDb +import com.itjw.txviewer.database.ITrGenerator +import com.itjw.txviewer.database.ITrHierNode +import com.itjw.txviewer.database.ITrStream +import com.itjw.txviewer.database.ITransaction + +class TrStream extends TrHierNode implements ITrStream { + Long id; + TrTextDb database + String name; + String fullName; + String kind; + def generators = []; + def childs = [] + private allTransactions; + + public TrHierNode(String name){ + this.name=name + } + + @Override + public List getChildNodes() { + return childs.sort{it.name}; + } + + + TrStream(int id, TrTextDb db, String name, String kind){ + this.id=id + this.database=db + this.name=name + this.fullName=name + this.kind=kind + } + + List getGenerators(){ + return generators as List + } + + @Override + public ITrDb getDb() { + return database; + } + + @Override + public int getMaxConcurrrentTx() { + def rowendtime = [0] + getTransactions().each{Transaction tx -> + def rowIdx = 0 + for(rowIdx=0; rowendtime.size()tx.beginTime.value; rowIdx++); + if(rowendtime.size<=rowIdx){ + rowendtime< getTransactions() { + if(!allTransactions) + allTransactions=generators.transactions.flatten().sort{it.beginTime.value} + return allTransactions + } + +} diff --git a/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrTextDb.groovy b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrTextDb.groovy new file mode 100644 index 0000000..ff6f537 --- /dev/null +++ b/com.itjw.txviewer.database.text/src/com/itjw/txviewer/database/text/TrTextDb.groovy @@ -0,0 +1,201 @@ +package com.itjw.txviewer.database.text; + +import java.io.InputStream; +import java.util.Collection; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrGenerator; +import com.itjw.txviewer.database.ITrHierNode; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.InputFormatException; +import com.itjw.txviewer.database.EventTime + +public class TrTextDb extends TrHierNode implements ITrDb{ + + private EventTime maxTime; + def streams = [] + def childs = [] + + public String getFullName() { + return getName(); + } + + @Override + public EventTime getMaxTime() { + return maxTime; + } + + public List getAllStreams() { + return new LinkedList(streams); + } + + public List getChildNodes() { + return childs.sort{it.name}; + } + + public Map getGeneratorsById() { + TreeMap res = new TreeMap(); + streams.each{TrStream stream -> stream.generators.each{res.put(it.id, id)} } + return res; + } + + void clear(){ + streams = [] + maxTime=new EventTime(0, "ns") + } + + void load(InputStream inp) throws InputFormatException { + parseInput(inp) + } + + void parseFromTextFile(filename){ + def file = new File(filename); + this.databaseName = filname; + parseInput(file) + } + + private def parseInput(input){ + def streamsById = [:] + def generatorsById = [:] + def transactionsById = [:] + TrGenerator generator + Transaction transaction + boolean endTransaction=false + def matcher + input.eachLine { line -> + def tokens = line.split(/\s+/) + switch(tokens[0]){ + case "scv_tr_stream": + case "scv_tr_generator": + case "begin_attribute": + case "end_attribute": + if ((matcher = line =~ /^scv_tr_stream\s+\(ID (\d+),\s+name\s+"([^"]+)",\s+kind\s+"([^"]+)"\)$/)) { + def id = Integer.parseInt(matcher[0][1]) + def stream = new TrStream(id, this, matcher[0][2], matcher[0][3]) + streams<transaction.beginTime?maxTime:transaction.beginTime + endTransaction=false + break + case "tx_end"://matcher = line =~ /^tx_end\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/ + def id = Integer.parseInt(tokens[1]) + transaction = transactionsById[id] + assert Integer.parseInt(tokens[2])==transaction.generator.id + transaction.endTime = new EventTime(Integer.parseInt(tokens[3]), tokens[4]) + transaction.generator.end_attrs_idx=0; + maxTime = maxTime>transaction.endTime?maxTime:transaction.endTime + endTransaction=true + break + case "tx_record_attribute"://matcher = line =~ /^tx_record_attribute\s+(\d+)\s+"([^"]+)"\s+(\S+)\s*=\s*(.+)$/ + def id = Integer.parseInt(tokens[1]) + transactionsById[id].attributes.add(new TrAttribute(tokens[2][1..-2], tokens[3], tokens[5..-1].join(' '))) + break + case "a"://matcher = line =~ /^a\s+(.+)$/ + if(endTransaction){ + transaction.end_attrs << new TrAttribute(transaction.generator.end_attrs[0], tokens[1]) + } else { + transaction.begin_attrs << new TrAttribute(transaction.generator.begin_attrs[0], tokens[1]) + } + break + case "tx_relation"://matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/ + Transaction tr1= transactionsById[Integer.parseInt(tokens[2])] + Transaction tr2= transactionsById[Integer.parseInt(tokens[3])] + switch(tokens[1][1..-2]){ + case "CHILD": + tr1.child< + def sortedTx = gen.transactions.sort{it.beginTime} + if(sortedTx.size()>1) + for(int i=1;i + def hier = stream.fullName.split(/\./) + ITrHierNode node = this + hier.each { name -> + def n1 = node.childNodes.find{it.name == name} + if(name == hier[-1]){ //leaf + if(n1!=null) { + if(n1 instanceof TrHierNode){ + node.childNodes.remove(n1) + stream.childNodes.addAll(n1.childNodes) + } else { + throw new InputFormatException() + } + } + stream.name=name + node.childNodes< begin_attrs = new ArrayList() + ArrayList end_attrs = new ArrayList() + ArrayList attributes = new ArrayList() + Transaction prev, next + def pred =[] + def succ =[] + def parent =[] + def child =[] + + Transaction(int id, TrGenerator generator, EventTime begin){ + this.id=id + this.generator=generator + this.beginTime=begin + } + + @Override + List getBeginAttrs() { + return begin_attrs + } + + @Override + List getEndAttrs() { + return end_attrs + } + + List getAttributes(){ + return attributes + } + + @Override + public Set getNextInRelationship(RelationType rel) { + switch(rel){ + case RelationType.PREDECESSOR: + return pred + break + case RelationType.SUCCESSOR: + return succ + break + case RelationType.PREVIOUS: + return [prev] + break + case RelationType.NEXT: + return[next] + break + case RelationType.PARENT: + return parent + break + case RelationType.CHILD: + return child + break + } + } + + @Override + public Object getEditableValue() { + // TODO Auto-generated method stub + return null; + } + + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + return null; + } + + @Override + public Object getPropertyValue(Object id) { + return null; + } + + @Override + public boolean isPropertySet(Object id) { + return false; + } + + @Override + public void resetPropertyValue(Object id) { + } + + @Override + public void setPropertyValue(Object id, Object value) { + } +} diff --git a/com.itjw.txviewer.database/.classpath b/com.itjw.txviewer.database/.classpath new file mode 100644 index 0000000..ad32c83 --- /dev/null +++ b/com.itjw.txviewer.database/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/com.itjw.txviewer.database/.project b/com.itjw.txviewer.database/.project new file mode 100644 index 0000000..10e4470 --- /dev/null +++ b/com.itjw.txviewer.database/.project @@ -0,0 +1,28 @@ + + + com.itjw.txviewer.database + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.itjw.txviewer.database/.settings/org.eclipse.jdt.core.prefs b/com.itjw.txviewer.database/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c537b63 --- /dev/null +++ b/com.itjw.txviewer.database/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/com.itjw.txviewer.database/.settings/org.eclipse.pde.core.prefs b/com.itjw.txviewer.database/.settings/org.eclipse.pde.core.prefs new file mode 100644 index 0000000..f29e940 --- /dev/null +++ b/com.itjw.txviewer.database/.settings/org.eclipse.pde.core.prefs @@ -0,0 +1,3 @@ +eclipse.preferences.version=1 +pluginProject.extensions=false +resolve.requirebundle=false diff --git a/com.itjw.txviewer.database/META-INF/MANIFEST.MF b/com.itjw.txviewer.database/META-INF/MANIFEST.MF new file mode 100644 index 0000000..aa871f2 --- /dev/null +++ b/com.itjw.txviewer.database/META-INF/MANIFEST.MF @@ -0,0 +1,10 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Transaction Database +Bundle-SymbolicName: com.itjw.txviewer.database +Bundle-Version: 1.0.0.qualifier +Bundle-Vendor: ITJW +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: com.itjw.txviewer.database +Require-Bundle: org.eclipse.ui.views diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/EventTime.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/EventTime.class new file mode 100644 index 0000000..1b5427a Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/EventTime.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttrType.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttrType.class new file mode 100644 index 0000000..94fb32a Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttrType.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttribute.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttribute.class new file mode 100644 index 0000000..c4ac760 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrAttribute.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrDb.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrDb.class new file mode 100644 index 0000000..5b8cd3e Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrDb.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrGenerator.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrGenerator.class new file mode 100644 index 0000000..d15efb4 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrGenerator.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrHierNode.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrHierNode.class new file mode 100644 index 0000000..9214e20 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrHierNode.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrStream.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrStream.class new file mode 100644 index 0000000..bd07ac1 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITrStream.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITransaction.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITransaction.class new file mode 100644 index 0000000..03917c9 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/ITransaction.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/InputFormatException.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/InputFormatException.class new file mode 100644 index 0000000..25c91f4 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/InputFormatException.class differ diff --git a/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/RelationType.class b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/RelationType.class new file mode 100644 index 0000000..3400ad8 Binary files /dev/null and b/com.itjw.txviewer.database/bin/com/itjw/txviewer/database/RelationType.class differ diff --git a/com.itjw.txviewer.database/build.properties b/com.itjw.txviewer.database/build.properties new file mode 100644 index 0000000..34d2e4d --- /dev/null +++ b/com.itjw.txviewer.database/build.properties @@ -0,0 +1,4 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + . diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/EventTime.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/EventTime.java new file mode 100644 index 0000000..4f6f07f --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/EventTime.java @@ -0,0 +1,57 @@ +package com.itjw.txviewer.database; + +public class EventTime implements Comparable{ + public static final double NS = 1000000.0; + public static final double MS = 1000000000.0; + private long value; // unit is femto seconds + + public EventTime(Long value, String unit){ + setValue(value, unit); + } + + public long getValue(){ + return(value); + } + + public double getScaledValue(double scale){ + return value/scale; + } + + public double getValueNS(){ + return getScaledValue(NS); + } + + public double getValueMS(){ + return getScaledValue(MS); + } + + public void setValue(long value){ + this.value=value; + } + + public void setValue(long value, String unit){ + this.value=value; + if("fs".compareToIgnoreCase(unit)==0) + this.value=value; + else if("ps".compareToIgnoreCase(unit)==0) + this.value=value*1000; + else if("ns".compareToIgnoreCase(unit)==0) + this.value=value*1000000; + else if("us".compareToIgnoreCase(unit)==0) + this.value=value*1000000000; + else if("ms".compareToIgnoreCase(unit)==0) + this.value=value*1000000000000L; + else { + System.err.print("Don't know what to do with "+unit+"\n"); + } + } + + public String toString(){ + return value/1000000 +"ns"; + } + + @Override + public int compareTo(EventTime other) { + return this.value getAllStreams(); + + public void load(InputStream inp) throws InputFormatException; + + public void clear(); + +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrGenerator.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrGenerator.java new file mode 100644 index 0000000..adb52f8 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrGenerator.java @@ -0,0 +1,11 @@ +package com.itjw.txviewer.database; + +import java.util.List; + +public interface ITrGenerator { + public Long getId(); + public ITrStream getStream(); + public String getName(); +// public Boolean isActive(); + public List getTransactions(); +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrHierNode.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrHierNode.java new file mode 100644 index 0000000..fca7e85 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrHierNode.java @@ -0,0 +1,32 @@ +package com.itjw.txviewer.database; + +import java.beans.PropertyChangeListener; +import java.util.List; + +public interface ITrHierNode { + /** + * 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) ; + + public String getFullName(); + + public String getName(); + + public void setName(String name); + + public List getChildNodes(); + +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrStream.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrStream.java new file mode 100644 index 0000000..f41d4b9 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITrStream.java @@ -0,0 +1,19 @@ +package com.itjw.txviewer.database; + +import java.util.List; + +public interface ITrStream extends ITrHierNode { + + public Long getId(); + + public String getKind(); + + public ITrDb getDb(); + + public List getGenerators(); + + public List getTransactions(); + + public int getMaxConcurrrentTx(); + +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITransaction.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITransaction.java new file mode 100644 index 0000000..7ff6e48 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/ITransaction.java @@ -0,0 +1,15 @@ +package com.itjw.txviewer.database; + +import java.util.List; +import java.util.Set; + +public interface ITransaction { + public Long getId(); + public ITrGenerator getGenerator(); + public EventTime getBeginTime(); + public EventTime getEndTime(); + public List getBeginAttrs(); + public List getEndAttrs(); + public List getAttributes(); + public Set getNextInRelationship(RelationType rel); +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/InputFormatException.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/InputFormatException.java new file mode 100644 index 0000000..26dbcf3 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/InputFormatException.java @@ -0,0 +1,10 @@ +package com.itjw.txviewer.database; + +public class InputFormatException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 8676129878197783368L; + +} diff --git a/com.itjw.txviewer.database/src/com/itjw/txviewer/database/RelationType.java b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/RelationType.java new file mode 100644 index 0000000..28cbd39 --- /dev/null +++ b/com.itjw.txviewer.database/src/com/itjw/txviewer/database/RelationType.java @@ -0,0 +1,5 @@ +package com.itjw.txviewer.database; + +public enum RelationType { + PREDECESSOR, SUCCESSOR, PREVIOUS, NEXT, PARENT, CHILD; +} diff --git a/com.itjw.txviewer.feature/.project b/com.itjw.txviewer.feature/.project new file mode 100644 index 0000000..78f8e93 --- /dev/null +++ b/com.itjw.txviewer.feature/.project @@ -0,0 +1,17 @@ + + + com.itjw.txviewer.feature + + + + + + org.eclipse.pde.FeatureBuilder + + + + + + org.eclipse.pde.FeatureNature + + diff --git a/com.itjw.txviewer.feature/build.properties b/com.itjw.txviewer.feature/build.properties new file mode 100644 index 0000000..64f93a9 --- /dev/null +++ b/com.itjw.txviewer.feature/build.properties @@ -0,0 +1 @@ +bin.includes = feature.xml diff --git a/com.itjw.txviewer.feature/feature.xml b/com.itjw.txviewer.feature/feature.xml new file mode 100644 index 0000000..191bbd7 --- /dev/null +++ b/com.itjw.txviewer.feature/feature.xml @@ -0,0 +1,55 @@ + + + + + A viewer for SystemC Verification Library transactions + + + + [Enter Copyright Description here.] + + + + [Enter License Description here.] + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.itjw.txviewer.feature/txviewer.product b/com.itjw.txviewer.feature/txviewer.product new file mode 100644 index 0000000..4ffad07 --- /dev/null +++ b/com.itjw.txviewer.feature/txviewer.product @@ -0,0 +1,35 @@ + + + + + + + + + + -XstartOnFirstThread -Dorg.eclipse.swt.internal.carbon.smallFonts + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.itjw.txviewer.graph/.classpath b/com.itjw.txviewer.graph/.classpath new file mode 100644 index 0000000..8586d88 --- /dev/null +++ b/com.itjw.txviewer.graph/.classpath @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/com.itjw.txviewer.graph/.project b/com.itjw.txviewer.graph/.project new file mode 100644 index 0000000..28dd19b --- /dev/null +++ b/com.itjw.txviewer.graph/.project @@ -0,0 +1,29 @@ + + + com.itjw.txviewer.graph + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.jdt.groovy.core.groovyNature + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/com.itjw.txviewer.graph/.settings/org.eclipse.jdt.core.prefs b/com.itjw.txviewer.graph/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..c537b63 --- /dev/null +++ b/com.itjw.txviewer.graph/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/com.itjw.txviewer.graph/META-INF/MANIFEST.MF b/com.itjw.txviewer.graph/META-INF/MANIFEST.MF new file mode 100644 index 0000000..6d500d7 --- /dev/null +++ b/com.itjw.txviewer.graph/META-INF/MANIFEST.MF @@ -0,0 +1,19 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Graph +Bundle-SymbolicName: com.itjw.txviewer.graph; singleton:=true +Bundle-Version: 1.0.0.qualifier +Bundle-Activator: com.itjw.txviewer.graph.TxEditorPlugin +Bundle-Vendor: ITJW +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.jface.text, + org.eclipse.core.resources, + org.eclipse.ui.editors, + org.eclipse.ui.ide, + org.eclipse.gef, + org.eclipse.ui.views.properties.tabbed +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Import-Package: com.itjw.txviewer.database, + org.eclipse.ui.views.contentoutline diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TrHierNodeSelection.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TrHierNodeSelection.class new file mode 100644 index 0000000..f153fed Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TrHierNodeSelection.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TransactionSelection.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TransactionSelection.class new file mode 100644 index 0000000..f4dc208 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TransactionSelection.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart$1.class new file mode 100644 index 0000000..050f000 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart.class new file mode 100644 index 0000000..dc8dba2 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPart.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPlugin.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPlugin.class new file mode 100644 index 0000000..ee18b66 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxEditorPlugin.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage$1.class new file mode 100644 index 0000000..9b8413d Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage.class new file mode 100644 index 0000000..1e8a705 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/TxOutlinePage.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/AddToWave.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/AddToWave.class new file mode 100644 index 0000000..87cee63 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/AddToWave.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$1.class new file mode 100644 index 0000000..3400286 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$2.class new file mode 100644 index 0000000..e2ae0c6 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory.class new file mode 100644 index 0000000..0ba142a Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/actions/TxActionFactory.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrDbFacade.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrDbFacade.class new file mode 100644 index 0000000..9294668 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrDbFacade.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrHierNodeFacade.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrHierNodeFacade.class new file mode 100644 index 0000000..2790237 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrHierNodeFacade.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrStreamFacade.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrStreamFacade.class new file mode 100644 index 0000000..a7b8ba6 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITrStreamFacade.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionFacade.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionFacade.class new file mode 100644 index 0000000..e4a7f5b Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionFacade.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionProperties.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionProperties.class new file mode 100644 index 0000000..1cd0551 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/data/ITransactionProperties.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$1.class new file mode 100644 index 0000000..048ec45 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$2.class new file mode 100644 index 0000000..e5318d1 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane.class new file mode 100644 index 0000000..04f0417 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ListPane.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/NameListPane.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/NameListPane.class new file mode 100644 index 0000000..b29dd7f Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/NameListPane.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$1.class new file mode 100644 index 0000000..7ca9218 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$2.class new file mode 100644 index 0000000..ab59e2a Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$3.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$3.class new file mode 100644 index 0000000..83491c6 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$3.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$4.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$4.class new file mode 100644 index 0000000..7a59317 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas$4.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.class new file mode 100644 index 0000000..e687a66 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$1.class new file mode 100644 index 0000000..0713e0d Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$2.class new file mode 100644 index 0000000..c41b0ed Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$3.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$3.class new file mode 100644 index 0000000..704bf4a Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$3.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$4.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$4.class new file mode 100644 index 0000000..0056c9e Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$4.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$5.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$5.class new file mode 100644 index 0000000..40bf5ec Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay$5.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay.class new file mode 100644 index 0000000..9814d05 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/TxDisplay.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ValueListPane.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ValueListPane.class new file mode 100644 index 0000000..e897527 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/ValueListPane.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.class new file mode 100644 index 0000000..9f8f2da Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/util/Pair.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/util/Pair.class new file mode 100644 index 0000000..a1471da Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/util/Pair.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionPropertiesView.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionPropertiesView.class new file mode 100644 index 0000000..e7b65bd Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionPropertiesView.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView$1.class new file mode 100644 index 0000000..986504d Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView.class new file mode 100644 index 0000000..073ec4b Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/SelectionTableView.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$1.class new file mode 100644 index 0000000..e09f732 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$2.class new file mode 100644 index 0000000..67f7c4b Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$3.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$3.class new file mode 100644 index 0000000..d8ac196 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$3.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$4.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$4.class new file mode 100644 index 0000000..15dc9fe Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$4.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$5.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$5.class new file mode 100644 index 0000000..b1cfb91 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$5.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$NameSorter.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$NameSorter.class new file mode 100644 index 0000000..866675e Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$NameSorter.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeObject.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeObject.class new file mode 100644 index 0000000..c9c3e03 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeObject.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeParent.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeParent.class new file mode 100644 index 0000000..2c51b20 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$TreeParent.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewContentProvider.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewContentProvider.class new file mode 100644 index 0000000..9cf977e Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewContentProvider.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewLabelProvider.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewLabelProvider.class new file mode 100644 index 0000000..75f9b42 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView$ViewLabelProvider.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView.class new file mode 100644 index 0000000..496046e Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/TxDbView.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.class new file mode 100644 index 0000000..0664a08 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.class new file mode 100644 index 0000000..58c2aa1 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$1.class new file mode 100644 index 0000000..b341a1d Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$2.class new file mode 100644 index 0000000..fbc0284 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$3.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$3.class new file mode 100644 index 0000000..0b0b8c2 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty$3.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty.class new file mode 100644 index 0000000..71dec7a Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/AttributeProperty.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$1.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$1.class new file mode 100644 index 0000000..73f6c4a Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$1.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$2.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$2.class new file mode 100644 index 0000000..23becc2 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$2.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$3.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$3.class new file mode 100644 index 0000000..c340266 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty$3.class differ diff --git a/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty.class b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty.class new file mode 100644 index 0000000..e71a4c5 Binary files /dev/null and b/com.itjw.txviewer.graph/bin/com/itjw/txviewer/graph/views/sections/RelatedProperty.class differ diff --git a/com.itjw.txviewer.graph/build.properties b/com.itjw.txviewer.graph/build.properties new file mode 100644 index 0000000..c4166fb --- /dev/null +++ b/com.itjw.txviewer.graph/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = plugin.xml,\ + META-INF/,\ + .,\ + icons/,\ + contexts.xml,\ + res/ diff --git a/com.itjw.txviewer.graph/contexts.xml b/com.itjw.txviewer.graph/contexts.xml new file mode 100644 index 0000000..64aff45 --- /dev/null +++ b/com.itjw.txviewer.graph/contexts.xml @@ -0,0 +1,12 @@ + + + This is the context help for the sample view with a tree viewer. It was generated by a PDE template. + + + + + + + + + diff --git a/com.itjw.txviewer.graph/icons/sample.gif b/com.itjw.txviewer.graph/icons/sample.gif new file mode 100644 index 0000000..34fb3c9 Binary files /dev/null and b/com.itjw.txviewer.graph/icons/sample.gif differ diff --git a/com.itjw.txviewer.graph/plugin.xml b/com.itjw.txviewer.graph/plugin.xml new file mode 100644 index 0000000..e0c043d --- /dev/null +++ b/com.itjw.txviewer.graph/plugin.xml @@ -0,0 +1,100 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/com.itjw.txviewer.graph/res/images/database.png b/com.itjw.txviewer.graph/res/images/database.png new file mode 100755 index 0000000..3d09261 Binary files /dev/null and b/com.itjw.txviewer.graph/res/images/database.png differ diff --git a/com.itjw.txviewer.graph/res/images/folder.png b/com.itjw.txviewer.graph/res/images/folder.png new file mode 100755 index 0000000..784e8fa Binary files /dev/null and b/com.itjw.txviewer.graph/res/images/folder.png differ diff --git a/com.itjw.txviewer.graph/res/images/stream.png b/com.itjw.txviewer.graph/res/images/stream.png new file mode 100755 index 0000000..c32d25c Binary files /dev/null and b/com.itjw.txviewer.graph/res/images/stream.png differ diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TrHierNodeSelection.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TrHierNodeSelection.java new file mode 100644 index 0000000..b0d42d3 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TrHierNodeSelection.java @@ -0,0 +1,61 @@ +package com.itjw.txviewer.graph; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.eclipse.jface.viewers.IStructuredSelection; + +import com.itjw.txviewer.graph.data.ITrHierNodeFacade; + +public class TrHierNodeSelection implements IStructuredSelection { + + List selection = new ArrayList(); + + public TrHierNodeSelection(ITrHierNodeFacade node){ + selection.add(node); + } + + public TrHierNodeSelection(List nodes){ + selection.addAll(nodes); + } + + public void add(ITrHierNodeFacade node){ + selection.add(node); + } + + public void addAll(List nodes){ + selection.addAll(nodes); + } + + @Override + public boolean isEmpty() { + return selection.size()==0; + } + + @Override + public Object getFirstElement() { + return selection.get(0); + } + + @Override + public Iterator iterator() { + return selection.iterator(); + } + + @Override + public int size() { + return selection.size(); + } + + @Override + public Object[] toArray() { + // TODO Auto-generated method stub + return selection.toArray(); + } + + @Override + public List toList() { + return selection; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TransactionSelection.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TransactionSelection.java new file mode 100644 index 0000000..6680bcb --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TransactionSelection.java @@ -0,0 +1,67 @@ +package com.itjw.txviewer.graph; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import org.eclipse.jface.viewers.IStructuredSelection; + +import com.itjw.txviewer.graph.data.ITrStreamFacade; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class TransactionSelection implements IStructuredSelection { + + List selection = new ArrayList(); + + public TransactionSelection(ITransactionFacade node){ + selection.add(node); + } + + public TransactionSelection(List nodes){ + selection.addAll(nodes); + } + + public TransactionSelection(ITransactionFacade currentSelection, ITrStreamFacade currentStreamSelection) { + selection.add(currentSelection); + if(currentStreamSelection!=null) + selection.add(currentStreamSelection); + } + + public void add(ITransactionFacade node){ + selection.add(node); + } + + public void addAll(List nodes){ + selection.addAll(nodes); + } + + @Override + public boolean isEmpty() { + return selection.size()==0; + } + + @Override + public ITransactionFacade getFirstElement() { + return (ITransactionFacade)selection.get(0); + } + + @Override + public Iterator iterator() { + return selection.iterator(); + } + + @Override + public int size() { + return selection.size(); + } + + @Override + public Object[] toArray() { + return selection.toArray(); + } + + @Override + public List toList() { + return selection; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPart.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPart.java new file mode 100644 index 0000000..56f90a9 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPart.java @@ -0,0 +1,207 @@ +package com.itjw.txviewer.graph; + +import java.util.LinkedList; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.gef.ui.actions.ActionRegistry; +import org.eclipse.gef.ui.parts.SelectionSynchronizer; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorSite; +import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.part.EditorPart; +import org.eclipse.ui.views.contentoutline.IContentOutlinePage; +import org.eclipse.ui.views.properties.IPropertySheetPage; +import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.InputFormatException; +import com.itjw.txviewer.graph.actions.AddToWave; +import com.itjw.txviewer.graph.data.ITrDbFacade; +import com.itjw.txviewer.graph.data.ITrStreamFacade; +import com.itjw.txviewer.graph.ui.swt.TxDisplay; + +public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPageContributor { + + public static final String ID = "com.itjw.txviewer.graph.TxEditorPart"; //$NON-NLS-1$ + + private TxDisplay txDisplay; + + /** This is the root of the editor's model. */ + private ITrDb database; + + private LinkedList streamList; + + private SelectionSynchronizer synchronizer; + + private ActionRegistry actionRegistry; + + public TxEditorPart() { + streamList = new LinkedList(); + + } + + /** + * Create contents of the editor part. + * @param parent + */ + @Override + public void createPartControl(Composite parent) { + /** Add handlers for global actions (delete, etc) */ + IActionBars actionBars = getEditorSite().getActionBars(); + actionBars.setGlobalActionHandler(AddToWave.ID, new Action() { + @Override + public void runWithEvent(Event event) { + System.out.println("AddToWave with event"); + } + + @Override + public void run() { + System.out.println("AddToWave"); + } + }); + + txDisplay = new TxDisplay(parent, this, getSite()); + TxEditorPlugin.getDefault().editorOpened(this); + getSite().setSelectionProvider(txDisplay); + } + + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput) + */ + protected void setInput(IEditorInput input) { + super.setInput(input); + try { + IFile file = ((IFileEditorInput) input).getFile(); + database = new ITrDbFacade(); + if(txDisplay !=null) database.addPropertyChangeListener(txDisplay); + database.load(file.getContents()); + setPartName(((IFileEditorInput) input).getFile().getName()); +// for(ITrStream stream: database.getAllStreams()) +// streamList.add(new TxStreamAdapter(stream)); + } catch (InputFormatException e) { + handleLoadException(e); + } catch (CoreException e) { + e.printStackTrace(); + } + } + + private void handleLoadException(Exception e) { + System.err.println("** Load failed. Using default model. **"); + e.printStackTrace(); + database = null; + } + + + @Override + public void setFocus() { + // Set the focus + } + + @Override + public void doSave(IProgressMonitor monitor) { + // Do the Save operation + } + + @Override + public void doSaveAs() { + // Do the Save As operation + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class type) { + if (type == IContentOutlinePage.class) // outline page + return new TxOutlinePage(this); + else if (type == IPropertySheetPage.class) // use tabbed property sheet instead of standard one + return new TabbedPropertySheetPage(this); + return super.getAdapter(type); + } + + public SelectionSynchronizer getSelectionSynchronizer() { + if (synchronizer == null) + synchronizer = new SelectionSynchronizer(); + return synchronizer; + } + + public ActionRegistry getActionRegistry() { + if (actionRegistry == null) + actionRegistry = new ActionRegistry(); + return actionRegistry; + } + + public ITrDb getModel() { + return database; + } + + + + @Override + public void init(IEditorSite site, IEditorInput input) + throws PartInitException { + // Initialize the editor part + setSite(site); + setInput(input); + } + + @Override + public boolean isDirty() { + return false; + } + + @Override + public boolean isSaveAsAllowed() { + return false; + } + + public LinkedList getStreamList() { + return streamList; + } + + public ITrDb getDatabase() { + return database; + } + + public void addStreamToList(ITrStream stream){ + if(stream instanceof ITrStreamFacade) + streamList.add((ITrStreamFacade)stream); + else + streamList.add(new ITrStreamFacade(stream)); + txDisplay.streamListChanged(); + } + + public void addStreamsToList(ITrStream[] streams){ + for(ITrStream stream: streams) addStreamToList(stream); + txDisplay.streamListChanged(); + } + + public void removeStreamFromList(ITrStream stream){ + txDisplay.streamListChanged(); + } + + public void removeStreamsFromList(ITrStream[] streams){ + txDisplay.streamListChanged(); + } + + public void setSelection(ISelection selection){ + txDisplay.setSelection(selection); + } + + @Override + public String getContributorId() { + return getSite().getId(); + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPlugin.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPlugin.java new file mode 100644 index 0000000..2c7b22f --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxEditorPlugin.java @@ -0,0 +1,129 @@ +package com.itjw.txviewer.graph; + +import java.io.File; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +import org.eclipse.draw2d.ColorConstants; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class TxEditorPlugin extends AbstractUIPlugin { + + public static final int lineColor=0; + public static final int txBgColor=1; + public static final int highliteLineColor=2; + public static final int txHighliteBgColor=3; + public static final int trackBgLightColor=4; + public static final int trackBgDarkColor=5; + public static final int headerBgColor=6; + public static final int headerFgColor=7; + + // The plug-in ID + public static final String PLUGIN_ID = "com.itjw.txviewer.graph"; //$NON-NLS-1$ + + // The shared instance + private static TxEditorPlugin plugin; + + private ResourceBundle resourceBundle; + + private TxEditorPart openedTxEditorPart; + + /** + * The constructor + */ + public TxEditorPlugin() { + openedTxEditorPart=null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + try { + resourceBundle = ResourceBundle.getBundle(plugin.getClass().getName()); + } catch (MissingResourceException x) { + resourceBundle = null; + } + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static TxEditorPlugin getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + String fullpath = File.separator+"res"+File.separator+"images"+File.separator+path; + return imageDescriptorFromPlugin(PLUGIN_ID, fullpath); + } + + public static Image createImage(String name) { + ImageDescriptor id=getImageDescriptor(name+".png"); + return id.createImage(); + } + + public Color getColor(int idx){ + switch (idx) { + case lineColor: + return ColorConstants.red; + case txBgColor: + return ColorConstants.green; + case highliteLineColor: + return ColorConstants.cyan; + case txHighliteBgColor: + return ColorConstants.darkGreen; + case trackBgLightColor: + return new Color(null, 220, 220, 220); + case trackBgDarkColor: + return new Color(null, 200, 200, 200); + case headerBgColor: + return new Color(null, 255, 255, 255); + case headerFgColor: + return new Color(null, 55, 55, 55); + default: + break; + } + return ColorConstants.black; + } + + public ResourceBundle getResourceBundle() { + return resourceBundle; + } + + public void editorOpened(TxEditorPart txEditorPart) { + openedTxEditorPart=txEditorPart; + } + + public TxEditorPart getOpenEditorPart(){ + return openedTxEditorPart; + } +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxOutlinePage.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxOutlinePage.java new file mode 100644 index 0000000..df006cf --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/TxOutlinePage.java @@ -0,0 +1,154 @@ +package com.itjw.txviewer.graph; + +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.part.IPageSite; +import org.eclipse.ui.views.contentoutline.ContentOutline; +import org.eclipse.ui.views.contentoutline.ContentOutlinePage; + +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.graph.actions.TxActionFactory; +import com.itjw.txviewer.graph.data.ITrHierNodeFacade; +import com.itjw.txviewer.graph.views.provider.TxDbTreeContentProvider; +import com.itjw.txviewer.graph.views.provider.TxDbTreeLabelProvider; + +/** + * Creates an outline pagebook for this editor. + */ +public class TxOutlinePage extends ContentOutlinePage implements ISelectionListener, ISelectionProvider { + + private TxEditorPart editor; + + public TxOutlinePage(TxEditorPart editor) { + this.editor = editor; + } + + /* + * (non-Javadoc) + * + * @see + * org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite + * ) + */ + public void createControl(Composite parent) { + super.createControl(parent); + TreeViewer contentOutlineViewer = getTreeViewer(); + contentOutlineViewer.addSelectionChangedListener(this); + // Set up the tree viewer + contentOutlineViewer.setContentProvider(new TxDbTreeContentProvider()); + contentOutlineViewer.setLabelProvider(new TxDbTreeLabelProvider()); + contentOutlineViewer.setInput(editor.getDatabase()); + // initialize context menu depending on the the selectec item + MenuManager menuMgr = new MenuManager(); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(contentOutlineViewer.getControl()); + contentOutlineViewer.getTree().setMenu(menu); + getSite().registerContextMenu("com.itjw.txviewer.graph.outline.contextmenu", menuMgr, contentOutlineViewer); + // add me as selection listener + getSite().getPage().addSelectionListener((ISelectionListener) this); + //getSite().getPage().addSelectionListener("SampleViewId",(ISelectionListener)this); + getSite().setSelectionProvider(this); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#dispose() + */ + public void dispose() { + // dispose + super.dispose(); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.part.IPage#getControl() + */ + public Control getControl() { + return getTreeViewer().getControl(); + } + + /** + * @see org.eclipse.ui.part.IPageBookViewPage#init(org.eclipse.ui.part.IPageSite) + */ + public void init(IPageSite pageSite) { + super.init(pageSite); + IActionBars bars = pageSite.getActionBars(); + String id = ActionFactory.PASTE.getId(); + bars.setGlobalActionHandler(id, editor.getActionRegistry().getAction(id)); + id = ActionFactory.DELETE.getId(); + bars.setGlobalActionHandler(id, editor.getActionRegistry().getAction(id)); + } + + private void fillContextMenu(IMenuManager menuMgr) { + // initalize the context menu + getTreeViewer().getSelection(); + ISelection selection = getTreeViewer().getSelection(); + Object obj = ((IStructuredSelection) selection).getFirstElement(); + menuMgr.add(TxActionFactory.getAction(TxActionFactory.ADD_TO_WAVE, obj instanceof ITrStream)); + menuMgr.add(TxActionFactory.getAction(TxActionFactory.ADD_ALL_TO_WAVE, true)); + menuMgr.add(TxActionFactory.getAction(TxActionFactory.REMOVE_FROM_WAVE, obj instanceof ITrStream)); + menuMgr.add(TxActionFactory.getAction(TxActionFactory.REMOVE_ALL_FROM_WAVE, true)); + } + + + //ISelectionListener methods + @Override + public void selectionChanged(IWorkbenchPart part, ISelection selection) { + if(!(part instanceof ContentOutline) && selection instanceof TrHierNodeSelection){ + System.out.println("Something selected"); + } + } + + /** + * Returns the current selection for this provider. + * + * @return the current selection + */ + public ISelection getSelection() { + if (getTreeViewer() == null) { + return StructuredSelection.EMPTY; + } + return getTreeViewer().getSelection(); + } + + public void setSelection(ISelection selection){ + if (getTreeViewer() != null) { + getTreeViewer().setSelection(selection); + } + } + /** + * @see org.eclipse.jface.viewers.ISelectionProvider#selectionChanged(SelectionChangedEvent) + */ + public void selectionChanged(SelectionChangedEvent anEvent) { + // translate the tree selection + ISelection selection = anEvent.getSelection(); + if (!selection.isEmpty()) { + Object tmp = ((IStructuredSelection) selection).getFirstElement(); + if (tmp instanceof ITrHierNodeFacade) { + fireSelectionChanged(new TrHierNodeSelection((ITrHierNodeFacade) tmp)); + } + } + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/AddToWave.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/AddToWave.java new file mode 100644 index 0000000..3a8e89f --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/AddToWave.java @@ -0,0 +1,15 @@ +package com.itjw.txviewer.graph.actions; + +import org.eclipse.jface.action.Action; + +public class AddToWave extends Action { + + public AddToWave() { + super("Add to wave"); + // TODO Auto-generated constructor stub + } + + public static final String ID = "com.itjw.txviewer.graph.action.AddToWave"; + + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/TxActionFactory.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/TxActionFactory.java new file mode 100644 index 0000000..c11047b --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/actions/TxActionFactory.java @@ -0,0 +1,103 @@ +package com.itjw.txviewer.graph.actions; + +import java.util.LinkedList; + +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; + +import com.itjw.txviewer.database.ITrHierNode; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.ITransaction; +import com.itjw.txviewer.graph.TransactionSelection; +import com.itjw.txviewer.graph.TxEditorPlugin; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class TxActionFactory { + public static final int ADD_TO_WAVE = 0; + public static final int ADD_ALL_TO_WAVE = 1; + public static final int REMOVE_FROM_WAVE = 2; + public static final int REMOVE_ALL_FROM_WAVE = 3; + public static final int JUMP_TO_TX = 4; + private static TxActionFactory instance; + + private TxActionFactory(){} + + public static TxActionFactory getInstance() { + if(instance == null) instance=new TxActionFactory(); + return instance; + } + + public static Action getAction(int actionId, boolean enabled){ + switch(actionId){ + case ADD_TO_WAVE: + return getInstance().makeStreamAction("Add to Wave", ISharedImages.IMG_OBJ_ADD, enabled, false); + case ADD_ALL_TO_WAVE: + return getInstance().makeStreamAction("Add all to Wave", ISharedImages.IMG_OBJ_ADD, true, false); + case REMOVE_FROM_WAVE: + return getInstance().makeStreamAction("Remove from Wave", ISharedImages.IMG_TOOL_DELETE, enabled, true); + case REMOVE_ALL_FROM_WAVE: + return getInstance().makeStreamAction("Remove all from Wave", ISharedImages.IMG_TOOL_DELETE, true, true); + case JUMP_TO_TX: + return getInstance().makeTransactionAction("Jump to Transaction", ISharedImages.IMG_OBJ_ADD, true); + } + return null; + } + + private Action makeStreamAction(String text, String imgDescriptor, boolean enabled, final boolean remove) { + Action action = new Action() { + public void run() { + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); + for(Object obj :((IStructuredSelection) selection).toArray()){ + if(obj instanceof ITrStream){ + if(remove) + TxEditorPlugin.getDefault().getOpenEditorPart().removeStreamFromList((ITrStream) obj); + else + TxEditorPlugin.getDefault().getOpenEditorPart().addStreamToList((ITrStream) obj); + } else if(obj instanceof ITrHierNode){ + LinkedList queue = new LinkedList(); + LinkedList streams = new LinkedList(); + queue.add((ITrHierNode)obj); + while(queue.size()>0){ + ITrHierNode n = queue.poll(); + if(n instanceof ITrStream) streams.add((ITrStream) n); + queue.addAll(n.getChildNodes()); + } + if(remove) + TxEditorPlugin.getDefault().getOpenEditorPart().removeStreamsFromList(streams.toArray(new ITrStream[]{})); + else + TxEditorPlugin.getDefault().getOpenEditorPart().addStreamsToList(streams.toArray(new ITrStream[]{})); + } + } + } + }; + action.setText(text); + action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgDescriptor)); + action.setEnabled(enabled); + return action; + } + + private Action makeTransactionAction(String text, String imgDescriptor, boolean enabled) { + Action action = new Action() { + public void run() { + ISelection selection = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getSelectionService().getSelection(); + for(Object obj :((IStructuredSelection) selection).toArray()){ + ISelection sel=null; + if(obj instanceof ITransactionFacade){ + sel = new TransactionSelection((ITransactionFacade) obj); + } else if(obj instanceof ITransaction){ + sel = new TransactionSelection(new ITransactionFacade( (ITransaction) obj)); + } + if(sel!=null) + TxEditorPlugin.getDefault().getOpenEditorPart().setSelection(sel); + } + } + }; + action.setText(text); + action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgDescriptor)); + action.setEnabled(enabled); + return action; + } +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrDbFacade.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrDbFacade.java new file mode 100644 index 0000000..757e333 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrDbFacade.java @@ -0,0 +1,86 @@ +package com.itjw.txviewer.graph.data; + +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.PropertyDescriptor; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.ServiceReference; + +import com.itjw.txviewer.database.EventTime; +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.InputFormatException; + +public class ITrDbFacade extends ITrHierNodeFacade implements ITrDb { + + protected final static String PROPERTY_DURATION = "DURATIONS"; + protected final static String PROPERTY_STREAMS = "NR_OF_STREAMS"; + + public static final String DATABASE = "DATABASE"; + + public ITrDbFacade() { + super(null); + } + + private ITrDb getDb(){ + return (ITrDb)iTrHierNode; + } + + @Override + public EventTime getMaxTime() { + return getDb().getMaxTime(); + } + + @Override + public List getAllStreams() { + return getDb().getAllStreams(); + } + + @Override + public void load(InputStream input) throws InputFormatException { + BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext(); + ServiceReference serviceReference = context.getServiceReference(ITrDb.class.getName()); + ITrDb iTrDb = (ITrDb) context.getService(serviceReference); + iTrDb.load(input); + iTrHierNode=iTrDb; + firePropertyChange(DATABASE, null, getDb()); + } + + @Override + public void clear() { + firePropertyChange(DATABASE, getDb(), null); + getDb().clear(); + } + + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + if (propertyDescriptors == null) { + super.getPropertyDescriptors(); + // Create a descriptor and set a category + PropertyDescriptor nrDescriptor = new PropertyDescriptor(PROPERTY_DURATION, "Duration"); + nrDescriptor.setCategory("Hier Node"); + PropertyDescriptor streamsDescriptor = new PropertyDescriptor(PROPERTY_STREAMS, "Stream count"); + nrDescriptor.setCategory("Hier Node"); + IPropertyDescriptor[] result = Arrays.copyOf(propertyDescriptors, propertyDescriptors.length + 2); + System.arraycopy(new IPropertyDescriptor[] {nrDescriptor, streamsDescriptor}, 0, result, propertyDescriptors.length, 2); + propertyDescriptors = result; + } + return propertyDescriptors; + } + + @Override + public Object getPropertyValue(Object id) { + if (id.equals(PROPERTY_DURATION)) { + return getMaxTime().getValueNS(); + } else if (id.equals(PROPERTY_STREAMS)) { + return getAllStreams().size(); + } else { + return super.getPropertyValue(id); + } + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrHierNodeFacade.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrHierNodeFacade.java new file mode 100644 index 0000000..83a994a --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrHierNodeFacade.java @@ -0,0 +1,150 @@ +package com.itjw.txviewer.graph.data; + +import java.beans.PropertyChangeListener; +import java.beans.PropertyChangeSupport; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.IPropertySource; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import com.itjw.txviewer.database.ITrHierNode; +import com.itjw.txviewer.database.ITrStream; + +public class ITrHierNodeFacade implements ITrHierNode, IPropertySource { + protected final static String PROPERTY_NAME = "Name"; + protected final static String PROPERTY_FULLNAME = "HierName"; + + private transient PropertyChangeSupport pcs = new PropertyChangeSupport(this); + + protected ITrHierNode iTrHierNode; + + protected ITrHierNodeFacade parent; + + protected IPropertyDescriptor[] propertyDescriptors; + + public ITrHierNodeFacade(ITrHierNode iTrHierNode) { + this.iTrHierNode = iTrHierNode; + } + + public ITrHierNodeFacade(ITrHierNode iTrHierNode, ITrHierNodeFacade parent) { + this.iTrHierNode = iTrHierNode; + this.parent=parent; + } + + @Override + public String getFullName() { + return iTrHierNode.getFullName(); + } + + @Override + public void setName(String name) { + iTrHierNode.setName(name); + } + + @Override + public String getName() { + return iTrHierNode.getName(); + } + + @Override + public List getChildNodes() { + ArrayList res = new ArrayList(); + for(ITrHierNode node:iTrHierNode.getChildNodes()){ + if(node instanceof ITrStream){ + res.add(new ITrStreamFacade((ITrStream)node)); + } else { + res.add(new ITrHierNodeFacade(node)); + } + } + return res; + } + + /** + * Attach a non-null PropertyChangeListener to this object. + * + * @param l + * a non-null PropertyChangeListener instance + * @throws IllegalArgumentException + * if the parameter is null + */ + public synchronized void addPropertyChangeListener(PropertyChangeListener l) { + if (l == null) { + throw new IllegalArgumentException(); + } + pcs.addPropertyChangeListener(l); + } + /** + * Report a property change to registered listeners (for example edit + * parts). + * + * @param property + * the programmatic name of the property that changed + * @param oldValue + * the old value of this property + * @param newValue + * the new value of this property + */ + protected void firePropertyChange(String property, Object oldValue, Object newValue) { + if (pcs.hasListeners(property)) { + pcs.firePropertyChange(property, oldValue, newValue); + } + } + + /** + * Remove a PropertyChangeListener from this component. + * + * @param l + * a PropertyChangeListener instance + */ + public synchronized void removePropertyChangeListener(PropertyChangeListener l) { + if (l != null) { + pcs.removePropertyChangeListener(l); + } + } + + // IPropertySource methods + @Override + public Object getEditableValue() { + return null; + } + + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + if (propertyDescriptors == null) { + // Create a descriptor and set a category + PropertyDescriptor nameDescriptor = new PropertyDescriptor(PROPERTY_NAME, "Name"); + nameDescriptor.setCategory("Hier Node"); + PropertyDescriptor fullnameDescriptor = new PropertyDescriptor(PROPERTY_FULLNAME, "Full name"); + fullnameDescriptor.setCategory("Hier Node"); + propertyDescriptors = new IPropertyDescriptor[] {nameDescriptor, fullnameDescriptor}; + } + return propertyDescriptors; + } + + @Override + public Object getPropertyValue(Object id) { + if (id.equals(PROPERTY_NAME)) { + return getName(); + } else if(id.equals(PROPERTY_FULLNAME)){ + return getFullName(); + } else + return null; + } + + @Override + public boolean isPropertySet(Object id) { + String curName = (String)getPropertyValue(id); + return curName!=null && curName.length()>0; + } + + @Override + public void resetPropertyValue(Object id) { + } + + @Override + public void setPropertyValue(Object id, Object value) { + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrStreamFacade.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrStreamFacade.java new file mode 100644 index 0000000..678bf81 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITrStreamFacade.java @@ -0,0 +1,102 @@ +package com.itjw.txviewer.graph.data; + +import java.util.Arrays; +import java.util.List; + +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrGenerator; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.ITransaction; + +public class ITrStreamFacade extends ITrHierNodeFacade implements ITrStream { + + protected final static String PROPERTY_NUMBER = "NR_OF_TRANSACTIONS"; + private int height; + + private ITrStream getStream(){ + return (ITrStream)iTrHierNode; + } + + public ITrStreamFacade(ITrStream iTrStream) { + super(iTrStream); + } + + public ITrStreamFacade(ITrStream iTrStream, ITrHierNodeFacade parent) { + super(iTrStream, parent); + } + + @Override + public Long getId() { + return getStream().getId(); + } + + @Override + public String getKind() { + return getStream().getKind(); + } + + @Override + public ITrDb getDb() { + // TODO Auto-generated method stub + return getStream().getDb(); + } + + @Override + public List getGenerators() { + return getStream().getGenerators(); + } + + @Override + public List getTransactions() { + return getStream().getTransactions(); + } + + @Override + public int getMaxConcurrrentTx() { + return getStream().getMaxConcurrrentTx(); + } + + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + if (propertyDescriptors == null) { + super.getPropertyDescriptors(); + // Create a descriptor and set a category + PropertyDescriptor nrDescriptor = new PropertyDescriptor(PROPERTY_NUMBER, "# of transactions"); + nrDescriptor.setCategory("Stream"); + IPropertyDescriptor[] result = Arrays.copyOf(propertyDescriptors, propertyDescriptors.length + 1); + System.arraycopy(new IPropertyDescriptor[] {nrDescriptor}, 0, result, propertyDescriptors.length, 1); + propertyDescriptors = result; + } + return propertyDescriptors; + } + + @Override + public Object getPropertyValue(Object id) { + if (id.equals(PROPERTY_NUMBER)) { + return getStream().getTransactions().size(); + } else { + return super.getPropertyValue(id); + } + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + + public double getMaxTimeNS() { + return getDb().getMaxTime().getValueNS(); + } + + public String getValueAtCursor(int i) { + return "-"; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionFacade.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionFacade.java new file mode 100644 index 0000000..89d9913 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionFacade.java @@ -0,0 +1,70 @@ +package com.itjw.txviewer.graph.data; + +import java.util.List; +import java.util.Set; + +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.ui.views.properties.IPropertySource; + +import com.itjw.txviewer.database.EventTime; +import com.itjw.txviewer.database.ITrAttribute; +import com.itjw.txviewer.database.ITrGenerator; +import com.itjw.txviewer.database.ITransaction; +import com.itjw.txviewer.database.RelationType; + +public class ITransactionFacade implements ITransaction, IAdaptable { + + protected ITransaction iTransaction; + + public ITransactionFacade(ITransaction iTransaction) { + this.iTransaction = iTransaction; + } + + @Override + public Long getId() { + return iTransaction.getId(); + } + + @Override + public ITrGenerator getGenerator() { + return iTransaction.getGenerator(); + } + + @Override + public EventTime getBeginTime() { + return iTransaction.getBeginTime(); + } + + @Override + public EventTime getEndTime() { + return iTransaction.getEndTime(); + } + + @Override + public List getBeginAttrs() { + return iTransaction.getBeginAttrs(); + } + + @Override + public List getEndAttrs() { + return iTransaction.getEndAttrs(); + } + + @Override + public List getAttributes() { + return iTransaction.getAttributes(); + } + + @Override + public Set getNextInRelationship(RelationType rel) { + return iTransaction.getNextInRelationship(rel); + } + + @SuppressWarnings("rawtypes") + @Override + public Object getAdapter(Class adapter) { + if (adapter == IPropertySource.class) + return new ITransactionProperties(this); + return null; + } +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionProperties.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionProperties.java new file mode 100644 index 0000000..6a38495 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/data/ITransactionProperties.java @@ -0,0 +1,107 @@ +package com.itjw.txviewer.graph.data; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.ui.views.properties.IPropertyDescriptor; +import org.eclipse.ui.views.properties.IPropertySource; +import org.eclipse.ui.views.properties.PropertyDescriptor; + +import com.itjw.txviewer.database.ITrAttribute; +import com.itjw.txviewer.database.ITransaction; + +public class ITransactionProperties implements IPropertySource { + + private ITransaction iTransaction; + + public final static String PROPERTY_ID = "ID"; + public final static String PROPERTY_BEGINTIME = "BEGINTIME"; + public final static String PROPERTY_ENDTIME = "ENDTIME"; + + protected IPropertyDescriptor[] propertyDescriptors; + + public ITransactionProperties(ITransaction iTransaction) { + this.iTransaction=iTransaction; + } + + @Override + public Object getEditableValue() { + return null; + } + + @Override + public IPropertyDescriptor[] getPropertyDescriptors() { + if (propertyDescriptors == null) { + ArrayList idDescriptor=new ArrayList(); + // Create a descriptor and set a category + PropertyDescriptor nameDescriptor = new PropertyDescriptor(PROPERTY_ID, "Id"); + nameDescriptor.setCategory("Attributes"); + idDescriptor.add(nameDescriptor); + PropertyDescriptor begTimeDescriptor = new PropertyDescriptor(PROPERTY_BEGINTIME, "Begin time"); + begTimeDescriptor.setCategory("Attributes"); + idDescriptor.add(begTimeDescriptor); + PropertyDescriptor endTimeDescriptor = new PropertyDescriptor(PROPERTY_ENDTIME, "End time"); + endTimeDescriptor.setCategory("Attributes"); + idDescriptor.add(endTimeDescriptor); +// for(ITrAttribute attr:iTransaction.getBeginAttrs()){ +// PropertyDescriptor descr = new PropertyDescriptor("BEGIN_"+attr.getName(), attr.getName()); +// descr.setCategory("Begin attributes"); +// idDescriptor.add(descr); +// } +// for(ITrAttribute attr:iTransaction.getEndAttrs()){ +// PropertyDescriptor descr = new PropertyDescriptor("END_"+attr.getName(), attr.getName()); +// descr.setCategory("End attributes"); +// idDescriptor.add(descr); +// } +// for(ITrAttribute attr:iTransaction.getAttributes()){ +// PropertyDescriptor descr = new PropertyDescriptor("REC_"+attr.getName(), attr.getName()); +// descr.setCategory("Recorded attributes"); +// idDescriptor.add(descr); +// } + propertyDescriptors = idDescriptor.toArray(new IPropertyDescriptor[idDescriptor.size()]); + } + return propertyDescriptors; + } + + @Override + public Object getPropertyValue(Object id) { + if (id.equals(PROPERTY_ID)) { + return iTransaction.getId(); + } else if(id.equals(PROPERTY_BEGINTIME)){ + return iTransaction.getBeginTime();//.getValueNS(); + } else if(id.equals(PROPERTY_ENDTIME)){ + return iTransaction.getEndTime();//.getValueNS(); + } else if(id instanceof String){ + String strId=(String)id; + List set; + if(strId.startsWith("BEGIN_")){ + set=iTransaction.getBeginAttrs(); + } else if(strId.startsWith("END_")){ + set=iTransaction.getEndAttrs(); + } else { + set=iTransaction.getAttributes(); + } + for(ITrAttribute attr:set){ + if(strId.endsWith("_"+attr.getName())){ + return attr.getValue(); + } + } + } + return null; + } + + @Override + public boolean isPropertySet(Object id) { + String curName = (String)getPropertyValue(id); + return curName!=null && curName.length()>0; + } + + @Override + public void resetPropertyValue(Object id) { + } + + @Override + public void setPropertyValue(Object id, Object value) { + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ListPane.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ListPane.java new file mode 100644 index 0000000..6c7d00e --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ListPane.java @@ -0,0 +1,162 @@ +package com.itjw.txviewer.graph.ui.swt; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.FormLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.ScrollBar; +import com.itjw.txviewer.graph.TxEditorPlugin; +import com.itjw.txviewer.graph.data.ITrStreamFacade; + +public abstract class ListPane extends Composite implements PaintListener { + + public static final String SELECTION= "StreamSelected"; + + private TxEditorPlugin plugin; + private TxDisplay display; + ScrolledComposite scroll; + Composite frame; + private MouseAdapter mouseLabelListener; + private List listeners = new ArrayList(); + + public ListPane(Composite parent, TxDisplay txDisplay) { + super(parent, SWT.NONE); + FormLayout fl = new FormLayout(); + fl.marginHeight = 0; + fl.marginWidth = 0; + this.setLayout(fl); + plugin=TxEditorPlugin.getDefault(); + display=txDisplay; + + Label header=new Label(this, SWT.NONE); + header.setText(getHeaderValue()); + header.setAlignment(SWT.CENTER); + FormData fh = new FormData(); + fh.top=fh.left=new FormAttachment(0); + fh.right=new FormAttachment(100); + fh.bottom=new FormAttachment(0, WaveImageCanvas.rulerHeight); + header.setLayoutData(fh); + header.setBackground(plugin.getColor(TxEditorPlugin.headerBgColor)); + header.setForeground(plugin.getColor(TxEditorPlugin.headerFgColor)); + + scroll=new ScrolledComposite(this, SWT.H_SCROLL | SWT.V_SCROLL); + FormData fd = new FormData(); + fd.top=new FormAttachment(0); + fd.bottom=new FormAttachment(100); + fd.left=new FormAttachment(0); + fd.right=new FormAttachment(100); + scroll.setLayoutData(fd); + scroll.setAlwaysShowScrollBars(true); + scroll.getHorizontalBar().setVisible(true); + scroll.getVerticalBar().setVisible(false); + frame = new Composite(scroll, SWT.NONE); + + GridLayout gl = new GridLayout(1, false); + gl.marginHeight = 0; + gl.marginWidth = 0; + gl.verticalSpacing = 0; + frame.setLayout(gl); + scroll.setContent(frame); + scroll.setExpandVertical(true); + scroll.setExpandHorizontal(true); + scroll.addControlListener(new ControlAdapter() { + public void controlResized(ControlEvent e) { + updateSize(); + } + }); + scroll.pack(); + mouseLabelListener = new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + fireStreamSelected(e.widget.getData()); + } + }; + } + + public void scrollToY(int y){ + if (scroll.getContent() == null) return; + Point location = scroll.getContent().getLocation (); + ScrollBar vBar = scroll.getVerticalBar (); + vBar.setSelection(y); + scroll.getContent().setLocation (location.x, -y); + } + + public void streamListChanged() { + for(Control ctrl:frame.getChildren()) ctrl.dispose(); + int trackIdx=0; + for(ITrStreamFacade str: display.getTxEditor().getStreamList()){ + Label l = new Label(frame, SWT.NONE); + l.setText(getLabelValue(str)); + l.setData(str); + formatLabel(l, str, trackIdx++); + l.addMouseListener(mouseLabelListener); + } + frame.pack(true); + frame.layout(true); + updateSize(); + } + + protected void formatLabel(Label l, ITrStreamFacade str, int trackIdx){ +// GridData gd = new GridData(SWT.FILL, SWT.CENTER, true, false); + GridData gd = new GridData(); + gd.verticalIndent=trackIdx==0?WaveImageCanvas.rulerHeight:0; + gd.verticalAlignment = SWT.CENTER; + gd.horizontalAlignment = SWT.FILL; + gd.heightHint=str.getHeight(); + gd.grabExcessHorizontalSpace=true; + l.setLayoutData(gd); + l.setBackground(trackIdx%2==0?plugin.getColor(TxEditorPlugin.trackBgLightColor):plugin.getColor(TxEditorPlugin.trackBgDarkColor)); + l.setSize(0,str.getHeight()); + } + + public void paintControl(PaintEvent e){ + e.gc.setBackground(new Color(null, 255, 255, 255)); + e.gc.fillRectangle(e.x, e.y, e.width, 20); + } + + private void updateSize() { + Rectangle r = getClientArea(); + Point p = frame.computeSize(SWT.DEFAULT, SWT.DEFAULT); + scroll.setMinSize(frame.computeSize(r.width>p.x?r.width:p.x, SWT.DEFAULT)); + scroll.getVerticalBar().setVisible(false); + } + + public void addLabelClickListener(PropertyChangeListener listener){ + listeners.add(listener); + } + + public void removePropertyChangeListener(PropertyChangeListener listener) { + listeners.remove(listener); + } + + protected void fireStreamSelected(Object newValue) { + PropertyChangeEvent event = new PropertyChangeEvent(this, SELECTION, null, newValue); + for (int i = 0; i < listeners.size(); i++) + listeners.get(i).propertyChange(event); + } + + abstract String getHeaderValue(); + + abstract String getLabelValue(ITrStreamFacade str); + +} \ No newline at end of file diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/NameListPane.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/NameListPane.java new file mode 100644 index 0000000..271d355 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/NameListPane.java @@ -0,0 +1,23 @@ +package com.itjw.txviewer.graph.ui.swt; + +import org.eclipse.swt.widgets.Composite; + +import com.itjw.txviewer.graph.data.ITrStreamFacade; + +public class NameListPane extends ListPane { + + public NameListPane(Composite parent, TxDisplay txDisplay) { + super(parent, txDisplay); + } + + @Override + String getLabelValue(ITrStreamFacade str) { + return str.getFullName(); + } + + @Override + String getHeaderValue() { + return "Name"; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.java new file mode 100644 index 0000000..2780f4b --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/SWTImageCanvas.java @@ -0,0 +1,376 @@ +package com.itjw.txviewer.graph.ui.swt; + +import java.awt.geom.AffineTransform; +import java.awt.geom.Point2D; + +import org.eclipse.swt.events.ControlAdapter; +import org.eclipse.swt.events.ControlEvent; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ScrollBar; + +public class SWTImageCanvas extends Canvas { + /* zooming rates in x and y direction are equal.*/ + final float ZOOMIN_RATE = 1.1f; /* zoomin rate */ + final float ZOOMOUT_RATE = 0.9f; /* zoomout rate */ + protected Image sourceImage; /* original image */ + private Image screenImage; /* screen image */ + private AffineTransform transform = new AffineTransform(); + protected boolean center; + + + /** + * Constructor for ScrollableCanvas. + * @param parent the parent of this control. + * @param style the style of this control. + */ + public SWTImageCanvas(final Composite parent, int style) { + super( parent, style ); + center=true; + addControlListener(new ControlAdapter() { /* resize listener. */ + public void controlResized(ControlEvent event) { + syncScrollBars(); + } + }); + addPaintListener(new PaintListener() { /* paint listener. */ + public void paintControl(final PaintEvent event) { + paint(event.gc); + } + }); + initScrollBars(); + } + + /** + * Dispose the garbage here + */ + public void dispose() { + if (sourceImage != null && !sourceImage.isDisposed()) { + sourceImage.dispose(); + } + if (screenImage != null && !screenImage.isDisposed()) { + screenImage.dispose(); + } + } + + /* Paint function */ + private void paint(GC gc) { + Rectangle clientRect = getClientArea(); /* Canvas' painting area */ + if (sourceImage != null) { + Rectangle imageRect = inverseTransformRect(transform, clientRect); + int gap = 2; /* find a better start point to render */ + imageRect.x -= gap; imageRect.y -= gap; + imageRect.width += 2 * gap; imageRect.height += 2 * gap; + + Rectangle imageBound = sourceImage.getBounds(); + imageRect = imageRect.intersection(imageBound); + Rectangle destRect = transformRect(transform, imageRect); + + if (screenImage != null) screenImage.dispose(); + screenImage = new Image(getDisplay(), clientRect.width, clientRect.height); + GC newGC = new GC(screenImage); + newGC.setClipping(clientRect); + newGC.drawImage(sourceImage, + imageRect.x, imageRect.y, imageRect.width, imageRect.height, + destRect.x, destRect.y, destRect.width, destRect.height); + newGC.dispose(); + + gc.drawImage(screenImage, 0, 0); + + postImagePaint(gc); + } else { + gc.setClipping(clientRect); + gc.fillRectangle(clientRect); + initScrollBars(); + } + } + + protected void postImagePaint(GC gc){ + // do nothing, to be overridden by childs + } + + /* Initalize the scrollbar and register listeners. */ + private void initScrollBars() { + ScrollBar horizontal = getHorizontalBar(); + horizontal.setEnabled(false); + horizontal.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + scrollHorizontally((ScrollBar) event.widget); + } + }); + ScrollBar vertical = getVerticalBar(); + vertical.setEnabled(false); + vertical.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent event) { + scrollVertically((ScrollBar) event.widget); + } + }); + } + + /* Scroll horizontally */ + private void scrollHorizontally(ScrollBar scrollBar) { + if (sourceImage == null) return; + + AffineTransform af = transform; + double tx = af.getTranslateX(); + double select = -scrollBar.getSelection(); + af.preConcatenate(AffineTransform.getTranslateInstance(select - tx, 0)); + transform = af; + syncScrollBars(); + } + + /* Scroll vertically */ + private void scrollVertically(ScrollBar scrollBar) { + if (sourceImage == null) return; + + AffineTransform af = transform; + double ty = af.getTranslateY(); + double select = -scrollBar.getSelection(); + af.preConcatenate(AffineTransform.getTranslateInstance(0, select - ty)); + transform = af; + syncScrollBars(); + } + + public void scrollToY(int y){ + ScrollBar vBar = getVerticalBar(); + vBar.setSelection(y); + scrollVertically(vBar); + } + + public void scrollToX(int x){ + ScrollBar hBar = getHorizontalBar(); + hBar.setSelection(x); + scrollHorizontally(hBar); + } + + /** + * Source image getter. + * @return sourceImage. + */ + public Image getSourceImage() { + return sourceImage; + } + + /** + * Source image setter. + * @return sourceImage. + */ + public void setSourceImage(Image sourceImage) { + if(this.sourceImage!=null) this.sourceImage.dispose(); + this.sourceImage=sourceImage; + } + + public AffineTransform getTransform() { + return transform; + } + + /** + * Synchronize the scrollbar with the image. If the transform is out + * of range, it will correct it. This function considers only following + * factors : transform, image size, client area. + */ + public void syncScrollBars() { + if (sourceImage == null) { + redraw(); + return; + } + + AffineTransform af = transform; + double sx = af.getScaleX(), sy = af.getScaleY(); + double tx = af.getTranslateX(), ty = af.getTranslateY(); + if (tx > 0) tx = 0; + if (ty > 0) ty = 0; + + ScrollBar horizontal = getHorizontalBar(); + horizontal.setIncrement((int) (getClientArea().width / 100)); + horizontal.setPageIncrement(getClientArea().width); + Rectangle imageBound = sourceImage.getBounds(); + int cw = getClientArea().width, ch = getClientArea().height; + if (imageBound.width * sx > cw) { /* image is wider than client area */ + horizontal.setMaximum((int) (imageBound.width * sx)); + horizontal.setEnabled(true); + if (((int) - tx) > horizontal.getMaximum() - cw) + tx = -horizontal.getMaximum() + cw; + } else { /* image is narrower than client area */ + horizontal.setEnabled(false); + tx = center?((cw - imageBound.width * sx) / 2):0; //center or put left if too small. + } + horizontal.setSelection((int) (-tx)); + horizontal.setThumb((int) (getClientArea().width)); + + ScrollBar vertical = getVerticalBar(); + vertical.setIncrement((int) (getClientArea().height / 100)); + vertical.setPageIncrement((int) (getClientArea().height)); + if (imageBound.height * sy > ch) { /* image is higher than client area */ + vertical.setMaximum((int) (imageBound.height * sy)); + vertical.setEnabled(true); + if (((int) - ty) > vertical.getMaximum() - ch) + ty = -vertical.getMaximum() + ch; + } else { /* image is less higher than client area */ + vertical.setEnabled(false); + ty = center?((ch - imageBound.height * sy) / 2):0; //center or put top if too small. + } + vertical.setSelection((int) (-ty)); + vertical.setThumb((int) (getClientArea().height)); + + /* update transform. */ + af = AffineTransform.getScaleInstance(sx, sy); + af.preConcatenate(AffineTransform.getTranslateInstance(tx, ty)); + transform = af; + + redraw(); + } + + /** + * Fit the image onto the canvas + */ + public void fitCanvas() { + if (sourceImage == null) return; + Rectangle imageBound = sourceImage.getBounds(); + Rectangle destRect = getClientArea(); + double sx = (double) destRect.width / (double) imageBound.width; + double sy = (double) destRect.height / (double) imageBound.height; + double s = Math.min(sx, sy); + double dx = 0.5 * destRect.width; + double dy = 0.5 * destRect.height; + centerZoom(dx, dy, s, new AffineTransform()); + } + + /** + * Show the image with the original size + */ + public void resetTransform() { + if (sourceImage == null) return; + transform = new AffineTransform(); + syncScrollBars(); + } + + /** + * Perform a zooming operation centered on the given point + * (dx, dy) and using the given scale factor. + * The given AffineTransform instance is preconcatenated. + * @param dx center x + * @param dy center y + * @param scale zoom rate + * @param af original affinetransform + */ + public void centerZoom(double dx, double dy, double scale, AffineTransform af) { + af.preConcatenate(AffineTransform.getTranslateInstance(-dx, -dy)); + af.preConcatenate(AffineTransform.getScaleInstance(scale, scale)); + af.preConcatenate(AffineTransform.getTranslateInstance(dx, dy)); + transform = af; + syncScrollBars(); + } + + /** + * Zoom in around the center of client Area. + */ + public void zoomIn() { + if (sourceImage == null) return; + Rectangle rect = getClientArea(); + int w = rect.width, h = rect.height; + double dx = ((double) w) / 2; + double dy = ((double) h) / 2; + centerZoom(dx, dy, ZOOMIN_RATE, transform); + } + + /** + * Zoom out around the center of client Area. + */ + public void zoomOut() { + if (sourceImage == null) return; + Rectangle rect = getClientArea(); + int w = rect.width, h = rect.height; + double dx = ((double) w) / 2; + double dy = ((double) h) / 2; + centerZoom(dx, dy, ZOOMOUT_RATE, transform); + } + + /** + * Given an arbitrary rectangle, get the rectangle with the given transform. + * The result rectangle is positive width and positive height. + * @param af AffineTransform + * @param src source rectangle + * @return rectangle after transform with positive width and height + */ + protected static Rectangle transformRect(AffineTransform af, Rectangle src){ + Rectangle dest= new Rectangle(0,0,0,0); + src=absRect(src); + Point p1=new Point(src.x,src.y); + p1=transformPoint(af,p1); + dest.x=p1.x; dest.y=p1.y; + dest.width=(int)(src.width*af.getScaleX()); + dest.height=(int)(src.height*af.getScaleY()); + return dest; + } + + /** + * Given an arbitrary rectangle, get the rectangle with the inverse given transform. + * The result rectangle is positive width and positive height. + * @param af AffineTransform + * @param src source rectangle + * @return rectangle after transform with positive width and height + */ + protected static Rectangle inverseTransformRect(AffineTransform af, Rectangle src){ + Rectangle dest= new Rectangle(0,0,0,0); + src=absRect(src); + Point p1=new Point(src.x,src.y); + p1=inverseTransformPoint(af,p1); + dest.x=p1.x; dest.y=p1.y; + dest.width=(int)(src.width/af.getScaleX()); + dest.height=(int)(src.height/af.getScaleY()); + return dest; + } + /** + * Given an arbitrary point, get the point with the given transform. + * @param af affine transform + * @param pt point to be transformed + * @return point after tranform + */ + protected static Point transformPoint(AffineTransform af, Point pt) { + Point2D src = new Point2D.Float(pt.x, pt.y); + Point2D dest= af.transform(src, null); + Point point=new Point((int)Math.floor(dest.getX()), (int)Math.floor(dest.getY())); + return point; + } + + /** + * Given an arbitrary point, get the point with the inverse given transform. + * @param af AffineTransform + * @param pt source point + * @return point after transform + */ + protected static Point inverseTransformPoint(AffineTransform af, Point pt){ + Point2D src=new Point2D.Float(pt.x,pt.y); + try{ + Point2D dest= af.inverseTransform(src, null); + return new Point((int)Math.floor(dest.getX()), (int)Math.floor(dest.getY())); + }catch (Exception e){ + e.printStackTrace(); + return new Point(0,0); + } + } + + /** + * Given arbitrary rectangle, return a rectangle with upper-left + * start and positive width and height. + * @param src source rectangle + * @return result rectangle with positive width and height + */ + protected static Rectangle absRect(Rectangle src){ + Rectangle dest= new Rectangle(0,0,0,0); + if(src.width<0) { dest.x=src.x+src.width+1; dest.width=-src.width; } + else{ dest.x=src.x; dest.width=src.width; } + if(src.height<0) { dest.y=src.y+src.height+1; dest.height=-src.height; } + else{ dest.y=src.y; dest.height=src.height; } + return dest; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/TxDisplay.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/TxDisplay.java new file mode 100644 index 0000000..920f51a --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/TxDisplay.java @@ -0,0 +1,170 @@ +package com.itjw.txviewer.graph.ui.swt; + +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; + +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.SashForm; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.ScrollBar; +import org.eclipse.ui.IWorkbenchPartSite; + +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.database.ITransaction; +import com.itjw.txviewer.graph.TrHierNodeSelection; +import com.itjw.txviewer.graph.TransactionSelection; +import com.itjw.txviewer.graph.TxEditorPart; +import com.itjw.txviewer.graph.data.ITrDbFacade; +import com.itjw.txviewer.graph.data.ITrStreamFacade; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class TxDisplay implements PropertyChangeListener, ISelectionProvider{ + + private TxEditorPart txEditor; + private SashForm sashFormTop; + private ListPane txNamePane; + private ListPane txValuePane; + private WaveImageCanvas waveImageCanvas; + + private ListenerList listeners = new ListenerList(); + private ITrStreamFacade currentStreamSelection; + private ITransactionFacade currentSelection; + + public TxDisplay(Composite parent, TxEditorPart txEditorPart, IWorkbenchPartSite site) { + txEditor = txEditorPart; + sashFormTop = new SashForm(parent, SWT.HORIZONTAL+SWT.BORDER); + sashFormTop.setLayoutData(new GridData(GridData.FILL_BOTH)); + final SashForm sashFormLeft = new SashForm(sashFormTop, SWT.HORIZONTAL); + txNamePane = new NameListPane(sashFormLeft, this); + txNamePane.addLabelClickListener(this); + txValuePane = new ValueListPane(sashFormLeft, this); + txValuePane.addLabelClickListener(this); + waveImageCanvas = new WaveImageCanvas(sashFormTop, SWT.DOUBLE_BUFFERED|SWT.H_SCROLL|SWT.V_SCROLL); + waveImageCanvas.addMouseListener(new MouseAdapter() { + @Override + public void mouseUp(MouseEvent e) { + currentSelection = waveImageCanvas.getTransactionAtPos(new Point(e.x, e.y)); + waveImageCanvas.setCurrentSelection(currentSelection); + if(currentSelection!=null || currentStreamSelection!=null) + setSelection(getSelection()); + else + setSelection(StructuredSelection.EMPTY); + } + }); + txNamePane.scroll.getVerticalBar().addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int y = ((ScrollBar) e.widget).getSelection(); + txValuePane.scrollToY(y); + waveImageCanvas.scrollToY(y); + } + }); + txValuePane.scroll.getVerticalBar().addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int y = ((ScrollBar) e.widget).getSelection(); + txNamePane.scrollToY(y); + waveImageCanvas.scrollToY(y); + } + }); + waveImageCanvas.getVerticalBar().addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + int y = ((ScrollBar) e.widget).getSelection(); + txNamePane.scrollToY(y); + txValuePane.scrollToY(y); + } + }); + + sashFormTop.setWeights(new int[] {30, 70}); + sashFormLeft.setWeights(new int[] {75, 25}); + + if(txEditor.getModel()!= null) + streamListChanged(); + } + + public TxEditorPart getTxEditor() { + return txEditor; + } + + public void streamListChanged() { + waveImageCanvas.setWaveformList(getTxEditor().getStreamList()); + txNamePane.streamListChanged(); + txValuePane.streamListChanged(); + sashFormTop.redraw(); + } + + public void addSelectionListener(SelectionListener listener) { + waveImageCanvas.addSelectionListener(listener); + } + + @Override + public void propertyChange(PropertyChangeEvent pce) { + if(pce.getPropertyName().equals(ITrDbFacade.DATABASE)){ + streamListChanged(); + }else if(pce.getPropertyName().equals(ListPane.SELECTION)){ + currentSelection=null; + ITrStream str = (ITrStream)pce.getNewValue(); + if(str instanceof ITrStreamFacade) + currentStreamSelection=(ITrStreamFacade)str; + else + currentStreamSelection=new ITrStreamFacade(str); + if(currentStreamSelection!=null) + setSelection(getSelection()); + else + setSelection(StructuredSelection.EMPTY); + } + + } + + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + listeners.add(listener); + } + + @Override + public ISelection getSelection() { + if(currentSelection!=null) + return new TransactionSelection(currentSelection); + else if(currentStreamSelection!=null) + return new TrHierNodeSelection(currentStreamSelection); + else + return null; + } + + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + listeners.remove(listener); + } + + @Override + public void setSelection(ISelection selection) { + if(selection instanceof TransactionSelection){ + ITransaction tr =((TransactionSelection)selection).getFirstElement(); + currentSelection = (tr instanceof ITransactionFacade)?(ITransactionFacade)tr:new ITransactionFacade(tr); + } + Object[] list = listeners.getListeners(); + for (int i = 0; i < list.length; i++) { + ((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection)); + } + if(waveImageCanvas.getCurrentSelection()!=currentSelection) + waveImageCanvas.setCurrentSelection(currentSelection); + waveImageCanvas.getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + waveImageCanvas.redraw(); + } + }); + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ValueListPane.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ValueListPane.java new file mode 100644 index 0000000..3d2b279 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/ValueListPane.java @@ -0,0 +1,30 @@ +package com.itjw.txviewer.graph.ui.swt; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; + +import com.itjw.txviewer.graph.data.ITrStreamFacade; + +public class ValueListPane extends ListPane { + + public ValueListPane(Composite parent, TxDisplay txDisplay) { + super(parent, txDisplay); + } + + @Override + String getLabelValue(ITrStreamFacade str) { + return str.getValueAtCursor(0); + } + + @Override + String getHeaderValue() { + return "Value"; + } + + protected void formatLabel(Label l, ITrStreamFacade str, int trackIdx){ + super.formatLabel(l, str, trackIdx); + l.setAlignment(SWT.CENTER); + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.java new file mode 100644 index 0000000..fb110f0 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/ui/swt/WaveImageCanvas.java @@ -0,0 +1,213 @@ +package com.itjw.txviewer.graph.ui.swt; + +import java.util.Iterator; +import java.util.LinkedList; +import java.util.TreeMap; +import java.util.Vector; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TypedListener; + +import com.itjw.txviewer.database.ITransaction; +import com.itjw.txviewer.graph.TxEditorPlugin; +import com.itjw.txviewer.graph.data.ITrStreamFacade; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class WaveImageCanvas extends SWTImageCanvas{ + + static final int rulerHeight = 20; + static final int rulerTickMinor = 10; + static final int rulerTickMajor = 100; + static final int trackHeight = 50; + static final int trackInset =2; + static final int txHeight = trackHeight-2*trackInset; + + private TxEditorPlugin plugin; + private Rectangle size = new Rectangle(0,0,0,0); + private TreeMap loc2str; + private TreeMap strId2bb; + + private ITransactionFacade currentSelection; + + public WaveImageCanvas(final Composite parent) { + this(parent, SWT.NONE); + } + + public WaveImageCanvas(final Composite parent, int style) { + super(parent, style | SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_BACKGROUND); + plugin=TxEditorPlugin.getDefault(); + loc2str=new TreeMap(); + strId2bb=new TreeMap(); + center=false; + } + + public void setWaveformList(LinkedList linkedList){ + double maxTime=1.0; + int height=rulerHeight; + for(ITrStreamFacade str:linkedList){ + maxTime = Math.max(maxTime, str.getDb().getMaxTime().getValueNS()); + int strHeight=str.getMaxConcurrrentTx(); + str.setHeight(strHeight*trackHeight); + height+=str.getHeight(); + } + size = new Rectangle(0,0,(int) Math.ceil(maxTime),height); + Image buffer = new Image(getDisplay(), size); + GC gc = new GC(buffer); + gc.setAntialias(SWT.ON); + int trackOffset=rulerHeight; + int trackIdx=0; + Vector rowendtime = new Vector(); + loc2str.clear(); + strId2bb.clear(); + for(ITrStreamFacade str:linkedList){ + loc2str.put(trackOffset, str); + rowendtime.clear(); + rowendtime.add(0); + drawTrack(gc, new Rectangle(0, trackOffset, size.width, trackHeight), trackIdx); + for(ITransaction tx: str.getTransactions()){ + int rowIdx=0; + Integer beginTime = (int)(tx.getBeginTime().getValueNS()); + Integer endTime = (int)(tx.getEndTime().getValueNS()); + for(rowIdx=0; rowendtime.size()beginTime; rowIdx++); + if(rowendtime.size()<=rowIdx){ + rowendtime.add(endTime!=null?endTime:beginTime+1); + drawTrack(gc, new Rectangle(0, trackOffset+rowIdx*trackHeight, size.width, trackHeight), trackIdx); + } else { + rowendtime.set(rowIdx, endTime!=null?endTime:beginTime+1); + } + int width = endTime!=null?endTime-beginTime:1; + Rectangle bb = new Rectangle(beginTime, trackOffset+rowIdx*trackHeight+trackInset, width, txHeight); + strId2bb.put(tx.getId(), bb); + drawTx(gc, bb); + } + trackOffset+=rowendtime.size()*trackHeight; + trackIdx++; + } + gc.dispose(); + setSourceImage(buffer); + redraw(); + syncScrollBars(); + } + + private void drawTx(GC gc, Rectangle bb){ + gc.setForeground(plugin.getColor(TxEditorPlugin.lineColor)); + gc.setFillRule(SWT.FILL_EVEN_ODD); + gc.setBackground(plugin.getColor(TxEditorPlugin.txBgColor)); + gc.setLineWidth(1); + gc.setLineStyle(SWT.LINE_SOLID); + if(bb.width<8){ + gc.fillRectangle(bb); + gc.drawRectangle(bb); + } else { + gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 4, 4); + gc.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 4, 4); + } + } + + private void drawHighliteTx(GC gc, Rectangle bb){ + gc.setForeground(plugin.getColor(TxEditorPlugin.highliteLineColor)); + gc.setFillRule(SWT.FILL_EVEN_ODD); + gc.setBackground(plugin.getColor(TxEditorPlugin.txHighliteBgColor)); + gc.setLineWidth(1); + gc.setLineStyle(SWT.LINE_SOLID); + if(bb.width<10){ + gc.fillRectangle(bb); + gc.drawRectangle(bb); + } else { + gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); + gc.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 5, 5); + } + } + + private void drawTrack(GC gc, Rectangle bb, int trackIdx){ + gc.setForeground(plugin.getColor(TxEditorPlugin.lineColor)); + gc.setFillRule(SWT.FILL_EVEN_ODD); + gc.setBackground(trackIdx%2==0? + plugin.getColor(TxEditorPlugin.trackBgLightColor): + plugin.getColor(TxEditorPlugin.trackBgDarkColor)); + gc.setLineWidth(1); + gc.setLineStyle(SWT.LINE_SOLID); + gc.fillRectangle(bb); + gc.drawLine(bb.x, bb.y+bb.height/2, bb.width, bb.y+bb.height/2); + } + + protected void postImagePaint(GC gc){ + Rectangle imageRect = inverseTransformRect(getTransform(), getClientArea()); + if(currentSelection!=null){ + Rectangle bb = strId2bb.get(currentSelection.getId()); + if(bb != null) { + drawHighliteTx(gc, new Rectangle(bb.x-imageRect.x, bb.y-imageRect.y, bb.width, bb.height)); + } else + System.err.print("No bounding box for transaction "+currentSelection.getId()+" found!"); + } + drawRuler(gc, imageRect); + } + + private void drawRuler(GC gc, Rectangle clientRect) { + int startMinorIncr = ((int)(clientRect.x/rulerTickMinor))*rulerTickMinor; + gc.setBackground(getDisplay().getSystemColor (SWT.COLOR_WIDGET_BACKGROUND)); + gc.fillRectangle(new Rectangle(-clientRect.x, 0, clientRect.width, rulerHeight)); + gc.setBackground(plugin.getColor(TxEditorPlugin.headerBgColor)); + gc.fillRectangle(new Rectangle(-clientRect.x, 0, clientRect.width, rulerHeight-1)); + gc.setForeground(plugin.getColor(TxEditorPlugin.headerFgColor)); + gc.drawLine(-clientRect.x, rulerHeight-2, clientRect.width+clientRect.x, rulerHeight-2); + for(int x=startMinorIncr; x<(clientRect.x+clientRect.width); x+=rulerTickMinor){ + if((x%rulerTickMajor)==0){ + gc.drawLine(x-clientRect.x, 10, x-clientRect.x, rulerHeight-2); + gc.drawText(Integer.toString(x), x-clientRect.x, 0); + }else{ + gc.drawLine(x-clientRect.x, 15, x-clientRect.x, rulerHeight-2); + } + } + } + + private ITransaction getTrAtTime(ITrStreamFacade str, double t){ + ITransaction res=null; + Iterator iter = str.getTransactions().iterator(); + while(iter.hasNext()){ + res = iter.next(); + if(res.getEndTime().getValueNS()>=t) break; + } + if(res!=null && res.getBeginTime().getValueNS()-10 { + private A first; + private B second; + + public Pair(A first, B second) { + super(); + this.first = first; + this.second = second; + } + + public int hashCode() { + int hashFirst = first != null ? first.hashCode() : 0; + int hashSecond = second != null ? second.hashCode() : 0; + + return (hashFirst + hashSecond) * hashSecond + hashFirst; + } + + @SuppressWarnings("unchecked") + public boolean equals(Object other) { + if (other instanceof Pair) { + Pair otherPair = (Pair)other; + return + (( this.first == otherPair.first || + ( this.first != null && otherPair.first != null && + this.first.equals(otherPair.first))) && + ( this.second == otherPair.second || + ( this.second != null && otherPair.second != null && + this.second.equals(otherPair.second))) ); + } + + return false; + } + + public String toString() + { + return "(" + first + ", " + second + ")"; + } + + public A getFirst() { + return first; + } + + public void setFirst(A first) { + this.first = first; + } + + public B getSecond() { + return second; + } + + public void setSecond(B second) { + this.second = second; + } +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionPropertiesView.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionPropertiesView.java new file mode 100644 index 0000000..3979847 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionPropertiesView.java @@ -0,0 +1,11 @@ +package com.itjw.txviewer.graph.views; + +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.PropertySheet; + +public class SelectionPropertiesView extends PropertySheet { + @Override + protected boolean isImportant(IWorkbenchPart part) { + return part.getSite().getId().equals("com.itjw.txviewer.graph.TxEditorPart"); + } +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionTableView.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionTableView.java new file mode 100644 index 0000000..759c44d --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/SelectionTableView.java @@ -0,0 +1,99 @@ +package com.itjw.txviewer.graph.views; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IMarkSelection; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.text.TextViewer; +import org.eclipse.jface.viewers.ArrayContentProvider; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.model.WorkbenchLabelProvider; +import org.eclipse.ui.part.PageBook; +import org.eclipse.ui.part.ViewPart; + +/** + * This view simply mirrors the current selection in the workbench window. + * It works for both, element and text selection. + */ +public class SelectionTableView extends ViewPart { + + private PageBook pagebook; + private TableViewer tableviewer; + private TextViewer textviewer; + + // the listener we register with the selection service + private ISelectionListener listener = new ISelectionListener() { + public void selectionChanged(IWorkbenchPart sourcepart, ISelection selection) { + // we ignore our own selections + if (sourcepart != SelectionTableView.this) { + showSelection(sourcepart, selection); + } + } + }; + + /** + * Shows the given selection in this view. + */ + public void showSelection(IWorkbenchPart sourcepart, ISelection selection) { + setContentDescription(sourcepart.getTitle() + " (" + selection.getClass().getName() + ")"); + if (selection instanceof IStructuredSelection) { + IStructuredSelection ss = (IStructuredSelection) selection; + showItems(ss.toArray()); + } + if (selection instanceof ITextSelection) { + ITextSelection ts = (ITextSelection) selection; + showText(ts.getText()); + } + if (selection instanceof IMarkSelection) { + IMarkSelection ms = (IMarkSelection) selection; + try { + showText(ms.getDocument().get(ms.getOffset(), ms.getLength())); + } catch (BadLocationException ble) { } + } + } + + private void showItems(Object[] items) { + tableviewer.setInput(items); + pagebook.showPage(tableviewer.getControl()); + } + + private void showText(String text) { + textviewer.setDocument(new Document(text)); + pagebook.showPage(textviewer.getControl()); + } + + public void createPartControl(Composite parent) { + // the PageBook allows simple switching between two viewers + pagebook = new PageBook(parent, SWT.NONE); + + tableviewer = new TableViewer(pagebook, SWT.NONE); + tableviewer.setLabelProvider(new WorkbenchLabelProvider()); + tableviewer.setContentProvider(new ArrayContentProvider()); + + // we're cooperative and also provide our selection + // at least for the tableviewer + getSite().setSelectionProvider(tableviewer); + + textviewer = new TextViewer(pagebook, SWT.H_SCROLL | SWT.V_SCROLL); + textviewer.setEditable(false); + + getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(listener); + } + + public void setFocus() { + pagebook.setFocus(); + } + + public void dispose() { + // important: We need do unregister our listener when the view is disposed + getSite().getWorkbenchWindow().getSelectionService().removeSelectionListener(listener); + super.dispose(); + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/TxDbView.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/TxDbView.java new file mode 100644 index 0000000..6ef6ed5 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/TxDbView.java @@ -0,0 +1,294 @@ +package com.itjw.txviewer.graph.views; + +import java.util.ArrayList; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.part.*; +import org.eclipse.jface.viewers.*; +import org.eclipse.swt.graphics.Image; +import org.eclipse.jface.action.*; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.ui.*; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.SWT; +import org.eclipse.core.runtime.IAdaptable; + + +/** + * This sample class demonstrates how to plug-in a new + * workbench view. The view shows data obtained from the + * model. The sample creates a dummy model on the fly, + * but a real implementation would connect to the model + * available either in this or another plug-in (e.g. the workspace). + * The view is connected to the model using a content provider. + *

+ * The view uses a label provider to define how model + * objects should be presented in the view. Each + * view can present the same model objects using + * different labels and icons, if needed. Alternatively, + * a single label provider can be shared between views + * in order to ensure that objects of the same type are + * presented in the same way everywhere. + *

+ */ + +public class TxDbView extends ViewPart { + + /** + * The ID of the view as specified by the extension. + */ + public static final String ID = "com.itjw.txviewer.graph.views.TxDbView"; + + private TreeViewer viewer; + private DrillDownAdapter drillDownAdapter; + private Action action1; + private Action action2; + private Action doubleClickAction; + + /* + * The content provider class is responsible for + * providing objects to the view. It can wrap + * existing objects in adapters or simply return + * objects as-is. These objects may be sensitive + * to the current input of the view, or ignore + * it and always show the same content + * (like Task List, for example). + */ + + class TreeObject implements IAdaptable { + private String name; + private TreeParent parent; + + public TreeObject(String name) { + this.name = name; + } + public String getName() { + return name; + } + public void setParent(TreeParent parent) { + this.parent = parent; + } + public TreeParent getParent() { + return parent; + } + public String toString() { + return getName(); + } + @SuppressWarnings("rawtypes") + public Object getAdapter(Class key) { + return null; + } + } + + class TreeParent extends TreeObject { + private ArrayList children; + public TreeParent(String name) { + super(name); + children = new ArrayList(); + } + public void addChild(TreeObject child) { + children.add(child); + child.setParent(this); + } + public void removeChild(TreeObject child) { + children.remove(child); + child.setParent(null); + } + public TreeObject [] getChildren() { + return children.toArray(new TreeObject[children.size()]); + } + public boolean hasChildren() { + return children.size()>0; + } + } + + class ViewContentProvider implements IStructuredContentProvider, + ITreeContentProvider { + private TreeParent invisibleRoot; + + public void inputChanged(Viewer v, Object oldInput, Object newInput) { + } + public void dispose() { + } + public Object[] getElements(Object parent) { + if (parent.equals(getViewSite())) { + if (invisibleRoot==null) initialize(); + return getChildren(invisibleRoot); + } + return getChildren(parent); + } + public Object getParent(Object child) { + if (child instanceof TreeObject) { + return ((TreeObject)child).getParent(); + } + return null; + } + public Object [] getChildren(Object parent) { + if (parent instanceof TreeParent) { + return ((TreeParent)parent).getChildren(); + } + return new Object[0]; + } + public boolean hasChildren(Object parent) { + if (parent instanceof TreeParent) + return ((TreeParent)parent).hasChildren(); + return false; + } +/* + * We will set up a dummy model to initialize tree heararchy. + * In a real code, you will connect to a real model and + * expose its hierarchy. + */ + private void initialize() { + TreeObject to1 = new TreeObject("Leaf 1"); + TreeObject to2 = new TreeObject("Leaf 2"); + TreeObject to3 = new TreeObject("Leaf 3"); + TreeParent p1 = new TreeParent("Parent 1"); + p1.addChild(to1); + p1.addChild(to2); + p1.addChild(to3); + + TreeObject to4 = new TreeObject("Leaf 4"); + TreeParent p2 = new TreeParent("Parent 2"); + p2.addChild(to4); + + TreeParent root = new TreeParent("Root"); + root.addChild(p1); + root.addChild(p2); + + invisibleRoot = new TreeParent(""); + invisibleRoot.addChild(root); + } + } + class ViewLabelProvider extends LabelProvider { + + public String getText(Object obj) { + return obj.toString(); + } + public Image getImage(Object obj) { + String imageKey = ISharedImages.IMG_OBJ_ELEMENT; + if (obj instanceof TreeParent) + imageKey = ISharedImages.IMG_OBJ_FOLDER; + return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey); + } + } + class NameSorter extends ViewerSorter { + } + + /** + * The constructor. + */ + public TxDbView() { + } + + /** + * This is a callback that will allow us + * to create the viewer and initialize it. + */ + public void createPartControl(Composite parent) { + viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL); + drillDownAdapter = new DrillDownAdapter(viewer); + viewer.setContentProvider(new ViewContentProvider()); + viewer.setLabelProvider(new ViewLabelProvider()); + viewer.setSorter(new NameSorter()); + viewer.setInput(getViewSite()); + + // Create the help context id for the viewer's control + PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "com.itjw.txviewer.graph.viewer"); + makeActions(); + hookContextMenu(); + hookDoubleClickAction(); + contributeToActionBars(); + } + + private void hookContextMenu() { + MenuManager menuMgr = new MenuManager("#PopupMenu"); + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager manager) { + TxDbView.this.fillContextMenu(manager); + } + }); + Menu menu = menuMgr.createContextMenu(viewer.getControl()); + viewer.getControl().setMenu(menu); + getSite().registerContextMenu(menuMgr, viewer); + } + + private void contributeToActionBars() { + IActionBars bars = getViewSite().getActionBars(); + fillLocalPullDown(bars.getMenuManager()); + fillLocalToolBar(bars.getToolBarManager()); + } + + private void fillLocalPullDown(IMenuManager manager) { + manager.add(action1); + manager.add(new Separator()); + manager.add(action2); + } + + private void fillContextMenu(IMenuManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + // Other plug-ins can contribute there actions here + manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); + } + + private void fillLocalToolBar(IToolBarManager manager) { + manager.add(action1); + manager.add(action2); + manager.add(new Separator()); + drillDownAdapter.addNavigationActions(manager); + } + + private void makeActions() { + action1 = new Action() { + public void run() { + showMessage("Action 1 executed"); + } + }; + action1.setText("Action 1"); + action1.setToolTipText("Action 1 tooltip"); + action1.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + + action2 = new Action() { + public void run() { + showMessage("Action 2 executed"); + } + }; + action2.setText("Action 2"); + action2.setToolTipText("Action 2 tooltip"); + action2.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages(). + getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK)); + doubleClickAction = new Action() { + public void run() { + ISelection selection = viewer.getSelection(); + Object obj = ((IStructuredSelection)selection).getFirstElement(); + showMessage("Double-click detected on "+obj.toString()); + } + }; + } + + private void hookDoubleClickAction() { + viewer.addDoubleClickListener(new IDoubleClickListener() { + public void doubleClick(DoubleClickEvent event) { + doubleClickAction.run(); + } + }); + } + private void showMessage(String message) { + MessageDialog.openInformation( + viewer.getControl().getShell(), + "Transaction Database View", + message); + } + + /** + * Passing the focus request to the viewer's control. + */ + public void setFocus() { + viewer.getControl().setFocus(); + } +} \ No newline at end of file diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.java new file mode 100644 index 0000000..a6ca6c6 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeContentProvider.java @@ -0,0 +1,45 @@ +package com.itjw.txviewer.graph.views.provider; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrHierNode; + +public class TxDbTreeContentProvider implements ITreeContentProvider { + + private ITrDb database; + + @Override + public void dispose() { } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + database=(ITrDb)newInput; + } + + @Override + public Object[] getElements(Object inputElement) { + return database.getChildNodes().toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + if(parentElement instanceof ITrHierNode){ + return ((ITrHierNode)parentElement).getChildNodes().toArray(); + } + return null; + } + + @Override + public Object getParent(Object element) { + return null; + } + + @Override + public boolean hasChildren(Object element) { + Object[] obj = getChildren(element); + return obj == null ? false : obj.length > 0; + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.java new file mode 100644 index 0000000..23e6783 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/provider/TxDbTreeLabelProvider.java @@ -0,0 +1,72 @@ +package com.itjw.txviewer.graph.views.provider; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.jface.viewers.ILabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.graphics.Image; + +import com.itjw.txviewer.database.ITrDb; +import com.itjw.txviewer.database.ITrHierNode; +import com.itjw.txviewer.database.ITrStream; +import com.itjw.txviewer.graph.TxEditorPlugin; + +public class TxDbTreeLabelProvider implements ILabelProvider { + + private List listeners = new ArrayList(); + + private Image database; + private Image stream; + private Image folder; + + + public TxDbTreeLabelProvider() { + super(); + database=TxEditorPlugin.createImage("database"); + stream=TxEditorPlugin.createImage("stream"); + folder=TxEditorPlugin.createImage("folder"); + } + + @Override + public void addListener(ILabelProviderListener listener) { + listeners.add(listener); + } + + @Override + public void dispose() { + if(database!=null) database.dispose(); + if(stream!=null) stream.dispose(); + if(folder!=null) folder.dispose(); + } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener listener) { + listeners.remove(listener); + } + + @Override + public Image getImage(Object element) { + if(element instanceof ITrDb){ + return database; + }else if(element instanceof ITrStream){ + return stream; + }else if(element instanceof ITrHierNode){ + return folder; + } else + return null; + } + + @Override + public String getText(Object element) { + return ((ITrHierNode)element).getName(); + } + +} + + diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/AttributeProperty.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/AttributeProperty.java new file mode 100644 index 0000000..a09c282 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/AttributeProperty.java @@ -0,0 +1,252 @@ +package com.itjw.txviewer.graph.views.sections; + +import java.util.HashMap; +import java.util.List; +import java.util.TreeMap; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +import com.itjw.txviewer.database.ITrAttribute; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class AttributeProperty extends AbstractPropertySection implements ISelectionProvider { + + private final String[] titles = { "Location", "Name", "Type", "Value" }; + + private ListenerList listeners = new ListenerList(); + + private ITransactionFacade iTr; + + private ISelection currentSelection; + + private TreeViewer treeViewer; + + public AttributeProperty() { + } + + public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) { + super.createControls(parent, aTabbedPropertySheetPage); + Composite composite = getWidgetFactory().createFlatFormComposite(parent); + Tree tree = new Tree(composite, SWT.BORDER | SWT.FULL_SELECTION); + tree.setHeaderVisible(true); + treeViewer = new TreeViewer(tree); + + TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); + tree.setLinesVisible(true); + column1.setAlignment(SWT.LEFT); + column1.setText(titles[0]); + column1.setWidth(75); + TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT); + column2.setAlignment(SWT.LEFT); + column2.setText(titles[1]); + column2.setWidth(150); + TreeColumn column3 = new TreeColumn(tree, SWT.LEFT); + tree.setLinesVisible(true); + column3.setAlignment(SWT.LEFT); + column3.setText(titles[2]); + column3.setWidth(100); + TreeColumn column4 = new TreeColumn(tree, SWT.RIGHT); + column4.setAlignment(SWT.LEFT); + column4.setText(titles[3]); + column4.setWidth(150); + + Object layoutData = parent.getLayoutData(); + if (layoutData instanceof GridData) { + GridData gridData = (GridData) layoutData; + gridData.grabExcessVerticalSpace = true; + gridData.verticalAlignment = SWT.FILL; + } + + FormData formData = new FormData(); + formData.left = new FormAttachment(0); + formData.top = new FormAttachment(0); + formData.right = new FormAttachment(100); + formData.bottom = new FormAttachment(100); + tree.setLayoutData(formData); + + treeViewer.setAutoExpandLevel(2); + treeViewer.setContentProvider(new ITreeContentProvider() { + TreeMap> hier = new TreeMap>(); + HashMap parents = new HashMap(); + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof String) { + hier.clear(); + parents.clear(); + String location="Begin"; + List txSet = iTr.getBeginAttrs(); + if (txSet != null && txSet.size() > 0) { + hier.put(location, txSet); + for (ITrAttribute tr : txSet) + if (tr != null) + parents.put(tr, location); + } + location="Recorded"; + txSet = iTr.getAttributes(); + if (txSet != null && txSet.size() > 0) { + hier.put(location, txSet); + for (ITrAttribute tr : txSet) + if (tr != null) + parents.put(tr, location); + } + location="End"; + txSet = iTr.getEndAttrs(); + if (txSet != null && txSet.size() > 0) { + hier.put(location, txSet); + for (ITrAttribute tr : txSet) + if (tr != null) + parents.put(tr, location); + } + } + } + + @Override + public void dispose() { } + + @Override + public boolean hasChildren(Object element) { + Object[] childs = getChildren(element); + return childs != null && childs.length > 0; + } + + @Override + public Object getParent(Object element) { + if (element instanceof ITrAttribute) + return parents.get(element); + else + return null; + } + + @Override + public Object[] getElements(Object inputElement) { + return hier.keySet().toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof String) + return hier.get((String) parentElement).toArray(); + else + return null; + } + }); + treeViewer.setLabelProvider(new ITableLabelProvider() { + @Override + public void removeListener(ILabelProviderListener listener) { } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void dispose() { } + + @Override + public void addListener(ILabelProviderListener listener) { } + + @Override + public String getColumnText(Object element, int columnIndex) { + if (columnIndex == 0 && element instanceof String) + return element.toString(); + else if(element instanceof ITrAttribute){ + ITrAttribute attr = (ITrAttribute)element; + if (columnIndex == 1 ) + return attr.getName(); + else if (columnIndex == 2 ) + return attr.getType(); + else if (columnIndex == 3){ + if("UNSIGNED".equals(attr.getType()) && + (attr.getName().contains("addr")||attr.getName().contains("data"))) + return "0x"+Long.toHexString(Long.parseLong(attr.getValue().toString())); + else + return attr.getValue().toString(); + } + } + return null; + } + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + }); + + MenuManager menuMgr = new MenuManager("#PopUp"); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + ISelection selection = treeViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + System.out.println(((IStructuredSelection)selection).getFirstElement().toString()); + } + } + }); + Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); + treeViewer.getControl().setMenu(menu); + aTabbedPropertySheetPage.getSite().setSelectionProvider(this); + } + + public void setInput(IWorkbenchPart part, ISelection selection) { + super.setInput(part, selection); + currentSelection = null; + Assert.isTrue(selection instanceof IStructuredSelection); + Object input = ((IStructuredSelection) selection).getFirstElement(); + Assert.isTrue(input instanceof ITransactionFacade); + iTr = (ITransactionFacade) input; + } + + public void refresh() { + treeViewer.setInput("All"); + } + + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + listeners.add(listener); + } + + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + listeners.remove(listener); + } + + public ISelection getSelection() { + return currentSelection != null ? currentSelection : super.getSelection(); + } + + @Override + public void setSelection(ISelection selection) { + currentSelection = selection; + Object[] list = listeners.getListeners(); + for (int i = 0; i < list.length; i++) { + ((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection)); + } + } + +} diff --git a/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/RelatedProperty.java b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/RelatedProperty.java new file mode 100644 index 0000000..585bda7 --- /dev/null +++ b/com.itjw.txviewer.graph/src/com/itjw/txviewer/graph/views/sections/RelatedProperty.java @@ -0,0 +1,250 @@ +package com.itjw.txviewer.graph.views.sections; + +import java.util.HashMap; +import java.util.Set; +import java.util.TreeMap; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.ListenerList; +import org.eclipse.jface.action.IMenuListener; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.action.MenuManager; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITableLabelProvider; +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TreeViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.layout.FormAttachment; +import org.eclipse.swt.layout.FormData; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Menu; +import org.eclipse.swt.widgets.Tree; +import org.eclipse.swt.widgets.TreeColumn; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection; +import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; + +import com.itjw.txviewer.database.ITransaction; +import com.itjw.txviewer.database.RelationType; +import com.itjw.txviewer.graph.TransactionSelection; +import com.itjw.txviewer.graph.actions.TxActionFactory; +import com.itjw.txviewer.graph.data.ITransactionFacade; + +public class RelatedProperty extends AbstractPropertySection implements ISelectionProvider, ISelectionChangedListener { + + private final String[] titles = { "Relation", "Tx Id" }; + + private ListenerList listeners = new ListenerList(); + + private ITransactionFacade iTr; + + private ISelection currentSelection; + + private TreeViewer treeViewer; + + public RelatedProperty() { + } + + public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) { + super.createControls(parent, aTabbedPropertySheetPage); + Composite composite = getWidgetFactory().createFlatFormComposite(parent); + Tree tree = new Tree(composite, SWT.BORDER | SWT.FULL_SELECTION); + tree.setHeaderVisible(true); + treeViewer = new TreeViewer(tree); + + TreeColumn column1 = new TreeColumn(tree, SWT.LEFT); + tree.setLinesVisible(true); + column1.setAlignment(SWT.LEFT); + column1.setText(titles[0]); + column1.setWidth(150); + TreeColumn column2 = new TreeColumn(tree, SWT.RIGHT); + column2.setAlignment(SWT.LEFT); + column2.setText(titles[1]); + column2.setWidth(150); + + Object layoutData = parent.getLayoutData(); + if (layoutData instanceof GridData) { + GridData gridData = (GridData) layoutData; + gridData.grabExcessVerticalSpace = true; + gridData.verticalAlignment = SWT.FILL; + } + + FormData formData = new FormData(); + formData.left = new FormAttachment(0); + formData.top = new FormAttachment(0); + formData.right = new FormAttachment(100); + formData.bottom = new FormAttachment(100); + tree.setLayoutData(formData); + + treeViewer.setAutoExpandLevel(2); + treeViewer.setContentProvider(new ITreeContentProvider() { + TreeMap> hier = new TreeMap>(); + HashMap parents = new HashMap(); + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + if (newInput instanceof RelationType[]) { + hier.clear(); + parents.clear(); + for (RelationType rel : (RelationType[]) newInput) { + Set txSet = iTr.getNextInRelationship(rel); + if (txSet != null && txSet.size() > 0) { + boolean hasChilds=false; + for (ITransaction tr : txSet) + if (tr != null){ + parents.put(tr, rel); + hasChilds=true; + } + if(hasChilds) hier.put(rel, txSet); + } + } + } + } + + @Override + public void dispose() { } + + @Override + public boolean hasChildren(Object element) { + Object[] childs = getChildren(element); + return childs != null && childs.length > 0; + } + + @Override + public Object getParent(Object element) { + if (element instanceof ITransaction) + return parents.get(element); + else + return null; + } + + @Override + public Object[] getElements(Object inputElement) { + return hier.keySet().toArray(); + } + + @Override + public Object[] getChildren(Object parentElement) { + if (parentElement instanceof RelationType) + return hier.get((RelationType) parentElement).toArray(); + else + return null; + } + }); + treeViewer.setLabelProvider(new ITableLabelProvider() { + @Override + public void removeListener(ILabelProviderListener listener) { } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void dispose() { } + + @Override + public void addListener(ILabelProviderListener listener) { } + + @Override + public String getColumnText(Object element, int columnIndex) { + if (columnIndex == 0 && element instanceof RelationType) + return element.toString(); + else if (columnIndex == 1 && element instanceof ITransaction) + return ((ITransaction) element).getId().toString(); + else + return null; + } + + @Override + public Image getColumnImage(Object element, int columnIndex) { + return null; + } + }); + treeViewer.addSelectionChangedListener(this); + MenuManager menuMgr = new MenuManager("#PopUp"); //$NON-NLS-1$ + menuMgr.setRemoveAllWhenShown(true); + menuMgr.addMenuListener(new IMenuListener() { + public void menuAboutToShow(IMenuManager mgr) { + fillContextMenu(mgr); + } + }); + Menu menu = menuMgr.createContextMenu(treeViewer.getControl()); + treeViewer.getControl().setMenu(menu); + aTabbedPropertySheetPage.getSite().setSelectionProvider(this); + getPart().getSite().setSelectionProvider(this); + + } + + private void fillContextMenu(IMenuManager menuMgr) { + // initalize the context menu + ISelection selection = treeViewer.getSelection(); + if (selection instanceof IStructuredSelection) { + Object obj = ((IStructuredSelection) selection).getFirstElement(); + menuMgr.add(TxActionFactory.getAction(TxActionFactory.JUMP_TO_TX, obj instanceof ITransaction)); + } + } + + public void setInput(IWorkbenchPart part, ISelection selection) { + super.setInput(part, selection); + currentSelection = null; + Assert.isTrue(selection instanceof IStructuredSelection); + Object input = ((IStructuredSelection) selection).getFirstElement(); + Assert.isTrue(input instanceof ITransactionFacade); + iTr = (ITransactionFacade) input; + } + + public void refresh() { + treeViewer.setInput(RelationType.values()); + } + + public void aboutToBeShown() { + treeViewer.expandAll(); + } + + @Override + public void addSelectionChangedListener(ISelectionChangedListener listener) { + listeners.add(listener); + } + + @Override + public void removeSelectionChangedListener(ISelectionChangedListener listener) { + listeners.remove(listener); + } + + public ISelection getSelection() { + return currentSelection != null ? currentSelection : super.getSelection(); + } + + @Override + public void setSelection(ISelection selection) { + currentSelection = selection; + Object[] list = listeners.getListeners(); + for (int i = 0; i < list.length; i++) { + ((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection)); + } + } + + @Override + public void selectionChanged(SelectionChangedEvent event) { + ISelection selection = event.getSelection(); + if(selection instanceof IStructuredSelection){ + IStructuredSelection treeSelection =(IStructuredSelection)selection; + Object elem = treeSelection.getFirstElement(); + if(elem instanceof ITransactionFacade){ + currentSelection = new TransactionSelection((ITransactionFacade)elem); + } else if(elem instanceof ITransaction){ + currentSelection = new TransactionSelection(new ITransactionFacade((ITransaction)elem)); + } + } + } + +}