package com.gurkensalat.jenkinsci.plugins.transifex;

import hudson.Extension;
import hudson.model.AbstractProject;
import hudson.model.Action;
import hudson.model.Job;
import hudson.model.JobProperty;
import hudson.model.JobPropertyDescriptor;
import java.util.Collection;
import java.util.Collections;
import net.sf.json.JSONObject;

import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.StaplerRequest;

/**
 * Stores the Transifex related project properties.
 * <p>
 * As of now this is only the URL to the Transifex project.
 * 
 * @todo Should we store the TransifexUrl instead of the String?
 * @author Stefan Saasen <stefan@coravy.com>
 */
public final class TransifexProjectProperty extends JobProperty<AbstractProject<?, ?>>
{

	/**
	 * This will the URL to the project main branch.
	 */
	private String projectUrl;

	@DataBoundConstructor
	public TransifexProjectProperty(String projectUrl)
	{
		this.projectUrl = new TransifexUrl(projectUrl).baseUrl();
	}

	/**
	 * @return the projectUrl
	 */
	public TransifexUrl getProjectUrl()
	{
		return new TransifexUrl(projectUrl);
	}

	@Override
	public Collection<? extends Action> getJobActions(AbstractProject<?, ?> job)
	{
		if (null != projectUrl)
		{
			return Collections.singleton(new TransifexLinkAction(this));
		}
		return Collections.emptyList();
	}

	/*
	 * @Override public JobPropertyDescriptor getDescriptor() { return
	 * DESCRIPTOR; }
	 * 
	 * public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();
	 */
	@Extension
	public static final class DescriptorImpl extends JobPropertyDescriptor
	{

		public DescriptorImpl()
		{
			super(TransifexProjectProperty.class);
			load();
		}

		public boolean isApplicable(Class<? extends Job> jobType)
		{
			return AbstractProject.class.isAssignableFrom(jobType);
		}

		public String getDisplayName()
		{
			return "Transifex project page";
		}

		@Override
		public JobProperty<?> newInstance(StaplerRequest req, JSONObject formData) throws FormException
		{
			TransifexProjectProperty tpp = req.bindJSON(TransifexProjectProperty.class, formData);
			if (tpp.projectUrl == null)
			{
				tpp = null; // not configured
			}
			return tpp;
		}

	}
}

@@ -629,36 +629,41 @@
 hor 
-Stefan Saasen %3Cstefan@coravy
+Hakan Tandogan %3Chakan@gurkensalat
 .com
@@ -1341,182 +1341,8 @@
 %09%7D%0A%0A
-%09/*%0A%09 * @Override public JobPropertyDescriptor getDescriptor() %7B return%0A%09 * DESCRIPTOR; %7D%0A%09 * %0A%09 * public static final DescriptorImpl DESCRIPTOR = new DescriptorImpl();%0A%09 */%0A
 %09@Ex
@@ -1674,24 +1674,40 @@
 yName()%0A%09%09%7B%0A
+%09%09%09// TODO I18N%0A
 %09%09%09return %22T

Prepare for I18N