Example usage for org.eclipse.jdt.core Flags isEnum

List of usage examples for org.eclipse.jdt.core Flags isEnum

Introduction

In this page you can find the example usage for org.eclipse.jdt.core Flags isEnum.

Prototype

public static boolean isEnum(int flags) 

Source Link

Document

Returns whether the given integer has the AccEnum bit set.

Usage

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

License:Open Source License

private void createEnumPropvalueProposals(IFXEnumProperty prop, EObject model, ContentAssistContext context,
        EReference typeReference, ICompletionProposalAcceptor acceptor) {
    IType t = prop.getEnumType();/*from ww w  . j  a v  a  2 s . c  om*/
    if (t != null) {
        try {
            for (IField f : t.getFields()) {
                if (Flags.isEnum(f.getFlags())) {
                    ICompletionProposal p = createCompletionProposal("\"" + f.getElementName() + "\"",
                            new StyledString(f.getElementName()).append(" - " + prop.getEnumTypeAsString(false),
                                    StyledString.QUALIFIER_STYLER),
                            IconKeys.getIcon(IconKeys.ENUM_KEY), getPriorityHelper().getDefaultPriority(),
                            "\"" + context.getPrefix(), context);
                    if (p instanceof ConfigurableCompletionProposal) {
                        ConfigurableCompletionProposal cp = (ConfigurableCompletionProposal) p;
                        cp.setAdditionalProposalInfo(model);
                        cp.setHover(new HoverImpl(f));
                    }

                    acceptor.accept(p);
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

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);
            }/*from  w w  w .  ja  v  a 2 s  .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.fxml.editors.FXMLCompletionProposalComputer.java

License:Open Source License

private void createAttributeValueEnumProposals(ContentAssistRequest contentAssistRequest,
        CompletionProposalInvocationContext context, IFXEnumProperty p) {
    IType t = p.getEnumType();//  w  w w . j  ava  2 s  .  c  o m
    if (t != null) {
        try {
            for (IField f : t.getFields()) {
                if (Flags.isEnum(f.getFlags())) {
                    FXMLCompletionProposal cp = createProposal(contentAssistRequest, context,
                            "\"" + f.getElementName(),
                            new StyledString(f.getElementName()).append(" - " + p.getEnumTypeAsString(false),
                                    StyledString.QUALIFIER_STYLER),
                            IconKeys.getIcon(IconKeys.ENUM_KEY), ATTRIBUTE_MATCHER);
                    if (cp != null) {
                        cp.setAdditionalProposalInfo(EcoreFactory.eINSTANCE.createEClass());
                        cp.setHover(new HoverImpl(f));
                        contentAssistRequest.addProposal(cp);
                    }
                }
            }
        } catch (JavaModelException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

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

License:Open Source License

public static IJavaElement computeTagAttValueHelp(IDOMNode xmlnode, int offset) {
    NamedNodeMap m = xmlnode.getAttributes();
    IDOMNode attribute = null;/*from  www  . ja va2  s.  c o m*/
    if (m == null) {
        return 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;
        IFXProperty p = null;

        if ("http://javafx.com/fxml".equals(attribute.getNamespaceURI())) {
            Document d = xmlnode.getOwnerDocument();
            return Util.findType(attribute.getNodeValue(), d);
        }

        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) {
                    p = fxClass.getStaticProperty(parts[1]);

                }
            }
        } else {
            IType ownerType = Util.findType(parent.getNodeName(), parent.getOwnerDocument());
            if (ownerType != null) {
                IFXClass fxClass = FXPlugin.getClassmodel().findClass(ownerType.getJavaProject(), ownerType);
                if (fxClass != null) {
                    p = fxClass.getProperty(attribute.getNodeName());

                }
            }
        }

        if (p instanceof IFXEnumProperty) {
            IType t = ((IFXEnumProperty) p).getEnumType();
            try {
                for (IField f : t.getFields()) {
                    if (Flags.isEnum(f.getFlags())) {
                        if (f.getElementName().equals(attribute.getNodeValue())) {
                            return f;
                        }
                    }
                }
            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else if (p instanceof IFXEventHandlerProperty && attribute.getNodeValue().startsWith("#")) {
            Document d = xmlnode.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 cl = FXPlugin.getClassmodel().findCtrlClass(t.getJavaProject(), t);
                    IFXCtrlEventMethod method = cl.getAllEventMethods()
                            .get(attribute.getNodeValue().substring(1));
                    if (method != null) {
                        return method.getJavaElement();
                    }
                }
            }
        }
    }

    return null;
}

