Search in sources :

Example 16 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class CreateClassifierPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
    return ctx.getTarget().getBusinessObject(EObject.class).map(targetBo -> {
        if (!(targetBo instanceof AadlPackage || isValidBaseClassifier(targetBo))) {
            return null;
        }
        final BusinessObjectContext pkgBoc = getPackageBoc(ctx.getTarget(), ctx.getQueryService());
        if (pkgBoc == null) {
            return null;
        }
        final AadlPackage pkg = (AadlPackage) pkgBoc.getBusinessObject();
        final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
        final ResourceSet rs = targetBo.eResource().getResourceSet();
        return Operation.createWithBuilder(builder -> {
            builder.supply(() -> {
                final ClassifierOperation args = buildCreateOperations(pkg, targetBo, project, rs);
                if (args == null) {
                    return StepResult.abort();
                }
                return StepResult.forValue(args);
            }).executeOperation(classifierOp -> Operation.createWithBuilder(innerBuilder -> {
                final ClassifierOperationExecutor opExec = new ClassifierOperationExecutor(rs, project);
                opExec.execute(innerBuilder, classifierOp, pkgBoc);
            }));
        });
    });
}
Also used : DefaultCreateSelectClassifierDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel) StepResult(org.osate.ge.operations.StepResult) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) ClassifierOperationDialog(org.osate.ge.aadl2.ui.internal.dialogs.ClassifierOperationDialog) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) BusinessObjectContext(org.osate.ge.BusinessObjectContext) AadlImages(org.osate.ge.aadl2.internal.AadlImages) BasePaletteCommand(org.osate.ge.palette.BasePaletteCommand) IProject(org.eclipse.core.resources.IProject) EClass(org.eclipse.emf.ecore.EClass) Classifier(org.osate.aadl2.Classifier) ImmutableList(com.google.common.collect.ImmutableList) AadlUiUtil(org.osate.ge.aadl2.ui.internal.AadlUiUtil) Aadl2Package(org.osate.aadl2.Aadl2Package) EnumSet(java.util.EnumSet) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ClassifierOperationPartType(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType) GetTargetedOperationContext(org.osate.ge.palette.GetTargetedOperationContext) Operation(org.osate.ge.operations.Operation) Collection(java.util.Collection) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) AadlClassifierUtil(org.osate.ge.aadl2.internal.util.AadlClassifierUtil) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) Display(org.eclipse.swt.widgets.Display) ProjectUtil(org.osate.ge.ProjectUtil) QueryService(org.osate.ge.services.QueryService) ComponentCategory(org.osate.aadl2.ComponentCategory) StringUtil(org.osate.ge.StringUtil) AadlCategories(org.osate.ge.aadl2.AadlCategories) Optional(java.util.Optional) AadlNamingUtil(org.osate.ge.aadl2.internal.AadlNamingUtil) ClassifierOperationPart(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPart) ExecutableQuery(org.osate.ge.query.ExecutableQuery) TargetedPaletteCommand(org.osate.ge.palette.TargetedPaletteCommand) AadlPackage(org.osate.aadl2.AadlPackage) ClassifierOperationExecutor(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationExecutor) EObject(org.eclipse.emf.ecore.EObject) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation) ResourceSet(org.eclipse.emf.ecore.resource.ResourceSet) BusinessObjectContext(org.osate.ge.BusinessObjectContext) IProject(org.eclipse.core.resources.IProject)

Example 17 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class GoToPackageDiagramHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    // Get diagram and selected BOCs
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 0) {
        throw new RuntimeException("No element selected");
    }
    final Object bo = selectedBusinessObjectContexts.get(0).getBusinessObject();
    final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
    final AadlPackage pkg = Objects.requireNonNull(getPackage(bo), "Unable to retrieve package");
    diagramService.openOrCreateDiagramForBusinessObject(pkg);
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) AadlPackage(org.osate.aadl2.AadlPackage) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 18 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class OpenAssociatedDiagramHandler method setEnabled.

@Override
public void setEnabled(final Object evaluationContext) {
    boolean enabled = false;
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 1) {
        final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
        final Object bo = selectedBusinessObjectContext.getBusinessObject();
        enabled = (bo instanceof AadlPackage || bo instanceof Classifier || (bo instanceof Subcomponent && AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo) != null)) && ProjectUtil.getProjectForBo(bo).isPresent();
    }
    setBaseEnabled(enabled);
}
Also used : AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 19 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class OpenAssociatedDiagramHandler method execute.

@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
    final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof InternalDiagramEditor)) {
        throw new RuntimeException("Unexpected editor: " + activeEditor);
    }
    // Get diagram and selected BOCs
    final List<BusinessObjectContext> selectedBusinessObjectContexts = AgeHandlerUtil.getSelectedBusinessObjectContexts();
    if (selectedBusinessObjectContexts.size() == 0) {
        throw new RuntimeException("No element selected");
    }
    final BusinessObjectContext selectedBusinessObjectContext = selectedBusinessObjectContexts.get(0);
    final Object bo = selectedBusinessObjectContext.getBusinessObject();
    final DiagramService diagramService = Objects.requireNonNull(Adapters.adapt(activeEditor, DiagramService.class), "Unable to retrieve diagram service");
    if (bo instanceof AadlPackage || bo instanceof Classifier) {
        diagramService.openOrCreateDiagramForBusinessObject(bo);
    } else if (bo instanceof Subcomponent) {
        final ComponentClassifier cc = AadlSubcomponentUtil.getComponentClassifier(selectedBusinessObjectContext, (Subcomponent) bo);
        if (cc != null) {
            diagramService.openOrCreateDiagramForBusinessObject(cc);
        }
    }
    return null;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) ComponentClassifier(org.osate.aadl2.ComponentClassifier) AadlPackage(org.osate.aadl2.AadlPackage) Subcomponent(org.osate.aadl2.Subcomponent) IEditorPart(org.eclipse.ui.IEditorPart) DiagramService(org.osate.ge.internal.services.DiagramService) ComponentClassifier(org.osate.aadl2.ComponentClassifier) Classifier(org.osate.aadl2.Classifier) BusinessObjectContext(org.osate.ge.BusinessObjectContext)

