Search in sources :

Example 1 with FileInPlaceEditorInput

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;
}
Also used : FileInPlaceEditorInput(org.eclipse.ui.part.FileInPlaceEditorInput) IFile(org.eclipse.core.resources.IFile) InputStream(java.io.InputStream) IEditorPart(org.eclipse.ui.IEditorPart) PartInitException(org.eclipse.ui.PartInitException) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) DatabaseObject(com.twinsoft.convertigo.beans.core.DatabaseObject) PartInitException(org.eclipse.ui.PartInitException)

Aggregations

DatabaseObject (com.twinsoft.convertigo.beans.core.DatabaseObject)1 InputStream (java.io.InputStream)1 IFile (org.eclipse.core.resources.IFile)1 IEditorPart (org.eclipse.ui.IEditorPart)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 PartInitException (org.eclipse.ui.PartInitException)1 FileInPlaceEditorInput (org.eclipse.ui.part.FileInPlaceEditorInput)1