Search in sources :

Example 11 with GraphicalEditorException

use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.

the class DefaultDiagramService method createDiagram.

@Override
public void createDiagram(final IFile diagramFile, final DiagramType diagramType, final Object contextBo) {
    // Create an AgeDiagram object. This object doesn't have to be completely valid. It just needs to be able to be written.
    final AgeDiagram diagram = new AgeDiagram();
    // Build diagram configuration
    final CanonicalBusinessObjectReference contextBoCanonicalRef = contextBo == null ? null : Objects.requireNonNull(referenceService.getCanonicalReference(contextBo), "Unable to build canonical reference for business object: " + contextBo);
    diagram.modify("Configure Diagram", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagramType, true).contextBoReference(contextBoCanonicalRef).connectionPrimaryLabelsVisible(false).build()));
    final URI newDiagramUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
    DiagramSerialization.write(diagramFile.getProject(), diagram, newDiagramUri);
    try {
        diagramFile.refreshLocal(IResource.DEPTH_INFINITE, null);
    } catch (final CoreException e) {
        throw new GraphicalEditorException(e);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) CanonicalBusinessObjectReference(org.osate.ge.CanonicalBusinessObjectReference) DiagramConfigurationBuilder(org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder) URI(org.eclipse.emf.common.util.URI) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Example 12 with GraphicalEditorException

use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.

the class DefaultBusinessObjectTreeUpdater method updateTree.

@Override
public BusinessObjectNode updateTree(final DiagramConfiguration configuration, final BusinessObjectNode tree) {
    // Refresh Child Nodes
    final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
    final BusinessObjectNode newRoot = nodeFactory.create(null, UUID.randomUUID(), null, Completeness.UNKNOWN);
    final Map<RelativeBusinessObjectReference, Object> boMap;
    // Determine what business objects are required based on the diagram configuration
    if (configuration.getContextBoReference() == null) {
        // Get potential top level business objects from providers
        // A simple business object context which is used as the root BOC for contextless diagrams. It has no parent and used the current
        // project as the business object.
        final BusinessObjectContext contextlessRootBoc = new BusinessObjectContext() {

            @Override
            public Collection<? extends BusinessObjectContext> getChildren() {
                return Collections.emptyList();
            }

            @Override
            public BusinessObjectContext getParent() {
                return null;
            }

            @Override
            public Object getBusinessObject() {
                return projectProvider.getProject();
            }
        };
        final Collection<Object> potentialRootBusinessObjects = bopHelper.getChildBusinessObjects(contextlessRootBoc);
        // Determine the root business objects
        final Set<RelativeBusinessObjectReference> existingRootBranches = tree.getChildrenMap().keySet();
        // Content filters are not supported for the root of diagrams.
        final ImmutableSet<ContentFilter> rootContentFilters = ImmutableSet.of();
        boMap = getChildBusinessObjects(potentialRootBusinessObjects, existingRootBranches, rootContentFilters);
        // Contextless diagrams are always considered complete
        newRoot.setCompleteness(Completeness.COMPLETE);
        // This is needed so the configure diagram dialog, etc will know which project should be used to
        // retrieve root objects.
        // Set the root of the BO tree to the project
        newRoot.setBusinessObject(projectProvider.getProject());
    } else {
        // Get the context business object
        Object contextBo = refService.resolve(configuration.getContextBoReference());
        if (contextBo == null) {
            final String contextLabel = refService.getLabel(configuration.getContextBoReference());
            throw new GraphicalEditorException("Unable to find context business object: " + contextLabel);
        }
        // Require the use of the business object specified in the diagram along with any other business objects which are already in the diagram.
        final RelativeBusinessObjectReference relativeReference = refService.getRelativeReference(contextBo);
        if (relativeReference == null) {
            throw new GraphicalEditorException("Unable to build relative reference for context business object: " + contextBo);
        }
        boMap = new HashMap<>();
        boMap.put(relativeReference, contextBo);
        newRoot.setCompleteness(Completeness.COMPLETE);
    }
    // Add embedded business objects to the child BO map
    addEmbeddedBusinessObjectsToBoMap(tree.getChildrenMap().values(), boMap);
    // Populate the new tree
    final Map<RelativeBusinessObjectReference, BusinessObjectNode> oldNodes = tree.getChildrenMap();
    createNodes(configuration.getDiagramType(), bopHelper, boMap, oldNodes, newRoot);
    // Build set of the names of all properties which are enabled
    final Set<String> enabledPropertyNames = new HashSet<>(configuration.getEnabledAadlPropertyNames());
    // Add properties which are always enabled regardless of configuration setting
    enabledPropertyNames.add("communication_properties::timing");
    // Get the property objects
    final Set<Property> enabledProperties = getPropertiesByLowercasePropertyNames(enabledPropertyNames);
    // Process properties. This is done after everything else since properties may need to refer to other nodes.
    final AadlPropertyResolver propertyResolver = new AadlPropertyResolver(newRoot);
    processProperties(propertyResolver, newRoot, tree, enabledProperties);
    return newRoot;
}
Also used : AadlPropertyResolver(org.osate.ge.aadl2.internal.aadlproperties.AadlPropertyResolver) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) ContentFilter(org.osate.ge.ContentFilter) FundamentalContentFilter(org.osate.ge.FundamentalContentFilter) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) EObject(org.eclipse.emf.ecore.EObject) InstanceObject(org.osate.aadl2.instance.InstanceObject) BusinessObjectProviderHelper(org.osate.ge.internal.util.BusinessObjectProviderHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) Property(org.osate.aadl2.Property) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) HashSet(java.util.HashSet)

