Пример #1
0
 @Override
 public Node.PropertySet[] getPropertySets() {
   final Node.PropertySet[][] props = new Node.PropertySet[1][];
   Runnable runnable =
       new Runnable() {
         @Override
         public void run() {
           FormLAF.executeWithLAFLocks(
               new Runnable() {
                 @Override
                 public void run() {
                   props[0] = component.getProperties();
                 }
               });
         }
       };
   if (EventQueue.isDispatchThread()) {
     runnable.run();
   } else {
     try {
       // We have made some attempts to keep initialization
       // of properties outside AWT thread, but it always
       // deadlocked with AWT thread for various reasons.
       EventQueue.invokeAndWait(runnable);
     } catch (InterruptedException iex) {
       FormUtils.LOGGER.log(Level.INFO, iex.getMessage(), iex);
     } catch (InvocationTargetException itex) {
       FormUtils.LOGGER.log(Level.INFO, itex.getMessage(), itex);
     }
   }
   return props[0];
 }
Пример #2
0
 /**
  * Determines if the given DataObject has an opened editor
  *
  * @param dataObject
  * @return true if the given DataObject has an opened editor. Otherwise false.
  * @throws InterruptedException
  * @throws InvocationTargetException
  */
 private boolean hasOpenedEditorPanes(final DataObject dataObject)
     throws InterruptedException, InvocationTargetException {
   final boolean[] hasEditorPanes = new boolean[] {false};
   Runnable r =
       new Runnable() {
         @Override
         public void run() {
           final EditorCookie cookie = dataObject.getLookup().lookup(EditorCookie.class);
           if (cookie != null) {
             // hack - care only about dataObjects with opened editors.
             // otherwise we won't assume it's file were opened to be edited
             JEditorPane pane = NbDocument.findRecentEditorPane(cookie);
             if (pane == null) {
               if (cookie instanceof EditorCookie.Observable) {
                 final EditorCookie.Observable o = (EditorCookie.Observable) cookie;
                 PropertyChangeListener l =
                     new PropertyChangeListener() {
                       @Override
                       public void propertyChange(PropertyChangeEvent evt) {
                         if (EditorCookie.Observable.PROP_OPENED_PANES.equals(
                             evt.getPropertyName())) {
                           addOpenedFiles(getFiles(dataObject));
                           o.removePropertyChangeListener(this);
                         }
                       }
                     };
                 o.addPropertyChangeListener(l);
                 pane = NbDocument.findRecentEditorPane(cookie);
                 if (pane != null) {
                   hasEditorPanes[0] = true;
                   o.removePropertyChangeListener(l);
                 }
               } else {
                 JEditorPane[] panes = cookie.getOpenedPanes();
                 hasEditorPanes[0] = panes != null && panes.length > 0;
               }
             } else {
               hasEditorPanes[0] = true;
             }
           }
         }
       };
   if (SwingUtilities.isEventDispatchThread()) {
     r.run();
   } else {
     SwingUtilities.invokeAndWait(r);
   }
   return hasEditorPanes[0];
 }