Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • deniz.cingoez/robocup-speechrec
  • t.dilger/robocup-speechrec
  • msterz/robocup-speechrec
  • patric.steckstor/robocup-speechrec
  • jennifer.lee/robocup-speechrec
  • jharin/robocup-speechrec
  • f.thiemer/robocup-speechrec
  • augustin.harter/robocup-speechrec
  • jleichert/robocup-speechrec
9 results
Show changes
Showing
with 0 additions and 1399 deletions
package hterhors.editor;
import hterhors.editor.scanners.ISRPartitionScanner;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.ui.editors.text.FileDocumentProvider;
public class ISRDocumentProvider extends FileDocumentProvider {
@Override
protected IDocument createDocument(Object element) throws CoreException {
IDocument document = super.createDocument(element);
if (document != null) {
IDocumentPartitioner partitioner = new FastPartitioner(
new ISRPartitionScanner(), new String[] {
ISRPartitionScanner.ISR_IGNORE,
ISRPartitionScanner.ISR_RULE,
});
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
}
return document;
}
/**
* @uml.property name="iSRPartitionScanner"
* @uml.associationEnd inverse="iSRDocumentProvider:hterhors.editor.scanners.ISRPartitionScanner"
*/
private ISRPartitionScanner isrPartitionScanner;
/**
* Getter of the property <tt>iSRPartitionScanner</tt>
* @return Returns the isrPartitionScanner.
* @uml.property name="iSRPartitionScanner"
*/
public ISRPartitionScanner getISRPartitionScanner() {
return isrPartitionScanner;
}
/**
* Setter of the property <tt>iSRPartitionScanner</tt>
* @param iSRPartitionScanner The isrPartitionScanner to set.
* @uml.property name="iSRPartitionScanner"
*/
public void setISRPartitionScanner(ISRPartitionScanner isrPartitionScanner) {
this.isrPartitionScanner = isrPartitionScanner;
}
}
\ No newline at end of file
package hterhors.editor;
import hterhors.Activator;
import hterhors.editor.markers.MarkerContainer;
import hterhors.editor.markers.MarkingErrorHandler;
import hterhors.editor.outline.EditorContentOutlinePage;
import java.io.File;
import java.util.ResourceBundle;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
import org.eclipse.ui.texteditor.ContentAssistAction;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
/**
* The main editor. Manages the Plugins Editor.
*
* @author Hendrik
*/
public class ISREditor extends TextEditor {
/**
* @uml.property name="colorManager"
* @uml.associationEnd
*/
private ColorManager colorManager;
/**
* @uml.property name="input"
*/
private IEditorInput input;
/**
* @uml.property name="outlinePage"
* @uml.associationEnd
*/
private EditorContentOutlinePage outlinePage;
public ISREditor() {
super();
new Activator();
colorManager = new ColorManager();
ISRDocumentProvider documentProvider = new ISRDocumentProvider();
ISRSourceViewerConfiguration svc = new ISRSourceViewerConfiguration(
colorManager, this);
setSourceViewerConfiguration(svc);
setDocumentProvider(documentProvider);
// if (vT == null) {
new ValidateThread().start();
// }
}
// static ValidateThread vT = null;
//
// private ValidateThread getThread() {
// if (vT == null) {
// return vT = new ValidateThread();
// }
// return vT;
//
// }
/**
* This thread calls validateAndMark() every 500 millisec. to validate the
* current Grammar. For efficient the validating is triggered in case of
* dirty editor-content.
*
* @author Hendrik
*
*/
class ValidateThread extends Thread {
@Override
public void run() {
boolean isDirty = true;
super.run();
while (true) {
try {
isDirty = ISREditor.this.getSite().getPage()
.getActiveEditor().isDirty()
&& ISREditor.this.getSite().getPage()
.getActiveEditor().getTitle() == getInputFile()
.getName();
} catch (NullPointerException e) {
}
try {
if (getInputDocument() != null && isDirty)
validateAndMark();
sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
@Override
public void dispose() {
colorManager.dispose();
if (outlinePage != null)
outlinePage.setInput(null);
super.dispose();
}
@Override
protected void doSetInput(IEditorInput newInput) throws CoreException {
super.doSetInput(newInput);
this.input = newInput;
if (outlinePage != null)
outlinePage.setInput(input);
validateAndMark();
}
@Override
protected void editorSaved() {
super.editorSaved();
if (outlinePage != null)
outlinePage.update();
this.setInput(input);
}
// ValidateThreadListener threadListener = new ValidateThreadListener();
public synchronized IDocument getInputDocument() {
try {
IDocument document = getDocumentProvider().getDocument(input);
return document;
} catch (NullPointerException e) {
return null;
}
// if (document != null) {
// document.addDocumentListener(new IDocumentListener() {
//
// @Override
// public void documentChanged(DocumentEvent event) {
// System.out.println("changed");
// // threadListener.run = true;
// // threadListener.run();
// }
//
// @Override
// public void documentAboutToBeChanged(DocumentEvent event) {
// System.out.println("changed2");
// }
// });
// }
}
// class ValidateThreadListener extends Thread {
//
// boolean run = true;
//
// @Override
// public void run() {
// super.run();
// while (run) {
// System.out.println(run);
// try {
// run = false;
// sleep(2000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// System.out.println(run);
// if (getInputDocument() != null && ISREditor.this.isDirty()) {
// if (!run) {
// System.out.println("VALIDATE");
// // validateAndMark();
// }
// }
// }
// }
// }
/**
* Triggers the validation of the current grammar.
*
*/
public synchronized void validateAndMark() {
if (getInputDocument() != null
&& MarkerContainer.isDirty(getInputDocument().get())) {
MarkingErrorHandler markingErrorHandler = new MarkingErrorHandler(
getInputFile(), getInputDocument());
markingErrorHandler.removeExistingMarker();
markingErrorHandler.setCurrentMarker();
}
}
/**
* Returns the current input as an IFile object.
*
* @return File with the current grammar.
*/
protected synchronized IFile getInputFile() {
IFileEditorInput ife = (IFileEditorInput) input;
IFile file = ife.getFile();
return file;
}
/**
* Returns the current editor-input
*
* @return current editor-input.
* @uml.property name="input"
*/
public IEditorInput getInput() {
return input;
}
@Override
protected void createActions() {
super.createActions();
ResourceBundle bundle = Activator.getDefault().getResourceBundle();
setAction("ContentFormatProposal", new TextOperationAction(bundle,
"ContentFormatProposal.", this, ISourceViewer.FORMAT));
Action action = new ContentAssistAction(bundle,
"ContentAssistProposal.", this);
String id = ITextEditorActionDefinitionIds.CONTENT_ASSIST_PROPOSALS;
action.setActionDefinitionId(id);
setAction("ContentAssistProposal", action);
markAsStateDependentAction("ContentAssistProposal", true);
}
@Override
public Object getAdapter(Class required) {
if (IContentOutlinePage.class.equals(required)) {
if (outlinePage == null) {
outlinePage = new EditorContentOutlinePage(this);
if (getEditorInput() != null)
outlinePage.setInput(getEditorInput());
}
return outlinePage;
}
return super.getAdapter(required);
}
}
\ No newline at end of file
package hterhors.editor;
import hterhors.Activator;
import java.util.ResourceBundle;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.editors.text.TextEditorActionContributor;
import org.eclipse.ui.part.EditorActionBarContributor;
import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.RetargetTextEditorAction;
/**
* Manages the installation and deinstallation of actions for the editor.
*/
public class ISREditorContributor extends TextEditorActionContributor {
protected RetargetTextEditorAction contentAssistProposal;
protected RetargetTextEditorAction contentAssistTip;
protected RetargetTextEditorAction formatProposal;
/**
* Constructor for SQLEditorContributor. Creates a new contributor in the
* form of adding Content Assist, Conent Format and Assist tip menu items
*/
public ISREditorContributor() {
super();
ResourceBundle bundle = Activator.getDefault()
.getResourceBundle();
contentAssistProposal = new RetargetTextEditorAction(bundle,
"ContentAssistProposal.");
formatProposal = new RetargetTextEditorAction(bundle,
"ContentFormatProposal.");
contentAssistTip = new RetargetTextEditorAction(bundle,
"ContentAssistTip.");
}
public void contributeToMenu(IMenuManager mm) {
super.contributeToMenu(mm);
IMenuManager editMenu = mm
.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null) {
editMenu.add(new Separator());
editMenu.add(contentAssistProposal);
editMenu.add(formatProposal);
editMenu.add(contentAssistTip);
}
}
/**
* Sets the active editor to this contributor. This updates the actions to
* reflect the editor.
*
* @see EditorActionBarContributor#editorChanged
*/
public void setActiveEditor(IEditorPart part) {
super.setActiveEditor(part);
ITextEditor editor = null;
if (part instanceof ITextEditor)
editor = (ITextEditor) part;
contentAssistProposal.setAction(getAction(editor,
"ContentAssistProposal"));
formatProposal.setAction(getAction(editor, "ContentFormatProposal"));
contentAssistTip.setAction(getAction(editor, "ContentAssistTip"));
}
/**
*
* Contributes to the toolbar.
*
* @see EditorActionBarContributor#contributeToToolBar
*/
public void contributeToToolBar(IToolBarManager tbm) {
super.contributeToToolBar(tbm);
tbm.add(new Separator());
}
}
\ No newline at end of file
/*
* Created on Oct 10, 2004
*/
package hterhors.editor;
import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITypedRegion;
import org.eclipse.jface.text.rules.FastPartitioner;
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
/**
* Helper class for programmers. Use this class in ISRDocumentProvider instead
* of the FastPartitioner to display the partitions.
*
* @author Hendrik
*
*/
public class ISRPartitioner extends FastPartitioner {
public ISRPartitioner(IPartitionTokenScanner scanner,
String[] legalContentTypes) {
super(scanner, legalContentTypes);
}
public ITypedRegion[] computePartitioning(int offset, int length,
boolean includeZeroLengthPartitions) {
return super.computePartitioning(offset, length,
includeZeroLengthPartitions);
}
public void connect(IDocument document, boolean delayInitialization) {
super.connect(document, delayInitialization);
printPartitions(document);
}
public void printPartitions(IDocument document) {
StringBuffer buffer = new StringBuffer();
ITypedRegion[] partitions = computePartitioning(0, document.getLength());
for (int i = 0; i < partitions.length; i++) {
try {
buffer.append("Partition type: " + partitions[i].getType()
+ ", offset: " + partitions[i].getOffset()
+ ", length: " + partitions[i].getLength());
buffer.append("\n");
buffer.append("Text:\n");
buffer.append(document.get(partitions[i].getOffset(),
partitions[i].getLength()));
buffer.append("\n---------------------------\n\n\n");
} catch (BadLocationException e) {
e.printStackTrace();
}
}
System.out.print(buffer);
}
}
\ No newline at end of file
package hterhors.editor;
import hterhors.editor.format.DefaultFormattingStrategy;
import hterhors.editor.format.IgnoreFormattingStrategy;
import hterhors.editor.format.RuleFormattingStrategy;
import hterhors.editor.hoverinfos.GenerateHoverInfos;
import hterhors.editor.hoverinfos.IISRAnnontationHover;
import hterhors.editor.hyperlink.IsrHyperLinkDetector;
import hterhors.editor.scanners.ISRPartitionScanner;
import hterhors.editor.scanners.ISRSyntaxScanner;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.ITextDoubleClickStrategy;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.text.TextAttribute;
import org.eclipse.jface.text.contentassist.ContentAssistEvent;
import org.eclipse.jface.text.contentassist.ContentAssistant;
import org.eclipse.jface.text.contentassist.ICompletionListener;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.jface.text.contentassist.IContentAssistant;
import org.eclipse.jface.text.formatter.ContentFormatter;
import org.eclipse.jface.text.formatter.IContentFormatter;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
import org.eclipse.jface.text.presentation.IPresentationReconciler;
import org.eclipse.jface.text.presentation.PresentationReconciler;
import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.texteditor.ITextEditor;
/**
* @author Hendrik
*/
public class ISRSourceViewerConfiguration extends SourceViewerConfiguration {
/**
* @uml.property name="doubleClickStrategy"
* @uml.associationEnd
*/
private DoubleClickStrategy doubleClickStrategy;
/**
* @uml.property name="scanner"
* @uml.associationEnd
*/
private ISRSyntaxScanner scanner;
/**
* @uml.property name="colorManager"
* @uml.associationEnd
*/
private ColorManager colorManager;
/**
* @uml.property name="editor"
* @uml.associationEnd
*/
private ISREditor editor;
public ISRSourceViewerConfiguration(ColorManager colorManager,
ISREditor editor) {
this.colorManager = colorManager;
this.editor = editor;
}
@Override
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
ISRPartitionScanner.ISR_IGNORE, ISRPartitionScanner.ISR_RULE, };
}
@Override
public ITextDoubleClickStrategy getDoubleClickStrategy(
ISourceViewer sourceViewer, String contentType) {
if (doubleClickStrategy == null)
doubleClickStrategy = new DoubleClickStrategy();
return doubleClickStrategy;
}
/**
* Returns the ISRSyntaxScanner. If scanner is null it will be created.
*
* @return The current ISRSyntaxScanner
*
*/
private ISRSyntaxScanner getISRSyntaxScanner() {
if (scanner == null) {
scanner = new ISRSyntaxScanner(colorManager);
scanner.setDefaultReturnToken(new Token(new TextAttribute(
colorManager.getColor(IISRColorConstants.DEFAULT))));
}
return scanner;
}
@Override
public IPresentationReconciler getPresentationReconciler(
ISourceViewer sourceViewer) {
PresentationReconciler reconciler = new PresentationReconciler();
DefaultDamagerRepairer dr = new DefaultDamagerRepairer(
getISRSyntaxScanner());
reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
dr = new DefaultDamagerRepairer(getISRSyntaxScanner());
reconciler.setDamager(dr, ISRPartitionScanner.ISR_IGNORE);
reconciler.setRepairer(dr, ISRPartitionScanner.ISR_IGNORE);
dr = new DefaultDamagerRepairer(getISRSyntaxScanner());
reconciler.setDamager(dr, ISRPartitionScanner.ISR_RULE);
reconciler.setRepairer(dr, ISRPartitionScanner.ISR_RULE);
dr = new DefaultDamagerRepairer(getISRSyntaxScanner());
return reconciler;
}
@Override
public IContentAssistant getContentAssistant(ISourceViewer sv) {
ContentAssistant ca = new ContentAssistant();
final ISRContentAssistantRuleProcessor carp = new ISRContentAssistantRuleProcessor();
final ISRContentAssistantIgnoreRuleProcessor cairp = new ISRContentAssistantIgnoreRuleProcessor();
final ISRContentAssistantDefaultProcessor cadp = new ISRContentAssistantDefaultProcessor();
ca.setContentAssistProcessor(carp, ISRPartitionScanner.ISR_RULE);
ca.setContentAssistProcessor(cairp, ISRPartitionScanner.ISR_IGNORE);
ca.setContentAssistProcessor(cadp, IDocument.DEFAULT_CONTENT_TYPE);
ca.setInformationControlCreator(getInformationControlCreator(sv));
ca.addCompletionListener(new ICompletionListener() {
@Override
public void selectionChanged(ICompletionProposal arg0, boolean arg1) {
}
@Override
public void assistSessionStarted(ContentAssistEvent arg0) {
((ISRContentAssistantRuleProcessor) carp)
.setOverride(getSelectedText(editor).length());
((ISRContentAssistantIgnoreRuleProcessor) cairp)
.setOverride(getSelectedText(editor).length());
((ISRContentAssistantDefaultProcessor) cadp)
.setOverride(getSelectedText(editor).length());
}
@Override
public void assistSessionEnded(ContentAssistEvent arg0) {
}
});
return ca;
}
/**
* Returns the current selected text from a specified editor.
*
* @param editor
* The Editor from which the selection should take.
* @return The current Selection
*/
private String getSelectedText(ITextEditor editor) {
ISelection selection = editor.getSelectionProvider().getSelection();
return ((ITextSelection) selection).getText();
}
@Override
public IHyperlinkDetector[] getHyperlinkDetectors(ISourceViewer sourceViewer) {
return new IHyperlinkDetector[] { new IsrHyperLinkDetector(editor) };
}
@Override
public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
ContentFormatter formatter = new ContentFormatter();
RuleFormattingStrategy ruleFormattingStrategy = new RuleFormattingStrategy();
IgnoreFormattingStrategy ignoreFormattingStrategy = new IgnoreFormattingStrategy();
DefaultFormattingStrategy defaultFormattingStrategy = new DefaultFormattingStrategy();
formatter.setFormattingStrategy(defaultFormattingStrategy,
IDocument.DEFAULT_CONTENT_TYPE);
formatter.setFormattingStrategy(ignoreFormattingStrategy,
ISRPartitionScanner.ISR_IGNORE);
formatter.setFormattingStrategy(ruleFormattingStrategy,
ISRPartitionScanner.ISR_RULE);
return formatter;
}
@Override
public ITextHover getTextHover(ISourceViewer sourceViewer,
String contentType) {
return new GenerateHoverInfos(sourceViewer, contentType);
}
@Override
public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
super.getAnnotationHover(sourceViewer);
return new IISRAnnontationHover();
}
}
\ No newline at end of file
package hterhors.editor.format;
import org.eclipse.jface.text.formatter.IFormattingStrategy;
public class DefaultFormattingStrategy implements IFormattingStrategy {
protected static final String lineSeparator = System
.getProperty("line.separator");
public DefaultFormattingStrategy() {
super();
}
public void formatterStarts(String initialIndentation) {
}
public String format(String content, boolean isLineStart,
String indentation, int[] positions) {
content = content.replace(lineSeparator, " ");
content = content.replaceAll("\\s+", " ");
content = content.replace("\t", " ");
return content;
}
public void formatterStops() {
}
}
\ No newline at end of file
package hterhors.editor.format;
import org.eclipse.jface.text.formatter.IFormattingStrategy;
public class IgnoreFormattingStrategy implements IFormattingStrategy {
protected static final String lineSeparator = System
.getProperty("line.separator");
public IgnoreFormattingStrategy() {
super();
}
public void formatterStarts(String initialIndentation) {
}
public String format(String content, boolean isLineStart,
String indentation, int[] positions) {
return content.replace(lineSeparator, " ").replaceAll("\\s+", " ")
+ lineSeparator + lineSeparator;
}
public void formatterStops() {
}
}
\ No newline at end of file
package hterhors.editor.format;
import java.util.StringTokenizer;
import org.eclipse.jface.text.formatter.IFormattingStrategy;
public class RuleFormattingStrategy implements IFormattingStrategy {
protected static final String lineSeparator = System
.getProperty("line.separator");
public RuleFormattingStrategy() {
super();
}
public void formatterStarts(String initialIndentation) {
}
public String format(String content, boolean isLineStart,
String indentation, int[] positions) {
content = content.replace(lineSeparator, " ");
content = content.replaceAll("\\s+", " ");
content = content.replace("\t", " ");
StringTokenizer stringTokenizer = new StringTokenizer(content);
String space = "";
if (stringTokenizer.hasMoreTokens()) {
String token = stringTokenizer.nextToken();
for (int i = 0; i < token.length(); i++) {
space += " ";
}
}
content = content.replace("|", lineSeparator + space + "|");
content = content.replace(";", ";" + lineSeparator + lineSeparator);
return content;
}
public void formatterStops() {
}
}
\ No newline at end of file
package hterhors.editor.helper;
/**
* @author Hendrik
*/
public class Word {
/**
* @uml.property name="beginningOffset"
*/
private int beginningOffset = 0;
/**
* @uml.property name="endOffset"
*/
private int endOffset = 0;
/**
* @uml.property name="word"
*/
private StringBuffer word = new StringBuffer();
private String document;
private int offset;
/**
* @uml.property name="isNull"
*/
private boolean isNull;
public Word(int offset, String document) {
this.offset = offset;
this.document = document;
calculate();
}
/**
* @return
* @uml.property name="isNull"
*/
public boolean isNull() {
return isNull;
}
/**
* @return
* @uml.property name="beginningOffset"
*/
public int getBeginningOffset() {
return offset - beginningOffset;
}
/**
* @return
* @uml.property name="endOffset"
*/
public int getEndOffset() {
return offset + endOffset;
}
/**
* @return
* @uml.property name="word"
*/
public String getWord() {
return word.toString();
}
private void calculate() {
char c = document.charAt(offset);
if (Character.isWhitespace(c) || offset == 0) {
isNull = true;
return;
} else {
word.append(c);
}
while (true) {
beginningOffset++;
if (offset - beginningOffset >= 0) {
c = document.charAt(offset - beginningOffset);
if (Character.isWhitespace(c)) {
break;
} else {
word.append(c);
}
} else {
break;
}
}
word = word.reverse();
while (true) {
endOffset++;
if (offset + endOffset < document.length()) {
c = document.charAt(offset + endOffset);
if (Character.isWhitespace(c)) {
break;
} else {
word.append(c);
}
} else {
break;
}
}
}
}
\ No newline at end of file
package hterhors.editor.hoverinfos;
import hterhors.editor.helper.Word;
import hterhors.editor.markers.MarkerContainer;
import hterhors.editor.markers.ISRValidationObject;
import hterhors.editor.markers.IsrRuleValidator;
import java.util.StringTokenizer;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextHover;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.source.ISourceViewer;
public class GenerateHoverInfos implements ITextHover {
public GenerateHoverInfos(ISourceViewer sourceViewer, String contentType) {
}
@Override
public String getHoverInfo(ITextViewer viewer, IRegion region) {
String document = viewer.getDocument().get();
int regOff;
Word word = new Word(regOff = region.getOffset(), document);
if (word.isNull()) {
return null;
}
for (ISRValidationObject err : MarkerContainer.getErrors(document)) {
if (regOff >= err.getColumnStart() && regOff <= err.getColumnEnd()) {
return err.getErrorMessage();
}
}
for (ISRValidationObject warn : MarkerContainer.getWarnings(document)) {
if (regOff >= warn.getColumnStart()
&& regOff <= warn.getColumnEnd()) {
return warn.getErrorMessage();
}
}
boolean isIndex = false;
if (word.getWord().matches(IsrRuleValidator.NON_TERMINAL + "(;?|:?)")) {
String text = word.getWord().replace(";", "").replace(":", "");
int begin = document.indexOf(text);
do {
StringTokenizer stringTokenizer = new StringTokenizer(
document.substring(begin));
while (stringTokenizer.hasMoreTokens()) {
String cT = stringTokenizer.nextToken();
if (cT.matches(IsrRuleValidator.NON_TERMINAL_DECLARATION)) {
isIndex = true;
} else if (cT.matches(IsrRuleValidator.NON_TERMINAL)
&& stringTokenizer.hasMoreTokens()) {
if (stringTokenizer.nextToken().matches(
IsrRuleValidator.C)) {
isIndex = true;
}
}
break;
}
if (isIndex) {
break;
}
} while ((begin = document.indexOf(text, begin + text.length())) != -1
|| !isIndex);
StringTokenizer hoverInfo;
hoverInfo = new StringTokenizer(document.substring(begin), ";",
true);
if (hoverInfo.hasMoreTokens()) {
return "\nDeclaration: \n\n " + hoverInfo.nextToken() + " ;\n";
} else {
return null;
}
}
return null;
}
@Override
public IRegion getHoverRegion(ITextViewer viewer, int offset) {
return new Region(offset, 20);
}
}
package hterhors.editor.hoverinfos;
import java.util.Iterator;
import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.ui.texteditor.MarkerAnnotation;
public class IISRAnnontationHover implements IAnnotationHover {
@Override
public String getHoverInfo(ISourceViewer sourceViewer, int i) {
StringBuffer out = new StringBuffer();
boolean begin = true;
for (@SuppressWarnings("unchecked")
Iterator<MarkerAnnotation> iterator = (Iterator<MarkerAnnotation>) sourceViewer
.getAnnotationModel().getAnnotationIterator(); iterator
.hasNext();) {
try {
Object maO;
if ((maO = iterator.next()) instanceof MarkerAnnotation) {
MarkerAnnotation ma = (MarkerAnnotation) maO;
IMarker m = (IMarker) ma.getMarker();
Integer line = Integer.valueOf((Integer) m
.getAttribute(IMarker.LINE_NUMBER));
if (i+1 == line) {
if (!begin) {
out.append("\n");
}
out.append((String) m.getAttribute(IMarker.MESSAGE));
begin = false;
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (CoreException e) {
e.printStackTrace();
}
}
return out.toString();
}
}
package hterhors.editor.hyperlink;
import hterhors.editor.ISREditor;
import hterhors.editor.helper.Word;
import hterhors.editor.markers.IsrRuleValidator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.ITextViewer;
import org.eclipse.jface.text.Region;
import org.eclipse.jface.text.hyperlink.AbstractHyperlinkDetector;
import org.eclipse.jface.text.hyperlink.IHyperlink;
import org.eclipse.jface.text.hyperlink.IHyperlinkDetector;
/**
* @author Hendrik
*/
public class IsrHyperLinkDetector extends AbstractHyperlinkDetector implements IHyperlinkDetector {
/**
* @uml.property name="editor"
* @uml.associationEnd
*/
private ISREditor editor;
public IsrHyperLinkDetector() {
}
public IsrHyperLinkDetector(ISREditor editor) {
this.editor = editor;
}
public IHyperlink[] detectHyperlinks(ITextViewer textViewer,
IRegion region, boolean canShowMultipleHyperlinks) {
IDocument document = textViewer.getDocument();
Word word = new Word(region.getOffset(), document.get());
if (word.isNull() || !checkValidWord(word.getWord())) {
return null;
}
String text = word.getWord().replace(";", "").replaceAll(":","");
if (word.getBeginningOffset() < 0 || word.getEndOffset() < 0
|| word.getBeginningOffset() == word.getEndOffset() + 1) {
return null;
}
IRegion reg = new Region(word.getBeginningOffset() + 1, text
.length());
return new IHyperlink[] { new IsrHyperlink(reg, text, editor,
document) };
}
private boolean checkValidWord(String word) {
return word.matches(IsrRuleValidator.NON_TERMINAL + ";?");
}
}
package hterhors.editor.hyperlink;
import java.util.StringTokenizer;
import hterhors.editor.ISREditor;
import hterhors.editor.markers.IsrRuleValidator;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.hyperlink.IHyperlink;
/**
* Java element hyperlink.
* @since 3.1
*/
public class IsrHyperlink implements IHyperlink {
private String word;
private IRegion region;
/**
* @uml.property name="editor"
* @uml.associationEnd
*/
private ISREditor editor;
private String document;
public IsrHyperlink(IRegion region, String text, ISREditor editor,
IDocument document) {
this.editor = editor;
this.region = region;
this.word = text;
this.document = document.get();
}
public IRegion getHyperlinkRegion() {
return region;
}
public void open() {
boolean isIndex = false;
int begin = document.indexOf(word);
do {
StringTokenizer stringTokenizer = new StringTokenizer(
document.substring(begin));
while (stringTokenizer.hasMoreTokens()) {
String cT = stringTokenizer.nextToken();
if (cT.matches(IsrRuleValidator.NON_TERMINAL_DECLARATION)) {
isIndex = true;
} else if (cT.matches(IsrRuleValidator.NON_TERMINAL)
&& stringTokenizer.hasMoreTokens()) {
if (stringTokenizer.nextToken().matches(IsrRuleValidator.C)) {
isIndex = true;
}
}
break;
}
if (isIndex) {
break;
}
} while ((begin = document.indexOf(word, begin + word.length())) != -1
|| !isIndex);
editor.selectAndReveal(begin, word.length() + 1);
editor.setFocus();
}
public String getTypeLabel() {
return null;
}
public String getHyperlinkText() {
return null;
}
}
\ No newline at end of file
package hterhors.editor.info;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
public class InfoExampleHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ITextEditor textEditor = (ITextEditor) HandlerUtil
.getActiveEditor(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
Shell shell = HandlerUtil.getActiveShell(event);
MessageBox mb = new MessageBox(shell, SWT.SMOOTH);
mb.setText("General infos");
mb.setMessage(InfoStringGetter.infoStringGetter(getClass(),"/resources/info_example.txt"));
mb.open();
return null;
}
}
package hterhors.editor.info;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.handlers.HandlerUtil;
public class InfoFunctionalityHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Shell shell = HandlerUtil.getActiveShell(event);
MessageBox mb = new MessageBox(shell, SWT.SMOOTH);
mb.setText("Functionality infos");
mb.setMessage(InfoStringGetter.infoStringGetter(getClass(),"/resources/info_functionality.txt"));
mb.open();
return null;
}
}
package hterhors.editor.info;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
public class InfoGeneralHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ITextEditor textEditor = (ITextEditor) HandlerUtil
.getActiveEditor(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
Shell shell = HandlerUtil.getActiveShell(event);
MessageBox mb = new MessageBox(shell, SWT.SMOOTH);
mb.setText("General infos");
mb.setMessage(InfoStringGetter.infoStringGetter(getClass(),"/resources/info_general.txt"));
mb.open();
return null;
}
}
package hterhors.editor.info;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import org.eclipse.core.commands.AbstractHandler;
public class InfoStringGetter {
public static String infoStringGetter(
Class<? extends AbstractHandler> class1,String path) {
StringBuffer info = new StringBuffer();
String tmp;
InputStreamReader reader = null;
BufferedReader d = null;
try {
InputStream bis = null;
bis = class1.getResource(path)
.openStream();
reader = new InputStreamReader(bis);
d = new BufferedReader(reader);
while ((tmp = d.readLine()) != null)
info.append(tmp + "\n");
} catch (IOException e1) {
return "An error has accrued!\n Missing resources could be the trigger.";
} finally {
try {
if (d != null)
d.close();
} catch (IOException e) {
}
}
return info.toString();
}
}
package hterhors.editor.info;
import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.handlers.HandlerUtil;
import org.eclipse.ui.texteditor.ITextEditor;
public class InfoSyntaxHandler extends AbstractHandler {
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
ITextEditor textEditor = (ITextEditor) HandlerUtil
.getActiveEditor(event);
IEditorInput input = HandlerUtil.getActiveEditorInput(event);
Shell shell = HandlerUtil.getActiveShell(event);
MessageBox mb = new MessageBox(shell, SWT.SMOOTH);
mb.setText("General infos");
mb.setMessage(InfoStringGetter.infoStringGetter(getClass(),"/resources/info_syntax.txt"));
mb.open();
return null;
}
}
package hterhors.editor.markers;
/**
* @author Hendrik
*/
public enum EISRType {
/**
* @uml.property name="sTART"
* @uml.associationEnd
*/
START, /**
* @uml.property name="dECLARATION_NON_TERMINAL"
* @uml.associationEnd
*/
DECLARATION_NON_TERMINAL, /**
* @uml.property name="oR"
* @uml.associationEnd
*/
OR, /**
* @uml.property name="tERMINAL"
* @uml.associationEnd
*/
TERMINAL, /**
* @uml.property name="nON_TERMINAL"
* @uml.associationEnd
*/
NON_TERMINAL, /**
* @uml.property name="nONTERMINAL_END"
* @uml.associationEnd
*/
NONTERMINAL_END, /**
* @uml.property name="tECHNICAL_NON_TERMINAL_END"
* @uml.associationEnd
*/
TECHNICAL_NON_TERMINAL_END, /**
* @uml.property name="tERMINAL_END"
* @uml.associationEnd
*/
TERMINAL_END, /**
* @uml.property name="tECHNICAL_DECLARATION_NON_TERMINAL"
* @uml.associationEnd
*/
TECHNICAL_DECLARATION_NON_TERMINAL, /**
* @uml.property name="tECHNICAL_NON_TERMINAL"
* @uml.associationEnd
*/
TECHNICAL_NON_TERMINAL, /**
* @uml.property name="jOKER_TERMINAL_END"
* @uml.associationEnd
*/
JOKER_TERMINAL_END, /**
* @uml.property name="jOKER_TERMINAL"
* @uml.associationEnd
*/
JOKER_TERMINAL;
}
package hterhors.editor.markers;
/**
* @author Hendrik
*/
public class ISRValidationObject {
/**
* @uml.property name="errorMessage"
*/
private String errorMessage;
/**
* @uml.property name="lineNumber"
*/
private int lineNumber;
/**
* @uml.property name="columnStart"
*/
private int columnStart;
/**
* @uml.property name="columnEnd"
*/
private int columnEnd;
/**
* @uml.property name="type"
* @uml.associationEnd
*/
private EValidType type;
public ISRValidationObject(String errorMessage, int lineNumber,
int columnStart, int columnEnd, EValidType type) {
this.errorMessage = errorMessage;
this.lineNumber = lineNumber;
this.columnStart = columnStart;
this.columnEnd = columnEnd;
this.type = type;
}
/**
* @return
* @uml.property name="errorMessage"
*/
public String getErrorMessage() {
return errorMessage;
}
/**
* @return
* @uml.property name="lineNumber"
*/
public int getLineNumber() {
return lineNumber;
}
/**
* @return
* @uml.property name="columnStart"
*/
public int getColumnStart() {
return columnStart;
}
/**
* @return
* @uml.property name="columnEnd"
*/
public int getColumnEnd() {
return columnEnd;
}
public String toString() {
StringBuffer buf = new StringBuffer();
buf.append(type + " on ").append(" line ").append(lineNumber)
.append(", column starts ").append(columnStart)
.append(", column ends ").append(columnEnd).append(": ")
.append(errorMessage).append("\n");
return buf.toString();
}
/**
* @author Hendrik
*/
enum EValidType {
/**
* @uml.property name="error"
* @uml.associationEnd
*/
Error, /**
* @uml.property name="warning"
* @uml.associationEnd
*/
Warning;
}
}