use of org.eclipse.emf.common.notify.AdapterFactory in project xtext-core by eclipse.
the class CompositeNodeTest method testIsAdapterForType.
@Test
public void testIsAdapterForType() {
EObject object = EcoreFactory.eINSTANCE.createEObject();
CompositeNodeWithSemanticElement node = createCompositeNode();
object.eAdapters().add(node);
AdapterFactory adapterFactory = new EcoreAdapterFactory();
Adapter adapter = adapterFactory.adapt(object, INode.class);
assertSame(node, adapter);
// the following line may not throw a ClassCastException
Adapter secondAdapter = adapterFactory.adapt(object, new Object());
assertNull(secondAdapter);
}
use of org.eclipse.emf.common.notify.AdapterFactory in project InformationSystem by ObeoNetwork.
the class InteractionServices method changeParentForInteraction.
/**
* Change the parent of an interaction with a selected one
* @param interaction
* @return
*/
public Interaction changeParentForInteraction(final Interaction interaction) {
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
InteractionParentSelectionLabelProvider labelProvider = new InteractionParentSelectionLabelProvider(adapterFactory);
InteractionParentSelectionContentProvider contentProvider = new InteractionParentSelectionContentProvider(adapterFactory);
ElementTreeSelectionDialog dlg = new ElementTreeSelectionDialog(shell, labelProvider, contentProvider);
dlg.setHelpAvailable(false);
dlg.setValidator(new ISelectionStatusValidator() {
public IStatus validate(Object[] selection) {
Object selectedObject = selection[0];
if (selectedObject instanceof EObject) {
IPermissionAuthority authority = PermissionAuthorityRegistry.getDefault().getPermissionAuthority((EObject) selectedObject);
if (authority != null) {
LockStatus lockStatus = authority.getLockStatus((EObject) selectedObject);
if (LockStatus.LOCKED_BY_OTHER.equals(lockStatus)) {
return new Status(IStatus.ERROR, Activator.PLUGIN_ID, "This element is locked by another user");
}
}
}
return new Status(IStatus.OK, Activator.PLUGIN_ID, "");
}
});
dlg.setTitle("Change interaction's parent");
dlg.setMessage("Select the new parent for the interaction");
Session session = SessionManager.INSTANCE.getSession(interaction);
if (session == null) {
return interaction;
}
dlg.setInput(session.getSemanticResources().toArray());
dlg.setInitialSelection(interaction.eContainer());
int btn = dlg.open();
if (btn == Dialog.OK) {
Object selectedElement = dlg.getFirstResult();
if (selectedElement instanceof ObeoDSMObject && selectedElement != interaction.eContainer()) {
// Change the parent
((ObeoDSMObject) selectedElement).getBehaviours().add(interaction);
}
}
return interaction;
}
use of org.eclipse.emf.common.notify.AdapterFactory in project tdq-studio-se by Talend.
the class ExampleLauncher method compare.
public static void compare() {
// Load the two input models
ResourceSet resourceSet1 = new ResourceSetImpl();
ResourceSet resourceSet2 = new ResourceSetImpl();
// String xmi1 = "path/to/first/model.xmi";
// String xmi2 = "path/to/second/model.xmi";
load(fileName1, resourceSet1);
load(fileName2, resourceSet2);
// Configure EMF Compare
IEObjectMatcher matcher = DefaultMatchEngine.createDefaultEObjectMatcher(UseIdentifiers.NEVER);
IComparisonFactory comparisonFactory = new DefaultComparisonFactory(new DefaultEqualityHelperFactory());
IMatchEngine.Factory matchEngineFactory = new MatchEngineFactoryImpl(matcher, comparisonFactory);
matchEngineFactory.setRanking(20);
IMatchEngine.Factory.Registry matchEngineRegistry = new MatchEngineFactoryRegistryImpl();
matchEngineRegistry.add(matchEngineFactory);
EMFCompare comparator = EMFCompare.builder().setMatchEngineFactoryRegistry(matchEngineRegistry).build();
// Compare the two models
IComparisonScope scope = new DefaultComparisonScope(resourceSet1, resourceSet2, null);
Comparison compare = comparator.compare(scope);
comparator.compare(scope);
EList<Diff> differences = compare.getDifferences();
ICompareEditingDomain editingDomain = EMFCompareEditingDomain.create(scope.getLeft(), scope.getRight(), null);
AdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
EMFCompareConfiguration configuration = new EMFCompareConfiguration(new CompareConfiguration());
CompareEditorInput input = new ComparisonScopeEditorInput(configuration, editingDomain, adapterFactory, comparator, scope);
// CompareUI.openCompareDialog(input); // or CompareUI.openCompareEditor(input);
CompareUI.openCompareEditor(input);
}
use of org.eclipse.emf.common.notify.AdapterFactory in project tdq-studio-se by Talend.
the class MNComposedAdapterFactory method createFactoryList.
public static final ArrayList<AdapterFactory> createFactoryList() {
ArrayList<AdapterFactory> factories = new ArrayList<AdapterFactory>();
factories.add(new ResourceItemProviderAdapterFactory());
factories.add(new RelationalItemProviderAdapterFactory());
factories.add(new orgomg.cwm.resource.relational.provider.RelationalItemProviderAdapterFactory());
factories.add(new AnalysisItemProviderAdapterFactory());
factories.add(new ReflectiveItemProviderAdapterFactory());
return factories;
}
use of org.eclipse.emf.common.notify.AdapterFactory in project InformationSystem by ObeoNetwork.
the class CategorySelectionPage method createControl.
/**
* {@inheritDoc}
*
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
*/
public void createControl(Composite parent) {
Composite control = new Composite(parent, SWT.NONE);
GridData gd = new GridData(GridData.FILL_BOTH);
control.setLayoutData(gd);
GridLayout layout = new GridLayout();
control.setLayout(layout);
Label intro = new Label(control, SWT.NONE);
// $NON-NLS-1$
intro.setText(RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_label"));
GridData labelData = new GridData(GridData.FILL_HORIZONTAL);
intro.setLayoutData(labelData);
categoriesViewer = new TreeViewer(control);
categoriesViewer.getControl().setLayoutData(gd);
AdapterFactory adapterFactory = ViewHelper.INSTANCE.createAdapterFactory();
categoriesViewer.setLabelProvider(new LinkedRequirementsLabelProvider(adapterFactory));
categoriesViewer.setContentProvider(new RequirementsRepositoriesContentProvider(adapterFactory) {
@Override
public Object[] getChildren(Object object) {
if (object instanceof Category) {
return ((Category) object).getSubCategories().toArray();
}
return super.getChildren(object);
}
@Override
public boolean hasChildren(Object object) {
if (object instanceof Category) {
return !((Category) object).getSubCategories().isEmpty();
}
return super.hasChildren(object);
}
});
categoriesViewer.setInput(getInput());
categoriesViewer.addSelectionChangedListener(new ISelectionChangedListener() {
public void selectionChanged(SelectionChangedEvent event) {
EObject selection = getTreeviewSelection();
if (selection instanceof Category) {
selectedCategory = (Category) selection;
setPageComplete(true);
} else {
setPageComplete(false);
}
createCategorie.setEnabled(selection instanceof Category || selection instanceof Repository);
}
});
createCategorie = new Button(control, SWT.PUSH);
createCategorie.setText(// $NON-NLS-1$
RequirementLinkerPlugin.getInstance().getString("CategorySelectionPage_CreateCategoryButton_title"));
createCategorie.addSelectionListener(new SelectionAdapter() {
/**
* {@inheritDoc}
*
* @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
*/
@Override
public void widgetSelected(SelectionEvent e) {
InputDialog dialog = new InputDialog(getShell(), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_title"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_description"), RequirementLinkerPlugin.getInstance().getString(// $NON-NLS-1$
"CategorySelectionPage_CreateCategoryDialog_defaultvalue"), null);
int open = dialog.open();
if (open == Window.OK) {
Category category = RequirementFactory.eINSTANCE.createCategory();
category.setName(dialog.getValue());
if (getTreeviewSelection() instanceof Category) {
((Category) getTreeviewSelection()).getSubCategories().add(category);
} else if (getTreeviewSelection() instanceof Repository) {
((Repository) getTreeviewSelection()).getMainCategories().add(category);
}
}
}
});
createCategorie.setEnabled(false);
if (currentValue != null) {
categoriesViewer.reveal(currentValue);
categoriesViewer.setSelection(new StructuredSelection(currentValue));
}
setControl(control);
}
Aggregations