use of com.amalto.workbench.webservices.WSDataModelPKArray in project tmdm-studio-se by Talend.
the class NewItemHandler method createItemRecord.
public boolean createItemRecord(final TMDMService service, final Shell ashell, final WSDataClusterPK wsDataClusterPK, boolean isMaster) {
if (service == null || wsDataClusterPK == null) {
throw new IllegalArgumentException();
}
final Shell shell = ashell != null ? ashell : Display.getCurrent().getActiveShell();
try {
// $NON-NLS-1$
String xml = "<NewItem><NewElement></NewElement></NewItem>";
// $NON-NLS-1$
WSDataModelPKArray dataModelPKs = service.getDataModelPKs(new WSRegexDataModelPKs("*"));
List<WSDataModelPK> dmPKs = dataModelPKs.getWsDataModelPKs();
List<String> dataModels = new ArrayList<String>();
if (dmPKs != null) {
for (WSDataModelPK pk : dmPKs) {
if (!"XMLSCHEMA---".equals(pk.getPk())) {
// $NON-NLS-1$
dataModels.add(pk.getPk());
}
}
}
final DataContainerDOMViewDialog d = new DataContainerDOMViewDialog(shell, service, Util.parse(xml), dataModels, DOMViewDialog.SOURCE_VIEWER, null, isMaster);
d.addListener(new Listener() {
public void handleEvent(Event event) {
if (event.button == DOMViewDialog.BUTTON_SAVE) {
// attempt to save
try {
WSPutItem putItem = new WSPutItem(false, wsDataClusterPK, // $NON-NLS-1$
"".equals(d.getDataModelName()) ? // $NON-NLS-1$
null : new WSDataModelPK(d.getDataModelName()), d.getXML());
// $NON-NLS-1$
WSPutItemWithReport item = new WSPutItemWithReport(d.isBeforeVerification(), "genericUI", putItem);
if (d.isTriggerProcess()) {
service.putItemWithReport(item);
} else {
service.putItem(putItem);
}
created = true;
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(shell, Messages.DataClusterBrowserMainPage_100, Messages.bind(Messages.DataClusterBrowserMainPage_101, Util.formatErrorMessage(e.getLocalizedMessage())));
return;
}
}
d.close();
}
});
d.setBlockOnOpen(true);
d.open();
} catch (Exception e) {
log.error(e.getMessage(), e);
if (!Util.handleConnectionException(shell, e, null)) {
MessageDialog.openError(shell, Messages._Error, Messages.bind(Messages.DataClusterBrowserMainPage_103, e.getLocalizedMessage()));
}
}
return created;
}
Aggregations