Search in sources :

Example 1 with MMapURI

use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.

the class RefactoringUtils method makeNewMMapUri.

public static MMapURI makeNewMMapUri(@Nonnull final Project project, @Nonnull final MMapURI oldFile, @Nonnull VirtualFile newFile) {
    final File projectFolder = IdeaUtils.findProjectFolder(project);
    if (projectFolder == null)
        throw new NullPointerException("Project folder is not found for " + project);
    URI baseURI = VfsUtil.toUri(newFile);
    if (baseURI.isAbsolute()) {
        final URI projectURI = VfsUtil.toUri(projectFolder);
        baseURI = projectURI.relativize(baseURI);
    }
    return MMapURI.makeFromFilePath(projectFolder, baseURI.toString(), oldFile.getParameters());
}
Also used : PsiExtraFile(com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PsiFile(com.intellij.psi.PsiFile) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) URI(java.net.URI)

Example 2 with MMapURI

use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.

the class MapUtils method findTopicsRelatedToFile.

@Nonnull
@MustNotContainNull
public static List<Topic> findTopicsRelatedToFile(@Nullable final File baseFolder, @Nonnull final File file, @Nonnull final MindMap map) {
    final List<Topic> result = new ArrayList<>();
    final Path theFile = file.isAbsolute() ? file.toPath() : new File(baseFolder, file.getAbsolutePath()).toPath();
    final boolean folder = file.isDirectory();
    for (final Topic t : map) {
        final ExtraFile linkToFile = (ExtraFile) t.getExtras().get(Extra.ExtraType.FILE);
        if (linkToFile != null) {
            final MMapURI uri = linkToFile.getAsURI();
            final Path linkFile = uri.asFile(baseFolder).toPath();
            if (folder) {
                if (linkFile.startsWith(theFile)) {
                    result.add(t);
                }
            } else if (linkFile.equals(theFile)) {
                result.add(t);
            }
        }
    }
    return result;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) Topic(com.igormaznitsa.mindmap.model.Topic) File(java.io.File) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) ExtraFile(com.igormaznitsa.mindmap.model.ExtraFile) Nonnull(javax.annotation.Nonnull) MustNotContainNull(com.igormaznitsa.meta.annotation.MustNotContainNull)

Example 3 with MMapURI

use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.

the class UiUtils method editURI.

@Nullable
public static MMapURI editURI(@Nonnull final String title, @Nullable final MMapURI uri) {
    final UriEditPanel textEditor = new UriEditPanel(uri == null ? null : uri.asString(false, false));
    textEditor.doLayout();
    textEditor.setPreferredSize(new Dimension(450, textEditor.getPreferredSize().height));
    if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, title, textEditor)) {
        final String text = textEditor.getText();
        if (text.isEmpty()) {
            return EMPTY_URI;
        }
        try {
            return new MMapURI(text.trim());
        } catch (URISyntaxException ex) {
            DialogProviderManager.getInstance().getDialogProvider().msgError(null, String.format(BUNDLE.getString("NbUtils.errMsgIllegalURI"), text));
            return null;
        }
    } else {
        return null;
    }
}
Also used : UriEditPanel(com.igormaznitsa.sciareto.ui.editors.mmeditors.UriEditPanel) Dimension(java.awt.Dimension) URISyntaxException(java.net.URISyntaxException) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) Nullable(javax.annotation.Nullable)

Example 4 with MMapURI

use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.

the class NbUtils method editURI.

@Nullable
public static MMapURI editURI(@Nullable Component parentComponent, @Nonnull final String title, @Nullable final MMapURI uri) {
    final UriEditPanel textEditor = new UriEditPanel(uri == null ? null : uri.asString(false, false));
    textEditor.doLayout();
    textEditor.setPreferredSize(new Dimension(450, textEditor.getPreferredSize().height));
    final NotifyDescriptor desc = new NotifyDescriptor.Confirmation(textEditor, title, NotifyDescriptor.OK_CANCEL_OPTION, NotifyDescriptor.PLAIN_MESSAGE);
    if (DialogDisplayer.getDefault().notify(desc) == NotifyDescriptor.OK_OPTION) {
        final String text = textEditor.getText();
        if (text.isEmpty()) {
            return EMPTY_URI;
        }
        try {
            return new MMapURI(text.trim());
        } catch (URISyntaxException ex) {
            msgError(parentComponent, String.format(java.util.ResourceBundle.getBundle("com/igormaznitsa/nbmindmap/i18n/Bundle").getString("NbUtils.errMsgIllegalURI"), text));
            return null;
        }
    } else {
        return null;
    }
}
Also used : NotifyDescriptor(org.openide.NotifyDescriptor) UriEditPanel(com.igormaznitsa.nbmindmap.nb.swing.UriEditPanel) Dimension(java.awt.Dimension) URISyntaxException(java.net.URISyntaxException) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) Nullable(javax.annotation.Nullable)

Example 5 with MMapURI

use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.

the class NodeProject method deleteAllLinksToFile.

@Nonnull
@MustNotContainNull
public List<File> deleteAllLinksToFile(@Nonnull @MustNotContainNull final List<File> listOfFilesToProcess, @Nonnull final File fileToRemove) {
    final List<File> affectedFiles = new ArrayList<>();
    final File baseFolder = makeFileForNode();
    final MMapURI fileURI = new MMapURI(baseFolder, fileToRemove, null);
    for (final File file : listOfFilesToProcess) {
        if (file.isFile()) {
            try {
                // NOI18N
                final MindMap map = new MindMap(null, new StringReader(FileUtils.readFileToString(file, "UTF-8")));
                if (map.deleteAllLinksToFile(baseFolder, fileURI)) {
                    SystemUtils.saveUTFText(file, map.packToString());
                    affectedFiles.add(file);
                }
            } catch (IOException ex) {
                // NOI18N
                LOGGER.error("Can't process mind map file", ex);
            }
        }
    }
    return affectedFiles;
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) ArrayList(java.util.ArrayList) StringReader(java.io.StringReader) IOException(java.io.IOException) File(java.io.File) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) Nonnull(javax.annotation.Nonnull) MustNotContainNull(com.igormaznitsa.meta.annotation.MustNotContainNull)

Aggregations

MMapURI (com.igormaznitsa.mindmap.model.MMapURI)12 File (java.io.File)6 URISyntaxException (java.net.URISyntaxException)5 MindMap (com.igormaznitsa.mindmap.model.MindMap)4 ArrayList (java.util.ArrayList)4 Nonnull (javax.annotation.Nonnull)4 MustNotContainNull (com.igormaznitsa.meta.annotation.MustNotContainNull)3 IOException (java.io.IOException)3 StringReader (java.io.StringReader)3 URI (java.net.URI)3 Nullable (javax.annotation.Nullable)3 ExtraFile (com.igormaznitsa.mindmap.model.ExtraFile)2 Topic (com.igormaznitsa.mindmap.model.Topic)2 MindMapLink (com.igormaznitsa.nbmindmap.nb.refactoring.MindMapLink)2 PsiFile (com.intellij.psi.PsiFile)2 Dimension (java.awt.Dimension)2 Problem (org.netbeans.modules.refactoring.api.Problem)2 FileObject (org.openide.filesystems.FileObject)2 PsiExtraFile (com.igormaznitsa.ideamindmap.lang.psi.PsiExtraFile)1 UriEditPanel (com.igormaznitsa.ideamindmap.swing.UriEditPanel)1