mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
keep defaults for variants separate
This commit is contained in:
@@ -27,7 +27,8 @@ import org.diylc.core.Template;
|
||||
|
||||
public interface ITemplateProcessor {
|
||||
|
||||
public static final String TEMPLATES_KEY = "templates";
|
||||
public static final String TEMPLATES_KEY = "templates";
|
||||
public static final String DEFAULT_TEMPLATES_KEY = "defaultTemplates";
|
||||
|
||||
void saveSelectedComponentAsTemplate(String templateName);
|
||||
|
||||
@@ -39,7 +40,9 @@ public interface ITemplateProcessor {
|
||||
|
||||
void deleteTemplate(String categoryName, String componentTypeName, String templateName);
|
||||
|
||||
void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean defaultFlag);
|
||||
void setTemplateDefault(String categoryName, String componentTypeName, String templateName);
|
||||
|
||||
String getDefaultTemplate(String categoryName, String componentTypeName);
|
||||
|
||||
public class TemplateAlreadyExistsException extends Exception {
|
||||
|
||||
|
||||
@@ -29,15 +29,15 @@ public class Template {
|
||||
|
||||
private String name;
|
||||
private Map<String, Object> values;
|
||||
private List<Point> points;
|
||||
private List<Point> points;
|
||||
@Deprecated
|
||||
private boolean defaultFlag;
|
||||
|
||||
public Template(String name, Map<String, Object> values, List<Point> points, boolean defaultFlag) {
|
||||
public Template(String name, Map<String, Object> values, List<Point> points) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.points = points;
|
||||
this.defaultFlag = defaultFlag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -64,19 +64,10 @@ public class Template {
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public boolean isDefaultFlag() {
|
||||
return defaultFlag;
|
||||
}
|
||||
|
||||
public void setDefaultFlag(boolean defaultFlag) {
|
||||
this.defaultFlag = defaultFlag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = prime * result + (defaultFlag ? 1231 : 1237);
|
||||
result = prime * result + ((name == null) ? 0 : name.hashCode());
|
||||
result = prime * result + ((points == null) ? 0 : points.hashCode());
|
||||
result = prime * result + ((values == null) ? 0 : values.hashCode());
|
||||
@@ -92,8 +83,6 @@ public class Template {
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
Template other = (Template) obj;
|
||||
if (defaultFlag != other.defaultFlag)
|
||||
return false;
|
||||
if (name == null) {
|
||||
if (other.name != null)
|
||||
return false;
|
||||
|
||||
@@ -2091,10 +2091,11 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
// try to find a default template if none is provided
|
||||
if (componentType != null && template == null) {
|
||||
String defaultTemplate = getDefaultTemplate(componentType.getCategory(), componentType.getName());
|
||||
List<Template> templates = getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||
if (templates != null)
|
||||
if (templates != null && defaultTemplate != null)
|
||||
for (Template t : templates) {
|
||||
if (t.isDefaultFlag()) {
|
||||
if (t.getName().equals(defaultTemplate)) {
|
||||
template = t;
|
||||
break;
|
||||
}
|
||||
@@ -2165,7 +2166,7 @@ public class Presenter implements IPlugInPort {
|
||||
point.translate(-x, -y);
|
||||
}
|
||||
|
||||
Template template = new Template(templateName, values, points, false);
|
||||
Template template = new Template(templateName, values, points);
|
||||
boolean exists = false;
|
||||
for (Template t : templates) {
|
||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||
@@ -2309,21 +2310,27 @@ public class Presenter implements IPlugInPort {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean defaultFlag) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s, %s, %s)", categoryName, componentTypeName, templateName,
|
||||
defaultFlag));
|
||||
Map<String, List<Template>> templateMap =
|
||||
(Map<String, List<Template>>) ConfigurationManager.getInstance().readObject(TEMPLATES_KEY, null);
|
||||
if (templateMap != null) {
|
||||
List<Template> templates = templateMap.get(categoryName + "." + componentTypeName);
|
||||
if (templates != null) {
|
||||
for (Template template : templates)
|
||||
template.setDefaultFlag(defaultFlag && templateName.equals(template.getName()));
|
||||
ConfigurationManager.getInstance().writeValue(TEMPLATES_KEY, templateMap);
|
||||
return;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("Could not find the specified template.");
|
||||
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName) {
|
||||
LOG.debug(String.format("setTemplateDefault(%s, %s, %s)", categoryName, componentTypeName, templateName));
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
defaultTemplateMap = new HashMap<String, String>();
|
||||
if (templateName.equals(defaultTemplateMap.get(categoryName + "." + componentTypeName)))
|
||||
defaultTemplateMap.remove(categoryName + "." + componentTypeName);
|
||||
else
|
||||
defaultTemplateMap.put(categoryName + "." + componentTypeName, templateName);
|
||||
ConfigurationManager.getInstance().writeValue(DEFAULT_TEMPLATES_KEY, defaultTemplateMap);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public String getDefaultTemplate(String categoryName, String componentTypeName) {
|
||||
Map<String, String> defaultTemplateMap =
|
||||
(Map<String, String>) ConfigurationManager.getInstance().readObject(DEFAULT_TEMPLATES_KEY, null);
|
||||
if (defaultTemplateMap == null)
|
||||
return null;
|
||||
return defaultTemplateMap.get(categoryName + "." + componentTypeName);
|
||||
}
|
||||
|
||||
private Set<IDIYComponent<?>> getLockedComponents() {
|
||||
|
||||
Reference in New Issue
Block a user