Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to open model file in text editor programmatically(How to open model file in text editor programmatically)
How to open model file in text editor programmatically [message #1807259] Mon, 27 May 2019 06:19 Go to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Hi,

I want to open a xtext model file in text editor in some conditions.

File ->OpenWith works fine, but I want to achieve this programmatically.
When user double clicks on the file. I want to check some condition and if true, I want to open that file in text editor.

How can I achieve this ?


Thanks and regards,
Virag Purnam
Re: How to open model file in text editor programmatically [message #1807260 is a reply to message #1807259] Mon, 27 May 2019 06:33 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
have a look at the org.eclipse.ui.ide.editorAssociationOverride extension point

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807267 is a reply to message #1807260] Mon, 27 May 2019 09:53 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Hi Mr. Christian Dietrich,

Do you have example?
Where should I call this to override association.
Can I call from NatureAddingEditorCallback.java ?

Thanks and regards,
Virag Purnam
Re: How to open model file in text editor programmatically [message #1807269 is a reply to message #1807267] Mon, 27 May 2019 10:11 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
No I don't (at least none I can give you just so)

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807270 is a reply to message #1807269] Mon, 27 May 2019 10:12 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
And you don't call it. You simply implement it.
It will be called if you open a file
And then you can tell it to open with another editor
Instead of the all


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807271 is a reply to message #1807270] Mon, 27 May 2019 10:19 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Hi Mr. Christian Dietrich,

I have implemented IEditorAssociationOverride after using that extension point but it is not getting called when I open file.

Any idea?

<extension
          point="org.eclipse.ui.ide.editorAssociationOverride">
       <editorAssociationOverride
             class="CustomEditorAssociationOverride"
             id="customEditorAssociationOverride">
       </editorAssociationOverride>
    </extension>


Thanks and regards,
Virag Purnam

[Updated on: Mon, 27 May 2019 10:40]

Report message to a moderator

Re: How to open model file in text editor programmatically [message #1807275 is a reply to message #1807271] Mon, 27 May 2019 10:45 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
how does your impl look like

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de

[Updated on: Mon, 27 May 2019 10:46]

Report message to a moderator

Re: How to open model file in text editor programmatically [message #1807276 is a reply to message #1807275] Mon, 27 May 2019 10:49 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
btw class in the default package is always a bad idea

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807277 is a reply to message #1807276] Mon, 27 May 2019 11:19 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
In implementation.
I just added some sysout to check if control comes there.

public class CustomEditorAssociationOverride implements IEditorAssociationOverride {

	public CustomEditorAssociationOverride() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		System.out.println("Virag");
		return null;
	}

	@Override
	public IEditorDescriptor[] overrideEditors(String fileName, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		System.out.println("Virag1");
		return null;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		System.out.println("Virag2");
		return null;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		System.out.println("Virag3");
		return null;
	}

}
Re: How to open model file in text editor programmatically [message #1807278 is a reply to message #1807276] Mon, 27 May 2019 11:19 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
In implementation.
I just added some sysout to check if control comes there.

public class CustomEditorAssociationOverride implements IEditorAssociationOverride {

	public CustomEditorAssociationOverride() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		System.out.println("Virag");
		return null;
	}

	@Override
	public IEditorDescriptor[] overrideEditors(String fileName, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		System.out.println("Virag1");
		return null;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		System.out.println("Virag2");
		return null;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		System.out.println("Virag3");
		return null;
	}

}
Re: How to open model file in text editor programmatically [message #1807279 is a reply to message #1807278] Mon, 27 May 2019 11:21 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
I will move the class to specific package. Thanks for the pointer.

Regards,
Virag Purnam
Re: How to open model file in text editor programmatically [message #1807280 is a reply to message #1807279] Mon, 27 May 2019 11:29 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
and you should return editorDescriptors
(or the specific one if you want to change)


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807281 is a reply to message #1807280] Mon, 27 May 2019 11:34 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Hello Mr. Christian Dietrich,

But still these methods are not getting called, when file is opened.
Do you see any mistake from my end ?

Thanks and regards,
Virag Purnam
Re: How to open model file in text editor programmatically [message #1807283 is a reply to message #1807281] Mon, 27 May 2019 11:51 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
please show complete class and plugin.xml again

Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807314 is a reply to message #1807283] Tue, 28 May 2019 04:25 Go to previous messageGo to next message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Hi Mr. Christian Dietrich,

I have created a sample Xtext project for the same.

Grammar:
grammar org.xtext.example.mydsl.MyDsl with org.eclipse.xtext.common.Terminals hidden(WS, ML_COMMENT, SL_COMMENT, TEST_STMT)

generate myDsl "http://www.xtext.org/example/mydsl/MyDsl"

Model:
	conts+=Cont* procs+=Proc*;
	
Cont:
	'Cont' name=ID '{' items+=Item* '}' ;

Item: 'Item' name=ID;


Proc:
	'Link' item1=[Item|ID] 'OF' con1=[Cont|ID] 'TO' item2=[Item|ID] 'OF' con2=[Cont|ID]
;

//Test  statement
terminal TEST_STMT :  'FreeText: ' ->  '.';


Plugin.xml :
<?xml version="1.0" encoding="windows-1252"?>
<?eclipse version="3.0"?>
<plugin>
	<extension
		point="org.eclipse.ui.editors">
		<editor
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.XtextEditor"
			contributorClass="org.eclipse.ui.editors.text.TextEditorActionContributor"
			default="true"
			extensions="mydsl"
			id="org.xtext.example.mydsl.MyDsl"
			name="MyDsl Editor">
		</editor>
	</extension>
	<extension
		point="org.eclipse.ui.handlers">
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclarationHandler"
			commandId="org.eclipse.xtext.ui.editor.hyperlinking.OpenDeclaration">
			<activeWhen>
				<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
				</reference>
			</activeWhen>
		</handler>
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.handler.ValidateActionHandler"
			commandId="org.xtext.example.mydsl.MyDsl.validate">
		<activeWhen>
			<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
			</reference>
		</activeWhen>
		</handler>
		<!-- copy qualified name -->
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedNameHandler"
			commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName">
			<activeWhen>
				<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened" />
			</activeWhen>
		</handler>
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedNameHandler"
			commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedName">
			<activeWhen>
				<and>
					<reference definitionId="org.xtext.example.mydsl.MyDsl.XtextEditor.opened" />
					<iterate>
						<adapt type="org.eclipse.xtext.ui.editor.outline.IOutlineNode" />
					</iterate>
				</and>
			</activeWhen>
		</handler>
	</extension>
	<extension point="org.eclipse.core.expressions.definitions">
		<definition id="org.xtext.example.mydsl.MyDsl.Editor.opened">
			<and>
				<reference definitionId="isActiveEditorAnInstanceOfXtextEditor"/>
				<with variable="activeEditor">
					<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
						value="org.xtext.example.mydsl.MyDsl"
						forcePluginActivation="true"/>
				</with>
			</and>
		</definition>
		<definition id="org.xtext.example.mydsl.MyDsl.XtextEditor.opened">
			<and>
				<reference definitionId="isXtextEditorActive"/>
				<with variable="activeEditor">
					<test property="org.eclipse.xtext.ui.editor.XtextEditor.languageName"
						value="org.xtext.example.mydsl.MyDsl"
						forcePluginActivation="true"/>
				</with>
			</and>
		</definition>
	</extension>
	<extension
			point="org.eclipse.ui.preferencePages">
		<page
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.preferences.LanguageRootPreferencePage"
			id="org.xtext.example.mydsl.MyDsl"
			name="MyDsl">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.syntaxcoloring.SyntaxColoringPreferencePage"
			id="org.xtext.example.mydsl.MyDsl.coloring"
			name="Syntax Coloring">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.templates.XtextTemplatePreferencePage"
			id="org.xtext.example.mydsl.MyDsl.templates"
			name="Templates">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
	</extension>
	<extension
			point="org.eclipse.ui.propertyPages">
		<page
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.preferences.LanguageRootPreferencePage"
			id="org.xtext.example.mydsl.MyDsl"
			name="MyDsl">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
			<enabledWhen>
				<adapt type="org.eclipse.core.resources.IProject"/>
			</enabledWhen>
			<filter name="projectNature" value="org.eclipse.xtext.ui.shared.xtextNature"/>
		</page>
	</extension>
	<extension
		point="org.eclipse.ui.keywords">
		<keyword
			id="org.xtext.example.mydsl.ui.keyword_MyDsl"
			label="MyDsl"/>
	</extension>
	<extension
		point="org.eclipse.ui.commands">
	<command
			description="Trigger expensive validation"
			id="org.xtext.example.mydsl.MyDsl.validate"
			name="Validate">
	</command>
	<!-- copy qualified name -->
	<command
			id="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
			categoryId="org.eclipse.ui.category.edit"
			description="Copy the qualified name for the selected element"
			name="Copy Qualified Name">
	</command>
	<command
			id="org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedName"
			categoryId="org.eclipse.ui.category.edit"
			description="Copy the qualified name for the selected element"
			name="Copy Qualified Name">
	</command>
	</extension>
	<extension point="org.eclipse.ui.menus">
		<menuContribution
			locationURI="popup:#TextEditorContext?after=group.edit">
			 <command
				 commandId="org.xtext.example.mydsl.MyDsl.validate"
				 style="push"
				 tooltip="Trigger expensive validation">
			<visibleWhen checkEnabled="false">
				<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
				</reference>
			</visibleWhen>
		</command>
		</menuContribution>
		<!-- copy qualified name -->
		<menuContribution locationURI="popup:#TextEditorContext?after=copy">
			<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
				style="push" tooltip="Copy Qualified Name">
				<visibleWhen checkEnabled="false">
					<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened" />
				</visibleWhen>
			</command>
		</menuContribution>
		<menuContribution locationURI="menu:edit?after=copy">
			<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.EditorCopyQualifiedName"
				style="push" tooltip="Copy Qualified Name">
				<visibleWhen checkEnabled="false">
					<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened" />
				</visibleWhen>
			</command>
		</menuContribution>
		<menuContribution locationURI="popup:org.eclipse.xtext.ui.outline?after=additions">
			<command commandId="org.eclipse.xtext.ui.editor.copyqualifiedname.OutlineCopyQualifiedName"
				style="push" tooltip="Copy Qualified Name">
				<visibleWhen checkEnabled="false">
					<and>
						<reference definitionId="org.xtext.example.mydsl.MyDsl.XtextEditor.opened" />
						<iterate>
							<adapt type="org.eclipse.xtext.ui.editor.outline.IOutlineNode" />
						</iterate>
					</and>
				</visibleWhen>
			</command>
		</menuContribution>
	</extension>
	<extension point="org.eclipse.ui.menus">
		<menuContribution locationURI="popup:#TextEditorContext?endof=group.find">
			<command commandId="org.eclipse.xtext.ui.editor.FindReferences">
				<visibleWhen checkEnabled="false">
					<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
					</reference>
				</visibleWhen>
			</command>
		</menuContribution>
	</extension>
	<extension point="org.eclipse.ui.handlers">
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.findrefs.FindReferencesHandler"
			commandId="org.eclipse.xtext.ui.editor.FindReferences">
			<activeWhen>
				<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
				</reference>
			</activeWhen>
		</handler>
	</extension>
	<extension point="org.eclipse.core.contenttype.contentTypes">
		<content-type
			base-type="org.eclipse.core.runtime.text"
			file-extensions="mydsl"
			id="org.xtext.example.mydsl.MyDsl.contenttype"
			name="MyDsl File"
			priority="normal">
		</content-type>
	</extension>
	<!-- adding resource factories -->
	<extension
		point="org.eclipse.emf.ecore.extension_parser">
		<parser
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.resource.IResourceFactory"
			type="mydsl">
		</parser>
	</extension>
	<extension point="org.eclipse.xtext.extension_resourceServiceProvider">
		<resourceServiceProvider
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.resource.IResourceUIServiceProvider"
			uriExtension="mydsl">
		</resourceServiceProvider>
	</extension>
	<!-- marker definitions for org.xtext.example.mydsl.MyDsl -->
	<extension
			id="mydsl.check.fast"
			name="MyDsl Problem"
			point="org.eclipse.core.resources.markers">
		<super type="org.eclipse.xtext.ui.check.fast"/>
		<persistent value="true"/>
	</extension>
	<extension
			id="mydsl.check.normal"
			name="MyDsl Problem"
			point="org.eclipse.core.resources.markers">
		<super type="org.eclipse.xtext.ui.check.normal"/>
		<persistent value="true"/>
	</extension>
	<extension
			id="mydsl.check.expensive"
			name="MyDsl Problem"
			point="org.eclipse.core.resources.markers">
		<super type="org.eclipse.xtext.ui.check.expensive"/>
		<persistent value="true"/>
	</extension>
	<extension point="org.eclipse.ui.preferencePages">
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.validation.ValidatorPreferencePage"
			id="org.xtext.example.mydsl.MyDsl.validator.preferencePage"
			name="Errors/Warnings">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
	</extension>
	<extension point="org.eclipse.xtext.builder.participant">
		<participant
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.builder.IXtextBuilderParticipant"
			fileExtensions="mydsl"/>
	</extension>
	<extension point="org.eclipse.ui.preferencePages">
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.builder.preferences.BuilderPreferencePage"
			id="org.xtext.example.mydsl.MyDsl.compiler.preferencePage"
			name="Compiler">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
	</extension>
	<extension point="org.eclipse.ui.propertyPages">
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.builder.preferences.BuilderPreferencePage"
			id="org.xtext.example.mydsl.MyDsl.compiler.propertyPage"
			name="Compiler">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
			<enabledWhen>
				<adapt type="org.eclipse.core.resources.IProject"/>
			</enabledWhen>
			<filter name="projectNature" value="org.eclipse.xtext.ui.shared.xtextNature"/>
		</page>
	</extension>
	<extension point="org.eclipse.ui.menus">
		<menuContribution locationURI="popup:#TextEditorContext?after=xtext.ui.openDeclaration">
			<command
				commandId="org.eclipse.xtext.ui.OpenGeneratedFileCommand"
				id="org.xtext.example.mydsl.MyDsl.OpenGeneratedCode"
				style="push">
				<visibleWhen checkEnabled="false">
					<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened" />
				</visibleWhen>
			</command>
		</menuContribution>
	</extension>
	<extension point="org.eclipse.ui.handlers">
		<handler
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.generator.trace.OpenGeneratedFileHandler"
			commandId="org.eclipse.xtext.ui.OpenGeneratedFileCommand">
			<activeWhen>
				<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened" />
			</activeWhen>
		</handler>
	</extension>
	<!-- Quick Outline -->
	<extension
		point="org.eclipse.ui.handlers">
		<handler 
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.outline.quickoutline.ShowQuickOutlineActionHandler"
			commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline">
			<activeWhen>
				<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
				</reference>
			</activeWhen>
		</handler>
	</extension>
	<extension
		point="org.eclipse.ui.commands">
		<command
			description="Open the quick outline."
			id="org.eclipse.xtext.ui.editor.outline.QuickOutline"
			name="Quick Outline">
		</command>
	</extension>
	<extension point="org.eclipse.ui.menus">
		<menuContribution
			locationURI="popup:#TextEditorContext?after=group.open">
			<command commandId="org.eclipse.xtext.ui.editor.outline.QuickOutline"
				style="push"
				tooltip="Open Quick Outline">
				<visibleWhen checkEnabled="false">
					<reference definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened"/>
				</visibleWhen>
			</command>
		</menuContribution>
	</extension>
	<!-- quickfix marker resolution generator for org.xtext.example.mydsl.MyDsl -->
	<extension
			point="org.eclipse.ui.ide.markerResolution">
		<markerResolutionGenerator
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator"
			markerType="org.xtext.example.mydsl.ui.mydsl.check.fast">
			<attribute
				name="FIXABLE_KEY"
				value="true">
			</attribute>
		</markerResolutionGenerator>
		<markerResolutionGenerator
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator"
			markerType="org.xtext.example.mydsl.ui.mydsl.check.normal">
			<attribute
				name="FIXABLE_KEY"
				value="true">
			</attribute>
		</markerResolutionGenerator>
		<markerResolutionGenerator
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.quickfix.MarkerResolutionGenerator"
			markerType="org.xtext.example.mydsl.ui.mydsl.check.expensive">
			<attribute
				name="FIXABLE_KEY"
				value="true">
			</attribute>
		</markerResolutionGenerator>
	</extension>
	<!-- Rename Refactoring -->
	<extension point="org.eclipse.ui.handlers">
		<handler 
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.refactoring.ui.DefaultRenameElementHandler"
			commandId="org.eclipse.xtext.ui.refactoring.RenameElement">
			<activeWhen>
				<reference
					definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
				</reference>
			</activeWhen>
		</handler>
	</extension>
	<extension point="org.eclipse.ui.menus">
		<menuContribution
			locationURI="popup:#TextEditorContext?after=group.edit">
			<command commandId="org.eclipse.xtext.ui.refactoring.RenameElement"
				style="push">
				<visibleWhen checkEnabled="false">
					<reference
						definitionId="org.xtext.example.mydsl.MyDsl.Editor.opened">
					</reference>
				</visibleWhen>
			</command>
		</menuContribution>
	</extension>
	<extension point="org.eclipse.ui.preferencePages">
		<page
			category="org.xtext.example.mydsl.MyDsl"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.refactoring.ui.RefactoringPreferencePage"
			id="org.xtext.example.mydsl.MyDsl.refactoring"
			name="Refactoring">
			<keywordReference id="org.xtext.example.mydsl.ui.keyword_MyDsl"/>
		</page>
	</extension>
	<extension point="org.eclipse.compare.contentViewers">
		<viewer id="org.xtext.example.mydsl.MyDsl.compare.contentViewers"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.compare.InjectableViewerCreator"
			extensions="mydsl">
		</viewer>
		<contentTypeBinding
			contentTypeId="org.xtext.example.mydsl.MyDsl.contenttype"
			contentViewerId="org.xtext.example.mydsl.MyDsl.compare.contentViewers" />
	</extension>
	<extension point="org.eclipse.compare.contentMergeViewers">
		<viewer id="org.xtext.example.mydsl.MyDsl.compare.contentMergeViewers"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.compare.InjectableViewerCreator"
			extensions="mydsl" label="MyDsl Compare">
		</viewer>
		<contentTypeBinding
			contentTypeId="org.xtext.example.mydsl.MyDsl.contenttype"
			contentMergeViewerId="org.xtext.example.mydsl.MyDsl.compare.contentMergeViewers" />
	</extension>
	<extension point="org.eclipse.ui.editors.documentProviders">
		<provider id="org.xtext.example.mydsl.MyDsl.editors.documentProviders"
			class="org.xtext.example.mydsl.ui.MyDslExecutableExtensionFactory:org.eclipse.xtext.ui.editor.model.XtextDocumentProvider"
			extensions="mydsl">
		</provider>
	</extension>
	<extension point="org.eclipse.team.core.fileTypes">
		<fileTypes
			extension="mydsl"
			type="text">
		</fileTypes>
	</extension>
 <extension
       point="org.eclipse.ui.ide.editorAssociationOverride">
    <editorAssociationOverride
          class="org.xtext.example.mydsl.ui.CustomEditorAssociationOverride"
          id="org.xtext.example.mydsl.ui.customEditorAssociationOverride">
    </editorAssociationOverride>
 </extension>
</plugin>


CustomEditorAssociationOverride.java

package org.xtext.example.mydsl.ui;

import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.ide.IEditorAssociationOverride;

public class CustomEditorAssociationOverride implements IEditorAssociationOverride {

	public CustomEditorAssociationOverride() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		return editorDescriptors;
	}

	@Override
	public IEditorDescriptor[] overrideEditors(String fileName, IContentType contentType,
			IEditorDescriptor[] editorDescriptors) {
		// TODO Auto-generated method stub
		return editorDescriptors;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		return editorDescriptor;
	}

	@Override
	public IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType,
			IEditorDescriptor editorDescriptor) {
		// TODO Auto-generated method stub
		return editorDescriptor;
	}

}


Model file:
Cont container1 {	
	Item item1
	
}

Cont container2 {
	Item item2
}  

Link item1 OF container1 TO item2 OF container2



Thanks for your continuous help.

Thanks and regards,
Virag Purnam
Re: How to open model file in text editor programmatically [message #1807316 is a reply to message #1807314] Tue, 28 May 2019 04:57 Go to previous messageGo to next message
Christian Dietrich is currently online Christian DietrichFriend
Messages: 13067
Registered: July 2009
Senior Member
i still cannot reproduce.
if i create a mydsl file the override class will be asked


Need professional support for Xtext, Xpand, EMF?
Go to: https://www.itemis.com/en/xtext/
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Re: How to open model file in text editor programmatically [message #1807317 is a reply to message #1807316] Tue, 28 May 2019 05:10 Go to previous message
Virag Purnam is currently offline Virag PurnamFriend
Messages: 107
Registered: June 2014
Senior Member
Ok.
I will check again.
Thanks for your reply.

Regards,
Virag Purnam

[Updated on: Tue, 28 May 2019 05:11]

Report message to a moderator

Previous Topic:Xtext - how to extend XtextDocument class
Next Topic:Call quickfix validation from Problems View
Goto Forum:
  


Current Time: Tue Aug 20 18:17:42 GMT 2019

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

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

Back to the top