public void process(PropjavaResource resource) {
    URI javaURI = resource.getURI().trimFileExtension().appendFileExtension("java");
    Resource javaResource = resource.getResourceSet().createResource(javaURI);
    javaResource.getContents().addAll(EcoreUtil.copyAll(resource.getContents()));

    boolean changed = true;

    while (changed) {
      changed = false;
      Collection<Property> properties =
          PropjavaEObjectUtil.getObjectsByType(
              javaResource.getAllContents(), PropertiesPackage.eINSTANCE.getProperty());
      for (Property property : properties) {
        convertToField(property);
        changed = true;
        break;
      }
    }

    try {
      javaResource.save(null);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  @Override
  public void doSaveAs() {
    SaveAsDialog saveAsDialog = new SaveAsDialog(getSite().getShell());
    saveAsDialog.create();
    saveAsDialog.setMessage(EcoreEditorPlugin.INSTANCE.getString("_UI_SaveAs_message"));
    saveAsDialog.open();
    IPath path = saveAsDialog.getResult();
    if (path != null) {
      IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(path);
      if (file != null) {
        ResourceSet resourceSet = editingDomain.getResourceSet();
        Resource currentResource = resourceSet.getResources().get(0);
        URI newURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);

        Resource newResource = resourceSet.createResource(newURI);
        newResource.getContents().addAll(EcoreUtil.copyAll(currentResource.getContents()));
        resourceSet.getResources().remove(0);
        resourceSet.getResources().move(0, newResource);

        IFileEditorInput modelFile = new FileEditorInput(file);
        setInputWithNotify(modelFile);
        setPartName(file.getName());
        doSave(getActionBars().getStatusLineManager().getProgressMonitor());
      }
    }
  }
  public static void addTableForSpecifiedDataPackage(
      DatabaseConnection dbconn, MetadataTable dbtable)
      throws ClassNotFoundException, InstantiationException, IllegalAccessException, SQLException {
    // if the database connection is contextmodel, need to get the original value of every parameter
    IMetadataConnection imetadataConnection = ConvertionHelper.convert(dbconn);
    DatabaseConnection conn = (DatabaseConnection) imetadataConnection.getCurrentConnection();
    Collection<orgomg.cwm.objectmodel.core.Package> newDataPackage =
        EcoreUtil.copyAll(dbconn.getDataPackage());
    ConnectionHelper.addPackages(newDataPackage, conn);

    // String catalog = "";
    // fixed bug TDI-19395
    String catalog = imetadataConnection.getDatabase();
    String schema = "";
    EObject container = dbtable.eContainer();
    if (container != null) {
      if (container instanceof Schema) {
        schema = ((Schema) container).getName();
        EObject c = container.eContainer();
        if (c != null && c instanceof Catalog) {
          catalog = ((Catalog) c).getName();
        }
      } else if (container instanceof Catalog) {
        catalog = ((Catalog) container).getName();
      }
    }
    boolean isAccess =
        EDatabaseTypeName.ACCESS.getDisplayName().equals(imetadataConnection.getDbType());
    if (!isAccess) {
      schema = ExtractMetaDataUtils.getInstance().getMeataConnectionSchema(imetadataConnection);
    }
    addTableForTemCatalogOrSchema(catalog, schema, dbconn, dbtable, imetadataConnection);
  }
  @Override
  public Command createCommand(Collection<?> selection) {
    EStructuralFeature ef = feature;
    EObject owner = (EObject) viewer.getInput();
    if (domain.getClipboard() == null) {
      return UnexecutableCommand.INSTANCE;
    }
    Collection<Object> objs = getPasteObjs(EcoreUtil.copyAll(domain.getClipboard()), eclass);
    if (objs.size() > 0) {
      if (!MetadataViewerUtil.isShowCategory(viewer)) {
        return AddCommand.create(getEditingDomain(), owner, ef, objs);
      }
      MetadataCategory cate = MetadataViewerUtil.getSelectedCategory(viewer, false);
      if (cate instanceof UncategorizedItemsCategoryImpl) {
        return AddCommand.create(getEditingDomain(), owner, ef, objs);
      } else if (cate instanceof MetadataCategory) {
        CompoundCommand command = new CompoundCommand();
        command.append(
            AddCommand.create(
                getEditingDomain(), cate, MetadataPackage.Literals.METADATA_CATEGORY__ITEMS, objs));

        command.append(AddCommand.create(getEditingDomain(), owner, ef, objs));
        // 再添加到分组

        return command;
      }
    }
    return UnexecutableCommand.INSTANCE;
  }
 /**
  * @param copyObjs
  * @return 转换为粘贴对象
  */
 private Collection<Object> getPasteObjs(Collection<Object> copyObjs, EClass eclass) {
   List<Object> objs = new ArrayList<Object>();
   Map<EStructuralFeature, EStructuralFeature> map =
       new HashMap<EStructuralFeature, EStructuralFeature>();
   // 由第一个复制对象,找出复制对象和粘贴对象匹配的属性
   Iterator<Object> it = copyObjs.iterator();
   if (it.hasNext()) {
     Object obj = it.next();
     if (obj instanceof EObject) {
       EObject copyObj = (EObject) obj;
       // 如果是同一个编辑器内进行粘贴,直接返回复制对象集合
       if (copyObj.eClass().equals(eclass)) {
         return copyObjs;
       }
       // name一样,则表示属性匹配
       for (EStructuralFeature copyFeature : copyObj.eClass().getEAllStructuralFeatures()) {
         if (!exclude.contains(copyFeature)) {
           for (EStructuralFeature pasteFeature : eclass.getEAllStructuralFeatures()) {
             if (StringUtils.equals(copyFeature.getName(), pasteFeature.getName())) {
               map.put(copyFeature, pasteFeature);
               break;
             }
           }
         }
       }
     }
   }
   // 如果没有匹配的属性,则返回空集合
   if (map.isEmpty()) {
     return objs;
   }
   for (Object obj : copyObjs) {
     EObject copyObj = (EObject) obj;
     EObject pasteObj = eclass.getEPackage().getEFactoryInstance().create(eclass);
     for (Entry<EStructuralFeature, EStructuralFeature> entry : map.entrySet()) {
       EStructuralFeature copyFeature = entry.getKey();
       EStructuralFeature pasteFeature = entry.getValue();
       if (copyFeature instanceof EAttribute) {
         // 设置匹配属性值
         pasteObj.eSet(pasteFeature, copyObj.eGet(copyFeature));
       } else if (copyFeature instanceof EReference) {
         // 设置匹配子集
         Collection<Object> tmp = (Collection<Object>) copyObj.eGet(copyFeature);
         if (tmp != null) {
           pasteObj.eSet(
               pasteFeature,
               getPasteObjs(
                   EcoreUtil.copyAll(tmp), ((EReference) pasteFeature).getEReferenceType()));
         }
       }
     }
     objs.add(pasteObj);
   }
   return objs;
 }
示例#6
0
 private void copyContent(Scenario source, Scenario target) {
   target.setContent(EcoreUtil.copy(source.getContent()));
   target.setTeslaContent(EcoreUtil.copy(source.getTeslaContent()));
   target.getAttachments().clear();
   target.getAttachments().addAll(EcoreUtil.copyAll(source.getAttachments()));
   target.getContexts().clear();
   target.getContexts().addAll(source.getContexts());
   target.getVerifications().clear();
   target.getVerifications().addAll(source.getVerifications());
   target.setDescription(source.getDescription());
 }
 private MPart createPart(MPartDescriptor descriptor) {
   if (descriptor == null) {
     return null;
   }
   MPart part = modelService.createModelElement(MPart.class);
   part.setElementId(descriptor.getElementId());
   part.getMenus().addAll(EcoreUtil.copyAll(descriptor.getMenus()));
   if (descriptor.getToolbar() != null) {
     part.setToolbar((MToolBar) EcoreUtil.copy((EObject) descriptor.getToolbar()));
   }
   part.setContributorURI(descriptor.getContributorURI());
   part.setCloseable(descriptor.isCloseable());
   part.setContributionURI(descriptor.getContributionURI());
   part.setLabel(descriptor.getLabel());
   part.setIconURI(descriptor.getIconURI());
   part.setTooltip(descriptor.getTooltip());
   part.getHandlers().addAll(EcoreUtil.copyAll(descriptor.getHandlers()));
   part.getTags().addAll(descriptor.getTags());
   part.getPersistedState().putAll(descriptor.getPersistedState());
   part.getBindingContexts().addAll(descriptor.getBindingContexts());
   return part;
 }
  /**
   * Obtains the operations declared on the specified type.
   *
   * @param classifierName The name of the classifier which operation are sought.
   * @return The operations it declares. <code>null</code> if none.
   */
  public synchronized EList<EOperation> getExistingOperations(String classifierName) {
    EList<EOperation> result = new BasicEList<EOperation>();

    if (PRIMITIVE_STRING_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(stringType.getEOperations()));
    } else if (TYPE_OCLANY_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(oclAnyType.getEOperations()));
    } else if (TYPE_EOBJECT_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(eObjectType.getEOperations()));
    } else if (TYPE_COLLECTION_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(collectionType.getEOperations()));
    } else if (TYPE_ORDEREDSET_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(orderedSetType.getEOperations()));
    } else if (TYPE_SEQUENCE_NAME.equals(classifierName)) {
      result.addAll(EcoreUtil.copyAll(sequenceType.getEOperations()));
    }
    return result;
  }
示例#9
0
 private void createActivityParameters(BehavioralFeature specification) {
   getProduct().getOwnedParameters().addAll(EcoreUtil.copyAll(specification.getOwnedParameters()));
 }
示例#10
0
  protected void createBroadcast(String id, Port port, List<? extends Edge> outList) {

    // Add broadcast vertex
    Actor bcast = dfFactory.createActor();
    bcast.setName(id + "_" + port.getName());

    Instance instance = dfFactory.createInstance(id + "_" + port.getName() + "_bcast", bcast);
    network.add(instance);

    Type portVarType = irFactory.createTypeList(1, port.getType());

    Pattern inputPattern = dfFactory.createPattern();
    Pattern outputPattern = dfFactory.createPattern();

    Port input = dfFactory.createPort(EcoreUtil.copy(port.getType()), "input");
    bcast.getInputs().add(input);

    // Creates a connection between the vertex and the broadcast
    Connection conn = (Connection) outList.get(0);
    Connection incoming =
        dfFactory.createConnection(
            conn.getSource(),
            conn.getSourcePort(),
            instance,
            input,
            EcoreUtil.copyAll(conn.getAttributes()));
    incoming.getAttributes().addAll(EcoreUtil.copyAll(conn.getAttributes()));
    network.getConnections().add(incoming);

    inputPattern.setNumTokens(input, 1);
    inputPattern.setVariable(input, irFactory.createVar(portVarType, "input", true, 0));

    // Change the source of the other connections
    int i = 0;
    for (Edge edge : outList) {
      Port output = dfFactory.createPort(EcoreUtil.copy(port.getType()), "output_" + i);
      bcast.getOutputs().add(output);

      Connection connection = (Connection) edge;
      connection.setSourcePort(output);
      connection.setSource(instance);

      outputPattern.setNumTokens(output, 1);
      outputPattern.setVariable(output, irFactory.createVar(portVarType, "output_" + i, true, 0));

      i++;
    }

    // Create body of the broadcast
    Procedure body = irFactory.createProcedure("copy", 0, irFactory.createTypeVoid());
    Var tmpVar = body.newTempLocalVariable(IrUtil.copy(port.getType()), "tmp");
    BlockBasic block = IrUtil.getLast(body.getBlocks());

    block.add(irFactory.createInstLoad(tmpVar, inputPattern.getVariable(input), 0));
    for (Port output : bcast.getOutputs()) {
      block.add(irFactory.createInstStore(outputPattern.getVariable(output), 0, tmpVar));
    }

    // Create the scheduler
    Procedure scheduler =
        irFactory.createProcedure("isSchedulable_copy", 0, irFactory.createTypeBool());
    BlockBasic block2 = IrUtil.getLast(scheduler.getBlocks());
    block2.add(irFactory.createInstReturn(irFactory.createExprBool(true)));

    Action copy =
        dfFactory.createAction(
            "copy", inputPattern, outputPattern, dfFactory.createPattern(), scheduler, body);

    bcast.getActions().add(copy);
    bcast.getActionsOutsideFsm().add(copy);
  }