Java Code Examples for org.openide.loaders.DataFolder#getPrimaryFile()
The following examples show how to use
org.openide.loaders.DataFolder#getPrimaryFile() .
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: JavaTemplateAttributesProvider.java From netbeans with Apache License 2.0 | 6 votes |
public Map<String,?> attributesFor(DataObject template, DataFolder target, String name) { FileObject templateFO = template.getPrimaryFile(); if (!JavaDataLoader.JAVA_EXTENSION.equals(templateFO.getExt()) || templateFO.isFolder()) { return null; } FileObject targetFO = target.getPrimaryFile(); Map<String,Object> result = new HashMap<String,Object>(); ClassPath cp = ClassPath.getClassPath(targetFO, ClassPath.SOURCE); if (cp == null) { LOG.warning("No classpath was found for folder: " + target.getPrimaryFile()); // NOI18N } else { result.put("package", cp.getResourceName(targetFO, '.', false)); // NOI18N } String sourceLevel = SourceLevelQuery.getSourceLevel(targetFO); if (sourceLevel != null) { result.put("javaSourceLevel", sourceLevel); // NOI18N if (isJava15orLater(sourceLevel)) result.put("java15style", Boolean.TRUE); // NOI18N } return result; }
Example 2
Source File: ProjectTemplateAttributesLegacy.java From netbeans with Apache License 2.0 | 6 votes |
@Override public Map<String, ?> attributesFor(DataObject template, DataFolder target, String name) { FileObject targetF = target.getPrimaryFile(); Project prj = FileOwnerQuery.getOwner(targetF); Map<String, Object> all = new HashMap<>(); if (prj != null) { // call old providers Collection<? extends CreateFromTemplateAttributesProvider> oldProvs = prj.getLookup().lookupAll(CreateFromTemplateAttributesProvider.class); if (!oldProvs.isEmpty()) { for (CreateFromTemplateAttributesProvider attrs : oldProvs) { Map<String, ? extends Object> m = attrs.attributesFor(template, target, name); if (m != null) { all.putAll(m); } } } } all.put(ProjectTemplateAttributesLegacy.class.getName(), Boolean.TRUE); return checkProjectAttrs(all, targetF); }
Example 3
Source File: LayersBridge.java From netbeans with Apache License 2.0 | 6 votes |
/** * Custom profile is present if: * a/ the profile's folder can be reverted (=> was materialized on writable layer) * b/ there's no "reveal" entry for it in its parent => was not present * @param profileName * @return C */ public boolean isCustomProfile(String profileName) { DataFolder profileFolder = getExistingProfile(profileName); if (profileFolder == null) { return true; } FileObject f = profileFolder.getPrimaryFile(); if (!f.canRevert()) { return false; } FileObject parentF = profileFolder.getPrimaryFile().getParent(); if (parentF == null) { // very very unlikely return true; } Collection<FileObject> col = (Collection<FileObject>)parentF.getAttribute("revealEntries"); if (col == null) { return true; } for (FileObject f2 : col) { if (f2.getNameExt().equals(profileName)) { return false; } } return true; }
Example 4
Source File: FolderRenameHandlerImpl.java From netbeans with Apache License 2.0 | 6 votes |
@Override public void handleRename(DataFolder folder, String newName) { InstanceContent ic = new InstanceContent(); ic.add(folder.getNodeDelegate()); ExplorerContext d = new ExplorerContext(); d.setNewName(newName); ic.add(d); final Lookup l = new AbstractLookup(ic); if (ActionsImplementationFactory.canRename(l)) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l); a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT); } }); } else { FileObject fo = folder.getPrimaryFile(); try { folder.rename(newName); } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } } }
Example 5
Source File: ActionPasteType.java From netbeans with Apache License 2.0 | 6 votes |
/** * */ static PasteType getPasteType(final DataFolder targetFolder, final Transferable transfer) { final FileObject folder = targetFolder.getPrimaryFile(); PasteType retVal = null; try { /*Copy/Cut/Paste is allowed just on SystemFileSystem*/ if (folder.getFileSystem().isDefault()) { final int[] pasteOperations = new int[]{LoaderTransfer.CLIPBOARD_COPY, LoaderTransfer.CLIPBOARD_CUT}; for (int i = 0; i < pasteOperations.length; i++) { final DataObject[] dataObjects = LoaderTransfer.getDataObjects(transfer, pasteOperations[i]); if (dataObjects != null) { if (canBePasted(dataObjects, targetFolder, pasteOperations[i])) { retVal = new PasteTypeImpl(Arrays.asList(dataObjects), targetFolder, pasteOperations[i]); break; } } } } } catch (FileStateInvalidException e) {/*just null is returned if folder.getFileSystem fires ISE*/} return retVal; }
Example 6
Source File: TargetEvaluator.java From netbeans with Apache License 2.0 | 6 votes |
/** * Used by the ObjectNameWizard panel to set the target folder * gotten from the system wizard initially. */ void setInitialFolder(DataFolder selectedFolder, Project p) { if (selectedFolder == null) { return; } FileObject targetFolder = selectedFolder.getPrimaryFile(); Sources sources = ProjectUtils.getSources(p); SourceGroup[] groups = sources.getSourceGroups(JavaProjectConstants.SOURCES_TYPE_JAVA); String packageName = null; for (int i = 0; i < groups.length && packageName == null; i++) { packageName = org.openide.filesystems.FileUtil.getRelativePath(groups[i].getRootFolder(), targetFolder); deployData.setWebApp(DeployData.getWebAppFor(groups[i].getRootFolder())); } if (packageName == null) { packageName = ""; } setInitialPath(packageName); }
Example 7
Source File: GUIRegistrationPanel.java From netbeans with Apache License 2.0 | 5 votes |
/** * Actually really dedicated for Loader…Actions and * Editors…Popup. */ private List<DataFolder> getFoldersByName(final DataFolder startFolder, final String subFoldersName) { List<DataFolder> result = new ArrayList<DataFolder>(); for (DataFolder dObj : getFolders(startFolder)) { if (subFoldersName.equals(dObj.getName()) && dObj.getPrimaryFile().getParent() != startFolder.getPrimaryFile()) { result.add(dObj); } } return result; }
Example 8
Source File: CategoryNode.java From netbeans with Apache License 2.0 | 5 votes |
private CategoryNode( Node originalNode, InstanceContent content, Lookup lkp ) { super( originalNode, new Children( originalNode, lkp ), new ProxyLookup( new Lookup[] { lkp, new AbstractLookup(content), originalNode.getLookup() } ) ); DataFolder folder = (DataFolder)originalNode.getCookie( DataFolder.class ); if( null != folder ) { content.add( new DataFolder.Index( folder, this ) ); FileObject fob = folder.getPrimaryFile(); Object catName = fob.getAttribute( CAT_NAME ); if (catName instanceof String) setDisplayName((String)catName); } content.add( this ); }
Example 9
Source File: DefaultSettings.java From netbeans with Apache License 2.0 | 5 votes |
private String constructPrefsFileName( Model model ) { DataFolder dof = (DataFolder)model.getRoot().lookup( DataFolder.class ); if( null != dof ) { FileObject fo = dof.getPrimaryFile(); if( null != fo ) { return fo.getPath(); } } return model.getName(); }
Example 10
Source File: SrcNode.java From netbeans with Apache License 2.0 | 5 votes |
private SrcNode(final PhpProject project, DataFolder folder, final FilterNode node, String name, final boolean isTest) { super(node, org.openide.nodes.Children.createLazy(new Callable<org.openide.nodes.Children>() { @Override public org.openide.nodes.Children call() throws Exception { return new FolderChildren(project, node, isTest); } }), new ProxyLookup(folder.getNodeDelegate().getLookup())); this.project = project; this.isTest = isTest; fo = folder.getPrimaryFile(); disableDelegation(DELEGATE_GET_DISPLAY_NAME | DELEGATE_SET_DISPLAY_NAME | DELEGATE_GET_SHORT_DESCRIPTION | DELEGATE_GET_ACTIONS); setDisplayName(name); }
Example 11
Source File: ModelTest.java From netbeans with Apache License 2.0 | 5 votes |
/** * Test of getRoot method, of class org.netbeans.modules.palette.Model. */ public void testGetRoot() throws IOException { PaletteController pc = PaletteFactory.createPalette( getRootFolderName(), new DummyActions() ); Model model = pc.getModel(); Lookup rootLookup = model.getRoot(); DataFolder df = (DataFolder)rootLookup.lookup( DataFolder.class ); assertNotNull( df ); FileObject fo = df.getPrimaryFile(); assertNotNull( fo ); assertEquals( getRootFolderName(), fo.getName() ); }
Example 12
Source File: AbstractTestUtil.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates new Data Object */ public static DataObject createDataObject(DataFolder folder, final String name, final String extension, final String content) throws IOException { final FileObject targetFolder = folder.getPrimaryFile(); FileSystem filesystem = targetFolder.getFileSystem(); final FileObject[] fileObject = new FileObject[1]; AtomicAction fsAction = new AtomicAction() { public void run() throws IOException { FileObject fo = targetFolder.createData(name, extension); FileLock lock = null; try { lock = fo.lock(); OutputStream out = fo.getOutputStream(lock); out = new BufferedOutputStream(out, 999); Writer writer = new OutputStreamWriter(out, "UTF8"); // NOI18N writer.write(content + '\n'); // NOI18N writer.flush(); writer.close(); // return DataObject lock.releaseLock(); lock = null; fileObject[0] = fo; } finally { if (lock != null) lock.releaseLock(); } } }; filesystem.runAtomicAction(fsAction); return DataObject.find(fileObject[0]); }
Example 13
Source File: ActionPasteType.java From netbeans with Apache License 2.0 | 5 votes |
private static boolean canBePasted(final DataObject[] dataObjects, final DataFolder targetFolder, final int operation) throws FileStateInvalidException { final Set<DataObject> pasteableDataObjects = new HashSet<DataObject> (); final FileObject folder = targetFolder.getPrimaryFile(); DataObject[] folderChildren = targetFolder.getChildren(); for (int j = 0; j < dataObjects.length; j++) { final DataObject dataObject = dataObjects[j]; final FileObject fo = dataObject.getPrimaryFile (); if (!isAction(dataObject) || !fo.getFileSystem().isDefault()) { break; } final boolean isCopyPaste = operation == LoaderTransfer.CLIPBOARD_COPY && dataObject.isCopyAllowed(); final boolean isCutPaste = operation == LoaderTransfer.CLIPBOARD_CUT && dataObject.isMoveAllowed() && !(fo.getParent() == folder);//prevents from cutting into the same folder where it was if (isCopyPaste || isCutPaste) { boolean isDuplicate = false; for( int i=0; i<folderChildren.length; i++ ) { if( 0 == folderChildren[i].getName().compareTo( dataObject.getName() ) ) { isDuplicate = true; break; } } if( !isDuplicate ) pasteableDataObjects.add(dataObject); } } return (pasteableDataObjects.size() == dataObjects.length); }
Example 14
Source File: ToolbarPool.java From netbeans with Apache License 2.0 | 5 votes |
/** * Returns a <code>Toolbar.Folder</code> cookie for the specified * <code>DataFolder</code>. * @param df a <code>DataFolder</code> to create the cookie for * @return a <code>Toolbar.Folder</code> for the specified folder */ @Override protected InstanceCookie acceptFolder (DataFolder df) { Toolbar res = new Toolbar(df); //#223266 FileObject fo = df.getPrimaryFile(); Object disable = fo.getAttribute("nb.toolbar.overflow.disable"); //NOI18N if (Boolean.TRUE.equals(disable)) { res.putClientProperty("nb.toolbar.overflow.disable", Boolean.TRUE); //NOI18N } return res.waitFinished(); }
Example 15
Source File: MenuBar.java From netbeans with Apache License 2.0 | 5 votes |
/** Constructor. */ public LazyMenu(final DataFolder df, boolean icon) { this.master = df; this.icon = icon; this.dynaModel = new DynaMenuModel(); this.slave = new MenuFolder(); setName(df.getName()); final FileObject pf = df.getPrimaryFile(); Object prefix = pf.getAttribute("property-prefix"); // NOI18N if (prefix instanceof String) { Enumeration<String> en = pf.getAttributes(); while (en.hasMoreElements()) { String attrName = en.nextElement(); if (attrName.startsWith((String)prefix)) { putClientProperty( attrName.substring(((String)prefix).length()), pf.getAttribute(attrName) ); } } } // Listen for changes in Node's DisplayName/Icon Node n = master.getNodeDelegate (); n.addNodeListener (org.openide.nodes.NodeOp.weakNodeListener (this, n)); Mutex.EVENT.readAccess(this); getModel().addChangeListener(this); }
Example 16
Source File: XMLWizardIterator.java From netbeans with Apache License 2.0 | 4 votes |
public Set instantiate(TemplateWizard templateWizard) throws IOException { final DataFolder folder = templateWizard.getTargetFolder(); final File pobj = FileUtil.toFile(folder.getPrimaryFile()); final String extension = XML_EXT; // #22812 we do not control validity constrains of target panel // assure uniquess to "<default>" name String targetName = templateWizard.getTargetName(); if (targetName == null || "null".equals(targetName)) { // NOI18N targetName = "XMLDocument"; // NOI18N } final FileObject targetFolder = folder.getPrimaryFile(); String uniqueTargetName = targetName; int i = 2; while (targetFolder.getFileObject(uniqueTargetName, extension) != null) { uniqueTargetName = targetName + i; i++; } final String name = uniqueTargetName; String nameExt = name + "." + extension; // in atomic action create data object and return it FileSystem filesystem = targetFolder.getFileSystem(); final Map<String, Object> params = prepareParameters(folder); FileObject template = Templates.getTemplate(templateWizard); final DataObject dTemplate = DataObject.find(template); DataObject dobj = dTemplate.createFromTemplate(folder, name, params); FileObject f = dobj.getPrimaryFile(); // perform default action and return Set set = new HashSet(1); DataObject createdObject = DataObject.find(f); GuiUtil.performDefaultAction(createdObject); set.add(createdObject); formatXML(f); return set; }
Example 17
Source File: MasterPanel.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void readSettings(Object settings) { wizardDesc = (WizardDescriptor) settings; boolean valid = true; if (!inNewProject && (settings instanceof TemplateWizard)) { try { TemplateWizard wizard = (TemplateWizard)settings; DataFolder folder = wizard.getTargetFolder(); FileObject fob = folder.getPrimaryFile(); ClassPath cp = ClassPath.getClassPath(fob, ClassPath.SOURCE); String name = cp.getResourceName(fob).trim(); valid = (name.length() != 0); if (!valid) { showMsg("MSG_MasterDefaultPackage"); // NOI18N } else { FileObject root = cp.findOwnerRoot(fob); URL[] urls = UnitTestForSourceQuery.findSources(root); if (urls.length != 0) { showMsg("MSG_MasterTestPackage"); // NOI18N valid = false; } } Project project = FileOwnerQuery.getOwner(fob); if (project.getLookup().lookup(PersistenceLocationProvider.class) == null) { // For example module project showMsg("MSG_MasterNoProvider"); // NOI18N valid = false; } } catch (IOException ioex) { Logger.getLogger(getClass().getName()).log(Level.INFO, ioex.getMessage(), ioex); } } connectionCombo.setEnabled(valid); if (!valid) { setValid(false); } else { if (connectionCombo.getSelectedItem() == null) { showMsg("MSG_MasterDefaultConnection",true); // NOI18N } } // After pushing Back button and Next button wizard removes label text // This code will setup last msg again if (lastMsg != null) { showMsg(lastMsg, lastMsgInfoIconEnabled); } }
Example 18
Source File: LayersBridge.java From netbeans with Apache License 2.0 | 4 votes |
/** * Reads original keymap entries, which are now replaced or deleted by the user's * writable layer. * * @param root * @return */ private Map<ShortcutAction, Set<String>> readOriginalKeymap(DataFolder root) { Map<ShortcutAction, Set<String>> keymap = new HashMap<ShortcutAction, Set<String>> (); if (root == null) return keymap; FileObject fo = root.getPrimaryFile(); Collection<FileObject> entries = (Collection<FileObject>)fo.getAttribute("revealEntries"); Set<String> names = new HashSet<String>(); for (FileObject f : entries) { try { GlobalAction action; names.add(f.getName()); if (EXT_REMOVED.equals(f.getExt()) && FileUtil.findBrother(f, "shadow") == null) { action = REMOVED; } else { FileObject orig = DataShadow.findOriginal(f); if (orig == null) { continue; } DataObject dataObject = DataObject.find(orig); if (dataObject instanceof DataFolder) continue; action = createActionWithLookup (dataObject, null, f.getName(), false); } if (action == null) continue; String shortcut = f.getName(); LOG.log(Level.FINEST, "Overriden action {0}: {1}, by {2}", new Object[] { action.getId(), shortcut, f.getPath() }); Set<String> s = keymap.get (action); if (s == null) { s = new HashSet<String> (); keymap.put (action, s); } s.add (shortcut); } catch (IOException ex) { // handle somehow } } return keymap; }
Example 19
Source File: DBSchemaWizardIterator.java From netbeans with Apache License 2.0 | 4 votes |
/** * Hack which sets the default target to the src/conf or src directory, * whichever exists. */ private void setDefaultTarget() { FileObject targetFO; try { DataFolder target = wizardInstance.getTargetFolder(); targetFO = target.getPrimaryFile(); } catch (IOException e) { targetFO = null; } Project targetProject = Templates.getProject(wizardInstance); if (targetProject != null) { FileObject projectDir = targetProject.getProjectDirectory(); if (targetFO == null || targetFO.equals(projectDir)) { FileObject newTargetFO = projectDir.getFileObject("src/conf"); // NOI18N if (newTargetFO == null || !newTargetFO.isValid()) { newTargetFO = projectDir.getFileObject("src/META-INF"); // NOI18N // take existence of <projectdir>/src/main as indication // of maven style project layout FileObject tempFo = projectDir.getFileObject("src/main"); // NOI18N if (tempFo != null) { try { newTargetFO = FileUtil.createFolder(tempFo, "resources/META-INF"); } catch (IOException ex) { LOG.log(Level.INFO, "Failed to create META-INF folder", ex); } } if (newTargetFO == null) { if (newTargetFO == null || !newTargetFO.isValid()) { newTargetFO = projectDir.getFileObject("src"); // NOI18N if (newTargetFO == null || !newTargetFO.isValid()) { return; } } } } DataFolder newTarget = DataFolder.findFolder(newTargetFO); wizardInstance.setTargetFolder(newTarget); } } }
Example 20
Source File: PackageRenameHandlerImpl.java From netbeans with Apache License 2.0 | 4 votes |
@Override public void handleRename(Node node, String newName) { DataFolder dob = (DataFolder) node.getCookie(DataObject.class); FileObject fo = dob.getPrimaryFile(); if (node.isLeaf()) { //rename empty package and don't try to do any refactoring try { if (!RefactoringUtils.isValidPackageName(newName)) { String msg = new MessageFormat(NbBundle.getMessage(RenameRefactoringPlugin.class,"ERR_InvalidPackage")).format( new Object[] {newName} ); DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( msg, NotifyDescriptor.INFORMATION_MESSAGE)); return; } ClassPath sourcepath = ClassPath.getClassPath(fo, ClassPath.SOURCE); if (sourcepath == null) { throw new IOException("no sourcepath for " + fo); } FileObject root = sourcepath.findOwnerRoot(fo); if (root == null) { throw new IOException(fo + " not in its own sourcepath " + sourcepath); } FileObject newFolder = FileUtil.createFolder(root, newName.replace('.','/')); while (dob.getChildren().length == 0 && dob.isDeleteAllowed() && !dob.getPrimaryFile().equals(newFolder)) { DataFolder parent = dob.getFolder(); dob.delete(); dob = parent; } } catch (IOException ioe) { ErrorManager.getDefault().notify(ioe); } return; } InstanceContent ic = new InstanceContent(); ic.add(node); ExplorerContext d = new ExplorerContext(); d.setNewName(newName); ic.add(d); final Lookup l = new AbstractLookup(ic); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { Action a = RefactoringActionsFactory.renameAction().createContextAwareInstance(l); if (Boolean.TRUE.equals(a.getValue("applicable"))) { //NOI18N a.actionPerformed(RefactoringActionsFactory.DEFAULT_EVENT); } } }); }