use of com.igormaznitsa.sciareto.ui.tree.NodeProject in project netbeans-mmd-plugin by raydac.
the class MainFrame method showGraphMindMapFileLinksDialog.
// GEN-LAST:event_menuEditCutActionPerformed
@Override
public boolean showGraphMindMapFileLinksDialog(@Nullable final File projectFolder, @Nullable final File initialMindMapFile, final boolean openIfSelected) {
Utils.assertSwingDispatchThread();
boolean result = false;
if (projectFolder != null || initialMindMapFile != null) {
File projectFolderToUse = projectFolder;
if (projectFolderToUse == null) {
final NodeProject foundProject = findProjectForFile(initialMindMapFile);
if (foundProject != null) {
projectFolderToUse = foundProject.getFolder();
}
}
final FileLinkGraphPanel graph = new FileLinkGraphPanel(projectFolderToUse, initialMindMapFile);
JOptionPane.showMessageDialog(this, graph, "Graph of Mind Map file links", JOptionPane.PLAIN_MESSAGE);
final FileLinkGraphPanel.FileVertex selected = graph.getSelectedFile();
final File fileToOpen = selected == null ? null : selected.getFile();
if (openIfSelected && fileToOpen != null) {
result = true;
boolean cantFind = true;
if (fileToOpen.exists()) {
if (fileToOpen.isFile()) {
if (openFileAsTab(fileToOpen)) {
cantFind = false;
}
} else if (fileToOpen.isDirectory()) {
focusInTree(fileToOpen);
cantFind = false;
}
}
if (cantFind) {
DialogProviderManager.getInstance().getDialogProvider().msgWarn(null, "Can't open file \'" + fileToOpen.getAbsolutePath() + "\'!");
result = false;
}
}
}
return result;
}
use of com.igormaznitsa.sciareto.ui.tree.NodeProject 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.sciareto.ui.tree.NodeProject in project netbeans-mmd-plugin by raydac.
the class MainFrame method menuNavigateLinksGraphActionPerformed.
private void menuNavigateLinksGraphActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_menuNavigateLinksGraphActionPerformed
final File file = this.getFocusedTab().getAssociatedFile();
final NodeProject project = findProjectForFile(file);
showGraphMindMapFileLinksDialog(project == null ? null : project.getFolder(), file, true);
}
use of com.igormaznitsa.sciareto.ui.tree.NodeProject in project netbeans-mmd-plugin by raydac.
the class MainFrame method openProject.
// GEN-LAST:event_menuOpenProjectActionPerformed
@Override
public boolean openProject(@Nonnull final File folder, final boolean enforceSeparatedProject) {
boolean result = false;
if (folder.isDirectory()) {
final NodeProject alreadyOpened = findProjectForFile(folder);
if (alreadyOpened == null || enforceSeparatedProject) {
final boolean firstProject = this.explorerTree.getCurrentGroup().getChildCount() == 0;
final NodeProject node = this.explorerTree.getCurrentGroup().addProjectFolder(folder);
if (firstProject) {
this.explorerTree.unfoldProject(node);
}
try {
FileHistoryManager.getInstance().registerOpenedProject(folder);
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't register last opened project", ex);
}
} else {
this.focusInTree(folder);
}
result = true;
} else {
// NOI18N
LOGGER.error("Can't find folder : " + folder);
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't find project folder!");
}
return result;
}
use of com.igormaznitsa.sciareto.ui.tree.NodeProject in project netbeans-mmd-plugin by raydac.
the class MainFrame method deleteTreeNode.
@Override
public boolean deleteTreeNode(@Nonnull final NodeFileOrFolder node) {
final File file = node.makeFileForNode();
if (file != null && file.exists()) {
final List<TabTitle> tabsToClose = this.tabPane.findListOfRelatedTabs(file);
boolean hasUnsaved = false;
for (final TabTitle t : tabsToClose) {
hasUnsaved |= t.isChanged();
}
if (hasUnsaved && !DialogProviderManager.getInstance().getDialogProvider().msgConfirmOkCancel(null, "Confirmation", "Are you sure to delete changed unsaved file?")) {
return false;
}
closeTab(tabsToClose.toArray(new TabTitle[tabsToClose.size()]));
final NodeProject project = findProjectForFile(file);
List<File> affectedFiles = project == null ? Collections.EMPTY_LIST : project.findAffectedFiles(file);
final Iterator<File> iterator = affectedFiles.iterator();
final Path removingFile = file.toPath();
while (iterator.hasNext()) {
if (iterator.next().toPath().startsWith(removingFile)) {
iterator.remove();
}
}
if (!affectedFiles.isEmpty()) {
affectedFiles = UiUtils.showSelectAffectedFiles(affectedFiles);
if (affectedFiles == null) {
return false;
}
}
boolean ok = false;
if (file.isDirectory()) {
if (SystemUtils.deleteFile(file, DELETE_MOVING_FILE_TO_TRASH)) {
ok = true;
} else {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't delete directory, see the log!");
}
} else {
ok = SystemUtils.deleteFile(file, DELETE_MOVING_FILE_TO_TRASH);
if (!ok) {
DialogProviderManager.getInstance().getDialogProvider().msgError(null, "Can't delete file!");
}
}
if (ok) {
explorerTree.deleteNode(node);
}
if (!affectedFiles.isEmpty() && project != null) {
final List<File> changedFiles = project.deleteAllLinksToFile(affectedFiles, file);
if (!changedFiles.isEmpty()) {
for (final TabTitle t : tabPane) {
final File associated = t.getAssociatedFile();
if (associated != null && changedFiles.contains(associated)) {
t.reload(true);
}
}
}
}
return ok;
}
return false;
}
Aggregations