diff options
Diffstat (limited to 'plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties')
3 files changed, 195 insertions, 0 deletions
diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/ImportedPackageLocationObservableValue.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/ImportedPackageLocationObservableValue.java new file mode 100644 index 00000000000..62590a52b2e --- /dev/null +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/databinding/ImportedPackageLocationObservableValue.java @@ -0,0 +1,75 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ + +package org.eclipse.papyrus.uml.properties.databinding; + +import org.eclipse.core.databinding.observable.value.AbstractObservableValue; +import org.eclipse.emf.common.util.URI; +import org.eclipse.emf.ecore.util.EcoreUtil; +import org.eclipse.uml2.uml.Package; + +/** + * Observable value of Imported Package's location. + * + * @author Gabriel Pascual + * + */ +public class ImportedPackageLocationObservableValue extends AbstractObservableValue { + + /** The Constant UNKNOWN_LOCATION. */ + private static final String UNKNOWN_LOCATION = "Unknown"; + + /** The imported package. */ + private Package importedPackage = null; + + + /** + * Instantiates a new imported package location. + * + * @param source + * the source + */ + public ImportedPackageLocationObservableValue(Package source) { + super(); + importedPackage = source; + } + + /** + * @see org.eclipse.core.databinding.observable.value.IObservableValue#getValueType() + * + * @return + */ + public Object getValueType() { + return String.class; + } + + /** + * @see org.eclipse.core.databinding.observable.value.AbstractObservableValue#doGetValue() + * + * @return + */ + @Override + protected Object doGetValue() { + String location = UNKNOWN_LOCATION; + + if (importedPackage.eIsProxy()) { + location = EcoreUtil.getURI(importedPackage).trimFragment().toString(); + } else if (importedPackage.eResource() != null) { + URI uri = importedPackage.eResource().getURI(); + if (uri != null) { + location = uri.toString(); + } + } + return location; + } + +} diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElement.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElement.java new file mode 100644 index 00000000000..d44cbc005d3 --- /dev/null +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElement.java @@ -0,0 +1,63 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ + +package org.eclipse.papyrus.uml.properties.modelelement; + +import org.eclipse.core.databinding.observable.IObservable; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.uml.properties.databinding.ImportedPackageLocationObservableValue; +import org.eclipse.papyrus.views.properties.modelelement.EMFModelElement; +import org.eclipse.uml2.uml.Package; + +/** + * + * Model element of Imported Package. + * + * @author Gabriel Pascual + * + */ +public class ImportedPackageModelElement extends EMFModelElement { + + /** The Constant LOCATION_PROPERTY_PATH. */ + private final static String LOCATION_PROPERTY_PATH = "location"; //$NON-NLS-1$ + + /** + * Constructor. + * + * @param source + * the source + * @param domain + * the domain + */ + public ImportedPackageModelElement(EObject source, EditingDomain domain) { + super(source, domain); + } + + /** + * @see org.eclipse.papyrus.views.properties.modelelement.EMFModelElement#doGetObservable(java.lang.String) + * + * @param propertyPath + * @return + */ + @Override + protected IObservable doGetObservable(String propertyPath) { + + // Location of Imported Package + if (LOCATION_PROPERTY_PATH.equals(propertyPath)) { + return new ImportedPackageLocationObservableValue((Package) source); + } + + return super.doGetObservable(propertyPath); + } + +} diff --git a/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElementFactory.java b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElementFactory.java new file mode 100644 index 00000000000..2777c5bc0ef --- /dev/null +++ b/plugins/uml/properties/org.eclipse.papyrus.uml.properties/src/org/eclipse/papyrus/uml/properties/modelelement/ImportedPackageModelElementFactory.java @@ -0,0 +1,57 @@ +/***************************************************************************** + * Copyright (c) 2014 CEA LIST. + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Gabriel Pascual (ALL4TEC) gabriel.pascual@all4tec.net - Initial API and implementation + *****************************************************************************/ + +package org.eclipse.papyrus.uml.properties.modelelement; + +import org.eclipse.emf.edit.domain.EditingDomain; +import org.eclipse.papyrus.infra.emf.utils.EMFHelper; +import org.eclipse.papyrus.uml.tools.utils.UMLUtil; +import org.eclipse.papyrus.views.properties.Activator; +import org.eclipse.papyrus.views.properties.contexts.DataContextElement; +import org.eclipse.papyrus.views.properties.modelelement.EMFModelElementFactory; +import org.eclipse.uml2.uml.Element; + + +/** + * A factory for creating ImportedPackageModelElement objects. + * + * @author Gabriel Pascual + */ +public class ImportedPackageModelElementFactory extends EMFModelElementFactory { + + + /** The Constant RESOLUTION_WARNING_MESSAGE. */ + private static final String RESOLUTION_WARNING_MESSAGE = "Unable to resolve the selected element to a UML Element"; + + /** + * Do create from source. + * + * @param source + * the source + * @param context + * the context + * @return the imported package model element + * @see org.eclipse.papyrus.views.properties.modelelement.EMFModelElementFactory#doCreateFromSource(java.lang.Object, org.eclipse.papyrus.views.properties.contexts.DataContextElement) + */ + @Override + protected ImportedPackageModelElement doCreateFromSource(Object source, DataContextElement context) { + Element umlSource = UMLUtil.resolveUMLElement(source); + if (umlSource == null) { + Activator.log.warn(RESOLUTION_WARNING_MESSAGE); + return null; + } + + EditingDomain domain = EMFHelper.resolveEditingDomain(umlSource); + return new ImportedPackageModelElement(umlSource, domain); + } + +} |