use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.
the class GefAgeDiagram method updateConnectionAnchors.
private void updateConnectionAnchors(final DiagramElement de, final BaseConnectionNode node) {
if (node instanceof FlowIndicatorNode) {
final FlowIndicatorNode fi = (FlowIndicatorNode) node;
final IAnchor anchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), null);
if (anchor != null) {
fi.setStartAnchor(anchor);
}
} else if (node instanceof ConnectionNode) {
final ConnectionNode cn = (ConnectionNode) node;
final IAnchor startAnchor = GefAgeDiagramUtil.getAnchor(this, de.getStartElement(), de.getEndElement());
final IAnchor endAnchor = GefAgeDiagramUtil.getAnchor(this, de.getEndElement(), de.getStartElement());
if (startAnchor != null && endAnchor != null) {
cn.setStartAnchor(startAnchor);
cn.setEndAnchor(endAnchor);
}
} else {
throw new AgeGefRuntimeException("Unexpected node: " + node);
}
}
use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.
the class StyleToFx method createStyle.
/**
* Creates an {@link FxStyle} instance from a {@link Style} instance.
* @param style the style for which to create an {@link FxStyle}.
* @return the Java FX implementation specific style.
*/
public FxStyle createStyle(final Style style) {
if (!style.isComplete()) {
throw new AgeGefRuntimeException("Specified style must be complete");
}
final IPath imagePath = style.getShowAsImage() ? style.getImagePath() : null;
// Convert from pixels to points
final double fontSizeInPoints = style.getFontSize() * 96.0 / 72.0;
return new FxStyle.Builder().backgroundColor(convert(style.getBackgroundColor())).outlineColor(convert(style.getOutlineColor())).fontColor(convert(style.getFontColor())).font(Font.font("Arial", FontWeight.NORMAL, fontSizeInPoints)).strokeDashArray(getStrokeDashArray(style.getLineStyle())).lineWidth(style.getLineWidth()).horizontalLabelPosition(convert(style.getHorizontalLabelPosition())).verticalLabelPosition(convert(style.getVerticalLabelPosition())).primaryLabelsVisible(style.getPrimaryLabelVisible()).image(imagePath == null ? null : imageManager.getImageReference(imagePath.toFile().toPath())).build();
}
use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.
the class AgeEditor method init.
@Override
public void init(final IEditorSite site, final IEditorInput input) throws PartInitException {
setInput(input);
setSite(site);
// Register a resource change listener to handle moving and deleting the resource.
ResourcesPlugin.getWorkspace().addResourceChangeListener(resourceChangeListener);
site.getWorkbenchWindow().getSelectionService().addPostSelectionListener(toolPostSelectionListener);
site.setSelectionProvider(selectionProvider);
// Activate Context
final IContextService contextService = site.getService(IContextService.class);
if (contextService != null) {
contextService.activateContext(CONTEXT_ID);
}
// Register actions for retargatable actions
new UndoRedoActionGroup(site, DefaultActionService.CONTEXT, true).fillActionBars(site.getActionBars());
registerAction(new CopyAction());
registerAction(new PasteAction(this));
registerAction(new SelectAllAction(this));
// Load the diagram
final org.osate.ge.diagram.Diagram mmDiagram = DiagramSerialization.readMetaModelDiagram(URI.createPlatformResourceURI(diagramFile.getFullPath().toString(), true));
diagram = DiagramSerialization.createAgeDiagram(project, mmDiagram, extRegistry);
// Display warning if the diagram is stored with a newer version of the diagram file format.
if (mmDiagram.getFormatVersion() > DiagramSerialization.FORMAT_VERSION) {
MessageDialog.openWarning(Display.getCurrent().getActiveShell(), "Diagram Created with Newer Version of OSATE", "The diagram '" + diagramFile.getName() + "' was created with a newer version of the OSATE. The diagram may not be correctly displayed. Saving the diagram with this version of OSATE may result in the loss of diagram information.");
}
// Ensure the project is built. This prevents being unable to find the context due to the Xtext index not having completed.
try {
project.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
} catch (CoreException e) {
throw new AgeGefRuntimeException(e);
}
// Update the diagram to finish initializing the diagram's fields
actionService.execute("Update on Load", ExecutionMode.HIDE, () -> {
diagram.modify("Update Diagram", m -> {
// Check the diagram's context
final DiagramContextChecker contextChecker = new DiagramContextChecker(project, projectReferenceService, systemInstanceLoader);
final boolean workbenchIsVisible = isWorkbenchVisible();
final DiagramContextChecker.Result result = contextChecker.checkContextFullBuild(diagram, workbenchIsVisible);
if (!result.isContextValid()) {
// we only prompts to relink if the workbench is visible.
if (!workbenchIsVisible) {
closeEditor();
}
final String refContextLabel = projectReferenceService.getLabel(diagram.getConfiguration().getContextBoReference());
throw new AgeGefRuntimeException("Unable to resolve context: " + refContextLabel);
}
diagramUpdater.updateDiagram(diagram);
});
return null;
});
this.modelChangeNotifier.addChangeListener(modelChangeListener);
// Set the initial selection to the diagram
selectionProvider.setSelection(new StructuredSelection(diagram));
site.getWorkbenchWindow().getPartService().addPartListener(partListener);
diagram.addModificationListener(diagramModificationListener);
}
use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.
the class MoveConnectionPointInteraction method onMouseReleased.
@Override
protected Interaction.InteractionState onMouseReleased(final MouseEvent e) {
if (e.getButton() != MouseButton.PRIMARY) {
return super.onMouseReleased(e);
}
final BaseConnectionNode connectionNode = activeHandle.getSceneNode();
try {
final Transform sceneToDiagramTransform = editor.getGefDiagram().getSceneNode().getLocalToSceneTransform().createInverse();
final Transform connectionToDiagramTransform = sceneToDiagramTransform.createConcatenation(connectionNode.getLocalToSceneTransform());
editor.getDiagram().modify("Update Control Point", m -> {
final DiagramElement diagramElementToModify = editor.getGefDiagram().getDiagramElement(connectionNode);
if (diagramElementToModify == null) {
throw new AgeGefRuntimeException("Unable to find diagram element");
}
m.setBendpoints(diagramElementToModify, connectionNode.getInnerConnection().getControlPoints().stream().map(p -> GefAgeDiagramUtil.toAgePoint(connectionToDiagramTransform.transform(p.x, p.y))).collect(Collectors.toList()));
if (connectionNode instanceof FlowIndicatorNode) {
m.setPosition(diagramElementToModify, GefAgeDiagramUtil.toAgePoint(PreferredPosition.get(connectionNode)));
}
});
// The scene will be updated based on our modification. No need to update the scene in close().
updateSceneGraphOnComplete = false;
} catch (NonInvertibleTransformException ex) {
throw new AgeGefRuntimeException("Unable to create diagram scene to local transform", ex);
}
return InteractionState.COMPLETE;
}
use of org.osate.ge.gef.AgeGefRuntimeException in project osate2 by osate.
the class GefAgeDiagram method ensureSceneNodeExists.
/**
* Ensures that a scene node exists for the specified GEF diagram element.
* Creates or recreates scene nodes and adds to the scene graph as necessary. Updates the specified GEF diagram element.
* @param gefDiagramElement the GEF diagram element for which to ensure that the scene node exists.
* @param parentDiagramElementSceneNode the scene node for the parent of the GEF diagram element. This is specified instead of using
* the value contained in the GEF diagram element because it may not be up to date.
* @return the scene node for the diagram element. This specified GEF diagram element will be updated to hold this value.
*/
private Node ensureSceneNodeExists(GefDiagramElement gefDiagramElement, final Node parentDiagramElementSceneNode) {
Objects.requireNonNull(parentDiagramElementSceneNode, "parentDiagramElementScenenNode must not be null");
final Graphic graphic = Objects.requireNonNull(gefDiagramElement.diagramElement.getGraphic(), "graphic must not be null");
final DiagramElement childDiagramElement = gefDiagramElement.diagramElement;
//
// The following final variables determine the operations that needs to be performed by the remainder of the function.
// They are set by comparing the previous state with the current state of the diagram element.
//
final boolean docked = childDiagramElement.getDockArea() != null;
final boolean parentIsConnection = parentDiagramElementSceneNode instanceof BaseConnectionNode;
final boolean create = !Objects.equals(graphic, gefDiagramElement.sourceGraphic) || docked != gefDiagramElement.sceneNode instanceof DockedShape || parentIsConnection != gefDiagramElement.parentDiagramNodeSceneNode instanceof BaseConnectionNode;
final boolean addToScene = create || gefDiagramElement.parentDiagramNodeSceneNode != parentDiagramElementSceneNode;
final boolean removeFromScene = addToScene && gefDiagramElement.sceneNode != null;
// Update other fields
gefDiagramElement.sourceGraphic = graphic;
// Remove the node for the scene graph
if (removeFromScene) {
removeNode(gefDiagramElement.sceneNode);
}
//
if (create) {
// Remove mapping to old scene node
if (gefDiagramElement.sceneNode != null) {
sceneNodeToGefDiagramElementMap.remove(gefDiagramElement.sceneNode);
}
// Create the new node. Create a graphic and then a wrapper as appropriate
final Node graphicNode = GraphicToFx.createNode(graphic);
if (graphicNode instanceof BaseConnectionNode) {
final BaseConnectionNode newConnectionNode = (BaseConnectionNode) graphicNode;
gefDiagramElement.sceneNode = graphicNode;
// Create the primary label node
final LabelNode primaryLabel = new LabelNode();
newConnectionNode.getPrimaryLabels().add(primaryLabel);
gefDiagramElement.primaryLabel = primaryLabel;
} else if (graphicNode instanceof LabelNode) {
gefDiagramElement.sceneNode = graphicNode;
} else if (parentIsConnection) {
// NOTE: This should only occur for fixed sized graphics
// Rotate midpoint decorations 180.0 degrees because our connection not expects midpoint decorations to be oriented as if
// the connection was left to right and that is not how graphics are specified in the graphical editor.
final Group rotationWrapper = new Group();
rotationWrapper.getChildren().add(graphicNode);
rotationWrapper.setRotate(180.0);
gefDiagramElement.sceneNode = rotationWrapper;
} else {
if (docked) {
final DockedShape newDockedShape = new DockedShape();
newDockedShape.setGraphic(graphicNode);
gefDiagramElement.sceneNode = newDockedShape;
// Create the primary label node
final LabelNode primaryLabel = new LabelNode();
newDockedShape.getPrimaryLabels().add(primaryLabel);
gefDiagramElement.primaryLabel = primaryLabel;
// Create annotation node
final LabelNode annotationLabel = new LabelNode();
newDockedShape.getSecondaryLabels().add(annotationLabel);
gefDiagramElement.annotationLabel = annotationLabel;
} else {
final ContainerShape newContainerShape = new ContainerShape();
newContainerShape.setGraphic(graphicNode);
gefDiagramElement.sceneNode = newContainerShape;
// Create the primary label node
final LabelNode primaryLabel = new LabelNode();
newContainerShape.getPrimaryLabels().add(primaryLabel);
gefDiagramElement.primaryLabel = primaryLabel;
}
}
// Add mapping to scene node
if (gefDiagramElement.sceneNode != null) {
sceneNodeToGefDiagramElementMap.put(gefDiagramElement.sceneNode, gefDiagramElement);
}
StyleRoot.set(gefDiagramElement.sceneNode, true);
}
//
if (addToScene) {
if (gefDiagramElement.sceneNode instanceof BaseConnectionNode) {
diagramNode.getChildren().add(gefDiagramElement.sceneNode);
// Flow indicators are positioned relative to the scene node of the parent diagram element
if (gefDiagramElement.sceneNode instanceof FlowIndicatorNode) {
if (parentDiagramElementSceneNode instanceof ContainerShape) {
((FlowIndicatorNode) gefDiagramElement.sceneNode).setPositioningReference(parentDiagramElementSceneNode);
} else {
throw new AgeGefRuntimeException("Unexpected parent diagram element scene node for flow indicator: " + parentDiagramElementSceneNode);
}
}
} else if (gefDiagramElement.sceneNode instanceof LabelNode) {
// Add label to parent
if (parentDiagramElementSceneNode instanceof ContainerShape) {
((ContainerShape) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
} else if (parentDiagramElementSceneNode instanceof DockedShape) {
((DockedShape) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
} else if (parentDiagramElementSceneNode instanceof BaseConnectionNode) {
((BaseConnectionNode) parentDiagramElementSceneNode).getSecondaryLabels().add(gefDiagramElement.sceneNode);
} else {
throw new AgeGefRuntimeException("Unexpected parent node for label: " + parentDiagramElementSceneNode);
}
} else if (parentIsConnection) {
((BaseConnectionNode) parentDiagramElementSceneNode).getMidpointDecorations().add(gefDiagramElement.sceneNode);
} else {
final DockArea dockArea = childDiagramElement.getDockArea();
if (gefDiagramElement.sceneNode instanceof DockedShape) {
final DockedShape dockedShape = (DockedShape) gefDiagramElement.sceneNode;
// Add the docked shape to the appropriate list
if (parentDiagramElementSceneNode instanceof ContainerShape) {
final ContainerShape containerShapeParent = (ContainerShape) parentDiagramElementSceneNode;
containerShapeParent.addOrUpdateDockedChild(dockedShape, GefAgeDiagramUtil.toDockSide(dockArea));
} else if (parentDiagramElementSceneNode instanceof DockedShape) {
final DockedShape dockedShapeParent = (DockedShape) parentDiagramElementSceneNode;
dockedShapeParent.getNestedChildren().add(dockedShape);
} else {
throw new AgeGefRuntimeException("Unexpected parent for docked shape: " + parentDiagramElementSceneNode);
}
} else {
if (parentDiagramElementSceneNode instanceof ContainerShape) {
final ContainerShape containerShapeParent = (ContainerShape) parentDiagramElementSceneNode;
containerShapeParent.getFreeChildren().add(gefDiagramElement.sceneNode);
} else if (parentDiagramElementSceneNode instanceof Group) {
((Group) parentDiagramElementSceneNode).getChildren().add(gefDiagramElement.sceneNode);
} else {
throw new AgeGefRuntimeException("Unexpected parent node for container shape: " + parentDiagramElementSceneNode);
}
}
}
gefDiagramElement.parentDiagramNodeSceneNode = parentDiagramElementSceneNode;
}
return gefDiagramElement.sceneNode;
}
Aggregations