001: /*
002: * soapUI, copyright (C) 2004-2007 eviware.com
003: *
004: * soapUI is free software; you can redistribute it and/or modify it under the
005: * terms of version 2.1 of the GNU Lesser General Public License as published by
006: * the Free Software Foundation.
007: *
008: * soapUI is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
009: * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
010: * See the GNU Lesser General Public License for more details at gnu.org.
011: */
012:
013: package com.eviware.soapui.impl.wsdl.panels.testcase.actions;
014:
015: import java.awt.BorderLayout;
016: import java.awt.Dimension;
017: import java.awt.event.ActionEvent;
018:
019: import javax.swing.AbstractAction;
020: import javax.swing.Action;
021: import javax.swing.BorderFactory;
022: import javax.swing.JButton;
023: import javax.swing.JDialog;
024: import javax.swing.JPanel;
025:
026: import com.eviware.soapui.impl.wsdl.testcase.WsdlTestCase;
027: import com.eviware.soapui.impl.wsdl.teststeps.WsdlTestRequestStep;
028: import com.eviware.soapui.model.testsuite.TestStep;
029: import com.eviware.soapui.support.UISupport;
030: import com.eviware.soapui.support.components.SimpleForm;
031: import com.jgoodies.forms.factories.ButtonBarFactory;
032:
033: /**
034: * Set the credentials for all requests in a testcase
035: *
036: * @author Ole.Matzura
037: */
038:
039: public class SetCredentialsAction extends AbstractAction {
040: private final WsdlTestCase testCase;
041: private JDialog dialog;
042: private SimpleForm form;
043:
044: private static final String DOMAIN = "Domain";
045: private static final String PASSWORD = "Password";
046: private static final String USERNAME = "Username";
047:
048: public SetCredentialsAction(WsdlTestCase testCase) {
049: this .testCase = testCase;
050: putValue(Action.SMALL_ICON, UISupport
051: .createImageIcon("/set_credentials.gif"));
052: putValue(Action.SHORT_DESCRIPTION,
053: "Sets the credentials for all requests in this testcase");
054: }
055:
056: public void actionPerformed(ActionEvent e) {
057: if (dialog == null) {
058: buildDialog();
059: }
060:
061: UISupport.showDialog(dialog);
062: }
063:
064: private void buildDialog() {
065: dialog = new JDialog(UISupport.getMainFrame(),
066: "Set TestCase Credentials");
067: form = new SimpleForm();
068: form.appendTextField(USERNAME,
069: "Username to use for authentication");
070: form.appendTextField(PASSWORD,
071: "Password to use for authentication");
072: form.appendTextField(DOMAIN, "Domain to specify (for NTLM)");
073: form.getPanel().setBorder(
074: BorderFactory.createEmptyBorder(0, 0, 10, 0));
075:
076: JPanel panel = new JPanel(new BorderLayout());
077: panel.add(form.getPanel(), BorderLayout.CENTER);
078:
079: JPanel buttonBar = ButtonBarFactory.buildOKCancelBar(
080: new JButton(new OkAction()), new JButton(
081: new CancelAction()));
082: panel.add(buttonBar, BorderLayout.SOUTH);
083: panel
084: .setBorder(BorderFactory.createEmptyBorder(10, 10, 10,
085: 10));
086: panel.setPreferredSize(new Dimension(270, (int) panel
087: .getPreferredSize().getHeight()));
088:
089: dialog.getContentPane().add(panel);
090: dialog.pack();
091: }
092:
093: private class OkAction extends AbstractAction {
094: public OkAction() {
095: super ("Ok");
096: }
097:
098: public void actionPerformed(ActionEvent e) {
099: for (int c = 0; c < testCase.getTestStepCount(); c++) {
100: TestStep step = testCase.getTestStepAt(c);
101: if (step instanceof WsdlTestRequestStep) {
102: WsdlTestRequestStep requestStep = (WsdlTestRequestStep) step;
103: requestStep.getTestRequest().setUsername(
104: form.getComponentValue(USERNAME));
105: requestStep.getTestRequest().setPassword(
106: form.getComponentValue(PASSWORD));
107: requestStep.getTestRequest().setDomain(
108: form.getComponentValue(DOMAIN));
109: }
110: }
111:
112: dialog.setVisible(false);
113: }
114: }
115:
116: private class CancelAction extends AbstractAction {
117: public CancelAction() {
118: super ("Cancel");
119: }
120:
121: public void actionPerformed(ActionEvent e) {
122: dialog.setVisible(false);
123: }
124: }
125: }
|