use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class SearchResultViewer method handleLabelProviderChanged.
@Override
protected void handleLabelProviderChanged(LabelProviderChangedEvent event) {
Object[] changed = event.getElements();
if (changed != null && !fResourceToItemsMapper.isEmpty()) {
ArrayList<Object> others = new ArrayList<>(changed.length);
for (Object curr : changed) {
if (curr instanceof IResource)
fResourceToItemsMapper.resourceChanged((IResource) curr);
else if (curr instanceof IAdaptable) {
IResource resource = ((IAdaptable) curr).getAdapter(IResource.class);
if (resource != null)
fResourceToItemsMapper.resourceChanged(resource);
} else
others.add(curr);
}
if (others.isEmpty()) {
return;
}
event = new LabelProviderChangedEvent((IBaseLabelProvider) event.getSource(), others.toArray());
}
super.handleLabelProviderChanged(event);
}
use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class TextFileDocumentProvider method createFileInfo.
/**
* Creates and returns the file info object
* for the given element.
* <p>
* Subclasses which extend {@link org.eclipse.ui.editors.text.TextFileDocumentProvider.FileInfo}
* will probably have to extend this method as well.
* </p>
*
* @param element the element
* @return a file info object of type <code>FileInfo</code>
* or <code>null</code> if none can be created
* @throws CoreException if the file info object could not successfully be created
*/
protected FileInfo createFileInfo(Object element) throws CoreException {
if (!(element instanceof IAdaptable))
return null;
IAdaptable adaptable = (IAdaptable) element;
IFile file = null;
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
ITextFileBuffer fileBuffer = null;
LocationKind locationKind = null;
file = adaptable.getAdapter(IFile.class);
if (file != null) {
IPath location = file.getFullPath();
locationKind = LocationKind.IFILE;
manager.connect(location, locationKind, getProgressMonitor());
fileBuffer = manager.getTextFileBuffer(location, locationKind);
} else {
ILocationProvider provider = adaptable.getAdapter(ILocationProvider.class);
if (provider instanceof ILocationProviderExtension) {
URI uri = ((ILocationProviderExtension) provider).getURI(element);
if (ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(uri).length == 0) {
IFileStore fileStore = EFS.getStore(uri);
manager.connectFileStore(fileStore, getProgressMonitor());
fileBuffer = manager.getFileStoreTextFileBuffer(fileStore);
}
}
if (fileBuffer == null && provider != null) {
IPath location = provider.getPath(element);
if (location == null)
return null;
locationKind = LocationKind.NORMALIZE;
manager.connect(location, locationKind, getProgressMonitor());
fileBuffer = manager.getTextFileBuffer(location, locationKind);
file = FileBuffers.getWorkspaceFileAtLocation(location);
}
}
if (fileBuffer != null) {
fileBuffer.requestSynchronizationContext();
FileInfo info = createEmptyFileInfo();
info.fTextFileBuffer = fileBuffer;
info.fTextFileBufferLocationKind = locationKind;
info.fCachedReadOnlyState = isSystemFileReadOnly(info);
if (file != null)
info.fModel = createAnnotationModel(file);
if (info.fModel == null)
info.fModel = info.fTextFileBuffer.getAnnotationModel();
setUpSynchronization(info);
return info;
}
return null;
}
use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class TextSourceViewerConfiguration method getRegisteredHyperlinkDetectors.
/**
* Returns the registered hyperlink detectors which are used to detect
* hyperlinks in the given source viewer.
*
* @param sourceViewer the source viewer to be configured by this configuration
* @return an array with hyperlink detectors or <code>null</code> if no hyperlink detectors are registered
* @since 3.3
*/
protected final IHyperlinkDetector[] getRegisteredHyperlinkDetectors(ISourceViewer sourceViewer) {
HyperlinkDetectorRegistry registry = EditorsUI.getHyperlinkDetectorRegistry();
Map<String, IAdaptable> targets = getHyperlinkDetectorTargets(sourceViewer);
Assert.isNotNull(targets);
IHyperlinkDetector[] result = null;
Iterator<Entry<String, IAdaptable>> iter = targets.entrySet().iterator();
while (iter.hasNext()) {
Entry<String, IAdaptable> target = iter.next();
String targetId = target.getKey();
IAdaptable context = target.getValue();
result = merge(result, registry.createHyperlinkDetectors(targetId, context));
}
return result;
}
use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class FileBufferOperationAction method selectionChanged.
@Override
public void selectionChanged(IAction action, ISelection selection) {
fResources = new HashSet<>();
fLocation = null;
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
Iterator<?> e = structuredSelection.iterator();
while (e.hasNext()) {
Object element = e.next();
if (element instanceof IResource)
fResources.add(element);
else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
Object adapter = adaptable.getAdapter(IResource.class);
if (adapter instanceof IResource)
fResources.add(adapter);
}
}
}
if (selection instanceof ITextSelection) {
IWorkbenchWindow window = getWorkbenchWindow();
if (window != null) {
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
if (workbenchPart instanceof IEditorPart) {
IEditorPart editorPart = (IEditorPart) workbenchPart;
IEditorInput input = editorPart.getEditorInput();
Object adapter = input.getAdapter(IResource.class);
if (adapter instanceof IResource)
fResources.add(adapter);
else {
adapter = input.getAdapter(ILocationProvider.class);
if (adapter instanceof ILocationProvider) {
ILocationProvider provider = (ILocationProvider) adapter;
fLocation = provider.getPath(input);
}
}
}
}
}
action.setText(getText());
action.setEnabled(!fResources.isEmpty() || fLocation != null);
}
use of org.eclipse.core.runtime.IAdaptable in project eclipse.platform.text by eclipse.
the class TextViewerUndoManagerTest method internalTestTransferNonTextOp.
// --- DocumentUndoManager only ---
public void internalTestTransferNonTextOp(final boolean isUndoable) throws Exception {
Object context = new Object();
DocumentUndoManager tempUndoManager = new DocumentUndoManager(new Document());
tempUndoManager.connect(context);
IUndoableOperation operation = new AbstractOperation("") {
@Override
public boolean canUndo() {
return isUndoable;
}
@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
@Override
public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
@Override
public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
return Status.OK_STATUS;
}
};
operation.addContext(tempUndoManager.getUndoContext());
OperationHistoryFactory.getOperationHistory().add(operation);
assertEquals(isUndoable, tempUndoManager.undoable());
final DocumentUndoManager undoManager = new DocumentUndoManager(new Document());
Object newContext = new Object();
undoManager.connect(newContext);
undoManager.addDocumentUndoListener(new IDocumentUndoListener() {
@Override
public void documentUndoNotification(DocumentUndoEvent event) {
fail();
}
});
undoManager.transferUndoHistory(tempUndoManager);
tempUndoManager.disconnect(context);
assertEquals(isUndoable, undoManager.undoable());
undoManager.undo();
assertEquals(false, undoManager.undoable());
undoManager.disconnect(newContext);
}
Aggregations