Commit 91f84c0c authored by Benedikt Engeser's avatar Benedikt Engeser

IDocument->CupTextEditor

parent 51607ef6
......@@ -5,18 +5,20 @@ import java.util.HashMap;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.jface.text.IDocument;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
public class Controller {
// The Job handling changes in a document is triggered after x seconds
static final int SET_CHANGED_AFTER_SECONDS = 3;
// Static reference to the controller instance per document
static HashMap<IDocument, Controller> instances = new HashMap<IDocument, Controller>();
static HashMap<CupTextEditor, Controller> instances = new HashMap<CupTextEditor, Controller>();
// attributes
// The Job that's executed after a document change is detected (changeJob)
private DocumentDidChangeJob myJob = null;
// the document, the instance is managing
private IDocument myDocument = null;
private CupTextEditor myEditor = null;
// if the changeJob takes some time, it's good to know if it has to be
// reexecuted after it finishes
private long changeJobReRunRequested = 0;
......@@ -26,22 +28,22 @@ public class Controller {
/*
* Static singleton getter
*/
public static Controller getInstance(IDocument doc) {
Controller instance = instances.get(doc);
public static Controller getInstance(CupTextEditor edit) {
Controller instance = instances.get(edit);
if (instance != null) {
return instance;
} else {
instances.put(doc, new Controller(doc));
return instances.get(doc);
instances.put(edit, new Controller(edit));
return instances.get(edit);
}
}
/*
* The Constructor, taking the document it's controlling as a parameter
* The Constructor, taking the editor it's controlling as a parameter
*/
public Controller(IDocument doc) {
myDocument = doc;
myJob = new DocumentDidChangeJob(doc);
public Controller(CupTextEditor editor) {
myEditor = editor;
myJob = new DocumentDidChangeJob(editor);
myJob.setSystem(true);
}
......
......@@ -17,16 +17,17 @@ import de.in.tum.www2.cup.DefaultErrorReporter;
import de.in.tum.www2.cup.LALRResult;
import de.in.tum.www2.cup.ast.ParserResult;
import de.in.tum.www2.cup.internal.internal_error;
import de.tum.in.www2.cupplugin.editors.CupTextEditor;
public class DocumentDidChangeJob extends Job {
boolean iAmCurrentlyRunning = false;
IDocument myDocument = null;
CupTextEditor myEditor = null;
public DocumentDidChangeJob(IDocument doc) {
super(""+ doc.hashCode());
myDocument = doc;
public DocumentDidChangeJob(CupTextEditor editor) {
super(""+ editor.hashCode());
myEditor = editor;
}
......@@ -40,7 +41,7 @@ public class DocumentDidChangeJob extends Job {
* TODO: Job bestücken, vll mit callbacks
*/
String codeText = myDocument.get();
String codeText = myEditor.get();
InputStream in = new ByteArrayInputStream(codeText.getBytes());
CupParser p = new CupParser(new DefaultErrorReporter(), in);
......@@ -74,7 +75,7 @@ public class DocumentDidChangeJob extends Job {
//nichts mehr ändern ab hier
iAmCurrentlyRunning = false;
CallbackJob cb = new CallbackJob(myDocument);
CallbackJob cb = new CallbackJob(myEditor);
cb.setSystem(true);
cb.schedule();
return Status.OK_STATUS;
......@@ -82,15 +83,15 @@ public class DocumentDidChangeJob extends Job {
class CallbackJob extends UIJob{
IDocument myDocument = null;
public CallbackJob(IDocument doc) {
super(""+ doc.hashCode());
myDocument = doc;
CupTextEditor myEditor = null;
public CallbackJob(CupTextEditor editor) {
super(""+ editor.hashCode());
myEditor = editor;
}
@Override
public IStatus runInUIThread(IProgressMonitor monitor) {
Controller.getInstance(myDocument).notifyChangeJobFinished();
Controller.getInstance(myEditor).notifyChangeJobFinished();
return Status.OK_STATUS;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment