[WIP ]reorganized dir structure

This commit is contained in:
2020-06-01 17:26:56 +02:00
parent 3e5ab7b0ac
commit 97693cd0c4
374 changed files with 43 additions and 390 deletions

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -0,0 +1,2 @@
/bin
/target/

View File

@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>com.minres.scviewer.ui</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ManifestBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.SchemaBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.pde.ds.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature>
<nature>org.eclipse.jdt.groovy.core.groovyNature</nature>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>

View File

@@ -0,0 +1,12 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8

View File

@@ -0,0 +1,3 @@
eclipse.preferences.version=1
groovy.compiler.level=26
groovy.script.filters=**/*.dsld,y,**/*.gradle,n

View File

@@ -0,0 +1,4 @@
activeProfiles=
eclipse.preferences.version=1
resolveWorkspaceProjects=true
version=1

View File

@@ -0,0 +1,26 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: SCViewer
Bundle-SymbolicName: com.minres.scviewer.ui;singleton:=true
Bundle-Version: 1.0.1.qualifier
Bundle-Activator: com.minres.scviewer.ui.TxEditorPlugin
Bundle-Vendor: MINRES Technologies GmbH
Require-Bundle: com.minres.scviewer.database;bundle-version="1.0.0",
com.minres.scviewer.database.ui;bundle-version="1.0.0",
com.minres.scviewer.database.ui.swt;bundle-version="1.0.0",
org.eclipse.core.runtime,
org.eclipse.core.resources,
org.eclipse.jface.text,
org.eclipse.ui,
org.eclipse.ui.editors,
org.eclipse.ui.ide,
org.eclipse.ui.views.properties.tabbed,
org.eclipse.swt,
org.eclipse.osgi,
org.eclipse.core.expressions;bundle-version="3.4.600",
org.eclipse.jface
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Bundle-ActivationPolicy: lazy
Import-Package: com.google.common.collect
Service-Component: OSGI-INF/component.xml
Automatic-Module-Name: com.minres.scviewer.ui

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="com.minres.scviewer.ui">
<implementation class="com.minres.scviewer.ui.TxEditorPart"/>
<reference bind="bind" cardinality="1..1" interface="com.minres.scviewer.database.IWaveformDbFactory" name="IWaveformDbFactory" policy="static" unbind="unbind"/>
</scr:component>

View File