Example 20 with AadlPackage

use of org.osate.aadl2.AadlPackage in project osate2 by osate.

the class CreateGeneralizationPaletteCommand method getOperation.

@Override
public Optional<Operation> getOperation(final GetCreateConnectionOperationContext ctx) {
    final Object readonlySubtype = ctx.getSource().getBusinessObject();
    final Classifier supertype = ctx.getDestination().getBusinessObject(Classifier.class).orElse(null);
    // Ensure they are valid and are not the same
    if (readonlySubtype == null || supertype == null || readonlySubtype == supertype) {
        return Optional.empty();
    }
    // Rules:
    // Abstract types can be extended by any type.
    // Types can be extended by other types in their category
    // Implementations can extend other implementations with same category and abstract implementation in some cases.
    // Feature Group Types can extend other feature group types
    final boolean canCreate = (readonlySubtype instanceof ComponentType && (supertype instanceof AbstractType || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof ComponentImplementation && (supertype instanceof AbstractImplementation || supertype.getClass() == readonlySubtype.getClass())) || (readonlySubtype instanceof FeatureGroupType && supertype instanceof FeatureGroupType);
    if (!canCreate) {
        return Optional.empty();
    }
    return Operation.createSimple(ctx.getSource(), Classifier.class, subtype -> {
        // Import the package if necessary
        if (subtype.getNamespace() instanceof PackageSection && subtype.getNamespace().getOwner() instanceof AadlPackage && supertype.getNamespace() instanceof PackageSection && supertype.getNamespace().getOwner() instanceof AadlPackage) {
            final PackageSection subtypeSection = (PackageSection) subtype.getNamespace();
            final AadlPackage supertypePackage = (AadlPackage) supertype.getNamespace().getOwner();
            AadlImportsUtil.addImportIfNeeded(subtypeSection, supertypePackage);
        }
        // Create the generalization
        final Object newBo;
        if (subtype instanceof ComponentType) {
            final ComponentType ct = (ComponentType) subtype;
            final TypeExtension te = ct.createOwnedExtension();
            te.setExtended((ComponentType) supertype);
            newBo = te;
        } else if (subtype instanceof ComponentImplementation) {
            final ComponentImplementation ci = (ComponentImplementation) subtype;
            final ImplementationExtension ie = ci.createOwnedExtension();
            ie.setExtended((ComponentImplementation) supertype);
            newBo = ie;
        } else if (subtype instanceof FeatureGroupType) {
            final FeatureGroupType fgt = (FeatureGroupType) subtype;
            final GroupExtension ge = fgt.createOwnedExtension();
            ge.setExtended((FeatureGroupType) supertype);
            newBo = ge;
        } else {
            return StepResult.abort();
        }
        return StepResultBuilder.create().showNewBusinessObject(ctx.getSource(), newBo).build();
    });
}
Also used : ComponentImplementation(org.osate.aadl2.ComponentImplementation) ComponentType(org.osate.aadl2.ComponentType) AadlPackage(org.osate.aadl2.AadlPackage) PackageSection(org.osate.aadl2.PackageSection) FeatureGroupType(org.osate.aadl2.FeatureGroupType) TypeExtension(org.osate.aadl2.TypeExtension) ImplementationExtension(org.osate.aadl2.ImplementationExtension) Classifier(org.osate.aadl2.Classifier) AbstractType(org.osate.aadl2.AbstractType) GroupExtension(org.osate.aadl2.GroupExtension) AbstractImplementation(org.osate.aadl2.AbstractImplementation)

Aggregations

AadlPackage (org.osate.aadl2.AadlPackage)106 EObject (org.eclipse.emf.ecore.EObject)45 Classifier (org.osate.aadl2.Classifier)39 NamedElement (org.osate.aadl2.NamedElement)26 ArrayList (java.util.ArrayList)22 ComponentImplementation (org.osate.aadl2.ComponentImplementation)20 PackageSection (org.osate.aadl2.PackageSection)18 Element (org.osate.aadl2.Element)17 ComponentClassifier (org.osate.aadl2.ComponentClassifier)16 PropertySet (org.osate.aadl2.PropertySet)15 AnnexLibrary (org.osate.aadl2.AnnexLibrary)14 EList (org.eclipse.emf.common.util.EList)13 Optional (java.util.Optional)11 Test (org.junit.Test)11 SystemInstance (org.osate.aadl2.instance.SystemInstance)11 List (java.util.List)10 URI (org.eclipse.emf.common.util.URI)10 Subcomponent (org.osate.aadl2.Subcomponent)10 Inject (com.google.inject.Inject)9 IFile (org.eclipse.core.resources.IFile)9