Java Code Examples for org.eclipse.emf.ecore.util.EContentAdapter

The following are top voted examples for showing how to use org.eclipse.emf.ecore.util.EContentAdapter. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: openhab1-addons   File: TinkerforgeBinding.java   View source code 7 votes vote down vote up
/**
 * Adds a listener {@link EContentAdapter} to the {@link Ecosystem}. The listener handles updated
 * sensor values and posts them to the openhab eventbus by
 * {@link #processTFDeviceValues(Notification) processTFDeviceValues}. Furthermore the addition
 * and removal of devices is handled by {@link #initializeTFDevices(Notification)
 * initializeTFDevices}.
 *
 * @param tinkerforgeEcosystem The EMF Ecosystem object.
 */
private void listen2Model(Ecosystem tinkerforgeEcosystem) {
    EContentAdapter modelAdapter = new EContentAdapter() {
        @Override
        public void notifyChanged(Notification notification) {
            super.notifyChanged(notification);
            logger.debug("TinkerforgeNotifier was notified");
            if (notification.getEventType() == Notification.ADD
                    || notification.getEventType() == Notification.ADD_MANY
                    || notification.getEventType() == Notification.REMOVE
                    || notification.getEventType() == Notification.REMOVE_MANY) {
                initializeTFDevices(notification);
            } else {
                processTFDeviceValues(notification);
            }
        }

    };
    tinkerforgeEcosystem.eAdapters().add(modelAdapter);
}
 
Example 2
Project: n4js   File: N4JSResource.java   View source code 6 votes vote down vote up
/**
 * Creates a custom notification and sends it for proxy and loaded object. Registers adapters to loaded object.
 *
 * @param idx
 *            index in the contents list (first or second slot)
 * @param oldProxy
 *            the proxified object before being loaded
 */
protected void notifyProxyResolved(int idx, EObject oldProxy) {
	if (eNotificationRequired() && idx < contents.size()) {
		EObject newObject = contents.basicGet(idx);
		Notification notification = new NotificationImpl(Notification.RESOLVE, oldProxy, newObject) {
			@Override
			public Object getNotifier() {
				return N4JSResource.this;
			}

			@Override
			public int getFeatureID(Class<?> expectedClass) {
				return RESOURCE__CONTENTS;
			}
		};
		eNotify(notification);
		for (Adapter adapter : eAdapters()) {
			if (adapter instanceof EContentAdapter && !newObject.eAdapters().contains(adapter)) {
				newObject.eAdapters().add(adapter);
			}
		}
	}
}
 
Example 3
Project: termsuite-ui   File: PipelinePart.java   View source code 6 votes vote down vote up
@Inject @Optional
private void init(@UIEventTopic(TermSuiteEvents.EDITOR_INITIATED) Object part, MPart mPart) {
	if(this == part) {
		EPipeline pipeline = (EPipeline) context.get(TermSuiteUI.INPUT_OBJECT);
		this.pipelineValue.setValue(pipeline);
		this.context.set(EPipeline.class, pipeline);
		pipeline.eAdapters().add(new EContentAdapter() {
			public void notifyChanged(Notification notification) {
				super.notifyChanged(notification);
				if(notification.getFeature().equals(TermsuiteuiPackage.eINSTANCE.getEPipeline_Name())) {
					mPart.setLabel(notification.getNewStringValue());
				} else {
					// set dirty, unless this is a pipeline rename
					dirty.setDirty(true);
					validatePipeline();
				}
			}
		});
		validatePipeline();
	}
}
 
Example 4
Project: openhab-hdl   File: TinkerforgeBinding.java   View source code 6 votes vote down vote up
/**
 * Adds a listener {@link EContentAdapter} to the {@link Ecosystem}. The listener handles updated
 * sensor values and posts them to the openhab eventbus by
 * {@link #processTFDeviceValues(Notification) processTFDeviceValues}. Furthermore the addition
 * and removal of devices is handled by {@link #initializeTFDevices(Notification)
 * initializeTFDevices}.
 * 
 * @param tinkerforgeEcosystem The EMF Ecosystem object.
 */
private void listen2Model(Ecosystem tinkerforgeEcosystem) {
  EContentAdapter modelAdapter = new EContentAdapter() {
    @Override
    public void notifyChanged(Notification notification) {
      super.notifyChanged(notification);
      logger.debug("TinkerforgeNotifier was notified");
      if (notification.getEventType() == Notification.ADD
          || notification.getEventType() == Notification.ADD_MANY
          || notification.getEventType() == Notification.REMOVE
          || notification.getEventType() == Notification.REMOVE_MANY) {
        initializeTFDevices(notification);
      } else {
        processTFDeviceValues(notification);
      }
    }

  };
  tinkerforgeEcosystem.eAdapters().add(modelAdapter);
}
 
