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;
}
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()]);
}
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]);
}
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();
}
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);
}
}
Aggregations