use of org.osate.ge.businessobjecthandling.CanRenameContext in project osate2 by osate.
the class EditorRenameUtil method canRename.
public static boolean canRename(final DiagramElement de) {
final Object bo = de.getBusinessObject();
// Only EObjects are supported at this time
if (!(bo instanceof EObject)) {
return false;
}
final BusinessObjectHandler handler = de.getBusinessObjectHandler();
if (!handler.canRename(new CanRenameContext(bo))) {
return false;
}
if (!RenameUtil.supportsNonLtkRename(handler) && RenameUtil.getRenameRefactoring(bo) == null) {
return false;
}
return true;
}
use of org.osate.ge.businessobjecthandling.CanRenameContext in project osate2 by osate.
the class PasteAction method ensureBusinessObjectHasUniqueName.
/**
* If the element is renameable and the name can be validated, then generate a name that passes validation.
* Otherwise, do not change the element's name. Contains special handling for component implementations.
* @param bo
* @param boHandler
*/
private static void ensureBusinessObjectHasUniqueName(final EObject bo, final BusinessObjectHandler boHandler) {
if (supportsRenaming(bo, boHandler) && boHandler.canRename(new CanRenameContext(bo))) {
// Determine the current name of the business object.
final String originalName = boHandler.getNameForRenaming(new GetNameContext(bo));
// contain the component type / component type alias appropriate for the destination package.
if (bo instanceof ComponentImplementation) {
final ComponentImplementation ci = (ComponentImplementation) bo;
final ComponentType ct = ci.getType();
final ClassifierCreationHelper classifierCreationHelper = new ClassifierCreationHelper(ci.eResource().getResourceSet());
final String ciTypeName;
if (ct == null) {
ciTypeName = ci.getTypeName();
} else {
if (!AadlNameUtil.namesAreEqual(ci.getNamespace(), ct.getNamespace())) {
if (!(ci.getNamespace() instanceof PackageSection)) {
throw new RuntimeException("New component implementation is not contained in a package section");
}
final PackageSection section = (PackageSection) ci.getNamespace();
// Import the package if necessary
final AadlPackage typePkg = (AadlPackage) ct.getNamespace().getOwner();
AadlImportsUtil.addImportIfNeeded(section, typePkg);
// Create an alias for the component type
final ClassifierCreationHelper.RenamedTypeDetails aliasDetails = classifierCreationHelper.getRenamedType(section, typePkg, ct.getName());
if (!aliasDetails.exists) {
final ComponentTypeRename ctr = section.createOwnedComponentTypeRename();
ctr.setName(aliasDetails.aliasName);
ctr.setCategory(ct.getCategory());
ctr.setRenamedComponentType(ct);
}
ciTypeName = aliasDetails.aliasName;
} else {
ciTypeName = ct.getName();
}
}
setName(bo, boHandler, ciTypeName + ".osate_ge_temporary_name_00001");
} else {
// Set name to dummy name so that validate name will work as expected. Many implementations
// of validate name check if the name has changed.
setName(bo, boHandler, "");
}
// Determine a new name for the business object
final String baseName = originalName;
String newName = originalName;
int count = 1;
while (true) {
final String result = RenameUtil.checkNewNameValidity(bo, boHandler, newName);
if (result == null) {
break;
}
newName = baseName + "_copy" + (count == 1 ? "" : Integer.toString(count));
count++;
}
// specified value does not include the type name.
if (bo instanceof ComponentImplementation) {
newName = ((ComponentImplementation) bo).getTypeName() + "." + newName;
}
// Update the business object's name
setName(bo, boHandler, newName);
}
}
Aggregations