Search in sources :

Example 1 with XSDDeleteTypeDefinition

use of com.amalto.workbench.actions.XSDDeleteTypeDefinition 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();
}
Also used : XSDAttributeUse(org.eclipse.xsd.XSDAttributeUse) XSDModelGroup(org.eclipse.xsd.XSDModelGroup) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) XSDTypeDefinition(org.eclipse.xsd.XSDTypeDefinition) Iterator(java.util.Iterator) XSDTerm(org.eclipse.xsd.XSDTerm) XSDComplexTypeDefinition(org.eclipse.xsd.XSDComplexTypeDefinition) XSDXPathDefinition(org.eclipse.xsd.XSDXPathDefinition) XSDParticle(org.eclipse.xsd.XSDParticle) XSDSchema(org.eclipse.xsd.XSDSchema) IAvailableModel(com.amalto.workbench.availablemodel.IAvailableModel) XSDSimpleTypeDefinition(org.eclipse.xsd.XSDSimpleTypeDefinition) XSDPasteConceptAction(com.amalto.workbench.actions.XSDPasteConceptAction) XSDWildcard(org.eclipse.xsd.XSDWildcard) EList(org.eclipse.emf.common.util.EList) XSDEditFacetAction(com.amalto.workbench.actions.XSDEditFacetAction) XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) XSDIdentityConstraintDefinition(org.eclipse.xsd.XSDIdentityConstraintDefinition) TreeObject(com.amalto.workbench.models.TreeObject) XSDDeleteTypeDefinition(com.amalto.workbench.actions.XSDDeleteTypeDefinition) XSDAttributeDeclaration(org.eclipse.xsd.XSDAttributeDeclaration) Separator(org.eclipse.jface.action.Separator)

Example 2 with XSDDeleteTypeDefinition

use of com.amalto.workbench.actions.XSDDeleteTypeDefinition in project tmdm-studio-se by Talend.

the class DataModelMainPage method createActions.

protected void createActions() {
    this.newConceptAction = new XSDNewConceptAction(this);
    this.deleteConceptAction = (XSDDeleteConceptAction) getAdapter(XSDDeleteConceptAction.class);
    createNewBrowseItemViewAction();
    this.deleteConceptWrapAction = new XSDDeleteConceptWrapAction(this);
    this.newElementAction = new XSDNewElementAction(this);
    this.deleteElementAction = new XSDDeleteElementAction(this);
    this.deleteAttributeAction = new XSDDeleteAttributeAction(this);
    this.changeToComplexTypeAction = new XSDChangeToComplexTypeAction(this, false);
    this.changeSubElementGroupAction = new XSDChangeToComplexTypeAction(this, true);
    this.deleteParticleAction = new XSDDeleteParticleAction(this);
    this.newGroupFromTypeAction = new XSDNewGroupFromTypeAction(this);
    this.copyConceptAction = new XSDCopyConceptAction(this, Messages.CopyEntityText);
    this.editParticleAction = new XSDEditParticleAction(this);
    this.editConceptAction = new XSDEditConceptAction(this);
    this.editElementAction = new XSDEditElementAction(this);
    this.deleteIdentityConstraintAction = new XSDDeleteIdentityConstraintAction(this);
    this.newIdentityConstraintAction = new XSDNewIdentityConstraintAction(this);
    this.deleteXPathAction = new XSDDeleteXPathAction(this);
    this.newXPathAction = new XSDNewXPathAction(this);
    this.editXPathAction = new XSDEditXPathAction(this);
    this.changeToSimpleTypeAction = new XSDChangeToSimpleTypeAction(this);
    this.changeBaseTypeAction = new XSDChangeBaseTypeAction(this);
    this.getXPathAction = new XSDGetXPathAction(this);
    this.setAnnotationLabelAction = new XSDSetAnnotationLabelAction(this);
    this.setAnnotationDescriptionsAction = new XSDSetAnnotationDescriptionsAction(this);
    this.setAnnotationForeignKeyAction = (XSDSetAnnotationForeignKeyAction) getAdapter(XSDSetAnnotationForeignKeyAction.class);
    this.skipToFKAction = new XSDSkipToFKAction(this);
    this.setAnnotationFKFilterAction = (XSDSetAnnotationFKFilterAction) getAdapter(XSDSetAnnotationFKFilterAction.class);
    this.setAnnotationForeignKeyInfoAction = (XSDSetAnnotationForeignKeyInfoAction) getAdapter(XSDSetAnnotationForeignKeyInfoAction.class);
    this.setAnnotationDisplayFomatAction = new XSDSetAnnotaionDisplayFormatAction(this);
    this.setAnnotationLookupFieldsAction = new XSDAnnotationLookupFieldsAction(this);
    this.setAnnotationPrimaryKeyInfoAction = new XSDSetAnnotationPrimaryKeyInfoAction(this);
    this.deleteTypeDefinition = new XSDDeleteTypeDefinition(this);
    this.newComplexTypeAction = new XSDNewComplexTypeDefinition(this);
    this.newSimpleTypeAction = new XSDNewSimpleTypeDefinition(this);
    this.editComplexTypeAction = new XSDEditComplexTypeAction(this);
    this.setFacetMsgAction = new XSDSetFacetMessageAction(this);
    deleteConceptWrapAction.regisDelAction(XSDElementDeclarationImpl.class, deleteConceptAction);
    deleteConceptWrapAction.regisDelAction(XSDParticleImpl.class, deleteParticleAction);
    deleteConceptWrapAction.regisDelAction(XSDAttributeUseImpl.class, deleteAttributeAction);
    deleteConceptWrapAction.regisDelAction(XSDAttributeDeclarationImpl.class, deleteAttributeAction);
    deleteConceptWrapAction.regisDelAction(XSDIdentityConstraintDefinitionImpl.class, deleteIdentityConstraintAction);
    deleteConceptWrapAction.regisDelAction(XSDXPathDefinitionImpl.class, deleteXPathAction);
    deleteConceptWrapAction.regisDelAction(null, deleteElementAction);
    deleteConceptWrapAction.regisDelAction(XSDComplexTypeDefinitionImpl.class, deleteTypeDefinition);
    deleteConceptWrapAction.regisDelAction(XSDSimpleTypeDefinitionImpl.class, deleteTypeDefinition);
    if (exAdapter != null) {
        exAdapter.createActions();
    }
}
Also used : XSDChangeBaseTypeAction(com.amalto.workbench.actions.XSDChangeBaseTypeAction) XSDSetAnnotationPrimaryKeyInfoAction(com.amalto.workbench.actions.XSDSetAnnotationPrimaryKeyInfoAction) XSDSetAnnotaionDisplayFormatAction(com.amalto.workbench.actions.XSDSetAnnotaionDisplayFormatAction) XSDNewComplexTypeDefinition(com.amalto.workbench.actions.XSDNewComplexTypeDefinition) XSDDeleteXPathAction(com.amalto.workbench.actions.XSDDeleteXPathAction) XSDSetAnnotationLabelAction(com.amalto.workbench.actions.XSDSetAnnotationLabelAction) XSDSetAnnotationDescriptionsAction(com.amalto.workbench.actions.XSDSetAnnotationDescriptionsAction) XSDSetFacetMessageAction(com.amalto.workbench.actions.XSDSetFacetMessageAction) XSDSkipToFKAction(com.amalto.workbench.actions.XSDSkipToFKAction) XSDDeleteElementAction(com.amalto.workbench.actions.XSDDeleteElementAction) XSDDeleteParticleAction(com.amalto.workbench.actions.XSDDeleteParticleAction) XSDNewElementAction(com.amalto.workbench.actions.XSDNewElementAction) XSDDeleteIdentityConstraintAction(com.amalto.workbench.actions.XSDDeleteIdentityConstraintAction) XSDNewIdentityConstraintAction(com.amalto.workbench.actions.XSDNewIdentityConstraintAction) XSDChangeToSimpleTypeAction(com.amalto.workbench.actions.XSDChangeToSimpleTypeAction) XSDEditXPathAction(com.amalto.workbench.actions.XSDEditXPathAction) XSDDeleteConceptWrapAction(com.amalto.workbench.actions.XSDDeleteConceptWrapAction) XSDEditConceptAction(com.amalto.workbench.actions.XSDEditConceptAction) XSDNewGroupFromTypeAction(com.amalto.workbench.actions.XSDNewGroupFromTypeAction) XSDEditParticleAction(com.amalto.workbench.actions.XSDEditParticleAction) XSDChangeToComplexTypeAction(com.amalto.workbench.actions.XSDChangeToComplexTypeAction) XSDEditComplexTypeAction(com.amalto.workbench.actions.XSDEditComplexTypeAction) XSDNewXPathAction(com.amalto.workbench.actions.XSDNewXPathAction) XSDGetXPathAction(com.amalto.workbench.actions.XSDGetXPathAction) XSDCopyConceptAction(com.amalto.workbench.actions.XSDCopyConceptAction) XSDNewSimpleTypeDefinition(com.amalto.workbench.actions.XSDNewSimpleTypeDefinition) XSDEditElementAction(com.amalto.workbench.actions.XSDEditElementAction) XSDAnnotationLookupFieldsAction(com.amalto.workbench.actions.XSDAnnotationLookupFieldsAction) XSDNewConceptAction(com.amalto.workbench.actions.XSDNewConceptAction) XSDDeleteAttributeAction(com.amalto.workbench.actions.XSDDeleteAttributeAction) XSDDeleteTypeDefinition(com.amalto.workbench.actions.XSDDeleteTypeDefinition)