@@ -0,0 +1,56 @@
Silk companion icon set #1 - "More Silk!"
Last updated: 19 November 2007
_________________________________________
Damien Guard
http://www.damieng.com/icons/silkcompanion
_________________________________________
This work is licensed under a
Creative Commons Attribution 2.5 License.
[ http://creativecommons.org/licenses/by/2.5/ ]
The FamFamFam Silk icon set is a very large,
consistent set of well-drawn icons that has
proven to be popular with both applications
and web sites.
On a number of occasions I have found myself
wanting more icons in the same style. This
companion set represents what I needed but also
what I felt like adding.
Some are new icons in the same style, some are
alternative sizes/colours of the existing icons
and some are new compositions of the elements.
Any questions about this companion set please
contact damieng@gmail.com.
The Original Silk readme this work is based upon:
Silk icon set 1.3
_________________________________________
Mark James
http://www.famfamfam.com/lab/icons/silk/
_________________________________________
This work is licensed under a
Creative Commons Attribution 2.5 License.
[ http://creativecommons.org/licenses/by/2.5/ ]
This means you may use it for any purpose,
and make any changes you like.
All I ask is that you include a link back
to this page in your credits.
Are you using this icon set? Send me an email
(including a link or picture if available) to
mjames@gmail.com
Any other questions about this icon set please
contact mjames@gmail.com

View File

@@ -0,0 +1,8 @@
bin.includes = plugin.xml,\
META-INF/,\
.,\
contexts.xml,\
res/,\
OSGI-INF/
jars.compile.order = .
source.. = src/

View File

@@ -0,0 +1,12 @@
<contexts>
<context id="viewer" title="Sample View">
<description>This is the context help for the sample view with a tree viewer. It was generated by a PDE template.</description>
<topic href="/PLUGINS_ROOT/org.eclipse.platform.doc.isv/guide/ua_help_context.htm" label="Context-sensitive help">
<enablement>
<with variable="platform">
<test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.platform.doc.isv"/>
</with>
</enablement>
</topic>
</context>
</contexts>

View File

@@ -0,0 +1,22 @@
Silk icon set 1.3
_________________________________________
Mark James
http://www.famfamfam.com/lab/icons/silk/
_________________________________________
This work is licensed under a
Creative Commons Attribution 2.5 License.
[ http://creativecommons.org/licenses/by/2.5/ ]
This means you may use it for any purpose,
and make any changes you like.
All I ask is that you include a link back
to this page in your credits.
Are you using this icon set? Send me an email
(including a link or picture if available) to
mjames@gmail.com
Any other questions about this icon set please
contact mjames@gmail.com

View File

@@ -0,0 +1,513 @@
<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
<extension
point="org.eclipse.ui.views">
<category
name="TxViewer"
id="com.minres.scviewer.ui">
</category>
</extension>
<extension
point="org.eclipse.help.contexts">
<contexts
file="contexts.xml">
</contexts>
</extension>
<extension
point="org.eclipse.ui.editors">
<editor
class="com.minres.scviewer.ui.TxEditorPart"
contributorClass="com.minres.scviewer.ui.TxEditorActionBarContributor"
extensions="txdb"
filenames="*.txdb,*.txlog,*.vcd"
icon="res/images/scviewer.png"
id="com.minres.scviewer.ui.TxEditorPart"
name="Wave Viewer">
</editor>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyContributor">
<propertyContributor
contributorId="com.minres.scviewer.ui.TxEditorPart">
<propertyCategory
category="Transaction"></propertyCategory>
</propertyContributor>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertyTabs">
<propertyTabs
contributorId="com.minres.scviewer.ui.TxEditorPart">
<propertyTab
category="Transaction"
id="com.minres.scviewer.ui.propertyTabTransaction"
label="Transaction">
</propertyTab>
<propertyTab
afterTab="com.minres.scviewer.ui.propertyTabTransaction"
category="Transaction"
id="com.minres.scviewer.ui.propertyTabAttributes"
label="Attributes">
</propertyTab>
<propertyTab
afterTab="com.minres.scviewer.ui.propertyTabAttributes"
category="Transaction"
id="com.minres.scviewer.ui.propertyTabRelated"
label="Related Tx">
</propertyTab>
</propertyTabs>
</extension>
<extension
point="org.eclipse.ui.views.properties.tabbed.propertySections">
<propertySections
contributorId="com.minres.scviewer.ui.TxEditorPart">
<propertySection
class="org.eclipse.ui.views.properties.tabbed.AdvancedPropertySection"
id="com.minres.scviewer.ui.propertySectionAll"
tab="com.minres.scviewer.ui.propertyTabTransaction">
<input
type="com.minres.scviewer.database.ITx">
</input>
</propertySection>
<propertySection
afterSection="com.minres.scviewer.ui.propertySectionAll"
class="com.minres.scviewer.ui.views.sections.AttributeProperty"
id="com.minres.scviewer.ui.propertySectionAttributes"
tab="com.minres.scviewer.ui.propertyTabAttributes">
<input
type="com.minres.scviewer.database.ITx">
</input>
</propertySection>
<propertySection
afterSection="com.minres.scviewer.ui.propertySectionAttributes"
class="com.minres.scviewer.ui.views.sections.RelatedProperty"
id="com.minres.scviewer.ui.propertySectionRelated"
tab="com.minres.scviewer.ui.propertyTabRelated">
<input
type="com.minres.scviewer.database.ITx">
</input>
</propertySection>
</propertySections>
</extension>
<extension
point="org.eclipse.core.runtime.adapters">
<factory
adaptableType="com.minres.scviewer.database.ITx"
class="com.minres.scviewer.ui.adapter.TxAdapterFactory">
<adapter
type="org.eclipse.ui.views.properties.IPropertySource">
</adapter>
</factory>
</extension>
<extension
point="org.eclipse.ui.elementFactories">
<factory
class="com.minres.scviewer.ui.TxEditorInputFactory"
id="com.minres.scviewer.ui.TxEditorInputFactory">
</factory>
</extension>
<extension
point="org.eclipse.ui.menus">
<menuContribution
allPopups="false"
locationURI="toolbar:org.eclipse.ui.main.toolbar">
<toolbar
id="com.minres.scviewer.ui.toolbar1">
<command
commandId="com.minres.scviewer.ui.gotoPrev"
label="Prev"
style="push"
tooltip="Go to previous event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoNext"
label="Next"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
id="com.minres.scviewer.ui.zoom.command"
style="pulldown"
tooltip="Set zoom level">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomin"
label="Zoom in"
style="push"
tooltip="Zoom into">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomout"
label="Zoom out"
style="push"
tooltip="Zoom out of">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
</toolbar>
</menuContribution>
<menuContribution
locationURI="menu:com.minres.scviewer.ui.zoom.command">
<command
commandId="com.minres.scviewer.ui.zoom"
label="100ps"
style="push"
tooltip="Resolution 100ps">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="5">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="1ns"
style="push"
tooltip="Resolution 1ns">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="6">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="10ns"
style="push"
tooltip="Resolution 10ns">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="7">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="100ns"
style="push"
tooltip="Resolution 100ns">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="8">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="1µs"
style="push"
tooltip="Resolution 1us">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="9">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="10µs"
style="push"
tooltip="Resolution 10us">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="10">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="100µs"
style="push"
tooltip="Resolution 100us">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="11">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="1ms"
style="push"
tooltip="Resolution 1ms">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="12">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="10ms"
style="push"
tooltip="Resolution 10ms">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="13">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="100ms"
style="push"
tooltip="Resolution 100ms">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="14">
</parameter>
</command>
<command
commandId="com.minres.scviewer.ui.zoom"
label="1s"
style="push"
tooltip="Resolution 1s">
<parameter
name="com.minres.scviewer.ui.zoom.level"
value="15">
</parameter>
</command>
</menuContribution>
<menuContribution
allPopups="false"
locationURI="popup:com.minres.scviewer.ui.TxEditorPart">
<command
commandId="com.minres.scviewer.ui.removeWave"
label="Remove"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomin"
label="Zoom in"
style="push"
tooltip="Zoom into">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.zoomout"
label="Zoom out"
style="push"
tooltip="Zoom out of">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoPrev"
label="Prev"
style="push"
tooltip="Go to previous event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
<command
commandId="com.minres.scviewer.ui.gotoNext"
label="Next"
style="push"
tooltip="Go to next event">
<visibleWhen
checkEnabled="false">
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</visibleWhen>
</command>
</menuContribution>
</extension>
<extension
point="org.eclipse.ui.commands">
<command
description="Go to next event"
id="com.minres.scviewer.ui.gotoNext"
name="Next">
</command>
<command
description="Go to previous event"
id="com.minres.scviewer.ui.gotoPrev"
name="Prev">
</command>
<command
defaultHandler="com.minres.scviewer.ui.handler.Zoom"
description="Set the zoom level"
id="com.minres.scviewer.ui.zoom"
name="Zoom">
<commandParameter
id="com.minres.scviewer.ui.zoom.level"
name="level"
optional="true">
</commandParameter>
</command>
<command
id="com.minres.scviewer.ui.zoomin"
name="Zoom in">
</command>
<command
id="com.minres.scviewer.ui.zoomout"
name="Zoom out">
</command>
<command
id="com.minres.scviewer.ui.removeWave"
name="Remove wave">
</command>
</extension>
<extension
point="org.eclipse.ui.handlers">
<handler
class="com.minres.scviewer.ui.handler.GotoPrev"
commandId="com.minres.scviewer.ui.gotoPrev">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference>
</enabledWhen>
</handler>
<handler
class="com.minres.scviewer.ui.handler.GotoNext"
commandId="com.minres.scviewer.ui.gotoNext">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.oneTxSeleted">
</reference>
</enabledWhen>
</handler>
<handler
class="com.minres.scviewer.ui.handler.ZoomInOut"
commandId="com.minres.scviewer.ui.zoomin">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</enabledWhen>
</handler>
<handler
class="com.minres.scviewer.ui.handler.ZoomInOut"
commandId="com.minres.scviewer.ui.zoomout">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.waveEditorActive">
</reference>
</enabledWhen>
</handler>
<handler
class="com.minres.scviewer.ui.handler.RemoveHandler"
commandId="com.minres.scviewer.ui.removeWave">
<enabledWhen>
<reference
definitionId="com.minres.scviewer.ui.oneWaveSeleted">
</reference>
</enabledWhen>
</handler>
</extension>
<extension
point="org.eclipse.core.expressions.definitions">
<definition
id="com.minres.scviewer.ui.oneWaveSeleted">
<with
variable="selection">
<and>
<count
value="1">
</count>
<iterate
operator="or">
<instanceof value="com.minres.scviewer.database.IWaveform"/>
</iterate>
</and>
</with>
</definition>
<definition
id="com.minres.scviewer.ui.oneTxSeleted">
<with
variable="selection">
<and>
<count
value="1">
</count>
<iterate
operator="or">
<instanceof value="com.minres.scviewer.database.ITx"/>
</iterate>
</and>
</with>
</definition>
<definition
id="com.minres.scviewer.ui.waveEditorActive">
<with
variable="activeEditorId">
<equals
value="com.minres.scviewer.ui.TxEditorPart">
</equals>
</with>
</definition>
</extension>
<extension
point="org.eclipse.ui.commandImages">
<image
commandId="com.minres.scviewer.ui.gotoPrev"
disabledIcon="res/images/previous-green-d.png"
icon="res/images/previous-green.png">
</image>
<image
commandId="com.minres.scviewer.ui.gotoNext"
disabledIcon="res/images/next-green-d.png"
icon="res/images/next-green.png">
</image>
<image
commandId="com.minres.scviewer.ui.zoom"
icon="res/images/zoom.png">
</image>
<image
commandId="com.minres.scviewer.ui.zoomin"
icon="res/images/zoom_in.png">
</image>
<image
commandId="com.minres.scviewer.ui.zoomout"
icon="res/images/zoom_out.png">
</image>
<image
commandId="com.minres.scviewer.ui.removeWave"
icon="res/images/cross.png">
</image>
</extension>
</plugin>

View File

@@ -0,0 +1,12 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<artifactId>com.minres.scviewer.ui</artifactId>
<parent>
<groupId>com.minres.scviewer</groupId>
<artifactId>com.minres.scviewer.parent</artifactId>
<version>2.0.0-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>
<packaging>eclipse-plugin</packaging>
<version>1.0.1-SNAPSHOT</version>
</project>

Binary file not shown.

After

Width:  |  Height:  |  Size: 655 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 390 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 537 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 337 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 519 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 345 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 524 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 255 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 717 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 444 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 692 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 725 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 708 B

View File

@@ -0,0 +1,36 @@
package com.minres.scviewer.ui;
public final class Hex {
public static byte[] decode(final String hex) {
if (hex.length() % 2 != 0) {
throw new IllegalArgumentException("A hex string must contain an even number of characters: " + hex);
}
byte[] out = new byte[hex.length() / 2];
for (int i = 0; i < hex.length(); i += 2) {
int high = Character.digit(hex.charAt(i), 16);
int low = Character.digit(hex.charAt(i + 1), 16);
if (high == -1 || low == -1) {
throw new IllegalArgumentException("A hex string can only contain the characters 0-9, A-F, a-f: " + hex);
}
out[i / 2] = (byte) (high * 16 + low);
}
return out;
}
private static final char[] UPPER_HEX_DIGITS = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', };
public static String encode(final byte[] bytes) {
StringBuilder stringBuilder = new StringBuilder(bytes.length * 2);
for (byte cur : bytes) {
stringBuilder.append(UPPER_HEX_DIGITS[(cur >> 4) & 0xF]);
stringBuilder.append(UPPER_HEX_DIGITS[(cur & 0xF)]);
}
return stringBuilder.toString();
}
private Hex() {
}
}

View File

@@ -0,0 +1,21 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import org.eclipse.ui.part.EditorActionBarContributor;
public class TxEditorActionBarContributor extends EditorActionBarContributor {
public TxEditorActionBarContributor() {
// TODO Auto-generated constructor stub
}
}

View File

@@ -0,0 +1,51 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.part.FileEditorInput;
public class TxEditorInput extends FileEditorInput {
private ArrayList<String> streamNames;
private Boolean secondaryLoaded=null;
public TxEditorInput(IFile file) {
super(file);
streamNames=new ArrayList<String>();
}
public String getFactoryId(){
return TxEditorInputFactory.getFactoryId();
}
public void saveState(IMemento memento) {
TxEditorInputFactory.saveState(memento, this);
}
public List<String> getStreamNames() {
return streamNames;
}
public Boolean isSecondaryLoaded() {
return secondaryLoaded;
}
public void setSecondaryLoaded(Boolean secondaryLoaded) {
this.secondaryLoaded = secondaryLoaded;
}
}

View File

@@ -0,0 +1,115 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IElementFactory;
import org.eclipse.ui.IMemento;
public class TxEditorInputFactory implements IElementFactory {
/**
* Factory id. The workbench plug-in registers a factory by this name
* with the "org.eclipse.ui.elementFactories" extension point.
*/
private static final String ID_FACTORY = "com.minres.scviewer.ui.TxEditorInputFactory"; //$NON-NLS-1$
/**
* Tag for the IFile.fullPath of the file resource.
*/
private static final String TAG_PATH = "path"; //$NON-NLS-1$
/**
* Tag for the secondaryLoade of the resource.
*/
private static final String TAG_SECONDARY = "secondary"; //$NON-NLS-1$
/**
* Tag for the streamList of the resource.
*/
private static final String TAG_STREAMLIST = "stream_list"; //$NON-NLS-1$
/**
* Creates a new factory.
*/
public TxEditorInputFactory() {
}
/* (non-Javadoc)
* Method declared on IElementFactory.
*/
@SuppressWarnings("unchecked")
public IAdaptable createElement(IMemento memento) {
// Get the file name.
String fileName = memento.getString(TAG_PATH);
if (fileName == null) {
return null;
}
// Get a handle to the IFile...which can be a handle
// to a resource that does not exist in workspace
IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fileName));
if (file != null) {
TxEditorInput tei = new TxEditorInput(file);
Boolean isSecondaryLoaded = memento.getBoolean(TAG_SECONDARY);
if(isSecondaryLoaded!=null)
tei.setSecondaryLoaded(isSecondaryLoaded);
String listData = memento.getString(TAG_STREAMLIST);
if (listData != null) {
try {
ByteArrayInputStream bais = new ByteArrayInputStream(Hex.decode(listData));
ObjectInputStream ois = new ObjectInputStream(bais);
Object obj = ois.readObject();
if(obj instanceof List<?>)
tei.getStreamNames().addAll((List<String>)obj);
} catch (Exception e) {
}
}
return tei;
}
return null;
}
/**
* Returns the element factory id for this class.
*
* @return the element factory id
*/
public static String getFactoryId() {
return ID_FACTORY;
}
/**
* Saves the state of the given file editor input into the given memento.
*
* @param memento the storage area for element state
* @param input the file editor input
*/
public static void saveState(IMemento memento, TxEditorInput input) {
IFile file = input.getFile();
memento.putString(TAG_PATH, file.getFullPath().toString());
if(input.isSecondaryLoaded()!=null) memento.putBoolean(TAG_SECONDARY, input.isSecondaryLoaded());
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(input.getStreamNames());
memento.putString(TAG_STREAMLIST, Hex.encode(baos.toByteArray()));
} catch (IOException e) {
}
}
}

