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.actions;
014:
015: import java.io.File;
016:
017: import com.eviware.soapui.impl.WorkspaceImpl;
018: import com.eviware.soapui.impl.wsdl.WsdlProject;
019: import com.eviware.soapui.support.UISupport;
020: import com.eviware.soapui.support.action.support.AbstractSoapUIAction;
021: import com.eviware.x.form.XFormDialog;
022: import com.eviware.x.form.XFormField;
023: import com.eviware.x.form.XFormFieldListener;
024: import com.eviware.x.form.support.ADialogBuilder;
025: import com.eviware.x.form.support.AField;
026: import com.eviware.x.form.support.AForm;
027: import com.eviware.x.form.support.AField.AFieldType;
028:
029: /**
030: * Action for creating a new WSDL project
031: *
032: * @author Ole.Matzura
033: */
034:
035: public class NewWsdlProjectAction extends
036: AbstractSoapUIAction<WorkspaceImpl> {
037: public static final String SOAPUI_ACTION_ID = "NewWsdlProjectAction";
038: private XFormDialog dialog;
039:
040: public NewWsdlProjectAction() {
041: super ("New WSDL Project",
042: "Creates a new WSDL Project in this workspace");
043: }
044:
045: public void perform(WorkspaceImpl workspace, Object param) {
046: if (dialog == null) {
047: dialog = ADialogBuilder.buildDialog(Form.class);
048: dialog.setValue(Form.CREATEREQUEST, Boolean.toString(true));
049: dialog.getFormField(Form.INITIALWSDL).addFormFieldListener(
050: new XFormFieldListener() {
051:
052: public void valueChanged(
053: XFormField sourceField,
054: String newValue, String oldValue) {
055: dialog
056: .getFormField(Form.CREATEREQUEST)
057: .setEnabled(
058: newValue.trim().length() > 0);
059: }
060: });
061: } else {
062: dialog.setValue(Form.PROJECTNAME, "");
063: dialog.setValue(Form.INITIALWSDL, "");
064: }
065:
066: if (dialog.show()) {
067: try {
068: WsdlProject project = workspace.createProject(dialog
069: .getValue(Form.PROJECTNAME));
070: if (project != null) {
071: String url = dialog.getValue(Form.INITIALWSDL)
072: .trim();
073: if (url.length() > 0) {
074: if (new File(url).exists())
075: url = "file:" + url;
076:
077: project.importWsdl(url, dialog.getValue(
078: Form.CREATEREQUEST).equals("true"));
079: }
080:
081: UISupport.select(project);
082: }
083: } catch (Exception ex) {
084: UISupport.showErrorMessage(ex);
085: }
086: }
087: }
088:
089: @AForm(name="New WSDL Project",description="Creates a new WSDL Project in this workspace")
090: private class Form {
091: @AField(name="Project Name",description="The name of the project to create",type=AFieldType.STRING)
092: public final static String PROJECTNAME = "Project Name";
093:
094: @AField(name="Initial WSDL",description="URL or filename of initial WSDL",type=AFieldType.FILE)
095: public final static String INITIALWSDL = "Initial WSDL";
096:
097: @AField(name="Create Requests",description="Create sample requests for all operations?",type=AFieldType.BOOLEAN,enabled=false)
098: public final static String CREATEREQUEST = "Create Requests";
099: }
100:
101: }
|