Geschreibsel Tagged: java http://www.fsteeg.com/tags/java Wed, 07 Sep 2011 00:00:01 +0000 Wed, 07 Sep 2011 00:00:01 +0000 Cloudio: SWT-based tag cloud visualization for Zest <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2011/09/07/cloudio-swt-based-tag-cloud-visualization-for-zest/">https://fsteeg.wordpress.com/2011/09/07/cloudio-swt-based-tag-cloud-visualization-for-zest/</a></small></p> <p/> Thanks to a <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=349969">contribution</a> by <a href="https://twitter.com/#!/sschwieb">Stephan Schwiebert</a>, the Eclipse GEF <a href="http://www.eclipse.org/gef/zest/">Zest</a> toolkit now contains an SWT-based tag cloud visualization component. Using SWT widgets and JFace viewers, you can create tag clouds like this one: <p/> <img class="alignnone" title="cloud-img-shot.png" src="http://dl.dropbox.com/u/7546431/cloud-img-shot.png" alt="" /> <p/> The tag clouds are highly customizable. To demonstrate the possibilities, Cloudio contains a sample RCP application. It can load a text file, provides access to the visualization parameters, and supports image export: <p/> <img class="alignnone" title="cloud-app.png" src="http://dl.dropbox.com/u/7546431/cloud-app.png" alt="" /> <p/> Cloudio is part of the <a href="http://git.eclipse.org/c/gef/org.eclipse.zest.git">Zest Git repository</a>. Its help content (like the other Zest documentation) is generated from the Eclipse <a href="http://wiki.eclipse.org/Zest/Cloudio">wiki</a>. Builds and p2 repos are available from the <a href="https://hudson.eclipse.org/hudson/job/gef-zest-nightly/">nightly</a> and <a href="https://hudson.eclipse.org/hudson/job/gef-zest-integration/">integration</a> CI jobs. Integration builds can also be installed from the <a href="http://marketplace.eclipse.org/content/zest">marketplace</a>. You can get in touch in the <a href="http://www.eclipse.org/forums/eclipse.tools.gef">GEF forum</a> and report bugs on <a href="https://bugs.eclipse.org/bugs/enter_bug.cgi?product=GEF&amp;component=Zest">Bugzilla</a>. http://www.fsteeg.com/notes/cloudio-swt-based-tag-cloud-visualization-for-zesthttp://www.fsteeg.com/notes/cloudio-swt-based-tag-cloud-visualization-for-zest Wed, 07 Sep 2011 00:00:01 +0000 eclipsejavaprogrammingzest Run MWE2 workflows for Xtext 2.0 in a Tycho build <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2011/07/15/run-mwe2-workflows-for-xtext-2-0-in-a-tycho-build/">https://fsteeg.wordpress.com/2011/07/15/run-mwe2-workflows-for-xtext-2-0-in-a-tycho-build/</a></small></p> <p/> I've been doing some work on the Zest build to make the MWE workflow (which generates a bunch of files from an <a href="http://www.eclipse.org/Xtext/">Xtext</a> grammar) part of the <a href="http://www.eclipse.org/tycho/">Tycho</a> build. I guess I just couldn't stand committing tons of changes after some very small tweaks to the grammar I did earlier today. <p/> To hook the workflow into the Tycho build, I was basically able to use the info in the very good and detailed <a href="http://kthoms.wordpress.com/2010/08/18/building-xtext-projects-with-maven-tycho/">tutorial by Karsten Thoms</a>. To make it work for our specific project setup and for the latest Xtext version I still had to tweak some minor things, so I thought I'll do a quick writeup of what I have actually done to make it work. This assumes you already have an Xtext project and you're already building with Tycho in general. If not, check out the tutorial mentioned above. <p/> To add the MWE workflow to the Tycho build, all I had to do was add a plugin repository in the <a href="http://git.eclipse.org/c/gef/org.eclipse.zest.git/tree/pom.xml">parent pom</a>: <pre><code>&lt;pluginRepositories&gt; &lt;pluginRepository&gt; &lt;id&gt;fornax-snapshots&lt;/id&gt; &lt;url&gt;http://www.fornax-platform.org/archiva/repository/snapshots/&lt;/url&gt; &lt;snapshots&gt;&lt;enabled&gt;true&lt;/enabled&gt;&lt;/snapshots&gt; &lt;/pluginRepository&gt; &lt;/pluginRepositories&gt;</code></pre> <p/> Add a plugin pointing to the MWE workflow file in the Xtext <a href="http://git.eclipse.org/c/gef/org.eclipse.zest.git/tree/org.eclipse.zest.dot.core/pom.xml">grammar project pom</a>: <pre><code>&lt;build&gt; &lt;plugins&gt; &lt;plugin&gt; &lt;groupId&gt;org.fornax.toolsupport&lt;/groupId&gt; &lt;artifactId&gt;fornax-oaw-m2-plugin&lt;/artifactId&gt; &lt;version&gt;3.3.0-SNAPSHOT&lt;/version&gt; &lt;configuration&gt; &lt;workflowEngine&gt;mwe2&lt;/workflowEngine&gt; &lt;workflowDescriptor&gt;src/parser/GenerateLang.mwe2&lt;/workflowDescriptor&gt; &lt;/configuration&gt; &lt;executions&gt; &lt;execution&gt; &lt;phase&gt;generate-sources&lt;/phase&gt; &lt;goals&gt;&lt;goal&gt;run-workflow&lt;/goal&gt;&lt;/goals&gt; &lt;/execution&gt; &lt;/executions&gt; &lt;/plugin&gt; &lt;/plugins&gt; &lt;/build&gt;</code></pre> <p/> And define the Xtext grammar project source folder as a resource directory: <pre><code>&lt;build&gt; &lt;resources&gt; &lt;resource&gt;&lt;directory&gt;src&lt;/directory&gt;&lt;/resource&gt; &lt;/resources&gt; &lt;/build&gt;</code></pre> <p/> When running <em>mvn clean install</em>, the MWE workflow now runs as part of the grammar project build. http://www.fsteeg.com/notes/run-mwe2-workflows-for-xtext-20-in-a-tycho-buildhttp://www.fsteeg.com/notes/run-mwe2-workflows-for-xtext-20-in-a-tycho-build Fri, 15 Jul 2011 00:00:01 +0000 dsleclipsejavaprogramming Setting up Contracts for Java in Eclipse <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/">https://fsteeg.wordpress.com/2011/02/07/setting-up-contracts-for-java-in-eclipse/</a></small></p> <p/> On Friday, <a href="http://code.google.com/p/cofoja/">Contracts for Java</a> was announced on the <a href="http://google-opensource.blogspot.com/2011/02/contracts-for-java.html">Google Open Source Blog</a>. Learning about this at the beginning of the weekend was perfect timing for me: I had time to check it out, and while setting it up was some work, <a href="http://twitter.com/#!/fsteeg/status/33977183697371136">I was hooked right away</a>. <p/> Now something like Contracts for Java is only really useful if it is well integrated into the tools you use everyday - which in my case is Eclipse. Eclipse allows many levels of integration, and I quickly had it working by running <em>javac</em> as an <a href="http://help.eclipse.org/helios/index.jsp?topic=/org.eclipse.platform.doc.user/gettingStarted/qs-97_standalone_ets.htm">external tool</a> - which is OK, but not ideal, since it requires running the tool manually after every change to the annotations, and doesn't give in-place error messages. I quickly found out Eclipse has support for custom <a href="http://www.eclipse.org/jdt/apt/main.html">annotation processing</a>. I had to fiddle a little until I got that configured properly with Contracts for Java so I thought I do a quick write-up so other people can try this cool new tool in Eclipse. <p/> Contracts for Java doesn't provide any binary downloads yet, so my first step was to build a Jar. To use it, create a Java project, and add <a href="http://dl.dropbox.com/u/7546431/cofoja-current.jar">cofoja-latest.jar</a> and <a href="http://dl.dropbox.com/u/7546431/asm-all-3.3.1.jar">asm-all-3.3.1.jar</a> to the build path. Then add some code that uses contract annotations (copy and paste the code below into the src folder of the project): <pre><code>import com.google.java.contract.Ensures; import com.google.java.contract.Requires; <p/> public class Contracts { public static void main(String[] args) { System.out.println(new Numbers().add(-10, 5)); } } <p/> class Numbers { @Requires({ &quot;c &gt; 0&quot;, &quot;b &gt; 0&quot; }) @Ensures({ &quot;result &gt; a&quot;, &quot;result &gt; b&quot; }) int add(int a, int b) { return a - b; } }</code></pre> <p/> Next, configure the annotation processing in the project properties &gt; <em>Java Compiler</em> &gt; <em>Annotation Processing</em>. To make Contracts for Java work with the Eclipse Java compiler, currently some specific properties have to be set up: set the <em>com.google.java.contract.classpath</em> property to the location of your cofoja-latest.jar and the <em>com.google.java.contract.classoutput</em> property to the location of your project's <em>src</em> or separate <em>bin</em> folder (both relative to the project root, using the %PROJECT.DIR% variable): <p><a href="http://fsteeg.com/images/cofoja-setup-options.png"><img class="size-full aligncenter" title="cofoja-setup-options" src="http://fsteeg.com/images/cofoja-setup-options.png" alt="" /></a></p> If your project uses multiple Jars they currently have to be given with absolute paths as the <em>com.google.java.contract.classpath</em> value, separated with ':' on Unix or ';' on Windows. Next, make sure you have set up your workspace to refresh automatically in <em>Preferences</em> &gt; <em>General</em> &gt; <em>Workspace</em> to make Eclipse see the resources generated by the annotation processor. Then, add the cofoja-latest.jar to the project properties &gt; <em>Java Compiler</em> &gt; <em>Annotation Processing</em> &gt; <em>Factory Path</em>: <p><a href="http://fsteeg.com/images/cofoja-setup-2.png"><img class="size-full aligncenter" title="cofoja-setup-2" src="http://fsteeg.com/images/cofoja-setup-2.png" alt="" /></a></p> Now issues in the annotation values are reported in the editor, like variables that cannot be found, e.g. for our code above: <p><a href="http://fsteeg.com/images/cofoja-setup-31.png"><img class="size-full aligncenter" title="cofoja-setup-3" src="http://fsteeg.com/images/cofoja-setup-31.png" alt="" /></a></p> To have the contracts checked at runtime, add <em>-javaagent:cofoja-current.jar</em> to the VM arguments of your run configuration: <p><a href="http://fsteeg.com/images/cofoja-setup-41.png"><img class="size-full aligncenter" title="cofoja-setup-4" src="http://fsteeg.com/images/cofoja-setup-41.png" alt="" /></a></p> Now when running, we are made aware of the violated precondition in our code: <p><a href="http://fsteeg.com/images/cofoja-setup-51.png"><img class="size-full aligncenter" title="cofoja-setup-5" src="http://fsteeg.com/images/cofoja-setup-51.png" alt="" /></a></p> After we fix the call violating the precondition to <em>new Numbers().add(10, 5);</em> we now see our implementation of <em>add</em> does not fulfill the postcondition: <p><a href="http://fsteeg.com/images/cofoja-setup-6.png"><img class="size-full aligncenter" title="cofoja-setup-6" src="http://fsteeg.com/images/cofoja-setup-6.png" alt="" /></a></p> After fixing our implementation to <em>return a + b;</em> the code now runs without errors. For further information on using Contracts for Java check out the <a href="http://code.google.com/p/cofoja/w/list">project wiki</a>. General information on design by contract can be found <a href="http://en.wikipedia.org/wiki/Design_by_contract#Bibliography">elsewhere</a>. http://www.fsteeg.com/notes/setting-up-contracts-for-java-in-eclipsehttp://www.fsteeg.com/notes/setting-up-contracts-for-java-in-eclipse Mon, 07 Feb 2011 00:00:01 +0000 eclipsejavaprogramming Scala, object persistence, and the original NoSQL: XML <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2010/08/30/scala-object-persistence-and-the-original-nosql-xml/">https://fsteeg.wordpress.com/2010/08/30/scala-object-persistence-and-the-original-nosql-xml/</a></small></p> <p/> In our <a href="http://fsteeg.wordpress.com/2010/04/18/an-eclipse-rcp-digitization-wiki-with-e4-and-scala/">digitization wiki</a> <a href="http://github.com/spinfo/drc">project</a> based on <a href="http://www.eclipse.org/eclipse4/">Eclipse 4</a> and <a href="http://www.scala-lang.org/">Scala</a> it was time to find a persistence solution. As a quick overview of what it's about, our app will basically allow a user to edit a digitized book page, showing the original scan as an image, with the selected word highlighted. It currently looks like this: <p/> <a href="http://fsteeg.com/images/drc-b1-m4.png"><img class="alignnone size-full" title="drc-b1-m4" src="http://fsteeg.com/images/drc-b1-m4.png" alt="A digitization wiki using Scala and Eclipse 4" /></a> <p/> For the initial prototype implementation, we used XML files in zips to store the page content, combined with <a href="https://truezip.dev.java.net/">TrueZIP</a>, a library which allows access to files in zips the way it should be: like files in a folder. So we could basically create and use the zip entries like this: <pre><code>val zipEntry = new File(&quot;PPN345572629_0004.zip/0001.xml&quot;)</code></pre> <p/> The XML is created using <a href="http://www.codecommit.com/blog/scala/working-with-scalas-xml-support">Scala's XML support</a>, e.g. the top class in our domain model (Page) is serialized by specifying the root element and calling <em>toXml</em> on each containing element (the words), like this: <pre><code>def toXml:Elem = &lt;page&gt; { words.map(_.toXml) } &lt;/page&gt;</code></pre> <p/> The XML is deserialized with the reverse action, by passing the deserialized word elements contained in the root element to the Page factory method: <pre><code>def fromXml(page:Elem) = Page( for(word &lt;- (page \ &quot;word&quot;)) yield Word.fromXml(word) )</code></pre> <p/> So that was basically our prototypical persistence mechanism. Of course, to actually collaboratively correct our digitized texts, we needed a central DB instance on some server. Or maybe not exactly: having <a href="http://chaosradio.ccc.de/cre125.html">heard good things about CouchDB</a> (in german), it was the first option I looked into. The distributed nature of CouchDB sounded very interesting and seemed appropriate for our project - not for performance reasons, but to provide offline or decentralized editing as an option. <p/> So I looked into <a href="http://couchdb.apache.org/">CouchDB</a> with <a href="http://github.com/debasishg/scouchdb">scouchdb</a>, a Scala API to access it (<a href="http://twitter.com/fsteeg/statuses/20551941141">and a very welcoming project</a>). After input from my colleague, I became aware that we'd lose quite a bit of installation ease if we pick a non-Java DB, so CouchDB was not really a client side option for offline storage, and therefore the strongest reason for us to consider it no longer there. <p/> Next I considered an embedded relational Java DB with some ORM or ORM-like access. A JPA solution like EclipseLink or Hibernate seemed overkill and not ideal for Scala. Instead I took a closer look at <a href="http://github.com/szeiger/scala-query">ScalaQuery</a>, which uses Scala's <em>for expressions</em> for DB queries, which seems like the thing you want if you happen to use a language that basically has a query language built-in. <p/> For instance, in ScalaQuery, we could write a query to get all pairs of pages and words where the page contains the word and the original form of the word is <em>Bonifaci</em> like this: <pre><code>val bonifaci = for (page &lt;- Pages; word &lt;- Words; if page.id === word.pageId &amp;&amp; word.original === &quot;Bonifaci&quot;) yield (page, word)</code></pre> <p/> To allow this kind of queries, we need to define tables named <em>Pages</em> and <em>Words</em>. Defining the tables with ScalaQuery is quite elegant, e.g. our main table for pages could be defined like this: <pre><code>object Pages extends Table[(String, java.sql.Blob)](&quot;pages&quot;) { def id = column[String](&quot;id&quot;, O PrimaryKey) def image = column[java.sql.Blob](&quot;image&quot;) def * = id ~ image }</code></pre> <p/> However, this leads to either a duplication of our domain objects (have a table object as above and the original class) or a complete rewrite (use table objects like above as the domain objects), which both seemed wrong. <p/> Also, thinking about alternatives to our XML representation, I came to realize that we would want some form of XML export anyway to ensure long-term access to our data, which is in the public domain and a cultural asset. Of course it would be possible to implement this as some form of export, but if possible it would be just perfect if we could use a single persistence mechanism. <p/> I did remember there are some XML DBs around, but initially abandoned that idea since XML is only half of what we store (the other thing being the images used to correct the text, see screenshot above). But after being unhappy with these other solutions, I took a closer look at <a href="http://exist.sourceforge.net/">eXist-db</a>, an XML DB licensed under the LGPL which by default runs on <a href="http://eclipse.org/jetty/">Jetty</a>. <p/> And I learned that eXist actually supports both XML and binary data, which was just what we needed. With eXist, we also get XQuery support and various interfaces to the data. In our case, this is less of an immediate concern, given Scala's XML support and <em>for expressions</em> are a bit like built-in XQuery capabilities. For instance, a query on XML that is equivalent to the ScalaQuery from above could look like this: <pre><code>val bonifaci = for (page &lt;- xml\&quot;page&quot;; word &lt;- page\&quot;word&quot;; if (word\&quot;@original&quot;).text == &quot;Bonifaci&quot;) yield (page, word)</code></pre> <p/> This is not only about as concise as the query above, but also allows to express the hierarchical nature of our data in the query ('each word in the page'), instead of having to map the relational representation ('all words with a certain page ID'). <p/> As we already deserialize the XML to page objects, what we actually do is query on these. For switching the serialization from entries in a zip file to the eXist DB and allow these queries, the only conceptual change was to store the XML and image files in the DB instead of using a File object, which allowed a really smooth transition. <p/> And with Scala's rich semantics and XML support, our DB wrapper in Scala can be very <a href="http://lamp.epfl.ch/~odersky/blogs/isscalacomplex.html">simple</a> and precise about what it offers in its API, namely XML documents for a collection ID (if found in the DB): <pre><code>val xmls:Option[List[Elem]] = Db.xml(collection)</code></pre> <p/> Or binary data: <pre><code>val imgs:Option[List[Array[Byte]]] = Db.bin(collection)</code></pre> <p/> The elements provided by the DB in this way can be passed to the original deserialization method of Page: <pre><code>val pages:List[Page] = for(page &lt;- Db.xml(collection)) yield Page.fromXml(page)</code></pre> <p/> Given this, we can now use a plain Scala <em>for expression</em> on the deserialized objects to query our data like this: <pre><code>val bonifaci = for (page &lt;- pages; word &lt;- page.words; if word.original == &quot;Bonifaci&quot;) yield (page, word)</code></pre> <p/> At this point we have replaced the file storage with the DB, but are still creating the XML manually, using Scala's XML literals. To avoid any duplication (each class parameter or field is represented again in the serialization logic), and basically eliminate all direct XML manipulation, we could use an XML binding library like <a href="http://scalaxb.org/">scalaxb</a>, <a href="https://jaxb.dev.java.net/">JAXB-RI</a> or <a href="http://eclipse.org/eclipselink/moxy.php">MOXy</a>. <p/> On the other hand, the type safety of the Scala XML serialization code makes the duplication feel much less dangerous than traditional, string-based XML serialization (which can break easily unnoticed by the compiler). And being about as concise as some JAXB annotations and marshalling code would be, the disadvantages seem almost entirely theoretical, but we'll see - swapping the serialization logic should be as easy as swapping the storage implementation was. http://www.fsteeg.com/notes/scala-object-persistence-and-the-original-nosql-xmlhttp://www.fsteeg.com/notes/scala-object-persistence-and-the-original-nosql-xml Mon, 30 Aug 2010 00:00:01 +0000 programmingeclipsejavaxmlscala An Eclipse RCP digitization wiki with e4 and Scala <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2010/04/18/an-eclipse-rcp-digitization-wiki-with-e4-and-scala/">https://fsteeg.wordpress.com/2010/04/18/an-eclipse-rcp-digitization-wiki-with-e4-and-scala/</a></small></p> <p/> We have reached the first milestone of a new project I have been working on since November. The goal of the <a href="http://www.spinfo.phil-fak.uni-koeln.de/forschung-drc.html">project</a> (which is funded by the <a href="http://en.wikipedia.org/wiki/Deutsche_Forschungsgemeinschaft">DFG</a>) is to create a wiki for collaboratively improving the digitization of the <em>Romansch Chrestomathy</em>, a collection of <a href="http://en.wikipedia.org/wiki/Romansh_language">Romansch</a> texts. <p/> I think the domain of this project is very interesting, as it not only aims at improving access to cultural assets, but also takes the community wiki approach, which leads to a situation that is probably not the most common case in academic software development: users are part of the plan. <p/> But perhaps even more, I'm excited about the technical parts of the project, as we use both <a href="http://www.scala-lang.org/">Scala</a> for the core, non-UI components and <a href="http://wiki.eclipse.org/E4">e4</a> for the UI. <p/> Our first milestone for the initial beta (which we plan to release in summer) provides a basic local, single-user implementation of our system. It features basic search and page selection, editing and persistence, word-based edit history and highlighting of the currently selected word in the original scan. <p/> <a href="http://fsteeg.com/images/screenshot-drc-b1-m1.png"><img class="alignnone size-full" title="screenshot-drc-b1-m1" src="http://fsteeg.com/images/screenshot-drc-b1-m1.png" alt="Screenshot" /></a> <p/> As expected, combining two cutting edge technologies (Scala 2.8 and e4) does cause some inconveniences (e.g. I currently can't develop the Scala and the e4 code in the same Eclipse instance, as the Scala IDE for Eclipse does not yet support Helios and e4 won't run on Galileo). <p/> But once I had a proper Ant build system in place (compile Scala sources, deploy as Jars into the e4 workspace, etc.), I was amazed about the concise code base we were able to build both for the backend and the UI with this approach. <p/> To give some examples of what I liked about developing using Scala and e4 I've picked out a few lines from both sides of the current (not very large) code base. <p/> On the Scala side, I really liked having features like <a href="http://www.codecommit.com/blog/scala/case-classes-are-cool">case classes</a>, <a href="http://www.scala-lang.org/node/131">XML support</a>, and <a href="http://www.codecommit.com/blog/scala/quick-explanation-of-scalas-syntax">concise anonymous functions</a>. <p/> For instance, the XML serialization method of a <code>Page</code> defines that the full structure of the XML is to be filled with the XML representation of each <code>Word</code> of the <code>Page</code>: <pre><code>def toXml = &lt;page&gt; { words.toList.map(_.toXml) } &lt;/page&gt;</code></pre> <p/> We also needed a method to get a simple text representation of the <code>Page</code>, made only of the most recent form of each <code>Word</code>: <pre><code>def toText = (&quot;&quot; /: words) (_ + &quot; &quot; + _.history.top.form)</code></pre> <p/> And to implement a simple full text search for collecting pages in which the edit history of a <code>Word</code> contains the given term, I checked each <code>Page</code> like this: <pre><code>page.words.exists(_.history.exists(_.form contains term))</code></pre> <p/> On the e4 side, the whole development experience feels much more lightweight and modern than developing with Eclipse 3 thanks to e4 features like the <del datetime="2010-07-22T17:24:48+00:00"><a href="http://wiki.eclipse.org/E4/UI/Toolkit_Model">Toolkit</a></del> <a href="http://wiki.eclipse.org/E4/UI/Modeled_UI">Workbench Model</a>, <a href="http://wiki.eclipse.org/E4/Contexts">dependency injection</a> and <a href="http://wiki.eclipse.org/E4/CSS/SWT_Mapping">CSS styling</a>. <p/> For instance, the view at the bottom of the application (showing the original scan) needs to listen to the selection of the <code>Page</code> in the top view (showing pages matching the search term). To listen to the selection of pages, the view defines a method with the following signature: <pre><code>@Inject public void setSelection(@Optional @Named(SELECTION) Page page)</code></pre> <p/> At the same time, the bottom view also needs to react to the selection of a word in the central edit view, in order to highlight the particular section in the page. Again, we define that we want to get called if a word is selected somewhere (which is represented by a <code>Text</code> widget here): <pre><code>@Inject public void setSelection(@Optional @Named(SELECTION) Text word)</code></pre> <p/> And I think it's really awesome to be able to specify font style and size (and even gradients) for the <code>Text</code> widgets used in the edit view with CSS: <pre><code>Text { font: Times 14px; background-color: #e8e8e8 #cccccc 60%; }</code></pre> <p/> With the information on how the views are put together in the TM and the CSS file containing the styling information, the remaining UI code feels much lighter than before: there are basically just a few view classes and handlers, communicating loosely via DI and the TM. <p/> So for me, combining Scala and e4 is a great new way to write a Java desktop app! And hopefully more... Our plans for the beta include multi-user support and web deployment with <a href="http://wiki.eclipse.org/RAP">RAP</a> - some challenges for sure, but with the great start I had into e4 development, I'm very confident it will work out! <p/> We have been working on this in public from the start (after all, it's publicly funded), so you can take a closer look at the code or check out this very early state of the application <a href="http://www.github.com/fsteeg/drc">on GitHub</a>.We have reached the first milestone of a new project I have been working on since November: an Eclipse RCP wiki application (implemented using e4 and Scala) to collaboratively improve the digitization of the Romansch Chrestomathy, a collection of Romansch texts. [...] http://www.fsteeg.com/notes/an-eclipse-rcp-digitization-wiki-with-e4-and-scalahttp://www.fsteeg.com/notes/an-eclipse-rcp-digitization-wiki-with-e4-and-scala Sun, 18 Apr 2010 00:00:01 +0000 eclipsejavaprogrammingscala The Eclipse Notebook <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2009/03/19/the-eclipse-notebook/">https://fsteeg.wordpress.com/2009/03/19/the-eclipse-notebook/</a></small></p> <p/> The Eclipse Notebook is an Eclipse editor to manage your notes. All notes are stored in a single XML file in your workspace, making it easily manageable with version control etc. For authoring, it supports embedded Graphviz/Dot (needs to be installed separately) and Wikitext. The Eclipse Notebook allows you to view, filter and edit your notes in two ways (each in a different tab of the editor): As an HTML preview (which can be saved) and as a form editor. In both modes, the notes can be filtered for flexible search criteria (like all notes tagged as x or all notes from 2003, etc). The filtered notes can be exported as an HTML page or as a new Notebook file.<p></p><p><img border="1" src="http://fsteeg.com/files/notes.png" /></p><p><i>Installation</i>: The Eclipse Notebook can be installed from the update site at <i><a href="http://quui.com/updates">http://quui.com/updates</a></i> (requires Eclipse 3.4, aka Ganymede). Use the wizard to create a new empty Notebook after installation. Note that this is an early release, and out of the box will only work on Linux systems. On other platforms, you currently need to add "-Dfile.encoding=UTF-8" to your eclipse.ini file. It also has some other rough edges, e.g. no Undo in the Edit tab, so you have been warned.</p> http://www.fsteeg.com/notes/the-eclipse-notebookhttp://www.fsteeg.com/notes/the-eclipse-notebook Thu, 19 Mar 2009 00:00:01 +0000 eclipsejava Eclipse Features <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2009/03/19/eclipse-features/">https://fsteeg.wordpress.com/2009/03/19/eclipse-features/</a></small></p> <p/> I've added two Eclipse Features to the update site: my <a href="http://wp.me/pwKJk-27">Notebook editor</a> and the very experimental Eclipse version of the qLog logging visualizer (<a href="http://quui.com">info</a>). I've also updated some of the old Eclipse Features on the update site, as well as the update site itself: to reflect the experimental status of the features provided there, I've changed the version numbers to a leading zero. So in case you have already installed some of the features, you should uninstall them first (and probably delete the contents of the cache folders in eclipse/p2). The update site can be found at: <em><a href="http://quui.com/updates">http://quui.com/updates</a></em>. http://www.fsteeg.com/notes/eclipse-featureshttp://www.fsteeg.com/notes/eclipse-features Thu, 19 Mar 2009 00:00:01 +0000 eclipsejava Coding Alaaf! <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2009/03/19/coding-alaaf/">https://fsteeg.wordpress.com/2009/03/19/coding-alaaf/</a></small></p> <p/> I have been using the leisure of <a href="http://en.wikipedia.org/wiki/Cologne_carnival">the fifth season</a> to play a bit with some side projects.<p></p><p>In <a href="http://splink.org/?p=10">qLog</a> for Eclipse, I've improved the scrolling behaviour (with <a href="http://stackoverflow.com/questions/570818">some help</a>) and tweaked <a href="http://www.quui.com/">our</a> Log4j appender a bit. You can install or update the plug-in using our update site at <a href="http://www.quui.com/updates">http://www.quui.com/updates</a>. If you are running on a non-Linux system, you will have to install <a href="https://developer.mozilla.org/en/XULRunner">XulRunner</a> to make this work. To use the plug-in with Log4j, simply add a <a href="http://fsteeg.com/files/ql4e/Log4jAppender.java">de.quui.qlog.Log4jAppender</a> to your Log4j logger. Check out <a href="http://fsteeg.com/files/ql4e/AppenderTest.java">this test</a>, which will log the messages you can see on the screenshot below.</p><p><img border="1" src="http://fsteeg.com/files/ql4e/ql4e.png" /></p><p>For <a href="http://hollala.sourceforge.net/">Hollala</a>, I've made WordNet optional, fixed some bugs and, most importantly, set up a proper Ant build system (to build, test, javadoc, jar and zip it). I've also added a download link to the latest version on the <a href="http://hollala.sourceforge.net/">project page</a>.</p> http://www.fsteeg.com/notes/coding-alaafhttp://www.fsteeg.com/notes/coding-alaaf Thu, 19 Mar 2009 00:00:01 +0000 eclipsejava Encapsulation, JAXB, and JavaBeans This was not obvious to me: When designing a class to be serialized using JAXB (and getting exceptions about missing getters, setters or no-args constructors), do we need to follow the JavaBeans anti-pattern (the 'anti' is my conclusion from reading Effective Java, 2nd ed., p. 12) and [http://www.javaworld.com/javaworld/jw-09-2003/jw-0905-toolbox.html kiss encapsulation goodbye]? No, you can use a private no-args constructor and let JAXB access private fields directly by annotating the class with: ''@XmlAccessorType(value = XmlAccessType.FIELD)''. No getters, setters, or public fields required. http://www.fsteeg.com/notes/encapsulation-jaxb-and-javabeanshttp://www.fsteeg.com/notes/encapsulation-jaxb-and-javabeans Tue, 06 Jan 2009 00:00:01 +0000 javaprogrammming My five steps to programmer's heaven in seven years <a href="http://fsteeg.com/images/2008-12-17_programming-java-lisp-prolog-ruby-scala_My-five-steps-to-programmers-heaven-in-seven-years.dot" title="Graphviz DOT diagram source (also embedded in HTML source)"> <img src="http://fsteeg.com/images/2008-12-17_programming-java-lisp-prolog-ruby-scala_My-five-steps-to-programmers-heaven-in-seven-years.svg" alt="Graphviz DOT diagram source (also embedded in HTML source)" /> </a> <!-- <pre><code>/* Generate image with: dot -Tsvg 2008-12-17_programming-java-lisp-prolog-ruby-scala_My-five-steps-to-programmers-heaven-in-seven-years.dot -o 2008-12-17_programming-java-lisp-prolog-ruby-scala_My-five-steps-to-programmers-heaven-in-seven-years.svg */ digraph{node[shape=box] rankdir=LR center=true concentrate=true //subgraph cluster_0{Java Scala} //subgraph cluster_1{Lisp Prolog Ruby} Java->Scala[constraint=false dir=back] Java -> Lisp; Lisp->Prolog; Prolog->Ruby; Ruby->Scala; Scala->Java[style=dotted arrowhead=none] } </code></pre> --> http://www.fsteeg.com/notes/my-five-steps-to-programmers-heaven-in-seven-yearshttp://www.fsteeg.com/notes/my-five-steps-to-programmers-heaven-in-seven-years Wed, 17 Dec 2008 00:00:01 +0000 programmingjavalispprologrubyscala Trees with Generics and Visitors <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2007/12/31/trees-with-generics-and-visitors/">https://fsteeg.wordpress.com/2007/12/31/trees-with-generics-and-visitors/</a></small></p> <p/> Using <a href="http://en.wikipedia.org/wiki/Java_generics">generics</a> and the <a href="http://en.wikipedia.org/wiki/Visitor_pattern">visitor pattern</a>, it is actually possible to define a generic tree for different objects <span style="font-style:italic;">and</span> different operations on the tree, I have learned from the very interesting book <span style="font-style:italic;"><a href="http://www.oreilly.com/catalog/javagenerics/">Java Generics and Collections</a></span>. This seems quite useful to me. I have added an implementation for general trees based on the binary tree implementation in that book to the <a href="http://en.literateprograms.org/Generic_tree_%28Java%29">Literate Programs</a> wiki. Now what gets me thinking is that I have read someone (think it was <a href="http://www.3plus4.de/">sma</a>) writing the visitor pattern is superfluous. Could that be meant as in 'for certain languages, where visiting can be done very naturally'? Then this would still all make sense for Java. http://www.fsteeg.com/notes/trees-with-generics-and-visitorshttp://www.fsteeg.com/notes/trees-with-generics-and-visitors Mon, 31 Dec 2007 00:00:01 +0000 javaprogramming It all rocks! The release of Leopard caused a little journey of thoughts around Java and Eclipse on the Mac for me, and I come to two pleasant conclusions: Leopard rocks, and alternatives rock, too. I guess the situation after the Leopard release was really a moment that acted as a catalyst for change. The lack of Java 6 and the fact that the Mac SWT is based on the deprecated Carbon API made the Mac seem like a non-optimal platform for Java development, although the new Java is much faster than the previous one, with noticeably improved application startup times. Then, basically within a few days, both a <a href="http://landonf.bikemonkey.org/code/macosx">Java 6 port to Mac OS</a> and a <a href="http://inside-swt.blogspot.com/2007/11/great-success.html">Cocoa implementation of SWT</a> have been started and made running. This is awesome! And I found <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=209376">a way around the classloader issues</a> I had with our project setup. <p/> And that's only a few days after coming to the conclusion that the recent Ubuntu is actually a wonderful alternative for all the stuff I need for work, with a nice modern UI, complete hardware support without a single tweak (on my original MacBook) and great Java and Eclipse support. So now I have both: An awesome alternative free OS which is a great basis for work stuff, giving me a relaxed feeling of non-vendor-lock-in, independence and reliability as well as everything I need right now on my favourite OS with all that awesome stuff Leopard brings along, in particular Time Machine (which really changed my feeling toward my computer a lot, like, I started using Stickies again... lately, the only thing I really trusted was the versioned stuff in my Eclipse workspace), plus a real perspective with a Cocoa SWT and a FOSS Java 6 port. <p/> So all this recent Java and Eclipse stuff really rocks, and I haven't even mentioned Google's awesome new Java (<a href="http://code.google.com/android/what-is-android.html">all that's blue</a>) mobile application framework called 'Android', with its <a href="http://code.google.com/android/intro/hello-android.html">Eclipse-integrated SDK</a>, which will establish Java (and this is the Apache-licensed Harmony Java!) in an amazingly important market area, independent of any particular company, as it happened in other areas before (like different application servers or Eclipse). With both GPL and non-GPL-but-FOSS alternatives Java really seems to become ubiquitous, be it on the server, for mobile devices or cross-platform desktop applications, be it for free or for proprietary software, and be it as a language or as a platform <a href="http://jruby.codehaus.org/">for</a> <a href="http://www.scala-lang.org/">new</a> languages. http://www.fsteeg.com/notes/it-all-rockshttp://www.fsteeg.com/notes/it-all-rocks Tue, 30 Oct 2007 00:00:01 +0000 macjavaeclipse TopCoder Algorithm Competition Eclipse Plug-in <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2007/09/26/topcoder-algorithm-competition-eclipse-plug-in/">https://fsteeg.wordpress.com/2007/09/26/topcoder-algorithm-competition-eclipse-plug-in/</a></small></p> <p/> As the latest version of my little Eclipse Plug-in for TopCoder Algorithm Competitions which I made available here on my blog was a little outdated and buried in an older post, and since I just fixed a bug when running it on Windows I decided to make the recent version available from an update site. <p/> The plugin can now be installed from the update site at: <em><a style="color:#000000;margin:0;padding:0;" href="http://quui.com/updates">http://quui.com/updates</a></em> <p/> Usage: <ul> <li>Select a Java Project that is configured to use JUnit and uses the project folder for source and class files (can be set in the new Java Project Wizard).</li> <li>Select File -&gt; New... -&gt; Others -&gt; TopCoder -&gt; TopCoder Algorithm Solution, paste the problem statement and click finish.</li> </ul> The wizard will generate a solution stub and JUnit tests for the samples in the statement and will run these (so you can immediately re-run them with 'Run Last Launched'). The plug-in also contributes some cheat sheets with stuff I sometimes find useful to remember during a <a href="http://www.topcoder.com/tc">TopCoder Algorithm Competition</a>. http://www.fsteeg.com/notes/topcoder-algorithm-competition-eclipse-plug-inhttp://www.fsteeg.com/notes/topcoder-algorithm-competition-eclipse-plug-in Wed, 26 Sep 2007 00:00:01 +0000 algorithmseclipsejavaprogramming Accessing files in Jars <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2007/02/23/accessing-files-in-jars/">https://fsteeg.wordpress.com/2007/02/23/accessing-files-in-jars/</a></small></p> <p/> Just as a small note, as I was only hardly finding help on this anywhere: If you are trying to access files in a folder, which is bundled inside a Jar file and you try to access them as anyone would: by instantiating a File for the directory - via <code>getResource("directory/")</code> - and then getting all the files: it doesn't work, you can't access a folder in a Jar, you will have to iterate over all the JarEntries, and check for each if it is in the directory (or check its name), like this: <pre><code>JarFile jarFile = new JarFile(&quot;some.jar&quot;); Enumeration&lt;JarEntry&gt; entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry e = entries.nextElement(); if (e.getName().endsWith(&quot;lst&quot;)) { InputStream inputStream = jarFile.getInputStream(e); Scanner s = new Scanner(inputStream); while (s.hasNextLine()) { String nextLine = s.nextLine(); //... } } }</code></pre> <p/> On the other hand, if you need to access only a single file, the way to go is using the <code>getResourceAsStream()</code> method in Class and reading the stream. http://www.fsteeg.com/notes/accessing-files-in-jarshttp://www.fsteeg.com/notes/accessing-files-in-jars Fri, 23 Feb 2007 00:00:01 +0000 java Datentypen Diagramm zur Veranschaulichung der Verdopplung grundlegender Datentypen in Java:<br><br> <a href="http://fsteeg.com/images/2006-11-29_java_Datentypen.dot" title="Graphviz DOT diagram source (also embedded in HTML source)"> <img src="http://fsteeg.com/images/2006-11-29_java_Datentypen.svg" alt="Graphviz DOT diagram source (also embedded in HTML source)" /> </a> <!-- <pre><code>/* Generate image with: dot -Tsvg 2006-11-29_java_Datentypen.dot -o 2006-11-29_java_Datentypen.svg */ digraph{ rankdir=LR node[shape=box] edge[dir=back] datentyp[label="Datentyp" style=dashed] einfach[label="einfacher\nDatentyp" style=dashed] referenz[label="Referenztyp" style=dashed] boolean[style=filled] numerisch[label="numerischer\nTyp" style=dashed] integer[label="ganzzahliger\nTyp" style=dashed] gleitpunkt[label="Gleitpunkt\nTyp" style=dashed] char[style=filled] byte[style=filled] short[style=filled] int[style=filled] float[style=filled] double[style=filled] long[style=filled] rnumeral[label="numerischer\nTyp", style=dashed] rganzzahl[label="ganzzahliger\nTyp", style=dashed] rgleitzahl[label="Gleitpunkt\nTyp", style=dashed] //array[label="z.B. new String[]\n{\"Ein\",\"Array\"}"] rfloat [label="Float" style=filled] rdouble [label="Double" style=filled] rzeichen [label="Character" style=filled] rboolean[label="Boolean" style=filled] rinteger[label="Integer" style=filled] rlong[label="Long" style=filled] rbyte[label="Byte" style=filled] rshort[label="Short" style=filled] datentyp->referenz subgraph cluster_big { label=Objekte; style=dashed rnumeral->rgleitzahl rgleitzahl->rfloat rgleitzahl->rdouble referenz->rnumeral rnumeral->rganzzahl rganzzahl->rinteger rganzzahl->rlong rganzzahl->rbyte rganzzahl->rshort rganzzahl -> rzeichen referenz->rboolean } datentyp->einfach subgraph cluster_small { label=Primitive; style=dashed einfach->boolean einfach->numerisch numerisch->integer numerisch->gleitpunkt integer->char integer->byte integer->short integer->int integer->long gleitpunkt->float gleitpunkt->double } } </code></pre> --> http://www.fsteeg.com/notes/datentypenhttp://www.fsteeg.com/notes/datentypen Wed, 29 Nov 2006 00:00:01 +0000 java Literale <a href="http://fsteeg.com/images/2006-11-01_java_Literale.dot" title="Graphviz DOT diagram source (also embedded in HTML source)"> <img src="http://fsteeg.com/images/2006-11-01_java_Literale.svg" alt="Graphviz DOT diagram source (also embedded in HTML source)" /> </a> <!-- <pre><code>/* Generate image with: dot -Tsvg 2006-11-01_java_Literale.dot -o 2006-11-01_java_Literale.svg */ digraph literale { node[style=filled, shape=box, fillcolor="#F0F0F0"] edge[dir=back, arrowtail=empty] literal[label="Literal", style=dashed] numeral[label="Numeral", style=dashed] wahrheit[label="Wahrheitswert-\nLiteral", style=dashed] ganzzahl[label="Ganzzahliges\nNumeral", style=dashed] gleitzahl[label="Gleitkomma\nNumeral", style=dashed] alphanumerisch[label="Alphanumerisches\nLiteral", style=dashed] //array[label="z.B. new String[]\n{\"Ein\",\"Array\"}"] float [label="12.6F, .6F\n(Float)"] double [label="12.5, .6\n(Double)"] text [label="\"Hallo\", \"1 2 3\"\n(String)"] zeichen [label="'a', '9'\n(Character)"] boolean[label="true, false\n(Boolean)"] integer[label="12, 45\n(Integer)"] long[label="12L, 56L\n(Long)"] literal->numeral numeral->ganzzahl numeral->gleitzahl gleitzahl->float gleitzahl->double ganzzahl->integer ganzzahl->long literal->alphanumerisch alphanumerisch->text alphanumerisch->zeichen literal->wahrheit->boolean } </code></pre> --> <p> </p><pre>// Numerale, ganzzahlig: Integer i = 12; // 32 bit (4 byte) Long l = 12L; // 64 bit (8 byte) // Numerale, Dezimalzahlen: Float f = 12.5F; // 32 bit (4 byte) Double d = 12.5; // 64 bit (8 byte) // Literale, alphanumerisch: Character c = '7'; // ein Zeichen String s = "Hallo 1 2 3"; // Zeichenkette // Wahrheitswert-Literal Boolean b = true; // true oder false </pre> http://www.fsteeg.com/notes/literalehttp://www.fsteeg.com/notes/literale Wed, 01 Nov 2006 00:00:01 +0000 java Adapter Pattern and Java Interfaces <p><small>Cross-posted to: <a href="https://fsteeg.wordpress.com/2004/08/31/adapter-pattern-and-java-interfaces/">https://fsteeg.wordpress.com/2004/08/31/adapter-pattern-and-java-interfaces/</a></small></p> <p/> I just thought that patterns actually do matter even in basic programming education. Consider Java Interfaces. I think it is important to be aware of the general concept of classes having interfaces to really use Java Interfaces. It might be useful approaching it from that side. Reading the chapter on the Adapter Pattern in GOF made me realize Java Interfaces are class adapters in GOF, allowing multiple inheritance only for classes without functionality. And then it really makes sense calling these <em>Interfaces</em>, yet it is unintuitive as a class thereby has many different Interfaces which together are the interface of the class. http://www.fsteeg.com/notes/adapter-pattern-and-java-interfaceshttp://www.fsteeg.com/notes/adapter-pattern-and-java-interfaces Tue, 31 Aug 2004 00:00:01 +0000 javaprogramming RCP The Eclipse RCP is really such a cool thing I think. Theres really a huge professional team and the authorities in Software Engineering (Erich Gamma, Kent Beck) developing robust, well designed, reusable components for your software on a real production level - for free. Its really OO's promises for reusability becoming true. (I wont start on how great Eclipse is as a Java IDE and Tools Platform now, just for completness sake it shall have been mentioned ;) http://www.fsteeg.com/notes/rcphttp://www.fsteeg.com/notes/rcp Sun, 29 Aug 2004 00:00:01 +0000 java