org.eclipse.ui.IURIEditorInput Java Examples

The following examples show how to use org.eclipse.ui.IURIEditorInput. 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: 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 #2
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 #3
Source File: PydevPackageExplorer.java    From Pydev with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns the element contained in the EditorInput
 */
Object getElementOfInput(IEditorInput input) {
    if (input instanceof IFileEditorInput) {
        return ((IFileEditorInput) input).getFile();
    }
    if (input instanceof IURIEditorInput) {
        IURIEditorInput iuriEditorInput = (IURIEditorInput) input;
        URI uri = iuriEditorInput.getURI();
        return new File(uri);

    }
    if (input instanceof PydevZipFileEditorInput) {
        PydevZipFileEditorInput pydevZipFileEditorInput = (PydevZipFileEditorInput) input;
        try {
            IStorage storage = pydevZipFileEditorInput.getStorage();
            if (storage instanceof PydevZipFileStorage) {
                PydevZipFileStorage pydevZipFileStorage = (PydevZipFileStorage) storage;
                return pydevZipFileStorage;
            }
        } catch (CoreException e) {
            Log.log(e);
        }

    }
    return null;
}
 
Example #4
Source File: IDEFileReportProvider.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
public IPath getInputPath( IEditorInput input )
{
	if ( input instanceof IURIEditorInput )
	{
		//return new Path( ( (IURIEditorInput) input ).getURI( ).getPath( ) );
		URI uri = ( (IURIEditorInput) input ).getURI( );
		if(uri == null && input instanceof IFileEditorInput)
			return ((IFileEditorInput)input).getFile( ).getFullPath( );
		IPath localPath = URIUtil.toPath( uri );
		String host = uri.getHost( );
		if ( host != null && localPath == null )
		{
			return new Path( host + uri.getPath( ) ).makeUNC( true );
		}
		return localPath;
	}
	if ( input instanceof IFileEditorInput )
	{
		return ( (IFileEditorInput) input ).getFile( ).getLocation( );
	}
	return null;
}
 
Example #5
Source File: CustomEditorListener.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void partActivated(IWorkbenchPartReference partRef) {
    IEditorPart part = partRef.getPage().getActiveEditor();
    if (!(part instanceof AbstractTextEditor))
        return;

    // log new active file
    IEditorInput input = part.getEditorInput();
    if (input instanceof IURIEditorInput) {
        URI uri = ((IURIEditorInput)input).getURI();
        if (uri != null && uri.getPath() != null) {
            String currentFile = uri.getPath();
            long currentTime = System.currentTimeMillis() / 1000;
            if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
Example #6
Source File: ClangFormatFormatter.java    From CppStyle with MIT License 6 votes vote down vote up
private static IPath getSourceFilePathFromEditorInput(IEditorInput editorInput) {
	if (editorInput instanceof IURIEditorInput) {
		URI uri = ((IURIEditorInput) editorInput).getURI();
		if (uri != null) {
			IPath path = URIUtil.toPath(uri);
			if (path != null) {
				  return path;
			}
		}
	}

	if (editorInput instanceof IFileEditorInput) {
		IFile file = ((IFileEditorInput) editorInput).getFile();
		if (file != null) {
			return file.getLocation();
		}
	}

	if (editorInput instanceof ILocationProvider) {
		return ((ILocationProvider) editorInput).getPath(editorInput);
	}

	return null;
}
 
Example #7
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 #8
Source File: XdsModel.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * TODO : common with CoreEditorUtils
 * @param input
 * @return
 */
private static URI toURI(IEditorInput input) {
	URI uri = null;
	if (input instanceof IStorageEditorInput) {
		IStorageEditorInput storageEditorInput = (IStorageEditorInput)input;
		IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class);
		if (state != null) {
			uri = HistoryFs.toURI(state);
		}
	}
	else if (input instanceof IURIEditorInput) {

		IURIEditorInput uriEditorInput = (IURIEditorInput) input;
		uri = uriEditorInput.getURI();
	}

	return uri;
}
 
Example #9
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public String getEncoding(Object element) {
	String encoding = super.getEncoding(element);
	if (encoding == null && element instanceof IStorageEditorInput) {
		try {
			IStorage storage = ((IStorageEditorInput) element).getStorage();
			URI uri = storage2UriMapper.getUri(storage);
			if (uri != null) {
				encoding = encodingProvider.getEncoding(uri);
			} else if (storage instanceof IEncodedStorage) {
				encoding = ((IEncodedStorage)storage).getCharset();
			}
		} catch (CoreException e) {
			throw new WrappedException(e);
		}
	}
	if (encoding == null) {
		if (isWorkspaceExternalEditorInput(element))
			encoding = getWorkspaceExternalEncoding((IURIEditorInput)element);
		else
			encoding = getWorkspaceOrDefaultEncoding();
	}
	return encoding;
}
 
Example #10
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isModifiable(Object element) {
	if (isWorkspaceExternalEditorInput(element)) {
		URIInfo info= (URIInfo) getElementInfo(element);
		if (info != null) {
			if (info.updateCache) {
				try {
					updateCache((IURIEditorInput) element);
				} catch (CoreException x) {
					handleCoreException(x, "XtextDocumentProvider.isModifiable");
				}
			}
			return info.isModifiable;
		}
	}
	return super.isModifiable(element);
}
 
Example #11
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @since 2.3
 */
protected void updateCache(IURIEditorInput input) throws CoreException {
	URIInfo info= (URIInfo) getElementInfo(input);
	if (info != null) {
		URI emfURI = toEmfUri(input.getURI());
		if (emfURI != null) {
			boolean readOnly = true;
			if (emfURI.isFile() && !emfURI.isArchive()) {
				// TODO: Should we use the ResourceSet somehow to obtain the URIConverter for the file protocol?
				// see also todo below, but don't run into a stackoverflow ;-)
				Map<String, ?> attributes = URIConverter.INSTANCE.getAttributes(emfURI, null);
				readOnly = Boolean.TRUE.equals(attributes.get(URIConverter.ATTRIBUTE_READ_ONLY));
			}
			info.isReadOnly=  readOnly;
			info.isModifiable= !readOnly;
		}
		info.updateCache= false;
	}
}
 
Example #12
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean isReadOnly(Object element) {
	if (isWorkspaceExternalEditorInput(element)) {
		URIInfo info= (URIInfo) getElementInfo(element);
		if (info != null) {
			if (info.updateCache) {
				try {
					updateCache((IURIEditorInput) element);
				} catch (CoreException x) {
					handleCoreException(x, "XtextDocumentProvider.isReadOnly");
				}
			}
			return info.isReadOnly;
		}
	}
	return super.isReadOnly(element);
}
 
Example #13
Source File: CoreEditorUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
    * Returns File underlying this editor input. 
    * 
    * This method should be modified, whenever new editor input is supported 
    * for some editor requiring access to File.
    * 
    * @param input the editor input to operate on.
    * 
    * @return file underlying given editor input.
    */    
   public static File editorInputToFile(IEditorInput input) {
	if (input == null) 
	    return null;
	
       if (input instanceof IFileEditorInput) {
       	IFile file = editorInputToIFile(input);
           if (file != null) {
               return ResourceUtils.getAbsoluteFile(file);
           }
       }
       else if (input instanceof IURIEditorInput) {
           IURIEditorInput uriEditorInput = (IURIEditorInput) input;
           return new File(uriEditorInput.getURI());
       }
       else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput || input instanceof IStorageEditorInput) {
       	// do nothing
	}
       else{
       	LogHelper.logError("Unknown editor input");
       }
       
       return null;
}
 
Example #14
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}
 
Example #15
Source File: PydevFileEditorInput.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public URI getURI(Object element) {
    if (element instanceof IURIEditorInput) {
        IURIEditorInput editorInput = (IURIEditorInput) element;
        return editorInput.getURI();
    }
    return null;
}
 
Example #16
Source File: ReportEditorProxy.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void init( IEditorSite site, IEditorInput input )
		throws PartInitException
{
	cachedSite = site;

	if ( instance != null )
	{
		getSite( ).getWorkbenchWindow( )
				.getPartService( )
				.removePartListener( instance );
		instance.dispose( );
	}

	if ( input instanceof IFileEditorInput
			|| input instanceof IURIEditorInput )
	{
		instance = new IDEMultiPageReportEditor( );
	}
	else
	{
		instance = new MultiPageReportEditor( );
	}

	// must add property listener before init.
	instance.addPropertyListener( this );

	instance.init( site, input );
	getSite( ).getWorkbenchWindow( )
			.getPartService( )
			.addPartListener( this );

}
 
Example #17
Source File: CustomExecutionListener.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void postExecuteSuccess(String commandId, Object returnValue) {
    if (commandId.equals("org.eclipse.ui.file.save")) {
        IWorkbench workbench = PlatformUI.getWorkbench();
        if (workbench == null) return;
        IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
        if (window == null) return;

        if (window.getPartService() == null) return;
        if (window.getPartService().getActivePart() == null) return;
        if (window.getPartService().getActivePart().getSite() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
        if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

        // log file save event
        IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
        if (input instanceof IURIEditorInput) {
            URI uri = ((IURIEditorInput)input).getURI();
            if (uri != null && uri.getPath() != null) {
                String currentFile = uri.getPath();
                long currentTime = System.currentTimeMillis() / 1000;

                // always log writes
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), true);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
Example #18
Source File: CustomCaretListener.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void caretMoved(CaretEvent event) {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) return;
    if (window.getPartService() == null) return;
    if (window.getPartService().getActivePart() == null) return;
    if (window.getPartService().getActivePart().getSite() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

    // log file if one is opened by default
    IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
    if (input instanceof IURIEditorInput) {
        URI uri = ((IURIEditorInput)input).getURI();
        if (uri != null && uri.getPath() != null) {
            String currentFile = uri.getPath();
            long currentTime = System.currentTimeMillis() / 1000;
            if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                WakaTime.getDefault().lastFile = currentFile;
                WakaTime.getDefault().lastTime = currentTime;
            }
        }
    }
}
 
Example #19
Source File: H5Editor.java    From dawnsci with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the file path from a FileStoreEditorInput. Removes any "file:"
 * from the URI to the file path if it exists.
 * 
 * @param fileInput
 * @return String
 */
public String getFilePath(IEditorInput fileInput) {
	
	final IFile file = (IFile)fileInput.getAdapter(IFile.class);
	if (file!=null) return file.getLocation().toOSString();

	if (fileInput instanceof IURIEditorInput) {
		String path = ((IURIEditorInput)fileInput).getURI().toString();
		if (path.startsWith("file:")) path = path.substring(5);
		path = path.replace("%20", " ");
		return path;
	} 
	return null;
}
 
Example #20
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 #21
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected IAnnotationModel createAnnotationModel(Object element) throws CoreException {
	if (element instanceof IFileEditorInput) {
		IFileEditorInput input = (IFileEditorInput) element;
		return new XtextResourceMarkerAnnotationModel(input.getFile(), issueResolutionProvider, issueUtil);
	} else if (element instanceof IURIEditorInput) {
		return new AnnotationModel();
	}
	return super.createAnnotationModel(element);
}
 
Example #22
Source File: IndexQueryingHyperlinkDetector.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
protected URI getURI()
{
	// Now try and resolve the value as a URI...
	IEditorInput input = getEditorInput();
	if (input instanceof IURIEditorInput)
	{
		return ((IURIEditorInput) input).getURI();
	}
	if (input instanceof IFileEditorInput)
	{
		IFile file = ((IFileEditorInput) input).getFile();
		return file.getLocationURI();
	}
	return null;
}
 
Example #23
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 #24
Source File: DeleteEditorFileHandler_FilePDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testExecuteWithUriEditorInput() throws IOException {
  File file = tempFolder.newFile( "foo.txt" );
  IURIEditorInput editorInput = mockUriEditorInput( file );

  executeHandler( editorInput );

  assertThat( file ).doesNotExist();
}
 
Example #25
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 #26
Source File: CoreEditorUtils.java    From xds-ide with Eclipse Public License 1.0 5 votes vote down vote up
public static IFileStore editorInputToFileStore(IEditorInput input) {
	if (input == null) 
	    return null;
	
	IFileStore result = null;
	
       if (input instanceof IFileEditorInput) {
       	IFile file = editorInputToIFile(input);
           if (file != null) {
           	result =  ResourceUtils.toFileStore(file);
           }
       }
       else if (input instanceof IURIEditorInput) {
           IURIEditorInput uriEditorInput = (IURIEditorInput) input;
           result =  ResourceUtils.toFileStore(uriEditorInput.getURI());
       }
       else if (input instanceof CommonSourceNotFoundEditorInput || input instanceof CompareEditorInput) {
       	// do nothing
       	 return null;
	}
       else if (input instanceof IStorageEditorInput) {
       	IStorageEditorInput storageEditorInput = (IStorageEditorInput)input;
       	IFileRevision state = AdapterUtilities.getAdapter(storageEditorInput, IFileRevision.class);
       	if (state != null) {
       		result = ResourceUtils.toFileStore(HistoryFs.toURI(state));
       	}
       }
       
       if (result == null){
       	LogHelper.logError("Unknown editor input");
       }
       
       return result;
}
 
Example #27
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 #28
Source File: XtextDocumentProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.3
 */
protected boolean isWorkspaceExternalEditorInput(Object element) {
	return element instanceof IURIEditorInput && !(element instanceof IFileEditorInput);
}
 
Example #29
Source File: WakaTime.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void earlyStartup() {
    final IWorkbench workbench = PlatformUI.getWorkbench();

    // listen for save file events
    ICommandService commandService = (ICommandService) workbench.getService(ICommandService.class);
    executionListener = new CustomExecutionListener();
    commandService.addExecutionListener(executionListener);

    workbench.getDisplay().asyncExec(new Runnable() {
        public void run() {
            IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
            if (window == null) return;

            // setup wakatime menu
            //MenuHandler handler = new MenuHandler();
            String debug = ConfigFile.get("settings", "debug");
            DEBUG = debug != null && debug.trim().equals("true");


            WakaTime.log.debug("Initializing WakaTime plugin (https://wakatime.com) v"+VERSION);

            // prompt for apiKey if not set
            String apiKey = ConfigFile.get("settings", "api_key");
            if (apiKey == "") {
                promptForApiKey(window);
            }

            Dependencies.configureProxy();

            if (!Dependencies.isPythonInstalled()) {
                Dependencies.installPython();
                if (!Dependencies.isPythonInstalled()) {
                    MessageDialog dialog = new MessageDialog(window.getShell(),
                        "Warning!", null,
                        "WakaTime needs Python installed. Please install Python from python.org/downloads, then restart Eclipse.",
                        MessageDialog.WARNING, new String[]{IDialogConstants.OK_LABEL}, 0);
                    dialog.open();
                }
            }
            checkCore();

            if (window.getPartService() == null) return;

            // listen for caret movement
            if (window.getPartService().getActivePartReference() != null &&
                window.getPartService().getActivePartReference().getPage() != null &&
                window.getPartService().getActivePartReference().getPage().getActiveEditor() != null
            ) {
                IEditorPart part = window.getPartService().getActivePartReference().getPage().getActiveEditor();
                if (!(part instanceof AbstractTextEditor))
                    return;
                ((StyledText)part.getAdapter(Control.class)).addCaretListener(new CustomCaretListener());
            }

            // listen for change of active file
            window.getPartService().addPartListener(editorListener);

            if (window.getPartService().getActivePart() == null) return;
            if (window.getPartService().getActivePart().getSite() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return;
            if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return;

            // log file if one is opened by default
            IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();
            if (input instanceof IURIEditorInput) {
                URI uri = ((IURIEditorInput)input).getURI();
                if (uri != null && uri.getPath() != null) {
                    String currentFile = uri.getPath();
                    long currentTime = System.currentTimeMillis() / 1000;
                    if (!currentFile.equals(WakaTime.getDefault().lastFile) || WakaTime.getDefault().lastTime + WakaTime.FREQUENCY * 60 < currentTime) {
                        WakaTime.sendHeartbeat(currentFile, WakaTime.getActiveProject(), false);
                        WakaTime.getDefault().lastFile = currentFile;
                        WakaTime.getDefault().lastTime = currentTime;
                    }
                }
            }

            WakaTime.log.debug("Finished initializing WakaTime plugin (https://wakatime.com) v"+VERSION);
        }
    });
}
 
Example #30
Source File: DeleteEditorFileHandler_FilePDETest.java    From eclipse-extras with Eclipse Public License 1.0 4 votes vote down vote up
private static IURIEditorInput mockUriEditorInput( File file ) {
  IURIEditorInput editorInput = mock( IURIEditorInput.class );
  when( editorInput.getURI() ).thenReturn( file.toURI() );
  return editorInput;
}