content: package com.japisoft.editix.action.xml;
  
  import java.awt.event.FocusEvent;
  import java.awt.event.FocusListener;
  
  import javax.swing.DefaultComboBoxModel;
  import javax.swing.JPanel;
  import javax.swing.event.PopupMenuEvent;
  import javax.swing.event.PopupMenuListener;
  
  import com.japisoft.framework.ui.text.FileTextField;
  import com.japisoft.framework.ui.text.PathBuilder;
  
  /**
  This program is available under two licenses : 
  
  1. For non commercial usage : 
  
  This program is free software: you can redistribute it and/or modify
  it under the terms of the GNU General Public License as published by
  the Free Software Foundation, either version 3 of the License, or
  (at your option) any later version.
  
  This program is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  GNU General Public License for more details.
  
  You should have received a copy of the GNU General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
  
  2. For commercial usage :
  
  You need to get a commercial license for source usage at : 
  
  http://www.editix.com/buy.html
  
  Copyright (c) 2018 Alexandre Brillant - JAPISOFT SARL - http://www.japisoft.com
  
  @author Alexandre Brillant - abrillant@japisoft.com
  @author JAPISOFT SARL - http://www.japisoft.com
  
  */
  public class UseDefaultPanel extends JPanel implements PopupMenuListener {
  
  	/** Creates new form UseDefaultPanel */
      public UseDefaultPanel( String element, String ext, PathBuilder builder ) {
          initComponents( element, ext, builder );
      }
      
      public void addNotify() {
      	super.addNotify();
      	tfRoot.addPopupMenuListener( this );
      }
  
  	public void removeNotify() {
  		super.removeNotify();
  		tfRoot.removePopupMenuListener( this );
  	}
  
  	public void popupMenuCanceled(PopupMenuEvent e) {
  	}
  
  	public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
  	}
  
  	public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
  		if ( delegateForRoots != null ) {
  			if ( ( lastPath == null ) || 
  					!( lastPath.equals( ftfFile.getText() ) ) ) {
  				if ( ftfFile.getText() != null ) {
  					// Fill it with the delegate
  					String[] content = delegateForRoots.getRoots( ftfFile.getText() );
  					if ( content != null && ( content.length > 0 ) ) {
  						tfRoot.setModel(
  							new DefaultComboBoxModel( content ) 
  						);
  						tfRoot.setSelectedIndex( 0 );
  					}
  				}
  			}
  			lastPath = ftfFile.getText();
  		}		
  	}
  
  	private String lastPath = null;
  	
  	private UseDefaultRootBuilder delegateForRoots;
  
  	public void setUseDefaultRootBuilder( UseDefaultRootBuilder delegate ) {
  		this.delegateForRoots = delegate;
  	}
  
  	public void setCurrentDirectory( String loc ) {
  		ftfFile.setCurrentDirectory( loc );
  	}
  
      /** This method is called from within the constructor to
       * initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is
       * always regenerated by the Form Editor. */
      private void initComponents( 
      		String element, 
      		String ext, 
      		PathBuilder builder ) {
      	jLabel1 = new javax.swing.JLabel();
          tfRoot = new javax.swing.JComboBox();
          tfRoot.setEditable( true );
          jLabel2 = new javax.swing.JLabel();
          ftfFile = new FileTextField( null, null, ext, builder );
          relPathCb = new javax.swing.JCheckBox();
          
          jLabel1.setText("Root Node");
          jLabel2.setText("External " + element );
  
          relPathCb.setSelected(true);
          relPathCb.setText("Relative Path");
          relPathCb.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
          relPathCb.setMargin(new java.awt.Insets(0, 0, 0, 0));
  
          org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
          this.setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
              .add(layout.createSequentialGroup()
                  .addContainerGap()
                  .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                      .add(tfRoot, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 326, Short.MAX_VALUE)
                      .add(jLabel1)
                      .add(jLabel2)
                      .add(ftfFile, 0, 326, Short.MAX_VALUE)
                      .add(relPathCb))
                  .addContainerGap())
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
              .add(layout.createSequentialGroup()
                  .addContainerGap()
                  .add(jLabel1)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(tfRoot, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(jLabel2)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(ftfFile, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                  .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                  .add(relPathCb)
                  .addContainerGap(109, Short.MAX_VALUE))
          );
  
      }// </editor-fold>
  
      // Variables declaration - do not modify
      public FileTextField ftfFile;
      private javax.swing.JLabel jLabel1;
      private javax.swing.JLabel jLabel2;
      public javax.swing.JComboBox tfRoot;
      public javax.swing.JCheckBox relPathCb;
      // End of variables declaration	
  	
  }
  