mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
simplified component framework
This commit is contained in:
+2
-2
@@ -23,8 +23,8 @@ public class ComparatorFactory {
|
||||
|
||||
@Override
|
||||
public int compare(IDIYComponent o1, IDIYComponent o2) {
|
||||
String name1 = ComponentProcessor.getInstance().extractComponentName(o1);
|
||||
String name2 = ComponentProcessor.getInstance().extractComponentName(o2);
|
||||
String name1 = o1.getName();
|
||||
String name2 = o2.getName();
|
||||
if (name1 == null || name2 == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
-66
@@ -11,8 +11,6 @@ import org.apache.log4j.Logger;
|
||||
import org.diylc.common.ControlPointWrapper;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.IDIYComponent;
|
||||
import org.diylc.core.annotations.ComponentName;
|
||||
import org.diylc.core.annotations.ComponentValue;
|
||||
import org.diylc.core.annotations.ControlPoint;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
|
||||
@@ -174,68 +172,4 @@ public class ComponentProcessor {
|
||||
}
|
||||
return properties;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the method annotated with {@link ComponentName} annotations and
|
||||
* calls it to retrieve component name.
|
||||
*
|
||||
* @param component
|
||||
* @return
|
||||
*/
|
||||
public String extractComponentName(IDIYComponent component) {
|
||||
String name = null;
|
||||
for (Method method : component.getClass().getMethods()) {
|
||||
if (method.isAnnotationPresent(ComponentName.class)) {
|
||||
try {
|
||||
name = method.invoke(component).toString();
|
||||
} catch (Exception e) {
|
||||
name = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the method annotated with {@link ComponentName} and it's matching
|
||||
* setter and calls the setter to update the component name.
|
||||
*
|
||||
* @param component
|
||||
* @param newName
|
||||
*/
|
||||
public void writeComponentName(IDIYComponent component, String newName) {
|
||||
for (Method method : component.getClass().getMethods()) {
|
||||
if (method.isAnnotationPresent(ComponentName.class)) {
|
||||
try {
|
||||
Method setter = component.getClass().getMethod(
|
||||
method.getName().replaceFirst("get", "set"), String.class);
|
||||
setter.invoke(component, newName);
|
||||
} catch (Exception e) {
|
||||
LOG.warn("Could not update component name on a component of type "
|
||||
+ component.getClass().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds the method annotated with {@link ComponentValue} annotations and
|
||||
* calls it to retrieve component value.
|
||||
*
|
||||
* @param component
|
||||
* @return
|
||||
*/
|
||||
public String extractComponentValue(IDIYComponent component) {
|
||||
String value = null;
|
||||
for (Method method : component.getClass().getMethods()) {
|
||||
if (method.isAnnotationPresent(ComponentValue.class)) {
|
||||
try {
|
||||
value = method.invoke(component).toString();
|
||||
} catch (Exception e) {
|
||||
value = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-3
@@ -716,14 +716,13 @@ public class Presenter implements IPlugInPort {
|
||||
String name = namePrefix + i;
|
||||
exists = false;
|
||||
for (IDIYComponent c : currentProject.getComponents()) {
|
||||
String cName = ComponentProcessor.getInstance().extractComponentName(c);
|
||||
if (cName.equals(name)) {
|
||||
if (c.getName().equals(name)) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
ComponentProcessor.getInstance().writeComponentName(component, namePrefix + i);
|
||||
component.setName(namePrefix + i);
|
||||
|
||||
// Add it to the project.
|
||||
currentProject.getComponents().add(component);
|
||||
|
||||
Reference in New Issue
Block a user