Example usage for org.eclipse.jdt.core IType getJavaProject

List of usage examples for org.eclipse.jdt.core IType getJavaProject

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IType getJavaProject.

Prototype

IJavaProject getJavaProject();

Source Link

Document

Returns the Java project this element is contained in, or null if this element is not contained in any Java project (for instance, the IJavaModel is not contained in any Java project).

Usage

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.contentassist.FXGraphProposalProvider.java

License:Open Source License

private void collectStaticFields(List<IField> fields, IType type) throws JavaModelException {
    //FIXME Don't we have to check if the field is assignable???
    for (IField f : type.getFields()) {
        if (Flags.isStatic(f.getFlags())) {
            fields.add(f);/*  www. j  av a2s  .  c om*/
        }
    }

    String s = type.getSuperclassName();

    if (s != null) {
        String fqn = at.bestsolution.efxclipse.tooling.model.internal.utils.Util.getFQNType(type,
                Signature.getTypeErasure(s));
        collectStaticFields(fields, type.getJavaProject().findType(fqn));
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.hover.FXHoverProvider.java

License:Open Source License

@Override
public IInformationControlCreatorProvider getHoverInfo(EObject object, ITextViewer viewer, IRegion region) {
    if (object instanceof Element) {
        Element e = (Element) object;
        if (e.getType() != null) {
            IType t = getJDTType(e.getType().getType());
            if (t != null) {
                return createHover(t, object, viewer, region);
            }//  www .  j a  v  a 2s  .c  o  m
        }
    } else if (object instanceof Property) {
        Property p = (Property) object;
        if (p.eContainer() instanceof Element) {
            Element e = (Element) p.eContainer();
            if (e.getType() != null) {
                IType t = getJDTType(e.getType().getType());
                if (t != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(t.getJavaProject(), t);
                    if (fxClass != null) {
                        IFXProperty fxp = fxClass.getProperty(p.getName());
                        if (fxp != null) {
                            return createHover(fxp.getJavaElement(), object, viewer, region);
                        }
                    }
                }
            }
        }
    } else if (object instanceof StaticCallValueProperty) {
        StaticCallValueProperty sp = (StaticCallValueProperty) object;
        if (sp.getType() != null) {
            IType t = getJDTType(sp.getType().getType());
            if (t != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(t.getJavaProject(), t);
                if (fxClass != null) {
                    IFXProperty fxp = fxClass.getStaticProperty(sp.getName());
                    if (fxp != null) {
                        return createHover(fxp.getJavaElement(), object, viewer, region);
                    }
                }
            }
        }
    } else if (object instanceof StaticValueProperty) {
        StaticValueProperty sp = (StaticValueProperty) object;

        EObject eo = sp.eContainer();
        Element target = null;

        while (eo.eContainer() != null) {
            if (eo.eContainer() instanceof Element) {
                target = (Element) eo.eContainer();
                break;
            }
            eo = eo.eContainer();
        }

        if (target != null) {
            if (target.getType() != null) {
                IType t = getJDTType(target.getType().getType());
                if (t != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(t.getJavaProject(), t);
                    if (fxClass != null) {
                        IFXProperty fxp = fxClass.getStaticProperty(sp.getName());
                        if (fxp != null) {
                            return createHover(fxp.getJavaElement(), object, viewer, region);
                        }
                    }
                }
            }
        }
    } else if (object instanceof ValueProperty) {
        if (object instanceof ControllerHandledValueProperty) {
            ControllerHandledValueProperty cp = (ControllerHandledValueProperty) object;

            Model m = (Model) object.eResource().getContents().get(0);

            if (m != null) {
                ComponentDefinition def = m.getComponentDef();
                if (def != null) {
                    if (def.getController() != null && def.getController().getType() != null) {
                        IType t = getJDTType(def.getController().getType());
                        if (t != null) {
                            IFXCtrlClass fxClass = FXPlugin.getClassmodel().findCtrlClass(t.getJavaProject(),
                                    t);
                            if (fxClass != null) {
                                IFXCtrlEventMethod fxp = fxClass.getAllEventMethods().get(cp.getMethodname());
                                if (fxp != null) {
                                    return createHover(fxp.getJavaElement(), object, viewer, region);
                                }
                            }
                        }
                    }
                }
            }
        } else if (object instanceof SimpleValueProperty) {
            SimpleValueProperty sp = (SimpleValueProperty) object;
            if (sp.eContainer() instanceof Property && sp.getStringValue() != null) {
                Property p = (Property) sp.eContainer();

                if (p.eContainer() instanceof Element) {
                    Element e = (Element) p.eContainer();
                    if (e.getType() != null) {
                        IType t = getJDTType(e.getType().getType());
                        if (t != null) {
                            IFXClass fxClass = FXPlugin.getClassmodel().findClass(t.getJavaProject(), t);
                            if (fxClass != null) {
                                IFXProperty fxp = fxClass.getProperty(p.getName());
                                if (fxp instanceof IFXEnumProperty) {
                                    IType enumType = ((IFXEnumProperty) fxp).getEnumType();
                                    try {
                                        for (IField f : enumType.getFields()) {
                                            if (Flags.isEnum(f.getFlags())) {
                                                if (f.getElementName().equals(sp.getStringValue())) {
                                                    return createHover(f, object, viewer, region);
                                                }
                                            }
                                        }
                                    } catch (JavaModelException ex) {
                                        // TODO Auto-generated catch block
                                        ex.printStackTrace();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return super.getHoverInfo(object, viewer, region);
}

From source file:at.bestsolution.efxclipse.tooling.fxgraph.ui.hyperlinking.FXGraphHyperlinkHelper.java

License:Open Source License

@Override
public IHyperlink[] createHyperlinksByOffset(XtextResource resource, int offset,
        boolean createMultipleHyperlinks) {
    IHyperlink[] links = super.createHyperlinksByOffset(resource, offset, createMultipleHyperlinks);

    EObject eo = eObjectAtOffsetHelper.resolveElementAt(resource, offset);
    if (eo instanceof ControllerHandledValueProperty) {
        INode n = NodeModelUtils.getNode(eo);

        if (n != null) {
            INode currentNode = NodeModelUtils.findLeafNodeAtOffset(n, offset);
            List<INode> l = NodeModelUtils.findNodesForFeature(eo,
                    FXGraphPackage.Literals.CONTROLLER_HANDLED_VALUE_PROPERTY__METHODNAME);
            if (l.contains(currentNode)) {
                Region region = new Region(currentNode.getOffset(), currentNode.getLength());

                Model m = (Model) eo.eResource().getContents().get(0);

                if (m != null) {
                    ComponentDefinition def = m.getComponentDef();
                    if (def != null) {
                        if (def.getController() != null && def.getController().getType() != null) {
                            IType t = getJDTType(def.getController().getType());
                            if (t != null) {
                                IFXCtrlClass fxClass = FXPlugin.getClassmodel()
                                        .findCtrlClass(t.getJavaProject(), t);
                                if (fxClass != null) {
                                    IFXCtrlEventMethod fxp = fxClass.getAllEventMethods()
                                            .get(currentNode.getText());
                                    if (fxp != null) {
                                        HyperlinkImpl h = new HyperlinkImpl(region, fxp.getJavaElement());
                                        if (links == null || links.length == 0) {
                                            return new IHyperlink[] { h };
                                        } else {
                                            IHyperlink[] rv = new IHyperlink[links.length + 1];
                                            System.arraycopy(links, 0, rv, 0, rv.length);
                                            rv[rv.length - 1] = h;
                                            return rv;
                                        }
                                    }/*from www  .j  a  va 2 s.c  o  m*/
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    return links;
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

@Override
protected void addAttributeNameProposals(ContentAssistRequest contentAssistRequest,
        CompletionProposalInvocationContext context) {
    String typeName = null;//w w  w .j  a va  2 s . c  o  m
    Node parent = contentAssistRequest.getParent();
    Set<String> existingAttributes = new HashSet<>();
    if (parent.getNodeType() == Node.ELEMENT_NODE) {
        typeName = parent.getNodeName();
        Element e = (Element) parent;
        for (int i = 0; i < e.getAttributes().getLength(); i++) {
            existingAttributes.add(e.getAttributes().item(i).getNodeName());
        }
    }

    System.err.println(existingAttributes);

    if ("fx:root".equals(typeName)) {
        typeName = parent.getAttributes().getNamedItem("type").getNodeValue();
    }

    if (typeName != null) {

        if (Character.isLowerCase(typeName.charAt(0)) || typeName.contains(".")) {
            // no proposal for static elements and attribute definitions
            return;
        }

        IType type = findType(typeName, contentAssistRequest, context);
        if (type != null) {
            IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);

            if (fxClass.getValueOf() != null) {
                FXMLCompletionProposal cp = createAttributeProposal(contentAssistRequest, context,
                        "fx:value=\"\"",
                        new StyledString("fx:valueOf").append(" - " + fxClass.getSimpleName(),
                                StyledString.QUALIFIER_STYLER),
                        IconKeys.getIcon(IconKeys.FIELD_KEY), DEFAULT_PRIORITY + 10, MATCHER);
                if (cp != null) {
                    cp.setAdditionalProposalInfo(EcoreFactory.eINSTANCE.createEClass());
                    cp.setHover(new HoverImpl(fxClass.getValueOf()));

                    contentAssistRequest.addProposal(cp);
                }
            }

            for (IFXProperty property : fxClass.getAllProperties().values()) {
                if (!existingAttributes.contains(property.getName())) {
                    createAttributeNameProposal(contentAssistRequest, context, property);
                }
            }

            if (parent.getParentNode() != null) {
                Node n = null;

                if (Character.isUpperCase(parent.getParentNode().getNodeName().charAt(0))
                        || "fx:root".equals(parent.getParentNode().getNodeName())) {
                    n = parent.getParentNode();
                } else if (parent.getParentNode().getParentNode() != null) {
                    if (Character.isUpperCase(parent.getParentNode().getParentNode().getNodeName().charAt(0))
                            || "fx:root".equals(parent.getParentNode().getParentNode().getNodeName())) {
                        n = parent.getParentNode().getParentNode();
                    }
                }

                if (n != null) {
                    IType containerType;
                    if ("fx:root".equals(n.getNodeName())) {
                        containerType = Util.findType(n.getAttributes().getNamedItem("type").getNodeValue(),
                                parent.getOwnerDocument());
                    } else {
                        containerType = Util.findType(n.getNodeName(), parent.getOwnerDocument());
                    }

                    if (containerType != null) {
                        IFXClass fxclass = FXPlugin.getClassmodel().findClass(type.getJavaProject(),
                                containerType);
                        if (fxclass != null) {
                            for (IFXProperty property : fxclass.getAllStaticProperties().values()) {
                                if (!existingAttributes.contains(
                                        property.getFXClass().getSimpleName() + "." + property.getName())) {
                                    createAttributeNameProposal(contentAssistRequest, context, property);
                                }
                            }
                        }
                    }
                } else {
                    FXMLCompletionProposal cp = createAttributeProposal(contentAssistRequest, context,
                            "fx:controller=\"\"",
                            new StyledString("fx:controller").append(" - FXML built-in",
                                    StyledString.QUALIFIER_STYLER),
                            IconKeys.getIcon(IconKeys.CLASS_KEY), DEFAULT_PRIORITY + 10, MATCHER);
                    if (cp != null) {
                        contentAssistRequest.addProposal(cp);
                    }
                }
            }
        }
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

@Override
protected void addTagNameProposals(ContentAssistRequest contentAssistRequest, int childPosition,
        CompletionProposalInvocationContext context) {
    Node parent = contentAssistRequest.getParent();

    if (parent.getNodeType() == Node.ELEMENT_NODE) {
        if (parent.getNodeName().contains(".")) {
            String[] parts = parent.getNodeName().split("\\.");
            IType ownerType = Util.findType(parts[0], parent.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    IFXProperty p = fxClass.getStaticProperty(parts[1]);
                    if (p != null) {
                        if (p instanceof IFXObjectProperty) {
                            IFXObjectProperty op = (IFXObjectProperty) p;
                            createSubtypeProposals(contentAssistRequest, context, op.getElementType());
                        } else if (p instanceof IFXCollectionProperty) {
                            IFXCollectionProperty cp = (IFXCollectionProperty) p;
                            createSubtypeProposals(contentAssistRequest, context, cp.getElementType());
                        }/*  www .j a  v  a 2s .co m*/
                    }
                }
            }
        } else if (Character.isUpperCase(parent.getNodeName().charAt(0))
                || "fx:root".equals(parent.getNodeName())) {
            if (!contentAssistRequest.getMatchString().isEmpty()
                    && Character.isUpperCase(contentAssistRequest.getMatchString().charAt(0))) {
                // TODO This means we are static?
                // IJavaProject jproject =
                // findProject(contentAssistRequest);
                // try {
                // IType superType =
                // jproject.findType("javafx.scene.Parent");
                // if( superType != null ) {
                // createSubtypeProposals(contentAssistRequest, context,
                // superType);
                // }
                // } catch (JavaModelException e) {
                // // TODO Auto-generated catch block
                // e.printStackTrace();
                // }
            } else {

                if (parent.getParentNode() != null) {
                    Node n = null;

                    if ("fx:root".equals(parent.getNodeName())) {
                        n = parent;
                    } else if (Character.isUpperCase(parent.getParentNode().getNodeName().charAt(0))
                            || "fx:root".equals(parent.getParentNode().getNodeName())) {
                        n = parent.getParentNode();
                    } else if (parent.getParentNode().getParentNode() != null) {
                        if (Character
                                .isUpperCase(parent.getParentNode().getParentNode().getNodeName().charAt(0))
                                || "fx:root".equals(parent.getParentNode().getParentNode().getNodeName())) {
                            n = parent.getParentNode().getParentNode();
                        }
                    }

                    if (n != null) {
                        IType type;
                        if ("fx:root".equals(n.getNodeName())) {
                            type = Util.findType(n.getAttributes().getNamedItem("type").getNodeValue(),
                                    parent.getOwnerDocument());
                        } else {
                            type = Util.findType(n.getNodeName(), parent.getOwnerDocument());
                        }

                        if (type != null) {
                            IFXClass fxclass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                            if (fxclass != null) {
                                for (IFXProperty p : fxclass.getAllStaticProperties().values()) {
                                    String proposalValue = fxclass.getSimpleName() + "." + p.getName() + ">"
                                            + "</" + fxclass.getSimpleName() + "." + p.getName() + ">";
                                    String sType;

                                    if (p instanceof IFXPrimitiveProperty) {
                                        IFXPrimitiveProperty pp = (IFXPrimitiveProperty) p;
                                        sType = pp.getType() == Type.STRING ? "String" : pp.getType().jvmType();
                                    } else if (p instanceof IFXObjectProperty) {
                                        IFXObjectProperty op = (IFXObjectProperty) p;
                                        sType = op.getElementTypeAsString(false);
                                    } else if (p instanceof IFXEnumProperty) {
                                        IFXEnumProperty ep = (IFXEnumProperty) p;
                                        sType = ep.getEnumTypeAsString(false);
                                    } else {
                                        sType = "<unknown>";
                                    }

                                    FXMLCompletionProposal cp = createElementProposal(contentAssistRequest,
                                            context, proposalValue,
                                            new StyledString().append("(static) ", StyledString.COUNTER_STYLER)
                                                    .append(p.getFXClass().getSimpleName() + "." + p.getName())
                                                    .append(" - " + sType, StyledString.QUALIFIER_STYLER),
                                            true, PRIORITY_LOWER_1, null, STATIC_ELEMENT_MATCHER);
                                    if (cp != null) {
                                        cp.setAdditionalProposalInfo(EcoreFactory.eINSTANCE.createEClass());
                                        cp.setHover(new HoverImpl(p.getJavaElement()));
                                        contentAssistRequest.addProposal(cp);
                                    }
                                }
                            }
                        }
                    }
                }
                IType type;

                if ("fx:root".equals(parent.getNodeName())) {
                    type = Util.findType(parent.getAttributes().getNamedItem("type").getNodeValue(),
                            parent.getOwnerDocument());
                } else {
                    type = Util.findType(parent.getNodeName(), parent.getOwnerDocument());
                }

                if (type != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                    if (fxClass != null) {
                        for (IFXProperty property : fxClass.getAllProperties().values()) {
                            createPropertyElementNameProposal(contentAssistRequest, context, property);
                        }
                    }
                }
            }

            IType type;

            if ("fx:root".equals(parent.getNodeName())) {
                type = Util.findType(parent.getAttributes().getNamedItem("type").getNodeValue(),
                        parent.getOwnerDocument());
            } else {
                type = Util.findType(parent.getNodeName(), parent.getOwnerDocument());
            }

            if (type != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                if (fxClass != null) {
                    IFXProperty p = fxClass.getDefaultProperty();
                    if (p instanceof IFXObjectProperty) {
                        createSubtypeProposals(contentAssistRequest, context,
                                ((IFXObjectProperty) p).getElementType());
                    } else if (p instanceof IFXCollectionProperty) {
                        createSubtypeProposals(contentAssistRequest, context,
                                ((IFXCollectionProperty) p).getElementType());
                    }
                }
            }
        } else {
            createClassElementNameProposal(contentAssistRequest, context);
        }
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

private void createClassElementNameProposal(ContentAssistRequest contentAssistRequest,
        CompletionProposalInvocationContext context) {
    Node propertyType = contentAssistRequest.getParent();
    Node elementType = propertyType.getParentNode();

    IType type;
    if ("fx:root".equals(elementType.getNodeName())) {
        type = Util.findType(elementType.getAttributes().getNamedItem("type").getNodeValue(),
                elementType.getOwnerDocument());
    } else {//  ww w.  j ava2 s  .c  o m
        type = findType(elementType.getNodeName(), contentAssistRequest, context);
    }

    if (type != null) {
        IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
        if (fxClass != null) {
            IFXProperty p = fxClass.getProperty(propertyType.getNodeName());
            if (p instanceof IFXObjectProperty) {
                IFXObjectProperty op = (IFXObjectProperty) p;
                createSubtypeProposals(contentAssistRequest, context, op.getElementType());
            } else if (p instanceof IFXCollectionProperty) {
                IFXCollectionProperty cp = (IFXCollectionProperty) p;
                createSubtypeProposals(contentAssistRequest, context, cp.getElementType());
            }
        }
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

@Override
protected void addAttributeValueProposals(final ContentAssistRequest contentAssistRequest,
        final CompletionProposalInvocationContext context) {
    IDOMNode n = (IDOMNode) contentAssistRequest.getNode();

    if (Character.isUpperCase(n.getNodeName().charAt(0))) {
        NamedNodeMap m = n.getAttributes();
        IDOMNode attribute = null;//  w w w  .j  a  v  a2 s .c  om
        for (int i = 0; i < m.getLength(); i++) {
            IDOMNode a = (IDOMNode) m.item(i);
            if (a.contains(contentAssistRequest.getStartOffset())) {
                attribute = a;
            }
        }

        if (attribute != null) {
            if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) {
                if ("constant".equals(attribute.getLocalName())) {
                    IType type = findType(n.getNodeName(), contentAssistRequest, context);
                    if (type != null) {
                        try {
                            List<IField> fields = new ArrayList<IField>();
                            collectStaticFields(fields, type);

                            for (IField f : fields) {
                                StyledString s = new StyledString(f.getElementName() + " : "
                                        + Signature.getSimpleName(Signature.toString(f.getTypeSignature())));
                                String owner = ((IType) f.getAncestor(IJavaElement.TYPE)).getElementName();
                                s.append(" - " + Signature.getSimpleName(owner), StyledString.QUALIFIER_STYLER);

                                FXMLCompletionProposal cp = createProposal(contentAssistRequest, context,
                                        "\"" + f.getElementName(), s, IconKeys.getIcon(IconKeys.CLASS_KEY),
                                        CLASS_ATTRIBUTE_MATCHER);

                                if (cp != null) {
                                    contentAssistRequest.addProposal(cp);
                                }
                            }

                        } catch (JavaModelException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }
                } else if ("controller".equals(attribute.getLocalName())) {
                    IJavaProject jproject = findProject(contentAssistRequest);

                    char[] typeName = null;
                    char[] packageName = null;
                    if (!contentAssistRequest.getMatchString().isEmpty()) {
                        if (contentAssistRequest.getMatchString().startsWith("\"")) {
                            typeName = contentAssistRequest.getMatchString().substring(1).toCharArray();
                        } else {
                            typeName = contentAssistRequest.getMatchString().toCharArray();
                        }
                    }

                    IJavaSearchScope searchScope = SearchEngine
                            .createJavaSearchScope(new IJavaElement[] { jproject });
                    SearchEngine searchEngine = new SearchEngine();
                    try {
                        searchEngine.searchAllTypeNames(packageName, SearchPattern.R_PATTERN_MATCH, typeName,
                                SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CAMELCASE_MATCH,
                                IJavaSearchConstants.TYPE, searchScope, new TypeNameRequestor() {
                                    public void acceptType(int modifiers, char[] packageName,
                                            char[] simpleTypeName, char[][] enclosingTypeNames, String path) {
                                        String sPackageName = new String(packageName);
                                        int priority = PRIORITY_LOWER_1;
                                        if (sPackageName.startsWith("com.sun")) {
                                            priority -= 10;
                                        }
                                        StyledString s = new StyledString(new String(simpleTypeName));
                                        s.append(" - " + sPackageName, StyledString.QUALIFIER_STYLER);

                                        FXMLCompletionProposal cp = createProposal(contentAssistRequest,
                                                context, "\"" + sPackageName + "." + new String(simpleTypeName),
                                                s, IconKeys.getIcon(IconKeys.CLASS_KEY),
                                                CLASS_ATTRIBUTE_MATCHER);

                                        if (cp != null) {
                                            contentAssistRequest.addProposal(cp);
                                        }
                                    }
                                }, IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH, new NullProgressMonitor());
                    } catch (JavaModelException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }

                }
            } else if (attribute.getNodeName().contains(".")) {
                String[] parts = attribute.getNodeName().split("\\.");

                IType type = findType(parts[0], contentAssistRequest, context);
                if (type != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                    if (fxClass != null) {
                        IFXProperty p = fxClass.getStaticProperty(parts[1]);
                        if (p instanceof IFXPrimitiveProperty) {
                            createAttributeValuePrimitiveProposals(contentAssistRequest, context,
                                    (IFXPrimitiveProperty) p);
                        } else if (p instanceof IFXEnumProperty) {
                            createAttributeValueEnumProposals(contentAssistRequest, context,
                                    (IFXEnumProperty) p);
                        } else if (p instanceof IFXObjectProperty) {
                            createAttributeValueObjectProposals(contentAssistRequest, context,
                                    (IFXObjectProperty) p);
                        }
                    }
                }
            } else {
                IType type = findType(n.getNodeName(), contentAssistRequest, context);
                if (type != null) {
                    IFXClass fxClass = FXPlugin.getClassmodel().findClass(type.getJavaProject(), type);
                    if (fxClass != null) {
                        IFXProperty p = fxClass.getProperty(attribute.getNodeName());
                        if (p instanceof IFXPrimitiveProperty) {
                            createAttributeValuePrimitiveProposals(contentAssistRequest, context,
                                    (IFXPrimitiveProperty) p);
                        } else if (p instanceof IFXEnumProperty) {
                            createAttributeValueEnumProposals(contentAssistRequest, context,
                                    (IFXEnumProperty) p);
                        } else if (p instanceof IFXObjectProperty) {
                            createAttributeValueObjectProposals(contentAssistRequest, context,
                                    (IFXObjectProperty) p);
                        } else if (p instanceof IFXEventHandlerProperty) {
                            createAttributeValueEventHandlerProposals(contentAssistRequest, context,
                                    (IFXEventHandlerProperty) p);
                        }
                    }
                }
            }
        }
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

private void createAttributeValueEventHandlerProposals(ContentAssistRequest contentAssistRequest,
        CompletionProposalInvocationContext context, IFXEventHandlerProperty p) {
    Document d = contentAssistRequest.getNode().getOwnerDocument();
    Element e = d.getDocumentElement();
    Attr a = e.getAttributeNodeNS("http://javafx.com/fxml", "controller");
    if (a != null) {
        IType t = Util.findType(a.getValue(), d);
        if (t != null) {
            IFXCtrlClass ctrlClass = FXPlugin.getClassmodel().findCtrlClass(t.getJavaProject(), t);
            if (ctrlClass != null) {

                for (IFXCtrlEventMethod ctrlMethod : ctrlClass.getAllEventMethods().values()) {
                    StyledString s = null;
                    if (!ctrlMethod.hasArgument()) {
                        s = new StyledString(ctrlMethod.getName() + "()");
                    } else {
                        if (at.bestsolution.efxclipse.tooling.model.Util.assignable(p.getEventType(),
                                ctrlMethod.getArgumentType())) {
                            s = new StyledString(
                                    ctrlMethod.getName() + "(" + p.getEventTypeAsString(false) + ")");
                        }/*w  w w .ja  va 2s  .  c om*/
                    }

                    if (s != null) {
                        s.append(" - " + ctrlClass.getSimpleName(), StyledString.QUALIFIER_STYLER);
                        Image img = null;

                        switch (ctrlMethod.getVisibility()) {
                        case PUBLIC:
                            img = IconKeys.getIcon(IconKeys.METHOD_PUBLIC_KEY);
                            break;
                        case PACKAGE:
                            img = IconKeys.getIcon(IconKeys.METHOD_DEFAULT_KEY);
                            break;
                        case PROTECTED:
                            img = IconKeys.getIcon(IconKeys.METHOD_PROTECTED_KEY);
                            break;
                        default:
                            img = IconKeys.getIcon(IconKeys.METHOD_PRIVATE_KEY);
                            break;
                        }

                        FXMLCompletionProposal cp = createProposal(contentAssistRequest, context,
                                "\"#" + ctrlMethod.getName(), s, img, EVENT_ATTRIBUTE_MATCHER);

                        if (cp != null) {
                            contentAssistRequest.addProposal(cp);
                        }
                    }
                }

            }
        }
    }
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLTextHover.java

License:Open Source License

public static IJavaElement computeTagNameHelp(IDOMNode xmlnode) {
    if (Character.isLowerCase(xmlnode.getNodeName().charAt(0))) {
        Node parent = xmlnode.getParentNode();
        if (parent == null || parent.getNodeName() == null || parent.getOwnerDocument() == null) {
            return null;
        }//w ww . j  a v  a2s .co  m
        IType ownerType = Util.findType(parent.getNodeName(), parent.getOwnerDocument());
        if (ownerType != null) {
            IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
            if (fxClass != null) {
                IFXProperty p = fxClass.getProperty(xmlnode.getNodeName());
                if (p != null) {
                    return p.getJavaElement();
                }
            }
        }
    } else {
        if (xmlnode.getNodeName().contains(".")) {
            String[] parts = xmlnode.getNodeName().split("\\.");
            IType ownerType = Util.findType(parts[0], xmlnode.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    IFXProperty p = fxClass.getStaticProperty(parts[1]);
                    if (p != null) {
                        return p.getJavaElement();
                    }
                }
            }
        } else {
            IType ownerType = Util.findType(xmlnode.getNodeName(), xmlnode.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    try {
                        return Util.findProject(xmlnode.getOwnerDocument()).findType(fxClass.getFQN());
                    } catch (JavaModelException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            }
        }
    }

    return null;
}

From source file:at.bestsolution.efxclipse.tooling.fxml.editors.FXMLTextHover.java

License:Open Source License

public static IJavaElement computeTagAttNameHelp(IDOMNode xmlnode, int offset) {
    NamedNodeMap m = xmlnode.getAttributes();
    IDOMNode attribute = null;//from w  ww  .  ja v  a  2s  . co  m
    if (m != null) {
        for (int i = 0; i < m.getLength(); i++) {
            IDOMNode a = (IDOMNode) m.item(i);
            if (a.contains(offset)) {
                attribute = a;
            }
        }
    }

    if (attribute != null) {
        Node parent = xmlnode;

        if (attribute.getNodeName().contains(".")) {
            String[] parts = attribute.getNodeName().split("\\.");
            IType ownerType = Util.findType(parts[0], parent.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    IFXProperty p = fxClass.getStaticProperty(parts[1]);
                    if (p != null) {
                        return p.getJavaElement();
                    }
                }
            }
        } else {
            IType ownerType = Util.findType(parent.getNodeName(), parent.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    IFXProperty p = fxClass.getProperty(attribute.getNodeName());
                    if (p != null) {
                        return p.getJavaElement();
                    }
                }
            }
        }
    }

    return null;
}