PageRenderTime 24ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/projects/netbeans-7.3/php.project/src/org/netbeans/modules/php/project/ui/wizards/RunAsInternalServer.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 343 lines | 254 code | 34 blank | 55 comment | 11 complexity | 33ec7351b9fe2957dbcf18c365b582cb MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
  5. *
  6. * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  7. * Other names may be trademarks of their respective owners.
  8. *
  9. * The contents of this file are subject to the terms of either the GNU
  10. * General Public License Version 2 only ("GPL") or the Common
  11. * Development and Distribution License("CDDL") (collectively, the
  12. * "License"). You may not use this file except in compliance with the
  13. * License. You can obtain a copy of the License at
  14. * http://www.netbeans.org/cddl-gplv2.html
  15. * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  16. * specific language governing permissions and limitations under the
  17. * License. When distributing the software, include this License Header
  18. * Notice in each file and include the License file at
  19. * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
  20. * particular file as subject to the "Classpath" exception as provided
  21. * by Oracle in the GPL Version 2 section of the License file that
  22. * accompanied this code. If applicable, add the following below the
  23. * License Header, with the fields enclosed by brackets [] replaced by
  24. * your own identifying information:
  25. * "Portions Copyrighted [year] [name of copyright owner]"
  26. *
  27. * If you wish your version of this file to be governed by only the CDDL
  28. * or only the GPL Version 2, indicate your decision by adding
  29. * "[Contributor] elects to include this software in this distribution
  30. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  31. * single choice of license, a recipient has the option to distribute
  32. * your version of this file under either the CDDL, the GPL Version 2 or
  33. * to extend the choice of license to its licensees as provided above.
  34. * However, if you add GPL Version 2 code and therefore, elected the GPL
  35. * Version 2 license, then the option applies only if the new code is
  36. * made subject to such option by the copyright holder.
  37. *
  38. * Contributor(s):
  39. *
  40. * Portions Copyrighted 2012 Sun Microsystems, Inc.
  41. */
  42. package org.netbeans.modules.php.project.ui.wizards;
  43. import java.awt.event.ActionEvent;
  44. import java.awt.event.ActionListener;
  45. import java.io.File;
  46. import java.io.FileNotFoundException;
  47. import javax.swing.GroupLayout;
  48. import javax.swing.GroupLayout.Alignment;
  49. import javax.swing.JButton;
  50. import javax.swing.JComboBox;
  51. import javax.swing.JLabel;
  52. import javax.swing.JTextField;
  53. import javax.swing.LayoutStyle.ComponentPlacement;
  54. import javax.swing.event.ChangeListener;
  55. import javax.swing.event.DocumentListener;
  56. import org.netbeans.modules.php.project.PhpVisibilityQuery;
  57. import org.netbeans.modules.php.project.connections.ConfigManager;
  58. import org.netbeans.modules.php.project.runconfigs.RunConfigInternal;
  59. import org.netbeans.modules.php.project.ui.SourcesFolderProvider;
  60. import org.netbeans.modules.php.project.ui.Utils;
  61. import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
  62. import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties.RunAsType;
  63. import org.netbeans.modules.php.project.ui.customizer.RunAsPanel;
  64. import org.openide.awt.Mnemonics;
  65. import org.openide.util.ChangeSupport;
  66. import org.openide.util.Exceptions;
  67. import org.openide.util.NbBundle;
  68. /**
  69. * Configuration panel for internal web server.
  70. */
  71. public class RunAsInternalServer extends RunAsPanel.InsidePanel {
  72. private static final long serialVersionUID = -4154687891321321147L;
  73. final ChangeSupport changeSupport = new ChangeSupport(this);
  74. private final JLabel[] labels;
  75. private final JTextField[] textFields;
  76. private final String[] propertyNames;
  77. private final SourcesFolderProvider sourcesFolderProvider;
  78. public RunAsInternalServer(ConfigManager manager, SourcesFolderProvider sourcesFolderProvider) {
  79. super(manager);
  80. this.sourcesFolderProvider = sourcesFolderProvider;
  81. initComponents();
  82. this.labels = new JLabel[] {
  83. hostnameLabel,
  84. portLabel,
  85. routerLabel
  86. };
  87. this.textFields = new JTextField[] {
  88. hostnameTextField,
  89. portTextField,
  90. routerTextField
  91. };
  92. this.propertyNames = new String[] {
  93. PhpProjectProperties.HOSTNAME,
  94. PhpProjectProperties.PORT,
  95. PhpProjectProperties.ROUTER
  96. };
  97. assert labels.length == textFields.length && labels.length == propertyNames.length;
  98. for (int i = 0; i < textFields.length; i++) {
  99. DocumentListener dl = new FieldUpdater(propertyNames[i], labels[i], textFields[i]);
  100. textFields[i].getDocument().addDocumentListener(dl);
  101. }
  102. runAsComboBox.addActionListener(new ActionListener() {
  103. @Override
  104. public void actionPerformed(ActionEvent e) {
  105. changeSupport.fireChange();
  106. }
  107. });
  108. }
  109. @Override
  110. protected RunAsType getRunAsType() {
  111. return RunConfigInternal.getRunAsType();
  112. }
  113. @Override
  114. protected String getDisplayName() {
  115. return RunConfigInternal.getDisplayName();
  116. }
  117. @Override
  118. protected JLabel getRunAsLabel() {
  119. return runAsLabel;
  120. }
  121. @Override
  122. protected JComboBox getRunAsCombo() {
  123. return runAsComboBox;
  124. }
  125. @Override
  126. protected void loadFields() {
  127. for (int i = 0; i < textFields.length; i++) {
  128. String value = getValue(propertyNames[i]);
  129. if (value == null) {
  130. if (PhpProjectProperties.HOSTNAME.equals(propertyNames[i])) {
  131. value = RunConfigInternal.DEFAULT_HOSTNAME;
  132. } else if (PhpProjectProperties.PORT.equals(propertyNames[i])) {
  133. value = String.valueOf(RunConfigInternal.DEFAULT_PORT);
  134. }
  135. }
  136. textFields[i].setText(value);
  137. }
  138. }
  139. @Override
  140. protected void validateFields() {
  141. // validation is done in RunConfigurationPanel
  142. changeSupport.fireChange();
  143. }
  144. public void addRunAsInternalServerListener(ChangeListener listener) {
  145. changeSupport.addChangeListener(listener);
  146. }
  147. public void removeRunAsInternalServerListener(ChangeListener listener) {
  148. changeSupport.removeChangeListener(listener);
  149. }
  150. public RunConfigInternal createRunConfig() {
  151. return RunConfigInternal.create()
  152. .setHostname(hostnameTextField.getText())
  153. .setPort(portTextField.getText())
  154. .setWorkDir(getSources())
  155. .setDocumentRoot(getSources())
  156. .setRouterRelativePath(routerTextField.getText());
  157. }
  158. public void hideRouter() {
  159. routerLabel.setVisible(false);
  160. routerTextField.setVisible(false);
  161. routerBrowseButton.setVisible(false);
  162. }
  163. public void setHostname(String hostname) {
  164. hostnameTextField.setText(hostname);
  165. }
  166. public void setPort(String port) {
  167. portTextField.setText(port);
  168. }
  169. public void setRouter(String router) {
  170. routerTextField.setText(router);
  171. }
  172. private File getSources() {
  173. return sourcesFolderProvider.getSourcesFolder();
  174. }
  175. /**
  176. * 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
  177. * Editor.
  178. */
  179. @SuppressWarnings("unchecked")
  180. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  181. private void initComponents() {
  182. runAsLabel = new JLabel();
  183. runAsComboBox = new JComboBox();
  184. hostnameLabel = new JLabel();
  185. hostnameTextField = new JTextField();
  186. portLabel = new JLabel();
  187. portTextField = new JTextField();
  188. urlHintLabel = new JLabel();
  189. routerLabel = new JLabel();
  190. routerTextField = new JTextField();
  191. routerBrowseButton = new JButton();
  192. noteLabel = new JLabel();
  193. phpVersionInfoLabel = new JLabel();
  194. Mnemonics.setLocalizedText(runAsLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.runAsLabel.text")); // NOI18N
  195. Mnemonics.setLocalizedText(hostnameLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.hostnameLabel.text")); // NOI18N
  196. Mnemonics.setLocalizedText(portLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.portLabel.text")); // NOI18N
  197. Mnemonics.setLocalizedText(urlHintLabel, " "); // NOI18N
  198. Mnemonics.setLocalizedText(routerLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.routerLabel.text")); // NOI18N
  199. Mnemonics.setLocalizedText(routerBrowseButton, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.routerBrowseButton.text")); // NOI18N
  200. routerBrowseButton.addActionListener(new ActionListener() {
  201. public void actionPerformed(ActionEvent evt) {
  202. routerBrowseButtonActionPerformed(evt);
  203. }
  204. });
  205. Mnemonics.setLocalizedText(noteLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.noteLabel.text")); // NOI18N
  206. Mnemonics.setLocalizedText(phpVersionInfoLabel, NbBundle.getMessage(RunAsInternalServer.class, "RunAsInternalServer.phpVersionInfoLabel.text")); // NOI18N
  207. GroupLayout layout = new GroupLayout(this);
  208. this.setLayout(layout);
  209. layout.setHorizontalGroup(
  210. layout.createParallelGroup(Alignment.LEADING)
  211. .addGroup(layout.createSequentialGroup()
  212. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  213. .addComponent(routerLabel)
  214. .addComponent(portLabel)
  215. .addComponent(runAsLabel)
  216. .addComponent(hostnameLabel))
  217. .addPreferredGap(ComponentPlacement.RELATED)
  218. .addGroup(layout.createParallelGroup(Alignment.LEADING)
  219. .addGroup(layout.createSequentialGroup()
  220. .addComponent(routerTextField)
  221. .addPreferredGap(ComponentPlacement.RELATED)
  222. .addComponent(routerBrowseButton))
  223. .addGroup(layout.createSequentialGroup()
  224. .addComponent(urlHintLabel)
  225. .addContainerGap())
  226. .addComponent(runAsComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  227. .addComponent(hostnameTextField)
  228. .addGroup(layout.createSequentialGroup()
  229. .addComponent(portTextField, GroupLayout.PREFERRED_SIZE, 50, GroupLayout.PREFERRED_SIZE)
  230. .addGap(0, 0, Short.MAX_VALUE))))
  231. .addGroup(layout.createSequentialGroup()
  232. .addContainerGap()
  233. .addComponent(phpVersionInfoLabel)
  234. .addContainerGap())
  235. .addGroup(layout.createSequentialGroup()
  236. .addComponent(noteLabel)
  237. .addGap(0, 0, Short.MAX_VALUE))
  238. );
  239. layout.setVerticalGroup(
  240. layout.createParallelGroup(Alignment.LEADING)
  241. .addGroup(layout.createSequentialGroup()
  242. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  243. .addComponent(runAsLabel)
  244. .addComponent(runAsComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  245. .addGap(18, 18, 18)
  246. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  247. .addComponent(hostnameLabel)
  248. .addComponent(hostnameTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  249. .addPreferredGap(ComponentPlacement.RELATED)
  250. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  251. .addComponent(portLabel)
  252. .addComponent(portTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  253. .addPreferredGap(ComponentPlacement.RELATED)
  254. .addComponent(urlHintLabel)
  255. .addPreferredGap(ComponentPlacement.RELATED)
  256. .addGroup(layout.createParallelGroup(Alignment.BASELINE)
  257. .addComponent(routerLabel)
  258. .addComponent(routerTextField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  259. .addComponent(routerBrowseButton))
  260. .addGap(18, 18, 18)
  261. .addComponent(noteLabel)
  262. .addPreferredGap(ComponentPlacement.RELATED)
  263. .addComponent(phpVersionInfoLabel)
  264. .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
  265. );
  266. }// </editor-fold>//GEN-END:initComponents
  267. private void routerBrowseButtonActionPerformed(ActionEvent evt) {//GEN-FIRST:event_routerBrowseButtonActionPerformed
  268. try {
  269. Utils.browseFolderFile(PhpVisibilityQuery.getDefault(), getSources(), routerTextField);
  270. } catch (FileNotFoundException ex) {
  271. // cannot happen for sources
  272. Exceptions.printStackTrace(ex);
  273. }
  274. }//GEN-LAST:event_routerBrowseButtonActionPerformed
  275. // Variables declaration - do not modify//GEN-BEGIN:variables
  276. private JLabel hostnameLabel;
  277. private JTextField hostnameTextField;
  278. private JLabel noteLabel;
  279. private JLabel phpVersionInfoLabel;
  280. private JLabel portLabel;
  281. private JTextField portTextField;
  282. private JButton routerBrowseButton;
  283. private JLabel routerLabel;
  284. private JTextField routerTextField;
  285. private JComboBox runAsComboBox;
  286. private JLabel runAsLabel;
  287. private JLabel urlHintLabel;
  288. // End of variables declaration//GEN-END:variables
  289. //~ Inner classes
  290. private class FieldUpdater extends TextFieldUpdater {
  291. public FieldUpdater(String propName, JLabel label, JTextField field) {
  292. super(propName, label, field);
  293. }
  294. @Override
  295. protected final String getDefaultValue() {
  296. return RunAsInternalServer.this.getDefaultValue(getPropName());
  297. }
  298. @Override
  299. protected void processUpdate() {
  300. super.processUpdate();
  301. updateUrlHint();
  302. }
  303. // update hint & store project url as well (for running/debugging the project)
  304. private void updateUrlHint() {
  305. String url = createRunConfig().getUrlHint();
  306. urlHintLabel.setText(url != null ? url : " "); // NOI18N
  307. }
  308. }
  309. }