use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.
the class AbstractSelectedColumnCommand method setInstanceHeader.
/**
* Sets the instance header for a <code>ScenarioSimulationContext</code>.
* @param context It contains the <b>Context</b> inside which the commands will be executed
* @param selectedColumn The selected <code>ScenarioGridColumn</code> where the command was launched
*/
protected void setInstanceHeader(ScenarioSimulationContext context, ScenarioGridColumn selectedColumn, String alias, String fullClassName) {
int columnIndex = context.getAbstractScesimGridModelByGridWidget(gridWidget).getColumns().indexOf(selectedColumn);
final FactIdentifier factIdentifier = setEditableHeadersAndGetFactIdentifier(context, selectedColumn, alias, fullClassName);
setInstanceHeaderMetaData(selectedColumn, alias, factIdentifier);
final ScenarioHeaderMetaData propertyHeaderMetaData = selectedColumn.getPropertyHeaderMetaData();
setPropertyMetaData(propertyHeaderMetaData, getPropertyPlaceHolder(columnIndex), false, selectedColumn, ScenarioSimulationUtils.getPlaceHolder(selectedColumn.isInstanceAssigned(), selectedColumn.isPropertyAssigned(), factMappingValueType, fullClassName));
context.getAbstractScesimGridModelByGridWidget(gridWidget).updateColumnInstance(columnIndex, selectedColumn);
if (context.getScenarioSimulationEditorPresenter() != null) {
context.getScenarioSimulationEditorPresenter().reloadTestTools(false);
}
}
use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.
the class AbstractScesimGridModel method updateHeader.
public void updateHeader(int columnIndex, int headerRowIndex, String headerCellValue) {
final ScenarioHeaderMetaData editedMetadata = (ScenarioHeaderMetaData) getColumns().get(columnIndex).getHeaderMetaData().get(headerRowIndex);
// do not update if old and new value are the same
if (Objects.equals(editedMetadata.getTitle(), headerCellValue)) {
return;
}
ScesimModelDescriptor simulationDescriptor = abstractScesimModel.getScesimModelDescriptor();
FactMapping factMappingToEdit = simulationDescriptor.getFactMappingByIndex(columnIndex);
ScenarioHeaderMetaData.MetadataType metadataType = editedMetadata.getMetadataType();
IntStream.range(0, getColumnCount()).forEach(index -> updateFactMapping(simulationDescriptor, factMappingToEdit, index, headerCellValue, metadataType));
if (editedMetadata.getMetadataType().equals(ScenarioHeaderMetaData.MetadataType.INSTANCE)) {
eventBus.fireEvent(new ReloadTestToolsEvent(false));
}
}
use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.
the class ScenarioSimulationGridWidgetMouseEventHandler method handleHeaderCell.
@Override
public boolean handleHeaderCell(final GridWidget gridWidget, final Point2D relativeLocation, final int uiHeaderRowIndex, final int uiHeaderColumnIndex, final AbstractNodeMouseEvent event) {
// Get column information
final double cx = relativeLocation.getX();
final BaseGridRendererHelper rendererHelper = gridWidget.getRendererHelper();
final BaseGridRendererHelper.ColumnInformation ci = rendererHelper.getColumnInformation(cx);
final GridColumn<?> column = ci.getColumn();
if (column == null) {
return false;
}
final ScenarioHeaderMetaData headerMetaData = (ScenarioHeaderMetaData) column.getHeaderMetaData().get(uiHeaderRowIndex);
final GridData gridData = gridWidget.getModel();
if (!gridData.getSelectedHeaderCells().isEmpty() && editSupportedLocal(headerMetaData.getSupportedEditAction(), event)) {
final GridData.SelectedCell firstSelectedHeaderCell = gridData.getSelectedHeaderCells().get(0);
final Optional<GridColumn<?>> firstSelectedColumnOptional = gridData.getColumns().stream().filter(col -> col.getIndex() == firstSelectedHeaderCell.getColumnIndex()).findFirst();
final int firstSelectedColumnPosition = gridData.getColumns().indexOf(firstSelectedColumnOptional.orElseThrow(IllegalStateException::new));
return startEditLocal((ScenarioGrid) gridWidget, firstSelectedColumnPosition, (ScenarioGridColumn) column, uiHeaderRowIndex, true);
}
return true;
}
use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.
the class ScenarioContextMenuRegistry method manageHeaderRightClick.
/**
* This method check if the click happened on an <b>header</b> cell. If it is so, manage it and returns <code>true</code>,
* otherwise returns <code>false</code>
* @param scenarioGrid
* @param left
* @param top
* @param uiHeaderRowIndex - coordinates relative to the grid top left corner
* @param uiColumnIndex
* @return
*/
private boolean manageHeaderRightClick(final ScenarioGrid scenarioGrid, final int left, final int top, final Integer uiHeaderRowIndex, final Integer uiColumnIndex) {
final ScenarioGridColumn column = (ScenarioGridColumn) scenarioGrid.getModel().getColumns().get(uiColumnIndex);
if (column == null) {
return false;
}
ScenarioHeaderMetaData columnMetadata = ScenarioSimulationGridHeaderUtilities.getColumnScenarioHeaderMetaData(column, uiHeaderRowIndex);
if (columnMetadata == null) {
return false;
}
if (uiHeaderRowIndex == null) {
return false;
}
boolean showDuplicateInstance = scenarioGrid.getType().equals(ScenarioSimulationModel.Type.RULE);
String group = ScenarioSimulationUtils.getOriginalColumnGroup(columnMetadata.getColumnGroup());
/* The first case managed, empty string, is related to clicking on the first header row, the one containing
GIVEN or EXPECT labels. In this case, the menu to show depends on columnMetadata.getTitle() value.
All other cases, "GIVEN" and "EXPECT" groups names, manage the other headers rows.
*/
switch(group) {
case "":
switch(columnMetadata.getTitle()) {
case "GIVEN":
headerGivenContextMenu.show(scenarioGrid.getGridWidget(), left, top);
break;
case "EXPECT":
headerExpectedContextMenu.show(scenarioGrid.getGridWidget(), left, top);
break;
default:
otherContextMenu.show(left, top);
}
break;
case "GIVEN":
givenContextMenu.show(scenarioGrid.getGridWidget(), left, top, uiColumnIndex, group, Objects.equals(columnMetadata.getMetadataType(), ScenarioHeaderMetaData.MetadataType.PROPERTY), showDuplicateInstance);
break;
case "EXPECT":
expectedContextMenu.show(scenarioGrid.getGridWidget(), left, top, uiColumnIndex, group, Objects.equals(columnMetadata.getMetadataType(), ScenarioHeaderMetaData.MetadataType.PROPERTY), showDuplicateInstance);
break;
default:
otherContextMenu.show(left, top);
}
scenarioGrid.setSelectedColumnAndHeader(uiHeaderRowIndex, uiColumnIndex);
return true;
}
use of org.drools.workbench.screens.scenariosimulation.client.metadata.ScenarioHeaderMetaData in project drools-wb by kiegroup.
the class ScenarioGridTest method testShowContextMenuGivenOrExpect.
@Test
public void testShowContextMenuGivenOrExpect() {
final String columnGroup = "grp";
final ScenarioHeaderMetaData scenarioHeaderMetaDataMock = mock(ScenarioHeaderMetaData.class);
when(scenarioHeaderMetaDataMock.getColumnGroup()).thenReturn(columnGroup);
final int uiColumnIndex = 0;
final int uiRowIndex = 0;
final double columnWidth = 100.0;
final GridColumn columnMock = mock(ScenarioGridColumn.class);
when(columnMock.getIndex()).thenReturn(uiColumnIndex);
when(columnMock.getWidth()).thenReturn(columnWidth);
when(((ScenarioGridColumn) columnMock).getFactIdentifier()).thenReturn(FactIdentifier.EMPTY);
when(columnMock.getHeaderMetaData()).thenReturn(Collections.singletonList(scenarioHeaderMetaDataMock));
when(((ScenarioGridColumn) columnMock).getInformationHeaderMetaData()).thenReturn(scenarioHeaderMetaDataMock);
when(scenarioGridModelMock.getColumns()).thenReturn(Collections.singletonList(columnMock));
final double rowHeight = 40.0;
final GridRow gridRow = mock(ScenarioGridRow.class);
when(gridRow.getHeight()).thenReturn(rowHeight);
when(scenarioGridModelMock.getRow(uiRowIndex)).thenReturn(gridRow);
when(rendererHelperMock.getColumnInformation(50.0)).thenReturn(columnInformationMock);
when(columnInformationMock.getColumn()).thenReturn(columnMock);
}
Aggregations