View File

@@ -0,0 +1,410 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IStatusLineManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.StatusLineContributionItem;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.eclipse.ui.part.EditorPart;
import org.eclipse.ui.progress.IProgressService;
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.minres.scviewer.database.IWaveform;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IWaveformDbFactory;
import com.minres.scviewer.database.swt.WaveformViewerFactory;
import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.database.ui.IWaveformViewer;
import com.minres.scviewer.database.ui.TrackEntry;
import com.minres.scviewer.ui.views.TxOutlinePage;
public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPageContributor {
private IWaveformDbFactory waveformDbFactory;
public synchronized void bind(IWaveformDbFactory factory){
waveformDbFactory=factory;
}
public synchronized void unbind(IWaveformDbFactory factory){
if(waveformDbFactory==factory)
waveformDbFactory=null;
}
private final static String[] zoomLevel={
"1fs", "10fs", "100fs",
"1ps", "10ps", "100ps",
"1ns", "10ns", "100ns",
"1µs", "10µs", "10µs",
"1ms", "10ms", "100ms", "1s"};
public static final String ID = "com.minres.scviewer.ui.TxEditorPart"; //$NON-NLS-1$
public static final String WAVE_ACTION_ID = "com.minres.scviewer.ui.action.AddToWave";
private IWaveformViewer txDisplay;
/** This is the root of the editor's model. */
private IWaveformDb database;
private Composite myParent;
private StatusLineContributionItem cursorStatusLineItem;
private StatusLineContributionItem zoomStatusLineItem;
public TxEditorPart() {
}
/**
* Create contents of the editor part.
* @param parent
*/
@Override
public void createPartControl(Composite parent) {
myParent=parent;
database=waveformDbFactory.getDatabase();
database.addPropertyChangeListener(new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if("WAVEFORMS".equals(evt.getPropertyName())) {
myParent.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
txDisplay.setMaxTime(database.getMaxTime());
}
});
}
}
});
WaveformViewerFactory factory = new WaveformViewerFactory();
txDisplay = factory.createPanel(parent);
txDisplay.setMaxTime(0);
txDisplay.addPropertyChangeListener(IWaveformViewer.CURSOR_PROPERTY, new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
Long time = (Long) evt.getNewValue();
cursorStatusLineItem.setText("Cursor: "+ time/1000000+"ns");
}
});
getSite().setSelectionProvider(txDisplay);
new Thread(new Runnable() {
@Override
public void run() {
try {
loadDatabases();
} catch (InvocationTargetException | IOException | InterruptedException e) {
handleLoadException(e);
}
}
}).run();
zoomStatusLineItem.setText("Zoom level: "+zoomLevel[txDisplay.getZoomLevel()]);
cursorStatusLineItem.setText("Cursor: "+ txDisplay.getCursorTime()/1000000+"ns");
MenuManager menuMgr = new MenuManager("#PopupMenu");
// menuMgr.setRemoveAllWhenShown(true);
// menuMgr.addMenuListener(new IMenuListener() {
// public void menuAboutToShow(IMenuManager manager) {
// fillContextMenu(manager);
// }
// });
Menu menu = menuMgr.createContextMenu(txDisplay.getControl());
txDisplay.getControl().setMenu(menu);
getSite().registerContextMenu(menuMgr, txDisplay);
}
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.part.EditorPart#setInput(org.eclipse.ui.IEditorInput)
*/
protected void setInput(IEditorInput input) {
super.setInput(input);
if(input instanceof IFileEditorInput && !(input instanceof TxEditorInput))
super.setInput(new TxEditorInput(((IFileEditorInput)input).getFile()));
setPartName(input.getName());
}
protected void loadDatabases() throws IOException, InvocationTargetException, InterruptedException {
IWorkbench wb = PlatformUI.getWorkbench();
IProgressService ps = wb.getProgressService();
IEditorInput input = getEditorInput();
File file=null;
boolean loadSecondary=false;
boolean dontAskForSecondary=false;
ArrayList<File> filesToLoad=new ArrayList<File>();
if(input instanceof TxEditorInput){
TxEditorInput txInput = (TxEditorInput) input;
file = txInput.getFile().getLocation().toFile();
loadSecondary=txInput.isSecondaryLoaded()==null||txInput.isSecondaryLoaded();
dontAskForSecondary=txInput.isSecondaryLoaded()!=null;
} else if(input instanceof FileStoreEditorInput){
file=new File(((FileStoreEditorInput) input).getURI().getPath());
}
if(file.exists()){
filesToLoad.add(file);
if(loadSecondary){
String ext = getFileExtension(file.getName());
if("vcd".equals(ext.toLowerCase())){
if(dontAskForSecondary || askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txdb")))){
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txdb")));
if(input instanceof TxEditorInput) ((TxEditorInput) input).setSecondaryLoaded(true);
}else if(dontAskForSecondary ||askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txlog")))){
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txlog")));
if(input instanceof TxEditorInput) ((TxEditorInput) input).setSecondaryLoaded(true);
}
} else if("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())){
if(dontAskForSecondary || askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "vcd")))){
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "vcd")));
if(input instanceof TxEditorInput) ((TxEditorInput) input).setSecondaryLoaded(true);
}
}
}
}
final File[] files=filesToLoad.toArray(new File[filesToLoad.size()]);
ps.run(true, false, new IRunnableWithProgress() {
//ps.busyCursorWhile(new IRunnableWithProgress() {
public void run(IProgressMonitor pm) throws InvocationTargetException {
pm.beginTask("Loading database "+files[0].getName(), files.length);
try {
database.load(files[0]);
database.addPropertyChangeListener(txDisplay);
pm.worked(1);
if(pm.isCanceled()) return;
if(files.length==2){
database.load(files[1]);
pm.worked(1);
}
myParent.getDisplay().syncExec(new Runnable() {
@Override
public void run() {
updateTxDisplay();
}
});
} catch (Exception e) {
database=null;
throw new InvocationTargetException(e);
}
pm.done();
}
});
}
protected boolean askIfToLoad(File txFile) {
if(txFile.exists() &&
MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open",
"Would you like to open the adjacent database "+txFile.getName()+" as well?")){
return true;
}
return false;
}
protected void updateTxDisplay() {
txDisplay.setMaxTime(database.getMaxTime());
if(TxEditorPart.this.getEditorInput() instanceof TxEditorInput &&
((TxEditorInput) TxEditorPart.this.getEditorInput()).getStreamNames().size()>0){
LinkedList<TrackEntry> entries= new LinkedList<>();
for(String streamName:((TxEditorInput) TxEditorPart.this.getEditorInput()).getStreamNames()){
IWaveform stream = database.getStreamByName(streamName);
if(stream!=null)
entries.add(new TrackEntry(stream));
}
txDisplay.getStreamList().addAll(entries);
}
}
protected static String renameFileExtension(String source, String newExt) {
String target;
String currentExt = getFileExtension(source);
if (currentExt.equals("")){
target=source+"."+newExt;
} else {
target=source.replaceFirst(Pattern.quote("."+currentExt)+"$", Matcher.quoteReplacement("."+newExt));
}
return target;
}
protected static String getFileExtension(String f) {
String ext = "";
int i = f.lastIndexOf('.');
if (i > 0 && i < f.length() - 1) {
ext = f.substring(i + 1);
}
return ext;
}
private void handleLoadException(Exception e) {
e.printStackTrace();
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
"Error loading database", e.getMessage());
database = null;
}
@Override
public void setFocus() {
myParent.setFocus();
}
@Override
public void doSave(IProgressMonitor monitor) {
}
@Override
public void doSaveAs() {
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@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 IWaveformDb getModel() {
return database;
}
@Override
public void init(IEditorSite site, IEditorInput input)
throws PartInitException {
// Initialize the editor part
setSite(site);
setInput(input);
zoomStatusLineItem = new StatusLineContributionItem("TxEditorZoomContributionItem");
cursorStatusLineItem = new StatusLineContributionItem("TxEditorCursorContributionItem");
IActionBars actionBars = getEditorSite().getActionBars();
IStatusLineManager manager = actionBars.getStatusLineManager();
manager.add(zoomStatusLineItem);
manager.add(cursorStatusLineItem);
actionBars.updateActionBars();
}
@Override
public boolean isDirty() {
return false;
}
@Override
public boolean isSaveAsAllowed() {
return false;
}
public IWaveformDb getDatabase() {
return database;
}
public void addStreamToList(IWaveform obj){
if(getEditorInput() instanceof TxEditorInput && !((TxEditorInput) getEditorInput()).getStreamNames().contains(obj.getFullName())){
((TxEditorInput) getEditorInput()).getStreamNames().add(obj.getFullName());
txDisplay.getStreamList().add(new TrackEntry(obj));
} else
txDisplay.getStreamList().add(new TrackEntry(obj));
}
public void addStreamsToList(IWaveform[] iWaveforms){
for(IWaveform stream:iWaveforms)
addStreamToList(stream);
}
public void removeStreamFromList(IWaveform waveform){
if(getEditorInput() instanceof TxEditorInput && ((TxEditorInput) getEditorInput()).getStreamNames().contains(waveform.getFullName())){
((TxEditorInput) getEditorInput()).getStreamNames().remove(waveform.getFullName());
}
TrackEntry entry=null;
for(TrackEntry e:txDisplay.getStreamList()) {
if(e.waveform==waveform) {
entry=e;
break;
}
}
txDisplay.getStreamList().remove(entry);
}
public void removeStreamsFromList(IWaveform[] iWaveforms){
for(IWaveform stream:iWaveforms)
removeStreamFromList(stream);
}
public List<TrackEntry> getStreamList(){
return txDisplay.getStreamList();
}
public void setSelection(final ISelection selection){
myParent.getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
txDisplay.setSelection(selection);
}
});
}
public ISelection getSelection(){
return txDisplay.getSelection();
}
@Override
public String getContributorId() {
return getSite().getId();
}
public void moveSelection(GotoDirection next) {
txDisplay.moveSelection( next);
}
public void setZoomLevel(Integer level) {
txDisplay.setZoomLevel(level);
}
public void setZoomFit() {
txDisplay.setZoomLevel(6);
}
public int getZoomLevel() {
return txDisplay.getZoomLevel();
}
public void removeSelected() {
// TODO TxDisplay needs to be extended
}
}

