Search in sources :

Example 1 with XulEventSource

use of org.pentaho.ui.xul.XulEventSource 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)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 Vector (java.util.Vector)1 DataType (org.pentaho.metadata.model.concept.types.DataType)1 ColumnInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ColumnInfo)1 XulEventSource (org.pentaho.ui.xul.XulEventSource)1 BindingConvertor (org.pentaho.ui.xul.binding.BindingConvertor)1 FactoryBasedBindingProvider (org.pentaho.ui.xul.binding.FactoryBasedBindingProvider)1 XulTree (org.pentaho.ui.xul.containers.XulTree)1