Xtext Save Action [message #1059783] |
Tue, 21 May 2013 15:06 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi all,
I write a code in the Xtext save method.I have problem:
1:Auto Complision is not active in the editor.
2.I can not Ctrl+Z
3-My cursor is in the beginning of the editor every time.
4-I can not trim mymodel.getDisplayName().if I trim it ,changes not do.
@Override
public void afterSave(XtextEditor editor) {
// TODO Auto-generated method stub
IXtextDocument myDocument = editor.getDocument();
myDocument.modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource res) throws Exception {
ContentModel mymodel =(ContentModel) res.getContents().get(0);
mymodel.setName(mymodel.getDisplayName().toString().intern());
System.out.println(mymodel.getDisplayName().toString());
return null;
}
});
Best Regrads,
[Updated on: Tue, 21 May 2013 15:06] Report message to a moderator
|
|
|
Re: Xtext Save Action [message #1059797 is a reply to message #1059783] |
Tue, 21 May 2013 16:02 |
|
Hi,
i dont understand 1 2 and 3
4 works fine for me
package org.xtext.example.mydsl.ui;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.xtext.builder.nature.NatureAddingEditorCallback;
import org.eclipse.xtext.resource.XtextResource;
import org.eclipse.xtext.ui.editor.XtextEditor;
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
import org.xtext.example.mydsl.myDsl.Greeting;
import org.xtext.example.mydsl.myDsl.Model;
public class MyDslEditorCallback extends NatureAddingEditorCallback {
@Override
public void afterSave(XtextEditor editor) {
System.out.println("here we go");
editor.getDocument().modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state) throws Exception {
for (Greeting g : ((Model)state.getContents().get(0)).getGreetings()) {
g.setName(g.getName().toUpperCase());
}
return null;
}
});
if (isDirty()) {
editor.doSave(new NullProgressMonitor());
}
super.afterSave(editor);
}
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
Re: Xtext Save Action [message #1059956 is a reply to message #1059896] |
Wed, 22 May 2013 11:00 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
I bind NatureAddingEditorCallback in the UI.but not works,I do not bind it ?
@Override
public Class<? extends org.eclipse.xtext.ui.editor.IXtextEditorCallback> bindIXtextEditorCallback() {
return org.eclipse.xtext.builder.nature.NatureAddingEditorCallback.class;
}
public Class<? extends EditorCallback> bindModulefileBuilder() {
return EditorCallback.class;
}
Best regards,
[Updated on: Wed, 22 May 2013 11:07] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: Xtext Save Action [message #1060324 is a reply to message #1060323] |
Fri, 24 May 2013 07:19 |
|
Hi I still do not get it why you traverse the model from the starting
point and look for all places that are from interest for you. This is
not at all Xtext specific. If you have A and B and A has a b B you'd
call a.getB()
?!?
--
Need training, onsite consulting or any other kind of help for Xtext?
Go visit http://xtext.itemis.com or send a mail to xtext at itemis dot de
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
Re: Xtext Save Action [message #1060327 is a reply to message #1060324] |
Fri, 24 May 2013 07:30 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian ,
I understand you ,but I define ContentUnit in the grammar ,ContentUnit returns ContentUnit:
ContentModel | WebApplication | SiteCollection | Web | CustomList | ContentType | Field | View;
I write my code :
if(mymodel.getDisplayName().equals(null) || mymodel.getDisplayName().equals("")){
mymodel.setDisplayName(mymodel.getName());
mymodel.getOwnedWebApplication().setDisplayName(mymodel.getOwnedWebApplication().getName());
}
Must I do for every element ?
[Updated on: Fri, 24 May 2013 07:30] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Xtext Save Action [message #1060718 is a reply to message #1060715] |
Tue, 28 May 2013 08:44 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
I want to do Create an element,its default fields are created automatically such as my grammar :
ContentType returns ContentType:
'ContentType'
name=QualifiedName
'{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('description' '=' description=STRING)?
('group' '=' group=STRING)?
('parent' '=' parentContentType=[ContentType|QualifiedName])?
(ownedField+=Field (ownedField+=Field)*)?
'}';
Field returns Field:
LookUp | BooleanField | TextField | NumberField;
TextField returns TextField:
'Text' name=QualifiedName '{'
'guID' '=' guID=STRING
'displayName' '=' displayName=STRING
('required' '=' required=EBoolean)?
('unlimitedLenghtInDocumentLibraries' '=' unlimitedLenghtInDocumentLibraries=EBoolean)?
('description' '=' description=STRING)?
('group' '=' group=STRING)?
('default' '=' default=STRING)?
('displaySize' '=' displaySize=INT)?
('maxLength' '=' maxLength=INT)?
'}';
My grammar is below.When I create a contenttype ,ContentType's Fields are created automatically:ownedField+=Field (ownedField+=Field)*)?
When I create ContentType below Text Field is created automatically in the Xtext Editor.User may change its property onlly.I hope ,I can explain my problem.
Text text {
guID = "guID"
displayName="bollty u" required = true unlimitedLenghtInDocumentLibraries= false default = "Default"
}
[Updated on: Tue, 28 May 2013 08:45] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Re: Xtext Save Action [message #1060763 is a reply to message #1060755] |
Tue, 28 May 2013 11:46 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Thank you for help .I try it.My problem may be solved
I written code in the public class MyXtextDocumentProvider extends XtextDocumentProvider{
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
super.doSaveDocument(monitor, element, document, overwrite);
}
protected boolean createNewEntity(Entity sibling, String name) {
Entity newEntity = DomainmodelFactory.eINSTANCE.createEntity();
newEntity.setName(name);
return addTypeAsSibling(sibling, newEntity);
}
protected boolean createNewDatatype(Entity sibling, String name) {
DataType newDatatype = DomainmodelFactory.eINSTANCE.createDataType();
newDatatype.setName(name);
return addTypeAsSibling(sibling, newDatatype);
}
protected boolean addTypeAsSibling(Entity sibling, Type newType) {
EObject container = sibling.eContainer();
EList<AbstractElement> elements = null;
if (container instanceof PackageDeclaration) {
elements = ((PackageDeclaration) container).getElements();
} else if (container instanceof DomainModel) {
elements = ((DomainModel) container).getElements();
} else {
return false;
}
int index = elements.indexOf(sibling) + 1;
elements.add(index, newType);
return true;
}
}
|
|
|
|
Re: Xtext Save Action [message #1060803 is a reply to message #1060775] |
Tue, 28 May 2013 13:13 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
No .not solved my problem.I will try XtextDocumentProvider.doSaveDocument.
but I want to use org.eclipse.xtext.ui.editor.model.edit.ISemanticModification in the XtextDocumentProvider.I do not use :(How can I solved my problem.
I want to try below code in the XtextDocumentProvider with Save action:
@Fix(DomainmodelLinkingDiagnosticMessageProvider.MISSING_REFERENCE_TYPE)
public void createReferenceType(final Issue issue, IssueResolutionAcceptor acceptor) {
final String linkText = issue.getData()[0];
acceptor.accept(issue, "Create entity '" + linkText + "'", "Create entity '" + linkText + "'", null,
new ISemanticModification() {
public void apply(final EObject element, IModificationContext context) {
createNewEntity((Entity) element.eContainer().eContainer(), linkText);
}
});
createLinkingIssueResolutions(issue, acceptor);
}
protected boolean createNewEntity(Entity sibling, String name) {
Entity newEntity = DomainmodelFactory.eINSTANCE.createEntity();
newEntity.setName(name);
return addTypeAsSibling(sibling, newEntity);
}
protected boolean createNewDatatype(Entity sibling, String name) {
DataType newDatatype = DomainmodelFactory.eINSTANCE.createDataType();
newDatatype.setName(name);
return addTypeAsSibling(sibling, newDatatype);
}
protected boolean addTypeAsSibling(Entity sibling, Type newType) {
EObject container = sibling.eContainer();
EList<AbstractElement> elements = null;
if (container instanceof PackageDeclaration) {
elements = ((PackageDeclaration) container).getElements();
} else if (container instanceof DomainModel) {
elements = ((DomainModel) container).getElements();
} else {
return false;
}
int index = elements.indexOf(sibling) + 1;
elements.add(index, newType);
return true;
}
|
|
|
|
|
|
Re: Xtext Save Action [message #1060819 is a reply to message #1060812] |
Tue, 28 May 2013 14:02 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
not works it .I must do When User create Contenttype,textfield created in it .Hense Save action may not solved my problem.
public class MyXtextDocumentProvider extends XtextDocumentProvider{
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
super.doSaveDocument(monitor, element, document, overwrite);
//boolean createNewEntity(Field sibling, String name) {
TextField newEntity = MyDslFactory.eINSTANCE.createTextField();
newEntity.setName("text");
System.out.println("....");
//}
}
I want to Which class detect which elements.hence When User create Contenttype ,I will do change after contenttype is created
[Updated on: Tue, 28 May 2013 14:31] Report message to a moderator
|
|
|
|
Re: Xtext Save Action [message #1060840 is a reply to message #1060836] |
Tue, 28 May 2013 15:33 |
|
Cant you simply
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
((IXtextDocument)document).modify(....)// ; stuff you should already have
super.doSaveDocument(monitor, element, document, overwrite);
}
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
Re: Xtext Save Action [message #1060879 is a reply to message #1060840] |
Tue, 28 May 2013 19:56 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian ,
I write code now,but not fineshed.
public class MyXtextDocumentProvider extends XtextDocumentProvider{
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
super.doSaveDocument(monitor, element, document, overwrite);
((IXtextDocument)document).modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state) throws Exception {
org.xtext.example.mydsl.myDsl.ContentType newElement = org.xtext.example.mydsl.myDsl.MyDslFactory.eINSTANCE
.createContentType();
TextField text = MyDslFactory.eINSTANCE.createTextField();
text.setName("text");
text.setDisplayName("text");
newElement.getOwnedField().add(text);
TextField created = MyDslFactory.eINSTANCE.createTextField();
created.setName("created");
created.setDisplayName("created");
newElement.getOwnedField().add(created);
TextField createdBy = MyDslFactory.eINSTANCE.createTextField();
createdBy.setName("createdBy");
createdBy.setDisplayName("created By");
newElement.getOwnedField().add(createdBy);
return null;
}
} );
my problem is added elements index and When user create a contenttype,such as Text text is created automatically.
|
|
|
Re: Xtext Save Action [message #1060932 is a reply to message #1060840] |
Wed, 29 May 2013 08:27 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
I do not solved my problem.
my code is below:
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
super.doSaveDocument(monitor, element, document, overwrite);
((IXtextDocument)document).modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state) throws Exception {
ContentType newElement = MyDslFactory.eINSTANCE.createContentType();
state.getContents().set(0 ,MyDslFactory.eINSTANCE.createTextField() );
MyDslPackage.eINSTANCE.eClass();
MyDslFactory factory = MyDslFactory.eINSTANCE;
TextField newEntity = MyDslFactory.eINSTANCE.createTextField();
newEntity.setName("text");
newEntity.setDisplayName("text");
newElement.getOwnedField().add(newEntity);
return null;
}
} );
}
I receive an error :
Save Failed
These errors need to be fixed before the model can be serialized.
TextField: Feature TextField.displayName must be set. Constraint: (name displayName) Quantities: displayName:0, name:0
TextField: Feature TextField.name must be set. Constraint: (name guID) Quantities: guID:1, name:0
Best regards,
|
|
|
|
|
|
|
Re: Xtext Save Action [message #1061016 is a reply to message #1060932] |
Wed, 29 May 2013 14:11 |
junior developer Messages: 354 Registered: January 2013 |
Senior Member |
|
|
Hi Christian,
I understand you,but This code is not work,same as EMF changes.Solved my problem with this method (below).is there a class for this problem.One User create an element,such as contenttype,created own default fields automatically.I could try another methor or class.
junior developer wrote on Wed, 29 May 2013 04:27Hi Christian,
I do not solved my problem.
my code is below:
@Override
protected void doSaveDocument(IProgressMonitor monitor, Object element,
IDocument document, boolean overwrite) throws CoreException {
super.doSaveDocument(monitor, element, document, overwrite);
((IXtextDocument)document).modify(new IUnitOfWork<Void, XtextResource>() {
@Override
public java.lang.Void exec(XtextResource state) throws Exception {
ContentType newElement = MyDslFactory.eINSTANCE.createContentType();
state.getContents().set(0 ,MyDslFactory.eINSTANCE.createTextField() );
MyDslPackage.eINSTANCE.eClass();
MyDslFactory factory = MyDslFactory.eINSTANCE;
TextField newEntity = MyDslFactory.eINSTANCE.createTextField();
newEntity.setName("text");
newEntity.setDisplayName("text");
newElement.getOwnedField().add(newEntity);
return null;
}
} );
}
I receive an error :
Save Failed
These errors need to be fixed before the model can be serialized.
TextField: Feature TextField.displayName must be set. Constraint: (name displayName) Quantities: displayName:0, name:0
TextField: Feature TextField.name must be set. Constraint: (name guID) Quantities: guID:1, name:0
Best regards,
|
|
|
Re: Xtext Save Action [message #1061021 is a reply to message #1061016] |
Wed, 29 May 2013 14:28 |
|
Hi,
why call super.doSaveDocument(monitor, element, document, overwrite);
first and the modify it, id do it the other way round.
state.getContents().set(0 ,MyDslFactory.eINSTANCE.createTextField() );
this textfield has no name and description .
why do you want to change the root at alle.
id do something like
MyRootClass root = (MyRootClass )state.getContents().get(0);
//work with the root,
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
|
|
|
|
|
|
|
|
|
|