Java Code Examples for org.netbeans.api.project.SourceGroup#contains()
The following examples show how to use
org.netbeans.api.project.SourceGroup#contains() .
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: DefaultPlugin.java From netbeans with Apache License 2.0 | 6 votes |
/** * Finds a Java source group the given file belongs to. * * @param file {@code FileObject} to find a {@code SourceGroup} for * @return the found {@code SourceGroup}, or {@code null} if the given * file does not belong to any Java source group */ private static SourceGroup findSourceGroup(FileObject file) { final Project project = FileOwnerQuery.getOwner(file); if (project == null) { return null; } Sources src = ProjectUtils.getSources(project); SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA); for (SourceGroup srcGrp : srcGrps) { FileObject rootFolder = srcGrp.getRootFolder(); if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) && srcGrp.contains(file)) { return srcGrp; } } return null; }
Example 2
Source File: DefaultPlugin.java From netbeans with Apache License 2.0 | 6 votes |
/** * Finds a Java source group the given file belongs to. * * @param file {@literal FileObject} to find a {@literal SourceGroup} for * @return the found {@literal SourceGroup}, or {@literal null} if the given * file does not belong to any Java source group */ private static SourceGroup findSourceGroup(FileObject file) { final Project project = FileOwnerQuery.getOwner(file); if (project == null) { return null; } Sources src = ProjectUtils.getSources(project); SourceGroup[] srcGrps = src.getSourceGroups(SOURCES_TYPE_JAVA); for (SourceGroup srcGrp : srcGrps) { FileObject rootFolder = srcGrp.getRootFolder(); if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) && srcGrp.contains(file)) { return srcGrp; } } return null; }
Example 3
Source File: RefactoringUtils.java From netbeans with Apache License 2.0 | 6 votes |
/** * 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 4
Source File: TestSingleMethodSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isTestClass(Node activatedNode) { FileObject fileObject = org.netbeans.modules.gsf.testrunner.ui.api.UICommonUtils.getFileObjectFromNode(activatedNode); if (fileObject != null && CommonTestUtil.isJavaFile(fileObject)) { Project project = FileOwnerQuery.getOwner(fileObject); if (project != null) { SourceGroup[] javaSGs = new JavaUtils(project).getJavaSourceGroups(); for (int i = 0; i < javaSGs.length; i++) { SourceGroup javaSG = javaSGs[i]; FileObject rootFolder = javaSG.getRootFolder(); URL[] testRoots = UnitTestForSourceQuery.findUnitTests(rootFolder); URL[] sourceRoots = UnitTestForSourceQuery.findSources(rootFolder); if (((fileObject == rootFolder) || FileUtil.isParentOf(rootFolder, fileObject)) && javaSG.contains(fileObject)) { // activated FO is contained in the javaSG source group if (testRoots.length == 0 && sourceRoots.length > 0) { // javaSG has corresponding source root but no corresponding test root, // thus the activated FO is a test class, so activate action return true; } } } } } return false; }
Example 5
Source File: TestSingleMethodSupport.java From netbeans with Apache License 2.0 | 6 votes |
public static boolean isTestClass(Node activatedNode) { FileObject fileObject = org.netbeans.modules.gsf.testrunner.ui.api.UICommonUtils.getFileObjectFromNode(activatedNode); if (fileObject != null && CommonTestUtil.isJavaFile(fileObject)) { Project project = FileOwnerQuery.getOwner(fileObject); if (project != null) { SourceGroup[] javaSGs = new JavaUtils(project).getJavaSourceGroups(); for (int i = 0; i < javaSGs.length; i++) { SourceGroup javaSG = javaSGs[i]; FileObject rootFolder = javaSG.getRootFolder(); URL[] testRoots = UnitTestForSourceQuery.findUnitTests(rootFolder); URL[] sourceRoots = UnitTestForSourceQuery.findSources(rootFolder); if (((fileObject == rootFolder) || FileUtil.isParentOf(rootFolder, fileObject)) && javaSG.contains(fileObject)) { // activated FO is contained in the javaSG source group if (testRoots.length == 0 && sourceRoots.length > 0) { // javaSG has corresponding source root but no corresponding test root, // thus the activated FO is a test class, so activate action return true; } } } } } return false; }
Example 6
Source File: Utils.java From netbeans with Apache License 2.0 | 6 votes |
/** * Finds a Java source group the given file belongs to. * * @param file {@literal FileObject} to find a {@literal SourceGroup} for * @return the found {@literal SourceGroup}, or {@literal null} if the given * file does not belong to any Java source group */ private static SourceGroup findSourceGroup(FileObject file) { final Project project = FileOwnerQuery.getOwner(file); if (project == null) { return null; } Sources src = ProjectUtils.getSources(project); SourceGroup[] srcGrps = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (SourceGroup srcGrp : srcGrps) { FileObject rootFolder = srcGrp.getRootFolder(); if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) && srcGrp.contains(file)) { return srcGrp; } } return null; }
Example 7
Source File: VCSContext.java From netbeans with Apache License 2.0 | 5 votes |
private static void removeContainedExclusions (Map<FileObject, VCSFileProxy> rootFilesExclusions, Set<SourceGroup> sourceGroups) { for (SourceGroup sourceGroup : sourceGroups) { for (Iterator<Map.Entry<FileObject, VCSFileProxy>> it = rootFilesExclusions.entrySet().iterator(); it.hasNext(); ) { FileObject exclusion = it.next().getKey(); if (sourceGroup.contains(exclusion)) { it.remove(); } } } }
Example 8
Source File: DefaultPlugin.java From netbeans with Apache License 2.0 | 5 votes |
/** * */ @Override protected boolean canCreateTests(FileObject... fileObjects) { if (fileObjects.length == 0) { return false; } final FileObject firstFile = fileObjects[0]; final SourceGroup sourceGroup = findSourceGroup(firstFile); if (sourceGroup == null) { return false; } final FileObject rootFolder = sourceGroup.getRootFolder(); if (UnitTestForSourceQuery.findUnitTests(rootFolder).length == 0) { return false; } /* * Now we know that source folder of the first file has a corresponding * test folder (possible non-existent). */ if (fileObjects.length == 1) { /* ... if there is just one file selected, it is all we need: */ return true; } /* * ...for multiple files, we just check that all the selected files * have the same root folder: */ for (int i = 1; i < fileObjects.length; i++) { FileObject fileObj = fileObjects[i]; if (!FileUtil.isParentOf(rootFolder, fileObj) || !sourceGroup.contains(fileObj)) { return false; } } return true; }
Example 9
Source File: GlobalFormatAction.java From netbeans with Apache License 2.0 | 5 votes |
private static void addRecursivelly(FileObject top, List<FileObject> into, Set<String> sourceIds, ClassPath sourceCP, SourceGroup sg, AtomicBoolean cancel) { List<FileObject> todo = new LinkedList<FileObject>(); Iterator<String> sIDIter = sourceIds.iterator(); while (sourceCP == null && sIDIter.hasNext()) { if (cancel.get()) return; sourceCP = ClassPath.getClassPath(top, sIDIter.next()); } todo.add(top); while (!todo.isEmpty()) { if (cancel.get()) return; FileObject current = todo.remove(0); if (!VisibilityQuery.getDefault().isVisible(current)) continue; if (sourceCP != null && !sourceCP.contains(current)) continue; if (sg != null && !sg.contains(current)) continue; if (current.isData()) { into.add(current); } todo.addAll(Arrays.asList(current.getChildren())); } }
Example 10
Source File: CommonTestUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Finds a <code>SourceGroup</code> the given file belongs to. * Only Java <code>SourceGroup</code>s are taken into account. * * @param project the <code>Project</code> the file belongs to * @param file <code>FileObject</code> whose owning * <code>SourceGroup</code> to be found * @return Java <code>SourceGroup</code> containing the given * file; or <code>null</code> if no such * <code>SourceGroup</code> was found */ public static SourceGroup findSourceGroupOwner(Project project, FileObject file) { final SourceGroup[] sourceGroups = new JavaUtils(project).getJavaSourceGroups(); for (int i = 0; i < sourceGroups.length; i++) { SourceGroup srcGroup = sourceGroups[i]; FileObject root = srcGroup.getRootFolder(); if (((file==root)||(FileUtil.isParentOf(root,file))) && srcGroup.contains(file)) { return srcGroup; } } return null; }
Example 11
Source File: CommonTestUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Finds all <code>SourceGroup</code>s of the given project * containing a class of the given name. * * @param project project to be searched for matching classes * @param className class name pattern * @return unmodifiable collection of <code>SourceGroup</code>s * which contain files corresponding to the given name * (may be empty but not <code>null</code>) * @author Marian Petras */ public static Collection<SourceGroup> findSourceGroupOwners( final Project project, final String className) { final SourceGroup[] sourceGroups = new JavaUtils(project).getJavaSourceGroups(); if (sourceGroups.length == 0) { return Collections.<SourceGroup>emptyList(); } final String relativePath = className.replace('.', '/') + ".java"; //NOI18N ArrayList<SourceGroup> result = new ArrayList<SourceGroup>(4); for (int i = 0; i < sourceGroups.length; i++) { SourceGroup srcGroup = sourceGroups[i]; FileObject root = srcGroup.getRootFolder(); FileObject file = root.getFileObject(relativePath); if (file != null && FileUtil.isParentOf(root, file) && srcGroup.contains(file)) { result.add(srcGroup); } } if (result.isEmpty()) { return Collections.<SourceGroup>emptyList(); } result.trimToSize(); return Collections.unmodifiableList(result); }
Example 12
Source File: TestAction.java From netbeans with Apache License 2.0 | 5 votes |
/** */ static SourceGroup getSourceGroup(FileObject file, Project prj) { Sources src = ProjectUtils.getSources(prj); SourceGroup[] srcGrps = src.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (SourceGroup srcGrp : srcGrps) { FileObject rootFolder = srcGrp.getRootFolder(); if (((file == rootFolder) || FileUtil.isParentOf(rootFolder, file)) && srcGrp.contains(file)) { return srcGrp; } } return null; }
Example 13
Source File: LibrariesNode.java From netbeans with Apache License 2.0 | 5 votes |
private static SourceGroup findSourceGroup(FileObject fo, ClassPathModifier modifierImpl) { SourceGroup[]sgs = modifierImpl.getExtensibleSourceGroups(); for (SourceGroup sg : sgs) { if ((fo == sg.getRootFolder() || FileUtil.isParentOf(sg.getRootFolder(),fo)) && sg.contains(fo)) { return sg; } } throw new AssertionError("Cannot find source group for '"+fo+"' in "+Arrays.asList(sgs)); // NOI18N }
Example 14
Source File: DefaultPlugin.java From netbeans with Apache License 2.0 | 5 votes |
/** * */ @Override protected boolean canCreateTests(FileObject... fileObjects) { if (fileObjects.length == 0) { return false; } final FileObject firstFile = fileObjects[0]; final SourceGroup sourceGroup = findSourceGroup(firstFile); if (sourceGroup == null) { return false; } final FileObject rootFolder = sourceGroup.getRootFolder(); if (UnitTestForSourceQuery.findUnitTests(rootFolder).length == 0) { return false; } /* * Now we know that source folder of the first file has a corresponding * test folder (possible non-existent). */ if (fileObjects.length == 1) { /* ... if there is just one file selected, it is all we need: */ return true; } /* * ...for multiple files, we just check that all the selected files * have the same root folder: */ for (int i = 1; i < fileObjects.length; i++) { FileObject fileObj = fileObjects[i]; if (!FileUtil.isParentOf(rootFolder, fileObj) || !sourceGroup.contains(fileObj)) { return false; } } return true; }
Example 15
Source File: TvActivityWizardIterator.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void initialize(WizardDescriptor wizard) { this.wizard = wizard; index = 0; panels = createPanels(); // Make sure list of steps is accurate. steps = createSteps(); wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0); for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()])); } } NewFileWizard fileWizard = (NewFileWizard) wizard; try { Project project = (Project) wizard.getProperty("project"); if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) { NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project; File projectDirectory = gradleProject.getProjectDirectoryAsFile(); DataFolder targetFolder = fileWizard.getTargetFolder(); String targetPath = targetFolder.getPrimaryFile().getPath(); BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class); AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class); SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); FileObject srcRootFolder = null; for (SourceGroup sourceGroup : sourceGroups) { if (sourceGroup.contains(targetFolder.getPrimaryFile())) { srcRootFolder = sourceGroup.getRootFolder(); } } sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML); FileObject manifestRootFolder = null; if (sourceGroups.length == 1) { manifestRootFolder = sourceGroups[0].getRootFolder(); } wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder)); Variant variant = buildVariant.getCurrentVariant(); wizard.putProperty(BUILD_VARIANT, variant); if (srcRootFolder != null) { String packageName = targetPath.replace(srcRootFolder.getPath(), ""); packageName = packageName.replace("/", ".").replace("\\", "."); packageName = packageName.substring(1); wizard.putProperty(PROP_PROJECT_PACKAGE, packageName); } AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project); if (projectPlatform != null) { AndroidSdk sdk = projectPlatform.getSdk(); wizard.putProperty(PROP_PROJECT_SDK, sdk); wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_PLATFORM, new PlatformDecorator(projectPlatform)); wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_ENABLED, true); } Project rootProject = AndroidProjects.findRootProject(project); if (rootProject != null) { wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory())); String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1); if (!folderName.contains("/") && !folderName.contains("\\")) { wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_TV_FOLDER, folderName); } } AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class); if (aPrj != null) { String buildToolsVersion = aPrj.getBuildToolsVersion(); wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion); } wizard.putProperty(ERROR_NO_ANDROID, false); } else { wizard.putProperty(ERROR_NO_ANDROID, true); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
Example 16
Source File: FileWizardIterator.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void initialize(WizardDescriptor wizard) { this.wizard = wizard; String displayName = (String) wizard.getProperty("NewFileWizard_Title"); type = Type.find(displayName); index = 0; panels = createPanels(); // Make sure list of steps is accurate. steps = createSteps(); wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0); for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()])); } } NewFileWizard fileWizard = (NewFileWizard) wizard; try { Project project = (Project) wizard.getProperty("project"); if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) { NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project; File projectDirectory = gradleProject.getProjectDirectoryAsFile(); DataFolder targetFolder = fileWizard.getTargetFolder(); String targetPath = targetFolder.getPrimaryFile().getPath(); BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class); AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class); SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); FileObject srcRootFolder = null; for (SourceGroup sourceGroup : sourceGroups) { if (sourceGroup.contains(targetFolder.getPrimaryFile())) { srcRootFolder = sourceGroup.getRootFolder(); } } sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML); FileObject manifestRootFolder = null; if (sourceGroups.length == 1) { manifestRootFolder = sourceGroups[0].getRootFolder(); } wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder)); Variant variant = buildVariant.getCurrentVariant(); wizard.putProperty(BUILD_VARIANT, variant); if (srcRootFolder != null) { String packageName = targetPath.replace(srcRootFolder.getPath(), ""); packageName = packageName.replace("/", ".").replace("\\", "."); packageName = packageName.substring(1); wizard.putProperty(PROP_PROJECT_PACKAGE, packageName); } AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project); if (projectPlatform != null) { AndroidSdk sdk = projectPlatform.getSdk(); wizard.putProperty(PROP_PROJECT_SDK, sdk); wizard.putProperty(PROP_PLATFORM, new PlatformDecorator(projectPlatform)); } Project rootProject = AndroidProjects.findRootProject(project); if (rootProject != null) { wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory())); String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1); if (!folderName.contains("/") && !folderName.contains("\\")) { wizard.putProperty(PROP_SUB_PROJECT_FOLDER, folderName); } } AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class); if (aPrj != null) { String buildToolsVersion = aPrj.getBuildToolsVersion(); wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion); } wizard.putProperty(ERROR_NO_ANDROID, false); } else { wizard.putProperty(ERROR_NO_ANDROID, true); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
Example 17
Source File: Utils.java From netbeans with Apache License 2.0 | 4 votes |
public static boolean isSupportEnabled(Class lookupClass, FileObject[] activatedFOs) { if (activatedFOs.length == 0) { return false; } final FileObject firstFile = activatedFOs[0]; Project p = FileOwnerQuery.getOwner(firstFile); if (p == null) { return false; } if(p.getLookup().lookup(lookupClass) == null) { return false; } if(firstFile == p.getProjectDirectory()) { // "Run Selenium Tests" action should be active for the project node return true; } final SourceGroup sourceGroup = findSourceGroup(firstFile); if (sourceGroup == null) { return false; } final FileObject rootFolder = sourceGroup.getRootFolder(); if (UnitTestForSourceQuery.findUnitTests(rootFolder).length == 0 && UnitTestForSourceQuery.findSources(rootFolder).length == 0) { return false; } /* * Now we know that source folder of the first file has a corresponding * test folder (possible non-existent). */ if (activatedFOs.length == 1) { /* ... if there is just one file selected, it is all we need: */ return true; } /* * ...for multiple files, we just check that all the selected files * have the same root folder: */ for (int i = 1; i < activatedFOs.length; i++) { FileObject fileObj = activatedFOs[i]; if (!FileUtil.isParentOf(rootFolder, fileObj) || !sourceGroup.contains(fileObj)) { return false; } } return true; }
Example 18
Source File: JavaProfilerSourceImpl.java From netbeans with Apache License 2.0 | 4 votes |
private static boolean isJunit3TestSuite(FileObject fo) { final boolean[] rslt = new boolean[]{false}; SourceGroup sg = SourceGroupModifier.createSourceGroup(FileOwnerQuery.getOwner(fo), JavaProjectConstants.SOURCES_TYPE_JAVA, JavaProjectConstants.SOURCES_HINT_TEST); if (sg == null) { LOG.log(Level.INFO, "Can not resolve source group for {0}", fo.getPath()); return false; } if (FileUtil.getRelativePath(sg.getRootFolder(), fo) != null && // need to check for this first otherwise i will get IAE sg.contains(fo)) { JavaSource js = JavaSource.forFileObject(fo); if (js == null) { return false; } try { js.runUserActionTask(new CancellableTask<CompilationController>() { public void cancel() { // do nothing } public void run(final CompilationController cc) throws Exception { cc.toPhase(Phase.ELEMENTS_RESOLVED); ErrorAwareTreePathScanner<Void, Void> scanner = new ErrorAwareTreePathScanner<Void, Void>() { @Override public Void visitMethod(MethodTree node, Void p) { Element e = cc.getTrees().getElement(getCurrentPath()); if (e.getKind() == ElementKind.METHOD) { ExecutableElement ee = (ExecutableElement)e; if (ee.getSimpleName().contentEquals("suite") && // NOI18N (ee.getReturnType().toString().equals(JUNIT_TEST) || ee.getReturnType().toString().equals(JUNIT_SUITE))) { rslt[0] |= true; } } return super.visitMethod(node, p); } }; scanner.scan(cc.getCompilationUnit(), null); } }, true); return rslt[0]; } catch (IOException ioex) { ProfilerLogger.log(ioex); return false; } } return rslt[0]; }
Example 19
Source File: WearActivityWizardIterator.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void initialize(WizardDescriptor wizard) { this.wizard = wizard; index = 0; panels = createPanels(); // Make sure list of steps is accurate. steps = createSteps(); wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0); for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()])); } } NewFileWizard fileWizard = (NewFileWizard) wizard; try { Project project = (Project) wizard.getProperty("project"); if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) { NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project; File projectDirectory = gradleProject.getProjectDirectoryAsFile(); DataFolder targetFolder = fileWizard.getTargetFolder(); String targetPath = targetFolder.getPrimaryFile().getPath(); BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class); AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class); SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); FileObject srcRootFolder = null; for (SourceGroup sourceGroup : sourceGroups) { if (sourceGroup.contains(targetFolder.getPrimaryFile())) { srcRootFolder = sourceGroup.getRootFolder(); } } sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML); FileObject manifestRootFolder = null; if (sourceGroups.length == 1) { manifestRootFolder = sourceGroups[0].getRootFolder(); } wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder)); Variant variant = buildVariant.getCurrentVariant(); wizard.putProperty(BUILD_VARIANT, variant); if (srcRootFolder != null) { String packageName = targetPath.replace(srcRootFolder.getPath(), ""); packageName = packageName.replace("/", ".").replace("\\", "."); packageName = packageName.substring(1); wizard.putProperty(PROP_PROJECT_PACKAGE, packageName); } AndroidPlatformInfo projectPlatform = AndroidProjects.projectPlatform(project); if (projectPlatform != null) { AndroidSdk sdk = projectPlatform.getSdk(); wizard.putProperty(PROP_PROJECT_SDK, sdk); wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_PLATFORM, new PlatformDecorator(projectPlatform)); wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_ENABLED, true); } Project rootProject = AndroidProjects.findRootProject(project); if (rootProject != null) { wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory())); String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1); if (!folderName.contains("/") && !folderName.contains("\\")) { wizard.putProperty(AndroidProjectTemplatePanelVisualAndroidSettings.PROP_WEAR_FOLDER, folderName); } } AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class); if (aPrj != null) { String buildToolsVersion = aPrj.getBuildToolsVersion(); wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion); } wizard.putProperty(ERROR_NO_ANDROID, false); } else { wizard.putProperty(ERROR_NO_ANDROID, true); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
Example 20
Source File: MobileActivityWizardIterator.java From NBANDROID-V2 with Apache License 2.0 | 4 votes |
@Override public void initialize(WizardDescriptor wizard) { this.wizard = wizard; index = 0; panels = createPanels(); // Make sure list of steps is accurate. steps = createSteps(); wizard.putProperty(WizardDescriptor.PROP_CONTENT_SELECTED_INDEX, 0); for (int i = 0; i < panels.size(); i++) { Component c = panels.get(i).getComponent(); if (c instanceof JComponent) { // assume Swing components JComponent jc = (JComponent) c; // Step #. // TODO if using org.openide.dialogs >= 7.8, can use WizardDescriptor.PROP_*: jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer(i)); // Step name (actually the whole list for reference). jc.putClientProperty("WizardPanel_contentData", steps.toArray(new String[steps.size()])); } } NewFileWizard fileWizard = (NewFileWizard) wizard; try { Project project = (Project) wizard.getProperty("project"); if (AndroidProjects.isAndroidMavenProject(project) && (project instanceof NbAndroidProjectImpl)) { NbAndroidProjectImpl gradleProject = (NbAndroidProjectImpl) project; File projectDirectory = gradleProject.getProjectDirectoryAsFile(); DataFolder targetFolder = fileWizard.getTargetFolder(); String targetPath = targetFolder.getPrimaryFile().getPath(); BuildVariant buildVariant = project.getLookup().lookup(BuildVariant.class); AndroidSources androidSources = project.getLookup().lookup(AndroidSources.class); SourceGroup[] sourceGroups = androidSources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); FileObject srcRootFolder = null; for (SourceGroup sourceGroup : sourceGroups) { if (sourceGroup.contains(targetFolder.getPrimaryFile())) { srcRootFolder = sourceGroup.getRootFolder(); } } sourceGroups = androidSources.getSourceGroups(AndroidConstants.ANDROID_MANIFEST_XML); FileObject manifestRootFolder = null; if (sourceGroups.length == 1) { manifestRootFolder = sourceGroups[0].getRootFolder(); } wizard.putProperty(MANIFEST_ROOT_FOLDER, FileUtil.toFile(manifestRootFolder)); Variant variant = buildVariant.getCurrentVariant(); wizard.putProperty(BUILD_VARIANT, variant); if (srcRootFolder != null) { try { String packageName = targetPath.replace(srcRootFolder.getPath(), ""); packageName = packageName.replace("/", ".").replace("\\", "."); packageName = packageName.substring(1); wizard.putProperty(PROP_PROJECT_PACKAGE, packageName); } catch (Exception e) { } } PlatformDecorator projectPlatform = new PlatformDecorator(AndroidProjects.projectPlatform(project)); if (projectPlatform != null) { AndroidSdk sdk = projectPlatform.getSdk(); wizard.putProperty(PROP_PROJECT_SDK, sdk); wizard.putProperty(PROP_PHONE_TABLET_PLATFORM, projectPlatform); wizard.putProperty(PROP_PHONE_TABLET_ENABLED, true); } Project rootProject = AndroidProjects.findRootProject(project); if (rootProject != null) { wizard.putProperty(AndroidProjectTemplatePanelVisualBasicSettings.PROP_PROJECT_DIR, FileUtil.toFile(rootProject.getProjectDirectory())); String folderName = project.getProjectDirectory().getPath().replace(rootProject.getProjectDirectory().getPath(), "").substring(1); if (!folderName.contains("/") && !folderName.contains("\\")) { wizard.putProperty(PROP_PHONE_TABLET_FOLDER, folderName); } } AndroidProject aPrj = project.getLookup().lookup(AndroidProject.class); if (aPrj != null) { String buildToolsVersion = aPrj.getBuildToolsVersion(); wizard.putProperty(BUILD_TOOL_VERSION, buildToolsVersion); } wizard.putProperty(ERROR_NO_ANDROID, false); } else { wizard.putProperty(ERROR_NO_ANDROID, true); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }