use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.
the class EditXObjectAction method run.
@Override
public void run() {
try {
super.run();
if (xobject == null || !xobject.isXObject()) {
return;
}
// Access to server and get port
TMDMService service = Util.getMDMService(new URL(xobject.getEndpointAddress()), xobject.getUsername(), xobject.getPassword());
switch(xobject.getType()) {
case TreeObject.DATA_MODEL:
WSDataModel wsDataModel = service.getDataModel(new WSGetDataModel((WSDataModelPK) xobject.getWsKey()));
xobject.setWsObject(wsDataModel);
// XSDEditorUtil.openDataModel(xobject, false);
return;
case TreeObject.VIEW:
WSView wsView = service.getView(new WSGetView((WSViewPK) xobject.getWsKey()));
xobject.setWsObject(wsView);
break;
case TreeObject.DATA_CLUSTER:
WSDataCluster wsDataCluster = service.getDataCluster(new WSGetDataCluster((WSDataClusterPK) xobject.getWsKey()));
xobject.setWsObject(wsDataCluster);
break;
case TreeObject.STORED_PROCEDURE:
WSStoredProcedure wsStoredProcedure = service.getStoredProcedure(new WSGetStoredProcedure((WSStoredProcedurePK) xobject.getWsKey()));
xobject.setWsObject(wsStoredProcedure);
break;
case TreeObject.ROUTING_RULE:
WSRoutingRule wsRoutingRule = service.getRoutingRule(new WSGetRoutingRule((WSRoutingRulePK) xobject.getWsKey()));
xobject.setWsObject(wsRoutingRule);
break;
case TreeObject.TRANSFORMER:
WSTransformerV2 wsTranformer = service.getTransformerV2(new WSGetTransformerV2((WSTransformerV2PK) xobject.getWsKey()));
xobject.setWsObject(wsTranformer);
break;
case TreeObject.MENU:
WSMenu wsMenu = service.getMenu(new WSGetMenu((WSMenuPK) xobject.getWsKey()));
xobject.setWsObject(wsMenu);
break;
case TreeObject.SERVICE_CONFIGURATION:
break;
case TreeObject.JOB_REGISTRY:
// System.out.println("JOB_REGISTRY "+ xobject.getDisplayName());
break;
case TreeObject.JOB:
// System.out.println("JOB "+ xobject.getDisplayName()+" "+xobject.getWsKey());
xobject.setWsObject(xobject.getDisplayName());
break;
case TreeObject.ROLE:
if (exAdapter != null) {
exAdapter.run(service, xobject);
}
break;
case TreeObject.RESOURCES:
case TreeObject.CUSTOM_TYPE:
case TreeObject.DATA_MODEL_RESOURCE:
case TreeObject.DATA_MODEL_TYPES_RESOURCE:
case TreeObject.CUSTOM_TYPES_RESOURCE:
case TreeObject.PICTURES_RESOURCE:
break;
default:
MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages.EditXObjectAction_ErrorMsg1, IConstants.TALEND, xobject.getType()));
return;
}
if (page == null) {
this.page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
}
this.page.openEditor(new XObjectEditorInput(xobject, xobject.getDisplayName()), // $NON-NLS-1$
"com.amalto.workbench.editors.XObjectEditor");
} catch (Exception e) {
log.error(e.getMessage(), e);
if (!Util.handleConnectionException(getShell(), e, Messages.EditXObjectAction_ErrorMsg2)) {
MessageDialog.openError(getShell(), Messages._Error, Messages.bind(Messages.EditXObjectAction_ErrorMsg2, e.getLocalizedMessage()));
}
}
}
use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.
the class DataModelMainPage method createCharacteristicsContent.
protected void createCharacteristicsContent(FormToolkit toolkit, Composite mainComposite) {
try {
GridLayout layout = new GridLayout();
layout.verticalSpacing = 0;
mainComposite.getParent().setLayout(layout);
GridData gdMainComposite = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
gdMainComposite.widthHint = 1;
gdMainComposite.heightHint = 1;
mainComposite.setLayoutData(gdMainComposite);
WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
// description
Composite descriptionComposite = toolkit.createComposite(mainComposite, SWT.NONE);
descriptionComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
descriptionComposite.setLayout(new GridLayout());
desAntionComposite = new // $NON-NLS-1$
DescAnnotationComposite(// $NON-NLS-1$
Messages.DescriptionText, // $NON-NLS-1$
" ...", // $NON-NLS-1$
toolkit, // $NON-NLS-1$
descriptionComposite, null, false);
// $NON-NLS-1$
desAntionComposite.setText(wsObject.getDescription() == null ? "" : wsObject.getDescription());
desAntionComposite.getTextWidget().addModifyListener(new ModifyListener() {
public void modifyText(ModifyEvent e) {
markDirty();
}
});
desAntionComposite.setEnable(!isReadOnly());
Composite btnCmp = toolkit.createComposite(mainComposite);
btnCmp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 2, 1));
GridLayout gLayout = new GridLayout();
gLayout.numColumns = 4;
gLayout.horizontalSpacing = 20;
gLayout.verticalSpacing = 0;
btnCmp.setLayout(gLayout);
xsdSchema = getXSDSchema(wsObject.getXsdSchema());
createSash(mainComposite);
hookSelectionProvider();
if (!isReadOnly()) {
createCompDropTarget();
hookContextMenu();
hookDoubleClickAction();
hookTypesContextMenu();
}
// init undo history
initializeOperationHistory();
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.
the class DataModelMainPage method createToolBar.
private void createToolBar(Composite parent) {
Composite toolBarComp = new Composite(parent, SWT.BORDER);
GridData gd = new GridData(SWT.FILL, SWT.TOP, true, false, 2, 1);
gd.heightHint = 25;
toolBarComp.setLayoutData(gd);
final GridLayout glToolBarBackground = new GridLayout();
glToolBarBackground.verticalSpacing = 0;
glToolBarBackground.marginWidth = 0;
glToolBarBackground.marginHeight = 0;
glToolBarBackground.horizontalSpacing = 0;
toolBarComp.setLayout(glToolBarBackground);
ToolBar resultToolBar = new ToolBar(toolBarComp, SWT.FLAT | SWT.HORIZONTAL);
gd = new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1);
resultToolBar.setLayoutData(gd);
ToolItem importToolItem = new ToolItem(resultToolBar, SWT.PUSH);
importToolItem.setImage(ImageCache.getCreatedImage(EImage.IMPORT.getPath()));
importToolItem.setToolTipText(Messages.ImportText);
importToolItem.setEnabled(!isReadOnly());
ToolItem exportToolItem = new ToolItem(resultToolBar, SWT.PUSH);
exportToolItem.setImage(ImageCache.getCreatedImage(EImage.EXPORT.getPath()));
exportToolItem.setToolTipText(Messages.ExportText);
exportToolItem.setEnabled(!isReadOnly());
ToolItem importSchemalItem = new ToolItem(resultToolBar, SWT.PUSH);
importSchemalItem.setImage(ImageCache.getCreatedImage(EImage.CHECKIN_ACTION.getPath()));
importSchemalItem.setToolTipText(Messages.ImportIncludeSchema);
importSchemalItem.setEnabled(!isReadOnly());
importToolItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(getSite().getShell(), SWT.OPEN);
// $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
fd.setFilterExtensions(new String[] { "*.xsd", "*.dtd", "*.xml" });
// set the default path to the workspace.
fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
fd.setText(Messages.SelectXMLDefinition);
String filename = fd.open();
if (filename == null) {
return;
}
xsdSchema = null;
inferXsdFromXml(filename);
}
private void inferXsdFromXml(String xmlFile) {
int infer = 0;
// $NON-NLS-1$
String xsd = "";
try {
// $NON-NLS-1$
String inputType = xmlFile.substring(xmlFile.lastIndexOf("."));
if (inputType.equals(".xsd")) {
// $NON-NLS-1$
xsd = Util.getXML(xmlFile);
xsdSchema = Util.createXsdSchema(xsd, xobject);
xsd = Util.nodeToString(xsdSchema.getDocument());
} else {
XSDDriver d = new XSDDriver();
// $NON-NLS-1$
infer = d.doMain(new String[] { xmlFile, "out.xsd" });
if (infer == 0) {
xsd = d.outputXSD();
}
}
} catch (Exception e) {
log.error(e.getMessage(), e);
infer = 2;
} finally {
if (infer == 0 && !xsd.equals("")) {
// $NON-NLS-1$
WSDataModel wsObj = (WSDataModel) (xobject.getWsObject());
wsObj.setXsdSchema(xsd);
validateSchema(xsd);
refreshData();
markDirtyWithoutCommit();
} else if (infer != 0) {
MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.XsdSchemaInferred);
}
}
}
void validateSchema(String xsd) {
try {
boolean elem = false;
XSDSchema schema = getXSDSchema(xsd);
NodeList nodeList = schema.getDocument().getDocumentElement().getChildNodes();
for (int idx = 0; idx < nodeList.getLength(); idx++) {
Node node = nodeList.item(idx);
if (node instanceof Element && node.getLocalName().indexOf("element") >= 0) {
// $NON-NLS-1$
elem = true;
break;
}
}
if (!elem) {
MessageDialog.openWarning(getSite().getShell(), Messages.Warning, Messages.NoElementNode);
}
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
});
exportToolItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
FileDialog fd = new FileDialog(getSite().getShell(), SWT.SAVE);
// $NON-NLS-1$
fd.setFilterExtensions(new String[] { "*.xsd" });
fd.setFilterPath(Platform.getInstanceLocation().getURL().getPath().substring(1));
fd.setText(Messages.SaveDataModuleXSDSchema);
String filename = fd.open();
if (filename == null) {
return;
}
inferXsdFromDataModule(filename);
}
private void inferXsdFromDataModule(String xmlFile) {
WSDataModel wsObject = (WSDataModel) (xobject.getWsObject());
XSDDriver d = new XSDDriver();
if (d.outputXSD_UTF_8(wsObject.getXsdSchema(), xmlFile) != null) {
MessageDialog.openInformation(getSite().getShell(), Messages.ExportXSD, Messages.OperationExportingXsd);
} else {
MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.FailedExportXSD);
}
}
});
importSchemalItem.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
popupImportDialog();
}
});
}
use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.
the class XSDEditor method doSave.
@Override
public void doSave(IProgressMonitor monitor) {
XSDDirectivesManager.removeUnusedXSDImports(getXSDSchema());
structuredTextEditor.doSave(monitor);
InputStream stream = null;
try {
EditorPart part = (EditorPart) getSelectedPage();
String xsd = null;
if (null != part) {
if (part instanceof StructuredTextEditor) {
xsd = ((StructuredTextEditor) part).getTextViewer().getDocument().get();
} else {
// main page or er editor
DataModelMainPage dmp = getdMainPage();
xsd = dmp.getXSDSchemaString();
}
}
if (null != xsd) {
DataModelMainPage mainPage = getdMainPage();
WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
wsDataModel.setXsdSchema(xsd);
if (mainPage != null) {
mainPage.save(xsd);
}
// $NON-NLS-1$
fileContents = xsd.getBytes("utf-8");
}
getDataModelEditorPage().setDirty(false);
} catch (Exception e) {
log.error(e.getMessage(), e);
} finally {
IOUtils.closeQuietly(stream);
if (null != monitor) {
monitor.done();
}
}
}
use of com.amalto.workbench.webservices.WSDataModel in project tmdm-studio-se by Talend.
the class XSDEditor method doPageChanged.
protected void doPageChanged(int newPageIndex, int lastPageIndex) {
if (xobject == null) {
return;
}
try {
if (newPageIndex == MODEL_PAGE_INDEX) {
DataModelMainPage mainPage = getDataModelEditorPage();
if (mainPage != null) {
if (lastPageIndex == SOURCE_PAGE_INDEX) {
validateXsdSourceEditor();
if (!hasXSDErrors) {
String xsd = getSourcePageDocument();
XSDSchema schema = Util.createXsdSchema(xsd, xobject);
mainPage.setXsdSchema(schema);
}
}
mainPage.refresh();
//
expandHelper.recoverExpandState(mainPage);
}
} else if (newPageIndex == SOURCE_PAGE_INDEX) {
if (hasXSDErrors) {
return;
}
// save DataModelMainPage's contents to file
DataModelMainPage mainPage = getDataModelEditorPage();
expandHelper.recordExpandState(mainPage);
if (mainPage != null && this.isDirty()) {
String xsd = mainPage.getXSDSchemaString();
xsd = Util.formatXsdSource(xsd);
WSDataModel wsDataModel = (WSDataModel) xobject.getWsObject();
wsDataModel.setXsdSchema(xsd);
IFile file = getXSDFile(xobject);
// $NON-NLS-1$
file.setCharset("utf-8", null);
// $NON-NLS-1$
file.setContents(new ByteArrayInputStream(xsd.getBytes("utf-8")), IFile.FORCE, null);
}
}
} catch (SAXParseException ex) {
// do nothing
} catch (Exception e) {
log.error(e.getMessage(), e);
}
}
Aggregations