renamed BOM objects

This commit is contained in:
bancika
2011-01-04 21:13:13 +00:00
parent 32409b186f
commit 2bd2ecd13d
8 changed files with 37 additions and 35 deletions
@@ -4,7 +4,7 @@ import java.awt.Point;
import org.diylc.core.IDIYComponent;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.BomName;
import org.diylc.core.annotations.ComponentName;
import org.diylc.core.annotations.ControlPoint;
import org.diylc.core.annotations.EditableProperty;
import org.diylc.core.measures.Size;
@@ -48,7 +48,7 @@ public abstract class AbstractLeadedDIYComponent implements IDIYComponent {
*/
protected abstract Size getDefaultHeight();
@BomName
@ComponentName
@EditableProperty
public String getName() {
return name;
@@ -7,8 +7,8 @@ import java.awt.Point;
import org.diylc.core.ComponentState;
import org.diylc.core.IDIYComponent;
import org.diylc.core.VisibilityPolicy;
import org.diylc.core.annotations.BomName;
import org.diylc.core.annotations.BomValue;
import org.diylc.core.annotations.ComponentName;
import org.diylc.core.annotations.ComponentValue;
import org.diylc.core.annotations.ComponentDescriptor;
import org.diylc.core.annotations.ControlPoint;
import org.diylc.core.annotations.EditableProperty;
@@ -47,7 +47,7 @@ public class MockDIYComponent implements IDIYComponent {
super();
}
@BomName
@ComponentName
@EditableProperty
public String getName() {
return name;
@@ -75,7 +75,7 @@ public class MockDIYComponent implements IDIYComponent {
this.testField = testField;
}
@BomValue
@ComponentValue
@EditableProperty(defaultable = true)
public Capacitance getC() {
return c;
@@ -5,11 +5,12 @@ import java.lang.annotation.RetentionPolicy;
/**
* Annotates getter for the component name that will be shown in the BOM. Only
* one getter per class may be tagged with this annotation.
* one getter per class may be tagged with this annotation and, must return
* string type and there has to be a matching setter.
*
* @author Branislav Stojkovic
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface BomName {
public @interface ComponentName {
}
@@ -10,6 +10,6 @@ import java.lang.annotation.RetentionPolicy;
* @author Branislav Stojkovic
*/
@Retention(RetentionPolicy.RUNTIME)
public @interface BomValue {
public @interface ComponentValue {
}
@@ -28,8 +28,8 @@ public class BomMaker {
public List<BomEntry> createBom(List<IDIYComponent> components) {
Map<String, BomEntry> entryMap = new HashMap<String, BomEntry>();
for (IDIYComponent component : components) {
String name = ComponentProcessor.getInstance().extractBomName(component);
String value = ComponentProcessor.getInstance().extractBomValue(component);
String name = ComponentProcessor.getInstance().extractComponentName(component);
String value = ComponentProcessor.getInstance().extractComponentValue(component);
if ((name != null) && (value != null)) {
String key = name + "|" + value;
if (entryMap.containsKey(key)) {
@@ -193,14 +193,14 @@ public class StatusBar extends JPanel implements IPlugIn {
if (componentsUnderCursor.size() == 1) {
getStatusLabel().setText(
"Drag \""
+ ComponentProcessor.getInstance().extractBomName(
+ ComponentProcessor.getInstance().extractComponentName(
componentsUnderCursor.get(0)) + "\"");
} else {
getStatusLabel().setText(
"Hold CTRL key to drag all "
+ componentsUnderCursor.size()
+ " components under the cursor or drag only \""
+ ComponentProcessor.getInstance().extractBomName(
+ ComponentProcessor.getInstance().extractComponentName(
componentsUnderCursor.get(0)) + "\"");
}
}
@@ -11,8 +11,8 @@ 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.BomName;
import org.diylc.core.annotations.BomValue;
import org.diylc.core.annotations.ComponentName;
import org.diylc.core.annotations.ComponentValue;
import org.diylc.core.annotations.ControlPoint;
import org.diylc.core.annotations.EditableProperty;
@@ -91,8 +91,8 @@ public class ComponentProcessor {
* Reads all control points from the specified component class. Note than
* control points are cached, so it may happen that control points returned
* already have their values populated. Always use
* {@link ControlPointWrapper#readFrom(IDIYComponent)} to update their
* state from an actual component.
* {@link ControlPointWrapper#readFrom(IDIYComponent)} to update their state
* from an actual component.
*
* @param clazz
* @return
@@ -135,8 +135,7 @@ public class ComponentProcessor {
* @param selectedComponents
* @return
*/
public List<PropertyWrapper> getMutualSelectionProperties(
List<IDIYComponent> selectedComponents) {
public List<PropertyWrapper> getMutualSelectionProperties(List<IDIYComponent> selectedComponents) {
if (selectedComponents.isEmpty()) {
return null;
}
@@ -177,16 +176,16 @@ public class ComponentProcessor {
}
/**
* Finds the method annotated with {@link BomName} annotations and calls it
* to retrieve component name.
* Finds the method annotated with {@link ComponentName} annotations and
* calls it to retrieve component name.
*
* @param component
* @return
*/
public String extractBomName(IDIYComponent component) {
public String extractComponentName(IDIYComponent component) {
String name = null;
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(BomName.class)) {
if (method.isAnnotationPresent(ComponentName.class)) {
try {
name = method.invoke(component).toString();
} catch (Exception e) {
@@ -198,36 +197,38 @@ public class ComponentProcessor {
}
/**
* Finds the method annotated with {@link BomName} and it's matching setter
* and calls the setter to update the component 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 newBomName
* @param newName
*/
public void writeBomName(IDIYComponent component, String newBomName) {
public void writeComponentName(IDIYComponent component, String newName) {
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(BomName.class)) {
if (method.isAnnotationPresent(ComponentName.class)) {
try {
Method setter = component.getClass().getMethod(
method.getName().replaceFirst("get", "set"), String.class);
setter.invoke(component, newBomName);
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 BomValue} annotations and calls it
* to retrieve component value.
* Finds the method annotated with {@link ComponentValue} annotations and
* calls it to retrieve component value.
*
* @param component
* @return
*/
public String extractBomValue(IDIYComponent component) {
public String extractComponentValue(IDIYComponent component) {
String value = null;
for (Method method : component.getClass().getMethods()) {
if (method.isAnnotationPresent(BomValue.class)) {
if (method.isAnnotationPresent(ComponentValue.class)) {
try {
value = method.invoke(component).toString();
} catch (Exception e) {
@@ -714,14 +714,14 @@ public class Presenter implements IPlugInPort {
String name = namePrefix + i;
exists = false;
for (IDIYComponent c : currentProject.getComponents()) {
String cName = ComponentProcessor.getInstance().extractBomName(c);
String cName = ComponentProcessor.getInstance().extractComponentName(c);
if (cName.equals(name)) {
exists = true;
break;
}
}
}
ComponentProcessor.getInstance().writeBomName(component, namePrefix + i);
ComponentProcessor.getInstance().writeComponentName(component, namePrefix + i);
// Add it to the project.
currentProject.getComponents().add(component);