[WIP ]reorganized dir structure

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

View File

@ -0,0 +1,779 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.status;
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;
import org.eclipse.wb.swt.SWTResourceManager;
import org.osgi.service.prefs.Preferences;
/**
* The Heap Status control, which shows the heap usage statistics in the window trim.
* Part of the code is taken from the eclipse internal implementation
*/
public class HeapStatus extends Composite {
/** The armed. */
private boolean armed;
/** The gc image. */
private Image gcImage;
/** The disabled gc image. */
private Image disabledGcImage;
/** The arm col. */
private Color bgCol, usedMemCol, lowMemCol, freeMemCol, topLeftCol, bottomRightCol, sepCol, textCol, markCol, armCol;
/** The button. */
private Canvas button;
/** The preferences. */
private Preferences preferences;
/** The update interval. */
private int updateInterval;
/** The show max. */
private boolean showMax;
/** The total mem. */
private long totalMem;
/** The prev total mem. */
private long prevTotalMem = -1L;
/** The prev used mem. */
private long prevUsedMem = -1L;
/** The has changed. */
private boolean hasChanged;
/** The used mem. */
private long usedMem;
/** The mark. */
private long mark = -1;
/** The img bounds. */
// start with 12x12
private Rectangle imgBounds = new Rectangle(0,0,12,12);
/** The max mem. */
private long maxMem = Long.MAX_VALUE;
/** The max mem known. */
private boolean maxMemKnown;
/** The low mem threshold. */
private float lowMemThreshold = 0.05f;
/** The show low mem threshold. */
private boolean showLowMemThreshold = true;
/** The update tooltip. */
private boolean updateTooltip = false;
/** The is in gc. */
protected volatile boolean isInGC = false;
/** The timer. */
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);
}
}
};
/** The pref listener. */
private final IPreferenceChangeListener prefListener = new IPreferenceChangeListener() {
@Override
public void preferenceChange(PreferenceChangeEvent event) {
if (IHeapStatusConstants.PREF_UPDATE_INTERVAL.equals(event.getKey())) {
setUpdateIntervalInMS(preferences.getInt(IHeapStatusConstants.PREF_UPDATE_INTERVAL, 100));
}
else if (IHeapStatusConstants.PREF_SHOW_MAX.equals(event.getKey())) {
showMax = preferences.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, Preferences preferences) {
super(parent, SWT.NONE);
maxMem = getMaxMem();
maxMemKnown = maxMem != Long.MAX_VALUE;
this.preferences = preferences;
if(this.preferences instanceof IEclipsePreferences)
((IEclipsePreferences)this.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 = SWTResourceManager.getColor(255, 70, 70); // medium red
freeMemCol = SWTResourceManager.getColor(255, 190, 125); // light orange
bgCol = SWTResourceManager.getColor(SWT.COLOR_WIDGET_BACKGROUND);
sepCol = topLeftCol = armCol = SWTResourceManager.getColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
bottomRightCol = SWTResourceManager.getColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW);
markCol = textCol = SWTResourceManager.getColor(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);
}
}
});
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setBackground(org.eclipse.swt.graphics.Color)
*/
@Override
public void setBackground(Color color) {
bgCol = color;
button.redraw();
button.update();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#setForeground(org.eclipse.swt.graphics.Color)
*/
@Override
public void setForeground(Color color) {
if (color == null) {
usedMemCol = getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
} else {
usedMemCol = color;
}
button.redraw();
button.update();
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Control#getForeground()
*/
@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.
*
* @return the max mem
*/
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;
}
/**
* Sets the update interval in ms.
*
* @param interval the new update interval in ms
*/
private void setUpdateIntervalInMS(int interval) {
updateInterval = Math.max(100, interval);
}
/**
* Do dispose.
*/
private void doDispose() {
if(preferences instanceof IEclipsePreferences)
((IEclipsePreferences)preferences).removePreferenceChangeListener(prefListener);
if (gcImage != null) {
gcImage.dispose();
}
if (disabledGcImage != null) {
disabledGcImage.dispose();
}
}
/* (non-Javadoc)
* @see org.eclipse.swt.widgets.Composite#computeSize(int, int, boolean)
*/
@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);
}
/**
* Arm.
*
* @param armed the armed
*/
private void arm(boolean armed) {
if (this.armed == armed) {
return;
}
this.armed = armed;
button.redraw();
button.update();
}
/**
* Gc running.
*
* @param isInGC the is in gc
*/
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);
}
/**
* Fill menu.
*
* @param menuMgr the menu mgr
*/
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();
}
/**
* Gc.
*/
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();
}
/**
* Busy gc.
*/
private void busyGC() {
for (int i = 0; i < 2; ++i) {
System.gc();
System.runFinalization();
}
}
/**
* Paint button.
*
* @param gc the gc
*/
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);
}
}
/**
* Paint composite.
*
* @param gc the gc
*/
private void paintComposite(GC gc) {
if (showMax && maxMemKnown) {
paintCompositeMaxKnown(gc);
} else {
paintCompositeMaxUnknown(gc);
}
}
/**
* Paint composite max unknown.
*
* @param gc the 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);
}
}
/**
* Paint composite max known.
*
* @param gc the gc
*/
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
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.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);
}
}
/**
* Paint mark.
*
* @param gc the gc
* @param x the x
* @param y the y
* @param h the 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);
}
/**
* Update stats.
*/
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;
}
}
/**
* Update tool tip.
*/
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).
*
* @param numBytes the num bytes
* @return the string
*/
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).
*
* @param numBytes the num bytes
* @return the long
*/
private long convertToMeg(long numBytes) {
return (numBytes + (512 * 1024)) / (1024 * 1024);
}
/**
* The Class SetMarkAction.
*/
class SetMarkAction extends Action {
/**
* Instantiates a new sets the mark action.
*/
SetMarkAction() {
super("&Set Mark");
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
setMark();
}
}
/**
* The Class ClearMarkAction.
*/
class ClearMarkAction extends Action {
/**
* Instantiates a new clear mark action.
*/
ClearMarkAction() {
super("&Clear Mark");
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
clearMark();
}
}
/**
* The Class ShowMaxAction.
*/
class ShowMaxAction extends Action {
/**
* Instantiates a new show max action.
*/
ShowMaxAction() {
super("Show &Max Heap", IAction.AS_CHECK_BOX);
setEnabled(maxMemKnown);
setChecked(showMax);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run() {
preferences.putBoolean(IHeapStatusConstants.PREF_SHOW_MAX, isChecked());
redraw();
}
}
/**
* The Class CloseHeapStatusAction.
*/
class CloseHeapStatusAction extends Action{
/**
* Instantiates a new close heap status action.
*/
CloseHeapStatusAction(){
super("&Close");
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.Action#run()
*/
@Override
public void run(){
// WorkbenchWindow wbw = (WorkbenchWindow) PlatformUI.getWorkbench()
// .getActiveWorkbenchWindow();
// if (wbw != null) {
// wbw.showHeapStatus(false);
// }
System.out.println("NYI");
}
}
}

View File

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

View File

@ -0,0 +1,249 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.status;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.inject.Inject;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
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.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.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.osgi.service.prefs.PreferencesService;
import com.minres.scviewer.e4.application.AppModelId;
import com.minres.scviewer.e4.application.Messages;
/**
* The Class StatusBarControl.
*/
public class StatusBarControl {
/** The Constant STATUS_UPDATE. */
public static final String STATUS_UPDATE="StatusUpdate"; //$NON-NLS-1$
/** The model service. */
@Inject EModelService modelService;
/** The osgi preverences. */
@Inject @Optional PreferencesService osgiPreverences;
/** The sync. */
private final UISynchronize sync;
/** The manager. */
protected StatusLineManager manager;
/** The monitor. */
private SyncedProgressMonitor monitor;
/** The progress bar. */
private ProgressBar progressBar;
/**
* Instantiates a new status bar control.
*
* @param sync the sync
*/
@Inject
public StatusBarControl(UISynchronize sync) {
this.sync=sync;
manager = new StatusLineManager();
manager.update(true);
}
/**
* Creates the widget.
*
* @param parent the parent
* @param toolControl the tool control
*/
@PostConstruct
void createWidget(Composite parent, MToolControl toolControl) {
if (toolControl.getElementId().equals(AppModelId.TOOLCONTROL_ORG_ECLIPSE_UI_STATUSLINE)) { //$NON-NLS-1$
createStatusLine(parent, toolControl);
} else if (toolControl.getElementId().equals(AppModelId.TOOLCONTROL_ORG_ECLIPSE_UI_HEAPSTATUS)) { //$NON-NLS-1$
createHeapStatus(parent, toolControl);
} else if (toolControl.getElementId().equals(AppModelId.TOOLCONTROL_ORG_ECLIPSE_UI_PROGRESSBAR)) { //$NON-NLS-1$
createProgressBar(parent, toolControl);
}
}
/**
* Destroy.
*/
@PreDestroy
void destroy() {
if (manager != null) {
manager.dispose();
manager = null;
}
}
/**
* Creates the progress bar.
*
* @param parent the parent
* @param toolControl the tool control
*/
private void createProgressBar(Composite parent, MToolControl toolControl) {
new Label(parent, SWT.NONE);
progressBar = new ProgressBar(parent, SWT.SMOOTH);
progressBar.setBounds(100, 10, 200, 20);
new Label(parent, SWT.NONE);
monitor=new SyncedProgressMonitor(progressBar);
Job.getJobManager().setProgressProvider(new ProgressProvider() {
@Override
public IProgressMonitor createMonitor(Job job) {
return monitor.addJob(job);
}
});
}
/**
* Creates the heap status.
*
* @param parent the parent
* @param toolControl the tool control
*/
private void createHeapStatus(Composite parent, MToolControl toolControl) {
new HeapStatus(parent, osgiPreverences.getSystemPreferences());
}
/**
* Creates the status line.
*
* @param parent the parent
* @param toolControl the tool control
*/
private void createStatusLine(Composite parent, MToolControl toolControl) {
// IEclipseContext context = modelService.getContainingContext(toolControl);
manager.createControl(parent);
}
/**
* Gets the status event.
*
* @param text the text
* @return the status event
*/
@Inject @Optional
public void getStatusEvent(@UIEventTopic(STATUS_UPDATE) String text) {
if(manager!=null ){
manager.setMessage(text);
}
}
/**
* The Class SyncedProgressMonitor.
*/
private final class SyncedProgressMonitor extends NullProgressMonitor {
// thread-Safe via thread confinement of the UI-Thread
/** The running tasks. */
// (means access only via UI-Thread)
private long runningTasks = 0L;
/** The progress bar. */
private ProgressBar progressBar;
/**
* Instantiates a new synced progress monitor.
*
* @param progressBar the progress bar
*/
public SyncedProgressMonitor(ProgressBar progressBar) {
super();
this.progressBar = progressBar;
runningTasks=0;
progressBar.setSelection(0);
progressBar.setEnabled(false);
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.NullProgressMonitor#beginTask(java.lang.String, int)
*/
@Override
public void beginTask(final String name, final int totalWork) {
sync.asyncExec(new Runnable() {
@Override
public void run() {
runningTasks++;
if(runningTasks == 1) { // --- no task is running at the moment ---
progressBar.setEnabled(true);
progressBar.setSelection(0);
}
progressBar.setMaximum(totalWork);
progressBar.setToolTipText(Messages.StatusBarControl_1 + runningTasks + Messages.StatusBarControl_2 + name);
}
});
}
/* (non-Javadoc)
* @see org.eclipse.core.runtime.NullProgressMonitor#worked(int)
*/
@Override
public void worked(final int work) {
sync.asyncExec(new Runnable() {
@Override
public void run() {
progressBar.setSelection(progressBar.getSelection() + work);
}
});
}
/**
* Adds the job.
*
* @param job the job
* @return the i progress monitor
*/
public IProgressMonitor addJob(Job job){
if(job != null){
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(final IJobChangeEvent event) {
sync.asyncExec(new Runnable() {
@Override
public void run() {
if(event.getResult()==null) return;
if(runningTasks>0) runningTasks--;
if (runningTasks > 0){ // --- some tasks are still running ---
progressBar.setToolTipText(Messages.StatusBarControl_3 + runningTasks);
} else { // --- all tasks are done (a reset of selection could also be done) ---
progressBar.setToolTipText(Messages.StatusBarControl_4);
progressBar.setSelection(progressBar.getMaximum());
progressBar.setEnabled(false);
}
}
});
// clean-up
event.getJob().removeJobChangeListener(this);
}
});
}
return this;
}
}
}

View File

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

View File

@ -0,0 +1,209 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.status;
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.jface.viewers.IStructuredSelection;
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;
import com.minres.scviewer.e4.application.Messages;
/**
* The Class WaveStatusBarControl.
*/
public class WaveStatusBarControl extends StatusBarControl {
/** The Constant ZOOM_LEVEL. */
public static final String ZOOM_LEVEL="ZoomLevelUpdate"; //$NON-NLS-1$
/** The Constant CURSOR_TIME. */
public static final String CURSOR_TIME="CursorPosUpdate"; //$NON-NLS-1$
/** The Constant MARKER_TIME. */
public static final String MARKER_TIME="MarkerPosUpdate"; //$NON-NLS-1$
/** The Constant MARKER_DIFF. */
public static final String MARKER_DIFF="MarlerDiffUpdate"; //$NON-NLS-1$
/** The model service. */
@Inject
EModelService modelService;
/**
* The Class TextContributionItem.
*/
class TextContributionItem extends ContributionItem {
/** The label string. */
final String labelString;
/** The width. */
//final int width;
/** The text. */
CLabel label, text;
/** The content. */
private String content;
/**
* Instantiates a new text contribution item.
*
* @param labelString the label string
* @param width the width
*/
public TextContributionItem(String labelString /*, int width */) {
super();
this.labelString = labelString;
//this.width=width;
content=""; //$NON-NLS-1$
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.ContributionItem#fill(org.eclipse.swt.widgets.Composite)
*/
@Override
public void fill(Composite parent) {
Composite box=new Composite(parent, SWT.NONE); //NONE
box.setLayout(new GridLayout(2, false));
label=new CLabel(box, SWT.SHADOW_NONE);
label.setText(labelString);
text=new CLabel(box, SWT.SHADOW_IN);
text.setAlignment(SWT.RIGHT);
//GridData layoutData=new GridData(SWT.DEFAULT, SWT.DEFAULT, true, false);
GridData layoutData=new GridData(SWT.DEFAULT, SWT.DEFAULT, true, false);
layoutData.minimumWidth=70;
//layoutData.minimumWidth=width;
text.setLayoutData(layoutData);
}
/* (non-Javadoc)
* @see org.eclipse.jface.action.ContributionItem#isDynamic()
*/
@Override
public boolean isDynamic() {
return true;
}
/**
* Sets the text.
*
* @param message the new text
*/
public void setText(String message){
this.content=message;
if(text!=null && !text.isDisposed()) text.setText(content);
}
}
/** The zoom contribution. */
TextContributionItem cursorContribution, markerContribution, markerDiffContribution, zoomContribution;
/**
* Instantiates a new wave status bar control.
*
* @param sync the sync
*/
@Inject
public WaveStatusBarControl(UISynchronize sync) {
super(sync);
cursorContribution = new TextContributionItem(Messages.WaveStatusBarControl_5 /*, 150 */); //150
markerContribution = new TextContributionItem(Messages.WaveStatusBarControl_6 /*, 150 */); //150
markerDiffContribution = new TextContributionItem(Messages.WaveStatusBarControl_7 /*, 150 */); //150
zoomContribution = new TextContributionItem(Messages.WaveStatusBarControl_8 /*, 60 */); //60
manager.appendToGroup(StatusLineManager.BEGIN_GROUP,cursorContribution);
manager.appendToGroup(StatusLineManager.BEGIN_GROUP,markerContribution);
manager.appendToGroup(StatusLineManager.BEGIN_GROUP,markerDiffContribution);
manager.appendToGroup(StatusLineManager.BEGIN_GROUP, zoomContribution);
}
/**
* Sets the selection.
*
* @param selection the new selection
*/
@Inject
public void setSelection(@Named(IServiceConstants.ACTIVE_SELECTION)@Optional IStructuredSelection selection){
if(manager!=null && selection!=null){
switch(selection.size()){
case 0:
manager.setMessage(""); //$NON-NLS-1$
break;
case 1:
manager.setMessage(selection.getFirstElement().getClass().getSimpleName()+Messages.WaveStatusBarControl_10);
break;
default:
manager.setMessage(""+selection.size()+Messages.WaveStatusBarControl_12); //$NON-NLS-1$
break;
}
}
}
/**
* Gets the zoom event.
*
* @param text the text
* @return the zoom event
*/
@Inject @Optional
public void getZoomEvent(@UIEventTopic(ZOOM_LEVEL) String text) {
zoomContribution.setText(text);
}
/**
* Gets the cursor event.
*
* @param text the text
* @return the cursor event
*/
@Inject @Optional
public void getCursorEvent(@UIEventTopic(CURSOR_TIME) String text) {
cursorContribution.setText(text);
}
/**
* Gets the marker event.
*
* @param text the text
* @return the marker event
*/
@Inject @Optional
public void getMarkerEvent(@UIEventTopic(MARKER_TIME) String text) {
markerContribution.setText(text);
}
/**
* Gets the diff event.
*
* @param text the text
* @return the diff event
*/
@Inject @Optional
public void getDiffEvent(@UIEventTopic(MARKER_DIFF) String text) {
markerDiffContribution.setText(text);
}
}

View File

@ -0,0 +1,180 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.util;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Hashtable;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
/**
* Class monitoring a {@link File} for changes.
*
*/
public class FileMonitor {
/** The timer. */
private Timer timer;
/** The enabled. */
private boolean enabled;
/** The timer entries. */
private Hashtable<String, FileSetMonitorTask> timerEntries;
/**
* Constructor.
*/
public FileMonitor() {
// Create timer, run timer thread as daemon.
timer = new Timer(true);
timerEntries = new Hashtable<String, FileSetMonitorTask>();
enabled=true;
}
/**
* Adds a monitored file with a FileChangeListener.
*
* @param listener listener to notify when the file changed.
* @param file the file
* @param period polling period in milliseconds.
* @return the i modification checker
*/
public IModificationChecker addFileChangeListener(IFileChangeListener listener, File file, long period) {
return addFileChangeListener(listener, Arrays.asList(new File[]{file}), period);
}
/**
* Adds a monitored file with a FileChangeListener.
* List<File> filesToLoad
*
* @param listener listener to notify when the file changed.
* @param files the files
* @param period polling period in milliseconds.
* @return the i modification checker
*/
public IModificationChecker addFileChangeListener(IFileChangeListener listener, List<File> files, long period) {
removeFileChangeListener(listener);
FileSetMonitorTask task = new FileSetMonitorTask(listener, files, period);
timerEntries.put(Integer.toHexString(listener.hashCode()), task);
timer.schedule(task, period, period);
return task;
}
/**
* Remove the listener from the notification list.
*
* @param listener
* the listener to be removed.
*/
public void removeFileChangeListener(IFileChangeListener listener) {
FileSetMonitorTask task = timerEntries.remove(Integer.toHexString(listener.hashCode()));
if (task != null) task.cancel();
}
/**
* Fires notification that a file changed.
*
* @param listener
* file change listener
* @param file
* the file that changed
*/
protected void fireFileChangeEvent(IFileChangeListener listener, List<File> file) {
if(enabled) listener.fileChanged(file);
}
/**
* Checks if is enabled.
*
* @return true, if is enabled
*/
public boolean isEnabled() {
return enabled;
}
/**
* Sets the enabled.
*
* @param enabled the new enabled
*/
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
/**
* File monitoring task.
*/
class FileSetMonitorTask extends TimerTask implements IModificationChecker{
/** The listener. */
IFileChangeListener listener;
/** The monitored files. */
private List<File> monitoredFiles;
/** The last modified times. */
private List<Long> lastModifiedTimes;
/** The period. */
public final long period;
/**
* Instantiates a new file set monitor task.
*
* @param listener the listener
* @param monitoredFiles the monitored files
* @param period the period
*/
public FileSetMonitorTask(IFileChangeListener listener, List<File> monitoredFiles, long period) {
this.period=period;
this.monitoredFiles = monitoredFiles;
this.listener = listener;
lastModifiedTimes= new ArrayList<>();
for(File monitoredFile:monitoredFiles){
Long lmt = 0L;
try {
lmt=monitoredFile.lastModified();
} catch(Exception e){}
lastModifiedTimes.add(lmt);
}
}
/* (non-Javadoc)
* @see java.util.TimerTask#run()
*/
public void run() {
check();
}
/* (non-Javadoc)
* @see com.minres.scviewer.e4.application.internal.util.IModificationChecker#check()
*/
public void check() {
boolean res = false;
for(int i=0; i<monitoredFiles.size(); ++i){
File file = monitoredFiles.get(i);
Long lmt = 0L;
try {
lmt=file.lastModified();
} catch(Exception e){}
if (!lmt.equals(lastModifiedTimes.get(i)))
res |= true;
lastModifiedTimes.set(i, lmt);
}
if(res)
fireFileChangeEvent(this.listener, monitoredFiles);
}
}
}

View File

@ -0,0 +1,30 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.util;
import java.io.File;
import java.util.List;
/**
* Listener interested in {@link File} changes.
*
*/
public interface IFileChangeListener {
/**
* Invoked when a file changes.
*
* @param file the file
*/
public void fileChanged(List<File> file);
}

View File

@ -0,0 +1,23 @@
/*******************************************************************************
* Copyright (c) 2015 MINRES Technologies GmbH and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* MINRES Technologies GmbH - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.e4.application.internal.util;
/**
* The Interface IModificationChecker. Allows to trigger a check independent of the timer
*/
public interface IModificationChecker {
/**
* Check.
*/
public void check();
}