use of org.pentaho.ui.xul.binding.BindingConvertor in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestController method bindSelectedLogLevel.
private void bindSelectedLogLevel(BindingFactory bindingFactory) throws InvocationTargetException, XulException {
Binding logBinding = bindingFactory.createBinding(model, "logLevel", logLevels, "selectedItem");
logBinding.setBindingType(Binding.Type.BI_DIRECTIONAL);
BindingConvertor logLevelConverter = new BindingConvertor<LogLevel, String>() {
@Override
public String sourceToTarget(LogLevel value) {
return value.getDescription();
}
@Override
public LogLevel targetToSource(String value) {
for (LogLevel level : LogLevel.values()) {
if (level.getDescription().equals(value)) {
return level;
}
}
throw new IllegalArgumentException(String.format("'%s' does not correspond to a valid LogLevel value.", value));
}
};
logBinding.setConversion(logLevelConverter);
logBinding.initialize();
logBinding.fireSourceChanged();
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project pdi-dataservice-server-plugin by pentaho.
the class DataServiceTestController method bindSelectedMaxRows.
private void bindSelectedMaxRows(BindingFactory bindingFactory) throws InvocationTargetException, XulException {
Binding binding = bindingFactory.createBinding(model, "maxRows", maxRows, "selectedItem");
binding.setBindingType(Binding.Type.BI_DIRECTIONAL);
BindingConvertor maxRowsConverter = new BindingConvertor<Integer, Integer>() {
@Override
public Integer sourceToTarget(Integer value) {
return DataServiceTestModel.MAXROWS_CHOICES.indexOf(value);
}
@Override
public Integer targetToSource(Integer value) {
return DataServiceTestModel.MAXROWS_CHOICES.indexOf(value);
}
};
binding.setConversion(maxRowsConverter);
binding.initialize();
binding.fireSourceChanged();
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.
the class WizardRelationalDatasourceController method init.
@Bindable
public void init(final DatasourceModel datasourceModel) {
this.datasourceModel = datasourceModel;
bf = new GwtBindingFactory(document);
// $NON-NLS-1$
sampleDataTree = (XulTree) document.getElementById("relationalSampleDataTable");
// $NON-NLS-1$
aggregationEditorDialog = (XulDialog) document.getElementById("relationalAggregationEditorDialog");
// $NON-NLS-1$
sampleDataDialog = (XulDialog) document.getElementById("relationalSampleDataDialog");
// $NON-NLS-1$
errorDialog = (XulDialog) document.getElementById("errorDialog");
// $NON-NLS-1$
errorLabel = (XulLabel) document.getElementById("errorLabel");
// $NON-NLS-1$
applyQueryConfirmationDialog = (XulDialog) document.getElementById("applyQueryConfirmationDialog");
// $NON-NLS-1$
errorLabel = (XulLabel) document.getElementById("errorLabel");
// $NON-NLS-1$
successDialog = (XulDialog) document.getElementById("successDialog");
// $NON-NLS-1$
successLabel = (XulLabel) document.getElementById("successLabel");
// $NON-NLS-1$
datasourceName = (XulTextbox) document.getElementById("datasourceName");
// $NON-NLS-1$
connections = (XulListbox) document.getElementById("connectionList");
// $NON-NLS-1$
query = (XulTextbox) document.getElementById("query");
// $NON-NLS-1$
connectionDialog = (XulDialog) document.getElementById("connectionDialog");
// $NON-NLS-1$
previewResultsDialog = (XulDialog) document.getElementById("previewResultsDialog");
// $NON-NLS-1$
previewResultsTable = (XulTree) document.getElementById("previewResultsTable");
// $NON-NLS-1$
previewResultsTreeCols = (XulTreeCols) document.getElementById("previewResultsTreeCols");
// $NON-NLS-1$
previewLimit = (XulTextbox) document.getElementById("previewLimit");
// $NON-NLS-1$
editConnectionButton = (XulButton) document.getElementById("editConnection");
// $NON-NLS-1$
removeConnectionButton = (XulButton) document.getElementById("removeConnection");
// $NON-NLS-1$
editQueryButton = (XulButton) document.getElementById("editQuery");
// $NON-NLS-1$
previewButton = (XulButton) document.getElementById("preview");
bf.setBindingType(Binding.Type.ONE_WAY);
bf.createBinding(datasourceModel.getGuiStateModel(), "relationalPreviewValidated", previewButton, // $NON-NLS-1$ //$NON-NLS-2$
"!disabled");
List<Binding> bindingsThatNeedInitialized = new ArrayList<Binding>();
BindingConvertor<IDatabaseConnection, Boolean> buttonConvertor = new BindingConvertor<IDatabaseConnection, Boolean>() {
@Override
public Boolean sourceToTarget(IDatabaseConnection value) {
return !(value == null);
}
@Override
public IDatabaseConnection targetToSource(Boolean value) {
return null;
}
};
bf.setBindingType(Binding.Type.ONE_WAY);
final Binding domainBinding = bf.createBinding(datasourceModel.getGuiStateModel(), "connections", this, // $NON-NLS-1$ //$NON-NLS-2$
"relationalConnections");
// $NON-NLS-1$
bf.createBinding(this, connectionNamesListProp, connections, "elements");
bf.createBinding(datasourceModel, "selectedRelationalConnection", editConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
buttonConvertor);
bf.createBinding(datasourceModel, "selectedRelationalConnection", removeConnectionButton, "!disabled", // $NON-NLS-1$ //$NON-NLS-2$
buttonConvertor);
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(datasourceModel, "selectedRelationalConnection", connections, "selectedIndex", new // $NON-NLS-1$ //$NON-NLS-2$
BindingConvertor<IDatabaseConnection, Integer>() {
@Override
public Integer sourceToTarget(IDatabaseConnection connection) {
if (connection != null) {
return datasourceModel.getGuiStateModel().getConnectionIndex(connection);
}
return -1;
}
@Override
public IDatabaseConnection targetToSource(Integer value) {
if (value >= 0) {
return datasourceModel.getGuiStateModel().getConnections().get(value);
}
return null;
}
});
bf.setBindingType(Binding.Type.BI_DIRECTIONAL);
bf.createBinding(datasourceModel.getGuiStateModel(), "previewLimit", previewLimit, // $NON-NLS-1$ //$NON-NLS-2$
"value");
// $NON-NLS-1$ //$NON-NLS-2$
bf.createBinding(datasourceModel, "query", query, "value");
try {
// Fires the population of the model listbox. This cascades down to the categories and columns. In essence, this
// call initializes the entire UI.
domainBinding.fireSourceChanged();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
for (Binding b : bindingsThatNeedInitialized) {
try {
b.fireSourceChanged();
} catch (Exception e) {
System.out.println(e.getMessage());
e.printStackTrace();
}
}
}
use of org.pentaho.ui.xul.binding.BindingConvertor 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();
}
use of org.pentaho.ui.xul.binding.BindingConvertor in project data-access by pentaho.
the class JoinDefinitionsStep method setBindings.
public void setBindings() {
BindingFactory bf = new GwtBindingFactory(document);
bf.createBinding(this.joinGuiModel.getLeftTables(), "children", this.leftTables, "elements");
bf.createBinding(this.joinGuiModel.getRightTables(), "children", this.rightTables, "elements");
bf.createBinding(this.leftTables, "selectedItem", this.joinGuiModel, "leftJoinTable");
bf.createBinding(this.rightTables, "selectedItem", this.joinGuiModel, "rightJoinTable");
bf.createBinding(this.joinGuiModel.getJoins(), "children", this.joinsList, "elements");
bf.createBinding(this.joinsList, "selectedItem", this.joinGuiModel, "selectedJoin");
bf.createBinding(this.leftTables, "selectedItem", this.leftKeyFieldList, "elements", new TableSelectionConvertor(this.leftTables));
bf.createBinding(this.rightTables, "selectedItem", this.rightKeyFieldList, "elements", new TableSelectionConvertor(this.rightTables));
this.leftKeyFieldBinding = bf.createBinding(this.leftKeyFieldList, "selectedIndex", this.joinGuiModel, "leftKeyField", new BindingConvertor<Integer, JoinFieldModel>() {
@Override
public JoinFieldModel sourceToTarget(final Integer index) {
JoinTableModel joinTable = joinGuiModel.getLeftJoinTable();
if (joinTable != null) {
List<JoinFieldModel> fields = joinTable.getFields();
if (index == -1 || fields.isEmpty()) {
return null;
}
return fields.get(index);
}
return null;
}
@Override
public Integer targetToSource(final JoinFieldModel value) {
return null;
}
});
this.rightKeyFieldBinding = bf.createBinding(this.rightKeyFieldList, "selectedIndex", this.joinGuiModel, "rightKeyField", new BindingConvertor<Integer, JoinFieldModel>() {
@Override
public JoinFieldModel sourceToTarget(final Integer index) {
JoinTableModel joinTable = joinGuiModel.getRightJoinTable();
if (joinTable != null) {
List<JoinFieldModel> fields = joinTable.getFields();
if (index == -1 || fields.isEmpty()) {
return null;
}
return fields.get(index);
}
return null;
}
@Override
public Integer targetToSource(final JoinFieldModel value) {
return null;
}
});
}
Aggregations