mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +10:00
refactor editably property
add transformer coil and core
This commit is contained in:
@@ -9,11 +9,13 @@ import javax.swing.JLabel;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.annotations.EditableProperty;
|
||||
import org.diylc.core.annotations.DynamicList;
|
||||
import org.diylc.core.annotations.MultiLineText;
|
||||
import org.diylc.core.measures.AbstractMeasure;
|
||||
|
||||
/**
|
||||
* Based on {@link PropertyWrapper#getType()}, creates an appropriate {@link Component} that can edit that type.
|
||||
* Based on {@link PropertyWrapper#getType()}, creates an appropriate {@link Component} that can
|
||||
* edit that type.
|
||||
*
|
||||
* @author Branislav Stojkovic
|
||||
*/
|
||||
@@ -22,13 +24,21 @@ public class FieldEditorFactory {
|
||||
private static final Logger LOG = Logger.getLogger(FieldEditorFactory.class);
|
||||
|
||||
public static Component createFieldEditor(PropertyWrapper property) {
|
||||
if (property.getType().equals(String.class) && property.getListItems() != null) {
|
||||
StringListEditor editor = new StringListEditor(property);
|
||||
return editor;
|
||||
try {
|
||||
if (property.getType().equals(String.class) && property.getGetter().isAnnotationPresent(DynamicList.class)) {
|
||||
StringListEditor editor = new StringListEditor(property);
|
||||
return editor;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not determine if a function is annotated with DynamicList", e);
|
||||
}
|
||||
if (property.getType().equals(String.class) && EditableProperty.MULTI_LINE.equals(property.getAdditionalOptions())) {
|
||||
MultiLineStringEditor editor = new MultiLineStringEditor(property);
|
||||
return editor;
|
||||
try {
|
||||
if (property.getType().equals(String.class) && property.getGetter().isAnnotationPresent(MultiLineText.class)) {
|
||||
MultiLineStringEditor editor = new MultiLineStringEditor(property);
|
||||
return editor;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
LOG.error("Could not determine if a function is annotated with MultiLineText", e);
|
||||
}
|
||||
if (property.getType().equals(String.class)) {
|
||||
StringEditor editor = new StringEditor(property);
|
||||
|
||||
@@ -24,7 +24,7 @@ public class IntEditor extends DoubleTextField {
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
property.setChanged(true);
|
||||
setBackground(oldBg);
|
||||
property.setValue(((Double) evt.getNewValue()).intValue());
|
||||
property.setValue(evt.getNewValue() == null ? null : ((Double) evt.getNewValue()).intValue());
|
||||
}
|
||||
});
|
||||
if (!property.isUnique()) {
|
||||
|
||||
@@ -3,11 +3,13 @@ package org.diylc.swing.gui.editor;
|
||||
import java.awt.Color;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import javax.swing.DefaultComboBoxModel;
|
||||
import javax.swing.JComboBox;
|
||||
|
||||
import org.diylc.common.PropertyWrapper;
|
||||
import org.diylc.core.annotations.DynamicList;
|
||||
import org.diylc.utils.Constants;
|
||||
|
||||
public class StringListEditor extends JComboBox {
|
||||
@@ -18,9 +20,11 @@ public class StringListEditor extends JComboBox {
|
||||
|
||||
private final PropertyWrapper property;
|
||||
|
||||
public StringListEditor(final PropertyWrapper property) {
|
||||
public StringListEditor(final PropertyWrapper property) throws Exception {
|
||||
this.property = property;
|
||||
Object[] values = property.getListItems();
|
||||
String listFunctionName = property.getGetter().getAnnotation(DynamicList.class).availableValueFunction();
|
||||
Method function = property.getOwnerObject().getClass().getMethod(listFunctionName);
|
||||
Object[] values = (Object[]) function.invoke(property.getOwnerObject());
|
||||
setModel(new DefaultComboBoxModel(values));
|
||||
setSelectedItem(property.getValue());
|
||||
addItemListener(new ItemListener() {
|
||||
|
||||
Reference in New Issue
Block a user