org.eclipse.ui.IPathEditorInput Java Examples

The following examples show how to use org.eclipse.ui.IPathEditorInput. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractBreakpointRulerAction.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @return the IEditorInput if we're dealing with an external file (or null otherwise)
 */
public static IEditorInput getExternalFileEditorInput(ITextEditor editor) {
    IEditorInput input = editor.getEditorInput();

    //only return not null if it's an external file (IFileEditorInput marks a workspace file, not external file)
    if (input instanceof IFileEditorInput) {
        return null;
    }

    if (input instanceof IPathEditorInput) { //PydevFileEditorInput would enter here
        return input;
    }

    try {
        if (input instanceof IURIEditorInput) {
            return input;
        }
    } catch (Throwable e) {
        //IURIEditorInput not added until eclipse 3.3
    }

    //Note that IStorageEditorInput is not handled for external files (files from zip)

    return input;
}
 
Example #2
Source File: IDEReportProviderFactory.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IReportProvider getProvider( IEditorInput input )
	{
		if ( input instanceof IFileEditorInput )
		{
			return new IDEFileReportProvider( );
		}
		else if ( input instanceof IPathEditorInput )
		{
			return super.getProvider( input );
		}
//		else
//		{
//			return FileReportProvider.getInstance( );
//		}
		return null;
	}
 
Example #3
Source File: UIUtils.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns the URI for the specific editor input.
 * 
 * @param input
 *            the editor input
 * @return the URI, or null if none could be determined
 */
public static URI getURI(IEditorInput input)
{
	if (input instanceof IFileEditorInput)
	{
		return ((IFileEditorInput) input).getFile().getLocationURI();
	}
	if (input instanceof IURIEditorInput)
	{
		return ((IURIEditorInput) input).getURI();
	}
	if (input instanceof IPathEditorInput)
	{
		return URIUtil.toURI(((IPathEditorInput) input).getPath());
	}
	return null;
}
 
Example #4
Source File: FilenameDifferentiator.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private IPath getPath(IEditorPart otherEditor)
{
	IEditorInput input = otherEditor.getEditorInput();
	try
	{
		if (input instanceof IPathEditorInput)
		{
			return ((IPathEditorInput) input).getPath();
		}

		URI uri = (URI) input.getAdapter(URI.class);
		if (uri != null)
		{
			return new Path(uri.getHost() + Path.SEPARATOR + uri.getPath());
		}
		if (input instanceof IURIEditorInput)
		{
			return URIUtil.toPath(((IURIEditorInput) input).getURI());
		}
	}
	catch (Exception e)
	{
	}
	return null;
}
 
Example #5
Source File: UIUtil.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * 
 * @param fileName
 *            the fileName
 * @return the editor with the given fileName, or null if not found.
 */
public static IEditorPart findOpenedEditor( String fileName )
{
	IWorkbenchPage page = PlatformUI.getWorkbench( )
			.getActiveWorkbenchWindow( )
			.getActivePage( );

	IEditorReference[] editors = page.getEditorReferences( );

	for ( int i = 0; i < editors.length; i++ )
	{
		IEditorPart part = editors[i].getEditor( true );
		IPath location = ( (IPathEditorInput) part.getEditorInput( ) ).getPath( );

		if ( fileName.equalsIgnoreCase( location.toOSString( ) ) )
		{
			return part;
		}
	}

	return null;
}
 
Example #6
Source File: FileReportProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IPath getSaveAsPath( Object element )
{
	if ( element instanceof IPathEditorInput )
	{
		IEditorInput input = (IEditorInput) element;

		SaveReportAsWizardDialog dialog = new SaveReportAsWizardDialog( UIUtil.getDefaultShell( ),
				new SaveReportAsWizard( model, input ) );
		if ( dialog.open( ) == Window.OK )
		{
			return dialog.getResult( );
		}
	}
	return null;
}
 
Example #7
Source File: PySourceLocatorBase.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
public IEditorInput findFromOpenedPyEdits() {
    Object ret = OpenEditors.iterOpenEditorsUntilFirstReturn(new ICallback<Object, IPyEdit>() {

        @Override
        public Object call(IPyEdit pyEdit) {
            IEditorInput editorInput = (IEditorInput) pyEdit.getEditorInput();
            if (editorInput instanceof IPathEditorInput) {
                IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;
                IPath localPath = pathEditorInput.getPath();
                if (localPath != null) {
                    if (matchesPath(matchName, editorInput, localPath)) {
                        return editorInput;
                    }
                }
            } else {
                File editorFile = pyEdit.getEditorFile();
                if (editorFile != null) {
                    if (matchesFile(matchName, editorInput, editorFile)) {
                        return editorInput;
                    }
                }
            }
            return null;
        }
    });
    return (IEditorInput) ret;
}
 
Example #8
Source File: WizardSaveAsPage.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void setOriginalFile( IEditorInput input )
{
	String container = ( (IPathEditorInput) input ).getPath( )
			.removeLastSegments( 1 )
			.toOSString( );
	support.setInitialFileLocation( container );
	support.setInitialFileName( input.getName( ) );
}
 
Example #9
Source File: ReportEditorInput.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public boolean equals( Object obj )
{
	if ( this == obj )
		return true;
	if ( obj instanceof IPathEditorInput )
	{
		obj = new ReportEditorInput( (IPathEditorInput) obj );
	}
	if ( !( obj instanceof ReportEditorInput ) )
		return false;
	return file.equals( ( (ReportEditorInput) obj ).file );
}
 
Example #10
Source File: FileReportDocumentProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public boolean isReadOnly( Object element )
{
	if ( element instanceof IPathEditorInput )
	{
		File file = ( (IPathEditorInput) element ).getPath( ).toFile( );
		return !file.canWrite( );
	}
	return super.isReadOnly( element );
}
 
Example #11
Source File: LibraryProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private File getInputForlder( )
{
	IEditorPart editor = UIUtil.getActiveEditor( true );
	if ( editor != null )
	{
		IEditorInput input = editor.getEditorInput( );
		if ( input instanceof IPathEditorInput )
		{
			return ( (IPathEditorInput) input ).getPath( )
					.toFile( )
					.getParentFile( );
		}
	}
	return null;
}
 
Example #12
Source File: FileReportProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public IPath getInputPath( IEditorInput input )
{
	if ( input instanceof IPathEditorInput )
	{
		return ( (IPathEditorInput) input ).getPath( );
	}
	return null;
}
 
Example #13
Source File: DeleteEditorFileHandler.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private static File getFile( IEditorInput editorInput ) {
  File result = null;
  if( editorInput instanceof IPathEditorInput ) {
    IPathEditorInput pathEditorInput = ( IPathEditorInput )editorInput;
    result = pathEditorInput.getPath().toFile();
  } else if( editorInput instanceof IURIEditorInput ) {
    IURIEditorInput uriEditorInput = ( IURIEditorInput )editorInput;
    result = URIUtil.toFile( uriEditorInput.getURI() );
  }
  return result;
}
 
Example #14
Source File: FileReportProvider.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void saveReport( ModuleHandle moduleHandle, Object element,
		IPath origReportPath, IProgressMonitor monitor )
{
	if ( element instanceof IPathEditorInput )
	{
		IPathEditorInput input = (IPathEditorInput) element;

		saveFile( moduleHandle,
				input.getPath( ).toFile( ),
				origReportPath,
				monitor );
	}
}
 
Example #15
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Gets the indexing associated with the editor.
 * 
 * @param editor
 * @return
 */
public static Index getIndex(AbstractThemeableEditor editor)
{
	// NOTE: Moved from CommonContentAssistProcessor
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			IFile file = fileEditorInput.getFile();

			return getIndexManager().getIndex(file.getProject().getLocationURI());
		}
		if (editorInput instanceof IURIEditorInput)
		{
			IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;

			// FIXME This file may be a child, we need to check to see if there's an index with a parent URI.
			return getIndexManager().getIndex(uriEditorInput.getURI());
		}
		if (editorInput instanceof IPathEditorInput)
		{
			IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;

			// FIXME This file may be a child, we need to check to see if there's an index with a parent URI.
			return getIndexManager().getIndex(URIUtil.toURI(pathEditorInput.getPath()));
		}
	}

	return null;
}
 
Example #16
Source File: ImageViewerEditor.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
private static void checkEditorInput( IEditorInput input ) {
  if(    !( input instanceof IStorageEditorInput )
      && !( input instanceof IPathEditorInput )
      && !( input instanceof IURIEditorInput ) )
  {
    throw new IllegalArgumentException( "Invalid input: " + input );
  }
}
 
Example #17
Source File: DeleteEditorFileHandler_FilePDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testExecuteWithPathEditorInput() throws IOException {
  File file = tempFolder.newFile( "foo.txt" );
  IPathEditorInput editorInput = mockPathEditorInput( file );

  executeHandler( editorInput );

  assertThat( file ).doesNotExist();
}
 
Example #18
Source File: EditorUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Gets the URI associated with the editor.
 * 
 * @param editor
 * @return
 */
public static URI getURI(IEditorPart editor)
{
	// NOTE: Moved from CommonContentAssistProcessor
	if (editor != null)
	{
		IEditorInput editorInput = editor.getEditorInput();

		if (editorInput instanceof IURIEditorInput)
		{
			IURIEditorInput uriEditorInput = (IURIEditorInput) editorInput;
			return uriEditorInput.getURI();
		}
		if (editorInput instanceof IPathEditorInput)
		{
			IPathEditorInput pathEditorInput = (IPathEditorInput) editorInput;
			return URIUtil.toURI(pathEditorInput.getPath());
		}
		if (editorInput instanceof IFileEditorInput)
		{
			IFileEditorInput fileEditorInput = (IFileEditorInput) editorInput;
			return fileEditorInput.getFile().getLocationURI();
		}
		try
		{
			if (editorInput instanceof IStorageEditorInput)
			{
				IStorageEditorInput storageEditorInput = (IStorageEditorInput) editorInput;
				IStorage storage = storageEditorInput.getStorage();
				if (storage != null)
				{
					IPath path = storage.getFullPath();
					if (path != null)
					{
						return URIUtil.toURI(path);
					}
				}
			}
		}
		catch (CoreException e)
		{
			IdeLog.logError(CommonEditorPlugin.getDefault(), e);
		}
		if (editorInput instanceof ILocationProviderExtension)
		{
			ILocationProviderExtension lpe = (ILocationProviderExtension) editorInput;
			return lpe.getURI(null);
		}
		if (editorInput instanceof ILocationProvider)
		{
			ILocationProvider lp = (ILocationProvider) editorInput;
			return URIUtil.toURI(lp.getPath(null));
		}
	}

	return null;
}
 
Example #19
Source File: DeleteEditorFileHandler_FilePDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
private static IPathEditorInput mockPathEditorInput( File file ) throws IOException {
  IPathEditorInput editorInput = mock( IPathEditorInput.class );
  when( editorInput.getPath() ).thenReturn( new Path( file.getCanonicalPath() ) );
  return editorInput;
}
 
Example #20
Source File: ReportEditorInput.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Constructor
 * 
 * @param input
 */
public ReportEditorInput( IPathEditorInput input )
{
	this( input.getPath( ).toFile( ) );
}