Subversion Repositories XServices

Rev

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

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