Example 13 with GraphicalEditorException

use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.

the class LtkRenameAction method renameWithLtk.

/**
 * Renames the specified model element using an LTK rename refactoring.
 * @param bo the model element to rename
 * @param value the new name for the model element
 * @return true if the rename occurred
 */
private boolean renameWithLtk(final EObject bo, final String value) {
    // Prevent model notification changes from being sent until after the refactoring
    try (Lock lock = modelChangeNotifier.lock()) {
        // Rename the element using LTK
        final ProcessorBasedRefactoring renameRefactoring = RenameUtil.getRenameRefactoring(bo);
        final RefactoringStatus refactoringStatus = prepareAndCheck(renameRefactoring, value);
        if (!refactoringStatus.isOK()) {
            final Dialog dlg = RefactoringUI.createRefactoringStatusDialog(refactoringStatus, Display.getCurrent().getActiveShell(), "Refactoring", false);
            if (dlg.open() != Window.OK) {
                // Abort
                return false;
            }
        }
        try {
            final Change change = renameRefactoring.createChange(new NullProgressMonitor());
            new WorkspaceModifyOperation() {

                @Override
                protected void execute(IProgressMonitor monitor) throws CoreException {
                    // Perform the modification
                    change.perform(monitor);
                    // Build the project, reconcile all open AADL text editors and then build again.
                    // This seems to be the best way to ensure that all the model change events have been
                    // queued before the model change notification lock is released
                    buildProject();
                    ensureReconciled();
                    buildProject();
                }
            }.run(null);
        } catch (final InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new GraphicalEditorException(e);
        } catch (final RuntimeException | InvocationTargetException | CoreException e) {
            throw new GraphicalEditorException(e);
        }
    }
    return true;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) WorkspaceModifyOperation(org.eclipse.ui.actions.WorkspaceModifyOperation) RefactoringStatus(org.eclipse.ltk.core.refactoring.RefactoringStatus) Change(org.eclipse.ltk.core.refactoring.Change) ProcessorBasedRefactoring(org.eclipse.ltk.core.refactoring.participants.ProcessorBasedRefactoring) InvocationTargetException(java.lang.reflect.InvocationTargetException) Lock(org.osate.ge.internal.services.ModelChangeNotifier.Lock) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) Dialog(org.eclipse.jface.dialogs.Dialog) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException)

Example 14 with GraphicalEditorException

use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.

the class DefaultAadlModificationService method getParsedAnnexRootIndices.

/**
 * Return indices that indicate the location of an object within a parsed annex element.
 * @param obj
 * @return
 */
private Deque<Integer> getParsedAnnexRootIndices(final EObject obj) {
    assert !(obj instanceof DefaultAnnexLibrary || obj instanceof DefaultAnnexSubclause);
    final Deque<Integer> indices = new ArrayDeque<>();
    // Find the root of the parsed annex
    EObject tmp = obj;
    while (tmp != null && !(tmp instanceof AnnexLibrary || tmp instanceof AnnexSubclause)) {
        final int newIndex = ECollections.indexOf(tmp.eContainer().eContents(), tmp, 0);
        if (newIndex == -1) {
            throw new GraphicalEditorException("Unable to get index inside of container contents");
        }
        indices.push(newIndex);
        ;
        tmp = tmp.eContainer();
    }
    return indices;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) ArrayDeque(java.util.ArrayDeque) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Example 15 with GraphicalEditorException

use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.

the class DefaultAadlModificationService method modifyAnnexInXtextDocument.

private <TagType, BusinessObjectType extends EObject> ModifySafelyResults modifyAnnexInXtextDocument(final XtextResource resource, final EObject defaultAnnexElement, final TagType tag, final BusinessObjectType bo, final Modifier<TagType, BusinessObjectType> modifier) {
    // Make a copy of the resource
    final EObject parsedAnnexElement = getParsedAnnexElement(defaultAnnexElement);
    final ResourceSet tmpResourceSet = new ResourceSetImpl();
    final Resource tmpResource = tmpResourceSet.createResource(resource.getURI());
    tmpResource.getContents().addAll(EcoreUtil.copyAll(resource.getContents()));
    // Clone the bo specified by the modification
    final EObject parsedAnnexRootClone = tmpResourceSet.getEObject(EcoreUtil.getURI(parsedAnnexElement), false);
    final Deque<Integer> indexStack = getParsedAnnexRootIndices(bo);
    EObject tmpClonedObject = parsedAnnexRootClone;
    while (!indexStack.isEmpty()) {
        tmpClonedObject = tmpClonedObject.eContents().get(indexStack.pop());
    }
    @SuppressWarnings("unchecked") final BusinessObjectType clonedUserObject = (BusinessObjectType) tmpClonedObject;
    // Modify the annex by modifying the cloned object, unparsing, and then updating the source text of the original default annex element.
    return modifySafely(resource, tag, defaultAnnexElement, (unusedTag, defaultAnnexElement1) -> {
        // Modify the cloned object
        modifier.modify(tag, clonedUserObject);
        // Unparse the annex text of the cloned object and update the Xtext document
        if (parsedAnnexRootClone instanceof AnnexLibrary) {
            final DefaultAnnexLibrary defaultAnnexLibrary = (DefaultAnnexLibrary) defaultAnnexElement1;
            final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexLibrary.getName()).unparseAnnexLibrary((AnnexLibrary) parsedAnnexRootClone, "  ");
            final String sourceTxt1 = alignAnnexTextToCore(resource, annexText, 1);
            EcoreUtil.delete(defaultAnnexLibrary.getParsedAnnexLibrary());
            defaultAnnexLibrary.setSourceText(sourceTxt1);
        } else if (parsedAnnexRootClone instanceof AnnexSubclause) {
            final DefaultAnnexSubclause defaultAnnexSubclause = (DefaultAnnexSubclause) defaultAnnexElement1;
            final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexSubclause.getName()).unparseAnnexSubclause((AnnexSubclause) parsedAnnexRootClone, "  ");
            final String sourceTxt2 = alignAnnexTextToCore(resource, annexText, 2);
            EcoreUtil.delete(defaultAnnexSubclause.getParsedAnnexSubclause());
            defaultAnnexSubclause.setSourceText(sourceTxt2);
        } else {
            throw new GraphicalEditorException("Unhandled case, parsedAnnexRoot is of type: " + parsedAnnexRootClone.getClass());
        }
    }, false);
}
Also used : ResourceSetImpl(org.eclipse.emf.ecore.resource.impl.ResourceSetImpl) Resource(org.eclipse.emf.ecore.resource.Resource) XtextResource(org.eclipse.xtext.resource.XtextResource) IResource(org.eclipse.core.resources.IResource) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) EObject(org.eclipse.emf.ecore.EObject) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary) AnnexLibrary(org.osate.aadl2.AnnexLibrary) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) DefaultAnnexSubclause(org.osate.aadl2.DefaultAnnexSubclause) AnnexSubclause(org.osate.aadl2.AnnexSubclause) GraphicalEditorException(org.osate.ge.internal.GraphicalEditorException) DefaultAnnexLibrary(org.osate.aadl2.DefaultAnnexLibrary)

Aggregations

GraphicalEditorException (org.osate.ge.internal.GraphicalEditorException)15 IOException (java.io.IOException)5 EObject (org.eclipse.emf.ecore.EObject)4 Resource (org.eclipse.emf.ecore.resource.Resource)4 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)4 ResourceSetImpl (org.eclipse.emf.ecore.resource.impl.ResourceSetImpl)4 HashSet (java.util.HashSet)3 IProject (org.eclipse.core.resources.IProject)3 CoreException (org.eclipse.core.runtime.CoreException)3 URI (org.eclipse.emf.common.util.URI)3 Collection (java.util.Collection)2 Collections (java.util.Collections)2 List (java.util.List)2 Entry (java.util.Map.Entry)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 IStatus (org.eclipse.core.runtime.IStatus)2