blob: 38a89596dcadf226be70b4069a65ec68d62c6015 [file] [log] [blame]
/*****************************************************************************
* Copyright (c) 2019 CEA LIST.
*
*
* 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:
* Xavier Le Pallec (for CEA LIST) xlepallec@lilo.org - Bug 558456
*
*****************************************************************************/
package org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.mapping.java2js;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.papyrus.uml.diagram.clazz.edit.parts.PropertyForClassEditPart;
import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.Activator;
import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.mapping.TypesFactory;
import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.mapping.jsonstructures.JsonStructuresFactory;
import org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.mapping.jsonstructures.JsonUmlProperty;
import org.eclipse.uml2.uml.Property;
/**
* This class is dedicated to fed an instance of
* {@link org.eclipse.papyrus.uml.diagram.clazz.lf.classtextualedition.mapping.jsonstructures.JsonUmlProperty}
* from a real Papyrus property represented by a property edit part:
* <OL>
* <LI>The constructor takes a property edit part as a parameter, creates an
* instance of UmlProperty, gets the org.eclipse.uml2.uml.Property indirectly
* referenced by the property edit part and invokes the following method</LI>
* <LI>The method {@link JsonUmlPropertyFromEditPart#createFromEditPart()} feeds the
* previous instance</LI>
* <LI>Finally, the method {@link JsonUmlPropertyFromEditPart#getProperty()} allows
* to get the previous instance</LI>
* </OL>
*
*/
public class JsonUmlPropertyFromEditPart {
private JsonUmlProperty property;
protected Property sourceProperty;
private static final Activator LOGGER = Activator.getDefault();
/**
* The constructor takes a property edit part as a parameter, creates an
* instance of UmlProperty, get the org.eclipse.uml2.uml.Property indirectly
* referenced by the property edit part and invokes
* {@link JsonUmlPropertyFromEditPart#createFromEditPart()}.
*
* @param editPart
* the edit part indirectly containing the the real property
*/
public JsonUmlPropertyFromEditPart(PropertyForClassEditPart editPart) {
super();
this.property = JsonStructuresFactory.getInstance().createJsonUmlProperty();
if (editPart.getModel() instanceof View) {
View visualStuff = View.class.cast(editPart.getModel());
if (visualStuff.getElement() instanceof Property) {
sourceProperty = Property.class.cast(visualStuff.getElement());
createFromEditPart();
} else {
LOGGER.logCastProblem("visualStuff.getElement()", Property.class); //$NON-NLS-1$
}
} else {
LOGGER.logCastProblem("editPart.getModel()", View.class); //$NON-NLS-1$
}
}
/**
* This method feeds the instance of UmlProperty by accessing all the
* properties of the instance of org.eclipse.uml2.uml.Property (get in the
* constructor).
*/
protected void createFromEditPart() {
this.property.setName(sourceProperty.getName());
this.property.setDerived(sourceProperty.isDerived());
this.property.setVisibility(sourceProperty.getVisibility().getLiteral());
this.property.setType(TypesFactory.getInstance().createTypeHelper(sourceProperty).getTypeNameForAGivenType(sourceProperty.getType()));
this.property.setLower(sourceProperty.getLower());
this.property.setUpper(sourceProperty.getUpper());
this.property.setUnique(sourceProperty.isUnique());
this.property.setOrdered(sourceProperty.isOrdered());
this.property.setReadOnly(sourceProperty.isReadOnly());
this.property.setDerivedUnion(sourceProperty.isDerivedUnion());
this.property.setId(sourceProperty.isID());
}
/**
* Gets the instance of UmlProperty. It may be not fed.
*
* @return the instance of UmlProperty.
*/
public JsonUmlProperty getProperty() {
return property;
}
/**
* Sets the instance of UmlProperty.
*
* @param property
* the instance of UmlProperty
*/
public void setProperty(JsonUmlProperty property) {
this.property = property;
}
}