List of usage examples for org.eclipse.jface.viewers StructuredSelection StructuredSelection
public StructuredSelection(List elements)
List
. From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java
License:Open Source License
private void addFile() { FileDialog dialog = new FileDialog(getShell(), SWT.NONE); dialog.setText(Resources.getText("dialog.settings.addFile")); dialog.setFilterPath(getCurrentDir().getAbsolutePath()); dialog.setFilterExtensions(ConfiguratorConstant.PACKAGE_FILE_EXTS); String file = dialog.open();//from w w w .j a v a 2 s .c o m if (file != null) { File f = new File(file); files.add(f); filesViewer.refresh(); filesViewer.setSelection(new StructuredSelection(f)); updateCommandLine(); } }
From source file:com.alibaba.antx.config.gui.dialog.SettingsDialog.java
License:Open Source License
private void remove() { StructuredSelection selection = (StructuredSelection) filesViewer.getSelection(); if (!selection.isEmpty()) { File nextFile = removeAndGetNext(files, (File) selection.getFirstElement()); filesViewer.refresh();//from ww w . jav a 2s . c o m updateCommandLine(); if (nextFile != null) { filesViewer.setSelection(new StructuredSelection(nextFile)); } } }
From source file:com.amalto.workbench.actions.XSDAddComplexTypeElementAction.java
License:Open Source License
private boolean createComplexTypeParticle() { try {//from ww w . j a v a2s. c o m XSDParticle particle = createParticle(); boolean flag = transformToComplexType(particle); if (!flag) { modelGroup.getContents().remove(particle); return false; } page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(particle), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._CreateCTypeError, e.getLocalizedMessage())); return false; } return true; }
From source file:com.amalto.workbench.actions.XSDEditXPathAction.java
License:Open Source License
public IStatus doAction() { try {//from www. j av a2s. c o m IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement(); icd = (XSDIdentityConstraintDefinition) xpath.getContainer(); // InputDialog id = new InputDialog( // page.getSite().getShell(), // "Edit XPath", // "Enter a new XPath for the "+((xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL))?"field":"selector"), // xpath.getValue(), // new IInputValidator() { // public String isValid(String newText) { // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty"; // return null; // }; // } // ); // List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer()); List<String> childNames = new ArrayList<String>(); childNames.add("."); //$NON-NLS-1$ SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(), Messages.XSDEditXPathAction_DialogTitle, childNames, xpath.getValue()); id.create(); id.setBlockOnOpen(true); int ret = id.open(); if (ret == Window.CANCEL) { return Status.CANCEL_STATUS; } String field = id.getField(); if (field.length() == 0) return Status.CANCEL_STATUS; XSDXPathDefinition newXpath = XSDSchemaBuildingTools.getXSDFactory().createXSDXPathDefinition(); newXpath.setValue(field); if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) { int index = icd.getFields().indexOf(xpath); newXpath.setVariety(XSDXPathVariety.FIELD_LITERAL); icd.getFields().set(index, newXpath); } else { newXpath.setVariety(XSDXPathVariety.SELECTOR_LITERAL); icd.setSelector(newXpath); } icd.updateElement(); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(newXpath), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDEditXPathAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewGroupFromParticleAction.java
License:Open Source License
public IStatus doAction() { try {//from www.j a v a2s. c o m IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); selParticle = (XSDParticle) selection.getFirstElement(); if (!(selParticle.getContainer() instanceof XSDModelGroup)) return Status.CANCEL_STATUS; XSDModelGroup group = (XSDModelGroup) selParticle.getContainer(); // get position of the selected particle in the container int index = 0; int i = 0; for (Iterator iter = group.getContents().iterator(); iter.hasNext();) { XSDParticle p = (XSDParticle) iter.next(); if (p.equals(selParticle)) { index = i; break; } i++; } dialog = new NewGroupDialog(this, page.getSite().getShell()); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Dialog.CANCEL) { return Status.CANCEL_STATUS; } XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); // add an element declaration XSDElementDeclaration subElement = factory.createXSDElementDeclaration(); subElement.setName("subelement");//$NON-NLS-1$ subElement.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$ XSDParticle subParticle = factory.createXSDParticle(); subParticle.setMinOccurs(1); subParticle.setMaxOccurs(1); subParticle.setContent(subElement); subParticle.updateElement(); XSDModelGroup newGroup = factory.createXSDModelGroup(); if (isChoice) newGroup.setCompositor(XSDCompositor.CHOICE_LITERAL); else if (isAll) newGroup.setCompositor(XSDCompositor.ALL_LITERAL); else newGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); newGroup.getContents().add(0, subParticle); newGroup.updateElement(); XSDParticle particle = factory.createXSDParticle(); particle.setContent(newGroup); particle.setMinOccurs(this.minOccurs); particle.setMaxOccurs(this.maxOccurs); group.getContents().add(index + 1, particle); group.updateElement(); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(particle), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewGroupFromParticleAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.CANCEL_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewGroupFromTypeAction.java
License:Open Source License
public IStatus doAction() { try {/*from w w w. java 2 s .c om*/ IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) { XSDComplexTypeDefinition ctd = (XSDComplexTypeDefinition) selection.getFirstElement(); if (!(ctd.getContent() instanceof XSDParticle)) return Status.CANCEL_STATUS; if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) return Status.CANCEL_STATUS; group = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm(); } else if (selection.getFirstElement() instanceof XSDParticle) { group = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm(); } else { return Status.CANCEL_STATUS; } dialog = new NewGroupDialog(this, page.getSite().getShell()); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Window.CANCEL) { return Status.CANCEL_STATUS; } XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); // add an element declaration XSDElementDeclaration subElement = factory.createXSDElementDeclaration(); subElement.setName("subelement");//$NON-NLS-1$ subElement.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), "string"));//$NON-NLS-1$ XSDParticle subParticle = factory.createXSDParticle(); subParticle.setMinOccurs(1); subParticle.setMaxOccurs(1); subParticle.setContent(subElement); subParticle.updateElement(); XSDModelGroup newGroup = factory.createXSDModelGroup(); if (isChoice) newGroup.setCompositor(XSDCompositor.CHOICE_LITERAL); else if (isAll) newGroup.setCompositor(XSDCompositor.ALL_LITERAL); else newGroup.setCompositor(XSDCompositor.SEQUENCE_LITERAL); newGroup.getContents().add(0, subParticle); newGroup.updateElement(); XSDParticle particle = factory.createXSDParticle(); particle.setContent(newGroup); particle.setMinOccurs(this.minOccurs); particle.setMaxOccurs(this.maxOccurs); group.getContents().add(0, particle); group.updateElement(); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(particle), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewGroupFromTypeAction_ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewIdentityConstraintAction.java
License:Open Source License
@Override public IStatus doAction() { try {//from w ww . ja v a2s . c om int index = -1; // EList list = schema.getIdentityConstraintDefinitions(); // schema.getElement(); IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); List<String> childNames = new ArrayList<String>(); if (selection.getFirstElement() instanceof XSDElementDeclaration) { decl = (XSDElementDeclaration) selection.getFirstElement(); // childNames = Util.getChildElementNames(decl.getElement()); } else if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) { XSDIdentityConstraintDefinition selIcd = (XSDIdentityConstraintDefinition) selection .getFirstElement(); decl = (XSDElementDeclaration) (selIcd.getContainer()); // get position of the selected Identity Constraint in the container (Element Declaration) int i = 0; for (Iterator iter = decl.getIdentityConstraintDefinitions().iterator(); iter.hasNext();) { XSDIdentityConstraintDefinition ic = (XSDIdentityConstraintDefinition) iter.next(); if (ic.equals(selIcd)) { index = i; break; } i++; } } else if (selection.getFirstElement() instanceof XSDParticle) { XSDParticle selParticle = (XSDParticle) selection.getFirstElement(); if (!(selParticle.getTerm() instanceof XSDElementDeclaration)) return Status.CANCEL_STATUS; decl = (XSDElementDeclaration) selParticle.getTerm(); // childNames.add(decl.getName()); } else { MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewIdentityConstraintAction_ErrorMsg, selection.getFirstElement().getClass().getName())); return Status.CANCEL_STATUS; } childNames = Util.getChildElementNames("", decl); //$NON-NLS-1$ // filter the non top level fields List<String> topChilds = new ArrayList<String>(); for (String child : childNames) { if (child.indexOf('/') == -1) { topChilds.add(child); } } dialog = new IdentityConstraintInputDialog(decl, page.getSite().getShell(), Messages.XSDNewIdentityConstraintAction_AddANewKey, topChilds, decl.getName()); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Window.CANCEL) { return Status.CANCEL_STATUS; } keyName = dialog.getKeyName(); fieldName = dialog.getFieldName(); type = dialog.getType(); XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDIdentityConstraintDefinition icd = factory.createXSDIdentityConstraintDefinition(); icd.setName(keyName); icd.setIdentityConstraintCategory(type); XSDXPathDefinition selector = factory.createXSDXPathDefinition(); selector.setVariety(XSDXPathVariety.SELECTOR_LITERAL); selector.setValue("."); //$NON-NLS-1$ icd.setSelector(selector); XSDXPathDefinition field = factory.createXSDXPathDefinition(); field.setVariety(XSDXPathVariety.FIELD_LITERAL); field.setValue("."); //$NON-NLS-1$ // if complex content set name of first field if (fieldName == null || fieldName.trim().length() == 0) { if (decl.getTypeDefinition() instanceof XSDComplexTypeDefinition) { XSDComplexTypeContent ctc = ((XSDComplexTypeDefinition) decl.getTypeDefinition()).getContent(); if (ctc instanceof XSDParticle) { if (((XSDParticle) ctc).getTerm() instanceof XSDModelGroup) { XSDModelGroup mg = (XSDModelGroup) ((XSDParticle) ctc).getTerm(); if (mg.getContents().size() > 0) if (mg.getContents().get(0).getTerm() instanceof XSDElementDeclaration) field.setValue(((XSDElementDeclaration) (mg.getContents().get(0).getTerm())) .getName()); } } } } else { field.setValue(fieldName); } icd.getFields().add(field); decl.getIdentityConstraintDefinitions().add(index + 1, icd); decl.updateElement(); updateElementForAddedfield(icd, fieldName); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(icd), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDNewIdentityConstraintAction_ErrorMsg2, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewParticleFromParticleAction.java
License:Open Source License
public IStatus doAction() { try {/*from w ww. ja va 2s .c om*/ IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); selParticle = (XSDParticle) selection.getFirstElement(); if (!(selParticle.getContainer() instanceof XSDModelGroup)) return Status.CANCEL_STATUS; ; XSDModelGroup group = (XSDModelGroup) selParticle.getContainer(); // get position of the selected particle in the container int index = 0; int i = 0; for (Iterator<XSDParticle> iter = group.getContents().iterator(); iter.hasNext();) { XSDParticle p = (XSDParticle) iter.next(); if (p.equals(selParticle)) { index = i; break; } i++; } EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations(); List<String> elementDeclarations = new ArrayList<String>(); for (Iterator<XSDElementDeclaration> iter = eDecls.iterator(); iter.hasNext();) { XSDElementDeclaration d = (XSDElementDeclaration) iter.next(); if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) continue; elementDeclarations .add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));//$NON-NLS-1$//$NON-NLS-2$ } elementDeclarations.add("");//$NON-NLS-1$ dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, null, null, elementDeclarations, 0, 1, true, false); dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Dialog.CANCEL) { return Status.CANCEL_STATUS; } XSDElementDeclaration elem = (XSDElementDeclaration) selParticle.getContent(); if (Util.changeElementTypeToSequence(elem, maxOccurs) == Status.CANCEL_STATUS) { return Status.CANCEL_STATUS; } XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDElementDeclaration decl = factory.createXSDElementDeclaration(); decl.setName(this.elementName); if (!refName.equals("")) {//$NON-NLS-1$ XSDElementDeclaration ref = Util.findReference(refName, schema); if (ref != null) { decl.setResolvedElementDeclaration(ref); } } else { decl.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName)); } XSDParticle particle = factory.createXSDParticle(); particle.setContent(decl); particle.setMinOccurs(this.minOccurs); if (maxOccurs > -1) { particle.setMaxOccurs(this.maxOccurs); } else { particle.setMaxOccurs(this.maxOccurs); group.getContents().add(group.getContents().size(), particle); group.updateElement(); if (particle.getElement().getAttributeNode("maxOccurs") != null)//$NON-NLS-1$ particle.getElement().getAttributeNode("maxOccurs").setNodeValue("unbounded");//$NON-NLS-1$//$NON-NLS-2$ else { particle.getElement().setAttribute("maxOccurs", "unbounded");//$NON-NLS-1$//$NON-NLS-2$ } } if (maxOccurs > -1) { group.getContents().add(group.getContents().size(), particle); group.updateElement(); } // fix 0010248. add annotion from parent if (dialog.isInherit()) { XSDTerm totm = particle.getTerm(); XSDElementDeclaration concept = null; if (Util.getParent(selParticle) instanceof XSDElementDeclaration) concept = (XSDElementDeclaration) Util.getParent(selParticle); else if (Util.getParent(selParticle) instanceof XSDComplexTypeDefinition) { if (selParticle instanceof XSDParticle) concept = (XSDElementDeclaration) ((XSDParticle) selParticle).getContent(); else if (selParticle instanceof XSDElementDeclaration) concept = (XSDElementDeclaration) selParticle; } XSDAnnotation fromannotation = null; if (concept != null) fromannotation = concept.getAnnotation(); if (fromannotation != null) { XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm); if (((XSDElementDeclaration) totm).getType() != null) addAnnotion(struc, fromannotation); } } page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(particle), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewParticleFromTypeAction.java
License:Open Source License
@Override public IStatus doAction() { try {/*from w w w. j a v a2 s. c o m*/ IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); if (selection.getFirstElement() instanceof XSDComplexTypeDefinition) { ctd = (XSDComplexTypeDefinition) selection.getFirstElement(); if (!(ctd.getContent() instanceof XSDParticle)) { return Status.CANCEL_STATUS; } if (!(((XSDParticle) ctd.getContent()).getTerm() instanceof XSDModelGroup)) { return Status.CANCEL_STATUS; } ; group = (XSDModelGroup) ((XSDParticle) ctd.getContent()).getTerm(); } else if (selection.getFirstElement() instanceof XSDParticle) { group = (XSDModelGroup) ((XSDParticle) selection.getFirstElement()).getTerm(); } else if (selection.getFirstElement() instanceof XSDModelGroup) { group = (XSDModelGroup) selection.getFirstElement(); } else { log.info(Messages.bind(Messages._UnkownSection, selection.getFirstElement().getClass().getName(), selection.getFirstElement().toString())); return Status.CANCEL_STATUS; } EList<XSDElementDeclaration> eDecls = schema.getElementDeclarations(); List<String> elementDeclarations = new LinkedList<String>(); for (XSDElementDeclaration xsdElementDeclaration : eDecls) { XSDElementDeclaration d = xsdElementDeclaration; if (d.getTargetNamespace() != null && d.getTargetNamespace().equals(IConstants.DEFAULT_NAME_SPACE)) { continue; } elementDeclarations .add(d.getQName() + (d.getTargetNamespace() != null ? " : " + d.getTargetNamespace() : ""));//$NON-NLS-1$//$NON-NLS-2$ } elementDeclarations.add("");//$NON-NLS-1$ dialog = new BusinessElementInputDialog(this, page.getSite().getShell(), Messages._AddANewBusinessElement, "", "", elementDeclarations, 0, 1, true, false);//$NON-NLS-1$//$NON-NLS-2$; dialog.setBlockOnOpen(true); int ret = dialog.open(); if (ret == Dialog.CANCEL) { return Status.CANCEL_STATUS; } XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDElementDeclaration decl = factory.createXSDElementDeclaration(); decl.setName(this.elementName); // decl.setTypeDefinition(schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), // simpleTypeName)); if (!refName.equals("")) {//$NON-NLS-1$ XSDElementDeclaration ref = Util.findReference(refName, schema); if (ref != null) { decl.setResolvedElementDeclaration(ref); } } else { decl.setTypeDefinition( schema.resolveSimpleTypeDefinition(schema.getSchemaForSchemaNamespace(), simpleTypeName)); } XSDParticle particle = factory.createXSDParticle(); particle.setContent(decl); particle.setMinOccurs(this.minOccurs); particle.setMaxOccurs(this.maxOccurs); group.getContents().add(group.getContents().size(), particle); group.updateElement(); if (Util.changeElementTypeToSequence(decl, maxOccurs) == Status.CANCEL_STATUS) { return Status.CANCEL_STATUS; } // fix 0010248. add annotion from parent if (dialog.isInherit()) { XSDTerm totm = particle.getTerm(); XSDElementDeclaration concept = null; Object obj = Util.getParent(particle); if (obj instanceof XSDElementDeclaration) { concept = (XSDElementDeclaration) obj; } else { concept = (XSDElementDeclaration) particle.getContent(); } XSDAnnotation fromannotation = null; if (concept != null) { fromannotation = concept.getAnnotation(); } if (fromannotation != null) { XSDAnnotationsStructure struc = new XSDAnnotationsStructure(totm); if (((XSDElementDeclaration) totm).getType() != null) { addAnnotion(struc, fromannotation); } } } page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(particle), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages._ErrorCreatBusinessElement, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }
From source file:com.amalto.workbench.actions.XSDNewXPathAction.java
License:Open Source License
@Override public IStatus doAction() { try {/* w ww .j a v a 2 s . com*/ int index = 0; IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection(); if (selection.getFirstElement() instanceof XSDIdentityConstraintDefinition) { icd = (XSDIdentityConstraintDefinition) selection.getFirstElement(); } else if (selection.getFirstElement() instanceof XSDXPathDefinition) { XSDXPathDefinition xpath = (XSDXPathDefinition) selection.getFirstElement(); icd = (XSDIdentityConstraintDefinition) xpath.getContainer(); if (xpath.getVariety().equals(XSDXPathVariety.FIELD_LITERAL)) index = icd.getFields().indexOf(xpath) + 1; else index = 0; } else { MessageDialog.openError(this.page.getSite().getShell(), Messages._Error, Messages.XSDNewXPathAction_Huhhh + selection.getFirstElement().getClass().getName()); return Status.CANCEL_STATUS; } // InputDialog id = new InputDialog( // page.getSite().getShell(), // "New XPath", // "Enter a new XPath to the field", // null, // new IInputValidator() { // public String isValid(String newText) { // if ((newText==null) || "".equals(newText)) return "The XPath cannot be empty"; // return null; // }; // } // ); List<String> childNames = Util.getChildElementNames("", (XSDElementDeclaration) icd.getContainer()); //$NON-NLS-1$ // filter the non top level fields List<String> topChilds = new ArrayList<String>(); for (String child : childNames) { if (child.indexOf('/') == -1) { topChilds.add(child); } } // forbid to add already exists field EList<XSDXPathDefinition> fields = icd.getFields(); for (XSDXPathDefinition fd : fields) { if (topChilds.contains(fd.getValue())) topChilds.remove(fd.getValue()); } SelectFieldDialog id = new SelectFieldDialog(page.getSite().getShell(), Messages.XSDNewXPathAction_SelectOnField, topChilds, null); id.create(); id.setBlockOnOpen(true); int ret = id.open(); if (ret == Dialog.CANCEL) { return Status.CANCEL_STATUS; } String field = id.getField(); if (field.length() == 0) return Status.CANCEL_STATUS; XSDFactory factory = XSDSchemaBuildingTools.getXSDFactory(); XSDXPathDefinition xpath = factory.createXSDXPathDefinition(); xpath.setValue(field); xpath.setVariety(XSDXPathVariety.FIELD_LITERAL); icd.getFields().add(index, xpath); icd.updateElement(); updateElementForAddedfield(icd, field); page.refresh(); page.getTreeViewer().setSelection(new StructuredSelection(xpath), true); page.markDirty(); } catch (Exception e) { log.error(e.getMessage(), e); MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.ErrorMsg, e.getLocalizedMessage())); return Status.CANCEL_STATUS; } return Status.OK_STATUS; }