Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[contribs] Add examples related to the tutorials.
close #671 Signed-off-by: Stéphane Galland <galland@arakhne.org>
- Loading branch information
1 parent
9ed7a6f
commit 3d620d7
Showing
16 changed files
with
641 additions
and
1 deletion.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
contribs/io.sarl.examples/io.sarl.examples.plugin/ADD_EXAMPLE.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
# How to add an example | ||
|
||
Let the example having the following identifiers: | ||
* `io-sarl-demos-myexample` | ||
* `io_sarl_demos_myexample` | ||
* `io.sarl.examples.myexample` | ||
|
||
|
||
## 1. Include the example code | ||
|
||
1. Create the folder `projects/io-sarl-demos-myexample`. | ||
2. Copy the example's code into the created folder. | ||
|
||
|
||
## 2. Create the wizard for importing the example | ||
|
||
Add in the `plugin.xml` file: | ||
|
||
|
||
<!-- ========= io-sarl-demos-myexample Example ========= --> | ||
|
||
<extension point="org.eclipse.ui.newWizards"> | ||
<wizard id="io.sarl.examples.myexample" | ||
name="%io_sarl_demos_myexample_Name" | ||
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard" | ||
category="org.eclipse.ui.Examples/io.sarl.Examples" | ||
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif" | ||
project="true"> | ||
<description>%io_sarl_demos_myexample_Description</description> | ||
</wizard> | ||
</extension> | ||
|
||
<extension point="org.eclipse.ui.newWizards"> | ||
<wizard id="io.sarl.examples.myexample" | ||
name="%io_sarl_demos_myexample_Name" | ||
class="org.eclipse.emf.common.ui.wizard.ExampleInstallerWizard" | ||
category="io.sarl.eclipse.category.wizards/io.sarl.project.Examples" | ||
icon="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif" | ||
project="true"> | ||
<description>%io_sarl_demos_myexample_Description</description> | ||
</wizard> | ||
</extension> | ||
|
||
<extension point="org.eclipse.emf.common.ui.examples"> | ||
<example wizardID="io.sarl.examples.myexample" pageImage="platform:/plugin/org.eclipse.xtend.examples/icons/genproject.gif"> | ||
<projectDescriptor name="io-sarl-demos-basic-myexample" contentURI="contents/io-sarl-demos-myexample.zip" description="%io_sarl_demos_myexample_Description"/> | ||
<fileToOpen location="io-sarl-demos-myexample/path/to/the/file/to/open"/> | ||
</example> | ||
</extension> | ||
|
||
|
||
Replace `path/to/the/file/to/open` by the path to the file to be opened after importing the example. | ||
|
||
|
||
## 3. Update the localized strings. | ||
|
||
The update explained in the previous section uses two strings in the localized properties. | ||
Add in the `OSGI-INF/bundle.properties` file: | ||
|
||
|
||
io_sarl_demos_myexample_Name = THE NAME OF THE EXAMPLE | ||
io_sarl_demos_myexample_Description = THE DESCRIPTION OF THE EXAMPLE | ||
|
||
|
||
|
||
## 4. Add a quick link in the welcome pages. | ||
|
||
In order to add a quick link to the example, you should add into the `plugin.xml` file: | ||
|
||
|
||
<!-- adding a new quicklink for the example --> | ||
<extension | ||
point="org.eclipse.ui.intro.quicklinks"> | ||
<command | ||
id="org.eclipse.ui.newWizard(newWizardId=io.sarl.examples.myexample)" | ||
description="%io_sarl_demos_myexample__Description" | ||
label="%io_sarl_demos_myexample__Name" | ||
icon="platform:/plugin/org.eclipse.ui.intro.universal/themes/circles/graphics/icons/ctool/sa_onesample48.gif"> | ||
</command> | ||
</extension> | ||
|
||
|
||
|
||
## 5. Add the example into the welcome page | ||
|
||
Add into the `SARL-Example-Intro.xml` file: | ||
|
||
|
||
<group style-id="quick-links" id="quick-links"> | ||
<link style-id="content-link" label="Description of the example in the welcome page" | ||
url="http://org.eclipse.ui.intro/execute?command=org.eclipse.ui.newWizard%28newWizardId%3Dio.sarl.examples.myexample%29" | ||
id="io.sarl.examples.myexample"> | ||
<text> | ||
Detailed description of the example. | ||
</text> | ||
</link> | ||
</group> | ||
|
||
|
||
|
||
## 6. Update the building script | ||
|
||
Add into the `build.xml` file: | ||
|
||
|
||
<zip_example name="io-sarl-demos-myexample" /> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...rl-tutorials-holonicauction/src/main/sarl/io/sarl/examples/holonicauction/auctioneer.sarl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package io.sarl.examples.holonicauction | ||
|
||
import io.sarl.core.Initialize | ||
import io.sarl.core.InnerContextAccess | ||
import io.sarl.lang.core.Address | ||
import io.sarl.core.Lifecycle | ||
import io.sarl.core.Schedules | ||
import io.sarl.core.Behaviors | ||
import io.sarl.core.Logging | ||
|
||
agent Auctioneer { | ||
|
||
uses Behaviors, InnerContextAccess, Lifecycle, Schedules, Logging | ||
|
||
var maxBid = 0f | ||
var winner : Address | ||
var hasBid = false | ||
var isAuctionOpened = true | ||
|
||
on Initialize { | ||
info("Creating bidders") | ||
for(i : 1..3) { | ||
spawnInContext(typeof(Bidder), innerContext) | ||
} | ||
|
||
info("Propose initial price: 50") | ||
wake(new Price(50)) | ||
|
||
in(10000) [ | ||
val waitTask = task("wait-task") | ||
waitTask.every(10000) [ | ||
synchronized(this) { | ||
if (!isAuctionOpened) { | ||
info("No more action: waiting for bidder death.") | ||
if (!hasMemberAgent) { | ||
waitTask.cancel | ||
killMe | ||
} | ||
} else { | ||
if (!hasBid) { | ||
info("NO MORE BID") | ||
isAuctionOpened = false | ||
if (winner === null) { | ||
info("No winner") | ||
} else { | ||
info("The winner is " + winner | ||
+ " with the bid of " + maxBid) | ||
} | ||
info("Killing the bidders") | ||
wake(new StopAuction) | ||
} | ||
else { | ||
var newPrice : float | ||
if (winner === null) { | ||
newPrice = 50 | ||
} else { | ||
newPrice = maxBid | ||
} | ||
info("NEXT BIDDING TURN: " + newPrice) | ||
wake(new Price(newPrice)) | ||
} | ||
hasBid = false | ||
} | ||
} | ||
] | ||
] | ||
} | ||
|
||
on Bid [ isAuctionOpened ] { | ||
info("Receiving bid: " + occurrence.value) | ||
synchronized(this) { | ||
hasBid = true | ||
if (occurrence.value > maxBid) { | ||
info(" better bid") | ||
maxBid = occurrence.value | ||
winner = occurrence.source | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.