/**
 * 
 */
package org.corpus_tools.atomic.tokeneditor.handlers;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;

/**
 * TODO Description
 *
 * @author Stephan Druskat <mail@sdruskat.net>
 *
 */
public class NewTokenHandler extends AbstractHandler {

	/* (non-Javadoc)
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
	 */
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		System.err.println("CREATE NEW TOKEN");
		return null;
	}

}

@@ -75,147 +75,483 @@
 org.
-eclipse.core.commands.AbstractHandler;%0Aimport org.eclipse.core.commands.ExecutionEvent;%0Aimport org.eclipse.core.commands.ExecutionException
+corpus_tools.atomic.api.commands.DocumentGraphAwareHandler;%0Aimport org.corpus_tools.salt.common.STextualRelation;%0Aimport org.corpus_tools.salt.common.SToken;%0Aimport org.eclipse.core.commands.ExecutionEvent;%0Aimport org.eclipse.core.commands.ExecutionException;%0Aimport org.eclipse.jface.viewers.StructuredSelection;%0Aimport org.eclipse.swt.custom.StyledText;%0Aimport org.eclipse.swt.widgets.Event;%0Aimport org.eclipse.swt.widgets.Widget;%0Aimport org.eclipse.ui.handlers.HandlerUtil
 ;%0A%0A/
@@ -671,16 +671,26 @@
 nds 
-Abstract
+DocumentGraphAware
 Hand
@@ -699,16 +699,20 @@
 r %7B%0A%0A%09/*
+%0A%09 *
  (non-Ja
@@ -726,12 +726,21 @@
 %09 * 
-@see
+%0A%09 * @see%0A%09 *
  org
@@ -797,32 +797,37 @@
 e.core.commands.
+%0A%09 * 
 ExecutionEvent)%0A
@@ -922,44 +922,1195 @@
 %0A%09%09S
-ystem.err.println(%22CREATE NEW TOKEN%22
+Token selectedToken = null;%0A%09%09Widget widget;%0A%09%09if (getGraph() != null) %7B%0A%09%09%09if (!((widget = ((Event) event.getTrigger()).widget) instanceof StyledText)) %7B%0A%09%09%09%09selectedToken = getGraph().getSortedTokenByText().get(((int%5B%5D)((StructuredSelection) HandlerUtil.getCurrentSelectionChecked(event)).getFirstElement())%5B0%5D);%0A%09%09%09%7D%0A%09%09%09/*%0A%09%09%09 * It's expensive to get the respective token for a StyledText's%0A%09%09%09 * caret position with every navigation stepin the text, so instead,%0A%09%09%09 * execute the necessary logic here.  %0A%09%09%09 */%0A%09%09%09else %7B%0A%09%09%09%09if ((widget = ((Event) event.getTrigger()).widget) instanceof StyledText) %7B%0A%09%09%09%09%09StyledText text = (StyledText) widget;%0A%09%09%09%09%09int caretPosition = text.getCaretOffset();%0A%09%09%09%09%09relations: for (STextualRelation rel : getGraph().getTextualRelations()) %7B%0A%09%09%09%09%09%09if (rel.getEnd() == caretPosition %7C%7C rel.getEnd() == caretPosition) %7B%0A%09%09%09%09%09%09%09selectedToken = rel.getSource();%0A%09%09%09%09%09%09%09break relations;%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09else if (rel.getEnd() %3E caretPosition) %7B%0A%09%09%09%09%09%09%09if (rel.getStart() %3C caretPosition) %7B%0A%09%09%09%09%09%09%09%09selectedToken = rel.getSource();%0A%09%09%09%09%09%09%09%09break relations;%0A%09%09%09%09%09%09%09%7D%0A%09%09%09%09%09%09%7D%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D%0A%09%09// FIXME%0A%09%09System.err.println(getGraph().getText(selectedToken)
 );%0A%09
@@ -2126,11 +2126,10 @@
 ull;%0A%09%7D%0A
-%0A
 %7D%0A

Implement NewTokenHandler extending DocumentGraphAwareHandler