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 |
} |