Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Saturday, January 07, 2023

Using Nebula TextAssist from Glimmer DSL for SWT

Recently, I received a support request concerning Glimmer DSL for SWT (JRuby Desktop Development GUI Framework) and the use of Nebula Custom Widgets, specifically the text_assist widget (auto-complete text field). 

For a quick background about Nebula, it is a collection of 55+ enterprise-grade high-quality SWT (Standard Widget Toolkit) custom widgets, including a progress circle, a password revealer, and an oscilloscope. Thanks to Glimmer DSL for SWT, they are usable from Ruby.




The support request mentioned that the text_assist custom widget was not working. It was because its Nebula implementation does not follow the SWT convention of always supporting a constructor that only takes (parent, style) arguments. This convention is actually universal in all widgets included in SWT out of the box. It is taken advantage of by Glimmer DSL for SWT to automate wiring of widgets between parents and children without having to pass arguments explicitly. The wiring is done automatically by simply nesting a child keyword (e.g. label) under a parent keyword (e.g. composite). Unfortunately, this convention is broken by the text_assist widget API, as documented in the TextAssist Nebula widget page:

“There is a big difference with other SWT widget : there is no constructor TextAssist(Composite parent, int style).

The only constructor available is public TextAssist(final Composite parent, final int style, final TextAssistContentProvider contentProvider)”
As such, nesting text_assist directly under a parent without passing arguments breaks.

The fix is very simple though. Glimmer DSL for SWT follows the 80/20 rule, which is common in Rails. That means, it automates 80% of the cases with convention over configuration for ultra-high productivity, and yet it still supports the remaining 20% of the cases (e.g. SWT widget not following API convention) through direct configuration. 

In the case of the Nebula text_assist custom widget, given that its API deviates from the standard convention, you can still use it by simply passing constructor arguments for text_assist directly in order to have it work as expected by its API. 

Let us demonstrate with an example.



Animated screenshot:




The shell widget (aka window) parent proxy Ruby object (wrapper of SWT Java object) is grabbed from the parent block variable (or any variable the parent is assigned to) before invoking the swt_widget method on it to grab the wrapped SWT Java object and pass it as per the expectation of the text_assist widget API (normally, all of this is done automatically for you with standard convention SWT widgets).   

Remember Shoes (the old Ruby desktop gem)? One of its biggest issues was lack of simple extensibility via high quality custom widgets. On the other hand, Glimmer DSL for SWT not only supports custom widgets written in Ruby, but also supports the entire Eclipse ecosystem and custom widgets written in Java, like Nebula.

Please support the most productive desktop development framework in Ruby (including productivity benefits not found in any web framework) by building applications in Glimmer DSL for SWT (or other Glimmer GUI DSLs)!

Happy Glimmering!

Friday, October 22, 2010

Rails Tutorial Submission at EclipseCon 2011

I submitted this tutorial proposal for EclipseCon 2011. If it catches your interest, please comment/vote for it by following the link at the bottom



Title: Behavior Driven Web Development with Rails, Aptana, and Cucumber



Abstract:


If you have been waiting for a good excuse to finally plunge into the Ruby world and learn the wildly popular Rails web framework, this is the tutorial to attend at EclipseCon. Not only does it cover the basics of Ruby and Rails, yet also behavior/test driven development with Cucumber/RSpec. The Eclipse-based Aptana RadRails IDE will be the main tool used in this tutorial.



The tutorial will include:


  • Basics of Ruby including some basics in meta-programming

  • Basics of Rails covering MVC and configuration

  • Basics of Behavior Driven Development with Cucumber

  • Basics of Test Driven Development with RSpec

  • Basics of the Eclipse-based Aptana RadRails IDE for Ruby on Rails development

  • An example Ruby on Rails application that walks students through learning the different components of a Rails application




Most of the material of the tutorial will be inspired by the Rails training courses I have given at Obtiva, such as the Rails TDD Bootcamp and the Rails 10-week Evenings Course (self-authored)



Link:


https://www.eclipsecon.org/submissions/2011/view_talk.php?id=1985&search=difficulty%3D%22easiest%22

Friday, November 27, 2009

Invoking Glimmer Tests and Specs via Rake

