Skip to content

Commit

Permalink
Corrects various issues introduced in the previous commit on NEWT
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Oct 14, 2021
1 parent 1f2a3f0 commit 3651574
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 11 deletions.
@@ -1,3 +1,13 @@
/*******************************************************************************************************
*
* LayeredDisplaySynchronizer.java, in ummisco.gama.ui.experiment, is part of the source code of the
* GAMA modeling and simulation platform (v.1.8.2).
*
* (c) 2007-2021 UMI 209 UMMISCO IRD/SU & Partners (IRIT, MIAT, TLU, CTU)
*
* Visit https://github.com/gama-platform/gama for license information and contacts.
*
********************************************************************************************************/
package ummisco.gama.ui.views.displays;

import static ummisco.gama.dev.utils.FLAGS.USE_OLD_SYNC_STRATEGY;
Expand All @@ -8,30 +18,56 @@
import msi.gama.common.interfaces.IDisplaySynchronizer;
import ummisco.gama.dev.utils.DEBUG;

/**
* The Class LayeredDisplaySynchronizer.
*/
public class LayeredDisplaySynchronizer implements IDisplaySynchronizer {

static {
DEBUG.OFF();
}

/** The view update lock. */
Semaphore viewUpdateLock = new Semaphore(0);

/** The surface render lock. */
Semaphore surfaceRenderLock = new Semaphore(1);

/** The surface realisation lock. */
Semaphore surfaceRealisationLock = new Semaphore(0);

/** The surface. */
IDisplaySurface surface;

/**
* Acquire view lock.
*
* @throws InterruptedException the interrupted exception
*/
private void acquireViewLock() throws InterruptedException {
if (viewUpdateLock.availablePermits() > 0) { viewUpdateLock.drainPermits(); }
viewUpdateLock.acquire();
}

/**
* Release view lock.
*/
private void releaseViewLock() {
viewUpdateLock.release();
}

/**
* Acquire lock.
*
* @throws InterruptedException the interrupted exception
*/
private synchronized void acquireLock() throws InterruptedException {
wait();
}

/**
* Release lock.
*/
private synchronized void releaseLock() {
notify();
}
Expand Down Expand Up @@ -63,9 +99,7 @@ public void waitForRenderingToBeFinished() {
DEBUG.OUT("Waiting for surface to be rendered: " + Thread.currentThread().getName());
try {
if (USE_OLD_SYNC_STRATEGY) {
while (!surface.isRendered() && !surface.isDisposed()) {
Thread.sleep(10);
}
while (!surface.isRendered() && !surface.isDisposed()) { Thread.sleep(10); }
} else {
if (surfaceRenderLock.availablePermits() > 0) { surfaceRenderLock.drainPermits(); }
surfaceRenderLock.acquire();
Expand All @@ -80,9 +114,14 @@ public void signalRenderingIsFinished() {
surfaceRenderLock.release();
}

/**
* Sets the surface.
*
* @param surface the new surface
*/
public void setSurface(final IDisplaySurface surface) {
this.surface = surface;
surface.setDisplaySynchronizer(this);
if (surface != null) { surface.setDisplaySynchronizer(this); }

}

Expand Down
Expand Up @@ -79,6 +79,9 @@ public abstract class LayeredDisplayView extends GamaViewPart

/** The in init phase. */
protected volatile boolean inInitPhase = true;

/** The closing. */
private volatile boolean closing = false;

@Override
public void setIndex(final int index) { realIndex = index; }
Expand Down
Expand Up @@ -341,8 +341,12 @@ public static void hideView(final String id) {
run(() -> {
final IWorkbenchPage activePage = getPage();
if (activePage == null) return;
final IWorkbenchPart part = activePage.findView(id);
if (part != null && activePage.isPartVisible(part)) { activePage.hideView((IViewPart) part); }
final IViewReference view = activePage.findViewReference(id);
if (view != null) {
IWorkbenchPart part = view.getPart(false);
if (part != null && activePage.isPartVisible(part)) { activePage.hideView((IViewPart) part); }
}

});

}
Expand Down
Expand Up @@ -73,9 +73,6 @@ public abstract class GamaViewPart extends ViewPart
/** The root composite. */
private Composite rootComposite;

/** The closing. */
protected volatile boolean closing;

/**
* The Enum UpdatePriority.
*/
Expand Down Expand Up @@ -349,8 +346,6 @@ public void displayTooltip(final String text, final GamaUIColor color) {

@Override
public void close(final IScope scope) {
if (closing) return;
closing = true;
WorkbenchHelper.asyncRun(() -> {
try {
WorkbenchHelper.hideView(GamaViewPart.this);
Expand Down

0 comments on commit 3651574

Please sign in to comment.