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

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

Introduction

In this page you can find the example usage for org.eclipse.jdt.core IPackageFragmentRoot 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:com.iw.plugins.spindle.ui.wizards.fields.SuperClassDialogField.java

License:Mozilla Public License

/**
 * @see TypeDialogField#getType()/*w  ww  .  java  2  s  . co m*/
 */
public IType getType() {

    String typeName = getTextValue();
    if (chosenType == null || (typeName == null && "".equals(typeName))) {
        IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
        try {
            chosenType = resolveTypeName(root.getJavaProject(), "java.lang.Object");
        } catch (JavaModelException e) {
        }
    }
    return super.getType();
}

From source file:com.iw.plugins.spindle.ui.wizards.fields.TypeDialogField.java

License:Mozilla Public License

private IJavaSearchScope createSearchScope(IPackageFragmentRoot root) {
    IJavaProject jproject = root.getJavaProject();
    IJavaSearchScope result = null;//  www .j  a va  2s .c  o m
    IType hrootElement = null;
    try {
        if (hierarchyRoot != null) {
            hrootElement = jproject.findType(hierarchyRoot);
        }
        if (hrootElement != null) {
            result = SearchEngine.createHierarchyScope(hrootElement);
        }
    } catch (JavaModelException jmex) {
        //ignore
        jmex.printStackTrace();
    }
    if (result == null) {
        IJavaElement[] elements = new IJavaElement[] { jproject };
        result = SearchEngine.createJavaSearchScope(elements);
    }
    return result;
}

From source file:com.iw.plugins.spindle.wizards.fields.ApplicationServletClassDialog.java

License:Mozilla Public License

private IStatus hasTapestryServletClassAsSuperType(String superclassName, IPackageFragmentRoot root) {
    SpindleStatus status = new SpindleStatus();
    enableButton(root == null);//from  w w  w  .j a  v  a 2  s .co m
    if (root == null) {
        return status;
    }
    String superclassBaseTypeName = MessageUtil.getString("TapestryEngine.defaultServlet");
    if (superclassBaseTypeName == null) {
        throw new Error("tapestry servlet type: " + superclassBaseTypeName + " does not exist in properties!");
    }
    if (!superclassName.equals(superclassBaseTypeName)) {
        try {
            IType chosenSuperclassType = resolveTypeName(root.getJavaProject(), superclassName);
            if (chosenSuperclassType == null) {
                status.setWarning(
                        MessageUtil.getFormattedString(name + ".warning.TypeNotExists", superclassName));
                return status;
            }
            boolean isBinary = chosenSuperclassType.isBinary();
            IType superclassBaseType = resolveTypeName(root.getJavaProject(), superclassBaseTypeName);
            if (superclassBaseType == null || !superclassBaseType.exists()) {
                status.setError(MessageUtil.getFormattedString(name + ".warning.TypeNotExists",
                        superclassBaseTypeName));
                return status;
            }
            boolean match = false;
            ITypeHierarchy hierarchy = chosenSuperclassType.newSupertypeHierarchy(null);
            if (hierarchy.exists()) {
                IType[] superClasses = hierarchy.getAllSupertypes(chosenSuperclassType);
                for (int i = 0; i < superClasses.length; i++) {
                    if (superClasses[i].equals(superclassBaseType)) {
                        match = true;
                    }
                }
            }
            if (!match) {
                status.setError(MessageUtil.getFormattedString(name + ".warning.SuperclassClassNotExtend",
                        superclassBaseTypeName));
                return status;
            }

        } catch (JavaModelException e) {
            status.setError(name + ".error.couldn't.do.it");
        }
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.fields.ContainerDialogField.java

License:Mozilla Public License

/**
 * @see IDialogFieldChangedListener#dialogFieldButtonPressed(DialogField)
 *///  w  w w . ja  v  a 2 s .  c  o m
public void dialogFieldButtonPressed(DialogField field) {

    IPackageFragmentRoot root = getPackageFragmentRoot();
    IJavaProject jproject = (root != null) ? root.getJavaProject() : null;
    root = chooseSourceContainer(jproject);
    if (root != null) {
        setPackageFragmentRoot(root, isEnabled());
    }
}

From source file:com.iw.plugins.spindle.wizards.fields.EngineClassDialog.java

License:Mozilla Public License

protected IStatus typeChanged() {

    SpindleStatus status = new SpindleStatus();

    String engineClassname = getTextValue();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();

    enableButton(root != null);/*from   w w  w .  j ava2 s . com*/
    chosenType = null;
    if (root == null || engineClassname == null || "".equals(engineClassname)) {
        status.setError(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", "'empty string'"));
        return status;
    }
    try {
        IType engineType = resolveTypeName(root.getJavaProject(), engineClassname);
        if (engineType == null) {
            status.setError(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", engineClassname));
            return status;
        }
        boolean isBinary = engineType.isBinary();
        String engineBaseTypeName = MessageUtil.getString("TapestryEngine.classname");
        if (engineBaseTypeName == null) {
            throw new Error(
                    "tapestry engine base type: " + engineBaseTypeName + " does not exist in properties!");
        }
        IType engineBaseType = resolveTypeName(root.getJavaProject(), engineBaseTypeName);
        if (engineBaseType == null || !engineBaseType.exists()) {
            status.setError(MessageUtil.getFormattedString(name + ".warning.EngineBaseTypeNotExists",
                    engineBaseTypeName));
            return status;
        }
        boolean match = false;
        if (engineBaseType.isInterface()) {
            String[] superInterfaces = engineType.getSuperInterfaceNames();
            if (superInterfaces != null && superInterfaces.length > 0) {
                for (int i = 0; i < superInterfaces.length; i++) {
                    if (isBinary && engineBaseTypeName.endsWith(superInterfaces[i])) {
                        match = true;
                    } else {
                        match = engineBaseTypeName.equals(superInterfaces[i]);
                    }
                }
            } else {
                match = false;
            }
            if (!match) {
                status.setWarning(MessageUtil.getFormattedString(
                        name + ".warning.EngineDoesNotImplementInterface", engineBaseTypeName));
                return status;
            }
        } else {
            ITypeHierarchy hierarchy = engineType.newSupertypeHierarchy(null);
            if (hierarchy.exists()) {
                IType[] superClasses = hierarchy.getAllSupertypes(engineType);
                for (int i = 0; i < superClasses.length; i++) {
                    if (superClasses[i].equals(engineBaseType)) {
                        match = true;
                    }
                }
            }
            if (!match) {
                if (!canFindJavaxServletJar(root.getJavaProject())) {
                    status.setError(MessageUtil.getString(name + ".error.javax.servlet.jar.NOTFOUND"));
                } else {
                    status.setError(MessageUtil.getFormattedString(name + ".warning.EngineClassNotExtend",
                            engineBaseTypeName));
                }
                return status;
            }
            chosenType = engineType;
        }

    } catch (JavaModelException e) {
        status.setError(name + ".error.couldn't.do.it");
    }

    return status;

}

From source file:com.iw.plugins.spindle.wizards.fields.InterfaceChooser.java

License:Mozilla Public License

protected IType chooseInterface() {

    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    if (root == null) {
        return null;
    }/*from w  ww  . ja  v  a 2 s. c  om*/

    IJavaProject jproject = root.getJavaProject();
    IJavaElement[] elements = new IJavaElement[] { jproject };
    IJavaSearchScope scope = SearchEngine.createJavaSearchScope(elements);

    try {
        SelectionDialog dialog = JavaUI.createTypeDialog(getShell(), getRunnableContext(), scope,
                IJavaElementSearchConstants.CONSIDER_INTERFACES, false);
        dialog.setTitle(MessageUtil.getString(name + ".InterfaceChooser.title"));
        dialog.setMessage(MessageUtil.getString(name + ".InterfaceChooser.message"));

        if (dialog.open() == dialog.OK) {
            return (IType) dialog.getResult()[0]; //FirstResult();
        }
    } catch (JavaModelException jmex) {
        TapestryPlugin.getDefault().logException(jmex);
    }
    return null;
}

From source file:com.iw.plugins.spindle.wizards.fields.PackageDialogField.java

License:Mozilla Public License

public IStatus packageChanged() {
    SpindleStatus status = new SpindleStatus();
    checkButtonEnabled();// ww w .  ja va  2 s. c  o  m
    String packName = getTextValue();
    if (!"".equals(packName)) {
        IStatus val = JavaConventions.validatePackageName(packName);
        if (val.getSeverity() == IStatus.ERROR) {
            status.setError(
                    MessageUtil.getFormattedString(name + ".error.InvalidPackageName", val.getMessage()));
            return status;
        } else if (val.getSeverity() == IStatus.WARNING) {
            status.setWarning(
                    MessageUtil.getFormattedString(name + ".warning.DiscouragedPackageName", val.getMessage()));
            // continue
        }
    } else {

        status.setError("Using the default package is not allowed. Choose (or enter) a package");
        return status;
    }

    IPackageFragmentRoot root;
    if (container == null) {
        root = null;
    } else {
        root = container.getPackageFragmentRoot();
    }
    if (root != null) {
        IPackageFragment pack = root.getPackageFragment(packName);
        try {
            IPath rootPath = root.getPath();
            IPath outputPath = root.getJavaProject().getOutputLocation();
            if (rootPath.isPrefixOf(outputPath) && !rootPath.equals(outputPath)) {
                // if the bin folder is inside of our root, dont allow to name a package
                // like the bin folder
                IPath packagePath = pack.getUnderlyingResource().getFullPath();
                if (outputPath.isPrefixOf(packagePath)) {
                    status.setError(MessageUtil.getString(name + ".error.ClashOutputLocation"));
                    return status;
                }
            }
        } catch (JavaModelException e) {
            TapestryPlugin.getDefault().logException(e);
            // let pass         
        }

        currentPackage = pack;
    } else {
        status.setError("");
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.fields.SpecClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();

    String specClassname = getTextValue();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    chosenType = null;//from  ww w  .j  ava 2  s. c  o  m
    enableButton(root != null);
    if (root == null || "".equals(specClassname.trim())) {
        status.setError(MessageUtil.getString(name + ".error.EnterTypeName"));
        return status;
    }
    try {
        IType specType = resolveTypeName(root.getJavaProject(), specClassname);
        if (specType == null) {
            status.setError(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", specClassname));
            return status;
        }
        if (specType.isInterface()) {
            status.setError(MessageUtil.getString(name + ".error.ClassIsNotClass"));
            return status;
        }
        boolean isBinary = specType.isBinary();
        String specBaseTypeName = MessageUtil.getString("TapestryComponentSpec.specBaseClass");
        String specInterfaceName = MessageUtil.getString("TapestryComponentSpec.specInterface");
        if (specBaseTypeName == null || specInterfaceName == null) {
            throw new Error("tapestry component wizard resources missing. Unable to continue");
        }
        IType specBaseType = resolveTypeName(root.getJavaProject(), specBaseTypeName);
        if (specBaseType == null || !specBaseType.exists()) {
            status.setError(
                    MessageUtil.getFormattedString(name + ".warning.BaseTypeNotExists", specBaseTypeName));
            return status;
        }

        if (!Utils.extendsType(specType, specBaseType)) {
            if (!Utils.implementsInterface(specType, specInterfaceName)) {
                status.setError(MessageUtil.getString(name + ".error.DoesNotExtendOrImplement"));
                return status;
            }
        }
        chosenType = specType;
    } catch (JavaModelException e) {
        status.setError(name + ".error.couldn't.do.it");
    }
    return status;
}

From source file:com.iw.plugins.spindle.wizards.fields.SuperClassDialogField.java

License:Mozilla Public License

protected IStatus typeChanged() {
    SpindleStatus status = new SpindleStatus();
    IPackageFragmentRoot root = packageChooser.getContainer().getPackageFragmentRoot();
    //    enableButton(root != null);
    if (root == null) {
        return status;
    }//from   w ww. j  av  a 2s  . c  o  m
    String typeName = getTextValue();
    chosenType = null;
    try {
        IType type = resolveTypeName(root.getJavaProject(), typeName);
        if (type == null) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeNotExists", typeName));
            return status;
        }
        if (type.isInterface()) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsNotClass", typeName));
            return status;
        }

        int flags = type.getFlags();
        if (Flags.isFinal(flags)) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsFinal", typeName));
            return status;
        } else if (!Utils.isVisible(type, packageChooser.getPackageFragment())) {
            status.setWarning(MessageUtil.getFormattedString(name + ".warning.TypeIsNotVisible", typeName));
            return status;
        }
        chosenType = type;
    } catch (JavaModelException e) {
        status.setError(MessageUtil.getString(name + ".error.InvalidTypeName"));
        TapestryPlugin.getDefault().logException(e);
    }
    return status;
}

From source file:com.liferay.ide.portlet.ui.wizard.NewPortletClassWizardPage.java

License:Open Source License

/**
 * Add folder group to composite//from  ww  w .j  av a  2 s . com
 */
protected void createFolderGroup(Composite composite) {
    // folder
    Label folderLabel = new Label(composite, SWT.LEFT);
    folderLabel.setText(J2EEUIMessages.FOLDER_LABEL);
    folderLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));

    folderText = new Text(composite, SWT.SINGLE | SWT.BORDER);
    folderText.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    synchHelper.synchText(folderText, INewJavaClassDataModelProperties.SOURCE_FOLDER, null);

    IPackageFragmentRoot root = getSelectedPackageFragmentRoot();

    String projectName = model.getStringProperty(IArtifactEditOperationDataModelProperties.PROJECT_NAME);

    if (projectName != null && projectName.length() > 0) {
        IProject targetProject = ProjectUtilities.getProject(projectName);

        if (root == null || !root.getJavaProject().getProject().equals(targetProject)) {
            IFolder folder = getDefaultJavaSourceFolder(targetProject);

            if (folder != null) {
                folderText.setText(folder.getFullPath().toPortableString());
            }
        } else {
            folderText.setText(root.getPath().toString());
        }
    }

    folderButton = new Button(composite, SWT.PUSH);
    folderButton.setText(J2EEUIMessages.BROWSE_BUTTON_LABEL);
    folderButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL));
    folderButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
            // Do nothing
        }

        public void widgetSelected(SelectionEvent e) {
            handleFolderButtonPressed();
        }

    });
}