As part of implementing the Game of Life UI in Glimmer, I actually updated Glimmer's Rakefile to invoke all tests successfully. Since the Game of Life domain logic was test-driven with RSpec, I also had Rakefile invoke both specs and regular unit-tests with the default command: jrake (the j is needed because Glimmer runs on jRuby instead of Ruby)

"jrake spec" invokes specs alone.
"jrake test" invokes unit-tests alone.

More improvement and changes are coming Glimmer's way including an attractive image on the landing page:

Thursday, November 26, 2009

Conway's Game of Life - Glimmer Edition

I recently attended a Chicago Ruby group meeting where everybody paired up on implementing a version of Conway's Game of Life in Ruby. At the end of the meeting, the logic of the game was completely test-driven and ready for use, so I decided to slap on a Glimmer UI on top of it afterward: Here is Glimmer's repository: http://dev.eclipse.org/svnroot/technology/org.eclipse.glimmer.core/ Here are the tests written with RSpec: http://dev.eclipse.org/svnroot/technology/org.eclipse.glimmer.core/spec/samples/game_of_life/ And, here is the implementation: http://dev.eclipse.org/svnroot/technology/org.eclipse.glimmer.core/samples/game_of_life/ The game logic is in grid.rb and cell.rb whereas the UI code is in game_of_life.rb. cell_presenter.rb provides the presenter needed for data-binding with the MVP pattern. Here is how the Glimmer UI code looks like: width = 7 height = 7 grid = Grid.new(width, height) shell {   text "Conway's Game of Life (Glimmer Edition)"   composite {     layout GridLayout.new(width,true)     (0...width).each { |x|       (0...height).each { |y|         button {           layout_data GridData.new(fill, fill, true, true)           text bind(CellPresenter.new(grid, x, y), :alive)           on_widget_selected {             grid.toggle_aliveness!(x, y)           }         }       }     }     button {       text "Step"       on_widget_selected {         grid.step!       }     }   } }.open It simply iterates over the Game of Life grid cells, wrapping each with a presenter and binding it to a button in the UI: text bind(CellPresenter.new(grid, x, y), :alive) When a button is clicked, the cell aliveness is toggled to "alive" (showing 'o') or "dead". This enables player to lay out the grid of cells: on_widget_selected {   grid.toggle_aliveness!(x, y) } Finally, to step the game, there is a "Step" button that steps the grid into the next generation, resulting in cells that die, new cells born, and cells that simply continue to be alive: button {   text "Step"   on_widget_selected {     grid.step!   } } One thing that is noteworthy is that Glimmer's support for data-binding greatly facilitated the decoupling of the UI from the domain logic enabling us to write our domain code in full isolation of the UI, and later adding the UI and its related presentation logic via the Glimmer UI DSL and the presenter. Hit me up with comments or an email if you have any questions. Happy thanksgiving!

p.s. 2021-08-01: superceded with canvas-based implementation in Glimmer DSL for SWT v4.20.13.11: https://andymaleh.blogspot.com/2021/08/conways-game-of-life-elaborate-glimmer.html

Wednesday, September 23, 2009

Glimmer Webinar Video

Here is a video of the Glimmer Webinar I gave today:
http://live.eclipse.org/node/792

Enjoy!

And, email me any questions you have.

Tuesday, September 22, 2009

Webinar: Simplifying Desktop Development with Glimmer

Webinar:

Simplifying Desktop Development with Glimmer

Link:

http://live.eclipse.org/node/792


Abstract:


Programming SWT/JFace user-interfaces in Java often involves a lot of repetitive boiler-plate code that is overly verbose and hard to map to the user-interface visually. This can significantly hinder maintainability and productivity for Eclipse RCP projects.

Enter Glimmer; a JRuby API for SWT that takes advantage of the expressive Ruby language to provide a simple user-interface DSL (domain-specific language). Developers can rely on Glimmer to build the presentation layer of desktop applications in Ruby while keeping the business logic in Java, or alternatively do complete desktop application development in Ruby. Glimmer comes with built-in data-binding support to greatly facilitate writing maintainable and testable desktop application code.

