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.action;
019:
020: import java.awt.Color;
021: import java.util.List;
022: import java.util.Vector;
023: import java.util.logging.Level;
024: import java.util.logging.Logger;
025:
026: import javax.swing.JDialog;
027: import javax.swing.JLabel;
028: import javax.swing.JOptionPane;
029: import javax.swing.JTextField;
030:
031: import de.finix.contelligent.client.ContelligentClient;
032: import de.finix.contelligent.client.base.ComponentFactory;
033: import de.finix.contelligent.client.base.ComponentNotFoundException;
034: import de.finix.contelligent.client.base.ContelligentComponent;
035:
036: public class ActionOptionPane extends JOptionPane {
037:
038: private static Logger logger = Logger
039: .getLogger(ActionOptionPane.class.getName());
040:
041: private ContelligentComponent parameterFolder;
042:
043: private List<JLabel> parameterLabel = new Vector<JLabel>();
044:
045: private List<JTextField> parameterField = new Vector<JTextField>();
046:
047: public ActionOptionPane(ContelligentComponent parameterFolder) {
048: this .parameterFolder = parameterFolder;
049: }
050:
051: public int showPerformActionDialog(String title, List parameterList) {
052: JLabel actionLabel = new JLabel(title);
053: Object[] array = new Object[parameterList.size() * 2 + 1];
054: array[0] = actionLabel;
055: for (int i = 0; i < parameterList.size(); i++) {
056: String parameterName = (String) parameterList.get(i);
057: try {
058: ContelligentComponent parameter = ComponentFactory
059: .getInstance().getComponent(
060: parameterFolder.getPath() + "/"
061: + parameterName);
062:
063: JLabel label = new JLabel(parameter.getName());
064:
065: // maybe the parameter is a link, so we follow the component/link
066: parameter = parameter.followLink();
067:
068: // if the followed link is null we have to set the
069: // attributes manually. Therefore we initialize them here.
070: boolean required = false;
071: String value = "";
072:
073: // if the followed link is null it was a link wich was part of
074: // an infinite loop
075: if (parameter == null) {
076: required = true;
077: value = "";
078: } else {
079: required = Boolean
080: .valueOf(
081: parameter
082: .getPropertyValue(ContelligentComponent.REQUIRED))
083: .booleanValue();
084: value = parameter
085: .getPropertyValue(ContelligentComponent.DEFAULT);
086: }
087:
088: if (required) {
089: label.setForeground(Color.red);
090: }
091: array[i * 2 + 1] = label;
092: parameterLabel.add(label);
093: JTextField valueField = new JTextField(15);
094: valueField.setText(value);
095: parameterField.add(valueField);
096: array[i * 2 + 2] = valueField;
097: } catch (ComponentNotFoundException cnfe) {
098: logger.log(Level.SEVERE, "Parameter " + parameterName
099: + " not found", cnfe);
100: }
101: }
102: setMessage(array);
103: setMessageType(QUESTION_MESSAGE);
104: setOptionType(OK_CANCEL_OPTION);
105:
106: JDialog dialog = createDialog(ContelligentClient
107: .getActiveFrame(), title);
108: dialog.setVisible(true);
109: if (getValue() instanceof Integer) {
110: return ((Integer) getValue()).intValue();
111: }
112: return CANCEL_OPTION;
113: }
114:
115: public String[][] getParameter() {
116: String[][] parameter = new String[parameterLabel.size() + 1][2];
117: for (int i = 0; i < parameterLabel.size(); i++) {
118: String parameterName = parameterLabel.get(i).getText();
119: String parameterValue = parameterField.get(i).getText();
120: parameter[i][0] = parameterName;
121: parameter[i][1] = parameterValue;
122: }
123: return parameter;
124: }
125: }
|