use of org.pentaho.ui.xul.stereotype.Bindable in project data-access by pentaho.
the class WizardConnectionController method updateConnection.
@Bindable
public void updateConnection() {
RequestBuilder updateConnectionBuilder = new RequestBuilder(RequestBuilder.POST, ConnectionController.getServiceURL("update"));
updateConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
updateConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
currentConnection = AutobeanUtilities.connectionBeanToImpl(currentConnection);
datasourceModel.getGuiStateModel().updateConnection(existingConnectionName, currentConnection);
datasourceModel.setSelectedRelationalConnection(currentConnection);
} else if (response.getStatusCode() == Response.SC_INTERNAL_SERVER_ERROR) {
// We assume that this means the connection doesn't exist to
// update so we'll add it
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.getServiceURL("deletebyname", new String[][] { { "name", previousConnectionName } }));
try {
deleteConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
if (connections != null && connections.size() > 0) {
datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
} else {
datasourceModel.setSelectedRelationalConnection(null);
}
addConnection();
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0004_UNABLE_TO_UPDATE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of org.pentaho.ui.xul.stereotype.Bindable in project data-access by pentaho.
the class WizardConnectionController method deleteConnection.
@Bindable
public void deleteConnection() {
removeConfirmationDialog.hide();
RequestBuilder deleteConnectionBuilder = new RequestBuilder(RequestBuilder.DELETE, ConnectionController.getServiceURL("deletebyname", new String[][] { { "name", datasourceModel.getSelectedRelationalConnection().getName() } }));
try {
deleteConnectionBuilder.sendRequest(null, new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
try {
if (response.getStatusCode() == Response.SC_OK) {
openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.CONNECTION_DELETED"));
datasourceModel.getGuiStateModel().deleteConnection(datasourceModel.getSelectedRelationalConnection().getName());
List<IDatabaseConnection> connections = datasourceModel.getGuiStateModel().getConnections();
if (connections != null && connections.size() > 0) {
datasourceModel.setSelectedRelationalConnection(connections.get(connections.size() - 1));
} else {
datasourceModel.setSelectedRelationalConnection(null);
}
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0002_UNABLE_TO_DELETE_CONNECTION"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of org.pentaho.ui.xul.stereotype.Bindable in project data-access by pentaho.
the class WizardConnectionController method toggleSuccessDetails.
@Bindable
public void toggleSuccessDetails() {
// $NON-NLS-1$
XulHbox details = (XulHbox) document.getElementById("success_details_hider");
details.setVisible(!details.isVisible());
}
use of org.pentaho.ui.xul.stereotype.Bindable in project data-access by pentaho.
the class WizardConnectionController method testConnection.
@Bindable
public void testConnection() {
RequestBuilder testConnectionBuilder = new RequestBuilder(RequestBuilder.PUT, ConnectionController.getServiceURL("test"));
testConnectionBuilder.setHeader("Content-Type", "application/json");
try {
// AutoBean<IDatabaseConnection> bean = AutoBeanUtils.getAutoBean(currentConnection);
AutoBean<IDatabaseConnection> bean = createIDatabaseConnectionBean(currentConnection);
testConnectionBuilder.sendRequest(AutoBeanCodex.encode(bean).getPayload(), new RequestCallback() {
@Override
public void onError(Request request, Throwable exception) {
displayErrorMessage(exception);
}
@Override
public void onResponseReceived(Request request, Response response) {
Boolean testPassed = new Boolean(response.getText());
try {
if (testPassed) {
openSuccesDialog(MessageHandler.getString("SUCCESS"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.CONNECTION_TEST_SUCCESS"));
} else {
openErrorDialog(MessageHandler.getString("ERROR"), // $NON-NLS-1$
MessageHandler.getString(// $NON-NLS-1$
"ConnectionController.ERROR_0003_CONNECTION_TEST_FAILED"));
}
} catch (Exception e) {
displayErrorMessage(e);
}
}
});
} catch (RequestException e) {
displayErrorMessage(e);
}
}
use of org.pentaho.ui.xul.stereotype.Bindable 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();
}
}
}
Aggregations