Search in sources :

Example 11 with DMNModelInstrumentedBase

use of org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase in project kie-wb-common by kiegroup.

the class EditableNameAndDataTypeColumn method edit.

@Override
public void edit(final GridCell<InformationItemCell.HasNameCell> cell, final GridBodyCellRenderContext context, final Consumer<GridCellValue<InformationItemCell.HasNameCell>> callback) {
    final int rowIndex = context.getRowIndex();
    if (!isEditable.test(rowIndex)) {
        return;
    }
    final int uiRowIndex = context.getRowIndex();
    final int uiColumnIndex = context.getColumnIndex();
    final double cellWidth = context.getCellWidth();
    final double cellHeight = context.getCellHeight();
    final double absoluteCellX = context.getAbsoluteCellX();
    final double absoluteCellY = context.getAbsoluteCellY();
    final InformationItemCell.HasNameAndDataTypeCell binding = (InformationItemCell.HasNameAndDataTypeCell) cell.getValue().getValue();
    editor.bind(new HasValueAndTypeRef<Name>() {

        @Override
        public QName getTypeRef() {
            return binding.getTypeRef();
        }

        @Override
        public void setTypeRef(final QName typeRef) {
            if (Objects.equals(typeRef, getTypeRef())) {
                return;
            }
            setTypeRefConsumer.accept(binding, typeRef);
        }

        @Override
        public Name getValue() {
            return binding.getName();
        }

        @Override
        public void setValue(final Name name) {
            if (Objects.equals(name, getValue())) {
                return;
            }
            if (name == null || name.getValue() == null || name.getValue().trim().isEmpty()) {
                clearValueConsumer.accept(binding);
            } else {
                setValueConsumer.accept(binding, name);
            }
        }

        @Override
        public String getPopoverTitle() {
            return EditableNameAndDataTypeColumn.this.getPopoverTitle();
        }

        @Override
        public Name toModelValue(final String componentValue) {
            return new Name(componentValue);
        }

        @Override
        public String toWidgetValue(final Name modelValue) {
            return modelValue.getValue();
        }

        @Override
        public String getValueLabel() {
            return translationService.getTranslation(DMNEditorConstants.NameAndDataTypePopover_NameLabel);
        }

        @Override
        public String normaliseValue(final String componentValue) {
            return NameUtils.normaliseName(componentValue);
        }

        @Override
        public DMNModelInstrumentedBase asDMNModelInstrumentedBase() {
            return binding.asDMNModelInstrumentedBase();
        }

        @Override
        public List<HasTypeRef> getHasTypeRefs() {
            return getNotNullHasTypeRefs(binding);
        }
    }, uiRowIndex, uiColumnIndex);
    final double[] dxy = { absoluteCellX + cellWidth / 2, absoluteCellY + cellHeight / 2 };
    final Optional<Point2D> rx = ((GridBodyCellEditContext) context).getRelativeLocation();
    rx.ifPresent(r -> {
        dxy[0] = r.getX();
        dxy[1] = r.getY();
    });
    cellEditorControls.show(editor, (int) (dxy[0]), (int) (dxy[1]));
}
Also used : QName(org.kie.workbench.common.dmn.api.property.dmn.QName) DMNModelInstrumentedBase(org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase) InformationItemCell(org.kie.workbench.common.dmn.client.editors.expressions.types.context.InformationItemCell) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Point2D(com.ait.lienzo.client.core.types.Point2D) List(java.util.List) GridBodyCellEditContext(org.uberfire.ext.wires.core.grids.client.widget.context.GridBodyCellEditContext)

Aggregations

DMNModelInstrumentedBase (org.kie.workbench.common.dmn.api.definition.model.DMNModelInstrumentedBase)11 Test (org.junit.Test)3 HasTypeRef (org.kie.workbench.common.dmn.api.definition.HasTypeRef)3 HasVariable (org.kie.workbench.common.dmn.api.definition.HasVariable)3 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)3 Definitions (org.kie.workbench.common.dmn.api.definition.model.Definitions)3 Node (org.kie.workbench.common.stunner.core.graph.Node)3 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)3 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)3 HasName (org.kie.workbench.common.dmn.api.definition.HasName)2 IsInformationItem (org.kie.workbench.common.dmn.api.definition.model.IsInformationItem)2 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2 Point2D (com.ait.lienzo.client.core.types.Point2D)1 List (java.util.List)1 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 BusinessKnowledgeModel (org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel)1 DecisionTable (org.kie.workbench.common.dmn.api.definition.model.DecisionTable)1 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)1 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)1