use of org.osate.ge.internal.services.UiService in project osate2 by osate.
the class SetBindingTool method activated.
@Override
public void activated(final ActivatedEvent ctx) {
final BusinessObjectContext[] selectedBocs = ctx.getSelectedBocs().toArray(new BusinessObjectContext[ctx.getSelectedBocs().size()]);
final AgeDiagram diagram = ctx.getDiagram();
final AadlModificationService aadlModService = ctx.getAadlModificatonService();
final UiService uiService = ctx.getUiService();
try {
final BusinessObjectContext componentImplementationBoc = ToolUtil.findComponentImplementationBoc(selectedBocs[0]);
// Open Dialog
if (currentWindow == null && componentImplementationBoc != null) {
currentWindow = new SetBindingWindow(Display.getCurrent().getActiveShell(), componentImplementationBoc, selectedBocs);
if (currentWindow.open() == Window.OK) {
// Ensure the diagram is configured to show the specified binding property
if (!diagram.getConfiguration().getEnabledAadlPropertyNames().contains(currentWindow.getSelectedProperty().getQualifiedName().toLowerCase())) {
diagram.modify("Configure Diagram", m -> {
m.setDiagramConfiguration(new DiagramConfigurationBuilder(diagram.getConfiguration()).addAadlProperty(currentWindow.getSelectedProperty().getQualifiedName()).build());
});
}
// Create the property association
createPropertyAssociations(aadlModService);
}
currentWindow = null;
}
} finally {
uiService.deactivateActiveTool();
}
}
use of org.osate.ge.internal.services.UiService in project osate2 by osate.
the class EditFlowContributionItem method createControl.
@Override
protected Control createControl(final Composite parent) {
editFlowBtn = new Button(parent, SWT.PUSH);
editFlowBtn.setImage(editIcon.createImage());
editFlowBtn.setToolTipText("Edit...");
updateButton();
editFlowBtn.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(final SelectionEvent e) {
segmentNodes.clear();
final DiagramElement container = selectedHighlightableFlow.getDiagramElementContainer();
final NamedElement flowSegment = AgeAadlUtil.getRootRefinedElement(selectedHighlightableFlow.getFlowSegment());
final ComponentImplementation ci = FlowContributionItemUtil.getComponentImplementation(container.getBusinessObject());
// Set focus to editor for activating create flow tool
editor.setFocus();
editor.selectDiagramNodes(Collections.singletonList(editor.getDiagram()));
final UiService uiService = Adapters.adapt(editor, UiService.class);
// Create dialog and activate appropriate flow tool
if (flowSegment instanceof EndToEndFlow) {
final EndToEndFlow endToEndFlow = AgeEmfUtil.resolveOrNull(flowSegment, EndToEndFlow.class, ci.eResource().getResourceSet());
// Activate tool
uiService.activateTool(new CreateEndToEndFlowSpecificationTool(editor, container, endToEndFlow));
} else if (flowSegment instanceof FlowSpecification) {
final FlowSpecification fs = AgeEmfUtil.resolveOrNull(flowSegment, FlowSpecification.class, ci.eResource().getResourceSet());
getFlowImplementation(ci, fs).ifPresent(fi -> {
uiService.activateTool(new CreateFlowImplementationTool(editor, container, fi));
});
} else {
throw new RuntimeException("Unsupported flow type.");
}
}
private Optional<FlowImplementation> getFlowImplementation(final ComponentImplementation ci, final FlowSpecification flowSpec) {
final List<FlowImplementation> flowImpls = ci.getAllFlowImplementations().stream().filter(fi -> fi.getSpecification() == flowSpec).collect(Collectors.toList());
if (flowImpls.size() == 1) {
return Optional.of(flowImpls.get(0));
} else {
final FlowImplementationSelectionDialog dlg = new FlowImplementationSelectionDialog(Display.getCurrent().getActiveShell(), flowImpls, "Select", "Choose the flow implementation to edit.");
if (dlg.open() == Window.OK) {
return Optional.ofNullable(dlg.getSelectedFlowImplementation());
}
}
return Optional.empty();
}
});
return editFlowBtn;
}
use of org.osate.ge.internal.services.UiService 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();
}
}
use of org.osate.ge.internal.services.UiService 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.internal.services.UiService in project osate2 by osate.
the class AgeHandlerUtil method activateTool.
/**
* Activates a tool for the active editor
* @param event the event used to determine the active editor
* @param tool the tool to activate
*/
public static void activateTool(final ExecutionEvent event, final Tool tool) {
final IEditorPart editorPart = HandlerUtil.getActiveEditor(event);
final UiService uiService = Adapters.adapt(editorPart, UiService.class);
if (uiService == null) {
throw new RuntimeException("Unable to get UiService");
}
uiService.activateTool(tool);
}
Aggregations