Search in sources :

Example 1 with LayeredElementBindingImpl

use of org.eclipse.sapphire.modeling.LayeredElementBindingImpl in project liferay-ide by liferay.

the class TransitionMetadataResource method createBinding.

@Override
protected PropertyBinding createBinding(Property property) {
    PropertyBinding binding = null;
    PropertyDef def = property.definition();
    if (TransitionMetadata.PROP_NAME.equals(def)) {
        binding = new ValuePropertyBinding() {

            @Override
            public String read() {
                return TransitionMetadataResource.this._metadata.getName();
            }

            @Override
            public void write(String value) {
                TransitionMetadataResource.this._metadata.setName(value);
                WorkflowNodeMetadataResource wfNodeMetadataResource = parent().adapt(WorkflowNodeMetadataResource.class);
                wfNodeMetadataResource.saveMetadata();
            }
        };
    } else if (TransitionMetadata.PROP_LABEL_LOCATION.equals(def)) {
        binding = new LayeredElementBindingImpl() {

            @Override
            public ElementType type(Resource resource) {
                return Position.TYPE;
            }

            @Override
            protected Resource createResource(Object obj) {
                return new LabelPositionResource((Point) obj, TransitionMetadataResource.this);
            }

            @Override
            protected Object readUnderlyingObject() {
                return TransitionMetadataResource.this._metadata.getLabelPosition();
            }
        };
    } else if (TransitionMetadata.PROP_BENDPOINTS.equals(def)) {
        binding = new LayeredListPropertyBinding() {

            @Override
            public void remove(Resource resource) {
                if (resource instanceof PositionResource) {
                    List<Point> bendPoints = TransitionMetadataResource.this._metadata.getBendpoints();
                    bendPoints.remove(((PositionResource) resource).getPoint());
                    WorkflowNodeMetadataResource wfNodeMetadataResource = parent().adapt(WorkflowNodeMetadataResource.class);
                    wfNodeMetadataResource.saveMetadata();
                }
            }

            @Override
            public ElementType type(Resource resource) {
                return ConnectionBendpoint.TYPE;
            }

            @Override
            protected Object insertUnderlyingObject(ElementType type, int position) {
                Point newBendpoint = new Point();
                List<Point> bendPoints = TransitionMetadataResource.this._metadata.getBendpoints();
                bendPoints.add(position, newBendpoint);
                WorkflowNodeMetadataResource wfNodeMetadataResource = parent().adapt(WorkflowNodeMetadataResource.class);
                wfNodeMetadataResource.saveMetadata();
                return newBendpoint;
            }

            @Override
            protected List<?> readUnderlyingList() {
                return TransitionMetadataResource.this._metadata.getBendpoints();
            }

            @Override
            protected Resource resource(Object obj) {
                return new PositionResource((Point) obj, TransitionMetadataResource.this);
            }
        };
    }
    if (binding != null) {
        binding.init(property);
    }
    return binding;
}
Also used : ElementType(org.eclipse.sapphire.ElementType) PropertyDef(org.eclipse.sapphire.PropertyDef) Resource(org.eclipse.sapphire.Resource) ConnectionBendpoint(com.liferay.ide.kaleo.core.model.ConnectionBendpoint) LayeredListPropertyBinding(org.eclipse.sapphire.LayeredListPropertyBinding) PropertyBinding(org.eclipse.sapphire.PropertyBinding) ValuePropertyBinding(org.eclipse.sapphire.ValuePropertyBinding) LayeredListPropertyBinding(org.eclipse.sapphire.LayeredListPropertyBinding) LayeredElementBindingImpl(org.eclipse.sapphire.modeling.LayeredElementBindingImpl) ValuePropertyBinding(org.eclipse.sapphire.ValuePropertyBinding) List(java.util.List)

Aggregations

ConnectionBendpoint (com.liferay.ide.kaleo.core.model.ConnectionBendpoint)1 List (java.util.List)1 ElementType (org.eclipse.sapphire.ElementType)1 LayeredListPropertyBinding (org.eclipse.sapphire.LayeredListPropertyBinding)1 PropertyBinding (org.eclipse.sapphire.PropertyBinding)1 PropertyDef (org.eclipse.sapphire.PropertyDef)1 Resource (org.eclipse.sapphire.Resource)1 ValuePropertyBinding (org.eclipse.sapphire.ValuePropertyBinding)1 LayeredElementBindingImpl (org.eclipse.sapphire.modeling.LayeredElementBindingImpl)1