Пример #1
0
 private void installAdapterIfMissing(Adapter adapter, EObject context) {
   if (EcoreUtil.getAdapter(context.eAdapters(), RuleNames.class) == null) {
     context.eAdapters().add(adapter);
   } else {
     throw new IllegalStateException("Duplicate adapter");
   }
 }
 @Override
 public List<EObject> getLinkedObjects(EObject context, EReference ref, INode node)
     throws IllegalNodeException {
   try {
     depth++;
     String text = getText(node);
     boolean traceLookup = BaseScopeProvider.LOOKUP.isActive();
     if ((text == null) || "".equals(text)) { // Avoid IQualifiedNameConverter IAE
       if (traceLookup) {
         BaseScopeProvider.LOOKUP.println("" + depth + " Lookup null");
       }
       return Collections.emptyList();
     }
     IScope scope = getScope(context, ref);
     if (traceLookup) {
       //				EObject target = ((ScopeView)scope).getTarget();
       //				String inString = target instanceof ElementCS ? ((ElementCS)target).getSignature() :
       // target.toString();
       //				BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text + " in " + inString);
       BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text);
     }
     if (scope == null) {
       return Collections.emptyList();
     }
     QualifiedName qualifiedName = QualifiedName.create(text);
     List<EObject> linkedObjects = lookUp(scope, qualifiedName);
     if ((linkedObjects.size() <= 0) && text.startsWith("_")) { // Deprecated compatibility
       linkedObjects = lookUp(scope, QualifiedName.create(text.substring(1)));
     }
     if (traceLookup) {
       BaseScopeProvider.LOOKUP.println("" + depth + " Lookup " + text + " failed");
     }
     List<Adapter> eAdapters = context.eAdapters();
     Adapter adapter = EcoreUtil.getAdapter(eAdapters, ExceptionAdapter.class);
     if (adapter != null) {
       eAdapters.remove(adapter);
     }
     if (linkedObjects.size() > 1) {
       if (DEBUG_RETRY.isActive()) {
         scope.getElements(qualifiedName);
       }
       AmbiguitiesAdapter.setAmbiguities(context, linkedObjects);
       return Collections.emptyList();
     }
     if (linkedObjects.size() <= 0) {
       if (DEBUG_RETRY.isActive()) {
         scope.getElements(qualifiedName);
       }
     }
     return linkedObjects;
   } catch (IllegalLibraryException e) {
     context.eAdapters().add(new ExceptionAdapter(e));
     return Collections.emptyList();
   } finally {
     depth--;
   }
 }
  public static void executeIfNeeded(EObject value) {
    List<InsertionAdapter> allAdapters = new ArrayList<InsertionAdapter>();

    for (Adapter adapter : value.eAdapters()) {
      if (adapter instanceof InsertionAdapter) {
        allAdapters.add((InsertionAdapter) adapter);
      }
    }
    value.eAdapters().removeAll(allAdapters);
    for (InsertionAdapter adapter : allAdapters) adapter.execute();
  }
 protected ASPM.resource.ASPM.mopp.ASPMLayoutInformationAdapter getLayoutInformationAdapter(
     org.eclipse.emf.ecore.EObject element) {
   for (org.eclipse.emf.common.notify.Adapter adapter : element.eAdapters()) {
     if (adapter instanceof ASPM.resource.ASPM.mopp.ASPMLayoutInformationAdapter) {
       return (ASPM.resource.ASPM.mopp.ASPMLayoutInformationAdapter) adapter;
     }
   }
   ASPM.resource.ASPM.mopp.ASPMLayoutInformationAdapter newAdapter =
       new ASPM.resource.ASPM.mopp.ASPMLayoutInformationAdapter();
   element.eAdapters().add(newAdapter);
   return newAdapter;
 }
 protected ssl.resource.ssl.ISslReferenceCache getCache(org.eclipse.emf.ecore.EObject object) {
   org.eclipse.emf.ecore.EObject root =
       ssl.resource.ssl.util.SslEObjectUtil.findRootContainer(object);
   java.util.List<org.eclipse.emf.common.notify.Adapter> eAdapters = root.eAdapters();
   for (org.eclipse.emf.common.notify.Adapter adapter : eAdapters) {
     if (adapter instanceof ReferenceCache) {
       ReferenceCache cache = (ReferenceCache) adapter;
       return cache;
     }
   }
   ReferenceCache cache = new ReferenceCache();
   root.eAdapters().add(cache);
   return cache;
 }
