| /** |
| * Copyright (c) 2011, 2015 - Lunifera GmbH (Gross Enzersdorf, Austria), Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License 2.0 |
| * which accompanies this distribution, and is available at |
| * https://www.eclipse.org/legal/epl-2.0/ |
| * |
| * SPDX-License-Identifier: EPL-2.0 |
| * |
| * Contributors: |
| * Florian Pirchner - Initial implementation |
| */ |
| package org.eclipse.osbp.runtime.web.ecview.presentation.vaadin.internal.services; |
| |
| import java.util.Collections; |
| import java.util.HashMap; |
| import java.util.HashSet; |
| import java.util.Map; |
| import java.util.Set; |
| |
| import org.eclipse.osbp.ecview.core.common.context.IViewContext; |
| import org.eclipse.osbp.ecview.core.common.model.core.YEmbeddable; |
| import org.eclipse.osbp.ecview.core.common.services.IWidgetAssocationsService; |
| import org.eclipse.osbp.ecview.core.common.tooling.IWidgetMouseClickService; |
| import org.eclipse.osbp.runtime.common.event.IEventBroker; |
| |
| import com.vaadin.event.LayoutEvents; |
| import com.vaadin.event.LayoutEvents.LayoutClickEvent; |
| import com.vaadin.event.LayoutEvents.LayoutClickListener; |
| import com.vaadin.event.LayoutEvents.LayoutClickNotifier; |
| import com.vaadin.ui.Component; |
| import com.vaadin.ui.Panel; |
| |
| @SuppressWarnings("serial") |
| public class WidgetMouseClickService implements IWidgetMouseClickService, |
| LayoutClickListener { |
| |
| private Set<Listener> listeners = Collections |
| .synchronizedSet(new HashSet<IWidgetMouseClickService.Listener>()); |
| private IWidgetAssocationsService<Component, YEmbeddable> associations; |
| private IViewContext context; |
| private LayoutClickNotifier widget; |
| private IEventBroker eventBroker; |
| |
| public WidgetMouseClickService(IViewContext context) { |
| this.context = context; |
| this.associations = context.getService(IWidgetAssocationsService.ID); |
| this.eventBroker = context.getService(IEventBroker.class.getName()); |
| } |
| |
| @Override |
| public void addListener(Listener listener) { |
| listeners.add(listener); |
| } |
| |
| @Override |
| public void removeListener(Listener listener) { |
| listeners.remove(listener); |
| } |
| |
| @Override |
| public void activate() { |
| Panel panel = (Panel) context.getViewEditpart().getPresentation() |
| .getWidget(); |
| widget = (LayoutEvents.LayoutClickNotifier) panel.getContent(); |
| widget.addLayoutClickListener(this); |
| } |
| |
| @Override |
| public void dactivate() { |
| if (widget != null) { |
| widget.removeLayoutClickListener(this); |
| widget = null; |
| } |
| } |
| |
| @Override |
| public void layoutClick(LayoutClickEvent event) { |
| synchronized (listeners) { |
| Object model = associations.getModelElement(event |
| .getClickedComponent()); |
| |
| for (Listener listener : listeners) { |
| listener.clicked(model); |
| } |
| |
| if (eventBroker != null) { |
| Map<String, Object> data = new HashMap<String, Object>(); |
| data.put(PROP_MODEL_ELEMENT, model); |
| data.put(PROP_WIDGET, event.getChildComponent()); |
| eventBroker.send(IWidgetMouseClickService.EVENT_TOPIC, data); |
| } |
| } |
| } |
| |
| } |