/**
   * Initialize the composite with pre-existing values.
   *
   * @param ruleWrapper the {@link RuleWrapper}.
   */
  public void init(RuleWrapper ruleWrapper) {
    PointSymbolizerWrapper pointSymbolizerWrapper =
        ruleWrapper.getGeometrySymbolizersWrapper().adapt(PointSymbolizerWrapper.class);

    mainComposite = new Composite(parent, SWT.RESIZE);
    mainComposite.setLayout(new GridLayout(2, false));
    mainComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    Label fontLabel = new Label(mainComposite, SWT.NONE);
    fontLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    fontLabel.setText("Font:"); // $NON-NLS-1$

    fontCombo = new Combo(mainComposite, SWT.DROP_DOWN | SWT.READ_ONLY);
    fontCombo.setItems(getScalableFonts());
    fontCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));

    String characterPath = pointSymbolizerWrapper.getMarkName();
    if (characterPath != null && characterPath.matches("ttf://.+#.+")) { // $NON-NLS-1$
      String[] fontElements = characterPath.substring(6).split("#"); // $NON-NLS-1$
      int index = fontCombo.indexOf(fontElements[0]);
      if (index != -1) {
        fontCombo.select(index);
        characterCode = fontElements[1].substring(2);
      } else {
        fontCombo.select(0);
        characterCode = Integer.toHexString(PLUS_SIGN);
      }
    } else {
      fontCombo.select(0);
      characterCode = Integer.toHexString(PLUS_SIGN);
    }

    fontCombo.addSelectionListener(this);
    fontName = fontCombo.getItem(fontCombo.getSelectionIndex());

    table = new Table(mainComposite, SWT.VIRTUAL | SWT.BORDER | SWT.V_SCROLL | SWT.SIMPLE);
    GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
    gridData.horizontalSpan = 2;
    gridData.heightHint = 300;
    table.setLayoutData(gridData);
    table.setLinesVisible(true);
    table.setRedraw(false);
    Font font = new Font(Display.getCurrent(), fontName, FONT_SIZE, SWT.NORMAL);
    table.setFont(font);

    table.addListener(
        SWT.SetData,
        new Listener() {
          java.awt.Font awtFont = (new java.awt.Font(fontName, java.awt.Font.PLAIN, FONT_SIZE));

          @Override
          public void handleEvent(Event event) {

            final TableItem item = (TableItem) event.item;
            final int index = table.indexOf(item);
            final int ch = +FIRST_CHAR;

            // set a loading message
            item.setText(0, "..."); // $NON-NLS-1$

            Job load =
                new Job("Loading font icon") {

                  @Override
                  protected IStatus run(IProgressMonitor monitor) {

                    Display.getDefault()
                        .syncExec(
                            new Runnable() {

                              public void run() {

                                int character = ch + (index * COLUMNS);

                                for (int cel = 0; cel < COLUMNS; cel++) {

                                  if (character < CHARACTERS) {
                                    if (character > 0xFF && !awtFont.canDisplay(character)) {
                                      item.setText(cel, ""); // $NON-NLS-1$
                                    } else {
                                      item.setText(cel, characterString[character]);
                                    }
                                  }

                                  character++;
                                }
                              }
                            });

                    return Status.OK_STATUS;
                  }
                };

            load.schedule();
          }
        });

    for (int i = 0; i < COLUMNS; i++) {
      new TableColumn(table, SWT.NONE);
    }

    initializeCharacterStringArray();
    table.setItemCount(CHARACTERS / COLUMNS);

    table.getColumn(0).pack();
    int width = table.getColumn(0).getWidth();
    for (int i = 1; i < COLUMNS; i++) {
      table.getColumn(i).setWidth(width);
    }

    // Set redraw back to true so that the table
    // will paint appropriately
    table.setRedraw(true);
    //
    tableCursor = new TableCursor(table, SWT.NONE);
    tableCursor.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));

    int index = Integer.parseInt(characterCode, 16);
    int row = index / COLUMNS - 4;
    int col = index % COLUMNS;
    tableCursor.setSelection(row, col);
    tableCursor.setFont(font);
    tableCursor.addSelectionListener(this);

    characterLabel = new Label(mainComposite, SWT.NONE);
    characterLabel.setText(LABEL_PREFIX + characterCode + "      "); // $NON-NLS-1$
  }
  public static void main(String[] args) {
    Display display = new Display();
    Shell shell = new Shell(display);
    shell.setText("Table Cursor Test");

    shell.setLayout(new FillLayout());

    final Table table = new Table(shell, SWT.SINGLE | SWT.FULL_SELECTION);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    for (int i = 0; i < 5; i++) {
      TableColumn column = new TableColumn(table, SWT.CENTER);
      column.setText("Column " + (i + 1));
      column.pack();
    }

    for (int i = 0; i < 5; i++) {
      new TableItem(table, SWT.NONE);
    }

    final TableCursor cursor = new TableCursor(table, SWT.NONE);

    final ControlEditor editor = new ControlEditor(cursor);
    editor.grabHorizontal = true;
    editor.grabVertical = true;

    cursor.addSelectionListener(
        new SelectionAdapter() {
          // This is called as the user navigates around the table
          public void widgetSelected(SelectionEvent event) {
            // Select the row in the table where the TableCursor is
            table.setSelection(new TableItem[] {cursor.getRow()});
          }

          // This is called when the user hits Enter
          public void widgetDefaultSelected(SelectionEvent event) {
            final Text text = new Text(cursor, SWT.NONE);
            text.setFocus();
            // Copy the text from the cell to the Text control
            text.setText(cursor.getRow().getText(cursor.getColumn()));
            text.setFocus();
            // Add a handler to detect key presses
            text.addKeyListener(
                new KeyAdapter() {
                  public void keyPressed(KeyEvent event) {
                    switch (event.keyCode) {
                      case SWT.CR:
                        cursor.getRow().setText(cursor.getColumn(), text.getText());
                      case SWT.ESC:
                        text.dispose();
                        break;
                    }
                  }
                });
            editor.setEditor(text);
          }
        });

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) {
        display.sleep();
      }
    }
    display.dispose();
  }