Subversion Repositories XServices

Rev

Rev 30 | Rev 52 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 39
1
/*
1
/*
2
 *   Mylyn Connector for Serena Business Mashups
2
 *   Mylyn Connector for Serena Business Mashups
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
4
 *
4
 *
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
5
 *   Licensed under the Apache License, Version 2.0 (the "License");
6
 *   you may not use this file except in compliance with the License.
6
 *   you may not use this file except in compliance with the License.
7
 *   You may obtain a copy of the License at
7
 *   You may obtain a copy of the License at
8
 *
8
 *
9
 *       http://www.apache.org/licenses/LICENSE-2.0
9
 *       http://www.apache.org/licenses/LICENSE-2.0
10
 *
10
 *
11
 *   Unless required by applicable law or agreed to in writing, software
11
 *   Unless required by applicable law or agreed to in writing, software
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *   See the License for the specific language governing permissions and
14
 *   See the License for the specific language governing permissions and
15
 *   limitations under the License.
15
 *   limitations under the License.
16
 * 
16
 * 
17
 *   Serena, TeamTrack and Serena Business Mashup are 
17
 *   Serena, TeamTrack and Serena Business Mashup are 
18
 * 	 registered trademarks of SERENA Software Inc.
18
 * 	 registered trademarks of SERENA Software Inc.
19
 */
19
 */
20
package net.brutex.mylyn.sbmconnector.ui;
20
package net.brutex.mylyn.sbmconnector.ui;
-
 
21
 
-
 
22
import java.util.List;
21
 
23
 
22
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
24
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
-
 
25
import net.brutex.mylyn.sbmconnector.core.SBMClient;
-
 
26
import net.brutex.mylyn.sbmconnector.core.SBMRepositoryConnector;
-
 
27
import net.brutex.mylyn.sbmconnector.core.model.SBMField;
23
import net.brutex.mylyn.sbmconnector.core.SBMClient;
28
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
24
 
29
 
25
import org.eclipse.core.runtime.CoreException;
30
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IProgressMonitor;
31
import org.eclipse.core.runtime.IProgressMonitor;
-
 
32
import org.eclipse.jface.dialogs.IMessageProvider;
27
import org.eclipse.mylyn.tasks.core.TaskRepository;
33
import org.eclipse.mylyn.tasks.core.TaskRepository;
28
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
34
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
-
 
35
import org.eclipse.swt.SWT;
-
 
36
import org.eclipse.swt.events.ModifyEvent;
-
 
37
import org.eclipse.swt.events.ModifyListener;
-
 
38
import org.eclipse.swt.layout.GridData;
-
 
39
import org.eclipse.swt.layout.GridLayout;
-
 
40
import org.eclipse.swt.widgets.Combo;
29
import org.eclipse.swt.widgets.Composite;
41
import org.eclipse.swt.widgets.Composite;
-
 
42
import org.eclipse.swt.widgets.Event;
-
 
43
import org.eclipse.swt.widgets.Label;
-
 
44
import org.eclipse.swt.widgets.Listener;
-
 
45
import org.eclipse.swt.widgets.Table;
-
 
46
import org.eclipse.swt.widgets.TableColumn;
-
 
47
import org.eclipse.swt.widgets.TableItem;
-
 
48
import org.eclipse.ui.forms.widgets.ExpandableComposite;
-
 
49
import org.eclipse.ui.forms.widgets.FormToolkit;
30
 
50
 