Пример #6
0
  @Test
  public void getAddedAndRemoved() {
    final EObject obj00 = EcoreUtil.create(eClass0);
    final EObject obj1 = EcoreUtil.create(eClass1);
    final EObject obj01 = EcoreUtil.create(eClass0);
    final EObject obj02 = EcoreUtil.create(eClass0);
    final List<Notification> messages = new ArrayList<Notification>();
    obj1.eAdapters()
        .add(
            new AdapterImpl() {
              @Override
              public void notifyChanged(Notification msg) {
                messages.add(msg);
              }
            });

    // Add
    obj1.eSet(multiRef, Arrays.asList(new EObject[] {obj00, obj01}));
    EMFUtils.setOrAdd(obj1, multiRef, obj02);

    // Remove
    final List list = (List) obj1.eGet(multiRef);
    list.remove(obj00);
    list.removeAll(Arrays.asList(new EObject[] {obj01, obj02}));

    final List<EObject> addedObjects = new ArrayList<EObject>();
    final List<EObject> removedObjects = new ArrayList<EObject>();
    for (Notification msg : messages) {
      addedObjects.addAll(EMFUtils.getAddedObjects(msg, obj00.getClass()));
      removedObjects.addAll(EMFUtils.getRemovedObjects(msg, obj00.getClass()));
    }

    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), addedObjects);
    assertEquals(Arrays.asList(new EObject[] {obj00, obj01, obj02}), removedObjects);
  }
 @Override
 public boolean add(EObject object) {
   Assert.isTrue(object instanceof TaskReassignment);
   object.eAdapters().add(this);
   ((TaskReassignment) object).setTask(task);
   return super.add(object);
 }
Пример #8
0
 protected void registerSemanticModelListener(final Adapter modelListener) {
   // be default register a listener at the host's semantic model
   registeredSemanticModelElement = getHostSemanticModel();
   if (registeredSemanticModelElement != null) {
     registeredSemanticModelElement.eAdapters().add(modelListener);
   }
 }
Пример #9
0
  @Override
  public IScriptDependency addDependency(IScriptDependency dependency) {
    /*
     * Find the list of dependencies for the object of the specified dependency
     */
    final EObject object = dependency.getObject();
    EList<IScriptDependency> dList = getDependencies().get(object);
    if (dList == null) {
      final BasicEMap.Entry<EObject, EList<IScriptDependency>> entry =
          (Entry<EObject, EList<IScriptDependency>>)
              IScriptEngineFactory.eINSTANCE.create(
                  IScriptEnginePackage.Literals.EOBJECT_TO_SCRIPT_DEPENDENCY_LIST_MAP_ENTRY);
      entry.setKey(object);
      getDependencies().add(entry);
      dList = entry.getValue();
      object.eAdapters().add(myDependencyAdapter);
    }

    /*
     * See if we have an identical entry of the list
     */
    for (final IScriptDependency d : dList) {
      if (d.equals(dependency)) return d;
    }
    dList.add(dependency);

    return dependency;
  }
 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);
   }
 }
 @Override
 public String getDocumentation(EObject o) {
   if (o == null) return null;
   if (o instanceof JvmIdentifiableElement) {
     DocumentationAdapter adapter =
         (DocumentationAdapter) EcoreUtil.getAdapter(o.eAdapters(), DocumentationAdapter.class);
     if (adapter != null) return adapter.getDocumentation();
   }
   return super.getDocumentation(o);
 }
Пример #12
0
 /**
  * {@inheritDoc}
  *
  * @see org.eclipse.jface.dialogs.Dialog#close()
  */
 @Override
 public boolean close() {
   if (objectChangeAdapter != null) {
     selection.eAdapters().remove(objectChangeAdapter);
   }
   if (composedAdapterFactory != null) {
     composedAdapterFactory.dispose();
   }
   return super.close();
 }