Example 5
Project: termsuite-ui   File: TerminologyPart.java   View source code 5 votes vote down vote up
@Inject @Optional
	private void init(@UIEventTopic(TermSuiteEvents.EDITOR_INITIATED) Object part, MPart mPart) {
		if(this == part) {
			ETerminology terminology = (ETerminology)context.get(TermSuiteUI.INPUT_OBJECT);
			terminology.eAdapters().add(new EContentAdapter() {
				public void notifyChanged(Notification notification) {
					super.notifyChanged(notification);
					if(notification.getFeature().equals(TermsuiteuiPackage.eINSTANCE.getETerminology_Name())) {
						mPart.setLabel(toPartLabel(terminology));
					} else {
						// set dirty
//						dirty.setDirty(true);
					}
				}
			});
			final IndexedCorpus indexedCorpus = eTerminologyService.readTerminology(terminology);
			context.set(IndexedCorpus.class, indexedCorpus);
			context.set(Terminology.class, indexedCorpus.getTerminology());
			final TerminologyService terminologyService = eTerminologyService.getTerminologyService(terminology);
			context.set(TerminologyService.class, terminologyService);
			Job job = Job.create("Open terminology", monitor -> {
				sync.asyncExec(() -> viewer.setInput(terminologyService));
				return Status.OK_STATUS;
			});
			job.schedule();
		}
	}
 
Example 6
Project: dawn-marketplace-server   File: SolutionEditor.java   View source code 5 votes vote down vote up
@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
	setSite(site);
	setInput(input);

	fSaveAction= ActionFactory.SAVE.create(getSite().getWorkbenchWindow());
	site.getActionBars().setGlobalActionHandler(ActionFactory.SAVE.getId(), fSaveAction);
	site.getActionBars().updateActionBars();
	
	FileEditorInput i = (FileEditorInput) input;
	try {
		node = MarketplaceSerializer.loadNode(i.getPath().toFile());
	} catch (Exception e) {
		// TODO: Notify about error loading
	}
	if (node==null) {
		node = MarketplaceFactory.eINSTANCE.createNode();
	}
	// detect changes
	EContentAdapter adapter = new EContentAdapter() {
		@Override
		public void notifyChanged(org.eclipse.emf.common.notify.Notification notification) {
			super.notifyChanged(notification);				
			dirty = true;
			SolutionEditor.this.firePropertyChange(IEditorPart.PROP_DIRTY);
			SolutionEditor.this.setPartName(getSolutionTitle());
		}
	};
	node.eAdapters().add(adapter);
	adapter.setTarget(node);
	setPartName(getSolutionTitle());
	firePropertyChange(IEditorPart.PROP_DIRTY);
}
 
Example 7
Project: xtext-core   File: GenericUnloaderTest.java   View source code 5 votes vote down vote up
@Test public void testHandleContentAdapter() throws Exception {
	EPackage root = createExample();
	EContentAdapter eContentAdapter = new EContentAdapter();
	root.eAdapters().add(eContentAdapter);
	IReferableElementsUnloader.GenericUnloader genericUnloader = new IReferableElementsUnloader.GenericUnloader();
	try {
		genericUnloader.unloadRoot(root);
	} catch (StackOverflowError e) {
		e.printStackTrace();
		fail("Unload does not cope with contentAdpaters");
	}
	// isEmtpy() does not work in EMF 3.5
	assertEquals(0, root.eAdapters().size());
}
 
Example 8
Project: eavp   File: FXAttachment.java   View source code 5 votes vote down vote up
@Override
public void addGeometry(Geometry geom) {
	super.addGeometry(geom);

	if (fxAttachmentNode == null) {
		fxAttachmentNode = new Group();
	}

	if (knownParts == null) {
		knownParts = new ArrayList<>();
	}

	// If the geometry is not recognized, add it
	if (!knownParts.contains(geom)) {

		// Register to listen for changes from the geometry or its children
		// INodes
		geom.eAdapters().add(new EContentAdapter() {

			@Override
			public void notifyChanged(Notification notification) {
				handleUpdate(geom, notification);
			}
		});

		// Add the geometry to the list of known parts
		knownParts.add(geom);

		// Have the geometry refreshed when it is added
		handleUpdate(geom, null);

	}
}
 