Aggregations

XSDDeleteTypeDefinition (com.amalto.workbench.actions.XSDDeleteTypeDefinition)2 XSDAnnotationLookupFieldsAction (com.amalto.workbench.actions.XSDAnnotationLookupFieldsAction)1 XSDChangeBaseTypeAction (com.amalto.workbench.actions.XSDChangeBaseTypeAction)1 XSDChangeToComplexTypeAction (com.amalto.workbench.actions.XSDChangeToComplexTypeAction)1 XSDChangeToSimpleTypeAction (com.amalto.workbench.actions.XSDChangeToSimpleTypeAction)1 XSDCopyConceptAction (com.amalto.workbench.actions.XSDCopyConceptAction)1 XSDDeleteAttributeAction (com.amalto.workbench.actions.XSDDeleteAttributeAction)1 XSDDeleteConceptWrapAction (com.amalto.workbench.actions.XSDDeleteConceptWrapAction)1 XSDDeleteElementAction (com.amalto.workbench.actions.XSDDeleteElementAction)1 XSDDeleteIdentityConstraintAction (com.amalto.workbench.actions.XSDDeleteIdentityConstraintAction)1 XSDDeleteParticleAction (com.amalto.workbench.actions.XSDDeleteParticleAction)1 XSDDeleteXPathAction (com.amalto.workbench.actions.XSDDeleteXPathAction)1 XSDEditComplexTypeAction (com.amalto.workbench.actions.XSDEditComplexTypeAction)1 XSDEditConceptAction (com.amalto.workbench.actions.XSDEditConceptAction)1 XSDEditElementAction (com.amalto.workbench.actions.XSDEditElementAction)1 XSDEditFacetAction (com.amalto.workbench.actions.XSDEditFacetAction)1 XSDEditParticleAction (com.amalto.workbench.actions.XSDEditParticleAction)1 XSDEditXPathAction (com.amalto.workbench.actions.XSDEditXPathAction)1 XSDGetXPathAction (com.amalto.workbench.actions.XSDGetXPathAction)1 XSDNewComplexTypeDefinition (com.amalto.workbench.actions.XSDNewComplexTypeDefinition)1