20091214

Cycle Mode 2009

I went to Cycle Mode 2009, a biggest bicycle exhibition, like a motor show, at Makuhari Messe.
(I forgot to bring my camera...)
I test-rode a few bikes: a few rode bikes, a recumbent, and a battery bike.

Now that bicycle is very in fashion, there are so many visitors that sometimes I have to wait for tens of minutes for a ride. What I newly know today is that Bridgestone established their brand, anchor, and Daisuke Imanaka, the first ever Tour-de-France Japanese rider, founded his new trading company Interfax to introduce really nice bikes and parts to Japanese riders.
I hope Japan will become nice country for cyclists and recover Japanese self-sufficiency ratio of bicycle.

Ostrich presenter demonstrated how to disassemble a bike and put the parts into a carry bag (輪行袋). It was easier than I imagined. I'm sure I will buy a bag. I might also buy a helmet; OGK's helmet is designed for Japanese.

Those who I went with were far more knowledgeable and interested in bikes. They said they would come to the show again.

After that I had Japanese sake with them. I like Denshu (田酒) for its standard taste.
Dassai 23% (獺祭 磨き二割三分) was super rich.
I thank them for inviting me for the show and drinking!

20091210

Table Event Handler

I made a code to handle button events and click event to edit the contents set to an SWT TableViewer. Sadly, however, my code was not adapted to my project officially.
I would like to put it here after generalizing confidential parts.

All you have to do is to create your own inherited handler by overriding newTableElement() and editTableElement() methods and set the table and the buttons to your handler.



package com.example.dialog.handler;

import java.util.ArrayList;
import java.util.List;

import metamodeling.generic.kernel.UMLNamedElement;
import metamodeling.generic.kernel.UMLNamespace;

import org.eclipse.emf.common.util.EList;
import org.eclipse.jface.viewers.DoubleClickEvent;
import org.eclipse.jface.viewers.IDoubleClickListener;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;

public abstract class TableEventHandler {

   private Button        newButton;
   private Button        editButton;
   private Button        removeButton;
   private Button        upButton;
   private Button        downButton;
   IStructuredSelection  selection;
   TableViewer           viewer;
   List<Integer>         indexes = new ArrayList<Integer>();

   public void setNewButton(Button newButton) {
       this.newButton = newButton;
       this.newButton.addSelectionListener(new SelectionAdapter() {
           public void widgetSelected(SelectionEvent e) {
               newTableElement();
           }
       });
   }

   public void setEditButton(Button editButton) {
       this.editButton = editButton;
       this.editButton.addSelectionListener(new SelectionAdapter() {
           public void widgetSelected(SelectionEvent e) {
               editTableElement();
           }
       });
   }

   public void setRemoveButton(Button removeButton) {
       this.removeButton = removeButton;
       this.removeButton.addSelectionListener(new SelectionAdapter() {
           public void widgetSelected(SelectionEvent e) {
               removeTableElement();
           }
       });
   }

   public void setUpButton(Button upButton) {
       this.upButton = upButton;
       this.upButton.addSelectionListener(new SelectionAdapter() {
           public void widgetSelected(SelectionEvent e) {
               for (int i = 0; i <= indexes.size() - 1; i++) {
                   getElements().move(indexes.get(i) - 1, indexes.get(i));
               }
               viewer.setSelection(selection, true);
           }
       });
   }

   public void setDownButton(Button downButton) {
       this.downButton = downButton;
       this.downButton.addSelectionListener(new SelectionAdapter() {
           public void widgetSelected(SelectionEvent e) {
               for (int i = indexes.size() - 1; i >= 0; i--) {
                   getElements().move(indexes.get(i) + 1, indexes.get(i));
               }
               viewer.setSelection(selection, true);
           }
       });
   }

   private EList<UMLNamedElement> getElements() {
       return ((UMLNamespace) viewer.getInput()).getTheContainedElements();

   }

   public void setViewer(TableViewer viewer) {
       this.viewer = viewer;
       viewer.addSelectionChangedListener(new ISelectionChangedListener() {

           public void selectionChanged(SelectionChangedEvent event) {
               if (event.getSelection() instanceof IStructuredSelection) {
                   selection = (IStructuredSelection) event.getSelection();
                   if (selection.size() < 1) {
                       if (editButton != null)
                           editButton.setEnabled(false);
                       if (removeButton != null)
                           removeButton.setEnabled(false);
                       if (upButton != null)
                           upButton.setEnabled(false);
                       if (downButton != null)
                           downButton.setEnabled(false);
                   } else {
                       if (upButton != null && downButton != null) {
                           indexes.clear();
                           for (Object each : selection.toList()) {
                               indexes.add(getElements().indexOf(each));
                           }

                           if (indexes.get(0) > 0) {
                               upButton.setEnabled(true);
                           } else {
                               upButton.setEnabled(false);
                           }
                           if (indexes.get(indexes.size() - 1) < getElements()
                                   .size() - 1) {
                               downButton.setEnabled(true);
                           } else {
                               downButton.setEnabled(false);
                           }
                       }

                       if (selection.size() == 1) {
                           if (editButton != null)
                               editButton.setEnabled(true);
                           if (removeButton != null)
                               removeButton.setEnabled(true);
                       } else if (selection.size() > 1) {
                           if (editButton != null)
                               editButton.setEnabled(false);
                           if (removeButton != null)
                               removeButton.setEnabled(false);
                       }
                   }
               }
           }
       });

       viewer.addDoubleClickListener(new IDoubleClickListener() {

           public void doubleClick(DoubleClickEvent event) {
               if (event.getSelection() instanceof IStructuredSelection) {
                   selection = (IStructuredSelection) event.getSelection();
                   editTableElement();
               }
           }
       });
   }

   protected Object getFirstSelectedElement() {
       return selection.getFirstElement();
   }

   protected abstract void newTableElement();

   protected abstract void editTableElement();

   protected void removeTableElement() {
           getElements().remove(getFirstSelectedElement());
   }
}

20091202

My Girl (2)

After a little investigation, I know that the composer of the song "My Girl" respects KAN very much.
http://www.tadashinya.com/profile.html

I guess that's why the melody makes me feel nice.