use of org.eclipse.ui.editors.text.ILocationProvider in project webtools.sourceediting by eclipse.
the class StorageModelProvider method calculateBaseLocation.
String calculateBaseLocation(IStorageEditorInput input) {
String location = null;
if (input instanceof IPathEditorInput) {
IPath path = ((IPathEditorInput) input).getPath();
if (path != null) {
location = path.toString();
}
}
if (location == null && input instanceof ILocationProvider) {
IPath path = ((ILocationProvider) input).getPath(input);
if (path != null) {
location = path.toString();
}
}
if (location == null) {
try {
IStorage storage = input.getStorage();
if (storage != null) {
IPath storagePath = storage.getFullPath();
String name = storage.getName();
if (storagePath != null) {
/*
* If the path's last segment and the name are
* different, the IStorage contract is not being
* honored
* (https://bugs.eclipse.org/bugs/show_bug.cgi?
* id=73098). Favor the name
*/
if (!storagePath.lastSegment().equals(name)) {
IPath workingPath = storagePath.addTrailingSeparator();
location = workingPath.append(name).toString();
} else {
location = storagePath.makeAbsolute().toString();
}
}
if (location == null)
location = name;
}
} catch (CoreException e) {
Logger.logException(e);
} finally {
if (location == null)
location = input.getName();
}
}
return location;
}
use of org.eclipse.ui.editors.text.ILocationProvider in project webtools.sourceediting by eclipse.
the class DebugTextEditor method createActions.
/*
* (non-Javadoc)
*
* @see org.eclipse.ui.editors.text.TextEditor#createActions()
*/
protected void createActions() {
super.createActions();
// StructuredTextEditor Action - toggle breakpoints
IAction action = new ToggleBreakpointAction(this, getVerticalRuler()) {
protected String getContentType(IDocument document) {
ILocationProvider provider = getEditorInput().getAdapter(ILocationProvider.class);
if (provider != null) {
IPath location = provider.getPath(getEditorInput());
return detectContentType(location).getId();
} else if (getEditorInput() instanceof IPathEditorInput) {
IPath location = ((IPathEditorInput) getEditorInput()).getPath();
return detectContentType(location).getId();
}
return IContentTypeManager.CT_TEXT;
}
};
setAction(ActionDefinitionIds.TOGGLE_BREAKPOINTS, action);
// StructuredTextEditor Action - manage breakpoints
action = new ManageBreakpointAction(this, getVerticalRuler());
setAction(ActionDefinitionIds.MANAGE_BREAKPOINTS, action);
// StructuredTextEditor Action - edit breakpoints
action = new EditBreakpointAction(this, getVerticalRuler());
setAction(ActionDefinitionIds.EDIT_BREAKPOINTS, action);
}
use of org.eclipse.ui.editors.text.ILocationProvider in project pmd-eclipse-plugin by pmd.
the class ReviewCodeHandler method computeSelectedResources.
/**
* Computes the selected resources.
*/
protected final void computeSelectedResources() {
if (fResources != null || fLocation != null) {
return;
}
ISelection selection = getSelection();
if (selection instanceof IStructuredSelection) {
IStructuredSelection structuredSelection = (IStructuredSelection) selection;
List resources = new ArrayList(structuredSelection.size());
Iterator<?> e = structuredSelection.iterator();
while (e.hasNext()) {
Object element = e.next();
if (element instanceof IResource) {
resources.add(element);
} else if (element instanceof IAdaptable) {
IAdaptable adaptable = (IAdaptable) element;
Object adapter = adaptable.getAdapter(IResource.class);
if (adapter instanceof IResource) {
resources.add(adapter);
}
}
}
if (!resources.isEmpty()) {
fResources = (IResource[]) resources.toArray(new IResource[resources.size()]);
}
} else 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 = new IResource[] { (IResource) adapter };
} else {
adapter = input.getAdapter(ILocationProvider.class);
if (adapter instanceof ILocationProvider) {
ILocationProvider provider = (ILocationProvider) adapter;
fLocation = provider.getPath(input);
}
}
}
}
}
}
use of org.eclipse.ui.editors.text.ILocationProvider in project webtools.sourceediting by eclipse.
the class StorageModelProvider method calculateID.
String calculateID(IStorageEditorInput input) {
/**
* Typically CVS will return a path of "filename.ext" and the input's
* name will be "filename.ext version". The path must be used to load
* the model so that the suffix will be available to compute the
* contentType properly. The editor input name can then be set as the
* base location for display on the editor title bar.
*/
String path = null;
if (input instanceof ILocationProvider) {
IPath ipath = ((ILocationProvider) input).getPath(input);
if (ipath != null) {
path = ipath.toString();
}
}
if (path == null) {
try {
IStorage storage = input.getStorage();
if (storage != null) {
IPath storagePath = storage.getFullPath();
String name = storage.getName();
if (storagePath != null) {
// Favor the name.
if (!storagePath.lastSegment().equals(name)) {
IPath workingPath = storagePath.addTrailingSeparator();
path = workingPath.append(name).toString();
} else {
path = storagePath.makeAbsolute().toString();
}
}
if (path == null)
path = name;
}
} catch (CoreException e) {
Logger.logException(e);
} finally {
if (path == null)
// $NON-NLS-1$
path = input.getName();
}
}
/*
* Prepend the hash to the path value so that we have a 1:1:1 match
* between editor inputs, element info, and models. The editor manager
* should help prevent needlessly duplicated models as long as two
* editor inputs from the same storage indicate they're equals().
*/
// $NON-NLS-1$
path = input.hashCode() + "#" + path;
return path;
}
Aggregations