Subversion Repositories XServices

Rev

Rev 39 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 brianR 1
/*
2
 *   Mylyn Connector for Serena Business Mashups
3
 * 	 Copyright 2010 Brian Rosenberger (Brutex Network)
4
 *
5
 *   Licensed under the Apache License, Version 2.0 (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
8
 *
9
 *       http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 *   Unless required by applicable law or agreed to in writing, software
12
 *   distributed under the License is distributed on an "AS IS" BASIS,
13
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 *   See the License for the specific language governing permissions and
15
 *   limitations under the License.
16
 *
17
 *   Serena, TeamTrack and Serena Business Mashup are
18
 * 	 registered trademarks of SERENA Software Inc.
19
 */
20
package net.brutex.mylyn.sbmconnector.ui;
21
 
22
import net.brutex.mylyn.sbmconnector.SBMConnectorPlugin;
23
import net.brutex.mylyn.sbmconnector.core.SBMClient;
24
 
25
import org.eclipse.core.runtime.CoreException;
26
import org.eclipse.core.runtime.IProgressMonitor;
27
import org.eclipse.mylyn.tasks.core.TaskRepository;
28
import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositorySettingsPage;
29
import org.eclipse.swt.widgets.Composite;
30
 
31
public class SBMRepositorySettingsPage extends AbstractRepositorySettingsPage {
32
 
33
	public SBMRepositorySettingsPage(String title, String description,
34
			TaskRepository taskRepository) {
35
		super(title, description, taskRepository);
36
		// TODO Auto-generated constructor stub
37
	}
38
 
39
	@Override
40
	protected void createAdditionalControls(Composite parent) {
41
		// TODO Auto-generated method stub
42
 
43
	}
44
 
45
	@Override
46
	public String getConnectorKind() {
47
		return SBMConnectorPlugin.CONNECTOR_KIND;
48
	}
49
 
50
	@Override
51
	protected Validator getValidator(TaskRepository repository) {
52
		return new SBMConnectionValidator(repository);
53
	}
54
 
55
	@Override
56
	protected boolean isValidUrl(String url) {
57
		if(url.contains("<server>")) return false;
58
		return true;
59
	}
60
 
61
	@Override
62
	protected void applyValidatorResult(Validator validator) {
63
		if (((SBMConnectionValidator) validator).getResult() != null) {
64
			getContainer().updateButtons();
65
		}
66
		super.applyValidatorResult(validator);
67
	}
68
 
69
	protected class SBMConnectionValidator extends Validator {
70
		private TaskRepository repository;
71
		private String result = null;
72
 
73
		protected SBMConnectionValidator(TaskRepository repository) {
74
		this.repository = repository;
75
		}
76
 
77
		@Override
78
		public void run(IProgressMonitor monitor) throws CoreException {
79
			monitor.beginTask("Prüfe Verbindung", IProgressMonitor.UNKNOWN);
80
			SBMClient client = new SBMClient(repository);
81
			if(!client.canAuthenticate()) {
82
				result = "Verbindung fehlgeschlagen";
83
			}
84
			result = "Verbindung erfolgreich";
85
			monitor.done();
86
		}
87
 
88
		public String getResult() { return result; }
89
	}
90
 
91
}