use of com.liferay.ide.kaleo.ui.editor.HiddenFileEditorInput in project liferay-ide by liferay.
the class AbstractKaleoEditorHelper method openEditor.
public void openEditor(ISapphirePart sapphirePart, Element modelElement, ValueProperty valueProperty) {
try {
Object content = modelElement.property(valueProperty).content();
if (content == null) {
content = "";
}
IProject project = sapphirePart.adapt(IProject.class);
IEditorInput editorInput = modelElement.adapt(IEditorInput.class);
String name = editorInput.getName();
Node node = modelElement.nearest(Node.class);
String nodeName = node.getName().content();
HiddenFileEditorInput hiddenFileEditorInput = _getHiddenFileEditorInput(project, name, nodeName, content.toString());
IEditorSite editorSite = sapphirePart.adapt(IEditorSite.class);
IWorkbenchWindow wbWindow = editorSite.getWorkbenchWindow();
IEditorPart editorPart = wbWindow.getActivePage().openEditor(hiddenFileEditorInput, _editorId);
ITextEditor textEditor = (ITextEditor) editorPart.getAdapter(ITextEditor.class);
IDocumentListener documentListener = new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
String contents = event.getDocument().get();
modelElement.property(valueProperty).write(contents);
}
};
IDocumentProvider documentProvider = textEditor.getDocumentProvider();
documentProvider.getDocument(hiddenFileEditorInput).addDocumentListener(documentListener);
IWorkbenchPartSite wbPartSite = editorPart.getSite();
IPartListener partListener = new IPartListener() {
public void partActivated(IWorkbenchPart part) {
}
public void partBroughtToTop(IWorkbenchPart part) {
}
public void partClosed(IWorkbenchPart part) {
if ((part != null) && part.equals(editorPart)) {
new WorkspaceJob("delete temp editor file") {
@Override
public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
try {
IFile file = hiddenFileEditorInput.getFile();
file.getParent().delete(true, null);
} catch (CoreException ce) {
}
return Status.OK_STATUS;
}
}.schedule(100);
}
}
public void partDeactivated(IWorkbenchPart part) {
}
public void partOpened(IWorkbenchPart part) {
}
};
wbPartSite.getPage().addPartListener(partListener);
} catch (Exception e) {
KaleoUI.logError("Error opening editor.", e);
}
}
Aggregations