Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » openEditor in junit test refuses to open my editor, returns TextEditor
openEditor in junit test refuses to open my editor, returns TextEditor [message #725475] Wed, 14 September 2011 21:25 Go to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
I have an editor set up to open Makefile.am and Makefile.in files. I have specified a contenttype extension with "am" file extension and "Makefile.am,Makefile.in" files specified. I also have the same specified in my Automake editor and I refer to the content type id there as well (perhaps overkill).

In the Linux Tools EPP, it works fine. If one clicks on a Makefile.am or Makefile.in file, it opens using the editor.

In my junit test, I use Display.syncExec and create a Makefile.am file and then try and use:


EditorPart openEditor = org.eclipse.ui.ide.IDE.openEditor(
workbench.getActiveWorkbenchWindow().getActivePage(),
makefileAmFile,
true);

I then cast this to an AutomakeEditor to test various aspects of the editor.

When I run this test, I keep getting a ClassCastException because openEditor keeps giving me back a TextEditor and not an AutomakeEditor.

Any ideas why this works in normal Eclipse (i.e. double-clicking on a Makefile.am file brings up the right editor) but not under the junit test framework?
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #725555 is a reply to message #725475] Thu, 15 September 2011 07:09 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 14.09.2011 23:25, Jeff Johnston wrote:
> I have an editor set up to open Makefile.am and Makefile.in files. I
> have specified a contenttype extension with "am" file extension and
> "Makefile.am,Makefile.in" files specified. I also have the same
> specified in my Automake editor and I refer to the content type id
> there as well (perhaps overkill).
>
> In the Linux Tools EPP, it works fine. If one clicks on a Makefile.am
> or Makefile.in file, it opens using the editor.
>
> In my junit test, I use Display.syncExec and create a Makefile.am file
> and then try and use:
>
>
> EditorPart openEditor = org.eclipse.ui.ide.IDE.openEditor(
> workbench.getActiveWorkbenchWindow().getActivePage(),
> makefileAmFile,
> true);
>
> I then cast this to an AutomakeEditor to test various aspects of the
> editor.
>
> When I run this test, I keep getting a ClassCastException because
> openEditor keeps giving me back a TextEditor and not an AutomakeEditor.
>
> Any ideas why this works in normal Eclipse (i.e. double-clicking on a
> Makefile.am file brings up the right editor) but not under the junit
> test framework?
I see two possible reasons:
1) You manually defined the content type or default editor in your
normal Eclipse and hence it is missing when running the test
2) The bundle which defines the content type is not part of the required
bundles.

Dani
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #725739 is a reply to message #725555] Thu, 15 September 2011 16:15 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Quote:
I see two possible reasons:
1) You manually defined the content type or default editor in your
normal Eclipse and hence it is missing when running the test
2) The bundle which defines the content type is not part of the required
bundles.

Dani


Well I verified that the test plug-in does require Autotools UI plugin and Autotools Core plugin so that eliminates number 2.

Can you explain what you mean by the first case above?

My plugins are checked out in my top-level Eclipse and the Autotools UI plugin uses extensions in plugin.xml to specify the content type and editor. I run a child Eclipse application from the parent which uses all plugins from my workspace and in the child Eclipse I can double-click on a Makefile.am file in the workspace and it opens with the Automake editor. Interestingly enough, if I open an external Makefile.am from the child Eclipse, a different editor (rpm editor from another plug-in) gets used which isn't right since the rpm editor should be opening .spec files. Perhaps this indicates something??

I have the Autotools tests plugin checked out in the child Eclipse and I do a right-click->run as.. ->Junit Plugin test on the particular test which is failing.

