Java Code Examples for org.openide.filesystems.FileUtil#getFileDisplayName()

The following examples show how to use org.openide.filesystems.FileUtil#getFileDisplayName() . 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: ClassPathListCellRenderer.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private String getToolTipText( ClassPathSupport.Item item ) {
    if ( item.isBroken() &&
         ( item.getType() == ClassPathSupport.Item.TYPE_JAR ||
           item.getType() == ClassPathSupport.Item.TYPE_ARTIFACT )  ) {
        return evaluator.evaluate( item.getReference() );
    }
    switch ( item.getType() ) {
        case ClassPathSupport.Item.TYPE_JAR:
            File f = item.getResolvedFile();
            // if not absolute path:
            if (!f.getPath().equals(item.getFilePath()) || item.getVariableBasedProperty() != null) {
                return f.getPath();
            }
            break;
        case ClassPathSupport.Item.TYPE_ARTIFACT:                
            final AntArtifact artifact = item.getArtifact();
            if (artifact != null) {
                final FileObject projDir = artifact.getProject().getProjectDirectory();
                if (projDir != null) {
                    return FileUtil.getFileDisplayName(projDir);
                }
            }               
    }

    return null;
}
 
Example 2
Source File: ClassPathFileChooser.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Node createPackageRootNode(FileObject rootFO, Project project, Filter filter) {
    Node origNode;
    try {
        origNode = DataObject.find(rootFO).getNodeDelegate();
    }
    catch (DataObjectNotFoundException ex) {
        ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex);
        return null;
    }

    String displayName;
    Project owner = FileOwnerQuery.getOwner(rootFO);
    if (owner != null) {
        SourceGroup g = getSourceGroup(rootFO, owner);
        displayName = g != null ? g.getDisplayName() : FileUtil.getFileDisplayName(rootFO);
        if (project != owner) {
            ProjectInformation pi = ProjectUtils.getInformation(owner);
            displayName += " [" + pi.getDisplayName() + "]"; // NOI18N
        }
    }
    else displayName = FileUtil.getFileDisplayName(rootFO);

    return new FilteredNode(origNode, displayName, filter);

}
 
Example 3
Source File: GrailsTargetChooserPanelGUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void updateText() {  
    SourceGroup g = group;
    FileObject rootFolder = g.getRootFolder();
    String packageName = getPackageFileName();
    String documentName = documentNameTextField.getText().trim();
    if ( documentName.length() > 0 ) {
        documentName = documentName + expectedExtension;
    }
    String createdFileName = FileUtil.getFileDisplayName( rootFolder ) + 
        ( packageName.startsWith("/") || packageName.startsWith( File.separator ) ? "" : "/" ) + // NOI18N
        packageName + 
        ( packageName.endsWith("/") || packageName.endsWith( File.separator ) || packageName.length() == 0 ? "" : "/" ) + // NOI18N
        documentName;
    
    fileTextField.setText( createdFileName.replace( '/', File.separatorChar ) ); // NOI18N        
}
 
Example 4
Source File: SQLEditorSupport.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void saveAs(FileObject folder, String fileName) throws IOException {
    String fn = FileUtil.getFileDisplayName(folder) + File.separator + fileName; 
    File existingFile = FileUtil.normalizeFile(new File(fn));
    if (existingFile.exists()) {
        NotifyDescriptor confirm = new NotifyDescriptor.Confirmation(
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplace", fileName),
                NbBundle.getMessage(SQLEditorSupport.class,
                "MSG_ConfirmReplaceFileTitle"),
                NotifyDescriptor.YES_NO_OPTION);
        DialogDisplayer.getDefault().notify(confirm);
        if (!confirm.getValue().equals(NotifyDescriptor.YES_OPTION)) {
            return;
        }
    }
    if (isConsole()) {
        // #166370 - if console, need to save document before copying
        saveDocument();
    }
    super.saveAs(folder, fileName);
}
 
Example 5
Source File: VariousUtils.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @param sourceFile needs to be data file (not folder)
 */
