Search in sources :

Example 1 with ILocationProvider

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;
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ILocationProvider(org.eclipse.ui.editors.text.ILocationProvider) IStorage(org.eclipse.core.resources.IStorage)

Example 2 with ILocationProvider

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);
}
Also used : IPathEditorInput(org.eclipse.ui.IPathEditorInput) IAction(org.eclipse.jface.action.IAction) IPath(org.eclipse.core.runtime.IPath) ILocationProvider(org.eclipse.ui.editors.text.ILocationProvider) IDocument(org.eclipse.jface.text.IDocument)

Example 3 with ILocationProvider

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);
                    }
                }
            }
        }
    }
}
Also used : IAdaptable(org.eclipse.core.runtime.IAdaptable) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ArrayList(java.util.ArrayList) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IEditorPart(org.eclipse.ui.IEditorPart) ITextSelection(org.eclipse.jface.text.ITextSelection) IWorkbenchPart(org.eclipse.ui.IWorkbenchPart) ISelection(org.eclipse.jface.viewers.ISelection) ILocationProvider(org.eclipse.ui.editors.text.ILocationProvider) ArrayList(java.util.ArrayList) List(java.util.List) IResource(org.eclipse.core.resources.IResource) IEditorInput(org.eclipse.ui.IEditorInput)

Example 4 with ILocationProvider

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;
}
Also used : IPath(org.eclipse.core.runtime.IPath) CoreException(org.eclipse.core.runtime.CoreException) ILocationProvider(org.eclipse.ui.editors.text.ILocationProvider) IStorage(org.eclipse.core.resources.IStorage)

Aggregations

ILocationProvider (org.eclipse.ui.editors.text.ILocationProvider)4 IPath (org.eclipse.core.runtime.IPath)3 IStorage (org.eclipse.core.resources.IStorage)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPathEditorInput (org.eclipse.ui.IPathEditorInput)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 IAdaptable (org.eclipse.core.runtime.IAdaptable)1 IAction (org.eclipse.jface.action.IAction)1 IDocument (org.eclipse.jface.text.IDocument)1 ITextSelection (org.eclipse.jface.text.ITextSelection)1 ISelection (org.eclipse.jface.viewers.ISelection)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 IEditorInput (org.eclipse.ui.IEditorInput)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPart (org.eclipse.ui.IWorkbenchPart)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1