I also should note that the base type of the automake content type is org.eclipse.core.runtime.text. Could that somehow be a cause of the problem?
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #725951 is a reply to message #725739] Fri, 16 September 2011 09:10 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 15.09.2011 18:15, Jeff Johnston wrote:
> Quote:
>> I see two possible reasons:
>> 1) You manually defined the content type or default editor in your
>> normal Eclipse and hence it is missing when running the test
>> 2) The bundle which defines the content type is not part of the required
>> bundles.
>>
>> Dani
>
>
> Well I verified that the test plug-in does require Autotools UI plugin
> and Autotools Core plugin so that eliminates number 2.
>
> Can you explain what you mean by the first case above?
I meant, if you test things in your manual workspace, maybe at some
earlier date you define the file association (General > Editors > File
Associations) manually and that's why it works there.
> My plugins are checked out in my top-level Eclipse and the Autotools
> UI plugin uses extensions in plugin.xml to specify the content type
> and editor.
Run your test using -debug to see whether maybe some bundles aren't
correctly loaded.
> I run a child Eclipse application from the parent which uses all
> plugins from my workspace and in the child Eclipse I can double-click
> on a Makefile.am file in the workspace and it opens with the Automake
> editor. Interestingly enough, if I open an external Makefile.am from
> the child Eclipse, a different editor (rpm editor from another
> plug-in) gets used which isn't right since the rpm editor should be
> opening .spec files. Perhaps this indicates something??
Is your content type only defined on file extensions or does it uses a
content describer?
> I have the Autotools tests plugin checked out in the child Eclipse and
> I do a right-click->run as.. ->Junit Plugin test on the particular
> test which is failing.
>
> I also should note that the base type of the automake content type is
> org.eclipse.core.runtime.text. Could that somehow be a cause of the
> problem?
No.

Dani
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #726182 is a reply to message #725951] Fri, 16 September 2011 18:20 Go to previous messageGo to next message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
I did some debugging.

It finds the editor fine. It is the default editor, but it then filters it out in EditorRegistry.findRelatedObjects() when it calls WorkbenchActivityHelper.filterItem(). The check for identifier.isEnabled() returns false. Any ideas on why it would think the editor is not enabled?

public static final boolean filterItem(Object object) {
		if (object instanceof IPluginContribution) {
			IPluginContribution contribution = (IPluginContribution) object;
			IWorkbenchActivitySupport workbenchActivitySupport = PlatformUI
					.getWorkbench().getActivitySupport();
			IIdentifier identifier = workbenchActivitySupport
					.getActivityManager().getIdentifier(
							createUnifiedId(contribution));
			if (!identifier.isEnabled()) {
				return true;
			}
		}
		return false;
	}
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #726674 is a reply to message #726182] Mon, 19 September 2011 08:28 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
On 16.09.2011 20:20, Jeff Johnston wrote:
> I did some debugging.
>
> It finds the editor fine. It is the default editor, but it then
> filters it out in EditorRegistry.findRelatedObjects() when it calls
> WorkbenchActivityHelper.filterItem(). The check for
> identifier.isEnabled() returns false. Any ideas on why it would think
> the editor is not enabled?
Maybe some activities are defined in your test setup which filter your
editor? Look for 'org.eclipse.ui.activities' and
'org.eclipse.ui.activitySupport' extensions.

Dani
>
>
> public static final boolean filterItem(Object object) {
> if (object instanceof IPluginContribution) {
> IPluginContribution contribution = (IPluginContribution)
> object;
> IWorkbenchActivitySupport workbenchActivitySupport =
> PlatformUI
> .getWorkbench().getActivitySupport();
> IIdentifier identifier = workbenchActivitySupport
> .getActivityManager().getIdentifier(
> createUnifiedId(contribution));
> if (!identifier.isEnabled()) {
> return true;
> }
> }
> return false;
> }
>
Re: openEditor in junit test refuses to open my editor, returns TextEditor [message #726906 is a reply to message #726674] Mon, 19 September 2011 21:39 Go to previous message
Jeff Johnston is currently offline Jeff JohnstonFriend
Messages: 215
Registered: July 2009
Senior Member
Quote:
Maybe some activities are defined in your test setup which filter your
editor? Look for 'org.eclipse.ui.activities' and
'org.eclipse.ui.activitySupport' extensions.

Dani


Thanks Dani. That appeared to be the problem. There was a plug-in that had activity ids and patterns set up in it. It used a pattern that matched Autotool stuff to map it to a general id, but it did not set default enablement for that id. Adding a default enablement statement seemed to have fixed the problem.

Not sure as to why this problem didn't show up using the editor via double-clicking on a file, but I am happy to have gotten to this work finally.
Previous Topic:Slow performance with AntiVirus (Panda Security IS12)
Next Topic:Change the title bar color of a view
Goto Forum:
  


Current Time: Thu Apr 18 04:19:16 GMT 2024

Powered by FUDForum. Page generated in 0.02383 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top