Commit 8581cb0f authored by Johannes Roith's avatar Johannes Roith

add markers and outline.

parent 2bc0f620
......@@ -34,5 +34,15 @@
extensions="cup">
</participant>
</extension>
<extension
id="org.tum.in.www2.cupplugin.markers.problem"
point="org.eclipse.core.resources.markers">
<super
type="org.eclipse.core.resources.problemmarker">
</super>
<persistent
value="true">
</persistent>
</extension>
</plugin>
......@@ -24,7 +24,7 @@ public class Controller {
private final Object lock = new Object();
/*
* Static singelton getter
* Static singleton getter
*/
public static Controller getInstance(IDocument doc) {
Controller instance = instances.get(doc);
......
package de.tum.in.www2.cupplugin.controller;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
......@@ -28,10 +29,7 @@ public class DocumentDidChangeJob extends Job {
/*
* TODO: Job bestücken, vll mit callbacks
*/
//nichts mehr ändern ab hier
iAmCurrentlyRunning = false;
CallbackJob cb = new CallbackJob(myDocument);
......
package de.tum.in.www2.cupplugin.editors;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.DocumentEvent;
import org.eclipse.jface.text.IDocumentListener;
......@@ -7,11 +10,41 @@ import de.tum.in.www2.cupplugin.controller.Controller;
class CTEDocumentListener implements IDocumentListener {
private IFile file;
public CTEDocumentListener(IFile file) {
this.file = file;
}
public void documentAboutToBeChanged(DocumentEvent event) {
return;
}
public void documentChanged(DocumentEvent event) {
// TODO: does not belong here...
try {
// file.findMarker();
IMarker marker;
marker = file.createMarker("org.tum.in.www2.cupplugin.markers.problem");
marker.setAttribute(IMarker.SEVERITY, IMarker.SEVERITY_ERROR);
marker.setAttribute(IMarker.MESSAGE, "hello world from problem marker!");
marker.setAttribute(IMarker.LINE_NUMBER, 3);
// marker.delete();
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("starting job chain"); // Log message TODO: DELETE!
Controller controller = Controller.getInstance(event.getDocument());
controller.notifyChange();
......
package de.tum.in.www2.cupplugin.editors;
import org.eclipse.jface.viewers.IContentProvider;
import org.eclipse.jface.viewers.ILabelProvider;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
import org.eclipse.swt.widgets.MessageBox;
public class CupContentOutlinePage extends ContentOutlinePage {
class LabelProvider implements ILabelProvider {
public void addListener(ILabelProviderListener listener) {
}
public void dispose() {
}
public boolean isLabelProperty(Object element, String property) {
return true;
}
public void removeListener(ILabelProviderListener listener) {
}
public Image getImage(Object element) {
return null;
}
public String getText(Object element) {
return "hello";
}
}
class Entry {
public int id;
public Entry(int id) {
this.id = id;
}
}
class ContentProvider implements ITreeContentProvider {
public void dispose() {
}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
}
public Object[] getElements(Object inputElement) {
// handles the root object.
return getChildren(inputElement);
}
public Object[] getChildren(Object parentElement) {
int id = ((Entry) parentElement).id + 1;
return new Object[] { new Entry(id), new Entry(id+1) };
}
public Object getParent(Object element) {
return null;
}
public boolean hasChildren(Object element) {
if (((Entry) element).id < 10)
return true;
return false;
}
}
@Override
public void createControl(Composite parent) {
super.createControl(parent);
TreeViewer viewer = getTreeViewer();
viewer.setContentProvider(new ContentProvider());
viewer.setLabelProvider(new LabelProvider());
viewer.addSelectionChangedListener(this);
viewer.setInput(new Entry(3));
viewer.refresh();
viewer.expandAll();
}
}
......@@ -9,12 +9,15 @@ import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.editors.text.TextFileDocumentProvider;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
import java_cup.*;
import java_cup.runtime.ComplexSymbolFactory;
public class CupTextEditor extends TextEditor {
private CupContentOutlinePage outlinePage;
static Color blue = new Color (Display.getCurrent(), 0, 0, 255);
static Color green = new Color (Display.getCurrent(), 0, 255, 0);
static Color red = new Color (Display.getCurrent(), 255, 0, 0);
......@@ -31,7 +34,16 @@ public class CupTextEditor extends TextEditor {
// java_cup.Lexer = new java_cup.Lexer(arg0, f);
}
public Object getAdapter(Class required) {
if (IContentOutlinePage.class.equals(required)) {
if (outlinePage == null) {
outlinePage = new CupContentOutlinePage();
// getDocumentProvider(), this);
// outlinePage.setInput(getEditorInput());
}
return outlinePage;
}
return super.getAdapter(required);
}
}
......@@ -8,6 +8,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
......@@ -208,6 +209,8 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
boolean addHooksToMainTextEditor(ITextEditor editor) {
IFile file = ((FileEditorInput) editor.getEditorInput()).getFile();
// Add Document listener to react on changes
IDocumentProvider dp = editor.getDocumentProvider();
if(dp == null){
......@@ -217,7 +220,7 @@ public class MultiPageEditor extends MultiPageEditorPart implements IResourceCha
if(doc == null){
return false;
}
doc.addDocumentListener(new CTEDocumentListener());
doc.addDocumentListener(new CTEDocumentListener(file));
return true;
}
......
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