Search in sources :

Example 1 with ViewpointSelector

use of org.eclipse.sirius.business.api.session.ViewpointSelector in project InformationSystem by ObeoNetwork.

the class ProjectLibraryImporter method addReferencedAnalysis.

private void addReferencedAnalysis() {
    // Get main analysis
    Session sourceSession = importData.getSourceSession();
    Session targetSession = importData.getTargetSession();
    DAnalysis sourceMainAnalysis = getMainAnalysis(sourceSession);
    // Add the copied analysis as a referenced analysis
    if (sourceMainAnalysis != null) {
        EObject targetMainAnalysis = importData.getCopyEObject(sourceMainAnalysis);
        if (targetMainAnalysis instanceof DAnalysis && targetSession instanceof DAnalysisSession) {
            ((DAnalysisSession) targetSession).addReferencedAnalysis((DAnalysis) targetMainAnalysis);
        }
    }
    // Add required viewpoints
    for (DView view : sourceMainAnalysis.getOwnedViews()) {
        Viewpoint viewpoint = view.getViewpoint();
        Option<URI> viewpointURI = new ViewpointQuery(viewpoint).getViewpointURI();
        if (viewpointURI.some()) {
            Viewpoint sessionVP = ViewpointRegistry.getInstance().getViewpoint(viewpointURI.get());
            if (sessionVP != null) {
                if (!SiriusResourceHelper.isViewExistForSirius(targetSession, sessionVP)) {
                    // We have to add the viewpoint
                    // TODO Monitor
                    new ViewpointSelector(targetSession).selectViewpoint(sessionVP, false, new NullProgressMonitor());
                }
            }
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ViewpointQuery(org.eclipse.sirius.business.api.query.ViewpointQuery) DAnalysisSession(org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession) Viewpoint(org.eclipse.sirius.viewpoint.description.Viewpoint) EObject(org.eclipse.emf.ecore.EObject) DAnalysis(org.eclipse.sirius.viewpoint.DAnalysis) ViewpointSelector(org.eclipse.sirius.business.api.session.ViewpointSelector) URI(org.eclipse.emf.common.util.URI) Session(org.eclipse.sirius.business.api.session.Session) DAnalysisSession(org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession) IEditingSession(org.eclipse.sirius.ui.business.api.session.IEditingSession) DView(org.eclipse.sirius.viewpoint.DView)

Example 2 with ViewpointSelector

use of org.eclipse.sirius.business.api.session.ViewpointSelector in project InformationSystem by ObeoNetwork.

the class BusinessProjectImporter method addRepresentationDescriptor.

private void addRepresentationDescriptor(Session session, DRepresentationDescriptor representationDescriptor, Viewpoint viewpoint) {
    if (viewpoint != null) {
        DView view = getViewForViewpoint(viewpoint, session);
        if (view != null) {
            view.getOwnedRepresentationDescriptors().add(representationDescriptor);
            view.eResource().getContents().add(representationDescriptor.getRepresentation());
            return;
        }
        // If we reach this point it probably means the viewpoint was not selected yet
        new ViewpointSelector(session).selectViewpoint(viewpoint, false, new NullProgressMonitor());
        view = getViewForViewpoint(viewpoint, session);
        if (view != null) {
            view.getOwnedRepresentationDescriptors().add(representationDescriptor);
            view.eResource().getContents().add(representationDescriptor.getRepresentation());
            return;
        }
    }
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) ViewpointSelector(org.eclipse.sirius.business.api.session.ViewpointSelector) DView(org.eclipse.sirius.viewpoint.DView)

Aggregations

NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)2 ViewpointSelector (org.eclipse.sirius.business.api.session.ViewpointSelector)2 DView (org.eclipse.sirius.viewpoint.DView)2 URI (org.eclipse.emf.common.util.URI)1 EObject (org.eclipse.emf.ecore.EObject)1 ViewpointQuery (org.eclipse.sirius.business.api.query.ViewpointQuery)1 Session (org.eclipse.sirius.business.api.session.Session)1 DAnalysisSession (org.eclipse.sirius.business.api.session.danalysis.DAnalysisSession)1 IEditingSession (org.eclipse.sirius.ui.business.api.session.IEditingSession)1 DAnalysis (org.eclipse.sirius.viewpoint.DAnalysis)1 Viewpoint (org.eclipse.sirius.viewpoint.description.Viewpoint)1