Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[JENKINS-31162] Initial source code modification about Item categoriz…
…ation
- Loading branch information
Manuel Recena
committed
Mar 11, 2016
1 parent
8b47f5c
commit 09a58b1
Showing
8 changed files
with
231 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
core/src/main/java/jenkins/model/ItemCategory/Categories.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package jenkins.model.ItemCategory; | ||
|
||
import org.kohsuke.stapler.HttpResponse; | ||
import org.kohsuke.stapler.StaplerRequest; | ||
import org.kohsuke.stapler.StaplerResponse; | ||
import org.kohsuke.stapler.export.Exported; | ||
import org.kohsuke.stapler.export.ExportedBean; | ||
import org.kohsuke.stapler.export.Flavor; | ||
|
||
import javax.servlet.ServletException; | ||
import java.io.IOException; | ||
import java.io.Serializable; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
/** | ||
* It is a logic representation of a set of {$Category}. | ||
*/ | ||
@ExportedBean | ||
public class Categories implements HttpResponse, Serializable { | ||
|
||
private List<Category> items; | ||
|
||
public Categories() { | ||
items = new ArrayList<Category>(); | ||
} | ||
|
||
@Exported(name = "categories") | ||
public List<Category> getItems() { | ||
return items; | ||
} | ||
|
||
@Override | ||
public void generateResponse(StaplerRequest req, StaplerResponse rsp, Object node) throws IOException, ServletException { | ||
rsp.serveExposedBean(req, this, Flavor.JSON); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
core/src/main/java/jenkins/model/ItemCategory/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package jenkins.model.ItemCategory; | ||
|
||
import hudson.model.TopLevelItem; | ||
import org.kohsuke.stapler.export.Exported; | ||
import org.kohsuke.stapler.export.ExportedBean; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* Represents an {$link ItemCategory} and its {@link TopLevelItem}s. | ||
*/ | ||
@ExportedBean | ||
public class Category implements Serializable { | ||
|
||
private String id; | ||
|
||
private String name; | ||
|
||
private String description; | ||
|
||
private String iconClassName; | ||
|
||
private List<String> items; | ||
|
||
public Category(String id, String name, String description, String iconClassName, List<String> items) { | ||
this.id= id; | ||
this.name = name; | ||
this.description = description; | ||
this.iconClassName = iconClassName; | ||
this.items = items; | ||
} | ||
|
||
@Exported | ||
public String getId() { | ||
return id; | ||
} | ||
|
||
@Exported | ||
public String getName() { | ||
return name; | ||
} | ||
|
||
@Exported | ||
public String getDescription() { | ||
return description; | ||
} | ||
|
||
@Exported | ||
public String getIconClassName() { | ||
return iconClassName; | ||
} | ||
|
||
@Exported | ||
public List<String> getItems() { | ||
return items; | ||
} | ||
|
||
} |
43 changes: 25 additions & 18 deletions
43
...main/java/jenkins/model/ItemCategory.java → ...kins/model/ItemCategory/ItemCategory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,61 @@ | ||
package jenkins.model; | ||
package jenkins.model.ItemCategory; | ||
|
||
import hudson.Extension; | ||
import hudson.ExtensionPoint; | ||
import hudson.model.ModelObject; | ||
import jenkins.model.Messages; | ||
|
||
/** | ||
* A category for {@link hudson.model.Item}s. | ||
*/ | ||
public abstract class ItemCategory implements ModelObject, ExtensionPoint { | ||
|
||
/** | ||
* The icon class specification e.g. 'icon-category-folder', 'icon-help' etc. | ||
* The size specification should not be provided as that is determined by the | ||
* context of where the category is displayed. | ||
* Identifier, e.g. "category-id-default", etc. | ||
* | ||
* @return the identifier | ||
*/ | ||
public abstract String getId(); | ||
|
||
/** | ||
* The icon class specification e.g. 'category-icon-folder', 'category-icon-default', etc. | ||
* | ||
* @return the icon class specification | ||
*/ | ||
public abstract String getIconClassName(); | ||
|
||
/** | ||
* The description in plain text | ||
* | ||
* @return the description | ||
*/ | ||
public abstract String getDescription(); | ||
|
||
/** | ||
* The default category, if an item doesn't belong anywhere else, this is where it goes by default. | ||
*/ | ||
@Extension | ||
public static final class Default extends ItemCategory { | ||
|
||
@Override | ||
public String getIconClassName() { | ||
return "icon-category-default"; //TODO whatever Gus decides | ||
public String getId() { | ||
return "category-id-default"; | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.ItemCategory_Default_DisplayName(); | ||
public String getIconClassName() { | ||
return "category-icon-default"; | ||
} | ||
} | ||
|
||
/** | ||
* A category suitable for folder and container (not docker) like items. | ||
*/ | ||
@Extension | ||
public static final class Folders extends ItemCategory { | ||
|
||
@Override | ||
public String getIconClassName() { | ||
return "icon-category-folders"; //TODO whatever Gus decides | ||
public String getDescription() { | ||
return Messages.ItemCategory_Default_Description(); | ||
} | ||
|
||
@Override | ||
public String getDisplayName() { | ||
return Messages.ItemCategory_Folders_DisplayName(); | ||
return Messages.ItemCategory_Default_DisplayName(); | ||
} | ||
} | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
core/src/main/java/jenkins/model/ItemCategory/ItemCategoryConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package jenkins.model.ItemCategory; | ||
|
||
import hudson.Extension; | ||
import hudson.ExtensionList; | ||
import hudson.ExtensionPoint; | ||
import hudson.model.TopLevelItemDescriptor; | ||
|
||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import java.util.Collection; | ||
import java.util.logging.Logger; | ||
|
||
/** | ||
* A mapper of {@link ItemCategory}s to {@link hudson.model.Item}s. | ||
*/ | ||
public abstract class ItemCategoryConfigurator implements ExtensionPoint { | ||
|
||
public static final Logger LOGGER = Logger.getLogger(ItemCategoryConfigurator.class.getName()); | ||
|
||
/** | ||
* Provides the category for the requested item or null if this mapper doesn't have one. | ||
* | ||
* @param descriptor the item to categorise | ||
* | ||
* @return the category or null | ||
*/ | ||
@CheckForNull | ||
protected abstract ItemCategory getCategoryFor(@Nonnull TopLevelItemDescriptor descriptor); | ||
|
||
/** | ||
* Finds the category specified by the first mapper. | ||
* If none can be found {@link ItemCategory.Default} is returned. | ||
* | ||
* @param descriptor the item to categorise. | ||
* | ||
* @return the category | ||
*/ | ||
@Nonnull | ||
public static ItemCategory getCategory(@Nonnull TopLevelItemDescriptor descriptor) { | ||
for (ItemCategoryConfigurator m : all()) { | ||
ItemCategory category = m.getCategoryFor(descriptor); | ||
if (category != null) { | ||
return category; | ||
} | ||
} | ||
throw new IllegalStateException(); | ||
} | ||
|
||
public static Collection<ItemCategoryConfigurator> all() { | ||
return ExtensionList.lookup(ItemCategoryConfigurator.class); | ||
} | ||
|
||
/** | ||
* Mapper implementation with the lowest ordinal that simply returns {@link ItemCategory.Default}. | ||
*/ | ||
@Extension(ordinal = Integer.MIN_VALUE) | ||
public static final class DefaultConfigurator extends ItemCategoryConfigurator { | ||
|
||
@Override | ||
public ItemCategory getCategoryFor(@Nonnull TopLevelItemDescriptor descriptor) { | ||
return ExtensionList.lookup(ItemCategory.Default.class).iterator().next(); | ||
} | ||
} | ||
} |
Oops, something went wrong.