View File

@@ -0,0 +1,134 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui;
import java.io.File;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ResourceLocator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.eclipse.wb.swt.SWTResourceManager;
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.minres.scviewer.ui"; //$NON-NLS-1$
// The shared instance
private static TxEditorPlugin plugin;
private ResourceBundle resourceBundle;
/**
* 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;
SWTResourceManager.dispose();
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 ResourceLocator.imageDescriptorFromBundle(PLUGIN_ID, fullpath).orElse(null);
}
public static Image createImage(String name) {
ImageDescriptor id=getImageDescriptor(name+".png");
return id.createImage();
}
public Color getColor(int idx){
switch (idx) {
case lineColor:
return SWTResourceManager.getColor(SWT.COLOR_RED);
case txBgColor:
return SWTResourceManager.getColor(SWT.COLOR_GREEN);
case highliteLineColor:
return SWTResourceManager.getColor(SWT.COLOR_CYAN);
case txHighliteBgColor:
return SWTResourceManager.getColor(SWT.COLOR_DARK_GREEN);
case trackBgLightColor:
return SWTResourceManager.getColor(220, 220, 220);
case trackBgDarkColor:
// return SWTResourceManager.getColor(200, 200, 200);
return SWTResourceManager.getColor(SWT.COLOR_BLACK);
case headerBgColor:
return SWTResourceManager.getColor(255, 255, 255);
case headerFgColor:
return SWTResourceManager.getColor(55, 55, 55);
default:
break;
}
return SWTResourceManager.getColor(SWT.COLOR_BLACK);
}
public ResourceBundle getResourceBundle() {
return resourceBundle;
}
}

View File

@@ -0,0 +1,91 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.adapter;
import java.util.ArrayList;
import org.eclipse.ui.views.properties.IPropertyDescriptor;
import org.eclipse.ui.views.properties.IPropertySource;
import org.eclipse.ui.views.properties.PropertyDescriptor;
import com.minres.scviewer.database.ITx;
public class ITransactionPropertySource implements IPropertySource {
private ITx iTransaction;
public final static String PROPERTY_ID = "ID";
public final static String PROPERTY_BEGINTIME = "BEGINTIME";
public final static String PROPERTY_ENDTIME = "ENDTIME";
public final static String PROPERTY_NAME = "NAME";
protected IPropertyDescriptor[] propertyDescriptors;
public ITransactionPropertySource(ITx iTransaction) {
this.iTransaction=iTransaction;
}
@Override
public Object getEditableValue() {
return null;
}
@Override
public IPropertyDescriptor[] getPropertyDescriptors() {
if (propertyDescriptors == null) {
ArrayList<IPropertyDescriptor> descriptor=new ArrayList<IPropertyDescriptor>();
// Create a descriptor and set a category
PropertyDescriptor idDescriptor = new PropertyDescriptor(PROPERTY_ID, "Id");
idDescriptor.setCategory("Attributes");
descriptor.add(idDescriptor);
PropertyDescriptor begTimeDescriptor = new PropertyDescriptor(PROPERTY_BEGINTIME, "Begin time");
begTimeDescriptor.setCategory("Attributes");
descriptor.add(begTimeDescriptor);
PropertyDescriptor endTimeDescriptor = new PropertyDescriptor(PROPERTY_ENDTIME, "End time");
endTimeDescriptor.setCategory("Attributes");
descriptor.add(endTimeDescriptor);
PropertyDescriptor nameDescriptor = new PropertyDescriptor(PROPERTY_NAME, "Name");
nameDescriptor.setCategory("Attributes");
descriptor.add(nameDescriptor);
propertyDescriptors = descriptor.toArray(new IPropertyDescriptor[descriptor.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.equals(PROPERTY_NAME)){
return iTransaction.getGenerator().getName();
}
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) {
}
}

View File

@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.adapter;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.ui.views.properties.IPropertySource;
import com.minres.scviewer.database.ITx;
public class TxAdapterFactory implements IAdapterFactory {
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Object getAdapter(Object adaptableObject, Class adapterType) {
if (adapterType == IPropertySource.class)
return new ITransactionPropertySource((ITx) adaptableObject);
return null;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Class[] getAdapterList() {
return new Class[]{IPropertySource.class};
}
}

View File

@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.ui.TxEditorPart;
public class GotoNext extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
((TxEditorPart)editor).moveSelection(GotoDirection.NEXT);
}
return null;
}
}

View File

@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import com.minres.scviewer.database.ui.GotoDirection;
import com.minres.scviewer.ui.TxEditorPart;
public class GotoPrev extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
((TxEditorPart)editor).moveSelection(GotoDirection.PREV);
}
return null;
}
}

View File

@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.ui.TxEditorPart;
public class RemoveHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
TxEditorPart editorPart = (TxEditorPart) editor;
ISelection selection =editorPart.getSelection();
if(selection instanceof StructuredSelection && ((StructuredSelection)selection).getFirstElement() instanceof IWaveform){
editorPart.removeStreamFromList((IWaveform) ((StructuredSelection)selection).getFirstElement());
editorPart.setSelection(new StructuredSelection());
}
}
return null;
}
}

View File

@@ -0,0 +1,41 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import com.minres.scviewer.ui.TxEditorPart;
public class Zoom extends AbstractHandler {
private static final String PARM_MSG = "com.minres.scviewer.ui.zoom.level";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
String msg = event.getParameter(PARM_MSG);
if (msg == null) {
if(editor instanceof TxEditorPart){
((TxEditorPart)editor).setZoomFit();
}
} else {
Integer level = Integer.parseInt(msg);
if(editor instanceof TxEditorPart){
((TxEditorPart)editor).setZoomLevel(level);
}
}
return null;
}
}

View File

@@ -0,0 +1,39 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.handler;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.handlers.HandlerUtil;
import com.minres.scviewer.ui.TxEditorPart;
public class ZoomInOut extends AbstractHandler {
private static final String ZOOMIN_ID = "com.minres.scviewer.ui.zoomin";
private static final String ZOOMOUT_ID= "com.minres.scviewer.ui.zoomout";
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IEditorPart editor = HandlerUtil.getActiveEditor(event);
if(editor instanceof TxEditorPart){
String id = event.getCommand().getId();
TxEditorPart txEditor=(TxEditorPart) editor;
if (ZOOMIN_ID.compareTo(id) == 0)
txEditor.setZoomLevel(txEditor.getZoomLevel()-1);
else if(ZOOMOUT_ID.compareTo(id) == 0)
txEditor.setZoomLevel(txEditor.getZoomLevel()+1);
}
return null;
}
}

View File

@@ -0,0 +1,109 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.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();
}
}

View File

@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.views;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.views.properties.PropertySheet;
public class TransactionPropertySheet extends PropertySheet {
public TransactionPropertySheet() {
super();
}
@Override
protected boolean isImportant(IWorkbenchPart part) {
return part.getSite().getId().equals("com.minres.scviewer.ui.TxEditorPart");
}
}

View File

@@ -0,0 +1,220 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.views;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.LinkedList;
import org.eclipse.jface.action.Action;
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.ISelectionListener;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.IPageSite;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.IWaveform;
import com.minres.scviewer.ui.TxEditorPart;
import com.minres.scviewer.ui.views.provider.TxDbTreeContentProvider;
import com.minres.scviewer.ui.views.provider.TxDbTreeLabelProvider;
/**
* Creates an outline pagebook for this editor.
*/
public class TxOutlinePage extends ContentOutlinePage implements ISelectionListener, ISelectionProvider, PropertyChangeListener {
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;
private TxEditorPart editor;
TreeViewer contentOutlineViewer ;
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);
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.minres.scviewer.ui.outline.contextmenu", menuMgr, contentOutlineViewer);
// add me as selection listener
getSite().getPage().addSelectionListener((ISelectionListener) this);
//getSite().getPage().addSelectionListener("SampleViewId",(ISelectionListener)this);
getSite().setSelectionProvider(this);
editor.getDatabase().addPropertyChangeListener(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();
}
private void fillContextMenu(IMenuManager menuMgr) {
// initalize the context menu
getTreeViewer().getSelection();
ISelection selection = getTreeViewer().getSelection();
if(selection instanceof IStructuredSelection){
IStructuredSelection sel = (IStructuredSelection) selection;
Object obj = sel.getFirstElement();
menuMgr.add(makeStreamAction("Add to Wave", ISharedImages.IMG_OBJ_ADD, sel, obj instanceof IWaveform, false));
menuMgr.add(makeStreamAction("Add all to Wave", ISharedImages.IMG_OBJ_ADD, sel, true, false));
// menuMgr.add(makeStreamAction("Remove from Wave", ISharedImages.IMG_TOOL_DELETE, sel, obj instanceof IWaveform, true));
// menuMgr.add(makeStreamAction("Remove all from Wave", ISharedImages.IMG_TOOL_DELETE, sel, true, true));
}
}
//ISelectionListener methods
@Override
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
// if(!(part instanceof ContentOutline) && selection instanceof IStructuredSelection){
// if(((IStructuredSelection)selection).getFirstElement() instanceof ITransaction){
// System.out.println("Transaction with id "+((ITransaction)((IStructuredSelection)selection).getFirstElement()).getId() +" selected");
// } else if(((IStructuredSelection)selection).getFirstElement() != null)
// System.out.println("Something else 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 IHierNode) {
fireSelectionChanged(new StructuredSelection((IHierNode) tmp));
}
}
}
private Action makeStreamAction(String text, String imgDescriptor, final IStructuredSelection selection, boolean enabled, final boolean remove) {
Action action = new Action() {
public void run() {
if(selection!=null)
for(Object obj :selection.toArray()){
if(obj instanceof IWaveform){
if(remove)
editor.removeStreamFromList((IWaveform) obj);
else
editor.addStreamToList((IWaveform) obj);
} else if(obj instanceof IHierNode){
LinkedList<IHierNode> queue = new LinkedList<IHierNode>();
LinkedList<IWaveform> streams = new LinkedList<IWaveform>();
queue.add((IHierNode)obj);
while(queue.size()>0){
IHierNode n = queue.poll();
if(n instanceof IWaveform) streams.add((IWaveform) n);
queue.addAll(n.getChildNodes());
}
if(remove)
editor.removeStreamsFromList(streams.toArray(new IWaveform[]{}));
else
editor.addStreamsToList(streams.toArray(new IWaveform[]{}));
}
}
}
};
action.setText(text);
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgDescriptor));
if(selection.getFirstElement() instanceof IWaveform && editor.getStreamList().contains(selection.getFirstElement()))
action.setEnabled(false);
else
action.setEnabled(true);
return action;
}
@Override
public void propertyChange(PropertyChangeEvent evt) {
if("CHILDS".equals(evt.getPropertyName())) {
contentOutlineViewer.refresh();
}
}
}

