[WIP ]reorganized dir structure
This commit is contained in:
@ -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() {
|
||||
}
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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) {
|
||||
}
|
||||
|
||||
}
|
@ -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};
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
@ -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");
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user