Example 9
Project: Environment   File: EObjectWrapper.java   View source code 5 votes vote down vote up
public EObjectWrapper(T master, List<T> slaves)
{
	this.slaves = slaves;
	this.master = master;

	this.master.eAdapters().add(new EContentAdapter()
	{
		@Override
		public void notifyChanged(Notification notification)
		{
			super.notifyChanged(notification);
			
			// Mind only 1-6 : SET, UNSET, ADD, REMOVE, ADD_ALL, REMOVE_ALL
			if (notification.getEventType() > 6 || notification.getEventType()<1)
				return;

			for (EObject slave : EObjectWrapper.this.slaves)
			{
				if (notification.getNotifier() != EObjectWrapper.this.master)
				{
					if (((EObject)notification.getNotifier()).eContainer() == null) return;

					String relativeURIFragmentPath = EcoreUtil.getRelativeURIFragmentPath(
							EObjectWrapper.this.master,
							(EObject) notification.getNotifier());

					EObject subSlave = EcoreUtil.getEObject(slave, relativeURIFragmentPath);
					pushToSlave(subSlave, notification);
				}
				else
				{
					pushToSlave(slave, notification);
				}

			}
		}
	});
}
 
Example 10
Project: Environment   File: InputAlternative.java   View source code 5 votes vote down vote up
private void initModiscoListener()
{
	this.modiscoConfiguration.eAdapters().add(new EContentAdapter(){
		@Override
		public void notifyChanged(Notification msg)
		{
			if (msg.getEventType() == Notification.RESOLVE) return;
			setDirty(true);
		}
	});
}
 
Example 11
Project: clickwatch   File: HandlerEventAdapter.java   View source code 5 votes vote down vote up
@Override
public void init(IInternalNodeConnection connection) {
    super.init(connection);
    if (initializationRequired) {
        connection.getNode().eAdapters().add(new EContentAdapter() {
            @Override
            public void notifyChanged(Notification msg) {
                if (msg.getFeature() == ClickWatchModelPackage.eINSTANCE.getNode_Elements() || 
                        msg.getFeature() == ClickWatchModelPackage.eINSTANCE.getElement_Children() ||
                        msg.getFeature() == ClickWatchModelPackage.eINSTANCE.getElement_Handlers()) {
                    if (!metaDataMightHaveChanged) {
                        logger.log(ILogger.DEBUG, "HandlerEventAdapter realized that meta-data has changed", null);
                    }
                    metaDataMightHaveChanged = true;
                    
                }
                super.notifyChanged(msg);
            }

            @Override
            protected void selfAdapt(Notification notification) {
                if (!(notification.getNotifier() instanceof Handler)) {
                    super.selfAdapt(notification);
                }
            }                             
        });
        initializationRequired = false;
    }
}
 
Example 12
Project: gemoc-studio-modeldebugging   File: SimpleModelChangeListenerAddon.java   View source code 4 votes vote down vote up
public SimpleModelChangeListenerAddon(final IExecutionEngine engine) {
	this.engine = engine;
	changes = new HashMap<>();
	registeredAddons = new HashSet<>();
	adapter = new EContentAdapter() {

		@Override
		public void notifyChanged(Notification notification) {
			super.notifyChanged(notification);
			int eventType = notification.getEventType();
			Object notifier = notification.getNotifier();
			if (eventType < Notification.EVENT_TYPE_COUNT && notifier instanceof EObject && !notification.isTouch()) {
				switch (notification.getEventType()) {
				case Notification.ADD:
				case Notification.ADD_MANY:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getNewValue(),
							FieldChange.ChangeType.ADD);
					break;
				case Notification.REMOVE:
				case Notification.REMOVE_MANY:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getOldValue(),
							FieldChange.ChangeType.REMOVE);
					break;
				case Notification.MOVE:
				case Notification.SET:
				case Notification.UNSET:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getNewValue(),
							FieldChange.ChangeType.MODIFY);
					break;
				}
			}
		}
	};
	Set<Resource> allResources = org.eclipse.gemoc.commons.eclipse.emf.EMFResource.getRelatedResources(this.engine
			.getExecutionContext().getResourceModel());
	allResources.stream().forEach(r -> {
		if (r != null) {
			r.eAdapters().add(adapter);
		}
	});
}
 
Example 13
Project: DarwinSPL   File: DwFeatureModelConfiguratorEditor.java   View source code 4 votes vote down vote up
protected void registerListeners() {

		super.registerControlListeners();
		
		HyVarRecButtonListener hyVarRecButtonListener = new HyVarRecButtonListener();
		ButtonListener buttonListener = new ButtonListener();
		
		selectedConfiguration.eAdapters().add(new EContentAdapter() {
			@Override
			public void notifyChanged(Notification notification) {
				super.notifyChanged(notification);

				selectedConfigurationComposite.setConfiguration(selectedConfiguration, getCurrentSelectedDate());
			}
		});

		validateWithEvolutionButton.addSelectionListener(hyVarRecButtonListener);
		explainWithEvolutionButton.addSelectionListener(hyVarRecButtonListener);
		
		validateContextButton.addSelectionListener(hyVarRecButtonListener);
		explainButton.addSelectionListener(hyVarRecButtonListener);

		simulateButton.addSelectionListener(hyVarRecButtonListener);
		
		checkSatisfiabilityButton.addSelectionListener(buttonListener);
		checkConfigurationValidity.addSelectionListener(buttonListener);

//		numberOfPossibleConfigurationsButton.addSelectionListener(new SelectionAdapter() {
//			@Override
//			public void widgetSelected(SelectionEvent e) {
//				//calculateNumberOfPossibleConfigurations();
//			}
//		});

		selectedConfigurationComposite.getCompleteButton().addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				//autoCompleteVersions();
			}
		});

		selectedConfigurationComposite.getSaveConfigurationButton().addSelectionListener(new DwSaveConfigurationListener(this));
		
		selectedConfigurationComposite.getLoadConfigurationButton().addSelectionListener(new DwLoadConfigurationListener(this));

		selectedConfigurationComposite.getDeriveVariantButton().addSelectionListener(new DwDeriveVariantListener(this));
	}
 
Example 14
Project: ModelDebugging   File: SimpleModelChangeListenerAddon.java   View source code 4 votes vote down vote up
public SimpleModelChangeListenerAddon(final IExecutionEngine engine) {
	this.engine = engine;
	changes = new HashMap<>();
	registeredAddons = new HashSet<>();
	adapter = new EContentAdapter() {

		@Override
		public void notifyChanged(Notification notification) {
			super.notifyChanged(notification);
			int eventType = notification.getEventType();
			Object notifier = notification.getNotifier();
			if (eventType < Notification.EVENT_TYPE_COUNT && notifier instanceof EObject && !notification.isTouch()) {
				switch (notification.getEventType()) {
				case Notification.ADD:
				case Notification.ADD_MANY:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getNewValue(),
							FieldChange.ChangeType.ADD);
					break;
				case Notification.REMOVE:
				case Notification.REMOVE_MANY:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getOldValue(),
							FieldChange.ChangeType.REMOVE);
					break;
				case Notification.MOVE:
				case Notification.SET:
				case Notification.UNSET:
					addFeatureChange((EStructuralFeature) notification.getFeature(),
							(EObject) notification.getNotifier(), notification.getNewValue(),
							FieldChange.ChangeType.MODIFY);
					break;
				}
			}
		}
	};
	Set<Resource> allResources = org.eclipse.gemoc.commons.eclipse.emf.EMFResource.getRelatedResources(this.engine
			.getExecutionContext().getResourceModel());
	allResources.stream().forEach(r -> {
		if (r != null) {
			r.eAdapters().add(adapter);
		}
	});
}
 
Example 15
Project: birt   File: TaskSelectType.java   View source code 4 votes vote down vote up
protected void updateAdapters( )
{
	EObject model = getChartModelObject( );
	
	if ( container instanceof ChartWizard )
	{
		// Refresh all adapters
		EContentAdapter adapter = ( (ChartWizard) container ).getAdapter( );

		model.eAdapters( ).remove( adapter );
		TreeIterator<EObject> iterator = model.eAllContents( );
		while ( iterator.hasNext( ) )
		{
			EObject oModel = iterator.next( );
			oModel.eAdapters( ).remove( adapter );
		}
		model.eAdapters( ).add( adapter );
	}
	else
	{
		// For extension case, create an adapter and add change listener
		EList<Adapter> adapters = model.eAdapters( );
		if ( adapters.isEmpty( ) )
		{
			// Get the previous adapter if existent
			if ( adapter == null )
			{
				adapter = new ChartAdapter( container );
				adapter.addListener( this );
			}
			adapters.add( adapter );
		}
		else
		{
			if ( adapters.get( 0 ) instanceof ChartAdapter )
			{
				( (ChartAdapter) adapters.get( 0 ) ).addListener( this );
			}
		}
	}
}
 
Example 16
Project: birt   File: ChartWizard.java   View source code 4 votes vote down vote up
public EContentAdapter getAdapter( )
{
	return adapter;
}