001    /******************************************************************************
002     * Copyright (C) MActor Developers. All rights reserved.                        *
003     * ---------------------------------------------------------------------------*
004     * This file is part of MActor.                                               *
005     *                                                                            *
006     * MActor is free software; you can redistribute it and/or modify             *
007     * it under the terms of the GNU General Public License as published by       *
008     * the Free Software Foundation; either version 2 of the License, or          *
009     * (at your option) any later version.                                        *
010     *                                                                            *
011     * MActor is distributed in the hope that it will be useful,                  *
012     * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
013     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
014     * GNU General Public License for more details.                               *
015     *                                                                            *
016     * You should have received a copy of the GNU General Public License          *
017     * along with MActor; if not, write to the Free Software                      *
018     * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA *
019     ******************************************************************************/
020    package org.mactor.ui.gui.project.editors;
021    
022    import java.awt.FlowLayout;
023    
024    import javax.swing.JCheckBox;
025    import javax.swing.JLabel;
026    import javax.swing.JTextField;
027    
028    import org.dom4j.Element;
029    import org.mactor.framework.MactorException;
030    import org.mactor.ui.gui.project.ProjectTreeNode;
031    
032    public class MessageReceiveNodeEditor extends AbstractNodeEditor {
033            JTextField minMessageCountText = new JTextField(5);
034            JTextField maxMessageCountText = new JTextField(5);
035            JTextField maxTimeoutSecondsText = new JTextField(5);
036            JCheckBox blockUntilTimeout = new JCheckBox("Block Until Timeout");
037            MessageSubscribersComboBox msCb = new MessageSubscribersComboBox();
038            Element data;
039            public MessageReceiveNodeEditor() {
040                    super(new FlowLayout());
041                    SimpleFormPanel box = new SimpleFormPanel();
042                    box.add(new JLabel("Message Subscriber:"));
043                    box.add(msCb);
044                    box.add(new JLabel("Min Message Count:"));
045                    box.add(minMessageCountText);
046                    box.add(new JLabel("Max Message Count:"));
047                    box.add(maxMessageCountText);
048                    box.add(new JLabel("Timeout (seconds):"));
049                    box.add(maxTimeoutSecondsText);
050                    box.add(blockUntilTimeout);
051                    add(box);
052            }
053            public void applyChanges() {
054                    EditorUtil.setAttributeValue(data, "message_subscribe_node_name", msCb.getSelectedMessageSubscriber());
055                    EditorUtil.setAttributeValue(data, "min_message_count", minMessageCountText.getText());
056                    EditorUtil.setAttributeValue(data, "max_message_count", maxMessageCountText.getText());
057                    EditorUtil.setAttributeValue(data, "max_timeout_seconds", maxTimeoutSecondsText.getText());
058                    EditorUtil.setAttributeValue(data, "block_until_timeout", blockUntilTimeout.isSelected() + "");
059            }
060            public void setData(ProjectTreeNode node) throws MactorException {
061                    this.data = (Element) node.getModelObject();
062                    msCb.setConfig(this.data);
063                    minMessageCountText.setText(EditorUtil.getAttributeValue(this.data, "min_message_count"));
064                    maxMessageCountText.setText(EditorUtil.getAttributeValue(this.data, "max_message_count"));
065                    maxTimeoutSecondsText.setText(EditorUtil.getAttributeValue(this.data, "max_timeout_seconds"));
066                    blockUntilTimeout.setSelected(Boolean.parseBoolean(EditorUtil.getAttributeValue(this.data, "block_until_timeout")));
067                    msCb.setSelectedMessageSubscriber(this.data.attributeValue("message_subscribe_node_name"));
068            }
069            public void setConfig(NodeEditorConfig config) {
070            }
071    }