org.eclipse.emf.common.notify.impl.AdapterImpl Java Examples

The following examples show how to use org.eclipse.emf.common.notify.impl.AdapterImpl. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: xtext-core   Author: eclipse   File: OnChangeEvictingCacheAdapterTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testCacheSurvivesChangesToAdapters() throws Exception {
	EcoreFactory factory = EcoreFactory.eINSTANCE;
	EClass eClass = factory.createEClass();
	Resource resource = new ResourceImpl();
	resource.getContents().add(eClass);
	CacheAdapter ca = new OnChangeEvictingCache().getOrCreate(resource);
	setValue(ca);
	List<Adapter> adapters = resource.eAdapters();
	assertIsSet(ca);
	AdapterImpl adapter = new AdapterImpl();
	adapters.add(adapter);
	assertIsSet(ca);
	adapters.remove(adapter);
	assertIsSet(ca);
}
 
Example #2
Source Project: ice   Author: eclipse   File: GeometryComponent.java    License: Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Mutator method for the held geometry
 * 
 * @param newGeometry
 *            the new Geometry to hold
 */
public void setGeometry(Geometry newGeometry) {
	geometry = newGeometry;

	// Register self as a listener for the geometry
	geometry.eAdapters().add(new AdapterImpl() {

		@Override
		public void notifyChanged(Notification notification) {
			notifyListeners();
		}
	});

	// Notify listeners
	notifyListeners();
}
 
Example #3
Source Project: dsl-devkit   Author: dsldevkit   File: InferenceContainerImplCustom.java    License: Eclipse Public License 1.0 5 votes vote down vote up
protected InferenceContainerImplCustom() {
  eAdapters().add(new AdapterImpl() {
    @SuppressWarnings("unchecked")
    @Override
    public void notifyChanged(final Notification msg) {
      if (msg.getFeature() != ModelInferencePackage.Literals.INFERENCE_CONTAINER__CONTENTS || eResource() == null) {
        return;
      }
      switch (msg.getEventType()) {
      case Notification.ADD:
        addFragmentMapping((EObject) msg.getNewValue());
        break;
      case Notification.ADD_MANY:
        for (EObject newObject : (List<EObject>) msg.getNewValue()) {
          addFragmentMapping(newObject);
        }
        break;
      case Notification.REMOVE:
        objectToFragmentMap.remove(msg.getOldValue());
        break;
      case Notification.REMOVE_MANY:
        for (EObject oldObject : (List<EObject>) msg.getOldValue()) {
          objectToFragmentMap.remove(oldObject);
        }
        break;
      case Notification.MOVE:
      case Notification.SET:
        throw new UnsupportedOperationException("Operations move() and set() are not supported."); //$NON-NLS-1$
      default:
        break;
      }
    }
  });
}
 
Example #4
Source Project: sarl   Author: sarl   File: DocumentationBuilderFragment.java    License: Apache License 2.0 4 votes vote down vote up
/** Generate the adapter that supports the inner documentation.
 */
protected void generateInnerDocumentationAdapter() {
	final TypeReference adapter = getCodeElementExtractor().getInnerBlockDocumentationAdapter();
	final StringConcatenationClient content = new StringConcatenationClient() {
		@Override
		protected void appendTo(TargetStringConcatenation it) {
			it.append("public class "); //$NON-NLS-1$
			it.append(adapter.getSimpleName());
			it.append(" extends "); //$NON-NLS-1$
			it.append(AdapterImpl.class);
			it.append(" {"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append("\tprivate String documentation;"); //$NON-NLS-1$
			it.newLine();
			it.append("\[email protected]"); //$NON-NLS-1$
			it.append(Pure.class);
			it.newLine();
			it.append("\tpublic String getDocumentation() {"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append("\t\treturn this.documentation;"); //$NON-NLS-1$
			it.newLine();
			it.append("\t}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append("\tpublic void setDocumentation(String documentation) {"); //$NON-NLS-1$
			it.newLine();
			it.append("\t\tthis.documentation = documentation;"); //$NON-NLS-1$
			it.newLine();
			it.append("\t}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append("\[email protected]"); //$NON-NLS-1$
			it.append(Pure.class);
			it.newLine();
			it.append("\tpublic boolean isAdapterForType(Object type) {"); //$NON-NLS-1$
			it.newLine();
			it.append("\t\treturn type == "); //$NON-NLS-1$
			it.append(adapter.getSimpleName());
			it.append(".class;"); //$NON-NLS-1$
			it.newLine();
			it.append("\t}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
			it.newLine();
			it.append("}"); //$NON-NLS-1$
			it.newLineIfNotEmpty();
		}

	};
	final JavaFileAccess createJavaFile = getFileAccessFactory().createJavaFile(adapter, content);
	createJavaFile.writeTo(getSrcGen());
}
 
Example #5
Source Project: bonita-studio   Author: bonitasoft   File: GroupsWizardPage.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
protected StructuredViewer createViewer(final Composite parent) {
    final FilteredTree fileredTree = new FilteredTree(parent, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION, new PatternFilter(), true);
    ((Text) ((Composite) fileredTree.getChildren()[0]).getChildren()[0]).setMessage(Messages.search);
    fileredTree.setLayoutData(GridDataFactory.fillDefaults().grab(true, true).minSize(200, 200).create());
    fileredTree.getViewer().setContentProvider(new GroupContentProvider());
    fileredTree.forceFocus();

    groupSingleSelectionObservable = ViewersObservables.observeSingleSelection(fileredTree.getViewer());
    groupSingleSelectionObservable.addValueChangeListener(new IValueChangeListener() {

        private final Adapter groupAdapter = new AdapterImpl() {

            /*
             * (non-Javadoc)
             * @see org.eclipse.emf.common.notify.impl.AdapterImpl#notifyChanged(org.eclipse.emf.common.notify.Notification)
             */
            @Override
            public void notifyChanged(Notification notification) {
                switch (notification.getFeatureID(org.bonitasoft.studio.actors.model.organization.Group.class)) {
                    case OrganizationPackage.GROUP__NAME:
                        handleGroupNameChange(notification);
                        break;
                    default:
                        break;
                }
                super.notifyChanged(notification);
            }
        };

        @Override
        public void handleValueChange(final ValueChangeEvent event) {
            final org.bonitasoft.studio.actors.model.organization.Group previousGroup = (org.bonitasoft.studio.actors.model.organization.Group) event.diff
                    .getOldValue();
            if (previousGroup != null) {
                previousGroup.eAdapters().remove(groupAdapter);
            }
            final org.bonitasoft.studio.actors.model.organization.Group selectedGroup = (org.bonitasoft.studio.actors.model.organization.Group) event.diff
                    .getNewValue();

            if (selectedGroup != null) {
                setControlEnabled(getInfoGroup(), true);
                selectedGroup.eAdapters().add(groupAdapter);
                addSubGroupButton.setEnabled(true);
            } else {
                addSubGroupButton.setEnabled(false);
                setControlEnabled(getInfoGroup(), false);
            }

        }
    });

    return fileredTree.getViewer();
}