Initial version of E4 based SC Viewer application
This commit is contained in:
@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014 TwelveTone LLC and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Steven Spungin <steven@spungin.tv> - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.ui.workbench.lifecycle.PostContextCreate;
|
||||
import org.eclipse.e4.ui.workbench.lifecycle.PreSave;
|
||||
import org.eclipse.e4.ui.workbench.lifecycle.ProcessAdditions;
|
||||
import org.eclipse.e4.ui.workbench.lifecycle.ProcessRemovals;
|
||||
|
||||
/**
|
||||
* This is a stub implementation containing e4 LifeCycle annotated methods.<br />
|
||||
* There is a corresponding entry in <em>plugin.xml</em> (under the
|
||||
* <em>org.eclipse.core.runtime.products' extension point</em>) that references
|
||||
* this class.
|
||||
**/
|
||||
@SuppressWarnings("restriction")
|
||||
public class E4LifeCycle {
|
||||
|
||||
@PostContextCreate
|
||||
void postContextCreate(IEclipseContext workbenchContext) {
|
||||
}
|
||||
|
||||
@PreSave
|
||||
void preSave(IEclipseContext workbenchContext) {
|
||||
}
|
||||
|
||||
@ProcessAdditions
|
||||
void processAdditions(IEclipseContext workbenchContext) {
|
||||
}
|
||||
|
||||
@ProcessRemovals
|
||||
void processRemovals(IEclipseContext workbenchContext) {
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2013 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Lars Vogel <lars.Vogel@gmail.com> - Bug 419770
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
public class AboutHandler {
|
||||
@Execute
|
||||
public void execute(Shell shell) {
|
||||
MessageDialog.openInformation(shell, "About", "Eclipse 4 Application example.");
|
||||
}
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class DeleteWaveformHandler {
|
||||
|
||||
@CanExecute
|
||||
public Boolean canExecute(ESelectionService selectionService){
|
||||
Object o = selectionService.getSelection();
|
||||
return o instanceof IWaveform<?>;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(ESelectionService selectionService, MPart activePart) {
|
||||
Object o = activePart.getObject();
|
||||
Object sel = selectionService.getSelection();
|
||||
if(o instanceof WaveformViewerPart && sel instanceof IWaveform<?>){
|
||||
((WaveformViewerPart)o).removeStreamFromList((IWaveform<?>) sel);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,38 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class MoveWaveformHandler {
|
||||
|
||||
static final String PARAMETER_ID="com.minres.scviewer.e4.application.command.movewaveformupCommand.parameter.dir";
|
||||
|
||||
@CanExecute
|
||||
public Boolean canExecute(ESelectionService selectionService){
|
||||
Object o = selectionService.getSelection();
|
||||
return o instanceof IWaveform<?> || o instanceof ITx;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAMETER_ID) String param, EPartService partService) {
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
if(obj instanceof WaveformViewerPart){
|
||||
if("up".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveSelected(-1);
|
||||
else if("down".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveSelected(1);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.swt.GotoDirection;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class NavigateEvent {
|
||||
|
||||
final static String PARAMTER_ID="com.minres.scviewer.e4.application.command.navigateEventCommand.parameter.dir";
|
||||
|
||||
@CanExecute
|
||||
public Boolean canExecute(ESelectionService selectionService){
|
||||
Object o = selectionService.getSelection();
|
||||
return o instanceof IWaveform<?> || o instanceof ITx;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAMTER_ID) String param, EPartService partService) {
|
||||
// public void execute(EPartService partService) {
|
||||
// String param="next";
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
if(obj instanceof WaveformViewerPart){
|
||||
if("next".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveCursor(GotoDirection.NEXT);
|
||||
else if("prev".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveCursor(GotoDirection.PREV);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.swt.GotoDirection;
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class NavigateTrans {
|
||||
|
||||
final static String PARAMTER_ID="com.minres.scviewer.e4.application.command.navigateTransCommand.parameter.dir";
|
||||
|
||||
@CanExecute
|
||||
public Boolean canExecute(ESelectionService selectionService){
|
||||
Object o = selectionService.getSelection();
|
||||
return o instanceof ITx;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAMTER_ID) String param, EPartService partService) {
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
if(obj instanceof WaveformViewerPart){
|
||||
if("next".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveSelection(GotoDirection.NEXT);
|
||||
else if("prev".equalsIgnoreCase(param))
|
||||
((WaveformViewerPart)obj).moveSelection(GotoDirection.PREV);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,61 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Lars Vogel <lars.Vogel@gmail.com> - Bug 419770
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.eclipse.e4.core.contexts.IEclipseContext;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.MApplication;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
public class OpenHandler {
|
||||
|
||||
@Execute
|
||||
public void execute(Shell shell, MApplication app, EModelService modelService, EPartService partService){
|
||||
FileDialog dialog = new FileDialog(shell, SWT.MULTI);
|
||||
dialog.setFilterExtensions (new String []{"vcd", "txdb", "txlog"});
|
||||
dialog.open();
|
||||
String path = dialog.getFilterPath();
|
||||
for(String fileName: dialog.getFileNames()){
|
||||
File file = new File(path+File.separator+fileName);
|
||||
if(file.exists()){
|
||||
// MPart part = MBasicFactory.INSTANCE.createPart();
|
||||
// part.setLabel(fileName);
|
||||
// part.setContributionURI("bundleclass://com.minres.scviewer.e4.application/"+
|
||||
// WaveformViewerPart.class.getName());
|
||||
MPart part = partService .createPart("com.minres.scviewer.e4.application.partdescriptor.waveformviewer");
|
||||
part.setLabel(fileName);
|
||||
|
||||
|
||||
MPartStack partStack = (MPartStack)modelService.find("org.eclipse.editorss", app);
|
||||
partStack.getChildren().add(part);
|
||||
partService.showPart(part, PartState.ACTIVATE);
|
||||
// Object o = part.getObject();
|
||||
// if(o instanceof WaveformViewerPart)
|
||||
// ((WaveformViewerPart)o).setPartInput(file);
|
||||
IEclipseContext ctx=part.getContext();
|
||||
ctx.modify("input", file);
|
||||
ctx.declareModifiable("input");
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2013 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Lars Vogel <lars.Vogel@gmail.com> - Bug 419770
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.workbench.IWorkbench;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
|
||||
|
||||
public class QuitHandler {
|
||||
@Execute
|
||||
public void execute(IWorkbench workbench, Shell shell){
|
||||
if (MessageDialog.openConfirm(shell, "Confirmation",
|
||||
"Do you want to exit?")) {
|
||||
workbench.close();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2010 - 2013 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* IBM Corporation - initial API and implementation
|
||||
* Lars Vogel <lars.Vogel@gmail.com> - Bug 419770
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
|
||||
public class SaveHandler {
|
||||
|
||||
@CanExecute
|
||||
public boolean canExecute(EPartService partService) {
|
||||
if (partService != null) {
|
||||
return !partService.getDirtyParts().isEmpty();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(EPartService partService) {
|
||||
partService.saveAll(false);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
|
||||
public class SelectAllHandler {
|
||||
|
||||
@Execute
|
||||
public void execute() {
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
|
||||
package com.minres.scviewer.e4.application.handlers;
|
||||
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.CanExecute;
|
||||
import org.eclipse.e4.core.di.annotations.Execute;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EPartService;
|
||||
|
||||
import com.minres.scviewer.e4.application.parts.WaveformViewerPart;
|
||||
|
||||
public class ZoomHandler {
|
||||
|
||||
final static String PARAMTER_ID="com.minres.scviewer.e4.application.command.zoomcommand.parameter.level";
|
||||
|
||||
@CanExecute
|
||||
public boolean canExecute(EPartService partService) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Execute
|
||||
public void execute(@Named(PARAMTER_ID) String level, EPartService partService) {
|
||||
MPart part = partService.getActivePart();
|
||||
Object obj = part.getObject();
|
||||
if(obj instanceof WaveformViewerPart){
|
||||
WaveformViewerPart waveformViewerPart = (WaveformViewerPart) obj;
|
||||
int zoomLevel = waveformViewerPart.getZoomLevel();
|
||||
if("in".equalsIgnoreCase(level))
|
||||
waveformViewerPart.setZoomLevel(zoomLevel-1);
|
||||
else if("out".equalsIgnoreCase(level))
|
||||
waveformViewerPart.setZoomLevel(zoomLevel+1);
|
||||
else if("fit".equalsIgnoreCase(level))
|
||||
waveformViewerPart.setZoomFit();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,607 @@
|
||||
package com.minres.scviewer.e4.application.internal;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent;
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.action.IMenuListener;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.MenuManager;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.graphics.Rectangle;
|
||||
import org.eclipse.swt.widgets.Canvas;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.wb.swt.ResourceManager;
|
||||
|
||||
/**
|
||||
* The Heap Status control, which shows the heap usage statistics in the window trim.
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public class HeapStatus extends Composite {
|
||||
|
||||
private boolean armed;
|
||||
private Image gcImage;
|
||||
private Image disabledGcImage;
|
||||
private Color bgCol, usedMemCol, lowMemCol, freeMemCol, topLeftCol, bottomRightCol, sepCol, textCol, markCol, armCol;
|
||||
private Canvas button;
|
||||
private IEclipsePreferences prefStore;
|
||||
private int updateInterval;
|
||||
private boolean showMax;
|
||||
private long totalMem;
|
||||
private long prevTotalMem = -1L;
|
||||
private long prevUsedMem = -1L;
|
||||
private boolean hasChanged;
|
||||
private long usedMem;
|
||||
private long mark = -1;
|
||||
// start with 12x12
|
||||
private Rectangle imgBounds = new Rectangle(0,0,12,12);
|
||||
private long maxMem = Long.MAX_VALUE;
|
||||
private boolean maxMemKnown;
|
||||
private float lowMemThreshold = 0.05f;
|
||||
private boolean showLowMemThreshold = true;
|
||||
private boolean updateTooltip = false;
|
||||
|
||||
protected volatile boolean isInGC = false;
|
||||
|
||||
private final Runnable timer = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDisposed()) {
|
||||
updateStats();
|
||||
if (hasChanged) {
|
||||
if (updateTooltip) {
|
||||
updateToolTip();
|
||||
}
|
||||
redraw();
|
||||
hasChanged = false;
|
||||
}
|
||||
getDisplay().timerExec(updateInterval, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private final IPreferenceChangeListener prefListener = new IPreferenceChangeListener() {
|
||||
@Override
|
||||
public void preferenceChange(PreferenceChangeEvent event) {
|
||||
if (IHeapStatusConstants.PREF_UPDATE_INTERVAL.equals(event.getKey())) {
|
||||
setUpdateIntervalInMS(prefStore.getInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 100));
|
||||
}
|
||||
else if (IHeapStatusConstants.PREF_SHOW_MAX.equals(event.getKey())) {
|
||||
showMax = prefStore.getBoolean(IHeapStatusConstants.PREF_SHOW_MAX, true);
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates a new heap status control with the given parent, and using
|
||||
* the given preference store to obtain settings such as the refresh
|
||||
* interval.
|
||||
*
|
||||
* @param parent the parent composite
|
||||
* @param preferences the preference store
|
||||
*/
|
||||
public HeapStatus(Composite parent, IEclipsePreferences preferences) {
|
||||
super(parent, SWT.NONE);
|
||||
|
||||
maxMem = getMaxMem();
|
||||
maxMemKnown = maxMem != Long.MAX_VALUE;
|
||||
|
||||
this.prefStore = preferences;
|
||||
preferences.addPreferenceChangeListener(prefListener);
|
||||
|
||||
setUpdateIntervalInMS(preferences.getInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 100));
|
||||
showMax = preferences.getBoolean(IHeapStatusConstants.PREF_SHOW_MAX, true);
|
||||
|
||||
button = new Canvas(this, SWT.NONE);
|
||||
button.setToolTipText("Run Garbage Collection");
|
||||
|
||||
ImageDescriptor imageDesc = ResourceManager.getPluginImageDescriptor("com.minres.scviewer.e4.application", "icons/trash.png"); //$NON-NLS-1$
|
||||
Display display = getDisplay();
|
||||
gcImage = imageDesc.createImage();
|
||||
if (gcImage != null) {
|
||||
imgBounds = gcImage.getBounds();
|
||||
disabledGcImage = new Image(display, gcImage, SWT.IMAGE_DISABLE);
|
||||
}
|
||||
usedMemCol = display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
|
||||
lowMemCol = new Color(display, 255, 70, 70); // medium red
|
||||
freeMemCol = new Color(display, 255, 190, 125); // light orange
|
||||
bgCol = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
|
||||
sepCol = topLeftCol = armCol = display.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
|
||||
bottomRightCol = display.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
|
||||
markCol = textCol = display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
|
||||
|
||||
createContextMenu();
|
||||
|
||||
Listener listener = new Listener() {
|
||||
|
||||
@Override
|
||||
public void handleEvent(Event event) {
|
||||
switch (event.type) {
|
||||
case SWT.Dispose:
|
||||
doDispose();
|
||||
break;
|
||||
case SWT.Resize:
|
||||
Rectangle rect = getClientArea();
|
||||
button.setBounds(rect.width - imgBounds.width - 1, 1, imgBounds.width, rect.height - 2);
|
||||
break;
|
||||
case SWT.Paint:
|
||||
if (event.widget == HeapStatus.this) {
|
||||
paintComposite(event.gc);
|
||||
}
|
||||
else if (event.widget == button) {
|
||||
paintButton(event.gc);
|
||||
}
|
||||
break;
|
||||
case SWT.MouseUp:
|
||||
if (event.button == 1) {
|
||||
if (!isInGC) {
|
||||
arm(false);
|
||||
gc();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SWT.MouseDown:
|
||||
if (event.button == 1) {
|
||||
if (event.widget == HeapStatus.this) {
|
||||
setMark();
|
||||
} else if (event.widget == button) {
|
||||
if (!isInGC)
|
||||
arm(true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SWT.MouseEnter:
|
||||
HeapStatus.this.updateTooltip = true;
|
||||
updateToolTip();
|
||||
break;
|
||||
case SWT.MouseExit:
|
||||
if (event.widget == HeapStatus.this) {
|
||||
HeapStatus.this.updateTooltip = false;
|
||||
} else if (event.widget == button) {
|
||||
arm(false);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
addListener(SWT.Dispose, listener);
|
||||
addListener(SWT.MouseDown, listener);
|
||||
addListener(SWT.Paint, listener);
|
||||
addListener(SWT.Resize, listener);
|
||||
addListener(SWT.MouseEnter, listener);
|
||||
addListener(SWT.MouseExit, listener);
|
||||
button.addListener(SWT.MouseDown, listener);
|
||||
button.addListener(SWT.MouseExit, listener);
|
||||
button.addListener(SWT.MouseUp, listener);
|
||||
button.addListener(SWT.Paint, listener);
|
||||
|
||||
// make sure stats are updated before first paint
|
||||
updateStats();
|
||||
|
||||
getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDisposed()) {
|
||||
getDisplay().timerExec(updateInterval, timer);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBackground(Color color) {
|
||||
bgCol = color;
|
||||
button.redraw();
|
||||
button.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setForeground(Color color) {
|
||||
if (color == null) {
|
||||
usedMemCol = getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
|
||||
} else {
|
||||
usedMemCol = color;
|
||||
}
|
||||
|
||||
button.redraw();
|
||||
button.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getForeground() {
|
||||
if (usedMemCol != null) {
|
||||
return usedMemCol;
|
||||
}
|
||||
return getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the maximum memory limit, or Long.MAX_VALUE if the max is not known.
|
||||
*/
|
||||
private long getMaxMem() {
|
||||
long max = Long.MAX_VALUE;
|
||||
try {
|
||||
// Must use reflect to allow compilation against JCL/Foundation
|
||||
Method maxMemMethod = Runtime.class.getMethod("maxMemory", new Class[0]); //$NON-NLS-1$
|
||||
Object o = maxMemMethod.invoke(Runtime.getRuntime(), new Object[0]);
|
||||
if (o instanceof Long) {
|
||||
max = ((Long) o).longValue();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore if method missing or if there are other failures trying to determine the max
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
private void setUpdateIntervalInMS(int interval) {
|
||||
updateInterval = Math.max(100, interval);
|
||||
}
|
||||
|
||||
private void doDispose() {
|
||||
prefStore.removePreferenceChangeListener(prefListener);
|
||||
if (gcImage != null) {
|
||||
gcImage.dispose();
|
||||
}
|
||||
if (disabledGcImage != null) {
|
||||
disabledGcImage.dispose();
|
||||
}
|
||||
|
||||
if (lowMemCol != null) {
|
||||
lowMemCol.dispose();
|
||||
}
|
||||
if (freeMemCol != null) {
|
||||
freeMemCol.dispose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Point computeSize(int wHint, int hHint, boolean changed) {
|
||||
GC gc = new GC(this);
|
||||
Point p = gc.textExtent("MMMMMMMMMMMM");
|
||||
int height = imgBounds.height;
|
||||
// choose the largest of
|
||||
// - Text height + margins
|
||||
// - Image height + margins
|
||||
// - Default Trim heightin
|
||||
height = Math.max(height, p.y) + 4;
|
||||
height = Math.max(TrimUtil.TRIM_DEFAULT_HEIGHT, height);
|
||||
gc.dispose();
|
||||
return new Point(p.x + 15, height);
|
||||
}
|
||||
|
||||
private void arm(boolean armed) {
|
||||
if (this.armed == armed) {
|
||||
return;
|
||||
}
|
||||
this.armed = armed;
|
||||
button.redraw();
|
||||
button.update();
|
||||
}
|
||||
|
||||
private void gcRunning(boolean isInGC) {
|
||||
if (this.isInGC == isInGC) {
|
||||
return;
|
||||
}
|
||||
this.isInGC = isInGC;
|
||||
button.redraw();
|
||||
button.update();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the context menu
|
||||
*/
|
||||
private void createContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager();
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
@Override
|
||||
public void menuAboutToShow(IMenuManager menuMgr) {
|
||||
fillMenu(menuMgr);
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(this);
|
||||
setMenu(menu);
|
||||
}
|
||||
|
||||
private void fillMenu(IMenuManager menuMgr) {
|
||||
menuMgr.add(new SetMarkAction());
|
||||
menuMgr.add(new ClearMarkAction());
|
||||
menuMgr.add(new ShowMaxAction());
|
||||
menuMgr.add(new CloseHeapStatusAction());
|
||||
// if (isKyrsoftViewAvailable()) {
|
||||
// menuMgr.add(new ShowKyrsoftViewAction());
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the mark to the current usedMem level.
|
||||
*/
|
||||
private void setMark() {
|
||||
updateStats(); // get up-to-date stats before taking the mark
|
||||
mark = usedMem;
|
||||
hasChanged = true;
|
||||
redraw();
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the mark.
|
||||
*/
|
||||
private void clearMark() {
|
||||
mark = -1;
|
||||
hasChanged = true;
|
||||
redraw();
|
||||
}
|
||||
|
||||
private void gc() {
|
||||
gcRunning(true);
|
||||
Thread t = new Thread() {
|
||||
@Override
|
||||
public void run() {
|
||||
busyGC();
|
||||
getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!isDisposed()) {
|
||||
gcRunning(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
t.start();
|
||||
}
|
||||
|
||||
private void busyGC() {
|
||||
for (int i = 0; i < 2; ++i) {
|
||||
System.gc();
|
||||
System.runFinalization();
|
||||
}
|
||||
}
|
||||
|
||||
private void paintButton(GC gc) {
|
||||
Rectangle rect = button.getClientArea();
|
||||
if (isInGC) {
|
||||
if (disabledGcImage != null) {
|
||||
int buttonY = (rect.height - imgBounds.height) / 2 + rect.y;
|
||||
gc.drawImage(disabledGcImage, rect.x, buttonY);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (armed) {
|
||||
gc.setBackground(armCol);
|
||||
gc.fillRectangle(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
if (gcImage != null) {
|
||||
int by = (rect.height - imgBounds.height) / 2 + rect.y; // button y
|
||||
gc.drawImage(gcImage, rect.x, by);
|
||||
}
|
||||
}
|
||||
|
||||
private void paintComposite(GC gc) {
|
||||
if (showMax && maxMemKnown) {
|
||||
paintCompositeMaxKnown(gc);
|
||||
} else {
|
||||
paintCompositeMaxUnknown(gc);
|
||||
}
|
||||
}
|
||||
|
||||
private void paintCompositeMaxUnknown(GC gc) {
|
||||
Rectangle rect = getClientArea();
|
||||
int x = rect.x;
|
||||
int y = rect.y;
|
||||
int w = rect.width;
|
||||
int h = rect.height;
|
||||
int bw = imgBounds.width; // button width
|
||||
int dx = x + w - bw - 2; // divider x
|
||||
int sw = w - bw - 3; // status width
|
||||
int uw = (int) (sw * usedMem / totalMem); // used mem width
|
||||
int ux = x + 1 + uw; // used mem right edge
|
||||
if (bgCol != null) {
|
||||
gc.setBackground(bgCol);
|
||||
}
|
||||
gc.fillRectangle(rect);
|
||||
gc.setForeground(sepCol);
|
||||
gc.drawLine(dx, y, dx, y + h);
|
||||
gc.drawLine(ux, y, ux, y + h);
|
||||
gc.setForeground(topLeftCol);
|
||||
gc.drawLine(x, y, x+w, y);
|
||||
gc.drawLine(x, y, x, y+h);
|
||||
gc.setForeground(bottomRightCol);
|
||||
gc.drawLine(x+w-1, y, x+w-1, y+h);
|
||||
gc.drawLine(x, y+h-1, x+w, y+h-1);
|
||||
|
||||
gc.setBackground(usedMemCol);
|
||||
gc.fillRectangle(x + 1, y + 1, uw, h - 2);
|
||||
|
||||
String s = convertToMegString(usedMem)+" of "+ convertToMegString(totalMem);
|
||||
Point p = gc.textExtent(s);
|
||||
int sx = (rect.width - 15 - p.x) / 2 + rect.x + 1;
|
||||
int sy = (rect.height - 2 - p.y) / 2 + rect.y + 1;
|
||||
gc.setForeground(textCol);
|
||||
gc.drawString(s, sx, sy, true);
|
||||
|
||||
// draw an I-shaped bar in the foreground colour for the mark (if present)
|
||||
if (mark != -1) {
|
||||
int ssx = (int) (sw * mark / totalMem) + x + 1;
|
||||
paintMark(gc, ssx, y, h);
|
||||
}
|
||||
}
|
||||
|
||||
private void paintCompositeMaxKnown(GC gc) {
|
||||
Rectangle rect = getClientArea();
|
||||
int x = rect.x;
|
||||
int y = rect.y;
|
||||
int w = rect.width;
|
||||
int h = rect.height;
|
||||
int bw = imgBounds.width; // button width
|
||||
int dx = x + w - bw - 2; // divider x
|
||||
int sw = w - bw - 3; // status width
|
||||
int uw = (int) (sw * usedMem / maxMem); // used mem width
|
||||
int ux = x + 1 + uw; // used mem right edge
|
||||
int tw = (int) (sw * totalMem / maxMem); // current total mem width
|
||||
int tx = x + 1 + tw; // current total mem right edge
|
||||
|
||||
gc.setBackground(bgCol);
|
||||
gc.fillRectangle(rect);
|
||||
gc.setForeground(sepCol);
|
||||
gc.drawLine(dx, y, dx, y + h);
|
||||
gc.drawLine(ux, y, ux, y + h);
|
||||
gc.drawLine(tx, y, tx, y + h);
|
||||
gc.setForeground(topLeftCol);
|
||||
gc.drawLine(x, y, x+w, y);
|
||||
gc.drawLine(x, y, x, y+h);
|
||||
gc.setForeground(bottomRightCol);
|
||||
gc.drawLine(x+w-1, y, x+w-1, y+h);
|
||||
gc.drawLine(x, y+h-1, x+w, y+h-1);
|
||||
|
||||
if (lowMemThreshold != 0 && ((double)(maxMem - usedMem) / (double)maxMem < lowMemThreshold)) {
|
||||
gc.setBackground(lowMemCol);
|
||||
} else {
|
||||
gc.setBackground(usedMemCol);
|
||||
}
|
||||
gc.fillRectangle(x + 1, y + 1, uw, h - 2);
|
||||
|
||||
gc.setBackground(freeMemCol);
|
||||
gc.fillRectangle(ux + 1, y + 1, tx - (ux + 1), h - 2);
|
||||
|
||||
// paint line for low memory threshold
|
||||
if (showLowMemThreshold && lowMemThreshold != 0) {
|
||||
gc.setForeground(lowMemCol);
|
||||
int thresholdX = x + 1 + (int) (sw * (1.0 - lowMemThreshold));
|
||||
gc.drawLine(thresholdX, y + 1, thresholdX, y + h - 2);
|
||||
}
|
||||
|
||||
String s = convertToMegString(usedMem)+" of "+convertToMegString(totalMem);
|
||||
Point p = gc.textExtent(s);
|
||||
int sx = (rect.width - 15 - p.x) / 2 + rect.x + 1;
|
||||
int sy = (rect.height - 2 - p.y) / 2 + rect.y + 1;
|
||||
gc.setForeground(textCol);
|
||||
gc.drawString(s, sx, sy, true);
|
||||
|
||||
// draw an I-shaped bar in the foreground colour for the mark (if present)
|
||||
if (mark != -1) {
|
||||
int ssx = (int) (sw * mark / maxMem) + x + 1;
|
||||
paintMark(gc, ssx, y, h);
|
||||
}
|
||||
}
|
||||
|
||||
private void paintMark(GC gc, int x, int y, int h) {
|
||||
gc.setForeground(markCol);
|
||||
gc.drawLine(x, y+1, x, y+h-2);
|
||||
gc.drawLine(x-1, y+1, x+1, y+1);
|
||||
gc.drawLine(x-1, y+h-2, x+1, y+h-2);
|
||||
}
|
||||
|
||||
private void updateStats() {
|
||||
Runtime runtime = Runtime.getRuntime();
|
||||
totalMem = runtime.totalMemory();
|
||||
long freeMem = runtime.freeMemory();
|
||||
usedMem = totalMem - freeMem;
|
||||
|
||||
if (convertToMeg(prevUsedMem) != convertToMeg(usedMem)) {
|
||||
prevUsedMem = usedMem;
|
||||
this.hasChanged = true;
|
||||
}
|
||||
|
||||
if (prevTotalMem != totalMem) {
|
||||
prevTotalMem = totalMem;
|
||||
this.hasChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateToolTip() {
|
||||
String usedStr = convertToMegString(usedMem);
|
||||
String totalStr = convertToMegString(totalMem);
|
||||
String maxStr = maxMemKnown ? convertToMegString(maxMem) : "<unknown>";
|
||||
String markStr = mark == -1 ? "<none>" : convertToMegString(mark);
|
||||
String toolTip = "Heap size: "+usedStr+" of total: "+totalStr+" max: "+maxStr+" mark: "+markStr;
|
||||
if (!toolTip.equals(getToolTipText())) {
|
||||
setToolTipText(toolTip);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given number of bytes to a printable number of megabytes (rounded up).
|
||||
*/
|
||||
private String convertToMegString(long numBytes) {
|
||||
return new Long(convertToMeg(numBytes)).toString()+"M";
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts the given number of bytes to the corresponding number of megabytes (rounded up).
|
||||
*/
|
||||
private long convertToMeg(long numBytes) {
|
||||
return (numBytes + (512 * 1024)) / (1024 * 1024);
|
||||
}
|
||||
|
||||
|
||||
class SetMarkAction extends Action {
|
||||
SetMarkAction() {
|
||||
super("&Set Mark");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
setMark();
|
||||
}
|
||||
}
|
||||
|
||||
class ClearMarkAction extends Action {
|
||||
ClearMarkAction() {
|
||||
super("&Clear Mark");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
clearMark();
|
||||
}
|
||||
}
|
||||
|
||||
class ShowMaxAction extends Action {
|
||||
ShowMaxAction() {
|
||||
super("Show &Max Heap", IAction.AS_CHECK_BOX);
|
||||
setEnabled(maxMemKnown);
|
||||
setChecked(showMax);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
prefStore.putBoolean(IHeapStatusConstants.PREF_SHOW_MAX, isChecked());
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
|
||||
class CloseHeapStatusAction extends Action{
|
||||
|
||||
CloseHeapStatusAction(){
|
||||
super("&Close");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(){
|
||||
// WorkbenchWindow wbw = (WorkbenchWindow) PlatformUI.getWorkbench()
|
||||
// .getActiveWorkbenchWindow();
|
||||
// if (wbw != null) {
|
||||
// wbw.showHeapStatus(false);
|
||||
// }
|
||||
System.out.println("NYI");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package com.minres.scviewer.e4.application.internal;
|
||||
/**
|
||||
* Preference constants for the heap status.
|
||||
*
|
||||
* @since 3.1
|
||||
*/
|
||||
public interface IHeapStatusConstants {
|
||||
|
||||
/**
|
||||
* Preference key for the update interval (value in milliseconds).
|
||||
*/
|
||||
String PREF_UPDATE_INTERVAL = "HeapStatus.updateInterval"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* Preference key for whether to show max heap, if available (value is boolean).
|
||||
*/
|
||||
String PREF_SHOW_MAX = "HeapStatus.showMax"; //$NON-NLS-1$
|
||||
|
||||
}
|
@ -0,0 +1,209 @@
|
||||
package com.minres.scviewer.e4.application.internal;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.core.internal.preferences.BundleDefaultPreferences;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
||||
import org.eclipse.core.runtime.jobs.ProgressProvider;
|
||||
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.di.UISynchronize;
|
||||
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.jface.action.StatusLineManager;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
public class StatusBarControl {
|
||||
|
||||
public static final String STATUS_UPDATE="StatusUpdate";
|
||||
public static final String ZOOM_LEVEL="ZoomLevelUpdate";
|
||||
public static final String CURSOR_TIME="CursorPosUpdate";
|
||||
|
||||
@Inject EModelService modelService;
|
||||
@Inject @Optional IEclipsePreferences preferences;
|
||||
private final UISynchronize sync;
|
||||
|
||||
protected StatusLineManager manager;
|
||||
|
||||
private SyncedProgressMonitor monitor;
|
||||
|
||||
@Inject
|
||||
public StatusBarControl(UISynchronize sync) {
|
||||
this.sync=sync;
|
||||
manager = new StatusLineManager();
|
||||
manager.update(true);
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
void createWidget(Composite parent, MToolControl toolControl) {
|
||||
if (toolControl.getElementId().equals("org.eclipse.ui.StatusLine")) { //$NON-NLS-1$
|
||||
createStatusLine(parent, toolControl);
|
||||
} else if (toolControl.getElementId().equals("org.eclipse.ui.HeapStatus")) { //$NON-NLS-1$
|
||||
createHeapStatus(parent, toolControl);
|
||||
} else if (toolControl.getElementId().equals("org.eclipse.ui.ProgressBar")) { //$NON-NLS-1$
|
||||
createProgressBar(parent, toolControl);
|
||||
}
|
||||
}
|
||||
|
||||
@PreDestroy
|
||||
void destroy() {
|
||||
if (manager != null) {
|
||||
manager.dispose();
|
||||
manager = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param toolControl
|
||||
*/
|
||||
private void createProgressBar(Composite parent, MToolControl toolControl) {
|
||||
manager.createControl(parent);
|
||||
monitor=new SyncedProgressMonitor(manager.getProgressMonitor());
|
||||
Job.getJobManager().setProgressProvider(new ProgressProvider() {
|
||||
@Override
|
||||
public IProgressMonitor createMonitor(Job job) {
|
||||
return monitor.addJob(job);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param toolControl
|
||||
*/
|
||||
private void createHeapStatus(Composite parent, MToolControl toolControl) {
|
||||
if(preferences==null){
|
||||
preferences=new BundleDefaultPreferences();
|
||||
preferences.putInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 100);
|
||||
preferences.putBoolean(IHeapStatusConstants.PREF_SHOW_MAX, true);
|
||||
}
|
||||
new HeapStatus(parent, preferences);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param toolControl
|
||||
*/
|
||||
private void createStatusLine(Composite parent, MToolControl toolControl) {
|
||||
// IEclipseContext context = modelService.getContainingContext(toolControl);
|
||||
manager.createControl(parent);
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(STATUS_UPDATE) String text) {
|
||||
if(manager!=null ){
|
||||
manager.setMessage(text);
|
||||
}
|
||||
}
|
||||
|
||||
private final class SyncedProgressMonitor implements IProgressMonitor {
|
||||
|
||||
IProgressMonitor delegate;
|
||||
private boolean cancelled;
|
||||
|
||||
SyncedProgressMonitor(IProgressMonitor delegate){
|
||||
this.delegate=delegate;
|
||||
}
|
||||
|
||||
public IProgressMonitor addJob(Job job){
|
||||
if(job != null){
|
||||
job.addJobChangeListener(new JobChangeAdapter() {
|
||||
@Override
|
||||
public void done(IJobChangeEvent event) {
|
||||
// clean-up
|
||||
event.getJob().removeJobChangeListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beginTask(final String name, final int totalWork) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.beginTask(name, totalWork);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void worked(final int work) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.worked(work);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void done() {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.done();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void internalWorked(final double work) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.internalWorked(work);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCanceled() {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
cancelled=delegate.isCanceled();
|
||||
}
|
||||
});
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCanceled(final boolean value) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.setCanceled(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setTaskName(final String name) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.setTaskName(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void subTask(final String name) {
|
||||
sync.syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
delegate.subTask(name);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
package com.minres.scviewer.e4.application.internal;
|
||||
import org.eclipse.jface.dialogs.Dialog;
|
||||
import org.eclipse.jface.resource.JFaceResources;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.GC;
|
||||
import org.eclipse.swt.graphics.Point;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
|
||||
/**
|
||||
* Simple class to provide some common internal Trim support.
|
||||
*
|
||||
* @since 3.2
|
||||
*
|
||||
*/
|
||||
public class TrimUtil {
|
||||
|
||||
/**
|
||||
* Default height for workbench trim.
|
||||
*/
|
||||
public static final int TRIM_DEFAULT_HEIGHT;
|
||||
static {
|
||||
Shell s = new Shell(Display.getCurrent(), SWT.NONE);
|
||||
s.setLayout(new GridLayout());
|
||||
ToolBar t = new ToolBar(s, SWT.NONE);
|
||||
t.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
ToolItem ti = new ToolItem(t, SWT.PUSH);
|
||||
ti.setImage(JFaceResources.getImageRegistry().get(Dialog.DLG_IMG_MESSAGE_INFO));
|
||||
s.layout();
|
||||
int toolItemHeight = t.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
|
||||
GC gc = new GC(s);
|
||||
Point fontSize = gc.textExtent("Wg"); //$NON-NLS-1$
|
||||
gc.dispose();
|
||||
TRIM_DEFAULT_HEIGHT = Math.max(toolItemHeight, fontSize.y);
|
||||
s.dispose();
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,100 @@
|
||||
package com.minres.scviewer.e4.application.internal;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.di.UISynchronize;
|
||||
import org.eclipse.e4.ui.services.IServiceConstants;
|
||||
import org.eclipse.e4.ui.workbench.modeling.EModelService;
|
||||
import org.eclipse.jface.action.ContributionItem;
|
||||
import org.eclipse.jface.action.StatusLineManager;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.custom.CLabel;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
public class WaveStatusBarControl extends StatusBarControl {
|
||||
|
||||
public static final String STATUS_UPDATE="StatusUpdate";
|
||||
public static final String ZOOM_LEVEL="ZoomLevelUpdate";
|
||||
public static final String CURSOR_TIME="CursorPosUpdate";
|
||||
|
||||
@Inject
|
||||
EModelService modelService;
|
||||
|
||||
class TextContributionItem extends ContributionItem {
|
||||
|
||||
final String labelString;
|
||||
final int width;
|
||||
CLabel label, text;
|
||||
private String content;
|
||||
|
||||
public TextContributionItem(String labelString, int width) {
|
||||
super();
|
||||
this.labelString = labelString;
|
||||
this.width=width;
|
||||
content="";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fill(Composite parent) {
|
||||
Composite box=new Composite(parent, SWT.NONE);
|
||||
box.setLayout(new GridLayout(2, false));
|
||||
label=new CLabel(box, SWT.SHADOW_NONE);
|
||||
label.setText(labelString);
|
||||
text=new CLabel(box, SWT.SHADOW_IN);
|
||||
GridData layoutData=new GridData(SWT.DEFAULT, SWT.DEFAULT, true, false);
|
||||
layoutData.minimumWidth=width;
|
||||
text.setLayoutData(layoutData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDynamic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setText(String message){
|
||||
this.content=message;
|
||||
if(text!=null && !text.isDisposed()) text.setText(content);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TextContributionItem zoomContribution, cursorContribution;
|
||||
|
||||
@Inject
|
||||
public WaveStatusBarControl(UISynchronize sync) {
|
||||
super(sync);
|
||||
zoomContribution = new TextContributionItem("Z:", 150);
|
||||
cursorContribution = new TextContributionItem("C:", 120);
|
||||
manager.appendToGroup(StatusLineManager.BEGIN_GROUP,cursorContribution);
|
||||
manager.appendToGroup(StatusLineManager.MIDDLE_GROUP, zoomContribution);
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION)@Optional Object obj){
|
||||
// if(status!=null ) status.setText(obj==null?"":obj.toString());
|
||||
if(manager!=null ){
|
||||
if(obj instanceof List<?>){
|
||||
manager.setMessage(""+((List<?>)obj).size()+" Elements");
|
||||
} else
|
||||
manager.setMessage(obj==null?"":obj.getClass().getSimpleName()+" selected");
|
||||
}
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getZoomEvent(@UIEventTopic(ZOOM_LEVEL) String text) {
|
||||
zoomContribution.setText(text);
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getCursorEvent(@UIEventTopic(CURSOR_TIME) String text) {
|
||||
cursorContribution.setText(text);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,108 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.Focus;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.TreeViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbLabelProvider;
|
||||
|
||||
public class DesignBrowser implements ISelectionChangedListener {
|
||||
|
||||
@Inject IEventBroker eventBroker;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
private TreeViewer contentOutlineViewer;
|
||||
|
||||
private PropertyChangeListener l = new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if("CHILDS".equals(evt.getPropertyName())){
|
||||
contentOutlineViewer.getTree().getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
contentOutlineViewer.refresh();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@PostConstruct
|
||||
public void createComposite(Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
contentOutlineViewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
contentOutlineViewer.addSelectionChangedListener(this);
|
||||
contentOutlineViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
contentOutlineViewer.setContentProvider(new TxDbContentProvider());
|
||||
contentOutlineViewer.setLabelProvider(new TxDbLabelProvider());
|
||||
contentOutlineViewer.setUseHashlookup(true);
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
contentOutlineViewer.getTree().setFocus();
|
||||
setSelection(contentOutlineViewer.getSelection());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
setSelection(event.getSelection());
|
||||
}
|
||||
|
||||
protected void setSelection(ISelection iSelection) {
|
||||
IStructuredSelection selection = (IStructuredSelection)iSelection;
|
||||
switch(selection.size()){
|
||||
case 0:
|
||||
eventBroker.post(WaveformViewerPart.ACTIVE_NODE, null);
|
||||
break;
|
||||
case 1:
|
||||
eventBroker.post(WaveformViewerPart.ACTIVE_NODE, selection.getFirstElement());
|
||||
selectionService.setSelection(selection.getFirstElement());
|
||||
break;
|
||||
default:
|
||||
eventBroker.post(WaveformViewerPart.ACTIVE_NODE, selection.getFirstElement());
|
||||
selectionService.setSelection(selection.toList());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_DATABASE) IWaveformDb database) {
|
||||
Object input = contentOutlineViewer.getInput();
|
||||
if(input!=null && input instanceof List<?>)
|
||||
((List<IWaveformDb>)input).get(0).removePropertyChangeListener(l);
|
||||
contentOutlineViewer.setInput(Arrays.asList(new IWaveformDb[]{database}));
|
||||
// Set up the tree viewer
|
||||
database.addPropertyChangeListener(l);
|
||||
}
|
||||
/*
|
||||
* TODO: needs top be implemented
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE_PATH) String path) {
|
||||
|
||||
}
|
||||
*/
|
||||
};
|
@ -0,0 +1,233 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.Focus;
|
||||
import org.eclipse.e4.ui.services.IServiceConstants;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.jface.viewers.ViewerSorter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ControlAdapter;
|
||||
import org.eclipse.swt.events.ControlEvent;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
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.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.e4.application.provider.TxPropertiesContentProvider;
|
||||
import com.minres.scviewer.e4.application.provider.TxPropertiesLabelProvider;
|
||||
|
||||
public class TransactionDetails {
|
||||
|
||||
// Column constants
|
||||
public static final int COLUMN_FIRST = 0;
|
||||
|
||||
public static final int COLUMN_SECOND = 1;
|
||||
|
||||
@Inject IEventBroker eventBroker;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
private Text nameFilter;
|
||||
private TableViewer txTableViewer;
|
||||
private TableColumn col1, col2;
|
||||
TxAttributeFilter attributeFilter;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void createComposite(final Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
|
||||
nameFilter = new Text(parent, SWT.BORDER);
|
||||
nameFilter.setMessage("Enter text to filter");
|
||||
nameFilter.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
attributeFilter.setSearchText(((Text) e.widget).getText());
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
attributeFilter = new TxAttributeFilter();
|
||||
|
||||
txTableViewer = new TableViewer(parent);
|
||||
txTableViewer.setContentProvider(new TxPropertiesContentProvider());
|
||||
txTableViewer.setLabelProvider(new TxPropertiesLabelProvider());
|
||||
txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
txTableViewer.addFilter(attributeFilter);
|
||||
|
||||
// Set up the table
|
||||
Table table = txTableViewer.getTable();
|
||||
table.setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
|
||||
// Add the first name column
|
||||
col1 = new TableColumn(table, SWT.LEFT);
|
||||
col1.setText("Name");
|
||||
col1.setResizable(true);
|
||||
col1.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
((TxAttributeViewerSorter) txTableViewer.getSorter()).doSort(COLUMN_FIRST);
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
// Add the last name column
|
||||
col2 = new TableColumn(table, SWT.LEFT);
|
||||
col2.setText("Value");
|
||||
col2.setResizable(true);
|
||||
col2.addSelectionListener(new SelectionAdapter() {
|
||||
public void widgetSelected(SelectionEvent event) {
|
||||
((TxAttributeViewerSorter) txTableViewer.getSorter()).doSort(COLUMN_SECOND);
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
|
||||
// Pack the columns
|
||||
for (int i = 0, n = table.getColumnCount(); i < n; i++) {
|
||||
table.getColumn(i).pack();
|
||||
}
|
||||
|
||||
// Turn on the header and the lines
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
|
||||
parent.addControlListener(new ControlAdapter() {
|
||||
public void controlResized(ControlEvent e) {
|
||||
Table table = txTableViewer.getTable();
|
||||
Rectangle area = parent.getClientArea();
|
||||
Point preferredSize = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
|
||||
int width = area.width - 2*table.getBorderWidth();
|
||||
if (preferredSize.y > area.height + table.getHeaderHeight()) {
|
||||
// Subtract the scrollbar width from the total column width
|
||||
// if a vertical scrollbar will be required
|
||||
Point vBarSize = table.getVerticalBar().getSize();
|
||||
width -= vBarSize.x;
|
||||
}
|
||||
Point oldSize = table.getSize();
|
||||
if (oldSize.x > area.width) {
|
||||
// table is getting smaller so make the columns
|
||||
// smaller first and then resize the table to
|
||||
// match the client area width
|
||||
col1.setWidth(width/3);
|
||||
col2.setWidth(width - col1.getWidth());
|
||||
table.setSize(area.width, area.height);
|
||||
} else {
|
||||
// table is getting bigger so make the table
|
||||
// bigger first and then make the columns wider
|
||||
// to match the client area width
|
||||
table.setSize(area.width, area.height);
|
||||
col1.setWidth(width/3);
|
||||
col2.setWidth(width - col1.getWidth());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
txTableViewer.getTable().setFocus();
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object){
|
||||
if(txTableViewer!=null && !txTableViewer.getTable().isDisposed())
|
||||
if(object instanceof ITx){
|
||||
txTableViewer.setInput(object);
|
||||
} else {
|
||||
txTableViewer.setInput(null);
|
||||
}
|
||||
}
|
||||
|
||||
class TxAttributeViewerSorter extends ViewerSorter {
|
||||
private static final int ASCENDING = 0;
|
||||
|
||||
private static final int DESCENDING = 1;
|
||||
|
||||
private int column;
|
||||
|
||||
private int direction;
|
||||
|
||||
/**
|
||||
* Does the sort. If it's a different column from the previous sort, do an
|
||||
* ascending sort. If it's the same column as the last sort, toggle the sort
|
||||
* direction.
|
||||
*
|
||||
* @param column
|
||||
*/
|
||||
public void doSort(int column) {
|
||||
if (column == this.column) {
|
||||
// Same column as last sort; toggle the direction
|
||||
direction = 1 - direction;
|
||||
} else {
|
||||
// New column; do an ascending sort
|
||||
this.column = column;
|
||||
direction = ASCENDING;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the object for sorting
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(Viewer viewer, Object e1, Object e2) {
|
||||
int rc = 0;
|
||||
ITxAttribute p1 = (ITxAttribute) e1;
|
||||
ITxAttribute p2 = (ITxAttribute) e2;
|
||||
|
||||
// Determine which column and do the appropriate sort
|
||||
switch (column) {
|
||||
case COLUMN_FIRST:
|
||||
rc = getComparator().compare(p1.getName(), p2.getName());
|
||||
break;
|
||||
case COLUMN_SECOND:
|
||||
rc = getComparator().compare(p1.getValue(), p2.getValue());
|
||||
break;
|
||||
}
|
||||
|
||||
// If descending order, flip the direction
|
||||
if (direction == DESCENDING)
|
||||
rc = -rc;
|
||||
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
public class TxAttributeFilter extends ViewerFilter {
|
||||
|
||||
private String searchString;
|
||||
|
||||
public void setSearchText(String s) {
|
||||
this.searchString = ".*" + s + ".*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (searchString == null || searchString.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
ITxAttribute p = (ITxAttribute) element;
|
||||
if (p.getName().matches(searchString)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,170 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.Focus;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.services.IServiceConstants;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.viewers.ViewerFilter;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.events.ModifyEvent;
|
||||
import org.eclipse.swt.events.ModifyListener;
|
||||
import org.eclipse.swt.events.SelectionAdapter;
|
||||
import org.eclipse.swt.events.SelectionEvent;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.swt.widgets.ToolBar;
|
||||
import org.eclipse.swt.widgets.ToolItem;
|
||||
import org.eclipse.wb.swt.ResourceManager;
|
||||
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbContentProvider;
|
||||
import com.minres.scviewer.e4.application.provider.TxDbLabelProvider;
|
||||
|
||||
public class WaveformListPart implements ISelectionChangedListener {
|
||||
|
||||
@Inject IEventBroker eventBroker;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
private Text nameFilter;
|
||||
private TableViewer txTableViewer;
|
||||
ToolItem appendItem, insertItem;
|
||||
WaveformAttributeFilter attributeFilter;
|
||||
|
||||
@PostConstruct
|
||||
public void createComposite(Composite parent) {
|
||||
parent.setLayout(new GridLayout(1, false));
|
||||
|
||||
nameFilter = new Text(parent, SWT.BORDER);
|
||||
nameFilter.setMessage("Enter text to filter waveforms");
|
||||
nameFilter.addModifyListener(new ModifyListener() {
|
||||
@Override
|
||||
public void modifyText(ModifyEvent e) {
|
||||
attributeFilter.setSearchText(((Text) e.widget).getText());
|
||||
txTableViewer.refresh();
|
||||
}
|
||||
});
|
||||
nameFilter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
|
||||
|
||||
attributeFilter = new WaveformAttributeFilter();
|
||||
|
||||
txTableViewer = new TableViewer(parent);
|
||||
txTableViewer.setContentProvider(new TxDbContentProvider());
|
||||
txTableViewer.setLabelProvider(new TxDbLabelProvider());
|
||||
txTableViewer.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
|
||||
txTableViewer.addSelectionChangedListener(this);
|
||||
txTableViewer.addFilter(attributeFilter);
|
||||
|
||||
ToolBar toolBar = new ToolBar(parent, SWT.FLAT | SWT.RIGHT);
|
||||
toolBar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 1, 1));
|
||||
toolBar.setBounds(0, 0, 87, 20);
|
||||
|
||||
insertItem = new ToolItem(toolBar, SWT.NONE);
|
||||
insertItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/bullet_plus.png"));
|
||||
insertItem.setText("Insert");
|
||||
insertItem.setEnabled(false);
|
||||
insertItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
eventBroker.post(WaveformViewerPart.ADD_WAVEFORM,
|
||||
((IStructuredSelection)txTableViewer.getSelection()).toList());
|
||||
|
||||
}
|
||||
});
|
||||
appendItem = new ToolItem(toolBar, SWT.NONE);
|
||||
appendItem.setImage(ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/bullet_plus.png"));
|
||||
appendItem.setText("Append");
|
||||
appendItem.setEnabled(false);
|
||||
appendItem.addSelectionListener(new SelectionAdapter() {
|
||||
@Override
|
||||
public void widgetSelected(SelectionEvent e) {
|
||||
eventBroker.post(WaveformViewerPart.ADD_WAVEFORM,
|
||||
((IStructuredSelection)txTableViewer.getSelection()).toList());
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
txTableViewer.getTable().setFocus();
|
||||
setSelection(txTableViewer.getSelection());
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getStatusEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE) Object o) {
|
||||
txTableViewer.setInput(o);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
setSelection(event.getSelection());
|
||||
}
|
||||
|
||||
protected void setSelection(ISelection iSelection) {
|
||||
IStructuredSelection selection = (IStructuredSelection)iSelection;
|
||||
switch(selection.size()){
|
||||
case 0:
|
||||
appendItem.setEnabled(false);
|
||||
insertItem.setEnabled(false);
|
||||
break;
|
||||
case 1:
|
||||
selectionService.setSelection(selection.getFirstElement());
|
||||
appendItem.setEnabled(true);
|
||||
break;
|
||||
default:
|
||||
selectionService.setSelection(selection.toList());
|
||||
appendItem.setEnabled(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject
|
||||
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION) @Optional Object object){
|
||||
if(txTableViewer!=null && !insertItem.isDisposed() && !appendItem.isDisposed())
|
||||
if(object instanceof ITx && appendItem.isEnabled()){
|
||||
insertItem.setEnabled(true);
|
||||
} else if(object instanceof IWaveform<?> && appendItem.isEnabled()){
|
||||
insertItem.setEnabled(true);
|
||||
} else {
|
||||
insertItem.setEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
public class WaveformAttributeFilter extends ViewerFilter {
|
||||
|
||||
private String searchString;
|
||||
|
||||
public void setSearchText(String s) {
|
||||
this.searchString = ".*" + s + ".*";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean select(Viewer viewer, Object parentElement, Object element) {
|
||||
if (searchString == null || searchString.length() == 0) {
|
||||
return true;
|
||||
}
|
||||
IWaveform<?> p = (IWaveform<?>) element;
|
||||
if (p.getName().matches(searchString)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,369 @@
|
||||
package com.minres.scviewer.e4.application.parts;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.core.runtime.SubMonitor;
|
||||
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
|
||||
import org.eclipse.core.runtime.jobs.Job;
|
||||
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
|
||||
import org.eclipse.e4.core.di.annotations.Optional;
|
||||
import org.eclipse.e4.core.services.events.IEventBroker;
|
||||
import org.eclipse.e4.ui.di.Focus;
|
||||
import org.eclipse.e4.ui.di.PersistState;
|
||||
import org.eclipse.e4.ui.di.UIEventTopic;
|
||||
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
||||
import org.eclipse.e4.ui.services.EMenuService;
|
||||
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelectionChangedListener;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.SelectionChangedEvent;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
import com.minres.scviewer.database.IWaveformEvent;
|
||||
import com.minres.scviewer.database.swt.GotoDirection;
|
||||
import com.minres.scviewer.database.swt.TxDisplay;
|
||||
import com.minres.scviewer.e4.application.internal.StatusBarControl;
|
||||
|
||||
public class WaveformViewerPart {
|
||||
|
||||
public static final String ACTIVE_DATABASE="Active_Database";
|
||||
public static final String ACTIVE_NODE="ActiveNode";
|
||||
public static final String ACTIVE_NODE_PATH="ActiveNodePath";
|
||||
public static final String ADD_WAVEFORM="AddWaveform";
|
||||
|
||||
protected static final String DATABASE_FILE = "DATABASE_FILE";
|
||||
protected static final String SHOWN_WAVEFORM = "SHOWN_WAVEFORM";
|
||||
|
||||
private final static String[] zoomLevel={
|
||||
"1fs", "10fs", "100fs",
|
||||
"1ps", "10ps", "100ps",
|
||||
"1ns", "10ns", "100ns",
|
||||
"1µs", "10µs", "10µs",
|
||||
"1ms", "10ms", "100ms", "1s"};
|
||||
|
||||
public static final String ID = "com.minres.scviewer.ui.TxEditorPart"; //$NON-NLS-1$
|
||||
|
||||
public static final String WAVE_ACTION_ID = "com.minres.scviewer.ui.action.AddToWave";
|
||||
|
||||
private TxDisplay txDisplay;
|
||||
|
||||
@Inject private IEventBroker eventBroker;
|
||||
|
||||
@Inject EMenuService menuService;
|
||||
|
||||
@Inject ESelectionService selectionService;
|
||||
|
||||
private IWaveformDb database;
|
||||
|
||||
private IHierNode activeNode;
|
||||
|
||||
private Composite myParent;
|
||||
|
||||
ArrayList<File> filesToLoad;
|
||||
|
||||
Map<String, String> persistedState;
|
||||
|
||||
|
||||
@PostConstruct
|
||||
public void createComposite(MPart part, Composite parent, IWaveformDbFactory dbFactory) {
|
||||
myParent=parent;
|
||||
database=dbFactory.getDatabase();
|
||||
database.addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if("WAVEFORMS".equals(evt.getPropertyName())) {
|
||||
myParent.getDisplay().syncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txDisplay.setMaxTime(database.getMaxTime());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
txDisplay = new TxDisplay(parent);
|
||||
txDisplay.setMaxTime(0);
|
||||
txDisplay.addPropertyChangeListener(TxDisplay.CURSOR_PROPERTY, new PropertyChangeListener() {
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
Long time = (Long) evt.getNewValue();
|
||||
eventBroker.post(StatusBarControl.CURSOR_TIME, ""+ time/1000000+"ns");
|
||||
|
||||
}
|
||||
});
|
||||
txDisplay.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
if(event.getSelection() instanceof IStructuredSelection)
|
||||
for(Object o:((IStructuredSelection)event.getSelection()).toList()){
|
||||
if(o instanceof ITx || o instanceof IWaveform<?>){
|
||||
selectionService.setSelection(o);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
filesToLoad=new ArrayList<File>();
|
||||
persistedState = part.getPersistedState();
|
||||
Integer files = persistedState.containsKey(DATABASE_FILE+"S")?Integer.parseInt(persistedState.get(DATABASE_FILE+"S")):0;
|
||||
for(int i=0; i<files;i++){
|
||||
filesToLoad.add(new File(persistedState.get(DATABASE_FILE+i)));
|
||||
}
|
||||
if(filesToLoad.size()>0)
|
||||
loadDatabase();
|
||||
eventBroker.post(StatusBarControl.ZOOM_LEVEL, zoomLevel[txDisplay.getZoomLevel()]);
|
||||
menuService.registerContextMenu(txDisplay.getNameControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext");
|
||||
menuService.registerContextMenu(txDisplay.getValueControl(), "com.minres.scviewer.e4.application.popupmenu.namecontext");
|
||||
menuService.registerContextMenu(txDisplay.getWaveformControl(), "com.minres.scviewer.e4.application.popupmenu.wavecontext");
|
||||
}
|
||||
|
||||
protected void loadDatabase() {
|
||||
Job job = new Job(" My Job") {
|
||||
@Override
|
||||
protected IStatus run( IProgressMonitor monitor) {
|
||||
// convert to SubMonitor and set total number of work units
|
||||
SubMonitor subMonitor = SubMonitor.convert(monitor, filesToLoad.size());
|
||||
try {
|
||||
for(File file: filesToLoad){
|
||||
// TimeUnit.SECONDS.sleep(20);
|
||||
database.load(file);
|
||||
database.addPropertyChangeListener(txDisplay);
|
||||
subMonitor.worked(1);
|
||||
if(monitor.isCanceled()) return Status.CANCEL_STATUS;
|
||||
}
|
||||
// sleep a second
|
||||
} catch (Exception e) {
|
||||
database=null;
|
||||
e.printStackTrace();
|
||||
return Status.CANCEL_STATUS;
|
||||
}
|
||||
return Status.OK_STATUS;
|
||||
}
|
||||
};
|
||||
job.addJobChangeListener(new JobChangeAdapter(){
|
||||
@Override
|
||||
public void done(IJobChangeEvent event) {
|
||||
if(event.getResult()==Status.OK_STATUS)
|
||||
myParent.getDisplay().asyncExec(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
txDisplay.setMaxTime(database.getMaxTime());
|
||||
restoreState();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
job.schedule(0);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@Optional
|
||||
public void setPartInput( @Named( "input" ) Object partInput ) {
|
||||
if(partInput instanceof File){
|
||||
filesToLoad=new ArrayList<File>();
|
||||
File file = (File) partInput;
|
||||
if(file.exists()){
|
||||
filesToLoad.add(file);
|
||||
try {
|
||||
String ext = getFileExtension(file.getName());
|
||||
if("vcd".equals(ext.toLowerCase())){
|
||||
if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txdb")))){
|
||||
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txdb")));
|
||||
}else if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "txlog")))){
|
||||
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "txlog")));
|
||||
}
|
||||
} else if("txdb".equals(ext.toLowerCase()) || "txlog".equals(ext.toLowerCase())){
|
||||
if(askIfToLoad(new File(renameFileExtension(file.getCanonicalPath(), "vcd")))){
|
||||
filesToLoad.add(new File(renameFileExtension(file.getCanonicalPath(), "vcd")));
|
||||
}
|
||||
}
|
||||
} catch (IOException e) { // silently ignore any error
|
||||
}
|
||||
}
|
||||
if(filesToLoad.size()>0)
|
||||
loadDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
@Focus
|
||||
public void setFocus() {
|
||||
myParent.setFocus();
|
||||
updateAll();
|
||||
}
|
||||
|
||||
@PersistState
|
||||
public void saveState(MPart part) {
|
||||
// save changes
|
||||
Map<String, String> persistedState = part.getPersistedState();
|
||||
persistedState.put(DATABASE_FILE+"S", Integer.toString(filesToLoad.size()));
|
||||
Integer index=0;
|
||||
for(File file:filesToLoad){
|
||||
persistedState.put(DATABASE_FILE+index, file.getAbsolutePath());
|
||||
index++;
|
||||
}
|
||||
if(activeNode!=null)
|
||||
persistedState.put(ACTIVE_NODE_PATH, activeNode.getFullName());
|
||||
persistedState.put(SHOWN_WAVEFORM+"S", Integer.toString(txDisplay.getStreamList().size()));
|
||||
index=0;
|
||||
for(IWaveform<? extends IWaveformEvent> waveform:txDisplay.getStreamList()){
|
||||
persistedState.put(SHOWN_WAVEFORM+index, waveform.getFullName());
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
protected void restoreState() {
|
||||
updateAll();
|
||||
String hierName = persistedState.get(ACTIVE_NODE_PATH);
|
||||
if(hierName!=null) eventBroker.post(ACTIVE_NODE_PATH, hierName);
|
||||
Integer waves = persistedState.containsKey(SHOWN_WAVEFORM+"S")?Integer.parseInt(persistedState.get(SHOWN_WAVEFORM+"S")):0;
|
||||
List<IWaveform<? extends IWaveformEvent>> res = new LinkedList<>();
|
||||
for(int i=0; i<waves;i++){
|
||||
IWaveform<? extends IWaveformEvent> waveform = database.getStreamByName(persistedState.get(SHOWN_WAVEFORM+i));
|
||||
if(waveform!=null) res.add(waveform);
|
||||
}
|
||||
if(res.size()>0) txDisplay.getStreamList().addAll(res);
|
||||
}
|
||||
|
||||
private void updateAll() {
|
||||
eventBroker.post(ACTIVE_DATABASE, database);
|
||||
eventBroker.post(StatusBarControl.ZOOM_LEVEL, zoomLevel[txDisplay.getZoomLevel()]);
|
||||
eventBroker.post(StatusBarControl.CURSOR_TIME, Long.toString(txDisplay.getCursorTime()/1000000)+"ns");
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getActiveNodeEvent(@UIEventTopic(WaveformViewerPart.ACTIVE_NODE) Object o, MPart activePart) {
|
||||
if(o instanceof IHierNode){
|
||||
activeNode=(IHierNode) o;
|
||||
}
|
||||
}
|
||||
|
||||
@Inject @Optional
|
||||
public void getAddWaveformEvent(@UIEventTopic(WaveformViewerPart.ADD_WAVEFORM) Object o) {
|
||||
Object sel = selectionService.getSelection();
|
||||
if(sel instanceof List<?>)
|
||||
for(Object el:((List<?>)sel)){
|
||||
if(el instanceof IWaveform<?>)
|
||||
addStreamToList((IWaveform<?>) el);
|
||||
}
|
||||
else if(sel instanceof IWaveform<?> )
|
||||
addStreamToList((IWaveform<?>) sel);
|
||||
}
|
||||
|
||||
/*
|
||||
@Inject
|
||||
public void setWaveform(@Optional @Named( IServiceConstants.ACTIVE_SELECTION) IWaveform<?> waveform,
|
||||
@Optional @Named( IServiceConstants.ACTIVE_PART) MPart part) {
|
||||
if (txDisplay!= null && part.getObject()!=this) {
|
||||
txDisplay.setSelection(waveform==null?new StructuredSelection():new StructuredSelection(waveform));
|
||||
}
|
||||
}
|
||||
*/
|
||||
protected boolean askIfToLoad(File txFile) {
|
||||
if(txFile.exists() &&
|
||||
MessageDialog.openQuestion(myParent.getDisplay().getActiveShell(), "Database open",
|
||||
"Would you like to open the adjacent database "+txFile.getName()+" as well?")){
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected static String renameFileExtension(String source, String newExt) {
|
||||
String target;
|
||||
String currentExt = getFileExtension(source);
|
||||
if (currentExt.equals("")){
|
||||
target=source+"."+newExt;
|
||||
} else {
|
||||
target=source.replaceFirst(Pattern.quote("."+currentExt)+"$", Matcher.quoteReplacement("."+newExt));
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
protected static String getFileExtension(String f) {
|
||||
String ext = "";
|
||||
int i = f.lastIndexOf('.');
|
||||
if (i > 0 && i < f.length() - 1) {
|
||||
ext = f.substring(i + 1);
|
||||
}
|
||||
return ext;
|
||||
}
|
||||
|
||||
public IWaveformDb getModel() {
|
||||
return database;
|
||||
}
|
||||
public IWaveformDb getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void addStreamToList(IWaveform<? extends IWaveformEvent> obj){
|
||||
txDisplay.getStreamList().add(obj);
|
||||
}
|
||||
|
||||
public void addStreamsToList(IWaveform<? extends IWaveformEvent>[] iWaveforms){
|
||||
for(IWaveform<? extends IWaveformEvent> stream:iWaveforms)
|
||||
addStreamToList(stream);
|
||||
}
|
||||
|
||||
public void removeStreamFromList(IWaveform<? extends IWaveformEvent> obj){
|
||||
txDisplay.getStreamList().remove(obj);
|
||||
}
|
||||
|
||||
public void removeStreamsFromList(IWaveform<? extends IWaveformEvent>[] iWaveforms){
|
||||
for(IWaveform<? extends IWaveformEvent> stream:iWaveforms)
|
||||
removeStreamFromList(stream);
|
||||
}
|
||||
|
||||
public List<IWaveform<? extends IWaveformEvent>> getStreamList(){
|
||||
return txDisplay.getStreamList();
|
||||
}
|
||||
|
||||
public void moveSelected(int i) {
|
||||
txDisplay.moveSelected(i);
|
||||
}
|
||||
|
||||
public void moveSelection(GotoDirection direction) {
|
||||
txDisplay.moveSelection(direction);
|
||||
}
|
||||
|
||||
public void moveCursor(GotoDirection direction) {
|
||||
txDisplay.moveCursor(direction); }
|
||||
|
||||
public void setZoomLevel(Integer level) {
|
||||
if(level<0) level=0;
|
||||
if(level>zoomLevel.length-1) level=zoomLevel.length-1;
|
||||
txDisplay.setZoomLevel(level);
|
||||
eventBroker.post(StatusBarControl.ZOOM_LEVEL, zoomLevel[txDisplay.getZoomLevel()]);
|
||||
}
|
||||
|
||||
public void setZoomFit() {
|
||||
txDisplay.setZoomLevel(6);
|
||||
eventBroker.post(StatusBarControl.ZOOM_LEVEL, zoomLevel[txDisplay.getZoomLevel()]);
|
||||
}
|
||||
|
||||
public int getZoomLevel() {
|
||||
return txDisplay.getZoomLevel();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,68 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.viewers.ITreeContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
|
||||
public class TxDbContentProvider implements ITreeContentProvider {
|
||||
|
||||
// private List<HierNode> nodes;
|
||||
private boolean showNodes=false;
|
||||
|
||||
@Override
|
||||
public void dispose() { }
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
showNodes=!(newInput instanceof IHierNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if(inputElement instanceof IHierNode){
|
||||
return Collections2.filter(((IHierNode)inputElement).getChildNodes(), new Predicate<IHierNode>(){
|
||||
@Override
|
||||
public boolean apply(IHierNode arg0) {
|
||||
return (arg0 instanceof IWaveform<?>)!=showNodes;
|
||||
}
|
||||
}).toArray();
|
||||
}else if(inputElement instanceof List<?>)
|
||||
return ((List<?>)inputElement).toArray();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getChildren(Object parentElement) {
|
||||
return getElements(parentElement);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParent(Object element) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasChildren(Object element) {
|
||||
// Object[] obj = getChildren(element);
|
||||
Object[] obj = getElements(element);
|
||||
return obj == null ? false : obj.length > 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.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 org.eclipse.wb.swt.ResourceManager;
|
||||
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ISignal;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
|
||||
public class TxDbLabelProvider implements ILabelProvider {
|
||||
|
||||
private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>();
|
||||
|
||||
private Image database;
|
||||
private Image stream;
|
||||
private Image signal;
|
||||
private Image folder;
|
||||
|
||||
|
||||
public TxDbLabelProvider() {
|
||||
super();
|
||||
database=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/database.png");
|
||||
stream=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/stream.png");
|
||||
folder=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/folder.png");
|
||||
signal=ResourceManager.getPluginImage("com.minres.scviewer.e4.application", "icons/signal.png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
if(database!=null) database.dispose();
|
||||
if(stream!=null) stream.dispose();
|
||||
if(folder!=null) folder.dispose();
|
||||
if(signal!=null) signal.dispose();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getImage(Object element) {
|
||||
if(element instanceof IWaveformDb){
|
||||
return database;
|
||||
}else if(element instanceof ITxStream){
|
||||
return stream;
|
||||
}else if(element instanceof ISignal<?>){
|
||||
return signal;
|
||||
}else if(element instanceof IHierNode){
|
||||
return folder;
|
||||
} else
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
return ((IHierNode)element).getName();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.provider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Collections2;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
|
||||
public class TxPropertiesContentProvider implements IStructuredContentProvider {
|
||||
|
||||
// private List<HierNode> nodes;
|
||||
private boolean showNodes=false;
|
||||
|
||||
@Override
|
||||
public void dispose() { }
|
||||
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
showNodes=!(newInput instanceof IHierNode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if(inputElement instanceof ITx){
|
||||
return Collections2.filter(((ITx)inputElement).getAttributes(), new Predicate<ITxAttribute>(){
|
||||
@Override
|
||||
public boolean apply(ITxAttribute arg0) {
|
||||
return (arg0 instanceof ITx)!=showNodes;
|
||||
}
|
||||
}).toArray();
|
||||
}else if(inputElement instanceof List<?>)
|
||||
return ((List<?>)inputElement).toArray();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,72 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2014, 2015 MINRES Technologies GmbH and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* MINRES Technologies GmbH - initial API and implementation
|
||||
*******************************************************************************/
|
||||
package com.minres.scviewer.e4.application.provider;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.jface.viewers.ILabelProviderListener;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.e4.application.parts.TransactionDetails;
|
||||
|
||||
public class TxPropertiesLabelProvider implements ITableLabelProvider {
|
||||
|
||||
private List<ILabelProviderListener> listeners = new ArrayList<ILabelProviderListener>();
|
||||
|
||||
public TxPropertiesLabelProvider() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addListener(ILabelProviderListener listener) {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeListener(ILabelProviderListener listener) {
|
||||
listeners.remove(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isLabelProperty(Object element, String property) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getColumnImage(Object element, int columnIndex) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getColumnText(Object element, int columnIndex) {
|
||||
ITxAttribute attribute = (ITxAttribute) element;
|
||||
String text = "";
|
||||
switch (columnIndex) {
|
||||
case TransactionDetails.COLUMN_FIRST:
|
||||
text = attribute.getName();
|
||||
break;
|
||||
case TransactionDetails.COLUMN_SECOND:
|
||||
text = attribute.getValue().toString();
|
||||
break;
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user