use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.
the class ExplorerTree method addTreeAsTopic.
private void addTreeAsTopic(@Nullable final NodeProject project, @Nonnull final NodeFileOrFolder node, @Nonnull final MMDEditor editor) {
final File projectFolder = project == null ? null : project.getFolder();
if (project != null) {
if (node.findProject() != project) {
if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Different projects", "Opened Map file from another project. File paths will not be relative ones.")) {
return;
}
}
}
final List<Topic> targetTopics = new ArrayList<>(Arrays.asList(editor.getMindMapPanel().getSelectedTopics()));
if (targetTopics.size() > 1) {
if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Multiple selection detected", "New children will be generated for all focused topics.")) {
return;
}
} else {
if (targetTopics.isEmpty() && editor.getMindMapPanel().getModel().getRoot() != null) {
if (!DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "No selected parent", "There is not selected topic. The Root will be used as the parent.")) {
return;
}
targetTopics.add(editor.getMindMapPanel().getModel().getRoot());
}
}
editor.getMindMapPanel().executeModelJobs(new MindMapPanel.ModelJob() {
@Nonnull
private Topic recursiveGenerateTopics(@Nullable final File projectFolder, @Nonnull final MindMap model, @Nullable final Topic parent, @Nonnull final NodeFileOrFolder node) {
final ExtraFile fileLink = new ExtraFile(new MMapURI(projectFolder, node.makeFileForNode(), null));
final Topic theTopic;
if (parent == null) {
theTopic = new Topic(model, null, node.toString(), fileLink);
} else {
theTopic = parent.makeChild(node.toString(), null);
theTopic.setExtra(fileLink);
}
if (!node.isLeaf()) {
final Enumeration<NodeFileOrFolder> children = node.children();
while (children.hasMoreElements()) {
recursiveGenerateTopics(projectFolder, model, theTopic, children.nextElement());
}
}
return theTopic;
}
@Override
public boolean doChangeModel(@Nonnull final MindMap model) {
Topic createdTopic = null;
if (targetTopics.isEmpty()) {
createdTopic = recursiveGenerateTopics(projectFolder, model, null, node);
} else {
boolean first = true;
for (final Topic t : targetTopics) {
final Topic generated = recursiveGenerateTopics(projectFolder, model, t, node);
if (first) {
createdTopic = generated;
}
first = false;
}
}
if (editor.getMindMapPanel().getSelectedTopics().length == 0 && createdTopic != null) {
final Topic forfocus = createdTopic;
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
editor.getMindMapPanel().focusTo(forfocus);
}
});
}
return true;
}
});
}
use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.
the class FileLinkGraphPanel method addMindMapAndFillByItsLinks.
@Nullable
private static FileVertex addMindMapAndFillByItsLinks(@Nullable final FileVertex parent, @Nonnull @Nullable final Graph<FileVertex, Number> graph, @Nullable final File projectFolder, @Nonnull final File mindMapFile, @Nonnull final AtomicInteger edgeCounter, @Nonnull Set<File> mapFilesInProcessing) {
MindMap map;
FileVertex thisVertex;
try {
thisVertex = new FileVertex(mindMapFile, FileVertexType.MINDMAP);
// NOI18N
map = new MindMap(null, new StringReader(FileUtils.readFileToString(mindMapFile, "UTF-8")));
if (parent != null) {
for (final MMapURI fileUri : MapUtils.extractAllFileLinks(map)) {
if (parent.getFile().equals(fileUri.asFile(projectFolder))) {
graph.addEdge(edgeCounter.getAndIncrement(), thisVertex, parent, EdgeType.DIRECTED);
break;
}
}
if (mapFilesInProcessing.contains(mindMapFile)) {
return null;
}
}
} catch (final Exception ex) {
// NOI18N
LOGGER.error("Can't load mind map : " + mindMapFile, ex);
thisVertex = new FileVertex(mindMapFile, FileVertexType.UNKNOWN);
map = null;
}
mapFilesInProcessing.add(mindMapFile);
graph.addVertex(thisVertex);
if (map != null) {
for (final MMapURI fileUri : MapUtils.extractAllFileLinks(map)) {
final FileVertex that;
final File convertedFile = convertUriInFile(mindMapFile, projectFolder, fileUri);
if (convertedFile == null) {
that = new FileVertex(fileUri.asFile(projectFolder), FileVertexType.NOTFOUND);
} else if (convertedFile.isDirectory()) {
that = new FileVertex(convertedFile, FileVertexType.FOLDER);
} else if (convertedFile.isFile()) {
if (convertedFile.getName().endsWith(".mmd")) {
// NOI18N
if (convertedFile.equals(mindMapFile)) {
that = thisVertex;
} else {
that = addMindMapAndFillByItsLinks(thisVertex, graph, projectFolder, convertedFile, edgeCounter, mapFilesInProcessing);
}
} else {
that = new FileVertex(convertedFile, FileVertexType.DOCUMENT);
}
} else {
that = new FileVertex(convertedFile, convertedFile.exists() ? FileVertexType.UNKNOWN : FileVertexType.NOTFOUND);
}
if (that != null) {
graph.addEdge(edgeCounter.getAndIncrement(), thisVertex, that, EdgeType.DIRECTED);
}
}
}
return thisVertex;
}
use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.
the class NodeProject method replaceAllLinksToFile.
@Nonnull
@MustNotContainNull
public List<File> replaceAllLinksToFile(@Nonnull @MustNotContainNull final List<File> listOfFilesToProcess, @Nonnull final File oldFile, @Nonnull final File newFile) {
final List<File> affectedFiles = new ArrayList<>();
final File baseFolder = makeFileForNode();
final MMapURI oldFileURI = new MMapURI(baseFolder, oldFile, null);
final MMapURI newFileURI = new MMapURI(baseFolder, newFile, 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.replaceAllLinksToFile(baseFolder, oldFileURI, newFileURI)) {
SystemUtils.saveUTFText(file, map.packToString());
affectedFiles.add(file);
}
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't process mind map file", ex);
}
}
}
return affectedFiles;
}
use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.
the class MoveFileActionPlugin method processFile.
@Override
protected Problem processFile(final Project project, final int level, final File projectFolder, final FileObject fileObject) {
final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);
final Lookup targetLookup = this.refactoring.getTarget();
if (targetLookup == null) {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindLookup"));
}
final URL targetURL = targetLookup.lookup(URL.class);
if (targetURL != null) {
try {
URI baseURI = targetURL.toURI();
if (baseURI.isAbsolute()) {
final URI projectURI = Utilities.toURI(projectFolder);
baseURI = projectURI.relativize(baseURI);
}
final MMapURI newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null).replaceBaseInPath(true, baseURI, level);
for (final FileObject mmap : allMapsInProject(project)) {
try {
if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
final MoveElement element = new MoveElement(new MindMapLink(mmap), projectFolder, MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
element.setTarget(newFileAsURI);
addElement(element);
}
} catch (Exception ex) {
ErrorManager.getDefault().notify(ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
}
}
} catch (URISyntaxException ex) {
// NOI18N
LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex);
// NOI18N
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantMakeURIForFile"));
}
return null;
} else {
return new Problem(true, BUNDLE.getString("MoveFileActionPlugin.cantFindURL"));
}
}
use of com.igormaznitsa.mindmap.model.MMapURI in project netbeans-mmd-plugin by raydac.
the class RenameFileActionPlugin method processFile.
@Override
protected Problem processFile(final Project project, final int level, final File projectFolder, final FileObject fileObject) {
final MMapURI fileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null);
String newFileName = this.refactoring.getNewName();
if (newFileName == null) {
return new Problem(false, "Detected null as new file name for rename refactoring action");
}
if (level == 0 && !fileObject.isFolder()) {
final String ext = FilenameUtils.getExtension(fileObject.getNameExt());
if (!ext.isEmpty()) {
if (!newFileName.toLowerCase(Locale.ENGLISH).endsWith('.' + ext)) {
newFileName += '.' + ext;
}
}
} else {
newFileName = newFileName.replace('.', '/');
}
final MMapURI newFileAsURI;
try {
if (level == 0) {
newFileAsURI = MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null).replaceName(newFileName);
} else {
newFileAsURI = MMapURI.makeFromFilePath(projectFolder, replaceNameInPath(level, fileObject.getPath(), newFileName), null);
}
} catch (URISyntaxException ex) {
// NOI18N
LOGGER.error("Can't make new file uri for " + fileObject.getPath(), ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantMakeURI"));
}
for (final FileObject mmap : allMapsInProject(project)) {
if (isCanceled()) {
break;
}
try {
if (doesMindMapContainFileLink(project, mmap, fileAsURI)) {
final RenameElement element = new RenameElement(new MindMapLink(mmap), projectFolder, MMapURI.makeFromFilePath(projectFolder, fileObject.getPath(), null));
element.setNewFile(newFileAsURI);
addElement(element);
}
} catch (Exception ex) {
ErrorManager.getDefault().notify(ex);
return new Problem(true, BUNDLE.getString("Refactoring.CantProcessMindMap"));
}
}
return null;
}
Aggregations