Search in sources :

Example 1 with AdapterFactory

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);
}
Also used : AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) EcoreAdapterFactory(org.eclipse.emf.ecore.util.EcoreAdapterFactory) EObject(org.eclipse.emf.ecore.EObject) Adapter(org.eclipse.emf.common.notify.Adapter) EObject(org.eclipse.emf.ecore.EObject) EcoreAdapterFactory(org.eclipse.emf.ecore.util.EcoreAdapterFactory) Test(org.junit.Test)

Example 2 with AdapterFactory

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;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) IPermissionAuthority(org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority) IStatus(org.eclipse.core.runtime.IStatus) LockStatus(org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) InteractionParentSelectionLabelProvider(org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionLabelProvider) ElementTreeSelectionDialog(org.eclipse.ui.dialogs.ElementTreeSelectionDialog) Shell(org.eclipse.swt.widgets.Shell) InteractionParentSelectionContentProvider(org.obeonetwork.dsl.interaction.design.ui.extension.providers.InteractionParentSelectionContentProvider) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) ISelectionStatusValidator(org.eclipse.ui.dialogs.ISelectionStatusValidator) EObject(org.eclipse.emf.ecore.EObject) ObeoDSMObject(org.obeonetwork.dsl.environment.ObeoDSMObject) Session(org.eclipse.sirius.business.api.session.Session)

Example 3 with AdapterFactory

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);
}
Also used : MatchEngineFactoryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl) Diff(org.eclipse.emf.compare.Diff) CompareConfiguration(org.eclipse.compare.CompareConfiguration) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) MatchEngineFactoryRegistryImpl(org.eclipse.emf.compare.match.impl.MatchEngineFactoryRegistryImpl) IComparisonScope(org.eclipse.emf.compare.scope.IComparisonScope) DefaultComparisonFactory(org.eclipse.emf.compare.match.DefaultComparisonFactory) Comparison(org.eclipse.emf.compare.Comparison) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ICompareEditingDomain(org.eclipse.emf.compare.domain.ICompareEditingDomain) ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) DefaultEqualityHelperFactory(org.eclipse.emf.compare.match.DefaultEqualityHelperFactory) DefaultComparisonScope(org.eclipse.emf.compare.scope.DefaultComparisonScope) IComparisonFactory(org.eclipse.emf.compare.match.IComparisonFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EMFCompareConfiguration(org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration) ComparisonScopeEditorInput(org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput) CompareEditorInput(org.eclipse.compare.CompareEditorInput) EMFCompare(org.eclipse.emf.compare.EMFCompare) IEObjectMatcher(org.eclipse.emf.compare.match.eobject.IEObjectMatcher) IMatchEngine(org.eclipse.emf.compare.match.IMatchEngine)

Example 4 with AdapterFactory

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;
}
Also used : AnalysisItemProviderAdapterFactory(org.talend.dataquality.analysis.provider.AnalysisItemProviderAdapterFactory) ReflectiveItemProviderAdapterFactory(org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) ResourceItemProviderAdapterFactory(org.eclipse.emf.edit.provider.resource.ResourceItemProviderAdapterFactory) AnalysisItemProviderAdapterFactory(org.talend.dataquality.analysis.provider.AnalysisItemProviderAdapterFactory) ReflectiveItemProviderAdapterFactory(org.eclipse.emf.edit.provider.ReflectiveItemProviderAdapterFactory) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) RelationalItemProviderAdapterFactory(org.talend.cwm.relational.provider.RelationalItemProviderAdapterFactory) ComposedAdapterFactory(org.eclipse.emf.edit.provider.ComposedAdapterFactory) ArrayList(java.util.ArrayList) RelationalItemProviderAdapterFactory(org.talend.cwm.relational.provider.RelationalItemProviderAdapterFactory)

Example 5 with AdapterFactory

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);
}
Also used : Category(org.obeonetwork.dsl.requirement.Category) InputDialog(org.eclipse.jface.dialogs.InputDialog) Composite(org.eclipse.swt.widgets.Composite) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) LinkedRequirementsLabelProvider(org.obeonetwork.tools.requirement.wizard.util.LinkedRequirementsLabelProvider) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Repository(org.obeonetwork.dsl.requirement.Repository) Button(org.eclipse.swt.widgets.Button) AdapterFactory(org.eclipse.emf.common.notify.AdapterFactory) RequirementsRepositoriesContentProvider(org.obeonetwork.tools.requirement.wizard.util.RequirementsRepositoriesContentProvider) EObject(org.eclipse.emf.ecore.EObject) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) EObject(org.eclipse.emf.ecore.EObject)

Aggregations

AdapterFactory (org.eclipse.emf.common.notify.AdapterFactory)6 EObject (org.eclipse.emf.ecore.EObject)4 ComposedAdapterFactory (org.eclipse.emf.edit.provider.ComposedAdapterFactory)4 IStatus (org.eclipse.core.runtime.IStatus)2 Status (org.eclipse.core.runtime.Status)2 Session (org.eclipse.sirius.business.api.session.Session)2 IPermissionAuthority (org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority)2 LockStatus (org.eclipse.sirius.ecore.extender.business.api.permission.LockStatus)2 ArrayList (java.util.ArrayList)1 CompareConfiguration (org.eclipse.compare.CompareConfiguration)1 CompareEditorInput (org.eclipse.compare.CompareEditorInput)1 Adapter (org.eclipse.emf.common.notify.Adapter)1 Comparison (org.eclipse.emf.compare.Comparison)1 Diff (org.eclipse.emf.compare.Diff)1 EMFCompare (org.eclipse.emf.compare.EMFCompare)1 ICompareEditingDomain (org.eclipse.emf.compare.domain.ICompareEditingDomain)1 EMFCompareConfiguration (org.eclipse.emf.compare.ide.ui.internal.configuration.EMFCompareConfiguration)1 ComparisonScopeEditorInput (org.eclipse.emf.compare.ide.ui.internal.editor.ComparisonScopeEditorInput)1 DefaultComparisonFactory (org.eclipse.emf.compare.match.DefaultComparisonFactory)1 DefaultEqualityHelperFactory (org.eclipse.emf.compare.match.DefaultEqualityHelperFactory)1