Ejemplo n.º 1
0
  private void addNodeStatechart(statechart.Node node, String fatherLabel) {

    if (root.getLabel().equals(fatherLabel)) root.getChildren().add(node);
    else {
      DFSAdd(root, fatherLabel, node);
    }
  }
Ejemplo n.º 2
0
  private void DFAccess(statechart.Node father) {

    for (int i = 0; i < father.getChildren().size(); i++) {
      IACModel.getNodes().add(StatechartNodeToIACNode(father.getChildren().get(i)));
      DFAccess(father.getChildren().get(i));
    }
  }
Ejemplo n.º 3
0
  private statechart.Node IACNodeToStateChartNode(IAC.Node node) {
    if (node == null) return null;
    statechart.Node item = StatechartFactory.eINSTANCE.createNode();

    item.setActivity(node.getActivity());
    item.setLabel(node.getLabel());
    item.setName(node.getName());
    item.setType(node.getType());

    return item;
  }
Ejemplo n.º 4
0
  /** @generated */
  protected CommandResult doExecuteWithResult(IProgressMonitor monitor, IAdaptable info)
      throws ExecutionException {
    Node newElement = StatechartFactory.eINSTANCE.createNode();

    Node owner = (Node) getElementToEdit();
    owner.getChildren().add(newElement);

    ElementInitializers.getInstance().init_Node_3003(newElement);

    doConfigure(newElement, monitor, info);

    ((CreateElementRequest) getRequest()).setNewElement(newElement);
    return CommandResult.newOKCommandResult(newElement);
  }
Ejemplo n.º 5
0
 private statechart.Node DFSAdd(Node root, String label, statechart.Node node) {
   Iterator<Node> it = root.getChildren().iterator();
   statechart.Node search = null;
   while (it.hasNext()) {
     search = it.next();
     if (search.getLabel().equals(label)) {
       search.getChildren().add((Node) node);
       return search;
     } else if (search.getChildren().size() > 0) {
       Node newsearch = DFSAdd(search, label, node);
       if (newsearch != null) {
         return newsearch;
       }
     }
   }
   return null;
 }
Ejemplo n.º 6
0
 private statechart.Node DFSearch(statechart.Node root, String label) {
   Iterator<Node> it = root.getChildren().iterator();
   statechart.Node search = null;
   while (it.hasNext()) {
     search = it.next();
     if (search.getLabel().equals(label)) {
       //	System.out.println("Label : " + search.getLabel());
       return search;
     } else if (search.getChildren().size() > 0) {
       statechart.Node newsearch = DFSearch(search, label);
       if (newsearch != null) return newsearch;
     }
   }
   // if(search!=null)
   //	System.out.println("To teleutaio "+ search.getLabel());
   return null;
 }
Ejemplo n.º 7
0
  private IAC.Node StatechartNodeToIACNode(statechart.Node node) {
    if (node == null) return null;
    IAC.Node item = IACFactory.eINSTANCE.createNode();

    item.setActivity(node.getActivity());
    item.setLabel(node.getLabel());
    item.setName(node.getName());
    item.setType(node.getType());
    if (node.getFather_of() != null)
      item.getFather_of().add(getNodeIAC(node.getFather_of().getLabel()));

    return item;
  }
Ejemplo n.º 8
0
  private void DFAddVariables(statechart.Node father) {

    for (int i = 0; i < father.getChildren().size(); i++) {
      if (!father.getChildren().get(i).getVariables().isEmpty()) {
        for (int j = 0; j < IACModel.getNodes().size(); j++) {
          IAC.Node n = IACModel.getNodes().get(j);

          if (IACModel.getNodes()
              .get(j)
              .getLabel()
              .equals(father.getChildren().get(i).getLabel())) {
            IAC.Variable var = IACFactory.eINSTANCE.createVariable();
            for (int q = 0; q < father.getChildren().get(i).getVariables().size(); q++) {
              //	System.out.println("StateChartVAR
              // "+father.getChildren().get(i).getVariables().get(q));

              var.setName(father.getChildren().get(i).getVariables().get(q).getName());
              var.setType(father.getChildren().get(i).getVariables().get(q).getType());
              // System.out.println("VAR "+ var);
              for (int p = 0; p < IACModel.getVariables().size(); p++) {
                //	System.out.println("IACMODEL VAR "+ IACModel.getVariables().get(p));
                if (var.getName().equals(IACModel.getVariables().get(p).getName())
                    && var.getType().equals(IACModel.getVariables().get(p).getType())) {
                  //	System.out.println("IACMODEL VAR "+ IACModel.getVariables().get(p));
                  n.getVariables().add(IACModel.getVariables().get(p));
                  if (!n.getVariables().isEmpty()) {
                    System.out.println(n.getVariables().get(0));
                  }
                }
              }
            }
            IACModel.getNodes().set(j, n);
            break;
          }
        }
      }

      DFAddVariables(father.getChildren().get(i));
    }
  }
Ejemplo n.º 9
0
 private statechart.Node getNodeStateChart(String label) {
   if (root.getLabel().equals(label)) return root;
   else return DFSearch(root, label);
 }
Ejemplo n.º 10
0
  public String StateChartToIAC(String filename, String Path) {
    String file = new String();
    statechart.Model old = (statechart.Model) StatechartFactory.eINSTANCE.createModel();
    ResourceSet resourceSet1 = new ResourceSetImpl();
    resourceSet1
        .getResourceFactoryRegistry()
        .getExtensionToFactoryMap()
        .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());

    resourceSet1.getPackageRegistry().put(StatechartPackage.eNS_URI, StatechartPackage.eINSTANCE);
    Resource resource = resourceSet1.createResource(URI.createURI(StatechartPackage.eNS_URI));
    try {
      File source = new File(filename);
      resource.load(new FileInputStream(source), new HashMap<Object, Object>());
      resource.load(null);
      old = (statechart.Model) resource.getContents().get(0);
      root = old.getNodes().get(0);
      IACroot = StatechartNodeToIACNode(root);
      IACModel.getNodes().add(IACroot);

      for (int i = 0; i < root.getChildren().size(); i++) {
        IACModel.getNodes().add(StatechartNodeToIACNode(root.getChildren().get(i)));
        DFAccess(root.getChildren().get(i));
      }

      IAC.Transition item = IACFactory.eINSTANCE.createTransition();
      for (Iterator<statechart.Transition> it = old.getTransitions().iterator(); it.hasNext(); ) {
        statechart.Transition cur = it.next();
        item = IACFactory.eINSTANCE.createTransition();
        item.setName(cur.getName());
        if (cur.getTE() != null) item.setTE(cur.getTE());
        item.setSource(getNodeIAC(cur.getSource().getLabel()));
        item.setTarget(getNodeIAC(cur.getTarget().getLabel()));
        IACModel.getTransitions().add(item);
      }
      IAC.Variable var;
      for (int i = 0; i < old.getVariables().size(); i++) {
        var = IACFactory.eINSTANCE.createVariable();
        var.setName(old.getVariables().get(i).getName());
        var.setType(old.getVariables().get(i).getType());
        IACModel.getVariables().add(var);
      }

      DFAddVariables(root);

      IACModel.setName(old.getName());
      ResourceSet resourceSet = new ResourceSetImpl();

      // Register the appropriate resource factory to handle all file
      // extensions.
      //
      resourceSet
          .getResourceFactoryRegistry()
          .getExtensionToFactoryMap()
          .put(Resource.Factory.Registry.DEFAULT_EXTENSION, new XMIResourceFactoryImpl());

      // Register the package to ensure it is available during loading.
      //
      resourceSet.getPackageRegistry().put(StatechartPackage.eNS_URI, IACPackage.eINSTANCE);

      Resource resource1 = resourceSet.createResource(URI.createURI(IACPackage.eNS_URI));
      resource1.getContents().add(IACModel);
      try {
        file = Path + File.separator + IACModel.getName() + "_new.iac";
        FileOutputStream out = new FileOutputStream(new File(file));
        resource1.save(out, null);
        // createDialog("The new Model is in the file : " +file);
      } catch (Exception e) {
        // TODO: handle exception
        //	createDialog(e.getMessage());
      }
    } catch (FileNotFoundException e) {
      // TODO Auto-generated catch block
      //	createDialog(e.getMessage());
    } catch (IOException e) {
      // TODO Auto-generated catch block
      //	createDialog(e.getMessage());
    }

    return file;
  }