View File

@@ -0,0 +1,55 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.views.provider;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.Viewer;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IHierNode;
public class TxDbTreeContentProvider implements ITreeContentProvider {
private IWaveformDb database;
@Override
public void dispose() { }
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
database=(IWaveformDb)newInput;
}
@Override
public Object[] getElements(Object inputElement) {
return database.getChildNodes().toArray();
}
@Override
public Object[] getChildren(Object parentElement) {
if(parentElement instanceof IHierNode){
return ((IHierNode)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;
}
}

View File

@@ -0,0 +1,88 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.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.minres.scviewer.database.ISignal;
import com.minres.scviewer.database.IWaveformDb;
import com.minres.scviewer.database.IHierNode;
import com.minres.scviewer.database.ITxStream;
import com.minres.scviewer.ui.TxEditorPlugin;
public class TxDbTreeLabelProvider implements ILabelProvider {
private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>();
private Image database;
private Image stream;
private Image signal;
private Image folder;
public TxDbTreeLabelProvider() {
super();
database=TxEditorPlugin.createImage("database");
stream=TxEditorPlugin.createImage("stream");
folder=TxEditorPlugin.createImage("folder");
signal=TxEditorPlugin.createImage("signal");
}
@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();
if(signal!=null) signal.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 IWaveformDb){
return database;
}else if(element instanceof ITxStream){
return stream;
}else if(element instanceof ISignal<?>){
return signal;
}else if(element instanceof IHierNode){
return folder;
} else
return null;
}
@Override
public String getText(Object element) {
return ((IHierNode)element).getName();
}
}

