This repository has been archived by the owner on Jan 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from dmitrygusev/master
Support for BeanDisplay and Alerts
- Loading branch information
Showing
10 changed files
with
388 additions
and
12 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
6 changes: 6 additions & 0 deletions
6
src/main/java/com/trsvax/bootstrap/environment/AlertsEnvironment.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,6 @@ | ||
package com.trsvax.bootstrap.environment; | ||
|
||
|
||
public interface AlertsEnvironment extends FWEnvironment { | ||
|
||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/trsvax/bootstrap/environment/AlertsValues.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,41 @@ | ||
package com.trsvax.bootstrap.environment; | ||
|
||
import com.trsvax.bootstrap.FrameworkMixin; | ||
|
||
public class AlertsValues implements AlertsEnvironment { | ||
private boolean isInstrumented; | ||
private String type; | ||
private String prefix = "alert"; | ||
|
||
public AlertsValues(AlertsEnvironment values) { | ||
if ( values != null ) { | ||
this.type = values.getType(null); | ||
} | ||
} | ||
|
||
public boolean isInstrumented() { | ||
return isInstrumented; | ||
} | ||
|
||
public void withInstrumented(boolean value) { | ||
isInstrumented = value; | ||
} | ||
|
||
public String getType(FrameworkMixin mixin) { | ||
if ( mixin == null ) { | ||
return type; | ||
} | ||
return mixin.getType() == null ? type : mixin.getType(); | ||
} | ||
|
||
public AlertsValues withType(String type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
|
||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/trsvax/bootstrap/environment/BeanDisplayEnvironment.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,6 @@ | ||
package com.trsvax.bootstrap.environment; | ||
|
||
|
||
public interface BeanDisplayEnvironment extends FWEnvironment { | ||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/main/java/com/trsvax/bootstrap/environment/BeanDisplayValues.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,40 @@ | ||
package com.trsvax.bootstrap.environment; | ||
|
||
import com.trsvax.bootstrap.FrameworkMixin; | ||
|
||
public class BeanDisplayValues implements BeanDisplayEnvironment { | ||
private boolean isInstrumented; | ||
private String type; | ||
private String prefix = "dl"; | ||
|
||
public BeanDisplayValues(BeanDisplayEnvironment values) { | ||
if ( values != null ) { | ||
this.type = values.getType(null); | ||
} | ||
} | ||
|
||
public boolean isInstrumented() { | ||
return isInstrumented; | ||
} | ||
|
||
public void withInstrumented(boolean value) { | ||
isInstrumented = value; | ||
} | ||
|
||
public String getType(FrameworkMixin mixin) { | ||
if ( mixin == null ) { | ||
return type; | ||
} | ||
return mixin.getType() == null ? type : mixin.getType(); | ||
} | ||
|
||
public BeanDisplayValues withType(String type) { | ||
this.type = type; | ||
return this; | ||
} | ||
|
||
public String getPrefix() { | ||
return prefix; | ||
} | ||
|
||
} |
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
101 changes: 101 additions & 0 deletions
101
src/main/java/com/trsvax/bootstrap/services/bootstrapprovider/AlertsProvider.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,101 @@ | ||
package com.trsvax.bootstrap.services.bootstrapprovider; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import org.apache.tapestry5.Asset; | ||
import org.apache.tapestry5.MarkupWriter; | ||
import org.apache.tapestry5.annotations.Path; | ||
import org.apache.tapestry5.corelib.components.Alerts; | ||
import org.apache.tapestry5.dom.Element; | ||
import org.apache.tapestry5.dom.Visitor; | ||
import org.apache.tapestry5.ioc.annotations.Inject; | ||
import org.apache.tapestry5.json.JSONArray; | ||
import org.apache.tapestry5.services.Environment; | ||
import org.apache.tapestry5.services.javascript.InitializationPriority; | ||
import org.apache.tapestry5.services.javascript.JavaScriptSupport; | ||
import org.slf4j.Logger; | ||
|
||
import com.trsvax.bootstrap.AbstractFrameworkProvider; | ||
import com.trsvax.bootstrap.BootstrapProvider; | ||
import com.trsvax.bootstrap.FrameworkMixin; | ||
import com.trsvax.bootstrap.environment.AlertsEnvironment; | ||
|
||
public class AlertsProvider extends AbstractFrameworkProvider implements BootstrapProvider { | ||
|
||
public class AlertsVisitor implements Visitor { | ||
|
||
Element controls; | ||
final String type; | ||
final Set<Element> pop; | ||
final FrameworkMixin mixin; | ||
|
||
public AlertsVisitor(final FrameworkMixin mixin, final String type, final Set<Element> pop) { | ||
this.type = type; | ||
this.pop = pop; | ||
this.mixin = mixin; | ||
} | ||
|
||
public void visit(Element element) { | ||
if (!hasName("div", element)) { | ||
return; | ||
} | ||
|
||
javaScriptSupport.importStylesheet(alertsCss); | ||
javaScriptSupport.importJavaScriptLibrary(alertsJs); | ||
javaScriptSupport.addInitializerCall(InitializationPriority.EARLY, "bootstrapAlerts", new JSONArray()); | ||
} | ||
|
||
} | ||
|
||
private final Class<?>[] handles = {Alerts.class}; | ||
private final Class<AlertsEnvironment> environmentClass = AlertsEnvironment.class; | ||
private final Environment environment; | ||
@SuppressWarnings("unused") | ||
private final Logger logger; | ||
|
||
@Inject @Path("classpath:com/trsvax/bootstrap/t5-bootstrap-alerts.js") | ||
private Asset alertsJs; | ||
|
||
@Inject @Path("classpath:com/trsvax/bootstrap/t5-bootstrap-alerts.css") | ||
private Asset alertsCss; | ||
private JavaScriptSupport javaScriptSupport; | ||
|
||
public AlertsProvider(Environment environment, Logger logger, JavaScriptSupport javaScriptSupport) { | ||
this.environment = environment; | ||
this.logger = logger; | ||
this.javaScriptSupport = javaScriptSupport; | ||
} | ||
|
||
public boolean instrument(FrameworkMixin mixin) { | ||
return instrument(mixin, environment.peekRequired(environmentClass), handles); | ||
} | ||
|
||
boolean handle(FrameworkMixin mixin) { | ||
if ( Alerts.class.getCanonicalName().equals(mixin.getComponentClassName())) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public boolean cleanupRender(FrameworkMixin mixin, MarkupWriter writer) { | ||
|
||
if ( ! handle(mixin)) { | ||
return false; | ||
} | ||
|
||
final AlertsEnvironment alertsEnvironment = environment.peekRequired(environmentClass); | ||
final String type = alertsEnvironment.getType(mixin); | ||
if ( type == null ) { | ||
return false; | ||
} | ||
|
||
final Set<Element> pop = new HashSet<Element>(); | ||
mixin.getRoot().visit( new AlertsVisitor(mixin,type,pop)); | ||
for ( Element element : pop ) { | ||
element.pop(); | ||
} | ||
return true; | ||
} | ||
} |
Oops, something went wrong.