Пример #13
0
  public void dispose() {
    comparison = null;
    for (ResourceSet rs : resourceSets) {
      EList<Resource> resources = rs.getResources();
      for (Resource resource : resources) {
        TreeIterator<EObject> allContents = EcoreUtil.getAllProperContents(resource, false);
        while (allContents.hasNext()) {
          final EObject next = allContents.next();
          next.eAdapters().clear();
        }
        resource.eAdapters().clear();
      }

      rs.getResources().clear();
      rs.eAdapters().clear();
    }

    resourceSets = null;

    Job cleanJob =
        new Job("ClearWorkspace") {
          @Override
          protected IStatus run(IProgressMonitor monitor) {
            try {
              // Close & delete projects from workspace
              IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
              for (IProject project : projects) {
                project.close(new NullProgressMonitor());
                project.delete(false, new NullProgressMonitor());
              }
            } catch (CoreException e) {
              Throwables.propagate(e);
            }
            return Status.OK_STATUS;
          }
        };
    cleanJob.schedule();
    try {
      cleanJob.join();
    } catch (InterruptedException e) {
      Throwables.propagate(e);
    }

    if (repository != null) {
      repository.close();
      repository = null;
    }
    for (Runnable disposer : disposers) {
      disposer.run();
    }
    disposers.clear();

    // Delete repository from temp directory
    GitUtil.deleteRepo(repoFile);
  }
Пример #14
0
 protected void replaceProxyInLayoutAdapters(
     org.eclipse.emf.ecore.EObject container,
     org.eclipse.emf.ecore.EObject proxy,
     org.eclipse.emf.ecore.EObject target) {
   for (org.eclipse.emf.common.notify.Adapter adapter : container.eAdapters()) {
     if (adapter instanceof genericity.language.gbind.mopp.GbindLayoutInformationAdapter) {
       genericity.language.gbind.mopp.GbindLayoutInformationAdapter layoutInformationAdapter =
           (genericity.language.gbind.mopp.GbindLayoutInformationAdapter) adapter;
       layoutInformationAdapter.replaceProxy(proxy, target);
     }
   }
 }
Пример #15
0
  @Override
  protected Control createDialogArea(Composite parent) {
    updateTitle();
    final Composite composite = (Composite) super.createDialogArea(parent);
    composite.setBackground(getShell().getDisplay().getSystemColor(SWT.COLOR_WHITE));
    final ScrolledComposite scrolledComposite =
        new ScrolledComposite(composite, SWT.H_SCROLL | SWT.V_SCROLL);
    scrolledComposite.setBackground(composite.getBackground());
    scrolledComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    scrolledComposite.setExpandVertical(true);
    scrolledComposite.setExpandHorizontal(true);

    final Composite content = new Composite(scrolledComposite, SWT.NONE);
    content.setBackground(composite.getBackground());
    GridLayoutFactory.fillDefaults().numColumns(2).equalWidth(false).applyTo(content);
    GridDataFactory.fillDefaults().grab(true, true).align(SWT.FILL, SWT.FILL).applyTo(content);

    try {
      if (view == null) {
        ECPSWTViewRenderer.INSTANCE.render(content, selection);
      } else {
        ECPSWTViewRenderer.INSTANCE.render(content, selection, view);
      }
    } catch (final ECPRendererException ex) {
      Activator.log(ex);
    }

    scrolledComposite.setContent(content);
    final Point point = content.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    content.setSize(point);
    scrolledComposite.setMinSize(point);

    objectChangeAdapter =
        new AdapterImpl() {

          /**
           * {@inheritDoc}
           *
           * @see
           *     org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
           */
          @Override
          public void notifyChanged(Notification msg) {
            super.notifyChanged(msg);
            updateTitle();
          }
        };
    selection.eAdapters().add(objectChangeAdapter);

    return composite;
  }
Пример #16
0
 protected void walk(EObject object) {
   for (EObject child : object.eContents()) {
     Collection<Adapter> adapters = child.eAdapters();
     if (adapters != null) {
       boolean once = false;
       for (Object adapter : adapters) {
         if (adapter != null) {
           if (!once) {
             System.out.println("*** " + child);
             once = true;
           }
           System.out.println("  * " + adapter);
         }
       }
     }
     walk(child);
   }
 }
  public Object getAdapter(Object adaptableObject, Class adapterType) {
    if (adapterType == IValidationStatusProvider.class) {
      EObject eObject = null;

      if (adaptableObject instanceof IModelObject) {
        eObject = getEObject((IModelObject) adaptableObject);
      } else if (adaptableObject instanceof EObject) {
        eObject = (EObject) adaptableObject;
      }

      if (eObject != null) {
        for (Adapter adapter : eObject.eAdapters()) {
          if (adapter instanceof IValidationService) {
            return ((IValidationService) adapter).getValidationStatusProvider();
          }
        }
      }
    }

    return null;
  }
 public static EObject add(EObject object, String featureName, EObject value) {
   value.eAdapters().add(new InsertionAdapter(object, featureName, value));
   return value;
 }
 public static EObject add(EObject object, EStructuralFeature feature, EObject value) {
   value.eAdapters().add(new InsertionAdapter(object, feature, value));
   return value;
 }
  @SuppressWarnings("unchecked")
  public void execute() {
    // if the object into which this value is being added has other adapters execute those first
    executeIfNeeded(object);

    // remove this adapter from the value - this adapter is a one-shot deal!
    value.eAdapters().remove(this);
    try {
      Object o = object.eGet(feature);
    } catch (Exception e1) {
      try {
        Object o = value.eGet(feature);
        // this is the inverse add of object into value
        o = value;
        value = object;
        object = (EObject) o;
      } catch (Exception e2) {
      }
    }
    // if there are any EObjects contained or referenced by this value, execute those adapters first
    executeChildren(value);

    // set the value in the object
    boolean valueChanged = false;
    final EList<EObject> list = feature.isMany() ? (EList<EObject>) object.eGet(feature) : null;
    if (list == null) valueChanged = object.eGet(feature) != value;
    else valueChanged = !list.contains(value);

    if (valueChanged) {
      TransactionalEditingDomain domain = getEditingDomain();
      if (domain == null) {
        if (list == null) object.eSet(feature, value);
        else list.add(value);
        // assign the value's ID if it has one:
        // because of changes made by cascading InsertionAdapters,
        // the object could now be contained in a resource and hence
        // the setID() will need to be executed on the command stack.
        domain = getEditingDomain();
        if (domain == null) {
          ModelUtil.setID(value);
        } else {
          domain
              .getCommandStack()
              .execute(
                  new RecordingCommand(domain) {
                    @Override
                    protected void doExecute() {
                      ModelUtil.setID(value);
                    }
                  });
        }
      } else {
        domain
            .getCommandStack()
            .execute(
                new RecordingCommand(domain) {
                  @Override
                  protected void doExecute() {
                    ExtendedPropertiesAdapter adapter =
                        (ExtendedPropertiesAdapter)
                            AdapterUtil.adapt(object, ExtendedPropertiesAdapter.class);
                    if (adapter != null) {
                      adapter.getFeatureDescriptor(feature).setValue(value);
                    } else {
                      if (list == null) object.eSet(feature, value);
                      else list.add(value);
                    }
                    // assign the value's ID if it has one
                    ModelUtil.setID(value);
                  }
                });
      }
    }
  }
 @Override
 public void addAdapter(Adapter adapter) {
   eObject.eAdapters().add(adapter);
 }
Пример #22
0
 protected void unregisterSemanticModelListener(final Adapter modelListener) {
   if (registeredSemanticModelElement != null) {
     registeredSemanticModelElement.eAdapters().remove(modelListener);
   }
 }
 @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();
   }
 }
 /**
  * Adds adapters on view associated with Edit Part.
  *
  * @param view
  */
 private void addAdapters(View view) {
   EObject element = view.getElement();
   if (element != null) {
     element.eAdapters().add(new PredicateNameRefreshmentAdapter(this));
   }
 }
 @Override
 public void removeAdapter(Adapter adapter) {
   eObject.eAdapters().remove(adapter);
 }
 @Override
 public EObject remove(int index) {
   EObject object = super.remove(index);
   object.eAdapters().remove(this);
   return object;
 }
 public DerivedFeatureAdapter(EObject source, EStructuralFeature derivedFeature) {
   super();
   this.source = (InternalEObject) source;
   this.derivedFeature = derivedFeature;
   source.eAdapters().add(this);
 }