use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DatabaseObjectTreeObject method rename.
public boolean rename(String newName, boolean bDialog) {
try {
if (!StringUtils.isNormalized(newName)) {
throw new ConvertigoException("The name \"" + newName + "\" must be normalized.\nDon't start with number and don't use non ASCII caracters.");
}
DatabaseObject databaseObject = getObject();
String oldName = databaseObject.getName();
if (newName.equals(oldName)) {
return true;
}
if (newName.equalsIgnoreCase(oldName)) {
throw new ConvertigoException("The rename operation is case insensitive.");
}
rename_(newName, bDialog);
} catch (ConvertigoException e) {
ConvertigoPlugin.logException(e, "Unable to change the object name.", bDialog);
return false;
} catch (CoreException e) {
ConvertigoPlugin.logException(e, "Unable to change the object name.", bDialog);
return false;
}
return true;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DatabaseObjectTreeObject method rename_.
protected void rename_(String newName, boolean bDialog) throws ConvertigoException, CoreException {
// Verify if an object with the same name exists
TreeObject siblingTreeObject = this;
while ((siblingTreeObject = siblingTreeObject.getPreviousSibling()) != null) {
if (siblingTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject siblingDatabaseObjectTreeObject = (DatabaseObjectTreeObject) siblingTreeObject;
if (!siblingDatabaseObjectTreeObject.isInherited) {
DatabaseObject databaseObjectTmp = siblingDatabaseObjectTreeObject.getObject();
String databaseObjectName = databaseObjectTmp.getName();
if (databaseObjectName.equalsIgnoreCase(newName)) {
throw new ConvertigoException("Another object with the same name already exists (case insensitive).");
}
}
}
}
siblingTreeObject = this;
while ((siblingTreeObject = siblingTreeObject.getNextSibling()) != null) {
if (siblingTreeObject instanceof DatabaseObjectTreeObject) {
DatabaseObjectTreeObject siblingDatabaseObjectTreeObject = (DatabaseObjectTreeObject) siblingTreeObject;
if (!siblingDatabaseObjectTreeObject.isInherited) {
DatabaseObject databaseObjectTmp = siblingDatabaseObjectTreeObject.getObject();
String databaseObjectName = databaseObjectTmp.getName();
if (databaseObjectName.equalsIgnoreCase(newName)) {
throw new ConvertigoException("Another object with the same name already exists (case insensitive).");
}
}
}
}
DatabaseObject databaseObject = getObject();
databaseObject.setName(newName);
databaseObject.hasChanged = true;
hasBeenModified(true);
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DatabaseObjectTreeObject method getDescriptors.
protected void getDescriptors() {
if (propertyDescriptors != null && databaseObjectBeanDescriptor != null && databaseObjectPropertyDescriptors != null) {
return;
}
DatabaseObject databaseObject = getObject();
if ((!(databaseObject instanceof Project)) && (databaseObject.getParent() == null))
// No needs for removed object
return;
int len;
java.beans.PropertyDescriptor databaseObjectPropertyDescriptor;
try {
BeanInfo bi = databaseObjectBeanInfo = CachedIntrospector.getBeanInfo(databaseObject.getClass());
databaseObjectBeanDescriptor = bi.getBeanDescriptor();
databaseObjectPropertyDescriptors = bi.getPropertyDescriptors();
len = databaseObjectPropertyDescriptors.length;
} catch (Exception e) {
String message = "Error while introspecting object " + databaseObject.getName() + " (" + databaseObject.getQName() + ")";
ConvertigoPlugin.logException(e, message);
return;
}
List<PropertyDescriptor> vPropertyDescriptors = new ArrayList<PropertyDescriptor>(32);
PropertyDescriptor propertyDescriptor;
propertyDescriptor = new PropertyDescriptor(P_TYPE, "Type");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_JAVA_CLASS, "Java class");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_NAME, "Name");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_QNAME, "QName");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_PRIORITY, "Priority");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_DEPTH, "Depth");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_EXPORTED, "Exported");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
propertyDescriptor = new PropertyDescriptor(P_MIN_VERSION, "Min version");
propertyDescriptor.setCategory("Information");
vPropertyDescriptors.add(propertyDescriptor);
// Get Dynamic properties
List<PropertyDescriptor> dynamicPropertyDescriptors = getDynamicPropertyDescriptors();
for (PropertyDescriptor dynamicPropertyDescriptor : dynamicPropertyDescriptors) {
vPropertyDescriptors.add(dynamicPropertyDescriptor);
}
// Get properties
boolean isExtractionRule = (databaseObject instanceof com.twinsoft.convertigo.beans.core.ExtractionRule);
boolean isMaskedProperty = false;
for (int i = 0; i < len; i++) {
databaseObjectPropertyDescriptor = databaseObjectPropertyDescriptors[i];
// Don't display hidden or expert propertyDescriptors.
if (databaseObjectPropertyDescriptor.isHidden()) {
continue;
}
if (databaseObject.checkBlackListParentClass(databaseObjectPropertyDescriptor)) {
continue;
}
String name = databaseObjectPropertyDescriptor.getName();
String displayName = databaseObjectPropertyDescriptor.getDisplayName();
Method getter = databaseObjectPropertyDescriptor.getReadMethod();
Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
// Only display read/write propertyDescriptors.
if (getter == null || setter == null) {
continue;
}
Class<?> pec = null;
try {
Object[] args = {};
Object value = getter.invoke(databaseObject, args);
pec = databaseObjectPropertyDescriptor.getPropertyEditorClass();
// Now figure out how to display it...
isMaskedProperty = databaseObject.isMaskedProperty(Visibility.Studio, name);
propertyDescriptor = findPropertyDescriptor(name, displayName, databaseObjectPropertyDescriptor, value, pec, isExtractionRule, isMaskedProperty);
if (isMaskedProperty) {
propertyDescriptor.setLabelProvider(new LabelProvider() {
@Override
public String getText(Object element) {
String regexp = element instanceof String ? "." : "[^\\[\\]\\,]";
String text = super.getText(element);
return text.replaceAll(regexp, "*");
}
});
}
vPropertyDescriptors.add(propertyDescriptor);
} catch (Exception e) {
String message = "Error while introspecting parameter \"" + name + "\"";
ConvertigoPlugin.logException(e, message);
continue;
}
}
propertyDescriptors = (IPropertyDescriptor[]) vPropertyDescriptors.toArray(new IPropertyDescriptor[] {});
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DatabaseObjectTreeObject method equals.
@Override
public boolean equals(Object obj) {
if (super.equals(obj)) {
return true;
}
if (obj instanceof DatabaseObjectTreeObject) {
DatabaseObject o1 = getObject();
DatabaseObject o2 = ((DatabaseObjectTreeObject) obj).getObject();
return o1 != null && o1.equals(o2);
}
return false;
}
use of com.twinsoft.convertigo.beans.core.DatabaseObject in project convertigo by convertigo.
the class DatabaseObjectTreeObject method setPropertyValue.
public void setPropertyValue(Object id, Object value) {
MobileBuilder mb = null;
IEditorPart editorPart = ConvertigoPlugin.getDefault().getApplicationComponentEditor();
if (editorPart != null) {
IEditorInput input = editorPart.getEditorInput();
if (input instanceof com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.mobile.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
if (input instanceof com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput) {
com.twinsoft.convertigo.eclipse.editors.ngx.ApplicationComponentEditorInput editorInput = GenericUtils.cast(input);
mb = editorInput.getApplication().getProject().getMobileBuilder();
}
}
DatabaseObject databaseObject = getObject();
Object oldValue = getPropertyValue(id);
String propertyName = (String) id;
ComboBoxCellEditor editor = DynamicComboBoxPropertyDescriptor.getLast();
if (editor != null && (!acceptSymbols() || !Integer.valueOf(editor.getItems().length - 1).equals(value))) {
editor = null;
}
if (isValueInProcess || (oldValue != null && oldValue.equals(value) && editor == null)) {
return;
}
try {
isValueInProcess = true;
java.beans.PropertyDescriptor databaseObjectPropertyDescriptor = getPropertyDescriptor(propertyName);
TreeViewer viewer = (TreeViewer) getAdapter(TreeViewer.class);
if (databaseObjectPropertyDescriptor == null)
return;
Class<?> propertyClass = databaseObjectPropertyDescriptor.getPropertyType();
Class<?> pec = databaseObjectPropertyDescriptor.getPropertyEditorClass();
if (editor != null) {
Control control = editor.getControl();
Display display = control.getDisplay();
final Shell shell = new Shell(control.getShell(), SWT.ON_TOP | SWT.TOOL | SWT.NO_FOCUS | SWT.APPLICATION_MODAL);
shell.setLocation(control.toDisplay(0, 0));
shell.setSize(control.getSize());
shell.setLayout(new FillLayout());
final Text text = new Text(shell, SWT.NONE);
final String[] newValue = new String[] { null };
String[] items = editor.getItems();
text.setText(items[items.length - 1]);
text.addTraverseListener(new TraverseListener() {
@Override
public void keyTraversed(TraverseEvent e) {
if (e.detail == SWT.TRAVERSE_RETURN) {
newValue[0] = text.getText();
shell.close();
}
}
});
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
if (newValue[0] != null) {
value = newValue[0];
}
}
Object oriValue = value;
boolean changed;
do {
changed = false;
boolean wasSymbolError = databaseObject.isSymbolError();
value = databaseObject.compileProperty(propertyClass, propertyName, oriValue);
try {
oldValue = Engine.theApp.databaseObjectsManager.getCompiledValue(oldValue);
} catch (UndefinedSymbolsException e) {
oldValue = e.incompletValue();
}
Set<String> symbolsErrors = databaseObject.getSymbolsErrors(propertyName);
if (symbolsErrors != null) {
boolean[] res = ConvertigoPlugin.warningGlobalSymbols(databaseObject.getProject().getName(), databaseObject.getName(), databaseObject.getDatabaseType(), propertyName, "" + databaseObject.getCompilablePropertySourceValue(propertyName), symbolsErrors, false);
changed = res[0];
if (changed) {
Engine.theApp.databaseObjectsManager.symbolsCreateUndefined(symbolsErrors);
} else {
databaseObject.getProject().undefinedGlobalSymbols = true;
viewer.update(getProjectTreeObject(), null);
}
} else if (wasSymbolError) {
Engine.theApp.databaseObjectsManager.symbolsProjectCheckUndefined(databaseObject.getProject().getName());
viewer.update(getProjectTreeObject(), null);
}
} while (changed);
if (editor != null && value instanceof String) {
String[] items = editor.getItems();
int len = items.length - 1;
String strValue = (String) value;
value = 0;
for (int i = 0; i < len; i++) {
if (items[i].equals(strValue)) {
value = i;
break;
}
;
}
}
if (pec != null && propertyClass != int.class && propertyClass != Integer.class && value instanceof Integer) {
Object[] values = null;
try {
int index = (Integer) value;
if (PropertyWithTagsEditorAdvance.class.isAssignableFrom(pec)) {
Method getTags = pec.getMethod("getTags", new Class[] { DatabaseObjectTreeObject.class, String.class });
values = (String[]) getTags.invoke(null, new Object[] { this, propertyName });
value = values[index];
} else if (Enum.class.isAssignableFrom(pec)) {
values = (Enum[]) pec.getMethod("values").invoke(null);
value = index < values.length ? values[index] : values[0];
if (propertyClass == String.class) {
value = value.toString();
}
}
} catch (ArrayIndexOutOfBoundsException e) {
value = values.length > 0 ? values[0] : "";
String message = "Incorrect property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\".";
ConvertigoPlugin.logWarning(message);
}
}
if ((EmulatorTechnologyEditor.class.equals(pec))) {
Method getEmulatorClassNames = pec.getDeclaredMethod("getEmulatorClassNames", new Class[] { DatabaseObjectTreeObject.class });
String[] emulatorClassNames = (String[]) getEmulatorClassNames.invoke(null, new Object[] { this });
value = emulatorClassNames[((Integer) value).intValue()];
}
// Must rename bean when normalizedScreenClassName changed
if (databaseObject instanceof ScHandlerStatement) {
ScHandlerStatement scHandlerStatement = (ScHandlerStatement) databaseObject;
if (propertyName.equals("normalizedScreenClassName")) {
if (!this.rename("on" + (String) value + scHandlerStatement.getHandlerType(), Boolean.FALSE))
return;
}
} else // Must rename bean when handlerType changed
if ((databaseObject instanceof HandlerStatement) && !(databaseObject instanceof ScDefaultHandlerStatement)) {
// HandlerStatement handlerStatement = (HandlerStatement)databaseObject;
if (propertyName.equals("handlerType")) {
if (!this.rename("on" + (String) value, Boolean.FALSE))
return;
}
}
// Set property's nillable value
if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue("nillable"))) {
try {
PropertyDescriptor pd = findPropertyDescriptor(propertyName);
if ((pd != null) && (pd instanceof DataOrNullPropertyDescriptor)) {
Boolean isNull = ((DataOrNullPropertyDescriptor) pd).isNullProperty();
((INillableProperty) databaseObject).setNullProperty(propertyName, isNull);
if (isNull) {
// Overrides fake editor value to real bean's one
if (value instanceof String)
value = "";
if (value instanceof XMLVector)
value = new XMLVector<Object>();
}
}
} catch (Exception e) {
String message = "Error while trying to set 'isNull' attribute of property \"" + propertyName + "\" for the object \"" + databaseObject.getName() + "\".";
ConvertigoPlugin.logException(e, message);
}
}
// Check XML name property value if needed
if (Boolean.TRUE.equals(databaseObjectPropertyDescriptor.getValue(DatabaseObject.PROPERTY_XMLNAME))) {
if (value instanceof String) {
String sValue = value.toString();
if (!XMLUtils.checkName(sValue)) {
String message = "The property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\" is not a valid XML name: " + sValue;
ConvertigoPlugin.logWarning(message);
return;
}
}
}
Method setter = databaseObjectPropertyDescriptor.getWriteMethod();
Object[] args = { value };
setter.invoke(databaseObject, args);
hasBeenModified(true);
// Set treeObject isEnabled attribute value (Fix #1129)
if (propertyName.equals("isEnabled") || propertyName.equals("isEnable")) {
setEnabled(value.equals(true));
}
viewer.update(this, null);
// update property view and display the new value for zone editor
if (pec != null) {
PropertySheet propertySheet = ConvertigoPlugin.getDefault().getPropertiesView();
if (propertySheet != null && pec.getName().contains("ZoneEditor")) {
Tree tree = (Tree) propertySheet.getCurrentPage().getControl();
TreeItem[] treeItems = tree.getSelection();
for (int i = 0; i < treeItems.length; i++) {
TreeItem treeItem = treeItems[i];
if (treeItem.getText().equals(databaseObjectPropertyDescriptor.getDisplayName())) {
PropertySheetEntry propEntry = (PropertySheetEntry) treeItem.getData();
propEntry.getEditor(tree).setValue(value);
propEntry.setValues(args);
}
}
tree.update();
}
}
Engine.logStudio.info("---------------------- SetPropertyValue started: " + propertyName + "----------------------");
if (mb != null) {
mb.prepareBatchBuild();
}
BatchOperationHelper.start();
TreeObjectEvent treeObjectEvent = new TreeObjectEvent(this, propertyName, oldValue, value);
ConvertigoPlugin.projectManager.getProjectExplorerView().fireTreeObjectPropertyChanged(treeObjectEvent);
BatchOperationHelper.stop();
} catch (Exception e) {
String message = "Error while trying to set property \"" + propertyName + "\" value for the object \"" + databaseObject.getName() + "\".";
ConvertigoPlugin.logException(e, message);
} finally {
BatchOperationHelper.cancel();
Engine.logStudio.info("---------------------- SetPropertyValue ended: " + propertyName + "----------------------");
isValueInProcess = false;
}
}
Aggregations