31
public class SBMRepositorySettingsPage extends AbstractRepositorySettingsPage {
51
public class SBMRepositorySettingsPage extends AbstractRepositorySettingsPage {
-
 
52
 
-
 
53
	private Combo table;
-
 
54
	private Table list;
-
 
55
 
-
 
56
	private String solutionTable = "";
-
 
57
	private String solutionTableList = "";
-
 
58
	private String tableFieldList = "";
-
 
59
	private String tableFullFieldList = "";
-
 
60
 
-
 
61
	public static final String STRING_SOLUTIONTABLE = "solutionTable";
-
 
62
	public static final String STRING_SOLUTIONTABLELIST = "solutionTableList";
-
 
63
	public static final String STRING_TABLEFIELDLIST = "tableFieldList";
-
 
64
	public static final String STRING_TABLEFULLFIELDLIST = "tableFullFieldList";
32
 
65
 
33
	public SBMRepositorySettingsPage(String title, String description,
66
	public SBMRepositorySettingsPage(String title, String description,
34
			TaskRepository taskRepository) {
67
			TaskRepository taskRepository) {
35
		super(title, description, taskRepository);
68
		super(title, description, taskRepository);
-
 
69
		setNeedsAdvanced(false);
-
 
70
		setNeedsValidation(true);
-
 
71
		setNeedsEncoding(false);
36
		// TODO Auto-generated constructor stub
72
		// initialize table and table list if not null
-
 
73
		if (taskRepository.hasProperty(STRING_SOLUTIONTABLE)) {
-
 
74
			this.solutionTable = taskRepository
-
 
75
					.getProperty(STRING_SOLUTIONTABLE);
-
 
76
		}
-
 
77
		if (taskRepository.hasProperty(STRING_SOLUTIONTABLELIST)) {
-
 
78
			this.solutionTableList = taskRepository
-
 
79
					.getProperty(STRING_SOLUTIONTABLELIST);
-
 
80
		}
-
 
81
		if (taskRepository.hasProperty(STRING_TABLEFIELDLIST)) {
-
 
82
			this.tableFieldList = taskRepository
-
 
83
					.getProperty(STRING_TABLEFIELDLIST);
-
 
84
		}
-
 
85
		if (taskRepository.hasProperty(STRING_TABLEFULLFIELDLIST)) {
-
 
86
			this.tableFullFieldList = taskRepository
-
 
87
					.getProperty(STRING_TABLEFULLFIELDLIST);
-
 
88
		}
37
	}
89
	}
38
 
90
 
39
	@Override
91
	@Override
40
	protected void createAdditionalControls(Composite parent) {
92
	public void applyTo(TaskRepository repository) {
-
 
93
		super.applyTo(repository);
41
		// TODO Auto-generated method stub
94
		if (!solutionTable.isEmpty()) {
-
 
95
			repository.setProperty(STRING_SOLUTIONTABLE, solutionTable);
-
 
96
			repository.setProperty(STRING_SOLUTIONTABLELIST, solutionTableList);
-
 
97
			String fieldlist = ",";
-
 
98
			String fullfieldlist = ",";
-
 
99
			for (TableItem t : list.getItems()) {
-
 
100
				if (t.getChecked())
-
 
101
					fieldlist = fieldlist + t.getText(2) + ",";
-
 
102
				fullfieldlist = fullfieldlist + t.getText(2) + ",";
-
 
103
			}
-
 
104
			repository.setProperty(STRING_TABLEFIELDLIST, fieldlist);
-
 
105
			repository.setProperty(STRING_TABLEFULLFIELDLIST, fullfieldlist);
-
 
106
		}
-
 
107
	}
-
 
108
 
-
 
109
	@Override
-
 
110
	public boolean isPageComplete() {
-
 
111
		if (table != null && table.getText().length() > 4) {
-
 
112
			return super.isPageComplete();
-
 
113
		}
-
 
114
		return false;
-
 
115
	}
-
 
116
 
-
 
117
	@Override
-
 
118
	protected void createContributionControls(Composite parentControl) {
-
 
119
		ExpandableComposite expander = createSection(parentControl,
-
 
120
				"Mashup application");
-
 
121
		FormToolkit toolkit = new FormToolkit(parentControl.getDisplay());
-
 
122
		Composite control = toolkit.createComposite(expander, SWT.NONE);
-
 
123
		GridLayout gridLayout = new GridLayout();
-
 
124
		gridLayout.numColumns = 2;
-
 
125
		gridLayout.verticalSpacing = 5;
-
 
126
		gridLayout.marginWidth = 0;
-
 
127
		control.setLayout(gridLayout);
-
 
128
		control.setBackground(parentControl.getBackground());
-
 
129
 
-
 
130
		Label label = new Label(control, SWT.NONE);
-
 
131
		label.setText("Table:");
-
 
132
 
-
 
133
		table = new Combo(control, SWT.SINGLE | SWT.BORDER);
-
 
134
		Label label_list = new Label(control, SWT.NONE | SWT.TOP);
-
 
135
		label_list.setText("Fields:");
-
 
136
		list = new Table(control, SWT.MULTI | SWT.BORDER | SWT.V_SCROLL
-
 
137
				| SWT.H_SCROLL | SWT.FULL_SELECTION | SWT.CHECK);
-
 
138
		list.setLinesVisible(true);
-
 
139
		list.setHeaderVisible(true);
-
 
140
		GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
-
 
141
		data.heightHint = 200;
-
 
142
		list.setLayoutData(data);
-
 
143
		String[] titles = { " ", "Display Name", "DBName", "Type" };
-
 
144
		for (int i = 0; i < titles.length; i++) {
-
 
145
			TableColumn column = new TableColumn(list, SWT.NONE);
-
 
146
			column.setText(titles[i]);
-
 
147
		}
-
 
148
		list.addListener(SWT.Selection, new Listener() {
-
 
149
			@Override
-
 
150
			public void handleEvent(Event event) {
-
 
151
				//avoid that a system field may be unchecked
-
 
152
				try {
-
 
153
					SBMSystemFields
-
 
154
							.valueOf(((TableItem) event.item).getText(2));
-
 
155
					((TableItem) event.item).setChecked(true);
-
 
156
				} catch (IllegalArgumentException e) {
-
 
157
					// do nothing
-
 
158
				}
-
 
159
			}
-
 
160
		});
-
 
161
		table.addListener(SWT.Selection, new Listener() {
-
 
162
			@Override
-
 
163
			public void handleEvent(Event arg0) {
-
 
164
				// when the table has been changed
-
 
165
				// try to re-read the field list
-
 
166
				tableFieldList = "";
-
 
167
				tableFullFieldList = "";
-
 
168
				try {
-
 
169
					SBMField[] fields = SBMRepositoryConnector.getClient(
-
 
170
						createTaskRepository()).getFields(table.getText())
-
 
171
						.toArray(new SBMField[0]);
-
 
172
				fillList(list, fields);
-
 
173
				} catch (Exception e) { }
-
 
174
				if (getWizard() != null) {
-
 
175
					solutionTable = table.getText();
-
 
176
					getWizard().getContainer().updateButtons();
-
 
177
				}
-
 
178
			}
-
 
179
 
-
 
180
		});
-
 
181
		regenerateTables();
42
 
182
		expander.setClient(control);
43
	}
183
	}
44
 
184
 
45
	@Override
185
	@Override
46
	public String getConnectorKind() {
186
	public String getConnectorKind() {
47
		return SBMConnectorPlugin.CONNECTOR_KIND;
187
		return SBMConnectorPlugin.CONNECTOR_KIND;
48
	}
188
	}
49
 
189
 
50
	@Override
190
	@Override
51
	protected Validator getValidator(TaskRepository repository) {
191
	protected Validator getValidator(TaskRepository repository) {
52
		return new SBMConnectionValidator(repository);
192
		return new SBMConnectionValidator(repository);
53
	}
193
	}
54
 
194
 
55
	@Override
195
	@Override
56
	protected boolean isValidUrl(String url) {
196
	protected boolean isValidUrl(String url) {
57
		if(url.contains("<server>")) return false;
197
		if (url.contains("<server>"))
-
 
198
			return false;
58
		return true;
199
		return true;
59
	}
200
	}
60
	
201
 
61
	@Override
202
	@Override
62
	protected void applyValidatorResult(Validator validator) {
203
	protected void applyValidatorResult(Validator validator) {
63
		if (((SBMConnectionValidator) validator).getResult() != null) {
204
		if (((SBMConnectionValidator) validator).getResult() != null) {
-
 
205
			setMessage("Validate first!", IMessageProvider.ERROR);
-
 
206
			setNeedsValidation(true);
-
 
207
		} else {
64
			getContainer().updateButtons();
208
			regenerateTables();
65
		}
209
		}
-
 
210
	}
-
 
211
 
-
 
212
	private void regenerateTables() {
-
 
213
		try {
-
 
214
			List<String> tables = SBMRepositoryConnector.getClient(
-
 
215
					createTaskRepository()).getPrimaryTables();
-
 
216
			for (String table_name : tables) {
-
 
217
				table.add(table_name);
66
		super.applyValidatorResult(validator);
218
				if (solutionTable.equals(table_name)) {
-
 
219
					table.setText(table_name);
-
 
220
				}
-
 
221
			}
-
 
222
		} catch (Exception e) {
-
 
223
			// it was not possible to read the list of tables
-
 
224
			// from the server, so just restore saved settings
-
 
225
			table.add(solutionTable);
-
 
226
			table.setText(solutionTable);
-
 
227
		}
-
 
228
		try {
-
 
229
		SBMField[] fields = SBMRepositoryConnector.getClient(
-
 
230
				createTaskRepository()).getFields(table.getText()).toArray(
-
 
231
				new SBMField[0]);
-
 
232
				fillList(list, fields);
-
 
233
		} catch (Exception e) {
-
 
234
			// it was not possible to read the fields for the given table
-
 
235
			// do nothing
-
 
236
		}
-
 
237
 
67
	}
238
	}
68
	
239
 
69
	protected class SBMConnectionValidator extends Validator {
240
	protected class SBMConnectionValidator extends Validator {
70
		private TaskRepository repository;
241
		private TaskRepository repository;
71
		private String result = null;
242
		private String result = null;
72
		
243
 
73
		protected SBMConnectionValidator(TaskRepository repository) {
244
		protected SBMConnectionValidator(TaskRepository repository) {
74
		this.repository = repository;
245
			this.repository = repository;
75
		}
246
		}
76
		
247
 
77
		@Override
248
		@Override
78
		public void run(IProgressMonitor monitor) throws CoreException {
249
		public void run(IProgressMonitor monitor) throws CoreException {
79
			monitor.beginTask("Prüfe Verbindung", IProgressMonitor.UNKNOWN);
250
			monitor.beginTask("Prüfe Verbindung", IProgressMonitor.UNKNOWN);
80
			SBMClient client = new SBMClient(repository);
251
			SBMClient client = new SBMClient(repository);
81
			if(!client.canAuthenticate()) {
252
			if (!client.canAuthenticate()) {
82
				result = "Verbindung fehlgeschlagen";
253
				result = "Verbindung fehlgeschlagen";
-
 
254
			} else {
-
 
255
				result = null;
83
			}
256
			}
84
			result = "Verbindung erfolgreich";
-
 
85
			monitor.done();
257
			monitor.done();
86
		}
258
		}
87
		
259
 
-
 
260
		public String getResult() {
-
 
261
			return result;
-
 
262
		}
-
 
263
	}
-
 
264
 
-
 
265
	private void fillList(Table list, SBMField[] fields) {
-
 
266
		list.removeAll();
-
 
267
		for (int i = 0; i < fields.length; i++) {
-
 
268
			TableItem item = new TableItem(list, 0);
-
 
269
			item.setText(0, "");
-
 
270
			item.setText(1, fields[i].getLabel());
-
 
271
			item.setText(2, fields[i].getName());
-
 
272
			item.setText(3, fields[i].getType().getValue().replaceFirst(
-
 
273
					"FLDTYPE-", ""));
-
 
274
			try {
-
 
275
				// auto-select all system fields
-
 
276
				SBMSystemFields.valueOf(fields[i].getName());
-
 
277
				item.setChecked(true);
-
 
278
			} catch (IllegalArgumentException e) {
-
 
279
				// do nothing
-
 
280
			}
-
 
281
			if (tableFieldList.contains(","+fields[i].getName()+",")) {
-
 
282
				// item has been checked before
-
 
283
				// so check it
-
 
284
				item.setChecked(true);
-
 
285
			}
-
 
286
		}
-
 
287
 
-
 
288
		for (TableColumn c : list.getColumns()) {
-
 
289
			c.pack();
-
 
290
		}
-
 
291
	}
-
 
292
 
-
 
293
	@Override
-
 
294
	protected void createAdditionalControls(Composite arg0) {
-
 
295
		// TODO Auto-generated method stub
88
		public String getResult() { return result; }
296
 
89
	}
297
	}
90
	
298
 
91
}
299
}