|
|
@ -1,5 +1,6 @@ |
|
|
|
package com.fr.design.extra; |
|
|
|
package com.fr.design.extra; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fr.base.FRContext; |
|
|
|
import com.fr.base.TemplateUtils; |
|
|
|
import com.fr.base.TemplateUtils; |
|
|
|
import com.fr.general.IOUtils; |
|
|
|
import com.fr.general.IOUtils; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
|
import com.fr.stable.StableUtils; |
|
|
@ -28,7 +29,7 @@ import java.util.Map; |
|
|
|
* Created by richie on 16/3/19. |
|
|
|
* Created by richie on 16/3/19. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class PluginWebPane extends JFXPanel { |
|
|
|
public class PluginWebPane extends JFXPanel { |
|
|
|
|
|
|
|
private static final String RESOURCE_URL = "resourceURL"; |
|
|
|
private WebEngine webEngine; |
|
|
|
private WebEngine webEngine; |
|
|
|
|
|
|
|
|
|
|
|
public PluginWebPane(final String installHome, final String mainJs) { |
|
|
|
public PluginWebPane(final String installHome, final String mainJs) { |
|
|
@ -42,6 +43,27 @@ public class PluginWebPane extends JFXPanel { |
|
|
|
WebView webView = new WebView(); |
|
|
|
WebView webView = new WebView(); |
|
|
|
webEngine = webView.getEngine(); |
|
|
|
webEngine = webView.getEngine(); |
|
|
|
try{ |
|
|
|
try{ |
|
|
|
|
|
|
|
String htmlString = getRenderedHtml(installHome, mainJs); |
|
|
|
|
|
|
|
webEngine.loadContent(htmlString); |
|
|
|
|
|
|
|
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void handle(WebEvent<String> event) { |
|
|
|
|
|
|
|
showAlert(event.getData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
JSObject obj = (JSObject) webEngine.executeScript("window"); |
|
|
|
|
|
|
|
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); |
|
|
|
|
|
|
|
webView.setContextMenuEnabled(false);//屏蔽右键
|
|
|
|
|
|
|
|
root.setCenter(webView); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String getRenderedHtml(String installHome, String mainJs) throws IOException { |
|
|
|
InputStream inp = IOUtils.readResource(StableUtils.pathJoin(installHome, mainJs)); |
|
|
|
InputStream inp = IOUtils.readResource(StableUtils.pathJoin(installHome, mainJs)); |
|
|
|
if (inp == null) { |
|
|
|
if (inp == null) { |
|
|
|
throw new IOException("Not found template: " + mainJs); |
|
|
|
throw new IOException("Not found template: " + mainJs); |
|
|
@ -52,35 +74,22 @@ public class PluginWebPane extends JFXPanel { |
|
|
|
String line; |
|
|
|
String line; |
|
|
|
Map<String, Object> map4Tpl = new HashMap<String, Object>(); |
|
|
|
Map<String, Object> map4Tpl = new HashMap<String, Object>(); |
|
|
|
|
|
|
|
|
|
|
|
map4Tpl.put("servletURL", "file:///" + URLEncoder.encode(installHome, "UTF-8")); |
|
|
|
map4Tpl.put(RESOURCE_URL, "file:///" + URLEncoder.encode(installHome, "UTF-8")); |
|
|
|
while ((line = read.readLine()) != null) { |
|
|
|
while ((line = read.readLine()) != null) { |
|
|
|
if (sb.length() > 0) { |
|
|
|
if (sb.length() > 0) { |
|
|
|
sb.append('\n'); |
|
|
|
sb.append('\n'); |
|
|
|
} |
|
|
|
} |
|
|
|
sb.append(line); |
|
|
|
sb.append(line); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
String htmlString = StringUtils.EMPTY; |
|
|
|
String htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl); |
|
|
|
try{ |
|
|
|
reader.close(); |
|
|
|
htmlString = TemplateUtils.renderParameter4Tpl(sb.toString(), map4Tpl); |
|
|
|
inp.close(); |
|
|
|
|
|
|
|
webEngine.loadContent(htmlString); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
webEngine.setOnAlert(new EventHandler<WebEvent<String>>() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void handle(WebEvent<String> event) { |
|
|
|
|
|
|
|
showAlert(event.getData()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
JSObject obj = (JSObject) webEngine.executeScript("window"); |
|
|
|
|
|
|
|
obj.setMember("PluginHelper", PluginWebBridge.getHelper(webEngine)); |
|
|
|
|
|
|
|
webView.setContextMenuEnabled(false);//屏蔽右键
|
|
|
|
|
|
|
|
root.setCenter(webView); |
|
|
|
|
|
|
|
}catch (Exception e){ |
|
|
|
}catch (Exception e){ |
|
|
|
|
|
|
|
FRContext.getLogger().error(e.getMessage(), e); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
reader.close(); |
|
|
|
} |
|
|
|
inp.close(); |
|
|
|
}); |
|
|
|
return htmlString; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void showAlert(final String message) { |
|
|
|
private void showAlert(final String message) { |
|
|
|