Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2002-06-27 16:59:40 +0000
committerKai Maetzel2002-06-27 16:59:40 +0000
commit8c5e9f69f6d9608660099e93ee15f2a938ed7894 (patch)
tree7f2a2c868b6ee175f43a7c3a887200257f8c0fb3 /org.eclipse.ui.examples.javaeditor
parent9d2c6fd88db935be042b6706640cf5adf508e206 (diff)
downloadeclipse.platform.text-8c5e9f69f6d9608660099e93ee15f2a938ed7894.tar.gz
eclipse.platform.text-8c5e9f69f6d9608660099e93ee15f2a938ed7894.tar.xz
eclipse.platform.text-8c5e9f69f6d9608660099e93ee15f2a938ed7894.zip
Example codev20020627R2_0
Diffstat (limited to 'org.eclipse.ui.examples.javaeditor')
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java52
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java9
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java27
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java9
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java11
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java42
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm13
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gifbin0 -> 1045 bytes
-rw-r--r--org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html4
9 files changed, 125 insertions, 42 deletions
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
index b01f739b8e0..aba3eedc87d 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaActionContributor.java
@@ -9,18 +9,19 @@ 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.IActionBars;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.editors.text.TextEditorActionContributor;
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.
+ * Contributes interesting Java actions to the desktop's Edit menu and the toolbar.
*/
-public class JavaActionContributor extends BasicTextEditorActionContributor {
+public class JavaActionContributor extends TextEditorActionContributor {
protected RetargetTextEditorAction fContentAssistProposal;
protected RetargetTextEditorAction fContentAssistTip;
@@ -31,36 +32,33 @@ public class JavaActionContributor extends BasicTextEditorActionContributor {
*/
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
+ /*
+ * @see IEditorActionBarContributor#init(IActionBars)
*/
- public void contributeToMenu(IMenuManager menuManager) {
+ public void init(IActionBars bars) {
+ super.init(bars);
+
+ IMenuManager menuManager= bars.getMenuManager();
IMenuManager editMenu= menuManager.findMenuUsingPath(IWorkbenchActionConstants.M_EDIT);
if (editMenu != null) {
editMenu.add(new Separator());
editMenu.add(fContentAssistProposal);
editMenu.add(fContentAssistTip);
+ }
+
+ IToolBarManager toolBarManager= bars.getToolBarManager();
+ if (toolBarManager != null) {
+ toolBarManager.add(new Separator());
+ toolBarManager.add(fTogglePresentation);
}
}
- /* (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) {
+ private void doSetActiveEditor(IEditorPart part) {
super.setActiveEditor(part);
ITextEditor editor= null;
@@ -73,4 +71,20 @@ public class JavaActionContributor extends BasicTextEditorActionContributor {
fTogglePresentation.setEditor(editor);
fTogglePresentation.update();
}
+
+ /*
+ * @see IEditorActionBarContributor#setActiveEditor(IEditorPart)
+ */
+ public void setActiveEditor(IEditorPart part) {
+ super.setActiveEditor(part);
+ doSetActiveEditor(part);
+ }
+
+ /*
+ * @see IEditorActionBarContributor#dispose()
+ */
+ public void dispose() {
+ doSetActiveEditor(null);
+ super.dispose();
+ }
}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
index f11dfd17065..7bcbb08c450 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaDocumentProvider.java
@@ -8,6 +8,7 @@ package org.eclipse.ui.examples.javaeditor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.text.IDocument;
import org.eclipse.jface.text.IDocumentPartitioner;
+import org.eclipse.jface.text.rules.DefaultPartitioner;
import org.eclipse.jface.text.rules.RuleBasedPartitioner;
import org.eclipse.ui.editors.text.FileDocumentProvider;
import org.eclipse.ui.examples.javaeditor.java.JavaPartitionScanner;
@@ -33,17 +34,17 @@ public class JavaDocumentProvider extends FileDocumentProvider {
IDocument document= super.createDocument(element);
if (document != null) {
IDocumentPartitioner partitioner= createJavaPartitioner();
- partitioner.connect(document);
document.setDocumentPartitioner(partitioner);
+ partitioner.connect(document);
}
return document;
}
/**
- * Return a paritioner for .java files.
+ * Return a partitioner for .java files.
*/
- private RuleBasedPartitioner createJavaPartitioner() {
- return new RuleBasedPartitioner(getJavaPartitionScanner(), TYPES);
+ private IDocumentPartitioner createJavaPartitioner() {
+ return new DefaultPartitioner(getJavaPartitionScanner(), TYPES);
}
/**
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
index b911cd41192..3d46dd102fb 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaSourceViewerConfiguration.java
@@ -5,6 +5,8 @@ package org.eclipse.ui.examples.javaeditor;
* All Rights Reserved.
*/
+import java.util.List;
+
import org.eclipse.swt.graphics.RGB;
import org.eclipse.jface.text.DefaultAutoIndentStrategy;
import org.eclipse.jface.text.IAutoIndentStrategy;
@@ -16,7 +18,11 @@ 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.BufferedRuleBasedScanner;
+import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
+import org.eclipse.jface.text.rules.IToken;
import org.eclipse.jface.text.rules.RuleBasedDamagerRepairer;
+import org.eclipse.jface.text.rules.Token;
import org.eclipse.jface.text.source.IAnnotationHover;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.jface.text.source.SourceViewerConfiguration;
@@ -31,6 +37,17 @@ import org.eclipse.ui.examples.javaeditor.util.JavaColorProvider;
* Example configuration for an <code>SourceViewer</code> which shows Java code.
*/
public class JavaSourceViewerConfiguration extends SourceViewerConfiguration {
+
+
+ /**
+ * Single token scanner.
+ */
+ static class SingleTokenScanner extends BufferedRuleBasedScanner {
+ public SingleTokenScanner(TextAttribute attribute) {
+ setDefaultReturnToken(new Token(attribute));
+ }
+ };
+
/**
* Default constructor.
@@ -105,16 +122,16 @@ public class JavaSourceViewerConfiguration extends SourceViewerConfiguration {
JavaColorProvider provider= JavaEditorEnvironment.getJavaColorProvider();
PresentationReconciler reconciler= new PresentationReconciler();
-
- RuleBasedDamagerRepairer dr= new RuleBasedDamagerRepairer(JavaEditorEnvironment.getJavaCodeScanner(), new TextAttribute(provider.getColor(provider.DEFAULT)));
+
+ DefaultDamagerRepairer dr= new DefaultDamagerRepairer(JavaEditorEnvironment.getJavaCodeScanner());
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)));
+
+ dr= new DefaultDamagerRepairer(new SingleTokenScanner(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)));
+ dr= new DefaultDamagerRepairer(new SingleTokenScanner(new TextAttribute(provider.getColor(provider.MULTI_LINE_COMMENT))));
reconciler.setDamager(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
reconciler.setRepairer(dr, JavaPartitionScanner.JAVA_MULTILINE_COMMENT);
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
index 3c1f3a867f3..78b6a4ac309 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaTextHover.java
@@ -23,11 +23,12 @@ public class JavaTextHover implements ITextHover {
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
if (hoverRegion != null) {
try {
- return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
+ if (hoverRegion.getLength() > -1)
+ return textViewer.getDocument().get(hoverRegion.getOffset(), hoverRegion.getLength());
} catch (BadLocationException x) {
}
}
- return null;
+ return "empty selection";
}
/* (non-Javadoc)
@@ -35,8 +36,8 @@ public class JavaTextHover implements ITextHover {
*/
public IRegion getHoverRegion(ITextViewer textViewer, int offset) {
Point selection= textViewer.getSelectedRange();
- if (selection.y > 0 && selection.x <= offset && offset <= selection.x + selection.y)
+ if (selection.x <= offset && offset < selection.x + selection.y)
return new Region(selection.x, selection.y);
- return null;
+ return new Region(offset, 0);
}
}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
index 9efa3acc004..8b9d5eb739d 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaCompletionProcessor.java
@@ -8,11 +8,13 @@ package org.eclipse.ui.examples.javaeditor.java;
import java.text.MessageFormat;
import org.eclipse.jface.text.ITextViewer;
+import org.eclipse.jface.text.TextPresentation;
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.IContextInformationPresenter;
import org.eclipse.jface.text.contentassist.IContextInformationValidator;
/**
@@ -24,7 +26,7 @@ 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 static class Validator implements IContextInformationValidator, IContextInformationPresenter {
protected int fInstallOffset;
@@ -41,6 +43,13 @@ public class JavaCompletionProcessor implements IContentAssistProcessor {
public void install(IContextInformation info, ITextViewer viewer, int offset) {
fInstallOffset= offset;
}
+
+ /*
+ * @see org.eclipse.jface.text.contentassist.IContextInformationPresenter#updatePresentation(int, TextPresentation)
+ */
+ public boolean updatePresentation(int documentPosition, TextPresentation presentation) {
+ return false;
+ }
};
protected final static String[] fgProposals=
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
index e817770a938..291e31fca81 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/java/JavaPartitionScanner.java
@@ -8,10 +8,13 @@ package org.eclipse.ui.examples.javaeditor.java;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jface.text.rules.EndOfLineRule;
+import org.eclipse.jface.text.rules.ICharacterScanner;
+import org.eclipse.jface.text.rules.IPredicateRule;
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.RuleBasedPartitionScanner;
import org.eclipse.jface.text.rules.RuleBasedScanner;
import org.eclipse.jface.text.rules.SingleLineRule;
import org.eclipse.jface.text.rules.Token;
@@ -20,10 +23,9 @@ import org.eclipse.jface.text.rules.WordRule;
/**
* This scanner recognizes the JavaDoc comments and Java multi line comments.
*/
-public class JavaPartitionScanner extends RuleBasedScanner {
+public class JavaPartitionScanner extends RuleBasedPartitionScanner {
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$
@@ -46,6 +48,34 @@ public class JavaPartitionScanner extends RuleBasedScanner {
return (c == '*' || c == '/');
}
};
+
+ /**
+ *
+ */
+ static class WordPredicateRule extends WordRule implements IPredicateRule {
+
+ private IToken fSuccessToken;
+
+ public WordPredicateRule(IToken successToken) {
+ super(new EmptyCommentDetector());
+ fSuccessToken= successToken;
+ addWord("/**/", fSuccessToken);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IPredicateRule#evaluate(ICharacterScanner, boolean)
+ */
+ public IToken evaluate(ICharacterScanner scanner, boolean resume) {
+ return super.evaluate(scanner);
+ }
+
+ /*
+ * @see org.eclipse.jface.text.rules.IPredicateRule#getSuccessToken()
+ */
+ public IToken getSuccessToken() {
+ return fSuccessToken;
+ }
+ };
/**
* Creates the partitioner and sets up the appropriate rules.
@@ -66,16 +96,14 @@ public class JavaPartitionScanner extends RuleBasedScanner {
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);
+ rules.add(new WordPredicateRule(comment));
// 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()];
+ IPredicateRule[] result= new IPredicateRule[rules.size()];
rules.toArray(result);
- setRules(result);
+ setPredicateRules(result);
}
}
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm
new file mode 100644
index 00000000000..e1aabb63d6a
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/hglegal2002.htm
@@ -0,0 +1,13 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+ <title>Legal Notices</title>
+</head>
+<body>
+
+<h3>
+<a NAME="Notices"></a>Notices</h3>
+(c) Copyright IBM Corp. and others 2000, 2002. All Rights Reserved.
+</body>
+</html>
diff --git a/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.gif
new file mode 100644
index 00000000000..61cef485216
--- /dev/null
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/ngibmcpy2002.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
index d81ed0b127f..81042c28919 100644
--- a/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html
+++ b/org.eclipse.ui.examples.javaeditor/doc-html/ui_javaeditor_ex.html
@@ -2,7 +2,7 @@
<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]">
+ <meta name="GENERATOR" content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
<title>Desktop - Java Editor Example</title>
</head>
<body>
@@ -231,6 +231,6 @@ specific source viewer plugins such as the JavaDocDamagerRepairer.</li>
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>
+<p><a href="hglegal2002.htm"><img SRC="ngibmcpy2002.gif" ALT="Copyright IBM Corp. 2000, 2001. All Rights Reserved." BORDER=0 height=14 width=324></a>
</body>
</html>

Back to the top