-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
155 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...ain/java/com/holonplatform/artisan/vaadin/flow/components/templates/HolonInputFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...-flow-components/src/main/resources/META-INF/resources/frontend/src/HolonInputFilter.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |