Search in sources :

Example 11 with MMapURI

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

the class IdeaUtils method editURI.

public static MMapURI editURI(final MindMapDocumentEditor editor, final String title, final MMapURI uri) {
    final UriEditPanel uriEditor = new UriEditPanel(uri == null ? null : uri.asString(false, false));
    uriEditor.doLayout();
    uriEditor.setPreferredSize(new Dimension(450, uriEditor.getPreferredSize().height));
    if (plainMessageOkCancel(editor.getProject(), title, uriEditor)) {
        final String text = uriEditor.getText();
        if (text.isEmpty()) {
            return EMPTY_URI;
        }
        try {
            if (!new URI(text).isAbsolute())
                throw new URISyntaxException(text, "URI is not absolute one");
            return new MMapURI(text.trim());
        } catch (URISyntaxException ex) {
            editor.getDialogProvider().msgError(null, String.format(BUNDLE.getString("NbUtils.errMsgIllegalURI"), text));
            return null;
        }
    } else {
        return null;
    }
}
Also used : UriEditPanel(com.igormaznitsa.ideamindmap.swing.UriEditPanel) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) MMapURI(com.igormaznitsa.mindmap.model.MMapURI) MMapURI(com.igormaznitsa.mindmap.model.MMapURI)

Example 12 with MMapURI

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

the class PsiExtraFileReference method retargetToFile.

public void retargetToFile(final PsiFileSystemItem file) {
    final MMapURI oldUri = extraFile.getMMapURI();
    try {
        final MMapURI newUri = RefactoringUtils.makeNewMMapUri(extraFile.getProject(), oldUri, file.getVirtualFile());
        final String packedNewMindMap = RefactoringUtils.replaceMMUriToNewFile(extraFile, oldUri, newUri);
        final PsiFile containingFile = extraFile.getContainingFile();
        final Document document = FileDocumentManager.getInstance().getDocument(containingFile.getVirtualFile());
        CommandProcessor.getInstance().executeCommand(containingFile.getProject(), new Runnable() {

            @Override
            public void run() {
                ApplicationManager.getApplication().runWriteAction(new Runnable() {

                    @Override
                    public void run() {
                        final String packedMindMap = packedNewMindMap;
                        document.setText(packedMindMap);
                        FileDocumentManager.getInstance().saveDocument(document);
                    }
                });
            }
        }, null, null, document);
        extraFile.setMMapURI(newUri);
    } catch (IOException ex) {
        throw new IncorrectOperationException("Can't update links in mind map", (Throwable) ex);
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) IOException(java.io.IOException) Document(com.intellij.openapi.editor.Document) MMapURI(com.igormaznitsa.mindmap.model.MMapURI)

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