use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class CreateEndToEndFlowSpecificationTool method update.
/**
* Update the diagram and tool dialog
* @param selectedBocs - the selected bocs
*/
private void update(final List<BusinessObjectContext> selectedBocs) {
if (createFlowDialog != null) {
if (createFlowDialog.getShell() != null && !createFlowDialog.getShell().isDisposed() && createFlowDialog.elementSelectionDlg == null) {
// If the selection is qualified, add it
if (selectedBocs.size() > 1) {
createFlowDialog.setErrorMessage("Multiple elements selected. Select a single element. " + " " + getDialogMessage());
} else if (selectedBocs.size() == 1) {
// Get the selected boc
final BusinessObjectContext selectedBoc = (BusinessObjectContext) selectedBocs.get(0);
if (!modeFeatureSelections.contains(selectedBoc) && createFlowDialog.addSelectedElement(selectedBoc)) {
// Insert flow segments before first mode feature
final Color color;
if (selectedBoc.getBusinessObject() instanceof ModeFeature) {
modeFeatureSelections.add(selectedBoc);
color = Color.MAGENTA.brighter();
} else {
segmentSelections.add(new SegmentData(selectedBoc, new ArrayList<>()));
if (segmentSelections.size() == 1) {
// Set default name on first selection if one does not exist
createFlowDialog.getOwnerComponentImplementation().ifPresent(ci -> {
createFlowDialog.setTitle("Creating End To End Flow in: " + ci.getQualifiedName());
if (createFlowDialog.endToEndFlowName.isEmpty()) {
createFlowDialog.setEndToEndFlowName(ci);
}
});
color = Color.ORANGE.darker();
} else {
color = Color.MAGENTA.darker();
}
}
setColor(selectedBoc, color);
}
createFlowDialog.updateSegments();
final boolean isValid = createFlowDialog.isEndToEndFlowValid(createEndToEndFlow());
createFlowDialog.updateWidgets(isValid);
createFlowDialog.setErrorMessage(null);
createFlowDialog.setMessage(getDialogMessage());
} else {
createFlowDialog.updateSegments();
}
} else if (createFlowDialog.elementSelectionDlg != null && createFlowDialog.elementSelectionDlg.getShell() != null && !createFlowDialog.elementSelectionDlg.getShell().isDisposed() && createFlowDialog.elementSelectionDlg.getShell().isVisible()) {
final CreateFlowsToolsDialog.ElementSelectionDialog elementSelectionDlg = createFlowDialog.elementSelectionDlg;
// Selecting an element for editing end to end flows
if (selectedBocs.size() > 1) {
elementSelectionDlg.setErrorMessage("Multiple elements are selected.\n " + elementSelectionDlg.getMessage());
elementSelectionDlg.setSelection(null);
} else if (selectedBocs.size() == 1) {
elementSelectionDlg.setErrorMessage(null);
final BusinessObjectContext selectedBoc = selectedBocs.get(0);
elementSelectionDlg.setSelection(selectedBoc);
}
}
}
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class FlowToolUtil method createSegmentData.
/**
* Creates a {@link SegmentData} instance for a flow end. The referenced {@link BusinessObjectContext} will be a {@link DiagramElement} if the flow end is in the diagram.
* Otherwise, it will be an instance of a private implementation.
* @return the new {@link SegmentData} instance. Will not return null.
*/
public static SegmentData createSegmentData(final ReferenceBuilderService referenceBuilder, final DiagramElement container, final FlowEnd flowEnd) {
final DiagramElement tmp;
if (flowEnd.getContext() == null) {
tmp = container;
} else {
tmp = container.getChildByRelativeReference(referenceBuilder.getRelativeReference(flowEnd.getContext()));
if (tmp == null) {
return new SegmentData(new ChildlessBusinessObjectContext(new ChildlessBusinessObjectContext(container, flowEnd.getContext()), flowEnd.getFeature()));
}
}
final DiagramElement flowEndDiagramElement = tmp.getChildByRelativeReference(referenceBuilder.getRelativeReference(flowEnd.getFeature()));
if (flowEndDiagramElement == null) {
return new SegmentData(new ChildlessBusinessObjectContext(tmp, flowEnd.getFeature()));
}
return new SegmentData(flowEndDiagramElement);
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class FlowToolUtil method createSegmentData.
/**
* Creates a {@link SegmentData} instance for an end to end flow segment. The referenced {@link BusinessObjectContext} will be a {@link DiagramElement} if the flow segment is in the diagram.
* Otherwise, it will be an instance of a private implementation.
* @return the new {@link SegmentData} instance. Will not return null.
*/
public static SegmentData createSegmentData(final ReferenceBuilderService referenceBuilder, final DiagramElement container, final EndToEndFlowSegment seg) {
final DiagramElement tmp;
if (seg.getContext() == null) {
tmp = container;
} else {
tmp = container.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getContext()));
if (tmp == null) {
return new SegmentData(new ChildlessBusinessObjectContext(new ChildlessBusinessObjectContext(container, seg.getContext()), seg.getFlowElement()));
}
}
if (seg.getFlowElement() instanceof EndToEndFlow) {
final List<DiagramElement> highlightableSegments = new ArrayList<>();
findSegmentDiagramElements((EndToEndFlow) AgeAadlUtil.getRootRefinedElement(seg.getFlowElement()), tmp, highlightableSegments);
return new SegmentData(new ChildlessBusinessObjectContext(tmp, seg.getFlowElement()), highlightableSegments);
} else {
final DiagramElement flowElementDiagramElement = tmp.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getFlowElement()));
if (flowElementDiagramElement == null) {
return new SegmentData(new ChildlessBusinessObjectContext(tmp, seg.getFlowElement()));
}
return new SegmentData(flowElementDiagramElement);
}
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class FlowToolUtil method createSegmentData.
/**
* Creates a {@link SegmentData} instance for a flow segment. The referenced {@link BusinessObjectContext} will be a {@link DiagramElement} if the flow segment is in the diagram.
* Otherwise, it will be an instance of a private implementation.
* @return the new {@link SegmentData} instance. Will not return null.
*/
public static SegmentData createSegmentData(final ReferenceBuilderService referenceBuilder, final DiagramElement container, final FlowSegment seg) {
final DiagramElement tmp;
if (seg.getContext() == null) {
tmp = container;
} else {
tmp = container.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getContext()));
if (tmp == null) {
return new SegmentData(new ChildlessBusinessObjectContext(new ChildlessBusinessObjectContext(container, seg.getContext()), seg.getFlowElement()));
}
}
final DiagramElement flowElementDiagramElement = tmp.getChildByRelativeReference(referenceBuilder.getRelativeReference(seg.getFlowElement()));
if (flowElementDiagramElement == null) {
return new SegmentData(new ChildlessBusinessObjectContext(tmp, seg.getFlowElement()));
}
return new SegmentData(flowElementDiagramElement);
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class CreateEndToEndFlowSpecificationTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final UiService uiService = ctx.getUiService();
try {
ctx.getSelectedBoc().ifPresent(selectedBoc -> {
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final ColoringService coloringService = ctx.getColoringService();
// Check for existing errors and warnings
final Set<Diagnostic> diagnostics = ToolUtil.getAllReferencedPackageDiagnostics(selectedBoc);
// Do not allow tool activation if there are errors in the models
final Set<Diagnostic> errors = FlowDialogUtil.getErrors(diagnostics);
if (!errors.isEmpty()) {
Display.getDefault().asyncExec(() -> new FlowDialogUtil.ErrorDialog("The Create End-To-End", errors).open());
} else {
// Create a coloring object that will allow adjustment of pictogram
coloring = coloringService.adjustColors();
// Create and update based on current selection
createFlowDialog.create();
if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
update(Collections.singletonList(selectedBoc));
} else {
final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
while (segmentIt.hasNext()) {
final SegmentData segmentData = segmentIt.next();
setColor(segmentData, Color.MAGENTA.darker());
}
for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
}
update();
}
if (createFlowDialog.open() == Window.OK && createFlowDialog != null) {
createFlowDialog.getFlow().ifPresent(endToEndFlow -> {
if (createFlowDialog.eteFlowToEdit != null) {
// Editing end to end flow
final EndToEndFlow endToEndFlowToEdit = (EndToEndFlow) createFlowDialog.eteFlowToEdit;
aadlModService.modify(endToEndFlowToEdit, eTEFlowToEdit -> {
eTEFlowToEdit.getAllFlowSegments().clear();
eTEFlowToEdit.getAllFlowSegments().addAll(endToEndFlow.getAllFlowSegments());
eTEFlowToEdit.setName(endToEndFlow.getName());
eTEFlowToEdit.getInModeOrTransitions().clear();
eTEFlowToEdit.getInModeOrTransitions().addAll(endToEndFlow.getInModeOrTransitions());
});
} else {
// Creating end to end flow
createFlowDialog.getOwnerComponentImplementation().ifPresent(ownerCi -> {
aadlModService.modify(ownerCi, ci -> {
ci.getOwnedEndToEndFlows().add(endToEndFlow);
ci.setNoFlows(false);
});
});
}
});
}
}
});
} finally {
uiService.deactivateActiveTool();
}
}
Aggregations