View Javadoc

1   /*
2   Copyright (C) 2000 - 2007 Grid Systems, S.A.
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License, version 2, as
6   published by the Free Software Foundation.
7   
8   This program is distributed in the hope that it will be useful,
9   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12  
13  You should have received a copy of the GNU General Public License
14  along with this program; if not, write to the Free Software
15  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17  
18  /*
19   * Project: KernelConfigurator
20   * Created on 02-mar-2004
21   *
22   * Copyright (c)2003 Grid Systems
23   */
24  package com.gridsystems.config.modules.jvm;
25  
26  import java.util.List;
27  
28  import com.gridsystems.config.ConfiguratorModel;
29  import com.gridsystems.config.app.UI;
30  import com.gridsystems.config.tools.ErrorSupport;
31  import com.gridsystems.config.tools.PortVerifier;
32  import com.gridsystems.config.tools.console.AbstractConsoleView;
33  import com.gridsystems.config.tools.console.GroupField;
34  import com.gridsystems.config.tools.console.ValueField;
35  
36  /**
37   * Console View for the JVM Configurator.
38   *
39   * @author <a href="mailto:rruiz@gridsystems.com">Rodrigo Ruiz Aguayo</a>
40   * @version 1.0
41   */
42  public class JVMConsoleView extends AbstractConsoleView {
43    /**
44     * Minimum heap size.
45     */
46    ValueField fldMinHeap;
47  
48    /**
49     * Maximum heap size.
50     */
51    ValueField fldMaxHeap;
52  
53    /**
54     * Thread stack size.
55     */
56    ValueField fldStackSize;
57  
58    /**
59     * Proxy flag.
60     */
61    ValueField fldUseProxy;
62  
63    /**
64     * Proxy host address.
65     */
66    ValueField fldProxyHost;
67  
68    /**
69     * Proxy port.
70     */
71    ValueField fldProxyPort;
72  
73    /**
74     * Remote debugging flag.
75     */
76    ValueField fldDebugEnabled;
77  
78    /**
79     * Remote debugging port.
80     */
81    ValueField fldDebugPort;
82  
83    /**
84     * "Suspend at start" flag for remote debugging.
85     */
86    ValueField fldDebugSuspend;
87  
88    /**
89     * Creates a new instance bound to the specified configurator.
90     *
91     * @param config The configurator instance.
92     */
93    public JVMConsoleView(JVMConfigurator config) {
94      super(config);
95  
96      fldMinHeap = createValueField("fldMinHeap", null);
97      fldMaxHeap = createValueField("fldMaxHeap", null);
98      fldStackSize = createValueField("fldStackSize", null);
99      fldUseProxy = createBoolField("fldUseProxy");
100     fldProxyHost = createValueField("fldProxyHost", null);
101     fldProxyPort = createValueField("fldProxyPort", null);
102     fldDebugEnabled = createBoolField("fldDebugEnabled");
103     fldDebugPort = createValueField("fldDebugPort", null);
104     fldDebugSuspend = createBoolField("fldDebugSuspend");
105   }
106 
107   /**
108    * {@inheritDoc}
109    */
110   public String getTitle() {
111     return bundle.getString("config.name");
112   }
113 
114   /**
115    * {@inheritDoc}
116    */
117   public String getSubtitle() {
118     return bundle.getString("config.description");
119   }
120 
121   /**
122    * {@inheritDoc}
123    */
124   public void getValues(ConfiguratorModel model) {
125     JVMConfigModel data = (JVMConfigModel)model;
126 
127     fldMinHeap.setValue(data.getMinHeap());
128     fldMaxHeap.setValue(data.getMaxHeap());
129     fldStackSize.setValue(data.getStackSize());
130 
131     if (UI.isExpertMode()) {
132       fldUseProxy.setValue(data.getUseProxy());
133       fldProxyHost.setValue(data.getProxyHost());
134       fldProxyPort.setValue(data.getProxyPort());
135 
136       fldDebugEnabled.setValue(data.getDebugEnabled());
137       fldDebugPort.setValue(data.getDebugPort());
138       fldDebugSuspend.setValue(data.getDebugSuspend());
139     }
140   }
141 
142   /**
143    * {@inheritDoc}
144    */
145   public void setValues(ConfiguratorModel model) {
146     JVMConfigModel data = (JVMConfigModel)model;
147 
148     data.setValue("heap.min",   fldMinHeap.getValue());
149     data.setValue("heap.max",   fldMaxHeap.getValue());
150     data.setValue("stack.size", fldStackSize.getValue());
151 
152     if (UI.isExpertMode()) {
153       data.setValue("proxy.use",  fldUseProxy.getValue());
154       data.setValue("proxy.host", fldProxyHost.getValue());
155       data.setValue("proxy.port", fldProxyPort.getValue());
156 
157       data.setValue("debug.enable", fldDebugEnabled.getValue());
158       data.setValue("debug.port", fldDebugPort.getValue());
159       data.setValue("debug.suspend", fldDebugSuspend.getValue());
160     }
161   }
162 
163   /**
164    * {@inheritDoc}
165    */
166   protected void getContents(List<Object> contents) {
167     // Sets the field verifiers
168     ErrorSupport support = new ErrorSupport(this.getConfigurator());
169     support.addError("badMemSize1", "MinHeap: " + getString("errors.badMemSize"));
170     support.addError("badMemSize2", "MaxHeap: " + getString("errors.badMemSize"));
171     support.addError("badMemSize3", "StackSize: " + getString("errors.badMemSize"));
172     support.addError("badProxyPort", getString("errors.badProxyPort"));
173     support.addError("badDebugPort", getString("errors.badDebugPort"));
174 
175     fldMinHeap.setVerifier(new MemSizeVerifier(support, "badMemSize1"));
176     fldMaxHeap.setVerifier(new MemSizeVerifier(support, "badMemSize2"));
177     fldStackSize.setVerifier(new MemSizeVerifier(support, "badMemSize3", true));
178     fldProxyPort.setVerifier(new PortVerifier(support, "badProxyPort"));
179     fldDebugPort.setVerifier(new PortVerifier(support, "badDebugPort"));
180 
181     // Groups fields into logical areas
182     GroupField grpMemory = new GroupField(bundle, "pnlMemory.title");
183     grpMemory.addField(fldMinHeap);
184     grpMemory.addField(fldMaxHeap);
185     grpMemory.addField(fldStackSize);
186 
187     // Sets the form contents
188     contents.add(grpMemory);
189 
190     // Adds key mappings for fields edition
191     addKeyMapping(grpMemory);
192 
193     if (UI.isExpertMode()) {
194       GroupField grpProxy = new GroupField(bundle, "pnlProxy.title");
195       grpProxy.addField(fldUseProxy);
196       grpProxy.addField(fldProxyHost);
197       grpProxy.addField(fldProxyPort);
198 
199       GroupField grpDebug = new GroupField(bundle, "pnlDebug.title");
200       grpDebug.addField(fldDebugEnabled);
201       grpDebug.addField(fldDebugPort);
202       grpDebug.addField(fldDebugSuspend);
203 
204       contents.add("-");
205       contents.add(grpProxy);
206       contents.add("-");
207       contents.add(grpDebug);
208 
209       addKeyMapping(grpProxy);
210       addKeyMapping(grpDebug);
211     }
212   }
213 }