| Xtext Save Action [message #1059783] |
Tue, 21 May 2013 11:06  |
junior developer Messages: 159 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 11:06] Report message to a moderator
|
|
|
|
|
|
|
|
| Re: Xtext Save Action [message #1059956 is a reply to message #1059896] |
Wed, 22 May 2013 07:00   |
junior developer Messages: 159 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 07:07] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| Re: Xtext Save Action [message #1060327 is a reply to message #1060324] |
Fri, 24 May 2013 03:30   |
junior developer Messages: 159 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 03:30] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Xtext Save Action [message #1060718 is a reply to message #1060715] |
Tue, 28 May 2013 04:44   |
junior developer Messages: 159 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 04:45] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
| Re: Xtext Save Action [message #1060763 is a reply to message #1060755] |
Tue, 28 May 2013 07:46   |
junior developer Messages: 159 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;
}
}
|
|
|