@Override
    public void eventsHappenedInCommand(List<SModelEvent> events) {
      for (SModelEvent event : events) {
        if (event.getModelDescriptor() == null) continue;
        if (!myModels.contains(event.getModelDescriptor().getReference())) continue;

        if (event instanceof SModelRootEvent) {
          SModelRootEvent modelRootEvent = (SModelRootEvent) event;
          SNodeReference rootPointer =
              new jetbrains.mps.smodel.SNodePointer(modelRootEvent.getRoot());
          if (modelRootEvent.isRemoved() && myNodes.contains(rootPointer)) {
            myChanged = true;
            return;
          }
        } else if (event instanceof SModelChildEvent) {
          SModelChildEvent modelChildEvent = (SModelChildEvent) event;
          SNodeReference childPointer =
              new jetbrains.mps.smodel.SNodePointer(
                  modelChildEvent.getModel().getReference(),
                  modelChildEvent.getChild().getNodeId());
          if (modelChildEvent.isRemoved() && myNodes.contains(childPointer)) {
            myChanged = true;
            return;
          }
        }
      }
    }
Example #2
0
 @Override
 public void beforeRootRemoved(SModelRootEvent event) {
   synchronized (myLock) {
     removeContextForNode(
         new jetbrains.mps.smodel.SNodePointer(
             event.getModel().getReference(), event.getRoot().getNodeId()));
   }
 }
Example #3
0
 private void processRoot(final SModelRootEvent event) {
   SNode root = event.getRoot();
   final boolean added = event.isAdded();
   if ((added ? root.getModel() == null : root.getModel() != null)) {
     return;
   }
   final SNodeId rootId = root.getNodeId();
   runUpdateTask(
       new _FunctionTypes._void_P0_E0() {
         public void invoke() {
           if (added) {
             removeChanges(
                 rootId,
                 DeleteRootChange.class,
                 new _FunctionTypes._return_P1_E0<Boolean, DeleteRootChange>() {
                   public Boolean invoke(DeleteRootChange ch) {
                     return true;
                   }
                 });
             buildAndAddChanges(
                 new _FunctionTypes._void_P1_E0<ChangeSetBuilder>() {
                   public void invoke(ChangeSetBuilder b) {
                     b.buildForNode(getOldNode(rootId), event.getRoot());
                   }
                 });
           } else {
             if (removeChanges(
                     rootId,
                     AddRootChange.class,
                     new _FunctionTypes._return_P1_E0<Boolean, AddRootChange>() {
                       public Boolean invoke(AddRootChange ch) {
                         return true;
                       }
                     })
                 == 0) {
               // root was not added
               removeDescendantChanges(rootId);
               buildAndAddChanges(
                   new _FunctionTypes._void_P1_E0<ChangeSetBuilder>() {
                     public void invoke(ChangeSetBuilder b) {
                       b.buildForNode(getOldNode(rootId), null);
                     }
                   });
             }
           }
         }
       },
       null,
       event);
 }