use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class ResourceChange method getModificationStamp.
private long getModificationStamp(IResource resource) {
if (!(resource instanceof IFile))
return resource.getModificationStamp();
IFile file = (IFile) resource;
ITextFileBuffer buffer = getBuffer(file);
if (buffer == null) {
return file.getModificationStamp();
} else {
IDocument document = buffer.getDocument();
if (document instanceof IDocumentExtension4) {
return ((IDocumentExtension4) document).getModificationStamp();
} else {
return file.getModificationStamp();
}
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class MultiStateUndoChange method perform.
/**
* {@inheritDoc}
*/
public Change perform(IProgressMonitor pm) throws CoreException {
if (fValidationState == null || fValidationState.isValid(needsSaving(), false).hasFatalError())
return new NullChange();
if (pm == null)
pm = new NullProgressMonitor();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
//$NON-NLS-1$
pm.beginTask("", 2);
ITextFileBuffer buffer = null;
try {
manager.connect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
buffer = manager.getTextFileBuffer(fFile.getFullPath(), LocationKind.IFILE);
IDocument document = buffer.getDocument();
ContentStamp currentStamp = ContentStamps.get(fFile, document);
// perform the changes
LinkedList list = new LinkedList();
for (int index = 0; index < fUndos.length; index++) {
UndoEdit edit = fUndos[index];
UndoEdit redo = edit.apply(document, TextEdit.CREATE_UNDO);
list.addFirst(redo);
}
// try to restore the document content stamp
boolean success = ContentStamps.set(document, fContentStampToRestore);
if (needsSaving()) {
buffer.commit(pm, false);
if (!success) {
// We weren't able to restore document stamp.
// Since we save restore the file stamp instead
ContentStamps.set(fFile, fContentStampToRestore);
}
}
return createUndoChange((UndoEdit[]) list.toArray(new UndoEdit[list.size()]), currentStamp);
} catch (BadLocationException e) {
throw Changes.asCoreException(e);
} finally {
if (buffer != null)
manager.disconnect(fFile.getFullPath(), LocationKind.IFILE, new SubProgressMonitor(pm, 1));
}
}
use of org.eclipse.jface.text.IDocument in project che by eclipse.
the class TextFileChange method acquireDocument.
/**
* {@inheritDoc}
*/
protected IDocument acquireDocument(IProgressMonitor pm) throws CoreException {
fAcquireCount++;
if (fAcquireCount > 1)
return fBuffer.getDocument();
ITextFileBufferManager manager = FileBuffers.getTextFileBufferManager();
IPath path = fFile.getFullPath();
manager.connect(path, LocationKind.IFILE, pm);
fBuffer = manager.getTextFileBuffer(path, LocationKind.IFILE);
IDocument result = fBuffer.getDocument();
fContentStamp = ContentStamps.get(fFile, result);
return result;
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method createViewerForIfConnection.
public static ISourceViewer createViewerForIfConnection(Composite composite) {
StringBuffer buff = new StringBuffer();
//$NON-NLS-1$
buff.append("package internal;\n\n");
buff.append(getImports());
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
//$NON-NLS-1$
buff.append("\tprivate static java.util.Properties context = new java.util.Properties();\n");
//$NON-NLS-1$
buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
//$NON-NLS-1$
buff.append("\tpublic void myFunction(){\n");
//$NON-NLS-1$
buff.append("\t if( \n");
int documentOffset = buff.toString().length();
//$NON-NLS-1$
buff.append("){\n\t}");
//$NON-NLS-1$
buff.append("\n\t\n}\n}");
IDocument document = new Document();
document.set(buff.toString());
boolean checkCode = false;
int styles = SWT.BORDER | SWT.MULTI | SWT.V_SCROLL | SWT.H_SCROLL | SWT.WRAP;
return initializeViewer(composite, styles, checkCode, document, documentOffset);
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method createViewerWithVariables.
public static ReconcilerViewer createViewerWithVariables(Composite composite, int styles, IExpressionDataBean dataBean) {
IDocument document = new Document();
StringBuffer buff = new StringBuffer();
//$NON-NLS-1$
buff.append("\npackage internal;\n\n");
buff.append(getImports());
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("public class " + VIEWER_CLASS_NAME + currentId + " {\n");
IRunProcessService runProcessService = getRunProcessService();
if (runProcessService != null && runProcessService.getSelectedContext() != null) {
List<IContextParameter> params = runProcessService.getSelectedContext().getContextParameterList();
buff.append(TEXT_1);
for (IContextParameter ctxParam : params) {
buff.append(TEXT_2);
buff.append(ctxParam.getName());
buff.append(TEXT_3);
buff.append(ctxParam.getName());
buff.append(TEXT_4);
}
buff.append(TEXT_5);
for (IContextParameter ctxParam : params) {
if (//$NON-NLS-1$ //$NON-NLS-2$
ctxParam.getType().equals("id_List Of Value") || ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") || ctxParam.getType().equals("id_Character")) {
//$NON-NLS-1$ //$NON-NLS-2$
buff.append(TEXT_6);
buff.append(ctxParam.getName());
buff.append(TEXT_7);
} else {
buff.append(TEXT_8);
buff.append(JavaTypesManager.getTypeToGenerate(ctxParam.getType(), true));
buff.append(TEXT_9);
buff.append(ctxParam.getName());
buff.append(TEXT_10);
}
}
buff.append(TEXT_11);
//$NON-NLS-1$
buff.append("\tprivate static ContextProperties context = new ContextProperties();\n");
//$NON-NLS-1$
buff.append("\tprivate static final java.util.Map<String, Object> globalMap = new java.util.HashMap<String, Object>();\n");
if (dataBean != null) {
buff.append(parseVariables(dataBean.getVariables()));
//$NON-NLS-1$ //$NON-NLS-2$
buff.append("\tpublic " + dataBean.getExpressionType() + " myFunction(){\n");
}
//$NON-NLS-1$
buff.append("\t\treturn \n");
}
int length = buff.toString().length();
//$NON-NLS-1$
String defaultValue = "";
//$NON-NLS-1$
buff.append(defaultValue + "\n;\t\n}\n}");
document.set(buff.toString());
return initializeViewer(composite, styles, true, document, length);
}
Aggregations