Java Code Examples for org.eclipse.ui.IWorkbenchWindow#getPartService()

The following examples show how to use org.eclipse.ui.IWorkbenchWindow#getPartService() . 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: OccurrencesSearchMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init(IWorkbenchWindow window) {
	disposeSubmenuActions(); // paranoia code: double initialization should not happen
	if (window != null) {
		fPartService= window.getPartService();
		if (fPartService != null) {
			fRetargetActions= new RetargetAction[] {
				createSubmenuAction(fPartService, JdtActionConstants.FIND_OCCURRENCES_IN_FILE, ActionMessages.OccurrencesSearchMenuAction_occurrences_in_file_label, IJavaEditorActionDefinitionIds.SEARCH_OCCURRENCES_IN_FILE),
				createSubmenuAction(fPartService, JdtActionConstants.FIND_IMPLEMENT_OCCURRENCES, ActionMessages.OccurrencesSearchMenuAction_implementing_methods_label, IJavaEditorActionDefinitionIds.SEARCH_IMPLEMENT_OCCURRENCES_IN_FILE),
				createSubmenuAction(fPartService, JdtActionConstants.FIND_EXCEPTION_OCCURRENCES, ActionMessages.OccurrencesSearchMenuAction_throwing_exception_label, IJavaEditorActionDefinitionIds.SEARCH_EXCEPTION_OCCURRENCES_IN_FILE),
				createSubmenuAction(fPartService, JdtActionConstants.FIND_METHOD_EXIT_OCCURRENCES, ActionMessages.OccurrencesSearchMenuAction_method_exits_label, IJavaEditorActionDefinitionIds.SEARCH_METHOD_EXIT_OCCURRENCES),
				createSubmenuAction(fPartService, JdtActionConstants.FIND_BREAK_CONTINUE_TARGET_OCCURRENCES, ActionMessages.OccurrencesSearchMenuAction_break_continue_target_label, IJavaEditorActionDefinitionIds.SEARCH_BREAK_CONTINUE_TARGET_OCCURRENCES)
			};
		}
	}
}
 
Example 2
Source File: WakaTime.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static String getActiveProject() {
    IWorkbench workbench = PlatformUI.getWorkbench();
    IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
    if (window == null) return null;
    if (window.getPartService() == null) return null;
    if (window.getPartService().getActivePart() == null) return null;
    if (window.getPartService().getActivePart().getSite() == null) return null;
    if (window.getPartService().getActivePart().getSite().getPage() == null) return null;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor() == null) return null;
    if (window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput() == null) return null;

    IEditorInput input = window.getPartService().getActivePart().getSite().getPage().getActiveEditor().getEditorInput();

    IProject project = null;

    if (input instanceof FileEditorInput) {
        project = ((FileEditorInput)input).getFile().getProject();
    }

    if (project == null)
        return null;

    return project.getName();
}
 
Example 3
Source File: EditorBoundViewPart.java    From depan with Apache License 2.0 5 votes vote down vote up
protected E getActiveEditor() {
  IWorkbenchWindow wndo = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
  if (null == wndo) {
    return null;
  }

  IPartService srvc = wndo.getPartService();
  return getAcceptableEditor(srvc.getActivePart());
}
 
Example 4
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void windowClosed(IWorkbenchWindow window)
{
	IPartService partService = window.getPartService();
	if (partService != null)
	{
		partService.removePartListener(fPartListener);
	}
	window.removePerspectiveListener(fPerspectiveListener);
}
 
Example 5
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
public void windowOpened(IWorkbenchWindow window)
{
	IPartService partService = window.getPartService();
	if (partService != null)
	{
		partService.addPartListener(fPartListener);
	}
	window.addPerspectiveListener(fPerspectiveListener);
}
 
Example 6
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void addPartListener()
{
	try
	{
		IWorkbench workbench = PlatformUI.getWorkbench();
		if (workbench != null)
		{
			IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
			IPartService partService;
			for (IWorkbenchWindow window : windows)
			{
				partService = window.getPartService();
				if (partService != null)
				{
					partService.addPartListener(fPartListener);
				}
				window.addPerspectiveListener(fPerspectiveListener);
			}

			// Listen on any future windows
			PlatformUI.getWorkbench().addWindowListener(fWindowListener);
		}
	}
	catch (Exception e)
	{
		// ignore, may be running headless, like in tests
	}
}
 
Example 7
Source File: CommonEditorPlugin.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
private void removePartListener()
{
	IWorkbench workbench = null;
	try
	{
		workbench = PlatformUI.getWorkbench();
	}
	catch (Exception e)
	{
		// ignore, may be running headless, like in tests
	}
	if (workbench != null)
	{
		IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
		IPartService partService;
		for (IWorkbenchWindow window : windows)
		{
			partService = window.getPartService();
			if (partService != null)
			{
				partService.removePartListener(fPartListener);
			}
			window.removePerspectiveListener(fPerspectiveListener);
		}
		PlatformUI.getWorkbench().removeWindowListener(fWindowListener);
	}
}
 
Example 8
Source File: SurroundWithTemplateMenuAction.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void init(IWorkbenchWindow window) {
	if (fPartService != null) {
		fPartService.removePartListener(fPartListener);
		fPartService= null;
	}

	if (window != null) {
		IPartService partService= window.getPartService();
		if (partService != null) {
			fPartService= partService;
			partService.addPartListener(fPartListener);
		}
	}
}
 
Example 9
Source File: WakaTime.java    From eclipse-wakatime with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void stop(BundleContext context) throws Exception {
    plugin = null;
    super.stop(context);

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window != null && window.getPartService() != null)
        window.getPartService().removePartListener(editorListener);
}
 
Example 10
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 11
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 12
Source File: EditorManager.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public void initialize() {
	IWorkbenchWindow window = WorkbenchUtils.getActiveWorkbenchWindow();
	IPartService partService = window.getPartService();
	partService.addPartListener(new ViewPartListener());
}
 
Example 13
Source File: JavaScriptLightWeightEditor.java    From typescript.java with MIT License 4 votes vote down vote up
private IWorkbenchPart getActivePart() {
	IWorkbenchWindow window = getSite().getWorkbenchWindow();
	IPartService service = window.getPartService();
	IWorkbenchPart part = service.getActivePart();
	return part;
}
 
Example 14
Source File: JavaEditor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
private IWorkbenchPart getActivePart() {
	IWorkbenchWindow window= getSite().getWorkbenchWindow();
	IPartService service= window.getPartService();
	IWorkbenchPart part= service.getActivePart();
	return part;
}
 
Example 15
Source File: WorkbenchUtils.java    From goclipse with Eclipse Public License 1.0 4 votes vote down vote up
public static IWorkbenchPart getActivePart(IWorkbenchPartSite site) {
	IWorkbenchWindow window = site.getWorkbenchWindow();
	IPartService service = window.getPartService();
	return service.getActivePart();
}