In this webinar, I will introduce Glimmer, demo the latest features by contrasting the code of an application written in both Glimmer and classic SWT, provide a quick update on the status of the project and finally, have a Q&A and feedback session.

Total running time will be approximately 1 hour

9:00 am PDT / 12:00 pm EDT / 4:00 pm GMT - Convert to other time zones

Monday, July 27, 2009

Mouse-less Eclipse

Last updated on July 29, 2009

A fellow blog reader commented on a post I made last month titled The IDE vs Editor War in the Ruby World, asking how I actually use Eclipse in a mouse-less way. So, I decided to post a list of all Eclipse shortcuts that I find practical enough to use in my day-to-day work. Note that my focus will be mostly on text editing shortcuts as opposed to language specific shortcuts.

Mouse-less Eclipse Keyboard Shortcuts:


  • CTRL+SHIFT+L: lists all available shortcuts (useful for learning)
  • CTRL+SHIFT+R: lookup up a resource (e.g. html, xml, rb, erb, properties, etc...)
  • CTRL+SHIFT+T: lookup a class name (e.g. String or Customer)
  • CTRL+F6: quickly jump between open files
  • CTRL+E: jump between open files using a filename filter or navigation keys
  • ALT+LEFT and ALT+RIGHT: navigate back and forth in the history of the files I opened. I rely on this one a lot to avoid using the mouse when navigating back and forth between different classes that collaborate to get a user interaction handled.
  • CTRL+O: lookup a method (thanks Kristian for reminding me)
  • F3: jump to method, class, or variable declaration.
  • CTRL+J keyword: instant search of a keyword within a file
  • CTRL+F keyword then ENTER: regular search.
  • CTRL+K and CTRL+SHIFT+K: find next and find previous repeating search for the last keyword
  • Highlight text to find other occurrances of a keyword and then CTRL+K: lets you find a keyword without even typing it if you see one occurrence already in the file (for example, you see a use of the slow performing method "reindex" and you wonder where else it's used in the file)
  • CTRL+H: project-wide search for a keyword. You can also specify file patterns. Make sure to tab into fields or use mnemonics and hit ENTER instead of using the mouse. Once the search completes, pick the result you want using the up/down arrows and then hit enter to open the file.
  • HOME/END/PGUP/PGDN: for navigation of course. I've been surprised many times by how very few developers rely on these buttons to navigate a file efficiently without using the mouse.
  • CTRL+LEFT and CTRL+RIGHT: jump between words for quicker navigation in a line without taking hand off keyboard to use the mouse.
  • CTRL+SHIFT+LEFT and CTRL+SHIFT+RIGHT: quick highlighting of words without taking hand off keyboard to use the mouse.
  • CTRL+L: jump to a particular line number. I keep line numbers visible to quickly locate stack trace errors. This one is invaluable in saving me from paging through a file or using the mouse.
  • CTRL+ALT+DOWN (or UP): clones a line downwards. It's like copy/paste without using the clipboard, which I use often to avoid emptying the clipboard from something I've copied that I'd like to paste somewhere. This is most useful with the CTRL+UP/DOWN shortcuts.
  • CTRL+UP and CTRL+DOWN: moves a line up or down quickly. I often start by cloning a line, and then I move the cloned line down or up to the place I want it to be at.
  • CTRL+SHIFT+F: format content (makes sure everything is indented nicely)
  • ALT+SHIFT+UP: highlights an entire variable name even if it had underscores and multiple words
  • ALT+W P: access preferences via ALT+character mnemonics
  • ALT+character mnemonics in general: useful to do all upper menu navigation instantly without a mouse if you're on Linux or Windows (sorry Mac people). Over time, your nervous system ends up memorizing a lot of the character sequences, saving you from having to even read the menu items, let alone pointing at them with a mouse and clicking them.
Additionally, there are many shortcuts for refactoring and source generation, which I will leave for the readers to discover on their own through the menus of Eclipse.

If I remember more shortcuts over the next few days, I will make sure to update the list above. Although anyone can look up shortcuts in the Eclipse keys preferences page, not all shortcuts are practical, so I am only highlighting the ones that I consistently use to increase productivity and flow. Of course, there may be shortcuts that I have not learned to appreciate yet, so feel free to contribute in the comments the shortcuts you normally like to use.

How do I know about all these shortcuts? Did I learn them all from a reference? How can I keep learning more shortcuts in my day-to-day job? I'll leave the answers to these questions to a future blog post.

Tuesday, June 02, 2009

The IDE vs Editor War in the Ruby World

Ever since I switched to Ruby programming last September to develop Rails web applications, I've been fighting an up-hill battle to convince other developers of the value of using Eclipse or IDEs in general.

Since Ruby is an interpreted language (with a transparent compilation step for optimizations purposes only), developers mainly rely on test-driven development to produce reliable code. Auto-compilation and verification of code is thus rendered for the most part unnecessary.

Additionally, given Ruby's support for attributes (via attr* methods) and no need to declare class variables, many of the source code generators used in Java are not needed in Ruby. After all, Ruby's philosophy is about producting the tersest most abstract code, free of boiler-plate repetitive code.

Refactoring with Ruby is often done manually, but given that there isn't usually a lot of code with proper abstraction, and given Ruby's method aliasing support, huge refactorings of the nature that ripples through the whole system are rare, and thus refactoring is quite easy to perform manually especially given the protection of the Ruby must-have unit tests.

So, what does that leave as far as tooling needs? Color coding, syntax highlighting, file lookup, search and replace, and possibly some autocompletion capabilities.

Well, these limited needs brought back the popularity of simple editors that support just these features. By simple editors, I do actually mean good old VIM and emacs as well as the new extremely popular Mac editor, TextMate.

After 10 months of pair-programming with different Ruby developers with varying habits and backgrounds, I got to do a pilgrimage through most Ruby editors and IDEs. So far, I've gone through TextMate, VIM, Aptana RadRails, Eclipse DLTK, NetBeans, and IntelliJ RubyMine.

Yes, I'm a shortcut freak, and I used to write Java programs in Eclipse mouse-less!!! So, how did other editors and IDEs measure in comparison as far as shortcuts and productivity?

I'll leave that to another post.

In the meantime, what is your opinion of the matter? Do any of you prefer editors over IDEs? If so what's your editor/IDE of choice and what are the reasons you like it? Feel free to mention different ones for different programming languages.

Thursday, March 26, 2009

XP West Michigan and EclipseCon 2009

Tyler Jennings, Jake Scruggs, and I went on a road trip to Grand Rapids, Michigan yesterday and gave two presentations at the XP West Michigan user group. Jake presented "What’s the right level of testing?", and Tyler and I presented "Pairing Parody". Atomic Object hosted us and gave us a tour around their office. They had a nice open environment for pair-programming and a street light that signals the state of project builds (red for failure, green for success, and yellow for build in progress). The experience was very hospitable overall thanks to Michael Swieton.

Today, I flew to the Silicon Valley area around San Jose, California to present at EclipseCon 2009 tomorrow. I will be giving a short talk about Glimmer and the current state of the project.

If you have any specific questions about the project, feel free to list them here in the comments, and I will try to cover them in the talk.

Tuesday, February 03, 2009

Obtiva HackFest and Glimmer Tree Data Binding in Progress

Today, instead of having our weekly GeekFest meeting at Obtiva, Dave organized a HackFest instead.

Colin, Dave, Roy, and Nate worked on
Colin's ultimate midi controller project. Tom, Leah, and Jake worked on the Metric Fu Aggregator. And, Tyler, Turner, and I worked on implementing Tree Data-Binding support for Glimmer.

In one hour, we made as much progress as we could, which amounted to coming up with a design for the data-binding syntax in this unit test:


module Node
attr_accessor :parent, :children
end

class Person
include Node
attr_accessor :name, :age, :adult
end

def test_root_node_only
adam = Person.new
adam.name = "Adam"

@target = shell {
@tree = tree {
items bind(adam, :name)
}
}

assert_equal 1, @tree.widget.getItems.size
assert_equal adam, @tree.widget.getItems.first
end


To bind SWT Tree items to a model node hierarchy, you pass two parameters to the bind command: the root model node and the name of the attribute to be used for displaying text in the tree.

More tests will eventually be written to test data-binding a root model with children.

In the future, this will probably grow in other directions to handle tree node images and selection.

Test-driven design is a common practice at Obtiva as it gets many birds with one stone: ease of exploration of ideas, test-coverage, clean code design, and higher productivity due to incremental development preventing endless hours of debugging.

Stay tuned for more on Tree Data-Binding support in Glimmer in the future.

Thursday, January 29, 2009

Sudoku Solver in Glimmer

Dave Hoover recently experimented with writing a Sudoku solver in Ruby, so Joseph Leddy and I decided to slap a Glimmer cover on top of it. We pair-programmed on writing it test-first following the Model View Presenter pattern.

Here is how the user-interface looks like:



I'll provide more details once I've committed the code to the Glimmer repository.

Monday, December 22, 2008

Glimmer Short Talk Description Change for EclipseCon 2009

I reported a few days ago that I will be presenting Glimmer at EclipseCon 2009:
http://andymaleh.blogspot.com/2008/12/eclipsecon-2009-here-i-come.html

I just wanted to mention that I updated the description to provide more value to attendees in the 10-minute talk that I will be giving in 2009. Last year, I provided a quick introduction to what Glimmer is about. This year, I will expand by demonstrating the latest features added to Glimmer.

Here is the part I specifically changed in the talk's description:
In this presentation, I will introduce Glimmer, demo the latest features by contrasting the code of an application written in both Glimmer and classic SWT, and finally provide a quick update on the status of the project.
Looking forward to seeing everyone at the conference.

Wednesday, December 17, 2008

EclipseCon 2009 Here I Come

I'm speaking at EclipseCon 2009

My Glimmer talk proposed for EclipseCon 2009 has been accepted:
https://www.eclipsecon.org/submissions/2009/view_talk.php?id=367

Looking forward to being at Santa Clara, California during Mar 23-26 2009.

Monday, December 15, 2008

First Code Example of Glimmer RSpec/SWTBot Testing

So, I mentioned in this >>blog post<< that Glimmer's now got Behavior-Driven Development support through RSpec and SWTBot.

In this post, I'll go over some of the technical aspects of how that works.

RSpec Cucumber is an engine that lets you map English statements (or any language actually) to executable code in order to validate software specifications written as scenarios with the code written to fulfill them. This is pretty much what Acceptance Tests in the XP process are.

Here is an RSpec Cucumber login.feature file that I wrote to test a Login (Glimmer) sample application:


Feature: Login feature
In order to keep user data secure
As a user
I would like to be authenticated before I can access my data

Scenario: Login
Given I fill in "User" for "Username"
And I fill in "Pass" for "Password"
When I "Login"
Then my status should be "Logged In"

Scenario: Logout
GivenScenario Login
When I "Logout"
Then my status should be "Logged Out"


The top 3 lines after the feature heading describe the user story being developed in the stakeholder language. Those lines are not executable.

The scenarios that follow however, which demonstrate the feature functionality, are written in the Given/When/Then format and executed to validate that the implementation satisfies the specification.

In order to execute these scenarios, you need to have code that can execute each step (statement on a line) in every scenario. Such code is arranged in *_steps.rb files. Here is how such code is written:


When /I fill in "(.*)" for "(.*)"/ do |text, label|
  @bot.text_with_label(label).text = text
end

When /I "(.*)"/ do |button|
  @bot.button(button).click
end

Then /my status should be "(.*)"/ do |text|
  @bot.label(text).should_not be_nil
end


The @bot object is actually an instance of the SWTBot class. This is an SWT driver that enables you to poke at an SWT desktop application by simulating a user filling in fields and initiating events like clicking a button.

Let's go through the steps one by one.

The following statement grabs a text box with the specified label, and sets its text property to whatever the text mentioned in the step is:


When /I fill in "(.*)" for "(.*)"/ do |text, label|
  @bot.text_with_label(label).text = text
end


This following statement on the other hand grabs a button based on the text that is displayed on it, and simulates a user click on it:


When /I "(.*)"/ do |button|
  @bot.button(button).click
end


Finally, this following statement looks for a label with the specified text and says that it should not be nil (null.) The should_not method is a method from RSpec that lets you write assertions using English-like statements as opposed to using the assert_equals method with two parameters:


Then /my status should be "(.*)"/ do |text|
  @bot.label(text).should_not be_nil
end


My code samples are still experimental and not ready to share yet. Once I have them in a good-enough state, I will commit them to the repository and blog about them in order to give people the opportunity to play with them.

Saturday, December 13, 2008

Friend of Eclipse 2009

Just wanted to share that I renewed my friendship with Eclipse.



If you want to become a friend too or just renew your friendship, click on the image above for more details.

I do it because I am very appreciative of all the work that went into Eclipse, RCP, SWT, and the ecosystem in general.

Thursday, December 11, 2008

Glimmer's Got BDD through RSpec and SWTBot

I got an RSpec Story Runner (Cucumber) test passing with Glimmer code that tests whether a user logs in successfully.

RSpec is a Ruby library that encourages BDD (Behavior Driven Development,) enabling you to drive the functionality of your application from the outside in by specifying the external behavior from the user's point of view and in the user's language.

Here is the test I got passing with Glimmer:


Feature: Login feature
In order to keep user data secure
As a user
I would like to be authenticated before I can access my data

Scenario: Login
Given I fill in "User" for "Username"
And I fill in "Pass" for "Password"
When I "Login"
Then my status should become "Logged In"


It uses SWTBot behind the scenes to execute the scenario steps, such as filling in text fields and pressing the login button.

Here is the user-interface:



Here is the user-interface Glimmer code relying on data-binding:


@shell = shell {
text "Login"
composite {
layout GridLayout.new(2, false) #two columns with differing widths

label { text "Username:" } # goes in column 1
text { # goes in column 2
text bind(presenter, :user_name)
enabled bind(presenter, :logged_out)
}

label { text "Password:" }
text(SWT::PASSWORD | SWT::BORDER) {
text bind(presenter, :password)
enabled bind(presenter, :logged_out)
}

label { text "Status:" }
label { text bind(presenter, :status) }

button {
text "Login"
enabled bind(presenter, :logged_out)
on_widget_selected { presenter.login }
}

button {
text "Logout"
enabled bind(presenter, :logged_in)
on_widget_selected { presenter.logout }
}
}
}
@shell.open


In a future post, I will discuss the technical details of how this works.

Saturday, December 06, 2008

Glimmer on JRuby 1.1.5

Glimmer is now compatible with JRuby 1.1.5.

Thanks to dacm for taking the effort to report a Glimmer incompatibility bug on Eclipse BugZilla:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=257793

It is now fixed.

Thanks to Steve, Tom, and Starling too for reporting that bug along with the fix.

The changes were deployed to both SVN and GitHub repositories.

Friday, December 05, 2008

Glimmer Finally Available at GitHub

Yes! After so many requests, Glimmer's Eclipse SVN Repository is finally cloned at GitHub (thanks to Soleone's suggestion to use git-svn):
git://github.com/AndyObtiva/glimmer.git

Here is the main GitHub project page:
http://github.com/AndyObtiva/glimmer/tree/master

This will make it much easier for people to contribute to Glimmer. Instead of checking out the SVN repository and submitting patches back to me to merge. Developers can now fork Glimmer completely on GitHub, commit multiple changes, and then notify me to merge the forked version back into the origin/trunk.

Happy Glimmering!

Wednesday, December 03, 2008

Glimmer WIKI and FAQ

Glimmer's got pages on the Eclipse WIKI now:

http://wiki.eclipse.org/Glimmer
http://wiki.eclipse.org/Glimmer/FAQ

They will be updated gradually as the project continues to grow.

Tuesday, December 02, 2008

Video of Glimmer DSL Engine lightning talk @ RubyConf 2008

A number of people expressed interest in contributing to Glimmer, and they wanted to get an understanding of Glimmer's internal workings in order to get started.

I gave a lightning talk about Glimmer's DSL engine during RubyConf 2008, and fortunately the ConFreaks guys recorded a video of it, just as they recorded one of my >>main Glimmer talk<<.

Check it out over here:
http://rubyconf2008.confreaks.com/glimmers-dsl-engine.html

It is pretty short (10 minutes,) but provides a good primer for Glimmer's internal DSL engine.