Search in sources :

Example 11 with XulTree

use of org.pentaho.ui.xul.containers.XulTree 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

XulTree (org.pentaho.ui.xul.containers.XulTree)11 XulTreeRow (org.pentaho.ui.xul.containers.XulTreeRow)3 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)2 XulComponent (org.pentaho.ui.xul.XulComponent)2 XulTreeCell (org.pentaho.ui.xul.components.XulTreeCell)2 XulTreeItem (org.pentaho.ui.xul.containers.XulTreeItem)2 Bindable (org.pentaho.ui.xul.stereotype.Bindable)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 MissingResourceException (java.util.MissingResourceException)1 Vector (java.util.Vector)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1 ModifyListener (org.eclipse.swt.events.ModifyListener)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Composite (org.eclipse.swt.widgets.Composite)1 Before (org.junit.Before)1 ExtTextbox (org.pentaho.di.ui.core.database.dialog.tags.ExtTextbox)1 ErrorDialog (org.pentaho.di.ui.core.dialog.ErrorDialog)1 ComboVar (org.pentaho.di.ui.core.widget.ComboVar)1