|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: xtext editor hanging for long time [message #1736766 is a reply to message #1736754] |
Fri, 01 July 2016 15:12 |
Sachin Samaram Messages: 271 Registered: April 2016 |
Senior Member |
|
|
Hi,
I have extended NatureAddingEditorCallback but on selecting yes/no from the dialog my code is not calling up. What could be the problem?
import org.eclipse.core.resources.IFile
import org.eclipse.core.resources.IWorkspace
import org.eclipse.core.resources.ResourcesPlugin
import org.eclipse.core.runtime.IPath
import org.eclipse.core.runtime.Path
import org.eclipse.xtext.ui.editor.IXtextEditorCallback
import org.eclipse.xtext.ui.editor.XtextEditor
import org.eclipse.xtext.builder.nature.NatureAddingEditorCallback
import org.eclipse.xtext.ui.util.DontAskAgainDialogs
import org.eclipse.xtext.builder.nature.Messages
import org.eclipse.jface.dialogs.IDialogConstants
import com.google.inject.Inject
import org.eclipse.xtext.builder.nature.ToggleXtextNatureAction
import org.eclipse.jface.dialogs.MessageDialogWithToggle
import org.eclipse.core.resources.IResource
class EditorOnSave extends NatureAddingEditorCallback implements IXtextEditorCallback {
private static final String ADD_XTEXT_NATURE = "add_xtext_nature";
@Inject
private ToggleXtextNatureAction toggleNature;
@Inject DontAskAgainDialogs dialogs;
override void afterCreatePartControl(XtextEditor editor) {
println(" afterCreatePartControl ###########################")
super.afterCreatePartControl(editor);
val IResource resource = editor.getResource();
if (resource != null && !toggleNature.hasNature(resource.getProject()) && resource.getProject().isAccessible()
&& !resource.getProject().isHidden()) {
val String title = Messages.NatureAddingEditorCallback_MessageDialog_Title;
val String message = Messages.NatureAddingEditorCallback_MessageDialog_Msg0 + resource.getProject().getName()
+ Messages.NatureAddingEditorCallback_MessageDialog_Msg1;
var boolean addNature = false;
if (MessageDialogWithToggle.PROMPT.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
val int userAnswer = dialogs.askUser(message, title, ADD_XTEXT_NATURE, editor.getEditorSite().getShell());
if (userAnswer == IDialogConstants.YES_ID) {
println("Yes ID clicked.....")
return;
} else if (userAnswer == IDialogConstants.CANCEL_ID) {
println("Cancel ID clicked.....")
return;
}
} else if (MessageDialogWithToggle.ALWAYS.equals(dialogs.getUserDecision(ADD_XTEXT_NATURE))) {
println("dialog ID clicked.....")
addNature = true;
}
if (addNature) {
toggleNature.toggleNature(null);
}
}
}
override afterSave(XtextEditor editor) {
val IWorkspace workspace= ResourcesPlugin.getWorkspace();
val IPath location= Path.fromOSString(editor.resource.rawLocation.toFile.getAbsolutePath());
val IFile ifile= workspace.getRoot().getFileForLocation(location);
GenerationHandler.exec(ifile)
}
override afterSetInput(XtextEditor xtextEditor) {}
override beforeDispose(XtextEditor editor) {}
override beforeSetInput(XtextEditor xtextEditor) {}
override onValidateEditorInputState(XtextEditor editor) {
return true
}
}
[Updated on: Fri, 01 July 2016 16:55] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06745 seconds