Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EDT:Code snippets"

m
 
(113 intermediate revisions by 5 users not shown)
Line 1: Line 1:
Real code for real people. [[#Share_a_code_snippet|Share your code snippets]] with others! <br>
+
* [[EDT:Declaring data|Declaring values of EGL native types]]  
  
== Rich UI  ==
+
* [[EDT:Working with custom types|Working with custom types]]
  
== Services  ==
+
* [[EDT:Writing statements|Writing statements]]
  
== Database access  ==
+
* [[EDT:Working with a database|Working with a database]]
  
==== Record definition  ====
+
* [[EDT:Accessing a service|Accessing a service]]
  
<source lang="java">
+
* [[EDT:Writing a Rich UI application|Writing a Rich UI application]]
record CUSTOMER type Entity{@table{name = "CUSTOMER"}}
+
    NAME string
+
    COUNTRY string{@id};
+
    STATE string?;
+
    CUSTID string;
+
end
+
</source>
+
  
==== Get a record  ====
+
<br><br>
  
<source lang="java">
+
To share a code snippet:
function getCust{id String in} returns (Customer)
+
    ds SQLDataSource?{@resource {}};
+
    aCust Customer;
+
    get aCust from ds using(id);
+
    return (aCust);
+
end
+
</source>
+
  
==== Add a record ====
+
*On the page of interest, click '''Edit''' and, if necessary, log in to eclipse.org.
 +
*Add a section or update an existing one; but always include your code in the following wikitext markup:<br>
 +
<pre>        &lt;source lang="java"&gt;
 +
          // put code here
 +
        &lt;/source&gt;
 +
   
 +
</pre>
 +
*The &lt;source&gt; tag is used instead of &lt;code&gt; or &lt;pre&gt; since it provides syntax highlighting similar to an advanced source code editor. We use the Java language highlighting, since a highlighter for EGL doesn't exist (yet). If you are interested in writing a syntax highlighter for EGL, the GeSHi (Generic Syntax Highlighter) extension is used.
 +
* For longer examples, consider adding line numbers using line="GESHI_NORMAL_LINE_NUMBERS" in the source tag, though for some reason then the snippet doesn't appear in a colored background.
 +
*To add most of your content, click Wikitext or disable the Rich Editor.
 +
*Before you create a new page, read [[EDT:How to Create/Edit Wiki pages|these instructions]].
  
<source lang="java">
+
For help with editing, see [http://meta.wikimedia.org/wiki/Help:Wikitext_examples Wikitext examples]. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  
function addCust{customer Customer in}
+
    ds SQLDataSource?{@resource {}};
+
    add customer to ds;
+
end
+
</source>
+
  
==== Loop through a SQL result set  ====
+
[[Category:EDT]]
 
+
<source lang="java">
+
function loopCust()
+
    ds SQLDataSource?{@resource{bindingkey = "MyDB"}};
+
    rs SQLResultSet?;
+
 
+
    open rs from ds with #sql{
+
SELECT * FROM CUSTOMER
+
    };
+
 
+
    myCust Customer;
+
 
+
    //Loop through results and write out customer name
+
    while(rs.setNext())
+
        get myCust from rs;
+
        Syslib.writeStdOut (Customer name: " + myCust.name);
+
    end
+
 
+
end
+
</source>
+
 
+
<br>
+
 
+
== Share a code snippet  ==
+
 
+
Login to eclipse.org and edit this page. Use the Wikitext to add a new snippet. Use the '''source lang="java"''' tag will provide a background for your snippet and provide some syntax highlighting.
+

Latest revision as of 15:15, 6 March 2012



To share a code snippet:

  • On the page of interest, click Edit and, if necessary, log in to eclipse.org.
  • Add a section or update an existing one; but always include your code in the following wikitext markup:
        <source lang="java">
          // put code here 
        </source>
 
  • The <source> tag is used instead of <code> or <pre> since it provides syntax highlighting similar to an advanced source code editor. We use the Java language highlighting, since a highlighter for EGL doesn't exist (yet). If you are interested in writing a syntax highlighter for EGL, the GeSHi (Generic Syntax Highlighter) extension is used.
  • For longer examples, consider adding line numbers using line="GESHI_NORMAL_LINE_NUMBERS" in the source tag, though for some reason then the snippet doesn't appear in a colored background.
  • To add most of your content, click Wikitext or disable the Rich Editor.
  • Before you create a new page, read these instructions.

For help with editing, see Wikitext examples.       

Back to the top