Java Code Examples for org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA

The following examples show how to use org.netbeans.api.java.project.JavaProjectConstants#SOURCES_TYPE_JAVA . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RefactoringUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Is given file on any source classpath?
 *
 * @param fo
 * @return
 * @deprecated 
 */
@Deprecated
public static boolean isOnSourceClasspath(FileObject fo) {
    Project pr = FileOwnerQuery.getOwner(fo);
    if (pr == null) {
        return false;
    }

    //workaround for 143542
    for (String type : new String[]{JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_TYPE_RESOURCES}) {
        for (SourceGroup sg : ProjectUtils.getSources(pr).getSourceGroups(type)) {
            if (fo == sg.getRootFolder() || (FileUtil.isParentOf(sg.getRootFolder(), fo) && sg.contains(fo))) {
                return ClassPath.getClassPath(fo, ClassPath.SOURCE) != null;
            }
        }
    }
    return false;
    //end of workaround
    //return ClassPath.getClassPath(fo, ClassPath.SOURCE)!=null;
}
 
Example 2
Source File: JSEApplicationClassChooser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void initCombos() {
        Sources sources = ProjectUtils.getSources(project);
        SourceGroup[] sourceGroupsJava = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
        if (sourceGroupsJava == null) {
            throw new IllegalStateException(
                    NbBundle.getMessage(FXMLTemplateWizardIterator.class,
                    "MSG_ConfigureFXMLPanel_SGs_Error")); // NOI18N
        }
        support = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
        support.addSourceGroups(sourceGroupsJava); //must exist

        comboBoxSourceRoot.setModel(new DefaultComboBoxModel(support.getSourceGroups().toArray()));
//        SourceGroupSupport.SourceGroupProxy preselectedGroup = support.getParent().getCurrentSourceGroup();
//        ignoreRootCombo = true;
//        comboBoxSourceRoot.setSelectedItem(preselectedGroup);
//        ignoreRootCombo = false;
//        comboBoxPackage.getEditor().setItem(support.getParent().getCurrentPackageName());
        updatePackages();
        updateText();
        updateResult();
    }
 
Example 3
Source File: SourceRoots.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static SourceRoots create(UpdateHelper helper, PropertyEvaluator evaluator, ReferenceHelper refHelper,
        String projectConfigurationNamespace, String elementName, boolean isTest, String newRootNameTemplate) {
    Parameters.notNull("helper", helper); // NOI18N
    Parameters.notNull("evaluator", evaluator); // NOI18N
    Parameters.notNull("refHelper", refHelper); // NOI18N
    Parameters.notNull("projectConfigurationNamespace", projectConfigurationNamespace); // NOI18N
    Parameters.notNull("elementName", elementName); // NOI18N
    Parameters.notNull("newRootNameTemplate", newRootNameTemplate); // NOI18N

    return new SourceRoots(helper, evaluator, refHelper, projectConfigurationNamespace, elementName,
            JavaProjectConstants.SOURCES_TYPE_JAVA, isTest, newRootNameTemplate);
}
 
Example 4
Source File: FolderTreeElement.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static SourceGroup getSourceGroup(FileObject file) {
    Project prj = FileOwnerQuery.getOwner(file);
    if (prj == null) {
        return null;
    }
    Sources src = ProjectUtils.getSources(prj);
    List<SourceGroup> allgroups = new ArrayList<>();
    //TODO: needs to be generified
    String[] sourceTypes = new String[] {
        JavaProjectConstants.SOURCES_TYPE_JAVA,
        "xml", //NOI18N
    };
    for (String sourceType : sourceTypes) {
        allgroups.addAll(Arrays.asList(src.getSourceGroups(sourceType)));
    }
    if (allgroups.isEmpty()) {
        // Unknown project group
        Logger.getLogger(FolderTreeElement.class.getName()).severe("Cannot find SourceGroup for " + file.getPath()); // NOI18N
        return null;
    }
    for (SourceGroup group : allgroups) {
        if (group.getRootFolder().equals(file) || FileUtil.isParentOf(group.getRootFolder(), file)) {
            return group;
        }
    }
    return null;
}
 
Example 5
Source File: LayerUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Find a resource path for a project.
 * @param project a module project
 * @return a classpath where resources can be found
 */
