/* Copyright (C) 2019 Chris Piker, Jeremy Faden * * This package, org.autoplot.dfc, is part Autoplot . It provides an * interface to the Das2 Federated Catalog (DFC) system. * * Autoplot is open source */ package org.autoplot.fdc; import java.awt.Window; import java.util.List; import java.util.Map; import javax.swing.JOptionPane; import javax.swing.JPanel; import org.autoplot.datasource.DataSetURI; import org.autoplot.datasource.DataSourceEditorPanel; import org.autoplot.datasource.URISplit; import org.das2.catalog.DasNode; import org.das2.catalog.DasNodeFactory; import org.das2.util.filesystem.FileSystem; import org.das2.util.monitor.NullProgressMonitor; import org.das2.util.monitor.ProgressMonitor; /** * * @author cwp */ public class FedCatSourceEditorPanel extends javax.swing.JPanel implements DataSourceEditorPanel { private DasNode nodeCur; private DasNode nodeRoot; private Map paramCur; private String sCurUri; /** * Creates new form FedCatSourceEditorPanel */ public FedCatSourceEditorPanel() { 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); // The split function above will represent the node url as a file item so pull that String sCatPath = split.file; // If this starts with a known das top-branch catalog, or one of it's convienence // strings, we can resolve it to something if((sCatPath.startsWith(DasNodeFactory.dasRootPath())) || sCatPath.startsWith("site:") || sCatPath.startsWith("test:") ) return false; // FIXME: For regular filesystem URLs I don't know if this URL is bad unless I // download the object and inspect it. But there is no progress monitor here // so I'm probably not supposed to do that. Not sure what to do and so have just // copied in code from CdfDataSourceEditoryPanel. --cwp 2019-11-10 if( split.resourceUri==null) return true; FileSystem fs = FileSystem.create( DataSetURI.getWebURL( DataSetURI.toUri(split.path) ).toURI() ); return fs.isDirectory( split.file.substring(split.path.length()) ); } /** 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); // Try to get a node definition, this version will fail if there is a system // that selects das2 catalog node definitions using HTTP GET parameters, as these // will be interpreted as data select parameters. nodeCur = DasNodeFactory.getNearestNode(split.file, mon, false /*don't force reload ?*/); 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 sFullUri */ @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. } }