use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class DataModelMainPage method fillContextMenu.
protected void fillContextMenu(IMenuManager manager, boolean isType) {
IStructuredSelection selection;
if (!isType) {
selection = ((IStructuredSelection) viewer.getSelection());
} else {
selection = ((IStructuredSelection) typesViewer.getSelection());
}
Object[] selectedObjs = selection.toArray();
Object obj = selection.getFirstElement();
if (!isType) {
manager.add(newConceptAction);
} else {
manager.add(newComplexTypeAction);
manager.add(newSimpleTypeAction);
// add by ymli; fix the bug:0012228. Made the multiple types can be deleted.
XSDDeleteTypeDefinition deleteTypeDefinition1;
if (selectedObjs.length > 1) {
deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, true);
} else {
deleteTypeDefinition1 = new XSDDeleteTypeDefinition(this, false);
}
if (selectedObjs.length >= 1 && deleteTypeDefinition1.isTypeDefinition(selectedObjs)) {
manager.add(deleteTypeDefinition1);
}
deleteConceptWrapAction.regisExtraClassToDel(XSDComplexTypeDefinitionImpl.class);
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
manager.add(deleteConceptWrapAction.outPutDeleteActions());
if (deleteConceptWrapAction.checkOutAllConcept(selectedObjs)) {
manager.add(newBrowseItemAction);
}
}
if (exAdapter != null && obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1) {
exAdapter.fillContextMenu(manager);
}
}
manager.add(new Separator());
if (!isType && ((selection == null) || (selection.getFirstElement() == null))) {
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 0) {
manager.add(new Separator(ADDITIONMENUID));
// add by ymli, fix bug 0009770
// $NON-NLS-1$
String title = "";
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
title = Messages.PasteEntityText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
title = Messages.PasteEntitiesText;
}
XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
if (pasteConceptAction.checkInPasteType()) {
manager.add(new Separator());
manager.add(pasteConceptAction);
}
}
return;
}
// Element Declaration
if (obj instanceof XSDElementDeclaration && selectedObjs.length == 1) {
// check if concept or "just" element
XSDElementDeclaration decl = (XSDElementDeclaration) obj;
boolean isConcept = Util.checkConcept(decl);
if (!Util.IsAImporedElement(decl, xsdSchema)) {
if (isConcept) {
manager.add(editConceptAction);
manager.add(deleteConceptAction);
manager.add(newBrowseItemAction);
} else {
manager.add(editElementAction);
manager.add(deleteElementAction);
}
// add by ymli. fix bug 0009770 add the copy of concepts
copyConceptAction.setText(Messages.CopyEntityText);
if (Util.checkInCopy(selectedObjs)) {
manager.add(new Separator());
manager.add(copyConceptAction);
}
/*
* boolean isMulti = false; if(WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size()>1)
* isMulti = true;
*/
// $NON-NLS-1$
String title = "";
if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() > 1) {
title = Messages.PasteEntitiesText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getConcepts().size() == 1) {
title = Messages.PasteEntityText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() > 1) {
title = Messages.PasteElementsText;
} else if (WorkbenchClipboard.getWorkbenchClipboard().getParticles().size() == 1) {
title = Messages.PasteElement;
}
XSDPasteConceptAction pasteConceptAction = new XSDPasteConceptAction(this, title);
if (pasteConceptAction.checkInPasteType()) {
manager.add(pasteConceptAction);
}
manager.add(new Separator());
manager.add(newElementAction);
manager.add(new Separator());
manager.add(changeToComplexTypeAction);
manager.add(changeToSimpleTypeAction);
// add by fliu, see bugID:0009157
if (((XSDElementDeclaration) obj).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
manager.add(setFacetMsgAction);
manager.add(setAnnotationDisplayFomatAction);
}
manager.add(new Separator());
manager.add(newIdentityConstraintAction);
} else {
if (isConcept) {
manager.add(newBrowseItemAction);
}
manager.add(newElementAction);
}
// Annotations
if (!Util.IsAImporedElement(decl, xsdSchema) || !Util.IsAImporedElement(decl.getTypeDefinition(), xsdSchema)) {
setAnnotationActions2(obj, manager);
}
}
// add by rhou.fix bug 0012073: Enable to create element from sub element group
if (obj instanceof XSDModelGroup) {
manager.add(new Separator());
manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
manager.add(new Separator());
manager.add(changeSubElementGroupAction);
manager.add(new Separator());
manager.add(setAnnotationLabelAction);
addPasteElementAction(manager);
}
if (obj instanceof XSDAttributeUse && selectedObjs.length == 1) {
manager.add(deleteAttributeAction);
}
if (obj instanceof XSDAttributeDeclaration && selectedObjs.length == 1) {
manager.add(deleteAttributeAction);
}
if (obj instanceof XSDParticle && selectedObjs.length == 1) {
XSDTerm term = ((XSDParticle) obj).getTerm();
if (!(term instanceof XSDWildcard)) {
if (term instanceof XSDElementDeclaration) {
manager.add(editParticleAction);
if (!Util.IsAImporedElement(term, xsdSchema) || term.getContainer() instanceof XSDSchema) {
manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
if (term instanceof XSDModelGroup) {
manager.add(getAddElementMenuForTypeClass(XSDModelGroup.class, Messages._AddElement));
manager.add(newGroupFromTypeAction);
}
manager.add(deleteParticleAction);
// edit by ymli. fix the bug:0011523
copyConceptAction.setText(Messages.CopyElementText);
manager.add(copyConceptAction);
if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDComplexTypeDefinition) {
addPasteElementAction(manager);
}
manager.add(new Separator());
manager.add(changeToComplexTypeAction);
manager.add(changeToSimpleTypeAction);
// add by fliu, see bugID:0009157
manager.add(new Separator());
// Annotations
XSDTypeDefinition type = ((XSDElementDeclaration) term).getTypeDefinition();
setAnnotationActions(obj, manager);
if (((XSDElementDeclaration) term).getTypeDefinition() instanceof XSDSimpleTypeDefinition) {
manager.add(setFacetMsgAction);
manager.add(setAnnotationDisplayFomatAction);
}
// Xpath
manager.add(new Separator());
manager.add(getXPathAction);
}
}
}
}
if (obj instanceof XSDComplexTypeDefinition && selectedObjs.length == 1 && ((XSDComplexTypeDefinition) obj).getTargetNamespace() == null) {
if (!isType && !Util.IsAImporedElement((XSDParticle) obj, xsdSchema)) {
manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
manager.add(newGroupFromTypeAction);
}
if (!Util.IsAImporedElement((XSDComplexTypeDefinition) obj, xsdSchema)) {
// add by rhou.fix bug 0012073: Enable to create element from sub element group
manager.add(new Separator());
manager.add(getAddElementMenuForTypeClass(XSDComplexTypeDefinition.class, Messages._AddElement));
manager.add(new Separator());
manager.add(editComplexTypeAction);
}
manager.add(setAnnotationLabelAction);
addPasteElementAction(manager);
}
if (obj instanceof XSDIdentityConstraintDefinition && selectedObjs.length == 1 && ((XSDIdentityConstraintDefinition) obj).getTargetNamespace() == null && !Util.IsAImporedElement((XSDIdentityConstraintDefinition) obj, xsdSchema)) {
manager.add(deleteIdentityConstraintAction);
manager.add(new Separator());
manager.add(newXPathAction);
}
if (obj instanceof XSDXPathDefinition && selectedObjs.length == 1 && ((XSDXPathDefinition) obj).getSchema().getTargetNamespace() == null && !Util.IsAImporedElement((XSDXPathDefinition) obj, xsdSchema)) {
manager.add(editXPathAction);
manager.add(newXPathAction);
XSDXPathDefinition xpath = (XSDXPathDefinition) obj;
if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) {
manager.add(deleteXPathAction);
}
}
// for the anonymous simpleType
if (obj instanceof XSDSimpleTypeDefinition && selectedObjs.length == 1 && (!Util.IsAImporedElement((XSDSimpleTypeDefinition) obj, xsdSchema) || ((XSDSimpleTypeDefinition) obj).getName() == null)) {
XSDSimpleTypeDefinition typedef = (XSDSimpleTypeDefinition) obj;
manager.add(changeBaseTypeAction);
manager.add(new Separator());
if (typedef.getBaseTypeDefinition() != null) {
EList list = typedef.getBaseTypeDefinition().getValidFacets();
for (Iterator iter = list.iterator(); iter.hasNext(); ) {
String element = (String) iter.next();
manager.add(new XSDEditFacetAction(this, element));
}
}
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInDeletableType(selectedObjs)) {
deleteConceptWrapAction.prepareToDelSelectedItems(selection, viewer);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.checkInAllElementType(selectedObjs)) {
manager.add(newBrowseItemAction);
}
if (selectedObjs.length > 1 && deleteConceptWrapAction.outPutDeleteActions() != null) {
if (!isType) {
manager.add(deleteConceptWrapAction.outPutDeleteActions());
}
// $NON-NLS-1$
String title = "";
if (Util.checkInCopyTypeElement(selectedObjs)) {
title = Messages.CopyEntitiesText;
} else if (Util.checkInCOpyTypeParticle(selectedObjs)) {
title = Messages.CopyElements;
}
copyConceptAction.setText(title);
if (Util.checkInCopy(selectedObjs)) {
manager.add(copyConceptAction);
}
// add by ymli; fix bug:0016645
if (selectedObjs.length > 1 && isXSDParticles(selectedObjs)) {
manager.add(getAddElementMenuForTypeClass(XSDParticle.class, Messages._AddElementAfter));
}
}
if (exAdapter != null) {
exAdapter.fillContextMenu(manager, selectedObjs);
}
// available models
java.util.List<IAvailableModel> availablemodels = AvailableModelUtil.getAvailableModels(isLocalInput());
for (int i = 0; i < availablemodels.size(); i++) {
IAvailableModel model = availablemodels.get(i);
model.fillContextMenu(obj, manager, this, dataModelName);
if (i == 1) {
manager.add(new Separator());
}
}
//
manager.add(new Separator());
drillDownAdapter.addNavigationActions(manager);
// Other plug-ins can contribute there actions here
manager.add(new Separator(ADDITIONMENUID));
deleteConceptWrapAction.clearExtraClassToDel();
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class DataModelMainPage method openXSDParticleInSchemaTree.
private void openXSDParticleInSchemaTree() {
for (Object eachSelectedObj : getSelectionInSchemaTree()) {
viewer.collapseToLevel(eachSelectedObj, 3);
if (eachSelectedObj instanceof XSDModelGroup) {
viewer.expandToLevel(eachSelectedObj, 1);
}
if (eachSelectedObj instanceof XSDElementDeclaration) {
viewer.expandToLevel(eachSelectedObj, 1);
XSDTypeDefinition type = ((XSDElementDeclaration) eachSelectedObj).getTypeDefinition();
if (type instanceof XSDComplexTypeDefinition) {
XSDModelGroup mg = (XSDModelGroup) ((XSDParticle) ((XSDComplexTypeDefinition) type).getContent()).getTerm();
viewer.expandToLevel(mg, 1);
}
}
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class DataModelMainPage method doImportSchema.
protected void doImportSchema(final Collection<XSDSchemaContent> addtional) {
if (null == addtional || addtional.isEmpty()) {
return;
}
try {
int flag = ConflictDialog.NONE;
boolean dialogPopup = false;
List<XSDSchemaContent> contents = xsdSchema.getContents();
List<XSDSchemaContent> exists = new ArrayList<XSDSchemaContent>(contents);
for (XSDSchemaContent content : addtional) {
XSDSchemaContent exist = getContainedSchemaContent(exists, content);
if (null == exist) {
Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
xsdSchema.getElement().appendChild(importElement);
} else {
if (!dialogPopup) {
String type = null;
if (exist instanceof XSDElementDeclaration) {
type = Messages.DataModelMainPage_entity;
} else if (exist instanceof XSDTypeDefinition) {
type = Messages.DataModelMainPage_type;
} else {
continue;
}
LabelProvider provider = getContentLabelProvider(exist);
String message = Messages.bind(Messages.conflict_messages, type, provider.getText(exist));
ConflictDialog dialog = new ConflictDialog(getSite().getShell(), message);
if (dialog.open() == Dialog.OK) {
flag = dialog.getStatus();
dialogPopup = dialog.applyAll;
} else {
popupImportDialog();
return;
}
}
if (flag == ConflictDialog.OVERWRITE) {
contents.remove(exist);
Node importElement = xsdSchema.getDocument().importNode(content.getElement(), true);
xsdSchema.getElement().appendChild(importElement);
}
}
}
//
validateSchema();
markDirtyWithoutCommit();
setXsdSchema(xsdSchema);
getSchemaRoleFilterFromSchemaTree().setDataModelFilter(dataModelFilter);
// refresh types
viewer.setInput(getSite());
typesViewer.setInput(getSite());
MessageDialog.openInformation(getSite().getShell(), Messages.ImportXSDSche, Messages.ImportingXSDSchemaCompleted);
} catch (Exception ex) {
log.error(ex.getMessage(), ex);
// $NON-NLS-1$
String detail = "";
if (ex.getMessage() != null && !ex.getMessage().equals("")) {
// $NON-NLS-1$
// $NON-NLS-1$
detail += " , " + Messages.bind(Messages.Dueto, ex.getMessage());
}
MessageDialog.openError(getSite().getShell(), Messages._Error, Messages.bind(Messages.ImportingXSDSchemaFailed, detail));
}
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class XSDNewConceptAction method doAction.
@Override
public IStatus doAction() {
try {
List<String> customTypes = new ArrayList<String>();
for (Iterator<XSDTypeDefinition> iter = schema.getTypeDefinitions().iterator(); iter.hasNext(); ) {
XSDTypeDefinition type = iter.next();
if (type instanceof XSDSimpleTypeDefinition) {
customTypes.add(// $NON-NLS-1$ //$NON-NLS-2$
type.getName() + (type.getTargetNamespace() != null ? " : " + type.getTargetNamespace() : ""));
}
}
List<String> builtInTypes = new ArrayList<String>();
for (Iterator<XSDTypeDefinition> iter = schema.getSchemaForSchema().getTypeDefinitions().iterator(); iter.hasNext(); ) {
XSDTypeDefinition type = iter.next();
if (type instanceof XSDSimpleTypeDefinition) {
builtInTypes.add(type.getName());
}
}
NewConceptOrElementDialog id = new NewConceptOrElementDialog(this, page.getSite().getShell(), schema, Messages.XSDNewConceptAction_NewEntity, customTypes, builtInTypes);
id.setBlockOnOpen(true);
id.open();
if (id.getReturnCode() == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewConceptAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
use of org.eclipse.xsd.XSDTypeDefinition in project tmdm-studio-se by Talend.
the class XSDNewElementAction method doAction.
@Override
public IStatus doAction() {
try {
List<String> customTypes = new ArrayList<String>();
for (Iterator<XSDTypeDefinition> iter = schema.getTypeDefinitions().iterator(); iter.hasNext(); ) {
XSDTypeDefinition type = iter.next();
if (type instanceof XSDSimpleTypeDefinition) {
customTypes.add(// $NON-NLS-1$ //$NON-NLS-2$
type.getName() + (type.getTargetNamespace() != null ? " : " + type.getTargetNamespace() : ""));
}
}
List<String> builtInTypes = new ArrayList<String>();
for (Iterator<XSDTypeDefinition> iter = schema.getSchemaForSchema().getTypeDefinitions().iterator(); iter.hasNext(); ) {
XSDTypeDefinition type = iter.next();
if (type instanceof XSDSimpleTypeDefinition) {
builtInTypes.add(type.getName());
}
}
NewConceptOrElementDialog id = new NewConceptOrElementDialog(this, page.getSite().getShell(), schema, Messages.XSDNewElementAction_Text, customTypes, builtInTypes);
id.setBlockOnOpen(true);
id.open();
if (id.getReturnCode() == Window.CANCEL) {
return Status.CANCEL_STATUS;
}
} catch (Exception e) {
log.error(e.getMessage(), e);
MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewElementAction_ErrorMsg, e.getLocalizedMessage()));
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
Aggregations