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.sunas;
042:
043: import org.openide.util.HelpCtx;
044: import org.openide.util.NbBundle;
045: import java.util.Iterator;
046: import java.util.List;
047: import java.util.Vector;
048: import javax.swing.JPanel;
049: import javax.swing.event.ChangeEvent;
050: import org.netbeans.modules.profiler.attach.panels.AttachWizardPanel;
051: import org.netbeans.modules.profiler.attach.providers.TargetPlatform;
052: import org.netbeans.modules.profiler.attach.providers.ValidationResult;
053: import org.netbeans.modules.profiler.attach.wizard.AttachWizardContext;
054:
055: /**
056: *
057: * @author Jaroslav Bachorik
058: */
059: public class SunASIntegrationPanel extends AttachWizardPanel {
060: //~ Inner Classes ------------------------------------------------------------------------------------------------------------
061:
062: /*default*/class Model {
063: //~ Instance fields ------------------------------------------------------------------------------------------------------
064:
065: private List domains = null;
066: private String domain = ""; // NOI18N
067: private String installPath = ""; // NOI18N
068: private TargetPlatform targetPlatform;
069:
070: //~ Constructors ---------------------------------------------------------------------------------------------------------
071:
072: public Model() {
073: this .domains = new Vector();
074: targetPlatform = null;
075: }
076:
077: //~ Methods --------------------------------------------------------------------------------------------------------------
078:
079: public void setDomain(String domain) {
080: this .domain = domain;
081: publishUpdate(new ChangeEvent(this ));
082: }
083:
084: public String getDomain() {
085: return domain;
086: }
087:
088: public String getDomainHint() {
089: return domainHint;
090: }
091:
092: public List getDomains() {
093: return domains;
094: }
095:
096: public void setInstallPath(String installPath) {
097: SunASAutoIntegrationProvider provider = (SunASAutoIntegrationProvider) getContext()
098: .getIntegrationProvider();
099: String targetOS = getContext().getAttachSettings()
100: .getHostOS();
101:
102: ValidationResult validation = provider
103: .validateInstallation(targetOS, installPath);
104:
105: if (!validation.isValid()) {
106: hint = validation.getMessage();
107: domainHint = NbBundle
108: .getMessage(this .getClass(),
109: "SunAS8IntegrationProvider_InstallDirPendingMsg"); // NOI18N
110: } else {
111: hint = ""; // NOI18N
112: domainHint = ""; // NOI18N
113: }
114:
115: this .installPath = installPath;
116: updateDomains();
117: publishUpdate(new ChangeEvent(this ));
118: }
119:
120: public String getInstallPath() {
121: return installPath;
122: }
123:
124: public String getInstallPathHint() {
125: return hint;
126: }
127:
128: public TargetPlatform getSelectedPlatform() {
129: return targetPlatform;
130: }
131:
132: public void setTargetJava(TargetPlatform java) {
133: targetPlatform = java;
134: publishUpdate(new ChangeEvent(this ));
135: }
136:
137: private void updateDomains() {
138: SunASAutoIntegrationProvider provider = (SunASAutoIntegrationProvider) getContext()
139: .getIntegrationProvider();
140:
141: domains.clear();
142: domains.addAll(provider
143: .getAvailableDomains(this .installPath));
144:
145: if (((this .domain == null) || (this .domain.length() == 0))
146: && (this .domains.size() > 0)) {
147: this .domain = (String) this .domains.get(0);
148: } else if (this .domains.size() == 0) {
149: this .domain = null;
150: }
151: }
152: }
153:
154: //~ Static fields/initializers -----------------------------------------------------------------------------------------------
155:
156: private static final String HELP_CTX_KEY = "SunASIntegrationPanel.HelpCtx"; // NOI18N
157: private static final HelpCtx HELP_CTX = new HelpCtx(HELP_CTX_KEY);
158:
159: //~ Instance fields ----------------------------------------------------------------------------------------------------------
160:
161: private Model model = null;
162: private String domainHint = ""; // NOI18N
163: private String hint = ""; // NOI18N
164: private SunASIntegrationPanelUI panel = null;
165:
166: //~ Constructors -------------------------------------------------------------------------------------------------------------
167:
168: /** Creates a new instance of SunASIntegrationPanel */
169: public SunASIntegrationPanel() {
170: this .model = new Model();
171: }
172:
173: //~ Methods ------------------------------------------------------------------------------------------------------------------
174:
175: public HelpCtx getHelp() {
176: return HELP_CTX;
177: }
178:
179: public boolean isValid() {
180: return (this .model.getInstallPath() != null)
181: && (this .model.getInstallPath().length() > 0)
182: && (this .model.getDomain() != null)
183: && (this .model.getDomain().length() > 0)
184: && (this .model.getSelectedPlatform() != null);
185: }
186:
187: public boolean canBack(AttachWizardContext context) {
188: return true;
189: }
190:
191: public boolean canFinish(AttachWizardContext context) {
192: return false;
193: }
194:
195: public boolean canNext(AttachWizardContext context) {
196: return isValid();
197: }
198:
199: public boolean onCancel(AttachWizardContext context) {
200: return true;
201: }
202:
203: public void onEnter(AttachWizardContext context) {
204: if ((model.getDomain() == null)
205: || (model.getDomain().length() == 0)) {
206: model.setDomain(((SunASAutoIntegrationProvider) context
207: .getIntegrationProvider()).getDomain());
208: }
209:
210: if ((model.getInstallPath() == null)
211: || (model.getInstallPath().length() == 0)) {
212: model
213: .setInstallPath(((SunASAutoIntegrationProvider) context
214: .getIntegrationProvider())
215: .getInstallationPath());
216: }
217:
218: final String selectedJavaHome = ((SunASAutoIntegrationProvider) context
219: .getIntegrationProvider()).getTargetJava();
220: final List platformList = TargetPlatform.getPlatformList(false);
221:
222: for (Iterator it = platformList.iterator(); it.hasNext();) {
223: TargetPlatform platform = (TargetPlatform) it.next();
224:
225: if (platform.equals(selectedJavaHome)) {
226: model.setTargetJava(platform);
227:
228: break;
229: }
230: }
231:
232: panel.loadModel();
233: }
234:
235: public void onExit(AttachWizardContext context) {
236: SunASAutoIntegrationProvider provider = (SunASAutoIntegrationProvider) getContext()
237: .getIntegrationProvider();
238: boolean isModified = false;
239:
240: if (!provider.getInstallationPath().equals(
241: this .model.getInstallPath())) {
242: isModified = true;
243: } else if (!provider.getDomain().equals(this .model.getDomain())) {
244: isModified = true;
245: } else if ((provider.getTargetJavaHome() != null)
246: && (model.getSelectedPlatform() != null)
247: && !provider.getTargetJavaHome().equals(
248: this .model.getSelectedPlatform().getHomePath())) {
249: isModified = true;
250: }
251:
252: if (isModified) {
253: context.setConfigChanged();
254: }
255:
256: provider.setInstallationPath(this .model.getInstallPath());
257: provider.setDomain(this .model.getDomain());
258: provider.setTargetPlatform(this .model.getSelectedPlatform());
259: }
260:
261: public void onFinish(AttachWizardContext context) {
262: }
263:
264: protected JPanel getRenderPanel() {
265: if (panel == null) {
266: panel = new SunASIntegrationPanelUI(this .model);
267: }
268:
269: return panel;
270: }
271:
272: protected void onPanelShow() {
273: this.panel.refreshJvmList(model.getSelectedPlatform());
274: }
275: }
|