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());
}
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;
}
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;
}
}
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;
}
}
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;
}
Aggregations