Subversion Repositories XServices

Rev

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

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