/**
  * Creates a notification filter which filters notifications that may possibly result in
  * uncontained links.
  *
  * @generated
  */
 private NotificationFilter createUncontainedLinksFilter() {
   return NotificationFilter.createEventTypeFilter(Notification.SET)
       .or(
           NotificationFilter.createEventTypeFilter(Notification.UNSET)
               .or(
                   NotificationFilter.createEventTypeFilter(Notification.REMOVE)
                       .or(NotificationFilter.createEventTypeFilter(Notification.REMOVE_MANY))));
 }
Ejemplo n.º 2
0
 /** @generated */
 public ResourceSetModificationListener(ResourceSetInfo info) {
   myInfo = info;
   myModifiedFilter =
       NotificationFilter.createEventTypeFilter(Notification.SET)
           .or(NotificationFilter.createEventTypeFilter(Notification.UNSET))
           .and(
               NotificationFilter.createFeatureFilter(
                   Resource.class, Resource.RESOURCE__IS_MODIFIED));
 }
 private static void addResourceTrackingModificationAdapter(
     TransactionalEditingDomain editingDomain) {
   EList<Adapter> adapters = editingDomain.getResourceSet().eAdapters();
   Adapter adapter = EcoreUtil.getAdapter(adapters, SetTrackModificationAdapter.class);
   if (adapter == null) {
     final NotificationFilter diagramResourceModifiedFilter =
         NotificationFilter.createNotifierFilter(editingDomain.getResourceSet())
             .and(NotificationFilter.createEventTypeFilter(Notification.ADD))
             .and(
                 NotificationFilter.createFeatureFilter(
                     ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
     adapters.add(new SetTrackModificationAdapter(diagramResourceModifiedFilter));
   }
 }
Ejemplo n.º 4
0
    /** @generated */
    public void notifyChanged(Notification notification) {
      if (notification.getNotifier() instanceof ResourceSet) {
        super.notifyChanged(notification);
      }
      if (!notification.isTouch() && myModifiedFilter.matches(notification)) {
        if (notification.getNotifier() instanceof Resource) {
          Resource resource = (Resource) notification.getNotifier();
          if (resource.isLoaded()) {
            boolean modified = false;
            for (Iterator /*<org.eclipse.emf.ecore.resource.Resource>*/ it =
                    myInfo.getLoadedResourcesIterator();
                it.hasNext() && !modified; ) {
              Resource nextResource = (Resource) it.next();
              if (nextResource.isLoaded()) {
                modified = nextResource.isModified();
              }
            }
            boolean dirtyStateChanged = false;
            synchronized (myInfo) {
              if (modified != myInfo.fCanBeSaved) {
                myInfo.fCanBeSaved = modified;
                dirtyStateChanged = true;
              }
            }
            if (dirtyStateChanged) {
              fireElementDirtyStateChanged(myInfo.getEditorInput(), modified);

              if (!modified) {
                myInfo.setModificationStamp(computeModificationStamp(myInfo));
              }
            }
          }
        }
      }
    }
 public void notifyChanged(Notification notification) {
   if (diagramResourceModifiedFilter.matches(notification)) {
     Object value = notification.getNewValue();
     if (value instanceof Resource) {
       ((Resource) value).setTrackingModification(true);
     }
   }
 }
Ejemplo n.º 6
0
  /** @generated */
  private TransactionalEditingDomain createEditingDomain() {
    TransactionalEditingDomain editingDomain =
        DiagramEditingDomainFactory.getInstance().createEditingDomain();
    editingDomain.setID("StateChartDesign.diagram.EditingDomain"); // $NON-NLS-1$
    final NotificationFilter diagramResourceModifiedFilter =
        NotificationFilter.createNotifierFilter(editingDomain.getResourceSet())
            .and(NotificationFilter.createEventTypeFilter(Notification.ADD))
            .and(
                NotificationFilter.createFeatureFilter(
                    ResourceSet.class, ResourceSet.RESOURCE_SET__RESOURCES));
    editingDomain
        .getResourceSet()
        .eAdapters()
        .add(
            new Adapter() {

              private Notifier myTarger;

              public Notifier getTarget() {
                return myTarger;
              }

              public boolean isAdapterForType(Object type) {
                return false;
              }

              public void notifyChanged(Notification notification) {
                if (diagramResourceModifiedFilter.matches(notification)) {
                  Object value = notification.getNewValue();
                  if (value instanceof Resource) {
                    ((Resource) value).setTrackingModification(true);
                  }
                }
              }

              public void setTarget(Notifier newTarget) {
                myTarger = newTarget;
              }
            });

    return editingDomain;
  }
 /**
  * Creates a notification filter which filters notifications that may possibly affect the
  * notational model
  *
  * @generated
  */
 protected NotificationFilter createFilter() {
   NotificationFilter filter =
       NotificationFilter.createFeatureFilter(MindmapPackage.eINSTANCE.getMap_RootTopics());
   filter =
       filter.or(
           NotificationFilter.createFeatureFilter(MindmapPackage.eINSTANCE.getMap_Resources()));
   filter = filter.and(NotificationFilter.createNotifierFilter(getDiagram().getElement()));
   return filter;
 }
 /**
  * Creates a notification filter which filters notifications that may possibly affect the
  * notational model
  *
  * @generated
  */
 protected NotificationFilter createFilter() {
   NotificationFilter filter =
       NotificationFilter.createFeatureFilter(MindmapPackage.eINSTANCE.getMap_Relations());
   filter =
       filter.or(
           NotificationFilter.createFeatureFilter(
               MindmapPackage.eINSTANCE.getRelationship_Source()));
   filter =
       filter.or(
           NotificationFilter.createFeatureFilter(
               MindmapPackage.eINSTANCE.getRelationship_Target()));
   filter = getConstrainedChildLinksFilter().or(filter);
   filter = filter.or(createUncontainedLinksFilter());
   return filter;
 }
Ejemplo n.º 9
0
 /**
  * Subclasses may override/extend this method to create custom filters, perhaps based on the
  * default filter create by the superclass. <b>Note</b> that this method is invoked by the
  * superclass constructor, so subclasses must not attempt to access their own state.
  *
  * @return my notification filter
  */
 protected NotificationFilter createFilter() {
   return NotificationFilter.createNotifierTypeFilter(ResourceSet.class)
       .or(NotificationFilter.createNotifierTypeFilter(Resource.class));
 }
Ejemplo n.º 10
0
/**
 * Listens for removed Ensembles and closes their editors
 *
 * @author Marco Jacobasch
 */
public class EnsembleRemoveListener extends DemultiplexingListener {

  /** NotificationFilter to select only remove notifications and Ensembles or EnsembleRepository */
  private static final NotificationFilter REMOVE_FILTER =
      NotificationFilter.createEventTypeFilter(Notification.REMOVE)
          .and(
              NotificationFilter.createNotifierTypeFilter(
                      DatamodelPackage.Literals.CONCRETE_ENSEMBLE)
                  .or(
                      NotificationFilter.createNotifierTypeFilter(
                          DatamodelPackage.Literals.ENSEMBLE_REPOSITORY)));

  /** Creates Listener with a NotificationFilter */
  public EnsembleRemoveListener() {
    super(REMOVE_FILTER);
  }

  /**
   * 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);
                  }
                }
              });
    }
  }

  /**
   * Get the current active page to close all editors
   *
   * @return
   */
  private IWorkbenchPage getActivePage() {
    IWorkbenchPage result = null;

    IWorkbench bench = PlatformUI.getWorkbench();
    if (bench != null) {
      IWorkbenchWindow window = bench.getActiveWorkbenchWindow();

      if (window != null) {
        result = window.getActivePage();
      }
    }

    return result;
  }
}