use of org.eclipse.jface.text.IDocumentListener 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);
}
}
use of org.eclipse.jface.text.IDocumentListener in project hale by halestudio.
the class ValidatingSourceViewer method init.
/**
* Initialize the Job and listener.
*/
protected void init() {
validateJob = new Job("Source viewer validation") {
@Override
public boolean shouldRun() {
return validationEnabled.get();
}
@Override
public boolean shouldSchedule() {
return validationEnabled.get();
}
@Override
protected IStatus run(IProgressMonitor monitor) {
String content;
changeLock.lock();
try {
if (!changed) {
return Status.OK_STATUS;
}
IDocument doc = getDocument();
if (doc != null) {
content = doc.get();
} else {
content = "";
}
changed = false;
} finally {
changeLock.unlock();
}
boolean success = false;
try {
// this is the potentially long running stuff
success = validate(content);
} catch (Exception e) {
// ignore, but log
log.warn("Error validating document content", e);
success = false;
}
boolean notify = false;
changeLock.lock();
try {
/*
* Only notify listeners if the document was not changed in
* the meantime and the valid state is different than
* before.
*/
notify = !changed && valid != success;
if (notify) {
// set result
valid = success;
}
} finally {
changeLock.unlock();
}
if (notify) {
PropertyChangeEvent event = new PropertyChangeEvent(ValidatingSourceViewer.this, PROPERTY_VALID, !success, success);
notifyOnPropertyChange(event);
}
return Status.OK_STATUS;
}
};
validateJob.setUser(false);
validateJob.setRule(new ExclusiveSchedulingRule(this));
documentListener = new IDocumentListener() {
@Override
public void documentChanged(DocumentEvent event) {
scheduleValidation();
}
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
// do nothing
}
};
}
use of org.eclipse.jface.text.IDocumentListener in project hale by halestudio.
the class XMLStylePage3 method createControl.
/**
* @see IDialogPage#createControl(Composite)
*/
@Override
public void createControl(Composite parent) {
changed = false;
final Display display = parent.getDisplay();
FillLayout fillLayout = new FillLayout();
fillLayout.type = SWT.VERTICAL;
parent.setLayout(fillLayout);
CompositeRuler ruler = new CompositeRuler(3);
LineNumberRulerColumn lineNumbers = new LineNumberRulerColumn();
// SWT.COLOR_INFO_BACKGROUND));
lineNumbers.setBackground(display.getSystemColor(SWT.COLOR_GRAY));
// SWT.COLOR_INFO_FOREGROUND));
lineNumbers.setForeground(display.getSystemColor(SWT.COLOR_BLACK));
lineNumbers.setFont(JFaceResources.getTextFont());
ruler.addDecorator(0, lineNumbers);
viewer = new SourceViewer(parent, ruler, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
viewer.getTextWidget().setFont(JFaceResources.getTextFont());
SourceViewerConfiguration conf = new SourceViewerConfiguration();
viewer.configure(conf);
SLDTransformer trans = new SLDTransformer();
trans.setIndentation(2);
String xml;
try {
xml = trans.transform(getParent().getStyle());
} catch (TransformerException e) {
// $NON-NLS-1$
xml = "Error: " + e.getMessage();
}
IDocument doc = new Document();
doc.set(xml);
doc.addDocumentListener(new IDocumentListener() {
@Override
public void documentChanged(DocumentEvent event) {
changed = true;
}
@Override
public void documentAboutToBeChanged(DocumentEvent event) {
// ignore
}
});
viewer.setInput(doc);
setControl(viewer.getControl());
}
use of org.eclipse.jface.text.IDocumentListener in project mylyn.docs by eclipse.
the class MarkupViewerPreferencePage method createContents.
@Override
protected Control createContents(Composite parent) {
colorRegistry = new Colors();
colorRegistry.put(WHITE, new RGB(255, 255, 255));
Composite composite = new Composite(parent, SWT.NULL);
GridLayoutFactory.fillDefaults().margins(5, 5).numColumns(1).applyTo(composite);
Label label = new Label(composite, SWT.WRAP);
label.setText(Messages.MarkupViewerPreferencePage_appearanceInfo);
GridDataFactory.fillDefaults().applyTo(label);
Preferences preferences = WikiTextUiPlugin.getDefault().getPreferences();
Composite viewerContainer = new Composite(composite, SWT.BORDER);
GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1).applyTo(viewerContainer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(viewerContainer);
{
sourceViewer = new SourceViewer(viewerContainer, new VerticalRuler(0), SWT.WRAP | SWT.V_SCROLL);
GridDataFactory.fillDefaults().grab(true, true).applyTo(sourceViewer.getControl());
Document document = new Document(preferences.getMarkupViewerCss());
CssPartitioner partitioner = new CssPartitioner();
partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
sourceViewer.setDocument(document);
CssConfiguration configuration = new CssConfiguration(colorRegistry);
sourceViewer.configure(configuration);
}
label = new Label(composite, SWT.WRAP);
label.setText(Messages.MarkupViewerPreferencePage_preview);
GridDataFactory.fillDefaults().applyTo(label);
applyDialogFont(composite);
Composite previewViewerContainer = new Composite(composite, SWT.BORDER);
GridLayoutFactory.fillDefaults().margins(0, 0).numColumns(1).applyTo(previewViewerContainer);
GridDataFactory.fillDefaults().grab(true, true).applyTo(previewViewerContainer);
{
previewViewer = new HtmlViewer(previewViewerContainer, new VerticalRuler(0), SWT.WRAP | SWT.V_SCROLL);
previewViewer.getTextWidget().setBackground(colorRegistry.get(WHITE));
GridDataFactory.fillDefaults().grab(true, true).applyTo(previewViewer.getControl());
htmlViewerConfiguration = new HtmlViewerConfiguration(previewViewer);
previewViewer.configure(htmlViewerConfiguration);
previewViewer.getTextWidget().setEditable(false);
previewViewer.setStylesheet(preferences.getStylesheet());
if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT)) {
previewViewer.getTextWidget().setFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_DEFAULT_FONT));
}
if (JFaceResources.getFontRegistry().hasValueFor(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT)) {
previewViewer.setDefaultMonospaceFont(JFaceResources.getFontRegistry().get(WikiTextTasksUiPlugin.FONT_REGISTRY_KEY_MONOSPACE_FONT));
}
previewViewer.setHtml(createPreviewHtml());
sourceViewer.getDocument().addDocumentListener(new IDocumentListener() {
public void documentAboutToBeChanged(DocumentEvent event) {
}
public void documentChanged(DocumentEvent event) {
schedulePreviewUpdate();
}
});
}
return composite;
}
use of org.eclipse.jface.text.IDocumentListener in project ow by vtst.
the class AbstractEditorRegistry method removeEditor.
private synchronized void removeEditor(ITextEditor textEditor) {
IFile file = editorToFile.get(textEditor);
if (file != null)
fileToEditors.remove(file, textEditor);
IDocument document = editorToDocument.get(textEditor);
if (document != null) {
if (documentToEditors.remove(document, textEditor)) {
IDocumentListener listener = documentToListener.remove(document);
if (listener != null)
document.removeDocumentListener(listener);
documentToFile.remove(document);
}
}
}
Aggregations