use of org.osate.ge.BusinessObjectContext in project AGREE by loonwerks.
the class ShowInSimulationVariablesViewHandler method getBusinessObjectContexts.
private static List<BusinessObjectContext> getBusinessObjectContexts(final ISelection selection) {
if (!(selection instanceof IStructuredSelection)) {
return Collections.emptyList();
}
final IStructuredSelection ss = (IStructuredSelection) selection;
final List<BusinessObjectContext> bocs = new ArrayList<>(ss.size());
for (final Object sel : ss.toList()) {
final BusinessObjectContext boc = Adapters.adapt(sel, BusinessObjectContext.class);
if (boc == null) {
return Collections.emptyList();
}
bocs.add(boc);
}
return bocs;
}
use of org.osate.ge.BusinessObjectContext in project AGREE by loonwerks.
the class ShowInSimulationVariablesViewHandler method calculateEnabled.
private boolean calculateEnabled(final Object evaluationContext) {
final SimulationUIService simulationUiService = EclipseContextFactory.getServiceContext(FrameworkUtil.getBundle(getClass()).getBundleContext()).get(SimulationUIService.class);
if (simulationUiService == null) {
return false;
}
final List<BusinessObjectContext> selectedBocs = getSelectedDiagramElementsFromContext(evaluationContext);
if (simulationUiService.getCurrentState().getEngineState() == null || selectedBocs.size() != 1) {
return false;
}
final Object bo = selectedBocs.get(0).getBusinessObject();
// Make the command available if there is only one business object selected and it is not the root System instance
if ((bo instanceof FeatureInstance || bo instanceof ComponentInstance) && bo != ((InstanceObject) bo).getSystemInstance()) {
final InstanceObject io = (InstanceObject) bo;
// Compare the references from the diagram and simulation system instances. Only show the command if they match
final URI diagramSystemInstanceUri = EcoreUtil.getURI(io.getSystemInstance());
final URI simulationSystemInstanceUri = EcoreUtil.getURI(simulationUiService.getCurrentState().getSimulationEngine().getSystemInstance());
return diagramSystemInstanceUri != null && diagramSystemInstanceUri.equals(simulationSystemInstanceUri);
}
return false;
}
use of org.osate.ge.BusinessObjectContext in project osate2 by osate.
the class CreateAadlConnectionPaletteCommand method getOwnerBoc.
private static BusinessObjectContext getOwnerBoc(final BusinessObjectContext srcBoc, final BusinessObjectContext dstBoc) {
// Search for an appropriate owner. To be appropriate the owner BOC must be a component implementation or a subcomponent which is reachable from both
// the source and destination BOC.
int subcomponentsChecked1 = 0;
BusinessObjectContext temp1 = srcBoc.getParent();
while (temp1 != null) {
final Object bo1 = temp1.getBusinessObject();
if (bo1 instanceof Subcomponent || bo1 instanceof ComponentImplementation) {
BusinessObjectContext temp2 = dstBoc.getParent();
int subcomponentsChecked2 = 0;
while (temp2 != null) {
final Object bo2 = temp2.getBusinessObject();
if (bo2 instanceof Subcomponent || bo2 instanceof ComponentImplementation) {
if (temp1 == temp2) {
return temp1;
}
if (bo2 instanceof Subcomponent) {
subcomponentsChecked2++;
// Stop checking at second subcomponent
if (subcomponentsChecked2 >= 2) {
break;
}
} else if (bo2 instanceof ComponentImplementation) {
// Stop checking at component implementations
break;
}
}
temp2 = temp2.getParent();
}
if (temp1.getBusinessObject() instanceof Subcomponent) {
subcomponentsChecked1++;
// Stop checking at second subcomponent
if (subcomponentsChecked1 >= 2) {
break;
}
} else if (bo1 instanceof ComponentImplementation) {
// Stop checking at component implementations
break;
}
}
temp1 = temp1.getParent();
}
return null;
}
use of org.osate.ge.BusinessObjectContext in project osate2 by osate.
the class CreateClassifierPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(EObject.class).map(targetBo -> {
if (!(targetBo instanceof AadlPackage || isValidBaseClassifier(targetBo))) {
return null;
}
final BusinessObjectContext pkgBoc = getPackageBoc(ctx.getTarget(), ctx.getQueryService());
if (pkgBoc == null) {
return null;
}
final AadlPackage pkg = (AadlPackage) pkgBoc.getBusinessObject();
final IProject project = ProjectUtil.getProjectForBoOrThrow(pkg);
final ResourceSet rs = targetBo.eResource().getResourceSet();
return Operation.createWithBuilder(builder -> {
builder.supply(() -> {
final ClassifierOperation args = buildCreateOperations(pkg, targetBo, project, rs);
if (args == null) {
return StepResult.abort();
}
return StepResult.forValue(args);
}).executeOperation(classifierOp -> Operation.createWithBuilder(innerBuilder -> {
final ClassifierOperationExecutor opExec = new ClassifierOperationExecutor(rs, project);
opExec.execute(innerBuilder, classifierOp, pkgBoc);
}));
});
});
}
use of org.osate.ge.BusinessObjectContext in project osate2 by osate.
the class CreateFlowSourceSinkSpecificationPaletteCommand method getOperation.
@Override
public Optional<Operation> getOperation(final GetTargetedOperationContext ctx) {
return ctx.getTarget().getBusinessObject(Feature.class).map(feature -> {
final DirectionType requiredDirection;
if (flowKind == FlowKind.SOURCE) {
requiredDirection = DirectionType.OUT;
} else if (flowKind == FlowKind.SINK) {
requiredDirection = DirectionType.IN;
} else {
return null;
}
final List<ComponentType> potentialOwners = FlowSpecificationCreationUtil.getPotentialOwnersByFeature(ctx.getTarget(), ctx.getQueryService());
if (potentialOwners.isEmpty() || !FlowSpecificationCreationUtil.isValidFlowEnd(feature, ctx.getTarget(), requiredDirection, ctx.getQueryService())) {
return null;
}
final BusinessObjectContext container = FlowSpecificationCreationUtil.getFlowSpecificationOwnerBoc(ctx.getTarget(), ctx.getQueryService());
if (container == null) {
return null;
}
return Operation.createWithBuilder(createOp -> {
AadlUiUtil.selectClassifier(createOp, potentialOwners).modifyPreviousResult(ct -> {
final FlowSpecification fs = ct.createOwnedFlowSpecification();
fs.setKind(flowKind);
fs.setName(FlowSpecificationCreationUtil.getNewFlowSpecificationName(ct));
// Create the appropriate flow end depending on the type being created
final FlowEnd flowEnd;
if (flowKind == FlowKind.SOURCE) {
flowEnd = fs.createOutEnd();
} else if (flowKind == FlowKind.SINK) {
flowEnd = fs.createInEnd();
} else {
throw new RuntimeException("Unexpected flow kind: " + flowKind);
}
flowEnd.setFeature(feature);
flowEnd.setContext(FlowSpecificationCreationUtil.getContext(ctx.getTarget(), ctx.getQueryService()));
// Clear the no flows flag
ct.setNoFlows(false);
return StepResultBuilder.create().showNewBusinessObject(container, fs).build();
});
});
});
}
Aggregations