use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class GefDiagramExportService method loadDiagram.
private GefAgeDiagram loadDiagram(final IFile diagramFile) {
final URI uri = URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true);
final IProject project = ProjectUtil.getProjectOrNull(uri);
final org.osate.ge.diagram.Diagram mmDiagram = DiagramSerialization.readMetaModelDiagram(uri);
final IEclipseContext eclipseContext = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(GefDiagramExportService.class).getBundleContext());
final ExtensionRegistryService extensionRegistry = Objects.requireNonNull(eclipseContext.get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
final ReferenceService referenceService = Objects.requireNonNull(eclipseContext.get(ReferenceService.class), "unable to retrieve reference service");
final ActionService actionService = Objects.requireNonNull(eclipseContext.get(ActionService.class), "unable to retrieve action service");
final AgeDiagram diagram = DiagramSerialization.createAgeDiagram(project, mmDiagram, extensionRegistry);
// Update the diagram
final QueryService queryService = new DefaultQueryService(referenceService);
final ProjectProvider projectProvider = diagramFile::getProject;
final ProjectReferenceService projectReferenceService = new ProjectReferenceServiceProxy(referenceService, projectProvider);
final BusinessObjectNodeFactory nodeFactory = new BusinessObjectNodeFactory(projectReferenceService);
final DefaultBusinessObjectTreeUpdater boTreeUpdater = new DefaultBusinessObjectTreeUpdater(projectProvider, extensionRegistry, projectReferenceService, queryService, nodeFactory);
final DefaultDiagramElementGraphicalConfigurationProvider deInfoProvider = new DefaultDiagramElementGraphicalConfigurationProvider(queryService, () -> diagram, extensionRegistry);
final DiagramUpdater diagramUpdater = new DiagramUpdater(boTreeUpdater, deInfoProvider, actionService, projectReferenceService, projectReferenceService);
diagramUpdater.updateDiagram(diagram);
// Create the GEF Diagram
final GefAgeDiagram gefDiagram = new GefAgeDiagram(diagram, new DefaultColoringService(new org.osate.ge.internal.services.impl.DefaultColoringService.StyleRefresher() {
@Override
public void refreshDiagramColoring() {
// No-op. Handling coloring service refresh requests is not required.
}
@Override
public void refreshColoring(final Collection<DiagramElement> diagramElements) {
// No-op. Handling coloring service refresh requests is not required.
}
}));
// Add to scene. This is required for text rendering
new Scene(gefDiagram.getSceneNode());
// Update the diagram to reflect the scene graph and perform incremental layout
gefDiagram.updateDiagramFromSceneGraph(false);
diagram.modify("Incremental Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, gefDiagram));
return gefDiagram;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class AgeDiagramTest method beforeTest.
@Before
public void beforeTest() {
diagram = new AgeDiagram();
diagram.addModificationListener(ml);
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class DefaultDiagramService method getReferences.
@Override
public ReferenceCollection getReferences(final Set<IProject> relevantProjects, final Set<CanonicalBusinessObjectReference> originalCanonicalReferences) {
final InternalReferencesToUpdate references = new InternalReferencesToUpdate();
Display.getDefault().syncExec(() -> {
// Create updateable reference for open diagrams
for (final InternalDiagramEditor editor : getOpenEditorsMap(relevantProjects).values()) {
final AgeDiagramProvider diagramProvider = editor.getAdapter(AgeDiagramProvider.class);
if (diagramProvider == null) {
continue;
}
final AgeDiagram diagram = diagramProvider.getAgeDiagram();
if (diagram == null) {
continue;
}
// Update the diagram immediately. This is intended to ensure the diagram doesn't have any proxies
editor.updateNowIfModelHasChanged();
final CanonicalBusinessObjectReference diagramContextRef = diagram.getConfiguration().getContextBoReference();
if (diagramContextRef != null && originalCanonicalReferences.contains(diagramContextRef)) {
references.addReference(editor, diagramContextRef, new OpenDiagramContextReference(diagram));
}
// Get references from the diagram elements
getRuntimeReferencesFromChildren(editor, diagram, originalCanonicalReferences, references);
}
// Create updateable references for saved diagrams
savedDiagramIndex.getDiagramsByContexts(relevantProjects.stream(), originalCanonicalReferences).forEach(e -> references.addReference(e.getDiagramFile(), e.getContext(), new SavedDiagramContextReference()));
savedDiagramIndex.getDiagramElementUrisByReferences(relevantProjects.stream(), originalCanonicalReferences).forEach(e -> references.addReference(e.diagramFile, e.reference, new SavedDiagramElementReference(e.diagramElementUri)));
});
return references;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class ConfigureDiagramHandler method execute.
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (!(activeEditor instanceof InternalDiagramEditor)) {
throw new RuntimeException("Unexpected editor: " + activeEditor);
}
// Get diagram and selected elements
final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = diagramEditor.getDiagram();
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
// Get services
final BusinessObjectTreeUpdater boTreeUpdater = diagramEditor.getBoTreeUpdater();
final DiagramUpdater diagramUpdater = diagramEditor.getDiagramUpdater();
final ProjectProvider projectProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectProvider.class), "Unable to retrieve project provider");
final LayoutInfoProvider layoutInfoProvider = Objects.requireNonNull(Adapters.adapt(diagramEditor, LayoutInfoProvider.class), "Unable to retrieve layout information provider");
final ExtensionRegistryService extService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ExtensionRegistryService.class), "Unable to retrieve extension service");
final ProjectReferenceService referenceService = Objects.requireNonNull(Adapters.adapt(diagramEditor, ProjectReferenceService.class), "Unable to retrieve reference service");
BusinessObjectNode boTree = DiagramToBusinessObjectTreeConverter.createBusinessObjectNode(diagram);
// Update the tree so that it's business objects are refreshed
boTree = boTreeUpdater.updateTree(diagram.getConfiguration(), boTree);
final DefaultDiagramConfigurationDialogModel model = new DefaultDiagramConfigurationDialogModel(referenceService, extService, projectProvider, diagram.getConfiguration().getDiagramType());
// Create a BO path for the initial selection. The initial selection will be the first diagram element which will be included in the BO tree.
Object[] initialSelectionBoPath = null;
for (final DiagramElement selectedDiagramElement : selectedDiagramElements) {
if (model.shouldShowBusinessObject(selectedDiagramElement.getBusinessObject())) {
// Only build a selection path if the BO will be shown
DiagramNode tmp = selectedDiagramElement;
final LinkedList<Object> boList = new LinkedList<>();
while (tmp instanceof DiagramElement) {
boList.addFirst(tmp.getBusinessObject());
tmp = tmp.getParent();
}
initialSelectionBoPath = boList.toArray();
break;
}
}
// Show the dialog
final DiagramConfigurationDialog.Result result = DiagramConfigurationDialog.show(null, model, diagram.getConfiguration(), boTree, initialSelectionBoPath);
if (result != null) {
// Update the diagram
diagramEditor.getActionExecutor().execute("Set Diagram Configuration", ExecutionMode.NORMAL, () -> {
diagram.modify("Set Diagram Configuration", m -> {
m.setDiagramConfiguration(result.getDiagramConfiguration());
diagramUpdater.updateDiagram(diagram, result.getBusinessObjectTree());
});
// Clear ghosts triggered by this update to prevent them from being unghosted during the next update.
diagramUpdater.clearGhosts();
diagram.modify("Layout", m -> DiagramElementLayoutUtil.layoutIncrementally(diagram, m, layoutInfoProvider));
return null;
});
}
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class DistributeHorizontallyHandler method execute.
/**
* Distributes shapes along the X axis so each shape has an equal distance between them
*/
@Override
public Object execute(final ExecutionEvent event) throws ExecutionException {
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
diagram.modify("Distribute Horizontally", m -> {
selectedDiagramElements.sort(XValueComparator);
// Distribute the shapes horizontally
final double xDistribution = getXDistribution(selectedDiagramElements);
for (int i = 1; i < selectedDiagramElements.size() - 1; i++) {
final DiagramElement de = selectedDiagramElements.get(i);
final double x = getXValue(selectedDiagramElements.get(i - 1), xDistribution);
final double y = de.getY();
DiagramElementLayoutUtil.moveElement(m, de, new Point(x, y));
}
});
return null;
}
Aggregations