List of usage examples for org.eclipse.jface.dialogs MessageDialog openConfirm
public static boolean openConfirm(Shell parent, String title, String message)
From source file:codesnippetapp.handlers.QuitHandler.java
License:Open Source License
@Execute public void execute(IWorkbench workbench, IEclipseContext context, @Named(IServiceConstants.ACTIVE_SHELL) Shell shell, SnippetRepository repository) throws InvocationTargetException, InterruptedException { if (MessageDialog.openConfirm(shell, "Confirmation", "Do you want to exit?")) { int ret = Utils.confirmRepositorySave(repository, shell); if (ret == 2) //cancel return; workbench.close();// w ww .j av a2 s . c o m } }
From source file:com.aliyun.odps.eclipse.utils.DialogUtil.java
License:Apache License
public static boolean confirm(String title, String msg) { return MessageDialog.openConfirm(Display.getDefault().getActiveShell(), title, msg); }
From source file:com.amalto.workbench.actions.XSDAddComplexTypeElementAction.java
License:Open Source License
private boolean updateCompositorType(XSDTypeDefinition superType, XSDModelGroup currentGroup) { XSDParticle superTypeParticle = superType.getComplexType(); XSDTerm term = superTypeParticle.getTerm(); if (term instanceof XSDModelGroup) { XSDModelGroup group = (XSDModelGroup) term; if (group.getCompositor() == XSDCompositor.ALL_LITERAL || currentGroup.getCompositor() == XSDCompositor.ALL_LITERAL) { if (MessageDialog.openConfirm(null, Messages._ChangeToSequenceType, Messages._ComplexTypeToSequence)) { group.setCompositor(XSDCompositor.SEQUENCE_LITERAL); superTypeParticle.updateElement(); currentGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); currentGroup.updateElement(); return true; }//from ww w . jav a 2s . c o m return false; } } return true; }
From source file:com.amalto.workbench.actions.XSDChangeToComplexTypeAction.java
License:Open Source License
@Override public IStatus doAction() { try {//from ww w. ja v a 2 s. c om IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); isConcept = false; TreePath tPath = null; if (((TreeSelection) selection).getPaths().length > 0) { tPath = ((TreeSelection) selection).getPaths()[0]; } // fliu // add declNew to support convert action invoked from new concept/new element menu, in this case // declNew is the new created one not the selected one in tree vew if (declNew != null) { decl = declNew; checkConcept(); } else if (selection.getFirstElement() instanceof XSDModelGroup) { for (int i = 0; i < tPath.getSegmentCount(); i++) { if (tPath.getSegment(i) instanceof XSDElementDeclaration) { decl = (XSDElementDeclaration) tPath.getSegment(i); } else if (tPath.getSegment(i) instanceof XSDParticle) { decl = (XSDElementDeclaration) ((XSDParticle) tPath.getSegment(i)).getTerm(); } } checkConcept(); } else if (selection.getFirstElement() instanceof XSDElementDeclaration) { decl = (XSDElementDeclaration) selection.getFirstElement(); // check if concept or "just" element checkConcept(); } else if (selection.getFirstElement() instanceof XSDParticle) { // if it's a particle,it should change the element of its // content decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getContent(); } else { // if(selection.getFirstElement() instanceof XSDParticle ) if (selection.getFirstElement() != null) { // a sub element decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm(); } } // /save current Type Definition // XSDTypeDefinition current = decl.getTypeDefinition(); List<XSDComplexTypeDefinition> types = Util.getComplexTypes(decl.getSchema()); if (showDlg) { if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) { boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning, Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning); if (!confirm) { return Status.CANCEL_STATUS; } } if (tPath != null) { for (int i = 0; i < tPath.getSegmentCount(); i++) { if (tPath.getSegment(i) instanceof XSDElementDeclaration) { XSDTypeDefinition type = (((XSDElementDeclaration) tPath.getSegment(i)) .getTypeDefinition()); if (!type.equals(decl.getTypeDefinition())) { types.remove(type); } } if (tPath.getSegment(i) instanceof XSDParticle) { XSDTypeDefinition type = ((XSDElementDeclaration) (((XSDParticle) tPath.getSegment(i)) .getTerm())).getTypeDefinition(); if (!type.equals(decl.getTypeDefinition())) { types.remove(type); } } } } dialog = new ComplexTypeInputDialog(this, page.getSite().getShell(), "", schema, //$NON-NLS-1$ decl.getTypeDefinition(), types, isXSDModelGroup); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Dialog.CANCEL) { return Status.CANCEL_STATUS; } } if (!showDlg && !validateType()) { return Status.CANCEL_STATUS; } XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); boolean anonymous = (typeName == null) || ("".equals(typeName));//$NON-NLS-1$ boolean alreadyExists = false; XSDComplexTypeDefinition complexType = null; // the sub element created if needed XSDParticle subParticle = null; XSDParticle groupParticle = null; XSDElementDeclaration subElement = null; // check if already exist // add by ymli; fix the bug:0012278; XSDElementDeclaration parent = null; Object pObject = Util.getParent(decl); if (pObject instanceof XSDElementDeclaration) { parent = (XSDElementDeclaration) pObject; } if (!anonymous) { List<XSDComplexTypeDefinition> list = Util.getComplexTypes(schema); if (typeName.lastIndexOf(" : ") != -1) {//$NON-NLS-1$ typeName = typeName.substring(0, typeName.lastIndexOf(" : "));//$NON-NLS-1$ } for (XSDComplexTypeDefinition td : list) { if ((td.getName().equals(typeName))) { alreadyExists = true; complexType = td; break; } } } else { XSDComplexTypeDefinition declComplexType = null; if (parent != null && decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) { declComplexType = (XSDComplexTypeDefinition) decl.getTypeDefinition(); } if (declComplexType != null && declComplexType.getSchema() != null && declComplexType.getName() == null) { alreadyExists = true; } if (decl.getTypeDefinition() instanceof XSDSimpleTypeDefinition) { alreadyExists = false; } } if (alreadyExists) { XSDParticle partCnt = (XSDParticle) complexType.getContentType(); partCnt.unsetMaxOccurs(); partCnt.unsetMinOccurs(); XSDTypeDefinition superType = null; for (XSDTypeDefinition type : types) { if (type.getName().equals(superTypeName)) { superType = type; break; } } if (superType != null) { XSDModelGroup mdlGrp = (XSDModelGroup) partCnt.getTerm(); boolean status = updateCompositorType(superType, mdlGrp); if (!status) { return Status.CANCEL_STATUS; } complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); complexType.setBaseTypeDefinition(superType); } if (isAbstract) { complexType.setAbstract(isAbstract); } else { complexType.unsetAbstract(); } if (parent != null) { parent.updateElement(); } if (complexType != null) { complexType.updateElement(); } } else {// Create if does not exist // add an element declaration subElement = factory.createXSDElementDeclaration(); if (declNew != null) { // crate a new entity if (declNew.getName() != null) { subElement.setName(declNew.getName() + "Id");//$NON-NLS-1$ } } else { // create a complex element subElement.setName("subelement");//$NON-NLS-1$ } subElement.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$ subParticle = factory.createXSDParticle(); subParticle.unsetMaxOccurs(); subParticle.unsetMinOccurs(); subParticle.setContent(subElement); subParticle.updateElement(); // create group XSDModelGroup group = factory.createXSDModelGroup(); if (isChoice) { group.setCompositor(XSDCompositor.CHOICE_LITERAL); } else if (isAll) { group.setCompositor(XSDCompositor.ALL_LITERAL); } else { group.setCompositor(XSDCompositor.SEQUENCE_LITERAL); } group.getContents().add(0, subParticle); group.updateElement(); // create the complex type complexType = factory.createXSDComplexTypeDefinition(); if (!anonymous) { XSDTypeDefinition superType = null; for (XSDTypeDefinition type : types) { if (type.getName().equals(superTypeName)) { superType = type; break; } } complexType.setName(typeName); if (superType != null) { complexType.setDerivationMethod(XSDDerivationMethod.EXTENSION_LITERAL); complexType.setBaseTypeDefinition(superType); updateCompositorType(superType, group); } if (isAbstract) { complexType.setAbstract(isAbstract); } else { complexType.unsetAbstract(); } schema.getContents().add(complexType); } complexType.updateElement(); // add the group groupParticle = factory.createXSDParticle(); groupParticle.unsetMaxOccurs(); groupParticle.unsetMinOccurs(); groupParticle.setContent(group); groupParticle.updateElement(); complexType.setContent(groupParticle); complexType.updateElement(); } // end if NOT already exusts // set complex type to concept if (anonymous) { decl.setAnonymousTypeDefinition(complexType); } else { decl.setTypeDefinition(complexType); } if (isConcept) { buildUniqueKey(factory, decl, complexType, anonymous, alreadyExists); } // if isConcept decl.updateElement(); schema.update(); page.refresh(); declNew = null; page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeToCXX_ErrorMsg1, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDChangeToSimpleTypeAction.java
License:Open Source License
@Override public IStatus doAction() { try {/* w w w. j a va2 s . co m*/ XSDElementDeclaration decl = null; IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); // fliu // add declNew to support convert action invoked from new concept/new element menu, in this case // declNew is the new created one not the selected one in tree vew if (declNew != null) { decl = declNew; } else if (selection.getFirstElement() instanceof XSDElementDeclaration) { isConcept = true; decl = (XSDElementDeclaration) selection.getFirstElement(); } else { isConcept = false; if (selection.getFirstElement() != null) { decl = (XSDElementDeclaration) ((XSDParticle) selection.getFirstElement()).getTerm(); } } // build list of custom types and built in types List<String> customTypes = new ArrayList<String>(); for (XSDTypeDefinition type : schema.getTypeDefinitions()) { if (type instanceof XSDSimpleTypeDefinition) { if (type.getTargetNamespace() != null && !type.getTargetNamespace().equals(XSDConstants.SCHEMA_FOR_SCHEMA_URI_2001) || type.getTargetNamespace() == null) { customTypes.add(type.getName()); } } } List<String> builtInTypes = XSDUtil.getBuiltInTypes(); if (showDlg) { String name = decl.getTypeDefinition().getName(); if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) { name = null; boolean confirm = MessageDialog.openConfirm(page.getSite().getShell(), Messages.Warning, Messages.XSDChangeToCXX_ChangeToAnotherTypeWarning); if (!confirm) { return Status.CANCEL_STATUS; } } dialog = new SimpleTypeInputDialog(this, page.getSite().getShell(), schema, Messages.XSDChangeToXX_DialogTitle, customTypes, builtInTypes, name); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Window.CANCEL) { return Status.CANCEL_STATUS; } } // if concept // remove all unique keys and make new one if (isConcept) { // remove exisitng unique key(s) ArrayList keys = new ArrayList(); EList list = decl.getIdentityConstraintDefinitions(); for (Iterator iter = list.iterator(); iter.hasNext();) { XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next(); if (icd.getIdentityConstraintCategory().equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) { keys.add(icd); } } decl.getIdentityConstraintDefinitions().removeAll(keys); // add new unique Key XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDIdentityConstraintDefinition uniqueKey = factory.createXSDIdentityConstraintDefinition(); uniqueKey.setIdentityConstraintCategory(XSDIdentityConstraintCategory.UNIQUE_LITERAL); uniqueKey.setName(decl.getName()); XSDXPathDefinition selector = factory.createXSDXPathDefinition(); selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL); selector.setValue(".");//$NON-NLS-1$ uniqueKey.setSelector(selector); XSDXPathDefinition field = factory.createXSDXPathDefinition(); field.setVariety(XSDXPathVariety.FIELD_LITERAL); field.setValue(".");//$NON-NLS-1$ uniqueKey.getFields().add(field); decl.getIdentityConstraintDefinitions().add(uniqueKey); } // Save current type definition XSDTypeDefinition current = decl.getTypeDefinition(); // set new one if (builtIn) { decl.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), typeName)); } else { // check if concept already exists if (typeName != null && typeName.length() > 0) { XSDSimpleTypeDefinition std = null; String ns = "";//$NON-NLS-1$ if (typeName.lastIndexOf(" : ") != -1) {//$NON-NLS-1$ ns = typeName.substring(typeName.lastIndexOf(" : ") + 3);//$NON-NLS-1$ typeName = typeName.substring(0, typeName.lastIndexOf(" : "));//$NON-NLS-1$ } for (XSDTypeDefinition typeDef : schema.getTypeDefinitions()) { if (typeDef instanceof XSDSimpleTypeDefinition) { if (typeDef.getName().equals(typeName)) { std = (XSDSimpleTypeDefinition) typeDef; break; } } } if (std == null) { std = schema.resolveSimpleTypeDefinition(typeName); std.setBaseTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$ if (typeName.equals(EUUIDCustomType.MULTI_LINGUAL.getName())) { XSDPatternFacet f = XSDSchemaBuildingTools.getXSDFactory().createXSDPatternFacet(); f.setLexicalValue("(\\[\\w+\\:[^\\[\\]]*\\]){0,}");//$NON-NLS-1$ std.getFacetContents().add(f); } schema.getContents().add(std); } decl.setTypeDefinition(std); } else { XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); simpleType = factory.createXSDSimpleTypeDefinition(); simpleType.setBaseTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$ decl.setAnonymousTypeDefinition(simpleType); } } decl.updateElement(); // remove current if no more in use // if (current != null) { // if ( (current.getName()!=null) && //anonymous type // (!schema.getSchemaForSchemaNamespace().equals(current.getTargetNamespace())) // ){ // List eut =Util.findElementsUsingType(schema, current.getTargetNamespace(), current.getName()); // if (eut.size()==0) // schema.getContents().remove(current); // } // } declNew = null; page.refresh(); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDChangeToXX_ErrorMsg1, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDDeleteConceptAction.java
License:Open Source License
@Override public IStatus doAction() { try {/*ww w . j a v a 2 s . com*/ // xsdElem is to support the multiple delete action on key press, // which each delete action on concept must be explicit passed a xsdElem to // delete XSDElementDeclaration decl = toDeleteElement; if (decl == null) { ISelection selection = page.getTreeViewer().getSelection(); decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement(); } deletedEntityName = decl.getName(); // check if contains fk if (checkContainFK(decl.getName())) { boolean confirmed = MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteConceptAction_ConfirmDel, Messages.bind(Messages.XSDDeleteConceptAction_ConfirmInfo, decl.getName())); if (!confirmed) { return Status.CANCEL_STATUS; } } // check if refered by boolean isReferenced = isCommonReferedBy(decl); if (isReferenced) { boolean confirmed = MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteConceptAction_ConfirmDel, Messages.bind(Messages.XSDDeleteConceptAction_ConfirmReferInfo, decl.getName())); if (!confirmed) { return Status.CANCEL_STATUS; } } if (schema == null) { schema = ((ISchemaContentProvider) page.getTreeViewer().getContentProvider()).getXsdSchema(); } schema.getContents().remove(decl); schema.update(); toDeleteElement = null; page.refresh(); page.markDirtyWithoutCommit(); } catch (Exception e) { log.error(e.getMessage(), e); if (!Util.handleConnectionException(page.getSite().getShell(), e, Messages.XSDDeleteConceptAction_ErrorMsg)) { MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteConceptAction_ErrorMsg, e.getLocalizedMessage())); } return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDDeleteConceptWrapAction.java
License:Open Source License
@Override public IStatus doAction() { List<IStatus> results = new ArrayList<IStatus>(); try {//from w w w . ja v a2 s . co m IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); if (delObjs.isEmpty()) { return Status.CANCEL_STATUS; } else { boolean sameType = checkInSameClassType(delObjs.toArray(), delObjs.get(0).getClass()); String deleteLabel = Messages.DelLabel1; String elemDesc = ((Action) clsAction.get(delObjs.get(0).getClass())).getText(); int backPos = elemDesc.indexOf(" "); //$NON-NLS-1$ if (delObjs.size() > 1) { deleteLabel += elemDesc.substring(0, backPos) + Messages.DelLabel2 + delObjs.size() + Messages.DelLabel2A + (!sameType ? Messages.DelLabel2B : elemDesc.substring(backPos + 1)); if (deleteLabel.endsWith("y")) {//$NON-NLS-1$ deleteLabel = deleteLabel.substring(0, deleteLabel.length() - 1) + Messages.DelLabel3; } else { deleteLabel = deleteLabel + Messages.XSDDeleteXX_DelLabel4; } } else { deleteLabel += elemDesc.substring(0, backPos) + Messages.XSDDeleteXX_DelLabel5 + (!sameType ? Messages.XSDDeleteXX_DelLabel5A : elemDesc.substring(backPos + 1)); } if (!MessageDialog.openConfirm(page.getSite().getShell(), Messages.XSDDeleteXX_DialogTitle, deleteLabel)) { return Status.CANCEL_STATUS; } } for (Iterator iterator = delObjs.iterator(); iterator.hasNext();) { Object toDel = iterator.next(); UndoAction delExecute = null; boolean isElem = true; if (toDel instanceof XSDElementDeclaration) { XSDElementDeclaration decl = (XSDElementDeclaration) toDel; EList l = decl.getIdentityConstraintDefinitions(); for (Iterator iter = l.iterator(); iter.hasNext();) { XSDIdentityConstraintDefinition icd = (XSDIdentityConstraintDefinition) iter.next(); if (icd.getIdentityConstraintCategory() .equals(XSDIdentityConstraintCategory.UNIQUE_LITERAL)) { isElem = false; break; } } } if (toDel instanceof XSDXPathDefinition) { XSDXPathDefinition xpath = (XSDXPathDefinition) toDel; if (!xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) { continue; } } delExecute = clsAction.get(toDel.getClass()); if (isElem && toDel instanceof XSDElementDeclaration) { delExecute = clsAction.get(null); } if (delExecute instanceof XSDDeleteConceptAction && toDel instanceof XSDElementDeclaration) { ((XSDDeleteConceptAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel); } else if (delExecute instanceof XSDDeleteElementAction && toDel instanceof XSDElementDeclaration) { ((XSDDeleteElementAction) delExecute).setXSDTODel((XSDElementDeclaration) toDel); } else if (delExecute instanceof XSDDeleteParticleAction && toDel instanceof XSDParticle) { ((XSDDeleteParticleAction) delExecute).setXSDTODel((XSDParticle) toDel); } else if (delExecute instanceof XSDDeleteXPathAction && toDel instanceof XSDXPathDefinition) { ((XSDDeleteXPathAction) delExecute).setXSDTODel((XSDXPathDefinition) toDel); } else if (delExecute instanceof XSDDeleteIdentityConstraintAction && toDel instanceof XSDIdentityConstraintDefinition) { ((XSDDeleteIdentityConstraintAction) delExecute) .setXSDTODel((XSDIdentityConstraintDefinition) toDel); } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDComplexTypeDefinition) { ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDComplexTypeDefinition) toDel); } else if (delExecute instanceof XSDDeleteTypeDefinition && toDel instanceof XSDSimpleTypeDefinition) { ((XSDDeleteTypeDefinition) delExecute).setXSDTODel((XSDSimpleTypeDefinition) toDel); } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeUse) { ((XSDDeleteAttributeAction) delExecute).setXSDAttributeUse((XSDAttributeUse) toDel); } else if (delExecute instanceof XSDDeleteAttributeAction && toDel instanceof XSDAttributeDeclaration) { ((XSDDeleteAttributeAction) delExecute).setXSDAttribute((XSDAttributeDeclaration) toDel); } else { return Status.CANCEL_STATUS; } results.add(delExecute.execute()); } } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteXX_ErrorMsg, e.getLocalizedMessage())); return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS); } return (results.indexOf(Status.OK_STATUS) >= 0 ? Status.OK_STATUS : Status.CANCEL_STATUS); }
From source file:com.amalto.workbench.actions.XSDNewBrowseItemViewAction.java
License:Open Source License
@Override public void doRun() { if (isDirty()) { boolean save = MessageDialog.openConfirm(getShell(), Messages.SaveResource, Messages.bind(Messages.modifiedChanges, getDisplayName())); if (save) { saveEditor();// w w w . ja v a2s . c om } else { return; } } declList.clear(); List elementDeclarations = getSelectedXSDElementDeclarations(); for (Object obj : elementDeclarations) { if (obj instanceof XSDElementDeclaration) { XSDElementDeclaration declaration = (XSDElementDeclaration) obj; if (Util.getParent(obj) == obj) { declList.add(declaration); } } } if (!declList.isEmpty()) { // AddBrowseItemsWizard wizard = getAddBrowseItemsWizard(declList); WizardDialog dialog = new WizardDialog(getShell(), wizard); dialog.open(); } }
From source file:com.amalto.workbench.actions.XSDNewComplexTypeDefinition.java
License:Open Source License
private boolean checkParentType(XSDTypeDefinition superType, XSDModelGroup currentGroup) { XSDParticle complexType = superType.getComplexType(); XSDTerm term = complexType.getTerm(); if (term instanceof XSDModelGroup) { XSDModelGroup group = (XSDModelGroup) term; if (group.getCompositor() == XSDCompositor.ALL_LITERAL) { if (MessageDialog.openConfirm(null, Messages._ChangeToSequenceType, Messages._ComplexTypeToSequence)) { group.setCompositor(XSDCompositor.SEQUENCE_LITERAL); complexType.updateElement(); currentGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); currentGroup.updateElement(); return true; }//from www. ja v a2 s. co m return false; } } return true; }
From source file:com.amalto.workbench.actions.XSDPasteConceptAction.java
License:Open Source License
public void copyElements() { ArrayList<XSDParticle> particles = WorkbenchClipboard.getWorkbenchClipboard().getParticles(); IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); XSDComplexTypeContent content = null; XSDElementDeclaration element = null; if (selection.getFirstElement() instanceof XSDElementDeclaration) { element = (XSDElementDeclaration) selection.getFirstElement(); content = ((XSDComplexTypeDefinition) element.getTypeDefinition()).getContent(); } else if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) { content = ((XSDComplexTypeDefinition) selection.getFirstElement()).getContent(); } else if (selection.getFirstElement() instanceof XSDModelGroup) { XSDComplexTypeDefinition complexType = (XSDComplexTypeDefinition) ((XSDModelGroup) selection .getFirstElement()).getContainer().getContainer(); content = complexType.getContent(); } else {//from ww w. j av a2 s. c o m if (selection.getFirstElement() instanceof XSDParticle) { XSDParticle particle = (XSDParticle) selection.getFirstElement(); XSDElementDeclaration declar = (XSDElementDeclaration) particle.getTerm(); if (declar.getTypeDefinition() instanceof XSDComplexTypeDefinition) { XSDComplexTypeDefinition typeDefinition = (XSDComplexTypeDefinition) declar.getTypeDefinition(); content = typeDefinition.getContent(); } } } if (content instanceof XSDParticle) { XSDParticle partile = (XSDParticle) content; if (partile.getTerm() instanceof XSDModelGroup) { XSDModelGroup toGroup = ((XSDModelGroup) partile.getTerm()); for (XSDParticle particle : particles) { // if the is particle with the same name, donot copy it. if (isExist(toGroup, particle)) { boolean ifOverwrite = MessageDialog.openConfirm(this.page.getSite().getShell(), Messages.XSDPasteConceptAction_Confirm, Messages.bind(Messages.XSDPasteConceptAction_ErrorMsg3, ((XSDElementDeclaration) particle.getTerm()).getName())); if (ifOverwrite) { reomveElement(toGroup, particle); } else { continue; } } XSDParticle newParticle = (XSDParticle) particle.cloneConcreteComponent(true, false); if (newParticle.getContent() instanceof XSDElementDeclaration && Util.changeElementTypeToSequence(element, newParticle.getMaxOccurs()) == Status.CANCEL_STATUS) { break; } toGroup.getContents().add(newParticle); toGroup.updateElement(); if (newParticle.getContent() instanceof XSDElementDeclaration) { if (((XSDElementDeclaration) newParticle.getContent()) .getTypeDefinition() instanceof XSDComplexTypeDefinition) { addAnnotationForComplexType( (XSDComplexTypeDefinition) ((XSDElementDeclaration) particle.getContent()) .getTypeDefinition(), (XSDComplexTypeDefinition) ((XSDElementDeclaration) newParticle.getContent()) .getTypeDefinition()); } XSDAnnotationsStructure struc1 = new XSDAnnotationsStructure(newParticle.getTerm()); addAnnotion(struc1, ((XSDElementDeclaration) particle.getTerm()).getAnnotation()); Util.changeElementTypeToSequence((XSDElementDeclaration) newParticle.getContent(), newParticle.getMaxOccurs()); } } } } }