Show CheckAsFitProjectController.java syntax highlighted
package ca.ucalgary.cpsc.ebe.fitClipse.dialogs;
import java.io.File;
import java.util.StringTokenizer;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import ca.ucalgary.cpsc.ebe.fitClipse.connector.ServerConfiguration;
import ca.ucalgary.cpsc.ebe.fitClipse.runner.FITTestConfiguration;
public class CheckAsFitProjectController {
IProject project = null;
public CheckAsFitProjectController(IProject project) {
this.project = project;
}
public void performOK(ServerConfiguration config, FITTestConfiguration FTconfig, Shell shell, Text txt) throws Exception {
persistProjectNameSpace(txt);
persistServerConfiguration(config);
persistClassPath(FTconfig, shell);
}
private void persistProjectNameSpace(Text txt) {
String nameSpace = txt.getText();
try {
project.setPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse", "project.namspace"), nameSpace);
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void persistClassPath(FITTestConfiguration FTconfig, Shell shell){
File dir = new File(FTconfig.getTestSourceLoc());
if(!dir.exists()){
//pop up a question
if(MessageDialog.openQuestion(shell, "Directory Does Not Exist!", "The directory " + FTconfig.getTestSourceLoc() + " does not exist, create it?")){
dir.mkdirs();
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
}else{
return;
}
}
dir = new File(FTconfig.getTestResultLoc());
if(!dir.exists()){
if(MessageDialog.openQuestion(shell, "Directory Does Not Exist!", "The directory " + FTconfig.getTestResultLoc() + " does not exist, create it?")){
dir.mkdirs();
try {
project.refreshLocal(IResource.DEPTH_INFINITE, null);
} catch (CoreException e) {
e.printStackTrace();
}
}else{
return;
}
}
StringBuffer linkedPaths = new StringBuffer();
String[] paths = FTconfig.getClassPath();
for(String path: paths){
linkedPaths.append(path).append(";");
}
try {
project.setPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.classpath"), linkedPaths.toString());
project.setPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.src"), FTconfig.getTestSourceLoc());
project.setPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.result"), FTconfig.getTestResultLoc());
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
private void persistServerConfiguration(ServerConfiguration config) {
try {
project.setPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.host"), config
.getHost());
project.setPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.beanPort"),
config.getBeanPort());
project.setPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.webPort"), config
.getWebPort());
project.setPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.username"),
config.getUsername());
project.setPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.password"),
config.getPassword());
} catch (CoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void loadHostValue(Text txt, boolean defaultVal) {
if (defaultVal) {
txt.setText(ServerConfiguration.DEFAULT_HOST);
return;
}
try {
String value = null;
if ((value = project.getPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.host"))) != null) {
txt.setText(value);
} else {
txt.setText(ServerConfiguration.DEFAULT_HOST);
}
} catch (Exception e) {
}
}
public void loadBeanPortValue(Text txt, boolean defaultVal) {
if (defaultVal) {
txt.setText(ServerConfiguration.DEFAULT_BEAN_PORT);
return;
}
try {
String value = null;
if ((value = project.getPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.beanPort"))) != null) {
txt.setText(value);
} else {
txt.setText(ServerConfiguration.DEFAULT_BEAN_PORT);
}
} catch (Exception e) {
}
}
public void loadWebPortValue(Text txt, boolean defaultVal) {
if (defaultVal) {
txt.setText(ServerConfiguration.DEFAULT_WEB_PORT);
return;
}
try {
String value = null;
if ((value = project.getPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.webPort"))) != null) {
txt.setText(value);
} else {
txt.setText(ServerConfiguration.DEFAULT_WEB_PORT);
}
} catch (Exception e) {
}
}
public void loadUsernameValue(Text txt, boolean defaultVal) {
if (defaultVal) {
txt.setText(ServerConfiguration.DEFAULT_USERNAME);
return;
}
try {
String value = null;
if ((value = project.getPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.username"))) != null) {
txt.setText(value);
} else {
txt.setText(ServerConfiguration.DEFAULT_USERNAME);
}
} catch (Exception e) {
}
}
public void loadPasswordValue(Text txt, boolean defaultVal) {
if (defaultVal) {
txt.setText(ServerConfiguration.DEFAULT_PASSWORD);
return;
}
try {
String value = null;
if ((value = project.getPersistentProperty(new QualifiedName(
"ca.ucalgary.cpsc.ebe.fitClipse", "server.password"))) != null) {
txt.setText(value);
} else {
txt.setText(ServerConfiguration.DEFAULT_PASSWORD);
}
} catch (Exception e) {
}
}
public void loadClassPath(List classPath, boolean defaultVal){
try{
String[] paths = null;
if(defaultVal){
FITTestConfiguration config = new FITTestConfiguration(project);
paths = config.DEFAULT_PATH;
}else{
String linkedPath = project.getPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.classpath"));
StringTokenizer tokens = new StringTokenizer(linkedPath, ";");
int numPaths = tokens.countTokens();
paths = new String[numPaths];
for(int i = 0; tokens.hasMoreTokens(); i++){
String path = tokens.nextToken();
paths[i] = path;
}
}
classPath.removeAll();
for(int i = 0; i < paths.length; i++){
classPath.add(paths[i]);
}
}catch(Exception e){}
}
public void loadTestSourcePath(Text txt, boolean defaultVal){
try{
String srcPath = null;
if(defaultVal){
FITTestConfiguration config = new FITTestConfiguration(project);
srcPath = config.DEFAULT_TEST_SOURCE_LOCATION;
}else{
srcPath = project.getPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.src"));
}
if(srcPath != null)
txt.setText(srcPath);
else
txt.setText("");
}catch(Exception e){}
}
public void loadTestResultPath(Text txt, boolean defaultVal){
try{
String resultPath = null;
if(defaultVal){
FITTestConfiguration config = new FITTestConfiguration(project);
resultPath = config.DEFAULT_TEST_RESULT_LOCATION;
}else{
resultPath = project.getPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse","test.result"));
}
if(resultPath != null)
txt.setText(resultPath);
else
txt.setText("");
}catch(Exception e){}
}
public void performApply(ServerConfiguration config) {
persistServerConfiguration(config);
}
public void loadNamespace(Text txt){
try {
String nameSpace = project.getPersistentProperty(new QualifiedName("ca.ucalgary.cpsc.ebe.fitClipse", "project.namspace"));
if(nameSpace == null)
nameSpace = "";
txt.setText(nameSpace);
} catch (CoreException e) {
e.printStackTrace();
}
}
}
See more files for this project here