コード例 #1
0
 public static Collection<EObject> getAffectedValues(Notification notification, EClass clz) {
   if (notification.isTouch()) {
     return Collections.emptyList();
   }
   switch (notification.getEventType()) {
     case Notification.ADD:
     case Notification.SET:
       if (clz.isInstance(notification.getNewValue())) {
         return Collections.singletonList((EObject) notification.getNewValue());
       }
       return Collections.emptyList();
     case Notification.REMOVE:
     case Notification.UNSET:
       if (clz.isInstance(notification.getOldValue())) {
         return Collections.singletonList((EObject) notification.getOldValue());
       }
     case Notification.ADD_MANY:
       return affectingObjects(notification.getNewValue(), clz);
     case Notification.REMOVE_MANY:
       return affectingObjects(notification.getOldValue(), clz);
     case Notification.MOVE:
       if (notification.getNotifier() instanceof EObject
           && notification.getFeature() instanceof EStructuralFeature) {
         return affectingObjects(
             ((EObject) notification.getNotifier())
                 .eGet((EStructuralFeature) notification.getFeature()),
             clz);
       }
       return Collections.emptyList();
   }
   return Collections.emptyList();
 }
コード例 #2
0
  /**
   * Checks only if removed object was an Ensemble, if true, closes all open Ensemble Editors.
   *
   * <p>Checking remove event and correct classes is done by the NotificationFilter
   */
  @Override
  protected void handleNotification(TransactionalEditingDomain domain, Notification notification) {

    if (notification.getOldValue() instanceof Ensemble) {
      final Ensemble oldEnsemble = (Ensemble) notification.getOldValue();

      Display.getDefault()
          .asyncExec(
              new Runnable() {
                @Override
                public void run() {
                  IWorkbenchPage page = getActivePage();
                  Ensemble ens = oldEnsemble;

                  if (page != null) {
                    IEditorReference[] editors =
                        page.findEditors(
                            new EnsembleEditorInput(ens),
                            EnsembleEditor.ID,
                            IWorkbenchPage.MATCH_ID | IWorkbenchPage.MATCH_INPUT);

                    page.closeEditors(editors, false);
                  }
                }
              });
    }
  }
コード例 #3
0
  protected void handleResourceContents(Notification msg) {
    Resource.Internal resource = (Resource.Internal) msg.getNotifier();

    // Don't report addition of roots when loading nor removal of roots when unloading
    // because loading and unloading are semantically more significant events
    if (resource.isLoaded() && !resource.isLoading()) {
      switch (msg.getEventType()) {
        case Notification.ADD:
          handleRootAdded(resource, (EObject) msg.getNewValue());
          break;
        case Notification.ADD_MANY:
          for (Object next : (Iterable<?>) msg.getNewValue()) {
            handleRootAdded(resource, (EObject) next);
          }
          break;
        case Notification.REMOVE:
          handleRootRemoved(resource, (EObject) msg.getOldValue());
          break;
        case Notification.REMOVE_MANY:
          for (Object next : (Iterable<?>) msg.getOldValue()) {
            handleRootRemoved(resource, (EObject) next);
          }
          break;
        case Notification.SET:
          handleRootRemoved(resource, (EObject) msg.getOldValue());
          handleRootAdded(resource, (EObject) msg.getNewValue());
          break;
      }
    }
  }
コード例 #4
0
 public static boolean affects(Notification notification, EClass clz) {
   if (notification.isTouch()) {
     return false;
   }
   switch (notification.getEventType()) {
     case Notification.ADD:
     case Notification.SET:
       return clz.isInstance(notification.getNewValue());
     case Notification.REMOVE:
     case Notification.UNSET:
       return clz.isInstance(notification.getOldValue());
     case Notification.ADD_MANY:
       return affects(notification.getNewValue(), clz);
     case Notification.REMOVE_MANY:
       return affects(notification.getOldValue(), clz);
     case Notification.MOVE:
       if (notification.getNotifier() instanceof EObject
           && notification.getFeature() instanceof EStructuralFeature) {
         return affects(
             ((EObject) notification.getNotifier())
                 .eGet((EStructuralFeature) notification.getFeature()),
             clz);
       }
       return false;
   }
   return false;
 }
コード例 #5
0
  protected void handleResourceSetResources(Notification msg) {
    switch (msg.getEventType()) {
      case Notification.ADD:
        {
          Resource resource = (Resource) msg.getNewValue();
          addAdapter(resource);
          handleResourceAdded(resource);
        }
        break;
      case Notification.ADD_MANY:
        for (Object next : (Iterable<?>) msg.getNewValue()) {
          Resource resource = (Resource) next;
          addAdapter(resource);
          handleResourceAdded(resource);
        }
        break;
      case Notification.REMOVE:
        {
          Resource resource = (Resource) msg.getOldValue();
          try {
            handleResourceRemoved(resource);
          } finally {
            removeAdapter(resource);
          }
          break;
        }
      case Notification.REMOVE_MANY:
        for (Object next : (Iterable<?>) msg.getOldValue()) {
          Resource resource = (Resource) next;
          try {
            handleResourceRemoved(resource);
          } finally {
            removeAdapter(resource);
          }
        }
        break;
      case Notification.SET:
        {
          Resource oldResource = (Resource) msg.getOldValue();
          try {
            handleResourceRemoved(oldResource);
          } finally {
            removeAdapter(oldResource);
          }

          Resource newResource = (Resource) msg.getOldValue();
          addAdapter(newResource);
          handleResourceAdded(newResource);
          break;
        }
    }
  }
コード例 #6
0
 /** {@inheritedDoc} */
 public void notifyChanged(Notification notification) {
   // change the label of the figure managed by the host edit part (managed
   // by the parent edit
   // part in general...)
   // it must be changed only if:
   // - the annotation corresponding to the display of the stereotype
   // changes
   // - the stereotype application list has changed
   final int eventType = notification.getEventType();
   if (eventType == PapyrusStereotypeListener.APPLIED_STEREOTYPE) {
     // a stereotype was applied to the notifier
     // then a new listener should be added to the stereotype application
     getDiagramEventBroker().addNotificationListener((EObject) notification.getNewValue(), this);
     createAppliedStereotypeCompartment((EObject) notification.getNewValue());
   } else if (eventType == PapyrusStereotypeListener.UNAPPLIED_STEREOTYPE) {
     getDiagramEventBroker()
         .removeNotificationListener((EObject) notification.getOldValue(), this);
     removeAppliedStereotypeCompartment((EObject) notification.getNewValue());
   }
   // if element that has changed is a stereotype => refresh the label.
   if (notification.getNotifier() instanceof Node
       && (notification.getEventType() == Notification.ADD)
       && (notification.getNewValue() instanceof EAnnotation)) {
     if (UMLVisualInformationPapyrusConstant.STEREOTYPE_ANNOTATION
         == ((EAnnotation) notification.getNewValue()).getSource()) {
       // stereotype annotation has changed => refresh label display
       refreshDisplay();
     }
   }
 }
コード例 #7
0
 protected void highlight(final Notification notification, HighlightingParameters params) {
   int eventType = notification.getEventType();
   if (eventType == ADD || eventType == ADD_MANY) {
     fadeIn(notification.getNewValue(), params);
   } else if (eventType == REMOVE || eventType == REMOVE_MANY) {
     fadeOut(notification.getOldValue(), params);
   }
 }
コード例 #8
0
 public void notifyChanged(Notification notification) {
   if (notification.getNotifier() == value
       && !(notification.getOldValue() instanceof InsertionAdapter)) {
     // execute if an attribute in the new value has changed
     execute();
   } else if (notification.getNotifier() == object && notification.getNewValue() == value) {
     // if the new value has been added to the object, we can remove this adapter
     object.eAdapters().remove(this);
   }
 }
コード例 #9
0
  /*
   * @see org.eclipse.gmf.runtime.diagram.ui.editparts.ConnectionEditPart#handleNotificationEvent(org.eclipse.gmf.runtime.diagram.ui.internal.listener.NotificationEvent)
   */
  protected void handleNotificationEvent(Notification notification) {
    Object feature = notification.getFeature();
    if (NotationPackage.eINSTANCE.getView_SourceEdges().equals(feature)) refreshSourceConnections();
    else if (NotationPackage.eINSTANCE.getView_TargetEdges().equals(feature))
      refreshTargetConnections();
    else super.handleNotificationEvent(notification);

    if (NotationPackage.eINSTANCE.getIdentityAnchor_Id().equals(feature)
        || notification.getNewValue() instanceof IdentityAnchor
        || notification.getOldValue() instanceof IdentityAnchor) {
      anchorChange();
    }
  }
コード例 #10
0
ファイル: XtextResourceSet.java プロジェクト: NiciaB/xtext
 @Override
 public void notifyChanged(Notification notification) {
   final Map<URI, Resource> map = getURIResourceMap();
   if (map != null
       && notification.getFeatureID(Resource.class) == Resource.RESOURCE__URI
       && notification.getNotifier() instanceof Resource) {
     URI oldOne = (URI) notification.getOldValue();
     map.remove(oldOne);
     if (oldOne != null) {
       URI oldNormalized = getURIConverter().normalize(oldOne);
       if (!oldOne.equals(oldNormalized)) map.remove(oldNormalized);
     }
     Resource resource = (Resource) notification.getNotifier();
     registerURI(resource);
   }
   super.notifyChanged(notification);
 }
コード例 #11
0
 private void handlePresentationRegistration(Notification notification) {
   if (editingDomain == null) {
     throw new NullPointerException("Presentation registration, but editingDomain not yet set!");
   }
   if (notification.getEventType() == Notification.ADD) {
     ProrPresentationConfiguration config =
         (ProrPresentationConfiguration) notification.getNewValue();
     System.out.println("Registering: " + config);
     ProrUtil.getConfigItemProvider(config, getRootAdapterFactory())
         .registerPresentationConfiguration(config, editingDomain);
   } else if (notification.getEventType() == Notification.REMOVE) {
     ProrPresentationConfiguration config =
         (ProrPresentationConfiguration) notification.getOldValue();
     System.out.println("Unregistering: " + config);
     ProrUtil.getConfigItemProvider(config, getRootAdapterFactory())
         .unregisterPresentationConfiguration(config);
   }
 }
コード例 #12
0
 protected void updateSimpleRefs(Notification notification) {
   Simple simple = (Simple) notification.getNewValue();
   if (simple != null) { // Add Simple Refs associated with new value
     for (StructValue structValue : getStructValue()) {
       SimpleRef ref = PrfFactory.eINSTANCE.createSimpleRef();
       ref.setRefID(simple.getId());
       ref.setValue(PropertiesUtil.getDefaultValue(simple));
       SimpleRef oldRef = null;
       for (SimpleRef sr : structValue.getSimpleRef()) {
         if (sr.getRefID() != null && sr.getRefID().equals(simple.getId())) {
           oldRef = sr;
           break;
         }
       }
       if (oldRef != null) {
         structValue.getSimpleRef().remove(oldRef);
       }
       int index = this.getStruct().getSimple().indexOf(simple);
       structValue.getSimpleRef().add(index, ref);
     }
   } else { // Remove SimpleRefs associated with the oldValue
     simple = (Simple) notification.getOldValue();
     if (simple != null) {
       for (StructValue structValue : getStructValue()) {
         Collection<SimpleRef> removeRefs = null;
         for (SimpleRef ref : structValue.getSimpleRef()) {
           if (ref.getRefID() != null && simple.getId() != null) {
             if (ref.getRefID().equals(simple.getId())) {
               removeRefs = Collections.singletonList(ref);
               break;
             }
           } else if (ref.getRefID() == null && simple.getId() == null) {
             removeRefs = Collections.singletonList(ref);
             break;
           }
         }
         if (removeRefs != null) {
           structValue.getSimpleRef().removeAll(removeRefs);
         }
       }
     }
   }
 }
コード例 #13
0
  @Override
  public void notifyChanged(Notification msg) {
    Object notifier = msg.getNotifier();

    if (!msg.isTouch()) {
      if (notifier instanceof ResourceSet) {
        if (msg.getFeatureID(ResourceSet.class) == ResourceSet.RESOURCE_SET__RESOURCES) {
          handleResourceSetResources(msg);
        }
      } else if (notifier instanceof Resource) {
        switch (msg.getFeatureID(Resource.class)) {
          case Resource.RESOURCE__IS_LOADED:
            switch (msg.getEventType()) {
              case Notification.SET:
              case Notification.UNSET:
                if (msg.getNewBooleanValue()) {
                  handleResourceLoaded((Resource) notifier);
                } else {
                  handleResourceUnloaded((Resource) notifier);
                }
                break;
            }
            break;
          case Resource.RESOURCE__URI:
            switch (msg.getEventType()) {
              case Notification.SET:
              case Notification.UNSET:
                handleResourceURI(
                    (Resource) notifier, (URI) msg.getOldValue(), (URI) msg.getNewValue());
                break;
            }
            break;
          case Resource.RESOURCE__CONTENTS:
            handleResourceContents(msg);
            break;
        }
      }
    }
  }
コード例 #14
0
        public void notifyChanged(Notification notification) {
          if (debug) {
            DebugTrace.print(
                this, "notifyChanged", "notification=" + notification); // $NON-NLS-1$ //$NON-NLS-2$
          }
          if (!skipEventProcessing) {
            int eventType = notification.getEventType();
            switch (eventType) {
              case Notification.ADD:
                {
                  // A method element, typically a method plug-in, has been
                  // added to the managed library without using an editing
                  // command.
                  Object notifier = notification.getNotifier();
                  Object value = notification.getNewValue();
                  if ((notifier instanceof MethodLibrary) && (value instanceof MethodPlugin)) {
                    Collection affectedObjects = new ArrayList();
                    affectedObjects.add(value);
                    notifyListeners(ILibraryChangeListener.OPTION_NEWCHILD, affectedObjects);
                  }
                  break;
                }

              case Notification.SET:
                {
                  Object notifier = notification.getNotifier();
                  if (notifier != null) {
                    Collection affectedObjects = new ArrayList();
                    affectedObjects.add(notifier);
                    notifyListeners(ILibraryChangeListener.OPTION_CHANGED, affectedObjects);
                  }
                  break;
                }

              case Notification.REMOVE:
                {
                  // Either a method element has been removed from the
                  // containing element, or a method element reference has
                  // been deleted.
                  Object notifier = notification.getNotifier();
                  Object oldValue = notification.getOldValue();
                  Collection affectedObjects = new ArrayList();
                  if (oldValue instanceof EObject && ((EObject) oldValue).eContainer() == null) {
                    // A method element has been deleted.
                    affectedObjects.add(oldValue);
                    notifyListeners(ILibraryChangeListener.OPTION_DELETED, affectedObjects);
                  } else {
                    // A method element reference has been deleted, notify
                    // the listeners that the containing method element has
                    // changed.
                    affectedObjects.add(notifier);
                    notifyListeners(ILibraryChangeListener.OPTION_CHANGED, affectedObjects);
                  }
                  break;
                }

              case Notification.REMOVE_MANY:
                {
                  // Two or more method elements have been removed from
                  // the containing element, or tw or more method element
                  // reference have been deleted.
                  List oldValue = new ArrayList((Collection) notification.getOldValue());
                  ArrayList deletedElements = new ArrayList();
                  ArrayList removedReferences = new ArrayList();
                  if (!oldValue.isEmpty()) {
                    for (Iterator iter = oldValue.iterator(); iter.hasNext(); ) {
                      Object element = iter.next();
                      if (element instanceof EObject) {
                        if (((EObject) element).eContainer() == null) {
                          deletedElements.add(element);
                        } else {
                          removedReferences.add(element);
                        }
                      }
                    }
                  }
                  if (!deletedElements.isEmpty()) {
                    // Two or more method elements have been deleted.
                    notifyListeners(ILibraryChangeListener.OPTION_DELETED, deletedElements);
                  }
                  if (!removedReferences.isEmpty()) {
                    // Two or more method element reference has been
                    // deleted.
                    notifyListeners(ILibraryChangeListener.OPTION_CHANGED, removedReferences);
                  }
                  break;
                }
            }
          }
        }
