private void buildTree(
     final SimpleTree<Object> parent, final Map<String, Page> idToPageMap, final String pageId) {
   final Page page = idToPageMap.get(pageId);
   final SimpleTree<Object> node = new SimpleTree<Object>(parent, page.getName().getText(), page);
   for (final Instance instance : page.instance()) {
     buildTree(node, idToPageMap, instance.getSubPageID());
   }
 }
  private void updateModel(final IFile file) {
    final TransactionalEditingDomain domain =
        TransactionalEditingDomain.Factory.INSTANCE.createEditingDomain();
    final ResourceSet resourceSet = domain.getResourceSet();
    EObject diagramRoot = null;
    try {
      final URI domainModelURI = URI.createPlatformResourceURI(file.getFullPath().toString(), true);
      final Resource resource = resourceSet.getResource(domainModelURI, true);
      diagramRoot = resource.getContents().get(0);
    } catch (final Exception ex) {
      ex.printStackTrace();
    }

    PetriNet petriNet = null;
    if (diagramRoot == null || !(diagramRoot instanceof PetriNet)) {
      throw new NotAPetriNetException("The diagram root is not a Petri net", diagramRoot);
    } else {
      petriNet = (PetriNet) diagramRoot;
    }

    if (fileToTreeMap == null) {
      fileToTreeMap = new HashMap<IFile, SimpleTree<Object>>();
    }
    final HashSet<String> primePages = new HashSet<String>();
    final HashSet<String> notPrimePages = new HashSet<String>();
    final Map<String, Page> idToPageMap = new HashMap<String, Page>();

    for (final Page page : petriNet.getPage()) {
      idToPageMap.put(page.getId(), page);
      for (final Instance instance : page.instance()) {
        notPrimePages.add(instance.getSubPageID());
      }
      primePages.add(page.getId());
    }
    primePages.removeAll(notPrimePages);

    final SimpleTree<Object> root = new SimpleTree<Object>("Root");
    final SimpleTree<Object> declarations =
        new SimpleTree<Object>(root, CPNModelContentProvider.DECLARATION_HEADER);
    for (final HLDeclaration decl : petriNet.declaration()) {
      String declText = decl.getStructure().asShortString().replace('\n', ' ');
      declText = declText.replace('\r', ' ');
      final int maxLength = 30;
      if (declText.length() > maxLength) {
        declText = declText.substring(0, maxLength) + "...";
      }

      new SimpleTree<Object>(declarations, declText, decl);
    }

    for (final String pageId : primePages) {
      buildTree(root, idToPageMap, pageId);
    }

    fileToTreeMap.put(file, root);
  }