How to read the contents of the eclipse editor while editing/typing in it?
I am developing an Eclipse plugin which is required to read the contents of the editor every minute. So I want a button to start this process and one to stop it. Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
public class SampleHandler extends AbstractHandler {
int filename=0;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
for (int i=0; i<10;i++) {
/*MessageDialog.openInformation(
window.getShell(),
"TestEditorReader",
"Running in background"); */// function call to print in the window
PrintWriter writer = null;
try {
writer = new PrintWriter(filename+"file.txt", "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
filename++;
writer.println(getCurrentEditorContent()); // function call to store it in files
writer.close();
try {
Thread.sleep(10000);
}
catch (InterruptedException ie) {
}
}
return null;
}
public String getCurrentEditorContent() {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (!(editor instanceof ITextEditor)) return null;
ITextEditor ite = (ITextEditor)editor;
IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
return doc.get();
}
}
java eclipse plugins eclipse-plugin
add a comment |
I am developing an Eclipse plugin which is required to read the contents of the editor every minute. So I want a button to start this process and one to stop it. Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
public class SampleHandler extends AbstractHandler {
int filename=0;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
for (int i=0; i<10;i++) {
/*MessageDialog.openInformation(
window.getShell(),
"TestEditorReader",
"Running in background"); */// function call to print in the window
PrintWriter writer = null;
try {
writer = new PrintWriter(filename+"file.txt", "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
filename++;
writer.println(getCurrentEditorContent()); // function call to store it in files
writer.close();
try {
Thread.sleep(10000);
}
catch (InterruptedException ie) {
}
}
return null;
}
public String getCurrentEditorContent() {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (!(editor instanceof ITextEditor)) return null;
ITextEditor ite = (ITextEditor)editor;
IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
return doc.get();
}
}
java eclipse plugins eclipse-plugin
1
What does 'crashes' actually mean? But note that you must never callThread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something likeDisplay.timerExec
– greg-449
Jan 19 at 8:09
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
See this answer
– greg-449
Jan 19 at 8:25
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11
add a comment |
I am developing an Eclipse plugin which is required to read the contents of the editor every minute. So I want a button to start this process and one to stop it. Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
public class SampleHandler extends AbstractHandler {
int filename=0;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
for (int i=0; i<10;i++) {
/*MessageDialog.openInformation(
window.getShell(),
"TestEditorReader",
"Running in background"); */// function call to print in the window
PrintWriter writer = null;
try {
writer = new PrintWriter(filename+"file.txt", "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
filename++;
writer.println(getCurrentEditorContent()); // function call to store it in files
writer.close();
try {
Thread.sleep(10000);
}
catch (InterruptedException ie) {
}
}
return null;
}
public String getCurrentEditorContent() {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (!(editor instanceof ITextEditor)) return null;
ITextEditor ite = (ITextEditor)editor;
IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
return doc.get();
}
}
java eclipse plugins eclipse-plugin
I am developing an Eclipse plugin which is required to read the contents of the editor every minute. So I want a button to start this process and one to stop it. Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
Since I am new to plugin development I tried to work my way around a template given in eclipse. But the runtime application crashes.
public class SampleHandler extends AbstractHandler {
int filename=0;
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
//IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
for (int i=0; i<10;i++) {
/*MessageDialog.openInformation(
window.getShell(),
"TestEditorReader",
"Running in background"); */// function call to print in the window
PrintWriter writer = null;
try {
writer = new PrintWriter(filename+"file.txt", "UTF-8");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
filename++;
writer.println(getCurrentEditorContent()); // function call to store it in files
writer.close();
try {
Thread.sleep(10000);
}
catch (InterruptedException ie) {
}
}
return null;
}
public String getCurrentEditorContent() {
final IEditorPart editor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
.getActiveEditor();
if (!(editor instanceof ITextEditor)) return null;
ITextEditor ite = (ITextEditor)editor;
IDocument doc = ite.getDocumentProvider().getDocument(ite.getEditorInput());
return doc.get();
}
}
java eclipse plugins eclipse-plugin
java eclipse plugins eclipse-plugin
edited Jan 19 at 7:08
Mohammadreza Farahani
2,02331424
2,02331424
asked Jan 19 at 6:31
rp73rp73
12
12
1
What does 'crashes' actually mean? But note that you must never callThread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something likeDisplay.timerExec
– greg-449
Jan 19 at 8:09
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
See this answer
– greg-449
Jan 19 at 8:25
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11
add a comment |
1
What does 'crashes' actually mean? But note that you must never callThread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something likeDisplay.timerExec
– greg-449
Jan 19 at 8:09
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
See this answer
– greg-449
Jan 19 at 8:25
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11
1
1
What does 'crashes' actually mean? But note that you must never call
Thread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something like Display.timerExec
– greg-449
Jan 19 at 8:09
What does 'crashes' actually mean? But note that you must never call
Thread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something like Display.timerExec
– greg-449
Jan 19 at 8:09
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
See this answer
– greg-449
Jan 19 at 8:25
See this answer
– greg-449
Jan 19 at 8:25
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264661%2fhow-to-read-the-contents-of-the-eclipse-editor-while-editing-typing-in-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54264661%2fhow-to-read-the-contents-of-the-eclipse-editor-while-editing-typing-in-it%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
What does 'crashes' actually mean? But note that you must never call
Thread.sleep(10000)
in the user interface thread - this will make the entire UI lock up. Use something likeDisplay.timerExec
– greg-449
Jan 19 at 8:09
Thanks @greg-449, I am able to read from the editor without using the loop. I want to automatically extract the file every 10 seconds. I can type in the editor only once, and after that when I press the plugin button the entire application seems to get locked up. Can you please tell me how to use Display.timerExec?
– rp73
Jan 19 at 8:14
See this answer
– greg-449
Jan 19 at 8:25
@greg-449 Thanks a lot!!
– rp73
Jan 21 at 9:11