use of org.eclipse.ui.part.FileInPlaceEditorInput in project convertigo by convertigo.
the class GenericTextEditor method openDialogBox.
@Override
protected Object openDialogBox(Control cellEditorWindow) {
if (dialogCompositeClass != TextEditorComposite.class) {
return super.openDialogBox(cellEditorWindow);
}
try {
IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
if (activePage == null) {
return null;
}
String propertyName = (String) propertyDescriptor.getId();
java.beans.PropertyDescriptor[] propertyDescriptors = databaseObjectTreeObject.databaseObjectBeanInfo.getPropertyDescriptors();
java.beans.PropertyDescriptor propertyDescriptor = null;
for (java.beans.PropertyDescriptor pd : propertyDescriptors) {
if (propertyName.equals(pd.getName())) {
propertyDescriptor = pd;
break;
}
}
String extension = (propertyDescriptor != null && propertyDescriptor.getValue(MySimpleBeanInfo.GENERIC_EDITOR_EXTENSION) != null) ? propertyDescriptor.getValue(MySimpleBeanInfo.GENERIC_EDITOR_EXTENSION).toString() : "txt";
DatabaseObject dbo = databaseObjectTreeObject.getObject();
IFile file = databaseObjectTreeObject.getProjectTreeObject().getFile("_private/editor/" + dbo.getShortQName() + "/" + propertyName + "." + extension);
SwtUtils.fillFile(file, getValue().toString());
FileInPlaceEditorInput input = new FileInPlaceEditorInput(file);
IEditorPart editor = activePage.openEditor(input, "org.eclipse.ui.genericeditor.GenericEditor");
editor.addPropertyListener((Object source, int propId) -> {
if (propId == IEditorPart.PROP_DIRTY && !((IEditorPart) source).isDirty()) {
try (InputStream is = file.getContents()) {
setNewValue(IOUtils.toString(is, "UTF-8"));
} catch (Exception e) {
Engine.logStudio.error("Failed to save " + file.getName(), e);
}
}
});
} catch (PartInitException e) {
Engine.logStudio.error("failed to open editor", e);
}
return null;
}
Aggregations