From source file:at.bestsolution.efxclipse.tooling.jdt.ui.internal.FXBeanJavaCompletionProposalComputer.java

License:Open Source License

@Override
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context,
        IProgressMonitor monitor) {//from w w w.  ja va  2 s  .c o m
    if (context instanceof JavaContentAssistInvocationContext && false) {
        JavaContentAssistInvocationContext javaContext = (JavaContentAssistInvocationContext) context;
        CompletionContext completionContext = javaContext.getCoreContext();
        IJavaElement enclosingElement = null;
        if (completionContext.isExtended()) {
            enclosingElement = completionContext.getEnclosingElement();
        } else {
            try {
                enclosingElement = javaContext.getCompilationUnit()
                        .getElementAt(context.getInvocationOffset() + 1);
            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        List<ICompletionProposal> l = new ArrayList<ICompletionProposal>();

        if (enclosingElement != null) {
            IType type = (IType) enclosingElement.getAncestor(IJavaElement.TYPE);
            if (type == null) {
                return l;
            }

            try {
                IField[] fields = type.getFields();
                IMethod[] methods = type.getMethods();
                int offset = context.getInvocationOffset() - 3;
                if (offset > 0) {
                    String prefix = context.getDocument().get(offset, 3);
                    IType propType = type.getJavaProject().findType("javafx.beans.property.Property");
                    IType writableType = type.getJavaProject().findType("javafx.beans.value.WritableValue");

                    // Primitives
                    IType booleanType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyBooleanProperty");
                    IType doubleType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyDoubleProperty");
                    IType floatType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyFloatProperty");
                    IType intType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyIntegerProperty");
                    IType longType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyLongProperty");
                    IType stringType = type.getJavaProject()
                            .findType("javafx.beans.property.ReadOnlyStringProperty");

                    for (int i = 0; i < fields.length; i++) {
                        IField curr = fields[i];
                        if (!Flags.isEnum(curr.getFlags())) {
                            IType fieldType = toType(type, curr.getTypeSignature());
                            if (fieldType != null) {
                                if (assignable(fieldType, propType)) {
                                    if ("set".equals(prefix)) {
                                        if (assignable(fieldType, writableType)) {
                                            String setterName = NamingConventions.suggestSetterName(
                                                    type.getJavaProject(), curr.getElementName(),
                                                    curr.getFlags(), false, null);
                                            if (!hasMethod(methods, setterName)) {
                                                StyledString s = new StyledString(setterName
                                                        + "(" + toValue(fieldType, booleanType, doubleType,
                                                                floatType, intType, longType, stringType)
                                                        + ") : void");
                                                s.append(" - Setter for '" + curr.getElementName() + "'",
                                                        StyledString.QUALIFIER_STYLER);
                                                l.add(new CompletionProposalImpl(setterName, s));
                                            }
                                        }
                                    } else if (Character.isWhitespace(prefix.charAt(0))
                                            && prefix.endsWith("is")) {
                                        if (assignable(fieldType, booleanType)) {
                                            String getterName = NamingConventions.suggestGetterName(
                                                    type.getJavaProject(), curr.getElementName(),
                                                    curr.getFlags(), false, null);
                                            getterName = "is" + getterName.substring(3);
                                            if (!hasMethod(methods, getterName)) {
                                                StyledString s = new StyledString(getterName + "() : boolean");
                                                s.append(" - Getter for '" + curr.getElementName() + "'",
                                                        StyledString.QUALIFIER_STYLER);
                                                l.add(new CompletionProposalImpl(getterName, s));
                                            }
                                        }
                                    } else if ("get".equals(prefix)) {
                                        if (!assignable(fieldType, booleanType)) {
                                            String getterName = NamingConventions.suggestGetterName(
                                                    type.getJavaProject(), curr.getElementName(),
                                                    curr.getFlags(), false, null);
                                            if (!hasMethod(methods, getterName)) {
                                                StyledString s = new StyledString(getterName + "() : "
                                                        + toValue(fieldType, booleanType, doubleType, floatType,
                                                                intType, longType, stringType));
                                                s.append(" - Getter for '" + curr.getElementName() + "'",
                                                        StyledString.QUALIFIER_STYLER);
                                                l.add(new CompletionProposalImpl(getterName, s));
                                            }
                                        }
                                    } else if (Character.isWhitespace(prefix.charAt(2))) {
                                        String propertyName = curr.getElementName() + "Property";
                                        if (!hasMethod(methods, propertyName)) {
                                            StyledString s = new StyledString(propertyName);
                                            l.add(new CompletionProposalImpl(propertyName, s));
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

            } catch (JavaModelException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (BadLocationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return l;
    }
    return Collections.emptyList();
}

From source file:at.bestsolution.fxide.jdt.corext.util.JdtFlags.java

License:Open Source License

public static boolean isEnum(IMember member) throws JavaModelException {
    return Flags.isEnum(member.getFlags());
}

From source file:at.bestsolution.fxide.jdt.text.viewersupport.JavaElementLabelComposer.java

License:Open Source License

/**
 * Appends the style label for a field. Considers the F_* flags.
 *
 * @param field the element to render/*from  w  ww. j a v  a2s . co m*/
 * @param flags the rendering flags. Flags with names starting with 'F_' are considered.
 */
public void appendFieldLabel(IField field, long flags) {
    try {

        if (getFlag(flags, JavaElementLabels.F_PRE_TYPE_SIGNATURE) && field.exists()
                && !Flags.isEnum(field.getFlags())) {
            if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
                appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
            } else {
                appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
            }
            fBuffer.append(' ');
        }

        // qualification
        if (getFlag(flags, JavaElementLabels.F_FULLY_QUALIFIED)) {
            appendTypeLabel(field.getDeclaringType(),
                    JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
            fBuffer.append('.');
        }
        fBuffer.append(getElementName(field));

        if (getFlag(flags, JavaElementLabels.F_APP_TYPE_SIGNATURE) && field.exists()
                && !Flags.isEnum(field.getFlags())) {
            int offset = fBuffer.length();
            fBuffer.append(JavaElementLabels.DECL_STRING);
            if (getFlag(flags, JavaElementLabels.USE_RESOLVED) && field.isResolved()) {
                appendTypeSignatureLabel(field, new BindingKey(field.getKey()).toSignature(), flags);
            } else {
                appendTypeSignatureLabel(field, field.getTypeSignature(), flags);
            }
            //            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            //               fBuffer.setStyle(offset, fBuffer.length() - offset, DECORATIONS_STYLE);
            //            }
        }

        // category
        if (getFlag(flags, JavaElementLabels.F_CATEGORY) && field.exists())
            appendCategoryLabel(field, flags);

        // post qualification
        if (getFlag(flags, JavaElementLabels.F_POST_QUALIFIED)) {
            int offset = fBuffer.length();
            fBuffer.append(JavaElementLabels.CONCAT_STRING);
            appendTypeLabel(field.getDeclaringType(),
                    JavaElementLabels.T_FULLY_QUALIFIED | (flags & QUALIFIER_FLAGS));
            //            if (getFlag(flags, JavaElementLabels.COLORIZE)) {
            //               fBuffer.setStyle(offset, fBuffer.length() - offset, QUALIFIER_STYLE);
            //            }
        }

    } catch (JavaModelException e) {
        // TODO
        e.printStackTrace();
    }
}

From source file:com.amashchenko.eclipse.strutsclipse.java.SimpleJavaProposalCollector.java

License:Apache License

@Override
protected IJavaCompletionProposal createJavaCompletionProposal(CompletionProposal proposal) {
    if (collectMethods) {
        if (CompletionProposal.METHOD_REF == proposal.getKind() && Flags.isPublic(proposal.getFlags())) {
            char[] sig = proposal.getSignature();
            char[] declSig = proposal.getDeclarationSignature();
            // collect methods suitable for action methods ignoring Object
            // methods
            if (sig != null && declSig != null && ACTION_METHOD_SIGNATURE.equals(String.valueOf(sig))
                    && !OBJECT_SIGNATURE.equals(String.valueOf(declSig))) {
                return new SimpleJavaCompletionProposal(proposal, getInvocationContext(),
                        getImage(getLabelProvider().createImageDescriptor(proposal)));
            }//from w  ww. j  av a 2s. c o m
        }
    } else {
        // collect packages and classes suitable for actions
        if ((CompletionProposal.PACKAGE_REF == proposal.getKind()
                || CompletionProposal.TYPE_REF == proposal.getKind()) && !Flags.isAbstract(proposal.getFlags())
                && !Flags.isInterface(proposal.getFlags()) && !Flags.isEnum(proposal.getFlags())) {
            return new SimpleJavaCompletionProposal(proposal, getInvocationContext(),
                    getImage(getLabelProvider().createImageDescriptor(proposal)));
        }
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java

License:Open Source License

@Override
public String displayFragmentSourceInput() {
    try {/*  w  w w .  jav a  2 s .  c o  m*/
        // Compute a search scope: We need to merge all the subclasses
        // android.app.Fragment and android.support.v4.app.Fragment
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mRulesEngine.getProject();
        final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            IType oldFragmentType = javaProject.findType(CLASS_V4_FRAGMENT);

            // First check to make sure fragments are available, and if not,
            // warn the user.
            IAndroidTarget target = Sdk.getCurrent().getTarget(project);
            // No, this should be using the min SDK instead!
            if (target.getVersion().getApiLevel() < 11 && oldFragmentType == null) {
                // Compatibility library must be present
                MessageDialog dialog = new MessageDialog(Display.getCurrent().getActiveShell(),
                        "Fragment Warning", null,
                        "Fragments require API level 11 or higher, or a compatibility "
                                + "library for older versions.\n\n"
                                + " Do you want to install the compatibility library?",
                        MessageDialog.QUESTION, new String[] { "Install", "Cancel" },
                        1 /* default button: Cancel */);
                int answer = dialog.open();
                if (answer == 0) {
                    if (!AddSupportJarAction.install(project)) {
                        return null;
                    }
                } else {
                    return null;
                }
            }

            // Look up sub-types of each (new fragment class and compatibility fragment
            // class, if any) and merge the two arrays - then create a scope from these
            // elements.
            IType[] fragmentTypes = new IType[0];
            IType[] oldFragmentTypes = new IType[0];
            if (oldFragmentType != null) {
                ITypeHierarchy hierarchy = oldFragmentType.newTypeHierarchy(new NullProgressMonitor());
                oldFragmentTypes = hierarchy.getAllSubtypes(oldFragmentType);
            }
            IType fragmentType = javaProject.findType(CLASS_FRAGMENT);
            if (fragmentType != null) {
                ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor());
                fragmentTypes = hierarchy.getAllSubtypes(fragmentType);
            }
            IType[] subTypes = new IType[fragmentTypes.length + oldFragmentTypes.length];
            System.arraycopy(fragmentTypes, 0, subTypes, 0, fragmentTypes.length);
            System.arraycopy(oldFragmentTypes, 0, subTypes, fragmentTypes.length, oldFragmentTypes.length);
            scope = SearchEngine.createJavaSearchScope(subTypes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getShell();
        final AtomicReference<String> returnValue = new AtomicReference<String>();
        final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public Control createContentArea(Composite parentComposite) {
                        Composite composite = new Composite(parentComposite, SWT.NONE);
                        composite.setLayout(new GridLayout(1, false));
                        Button button = new Button(composite, SWT.PUSH);
                        button.setText("Create New...");
                        button.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                String fqcn = createNewFragmentClass(javaProject);
                                if (fqcn != null) {
                                    returnValue.set(fqcn);
                                    dialogHolder.get().close();
                                }
                            }
                        });
                        return composite;
                    }

                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });
        dialogHolder.set(dialog);

        dialog.setTitle("Choose Fragment Class");
        dialog.setMessage("Select a Fragment class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        if (returnValue.get() != null) {
            return returnValue.get();
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}

From source file:com.android.ide.eclipse.adt.internal.editors.layout.gre.ClientRulesEngine.java

License:Open Source License

@Override
public String displayCustomViewClassInput() {
    try {/*from  w  w  w  .j  av  a 2  s.  com*/
        IJavaSearchScope scope = SearchEngine.createWorkspaceScope();
        IProject project = mRulesEngine.getProject();
        final IJavaProject javaProject = BaseProjectHelper.getJavaProject(project);
        if (javaProject != null) {
            // Look up sub-types of each (new fragment class and compatibility fragment
            // class, if any) and merge the two arrays - then create a scope from these
            // elements.
            IType[] viewTypes = new IType[0];
            IType fragmentType = javaProject.findType(CLASS_VIEW);
            if (fragmentType != null) {
                ITypeHierarchy hierarchy = fragmentType.newTypeHierarchy(new NullProgressMonitor());
                viewTypes = hierarchy.getAllSubtypes(fragmentType);
            }
            scope = SearchEngine.createJavaSearchScope(viewTypes, IJavaSearchScope.SOURCES);
        }

        Shell parent = AdtPlugin.getShell();
        final AtomicReference<String> returnValue = new AtomicReference<String>();
        final AtomicReference<SelectionDialog> dialogHolder = new AtomicReference<SelectionDialog>();
        final SelectionDialog dialog = JavaUI.createTypeDialog(parent, new ProgressMonitorDialog(parent), scope,
                IJavaElementSearchConstants.CONSIDER_CLASSES, false,
                // Use ? as a default filter to fill dialog with matches
                "?", //$NON-NLS-1$
                new TypeSelectionExtension() {
                    @Override
                    public Control createContentArea(Composite parentComposite) {
                        Composite composite = new Composite(parentComposite, SWT.NONE);
                        composite.setLayout(new GridLayout(1, false));
                        Button button = new Button(composite, SWT.PUSH);
                        button.setText("Create New...");
                        button.addSelectionListener(new SelectionAdapter() {
                            @Override
                            public void widgetSelected(SelectionEvent e) {
                                String fqcn = createNewCustomViewClass(javaProject);
                                if (fqcn != null) {
                                    returnValue.set(fqcn);
                                    dialogHolder.get().close();
                                }
                            }
                        });
                        return composite;
                    }

                    @Override
                    public ITypeInfoFilterExtension getFilterExtension() {
                        return new ITypeInfoFilterExtension() {
                            @Override
                            public boolean select(ITypeInfoRequestor typeInfoRequestor) {
                                int modifiers = typeInfoRequestor.getModifiers();
                                if (!Flags.isPublic(modifiers) || Flags.isInterface(modifiers)
                                        || Flags.isEnum(modifiers) || Flags.isAbstract(modifiers)) {
                                    return false;
                                }
                                return true;
                            }
                        };
                    }
                });
        dialogHolder.set(dialog);

        dialog.setTitle("Choose Custom View Class");
        dialog.setMessage("Select a Custom View class (? = any character, * = any string):");
        if (dialog.open() == IDialogConstants.CANCEL_ID) {
            return null;
        }
        if (returnValue.get() != null) {
            return returnValue.get();
        }

        Object[] types = dialog.getResult();
        if (types != null && types.length > 0) {
            return ((IType) types[0]).getFullyQualifiedName();
        }
    } catch (JavaModelException e) {
        AdtPlugin.log(e, null);
    } catch (CoreException e) {
        AdtPlugin.log(e, null);
    }
    return null;
}