Example usage for org.eclipse.jface.viewers TreePath getSegment

List of usage examples for org.eclipse.jface.viewers TreePath getSegment

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TreePath getSegment.

Prototype

public Object getSegment(int index) 

Source Link

Document

Returns the element at the specified index in this path.

Usage

From source file:bndtools.jareditor.internal.JARContentTreePart.java

License:Open Source License

String[] getSelectedPath() {
    String[] result;/*from   w  w w  .ja v a  2  s. co m*/
    if (viewer.getSelection().isEmpty()) {
        result = null;
    } else {
        TreeSelection selection = (TreeSelection) viewer.getSelection();
        TreePath treePath = selection.getPaths()[0];
        result = new String[treePath.getSegmentCount()];
        for (int i = 0; i < result.length; i++) {
            result[i] = treePath.getSegment(i).toString();
        }
    }
    return result;
}

From source file:com.amalto.workbench.actions.XSDAnnotationLookupFieldsAction.java

License:Open Source License

public IStatus doAction() {
    try {//from  w w w  . j  av a  2  s. co m
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        struc.setXSDSchema(schema);
        // IStructuredSelection selection = (IStructuredSelection) page
        // .getTreeViewer().getSelection();
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure(
        // (XSDComponent) selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ExceptionInfo,
                    xSDCom.getClass().getName()));
        }

        dlg = new AnnotationOrderedListsDialog(new ArrayList(struc.getLookupFields().values()),
                new SelectionListener() {

                    public void widgetDefaultSelected(SelectionEvent e) {
                    }

                    public void widgetSelected(SelectionEvent e) {
                        dlg.close();
                    }
                }, page.getSite().getShell(), Messages.XSDAnnotationLookupFieldsAction_SetLookupFields,
                Messages.XSDAnnotationLookupFieldsAction_LookupFields, page,
                AnnotationOrderedListsDialog.AnnotationLookupField_ActionType, null);

        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        struc.setAccessRole(dlg.getXPaths(), false,
                (IStructuredContentProvider) page.getTreeViewer().getContentProvider(), "X_Lookup_Field");//$NON-NLS-1$

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDAnnotationLookupFieldsAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDChangeToComplexTypeAction.java

License:Open Source License

@Override
public IStatus doAction() {

    try {//  ww w.  java 2 s .  c  o m
        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.XSDEditFacetAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {//from w ww.  j  av a  2 s .c o  m

        IStructuredSelection selection = (IStructuredSelection) page.getTreeViewer().getSelection();

        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof XSDSimpleTypeDefinition) {
            std = (XSDSimpleTypeDefinition) selection.getFirstElement();
        } else {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDSimpleTypeDefinition) {
                    std = (XSDSimpleTypeDefinition) (tPath.getSegment(i));
                }
            }
        }
        // std = (XSDSimpleTypeDefinition)((IStructuredSelection)selection).getFirstElement();
        /**
         * totalDigits, fractionDigits, maxInclusive, maxExclusive, minInclusive, minExclusive
         */
        if (facetName.equals("pattern")) {//$NON-NLS-1$
            editPattern();
        } else if (facetName.equals("enumeration")) {//$NON-NLS-1$
            editEnumeration();
        } else if (facetName.equals("length")) {//$NON-NLS-1$
            editLength();
        } else if (facetName.equals("minLength")) {//$NON-NLS-1$
            editMinLength();
        } else if (facetName.equals("maxLength")) {//$NON-NLS-1$
            editMaxLength();
        } else if (facetName.equals("totalDigits")) {//$NON-NLS-1$
            editTotalDigits();
        } else if (facetName.equals("fractionDigits")) {//$NON-NLS-1$
            editFractionDigits();
        } else if (facetName.equals("maxInclusive")) {//$NON-NLS-1$
            editMaxInclusive();
        } else if (facetName.equals("maxExclusive")) {//$NON-NLS-1$
            editMaxExclusive();
        } else if (facetName.equals("minInclusive")) {//$NON-NLS-1$
            editMinInclusive();
        } else if (facetName.equals("minExclusive")) {//$NON-NLS-1$
            editMinExclusive();
        } else if (facetName.equals("whiteSpace")) {//$NON-NLS-1$
            editWhiteSpace();
        }

        else {
            MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                    Messages.bind(Messages.XSDEditFacetAction_ErrorMsg1, facetName));
            return Status.CANCEL_STATUS;
        }

        std.updateElement();

        page.getTreeViewer().refresh(true);
        page.markDirty();
        page.refresh();

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDEditFacetAction_ErrorMsg2, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotaionDisplayFormatAction.java

License:Open Source License

public IStatus doAction() {
    try {/* ww w. j  a  va 2  s  .co m*/
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        // IStructuredSelection selection = (IStructuredSelection)page.getTreeViewer().getSelection();
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.XSDSetAnnoXX_ExceptionInfo + selection.getFirstElement().getClass().getName());
        }

        dlg = new AnnotationLanguageLabelsDialog(struc.getDisplayFormat(), new SelectionListener() {

            public void widgetDefaultSelected(SelectionEvent e) {
            }

            public void widgetSelected(SelectionEvent e) {
                dlg.close();
            }
        }, page.getSite().getShell(), Messages.XSDSetAnnoXX_DialogTitle2);

        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }
        LinkedHashMap<String, String> fomats = dlg.getDescriptionsMap();
        struc.setDisplayFormat(fomats);

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(selection.getFirstElement(), 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetAnnoXX_ErrorMsg2, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationDescriptionsAction.java

License:Open Source License

public IStatus doAction() {
    try {/*from ww w.  j a  v a2 s.com*/

        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation)
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
            }
        } else
            xSDCom = (XSDComponent) selection.getFirstElement();
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.XSDSetAnnotationXX_ExceptionInfo2, xSDCom.getClass().getName()));
        }

        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getDescriptions(),
                new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(),
                Messages.XSDSetAnnotationXX_SetDescOfThisItem);
        dlg.setBlockOnOpen(true);
        dlg.open();

        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllDescriptions();
            // add the new ones
            LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
            Set<String> isoCodes = descriptions.keySet();
            for (Iterator iter = isoCodes.iterator(); iter.hasNext();) {
                String isoCode = (String) iter.next();
                struc.setDescription(isoCode, descriptions.get(isoCode));
            }
        } else {
            return Status.CANCEL_STATUS;
        }

        if (struc.hasChanged()) {
            page.markDirty();
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetAnnotationXX_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationFKFilterAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {/* ww w.j av  a 2 s  . c  o  m*/
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        String conceptName = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        if (xSDCom instanceof XSDElementDeclaration) {
            conceptName = xSDCom.getElement().getAttributes().getNamedItem("name").getNodeValue();//$NON-NLS-1$
        }
        if (xSDCom instanceof XSDParticle) {
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }

        fkd = getNewFKFilterDialog(page.getSite().getShell(), struc.getFKFilter(), page, conceptName);
        fkd.setDataModel(dataModelName);
        fkd.setLock(true);
        fkd.setBlockOnOpen(true);
        int ret = fkd.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        String fkfilter = fkd.getFilter();
        struc.setFKFilter(fkfilter);

        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ErrorFKFilter, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationForeignKeyAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {//from w  w w .  java2 s  .  c  o  m
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = null;
        if (xSDCom != null) {
            struc = new XSDAnnotationsStructure(xSDCom);
        }
        if (struc == null || struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.UnableEditType, xSDCom.getClass().getName()));
        }

        sxid = getNewSimpleXpathInputDlg(struc.getForeignKey());
        sxid.setLock(true);
        sxid.setPKXpaths(XSDUtil.getAllPKXpaths(schema));
        String fksep = struc.getForeignKeyNotSep();
        if (fksep != null) {
            sxid.setFkSep(Boolean.valueOf(fksep));
        }
        sxid.setBlockOnOpen(true);
        int ret = sxid.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        String fk = "".equals(sxid.getXpath()) ? null : sxid.getXpath().replaceAll("'|\"", "");//$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
        // keep the foreignkey in memory to improve performance
        if (Util.getForeignKeys() != null && fk != null) {
            if (struc.getForeignKey() != null) {
                Util.getForeignKeys().remove(Util.getConceptFromPath(struc.getForeignKey()));
            }
            Util.getForeignKeys().add(Util.getConceptFromPath(fk));
        }
        struc.setForeignKey(fk);
        Boolean sep = sxid.getSepFk();
        struc.setForeignKeyNotSep(sep);
        updateAnnotationStructure(struc);
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationForeignKeyInfoAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {//  w w  w  .java 2 s.  co m
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(
                    Messages.bind(Messages.UnableEditAnnotationType, xSDCom.getClass().getName()));
        }

        dlg = getNewAnnotaionOrderedListsDialog(struc.getForeignKeyInfos().values());

        dlg.setLock(true);
        dlg.setRetrieveFKinfos(struc.getRetrieveFKinfos());
        dlg.setFormatFKInfo(struc.getFormatForeignKeyInfo());
        dlg.setBlockOnOpen(true);
        int ret = dlg.open();
        if (ret == Window.CANCEL) {
            return Status.CANCEL_STATUS;
        }

        struc.setForeignKeyInfos(dlg.getXPaths());
        struc.setRetrieveFKinfos(dlg.isRetrieveFKinfos());
        struc.setFormatForeignKeyInfo(dlg.getFormatFKInfo());
        if (struc.hasChanged()) {
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
            page.markDirty();
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.ErrorForeignKey, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}

From source file:com.amalto.workbench.actions.XSDSetAnnotationLabelAction.java

License:Open Source License

@Override
public IStatus doAction() {
    try {/*from  w  w  w.  j  av a 2s .c o m*/
        // IStructuredSelection selection = (IStructuredSelection)page.getTreeViewer().getSelection();
        //
        // XSDAnnotationsStructure struc = new XSDAnnotationsStructure((XSDComponent)selection.getFirstElement());
        IStructuredSelection selection = (TreeSelection) page.getTreeViewer().getSelection();
        XSDComponent xSDCom = null;
        if (selection.getFirstElement() instanceof Element) {
            TreePath tPath = ((TreeSelection) selection).getPaths()[0];
            for (int i = 0; i < tPath.getSegmentCount(); i++) {
                if (tPath.getSegment(i) instanceof XSDAnnotation) {
                    xSDCom = (XSDAnnotation) (tPath.getSegment(i));
                }
            }
        } else {
            xSDCom = (XSDComponent) selection.getFirstElement();
        }
        XSDAnnotationsStructure struc = new XSDAnnotationsStructure(xSDCom);
        if (struc.getAnnotation() == null) {
            throw new RuntimeException(Messages.bind(Messages.XSDSetAnnotationLabelAction_ExceptioInfo,
                    xSDCom.getClass().getName()));
        }

        AnnotationLanguageLabelsDialog dlg = new AnnotationLanguageLabelsDialog(struc.getLabels(),
                new AnnotationLabelDialogSelectionListener(page), page.getEditorSite().getShell(),
                Messages.XSDSetAnnotationLabelAction_DialogTitle);
        dlg.setBlockOnOpen(true);
        dlg.open();

        if (dlg.getReturnCode() == Window.OK) {
            // remove existing annotations with labels
            struc.removeAllLabels();
            // add the new ones
            LinkedHashMap<String, String> descriptions = dlg.getDescriptionsMap();
            Set<String> isoCodes = descriptions.keySet();
            for (Iterator iter = isoCodes.iterator(); iter.hasNext();) {
                String isoCode = (String) iter.next();
                struc.setLabel(isoCode, descriptions.get(isoCode));
            }
        } else {
            return Status.CANCEL_STATUS;
        }

        if (struc.hasChanged()) {
            page.markDirty();
            page.refresh();
            page.getTreeViewer().expandToLevel(xSDCom, 2);
        }

    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error,
                Messages.bind(Messages.XSDSetAnnotationLabelAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }

    return Status.OK_STATUS;
}