use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DefaultDiagramService method createDiagram.
@Override
public void createDiagram(final IFile diagramFile, final DiagramType diagramType, final Object contextBo) {
// Create an AgeDiagram object. This object doesn't have to be completely valid. It just needs to be able to be written.
final AgeDiagram diagram = new AgeDiagram();
// Build diagram configuration
final CanonicalBusinessObjectReference contextBoCanonicalRef = contextBo == null ? null : Objects.requireNonNull(referenceService.getCanonicalReference(contextBo), "Unable to build canonical reference for business object: " + contextBo);
diagram.modify("Configure Diagram", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagramType, true).contextBoReference(contextBoCanonicalRef).connectionPrimaryLabelsVisible(false).build()));
final URI newDiagramUri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
DiagramSerialization.write(diagramFile.getProject(), diagram, newDiagramUri);
try {
diagramFile.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (final CoreException e) {
throw new GraphicalEditorException(e);
}
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DefaultBusinessObjectTreeUpdater method updateTree.
@Override
public BusinessObjectNode updateTree(final DiagramConfiguration configuration, final BusinessObjectNode tree) {
// Refresh Child Nodes
final BusinessObjectProviderHelper bopHelper = new BusinessObjectProviderHelper(extService);
final BusinessObjectNode newRoot = nodeFactory.create(null, UUID.randomUUID(), null, Completeness.UNKNOWN);
final Map<RelativeBusinessObjectReference, Object> boMap;
// Determine what business objects are required based on the diagram configuration
if (configuration.getContextBoReference() == null) {
// Get potential top level business objects from providers
// A simple business object context which is used as the root BOC for contextless diagrams. It has no parent and used the current
// project as the business object.
final BusinessObjectContext contextlessRootBoc = new BusinessObjectContext() {
@Override
public Collection<? extends BusinessObjectContext> getChildren() {
return Collections.emptyList();
}
@Override
public BusinessObjectContext getParent() {
return null;
}
@Override
public Object getBusinessObject() {
return projectProvider.getProject();
}
};
final Collection<Object> potentialRootBusinessObjects = bopHelper.getChildBusinessObjects(contextlessRootBoc);
// Determine the root business objects
final Set<RelativeBusinessObjectReference> existingRootBranches = tree.getChildrenMap().keySet();
// Content filters are not supported for the root of diagrams.
final ImmutableSet<ContentFilter> rootContentFilters = ImmutableSet.of();
boMap = getChildBusinessObjects(potentialRootBusinessObjects, existingRootBranches, rootContentFilters);
// Contextless diagrams are always considered complete
newRoot.setCompleteness(Completeness.COMPLETE);
// This is needed so the configure diagram dialog, etc will know which project should be used to
// retrieve root objects.
// Set the root of the BO tree to the project
newRoot.setBusinessObject(projectProvider.getProject());
} else {
// Get the context business object
Object contextBo = refService.resolve(configuration.getContextBoReference());
if (contextBo == null) {
final String contextLabel = refService.getLabel(configuration.getContextBoReference());
throw new GraphicalEditorException("Unable to find context business object: " + contextLabel);
}
// Require the use of the business object specified in the diagram along with any other business objects which are already in the diagram.
final RelativeBusinessObjectReference relativeReference = refService.getRelativeReference(contextBo);
if (relativeReference == null) {
throw new GraphicalEditorException("Unable to build relative reference for context business object: " + contextBo);
}
boMap = new HashMap<>();
boMap.put(relativeReference, contextBo);
newRoot.setCompleteness(Completeness.COMPLETE);
}
// Add embedded business objects to the child BO map
addEmbeddedBusinessObjectsToBoMap(tree.getChildrenMap().values(), boMap);
// Populate the new tree
final Map<RelativeBusinessObjectReference, BusinessObjectNode> oldNodes = tree.getChildrenMap();
createNodes(configuration.getDiagramType(), bopHelper, boMap, oldNodes, newRoot);
// Build set of the names of all properties which are enabled
final Set<String> enabledPropertyNames = new HashSet<>(configuration.getEnabledAadlPropertyNames());
// Add properties which are always enabled regardless of configuration setting
enabledPropertyNames.add("communication_properties::timing");
// Get the property objects
final Set<Property> enabledProperties = getPropertiesByLowercasePropertyNames(enabledPropertyNames);
// Process properties. This is done after everything else since properties may need to refer to other nodes.
final AadlPropertyResolver propertyResolver = new AadlPropertyResolver(newRoot);
processProperties(propertyResolver, newRoot, tree, enabledProperties);
return newRoot;
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class LtkRenameAction method renameWithLtk.
/**
* Renames the specified model element using an LTK rename refactoring.
* @param bo the model element to rename
* @param value the new name for the model element
* @return true if the rename occurred
*/
private boolean renameWithLtk(final EObject bo, final String value) {
// Prevent model notification changes from being sent until after the refactoring
try (Lock lock = modelChangeNotifier.lock()) {
// Rename the element using LTK
final ProcessorBasedRefactoring renameRefactoring = RenameUtil.getRenameRefactoring(bo);
final RefactoringStatus refactoringStatus = prepareAndCheck(renameRefactoring, value);
if (!refactoringStatus.isOK()) {
final Dialog dlg = RefactoringUI.createRefactoringStatusDialog(refactoringStatus, Display.getCurrent().getActiveShell(), "Refactoring", false);
if (dlg.open() != Window.OK) {
// Abort
return false;
}
}
try {
final Change change = renameRefactoring.createChange(new NullProgressMonitor());
new WorkspaceModifyOperation() {
@Override
protected void execute(IProgressMonitor monitor) throws CoreException {
// Perform the modification
change.perform(monitor);
// Build the project, reconcile all open AADL text editors and then build again.
// This seems to be the best way to ensure that all the model change events have been
// queued before the model change notification lock is released
buildProject();
ensureReconciled();
buildProject();
}
}.run(null);
} catch (final InterruptedException e) {
Thread.currentThread().interrupt();
throw new GraphicalEditorException(e);
} catch (final RuntimeException | InvocationTargetException | CoreException e) {
throw new GraphicalEditorException(e);
}
}
return true;
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DefaultAadlModificationService method getParsedAnnexRootIndices.
/**
* Return indices that indicate the location of an object within a parsed annex element.
* @param obj
* @return
*/
private Deque<Integer> getParsedAnnexRootIndices(final EObject obj) {
assert !(obj instanceof DefaultAnnexLibrary || obj instanceof DefaultAnnexSubclause);
final Deque<Integer> indices = new ArrayDeque<>();
// Find the root of the parsed annex
EObject tmp = obj;
while (tmp != null && !(tmp instanceof AnnexLibrary || tmp instanceof AnnexSubclause)) {
final int newIndex = ECollections.indexOf(tmp.eContainer().eContents(), tmp, 0);
if (newIndex == -1) {
throw new GraphicalEditorException("Unable to get index inside of container contents");
}
indices.push(newIndex);
;
tmp = tmp.eContainer();
}
return indices;
}
use of org.osate.ge.internal.GraphicalEditorException in project osate2 by osate.
the class DefaultAadlModificationService method modifyAnnexInXtextDocument.
private <TagType, BusinessObjectType extends EObject> ModifySafelyResults modifyAnnexInXtextDocument(final XtextResource resource, final EObject defaultAnnexElement, final TagType tag, final BusinessObjectType bo, final Modifier<TagType, BusinessObjectType> modifier) {
// Make a copy of the resource
final EObject parsedAnnexElement = getParsedAnnexElement(defaultAnnexElement);
final ResourceSet tmpResourceSet = new ResourceSetImpl();
final Resource tmpResource = tmpResourceSet.createResource(resource.getURI());
tmpResource.getContents().addAll(EcoreUtil.copyAll(resource.getContents()));
// Clone the bo specified by the modification
final EObject parsedAnnexRootClone = tmpResourceSet.getEObject(EcoreUtil.getURI(parsedAnnexElement), false);
final Deque<Integer> indexStack = getParsedAnnexRootIndices(bo);
EObject tmpClonedObject = parsedAnnexRootClone;
while (!indexStack.isEmpty()) {
tmpClonedObject = tmpClonedObject.eContents().get(indexStack.pop());
}
@SuppressWarnings("unchecked") final BusinessObjectType clonedUserObject = (BusinessObjectType) tmpClonedObject;
// Modify the annex by modifying the cloned object, unparsing, and then updating the source text of the original default annex element.
return modifySafely(resource, tag, defaultAnnexElement, (unusedTag, defaultAnnexElement1) -> {
// Modify the cloned object
modifier.modify(tag, clonedUserObject);
// Unparse the annex text of the cloned object and update the Xtext document
if (parsedAnnexRootClone instanceof AnnexLibrary) {
final DefaultAnnexLibrary defaultAnnexLibrary = (DefaultAnnexLibrary) defaultAnnexElement1;
final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexLibrary.getName()).unparseAnnexLibrary((AnnexLibrary) parsedAnnexRootClone, " ");
final String sourceTxt1 = alignAnnexTextToCore(resource, annexText, 1);
EcoreUtil.delete(defaultAnnexLibrary.getParsedAnnexLibrary());
defaultAnnexLibrary.setSourceText(sourceTxt1);
} else if (parsedAnnexRootClone instanceof AnnexSubclause) {
final DefaultAnnexSubclause defaultAnnexSubclause = (DefaultAnnexSubclause) defaultAnnexElement1;
final String annexText = getAnnexUnparserRegistry().getAnnexUnparser(defaultAnnexSubclause.getName()).unparseAnnexSubclause((AnnexSubclause) parsedAnnexRootClone, " ");
final String sourceTxt2 = alignAnnexTextToCore(resource, annexText, 2);
EcoreUtil.delete(defaultAnnexSubclause.getParsedAnnexSubclause());
defaultAnnexSubclause.setSourceText(sourceTxt2);
} else {
throw new GraphicalEditorException("Unhandled case, parsedAnnexRoot is of type: " + parsedAnnexRootClone.getClass());
}
}, false);
}
Aggregations