コード例 #15
0
  @Override
  public void notifyChanged(Notification notification) {
    EObject notifier = (EObject) notification.getNotifier();
    Object feature = notification.getFeature();

    Interaction interaction =
        EMFModelUtil.getRootContainerOfType(notifier, RamPackage.Literals.INTERACTION);

    // Notification could come from the interaction or an operand.
    if (notifier == specification || interaction == specification) {
      if (feature == RamPackage.Literals.FRAGMENT_CONTAINER__FRAGMENTS) {
        if (notification.getEventType() == Notification.ADD) {
          EObject newValue = (EObject) notification.getNewValue();

          RamSwitch<Object> switcher =
              new RamSwitch<Object>() {
                @Override
                public Object caseExecutionStatement(ExecutionStatement object) {
                  addStatementView(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseCombinedFragment(CombinedFragment object) {
                  addCombinedFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseAssignmentStatement(AssignmentStatement object) {
                  addAssignmentStatement(object);
                  return Boolean.TRUE;
                };
              };

          switcher.doSwitch(newValue);
        } else if (notification.getEventType() == Notification.REMOVE) {
          EObject oldValue = (EObject) notification.getOldValue();

          RamSwitch<Object> switcher =
              new RamSwitch<Object>() {
                @Override
                public Object caseExecutionStatement(ExecutionStatement object) {
                  removeInteractionFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseCombinedFragment(CombinedFragment object) {
                  removeCombinedFragment(object);
                  return Boolean.TRUE;
                }

                @Override
                public Object caseAssignmentStatement(AssignmentStatement object) {
                  removeInteractionFragment(object);
                  return Boolean.TRUE;
                }
              };

          switcher.doSwitch(oldValue);
        }
      } else if (feature == RamPackage.Literals.INTERACTION__LIFELINES) {
        switch (notification.getEventType()) {
          case Notification.ADD:
            Lifeline lifeline = (Lifeline) notification.getNewValue();
            addLifelineView(lifeline);
            break;
          case Notification.REMOVE:
            lifeline = (Lifeline) notification.getOldValue();
            removeLifelineView(lifeline);
            break;
        }
      } else if (feature == RamPackage.Literals.INTERACTION__MESSAGES) {
        switch (notification.getEventType()) {
          case Notification.ADD:
            Message message = (Message) notification.getNewValue();
            addMessageView(message);
            break;
          case Notification.REMOVE:
            message = (Message) notification.getOldValue();
            removeMessageView(message);
            break;
        }
      }
    } else if (notifier == layout) {
      if (feature == RamPackage.Literals.CONTAINER_MAP__VALUE) {
        if (notification.getEventType() == Notification.ADD) {
          ElementMapImpl elementMap = (ElementMapImpl) notification.getNewValue();
          LifelineView lifelineView = lifelines.get(elementMap.getKey());
          lifelineView.setLayoutElement(elementMap.getValue());
        }
      }
    }
  }
コード例 #16
0
  public void notifyChanged(Notification notification) {
    super.notifyChanged(notification);

    /*
     * We create partOpened / partClosed events based on both MPartWidget
     * events.
     *
     * The initial MPartVisible events are sent early and don't have the
     * actual implementation included. The MPartWidget events are sent as a
     * final step of "part is created" and therefore we use it to create
     * partOpened events. When the part is closed the widget is set to null.
     */
    if (MApplicationPackage.Literals.UI_ELEMENT__WIDGET.equals(notification.getFeature())) {
      if (notification.getEventType() != Notification.SET) return;
      if (notification.getOldValue() == notification.getNewValue())
        return; // avoid extra notifications
      Object part = notification.getNotifier();
      if (part instanceof MPart) {
        IWorkbenchPartReference ref = toPartRef((MPart) part);
        if (ref != null) {
          boolean isVisible = ((MPart) part).isVisible();
          if (isVisible) {
            if (notification.getNewValue() == null) {
              /*
               * not sure if this is the right place to fix bug
               * 283922 but if there is no widget and
               * isVisible==true, we must be shutting down, and we
               * should not send partOpened notifications.
               */
              return;
            }
            SaveablesList modelManager =
                (SaveablesList)
                    ref.getPart(true).getSite().getService(ISaveablesLifecycleListener.class);
            modelManager.postOpen(ref.getPart(true));
            partList.firePartOpened(ref);
          }
        }
      }
      return;
    }

    // Interpret E4 activation events:
    if (!MApplicationPackage.Literals.ELEMENT_CONTAINER__ACTIVE_CHILD.equals(
        notification.getFeature())) return;

    // at this time we only interpreting SET events
    if (notification.getEventType() != Notification.SET
        || notification.getEventType() != Notification.CREATE) return;

    // make sure something actually changed
    Object oldPart = notification.getOldValue();
    Object newPart = notification.getNewValue();

    // create 3.x visibility events
    if ((newPart != oldPart) && (oldPart instanceof MPart) && (newPart instanceof MPart))
      changeVisibility((MPart) oldPart, (MPart) newPart);

    // create 3.x activation events
    final Object object = e4Context.get(IServiceConstants.ACTIVE_PART);
    if ((newPart != oldPart) && newPart instanceof MPerspective) {
      // let legacy Workbench know about perspective activation
      IWorkbenchPage page = (IWorkbenchPage) e4Context.get(IWorkbenchPage.class.getName());
      if (page != null) {
        String id = ((MPerspective) newPart).getId();
        IPerspectiveDescriptor[] descriptors = page.getOpenPerspectives();
        for (IPerspectiveDescriptor desc : descriptors) {
          if (!id.equals(desc.getId())) continue;
          page.setPerspective(desc);
        }
      }
    }
    if (object instanceof MPart) {
      IWorkbenchPartReference ref = toPartRef((MPart) object);
      if (ref != null) {
        // set the Focus to the newly active part
        IWorkbenchPart part = ref.getPart(true);
        part.setFocus();
        // Update the action bars
        SubActionBars bars = (SubActionBars) ((PartSite) part.getSite()).getActionBars();
        bars.partChanged(part);
        partList.setActivePart(ref);
        if (ref instanceof IEditorReference) {
          IEditorReference editorReference = (IEditorReference) ref;
          partList.setActiveEditor(editorReference);
          final IEditorPart editor = editorReference.getEditor(true);
          e4Context.set(ISources.ACTIVE_EDITOR_NAME, editor);
          e4Context.set(ISources.ACTIVE_EDITOR_ID_NAME, editor.getSite().getId());
          e4Context.set(ISources.ACTIVE_EDITOR_INPUT_NAME, editor.getEditorInput());
        }
      }
    } else {
      partList.setActiveEditor(null);
      e4Context.set(ISources.ACTIVE_EDITOR_NAME, null);
      e4Context.set(ISources.ACTIVE_EDITOR_ID_NAME, null);
      e4Context.set(ISources.ACTIVE_EDITOR_INPUT_NAME, null);
      partList.setActivePart(null);
    }
  }
コード例 #17
0
 @Override
 public void notifyChanged(final Notification notification) {
   super.notifyChanged(notification);
   Object newValue = notification.getNewValue();
   Object oldValue = notification.getOldValue();
   switch (notification.getEventType()) {
     case Notification.ADD:
       if (newValue instanceof DcdComponentInstantiation) {
         final DcdComponentInstantiation object =
             (DcdComponentInstantiation) notification.getNewValue();
         this.modelMap.add(object);
       } else if (newValue instanceof DcdConnectInterface) {
         final DcdConnectInterface object = (DcdConnectInterface) newValue;
         if (object.getSource() == null || object.getTarget() == null || object.getId() == null) {
           return;
         }
         this.modelMap.add(object);
       }
       break;
     case Notification.ADD_MANY:
       for (Object obj : ((Collection<?>) newValue)) {
         if (obj instanceof DcdComponentInstantiation) {
           final DcdComponentInstantiation object = (DcdComponentInstantiation) obj;
           this.modelMap.add(object);
         } else if (newValue instanceof DcdConnectInterface) {
           final DcdConnectInterface object = (DcdConnectInterface) newValue;
           if (object.getSource() == null
               || object.getTarget() == null
               || object.getId() == null) {
             return;
           }
           this.modelMap.add(object);
         }
       }
       break;
     case Notification.REMOVE:
       if (oldValue instanceof DcdComponentInstantiation) {
         final DcdComponentInstantiation object = (DcdComponentInstantiation) oldValue;
         this.modelMap.remove(object);
       } else if (oldValue instanceof DcdComponentPlacement) {
         final DcdComponentPlacement object = (DcdComponentPlacement) oldValue;
         for (DcdComponentInstantiation i : object.getComponentInstantiation()) {
           this.modelMap.remove(i);
         }
       } else if (oldValue instanceof DcdConnectInterface) {
         final DcdConnectInterface object = (DcdConnectInterface) oldValue;
         this.modelMap.remove(object);
       }
       break;
     case Notification.REMOVE_MANY:
       for (Object obj : ((Collection<?>) oldValue)) {
         if (obj instanceof DcdComponentInstantiation) {
           final DcdComponentInstantiation object = (DcdComponentInstantiation) obj;
           this.modelMap.remove(object);
         } else if (oldValue instanceof DcdComponentPlacement) {
           final DcdComponentPlacement object = (DcdComponentPlacement) oldValue;
           for (DcdComponentInstantiation i : object.getComponentInstantiation()) {
             this.modelMap.remove(i);
           }
         } else if (obj instanceof DcdConnectInterface) {
           final DcdConnectInterface object = (DcdConnectInterface) obj;
           this.modelMap.remove(object);
         }
       }
       break;
     default:
       break;
   }
 }
コード例 #18
0
 /**
  * Check if profile applications are correctly duplicated on controlled package and that there is
  * no useless copy left.
  *
  * @see
  *     org.eclipse.emf.validation.AbstractModelConstraint#validate(org.eclipse.emf.validation.IValidationContext)
  * @param ctx validation context
  * @return validation status
  */
 public IStatus validate(IValidationContext ctx) {
   try {
     if (ctx.equals(lastValidatedContext)) {
       return ctx.createSuccessStatus();
     } else {
       lastValidatedContext = ctx;
     }
     EObject eObject = ctx.getTarget();
     // detect profile application creation
     if ((EMFEventType.ADD.equals(ctx.getEventType())
             || EMFEventType.ADD_MANY.equals(ctx.getEventType()))
         && ctx.getFeatureNewValue() instanceof ProfileApplication) {
       ProfileApplication profileAppl = (ProfileApplication) ctx.getFeatureNewValue();
       Package pack = (Package) eObject;
       boolean res = stereotypeApplicationAdded(pack, profileAppl);
       if (!res) {
         return ctx.createFailureStatus();
       }
     }
     // detect profile application deletion
     else if (((EMFEventType.REMOVE.equals(ctx.getEventType())
             && ctx.getFeatureNewValue() instanceof ProfileApplication)
         || EMFEventType.REMOVE_MANY.equals(ctx.getEventType()))) {
       Map<ProfileApplication, Profile> oldAssignement =
           new HashMap<ProfileApplication, Profile>(ctx.getAllEvents().size());
       for (Notification n : ctx.getAllEvents()) {
         // case when profile is removed from profile application : keep the reference
         if (ENotificationImpl.SET == n.getEventType()
             && UMLPackage.eINSTANCE.getProfileApplication_AppliedProfile().equals(n.getFeature())
             && n.getNotifier() instanceof ProfileApplication) {
           Profile profile = (Profile) n.getOldValue();
           ProfileApplication profileAppl = (ProfileApplication) n.getNotifier();
           oldAssignement.put(profileAppl, profile);
         }
         // cases when profile application is removed
         if (ENotificationImpl.REMOVE == n.getEventType()
             && n.getOldValue() instanceof ProfileApplication
             && n.getNotifier() instanceof Package) {
           ProfileApplication profileAppl = (ProfileApplication) n.getOldValue();
           Package pack = (Package) n.getNotifier();
           Profile profile = profileAppl.getAppliedProfile();
           if (profile == null) {
             profile = oldAssignement.get(profileAppl);
           }
           if (profile != null) {
             boolean res = stereotypeApplicationRemoved(pack, profileAppl, profile);
             if (!res) {
               return ctx.createFailureStatus();
             }
           }
         }
       }
     }
     return ctx.createSuccessStatus();
   } catch (RuntimeException rte) {
     // avoid throwing uncaught exception which would disable the constraint
     Activator.getDefault()
         .getLog()
         .log(
             new Status(Status.ERROR, Activator.PLUGIN_ID, Messages.error_during_validation, rte));
     // ensure that the constraint's failure does not prevent modification
     return ctx.createSuccessStatus();
   }
 }
コード例 #19
0
 // CHECKSTYLE:OFF
 @SuppressWarnings("unchecked")
 private void analyseNotification(Notification notification) {
   Object notifier = notification.getNotifier();
   if (notifier instanceof DTable) {
     if (notification.getFeature() == TablePackage.Literals.DTABLE__HEADER_COLUMN_WIDTH) {
       updateHeaderColumnWidth = true;
     } else if (notification.getFeature() == TablePackage.Literals.DTABLE__COLUMNS) {
       // The position is incremented by one cause of the header column
       if (notification.getEventType() == Notification.ADD) {
         if (notification.getNewValue() instanceof DColumn) {
           dColumnsToAdd.put((DColumn) notification.getNewValue(), notification.getPosition() + 1);
         }
       } else if (notification.getEventType() == Notification.MOVE) {
         if (notification.getNewValue() instanceof DColumn) {
           DColumn newValue = (DColumn) notification.getNewValue();
           int newPosition = notification.getPosition() + 1;
           dColumnsToAdd.put(newValue, newPosition);
           dColumnsToRemove.add(newValue);
         }
       } else if (notification.getEventType() == Notification.REMOVE) {
         if (notification.getOldValue() instanceof DColumn) {
           dColumnsToRemove.add((DColumn) notification.getOldValue());
         }
       } else if (notification.getEventType() == Notification.REMOVE_MANY
           && notification.getOldValue() instanceof EList) {
         for (final EObject oldValue : (EList<EObject>) notification.getOldValue()) {
           if (oldValue instanceof DTargetColumn) {
             dColumnsToRemove.add((DColumn) oldValue);
           }
         }
       }
     } else if (notification.getFeature() == ViewpointPackage.Literals.DSEMANTIC_DECORATOR__TARGET
         || notification.getFeature() == TablePackage.Literals.LINE_CONTAINER__LINES) {
       toRefreshInViewerWithUpdateLabels.add(notifier);
     }
   } else if (notifier instanceof DLine) {
     DLine dLine = (DLine) notifier;
     if (notification.getFeature() == TablePackage.Literals.DLINE__LABEL
         || notification.getFeature() == TablePackage.Literals.DLINE__CELLS
         || notification.getFeature() == TablePackage.Literals.DLINE__CURRENT_STYLE) {
       toUpdateInViewer.add(notifier);
     } else if (notification.getFeature() == TablePackage.Literals.DLINE__ORDERED_CELLS) {
       toRefreshInViewerWithUpdateLabels.add(notifier);
     } else if (notification.getFeature() == TablePackage.Literals.LINE_CONTAINER__LINES) {
       toRefreshInViewerWithUpdateLabels.add(notifier);
       // By default created DLine is expand of default value of
       // DLine.collapsed is false
       if (!dLine.isCollapsed()) {
         toExpands.add(dLine);
         analyseExpansionStateOfCreatedChildren(dLine.getLines());
       }
     } else if (notification.getFeature() == TablePackage.Literals.DLINE__VISIBLE) {
       launchGlobalRefreshWithoutUpdateLabels = true;
     } else if (notification.getFeature() == TablePackage.Literals.DLINE__COLLAPSED) {
       analyseExpansion(dLine);
     }
   } else if (notifier instanceof DColumn) {
     DColumn dColumn = (DColumn) notifier;
     if (notification.getFeature() == TablePackage.Literals.DCOLUMN__ORDERED_CELLS) {
       launchGlobalRefreshWithUpdateLabels = true;
     } else if (notification.getFeature() == TablePackage.Literals.DCOLUMN__LABEL) {
       dColumnsToUpdateDirectly.add(dColumn);
     } else if (notification.getFeature() == TablePackage.Literals.DCOLUMN__VISIBLE) {
       dColumnsToVisibilityChanged.put(dColumn, dColumn.isVisible());
     } else if (notification.getFeature() == TablePackage.Literals.DCOLUMN__WIDTH) {
       dColumnsWidthToUpdate.add(dColumn);
     }
   } else if (notification.getFeature() == TablePackage.Literals.DCELL__LABEL
       || notification.getFeature() == TablePackage.Literals.DCELL__CURRENT_STYLE
           && notifier instanceof DCell) {
     DCell dCell = (DCell) notifier;
     DLine dLine = dCell.getLine();
     if (dLine != null) {
       toUpdateInViewer.add(dLine);
     }
   } else if (isDTableElementStyleAttributeChange(notification)) {
     DTableElementStyle dTableElementStyle = (DTableElementStyle) notifier;
     EObject eContainer = dTableElementStyle.eContainer();
     if (eContainer instanceof DCell) {
       DCell dCell = (DCell) eContainer;
       DLine dLine = dCell.getLine();
       toUpdateInViewer.add(dLine);
     } else if (eContainer instanceof DLine) {
       toUpdateInViewer.add(eContainer);
     } else if (eContainer instanceof DColumn) {
       DColumn dColumn = (DColumn) eContainer;
       toRefreshInViewerWithUpdateLabels.add(dColumn.getTable());
     }
   } else if (notification.getNotifier() instanceof DCellStyle
       && isRGBValuesChange(notification)) {
     DCellStyle dCellStyle = (DCellStyle) notification.getNotifier();
     EObject dCellStyleContainer = dCellStyle.eContainer();
     if (dCellStyleContainer instanceof DCell) {
       DCell dCell = (DCell) dCellStyleContainer;
       DLine dLine = dCell.getLine();
       if (dLine != null) {
         toUpdateInViewer.add(dLine);
       }
     }
   }
 }
コード例 #20
0
 @Override
 public void notifyChanged(Notification notification) {
   logger.trace("[Source: " + derivedFeature.getName() + "] New notification: " + notification);
   for (DependentFeaturePath path : featurePaths) {
     if (notification.getFeature().equals(path.getNavigationFeature())) {
       logger.trace("Handling notification.");
       switch (notification.getEventType()) {
         case Notification.SET:
           EObject newValue = (EObject) notification.getNewValue();
           EObject tempOldValue = (EObject) notification.getOldValue();
           if (tempOldValue != null) {
             tempOldValue.eAdapters().remove(path.getDependantAdapter());
           } else {
             logger.debug("[DerivedFeatureAdapter] oldValue is not set");
           }
           if (newValue != null) {
             newValue.eAdapters().add(path.getDependantAdapter());
           } else {
             logger.debug("[DerivedFeatureAdapter] new value is not set");
           }
           break;
         case Notification.ADD:
           EObject added = (EObject) notification.getNewValue();
           added.eAdapters().add(path.getDependantAdapter());
           break;
         case Notification.ADD_MANY:
           EObject newValueCollection = (EObject) notification.getNewValue();
           for (Object newElement : (Collection<?>) newValueCollection) {
             ((Notifier) newElement).eAdapters().add(path.getDependantAdapter());
           }
           break;
         case Notification.REMOVE:
           EObject removed = (EObject) notification.getOldValue();
           removed.eAdapters().remove(path.getDependantAdapter());
           break;
         case Notification.REMOVE_MANY:
           EObject oldValueCollection = (EObject) notification.getOldValue();
           for (Object oldElement : (Collection<?>) oldValueCollection) {
             ((Notifier) oldElement).eAdapters().remove(path.getDependantAdapter());
           }
           break;
         case Notification.UNSET:
           EObject unset = (EObject) notification.getOldValue();
           unset.eAdapters().remove(path.getDependantAdapter());
           break;
         case Notification.CREATE:
         case Notification.MOVE: // currently no support for ordering
         case Notification.RESOLVE: // TODO is it safe to ignore all of them?
         case Notification.REMOVING_ADAPTER:
           break;
         default:
           logger.debug(
               "[DerivedFeatureAdapter] Unhandled notification: " + notification.getEventType());
           return; // No notification
       }
       refreshDerivedFeature();
     }
   }
   if (localFeatures.contains(notification.getFeature())) {
     logger.trace("Handling notification.");
     refreshDerivedFeature();
   }
 }
コード例 #21
0
 @Override
 public void notifyChanged(Notification msg) {
   switch (msg.getFeatureID(Map.class)) {
     case ProjectPackage.MAP__ABSTRACT:
       notifyMapListeners(
           new MapEvent(map, MapEventType.ABSTRACT, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__COLOR_PALETTE:
       notifyMapListeners(
           new MapEvent(map, MapEventType.COLOR_PALETTE, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__COLOUR_SCHEME:
       notifyMapListeners(
           new MapEvent(map, MapEventType.COLOUR_SCHEME, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__COMMAND_STACK:
       notifyMapListeners(
           new MapEvent(map, MapEventType.MAP_COMMAND, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__EDIT_MANAGER_INTERNAL:
       notifyMapListeners(
           new MapEvent(map, MapEventType.EDIT_MANAGER, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__LAYER_FACTORY:
       notifyMapListeners(
           new MapEvent(map, MapEventType.LAYER_FACTORY, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__NAME:
       notifyMapListeners(
           new MapEvent(map, MapEventType.NAME, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__NAV_COMMAND_STACK:
       notifyMapListeners(
           new MapEvent(map, MapEventType.NAV_COMMAND, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__PROJECT_INTERNAL:
       notifyMapListeners(
           new MapEvent(map, MapEventType.PROJECT, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__RENDER_MANAGER_INTERNAL:
       notifyMapListeners(
           new MapEvent(map, MapEventType.RENDER_MANAGER, msg.getNewValue(), msg.getOldValue()));
       break;
     case ProjectPackage.MAP__VIEWPORT_MODEL_INTERNAL:
       notifyMapListeners(
           new MapEvent(map, MapEventType.VIEWPORT_MODEL, msg.getNewValue(), msg.getOldValue()));
       break;
     default:
       break;
   }
 }
コード例 #22
0
  public void notifyChanged(Notification notification) {
    int type = notification.getEventType();
    int featureId = notification.getFeatureID(CoremodelPackage.class);

    if (notification.getNotifier() instanceof CoreModel) {
      if (type == Notification.REMOVE)
        switch (featureId) {
          case CoremodelPackage.CORE_MODEL__COMPONENTS:
            if (getCastedVisualModel().getDiagram() != null
                && notification.getOldValue() == getCastedSemanticModel())
              appendToLastAndExecuteCommand(getDeleteComponentCommand());

          case CoremodelPackage.CORE_MODEL__STEREOTYPES:
            if (notification.getOldValue() == getCastedSemanticModel().getStereotype()) {
              updateStereotypeName(getCastedFigure());
              refreshVisuals();
            }
        }
      return;
    }

    if (notification.getNotifier() instanceof Stereotype) {
      if (type == Notification.SET && featureId == CoremodelPackage.STEREOTYPE__NAME) {
        updateStereotypeName(getCastedFigure());
        refreshVisuals();
      }
      return;
    }

    if (notification.getNotifier() instanceof Responsibility) {
      if (type == Notification.SET && featureId == CoremodelPackage.RESPONSIBILITY__NAME) {
        updateResponsibilities(getCastedFigure());
        refreshVisuals();
      }
      return;
    }

    if (notification.getNotifier() instanceof ComponentModel) {
      switch (type) {
        case Notification.ADD:
          if (featureId == CoremodelPackage.COMPONENT_MODEL__FEATURES) {
            ((Responsibility) notification.getNewValue()).eAdapters().add(this);
            updateResponsibilities(getCastedFigure());
            refreshVisuals();
          }
          break;
        case Notification.REMOVE:
          if (featureId == CoremodelPackage.COMPONENT_MODEL__FEATURES) {
            ((Responsibility) notification.getOldValue()).eAdapters().remove(this);
            updateResponsibilities(getCastedFigure());
            refreshVisuals();
          }
          if (featureId == CoremodelPackage.COMPONENT_MODEL__OWNED_PORTS)
            notifyChildren(notification);
          break;

        case Notification.SET:
          switch (featureId) {
            case CoremodelPackage.COMPONENT_MODEL__NAME:
              getCastedFigure().setText(getCastedSemanticModel().getName());
              refreshVisuals();
              break;
            case CoremodelPackage.COMPONENT_MODEL__STEREOTYPE:
              updateStereotypeName(getCastedFigure());
              refreshVisuals();
              break;
          }
      }
      return;
    }

    // VisualModel
    featureId = notification.getFeatureID(EditormodelPackage.class);
    switch (type) {
      case Notification.ADD:
      case Notification.REMOVE:
        if (featureId == EditormodelPackage.VISUAL_MODEL__CHILDREN) refreshVisuals();
        break;
      case Notification.SET:
        if (featureId == EditormodelPackage.VISUAL_MODEL__DETAIL_LEVEL) {
          getCastedFigure()
              .showResponsibilites(notification.getNewIntValue() == VisualModel.HIGH_DETAIL);
          refreshVisuals();
        }
        break;
    }
    super.notifyChanged(notification);
  }