All Downloads are FREE. Search and download functionalities are using the official Maven repository.

info.kwarc.sally4.mhw.base.impl.MathHubDocument Maven / Gradle / Ivy

The newest version!
package info.kwarc.sally4.mhw.base.impl;

import info.kwarc.sally.comm.mathhubdocument.GetCurrentSelection;
import info.kwarc.sally.comm.mathhubdocument.GetCurrentSelectionResponse;
import info.kwarc.sally.comm.mathhubdocument.GetText;
import info.kwarc.sally.comm.mathhubdocument.GetTextResponse;
import info.kwarc.sally.comm.mathhubdocument.SelectText;
import info.kwarc.sally4.framing.SallyFrameMenu;
import info.kwarc.sally4.mhw.base.IMathHubDocument;
import info.kwarc.sally4.mhw.base.IMathHubRepository;
import info.kwarc.sally4.mhw.base.IMathHubUser;
import info.kwarc.sally4.mhw.base.IMathHubWorker;
import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.theo.Theo;

import java.util.concurrent.ExecutionException;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
import org.apache.felix.ipojo.annotations.Property;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.ipojo.annotations.Validate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component(name=MathHubDocument.factory_id)
@Provides(specifications=IMathHubDocument.class)
public class MathHubDocument implements IMathHubDocument {
	final public static String factory_id = "info.kwarc.sally4.mhw.base.impl.MathHubDocument";
	
	Logger log;
	
	@Requires(id="user",filter="(filterThatWillNeverSucceed=1)")
	IMathHubUser user;

	final public static String mathHubWorker = "mathHubWorker";
	@Requires(id = "mathHubWorker", filter = "(filterThatWillNeverSucceed=1)")
	IMathHubWorker worker;
	
	final public static String mathHubRepository = "mathHubRepository";
	@Requires(id = "mathHubRepository", filter = "(filterThatWillNeverSucceed=1)")
	IMathHubRepository repo;
	
	@ServiceProperty
	String repositoryId;
	
	@Requires(id="client",filter="(filterThatWillNeverSucceed=1)")
	SallyClient client;

	@Requires(id="frame",filter="(filterThatWillNeverSucceed=1)")
	SallyFrameMenu frames;
	
	@Requires(id="theo",filter="(filterThatWillNeverSucceed=1)")
	Theo theo;
	
	@Property
	String filePath;
	
	public MathHubDocument() {
		init();
	}
	
	public MathHubDocument(IMathHubUser user, String filePath) {
		this.user = user;
		this.filePath = filePath;
		init();
	}
	
	void init() {
		log = LoggerFactory.getLogger(getClass());
	}
	
	public IMathHubUser getUser() {
		return user;
	}
	
	@Override
	public String getWorkerRelativePath() {
		return filePath;
	}

	@Validate
	public void start() {
		repositoryId = repo.getRepositoryid();
	}
	
	@Invalidate
	public void stop() {
		
	}

	@Override
	public SallyClient getSallyClient() {
		return client;
	}

	@Override
	public SallyFrameMenu getSallyFrames() {
		return frames;
	}

	@Override
	public Theo getTheo() {
		return theo;
	}

	@Override
	public String getText() {
		try {
			return client.sendRequest(new GetText(), GetTextResponse.class).get().getText();
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public GetCurrentSelectionResponse getSelection() {
		try {
			return client.sendRequest(new GetCurrentSelection(), GetCurrentSelectionResponse.class).get();
		} catch (InterruptedException | ExecutionException e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public void selectText(int startRow, int startCol, int endRow, int endCol) {
		SelectText selText = new SelectText();
		selText.setStartcolumn(startCol);
		selText.setEndcolumn(endCol);
		selText.setStartrow(startRow);
		selText.setEndrow(endRow);
		client.sendEvent(selText);
	}

	@Override
	public String getAbsolutePath() {
		return worker.getLmh().getAbsolutePath(filePath);
	}

	@Override
	public IMathHubRepository getRepository() {
		return repo;
	}

	@Override
	public IMathHubWorker getWorker() {
		return worker;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy