Example #1
0
  protected void assertSetEList(List<?> prototypeList) {
    EList<Object> eList = new BasicEList<Object>();
    ECollections.setEList(eList, prototypeList);
    assertTrue("Empty list test", TestUtil.areEqual(prototypeList, eList));

    eList = new BasicEList<Object>();
    eList.add(0, "String");
    eList.add(Boolean.FALSE);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Smaller list test", TestUtil.areEqual(prototypeList, eList));

    eList = (EList<Object>) populateList(new BasicEList<Object>());
    ECollections.setEList(eList, prototypeList);
    assertTrue("Same list test", TestUtil.areEqual(prototypeList, eList));

    eList.remove(2);
    eList.add(3, this);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Equal size list test", TestUtil.areEqual(prototypeList, eList));

    eList.add(0, "String");
    eList.add(2, Boolean.FALSE);
    eList.add(Boolean.FALSE);
    eList.add(this);
    ECollections.setEList(eList, prototypeList);
    assertTrue("Bigger list test", TestUtil.areEqual(prototypeList, eList));
  }
 @Test
 public void testRemoveElementInSameLine() {
   try {
     StringConcatenation _builder = new StringConcatenation();
     _builder.append("entities");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Foo \"Bar\" /* the foo */ Baz \"Fizzle\"");
     _builder.newLine();
     _builder.append("end");
     _builder.newLine();
     final Model model = this._parseHelper.parse(_builder);
     DomainModel _domainModel = model.getDomainModel();
     EList<Entity> _entities = _domainModel.getEntities();
     _entities.remove(1);
     StringConcatenation _builder_1 = new StringConcatenation();
     _builder_1.append("entities");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("Foo \"Bar\" /* the foo */");
     _builder_1.newLine();
     _builder_1.append("end");
     this.assertSerializesTo(model, _builder_1);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 public void removeToOperations(Object newValue) {
   operationsList.remove(newValue);
   if (newValue != null) {
     operations.setText(operationsList.toString());
   } else {
     operations.setText(""); // $NON-NLS-1$
   }
 }
  /** Opens the edit part and restores the connections. */
  private void openEditPart() {

    final Set<ConnectionEditPart> connections = getAllConnections();

    for (final ConnectionEditPart i : connections) {
      final EdgeImpl edgeToRestore = (EdgeImpl) i.getModel();
      final Connection con = (Connection) edgeToRestore.getElement();

      if (con.isTemp()) {
        if (edgeToRestore.getSource() == editPartOfCompartment.getModel()
            && (!con.getOriginalSource().isEmpty())) {
          // readjust source
          final EList<Shape> oSources = con.getOriginalSource();
          final Shape source = oSources.remove(oSources.size() - 1);

          final NodeImpl shapeImpl = getViewFromModel(compartmentToSupport, source);

          edgeToRestore.setSource(shapeImpl);

          con.setSource(source);
        } else if (edgeToRestore.getTarget() == editPartOfCompartment.getModel()
            && (!con.getOriginalTarget().isEmpty())) {
          // readjust target
          final EList<Shape> oTargets = con.getOriginalTarget();
          final Shape target = oTargets.remove(oTargets.size() - 1);

          final NodeImpl shapeImpl = getViewFromModel(compartmentToSupport, target);
          edgeToRestore.setTarget(shapeImpl);

          con.setTarget(target);
        }
        if (con.getOriginalSource().isEmpty() && con.getOriginalTarget().isEmpty()) {
          // connection is points direct from original source to original target, thus it's not
          // temporal
          // anymore.
          con.setTemp(false);
        }
      }
    }
  }
  public void rebuildInputTable(
      InputTable inputTable, IMetadataTable metadataTable, PigMapData mapData) {
    if (metadataTable != null && metadataTable.getListColumns() != null) {
      List<IMetadataColumn> listColumns = metadataTable.getListColumns();
      EList<TableNode> nodes = inputTable.getNodes();
      for (int i = 0; i < listColumns.size(); i++) {
        IMetadataColumn column = listColumns.get(i);
        TableNode found = null;
        int j = 0;
        for (; j < nodes.size(); j++) {
          TableNode node = nodes.get(j);
          if (node.getName() != null && node.getName().equals(column.getLabel())) {
            found = node;
            break;
          }
        }
        if (found != null) {
          // set in case talend type changed in metadata
          found.setType(column.getTalendType());
          if (i != j) {
            // do switch to keep the same sequence
            TableNode temp = nodes.get(j);
            nodes.remove(j);
            nodes.add(i, temp);
          }
        } else {
          found = PigmapFactory.eINSTANCE.createTableNode();
          found.setName(column.getLabel());
          found.setType(column.getTalendType());
          found.setNullable(column.isNullable());
          nodes.add(i, found);
        }
      }

      if (nodes.size() > listColumns.size()) {
        List unUsed = new ArrayList();
        for (int i = listColumns.size(); i < nodes.size(); i++) {
          PigMapUtil.detachNodeConnections(nodes.get(i), mapData);
          unUsed.add(nodes.get(i));
        }
        nodes.removeAll(unUsed);
      }
    }

    // re-build the connections in case any unnecessary connections are created because of previous
    // bugs and can't
    // be deleted
    if (inputTable.isLookup()) {
      rebuildInputNodesConnections(inputTable.getNodes(), mapData);
    }
  }
  public void updateAttributeFields(
      FormContainer formContainer, FormElement formElement, Attribute att) {
    FormElement fieldForAttribute = null;
    if (formContainer instanceof FormSearch) {
      fieldForAttribute = SearchInitialization.getSearchFieldForAttribute(att);
    } else if (formContainer instanceof FormClass || formContainer instanceof FormWorkflow) {
      fieldForAttribute = ClassDiagramUtils.getFieldForAttribute(att);
    }

    if (!fieldForAttribute.getClass().isInstance(formElement)) {
      // mismatch so we replace the Field
      FormGroup eContainer = (FormGroup) formElement.eContainer();
      boolean contains = eContainer.getChildren().contains(formElement);

      if (headless) {
        EList<FormElement> children = null;
        if (contains) {
          children = eContainer.getChildren();
        } else {
          children = eContainer.getDisabled();
        }
        // add the new Field
        children.add(fieldForAttribute);
        // remove
        children.remove(formElement);
      } else {
        if (contains) {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Children(),
                  fieldForAttribute));
        } else {
          cc.append(
              AddCommand.create(
                  domain,
                  eContainer,
                  FormPackage.eINSTANCE.getFormGroup_Disabled(),
                  fieldForAttribute));
        }
        Command rmCmd = RemoveCommand.create(domain, formElement);
        cc.append(rmCmd);
      }
    }
  }
 @Test
 public void testCommentOnRemovedElement() {
   try {
     StringConcatenation _builder = new StringConcatenation();
     _builder.append("entities");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Foo \"Bar\" //inline comment before deleted element");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//comment on deleted element");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("/**");
     _builder.newLine();
     _builder.append("\t ");
     _builder.append("* another comment on the deleted element");
     _builder.newLine();
     _builder.append("\t ");
     _builder.append("*/");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Baz \"Fizzle\"");
     _builder.newLine();
     _builder.append("end");
     _builder.newLine();
     final Model model = this._parseHelper.parse(_builder);
     DomainModel _domainModel = model.getDomainModel();
     EList<Entity> _entities = _domainModel.getEntities();
     _entities.remove(1);
     StringConcatenation _builder_1 = new StringConcatenation();
     _builder_1.append("entities");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("Foo \"Bar\" //inline comment before deleted element");
     _builder_1.newLine();
     _builder_1.newLine();
     _builder_1.append("end");
     this.assertSerializesTo(model, _builder_1);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
  void removeInvalide(EObject o) {
    CompoundCommand removeCommands = new CompoundCommand();
    List<EObject> validationErrors = EcoreHelper.getValidationErrors(o);
    for (EObject eObject : validationErrors) {
      if (eObject instanceof FormElement) {

        System.out.println("SynchronizeWithClass.removeInvalide() remove :" + eObject);
        if (headless) {
          EList<?> children = null;
          EObject eContainer = eObject.eContainer();
          System.out.println("SynchronizeWithClass.removeInvalide() eContainer :" + eContainer);
          if (eContainer != null) {
            if (eContainer instanceof FormGroup) {
              FormGroup fg = (FormGroup) eContainer;

              if (fg.getChildren().contains(eObject)) {
                children = fg.getChildren();
              } else if (fg.getDisabled().contains(eObject)) {
                children = fg.getDisabled();
              }
            } else if (eContainer instanceof FormCollection) {
              children = ((FormCollection) eContainer).getForms();
            }

            boolean remove = children.remove(eObject);
            System.out.println("SynchronizeWithClass.removeInvalide() removed? " + remove);
          } else {
            System.out.println("SynchronizeWithClass.removeInvalide() allready removed !");
          }

        } else {
          Command delCmd = RemoveCommand.create(domain, eObject);
          removeCommands.append(delCmd);
        }
      }
    }
    if (!headless) {
      domain.getCommandStack().execute(removeCommands);
    }
  }
 public E remove(int index) {
   copy.remove(index);
   return original.remove(index);
 }
 public boolean remove(Object o) {
   copy.remove(o);
   return original.remove(o);
 }
 @Test
 public void smokeTest() {
   try {
     StringConcatenation _builder = new StringConcatenation();
     _builder.append("entities");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//before existing element");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Foo /* within existing element */ \"Bar\" /* after existing element*/");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//unrelated comment");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//before deleted element");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Baz \"Fizzle\" /* after deleted element */");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//between deleted elements");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//another deleted element");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("Blurb /* a comment within a deleted element */ \"Bla\"");
     _builder.newLine();
     _builder.append("\t");
     _builder.newLine();
     _builder.append("\t");
     _builder.append("//before inserted element");
     _builder.newLine();
     _builder.append("end");
     _builder.newLine();
     final Model model = this._parseHelper.parse(_builder);
     Entity _createEntity = HiddentokensequencertestFactory.eINSTANCE.createEntity();
     final Procedure1<Entity> _function =
         (Entity it) -> {
           it.setName("AAA");
           it.setDescription("BBB");
         };
     final Entity event = ObjectExtensions.<Entity>operator_doubleArrow(_createEntity, _function);
     DomainModel _domainModel = model.getDomainModel();
     EList<Entity> _entities = _domainModel.getEntities();
     _entities.remove(1);
     DomainModel _domainModel_1 = model.getDomainModel();
     EList<Entity> _entities_1 = _domainModel_1.getEntities();
     _entities_1.remove(1);
     DomainModel _domainModel_2 = model.getDomainModel();
     EList<Entity> _entities_2 = _domainModel_2.getEntities();
     _entities_2.add(event);
     StringConcatenation _builder_1 = new StringConcatenation();
     _builder_1.append("entities");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("//before existing element");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("Foo /* within existing element */ \"Bar\" /* after existing element*/");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("//unrelated comment");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("//between deleted elements");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.newLine();
     _builder_1.append("\t");
     _builder_1.append("//before inserted element");
     _builder_1.newLine();
     _builder_1.append("AAA \"BBB\" end");
     this.assertSerializesTo(model, _builder_1);
   } catch (Throwable _e) {
     throw Exceptions.sneakyThrow(_e);
   }
 }
 @Override
 public ClassLoader getClassLoader(final EObject ctx) {
   Resource _eResource = ctx.eResource();
   ResourceSet _resourceSet = _eResource.getResourceSet();
   final XtextResourceSet rs = ((XtextResourceSet) _resourceSet);
   ResourceSetContext _get = ResourceSetContext.get(rs);
   final boolean isBuilder = _get.isBuilder();
   ResourceSetContext _get_1 = ResourceSetContext.get(rs);
   final boolean isEditor = _get_1.isEditor();
   if (isBuilder) {
     EList<Adapter> _eAdapters = rs.eAdapters();
     Iterable<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter> _filter =
         Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(
             _eAdapters, ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class);
     final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter =
         IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(
             _filter);
     boolean _notEquals = (!Objects.equal(adapter, null));
     if (_notEquals) {
       return adapter.getClassLoader();
     }
   }
   if (isEditor) {
     Resource _editorResource = this.getEditorResource(ctx);
     EList<Adapter> _eAdapters_1 = _editorResource.eAdapters();
     Iterable<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter> _filter_1 =
         Iterables.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>filter(
             _eAdapters_1, ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter.class);
     final ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter adapter_1 =
         IterableExtensions.<ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter>head(
             _filter_1);
     boolean _notEquals_1 = (!Objects.equal(adapter_1, null));
     if (_notEquals_1) {
       ClassLoader _classLoader = adapter_1.getClassLoader();
       boolean _equals = Objects.equal(_classLoader, null);
       if (_equals) {
         Resource _editorResource_1 = this.getEditorResource(ctx);
         EList<Adapter> _eAdapters_2 = _editorResource_1.eAdapters();
         _eAdapters_2.remove(adapter_1);
       } else {
         return adapter_1.getClassLoader();
       }
     }
   }
   Object _classpathURIContext = rs.getClasspathURIContext();
   final IJavaProject project = ((IJavaProject) _classpathURIContext);
   final URLClassLoader classloader = this.createClassLoaderForJavaProject(project);
   if (isBuilder) {
     EList<Adapter> _eAdapters_3 = rs.eAdapters();
     ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter _processorClassloaderAdapter =
         new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
     _eAdapters_3.add(_processorClassloaderAdapter);
   }
   if (isEditor) {
     Resource _editorResource_2 = this.getEditorResource(ctx);
     EList<Adapter> _eAdapters_4 = _editorResource_2.eAdapters();
     ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter
         _processorClassloaderAdapter_1 =
             new ProcessorInstanceForJvmTypeProvider.ProcessorClassloaderAdapter(classloader);
     _eAdapters_4.add(_processorClassloaderAdapter_1);
   }
   return classloader;
 }
Example #13
0
  public void rebuildModelOutputs(List<IMetadataTable> outputMetadataTables, PigMapData mapData) {
    for (IMetadataTable meatadataTable : outputMetadataTables) {
      String name = meatadataTable.getTableName();
      OutputTable outputTable = null;
      for (OutputTable out : mapData.getOutputTables()) {
        if (out.getName() != null && out.getName().equals(name)) {
          outputTable = out;
          break;
        }
      }
      if (outputTable == null) {
        outputTable = PigmapFactory.eINSTANCE.createOutputTable();
        outputTable.setName(name);
        mapData.getOutputTables().add(outputTable);
      }

      List<IMetadataColumn> listColumns = meatadataTable.getListColumns();
      if (listColumns != null) {
        EList<TableNode> nodes = outputTable.getNodes();
        for (int i = 0; i < listColumns.size(); i++) {
          IMetadataColumn column = listColumns.get(i);
          TableNode found = null;
          int j = 0;
          for (; j < nodes.size(); j++) {
            TableNode node = nodes.get(j);
            if (node.getName() != null && node.getName().equals(column.getLabel())) {
              found = node;
              break;
            }
          }
          if (found != null) {
            // set in case talend type changed in metadata
            found.setType(column.getTalendType());
            if (i != j) {
              // do switch to keep the same sequence
              TableNode temp = nodes.get(j);
              nodes.remove(j);
              nodes.add(i, temp);
            }
          } else {
            found = PigmapFactory.eINSTANCE.createTableNode();
            found.setName(column.getLabel());
            found.setType(column.getTalendType());
            found.setNullable(column.isNullable());

            nodes.add(i, found);
          }
        }

        if (nodes.size() > listColumns.size()) {
          List unUsed = new ArrayList();
          for (int i = listColumns.size(); i < nodes.size(); i++) {
            TableNode node = nodes.get(i);
            PigMapUtil.detachConnectionsSouce(node, mapData);
            unUsed.add(node);
          }
          nodes.removeAll(unUsed);
        }
      }
      mapData.getOutputTables().add(outputTable);

      // re-build the connections in case any unnecessary connections are created because of
      // previous bugs and
      // can't be deleted
      rebuildOutputNodesConnections(outputTable.getNodes(), mapData);
    }
  }