Search in sources :

Example 1 with NodeFileOrFolder

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());
    }
}
Also used : NodeFileOrFolder(com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder) ListModel(javax.swing.ListModel) File(java.io.File)

Example 2 with NodeFileOrFolder

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();
    }
}
Also used : MindMap(com.igormaznitsa.mindmap.model.MindMap) InputStreamReader(java.io.InputStreamReader) NodeFileOrFolder(com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) LineIterator(org.apache.commons.io.LineIterator) FileInputStream(java.io.FileInputStream) NodeProject(com.igormaznitsa.sciareto.ui.tree.NodeProject) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 3 with NodeFileOrFolder

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());
    }
}
Also used : NodeFileOrFolder(com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder) ListModel(javax.swing.ListModel) File(java.io.File)

Example 4 with NodeFileOrFolder

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();
                    }
                });
            }
        }
    }
}
Also used : GoToFilePanel(com.igormaznitsa.sciareto.ui.misc.GoToFilePanel) NodeFileOrFolder(com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder) File(java.io.File)

Example 5 with NodeFileOrFolder

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);
    }
}
Also used : NodeFileOrFolder(com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder) NodeProject(com.igormaznitsa.sciareto.ui.tree.NodeProject) TabTitle(com.igormaznitsa.sciareto.ui.tabs.TabTitle) IOException(java.io.IOException) File(java.io.File)

Aggregations

NodeFileOrFolder (com.igormaznitsa.sciareto.ui.tree.NodeFileOrFolder)8 File (java.io.File)6 NodeProject (com.igormaznitsa.sciareto.ui.tree.NodeProject)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 ListModel (javax.swing.ListModel)2 MindMap (com.igormaznitsa.mindmap.model.MindMap)1 FileExaminator (com.igormaznitsa.sciareto.ui.misc.FileExaminator)1 GoToFilePanel (com.igormaznitsa.sciareto.ui.misc.GoToFilePanel)1 TabTitle (com.igormaznitsa.sciareto.ui.tabs.TabTitle)1 BufferedReader (java.io.BufferedReader)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Reader (java.io.Reader)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Nonnull (javax.annotation.Nonnull)1 LineIterator (org.apache.commons.io.LineIterator)1