Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornick2001-08-28 15:50:40 +0000
committernick2001-08-28 15:50:40 +0000
commitc328a6438da67f7dfad67582b72036e9aa3cde0f (patch)
tree6d1eded8543279fe45804ea23769bb60c1f5dd08 /org.eclipse.ui.examples.javaeditor
parenta353cc58ae2043547c965d605224661001b34287 (diff)
downloadeclipse.platform.text-c328a6438da67f7dfad67582b72036e9aa3cde0f.tar.gz
eclipse.platform.text-c328a6438da67f7dfad67582b72036e9aa3cde0f.tar.xz
eclipse.platform.text-c328a6438da67f7dfad67582b72036e9aa3cde0f.zip
kum: build submission 133
Diffstat (limited to 'org.eclipse.ui.examples.javaeditor')
-rw-r--r--org.eclipse.ui.examples.javaeditor/.cvsignore2
-rw-r--r--org.eclipse.ui.examples.javaeditor/.vcm_meta11
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java76
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java34
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java244
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java57
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java134
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java67
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java30
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties33
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java137
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java42
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java47
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java265
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java77
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java102
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java234
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java26
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java81
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaWordDetector.java63
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java66
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java80
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gifbin0 -> 125 bytes
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java53
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java21
-rw-r--r--org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java28
-rw-r--r--org.eclipse.ui.examples.javaeditor/build.properties12
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm14
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gifbin0 -> 814 bytes
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html236
-rw-r--r--org.eclipse.ui.examples.javaeditor/icons/basic/obj16/java.gifbin0 -> 140 bytes
-rw-r--r--org.eclipse.ui.examples.javaeditor/plugin.jars1
-rw-r--r--org.eclipse.ui.examples.javaeditor/plugin.properties14
-rw-r--r--org.eclipse.ui.examples.javaeditor/plugin.xml40
34 files changed, 2327 insertions, 0 deletions
diff --git a/org.eclipse.ui.examples.javaeditor/.cvsignore b/org.eclipse.ui.examples.javaeditor/.cvsignore
new file mode 100644
index 00000000000..3f041525eb9
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/.cvsignore
@@ -0,0 +1,2 @@
+bin
+.classpath
diff --git a/org.eclipse.ui.examples.javaeditor/.vcm_meta b/org.eclipse.ui.examples.javaeditor/.vcm_meta
new file mode 100644
index 00000000000..c51cef766bb
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/.vcm_meta
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project-description>
+ <comment></comment>
+ <nature id="org.eclipse.jdt.core.javanature"/>
+ <reference project-name="org.eclipse.ui"/>
+ <reference project-name="org.eclipse.core.runtime"/>
+ <reference project-name="org.eclipse.swt"/>
+ <reference project-name="org.eclipse.core.resources"/>
+ <builder name="org.eclipse.jdt.core.javabuilder">
+ </builder>
+</project-description>
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
new file mode 100644
index 00000000000..b01f739b8e0
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
@@ -0,0 +1,76 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ResourceBundle;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.IToolBarManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.texteditor.BasicTextEditorActionContributor;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.RetargetTextEditorAction;
+import org.eclipse.ui.texteditor.TextEditorAction;
+
+/**
+ * Contributes interesting Java actions to the desktop's Edit menu and
+ * the toolbar.
+ */
+public class JavaActionContributor extends BasicTextEditorActionContributor {
+
+ protected RetargetTextEditorAction fContentAssistProposal;
+ protected RetargetTextEditorAction fContentAssistTip;
+ protected TextEditorAction fTogglePresentation;
+
+ /**
+ * Default constructor.
+ */
+ public JavaActionContributor() {
+ super();
+
+ fContentAssistProposal= new RetargetTextEditorAction(JavaEditorMessages.getResourceBundle(), "ContentAssistProposal."); //$NON-NLS-1$
+ fContentAssistTip= new RetargetTextEditorAction(JavaEditorMessages.getResourceBundle(), "ContentAssistTip."); //$NON-NLS-1$
+ fTogglePresentation= new PresentationAction();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on EditorActionBarContributor
+ */
+ public void contributeToMenu(IMenuManager menuManager) {
+ IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
+ if (editMenu != null) {
+ editMenu.add(new Separator());
+ editMenu.add(fContentAssistProposal);
+ editMenu.add(fContentAssistTip);
+ }
+ }
+
+ /* (non-Javadoc)
+ * Method declared on EditorActionBarContributor
+ */
+ public void contributeToToolBar(IToolBarManager toolBarManager) {
+ toolBarManager.add(new Separator());
+ toolBarManager.add(fTogglePresentation);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on EditorActionBarContributor
+ */
+ public void setActiveEditor(IEditorPart part) {
+ super.setActiveEditor(part);
+
+ ITextEditor editor= null;
+ if (part instanceof ITextEditor)
+ editor= (ITextEditor) part;
+
+ fContentAssistProposal.setAction(getAction(editor, "ContentAssistProposal")); //$NON-NLS-1$
+ fContentAssistTip.setAction(getAction(editor, "ContentAssistTip")); //$NON-NLS-1$
+
+ fTogglePresentation.setEditor(editor);
+ fTogglePresentation.update();
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java
new file mode 100644
index 00000000000..676e4856b98
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaAnnotationHover.java
@@ -0,0 +1,34 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+
+/**
+ * The JavaAnnotationHover provides the hover support for java editors.
+ */
+
+public class JavaAnnotationHover implements IAnnotationHover {
+
+ /* (non-Javadoc)
+ * Method declared on IAnnotationHover
+ */
+ public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
+ IDocument document= sourceViewer.getDocument();
+
+ try {
+ IRegion info= document.getLineInformation(lineNumber);
+ return document.get(info.getOffset(), info.getLength());
+ } catch (BadLocationException x) {
+ }
+
+ return null;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java
new file mode 100644
index 00000000000..f4f2d466c66
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaContentOutlinePage.java
@@ -0,0 +1,244 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.BadPositionCategoryException;
+import org.eclipse.jface.text.DefaultPositionUpdater;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IPositionUpdater;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.LabelProvider;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.jface.viewers.Viewer;
+
+import org.eclipse.ui.texteditor.IDocumentProvider;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.views.contentoutline.ContentOutlinePage;
+
+/**
+ * A content outline page which always represents the content of the
+ * connected editor in 10 segments.
+ */
+public class JavaContentOutlinePage extends ContentOutlinePage {
+
+ /**
+ * A segment element.
+ */
+ protected static class Segment {
+ public String name;
+ public Position position;
+
+ public Segment(String name, Position position) {
+ this.name= name;
+ this.position= position;
+ }
+
+ public String toString() {
+ return name;
+ }
+ };
+
+ /**
+ * Divides the editor's document into ten segments and provides elements for them.
+ */
+ protected class ContentProvider implements ITreeContentProvider {
+
+ protected final static String SEGMENTS= "__java_segments"; //$NON-NLS-1$
+ protected IPositionUpdater fPositionUpdater= new DefaultPositionUpdater(SEGMENTS);
+ protected List fContent= new ArrayList(10);
+
+ protected void parse(IDocument document) {
+
+ int lines= document.getNumberOfLines();
+ int increment= Math.max(Math.round((float) (lines / 10)), 10);
+
+ for (int line= 0; line < lines; line += increment) {
+
+ int length= increment;
+ if (line + increment > lines)
+ length= lines - line;
+
+ try {
+
+ int offset= document.getLineOffset(line);
+ int end= document.getLineOffset(line + length);
+ length= end - offset;
+ Position p= new Position(offset, length);
+ document.addPosition(SEGMENTS, p);
+ fContent.add(new Segment(MessageFormat.format(JavaEditorMessages.getString("OutlinePage.segment.title_pattern"), new Object[] { new Integer(offset) }), p)); //$NON-NLS-1$
+
+ } catch (BadPositionCategoryException x) {
+ } catch (BadLocationException x) {
+ }
+ }
+ }
+
+ /*
+ * @see IContentProvider#inputChanged(Viewer, Object, Object)
+ */
+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
+ if (oldInput != null) {
+ IDocument document= fDocumentProvider.getDocument(oldInput);
+ if (document != null) {
+ try {
+ document.removePositionCategory(SEGMENTS);
+ } catch (BadPositionCategoryException x) {
+ }
+ document.removePositionUpdater(fPositionUpdater);
+ }
+ }
+
+ fContent.clear();
+
+ if (newInput != null) {
+ IDocument document= fDocumentProvider.getDocument(newInput);
+ if (document != null) {
+ document.addPositionCategory(SEGMENTS);
+ document.addPositionUpdater(fPositionUpdater);
+
+ parse(document);
+ }
+ }
+ }
+
+ /*
+ * @see IContentProvider#dispose
+ */
+ public void dispose() {
+ if (fContent != null) {
+ fContent.clear();
+ fContent= null;
+ }
+ }
+
+ /*
+ * @see IContentProvider#isDeleted(Object)
+ */
+ public boolean isDeleted(Object element) {
+ return false;
+ }
+
+ /*
+ * @see IStructuredContentProvider#getElements(Object)
+ */
+ public Object[] getElements(Object element) {
+ return fContent.toArray();
+ }
+
+ /*
+ * @see ITreeContentProvider#hasChildren(Object)
+ */
+ public boolean hasChildren(Object element) {
+ return element == fInput;
+ }
+
+ /*
+ * @see ITreeContentProvider#getParent(Object)
+ */
+ public Object getParent(Object element) {
+ if (element instanceof Segment)
+ return fInput;
+ return null;
+ }
+
+ /*
+ * @see ITreeContentProvider#getChildren(Object)
+ */
+ public Object[] getChildren(Object element) {
+ if (element == fInput)
+ return fContent.toArray();
+ return new Object[0];
+ }
+ };
+
+ protected Object fInput;
+ protected IDocumentProvider fDocumentProvider;
+ protected ITextEditor fTextEditor;
+
+ /**
+ * Creates a content outline page using the given provider and the given editor.
+ */
+ public JavaContentOutlinePage(IDocumentProvider provider, ITextEditor editor) {
+ super();
+ fDocumentProvider= provider;
+ fTextEditor= editor;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on ContentOutlinePage
+ */
+ public void createControl(Composite parent) {
+
+ super.createControl(parent);
+
+ TreeViewer viewer= getTreeViewer();
+ viewer.setContentProvider(new ContentProvider());
+ viewer.setLabelProvider(new LabelProvider());
+ viewer.addSelectionChangedListener(this);
+
+ if (fInput != null)
+ viewer.setInput(fInput);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on ContentOutlinePage
+ */
+ public void selectionChanged(SelectionChangedEvent event) {
+
+ super.selectionChanged(event);
+
+ ISelection selection= event.getSelection();
+ if (selection.isEmpty())
+ fTextEditor.resetHighlightRange();
+ else {
+ Segment segment= (Segment) ((IStructuredSelection) selection).getFirstElement();
+ int start= segment.position.getOffset();
+ int length= segment.position.getLength();
+ try {
+ fTextEditor.setHighlightRange(start, length, true);
+ } catch (IllegalArgumentException x) {
+ fTextEditor.resetHighlightRange();
+ }
+ }
+ }
+
+ /**
+ * Sets the input of the outline page
+ */
+ public void setInput(Object input) {
+ fInput= input;
+ update();
+ }
+
+ /**
+ * Updates the outline page.
+ */
+ public void update() {
+ TreeViewer viewer= getTreeViewer();
+
+ if (viewer != null) {
+ Control control= viewer.getControl();
+ if (control != null && !control.isDisposed()) {
+ control.setRedraw(false);
+ viewer.setInput(fInput);
+ viewer.expandAll();
+ control.setRedraw(true);
+ }
+ }
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
new file mode 100644
index 00000000000..f11dfd17065
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
@@ -0,0 +1,57 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.RuleBasedPartitioner;
+import org.eclipse.ui.editors.text.FileDocumentProvider;
+import org.eclipse.ui.examples.javaeditor.java.JavaPartitionScanner;
+
+/**
+ * The JavaDocumentProvider provides the IDocuments used by java editors.
+ */
+
+public class JavaDocumentProvider extends FileDocumentProvider {
+
+ private final static String[] TYPES= new String[] { JavaPartitionScanner.JAVA_DOC, JavaPartitionScanner.JAVA_MULTILINE_COMMENT };
+
+ private static JavaPartitionScanner fgScanner= null;
+
+ public JavaDocumentProvider() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on AbstractDocumentProvider
+ */
+ protected IDocument createDocument(Object element) throws CoreException {
+ IDocument document= super.createDocument(element);
+ if (document != null) {
+ IDocumentPartitioner partitioner= createJavaPartitioner();
+ partitioner.connect(document);
+ document.setDocumentPartitioner(partitioner);
+ }
+ return document;
+ }
+
+ /**
+ * Return a paritioner for .java files.
+ */
+ private RuleBasedPartitioner createJavaPartitioner() {
+ return new RuleBasedPartitioner(getJavaPartitionScanner(), TYPES);
+ }
+
+ /**
+ * Return a scanner for creating java partitions.
+ */
+ private JavaPartitionScanner getJavaPartitionScanner() {
+ if (fgScanner == null)
+ fgScanner= new JavaPartitionScanner();
+ return fgScanner;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
new file mode 100644
index 00000000000..af6f88eb2ee
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
@@ -0,0 +1,134 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ResourceBundle;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.DefaultRangeIndicator;
+import org.eclipse.ui.texteditor.TextOperationAction;
+import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
+
+/**
+ * Java specific text editor.
+ */
+public class JavaEditor extends TextEditor {
+
+ /** The outline page */
+ private JavaContentOutlinePage fOutlinePage;
+
+ /**
+ * Default constructor.
+ */
+ public JavaEditor() {
+ super();
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method extend the
+ * actions to add those specific to the receiver
+ */
+ protected void createActions() {
+ super.createActions();
+ setAction("ContentAssistProposal", new TextOperationAction(JavaEditorMessages.getResourceBundle(), "ContentAssistProposal.", this, ISourceViewer.CONTENTASSIST_PROPOSALS)); //$NON-NLS-1$ //$NON-NLS-2$
+ setAction("ContentAssistTip", new TextOperationAction(JavaEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs any extra
+ * disposal actions required by the java editor.
+ */
+ public void dispose() {
+ JavaEditorEnvironment.disconnect(this);
+ if (fOutlinePage != null)
+ fOutlinePage.setInput(null);
+ super.dispose();
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs any extra
+ * revert behavior required by the java editor.
+ */
+ public void doRevertToSaved() {
+ super.doRevertToSaved();
+ if (fOutlinePage != null)
+ fOutlinePage.update();
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs any extra
+ * save behavior required by the java editor.
+ */
+ public void doSave(IProgressMonitor monitor) {
+ super.doSave(monitor);
+ if (fOutlinePage != null)
+ fOutlinePage.update();
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs any extra
+ * save as behavior required by the java editor.
+ */
+ public void doSaveAs() {
+ super.doSaveAs();
+ if (fOutlinePage != null)
+ fOutlinePage.update();
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs sets the
+ * input of the outline page after AbstractTextEditor has set input.
+ */
+ public void doSetInput(IEditorInput input) throws CoreException {
+ super.doSetInput(input);
+ if (fOutlinePage != null)
+ fOutlinePage.setInput(input);
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method adds any
+ * JavaEditor specific entries.
+ */
+ public void editorContextMenuAboutToShow(MenuManager menu) {
+ super.editorContextMenuAboutToShow(menu);
+ addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
+ addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
+ }
+
+ /** The <code>JavaEditor</code> implementation of this
+ * <code>AbstractTextEditor</code> method performs gets
+ * the java content outline page if request is for a an
+ * outline page.
+ */
+ public Object getAdapter(Class required) {
+ if (IContentOutlinePage.class.equals(required)) {
+ if (fOutlinePage == null) {
+ fOutlinePage= new JavaContentOutlinePage(getDocumentProvider(), this);
+ if (getEditorInput() != null)
+ fOutlinePage.setInput(getEditorInput());
+ }
+ return fOutlinePage;
+ }
+ return super.getAdapter(required);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on AbstractTextEditor
+ */
+ protected void initializeEditor() {
+
+ JavaEditorEnvironment.connect(this);
+
+ setSourceViewerConfiguration(new JavaSourceViewerConfiguration());
+ setRangeIndicator(new DefaultRangeIndicator());
+ setEditorContextMenuId("#JavaEditorContext"); //$NON-NLS-1$
+ setRulerContextMenuId("#JavaRulerContext"); //$NON-NLS-1$
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java
new file mode 100644
index 00000000000..5849127c54b
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorEnvironment.java
@@ -0,0 +1,67 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.ui.examples.javaeditor.java.JavaCodeScanner;
+import org.eclipse.ui.examples.javaeditor.javadoc.JavaDocScanner;
+import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
+
+/** The JavaEditorEnvironment maintains singletons used by the java editor
+ * examples.
+ */
+public class JavaEditorEnvironment {
+
+ private static JavaColorProvider fgColorProvider;
+ private static JavaCodeScanner fgCodeScanner;
+ private static JavaDocScanner fgDocScanner;
+
+ private static int fgRefCount= 0;
+
+ /**
+ * A connection has occured - initialize the receiver if it is the first activation.
+ */
+ public static void connect(Object client) {
+ if (++fgRefCount == 1) {
+ fgColorProvider= new JavaColorProvider();
+ fgCodeScanner= new JavaCodeScanner(fgColorProvider);
+ fgDocScanner= new JavaDocScanner(fgColorProvider);
+ }
+ }
+
+ /**
+ * A disconnection has occured - clear the receiver if it is the last deactivation.
+ */
+ public static void disconnect(Object client) {
+ if (--fgRefCount == 0) {
+ fgCodeScanner= null;
+ fgDocScanner= null;
+ fgColorProvider.dispose();
+ fgColorProvider= null;
+ }
+ }
+
+ /**
+ * Returns the singleton scanner.
+ */
+ public static RuleBasedScanner getJavaCodeScanner() {
+ return fgCodeScanner;
+ }
+
+ /**
+ * Returns the singleton color provider.
+ */
+ public static JavaColorProvider getJavaColorProvider() {
+ return fgColorProvider;
+ }
+
+ /**
+ * Returns the singleton document scanner.
+ */
+ public static RuleBasedScanner getJavaDocScanner() {
+ return fgDocScanner;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java
new file mode 100644
index 00000000000..ff30b90639f
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.java
@@ -0,0 +1,30 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.ui.examples.javaeditor;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class JavaEditorMessages {
+
+ private static final String RESOURCE_BUNDLE= "org.eclipse.ui.examples.javaeditor.JavaEditorMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private JavaEditorMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ }
+
+ public static ResourceBundle getResourceBundle() {
+ return fgResourceBundle;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
new file mode 100644
index 00000000000..89a655da834
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
@@ -0,0 +1,33 @@
+#############################################################
+#
+# (c) Copyright IBM Corp. 2000, 2001.
+# All Rights Reserved.
+#
+#############################################################
+
+## Actions ##
+
+ContentAssistProposal.label=Content Assist@Ctrl+SPACE
+ContentAssistProposal.tooltip=Content Assist
+ContentAssistProposal.image=
+ContentAssistProposal.description=Content Assist
+
+ContentAssistTip.label=Content Tip@Ctrl+SHIFT+SPACE
+ContentAssistTip.tooltip=Content Tip
+ContentAssistTip.image=
+ContentAssistTip.description=Content Tip
+
+TogglePresentation.label=Change Presentation
+TogglePresentation.tooltip=Enable/Disable Segmented Source Viewer
+TogglePresentation.image=togglepresentation.gif
+TogglePresentation.description=Enable/Disable Segmented Source Viewer
+
+OutlinePage.segment.title_pattern=position {0}
+
+AutoIndent.error.bad_location_1=JavaAutoIndentStrategy.getAutoIndentString: BadLocationException
+AutoIndent.error.bad_location_2=JavaAutoIndentStrategy.calcShiftBackReplace: BadLocationException
+
+CompletionProcessor.ContextInfo.display.pattern=proposal {0} at position {1}
+CompletionProcessor.ContextInfo.value.pattern=proposal {0} valid from {1} to {2}
+CompletionProcessor.Proposal.ContextInfo.pattern={0} valid 5 characters around insertion point
+CompletionProcessor.Proposal.hoverinfo.pattern=Java keyword: {0}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
new file mode 100644
index 00000000000..b911cd41192
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
@@ -0,0 +1,137 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.IAutoIndentStrategy;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.contentassist.ContentAssistant;
+import org.eclipse.jface.text.contentassist.IContentAssistant;
+import org.eclipse.jface.text.presentation.IPresentationReconciler;
+import org.eclipse.jface.text.presentation.PresentationReconciler;
+import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer;
+import org.eclipse.jface.text.source.IAnnotationHover;
+import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.SourceViewerConfiguration;
+import org.eclipse.ui.examples.javaeditor.java.JavaAutoIndentStrategy;
+import org.eclipse.ui.examples.javaeditor.java.JavaCompletionProcessor;
+import org.eclipse.ui.examples.javaeditor.java.JavaDoubleClickSelector;
+import org.eclipse.ui.examples.javaeditor.java.JavaPartitionScanner;
+import org.eclipse.ui.examples.javaeditor.javadoc.JavaDocCompletionProcessor;
+import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
+
+/**
+ * Example configuration for an <code>SourceViewer</code> which shows Java code.
+ */
+public class JavaSourceViewerConfiguration extends SourceViewerConfiguration {
+
+ /**
+ * Default constructor.
+ */
+ public JavaSourceViewerConfiguration() {
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
+ return new JavaAnnotationHover();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
+ return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? new JavaAutoIndentStrategy() : new DefaultAutoIndentStrategy());
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
+ return new String[] { IDocument.DEFAULT_CONTENT_TYPE, JavaPartitionScanner.JAVA_DOC, JavaPartitionScanner.JAVA_MULTILINE_COMMENT };
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
+
+ ContentAssistant assistant= new ContentAssistant();
+ assistant.setContentAssistProcessor(new JavaCompletionProcessor(), IDocument.DEFAULT_CONTENT_TYPE);
+ assistant.setContentAssistProcessor(new JavaDocCompletionProcessor(), JavaPartitionScanner.JAVA_DOC);
+
+ assistant.enableAutoActivation(true);
+ assistant.setAutoActivationDelay(500);
+ assistant.setProposalPopupOrientation(assistant.PROPOSAL_OVERLAY);
+ assistant.setContextInformationPopupOrientation(assistant.CONTEXT_INFO_ABOVE);
+ assistant.setContextInformationPopupBackground(JavaEditorEnvironment.getJavaColorProvider().getColor(new RGB(150, 150, 0)));
+
+ return assistant;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) {
+ return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
+ return new JavaDoubleClickSelector();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
+ return new String[] { "\t", " " }; //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
+
+ JavaColorProvider provider= JavaEditorEnvironment.getJavaColorProvider();
+ PresentationReconciler reconciler= new PresentationReconciler();
+
+ RuleBasedDamagerRepairer dr= new RuleBasedDamagerRepairer(JavaEditorEnvironment.getJavaCodeScanner(), new TextAttribute(provider.getColor(provider.DEFAULT)));
+ reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
+ reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
+
+ dr= new RuleBasedDamagerRepairer(JavaEditorEnvironment.getJavaDocScanner(), new TextAttribute(provider.getColor(provider.JAVADOC_DEFAULT)));
+ reconciler.setDamager(dr, JavaPartitionScanner.JAVA_DOC);
+ reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_DOC);
+
+ dr= new RuleBasedDamagerRepairer(null, new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT)));
+ reconciler.setDamager(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
+ reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
+
+ return reconciler;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public int getTabWidth(ISourceViewer sourceViewer) {
+ return 4;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on SourceViewerConfiguration
+ */
+ public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
+ return new JavaTextHover();
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
new file mode 100644
index 00000000000..3c1f3a867f3
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
@@ -0,0 +1,42 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IRegion;
+import org.eclipse.jface.text.ITextHover;
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.Region;
+
+/**
+ * Example implementation for an <code>ITextHover</code> which hovers over Java code.
+ */
+public class JavaTextHover implements ITextHover {
+
+ /* (non-Javadoc)
+ * Method declared on ITextHover
+ */
+ public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
+ if (hoverRegion != null) {
+ try {
+ return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
+ } catch (BadLocationException x) {
+ }
+ }
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on ITextHover
+ */
+ public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
+ Point selection= textViewer.getSelectedRange();
+ if (selection.y > 0 && selection.x <= offset && offset <= selection.x + selection.y)
+ return new Region(selection.x, selection.y);
+ return null;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java
new file mode 100644
index 00000000000..625fbd2919e
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/PresentationAction.java
@@ -0,0 +1,47 @@
+package org.eclipse.ui.examples.javaeditor;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ResourceBundle;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.eclipse.ui.texteditor.TextEditorAction;
+
+/**
+ * A toolbar action which toggles the presentation model of the
+ * connected text editor. The editor shows either the highlight range
+ * only or always the whole document.
+ */
+public class PresentationAction extends TextEditorAction {
+
+ /**
+ * Constructs and updates the action.
+ */
+ public PresentationAction() {
+ super(JavaEditorMessages.getResourceBundle(), "TogglePresentation.", null); //$NON-NLS-1$
+ update();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IAction
+ */
+ public void run() {
+
+ ITextEditor editor= getTextEditor();
+
+ editor.resetHighlightRange();
+ boolean show= editor.showsHighlightRangeOnly();
+ setChecked(!show);
+ editor.showHighlightRangeOnly(!show);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on TextEditorAction
+ */
+ public void update() {
+ setChecked(getTextEditor() != null && getTextEditor().showsHighlightRangeOnly());
+ setEnabled(true);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java
new file mode 100644
index 00000000000..d47ab8b2c29
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaAutoIndentStrategy.java
@@ -0,0 +1,265 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.DefaultAutoIndentStrategy;
+import org.eclipse.jface.text.DocumentCommand;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * Auto indent strategy sensitive to brackets.
+ */
+public class JavaAutoIndentStrategy extends DefaultAutoIndentStrategy {
+
+ public JavaAutoIndentStrategy() {
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IAutoIndentStrategy
+ */
+ public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
+ if (c.length == 0 && c.text != null && endsWithDelimiter(d, c.text))
+ smartIndentAfterNewLine(d, c);
+ else if ("}".equals(c.text)) { //$NON-NLS-1$
+ smartInsertAfterBracket(d, c);
+ }
+ }
+
+ /**
+ * Returns whether or not the text ends with one of the given search strings.
+ */
+ private boolean endsWithDelimiter(IDocument d, String txt) {
+
+ String[] delimiters= d.getLegalLineDelimiters();
+
+ for (int i= 0; i < delimiters.length; i++) {
+ if (txt.endsWith(delimiters[i]))
+ return true;
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the line number of the next bracket after end.
+ * @returns the line number of the next matching bracket after end
+ * @param document - the document being parsed
+ * @param line - the line to start searching back from
+ * @param end - the end position to search back from
+ * @param closingBracketIncrease - the number of brackets to skip
+ */
+ protected int findMatchingOpenBracket(IDocument document, int line, int end, int closingBracketIncrease) throws BadLocationException {
+
+ int start= document.getLineOffset(line);
+ int brackcount= getBracketCount(document, start, end, false) - closingBracketIncrease;
+
+ // sum up the brackets counts of each line (closing brackets count negative,
+ // opening positive) until we find a line the brings the count to zero
+ while (brackcount < 0) {
+ line--;
+ if (line < 0) {
+ return -1;
+ }
+ start= document.getLineOffset(line);
+ end= start + document.getLineLength(line) - 1;
+ brackcount += getBracketCount(document, start, end, false);
+ }
+ return line;
+ }
+
+ /**
+ * Returns the bracket value of a section of text. Closing brackets have a value of -1 and
+ * open brackets have a value of 1.
+ * @returns the line number of the next matching bracket after end
+ * @param document - the document being parsed
+ * @param start - the start position for the search
+ * @param end - the end position for the search
+ * @param ignoreCloseBrackets - whether or not to ignore closing brackets in the count
+ */
+ private int getBracketCount(IDocument document, int start, int end, boolean ignoreCloseBrackets) throws BadLocationException {
+
+ int begin = start;
+ int bracketcount= 0;
+ while (begin < end) {
+ char curr= document.getChar(begin);
+ begin++;
+ switch (curr) {
+ case '/' :
+ if (begin < end) {
+ char next= document.getChar(begin);
+ if (next == '*') {
+ // a comment starts, advance to the comment end
+ begin= getCommentEnd(document, begin + 1, end);
+ } else if (next == '/') {
+ // '//'-comment: nothing to do anymore on this line
+ begin= end;
+ }
+ }
+ break;
+ case '*' :
+ if (begin < end) {
+ char next= document.getChar(begin);
+ if (next == '/') {
+ // we have been in a comment: forget what we read before
+ bracketcount= 0;
+ begin++;
+ }
+ }
+ break;
+ case '{' :
+ bracketcount++;
+ ignoreCloseBrackets= false;
+ break;
+ case '}' :
+ if (!ignoreCloseBrackets) {
+ bracketcount--;
+ }
+ break;
+ case '"' :
+ case '\'' :
+ begin= getStringEnd(document, begin, end, curr);
+ break;
+ default :
+ }
+ }
+ return bracketcount;
+ }
+
+ /**
+ * Returns the end position a comment starting at pos.
+ * @returns the end position a comment starting at pos
+ * @param document - the document being parsed
+ * @param position - the start position for the search
+ * @param end - the end position for the search
+ */
+ private int getCommentEnd(IDocument document, int position, int end) throws BadLocationException {
+ int currentPosition = position;
+ while (currentPosition < end) {
+ char curr= document.getChar(currentPosition);
+ currentPosition++;
+ if (curr == '*') {
+ if (currentPosition < end && document.getChar(currentPosition) == '/') {
+ return currentPosition + 1;
+ }
+ }
+ }
+ return end;
+ }
+
+ /**
+ * Returns the String at line with the leading whitespace removed.
+ * @returns the String at line with the leading whitespace removed.
+ * @param document - the document being parsed
+ * @param line - the line being searched
+ */
+ protected String getIndentOfLine(IDocument document, int line) throws BadLocationException {
+ if (line > -1) {
+ int start= document.getLineOffset(line);
+ int end= start + document.getLineLength(line) - 1;
+ int whiteend= findEndOfWhiteSpace(document, start, end);
+ return document.get(start, whiteend - start);
+ } else {
+ return ""; //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Returns the position of the character in the document after position.
+ * @returns the next location of character.
+ * @param document - the document being parsed
+ * @param position - the position to start searching from
+ * @param end - the end of the document
+ * @param character - the character you are trying to match
+ */
+ private int getStringEnd(IDocument document, int position, int end, char character) throws BadLocationException {
+ int currentPosition = position;
+ while (currentPosition < end) {
+ char currentCharacter= document.getChar(currentPosition);
+ currentPosition++;
+ if (currentCharacter == '\\') {
+ // ignore escaped characters
+ currentPosition++;
+ } else if (currentCharacter == character) {
+ return currentPosition;
+ }
+ }
+ return end;
+ }
+
+ /**
+ * Set the indent of a new line based on the command provided in the supplied document.
+ * @param document - the document being parsed
+ * @param command - the command being performed
+ */
+ protected void smartIndentAfterNewLine(IDocument document, DocumentCommand command) {
+
+ int docLength= document.getLength();
+ if (command.offset == -1 || docLength == 0)
+ return;
+
+ try {
+ int p= (command.offset == docLength ? command.offset - 1 : command.offset);
+ int line= document.getLineOfOffset(p);
+
+ StringBuffer buf= new StringBuffer(command.text);
+ if (command.offset < docLength && document.getChar(command.offset) == '}') {
+ int indLine= findMatchingOpenBracket(document, line, command.offset, 0);
+ if (indLine == -1) {
+ indLine= line;
+ }
+ buf.append(getIndentOfLine(document, indLine));
+ } else {
+ int start= document.getLineOffset(line);
+ int whiteend= findEndOfWhiteSpace(document, start, command.offset);
+ buf.append(document.get(start, whiteend - start));
+ if (getBracketCount(document, start, command.offset, true) > 0) {
+ buf.append('\t');
+ }
+ }
+ command.text= buf.toString();
+
+ } catch (BadLocationException excp) {
+ System.out.println(JavaEditorMessages.getString("AutoIndent.error.bad_location_1")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Set the indent of a bracket based on the command provided in the supplied document.
+ * @param document - the document being parsed
+ * @param command - the command being performed
+ */
+ protected void smartInsertAfterBracket(IDocument document, DocumentCommand command) {
+ if (command.offset == -1 || document.getLength() == 0)
+ return;
+
+ try {
+ int p= (command.offset == document.getLength() ? command.offset - 1 : command.offset);
+ int line= document.getLineOfOffset(p);
+ int start= document.getLineOffset(line);
+ int whiteend= findEndOfWhiteSpace(document, start, command.offset);
+
+ // shift only when line does not contain any text up to the closing bracket
+ if (whiteend == command.offset) {
+ // evaluate the line with the opening bracket that matches out closing bracket
+ int indLine= findMatchingOpenBracket(document, line, command.offset, 1);
+ if (indLine != -1 && indLine != line) {
+ // take the indent of the found line
+ StringBuffer replaceText= new StringBuffer(getIndentOfLine(document, indLine));
+ // add the rest of the current line including the just added close bracket
+ replaceText.append(document.get(whiteend, command.offset - whiteend));
+ replaceText.append(command.text);
+ // modify document command
+ command.length= command.offset - start;
+ command.offset= start;
+ command.text= replaceText.toString();
+ }
+ }
+ } catch (BadLocationException excp) {
+ System.out.println(JavaEditorMessages.getString("AutoIndent.error.bad_location_2")); //$NON-NLS-1$
+ }
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java
new file mode 100644
index 00000000000..fe88175eb2f
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCodeScanner.java
@@ -0,0 +1,77 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
+import org.eclipse.ui.examples.javaeditor.util.JavaWhitespaceDetector;
+import org.eclipse.ui.examples.javaeditor.util.JavaWordDetector;
+
+/**
+ * A Java code scanner.
+ */
+public class JavaCodeScanner extends RuleBasedScanner {
+
+ private static String[] fgKeywords= { "abstract", "break", "case", "catch", "class", "continue", "default", "do", "else", "extends", "final", "finally", "for", "if", "implements", "import", "instanceof", "interface", "native", "new", "package", "private", "protected", "public", "return", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "try", "volatile", "while" }; //$NON-NLS-36$ //$NON-NLS-35$ //$NON-NLS-34$ //$NON-NLS-33$ //$NON-NLS-32$ //$NON-NLS-31$ //$NON-NLS-30$ //$NON-NLS-29$ //$NON-NLS-28$ //$NON-NLS-27$ //$NON-NLS-26$ //$NON-NLS-25$ //$NON-NLS-24$ //$NON-NLS-23$ //$NON-NLS-22$ //$NON-NLS-21$ //$NON-NLS-20$ //$NON-NLS-19$ //$NON-NLS-18$ //$NON-NLS-17$ //$NON-NLS-16$ //$NON-NLS-15$ //$NON-NLS-14$ //$NON-NLS-13$ //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+ private static String[] fgTypes= { "void", "boolean", "char", "byte", "short", "int", "long", "float", "double" }; //$NON-NLS-1$ //$NON-NLS-5$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-8$ //$NON-NLS-9$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-2$
+
+ private static String[] fgConstants= { "false", "null", "true" }; //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+ private TextAttribute fComment;
+ private TextAttribute fKeyword;
+ private TextAttribute fType;
+ private TextAttribute fString;
+ private JavaColorProvider fColorProvider;
+
+ /**
+ * Creates a Java code scanner
+ */
+ public JavaCodeScanner(JavaColorProvider provider) {
+
+ IToken keyword= new Token(new TextAttribute(provider.getColor(JavaColorProvider.KEYWORD)));
+ IToken type= new Token(new TextAttribute(provider.getColor(JavaColorProvider.TYPE)));
+ IToken string= new Token(new TextAttribute(provider.getColor(JavaColorProvider.STRING)));
+ IToken comment= new Token(new TextAttribute(provider.getColor(JavaColorProvider.SINGLE_LINE_COMMENT)));
+ IToken other= new Token(new TextAttribute(provider.getColor(JavaColorProvider.DEFAULT)));
+
+ List rules= new ArrayList();
+
+ // Add rule for single line comments.
+ rules.add(new EndOfLineRule("//", comment)); //$NON-NLS-1$
+
+ // Add rule for strings and character constants.
+ rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+ rules.add(new SingleLineRule("'", "'", string, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+
+ // Add generic whitespace rule.
+ rules.add(new WhitespaceRule(new JavaWhitespaceDetector()));
+
+ // Add word rule for keywords, types, and constants.
+ WordRule wordRule= new WordRule(new JavaWordDetector(), other);
+ for (int i= 0; i < fgKeywords.length; i++)
+ wordRule.addWord(fgKeywords[i], keyword);
+ for (int i= 0; i < fgTypes.length; i++)
+ wordRule.addWord(fgTypes[i], type);
+ for (int i= 0; i < fgConstants.length; i++)
+ wordRule.addWord(fgConstants[i], type);
+ rules.add(wordRule);
+
+ IRule[] result= new IRule[rules.size()];
+ rules.toArray(result);
+ setRules(result);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
new file mode 100644
index 00000000000..9efa3acc004
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
@@ -0,0 +1,102 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.text.MessageFormat;
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ContextInformation;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+/**
+ * Example Java completion processor.
+ */
+public class JavaCompletionProcessor implements IContentAssistProcessor {
+
+ /**
+ * Simple content assist tip closer. The tip is valid in a range
+ * of 5 characters around its popup location.
+ */
+ protected static class Validator implements IContextInformationValidator {
+
+ protected int fInstallOffset;
+
+ /*
+ * @see IContextInformationValidator#isContextInformationValid(int)
+ */
+ public boolean isContextInformationValid(int offset) {
+ return Math.abs(fInstallOffset - offset) < 5;
+ }
+
+ /*
+ * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
+ */
+ public void install(IContextInformation info, ITextViewer viewer, int offset) {
+ fInstallOffset= offset;
+ }
+ };
+
+ protected final static String[] fgProposals=
+ { "abstract", "boolean", "break", "byte", "case", "catch", "char", "class", "continue", "default", "do", "double", "else", "extends", "false", "final", "finally", "float", "for", "if", "implements", "import", "instanceof", "int", "interface", "long", "native", "new", "null", "package", "private", "protected", "public", "return", "short", "static", "super", "switch", "synchronized", "this", "throw", "throws", "transient", "true", "try", "void", "volatile", "while" }; //$NON-NLS-48$ //$NON-NLS-47$ //$NON-NLS-46$ //$NON-NLS-45$ //$NON-NLS-44$ //$NON-NLS-43$ //$NON-NLS-42$ //$NON-NLS-41$ //$NON-NLS-40$ //$NON-NLS-39$ //$NON-NLS-38$ //$NON-NLS-37$ //$NON-NLS-36$ //$NON-NLS-35$ //$NON-NLS-34$ //$NON-NLS-33$ //$NON-NLS-32$ //$NON-NLS-31$ //$NON-NLS-30$ //$NON-NLS-29$ //$NON-NLS-28$ //$NON-NLS-27$ //$NON-NLS-26$ //$NON-NLS-25$ //$NON-NLS-24$ //$NON-NLS-23$ //$NON-NLS-22$ //$NON-NLS-21$ //$NON-NLS-20$ //$NON-NLS-19$ //$NON-NLS-18$ //$NON-NLS-17$ //$NON-NLS-16$ //$NON-NLS-15$ //$NON-NLS-14$ //$NON-NLS-13$ //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-7$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+ protected IContextInformationValidator fValidator= new Validator();
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
+ ICompletionProposal[] result= new ICompletionProposal[fgProposals.length];
+ for (int i= 0; i < fgProposals.length; i++) {
+ IContextInformation info= new ContextInformation(fgProposals[i], MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.ContextInfo.pattern"), new Object[] { fgProposals[i] })); //$NON-NLS-1$
+ result[i]= new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length(), null, fgProposals[i], info, MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.Proposal.hoverinfo.pattern"), new Object[] { fgProposals[i]})); //$NON-NLS-1$
+ }
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
+ IContextInformation[] result= new IContextInformation[5];
+ for (int i= 0; i < result.length; i++)
+ result[i]= new ContextInformation(
+ MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.display.pattern"), new Object[] { new Integer(i), new Integer(documentOffset) }), //$NON-NLS-1$
+ MessageFormat.format(JavaEditorMessages.getString("CompletionProcessor.ContextInfo.value.pattern"), new Object[] { new Integer(i), new Integer(documentOffset - 5), new Integer(documentOffset + 5)})); //$NON-NLS-1$
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return new char[] { '.', '(' };
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public char[] getContextInformationAutoActivationCharacters() {
+ return new char[] { '#' };
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public IContextInformationValidator getContextInformationValidator() {
+ return fValidator;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public String getErrorMessage() {
+ return null;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java
new file mode 100644
index 00000000000..be1ea743b21
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaDoubleClickSelector.java
@@ -0,0 +1,234 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextViewer;
+
+/**
+ * Double click strategy aware of Java identifier syntax rules.
+ */
+public class JavaDoubleClickSelector implements ITextDoubleClickStrategy {
+
+ protected ITextViewer fText;
+ protected int fPos;
+ protected int fStartPos;
+ protected int fEndPos;
+
+ protected static char[] fgBrackets= { '{', '}', '(', ')', '[', ']', '"', '"' };
+
+ /*
+ * Create a JavaDoubleClickSelector.
+ */
+ public JavaDoubleClickSelector() {
+ super();
+ }
+
+ /* (non-Javadoc)
+ * Method declared on ITextDoubleClickStrategy
+ */
+ public void doubleClicked(ITextViewer text) {
+
+ fPos= text.getSelectedRange().x;
+
+ if (fPos < 0)
+ return;
+
+ fText= text;
+
+ if (!selectBracketBlock())
+ selectWord();
+ }
+
+ /**
+ * Match the brackets at the current selection. Return true if successful,
+ * false otherwise.
+ */
+ protected boolean matchBracketsAt() {
+
+ char prevChar, nextChar;
+
+ int i;
+ int bracketIndex1= fgBrackets.length;
+ int bracketIndex2= fgBrackets.length;
+
+ fStartPos= -1;
+ fEndPos= -1;
+
+ // get the chars preceding and following the start position
+ try {
+
+ IDocument doc= fText.getDocument();
+
+ prevChar= doc.getChar(fPos - 1);
+ nextChar= doc.getChar(fPos);
+
+ // is the char either an open or close bracket?
+ for (i= 0; i < fgBrackets.length; i= i + 2) {
+ if (prevChar == fgBrackets[i]) {
+ fStartPos= fPos - 1;
+ bracketIndex1= i;
+ }
+ }
+ for (i= 1; i < fgBrackets.length; i= i + 2) {
+ if (nextChar == fgBrackets[i]) {
+ fEndPos= fPos;
+ bracketIndex2= i;
+ }
+ }
+
+ if (fStartPos > -1 && bracketIndex1 < bracketIndex2) {
+ fEndPos= searchForClosingBracket(fStartPos, prevChar, fgBrackets[bracketIndex1 + 1], doc);
+ if (fEndPos > -1)
+ return true;
+ else
+ fStartPos= -1;
+ } else if (fEndPos > -1) {
+ fStartPos= searchForOpenBracket(fEndPos, fgBrackets[bracketIndex2 - 1], nextChar, doc);
+ if (fStartPos > -1)
+ return true;
+ else
+ fEndPos= -1;
+ }
+
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+ /**
+ * Select the word at the current selection. Return true if successful,
+ * false otherwise.
+ */
+ protected boolean matchWord() {
+
+ IDocument doc= fText.getDocument();
+
+ try {
+
+ int pos= fPos;
+ char c;
+
+ while (pos >= 0) {
+ c= doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ --pos;
+ }
+
+ fStartPos= pos;
+
+ pos= fPos;
+ int length= doc.getLength();
+
+ while (pos < length) {
+ c= doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ ++pos;
+ }
+
+ fEndPos= pos;
+
+ return true;
+
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+ /**
+ * Returns the position of the closing bracket after startPosition.
+ * @returns the location of the closing bracket.
+ * @param startPosition - the beginning position
+ * @param openBracket - the character that represents the open bracket
+ * @param closeBracket - the character that represents the close bracket
+ * @param document - the document being searched
+ */
+ protected int searchForClosingBracket(int startPosition, char openBracket, char closeBracket, IDocument document) throws BadLocationException {
+ int stack= 1;
+ int closePosition= startPosition + 1;
+ int length= document.getLength();
+ char nextChar;
+
+ while (closePosition < length && stack > 0) {
+ nextChar= document.getChar(closePosition);
+ if (nextChar == openBracket && nextChar != closeBracket)
+ stack++;
+ else if (nextChar == closeBracket)
+ stack--;
+ closePosition++;
+ }
+
+ if (stack == 0)
+ return closePosition - 1;
+ else
+ return -1;
+
+ }
+
+ /**
+ * Returns the position of the open bracket before startPosition.
+ * @returns the location of the starting bracket.
+ * @param startPosition - the beginning position
+ * @param openBracket - the character that represents the open bracket
+ * @param closeBracket - the character that represents the close bracket
+ * @param document - the document being searched
+ */
+ protected int searchForOpenBracket(int startPosition, char openBracket, char closeBracket, IDocument document) throws BadLocationException {
+ int stack= 1;
+ int openPos= startPosition - 1;
+ char nextChar;
+
+ while (openPos >= 0 && stack > 0) {
+ nextChar= document.getChar(openPos);
+ if (nextChar == closeBracket && nextChar != openBracket)
+ stack++;
+ else if (nextChar == openBracket)
+ stack--;
+ openPos--;
+ }
+
+ if (stack == 0)
+ return openPos + 1;
+ else
+ return -1;
+ }
+
+ /**
+ * Select the area between the selected bracket and the closing bracket. Return
+ * true if successful.
+ */
+ protected boolean selectBracketBlock() {
+ if (matchBracketsAt()) {
+
+ if (fStartPos == fEndPos)
+ fText.setSelectedRange(fStartPos, 0);
+ else
+ fText.setSelectedRange(fStartPos + 1, fEndPos - fStartPos - 1);
+
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Select the word at the current selection.
+ */
+ protected void selectWord() {
+ if (matchWord()) {
+
+ if (fStartPos == fEndPos)
+ fText.setSelectedRange(fStartPos, 0);
+ else
+ fText.setSelectedRange(fStartPos + 1, fEndPos - fStartPos - 1);
+ }
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java
new file mode 100644
index 00000000000..85984c6e937
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaEditorMessages.java
@@ -0,0 +1,26 @@
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+package org.eclipse.ui.examples.javaeditor.java;
+
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+public class JavaEditorMessages {
+
+ private static final String RESOURCE_BUNDLE= "org.eclipse.ui.examples.javaeditor.JavaEditorMessages";//$NON-NLS-1$
+
+ private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
+
+ private JavaEditorMessages() {
+ }
+
+ public static String getString(String key) {
+ try {
+ return fgResourceBundle.getString(key);
+ } catch (MissingResourceException e) {
+ return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
+ }
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
new file mode 100644
index 00000000000..e817770a938
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
@@ -0,0 +1,81 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.MultiLineRule;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WordRule;
+
+/**
+ * This scanner recognizes the JavaDoc comments and Java multi line comments.
+ */
+public class JavaPartitionScanner extends RuleBasedScanner {
+
+ private final static String SKIP= "__skip"; //$NON-NLS-1$
+
+ public final static String JAVA_MULTILINE_COMMENT= "__java_multiline_comment"; //$NON-NLS-1$
+ public final static String JAVA_DOC= "__java_javadoc"; //$NON-NLS-1$
+
+ /**
+ * Detector for empty comments.
+ */
+ static class EmptyCommentDetector implements IWordDetector {
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector
+ */
+ public boolean isWordStart(char c) {
+ return (c == '/');
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector
+ */
+ public boolean isWordPart(char c) {
+ return (c == '*' || c == '/');
+ }
+ };
+
+ /**
+ * Creates the partitioner and sets up the appropriate rules.
+ */
+ public JavaPartitionScanner() {
+ super();
+
+ IToken javaDoc= new Token(JAVA_DOC);
+ IToken comment= new Token(JAVA_MULTILINE_COMMENT);
+
+ List rules= new ArrayList();
+
+ // Add rule for single line comments.
+ rules.add(new EndOfLineRule("//", Token.UNDEFINED)); //$NON-NLS-1$
+
+ // Add rule for strings and character constants.
+ rules.add(new SingleLineRule("\"", "\"", Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+ rules.add(new SingleLineRule("'", "'", Token.UNDEFINED, '\\')); //$NON-NLS-2$ //$NON-NLS-1$
+
+ // Add special case word rule.
+ WordRule wordRule= new WordRule(new EmptyCommentDetector());
+ wordRule.addWord("/**/", comment); //$NON-NLS-1$
+ rules.add(wordRule);
+
+ // Add rules for multi-line comments and javadoc.
+ rules.add(new MultiLineRule("/**", "*/", javaDoc)); //$NON-NLS-1$ //$NON-NLS-2$
+ rules.add(new MultiLineRule("/*", "*/", comment)); //$NON-NLS-1$ //$NON-NLS-2$
+
+ IRule[] result= new IRule[rules.size()];
+ rules.toArray(result);
+ setRules(result);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaWordDetector.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaWordDetector.java
new file mode 100644
index 00000000000..6aaf2850895
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaWordDetector.java
@@ -0,0 +1,63 @@
+package org.eclipse.ui.examples.javaeditor.java;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+
+/**
+ * Detects Java words in documents.
+ */
+public class JavaWordDetector {
+
+ /**
+ * Find the location of the word at offset in document.
+ * @returns Point - x is the start position, y is the end position.
+ * Return null if it is not found.
+ * @param document the document being searched.
+ * @param offset - the position to start searching from.
+ */
+ public static Point findWord(IDocument document, int offset) {
+
+ int start= -1;
+ int end= -1;
+
+ try {
+
+ int position= offset;
+ char character;
+
+ while (position >= 0) {
+ character= document.getChar(position);
+ if (!Character.isJavaIdentifierPart(character))
+ break;
+ --position;
+ }
+
+ start= position;
+
+ position= offset;
+ int length= document.getLength();
+
+ while (position < length) {
+ character= document.getChar(position);
+ if (!Character.isJavaIdentifierPart(character))
+ break;
+ ++position;
+ }
+
+ end= position;
+
+ if (end > start)
+ return new Point(start, end - start);
+
+ } catch (BadLocationException x) {
+ }
+
+ return null;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java
new file mode 100644
index 00000000000..b9994084f23
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocCompletionProcessor.java
@@ -0,0 +1,66 @@
+package org.eclipse.ui.examples.javaeditor.javadoc;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.contentassist.CompletionProposal;
+import org.eclipse.jface.text.contentassist.ICompletionProposal;
+import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
+import org.eclipse.jface.text.contentassist.IContextInformation;
+import org.eclipse.jface.text.contentassist.IContextInformationValidator;
+
+/**
+ * Example Java doc completion processor.
+ */
+public class JavaDocCompletionProcessor implements IContentAssistProcessor {
+
+ protected final static String[] fgProposals= { "@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version" }; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset) {
+ ICompletionProposal[] result= new ICompletionProposal[fgProposals.length];
+ for (int i= 0; i < fgProposals.length; i++)
+ result[i]= new CompletionProposal(fgProposals[i], documentOffset, 0, fgProposals[i].length());
+ return result;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public char[] getCompletionProposalAutoActivationCharacters() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public char[] getContextInformationAutoActivationCharacters() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public IContextInformationValidator getContextInformationValidator() {
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IContentAssistProcessor
+ */
+ public String getErrorMessage() {
+ return null;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java
new file mode 100644
index 00000000000..55dc5699280
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/javadoc/JavaDocScanner.java
@@ -0,0 +1,80 @@
+package org.eclipse.ui.examples.javaeditor.javadoc;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.jface.text.TextAttribute;
+import org.eclipse.jface.text.rules.IRule;
+import org.eclipse.jface.text.rules.IToken;
+import org.eclipse.jface.text.rules.IWordDetector;
+import org.eclipse.jface.text.rules.RuleBasedScanner;
+import org.eclipse.jface.text.rules.SingleLineRule;
+import org.eclipse.jface.text.rules.Token;
+import org.eclipse.jface.text.rules.WhitespaceRule;
+import org.eclipse.jface.text.rules.WordRule;
+import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
+import org.eclipse.ui.examples.javaeditor.util.JavaWhitespaceDetector;
+
+/**
+ * A rule based JavaDoc scanner.
+ */
+public class JavaDocScanner extends RuleBasedScanner {
+
+ /**
+ * A key word detector.
+ */
+ static class JavaDocWordDetector implements IWordDetector {
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector
+ */
+ public boolean isWordStart(char c) {
+ return (c == '@');
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector
+ */
+ public boolean isWordPart(char c) {
+ return Character.isLetter(c);
+ }
+ };
+
+ private static String[] fgKeywords= { "@author", "@deprecated", "@exception", "@param", "@return", "@see", "@serial", "@serialData", "@serialField", "@since", "@throws", "@version" }; //$NON-NLS-12$ //$NON-NLS-11$ //$NON-NLS-10$ //$NON-NLS-7$ //$NON-NLS-9$ //$NON-NLS-8$ //$NON-NLS-6$ //$NON-NLS-5$ //$NON-NLS-4$ //$NON-NLS-3$ //$NON-NLS-2$ //$NON-NLS-1$
+
+ /**
+ * Create a new java doc scanner.
+ */
+ public JavaDocScanner(JavaColorProvider provider) {
+ super();
+
+ IToken keyword= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_KEYWORD)));
+ IToken tag= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_TAG)));
+ IToken link= new Token(new TextAttribute(provider.getColor(JavaColorProvider.JAVADOC_LINK)));
+
+ List list= new ArrayList();
+
+ // Add rule for tags.
+ list.add(new SingleLineRule("<", ">", tag)); //$NON-NLS-2$ //$NON-NLS-1$
+
+ // Add rule for links.
+ list.add(new SingleLineRule("{", "}", link)); //$NON-NLS-2$ //$NON-NLS-1$
+
+ // Add generic whitespace rule.
+ list.add(new WhitespaceRule(new JavaWhitespaceDetector()));
+
+ // Add word rule for keywords.
+ WordRule wordRule= new WordRule(new JavaDocWordDetector());
+ for (int i= 0; i < fgKeywords.length; i++)
+ wordRule.addWord(fgKeywords[i], keyword);
+ list.add(wordRule);
+
+ IRule[] result= new IRule[list.size()];
+ list.toArray(result);
+ setRules(result);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif
new file mode 100644
index 00000000000..a0831f04bc6
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/togglepresentation.gif
Binary files differ
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java
new file mode 100644
index 00000000000..35c786bc815
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaColorProvider.java
@@ -0,0 +1,53 @@
+package org.eclipse.ui.examples.javaeditor.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.RGB;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * Manager for colors used in the Java editor
+ */
+public class JavaColorProvider {
+
+ public static final RGB MULTI_LINE_COMMENT= new RGB(128, 0, 0);
+ public static final RGB SINGLE_LINE_COMMENT= new RGB(128, 128, 0);
+ public static final RGB KEYWORD= new RGB(0, 0, 128);
+ public static final RGB TYPE= new RGB(0, 0, 128);
+ public static final RGB STRING= new RGB(0, 128, 0);
+ public static final RGB DEFAULT= new RGB(0, 0, 0);
+ public static final RGB JAVADOC_KEYWORD= new RGB(0, 128, 0);
+ public static final RGB JAVADOC_TAG= new RGB(128, 128, 128);
+ public static final RGB JAVADOC_LINK= new RGB(128, 128, 128);
+ public static final RGB JAVADOC_DEFAULT= new RGB(0, 128, 128);
+
+ protected Map fColorTable= new HashMap(10);
+
+ /**
+ * Release all of the color resources held onto by the receiver.
+ */
+ public void dispose() {
+ Iterator e= fColorTable.values().iterator();
+ while (e.hasNext())
+ ((Color) e.next()).dispose();
+ }
+
+ /**
+ * Return the Color that is stored in the Color table as rgb.
+ */
+ public Color getColor(RGB rgb) {
+ Color color= (Color) fColorTable.get(rgb);
+ if (color == null) {
+ color= new Color(Display.getCurrent(), rgb);
+ fColorTable.put(rgb, color);
+ }
+ return color;
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java
new file mode 100644
index 00000000000..a14a0eb40c0
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWhitespaceDetector.java
@@ -0,0 +1,21 @@
+package org.eclipse.ui.examples.javaeditor.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.rules.IWhitespaceDetector;
+
+/**
+ * A java aware white space detector.
+ */
+public class JavaWhitespaceDetector implements IWhitespaceDetector {
+
+ /* (non-Javadoc)
+ * Method declared on IWhitespaceDetector
+ */
+ public boolean isWhitespace(char character) {
+ return Character.isWhitespace(character);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java
new file mode 100644
index 00000000000..56126049274
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/Java Editor Example/org/eclipse/ui/examples/javaeditor/util/JavaWordDetector.java
@@ -0,0 +1,28 @@
+package org.eclipse.ui.examples.javaeditor.util;
+
+/*
+ * (c) Copyright IBM Corp. 2000, 2001.
+ * All Rights Reserved.
+ */
+
+import org.eclipse.jface.text.rules.IWordDetector;
+
+/**
+ * A Java aware word detector.
+ */
+public class JavaWordDetector implements IWordDetector {
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector.
+ */
+ public boolean isWordPart(char character) {
+ return Character.isJavaIdentifierPart(character);
+ }
+
+ /* (non-Javadoc)
+ * Method declared on IWordDetector.
+ */
+ public boolean isWordStart(char character) {
+ return Character.isJavaIdentifierStart(character);
+ }
+}
diff --git a/org.eclipse.ui.examples.javaeditor/build.properties b/org.eclipse.ui.examples.javaeditor/build.properties
new file mode 100644
index 00000000000..b7196de8811
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/build.properties
@@ -0,0 +1,12 @@
+bin.includes = plugin.xml,\
+ plugin.properties,\
+ icons/,\
+ *.jar
+build.includes = build.properties,\
+ plugin.jars,\
+ plugin.xml,\
+ plugin.properties,\
+ icons/,\
+ doc-html/
+source.javaeditorexample.jar = Java Editor Example
+build.vaj.Eclipse\ Java\ Editor\ Example = Java Editor Example
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm
new file mode 100644
index 00000000000..b071dbdf45b
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal.htm
@@ -0,0 +1,14 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.73 [en] (Win98; U) [Netscape]">
+ <title>Legal Notices</title>
+</head>
+<body>
+
+<h3>
+<a NAME="Notices"></a>Notices</h3>
+(c) Copyright IBM Corp. 2000, 2001. All Rights Reserved.
+</body>
+</html>
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif
new file mode 100644
index 00000000000..360f8e99891
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy.gif
Binary files differ
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html b/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html
new file mode 100644
index 00000000000..d81ed0b127f
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html
@@ -0,0 +1,236 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
+ <title>Desktop - Java Editor Example</title>
+</head>
+<body>
+
+<h2>
+<b>Example - Java Editor</b></h2>
+
+<h3>
+Introduction</h3>
+The Java Editor example demonstrates the standard features available for
+custom text editors.&nbsp; It also shows how&nbsp; to register an editor
+for a file extension (in this case .jav) and how to define a custom Document
+provider for use by that editor. This example is only for demonstration
+purposes. Java editing support is provided by the&nbsp; Eclipse Java Tooling.
+<h3>
+<b>Features demonstrated in the example editor</b></h3>
+
+<ul>
+<li>
+syntax highlighting</li>
+
+<li>
+content type sensitive content assist (JavaDoc and Java code)</li>
+
+<li>
+communication between content outliner and editor, i.e. content outliner
+selection feeds the highlight range of the editor</li>
+
+<li>
+two different presentation modes</li>
+
+<ul>
+<li>
+&nbsp;marking the highlight range using a visual range indicator</li>
+
+<li>
+confining the editor to show only text within the highlight range (e.g.
+show a single method of a Java class)</li>
+</ul>
+
+<li>
+marker handling</li>
+
+<li>
+document sharing</li>
+</ul>
+
+<h3>
+Features not demonstrated</h3>
+
+<ul>
+<li>
+content formatting</li>
+
+<li>
+dynamic reconciling of content outline page</li>
+</ul>
+
+<h3>
+Running the example editor</h3>
+
+<ol>
+<li>
+Create a project</li>
+
+<li>
+Create a file with the file extension ".jav" in the newly created project.
+The Java example editor opens automatically.</li>
+
+<li>
+Insert Java code. The Java code is dynamically colored. The example editor
+presents the following language elements in different colors: multi-line
+comments, single line comments, Java language reserved words, string and
+character constants, regular Java code, as well as multi-line comments
+following the JavaDoc guidelines. Inside those JavaDoc comments, JavaDoc
+keywords and tags are differently colored.</li>
+
+<li>
+Open a new Java multi-line comment by inserting "/*" outside a Java comment.
+All the text between the inserted "/*" and the first occurrence of "*/"
+or the end of the text changes its color to red. Append another "*". The
+red range changes color to green as the regular multi-line comment now
+is considered containing JavaDoc. Invoke code assist using CTRL-SPACE.
+The function of content assist is to support the user in writing code.
+So on invocation, content assist should list all possible valid completions
+at the invocation location. Inside JavaDoc, the example editor always proposes
+all JavaDoc keywords.</li>
+
+<li>
+Outside a Java comment invoke content tip using CTRL+SHIFT+SPACE. Five
+proposals are listed. Select one and press ENTER. A small floating red
+window appears above the current line displaying the selected proposal.
+The anticipated use of content tips is to let the user express her intention,
+e.g. to enter a method call and to present contextual information which
+guides the user by doing so. In the example editor, the proposal is considered
+valid five characters around the initial invocation location. While the
+content tip is visible, invoke content assist using CTRL+SPACE. Content
+assist invoked in this situation should help the user to accomplish her
+stated intention visible in the content tip. Inside regular Java code,
+the example editor always proposes all Java keywords.</li>
+
+<li>
+Save the Java code. Saving updates the content outliner. The content outliner
+contains ten entries each of them representing one of ten equally sized
+segments of the Java code in the editor. This style of content outline
+has been chosen to show that the semantics of highlight ranges can arbitrarily
+be defined. (See next steps.)</li>
+
+<li>
+Select one of the entries in the content outliner. The corresponding lines
+are marked with a blue bar in the editor's left vertical ruler.</li>
+
+<li>
+Now switch to the segmented presentation mode of the Java editor. For that
+make sure that the editor has the focus and press that button in the desktop's
+toolbar whose hover help says "Enable/Disable segmented source viewer".&nbsp;
+This functionality is anticipated to be used, e.g., for single method views.</li>
+
+<li>
+Select a different entry in the content outliner. Now the editor only shows
+the selected segment. By deselecting the entry in the content outliner,
+the complete Java code is shown again.</li>
+
+<li>
+Select an entry in the content outliner, select a fraction of the visible
+text, and add a task for the selection. The task shows up in the task list.
+Modify the visible code. In the task list, select the previously created
+task and press the "Go to file" button. The task is selected in the visible
+area, correctly taking the previously applied modifications into account.</li>
+
+<li>
+Select another entry in the content outliner. Reveal the previously added
+task from the task list. The editor's highlight range is automatically
+enlarged to enclose the range of the revealed task.</li>
+
+<li>
+Open a new workspace. In the new workspace, open a Java editor for the
+same file as in the original workspace. Modify the editor content. Switch
+back to the original workspace. The editor shows the changes made in the
+other workspace. The two editors showing the same file are lively linked.</li>
+</ol>
+
+<h3>
+Principles for creating custom text editors</h3>
+The following steps are usually necessary do develop a custom text editor.
+<ol>
+<li>
+Create a document provider. A document provider (see IDocumentProvider)
+produces and manages documents (see IDocument) containing a textual representation
+of editor input elements. It is important to decide how the translation
+between element and textual representation looks like and whether the document
+provider should be shared between multiple editors or not. See the class
+FileDocumentProvider in the Java example editor.</li>
+
+<li>
+Create a document partitioner. A document partitioner (see IDocumentPartitioner)
+divides a document into disjoint regions. The partitioner assigns each
+region one content type out of a set of content types predefined by the
+partitioner. On each document change the document's partitioning must be
+updated. See the class JavaPartitioner in the Java example editor. The
+JavaPartitioner determines regions of the types multi-line comments, JavaDoc
+comments, and everything else. It must be ensured that the document provider
+is set on each document produced by the document provider.</li>
+
+<li>
+Determine which of the source viewer plugins should be provided. Among
+other supported plugins are auto indent strategies, double click strategies,
+content formatter, and text presentation reconciler. The subsequent description
+will be restricted to the text presentation reconciler (see IPresentationReconciler).
+In the Java example editor, the text presentation reconciler is utilized
+to implement syntax highlighting.</li>
+
+<li>
+Create for all source viewer plugins the appropriate extensions for each
+supported content type. As seen above, the document partitioner defines
+the supported content types. The default implementation of IPresentationReconciler
+supports IPresentationDamagers and IPresentationRepairers as extensions.
+Those extensions are considered being specific for a particular content
+type. Thus, for a custom editor, the user must first select a subset of
+the supported content types. Regions of a type being a member of the selected
+subset will, e.g., be syntax highlighted. For each of those types the extensions
+must be implemented. See JavaDamagerRepairer and JavaDocDamagerRepairer
+in the example editor.</li>
+
+<li>
+Build a source viewer configuration using the previously created plugins
+and extensions. See JavaSourceViewerConfiguration in the example editor.</li>
+
+<li>
+Customize the class TextEditor or AbstractTextEditor with the developed
+document partitioner and source viewer configuration. Add or replace actions
+and adapt the construction of the editor's context menu. In the actual
+version, this customization must be done in a subclass. See JavaEditor
+in the example editor.</li>
+
+<li>
+Set up an appropriate action bar contributor who contributes editor-related
+actions to the desktop's toolbar and menus. See JavaActionContributor in
+the example editor.</li>
+
+<li>
+Extend the XML configuration file of the editor's plugin, so that the editor
+registers at the predefined editor extension point for a specific set of
+file extensions. Also set up the action bar contributor in the XML file.
+See plugin.xml of this example.</li>
+</ol>
+
+<h3>
+Code organization of the example</h3>
+The example code is organized in four packages:
+<ul>
+<li>
+<tt>org.eclipse.ui.examples.javaeditor </tt>contains all the editor specific
+classes.</li>
+
+<li>
+<tt>org.eclipse.ui.examples.javaeditor.java</tt> contains all Java specific
+source viewer plugins such as the JavaDamagerRepairer as well as the Java
+specific document partitioner.</li>
+
+<li>
+<tt>org.eclipse.ui.examples.javaeditor.javadoc </tt>contains all JavaDoc
+specific source viewer plugins such as the JavaDocDamagerRepairer.</li>
+
+<br><tt>org.eclipse.ui.examples.javaeditor.util</tt> contains convenience
+classes shared by the three other packages.</ul>
+
+<br>&nbsp;
+<p><a href="hglegal.htm"><img SRC="ngibmcpy.gif" ALT="Copyright IBM Corp. 2000, 2001. All Rights Reserved." BORDER=0 height=12 width=195></a>
+</body>
+</html>
diff --git a/org.eclipse.ui.examples.javaeditor/icons/basic/obj16/java.gif b/org.eclipse.ui.examples.javaeditor/icons/basic/obj16/java.gif
new file mode 100644
index 00000000000..83de817b719
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/icons/basic/obj16/java.gif
Binary files differ
diff --git a/org.eclipse.ui.examples.javaeditor/plugin.jars b/org.eclipse.ui.examples.javaeditor/plugin.jars
new file mode 100644
index 00000000000..dd36eb86353
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/plugin.jars
@@ -0,0 +1 @@
+javaeditorexample.jar=Java Editor Example \ No newline at end of file
diff --git a/org.eclipse.ui.examples.javaeditor/plugin.properties b/org.eclipse.ui.examples.javaeditor/plugin.properties
new file mode 100644
index 00000000000..93d4120c29e
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/plugin.properties
@@ -0,0 +1,14 @@
+#########################################
+# (c) Copyright IBM Corp. 2000, 2001.
+# All Rights Reserved.
+#########################################
+#
+# Resource strings for Java Example Editor
+#
+pluginName=JFace Text Example
+
+#
+# Extension point names
+#
+javaEditorName=Example Java Editor
+javaFileExtension=jav
diff --git a/org.eclipse.ui.examples.javaeditor/plugin.xml b/org.eclipse.ui.examples.javaeditor/plugin.xml
new file mode 100644
index 00000000000..a1bcd60ce7e
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/plugin.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- File written by PDE 1.0 -->
+<plugin
+ id="org.eclipse.ui.examples.javaeditor"
+ name="%pluginName"
+ version="1.0"
+ provider-name="Object Technology International, Inc.">
+<requires>
+ <import plugin="org.eclipse.ui"/>
+ <import plugin="org.eclipse.core.resources"/>
+</requires>
+
+<runtime>
+ <library name="javaeditorexample.jar">
+ <export name="*"/>
+ </library>
+</runtime>
+
+<extension
+ point="org.eclipse.ui.editors">
+ <editor
+ name="%javaEditorName"
+ icon="icons/basic/obj16/java.gif"
+ extensions="jav"
+ contributorClass="org.eclipse.ui.examples.javaeditor.JavaActionContributor"
+ class="org.eclipse.ui.examples.javaeditor.JavaEditor"
+ id="org.eclipse.ui.JavaEditor">
+ </editor>
+</extension>
+
+<extension
+ point="org.eclipse.ui.documentProviders">
+ <provider
+ extensions="%javaFileExtension"
+ class="org.eclipse.ui.examples.javaeditor.JavaDocumentProvider"
+ id="org.eclipse.ui.examples.javaeditor.JavaDocumentProvider">
+ </provider>
+</extension>
+
+</plugin>

Back to the top