/*******************************************************************************
 * Copyright (c) 2015, 2016 CNRS, IRIT, IRT AESE (IRT Saint Exupéry).
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the LGPL 3.0
 * which accompanies this distribution, and is available at
 * https://www.gnu.org/licenses/lgpl-3.0-standalone.html
 *
 * Contributors:
 *     Faiez Zalila - initial API and implementation and/or initial documentation
 *     Jorge Enrique Gutierrez Zuluaga
 *******************************************************************************/
package com.irtsaintexupery.fiacre.simulator.marking;

import org.eclipse.core.resources.IMarker;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.Position;
import org.eclipse.ui.texteditor.IMarkerUpdater;

public class MarkerUpdater implements IMarkerUpdater {
	/*
	*Returns the attributes for which this updater is responsible.
	*If the result is null, the updater assumes responsibility for any attributes.
	*/
	@Override
	public String[] getAttribute() {
	      return null;
	}

	@Override
	public String getMarkerType() {
	      //returns the marker type that we are interested in updating
	      return MarkerFactory.MARKER;
	}

	@Override
	public boolean updateMarker(IMarker marker, IDocument doc, Position position) {
	      try {
	            int start = position.getOffset();
	            int end = position.getOffset() + position.getLength();
	            marker.setAttribute(IMarker.CHAR_START, start);
	            marker.setAttribute(IMarker.CHAR_END, end);
	            return true;
	      } catch (CoreException e) {
	            return false;
	      }
	}
}
