blob: 382947b3d372e4ca129b95bdc9013e737b547dc1 [file] [log] [blame]
/*
*
* Copyright (c) 2011, 2016 - 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
* Loetz GmbH&Co.KG
*
*/
package org.eclipse.osbp.vaadin.emf.data;
import org.eclipse.emf.common.notify.AdapterFactory;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.edit.domain.EditingDomain;
import org.eclipse.emf.edit.provider.IItemLabelProvider;
import org.eclipse.emf.edit.provider.IItemPropertyDescriptor;
import org.eclipse.emf.edit.provider.IItemPropertySource;
import org.eclipse.osbp.runtime.web.vaadin.common.resource.IResourceProvider;
import org.eclipse.osbp.vaadin.emf.api.IModelingContext;
import com.vaadin.data.Item;
import com.vaadin.data.util.IndexedContainer;
// TODO: Auto-generated Javadoc
/***
* The base container to provide property descriptors and their values based on
* emf.edit.
*/
@SuppressWarnings("serial")
public class EmfPropertiesContainer extends IndexedContainer {
/** The Constant ICON. */
public static final String ICON = "icon";
/** The Constant KEY. */
public static final String KEY = "key";
/** The Constant VALUE. */
public static final String VALUE = "value";
/** The root element. */
private EObject rootElement;
/** The editing domain. */
@SuppressWarnings("unused")
private final EditingDomain editingDomain;
/** The adapter factory. */
private final AdapterFactory adapterFactory;
/**
* Instantiates a new emf properties container.
*
* @param modelingContext
* the modeling context
* @param resourceProvider
* the resource provider
*/
public EmfPropertiesContainer(IModelingContext modelingContext,
IResourceProvider resourceProvider) {
this.editingDomain = modelingContext.getEditingDomain();
this.adapterFactory = modelingContext.getAdapterFactory();
addContainerProperty(KEY, String.class, "");
addContainerProperty(VALUE, EmfItemPropertyDescritor.class, null);
}
/**
* Gets the root element.
*
* @return the root element
*/
public EObject getRootElement() {
return rootElement;
}
/**
* Sets the root element.
*
* @param rootElement
* the new root element
*/
@SuppressWarnings("unchecked")
public void setRootElement(EObject rootElement) {
if (this.rootElement == rootElement) {
return;
}
this.rootElement = rootElement;
removeAllItems();
if (rootElement != null) {
IItemPropertySource propertiesProvider = (IItemPropertySource) adapterFactory
.adapt(rootElement, IItemLabelProvider.class);
for (IItemPropertyDescriptor element : propertiesProvider
.getPropertyDescriptors(rootElement)) {
Item item = addItem(element);
item.getItemProperty(KEY).setValue(
element.getDisplayName(rootElement));
item.getItemProperty(VALUE).setValue(
new EmfItemPropertyDescritor(rootElement, element));
}
}
}
}