/**
 * 
 */
package de.uni_jena.iaa.linktype.atomic.editors.grapheditor.parts;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.Label;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.editparts.AbstractGraphicalEditPart;

import de.hu_berlin.german.korpling.saltnpepper.salt.saltCommon.sDocumentStructure.SToken;
import de.uni_jena.iaa.linktype.atomic.editors.grapheditor.figures.TokenFigure;
import de.uni_jena.iaa.linktype.atomic.editors.grapheditor.util.PartUtils;

/**
 * @author Stephan Druskat
 *
 */
public class TokenPart extends AbstractGraphicalEditPart {

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
	 */
	@Override
	protected IFigure createFigure() {
		return new TokenFigure(PartUtils.getVisualID(getModel()));
	}
	
	@Override
	protected void refreshVisuals() {
		SToken model = getModel();
		addTokenTextLabel(model);
		int x = PartUtils.getTokenX(getViewer(), model, getFigure());
		((GraphPart) getParent()).setLayoutConstraint(this, getFigure(), new Rectangle(x, 10, getFigure().getPreferredSize().width, getFigure().getPreferredSize().height)); // FIXME: Fixed y coord (10). Make settable in Prefs?
		super.refreshVisuals();
	}

	/**
	 * @param model
	 */
	private void addTokenTextLabel(SToken model) {
		String tokenText = PartUtils.getTokenText(model);
		Label label = new Label(tokenText);
		getFigure().add(label);
	}

	/* (non-Javadoc)
	 * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
	 */
	@Override
	protected void createEditPolicies() {
		// TODO Auto-generated method stub

	}
	
	public SToken getModel() {
		return (SToken) super.getModel();
	}

}

@@ -73,16 +73,68 @@
 parts;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 import o
@@ -239,16 +239,203 @@
 tangle;%0A
+import org.eclipse.emf.common.notify.Notification;%0Aimport org.eclipse.emf.common.notify.Notifier;%0Aimport org.eclipse.emf.ecore.EObject;%0Aimport org.eclipse.emf.ecore.util.EContentAdapter;%0A
 import o
@@ -830,16 +830,120 @@
 itPart %7B
+%0A%09%0A%09private TokenAdapter adapter;%0A%0A%09public TokenPart() %7B%0A%09%09super();%0A%09%09setAdapter(new TokenAdapter());%0A%09%7D
 %0A%0A%09/* (n
@@ -1955,67 +1955,1131 @@
 %0A%09%0A%09
-public SToken getModel() %7B%0A%09%09return (SToken) super.getModel
+@Override %0A%09protected List%3CEObject%3E getModelChildren() %7B%0A%09%09List%3CEObject%3E childrenList = new ArrayList%3CEObject%3E();%0A%09%09childrenList.addAll(getModel().getSAnnotations());%0A%09%09return childrenList;%0A%09%7D%0A%09%0A%09public SToken getModel() %7B%0A%09%09return (SToken) super.getModel();%0A%09%7D%0A%0A%09/**%0A%09 * @return the adapter%0A%09 */%0A%09public TokenAdapter getAdapter() %7B%0A%09%09return adapter;%0A%09%7D%0A%0A%09/**%0A%09 * @param adapter the adapter to set%0A%09 */%0A%09public void setAdapter(TokenAdapter adapter) %7B%0A%09%09this.adapter = adapter;%0A%09%7D%0A%09%0A%09/**%0A%09 * @author Stephan Druskat%0A%09 *%0A%09 */%0A%09public class TokenAdapter extends EContentAdapter %7B%0A%0A%09%09@Override public void notifyChanged(Notification n) %7B%0A%09%09%09refreshChildren();%0A%09    %7D%0A%09 %0A%09%09@Override public Notifier getTarget() %7B%0A%09    %09return getModel();%0A%09    %7D%0A%09 %0A%09    @Override public boolean isAdapterForType(Object type) %7B%0A%09    %09return type.equals(SToken.class);%0A%09    %7D%0A%0A%09%7D%0A%09%0A%09@Override %0A%09public void activate() %7B%0A%09%09if(!isActive()) %7B%0A%09%09%09getModel().eAdapters().add(getAdapter());%0A%09    %7D%0A%09%09super.activate();%0A%09%7D%0A%09 %0A%09@Override %0A%09public void deactivate() %7B%0A%09%09if(isActive()) %7B%0A%09%09%09getModel().eAdapters().remove(getAdapter());%0A%09%09%7D%0A%09%09super.deactivate
 ();%0A

Add adapter to TokenPart