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);
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method initializeModel.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.viewer.ReconcilerViewer#initializeModel(IDocument document)
*/
@Override
protected void initializeModel() {
getSourceViewerDecorationSupport().install(JavaPlugin.getDefault().getCombinedPreferenceStore());
this.setRangeIndicator(new DefaultRangeIndicator());
IAnnotationModel model;
IDocument document;
if (checkCode) {
IDocumentProvider provider = JavaPlugin.getDefault().getCompilationUnitDocumentProvider();
IEditorInput ei = new FileEditorInput(file);
try {
provider.connect(ei);
} catch (CoreException e) {
ExceptionHandler.process(e);
}
document = provider.getDocument(ei);
model = provider.getAnnotationModel(ei);
} else {
model = new AnnotationModel();
document = getDocument();
model.connect(document);
}
if (document != null) {
setDocument(document, model);
showAnnotations(model != null && checkCode);
}
super.initializeModel();
}
use of org.eclipse.jface.text.IDocument in project tdi-studio-se by Talend.
the class TalendCompletionProposalComputer method computeCompletionProposals.
@Override
public List computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
//$NON-NLS-1$
String prefix = "";
try {
if (context != null) {
prefix = context.computeIdentifierPrefix().toString();
//$NON-NLS-1$
String tmpPrefix = "";
IDocument doc = context.getDocument();
if ((!prefix.equals("")) || (doc.get().length() == 0)) {
//$NON-NLS-1$
tmpPrefix = prefix;
} else {
int offset = context.getInvocationOffset();
if (doc.getChar(offset - 1) == '.') {
// set by default to avoid other completions
//$NON-NLS-1$
tmpPrefix = ".";
if (offset >= CONTEXT_PREFIX.length() && doc.get(offset - CONTEXT_PREFIX.length(), CONTEXT_PREFIX.length()).equals(CONTEXT_PREFIX)) {
tmpPrefix = CONTEXT_PREFIX;
} else if (offset >= PERL_GLOBAL_PREFIX.length() & doc.get(offset - PERL_GLOBAL_PREFIX.length(), PERL_GLOBAL_PREFIX.length()).equals(PERL_GLOBAL_PREFIX)) {
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
// do nothing
break;
case PERL:
default:
tmpPrefix = PERL_GLOBAL_PREFIX;
}
} else {
// test each component label.
IDesignerCoreService service = (IDesignerCoreService) GlobalServiceRegister.getDefault().getService(IDesignerCoreService.class);
IProcess process = service.getCurrentProcess();
if (process == null) {
return Collections.EMPTY_LIST;
}
List<? extends INode> nodes = process.getGraphicalNodes();
for (INode node : nodes) {
//$NON-NLS-1$
String toTest = node.getLabel() + ".";
if (offset >= toTest.length() && doc.get(offset - toTest.length(), toTest.length()).equals(toTest)) {
tmpPrefix = toTest;
break;
}
}
}
}
}
prefix = tmpPrefix;
if (".".equals(prefix) && LanguageManager.getCurrentLanguage().equals(ECodeLanguage.PERL)) {
//$NON-NLS-1$
//$NON-NLS-1$
prefix = "";
}
}
} catch (BadLocationException e) {
throw new RuntimeException(e);
}
return computeCompletionProposals(context.getViewer(), prefix, context.getInvocationOffset(), monitor);
}
Aggregations