Java Code Examples for org.eclipse.emf.common.util.EList#add()

The following examples show how to use org.eclipse.emf.common.util.EList#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ELists.java    From dsl-devkit with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Filters an {@link EList} of type T to contain only elements matching the provided predicate.
 *
 * @param <T>
 *          list element type
 * @param unfiltered
 *          unfiltered list
 * @param predicate
 *          to apply
 * @return filtered list
 */
public static <T> EList<T> filter(final EList<T> unfiltered, final Predicate<? super T> predicate) {
  if (unfiltered == null) {
    return ECollections.emptyEList();
  }
  if (predicate == null) {
    throw new IllegalArgumentException("predicate must not be null"); //$NON-NLS-1$
  }
  EList<T> filtered = new BasicEList<T>(unfiltered.size() / 2); // Initial guess: half the original size
  for (T t : unfiltered) {
    if (predicate.apply(t)) {
      filtered.add(t);
    }
  }
  return filtered;
}
 
Example 2
Source File: UpdateConnectorDefinitionMigrationTest.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void should_migrateAfter_update_definitionVersion_in_connector() throws Exception {
    //Given
    doCallRealMethod().when(updateConnectorVersionMigration).migrateAfter(model, metamodel);
    final EList<Instance> connectorInstanceList = connectorInstanceList("id1","id2");
    final Instance oldConnectorInstance = aConnectorInstance("id1", "0.9");
    connectorInstanceList.add(oldConnectorInstance);
    when(model.getAllInstances("process.Connector")).thenReturn(connectorInstanceList);
    when(model.getAllInstances("connectorconfiguration.ConnectorConfiguration")).thenReturn(new BasicEList<Instance>());
    when(updateConnectorVersionMigration.shouldUpdateVersion("id1")).thenReturn(true);
    when(updateConnectorVersionMigration.getOldDefinitionVersion()).thenReturn("1.0");
    when(updateConnectorVersionMigration.getNewDefinitionVersion()).thenReturn("2.0");


    //When
    updateConnectorVersionMigration.migrateAfter(model, metamodel);

    //Then
    final Instance id1Connector = connectorInstanceList.get(0);
    final Instance id2Connector = connectorInstanceList.get(1);
    verify(id1Connector).set(UpdateConnectorDefinitionMigration.DEFINITION_VERSION_FEATURE_NAME, "2.0");
    verify(id2Connector, never()).set(UpdateConnectorDefinitionMigration.DEFINITION_VERSION_FEATURE_NAME, "2.0");
    verify(oldConnectorInstance, never()).set(UpdateConnectorDefinitionMigration.DEFINITION_VERSION_FEATURE_NAME, "2.0");
}
 
