Java Code Examples for org.openide.loaders.DataFolder#findFolder()
The following examples show how to use
org.openide.loaders.DataFolder#findFolder() .
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: ConfigureToolbarPanel.java From netbeans with Apache License 2.0 | 6 votes |
/** Creates new form ConfigureToolbarPanel */ private ConfigureToolbarPanel() { initComponents(); if (checkSmallIcons.getText().isEmpty()) { checkSmallIcons.setVisible(false); } setCursor( Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR ) ); FileObject paletteFolder = FileUtil.getConfigFile( "Actions" ); // NOI18N DataFolder df = DataFolder.findFolder( paletteFolder ); root = createFolderActionNode(df); final JLabel lblWait = new JLabel( getBundleString("LBL_PleaseWait") ); lblWait.setHorizontalAlignment( JLabel.CENTER ); palettePanel.setPreferredSize( new Dimension( 440, 350 ) ); palettePanel.add( lblWait ); getAccessibleContext().setAccessibleDescription( getBundleString("ACSD_ToolbarCustomizer") ); }
Example 2
Source File: DiffPresenter.java From netbeans with Apache License 2.0 | 6 votes |
private static void setDefaultDiffService(Object ds, String folder) { //System.out.println("setDefaultDiffService("+ds+")"); FileObject services = FileUtil.getConfigFile(folder); DataFolder df = DataFolder.findFolder(services); DataObject[] children = df.getChildren(); //System.out.println(" Got children."); for (int i = 0; i < children.length; i++) { if (children[i] instanceof InstanceDataObject) { InstanceDataObject ido = (InstanceDataObject) children[i]; if (ido.instanceOf(ds.getClass())) { //System.out.println(" Found an instance of my class."); try { if (ds.equals(ido.instanceCreate())) { //System.out.println(" Have it, settings the order."); df.setOrder(new DataObject[] { ido }); break; } } catch (java.io.IOException ioex) { } catch (ClassNotFoundException cnfex) {} } } } }
Example 3
Source File: XSLWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
/** * This is where, the schema gets instantiated from the template. */ public Set instantiate (TemplateWizard wizard) throws IOException { FileObject dir = Templates.getTargetFolder( wizard ); DataFolder df = DataFolder.findFolder( dir ); FileObject template = Templates.getTemplate( wizard ); DataObject dTemplate = DataObject.find( template ); DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard)); if (dobj == null) return Collections.emptySet(); encoding = EncodingUtil.getProjectEncoding(df.getPrimaryFile()); if(!EncodingUtil.isValidEncoding(encoding)) encoding = "UTF-8"; //NOI18N EditCookie edit = dobj.getCookie(EditCookie.class); if (edit != null) { EditorCookie editorCookie = dobj.getCookie(EditorCookie.class); Document doc = (Document)editorCookie.openDocument(); fixEncoding(doc, encoding); SaveCookie save = dobj.getCookie(SaveCookie.class); if (save!=null) save.save(); } return Collections.singleton(dobj.getPrimaryFile()); }
Example 4
Source File: TemplatesPanel.java From netbeans with Apache License 2.0 | 6 votes |
static private DataFolder getTargetFolder (Node [] nodes) { DataFolder folder; if (nodes == null || nodes.length == 0) { folder = DataFolder.findFolder (getTemplatesRoot ()); } else { // try if has a data folder (alert: leaf node can be a empty folder) folder = nodes[0].getLookup ().lookup (DataFolder.class); // if not this node then try its parent if (folder == null && nodes [0].isLeaf ()) { Node parent = nodes [0].getParentNode (); folder = parent.getLookup ().lookup (DataFolder.class); } } return folder; }
Example 5
Source File: JaxWsHandlerCreator.java From netbeans with Apache License 2.0 | 6 votes |
public void createLogicalHandler() throws IOException { String handlerName = Templates.getTargetName(wiz); FileObject pkg = Templates.getTargetFolder(wiz); DataFolder df = DataFolder.findFolder(pkg); FileObject template = Templates.getTemplate(wiz); DataObject dTemplate = DataObject.find(template); DataObject dobj = dTemplate.createFromTemplate(df, handlerName); //open in the editor final EditorCookie ec = dobj.getCookie(EditorCookie.class); RequestProcessor.getDefault().post(new Runnable(){ public void run(){ ec.open(); } }, 1000); }
Example 6
Source File: PhysicalView.java From netbeans with Apache License 2.0 | 6 votes |
@CheckForNull static Node createNodeForSourceGroup( @NonNull final SourceGroup group, @NonNull final Project project) { if ("sharedlibraries".equals(group.getName())) { //NOI18N //HACK - ignore shared libs group in UI, it's only useful for version control commits. return null; } final FileObject rootFolder = group.getRootFolder(); if (!rootFolder.isValid() || !rootFolder.isFolder()) { return null; } final FileObject projectDirectory = project.getProjectDirectory(); return new ProjectIconNode(new GroupNode( project, group, projectDirectory.equals(rootFolder) || FileUtil.isParentOf(rootFolder, projectDirectory), DataFolder.findFolder(rootFolder)), true); }
Example 7
Source File: ExpandFolderTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testGetNodesForAFolderExtjava() throws Exception { CountingSecurityManager.initialize(getWorkDirPath()); long now = System.currentTimeMillis(); DataFolder f = DataFolder.findFolder(root); Node n = f.getNodeDelegate(); Node[] arr = n.getChildren().getNodes(true); assertEquals("1000 nodes", 1000, arr.length); CountingSecurityManager.assertCounts("About 1000 * 4?", 4000, len); }
Example 8
Source File: SCFTHandlerTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testBasePropertiesAlwaysPresent() throws Exception { FileObject root = FileUtil.createMemoryFileSystem().getRoot(); FileObject fo = FileUtil.createData(root, "simpleObject.txt"); OutputStream os = fo.getOutputStream(); String txt = "print('<html><h1>'); print(name); print('</h1>');" + "print('<h2>'); print(date); print('</h2>');" + "print('<h3>'); print(time); print('</h3>');" + "print('<h4>'); print(user); print('</h4>');" + "print('<h4>'); print(dateTime.getTime()); print('</h4>');" + "print('</html>');"; os.write(txt.getBytes()); os.close(); fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); DataObject obj = DataObject.find(fo); DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root, "target")); Map<String,String> parameters = Collections.singletonMap("title", "Nazdar"); DataObject n = obj.createFromTemplate(folder, "complex", parameters); assertEquals("Created in right place", folder, n.getFolder()); assertEquals("Created with right name", "complex.txt", n.getName()); String res = readFile(n.getPrimaryFile()); if (res.indexOf("date") >= 0) fail(res); if (res.indexOf("time") >= 0) fail(res); if (res.indexOf("user") >= 0) fail(res); if (res.indexOf("name") >= 0) fail(res); if (res.indexOf("dateTime") >= 0) fail(res); }
Example 9
Source File: FavoritesNodeTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testCreateNodeAndChangeDataObject() throws Exception { FileObject fo = FileUtil.toFileObject(getWorkDir()); final DataFolder folder = DataFolder.findFolder(fo); final InstanceContent ic = new InstanceContent(); ic.add(folder); AbstractNode node = new AbstractNode(Children.LEAF, new AbstractLookup(ic)); Node res = FavoritesNode.createFilterNode(node); assertFalse("Now it has children", res.isLeaf()); }
Example 10
Source File: WhiteListCategoryPanelTest.java From netbeans with Apache License 2.0 | 5 votes |
private static void createWhiteListsFolder(Class<? extends WhiteListQueryImplementation.UserSelectable>... queries) throws IOException { final FileObject root = FileUtil.getConfigRoot(); final FileObject folder = FileUtil.createFolder(root,"org-netbeans-api-java/whitelists/"); //NOI18N final DataFolder target = DataFolder.findFolder(folder); for (Class<? extends WhiteListQueryImplementation.UserSelectable> q : queries) { InstanceDataObject.create(target, q.getSimpleName(), q); } }
Example 11
Source File: SafeDeleteUI.java From netbeans with Apache License 2.0 | 5 votes |
private void deletePackage(FileObject source) { ClassPath classPath = ClassPath.getClassPath(source, ClassPath.SOURCE); FileObject root = classPath != null ? classPath.findOwnerRoot(source) : null; DataFolder dataFolder = DataFolder.findFolder(source); FileObject parent = dataFolder.getPrimaryFile().getParent(); // First; delete all files except packages try { DataObject ch[] = dataFolder.getChildren(); boolean empty = true; for (int i = 0; ch != null && i < ch.length; i++) { if (!ch[i].getPrimaryFile().isFolder()) { ch[i].delete(); } else if (empty && VisibilityQuery.getDefault().isVisible(ch[i].getPrimaryFile())) { // 156529: hidden folders should be considered as empty content empty = false; } } // If empty delete itself if ( empty ) { dataFolder.delete(); } // Second; delete empty super packages, or empty folders when there is not root while (!parent.equals(root) && parent.getChildren().length == 0) { FileObject newParent = parent.getParent(); parent.delete(); parent = newParent; } } catch (IOException ex) { Exceptions.printStackTrace(ex); } }
Example 12
Source File: Services.java From netbeans with Apache License 2.0 | 5 votes |
private static DataFolder findSessionFolder(String name) { try { FileObject fo = FileUtil.getConfigFile(name); if (fo == null) { // resource not found, try to create new folder fo = FileUtil.createFolder(FileUtil.getConfigRoot(), name); } return DataFolder.findFolder(fo); } catch (IOException ex) { throw (IllegalStateException) new IllegalStateException("Folder not found and cannot be created: " + name).initCause(ex); // NOI18N } }
Example 13
Source File: AbstractGroovyWizard.java From netbeans with Apache License 2.0 | 5 votes |
@Override public Set instantiate(ProgressHandle handle) throws IOException { handle.start(); handle.progress(NbBundle.getMessage(AbstractGroovyWizard.class, "LBL_NewGroovyFileWizardIterator_WizardProgress_CreatingFile")); FileObject template = findCorrectTemplate(); FileObject targetFolder = Templates.getTargetFolder(wiz); String targetName = Templates.getTargetName(wiz); DataFolder dFolder = DataFolder.findFolder(targetFolder); DataObject dTemplate = DataObject.find(template); String pkgName = getPackageName(targetFolder); DataObject dobj; if (pkgName == null) { dobj = dTemplate.createFromTemplate(dFolder, targetName); } else { dobj = dTemplate.createFromTemplate(dFolder, targetName, Collections.singletonMap("package", pkgName)); // NOI18N } FileObject createdFile = dobj.getPrimaryFile(); Project proj = Templates.getProject(wiz); if (!GroovyExtender.isActive(proj)) { GroovyExtender.activate(proj); } handle.finish(); return Collections.singleton(createdFile); }
Example 14
Source File: ToolbarPoolDeadlockTest.java From netbeans with Apache License 2.0 | 5 votes |
@Override protected void setUp() throws Exception { FileObject root = FileUtil.getConfigRoot(); toolbars = FileUtil.createFolder (root, "Toolbars"); toolbarsFolder = DataFolder.findFolder (toolbars); FileObject[] arr = toolbars.getChildren (); for (int i = 0; i < arr.length; i++) { arr[i].delete (); } ToolbarPool tp = ToolbarPool.getDefault (); tp.waitFinished (); }
Example 15
Source File: ActivatorIterator.java From netbeans with Apache License 2.0 | 5 votes |
protected List<WizardDescriptor.Panel<WizardDescriptor>> createPanels (Project project, TemplateWizard wiz) { Sources sources = ProjectUtils.getSources(project); DataFolder targetFolder=null; try { targetFolder = wiz.getTargetFolder(); } catch (IOException ex) { targetFolder = DataFolder.findFolder(project.getProjectDirectory()); } return Collections.<WizardDescriptor.Panel<WizardDescriptor>>singletonList( JavaTemplates.createPackageChooser(project, sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA)) ); }
Example 16
Source File: HibernateWebModuleExtender.java From netbeans with Apache License 2.0 | 4 votes |
public void run() throws IOException { DataFolder targetDataFolder = DataFolder.findFolder(targetFolder); FileObject templateFileObject = FileUtil.getConfigFile("Templates/Hibernate/Hibernate.cfg.xml"); //NOI18N DataObject templateDataObject = DataObject.find(templateFileObject); DataObject newOne = templateDataObject.createFromTemplate( targetDataFolder, DEFAULT_CONFIG_FILENAME); SessionFactory sFactory = new SessionFactory(); int row = 0; if (configPanel.getSelectedDialect() != null && !"".equals(configPanel.getSelectedDialect())) { row = sFactory.addProperty2(configPanel.getSelectedDialect()); sFactory.setAttributeValue(SessionFactory.PROPERTY2, row, "name", dialect); } if (configPanel.getSelectedDriver() != null && !"".equals(configPanel.getSelectedDriver())) { row = sFactory.addProperty2(configPanel.getSelectedDriver()); sFactory.setAttributeValue(SessionFactory.PROPERTY2, row, "name", driver); } if (configPanel.getSelectedURL() != null && !"".equals(configPanel.getSelectedURL())) { row = sFactory.addProperty2(configPanel.getSelectedURL()); sFactory.setAttributeValue(SessionFactory.PROPERTY2, row, "name", url); } if (configPanel.getUserName() != null && !"".equals(configPanel.getUserName())) { row = sFactory.addProperty2(configPanel.getUserName()); sFactory.setAttributeValue(SessionFactory.PROPERTY2, row, "name", userName); } if (configPanel.getPassword() != null && !"".equals(configPanel.getPassword())) { row = sFactory.addProperty2(configPanel.getPassword()); sFactory.setAttributeValue(SessionFactory.PROPERTY2, row, "name", password); } HibernateCfgDataObject hdo = (HibernateCfgDataObject) newOne; hdo.addSessionFactory(sFactory); hdo.save(); // Register Hibernate Library in the project if its not already registered. HibernateEnvironment hibernateEnvironment = enclosingProject.getLookup().lookup(HibernateEnvironment.class); logger.info("Library registered : " + hibernateEnvironment.addHibernateLibraryToProject(hdo.getPrimaryFile())); // Register DB driver if possible. String selectedDriver = configPanel.getSelectedDriver(); if(!hibernateEnvironment.canLoadDBDriver(hdo.getHibernateConfiguration()) && (selectedDriver != null)) { logger.info("DB Driver not registered with the project. Registering now.."); logger.info("DB Driver registered : " + hibernateEnvironment.registerDBDriver(selectedDriver, hdo.getPrimaryFile())); } createdFilesSet.add(hdo.getPrimaryFile()); }
Example 17
Source File: ServletIterator.java From netbeans with Apache License 2.0 | 4 votes |
public Set<DataObject> instantiate() throws IOException { // Create the target folder. The next piece is independent of // the type of file we create, and it should be moved to the // evaluator class instead. The exact same process // should be used when checking if the directory is valid from // the wizard itself. // ------------------------- FROM HERE ------------------------- FileObject dir = Templates.getTargetFolder(wizard); DataFolder df = DataFolder.findFolder(dir); FileObject template = Templates.getTemplate(wizard); if (FileType.FILTER.equals(fileType) && ((WrapperSelection)customPanel).isWrapper()) { template = Templates.getTemplate(wizard); FileObject templateParent = template.getParent(); template = templateParent.getFileObject("AdvancedFilter","java"); //NOI18N } HashMap<String, Object> templateParameters = new HashMap<String, Object>(); templateParameters.put("servletEditorFold", NbBundle.getMessage(ServletIterator.class, "MSG_ServletEditorFold")); //NOI18N templateParameters.put("java17style", isJava17orLater(df.getPrimaryFile())); //NOI18N // Fix for IZ171834 - Badly generated servlet template in JavaEE6 Web Application initServletEmptyData( ); if (!deployData.makeEntry() && Utilities.isJavaEE6Plus(wizard)) { if (fileType == FileType.SERVLET) { AnnotationGenerator.webServlet((ServletData)deployData, templateParameters); } if (fileType == FileType.FILTER) { AnnotationGenerator.webFilter((ServletData)deployData, templateParameters); } } DataObject dTemplate = DataObject.find(template); DataObject dobj = dTemplate.createFromTemplate(df, Templates.getTargetName(wizard), templateParameters); //#150274 Project project = Templates.getProject(wizard); ContainerClassPathModifier modifier = project.getLookup().lookup(ContainerClassPathModifier.class); if (modifier != null) { modifier.extendClasspath(dobj.getPrimaryFile(), new String[] { ContainerClassPathModifier.API_SERVLET }); } // If the user does not want to add the file to the // deployment descriptor, return if (!deployData.makeEntry()) { return Collections.singleton(dobj); } if (!deployData.hasDD()) { // Create web.xml WebModule wm = WebModule.getWebModule(project.getProjectDirectory()); if (wm != null && wm.getDocumentBase() != null) { FileObject webInf = wm.getWebInf(); if (webInf == null) { webInf = FileUtil.createFolder(wm.getDocumentBase(), "WEB-INF"); //NOI18N } FileObject webXml = DDHelper.createWebXml(wm.getJ2eeProfile(), webInf); deployData.setWebApp(webXml); } } // needed to be able to finish ServletWizard from the second panel if (deployData.getClassName().length()==0) { String targetName = wizard.getTargetName(); FileObject targetFolder = Templates.getTargetFolder(wizard); String packageName = null; Sources sources = ProjectUtils.getSources(project); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); for (int i = 0; i < groups.length && packageName == null; i++) { if (WebModule.getWebModule (groups [i].getRootFolder ()) != null) { packageName = FileUtil.getRelativePath (groups [i].getRootFolder (), targetFolder); } } if (packageName!=null) packageName = packageName.replace('/','.'); else packageName=""; // compute (and set) the servlet-class deployData.setClassName(packageName.length()==0?targetName:packageName+"."+targetName); // compute (and set) the servlet-name and url-pattern String servletName = ((ServletData)deployData).createDDServletName(targetName); ((ServletData)deployData).createDDServletMapping(servletName); } deployData.createDDEntries(); if (fileType == FileType.SERVLET && dobj.getPrimaryFile()!=null) { dobj.getPrimaryFile().setAttribute("org.netbeans.modules.web.IsServletFile", Boolean.TRUE); // NOI18N } return Collections.singleton(dobj); }
Example 18
Source File: WebPagesNodeFactory.java From netbeans with Apache License 2.0 | 4 votes |
@Override public Node node(FileObject key) { DataFolder df = DataFolder.findFolder(key); return new WebPagesNode(df.getNodeDelegate().cloneNode(), key); }
Example 19
Source File: ClientSideProjectWizardIterator.java From netbeans with Apache License 2.0 | 4 votes |
private void createIndexFile(FileObject siteRoot) throws IOException { FileObject indexTemplate = FileUtil.getConfigFile("Templates/Other/html.html"); // NOI18N DataFolder dataFolder = DataFolder.findFolder(siteRoot); DataObject dataIndex = DataObject.find(indexTemplate); dataIndex.createFromTemplate(dataFolder, "index"); // NOI18N }
Example 20
Source File: SCFTHandlerTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testTemplateWizardCopiesItsPropertiesToMapForOverridenEntryOnMoreEntries() throws Exception { LocalFileSystem fs = new LocalFileSystem(); fs.setRootDirectory(getWorkDir()); FileObject root = fs.getRoot(); FileObject fo = FileUtil.createData(root, "simpleObject.java"); FileObject fo2 = FileUtil.createData(root, "simpleObject.form"); fo.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); fo2.setAttribute(ScriptingCreateFromTemplateHandler.SCRIPT_ENGINE_ATTR, "js"); Charset set = Charset.forName("iso-8859-2"); OutputStream os = fo2.getOutputStream(); OutputStreamWriter w = new OutputStreamWriter(os, set); String txt = "print('skvělej tým, co nikdy neusíná - ěščřžýáíéúů')"; w.write(txt); w.close(); DataObject obj = DataObject.find(fo); assertEquals(TwoPartObject.class, obj.getClass()); TwoPartObject tpo = (TwoPartObject)obj; tpo.encoding = set; FileObject root2 = FileUtil.createMemoryFileSystem().getRoot(); DataFolder folder = DataFolder.findFolder(FileUtil.createFolder(root2, "target")); Map<String,String> parameters = Collections.singletonMap("type", "empty"); FEQI.fs = root2.getFileSystem(); FEQI.result = Charset.forName("UTF-8"); DataObject n = obj.createFromTemplate(folder, "complex", parameters); Integer cnt = TwoPartLoader.queried.get(n.getPrimaryFile()); assertEquals("No query", null, cnt); assertEquals("Created in right place", folder, n.getFolder()); assertEquals("Created with right name", "complex", n.getName()); Iterator<FileObject> it = n.files().iterator(); it.next(); FileObject snd = it.next(); long length = snd.getSize(); if (length <= 0) { fail("Too small file: " + length + " for " + snd); } String normRead = readChars(snd, Charset.forName("UTF-8")); txt = txt.replaceAll("print\\('", "").replaceAll("'\\)", "") + "\n"; assertEquals(txt, normRead); }