use of org.eclipse.jdt.ui.text.JavaTextTools in project tdi-studio-se by Talend.
the class CodeView method createPartControl.
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
parent.setLayout(new FillLayout());
ECodeLanguage language = LanguageManager.getCurrentLanguage();
ISourceViewer viewer = null;
final StyledText text;
int styles = SWT.H_SCROLL | SWT.V_SCROLL;
document = new Document();
switch(language) {
case JAVA:
IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
viewer = new JavaSourceViewer(parent, null, null, false, styles, store);
viewer.setDocument(document);
JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
tools.setupJavaDocumentPartitioner(viewer.getDocument(), IJavaPartitions.JAVA_PARTITIONING);
SimpleJavaSourceViewerConfiguration config = new SimpleJavaSourceViewerConfiguration(tools.getColorManager(), store, null, IJavaPartitions.JAVA_PARTITIONING, true);
viewer.configure(config);
viewer.getTextWidget().setFont(JFaceResources.getFont(PreferenceConstants.EDITOR_TEXT_FONT));
document = viewer.getDocument();
break;
// empty since only have java
default:
}
viewer.setEditable(false);
text = viewer.getTextWidget();
// getSite().getWorkbenchWindow().getSelectionService().addSelectionListener(this);
IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
IAction wrapAction = new Action() {
@Override
public void run() {
text.setWordWrap(isChecked());
}
};
//$NON-NLS-1$
wrapAction.setToolTipText("wrap");
wrapAction.setChecked(false);
//$NON-NLS-1$
wrapAction.setImageDescriptor(ImageDescriptor.createFromFile(DesignerPlugin.class, "/icons/wrap.gif"));
tbm.add(wrapAction);
createMenu();
}
use of org.eclipse.jdt.ui.text.JavaTextTools in project tdi-studio-se by Talend.
the class TalendJavaSourceViewer method installViewerConfiguration.
/*
* (non-Javadoc)
*
* @see org.talend.core.ui.viewer.ReconcilerViewer#installViewerConfiguration()
*/
@Override
protected void installViewerConfiguration() {
JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
tools.setupJavaDocumentPartitioner(getDocument(), IJavaPartitions.JAVA_PARTITIONING);
IPreferenceStore store = JavaPlugin.getDefault().getCombinedPreferenceStore();
configure(new TalendJavaViewerConfiguration((IColorManager) sharedColors, store, this));
}
use of org.eclipse.jdt.ui.text.JavaTextTools in project tdi-studio-se by Talend.
the class JavaProcessor method formatCode.
/**
* DOC nrousseau Comment method "formatCode".
*
* from SourceViewer.doOperation for FORMAT.
*
* @param processCode
* @return
*/
@SuppressWarnings({ "unchecked" })
private String formatCode(String processCode) {
// we cannot make calls to Ui in headless mode
if (ProcessorUtilities.isExportConfig() || CommonsPlugin.isHeadless()) {
// nothing to do
return processCode;
}
final IDocument document = new Document(processCode);
JavaTextTools tools = JavaPlugin.getDefault().getJavaTextTools();
tools.setupJavaDocumentPartitioner(document, IJavaPartitions.JAVA_PARTITIONING);
IFormattingContext context = null;
DocumentRewriteSession rewriteSession = null;
if (document instanceof IDocumentExtension4) {
rewriteSession = ((IDocumentExtension4) document).startRewriteSession(DocumentRewriteSessionType.SEQUENTIAL);
}
try {
final String rememberedContents = document.get();
try {
final MultiPassContentFormatter formatter = new MultiPassContentFormatter(IJavaPartitions.JAVA_PARTITIONING, IDocument.DEFAULT_CONTENT_TYPE);
formatter.setMasterStrategy(new JavaFormattingStrategy());
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_DOC);
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_SINGLE_LINE_COMMENT);
// formatter.setSlaveStrategy(new CommentFormattingStrategy(),
// IJavaPartitions.JAVA_MULTI_LINE_COMMENT);
context = new FormattingContext();
context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
Map<String, String> preferences;
if (this.getTalendJavaProject() == null) {
preferences = new HashMap<String, String>(JavaCore.getOptions());
} else {
// use project options
preferences = new HashMap<String, String>(this.getTalendJavaProject().getJavaProject().getOptions(true));
}
context.setProperty(FormattingContextProperties.CONTEXT_PREFERENCES, preferences);
formatter.format(document, context);
} catch (RuntimeException x) {
// fire wall for
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
// if something went wrong we undo the changes we just did
// TODO to be removed after 3.0 M8
document.set(rememberedContents);
throw x;
}
} finally {
if (rewriteSession != null && document instanceof IDocumentExtension4) {
((IDocumentExtension4) document).stopRewriteSession(rewriteSession);
}
if (context != null) {
context.dispose();
}
}
return document.get();
}
use of org.eclipse.jdt.ui.text.JavaTextTools in project jbosstools-hibernate by jbosstools.
the class CriteriaEditorDocumentSetupParticipant method setup.
/**
* Sets up the document to be ready for use by a text file buffer.
*
* @see org.eclipse.core.filebuffers.IDocumentSetupParticipant#setup(org.eclipse.jface.text.IDocument)
*/
public void setup(IDocument document) {
JavaTextTools tools = HibernateConsolePlugin.getDefault().getJavaTextTools();
IDocumentPartitioner partitioner = tools.createDocumentPartitioner();
partitioner.connect(document);
if (document instanceof IDocumentExtension3) {
IDocumentExtension3 extension3 = (IDocumentExtension3) document;
extension3.setDocumentPartitioner(IJavaPartitions.JAVA_PARTITIONING, partitioner);
} else {
document.setDocumentPartitioner(partitioner);
}
}
Aggregations