Archive

Posts Tagged ‘Software Development’

Writing an Eclipse Plug-in (Part 15): Custom Project: Customizing the Perspective Menus (Main menu)

December 19, 2009 5 comments

Ah! Nothing like returning to the scene of the crime.

When we were last at the crime scene we were displaying projects in the Custom Navigator in various states of openness and closedness. What could possibly be next? Well, there are a few choices:

  • Customize the Custom Perspective so our current capabilities are available in the main workspace menu, toolbar and Customize Perspective window.
  • Add navigator popup menus to do things like New, Copy and Properties
  • Display information in the project structure

Even though I expect to create a Form-based editor to hide the ugliness of an XML file that is not necessarily the task of greatest import. In this post I am going to show how to add menu items to our Custom Perspective; we will customize the Custom Navigator popup menu in a future post.

We should always be implementing with the end in mind as a way of keeping extraneous features to a minimum anyway. At least that’s my story.

What (are we doing?)

There are about 7 ways to do almost anything in Eclipse. For example, if you want to open the New Wizard you could go about doing that in the following ways:

  1. Ctrl+N
  2. Main menu: File –> New
  3. Shift+Alt+N – opens the popup menu; select New
  4. Right click on a Project and select New
  5. Right click on a Folder and select New
  6. Toolbar: New button
  7. Toolbar: Java Class button: New: JUnit Test, Class, Interface, Enum, Annotation

And those were just the ones I thought of off the top of my head (okay, so maybe I tried them all first…).

So, in order to compete with all of the other plug-ins out there a plug-in developer has to make sure there are at least a minimum of ways to activate their plug-in: CRUD functionality (New, Open, Save, Delete), opening editor(s) and view(s), open the Properties window, etc.

The good news: Ctrl+N and Shift+Alt+N open the New Wizard window in every case (unless you change the key bindings) so we can safely ignore them.

The bad news: we only have a New Wizard for Custom Projects and two file types. This means that the only way to create a custom resource is either from the main menu (File –> New –> Other), Ctrl+N, or Shift+Alt+N. Since all three will activate the default New Wizard we have not gained anything.

The lesson to learn here is when you add something to the New Wizard your task list should include updating your perspective to support the:

  • Main Menu File menu
  • Toolbar
  • Customize Perspective window

Notice how the only thing this will do is make your existing behavior available in more places. Not a bad thing, just kinda extraneous; convenient for the user, feels like busy work for the developer.

You could also decide to add your GUI functionality to all of the perspectives, but beware: each perspective is specific to the task at hand. Adding the ability to do random things in arbitrary perspectives is bad form. Add functionality to specific perspectives as appropriate (what that means will vary with the capability you are implementing). Adding plugin.xml to a COBOL project doesn’t really mean anything. The road to menu pollution is paved with good intentions. Don’t be afraid to create custom perspectives where you can just go to town adding whatever you want with impunity.

So the tasks for the next few blogs are to add:

  • In the main menu: add Custom Projects, Schema, and Deployment files to File –> New
  • In the Toolbar: add a toolbar group for the above 3 items
  • In Customize Perspective: add the ability to enable/disable all of the above

In the Customize Perspective window adding the ability to enable/disable the above capabilities means:

  • Toolbar Visibility: Custom Project Element Creation (enable by default)
    • Custom Project
    • Schema File
    • Deployment File
  • Menu Visibility: File –> New, (already available, enable by default)
    • Custom Project
    • Schema File
    • Deployment File
  • Command Group Availability: Custom Project Element Creation (enable by default)
  • Shortcuts (affects Menu Visibility; enable by default)
    • New
      • Custom Project
      • Schema File
      • Deployment File
    • Open Perspective (Affects main menu Windows –> Open Perspective)
      • Resource (available, but not enabled)
    • Show View (Affects main menu Windows –> Open View)
      • Custom Plug-in Navigator (available, but not enabled)

How (are we doing it?)

In the main menu: add Custom Projects, Schema, and Deployment files to File –> New

Adding New Wizard entries onto the menu menu is done completely by configuration (my favorite).

  1. Open up plugin.xml for customplugin
  2. Go to Extensions–> Add –> perspectiveExtension and click Finish (yes, you could skip this step and use the existing perspectiveExtension entry)
  3. Change
    • targetID: *

    to

    • targetID: customplugin.perspective
  4. Right click on customplugin.perspective (perspectiveExtension) –> new –> newWizardShortcut
  5. Select newWizardShortcut and enter:
    • ID: customplugin.wizard.new.custom
    • The above is the id of the New Custom Project Wizard entry under org.eclipse.ui,newWizards –> Custom Project (wizard)
  6. Perform steps 4 and 5 for the Schema File (wizard) and Deployment File (wizard)
  7. Save plugin.xml

To make them appear in all of the perspectives change (do not try this at home. I am a trained professional):

  • Extensions –> perspectiveExtension –> targetID: customplugin.perspective

to

  • Extensions –> perspectiveExtension –> targetID: *

Remember, only you can prevent menu pollution.

As a wonderful side-effect the Customize Perspective window has the three New wizard entries entered automatically. Start the runtime workbench, open the Customize Perspective window (Windows –> Customize Perspective), select Menu Visibility and open File –> New.

In addition select the Shortcuts tab of the Customize Perspective window and see that for Submenu New the Shortcut Category has Custom Wizards selected and the three wizards are already checked.

The Toolbar tab and the Command Groups Availability tab are both devoid of entries for our Custom Project. Are we going to take care of that now? Well…no. Next time. Really. I know you’re disappointed, but if you push me I’ll make sure you get a lump of coal.

What Just Happened?

Configuration. Nothing like it for tedious tasks.

How much code did we write: none. It is going to be a good holiday.

Well, that’s it for this entry. It is Sunday, the holidays are getting closer and I was lucky to get this post out.

Next time: Adding the New Wizard functionality to the Toolbar. Maybe. If I get a Sega R-360.

Yuletide Felicitations!

Getting Sued into Professionalism

August 28, 2008 2 comments

I recently had a conversation about software development. Well, truth be told, I have conversations about software development all the time, but this one was a conversation I had been thinking about for a long time: why does so much software stink? And how do we fix that?

Typically, when anyone discusses the state of software development the use of tools, management practices, etc always get tossed about and everyone walks away feeling like the problem will be solved one day by the brute force of our backs (our brains, really) as we devour the elephant one bite at a time or climb the mountain one step at a time or however it is you feel like thinking about it.

A few years ago I realized that there will never be a tool or collection of tools that will solve this problem. The problem is not technology; it is people. Developers who inflate their abilities; managers who think managing a software team is the same as leading a squad of Green Berets into battle. This was going to take a more extreme solution that everyone is going to fight, well most would fight, but would take care of the quality problem once and for all. In some cases, the problem might get worse, but overall things will be better. Money will be spent to make sure that software works, developers have the background they need, certifications will mean something and a certain amount of prestige will come to the work of development and developers.

The solution to the software problem will be solved by… lawyers.

Yes, you read that right. Lawyers. The guys about whom Mario Puzo once said “A lawyer with a briefcase can steal more than a thousand men with guns.” In order to see how this is going to work I need to go into a little history and talk about that other profession folks love to malign (no, not accountants): doctors.

It is easy to forget that, in the United States, about a hundred years ago anyone could profess to be a doctor (at least that was true in the US. The Islamic world had a medical school before 872 AD). While a hundred years may sound like a long time in the grand scheme of things it might as well be yesterday. Even though the University of Pennsylvania School of Medicine, which began by giving lectures on anatomy in 1765, was one of the first schools to offer a medical degree the number of unlicensed/bogus physicians was quite high due to the general public having a deep-seated mistrust of experts. Kind of like today.

The road from charlatan to professional for the medical profession was a long, hard and ugly one; some would say that the fight is still going on, but very few would want to return to the days of unlicensed doctors no matter what you think of HMOs or malpractice insurance. If anyone could become a doctor they would (who wouldn’t want the money or the prestige?). So what keeps every well-meaning or discontented or idiotic person from practicing medicine? Perhaps the lure of homeopathy as a career? No, it is the same thing that keeps every well-meaning or discontented or idiotic person from practicing civil engineering: the law and, by extension, lawyers. Paying incredible fines and/or prison terms are a fantastic deterrent to fraud even if it doesn’t always work.

Do individual doctors, civil engineers, and accountants go to jail for fraud? Sometimes, but usually it is their employers who primarily pay the price: hospitals, construction firms and accounting firms pay the fines and they are never happy about it. Sometimes they even lose certifications so that the firm is no longer allowed to do business in their respective domains. Is this a happy ending? Of course not, but in our society it would appear that fines and jail time are a great way to get people to do the right thing. Not always, but usually.

So how does great medicine get done? Really, only two ways: you either pay a lot for it or you have a cadre of great practitioners who just get it right. Expensive or done by superstars.

Yeah, yeah, health care can be reasonably priced in countries outside the US, but we don’t have enough data points to determine if that sort of model holds up over time. I hope it does, but I don’t know and I am glad that there are countries willing to fund the experiment to find out.

So what we have are professions where the standards are so high that anyone who attempts to enter the field finds that the bar is set quite high. To some extent that is what defines a professional (well, other than doing a job for money): someone who has a skill or knowledge that places them in a position where their skill or knowledge is needed for very specialized work. Yes, plumbers and carpenters fit this definition, but I would like to concentrate on those professions that require higher education to achieve the skill and knowledge that is required.

What does this have to do with software development? Most of you have already figured it out: when bug-ridden software is released into the open market no one wins. Is it possible to release software with few or no bugs? Of course, just ask the guys who develop software for the space shuttle. “But isn’t that expensive?” I hear you say. Damn straight.

Great software only comes in two flavors: expensive or written by superstars. Sounds suspiciously like medicine. Or law. Or accounting. Or any of a number of other professions where the practitioners can be sued into the ground. It beats being tarred and feathered, but not by much.

But what about hackers (the good kind)? Can we expect folks who are writing software for the fun of it to be held responsible for writing software that someone else uses improperly? Perhaps, but if we think of developers today as the first doctors of a hundred or so years ago we know that as time progresses software will only become more and more ubiquitous and the effect of freely distributed software will be akin to the creation of medicine that has not had the benefit of FDA approval: it might work, or it might not, but it will be up to the user to decide if they want to take that chance. And if that medicine causes someone harm the maker of that medicine is held responsible (as opposed to someone deciding that taking some Liquid Plumber will help their digestion. You can’t hold the makers of LP responsible for someone else’s basic idiocy).

This is not a diatribe against open source software. Let me say that again.

This is not a diatribe against open source software. Far from it.

I am against companies that put out junk software for any reason. While the quality of open source software has been debated, and I don’t want to do that right now, the one thing we know is that when a company releases software that causes records to be lost, or leaves security holes where private information can be stolen, no one wins. Skyscrapers would not be built with the regularity that they are today if there was not the threat of prison if they came down with the same regularity. The same goes for bridges and anything else where there is the chance of losing gobs of money or lives. Yes, there is corruption and painful growing pains as a field that is not in a position to be sued suddenly finds itself in front of Judge Judy or Judge Scalia and has to explain why there are no industry standards for how their members are trained and held responsible when things go wrong that could have been avoided.

In defense of open source developers: I know they don’t have money. And they mean well. I am writing this using OpenOffice on a Kubuntu distribution on a WordPress blog. I love working on a Unix variant using tools that absolutely awesome developers have built giving up valuable time and effort to make it possible for me to accomplish the simple task of putting my thoughts on (virtual) paper so that I can say that as software developers, if we want to move to that next level of career maturity, not to mention money, we have to be in a position where we can be sued for doing a bad job.

But that is just me.

Thanks to Andrew Wardly for his comments.