use of com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor in project convertigo by convertigo.
the class DatabaseObjectTreeObject method findPropertyDescriptor.
private PropertyDescriptor findPropertyDescriptor(final String name, String displayName, java.beans.PropertyDescriptor databaseObjectPropertyDescriptor, Object value, final Class<?> pec, boolean isExtractionRule, boolean isMasked) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException {
PropertyDescriptor propertyDescriptor = null;
// Primitive types
if (pec == null) {
if (value instanceof Boolean) {
String[] values = new String[] { "true", "false" };
propertyDescriptor = new DynamicComboBoxPropertyDescriptor(name, displayName, values, this, name);
} else if (value instanceof Number) {
propertyDescriptor = new TextPropertyDescriptor(name, displayName);
// propertyDescriptor.setValidator(new CompilableValueValidator(new NumberValidator(value.getClass())));
}
} else // Complex types
{
if (PropertyWithValidatorEditor.class.isAssignableFrom(pec)) {
propertyDescriptor = new TextPropertyDescriptor(name, displayName);
propertyDescriptor.setValidator(getValidator(name));
} else if (PropertyWithTagsEditor.class.isAssignableFrom(pec)) {
String[] tags;
if (PropertyWithDynamicTagsEditor.class.isAssignableFrom(pec)) {
Method getTags = pec.getMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
tags = (String[]) getTags.invoke(null, new Object[] { this, name });
propertyDescriptor = new DynamicComboBoxPropertyDescriptor(name, displayName, getTags, this, name);
} else if (PropertyWithTagsEditorAdvance.class.isAssignableFrom(pec)) {
Method getTags = pec.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
tags = (String[]) getTags.invoke(null, new Object[] { this, name });
propertyDescriptor = new DynamicComboBoxPropertyDescriptor(name, displayName, tags, this, name);
} else {
Method getTags = pec.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class });
tags = (String[]) getTags.invoke(null, new Object[] { this });
propertyDescriptor = new DynamicComboBoxPropertyDescriptor(name, displayName, tags, this, name);
}
} else if (StringComboBoxPropertyDescriptor.class.isAssignableFrom(pec)) {
Method getTags = pec.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, name });
propertyDescriptor = new StringComboBoxPropertyDescriptor(name, displayName, tags, false);
} else if (com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor.class.isAssignableFrom(pec)) {
Method getTags = pec.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, name });
propertyDescriptor = new com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor(name, displayName, tags, false);
((com.twinsoft.convertigo.eclipse.property_editors.MobileSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
} else if (com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor.class.isAssignableFrom(pec)) {
Method getTags = pec.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, name });
propertyDescriptor = new com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor(name, displayName, tags, false);
((com.twinsoft.convertigo.eclipse.property_editors.NgxSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
} else if (PropertyWithDynamicInfoEditor.class.isAssignableFrom(pec)) {
Method getInfo = pec.getMethod("getInfo", new Class[] { DatabaseObjectTreeObject.class, String.class });
propertyDescriptor = new DynamicInfoPropertyDescriptor(name, displayName, getInfo, this, name);
} else if (AbstractDialogCellEditor.class.isAssignableFrom(pec)) {
propertyDescriptor = new PropertyDescriptor(name, displayName) {
@Override
public CellEditor createPropertyEditor(Composite parent) {
try {
Constructor<?> constructor = pec.getConstructor(new Class[] { Composite.class });
AbstractDialogCellEditor editor = (AbstractDialogCellEditor) constructor.newInstance(new Object[] { parent });
editor.propertyDescriptor = this;
editor.databaseObjectTreeObject = DatabaseObjectTreeObject.this;
if (getValidator() != null) {
editor.setValidator(getValidator());
}
return editor;
} catch (Exception e) {
ConvertigoPlugin.logException(e, "Unexpected exception");
return null;
}
}
};
} else if (Enum.class.isAssignableFrom(pec)) {
String[] tags = EnumUtils.toStrings(pec);
propertyDescriptor = new DynamicComboBoxPropertyDescriptor(name, displayName, tags, this, name);
}
}
// Special cases
if (propertyDescriptor == null) {
// editor for scriptable properties
Object scriptable = databaseObjectPropertyDescriptor.getValue("scriptable");
if ((scriptable != null) && (scriptable.equals(Boolean.TRUE)))
propertyDescriptor = new ScriptablePropertyDescriptor(name, displayName);
// editor for nillable properties
if (propertyDescriptor == null) {
Object nillable = databaseObjectPropertyDescriptor.getValue("nillable");
if ((nillable != null) && (nillable.equals(Boolean.TRUE))) {
int style = isMasked ? SWT.PASSWORD : SWT.NONE;
if (value instanceof String) {
propertyDescriptor = new DataOrNullPropertyDescriptor(name, displayName, StringOrNullEditor.class, style);
} else if (value instanceof XMLVector) {
propertyDescriptor = new DataOrNullPropertyDescriptor(name, displayName, ArrayOrNullEditor.class, style);
}
}
}
// editor for disabled properties
Object disable = databaseObjectPropertyDescriptor.getValue("disable");
if ((disable != null) && (disable.equals(Boolean.TRUE)))
propertyDescriptor = new InfoPropertyDescriptor(name, displayName);
}
// Default case
if (propertyDescriptor == null) {
propertyDescriptor = new TextPropertyDescriptor(name, displayName);
// propertyDescriptor.setValidator(new CompilableValueValidator(getValidator(name)));
}
if (propertyDescriptor != null) {
ICellEditorValidator validator = getValidator(name);
if (validator != null) {
propertyDescriptor.setValidator(validator);
}
final ILabelProvider labelProvider = propertyDescriptor.getLabelProvider();
propertyDescriptor.setLabelProvider(new ILabelProvider() {
@Override
public void removeListener(ILabelProviderListener listener) {
labelProvider.removeListener(listener);
}
@Override
public boolean isLabelProperty(Object element, String property) {
return labelProvider.isLabelProperty(element, property);
}
@Override
public void dispose() {
labelProvider.dispose();
}
@Override
public void addListener(ILabelProviderListener listener) {
labelProvider.addListener(listener);
}
@Override
public String getText(Object element) {
String text = labelProvider.getText(element);
try {
String compiled = Engine.theApp.databaseObjectsManager.getCompiledValue(text);
if (!text.equals(compiled)) {
text += " => " + compiled;
}
} catch (UndefinedSymbolsException e) {
text += " /!\\ undefined symbol /!\\";
}
return text;
}
@Override
public Image getImage(Object element) {
return labelProvider.getImage(element);
}
});
String beanDescription = databaseObjectPropertyDescriptor.getShortDescription();
int id = beanDescription.indexOf("|");
if (id != -1) {
beanDescription = beanDescription.substring(0, id);
}
if (isExtractionRule) {
propertyDescriptor.setCategory(databaseObjectPropertyDescriptor.isExpert() ? "Selection" : "Configuration");
} else {
Object categoryValue = databaseObjectPropertyDescriptor.getValue("category");
String category = categoryValue == null ? "Base properties" : String.valueOf(categoryValue);
propertyDescriptor.setCategory(databaseObjectPropertyDescriptor.isExpert() ? "Expert" : category);
}
beanDescription = cleanDescription(beanDescription);
propertyDescriptor.setDescription(beanDescription);
}
return propertyDescriptor;
}
use of com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor in project convertigo by convertigo.
the class MobileUIComponentTreeObject method getDynamicPropertyDescriptors.
@Override
protected List<PropertyDescriptor> getDynamicPropertyDescriptors() {
List<PropertyDescriptor> l = super.getDynamicPropertyDescriptors();
DatabaseObject dbo = getObject();
if (dbo instanceof UIDynamicElement) {
IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
if (ionBean != null) {
for (IonProperty property : ionBean.getProperties().values()) {
String id = property.getName();
String displayName = property.getLabel();
String editor = property.getEditor();
Object[] values = property.getValues();
int len = values.length;
if (property.isHidden()) {
continue;
}
PropertyDescriptor propertyDescriptor = null;
if (editor.isEmpty()) {
if (len == 0) {
propertyDescriptor = new TextPropertyDescriptor(id, displayName);
} else if (len == 1) {
propertyDescriptor = new PropertyDescriptor(id, displayName);
} else {
boolean isEditable = values[len - 1].equals(true);
int size = isEditable ? len - 1 : len;
String[] tags = new String[size];
for (int i = 0; i < size; i++) {
Object value = values[i];
tags[i] = value.equals(false) ? "not set" : value.toString();
}
// propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, !isEditable);
propertyDescriptor = new MobileSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
((MobileSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
}
} else {
if (editor.equals("StringComboBoxPropertyDescriptor")) {
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
Method getTags = c.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, id });
propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, true);
} catch (Exception e) {
e.printStackTrace();
}
} else {
propertyDescriptor = new PropertyDescriptor(id, displayName) {
@Override
public CellEditor createPropertyEditor(Composite parent) {
CellEditor cellEditor = null;
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
cellEditor = (CellEditor) c.getConstructor(Composite.class).newInstance(parent);
if (cellEditor instanceof AbstractDialogCellEditor) {
((AbstractDialogCellEditor) cellEditor).databaseObjectTreeObject = MobileUIComponentTreeObject.this;
((AbstractDialogCellEditor) cellEditor).propertyDescriptor = this;
}
} catch (Exception e) {
e.printStackTrace();
}
return cellEditor;
}
};
}
}
propertyDescriptor.setCategory(property.getCategory());
propertyDescriptor.setDescription(cleanDescription(property.getDescription()));
propertyDescriptor.setValidator(getValidator(id));
l.add(propertyDescriptor);
}
}
}
return l;
}
use of com.twinsoft.convertigo.eclipse.property_editors.StringComboBoxPropertyDescriptor in project convertigo by convertigo.
the class NgxUIComponentTreeObject method getDynamicPropertyDescriptors.
@Override
protected List<PropertyDescriptor> getDynamicPropertyDescriptors() {
List<PropertyDescriptor> l = super.getDynamicPropertyDescriptors();
DatabaseObject dbo = getObject();
if (dbo instanceof UIDynamicElement) {
IonBean ionBean = ((UIDynamicElement) dbo).getIonBean();
if (ionBean != null) {
for (IonProperty property : ionBean.getProperties().values()) {
String id = property.getName();
String displayName = property.getLabel();
String editor = property.getEditor();
Object[] values = property.getValues();
int len = values.length;
if (property.isHidden()) {
continue;
}
PropertyDescriptor propertyDescriptor = null;
if (editor.isEmpty()) {
if (len == 0) {
propertyDescriptor = new TextPropertyDescriptor(id, displayName);
} else if (len == 1) {
propertyDescriptor = new PropertyDescriptor(id, displayName);
} else {
boolean isEditable = values[len - 1].equals(true);
int size = isEditable ? len - 1 : len;
String[] tags = new String[size];
for (int i = 0; i < size; i++) {
Object value = values[i];
tags[i] = value.equals(false) ? "not set" : value.toString();
}
// propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, !isEditable);
propertyDescriptor = new NgxSmartSourcePropertyDescriptor(id, displayName, tags, !isEditable);
((NgxSmartSourcePropertyDescriptor) propertyDescriptor).databaseObjectTreeObject = this;
}
} else {
if (editor.equals("StringComboBoxPropertyDescriptor")) {
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
Method getTags = c.getDeclaredMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
String[] tags = (String[]) getTags.invoke(null, new Object[] { this, id });
propertyDescriptor = new StringComboBoxPropertyDescriptor(id, displayName, tags, true);
} catch (Exception e) {
e.printStackTrace();
}
} else {
propertyDescriptor = new PropertyDescriptor(id, displayName) {
@Override
public CellEditor createPropertyEditor(Composite parent) {
CellEditor cellEditor = null;
try {
Class<?> c = Class.forName("com.twinsoft.convertigo.eclipse.property_editors." + editor);
cellEditor = (CellEditor) c.getConstructor(Composite.class).newInstance(parent);
if (cellEditor instanceof AbstractDialogCellEditor) {
((AbstractDialogCellEditor) cellEditor).databaseObjectTreeObject = NgxUIComponentTreeObject.this;
((AbstractDialogCellEditor) cellEditor).propertyDescriptor = this;
}
} catch (Exception e) {
e.printStackTrace();
}
return cellEditor;
}
};
}
}
propertyDescriptor.setCategory(property.getCategory());
propertyDescriptor.setDescription(cleanDescription(property.getDescription()));
propertyDescriptor.setValidator(getValidator(id));
l.add(propertyDescriptor);
}
}
}
return l;
}
Aggregations