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-2007 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.xslt.project.wizard.element;
042:
043: import java.awt.GridBagConstraints;
044: import java.awt.GridBagLayout;
045: import java.awt.Insets;
046: import java.awt.event.ActionEvent;
047: import java.awt.event.ItemEvent;
048: import java.awt.event.ItemListener;
049: import java.util.List;
050:
051: import javax.swing.JButton;
052: import javax.swing.JComboBox;
053: import javax.swing.JLabel;
054: import javax.swing.JPanel;
055:
056: import org.openide.filesystems.FileObject;
057: import org.netbeans.api.project.Project;
058: import org.netbeans.modules.xml.catalogsupport.util.ProjectUtilities;
059: import org.netbeans.modules.xml.catalogsupport.util.ProjectWSDL;
060: import org.netbeans.modules.xml.wsdl.model.visitor.WSDLUtilities;
061: import static org.netbeans.modules.soa.ui.util.UI.*;
062:
063: /**
064: * @author Vladimir Yaroslavskiy
065: * @version 2007.01.30
066: */
067: final class PanelWebService<T> extends Panel<T> {
068:
069: PanelWebService(Project project, Panel<T> parent) {
070: this (project, parent, null);
071: }
072:
073: PanelWebService(Project project, Panel<T> parent,
074: String alternativeLabel) {
075: super (project, parent);
076: myFileLabelString = alternativeLabel;
077: }
078:
079: @Override
080: protected String getError() {
081: myFile = getWSDL();
082:
083: if (myFile == null) {
084: return i18n("ERR_Web_Service_Is_Required"); // NOI18N
085: }
086: return null;
087: }
088:
089: @Override
090: protected Object getResult() {
091: return WSDLUtilities.getWSDLModel(myFile);
092: }
093:
094: @Override
095: protected void createPanel(JPanel mainPanel, GridBagConstraints cc) {
096: JPanel panel = new JPanel(new GridBagLayout());
097: GridBagConstraints c = new GridBagConstraints();
098: c.anchor = GridBagConstraints.WEST;
099:
100: // label
101: c.gridy++;
102: c.weightx = 0.0;
103: c.fill = GridBagConstraints.NONE;
104: c.insets = new Insets(TINY_INSET, 0, TINY_INSET, 0);
105: if (myFileLabelString == null) {
106: myFileLabelString = i18n("LBL_Web_Service_File");
107: }
108: myFileLabel = createLabel(myFileLabelString); // NOI18N
109: a11y(myFileLabel, "ACSN_LBL_Web_Service_File",
110: "ACSD_LBL_Web_Service_File");
111: panel.add(myFileLabel, c);
112:
113: // wsdl
114: c.weightx = 1.0;
115: c.fill = GridBagConstraints.HORIZONTAL;
116: c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
117: myWSDL = new JComboBox();
118: myWSDL.setRenderer(new Renderer());
119: myFileLabel.setLabelFor(myWSDL);
120: panel.add(myWSDL, c);
121:
122: // [browse]
123: c.weightx = 0.0;
124: c.fill = GridBagConstraints.NONE;
125: c.insets = new Insets(TINY_INSET, SMALL_INSET, TINY_INSET, 0);
126: myBrowse = createButton(new ButtonAction(
127: i18n("LBL_Browse_WSDL"), // NOI18N
128: i18n("TLT_Browse_WSDL")) { // NOI18N
129: public void actionPerformed(ActionEvent event) {
130: printInformation( // to do m
131: "Dialog will be implemented by xml team," + // NOI18N
132: " see issue 93596."); // NOI18N
133: }
134: });
135: // panel.add(myBrowse, c);
136: mainPanel.add(panel, cc);
137: update();
138: }
139:
140: private ItemListener createItemListener(final boolean existing) {
141: return new ItemListener() {
142: public void itemStateChanged(ItemEvent event) {
143: setEnabled(existing);
144: }
145: };
146: }
147:
148: @Override
149: protected void setEnabled(boolean enabled) {
150: myWSDL.setEnabled(enabled);
151: myBrowse.setEnabled(enabled);
152: myFileLabel.setEnabled(enabled);
153: }
154:
155: @Override
156: protected void update() {
157: myWSDL.removeAllItems();
158: List<ProjectWSDL> wsdls = ProjectUtilities
159: .getProjectWSDLRecursively(getProject());
160:
161: for (ProjectWSDL wsdl : wsdls) {
162: myWSDL.addItem(wsdl);
163: }
164: }
165:
166: private FileObject getWSDL() {
167: if (myWSDL.getItemCount() == 0) {
168: return null;
169: }
170: return ((ProjectWSDL) myWSDL.getSelectedItem()).getFile();
171: }
172:
173: private String myFileLabelString;
174: private JButton myBrowse;
175: private JComboBox myWSDL;
176: private JLabel myFileLabel;
177: private FileObject myFile;
178: }
|