@Override
 public void componentOpened() {
   TopComponent projWindow = WindowManager.getDefault().findTopComponent("projectTabLogical_tc");
   trainingResultSets = projWindow.getLookup().lookupResult(DataSet.class);
   trainingResultSets.addLookupListener(this);
   resultChanged(new LookupEvent(trainingResultSets));
 }
 /* Singleton accessor. As WelcomeComponent is persistent singleton this
  * accessor makes sure that WelcomeComponent is deserialized by window system.
  * Uses known unique TopComponent ID "VisualVMWelcome" to get WelcomeComponent instance
  * from window system. "VisualVMWelcome" is name of settings file defined in module layer.
  */
 public static synchronized WelcomeComponent findComp() {
   WelcomeComponent wc = component.get();
   if (wc == null) {
     TopComponent tc = WindowManager.getDefault().findTopComponent(PREFERRED_ID); // NOI18N
     if (tc != null) {
       if (tc instanceof WelcomeComponent) {
         wc = (WelcomeComponent) tc;
         component = new WeakReference<WelcomeComponent>(wc);
       } else {
         // Incorrect settings file?
         IllegalStateException exc =
             new IllegalStateException(
                 "Incorrect settings file. Unexpected class returned." // NOI18N
                     + " Expected:"
                     + WelcomeComponent.class.getName() // NOI18N
                     + " Returned:"
                     + tc.getClass().getName()); // NOI18N
         ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, exc);
         // Fallback to accessor reserved for window system.
         wc = WelcomeComponent.createComp();
       }
     } else {
       // WelcomeComponent cannot be deserialized
       // Fallback to accessor reserved for window system.
       wc = WelcomeComponent.createComp();
     }
   }
   return wc;
 }
 @Override
 public void resultChanged(LookupEvent ev) {
   TopComponent tc = ref.get();
   if (tc == null) {
     r.removeLookupListener(this);
     synchronized (lookupListeners) {
       lookupListeners.remove(this);
     }
     return;
   }
   if (LOG.isLoggable(Level.FINER)) {
     LOG.log(Level.FINER, "  looking result changed for {0} ", new Object[] {ref.get()});
   }
   DataObject tcDataObject = tc.getLookup().lookup(DataObject.class);
   if (tcDataObject != null) {
     try {
       if (hasOpenedEditorPanes(tcDataObject)) {
         addOpenedFiles(getFiles(tcDataObject));
       }
     } catch (InterruptedException ex) {
       LOG.log(Level.WARNING, null, ex);
     } catch (InvocationTargetException ex) {
       LOG.log(Level.WARNING, null, ex);
     }
     r.removeLookupListener(this);
     synchronized (lookupListeners) {
       lookupListeners.remove(this);
     }
   }
 }
 /**
  * multiview components do not fire events when switching their inner tabs so we have to listen to
  * changes in lookup contents
  */
 private void switchLookupListener() {
   TopComponent active = TopComponent.getRegistry().getActivated();
   if (null != lookupRes) {
     lookupRes.removeLookupListener(SatelliteViewSwitch.this);
     lookupRes = null;
   }
   if (null != active) {
     lookupRes = active.getLookup().lookupResult(LayoutScene.class);
     lookupRes.addLookupListener(SatelliteViewSwitch.this);
     lookupRes.allItems();
   }
 }
  /**
   * Check whether Layer explorer window is the only opened window.
   *
   * @return
   */
  private boolean isLayersMaximized() {
    boolean isMaximized = true;
    TopComponent.Registry registry = TopComponent.getRegistry();
    Set openedTcs = registry.getOpened();
    for (Iterator i = openedTcs.iterator(); i.hasNext(); ) {
      TopComponent tc = (TopComponent) i.next();

      if (tc.isShowing() && !(tc instanceof SatelliteViewTopComponent)) {
        // other window(s) than the Layers are showing
        isMaximized = false;
        break;
      }
    }
    return isMaximized;
  }
Beispiel #6
0
  @Override
  public Visualization getVisualization() {

    Visualization v = new Visualization();
    PersistentVisualization pv = new PersistentVisualization();

    if (catProvider != null && catProvider.isOn()) {

      for (TopComponent tc : TopComponent.getRegistry().getOpened()) {
        if (tc instanceof TViewPanel) {
          TViewPanel tvp = (TViewPanel) tc;
          TypingData td = tvp.ds.getLookup().lookup(TypingData.class);
          if (ds == td) {
            DataModel dm = catProvider.getDataModel();
            if (dm == tvp.cp.getDataModel()) {
              v.filter = tvp.getFilter();
              v.category = catProvider;
              break;
            }
          }
        }
      }
    }
    pv.distanceFilterValue = uv.getDistanceFilterValue();
    pv.linearSize = uv.getLinearSize();
    v.pv = pv;

    return v;
  }
 private void updateTitle() {
   String titlePostfix = "";
   if (getFormModel().isValid()) {
     titlePostfix = " - " + getFormModel().getModelName();
   }
   toolView.setDisplayName(titlePrefix + titlePostfix);
 }
 private void addLookupListener(TopComponent tc) {
   Result<DataObject> r = tc.getLookup().lookupResult(DataObject.class);
   L l = new L(new WeakReference<TopComponent>(tc), r);
   synchronized (lookupListeners) {
     lookupListeners.add(l);
   }
   r.addLookupListener(l);
 }
 @Override
 protected void componentHidden() {
   super.componentHidden();
   if (null != content) {
     // notify components down the hierarchy tree that they no long
     // need to periodically refresh their content (e.g. RSS feeds)
     remove(content);
   }
 }
        @Override
        public void resultChanged(LookupEvent le) {

          // TODO: we should have some other Interface for things that can update the tags view
          // then we could get rid of the Library dependancy on the Explorer API
          if (TopComponent.getRegistry().getActivated() instanceof ExplorerManager.Provider) {
            update();
          }
        }
 @Override
 public void open() {
   // Open the repl in the output pane by default
   Mode m = WindowManager.getDefault().findMode("output");
   if (m != null) {
     m.dockInto(this);
   }
   super.open();
 }
Beispiel #12
0
 public void stopListening() {
   synchronized (theInstance) {
     if (null != registryListener) {
       TopComponent.getRegistry().removePropertyChangeListener(registryListener);
       registryListener = null;
       currentLayers = null;
     }
   }
 }
Beispiel #13
0
 private String getProjectType() {
   String ret = "";
   TopComponent.Registry registry = TopComponent.getRegistry();
   TopComponent tc = registry.getActivated();
   if (tc != null) {
     Lookup lkup = tc.getLookup();
     if (lkup != null) {
       DataObject dObj = lkup.lookup(DataObject.class);
       if (dObj != null) {
         FileObject fObj = dObj.getPrimaryFile();
         Project project = FileOwnerQuery.getOwner(fObj);
         if (project != null) {
           ret = project.getClass().getName();
         }
       }
     }
   }
   return ret;
 }
  @Override
  public JComponent[] getMenuPresenters() {
    List<DataContentTopComponent> newWindowLists = DataContentTopComponent.getNewWindowList();

    // Get DataContent provider to include in the menu
    int totalItems = newWindowLists.size() > 0 ? 2 : 1;
    JComponent[] comps = new JComponent[totalItems];
    int counter = 0;

    TopComponent contentWin = DataContentTopComponent.findInstance();
    JMenuItem defaultItem = new JMenuItem(contentWin.getName()); // set the main name

    defaultItem.addActionListener(new OpenTopComponentAction(contentWin));

    if (!Case.isCaseOpen() || Case.getCurrentCase().hasData() == false) {
      defaultItem.setEnabled(false); // disable the menu items when no case is opened
    } else {
      defaultItem.setEnabled(true); // enable the menu items when there's a case opened / created
    }

    comps[counter++] = defaultItem;

    // add the submenu
    if (newWindowLists != null) {
      if (newWindowLists.size() > 0) {

        JMenu submenu =
            new JMenu(
                NbBundle.getMessage(
                    this.getClass(), "DataContentDynamicMenu.menu.dataContentWin.text"));
        for (int i = 0; i < newWindowLists.size(); i++) {
          DataContentTopComponent dctc = newWindowLists.get(i);
          JMenuItem item = new JMenuItem(dctc.getName());
          item.addActionListener(new OpenTopComponentAction(dctc));
          submenu.add(item);
        }

        comps[counter++] = submenu;
      }
    }

    return comps;
  }
 @Override
 protected void componentActivated() {
   WindowManager.getDefault().findTopComponent("AssignmentEditorTopComponent").open();
   WindowManager.getDefault()
       .findTopComponent("AssignmentEditorTopComponent")
       .requestFocusInWindow();
   WindowManager.getDefault().findTopComponent("AssignmentEditorTopComponent").requestActive();
   super
       .componentActivated(); // To change body of generated methods, choose Tools | Templates.
 }
 @Override
 protected void componentOpened() {
   super.componentOpened();
   if (firstTimeOpen) {
     firstTimeOpen = false;
     if (!WelcomeOptions.getDefault().isShowOnStartup()) {
       close();
     }
   }
 }
 /**
  * Shows the desired multiview element. Must be called after the editor has been opened (i.e.
  * WSDLEditorSupport.open()) so the TopComponent will be the active one in the registry.
  *
  * @param id identifier of the multiview element.
  */
 public static void requestMultiviewActive(String id) {
   TopComponent activeTC = TopComponent.getRegistry().getActivated();
   MultiViewHandler handler = MultiViews.findMultiViewHandler(activeTC);
   if (handler != null) {
     MultiViewPerspective[] perspectives = handler.getPerspectives();
     for (MultiViewPerspective perspective : perspectives) {
       if (perspective.preferredID().equals(id)) {
         handler.requestActive(perspective);
       }
     }
   }
 }
Beispiel #18
0
 private ArrayList<TopComponent> findShowingTCs() {
   ArrayList<TopComponent> res = new ArrayList<>(3);
   TopComponent.getRegistry()
       .getOpened()
       .stream()
       .filter((tc) -> (tc.isShowing()))
       .forEach(
           (tc) -> {
             res.add(tc);
           });
   return res;
 }
  private void initContentPanel() {

    moreOptionsPane = new MoreOptionsPane(this, formModel.isMoreOptionsFormCollapsedOnInit());

    resetButton = createButton("org/esa/snap/rcp/icons/Undo24.gif");
    resetButton.setName("ResetButton");
    resetButton.setToolTipText("Reset to defaults"); /*I18N*/
    resetButton.addActionListener(wrapWithAutoApplyActionListener(e -> resetToDefaults()));

    multiApplyButton = createButton("org/esa/snap/rcp/icons/MultiAssignBands24.gif");
    multiApplyButton.setName("MultiApplyButton");
    multiApplyButton.setToolTipText("Apply to other bands"); /*I18N*/
    multiApplyButton.addActionListener(e -> applyMultipleColorPaletteDef());

    importButton = createButton("tango/22x22/actions/document-open.png");
    importButton.setName("ImportButton");
    importButton.setToolTipText("Import colour palette from text file."); /*I18N*/
    importButton.addActionListener(
        e -> {
          importColorPaletteDef();
          applyChanges();
        });
    importButton.setEnabled(true);

    exportButton = createButton("tango/22x22/actions/document-save-as.png");
    exportButton.setName("ExportButton");
    exportButton.setToolTipText("Save colour palette to text file."); /*I18N*/
    exportButton.addActionListener(
        e -> {
          exportColorPaletteDef();
          childForm.updateFormModel(getFormModel());
        });
    exportButton.setEnabled(true);

    helpButton = createButton("tango/22x22/apps/help-browser.png");
    helpButton.setToolTipText("Help."); /*I18N*/
    helpButton.setName("helpButton");
    helpButton.addActionListener(e -> toolView.getHelpCtx().display());

    editorPanel = new JPanel(new BorderLayout(4, 4));
    toolButtonsPanel = GridBagUtils.createPanel();

    contentPanel = new JPanel(new BorderLayout(4, 4));
    contentPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    contentPanel.setPreferredSize(new Dimension(320, 200));
    contentPanel.add(editorPanel, BorderLayout.CENTER);
    contentPanel.add(toolButtonsPanel, BorderLayout.EAST);

    setProductSceneView(SnapApp.getDefault().getSelectedProductSceneView());

    SnapApp.getDefault().getSelectionSupport(ProductSceneView.class).addHandler(this);
  }
Beispiel #20
0
 public void startListening() {
   if (!isLayersWindowEnabled()) {
     return;
   }
   synchronized (theInstance) {
     if (null == registryListener) {
       registryListener = createRegistryListener();
       TopComponent.getRegistry().addPropertyChangeListener(registryListener);
       switchLookupListener();
       run();
     }
   }
 }
  private void openAndCloseMembers(Perspective perspective) {
    // Close other perspective based on group name
    for (Perspective g : perspectives) {
      if (g != perspective) {
        TopComponentGroup tpg = WindowManager.getDefault().findTopComponentGroup(g.getName());
        if (tpg != null) {
          tpg.close();
        }
      }
    }

    // Open perspective
    TopComponentGroup tpg = WindowManager.getDefault().findTopComponentGroup(perspective.getName());
    if (tpg != null) {
      tpg.open();
    }

    // Close members
    for (TopComponent c : WindowManager.getDefault().getRegistry().getOpened()) {
      String pId = WindowManager.getDefault().findTopComponentID((TopComponent) c);
      for (PerspectiveMember perspectiveMember : members) {
        if (pId.equals(perspectiveMember.getTopComponentId())
            && !perspectiveMember.isMemberOf(perspective)) {
          boolean closed = c.close();
        }
      }
    }

    // Open members
    for (PerspectiveMember perspectiveMember : members) {
      if (perspectiveMember.isMemberOf(perspective)) {
        String pId = perspectiveMember.getTopComponentId();
        TopComponent c = WindowManager.getDefault().findTopComponent(pId);
        if (c != null && !c.isOpened()) {
          c.open();
        }
      }
    }
  }
 protected static EditorCookie getTextComponent(Node n) {
   DataObject dobj = n.getCookie(DataObject.class);
   if (dobj != null) {
     EditorCookie ec = dobj.getCookie(EditorCookie.class);
     if (ec != null) {
       TopComponent activetc = TopComponent.getRegistry().getActivated();
       if (activetc instanceof Pane) {
         return ec;
       }
     }
   }
   return null;
 }
 /**
  * Called when <code>TopComponent</code> is about to be shown. Shown here means the component is
  * selected or resides in it own cell in container in its <code>Mode</code>. The container is
  * visible and not minimized.
  *
  * <p><em>Note:</em> component is considered to be shown, even its container window is overlapped
  * by another window.
  *
  * @since 2.18
  *     <p>#38900 - lazy addition of GUI components
  */
 @Override
 protected void componentShowing() {
   if (!initialized) {
     initialized = true;
     doInitialize();
   }
   if (null != content && getComponentCount() == 0) {
     // notify components down the hierarchy tree that they should
     // refresh their content (e.g. RSS feeds)
     add(content, BorderLayout.CENTER);
   }
   super.componentShowing();
   //        setActivatedNodes( new Node[] {} );
 }
Beispiel #24
0
  private boolean isValidFileOpened() {
    boolean result = false;

    TopComponent.Registry registry = TopComponent.getRegistry();
    TopComponent tc = registry.getActivated();
    if (tc != null) {
      Lookup lkup = tc.getLookup();
      if (lkup != null) {
        DataObject dObj = lkup.lookup(DataObject.class);
        if (dObj != null) {
          String ext = dObj.getPrimaryFile().getExt();
          if (ext != null) {
            ext = ext.toLowerCase();
            if (ext.equals("java")) { // NOI18N
              return true;
            }
          }
        }
      }
    }

    return result;
  }
Beispiel #25
0
  @Override
  public void setName(String name) {
    String oldName = m_name;

    if (m_name.equals(name)) return;

    super.setName(name);

    m_name = name;

    onRename(oldName, m_name);

    if (m_topComponent != null) m_topComponent.setDisplayName(m_name);
  }
