- added SQLite back end
- reworked graphical representation to use widgets
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
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,31 @@
|
||||
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;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
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$
|
||||
|
||||
private static final String STREAMLIST_PATH = "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);
|
||||
String listData = memento.getString(STREAMLIST_PATH);
|
||||
if (listData != null) {
|
||||
try {
|
||||
ByteArrayInputStream bais = new ByteArrayInputStream(javax.xml.bind.DatatypeConverter.parseHexBinary(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());
|
||||
try {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||
oos.writeObject(input.getStreamNames());
|
||||
memento.putString(STREAMLIST_PATH, javax.xml.bind.DatatypeConverter.printHexBinary(baos.toByteArray()));
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorSite;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.FileStoreEditorInput;
|
||||
import org.eclipse.ui.internal.ide.dialogs.IFileStoreFilter;
|
||||
import org.eclipse.ui.part.EditorPart;
|
||||
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
|
||||
import org.eclipse.ui.views.properties.IPropertySheetPage;
|
||||
import org.eclipse.ui.views.properties.tabbed.ITabbedPropertySheetPageContributor;
|
||||
import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.framework.FrameworkUtil;
|
||||
import org.osgi.framework.InvalidSyntaxException;
|
||||
import org.osgi.framework.ServiceReference;
|
||||
|
||||
import com.minres.scviewer.database.ITrDb;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransactionDbFactory;
|
||||
import com.minres.scviewer.ui.swt.TxDisplay;
|
||||
import com.minres.scviewer.ui.views.TxOutlinePage;
|
||||
|
||||
public class TxEditorPart extends EditorPart implements ITabbedPropertySheetPageContributor {
|
||||
|
||||
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 TxDisplay txDisplay;
|
||||
|
||||
/** This is the root of the editor's model. */
|
||||
private ITrDb database;
|
||||
|
||||
private Composite myParent;
|
||||
|
||||
public TxEditorPart() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create contents of the editor part.
|
||||
* @param parent
|
||||
*/
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
myParent=parent;
|
||||
/** Add handlers for global actions (delete, etc) */
|
||||
// IActionBars actionBars = getEditorSite().getActionBars();
|
||||
// actionBars.setGlobalActionHandler(WAVE_ACTION_ID, new Action() {
|
||||
// @Override
|
||||
// public void runWithEvent(Event event) {
|
||||
// System.out.println("AddToWave with event");
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// System.out.println("AddToWave");
|
||||
// }
|
||||
// });
|
||||
|
||||
txDisplay = new TxDisplay(parent);
|
||||
if(database!=null) database.addPropertyChangeListener(txDisplay);
|
||||
getSite().setSelectionProvider(txDisplay);
|
||||
if(getEditorInput()!=null && ((TxEditorInput) getEditorInput()).getStreamNames().size()>0 && database!=null){
|
||||
if(MessageDialog.openConfirm(parent.getShell(), "Confirm", "Do you want the restore last state of the wave form?"))
|
||||
for(String streamName:((TxEditorInput) getEditorInput()).getStreamNames()){
|
||||
ITrStream stream = database.getStreamByName(streamName);
|
||||
if(stream!=null)
|
||||
txDisplay.addStream(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* (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){
|
||||
if(!(input instanceof TxEditorInput))
|
||||
super.setInput(new TxEditorInput(((IFileEditorInput)input).getFile()));
|
||||
try {
|
||||
IPath location = ((IFileEditorInput) input).getFile().getLocation();
|
||||
if (location != null)
|
||||
getTrDatabase(location.toFile());
|
||||
setPartName(((IFileEditorInput) input).getFile().getName());
|
||||
} catch (Exception e) {
|
||||
handleLoadException(e);
|
||||
}
|
||||
} else if(input instanceof FileStoreEditorInput){
|
||||
try {
|
||||
//database.load(((FileStoreEditorInput) input).getURI().toURL().openStream());
|
||||
File file=new File(((FileStoreEditorInput) input).getURI().getPath());
|
||||
getTrDatabase(file);
|
||||
setPartName(((FileStoreEditorInput) input).getName());
|
||||
} catch (Exception e) {
|
||||
handleLoadException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void getTrDatabase(File file) {
|
||||
try {
|
||||
BundleContext context = FrameworkUtil.getBundle(this.getClass()).getBundleContext();
|
||||
ServiceReference<?>[] serviceReferences = context.getServiceReferences(ITransactionDbFactory.class.getName(), null);
|
||||
if(serviceReferences!=null){
|
||||
for(ServiceReference<?> serviceReference:serviceReferences){
|
||||
database = ((ITransactionDbFactory) context.getService(serviceReference)).createDatabase(file);
|
||||
if(database!=null){
|
||||
if(txDisplay !=null) database.addPropertyChangeListener(txDisplay);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (InvalidSyntaxException e) {
|
||||
}
|
||||
MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
"Error loading database", "Could not find database loader implementation");
|
||||
database=null;
|
||||
// if(TxEditorPlugin.getDefault().getTransactionDbFactory()!=null){
|
||||
// database = TxEditorPlugin.getDefault().getTransactionDbFactory().createDatabase();
|
||||
// if(txDisplay !=null) database.addPropertyChangeListener(txDisplay);
|
||||
// } else {
|
||||
// MessageDialog.openError(PlatformUI.getWorkbench().getDisplay().getActiveShell(),
|
||||
// "Error loading database", "Could not find database loader implementation");
|
||||
// database=null;
|
||||
// }
|
||||
}
|
||||
|
||||
private void handleLoadException(Exception e) {
|
||||
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")
|
||||
@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 ITrDb getModel() {
|
||||
return database;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IEditorSite site, IEditorInput input)
|
||||
throws PartInitException {
|
||||
// Initialize the editor part
|
||||
setSite(site);
|
||||
setInput(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDirty() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSaveAsAllowed() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public ITrDb getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void addStreamToList(ITrStream stream){
|
||||
if(getEditorInput() instanceof TxEditorInput && !((TxEditorInput) getEditorInput()).getStreamNames().contains(stream.getFullName())){
|
||||
((TxEditorInput) getEditorInput()).getStreamNames().add(stream.getFullName());
|
||||
txDisplay.addStream(stream);
|
||||
} else
|
||||
txDisplay.addStream(stream);
|
||||
|
||||
}
|
||||
|
||||
public void addStreamsToList(ITrStream[] streams){
|
||||
for(ITrStream stream:streams)
|
||||
addStreamToList(stream);
|
||||
}
|
||||
|
||||
public void removeStreamFromList(ITrStream stream){
|
||||
if(getEditorInput() instanceof TxEditorInput && ((TxEditorInput) getEditorInput()).getStreamNames().contains(stream.getFullName())){
|
||||
((TxEditorInput) getEditorInput()).getStreamNames().remove(stream.getFullName());
|
||||
txDisplay.removeStream(stream);
|
||||
} else
|
||||
txDisplay.removeStream(stream);
|
||||
}
|
||||
|
||||
public void removeStreamsFromList(ITrStream[] streams){
|
||||
for(ITrStream stream:streams)
|
||||
removeStreamFromList(stream);
|
||||
}
|
||||
|
||||
public List<ITrStream> getStreamList(){
|
||||
return txDisplay.getStreamList();
|
||||
}
|
||||
|
||||
public void setSelection(final ISelection selection){
|
||||
myParent.getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txDisplay.setSelection(selection);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContributorId() {
|
||||
return getSite().getId();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,153 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.ui;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
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;
|
||||
|
||||
import com.minres.scviewer.database.ITransactionDbFactory;
|
||||
|
||||
/**
|
||||
* 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 imageDescriptorFromPlugin(PLUGIN_ID, fullpath);
|
||||
}
|
||||
|
||||
public static Image createImage(String name) {
|
||||
ImageDescriptor id=getImageDescriptor(name+".png");
|
||||
return id.createImage();
|
||||
}
|
||||
|
||||
public Color getColor(int idx){
|
||||
switch (idx) {
|
||||
case lineColor:
|
||||
return 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);
|
||||
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;
|
||||
}
|
||||
|
||||
private ITransactionDbFactory transactionDbFactory;
|
||||
private List<ITransactionDbFactory> factories= new ArrayList<ITransactionDbFactory>();
|
||||
public ITransactionDbFactory getTransactionDbFactory() {
|
||||
return transactionDbFactory;
|
||||
}
|
||||
|
||||
public void setTransactionDbFactory(ITransactionDbFactory transactionDbFactory) {
|
||||
factories.add( transactionDbFactory);
|
||||
System.out.println("Service bound");
|
||||
}
|
||||
|
||||
public void unsetTransactionDbFactory(ITransactionDbFactory transactionDbFactory) {
|
||||
factories.remove(transactionDbFactory);
|
||||
System.out.println("Service unbound");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package com.minres.scviewer.ui.adapter;
|
||||
|
||||
import org.eclipse.core.runtime.IAdapterFactory;
|
||||
import org.eclipse.ui.views.properties.IPropertySource;
|
||||
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
|
||||
public class AdapterFactory implements IAdapterFactory {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Object getAdapter(Object adaptableObject, Class adapterType) {
|
||||
if (adapterType == IPropertySource.class)
|
||||
return new ITransactionPropertySource((ITransaction) adaptableObject);
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
@Override
|
||||
public Class[] getAdapterList() {
|
||||
return new Class[]{IPropertySource.class};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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.ITransaction;
|
||||
|
||||
public class ITransactionPropertySource implements IPropertySource {
|
||||
|
||||
private ITransaction iTransaction;
|
||||
|
||||
public final static String PROPERTY_ID = "ID";
|
||||
public final static String PROPERTY_BEGINTIME = "BEGINTIME";
|
||||
public final static String PROPERTY_ENDTIME = "ENDTIME";
|
||||
public final static String PROPERTY_NAME = "NAME";
|
||||
|
||||
protected IPropertyDescriptor[] propertyDescriptors;
|
||||
|
||||
public ITransactionPropertySource(ITransaction 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,99 @@
|
||||
package com.minres.scviewer.ui.swt;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.ui.TxEditorPlugin;
|
||||
|
||||
public class Ruler extends Composite {
|
||||
|
||||
static final int height = 20;
|
||||
static final int rulerTickMinor = 10;
|
||||
static final int rulerTickMajor = 100;
|
||||
|
||||
private int length;
|
||||
private int start;
|
||||
|
||||
private TxEditorPlugin plugin;
|
||||
private Color headerBgColor;
|
||||
private Color headerFgColor;
|
||||
|
||||
Ruler(Composite parent, int style, int lenght) {
|
||||
super(parent, style | SWT.DOUBLE_BUFFERED);
|
||||
this.length=lenght;
|
||||
headerBgColor=getDisplay().getSystemColor(SWT.COLOR_WHITE);
|
||||
headerFgColor=getDisplay().getSystemColor(SWT.COLOR_BLACK);
|
||||
plugin=TxEditorPlugin.getDefault();
|
||||
if(plugin!=null){
|
||||
headerBgColor=plugin.getColor(TxEditorPlugin.headerBgColor);
|
||||
headerFgColor=plugin.getColor(TxEditorPlugin.headerFgColor);
|
||||
}
|
||||
addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
Ruler.this.widgetDisposed(e);
|
||||
}
|
||||
});
|
||||
addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent e) {
|
||||
Ruler.this.paintControl(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public int getLength() {
|
||||
return length;
|
||||
}
|
||||
|
||||
public void setLength(int length) {
|
||||
this.length = length;
|
||||
layout(true);
|
||||
redraw();
|
||||
}
|
||||
|
||||
protected void widgetDisposed(DisposeEvent e) {
|
||||
}
|
||||
|
||||
void paintControl(PaintEvent e) {
|
||||
GC gc = e.gc;
|
||||
int startMinorIncr = start;
|
||||
int modulo = start % rulerTickMinor;
|
||||
startMinorIncr+=rulerTickMinor-modulo;
|
||||
int bottom=height - 2;
|
||||
int end=start+e.width;
|
||||
|
||||
gc.setBackground(getDisplay().getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
|
||||
gc.fillRectangle(new Rectangle(0, 0, e.width, height));
|
||||
gc.setBackground(headerBgColor);
|
||||
gc.fillRectangle(new Rectangle(0, 0, e.width, height - 1));
|
||||
gc.setForeground(headerFgColor);
|
||||
gc.drawLine(0, bottom, e.width, bottom);
|
||||
|
||||
for (int tick = startMinorIncr; tick < end; tick += rulerTickMinor) {
|
||||
int x0 = tick-start;
|
||||
if ((tick % rulerTickMajor) == 0) {
|
||||
gc.drawLine(x0, 10, x0, bottom);
|
||||
gc.drawText(Integer.toString(tick), x0, 0);
|
||||
} else {
|
||||
gc.drawLine(x0, 15, x0, bottom);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point computeSize(int wHint, int hHint, boolean changed) {
|
||||
return new Point(0, height);
|
||||
}
|
||||
|
||||
public void setStartPoint(int start) {
|
||||
this.start=start;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
203
com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java
Normal file
203
com.minres.scviewer.ui/src/com/minres/scviewer/ui/swt/Track.java
Normal file
@@ -0,0 +1,203 @@
|
||||
package com.minres.scviewer.ui.swt;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Layout;
|
||||
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.ui.TxEditorPlugin;
|
||||
|
||||
public class Track extends Composite implements MouseListener {
|
||||
|
||||
static final int trackHeight = 50;
|
||||
static final int trackInset = 2;
|
||||
static final int txHeight = trackHeight - 2 * trackInset;
|
||||
|
||||
static double zoomFactor = EventTime.NS;
|
||||
private Color lineColor;
|
||||
private Color trackBgColor;
|
||||
|
||||
private ITransaction highlightedTx=null;
|
||||
|
||||
private HashMap<ITransaction, Transaction> transactionMap = new HashMap<ITransaction, Transaction>();
|
||||
|
||||
class TrackLayoutData {
|
||||
protected int x, y;
|
||||
TrackLayoutData(int x, int y){
|
||||
this.x=x;
|
||||
this.y=y;
|
||||
}
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class TrackLayout extends Layout {
|
||||
Point extent; // the cached sizes
|
||||
|
||||
protected Point computeSize(Composite composite, int wHint, int hHint, boolean changed) {
|
||||
if (changed || extent == null) {
|
||||
extent=new Point(0, 0);
|
||||
for(Control child:composite.getChildren()){
|
||||
Point cExtent = child.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
|
||||
TrackLayoutData dat = (TrackLayoutData) child.getLayoutData();
|
||||
extent.x=Math.max(extent.x, dat.x+cExtent.x);
|
||||
extent.y=Math.max(extent.y, dat.y+cExtent.y);
|
||||
}
|
||||
}
|
||||
return extent;
|
||||
}
|
||||
|
||||
protected void layout(Composite composite, boolean changed) {
|
||||
if(extent==null){
|
||||
extent=new Point(0, 0);
|
||||
changed=true;
|
||||
}
|
||||
for(Control child:composite.getChildren()){
|
||||
Point cExtent = child.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
|
||||
TrackLayoutData dat = (TrackLayoutData) child.getLayoutData();
|
||||
if(changed){
|
||||
extent.x=Math.max(extent.x, dat.x+cExtent.x);
|
||||
extent.y=Math.max(extent.y, dat.y+cExtent.y);
|
||||
}
|
||||
child.setBounds(dat.x, dat.y, cExtent.x, cExtent.y);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Track(Composite parent, int style) {
|
||||
super(parent, style);
|
||||
setLayout(new TrackLayout());
|
||||
addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
Track.this.widgetDisposed(e);
|
||||
}
|
||||
});
|
||||
addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent e) {
|
||||
Track.this.paintControl(e);
|
||||
}
|
||||
});
|
||||
TxEditorPlugin plugin=TxEditorPlugin.getDefault();
|
||||
lineColor=plugin.getColor(TxEditorPlugin.lineColor);
|
||||
trackBgColor=plugin.getColor(TxEditorPlugin.trackBgLightColor);
|
||||
}
|
||||
|
||||
|
||||
protected void widgetDisposed(DisposeEvent e) {
|
||||
}
|
||||
|
||||
void paintControl(PaintEvent e) {
|
||||
GC gc = e.gc;
|
||||
gc.setForeground(lineColor);
|
||||
gc.setFillRule(SWT.FILL_EVEN_ODD);
|
||||
gc.setBackground(trackBgColor);
|
||||
gc.setLineWidth(1);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
gc.fillRectangle(new Rectangle(e.x, e.y, e.width, e.height));
|
||||
for(int offset=e.y+trackHeight/2; offset<e.height; offset+=trackHeight)
|
||||
gc.drawLine(e.x, offset, e.x+e.width, offset);
|
||||
}
|
||||
|
||||
|
||||
public void setTransactions(List<ITransaction> transactions) {
|
||||
Vector<ITransaction> rowendtime = new Vector<ITransaction>();
|
||||
for (ITransaction tx : transactions) {
|
||||
int rowIdx = 0;
|
||||
for (ITransaction lastTx : rowendtime) {
|
||||
if((lastTx.getEndTime().getValue()-lastTx.getBeginTime().getValue())>0){
|
||||
if (lastTx.getEndTime().compareTo(tx.getBeginTime())<=0 )
|
||||
break;
|
||||
} else {
|
||||
if (lastTx.getEndTime().compareTo(tx.getBeginTime())<0 )
|
||||
break;
|
||||
}
|
||||
rowIdx++;
|
||||
}
|
||||
if (rowendtime.size() <= rowIdx) {
|
||||
rowendtime.add(tx);
|
||||
} else {
|
||||
rowendtime.set(rowIdx, tx);
|
||||
}
|
||||
int width = (int) ((tx.getEndTime().getValue()-tx.getBeginTime().getValue())/zoomFactor);
|
||||
if(width==0) width=1;
|
||||
Transaction t = new Transaction(this, SWT.NONE, width);
|
||||
t.setLayoutData(new Track.TrackLayoutData((int) (tx.getBeginTime().getValue()/zoomFactor), rowIdx*trackHeight));
|
||||
t.setData(tx);
|
||||
t.addMouseListener(this);
|
||||
transactionMap.put(tx, t);
|
||||
}
|
||||
layout(true,true);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
Event event = new Event();
|
||||
event.type = SWT.MouseDoubleClick;
|
||||
event.display=e.display;
|
||||
event.data = e.widget;
|
||||
event.button=e.button;
|
||||
event.time=e.time;
|
||||
this.notifyListeners(SWT.MouseDoubleClick, event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseDown(MouseEvent e) {
|
||||
Event event = new Event();
|
||||
event.type = SWT.MouseDown;
|
||||
event.display=e.display;
|
||||
event.data = e.widget;
|
||||
event.button=e.button;
|
||||
event.time=e.time;
|
||||
this.notifyListeners(SWT.MouseDown, event);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e) {
|
||||
Event event = new Event();
|
||||
event.type = SWT.MouseUp;
|
||||
event.display=e.display;
|
||||
event.data = e.widget;
|
||||
event.button=e.button;
|
||||
event.time=e.time;
|
||||
this.notifyListeners(SWT.MouseUp, event);
|
||||
}
|
||||
|
||||
public Transaction highlightTransaction(ITransaction tx){
|
||||
if(highlightedTx!=null){
|
||||
transactionMap.get(highlightedTx).highlight(false);
|
||||
highlightedTx=null;
|
||||
}
|
||||
if(tx!=null && transactionMap.containsKey(tx)){
|
||||
Transaction trans = transactionMap.get(tx);
|
||||
trans.highlight(true);
|
||||
highlightedTx=tx;
|
||||
return trans;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package com.minres.scviewer.ui.swt;
|
||||
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.DisposeEvent;
|
||||
import org.eclipse.swt.events.DisposeListener;
|
||||
import org.eclipse.swt.events.PaintEvent;
|
||||
import org.eclipse.swt.events.PaintListener;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.ui.TxEditorPlugin;
|
||||
|
||||
public class Transaction extends Composite {
|
||||
|
||||
public static int height = 50;
|
||||
public static Color lineColor;
|
||||
public static Color txBgColor;
|
||||
public static Color highliteLineColor;
|
||||
public static Color txHighliteBgColor;
|
||||
private int length;
|
||||
private boolean highlighted=false;
|
||||
|
||||
Transaction(Composite parent, int style, int lenght) {
|
||||
super(parent, style);
|
||||
this.length=lenght;
|
||||
addDisposeListener(new DisposeListener() {
|
||||
public void widgetDisposed(DisposeEvent e) {
|
||||
Transaction.this.widgetDisposed(e);
|
||||
}
|
||||
});
|
||||
addPaintListener(new PaintListener() {
|
||||
public void paintControl(PaintEvent e) {
|
||||
Transaction.this.paintControl(e);
|
||||
}
|
||||
});
|
||||
TxEditorPlugin plugin=TxEditorPlugin.getDefault();
|
||||
lineColor=plugin.getColor(TxEditorPlugin.lineColor);
|
||||
txBgColor=plugin.getColor(TxEditorPlugin.txBgColor);
|
||||
highliteLineColor=plugin.getColor(TxEditorPlugin.highliteLineColor);
|
||||
txHighliteBgColor=plugin.getColor(TxEditorPlugin.txHighliteBgColor);
|
||||
}
|
||||
|
||||
protected void widgetDisposed(DisposeEvent e) {
|
||||
}
|
||||
|
||||
void paintControl(PaintEvent e) {
|
||||
GC gc = e.gc;
|
||||
gc.setForeground(highlighted?highliteLineColor:lineColor);
|
||||
gc.setFillRule(SWT.FILL_EVEN_ODD);
|
||||
gc.setBackground(highlighted?txHighliteBgColor:txBgColor);
|
||||
gc.setLineWidth(1);
|
||||
gc.setLineStyle(SWT.LINE_SOLID);
|
||||
Rectangle bb = new Rectangle(0, 0, length-1, height-1);
|
||||
if(bb.width<8){
|
||||
gc.fillRectangle(bb);
|
||||
gc.drawRectangle(bb);
|
||||
} else {
|
||||
gc.fillRoundRectangle(bb.x, bb.y, bb.width, bb.height, 4, 4);
|
||||
gc.drawRoundRectangle(bb.x, bb.y, bb.width, bb.height, 4, 4);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point computeSize(int wHint, int hHint, boolean changed) {
|
||||
return new Point(length, height);
|
||||
}
|
||||
|
||||
public void highlight(boolean highlight) {
|
||||
highlighted=highlight;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,390 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.ui.swt;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.ISelectionProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.custom.SashForm;
|
||||
import org.eclipse.swt.custom.ScrolledComposite;
|
||||
import org.eclipse.swt.events.ControlAdapter;
|
||||
import org.eclipse.swt.events.ControlEvent;
|
||||
import org.eclipse.swt.events.MouseEvent;
|
||||
import org.eclipse.swt.events.MouseListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.layout.FillLayout;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.layout.RowData;
|
||||
import org.eclipse.swt.layout.RowLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.ScrollBar;
|
||||
import org.eclipse.wb.swt.SWTResourceManager;
|
||||
|
||||
import swing2swt.layout.BorderLayout;
|
||||
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
|
||||
public class TxDisplay implements PropertyChangeListener, ISelectionProvider, MouseListener{
|
||||
|
||||
private ListenerList listeners = new ListenerList();
|
||||
private ITrStream currentStreamSelection;
|
||||
private ITransaction currentSelection;
|
||||
private ScrolledComposite valueListScrolled;
|
||||
private ScrolledComposite nameListScrolled;
|
||||
private Composite nameList;
|
||||
private Composite valueList;
|
||||
private ScrolledComposite trackListScrolled;
|
||||
private Composite trackList;
|
||||
private Composite top;
|
||||
private ArrayList<ITrStream> streams=new ArrayList<ITrStream>();
|
||||
private Composite trackPane;
|
||||
private Ruler ruler;
|
||||
private HashMap<ITrStream, Track> trackMap = new HashMap<ITrStream, Track>();
|
||||
|
||||
public TxDisplay(Composite parent) {
|
||||
top = new Composite(parent, SWT.NONE);
|
||||
top.setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
|
||||
SashForm topSash = new SashForm(top, SWT.SMOOTH);
|
||||
topSash.setBackground(topSash.getDisplay().getSystemColor( SWT.COLOR_GRAY));
|
||||
|
||||
Composite composite = new Composite(topSash, SWT.NONE);
|
||||
composite.setLayout(new FillLayout(SWT.HORIZONTAL));
|
||||
|
||||
SashForm leftSash = new SashForm(composite, SWT.SMOOTH);
|
||||
leftSash.setBackground(leftSash.getDisplay().getSystemColor( SWT.COLOR_GRAY));
|
||||
// leftSash.addControlListener(new ControlAdapter() {
|
||||
// public void controlResized(ControlEvent e) {
|
||||
// recalculateNameBounds();
|
||||
// recalculateValueBounds();
|
||||
// }
|
||||
// });
|
||||
Composite namePane = createTextPane(leftSash, "Name");
|
||||
namePane.setBackground(namePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND));
|
||||
namePane.addControlListener(new ControlAdapter() {
|
||||
public void controlResized(ControlEvent e) {
|
||||
recalculateNameBounds();
|
||||
}
|
||||
});
|
||||
|
||||
nameListScrolled = new ScrolledComposite(namePane, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
nameListScrolled.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));
|
||||
nameListScrolled.setExpandHorizontal(true);
|
||||
nameListScrolled.setExpandVertical(true);
|
||||
nameList = new Composite(nameListScrolled, SWT.NONE);
|
||||
nameList.setLayout(createScrolledLayoutData(false));
|
||||
|
||||
nameListScrolled.setContent(nameList);
|
||||
|
||||
Composite valuePane = createTextPane(leftSash, "Value");
|
||||
valuePane.setBackground(valuePane.getDisplay().getSystemColor( SWT.COLOR_WIDGET_BACKGROUND));
|
||||
valuePane.addControlListener(new ControlAdapter() {
|
||||
public void controlResized(ControlEvent e) {
|
||||
recalculateValueBounds();
|
||||
}
|
||||
});
|
||||
valueListScrolled = new ScrolledComposite(valuePane, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
valueListScrolled.setLayoutData(new GridData(SWT.LEFT, SWT.TOP, true, true, 1, 1));
|
||||
valueListScrolled.setExpandHorizontal(true);
|
||||
valueListScrolled.setExpandVertical(true);
|
||||
valueList = new Composite(valueListScrolled, SWT.NONE);
|
||||
valueList.setLayout(createScrolledLayoutData(true));
|
||||
valueListScrolled.setContent(valueList);
|
||||
|
||||
|
||||
trackPane = new Composite(topSash, SWT.NONE);
|
||||
trackPane.setLayout(new BorderLayout(0, 0));
|
||||
ruler = new Ruler(trackPane, SWT.NONE, 0);
|
||||
ruler.setLayoutData(BorderLayout.NORTH);
|
||||
|
||||
trackListScrolled = new ScrolledComposite(trackPane, SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
trackListScrolled.setExpandVertical(true);
|
||||
trackListScrolled.setExpandHorizontal(true);
|
||||
trackList = new Composite(trackListScrolled, SWT.NONE);
|
||||
trackList.setLayout(createScrolledLayoutData(false));
|
||||
trackListScrolled.setContent(trackList);
|
||||
nameListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int y = ((ScrollBar) e.widget).getSelection();
|
||||
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y);
|
||||
trackListScrolled.setOrigin(trackListScrolled.getOrigin().x, y);
|
||||
}
|
||||
});
|
||||
valueListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int y = ((ScrollBar) e.widget).getSelection();
|
||||
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y);
|
||||
trackListScrolled.setOrigin(trackListScrolled.getOrigin().x, y);
|
||||
}
|
||||
});
|
||||
trackListScrolled.getVerticalBar().addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int y = ((ScrollBar) e.widget).getSelection();
|
||||
nameListScrolled.setOrigin(nameListScrolled.getOrigin().x, y);
|
||||
valueListScrolled.setOrigin(valueListScrolled.getOrigin().x, y);
|
||||
}
|
||||
});
|
||||
trackListScrolled.getHorizontalBar().addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
int x = ((ScrollBar) e.widget).getSelection();
|
||||
ruler.setStartPoint(x);
|
||||
}
|
||||
});
|
||||
|
||||
topSash.setWeights(new int[] {30, 70});
|
||||
leftSash.setWeights(new int[] {75, 25});
|
||||
|
||||
top.layout(true, true);
|
||||
streamListChanged();
|
||||
}
|
||||
|
||||
protected RowLayout createScrolledLayoutData(boolean center) {
|
||||
RowLayout nameListLayout = new RowLayout(SWT.VERTICAL);
|
||||
nameListLayout.spacing = 4;
|
||||
nameListLayout.marginTop = 0;
|
||||
nameListLayout.marginRight = 0;
|
||||
nameListLayout.marginLeft = 0;
|
||||
nameListLayout.marginBottom = 0;
|
||||
nameListLayout.fill = true;
|
||||
nameListLayout.wrap = false;
|
||||
nameListLayout.center=center;
|
||||
return nameListLayout;
|
||||
}
|
||||
|
||||
private Composite createTextPane(SashForm leftSash, String text) {
|
||||
Composite namePane = new Composite(leftSash, SWT.NONE);
|
||||
GridLayout gl_namePane = new GridLayout(1, false);
|
||||
gl_namePane.verticalSpacing = 0;
|
||||
gl_namePane.marginWidth = 0;
|
||||
gl_namePane.horizontalSpacing = 0;
|
||||
gl_namePane.marginHeight = 0;
|
||||
namePane.setLayout(gl_namePane);
|
||||
|
||||
CLabel nameLabel = new CLabel(namePane, SWT.NONE);
|
||||
GridData gd_nameLabel = new GridData(SWT.CENTER, SWT.CENTER, true, false, 1, 1);
|
||||
gd_nameLabel.heightHint = Ruler.height-2;
|
||||
nameLabel.setLayoutData(gd_nameLabel);
|
||||
nameLabel.setText(text);
|
||||
|
||||
Label nameSep = new Label(namePane, SWT.SEPARATOR | SWT.HORIZONTAL);
|
||||
nameSep.setBackground(SWTResourceManager.getColor(SWT.COLOR_DARK_GRAY));
|
||||
nameSep.setForeground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
|
||||
GridData gd_nameSep = new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1);
|
||||
gd_nameSep.heightHint = 2;
|
||||
nameSep.setLayoutData(gd_nameSep);
|
||||
return namePane;
|
||||
}
|
||||
|
||||
public void streamListChanged() {
|
||||
LinkedList<ITrStream>toAdd = new LinkedList<ITrStream>();
|
||||
toAdd.addAll(streams);
|
||||
for(Control child:trackList.getChildren()){
|
||||
Track track = (Track) child;
|
||||
Control c = (Control)track.getData("NAMEWIDGET");
|
||||
ITrStream stream=(ITrStream) track.getData("STREAM");
|
||||
if(!streams.contains(stream)){
|
||||
track.setVisible(false);
|
||||
c.setVisible(false);
|
||||
}else{
|
||||
toAdd.remove(stream);
|
||||
track.setVisible(true);
|
||||
c.setVisible(true);
|
||||
}
|
||||
}
|
||||
for(ITrStream stream: toAdd){
|
||||
Track track = new Track(trackList,SWT.NONE);
|
||||
track.setTransactions(stream.getTransactions());
|
||||
track.setData("STREAM", stream);
|
||||
track.addMouseListener(this);
|
||||
Point trackSize = track.computeSize(SWT.DEFAULT,SWT.DEFAULT);
|
||||
|
||||
Label trackName = new Label(nameList, SWT.NONE);
|
||||
trackName.setText(stream.getFullName());
|
||||
RowData trackNamelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||
trackName.setLayoutData(trackNamelayoutData);
|
||||
track.setData("NAMEWIDGET", trackName);
|
||||
|
||||
Label trackValue = new Label(valueList, SWT.NONE);
|
||||
trackValue.setText("-");
|
||||
RowData trackValuelayoutData = new RowData(SWT.DEFAULT, trackSize.y);
|
||||
trackValue.setLayoutData(trackValuelayoutData);
|
||||
track.setData("VALUEWIDGET", trackValue);
|
||||
trackMap.put(stream, track);
|
||||
}
|
||||
recalculateNameBounds();
|
||||
recalculateValueBounds();
|
||||
Point trackSize=trackList.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
trackListScrolled.setMinSize(trackSize);
|
||||
top.layout(true, true);
|
||||
}
|
||||
|
||||
protected void recalculateValueBounds() {
|
||||
if(streams.size()>0){
|
||||
Rectangle bounds = valueListScrolled.getParent().getBounds();
|
||||
Point size = valueList.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
// System.out.println("Value calc: "+bounds+" / "+size);
|
||||
int corr = (int) (2.35*valueListScrolled.getHorizontalBar().getSize().y);
|
||||
valueListScrolled.setMinSize(Math.max(bounds.width, size.x), Math.max(bounds.height-corr, size.y));
|
||||
valueListScrolled.setAlwaysShowScrollBars(true);
|
||||
valueListScrolled.getVerticalBar().setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
protected void recalculateNameBounds() {
|
||||
if(streams.size()>0){
|
||||
Rectangle bounds = nameListScrolled.getParent().getBounds();
|
||||
Point size = nameList.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
// System.out.println("Name calc: "+bounds+" / "+size);
|
||||
int corr = (int) (2.35*valueListScrolled.getHorizontalBar().getSize().y);
|
||||
nameListScrolled.setMinSize(Math.max(bounds.width, size.x), Math.max(bounds.height-corr, size.y));
|
||||
nameListScrolled.setAlwaysShowScrollBars(true);
|
||||
nameListScrolled.getVerticalBar().setVisible(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent pce) {
|
||||
currentSelection=null;
|
||||
ITrStream str = (ITrStream)pce.getNewValue();
|
||||
if(str instanceof ITrStream)
|
||||
currentStreamSelection=(ITrStream)str;
|
||||
if(currentStreamSelection!=null)
|
||||
setSelection(getSelection());
|
||||
else
|
||||
setSelection(StructuredSelection.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelectionChangedListener(ISelectionChangedListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ISelection getSelection() {
|
||||
if(currentSelection!=null)
|
||||
return new StructuredSelection(currentSelection);
|
||||
else if(currentStreamSelection!=null)
|
||||
return new StructuredSelection(currentStreamSelection);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeSelectionChangedListener(ISelectionChangedListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSelection(ISelection selection) {
|
||||
if(selection instanceof IStructuredSelection){
|
||||
Object sel =((IStructuredSelection)selection).getFirstElement();
|
||||
if(sel instanceof ITransaction && currentSelection!=sel){
|
||||
if(currentSelection!=null){
|
||||
ITrStream stream = currentSelection.getGenerator().getStream();
|
||||
if(trackMap.containsKey(stream)) trackMap.get(stream).highlightTransaction(null);
|
||||
}
|
||||
currentSelection=(ITransaction) sel;
|
||||
ITrStream stream = currentSelection.getGenerator().getStream();
|
||||
if(trackMap.containsKey(stream)){
|
||||
Transaction trans = trackMap.get(stream).highlightTransaction(currentSelection);
|
||||
trackListScrolled.showControl(trans);
|
||||
}
|
||||
Object[] list = listeners.getListeners();
|
||||
for (int i = 0; i < list.length; i++) {
|
||||
((ISelectionChangedListener) list[i]).selectionChanged(new SelectionChangedEvent(this, selection));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDoubleClick(MouseEvent e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseDown(MouseEvent e) {
|
||||
if(e.data!=null){
|
||||
StructuredSelection sel = new StructuredSelection(((Transaction)e.data).getData());
|
||||
setSelection(sel);
|
||||
}else{
|
||||
StructuredSelection sel = new StructuredSelection(new Object[]{ ((Track)e.widget).getData()});
|
||||
setSelection(sel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(MouseEvent e) {
|
||||
}
|
||||
|
||||
public boolean addStream(ITrStream paramE){
|
||||
boolean res = streams.add(paramE);
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean addAllStreams(ITrStream[] streams) {
|
||||
boolean res = this.streams.addAll(Arrays.asList(streams));
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean addAllStreams(Collection<? extends ITrStream> paramCollection){
|
||||
boolean res = streams.addAll(paramCollection);
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean removeStream(ITrStream paramObject){
|
||||
boolean res = streams.remove(paramObject);
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
public boolean removeAllStreams(Collection<?> paramCollection){
|
||||
boolean res = streams.removeAll(paramCollection);
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
public List<ITrStream> getStreamList(){
|
||||
return Collections.unmodifiableList(streams);
|
||||
}
|
||||
|
||||
public boolean removeAllStreams(ITrStream[] streams) {
|
||||
boolean res = this.streams.removeAll(Arrays.asList(streams));
|
||||
streamListChanged();
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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,213 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.ui.views;
|
||||
|
||||
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.IActionBars;
|
||||
import org.eclipse.ui.ISelectionListener;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.actions.ActionFactory;
|
||||
import org.eclipse.ui.part.IPageSite;
|
||||
import org.eclipse.ui.views.contentoutline.ContentOutline;
|
||||
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
|
||||
|
||||
import com.minres.scviewer.database.ITrHierNode;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
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 {
|
||||
|
||||
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;
|
||||
|
||||
public TxOutlinePage(TxEditorPart editor) {
|
||||
this.editor = editor;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite
|
||||
* )
|
||||
*/
|
||||
public void createControl(Composite parent) {
|
||||
super.createControl(parent);
|
||||
TreeViewer contentOutlineViewer = getTreeViewer();
|
||||
contentOutlineViewer.addSelectionChangedListener(this);
|
||||
// Set up the tree viewer
|
||||
contentOutlineViewer.setContentProvider(new TxDbTreeContentProvider());
|
||||
contentOutlineViewer.setLabelProvider(new TxDbTreeLabelProvider());
|
||||
contentOutlineViewer.setInput(editor.getDatabase());
|
||||
// initialize context menu depending on the the selectec item
|
||||
MenuManager menuMgr = new MenuManager();
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
fillContextMenu(manager);
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(contentOutlineViewer.getControl());
|
||||
contentOutlineViewer.getTree().setMenu(menu);
|
||||
getSite().registerContextMenu("com.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);
|
||||
}
|
||||
|
||||
/*
|
||||
* (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 ITrStream, 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 ITrStream,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 ITrHierNode) {
|
||||
fireSelectionChanged(new StructuredSelection((ITrHierNode) 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 ITrStream){
|
||||
if(remove)
|
||||
editor.removeStreamFromList((ITrStream) obj);
|
||||
else
|
||||
editor.addStreamToList((ITrStream) obj);
|
||||
} else if(obj instanceof ITrHierNode){
|
||||
LinkedList<ITrHierNode> queue = new LinkedList<ITrHierNode>();
|
||||
LinkedList<ITrStream> streams = new LinkedList<ITrStream>();
|
||||
queue.add((ITrHierNode)obj);
|
||||
while(queue.size()>0){
|
||||
ITrHierNode n = queue.poll();
|
||||
if(n instanceof ITrStream) streams.add((ITrStream) n);
|
||||
queue.addAll(n.getChildNodes());
|
||||
}
|
||||
if(remove)
|
||||
editor.removeStreamsFromList(streams.toArray(new ITrStream[]{}));
|
||||
else
|
||||
editor.addStreamsToList(streams.toArray(new ITrStream[]{}));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
action.setText(text);
|
||||
action.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(imgDescriptor));
|
||||
if(selection.getFirstElement() instanceof ITrStream && editor.getStreamList().contains(selection.getFirstElement()))
|
||||
action.setEnabled(false);
|
||||
else
|
||||
action.setEnabled(true);
|
||||
return action;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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.ITrDb;
|
||||
import com.minres.scviewer.database.ITrHierNode;
|
||||
|
||||
public class TxDbTreeContentProvider implements ITreeContentProvider {
|
||||
|
||||
private ITrDb database;
|
||||
|
||||
@Override
|
||||
public void dispose() { }
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
database=(ITrDb)newInput;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return database.getChildNodes().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if(parentElement instanceof ITrHierNode){
|
||||
return ((ITrHierNode)parentElement).getChildNodes().toArray();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object element) {
|
||||
Object[] obj = getChildren(element);
|
||||
return obj == null ? false : obj.length > 0;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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.ITrDb;
|
||||
import com.minres.scviewer.database.ITrHierNode;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
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 folder;
|
||||
|
||||
|
||||
public TxDbTreeLabelProvider() {
|
||||
super();
|
||||
database=TxEditorPlugin.createImage("database");
|
||||
stream=TxEditorPlugin.createImage("stream");
|
||||
folder=TxEditorPlugin.createImage("folder");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if(database!=null) database.dispose();
|
||||
if(stream!=null) stream.dispose();
|
||||
if(folder!=null) folder.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if(element instanceof ITrDb){
|
||||
return database;
|
||||
}else if(element instanceof ITrStream){
|
||||
return stream;
|
||||
}else if(element instanceof ITrHierNode){
|
||||
return folder;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
return ((ITrHierNode)element).getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,269 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - 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.ITrAttribute;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
|
||||
public class AttributeProperty extends AbstractPropertySection implements ISelectionProvider {
|
||||
|
||||
private final String[] titles = { "Location", "Name", "Type", "Value" };
|
||||
|
||||
private ListenerList listeners = new ListenerList();
|
||||
|
||||
private ITransaction 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<ITrAttribute>> hier = new TreeMap<String, List<ITrAttribute>>();
|
||||
HashMap<ITrAttribute, String> parents = new HashMap<ITrAttribute, String>();
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (newInput instanceof ITransaction) {
|
||||
List<ITrAttribute> attributes = ((ITransaction)newInput).getAttributes();
|
||||
hier.clear();
|
||||
parents.clear();
|
||||
|
||||
String location="Begin";
|
||||
List<ITrAttribute> childs=new LinkedList<ITrAttribute>();
|
||||
for (ITrAttribute 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<ITrAttribute>();
|
||||
for (ITrAttribute 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<ITrAttribute>();
|
||||
for (ITrAttribute 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 ITrAttribute)
|
||||
return parents.get(element);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return hier.keySet().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement instanceof String)
|
||||
return hier.get((String) parentElement).toArray();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
});
|
||||
treeViewer.setLabelProvider(new ITableLabelProvider() {
|
||||
@Override
|
||||
public void removeListener(ILabelProviderListener listener) { }
|
||||
|
||||
@Override
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() { }
|
||||
|
||||
@Override
|
||||
public void addListener(ILabelProviderListener listener) { }
|
||||
|
||||
@Override
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
if (columnIndex == 0 && element instanceof String)
|
||||
return element.toString();
|
||||
else if(element instanceof ITrAttribute){
|
||||
ITrAttribute attr = (ITrAttribute)element;
|
||||
if (columnIndex == 1 )
|
||||
return attr.getName();
|
||||
else if (columnIndex == 2 )
|
||||
return attr.getDataType().name();
|
||||
else if (columnIndex == 3){
|
||||
if("UNSIGNED".equals(attr.getType()) && (attr.getName().contains("addr")||attr.getName().contains("data")))
|
||||
try {
|
||||
return "0x"+Long.toHexString(Long.parseLong(attr.getValue().toString()));
|
||||
} catch(NumberFormatException e) {
|
||||
}
|
||||
return attr.getValue().toString();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
|
||||
MenuManager menuMgr = new MenuManager("#PopUp"); //$NON-NLS-1$
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager mgr) {
|
||||
ISelection selection = treeViewer.getSelection();
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
System.out.println(((IStructuredSelection)selection).getFirstElement().toString());
|
||||
}
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(treeViewer.getControl());
|
||||
treeViewer.getControl().setMenu(menu);
|
||||
aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
|
||||
}
|
||||
|
||||
public void setInput(IWorkbenchPart part, ISelection selection) {
|
||||
super.setInput(part, selection);
|
||||
currentSelection = null;
|
||||
Assert.isTrue(selection instanceof IStructuredSelection);
|
||||
Object input = ((IStructuredSelection) selection).getFirstElement();
|
||||
Assert.isTrue(input instanceof ITransaction);
|
||||
iTr = (ITransaction) 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,295 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2012 IT Just working.
|
||||
* 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:
|
||||
* IT Just working - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.ui.views.sections;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import org.eclipse.core.runtime.Assert;
|
||||
import org.eclipse.core.runtime.ListenerList;
|
||||
import org.eclipse.jface.action.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.ITrRelation;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class RelatedProperty extends AbstractPropertySection implements ISelectionProvider, ISelectionChangedListener {
|
||||
|
||||
private final String[] titles = { "Relation type", "Relation Name", "Tx Id" };
|
||||
|
||||
private ListenerList listeners = new ListenerList();
|
||||
|
||||
private ITransaction 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<ITrRelation>> hier = new TreeMap<String, Collection<ITrRelation>>();
|
||||
HashMap<ITrRelation, String> parents = new HashMap<ITrRelation, String>();
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
if (newInput instanceof ITransaction) {
|
||||
hier.clear();
|
||||
parents.clear();
|
||||
String relName = "incoming";
|
||||
Collection<ITrRelation> relSet = ((ITransaction)newInput).getIncomingRelations();
|
||||
if (relSet != null && relSet.size() > 0) {
|
||||
hier.put(relName, relSet);
|
||||
for (ITrRelation rel : relSet)
|
||||
parents.put(rel, relName);
|
||||
}
|
||||
relName = "outgoing";
|
||||
relSet = ((ITransaction)newInput).getOutgoingRelations();
|
||||
if (relSet != null && relSet.size() > 0) {
|
||||
hier.put(relName, relSet);
|
||||
for (ITrRelation 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 ITransaction)
|
||||
return parents.get(element);
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
return hier.keySet().toArray();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
if (parentElement instanceof 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 ITrRelation)
|
||||
return ((ITrRelation) element).getRelationType().getName();
|
||||
else if (columnIndex == 2 && element instanceof ITrRelation){
|
||||
ITrRelation rel = (ITrRelation) element;
|
||||
if(rel.getTarget()==iTr)
|
||||
return ((ITrRelation) element).getSource().getId().toString();
|
||||
else
|
||||
return ((ITrRelation) 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 ITransaction transaction) {
|
||||
Action action = new Action() {
|
||||
public void run() {
|
||||
if(obj instanceof ITrRelation){
|
||||
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
|
||||
ITransaction targetTransaction = ((ITrRelation)obj).getSource()==transaction?
|
||||
((ITrRelation)obj).getTarget():((ITrRelation)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 ITransaction);
|
||||
iTr = (ITransaction) 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