Package hidb2.gui.util

Source Code of hidb2.gui.util.PojoColumnDescr

/**
* This file is part of HIDB2.
*
* HIDB2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* HIDB2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU Lesser Public License for more details.
*
* You should have received a copy of the GNU Lesser Public License
* along with HIDB2. If not, see <http://www.gnu.org/licenses/>.
*/
package hidb2.gui.util;

import static hidb2.kern.AttrType.T_Double;
import static hidb2.kern.AttrType.T_Integer;
import hidb2.kern.AttrType;

import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.jface.viewers.CheckboxCellEditor;
import org.eclipse.jface.viewers.ComboBoxCellEditor;
import org.eclipse.jface.viewers.TextCellEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Table;

/**
* Generic attribut description for table edition.
*/
public class PojoColumnDescr extends PojoAttrDescr
  {
  protected int columnSize;

  protected boolean editable = false;

  protected CellEditor _cellEdt = null;

  /**
   * Create a new editable attribute to be edited.
   *
   * @param pAttrName Java Name of attribut. Prefixed by "set", "get" or "is" according to the type.
   * @param pAttrType Type of the attribut. in the range:   AttrType
   * @param pLabel    Label of the GUI
   * @param colSize   Size of the column in pixel
   */
  public PojoColumnDescr(String pAttrName, AttrType pAttrType, String pLabel, int colSize)
    {
    this(pAttrName, pAttrType, pLabel, colSize, true);
    }

  /**
   * Create a new attribut to be edited.
   *
   * @param pAttrName Java Name of attribut. Prefixed by "set", "get" or "is" according to the type.
   * @param pAttrType Type of the attribut. in the range:   C_TYPE_INT, C_TYPE_STRING, C_TYPE_BOOLEAN,
   *                  C_TYPE_DOUBLE, C_TYPE_VECTOR3D, C_TYPE_COLOR3D, C_TYPE_MESHEDOBJECTREF, C_TYPE_CHANNELREF
   * @param pLabel    Label of the GUI
   */
  public PojoColumnDescr(String pAttrName, AttrType pAttrType, String pLabel, int colSize, boolean edit)
    {
    super(pAttrName, pAttrType, pLabel);
    columnSize = colSize;
    editable = edit;
    }

  /**
   * Create the Table Cell Editor for the given attribute.
   *
   * Used by description editors ? duplicated in Parts ?!?
   *
   * @param table   Future Parent Table
   * @return
   */
  public CellEditor createCellEditor(Table table)
    {
    if ((_cellEdt == null) && editable)
      {
      switch (attrType)
        {
        case T_Integer:
          _cellEdt = new NumericCellEditor(table, SWT.SINGLE, T_Integer);
          break;

        case T_String:
          _cellEdt = new TextCellEditor(table);
          break;

        case T_Boolean:
          _cellEdt = new CheckboxCellEditor(table);
          break;

        case T_Double:
          _cellEdt = new NumericCellEditor(table, SWT.SINGLE, T_Double);
          break;

        case T_Date:
          _cellEdt = Parts.createDateTimeEditor(table, SWT.CALENDAR);
          break;

        case T_Time:
          _cellEdt = Parts.createDateTimeEditor(table, SWT.TIME);
          break;

        case T_TimeStamp:
          _cellEdt = Parts.createDateTimeEditor(table, SWT.CALENDAR | SWT.TIME);
          break;

        case T_Color: // Color
          log.warning("T_Color : Not Implemented yet");
          break;

        case T_RefList: // RefList
          log.warning("T_RefList : Not Implemented yet");
          break;

        case T_TypeEnum:
          AttrType[] vt = AttrType.values();

          int nbT = 0;
          for (AttrType at : vt)
            {
            if (at.id > 0)
              nbT++;
            }

          String[] tabTypesNames = new String[nbT];
          int i = 0;
          for (AttrType at : vt)
            {
            if (at.id > 0)
              {
              tabTypesNames[i++] = at.name;
              }
            }

          _cellEdt = new ComboBoxCellEditor(table, tabTypesNames, SWT.READ_ONLY);
          break;

        case T_Enum:
          log.warning("Method createCellEditor() shall be overridden for Enum[" + attrName + "]");
          break;

        case T_Image:
          log.warning("Not Implemented yet");
          break;

        default:
          throw new IllegalArgumentException();
        }
      }

    return _cellEdt;
    }

  }
TOP

Related Classes of hidb2.gui.util.PojoColumnDescr

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.