Home » Modeling » TMF (Xtext) » Xtext Save Action
|
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
|
|
| | | | | | | |
Goto Forum:
Current Time: Tue Sep 24 20:28:46 GMT 2024
Powered by FUDForum. Page generated in 0.05732 seconds
|