Search in sources :

Example 11 with DataType

use of org.pentaho.metadata.model.concept.types.DataType in project data-access by pentaho.

the class StageDataStep method generateDataTypeDisplay_horizontal.

private void generateDataTypeDisplay_horizontal() {
    // $NON-NLS-1$
    XulTree tree = (XulTree) document.getElementById("csvModelDataTable");
    tree.setRows(datasourceModel.getModelInfo().getColumns().length);
    bf.setBindingType(Binding.Type.ONE_WAY);
    tree.setBindingProvider(new FactoryBasedBindingProvider(bf) {

        @Override
        public BindingConvertor getConvertor(XulEventSource source, String prop1, XulEventSource target, String prop2) {
            if (source instanceof ColumnInfo) {
                if (prop1.equals("length") || prop1.equals("precision")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return BindingConvertor.integer2String();
                } else if (prop1.equals("include") && prop2.equals("value")) {
                    // this is the binding from the cell to the value of the checkbox
                    return null;
                } else if (prop1.equals("include")) {
                    // this binding is from the model to the checkbox
                    return BindingConvertor.boolean2String();
                } else if (prop1.equals("availableDataTypes")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("formatStrings")) {
                    // $NON-NLS-1$
                    return new BindingConvertor<List, Vector>() {

                        @SuppressWarnings("unchecked")
                        public Vector sourceToTarget(List value) {
                            return new Vector(value);
                        }

                        @SuppressWarnings("unchecked")
                        public List targetToSource(Vector value) {
                            return new ArrayList(value);
                        }
                    };
                } else if (prop1.equals("dataType") && prop2.equals("selectedIndex")) {
                    // $NON-NLS-1$ //$NON-NLS-2$
                    return new BindingConvertor<DataType, Integer>() {

                        @Override
                        public Integer sourceToTarget(DataType value) {
                            List<DataType> types = ColumnInfo.getAvailableDataTypes();
                            for (int i = 0; i < types.size(); i++) {
                                if (types.get(i).equals(value)) {
                                    return i;
                                }
                            }
                            return 0;
                        }

                        @Override
                        public DataType targetToSource(Integer value) {
                            return ColumnInfo.getAvailableDataTypes().get(value);
                        }
                    };
                } else if (prop1.equals("formatStringsDisabled")) {
                    return null;
                } else {
                    return BindingConvertor.string2String();
                }
            } else {
                return null;
            }
        }
    });
    tree.setElements(Arrays.asList(datasourceModel.getModelInfo().getColumns()));
    if (datasourceModel.getModelInfo().getColumns().length > 0) {
        tree.setSelectedRows(new int[] { 0 });
    }
    tree.update();
}
Also used : FactoryBasedBindingProvider(org.pentaho.ui.xul.binding.FactoryBasedBindingProvider) XulTree(org.pentaho.ui.xul.containers.XulTree) ArrayList(java.util.ArrayList) ColumnInfo(org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo) BindingConvertor(org.pentaho.ui.xul.binding.BindingConvertor) DataType(org.pentaho.metadata.model.concept.types.DataType) ArrayList(java.util.ArrayList) List(java.util.List) Vector(java.util.Vector) XulEventSource(org.pentaho.ui.xul.XulEventSource)

Example 12 with DataType

use of org.pentaho.metadata.model.concept.types.DataType in project data-access by pentaho.

the class ColumnInfo method getAvailableDataTypes.

@Bindable
public static List<DataType> getAvailableDataTypes() {
    if (availableDataTypes == null || availableDataTypes.size() == 0) {
        ArrayList<DataType> types = new ArrayList<DataType>();
        DataType[] dt = DataType.values();
        for (DataType dataType : dt) {
            // don't support url, binary, unknown, or image in csv
            switch(dataType) {
                case URL:
                case BINARY:
                case IMAGE:
                case UNKNOWN:
                    break;
                default:
                    // types.add(dataType.getDescription());
                    types.add(dataType);
                    break;
            }
        }
        availableDataTypes = types;
    }
    return availableDataTypes;
}
Also used : ArrayList(java.util.ArrayList) DataType(org.pentaho.metadata.model.concept.types.DataType) Bindable(org.pentaho.ui.xul.stereotype.Bindable)

Aggregations

DataType (org.pentaho.metadata.model.concept.types.DataType)12 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)7 ArrayList (java.util.ArrayList)3 TableItem (org.eclipse.swt.widgets.TableItem)2 JSONObject (org.json.JSONObject)2 Test (org.junit.Test)2 IPhysicalColumn (org.pentaho.metadata.model.IPhysicalColumn)2 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)2 AggregationType (org.pentaho.metadata.model.concept.types.AggregationType)2 FieldType (org.pentaho.metadata.model.concept.types.FieldType)2 Constraint (org.pentaho.metadata.query.model.Constraint)2 Operator (org.pentaho.platform.dataaccess.metadata.model.Operator)2 Column (org.pentaho.platform.dataaccess.metadata.model.impl.Column)2 InputStream (java.io.InputStream)1 List (java.util.List)1 Vector (java.util.Vector)1 Element (org.dom4j.Element)1 JSONArray (org.json.JSONArray)1 Point (org.pentaho.di.core.gui.Point)1 ValueMeta (org.pentaho.di.core.row.ValueMeta)1