/* * Constellation - An open source and standard compliant SDI * http://www.constellation-sdi.org * * Copyright 2014 Geomatys. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.constellation.swing; import org.constellation.admin.service.ConstellationClient; import org.constellation.configuration.ProviderReport; import org.constellation.configuration.ProviderServiceReport; import org.constellation.configuration.ProvidersReport; import org.jdesktop.swingx.combobox.ListComboBoxModel; import org.openide.util.Exceptions; import org.openide.util.NbBundle; import javax.swing.*; import java.awt.*; import java.io.IOException; import java.util.ArrayList; import java.util.List; /** * * @author guilhem */ public class JEditSourcePane extends javax.swing.JPanel { private SourceModel sourceModel; /** * Creates new form JEditSourcePane * @param server * @param serviceType * @param sourceModel */ public JEditSourcePane(final ConstellationClient serverV2, final String serviceType, final SourceModel sourceModel) { this.sourceModel = sourceModel; initComponents(); //create combobox items (dataReference string) final List<String> providerList = new ArrayList<>(); try { final ProvidersReport providersReport = serverV2.providers.listProviders(); final List<ProviderServiceReport> servicesReport = providersReport.getProviderServices(); for(final ProviderServiceReport serviceReport : servicesReport) { final String serviceProviderType = serviceReport.getType(); final List<ProviderReport> providers = serviceReport.getProviders(); for (final ProviderReport providerReport : providers) { boolean addProviderToList = false; //WFS -> data-store if ( ("WFS".equals(serviceType) && "feature-store".equals(serviceProviderType)) ) { addProviderToList = true; } //WMTS or WCS -> coverage-store if ( ("WMTS".equals(serviceType) || "WCS".equals(serviceType) ) && "coverage-store".equals(serviceProviderType)) { addProviderToList = true; } //WMS -> all layer provider if ("WMS".equals(serviceType)) { addProviderToList = true; } if (addProviderToList) { providerList.add(providerReport.getId()); } } } guiSourceList.setModel(new ListComboBoxModel(providerList)); if (sourceModel != null) { guiSourceList.setSelectedItem(sourceModel.getProviderId()); guiLoadAllBox.setSelected(sourceModel.isLoadAll()); } } catch (IOException ex) { Exceptions.printStackTrace(ex); } } /** * 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") // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jLabel1 = new JLabel(); guiSourceList = new JComboBox(); jLabel2 = new JLabel(); guiLoadAllBox = new JCheckBox(); jLabel1.setText("Source"); jLabel2.setText(NbBundle.getMessage(JProviderEditPane.class, "loadAll")); // NOI18N GroupLayout layout = new GroupLayout(this); this.setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(jLabel1) .addComponent(jLabel2)) .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addComponent(guiLoadAllBox) .addGap(0, 0, Short.MAX_VALUE)) .addComponent(guiSourceList, 0, 369, Short.MAX_VALUE)) .addContainerGap()) ); layout.linkSize(SwingConstants.HORIZONTAL, new Component[] {jLabel1, jLabel2}); layout.setVerticalGroup( layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) .addComponent(guiSourceList, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addComponent(jLabel1)) .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED) .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) .addComponent(jLabel2) .addComponent(guiLoadAllBox)) .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) ); layout.linkSize(SwingConstants.VERTICAL, new Component[] {guiSourceList, jLabel1, jLabel2}); }// </editor-fold>//GEN-END:initComponents // Variables declaration - do not modify//GEN-BEGIN:variables private JCheckBox guiLoadAllBox; private JComboBox guiSourceList; private JLabel jLabel1; private JLabel jLabel2; // End of variables declaration//GEN-END:variables public SourceModel getSourceEntry() { if (sourceModel == null) { sourceModel = new SourceModel(); } sourceModel.setProviderId((String)guiSourceList.getSelectedItem()); sourceModel.setLoadAll(guiLoadAllBox.isSelected()); return sourceModel; } public static SourceModel showDialog(final ConstellationClient serverV2, final String serviceType, final SourceModel source) { final JEditSourcePane pane = new JEditSourcePane(serverV2, serviceType, source); int res = JOptionPane.showOptionDialog(null, new Object[]{pane}, LayerRowModel.BUNDLE.getString("createSourceMsg"), JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null, null, null); if (res == JOptionPane.CANCEL_OPTION || res == JOptionPane.CLOSED_OPTION) { return null; } return pane.getSourceEntry(); } }