use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class RefactoringUtils method replaceMMUriToNewFile.
@Nonnull
public static String replaceMMUriToNewFile(@Nonnull final PsiExtraFile mindMapFile, @Nonnull final MMapURI oldFile, @Nonnull final MMapURI newFile) throws IOException {
final File projectFolder = IdeaUtils.findProjectFolder(mindMapFile);
if (projectFolder == null)
throw new NullPointerException("Project folder is not found for " + mindMapFile);
final MindMap parsedMap = new MindMap(null, new StringReader(mindMapFile.getContainingFile().getText()));
parsedMap.replaceAllLinksToFile(projectFolder, oldFile, newFile);
return parsedMap.write(new StringWriter(16384)).toString();
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class MainFrame method createMindMapFile.
@Nullable
@Override
public File createMindMapFile(@Nullable final File folder) {
final JFileChooser chooser = new JFileChooser(folder);
chooser.setDialogTitle("Create new Mind Map");
chooser.setFileFilter(MMDEditor.MMD_FILE_FILTER);
chooser.setMultiSelectionEnabled(false);
chooser.setApproveButtonText("Create");
File result = null;
if (chooser.showSaveDialog(Main.getApplicationFrame()) == JFileChooser.APPROVE_OPTION) {
File file = chooser.getSelectedFile();
if (!file.getName().endsWith(".mmd")) {
// NOI18N
// NOI18N
file = new File(file.getAbsolutePath() + ".mmd");
}
if (file.exists()) {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "File '" + file + "' already exists!");
} else {
try {
final MindMap mindMap = new MindMap(null, true);
final String text = mindMap.write(new StringWriter()).toString();
SystemUtils.saveUTFText(file, text);
result = file;
} catch (IOException ex) {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't save mind map into file '" + file.getName() + "'");
}
}
}
return result;
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class FindUsagesPanel method startSearchThread.
private void startSearchThread(@Nonnull @MustNotContainNull final List<NodeProject> scope, @Nonnull final NodeFileOrFolder itemToFind) {
int size = 0;
for (final NodeProject p : scope) {
size += p.size();
}
final File nodeFileToSearch = itemToFind.makeFileForNode();
if (nodeFileToSearch == null) {
safeSetProgressValue(Integer.MAX_VALUE);
} else {
final Runnable runnable = new Runnable() {
int value = 0;
private void processFile(final NodeFileOrFolder file) {
value++;
final File f = file.makeFileForNode();
final NodeProject project = file.findProject();
if (project != null) {
final String extension = FilenameUtils.getExtension(f.getName()).toLowerCase(Locale.ENGLISH);
if ("mmd".equals(extension)) {
// NOI18N
Reader reader = null;
try {
// NOI18N
reader = new BufferedReader(new InputStreamReader(new FileInputStream(f), "UTF-8"));
final MindMap map = new MindMap(null, reader);
if (!MapUtils.findTopicsRelatedToFile(project.getFolder(), nodeFileToSearch, map).isEmpty()) {
addFileIntoList(file);
}
} catch (Exception ex) {
// NOI18N
LOGGER.error("Can't parse map", ex);
} finally {
IOUtils.closeQuietly(reader);
}
} else if (findEverywhere) {
try {
// NOI18N
final LineIterator lineIterator = org.apache.commons.io.FileUtils.lineIterator(f, "UTF-8");
try {
while (lineIterator.hasNext()) {
if (Thread.currentThread().isInterrupted()) {
return;
}
final String lineFromFile = lineIterator.nextLine();
if (lineFromFile.contains(fullNormalizedPath)) {
addFileIntoList(file);
break;
}
}
} finally {
LineIterator.closeQuietly(lineIterator);
}
} catch (Exception ex) {
// NOI18N
LOGGER.error("Error during text search in file : " + f);
}
}
}
if (!Thread.currentThread().isInterrupted()) {
safeSetProgressValue(value);
}
}
private void processFolder(final NodeFileOrFolder folder) {
value++;
for (final NodeFileOrFolder f : folder) {
if (f.isLeaf()) {
processFile(f);
} else {
processFolder(f);
}
}
if (!Thread.currentThread().isInterrupted()) {
safeSetProgressValue(value);
}
}
@Override
public void run() {
for (final NodeProject p : scope) {
for (final NodeFileOrFolder f : p) {
if (Thread.currentThread().isInterrupted()) {
return;
}
if (f.isLeaf()) {
processFile(f);
} else {
processFolder(f);
}
}
}
safeSetProgressValue(Integer.MAX_VALUE);
}
};
// NOI18N
final Thread thread = new Thread(runnable, "SciaRetoSearchUsage");
thread.setDaemon(true);
final Thread oldThread = this.searchingThread.getAndSet(thread);
if (oldThread != null) {
oldThread.interrupt();
try {
oldThread.join(1000L);
} catch (InterruptedException ex) {
// NOI18N
LOGGER.error("Exception during waiting of search thread interruption", ex);
}
}
this.progressBarSearch.setMinimum(0);
this.progressBarSearch.setMaximum(size);
this.progressBarSearch.setValue(0);
thread.start();
}
}
use of com.igormaznitsa.mindmap.model.MindMap in project netbeans-mmd-plugin by raydac.
the class NodeProject method findAffectedFiles.
@Nonnull
@MustNotContainNull
public List<File> findAffectedFiles(@Nonnull final File changedFile) {
final File baseFolder = makeFileForNode();
final boolean folder = changedFile.isDirectory();
final List<File> result = new ArrayList<>();
for (final File mindMapFile : FileUtils.listFiles(baseFolder, new String[] { "mmd", "MMD" }, true)) {
// NOI18N
try {
// NOI18N
final MindMap map = new MindMap(null, new StringReader(FileUtils.readFileToString(mindMapFile, "UTF-8")));
if (!MapUtils.findTopicsRelatedToFile(baseFolder, changedFile, map).isEmpty()) {
result.add(mindMapFile);
}
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't process mind map file", ex);
}
}
return result;
}
use of com.igormaznitsa.mindmap.model.MindMap 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