View | Details | Raw Unified | Return to bug 168937 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/jst/ws/axis2/core/utils/Axis2CoreUtils.java (+74 lines)
Lines 16-21 Link Here
16
 * 20070824   200515 sandakith@wso2.com - Lahiru Sandakith, NON-NLS move to seperate file
16
 * 20070824   200515 sandakith@wso2.com - Lahiru Sandakith, NON-NLS move to seperate file
17
 * 20080625   210817 samindaw@wso2.com - Saminda Wijeratne, Setting the proxyBean and proxyEndPoint values - Refactoring
17
 * 20080625   210817 samindaw@wso2.com - Saminda Wijeratne, Setting the proxyBean and proxyEndPoint values - Refactoring
18
 * 20080924   247929 samindaw@wso2.com - Saminda Wijeratne, source folder not correctly set
18
 * 20080924   247929 samindaw@wso2.com - Saminda Wijeratne, source folder not correctly set
19
 * 20090305	  168938 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar export
20
 * 20090305	  168937 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar import
19
 *******************************************************************************/
21
 *******************************************************************************/
20
package org.eclipse.jst.ws.axis2.core.utils;
22
package org.eclipse.jst.ws.axis2.core.utils;
21
23
Lines 28-42 Link Here
28
import java.net.URL;
30
import java.net.URL;
29
import java.util.ArrayList;
31
import java.util.ArrayList;
30
import java.util.HashMap;
32
import java.util.HashMap;
33
import java.util.List;
31
34
32
import javax.xml.parsers.DocumentBuilder;
35
import javax.xml.parsers.DocumentBuilder;
33
import javax.xml.parsers.DocumentBuilderFactory;
36
import javax.xml.parsers.DocumentBuilderFactory;
34
import javax.xml.parsers.ParserConfigurationException;
37
import javax.xml.parsers.ParserConfigurationException;
35
38
39
import org.eclipse.core.resources.IFile;
40
import org.eclipse.core.resources.IFolder;
36
import org.eclipse.core.resources.IProject;
41
import org.eclipse.core.resources.IProject;
42
import org.eclipse.core.resources.IResource;
43
import org.eclipse.core.resources.IResourceVisitor;
37
import org.eclipse.core.resources.ResourcesPlugin;
44
import org.eclipse.core.resources.ResourcesPlugin;
38
import org.eclipse.core.runtime.CoreException;
45
import org.eclipse.core.runtime.CoreException;
39
import org.eclipse.core.runtime.IPath;
46
import org.eclipse.core.runtime.IPath;
47
import org.eclipse.core.runtime.Path;
40
import org.eclipse.jdt.core.IClasspathEntry;
48
import org.eclipse.jdt.core.IClasspathEntry;
41
import org.eclipse.jdt.core.IJavaProject;
49
import org.eclipse.jdt.core.IJavaProject;
42
import org.eclipse.jdt.core.IPackageFragmentRoot;
50
import org.eclipse.jdt.core.IPackageFragmentRoot;
Lines 44-49 Link Here
44
import org.eclipse.jdt.core.JavaModelException;
52
import org.eclipse.jdt.core.JavaModelException;
45
import org.eclipse.jdt.internal.core.JavaProject;
53
import org.eclipse.jdt.internal.core.JavaProject;
46
import org.eclipse.jst.ws.axis2.core.constant.Axis2Constants;
54
import org.eclipse.jst.ws.axis2.core.constant.Axis2Constants;
55
import org.eclipse.jst.ws.internal.common.J2EEUtils;
47
import org.w3c.dom.Document;
56
import org.w3c.dom.Document;
48
import org.w3c.dom.Element;
57
import org.w3c.dom.Element;
49
import org.w3c.dom.Node;
58
import org.w3c.dom.Node;
Lines 243-246 Link Here
243
	    }
252
	    }
244
	    return (String[])paths.toArray(new String[0]);
253
	    return (String[])paths.toArray(new String[0]);
245
	  } 
254
	  } 
255
	
256
	
257
	public static String[] getWorkspaceWebProjectList(){
258
		List webProjects=new ArrayList();
259
		IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
260
		for(IProject project:projects){
261
			try{
262
				J2EEUtils.getWebInfPath(project);
263
				webProjects.add(project.getName());
264
			}catch(Exception e){
265
				//not a web project
266
			}
267
		}
268
		return (String[])webProjects.toArray(new String[webProjects.size()]);
269
	}
270
	
271
	public static List getServiceFoldersInProject(IProject project){
272
		List services=new ArrayList();
273
		IPath webInfPath = J2EEUtils.getWebInfPath(project);
274
		IFolder folder=project.getFolder(webInfPath.removeFirstSegments(1));
275
		IFolder servicesFolder=folder.getFolder(new Path("services"));
276
277
		ServiceFolderVisitor visitor = new ServiceFolderVisitor(false);
278
		try {
279
			servicesFolder.accept(visitor);
280
		} catch (CoreException e1) {
281
			e1.printStackTrace();
282
		}
283
		for(IResource resource:visitor.getResources()){
284
			Path path = new Path(resource.toString().substring(servicesFolder.toString().length()));
285
			if (path.segmentCount()==1 && resource instanceof IFolder){
286
				IFolder folder2=(IFolder)resource;
287
				services.add(folder2);
288
			}
289
		}
290
		
291
		return services;
292
	}
293
	
294
	public static IFolder getServicesFolderofProject(IProject project){
295
		IPath webInfPath = J2EEUtils.getWebInfPath(project);
296
		IFolder folder=project.getFolder(webInfPath.removeFirstSegments(1));
297
		IFolder servicesFolder=folder.getFolder(new Path("services"));
298
		return servicesFolder;
299
	}
300
	
301
	private static class ServiceFolderVisitor implements IResourceVisitor{
302
		List<IResource> linkedFolders;
303
		boolean isGetOnlyLinkedFolders=false;
304
		public ServiceFolderVisitor(boolean isGetOnlyLinkedFolders){
305
			linkedFolders=new ArrayList<IResource>();
306
			this.isGetOnlyLinkedFolders=isGetOnlyLinkedFolders;
307
		}
308
		public boolean visit(IResource arg0) throws CoreException {
309
			if (!isGetOnlyLinkedFolders || arg0.isLinked()){
310
				if (arg0 instanceof IFolder || arg0 instanceof IFile)
311
					linkedFolders.add(arg0);
312
			}
313
			return true;
314
		}
315
		
316
		public IResource[] getResources(){
317
			return linkedFolders.toArray(new IResource[]{});
318
		}
319
	}
246
}
320
}
(-)src/org/eclipse/jst/ws/axis2/core/utils/ArchiveManipulator.java (+221 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 WSO2 Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * WSO2 Inc. - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
12
 * 20090305	  168938 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar export
13
 * 20090305	  168937 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar import
14
 *******************************************************************************/
15
16
package org.eclipse.jst.ws.axis2.core.utils;
17
18
import java.io.File;
19
import java.io.FileInputStream;
20
import java.io.FileOutputStream;
21
import java.io.IOException;
22
import java.io.InputStream;
23
import java.io.OutputStream;
24
import java.util.ArrayList;
25
import java.util.Collection;
26
import java.util.zip.ZipEntry;
27
import java.util.zip.ZipInputStream;
28
import java.util.zip.ZipOutputStream;
29
30
public class ArchiveManipulator {
31
	protected String archiveSourceDir;
32
33
    /**
34
     * Utility method to archive the given directory 
35
     * @param destArchiveName 
36
     * @param sourceDir
37
     * @throws IOException
38
     */
39
    public void archiveDir(String destArchiveName, String sourceDir) throws IOException {
40
        File zipDir = new File(sourceDir);
41
        if (!zipDir.isDirectory()) {
42
            throw new RuntimeException(sourceDir + " is not a directory");
43
        }
44
45
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(destArchiveName));
46
        this.archiveSourceDir = sourceDir;
47
        zipDir(zipDir, zos);
48
        zos.close();
49
    }
50
51
    /**
52
     * Utility method to archive the given file 
53
     * @param from
54
     * @param to
55
     * @throws IOException
56
     */
57
    public void archiveFile(String from, String to) throws IOException {
58
        FileInputStream in = new FileInputStream(from);
59
        ZipOutputStream out = new ZipOutputStream(new FileOutputStream(to));
60
        byte[] buffer = new byte[40960];
61
        int bytesRead;
62
        while ((bytesRead = in.read(buffer)) != -1) {
63
            out.write(buffer, 0, bytesRead);
64
        }
65
        in.close();
66
        out.close();
67
    }
68
69
    /**
70
     * List the contents of an archive
71
     * @param archive
72
     * @return List of Zip Entries
73
     * @throws IOException
74
     */
75
    public String[] check(String archive) throws IOException {
76
        ZipInputStream zin = null;
77
        InputStream in = null;
78
        Collection entries = new ArrayList();
79
        try {
80
            in = new FileInputStream(archive);
81
            zin = new ZipInputStream(in);
82
            ZipEntry entry;
83
            while ((entry = zin.getNextEntry()) != null) {
84
                entries.add(entry.getName());
85
            }
86
            return (String[]) entries.toArray(new String[entries.size()]);
87
        } finally {
88
            try {
89
                if (zin != null) {
90
                    zin.close();
91
                }
92
                if (in != null) {
93
                    in.close();
94
                }
95
            } catch (IOException e) {
96
                System.err.println("Could not close InputStream " + e);
97
            }
98
        }
99
    }
100
101
    /**
102
     * Utility method to extract an archive
103
     * @param archive
104
     * @param extractDir
105
     * @throws IOException
106
     */
107
    public void extract(String archive, String extractDir) throws IOException {
108
        FileInputStream inputStream = new FileInputStream(archive);
109
        extractFromStream(inputStream, extractDir);
110
    }
111
112
    /**
113
     * Utility method to extract form a stream to a given directory
114
     * @param inputStream
115
     * @param extractDir
116
     * @throws IOException
117
     */
118
    public void extractFromStream(InputStream inputStream, String extractDir) throws IOException {
119
        ZipInputStream zin = null;
120
        try {
121
            File unzipped = new File(extractDir);
122
            // Open the ZIP file
123
            zin = new ZipInputStream(inputStream);
124
            unzipped.mkdirs();
125
            ZipEntry entry;
126
            while ((entry = zin.getNextEntry()) != null) {
127
                String entryName = entry.getName();
128
                File f = new File(extractDir + File.separator + entryName);
129
130
                if (entryName.endsWith("/") && !f.exists()) { // this is a
131
                    // directory
132
                    f.mkdirs();
133
                    continue;
134
                }
135
136
                // This is a file. Carry out File processing
137
                int lastIndexOfSlash = entryName.lastIndexOf("/");
138
                String dirPath = "";
139
                if (lastIndexOfSlash != -1) {
140
                    dirPath = entryName.substring(0, lastIndexOfSlash);
141
                    File dir = new File(extractDir + File.separator + dirPath);
142
                    if (!dir.exists()) {
143
                        dir.mkdirs();
144
                    }
145
                }
146
147
                if (!f.isDirectory()) {
148
                    OutputStream out = new FileOutputStream(f);
149
                    byte[] buf = new byte[40960];
150
151
                    // Transfer bytes from the ZIP file to the output file
152
                    int len;
153
                    while ((len = zin.read(buf)) > 0) {
154
                        out.write(buf, 0, len);
155
                    }
156
                }
157
            }
158
        } catch (IOException e) {
159
            String msg = "Cannot unzip archive. It is probably corrupt";
160
            System.err.println(msg);
161
            e.printStackTrace();
162
            throw e;
163
        } finally {
164
            try {
165
                if (zin != null) {
166
                    zin.close();
167
                }
168
            } catch (IOException e) {
169
                e.printStackTrace();
170
            }
171
        }
172
    }
173
174
    /**
175
     * Utility method used by archive methods
176
     * @param zipDir
177
     * @param zos
178
     * @throws IOException
179
     */
180
    private void zipDir(File zipDir, ZipOutputStream zos) throws IOException {
181
        //get a listing of the directory content
182
        String[] dirList = zipDir.list();
183
        byte[] readBuffer = new byte[40960];
184
        int bytesIn = 0;
185
        //loop through dirList, and zip the files
186
        for (int i = 0; i < dirList.length; i++) {
187
            File f = new File(zipDir, dirList[i]);
188
            //place the zip entry in the ZipOutputStream object
189
            zos.putNextEntry(new ZipEntry(getZipEntryPath(f)));
190
            if (f.isDirectory()) {
191
                //if the File object is a directory, call this
192
                //function again to add its content recursively
193
                zipDir(f, zos);
194
                //loop again
195
                continue;
196
            }
197
            //if we reached here, the File object f was not a directory
198
            //create a FileInputStream on top of f
199
            FileInputStream fis = new FileInputStream(f);
200
201
            //now write the content of the file to the ZipOutputStream
202
            while ((bytesIn = fis.read(readBuffer)) != -1) {
203
                zos.write(readBuffer, 0, bytesIn);
204
            }
205
            //close the Stream
206
            fis.close();
207
        }
208
    }
209
210
    private String getZipEntryPath(File f) {
211
        String entryPath = f.getPath();
212
        entryPath = entryPath.substring(archiveSourceDir.length() + 1);
213
        if (File.separatorChar == '\\') {
214
            entryPath = entryPath.replace(File.separatorChar, '/');
215
        }
216
        if (f.isDirectory()) {
217
            entryPath += "/";
218
        }
219
        return entryPath;
220
    }
221
}
(-)build.properties (-1 / +3 lines)
Lines 12-17 Link Here
12
# 20070130   168762 sandakith@wso2.com - Lahiru Sandakith, Initial code to introduse the 
12
# 20070130   168762 sandakith@wso2.com - Lahiru Sandakith, Initial code to introduse the 
13
#											Axis2 runtime to the framework for 168762
13
#											Axis2 runtime to the framework for 168762
14
# 20070502   184302 sandakith@wso2.com - Lahiru Sandakith, Fix copyright for Axis2 plugins
14
# 20070502   184302 sandakith@wso2.com - Lahiru Sandakith, Fix copyright for Axis2 plugins
15
# 20090305   168937 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar import
15
###############################################################################
16
###############################################################################
16
source.. = src/
17
source.. = src/
17
output.. = bin/
18
output.. = bin/
Lines 20-23 Link Here
20
               META-INF/,\
21
               META-INF/,\
21
               .,\
22
               .,\
22
               plugin.properties,\
23
               plugin.properties,\
23
               about.html
24
               about.html,\
25
               icons/
(-)plugin.xml (-1 / +11 lines)
Lines 16-20 Link Here
16
              property="ClientProject"
16
              property="ClientProject"
17
              transform="org.eclipse.jst.ws.internal.common.StringToIProjectTransformer"/>
17
              transform="org.eclipse.jst.ws.internal.common.StringToIProjectTransformer"/>
18
    </extension> 
18
    </extension> 
19
19
    <extension point="org.eclipse.ui.importWizards">
20
        <wizard id="org.eclipse.jst.ws.axis2.importaar" name="AAR file" 
21
            category="org.eclipse.jst.ws.consumption.ui.wsimport.category"
22
            class="org.eclipse.jst.ws.internal.axis2.consumption.ui.widgets.imports.AARImportWizard"
23
            icon="./icons/aar.ico">
24
            <description>
25
                    Import axis2 archive to workspace.  
26
            </description> 
27
            <selection class="org.eclipse.core.resources.IProject"/> 
28
        </wizard> 
29
    </extension>
20
</plugin>
30
</plugin>
(-)src/org/eclipse/jst/ws/internal/axis2/consumption/ui/widgets/imports/AARImportWizard.java (+119 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 WSO2 Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * WSO2 Inc. - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
12
 * 20090305	  168937 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar import
13
 *******************************************************************************/
14
15
package org.eclipse.jst.ws.internal.axis2.consumption.ui.widgets.imports;
16
17
import java.io.File;
18
import java.io.IOException;
19
import java.lang.reflect.InvocationTargetException;
20
21
import org.eclipse.core.internal.resources.Resource;
22
import org.eclipse.core.resources.IFolder;
23
import org.eclipse.core.resources.IProject;
24
import org.eclipse.core.runtime.IPath;
25
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.NullProgressMonitor;
27
import org.eclipse.core.runtime.Path;
28
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.jface.operation.IRunnableWithProgress;
30
import org.eclipse.jface.viewers.IStructuredSelection;
31
import org.eclipse.jface.wizard.Wizard;
32
import org.eclipse.jst.ws.axis2.core.utils.ArchiveManipulator;
33
import org.eclipse.ui.IImportWizard;
34
import org.eclipse.ui.IWorkbench;
35
36
public class AARImportWizard extends Wizard implements IImportWizard{
37
	private AARImportWizardPage mainPage;
38
	private IStructuredSelection selection;
39
	private IProject selectedProject;
40
	
41
	@Override
42
	public boolean performFinish() {
43
		IRunnableWithProgress op = new IRunnableWithProgress() {
44
			public void run(IProgressMonitor monitor) throws InvocationTargetException {
45
				try {
46
					doFinish(monitor);
47
				} catch (Exception e) {
48
					throw new InvocationTargetException(e);
49
				} finally {
50
					monitor.done();
51
				}
52
			}
53
		};
54
		try {
55
			getContainer().run(true, false, op);
56
		} catch (InterruptedException e) {
57
			return false;
58
		} catch (InvocationTargetException e) {
59
			Throwable realException = e.getTargetException();
60
			realException.printStackTrace();
61
			if (realException.getMessage().trim().equalsIgnoreCase(""))
62
				MessageDialog.openError(getShell(), "Error", "Error occured while importing the service archive.");
63
			else
64
				MessageDialog.openError(getShell(), "Error", realException.getMessage());
65
			return false;
66
		}
67
		MessageDialog.openInformation(getShell(), "Axis2 Archive", "Axis2 archive imported successfully.");
68
		
69
		return true;	
70
	}
71
72
	public void init(IWorkbench arg0, IStructuredSelection arg1) {
73
		this.selection=arg1;
74
		if (selection.getFirstElement() instanceof IProject){
75
			selectedProject=(IProject)selection.getFirstElement();
76
		}
77
	}
78
	public void addPages() {
79
		super .addPages();
80
		
81
		mainPage = new AARImportWizardPage("AAR Export Wizard",selectedProject);
82
		addPage(mainPage);
83
	}
84
	
85
	private void doFinish(IProgressMonitor monitor) throws Exception {
86
		
87
		IFolder selectedServicesPath = mainPage.getSelectedServicesPath();
88
		
89
    	IPath selectedServicePath = selectedServicesPath.getLocation();
90
91
    	try {
92
93
	    	IPath serviceArchiveLocation = new Path(mainPage.getArchiveFileName());
94
			ArchiveManipulator archiveManipulator = new ArchiveManipulator();
95
			Path path = new Path(selectedServicePath.toOSString());
96
			String filename = serviceArchiveLocation.segments()[serviceArchiveLocation.segmentCount()-1];
97
			String fileExtension = serviceArchiveLocation.getFileExtension();
98
			filename=filename.substring(0,filename.length()-fileExtension.length()-1);
99
			IPath newServiceIPath = path.append(filename);
100
			String newServicePath = newServiceIPath.toOSString();
101
			File file = new File(newServicePath);
102
			int i=1;
103
			while(file.exists()){
104
				path.removeLastSegments(1);
105
				newServiceIPath=path.append(filename+"_"+i);
106
				newServicePath = newServiceIPath.toOSString();
107
				file = new File(newServicePath);
108
				i=i+1;
109
			}
110
			file.mkdirs();
111
			archiveManipulator.extract(serviceArchiveLocation.toOSString(), newServicePath);
112
			mainPage.getSelectedProject().refreshLocal(Resource.DEPTH_INFINITE, new NullProgressMonitor());
113
		} catch (IOException e) {
114
			throw e;
115
		}
116
	}
117
118
}
119
                
(-)src/org/eclipse/jst/ws/internal/axis2/consumption/ui/widgets/imports/AARImportWizardPage.java (+208 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 WSO2 Inc. and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 * WSO2 Inc. - initial API and implementation
10
 * yyyymmdd bug      Email and other contact information
11
 * -------- -------- -----------------------------------------------------------
12
 * 20090305	  168937 samindaw@wso2.com  - Saminda Wijeratne, Initial code to introduce aar import
13
 *******************************************************************************/
14
15
package org.eclipse.jst.ws.internal.axis2.consumption.ui.widgets.imports;
16
17
import java.io.File;
18
19
import org.eclipse.core.resources.IFolder;
20
import org.eclipse.core.resources.IProject;
21
import org.eclipse.core.resources.ResourcesPlugin;
22
import org.eclipse.jface.wizard.WizardPage;
23
import org.eclipse.jst.ws.axis2.core.utils.Axis2CoreUtils;
24
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.events.ModifyEvent;
26
import org.eclipse.swt.events.ModifyListener;
27
import org.eclipse.swt.events.SelectionAdapter;
28
import org.eclipse.swt.events.SelectionEvent;
29
import org.eclipse.swt.layout.GridData;
30
import org.eclipse.swt.layout.GridLayout;
31
import org.eclipse.swt.widgets.Button;
32
import org.eclipse.swt.widgets.Combo;
33
import org.eclipse.swt.widgets.Composite;
34
import org.eclipse.swt.widgets.FileDialog;
35
import org.eclipse.swt.widgets.Label;
36
import org.eclipse.swt.widgets.Text;
37
38
public class AARImportWizardPage extends WizardPage {
39
	private String archiveFileName="";
40
	private Text deployInWorkspaceText;
41
	private Combo projectSelectionCombo;
42
    private String serviceToArchive;
43
    private IProject selectedProject;
44
    
45
	protected AARImportWizardPage(String pageName, IProject selectedProject) {
46
		super(pageName);
47
		if (selectedProject!=null)
48
			this.selectedProject=selectedProject;
49
		setTitle("Axis2 Service Archive Importer");
50
		setDescription("Import axis2 service archive");
51
	}
52
53
	public void createControl(Composite parent) {
54
		Composite container = new Composite(parent, SWT.NULL);
55
		GridLayout layout = new GridLayout();
56
		container.setLayout(layout);
57
		layout.numColumns = 3;
58
		layout.verticalSpacing = 5;
59
		GridData gd;
60
		Label label;	
61
		
62
		
63
		label=new Label(container,SWT.NULL);
64
		gd = new GridData(GridData.FILL_HORIZONTAL);
65
		gd.horizontalSpan = 1;
66
		label.setLayoutData(gd);
67
		label.setText("Import AAR");
68
		
69
70
		deployInWorkspaceText = new Text(container, SWT.BORDER | SWT.SINGLE);
71
		gd = new GridData(GridData.FILL_HORIZONTAL);
72
		deployInWorkspaceText.setLayoutData(gd);
73
		deployInWorkspaceText.addModifyListener(new ModifyListener() {
74
			public void modifyText(ModifyEvent e) {
75
				handleDeployInWorkspaceText();
76
			}
77
		});
78
		
79
		Button deployInWorkspaceBrowseButton = new Button(container, SWT.PUSH);
80
		deployInWorkspaceBrowseButton.setText("Browse");
81
		deployInWorkspaceBrowseButton.addSelectionListener(new SelectionAdapter() {
82
			public void widgetSelected(SelectionEvent e) {
83
				handledeployInWorkspaceBrowseButton();
84
			}
85
		});
86
		
87
		label=new Label(container,SWT.NULL);
88
		gd = new GridData(GridData.FILL_HORIZONTAL);
89
		label.setLayoutData(gd);
90
		gd.horizontalSpan=3;
91
		
92
		label=new Label(container,SWT.NULL);
93
		gd = new GridData(GridData.FILL_HORIZONTAL);
94
		label.setLayoutData(gd);
95
		gd.horizontalSpan=1;
96
		label.setText("Web project");
97
		
98
		gd = new GridData(GridData.FILL_HORIZONTAL);
99
		gd.horizontalSpan=2;
100
		projectSelectionCombo = new Combo(container,SWT.NONE | SWT.READ_ONLY);
101
		projectSelectionCombo.setLayoutData(gd);
102
		projectSelectionCombo.addModifyListener(new ModifyListener(){
103
			public void modifyText(ModifyEvent arg0) {
104
				fillServiceSelectionCombo();
105
			}
106
			
107
		}); 
108
109
		fillProjectSelectionCombo();
110
		
111
		
112
		
113
		
114
		deployInWorkspaceText.setText("");
115
		handleDeployInWorkspaceText();
116
		setControl(parent);
117
	}
118
	
119
	private void fillServiceSelectionCombo(){
120
		if (projectSelectionCombo.getSelectionIndex()==-1) return;
121
		IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectSelectionCombo.getText());
122
		selectedProject=project;
123
	}
124
	
125
	private void fillProjectSelectionCombo(){
126
		String[] webProjects=Axis2CoreUtils.getWorkspaceWebProjectList();
127
		projectSelectionCombo.removeAll();
128
		
129
		for(String project:webProjects){
130
			projectSelectionCombo.add(project);
131
			if (project.equals(selectedProject.getName()))
132
				projectSelectionCombo.select(projectSelectionCombo.getItemCount()-1);
133
		}
134
		
135
		if (projectSelectionCombo.getSelectionIndex()==-1 && projectSelectionCombo.getItemCount()>0)
136
			projectSelectionCombo.select(0);
137
	}
138
139
	protected void handledeployInWorkspaceBrowseButton() {
140
		String fileName=getImportFile();
141
		if (fileName!=null){
142
			deployInWorkspaceText.setText(fileName);
143
		}
144
	}
145
146
	protected void handleDeployInWorkspaceText() {
147
		this.setArchiveFileName(deployInWorkspaceText.getText());
148
		setImportLocationStatusMsg();
149
	}
150
151
	private void setImportLocationStatusMsg(){
152
		String msg=null;
153
		File file = new File(getArchiveFileName());
154
    	if (getArchiveFileName().equalsIgnoreCase("") || !file.exists())
155
    		msg="Specified path to the file should be valid";
156
    	else if (!file.getName().toLowerCase().endsWith(".aar"))
157
    		msg="The selected file should have .aar extension";
158
    	else  
159
    		setDescription("Export axis2 service archive");
160
    	updateStatus(msg);
161
	}
162
	
163
	private void updateStatus(String msg){
164
		if (projectSelectionCombo.getSelectionIndex()==-1)
165
			msg="No Web Project available in the workspace to import the Axis2 Archive";
166
		setErrorMessage(msg);
167
		setPageComplete(msg==null);
168
	}
169
	
170
	private String getImportFile(){
171
		String fileName = null;
172
		FileDialog dlg = new FileDialog(getShell());
173
	    fileName = dlg.open();
174
	    return fileName;
175
	}
176
177
	public void setArchiveFileName(String archiveFileName) {
178
		this.archiveFileName = archiveFileName;
179
	}
180
181
	public String getArchiveFileName() {
182
		return archiveFileName;
183
	}
184
	
185
186
	/**
187
	 * @param serviceToArchive the serviceToArchive to set
188
	 */
189
	public void setServiceToArchive(String serviceToArchive) {
190
		this.serviceToArchive = serviceToArchive;
191
	}
192
193
	/**
194
	 * @return the serviceToArchive
195
	 */
196
	public String getServiceToArchive() {
197
		return serviceToArchive;
198
	}
199
	
200
	public IFolder getSelectedServicesPath(){
201
		return Axis2CoreUtils.getServicesFolderofProject(selectedProject);
202
203
	}
204
	
205
	public IProject getSelectedProject(){
206
		return selectedProject;
207
	}
208
}

Return to bug 168937