Subversion Repositories XServices

Rev

Rev 30 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30 Rev 39
Line 17... Line 17...
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;
Line -... Line 21...
-
 
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;
Line 23... Line 28...
23
import net.brutex.mylyn.sbmconnector.core.SBMClient;
28
import net.brutex.mylyn.sbmconnector.core.model.SBMSystemFields;
24
 
29
 
-
 
30
import org.eclipse.core.runtime.CoreException;
25
import org.eclipse.core.runtime.CoreException;
31
import org.eclipse.core.runtime.IProgressMonitor;
26
import org.eclipse.core.runtime.IProgressMonitor;
32
import org.eclipse.jface.dialogs.IMessageProvider;
-
 
33
import org.eclipse.mylyn.tasks.core.TaskRepository;
-
 
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;
27
import org.eclipse.mylyn.tasks.core.TaskRepository;
39
import org.eclipse.swt.layout.GridLayout;
-
 
40
import org.eclipse.swt.widgets.Combo;
-
 
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;
Line 28... Line 48...
28
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
48
import org.eclipse.ui.forms.widgets.ExpandableComposite;
Line -... Line 49...
-
 
49
import org.eclipse.ui.forms.widgets.FormToolkit;
-
 
50
 
-
 
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";
29
import org.eclipse.swt.widgets.Composite;
62
	public static final String STRING_SOLUTIONTABLELIST = "solutionTableList";
30
 
63
	public static final String STRING_TABLEFIELDLIST = "tableFieldList";
31
public class SBMRepositorySettingsPage extends AbstractRepositorySettingsPage {
64
	public static final String STRING_TABLEFULLFIELDLIST = "tableFullFieldList";
-
 
65
 
-
 
66
	public SBMRepositorySettingsPage(String title, String description,
-
 
67
			TaskRepository taskRepository) {
32
 
68
		super(title, description, taskRepository);
-
 
69
		setNeedsAdvanced(false);
-
 
70
		setNeedsValidation(true);
-
 
71
		setNeedsEncoding(false);
-
 
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
		}
33
	public SBMRepositorySettingsPage(String title, String description,
85
		if (taskRepository.hasProperty(STRING_TABLEFULLFIELDLIST)) {
Line 34... Line 86...
34
			TaskRepository taskRepository) {
86
			this.tableFullFieldList = taskRepository
35
		super(title, description, taskRepository);
87
					.getProperty(STRING_TABLEFULLFIELDLIST);
-
 
88
		}
36
		// TODO Auto-generated constructor stub
89
	}
-
 
90
 
-
 
91
	@Override
-
 
92
	public void applyTo(TaskRepository repository) {
-
 
93
		super.applyTo(repository);
-
 
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) + ",";
Line -... Line 103...
-
 
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();
37
	}
177
				}
Line 38... Line 178...
38
 
178
			}
39
	@Override
179
 
40
	protected void createAdditionalControls(Composite parent) {
180
		});
Line 52... Line 192...
52
		return new SBMConnectionValidator(repository);
192
		return new SBMConnectionValidator(repository);
53
	}
193
	}
Line 54... Line 194...
54
 
194
 
55
	@Override
195
	@Override
56
	protected boolean isValidUrl(String url) {
196
	protected boolean isValidUrl(String url) {
-
 
197
		if (url.contains("<server>"))
57
		if(url.contains("<server>")) return false;
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) {
-
 
204
		if (((SBMConnectionValidator) validator).getResult() != null) {
-
 
205
			setMessage("Validate first!", IMessageProvider.ERROR);
-
 
206
			setNeedsValidation(true);
63
		if (((SBMConnectionValidator) validator).getResult() != null) {
207
		} else {
64
			getContainer().updateButtons();
208
			regenerateTables();
65
		}
-
 
66
		super.applyValidatorResult(validator);
209
		}
67
	}
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);
-
 
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
 
-
 
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()) {
-
 
253
				result = "Verbindung fehlgeschlagen";
-
 
254
			} else {
82
				result = "Verbindung fehlgeschlagen";
255
				result = null;
83
			}
-
 
84
			result = "Verbindung erfolgreich";
256
			}
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();
88
		public String getResult() { return result; }
290
		}
89
	}
291
	}
-
 
292
 
-
 
293
	@Override
-
 
294
	protected void createAdditionalControls(Composite arg0) {
-
 
295
		// TODO Auto-generated method stub
-
 
296
 
-
 
297
	}
90
	
298