Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKai Maetzel2004-05-19 13:14:43 +0000
committerKai Maetzel2004-05-19 13:14:43 +0000
commit0874bbd656d0737a413c6332514574cae6d3989e (patch)
tree22d3cd8a6e48d87096c871b824a200cbff2546a9 /org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org
parentba98fd0de7172fce834a78c09279550ad8236e34 (diff)
downloadeclipse.platform.text-0874bbd656d0737a413c6332514574cae6d3989e.tar.gz
eclipse.platform.text-0874bbd656d0737a413c6332514574cae6d3989e.tar.xz
eclipse.platform.text-0874bbd656d0737a413c6332514574cae6d3989e.zip
folding in example editor
Diffstat (limited to 'org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org')
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java125
-rw-r--r--org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties83
2 files changed, 161 insertions, 47 deletions
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
index bc4b055f4b0..aebed1f69fc 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditor.java
@@ -11,17 +11,36 @@
package org.eclipse.ui.examples.javaeditor;
+import java.util.ResourceBundle;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.swt.widgets.Composite;
+
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.text.ITextViewerExtension5;
+import org.eclipse.jface.text.Position;
+import org.eclipse.jface.text.Region;
+import org.eclipse.jface.text.source.IAnnotationModel;
import org.eclipse.jface.text.source.ISourceViewer;
+import org.eclipse.jface.text.source.IVerticalRuler;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotation;
+import org.eclipse.jface.text.source.projection.ProjectionAnnotationModel;
+import org.eclipse.jface.text.source.projection.ProjectionSupport;
+import org.eclipse.jface.text.source.projection.ProjectionViewer;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.ITextEditor;
import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds;
+import org.eclipse.ui.texteditor.TextEditorAction;
import org.eclipse.ui.texteditor.TextOperationAction;
import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
@@ -30,9 +49,52 @@ import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
* Java specific text editor.
*/
public class JavaEditor extends TextEditor {
+
+
+ private class DefineFoldingRegionAction extends TextEditorAction {
+
+ public DefineFoldingRegionAction(ResourceBundle bundle, String prefix, ITextEditor editor) {
+ super(bundle, prefix, editor);
+ }
+
+ private IAnnotationModel getAnnotationModel(ITextEditor editor) {
+ return (IAnnotationModel) editor.getAdapter(ProjectionAnnotationModel.class);
+ }
+
+ /*
+ * @see org.eclipse.jface.action.Action#run()
+ */
+ public void run() {
+ ITextEditor editor= getTextEditor();
+ ISelection selection= editor.getSelectionProvider().getSelection();
+ if (selection instanceof ITextSelection) {
+ ITextSelection textSelection= (ITextSelection) selection;
+ if (!textSelection.isEmpty()) {
+ IAnnotationModel model= getAnnotationModel(editor);
+ if (model != null) {
+
+ int start= textSelection.getStartLine();
+ int end= textSelection.getEndLine();
+
+ try {
+ IDocument document= editor.getDocumentProvider().getDocument(editor.getEditorInput());
+ int offset= document.getLineOffset(start);
+ int endOffset= document.getLineOffset(end + 1);
+ Position position= new Position(offset, endOffset - offset);
+ model.addAnnotation(new ProjectionAnnotation(), position);
+ } catch (BadLocationException x) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+ }
/** The outline page */
private JavaContentOutlinePage fOutlinePage;
+ /** The projection support */
+ private ProjectionSupport fProjectionSupport;
/**
* Default constructor.
@@ -55,6 +117,9 @@ public class JavaEditor extends TextEditor {
a= new TextOperationAction(JavaEditorMessages.getResourceBundle(), "ContentAssistTip.", this, ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION); //$NON-NLS-1$
a.setActionDefinitionId(ITextEditorActionDefinitionIds.CONTENT_ASSIST_CONTEXT_INFORMATION);
setAction("ContentAssistTip", a); //$NON-NLS-1$
+
+ a= new DefineFoldingRegionAction(JavaEditorMessages.getResourceBundle(), "DefineFoldingRegion.", this);
+ setAction("DefineFoldingRegion", a);
}
/** The <code>JavaEditor</code> implementation of this
@@ -107,14 +172,14 @@ public class JavaEditor extends TextEditor {
fOutlinePage.setInput(input);
}
- /** The <code>JavaEditor</code> implementation of this
- * <code>AbstractTextEditor</code> method adds any
- * JavaEditor specific entries.
- */
- public void editorContextMenuAboutToShow(MenuManager menu) {
+ /*
+ * @see org.eclipse.ui.texteditor.ExtendedTextEditor#editorContextMenuAboutToShow(org.eclipse.jface.action.IMenuManager)
+ */
+ protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
addAction(menu, "ContentAssistProposal"); //$NON-NLS-1$
addAction(menu, "ContentAssistTip"); //$NON-NLS-1$
+ addAction(menu, "DefineFoldingRegion");
}
/** The <code>JavaEditor</code> implementation of this
@@ -131,6 +196,13 @@ public class JavaEditor extends TextEditor {
}
return fOutlinePage;
}
+
+ if (fProjectionSupport != null) {
+ Object adapter= fProjectionSupport.getAdapter(getSourceViewer(), required);
+ if (adapter != null)
+ return adapter;
+ }
+
return super.getAdapter(required);
}
@@ -140,7 +212,44 @@ public class JavaEditor extends TextEditor {
protected void initializeEditor() {
super.initializeEditor();
setSourceViewerConfiguration(new JavaSourceViewerConfiguration());
-// setEditorContextMenuId("#JavaEditorContext"); //$NON-NLS-1$
-// setRulerContextMenuId("#JavaRulerContext"); //$NON-NLS-1$
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.ExtendedTextEditor#createSourceViewer(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.source.IVerticalRuler, int)
+ */
+ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
+
+ fAnnotationAccess= createAnnotationAccess();
+ fOverviewRuler= createOverviewRuler(getSharedColors());
+
+ ISourceViewer viewer= new ProjectionViewer(parent, ruler, getOverviewRuler(), isOverviewRulerVisible(), styles);
+ // ensure decoration support has been created and configured.
+ getSourceViewerDecorationSupport(viewer);
+
+ return viewer;
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.ExtendedTextEditor#createPartControl(org.eclipse.swt.widgets.Composite)
+ */
+ public void createPartControl(Composite parent) {
+ super.createPartControl(parent);
+ ProjectionViewer viewer= (ProjectionViewer) getSourceViewer();
+ fProjectionSupport= new ProjectionSupport(viewer, getAnnotationAccess(), getSharedColors());
+ fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.error");
+ fProjectionSupport.addSummarizableAnnotationType("org.eclipse.ui.workbench.texteditor.warning");
+ fProjectionSupport.install();
+ viewer.doOperation(ProjectionViewer.TOGGLE);
+ }
+
+ /*
+ * @see org.eclipse.ui.texteditor.AbstractTextEditor#adjustHighlightRange(int, int)
+ */
+ protected void adjustHighlightRange(int offset, int length) {
+ ISourceViewer viewer= getSourceViewer();
+ if (viewer instanceof ITextViewerExtension5) {
+ ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
+ extension.exposeModelRange(new Region(offset, length));
+ }
}
}
diff --git a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
index 441a4a4e562..8e7801e10ec 100644
--- a/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
+++ b/org.eclipse.ui.examples.javaeditor/Eclipse Java Editor Example/org/eclipse/ui/examples/javaeditor/JavaEditorMessages.properties
@@ -1,39 +1,44 @@
-###############################################################################
-# Copyright (c) 2000, 2003 IBM Corporation and others.
-# All rights reserved. This program and the accompanying materials
-# are made available under the terms of the Common Public License v1.0
-# which accompanies this distribution, and is available at
-# http://www.eclipse.org/legal/cpl-v10.html
-#
-# Contributors:
-# IBM Corporation - initial API and implementation
-###############################################################################
-
-## 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}
-
-JavaTextHover.emptySelection=empty selection
+###############################################################################
+# Copyright (c) 2000, 2003 IBM Corporation and others.
+# All rights reserved. This program and the accompanying materials
+# are made available under the terms of the Common Public License v1.0
+# which accompanies this distribution, and is available at
+# http://www.eclipse.org/legal/cpl-v10.html
+#
+# Contributors:
+# IBM Corporation - initial API and implementation
+###############################################################################
+
+## 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
+
+DefineFoldingRegion.label=Define Folding Region
+DefineFoldingRegion.tooltip=Define Folding Region
+DefineFoldingRegion.image=
+DefineFoldingRegion.description=Define Folding Region
+
+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}
+
+JavaTextHover.emptySelection=empty selection

Back to the top