Initial commit.
@@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="xtend-gen"/>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/httpclient-4.2.5.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/httpcore-4.2.4.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/json-simple-1.1.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/libthrift-0.9.2-javadoc.jar"/>
|
||||
<classpathentry exported="true" kind="lib" path="lib/libthrift-0.9.2.jar"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
1
eclipse/plugins/com.irtsaintexupery.fiacre.simulator/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
||||
/bin/
|
||||
@@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>com.irtsaintexupery.fiacre.simulator</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.ManifestBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.pde.SchemaBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.pde.PluginNature</nature>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
@@ -0,0 +1,47 @@
|
||||
Manifest-Version: 1.0
|
||||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: Simulator
|
||||
Bundle-SymbolicName: com.irtsaintexupery.fiacre.simulator;singleton:=true
|
||||
Bundle-Version: 1.0.0.qualifier
|
||||
Bundle-Activator: com.irtsaintexupery.fiacre.simulator.Activator
|
||||
Bundle-Vendor: IRT
|
||||
Bundle-ActivationPolicy: lazy
|
||||
Require-Bundle: com.irtsaintexupery.fiacre.instance,
|
||||
org.eclipse.xtend.lib,
|
||||
fr.irit.fiacre.xtext.ui,
|
||||
org.eclipse.xtext.ui,
|
||||
org.eclipse.jface,
|
||||
org.eclipse.ui.workbench,
|
||||
org.eclipse.swt,
|
||||
org.eclipse.emf.edit,
|
||||
org.eclipse.emf.ecore,
|
||||
fr.irit.fiacre.xtext,
|
||||
org.eclipse.core.resources,
|
||||
fr.laas.libtts;bundle-version="1.0.0",
|
||||
org.eclipse.emf.common,
|
||||
org.eclipse.equinox.registry,
|
||||
org.eclipse.core.jobs,
|
||||
org.eclipse.jdt.core,
|
||||
org.eclipse.ui.workbench.texteditor,
|
||||
org.eclipse.xtext,
|
||||
com.irtsaintexupey.fiacre.simulator.msc;bundle-version="1.0.0",
|
||||
com.irtsaintexupey.fiacre.simulator.msc.edit;bundle-version="1.0.0",
|
||||
com.irtsaintexupey.fiacre.simulator.msc.editor;bundle-version="1.0.0"
|
||||
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
|
||||
Bundle-ClassPath: lib/libthrift-0.9.2-javadoc.jar,
|
||||
lib/libthrift-0.9.2.jar,
|
||||
.,
|
||||
lib/httpclient-4.2.5.jar,
|
||||
lib/httpcore-4.2.4.jar,
|
||||
lib/json-simple-1.1.jar,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective.model,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective.views
|
||||
Export-Package: com.irtsaintexupery.fiacre.simulator.core,
|
||||
com.irtsaintexupery.fiacre.simulator.marking,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective.model,
|
||||
com.irtsaintexupery.fiacre.simulator.perspective.views,
|
||||
com.irtsaintexupery.fiacre.simulator.staticjson.extractor,
|
||||
org.apache.thrift
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
###############################################################################
|
||||
# Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exup<75>ry).
|
||||
# All rights reserved. This program and the accompanying materials
|
||||
# are made available under the terms of the LGPL 3.0
|
||||
# which accompanies this distribution, and is available at
|
||||
# https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
#
|
||||
# Contributors:
|
||||
# Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
# Jorge Enrique Gutierrez Zuluaga
|
||||
###############################################################################
|
||||
source.. = src/
|
||||
output.. = bin/
|
||||
bin.includes = plugin.xml,\
|
||||
META-INF/,\
|
||||
.,\
|
||||
lib/libthrift-0.9.2-javadoc.jar,\
|
||||
lib/libthrift-0.9.2.jar,\
|
||||
lib/httpclient-4.2.5.jar,\
|
||||
lib/httpcore-4.2.4.jar,\
|
||||
lib/json-simple-1.1.jar
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<?pde version="3.8"?><target name="Running Platform" sequenceNumber="50">
|
||||
<locations>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.10.0.v201605250459"/>
|
||||
<repository location="http://download.eclipse.org/releases/neon"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.slf4j.api" version="1.7.2.v20121108-1250"/>
|
||||
<unit id="javax.servlet" version="3.1.0.v201410161800"/>
|
||||
<unit id="org.junit" version="4.12.0.v201504281640"/>
|
||||
<unit id="org.apache.commons.logging" version="1.1.1.v201101211721"/>
|
||||
<unit id="org.apache.commons.codec" version="1.6.0.v201305230611"/>
|
||||
<unit id="org.apache.commons.lang3" version="3.1.0.v201403281430"/>
|
||||
<unit id="org.apache.log4j" version="1.2.15.v201012070815"/>
|
||||
<repository location="http://download.eclipse.org/tools/orbit/downloads/drops/R20160221192158/repository/"/>
|
||||
</location>
|
||||
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
|
||||
<unit id="org.eclipse.sdk.ide" version="4.6.1.M20160907-1200"/>
|
||||
<repository location="http://download.eclipse.org/eclipse/updates/4.6"/>
|
||||
</location>
|
||||
</locations>
|
||||
<environment>
|
||||
<nl>fr_FR</nl>
|
||||
</environment>
|
||||
<launcherArgs>
|
||||
<vmArgs>-Xms256m -Xmx2048m</vmArgs>
|
||||
</launcherArgs>
|
||||
</target>
|
||||
|
After Width: | Height: | Size: 349 B |
|
After Width: | Height: | Size: 793 B |
|
After Width: | Height: | Size: 452 B |
|
After Width: | Height: | Size: 729 B |
|
After Width: | Height: | Size: 745 B |
|
After Width: | Height: | Size: 790 B |
|
After Width: | Height: | Size: 825 B |
|
After Width: | Height: | Size: 483 B |
|
After Width: | Height: | Size: 286 B |
|
After Width: | Height: | Size: 726 B |
|
After Width: | Height: | Size: 634 B |
|
After Width: | Height: | Size: 700 B |
|
After Width: | Height: | Size: 612 B |
|
After Width: | Height: | Size: 537 B |
|
After Width: | Height: | Size: 827 B |
265
eclipse/plugins/com.irtsaintexupery.fiacre.simulator/plugin.xml
Normal file
@@ -0,0 +1,265 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<?eclipse version="3.4"?>
|
||||
<!--
|
||||
Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
All rights reserved. This program and the accompanying materials
|
||||
are made available under the terms of the LGPL 3.0
|
||||
which accompanies this distribution, and is available at
|
||||
https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
|
||||
Contributors:
|
||||
Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
Jorge Enrique Gutierrez Zuluaga
|
||||
-->
|
||||
|
||||
<plugin>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<objectContribution
|
||||
objectClass="org.eclipse.core.resources.IFile"
|
||||
id="com.irtsaintexupery.fiacre.simulator.contribution1">
|
||||
<menu
|
||||
label="FiacreSimulator"
|
||||
path="additions"
|
||||
id="com.irtsaintexupery.fiacre.simulator.menu1">
|
||||
<separator
|
||||
name="group1">
|
||||
</separator>
|
||||
</menu>
|
||||
<action
|
||||
label="Simulate"
|
||||
class="com.irtsaintexupery.fiacre.simulator.popup.actions.FiacreSimulationAction"
|
||||
menubarPath="com.irtsaintexupery.fiacre.simulator.menu1/group1"
|
||||
enablesFor="1"
|
||||
id="com.irtsaintexupery.fiacre.simulator.newAction">
|
||||
</action>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
defaultHandler="com.irtsaintexupery.fiacre.simulator.core.FireEvent"
|
||||
id="com.irtsaintexupery.fiacre.simulator.fireEvent"
|
||||
name="Fire">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
allPopups="false"
|
||||
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
|
||||
<command
|
||||
commandId="com.irtsaintexupery.fiacre.simulator.fireEvent"
|
||||
style="push">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<with
|
||||
variable="activeMenuSelection">
|
||||
<iterate
|
||||
ifEmpty="false"
|
||||
operator="and">
|
||||
<adapt
|
||||
type="com.irtsaintexupery.fiacre.instance.fiacreinstance.FireableStatementBlock">
|
||||
</adapt>
|
||||
</iterate>
|
||||
</with>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
defaultHandler="com.irtsaintexupery.fiacre.simulator.core.DelayEvent"
|
||||
id="com.irtsaintexupery.fiacre.simulator.delayEvent"
|
||||
name="Delay">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
allPopups="false"
|
||||
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
|
||||
<command
|
||||
commandId="com.irtsaintexupery.fiacre.simulator.delayEvent"
|
||||
style="push">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<with
|
||||
variable="activeMenuSelection">
|
||||
<iterate
|
||||
ifEmpty="false"
|
||||
operator="and">
|
||||
<adapt
|
||||
type="com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceModel">
|
||||
</adapt>
|
||||
</iterate>
|
||||
</with>
|
||||
</visibleWhen>
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
allPopups="false"
|
||||
locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
|
||||
<toolbar
|
||||
id="com.irtsaintexupery.fiacre.simulator.toolbar">
|
||||
<command
|
||||
commandId="com.irtsaintexupery.fiacre.simulator.quitSimulatorCommand"
|
||||
icon="icons/stop.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.simulatorToolbar"
|
||||
style="push"
|
||||
tooltip="Quit Fiacre Simulator">
|
||||
</command>
|
||||
</toolbar>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
defaultHandler="com.irtsaintexupery.fiacre.simulator.core.QuitSimulator"
|
||||
id="com.irtsaintexupery.fiacre.simulator.quitSimulatorCommand"
|
||||
name="Quit Simulator">
|
||||
</command>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
point="org.eclipse.ui.views">
|
||||
<view
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.views.TransitionsView"
|
||||
icon="icons/lightning.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.transitionsView"
|
||||
name="Transitions"
|
||||
restorable="true">
|
||||
</view>
|
||||
<view
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.views.ValuesView"
|
||||
icon="icons/database_table.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.valuesView"
|
||||
name="Values"
|
||||
restorable="true">
|
||||
</view>
|
||||
<view
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.views.InstancesView"
|
||||
icon="icons/table_multiple.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.instancesView"
|
||||
name="Instances"
|
||||
restorable="true">
|
||||
</view>
|
||||
<view
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.views.ExecutedActionView"
|
||||
icon="icons/tick.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.executedActionView"
|
||||
name="Executed actions"
|
||||
restorable="true">
|
||||
</view>
|
||||
<view
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.views.SavedStatesView"
|
||||
icon="icons/brick.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.savedStatesView"
|
||||
name="Saved paths"
|
||||
restorable="true">
|
||||
</view>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.perspectives">
|
||||
<perspective
|
||||
class="com.irtsaintexupery.fiacre.simulator.perspective.PerspectiveSimulatorFactory"
|
||||
icon="icons/bricks.png"
|
||||
id="com.irtsaintexupery.fiacre.simulator.perspective.fiacreSimulator"
|
||||
name="Fiacre Simulator">
|
||||
</perspective>
|
||||
</extension>
|
||||
|
||||
<!-- Defines my own custom marker, use the marker view panel to see them when they are created-->
|
||||
<extension point="org.eclipse.core.resources.markers"
|
||||
id="com.irtsaintexupery.fiacre.simulator.marking.marker"
|
||||
name="FiacreMarker">
|
||||
<super type="org.eclipse.core.resources.textmarker"/>
|
||||
<super type="org.eclipse.core.resources.marker"/>
|
||||
<persistent value="true"/>
|
||||
</extension>
|
||||
|
||||
<!-- Popup menu to add a menu to right click of a java file in the text editor-->
|
||||
|
||||
<!-- Popup menu to add a menu to right click of a java file in the package explorer-->
|
||||
|
||||
<!-- Annotation specification:- describes what the annotation will look like and its properties -->
|
||||
<extension point="org.eclipse.ui.editors.markerAnnotationSpecification"
|
||||
id="com.irtsaintexupery.fiacre.simulator.marking.annotationspecification"
|
||||
name="FiacreAnnotation">
|
||||
<!-- <specification
|
||||
annotationType="org.eclipse.viatra2.slicemarker"
|
||||
colorPreferenceKey="org.eclipse.viatra2.slice.color"
|
||||
colorPreferenceValue="192,255,192"
|
||||
contributesToHeader="false"
|
||||
highlightPreferenceKey="org.eclipse.viatra2.slice.highlight"
|
||||
highlightPreferenceValue="true"
|
||||
includeOnPreferencePage="true"
|
||||
label="MyAnnotation"
|
||||
overviewRulerPreferenceKey="org.eclipse.viatra2.slice.overview"
|
||||
overviewRulerPreferenceValue="true"
|
||||
presentationLayer="0"
|
||||
textPreferenceKey="org.eclipse.viatra2.slice.text"
|
||||
textPreferenceValue="true"
|
||||
textStylePreferenceValue="BOX"
|
||||
verticalRulerPreferenceKey="org.eclipse.viatra2.slice.ruler"
|
||||
verticalRulerPreferenceValue="true">
|
||||
</specification> -->
|
||||
<specification
|
||||
annotationType="com.irtsaintexupery.fiacre.simulator.marking.annotation"
|
||||
label="FiacreAnnotation"
|
||||
icon="icons/bullet_pink.png"
|
||||
overviewRulerPreferenceKey="clruler"
|
||||
overviewRulerPreferenceValue="true"
|
||||
highlightPreferenceKey="org.eclipse.viatra2.slice.highlight"
|
||||
highlightPreferenceValue="true"
|
||||
colorPreferenceKey="clcolor"
|
||||
colorPreferenceValue="230,154,245"
|
||||
textPreferenceKey="cltext"
|
||||
textPreferenceValue="true"
|
||||
verticalRulerPreferenceKey="clvertical"
|
||||
verticalRulerPreferenceValue="true"
|
||||
textStylePreferenceKey="clstyle"
|
||||
textStylePreferenceValue="BOX">
|
||||
</specification>
|
||||
|
||||
</extension>
|
||||
|
||||
<!-- Links the annotation spec to the marker -->
|
||||
<extension point="org.eclipse.ui.editors.annotationTypes">
|
||||
<type
|
||||
markerSeverity="0"
|
||||
super="org.eclipse.ui.workbench.texteditor.info"
|
||||
name="com.irtsaintexupery.fiacre.simulator.marking.annotation"
|
||||
markerType="com.irtsaintexupery.fiacre.simulator.marking.marker"/>
|
||||
</extension>
|
||||
|
||||
<!-- define the marker updater class-->
|
||||
<extension point="org.eclipse.ui.editors.markerUpdaters">
|
||||
<updater
|
||||
id="com.irtsaintexupery.fiacre.simulator.marking.MarkerUpdater"
|
||||
class="com.irtsaintexupery.fiacre.simulator.marking.MarkerUpdater"
|
||||
markerType="com.irtsaintexupery.fiacre.simulator.marking.marker">
|
||||
</updater>
|
||||
</extension>
|
||||
|
||||
<!--define the decorator -->
|
||||
<extension point="org.eclipse.ui.decorators">
|
||||
<decorator
|
||||
id="com.irtsaintexupery.fiacre.simulator.marking.filedecorator"
|
||||
label="FiacreDecorator"
|
||||
state="true"
|
||||
class= "com.irtsaintexupery.fiacre.simulator.marking.FileDecorator"
|
||||
adaptable="true"
|
||||
lightweight="true">
|
||||
<enablement>
|
||||
<objectClass name="org.eclipse.core.resources.IResource"/>
|
||||
</enablement>
|
||||
</decorator>
|
||||
</extension>
|
||||
|
||||
</plugin>
|
||||
@@ -0,0 +1,86 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.core.FiacreSimulator;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class Activator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "com.irtsaintexupery.fiacre.simulator"; //$NON-NLS-1$
|
||||
|
||||
// The shared instance
|
||||
private static Activator plugin;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public Activator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
LibTTS libtts = FiacreSimulator.getLibTTS();
|
||||
if (libtts != null) {
|
||||
ViewsController.INSTANCE.deleteMarkers();
|
||||
//ViewsController.INSTANCE.clearAllViews();////////////////////////////
|
||||
libtts.quit();
|
||||
FiacreSimulator.setLibtts(null);
|
||||
System.out.println("quit simulator");
|
||||
}
|
||||
super.stop(context);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static Activator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import org.apache.thrift.TException;
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
import com.irtsaintexupery.fiacre.simulator.staticjson.extractor.DynamicJsonExtractor;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
import tts.Error;
|
||||
import tts.InvalidDelay;
|
||||
import tts.StateNotFound;
|
||||
|
||||
public class DelayEvent extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ReadDelay dialog = new ReadDelay(HandlerUtil.getActiveShell(event));
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK) {
|
||||
dialog.getValue();
|
||||
LibTTS libtts = FiacreSimulator.getLibTTS();
|
||||
DynamicJsonExtractor dje = FiacreSimulator.sendDje();
|
||||
try {
|
||||
libtts.getTTSSimulator().delay(dialog.getValue());
|
||||
dje.extractExecutableStatements();
|
||||
dje.saveInstanceResource();
|
||||
|
||||
|
||||
//Jorge Gutierrez 03/08/2016
|
||||
ViewsController.INSTANCE.updateTransitionView();
|
||||
ViewsController.INSTANCE.addDelayToAction(dialog.getValue());
|
||||
ViewsController.INSTANCE.updateExecutedActionView();
|
||||
|
||||
|
||||
} catch (Error e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("Error",e);
|
||||
//e.printStackTrace();
|
||||
} catch (StateNotFound e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("StateNotFound",e);
|
||||
//e.printStackTrace();
|
||||
} catch (InvalidDelay e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("InvalidDelay",e);
|
||||
//e.printStackTrace();
|
||||
} catch (TException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("TException",e);
|
||||
//e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("NumberFormatException: "+dialog.getValue()+" is not numeric value",e);
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,316 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.util.EcoreUtil;
|
||||
import org.eclipse.emf.edit.domain.EditingDomain;
|
||||
import org.eclipse.emf.edit.domain.IEditingDomainProvider;
|
||||
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
|
||||
import org.eclipse.jface.operation.IRunnableWithProgress;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
import com.irtsaintexupery.fiacre.simulator.staticjson.extractor.DynamicJsonExtractor;
|
||||
import com.irtsaintexupery.fiacre.simulator.staticjson.extractor.StaticJsonExtractor;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
|
||||
public class FiacreSimulator {
|
||||
private static LibTTS libtts;
|
||||
private static XtextResource fiacreResource;
|
||||
private static JSONObject fiacreStaticJson;
|
||||
private static Resource instanceResource;
|
||||
private static Resource mscResource;
|
||||
private static StaticJsonExtractor sje;
|
||||
private static DynamicJsonExtractor dje;
|
||||
|
||||
|
||||
|
||||
public FiacreSimulator(final IFile file){
|
||||
// /*
|
||||
// * If a current libtts exists and the user forgets to kill it, we kill
|
||||
// * it automatically
|
||||
// */
|
||||
//
|
||||
//
|
||||
// if (libtts != null) {
|
||||
// ViewsController.INSTANCE.clearAllViews();
|
||||
// ViewsController.INSTANCE.deleteMarkers();
|
||||
// libtts.quit();
|
||||
// FiacreSimulator.setLibtts(null);
|
||||
// }
|
||||
//
|
||||
// // Compile Fiacre model
|
||||
// Utils.compileFiacreModel(file);
|
||||
// Utils.callPythonCommand(file);
|
||||
//
|
||||
// // initialize libtts
|
||||
// libtts = new LibTTS(Utils.getTTSFilePath(file));
|
||||
// /*
|
||||
// * This condition allows to catch whether an exception was thrown during instantiating
|
||||
// * LibTTS. We can't do a try catch block because libTTS is a static field.
|
||||
// */
|
||||
// if (libtts.getTTSSimulator() != null) {
|
||||
// // Get the static json file
|
||||
// String static_json_file_path = Utils.getStaticJsonFilePath(file);
|
||||
// fiacreStaticJson = Utils.getStaticJsonObject(static_json_file_path);
|
||||
//
|
||||
// // get the fiacre xtext resource
|
||||
// fiacreResource = Utils.getFiacreXtextResource(file);
|
||||
//
|
||||
// // create fiacre instance model
|
||||
// setInstanceResource(Utils.createInstanceModel(file));
|
||||
// sje = new StaticJsonExtractor(fiacreResource, fiacreStaticJson, instanceResource);
|
||||
// sje.extract();
|
||||
// dje = new DynamicJsonExtractor(fiacreResource, instanceResource, libtts.getTTSSimulator(), fiacreStaticJson, sje.getMapping());
|
||||
// simulate();
|
||||
// }
|
||||
// else{
|
||||
// // It set LibTTS to null in order to check the first condition in this constructor
|
||||
// // in the next simulation.
|
||||
// // We do it here because we can't do it in the LibTTS initialize_tts_model method
|
||||
// FiacreSimulator.setLibtts(null);
|
||||
// }
|
||||
//
|
||||
// //Jorge Gutierrez 05/08/2016
|
||||
// ViewsController.INSTANCE.setFile(file);
|
||||
|
||||
|
||||
//Progress bar
|
||||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActivePart().getSite().getShell();
|
||||
IRunnableWithProgress runnable = new IRunnableWithProgress()
|
||||
{
|
||||
|
||||
@Override
|
||||
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException
|
||||
{
|
||||
monitor.beginTask("Loading", 6);
|
||||
monitor.subTask("part 1");
|
||||
monitor.worked( 2 );
|
||||
part1(file);
|
||||
|
||||
monitor.subTask("part 2");
|
||||
monitor.worked( 2 );
|
||||
part2(file);
|
||||
|
||||
monitor.subTask("part 3");
|
||||
monitor.worked( 1 );
|
||||
part3(file);
|
||||
|
||||
|
||||
monitor.subTask("finished");
|
||||
monitor.worked( 1 );
|
||||
|
||||
|
||||
monitor.done();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
ProgressMonitorDialog dialog = new ProgressMonitorDialog(shell);
|
||||
try
|
||||
{
|
||||
dialog.run(true, true, runnable);
|
||||
}
|
||||
catch (InvocationTargetException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private static void part1(final IFile file){
|
||||
Display.getDefault().asyncExec(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/*
|
||||
* If a current libtts exists and the user forgets to kill it, we kill
|
||||
* it automatically
|
||||
*/
|
||||
if (libtts != null) {
|
||||
ViewsController.INSTANCE.deleteMarkers();
|
||||
ViewsController.INSTANCE.clearAllViews();
|
||||
libtts.quit();
|
||||
FiacreSimulator.setLibtts(null);
|
||||
}
|
||||
|
||||
// Compile Fiacre model
|
||||
Utils.compileFiacreModel(file);
|
||||
Utils.callPythonCommand(file);
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void part2(final IFile file){
|
||||
Display.getDefault().asyncExec(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
// initialize libtts
|
||||
libtts = new LibTTS(Utils.getTTSFilePath(file));
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void part3(final IFile file){
|
||||
Display.getDefault().asyncExec(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
/*
|
||||
* This condition allows to catch whether an exception was thrown during instantiating
|
||||
* LibTTS. We can't do a try catch block because libTTS is a static field.
|
||||
*/
|
||||
if (libtts.getTTSSimulator() != null) {
|
||||
// Get the static json file
|
||||
String static_json_file_path = Utils.getStaticJsonFilePath(file);
|
||||
fiacreStaticJson = Utils.getStaticJsonObject(static_json_file_path);
|
||||
|
||||
// get the fiacre xtext resource
|
||||
fiacreResource = Utils.getFiacreXtextResource(file);
|
||||
|
||||
// create fiacre instance model
|
||||
setInstanceResource(Utils.createInstanceModel(file));
|
||||
mscResource= Utils.createMSCModel(file);
|
||||
|
||||
sje = new StaticJsonExtractor(fiacreResource, fiacreStaticJson, instanceResource, mscResource);
|
||||
sje.extract();
|
||||
dje = new DynamicJsonExtractor(fiacreResource, instanceResource, libtts.getTTSSimulator(), fiacreStaticJson, sje.getMapping(), mscResource);
|
||||
ViewsController.INSTANCE.setFile(file);
|
||||
simulate(file);
|
||||
}
|
||||
else{
|
||||
// It set LibTTS to null in order to check the first condition in this constructor
|
||||
// in the next simulation.
|
||||
// We do it here because we can't do it in the LibTTS initialize_tts_model method
|
||||
FiacreSimulator.setLibtts(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static LibTTS getLibTTS() {
|
||||
return libtts;
|
||||
}
|
||||
|
||||
public static DynamicJsonExtractor sendDje() {
|
||||
return dje;
|
||||
}
|
||||
|
||||
public static void simulate(IFile file) {
|
||||
// try {
|
||||
|
||||
dje.extractStates();
|
||||
dje.extractExecutableStatements();
|
||||
|
||||
dje.extractValues();
|
||||
dje.saveInstanceResource();
|
||||
|
||||
try {
|
||||
file.getParent().refreshLocal(1, null);
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
//msc
|
||||
dje.mscFirstStepExtract();
|
||||
//launch perspective
|
||||
ViewsController.INSTANCE.openPespective();
|
||||
|
||||
//libtts.getTTSSimulator().printCurrent();
|
||||
}
|
||||
|
||||
public LibTTS getLibtts() {
|
||||
return libtts;
|
||||
}
|
||||
|
||||
public static void setLibtts(LibTTS _libtts) {
|
||||
libtts = _libtts;
|
||||
}
|
||||
|
||||
public XtextResource getXtextResource() {
|
||||
return fiacreResource;
|
||||
}
|
||||
|
||||
public void setXtextResource(XtextResource xtextResource) {
|
||||
FiacreSimulator.fiacreResource = xtextResource;
|
||||
}
|
||||
|
||||
public JSONObject getStatic_json() {
|
||||
return fiacreStaticJson;
|
||||
}
|
||||
|
||||
public void setStatic_json(JSONObject static_json) {
|
||||
FiacreSimulator.fiacreStaticJson = static_json;
|
||||
}
|
||||
|
||||
public Resource getInstanceResource() {
|
||||
return instanceResource;
|
||||
}
|
||||
|
||||
public static void setInstanceResource(Resource instanceResource) {
|
||||
FiacreSimulator.instanceResource = instanceResource;
|
||||
}
|
||||
|
||||
static public EditingDomain getEditingDomainFor(EObject object) {
|
||||
Resource resource = object.eResource();
|
||||
if (resource != null) {
|
||||
IEditingDomainProvider editingDomainProvider =
|
||||
|
||||
(IEditingDomainProvider) EcoreUtil.getExistingAdapter(resource, IEditingDomainProvider.class);
|
||||
if (editingDomainProvider != null) {
|
||||
return editingDomainProvider.getEditingDomain();
|
||||
} else {
|
||||
ResourceSet resourceSet = resource.getResourceSet();
|
||||
if (resourceSet instanceof IEditingDomainProvider) {
|
||||
EditingDomain editingDomain = ((IEditingDomainProvider) resourceSet).getEditingDomain();
|
||||
return editingDomain;
|
||||
} else if (resourceSet != null) {
|
||||
editingDomainProvider = (IEditingDomainProvider) EcoreUtil.getExistingAdapter(resourceSet,
|
||||
IEditingDomainProvider.class);
|
||||
if (editingDomainProvider != null) {
|
||||
return editingDomainProvider.getEditingDomain();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// todO
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.thrift.TException;
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FireableStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.simulator.staticjson.extractor.DynamicJsonExtractor;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
import tts.Error;
|
||||
import tts.NotFireable;
|
||||
import tts.StateNotFound;
|
||||
import tts.Transition;
|
||||
import tts.TransitionNotFound;
|
||||
|
||||
public class FireEvent extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
|
||||
ISelection selection = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage().getSelection();
|
||||
if (selection != null & selection instanceof IStructuredSelection) {
|
||||
|
||||
try {
|
||||
IStructuredSelection strucSelection = (IStructuredSelection) selection;
|
||||
String tr_name = ((FireableStatementBlock) strucSelection.toList().get(0)).getName();
|
||||
LibTTS libtts = FiacreSimulator.getLibTTS();
|
||||
DynamicJsonExtractor dje = FiacreSimulator.sendDje();
|
||||
long tr_long = -1;
|
||||
for (Map.Entry<Long, Transition> tr : libtts.getTTSSimulator().getAllTransitions().entrySet()) {
|
||||
if (tr.getValue().getName().equals(tr_name)) {
|
||||
tr_long = tr.getKey();
|
||||
}
|
||||
}
|
||||
libtts.getTTSSimulator().fireTransition(tr_long);
|
||||
dje.extractExecutedStatements(libtts.getTTSSimulator().getAllTransitions().get(tr_long).name);
|
||||
dje.extractStates();
|
||||
dje.extractExecutableStatements();
|
||||
dje.extractValues();
|
||||
dje.saveInstanceResource();
|
||||
} catch (Error e) {
|
||||
Utils.showException("Error", e);
|
||||
// e.printStackTrace();
|
||||
} catch (StateNotFound e) {
|
||||
Utils.showException("StateNotFound", e);
|
||||
// e.printStackTrace();
|
||||
} catch (TransitionNotFound e) {
|
||||
Utils.showException("TransitionNotFound", e);
|
||||
// e.printStackTrace();
|
||||
} catch (NotFireable e) {
|
||||
Utils.showException("NotFireable", e);
|
||||
// e.printStackTrace();
|
||||
} catch (TException e) {
|
||||
Utils.showException("TException", e);
|
||||
// e.printStackTrace();
|
||||
} catch (NullPointerException e) {
|
||||
Utils.showException("NullPointerException", e);
|
||||
// e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.marking.MarkingController;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
|
||||
public class QuitSimulator extends AbstractHandler {
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
|
||||
LibTTS libtts = FiacreSimulator.getLibTTS();
|
||||
if (libtts != null) {
|
||||
//resets Marking on current file
|
||||
ViewsController.INSTANCE.deleteMarkers();
|
||||
libtts.quit();
|
||||
FiacreSimulator.setLibtts(null);
|
||||
//clean all content in each view
|
||||
ViewsController.INSTANCE.clearAllViews();
|
||||
System.out.println("quit simulator");
|
||||
MarkingController.file = null;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
|
||||
public class ReadDelay extends TitleAreaDialog {
|
||||
|
||||
private Text textValue;
|
||||
|
||||
private String value;
|
||||
|
||||
private Shell shell;
|
||||
|
||||
public ReadDelay(Shell parentShell) {
|
||||
super(parentShell);
|
||||
shell = parentShell;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
super.create();
|
||||
setTitle("Delaying Fiacre model");
|
||||
final ReadDelay read_delay = this;
|
||||
setMessage("This is a TitleAreaDialog", IMessageProvider.INFORMATION);
|
||||
this.getButton(OK).setEnabled(false);
|
||||
|
||||
textValue.addListener(SWT.Modify, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
try {
|
||||
value = textValue.getText();
|
||||
read_delay.getButton(OK).setEnabled(true);
|
||||
} catch (Exception e) {
|
||||
read_delay.getButton(OK).setEnabled(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
shell.addListener(SWT.Traverse, new Listener() {
|
||||
public void handleEvent(Event event) {
|
||||
if (event.detail == SWT.TRAVERSE_ESCAPE)
|
||||
event.doit = false;
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite area = (Composite) super.createDialogArea(parent);
|
||||
Composite container = new Composite(area, SWT.NONE);
|
||||
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
container.setLayout(layout);
|
||||
|
||||
createTextValue(container);
|
||||
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private void createTextValue(Composite container) {
|
||||
Label lbtTextValue = new Label(container, SWT.NONE);
|
||||
lbtTextValue.setText("enter delay");
|
||||
|
||||
GridData dataTextValue = new GridData();
|
||||
dataTextValue.grabExcessHorizontalSpace = true;
|
||||
dataTextValue.horizontalAlignment = GridData.FILL;
|
||||
|
||||
textValue = new Text(container, SWT.BORDER);
|
||||
textValue.setLayoutData(dataTextValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isResizable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// save content of the Text fields because they get disposed
|
||||
// as soon as the Dialog closes
|
||||
private void saveInput() {
|
||||
value = textValue.getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
saveInput();
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,455 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.core;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IStatus;
|
||||
import org.eclipse.core.runtime.MultiStatus;
|
||||
import org.eclipse.core.runtime.Path;
|
||||
import org.eclipse.core.runtime.Status;
|
||||
import org.eclipse.emf.common.CommonPlugin;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl;
|
||||
import org.eclipse.jface.dialogs.ErrorDialog;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
|
||||
import org.json.simple.JSONObject;
|
||||
import org.json.simple.parser.JSONParser;
|
||||
import org.json.simple.parser.ParseException;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ComponentDeclarationInstance;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.CompositionInstance;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.EnabledStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ExecutedStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FiacreinstanceFactory;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FiacreinstancePackage;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FireableStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceEnabledStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceExecutedStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceFireableStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceModel;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ProcessDeclarationInstance;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.VariableDeclarationInstance;
|
||||
import com.irtsaintexupery.fiacre.simulator.Activator;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.EnterStateStep;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MSC;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MscFactory;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MscPackage;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SendStep;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.Site;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.Step;
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SynchronisationStep;
|
||||
|
||||
import fr.irit.fiacre.xtext.fiacre.ArrayExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.ConstructionExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.FalseLiteral;
|
||||
import fr.irit.fiacre.xtext.fiacre.FiacreFactory;
|
||||
import fr.irit.fiacre.xtext.fiacre.FieldExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.IdentifierExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.NaturalLiteral;
|
||||
import fr.irit.fiacre.xtext.fiacre.QueueExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.RecordExpression;
|
||||
import fr.irit.fiacre.xtext.fiacre.TrueLiteral;
|
||||
import fr.irit.fiacre.xtext.ui.internal.XtextActivator;
|
||||
import fr.laas.libtts.Tools;
|
||||
|
||||
public class Utils {
|
||||
|
||||
private static FiacreinstanceFactory fiacre_instance_factory;
|
||||
private static MscFactory fiacre_msc_factory;
|
||||
private static FiacreFactory fiacre_factory = FiacreFactory.eINSTANCE;
|
||||
//private static String FRAC_PATH = "/home/faiez.zalila/.local/bin/frac-2.5.0/";
|
||||
|
||||
public static VariableDeclarationInstance createVariableDeclarationInstance() {
|
||||
return fiacre_instance_factory.createVariableDeclarationInstance();
|
||||
}
|
||||
|
||||
public static TrueLiteral createTrueLiteral() {
|
||||
return fiacre_factory.createTrueLiteral();
|
||||
}
|
||||
|
||||
public static FalseLiteral createFalseLiteral() {
|
||||
return fiacre_factory.createFalseLiteral();
|
||||
}
|
||||
|
||||
public static NaturalLiteral createNaturalLiteral() {
|
||||
return fiacre_factory.createNaturalLiteral();
|
||||
}
|
||||
|
||||
public static IdentifierExpression createIdentifierExpression() {
|
||||
return fiacre_factory.createIdentifierExpression();
|
||||
}
|
||||
|
||||
public static ComponentDeclarationInstance createComponentDeclarationInstance() {
|
||||
return fiacre_instance_factory.createComponentDeclarationInstance();
|
||||
}
|
||||
public static CompositionInstance createCompositionInstance() {
|
||||
return fiacre_instance_factory.createCompositionInstance();
|
||||
}
|
||||
|
||||
public static ProcessDeclarationInstance createProcessDeclarationInstance() {
|
||||
return fiacre_instance_factory.createProcessDeclarationInstance();
|
||||
}
|
||||
|
||||
public static InstanceExecutedStatementBlock createInstanceExecutedStatementBlock() {
|
||||
return fiacre_instance_factory.createInstanceExecutedStatementBlock();
|
||||
}
|
||||
|
||||
public static InstanceFireableStatementBlock createInstanceFireableStatementBlock() {
|
||||
return fiacre_instance_factory.createInstanceFireableStatementBlock();
|
||||
}
|
||||
|
||||
public static InstanceEnabledStatementBlock createInstanceEnabledStatementBlock() {
|
||||
return fiacre_instance_factory.createInstanceEnabledStatementBlock();
|
||||
}
|
||||
|
||||
public static ExecutedStatementBlock createExecutedStatementBlock() {
|
||||
return fiacre_instance_factory.createExecutedStatementBlock();
|
||||
}
|
||||
|
||||
public static FireableStatementBlock createFireableStatementBlock() {
|
||||
return fiacre_instance_factory.createFireableStatementBlock();
|
||||
}
|
||||
|
||||
public static EnabledStatementBlock createEnabledStatementBlock() {
|
||||
return fiacre_instance_factory.createEnabledStatementBlock();
|
||||
}
|
||||
|
||||
|
||||
public static Site createSite() {
|
||||
return fiacre_msc_factory.createSite();
|
||||
}
|
||||
public static Step createStep() {
|
||||
return fiacre_msc_factory.createStep();
|
||||
}
|
||||
public static SynchronisationStep createSynchronisationStep() {
|
||||
return fiacre_msc_factory.createSynchronisationStep();
|
||||
}
|
||||
public static SendStep createSendStep() {
|
||||
return fiacre_msc_factory.createSendStep();
|
||||
}
|
||||
public static EnterStateStep createEnterStateStep() {
|
||||
return fiacre_msc_factory.createEnterStateStep();
|
||||
}
|
||||
protected static Resource createInstanceModel(IFile file) {
|
||||
// Initialize the model
|
||||
FiacreinstancePackage.eINSTANCE.eClass();
|
||||
|
||||
// Retrieve the default factory singleton
|
||||
fiacre_instance_factory = FiacreinstanceFactory.eINSTANCE;
|
||||
// create the content of the model via this program
|
||||
InstanceModel instanceModel = fiacre_instance_factory.createInstanceModel();
|
||||
|
||||
// As of here we preparing to save the model content
|
||||
|
||||
// Register the XMI resource factory for the .website extension
|
||||
|
||||
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
|
||||
Map<String, Object> m = reg.getExtensionToFactoryMap();
|
||||
m.put("fiacreinstance", new XMIResourceFactoryImpl());
|
||||
|
||||
// Obtain a new resource set
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
// create a resource
|
||||
Resource resource = resSet.createResource(URI.createFileURI(getInstanceFilePath(file)));
|
||||
// Get the first model element and cast it to the right type, in my
|
||||
// example everything is hierarchical included in this first node
|
||||
resource.getContents().add(instanceModel);
|
||||
|
||||
// now save the content.
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
|
||||
protected static Resource createMSCModel(IFile file) {
|
||||
// Initialize the model
|
||||
MscPackage.eINSTANCE.eClass();
|
||||
|
||||
// Retrieve the default factory singleton
|
||||
fiacre_msc_factory = MscFactory.eINSTANCE;
|
||||
// create the content of the model via this program
|
||||
MSC mscModel = fiacre_msc_factory.createMSC();
|
||||
|
||||
// As of here we preparing to save the model content
|
||||
|
||||
// Register the XMI resource factory for the .website extension
|
||||
|
||||
Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE;
|
||||
Map<String, Object> m = reg.getExtensionToFactoryMap();
|
||||
m.put("mscmodel", new XMIResourceFactoryImpl());
|
||||
|
||||
// Obtain a new resource set
|
||||
ResourceSet resSet = new ResourceSetImpl();
|
||||
// create a resource
|
||||
Resource resource = resSet.createResource(URI.createFileURI(getMscFilePath(file)));
|
||||
// Get the first model element and cast it to the right type, in my
|
||||
// example everything is hierarchical included in this first node
|
||||
resource.getContents().add(mscModel);
|
||||
|
||||
// now save the content.
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return resource;
|
||||
}
|
||||
protected static String nameWithoutExtension(IFile file) {
|
||||
String fileName = file.getName();
|
||||
int pos = fileName.lastIndexOf(".");
|
||||
if (pos > 0) {
|
||||
fileName = fileName.substring(0, pos);
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
protected static String getTTSFilePath(IFile file) {
|
||||
return file.getParent().getLocation() + "/" + nameWithoutExtension(file) + ".tts";
|
||||
}
|
||||
|
||||
protected static String getInstanceFilePath(IFile file) {
|
||||
return file.getParent().getLocation() + "/" + nameWithoutExtension(file) + ".fiacreinstance";
|
||||
}
|
||||
protected static String getMscFilePath(IFile file) {
|
||||
return file.getParent().getLocation() + "/" + nameWithoutExtension(file) + ".mscmodel";
|
||||
}
|
||||
|
||||
protected static void callFracCommand(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder(Tools.FRAC_PATH+"frac","-g", "-j", file.getLocation().toString(),
|
||||
getTTSFilePath(file));
|
||||
pb_make.directory(new File(file.getParent().getLocation().toString()));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
System.out.println("Compiling Fiacre model ...");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void callFrac_G_Command(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder(Tools.FRAC_PATH+"frac", "-G", file.getLocation().toString(),
|
||||
getTTSFilePath(file)+"/"+file.getName()+".fcriG");
|
||||
pb_make.directory(new File(file.getParent().getLocation().toString()));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void callFrac_g_G_Command(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder(Tools.FRAC_PATH+"frac","-g","-G", file.getLocation().toString(),
|
||||
getTTSFilePath(file)+"/"+file.getName()+".fcrigG");
|
||||
pb_make.directory(new File(file.getParent().getLocation().toString()));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void callPythonCommand(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder("python", "-m", "json.tool",
|
||||
nameWithoutExtension(file) + ".json", "f_" + nameWithoutExtension(file) + ".json");
|
||||
pb_make.directory(new File(getTTSFilePath(file)));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void callMakeCommand(IFile file) {
|
||||
try {
|
||||
ProcessBuilder pb_make = new ProcessBuilder("make", "-f", Tools.FRAC_PATH+"Makefile",
|
||||
" NAME=" + nameWithoutExtension(file),"FRACLIB="+Tools.FRAC_PATH+"lib");
|
||||
pb_make.directory(new File(file.getParent().getLocation().toString()));
|
||||
Process p = pb_make.start();
|
||||
p.waitFor();
|
||||
System.out.println("Compiled Fiacre model");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
} catch (InterruptedException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static JSONObject getStaticJsonObject(String static_json_file_path) {
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
FileReader fr = new FileReader(static_json_file_path);
|
||||
Object obj = parser.parse(fr);
|
||||
// The most important statement
|
||||
// It is necessary to close the FileReader in order to
|
||||
// unlock the file locked during its opening
|
||||
fr.close();
|
||||
return (JSONObject) obj;
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static JSONObject getJsonObject(String string) {
|
||||
JSONParser parser = new JSONParser();
|
||||
try {
|
||||
Object obj = parser.parse(string);
|
||||
return (JSONObject) obj;
|
||||
} catch (ParseException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected static String getStaticJsonFilePath(IFile file) {
|
||||
return getTTSFilePath(file) + "/" + nameWithoutExtension(file) + ".json";
|
||||
}
|
||||
|
||||
protected static XtextResource getFiacreXtextResource(IFile file) {
|
||||
Injector injector = XtextActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre");
|
||||
XtextResourceSetProvider provider = injector.getInstance(XtextResourceSetProvider.class);
|
||||
ResourceSet resourceSet = provider.get(file.getProject());
|
||||
|
||||
URI xtextURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
|
||||
|
||||
return (XtextResource) resourceSet.getResource(xtextURI, true);
|
||||
|
||||
}
|
||||
|
||||
public static void saveResource(Resource resource) {
|
||||
try {
|
||||
resource.save(Collections.EMPTY_MAP);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
//Added
|
||||
URI resolvedFile = CommonPlugin.resolve(resource.getURI());
|
||||
IResource dfile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(resolvedFile.toFileString()));
|
||||
try {
|
||||
dfile.refreshLocal(IResource.DEPTH_INFINITE, null);
|
||||
} catch (CoreException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
protected static void compileFiacreModel(IFile file) {
|
||||
try {
|
||||
Tools.getProperties() ;
|
||||
} catch (IOException e1) {
|
||||
// TODO Auto-generated catch block
|
||||
e1.printStackTrace();
|
||||
}
|
||||
// Call Frac compiler
|
||||
callFracCommand(file);
|
||||
// Call make
|
||||
callMakeCommand(file);
|
||||
callFrac_g_G_Command(file);
|
||||
callFrac_G_Command(file);
|
||||
}
|
||||
public static QueueExpression createQueueExpression() {
|
||||
return fiacre_factory.createQueueExpression();
|
||||
}
|
||||
|
||||
public static ArrayExpression createArrayExpression() {
|
||||
return fiacre_factory.createArrayExpression();
|
||||
}
|
||||
|
||||
public static RecordExpression createRecordExpression() {
|
||||
return fiacre_factory.createRecordExpression();
|
||||
}
|
||||
|
||||
public static FieldExpression createFieldExpression() {
|
||||
return fiacre_factory.createFieldExpression();
|
||||
}
|
||||
|
||||
public static ConstructionExpression createConstructionExpression() {
|
||||
return fiacre_factory.createConstructionExpression();
|
||||
}
|
||||
|
||||
public static void showException(String message, final Exception ex) {
|
||||
|
||||
StringWriter sw = new StringWriter();
|
||||
PrintWriter pw = new PrintWriter(sw);
|
||||
ex.printStackTrace(pw);
|
||||
// ex.printStackTrace();
|
||||
|
||||
final String trace = sw.toString(); // stack trace as a string
|
||||
|
||||
// Temp holder of child statuses
|
||||
List<Status> childStatuses = new ArrayList<Status>();
|
||||
|
||||
String error = null;
|
||||
// Split output by OS-independend new-line
|
||||
for (String line : trace.split(System.getProperty("line.separator"))) {
|
||||
if (error == null)
|
||||
error = line;
|
||||
else
|
||||
childStatuses.add(new Status(IStatus.ERROR, Activator.PLUGIN_ID, line));
|
||||
}
|
||||
|
||||
MultiStatus multiStatus = new MultiStatus(Activator.PLUGIN_ID, IStatus.ERROR,
|
||||
childStatuses.toArray(new Status[] {}), // convert to array of
|
||||
// statuses
|
||||
error, ex);
|
||||
|
||||
ErrorDialog.openError(null, "Unexpected Error", message, multiStatus);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IEditorActionDelegate;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
|
||||
public class CountMarkersForFile implements IEditorActionDelegate {
|
||||
|
||||
public CountMarkersForFile() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveEditor(IAction action, IEditorPart editor) {
|
||||
}
|
||||
|
||||
/*
|
||||
* I am using this method to find the markers that are directly related to the specified ifile.
|
||||
* Then output the number of markers that are returned
|
||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
IFile file = (IFile) PlatformUI.getWorkbench().getActiveWorkbenchWindow().
|
||||
getActivePage().getActiveEditor().getEditorInput().
|
||||
getAdapter(IFile.class);
|
||||
List<IMarker> markers = MarkerFactory.findMarkers(file);
|
||||
MessageDialog dialog = new MessageDialog(MarkerPluginActivator.getShell(), "Marker Count", null, markers.size() + " marker(s)", MessageDialog.INFORMATION, new String[] {"OK"}, 0);
|
||||
dialog.open();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
import org.eclipse.jdt.core.IOpenable;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.TreeSelection;
|
||||
import org.eclipse.ui.IEditorActionDelegate;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
public class CountMarkersForFiles implements IEditorActionDelegate {
|
||||
|
||||
public CountMarkersForFiles() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveEditor(IAction action, IEditorPart editor) {
|
||||
}
|
||||
|
||||
/*
|
||||
* This is used to find all the markers for an IResource and any sub resources.
|
||||
* Then output the number of markers that are returned
|
||||
*/
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
TreeSelection selection = MarkerFactory.getTreeSelection();
|
||||
if (selection.getFirstElement() instanceof IOpenable) {
|
||||
IResource resource = (IResource) ((IAdaptable) selection.getFirstElement()).getAdapter(IResource.class);
|
||||
List<IMarker> markers = MarkerFactory.findAllMarkers(resource);
|
||||
|
||||
MessageDialog dialog = new MessageDialog(MarkerPluginActivator.getShell(), "Marker Count", null, markers.size() + " marker(s)", MessageDialog.INFORMATION, new String[] {"OK"}, 0);
|
||||
dialog.open();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IEditorActionDelegate;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
|
||||
public class CreateMarkerAction implements IEditorActionDelegate {
|
||||
|
||||
public CreateMarkerAction() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setActiveEditor(IAction action, IEditorPart editor) {
|
||||
}
|
||||
|
||||
/*
|
||||
* This action creates a new marker for the given IFile
|
||||
*/
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
try {
|
||||
TextSelection selection = MarkerFactory.getTextSelection();
|
||||
IFile file = (IFile) MarkerPluginActivator.getEditor().getEditorInput().getAdapter(IFile.class);
|
||||
IMarker mymarker = MarkerFactory.createMarker(file, new Position(selection.getOffset(), selection.getLength()));
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.IDecoration;
|
||||
import org.eclipse.jface.viewers.ILightweightLabelDecorator;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.swt.graphics.Color;
|
||||
import org.eclipse.swt.graphics.Font;
|
||||
|
||||
public class FileDecorator extends LabelProvider implements ILightweightLabelDecorator {
|
||||
|
||||
public static final String ICON = "/icons/sample.gif";
|
||||
private static Font font = new Font(null, "Arial", 10, 0);
|
||||
private static Color color = new Color(null, 0, 0, 255);
|
||||
|
||||
@Override
|
||||
public void decorate(Object resource, IDecoration decoration) {
|
||||
int markers = MarkerFactory.findMarkers((IResource) resource).size();
|
||||
if (MarkingController.file == resource) {
|
||||
decoration.addOverlay(ImageDescriptor.createFromFile(FileDecorator.class, ICON), IDecoration.TOP_RIGHT);
|
||||
decoration.addPrefix("");
|
||||
decoration.addSuffix(" - running ");
|
||||
decoration.setFont(font);
|
||||
decoration.setForegroundColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.jface.text.TextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.TreeSelection;
|
||||
|
||||
|
||||
public class MarkerFactory {
|
||||
|
||||
//Marker ID
|
||||
public static final String MARKER = "com.irtsaintexupery.fiacre.simulator.marking.marker";
|
||||
|
||||
//Annotation ID
|
||||
public static final String ANNOTATION = "com.irtsaintexupery.fiacre.simulator.marking.annotation";
|
||||
|
||||
/*
|
||||
* Creates a Marker
|
||||
*/
|
||||
public static IMarker createMarker(IResource res, Position position)
|
||||
throws CoreException {
|
||||
IMarker marker = null;
|
||||
//note: you use the id that is defined in your plugin.xml
|
||||
marker = res.createMarker(MARKER);
|
||||
marker.setAttribute(IMarker.MESSAGE, "My Marker");
|
||||
//compute and set char start and char end
|
||||
int start = position.getOffset();
|
||||
int end = position.getOffset() + position.getLength();
|
||||
marker.setAttribute(IMarker.CHAR_START, start);
|
||||
marker.setAttribute(IMarker.CHAR_END, end);
|
||||
return marker;
|
||||
}
|
||||
|
||||
/*
|
||||
* returns a list of a resources markers
|
||||
*/
|
||||
public static List<IMarker> findMarkers(IResource resource) {
|
||||
try {
|
||||
return Arrays.asList(resource.findMarkers(MARKER, true, IResource.DEPTH_ZERO));
|
||||
} catch (CoreException e) {
|
||||
return new ArrayList<IMarker>();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a list of markers that are linked to the resource or any sub resource of the resource
|
||||
*/
|
||||
public static List<IMarker> findAllMarkers(IResource resource) {
|
||||
try {
|
||||
return Arrays.asList(resource.findMarkers(MARKER, true, IResource.DEPTH_INFINITE));
|
||||
} catch (CoreException e) {
|
||||
return new ArrayList<IMarker>();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the selection of the package explorer
|
||||
*/
|
||||
public static TreeSelection getTreeSelection() {
|
||||
|
||||
ISelection selection = MarkerPluginActivator.getActiveWorkbenchWindow().getSelectionService().getSelection();
|
||||
if (selection instanceof TreeSelection) {
|
||||
return (TreeSelection)selection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns the selection of the package explorer
|
||||
*/
|
||||
public static TextSelection getTextSelection() {
|
||||
|
||||
ISelection selection = MarkerPluginActivator.getActiveWorkbenchWindow().getSelectionService().getSelection();
|
||||
if (selection instanceof TextSelection) {
|
||||
return (TextSelection)selection;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
// public static void addAnnotation(IMarker marker, ITextSelection selection, ITextEditor editor) {
|
||||
// //The DocumentProvider enables to get the document currently loaded in the editor
|
||||
// IDocumentProvider idp = editor.getDocumentProvider();
|
||||
//
|
||||
// //This is the document we want to connect to. This is taken from the current editor input.
|
||||
// IDocument document = idp.getDocument(editor.getEditorInput());
|
||||
//
|
||||
// //The IannotationModel enables to add/remove/change annoatation to a Document loaded in an Editor
|
||||
// IAnnotationModel iamf = idp.getAnnotationModel(editor.getEditorInput());
|
||||
//
|
||||
// //Note: The annotation type id specify that you want to create one of your annotations
|
||||
// SimpleMarkerAnnotation ma = new SimpleMarkerAnnotation(ANNOTATION, marker);
|
||||
//
|
||||
// //Finally add the new annotation to the model
|
||||
// iamf.connect(document);
|
||||
// iamf.addAnnotation(ma,new Position(selection.getOffset(),selection.getLength()));
|
||||
// iamf.disconnect(document);
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
import org.eclipse.ui.texteditor.ITextEditor;
|
||||
import org.osgi.framework.BundleContext;
|
||||
|
||||
/**
|
||||
* The activator class controls the plug-in life cycle
|
||||
*/
|
||||
public class MarkerPluginActivator extends AbstractUIPlugin {
|
||||
|
||||
// The plug-in ID
|
||||
public static final String PLUGIN_ID = "MyMarker";
|
||||
|
||||
// The shared instance
|
||||
private static MarkerPluginActivator plugin;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
public MarkerPluginActivator() {
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void start(BundleContext context) throws Exception {
|
||||
super.start(context);
|
||||
plugin = this;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
|
||||
*/
|
||||
public void stop(BundleContext context) throws Exception {
|
||||
plugin = null;
|
||||
super.stop(context);
|
||||
}
|
||||
|
||||
public static Shell getShell() {
|
||||
return getActiveWorkbenchWindow().getShell();
|
||||
}
|
||||
|
||||
public static IWorkbenchWindow getActiveWorkbenchWindow() {
|
||||
return PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the shared instance
|
||||
*
|
||||
* @return the shared instance
|
||||
*/
|
||||
public static MarkerPluginActivator getDefault() {
|
||||
return plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an image descriptor for the image file at the given
|
||||
* plug-in relative path
|
||||
*
|
||||
* @param path the path
|
||||
* @return the image descriptor
|
||||
*/
|
||||
public static ImageDescriptor getImageDescriptor(String path) {
|
||||
return imageDescriptorFromPlugin(PLUGIN_ID, path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Always good to have this static method as when dealing with IResources
|
||||
* having a interface to get the editor is very handy
|
||||
* @return
|
||||
*/
|
||||
public static ITextEditor getEditor() {
|
||||
return (ITextEditor) getActiveWorkbenchWindow().getActivePage().getActiveEditor();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.text.IDocument;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.ui.texteditor.IMarkerUpdater;
|
||||
|
||||
public class MarkerUpdater implements IMarkerUpdater {
|
||||
/*
|
||||
*Returns the attributes for which this updater is responsible.
|
||||
*If the result is null, the updater assumes responsibility for any attributes.
|
||||
*/
|
||||
@Override
|
||||
public String[] getAttribute() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMarkerType() {
|
||||
//returns the marker type that we are interested in updating
|
||||
return MarkerFactory.MARKER;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean updateMarker(IMarker marker, IDocument doc, Position position) {
|
||||
try {
|
||||
int start = position.getOffset();
|
||||
int end = position.getOffset() + position.getLength();
|
||||
marker.setAttribute(IMarker.CHAR_START, start);
|
||||
marker.setAttribute(IMarker.CHAR_END, end);
|
||||
return true;
|
||||
} catch (CoreException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.marking;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IMarker;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.jface.text.Position;
|
||||
import org.eclipse.xtext.nodemodel.impl.CompositeNode;
|
||||
import org.eclipse.xtext.nodemodel.util.NodeModelUtils;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceStatementBlock;
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.StatementBlock;
|
||||
|
||||
import fr.irit.fiacre.xtext.fiacre.Statement;
|
||||
import fr.irit.fiacre.xtext.ui.internal.XtextActivator;
|
||||
|
||||
public class MarkingController {
|
||||
// added selection attribute
|
||||
public static IFile file;
|
||||
|
||||
protected static XtextResource getFiacreXtextResource(IFile file) {
|
||||
Injector injector = XtextActivator.getInstance().getInjector("fr.irit"
|
||||
+ ".fiacre.xtext.Fiacre");
|
||||
XtextResourceSetProvider provider = injector
|
||||
.getInstance(XtextResourceSetProvider.class);
|
||||
ResourceSet resourceSet = provider.get(file.getProject());
|
||||
|
||||
URI xtextURI = URI.createPlatformResourceURI(file
|
||||
.getFullPath().toString(), true);
|
||||
|
||||
return (XtextResource) resourceSet.getResource(xtextURI, true);
|
||||
}
|
||||
|
||||
// Jorge Gutierrez 05/08/2016
|
||||
public static void highlightCode(StatementBlock statementblock) {
|
||||
|
||||
for (InstanceStatementBlock isb : statementblock
|
||||
.getInstanceStatementBlocks()) {
|
||||
CompositeNode tr_source_cn = (CompositeNode) NodeModelUtils
|
||||
.findActualNodeFor(isb.getTransitionSource());
|
||||
try {
|
||||
IMarker tr_src_marker = MarkerFactory.createMarker(file,
|
||||
new Position(tr_source_cn.getOffset(), tr_source_cn
|
||||
.getLength()));
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Statement s : isb.getStatements()) {
|
||||
CompositeNode s_cn = (CompositeNode) NodeModelUtils
|
||||
.findActualNodeFor(s);
|
||||
try {
|
||||
IMarker smarker = MarkerFactory.createMarker(file,
|
||||
new Position(s_cn.getOffset(), s_cn.getLength()));
|
||||
} catch (CoreException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Jorge Gutierrez 08/08/2016
|
||||
public static void deleteMarkers (IFile file){
|
||||
try {
|
||||
// int markers = MarkerFactory.findMarkers(file).size();
|
||||
// System.out.println("#marks before " + markers);
|
||||
// System.out.println("file " + file);
|
||||
file.deleteMarkers("com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".marking.marker", true, 0);
|
||||
// markers = MarkerFactory.findMarkers(file).size();
|
||||
// System.out.println("#marks after " + markers);
|
||||
|
||||
} catch (CoreException e) {
|
||||
//TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,83 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective;
|
||||
|
||||
import org.eclipse.ui.IFolderLayout;
|
||||
import org.eclipse.ui.IPageLayout;
|
||||
import org.eclipse.ui.IPerspectiveFactory;
|
||||
|
||||
public class PerspectiveSimulatorFactory implements IPerspectiveFactory {
|
||||
|
||||
@Override
|
||||
public void createInitialLayout(IPageLayout layout) {
|
||||
defineActions(layout);
|
||||
defineLayout(layout);
|
||||
|
||||
}
|
||||
|
||||
public void defineActions (IPageLayout layout){
|
||||
//Add "new wizards"
|
||||
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.folder");
|
||||
layout.addNewWizardShortcut("org.eclipse.ui.wizards.new.file");
|
||||
|
||||
//Add "show views"
|
||||
layout.addShowViewShortcut(IPageLayout.ID_RES_NAV);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_BOOKMARKS);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_OUTLINE);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_PROP_SHEET);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_PROP_SHEET);
|
||||
layout.addShowViewShortcut(IPageLayout.ID_TASK_LIST);
|
||||
}
|
||||
|
||||
public void defineLayout(IPageLayout layout) {
|
||||
//Editors are placed for free
|
||||
String editorArea = layout.getEditorArea();
|
||||
|
||||
//Place navigator and outiline to left of editor area.
|
||||
IFolderLayout navigator = layout.createFolder("navigator",
|
||||
IPageLayout.LEFT, (float) 0.18, editorArea);
|
||||
IFolderLayout instances = layout.createFolder("instances",
|
||||
IPageLayout.RIGHT, (float) 0.75, editorArea);
|
||||
IFolderLayout values = layout.createFolder("values",
|
||||
IPageLayout.BOTTOM, (float) 0.75, editorArea);
|
||||
IFolderLayout transitions = layout.createFolder("transitions",
|
||||
IPageLayout.BOTTOM, (float) 0.25, "instances");
|
||||
IFolderLayout executedAction = layout.createFolder("executedAction",
|
||||
IPageLayout.BOTTOM, (float) 0.5, "transitions");
|
||||
IFolderLayout savedStates = layout.createFolder("savedStates",
|
||||
IPageLayout.BOTTOM, (float) 0.4, "executedAction");
|
||||
|
||||
navigator.addView("org.eclipse.ui.navigator.ProjectExplorer");
|
||||
instances.addView("com.irtsaintexupery.fiacre.simulator.perspective"
|
||||
+ ".instancesView");
|
||||
transitions.addView("com.irtsaintexupery.fiacre.simulator.perspective"
|
||||
+ ".transitionsView");
|
||||
values.addView("com.irtsaintexupery.fiacre.simulator.perspective"
|
||||
+ ".valuesView");
|
||||
executedAction.addView("com.irtsaintexupery.fiacre.simulator.perspective"
|
||||
+ ".executedActionView");
|
||||
executedAction.addView("com.irtsaintexupery.fiacre.simulator.perspective"
|
||||
+ ".savedStatesView");
|
||||
}
|
||||
|
||||
public interface IPerspectivePlugin {
|
||||
//*plugin id
|
||||
public final static String PLUGIN_ID = "com.irtsaintexupery.fiacre"
|
||||
+ ".simulator.perspective";
|
||||
|
||||
//*perspective id
|
||||
public final static String TEST_PERSPECTIVE_ID = "com.irtsaintexupery"
|
||||
+ ".fiacre.simulator.perspective.fiacreSimulator";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.model;
|
||||
|
||||
public class ActionState {
|
||||
String action;
|
||||
Boolean delay;
|
||||
|
||||
public ActionState() {
|
||||
super();
|
||||
}
|
||||
|
||||
public ActionState(String action, Boolean delay) {
|
||||
super();
|
||||
this.action = action;
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
public String getAction() {
|
||||
return action;
|
||||
}
|
||||
|
||||
public void setAction(String action) {
|
||||
this.action = action;
|
||||
}
|
||||
|
||||
public Boolean getDelay() {
|
||||
return delay;
|
||||
}
|
||||
|
||||
public void setDelay(Boolean delay) {
|
||||
this.delay = delay;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.model;
|
||||
|
||||
import org.eclipse.core.runtime.IAdaptable;
|
||||
|
||||
public class TreeObject implements IAdaptable {
|
||||
private String name;
|
||||
private TreeParent parent;
|
||||
|
||||
public TreeObject(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setParent(TreeParent parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
public TreeParent getParent() {
|
||||
return parent;
|
||||
}
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
public <T> T getAdapter(Class<T> key) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class TreeParent extends TreeObject {
|
||||
private ArrayList children;
|
||||
public TreeParent(String name) {
|
||||
super(name);
|
||||
children = new ArrayList();
|
||||
}
|
||||
public void addChild(TreeObject child) {
|
||||
children.add(child);
|
||||
child.setParent(this);
|
||||
}
|
||||
public void removeChild(TreeObject child) {
|
||||
children.remove(child);
|
||||
child.setParent(null);
|
||||
}
|
||||
public TreeObject [] getChildren() {
|
||||
return (TreeObject [])children.toArray(new TreeObject[children.size()]);
|
||||
}
|
||||
public boolean hasChildren() {
|
||||
return children.size()>0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.model;
|
||||
|
||||
public class ValuesData {
|
||||
private String name;
|
||||
private String initial;
|
||||
private String current;
|
||||
|
||||
public ValuesData(){
|
||||
name = "";
|
||||
initial = "";
|
||||
current = "";
|
||||
}
|
||||
|
||||
public ValuesData(String n, String i, String c){
|
||||
name = n;
|
||||
initial = i;
|
||||
current = c;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String getInitial() {
|
||||
return initial;
|
||||
}
|
||||
public void setInitial(String initial) {
|
||||
this.initial = initial;
|
||||
}
|
||||
public String getCurrent() {
|
||||
return current;
|
||||
}
|
||||
public void setCurrent(String current) {
|
||||
this.current = current;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.model;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public enum ValuesDataProvider {
|
||||
INSTANCE;
|
||||
|
||||
///faire atention avec la privacité
|
||||
|
||||
private static List<ValuesData> data = new ArrayList<ValuesData>();
|
||||
|
||||
ValuesDataProvider() {
|
||||
}
|
||||
|
||||
public static void addValues(ValuesData values){
|
||||
data.add(values);
|
||||
}
|
||||
|
||||
public ValuesData getValues(Integer index){
|
||||
return data.get(index);
|
||||
}
|
||||
|
||||
public List<ValuesData> getData(){
|
||||
return data;
|
||||
}
|
||||
|
||||
public static void removeData(){
|
||||
data.clear();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,171 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
|
||||
public class ExecutedActionView extends ViewPart {
|
||||
|
||||
public static final String ID = "com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".perspective.executedActionView";
|
||||
|
||||
private TableViewer viewer;
|
||||
private Action undo;
|
||||
|
||||
private Vector <String> elementsTable = new Vector <String> ();
|
||||
|
||||
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
public String getColumnText(Object obj, int index) {
|
||||
return getText(obj);
|
||||
}
|
||||
public Image getColumnImage(Object obj, int index) {
|
||||
return getImage(obj);
|
||||
}
|
||||
public Image getImage(Object obj) {
|
||||
if (ViewsController.INSTANCE.isDelay(getText(obj))) {
|
||||
Image im = getImage("icons/time_add.png");
|
||||
return im;
|
||||
}else {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(ISharedImages.IMG_OBJS_TASK_TSK);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public ExecutedActionView() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
//TODO add elements to the table
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
|
||||
"ExecutedActionView.viewer");
|
||||
getSite().setSelectionProvider(viewer);
|
||||
makeActions();
|
||||
contributeToActionBars();
|
||||
undo.setEnabled(false);
|
||||
undo.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(new Separator());
|
||||
manager.add(undo);
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(undo);
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
undo = new Action() {
|
||||
public void run() {
|
||||
if (!elementsTable.isEmpty()) {
|
||||
ViewsController.INSTANCE.undoAction();
|
||||
}
|
||||
}
|
||||
};
|
||||
undo.setText("Undo");
|
||||
undo.setToolTipText("Undo");
|
||||
// ImageDescriptor imageDescriptorUndo = AbstractUIPlugin
|
||||
// .imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
// + ".simulator.perspective", "/icons/arrow_undo.png" );
|
||||
|
||||
undo.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
|
||||
//
|
||||
// redo = new Action() {
|
||||
// public void run() {
|
||||
// showMessage("Redo executed");
|
||||
// }
|
||||
// };
|
||||
// redo.setText("Redo");
|
||||
// redo.setToolTipText("Redo tooltip");
|
||||
// ImageDescriptor imageDescriptorRedo = AbstractUIPlugin
|
||||
// .imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
// + ".simulator.perspective", "/icons/arrow_redo.png" );
|
||||
// redo.setImageDescriptor(imageDescriptorRedo);
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
"Executed Action View",
|
||||
message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
|
||||
}
|
||||
|
||||
public void update(ArrayList<String> list) {
|
||||
elementsTable.clear();
|
||||
for (String s : list) {
|
||||
elementsTable.add(s);
|
||||
}
|
||||
if (elementsTable.isEmpty()) {
|
||||
undo.setEnabled(false);
|
||||
undo.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
|
||||
}else{
|
||||
undo.setEnabled(true);
|
||||
undo.setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
|
||||
}
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,264 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.views;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.ui.part.*;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.model.TreeObject;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.model.TreeParent;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.ui.*;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
||||
public class InstancesView extends ViewPart {
|
||||
|
||||
/**
|
||||
* The ID of the view as specified by the extension.
|
||||
*/
|
||||
public static final String ID = "com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".perspective.instancesView";
|
||||
|
||||
private TreeViewer viewer;
|
||||
private DrillDownAdapter drillDownAdapter;
|
||||
private Action doubleClickAction;
|
||||
private Action oneClickAction;
|
||||
private TreeObject instanceTree;
|
||||
|
||||
|
||||
|
||||
class ViewContentProvider implements ITreeContentProvider {
|
||||
@Override
|
||||
public void dispose() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
@Override
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
private TreeParent invisibleRoot;
|
||||
|
||||
public Object[] getElements(Object parent) {
|
||||
if (parent.equals(getViewSite())) {
|
||||
if (invisibleRoot==null) initialize();
|
||||
return getChildren(invisibleRoot);
|
||||
}
|
||||
return getChildren(parent);
|
||||
}
|
||||
public Object getParent(Object child) {
|
||||
if (child instanceof TreeObject) {
|
||||
return ((TreeObject)child).getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public Object [] getChildren(Object parent) {
|
||||
if (parent instanceof TreeParent) {
|
||||
return ((TreeParent)parent).getChildren();
|
||||
}
|
||||
return new Object[0];
|
||||
}
|
||||
public boolean hasChildren(Object parent) {
|
||||
if (parent instanceof TreeParent)
|
||||
return ((TreeParent)parent).hasChildren();
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
invisibleRoot = (TreeParent) instanceTree;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
class ViewLabelProvider extends ColumnLabelProvider {
|
||||
@Override
|
||||
public String getText(Object obj) {
|
||||
return obj.toString();
|
||||
|
||||
}
|
||||
@Override
|
||||
public Image getImage(Object obj) {
|
||||
String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
|
||||
if (obj instanceof TreeParent)
|
||||
if (((TreeParent) obj).getName().equals("")) {
|
||||
imageKey = ISharedImages.IMG_TOOL_UP_DISABLED;
|
||||
}else {
|
||||
imageKey = ISharedImages.IMG_TOOL_UP;
|
||||
}
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolTipText(Object obj) {
|
||||
return ViewsController.INSTANCE.returnFlatName((TreeObject) obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolTipDisplayDelayTime(Object object) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getToolTipTimeDisplayed(Object object) {
|
||||
return 5000;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public InstancesView() {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is a callback that will allow us
|
||||
* to create the viewer and initialize it.
|
||||
*/
|
||||
public void createPartControl(Composite parent) {
|
||||
|
||||
//create the content
|
||||
viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
drillDownAdapter = new DrillDownAdapter(viewer);
|
||||
|
||||
viewer.setContentProvider(new ViewContentProvider());
|
||||
|
||||
ColumnViewerToolTipSupport.enableFor(viewer);
|
||||
|
||||
viewer.setInput(getViewSite());
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
|
||||
viewer.expandAll();
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
|
||||
"viewDemo2.viewer");
|
||||
getSite().setSelectionProvider(viewer);
|
||||
makeActions();
|
||||
hookContextMenu();
|
||||
hookDoubleClickAction();
|
||||
hookOneClickAction();
|
||||
contributeToActionBars();
|
||||
}
|
||||
|
||||
private void hookContextMenu() {
|
||||
MenuManager menuMgr = new MenuManager("#PopupMenu");
|
||||
menuMgr.setRemoveAllWhenShown(true);
|
||||
menuMgr.addMenuListener(new IMenuListener() {
|
||||
public void menuAboutToShow(IMenuManager manager) {
|
||||
}
|
||||
});
|
||||
Menu menu = menuMgr.createContextMenu(viewer.getControl());
|
||||
viewer.getControl().setMenu(menu);
|
||||
getSite().registerContextMenu(menuMgr, viewer);
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
doubleClickAction = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
//showMessage("Double-click detected on "+obj.toString());
|
||||
if (!selection.isEmpty()) {
|
||||
ViewsController.INSTANCE.showInstanceSelected((TreeObject)obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
oneClickAction = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
if (selection != null & selection instanceof IStructuredSelection
|
||||
&& obj != null) {
|
||||
ViewsController.INSTANCE.showValuesView((TreeObject)obj);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private void hookDoubleClickAction() {
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
doubleClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void hookOneClickAction() {
|
||||
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
oneClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
"Instances View",
|
||||
message);
|
||||
}
|
||||
|
||||
/**
|
||||
* Passing the focus request to the viewer's control.
|
||||
*/
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
}
|
||||
|
||||
|
||||
public void update(TreeObject rood) {
|
||||
instanceTree = rood;
|
||||
viewer.setContentProvider(new ViewContentProvider());
|
||||
viewer.setInput(getViewSite());
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
|
||||
viewer.expandAll();
|
||||
}
|
||||
|
||||
public void selectInstanceObject(TreeObject obj) {
|
||||
viewer.setSelection(new StructuredSelection(obj), true);
|
||||
}
|
||||
|
||||
public void selectInstanceObject(ArrayList<TreeObject> instanceList) {
|
||||
|
||||
TreeObject[] array = new TreeObject[instanceList.size()];
|
||||
for (int i = 0; i < instanceList.size(); i++) {
|
||||
array[i] = instanceList.get(i);
|
||||
}
|
||||
viewer.setSelection(new StructuredSelection(array), true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,286 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.views;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.eclipse.jface.action.Action;
|
||||
import org.eclipse.jface.action.IMenuManager;
|
||||
import org.eclipse.jface.action.IToolBarManager;
|
||||
import org.eclipse.jface.action.Separator;
|
||||
import org.eclipse.jface.dialogs.IDialogConstants;
|
||||
import org.eclipse.jface.dialogs.IMessageProvider;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.dialogs.TitleAreaDialog;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.jface.viewers.ArrayContentProvider;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.ITableLabelProvider;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.TableViewer;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
import org.eclipse.swt.layout.GridLayout;
|
||||
import org.eclipse.swt.widgets.Button;
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Control;
|
||||
import org.eclipse.swt.widgets.Dialog;
|
||||
import org.eclipse.swt.widgets.Display;
|
||||
import org.eclipse.swt.widgets.Event;
|
||||
import org.eclipse.swt.widgets.Label;
|
||||
import org.eclipse.swt.widgets.Listener;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.swt.widgets.Text;
|
||||
import org.eclipse.ui.IActionBars;
|
||||
import org.eclipse.ui.ISharedImages;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.views.ExecutedActionView.ViewLabelProvider;
|
||||
|
||||
public class SavedStatesView extends ViewPart {
|
||||
|
||||
public static final String ID = "com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".perspective.SavedStatesView";
|
||||
|
||||
private TableViewer viewer;
|
||||
private Action save;
|
||||
private Action goTo;
|
||||
private Action delete;
|
||||
|
||||
private Vector <String> elementsTable = new Vector <String> ();
|
||||
|
||||
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
public String getColumnText(Object obj, int index) {
|
||||
return getText(obj);
|
||||
}
|
||||
public Image getColumnImage(Object obj, int index) {
|
||||
return getImage(obj);
|
||||
}
|
||||
public Image getImage(Object obj) {
|
||||
return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages
|
||||
.IMG_OPEN_MARKER);
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public SavedStatesView() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
//TODO add elements to the table
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
|
||||
"ExecutedActionView.viewer");
|
||||
getSite().setSelectionProvider(viewer);
|
||||
makeActions();
|
||||
contributeToActionBars();
|
||||
save.setEnabled(false);
|
||||
goTo.setEnabled(false);
|
||||
delete.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(new Separator());
|
||||
manager.add(save);
|
||||
manager.add(new Separator());
|
||||
manager.add(goTo);
|
||||
manager.add(new Separator());
|
||||
manager.add(delete);
|
||||
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(save);
|
||||
manager.add(goTo);
|
||||
manager.add(delete);
|
||||
}
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
save = new Action() {
|
||||
public void run() {
|
||||
SaveStateDialog dialog = new SaveStateDialog(viewer.getControl().getShell());
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK) {
|
||||
elementsTable.add(dialog.getTag());
|
||||
ViewsController.INSTANCE.addStateToMap(dialog.getTag());
|
||||
}
|
||||
}
|
||||
};
|
||||
save.setText("Save");
|
||||
save.setToolTipText("Save");
|
||||
ImageDescriptor imageDescriptorSave = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
+ ".simulator", "/icons/brick_add.png" );
|
||||
save.setImageDescriptor(imageDescriptorSave);
|
||||
|
||||
goTo = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
if (!selection.isEmpty()) {
|
||||
if (selection != null && selection instanceof IStructuredSelection) {
|
||||
ViewsController.INSTANCE.goToState(obj.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
goTo.setText("GoTo");
|
||||
goTo.setToolTipText("GoTo");
|
||||
ImageDescriptor imageDescriptorGoTo = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
+ ".simulator", "/icons/brick_go.png" );
|
||||
goTo.setImageDescriptor(imageDescriptorGoTo);
|
||||
|
||||
delete = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
if (!selection.isEmpty()) {
|
||||
if (selection != null && selection instanceof IStructuredSelection) {
|
||||
ViewsController.INSTANCE.deleteState(obj.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
delete.setText("Delete");
|
||||
delete.setToolTipText("Delete");
|
||||
ImageDescriptor imageDescriptorDelete = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
+ ".simulator", "/icons/brick_delete.png" );
|
||||
delete.setImageDescriptor(imageDescriptorDelete);
|
||||
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
"Executed Action View",
|
||||
message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class SaveStateDialog extends TitleAreaDialog {
|
||||
private Text tagLabel;
|
||||
private String tag;
|
||||
|
||||
public SaveStateDialog(Shell parentShell) {
|
||||
super(parentShell);
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create() {
|
||||
super.create();
|
||||
setTitle("Save state");
|
||||
setMessage("write a identifier Tag to current state", IMessageProvider.INFORMATION);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Control createDialogArea(Composite parent) {
|
||||
Composite area = (Composite) super.createDialogArea(parent);
|
||||
Composite container = new Composite(area, SWT.NONE);
|
||||
container.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
|
||||
GridLayout layout = new GridLayout(2, false);
|
||||
container.setLayout(layout);
|
||||
|
||||
createTagLabel(container);
|
||||
|
||||
return area;
|
||||
}
|
||||
|
||||
private void createTagLabel(Composite container) {
|
||||
Label lbtFirstName = new Label(container, SWT.NONE);
|
||||
lbtFirstName.setText("State Tag");
|
||||
|
||||
GridData dataFirstName = new GridData();
|
||||
dataFirstName.grabExcessHorizontalSpace = true;
|
||||
dataFirstName.horizontalAlignment = GridData.FILL;
|
||||
|
||||
tagLabel = new Text(container, SWT.BORDER);
|
||||
tagLabel.setLayoutData(dataFirstName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean isResizable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// save content of the Text fields because they get disposed
|
||||
// as soon as the Dialog closes
|
||||
private void saveInput() {
|
||||
tag = tagLabel.getText();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void okPressed() {
|
||||
saveInput();
|
||||
super.okPressed();
|
||||
}
|
||||
|
||||
public String getTag() {
|
||||
return tag;
|
||||
}
|
||||
}
|
||||
|
||||
public void update(ArrayList<String> list) {
|
||||
elementsTable.clear();
|
||||
for (String s : list) {
|
||||
elementsTable.add(s);
|
||||
}
|
||||
if(ViewsController.INSTANCE.getFile() != null){
|
||||
save.setEnabled(true);
|
||||
goTo.setEnabled(true);
|
||||
delete.setEnabled(true);
|
||||
}else {
|
||||
save.setEnabled(false);
|
||||
goTo.setEnabled(false);
|
||||
delete.setEnabled(false);
|
||||
}
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,260 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.views;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Menu;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.part.*;
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.apache.thrift.TException;
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.dialogs.MessageDialog;
|
||||
import org.eclipse.jface.resource.ImageDescriptor;
|
||||
import org.eclipse.ui.*;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.ui.part.ViewPart;
|
||||
import org.eclipse.ui.plugin.AbstractUIPlugin;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.core.DelayEvent;
|
||||
import com.irtsaintexupery.fiacre.simulator.core.FiacreSimulator;
|
||||
import com.irtsaintexupery.fiacre.simulator.core.ReadDelay;
|
||||
import com.irtsaintexupery.fiacre.simulator.core.Utils;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
import com.irtsaintexupery.fiacre.simulator.staticjson.extractor.DynamicJsonExtractor;
|
||||
|
||||
import fr.laas.libtts.LibTTS;
|
||||
import tts.Error;
|
||||
import tts.InvalidDelay;
|
||||
import tts.StateNotFound;
|
||||
|
||||
|
||||
|
||||
public class TransitionsView extends ViewPart {
|
||||
|
||||
public static final String ID = "com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".perspective.transitionsView";
|
||||
|
||||
private TableViewer viewer;
|
||||
private Action doubleClickAction;
|
||||
private Action oneClickAction;
|
||||
private Action delay;
|
||||
|
||||
private Vector <String> elementsTable = new Vector <String> ();
|
||||
|
||||
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
public String getColumnText(Object obj, int index) {
|
||||
return getText(obj);
|
||||
}
|
||||
public Image getColumnImage(Object obj, int index) {
|
||||
return getImage(obj);
|
||||
}
|
||||
public Image getImage(Object obj) {
|
||||
if (ViewsController.INSTANCE.isFireable(getText(obj))) {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(ISharedImages.IMG_OBJ_ADD);
|
||||
}else {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(ISharedImages.IMG_ELCL_STOP);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public TransitionsView() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
|
||||
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
//TODO add elements to the table
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
|
||||
// Create the help context id for the viewer's control
|
||||
PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(),
|
||||
"TransitionView.viewer");
|
||||
getSite().setSelectionProvider(viewer);
|
||||
makeActions();
|
||||
hookDoubleClickAction();
|
||||
hookOneClickAction();
|
||||
contributeToActionBars();
|
||||
delay.setEnabled(false);
|
||||
|
||||
}
|
||||
|
||||
private void contributeToActionBars() {
|
||||
IActionBars bars = getViewSite().getActionBars();
|
||||
fillLocalPullDown(bars.getMenuManager());
|
||||
fillLocalToolBar(bars.getToolBarManager());
|
||||
}
|
||||
|
||||
private void fillLocalPullDown(IMenuManager manager) {
|
||||
manager.add(new Separator());
|
||||
manager.add(delay);
|
||||
}
|
||||
|
||||
private void fillLocalToolBar(IToolBarManager manager) {
|
||||
manager.add(delay);
|
||||
}
|
||||
|
||||
|
||||
private void makeActions() {
|
||||
|
||||
doubleClickAction = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
//showMessage("Double-click fire on "+obj.toString());
|
||||
if (!selection.isEmpty()) {
|
||||
if (selection != null && selection instanceof IStructuredSelection
|
||||
&& ViewsController.INSTANCE.isFireable(obj.toString())
|
||||
) {
|
||||
ViewsController.INSTANCE.fireTransition(obj.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
oneClickAction = new Action() {
|
||||
public void run() {
|
||||
ISelection selection = viewer.getSelection();
|
||||
Object obj = ((IStructuredSelection)selection).getFirstElement();
|
||||
if (selection != null & selection instanceof IStructuredSelection
|
||||
&& obj != null) {
|
||||
ViewsController.INSTANCE.showSelectedTransition(obj
|
||||
.toString());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
delay = new Action() {
|
||||
public void run() {
|
||||
///////////////DELAY
|
||||
delay();
|
||||
}
|
||||
};
|
||||
delay.setText("delay");
|
||||
delay.setToolTipText("Delay");
|
||||
ImageDescriptor imageDescriptordelay = AbstractUIPlugin
|
||||
.imageDescriptorFromPlugin( "com.irtsaintexupery.fiacre"
|
||||
+ ".simulator", "/icons/time_add.png" );
|
||||
|
||||
delay.setImageDescriptor(imageDescriptordelay);
|
||||
}
|
||||
|
||||
private void hookDoubleClickAction() {
|
||||
viewer.addDoubleClickListener(new IDoubleClickListener() {
|
||||
public void doubleClick(DoubleClickEvent event) {
|
||||
doubleClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void hookOneClickAction() {
|
||||
viewer.addSelectionChangedListener(new ISelectionChangedListener() {
|
||||
@Override
|
||||
public void selectionChanged(SelectionChangedEvent event) {
|
||||
oneClickAction.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void showMessage(String message) {
|
||||
MessageDialog.openInformation(
|
||||
viewer.getControl().getShell(),
|
||||
"Transition View",
|
||||
message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
|
||||
}
|
||||
|
||||
public void update(ArrayList<String> list) {
|
||||
delay.setEnabled(true);
|
||||
elementsTable.clear();
|
||||
for (String s : list) {
|
||||
elementsTable.add(s);
|
||||
}
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
}
|
||||
|
||||
public void clearContent() {
|
||||
elementsTable.clear();
|
||||
delay.setEnabled(false);
|
||||
viewer.setContentProvider(ArrayContentProvider.getInstance());
|
||||
viewer.setInput(elementsTable);
|
||||
viewer.setLabelProvider(new ViewLabelProvider());
|
||||
}
|
||||
|
||||
//Jorge Gutierrez 22/08/2016
|
||||
public void delay(){
|
||||
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow()
|
||||
.getActivePage().getActivePart().getSite().getShell();
|
||||
ReadDelay dialog = new ReadDelay(shell);
|
||||
dialog.create();
|
||||
if (dialog.open() == Window.OK) {
|
||||
dialog.getValue();
|
||||
LibTTS libtts = FiacreSimulator.getLibTTS();
|
||||
DynamicJsonExtractor dje = FiacreSimulator.sendDje();
|
||||
try {
|
||||
libtts.getTTSSimulator().delay(dialog.getValue());
|
||||
dje.extractExecutableStatements();
|
||||
|
||||
|
||||
//Jorge Gutierrez 03/08/2016
|
||||
ViewsController.INSTANCE.updateTransitionView();
|
||||
ViewsController.INSTANCE.addDelayToAction(dialog.getValue());
|
||||
ViewsController.INSTANCE.updateExecutedActionView();
|
||||
|
||||
dje.saveInstanceResource();
|
||||
} catch (Error e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("Error",e);
|
||||
//e.printStackTrace();
|
||||
} catch (StateNotFound e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("StateNotFound",e);
|
||||
//e.printStackTrace();
|
||||
} catch (InvalidDelay e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("InvalidDelay",e);
|
||||
//e.printStackTrace();
|
||||
} catch (TException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("TException",e);
|
||||
//e.printStackTrace();
|
||||
} catch (NumberFormatException e) {
|
||||
// TODO Auto-generated catch block
|
||||
Utils.showException("NumberFormatException: "+dialog.getValue()+" is not numeric value",e);
|
||||
//e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,139 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.perspective.views;
|
||||
|
||||
import org.eclipse.swt.widgets.Composite;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.part.*;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.model.ValuesData;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.model.ValuesDataProvider;
|
||||
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.swt.graphics.Image;
|
||||
import org.eclipse.swt.layout.GridData;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.ui.*;
|
||||
import org.eclipse.swt.widgets.Table;
|
||||
import org.eclipse.swt.widgets.TableColumn;
|
||||
import org.eclipse.swt.SWT;
|
||||
|
||||
|
||||
public class ValuesView extends ViewPart {
|
||||
public static final String ID = "com.irtsaintexupery.fiacre.simulator"
|
||||
+ ".perspective.valuesView";
|
||||
|
||||
private TableViewer viewer;
|
||||
private Action doubleClickAction;
|
||||
|
||||
|
||||
|
||||
class ViewLabelProvider extends LabelProvider implements ITableLabelProvider {
|
||||
public String getColumnText(Object obj, int index) {
|
||||
return getText(obj);
|
||||
}
|
||||
public Image getColumnImage(Object obj, int index) {
|
||||
return getImage(obj);
|
||||
}
|
||||
public Image getImage(Object obj) {
|
||||
return PlatformUI.getWorkbench().getSharedImages()
|
||||
.getImage(ISharedImages.IMG_OBJ_ELEMENT);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* The constructor.
|
||||
*/
|
||||
public ValuesView() {
|
||||
// TODO Auto-generated constructor stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createPartControl(Composite parent) {
|
||||
viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL
|
||||
| SWT.FULL_SELECTION | SWT.BORDER);
|
||||
createTable(parent);
|
||||
final Table table = viewer.getTable();
|
||||
table.setHeaderVisible(true);
|
||||
table.setLinesVisible(true);
|
||||
|
||||
viewer.setContentProvider(new ArrayContentProvider());
|
||||
// get the content for the viewer, setInput will call getElements in the
|
||||
// contentProvider
|
||||
viewer.setInput(ValuesDataProvider.INSTANCE.getData());
|
||||
// make the selection available to other views
|
||||
getSite().setSelectionProvider(viewer);
|
||||
// set the sorter for the table
|
||||
|
||||
// define layout for the viewer
|
||||
GridData gridData = new GridData();
|
||||
gridData.verticalAlignment = GridData.FILL;
|
||||
gridData.horizontalSpan = 2;
|
||||
gridData.grabExcessHorizontalSpace = true;
|
||||
gridData.grabExcessVerticalSpace = true;
|
||||
gridData.horizontalAlignment = GridData.FILL;
|
||||
viewer.getControl().setLayoutData(gridData);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFocus() {
|
||||
viewer.getControl().setFocus();
|
||||
|
||||
}
|
||||
|
||||
private void createTable(Composite parent){
|
||||
String[] titles = { "Name", "Current Value" };
|
||||
int[] bounds = { 100, 100 };
|
||||
|
||||
// Name
|
||||
TableViewerColumn col = createTableViewerColumn(titles[0], bounds[0], 0);
|
||||
col.setLabelProvider(new ColumnLabelProvider() {
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
ValuesData e = (ValuesData)element;
|
||||
return e.getName();
|
||||
}
|
||||
});
|
||||
|
||||
// Current Value
|
||||
col = createTableViewerColumn(titles[1], bounds[1], 1);
|
||||
col.setLabelProvider(new ColumnLabelProvider() {
|
||||
@Override
|
||||
public String getText(Object element) {
|
||||
ValuesData e = (ValuesData)element;
|
||||
return ""+e.getCurrent();
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private TableViewerColumn createTableViewerColumn(String title, int bound,
|
||||
final int colNumber) {
|
||||
final TableViewerColumn viewerColumn = new TableViewerColumn(viewer,
|
||||
SWT.NONE);
|
||||
final TableColumn column = viewerColumn.getColumn();
|
||||
column.setText(title);
|
||||
column.setWidth(bound);
|
||||
column.setResizable(true);
|
||||
column.setMoveable(true);
|
||||
return viewerColumn;
|
||||
}
|
||||
|
||||
public void update() {
|
||||
viewer.setInput(ValuesDataProvider.INSTANCE.getData());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.popup.actions;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IActionDelegate;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
|
||||
import com.irtsaintexupery.fiacre.simulator.core.FiacreSimulator;
|
||||
import com.irtsaintexupery.fiacre.simulator.perspective.ViewsController;
|
||||
|
||||
|
||||
public class FiacreSimulationAction implements IObjectActionDelegate {
|
||||
|
||||
private Shell shell;
|
||||
// added selection attribute
|
||||
private ISelection selection;
|
||||
|
||||
/**
|
||||
* Constructor for Action1.
|
||||
*/
|
||||
public FiacreSimulationAction() {
|
||||
super();
|
||||
//toto
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
shell = targetPart.getSite().getShell();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#run(IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
// charger le fichier .fcr
|
||||
|
||||
//Jorge Gutierrez 12/08/2016
|
||||
try {
|
||||
ViewsController.INSTANCE.launchFeedBack();
|
||||
} catch (InvocationTargetException | InterruptedException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
IFile file = getFile();
|
||||
|
||||
FiacreSimulator simfcr = new FiacreSimulator(file);
|
||||
|
||||
}
|
||||
|
||||
// added getFile() method
|
||||
private IFile getFile() {
|
||||
return (IFile) ((IStructuredSelection) selection).getFirstElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
// Don't forget this line.
|
||||
// It is the most important line.
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,247 @@
|
||||
package com.irt.ingequip.fiacre.simulator.popup.actions;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.emf.ecore.resource.ResourceSet;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.BadLocationException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.swt.widgets.Shell;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.xtext.nodemodel.INode;
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
|
||||
import org.eclipse.xtext.resource.XtextResource;
|
||||
import org.eclipse.xtext.ui.editor.IURIEditorOpener;
|
||||
import org.eclipse.xtext.ui.editor.XtextEditor;
|
||||
import org.eclipse.xtext.ui.editor.model.XtextDocument;
|
||||
import org.eclipse.xtext.ui.editor.utils.EditorUtils;
|
||||
import org.eclipse.xtext.ui.resource.XtextResourceSetProvider;
|
||||
//import org.xtext.example.mydsl.ui.internal.MyDslActivator;
|
||||
import org.eclipse.xtext.util.TextRegion;
|
||||
import org.eclipse.xtext.validation.AbstractDeclarativeValidator;
|
||||
import org.eclipse.xtext.validation.AbstractDeclarativeValidator.StateAccess;
|
||||
import org.eclipse.xtext.validation.ValidationMessageAcceptor;
|
||||
|
||||
import com.google.inject.Injector;
|
||||
|
||||
import fr.irit.fiacre.xtext.fiacre.BlockStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.CaseStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.ConditionalStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.ExtendedConditionalStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.ForeachStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.SelectStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.Statement;
|
||||
import fr.irit.fiacre.xtext.fiacre.StatementChoice;
|
||||
import fr.irit.fiacre.xtext.fiacre.StatementSequence;
|
||||
import fr.irit.fiacre.xtext.fiacre.UnlessStatement;
|
||||
import fr.irit.fiacre.xtext.fiacre.WhileStatement;
|
||||
import fr.irit.fiacre.xtext.ui.internal.FiacreActivator;
|
||||
import fr.irit.fiacre.xtext.validation.FiacreValidator;
|
||||
|
||||
public class Simulate implements IObjectActionDelegate {
|
||||
|
||||
private Shell shell;
|
||||
// added selection attribute
|
||||
private ISelection selection;
|
||||
|
||||
/**
|
||||
* Constructor for Action1.
|
||||
*/
|
||||
public Simulate() {
|
||||
super();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart)
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
shell = targetPart.getSite().getShell();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#run(IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
IFile file = getFile();
|
||||
Injector injector = FiacreActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre");
|
||||
XtextResourceSetProvider provider = injector.getInstance(XtextResourceSetProvider.class);
|
||||
ResourceSet resourceSet = provider.get(file.getProject());
|
||||
|
||||
URI xtextURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
|
||||
|
||||
XtextResource xtextResource = (XtextResource) resourceSet.getResource(xtextURI, true);
|
||||
|
||||
System.out.println("resource" + xtextResource);
|
||||
|
||||
IURIEditorOpener editorOpener = injector.getInstance(IURIEditorOpener.class);
|
||||
final XtextEditor xtextEditor = (XtextEditor) editorOpener.open(xtextURI, true);
|
||||
System.out.println("editor 2" + xtextEditor);
|
||||
XtextDocument xtextDocument = (XtextDocument) xtextEditor.getDocument();
|
||||
System.out.println("document " + xtextDocument);
|
||||
for (int i = 0; i < xtextDocument.getNumberOfLines(); i++) {
|
||||
try {
|
||||
System.out.println("getLineLength " + i + " " + xtextDocument.getLineLength(i));
|
||||
System.out.println("getLineOffset " + i + " " + xtextDocument.getLineOffset(i));
|
||||
} catch (BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
EObjectAtOffsetHelper eObjectAtOffsetHelper = injector.getInstance(EObjectAtOffsetHelper.class);
|
||||
for (int i = 0; i < xtextDocument.getLength(); i++) {
|
||||
try {
|
||||
EObject object = eObjectAtOffsetHelper.resolveElementAt(xtextResource, i);
|
||||
EObject object2 = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i);
|
||||
EObject object3 = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(xtextResource, i);
|
||||
INode object4 = eObjectAtOffsetHelper.getCrossReferenceNode(xtextResource, new TextRegion(i, 1));
|
||||
|
||||
int line = xtextDocument.getLineOfOffset(i);
|
||||
int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)));
|
||||
|
||||
System.out.println("----- ");
|
||||
System.out.print("o " + i);
|
||||
System.out.print(" (l " + line + " ");
|
||||
System.out.print("c " + column + ") ");
|
||||
System.out.print("(el = " + (line + 1) + ", ");
|
||||
System.out.print("ec = " + (column + 1) + ") ");
|
||||
System.out.println("calculated offset " + getOffset(xtextDocument, line , column));
|
||||
System.out.println("object " + object);
|
||||
System.out.println("cross " + object3);
|
||||
System.out.println("contained " + object2);
|
||||
System.out.println("containerStatement " + getStatement(object2));
|
||||
System.out.println("object4 " + object4);
|
||||
|
||||
} catch (BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FiacreValidator validator = injector.getInstance(FiacreValidator.class);
|
||||
System.out.println("validator " + validator);
|
||||
System.out.println("getmsgacceptor " + validator.getMessageAcceptor() + this);
|
||||
|
||||
// StateAccess access = new StateAccess((AbstractDeclarativeValidator) validator.getMessageAcceptor());
|
||||
// validator.getMessageAcceptor().acceptError("Assigning any value not allowed in a function ",eObjectAtOffsetHelper.resolveElementAt(xtextResource, 14773),null,ValidationMessageAcceptor.INSIGNIFICANT_INDEX, null);
|
||||
// validator.state.get().hasErrors = true;
|
||||
// try {
|
||||
// BufferedReader bufferRead = new BufferedReader(new
|
||||
// InputStreamReader(System.in));
|
||||
// String s = bufferRead.readLine();
|
||||
// int x = Integer.parseInt(s);
|
||||
// String r = bufferRead.readLine();
|
||||
// int y = Integer.parseInt(r);
|
||||
//
|
||||
// //EObjectAtOffsetHelper eObjectAtOffsetHelper = new
|
||||
// EObjectAtOffsetHelper();
|
||||
// EObject object3 =
|
||||
// eObjectAtOffsetHelper.resolveElementAt(xtextResource,
|
||||
// getOffset(xtextDocument, x, y));
|
||||
// System.out.println("object3 " + object3);
|
||||
// try {
|
||||
// System.out.println("line of offset " +
|
||||
// xtextDocument.getLineOfOffset(getOffset(xtextDocument, x, y)));
|
||||
// } catch (BadLocationException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
//
|
||||
//
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
}
|
||||
|
||||
// added getFile() method
|
||||
private IFile getFile() {
|
||||
return (IFile) ((IStructuredSelection) selection).getFirstElement();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
// Don't forget this line.
|
||||
// It is the most important line.
|
||||
this.selection = selection;
|
||||
}
|
||||
|
||||
public int getOffset(XtextDocument xtextDocument, int x, int y) {
|
||||
int offset = 0;
|
||||
|
||||
for (int i = 0; i < x; i++) {
|
||||
try {
|
||||
offset += xtextDocument.getLineLength(i);
|
||||
} catch (BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
offset += y;
|
||||
System.out.println("offset" + offset);
|
||||
return offset;
|
||||
|
||||
}
|
||||
|
||||
public EObject eContainer(EObject root, Class<?> type) {
|
||||
EObject current = root;
|
||||
while (current != null) {
|
||||
if (type.isInstance(current)) {
|
||||
return current;
|
||||
} else {
|
||||
current = current.eContainer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EObject eContainerStatement(EObject root) {
|
||||
EObject current = root;
|
||||
while (current != null) {
|
||||
if (StatementSequence.class.isInstance(current.eContainer())) {
|
||||
return current;
|
||||
} else {
|
||||
current = current.eContainer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public EObject getStatement(EObject root) {
|
||||
EObject current = root;
|
||||
while (current != null) {
|
||||
if (!(isAtomicStatement(current.eContainer()))) {
|
||||
return current;
|
||||
} else {
|
||||
current = current.eContainer();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isAtomicStatement(EObject root) {
|
||||
if (eContainer(root, Statement.class) != null) {
|
||||
if (UnlessStatement.class.isInstance(root) || StatementChoice.class.isInstance(root)
|
||||
|| StatementSequence.class.isInstance(root) || ConditionalStatement.class.isInstance(root)
|
||||
|| ExtendedConditionalStatement.class.isInstance(root) || SelectStatement.class.isInstance(root)
|
||||
|| WhileStatement.class.isInstance(root) || ForeachStatement.class.isInstance(root)
|
||||
|| CaseStatement.class.isInstance(root) || BlockStatement.class.isInstance(root)
|
||||
) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,878 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.staticjson.extractor
|
||||
|
||||
import com.google.inject.Injector
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.BlockInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.DeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.EnabledStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ExecutableStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ExecutedStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.FireableStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceEnabledStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceExecutableStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceExecutedStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceFireableStatementBlock
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceModel
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ProcessDeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.VariableDeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.simulator.core.Utils
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.EnterStateStep
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MSC
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SendStep
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.Step
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.SynchronisationStep
|
||||
import fr.irit.fiacre.xtext.fiacre.ArrayExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.ArrayType
|
||||
import fr.irit.fiacre.xtext.fiacre.BasicType
|
||||
import fr.irit.fiacre.xtext.fiacre.BlockStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.CaseStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.ConditionalStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.ConstructionExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.Expression
|
||||
import fr.irit.fiacre.xtext.fiacre.ExtendedConditionalStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.FalseLiteral
|
||||
import fr.irit.fiacre.xtext.fiacre.FieldExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.ForeachStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.IdentifierExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.IdentifierPattern
|
||||
import fr.irit.fiacre.xtext.fiacre.Model
|
||||
import fr.irit.fiacre.xtext.fiacre.NaturalLiteral
|
||||
import fr.irit.fiacre.xtext.fiacre.PortDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.QueueExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.QueueType
|
||||
import fr.irit.fiacre.xtext.fiacre.RangeType
|
||||
import fr.irit.fiacre.xtext.fiacre.ReceiveStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.RecordExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.RecordType
|
||||
import fr.irit.fiacre.xtext.fiacre.ReferencedType
|
||||
import fr.irit.fiacre.xtext.fiacre.SelectStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.SendStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.Statement
|
||||
import fr.irit.fiacre.xtext.fiacre.StatementChoice
|
||||
import fr.irit.fiacre.xtext.fiacre.StatementSequence
|
||||
import fr.irit.fiacre.xtext.fiacre.TransitionSource
|
||||
import fr.irit.fiacre.xtext.fiacre.TrueLiteral
|
||||
import fr.irit.fiacre.xtext.fiacre.Type
|
||||
import fr.irit.fiacre.xtext.fiacre.TypeDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.UnionTagDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.UnionType
|
||||
import fr.irit.fiacre.xtext.fiacre.UnlessStatement
|
||||
import fr.irit.fiacre.xtext.fiacre.ValueExpression
|
||||
import fr.irit.fiacre.xtext.fiacre.VariablesDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.WhileStatement
|
||||
import fr.irit.fiacre.xtext.ui.internal.XtextActivator
|
||||
import fr.laas.libtts.TTSSimulator
|
||||
import java.util.ArrayList
|
||||
import java.util.HashMap
|
||||
import java.util.LinkedHashMap
|
||||
import java.util.Map
|
||||
import org.eclipse.emf.ecore.EObject
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.jface.text.BadLocationException
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.eclipse.xtext.ui.editor.IURIEditorOpener
|
||||
import org.eclipse.xtext.ui.editor.XtextEditor
|
||||
import org.eclipse.xtext.ui.editor.model.XtextDocument
|
||||
import org.json.simple.JSONArray
|
||||
import org.json.simple.JSONAware
|
||||
import org.json.simple.JSONObject
|
||||
|
||||
///Jorge Guiterrez 10/08/2016
|
||||
class DynamicJsonExtractor{
|
||||
var XtextResource fiacreResource
|
||||
var Resource instanceResource
|
||||
var Resource mscResource
|
||||
val TTSSimulator tTSSimulator
|
||||
var HashMap<BlockInstance, JSONAware> mapping_blockinstance_jsonelement
|
||||
var JSONObject fiacreStaticJson
|
||||
val HashMap<String, ArrayList<String>> tr_gl_tr_ins = new HashMap<String, ArrayList<String>>();
|
||||
val HashMap<String, LinkedHashMap<EObject, String>> tr_in_stmts = new HashMap<String, LinkedHashMap<EObject, String>>();
|
||||
|
||||
new(XtextResource _fiacreResource, Resource _instanceResource, TTSSimulator _TTSSimulator, JSONObject _fiacreStaticJson, HashMap<BlockInstance, JSONAware> _mapping, Resource _mscResource) {
|
||||
fiacreResource = _fiacreResource
|
||||
instanceResource = _instanceResource
|
||||
tTSSimulator = _TTSSimulator
|
||||
mapping_blockinstance_jsonelement = _mapping
|
||||
fiacreStaticJson = _fiacreStaticJson
|
||||
mscResource = _mscResource
|
||||
extractTransitionsMappings
|
||||
}
|
||||
def mscFirstStepExtract(){
|
||||
var Step step = Utils.createStep
|
||||
MSCModel.steps.add(step)
|
||||
for (pdi: instanceModel.eAllContents.toList.filter(ProcessDeclarationInstance)){
|
||||
var EnterStateStep esst = Utils.createEnterStateStep
|
||||
step.microSteps.add(esst)
|
||||
esst.stateName = pdi.currentState.name
|
||||
esst.site = MSCModel.sites.filter[site|site.name == pdi.flatname].get(0)
|
||||
}
|
||||
Utils.saveResource(mscResource)
|
||||
}
|
||||
def ArrayList<JSONObject> getallInstanceTransitionsObjects() {
|
||||
// Get all Instance transitions from the mapping between block instances and json object
|
||||
val ArrayList<JSONObject> allInstanceTransitions = new ArrayList<JSONObject>()
|
||||
for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].values.map[value|(value as JSONObject).get("transitions")])) {
|
||||
for (jelement : element as JSONArray) {
|
||||
allInstanceTransitions.add(jelement as JSONObject)
|
||||
}
|
||||
}
|
||||
allInstanceTransitions
|
||||
}
|
||||
|
||||
def extractTransitionsMappings() {
|
||||
val Injector injector = XtextActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre")
|
||||
val IURIEditorOpener editorOpener = injector.getInstance(IURIEditorOpener)
|
||||
val XtextEditor xtextEditor = editorOpener.open(fiacreResource.URI, true) as XtextEditor
|
||||
val XtextDocument xtextDocument = xtextEditor.document as XtextDocument
|
||||
val EObjectAtOffsetHelper eObjectAtOffsetHelper = injector.getInstance(EObjectAtOffsetHelper)
|
||||
// The following code line is just to show what performed inside mappings
|
||||
/*
|
||||
* It exists two kinds of transitions
|
||||
* Global transitions: which can be find in the json model root
|
||||
* and Instance transitions which can be find in the process instances
|
||||
* So from global transitions, we must find the instance transitions
|
||||
* to obtain, after, the locations for each transition
|
||||
*/
|
||||
// Get global transitions from the json model
|
||||
val JSONArray global_transitions = fiacreStaticJson.get("gtransitions") as JSONArray
|
||||
|
||||
// // Get all Instance transitions from the mapping between block instances and json object
|
||||
// val ArrayList<JSONObject> allInstanceTransitions = new ArrayList<JSONObject>()
|
||||
// for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].values.map[value|(value as JSONObject).get("transitions")])) {
|
||||
// for (jelement : element as JSONArray) {
|
||||
// allInstanceTransitions.add(jelement as JSONObject)
|
||||
// }
|
||||
// }
|
||||
// for each global transition name (a_global_tr_name)
|
||||
for (a_global_tr_name : global_transitions.map[agtr|(agtr as JSONObject).get("name")]) {
|
||||
|
||||
// Get the corresponding json object (a_g_tr_jobject) from the global transitions array list
|
||||
val JSONObject a_g_tr_jobject = global_transitions.filter[gtr|(gtr as JSONObject).get("name") == a_global_tr_name].get(0) as JSONObject
|
||||
// create an array list of instance transition of the current global transition
|
||||
val ArrayList<String> in_trs_of_gl = new ArrayList<String>()
|
||||
|
||||
// for each instance transition name, found in the transitions array of the global transition object
|
||||
for (a_i_tr_name : a_g_tr_jobject.get("transitions") as JSONArray) {
|
||||
// add the instance name in the array list
|
||||
in_trs_of_gl.add(a_i_tr_name as String)
|
||||
// Get the instance transition object (a_i_tr_jobject)
|
||||
val JSONObject a_i_tr_jobject = getallInstanceTransitionsObjects.filter[aatr|(aatr as JSONObject).get("name") == a_i_tr_name].get(0)
|
||||
|
||||
// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
|
||||
// just to print it and verify
|
||||
// val c_pdi = mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter[p1, p2|((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)].keySet.get(0);
|
||||
// Get locations of each instance transition
|
||||
// statements_ins_tr allows to save an eobject (an atomic statement or a transition source)
|
||||
// with its first position
|
||||
// for example fr.irit.fiacre.xtext.fiacre.impl.TransitionSourceImpl@53c7c937 = 325 3
|
||||
val LinkedHashMap<EObject, String> statements_ins_tr = new LinkedHashMap<EObject, String>()
|
||||
|
||||
// for each identified location in the locations table of an instance transition
|
||||
for (a_location_jsonobject : (a_i_tr_jobject as JSONObject).get("locations") as JSONArray) {
|
||||
// we find the from location
|
||||
val JSONObject from_location = (a_location_jsonobject as JSONObject).get("from") as JSONObject
|
||||
val long line_from = from_location.get("line") as Long
|
||||
val long char_from = from_location.get("char") as Long
|
||||
// we calculate the from offset
|
||||
val int offset_from = xtextDocument.getOffset(line_from.intValue, char_from.intValue)
|
||||
|
||||
// we find the to location
|
||||
val JSONObject to_location = (a_location_jsonobject as JSONObject).get("to") as JSONObject
|
||||
val long line_to = to_location.get("line") as Long
|
||||
val long char_to = to_location.get("char") as Long
|
||||
// we calculate the to offset
|
||||
val int offset_to = xtextDocument.getOffset(line_to.intValue, char_to.intValue)
|
||||
// from to from offset to the to offset
|
||||
for (var int i = offset_from; i <= offset_to; i++) {
|
||||
// we calculate the line column position from the offset
|
||||
val int line = xtextDocument.getLineOfOffset(i)
|
||||
val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))
|
||||
|
||||
// we find the corresponding statement
|
||||
val statement = eObjectAtOffsetHelper.resolveContainedElementAt(fiacreResource, i).getStatement
|
||||
// We insert the statements in the list with its line column location
|
||||
/*
|
||||
* We insert only transition source (from)
|
||||
* or atomic statement
|
||||
* In addition
|
||||
*/
|
||||
if((statement instanceof TransitionSource)
|
||||
//&& ! statements_ins_tr.keySet.contains(statement)
|
||||
&& statements_ins_tr.keySet.filter(TransitionSource).size == 0
|
||||
)
|
||||
statements_ins_tr.put(statement, (line + 1) + " " + (column + 1))
|
||||
|
||||
if(statement.isAtomicStatement)
|
||||
// TODO à voir l'histoire des to statement et les loop
|
||||
// if(statement instanceof ToStatement){
|
||||
// if(statements_ins_tr.keySet.filter(ToStatement).size == 0)
|
||||
// statements_ins_tr.put(statement, (line + 1) + " " + (column + 1))
|
||||
// }
|
||||
// else
|
||||
// if(! statements_ins_tr.keySet.contains(statement))
|
||||
statements_ins_tr.put(statement, (line + 1) + " " + (column + 1))
|
||||
}
|
||||
}
|
||||
tr_in_stmts.put(a_i_tr_name as String, statements_ins_tr)
|
||||
}
|
||||
// mapping global transition = instance transitions. en gros, c'est gtransitions de json dynamique
|
||||
tr_gl_tr_ins.put(a_global_tr_name as String, in_trs_of_gl)
|
||||
}
|
||||
}
|
||||
|
||||
def extractValues() {
|
||||
val HashMap<JSONObject, DeclarationInstance> variablesMappings = getVariablesMappings
|
||||
for (element : Utils.getJsonObject(tTSSimulator.state.getValues).keySet) {
|
||||
if(variablesMappings.filter[p1, p2|(p1 as JSONObject).get("flatname") == element].size > 0) {
|
||||
val JSONObject jo = variablesMappings.filter[p1, p2|(p1 as JSONObject).get("flatname") == element].keySet.get(0)
|
||||
val DeclarationInstance decl = variablesMappings.filter[p1, p2|(p1 as JSONObject).get("flatname") == element].values.get(0)
|
||||
val Object value = Utils.getJsonObject(tTSSimulator.state.getValues).get(element)
|
||||
val VariableDeclarationInstance vd_i = decl.variableDeclarationInstances.filter[vdi|vdi.variableDeclaration.name == jo.get("sourcename")].get(0)
|
||||
val HashMap<Object, Type> mapping_jsonType_fiacreType = getJSONTypeFiacreTypeMapping(jo.get("vartype"), (vd_i.variableDeclaration.eContainer as VariablesDeclaration).type)
|
||||
val HashMap<Object, Object> mapping_value_type = getValueTypeMapping(value, jo.get("vartype"))
|
||||
vd_i.currentValue = (getFiacreValue(value, mapping_value_type, mapping_jsonType_fiacreType) as ValueExpression)
|
||||
}
|
||||
}
|
||||
}
|
||||
/*
|
||||
* This method allows to obtain a mapping between jsontype (from "vartype" of a json variable)
|
||||
* and the fiacre type of this variable.
|
||||
* It consists to do the optimization on fiacre types, in the ecore side, as done in the json side
|
||||
* It can contain something like this
|
||||
* bool = fr.irit.fiacre.xtext.fiacre.impl.BooleanTypeImpl@19569e44
|
||||
* {"interval":{"high":3,"low":0}} = fr.irit.fiacre.xtext.fiacre.impl.RangeTypeImpl@3138f7b9
|
||||
* {"record":{"val":"bool","active_probes":{"interval":{"high":3,"low":0}}}} = fr.irit.fiacre.xtext.fiacre.impl.RecordTypeImpl@1f72ed22
|
||||
*/
|
||||
def HashMap<Object, Type> getJSONTypeFiacreTypeMapping(Object json_type, Type fiacre_type) {
|
||||
var HashMap<Object, Type> mapping_jsonType_fiacreType = new HashMap<Object, Type>()
|
||||
if(fiacre_type instanceof ReferencedType) {
|
||||
// If it is a referenced type, we get the the type of the referenced type
|
||||
val referenced_fiacre_type = ((fiacre_type as ReferencedType).type as TypeDeclaration).value
|
||||
mapping_jsonType_fiacreType.putAll(getJSONTypeFiacreTypeMapping(json_type, referenced_fiacre_type))
|
||||
} else {
|
||||
if(fiacre_type instanceof BasicType) {
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
} else {
|
||||
if(fiacre_type instanceof RangeType) {
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
} else {
|
||||
if(fiacre_type instanceof QueueType) {
|
||||
// get the element type of the queue type, both in json and ecore
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
val queue_json_element_type = ((json_type as JSONObject).get("queue") as JSONObject).get("elemtype")
|
||||
val queue_fiacre_element_type = (fiacre_type as QueueType).type
|
||||
mapping_jsonType_fiacreType.putAll(getJSONTypeFiacreTypeMapping(queue_json_element_type, queue_fiacre_element_type))
|
||||
} else {
|
||||
if(fiacre_type instanceof ArrayType) {
|
||||
// get the element type of the queue type, both in json and ecore
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
val array_json_element_type = ((json_type as JSONObject).get("array") as JSONObject).get("elemtype")
|
||||
val array_fiacre_element_type = (fiacre_type as ArrayType).type
|
||||
mapping_jsonType_fiacreType.putAll(getJSONTypeFiacreTypeMapping(array_json_element_type, array_fiacre_element_type))
|
||||
} else {
|
||||
if(fiacre_type instanceof UnionType) {
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
// get only typed union tags exemple: type xx is union toto | titi of int end
|
||||
// So we get only titi type which is int
|
||||
for (json_tag : ((json_type as JSONObject).get("union") as JSONObject).entrySet) {
|
||||
if((json_tag.value as JSONArray).size > 0) {
|
||||
val tag_fiacre_type = (fiacre_type as UnionType).tags.filter[fs|fs.tags.map[f|f.name].exists[an|an == json_tag.key]].get(0).type
|
||||
val tag_json_type = (json_tag.value as JSONArray).get(0)
|
||||
mapping_jsonType_fiacreType.putAll(getJSONTypeFiacreTypeMapping(tag_json_type, tag_fiacre_type))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(fiacre_type instanceof RecordType) {
|
||||
mapping_jsonType_fiacreType.put(json_type, fiacre_type)
|
||||
// get all fields types
|
||||
for (json_field : ((json_type as JSONObject).get("record") as JSONObject).entrySet) {
|
||||
val field_json_type = json_field.value
|
||||
val field_fiacre_type = (fiacre_type as RecordType).fields.filter[fs|fs.fields.map[f|f.name].exists[an|an == json_field.key]].get(0).type
|
||||
mapping_jsonType_fiacreType.putAll(getJSONTypeFiacreTypeMapping(field_json_type, field_fiacre_type))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mapping_jsonType_fiacreType
|
||||
}
|
||||
|
||||
def Expression getFiacreValue(Object value, HashMap<Object, Object> mapping_value_type, HashMap<Object, Type> mapping_jsonType_fiacreType) {
|
||||
if(value instanceof Long) {
|
||||
val NaturalLiteral nl = Utils.createNaturalLiteral
|
||||
nl.value = (value as Long).intValue
|
||||
nl
|
||||
} else {
|
||||
if(value instanceof String) {
|
||||
if((value as String) == "false" || (value as String) == "true") {
|
||||
// Fiacre boolean type
|
||||
if((value as String) == "false") {
|
||||
val FalseLiteral fl = Utils.createFalseLiteral
|
||||
fl
|
||||
} else {
|
||||
val TrueLiteral tl = Utils.createTrueLiteral
|
||||
tl
|
||||
}
|
||||
} else {
|
||||
val UnionType union_type = mapping_jsonType_fiacreType.get(mapping_value_type.get(value)) as UnionType
|
||||
// val TypeDeclaration typ_dec = model.declarations.filter(TypeDeclaration).filter[td|td.name == type_name].get(0)
|
||||
val UnionTagDeclaration tag = union_type.tags.map[tgs|tgs.tags].flatten.filter[atag|atag.name == value].get(0)
|
||||
val IdentifierExpression ide = Utils.createIdentifierExpression
|
||||
ide.declaration = tag
|
||||
ide
|
||||
}
|
||||
} else {
|
||||
if(value instanceof JSONArray) {
|
||||
if((mapping_value_type.get(value) as JSONObject).get("array") != null) {
|
||||
val ArrayExpression eae = Utils.createArrayExpression
|
||||
for (element : ( value as JSONArray)) {
|
||||
eae.values.add(getFiacreValue(element, mapping_value_type, mapping_jsonType_fiacreType))
|
||||
}
|
||||
eae
|
||||
} else {
|
||||
if((mapping_value_type.get(value) as JSONObject).get("queue") != null) {
|
||||
val QueueExpression qe = Utils.createQueueExpression
|
||||
for (element : ( value as JSONArray)) {
|
||||
qe.values.add(getFiacreValue(element, mapping_value_type, mapping_jsonType_fiacreType))
|
||||
}
|
||||
qe
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// otherwise JSON Object
|
||||
if((mapping_value_type.get(value) as JSONObject).get("record") != null) {
|
||||
val RecordExpression re = Utils.createRecordExpression
|
||||
// val String type_name = (getFiacreType(mapping_value_type.get(value) as JSONObject) as JSONObject).get("name") as String
|
||||
val RecordType record_type = mapping_jsonType_fiacreType.get(mapping_value_type.get(value)) as RecordType //getFiacreType(mapping_value_type.get(value) as JSONObject) as RecordType
|
||||
// val TypeDeclaration typ_dec = model.declarations.filter(TypeDeclaration).filter[td|td.name == type_name].get(0)
|
||||
for (element : (value as JSONObject).keySet) {
|
||||
val FieldExpression fie = Utils.createFieldExpression
|
||||
re.fields.add(fie)
|
||||
fie.field = record_type.fields.map[fis|fis.fields].flatten.filter[atag|atag.name == element].get(0)
|
||||
fie.value = getFiacreValue((value as JSONObject).get(element), mapping_value_type, mapping_jsonType_fiacreType)
|
||||
}
|
||||
re
|
||||
} else {
|
||||
// an union element with constructor
|
||||
if((mapping_value_type.get(value) as JSONObject).get("union") != null) {
|
||||
val ConstructionExpression cstre = Utils.createConstructionExpression
|
||||
val UnionType union_type = mapping_jsonType_fiacreType.get(mapping_value_type.get(value)) as UnionType // model.declarations.filter(TypeDeclaration).filter[td|td.name == type_name].get(0)
|
||||
val UnionTagDeclaration tag = union_type.tags.map[tgs|tgs.tags].flatten.filter[atag|atag.name == (value as JSONObject).keySet.get(0)].get(0)
|
||||
cstre.declaration = tag
|
||||
cstre.parameters.add(getFiacreValue((value as JSONObject).values.get(0), mapping_value_type, mapping_jsonType_fiacreType))
|
||||
cstre
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// def Type getFiacreType(JSONObject type) {
|
||||
// println("types " + (fiacreStaticJson.get("deftyp") as JSONArray).filter[t|(t as JSONObject).get("tdef").equals(type)])
|
||||
// if((fiacreStaticJson.get("deftyp") as JSONArray).filter[t|(t as JSONObject).get("tdef").equals(type)].size == 1) {
|
||||
// val String type_name = ((fiacreStaticJson.get("deftyp") as JSONArray).filter[t|(t as JSONObject).get("tdef").equals(type)].get(0) as JSONObject).get("name") as String
|
||||
// val TypeDeclaration typ_dec = model.declarations.filter(TypeDeclaration).filter[td|td.name == type_name].get(0)
|
||||
// typ_dec.value
|
||||
// }
|
||||
// }
|
||||
|
||||
def HashMap<Object, Object> getValueTypeMapping(Object value, Object type) {
|
||||
var HashMap<Object, Object> mapping_value_type = new HashMap<Object, Object>()
|
||||
if(value instanceof Long) {
|
||||
mapping_value_type.put(value as Object, type)
|
||||
} else {
|
||||
if(value instanceof String) {
|
||||
mapping_value_type.put(value as Object, type)
|
||||
} else {
|
||||
if(value instanceof JSONArray) {
|
||||
if((type as JSONObject).get("array") != null) {
|
||||
mapping_value_type.put(value, type)
|
||||
val length = (value as JSONArray).size
|
||||
for (var i = 0; i < length; i++) {
|
||||
// mapping_value_type.put((value as JSONArray).get(i), ((type as JSONObject).get("array") as JSONObject).get("elemtype"))
|
||||
mapping_value_type.putAll(getValueTypeMapping((value as JSONArray).get(i), ((type as JSONObject).get("array") as JSONObject).get("elemtype")))
|
||||
}
|
||||
} else {
|
||||
if((type as JSONObject).get("queue") != null) {
|
||||
mapping_value_type.put(value, type)
|
||||
val length = (value as JSONArray).size
|
||||
for (var i = 0; i < length; i++) {
|
||||
// mapping_value_type.put((value as JSONArray).get(i), ((type as JSONObject).get("queue") as JSONObject).get("elemtype"))
|
||||
mapping_value_type.putAll(getValueTypeMapping((value as JSONArray).get(i), ((type as JSONObject).get("queue") as JSONObject).get("elemtype")))
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// It is a JSONObject so It can be record value or union value
|
||||
if((type as JSONObject).get("record") != null) {
|
||||
mapping_value_type.put(value, type)
|
||||
for (ite : (value as JSONObject).keySet) {
|
||||
// mapping_value_type.put((value as JSONObject).get(ite), ((type as JSONObject).get("record") as JSONObject).get(ite))
|
||||
mapping_value_type.putAll(getValueTypeMapping((value as JSONObject).get(ite), ((type as JSONObject).get("record") as JSONObject).get(ite)))
|
||||
}
|
||||
} else {
|
||||
mapping_value_type.put(value, type)
|
||||
// mapping_value_type.put((value as JSONObject).values.get(0), ((type as JSONObject).get("union") as JSONObject).get((value as JSONObject).keySet.get(0)))
|
||||
mapping_value_type.putAll(getValueTypeMapping((value as JSONObject).values.get(0), (((type as JSONObject).get("union") as JSONObject).get((value as JSONObject).keySet.get(0)) as JSONArray).get(0)))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
mapping_value_type
|
||||
}
|
||||
|
||||
// def getType(JSONObject vartype) {
|
||||
// (fiacreStaticJson.get("deftyp") as JSONArray).filter[atype|((atype as JSONObject).get("tdef") as JSONObject).equals(vartype) == true]
|
||||
// }
|
||||
|
||||
def HashMap<JSONObject, DeclarationInstance> getVariablesMappings() {
|
||||
/*
|
||||
* Ce mapping permet d'identifier le couple suivant:
|
||||
* - une variable sous forme d'un object json
|
||||
* - La DeclarationInstance correspondante
|
||||
* Il y a deux sources de redondance à résoudre
|
||||
* D'abord une variable est instancié dans chacune des instances
|
||||
* Ceci est resolu à travers la flatname qui contient le numéro d'instance
|
||||
* Le deuxième niveau de redondance est les paramètres qui portent les mêmes noms
|
||||
* des variables. Ceci est résolu par le fait de vérifier s'il y a une variable instance qui
|
||||
* a le même nom dans la declaration instance
|
||||
*/
|
||||
var HashMap<JSONObject, DeclarationInstance> map_var_job_cdi = new HashMap<JSONObject, DeclarationInstance>()
|
||||
val ArrayList<JSONObject> fiacreVariablesAsJsonObjects = new ArrayList<JSONObject>
|
||||
// Get all json objects of vars from the mappings
|
||||
// TODO why just flatten doesn't work
|
||||
for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].values.map[value|(value as JSONObject).get("vars")])) {
|
||||
for (jelement : element as JSONArray) {
|
||||
fiacreVariablesAsJsonObjects.add(jelement as JSONObject)
|
||||
}
|
||||
}
|
||||
for (json_object_var : fiacreVariablesAsJsonObjects) {
|
||||
var ArrayList<DeclarationInstance> decls = new ArrayList<DeclarationInstance>
|
||||
for (decl : mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].filter[p1, p2|((p2 as JSONObject).get("vars") as JSONArray).contains(json_object_var)].
|
||||
keySet) {
|
||||
decls.add(decl as DeclarationInstance)
|
||||
}
|
||||
if(decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name == json_object_var.get("sourcename")]].size > 0) {
|
||||
map_var_job_cdi.put(json_object_var, decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name == json_object_var.get("sourcename")]].get(0))
|
||||
}
|
||||
}
|
||||
map_var_job_cdi
|
||||
}
|
||||
|
||||
def extractStates() {
|
||||
val ArrayList<JSONObject> allJsonStates = new ArrayList<JSONObject>
|
||||
|
||||
// Get all json variables objects from the mappings
|
||||
// TODO why just flatten doesn't work
|
||||
for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].values.map[value|(value as JSONObject).get("states")])) {
|
||||
for (jelement : element as JSONArray) {
|
||||
allJsonStates.add(jelement as JSONObject)
|
||||
}
|
||||
}
|
||||
//msc
|
||||
|
||||
|
||||
for (place : tTSSimulator.currentPlaces) {
|
||||
// cette condition permet d'éliminer les états qui ne sont pas dans le modèle Fiacre
|
||||
// et qui sont ajoutés par le compilateur
|
||||
if(allJsonStates.filter[a|a.get("flatname") == place].size > 0) {
|
||||
// json_object_state is the concerned json object corresponding
|
||||
// to the "place" name
|
||||
val JSONObject json_object_state = allJsonStates.filter[a|a.get("flatname") == place].get(0)
|
||||
// we find the c_pdi key whose the "states" json array of the corresponding value element
|
||||
// contains the json_object_state
|
||||
val c_pdi = mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter [ p1, p2 |
|
||||
((p2 as JSONObject).get("states") as JSONArray).contains(json_object_state)
|
||||
].keySet.get(0);
|
||||
// c_pdi is the concerned process declaration instance where the state must be updated.
|
||||
// According to the c_pdi and json_object_state, we update the currentState reference of c_pdi
|
||||
(c_pdi as ProcessDeclarationInstance).currentState = (c_pdi as ProcessDeclarationInstance).process.states.filter[state|state.name == json_object_state.get("sourcename")].get(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def extractExecutedStatements(String executed_tr_name) {
|
||||
clearAllExecutedStatements
|
||||
val ExecutedStatementBlock esb = extractExecutedStatementsBlock(executed_tr_name)
|
||||
// frac compiler adds some intermediate transitions
|
||||
// that don't exist in the static json description,
|
||||
// like in mouse_property example (__presentAfter__1_1_t1 transition)
|
||||
// Therefore for this global transition, it doesn't exist instance transitions
|
||||
// and the mapping doesn't exist for this transition
|
||||
// So, using this conditional statement, we eliminate this case
|
||||
if(tr_gl_tr_ins.filter[p1, p2|p1 == executed_tr_name].values.size > 0) {
|
||||
// for each instance transition (instance_tr) of the global transition (tr_name)
|
||||
for (instance_tr : tr_gl_tr_ins.filter[p1, p2|p1 == executed_tr_name].values.get(0)) // add the created instance statement block in the current instanceStatementBlocks
|
||||
{
|
||||
esb.instanceStatementBlocks.add(extractInstanceExecutedStatements(instance_tr))
|
||||
}
|
||||
}
|
||||
//msc
|
||||
//if it is sychronisation
|
||||
if(esb.instanceStatementBlocks.map[isb|isb.statements].flatten.exists[s|s instanceof IdentifierPattern && (s as IdentifierPattern).declaration instanceof PortDeclaration]){
|
||||
var Step step = Utils.createStep
|
||||
MSCModel.steps.add(step)
|
||||
var SynchronisationStep st = Utils.createSynchronisationStep
|
||||
step.microSteps.add(st)
|
||||
for (pdi : esb.instanceStatementBlocks.map[isb|isb.eContainer]){
|
||||
st.sites.add(MSCModel.sites.filter[site|site.name == (pdi as ProcessDeclarationInstance).flatname].get(0))
|
||||
}
|
||||
//
|
||||
var Step step2 = Utils.createStep
|
||||
MSCModel.steps.add(step2)
|
||||
for (pdi : esb.instanceStatementBlocks.map[isb|isb.eContainer]){
|
||||
var EnterStateStep esst = Utils.createEnterStateStep
|
||||
esst.stateName= (pdi as ProcessDeclarationInstance).currentState.name
|
||||
esst.site =MSCModel.sites.filter[site|site.name == (pdi as ProcessDeclarationInstance).flatname].get(0)
|
||||
step2.microSteps.add(esst)
|
||||
}
|
||||
}
|
||||
else{
|
||||
if((esb.instanceStatementBlocks.map[isb|isb.statements].flatten.exists[s|s instanceof SendStatement])){
|
||||
var Step step = Utils.createStep
|
||||
MSCModel.steps.add(step)
|
||||
var SendStep st = Utils.createSendStep
|
||||
step.microSteps.add(st)
|
||||
for (ss : esb.instanceStatementBlocks.map[isb|isb.statements].flatten.filter(SendStatement)){
|
||||
st.senderSites.add(MSCModel.sites.filter[site|site.name == (esb.instanceStatementBlocks.filter[isb|isb.statements.contains(ss)].get(0).eContainer as ProcessDeclarationInstance).flatname].get(0))
|
||||
}
|
||||
for (ss : esb.instanceStatementBlocks.map[isb|isb.statements].flatten.filter(ReceiveStatement)){
|
||||
st.receiverSites.add(MSCModel.sites.filter[site|site.name == (esb.instanceStatementBlocks.filter[isb|isb.statements.contains(ss)].get(0).eContainer as ProcessDeclarationInstance).flatname].get(0))
|
||||
}
|
||||
//
|
||||
var Step step2 = Utils.createStep
|
||||
MSCModel.steps.add(step2)
|
||||
for (pdi : esb.instanceStatementBlocks.map[isb|isb.eContainer]){
|
||||
var EnterStateStep esst = Utils.createEnterStateStep
|
||||
esst.stateName= (pdi as ProcessDeclarationInstance).currentState.name
|
||||
esst.site =MSCModel.sites.filter[site|site.name == (pdi as ProcessDeclarationInstance).flatname].get(0)
|
||||
step2.microSteps.add(esst)
|
||||
}
|
||||
}
|
||||
else{
|
||||
var Step step = Utils.createStep
|
||||
MSCModel.steps.add(step)
|
||||
for (pdi : esb.instanceStatementBlocks.map[isb|isb.eContainer]){
|
||||
var EnterStateStep esst= Utils.createEnterStateStep
|
||||
esst.site = MSCModel.sites.filter[site|site.name == (pdi as ProcessDeclarationInstance).flatname].get(0)
|
||||
esst.stateName = (pdi as ProcessDeclarationInstance).currentState.name
|
||||
step.microSteps.add(esst)
|
||||
}
|
||||
}
|
||||
}
|
||||
Utils.saveResource(mscResource)
|
||||
}
|
||||
|
||||
def extractInstanceExecutedStatements(String instance_tr_name) {
|
||||
// gel the instance transition json object whose the name is equal to instance_tr_name
|
||||
val JSONObject a_i_tr_jobject = getallInstanceTransitionsObjects.filter[aatr|(aatr as JSONObject).get("name") == instance_tr_name].get(0)
|
||||
// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
|
||||
val ProcessDeclarationInstance c_pdi = mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter [ p1, p2 |
|
||||
((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)
|
||||
].keySet.get(0) as ProcessDeclarationInstance;
|
||||
// the following if then else allows to forbid duplicate instance statements blocks
|
||||
// If the process declaration instance contains a block which have the same name
|
||||
if(c_pdi.instanceStatementBlocks.filter(InstanceExecutedStatementBlock).filter[ifst|ifst.name == instance_tr_name].size > 0) {
|
||||
// so, return this found block (this block will not be added again because the list doesn't accept duplicates)
|
||||
c_pdi.instanceStatementBlocks.filter(InstanceExecutedStatementBlock).filter[ifst|ifst.name == instance_tr_name].get(0)
|
||||
} else {
|
||||
// there is no block with this name, so create a new block
|
||||
val InstanceExecutedStatementBlock block = Utils.createInstanceExecutedStatementBlock
|
||||
block.name = instance_tr_name
|
||||
// get the LinkedHashMap that contains the statements of this instance transition
|
||||
for (element : tr_in_stmts.filter[p1, p2|p1 == instance_tr_name].values.get(0).keySet) {
|
||||
// and for each element
|
||||
// add it in the appropriate location
|
||||
if(element instanceof TransitionSource) {
|
||||
block.transitionSource = element
|
||||
} else {
|
||||
block.statements.add(element as Statement)
|
||||
}
|
||||
}
|
||||
c_pdi.instanceStatementBlocks.add(block)
|
||||
block
|
||||
}
|
||||
}
|
||||
|
||||
def clearAllExecutableStatements() {
|
||||
// delete all executable block statements in the instance model
|
||||
instanceModel.statementBlocks.removeAll(instanceModel.statementBlocks.filter(ExecutableStatementBlock))
|
||||
// delete all instance executable block statements in different process declaration instance
|
||||
instanceModel.eAllContents.toList.filter(ProcessDeclarationInstance).forEach[pdi|pdi.instanceStatementBlocks.removeAll(pdi.instanceStatementBlocks.filter(InstanceExecutableStatementBlock))]
|
||||
}
|
||||
|
||||
def clearAllExecutedStatements() {
|
||||
// delete all executable block statements in the instance model
|
||||
instanceModel.statementBlocks.removeAll(instanceModel.statementBlocks.filter(ExecutedStatementBlock))
|
||||
// delete all instance executable block statements in different process declaration instance
|
||||
instanceModel.eAllContents.toList.filter(ProcessDeclarationInstance).forEach[pdi|pdi.instanceStatementBlocks.removeAll(pdi.instanceStatementBlocks.filter(InstanceExecutedStatementBlock))]
|
||||
}
|
||||
|
||||
def ExecutedStatementBlock extractExecutedStatementsBlock(String transition_name) {
|
||||
val ExecutedStatementBlock esb = Utils.createExecutedStatementBlock
|
||||
esb.name = transition_name
|
||||
instanceModel.statementBlocks.add(esb)
|
||||
esb
|
||||
}
|
||||
|
||||
def extractExecutableStatements() {
|
||||
clearAllExecutableStatements
|
||||
// this for statement allows to iterate in a map
|
||||
for (Map.Entry<String, String> entry : tTSSimulator.enabledTransitions.entrySet()) {
|
||||
val String tr_name = entry.getKey()
|
||||
val String tr_interval = entry.getValue()
|
||||
// for each (tr_name, tr_interval), we create an EnabledStatementBlock
|
||||
val EnabledStatementBlock esb = extractEnabledStatements(tr_name, tr_interval)
|
||||
// frac compiler adds some intermediate transitions
|
||||
// that don't exist in the static json description,
|
||||
// like in mouse_property example (__presentAfter__1_1_t1 transition)
|
||||
// Therefore for this global transition, it doesn't exist instance transitions
|
||||
// and the mapping doesn't exist for this transition
|
||||
// So, using this conditional statement, we eliminate this case
|
||||
if(tr_gl_tr_ins.filter[p1, p2|p1 == tr_name].values.size > 0) {
|
||||
// for each instance transition (instance_tr) of the global transition (tr_name)
|
||||
for (instance_tr : tr_gl_tr_ins.filter[p1, p2|p1 == tr_name].values.get(0)) {
|
||||
// add the created instance statement block in the current instanceStatementBlocks
|
||||
esb.instanceStatementBlocks.add(extractInstanceEnabledStatements(instance_tr))
|
||||
}
|
||||
}
|
||||
}
|
||||
// Idem for fireable
|
||||
for (Map.Entry<String, String> entry : tTSSimulator.fireableTransitions.entrySet()) {
|
||||
val String tr_name = entry.getKey()
|
||||
val String tr_interval = entry.getValue()
|
||||
val FireableStatementBlock fsb = extractFireableStatements(tr_name, tr_interval)
|
||||
// frac compiler adds some intermediate transitions
|
||||
// that don't exist in the static json description,
|
||||
// like in mouse_property example (__presentAfter__1_1_t1 transition)
|
||||
// Therefore for this global transition, it doesn't exist instance transitions
|
||||
// and the mapping doesn't exist for this transition
|
||||
// So, using this conditional statement, we eliminate this case
|
||||
if(tr_gl_tr_ins.filter[p1, p2|p1 == tr_name].values.size > 0) {
|
||||
for (instance_tr : tr_gl_tr_ins.filter[p1, p2|p1 == tr_name].values.get(0)) {
|
||||
fsb.instanceStatementBlocks.add(extractInstanceFireableStatements(instance_tr))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def extractInstanceFireableStatements(String instance_tr_name) {
|
||||
// gel the instance transition json object whose the name is equal to instance_tr_name
|
||||
val JSONObject a_i_tr_jobject = getallInstanceTransitionsObjects.filter[aatr|(aatr as JSONObject).get("name") == instance_tr_name].get(0)
|
||||
// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
|
||||
val ProcessDeclarationInstance c_pdi = mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter [ p1, p2 |
|
||||
((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)
|
||||
].keySet.get(0) as ProcessDeclarationInstance;
|
||||
// the following if then else allows to forbid duplicate instance statements blocks
|
||||
// If the process declaration instance contains a block which have the same name
|
||||
if(c_pdi.instanceStatementBlocks.filter(InstanceFireableStatementBlock).filter[ifst|ifst.name == instance_tr_name].size > 0) {
|
||||
// so, return this found block (this block will not be added again because the list doesn't accept duplicates)
|
||||
c_pdi.instanceStatementBlocks.filter(InstanceFireableStatementBlock).filter[ifst|ifst.name == instance_tr_name].get(0)
|
||||
} else {
|
||||
// there is no block with this name, so create a new block
|
||||
val InstanceFireableStatementBlock block = Utils.createInstanceFireableStatementBlock
|
||||
block.name = instance_tr_name
|
||||
// get the LinkedHashMap that contains the statements of this instance transition
|
||||
for (element : tr_in_stmts.filter[p1, p2|p1 == instance_tr_name].values.get(0).keySet) {
|
||||
// and for each element
|
||||
// add it in the appropriate location
|
||||
if(element instanceof TransitionSource) {
|
||||
block.transitionSource = element
|
||||
} else {
|
||||
block.statements.add(element as Statement)
|
||||
}
|
||||
}
|
||||
c_pdi.instanceStatementBlocks.add(block)
|
||||
block
|
||||
}
|
||||
}
|
||||
|
||||
// Idem
|
||||
def extractInstanceEnabledStatements(String instance_tr_name) {
|
||||
// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
|
||||
val JSONObject a_i_tr_jobject = getallInstanceTransitionsObjects.filter[aatr|(aatr as JSONObject).get("name") == instance_tr_name].get(0)
|
||||
val ProcessDeclarationInstance c_pdi = mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter [ p1, p2 |
|
||||
((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)
|
||||
].keySet.get(0) as ProcessDeclarationInstance;
|
||||
if(c_pdi.instanceStatementBlocks.filter(InstanceEnabledStatementBlock).filter[ifst|ifst.name == instance_tr_name].size > 0) {
|
||||
c_pdi.instanceStatementBlocks.filter(InstanceEnabledStatementBlock).filter[ifst|ifst.name == instance_tr_name].get(0)
|
||||
} else {
|
||||
val InstanceEnabledStatementBlock block = Utils.createInstanceEnabledStatementBlock
|
||||
block.name = instance_tr_name
|
||||
for (element : tr_in_stmts.filter[p1, p2|p1 == instance_tr_name].values.get(0).keySet) {
|
||||
if(element instanceof TransitionSource) {
|
||||
block.transitionSource = element
|
||||
} else {
|
||||
block.statements.add(element as Statement)
|
||||
}
|
||||
}
|
||||
c_pdi.instanceStatementBlocks.add(block)
|
||||
block
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
def EnabledStatementBlock extractEnabledStatements(String transition_name, String interval) {
|
||||
val EnabledStatementBlock esb = Utils.createEnabledStatementBlock
|
||||
esb.name = transition_name
|
||||
esb.date = interval
|
||||
instanceModel.statementBlocks.add(esb)
|
||||
esb
|
||||
}
|
||||
|
||||
def FireableStatementBlock extractFireableStatements(String transition_name, String interval) {
|
||||
val FireableStatementBlock fsb = Utils.createFireableStatementBlock
|
||||
fsb.name = transition_name
|
||||
fsb.date = interval
|
||||
instanceModel.statementBlocks.add(fsb)
|
||||
fsb
|
||||
}
|
||||
|
||||
def int getOffset(XtextDocument xtextDocument, int line, int character) {
|
||||
var int offset = character
|
||||
for (var i = 0; i < line; i++) {
|
||||
try {
|
||||
offset += xtextDocument.getLineLength(i)
|
||||
} catch(BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace
|
||||
}
|
||||
}
|
||||
return offset
|
||||
}
|
||||
|
||||
def EObject eContainer(EObject root, Class<?> type) {
|
||||
var EObject current = root
|
||||
while(current != null) {
|
||||
if(type.isInstance(current)) {
|
||||
return current
|
||||
} else {
|
||||
current = current.eContainer
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
// def EObject eContainerStatement(EObject root) {
|
||||
// var EObject current = root
|
||||
// while(current != null) {
|
||||
// if(StatementSequence.isInstance(current.eContainer())) {
|
||||
// return current
|
||||
// } else {
|
||||
// current = current.eContainer
|
||||
// }
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
def EObject getStatement(EObject root) {
|
||||
var EObject current = root
|
||||
while(current != null) {
|
||||
if(!(isAtomicStatement(current.eContainer))) {
|
||||
return current
|
||||
} else {
|
||||
current = current.eContainer
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
def boolean isAtomicStatement(EObject root) {
|
||||
if(eContainer(root, Statement) != null) {
|
||||
if(UnlessStatement.isInstance(root) || StatementChoice.isInstance(root) || StatementSequence.isInstance(root) || ConditionalStatement.isInstance(root) ||
|
||||
ExtendedConditionalStatement.isInstance(root) || SelectStatement.isInstance(root) || WhileStatement.isInstance(root) || ForeachStatement.isInstance(root) ||
|
||||
CaseStatement.isInstance(root) || BlockStatement.isInstance(root)) {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
def InstanceModel getInstanceModel() {
|
||||
return instanceResource.contents.get(0) as InstanceModel
|
||||
}
|
||||
def MSC getMSCModel() {
|
||||
return mscResource.contents.get(0) as MSC
|
||||
}
|
||||
|
||||
def Model getModel() {
|
||||
return fiacreResource.contents.get(0) as Model
|
||||
}
|
||||
|
||||
def saveInstanceResource() {
|
||||
Utils.saveResource(instanceResource)
|
||||
}
|
||||
def saveMscResource() {
|
||||
Utils.saveResource(mscResource)
|
||||
}
|
||||
|
||||
def Resource getInstanceResource() {
|
||||
instanceResource
|
||||
}
|
||||
|
||||
// this method just to print to detect errors
|
||||
def println_elements(XtextResource xtextResource, XtextDocument xtextDocument) {
|
||||
for (var i = 0; i < xtextDocument.getNumberOfLines(); i++) {
|
||||
try {
|
||||
print("Line " + i + " Line length " + xtextDocument.getLineLength(i))
|
||||
println(" Line " + i + " LineOffset " + xtextDocument.getLineOffset(i))
|
||||
} catch(BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < xtextDocument.getLength(); i++) {
|
||||
val Injector injector = XtextActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre")
|
||||
val EObjectAtOffsetHelper eObjectAtOffsetHelper = injector.getInstance(EObjectAtOffsetHelper)
|
||||
try {
|
||||
val EObject object = eObjectAtOffsetHelper.resolveElementAt(xtextResource, i)
|
||||
val EObject object2 = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i)
|
||||
val EObject object3 = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(xtextResource, i)
|
||||
val int line = xtextDocument.getLineOfOffset(i)
|
||||
val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))
|
||||
if(i != xtextDocument.getOffset(line, column)) {
|
||||
println("error")
|
||||
}
|
||||
println("----- ")
|
||||
print("o " + i + " offset " + xtextDocument.getOffset(line, column) + " line of offset " + xtextDocument.getLineOfOffset(i))
|
||||
print(" (l " + line + " ")
|
||||
print("c " + column + ") ")
|
||||
print("(el = " + (line + 1) + ", ")
|
||||
println("ec = " + (column + 1) + ") ")
|
||||
println("object " + object)
|
||||
println("cross " + object3)
|
||||
println("contained " + object2)
|
||||
println("containerStatement " + getStatement(object2))
|
||||
|
||||
} catch(BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
def gettr_gl_tr_ins(){
|
||||
tr_gl_tr_ins
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,209 @@
|
||||
/*******************************************************************************
|
||||
* Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the LGPL 3.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* https://www.gnu.org/licenses/lgpl-3.0-standalone.html
|
||||
*
|
||||
* Contributors:
|
||||
* Faiez Zalila - initial API and implementation and/or initial documentation
|
||||
* Jorge Enrique Gutierrez Zuluaga
|
||||
*******************************************************************************/
|
||||
package com.irtsaintexupery.fiacre.simulator.staticjson.extractor
|
||||
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.BlockInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ComponentDeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.CompositionInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.DeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.InstanceModel
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.ProcessDeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.instance.fiacreinstance.VariableDeclarationInstance
|
||||
import com.irtsaintexupery.fiacre.simulator.core.Utils
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.MSC
|
||||
import com.irtsaintexupery.fiacre.simulator.msc.msc.Site
|
||||
import fr.irit.fiacre.xtext.fiacre.ComponentDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.CompositeBlock
|
||||
import fr.irit.fiacre.xtext.fiacre.Composition
|
||||
import fr.irit.fiacre.xtext.fiacre.InstanceDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.Model
|
||||
import fr.irit.fiacre.xtext.fiacre.ParameterizedDeclaration
|
||||
import fr.irit.fiacre.xtext.fiacre.ProcessDeclaration
|
||||
import java.util.HashMap
|
||||
import org.eclipse.emf.ecore.resource.Resource
|
||||
import org.eclipse.xtext.resource.XtextResource
|
||||
import org.json.simple.JSONArray
|
||||
import org.json.simple.JSONAware
|
||||
import org.json.simple.JSONObject
|
||||
|
||||
class StaticJsonExtractor {
|
||||
var XtextResource fiacreResource
|
||||
var JSONObject fiacreStaticJson
|
||||
var Resource instanceResource
|
||||
var Resource mscResource
|
||||
var HashMap<BlockInstance, JSONAware> mapping
|
||||
// The constructor
|
||||
new(XtextResource _fiacreResource, JSONObject _fiacreStaticJson, Resource _instanceResource, Resource _mscResource) {
|
||||
fiacreResource = _fiacreResource
|
||||
fiacreStaticJson = _fiacreStaticJson
|
||||
instanceResource = _instanceResource
|
||||
mapping = new HashMap<BlockInstance, JSONAware>()
|
||||
mscResource = _mscResource
|
||||
}
|
||||
|
||||
// This method extracts static information from the json model
|
||||
// and creates the fiacre instance model
|
||||
def extract() {
|
||||
extractFiacreModel()
|
||||
if (fiacreStaticJson.get("arch_var") instanceof JSONObject){
|
||||
extractMainDeclaration(fiacreStaticJson.getJSONObject("arch_var"))
|
||||
}
|
||||
else{
|
||||
for (element : fiacreStaticJson.get("arch_var") as JSONArray){
|
||||
extractMainDeclaration(element as JSONObject)
|
||||
}
|
||||
}
|
||||
|
||||
Utils.saveResource(instanceResource)
|
||||
Utils.saveResource(mscResource)
|
||||
}
|
||||
|
||||
def extractFiacreModel() {
|
||||
//instanceModel.name = (fiacreModel.root as Declaration).name + "Instance"
|
||||
instanceModel.model = fiacreModel
|
||||
}
|
||||
|
||||
def extractMainDeclaration(JSONObject jsonob) {
|
||||
val String name = jsonob.getJSONString("name")
|
||||
if(jsonob.component) {
|
||||
val ComponentDeclarationInstance cdi = Utils.createComponentDeclarationInstance
|
||||
instanceModel.instance.add(cdi)
|
||||
val ComponentDeclaration fcr_component = fiacreModel.declarations.filter[decl|decl.name==jsonob.get("name")].get(0) as ComponentDeclaration
|
||||
cdi.component = fcr_component
|
||||
cdi.name = fiacreModel.declarations.filter(ComponentDeclaration).filter[cd|cd.name == name].get(0).name
|
||||
jsonob.extractVariable(fcr_component, cdi)
|
||||
jsonob.getJSONArray("body").extractBody(cdi, fcr_component.body)
|
||||
mapping.put(cdi,jsonob)
|
||||
cdi.flatname = jsonob.getJSONString("flatname")
|
||||
} else {
|
||||
val ProcessDeclarationInstance pdi = Utils.createProcessDeclarationInstance
|
||||
instanceModel.instance.add(pdi)
|
||||
val ProcessDeclaration fcr_process = fiacreModel.declarations.filter[decl|decl.name==jsonob.get("name")].get(0) as ProcessDeclaration
|
||||
pdi.process = fcr_process
|
||||
pdi.name = fiacreModel.declarations.filter(ProcessDeclaration).filter[cd|cd.name == name].get(0).name
|
||||
jsonob.extractVariable(fcr_process, pdi)
|
||||
mapping.put(pdi,jsonob)
|
||||
pdi.flatname = jsonob.getJSONString("flatname")
|
||||
//msc part
|
||||
val Site site = Utils.createSite
|
||||
site.name = jsonob.getJSONString("flatname")
|
||||
MSCModel.sites.add(site)
|
||||
}
|
||||
}
|
||||
|
||||
def void extractBody(JSONArray json_composition, BlockInstance instance, Composition fiacre_composition) {
|
||||
for (element : json_composition) {
|
||||
if(element instanceof JSONArray) {
|
||||
// It is a composition
|
||||
val CompositionInstance ci = Utils.createCompositionInstance
|
||||
instance.blockInstances.add(ci)
|
||||
ci.composition = ((fiacre_composition.blocks.get(json_composition.indexOf(element))) as CompositeBlock).composition
|
||||
element.extractBody(ci, ((((fiacre_composition.blocks.get(json_composition.indexOf(element))) as CompositeBlock).composition)))
|
||||
} else {
|
||||
if((element as JSONObject).component) {
|
||||
// It is a component instance
|
||||
val String name = (element as JSONObject).getJSONString("name")
|
||||
val ComponentDeclarationInstance cdi = Utils.createComponentDeclarationInstance
|
||||
instance.blockInstances.add(cdi)
|
||||
cdi.instance = (((fiacre_composition.blocks.get(json_composition.indexOf(element))) as InstanceDeclaration).instance)
|
||||
(element as JSONObject).getJSONArray("body").extractBody(cdi,
|
||||
((((fiacre_composition.blocks.get(json_composition.indexOf(element))) as InstanceDeclaration).instance.component) as ComponentDeclaration).body)
|
||||
cdi.component = fiacreModel.declarations.filter(ComponentDeclaration).filter [ cd |
|
||||
cd.name == name
|
||||
].get(0)
|
||||
cdi.name = (fiacreModel.declarations.filter(ComponentDeclaration).filter [ cd |
|
||||
cd.name == name
|
||||
].get(0).name)
|
||||
(element as JSONObject).extractVariable(fiacreModel.declarations.filter(ComponentDeclaration).filter[cd|cd.name == name].get(0), cdi)
|
||||
mapping.put(cdi,element as JSONObject)
|
||||
cdi.flatname = (element as JSONObject).getJSONString("flatname")
|
||||
} else {
|
||||
// It is a process instance
|
||||
val String name = (element as JSONObject).getJSONString("name")
|
||||
val ProcessDeclarationInstance pdi = Utils.createProcessDeclarationInstance
|
||||
pdi.instance = ((fiacre_composition.blocks.get(json_composition.indexOf(element))) as InstanceDeclaration).instance
|
||||
instance.blockInstances.add(pdi)
|
||||
pdi.process = fiacreModel.declarations.filter(ProcessDeclaration).filter [ cd |
|
||||
cd.name == name
|
||||
].get(0)
|
||||
pdi.name = (fiacreModel.declarations.filter(ProcessDeclaration).filter [ cd |
|
||||
cd.name == name
|
||||
].get(0).name)
|
||||
(element as JSONObject).extractVariable(fiacreModel.declarations.filter(ProcessDeclaration).filter[cd|cd.name == name].get(0), pdi)
|
||||
mapping.put(pdi,element as JSONObject)
|
||||
pdi.flatname = (element as JSONObject).getJSONString("flatname")
|
||||
//msc part
|
||||
val Site site = Utils.createSite
|
||||
site.name = (element as JSONObject).getJSONString("flatname")
|
||||
MSCModel.sites.add(site)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def boolean isComponent(JSONObject jsonob) {
|
||||
if(jsonob.containsKey("body"))
|
||||
return true
|
||||
else
|
||||
return false
|
||||
}
|
||||
|
||||
def extractVariable(JSONObject jsonob, ParameterizedDeclaration comp_decl, DeclarationInstance cdi) {
|
||||
for (jvar : jsonob.getJSONArray("vars")) {
|
||||
val String var_name = (jvar as JSONObject).getJSONString("sourcename")
|
||||
|
||||
if(var_name.isVariableDeclaration(comp_decl)) {
|
||||
val VariableDeclarationInstance vi = Utils.createVariableDeclarationInstance
|
||||
cdi.variableDeclarationInstances.add(vi)
|
||||
vi.variableDeclaration = comp_decl.variables.map[vars|vars.variables].flatten.filter [ avar |
|
||||
avar.name == (jvar as JSONObject).getJSONString("sourcename")
|
||||
].get(0)
|
||||
}
|
||||
// else
|
||||
// vi.referenceDeclaration = comp_decl.parameters.map[vars|vars.parameters].flatten.filter[avar |avar.name == (jvar as JSONObject).getJSONString("sourcename")] .get(0)
|
||||
}
|
||||
}
|
||||
|
||||
def boolean isVariableDeclaration(String name, ParameterizedDeclaration declaration) {
|
||||
if(declaration.variables.map[vars|vars.variables].flatten.map[avar|avar.name].filter [ aname |
|
||||
aname == name
|
||||
].size > 0)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
}
|
||||
|
||||
def getJSONObject(JSONObject jsonOb, String key) {
|
||||
jsonOb.get(key) as JSONObject
|
||||
}
|
||||
|
||||
def getJSONString(JSONObject jsonOb, String key) {
|
||||
jsonOb.get(key) as String
|
||||
}
|
||||
|
||||
def getJSONArray(JSONObject jsonOb, String key) {
|
||||
jsonOb.get(key) as JSONArray
|
||||
}
|
||||
|
||||
def Model getFiacreModel() {
|
||||
return fiacreResource.contents.get(0) as Model
|
||||
}
|
||||
def MSC getMSCModel() {
|
||||
return mscResource.contents.get(0) as MSC
|
||||
}
|
||||
def InstanceModel getInstanceModel() {
|
||||
return instanceResource.contents.get(0) as InstanceModel
|
||||
}
|
||||
def HashMap<BlockInstance, JSONAware> getMapping(){
|
||||
return mapping
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
def HashMap<String, HashMap<JSONObject, DeclarationInstance>> getVariablesMappings() {
|
||||
var HashMap<String, HashMap<JSONObject, DeclarationInstance>> map_var_job_cdi = new HashMap<String, HashMap<JSONObject, DeclarationInstance>>()
|
||||
val ArrayList<JSONObject> fiacreVariablesAsJsonObjects = new ArrayList<JSONObject>
|
||||
// Get all json objects of vars from the mappings
|
||||
// TODO why just flatten doesn't work
|
||||
for (element : ( mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].values.map[value|(value as JSONObject).get("vars")])) {
|
||||
for (jelement : element as JSONArray) {
|
||||
fiacreVariablesAsJsonObjects.add(jelement as JSONObject)
|
||||
}
|
||||
}
|
||||
println("allJsonVariableValues "+fiacreVariablesAsJsonObjects)
|
||||
// for each value element generated in the dynamic json
|
||||
// for example "Process_1_vx" = 5
|
||||
for (element : fiacreVariablesAsJsonObjects.map[jvv|jvv.get("flatname")].toSet) {
|
||||
|
||||
// this if allows to eliminate added variables by frac like Main_w1
|
||||
if(fiacreVariablesAsJsonObjects.filter[a|a.get("flatname") == element].size > 0) {
|
||||
|
||||
// json_object_var is the concerned json object corresponding to the a fiacre variable
|
||||
// It may be possible that there is many json_object_var that have the same name
|
||||
// like the fp variable in the clock2.fcr
|
||||
for (json_object_var : fiacreVariablesAsJsonObjects.filter[a|a.get("flatname") == element]) {
|
||||
var ArrayList<DeclarationInstance> decls = new ArrayList<DeclarationInstance>
|
||||
for (decl : mapping_blockinstance_jsonelement.filter[p1, p2|p1 instanceof DeclarationInstance].filter [ p1, p2 |
|
||||
((p2 as JSONObject).get("vars") as JSONArray).contains(json_object_var)].keySet)
|
||||
{
|
||||
decls.add(decl as DeclarationInstance)
|
||||
}
|
||||
if (decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]].size>0){
|
||||
var HashMap<JSONObject, DeclarationInstance> map = new HashMap<JSONObject, DeclarationInstance>()
|
||||
println("declaration instances "+decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]])
|
||||
map.put(json_object_var,decls.filter[decl|decl.variableDeclarationInstances.map[vdi|vdi.variableDeclaration].exists[v|v.name==json_object_var.get("sourcename")]].get(0))
|
||||
map_var_job_cdi.put(element as String, map)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
map_var_job_cdi
|
||||
}
|
||||
|
||||
def extractdoc(XtextResource xtextResource) {
|
||||
|
||||
val Injector injector = FiacreActivator.getInstance().getInjector("fr.irit.fiacre.xtext.Fiacre")
|
||||
|
||||
System.out.println("resource" + xtextResource);
|
||||
|
||||
val IURIEditorOpener editorOpener = injector.getInstance(IURIEditorOpener)
|
||||
val XtextEditor xtextEditor = editorOpener.open(xtextResource.URI, true) as XtextEditor
|
||||
println("editor 2" + xtextEditor)
|
||||
val XtextDocument xtextDocument = xtextEditor.document as XtextDocument
|
||||
// System.out.println("document " + xtextDocument);
|
||||
// for (var i = 0; i < xtextDocument.getNumberOfLines(); i++) {
|
||||
// try {
|
||||
// println("getLineLength " + i + " " + xtextDocument.getLineLength(i))
|
||||
// println("getLineOffset " + i + " " + xtextDocument.getLineOffset(i))
|
||||
// } catch(BadLocationException e) {
|
||||
// // TODO Auto-generated catch block
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
val EObjectAtOffsetHelper eObjectAtOffsetHelper = injector.getInstance(EObjectAtOffsetHelper)
|
||||
for (var i = 0; i < xtextDocument.getLength(); i++) {
|
||||
try {
|
||||
val EObject object = eObjectAtOffsetHelper.resolveElementAt(xtextResource, i)
|
||||
val EObject object2 = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i)
|
||||
val EObject object3 = eObjectAtOffsetHelper.resolveCrossReferencedElementAt(xtextResource, i)
|
||||
val int line = xtextDocument.getLineOfOffset(i)
|
||||
val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))
|
||||
|
||||
println("----- ")
|
||||
print("o " + i + " offset " + xtextDocument.getOffset(line, column))
|
||||
print(" (l " + line + " ")
|
||||
print("c " + column + ") ")
|
||||
print("(el = " + (line + 1) + ", ")
|
||||
println("ec = " + (column + 1) + ") ")
|
||||
println("object " + object)
|
||||
println("cross " + object3)
|
||||
println("contained " + object2)
|
||||
println("containerStatement " + getStatement(object2))
|
||||
|
||||
} catch(BadLocationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* It exists two kinds of transitions
|
||||
* Global transitions: which can be find in the json model root
|
||||
* and Instance transitions which can be find in the process instances
|
||||
* So from global transitions, we must find the instance transitions
|
||||
* to obtain, after, the locations for each transition
|
||||
*/
|
||||
// Get global transitions from the json model
|
||||
val JSONArray global_transitions = fiacreStaticJson.get("gtransitions") as JSONArray
|
||||
|
||||
// Get all Instance transitions from the mapping
|
||||
val ArrayList<JSONObject> allInstanceTransitions = new ArrayList<JSONObject>()
|
||||
for (element : ( mapping.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].values.map[value|(value as JSONObject).get("transitions")])) {
|
||||
for (jelement : element as JSONArray) {
|
||||
allInstanceTransitions.add(jelement as JSONObject)
|
||||
}
|
||||
}
|
||||
// for each global transition name (a_global_tr_name)
|
||||
for (a_global_tr_name : global_transitions.map[agtr|(agtr as JSONObject).get("name")]) {
|
||||
|
||||
// Get the corresponding json object (a_g_tr_jobject) from the global transitions array list
|
||||
val JSONObject a_g_tr_jobject = global_transitions.filter[gtr|(gtr as JSONObject).get("name") == a_global_tr_name].get(0) as JSONObject
|
||||
println(a_global_tr_name + " " + a_g_tr_jobject)
|
||||
|
||||
// for each instance transition name find in the transitions array of the global transition object
|
||||
for (a_i_tr_name : a_g_tr_jobject.get("transitions") as JSONArray) {
|
||||
|
||||
// Get the instance transition object (a_i_tr_jobject)
|
||||
val JSONObject a_i_tr_jobject = allInstanceTransitions.filter[aatr|(aatr as JSONObject).get("name") == a_i_tr_name].get(0)
|
||||
|
||||
// Get the Process Declaration Instance that contains the instance transition object (a_i_tr_jobject)
|
||||
val c_pdi = mapping.filter[p1, p2|p1 instanceof ProcessDeclarationInstance].filter[p1, p2|((p2 as JSONObject).get("transitions") as JSONArray).contains(a_i_tr_jobject)].keySet.get(0);
|
||||
println("process instance " + c_pdi)
|
||||
println("tr in process " + a_i_tr_jobject)
|
||||
|
||||
// Get locations of each instance transition
|
||||
println("locations " + (a_i_tr_jobject as JSONObject).get("locations"))
|
||||
//
|
||||
for (a_location_jsonobject : (a_i_tr_jobject as JSONObject).get("locations") as JSONArray) {
|
||||
val JSONObject from_location = (a_location_jsonobject as JSONObject).get("from") as JSONObject
|
||||
val long line_from = from_location.get("line") as Long
|
||||
val long char_from = from_location.get("char") as Long
|
||||
val int offset_from = xtextDocument.getOffset(line_from.intValue, char_from.intValue)
|
||||
|
||||
println(line_from + " " + char_from + " " + offset_from)
|
||||
val JSONObject to_location = (a_location_jsonobject as JSONObject).get("to") as JSONObject
|
||||
val long line_to = to_location.get("line") as Long
|
||||
val long char_to = to_location.get("char") as Long
|
||||
val int offset_to = xtextDocument.getOffset(line_to.intValue, char_to.intValue)
|
||||
println(line_to + " " + char_to + " " + offset_to)
|
||||
for (var int i = offset_from; i <= offset_to; i++) {
|
||||
val int line = xtextDocument.getLineOfOffset(i)
|
||||
val int column = (i - xtextDocument.getLineOffset(xtextDocument.getLineOfOffset(i)))
|
||||
|
||||
val statement = eObjectAtOffsetHelper.resolveContainedElementAt(xtextResource, i).getStatement
|
||||
if(statement instanceof TransitionSource || statement.isAtomicStatement)
|
||||
println("(" + line + ", " + column + ") " + "(" + (line + 1) + ", " + (column + 1) + ") " + statement)
|
||||
}
|
||||
}
|
||||
println(" ")
|
||||
}
|
||||
println("---")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/.DynamicJsonExtractor.java._trace
|
||||
/.StaticJsonExtractor.java._trace
|
||||
/.*.xtendbin
|
||||
/DynamicJsonExtractor.java
|
||||
/StaticJsonExtractor.java
|
||||