use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.
the class SetBindingTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final BusinessObjectContext[] selectedBocs = ctx.getSelectedBocs().toArray(new BusinessObjectContext[ctx.getSelectedBocs().size()]);
final AgeDiagram diagram = ctx.getDiagram();
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final UiService uiService = ctx.getUiService();
try {
final BusinessObjectContext componentImplementationBoc = ToolUtil.findComponentImplementationBoc(selectedBocs[0]);
// Open Dialog
if (currentWindow == null && componentImplementationBoc != null) {
currentWindow = new SetBindingWindow(Display.getCurrent().getActiveShell(), componentImplementationBoc, selectedBocs);
if (currentWindow.open() == Window.OK) {
// Ensure the diagram is configured to show the specified binding property
if (!diagram.getConfiguration().getEnabledAadlPropertyNames().contains(currentWindow.getSelectedProperty().getQualifiedName().toLowerCase())) {
diagram.modify("Configure Diagram", m -> {
m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).addAadlProperty(currentWindow.getSelectedProperty().getQualifiedName()).build());
});
}
// Create the property association
createPropertyAssociations(aadlModService);
}
currentWindow = null;
}
} finally {
uiService.deactivateActiveTool();
}
}
use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.
the class AgeDiagramTest method testDiagramConfigurationEvent.
// Ensure that the element updated added is received.
@Test
public void testDiagramConfigurationEvent() {
assertThat(ml.wasDiagramConfigurationChanged(), is(equalTo(false)));
// Test an add event
diagram.modify("Set Diagram Configuration", m -> m.setDiagramConfiguration(new DiagramConfigurationBuilder(new CustomDiagramType(), false).addAadlProperty("test::test2").build()));
assertThat(ml.wasDiagramConfigurationChanged(), is(equalTo(true)));
}
use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.
the class DiagramContextChecker method promptToRelink.
/**
* Returns whether or not the diagram context was adjusted.
* @param diagram
* @param missingContextRef
* @return
*/
private boolean promptToRelink(final AgeDiagram diagram) {
final CanonicalBusinessObjectReference missingContextRef = diagram.getConfiguration().getContextBoReference();
final List<String> refSegs = missingContextRef.getSegments();
if (refSegs.size() < 2) {
return false;
}
final boolean isPackageRef = DeclarativeReferenceType.PACKAGE.getId().equals(refSegs.get(0));
final boolean isClassifierRef = DeclarativeReferenceType.CLASSIFIER.getId().equals(refSegs.get(0));
final boolean isSystemInstance = AadlReferenceUtil.isSystemInstanceReference(missingContextRef);
if (!isPackageRef && !isClassifierRef && !isSystemInstance) {
return false;
}
// Determine the options to present to the user
final Collection<?> options;
String searchPrefix = "";
if (isPackageRef || isClassifierRef) {
// Find all packages
final Collection<IEObjectDescription> packageDescriptions = AadlModelAccessUtil.getAllEObjectsByType(project, Aadl2Package.eINSTANCE.getAadlPackage());
if (isPackageRef) {
options = packageDescriptions;
} else {
// isClassifierRef
options = AadlModelAccessUtil.getAllEObjectsByType(project, Aadl2Package.eINSTANCE.getClassifier());
// Check if the package portion of the qualified name is a valid package.
// If so, use it as the initial filter
final String referencedClassifierQualifiedName = refSegs.get(1);
final String[] qualifiedNameParts = referencedClassifierQualifiedName.split("::");
if (qualifiedNameParts.length == 2) {
final String pkgName = qualifiedNameParts[0];
for (final IEObjectDescription desc : packageDescriptions) {
if (desc.getName().toString("::").equalsIgnoreCase(pkgName)) {
searchPrefix = pkgName.toLowerCase() + "::";
}
}
}
}
} else if (isSystemInstance) {
options = findInstanceModelFiles(project, new ArrayList<IPath>());
} else {
// Unexpected case: there is already a short circuit for the case where the reference isn't a package or classifier reference
throw new RuntimeException("Unexpected case");
}
// Don't prompt if there aren't any options.
if (options.size() == 0) {
return false;
}
final ElementSelectionDialog dlg = new ElementSelectionDialog(null, "Missing Diagram Context", "Unable to find diagram context \"" + refService.getLabel(missingContextRef) + "\".\nIf the model element has been renamed, select the new name for the model element.", options);
dlg.setFilter(searchPrefix);
if (dlg.open() != Window.OK) {
return false;
}
final CanonicalBusinessObjectReference newContextCanonicalRef;
final RelativeBusinessObjectReference newContextRelativeRef;
final Object newContext;
if (isSystemInstance) {
final IPath systemInstancePath = (IPath) dlg.getFirstSelectedElement();
newContextCanonicalRef = AadlReferenceUtil.getCanonicalBusinessObjectReferenceForSystemInstance(systemInstanceLoader, systemInstancePath);
newContextRelativeRef = AadlReferenceUtil.getRelativeBusinessObjectReferenceForSystemInstance(systemInstanceLoader, systemInstancePath);
// Create a dummy system instance. It will be replaced as part of the diagram updating process.
newContext = InstanceFactory.eINSTANCE.createSystemInstance();
} else {
final EObject newContextProxy = (EObject) dlg.getFirstSelectedElement();
// Find the live object
final ResourceSet liveResourceSet = AadlModelAccessUtil.getLiveResourceSet(project);
newContext = EcoreUtil.resolve(newContextProxy, liveResourceSet);
if (((EObject) newContext).eIsProxy()) {
throw new RuntimeException("Unable to retrieve non-proxy object for selection");
}
// Find canonical and relative reference
newContextCanonicalRef = refService.getCanonicalReference(newContext);
if (newContextCanonicalRef == null) {
throw new RuntimeException("Unable to retrieve reference for new diagram context: " + newContext);
}
newContextRelativeRef = refService.getRelativeReference(newContext);
if (newContextRelativeRef == null) {
throw new RuntimeException("Unable to retrieve relative reference for new diagram context: " + newContext);
}
}
// Update the diagram
diagram.modify("Update Diagram Context", m -> {
// Update the diagram's context
m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).contextBoReference(newContextCanonicalRef).build());
// Update the root element
if (diagram.getChildren().size() == 1) {
m.updateBusinessObject(diagram.getChildren().stream().findAny().get(), newContext, newContextRelativeRef);
}
});
return true;
}
use of org.osate.ge.internal.diagram.runtime.DiagramConfigurationBuilder 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.diagram.runtime.DiagramConfigurationBuilder in project osate2 by osate.
the class DiagramConfigurationDialog method main.
public static void main(String[] args) {
final Model model = new Model() {
@Override
public RelativeBusinessObjectReference getRelativeBusinessObjectReference(final Object bo) {
return new RelativeBusinessObjectReference(bo.toString());
}
@Override
public Collection<Object> getChildBusinessObjects(final BusinessObjectContext boc) {
final Collection<Object> children = new ArrayList<>();
for (int i = 1; i <= 100; i++) {
children.add("C" + i);
}
return children;
}
@Override
public String getName(final BusinessObjectContext boc) {
return boc.getBusinessObject().toString();
}
@Override
public ImmutableSet<ContentFilter> getDefaultContentFilters(final Object bo) {
return ImmutableSet.of(TestContentsFilter.FILTER1);
}
@Override
public Map<String, Collection<String>> getAadlProperties() {
final Map<String, Collection<String>> result = new HashMap<>();
result.put("test_ps1", Arrays.asList(new String[] { "a", "c", "b" }));
result.put("test_ps2", Arrays.asList(new String[] { "a", "b", "c" }));
result.put("test_ps3", Arrays.asList(new String[] { "d", "f", "e" }));
return result;
}
@Override
public Object getBusinessObject(final CanonicalBusinessObjectReference ref) {
return new Object();
}
@Override
public String getContextDescription(final Object contextBo) {
return "a::b::c (TestType)";
}
@Override
public boolean shouldShowBusinessObject(final Object bo) {
return !bo.equals("C3");
}
@Override
public Image getImage(final Object bo) {
return null;
}
@Override
public Object resolve(final Object bo) {
return bo;
}
@Override
public boolean isProxy(Object bo) {
return false;
}
};
final DiagramConfiguration diagramConfig = new DiagramConfigurationBuilder(new CustomDiagramType(), false).contextBoReference(new CanonicalBusinessObjectReference("test")).addAadlProperty("test::prop1").addAadlProperty("test_ps2::b").connectionPrimaryLabelsVisible(true).build();
// Create a test business object tree
final BusinessObjectNode rootNode = new BusinessObjectNode(null, UUID.randomUUID(), null, null, Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("A"), "A", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("B"), "B", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("C"), "C", Completeness.UNKNOWN, true);
new BusinessObjectNode(rootNode, UUID.randomUUID(), new RelativeBusinessObjectReference("D"), "D", Completeness.UNKNOWN, true);
// Show the dialog
final Result result = DiagramConfigurationDialog.show(null, model, diagramConfig, rootNode, new Object[] { "A", "C1", "C2", "C4" });
if (result == null) {
System.out.println("Dialog was canceled.");
} else {
System.out.println(result.getDiagramConfiguration());
System.out.println(result.getBusinessObjectTree());
}
}
Aggregations