use of org.osate.ge.aadl2.ui.internal.dialogs.DefaultCreateSelectClassifierDialogModel 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());
}
}
Aggregations