private void addSavedCommentRes(
      DiagramModel parent,
      Resource commentRes,
      Map<Resource, ArtifactFragment> instanceRes2AFMap,
      ReloRdfRepository repo) {
    Comment com = new Comment();
    // get text
    String text = repo.getStatement(commentRes, Comment.commentTxt, null).getObject().toString();
    com.setAnnoLabelText(text);
    parent.addComment(com);
    // get position
    String posX =
        repo.getStatement(commentRes, PointPositionedDiagramPolicy.posX, null)
            .getObject()
            .toString();
    String posY =
        repo.getStatement(commentRes, PointPositionedDiagramPolicy.posY, null)
            .getObject()
            .toString();

    int x = Integer.parseInt(posX);
    int y = Integer.parseInt(posY);
    Point createLoc = new Point(x, y);
    Statement stmt = repo.getStatement(commentRes, Comment.anchoredComment, null);
    if (stmt != null) {
      com.setAnchored(true);
      com.setRelDistance(createLoc);
    }
    setCommentLocation(com, createLoc);
    instanceRes2AFMap.put(commentRes, com);
  }
  @Override
  public void activate() {
    if (isActive()) return;
    super.activate();
    Value detailLevel = null;
    try {
      detailLevel =
          ((RepositoryMgr) ((RootArtifact) getModel()).getRepo())
              .getFileRepo()
              .getStatement(RSECore.createRseUri("DetailNode"), RSECore.detailLevelURI, null)
              .getObject();
    } catch (Throwable t) {

    }
    if (detailLevel != null) {
      ((RootArtifact) getModel())
          .setDetailLevel(Integer.valueOf(((Literal) detailLevel).getLabel()));
    }

    DiagramModel diagramModel = ((DiagramModel) getModel());
    diagramModel.addPropertyChangeListener(this);
    NonEmptyFigureSupport.listenToModel((ArtifactFragment) getModel(), nonEmptyFigure);
    getViewer().getEditDomain().getCommandStack().addCommandStackEventListener(stackEventListener);
    addInstancePanel();

    if (diagramModel.getRepo() != null && diagramModel.getSavedDiagramResource() != null) {
      // Use the file repo to get the information
      ReloRdfRepository repo = diagramModel.getRepo().getFileRepo();
      Map<Resource, ArtifactFragment> instanceRes2AFMap = new HashMap<Resource, ArtifactFragment>();
      instanceResToAF = new HashMap<Resource, ArtifactFragment>();
      addSavedContainee(
          diagramModel, diagramModel.getSavedDiagramResource(), instanceRes2AFMap, repo);
      addSavedControlFlows(
          diagramModel, diagramModel.getSavedDiagramResource(), instanceRes2AFMap, repo);
      addSavedConnections(diagramModel, instanceRes2AFMap, repo);
    }
  }
  private void addControlFlowModel(
      ArtifactFragment parent,
      Resource instanceRes,
      Resource modelRes,
      Map<Resource, ArtifactFragment> instanceRes2AFMap,
      ReloRdfRepository repo,
      DiagramModel diagramModel)
      throws Exception {

    Statement cfLabelStmt = repo.getStatement(modelRes, RSECore.name, null);
    Statement cfType = repo.getStatement(modelRes, RSECore.controlFlowName, null);

    ControlFlowModel cfModel = null;
    String cfTypeString = cfType.getObject().toString();
    if (cfTypeString.equals(RSECore.ifBlock.toString())) {
      cfModel = new IfBlockModel(diagramModel, cfLabelStmt.getObject().toString());

      ((IfBlockModel) cfModel)
          .addElseIfStmts(
              cfTypeString,
              getListOfConditionalStatements(
                  RSECore.ifStmt, modelRes, instanceRes, instanceRes2AFMap, repo));
      ((IfBlockModel) cfModel)
          .setElseStmts(
              getListOfConditionalStatements(
                  RSECore.elseStmt, modelRes, instanceRes, instanceRes2AFMap, repo));
      ((IfBlockModel) cfModel)
          .setThenStmts(
              getListOfConditionalStatements(
                  RSECore.thenStmt, modelRes, instanceRes, instanceRes2AFMap, repo));
    } else if (cfTypeString.equals(RSECore.loopBlock.toString())) {
      cfModel = new LoopBlockModel(diagramModel, cfLabelStmt.getObject().toString());
      ((LoopBlockModel) cfModel)
          .setLoopStmts(
              getListOfConditionalStatements(
                  RSECore.loopStmt, modelRes, instanceRes, instanceRes2AFMap, repo));
    } else if (cfTypeString.equals(RSECore.userControlBlock.toString())) {
      cfModel = new UserCreatedControlFlowModel(diagramModel, cfLabelStmt.getObject().toString());
      ((UserCreatedControlFlowModel) cfModel)
          .setStatements(
              getListOfConditionalStatements(
                  RSECore.conditionalStmt, modelRes, instanceRes, instanceRes2AFMap, repo));
    }

    if (parent instanceof DiagramModel) {
      diagramModel.addChildToConditionalLayer(cfModel);
    } else if (parent instanceof ControlFlowModel) {
      ((ControlFlowModel) parent).addInnerConditionalModel(cfModel);
      cfModel.setOuterConditionalModel((ControlFlowModel) parent);
      diagramModel.firePropertyChange(NodeModel.PROPERTY_CONDITIONAL_CHILDREN, null, cfModel);
    }

    StatementIterator containeeIter = repo.getStatements(modelRes, RSECore.contains, null);
    while (containeeIter.hasNext()) {
      Value obj = containeeIter.next().getObject();
      if (!(obj instanceof Resource)
          || repo.getStatement((Resource) obj, RSECore.model, null) == null)
        throw new Exception(
            "Child resource not found for parent resource: " + instanceRes.toString());

      Resource childInstanceRes = (Resource) obj;

      addControlFlowModel(
          cfModel, instanceRes, childInstanceRes, instanceRes2AFMap, repo, diagramModel);
    }
    //			if(instanceModel!=null)
    //				instanceModel.setInstanceRes(instanceRes);
    //			else
    //				logger.error("Could not create Instance model for resource: " + detailsRes.toString());
  }