org.vishia.gral.swt

## Class SwtTable

- java.lang.Object
- - org.vishia.gral.base.GralWidget.ImplAccess
  - - org.vishia.gral.base.GralTable.GraphicImplAccess
    - - org.vishia.gral.swt.SwtTable

- All Implemented Interfaces:
    java.util.EventListener, org.eclipse.swt.events.FocusListener, org.eclipse.swt.internal.SWTEventListener, GralWidgImpl_ifc, Removeable

      public class SwtTable
      extends GralTable.GraphicImplAccess
      implements GralWidgImpl_ifc, org.eclipse.swt.events.FocusListener

  Implementation of the GralTable for Swt graphic. The following schema shows the aggregation relations, see `Docu_UML_simpleNotation`:

                            |--widgg----------------->GralWidget<|-------+
                            |                             |              |
                  +--|>GralWidget.ImplAccess<--widgImpl---|              |
                  |                                                      |
                  |                                                      |
          +-|>GralTable.GraphicImplAccess                                |
          |                   |                                          |
       SwtTable               |                                     GralTable
          |                   |                                          |
          |                   |<-------------------------------------gi--|
          |                   |                                          |
          |                   |<&>-------------------------------------&>|
          |                        access to all protected methods and fields of GralTable
          |
          |
          |
          |---swtWidg----->SwtWidgetHelper
          |                       |
          |                       |
          |                       |--widgetSwt--->Control<|---Composite<|---SwtTable.Table
          |                                                      |               |
          |---cellsSwt--------------*>Text<*---------------------|            some Listener
          |
          |

  - The `GralTable` contains some implementation-non-specific things, most of table structure.
  - To access from this class to the GralTable, the inner class `GralTable.GraphicImplAccess` is used as super class of SwtTable with protected access.
  - The GralTable knows this class via the interface `GralWidgImpl_ifc` in its superclass association `GralWidget._wdgImpl`.
  - The GralTable knows this class via `GralTable.gi` association with the proper type.
  - The `GralTable.GraphicImplAccess` defines some abstract methods which are implemented here.
  - But some implementations of `GralWidgImpl_ifc` is found in `SwtWidgetHelper`. That are unique implementations, reuse it!
  - Therefore for reused implementations this class delegates the interface to `swtWidgHelper`.
  - The Swt widget core implementation is `SwtTable.Table` which is derived from `Composite`. That Composite contains some text fields which are the visible rows and columns of the table.
  - The text fields are created as children of the swt.widgets.Composite but associated in this class: `cellsSwt`. Therefore this class can access the visible rows and columns directly, using as `Text`.
  - The inner class `SwtTable.Table` is necessary only as implementor of `GralWidgetGthreadSet_ifc`. But that is an `Deprecated` interface. It is possible to replace it later with an simple instance of Composite.
  - The content of the table itself is stored in an array of `GralTable#tableLines`, see description of `GralTable`.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `(package private) static class` | `SwtTable.ActionUserMenuItem` This class wraps the `GralUserAction` for a menu action for the table.
    `private class` | `SwtTable.FocusListenerTable` Debug: this focus listener is not invoked any time.
    `private class` | `SwtTable.MousePressedListenerTable`
    `(package private) class` | `SwtTable.MouseWheelListenerTable`
    `private class` | `SwtTable.Table` The SWT-Composite for the cell texts and the scroll bar.
    `(package private) class` | `SwtTable.TableKeyListerner` A Table is completed with a special key listener.
    `private class` | `SwtTable.Vscrollbar` The widget for the vertical scroll bar is a canvas with a special paint routine.
    `private class` | `SwtTable.XXXFocusListenerCell` An instance of this is associated to any cell of the table.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `private org.eclipse.swt.widgets.Text` | `cellInFocus`
    `private org.eclipse.swt.widgets.Text[][]` | `cellsSwt` Some SWT Text Control fields.
    `(package private) org.eclipse.swt.graphics.Color` | `colorBackVscrollbar`
    `(package private) org.eclipse.swt.graphics.Color` | `colorSliderVscrollbar`
    `private org.eclipse.swt.events.FocusListener` | `focusListenerTable`
    `private SwtTable.MousePressedListenerTable` | `mousePressedListener`
    `private SwtTable.MouseWheelListenerTable` | `mouseWheelListener`
    `private SwtTable.TableKeyListerner` | `myKeyListener`
    `(package private) org.eclipse.swt.events.ControlListener` | `resizeListener`
    `protected SwtKeyListener` | `swtKeyListener`
    `protected org.eclipse.swt.widgets.Text` | `swtSearchText` SWT Text Control which contains a search text.
    `private SwtWidgetHelper` | `swtWidgHelper` It contains the association to the swt widget (Control) and the `SwtMng` and implements some methods of `GralWidgImpl_ifc` which are delegate from this.
    `(package private) org.eclipse.swt.events.TraverseListener` | `traverseListenerTable`
    `static java.lang.String` | `version` Version and history 2018-01-07 Hartmut new: `getCellTextFocus()` 2015-08-29 Hartmut chg: It has a `traverseListenerTable` now to accept 'tab' and 'sh-tab' as normal key instead usage to traverse between the text fields of a table.
    `private org.eclipse.swt.widgets.Canvas` | `vScrollBar`

    - ### Fields inherited from class org.vishia.gral.base.GralTable.GraphicImplAccess

      `bFocused, bFocusLost, bRedrawPending, bVscrollbarChanged, cells, chgEditableColumn, columnPixel, ixColorScrollbar, ixColorScrollbarLast, linePixel, mousect, mousetime, nrofColumnTreeShift, outer, redrawct, redrawtime, xpixelCell, xPixelUnit, XXXhasFocus, xyVscrollbar, y1Scrollbar, y2Scrollbar`

    - ### Fields inherited from class org.vishia.gral.base.GralWidget.ImplAccess

      `chgBitsDerived, chgColorBack, chgColorLine, chgColorText, chgEditable, chgFloat, chgFocus, chgFont, chgIntg, chgInvisible, chgObjects, chgPos, chgText, chgVisible, chgVisibleInfo, pixBounds, wdgimpl, widgg`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `SwtTable(GralTable<?> gralTable, SwtMng mng, org.eclipse.swt.widgets.Composite parent)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods
    Modifier and Type | Method and Description
    --- | ---
    `static GralTable` | `addTable(GralTable gralTable, SwtMng mng, java.lang.String sName, int height, int[] columnWidths)` Deprecated. Create an instance of `GralTable` and call
    `protected GralMenu` | `createColumnMenu(int column)` Should be implemented by the implementation class.
    `(package private) static void` | `createTable(GralTable<?> gralTable, SwtMng mng)`
    `protected void` | `drawCellContent(int iCellLine, GralTable.CellData[] cellLine, GralTable.TableLineData line, GralTable.LinePresentation linePresentationP)` This routine implements all things to set the content of any table cell to show it.
    `protected GralTable.CellData` | `drawCellInvisible(int iCellLine, int iCellCol)`
    `void` | `focusGained(org.eclipse.swt.events.FocusEvent ev)` Focus listener implementation for all cells.
    `void` | `focusLost(org.eclipse.swt.events.FocusEvent ev)` Focus listener implementation for all cells.
    `protected java.lang.String` | `getCellText(GralTable.CellData cell)` Gets the current text of the given cell from the graphic implementation.
    `protected java.lang.String` | `getCellTextFocus()` Gets the cell text from the focused cell in the implementation.
    `GralRectangle` | `getPixelPositionSize()`
    `protected int` | `getVisibleLinesTableImpl()`
    `java.lang.Object` | `getWidgetImplementation()` Returns the implementation class of the widget.
    `protected void` | `initSwtTable(org.eclipse.swt.widgets.Composite swtTable, int zColumns, SwtMng mng)`
    `protected void` | `keyPressed(org.eclipse.swt.events.KeyEvent keyEv)`
    `protected void` | `mouseDouble(org.eclipse.swt.events.MouseEvent ev)` Called internal from mouse event only.
    `protected void` | `mouseDown(org.eclipse.swt.events.MouseEvent ev)` Called internal from mouse event only.
    `protected void` | `mouseUp(org.eclipse.swt.events.MouseEvent ev)` Called internal from mouse event only.
    `private void` | `paintVscrollbar(org.eclipse.swt.graphics.GC gc, org.eclipse.swt.widgets.Canvas canvas)`
    `private void` | `redrawTableWithFocusedCell(org.eclipse.swt.widgets.Widget cell)` Sets the current cell as focused with the focus color.
    `boolean` | `remove()` Removes all referenced data, close all opened resources, removes all graphical widgets etc.
    `void` | `removeWidgetImplementation()` Removes the graphical widgets.
    `void` | `repaintGthread()` TODO implement in `GralTable.GraphicImplAccess`
    `GralColor` | `setBackgroundColor(GralColor color)`
    `protected void` | `setBoundsCells(int treeDepthBase, int zLineVisible)` Invoked in `GralTable.GraphicImplAccess.resizeTable(GralRectangle)` as action which should be implemented in the implementation layer.
    `void` | `setBoundsPixel(int x, int y, int dx, int dy)`
    `private void` | `setColorsSwt()`
    `protected void` | `setDragEnable(int dragType)` Implementation routine to set receiving a drag event and initializes the drag feature of the widget.
    `boolean` | `setFocusGThread()` Sets the focus to the current cell of the tab
    `GralColor` | `setForegroundColor(GralColor color)`
    `(package private) void` | `setTextToLine(org.eclipse.swt.widgets.Text widgSwt)` Invoked on `swtKeyListener` if enter.
    `void` | `setVisibleGThread(boolean bVisible)` Sets the implementation widget(s) visible state.
    `(package private) void` | `stop()`
    `boolean` | `XXXsetVisible(boolean visible)`

    - ### Methods inherited from class org.vishia.gral.base.GralTable.GraphicImplAccess

      `bChangedLinesForCell, bChangedLinesForCell, bColumnEditable, checkAndUpdateText, colorBackTable, colorBackVscrollbar, colorLineVscrollbar, colorSelectChars, colorSelectCharsBack, columnWidthsGral, determineSizeAndPositionScrollbar, focusGainedTable, focusLostTable, itsMng, ixColumn, mouseDoubleGral, mouseDownGral, mouseUpGral, processKeys, redrawTableWithFocusedCell, resizeTable, searchChars, setCellText, setFocusCellMousePressed, updateGraphicCellContent, zColumn`

    - ### Methods inherited from class org.vishia.gral.base.GralWidget.ImplAccess

      `acknChanged, actionShow, dyda, getActionChange, getChanged, gralWidgetFromImplData, setDropEnable, setFocused, setTextChanged, setVisibleState, XXXfocusGained`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### version

          public static final java.lang.String version

      Version and history
      - 2018-01-07 Hartmut new: `getCellTextFocus()`
      - 2015-08-29 Hartmut chg: It has a `traverseListenerTable` now to accept 'tab' and 'sh-tab' as normal key instead usage to traverse between the text fields of a table. TODO: What traversing functions are missing yet? They should not any traverse function between the cells.
      - 2013-06-29 Hartmut chg: refactoring. Now a GralTable can be created before the graphic is build. It is the new schema of GralWidget. The inner class `GraphicImplAccess` is provided as super class for the graphic implementation class, for example `SwtTable`.
      - 2013-10-08 Hartmut chg:
      - 2012-07-15 Hartmut new: search functionality: This implementation have a text field which shows the search string. While up and down keys the that lines are selected which text in the `GralTable.GraphicImplAccess.ixColumn()` starts whith the search string.
      - 2012-01-06 Hartmut new: concept of a table which is independent of the table implementation of the table implementations in the graphic system layer or in operation system: The capability of a SWT-table is not sufficient, for example the color of the selection bar is not able to change. Other reason: Implementation of table in SWT, AWT, Swing is different. It seems better to have one table concept with independent features, which based on simple widgets. is not
      Copyright/Copyleft: For this source the LGPL Lesser General Public License, published by the Free Software Foundation is valid. It means:
      1. You can use this source without any restriction for any desired purpose.
      2. You can redistribute copies of this source to everybody.
      3. Every user of this source, also the user of redistribute copies with or without payment, must accept this license for further using.
      4. But the LPGL ist not appropriate for a whole software product, if this source is only a part of them. It means, the user must publish this part of source, but don't need to publish the whole source of the own product.
      5. You can study and modify (improve) this source for own using or for redistribution, but you have to license the modified sources likewise under this LGPL Lesser General Public License. You mustn't delete this Copyright/Copyleft inscription in this source file.
      If you are intent to use this sources without publishing its usage, you can get a second license subscribing a special contract with the author.
      See Also:
        Constant Field Values

    - #### swtWidgHelper

          private final SwtWidgetHelper swtWidgHelper

      It contains the association to the swt widget (Control) and the `SwtMng` and implements some methods of `GralWidgImpl_ifc` which are delegate from this.

    - #### cellsSwt

          private final org.eclipse.swt.widgets.Text[][] cellsSwt

      Some SWT Text Control fields. There are the visible cells of the table. They are children of the Composite in `SwtWidgetHelper.widgetSwt`.

    - #### vScrollBar

          private org.eclipse.swt.widgets.Canvas vScrollBar

    - #### cellInFocus

          private org.eclipse.swt.widgets.Text cellInFocus

    - #### colorBackVscrollbar

          org.eclipse.swt.graphics.Color colorBackVscrollbar

    - #### colorSliderVscrollbar

          org.eclipse.swt.graphics.Color colorSliderVscrollbar

    - #### swtSearchText

          protected org.eclipse.swt.widgets.Text swtSearchText

      SWT Text Control which contains a search text. It is only visible if need.

    - #### focusListenerTable

          private final org.eclipse.swt.events.FocusListener focusListenerTable

    - #### mousePressedListener

          private final SwtTable.MousePressedListenerTable mousePressedListener

    - #### mouseWheelListener

          private final SwtTable.MouseWheelListenerTable mouseWheelListener

    - #### myKeyListener

          private final SwtTable.TableKeyListerner myKeyListener

    - #### resizeListener

          org.eclipse.swt.events.ControlListener resizeListener

    - #### traverseListenerTable

          org.eclipse.swt.events.TraverseListener traverseListenerTable

    - #### swtKeyListener

          protected SwtKeyListener swtKeyListener

  - ### Constructor Detail

    - #### SwtTable

          public SwtTable(GralTable<?> gralTable,
                          SwtMng mng,
                          org.eclipse.swt.widgets.Composite parent)

  - ### Method Detail

    - #### addTable

          @Deprecated
          public static GralTable addTable(GralTable gralTable,
                                                        SwtMng mng,
                                                        java.lang.String sName,
                                                        int height,
                                                        int[] columnWidths)

      Deprecated. Create an instance of `GralTable` and call
      Parameters:
        `gralTable` -
        `mng` -
        `sName` -
        `height` -
        `columnWidths` -
      Returns:

    - #### createTable

          static void createTable(GralTable<?> gralTable,
                                  SwtMng mng)

    - #### setColorsSwt

          private void setColorsSwt()

    - #### getWidgetImplementation

          public java.lang.Object getWidgetImplementation()

      Description copied from interface: `GralWidgImpl_ifc`
      Returns the implementation class of the widget. If the widget has more as one implementation widgets, this method returns one of the widgets, usual the first important one respectively that widget which represents the implementation layer. A widget of the implementation layer is a SWT.control or a `Component`.
      If more as one widget are part of the GralWidget, use the special `GralWidget._wdgImpl` class which should contain the references to that implementation widgets.
      Specified by:
        `getWidgetImplementation` in interface `GralWidgImpl_ifc`

    - #### setBackgroundColor

          public GralColor setBackgroundColor(GralColor color)

    - #### setForegroundColor

          public GralColor setForegroundColor(GralColor color)

    - #### setBoundsPixel

          public void setBoundsPixel(int x,
                                     int y,
                                     int dx,
                                     int dy)

      Specified by:
        `setBoundsPixel` in interface `GralWidgImpl_ifc`

    - #### getPixelPositionSize

          public GralRectangle getPixelPositionSize()

      Specified by:
        `getPixelPositionSize` in interface `GralWidgImpl_ifc`

    - #### XXXsetVisible

          public boolean XXXsetVisible(boolean visible)

    - #### repaintGthread

          public void repaintGthread()

      TODO implement in `GralTable.GraphicImplAccess`
      Specified by:
        `repaintGthread` in interface `GralWidgImpl_ifc`
      See Also:
        `GralWidgImpl_ifc.repaintGthread()`

    - #### setFocusGThread

          public boolean setFocusGThread()

      Sets the focus to the current cell of the tab
      Specified by:
        `setFocusGThread` in interface `GralWidgImpl_ifc`
      Returns:
        true if it has the focus after this operation. false on any error.
      See Also:
        `TODO this method must call in the graphic thread yet, queue it with {@link GralMng#setInfo(GralWidget, int, int, Object, Object)}.`

    - #### setVisibleGThread

          public void setVisibleGThread(boolean bVisible)

      Description copied from interface: `GralWidgImpl_ifc`
      Sets the implementation widget(s) visible state. The widgets are really invisible, or they are visible in principle, but they can be covered by other windows or clipping. This method should set the `GralWidget.bVisibleState` too. Therewith it is able to quest `GralWidget.isVisible()` in any thread.
      Specified by:
        `setVisibleGThread` in interface `GralWidgImpl_ifc`
      Parameters:
        `bVisible` - true then the widget should be visible, false it is set to invisible.

    - #### setDragEnable

          protected void setDragEnable(int dragType)

      Description copied from class: `GralWidget.ImplAccess`
      Implementation routine to set receiving a drag event and initializes the drag feature of the widget. A overridden routine should be implemented for the implementation graphic layer widget. This routine is invoked when it isn't overridden, it throws an exception because the drag feature isn't supported for the implementation.
      Overrides:
        `setDragEnable` in class `GralWidget.ImplAccess`
      Parameters:
        `dragType` - one of `KeyCode.dragFiles` or ..dragText

    - #### removeWidgetImplementation

          public void removeWidgetImplementation()

      Removes the graphical widgets.
      Specified by:
        `removeWidgetImplementation` in interface `GralWidgImpl_ifc`
      See Also:
        `org.vishia.gral.base.GralWidget#removeWidgetImplementation()`

    - #### remove

          public boolean remove()

      Description copied from interface: `org.vishia.util.Removeable`
      Removes all referenced data, close all opened resources, removes all graphical widgets etc. This method prepares a dereferencing of the instance. It is similar to the concept of Object.finalize(). But finalize() is designed for the last clearing before the garbage collector deletes an instance. In opposite remove cleans and closes on active run time. It may be proper to call remove inside the finalize() implementation. The remove() implementation should check whether some instances are removed already to support a second call of remove() after a first one!
      Specified by:
        `remove` in interface `Removeable`
      Overrides:
        `remove` in class `GralTable.GraphicImplAccess`
      Returns:
        true if successfully. If false it is a hint for the application that the instance itself should not be removed.

    - #### redrawTableWithFocusedCell

          private void redrawTableWithFocusedCell(org.eclipse.swt.widgets.Widget cell)

      Sets the current cell as focused with the focus color. It causes a redraw of the whole table because the cell may be shifted in table position. TODO this method must call in the graphic thread yet, queue it with `GralMng#setInfo(GralWidget, int, int, Object, Object)`.
      Parameters:
        `cell` - The cell

    - #### getVisibleLinesTableImpl

          protected int getVisibleLinesTableImpl()

      Specified by:
        `getVisibleLinesTableImpl` in class `GralTable.GraphicImplAccess`

    - #### drawCellContent

          protected void drawCellContent(int iCellLine,
                                         GralTable.CellData[] cellLine,
                                         GralTable.TableLineData line,
                                         GralTable.LinePresentation linePresentationP)

      This routine implements all things to set the content of any table cell to show it.
      Specified by:
        `drawCellContent` in class `GralTable.GraphicImplAccess`
      See Also:
        `org.vishia.gral.base.GralTable#drawCellContent(int, int, org.vishia.gral.base.GralTable.TableLineData)`

    - #### drawCellInvisible

          protected GralTable.CellData drawCellInvisible(int iCellLine,
                                                         int iCellCol)

      Specified by:
        `drawCellInvisible` in class `GralTable.GraphicImplAccess`

    - #### paintVscrollbar

          private void paintVscrollbar(org.eclipse.swt.graphics.GC gc,
                                       org.eclipse.swt.widgets.Canvas canvas)

    - #### createColumnMenu

          protected GralMenu createColumnMenu(int column)

      Description copied from class: `GralTable.GraphicImplAccess`
      Should be implemented by the implementation class.
      Specified by:
        `createColumnMenu` in class `GralTable.GraphicImplAccess`
      Parameters:
        `column` - The column
      Returns:
        The menu.

    - #### mouseDown

          protected void mouseDown(org.eclipse.swt.events.MouseEvent ev)

      Called internal from mouse event only.
      Parameters:
        `ev` -

    - #### mouseUp

          protected void mouseUp(org.eclipse.swt.events.MouseEvent ev)

      Called internal from mouse event only.
      Parameters:
        `ev` -

    - #### mouseDouble

          protected void mouseDouble(org.eclipse.swt.events.MouseEvent ev)

      Called internal from mouse event only.
      Parameters:
        `ev` -

    - #### setBoundsCells

          protected void setBoundsCells(int treeDepthBase,
                                        int zLineVisible)

      Description copied from class: `GralTable.GraphicImplAccess`
      Invoked in `GralTable.GraphicImplAccess.resizeTable(GralRectangle)` as action which should be implemented in the implementation layer. The `GralTable.GraphicImplAccess.xpixelCell` was set before.
      Specified by:
        `setBoundsCells` in class `GralTable.GraphicImplAccess`

    - #### setTextToLine

          void setTextToLine(org.eclipse.swt.widgets.Text widgSwt)

      Invoked on `swtKeyListener` if enter.

    - #### getCellText

          protected java.lang.String getCellText(GralTable.CellData cell)

      Description copied from class: `GralTable.GraphicImplAccess`
      Gets the current text of the given cell from the graphic implementation.
      Specified by:
        `getCellText` in class `GralTable.GraphicImplAccess`
      Returns:

    - #### getCellTextFocus

          protected java.lang.String getCellTextFocus()

      Description copied from class: `GralTable.GraphicImplAccess`
      Gets the cell text from the focused cell in the implementation.
      Specified by:
        `getCellTextFocus` in class `GralTable.GraphicImplAccess`

    - #### focusLost

          public void focusLost(org.eclipse.swt.events.FocusEvent ev)

      Focus listener implementation for all cells. This routine is invoked whenever the focus of any Text field of the table will be lost the focus. It invokes `GralTable.GraphicImplAccess#focusLostTable()` but only if `GralTable.GraphicImplAccess#bRedrawPending` is not set. That prevents invocation while `GralTable.GraphicImplAccess#updateGraphicCellContent()` sets the focus while updating the graphic cells.
      Specified by:
        `focusLost` in interface `org.eclipse.swt.events.FocusListener`

    - #### focusGained

          public void focusGained(org.eclipse.swt.events.FocusEvent ev)

      Focus listener implementation for all cells. This routine is invoked especially if the mouse is landing on a Text-field with click. Then this table line and column should be selected as currently.
      This routine is invoked on setFocus()-call too. In this case it should not done anything. The variable #bRedrawPending guards it.
      Specified by:
        `focusGained` in interface `org.eclipse.swt.events.FocusListener`
      See Also:
        `FocusListener.focusGained(org.eclipse.swt.events.FocusEvent)`

    - #### initSwtTable

          protected void initSwtTable(org.eclipse.swt.widgets.Composite swtTable,
                                      int zColumns,
                                      SwtMng mng)

    - #### keyPressed

          protected void keyPressed(org.eclipse.swt.events.KeyEvent keyEv)

    - #### stop

          void stop()