Search in sources :

Example 16 with AgeDiagram

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;
}
Also used : DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Point(org.osate.ge.graphics.Point) Point(org.osate.ge.graphics.Point)

Example 17 with AgeDiagram

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;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) IEditorPart(org.eclipse.ui.IEditorPart)

Example 18 with AgeDiagram

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;
}
Also used : InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) IEditorPart(org.eclipse.ui.IEditorPart)

Example 19 with AgeDiagram

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);
}
Also used : Element(org.osate.aadl2.Element) BusinessObjectHandler(org.osate.ge.businessobjecthandling.BusinessObjectHandler) RenameUtil(org.osate.ge.internal.ui.RenameUtil) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) DiagramElementLayoutUtil(org.osate.ge.internal.diagram.runtime.layout.DiagramElementLayoutUtil) EmbeddedBusinessObject(org.osate.ge.internal.model.EmbeddedBusinessObject) ClipboardService(org.osate.ge.internal.services.ClipboardService) ClassifierCreationHelper(org.osate.ge.aadl2.internal.util.classifiers.ClassifierCreationHelper) Classifier(org.osate.aadl2.Classifier) ComponentType(org.osate.aadl2.ComponentType) DiagramNodePredicates(org.osate.ge.internal.diagram.runtime.DiagramNodePredicates) RelativeBusinessObjectReference(org.osate.ge.RelativeBusinessObjectReference) Bundle(org.osgi.framework.Bundle) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) Collection(java.util.Collection) PackageSection(org.osate.aadl2.PackageSection) EObject(org.eclipse.emf.ecore.EObject) AadlPackage(org.osate.aadl2.AadlPackage) AadlImportsUtil(org.osate.ge.aadl2.AadlImportsUtil) Point(org.osate.ge.graphics.Point) DiagramElementUtil(org.osate.ge.internal.util.DiagramElementUtil) Objects(java.util.Objects) List(java.util.List) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) EclipseContextFactory(org.eclipse.e4.core.contexts.EclipseContextFactory) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) Feature(org.osate.aadl2.Feature) ComponentImplementation(org.osate.aadl2.ComponentImplementation) DiagramModification(org.osate.ge.internal.diagram.runtime.DiagramModification) ArrayList(java.util.ArrayList) InternalDiagramEditor(org.osate.ge.internal.ui.editor.InternalDiagramEditor) EClass(org.eclipse.emf.ecore.EClass) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext) Predicates(com.google.common.base.Predicates) GetNameContext(org.osate.ge.businessobjecthandling.GetNameContext) SimpleModifier(org.osate.ge.internal.services.AadlModificationService.SimpleModifier) Subcomponent(org.osate.aadl2.Subcomponent) XtextResource(org.eclipse.xtext.resource.XtextResource) AadlNameUtil(org.osate.ge.aadl2.internal.util.AadlNameUtil) EcoreUtil(org.eclipse.emf.ecore.util.EcoreUtil) Action(org.eclipse.jface.action.Action) CanRenameContext(org.osate.ge.businessobjecthandling.CanRenameContext) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) AgeHandlerUtil(org.osate.ge.internal.ui.handlers.AgeHandlerUtil) ComponentTypeRename(org.osate.aadl2.ComponentTypeRename) ActionFactory(org.eclipse.ui.actions.ActionFactory) NamedElement(org.osate.aadl2.NamedElement) Collections(java.util.Collections) FrameworkUtil(org.osgi.framework.FrameworkUtil) DiagramNode(org.osate.ge.internal.diagram.runtime.DiagramNode) Bundle(org.osgi.framework.Bundle) ArrayList(java.util.ArrayList) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AadlModificationService(org.osate.ge.internal.services.AadlModificationService) ReferenceBuilderService(org.osate.ge.services.ReferenceBuilderService) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) EObject(org.eclipse.emf.ecore.EObject) IEclipseContext(org.eclipse.e4.core.contexts.IEclipseContext)

Example 20 with AgeDiagram

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()]);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) Bundle(org.osgi.framework.Bundle) ExtensionRegistryService(org.osate.ge.internal.services.ExtensionRegistryService) IContributionItem(org.eclipse.jface.action.IContributionItem) ArrayList(java.util.ArrayList) IEditorPart(org.eclipse.ui.IEditorPart) ContentFilter(org.osate.ge.ContentFilter) DiagramElement(org.osate.ge.internal.diagram.runtime.DiagramElement) AgeDiagram(org.osate.ge.internal.diagram.runtime.AgeDiagram) Separator(org.eclipse.jface.action.Separator)

Aggregations

AgeDiagram (org.osate.ge.internal.diagram.runtime.AgeDiagram)46 DiagramElement (org.osate.ge.internal.diagram.runtime.DiagramElement)35 InternalDiagramEditor (org.osate.ge.internal.ui.editor.InternalDiagramEditor)20 IEditorPart (org.eclipse.ui.IEditorPart)18 List (java.util.List)16 Objects (java.util.Objects)16 Collectors (java.util.stream.Collectors)12 BusinessObjectContext (org.osate.ge.BusinessObjectContext)12 ExtensionRegistryService (org.osate.ge.internal.services.ExtensionRegistryService)11 DiagramNode (org.osate.ge.internal.diagram.runtime.DiagramNode)10 Collections (java.util.Collections)9 Adapters (org.eclipse.core.runtime.Adapters)9 DiagramUpdater (org.osate.ge.internal.diagram.runtime.updating.DiagramUpdater)9 Collection (java.util.Collection)8 LinkedList (java.util.LinkedList)8 Optional (java.util.Optional)8 Stream (java.util.stream.Stream)8 Point (org.osate.ge.graphics.Point)8 ArrayList (java.util.ArrayList)7 UiUtil (org.osate.ge.internal.ui.util.UiUtil)7