Dashboard > UDIG Developer Guide > Home > 2 Programmers Guide > 4 Guidelines and Rules > 5 Coding Conventions
5 Coding Conventions Log In | Sign Up   View a printable version of the current page.

Added by Richard Gould , last edited by Administrator on Sep 15, 2008  (view change)
Labels: 
(None)

As a strict policy we do our best to use the tools to capture our coding conventions; as such we make use of FindBugz, Code Templates and Code Formatters for all the small stuff.

This page covers what is left.

Converting a URL to a File

When you need to convert a java.net.URL object to a java.io.File object, you must take care that you do not ignore the 'authority' property on the URL object. This contains information about the server that the file is located on. On Windows systems, this includes the drive or network share, such as "E:" or "fooServer".

The rule is simple: If URL.getAuthority isn't null or empty, then the File should be constructed like so:

URL url = ...
File f = new File("//" + url.getAuthority() + url.getPath());

It is very important that you always check the authority when converting to a File!

There is a utility method in URLUtils that will do this for you:

File f = URLUtils.urlToFile(url);

Use it!

Example Checklist for an Import Wizard

The preceding sections on 1 UDIG Guidelines,2 Eclipse House Rules and 3 User Interface Guidelines may be a little bit abstract. Here is the results of apply those guidelines into an actual Quality Assurance Checklist for the UDIGImportPage.

Check Load Data
  listed in the "Add Layer" and "Data Import" wizards
  banner and a title
  starts with a prompt (not an error message)
  tab order as fields are filled in
  test if data is loaded correctly
  test that new content is selected (in layer or catalog view)
Check Context and Error
  starts with fields based on workspace context (ie the data we just loaded)
  restart page and check that history is remembered
  fill out the fields incorrectly and check reporting of error messages
Check DnD
  DnD with appropriate URL (check of canProcess method)
Check Help and Internationalization
  Check for presense of online reference page for this wizard
  Press F1 and (or click on the ?) for context sensitive help
  Restart and run tests with French

Implementation Tips

  • Workspace context is based on IDataWizard.getSelection().
  • History is maintained in Dialog settings and is remembered across runs (See 10 Adding History to Dialogs and Wizards)
  • Steal an existing wizban image and modify
  • jdbc urls are not "valid" urls, see the jdbc trail and are not usual done using DND

Code Checks

  • Turn on all warnings as in environment setup
  • Classes have at minimum a javadoc comment
  • Strings should be externalized for internationalization
Powered by a free Atlassian Confluence Open Source Project License granted to uDig. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators
User-friendly Desktop Internet GIS