Skip to content

Commit

Permalink
operator input filter component
Browse files Browse the repository at this point in the history
  • Loading branch information
rrighi committed Apr 19, 2019
1 parent 6276d79 commit 1d89121
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ public Menu() {
.forEach(a -> event.getApplicationLayout().getNavbarContent().add(a));
});

addOverlayStateChangeEventListener(evt -> {
System.err.println("-------> Overlay: " + evt.isOverlay());
});
// addOverlayStateChangeEventListener(evt -> {
// System.err.println("-------> Overlay: " + evt.isOverlay());
// });
}

private Component getMenuContent() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.holonplatform.artisan.vaadin.flow.components.builders.OperatorInputFilterConfigurator.FilterOperatorChangeListener;
import com.holonplatform.artisan.vaadin.flow.components.builders.OperatorInputFilterConfigurator.FilterOperatorSelectConfigurator;
import com.holonplatform.artisan.vaadin.flow.components.internal.builders.DefaultFilterOperatorSelectConfigurator;
import com.holonplatform.artisan.vaadin.flow.components.templates.HolonInputFilter;
import com.holonplatform.core.Registration;
import com.holonplatform.core.property.Property;
import com.holonplatform.core.query.QueryFilter;
Expand Down Expand Up @@ -79,6 +80,7 @@ public OperatorInputFilterAdapter(Property<? super T> property, InputFilterOpera
getElement().setAttribute("operator-input-filter", "");
// operator select
this.operatorSelect = new FilterOperatorSelect(operators);
this.operatorSelect.getElement().setAttribute("operator-input-filter-select", "");
this.operatorSelect.addValueChangeListener(e -> {
// check operator
getInput().ifPresent(i -> i.setReadOnly((e.getValue() != null
Expand All @@ -99,18 +101,14 @@ public OperatorInputFilterAdapter(Property<? super T> property, InputFilterOpera
public void build(Input<T> input) {
Obj.argumentNotNull(input, "Input must be not null");
this.input = input;

// ensure no children
getChildren().forEach(c -> remove(c));

final FilterOperatorSelect operatorSelect = getOperatorSelect();
operatorSelect.getElement().setAttribute("operator-filter-slot", "operator");
add(operatorSelect);

final Component inputComponent = input.getComponent();
inputComponent.getElement().setAttribute("operator-filter-slot", "operator");
add(inputComponent);

inputComponent.getElement().getStyle().set("flex-grow", "1");
// add components
final HolonInputFilter filter = new HolonInputFilter();
filter.setOperatorComponent(getOperatorSelect());
filter.setInputComponent(input.getComponent());
filter.getElement().getStyle().set("flex-grow", "1");
add(filter);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright 2016-2019 Axioma srl.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.holonplatform.artisan.vaadin.flow.components.templates;

import com.holonplatform.artisan.core.utils.Obj;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.HtmlImport;
import com.vaadin.flow.component.polymertemplate.PolymerTemplate;
import com.vaadin.flow.templatemodel.TemplateModel;

@Tag("holon-input-filter")
@HtmlImport("frontend://src/HolonInputFilter.html")
public class HolonInputFilter extends PolymerTemplate<TemplateModel> {

private static final long serialVersionUID = -8446468454355099170L;

private Component operator;
private Component input;

public HolonInputFilter() {
super();
}

public void setOperatorComponent(Component operator) {
Obj.argumentNotNull(operator, "Component must be not null");
removeOperator();
if (operator != null) {
addToSlot("operator", operator);
}
}

public void setInputComponent(Component input) {
Obj.argumentNotNull(input, "Component must be not null");
removeInput();
if (input != null) {
input.getElement().getStyle().set("flex-grow", "1");
addToSlot("input", input);
}
}

private void addToSlot(String slot, Component... components) {
for (Component component : components) {
setSlot(component, slot);
add(component);
}
}

private void add(Component component) {
getElement().appendChild(component.getElement());
}

private void removeOperator() {
remove(this.operator);
this.operator = null;
}

private void removeInput() {
remove(this.input);
this.input = null;
}

private static void remove(Component component) {
if (component != null) {
component.getElement().removeFromParent();
}
}

private static void setSlot(Component component, String slot) {
component.getElement().setAttribute("slot", slot);
}

}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<dom-module id="com-holonplatform-operator-input-filter" theme-for="vaadin-custom-field">
<dom-module id="com-holonplatform-operator-input-filter" theme-for="vaadin-custom-field">
<template>
<style>
:host([operator-input-filter]) div.inputs-wrapper {
display: flex;
}
:host([operator-input-filter]) [part="label"] {
padding-bottom: 0.25em;
:host([operator-input-filter]) .container {
flex-grow: 1;
}
</style>
</template>
Expand All @@ -14,9 +11,8 @@
<dom-module id="com-holonplatform-operator-input-filter-operator-select" theme-for="vaadin-select">
<template>
<style>
:host([operator-filter-slot="operator"]) {
width: 4.2em;
margin-right: 2px;
:host([operator-input-filter-select]) {
width: 4.3em;
}
</style>
</template>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!-- Dependency resources -->
<link rel="import" href="../bower_components/polymer/polymer-element.html">

<!-- Element definition -->
<dom-module id="holon-input-filter">
<template>
<style>
:host {
display: flex;
display: -webkit-box;
display: -webkit-flex;
display: -moz-box;
display: -ms-flexbox;
flex-direction: row;
-webkit-flex-direction: row;
-moz-flex-direction: row;
-ms-flex-direction: row;
-o-flex-direction: row;
justify-content: center;
align-items: center;
}

[part="operator"] {
display: inline-flex;
flex-grow: 0;
flex-shrink: 0;
margin-right: 1px;
}

[part="input"] {
display: inline-flex;
flex-grow: 1;
}
</style>
<div part="operator">
<slot name="operator"></slot>
</div>
<div part="input">
<slot name="input"></slot>
</div>
</template>

<!-- Register the element -->
<script>
class HolonInputFilter extends Polymer.Element {
static get is() {
return 'holon-input-filter'
}
}
customElements.define(HolonInputFilter.is, HolonInputFilter);
</script>
</dom-module>

0 comments on commit 1d89121

Please sign in to comment.