use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class FindFilesForTextPanel method listOfFoundElementsMouseMoved.
// GEN-LAST:event_listOfFoundElementsMouseClicked
private void listOfFoundElementsMouseMoved(java.awt.event.MouseEvent evt) {
// GEN-FIRST:event_listOfFoundElementsMouseMoved
final ListModel model = this.listOfFoundElements.getModel();
final int index = this.listOfFoundElements.locationToIndex(evt.getPoint());
if (index < 0) {
this.listOfFoundElements.setToolTipText(null);
} else {
final File file = ((NodeFileOrFolder) model.getElementAt(index)).makeFileForNode();
this.listOfFoundElements.setToolTipText(file == null ? null : file.getAbsolutePath());
}
}
use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder 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.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class GoToFilePanel method listFoundFilesMouseMoved.
// </editor-fold>//GEN-END:initComponents
private void listFoundFilesMouseMoved(java.awt.event.MouseEvent evt) {
// GEN-FIRST:event_listFoundFilesMouseMoved
final ListModel model = this.listFoundFiles.getModel();
final int index = this.listFoundFiles.locationToIndex(evt.getPoint());
if (index < 0) {
this.listFoundFiles.setToolTipText(null);
} else {
final File file = ((NodeFileOrFolder) model.getElementAt(index)).makeFileForNode();
this.listFoundFiles.setToolTipText(file == null ? null : file.getAbsolutePath());
}
}
use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class MainFrame method menuGoToFileActionPerformed.
// GEN-LAST:event_menuMakeDonationActionPerformed
private void menuGoToFileActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_menuGoToFileActionPerformed
final GoToFilePanel panel = new GoToFilePanel(this.explorerTree, JOptionPane.OK_OPTION);
if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, "Go To File", panel)) {
final NodeFileOrFolder selected = panel.getSelected();
if (selected != null) {
final File file = selected.makeFileForNode();
if (file != null) {
this.focusInTree(file);
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
explorerTree.requestFocus();
}
});
}
}
}
}
use of com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder in project netbeans-mmd-plugin by raydac.
the class MainFrame method saveState.
private void saveState() {
try {
final List<File> files = new ArrayList<>();
for (final NodeFileOrFolder p : this.explorerTree.getCurrentGroup()) {
final File f = ((NodeProject) p).getFolder();
if (f.isDirectory()) {
files.add(f);
}
}
FileHistoryManager.getInstance().saveActiveProjects(files.toArray(new File[files.size()]));
files.clear();
for (final TabTitle p : this.tabPane) {
final File f = p.getAssociatedFile();
if (f != null && f.isFile()) {
files.add(f);
}
}
FileHistoryManager.getInstance().saveActiveFiles(files.toArray(new File[files.size()]));
} catch (IOException ex) {
// NOI18N
LOGGER.error("Can't save state", ex);
}
}
Aggregations