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());
}
}
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);
}));
});
});
}
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);
});
}
Aggregations