Example 3
Source File: TypeUtils.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Same as {@link #createTypeRef(Type, TypingStrategy, TypeArgument...)}, but will create unbounded wildcards as
 * type arguments if fewer type arguments are provided than the number of type parameters of the given declared.
 */
public static ParameterizedTypeRef createTypeRef(Type declaredType, TypingStrategy typingStrategy,
		boolean autoCreateTypeArgs, TypeArgument... typeArgs) {
	if (declaredType == null) {
		return null; // avoid creating a bogus ParameterizedTypeRef with a 'declaredType' property of 'null'
	}
	final ParameterizedTypeRef ref;
	if (declaredType instanceof TFunction) {
		ref = TypeRefsFactory.eINSTANCE.createFunctionTypeRef();
		// } else if (declaredType instanceof TStructuralType) {
		// throw new IllegalArgumentException("a TStructuralType should not be used as declared type of a TypeRef");
	} else if (isStructural(typingStrategy)) {
		ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRefStructural();
	} else {
		ref = TypeRefsFactory.eINSTANCE.createParameterizedTypeRef();
	}
	ref.setDefinedTypingStrategy(typingStrategy);
	ref.setDeclaredType(declaredType);
	final EList<TypeArgument> refTypeArgs = ref.getTypeArgs();
	for (TypeArgument typeArg : typeArgs) {
		refTypeArgs.add(TypeUtils.copyIfContained(typeArg));
	}
	if (autoCreateTypeArgs) {
		sanitizeRawTypeRef(ref);
	}
	return ref;
}
 
Example 4
Source File: AbstractXtextResourceSetTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourcesAreInMap() {
  final XtextResourceSet rs = this.createEmptyResourceSet();
  Assert.assertEquals(0, rs.getURIResourceMap().size());
  final XtextResource resource = new XtextResource();
  resource.setURI(URI.createFileURI(new File("foo").getAbsolutePath()));
  EList<Resource> _resources = rs.getResources();
  _resources.add(resource);
  Assert.assertEquals(1, rs.getURIResourceMap().size());
  rs.getResources().remove(resource);
  Assert.assertTrue(resource.eAdapters().isEmpty());
  Assert.assertEquals(0, rs.getURIResourceMap().size());
}
 
Example 5
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmDoubleAnnotationValue it, final short[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Short> _function = (Short v) -> {
    EList<Double> _values = it.getValues();
    _values.add(Double.valueOf(((double) (v).shortValue())));
  };
  ((List<Short>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example 6
Source File: ResourceStorageTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testConstantValueIsPersisted() {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("class C {");
    _builder.newLine();
    _builder.append("\t");
    _builder.append("static val CONSTANT = \'a\' + \'b\' + 0");
    _builder.newLine();
    _builder.append("}");
    _builder.newLine();
    final String contents = _builder.toString();
    final XtendFile file = this.file(contents);
    final ByteArrayOutputStream bout = new ByteArrayOutputStream();
    ((ResourceStorageFacade) this.resourceStorageFacade).setStoreNodeModel(true);
    Resource _eResource = file.eResource();
    this.resourceStorageFacade.createResourceStorageWritable(bout).writeResource(((StorageAwareResource) _eResource));
    byte[] _byteArray = bout.toByteArray();
    ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
    final ResourceStorageLoadable in = this.resourceStorageFacade.createResourceStorageLoadable(_byteArrayInputStream);
    Resource _createResource = file.eResource().getResourceSet().createResource(URI.createURI("synthetic:/test/MyClass.xtend"));
    final StorageAwareResource resource = ((StorageAwareResource) _createResource);
    final InMemoryURIConverter converter = new InMemoryURIConverter();
    converter.addModel(resource.getURI().toString(), contents);
    ResourceSet _resourceSet = resource.getResourceSet();
    _resourceSet.setURIConverter(converter);
    EList<Resource> _resources = file.eResource().getResourceSet().getResources();
    _resources.add(resource);
    resource.loadFromStorage(in);
    EObject _get = resource.getContents().get(1);
    final JvmGenericType jvmClass = ((JvmGenericType) _get);
    JvmMember _last = IterableExtensions.<JvmMember>last(jvmClass.getMembers());
    final JvmField field = ((JvmField) _last);
    Assert.assertTrue(field.isConstant());
    Assert.assertTrue(field.isSetConstant());
    Assert.assertEquals("ab0", field.getConstantValue());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source File: PaletteImpl.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
public void shift( int step, int size )
{
	if ( size <= 0 || size > colorLib.size( ) )
	{
		size = colorLib.size( );
	}

	final EList<Fill> el = getEntries( );
	el.clear( );

	if ( step == 0 || Math.abs( step ) >= size )
	{
		// Do nothing
		step = 0;
	}
	else if ( step < 0 )
	{
		// Move to the left side
		step = -step;
	}
	else if ( step > 0 )
	{
		// Move to the right side
		step = size - step;
	}

	for ( int i = step; i < size; i++ )
	{
		el.add( ( (ColorDefinition) colorLib.get( i ) ).copyInstance( ) );
	}
	for ( int i = 0; i < step; i++ )
	{
		el.add( ( (ColorDefinition) colorLib.get( i ) ).copyInstance( ) );
	}
}
 
Example 8
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected void _setValue(final JvmCharAnnotationValue it, final byte[] value, final String componentType, final boolean mustBeArray) {
  final Consumer<Byte> _function = (Byte v) -> {
    EList<Character> _values = it.getValues();
    _values.add(Character.valueOf(((char) (v).byteValue())));
  };
  ((List<Byte>)Conversions.doWrapArray(value)).forEach(_function);
}
 
Example 9
Source File: AbstractXtextResourceSetTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testResourcesAreInMapWithNormalizedURI_03() {
  final XtextResourceSet rs = this.createEmptyResourceSet();
  Assert.assertEquals(0, rs.getURIResourceMap().size());
  final XtextResource resource = new XtextResource();
  EList<Resource> _resources = rs.getResources();
  _resources.add(resource);
  Assert.assertEquals(1, rs.getURIResourceMap().size());
  Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
  Assert.assertEquals(0, rs.getNormalizationMap().size());
  resource.setURI(URI.createURI("/a/../foo"));
  Assert.assertEquals(2, rs.getURIResourceMap().size());
  Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
  Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
  Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
  Assert.assertEquals(1, rs.getNormalizationMap().size());
  Assert.assertEquals(rs.getURIConverter().normalize(resource.getURI()), rs.getNormalizationMap().get(resource.getURI()));
  resource.setURI(URI.createURI("/a/../bar"));
  Assert.assertEquals(2, rs.getURIResourceMap().size());
  Assert.assertFalse(rs.getURIResourceMap().containsKey(null));
  Assert.assertEquals(resource, rs.getURIResourceMap().get(resource.getURI()));
  Assert.assertEquals(resource, rs.getURIResourceMap().get(rs.getURIConverter().normalize(resource.getURI())));
  Assert.assertEquals(1, rs.getNormalizationMap().size());
  Assert.assertEquals(rs.getURIConverter().normalize(resource.getURI()), rs.getNormalizationMap().get(resource.getURI()));
  resource.setURI(null);
  Assert.assertEquals(1, rs.getURIResourceMap().size());
  Assert.assertEquals(resource, rs.getURIResourceMap().get(null));
  Assert.assertEquals(0, rs.getNormalizationMap().size());
  rs.getResources().remove(resource);
  Assert.assertTrue(resource.eAdapters().isEmpty());
  Assert.assertEquals(0, rs.getURIResourceMap().size());
  Assert.assertEquals(0, rs.getNormalizationMap().size());
}
 
Example 10
Source File: ItemUIRegistryImpl.java    From openhab-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * This method creates a list of children for a group dynamically.
 * If there are no explicit children defined in a sitemap, the children
 * can thus be created on the fly by iterating over the members of the group item.
 *
 * @param group The group widget to get children for
 * @return a list of default widgets provided for the member items
 */
private EList<Widget> getDynamicGroupChildren(Group group) {
    EList<Widget> children = new BasicEList<>();
    String itemName = group.getItem();
    try {
        if (itemName != null) {
            Item item = getItem(itemName);
            if (item instanceof GroupItem) {
                GroupItem groupItem = (GroupItem) item;
                for (Item member : groupItem.getMembers()) {
                    Widget widget = getDefaultWidget(member.getClass(), member.getName());
                    if (widget != null) {
                        widget.setItem(member.getName());
                        children.add(widget);
                    }
                }
            } else {
                logger.warn("Item '{}' is not a group.", item.getName());
            }
        } else {
            logger.warn("Group does not specify an associated item - ignoring it.");
        }
    } catch (ItemNotFoundException e) {
        logger.warn("Dynamic group with label '{}' will be ignored, because its item '{}' does not exist.",
                group.getLabel(), itemName);
    }
    return children;
}
 
Example 11
Source File: ScriptBuilderImpl.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create the internal Sarl script.
 */
public void eInit(Resource resource, String packageName, IJvmTypeProvider context) {
	setTypeResolutionContext(context);
	if (this.script == null) {
		this.script = SarlFactory.eINSTANCE.createSarlScript();
		EList<EObject> content = resource.getContents();
		if (!content.isEmpty()) {
			content.clear();
		}
		content.add(this.script);
		if (!Strings.isEmpty(packageName)) {
			script.setPackage(packageName);
		}
	}
}
 
Example 12
Source File: RecipeBuilder.java    From neoscada with Eclipse Public License 1.0 5 votes vote down vote up
protected static void addProperty ( final EList<PropertyEntry> properties, final String key, final String value )
{
    final PropertyEntry pe = RecipeFactory.eINSTANCE.createPropertyEntry ();
    pe.setKey ( key );
    pe.setValue ( value );
    properties.add ( pe );
}
 
Example 13
Source File: SeriesGroupingComposite.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void setAggParameter( Text oSource )
{
	String text = oSource.getText( );
	int index = fAggParamtersTextWidgets.indexOf( oSource );
	EList<String> parameters = fGrouping.getAggregateParameters( );
	for ( int i = parameters.size( ); i < fAggParamtersTextWidgets.size( ); i++ )
	{
		parameters.add( null );
	}
	parameters.set( index, text );
}
 
Example 14
Source File: ProblemSupportImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addWarning(final Element element, final String message) {
  this.checkCanceled();
  this.checkValidationAllowed();
  final Pair<Resource, EObject> resAndObj = this.getResourceAndEObject(element);
  EList<Resource.Diagnostic> _warnings = resAndObj.getKey().getWarnings();
  EObject _value = resAndObj.getValue();
  EStructuralFeature _significantFeature = this.getSignificantFeature(resAndObj.getValue());
  EObjectDiagnosticImpl _eObjectDiagnosticImpl = new EObjectDiagnosticImpl(Severity.WARNING, "user.issue", message, _value, _significantFeature, (-1), null);
  _warnings.add(_eObjectDiagnosticImpl);
}
 
Example 15
Source File: ChangeSerializerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Test
public void testInsertBeforeComment() {
  final InMemoryURIHandler fs = new InMemoryURIHandler();
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("#1 root {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("/**/ ");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("child1;");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  Pair<String, String> _mappedTo = Pair.<String, String>of("inmemory:/file1.pstl", _builder.toString());
  this._changeSerializerTestHelper.operator_add(fs, _mappedTo);
  final ResourceSet rs = this._changeSerializerTestHelper.createResourceSet(fs);
  final Node model = this._changeSerializerTestHelper.<Node>contents(rs, "inmemory:/file1.pstl", Node.class);
  final IChangeSerializer serializer = this._changeSerializerTestHelper.newChangeSerializer();
  final IChangeSerializer.IModification<Resource> _function = (Resource it) -> {
    EList<Node> _children = model.getChildren();
    Node _createNode = this.fac.createNode();
    final Procedure1<Node> _function_1 = (Node it_1) -> {
      it_1.setName("bazz");
    };
    Node _doubleArrow = ObjectExtensions.<Node>operator_doubleArrow(_createNode, _function_1);
    _children.add(0, _doubleArrow);
  };
  serializer.<Resource>addModification(model.eResource(), _function);
  Collection<IEmfResourceChange> _endRecordChangesToTextDocuments = this._changeSerializerTestHelper.endRecordChangesToTextDocuments(serializer);
  StringConcatenation _builder_1 = new StringConcatenation();
  _builder_1.append("----------------- inmemory:/file1.pstl (syntax: <offset|text>) -----------------");
  _builder_1.newLine();
  _builder_1.append("#1 root {<9:0| bazz;>");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("/**/ ");
  _builder_1.newLine();
  _builder_1.append("\t");
  _builder_1.append("child1;");
  _builder_1.newLine();
  _builder_1.append("}");
  _builder_1.newLine();
  _builder_1.append("--------------------------------------------------------------------------------");
  _builder_1.newLine();
  _builder_1.append("9 0 \"\" -> \" bazz;\"");
  _builder_1.newLine();
  this._changeSerializerTestHelper.operator_tripleEquals(_endRecordChangesToTextDocuments, _builder_1);
}
 
Example 16
Source File: CopyEObjectFeaturesCommand.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
/**
 * @param targetElement
 * @param sourceElement
 * 
 */
public static void copyFeatures(EObject sourceElement, EObject targetElement) {
    List<EStructuralFeature> targetFeatures = targetElement.eClass().getEAllStructuralFeatures();
    for (EStructuralFeature feature : sourceElement.eClass().getEAllStructuralFeatures()) {
        if (targetFeatures.contains(feature)) {
            if (feature instanceof EReference) {
                EReference reference = (EReference)feature;
                Object value = sourceElement.eGet(reference);
                if (value instanceof EList<?>) {
                    EList<EObject> sourceList = (EList<EObject>)value;
                    EList<EObject> destList = (EList<EObject>)targetElement.eGet(feature);
                    while (!sourceList.isEmpty()) {
                        EObject referencedItem = sourceList.get(0);
                        sourceList.remove(referencedItem);
                        if (reference.getEOpposite() != null) {
                            referencedItem.eSet(reference.getEOpposite(), targetElement);
                        } else {
                            destList.add(referencedItem);
                        }
                    }
                } else {
                    targetElement.eSet(feature, sourceElement.eGet(feature));
                }
            } else if (feature instanceof EAttribute) {
                targetElement.eSet(feature, sourceElement.eGet(feature));
            }
        }else{//unset other features
            if(feature.isMany()){
                sourceElement.eSet(feature, Collections.emptyList());
            }else{
                sourceElement.eSet(feature, feature.getDefaultValue());
            }
        }
    }


    EObject container = sourceElement.eContainer();
    if (container != null) {
        Object parentFeatureValue = container.eGet(sourceElement.eContainingFeature());
        if (parentFeatureValue instanceof EList<?>) {
            //			int index = ((EList) parentFeatureValue).indexOf(sourceElement);
            ((EList<?>) parentFeatureValue).remove(sourceElement);
            // Add the new element at the same place than the older one
            // ((EList) parentFeatureValue).set(((EList)
            // parentFeatureValue).indexOf(sourceElement), targetElement);
            ((EList) parentFeatureValue).add(/* index, */targetElement);
        } else {
            container.eSet(sourceElement.eContainingFeature(), targetElement);
        }
    }
}
 
Example 17
Source File: AbstractOutlineTreeProvider.java    From dsl-devkit with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Creates children for all {@link EStructuralFeatures} (that are set) of the given {@link EObject} model element. {@inheritDoc}
 *
 * @param parentNode
 *          the parent {@link IOutlineNode}
 * @param modelElement
 *          a valid {@link EObject}
 */
@SuppressWarnings({"unchecked", "PMD.NPathComplexity"})
@Override
protected void internalCreateChildren(final IOutlineNode parentNode, final EObject modelElement) {
  // from all structural features, select only those which are set and retrieve the text location
  // TODO : sorting for feature lists needs to be based on the objects in the list, not the feature.
  List<Pair<Integer, EStructuralFeature>> pairsLocationFeature = Lists.newArrayList();
  for (EStructuralFeature structuralFeature : modelElement.eClass().getEAllStructuralFeatures()) {
    if (modelElement.eIsSet(structuralFeature)) {
      int offset = 0;
      List<INode> nodes = NodeModelUtils.findNodesForFeature(modelElement, structuralFeature);
      if (!nodes.isEmpty()) {
        offset = nodes.get(0).getTotalOffset();
      }
      pairsLocationFeature.add(Tuples.create(offset, structuralFeature));
    }
  }
  // sort the features according to their appearance in the source text
  Collections.sort(pairsLocationFeature, new Comparator<Pair<Integer, EStructuralFeature>>() {
    @Override
    public int compare(final Pair<Integer, EStructuralFeature> o1, final Pair<Integer, EStructuralFeature> o2) {
      return o1.getFirst() - o2.getFirst();
    }
  });
  // go through the sorted list of children and create nodes
  for (Pair<Integer, EStructuralFeature> pairLocationFeature : pairsLocationFeature) {
    EStructuralFeature feature = pairLocationFeature.getSecond();
    if (feature instanceof EAttribute) {
      if (getRelevantElements().contains(feature)) {
        createNodeDispatcher.invoke(parentNode, modelElement, feature);
      }
    } else if (feature instanceof EReference && ((EReference) feature).isContainment()) { // only consider containment references
      IOutlineNode listNode = null;
      EList<EObject> featureElements;
      Object value = modelElement.eGet(feature);
      if (feature.isMany()) {
        featureElements = (EList<EObject>) value;
        if (getRelevantElements().contains(feature)) {
          listNode = createEStructuralFeatureNode(parentNode, modelElement, feature, getImageDescriptor(feature), feature.getName(), false);
        }
      } else {
        featureElements = new BasicEList<EObject>();
        featureElements.add((EObject) value);
      }
      for (EObject childElement : featureElements) {
        if (childElement == null) {
          continue;
        }
        if (isRelevantElement(childElement)) {
          createNodeDispatcher.invoke(listNode != null ? listNode : parentNode, childElement);
        } else {
          createChildrenDispatcher.invoke(listNode != null ? listNode : parentNode, childElement);
        }
      }
    }
  }
}
 
Example 18
Source File: BonitaToBPMNExporter.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private void handleConnectorOnServiceTask(final Activity activity, final TServiceTask serviceTask,
        IModelSearch modelSearch) {
    final EList<Connector> connectors = activity.getConnectors();
    if (!connectors.isEmpty()) {
        final Connector connector = connectors.get(0);
        handleBonitaConnectorDefinition(connector.getDefinitionId(), modelSearch);
        /*
         * Service task should be used with a connector,
         * this connector will be the bpmn2 operation used
         * /!\BEGIN TO HANDLE A SINGLE OPERATION
         */
        serviceTask.setImplementation("BonitaConnector");
        serviceTask.setOperationRef(QName.valueOf("Exec" + connector.getDefinitionId()));

        final TDataInput dataInput = fillIOSpecificationWithNewDataInput(serviceTask,
                QName.valueOf(generateConnectorInputItemDef(connector.getDefinitionId())));
        final TDataOutput dataOutput = fillIOSpecificationWithNewDataOutput(serviceTask,
                QName.valueOf(generateConnectorOutputItemDef(connector.getDefinitionId())));

        final TDataInputAssociation tDataInputAssociation = ModelFactory.eINSTANCE.createTDataInputAssociation();

        final EList<TAssignment> inputAssignments = tDataInputAssociation.getAssignment();

        for (final ConnectorParameter cp : connector.getConfiguration().getParameters()) {
            final TAssignment inputAssignment = ModelFactory.eINSTANCE.createTAssignment();
            if (cp.getExpression() instanceof Expression
                    && ((Expression) cp.getExpression()).getContent() != null) {
                inputAssignment
                        .setFrom(convertExpression((Expression) cp.getExpression()));
                inputAssignment.setTo(createBPMNExpressionFromString("getDataInput('" + dataInput.getId() + "')/"
                        + XMLNS_HTTP_BONITASOFT_COM_BONITA_CONNECTOR_DEFINITION + ":" + cp.getKey()));
                inputAssignments.add(inputAssignment);
            }
        }
        if (!tDataInputAssociation.getAssignment().isEmpty()) {
            serviceTask.getDataInputAssociation().add(tDataInputAssociation);
            tDataInputAssociation.setTargetRef(dataInput.getId());
            //tDataInputAssociation.getSourceRef().add(da);
        }

        final TDataOutputAssociation tDataOutputAssociation = ModelFactory.eINSTANCE.createTDataOutputAssociation();

        final EList<TAssignment> outputAssignments = tDataOutputAssociation.getAssignment();
        for (final Operation opm : connector.getOutputs()) {
            if (opm.getRightOperand().hasName() &&
                    opm.getRightOperand().hasContent()) {
                final TAssignment outputAssignment = ModelFactory.eINSTANCE.createTAssignment();
                if (ExpressionConstants.CONNECTOR_OUTPUT_TYPE.equals(opm.getRightOperand().getType())) {
                    outputAssignment
                            .setFrom(createBPMNExpressionFromString("getDataOutput('" + dataInput.getId() + "')/"
                                    + XMLNS_HTTP_BONITASOFT_COM_BONITA_CONNECTOR_DEFINITION + ":"
                                    + opm.getRightOperand().getName()));
                } else {
                    outputAssignment.setFrom(convertExpression(opm.getRightOperand()));
                }
                if (opm.getLeftOperand().hasContent()) {
                    outputAssignment.setTo(convertExpression(opm.getLeftOperand()));
                }
                outputAssignments.add(outputAssignment);
            }
        }
        if (!tDataOutputAssociation.getAssignment().isEmpty()) {
            serviceTask.getDataOutputAssociation().add(tDataOutputAssociation);
            tDataOutputAssociation.setTargetRef(dataOutput.getId());
        }
    }
}
 
Example 19
Source File: BonitaToBPMNExporter.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
private TFlowElement createActivity(final FlowElement child, IModelSearch modelSearch) {
    // Tasks
    TFlowElement res = null;
    if (child instanceof CallActivity) {
        //WARNING in fact this is a call activity
        //TSubProcess bpmnSubprocess = ModelFactory.eINSTANCE.createTSubProcess();
        final TCallActivity tCallActivity = ModelFactory.eINSTANCE.createTCallActivity();
        //TODO: construct calledElement ID
        final CallActivity cActivity = (CallActivity) child;
        final Expression calledActivityName = cActivity.getCalledActivityName();
        if (calledActivityName != null
                && ExpressionConstants.CONSTANT_TYPE.equals(calledActivityName.getType())
                && calledActivityName.getContent() != null) {
            final Expression calledVersion = cActivity.getCalledActivityVersion();
            String version = null;
            if (calledVersion != null && calledVersion.getContent() != null
                    && !calledVersion.getContent().isEmpty()) {
                version = calledVersion.getContent();
            }
            final Optional<AbstractProcess> calledProcess = modelSearch.findProcess(calledActivityName.getContent(),
                    version);
            calledProcess.ifPresent(process -> tCallActivity
                    .setCalledElement(QName.valueOf(modelSearch.getEObjectID(process))));
        }
        res = tCallActivity;
    } else if (child instanceof ServiceTask) {
        res = ModelFactory.eINSTANCE.createTServiceTask();
    } else if (child instanceof ScriptTask) {
        res = ModelFactory.eINSTANCE.createTScriptTask();
    } else if (child instanceof Task) {
        final Task bonitaTask = (Task) child;
        final TUserTask bpmnTask = ModelFactory.eINSTANCE.createTUserTask();
        final Actor actor = bonitaTask.getActor();
        if (actor != null) {
            final EList<TResourceRole> resourceRoles = bpmnTask.getResourceRole();
            final TPerformer role = ModelFactory.eINSTANCE.createTPerformer();
            role.setResourceRef(QName.valueOf(modelSearch.getEObjectID(actor)));
            role.setId(EcoreUtil.generateUUID());
            resourceRoles.add(role);
            //TODO: check that a performer is the well thing to use search in the whole inheritance of ResourceRole
            //TODO: use assignment if specifying a name
            //TODO:
        }
        // TODO performer
        res = bpmnTask;
    } else if (child instanceof SendTask) {
        res = ModelFactory.eINSTANCE.createTSendTask();
    } else if (child instanceof ReceiveTask) {
        res = ModelFactory.eINSTANCE.createTReceiveTask();
    } else if (child instanceof Activity) {
        res = ModelFactory.eINSTANCE.createTTask();
    }
    if (child instanceof MultiInstantiable && res instanceof TActivity) {
        handleMultiInstance((MultiInstantiable) child, (TActivity) res);
    }
    return res;
}
 
Example 20
Source File: MarkerRangeImpl.java    From birt with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @generated
 */
protected void set( MarkerRange src )
{

	// children

	if ( src.getOutline( ) != null )
	{
		setOutline( src.getOutline( ).copyInstance( ) );
	}

	if ( src.getFill( ) != null )
	{
		setFill( src.getFill( ).copyInstance( ) );
	}

	if ( src.getStartValue( ) != null )
	{
		setStartValue( src.getStartValue( ).copyInstance( ) );
	}

	if ( src.getEndValue( ) != null )
	{
		setEndValue( src.getEndValue( ).copyInstance( ) );
	}

	if ( src.getLabel( ) != null )
	{
		setLabel( src.getLabel( ).copyInstance( ) );
	}

	if ( src.getFormatSpecifier( ) != null )
	{
		setFormatSpecifier( src.getFormatSpecifier( ).copyInstance( ) );
	}

	if ( src.getTriggers( ) != null )
	{
		EList<Trigger> list = getTriggers( );
		for ( Trigger element : src.getTriggers( ) )
		{
			list.add( element.copyInstance( ) );
		}
	}

	if ( src.getCursor( ) != null )
	{
		setCursor( src.getCursor( ).copyInstance( ) );
	}

	// attributes

	labelAnchor = src.getLabelAnchor( );

	labelAnchorESet = src.isSetLabelAnchor( );

}