blob: 6d90c44631e531a4034c56c82f56c173ce9e3603 [file] [log] [blame]
/*=============================================================================#
# Copyright (c) 2009, 2017 Stephan Wahlbrink and others.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Public License 2.0 which is available at
# https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
# which is available at https://www.apache.org/licenses/LICENSE-2.0.
#
# SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
#
# Contributors:
# Stephan Wahlbrink <sw@wahlbrink.eu> - initial API and implementation
#=============================================================================*/
package org.eclipse.statet.rj.eclient.graphics.comclient;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.statet.ecommons.collections.IntArrayMap;
import org.eclipse.statet.ecommons.ts.core.SystemRunnable;
import org.eclipse.statet.ecommons.ts.core.Tool;
import org.eclipse.statet.rj.eclient.core.AbstractRToolRunnable;
import org.eclipse.statet.rj.eclient.core.RToolService;
import org.eclipse.statet.rj.server.client.AbstractRJComClient;
import org.eclipse.statet.rj.server.client.AbstractRJComClientGraphicActions;
public class ERClientGraphicActions extends AbstractRJComClientGraphicActions
implements ToolRClientGraphicActions {
private final Tool tool;
private final IntArrayMap<Boolean> resizeTasks= new IntArrayMap<>();
private final IntArrayMap<Boolean> closeTasks= new IntArrayMap<>();
public ERClientGraphicActions(final AbstractRJComClient rjs, final Tool tool) {
super(rjs);
this.tool= tool;
}
private class ResizeRunnable extends AbstractRToolRunnable implements SystemRunnable {
private final int devId;
private final Runnable beforeResize;
public ResizeRunnable(final int devId, final Runnable beforeResize) {
super("r/rj/gd/resize", "Resize R Graphic"); //$NON-NLS-1$
this.devId= devId;
this.beforeResize= beforeResize;
}
@Override
public boolean changed(final int event, final Tool process) {
switch (event) {
case MOVING_FROM:
case REMOVING_FROM:
return false;
case BEING_ABANDONED:
synchronized (ERClientGraphicActions.this.closeTasks) {
ERClientGraphicActions.this.resizeTasks.put(this.devId, Boolean.FALSE);
}
return true;
default:
return true;
}
}
@Override
public void run(final RToolService r,
final IProgressMonitor monitor) throws CoreException {
synchronized (ERClientGraphicActions.this.closeTasks) {
ERClientGraphicActions.this.resizeTasks.put(this.devId, Boolean.FALSE);
}
this.beforeResize.run();
doResizeGraphic(this.devId, monitor);
}
}
private class CloseRunnable extends AbstractRToolRunnable implements SystemRunnable {
private final int devId;
public CloseRunnable(final int devId) {
super("r/rj/gd/close", "Close R Graphic ("+(devId+1)+")"); //$NON-NLS-1$
this.devId= devId;
}
@Override
public boolean changed(final int event, final Tool tool) {
switch (event) {
case MOVING_FROM:
return false;
case REMOVING_FROM:
case BEING_ABANDONED:
case FINISHING_OK:
case FINISHING_ERROR:
case FINISHING_CANCEL:
synchronized (ERClientGraphicActions.this.closeTasks) {
ERClientGraphicActions.this.closeTasks.put(this.devId, Boolean.FALSE);
}
return true;
default:
return true;
}
}
@Override
public void run(final RToolService r,
final IProgressMonitor monitor) throws CoreException {
doCloseGraphic(this.devId, monitor);
}
}
@Override
public Tool getRHandle() {
return this.tool;
}
@Override
public String getRLabel() {
return this.tool.getLabel(Tool.DEFAULT_LABEL);
}
@Override
public IStatus resizeGraphic(final int devId, final Runnable beforeResize) {
synchronized (this.resizeTasks) {
if (this.resizeTasks.put(devId, Boolean.TRUE) == Boolean.TRUE) {
return Status.OK_STATUS;
}
}
return this.tool.getQueue().add(new ResizeRunnable(devId, beforeResize));
}
@Override
public IStatus closeGraphic(final int devId) {
synchronized (this.closeTasks) {
if (this.closeTasks.put(devId, Boolean.TRUE) == Boolean.TRUE) {
return Status.OK_STATUS;
}
}
return this.tool.getQueue().add(new CloseRunnable(devId));
}
}