Monday, October 09, 2006

Introduction

As with most things I do, my purpose is not obtaining the result but understanding the journey. What I want to do write a winform so that I can  

·       Investigate the properties of the DataGridView control in Visual Studio 2005.

·       Configure the TableAdapter object so that the DataGridView control shows values from a database.

·       Use the DataGridView control to navigate and update the database.

The actual database I use is not that important. I chose to write a simple database in Access that records my household budget. Access for me is a comfort zone, but I think the database could just as easily be in SQL Server 2005. I may later migrate it to SQL Server 2005, but right now my interest is in the DataGridView control and not in the database software.

It turns out you can get an application running by just dragging and dropping and configuring property screens. You don’t really have to write any code at all. It’s designed to be “quick and easy.” But here’s a quote from Pro ADO.NET 2.0 by Sahil Malik. “… your application is just as good as the amount of effort you put into it. You can’t expect drag-and-drop applications to help you create a well-architected enterprise-level application …” The drag-and drop method is good for prototyping, and you can learn a bunch by reading the auto-generated code.

The Database

Here is how my database looks initially. I may expand on it as I develop my application, adding entries to tables, adding new tables, setting relationships between the tables.

Building the Winform

Just make a winform application. And click on Add New Data Source …

Then, click Next>.

I already had a connection from a previous attempt at this, and so I chose it. Click Next>.

Click Next>. The connection string gets saved in app.config.

Select Tables. I chose not to select Views. I don’t know how easy it would be to add them later. Hopefully, one would not have to start from scratch.

Click Finish. You now see a Data Source window with the generated DataSet.

 

Select Checks and drag it onto the form You see a DataGridView. Notice the navigation controls at the top and the components in the IDE footer.

You can now build and run the winform, and this is what you see. Note that CategoryID, Location, and BankID appear as integers. This is not what I want. I’d like to have a lookup table in a dropdown list.

Back in Visual Studio, select the DataGridView and expand the Smart Tag.  Then click Edit Columns …

Do the following for the three columns: CategoryID, Location, and BankID. Highlight the column in Selected Columns:.  On the right, in Bound Column Properties,

·       Go to Design à ColumnType. Drop down the list for its value and choose DataGridViewComboBoxColumn.

·       Go to Data à DisplayMember. Drop down the list for its value and choose Name.

·       Go to Data à DataSource. Drop down the value list. Expand Other Data Sources. Expand Project Data Sources. Expand ExpensesDataSet. Select the table corresponding to the column you originally selected. This is Category, Bank, or Location.

·       Go to Appearance à HeaderText. Type in the value field what you want to appear in the header of the table.

For each column that you do this to, you get two more components in the IDE footer.

Do it for the Category column and you get categoryBindingSource and categoryTableAdapter.

Do it for the Location column and you get locationBindingSource and locationTableAdapter.

Do it for the Bank column and you get bankBindingSource and bankTableAdapter.

Now I want to add a textbox that also binds and moves with the TableAdapter navigator. In the Data Sources pane expand ExpensesDataSet and then expand Category. Drag CategoryID onto the form.

Then, select the textbox, right-click and choose Properties. In the Properties window, expand (DataBindings). Select Text. Drop down the value and select CategoryID under checksBindingSource. Notice that the CategoryID changes as you navigate through the table.

Also, note that Update works.  Select a record. Double-click in a field. Edit the field. Then, click on the diskette symbol on the toolbar. Check that the record is updated either by looking in Access itself or by exiting the winform and reinvoking it.

 

10/9/2006 4:44:55 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [6]  |  Trackback
 Thursday, September 21, 2006

Here's the summary for a talk I gave at Portland's Linux Advanced Topics User's Group.

This talk is an introduction to Eclipse 3.2. It assumes that you know what Eclipse is and may even have installed it and cruised its menus, that you have not done anything serious with it, but that you might want to. Eclipse is both an IDE and an RCP (a starting platform for your own applications). Although I'll mention and define RCP, the talk is about using Eclipse as an IDE. I'll show how to use Eclipse to build a simple Java console application. As an IDE, it allows you to add your own plug-ins. The talk will also show how to add a simple plug-in. This talk is cribbed from various books; little if any of it is original.

Here are the notes.

AdvancedTopicsTalkPart1.doc (1.44 MB)

AdvancedTopicsTalkPart2.doc (1.08 MB)
9/21/2006 3:28:16 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Wednesday, September 20, 2006

Here are photos from a hike that I took in the Wallawas last month with a couple of friends.

Photos from hike

9/20/2006 11:12:21 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Saturday, August 05, 2006

More from the CodeCamp talk, fixed up and edited somewhat.

I went to OSCON (just the hall pass) and then to LANG .NET. Both conferences were much fun, and I left excited and motivated. I think it's time to get back into thinking about functional languages! But I'm going backpacking first; Lory stays home this time; she said she could get back into it, but a week on the mountain is too much for a start.

Running the SWT Application Standalone

That last example runs from within Eclipse. How do you run this application outside of Eclipse?

First, you have to set the CLASSPATH variable appropriately.

In addition, you must specify the java.library.path. This is the location of the java native SWT and GTK libraries. These are shared Linux libraries that end in so.

I specify this on the command line.

But this is not enough!

You must also specify the location of the native libraries.

Where are these native libraries?

Remember, when you added SWT to the workspace. This put the directory org.eclipse.swt under your workspace.

But that’s not the only place those libraries exist.

Under the Build Path for the project …

So I could specify java.library.path using those hidden directories, and it works just as well.

8/5/2006 10:45:28 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, July 24, 2006

This is an excerpt from my talk at CodeCamp 2.0 on 7/22.

Adding the Visual Editor

The Visual Editor is in fact a plug-in. And one you’re going to want if you plan to develop a win form.

I understand with Eclipse 3.2, Callisto makes installation simpler. But with 3.1.2, this is what I did. I chose Help à Software Updates à Find and Install.

1.    Select the Search for New features to install. Click Next

2.    Click on the New Remote Site … button and add http://update.eclipse..org/tools/ve/updates/1.0. Name it VE.

3.    Click on the New Remote Site … button and add http://update.eclipse.org/tools/emf/updates. Name it EMF.

4.    Click on the New Remote Site … button and add http://update.eclipse.org/updates/3.0 . Name it Old Eclipse.

5.    Select VE, EMF, and Old Eclipse. Click Finish.

 

 

 

 

How do you know the Visual Editor is installed? Open Eclipse, type Ctrl+N and look under the Java node to see Visual Class.

 

SWT, Swing, AWT

I’m going to show a little example using the Visual editor with SWT.  I don’t have much experience with these GUI libraries. From what I’ve read, I like SWT best, but I understand that Swing has strong adherents. I’d rather respect the differences than argue them.

SWT is the Standard Widget Toolkit. It’s the foundation for the Eclipse user interface from IBM. Originally IBM used Smalltalk internally, but it had deployment and configuration problems.

Sun wanted a portable widget API and wrote AWT, the Abstract Windowing Toolkit. Many considered it overly complex. Sun abandoned AWT in favor of JFC, the Java Foundation Classes, also known as Swing.

AWT suffered from a “lowest common denominator (LCD)” approach. To remain faithful to “write once, run anywhere” AWT offered only features supported by all the native windowing operating systems.

Swing solved the LCD problem by using no native code and no native widgets. Swing has “pluggable look and feels.” By default Swing adopts the native platform’s look and feel.

Some people maintain that Swing has not lived up to its promise. Reasons are speed (actually lack thereof) and look and feel. Swing devotees bristle at these statements. Swing performance has greatly improved (especially with JDK 1.4), but I read that it continues to be somewhat more sluggish than native applications. (I don’t really know; I haven’t done any performance studies.) About the look and feel … well, you can plug in whatever you want, but Swing may always be a step behind the latest GUIs because support for the GUI must be written explicitly into the Java library.

OTI (Object Technology International, who created widget interfaces for OTI Smalltalk and is now part of IBM) set out to create another GUI library and correct the faults of AWT and Swing. This was SWT. It uses native functionality when available, Java implementation when not.

Installing SWT

SWT is distributed as an archive file; I downloaded swt-3.1.2-gtk-linux-x86.zip. Then, open Eclipse and select File à Import … à Existing Projects Into Workspace.

 

 

 

The result is that org.eclipse.swt appears in the Package Explorer.

Writing a Simple Win Form with VE and SWT

Open Eclipse. Select File à New à Project … à Java Project. Click Next. Type in a Project Name and click Next, then Finish.

 

 

In the Package Explorer, under the Project Name, select src, right-click. Select New à Other à Visual Class. Type in a package name and a class name.

 

The class appears in the Visual Editor.

 

Drop down the Bean toolbar. Choose SWT Controls à Button. Release the mouse, then click on the win form. A button appears. Resize it. Then, select the button and right-click. Choose Set Text and type in the text you want to be displayed on the button. Using this same technique, make a textbox.

Then select the button and right-click. Select Events à Add Events … Choose “implements: …” and select Finish.

 

Then, add code in the button handler to write the textbox.

 

Now select the containing package in the Package Explorer and right-click. Choose Run As … à SWT application.

 

 

7/24/2006 9:31:52 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, June 12, 2006

I downloaded Eclipse 3.1.2 and for the last few days have been trying to become familiar with it. I'd like to say becoming proficient, but that's a while yet in the future. I had put it aside for a few days because I was busy studying for and taking a Microsoft Certification Test (70-320, XML Web Services, .Net Remoting, etc.) This is an old test, not part of their new program, but I had been reading about these topics for a while and thought I should get it out of the way. It was a hard test, I thought, probably hard for me because my knowledge of these topics comes mostly from books and not experience. I know it's silly, but I put the certificate I got on my wall; it took a bunch of effort, and I'm proud of it, so don't laugh.

I decided to run Eclipse under Linux (The Ubuntu Breezy edition) because I thought the spirit of Eclipse was more open-source Linux than proprietary Windows. However, the main book I'm looking at assumes you're running Windows. Alas. It's a good book, though eclipse Building Commercial-Quality Plug-ins by Eric Clayberg and Dan Rubel. The book is the second edition and also describes Eclipse 3.2. Now the latest download I got from www.eclipse.org was 3.1.2, and I'm sticking with that. The site discusses a release candidate (RC4), but what I'm doing right now is pretty simple, and I'll stay with 3.1.2 for now. Yes, I will upgrade, but I'm not ready to yet. The same is true with Linux. The new release Dapper Drake just came out, but I'm still running Breezy.

I'm scheduled to give a talk about Eclipse and plug-ins at  Portland Code Camp v2.0. This looks like a fun event, and it's free! I went to v1.0 last year. Check it out at http://pdx.techevents.info/codecamp/2/Default.aspx  .  So this is my reason for not upgrading right now. I have some stuff to prepare and don't want to risk getting my computers stuck in an upgrade. But upgrading is good, and I will do it, probably some time in August.

What I wanted to do was first give an introduction to Eclipse, intended for people who haven't used Eclipse before. You know, you've installed it and now what do all those menus mean and how can you set up a development environment and write a simple project. Then, I wanted to write a simple plug-in and show how to add it to the Eclipse environment.

Yesterday, I spent a bunch of time with CVS. Now I know this isn't the latest and hottest version control system, but my interest was not it using the latest and hottest but to understand how Eclipse integrates with version control. CVS is tried and true, and so my focus could then be on the integration of Eclipse with version control and not on the version control itself.

I discovered that my Ubuntu system didn't have CVS. Strange, I thought. In the old days, you installed Linux and it had everything, more than you wanted, more than you'd ever use. Today you get a stripped-down version (Breezy didn't even come with gcc) and then add what you need as you need it. Better, I think; you end up with a cleaner system, but it requires more effort.

Anyway, with Ubuntu, get eclipse through the Synaptic Packet Manager. Click Apply and it downloads and installs. I thought it curious that the installation asked me to load my original Ubuntu CD, but I save those things, so it was OK.

I've used CVS before, or course, but it's been a while. I dug up an old (but still good) book called Open Source development with CVS by Karl Fogel. I think it's like the CVS classic. (There's a newer edition, and he has a co-author.) I also found directions on the CVS wiki, http://ximbiot.com/cvs/wiki/index.php?title=Main_Page

Here's a short description of what it takes to get CVS working under Ubuntu. The first thing you got to do is make a repository. Remember that the repository is for CVS, not you; it's not a subdirectory of your working directory.  I looked at the directions in Fogel's book and choose to make the repository at /usr/local/cvsroot. I also looked at the Ubuntu forum, and apparently this is not the standard location. But the location doesn't really matter; it just has to be something. I became root and issued the command

cvs -d /usr/local/cvsroot init

Here's the result of that command. Note that a directory called CVSROOT is created under /usr/local/cvsroot, and there are a bunch of CVS files put there. One should leave them alone.

 

About permissions. CVS needs write access to the repository. Fogel recommends (and I did this) that you make a group of CVS users and then assign that group to the repository's group ownership and permissions.

Ubuntu has a nice GUI for making groups.

 

What I found, though, was that I was not a member of that group (checked with the groups command) until I logged off and then on again. I'm sure there's a way of forcing membership without logging off/on, and I fiddled for a while without success.

Also, it's more convenient to set an environment variable called CVSROOT to the repository's location, and the best place (I think) to make that definition is in .bashrc if you're using the bash shell.

Note that I also set an environment variable CVS_RSH, but that's another story. It turns out that this is critical for getting Eclipse to talk with CVS using the method I chose, but that's another story.

The next step was to get a little code project and see if I could check it in and out of CVS successfully. You know, eventually I want to do this with a Java project loaded into Eclipse, but for now, I just wrote a C project under my home directory. I wanted this project to be a little more than “hello world,” though. This meant putting together a toy application that would pull utilities from one directory and have a main program in another.

Now I know there are fancier ways of building applications these days, and I want to look at some of those when I get into Eclipse. But for this test, I relied on that old standard, make. I needed a recursive make and honestly thought I could remember how to do that, but my first attempt failed. I had to find a  book that I discovered years ago, Managing Projects with make by Andrew Oram and Steve Talbott (yes, I still had it).

To add the project to CVS, first delete all executables and and object files and import the project.

 

Here's what results.

 

The key thing to mention here is that although the project is imported, the remaining source files are not a CVS working copy. For example, if you try

cvs log ted001.c

CVS won't know about ted001.c in spite of the fact that it's a member of an imported project. You got to check out the files. Before doing this, I deleted all the source in the sample_project directory under my home. Yes, I was paranoiac enough to make a backup. Then, I checked out the files with (be sure to cd to the parent directory of sample_project before checking out).

cvs checkout sample_project

Then,

cvs log ted001.c

shows two entries: the initial import and the initial revision. I made a trivial change to ted001.c, then tried cvs log ted001.c again and saw the change displayed on my screen. So it appears to be working.

The next task is to get Eclipse talking to CVS. I'm almost there. Getting Eclipse to recognize the repository was not as trivial as the books make it out to be. I'll describe what I did next time.

6/12/2006 10:29:43 AM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [4]  |  Trackback
 Friday, June 02, 2006

Running Eclipse: Windows or Linux?

Well, I chose Linux, the Ubuntu Breezy edition. There's a Windows version, but I think Eclipse is better suited to the Linux environment, but I admit that's a personal opinion. In fact, I'm writing this with Open Office running under Ubuntu.

Installing Eclipse

There's an Eclipse that comes with Ubuntu. Well, I think you actually use gnome-apt-install. It's an icon on the top menu bar. I don't remember whether it's there by default or I put it there. You got to be root to run it. I was not happy with this Eclipse. It appeared to be missing source code, and one of the points of having Eclipse is to look at the source code, not to modify it, but to understand what's going on. I'm going to be interested in adding plugins, and books tell me I should look at source code when I do that.

I downloaded eclipse-SDK-3.1.2-linux-gtk.tar.gz from www.eclipse.org, placed in my directory /home/ted/Eclipse_downloads, unzipped with gunzip, then untarred with tar vxf. There isn't really any configuration. Untarring releases a bunch of files from the tarball, one of which is an executable called eclipse.

Where's the best place to install Eclipse? I don't know.

I run that executable without arguments. I'll add args later, but for now this is it.

Now there's a question of what java I'm using. Inside Eclipse. I can look at Windows-Preferences... and then on the right panel open up java and select Installed JREs. I chose the Sun JDK, which I donwloaded from Sun a while back. I'm not sure what the other JVMs are. One came with Ubuntu, and it doesn't work well with Eclipse. If I use the original java, I can make java programs OK but cannot stop at a breakpoint. I talked with Bill at Padnug about this, and he says this is a known problem, but it's not clear whether it is a java or an eclipse issue. Let's see if I understood this correctly. The JVM signifies when it reaches a breakpoint and some JVMs do it differently than others. Eclipse does not recognize all the variations.

One of my books (I got a bunch on Eclipse that I read all at once; this one is eclipse Distilled by David Carlson) says that “you might have several version of java installed on your computer and you should use the -vm option to specify the one you want to use.” Well, I don't. But the Eclipse IDE itself is telling me what java I'm using.

 

Notice the line on top of the console window. It says /usr/lib/j2sdk1.5-sun/bin/java, the Sun version I installed.

Also, my command window shows java goes there.

ted@halibut:~$ which java

/usr/bin/java

ted@halibut:~$ ls -l /usr/bin/java

lrwxrwxrwx  1 root root 22 2005-12-26 15:32 /usr/bin/java -> /etc/alternatives/java

ted@halibut:~$ ls -l /etc/alternatives/java

lrwxrwxrwx  1 root root 30 2005-12-29 13:46 /etc/alternatives/java -> /usr/lib/j2sdk1.5-sun/bin/java

 

The same links work for javac.

Looking at the Eclipse Source Code

So this is how I did it. I'm reading Contributing to eclipse by Erich Gamma and Kent Beck. This is an excellent book, written by two famous programmers, but it is somewhat out-of-date. Its examples come from an older version of Eclipse, and the screens show windows that we don't have any more.

So this is what I did. Choose File – Import ... Then, select External Plug-ins and Fragments and click Next. Choose to import as Binary projects, which makes the projects read-only. You can still look at the source for binary projects, and you want to look at that source when you add a plug-in of your own. But you don't want to modify any of that source. Click Next again and select Add All ...

The in the Package Explorer, you see a lot of projects. You can use the dropdown menu in the Package Explorer to filter out these plugins and see only your own projects if you want to. But if you leave then there and navigate to a class in one of the plugins, this is what you see. Yes, you can cruise the source code, which is just what I want to do.

 

This is org.eclipse.debug.core. Then open up org.eclispe.debug.core_3.1.2.jar. Then under org.eclipse.debug.core, double-click DebugPlugin.class. The book says to use Navigate – Open Type and put in *, but I haven't had luck with that. The resulting window always shows OK as disabled.

 

6/2/2006 1:13:44 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [0]  |  Trackback
 Monday, May 29, 2006

Well, I’ve been using realvnc (www.realvnc.com), and I think it’s neat. Now granted, I’ve only used it on my local network, which is a workgroup and not a domain; but I like it much more than the Remote Desktop that comes with Windows XP.

The reason I like it better than Remote Desktop is because I can share a desktop among more than one computer. I run Windows XP Pro SP2, and I’ve found that when I connect to another computer with Remote Desktop, my local computer logs off.

What I want is to share a program with multiple computers. You know, I’m running an app and I want three or four friends to also see that app. In fact I want more than that … I want those three or four friends to be able to take control of my app – click a checkbox or click a button. I can do this with realvnc.

We have used gotomeeting (www.gotomeeting.com) for this. Gotomeeting is a great program and works fine over the Internet. And I haven’t tried realvnc over the Internet. I think the cost of gotomeeting is reasonable. It’s about $50/month, but realvnc has a free version.

There are for-pay versions of realvnc. On their website you can compare features. The personal edition does encryption and file transfer along with some other features that I don’t understand like “one-port HTTP & VNC” and “Desktop Scaling.” The cost is reasonable (about $30 for each server site). I have not tried running the viewer on a site that does not have the server.

Gotomeeting has a messaging capability that realvnc lacks (or I haven’t found it.) This is not a big loss for me. We like to use Skype (www.skype.com) for voice communication anyway. BTW, Skype works really well over broadband and over the free wireless I can pick up in various coffee shops, but it worked terribly with PeoplePC. I had dialup PeoplePC for a while and was not impressed with its performance and got somewhat irritated with its silly user interface.

When I first started using realvnc, I was not able to share a desktop with several computers. When another viewer connected to my VNC server, the computer with the previous view lost its connection. Easily fixed, though, you got to configure the VNC viewer to have a shared connection. To do this open the viewer and click on Options before you connect to the VNC server. Then, under the Misc tab, choose “Shared connection…”

 

Here’s a screenshot of one of my computers running the viewer and connection to another of my computers running the server.

 

Now admittedly I have not tried this over the Internet yet. I don’t know what kind of problems firewalls and NAT routers will give me, but so far I really like realvnc.

Anyone else using it?

5/29/2006 3:04:17 PM (Pacific Daylight Time, UTC-07:00)  #    Disclaimer  |  Comments [4]  |  Trackback