001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.text;
019:
020: import java.awt.Dimension;
021: import java.awt.event.ActionEvent;
022: import java.awt.event.ActionListener;
023: import java.util.List;
024:
025: import javax.swing.JCheckBox;
026: import javax.swing.JComboBox;
027: import javax.swing.JComponent;
028: import javax.swing.JDialog;
029: import javax.swing.JLabel;
030: import javax.swing.JOptionPane;
031: import javax.swing.JPanel;
032: import javax.swing.JTextField;
033:
034: import de.finix.contelligent.client.ContelligentClient;
035: import de.finix.contelligent.client.base.ContelligentComponent;
036: import de.finix.contelligent.client.base.ParameterDescription;
037: import de.finix.contelligent.client.base.category.ContelligentCategory;
038: import de.finix.contelligent.client.base.category.ContelligentCategoryManager;
039: import de.finix.contelligent.client.i18n.Resources;
040: import de.finix.contelligent.client.util.JTextUtil;
041: import de.finix.contelligent.client.util.TableLayout;
042: import de.finix.contelligent.client.wizard.AbstractWizard;
043:
044: public class CreateTagOptionPane extends AbstractWizard {
045:
046: private JTextField textField;
047:
048: private ContelligentComponent component;
049:
050: private JCheckBox checkBoxes[];
051:
052: private JComponent parameterValue[];
053:
054: public CreateTagOptionPane(ContelligentComponent component) {
055: this .component = component;
056: }
057:
058: public String getPath() {
059: StringBuffer path = new StringBuffer(256);
060: path.append(textField.getText());
061: ParameterDescription[] parameters = (ParameterDescription[]) component
062: .getParameterDescriptions().toArray(
063: new ParameterDescription[0]);
064: boolean first = true;
065: for (int i = 0; i < parameters.length; i++) {
066: if (checkBoxes[i].isSelected() && parameterValue[i] != null) {
067: if (first) {
068: first = false;
069: path.append('?');
070: } else {
071: path.append('&');
072: }
073: path.append(parameters[i].getName());
074: path.append('=');
075: if (parameterValue[i] instanceof JComboBox) {
076: path.append(((JComboBox) parameterValue[i])
077: .getSelectedItem());
078: } else if (parameterValue[i] instanceof JTextField) {
079: path.append(((JTextField) parameterValue[i])
080: .getText());
081: }
082: }
083: }
084: return path.toString();
085: }
086:
087: public int showDialog(String text) {
088: List parameters = component.getParameterDescriptions();
089: checkBoxes = new JCheckBox[parameters.size()];
090: parameterValue = new JComponent[parameters.size()];
091: double rows[] = new double[5 + parameters.size()];
092: rows[0] = 25;
093: rows[1] = 25;
094: rows[2] = 10;
095: rows[3] = 50;
096: for (int i = 0; i < parameters.size(); i++) {
097: rows[4 + i] = 25;
098: }
099: rows[4 + parameters.size()] = TableLayout.FILL;
100: JPanel panel = new JPanel(new TableLayout(new double[][] {
101: { 20, 130, TableLayout.FILL }, rows }));
102:
103: JLabel titleLabel = JTextUtil.createTitle(Resources
104: .getLocalString("insert_wizard_path"));
105: panel.add(titleLabel, "0,0,2,0");
106: textField = new JTextField(text);
107: panel.add(textField, "0,1,2,1,f,t");
108: if (parameters.size() > 0) {
109: JComponent infoLabel = JTextUtil
110: .createMessageArea(Resources
111: .getLocalString("insert_wizard_description"));
112: panel.add(infoLabel, "0,3,2,3");
113: for (int i = 0; i < parameters.size(); i++) {
114: ParameterDescription parameter = (ParameterDescription) parameters
115: .get(i);
116: ContelligentCategory category = ContelligentCategoryManager
117: .getInstance().getCategoryByName(
118: parameter.getName());
119: if (category != null) {
120: checkBoxes[i] = new JCheckBox(category
121: .getDescription(Resources.getLocale())
122: .getTitle());
123: parameter.setDescription(category.getDescription(
124: Resources.getLocale()).getText());
125: } else {
126: checkBoxes[i] = new JCheckBox(parameter.getName());
127: }
128: panel.add(checkBoxes[i], "1," + (i + 4));
129: checkBoxes[i].addActionListener(new ActionListener() {
130: public void actionPerformed(ActionEvent e) {
131: JCheckBox source = (JCheckBox) e.getSource();
132: for (int i = 0; i < checkBoxes.length; i++) {
133: if (checkBoxes[i] == source
134: && parameterValue[i] != null) {
135: if (source.isSelected()) {
136: parameterValue[i].setEnabled(true);
137: } else {
138: parameterValue[i].setEnabled(false);
139: }
140: }
141: }
142:
143: }
144: });
145: if (parameter.isConstrained()) {
146: parameterValue[i] = new JComboBox(parameter
147: .getAllowedValues().toArray());
148: parameterValue[i].setEnabled(false);
149: } else {
150: parameterValue[i] = new JTextField();
151: parameterValue[i].setEnabled(false);
152: }
153: panel.add(parameterValue[i], "2," + (i + 4));
154: }
155: }
156: panel.setPreferredSize(new Dimension(400, Math.max(210,
157: 110 + 25 * parameters.size())));
158: setMessage(panel);
159: setOptionType(JOptionPane.OK_CANCEL_OPTION);
160:
161: JDialog dialog = createDialog(ContelligentClient
162: .getActiveFrame(), Resources
163: .getLocalString("insert_wizard_title"));
164: dialog.setVisible(true);
165: if (getValue() instanceof Integer) {
166: return ((Integer) getValue()).intValue();
167: }
168: return CANCEL_OPTION;
169: }
170: }
|