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
1 parent
65667a4
commit 33dc3be
Showing
39 changed files
with
856 additions
and
219 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
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
88 changes: 88 additions & 0 deletions
88
rapidoid-gui/src/main/java/org/rapidoid/gui/base/AbstractInput.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,88 @@ | ||
package org.rapidoid.gui.base; | ||
|
||
import org.rapidoid.annotation.Authors; | ||
import org.rapidoid.annotation.Since; | ||
import org.rapidoid.commons.AnyObj; | ||
import org.rapidoid.gui.GUI; | ||
import org.rapidoid.u.U; | ||
import org.rapidoid.var.Var; | ||
|
||
/* | ||
* #%L | ||
* rapidoid-gui | ||
* %% | ||
* Copyright (C) 2014 - 2016 Nikolche Mihajlovski and contributors | ||
* %% | ||
* 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. | ||
* #L% | ||
*/ | ||
|
||
@Authors("Nikolche Mihajlovski") | ||
@Since("5.1.0") | ||
public abstract class AbstractInput<W extends AbstractInput<?>> extends AbstractWidget<W> { | ||
|
||
protected Var<?> var; | ||
|
||
protected String name; | ||
|
||
public Var<?> var() { | ||
return var; | ||
} | ||
|
||
public W var(Var<?> var) { | ||
this.var = var; | ||
return me(); | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
public W name(String name) { | ||
this.name = name; | ||
return me(); | ||
} | ||
|
||
protected static boolean has(Var<?> var, Object value) { | ||
return var != null && AnyObj.contains(var.get(), str(value)); | ||
} | ||
|
||
protected static String str(Object value) { | ||
return GUI.str(value); | ||
} | ||
|
||
protected Var<?> _var() { | ||
return var != null ? var : U.notEmpty(name) ? GUI.var(name) : null; | ||
} | ||
|
||
protected Object _valOr(Object initial) { | ||
Var<?> _var = _var(); | ||
Object value = _var != null ? _var.get() : null; | ||
return U.or(value, initial); | ||
} | ||
|
||
protected String _strVal(Object initial) { | ||
Var<?> _var = _var(); | ||
Object value = _var != null ? _var.get() : null; | ||
return str(U.or(value, initial, "")); | ||
} | ||
|
||
protected String _name() { | ||
return U.or(name, var != null ? var.name() : null); | ||
} | ||
|
||
protected boolean picked(Object value, boolean initial) { | ||
return req().isGetReq() ? initial : has(_var(), value); | ||
} | ||
|
||
} |
Oops, something went wrong.