/* License: MIT */ package org.autoplot.dfc; import java.awt.Window; import java.util.List; import java.util.Map; import javax.swing.JOptionPane; import javax.swing.JPanel; import org.autoplot.datasource.DataSourceEditorPanel; import org.autoplot.datasource.URISplit; import org.das2.util.catalog.DasNode; import org.das2.util.catalog.DasNodeFactory; import org.das2.util.monitor.NullProgressMonitor; import org.das2.util.monitor.ProgressMonitor; /** * * @author cwp */ public class DfcSourceEditorPanel extends javax.swing.JPanel implements DataSourceEditorPanel { private DasNode nodeCur; private DasNode nodeRoot; private Map paramCur; private String sCurUri; /** * Creates new form Das2CatSourceEditorPanel */ public DfcSourceEditorPanel() { initComponents(); } /** * 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. */ @SuppressWarnings("unchecked") // //GEN-BEGIN:initComponents private void initComponents() { btnGroupRoot = new javax.swing.ButtonGroup(); tabbedPane = new javax.swing.JTabbedPane(); tabNav = new javax.swing.JPanel(); jPanel1 = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); jRadioButton1 = new javax.swing.JRadioButton(); jRadioButton2 = new javax.swing.JRadioButton(); jRadioButton3 = new javax.swing.JRadioButton(); jTextField1 = new javax.swing.JTextField(); jScrollPane3 = new javax.swing.JScrollPane(); jTree2 = new javax.swing.JTree(); tabSrc = new javax.swing.JPanel(); lblNodeOrigin = new javax.swing.JLabel(); jScrollPane1 = new javax.swing.JScrollPane(); jTextArea1 = new javax.swing.JTextArea(); pnlBottom = new javax.swing.JPanel(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); tabbedPane.setMaximumSize(new java.awt.Dimension(8000, 8000)); jLabel1.setText("Catalog:"); btnGroupRoot.add(jRadioButton1); jRadioButton1.setSelected(true); jRadioButton1.setText("Main"); jRadioButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton1ActionPerformed(evt); } }); btnGroupRoot.add(jRadioButton2); jRadioButton2.setText("Test"); btnGroupRoot.add(jRadioButton3); jRadioButton3.setText("Custom Root"); jRadioButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jRadioButton3ActionPerformed(evt); } }); jTextField1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jTextField1ActionPerformed(evt); } }); javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addComponent(jLabel1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jRadioButton1) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jRadioButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) .addComponent(jRadioButton3) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE) .addContainerGap()) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jLabel1) .addComponent(jRadioButton1) .addComponent(jRadioButton2) .addComponent(jRadioButton3) .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); jScrollPane3.setViewportView(jTree2); javax.swing.GroupLayout tabNavLayout = new javax.swing.GroupLayout(tabNav); tabNav.setLayout(tabNavLayout); tabNavLayout.setHorizontalGroup( tabNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(tabNavLayout.createSequentialGroup() .addGroup(tabNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(tabNavLayout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(tabNavLayout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane3))) .addContainerGap()) ); tabNavLayout.setVerticalGroup( tabNavLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(tabNavLayout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); tabbedPane.addTab("Select Source", tabNav); tabSrc.setLayout(new javax.swing.BoxLayout(tabSrc, javax.swing.BoxLayout.PAGE_AXIS)); lblNodeOrigin.setFont(new java.awt.Font("Dialog", 0, 12)); // NOI18N lblNodeOrigin.setText("tag:das2.org,2012:site:/uiowa/juno/wav/survey"); lblNodeOrigin.setFocusable(false); lblNodeOrigin.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); tabSrc.add(lblNodeOrigin); jTextArea1.setColumns(20); jTextArea1.setRows(5); jTextArea1.setTabSize(3); jScrollPane1.setViewportView(jTextArea1); tabSrc.add(jScrollPane1); tabbedPane.addTab("Query Options", tabSrc); jButton1.setText("Okay"); jButton2.setText("jButton2"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); javax.swing.GroupLayout pnlBottomLayout = new javax.swing.GroupLayout(pnlBottom); pnlBottom.setLayout(pnlBottomLayout); pnlBottomLayout.setHorizontalGroup( pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(pnlBottomLayout.createSequentialGroup() .addContainerGap(365, Short.MAX_VALUE) .addComponent(jButton2) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton1) .addGap(10, 10, 10)) ); pnlBottomLayout.setVerticalGroup( pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, pnlBottomLayout.createSequentialGroup() .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addGroup(pnlBottomLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton2) .addComponent(jButton1)) .addContainerGap()) ); javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(6, 6, 6) .addComponent(pnlBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addGap(5, 5, 5) .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(pnlBottom, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) .addContainerGap()) ); }// //GEN-END:initComponents private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButton1ActionPerformed {//GEN-HEADEREND:event_jRadioButton1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jRadioButton1ActionPerformed private void jRadioButton3ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jRadioButton3ActionPerformed {//GEN-HEADEREND:event_jRadioButton3ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jRadioButton3ActionPerformed private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jTextField1ActionPerformed {//GEN-HEADEREND:event_jTextField1ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jTextField1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButton2ActionPerformed {//GEN-HEADEREND:event_jButton2ActionPerformed // TODO add your handling code here: }//GEN-LAST:event_jButton2ActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.ButtonGroup btnGroupRoot; private javax.swing.JButton jButton1; private javax.swing.JButton jButton2; private javax.swing.JLabel jLabel1; private javax.swing.JPanel jPanel1; private javax.swing.JRadioButton jRadioButton1; private javax.swing.JRadioButton jRadioButton2; private javax.swing.JRadioButton jRadioButton3; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JScrollPane jScrollPane3; private javax.swing.JTextArea jTextArea1; private javax.swing.JTextField jTextField1; private javax.swing.JTree jTree2; private javax.swing.JLabel lblNodeOrigin; private javax.swing.JPanel pnlBottom; private javax.swing.JPanel tabNav; private javax.swing.JPanel tabSrc; private javax.swing.JTabbedPane tabbedPane; // End of variables declaration//GEN-END:variables // I think I am here because the data source factory rejected the given URL, so now // I, the GUI am asked to deal with it. @Override public boolean reject(String sFullUri) throws Exception { // We know how to deal with an empty resource URL, just pull the root nodes if(sFullUri.equals("vap+dc:")) return false; //URISplit split = URISplit.parse(sFullUri); // If this starts with one of the filsystem URLs, then it needs to handle the // completions first. //if ( split.file==null || split.file.equals("file:///") ) { // return false; //} throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } /** Gather any node definitions that will be needed for the dialog box * * URI examples that we may have to edit: * * vap+dc:tag:das2.org,2012:test:/swri/mars_express/aspera3/els?radius=2,3 * vap+dc:site:/uiowa/juno/survey/wav/das2?band=LFRL&time=2017-01-01,2017-01-02,60 * vap+dc:http://random.site.edu/~person/mysource.json?some_key=some_value * * @param sFullUri The full Autoplot URI, examples above * @param parent The window parent, in case we need to pop a dlg with a cancel button * @param mon A progress monitor * @return true, since at present there is no way to cancel * @throws Exception */ @Override public boolean prepare(String sFullUri, Window parent, ProgressMonitor mon) throws Exception { sCurUri = sFullUri; // Save off the full uri as a sanity check in setURI to make // sure I've prepared for the right thing URISplit split = URISplit.parse(sFullUri); String sNodeUrl = null; if( ! sFullUri.equals("vap+dc:")){ sNodeUrl = split.surl; } // Try to get a node definition nodeCur = DasNodeFactory.getNearestNode(sNodeUrl, mon, false /*don't force reload*/); if(nodeCur == null){ // Fall back to the root nodes, if that fails pop an error and give up. nodeCur = DasNodeFactory.getNearestNode(null, mon, false); if(nodeCur == null){ //Todo pop a cancel dialog??? String sMsg; if(sNodeUrl != null){ sMsg = "Couldn't find a catalog node at:
"+sNodeUrl+"
"; sMsg += "and fallback to catalog root definitions at:
"; sMsg += DasNodeFactory.defRootNodesAsStr(" ", "
"); sMsg += "
Failed."; } else{ sMsg = "Couldn't get root catalog definitions from:
"; sMsg += DasNodeFactory.defRootNodesAsStr(" ", "
"); } Object[] options = {"Cancel"}; JOptionPane.showOptionDialog( null, sMsg, "Connection Error", JOptionPane.DEFAULT_OPTION, JOptionPane.INFORMATION_MESSAGE, null, options, options[0] ); return false; } } // A root node has no parents, but that doesn't mean it's the global catalog root // that is a different concept. Note that getRootNode can return 'this'. if(!nodeCur.isRootNode()) nodeRoot = nodeCur.getRootNode(); return true; } /** Provides a starting full URI to the editor and trigger a runnable to show the * editor GUI. * * In general both the catalog panel and the source options panel are displayed * together, however if this is a standalone root of type source, that has no * parents, then only the source controls are displayed * @param uri */ @Override public void setURI(String sFullUri) { assert sFullUri.equals(sCurUri) : "URI changed after prepare"; // TODO: Prep the dialog } @Override public void markProblems(List problems) { // TODO: Add and problems with the URL you wish to specify. For now, // we surely have no problems ;) } @Override public JPanel getPanel() { return this; } @Override public String getURI() { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }