use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class DistributeVerticallyHandler method execute.
/**
* Distributes shapes along the Y 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 Vertically", m -> {
selectedDiagramElements.sort(YValueComparator);
// Distribute the shapes horizontally
final double yDistribution = getYDistribution(selectedDiagramElements);
for (int i = 1; i < selectedDiagramElements.size() - 1; i++) {
final DiagramElement de = selectedDiagramElements.get(i);
final double x = de.getX();
final double y = getYValue(selectedDiagramElements.get(i - 1), yDistribution);
DiagramElementLayoutUtil.moveElement(m, de, new Point(x, y));
}
});
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class HideAllContentsHandler 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 the extension registry
final Bundle bundle = FrameworkUtil.getBundle(getClass());
final ExtensionRegistryService extService = EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class);
if (extService == null) {
throw new RuntimeException("Unable to retrieve extension registry");
}
// Get diagram and selected elements
final InternalDiagramEditor diagramEditor = (InternalDiagramEditor) activeEditor;
final List<DiagramElement> selectedDiagramElements = AgeHandlerUtil.getSelectedDiagramElements();
final AgeDiagram diagram = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
diagram.modify("Hide All Contents", m -> {
// Remove children of selected elements
for (final DiagramElement e : selectedDiagramElements) {
for (final DiagramElement child : e.getChildren()) {
m.removeElement(child);
}
}
});
// Update the diagram
diagramEditor.updateDiagram();
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class HideElementHandler 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 = UiUtil.getDiagram(selectedDiagramElements);
if (diagram == null) {
throw new RuntimeException("Unable to get diagram");
}
final List<DiagramElement> elementsToHide = getElementsToHide(selectedDiagramElements);
diagram.modify("Hide", m -> {
// Hide selected elements
for (final DiagramElement e : elementsToHide) {
m.removeElement(e);
}
});
// Update the diagram
diagramEditor.updateDiagram();
return null;
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class PasteAction method run.
@Override
public void run() {
// Get services
final Bundle bundle = FrameworkUtil.getBundle(getClass());
final IEclipseContext context = EclipseContextFactory.getServiceContext(bundle.getBundleContext());
final AadlModificationService aadlModificationService = Objects.requireNonNull(context.getActive(AadlModificationService.class), "Unable to retrieve AADL modification service");
final ReferenceBuilderService refBuilder = Objects.requireNonNull(context.getActive(ReferenceBuilderService.class), "Unable to retrieve reference builder service");
// Perform modification
final DiagramNode dstDiagramNode = getDestinationDiagramNode();
final EObject dstBo = getDestinationEObject(dstDiagramNode);
final AgeDiagram diagram = DiagramElementUtil.getDiagram(dstDiagramNode);
final List<DiagramElement> newDiagramElements = new ArrayList<>();
diagram.modify("Paste", m -> {
// The modifier will do the actual copying to the diagram elements. It will also copy the business objects
// if the copied element includes the business object.
final SimpleModifier<EObject> modifier = dstBoToModify -> {
newDiagramElements.addAll(copyClipboardContents(dstBoToModify, dstDiagramNode, m, refBuilder));
};
// If any non-embedded business objects have been copied, then modify the AADL model. Otherwise, just modify the diagram.
final boolean anyHaveNonEmbeddedBo = getCopiedDiagramElements().stream().anyMatch(de -> de.getCopiedBusinessObject() instanceof EObject);
if (anyHaveNonEmbeddedBo) {
aadlModificationService.modify(dstBo, modifier);
} else {
modifier.modify(null);
}
// Update the diagram. This will set business objects and update the diagram to be consistent.
editor.getDiagramUpdater().updateDiagram(diagram);
});
// Update selection to match created diagram elements
editor.selectDiagramNodes(newDiagramElements);
}
use of org.osate.ge.internal.diagram.runtime.AgeDiagram in project osate2 by osate.
the class ShowHideFiltersContributionItem method getContributionItems.
@Override
protected IContributionItem[] getContributionItems() {
final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return EMPTY;
}
if (window.getActivePage() == null) {
return EMPTY;
}
final IEditorPart activeEditor = window.getActivePage().getActiveEditor();
if (!(activeEditor instanceof InternalDiagramEditor)) {
return EMPTY;
}
// Don't contribute commands if editor is not editable
final InternalDiagramEditor editor = (InternalDiagramEditor) activeEditor;
if (activeEditor == null || !editor.isEditable()) {
return EMPTY;
}
final Bundle bundle = FrameworkUtil.getBundle(getClass());
final ExtensionRegistryService extRegistry = Objects.requireNonNull(EclipseContextFactory.getServiceContext(bundle.getBundleContext()).get(ExtensionRegistryService.class), "Unable to retrieve extension registry");
final List<DiagramElement> diagramElements = SelectionUtil.getSelectedDiagramElements(window.getActivePage().getSelection(), true);
final AgeDiagram diagram = UiUtil.getDiagram(diagramElements);
if (diagram == null) {
return EMPTY;
}
final Multimap<String, ContentFilter> parentToApplicableFiltersMap = HashMultimap.create();
for (final ContentFilter contentFilter : extRegistry.getConfigurableContentFilters()) {
for (final DiagramElement diagramElement : diagramElements) {
if (contentFilter.isApplicable(diagramElement.getBusinessObject())) {
parentToApplicableFiltersMap.put(contentFilter.getParentId(), contentFilter);
break;
}
}
}
// Create command contributions
final List<IContributionItem> contributions = new ArrayList<>();
addContributionItems(contributions, null, parentToApplicableFiltersMap, window);
if (contributions.size() != 0) {
contributions.add(new Separator());
}
return contributions.toArray(new IContributionItem[contributions.size()]);
}
Aggregations