mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
added default templates
This commit is contained in:
@@ -17,6 +17,8 @@ public interface ITemplateProcessor {
|
||||
void applyTemplateToSelection(Template template);
|
||||
|
||||
void deleteTemplate(String categoryName, String componentTypeName, String templateName);
|
||||
|
||||
void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean defaultFlag);
|
||||
|
||||
public class TemplateAlreadyExistsException extends Exception {
|
||||
|
||||
|
||||
@@ -9,12 +9,14 @@ public class Template {
|
||||
private String name;
|
||||
private Map<String, Object> values;
|
||||
private List<Point> points;
|
||||
private boolean defaultFlag;
|
||||
|
||||
public Template(String name, Map<String, Object> values, List<Point> points) {
|
||||
public Template(String name, Map<String, Object> values, List<Point> points, boolean defaultFlag) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.values = values;
|
||||
this.points = points;
|
||||
this.defaultFlag = defaultFlag;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -41,10 +43,19 @@ 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());
|
||||
@@ -60,6 +71,8 @@ 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;
|
||||
@@ -77,4 +90,9 @@ public class Template {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1790,6 +1790,18 @@ public class Presenter implements IPlugInPort {
|
||||
setNewComponentTypeSlot(null, null);
|
||||
return;
|
||||
}
|
||||
|
||||
// try to find a default template if none is provided
|
||||
if (componentType != null && template == null) {
|
||||
List<Template> templates = getTemplatesFor(componentType.getCategory(), componentType.getName());
|
||||
for (Template t : templates) {
|
||||
if (t.isDefaultFlag()) {
|
||||
template = t;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
instantiationManager.setComponentTypeSlot(componentType, template, currentProject);
|
||||
if (componentType != null) {
|
||||
@@ -1854,7 +1866,7 @@ public class Presenter implements IPlugInPort {
|
||||
point.translate(-x, -y);
|
||||
}
|
||||
|
||||
Template template = new Template(templateName, values, points);
|
||||
Template template = new Template(templateName, values, points, false);
|
||||
boolean exists = false;
|
||||
for (Template t : templates) {
|
||||
if (t.getName().equalsIgnoreCase(templateName)) {
|
||||
@@ -1958,6 +1970,24 @@ public class Presenter implements IPlugInPort {
|
||||
}
|
||||
}
|
||||
}
|
||||
ConfigurationManager.getInstance().saveConfigration();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void setTemplateDefault(String categoryName, String componentTypeName, String templateName, boolean 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.");
|
||||
}
|
||||
|
||||
private Set<IDIYComponent<?>> getLockedComponents() {
|
||||
|
||||
Reference in New Issue
Block a user