Example #1
0
 public void setEditorManager(EditorTabManager editorManager) {
   editorManager
       .currentXHTMLResourceProperty()
       .addListener((observable, oldValue, newValue) -> refreshWebView(newValue));
   editorManager
       .needsRefreshProperty()
       .addListener(
           (observable, oldValue, newValue) -> {
             if (newValue) {
               logger.info("getting reload event from needs refresh property");
               webview.getEngine().reload();
             }
           });
   this.editorManager = editorManager;
 }
Example #2
0
 @Produces
 @EditorTabManagerProducer
 public static EditorTabManager getInstance() {
   if (instance == null) {
     instance = BeanFactory.getInstance().getBean(EditorTabManager.class);
     instance.init();
   }
   return instance;
 }
Example #3
0
 private void refreshWebView(Resource resource) {
   if (isVisible) {
     WebEngine engine = webview.getEngine();
     engine
         .getLoadWorker()
         .stateProperty()
         .addListener(
             (observable, oldValue, newValue) -> {
               if (newValue.equals(Worker.State.SUCCEEDED)) {
                 Document document = engine.getDocument();
                 Element documentElement = document.getDocumentElement();
                 if (documentElement != null) {
                   ((EventTarget) documentElement)
                       .addEventListener(
                           "click",
                           evt -> {
                             if (evt.getTarget() instanceof ElementImpl) {
                               Deque<ElementPosition> positions = new ArrayDeque<>();
                               ElementImpl currentElement = ((ElementImpl) evt.getTarget());
                               ElementImpl parent =
                                   (ElementImpl) currentElement.getParentElement();
                               while (parent != null) {
                                 NodeList children;
                                 if (StringUtils.isNotEmpty(currentElement.getNamespaceURI())) {
                                   children =
                                       parent.getElementsByTagNameNS(
                                           currentElement.getNamespaceURI(),
                                           currentElement.getNodeName());
                                 } else {
                                   children =
                                       parent.getElementsByTagName(currentElement.getNodeName());
                                 }
                                 for (int i = 0; i < children.getLength(); i++) {
                                   if (children.item(i) == currentElement) {
                                     ElementPosition position =
                                         new ElementPosition(
                                             currentElement.getNodeName(),
                                             i,
                                             currentElement.getNamespaceURI());
                                     positions.push(position);
                                   }
                                 }
                                 currentElement = parent;
                                 parent = (ElementImpl) currentElement.getParentElement();
                               }
                               editorManager.scrollTo(positions);
                             } else {
                               logger.info("clicked class " + evt.getTarget());
                             }
                           },
                           false);
                 }
               }
             });
     engine.load("http://localhost:8777/" + resource.getHref());
   }
 }