public static FileObject resolveInclude(FileObject sourceFile, Include include) {
    Parameters.notNull("sourceFile", sourceFile); //NOI18N
    if (sourceFile.isFolder()) {
        throw new IllegalArgumentException(FileUtil.getFileDisplayName(sourceFile));
    }
    return resolveInclude(sourceFile, resolveFileName(include));
}
 
Example 6
Source File: SourceGroupSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public String getCurrentPackagePath() {
    if(currentPackageName != null && currentSourceGroup != null) {
        String packageNameDecorated = (currentPackageName.startsWith("/") || currentPackageName.startsWith(File.separator) ? "" : "/") + // NOI18N
                currentPackageName
                + (currentPackageName.endsWith("/") || currentPackageName.endsWith(File.separator) || currentPackageName.length() == 0 ? "" : "/"); // NOI18N
        if(currentSourceGroup.isReal()) {
             return FileUtil.getFileDisplayName(currentSourceGroup.getRootFolder()) + packageNameDecorated;
        }
        return FileUtil.getFileDisplayName(currentSourceGroup.getRootFolder()) + "/<" + currentSourceGroup.getDisplayName() + ">" + packageNameDecorated; // NOI18N
    }
    return null;
}
 
Example 7
Source File: ModifyElementRulesPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private ListCellRenderer createStyleSheetsRenderer() {
    return new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            if (value == null) {
                setText("<html>" + Bundle.none_item());
            } else {
                FileObject file = (FileObject) value;
                FileObject webRoot = ProjectWebRootQuery.getWebRoot(file);

                String file2string;
                if (webRoot != null) {
                    file2string = FileUtil.getRelativePath(webRoot, file);
                } else {
                    file2string = FileUtil.getFileDisplayName(file);
                }

                setText(file2string);
            }
            return c;
        }
    };
}
 
Example 8
Source File: ModificationResult.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Returned string represents preview of resulting source. No difference
 * really is applied. Respects {@code isExcluded()} flag of difference.
 * 
 * @param   there can be more resulting source, user has to specify
 *          which wants to preview.
 * @return  if changes are applied source looks like return string
 * @throws  IllegalArgumentException if the provided {@link FileObject} is not
 *                                   modified in this {@link ModificationResult}
 */
public String getResultingSource(FileObject fileObject) throws IOException, IllegalArgumentException {
    Parameters.notNull("fileObject", fileObject);

    if (!getModifiedFileObjects().contains(fileObject)) {
        throw new IllegalArgumentException("File: " + FileUtil.getFileDisplayName(fileObject) + " is not modified in this ModificationResult");
    }
    
    StringWriter writer = new StringWriter();
    commit(fileObject, diffs.get(fileObject), writer);
    
    return writer.toString();
}
 
Example 9
Source File: AdvancedTasksStorage.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static AdvancedTasksStorage forBuildToolSupport(BuildTools.BuildToolSupport support) {
    Parameters.notNull("support", support); // NOI18N
    String workDirPath;
    FileObject workDir = support.getWorkDir();
    String relativePath = FileUtil.getRelativePath(support.getProject().getProjectDirectory(), workDir);
    if (relativePath != null) {
        workDirPath = relativePath;
    } else {
        workDirPath = FileUtil.getFileDisplayName(workDir);
    }
    return new AdvancedTasksStorage(support.getProject(), support.getIdentifier(), workDirPath);
}
 
Example 10
Source File: LayerHandle.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override String toString() {
    FileObject layer = getLayerFile();
    if (layer != null) {
        return FileUtil.getFileDisplayName(layer);
    } else {
        return FileUtil.getFileDisplayName(project.getProjectDirectory());
    }
}
 
Example 11
Source File: MoveMembersTransformer.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void changeMemberRefer(Element el, final MemberReferenceTree node, TreePath currentPath, final Element target) {
    if (el.getModifiers().contains(Modifier.STATIC)) {
        Tree oldT = node.getQualifierExpression();
        Tree newT = make.QualIdent(make.setLabel(make.QualIdent(target), target.getSimpleName()).toString());
        rewrite(oldT, newT);
    } else {
        SourcePositions positions = workingCopy.getTrees().getSourcePositions();
        long startPosition = positions.getStartPosition(workingCopy.getCompilationUnit(), node);
        long lineNumber = workingCopy.getCompilationUnit().getLineMap().getLineNumber(startPosition);
        String source = FileUtil.getFileDisplayName(workingCopy.getFileObject()) + ':' + lineNumber;
        problem = JavaPluginUtils.chainProblems(problem, new Problem(false, NbBundle.getMessage(MoveMembersRefactoringPlugin.class, "WRN_NoAccessor", source))); //NOI18N
    }
}
 
Example 12
Source File: FileProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Adds a file into the result
 * When the file is under processed {@link  SourceGroup} relative path
 * is displayed in the dialog. If the file is not under
 * {@link SourceGroup} absolute path is used. Never add a file owned by
 * other {@link SourceGroup}.
 * @param file The file to be added into result
 */
public void addFile (final FileObject file) {
    Parameters.notNull("file", file);   //NOI18N
    String path = FileUtil.getRelativePath(ctx.getRoot(), file);
    if (path == null) {
        path = FileUtil.getFileDisplayName(file);
    }
    final Project prj = ctx.getProject();
    addFileDescriptor(new FileDescription(file, path, prj));
}
 
Example 13
Source File: EjbRefactoringPlugin.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * @return a comma separated string representing the locations of the ejb-jar.xml files of the
 * given <code>ejbJars</code>.
 */
private String getEjbJarPaths(List<EjbJar> ejbJars) {
    // TODO: it would be probably better to display the project names instead
    StringBuilder ejbJarPaths = new StringBuilder();
    for (Iterator<EjbJar> it = ejbJars.iterator(); it.hasNext();) {
        EjbJar ejbJar = it.next();
        String path = FileUtil.getFileDisplayName(ejbJar.getDeploymentDescriptor());
        ejbJarPaths.append(path);
        if (it.hasNext()) {
            ejbJarPaths.append(", ");
        }
    }
    return ejbJarPaths.toString();
}
 
Example 14
Source File: DataEditorSupport.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a tool tip possibly marked up with document modified and read-only status.
 * Done for subclasses automatically in {@link #messageToolTip} but useful for other editor-like windows.
 * <p class="nonnormative">Behavior currently varies according to the system property {@code nb.tabnames.html}.</p>
 * @param file a file representing the tab
 * @param modified mark up the tool tip as for a document which is modified in memory
 * @param readOnly mark up the tool tip as for a document based on a read-only file
 * @return a tool tip
 * @since org.openide.loaders 7.7
 */
public static String toolTip(FileObject file, boolean modified, boolean readOnly) {
    String tip = FileUtil.getFileDisplayName(file);
    if (TABNAMES_HTML) {
        if (modified) {
            tip += NbBundle.getMessage(DataObject.class, "TIP_editor_modified");
        }
        if (readOnly) {
            tip += NbBundle.getMessage(DataObject.class, "TIP_editor_ro");
        }
    }
    return tip;
}
 
Example 15
Source File: ClientSideProjectLogicalView.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@NbBundle.Messages({
    "# {0} - project directory",
    "ClientSideProjectNode.project.description=HTML5 application in {0}",
    "# {0} - project directory",
    "ClientSideProjectNode.library.description=JavaScript library in {0}",
})
@Override
public String getShortDescription() {
    String projectDirName = FileUtil.getFileDisplayName(project.getProjectDirectory());
    if (project.isJsLibrary()) {
        return Bundle.ClientSideProjectNode_library_description(projectDirName);
    }
    return Bundle.ClientSideProjectNode_project_description(projectDirName);
}
 
Example 16
Source File: BootCPNodeFactory.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public String getShortDescription() {
    final Pair<String,JavaPlatform> platHolder = pp.getPlatform();
    if (platHolder != null && platHolder.second() != null && !platHolder.second().getInstallFolders().isEmpty()) {
        final FileObject installFolder = platHolder.second().getInstallFolders().iterator().next();
        return FileUtil.getFileDisplayName(installFolder);
    } else {
        return super.getShortDescription();
    }
}
 
Example 17
Source File: WritableXMLFileSystem.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public String getDisplayName() {
    FileObject fo = URLMapper.findFileObject(location);
    if (fo != null) {
        return FileUtil.getFileDisplayName(fo);
    } else {
        return location.toExternalForm();
    }
}
 
Example 18
Source File: J2SEModularProject.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public String toString() {
    return "J2SEModularProject[" + FileUtil.getFileDisplayName(getProjectDirectory()) + "]"; // NOI18N
}
 
Example 19
Source File: EditorSaveCookie.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private static String getName(FileObject fileObj) {
    return (fileObj != null) ? FileUtil.getFileDisplayName(fileObj) : null;
}
 
Example 20
Source File: DefaultSuiteProjectOperationsImplementation.java    From netbeans with Apache License 2.0 4 votes vote down vote up
static void deleteProject(final SuiteProject project, UserInputHandler handler) {
    String displayName = getDisplayName(project);
    FileObject projectFolder = project.getProjectDirectory();
    
    LOG.log(Level.FINE, "delete started: {0}", displayName);
    
    final List<FileObject> metadataFiles = ProjectOperations.getMetadataFiles(project);
    final List<FileObject> dataFiles = ProjectOperations.getDataFiles(project);
    final List<FileObject> allFiles = new ArrayList<FileObject>();
    
    allFiles.addAll(metadataFiles);
    allFiles.addAll(dataFiles);
    
    for (Iterator<FileObject> i = allFiles.iterator(); i.hasNext(); ) {
        FileObject f = i.next();
        if (!FileUtil.isParentOf(projectFolder, f)) {
            if (projectFolder.equals(f)) {
                // sources == project directory
                continue;
            }
            i.remove();
        }
    }
    
    
    final SubprojectProvider suiteProvider = project.getLookup().lookup(SubprojectProvider.class);
    final Set<Project> subProjects = (Set<Project>) suiteProvider.getSubprojects();
    final Set<NbModuleProject> subModules = new HashSet<NbModuleProject>();
    for(Project prjIter:subProjects) {
        NbModuleProject nbModulePrj = prjIter.getLookup().lookup(NbModuleProject.class);
        if(nbModulePrj != null) {
            subModules.add(nbModulePrj);
        }
    }
    final Map<NbModuleProject,List<FileObject>> subModulesDataFiles = getSubModulesDataFiles(subModules);
    
    
    final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(DefaultSuiteProjectOperationsImplementation.class, "LBL_Delete_Project_Caption"));
    final DefaultSuiteProjectDeletePanel deletePanel = new DefaultSuiteProjectDeletePanel(handle, displayName, FileUtil.getFileDisplayName(projectFolder), !subModulesDataFiles.isEmpty(), !subModules.isEmpty());
    
    String caption = NbBundle.getMessage(DefaultSuiteProjectOperationsImplementation.class, "LBL_Delete_Project_Caption");
    
    handler.showConfirmationDialog(deletePanel, project, caption, "Yes_Button", "No_Button", true, new Executor() { // NOI18N
        public @Override void execute() throws Exception {
            deletePanel.addProgressBar();
            
            close(project);
            
            Map<NbModuleProject,List<FileObject>> subModulesAllFiles = null;
            Map<NbModuleProject,List<FileObject>> subModulesMetadataFiles = null;
            
            if(deletePanel.isDeleteModules()) {
                for(NbModuleProject modulePrjIter:subModules) {
                    close(modulePrjIter);
                }
                subModulesAllFiles = new HashMap<NbModuleProject, List<FileObject>>();
                subModulesAllFiles.putAll(subModulesDataFiles);
                subModulesMetadataFiles = getSubModulesMetadataFiles(subModules, subModulesAllFiles);
            } 
            
            if (deletePanel.isDeleteSources()) {
                performDelete(project, allFiles, subModulesAllFiles, handle);
            } else {
                performDelete(project, metadataFiles, subModulesMetadataFiles, handle);
            }
            deletePanel.removeProgressBar();
        }
    });
    
    LOG.log(Level.FINE, "delete done: {0}", displayName);
}