Beispiel #26
0
 @Override
 public void run() {
   if (!SwingUtilities.isEventDispatchThread()) {
     EventQueue.invokeLater(this);
     return;
   }
   currentToken = new Object();
   TopComponent.Registry registry = TopComponent.getRegistry();
   final TopComponent activeTc = registry.getActivated();
   final Set<TopComponent> opened = new HashSet<>(registry.getOpened());
   final LayoutScene existingLayers = currentLayers;
   final boolean isMaximized = isLayersMaximized();
   final Object token = currentToken;
   RP.post(
       () -> {
         findNewLayers(existingLayers, activeTc, opened, isMaximized, token);
       });
 }
Beispiel #27
0
 /**
  * Semantics is similar to {@link org.openide.windows.TopComponent#getActivatedNodes()} except
  * that this method returns File objects instead od Nodes. Every node is examined for Files it
  * represents. File and Folder nodes represent their underlying files or folders. Project nodes
  * are represented by their source groups. Other logical nodes must provide FileObjects in their
  * Lookup.
  *
  * @return File [] array of activated files
  * @param nodes or null (then taken from windowsystem, it may be wrong on editor tabs #66700).
  */
 public static Context getCurrentContext(Node[] nodes) {
   if (nodes == null) {
     nodes = TopComponent.getRegistry().getActivatedNodes();
   }
   if (Arrays.equals(contextNodesCached.get(), nodes)) {
     Context ctx = contextCached.get();
     if (ctx != null) return ctx;
   }
   VCSContext vcsCtx = VCSContext.forNodes(nodes);
   Context ctx =
       new Context(
           new HashSet(vcsCtx.computeFiles(cvsFileFilter)),
           new HashSet(vcsCtx.getRootFiles()),
           new HashSet(vcsCtx.getExclusions()));
   contextCached = new WeakReference<Context>(ctx);
   contextNodesCached = new WeakReference<Node[]>(nodes);
   return ctx;
 }
 private static void showTopComponent(int id, Exception exception) {
   String name = "exception" + id;
   TopComponent c = NbComponents.findTopComponentByNameAndClass(name, TopComponent.class);
   if (c == null) {
     c =
         new TopComponent() {
           @Override
           public int getPersistenceType() {
             return TopComponent.PERSISTENCE_NEVER;
           }
         };
     c.setName(name);
     c.setDisplayName(exception.getClass().getSimpleName());
     c.setLayout(new BorderLayout());
     c.add(ExceptionPanel.create(exception), BorderLayout.CENTER);
     c.open();
   }
   c.requestActive();
 }
 private List<File> getFiles(TopComponent tc) {
   LOG.log(Level.FINER, " looking up files in tc {0} ", new Object[] {tc});
   DataObject tcDataObject = tc.getLookup().lookup(DataObject.class);
   if (tcDataObject == null) {
     boolean alreadyListening = false;
     Iterator<L> it = lookupListeners.iterator();
     synchronized (lookupListeners) {
       while (it.hasNext()) {
         L l = it.next();
         if (l.ref.get() == null) {
           l.r.removeLookupListener(l);
           it.remove();
         }
         if (l.ref.get() == tc) {
           alreadyListening = true;
           break;
         }
       }
     }
     if (!alreadyListening) {
       addLookupListener(tc);
     }
     return Collections.EMPTY_LIST;
   } else {
     try {
       return hasOpenedEditorPanes(tcDataObject)
           ? getFiles(tcDataObject)
           : Collections.EMPTY_LIST;
     } catch (InterruptedException ex) {
       LOG.log(Level.WARNING, null, ex);
     } catch (InvocationTargetException ex) {
       LOG.log(Level.WARNING, null, ex);
     }
   }
   return Collections.EMPTY_LIST;
 }
Beispiel #30
0
  public void showTopComponent() {
    if (m_topComponent == null) {
      m_topComponent = getTopComponent();
      m_topComponent.open();
    }

    if (m_topComponent != null) {
      if (!m_topComponent.isOpened()) {
        m_topComponent = getTopComponent();
        m_topComponent.open();
      }

      m_topComponent.requestActive();

      // repeated on purpose to assert the display name
      m_topComponent.requestActive();

      m_topComponent.setDisplayName(m_name);
    }
  }