All Downloads are FREE. Search and download functionalities are using the official Maven repository.

hudson.plugins.view.dashboard.DashboardPortlet Maven / Gradle / Ivy

Go to download

Hudson view that shows various cuts of build information via configured portlets.

The newest version!
package hudson.plugins.view.dashboard;

import hudson.DescriptorExtensionList;
import hudson.ExtensionPoint;
import hudson.model.Describable;
import hudson.model.Descriptor;
import hudson.model.Hudson;
import hudson.model.ModelObject;
import hudson.model.ParameterDefinition;
import hudson.model.TopLevelItem;

import org.kohsuke.stapler.Stapler;
import org.kohsuke.stapler.StaplerRequest;

import java.util.Comparator;

/**
 * Report that can summarize project data across multiple projects and display
 * the resulting data.
 * 
 * @author Peter Hayes
 */
public abstract class DashboardPortlet implements ModelObject, Describable, ExtensionPoint {
  private static int counter = 0;
	private String id;
	private String name;

	public DashboardPortlet(String name) {
    counter++;
		this.id = "dashboard_portlet_" + counter;
    this.name = name;
	}

  public String getId() {
    return id;
  }

	public String getName() {
		return name;
	}
	
	public Dashboard getDashboard() {
		// TODO Can the dashboard instance be a field on this class -- parent?
		StaplerRequest req = Stapler.getCurrentRequest();
		return req.findAncestorObject(Dashboard.class);
	}

	public String getDisplayName() {
		return getName();
	}
	
  public String getUrl() {
      return "portlet/"+getId()+'/';
  }
	
	/**
	 * Support accessing jobs available via view through portlets
	 */
	public TopLevelItem getJob(String name) {
		return getDashboard().getJob(name);
	}

  /**
   * {@inheritDoc}
   */
  public Descriptor getDescriptor() {
      return (Descriptor) Hudson.getInstance().getDescriptor(getClass());
  }

	/**
	 * Returns all the registered {@link ParameterDefinition} descriptors.
	 */
	public static DescriptorExtensionList> all() {
		return Hudson.getInstance().getDescriptorList(DashboardPortlet.class);
	}

  public static Comparator getComparator() {
    return new Comparator() {
      public int compare(Dashboard p1, Dashboard p2) {
        return p1.getDescription().compareTo(p2.getDescription());
      }
    };
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy