Friday, January 04, 2008

Cheat Sheet Extensibility - Part 2

Oops.

I forgot to mention one of the little tricks required to make the cheat sheet actually usable - you need to be able to signal it's completion :-)

There are a few things required to make this happen:
  1. the task requires a UI control which allows the user to signal that the task is complete. I used a form hyperlink control, similar to the following:
    ImageHyperlink link = toolkit.createImageHyperlink(
    form.getBody(),
    SWT.WRAP);
    Image img = AbstractUIPlugin.imageDescriptorFromPlugin(
    Activator.PLUGIN_ID, "/icons/complete_task.gif").createImage();
    link.setImage(img);
    link.addHyperlinkListener(this);
  2. a reference to the task being edited must be obtained. Fortunately, this is made available when the setInput method is called. In this method, use some code like this:

    public void setInput(IEditableTask _task, IMemento memento) {
    task = _task;
    }
  3. attach a listener to the control


  4. when the link is activated, your listener will be fired. When this happens, the task should be set to complete. This is then just a simple method call using the task instance which has already been saved:

    task.complete();

No comments: