Commit 0f5f58bb authored by Johannes Eder's avatar Johannes Eder
Browse files

Merge branch '4015' into 'master'

4015

See merge request af3/af3!353
parents 50f6f564 2daff1b5
......@@ -7,5 +7,6 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="src" path="res"/>
<classpathentry kind="output" path="build"/>
</classpath>
......@@ -30,4 +30,5 @@ Export-Package: org.fortiss.af3.component.ui,
org.fortiss.af3.component.ui.simulator.component,
org.fortiss.af3.component.ui.simulator.menu,
org.fortiss.af3.component.ui.simulator.views,
org.fortiss.af3.component.ui.simulatorfx.views,
org.fortiss.af3.component.ui.utils
......@@ -154,28 +154,32 @@
<extension
point="org.eclipse.ui.views">
<view
allowMultiple="false"
class="org.fortiss.af3.component.ui.simulator.SimulationView"
icon="icons/simulation.gif"
id="org.fortiss.af3.component.ui.simulator.SimulationView"
name="Simulation"
class="org.fortiss.af3.component.ui.simulatorfx.views.InputOutputTableFXView"
icon="icons/inputoutput.gif"
id="org.fortiss.af3.component.ui.simulatorfx.views.InputOutputTableFXView"
name="Input/Output View FX"
restorable="true">
</view>
<view
allowMultiple="true"
class="org.fortiss.af3.component.ui.simulator.component.InputOutputTableView"
icon="icons/inputoutput.gif"
id="org.fortiss.af3.component.ui.simulator.component.InputOutputTableView"
name="Input/Output View"
restorable="false">
class="org.fortiss.af3.component.ui.simulatorfx.views.DataStateTableViewFX"
icon="icons/simulator/datastate.gif"
id="org.fortiss.af3.component.ui.simulatorfx.views.DataStateTableViewFX"
name="Data State View FX"
restorable="true">
</view>
<view
allowMultiple="true"
class="org.fortiss.af3.component.ui.simulator.component.GraphicalStructureSimulationView"
icon="icons/componentstructure.gif"
id="org.fortiss.af3.component.ui.simulator.component.GraphicalStructureSimulationView"
name="Component Simulation View"
restorable="false">
class="org.fortiss.af3.component.ui.simulatorfx.views.GraphicalStructureSimulationFXView"
icon="icons/component.gif"
id="org.fortiss.af3.component.ui.simulatorfx.views.GraphicalStructureSimulationFXView"
name="Component Simulation View FX"
restorable="true">
</view>
<view
class="org.fortiss.af3.component.ui.simulatorfx.views.SimulationNavigatorFX"
icon="icons/simulation.gif"
id="org.fortiss.af3.component.ui.simulatorfx.views.SimulationNavigatorFX"
name="Simulation Navigator FX"
restorable="true">
</view>
</extension>
<extension
......
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ComboBox?>
<?import javafx.scene.control.TextField?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.FlowPane?>
<?import javafx.scene.layout.HBox?>
<BorderPane fx:id="borderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="458.0" prefWidth="722.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
<top>
<FlowPane BorderPane.alignment="TOP_LEFT">
<children>
<HBox alignment="TOP_RIGHT">
<children>
<Button fx:id="playBtn" mnemonicParsing="false" onAction="#onPlayBtn" text="Play" />
<Button fx:id="pauseBtn" mnemonicParsing="false" onAction="#onPauseBtn" text="Pause" />
<Button fx:id="backBtn" mnemonicParsing="false" onAction="#onBackBtn" text="StepBack" />
<Button fx:id="forwBtn" mnemonicParsing="false" onAction="#onForwBtn" text="StepForward" />
<Button fx:id="resetBtn" mnemonicParsing="false" onAction="#onResetBtn" text="Reset" />
<ComboBox fx:id="speedCombo" minWidth="70.0" onAction="#onSpeedCombo" prefWidth="100.0" promptText="Speed" />
<TextField fx:id="currentStep" minWidth="40.0" prefWidth="40.0" promptText="Current Step" />
</children>
</HBox>
</children>
</FlowPane>
</top>
</BorderPane>
ComponentControllerFactory.java a5feb78f57aee4a8206866ef2dc6ca13bb145305 GREEN
ComponentModelFactory.java 9141373b9498b8e947ef1ca8921128bdf66ec308 GREEN
ComponentModelFactory.java f8e7de4b6928970a5ba5300b4349a04c5064b63b GREEN
ComponentStructureFXEditor.java f7129096fe9e509f199d07f2db597dac8297a3a2 GREEN
ComponentStructureFXEditorBinding.java 19ca73be6a4ea974994d26db537329878748b20d GREEN
ComponentVisualFactory.java c784b5e87c08abc9a3e201c11bc08b93fce20f6a GREEN
ComponentVisualFactory.java 71c0be1ba3c396fd6e5804d3310ae0e7dae13b45 GREEN
......@@ -21,10 +21,10 @@ import static org.fortiss.tooling.common.util.LambdaUtils.filterList;
import java.util.List;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.IModelFactory;
import org.fortiss.af3.component.model.Channel;
import org.fortiss.af3.component.model.Component;
import org.fortiss.tooling.base.model.element.IConnection;
import org.fortiss.tooling.common.ui.javafx.lwfxef.model.IModelFactory;
/**
* The implementation of the {@link IModelFactory} for the component editor.
......@@ -33,7 +33,7 @@ import org.fortiss.tooling.base.model.element.IConnection;
*/
public final class ComponentModelFactory implements IModelFactory {
/** The currently edited component. */
private final Component rootElement;
private Component rootElement;
/** Constructor. */
public ComponentModelFactory(Component root) {
......
......@@ -38,7 +38,7 @@ import org.fortiss.tooling.common.ui.javafx.lwfxef.visual.IVisualFactory;
* @author hoelzl
* @author diewald
*/
public final class ComponentVisualFactory implements IVisualFactory {
public class ComponentVisualFactory implements IVisualFactory {
/** {@inheritDoc} */
@Override
public IContentVisual createContentVisual(IContentMVCBundle modelBundle) {
......
SimulationManager.java d1d0df983a08206bed9d6675a8dc6818562bd429 GREEN
SimulationPerspective.java 6d99ef287c75a0b0d40327a1ae5ddf9ff6003f2f GREEN
SimulationView.java 9e364404ebbb86f436b208ba289f47788b24fbc4 GREEN
SimulatorEasyStartMenu.java 56e223e4c2ef1d7263c09a0a358560f2cb9f0224 GREEN
SimulationManager.java cb86cfa954d590fb12f18336ef543236bff3164d GREEN
SimulationPerspective.java f7f95ca84f0d3f4388a84029a88f511e8b1e319d GREEN
SimulatorEasyStartMenu.java 01530a144c7c41f94803e209e8a9368b1bdb94cc GREEN
SimulatorExecutionTarget.java 2fabcff80c0bd39ba171846a69f38455878d159b GREEN
SimulatorExecutionTargetBase.java d6bacdb0182e445f3f8b9f2594f18f79ff9b431e GREEN
......@@ -20,7 +20,6 @@ import static org.fortiss.tooling.kernel.ui.util.MessageUtilsExtended.askQuestio
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import org.eclipse.ui.IPropertyListener;
import org.fortiss.af3.component.simulator.ExecutableComponent;
......@@ -32,7 +31,7 @@ import org.fortiss.tooling.base.model.element.IModelElementSpecification;
*
* @author hoelzl
*/
public class SimulationManager extends Observable {
public class SimulationManager {
/**
* Public ID for simulation changed event. This event occurs just after the
......@@ -68,12 +67,6 @@ public class SimulationManager extends Observable {
*/
public static final int SIMULATION_STEPPED_BACK_EVENT = 5;
/**
* Public ID for simulation about to step back event. This event occurs just
* before the executable's <code>performStepBack()</code> method is called.
*/
public static final int SIMULATION_ABOUT_TO_STEP_BACK_EVENT = 6;
/**
* Public ID for simulation refresh event. This event occurs after the
* back-end completed initialization or performed a step or some view
......@@ -82,7 +75,12 @@ public class SimulationManager extends Observable {
* updating visuals to changes of the back-end like performing a simulation
* step should be handled by the respective events.
*/
public static final int SIMULATION_REFRESH_EVENT = 5;
public static final int SIMULATION_REFRESH_EVENT = 6;
/**
* Public ID for simulation about to step back event. This event occurs just
* before the executable's <code>performStepBack()</code> method is called.
*/
public static final int SIMULATION_ABOUT_TO_STEP_BACK_EVENT = 7;
/** Default simulation speed => 4 simulation steps per second. */
private static final int DEFAULT_SPEED = 250;
......@@ -136,13 +134,10 @@ public class SimulationManager extends Observable {
simulationThread = new Thread("AF3 Simulation") {
@Override
public void run() {
int i = 0;
while(!isInterrupted()) {
long startTime = System.currentTimeMillis();
if(!performingStep) {
performStep();
setChanged();
notifyObservers();
}
if(lastException != null) {
break;
......@@ -159,7 +154,6 @@ public class SimulationManager extends Observable {
if(remainingDelay < 0 && !ignoreSpeedWarning) {
ignoreSpeedWarning = askQuestionInUIThread("Simulation Error",
"The length of the simulation step is too small. Do you want to continue?");
i++;
if(!ignoreSpeedWarning) {
reset();
}
......
......@@ -18,6 +18,7 @@ package org.fortiss.af3.component.ui.simulator;
import org.eclipse.ui.IFolderLayout;
import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IPerspectiveFactory;
import org.fortiss.af3.component.ui.simulatorfx.views.SimulationNavigatorFX;
/**
* Perspective for the component simulator.
......@@ -37,7 +38,7 @@ public class SimulationPerspective implements IPerspectiveFactory {
IFolderLayout left =
layout.createFolder("left", IPageLayout.LEFT, 0.2f, layout.getEditorArea());
left.addView(SimulationView.ID);
left.addView(SimulationNavigatorFX.ID);
IFolderLayout top =
layout.createFolder("top", IPageLayout.TOP, 0.6f, layout.getEditorArea());
......
/*-------------------------------------------------------------------------+
| Copyright 2011 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.af3.component.ui.simulator;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.getDefault;
import static org.fortiss.af3.component.ui.AF3ComponentUIActivator.getImageDescriptor;
import static org.fortiss.tooling.base.ui.utils.ActionUtils.setUpAction;
import static org.fortiss.tooling.kernel.ui.util.SelectionUtils.checkAndPickFirst;
import static org.fortiss.tooling.kernel.utils.LoggingUtils.error;
import java.text.Collator;
import java.util.EventListener;
import java.util.Observable;
import java.util.Observer;
import org.conqat.ide.commons.ui.jface.TreeContentProviderBase;
import org.eclipse.core.runtime.Assert;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.ActionContributionItem;
import org.eclipse.jface.action.ContributionItem;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionItem;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.ViewerComparator;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.FocusAdapter;
import org.eclipse.swt.events.FocusEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.ToolBar;
import org.eclipse.swt.widgets.ToolItem;
import org.eclipse.ui.IActionBars;
import org.eclipse.ui.IPartService;
import org.eclipse.ui.IPropertyListener;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.part.ViewPart;
import org.fortiss.af3.component.model.Component;
import org.fortiss.af3.component.simulator.ExecutableComponent;
import org.fortiss.af3.component.ui.simulator.menu.ISimulationContextMenuContributor;
import org.fortiss.af3.component.ui.simulator.menu.ISimulationContextMenuService;
import org.fortiss.af3.component.ui.simulator.views.SimulationViewBase;
import org.fortiss.tooling.base.model.element.IModelElementSpecification;
import org.fortiss.tooling.kernel.ui.service.IModelElementHandlerService;
/**
* The simulation view shows the tree of simulated components.
*
* @author hoelzl
*/
public class SimulationView extends ViewPart implements IPropertyListener, EventListener, Observer {
/** The ID of this view. */
public static final String ID = SimulationView.class.getName();
/** Stores the menu manager of the context menu. */
private MenuManager menuManager;
/** Stores the viewer which shows the currently running simulations */
private TreeViewer treeViewer;
/** Step Counter */
private IContributionItem stepCounter;
/** {@inheritDoc} */
@Override
public void createPartControl(Composite parent) {
treeViewer = new TreeViewer(parent, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL);
treeViewer.setContentProvider(new SimulationViewContentProvider());
treeViewer.setLabelProvider(new LabelProvider() {
/** {@inheritDoc} */
@Override
public Image getImage(Object element) {
if(element instanceof ExecutableComponent<?>) {
EObject modelElement = ((ExecutableComponent<?>)element).getModelElement();
EObject spec = ((ExecutableComponent<?>)element).getSpecification();
if(spec != null) {
return IModelElementHandlerService.getInstance().getIcon(spec);
}
return IModelElementHandlerService.getInstance().getIcon(modelElement);
}
return super.getImage(element);
}
});
treeViewer.setComparator(new ViewerComparator(Collator.getInstance()));
treeViewer.setAutoExpandLevel(2);
treeViewer.setInput(SimulationManager.INSTANCE);
treeViewer.addDoubleClickListener(new IDoubleClickListener() {
@Override
public void doubleClick(DoubleClickEvent event) {
ISimulationContextMenuContributor contrib = ISimulationContextMenuService.INSTANCE
.getTopMostContributor(SimulationView.this);
if(contrib != null) {
IContributionItem contribItem = contrib.getContributedItem(SimulationView.this,
getSelectedExecutableComponent());
if(contribItem instanceof ActionContributionItem)
((ActionContributionItem)contribItem).getAction().run();
}
}
});
createContextMenu();
fillActionBar(getViewSite().getActionBars());
updateActions();
SimulationManager.INSTANCE.addListener(this);
}
/** Returns the selected {@link ExecutableComponent}. */
public ExecutableComponent<?> getSelectedExecutableComponent() {
return checkAndPickFirst(treeViewer, ExecutableComponent.class);
}
/** Creates the context menu. */
private void createContextMenu() {
menuManager = ISimulationContextMenuService.INSTANCE.createContextMenu(this);
Menu menu = menuManager.createContextMenu(treeViewer.getTree());
treeViewer.getTree().setMenu(menu);
}
/** Shows a view with the given id. */
public void showSimulationView(String viewId, Component observedComponent) {
String secondaryId = Integer.toString(observedComponent.getId());
try {
getSite().getPage().showView(viewId, secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
} catch(PartInitException e) {
error(getDefault(), "Could not show simulation view!", e);
}
}
/** {@inheritDoc} */
@Override
public void setFocus() {
treeViewer.getTree().setFocus();
}
/** {@inheritDoc} */
@Override
public void propertyChanged(Object source, int propId) {
if(source == SimulationManager.INSTANCE) {
if(propId == SimulationManager.SIMULATED_COMPONENT_CHANGED_EVENT) {
treeViewer.refresh();
treeViewer.expandToLevel(3);
updateActions();
closeUnrelatedViews();
} else if(propId == SimulationManager.SIMULATION_PERFORMED_EVENT) {
updateActions();
} else if(propId == SimulationManager.SIMULATION_INITIALIZED_EVENT) {
((StepCounterContributionItem)SimulationView.this.stepCounter).resetCounter();
updateActions();
} else if(propId == SimulationManager.SIMULATION_STEPPED_BACK_EVENT) {
updateActions();
}
}
}
/** Closes unrelated views. */
private void closeUnrelatedViews() {
ExecutableComponent<? extends IModelElementSpecification> simulationObject =
SimulationManager.INSTANCE.getCurrentSimulation();
// close all views not part of the current simulation
for(IViewReference vref : getViewSite().getWorkbenchWindow().getActivePage()
.getViewReferences()) {
IViewPart vpart = vref.getView(false);
if(vpart instanceof SimulationViewBase) {
SimulationViewBase svb = (SimulationViewBase)vpart;
if(simulationObject == null || svb.getModelElement() == null ||
simulationObject.findSimilarExecutable(svb.getModelElement()) == null) {
getViewSite().getWorkbenchWindow().getActivePage().hideView(vpart);
}
}
}
}
/** {@inheritDoc} */
@Override
public void dispose() {
SimulationManager.INSTANCE.removeListener(this);
super.dispose();
}
/** Adds the actions to the action bar */
private void fillActionBar(IActionBars bars) {
IToolBarManager toolBarManager = bars.getToolBarManager();
for(IAction action : simulationViewActionsInstance.getActions()) {
toolBarManager.add(action);
}
IContributionItem simulationSpeed =
new SimulationSpeedContributionItem(getSite().getPage());
toolBarManager.add(simulationSpeed);
// the step counter
stepCounter = new StepCounterContributionItem(getSite().getPage());
toolBarManager.add(stepCounter);
stepCounter.setVisible(true);
}
/** Content provider for the simulation view. */
private class SimulationViewContentProvider extends TreeContentProviderBase {
/** {@inheritDoc} */
@SuppressWarnings({"unchecked"})
@Override
public Object[] getChildren(Object parentElement) {
if(parentElement instanceof ExecutableComponent) {
return ((ExecutableComponent<IModelElementSpecification>)parentElement)
.getSubElements().toArray();
}
return new Object[0];
}
/** {@inheritDoc} */
@Override
public Object[] getElements(Object inputElement) {
if(inputElement == SimulationManager.INSTANCE &&
SimulationManager.INSTANCE.getCurrentSimulation() != null) {
return new Object[] {SimulationManager.INSTANCE.getCurrentSimulation()};
}
return new Object[0];
}
}
/** Updates the action buttons. */
private void updateActions() {
if(SimulationManager.INSTANCE.getCurrentSimulation() != null) {
boolean isRunning = SimulationManager.INSTANCE.isSimulationRunning();
if(isRunning) {
simulationViewActionsInstance.pause.setEnabled(true);
simulationViewActionsInstance.performStep.setEnabled(false);
simulationViewActionsInstance.performStepBack.setEnabled(false);
simulationViewActionsInstance.run.setEnabled(false);
} else {
simulationViewActionsInstance.pause.setEnabled(false);
simulationViewActionsInstance.performStep.setEnabled(true);
boolean enableBack =
((StepCounterContributionItem)SimulationView.this.stepCounter).stepCount == 0;
simulationViewActionsInstance.performStepBack.setEnabled(!enableBack);
simulationViewActionsInstance.run.setEnabled(true);
}
simulationViewActionsInstance.initialize.setEnabled(true);
simulationViewActionsInstance.delete.setEnabled(true);
} else {
for(IAction a : simulationViewActionsInstance.getActions()) {
a.setEnabled(false);
}
}
}
/** Stores the singleton. */
public final SimulationViewActions simulationViewActionsInstance = new SimulationViewActions();
/** Class defining actions of the simulation view. */
/* package */class SimulationViewActions {
/** Action for performing a simulation step. */
public final Action performStep;
/** Action for performing a simulation step back. */
public final Action performStepBack;
/** Action for (re-)initializing the simulation. */
public final Action initialize;
/** Action for running the simulation. */
public final Action run;
/** Action for pausing the simulation. */
public final Action pause;
/** Action for stopping and deleting simulation. */
public final Action delete;
/** Returns the actions managed by this class. */
IAction[] getActions() {
return new IAction[] {run, pause, performStepBack, performStep, initialize, delete};
}
/** Constructor. */
public SimulationViewActions() {
performStep = new Action() {
@Override
public void run() {
((StepCounterContributionItem)SimulationView.this.stepCounter).incCounter();
SimulationManager.INSTANCE.performStep();
SimulationManager.INSTANCE.showLastErrorMessage();
}
};
setUpAction(performStep, "Step", "Simulated Step",
getImageDescriptor("icons/simulator/step.png"),
getImageDescriptor("icons/simulator/step_disabled.png"));
performStepBack = new Action() {
@Override
public void run() {
((StepCounterContributionItem)SimulationView.this.stepCounter).decCounter();
SimulationManager.INSTANCE.performStepBack();
SimulationManager.INSTANCE.showLastErrorMessage();
}
};
setUpAction(performStepBack, "StepBack", "Simulated Step Back",
getImageDescriptor("icons/simulator/back.png"),
getImageDescriptor("icons/simulator/back_disabled.png"));
initialize = new Action() {
@Override
public void run() {
SimulationManager.INSTANCE.reset();