public static ClassPath findResourceCP(Project project) {
    Sources s = ProjectUtils.getSources(project);
    List<FileObject> roots = new ArrayList<FileObject>();
    for (String type : new String[] {JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_TYPE_RESOURCES}) {
        for (SourceGroup group : s.getSourceGroups(type)) {
            roots.add(group.getRootFolder());
        }
    }
    if (roots.isEmpty()) {
        LOG.log(Level.WARNING, "no resource path for {0}", project);
    }
    return ClassPathSupport.createClassPath(roots.toArray(new FileObject[roots.size()]));
}
 
Example 6
Source File: JavaRootsProvider.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String getSourceRootType() {
    return JavaProjectConstants.SOURCES_TYPE_JAVA;
}
 
Example 7
Source File: FXMLTemplateWizardIterator.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize(WizardDescriptor wizard) {
    this.wizard = wizard;

    Project project = Templates.getProject(wizard);
    if (project == null) {
        throw new IllegalStateException(
                NbBundle.getMessage(FXMLTemplateWizardIterator.class,
                "MSG_ConfigureFXMLPanel_Project_Null_Error")); // NOI18N
    }
    isMavenOrGradle = JFXProjectUtils.isMavenProject(project) || JFXProjectUtils.isGradleProject(project);

    Sources sources = ProjectUtils.getSources(project);
    SourceGroup[] sourceGroupsJava = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA);
    SourceGroup[] sourceGroupsResources = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
    if (sourceGroupsJava == null || sourceGroupsJava.length == 0) {
        throw new IllegalStateException(
                NbBundle.getMessage(FXMLTemplateWizardIterator.class,
                "MSG_ConfigureFXMLPanel_SGs_Error")); // NOI18N
    }
    if(isMavenOrGradle) {
        supportFXML = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
        supportCSS = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_RESOURCES);
        if(sourceGroupsResources != null && sourceGroupsResources.length > 0) {
            supportFXML.addSourceGroups(sourceGroupsResources);
            supportCSS.addSourceGroups(sourceGroupsResources);
        } else {
            supportFXML.addSourceGroupProxy(project, NbBundle.getMessage(FXMLTemplateWizardIterator.class,"LAB_ProjectResources"), // NOI18N
                    new String[]{defaultMavenFXMLPackage, defaultMavenImagesPackage, defaultMavenCSSPackage});
            supportCSS.addSourceGroupProxy(project, NbBundle.getMessage(FXMLTemplateWizardIterator.class,"LAB_ProjectResources"), // NOI18N
                    new String[]{defaultMavenFXMLPackage, defaultMavenImagesPackage, defaultMavenCSSPackage});
            FileObject dirFXML = supportFXML.getCurrentPackageFolder(true);
            if (dirFXML == null) {
                // default Maven resources are overriden in the project's pom.xml (#250097)
                supportFXML = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
                supportFXML.addSourceGroups(sourceGroupsJava); //must exist
                supportCSS = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
                supportCSS.addSourceGroups(sourceGroupsJava); //must exist
            }
        }
    } else {
        supportFXML = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
        supportFXML.addSourceGroups(sourceGroupsJava); //must exist
        supportCSS = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
        supportCSS.addSourceGroups(sourceGroupsJava); //must exist
    }
    supportController = new SourceGroupSupport(JavaProjectConstants.SOURCES_TYPE_JAVA);
    supportController.addSourceGroups(sourceGroupsJava); //must exist
    supportController.setParent(supportFXML);
    supportCSS.setParent(supportFXML);
    
    index = 0;
    panels = createPanels(project, supportFXML, supportController, supportCSS);
    String[] steps = createSteps();
    for (int i = 0; i < panels.length; i++) {
        Component c = panels[i].getComponent();
        if (steps[i] == null) {
            // Default step name to component name of panel.
            // Mainly useful for getting the name of the target
            // chooser to appear in the list of steps.
            steps[i] = c.getName();
        }
        if (c instanceof JComponent) { // assume Swing components
            JComponent jc = (JComponent)c;
            // Step #.
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, i);
            // Step name (actually the whole list for reference).
            jc.putClientProperty(WizardDescriptor.PROP_CONTENT_DATA, steps);
        }
    }
}