001: /*
002: * The contents of this file are subject to the terms of the Common Development
003: * and Distribution License (the License). You may not use this file except in
004: * compliance with the License.
005: *
006: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
007: * or http://www.netbeans.org/cddl.txt.
008: *
009: * When distributing Covered Code, include this CDDL Header Notice in each file
010: * and include the License file at http://www.netbeans.org/cddl.txt.
011: * If applicable, add the following below the CDDL Header, with the fields
012: * enclosed by brackets [] replaced by your own identifying information:
013: * "Portions Copyrighted [year] [name of copyright owner]"
014: *
015: * The Original Software is NetBeans. The Initial Developer of the Original
016: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
017: * Microsystems, Inc. All Rights Reserved.
018: */
019:
020: package org.netbeans.modules.bpel.core.wizard;
021:
022: import java.awt.Component;
023: import java.awt.Container;
024: import java.util.Collection;
025: import java.util.Iterator;
026: import java.util.Vector;
027:
028: import javax.swing.JComponent;
029: import javax.swing.JLabel;
030: import javax.swing.text.JTextComponent;
031:
032: import org.openide.WizardDescriptor;
033:
034: /**
035: *
036: * @author from nb webservice module
037: */
038: public class Utilities {
039:
040: public static String[] createSteps(String[] before,
041: WizardDescriptor.Panel[] panels) {
042: //assert panels != null;
043: // hack to use the steps set before this panel processed
044: int diff = 0;
045: if (before == null) {
046: before = new String[0];
047: } else if (before.length > 0) {
048: diff = ("...".equals(before[before.length - 1])) ? 1 : 0; // NOI18N
049: }
050: String[] res = new String[(before.length - diff)
051: + panels.length];
052: for (int i = 0; i < res.length; i++) {
053: if (i < (before.length - diff)) {
054: res[i] = before[i];
055: } else {
056: res[i] = panels[i - before.length + diff]
057: .getComponent().getName();
058: }
059: }
060: return res;
061: }
062:
063: /*
064: * Changes the text of a JLabel in component from oldLabel to newLabel
065: */
066: public static JTextComponent findTextFieldForLabel(
067: JComponent component, String text) {
068: JLabel label = findLabel(component, text);
069: if (label != null) {
070: Component comp = label.getLabelFor();
071: if (comp != null && (comp instanceof JTextComponent))
072: return (JTextComponent) comp;
073: }
074: return null;
075: }
076:
077: /*
078: * taken from j2ee module
079: * Recursively gets all components in the components array and puts it in allComponents
080: */
081: private static void getAllComponents(Component[] components,
082: Collection allComponents) {
083: for (int i = 0; i < components.length; i++) {
084: if (components[i] != null) {
085: allComponents.add(components[i]);
086: if (((Container) components[i]).getComponentCount() != 0) {
087: getAllComponents(((Container) components[i])
088: .getComponents(), allComponents);
089: }
090: }
091: }
092: }
093:
094: /*
095: * taken from j2ee module
096: * Recursively finds a JLabel that has labelText in comp
097: */
098: private static JLabel findLabel(JComponent comp, String labelText) {
099: Vector allComponents = new Vector();
100: getAllComponents(comp.getComponents(), allComponents);
101: Iterator iterator = allComponents.iterator();
102: while (iterator.hasNext()) {
103: Component c = (Component) iterator.next();
104: if (c instanceof JLabel) {
105: JLabel label = (JLabel) c;
106: if (label.getText().equals(labelText)) {
107: return label;
108: }
109: }
110: }
111: return null;
112: }
113:
114: }
|