001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.modules.profiler.j2ee.tomcat;
042:
043: import java.util.Iterator;
044: import java.util.List;
045: import javax.swing.JPanel;
046: import javax.swing.event.ChangeEvent;
047: import org.netbeans.lib.profiler.common.AttachSettings;
048: import org.netbeans.modules.profiler.attach.panels.AttachWizardPanel;
049: import org.netbeans.modules.profiler.attach.providers.TargetPlatform;
050: import org.netbeans.modules.profiler.attach.providers.TargetPlatformEnum;
051: import org.netbeans.modules.profiler.attach.providers.ValidationResult;
052: import org.netbeans.modules.profiler.attach.wizard.AttachWizardContext;
053: import org.openide.util.HelpCtx;
054:
055: /**
056: *
057: * @author Tomas Hurka
058: * @author Jaroslav Bachorik
059: */
060: public class TomcatIntegrationPanel extends AttachWizardPanel {
061: //~ Inner Classes ------------------------------------------------------------------------------------------------------------
062:
063: /* default */class Model {
064: //~ Instance fields ------------------------------------------------------------------------------------------------------
065:
066: private TargetPlatform.TargetPlatformFilter platformFilter = new TargetPlatform.TargetPlatformFilter() {
067: public boolean isSupported(TargetPlatform javaPlatform) {
068: AttachSettings settings = getContext()
069: .getAttachSettings();
070: TargetPlatformEnum jvm = javaPlatform.getAsEnum();
071:
072: if (!settings.isDirect()) {
073: if (settings.isDynamic16()) {
074: if (!jvm.equals(TargetPlatformEnum.JDK6)
075: && !jvm.equals(TargetPlatformEnum.JDK7)) {
076: return false;
077: }
078: } else {
079: return false;
080: }
081: }
082:
083: ;
084:
085: return getContext().getIntegrationProvider()
086: .supportsJVM(javaPlatform.getAsEnum());
087: }
088: };
089:
090: private String catalinaBase = ""; // NOI18N
091: private String catalinaHint = ""; // NOI18N
092: private String tomcatHint = ""; // NOI18N
093: private String tomcatInstall = ""; // NOI18N
094: private TargetPlatform selectedPlatform = null;
095: private boolean catalinaValid = true;
096: private boolean tomcatValid = false;
097:
098: //~ Methods --------------------------------------------------------------------------------------------------------------
099:
100: public void setCatalinaBase(String path) {
101: if (getContext() == null) {
102: return;
103: }
104:
105: ValidationResult result = ((AbstractTomcatIntegrationProvider) getContext()
106: .getIntegrationProvider())
107: .validateCatalinaBase(path);
108:
109: if (result.isValid()) {
110: this .catalinaValid = true;
111: this .catalinaHint = ""; // NOI18N
112: } else {
113: this .catalinaValid = false;
114: this .catalinaHint = result.getMessage();
115: }
116:
117: this .catalinaBase = path;
118: publishUpdate(new ChangeEvent(this ));
119: }
120:
121: public String getCatalinaBase() {
122: return this .catalinaBase;
123: }
124:
125: public String getCatalinaBaseHint() {
126: return this .catalinaHint;
127: }
128:
129: public boolean isCatalinaValid() {
130: return this .catalinaValid;
131: }
132:
133: public TargetPlatform.TargetPlatformFilter getPlatformFilter() {
134: return platformFilter;
135: }
136:
137: public TargetPlatformEnum getSelectedJVM() {
138: return this .selectedPlatform.getAsEnum();
139: }
140:
141: public void setSelectedPlatform(TargetPlatform platform) {
142: this .selectedPlatform = platform;
143: publishUpdate(new ChangeEvent(this ));
144: }
145:
146: public TargetPlatform getSelectedPlatform() {
147: return this .selectedPlatform;
148: }
149:
150: public void setTomcatInstall(String path) {
151: if (getContext() == null) {
152: return;
153: }
154:
155: String targetOS = getContext().getAttachSettings()
156: .getHostOS();
157:
158: ValidationResult result = ((AbstractTomcatIntegrationProvider) getContext()
159: .getIntegrationProvider()).validateInstallation(
160: targetOS, path);
161:
162: if (result.isValid()) {
163: this .tomcatValid = true;
164: this .tomcatHint = ""; // NOI18N
165: } else {
166: this .tomcatValid = false;
167: this .tomcatHint = result.getMessage();
168: }
169:
170: this .tomcatInstall = path;
171: publishUpdate(new ChangeEvent(this ));
172: }
173:
174: public String getTomcatInstall() {
175: return this .tomcatInstall;
176: }
177:
178: public String getTomcatInstallHint() {
179: return this .tomcatHint;
180: }
181:
182: public boolean isTomcatValid() {
183: return this .tomcatValid;
184: }
185: }
186:
187: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
188:
189: private static final String HELP_CTX_KEY = "TomcatIntegrationPanel.HelpCtx"; // NOI18N
190: private static final HelpCtx HELP_CTX = new HelpCtx(HELP_CTX_KEY);
191:
192: //~ Instance fields ----------------------------------------------------------------------------------------------------------
193:
194: private Model model = null;
195: private TomcatIntegrationPanelUI panel = null;
196:
197: //~ Constructors -------------------------------------------------------------------------------------------------------------
198:
199: public TomcatIntegrationPanel() {
200: this .model = new Model();
201: }
202:
203: //~ Methods ------------------------------------------------------------------------------------------------------------------
204:
205: public HelpCtx getHelp() {
206: return HELP_CTX;
207: }
208:
209: public boolean isValid() {
210: return this .model.isTomcatValid()
211: && this .model.isCatalinaValid()
212: && (this .model.getSelectedPlatform() != null);
213: }
214:
215: public boolean canBack(AttachWizardContext context) {
216: return true;
217: }
218:
219: public boolean canFinish(AttachWizardContext context) {
220: return false;
221: }
222:
223: public boolean canNext(AttachWizardContext context) {
224: return isValid();
225: }
226:
227: public boolean onCancel(AttachWizardContext context) {
228: return true;
229: }
230:
231: public void onEnter(AttachWizardContext context) {
232: model
233: .setCatalinaBase(((AbstractTomcatIntegrationProvider) context
234: .getIntegrationProvider()).getCatalinaBase());
235: model
236: .setTomcatInstall(((AbstractTomcatIntegrationProvider) context
237: .getIntegrationProvider())
238: .getInstallationPath());
239:
240: final String selectedJavaHome = ((AbstractTomcatIntegrationProvider) context
241: .getIntegrationProvider()).getTargetJava();
242: final List platformList = TargetPlatform.getPlatformList(false);
243:
244: for (Iterator it = platformList.iterator(); it.hasNext();) {
245: TargetPlatform platform = (TargetPlatform) it.next();
246:
247: if (platform.getHomePath().equals(selectedJavaHome)) {
248: model.setSelectedPlatform(platform);
249: }
250: }
251:
252: this .panel.loadModel();
253: }
254:
255: public void onExit(AttachWizardContext context) {
256: // setTrackUpdates(false);
257: // this.panel.setModelDefaults();
258: // setTrackUpdates(true);
259: AbstractTomcatIntegrationProvider provider = (AbstractTomcatIntegrationProvider) context
260: .getIntegrationProvider();
261: boolean isModified = false;
262:
263: if ((provider.getTargetJavaHome() != null)
264: && (this .model.getSelectedPlatform() != null)
265: && !provider.getTargetJavaHome().equals(
266: this .model.getSelectedPlatform().getHomePath())) {
267: isModified = true;
268: } else if (!provider.getCatalinaBase().equals(
269: this .model.getCatalinaBase())) {
270: isModified = true;
271: } else if (!provider.getInstallationPath().equals(
272: this .model.getTomcatInstall())) {
273: isModified = true;
274: }
275:
276: if (isModified) {
277: context.setConfigChanged();
278: }
279:
280: provider.setTargetPlatform(this .model.getSelectedPlatform());
281: provider.setCatalinaBase(this .model.getCatalinaBase());
282: provider.setInstallationPath(this .model.getTomcatInstall());
283: }
284:
285: public void onFinish(AttachWizardContext context) {
286: }
287:
288: protected JPanel getRenderPanel() {
289: if (this .panel == null) {
290: this .panel = new TomcatIntegrationPanelUI(this .model);
291: }
292:
293: return this .panel;
294: }
295:
296: protected void onPanelShow() {
297: panel.refreshJvmList(model.getSelectedPlatform());
298: }
299: }
|