/* * The contents of this file are subject to the terms of the Common Development * and Distribution License (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at http://www.netbeans.org/cddl.html * or http://www.netbeans.org/cddl.txt. * * When distributing Covered Code, include this CDDL Header Notice in each file * and include the License file at http://www.netbeans.org/cddl.txt. * If applicable, add the following below the CDDL Header, with the fields * enclosed by brackets [] replaced by your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * The Original Software is NetBeans. The Initial Developer of the Original * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.modules.gwt4nb.services; import java.util.List; import javax.swing.DefaultComboBoxModel; import javax.swing.SwingUtilities; import javax.swing.event.DocumentEvent; import javax.swing.event.DocumentListener; import org.netbeans.modules.gwt4nb.GWTProjectInfo; import org.openide.util.NbBundle; /** * New GWT RPC service panel * * @author Tomasz.Slota@Sun.COM * @author see https://github.com/gwt4nb/gwt4nb/ * @author benno.markiewicz@googlemail.com (contributor) */ public class NewServicePanelVisual extends javax.swing.JPanel { private static final long serialVersionUID = 1; private final NewServicePanel controller; /** * Creates new form NewServicePanelVisual */ public NewServicePanelVisual(NewServicePanel controller) { this.controller = controller; initComponents(); final GWTProjectInfo pi = GWTProjectInfo.get(controller.getProject()); txtServiceName.getDocument().addDocumentListener(new ChangeListener()); txtSubpackage.getDocument().addDocumentListener(new ChangeListener()); List<String> modules = pi.getModules(); jComboBoxModule.setModel(new DefaultComboBoxModel(modules.toArray())); SwingUtilities.invokeLater(new Runnable(){ // Avoid endless loop @Override public void run() { update(); } }); } /** * @return class name of the synchronous service interface (without package) */ public String getServiceName(){ return txtServiceName.getText(); } /** * @return subpackage name (may also contain dots) */ public String getServiceSubpackage(){ return txtSubpackage.getText(); } /** * @return selected module name like "org.yournamehere.Main" */ public String getModuleName() { return (String) jComboBoxModule.getSelectedItem(); } public String getServletMapping(){ return txtServletMapping.getText(); } public boolean createUsageExample(){ return chkCreateExample.isSelected(); } private void update(){ String serviceName = txtServiceName.getText(); String subpackage = txtSubpackage.getText(); if(subpackage != null && !subpackage.equals("")){ // NOI18N subpackage += "."; // NOI18N } String module = (String) jComboBoxModule.getSelectedItem(); if (null != module) { String clientPckg = GWTProjectInfo.getClientPackage(module); String serverPckg = GWTProjectInfo.getServerPackage(module); String local = clientPckg + "." + subpackage + serviceName; // NOI18N String remote = serverPckg + "." + subpackage + serviceName + // NOI18N "Impl"; // NOI18N String async = clientPckg + "." + // NOI18N subpackage + serviceName + "Async"; // NOI18N txtLocalIFace.setText(local); txtAsyncIFace.setText(async); txtRemoteImpl.setText(remote); } else { txtLocalIFace.setText(""); txtAsyncIFace.setText(""); txtRemoteImpl.setText(""); } StringBuilder urlPattern = new StringBuilder(); if(txtSubpackage.getText().length()>0){ urlPattern.append(txtSubpackage.getText().toLowerCase()).append("/"); // NOI18N } urlPattern.append(txtServiceName.getText().toLowerCase()); txtServletMapping.setText(urlPattern.toString()); controller.fireChangeEvent(); } /** 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. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { lblServiceName = new javax.swing.JLabel(); txtServiceName = new javax.swing.JTextField(); lblLocalIFace = new javax.swing.JLabel(); lblRemoteImpl = new javax.swing.JLabel(); lblAsyncIFace = new javax.swing.JLabel(); txtAsyncIFace = new javax.swing.JTextField(); txtLocalIFace = new javax.swing.JTextField(); txtRemoteImpl = new javax.swing.JTextField(); lblServletMapping = new javax.swing.JLabel(); txtServletMapping = new javax.swing.JTextField(); chkCreateExample = new javax.swing.JCheckBox(); lblSubpackage = new javax.swing.JLabel(); txtSubpackage = new javax.swing.JTextField(); jLabelModule = new javax.swing.JLabel(); jComboBoxModule = new javax.swing.JComboBox(); setName(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "panelName")); // NOI18N lblServiceName.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.lblServiceName.text")); // NOI18N txtServiceName.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.txtServiceName.text")); // NOI18N lblLocalIFace.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.lblLocalIFace.text")); // NOI18N lblRemoteImpl.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.lblRemoteImpl.text")); // NOI18N lblAsyncIFace.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.lblAsyncIFace.text")); // NOI18N txtAsyncIFace.setEditable(false); txtAsyncIFace.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.txtAsyncIFace.text")); // NOI18N txtLocalIFace.setEditable(false); txtLocalIFace.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.txtLocalIFace.text")); // NOI18N txtRemoteImpl.setEditable(false); txtRemoteImpl.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.txtRemoteImpl.text")); // NOI18N lblServletMapping.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.lblServletMapping.text")); // NOI18N txtServletMapping.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.txtServletMapping.text")); // NOI18N chkCreateExample.setSelected(true); chkCreateExample.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.chkCreateExample.text")); // NOI18N lblSubpackage.setText(NbBundle.getMessage(NewServicePanelVisual.class, "SUBPACKAGE")); // NOI18N jLabelModule.setText(org.openide.util.NbBundle.getMessage(NewServicePanelVisual.class, "NewServicePanelVisual.jLabelModule.text")); // NOI18N jComboBoxModule.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jComboBoxModuleActionPerformed(evt); } }); 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() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(chkCreateExample) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(lblLocalIFace) .add(lblAsyncIFace) .add(lblRemoteImpl) .add(lblServletMapping)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtServletMapping, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE) .add(txtAsyncIFace, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtRemoteImpl, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtLocalIFace, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE))) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(lblServiceName) .add(lblSubpackage) .add(jLabelModule)) .add(71, 71, 71) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(org.jdesktop.layout.GroupLayout.TRAILING, txtServiceName, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE) .add(txtSubpackage, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 360, Short.MAX_VALUE) .add(jComboBoxModule, 0, 360, Short.MAX_VALUE)))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING) .add(layout.createSequentialGroup() .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblServiceName) .add(txtServiceName, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(5, 5, 5) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblSubpackage) .add(txtSubpackage, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(4, 4, 4) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(jLabelModule) .add(jComboBoxModule, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(18, 18, 18) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING) .add(txtServletMapping, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(lblServletMapping)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblLocalIFace) .add(txtLocalIFace, 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(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(txtAsyncIFace, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE) .add(lblAsyncIFace)) .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED) .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE) .add(lblRemoteImpl) .add(txtRemoteImpl, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)) .add(13, 13, 13) .add(chkCreateExample) .addContainerGap(68, Short.MAX_VALUE)) ); }// </editor-fold>//GEN-END:initComponents private void jComboBoxModuleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jComboBoxModuleActionPerformed update(); }//GEN-LAST:event_jComboBoxModuleActionPerformed // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JCheckBox chkCreateExample; private javax.swing.JComboBox jComboBoxModule; private javax.swing.JLabel jLabelModule; private javax.swing.JLabel lblAsyncIFace; private javax.swing.JLabel lblLocalIFace; private javax.swing.JLabel lblRemoteImpl; private javax.swing.JLabel lblServiceName; private javax.swing.JLabel lblServletMapping; private javax.swing.JLabel lblSubpackage; private javax.swing.JTextField txtAsyncIFace; private javax.swing.JTextField txtLocalIFace; private javax.swing.JTextField txtRemoteImpl; private javax.swing.JTextField txtServiceName; private javax.swing.JTextField txtServletMapping; private javax.swing.JTextField txtSubpackage; // End of variables declaration//GEN-END:variables private class ChangeListener implements DocumentListener{ @Override public void insertUpdate(DocumentEvent arg0) { update(); } @Override public void removeUpdate(DocumentEvent arg0) { update(); } @Override public void changedUpdate(DocumentEvent arg0) { update(); } } }