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

info.kwarc.sally4.framing.impl.SallyFrameMenuImpl Maven / Gradle / Ivy

The newest version!
package info.kwarc.sally4.framing.impl;

import info.kwarc.sally.comm.frames.ExecDocLevelService;
import info.kwarc.sally.comm.frames.RemoveDocLevelService;
import info.kwarc.sally.comm.frames.ShowSallyFrameMenu;
import info.kwarc.sally4.docmanager.CallbackManager;
import info.kwarc.sally4.docmanager.SallyMenuItem;
import info.kwarc.sally4.framing.DocumentLevelService;
import info.kwarc.sally4.framing.DocumentLevelService.State;
import info.kwarc.sally4.framing.SallyFrameMenu;
import info.kwarc.sally4.framing.factory.SallyFrameMenuFactory;
import info.kwarc.sally4.os.events.EventBusContext;
import info.kwarc.sally4.registration.SallyClient;
import info.kwarc.sally4.servlet.SallyServlet;
import info.kwarc.sally4.theo.Theo;

import java.util.ArrayList;
import java.util.HashMap;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Invalidate;
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;

import com.google.common.eventbus.Subscribe;

@Component(name=SallyFrameMenuImpl.factoryid)
@Provides(specifications=SallyFrameMenu.class)
public class SallyFrameMenuImpl implements SallyFrameMenu {
	  final public static String factoryid = "info.kwarc.sally4.framing.impl.SallyFrameMenuImpl";
		  
	public static class MenuListWindow {
		ArrayList items;
		String wndid;
		Theo theo;
		
		public ArrayList getItems() {
			return items;
		}
		public String getWndid() {
			return wndid;
		}
		public Theo getTheo() {
			return theo;
		}
	}
	
	EventBusContext context;
	  
	@Requires(id="clientInstance", filter="(filterThatWillNeverSucceed=1)")
	SallyClient clientInstance;

	@Requires(id="theoInstance", filter="(filterThatWillNeverSucceed=1)")
	Theo theoInstance;
	
	@Requires
	CallbackManager callbackManager;
		
	@ServiceProperty
	String clientQueue;
	
	@Requires
	SallyServlet servlet;
		
	Logger log;
	
	public SallyFrameMenuImpl() {
		log = LoggerFactory.getLogger(getClass());
	}
	
	HashMap docLevelServices;

	@Subscribe public void onNewDocumentLevelService(DocumentLevelService docService) {
		if (docService.getState() == State.Starting) {
			docLevelServices.put(docService.getId(), docService);
			clientInstance.sendEvent(docService.getDocLevelService());
			return;
		}
		if (docService.getState() == State.Stopping) {
			docLevelServices.remove(docService.getId());
			RemoveDocLevelService req = new RemoveDocLevelService();
			req.setId(docService.getId());
			clientInstance.sendEvent(req);
			return;
		}
	}
	
	@Subscribe public void onShowSallyFrame (ShowSallyFrameMenu request) {
		
		MenuItemAcceptor acceptor = new MenuItemAcceptor();

		MenuListWindow menuInfo = new MenuListWindow();
		menuInfo.items = acceptor.getItems();
		menuInfo.theo = theoInstance;
		
		String id = callbackManager.registerCallback(menuInfo);

		menuInfo.wndid = theoInstance.openNewWindow(servlet.getURL()+SallyFrameMenuFactory.menuPath+"?id="+id, "Sally Frames", request.getPosx(), request.getPosy(), 400, 300);
	};
		
	@Subscribe public void onExecuteDocLevelService(ExecDocLevelService exec) {
		DocumentLevelService docLevelService = docLevelServices.get(exec.getId());
		docLevelService.getRunnable().run();
	}
	
	@Validate
	void start() {
		clientQueue = clientInstance.getDocQueue();
		docLevelServices = new HashMap();
		context = clientInstance.getEventBusContext();
		context.register(this);
	}
	
	@Invalidate
	void stop() {
		context.unregister(this);
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy