Search in sources :

Example 6 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class TaskImpl method getUsedBy.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public EList<Task> getUsedBy() {
    Collection<Setting> usingTasksSettings = new GraalUsageCrossReferencer() {

        @Override
        protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) {
            return eReference == GraalPackage.Literals.TASK__USES;
        }

        @Override
        protected boolean containment(EObject eObject) {
            // (We use Resource instead of CDOResource to avoid dependency on CDO)
            return (eObject instanceof Resource) || (eObject instanceof System) || (eObject instanceof TasksGroup) || (eObject instanceof Task);
        }
    }.findUsage(this);
    List<Task> foundTasks = new ArrayList<Task>();
    for (Setting setting : usingTasksSettings) {
        foundTasks.add((Task) setting.getEObject());
    }
    return ECollections.unmodifiableEList(new BasicEList<Task>(foundTasks));
}
Also used : AbstractTask(org.obeonetwork.graal.AbstractTask) Task(org.obeonetwork.graal.Task) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) GraalUsageCrossReferencer(org.obeonetwork.graal.util.GraalUsageCrossReferencer) Resource(org.eclipse.emf.ecore.resource.Resource) ArrayList(java.util.ArrayList) System(org.obeonetwork.graal.System) TasksGroup(org.obeonetwork.graal.TasksGroup) EObject(org.eclipse.emf.ecore.EObject) EReference(org.eclipse.emf.ecore.EReference)

Example 7 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project InformationSystem by ObeoNetwork.

the class AbstractTaskImpl method getUseCase.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
public UseCase getUseCase() {
    Collection<Setting> useCaseReferences = new GraalUsageCrossReferencer() {

        @Override
        protected boolean crossReference(EObject eObject, EReference eReference, EObject crossReferencedEObject) {
            return eReference == GraalPackage.Literals.USE_CASE__TASKS;
        }

        @Override
        protected boolean containment(EObject eObject) {
            // (We use Resource instead of CDOResource to avoid dependency on CDO)
            return (eObject instanceof Resource) || (eObject instanceof System) || (eObject instanceof UseCase);
        }
    }.findUsage(this);
    UseCase useCase = null;
    for (Setting setting : useCaseReferences) {
        useCase = (UseCase) setting.getEObject();
        break;
    }
    return useCase;
}
Also used : Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) EObject(org.eclipse.emf.ecore.EObject) GraalUsageCrossReferencer(org.obeonetwork.graal.util.GraalUsageCrossReferencer) Resource(org.eclipse.emf.ecore.resource.Resource) UseCase(org.obeonetwork.graal.UseCase) EReference(org.eclipse.emf.ecore.EReference) System(org.obeonetwork.graal.System)

Example 8 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project xtext-eclipse by eclipse.

the class XtextGrammarQuickfixProvider method fixExternalImportedPackage.

@Fix(INVALID_PACKAGE_REFERENCE_EXTERNAL)
public void fixExternalImportedPackage(final Issue issue, IssueResolutionAcceptor acceptor) {
    if (issue.getData().length == 1)
        acceptor.accept(issue, "Update the imported package '" + issue.getData()[0] + "'", "Fix the bogus package import\n" + "import '" + issue.getData()[0] + "'", NULL_QUICKFIX_IMAGE, new IModification() {

            @Override
            public void apply(IModificationContext context) throws BadLocationException {
                String replaceString = valueConverterService.toString(issue.getData()[0], "STRING");
                IXtextDocument document = context.getXtextDocument();
                final List<String> importedPackages = document.priorityReadOnly(new IUnitOfWork<List<String>, XtextResource>() {

                    @Override
                    public List<String> exec(XtextResource state) throws Exception {
                        IResourceDescriptions descriptions = resourceDescriptionsProvider.getResourceDescriptions(state);
                        ResourceSet resourceSet = state.getResourceSet();
                        final Map<URI, URI> uriMap = Maps.newHashMap();
                        EPackage ePackage = loadPackageFromIndex(descriptions, resourceSet, uriMap, issue.getData()[0]);
                        if (ePackage != null) {
                            final Map<String, EPackage> packagePerNsURI = Maps.newHashMap();
                            packagePerNsURI.put(ePackage.getNsURI(), ePackage);
                            final Set<URI> updatedReferences = fixReferencesInPackages(ePackage, packagePerNsURI, uriMap, descriptions, resourceSet);
                            if (updatedReferences.isEmpty())
                                return null;
                            Iterator<EPackage> iterator = packagePerNsURI.values().iterator();
                            while (iterator.hasNext()) {
                                EPackage pack = iterator.next();
                                Resource resource = pack.eResource();
                                if (!resource.getURI().isPlatformResource()) {
                                    iterator.remove();
                                }
                            }
                            final List<String> result = Lists.newArrayList();
                            new WorkspaceModifyOperation() {

                                /* workspace lock */
                                @Override
                                protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
                                    try {
                                        for (EPackage pack : packagePerNsURI.values()) {
                                            Resource resource = pack.eResource();
                                            resource.save(Collections.singletonMap(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.PlatformSchemeAware() {

                                                @Override
                                                public URI deresolve(URI uri) {
                                                    // replace archive uris with platform:/plugin
                                                    if (!uri.isArchive() || !updatedReferences.contains(uri)) {
                                                        return super.deresolve(uri);
                                                    }
                                                    URI withoutFragment = uri.trimFragment();
                                                    if (uriMap.containsKey(withoutFragment)) {
                                                        withoutFragment = uriMap.get(withoutFragment);
                                                    }
                                                    return super.deresolve(withoutFragment.appendFragment(uri.fragment()));
                                                }
                                            }));
                                            result.add(resource.getURI().toString());
                                        }
                                    } catch (IOException ioe) {
                                        throw new InvocationTargetException(ioe);
                                    }
                                }
                            }.run(new NullProgressMonitor());
                            for (int i = resourceSet.getResources().size() - 1; i >= 0; i--) {
                                Resource resource = resourceSet.getResources().get(i);
                                if (!resource.getContents().isEmpty() && resource.getContents().get(0) instanceof GenModel) {
                                    resourceSet.getResources().remove(i);
                                }
                            }
                            return result;
                        }
                        return null;
                    }

                    private Set<URI> fixReferencesInPackages(EPackage ePackage, Map<String, EPackage> packagePerNsURI, Map<URI, URI> uriMap, IResourceDescriptions descriptions, ResourceSet resourceSet) {
                        Set<URI> result = Sets.newHashSet();
                        Map<EObject, Collection<Setting>> allReferences = EcoreUtil.CrossReferencer.find(Collections.singletonList(ePackage));
                        for (final Setting setting : Iterables.concat(allReferences.values())) {
                            if (setting.getEStructuralFeature().isChangeable()) {
                                final Object referenced = setting.get(true);
                                List<Object> references = null;
                                if (referenced instanceof EObject) {
                                    references = new AbstractList<Object>() {

                                        @Override
                                        public Object set(int index, Object element) {
                                            setting.set(element);
                                            return referenced;
                                        }

                                        @Override
                                        public Object get(int index) {
                                            return referenced;
                                        }

                                        @Override
                                        public int size() {
                                            return 1;
                                        }
                                    };
                                } else {
                                    @SuppressWarnings("unchecked") List<Object> casted = (List<Object>) referenced;
                                    references = casted;
                                }
                                for (int i = 0; i < references.size(); i++) {
                                    if (references.get(i) instanceof EObject) {
                                        EObject referencedEObject = (EObject) references.get(i);
                                        EPackage transitive = EcoreUtil2.getContainerOfType(referencedEObject, EPackage.class);
                                        if (isRegisteredPackage(transitive)) {
                                            if (referencedEObject instanceof EDataType)
                                                continue;
                                            if (referencedEObject == EcorePackage.Literals.EOBJECT)
                                                continue;
                                            EPackage fromWorkspace = packagePerNsURI.get(transitive.getNsURI());
                                            if (fromWorkspace == null && !packagePerNsURI.containsKey(transitive.getNsURI())) {
                                                fromWorkspace = loadPackageFromIndex(descriptions, resourceSet, uriMap, transitive.getNsURI());
                                                packagePerNsURI.put(transitive.getNsURI(), fromWorkspace);
                                            }
                                            if (fromWorkspace != null) {
                                                String fragment = transitive.eResource().getURIFragment(referencedEObject);
                                                EObject replacement = fromWorkspace.eResource().getEObject(fragment);
                                                if (replacement != null) {
                                                    result.add(EcoreUtil.getURI(replacement));
                                                    references.set(i, replacement);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        return result;
                    }

                    private boolean isRegisteredPackage(EPackage ePackage) {
                        return ePackage != null && (ePackage.eResource() == null || ePackage.getNsURI().equals(ePackage.eResource().getURI().toString()));
                    }

                    private EPackage loadPackageFromIndex(IResourceDescriptions descriptions, ResourceSet resourceSet, Map<URI, URI> uriMap, String nsURI) {
                        Iterable<IEObjectDescription> fixUs = descriptions.getExportedObjects(EcorePackage.Literals.EPACKAGE, QualifiedName.create(nsURI), false);
                        for (IEObjectDescription description : fixUs) {
                            if (description.getEObjectURI().isPlatformResource()) {
                                EObject result = resourceSet.getEObject(description.getEObjectURI(), true);
                                if (result instanceof EPackage) {
                                    return (EPackage) result;
                                }
                            }
                        }
                        URI genModelURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap(false).get(nsURI);
                        if (genModelURI != null) {
                            Resource genmodelResource = resourceSet.getResource(genModelURI, true);
                            GenModel genModel = (GenModel) genmodelResource.getContents().get(0);
                            for (GenPackage genPackage : genModel.getGenPackages()) {
                                Object object = genPackage.eGet(GenModelPackage.Literals.GEN_PACKAGE__ECORE_PACKAGE, false);
                                if (object instanceof EObject) {
                                    EObject proxy = (EObject) object;
                                    URI proxyURI = EcoreUtil.getURI(proxy);
                                    URI resolvedProxyURI = proxyURI.resolve(genModelURI);
                                    if (nsURI.equals(genPackage.getEcorePackage().getNsURI())) {
                                        EPackage result = genPackage.getEcorePackage();
                                        uriMap.put(result.eResource().getURI(), resolvedProxyURI.trimFragment());
                                        return result;
                                    }
                                }
                            }
                        }
                        return null;
                    }
                });
                String delimiter = document.get(issue.getOffset(), 1);
                if (!replaceString.startsWith(delimiter)) {
                    replaceString = delimiter + replaceString.substring(1, replaceString.length() - 1) + delimiter;
                }
                document.replace(issue.getOffset(), issue.getLength(), replaceString);
                if (importedPackages != null && !importedPackages.isEmpty()) {
                    final Shell shell = workbench.getActiveWorkbenchWindow().getShell();
                    shell.getDisplay().asyncExec(new Runnable() {

                        @Override
                        public void run() {
                            String title = "Please update the Ecore2XtextDslProjectContributor that generates the language.";
                            String message = "Please make sure that the Ecore2XtextDslProjectContributor that generates the language is up-to date.\n" + "Especially important is the registration of the referenced packages.\n" + "Please refer to the reference documentation for details.";
                            MessageDialog dialog = new MessageDialog(shell, title, null, message, MessageDialog.INFORMATION, new String[] { "Open Documentation", "Close" }, 1);
                            if (dialog.open() == 0) {
                                try {
                                    workbench.getBrowserSupport().getExternalBrowser().openURL(new URL(GRAMMAR_LANG_DOC));
                                } catch (Exception e) {
                                // ignore
                                }
                            }
                        }
                    });
                }
            }
        });
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Set(java.util.Set) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) EDataType(org.eclipse.emf.ecore.EDataType) XtextResource(org.eclipse.xtext.resource.XtextResource) GenPackage(org.eclipse.emf.codegen.ecore.genmodel.GenPackage) URI(org.eclipse.emf.common.util.URI) URL(java.net.URL) EPackage(org.eclipse.emf.ecore.EPackage) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) Shell(org.eclipse.swt.widgets.Shell) EObject(org.eclipse.emf.ecore.EObject) Iterator(java.util.Iterator) AbstractList(java.util.AbstractList) List(java.util.List) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) IModification(org.eclipse.xtext.ui.editor.model.edit.IModification) AbstractList(java.util.AbstractList) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Resource(org.eclipse.emf.ecore.resource.Resource) XMLResource(org.eclipse.emf.ecore.xmi.XMLResource) XtextResource(org.eclipse.xtext.resource.XtextResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) IOException(java.io.IOException) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) BadLocationException(org.eclipse.jface.text.BadLocationException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IResourceDescriptions(org.eclipse.xtext.resource.IResourceDescriptions) GenModel(org.eclipse.emf.codegen.ecore.genmodel.GenModel) IModificationContext(org.eclipse.xtext.ui.editor.model.edit.IModificationContext) EObject(org.eclipse.emf.ecore.EObject) Map(java.util.Map) IXtextDocument(org.eclipse.xtext.ui.editor.model.IXtextDocument) Fix(org.eclipse.xtext.ui.editor.quickfix.Fix)

Example 9 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project webtools.sourceediting by eclipse.

the class XSDDirectivesManager method doCrossReferencer.

/**
 * This determines the list of referenced components and hence the used schemas from which
 * we can determine what are the unused directives
 *
 * @param schema
 * @param unusedImportList
 * @param usedSchemas
 */
protected void doCrossReferencer(XSDSchema schema, List usedSchemas, Map xsdNamedComponentUsage) {
    // Calculate additional unused imports that may have the same
    // namespace that did not get added in the initial pass
    Iterator iterator = xsdNamedComponentUsage.keySet().iterator();
    // First determine the used schemas from the cross referencer
    while (iterator.hasNext()) {
        XSDNamedComponent namedComponent = (XSDNamedComponent) iterator.next();
        XSDSchema namedComponentSchema = namedComponent.getSchema();
        // want to check the external references
        if (namedComponentSchema == schema) {
            continue;
        }
        Collection collection = (Collection) xsdNamedComponentUsage.get(namedComponent);
        Iterator iterator2 = collection.iterator();
        while (iterator2.hasNext()) {
            Setting setting = (Setting) iterator2.next();
            Object obj = setting.getEObject();
            if (isComponentUsed(obj, schema, namedComponentSchema)) {
                if (!usedSchemas.contains(namedComponentSchema))
                    usedSchemas.add(namedComponentSchema);
            }
        }
    }
}
Also used : XSDNamedComponent(org.eclipse.xsd.XSDNamedComponent) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) Iterator(java.util.Iterator) Collection(java.util.Collection) EObject(org.eclipse.emf.ecore.EObject) XSDSchema(org.eclipse.xsd.XSDSchema)

Example 10 with Setting

use of org.eclipse.emf.ecore.EStructuralFeature.Setting in project tdq-studio-se by Talend.

the class WorkbenchUtils method impactExistingAnalyses.

/**
 * DOC qiongli TDQ-3317:move this method from ReloadDatabaseAction. to this class .
 *
 * @param oldDataProvider
 * @throws PartInitException
 */
public static void impactExistingAnalyses(DataProvider oldDataProvider) throws PartInitException {
    EList<Dependency> clientDependencies = oldDataProvider.getSupplierDependency();
    List<Analysis> unsynedAnalyses = new ArrayList<Analysis>();
    for (Dependency dep : clientDependencies) {
        for (ModelElement mod : dep.getClient()) {
            // MOD mzhao 2009-08-24 The dependencies include "Property" and "Analysis"
            if (!(mod instanceof Analysis)) {
                continue;
            }
            Analysis ana = (Analysis) mod;
            unsynedAnalyses.add(ana);
        }
        for (Analysis analysis : unsynedAnalyses) {
            // Reload.
            IFile file = getTempAnalysisFile(analysis);
            Analysis tempAnalysis = (Analysis) AnaResourceFileHelper.getInstance().getModelElement(file);
            // MOD qiongli 2010-8-17,bug 14977
            if (tempAnalysis != null) {
                Resource eResource = tempAnalysis.eResource();
                Map<EObject, Collection<Setting>> referenceMaps = EcoreUtil.UnresolvedProxyCrossReferencer.find(eResource);
                Iterator<EObject> it = referenceMaps.keySet().iterator();
                ModelElement eobj = null;
                boolean isModified = false;
                while (it.hasNext()) {
                    eobj = (ModelElement) it.next();
                    Collection<Setting> settings = referenceMaps.get(eobj);
                    for (Setting setting : settings) {
                        if (setting.getEObject() instanceof AnalysisContext) {
                            tempAnalysis.getContext().getAnalysedElements().remove(eobj);
                            isModified = true;
                        } else if (setting.getEObject() instanceof Indicator) {
                            // the only indicator in the column set analysis. (Added TDQ-8842 20140512 yyin)
                            if (AnalysisType.COLUMN_SET.equals(tempAnalysis.getParameters().getAnalysisType())) {
                                // ~
                                ((SimpleStatIndicator) setting.getEObject()).getAnalyzedColumns().remove(eobj);
                            } else {
                                tempAnalysis.getResults().getIndicators().remove(setting.getEObject());
                            }
                            isModified = true;
                        }
                    }
                }
                if (isModified) {
                    saveTempAnalysis(file, tempAnalysis);
                }
                // Should reopen this analyis's editor if it is opened now. what ever it is modified or not.
                EventManager.getInstance().publish(tempAnalysis.getName(), EventEnum.DQ_ANALYSIS_REOPEN_EDITOR, null);
            }
        }
    }
}
Also used : IFile(org.eclipse.core.resources.IFile) Setting(org.eclipse.emf.ecore.EStructuralFeature.Setting) ArrayList(java.util.ArrayList) Resource(org.eclipse.emf.ecore.resource.Resource) Dependency(orgomg.cwm.objectmodel.core.Dependency) AnalysisContext(org.talend.dataquality.analysis.AnalysisContext) Indicator(org.talend.dataquality.indicators.Indicator) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) Analysis(org.talend.dataquality.analysis.Analysis) EObject(org.eclipse.emf.ecore.EObject) Collection(java.util.Collection) SimpleStatIndicator(org.talend.dataquality.indicators.columnset.SimpleStatIndicator)

Aggregations

Setting (org.eclipse.emf.ecore.EStructuralFeature.Setting)16 EObject (org.eclipse.emf.ecore.EObject)11 ArrayList (java.util.ArrayList)7 Resource (org.eclipse.emf.ecore.resource.Resource)7 EReference (org.eclipse.emf.ecore.EReference)5 Collection (java.util.Collection)4 ECrossReferenceAdapter (org.eclipse.emf.ecore.util.ECrossReferenceAdapter)4 System (org.obeonetwork.graal.System)4 GraalUsageCrossReferencer (org.obeonetwork.graal.util.GraalUsageCrossReferencer)4 HashSet (java.util.HashSet)2 Iterator (java.util.Iterator)2 EDataType (org.eclipse.emf.ecore.EDataType)2 EPackage (org.eclipse.emf.ecore.EPackage)2 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)2 Session (org.eclipse.sirius.business.api.session.Session)2 Reference (org.obeonetwork.dsl.environment.Reference)2 Requirement (org.obeonetwork.dsl.requirement.Requirement)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 URL (java.net.URL)1