PageRenderTime 26ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/netbeans-7.3/mobility.project/src/org/netbeans/modules/mobility/project/ui/customizer/CustomizerDeploy.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 308 lines | 222 code | 24 blank | 62 comment | 39 complexity | fe3c4de09a6bd831ebdb5cc3fc7b92b9 MD5 | raw file
  1. /*
  2. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  3. *
  4. * Copyright 1997-2010 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. * Contributor(s):
  28. *
  29. * The Original Software is NetBeans. The Initial Developer of the Original
  30. * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
  31. * Microsystems, Inc. All Rights Reserved.
  32. *
  33. * If you wish your version of this file to be governed by only the CDDL
  34. * or only the GPL Version 2, indicate your decision by adding
  35. * "[Contributor] elects to include this software in this distribution
  36. * under the [CDDL or GPL Version 2] license." If you do not indicate a
  37. * single choice of license, a recipient has the option to distribute
  38. * your version of this file under either the CDDL, the GPL Version 2 or
  39. * to extend the choice of license to its licensees as provided above.
  40. * However, if you add GPL Version 2 code and therefore, elected the GPL
  41. * Version 2 license, then the option applies only if the new code is
  42. * made subject to such option by the copyright holder.
  43. */
  44. /*
  45. * Customizer.java
  46. *
  47. * Created on 23.Mar 2004, 11:31
  48. */
  49. package org.netbeans.modules.mobility.project.ui.customizer;
  50. import java.awt.Component;
  51. import java.awt.Container;
  52. import java.awt.event.ActionEvent;
  53. import java.awt.event.ActionListener;
  54. import java.util.ArrayList;
  55. import java.util.TreeMap;
  56. import java.util.Map;
  57. import java.util.Set;
  58. import javax.swing.JCheckBox;
  59. import javax.swing.JComboBox;
  60. import javax.swing.JPanel;
  61. import javax.swing.JRadioButton;
  62. import javax.swing.JSlider;
  63. import javax.swing.JSpinner;
  64. import javax.swing.text.JTextComponent;
  65. import org.netbeans.api.mobility.project.ui.customizer.ProjectProperties;
  66. import org.netbeans.modules.mobility.project.DefaultPropertiesDescriptor;
  67. import org.netbeans.modules.mobility.project.deployment.MobilityDeploymentManagerPanel;
  68. import org.netbeans.modules.mobility.project.deployment.MobilityDeploymentProperties;
  69. import org.netbeans.spi.mobility.deployment.DeploymentPlugin;
  70. import org.netbeans.spi.mobility.project.ui.customizer.CustomizerPanel;
  71. import org.netbeans.spi.mobility.project.ui.customizer.support.VisualPropertySupport;
  72. import org.netbeans.spi.mobility.project.ui.customizer.VisualPropertyGroup;
  73. import org.openide.util.Lookup;
  74. import org.openide.util.NbBundle;
  75. import org.openide.util.RequestProcessor;
  76. /**
  77. *
  78. * @author Adam Sotona
  79. */
  80. public class CustomizerDeploy extends JPanel implements CustomizerPanel, VisualPropertyGroup, ActionListener {
  81. private VisualPropertySupport vps;
  82. private boolean useDefault;
  83. private final String[] propertyGroup;
  84. private final String[] methodNames;
  85. private final Map<String,DeploymentPlugin> plugins;
  86. private MobilityDeploymentProperties mdp = new MobilityDeploymentProperties(new RequestProcessor());
  87. private String config;
  88. private ProjectProperties pp;
  89. private Component cComp = null;
  90. /** Creates new form CustomizerConfigs */
  91. public CustomizerDeploy() {
  92. initComponents();
  93. initAccessibility();
  94. ArrayList<String> propNames = new ArrayList<String>();
  95. plugins = new TreeMap<String,DeploymentPlugin>();
  96. propNames.add(DefaultPropertiesDescriptor.DEPLOYMENT_METHOD);
  97. propNames.add(DefaultPropertiesDescriptor.DEPLOYMENT_INSTANCE);
  98. for ( DeploymentPlugin p : Lookup.getDefault().lookup(new Lookup.Template<DeploymentPlugin>(DeploymentPlugin.class)).allInstances() )
  99. {
  100. plugins.put(p.getDeploymentMethodDisplayName(), p);
  101. propNames.addAll(p.getProjectPropertyDefaultValues().keySet());
  102. }
  103. propertyGroup = propNames.toArray(new String[propNames.size()]);
  104. methodNames = plugins.keySet().toArray(new String[plugins.size()]);
  105. jComboBoxMethod.addActionListener(this);
  106. jComboBoxInstance.addActionListener(this);
  107. }
  108. /** This method is called from within the constructor to
  109. * initialize the form.
  110. * WARNING: Do NOT modify this code. The content of this method is
  111. * always regenerated by the Form Editor.
  112. */
  113. // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  114. private void initComponents() {
  115. java.awt.GridBagConstraints gridBagConstraints;
  116. defaultCheck = new javax.swing.JCheckBox();
  117. jLabelMethod = new javax.swing.JLabel();
  118. jComboBoxMethod = new javax.swing.JComboBox();
  119. jLabelInstance = new javax.swing.JLabel();
  120. jComboBoxInstance = new javax.swing.JComboBox();
  121. jButtonManager = new javax.swing.JButton();
  122. jSeparator1 = new javax.swing.JSeparator();
  123. customPanel = new javax.swing.JPanel();
  124. setLayout(new java.awt.GridBagLayout());
  125. org.openide.awt.Mnemonics.setLocalizedText(defaultCheck, NbBundle.getMessage(CustomizerDeploy.class, "LBL_Use_Default")); // NOI18N
  126. defaultCheck.setMargin(new java.awt.Insets(0, 0, 0, 2));
  127. gridBagConstraints = new java.awt.GridBagConstraints();
  128. gridBagConstraints.gridx = 0;
  129. gridBagConstraints.gridy = 0;
  130. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  131. gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
  132. gridBagConstraints.weightx = 1.0;
  133. add(defaultCheck, gridBagConstraints);
  134. defaultCheck.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(CustomizerDeploy.class, "ACSN_CustDeploy_UseDefault")); // NOI18N
  135. defaultCheck.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(CustomizerDeploy.class, "ACSD_CustDeploy_UseDefault")); // NOI18N
  136. jLabelMethod.setLabelFor(jComboBoxMethod);
  137. org.openide.awt.Mnemonics.setLocalizedText(jLabelMethod, NbBundle.getMessage(CustomizerDeploy.class, "LBL_CustDeploy_Method")); // NOI18N
  138. gridBagConstraints = new java.awt.GridBagConstraints();
  139. gridBagConstraints.gridx = 0;
  140. gridBagConstraints.gridy = 1;
  141. gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
  142. gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
  143. add(jLabelMethod, gridBagConstraints);
  144. gridBagConstraints = new java.awt.GridBagConstraints();
  145. gridBagConstraints.gridx = 1;
  146. gridBagConstraints.gridy = 1;
  147. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  148. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  149. gridBagConstraints.weightx = 1.0;
  150. gridBagConstraints.insets = new java.awt.Insets(11, 5, 0, 0);
  151. add(jComboBoxMethod, gridBagConstraints);
  152. jComboBoxMethod.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerDeploy.class, "ACSD_Deployment_Method")); // NOI18N
  153. jLabelInstance.setLabelFor(jComboBoxInstance);
  154. org.openide.awt.Mnemonics.setLocalizedText(jLabelInstance, NbBundle.getMessage(CustomizerDeploy.class, "LBL_CustDeploy_DeploymentInstance")); // NOI18N
  155. gridBagConstraints = new java.awt.GridBagConstraints();
  156. gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
  157. gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
  158. add(jLabelInstance, gridBagConstraints);
  159. gridBagConstraints = new java.awt.GridBagConstraints();
  160. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  161. gridBagConstraints.weightx = 1.0;
  162. gridBagConstraints.insets = new java.awt.Insets(11, 5, 0, 0);
  163. add(jComboBoxInstance, gridBagConstraints);
  164. org.openide.awt.Mnemonics.setLocalizedText(jButtonManager, NbBundle.getMessage(CustomizerDeploy.class, "LBL_CustDeploy_Manage")); // NOI18N
  165. jButtonManager.addActionListener(new java.awt.event.ActionListener() {
  166. public void actionPerformed(java.awt.event.ActionEvent evt) {
  167. manageDeployments(evt);
  168. }
  169. });
  170. gridBagConstraints = new java.awt.GridBagConstraints();
  171. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  172. gridBagConstraints.insets = new java.awt.Insets(11, 5, 0, 0);
  173. add(jButtonManager, gridBagConstraints);
  174. gridBagConstraints = new java.awt.GridBagConstraints();
  175. gridBagConstraints.gridx = 0;
  176. gridBagConstraints.gridy = 5;
  177. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  178. gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
  179. gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
  180. add(jSeparator1, gridBagConstraints);
  181. customPanel.setLayout(new java.awt.BorderLayout());
  182. gridBagConstraints = new java.awt.GridBagConstraints();
  183. gridBagConstraints.gridx = 0;
  184. gridBagConstraints.gridy = 6;
  185. gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
  186. gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
  187. gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
  188. gridBagConstraints.weightx = 1.0;
  189. gridBagConstraints.weighty = 1.0;
  190. gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
  191. add(customPanel, gridBagConstraints);
  192. }// </editor-fold>//GEN-END:initComponents
  193. private void manageDeployments(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_manageDeployments
  194. String newSelection = MobilityDeploymentManagerPanel.manageDeployment((String) jComboBoxMethod.getSelectedItem(), (String) jComboBoxInstance.getSelectedItem());//GEN-LAST:event_manageDeployments
  195. mdp = new MobilityDeploymentProperties();
  196. initGroupValues(useDefault);
  197. if (newSelection != null) jComboBoxInstance.setSelectedItem(newSelection);
  198. }
  199. private void initAccessibility() {
  200. getAccessibleContext().setAccessibleName(NbBundle.getMessage(CustomizerRun.class, "ACSN_CustDeploy"));
  201. getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(CustomizerRun.class, "ACSD_CustDeploy"));
  202. }
  203. public void initValues(ProjectProperties props, String configuration) {
  204. for ( DeploymentPlugin p : Lookup.getDefault().lookup(new Lookup.Template<DeploymentPlugin>(DeploymentPlugin.class)).allInstances() ){
  205. if (p instanceof CustomizerPanel){
  206. ((CustomizerPanel)p).initValues(props, configuration);
  207. }
  208. }
  209. this.vps = VisualPropertySupport.getDefault(props);
  210. pp=props;
  211. config=configuration;
  212. vps.register(defaultCheck, configuration, this);
  213. }
  214. public String[] getGroupPropertyNames() {
  215. return propertyGroup;
  216. }
  217. public void initGroupValues(final boolean useDefault) {
  218. this.useDefault = useDefault;
  219. vps.register(jComboBoxMethod, methodNames, DefaultPropertiesDescriptor.DEPLOYMENT_METHOD, useDefault);
  220. jLabelMethod.setEnabled(!useDefault);
  221. actionPerformed(null);
  222. }
  223. public void actionPerformed(final ActionEvent e) {
  224. final String method = (String)jComboBoxMethod.getSelectedItem();
  225. final DeploymentPlugin p = method == null ? null : plugins.get(method);
  226. if (e == null || e.getSource().equals(jComboBoxMethod))
  227. {
  228. boolean supportsInstances = p != null && p.getGlobalPropertyDefaultValues().size() > 0;
  229. vps.register(jComboBoxInstance, supportsInstances ? mdp.getInstanceList(p.getDeploymentMethodName()).toArray() : new String[0], DefaultPropertiesDescriptor.DEPLOYMENT_INSTANCE, useDefault);
  230. jLabelInstance.setEnabled(!useDefault&&supportsInstances);
  231. jComboBoxInstance.setEnabled(!useDefault&&supportsInstances);
  232. jButtonManager.setEnabled(!useDefault&&supportsInstances);
  233. }
  234. if (e == null || e.getSource().equals(jComboBoxMethod) || e.getSource().equals(jComboBoxInstance)) {
  235. cComp = p == null ? null : p.createProjectCustomizerPanel();
  236. if (cComp != null)
  237. {
  238. if (cComp instanceof CustomizerPanel)
  239. ((CustomizerPanel)cComp).initValues(pp,config);
  240. registerSubcomponents(cComp, p.getProjectPropertyDefaultValues().keySet());
  241. }
  242. //To avoid screen flickering
  243. customPanel.setVisible(false);
  244. customPanel.removeAll();
  245. if (cComp != null) customPanel.add(cComp);
  246. customPanel.setVisible(true);
  247. customPanel.repaint();
  248. customPanel.validate();
  249. }
  250. }
  251. private void registerSubcomponents(final Component c, final Set propertyNames) {
  252. final String prop = c.getName();
  253. if (prop != null && propertyNames.contains(prop)) {
  254. if (c instanceof JCheckBox) {
  255. vps.register((JCheckBox)c, prop, useDefault);
  256. } else if (c instanceof JRadioButton) {
  257. vps.register((JRadioButton)c, prop, useDefault);
  258. } else if (c instanceof JComboBox) {
  259. vps.register((JComboBox)c, null, prop, useDefault);
  260. } else if (c instanceof JSlider) {
  261. vps.register((JSlider)c, prop, useDefault);
  262. } else if (c instanceof JSpinner) {
  263. vps.register((JSpinner)c, prop, useDefault);
  264. } else if (c instanceof JTextComponent) {
  265. vps.register((JTextComponent)c, prop, useDefault);
  266. } else assert false : "Unknown component type for registration"; //NOI18N
  267. }
  268. if (c instanceof Container) {
  269. final Component sub[] = ((Container)c).getComponents();
  270. for (int i=0; i<sub.length; i++) registerSubcomponents(sub[i], propertyNames);
  271. }
  272. if (useDefault) c.setEnabled(false);
  273. }
  274. // Variables declaration - do not modify//GEN-BEGIN:variables
  275. private javax.swing.JPanel customPanel;
  276. private javax.swing.JCheckBox defaultCheck;
  277. private javax.swing.JButton jButtonManager;
  278. private javax.swing.JComboBox jComboBoxInstance;
  279. private javax.swing.JComboBox jComboBoxMethod;
  280. private javax.swing.JLabel jLabelInstance;
  281. private javax.swing.JLabel jLabelMethod;
  282. private javax.swing.JSeparator jSeparator1;
  283. // End of variables declaration//GEN-END:variables
  284. }