| /** |
| * 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.Map; |
| |
| import org.eclipse.osbp.ecview.core.common.editpart.IElementEditpart; |
| import org.eclipse.osbp.ecview.core.common.editpart.emf.ElementEditpart; |
| import org.eclipse.osbp.ecview.core.common.model.core.YElement; |
| import org.eclipse.osbp.ecview.core.common.model.core.YFocusable; |
| import org.eclipse.osbp.ecview.core.common.services.AbstractWidgetAssocationsService; |
| import org.eclipse.osbp.ecview.core.extension.model.extension.YPanel; |
| |
| import com.vaadin.ui.Component; |
| |
| public class WidgetAssocationsService extends AbstractWidgetAssocationsService<Component, YElement> { |
| |
| @Override |
| public YElement getModelElement(String id) { |
| synchronized (associations) { |
| for (Map.Entry<Component, YElement> entry : associations.entrySet()) { |
| YElement yElement = entry.getValue(); |
| if (yElement.getId() != null && yElement.getId().equals(id)) { |
| return yElement; |
| } |
| } |
| } |
| return null; |
| } |
| |
| @Override |
| public IElementEditpart getEditpart(String id) { |
| YElement yElement = getModelElement(id); |
| return yElement != null ? ElementEditpart.findEditPartFor(yElement) : null; |
| } |
| |
| @Override |
| public YElement getModelElement(int layoutIdx) { |
| synchronized (associations) { |
| for (Map.Entry<Component, YElement> entry : associations.entrySet()) { |
| YElement yElement = entry.getValue(); |
| if (yElement instanceof YFocusable && !(yElement instanceof YPanel)) { |
| int yElementLayoutIdx = ((YFocusable) yElement).getLayoutIdx(); |
| if (layoutIdx == yElementLayoutIdx) { |
| return yElement; |
| } |
| } |
| } |
| } |
| return null; |
| } |
| |
| } |