View File

@@ -0,0 +1,271 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.views.sections;
import java.util.HashMap;
import java.util.LinkedList;
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.minres.scviewer.database.AssociationType;
import com.minres.scviewer.database.DataType;
import com.minres.scviewer.database.ITxAttribute;
import com.minres.scviewer.database.ITx;
public class AttributeProperty extends AbstractPropertySection implements ISelectionProvider {
private final String[] titles = { "Location", "Name", "Type", "Value" };
private ListenerList<ISelectionChangedListener> listeners = new ListenerList<ISelectionChangedListener>();
private ITx 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<String, List<ITxAttribute>> hier = new TreeMap<String, List<ITxAttribute>>();
HashMap<ITxAttribute, String> parents = new HashMap<ITxAttribute, String>();
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput instanceof ITx) {
List<ITxAttribute> attributes = ((ITx)newInput).getAttributes();
hier.clear();
parents.clear();
String location="Begin";
List<ITxAttribute> childs=new LinkedList<ITxAttribute>();
for (ITxAttribute attr : attributes)
if (attr != null && attr.getType()==AssociationType.BEGIN){
childs.add(attr);
parents.put(attr, location);
}
if(childs.size()>0) hier.put(location, childs);
location="Transaction";
childs=new LinkedList<ITxAttribute>();
for (ITxAttribute attr : attributes)
if (attr != null && attr.getType()==AssociationType.RECORD){
childs.add(attr);
parents.put(attr, location);
}
if(childs.size()>0) hier.put(location, childs);
location="End";
childs=new LinkedList<ITxAttribute>();
for (ITxAttribute attr : attributes)
if (attr != null && attr.getType()==AssociationType.END){
childs.add(attr);
parents.put(attr, location);
}
if(childs.size()>0) hier.put(location, childs);
}
}
@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 ITxAttribute)
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 ITxAttribute){
ITxAttribute attr = (ITxAttribute)element;
if (columnIndex == 1 )
return attr.getName();
else if (columnIndex == 2 )
return attr.getDataType().name();
else if (columnIndex == 3){
String value = attr.getValue().toString();
if((DataType.UNSIGNED == attr.getDataType() || DataType.INTEGER==attr.getDataType()) && !"0".equals(value)) {
try {
value = attr.getValue().toString() + "(0x"+Long.toHexString(Long.parseLong(attr.getValue().toString()))+")";
} catch(NumberFormatException e) { }
}
return value;
}
}
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 ITx);
iTr = (ITx) input;
}
public void refresh() {
treeViewer.setInput(iTr);
}
@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));
}
}
}

View File

@@ -0,0 +1,293 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.ui.views.sections;
import java.util.Collection;
import java.util.HashMap;
import java.util.TreeMap;
import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.ListenerList;
import org.eclipse.jface.action.Action;
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.StructuredSelection;
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.IEditorReference;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.properties.tabbed.AbstractPropertySection;
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
import com.minres.scviewer.database.ITx;
import com.minres.scviewer.database.ITxRelation;
public class RelatedProperty extends AbstractPropertySection implements ISelectionProvider, ISelectionChangedListener {
private final String[] titles = { "Relation type", "Relation Name", "Tx Id" };
private ListenerList<ISelectionChangedListener> listeners = new ListenerList<ISelectionChangedListener>();
private ITx 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.LEFT);
column2.setAlignment(SWT.LEFT);
column2.setText(titles[1]);
column2.setWidth(150);
TreeColumn column3 = new TreeColumn(tree, SWT.RIGHT);
column3.setAlignment(SWT.LEFT);
column3.setText(titles[2]);
column3.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<String, Collection<ITxRelation>> hier = new TreeMap<String, Collection<ITxRelation>>();
HashMap<ITxRelation, String> parents = new HashMap<ITxRelation, String>();
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
if (newInput instanceof ITx) {
hier.clear();
parents.clear();
String relName = "incoming";
Collection<ITxRelation> relSet = ((ITx)newInput).getIncomingRelations();
if (relSet != null && relSet.size() > 0) {
hier.put(relName, relSet);
for (ITxRelation rel : relSet)
parents.put(rel, relName);
}
relName = "outgoing";
relSet = ((ITx)newInput).getOutgoingRelations();
if (relSet != null && relSet.size() > 0) {
hier.put(relName, relSet);
for (ITxRelation rel : relSet)
parents.put(rel, relName);
}
}
}
@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 ITx)
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 (columnIndex == 1 && element instanceof ITxRelation)
return ((ITxRelation) element).getRelationType().getName();
else if (columnIndex == 2 && element instanceof ITxRelation){
ITxRelation rel = (ITxRelation) element;
if(rel.getTarget()==iTr)
return ((ITxRelation) element).getSource().getId().toString();
else
return ((ITxRelation) element).getTarget().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) {
ISelection selection = treeViewer.getSelection();
if (selection instanceof IStructuredSelection) {
Object obj = ((IStructuredSelection) selection).getFirstElement();
mgr.add(makeTransactionAction(obj, iTr));
}
}
});
Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
treeViewer.getControl().setMenu(menu);
// aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
// if(getPart()!=null){
// getPart().getSite().setSelectionProvider(this);
// }
}
private Action makeTransactionAction(final Object obj, final ITx transaction) {
Action action = new Action() {
public void run() {
if(obj instanceof ITxRelation){
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
ITx targetTransaction = ((ITxRelation)obj).getSource()==transaction?
((ITxRelation)obj).getTarget():((ITxRelation)obj).getSource();
for(IEditorReference editorRef: page.getEditorReferences()){
IWorkbenchPart part =editorRef.getPart(false);
if(editorRef.getPage().isPartVisible(part)){
part.getSite().getSelectionProvider().setSelection(new StructuredSelection(targetTransaction));
part.setFocus();
}
}
}
}
};
action.setText("Jump to Transaction");
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_ADD));
action.setEnabled(true);
return action;
}
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 ITx);
iTr = (ITx) input;
}
public void refresh() {
treeViewer.setInput(iTr);
}
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 ITransaction){
// currentSelection = new StructuredSelection(elem);
// }
// }
}
}

View File

@@ -0,0 +1,447 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package org.eclipse.wb.swt;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Font;
import org.eclipse.swt.graphics.FontData;
import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.widgets.Display;
/**
* Utility class for managing OS resources associated with SWT controls such as colors, fonts, images, etc.
* <p>
* !!! IMPORTANT !!! Application code must explicitly invoke the <code>dispose()</code> method to release the
* operating system resources managed by cached objects when those objects and OS resources are no longer
* needed (e.g. on application shutdown)
* <p>
* This class may be freely distributed as part of any application or plugin.
* <p>
* @author scheglov_ke
* @author Dan Rubel
*/
public class SWTResourceManager {
////////////////////////////////////////////////////////////////////////////
//
// Color
//
////////////////////////////////////////////////////////////////////////////
private static Map<RGB, Color> m_colorMap = new HashMap<RGB, Color>();
/**
* Returns the system {@link Color} matching the specific ID.
*
* @param systemColorID
* the ID value for the color
* @return the system {@link Color} matching the specific ID
*/
public static Color getColor(int systemColorID) {
Display display = Display.getCurrent();
return display.getSystemColor(systemColorID);
}
/**
* Returns a {@link Color} given its red, green and blue component values.
*
* @param r
* the red component of the color
* @param g
* the green component of the color
* @param b
* the blue component of the color
* @return the {@link Color} matching the given red, green and blue component values
*/
public static Color getColor(int r, int g, int b) {
return getColor(new RGB(r, g, b));
}
/**
* Returns a {@link Color} given its RGB value.
*
* @param rgb
* the {@link RGB} value of the color
* @return the {@link Color} matching the RGB value
*/
public static Color getColor(RGB rgb) {
Color color = m_colorMap.get(rgb);
if (color == null) {
Display display = Display.getCurrent();
color = new Color(display, rgb);
m_colorMap.put(rgb, color);
}
return color;
}
/**
* Dispose of all the cached {@link Color}'s.
*/
public static void disposeColors() {
for (Color color : m_colorMap.values()) {
color.dispose();
}
m_colorMap.clear();
}
////////////////////////////////////////////////////////////////////////////
//
// Image
//
////////////////////////////////////////////////////////////////////////////
/**
* Maps image paths to images.
*/
private static Map<String, Image> m_imageMap = new HashMap<String, Image>();
/**
* Returns an {@link Image} encoded by the specified {@link InputStream}.
*
* @param stream
* the {@link InputStream} encoding the image data
* @return the {@link Image} encoded by the specified input stream
*/
protected static Image getImage(InputStream stream) throws IOException {
try {
Display display = Display.getCurrent();
ImageData data = new ImageData(stream);
if (data.transparentPixel > 0) {
return new Image(display, data, data.getTransparencyMask());
}
return new Image(display, data);
} finally {
stream.close();
}
}
/**
* Returns an {@link Image} stored in the file at the specified path.
*
* @param path
* the path to the image file
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(String path) {
Image image = m_imageMap.get(path);
if (image == null) {
try {
image = getImage(new FileInputStream(path));
m_imageMap.put(path, image);
} catch (Exception e) {
image = getMissingImage();
m_imageMap.put(path, image);
}
}
return image;
}
/**
* Returns an {@link Image} stored in the file at the specified path relative to the specified class.
*
* @param clazz
* the {@link Class} relative to which to find the image
* @param path
* the path to the image file, if starts with <code>'/'</code>
* @return the {@link Image} stored in the file at the specified path
*/
public static Image getImage(Class<?> clazz, String path) {
String key = clazz.getName() + '|' + path;
Image image = m_imageMap.get(key);
if (image == null) {
try {
image = getImage(clazz.getResourceAsStream(path));
m_imageMap.put(key, image);
} catch (Exception e) {
image = getMissingImage();
m_imageMap.put(key, image);
}
}
return image;
}
private static final int MISSING_IMAGE_SIZE = 10;
/**
* @return the small {@link Image} that can be used as placeholder for missing image.
*/
private static Image getMissingImage() {
Image image = new Image(Display.getCurrent(), MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
//
GC gc = new GC(image);
gc.setBackground(getColor(SWT.COLOR_RED));
gc.fillRectangle(0, 0, MISSING_IMAGE_SIZE, MISSING_IMAGE_SIZE);
gc.dispose();
//
return image;
}
/**
* Style constant for placing decorator image in top left corner of base image.
*/
public static final int TOP_LEFT = 1;
/**
* Style constant for placing decorator image in top right corner of base image.
*/
public static final int TOP_RIGHT = 2;
/**
* Style constant for placing decorator image in bottom left corner of base image.
*/
public static final int BOTTOM_LEFT = 3;
/**
* Style constant for placing decorator image in bottom right corner of base image.
*/
public static final int BOTTOM_RIGHT = 4;
/**
* Internal value.
*/
protected static final int LAST_CORNER_KEY = 5;
/**
* Maps images to decorated images.
*/
@SuppressWarnings("unchecked")
private static Map<Image, Map<Image, Image>>[] m_decoratedImageMap = new Map[LAST_CORNER_KEY];
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
* @param decorator
* the {@link Image} to decorate the base image
* @return {@link Image} The resulting decorated image
*/
public static Image decorateImage(Image baseImage, Image decorator) {
return decorateImage(baseImage, decorator, BOTTOM_RIGHT);
}
/**
* Returns an {@link Image} composed of a base image decorated by another image.
*
* @param baseImage
* the base {@link Image} that should be decorated
* @param decorator
* the {@link Image} to decorate the base image
* @param corner
* the corner to place decorator image
* @return the resulting decorated {@link Image}
*/
public static Image decorateImage(final Image baseImage, final Image decorator, final int corner) {
if (corner <= 0 || corner >= LAST_CORNER_KEY) {
throw new IllegalArgumentException("Wrong decorate corner");
}
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[corner];
if (cornerDecoratedImageMap == null) {
cornerDecoratedImageMap = new HashMap<Image, Map<Image, Image>>();
m_decoratedImageMap[corner] = cornerDecoratedImageMap;
}
Map<Image, Image> decoratedMap = cornerDecoratedImageMap.get(baseImage);
if (decoratedMap == null) {
decoratedMap = new HashMap<Image, Image>();
cornerDecoratedImageMap.put(baseImage, decoratedMap);
}
//
Image result = decoratedMap.get(decorator);
if (result == null) {
Rectangle bib = baseImage.getBounds();
Rectangle dib = decorator.getBounds();
//
result = new Image(Display.getCurrent(), bib.width, bib.height);
//
GC gc = new GC(result);
gc.drawImage(baseImage, 0, 0);
if (corner == TOP_LEFT) {
gc.drawImage(decorator, 0, 0);
} else if (corner == TOP_RIGHT) {
gc.drawImage(decorator, bib.width - dib.width, 0);
} else if (corner == BOTTOM_LEFT) {
gc.drawImage(decorator, 0, bib.height - dib.height);
} else if (corner == BOTTOM_RIGHT) {
gc.drawImage(decorator, bib.width - dib.width, bib.height - dib.height);
}
gc.dispose();
//
decoratedMap.put(decorator, result);
}
return result;
}
/**
* Dispose all of the cached {@link Image}'s.
*/
public static void disposeImages() {
// dispose loaded images
{
for (Image image : m_imageMap.values()) {
image.dispose();
}
m_imageMap.clear();
}
// dispose decorated images
for (int i = 0; i < m_decoratedImageMap.length; i++) {
Map<Image, Map<Image, Image>> cornerDecoratedImageMap = m_decoratedImageMap[i];
if (cornerDecoratedImageMap != null) {
for (Map<Image, Image> decoratedMap : cornerDecoratedImageMap.values()) {
for (Image image : decoratedMap.values()) {
image.dispose();
}
decoratedMap.clear();
}
cornerDecoratedImageMap.clear();
}
}
}
////////////////////////////////////////////////////////////////////////////
//
// Font
//
////////////////////////////////////////////////////////////////////////////
/**
* Maps font names to fonts.
*/
private static Map<String, Font> m_fontMap = new HashMap<String, Font>();
/**
* Maps fonts to their bold versions.
*/
private static Map<Font, Font> m_fontToBoldFontMap = new HashMap<Font, Font>();
/**
* Returns a {@link Font} based on its name, height and style.
*
* @param name
* the name of the font
* @param height
* the height of the font
* @param style
* the style of the font
* @return {@link Font} The font matching the name, height and style
*/
public static Font getFont(String name, int height, int style) {
return getFont(name, height, style, false, false);
}
/**
* Returns a {@link Font} based on its name, height and style. Windows-specific strikeout and underline
* flags are also supported.
*
* @param name
* the name of the font
* @param size
* the size of the font
* @param style
* the style of the font
* @param strikeout
* the strikeout flag (warning: Windows only)
* @param underline
* the underline flag (warning: Windows only)
* @return {@link Font} The font matching the name, height, style, strikeout and underline
*/
public static Font getFont(String name, int size, int style, boolean strikeout, boolean underline) {
String fontName = name + '|' + size + '|' + style + '|' + strikeout + '|' + underline;
Font font = m_fontMap.get(fontName);
if (font == null) {
FontData fontData = new FontData(name, size, style);
if (strikeout || underline) {
try {
Class<?> logFontClass = Class.forName("org.eclipse.swt.internal.win32.LOGFONT"); //$NON-NLS-1$
Object logFont = FontData.class.getField("data").get(fontData); //$NON-NLS-1$
if (logFont != null && logFontClass != null) {
if (strikeout) {
logFontClass.getField("lfStrikeOut").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
}
if (underline) {
logFontClass.getField("lfUnderline").set(logFont, Byte.valueOf((byte) 1)); //$NON-NLS-1$
}
}
} catch (Throwable e) {
System.err.println("Unable to set underline or strikeout" + " (probably on a non-Windows platform). " + e); //$NON-NLS-1$ //$NON-NLS-2$
}
}
font = new Font(Display.getCurrent(), fontData);
m_fontMap.put(fontName, font);
}
return font;
}
/**
* Returns a bold version of the given {@link Font}.
*
* @param baseFont
* the {@link Font} for which a bold version is desired
* @return the bold version of the given {@link Font}
*/
public static Font getBoldFont(Font baseFont) {
Font font = m_fontToBoldFontMap.get(baseFont);
if (font == null) {
FontData fontDatas[] = baseFont.getFontData();
FontData data = fontDatas[0];
font = new Font(Display.getCurrent(), data.getName(), data.getHeight(), SWT.BOLD);
m_fontToBoldFontMap.put(baseFont, font);
}
return font;
}
/**
* Dispose all of the cached {@link Font}'s.
*/
public static void disposeFonts() {
// clear fonts
for (Font font : m_fontMap.values()) {
font.dispose();
}
m_fontMap.clear();
// clear bold fonts
for (Font font : m_fontToBoldFontMap.values()) {
font.dispose();
}
m_fontToBoldFontMap.clear();
}
////////////////////////////////////////////////////////////////////////////
//
// Cursor
//
////////////////////////////////////////////////////////////////////////////
/**
* Maps IDs to cursors.
*/
private static Map<Integer, Cursor> m_idToCursorMap = new HashMap<Integer, Cursor>();
/**
* Returns the system cursor matching the specific ID.
*
* @param id
* int The ID value for the cursor
* @return Cursor The system cursor matching the specific ID
*/
public static Cursor getCursor(int id) {
Integer key = Integer.valueOf(id);
Cursor cursor = m_idToCursorMap.get(key);
if (cursor == null) {
cursor = new Cursor(Display.getDefault(), id);
m_idToCursorMap.put(key, cursor);
}
return cursor;
}
/**
* Dispose all of the cached cursors.
*/
public static void disposeCursors() {
for (Cursor cursor : m_idToCursorMap.values()) {
cursor.dispose();
}
m_idToCursorMap.clear();
}
////////////////////////////////////////////////////////////////////////////
//
// General
//
////////////////////////////////////////////////////////////////////////////
/**
* Dispose of cached objects and their underlying OS resources. This should only be called when the cached
* objects are no longer needed (e.g. on application shutdown).
*/
public static void dispose() {
disposeColors();
disposeImages();
disposeFonts();
disposeCursors();
}
}