001: /*
002: * ChainBuilder ESB
003: * Visual Enterprise Integration
004: *
005: * Copyright (C) 2006 Bostech Corporation
006: *
007: * This program is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU General Public License as published by the
009: * Free Software Foundation; either version 2 of the License, or (at your option)
010: * any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
014: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
015: * for more details.
016: *
017: * You should have received a copy of the GNU General Public License along with
018: * this program; if not, write to the Free Software Foundation, Inc.,
019: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020: *
021: *
022: * $Id$
023: */
024:
025: package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.actions;
026:
027: import java.io.File;
028: import java.io.FilenameFilter;
029: import java.util.ArrayList;
030:
031: import org.eclipse.core.resources.ResourcesPlugin;
032: import org.eclipse.jface.dialogs.Dialog;
033: import org.eclipse.jface.dialogs.IDialogConstants;
034: import org.eclipse.swt.SWT;
035: import org.eclipse.swt.events.ModifyEvent;
036: import org.eclipse.swt.events.ModifyListener;
037: import org.eclipse.swt.events.SelectionAdapter;
038: import org.eclipse.swt.events.SelectionEvent;
039: import org.eclipse.swt.graphics.Point;
040: import org.eclipse.swt.layout.GridData;
041: import org.eclipse.swt.layout.GridLayout;
042: import org.eclipse.swt.widgets.Button;
043: import org.eclipse.swt.widgets.Composite;
044: import org.eclipse.swt.widgets.Control;
045: import org.eclipse.swt.widgets.DirectoryDialog;
046: import org.eclipse.swt.widgets.Label;
047: import org.eclipse.swt.widgets.Shell;
048: import org.eclipse.swt.widgets.Text;
049: import org.eclipse.ui.PlatformUI;
050: import org.eclipse.ui.part.FileEditorInput;
051:
052: import com.bostechcorp.cbesb.common.i18n.I18N;
053: import com.bostechcorp.cbesb.common.i18n.Messages;
054: import com.bostechcorp.cbesb.common.util.FileUtil;
055: import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
056: import com.bostechcorp.cbesb.ui.util.ProjectUtil;
057:
058: public class DeployeDialog extends Dialog {
059:
060: private Text exportDirectoryText;
061: private Button browseButton;
062: private String exportPath = "";
063: private boolean exportFlag = false;
064: private Button buttonExport;
065: private ArrayList<HTTP> list;
066: private String projectName = "";
067:
068: /**
069: * Create the dialog
070: * @param parentShell
071: */
072: public DeployeDialog(Shell parentShell, ArrayList<HTTP> list,
073: String projectName) {
074: super (parentShell);
075: this .list = list;
076: this .projectName = projectName;
077: }
078:
079: /**
080: * Create contents of the dialog
081: * @param parent
082: */
083: @Override
084: protected Control createDialogArea(Composite parent) {
085: Composite container = (Composite) super
086: .createDialogArea(parent);
087: final GridLayout gridLayout = new GridLayout();
088: gridLayout.marginTop = 10;
089: gridLayout.verticalSpacing = 10;
090: gridLayout.numColumns = 3;
091: container.setLayout(gridLayout);
092:
093: final Label theServiceAssemblyLabel = new Label(container,
094: SWT.NONE);
095: final GridData gridData = new GridData(SWT.LEFT, SWT.CENTER,
096: false, false, 2, 1);
097: gridData.heightHint = 34;
098: theServiceAssemblyLabel.setLayoutData(gridData);
099: theServiceAssemblyLabel.setText(I18N
100: .getString(Messages.DEPLOY_WSDL_EXPORT));
101: new Label(container, SWT.NONE);
102:
103: buttonExport = new Button(container, SWT.CHECK);
104: buttonExport.addSelectionListener(new SelectionAdapter() {
105: public void widgetSelected(final SelectionEvent e) {
106: if (buttonExport.getSelection()) {
107: exportDirectoryText.setEnabled(true);
108: browseButton.setEnabled(true);
109: dialogChange();
110:
111: } else {
112: exportDirectoryText.setEnabled(false);
113: browseButton.setEnabled(false);
114: dialogChange();
115: }
116: }
117: });
118:
119: buttonExport.setLayoutData(new GridData());
120: buttonExport.setText(I18N
121: .getString(Messages.DEPLOY_WSDL_EXPORT_YES));
122: new Label(container, SWT.NONE);
123: new Label(container, SWT.NONE);
124:
125: final Label exportToDirectoryLabel = new Label(container,
126: SWT.NONE);
127: exportToDirectoryLabel.setText(I18N
128: .getString(Messages.DEPLOY_WSDL_EXPORT_TO_DIRECTORY));
129:
130: exportDirectoryText = new Text(container, SWT.READ_ONLY
131: | SWT.BORDER);
132: exportDirectoryText.setLayoutData(new GridData(SWT.FILL,
133: SWT.CENTER, true, false));
134: exportDirectoryText.addModifyListener(new ModifyListener() {
135:
136: public void modifyText(ModifyEvent e) {
137:
138: dialogChange();
139: }
140:
141: });
142:
143: browseButton = new Button(container, SWT.NONE);
144: browseButton.addSelectionListener(new SelectionAdapter() {
145: public void widgetSelected(final SelectionEvent e) {
146: String projectLocation = ((FileEditorInput) PlatformUI
147: .getWorkbench().getActiveWorkbenchWindow()
148: .getActivePage().getActiveEditor()
149: .getEditorInput()).getFile().getProject()
150: .getLocation().toOSString();
151: DirectoryDialog dialog = new DirectoryDialog(
152: browseButton.getShell());
153: dialog.setFilterPath(projectLocation + "/src/wsdl");
154: dialog.setMessage(I18N
155: .getString(Messages.DEPLOY_WSDL_EXPORT_SELECT));
156: exportDirectoryText.setText(dialog.open());
157: }
158: });
159: browseButton.setText(I18N.getString(Messages.WIZARD_BROWSE));
160: browseButton.setEnabled(false);
161:
162: //
163: return container;
164: }
165:
166: protected void dialogChange() {
167:
168: if (buttonExport.getSelection()) {
169: if (exportDirectoryText.getText().equals("")) {
170: getOKButton().setEnabled(false);
171:
172: } else {
173: getOKButton().setEnabled(true);
174: }
175: } else {
176: getOKButton().setEnabled(true);
177: }
178: }
179:
180: @Override
181: protected void okPressed() {
182:
183: if (buttonExport.getSelection()) {
184: for (int i = 0; i < list.size(); i++) {
185: HTTP httpModel = list.get(i);
186: String servicesUnitName = projectName + "_"
187: + httpModel.getName();
188: // String wsdlPath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()
189: // +File.separator+projectName+"/src/SUs/"+servicesUnitName+"/wsdlPublic/"+servicesUnitName+".wsdl";
190: String wsdlPath = ResourcesPlugin.getWorkspace()
191: .getRoot().getLocation().toOSString()
192: + File.separator
193: + projectName
194: + "/src/SUs/"
195: + servicesUnitName + "/wsdlPublic/";
196: File wsdlDir = new File(wsdlPath);
197: File[] wsdlList = wsdlDir.listFiles(new WsdlFilter());
198: for (int j = 0; j < wsdlList.length; j++) {
199: FileUtil.copyFile(wsdlList[j], exportDirectoryText
200: .getText());
201: }
202: }
203: ProjectUtil.refreshProject(projectName);
204: }
205: super .okPressed();
206: }
207:
208: @Override
209: protected void cancelPressed() {
210:
211: super .cancelPressed();
212: }
213:
214: /**
215: * Create contents of the button bar
216: * @param parent
217: */
218: @Override
219: protected void createButtonsForButtonBar(Composite parent) {
220: createButton(parent, IDialogConstants.OK_ID,
221: IDialogConstants.OK_LABEL, true);
222: createButton(parent, IDialogConstants.CANCEL_ID,
223: IDialogConstants.CANCEL_LABEL, false);
224: }
225:
226: /**
227: * Return the initial size of the dialog
228: */
229: @Override
230: protected Point getInitialSize() {
231: return new Point(492, 261);
232: }
233:
234: public boolean isExportFlag() {
235: return exportFlag;
236: }
237:
238: public String getExportPath() {
239: return exportPath;
240: }
241:
242: protected void configureShell(Shell newShell) {
243: super .configureShell(newShell);
244: newShell.setText(I18N.getString(Messages.DEPLOY_DIALOG));
245: }
246:
247: public static class WsdlFilter implements FilenameFilter {
248:
249: public boolean accept(File dir, String name) {
250: return name.endsWith(".wsdl");
251: }
252:
253: }
254:
255: }
|