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: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.j2ee.jboss4.ide.ui;
042:
043: import java.awt.Component;
044: import java.io.File;
045: import java.io.IOException;
046: import java.util.HashSet;
047: import java.util.Iterator;
048: import java.util.MissingResourceException;
049: import java.util.Set;
050: import javax.swing.event.ChangeEvent;
051: import javax.swing.event.ChangeListener;
052: import org.netbeans.modules.j2ee.deployment.impl.ServerInstance;
053: import org.netbeans.modules.j2ee.deployment.impl.ServerRegistry;
054: import org.openide.WizardDescriptor;
055: import org.openide.util.HelpCtx;
056: import org.openide.util.NbBundle;
057:
058: /**
059: *
060: * @author Ivan Sidorkin
061: */
062: public class AddServerPropertiesPanel implements
063: WizardDescriptor.Panel, ChangeListener {
064:
065: private final static String PROP_ERROR_MESSAGE = "WizardPanel_errorMessage"; // NOI18N
066: private WizardDescriptor wizard;
067: private AddServerPropertiesVisualPanel component;
068: private JBInstantiatingIterator instantiatingIterator;
069:
070: /** Creates a new instance of AddServerPropertiesPanel */
071: public AddServerPropertiesPanel(
072: JBInstantiatingIterator instantiatingIterator) {
073: this .instantiatingIterator = instantiatingIterator;
074: }
075:
076: public boolean isValid() {
077: AddServerPropertiesVisualPanel panel = (AddServerPropertiesVisualPanel) getComponent();
078:
079: String host = panel.getHost();
080: String port = panel.getPort();
081:
082: if (panel.isLocalServer()) {
083: // wrong domain path
084: String path = panel.getDomainPath();
085: File serverDirectory = new File(JBPluginProperties
086: .getInstance().getInstallLocation());
087:
088: if (!JBPluginUtils.isGoodJBInstanceLocation(
089: serverDirectory, new File(path))) {
090: wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle
091: .getMessage(AddServerPropertiesPanel.class,
092: "MSG_WrongDomainPath"));
093: return false;
094: }
095:
096: ServerInstance[] si = ServerRegistry.getInstance()
097: .getServerInstances();
098:
099: for (int i = 0; i < si.length; i++) {
100: try {
101: String property = si[i]
102: .getInstanceProperties()
103: .getProperty(
104: JBPluginProperties.PROPERTY_SERVER_DIR);
105:
106: if (property == null)
107: continue;
108:
109: String root = new File(property).getCanonicalPath();
110:
111: if (root.equals(new File(path).getCanonicalPath())) {
112: wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle
113: .getMessage(
114: AddServerPropertiesPanel.class,
115: "MSG_InstanceExists"));
116: return false;
117: }
118: } catch (MissingResourceException ex) {
119: // It's normal behaviour when si[i] is something else then jboss instance
120: continue;
121: } catch (IOException ex) {
122: // It's normal behaviour when si[i] is something else then jboss instance
123: continue;
124: }
125: }
126:
127: try {
128: new Integer(port);
129: } catch (Exception e) {
130: wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle
131: .getMessage(AddServerPropertiesPanel.class,
132: "MSG_InvalidPort"));
133: return false;
134: }
135:
136: } else { //remote
137: if ((host.equals(""))) {
138: wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle
139: .getMessage(AddServerPropertiesPanel.class,
140: "MSG_EnterHost"));
141: return false;
142: }
143: if (port.equals("")) {
144: wizard.putProperty(PROP_ERROR_MESSAGE, NbBundle
145: .getMessage(AddServerPropertiesPanel.class,
146: "MSG_EnterPort"));
147: return false;
148: }
149: }
150:
151: wizard.putProperty(PROP_ERROR_MESSAGE, null);
152:
153: // JBTargetServerData ts = JBPluginProperties.getInstance().getTargetServerData();
154: instantiatingIterator.setHost(host);
155: instantiatingIterator.setPort(port);
156: instantiatingIterator.setServer(panel.getDomain());
157: instantiatingIterator.setServerPath(panel.getDomainPath());
158: instantiatingIterator.setDeployDir(JBPluginUtils
159: .getDeployDir(panel.getDomainPath()));
160:
161: JBPluginProperties.getInstance().setDomainLocation(
162: panel.getDomainPath());
163:
164: return true;
165: }
166:
167: public Component getComponent() {
168: if (component == null) {
169: component = new AddServerPropertiesVisualPanel();
170: component.addChangeListener(this );
171: }
172: return component;
173: }
174:
175: public void stateChanged(ChangeEvent ev) {
176: fireChangeEvent(ev);
177: }
178:
179: private void fireChangeEvent(ChangeEvent ev) {
180: //@todo implement it
181: Iterator it;
182: synchronized (listeners) {
183: it = new HashSet(listeners).iterator();
184: }
185: while (it.hasNext()) {
186: ((ChangeListener) it.next()).stateChanged(ev);
187: }
188: }
189:
190: private transient Set listeners = new HashSet(1);
191:
192: public void removeChangeListener(ChangeListener l) {
193: synchronized (listeners) {
194: listeners.remove(l);
195: }
196: }
197:
198: public void addChangeListener(ChangeListener l) {
199: synchronized (listeners) {
200: listeners.add(l);
201: }
202: }
203:
204: public void readSettings(Object settings) {
205: if (wizard == null)
206: wizard = (WizardDescriptor) settings;
207: }
208:
209: public void storeSettings(Object settings) {
210: }
211:
212: public HelpCtx getHelp() {
213: return new HelpCtx(
214: "j2eeplugins_registering_app_server_jboss_properties"); //NOI18N
215: }
216:
217: void installLocationChanged() {
218: if (component != null)
219: component.installLocationChanged();
220: }
221: }
|