Search in sources :

Example 96 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class RemovePotentialMatchesAction method usePluralLabel.

private boolean usePluralLabel() {
    ISelection s = fSite.getSelectionProvider().getSelection();
    if (!(s instanceof IStructuredSelection) || s.isEmpty())
        return false;
    IStructuredSelection selection = (IStructuredSelection) s;
    int size = selection.size();
    if (size <= 0)
        return false;
    int markerCount = 0;
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        SearchResultViewEntry entry = (SearchResultViewEntry) iter.next();
        Iterator<IMarker> entryIter = entry.getMarkers().iterator();
        while (entryIter.hasNext()) {
            IMarker marker = entryIter.next();
            if (marker.getAttribute(SearchUI.POTENTIAL_MATCH, false)) {
                markerCount++;
            }
            if (markerCount > 1)
                return true;
        }
    }
    return false;
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMarker(org.eclipse.core.resources.IMarker)

Example 97 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class RemovePotentialMatchesAction method getMarkers.

private IMarker[] getMarkers() {
    ISelection s = fSite.getSelectionProvider().getSelection();
    if (!(s instanceof IStructuredSelection))
        return null;
    IStructuredSelection selection = (IStructuredSelection) s;
    int size = selection.size();
    if (size <= 0)
        return null;
    ArrayList<IMarker> markers = new ArrayList<>(size * 3);
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        SearchResultViewEntry entry = (SearchResultViewEntry) iter.next();
        Iterator<IMarker> entryIter = entry.getMarkers().iterator();
        while (entryIter.hasNext()) {
            IMarker marker = entryIter.next();
            if (marker.getAttribute(SearchUI.POTENTIAL_MATCH, false))
                markers.add(marker);
        }
    }
    return markers.toArray(new IMarker[markers.size()]);
}
Also used : ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMarker(org.eclipse.core.resources.IMarker)

Example 98 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class RemoveResultAction method getMarkers.

private IMarker[] getMarkers(ISelection s) {
    if (!(s instanceof IStructuredSelection) || s.isEmpty())
        return null;
    IStructuredSelection selection = (IStructuredSelection) s;
    int size = selection.size();
    if (size <= 0)
        return null;
    ArrayList<IMarker> markers = new ArrayList<>(size * 3);
    int markerCount = 0;
    Iterator<?> iter = selection.iterator();
    while (iter.hasNext()) {
        SearchResultViewEntry entry = (SearchResultViewEntry) iter.next();
        markerCount += entry.getMatchCount();
        markers.addAll(entry.getMarkers());
    }
    return markers.toArray(new IMarker[markerCount]);
}
Also used : ArrayList(java.util.ArrayList) ISearchResultViewEntry(org.eclipse.search.ui.ISearchResultViewEntry) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IMarker(org.eclipse.core.resources.IMarker)

Example 99 with IMarker

use of org.eclipse.core.resources.IMarker in project eclipse.platform.text by eclipse.

the class SearchManager method internalSetCurrentSearch.

void internalSetCurrentSearch(final Search search, IProgressMonitor monitor) {
    if (fCurrentSearch != null)
        fCurrentSearch.backupMarkers();
    final Search previousSearch = fCurrentSearch;
    fCurrentSearch = search;
    monitor.beginTask(SearchMessages.SearchManager_updating, getCurrentResults().size() + 20);
    // remove current search markers
    try {
        SearchPlugin.getWorkspace().getRoot().deleteMarkers(SearchUI.SEARCH_MARKER, true, IResource.DEPTH_INFINITE);
    } catch (CoreException ex) {
        ExceptionHandler.handle(ex, SearchMessages.Search_Error_deleteMarkers_title, SearchMessages.Search_Error_deleteMarkers_message);
    }
    monitor.worked(10);
    // add search markers
    Iterator<SearchResultViewEntry> iter = getCurrentResults().iterator();
    ArrayList<SearchResultViewEntry> emptyEntries = new ArrayList<>(10);
    boolean filesChanged = false;
    boolean filesDeleted = false;
    IGroupByKeyComputer groupByKeyComputer = getCurrentSearch().getGroupByKeyComputer();
    while (iter.hasNext()) {
        monitor.worked(1);
        SearchResultViewEntry entry = iter.next();
        Iterator<Map<String, Object>> attrPerMarkerIter = entry.getAttributesPerMarker().iterator();
        entry.clearMarkerList();
        if (entry.getResource() == null || !entry.getResource().exists()) {
            emptyEntries.add(entry);
            filesDeleted = true;
            continue;
        }
        while (attrPerMarkerIter.hasNext()) {
            IMarker newMarker = null;
            try {
                newMarker = entry.getResource().createMarker(entry.getMarkerType());
            } catch (CoreException ex) {
                ExceptionHandler.handle(ex, SearchMessages.Search_Error_createMarker_title, SearchMessages.Search_Error_createMarker_message);
                continue;
            }
            try {
                newMarker.setAttributes(attrPerMarkerIter.next());
                if (groupByKeyComputer != null && groupByKeyComputer.computeGroupByKey(newMarker) == null) {
                    filesDeleted = true;
                    newMarker.delete();
                    continue;
                }
            } catch (CoreException ex) {
                ExceptionHandler.handle(ex, SearchMessages.Search_Error_markerAttributeAccess_title, SearchMessages.Search_Error_markerAttributeAccess_message);
            }
            entry.add(newMarker);
        }
        if (entry.getMatchCount() == 0)
            emptyEntries.add(entry);
        else if (!filesChanged && entry.getResource().getModificationStamp() != entry.getModificationStamp())
            filesChanged = true;
    }
    getCurrentResults().removeAll(emptyEntries);
    monitor.worked(10);
    String warningMessage = null;
    Display display = getDisplay();
    if (filesChanged)
        warningMessage = SearchMessages.SearchManager_resourceChanged;
    if (filesDeleted) {
        if (warningMessage == null)
            // $NON-NLS-1$
            warningMessage = "";
        else
            // $NON-NLS-1$
            warningMessage += "\n";
        warningMessage += SearchMessages.SearchManager_resourceDeleted;
    }
    if (warningMessage != null) {
        if (display != null && !display.isDisposed()) {
            final String warningTitle = SearchMessages.SearchManager_resourceChangedWarning;
            final String warningMsg = warningMessage;
            display.syncExec(() -> MessageDialog.openWarning(getShell(), warningTitle, warningMsg));
        }
    }
    // update viewers
    Iterator<SearchResultViewer> iter2 = fListeners.iterator();
    if (display != null && !display.isDisposed()) {
        final Viewer visibleViewer = ((SearchResultView) SearchUI.getSearchResultView()).getViewer();
        while (iter2.hasNext()) {
            final SearchResultViewer viewer = iter2.next();
            display.syncExec(() -> {
                if (previousSearch != null && viewer == visibleViewer)
                    previousSearch.setSelection(viewer.getSelection());
                viewer.setInput(null);
                viewer.setPageId(search.getPageId());
                viewer.setGotoMarkerAction(search.getGotoMarkerAction());
                viewer.setContextMenuTarget(search.getContextMenuContributor());
                viewer.setActionGroupFactory(null);
                viewer.setInput(getCurrentResults());
                viewer.setActionGroupFactory(search.getActionGroupFactory());
                viewer.setSelection(fCurrentSearch.getSelection(), true);
            });
        }
    }
    monitor.done();
}
Also used : ArrayList(java.util.ArrayList) Viewer(org.eclipse.jface.viewers.Viewer) CoreException(org.eclipse.core.runtime.CoreException) IGroupByKeyComputer(org.eclipse.search.ui.IGroupByKeyComputer) IMarker(org.eclipse.core.resources.IMarker) Map(java.util.Map) Display(org.eclipse.swt.widgets.Display)

Example 100 with IMarker

use of org.eclipse.core.resources.IMarker in project linuxtools by eclipse.

the class SpecfileElementHyperlink method open.

@Override
public void open() {
    IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorDescriptor desc = PlatformUI.getWorkbench().getEditorRegistry().getDefaultEditor(file.getName());
    HashMap<String, Object> map = new HashMap<>();
    // TODO don't increment the line number once the SpecfileSource reports
    // correct line
    map.put(IMarker.LINE_NUMBER, Integer.valueOf(getSource().getLineNumber() + 1));
    map.put(IDE.EDITOR_ID_ATTR, desc.getId());
    try {
        IMarker marker = file.createMarker(IMarker.TEXT);
        marker.setAttributes(map);
        IDE.openEditor(page, marker);
        marker.delete();
    } catch (CoreException e) {
        SpecfileLog.logError(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) HashMap(java.util.HashMap) IEditorDescriptor(org.eclipse.ui.IEditorDescriptor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IMarker(org.eclipse.core.resources.IMarker)

Aggregations

IMarker (org.eclipse.core.resources.IMarker)115 CoreException (org.eclipse.core.runtime.CoreException)31 Test (org.junit.Test)31 IFile (org.eclipse.core.resources.IFile)23 IResource (org.eclipse.core.resources.IResource)16 ArrayList (java.util.ArrayList)15 IProject (org.eclipse.core.resources.IProject)8 IPath (org.eclipse.core.runtime.IPath)8 Position (org.eclipse.jface.text.Position)8 Annotation (org.eclipse.jface.text.source.Annotation)7 Matchers.anyString (org.mockito.Matchers.anyString)7 IOException (java.io.IOException)6 HashMap (java.util.HashMap)6 Rule (net.sourceforge.pmd.Rule)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 BadLocationException (org.eclipse.jface.text.BadLocationException)6 RuleViolation (net.sourceforge.pmd.RuleViolation)5 JavaLanguageModule (net.sourceforge.pmd.lang.java.JavaLanguageModule)5 IDocument (org.eclipse.jface.text.IDocument)5 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)5