Requirements:
1- Store contacts having the following attributes:
- First Name
- Last Name
- Phone
- Street
- City
- State/Province
- Zip/Postal Code
- Country
2- List stored contacts
3- Search stored contacts by any of the contact attributes.
4- Sort contacts by First Name, Last Name, Email, Phone, or Full Address
5- Edit a stored contact
6- Delete a stored contact
7- Delete all stored contacts
Implementation:
1- Gem Install
gem install glimmer-dsl-swt -v4.24.4.3
% gem install glimmer-dsl-swt -v4.24.4.3
Fetching text-table-1.2.4.gem
Fetching rouge-3.28.0.gem
Fetching super_module-1.4.1.gem
Fetching wisper-2.0.1.gem
Fetching method_source-1.0.0.gem
Fetching tty-screen-0.8.1.gem
Fetching tty-cursor-0.7.1.gem
Fetching tty-reader-0.9.0.gem
Fetching tty-color-0.6.0.gem
Fetching pastel-0.8.0.gem
Fetching tty-prompt-0.23.1.gem
Fetching rake-tui-0.2.3.gem
Fetching awesome_print-1.9.2.gem
Fetching os-1.1.4.gem
Fetching nested_inherited_jruby_include_package-0.3.0.gem
Fetching jruby-win32ole-0.8.5.gem
Fetching facets-3.1.0.gem
Fetching array_include_methods-1.4.0.gem
Fetching glimmer-2.7.3.gem
Fetching puts_debuggerer-0.13.5.gem
Fetching glimmer-dsl-swt-4.24.4.3.gem
Fetching concurrent-ruby-1.1.10.gem
Successfully installed text-table-1.2.4
Successfully installed method_source-1.0.0
Successfully installed super_module-1.4.1
Successfully installed rouge-3.28.0
Successfully installed wisper-2.0.1
Successfully installed tty-screen-0.8.1
Successfully installed tty-cursor-0.7.1
Successfully installed tty-reader-0.9.0
Successfully installed tty-color-0.6.0
Successfully installed pastel-0.8.0
Successfully installed tty-prompt-0.23.1
Successfully installed rake-tui-0.2.3
Successfully installed awesome_print-1.9.2
Successfully installed puts_debuggerer-0.13.5
Successfully installed os-1.1.4
Successfully installed nested_inherited_jruby_include_package-0.3.0
Successfully installed jruby-win32ole-0.8.5
Successfully installed facets-3.1.0
Successfully installed array_include_methods-1.4.0
Successfully installed glimmer-2.7.3
Successfully installed concurrent-ruby-1.1.10
You are ready to use `glimmer` and `girb` commands on Windows and Linux.
On the Mac, run `glimmer-setup` command to complete setup of Glimmer DSL for SWT (it will configure a Mac required jruby option globally `-J-XstartOnFirstThread` so that you do not have to add manually), making `glimmer` and `girb` commands ready for use:
glimmer-setup
Successfully installed glimmer-dsl-swt-4.24.4.3
22 gems installed
glimmer-setup
2- Scaffolding
glimmer "scaffold[contact_manager]"
% glimmer "scaffold[contact_manager]"
Fetching highline-2.0.3.gem
Fetching rack-2.2.3.gem
Fetching semver2-3.4.2.gem
Fetching kamelcase-0.0.2.gem
Fetching nokogiri-1.13.4-java.gem
Fetching multi_xml-0.6.0.gem
Fetching multi_json-1.15.0.gem
Fetching jwt-2.3.0.gem
Fetching ruby2_keywords-0.0.5.gem
Fetching faraday-retry-1.0.3.gem
Fetching faraday-rack-1.0.0.gem
Fetching faraday-patron-1.0.0.gem
Fetching faraday-net_http-1.0.1.gem
Fetching faraday-net_http_persistent-1.2.0.gem
Fetching multipart-post-2.1.1.gem
Fetching faraday-multipart-1.0.3.gem
Fetching faraday-httpclient-1.0.1.gem
Fetching faraday-excon-1.1.0.gem
Fetching faraday-em_synchrony-1.0.0.gem
Fetching faraday-em_http-1.0.0.gem
Fetching hashie-3.6.0.gem
Fetching thread_safe-0.3.6-java.gem
Fetching descendants_tracker-0.0.4.gem
Fetching public_suffix-4.0.6.gem
Fetching addressable-2.8.0.gem
Fetching github_api-0.19.0.gem
Fetching faraday-1.10.0.gem
Fetching oauth2-1.4.9.gem
Fetching rchardet-1.8.0.gem
Fetching git-1.10.2.gem
Fetching builder-3.2.4.gem
Fetching juwelier-2.4.9.gem
Successfully installed semver2-3.4.2
Successfully installed nokogiri-1.13.4-java
Successfully installed kamelcase-0.0.2
Successfully installed highline-2.0.3
Successfully installed rack-2.2.3
Successfully installed multi_xml-0.6.0
Successfully installed multi_json-1.15.0
Successfully installed jwt-2.3.0
Successfully installed ruby2_keywords-0.0.5
Successfully installed faraday-retry-1.0.3
Successfully installed faraday-rack-1.0.0
Successfully installed faraday-patron-1.0.0
Successfully installed faraday-net_http_persistent-1.2.0
Successfully installed faraday-net_http-1.0.1
Successfully installed multipart-post-2.1.1
Successfully installed faraday-multipart-1.0.3
Successfully installed faraday-httpclient-1.0.1
Successfully installed faraday-excon-1.1.0
Successfully installed faraday-em_synchrony-1.0.0
Successfully installed faraday-em_http-1.0.0
Successfully installed faraday-1.10.0
Successfully installed oauth2-1.4.9
Successfully installed hashie-3.6.0
Successfully installed thread_safe-0.3.6-java
Successfully installed descendants_tracker-0.0.4
Successfully installed public_suffix-4.0.6
Successfully installed addressable-2.8.0
Successfully installed github_api-0.19.0
Successfully installed rchardet-1.8.0
Successfully installed git-1.10.2
Successfully installed builder-3.2.4
Successfully installed juwelier-2.4.9
32 gems installed
create .gitignore
create Rakefile
create Gemfile
create LICENSE.txt
create README.markdown
create .document
create lib
create lib/contact_manager.rb
create .rspec
Juwelier has prepared your gem in ./contact_manager
Created contact_manager/.gitignore
Created contact_manager/.ruby-version
Created contact_manager/.ruby-gemset
Created contact_manager/VERSION
Created contact_manager/LICENSE.txt
Created contact_manager/Gemfile
Created contact_manager/Rakefile
Created contact_manager/app/contact_manager.rb
Created contact_manager/app/contact_manager/view/app_view.rb
Created contact_manager/icons/windows/Contact Manager.ico
Created contact_manager/icons/macosx/Contact Manager.icns
Created contact_manager/icons/linux/Contact Manager.png
Created contact_manager/app/contact_manager/launch.rb
Created contact_manager/bin/contact_manager
jruby-9.3.7.0 - #gemset created /Users/andymaleh/.rvm/gems/jruby-9.3.7.0@contact_manager
jruby-9.3.7.0 - #generating contact_manager wrappers..............
Fetching gem metadata from https://rubygems.org/.........
Resolving dependencies...................
Using rake 13.0.6
Fetching public_suffix 4.0.6
Fetching array_include_methods 1.4.0
Fetching awesome_print 1.9.2
Fetching builder 3.2.4
Installing builder 3.2.4
Installing array_include_methods 1.4.0
Installing awesome_print 1.9.2
Installing public_suffix 4.0.6
Using bundler 2.3.9
Fetching concurrent-ruby 1.1.10
Fetching thread_safe 0.3.6 (java)
Installing concurrent-ruby 1.1.10
Fetching diff-lcs 1.5.0
Installing thread_safe 0.3.6 (java)
Installing diff-lcs 1.5.0
Fetching docile 1.4.0
Installing docile 1.4.0
Fetching facets 3.1.0
Fetching faraday-em_http 1.0.0
Fetching faraday-em_synchrony 1.0.0
Installing faraday-em_http 1.0.0
Installing facets 3.1.0
Installing faraday-em_synchrony 1.0.0
Fetching faraday-excon 1.1.0
Fetching faraday-httpclient 1.0.1
Installing faraday-excon 1.1.0
Installing faraday-httpclient 1.0.1
Fetching multipart-post 2.1.1
Fetching faraday-net_http 1.0.1
Installing multipart-post 2.1.1
Installing faraday-net_http 1.0.1
Fetching faraday-net_http_persistent 1.2.0
Fetching faraday-patron 1.0.0
Fetching faraday-rack 1.0.0
Installing faraday-net_http_persistent 1.2.0
Installing faraday-rack 1.0.0
Installing faraday-patron 1.0.0
Fetching faraday-retry 1.0.3
Installing faraday-retry 1.0.3
Fetching ruby2_keywords 0.0.5
Fetching rchardet 1.8.0
Installing ruby2_keywords 0.0.5
Installing rchardet 1.8.0
Fetching hashie 3.6.0
Fetching jwt 2.3.0
Installing hashie 3.6.0
Installing jwt 2.3.0
Fetching multi_json 1.15.0
Installing multi_json 1.15.0
Fetching multi_xml 0.6.0
Fetching rack 2.2.3
Installing multi_xml 0.6.0
Installing rack 2.2.3
Fetching jruby-win32ole 0.8.5
Fetching nested_inherited_jruby_include_package 0.3.0
Installing nested_inherited_jruby_include_package 0.3.0
Installing jruby-win32ole 0.8.5
Fetching os 1.1.4
Installing os 1.1.4
Fetching tty-color 0.6.0
Fetching tty-cursor 0.7.1
Fetching tty-screen 0.8.1
Installing tty-color 0.6.0
Installing tty-cursor 0.7.1
Installing tty-screen 0.8.1
Fetching wisper 2.0.1
Fetching rouge 3.28.0
Fetching method_source 1.0.0
Installing wisper 2.0.1
Installing method_source 1.0.0
Installing rouge 3.28.0
Fetching text-table 1.2.4
Installing text-table 1.2.4
Fetching highline 2.0.3
Installing highline 2.0.3
Using jar-dependencies 0.4.1
Fetching jruby-jars 9.3.7.0
Fetching jruby-rack 1.1.21
Installing jruby-rack 1.1.21
Fetching semver2 3.4.2
Installing semver2 3.4.2
Fetching racc 1.6.0 (java)
Installing racc 1.6.0 (java)
Fetching rspec-support 3.5.0
Installing rspec-support 3.5.0
Fetching rubyzip 1.3.0
Fetching simplecov-html 0.12.3
Installing rubyzip 1.3.0
Installing simplecov-html 0.12.3
Fetching simplecov_json_formatter 0.1.4
Installing simplecov_json_formatter 0.1.4
Fetching addressable 2.8.0
Fetching puts_debuggerer 0.13.5
Installing puts_debuggerer 0.13.5
Installing addressable 2.8.0
Fetching descendants_tracker 0.0.4
Installing descendants_tracker 0.0.4
Fetching faraday-multipart 1.0.3
Installing faraday-multipart 1.0.3
Fetching git 1.10.2
Fetching pastel 0.8.0
Fetching super_module 1.4.1
Installing git 1.10.2
Installing pastel 0.8.0
Installing super_module 1.4.1
Fetching tty-reader 0.9.0
Fetching psych 4.0.3 (java)
Installing tty-reader 0.9.0
Fetching kamelcase 0.0.2
Installing kamelcase 0.0.2
Installing jruby-jars 9.3.7.0
Installing psych 4.0.3 (java)
Fetching nokogiri 1.13.4 (java)
Fetching rspec-core 3.5.4
Installing rspec-core 3.5.4
jar dependencies for psych-4.0.3-java.gemspec . . .
Installing gem 'ruby-maven' . . .
Fetching rspec-expectations 3.5.0
Installing rspec-expectations 3.5.0
Installing nokogiri 1.13.4 (java)
Fetching rspec-mocks 3.5.0
Installing rspec-mocks 3.5.0
Fetching simplecov 0.21.2
Installing simplecov 0.21.2
Fetching faraday 1.10.0
Installing faraday 1.10.0
Fetching glimmer 2.7.3
Installing glimmer 2.7.3
Fetching tty-prompt 0.23.1
Installing tty-prompt 0.23.1
Fetching rspec 3.5.0
Fetching warbler 2.0.5
Installing rspec 3.5.0
Installing warbler 2.0.5
Fetching oauth2 1.4.9
Fetching rake-tui 0.2.3
Installing rake-tui 0.2.3
Installing oauth2 1.4.9
Fetching glimmer-dsl-swt 4.24.4.3
Fetching github_api 0.19.0
using maven for the first time results in maven
downloading all its default plugin and can take time.
as those plugins get cached on disk and further execution
of maven is much faster then the first time.
Installing github_api 0.19.0
Installing glimmer-dsl-swt 4.24.4.3
2022-04-11T20:47:17.877-04:00 [main] WARN FilenoUtil : Native subprocess control requires open access to the JDK IO subsystem
Pass '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED' to enable.
org.yaml:snakeyaml:1.28:compile
Fetching rdoc 6.4.0
Installing rdoc 6.4.0
Fetching juwelier 2.4.9
Installing juwelier 2.4.9
Bundle complete! 5 Gemfile dependencies, 74 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Post-install message from glimmer-dsl-swt:
["\nYou are ready to use `glimmer` and `girb` commands on Windows and Linux.\n\nOn the Mac, run `glimmer-setup` command to complete setup of Glimmer DSL for SWT (it will configure a Mac required jruby option globally `-J-XstartOnFirstThread` so that you do not have to add manually), making `glimmer` and `girb` commands ready for use:\n\nglimmer-setup\n\n"]
exist .rspec
create spec/spec_helper.rb
Created contact_manager/spec/spec_helper.rb
Generated: contact_manager.gemspec
Locking gem jar-dependencies by downloading and storing in vendor/jars...
lock_jars --vendor-dir vendor/jars
Installing gem 'ruby-maven' . . .
Installing gem 'ruby-maven-libs' . . .
using maven for the first time results in maven
downloading all its default plugin and can take time.
as those plugins get cached on disk and further execution
of maven is much faster then the first time.
-- jar root dependencies --
2022-04-11T20:48:09.018-04:00 [main] WARN FilenoUtil : Native subprocess control requires open access to the JDK IO subsystem
Pass '--add-opens java.base/sun.nio.ch=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED' to enable.
org.yaml:snakeyaml:1.28:compile
vendor jars:
- create vendor/jars/org/yaml/snakeyaml/1.28/snakeyaml-1.28.jar
Jars.lock created
Generating JAR configuration (config/warble.rb) to use with Warbler...
/Users/andymaleh/.rvm/gems/jruby-9.3.7.0@contact_manager/bin/warble
cp /Users/andymaleh/.rvm/gems/jruby-9.3.7.0@contact_manager/gems/warbler-2.0.5/warble.rb config/warble.rb
Generating JAR with Warbler...
/Users/andymaleh/.rvm/gems/jruby-9.3.7.0@contact_manager/bin/warble
application directory `db' does not exist or is not a directory; skipping
application directory `docs' does not exist or is not a directory; skipping
application directory `fonts' does not exist or is not a directory; skipping
application directory `images' does not exist or is not a directory; skipping
application directory `lib' does not exist or is not a directory; skipping
application directory `package' does not exist or is not a directory; skipping
application directory `script' does not exist or is not a directory; skipping
application directory `sounds' does not exist or is not a directory; skipping
application directory `videos' does not exist or is not a directory; skipping
rm -f dist/contact_manager.jar
Creating dist/contact_manager.jar
Generating native executable with jpackage...
Java Version 18 Detected!
jpackage --type app-image --dest 'packages/bundles' --input 'dist' --main-class JarMain --main-jar 'contact_manager.jar' --name 'Contact Manager' --vendor 'Contact Manager' --icon 'icons/macosx/Contact Manager.icns' --java-options '-XstartOnFirstThread' --mac-package-name 'Contact Manager' --mac-package-identifier 'org.contact_manager.application.contact_manager' --app-version "1.0.0" --copyright "Copyright (c) 2022 contact_manager" --name 'Contact Manager' --description 'Contact Manager'
Launching Glimmer Application: ./bin/contact_manager
Launching Glimmer Application: /Users/andymaleh/code/contact_manager/app/contact_manager/launch.rb
3- Add ActiveRecord gems to Gemfile
bundle install
Fetching gem metadata from https://rubygems.org/.......
Resolving dependencies..........................
Using rake 13.0.6
Using concurrent-ruby 1.1.10
Fetching zeitwerk 2.5.4
Fetching minitest 5.15.0
Using public_suffix 4.0.6
Fetching jdbc-sqlite3 3.28.0
Using array_include_methods 1.4.0
Using awesome_print 1.9.2
Using builder 3.2.4
Using bundler 2.3.9
Using thread_safe 0.3.6 (java)
Using diff-lcs 1.5.0
Using docile 1.4.0
Using facets 3.1.0
Using faraday-em_http 1.0.0
Using faraday-em_synchrony 1.0.0
Using faraday-excon 1.1.0
Using faraday-httpclient 1.0.1
Using multipart-post 2.1.1
Using faraday-net_http 1.0.1
Using faraday-net_http_persistent 1.2.0
Using faraday-patron 1.0.0
Using faraday-rack 1.0.0
Using faraday-retry 1.0.3
Using ruby2_keywords 0.0.5
Using rchardet 1.8.0
Using hashie 3.6.0
Using jwt 2.3.0
Using multi_json 1.15.0
Using multi_xml 0.6.0
Using rack 2.2.3
Using jruby-win32ole 0.8.5
Using nested_inherited_jruby_include_package 0.3.0
Using os 1.1.4
Using tty-color 0.6.0
Using tty-cursor 0.7.1
Using tty-screen 0.8.1
Using wisper 2.0.1
Using rouge 3.28.0
Using method_source 1.0.0
Using text-table 1.2.4
Using highline 2.0.3
Using jar-dependencies 0.4.1
Using jruby-jars 9.3.7.0
Using jruby-rack 1.1.21
Using semver2 3.4.2
Using racc 1.6.0 (java)
Using rspec-support 3.5.0
Using rubyzip 1.3.0
Using simplecov-html 0.12.3
Using simplecov_json_formatter 0.1.4
Fetching i18n 1.10.0
Installing zeitwerk 2.5.4
Installing minitest 5.15.0
Installing i18n 1.10.0
Fetching tzinfo 2.0.4
Using addressable 2.8.0
Using puts_debuggerer 0.13.5
Using descendants_tracker 0.0.4
Using glimmer 2.7.3
Using faraday-multipart 1.0.3
Using git 1.10.2
Using pastel 0.8.0
Using tty-reader 0.9.0
Using super_module 1.4.1
Using psych 4.0.3 (java)
Using kamelcase 0.0.2
Using nokogiri 1.13.4 (java)
Using rspec-core 3.5.4
Using rspec-expectations 3.5.0
Using rspec-mocks 3.5.0
Using warbler 2.0.5
Using simplecov 0.21.2
Using faraday 1.10.0
Using tty-prompt 0.23.1
Using rdoc 6.4.0
Using rspec 3.5.0
Using oauth2 1.4.9
Using rake-tui 0.2.3
Using github_api 0.19.0
Using glimmer-dsl-swt 4.24.4.3
Using juwelier 2.4.9
Installing tzinfo 2.0.4
Fetching activesupport 6.1.5
Installing activesupport 6.1.5
Fetching activemodel 6.1.5
Installing activemodel 6.1.5
Fetching activerecord 6.1.5
Installing activerecord 6.1.5
Fetching activerecord-jdbc-adapter 61.1 (java)
Installing jdbc-sqlite3 3.28.0
Installing activerecord-jdbc-adapter 61.1 (java)
Fetching activerecord-jdbcsqlite3-adapter 61.1 (java)
Installing activerecord-jdbcsqlite3-adapter 61.1 (java)
Bundle complete! 7 Gemfile dependencies, 84 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
4- Add an ActiveRecord migration for the contacts database table
5- Add a SQLite database with ActiveRecord
6- Add the Contact ActiveRecord model
7- Add the ContactRepository model
8- Add the ContactPresenter model
9- Add the ContactForm custom widget view
10- Add the ContactTable custom widget view
Create app/contact_manager/view/contact_table.rb and add the `contact_table` custom widget view code to it:
11- Add the ContactManagerMenuBar custom widget view
Create app/contact_manager/view/contact_manager_menu_bar.rb and add the `contact_manager_menu_bar` custom widget view code to it:
12- Update the AppView
Update app/contact_manager/view/app_view.rb by replacing all code with the following:
13- Update the ContactManager entry point
14- Replace app icons
15- Run
glimmer run
./bin/contact_manager
16- Package Native Executable
glimmer "package[dmg]"
glimmer "package[msi]"
glimmer "package[deb]"
glimmer "package[rpm]"
Software Architecture & Design
The View uses contact_form, contact_table, and contact_manager_menu_bar custom widgets (components).
The Contact Manager graphical user interface leverages the Master-Detail Interface Pattern by displaying a master list via contact_table and allowing navigation by selecting a Contact and displaying its details for editing in contact_form.
The Model layer includes a Contact and ContactRepository (DDD Repository Pattern) in addition to ContactPresenter (which is both a Controller and a Model at a higher level).
Contact follows the Active Record Pattern for Object Relational Mapping to store objects in a SQLite relational database table called contacts via a migration. It also implements ActiveRecord Validations for first_name, last_name, email, phone, and zip_or_postal_code fields.
ContactRepository provides the ability to search through all Contacts using the ActiveRecord Query Interface, triggered indirectly by ContactPresenter when typing into a text field that is on top of the contact_table .
The database is stored at File.join(Dir.home, 'db/contact_manager.sqlite3')
4 comments:
Thanks for sharing these!
Great post! I appreciate all the linked references, too. Thanks a lot.
Cool, working great. Thanks a lot!
You're welcome.
By the way, I just updated the article and project to improve and fix a few issues.
Details are in the project Change Log.
In summary, the glimmer-dsl-swt gem has been upgraded to v4.24.4.1, which includes table data-binding improvements and optimizations like auto-inferred column attributes by convention.
And, the following files were updated:
- app/contact_manager/model/contact.rb
- app/contact_manager/model/contact_presenter.rb
- app/contact_manager/view/contact_table.rb
Post a Comment