Search in sources :

Example 1 with ClassifierOperation

use of org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation in project osate2 by osate.

the class CreateClassifierPaletteCommand method buildCreateOperations.

/**
 * Build the operation that will be executed to create the classifier.
 * Returns null if the operation could not be created. For example: if the dialog was canceled.
 * @param pkg
 * @param targetBo
 * @param classifierType
 * @param project
 * @param namingService
 * @param rs
 * @return
 */
private ClassifierOperation buildCreateOperations(final AadlPackage pkg, final EObject targetBo, final IProject project, final ResourceSet rs) {
    final ClassifierCreationHelper classifierCreationHelper = new ClassifierCreationHelper(rs);
    // Handle case where target is a valid base classifier for quick creation.
    // Determine if the container is a valid base classifier
    final boolean targetIsValidBase = isValidBaseClassifier(targetBo);
    if (targetIsValidBase || !componentImplementation) {
        // 
        // Create the base operation part
        // 
        final EObject baseClassifier = targetIsValidBase ? targetBo : null;
        final ClassifierOperationPart basePart = baseClassifier == null ? ClassifierOperationPart.createNone() : ClassifierOperationPart.createExisting(baseClassifier);
        // 
        // Create the primary operation part
        // 
        final ClassifierOperationPartType primaryType;
        final ComponentCategory primaryComponentCategory;
        if (componentCategory == null) {
            primaryType = ClassifierOperationPartType.NEW_FEATURE_GROUP_TYPE;
            primaryComponentCategory = null;
        } else {
            primaryType = componentImplementation ? ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION : ClassifierOperationPartType.NEW_COMPONENT_TYPE;
            primaryComponentCategory = componentCategory;
        }
        final String defaultIdentifier = componentImplementation ? "impl" : "new_classifier";
        // Determine a unique name for the classifier
        final String potentialFullName = classifierCreationHelper.buildName(primaryType, pkg, defaultIdentifier, basePart);
        if (potentialFullName == null) {
            return null;
        }
        final String newName = AadlNamingUtil.buildUniqueIdentifier(pkg.getPublicSection(), potentialFullName);
        // Retrieve the identifier to be used for creation. For component implementations this is the part after the ".". For other types, it is the entire
        // name
        final String[] nameSegments = newName.split("\\.");
        final String primaryIdentifier = nameSegments[nameSegments.length - 1];
        final ClassifierOperationPart configuredPrimaryOperation = ClassifierOperationPart.createCreation(primaryType, pkg, primaryIdentifier, primaryComponentCategory);
        return new ClassifierOperation(configuredPrimaryOperation, basePart);
    } else {
        final ClassifierOperationDialog.Model model = new DefaultCreateSelectClassifierDialogModel(rs, "Configure component implementation.") {

            @Override
            public String getTitle() {
                return "Create Component Implementation";
            }

            @Override
            public Collection<?> getPackageOptions() {
                return AadlUiUtil.getEditablePackages(project);
            }

            @Override
            public Collection<?> getBaseSelectOptions(final ClassifierOperationPartType primaryOperation) {
                return AadlUiUtil.getValidBaseClassifierDescriptions(project, componentCategory, true);
            }

            @Override
            public Collection<?> getUnfilteredBaseSelectOptions(final ClassifierOperationPartType primaryOperation) {
                return null;
            }
        };
        // Show the dialog to determine the operation
        return ClassifierOperationDialog.show(Display.getCurrent().getActiveShell(), new ClassifierOperationDialog.ArgumentBuilder(model, EnumSet.of(ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION)).defaultPackage(pkg).showPrimaryPackageSelector(false).componentCategories(ImmutableList.of(componentCategory)).create());
    }
}
Also used : ClassifierOperationDialog(org.osate.ge.aadl2.ui.internal.dialogs.ClassifierOperationDialog) ClassifierOperationPart(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPart) ClassifierOperationPartType(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) DefaultCreateSelectClassifierDialogModel(org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel) ComponentCategory(org.osate.aadl2.ComponentCategory) EObject(org.eclipse.emf.ecore.EObject) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation)

Example 2 with ClassifierOperation

use of org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation 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 3 with ClassifierOperation

use of org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation in project osate2 by osate.

the class ClassifierOperationDialog method main.

public static void main(final String[] args) {
    final Model testModel = new Model() {

        @Override
        public String getTitle() {
            return "Select Element";
        }

        @Override
        public String getMessage(final ClassifierOperation value) {
            return "Select an element.";
        }

        @Override
        public Collection<?> getPackageOptions() {
            final List<Object> result = new ArrayList<>();
            result.add("A");
            result.add("B");
            return result;
        }

        @Override
        public String getPrimarySelectTitle() {
            return "Select Element";
        }

        @Override
        public String getPrimarySelectMessage() {
            return "Select an element.";
        }

        @Override
        public List<Object> getPrimarySelectOptions() {
            final List<Object> result = new ArrayList<>();
            result.add("C");
            result.add("D");
            return result;
        }

        @Override
        public List<Object> getUnfilteredPrimarySelectOptions() {
            final List<Object> result = getPrimarySelectOptions();
            result.add("E");
            result.add("F");
            return result;
        }

        @Override
        public List<Object> getBaseSelectOptions(final ClassifierOperationPartType primaryOperation) {
            final List<Object> result = new ArrayList<>();
            result.add("G");
            result.add("H");
            return result;
        }

        @Override
        public Collection<?> getUnfilteredBaseSelectOptions(final ClassifierOperationPartType primaryOperation) {
            final List<Object> result = getBaseSelectOptions(primaryOperation);
            result.add("I");
            result.add("J");
            return result;
        }

        @Override
        public String validate(final ClassifierOperation value) {
            return (value.getPrimaryPart().getType() == ClassifierOperationPartType.NEW_COMPONENT_IMPLEMENTATION && value.getPrimaryPart().getIdentifier().isEmpty()) ? "Primary identifier must not be empty." : null;
        }
    };
    Display.getDefault().syncExec(() -> {
        final ClassifierOperation result = show(new Shell(), new ArgumentBuilder(testModel, EnumSet.complementOf(EnumSet.of(ClassifierOperationPartType.NONE))).componentCategories(ImmutableList.of(ComponentCategory.ABSTRACT)).create());
        System.out.println("Result: " + result);
    });
}
Also used : Shell(org.eclipse.swt.widgets.Shell) ArrayList(java.util.ArrayList) ClassifierOperationPartType(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType) ClassifierOperation(org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation)

Aggregations

ClassifierOperation (org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperation)3 ClassifierOperationPartType (org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPartType)3 EObject (org.eclipse.emf.ecore.EObject)2 ComponentCategory (org.osate.aadl2.ComponentCategory)2 ClassifierCreationHelper (org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper)2 ClassifierOperationPart (org.osate.ge.aadl2.internal.util.classifiers.ClassifierOperationPart)2 ClassifierOperationDialog (org.osate.ge.aadl2.ui.internal.dialogs.ClassifierOperationDialog)2 DefaultCreateSelectClassifierDialogModel (org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel)2 ImmutableList (com.google.common.collect.ImmutableList)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 EnumSet (java.util.EnumSet)1 Optional (java.util.Optional)1 IProject (org.eclipse.core.resources.IProject)1 EClass (org.eclipse.emf.ecore.EClass)1 ResourceSet (org.eclipse.emf.ecore.resource.ResourceSet)1 Display (org.eclipse.swt.widgets.Display)1 Shell (org.eclipse.swt.widgets.Shell)1 Aadl2Package (org.osate.aadl2.Aadl2Package)1 AadlPackage (org.osate.aadl2.AadlPackage)1