Search in sources :

Example 1 with EditXSDEleDecNameValidator

use of com.amalto.workbench.utils.inputvalidator.EditXSDEleDecNameValidator in project tmdm-studio-se by Talend.

the class EntityWrapper method init.

private void init() {
    if (sourceEntity != null) {
        name = sourceEntity.getName();
        for (XSDIdentityConstraintDefinition eachId : sourceEntity.getIdentityConstraintDefinitions()) {
            keys.add(new KeyWrapper(eachId));
        }
        nameValidator = new EditXSDEleDecNameValidator(sourceEntity.getSchema());
    }
}
Also used : XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) EditXSDEleDecNameValidator(com.amalto.workbench.utils.inputvalidator.EditXSDEleDecNameValidator)

Example 2 with EditXSDEleDecNameValidator

use of com.amalto.workbench.utils.inputvalidator.EditXSDEleDecNameValidator in project tmdm-studio-se by Talend.

the class XSDEditElementAction method doAction.

@Override
public IStatus doAction() {
    try {
        ISelection selection = page.getTreeViewer().getSelection();
        XSDElementDeclaration decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
        String oldName = decl.getName();
        InputDialog id = new InputDialog(page.getSite().getShell(), Messages.XSDEditElementAction_EditElement, Messages.XSDEditElementAction_EnterNameForElement, oldName, new EditXSDEleDecNameValidator(schema));
        id.setBlockOnOpen(true);
        int ret = id.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        Object[] objs = Util.getAllObject(page.getSite(), objList, provider);
        Object[] allForeignKeyRelatedInfos = Util.getAllForeignKeyRelatedInfos(page.getSite(), new ArrayList<Object>(), provider, new HashSet<Object>());
        decl.setName(id.getValue());
        decl.updateElement();
        Util.updateReference(decl, objs, allForeignKeyRelatedInfos, oldName, id.getValue());
        // change unique key with new name of concept
        EList list = decl.getIdentityConstraintDefinitions();
        XSDIdentityConstraintDefinition toUpdate = null;
        for (Iterator iter = list.iterator(); iter.hasNext(); ) {
            XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next();
            if (icd.getName().equals(oldName)) {
                toUpdate = icd;
                break;
            }
        }
        if (toUpdate != null) {
            toUpdate.setName(id.getValue());
            toUpdate.updateElement();
        }
        page.refresh();
        page.markDirty();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditElementAction_ErrorEditElement, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : InputDialog(org.eclipse.jface.dialogs.InputDialog) ArrayList(java.util.ArrayList) EditXSDEleDecNameValidator(com.amalto.workbench.utils.inputvalidator.EditXSDEleDecNameValidator) EList(org.eclipse.emf.common.util.EList) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Iterator(java.util.Iterator) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition)

Aggregations

EditXSDEleDecNameValidator (com.amalto.workbench.utils.inputvalidator.EditXSDEleDecNameValidator)2 XSDIdentityConstraintDefinition (org.eclipse.xsd.XSDIdentityConstraintDefinition)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 EList (org.eclipse.emf.common.util.EList)1 InputDialog (org.eclipse.jface.dialogs.InputDialog)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 XSDElementDeclaration (org.eclipse.xsd.XSDElementDeclaration)1