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:
042: /*
043: * EditWSAttributesCookieImpl.java
044: *
045: * Created on April 12, 2006, 10:13 AM
046: *
047: * To change this template, choose Tools | Template Manager
048: * and open the template in the editor.
049: */
050:
051: package org.netbeans.modules.websvc.core.wseditor.support;
052:
053: import java.awt.Cursor;
054: import java.awt.Dialog;
055: import java.awt.event.WindowAdapter;
056: import java.awt.event.WindowEvent;
057: import java.util.Collection;
058: import java.util.HashSet;
059: import java.util.Map;
060: import java.util.Set;
061: import java.util.WeakHashMap;
062: import javax.swing.JFrame;
063: import javax.swing.SwingUtilities;
064: import org.netbeans.modules.websvc.api.jaxws.project.config.JaxWsModel;
065: import org.netbeans.modules.websvc.core.wseditor.spi.WSEditor;
066: import org.netbeans.modules.websvc.core.wseditor.spi.WSEditorProvider;
067: import org.netbeans.modules.websvc.core.wseditor.spi.WSEditorProviderRegistry;
068: import org.openide.DialogDescriptor;
069: import org.openide.DialogDisplayer;
070: import org.openide.NotifyDescriptor;
071: import org.openide.nodes.Node;
072: import org.openide.util.HelpCtx;
073: import org.openide.util.Lookup;
074: import org.openide.windows.WindowManager;
075:
076: /**
077: *
078: * @author rico
079: */
080: public class EditWSAttributesCookieImpl implements
081: EditWSAttributesCookie {
082:
083: /** Creates a new instance of EditWSAttributesCookieImpl */
084: public EditWSAttributesCookieImpl(Node node, JaxWsModel jaxWsModel) {
085: this .node = node;
086: this .jaxWsModel = jaxWsModel;
087: }
088:
089: public void openWSAttributesEditor() {
090: if (SwingUtilities.isEventDispatchThread()) { //Ensure it is in AWT thread
091: openEditor();
092: } else {
093: SwingUtilities.invokeLater(new Runnable() {
094: public void run() {
095: openEditor();
096: }
097: });
098: }
099: }
100:
101: private void openEditor() {
102: final JFrame mainWin = (JFrame) WindowManager.getDefault()
103: .getMainWindow();
104: final Cursor origCursor = mainWin.getGlassPane().getCursor();
105: mainWin.getGlassPane().setCursor(
106: Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
107: mainWin.getGlassPane().setVisible(true);
108:
109: tc = cachedTopComponents.get(node);
110: if (tc == null) {
111: //populate the editor registry if needed
112: populateWSEditorProviderRegistry();
113: //get all providers
114: providers = WSEditorProviderRegistry.getDefault()
115: .getEditorProviders();
116: tc = new EditWSAttributesPanel();
117: cachedTopComponents.put(this , tc);
118: }
119: populatePanels();
120: tc.addTabs(editors, node, jaxWsModel);
121: DialogDescriptor dialogDesc = new DialogDescriptor(tc, node
122: .getName());
123: dialogDesc.setHelpCtx(new HelpCtx(
124: EditWSAttributesCookieImpl.class));
125: Dialog dialog = DialogDisplayer.getDefault().createDialog(
126: dialogDesc);
127: dialog.setVisible(true);
128:
129: mainWin.getGlassPane().setCursor(origCursor);
130: mainWin.getGlassPane().setVisible(false);
131:
132: if (dialogDesc.getValue() == NotifyDescriptor.OK_OPTION) {
133: for (WSEditor editor : editors) {
134: editor.save(node, jaxWsModel);
135: }
136: } else {
137: for (WSEditor editor : editors) {
138: editor.cancel(node, jaxWsModel);
139: }
140: }
141: }
142:
143: class DialogWindowListener extends WindowAdapter {
144:
145: Set<WSEditor> editors;
146:
147: public DialogWindowListener(Set<WSEditor> editors) {
148: this .editors = editors;
149: }
150:
151: public void windowClosing(WindowEvent e) {
152: for (WSEditor editor : editors) {
153: editor.cancel(node, jaxWsModel);
154: }
155: }
156: }
157:
158: public Set getWSEditorProviders() {
159: return providers;
160: }
161:
162: private void populatePanels() {
163: editors = new HashSet<WSEditor>();
164: for (WSEditorProvider provider : providers) {
165: if (provider.enable(node)) {
166: //for each provider, create a WSAttributesEditor
167: WSEditor editor = provider.createWSEditor();
168: editors.add(editor);
169: }
170: }
171: }
172:
173: private void populateWSEditorProviderRegistry() {
174: WSEditorProviderRegistry registry = WSEditorProviderRegistry
175: .getDefault();
176: if (registry.getEditorProviders().isEmpty()) {
177: Lookup.Result<WSEditorProvider> results = Lookup
178: .getDefault().lookup(
179: new Lookup.Template<WSEditorProvider>(
180: WSEditorProvider.class));
181: Collection<? extends WSEditorProvider> services = results
182: .allInstances();
183: //System.out.println("###number of editors: " + services.size());
184: for (WSEditorProvider provider : services) {
185: registry.register(provider);
186: }
187: }
188: }
189:
190: private Set<WSEditorProvider> providers;
191: private Set<WSEditor> editors;
192: private static Map<EditWSAttributesCookie, EditWSAttributesPanel> cachedTopComponents = new WeakHashMap<EditWSAttributesCookie, EditWSAttributesPanel>();
193: private EditWSAttributesPanel tc;
194: private Node node;
195: private JaxWsModel jaxWsModel;
196: private DialogWindowListener windowListener;
197: }
|