use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class CreateEndToEndFlowSpecificationTool method setColor.
private void setColor(final Object o, final Color color) {
if (o instanceof DiagramElement) {
final DiagramElement de = (DiagramElement) o;
coloring.setForeground(de, color);
} else if (o instanceof SegmentData) {
final SegmentData segmentData = (SegmentData) o;
final BusinessObjectContext boc = segmentData.getBoc();
// Do not remove color from duplicate segments
if (color == null) {
for (final SegmentData sd : segmentSelections) {
if (sd.getBoc() == boc) {
return;
}
}
}
setColor(boc, color);
segmentData.getOwnedSegments().forEach(de -> setColor(de, color));
}
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class CreateFlowImplementationTool 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 Flow Implementation", errors).open());
} else {
coloring = coloringService.adjustColors();
// Create and update based on current selection
createFlowImplDlg.create();
if (segmentSelections.isEmpty() && modeFeatureSelections.isEmpty()) {
update(Collections.singletonList(selectedBoc), true);
} else {
final Iterator<SegmentData> segmentIt = segmentSelections.iterator();
if (segmentIt.hasNext()) {
// Set color for flow spec
setColor(segmentIt.next().getBoc(), Color.ORANGE.darker());
// Set color for flow segments
while (segmentIt.hasNext()) {
setColor(segmentIt.next().getBoc(), Color.MAGENTA.darker());
}
}
// Set color for in mode and mode transitions
for (Iterator<BusinessObjectContext> modeFeatureIt = modeFeatureSelections.iterator(); modeFeatureIt.hasNext(); setColor(modeFeatureIt.next(), Color.MAGENTA.brighter())) {
}
}
if (createFlowImplDlg.open() == Window.OK && createFlowImplDlg != null) {
final BusinessObjectContext ownerBoc = createFlowImplDlg.getOwnerBoc().orElse(null);
// Create a new flow impl based on selections
final FlowImplementation flowImpl = createFlowImplDlg.createFlow(ownerBoc);
createFlowImplDlg.getFlowComponentImplementation(ownerBoc).ifPresent(ownerCi -> {
// Modifications to perform
final List<AadlModificationService.Modification<? extends NamedElement, ? extends NamedElement>> modifications = new ArrayList<>();
if (createFlowImplDlg.flowImplToEdit != null) {
// Editing existing flow impl
final FlowImplementation flowImplToEdit = createFlowImplDlg.flowImplToEdit;
// Copy owned property associations from old flow impl to new flow impl and remove old flow impl
modifications.add(Modification.create(flowImplToEdit, fi -> {
flowImpl.getOwnedPropertyAssociations().addAll(EcoreUtil.copyAll(fi.getOwnedPropertyAssociations()));
EcoreUtil.remove(fi);
}));
}
// Add new flow impl
modifications.add(Modification.create(ownerCi, ci -> {
ci.getOwnedFlowImplementations().add(flowImpl);
ci.setNoFlows(false);
}));
// Perform modifications
aadlModService.modify(modifications);
});
}
}
});
} finally {
uiService.deactivateActiveTool();
}
}
use of org.osate.ge.aadl2.ui.internal.tools.FlowDialogUtil.SegmentData in project osate2 by osate.
the class CreateFlowImplementationTool method setColor.
private void setColor(final Object o, final Color color) {
if (o instanceof DiagramElement) {
final DiagramElement de = (DiagramElement) o;
coloring.setForeground(de, color);
} else if (o instanceof SegmentData) {
final SegmentData segmentData = (SegmentData) o;
final BusinessObjectContext boc = segmentData.getBoc();
// Do not remove color from duplicate segments
if (color == null) {
final Iterator<SegmentData> it = segmentSelections.iterator();
if (it.hasNext()) {
// Check if boc matches first segment to see if boc
// should be orange to show the implementations flow specification
final boolean isImplsFlowSpec = it.next().getBoc() == boc;
// Keep color if it matches a segment
while (it.hasNext()) {
if (it.next().getBoc() == boc) {
return;
}
}
if (isImplsFlowSpec) {
// Set orange to show flow specification
setColor(boc, Color.ORANGE.darker());
return;
}
}
}
setColor(boc, color);
}
}
Aggregations