Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'org.eclipse.jface.text')
-rw-r--r--org.eclipse.jface.text/.classpath8
-rw-r--r--org.eclipse.jface.text/.cvsignore1
-rw-r--r--org.eclipse.jface.text/.options7
-rw-r--r--org.eclipse.jface.text/.project32
-rw-r--r--org.eclipse.jface.text/about.html30
-rw-r--r--org.eclipse.jface.text/build.properties17
-rw-r--r--org.eclipse.jface.text/plugin.properties12
-rw-r--r--org.eclipse.jface.text/plugin.xml22
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/AnnotationBag.java52
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/IProjectionListener.java29
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotation.java154
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationHover.java160
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java146
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java224
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java285
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSupport.java260
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java1537
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/SourceViewerInformationControl.java338
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/collapsed.gifbin82 -> 0 bytes
-rw-r--r--org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/expanded.gifbin82 -> 0 bytes
-rw-r--r--org.eclipse.jface.text/scripts/exportplugin.xml29
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java823
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java211
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/IContentAssistSubjectControl.java297
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistProcessor.java53
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistant.java31
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationPresenter.java34
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationValidator.java35
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContentAssistant.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java78
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java192
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/images/content_assist_cue.gifbin106 -> 0 bytes
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/contentassist/package.html25
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java255
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java871
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java82
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.properties19
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java1587
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java629
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTML2TextReader.java302
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTMLTextPresenter.java191
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/Helper2.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IContentAssistListener2.java35
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IProposalListener.java26
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/LineBreakingReader.java114
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java100
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SingleCharReader.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SubstitutionTextReader.java151
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/package.html14
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java488
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java1011
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/CursorLinePainter.java259
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java91
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java410
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java420
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java218
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java835
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java72
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java468
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoEditStrategy.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java21
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java37
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java39
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java41
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java72
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java89
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension3.java53
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java145
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreatorExtension.java41
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java29
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension2.java31
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension3.java73
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java48
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IPaintPositionManager.java40
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IPainter.java94
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java55
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ISelectionValidator.java36
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java52
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHoverExtension.java29
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java40
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java39
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java101
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextPresentationListener.java34
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java84
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java434
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java103
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension2.java108
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension3.java96
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension4.java50
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension5.java118
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java94
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java34
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeperExtension.java46
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java45
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwnerExtension.java37
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/MarginPainter.java171
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java69
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/PaintManager.java380
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java133
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java121
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java120
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java699
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java189
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java4858
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java417
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java268
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java135
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java1107
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java408
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java1803
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java96
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java794
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java64
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java87
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java68
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension2.java74
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension3.java70
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java36
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java86
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java91
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistantExtension.java35
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java63
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java29
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java47
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java44
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java32
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java100
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/package.html25
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java796
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContextBasedFormattingStrategy.java76
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContext.java165
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContextProperties.java69
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java55
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatterExtension.java75
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingContext.java156
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java55
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategyExtension.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java314
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/package.html57
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java64
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenterExtension.java27
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java54
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension.java42
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension2.java31
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java494
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/information/package.html22
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java1178
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedPositionAnnotations.java310
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/link/ProposalPosition.java88
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/link/TabStopIterator.java215
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/link/package.html71
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/package.html82
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java60
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java76
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java27
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java56
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java583
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/package.html24
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconcileStep.java165
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java544
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java97
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java104
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilableModel.java21
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileResult.java22
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileStep.java100
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java62
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilerExtension.java27
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java60
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java45
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java107
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java219
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/package.html25
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java133
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java218
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java635
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java67
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java51
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java42
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java47
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java53
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java58
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java28
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java38
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java63
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java72
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java273
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java49
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java106
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java587
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java198
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java89
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java125
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java58
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java108
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java145
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/rules/package.html21
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java555
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java30
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java1394
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java985
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java665
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java856
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java51
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java89
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java33
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java65
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java46
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IChangeRulerColumn.java63
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java70
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java73
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffer.java73
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineRange.java31
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IOverviewRuler.java116
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISharedTextColors.java39
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java162
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension.java37
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java37
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java75
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java74
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java41
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java63
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfoExtension.java47
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerListener.java48
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java87
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java68
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java308
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java434
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java895
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineRange.java39
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java262
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java1229
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRulerHoverManager.java77
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java902
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java309
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java588
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRulerEvent.java46
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java146
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/source/package.html26
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java55
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java103
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties14
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java168
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java228
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java408
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html113
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java173
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java61
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties14
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java345
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java344
-rw-r--r--org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html113
261 files changed, 0 insertions, 53106 deletions
diff --git a/org.eclipse.jface.text/.classpath b/org.eclipse.jface.text/.classpath
deleted file mode 100644
index f2a7ad8ee11..00000000000
--- a/org.eclipse.jface.text/.classpath
+++ /dev/null
@@ -1,8 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="src" path="projection"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/org.eclipse.jface.text/.cvsignore b/org.eclipse.jface.text/.cvsignore
deleted file mode 100644
index ba077a4031a..00000000000
--- a/org.eclipse.jface.text/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
diff --git a/org.eclipse.jface.text/.options b/org.eclipse.jface.text/.options
deleted file mode 100644
index 667d1d1c9ff..00000000000
--- a/org.eclipse.jface.text/.options
+++ /dev/null
@@ -1,7 +0,0 @@
-# Debugging options for the org.eclipse.jface.text plug-in
-
-# Prints debug information related to AnnotationPainter
-org.eclipse.jface.text/debug/AnnotationPainter= false
-
-# Prints debug information related to AbstractContentAssistSubjectAdapter and its subclasses
-org.eclipse.jface.text/debug/ContentAssistSubjectAdapters= false \ No newline at end of file
diff --git a/org.eclipse.jface.text/.project b/org.eclipse.jface.text/.project
deleted file mode 100644
index 4c20484032c..00000000000
--- a/org.eclipse.jface.text/.project
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.jface.text</name>
- <comment></comment>
- <projects>
- <project>org.eclipse.core.runtime.compatibility</project>
- <project>org.eclipse.jface</project>
- <project>org.eclipse.swt</project>
- <project>org.eclipse.text</project>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.ManifestBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.pde.SchemaBuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.pde.PluginNature</nature>
- </natures>
-</projectDescription>
diff --git a/org.eclipse.jface.text/about.html b/org.eclipse.jface.text/about.html
deleted file mode 100644
index 9db411aab99..00000000000
--- a/org.eclipse.jface.text/about.html
+++ /dev/null
@@ -1,30 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
-<html>
-<head>
-<title>About</title>
-<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
-</head>
-<body lang="EN-US">
-<h2>About This Content</h2>
-
-<p>20th June, 2002</p>
-<h3>License</h3>
-<p>Eclipse.org makes available all content in this plug-in (&quot;Content&quot;). Unless otherwise indicated below, the Content is provided to you under the terms and conditions of the
-Common Public License Version 1.0 (&quot;CPL&quot;). A copy of the CPL is available at <a href="http://www.eclipse.org/legal/cpl-v10.html">http://www.eclipse.org/legal/cpl-v10.html</a>.
-For purposes of the CPL, &quot;Program&quot; will mean the Content.</p>
-
-<h3>Contributions</h3>
-
-<p>If this Content is licensed to you under the terms and conditions of the CPL, any Contributions, as defined in the CPL, uploaded, submitted, or otherwise
-made available to Eclipse.org, members of Eclipse.org and/or the host of Eclipse.org web site, by you that relate to such
-Content are provided under the terms and conditions of the CPL and can be made available to others under the terms of the CPL.</p>
-
-<p>If this Content is licensed to you under license terms and conditions other than the CPL (&quot;Other License&quot;), any modifications, enhancements and/or
-other code and/or documentation (&quot;Modifications&quot;) uploaded, submitted, or otherwise made available to Eclipse.org, members of Eclipse.org and/or the
-host of Eclipse.org, by you that relate to such Content are provided under terms and conditions of the Other License and can be made available
-to others under the terms of the Other License. In addition, with regard to Modifications for which you are the copyright holder, you are also
-providing the Modifications under the terms and conditions of the CPL and such Modifications can be made available to others under the terms of
-the CPL.</p>
-
-</body>
-</html> \ No newline at end of file
diff --git a/org.eclipse.jface.text/build.properties b/org.eclipse.jface.text/build.properties
deleted file mode 100644
index 9616ddc47f4..00000000000
--- a/org.eclipse.jface.text/build.properties
+++ /dev/null
@@ -1,17 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-bin.includes = plugin.properties,\
- plugin.xml,\
- .options,\
- *.jar,\
- about.html
-source.jfacetext.jar = src/,\
- projection/
diff --git a/org.eclipse.jface.text/plugin.properties b/org.eclipse.jface.text/plugin.properties
deleted file mode 100644
index db3cdf485c7..00000000000
--- a/org.eclipse.jface.text/plugin.properties
+++ /dev/null
@@ -1,12 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-pluginName = JFace Text
-providerName = Eclipse.org
diff --git a/org.eclipse.jface.text/plugin.xml b/org.eclipse.jface.text/plugin.xml
deleted file mode 100644
index 971c4dd5147..00000000000
--- a/org.eclipse.jface.text/plugin.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<?eclipse version="3.0"?>
-<plugin
- id="org.eclipse.jface.text"
- name="%pluginName"
- version="3.0.0"
- provider-name="%providerName">
-
- <runtime>
- <library name="jfacetext.jar">
- <export name="*"/>
- </library>
- </runtime>
-
- <requires>
- <import plugin="org.eclipse.core.runtime"/>
- <import plugin="org.eclipse.text" export="true"/>
- <import plugin="org.eclipse.swt"/>
- <import plugin="org.eclipse.jface"/>
- </requires>
-
-</plugin>
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/AnnotationBag.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/AnnotationBag.java
deleted file mode 100644
index c3ae97b7f49..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/AnnotationBag.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import java.util.HashSet;
-import java.util.Set;
-
-import org.eclipse.jface.text.source.Annotation;
-
-/**
- * A bag of annotations.
- *
- * @since 3.0
- */
-public class AnnotationBag extends Annotation {
-
- private Set fAnnotations;
-
- /** Creates a new annotation bag.
- *
- * @param type the annotation type
- */
- public AnnotationBag(String type) {
- super(type, false, null);
- }
-
- public void add(Annotation annotation) {
- if (fAnnotations == null)
- fAnnotations= new HashSet(2);
- fAnnotations.add(annotation);
- }
-
- public void remove(Annotation annotation) {
- if (fAnnotations != null) {
- fAnnotations.remove(annotation);
- if (fAnnotations.isEmpty())
- fAnnotations= null;
- }
- }
-
- public boolean isEmpty() {
- return fAnnotations == null;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/IProjectionListener.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/IProjectionListener.java
deleted file mode 100644
index a13cc0f4299..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/IProjectionListener.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-/**
- * Internal class. Do not use.
- *
- * @since 3.0
- */
-public interface IProjectionListener {
-
- /**
- * Tells this listener that projection has been enabled.
- */
- void projectionEnabled();
-
- /**
- * Tells this listener that projection has been disabled.
- */
- void projectionDisabled();
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotation.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotation.java
deleted file mode 100644
index a413c59e78f..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotation.java
+++ /dev/null
@@ -1,154 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.jface.resource.ImageDescriptor;
-
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationPresentation;
-import org.eclipse.jface.text.source.ImageUtilities;
-
-/**
- * Annotation used to represent the projection of a master document onto a
- * <code>ProjectionDocument</code>. A projection annotation can be either
- * expanded or collapsed. If expanded it corresponds to a segment of the
- * projection document. If collapsed, it represents a region of the master
- * document that does not have a corresponding segment in the projection
- * document.
- * <p>
- *
- * @since 3.0
- */
-public class ProjectionAnnotation extends Annotation implements IAnnotationPresentation {
-
- private static class DisplayDisposeRunnable implements Runnable {
-
- public void run() {
- if (fgCollapsedImage != null) {
- fgCollapsedImage.dispose();
- fgCollapsedImage= null;
- }
- if (fgExpandedImage != null) {
- fgExpandedImage.dispose();
- fgExpandedImage= null;
- }
- }
- }
-
- /**
- * The type of projection annotations.
- */
- public static final String TYPE= "org.eclipse.projection"; //$NON-NLS-1$
-
-
- private static final int COLOR= SWT.COLOR_DARK_GRAY;
- private static Image fgCollapsedImage;
- private static Image fgExpandedImage;
-
-
- /** The state of this annotation */
- private boolean fIsCollapsed= false;
- /** Indicates whether this annotation should be painted as range */
- private boolean fIsRangeIndication= false;
-
- /**
- * Creates a new projection annotation.
- */
- public ProjectionAnnotation() {
- this(false);
- }
-
- public ProjectionAnnotation(boolean isCollapsed) {
- super(TYPE, false, null);
- fIsCollapsed= isCollapsed;
- }
-
- public void setRangeIndication(boolean rangeIndication) {
- fIsRangeIndication= rangeIndication;
- }
-
- private void drawRangeIndication(GC gc, Canvas canvas, Rectangle r) {
- final int MARGIN= 3;
- Color fg= gc.getForeground();
- gc.setForeground(canvas.getDisplay().getSystemColor(COLOR));
-
- gc.setLineWidth(1);
- gc.drawLine(r.x + 4, r.y + 12, r.x + 4, r.y + r.height - MARGIN);
- gc.drawLine(r.x + 4, r.y + r.height - MARGIN, r.x + r.width - MARGIN, r.y + r.height - MARGIN);
- gc.setForeground(fg);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationPresentation#paint(org.eclipse.swt.graphics.GC, org.eclipse.swt.widgets.Canvas, org.eclipse.swt.graphics.Rectangle)
- */
- public void paint(GC gc, Canvas canvas, Rectangle rectangle) {
- Image image= getImage(canvas.getDisplay());
- if (image != null) {
- ImageUtilities.drawImage(image, gc, canvas, rectangle, SWT.CENTER, SWT.TOP);
- if (fIsRangeIndication)
- drawRangeIndication(gc, canvas, rectangle);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer()
- */
- public int getLayer() {
- return IAnnotationPresentation.DEFAULT_LAYER;
- }
-
- private Image getImage(Display display) {
- initializeImages(display);
- return isCollapsed() ? fgCollapsedImage : fgExpandedImage;
- }
-
- private void initializeImages(Display display) {
- if (fgCollapsedImage == null) {
-
- ImageDescriptor descriptor= ImageDescriptor.createFromFile(ProjectionAnnotation.class, "images/collapsed.gif"); //$NON-NLS-1$
- fgCollapsedImage= descriptor.createImage(display);
- descriptor= ImageDescriptor.createFromFile(ProjectionAnnotation.class, "images/expanded.gif"); //$NON-NLS-1$
- fgExpandedImage= descriptor.createImage(display);
-
- display.disposeExec(new DisplayDisposeRunnable());
- }
- }
-
- /**
- * Returns the state of this annotation.
- *
- * @return <code>true</code> if collapsed
- */
- public boolean isCollapsed() {
- return fIsCollapsed;
- }
-
- /**
- * Marks this annotation as being collapsed.
- */
- public void markCollapsed() {
- fIsCollapsed= true;
- }
-
- /**
- * Marks this annotation as being unfolded.
- */
- public void markExpanded() {
- fIsCollapsed= false;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationHover.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationHover.java
deleted file mode 100644
index b26321f7357..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationHover.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import java.util.Iterator;
-
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.resource.JFaceResources;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationHoverExtension;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModelExtension;
-import org.eclipse.jface.text.source.ILineRange;
-import org.eclipse.jface.text.source.ISourceViewer;
-import org.eclipse.jface.text.source.ISourceViewerExtension2;
-import org.eclipse.jface.text.source.LineRange;
-
-/**
- * Annotation hover for projection annotations.
- * <p>
- * Internal class. Do not use. Public for testing purposes only.
- *
- * @since 3.0
- */
-class ProjectionAnnotationHover implements IAnnotationHover, IAnnotationHoverExtension {
-
- private IInformationControlCreator fInformationControlCreator;
-
- /**
- * Sets the hover control creator for this projection annotation hover.
- *
- * @param creator the creator
- */
- public void setHoverControlCreator(IInformationControlCreator creator) {
- fInformationControlCreator= creator;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int)
- */
- public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
- // this is a no-op as semantics is defined by the implementation of the annotation hover extension
- return null;
- }
-
- private int compareRulerLine(Position position, IDocument document, int line) {
- if (position.getOffset() > -1 && position.getLength() > -1) {
- try {
- int startLine= document.getLineOfOffset(position.getOffset());
- if (line == startLine)
- return 1;
- if (startLine <= line && line <= document.getLineOfOffset(position.getOffset() + position.getLength()))
- return 2;
- } catch (BadLocationException x) {
- }
- }
- return 0;
- }
-
- private String getProjectionTextAtLine(ISourceViewer viewer, int line, int numberOfLines) {
-
- IAnnotationModel model= null;
- if (viewer instanceof ISourceViewerExtension2) {
- ISourceViewerExtension2 viewerExtension= (ISourceViewerExtension2) viewer;
- IAnnotationModel visual= viewerExtension.getVisualAnnotationModel();
- if (visual instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension modelExtension= (IAnnotationModelExtension) visual;
- model= modelExtension.getAnnotationModel(ProjectionSupport.PROJECTION);
- }
- }
-
- if (model != null) {
- try {
- IDocument document= viewer.getDocument();
- Iterator e= model.getAnnotationIterator();
- while (e.hasNext()) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
- if (!annotation.isCollapsed())
- continue;
-
- Position position= model.getPosition(annotation);
- if (position == null)
- continue;
-
- if (1 == compareRulerLine(position, document, line))
- return getText(document, position.getOffset(), position.getLength(), numberOfLines);
-
- }
- } catch (BadLocationException x) {
- }
- }
-
- return null;
- }
-
- private String getText(IDocument document, int offset, int length, int numberOfLines) throws BadLocationException {
- int endOffset= offset + length;
-
- try {
- int endLine= document.getLineOfOffset(offset) + Math.max(0, numberOfLines -1);
- IRegion lineInfo= document.getLineInformation(endLine);
- endOffset= Math.min(endOffset, lineInfo.getOffset() + lineInfo.getLength());
- } catch (BadLocationException x) {
- }
-
- return document.get(offset, endOffset - offset);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, org.eclipse.jface.text.source.ILineRange, int)
- */
- public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
- return getProjectionTextAtLine(sourceViewer, lineRange.getStartLine(), visibleLines);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverLineRange(org.eclipse.jface.text.source.ISourceViewer, int)
- */
- public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
- return new LineRange(lineNumber, 1);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#canHandleMouseCursor()
- */
- public boolean canHandleMouseCursor() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverControlCreator()
- */
- public IInformationControlCreator getHoverControlCreator() {
-
- if (fInformationControlCreator != null)
- return fInformationControlCreator;
-
- return new IInformationControlCreator() {
- public IInformationControl createInformationControl(Shell parent) {
- return new SourceViewerInformationControl(parent, JFaceResources.TEXT_FONT);
- }
- };
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java
deleted file mode 100644
index a84eca1e260..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionAnnotationModel.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModel;
-
-
-/**
- * A projection annotation model.
- *
- * @since 3.0
- */
-public class ProjectionAnnotationModel extends AnnotationModel {
-
-
- public ProjectionAnnotationModel() {
- }
-
- /**
- * Changes the state of the given annotation to collapsed. An appropriate
- * annotation model change event is sent out.
- *
- * @param annotation the annotation
- */
- public void collapse(Annotation annotation) {
- if (annotation instanceof ProjectionAnnotation) {
- ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
- if (!projection.isCollapsed()) {
- projection.markCollapsed();
- modifyAnnotation(projection, true);
- }
- }
- }
-
- /**
- * Changes the state of the given annotation to expanded. An appropriate
- * annotation model change event is sent out.
- *
- * @param annotation the annotation
- */
- public void expand(Annotation annotation) {
- if (annotation instanceof ProjectionAnnotation) {
- ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
- if (projection.isCollapsed()) {
- projection.markExpanded();
- modifyAnnotation(projection, true);
- }
- }
- }
-
- /**
- * Toggles the expansion state of the given annotation. An appropriate
- * annotation model change event is sent out.
- *
- * @param annotation the annotation
- */
- public void toggleExpansionState(Annotation annotation) {
- if (annotation instanceof ProjectionAnnotation) {
- ProjectionAnnotation projection= (ProjectionAnnotation) annotation;
-
- if (projection.isCollapsed())
- projection.markExpanded();
- else
- projection.markCollapsed();
-
- modifyAnnotation(projection, true);
- }
- }
-
- /**
- * Expands all annotations that overlap with the given range and are collapsed.
- *
- * @param offset the range offset
- * @param length the range length
- * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
- */
- public boolean expandAll(int offset, int length) {
- return expandAll(offset, length, true);
- }
-
- /**
- * Expands all annotations that overlap with the given range and are collapsed. Fires a model change event if
- * requested.
- *
- * @param offset the offset of the range
- * @param length the length of the range
- * @param fireModelChanged <code>true</code> if a model change event
- * should be fired, <code>false</code> otherwise
- * @return <code>true</code> if any annotation has been expanded, <code>false</code> otherwise
- */
- protected boolean expandAll(int offset, int length, boolean fireModelChanged) {
-
- boolean expanding= false;
-
- Iterator iterator= getAnnotationIterator();
- while (iterator.hasNext()) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next();
- if (annotation.isCollapsed()) {
- Position position= getPosition(annotation);
- if (position != null && position.overlapsWith(offset, length) /* || is a delete at the boundary */ ) {
- annotation.markExpanded();
- modifyAnnotation(annotation, false);
- expanding= true;
- }
- }
- }
-
- if (expanding && fireModelChanged)
- fireModelChanged();
-
- return expanding;
- }
-
- /**
- * Modifies the annotation model.
- *
- * @param deletions the list of deleted annotations
- * @param additions the set of annotations to add together with their associated position
- * @param modifications the list of modified annotations
- */
- public void modifyAnnotations(Annotation[] deletions, Map additions, Annotation[] modifications) {
- try {
- replaceAnnotations(deletions, additions, false);
- if (modifications != null) {
- for (int i= 0; i < modifications.length; i++)
- modifyAnnotation(modifications[i], false);
- }
- } catch (BadLocationException x) {
- }
- fireModelChanged();
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java
deleted file mode 100644
index 0f151c8073a..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionRulerColumn.java
+++ /dev/null
@@ -1,224 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-
-import java.util.Iterator;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.AnnotationRulerColumn;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModelExtension;
-
-
-/**
- * A ruler column for controlling the behavior of a
- * <code>ProjectionSourceViewer</code>.
- * <p>
- * Internal class. Do not use. Public only for testing purposes.
- *
- * @since 3.0
- */
-class ProjectionRulerColumn extends AnnotationRulerColumn {
-
- private ProjectionAnnotation fCurrentAnnotation;
-
- /**
- * Creates a new projection ruler column.
- *
- * @param model the column's annotation model
- * @param width the width in pixels
- * @param annotationAccess the annotation access
- */
- public ProjectionRulerColumn(IAnnotationModel model, int width, IAnnotationAccess annotationAccess) {
- super(model, width, annotationAccess);
- }
-
- /**
- * Creates a new projection ruler column.
- *
- * @param width the width in pixels
- * @param annotationAccess the annotation access
- */
- public ProjectionRulerColumn(int width, IAnnotationAccess annotationAccess) {
- super(width, annotationAccess);
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationRulerColumn#mouseClicked(int)
- */
- protected void mouseClicked(int line) {
- clearCurrentAnnotation();
- ProjectionAnnotation annotation= findAnnotation(line, true);
- if (annotation != null) {
- ProjectionAnnotationModel model= (ProjectionAnnotationModel) getModel();
- model.toggleExpansionState(annotation);
- }
- }
-
- /**
- * Returns the projection annotation of the column's annotation
- * model that contains the given line.
- *
- * @param line the line
- * @return the projection annotation containing the given line
- */
- private ProjectionAnnotation findAnnotation(int line, boolean exact) {
-
- ProjectionAnnotation previousAnnotation= null;
-
- IAnnotationModel model= getModel();
- if (model != null) {
- IDocument document= getCachedTextViewer().getDocument();
-
- int previousDistance= Integer.MAX_VALUE;
-
- Iterator e= model.getAnnotationIterator();
- while (e.hasNext()) {
- Object next= e.next();
- if (next instanceof ProjectionAnnotation) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) next;
- Position p= model.getPosition(annotation);
- if (p == null)
- continue;
-
- int distance= getDistance(p, document, line);
- if (distance == -1)
- continue;
-
- if (!exact) {
- if (distance < previousDistance) {
- previousAnnotation= annotation;
- previousDistance= distance;
- }
- } else if (distance == 0) {
- previousAnnotation= annotation;
- }
- }
- }
- }
-
- return previousAnnotation;
- }
-
- /**
- * Returns the distance of the given line to the the start line of the given position in the given document. The distance is
- * <code>-1</code> when the line is not included in the given position.
- *
- * @param position the position
- * @param document the document
- * @param line the line
- * @return <code>-1</code> if line is not contained, a position number otherwise
- */
- private int getDistance(Position position, IDocument document, int line) {
- if (position.getOffset() > -1 && position.getLength() > -1) {
- try {
- int startLine= document.getLineOfOffset(position.getOffset());
- int endLine= document.getLineOfOffset(position.getOffset() + position.getLength());
- if (startLine <= line && line < endLine)
- return line - startLine;
- } catch (BadLocationException x) {
- }
- }
- return -1;
- }
-
- private boolean clearCurrentAnnotation() {
- if (fCurrentAnnotation != null) {
- fCurrentAnnotation.setRangeIndication(false);
- fCurrentAnnotation= null;
- return true;
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerColumn#createControl(org.eclipse.jface.text.source.CompositeRuler, org.eclipse.swt.widgets.Composite)
- */
- public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
- Control control= super.createControl(parentRuler, parentControl);
-
- // set background
- Display display= parentControl.getDisplay();
- Color background= display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- control.setBackground(background);
-
- // install hover listener
- control.addMouseTrackListener(new MouseTrackAdapter() {
- public void mouseExit(MouseEvent e) {
- if (clearCurrentAnnotation())
- redraw();
- }
- });
-
- // install mouse move listener
- control.addMouseMoveListener(new MouseMoveListener() {
- public void mouseMove(MouseEvent e) {
- boolean redraw= false;
- ProjectionAnnotation annotation= findAnnotation(toDocumentLineNumber(e.y), false);
- if (annotation != fCurrentAnnotation) {
- if (fCurrentAnnotation != null) {
- fCurrentAnnotation.setRangeIndication(false);
- redraw= true;
- }
- fCurrentAnnotation= annotation;
- if (fCurrentAnnotation != null && !fCurrentAnnotation.isCollapsed()) {
- fCurrentAnnotation.setRangeIndication(true);
- redraw= true;
- }
- }
- if (redraw)
- redraw();
- }
- });
- return control;
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationRulerColumn#setModel(org.eclipse.jface.text.source.IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
- model= extension.getAnnotationModel(ProjectionSupport.PROJECTION);
- }
- super.setModel(model);
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationRulerColumn#isDelegatingToParentRuler()
- * @since 3.0
- */
- protected boolean isPropagatingMouseListener() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationRulerColumn#hasLineAnnotations(int)
- * @since 3.0
- */
- protected boolean hasAnnotation(int lineNumber) {
- return findAnnotation(lineNumber, true) != null;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java
deleted file mode 100644
index e1d35dea7da..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSummary.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ISynchronizable;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.IAnnotationAccessExtension;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModelExtension;
-
-/**
- * Strategy for managing annotation summaries for collapsed ranges.
- *
- * @since 3.0
- */
-class ProjectionSummary {
-
- private class Summarizer extends Thread {
-
- private boolean fReset= true;
-
- public Summarizer(IProgressMonitor monitor) {
- fProgressMonitor= monitor;
- setDaemon(true);
- start();
- }
-
- public void reset() {
- fReset= true;
- }
-
- /*
- * @see java.lang.Thread#run()
- */
- public void run() {
- while (true) {
- synchronized (fLock) {
- if (!fReset)
- break;
- fReset= false;
- }
- internalUpdateSummaries(fProgressMonitor);
- }
-
- synchronized (fLock) {
- fSummarizer= null;
- }
- }
- }
-
-
- private ProjectionViewer fProjectionViewer;
- private IAnnotationModel fAnnotationModel;
- private IAnnotationAccess fAnnotationAccess;
- private List fConfiguredAnnotationTypes;
-
- private Object fLock= new Object();
- private IProgressMonitor fProgressMonitor;
- private volatile Summarizer fSummarizer;
-
-
- public ProjectionSummary(ProjectionViewer projectionViewer, IAnnotationAccess annotationAccess) {
- super();
- fProjectionViewer= projectionViewer;
- fAnnotationAccess= annotationAccess;
- }
-
- public void addAnnotationType(String annotationType) {
- synchronized(fLock) {
- if (fConfiguredAnnotationTypes == null) {
- fConfiguredAnnotationTypes= new ArrayList();
- fConfiguredAnnotationTypes.add(annotationType);
- } else if (!fConfiguredAnnotationTypes.contains(annotationType))
- fConfiguredAnnotationTypes.add(annotationType);
- }
- }
-
- public void removeAnnotationType(String annotationType) {
- synchronized (fLock) {
- if (fConfiguredAnnotationTypes != null) {
- fConfiguredAnnotationTypes.remove(annotationType);
- if (fConfiguredAnnotationTypes.size() == 0)
- fConfiguredAnnotationTypes= null;
- }
- }
- }
-
- public void updateSummaries(IProgressMonitor monitor) {
- synchronized (fLock) {
- if (fConfiguredAnnotationTypes != null) {
- if (fSummarizer == null)
- fSummarizer= new Summarizer(monitor);
- fSummarizer.reset();
- }
- }
- }
-
- private void internalUpdateSummaries(IProgressMonitor monitor) {
-
- Object previousLockObject= null;
- fAnnotationModel= fProjectionViewer.getVisualAnnotationModel();
- if (fAnnotationModel == null)
- return;
-
- try {
-
-
- IDocument document= fProjectionViewer.getDocument();
- if (document instanceof ISynchronizable && fAnnotationModel instanceof ISynchronizable) {
- ISynchronizable sync= (ISynchronizable) fAnnotationModel;
- previousLockObject= sync.getLockObject();
- sync.setLockObject(((ISynchronizable) document).getLockObject());
- }
-
-
- removeSummaries(monitor);
- createSummaries(monitor);
-
- } finally {
-
- if (fAnnotationModel instanceof ISynchronizable) {
- ISynchronizable sync= (ISynchronizable) fAnnotationModel;
- sync.setLockObject(previousLockObject);
- }
- fAnnotationModel= null;
-
- }
- }
-
- private boolean isCanceled(IProgressMonitor monitor) {
- return monitor != null && monitor.isCanceled();
- }
-
- private void removeSummaries(IProgressMonitor monitor) {
- IAnnotationModelExtension extension= null;
- List bags= null;
-
- if (fAnnotationModel instanceof IAnnotationModelExtension) {
- extension= (IAnnotationModelExtension) fAnnotationModel;
- bags= new ArrayList();
- }
-
- Iterator e= fAnnotationModel.getAnnotationIterator();
- while (e.hasNext()) {
- Annotation annotation= (Annotation) e.next();
- if (annotation instanceof AnnotationBag) {
- if (bags == null)
- fAnnotationModel.removeAnnotation(annotation);
- else
- bags.add(annotation);
- }
-
- if (isCanceled(monitor))
- return;
- }
-
- if (bags != null && bags.size() > 0) {
- Annotation[] deletions= new Annotation[bags.size()];
- bags.toArray(deletions);
- if (!isCanceled(monitor))
- extension.replaceAnnotations(deletions, null);
- }
- }
-
- private void createSummaries(IProgressMonitor monitor) {
- ProjectionAnnotationModel model= fProjectionViewer.getProjectionAnnotationModel();
- if (model == null)
- return;
-
- Map additions= new HashMap();
-
- Iterator e= model.getAnnotationIterator();
- while (e.hasNext()) {
- ProjectionAnnotation projection= (ProjectionAnnotation) e.next();
- if (projection.isCollapsed()) {
- Position position= model.getPosition(projection);
- if (position != null) {
- IRegion summaryRegion= fProjectionViewer.computeCollapsedRegion(position);
- if (summaryRegion != null) {
- Position summaryAnchor= fProjectionViewer.computeCollapsedRegionAnchor(position);
- if (summaryAnchor != null)
- createSummary(additions, summaryRegion, summaryAnchor);
- }
- }
- }
-
- if (isCanceled(monitor))
- return;
- }
-
- if (additions.size() > 0) {
- if (fAnnotationModel instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) fAnnotationModel;
- if (!isCanceled(monitor))
- extension.replaceAnnotations(null, additions);
- } else {
- Iterator e1= additions.keySet().iterator();
- while (e1.hasNext()) {
- AnnotationBag bag= (AnnotationBag) e1.next();
- Position position= (Position) additions.get(bag);
- if (isCanceled(monitor))
- return;
- fAnnotationModel.addAnnotation(bag, position);
- }
- }
- }
- }
-
- private void createSummary(Map additions, IRegion summaryRange, Position summaryAnchor) {
-
- int size= 0;
- Map map= null;
-
- synchronized (fLock) {
- if (fConfiguredAnnotationTypes != null) {
- size= fConfiguredAnnotationTypes.size();
- map= new HashMap();
- for (int i= 0; i < size; i++) {
- String type= (String) fConfiguredAnnotationTypes.get(i);
- map.put(type, new AnnotationBag(type));
- }
- }
- }
-
- if (map == null)
- return;
-
- IAnnotationModel model= fProjectionViewer.getAnnotationModel();
- Iterator e= model.getAnnotationIterator();
- while (e.hasNext()) {
- Annotation annotation= (Annotation) e.next();
- AnnotationBag bag= findBagForType(map, annotation.getType());
- if (bag != null) {
- Position position= model.getPosition(annotation);
- if (includes(summaryRange, position))
- bag.add(annotation);
- }
- }
-
- for (int i= 0; i < size; i++) {
- AnnotationBag bag= (AnnotationBag) map.get(fConfiguredAnnotationTypes.get(i));
- if (!bag.isEmpty())
- additions.put(bag, new Position(summaryAnchor.getOffset(), summaryAnchor.getLength()));
- }
- }
-
- private AnnotationBag findBagForType(Map bagMap, String annotationType) {
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- Object[] superTypes= extension.getSupertypes(annotationType);
- for (int i= 0; i < superTypes.length; i++) {
- AnnotationBag bag= (AnnotationBag) bagMap.get(superTypes[i]);
- if (bag != null)
- return bag;
- }
- }
- return null;
- }
-
- private boolean includes(IRegion range, Position position) {
- if (position != null && !position.isDeleted())
- return range.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= range.getOffset() + range.getLength();
- return false;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSupport.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSupport.java
deleted file mode 100644
index 0186418bdd1..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionSupport.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.StyledTextContent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationPainter;
-import org.eclipse.jface.text.source.IAnnotationAccess;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.ISharedTextColors;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * Supports the configuration of projection capabilities for projection viewers.
- *
- * @since 3.0
- */
-public class ProjectionSupport {
-
- /**
- * Key of the projection annotation model inside the visual annotation
- * model. Also internally used as key for the projection drawing strategy.
- */
- public final static Object PROJECTION= new Object();
-
- private static class ProjectionAnnotationsPainter extends AnnotationPainter {
- public ProjectionAnnotationsPainter(ISourceViewer sourceViewer, IAnnotationAccess access) {
- super(sourceViewer, access);
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationPainter#findAnnotationModel(org.eclipse.jface.text.source.ISourceViewer)
- */
- protected IAnnotationModel findAnnotationModel(ISourceViewer sourceViewer) {
- if (sourceViewer instanceof ProjectionViewer) {
- ProjectionViewer projectionViewer= (ProjectionViewer) sourceViewer;
- return projectionViewer.getProjectionAnnotationModel();
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationPainter#skip(org.eclipse.jface.text.source.Annotation)
- */
- protected boolean skip(Annotation annotation) {
- if (annotation instanceof ProjectionAnnotation)
- return !((ProjectionAnnotation) annotation).isCollapsed();
-
- return super.skip(annotation);
- }
- }
-
- private static class ProjectionDrawingStrategy implements AnnotationPainter.IDrawingStrategy {
- /*
- * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color)
- */
- public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
- if (annotation instanceof ProjectionAnnotation) {
- ProjectionAnnotation projectionAnnotation= (ProjectionAnnotation) annotation;
- if (projectionAnnotation.isCollapsed()) {
-
- if (gc != null) {
-
- StyledTextContent content= textWidget.getContent();
- int line= content.getLineAtOffset(offset);
- int lineStart= content.getOffsetAtLine(line);
- String text= content.getLine(line);
- int lineLength= text == null ? 0 : text.length();
- int lineEnd= lineStart + lineLength;
- Point p= textWidget.getLocationAtOffset(lineEnd);
-
- Color c= gc.getForeground();
- gc.setForeground(color);
-
- FontMetrics metrics= gc.getFontMetrics();
-
- // baseline: where the dots are drawn
- int baseline= textWidget.getBaseline();
- // descent: number of pixels that the box extends over baseline
- int descent= Math.min(2, textWidget.getLineHeight() - baseline);
- // ascent: so much does the box stand up from baseline
- int ascent= metrics.getAscent();
- // leading: free space from line top to box upper line
- int leading= baseline - ascent;
- // height: height of the box
- int height= ascent + descent;
-
- int width= metrics.getAverageCharWidth();
- gc.drawRectangle(p.x, p.y + leading, width, height);
- int third= width/3;
- int dotsVertical= p.y + baseline - 1;
- gc.drawPoint(p.x + third, dotsVertical);
- gc.drawPoint(p.x + width - third, dotsVertical);
-
- gc.setForeground(c);
-
- } else {
- textWidget.redrawRange(offset, length, true);
- }
- }
- }
- }
- }
-
- private class ProjectionListener implements IProjectionListener {
-
- /*
- * @see org.eclipse.jface.text.source.projection.IProjectionListener#projectionEnabled()
- */
- public void projectionEnabled() {
- doEnableProjection();
- }
-
- /*
- * @see org.eclipse.jface.text.source.projection.IProjectionListener#projectionDisabled()
- */
- public void projectionDisabled() {
- doDisableProjection();
- }
- }
-
- private ProjectionViewer fViewer;
- private IAnnotationAccess fAnnotationAccess;
- private ISharedTextColors fSharedTextColors;
- private List fSummarizableTypes;
- private IInformationControlCreator fInformationControlCreator;
- private ProjectionListener fProjectionListener;
- private ProjectionAnnotationsPainter fPainter;
- private ProjectionRulerColumn fColumn;
-
-
- public ProjectionSupport(ProjectionViewer viewer, IAnnotationAccess annotationAccess, ISharedTextColors sharedTextColors) {
- fViewer= viewer;
- fAnnotationAccess= annotationAccess;
- fSharedTextColors= sharedTextColors;
- }
-
- public void addSummarizableAnnotationType(String annotationType) {
- if (fSummarizableTypes == null) {
- fSummarizableTypes= new ArrayList();
- fSummarizableTypes.add(annotationType);
- } else if (!fSummarizableTypes.contains(annotationType))
- fSummarizableTypes.add(annotationType);
- }
-
- public void removeSummarizableAnnotationType(String annotationType) {
- if (fSummarizableTypes != null)
- fSummarizableTypes.remove(annotationType);
- if (fSummarizableTypes.size() == 0)
- fSummarizableTypes= null;
- }
-
- public void setHoverControlCreator(IInformationControlCreator creator) {
- fInformationControlCreator= creator;
- }
-
- public void install() {
- fViewer.setProjectionSummary(createProjectionSummary());
-
- fProjectionListener= new ProjectionListener();
- fViewer.addProjectionListener(fProjectionListener);
- }
-
- public void dispose() {
- if (fProjectionListener != null) {
- fViewer.removeProjectionListener(fProjectionListener);
- fProjectionListener= null;
- }
- }
-
- protected void doEnableProjection() {
-
- if (fPainter == null) {
- fPainter= new ProjectionAnnotationsPainter(fViewer, fAnnotationAccess);
- fPainter.addDrawingStrategy(PROJECTION, new ProjectionDrawingStrategy());
- fPainter.addAnnotationType(ProjectionAnnotation.TYPE, PROJECTION);
- fPainter.setAnnotationTypeColor(ProjectionAnnotation.TYPE, fSharedTextColors.getColor(getColor()));
- fViewer.addPainter(fPainter);
- }
-
- if (fColumn == null) {
- fColumn= new ProjectionRulerColumn(9, fAnnotationAccess);
- fColumn.addAnnotationType(ProjectionAnnotation.TYPE);
- fColumn.setHover(createProjectionAnnotationHover());
- fViewer.addVerticalRulerColumn(fColumn);
- }
-
- fColumn.setModel(fViewer.getVisualAnnotationModel());
- }
-
- protected void doDisableProjection() {
- if (fPainter != null) {
- fViewer.removePainter(fPainter);
- fPainter.dispose();
- fPainter= null;
- }
-
- if (fColumn != null) {
- fViewer.removeVerticalRulerColumn(fColumn);
- fColumn= null;
- }
- }
-
- private ProjectionSummary createProjectionSummary() {
- ProjectionSummary summary= new ProjectionSummary(fViewer, fAnnotationAccess);
- if (fSummarizableTypes != null) {
- int size= fSummarizableTypes.size();
- for (int i= 0; i < size; i++)
- summary.addAnnotationType((String) fSummarizableTypes.get(i));
- }
- return summary;
- }
-
- private IAnnotationHover createProjectionAnnotationHover() {
- ProjectionAnnotationHover hover= new ProjectionAnnotationHover();
- hover.setHoverControlCreator(fInformationControlCreator);
- return hover;
- }
-
- /**
- * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
- */
- public Object getAdapter(ISourceViewer viewer, Class required) {
- if (ProjectionAnnotationModel.class.equals(required)) {
- if (viewer instanceof ProjectionViewer) {
- ProjectionViewer projectionViewer= (ProjectionViewer) viewer;
- return projectionViewer.getProjectionAnnotationModel();
- }
- }
- return null;
- }
-
- private RGB getColor() {
- // TODO read out preference settings
- Color c= Display.getDefault().getSystemColor(SWT.COLOR_DARK_GRAY);
- return c.getRGB();
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java
deleted file mode 100644
index abc767d6639..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/ProjectionViewer.java
+++ /dev/null
@@ -1,1537 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.runtime.NullProgressMonitor;
-
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.dnd.Clipboard;
-import org.eclipse.swt.dnd.DND;
-import org.eclipse.swt.dnd.TextTransfer;
-import org.eclipse.swt.dnd.Transfer;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Layout;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.FindReplaceDocumentAdapter;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentInformationMappingExtension;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ISlaveDocumentManager;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.projection.ProjectionDocument;
-import org.eclipse.jface.text.projection.ProjectionDocumentEvent;
-import org.eclipse.jface.text.projection.ProjectionDocumentManager;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModelEvent;
-import org.eclipse.jface.text.source.CompositeRuler;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModelExtension;
-import org.eclipse.jface.text.source.IAnnotationModelListener;
-import org.eclipse.jface.text.source.IAnnotationModelListenerExtension;
-import org.eclipse.jface.text.source.IOverviewRuler;
-import org.eclipse.jface.text.source.IVerticalRuler;
-import org.eclipse.jface.text.source.IVerticalRulerColumn;
-import org.eclipse.jface.text.source.SourceViewer;
-
-
-/**
- * A projection source viewer is a source viewer which does not support the
- * concept of a single visible region. Instead it supports multiple visible
- * regions which can dynamically be changed.
- * <p>
- * A projection source viewer uses a <code>ProjectionDocumentManager</code>
- * for the management of the visible document.
- * <p>
- * API in progress. Do not yet use.
- *
- * @since 3.0
- */
-public class ProjectionViewer extends SourceViewer implements ITextViewerExtension5 {
-
- private static final int BASE= INFORMATION; // see ISourceViewer.INFORMATION
-
- /** Operation constant for the expand operation. */
- public static final int EXPAND= BASE + 1;
- /** Operation constant for the collapse operation. */
- public static final int COLLAPSE= BASE + 2;
- /** Operation constant for the toggle projection operation. */
- public static final int TOGGLE= BASE + 3;
- /** Operation constant for the expand all operation. */
- public static final int EXPAND_ALL= BASE + 4;
-
- /**
- * Internal listener to changes of the annotation model.
- */
- private class AnnotationModelListener implements IAnnotationModelListener, IAnnotationModelListenerExtension {
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationModelListener#modelChanged(org.eclipse.jface.text.source.IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- processModelChanged(model, null);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationModelListenerExtension#modelChanged(org.eclipse.jface.text.source.AnnotationModelEvent)
- */
- public void modelChanged(AnnotationModelEvent event) {
- processModelChanged(event.getAnnotationModel(), event);
- }
-
- private void processModelChanged(IAnnotationModel model, AnnotationModelEvent event) {
- if (model == fProjectionAnnotationModel) {
-
- if (fProjectionSummary != null)
- fProjectionSummary.updateSummaries(new NullProgressMonitor());
- processCatchupRequest(event);
-
- } else if (model == getAnnotationModel() && fProjectionSummary != null)
- fProjectionSummary.updateSummaries(new NullProgressMonitor());
- }
- }
-
- /**
- * Executes the 'replaceVisibleDocument' operation when called the first time. Self-destructs afterwards.
- */
- private class ReplaceVisibleDocumentExecutor implements IDocumentListener {
-
- private IDocument fSlaveDocument;
- private IDocument fExecutionTrigger;
-
- public ReplaceVisibleDocumentExecutor(IDocument slaveDocument) {
- fSlaveDocument= slaveDocument;
- }
-
- public void install(IDocument executionTrigger) {
- if (executionTrigger != null && fSlaveDocument != null) {
- fExecutionTrigger= executionTrigger;
- fExecutionTrigger.addDocumentListener(this);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- fExecutionTrigger.removeDocumentListener(this);
- executeReplaceVisibleDocument(fSlaveDocument);
- }
- }
-
- /**
- * A command reifying a change of the projection document. This can be either
- * adding a master document range, removing a master document change, or invalidating
- * the viewer text presentation.
- */
- private static class ProjectionCommand {
-
- final static int ADD= 0;
- final static int REMOVE= 1;
- final static int INVALIDATE_PRESENTATION= 2;
-
- ProjectionDocument fProjection;
- int fType;
- int fOffset;
- int fLength;
-
- ProjectionCommand(ProjectionDocument projection, int type, int offset, int length) {
- fProjection= projection;
- fType= type;
- fOffset= offset;
- fLength= length;
- }
-
- ProjectionCommand(int offset, int length) {
- fType= INVALIDATE_PRESENTATION;
- fOffset= offset;
- fLength= length;
- }
-
- int computeExpectedCosts() {
-
- switch(fType) {
- case ADD: {
- try {
- IRegion[] gaps= fProjection.computeUnprojectedMasterRegions(fOffset, fLength);
- return gaps == null ? 0 : gaps.length;
- } catch (BadLocationException x) {
- }
- break;
- }
- case REMOVE: {
- try {
- IRegion[] fragments= fProjection.computeProjectedMasterRegions(fOffset, fLength);
- return fragments == null ? 0 : fragments.length;
- } catch (BadLocationException x) {
- }
- break;
- }
- }
- return 0;
- }
- }
-
- /**
- * The queue of projection command objects.
- */
- private static class ProjectionCommandQueue {
-
- final static int REDRAW_COSTS= 15;
- final static int INVALIDATION_COSTS= 10;
-
- List fList= new ArrayList(15);
- int fExpectedExecutionCosts= -1;
-
-
- void add(ProjectionCommand command) {
- fList.add(command);
- }
-
- Iterator iterator() {
- return fList.iterator();
- }
-
- void clear() {
- fList.clear();
- fExpectedExecutionCosts= -1;
- }
-
- boolean passedRedrawCostsThreshold() {
- if (fExpectedExecutionCosts == -1)
- computeExpectedExecutionCosts();
- return fExpectedExecutionCosts > REDRAW_COSTS;
- }
-
- boolean passedInvalidationCostsThreshold() {
- if (fExpectedExecutionCosts == -1)
- computeExpectedExecutionCosts();
- return fExpectedExecutionCosts > INVALIDATION_COSTS;
- }
-
- private void computeExpectedExecutionCosts() {
- int max_costs= Math.max(REDRAW_COSTS, INVALIDATION_COSTS);
- fExpectedExecutionCosts= fList.size();
- if (fExpectedExecutionCosts <= max_costs) {
- ProjectionCommand command;
- Iterator e= fList.iterator();
- while (e.hasNext()) {
- command= (ProjectionCommand) e.next();
- fExpectedExecutionCosts += command.computeExpectedCosts();
- if (fExpectedExecutionCosts > max_costs)
- break;
- }
- }
- }
- }
-
- /** The projection annotation model used by this viewer. */
- private ProjectionAnnotationModel fProjectionAnnotationModel;
- /** The annotation model listener */
- private IAnnotationModelListener fAnnotationModelListener= new AnnotationModelListener();
- /** The projection summary. */
- private ProjectionSummary fProjectionSummary;
- /** Indication that an annotation world change has not yet been processed. */
- private boolean fPendingAnnotationWorldChange= false;
- /** Indication whether projection changes in the visible document should be considered. */
- private boolean fHandleProjectionChanges= true;
- /** The list of projection listeners. */
- private List fProjectionListeners;
- /** Internal lock for protecting the list of pending requests */
- private Object fLock= new Object();
- /** The list of pending requests */
- private List fPendingRequests= new ArrayList();
- /** The replace-visible-document execution trigger */
- private IDocument fReplaceVisibleDocumentExecutionTrigger;
- /** <code>true</code> if projection was on the last time we switched to segmented mode. */
- private boolean fWasProjectionEnabled;
- /** The queue of projection commands used to assess the costs of projection changes. */
- private ProjectionCommandQueue fCommandQueue;
-
-
- /**
- * Creates a new projection source viewer.
- *
- * @param parent the SWT parent control
- * @param ruler the vertical ruler
- * @param overviewRuler the overview ruler
- * @param showsAnnotationOverview <code>true</code> if the overview ruler should be shown
- * @param styles the SWT style bits
- */
- public ProjectionViewer(Composite parent, IVerticalRuler ruler, IOverviewRuler overviewRuler, boolean showsAnnotationOverview, int styles) {
- super(parent, ruler, overviewRuler, showsAnnotationOverview, styles);
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#createLayout()
- */
- protected Layout createLayout() {
- return new RulerLayout(1);
- }
-
- /**
- * Sets the projection summary for this viewer.
- *
- * @param projectionSummary the projection summary.
- */
- public void setProjectionSummary(ProjectionSummary projectionSummary) {
- fProjectionSummary= projectionSummary;
- }
-
- /**
- * Adds the projection annotation model to the given annotation model.
- *
- * @param model the model to which the projection annotation model is added
- */
- private void addProjectionAnnotationModel(IAnnotationModel model) {
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
- extension.addAnnotationModel(ProjectionSupport.PROJECTION, fProjectionAnnotationModel);
- model.addAnnotationModelListener(fAnnotationModelListener);
- }
- }
-
- /**
- * Removes the projection annotation model from the given annotation model.
- *
- * @param model the mode from which the projection annotation model is removed
- */
- private IAnnotationModel removeProjectionAnnotationModel(IAnnotationModel model) {
- if (model instanceof IAnnotationModelExtension) {
- model.removeAnnotationModelListener(fAnnotationModelListener);
- IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
- return extension.removeAnnotationModel(ProjectionSupport.PROJECTION);
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#setDocument(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.source.IAnnotationModel, int, int)
- */
- public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) {
- boolean wasProjectionEnabled= false;
-
- synchronized (fLock) {
- fPendingRequests.clear();
- }
-
- if (fProjectionAnnotationModel != null) {
- wasProjectionEnabled= removeProjectionAnnotationModel(getVisualAnnotationModel()) != null;
- fProjectionAnnotationModel= null;
- }
-
- super.setDocument(document, annotationModel, modelRangeOffset, modelRangeLength);
-
- if (wasProjectionEnabled)
- enableProjection();
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#createVisualAnnotationModel(org.eclipse.jface.text.source.IAnnotationModel)
- */
- protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) {
- IAnnotationModel model= super.createVisualAnnotationModel(annotationModel);
- fProjectionAnnotationModel= new ProjectionAnnotationModel();
- return model;
- }
-
- /**
- * Returns the projection annotation model.
- *
- * @return the projection annotation model
- */
- public ProjectionAnnotationModel getProjectionAnnotationModel() {
- IAnnotationModel model= getVisualAnnotationModel();
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) model;
- return (ProjectionAnnotationModel) extension.getAnnotationModel(ProjectionSupport.PROJECTION);
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#createSlaveDocumentManager()
- */
- protected ISlaveDocumentManager createSlaveDocumentManager() {
- return new ProjectionDocumentManager();
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#updateSlaveDocument(org.eclipse.jface.text.IDocument, int, int)
- */
- protected boolean updateSlaveDocument(IDocument slaveDocument, int modelRangeOffset, int modelRangeLength) throws BadLocationException {
- if (slaveDocument instanceof ProjectionDocument) {
- ProjectionDocument projection= (ProjectionDocument) slaveDocument;
-
- int offset= modelRangeOffset;
- int length= modelRangeLength;
-
- if (!isProjectionMode()) {
- // mimic original TextViewer behavior
- IDocument master= projection.getMasterDocument();
- int line= master.getLineOfOffset(modelRangeOffset);
- offset= master.getLineOffset(line);
- length= (modelRangeOffset - offset) + modelRangeLength;
-
- }
-
- try {
- fHandleProjectionChanges= false;
- projection.replaceMasterDocumentRanges(offset, length);
- } finally {
- fHandleProjectionChanges= true;
- }
- return true;
- }
- return false;
- }
-
- public void addProjectionListener(IProjectionListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fProjectionListeners == null)
- fProjectionListeners= new ArrayList();
-
- if (!fProjectionListeners.contains(listener))
- fProjectionListeners.add(listener);
- }
-
- public void removeProjectionListener(IProjectionListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fProjectionListeners != null) {
- fProjectionListeners.remove(listener);
- if (fProjectionListeners.size() == 0)
- fProjectionListeners= null;
- }
- }
-
- protected void fireProjectionEnabled() {
- if (fProjectionListeners != null) {
- Iterator e= new ArrayList(fProjectionListeners).iterator();
- while (e.hasNext()) {
- IProjectionListener l= (IProjectionListener) e.next();
- l.projectionEnabled();
- }
- }
- }
-
- protected void fireProjectionDisabled() {
- if (fProjectionListeners != null) {
- Iterator e= new ArrayList(fProjectionListeners).iterator();
- while (e.hasNext()) {
- IProjectionListener l= (IProjectionListener) e.next();
- l.projectionDisabled();
- }
- }
- }
-
- /**
- * Returns whether this viewer is in projection mode.
- *
- * @return <code>true</code> if this viewer is in projection mode,
- * <code>false</code> otherwise
- */
- public final boolean isProjectionMode() {
- return getProjectionAnnotationModel() != null;
- }
-
- /**
- * Disables the projection mode.
- */
- public final void disableProjection() {
- if (isProjectionMode()) {
- removeProjectionAnnotationModel(getVisualAnnotationModel());
- fProjectionAnnotationModel.removeAllAnnotations();
- fFindReplaceDocumentAdapter= null;
- fireProjectionDisabled();
- }
- }
-
- /**
- * Enables the projection mode.
- */
- public final void enableProjection() {
- if (!isProjectionMode()) {
- addProjectionAnnotationModel(getVisualAnnotationModel());
- fFindReplaceDocumentAdapter= null;
- fireProjectionEnabled();
- }
- }
-
- private void expandAll() {
- int offset= 0;
- IDocument doc= getDocument();
- int length= doc == null ? 0 : doc.getLength();
- if (isProjectionMode()) {
- fProjectionAnnotationModel.expandAll(offset, length);
- }
- }
-
- private void expand() {
- if (isProjectionMode()) {
- Position found= null;
- Annotation bestMatch= null;
- Point selection= getSelectedRange();
- for (Iterator e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
- if (annotation.isCollapsed()) {
- Position position= fProjectionAnnotationModel.getPosition(annotation);
- // take the first most fine grained match
- if (position != null && touches(selection, position))
- if (found == null || position.includes(found.offset) && position.includes(found.offset + found.length)) {
- found= position;
- bestMatch= annotation;
- }
- }
- }
-
- if (bestMatch != null)
- fProjectionAnnotationModel.expand(bestMatch);
- }
- }
-
- private boolean touches(Point selection, Position position) {
- return position.overlapsWith(selection.x, selection.y) || selection.y == 0 && position.offset + position.length == selection.x + selection.y;
- }
-
- private void collapse() {
- if (isProjectionMode()) {
- Position found= null;
- Annotation bestMatch= null;
- Point selection= getSelectedRange();
- for (Iterator e= fProjectionAnnotationModel.getAnnotationIterator(); e.hasNext();) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
- if (!annotation.isCollapsed()) {
- Position position= fProjectionAnnotationModel.getPosition(annotation);
- // take the first most fine grained match
- if (position != null && touches(selection, position))
- if (found == null || found.includes(position.offset) && found.includes(position.offset + position.length)) {
- found= position;
- bestMatch= annotation;
- }
- }
- }
-
- if (bestMatch != null)
- fProjectionAnnotationModel.collapse(bestMatch);
- }
- }
-
- /**
- * Remembers whether to listen to projection changes of the visible
- * document.
- *
- * @see ProjectionDocument#addMasterDocumentRange(int, int)
- */
- private void addMasterDocumentRange(ProjectionDocument projection, int offset, int length) throws BadLocationException {
-
- if (fCommandQueue != null) {
- fCommandQueue.add(new ProjectionCommand(projection, ProjectionCommand.ADD, offset, length));
- } else {
- try {
- fHandleProjectionChanges= false;
- projection.addMasterDocumentRange(offset, length);
- } finally {
- fHandleProjectionChanges= true;
- }
- }
- }
-
- /**
- * Remembers whether to listen to projection changes of the visible
- * document.
- *
- * @see ProjectionDocument#removeMasterDocumentRange(int, int)
- */
- private void removeMasterDocumentRange(ProjectionDocument projection, int offset, int length) throws BadLocationException {
- if (fCommandQueue != null) {
- fCommandQueue.add(new ProjectionCommand(projection, ProjectionCommand.REMOVE, offset, length));
- } else {
- try {
- fHandleProjectionChanges= false;
- projection.removeMasterDocumentRange(offset, length);
- } finally {
- fHandleProjectionChanges= true;
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#setVisibleRegion(int, int)
- */
- public void setVisibleRegion(int start, int length) {
- if (!isSegmented())
- fWasProjectionEnabled= isProjectionMode();
- disableProjection();
- super.setVisibleRegion(start, length);
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#setVisibleDocument(org.eclipse.jface.text.IDocument)
- */
- protected void setVisibleDocument(IDocument document) {
- if (!isProjectionMode()) {
- super.setVisibleDocument(document);
- return;
- }
-
- // In projection mode we don't want to throw away the find/replace document adapter
- FindReplaceDocumentAdapter adapter= fFindReplaceDocumentAdapter;
- super.setVisibleDocument(document);
- fFindReplaceDocumentAdapter= adapter;
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#resetVisibleRegion()
- */
- public void resetVisibleRegion() {
- super.resetVisibleRegion();
- if (fWasProjectionEnabled)
- enableProjection();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewer#getVisibleRegion()
- */
- public IRegion getVisibleRegion() {
- disableProjection();
- IRegion visibleRegion= getModelCoverage();
- if (visibleRegion == null)
- visibleRegion= new Region(0, 0);
-
- return visibleRegion;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewer#overlapsWithVisibleRegion(int,int)
- */
- public boolean overlapsWithVisibleRegion(int offset, int length) {
- disableProjection();
- IRegion coverage= getModelCoverage();
- if (coverage == null)
- return false;
-
- boolean appending= (offset == coverage.getOffset() + coverage.getLength()) && length == 0;
- return appending || TextUtilities.overlaps(coverage, new Region(offset, length));
- }
-
- /**
- * Replace the visible document with the given document. Maintains the
- * scroll offset and the selection.
- *
- * @param visibleDocument the visible document
- */
- private void replaceVisibleDocument(IDocument slave) {
- if (fReplaceVisibleDocumentExecutionTrigger != null) {
- ReplaceVisibleDocumentExecutor executor= new ReplaceVisibleDocumentExecutor(slave);
- executor.install(fReplaceVisibleDocumentExecutionTrigger);
- } else
- executeReplaceVisibleDocument(slave);
- }
-
-
- private void executeReplaceVisibleDocument(IDocument visibleDocument) {
- StyledText textWidget= getTextWidget();
- try {
- if (textWidget != null && !textWidget.isDisposed())
- textWidget.setRedraw(false);
-
- int topIndex= getTopIndex();
- Point selection= getSelectedRange();
- setVisibleDocument(visibleDocument);
- setSelectedRange(selection.x, selection.y);
- setTopIndex(topIndex);
-
- } finally {
- if (textWidget != null && !textWidget.isDisposed())
- textWidget.setRedraw(true);
- }
- }
-
- /**
- * Hides the given range by collapsing it. If requested, a redraw request is issued.
- *
- * @param offset the offset of the range to hide
- * @param length the length of the range to hide
- * @param fireRedraw <code>true</code> if a redraw request should be issued, <code>false</code> otherwise
- * @throws BadLocationException in case the range is invalid
- */
- private void collapse(int offset, int length, boolean fireRedraw) throws BadLocationException {
- ProjectionDocument projection= null;
-
- IDocument visibleDocument= getVisibleDocument();
- if (visibleDocument instanceof ProjectionDocument)
- projection= (ProjectionDocument) visibleDocument;
- else {
- IDocument master= getDocument();
- IDocument slave= createSlaveDocument(getDocument());
- if (slave instanceof ProjectionDocument) {
- projection= (ProjectionDocument) slave;
- addMasterDocumentRange(projection, 0, master.getLength());
- replaceVisibleDocument(projection);
- }
- }
-
- if (projection != null)
- removeMasterDocumentRange(projection, offset, length);
-
- if (projection != null && fireRedraw) {
- // repaint line above
- IDocument document= getDocument();
- int line= document.getLineOfOffset(offset);
- if (line > 0) {
- IRegion info= document.getLineInformation(line - 1);
- internalInvalidateTextPresentation(info.getOffset(), info.getLength());
- }
- }
- }
-
- /**
- * Makes the given range visible again while keeping the given collapsed
- * ranges. If requested, a redraw request is issued.
- *
- * @param expanded the range to be expanded
- * @param collapsed a sequence of collapsed ranges completely contained by
- * the expanded range
- * @param fireRedraw <code>true</code> if a redraw request should be
- * issued, <code>false</code> otherwise
- * @throws BadLocationException in case the range is invalid
- */
- private void expand(Position expanded, Position[] collapsed, boolean fireRedraw) throws BadLocationException {
- IDocument slave= getVisibleDocument();
- if (slave instanceof ProjectionDocument) {
- ProjectionDocument projection= (ProjectionDocument) slave;
-
- // expand
- addMasterDocumentRange(projection, expanded.getOffset(), expanded.getLength());
-
- // collapse contained regions
- if (collapsed != null) {
- for (int i= 0; i < collapsed.length; i++) {
- IRegion p= computeCollapsedRegion(collapsed[i]);
- removeMasterDocumentRange(projection, p.getOffset(), p.getLength());
- }
- }
- }
- }
-
- /**
- * Processes the request for catch up with the annotation model in the UI thread. If the current
- * thread is not the UI thread or there are pending catch up requests, a new request is posted.
- *
- * @param event the annotation model event
- */
- protected final void processCatchupRequest(AnnotationModelEvent event) {
- if (Display.getCurrent() != null) {
- boolean run= false;
- synchronized (fLock) {
- run= fPendingRequests.isEmpty();
- }
- if (run) {
-
- try {
- catchupWithProjectionAnnotationModel(event);
- } catch (BadLocationException x) {
- throw new IllegalArgumentException();
- }
-
- } else
- postCatchupRequest(event);
- } else {
- postCatchupRequest(event);
- }
- }
-
- /**
- * Posts the request for catch up with the annotation model into the UI thread.
- *
- * @param event the annotation model event
- */
- protected final void postCatchupRequest(final AnnotationModelEvent event) {
- synchronized (fLock) {
- fPendingRequests.add(event);
- if (fPendingRequests.size() == 1) {
- StyledText widget= getTextWidget();
- if (widget != null) {
- Display display= widget.getDisplay();
- if (display != null) {
- display.asyncExec(new Runnable() {
- public void run() {
- try {
- while (true) {
- AnnotationModelEvent ame= null;
- synchronized (fLock) {
- if (fPendingRequests.size() == 0)
- return;
- ame= (AnnotationModelEvent) fPendingRequests.remove(0);
- }
- catchupWithProjectionAnnotationModel(ame);
- }
- } catch (BadLocationException x) {
- try {
- catchupWithProjectionAnnotationModel(null);
- } catch (BadLocationException x1) {
- throw new IllegalArgumentException();
- } finally {
- synchronized (fLock) {
- fPendingRequests.clear();
- }
- }
- }
- }
- });
- }
- }
- }
- }
- }
-
- /**
- * Adapts the slave visual document of this viewer to the changes described
- * in the annotation model event. When the event is <code>null</code>,
- * this is identical to a world change event.
- *
- * @param event the annotation model event or <code>null</code>
- * @exception BadLocationException in case the annotation model event is no longer in sync with the document
- */
- private void catchupWithProjectionAnnotationModel(AnnotationModelEvent event) throws BadLocationException {
- if (event == null) {
-
- fPendingAnnotationWorldChange= false;
- reinitializeProjection();
-
- } else if (event.isWorldChange()) {
-
- if (event.isValid()) {
- fPendingAnnotationWorldChange= false;
- reinitializeProjection();
- } else
- fPendingAnnotationWorldChange= true;
-
- } else {
-
- if (fPendingAnnotationWorldChange) {
- if (event.isValid()) {
- fPendingAnnotationWorldChange= false;
- reinitializeProjection();
- }
- } else {
-
- Annotation[] addedAnnotations= event.getAddedAnnotations();
- Annotation[] changedAnnotation= event.getChangedAnnotations();
- Annotation[] removedAnnotations= event.getRemovedAnnotations();
-
- fCommandQueue= new ProjectionCommandQueue();
-
- int topIndex= getTopIndex();
-
- processDeletions(event, removedAnnotations, true);
- List coverage= new ArrayList();
- processChanges(addedAnnotations, true, coverage);
- processChanges(changedAnnotation, true, coverage);
-
- ProjectionCommandQueue commandQueue= fCommandQueue;
- fCommandQueue= null;
-
- if (commandQueue.passedRedrawCostsThreshold()) {
-
- setRedraw(false);
- try {
-
- try {
- executeProjectionCommands(commandQueue, false);
- } catch (IllegalArgumentException x) {
- reinitializeProjection();
- }
-
- } finally {
- setRedraw(true, topIndex);
- }
-
- } else {
-
- Point selection= getSelectedRange();
- StyledText textWidget= getTextWidget();
-
- try {
- if (textWidget != null && !textWidget.isDisposed())
- textWidget.setRedraw(false);
-
- boolean fireRedraw= !commandQueue.passedInvalidationCostsThreshold();
- try {
- boolean visibleDocumentReplaced= executeProjectionCommands(commandQueue, fireRedraw);
- if (!visibleDocumentReplaced && !fireRedraw)
- invalidateTextPresentation();
- } catch (IllegalArgumentException x) {
- reinitializeProjection();
- }
-
- } finally {
-
- if (selection.x != -1 && selection.y != -1)
- setSelectedRange(selection.x, selection.y);
-
- if (textWidget != null && !textWidget.isDisposed()) {
- if (topIndex != -1)
- setTopIndex(topIndex);
- textWidget.setRedraw(true);
- }
- }
- }
-
- }
-
- }
- }
-
- private boolean executeProjectionCommands(ProjectionCommandQueue commandQueue, boolean fireRedraw) throws BadLocationException {
-
- ProjectionCommand command;
- Iterator e= commandQueue.iterator();
- while (e.hasNext()) {
- command= (ProjectionCommand) e.next();
- switch (command.fType) {
- case ProjectionCommand.ADD:
- addMasterDocumentRange(command.fProjection, command.fOffset, command.fLength);
- break;
- case ProjectionCommand.REMOVE:
- removeMasterDocumentRange(command.fProjection, command.fOffset, command.fLength);
- break;
- case ProjectionCommand.INVALIDATE_PRESENTATION:
- if (fireRedraw)
- invalidateTextPresentation(command.fOffset, command.fLength);
- break;
- }
- }
-
- commandQueue.clear();
-
- IDocument master= getDocument();
- IDocument slave= getVisibleDocument();
- if (slave instanceof ProjectionDocument && slave.getLength() == master.getLength()) {
- replaceVisibleDocument(master);
- return true;
- }
- return false;
- }
-
- private boolean covers(Position expanded, Position position) {
- if (!expanded.equals(position) && !position.isDeleted())
- return expanded.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= expanded.getOffset() + expanded.getLength();
- return false;
- }
-
- private Position[] computeCollapsedRanges(Position expanded) {
- List positions= new ArrayList(5);
- Iterator e= fProjectionAnnotationModel.getAnnotationIterator();
- while (e.hasNext()) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
- if (annotation.isCollapsed()) {
- Position position= fProjectionAnnotationModel.getPosition(annotation);
- if (position == null) {
- // annotation might already be deleted, we will be informed later on about this deletion
- continue;
- }
- if (covers(expanded, position))
- positions.add(position);
- }
- }
-
- if (positions.size() > 0) {
- Position[] result= new Position[positions.size()];
- positions.toArray(result);
- return result;
- }
-
- return null;
- }
-
- private void internalInvalidateTextPresentation(int offset, int length) {
- if (fCommandQueue != null) {
- fCommandQueue.add(new ProjectionCommand(offset, length));
- } else {
- invalidateTextPresentation(offset, length);
- }
- }
-
- /*
- * We pass the removed annotation into this method for performance reasons only. Otherwise, they could be fetch from the event.
- */
- private void processDeletions(AnnotationModelEvent event, Annotation[] removedAnnotations, boolean fireRedraw) throws BadLocationException {
- for (int i= 0; i < removedAnnotations.length; i++) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) removedAnnotations[i];
- if (annotation.isCollapsed()) {
- Position expanded= event.getPositionOfRemovedAnnotation(annotation);
- Position[] collapsed= computeCollapsedRanges(expanded);
- expand(expanded, collapsed, false);
- if (fireRedraw)
- internalInvalidateTextPresentation(expanded.getOffset(), expanded.getLength());
- }
- }
- }
-
- public IRegion computeCollapsedRegion(Position position) {
- try {
- IDocument document= getDocument();
- int line= document.getLineOfOffset(position.getOffset());
- int offset= document.getLineOffset(line + 1);
-
- int length= position.getLength() - (offset - position.getOffset());
- if (length > 0)
- return new Region(offset, length);
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- public Position computeCollapsedRegionAnchor(Position position) {
- try {
- IDocument document= getDocument();
- IRegion lineInfo= document.getLineInformationOfOffset(position.getOffset());
- return new Position(lineInfo.getOffset() + lineInfo.getLength(), 0);
- } catch (BadLocationException x) {
- }
- return null;
- }
-
- private void processChanges(Annotation[] annotations, boolean fireRedraw, List coverage) throws BadLocationException {
- for (int i= 0; i < annotations.length; i++) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) annotations[i];
- Position position= fProjectionAnnotationModel.getPosition(annotation);
-
- if (position == null)
- continue;
-
- if (annotation.isCollapsed()) {
- if (!covers(coverage, position)) {
- coverage.add(position);
- IRegion region= computeCollapsedRegion(position);
- if (region != null)
- collapse(region.getOffset(), region.getLength(), fireRedraw);
- }
- } else {
- if (!covers(coverage, position)) {
- Position[] collapsed= computeCollapsedRanges(position);
- expand(position, collapsed, false);
- if (fireRedraw)
- internalInvalidateTextPresentation(position.getOffset(), position.getLength());
- }
- }
- }
- }
-
- private boolean covers(List coverage, Position position) {
- Iterator e= coverage.iterator();
- while (e.hasNext()) {
- Position p= (Position) e.next();
- if (p.getOffset() <= position.getOffset() && position.getOffset() + position.getLength() <= p.getOffset() + p.getLength())
- return true;
- }
- return false;
- }
-
- public final void reinitializeProjection() throws BadLocationException {
-
- ProjectionDocument projection= null;
-
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- if (manager != null) {
- IDocument master= getDocument();
- if (master != null) {
- IDocument slave= manager.createSlaveDocument(master);
- if (slave instanceof ProjectionDocument) {
- projection= (ProjectionDocument) slave;
- addMasterDocumentRange(projection, 0, master.getLength());
- }
- }
- }
-
- if (projection != null) {
- Iterator e= fProjectionAnnotationModel.getAnnotationIterator();
- while (e.hasNext()) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) e.next();
- if (annotation.isCollapsed()) {
- Position position= fProjectionAnnotationModel.getPosition(annotation);
- if (position != null) {
- IRegion region= computeCollapsedRegion(position);
- if (region != null)
- removeMasterDocumentRange(projection, region.getOffset(), region.getLength());
- }
- }
- }
-
- }
-
- replaceVisibleDocument(projection);
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#handleVerifyEvent(org.eclipse.swt.events.VerifyEvent)
- */
- protected void handleVerifyEvent(VerifyEvent e) {
- IRegion modelRange= event2ModelRange(e);
- if (exposeModelRange(modelRange))
- e.doit= false;
- else
- super.handleVerifyEvent(e);
- }
-
- /**
- * Adds the give column as last column to this viewer's vertical ruler.
- *
- * @param column the column to be added
- */
- public void addVerticalRulerColumn(IVerticalRulerColumn column) {
- IVerticalRuler ruler= getVerticalRuler();
- if (ruler instanceof CompositeRuler) {
- CompositeRuler compositeRuler= (CompositeRuler) ruler;
- compositeRuler.addDecorator(99, column);
- }
- }
-
- /**
- * Removes the give column from this viewer's vertical ruler.
- *
- * @param column the column to be removed
- */
- public void removeVerticalRulerColumn(IVerticalRulerColumn column) {
- IVerticalRuler ruler= getVerticalRuler();
- if (ruler instanceof CompositeRuler) {
- CompositeRuler compositeRuler= (CompositeRuler) ruler;
- compositeRuler.removeDecorator(column);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension5#exposeModelRange(org.eclipse.jface.text.IRegion)
- */
- public boolean exposeModelRange(IRegion modelRange) {
- if (isProjectionMode())
- return fProjectionAnnotationModel.expandAll(modelRange.getOffset(), modelRange.getLength());
-
- if (!overlapsWithVisibleRegion(modelRange.getOffset(), modelRange.getLength())) {
- resetVisibleRegion();
- return true;
- }
-
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#setRangeIndication(int, int, boolean)
- */
- public void setRangeIndication(int offset, int length, boolean moveCursor) {
-
- List expand= new ArrayList(2);
- if (moveCursor) {
-
- // expand the immediate effected collapsed regions
- Iterator iterator= fProjectionAnnotationModel.getAnnotationIterator();
- while (iterator.hasNext()) {
- ProjectionAnnotation annotation= (ProjectionAnnotation) iterator.next();
- if (annotation.isCollapsed() && willAutoExpand(fProjectionAnnotationModel.getPosition(annotation), offset, length))
- expand.add(annotation);
- }
-
- if (!expand.isEmpty()) {
- Iterator e= expand.iterator();
- while (e.hasNext())
- fProjectionAnnotationModel.expand((Annotation) e.next());
- }
- }
-
- super.setRangeIndication(offset, length, moveCursor);
- }
-
- private boolean willAutoExpand(Position position, int offset, int length) {
- if (position == null || position.isDeleted())
- return false;
- // right or left boundary
- if (position.getOffset() == offset || position.getOffset() + position.getLength() == offset + length)
- return true;
- // completely embedded in given position
- if (position.getOffset() < offset && offset + length < position.getOffset() + position.getLength())
- return true;
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#handleDispose()
- * @since 3.0
- */
- protected void handleDispose() {
- fWasProjectionEnabled= false;
- super.handleDispose();
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#handleVisibleDocumentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- protected void handleVisibleDocumentChanged(DocumentEvent event) {
- if (fHandleProjectionChanges && event instanceof ProjectionDocumentEvent && isProjectionMode()) {
- ProjectionDocumentEvent e= (ProjectionDocumentEvent) event;
-
- DocumentEvent master= e.getMasterEvent();
- if (master != null)
- fReplaceVisibleDocumentExecutionTrigger= master.getDocument();
-
- try {
-
- int replaceLength= e.getText() == null ? 0 : e.getText().length();
- if (ProjectionDocumentEvent.PROJECTION_CHANGE == e.getChangeType()) {
- if (e.getLength() == 0 && replaceLength != 0)
- fProjectionAnnotationModel.expandAll(e.getMasterOffset(), e.getMasterLength());
- } else if (master != null && replaceLength > 0 ) {
- try {
- int numberOfLines= e.getDocument().getNumberOfLines(e.getOffset(), replaceLength);
- if (numberOfLines > 1)
- fProjectionAnnotationModel.expandAll(master.getOffset(), master.getLength());
- } catch (BadLocationException x) {
- }
- }
-
- } finally {
- fReplaceVisibleDocumentExecutionTrigger= null;
- }
-
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension5#getCoveredModelRanges(org.eclipse.jface.text.IRegion)
- */
- public IRegion[] getCoveredModelRanges(IRegion modelRange) {
- if (fInformationMapping == null)
- return new IRegion[] { new Region(modelRange.getOffset(), modelRange.getLength()) };
-
- if (fInformationMapping instanceof IDocumentInformationMappingExtension) {
- IDocumentInformationMappingExtension extension= (IDocumentInformationMappingExtension) fInformationMapping;
- try {
- return extension.getExactCoverage(modelRange);
- } catch (BadLocationException x) {
- }
- }
-
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextOperationTarget#doOperation(int)
- */
- public void doOperation(int operation) {
- switch (operation) {
- case TOGGLE:
- if (canDoOperation(TOGGLE)) {
- if (!isProjectionMode()) {
- enableProjection();
- } else {
- expandAll();
- disableProjection();
- }
- return;
- }
- }
-
- if (!isProjectionMode()) {
- super.doOperation(operation);
- return;
- }
-
- StyledText textWidget= getTextWidget();
- if (textWidget == null)
- return;
-
- Point selection= null;
- switch (operation) {
-
- case CUT:
-
- if (redraws()) {
- selection= getSelectedRange();
- if (selection.y == 0)
- copyMarkedRegion(true);
- else
- copyToClipboard(selection.x, selection.y, true, textWidget);
-
- selection= textWidget.getSelectionRange();
- fireSelectionChanged(selection.x, selection.y);
- }
- break;
-
- case COPY:
-
- if (redraws()) {
- selection= getSelectedRange();
- if (selection.y == 0)
- copyMarkedRegion(false);
- else
- copyToClipboard(selection.x, selection.y, false, textWidget);
- }
- break;
-
- case DELETE:
-
- if (redraws()) {
- try {
- selection= getSelectedRange();
- Point widgetSelection= textWidget.getSelectionRange();
- if (selection.y == 0 || selection.y == widgetSelection.y)
- deleteText();
- else
- deleteTextRange(selection.x, selection.y, textWidget);
-
- selection= textWidget.getSelectionRange();
- fireSelectionChanged(selection.x, selection.y);
-
- } catch (BadLocationException x) {
- // ignore
- }
- }
- break;
-
-
- case EXPAND_ALL:
- if (redraws())
- expandAll();
- break;
-
- case EXPAND:
- if (redraws()) {
- expand();
- }
- break;
-
- case COLLAPSE:
- if (redraws()) {
- collapse();
- }
- break;
-
- default:
- super.doOperation(operation);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.SourceViewer#canDoOperation(int)
- */
- public boolean canDoOperation(int operation) {
-
- switch (operation) {
- case COLLAPSE:
- case EXPAND:
- case EXPAND_ALL:
- return isProjectionMode();
- case TOGGLE:
- return !isSegmented();
- }
-
- return super.canDoOperation(operation);
- }
-
- private boolean isSegmented() {
- IDocument document= getDocument();
- int length= document == null ? 0 : document.getLength();
- IRegion visible= getModelCoverage();
- boolean isSegmented= visible != null && !visible.equals(new Region(0, length));
- return isSegmented;
- }
-
- private IRegion getMarkedRegion() {
- if (getTextWidget() == null)
- return null;
-
- if (fMarkPosition == null || fMarkPosition.isDeleted())
- return null;
-
- int start= fMarkPosition.getOffset();
- int end= getSelectedRange().x;
-
- return start > end ? new Region (end, start - end) : new Region(start, end - start);
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#copyMarkedRegion(boolean)
- */
- protected void copyMarkedRegion(boolean delete) {
- IRegion markedRegion= getMarkedRegion();
- if (markedRegion != null)
- copyToClipboard(markedRegion.getOffset(), markedRegion.getLength(), delete, getTextWidget());
- }
-
- private void copyToClipboard(int offset, int length, boolean delete, StyledText textWidget) {
-
- IDocument document= getDocument();
- Clipboard clipboard= new Clipboard(textWidget.getDisplay());
-
- try {
-
- Transfer[] dataTypes= new Transfer[] { TextTransfer.getInstance() };
- Object[] data= new Object[] { document.get(offset, length) };
- try {
- clipboard.setContents(data, dataTypes);
- } catch (SWTError e) {
- if (e.code != DND.ERROR_CANNOT_SET_CLIPBOARD)
- throw e;
- // TODO see https://bugs.eclipse.org/bugs/show_bug.cgi?id=59459
- // we should either log and/or inform the user
- // silently fail for now.
- return;
- }
-
- if (delete)
- deleteTextRange(offset, length, textWidget);
-
- } catch (BadLocationException x) {
- } finally {
- clipboard.dispose();
- }
- }
-
- private void deleteTextRange(int offset, int length, StyledText textWidget) throws BadLocationException {
- getDocument().replace(offset, length, null);
- int widgetCaret= modelOffset2WidgetOffset(offset);
- if (widgetCaret > -1)
- textWidget.setSelection(widgetCaret);
- }
-
- /**
- * Adapts the behavior to line based folding.
- */
- protected Point widgetSelection2ModelSelection(Point widgetSelection) {
-
- if (!isProjectionMode())
- return super.widgetSelection2ModelSelection(widgetSelection);
-
- IRegion modelSelection= widgetRange2ModelRange(new Region(widgetSelection.x, widgetSelection.y));
- if (modelSelection == null)
- return null;
-
- int modelOffset= modelSelection.getOffset();
- int modelLength= modelSelection.getLength();
- if (getVisibleDocument().getLength() == 0)
- modelLength= 0;
-
- int widgetSelectionExclusiveEnd= widgetSelection.x + widgetSelection.y;
- int modelExclusiveEnd= widgetOffset2ModelOffset(widgetSelectionExclusiveEnd);
-
- if (modelOffset + modelLength < modelExclusiveEnd)
- return new Point(modelOffset, modelExclusiveEnd - modelOffset);
-
- if (widgetSelectionExclusiveEnd == getVisibleDocument().getLength() && widgetSelectionExclusiveEnd > 0)
- return new Point(modelOffset, getDocument().getLength() - modelOffset);
-
- return new Point(modelOffset, modelLength);
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#getFindReplaceDocumentAdapter()
- */
- protected FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() {
- if (fFindReplaceDocumentAdapter == null) {
- IDocument document= isProjectionMode() ? getDocument() : getVisibleDocument();
- fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(document);
- }
- return fFindReplaceDocumentAdapter;
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#findAndSelect(int, java.lang.String, boolean, boolean, boolean, boolean)
- */
- protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
-
- if (!isProjectionMode())
- return super.findAndSelect(startPosition, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
-
- StyledText textWidget= getTextWidget();
- if (textWidget == null)
- return -1;
-
- try {
-
- IRegion matchRegion= getFindReplaceDocumentAdapter().find(startPosition, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
- if (matchRegion != null) {
- exposeModelRange(matchRegion);
- setSelectedRange(matchRegion.getOffset(), matchRegion.getLength());
- textWidget.showSelection();
- return matchRegion.getOffset();
- }
-
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#findAndSelectInRange(int, java.lang.String, boolean, boolean, boolean, int, int, boolean)
- */
- protected int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch) {
-
- if (!isProjectionMode())
- return super.findAndSelect(startPosition, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
-
- StyledText textWidget= getTextWidget();
- if (textWidget == null)
- return -1;
-
- try {
-
- int modelOffset= startPosition;
- if (forwardSearch && (startPosition == -1 || startPosition < rangeOffset)) {
- modelOffset= rangeOffset;
- } else if (!forwardSearch && (startPosition == -1 || startPosition > rangeOffset + rangeLength)) {
- modelOffset= rangeOffset + rangeLength;
- }
-
- IRegion matchRegion= getFindReplaceDocumentAdapter().find(modelOffset, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
- if (matchRegion != null) {
- int offset= matchRegion.getOffset();
- int length= matchRegion.getLength();
- if (rangeOffset <= offset && offset + length <= rangeOffset + rangeLength) {
- exposeModelRange(matchRegion);
- setSelectedRange(offset, length);
- textWidget.showSelection();
- return offset;
- }
- }
-
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/SourceViewerInformationControl.java b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/SourceViewerInformationControl.java
deleted file mode 100644
index 37274bafede..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/SourceViewerInformationControl.java
+++ /dev/null
@@ -1,338 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source.projection;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.resource.JFaceResources;
-
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlExtension;
-import org.eclipse.jface.text.source.SourceViewer;
-import org.eclipse.jface.text.source.SourceViewerConfiguration;
-
-/**
- * Source viewer based implementation of <code>IInformationControl</code>.
- * Displays information in a source viewer.
- * <p>
- * Internal class. Do not use. Public only for testing purposes.
- *
- * @since 3.0
- */
-class SourceViewerInformationControl implements IInformationControl, IInformationControlExtension, DisposeListener {
-
- /** Border thickness in pixels. */
- private static final int BORDER= 1;
-
-
- /** The control's shell */
- private Shell fShell;
- /** The control's text widget */
- private StyledText fText;
- /** The control's source viewer */
- private SourceViewer fViewer;
- /** The optional status field. */
- private Label fStatusField;
- /** The separator for the optional status field. */
- private Label fSeparator;
- /** The font of the optional status text label.*/
- private Font fStatusTextFont;
- /** The maximal widget width. */
- private int fMaxWidth;
- /** The maximal widget height. */
- private int fMaxHeight;
-
-
- /**
- * Creates a source viewer information control with the given shell as
- * parent and the given font.
- *
- * @param parent the parent shell
- * @param symbolicFontName the symbolic font name
- */
- public SourceViewerInformationControl(Shell parent, String symbolicFontName) {
- this(parent, SWT.NO_TRIM, SWT.NONE, symbolicFontName, null);
- }
-
- /**
- * Creates a source viewer information control with the given shell as
- * parent. The given shell styles are applied to the created shell. The
- * given styles are applied to the created styled text widget. The text
- * widget will be initialized with the given font. The status field will
- * contain the given text or be hidden.
- *
- * @param parent the parent shell
- * @param shellStyle the additional styles for the shell
- * @param style the additional styles for the styled text widget
- * @param symbolicFontName the symbolic font name
- * @param statusFieldText the text to be used in the optional status field
- * or <code>null</code> if the status field should be hidden
- */
- public SourceViewerInformationControl(Shell parent, int shellStyle, int style, String symbolicFontName, String statusFieldText) {
- GridLayout layout;
- GridData gd;
-
- fShell= new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle);
- Display display= fShell.getDisplay();
- fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
-
- Composite composite= fShell;
- layout= new GridLayout(1, false);
- int border= ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER;
- layout.marginHeight= border;
- layout.marginWidth= border;
- composite.setLayout(layout);
- gd= new GridData(GridData.FILL_HORIZONTAL);
- composite.setLayoutData(gd);
-
- if (statusFieldText != null) {
- composite= new Composite(composite, SWT.NONE);
- layout= new GridLayout(1, false);
- layout.marginHeight= 0;
- layout.marginWidth= 0;
- composite.setLayout(layout);
- gd= new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
- composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- }
-
- // Source viewer
- fViewer= new SourceViewer(composite, null, style);
- fViewer.configure(new SourceViewerConfiguration());
- fViewer.setEditable(false);
-
- fText= fViewer.getTextWidget();
- gd= new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
- fText.setLayoutData(gd);
- fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- fText.setFont(JFaceResources.getFont(symbolicFontName));
-
- fText.addKeyListener(new KeyListener() {
-
- public void keyPressed(KeyEvent e) {
- if (e.character == 0x1B) // ESC
- fShell.dispose();
- }
-
- public void keyReleased(KeyEvent e) {}
- });
-
- // Status field
- if (statusFieldText != null) {
-
- // Horizontal separator line
- fSeparator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
- fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- // Status field label
- fStatusField= new Label(composite, SWT.RIGHT);
- fStatusField.setText(statusFieldText);
- Font font= fStatusField.getFont();
- FontData[] fontDatas= font.getFontData();
- for (int i= 0; i < fontDatas.length; i++)
- fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
- fStatusTextFont= new Font(fStatusField.getDisplay(), fontDatas);
- fStatusField.setFont(fStatusTextFont);
- GridData gd2= new GridData(GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
- fStatusField.setLayoutData(gd2);
-
- // Regarding the color see bug 41128
- fStatusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
-
- fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- }
-
- addDisposeListener(this);
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControlExtension2#setInput(java.lang.Object)
- */
- public void setInput(Object input) {
- if (input instanceof String)
- setInformation((String)input);
- else
- setInformation(null);
- }
-
- /*
- * @see IInformationControl#setInformation(String)
- */
- public void setInformation(String content) {
- if (content == null) {
- fViewer.setInput(null);
- return;
- }
-
- IDocument doc= new Document(content);
- fViewer.setInput(doc);
- }
-
- /*
- * @see IInformationControl#setVisible(boolean)
- */
- public void setVisible(boolean visible) {
- fShell.setVisible(visible);
- }
-
- /*
- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
- */
- public void widgetDisposed(DisposeEvent event) {
- if (fStatusTextFont != null && !fStatusTextFont.isDisposed())
- fStatusTextFont.dispose();
-
- fStatusTextFont= null;
- fShell= null;
- fText= null;
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControl#dispose()
- */
- public final void dispose() {
- if (fShell != null && !fShell.isDisposed())
- fShell.dispose();
- else
- widgetDisposed(null);
- }
-
- /*
- * @see IInformationControl#setSize(int, int)
- */
- public void setSize(int width, int height) {
-
- if (fStatusField != null) {
- GridData gd= (GridData)fViewer.getTextWidget().getLayoutData();
- Point statusSize= fStatusField.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- Point separatorSize= fSeparator.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- gd.heightHint= height - statusSize.y - separatorSize.y;
- }
- fShell.setSize(width, height);
-
- if (fStatusField != null)
- fShell.pack(true);
- }
-
- /*
- * @see IInformationControl#setLocation(Point)
- */
- public void setLocation(Point location) {
- Rectangle trim= fShell.computeTrim(0, 0, 0, 0);
- Point textLocation= fText.getLocation();
- location.x += trim.x - textLocation.x;
- location.y += trim.y - textLocation.y;
- fShell.setLocation(location);
- }
-
- /*
- * @see IInformationControl#setSizeConstraints(int, int)
- */
- public void setSizeConstraints(int maxWidth, int maxHeight) {
- fMaxWidth= maxWidth;
- fMaxHeight= maxHeight;
- }
-
- /*
- * @see IInformationControl#computeSizeHint()
- */
- public Point computeSizeHint() {
- Point size= fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- size.x= Math.min(size.x, fMaxWidth);
- size.y= Math.min(size.y, fMaxHeight);
- return size;
- }
-
- /*
- * @see IInformationControl#addDisposeListener(DisposeListener)
- */
- public void addDisposeListener(DisposeListener listener) {
- fShell.addDisposeListener(listener);
- }
-
- /*
- * @see IInformationControl#removeDisposeListener(DisposeListener)
- */
- public void removeDisposeListener(DisposeListener listener) {
- fShell.removeDisposeListener(listener);
- }
-
- /*
- * @see IInformationControl#setForegroundColor(Color)
- */
- public void setForegroundColor(Color foreground) {
- fText.setForeground(foreground);
- }
-
- /*
- * @see IInformationControl#setBackgroundColor(Color)
- */
- public void setBackgroundColor(Color background) {
- fText.setBackground(background);
- }
-
- /*
- * @see IInformationControl#isFocusControl()
- */
- public boolean isFocusControl() {
- return fText.isFocusControl();
- }
-
- /*
- * @see IInformationControl#setFocus()
- */
- public void setFocus() {
- fShell.forceFocus();
- fText.setFocus();
- }
-
- /*
- * @see IInformationControl#addFocusListener(FocusListener)
- */
- public void addFocusListener(FocusListener listener) {
- fText.addFocusListener(listener);
- }
-
- /*
- * @see IInformationControl#removeFocusListener(FocusListener)
- */
- public void removeFocusListener(FocusListener listener) {
- fText.removeFocusListener(listener);
- }
-
- /*
- * @see IInformationControlExtension#hasContents()
- */
- public boolean hasContents() {
- return fText.getCharCount() > 0;
- }
-}
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/collapsed.gif b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/collapsed.gif
deleted file mode 100644
index 5f4c8bba4a6..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/collapsed.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/expanded.gif b/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/expanded.gif
deleted file mode 100644
index ff4d9c4a90b..00000000000
--- a/org.eclipse.jface.text/projection/org/eclipse/jface/text/source/projection/images/expanded.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jface.text/scripts/exportplugin.xml b/org.eclipse.jface.text/scripts/exportplugin.xml
deleted file mode 100644
index 9db702b0f9a..00000000000
--- a/org.eclipse.jface.text/scripts/exportplugin.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-<project name="Export JFace Text" default="export" basedir="..">
- <target name="init">
- <tstamp/>
- <property name="destdir" value="../../plugin-export" />
- <property name="plugin" value="org.eclipse.jface.text" />
- <property name="version" value="_3.0.0" />
- <property name="dest" value="${destdir}/${plugin}${version}" />
- </target>
-
- <target name="build" depends="init">
- <eclipse.incrementalBuild project="${plugin}" kind="incr"/>
- </target>
-
- <target name="export" depends="build">
- <mkdir dir="${destdir}" />
- <delete dir="${dest}" />
- <mkdir dir="${dest}" />
- <jar
- jarfile="${dest}/jfacetext.jar"
- basedir="bin"
- />
- <copy file="plugin.xml" todir="${dest}"/>
- <copy file="plugin.properties" todir="${dest}"/>
- <zip zipfile="${dest}/jfacetextsrc.zip">
- <fileset dir="src" />
- <fileset dir="projection"/>
- </zip>
- </target>
-</project>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java
deleted file mode 100644
index 7ba6964818d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/AbstractControlContentAssistSubjectAdapter.java
+++ /dev/null
@@ -1,823 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.core.runtime.Platform;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.graphics.Region;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-
-import org.eclipse.jface.resource.ImageDescriptor;
-import org.eclipse.jface.util.Assert;
-import org.eclipse.jface.viewers.ILabelProvider;
-
-import org.eclipse.jface.text.IEventConsumer;
-
-
-/**
- * An <code>AbstractControlContentAssistSubjectAdapter</code> delegates assistance requests from a
- * {@linkplain org.eclipse.jface.text.contentassist.ContentAssistant content assistant}
- * to a <code>Control</code>.
- *
- * A visual affordance can be configured via {@link #setContentAssistCueProvider(ILabelProvider)}.
- *
- * @since 3.0
- */
-public abstract class AbstractControlContentAssistSubjectAdapter implements IContentAssistSubjectControl {
-
- protected static final boolean DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jface.text/debug/ContentAssistSubjectAdapters")); //$NON-NLS-1$//$NON-NLS-2$
-
- /**
- * VerifyKeyListeners for the control.
- */
- private List fVerifyKeyListeners;
- /**
- * KeyListeners for the control.
- */
- private Set fKeyListeners;
- /**
- * The Listener installed on the control which passes events to
- * {@link #fVerifyKeyListeners fVerifyKeyListeners} and {@link #fKeyListeners fKeyListeners}.
- */
- private Listener fControlListener;
-
- /**
- * Creates a new {@link AbstractControlContentAssistSubjectAdapter}.
- **/
- public AbstractControlContentAssistSubjectAdapter() {
- fVerifyKeyListeners= new ArrayList(1);
- fKeyListeners= new HashSet(1);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getControl()
- */
- public abstract Control getControl();
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#addKeyListener(org.eclipse.swt.events.KeyListener)
- */
- public void addKeyListener(KeyListener keyListener) {
- fKeyListeners.add(keyListener);
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#addKeyListener()"); //$NON-NLS-1$
-
- installControlListener();
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeKeyListener(KeyListener keyListener) {
- boolean deleted= fKeyListeners.remove(keyListener);
-
- if (DEBUG) {
- if (!deleted)
- System.out.println("removeKeyListener -> wasn't here"); //$NON-NLS-1$
- System.out.println("AbstractControlContentAssistSubjectAdapter#removeKeyListener() -> " + fKeyListeners.size()); //$NON-NLS-1$
- }
-
- uninstallControlListener();
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean supportsVerifyKeyListener() {
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean appendVerifyKeyListener(final VerifyKeyListener verifyKeyListener) {
- fVerifyKeyListeners.add(verifyKeyListener);
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#appendVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$
-
- installControlListener();
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean prependVerifyKeyListener(final VerifyKeyListener verifyKeyListener) {
- fVerifyKeyListeners.add(0, verifyKeyListener);
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#prependVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$
-
- installControlListener();
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
- fVerifyKeyListeners.remove(verifyKeyListener);
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#removeVerifyKeyListener() -> " + fVerifyKeyListeners.size()); //$NON-NLS-1$
-
- uninstallControlListener();
- }
-
- /**
- * {@inheritDoc}
- */
- public void setEventConsumer(IEventConsumer eventConsumer) {
- // this is not supported
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#setEventConsumer()"); //$NON-NLS-1$
- }
-
- /**
- * {@inheritDoc}
- */
- public String getLineDelimiter() {
- return System.getProperty("line.separator"); //$NON-NLS-1$
- }
-
- /**
- * Installs <code>fControlListener</code>, which handles VerifyEvents and KeyEvents by
- * passing them to <code>fVerifyKeyListeners</code> and <code>fKeyListeners</code>.
- */
- private void installControlListener() {
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size()); //$NON-NLS-1$ //$NON-NLS-2$
-
- if (fControlListener != null)
- return;
-
- fControlListener= new Listener() {
- public void handleEvent(Event e) {
- if (! getControl().isFocusControl())
- return; //SWT.TRAVERSE_MNEMONIC events can also come in to inactive widgets
- VerifyEvent verifyEvent= new VerifyEvent(e);
- KeyEvent keyEvent= new KeyEvent(e);
- switch (e.type) {
- case SWT.Traverse :
-
- if (DEBUG)
- dump("before traverse", e, verifyEvent); //$NON-NLS-1$
-
- verifyEvent.doit= true;
- for (Iterator iter= fVerifyKeyListeners.iterator(); iter.hasNext(); ) {
- ((VerifyKeyListener) iter.next()).verifyKey(verifyEvent);
- if (! verifyEvent.doit) {
- e.detail= SWT.TRAVERSE_NONE;
- e.doit= true;
- if (DEBUG)
- dump("traverse eaten by verify", e, verifyEvent); //$NON-NLS-1$
- return;
- }
-
- if (DEBUG)
- dump("traverse ok", e, verifyEvent); //$NON-NLS-1$
- }
- break;
-
- case SWT.KeyDown:
- for (Iterator iter= fVerifyKeyListeners.iterator(); iter.hasNext(); ) {
- ((VerifyKeyListener) iter.next()).verifyKey(verifyEvent);
- if (! verifyEvent.doit) {
- e.doit= verifyEvent.doit;
- if (DEBUG)
- dump("keyDown eaten by verify", e, verifyEvent); //$NON-NLS-1$
- return;
- }
- }
-
- if (DEBUG)
- dump("keyDown ok", e, verifyEvent); //$NON-NLS-1$
-
- for (Iterator iter= fKeyListeners.iterator(); iter.hasNext();) {
- ((KeyListener) iter.next()).keyPressed(keyEvent);
- }
- break;
-
- default :
- Assert.isTrue(false);
- }
- }
-
- /**
- * Dump the given events to "standard" output.
- *
- * @param who who dump's
- * @param e the event
- * @param ve the verify event
- */
- private void dump(String who, Event e, VerifyEvent ve) {
- StringBuffer sb= new StringBuffer("--- [AbstractControlContentAssistSubjectAdapter]\n"); //$NON-NLS-1$
- sb.append(who);
- sb.append(" - e: keyCode="+e.keyCode+hex(e.keyCode)); //$NON-NLS-1$
- sb.append("; character="+e.character+hex(e.character)); //$NON-NLS-1$
- sb.append("; stateMask="+e.stateMask+hex(e.stateMask)); //$NON-NLS-1$
- sb.append("; doit="+e.doit); //$NON-NLS-1$
- sb.append("; detail="+e.detail+hex(e.detail)); //$NON-NLS-1$
- sb.append("; widget="+e.widget); //$NON-NLS-1$
- sb.append("\n"); //$NON-NLS-1$
- sb.append(" verifyEvent keyCode="+e.keyCode+hex(e.keyCode)); //$NON-NLS-1$
- sb.append("; character="+e.character+hex(e.character)); //$NON-NLS-1$
- sb.append("; stateMask="+e.stateMask+hex(e.stateMask)); //$NON-NLS-1$
- sb.append("; doit="+ve.doit); //$NON-NLS-1$
- sb.append("; widget="+e.widget); //$NON-NLS-1$
- System.out.println(sb);
- }
-
- private String hex(int i) {
- return "[0x" + Integer.toHexString(i) + ']'; //$NON-NLS-1$
- }
- };
- getControl().addListener(SWT.Traverse, fControlListener);
- getControl().addListener(SWT.KeyDown, fControlListener);
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#installControlListener() - installed"); //$NON-NLS-1$
- }
-
- /**
- * Uninstalls <code>fControlListener</code> iff there are no <code>KeyListener</code>s and no
- * <code>VerifyKeyListener</code>s registered.
- * Otherwise does nothing.
- */
- private void uninstallControlListener() {
- if (fControlListener == null || fKeyListeners.size() + fVerifyKeyListeners.size() != 0) {
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#uninstallControlListener() -> k: " + fKeyListeners.size() + ", v: " + fVerifyKeyListeners.size()); //$NON-NLS-1$ //$NON-NLS-2$
-
- return;
- }
- getControl().removeListener(SWT.Traverse, fControlListener);
- getControl().removeListener(SWT.KeyDown, fControlListener);
- fControlListener= null;
-
- if (DEBUG)
- System.out.println("AbstractControlContentAssistSubjectAdapter#uninstallControlListener() - done"); //$NON-NLS-1$
- }
-
- /**
- * Sets the visual affordance provider for content assist.
- * The given {@link ILabelProvider} methods are called with
- * {@link #getControl()} as argument.
- *
- * <ul>
- * <li><code>getImage(Object)</code> provides the visual cue image.
- * The image can maximally be 5 pixels wide and 8 pixels high.
- * If <code>getImage(Object)</code> returns <code>null</code>, a default image is used.
- * </li>
- * <li><code>getText(Object)</code> provides the hover info text.
- * It is shown when hovering over the cue image or the adapted {@link Control}.
- * No info text is shown if <code>getText(Object)</code> returns <code>null</code>.
- * </li>
- * </ul>
- * <p>
- * The given {@link ILabelProvider} becomes owned by the {@link AbstractControlContentAssistSubjectAdapter},
- * i.e. it gets disposed when the adapted {@link Control} is disposed
- * or when another {@link ILabelProvider} is set.
- * </p>
- *
- * @param labelProvider a {@link ILabelProvider}, or <code>null</code>
- * if the affordance should not be shown
- */
- public void setContentAssistCueProvider(ILabelProvider labelProvider) {
- SmartFieldController.setSmartCue(getControl(), labelProvider);
- }
-
- /**
- * The internal controller for cues and error messages on <code>Text</code> and
- * <code>Combo</code> <code>Control</code>s.
- */
- private static class SmartFieldController {
-
- /**
- * An info Hover to display a message next to a {@link Control}.
- */
- class Hover {
- /**
- * Distance of info hover arrow from left side.
- */
- private int HD= 10;
- /**
- * Width of info hover arrow.
- */
- private int HW= 8;
- /**
- * Height of info hover arrow.
- */
- private int HH= 10;
- /**
- * Margin around info hover text.
- */
- private int LABEL_MARGIN= 2;
- /**
- * This info hover's shell.
- */
- Shell fHoverShell;
- /**
- * The info hover text.
- */
- String fText= ""; //$NON-NLS-1$
-
- Hover(Shell parent) {
- final Display display= parent.getDisplay();
- fHoverShell= new Shell(parent, SWT.NO_TRIM | SWT.ON_TOP | SWT.NO_FOCUS);
- fHoverShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- fHoverShell.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- fHoverShell.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent pe) {
- pe.gc.drawString(fText, LABEL_MARGIN, LABEL_MARGIN);
- if (!fgCarbon)
- pe.gc.drawPolygon(getPolygon(true));
- }
- });
- fHoverShell.addMouseListener(new MouseAdapter() {
- public void mouseDown(MouseEvent e) {
- showHover(null, null);
- }
- });
- }
-
- int[] getPolygon(boolean border) {
- Point e= getExtent();
- if (border) {
- return new int[] { 0,0, e.x-1,0, e.x-1,e.y-1, HD+HW,e.y-1, HD+HW/2,e.y+HH-1, HD,e.y-1, 0,e.y-1, 0,0 };
- } else {
- return new int[] { 0,0, e.x, 0, e.x, e.y, HD+HW,e.y, HD+HW/2,e.y+HH, HD,e.y, 0,e.y, 0,0 };
- }
- }
-
- void dispose() {
- if (!fHoverShell.isDisposed())
- fHoverShell.dispose();
- }
-
- void setVisible(boolean visible) {
- if (visible) {
- if (!fHoverShell.isVisible())
- fHoverShell.setVisible(true);
- } else {
- if (fHoverShell.isVisible())
- fHoverShell.setVisible(false);
- }
- }
-
- void setText(String t) {
- if (t == null)
- t= ""; //$NON-NLS-1$
- if (! t.equals(fText)) {
- Point oldSize= getExtent();
- fText= t;
- fHoverShell.redraw();
- Point newSize= getExtent();
- if (!oldSize.equals(newSize)) {
- Region region= new Region();
- region.add(getPolygon(false));
- fHoverShell.setRegion(region);
- }
- }
- }
-
- boolean isVisible() {
- return fHoverShell.isVisible();
- }
-
- void setLocation(Control control) {
- if (control != null) {
- int h= getExtent().y;
- fHoverShell.setLocation(control.toDisplay(-HD+HW/2, -h-HH+1));
- }
- }
-
- Point getExtent() {
- GC gc= new GC(fHoverShell);
- Point e= gc.textExtent(fText);
- gc.dispose();
- e.x+= LABEL_MARGIN*2;
- e.y+= LABEL_MARGIN*2;
- return e;
- }
- }
-
- /**
- * A single plain HoverHandler is registered for the content assist control.
- * It handles mouse hover events to show/hide the info hover.
- */
- class HoverHandler extends MouseTrackAdapter {
- /**
- * The managing FieldFocusListener.
- */
- FieldFocusListener fFieldFocusListener;
- /**
- * Create a new HoverHandler.
- *
- * @param fieldFocusListener the field focus listener
- */
- HoverHandler(FieldFocusListener fieldFocusListener) {
- fFieldFocusListener= fieldFocusListener;
- }
- /**
- * @inheritDoc
- */
- public void mouseHover(MouseEvent e) {
- handleMouseEvent(e);
- }
- /**
- * @inheritDoc
- */
- public void mouseExit(MouseEvent e) {
- if (isHoverVisible())
- fFieldFocusListener.doHideHover();
- }
- /**
- * Subclasses may extend or reimplement this method.
- * @param e
- */
- void handleMouseEvent(MouseEvent e) {
- fFieldFocusListener.doShowHover();
- }
- }
-
- /**
- * One CueHandler is registered per ancestor control of the content assist control.
- * It paints the visual cue icon and handles mouse hover events to show/hide the info hover.
- */
- class CueHandler extends HoverHandler implements PaintListener {
- /**
- * Create a new CueHandler.
- *
- * @param fieldFocusListener the field focus listener
- */
- CueHandler(FieldFocusListener fieldFocusListener) {
- super(fieldFocusListener);
- }
- /**
- * @inheritDoc
- */
- public void paintControl(PaintEvent e) {
- fFieldFocusListener.paintControl(e);
- }
- /**
- * Updates the hover.
- *
- * @param event the mouse event
- */
- void handleMouseEvent(MouseEvent event) {
- fFieldFocusListener.updateHoverOnCue(event);
- }
- }
-
- class FieldFocusListener implements FocusListener {
- /**
- * Put icon relative to this control.
- */
- private Control fControl;
- /**
- * The icon's horizontal screen distance from top-left corner of control (in pixels).
- */
- private int fDx;
- /**
- * The icon's vertical screen distance from top-left corner of control (in pixels).
- */
- private int fDy;
- /**
- * The HoverHandler (only when control has focus).
- */
- private HoverHandler fHoverHandler;
-
- /**
- * Create a new FieldFocusListener
- * @param control the target control
- */
- FieldFocusListener(Control control) {
- fControl= control;
-
- fDx= -5;
- fDy= 1;
- if (fgCarbon) {
- if (control instanceof Text) {
- fDy+= 3;
- } else if (control instanceof Combo) {
- fDx-= 4;
- }
- } else if (fgWin32) {
- if (control instanceof Text) {
- fDx-= 2;
- fDy-= 2;
- }
- }
- }
-
- /**
- * Paint the cue image.
- * @param e the PaintEvent
- */
- void paintControl(PaintEvent e) {
- if (fControl.isDisposed())
- return;
- Image image= getCueImage(fControl);
- Point global= fControl.toDisplay(fDx, fDy);
- Point local= ((Control) e.widget).toControl(global);
- e.gc.drawImage(image, local.x, local.y);
- }
-
- /**
- * Show/hide the hover.
- * @param e the MouseEvent
- */
- void updateHoverOnCue(MouseEvent e) {
- Image image= getCueImage(fControl);
- Rectangle r= image.getBounds();
- Point global= fControl.toDisplay(fDx, fDy);
- Point local= ((Control) e.widget).toControl(global);
- r.x= local.x;
- r.y= local.y;
- if (r.contains(e.x, e.y))
- doShowHover();
- else
- doHideHover();
- }
-
- /**
- * Hide hover.
- */
- private void doHideHover() {
- showHover(fControl, null);
- }
-
- /**
- * Show hover.
- */
- public void doShowHover() {
- showHover(fControl, fLabelProvider.getText(fControl));
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- // install a CueHandler on every parent control
- if (DEBUG)
- System.out.println("Focus Gained: " + e.widget); //$NON-NLS-1$
-
- if (fHoverHandler == null) {
- fHoverHandler= new HoverHandler(this);
- fControl.addMouseTrackListener(fHoverHandler);
- }
-
- Control c= fControl.getParent();
- while (c != null) {
- if (DEBUG)
- System.out.println("install CueHandler: " + c.toString()); //$NON-NLS-1$
- CueHandler cueHandler= new CueHandler(this);
- Assert.isTrue(c.getData(ANNOTATION_HANDLER) == null, "parent control has CueHandler: " + c.toString()); //$NON-NLS-1$
- c.setData(ANNOTATION_HANDLER, cueHandler);
- c.addPaintListener(cueHandler);
- c.addMouseTrackListener(cueHandler);
- c.redraw();
- if (c instanceof Shell)
- break;
- else
- c= c.getParent();
- }
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
- */
- public void focusLost(FocusEvent e) {
- if (DEBUG) {
- System.out.println("Focus Lost: " + e.widget + ", at:"); //$NON-NLS-1$ //$NON-NLS-2$
- Thread.dumpStack();
- }
-
- if (fHoverHandler != null)
- fControl.removeMouseTrackListener(fHoverHandler);
-
- Control c= fControl.getParent();
- while (c != null) {
- if (DEBUG)
- System.out.println("uninstall CueHandler: " + c.toString()); //$NON-NLS-1$
- CueHandler cueHandler= (CueHandler) c.getData(ANNOTATION_HANDLER);
- //workaround for bug 64052:
- if (cueHandler != null) {
- c.setData(ANNOTATION_HANDLER, null);
- c.removePaintListener(cueHandler);
- c.removeMouseTrackListener(cueHandler);
- c.redraw();
- }
- if (c instanceof Shell)
- break;
- else
- c= c.getParent();
- }
- }
- }
-
- private static final String SMART_FIELD_CONTROLLER= "org.eclipse.SmartFieldController"; //$NON-NLS-1$
- private static final String SMART_FOCUS_LISTENER= "org.eclipse.SmartFieldController.smartFocusListener"; //$NON-NLS-1$
- private static final String ANNOTATION_HANDLER= "org.eclipse.SmartFieldController.annotationHandler"; //$NON-NLS-1$
-
- private static String fgPlatform= SWT.getPlatform();
- private static boolean fgCarbon= "carbon".equals(fgPlatform); //$NON-NLS-1$
- private static boolean fgWin32= "win32".equals(fgPlatform); //$NON-NLS-1$
-
- private Shell fShell;
- private ILabelProvider fLabelProvider;
- private Image fCueImage;
- private Hover fHover;
- private Control fHoverControl;
-
- /**
- * Installs or deinstalls a visual cue indicating availability of content assist on the given control.
- * At most one cue and one hover info is shown at any point in time.
- *
- * @param control the control on which to install or uninstall the cue
- * @param labelProvider the label provider or <code>null</code> to uninstall the cue
- */
- public static void setSmartCue(Control control, ILabelProvider labelProvider) {
- getSmartFieldController(control).internalSetSmartCue(control, labelProvider);
- }
-
- //---- private implementation
-
- private SmartFieldController(Shell shell) {
- fShell= shell;
- fShell.setData(SMART_FIELD_CONTROLLER, this);
-
- Listener l= new Listener() {
- public void handleEvent(Event event) {
- switch (event.type) {
- case SWT.Resize:
- case SWT.Move:
- if (fHover != null)
- fHover.setLocation(fHoverControl);
- break;
- case SWT.Dispose:
- Object data= fShell.getData(SMART_FIELD_CONTROLLER);
- if (data == SmartFieldController.this) {
- fShell.setData(SMART_FIELD_CONTROLLER, null);
- handleDispose();
- }
- break;
- //case SWT.Activate:
- case SWT.Deactivate:
- case SWT.Close:
- case SWT.Iconify:
- //case SWT.Deiconify:
- showHover(null, null);
- break;
- }
- }
- };
- shell.addListener(SWT.Dispose, l);
- shell.addListener(SWT.Resize, l);
- shell.addListener(SWT.Move, l);
- //shell.addListener(SWT.Activate, l);
- shell.addListener(SWT.Close, l);
- shell.addListener(SWT.Deactivate, l);
- shell.addListener(SWT.Iconify, l);
- //shell.addListener(SWT.Deiconify, l);
- }
-
- private void handleDispose() {
- fShell= null;
- fHoverControl= null;
- if (fHover != null) {
- fHover.dispose();
- fHover= null;
- }
- if (fCueImage != null) {
- fCueImage.dispose();
- fCueImage= null;
- }
- if (fLabelProvider != null) {
- fLabelProvider.dispose();
- fLabelProvider= null;
- }
- }
- /**
- * Gets the smart field controller from the <code>control</code>'s Shell.
- * @param control that target control
- * @return <code>control</code>'s shell
- */
- private static SmartFieldController getSmartFieldController(Control control) {
- Shell shell= control.getShell();
- Object data= shell.getData(SMART_FIELD_CONTROLLER);
- if (! (data instanceof SmartFieldController))
- data= new SmartFieldController(shell);
- return (SmartFieldController) data;
- }
-
- private void internalSetSmartCue(final Control control, ILabelProvider labelProvider) {
- if (fLabelProvider != null)
- fLabelProvider.dispose();
-
- fLabelProvider= labelProvider;
-
- FieldFocusListener focuslistener= (FieldFocusListener) control.getData(SMART_FOCUS_LISTENER);
-
- if (labelProvider != null) {
- // add smart stuff
- if (focuslistener == null) {
- focuslistener= new FieldFocusListener(control);
- control.setData(SMART_FOCUS_LISTENER, focuslistener);
- control.addFocusListener(focuslistener);
- }
- } else {
- // remove smart stuff
- if (focuslistener != null) {
- control.removeFocusListener(focuslistener);
- control.setData(SMART_FOCUS_LISTENER, null);
- }
-
- if (fCueImage != null) {
- fCueImage.dispose();
- fCueImage= null;
- }
- }
- }
- /**
- * Show or hide hover.
- * @param control target control
- * @param text a String to show in hover, or <code>null</code> to hide
- */
- private void showHover(Control control, String text) {
- if (text != null) {
- fHoverControl= control;
- if (fHover == null)
- fHover= new Hover(fShell);
- fHover.setText(text);
- fHover.setLocation(fHoverControl);
- fHover.setVisible(true);
- } else {
- fHoverControl= null;
- if (fHover != null)
- fHover.setVisible(false);
- }
- }
-
- private boolean isHoverVisible() {
- return fHover != null && fHover.isVisible();
- }
-
- private Image getCueImage(Control control) {
- Image image= null;
- if (fLabelProvider != null)
- image= fLabelProvider.getImage(control);
-
- return image != null ? image : getCueImage();
- }
-
- private Image getCueImage() {
- if (fCueImage == null) {
- ImageDescriptor cueID= ImageDescriptor.createFromFile(SmartFieldController.class, "images/content_assist_cue.gif"); //$NON-NLS-1$
- fCueImage= cueID.createImage(fShell.getDisplay());
- }
- return fCueImage;
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java
deleted file mode 100644
index d45967fc86e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ComboContentAssistSubjectAdapter.java
+++ /dev/null
@@ -1,211 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import java.util.HashMap;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-
-import org.eclipse.jface.util.Assert;
-
-/**
- * Adapts a <code>Combo</code> to an <code>IContentAssistSubjectControl</code>.
- * <p>
- * Known issues:
- * <ul>
- * <li>https://bugs.eclipse.org/bugs/show_bug.cgi?id=50121
- * => Combo doesn't get Arrow_up/Down keys on GTK</li>
- *
- * <li>https://bugs.eclipse.org/bugs/show_bug.cgi?id=50123
- * => Combo broken on MacOS X</li>
- * </ul>
- * </p>
- *
- * @see org.eclipse.swt.widgets.Combo
- * @see org.eclipse.jface.contentassist.IContentAssistSubjectControl
- * @since 3.0
- */
-public class ComboContentAssistSubjectAdapter extends AbstractControlContentAssistSubjectAdapter {
-
- /**
- * The <code>Document</code> of <code>fCombo</code>'s contents.
- */
- private class InternalDocument extends Document {
- /**
- * Updates this <code>Document</code> with changes in <code>fCombo</code>.
- */
- private ModifyListener fModifyListener;
-
- private InternalDocument() {
- super(fCombo.getText());
- fModifyListener= new ModifyListener() {
- /*
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void modifyText(ModifyEvent e) {
- set(fCombo.getText());
- }
- };
- fCombo.addModifyListener(fModifyListener);
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractDocument#replace(int, int, java.lang.String)
- */
- public void replace(int pos, int length, String text) throws BadLocationException {
- super.replace(pos, length, text);
- fCombo.removeModifyListener(fModifyListener);
- fCombo.setText(get());
- fCombo.addModifyListener(fModifyListener);
- }
- }
-
- /**
- * The combo.
- */
- private Combo fCombo;
- private HashMap fModifyListeners;
-
- /**
- * Creates a content assist subject control adapter for the given combo.
- *
- * @param combo the combo to adapt
- */
- public ComboContentAssistSubjectAdapter(Combo combo) {
- Assert.isNotNull(combo);
- fCombo= combo;
- fModifyListeners= new HashMap();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getControl()
- */
- public Control getControl() {
- return fCombo;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getLineHeight()
- */
- public int getLineHeight() {
- return fCombo.getTextHeight();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getCaretOffset()
- */
- public int getCaretOffset() {
- return fCombo.getSelection().y;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getLocationAtOffset(int)
- */
- public Point getLocationAtOffset(int offset) {
- String comboString= fCombo.getText();
- GC gc = new GC(fCombo);
- gc.setFont(fCombo.getFont());
- Point extent= gc.textExtent(comboString.substring(0, Math.min(offset, comboString.length())));
- int spaceWidth= gc.textExtent(" ").x; //$NON-NLS-1$
- gc.dispose();
- /*
- * FIXME: the two space widths below is a workaround for bug 44072
- */
- int x= 2 * spaceWidth + fCombo.getClientArea().x + fCombo.getBorderWidth() + extent.x;
- return new Point(x, fCombo.getClientArea().y);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getSelectionRange()
- */
- public Point getWidgetSelectionRange() {
- return new Point(fCombo.getSelection().x, Math.abs(fCombo.getSelection().y - fCombo.getSelection().x));
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getSelectedRange()
- */
- public Point getSelectedRange() {
- return new Point(fCombo.getSelection().x, Math.abs(fCombo.getSelection().y - fCombo.getSelection().x));
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getDocument()
- */
- public IDocument getDocument() {
- IDocument document= (IDocument)fCombo.getData("document"); //$NON-NLS-1$
- if (document == null) {
- document= new InternalDocument() ;
- fCombo.setData("document", document); //$NON-NLS-1$
- }
- return document;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#setSelectedRange(int, int)
- */
- public void setSelectedRange(int i, int j) {
- fCombo.setSelection(new Point(i, i+j));
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#revealRange(int, int)
- */
- public void revealRange(int i, int j) {
- // XXX: this should be improved
- fCombo.setSelection(new Point(i, i+j));
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#addSelectionListener(org.eclipse.swt.events.SelectionListener)
- */
- public boolean addSelectionListener(final SelectionListener selectionListener) {
- fCombo.addSelectionListener(selectionListener);
- Listener listener= new Listener() {
- /*
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void handleEvent(Event e) {
- selectionListener.widgetSelected(new SelectionEvent(e));
-
- }
- };
- fCombo.addListener(SWT.Modify, listener);
- fModifyListeners.put(selectionListener, listener);
- return true;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#removeSelectionListener(org.eclipse.swt.events.SelectionListener)
- */
- public void removeSelectionListener(SelectionListener selectionListener) {
- fCombo.removeSelectionListener(selectionListener);
- Object listener= fModifyListeners.get(selectionListener);
- if (listener instanceof Listener)
- fCombo.removeListener(SWT.Modify, (Listener)listener);
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/IContentAssistSubjectControl.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/IContentAssistSubjectControl.java
deleted file mode 100644
index 51a5f50761d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/IContentAssistSubjectControl.java
+++ /dev/null
@@ -1,297 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IEventConsumer;
-
-
-/**
- * A content assist subject control can request assistance provided by a
- * {@linkplain org.eclipse.jface.contentassist.ISubjectControlContentAssistant subject control content assistant}.
- *
- * @since 3.0
- */
-public interface IContentAssistSubjectControl {
-
- /**
- * Returns the control of this content assist subject control.
- *
- * @return the control of this content assist subject control
- */
- Control getControl();
-
- /**
- * Returns the line height.
- *
- * @return line height in pixel
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- int getLineHeight();
-
- /**
- * Returns the caret position relative to the start of the text in widget
- * coordinates.
- *
- * @return the caret position relative to the start of the text in widget
- * coordinates
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- int getCaretOffset();
-
- /**
- * Returns the x, y location of the upper left corner of the character
- * bounding box at the specified offset in the text. The point is relative
- * to the upper left corner of the widget client area.
- *
- * @param offset widget offset relative to the start of the content 0
- * <= offset <= getCharCount()
- * @return x, y location of the upper left corner of the character bounding
- * box at the specified offset in the text
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_RANGE when the offset is outside the
- * valid range (< 0 or >getCharCount())</li>
- * </ul>
- */
- Point getLocationAtOffset(int offset);
-
- /**
- * Returns the line delimiter used for entering new lines by key down or
- * paste operation.
- *
- * @return line delimiter used for entering new lines by key down or paste
- * operation
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- String getLineDelimiter();
-
- /**
- * Returns the selected range in the subject's widget.
- *
- * @return start and length of the selection, x is the offset of the
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- */
- Point getWidgetSelectionRange();
-
- /**
- * Returns the selected range.
- *
- * @return start and length of the selection, x is the offset and y the
- * length based on the subject's model (e.g. document)
- */
- Point getSelectedRange();
-
- /**
- * Sets the selected range. Offset and length based on the subject's
- * model (e.g. document).
- *
- * @param offset the offset of the selection based on the subject's model
- * (e.g. document)
- * @param length the length of the selection based on the subject's model
- * (e.g. document)
- */
- void setSelectedRange(int offset, int length);
-
- /**
- * Reveals the given region. Offset and length based on the subject's
- * model (e.g. document).
- *
- * @param offset the offset of the selection based on the subject's model
- * (e.g. document)
- * @param length the length of the selection based on the subject's model
- * (e.g. document)
- */
- void revealRange(int offset, int length);
-
- /**
- * Returns this content assist subject control's document.
- *
- * @return the viewer's input document
- */
- IDocument getDocument();
-
- /**
- * If supported, appends a verify key listener to the viewer's list of verify key
- * listeners. If the listener is already registered with the viewer this
- * call moves the listener to the end of the list.
- * <p>
- * Note: This content assist subject control may not support appending a verify
- * listener, in which case <code>false</code> will be returned. If this
- * content assist subject control only supports <code>addVerifyKeyListener</code>
- * then this method can be used but <code>prependVerifyKeyListener</code>
- * must return <code>false</code>.
- * </p>
- *
- * @param verifyKeyListener the listener to be added
- * @return <code>true</code> if the listener was added
- */
- boolean appendVerifyKeyListener(VerifyKeyListener verifyKeyListener);
-
- /**
- * If supported, inserts the verify key listener at the beginning of this content assist
- * subject's list of verify key listeners. If the listener is already
- * registered with the viewer this call moves the listener to the beginning
- * of the list.
- * <p>
- * Note: This content assist subject control may not support prepending a verify
- * listener, in which case <code>false</code> will be returned. However,
- * <code>appendVerifyKeyListener</code> might work.
- * </p>
- *
- * @param verifyKeyListener the listener to be inserted
- * @return <code>true</code> if the listener was added
- */
- boolean prependVerifyKeyListener(VerifyKeyListener verifyKeyListener);
-
- /**
- * Removes the verify key listener from this content assist subject control's
- * list of verify key listeners. If the listener is not registered, this
- * call has no effect.
- *
- * @param verifyKeyListener the listener to be removed
- */
- void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener);
-
- /**
- * Tests whether a verify key listener can be added either using <code>prependVerifyKeyListener</code>
- * or <code>appendVerifyKeyListener</code>.
- *
- * @return <code>true</code> if adding verify key listeners is supported
- */
- boolean supportsVerifyKeyListener();
-
- /**
- * Adds the listener to the collection of listeners who will be notified
- * when keys are pressed and released on the system keyboard, by sending it
- * one of the messages defined in the <code>KeyListener</code> interface.
- *
- * @param keyListener the listener which should be notified
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #removeKeyListener(KeyListener)
- */
- void addKeyListener(KeyListener keyListener);
-
- /**
- * Removes the listener from the collection of listeners who will be
- * notified when keys are pressed and released on the system keyboard.
- *
- * @param keyListener the listener which should be notified
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception org.eclipse.swt.SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the
- * thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener(KeyListener)
- */
- void removeKeyListener(KeyListener keyListener);
-
- /**
- * If supported, registers an event consumer with this content assist
- * subject.
- *
- * @param eventConsumer the content assist subject control's event consumer. <code>null</code>
- * is a valid argument.
- */
- void setEventConsumer(IEventConsumer eventConsumer);
-
- /**
- * Removes the specified selection listener.
- * <p>
- *
- * @param selectionListener the listener
- * @exception org.eclipse.swt.SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when listener is null</li>
- * </ul>
- */
- void removeSelectionListener(SelectionListener selectionListener);
-
- /**
- * If supported, adds a selection listener. A Selection event is sent by the widget when the
- * selection has changed.
- * <p>
- *
- * @param selectionListener the listener
- * @return <code>true</code> if adding a selection listener is supported
- * @exception org.eclipse.swt.SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT when listener is null</li>
- * </ul>
- */
- boolean addSelectionListener(SelectionListener selectionListener);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistProcessor.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistProcessor.java
deleted file mode 100644
index 2d66441c22a..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistProcessor.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-
-/**
- * Extension interface for {@link org.eclipse.jface.text.contentassist.IContentAssistProcessor}
- * which provides the context for the
- * {@linkplain org.eclipse.jface.contentassist.ISubjectControlContentAssistant subject control content assistant}.
- *
- * @since 3.0
- */
-public interface ISubjectControlContentAssistProcessor extends IContentAssistProcessor {
- /**
- * Returns a list of completion proposals based on the specified location
- * within the document that corresponds to the current cursor position
- * within the text viewer.
- *
- * @param contentAssistSubjectControl the content assist subject control whose
- * document is used to compute the proposals
- * @param documentOffset an offset within the document for which
- * completions should be computed
- * @return an array of completion proposals or <code>null</code> if no
- * proposals are possible
- */
- ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset);
-
- /**
- * Returns information about possible contexts based on the specified
- * location within the document that corresponds to the current cursor
- * position within the content assist subject control.
- *
- * @param contentAssistSubjectControl the content assist subject control whose
- * document is used to compute the possible contexts
- * @param documentOffset an offset within the document for which context
- * information should be computed
- * @return an array of context information objects or <code>null</code>
- * if no context could be found
- */
- IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int documentOffset);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistant.java
deleted file mode 100644
index 0051d5dc989..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContentAssistant.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-
-
-/**
- * Extends {@link org.eclipse.jface.text.contentassist.IContentAssistant} to
- * allow to install a content assistant on the given
- * {@linkplain org.eclipse.jface.contentassist.IContentAssistSubjectControl content assist subject control}.
- *
- * @since 3.0
- */
-public interface ISubjectControlContentAssistant extends IContentAssistant {
-
- /**
- * Installs content assist support on the given subject.
- *
- * @param contentAssistSubjectControl the one who requests content assist
- */
- void install(IContentAssistSubjectControl contentAssistSubjectControl);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationPresenter.java
deleted file mode 100644
index 7364e16a186..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationPresenter.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
-
-/**
- * Extends {@link org.eclipse.jface.text.contentassist.IContextInformationPresenter} to
- * allow to install a content assistant on the given
- * {@linkplain org.eclipse.jface.contentassist.IContentAssistSubjectControl content assist subject control}.
- *
- * @since 3.0
- */
-public interface ISubjectControlContextInformationPresenter extends IContextInformationPresenter {
-
- /**
- * Installs this presenter for the given context information.
- *
- * @param info the context information which this presenter should style
- * @param contentAssistSubjectControl the content assist subject control
- * @param documentPosition the document position for which the information has been computed
- */
- void install(IContextInformation info, IContentAssistSubjectControl contentAssistSubjectControl, int documentPosition);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationValidator.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationValidator.java
deleted file mode 100644
index b83168fb00b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/ISubjectControlContextInformationValidator.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-
-/**
- * Extends {@link org.eclipse.jface.text.contentassist.IContextInformationValidator} to
- * allow to install a content assistant on the given
- * {@linkplain org.eclipse.jface.contentassist.IContentAssistSubjectControl content assist subject control}.
- *
- * @since 3.0
- */
-public interface ISubjectControlContextInformationValidator extends IContextInformationValidator {
-
- /**
- * Installs this validator for the given context information.
- *
- * @param info the context information which this validator should check
- * @param contentAssistSubjectControl the content assist subject control
- * @param documentPosition the document position for which the information
- * has been computed
- */
- void install(IContextInformation info, IContentAssistSubjectControl contentAssistSubjectControl, int documentPosition);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContentAssistant.java
deleted file mode 100644
index 1215094e29e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContentAssistant.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * The standard implementation of the <code>IControlContentAssistant</code> interface.
- * Usually, clients instantiate this class and configure it before using it.
- *
- * @since 3.0
- */
-public class SubjectControlContentAssistant extends org.eclipse.jface.text.contentassist.ContentAssistant implements ISubjectControlContentAssistant {
-
- /*
- * @see ISubjectControlContentAssistant#install(IContentAssistSubjectControl)
- */
- public void install(IContentAssistSubjectControl contentAssistSubjectControl) {
- Assert.isNotNull(contentAssistSubjectControl);
- super.install(contentAssistSubjectControl);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java
deleted file mode 100644
index e7ee6098e0d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/SubjectControlContextInformationValidator.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.contentassist;
-
-
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.contentassist.IContentAssistProcessor;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-
-
-/**
- * A default implementation of the <code>IContextInfomationValidator</code> interface.
- * This implementation determines whether the information is valid by asking the content
- * assist processor for all context information objects for the current position. If the
- * currently displayed information is in the result set, the context information is
- * considered valid.
- *
- * @since 3.0
- */
-public final class SubjectControlContextInformationValidator implements ISubjectControlContextInformationValidator {
-
- /** The content assist processor. */
- private IContentAssistProcessor fProcessor;
- /** The context information to be validated. */
- private IContextInformation fContextInformation;
- /** The content assist subject control. */
- private IContentAssistSubjectControl fContentAssistSubjectControl;
-
- /**
- * Creates a new context information validator which is ready to be installed on
- * a particular context information.
- *
- * @param processor the processor to be used for validation
- */
- public SubjectControlContextInformationValidator(IContentAssistProcessor processor) {
- fProcessor= processor;
- }
-
- /*
- * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
- */
- public void install(IContextInformation contextInformation, ITextViewer viewer, int position) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * @see ISubjectControlContextInformationValidator#install(IContextInformation, IContentAssistSubjectControl, int)
- */
- public void install(IContextInformation contextInformation, IContentAssistSubjectControl contentAssistSubjectControl, int position) {
- fContextInformation= contextInformation;
- fContentAssistSubjectControl= contentAssistSubjectControl;
- }
-
- /*
- * @see IContentAssistTipCloser#isContextInformationValid(int)
- */
- public boolean isContextInformationValid(int position) {
- if (fContentAssistSubjectControl != null && fProcessor instanceof ISubjectControlContentAssistProcessor) {
- IContextInformation[] infos= ((ISubjectControlContentAssistProcessor)fProcessor).computeContextInformation(fContentAssistSubjectControl, position);
- if (infos != null && infos.length > 0) {
- for (int i= 0; i < infos.length; i++) {
- if (fContextInformation.equals(infos[i]))
- return true;
- }
- }
- }
- return false;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java
deleted file mode 100644
index 90fa23f7c25..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/TextContentAssistSubjectAdapter.java
+++ /dev/null
@@ -1,192 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.contentassist;
-
-import java.util.HashMap;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Text;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.Document;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Adapts a <code>Text</code> to an <code>IContentAssistSubjectControl</code>.
- *
- * @see org.eclipse.swt.widgets.Text
- * @see org.eclipse.jface.contentassist.IContentAssistSubjectControl
- * @since 3.0
- */
-public class TextContentAssistSubjectAdapter extends AbstractControlContentAssistSubjectAdapter {
-
- /**
- * The <code>Document</code> of <code>fCombo</code>'s contents.
- */
- private class InternalDocument extends Document {
-
- /**
- * Updates this <code>Document</code> with changes in <code>fText</code>.
- */
- private ModifyListener fModifyListener;
-
- private InternalDocument() {
- super(fText.getText());
- fModifyListener= new ModifyListener() {
- /*
- * @see org.eclipse.swt.events.ModifyListener#modifyText(org.eclipse.swt.events.ModifyEvent)
- */
- public void modifyText(ModifyEvent e) {
- set(fText.getText());
- }
- };
- fText.addModifyListener(fModifyListener);
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractDocument#replace(int, int, java.lang.String)
- */
- public void replace(int pos, int length, String text) throws BadLocationException {
- super.replace(pos, length, text);
- fText.removeModifyListener(fModifyListener);
- fText.setText(get());
- fText.addModifyListener(fModifyListener);
- }
- }
-
- /** The text. */
- private Text fText;
- /** The modify listeners. */
- private HashMap fModifyListeners;
-
- /**
- * Creates a content assist subject control adapter for the given text.
- *
- * @param text the text to adapt
- */
- public TextContentAssistSubjectAdapter(Text text) {
- Assert.isNotNull(text);
- fText= text;
- }
-
- /**
- * {@inheritDoc}
- */
- public Control getControl() {
- return fText;
- }
-
- /**
- * {@inheritDoc}
- */
- public int getLineHeight() {
- return fText.getLineHeight();
- }
-
- /**
- * {@inheritDoc}
- */
- public int getCaretOffset() {
- return fText.getCaretPosition();
- }
-
- /**
- * {@inheritDoc}
- */
- public Point getLocationAtOffset(int offset) {
- Point caretLocation= fText.getCaretLocation();
- /*
- * FIXME workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=52520
- */
- caretLocation.y += 2;
- return caretLocation;
- }
-
- /**
- * {@inheritDoc}
- */
- public Point getWidgetSelectionRange() {
- return new Point(fText.getSelection().x, Math.abs(fText.getSelection().y - fText.getSelection().x));
- }
-
- /**
- * {@inheritDoc}
- */
- public Point getSelectedRange() {
- return new Point(fText.getSelection().x, Math.abs(fText.getSelection().y - fText.getSelection().x));
- }
-
- /**
- * {@inheritDoc}
- */
- public IDocument getDocument() {
- IDocument document= (IDocument)fText.getData("document"); //$NON-NLS-1$
- if (document == null) {
- document= new InternalDocument() ;
- fText.setData("document", document); //$NON-NLS-1$
- }
- return document;
- }
-
- /**
- * {@inheritDoc}
- */
- public void setSelectedRange(int i, int j) {
- fText.setSelection(new Point(i, i+j));
- }
-
- /**
- * {@inheritDoc}
- */
- public void revealRange(int i, int j) {
- // XXX: this should be improved
- fText.setSelection(new Point(i, i+j));
- }
-
- /**
- * {@inheritDoc}
- */
- public boolean addSelectionListener(final SelectionListener selectionListener) {
- fText.addSelectionListener(selectionListener);
- Listener listener= new Listener() {
- /**
- * {@inheritDoc}
- */
- public void handleEvent(Event e) {
- selectionListener.widgetSelected(new SelectionEvent(e));
-
- }
- };
- fText.addListener(SWT.Modify, listener);
- fModifyListeners.put(selectionListener, listener);
- return true;
- }
-
- /**
- * {@inheritDoc}
- */
- public void removeSelectionListener(SelectionListener selectionListener) {
- fText.removeSelectionListener(selectionListener);
- Object listener= fModifyListeners.get(selectionListener);
- if (listener instanceof Listener)
- fText.removeListener(SWT.Modify, (Listener)listener);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/images/content_assist_cue.gif b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/images/content_assist_cue.gif
deleted file mode 100644
index fe62b77f4e7..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/images/content_assist_cue.gif
+++ /dev/null
Binary files differ
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/package.html
deleted file mode 100644
index 017a01312e3..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/contentassist/package.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a content assist add-on for implementors of <tt>IContentAssistSubjectControl</tt>.
-Content assist supports the user in writing&nbsp; by proposing context
-sensitive completions at a given position. A completion can also
-be a incomplete in itself and content assist provides means to deal with
-nested completions.
-<h2>
-Package Specification</h2>
-<tt>ISubjectControlContentAssistant</tt> defines the concept of the content assist add-on.
-It collaborates with content type specific completion processors (<tt>ISubjectControlContentAssistProcessor</tt>)
-in order to generate completion proposals (<tt>ICompletionProposal</tt>)
-valid at the current document position. The package provides a default
-implementation <tt>SubjectControlContentAssistant</tt> which completely defines and implements
-the UI and the control flow for content assist.
-<br>&nbsp;
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java
deleted file mode 100644
index 1738d9e64ce..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/AdditionalInfoController2.java
+++ /dev/null
@@ -1,255 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-import org.eclipse.jface.text.AbstractInformationControlManager;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
-
-
-
-/**
- * Displays the additional information available for a completion proposal.
- *
- * @since 2.0
- */
-class AdditionalInfoController2 extends AbstractInformationControlManager implements Runnable {
-
- /**
- * Internal table selection listener.
- */
- private class TableSelectionListener implements SelectionListener {
-
- /*
- * @see SelectionListener#widgetSelected(SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- handleTableSelectionChanged();
- }
-
- /*
- * @see SelectionListener#widgetDefaultSelected(SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- }
-
-
- /** The proposal table */
- private Table fProposalTable;
- /** The thread controlling the delayed display of the additional info */
- private Thread fThread;
- /** Indicates whether the display delay has been reset */
- private boolean fIsReset= false;
- /** Object to synchronize display thread and table selection changes */
- private final Object fMutex= new Object();
- /** Thread access lock. */
- private final Object fThreadAccess= new Object();
- /** Object to synchronize initial display of additonal info */
- private Object fStartSignal;
- /** The table selection listener */
- private SelectionListener fSelectionListener= new TableSelectionListener();
- /** The delay after which additional information is displayed */
- private int fDelay;
-
-
- /**
- * Creates a new additional information controller.
- *
- * @param creator the information control creator to be used by this controller
- * @param delay time in milliseconds after which additional info should be displayed
- */
- AdditionalInfoController2(IInformationControlCreator creator, int delay) {
- super(creator);
- fDelay= delay;
- setAnchor(ANCHOR_RIGHT);
- setFallbackAnchors(new Anchor[] { ANCHOR_LEFT, ANCHOR_BOTTOM, ANCHOR_RIGHT });
- }
-
- /*
- * @see AbstractInformationControlManager#install(Control)
- */
- public void install(Control control) {
-
- if (fProposalTable == control) {
- // already installed
- return;
- }
-
- super.install(control);
-
- Assert.isTrue(control instanceof Table);
- fProposalTable= (Table) control;
- fProposalTable.addSelectionListener(fSelectionListener);
- synchronized (fThreadAccess) {
- if (fThread != null)
- fThread.interrupt();
- fThread= new Thread(this, ContentAssistMessages.getString("InfoPopup.info_delay_timer_name")); //$NON-NLS-1$
-
- fStartSignal= new Object();
- synchronized (fStartSignal) {
- fThread.start();
- try {
- // wait until thread is ready
- fStartSignal.wait();
- } catch (InterruptedException x) {
- }
- }
- }
- }
-
- /*
- * @see AbstractInformationControlManager#disposeInformationControl()
- */
- public void disposeInformationControl() {
-
- synchronized (fThreadAccess) {
- if (fThread != null) {
- fThread.interrupt();
- fThread= null;
- }
- }
-
- if (fProposalTable != null && !fProposalTable.isDisposed()) {
- fProposalTable.removeSelectionListener(fSelectionListener);
- fProposalTable= null;
- }
-
- super.disposeInformationControl();
- }
-
- /*
- * @see java.lang.Runnable#run()
- */
- public void run() {
- try {
- while (true) {
-
- synchronized (fMutex) {
-
- if (fStartSignal != null) {
- synchronized (fStartSignal) {
- fStartSignal.notifyAll();
- fStartSignal= null;
- }
- }
-
- // Wait for a selection event to occur.
- fMutex.wait();
-
- while (true) {
- fIsReset= false;
- // Delay before showing the popup.
- fMutex.wait(fDelay);
- if (!fIsReset)
- break;
- }
- }
-
- if (fProposalTable != null && !fProposalTable.isDisposed()) {
- fProposalTable.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!fIsReset)
- showInformation();
- }
- });
- }
-
- }
- } catch (InterruptedException e) {
- }
-
- synchronized (fThreadAccess) {
- // only null fThread if it is us!
- if (Thread.currentThread() == fThread)
- fThread= null;
- }
- }
-
- /**
- *Handles a change of the line selected in the associated selector.
- */
- public void handleTableSelectionChanged() {
-
- if (fProposalTable != null && !fProposalTable.isDisposed() && fProposalTable.isVisible()) {
- synchronized (fMutex) {
- fIsReset= true;
- fMutex.notifyAll();
- }
- }
- }
-
- /*
- * @see AbstractInformationControlManager#computeInformation()
- */
- protected void computeInformation() {
-
- if (fProposalTable == null || fProposalTable.isDisposed())
- return;
-
- TableItem[] selection= fProposalTable.getSelection();
- if (selection != null && selection.length > 0) {
-
- TableItem item= selection[0];
-
- // compute information
- String information= null;
- Object d= item.getData();
-
- if (d instanceof ICompletionProposal) {
- ICompletionProposal p= (ICompletionProposal) d;
- information= p.getAdditionalProposalInfo();
- }
-
- if (d instanceof ICompletionProposalExtension3)
- setCustomInformationControlCreator(((ICompletionProposalExtension3) d).getInformationControlCreator());
- else
- setCustomInformationControlCreator(null);
-
- // compute subject area
- setMargins(4, -1);
- Rectangle area= fProposalTable.getBounds();
- area.x= 0; // subject area is the whole subject control
- area.y= 0;
-
- // set information & subject area
- setInformation(information, area);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractInformationControlManager#computeSizeConstraints(Control, IInformationControl)
- */
- protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) {
- Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl);
- Point size= subjectControl.getSize();
- if (sizeConstraint.x < size.x)
- sizeConstraint.x= size.x;
- if (sizeConstraint.y < size.y)
- sizeConstraint.y= size.y;
- return sizeConstraint;
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java
deleted file mode 100644
index 56f68009f38..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/CompletionProposalPopup2.java
+++ /dev/null
@@ -1,871 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-import org.eclipse.jface.resource.JFaceResources;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-
-
-
-/**
- * This class is used to present proposals to the user. If additional
- * information exists for a proposal, then selecting that proposal
- * will result in the information being displayed in a secondary
- * window.
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposal
- * @see org.eclipse.jface.text.contentassist.AdditionalInfoController
- */
-class CompletionProposalPopup2 implements IContentAssistListener2 {
-
- /** The associated text viewer */
- private ITextViewer fViewer;
- /** The associated content assistant */
- private ContentAssistant2 fContentAssistant;
- /** The used additional info controller */
- private AdditionalInfoController2 fAdditionalInfoController;
- /** The closing strategy for this completion proposal popup */
- private PopupCloser2 fPopupCloser= new PopupCloser2();
- /** The popup shell */
- private Shell fProposalShell;
- /** The proposal table */
- private Table fProposalTable;
- /** Indicates whether a completion proposal is being inserted */
- private boolean fInserting= false;
- /** The key listener to control navigation */
- private KeyListener fKeyListener;
- /** List of document events used for filtering proposals */
- private List fDocumentEvents= new ArrayList();
- /** Listener filling the document event queue */
- private IDocumentListener fDocumentListener;
- /** Reentrance count for <code>filterProposals</code> */
- private long fInvocationCounter= 0;
- /** The filter list of proposals */
- private ICompletionProposal[] fFilteredProposals;
- /** The computed list of proposals */
- private ICompletionProposal[] fComputedProposals;
- /** The offset for which the proposals have been computed */
- private int fInvocationOffset;
- /** The offset for which the computed proposaks have been filtered */
- private int fFilterOffset;
- /** The default line delimiter of the viewer's widget */
- private String fLineDelimiter;
- /** The most recently selected proposal. */
- private ICompletionProposal fLastProposal;
-
-
- /**
- * Creates a new completion proposal popup for the given elements.
- *
- * @param contentAssistant the content assistant feeding this popup
- * @param viewer the viewer on top of which this popup appears
- * @param infoController the info control collaborating with this popup
- * @since 2.0
- */
- public CompletionProposalPopup2(ContentAssistant2 contentAssistant, ITextViewer viewer, AdditionalInfoController2 infoController) {
- fContentAssistant= contentAssistant;
- fViewer= viewer;
- fAdditionalInfoController= infoController;
- }
-
- /**
- * Computes and presents completion proposals. The flag indicates whether this call has
- * be made out of an auto activation context.
- *
- * @param autoActivated <code>true</code> if auto activation context
- * @return an error message or <code>null</code> in case of no error
- */
- public String showProposals(final boolean autoActivated) {
-
- if (fKeyListener == null) {
- fKeyListener= new KeyListener() {
- public void keyPressed(KeyEvent e) {
- if (!Helper2.okToUse(fProposalShell))
- return;
-
- if (e.character == 0 && e.keyCode == SWT.MOD1) {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
- int index= fProposalTable.getSelectionIndex();
- if (index >= 0)
- selectProposal(index, true);
- }
- }
-
- public void keyReleased(KeyEvent e) {
- if (!Helper2.okToUse(fProposalShell))
- return;
-
- if (e.character == 0 && e.keyCode == SWT.MOD1) {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
- int index= fProposalTable.getSelectionIndex();
- if (index >= 0)
- selectProposal(index, false);
- }
- }
- };
- }
-
- final StyledText styledText= fViewer.getTextWidget();
- if (styledText != null && !styledText.isDisposed())
- styledText.addKeyListener(fKeyListener);
-
-// BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() {
-// public void run() {
-
- fInvocationOffset= fViewer.getSelectedRange().x;
- // lazily compute proposals
-// if (fComputedProposals == null) fComputedProposals= computeProposals(fContentAssistant.getCompletionPosition());
- fComputedProposals= computeProposals(fInvocationOffset);
-
- int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
- if (count == 0) {
-
- if (!autoActivated)
- styledText.getDisplay().beep();
-
- } else {
-
- if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting())
-
- insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
-
- else {
-
- if (fLineDelimiter == null)
- fLineDelimiter= styledText.getLineDelimiter();
-
- createProposalSelector();
- setProposals(fComputedProposals);
- resizeProposalSelector(true);
- displayProposals();
- }
- }
-// }
-// });
-
- return getErrorMessage();
- }
-
- /**
- * Returns the completion proposal available at the given offset of the
- * viewer's document. Delegates the work to the content assistant.
- *
- * @param offset the offset
- * @return the completion proposals available at this offset
- */
- private ICompletionProposal[] computeProposals(int offset) {
- return fContentAssistant.computeCompletionProposals(fViewer, offset);
- }
-
- /**
- * Returns the error message.
- *
- * @return the error message
- */
- private String getErrorMessage() {
- return fContentAssistant.getErrorMessage();
- }
-
- /**
- * Creates the proposal selector.
- */
- private void createProposalSelector() {
- if (Helper2.okToUse(fProposalShell))
- return;
-
- Control control= fViewer.getTextWidget();
- fProposalShell= new Shell(control.getShell(), SWT.ON_TOP);
-// fProposalShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE );
- fProposalTable= new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL);
-// fProposalTable= new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL);
-
- fProposalTable.setLocation(0, 0);
- if (fAdditionalInfoController != null)
- fAdditionalInfoController.setSizeConstraints(50, 10, true, false);
-
- GridLayout layout= new GridLayout();
- layout.marginWidth= 0;
- layout.marginHeight= 0;
- fProposalShell.setLayout(layout);
-
- GridData data= new GridData(GridData.FILL_BOTH);
- fProposalTable.setLayoutData(data);
-
- fProposalShell.pack();
-
- // set location
- Point currentLocation= fProposalShell.getLocation();
- Point newLocation= getLocation();
- if ((newLocation.x < currentLocation.x && newLocation.y == currentLocation.y) || newLocation.y < currentLocation.y)
- fProposalShell.setLocation(newLocation);
-
- if (fAdditionalInfoController != null) {
- fProposalShell.addControlListener(new ControlListener() {
-
- public void controlMoved(ControlEvent e) {}
-
- public void controlResized(ControlEvent e) {
- // resets the cached resize constraints
- fAdditionalInfoController.setSizeConstraints(50, 10, true, false);
- }
- });
- }
-
- fProposalShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
- Color c= fContentAssistant.getProposalSelectorBackground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fProposalTable.setBackground(c);
-
- c= fContentAssistant.getProposalSelectorForeground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fProposalTable.setForeground(c);
-
- fProposalTable.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {}
-
- public void widgetDefaultSelected(SelectionEvent e) {
- selectProposalWithMask(e.stateMask);
- }
- });
-
- fPopupCloser.install(fContentAssistant, fProposalTable);
-
- fProposalShell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- unregister(); // but don't dispose the shell, since we're being called from its disposal event!
- }
- });
-
- fProposalTable.setHeaderVisible(false);
- fContentAssistant.addToLayout(this, fProposalShell, ContentAssistant2.LayoutManager.LAYOUT_PROPOSAL_SELECTOR, fContentAssistant.getSelectionOffset());
- }
-
- /**
- * Returns the proposal selected in the proposal selector.
- *
- * @return the selected proposal
- * @since 2.0
- */
- private ICompletionProposal getSelectedProposal() {
- int i= fProposalTable.getSelectionIndex();
- if (i < 0 || i >= fFilteredProposals.length)
- return null;
- return fFilteredProposals[i];
- }
-
- /**
- * Takes the selected proposal and applies it.
- *
- * @param stateMask the state mask
- * @since 2.1
- */
- private void selectProposalWithMask(int stateMask) {
- ICompletionProposal p= getSelectedProposal();
- hide();
- if (p != null)
- insertProposal(p, (char) 0, stateMask, fViewer.getSelectedRange().x);
- }
-
- /**
- * Applies the given proposal at the given offset. The given character is the
- * one that triggered the insertion of this proposal.
- *
- * @param p the completion proposal
- * @param trigger the trigger character
- * @param offset the offset
- * @since 2.1
- */
- private void insertProposal(ICompletionProposal p, char trigger, int stateMask, int offset) {
-
- fInserting= true;
- IRewriteTarget target= null;
-
- try {
-
- IDocument document= fViewer.getDocument();
-
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fViewer;
- target= extension.getRewriteTarget();
- }
-
- if (target != null)
- target.beginCompoundChange();
-
- if (p instanceof ICompletionProposalExtension2) {
- ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
- e.apply(fViewer, trigger, stateMask, offset);
- } else if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension e= (ICompletionProposalExtension) p;
- e.apply(document, trigger, offset);
- } else {
- p.apply(document);
- }
-
- Point selection= p.getSelection(document);
- if (selection != null) {
- fViewer.setSelectedRange(selection.x, selection.y);
- fViewer.revealRange(selection.x, selection.y);
- }
-
- IContextInformation info= p.getContextInformation();
- if (info != null) {
-
- int position;
- if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension e= (ICompletionProposalExtension) p;
- position= e.getContextInformationPosition();
- } else {
- if (selection == null)
- selection= fViewer.getSelectedRange();
- position= selection.x + selection.y;
- }
-
- fContentAssistant.showContextInformation(info, position);
- }
-
- fContentAssistant.fireProposalChosen(p);
-
- } finally {
- if (target != null)
- target.endCompoundChange();
- fInserting= false;
- }
- }
-
- /**
- * Returns whether this popup has the focus.
- *
- * @return <code>true</code> if the popup has the focus
- */
- public boolean hasFocus() {
- if (Helper2.okToUse(fProposalShell))
- return (fProposalShell.isFocusControl() || fProposalTable.isFocusControl());
-
- return false;
- }
-
- /**
- * Hides this popup.
- */
- public void hide() {
-
- unregister();
-
- if (Helper2.okToUse(fProposalShell)) {
- fContentAssistant.removeContentAssistListener(this, ContentAssistant2.PROPOSAL_SELECTOR);
-
- fPopupCloser.uninstall();
- // see bug 47511: setVisible may run the event loop on GTK
- // and trigger a rentrant call - have to make sure we don't
- // dispose another shell that was already brought up in a
- // reentrant call when calling setVisible()
- Shell tempShell= fProposalShell;
- fProposalShell= null;
- tempShell.setVisible(false);
- tempShell.dispose();
- }
- }
-
- private void unregister() {
- if (fDocumentListener != null) {
- IDocument document= fViewer.getDocument();
- if (document != null)
- document.removeDocumentListener(fDocumentListener);
- fDocumentListener= null;
- }
- fDocumentEvents.clear();
-
- StyledText styledText= fViewer.getTextWidget();
- if (fKeyListener != null && styledText != null && !styledText.isDisposed())
- styledText.removeKeyListener(fKeyListener);
-
- if (fLastProposal != null) {
- if (fLastProposal instanceof ICompletionProposalExtension2) {
- ICompletionProposalExtension2 extension= (ICompletionProposalExtension2) fLastProposal;
- extension.unselected(fViewer);
- }
-
- fLastProposal= null;
- }
-
- fFilteredProposals= null;
-
- fContentAssistant.possibleCompletionsClosed();
- }
-
- /**
- *Returns whether this popup is active. It is active if the propsal selector is visible.
- *
- * @return <code>true</code> if this popup is active
- */
- public boolean isActive() {
- return fProposalShell != null && !fProposalShell.isDisposed();
- }
-
- /**
- * Initializes the proposal selector with these given proposals.
- *
- * @param proposals the proposals
- */
- private void setProposals(ICompletionProposal[] proposals) {
- if (Helper2.okToUse(fProposalTable)) {
-
- ICompletionProposal oldProposal= getSelectedProposal();
- if (oldProposal instanceof ICompletionProposalExtension2)
- ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
-
- fFilteredProposals= proposals;
-
- fProposalTable.setRedraw(false);
- fProposalTable.removeAll();
-
- Point selection= fViewer.getSelectedRange();
- int endOffset;
- endOffset= selection.x + selection.y;
- IDocument document= fViewer.getDocument();
- boolean validate= false;
- if (selection.y != 0 && document != null) validate= true;
- int selectionIndex= 0;
-
- TableItem item;
- ICompletionProposal p;
- for (int i= 0; i < proposals.length; i++) {
- p= proposals[i];
- item= new TableItem(fProposalTable, SWT.NULL);
- if (p.getImage() != null)
- item.setImage(p.getImage());
- item.setText(p.getDisplayString());
- item.setData(p);
-
- if (validate && validateProposal(document, p, endOffset, null)) {
- selectionIndex= i;
- validate= false;
- }
- }
-
- resizeProposalSelector(false);
-
- selectProposal(selectionIndex, false);
- fProposalTable.setRedraw(true);
- }
- }
-
- private void resizeProposalSelector(boolean adjustWidth) {
- // in order to fill in the table items so size computation works correctly
- // will cause flicker, though
- fProposalTable.setRedraw(true);
-
- int width= adjustWidth ? SWT.DEFAULT : ((GridData)fProposalTable.getLayoutData()).widthHint;
- Point size= fProposalTable.computeSize(width, SWT.DEFAULT, true);
-
- GridData data= new GridData(GridData.FILL_BOTH);
- data.widthHint= adjustWidth ? Math.min(size.x, 300) : width;
- data.heightHint= Math.min(getTableHeightHint(fProposalTable, fProposalTable.getItemCount()), getTableHeightHint(fProposalTable, 10));
- fProposalTable.setLayoutData(data);
-
- fProposalShell.layout(true);
- fProposalShell.pack();
-
- if (adjustWidth) {
- fProposalShell.setLocation(getLocation());
- }
- }
-
- /**
- * Computes the table hight hint for <code>table</code>.
- *
- * @param table the table to compute the height for
- * @param rows the number of rows to compute the height for
- * @return the height hint for <code>table</code>
- */
- private int getTableHeightHint(Table table, int rows) {
- if (table.getFont().equals(JFaceResources.getDefaultFont()))
- table.setFont(JFaceResources.getDialogFont());
- int result= table.getItemHeight() * rows;
- if (table.getLinesVisible())
- result+= table.getGridLineWidth() * (rows - 1);
-
- // TODO adjustment might just work on windows
-// return result + 4;
- return result;
- }
-
- private boolean validateProposal(IDocument document, ICompletionProposal p, int offset, DocumentEvent event) {
- // detect selected
- if (p instanceof ICompletionProposalExtension2) {
- ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
- if (e.validate(document, offset, event))
- return true;
- } else if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension e= (ICompletionProposalExtension) p;
- if (e.isValidFor(document, offset))
- return true;
- }
- return false;
- }
-
- /**
- * Returns the graphical location at which this popup should be made visible.
- *
- * @return the location of this popup
- */
- private Point getLocation() {
- StyledText text= fViewer.getTextWidget();
- Point selection= text.getSelection();
- Point p= text.getLocationAtOffset(selection.x);
- // TODO subtract border width!
- p.x -= fProposalShell.getBorderWidth();
- if (p.x < 0) p.x= 0;
- if (p.y < 0) p.y= 0;
- p= new Point(p.x, p.y + text.getLineHeight());
- p= text.toDisplay(p);
- if (p.x < 0) p.x= 0;
- if (p.y < 0) p.y= 0;
- return p;
- }
-
- /**
- *Displays this popup and install the additional info controller, so that additional info
- * is displayed when a proposal is selected and additional info is available.
- */
- private void displayProposals() {
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.PROPOSAL_SELECTOR)) {
-
- if (fDocumentListener == null)
- fDocumentListener= new IDocumentListener() {
- public void documentAboutToBeChanged(DocumentEvent event) {
- if (!fInserting)
- fDocumentEvents.add(event);
- }
-
- public void documentChanged(DocumentEvent event) {
- if (!fInserting)
- filterProposals();
- }
- };
- IDocument document= fViewer.getDocument();
- if (document != null)
- document.addDocumentListener(fDocumentListener);
-
- fProposalShell.setVisible(true);
- // see bug 47511: setVisible may run the event loop on GTK
- // and trigger a rentrant call - have to check whether we are still
- // visible
- if (!Helper2.okToUse(fProposalShell))
- return;
-
-
- if (fAdditionalInfoController != null) {
- fAdditionalInfoController.install(fProposalTable);
- fAdditionalInfoController.handleTableSelectionChanged();
- }
- }
- }
-
- /*
- * @see IContentAssistListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent e) {
- if (!Helper2.okToUse(fProposalShell))
- return true;
-
- char key= e.character;
- if (key == 0) {
- int newSelection= fProposalTable.getSelectionIndex();
- int visibleRows= (fProposalTable.getSize().y / fProposalTable.getItemHeight()) - 1;
- boolean smartToggle= false;
- switch (e.keyCode) {
-
- case SWT.ARROW_LEFT :
- case SWT.ARROW_RIGHT :
- filterProposals();
- return true;
-
- case SWT.ARROW_UP :
- newSelection -= 1;
- if (newSelection < 0)
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- case SWT.ARROW_DOWN :
- newSelection += 1;
- if (newSelection > fProposalTable.getItemCount() - 1)
- newSelection= 0;
- break;
-
- case SWT.PAGE_DOWN :
- newSelection += visibleRows;
- if (newSelection >= fProposalTable.getItemCount())
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- case SWT.PAGE_UP :
- newSelection -= visibleRows;
- if (newSelection < 0)
- newSelection= 0;
- break;
-
- case SWT.HOME :
- newSelection= 0;
- break;
-
- case SWT.END :
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- default :
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hide();
- return true;
- }
-
- selectProposal(newSelection, smartToggle);
-
- e.doit= false;
- return false;
-
- } else {
-
- switch (key) {
- case 0x1B: // Esc
- e.doit= false;
- hide();
- break;
-
- case '\n': // Ctrl-Enter on w2k
- case '\r': // Enter
- e.doit= false;
- selectProposalWithMask(e.stateMask);
- break;
-
- // in linked mode: hide popup
- // plus: don't invalidate the event in order to give LinkedUI a chance to handle it
- case '\t':
-// hide();
- break;
-
- default:
- ICompletionProposal p= getSelectedProposal();
- if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension t= (ICompletionProposalExtension) p;
- char[] triggers= t.getTriggerCharacters();
- if (contains(triggers, key)) {
- hide();
- if (key == ';') {
- e.doit= true;
- insertProposal(p, (char) 0, e.stateMask, fViewer.getSelectedRange().x);
- } else {
- e.doit= false;
- insertProposal(p, key, e.stateMask, fViewer.getSelectedRange().x);
- }
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Selects the entry with the given index in the proposal selector and feeds
- * the selection to the additional info controller.
- *
- * @param index the index in the list
- * @param smartToggle <code>true</code> if the smart toogle key has been pressed
- * @since 2.1
- */
- private void selectProposal(int index, boolean smartToggle) {
-
- ICompletionProposal oldProposal= getSelectedProposal();
- if (oldProposal instanceof ICompletionProposalExtension2)
- ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
-
- ICompletionProposal proposal= fFilteredProposals[index];
- if (proposal instanceof ICompletionProposalExtension2)
- ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
-
- fLastProposal= proposal;
-
- fProposalTable.setSelection(index);
- fProposalTable.showSelection();
- if (fAdditionalInfoController != null)
- fAdditionalInfoController.handleTableSelectionChanged();
- }
-
- /**
- * Returns whether the given character is contained in the given array of
- * characters.
- *
- * @param characters the list of characters
- * @param c the character to look for in the list
- * @return <code>true</code> if character belongs to the list
- * @since 2.0
- */
- private boolean contains(char[] characters, char c) {
-
- if (characters == null)
- return false;
-
- for (int i= 0; i < characters.length; i++) {
- if (c == characters[i])
- return true;
- }
-
- return false;
- }
-
- /*
- * @see IEventConsumer#processEvent(VerifyEvent)
- */
- public void processEvent(VerifyEvent e) {
- }
-
- /**
- * Filters the displayed proposal based on the given cursor position and the
- * offset of the original invocation of the content assistant.
- */
- private void filterProposals() {
- ++ fInvocationCounter;
- Control control= fViewer.getTextWidget();
- control.getDisplay().asyncExec(new Runnable() {
- long fCounter= fInvocationCounter;
- public void run() {
-
- if (fCounter != fInvocationCounter) return;
-
- int offset= fViewer.getSelectedRange().x;
- ICompletionProposal[] proposals= null;
- try {
- if (offset > -1) {
- DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents);
- proposals= computeFilteredProposals(offset, event);
- }
- } catch (BadLocationException x) {
- } finally {
- fDocumentEvents.clear();
- }
- fFilterOffset= offset;
-
- if (proposals != null && proposals.length > 0)
- setProposals(proposals);
- else
- hide();
- }
- });
- }
-
- /**
- * Computes the subset of already computed propsals that are still valid for
- * the given offset.
- *
- * @param offset the offset
- * @param event the merged document event
- * @return the set of filtered proposals
- * @since 2.0
- */
- private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event) {
-
- if (offset == fInvocationOffset && event == null)
- return fComputedProposals;
-
- if (offset < fInvocationOffset) {
- return null;
- }
-
- ICompletionProposal[] proposals= fComputedProposals;
- if (offset > fFilterOffset)
- proposals= fFilteredProposals;
-
- if (proposals == null)
- return null;
-
- IDocument document= fViewer.getDocument();
- int length= proposals.length;
- List filtered= new ArrayList(length);
- for (int i= 0; i < length; i++) {
-
- if (proposals[i] instanceof ICompletionProposalExtension2) {
-
- ICompletionProposalExtension2 p= (ICompletionProposalExtension2) proposals[i];
- if (p.validate(document, offset, event))
- filtered.add(p);
-
- } else if (proposals[i] instanceof ICompletionProposalExtension) {
-
- ICompletionProposalExtension p= (ICompletionProposalExtension) proposals[i];
- if (p.isValidFor(document, offset))
- filtered.add(p);
-
- } else {
- // restore original behavior
- fInvocationOffset= offset;
- fComputedProposals= computeProposals(fInvocationOffset);
- return fComputedProposals;
- }
- }
-
- ICompletionProposal[] p= new ICompletionProposal[filtered.size()];
- filtered.toArray(p);
- return p;
- }
-
- /**
- * Requests the proposal shell to take focus.
- *
- * @since 3.0
- */
- public void setFocus() {
- if (Helper2.okToUse(fProposalShell))
- fProposalShell.setFocus();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java
deleted file mode 100644
index 7dd029028b6..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-
-/**
- * Helper class to get NLSed messages.
- *
- * @since 3.0
- */
-class ContentAssistMessages {
-
- private static final String RESOURCE_BUNDLE= ContentAssistMessages.class.getName();
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private ContentAssistMessages() {
- }
-
- /**
- * Gets a string from the resource bundle.
- *
- * @param key the string used to get the bundle value, must not be null
- * @return the string from the resource bundle
- */
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the given arguments.
- *
- * @param key the string used to get the bundle value, must not be null
- * @param args the arguments used to format the string
- * @return the formatted string
- */
- public static String getFormattedString(String key, Object[] args) {
- String format= null;
- try {
- format= fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- return MessageFormat.format(format, args);
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the given argument.
- *
- * @param key the string used to get the bundle value, must not be null
- * @param arg the argument used to format the string
- * @return the formatted string
- */
- public static String getFormattedString(String key, Object arg) {
- String format= null;
- try {
- format= fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- if (arg == null)
- arg= ""; //$NON-NLS-1$
- return MessageFormat.format(format, new Object[] { arg });
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.properties
deleted file mode 100644
index 8aa64448ae1..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistMessages.properties
+++ /dev/null
@@ -1,19 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-
-
-InfoPopup.info_delay_timer_name=AdditionalInfo Delay
-
-ContentAssistant.assist_delay_timer_name=AutoAssist Delay
-
-HTMLTextPresenter.ellipse= ...
-
-HTML2TextReader.listItemPrefix=\t-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java
deleted file mode 100644
index 7d33f4997fe..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContentAssistant2.java
+++ /dev/null
@@ -1,1587 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Widget;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultInformationControl;
-import org.eclipse.jface.text.IEventConsumer;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.IWidgetTokenKeeper;
-import org.eclipse.jface.text.IWidgetTokenKeeperExtension;
-import org.eclipse.jface.text.IWidgetTokenOwner;
-import org.eclipse.jface.text.IWidgetTokenOwnerExtension;
-import org.eclipse.jface.text.TextUtilities;
-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.IContentAssistant;
-import org.eclipse.jface.text.contentassist.IContentAssistantExtension;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-
-
-/**
- * A custom implementation of the <code>IContentAssistant</code> interface.
- * This implementation is used by the linked mode ui. This is internal and subject
- * to change without notice.
- */
-public class ContentAssistant2 implements IContentAssistant, IContentAssistantExtension, IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
-
- /**
- * A generic closer class used to monitor various
- * interface events in order to determine whether
- * content-assist should be terminated and all
- * associated windows closed.
- */
- class Closer implements ControlListener, MouseListener, FocusListener, DisposeListener, IViewportListener {
-
- /**
- * Installs this closer on it's viewer's text widget.
- */
- protected void install() {
- Control w= fViewer.getTextWidget();
- if (Helper2.okToUse(w)) {
-
- Control shell= w.getShell();
- shell.addControlListener(this);
-
- w.addMouseListener(this);
- w.addFocusListener(this);
-
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- w.addDisposeListener(this);
- }
-
- fViewer.addViewportListener(this);
- }
-
- /**
- * Uninstalls this closer from the viewer's text widget.
- */
- protected void uninstall() {
- Control w= fViewer.getTextWidget();
- if (Helper2.okToUse(w)) {
-
- Control shell= w.getShell();
- if (Helper2.okToUse(shell))
- shell.removeControlListener(this);
-
- w.removeMouseListener(this);
- w.removeFocusListener(this);
-
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- w.removeDisposeListener(this);
- }
-
- fViewer.removeViewportListener(this);
- }
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent e) {
- hide();
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent e) {
- hide();
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent e) {
- hide();
- }
-
- /*
- * @see MouseListener#mouseUp(MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- hide();
- }
-
- /*
- * @see FocusListener#focusGained(FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see FocusListener#focusLost(FocusEvent)
- */
- public void focusLost(FocusEvent e) {
- if (fViewer != null) {
- Control control= fViewer.getTextWidget();
- if (control != null) {
- Display d= control.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- if (!hasFocus())
- hide();
- }
- });
- }
- }
- }
- }
-
- /*
- * @seeDisposeListener#widgetDisposed(DisposeEvent)
- */
- public void widgetDisposed(DisposeEvent e) {
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- hide();
- }
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int topIndex) {
- hide();
- }
-
- /**
- * Hides any open popups.
- */
- protected void hide() {
- fProposalPopup.hide();
- fContextInfoPopup.hide();
- }
- }
-
- /**
- * An implementation of <code>IContentAssistListener</code>, this class is
- * used to monitor key events in support of automatic activation
- * of the content assistant. If enabled, the implementation utilizes a
- * thread to watch for input characters matching the activation
- * characters specified by the content assist processor, and if
- * detected, will wait the indicated delay interval before
- * activating the content assistant.
- */
- class AutoAssistListener implements VerifyKeyListener, Runnable {
-
- private Thread fThread;
- private boolean fIsReset= false;
- private Object fMutex= new Object();
- private int fShowStyle;
-
- private final static int SHOW_PROPOSALS= 1;
- private final static int SHOW_CONTEXT_INFO= 2;
-
- protected AutoAssistListener() {
- }
-
- protected void start(int showStyle) {
- fShowStyle= showStyle;
- fThread= new Thread(this, ContentAssistMessages.getString("ContentAssistant.assist_delay_timer_name")); //$NON-NLS-1$
- fThread.start();
- }
-
- public void run() {
- try {
- while (true) {
- synchronized (fMutex) {
- if (fAutoActivationDelay != 0)
- fMutex.wait(fAutoActivationDelay);
- if (fIsReset) {
- fIsReset= false;
- continue;
- }
- }
- showAssist(fShowStyle);
- break;
- }
- } catch (InterruptedException e) {
- }
- fThread= null;
- }
-
- protected void reset(int showStyle) {
- synchronized (fMutex) {
- fShowStyle= showStyle;
- fIsReset= true;
- fMutex.notifyAll();
- }
- }
-
- protected void stop() {
- if (fThread != null) {
- fThread.interrupt();
- }
- }
-
- private boolean contains(char[] characters, char character) {
- if (characters != null) {
- for (int i= 0; i < characters.length; i++) {
- if (character == characters[i])
- return true;
- }
- }
- return false;
- }
-
- public void verifyKey(VerifyEvent e) {
- // Only act on typed characters and ignore modifier-only events
- if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0)
- return;
-
- int showStyle;
- int pos= fViewer.getSelectedRange().x;
- char[] activation= getCompletionProposalAutoActivationCharacters(fViewer, pos);
-
- if (contains(activation, e.character) && !fProposalPopup.isActive())
- showStyle= SHOW_PROPOSALS;
- else {
- activation= getContextInformationAutoActivationCharacters(fViewer, pos);
- if (contains(activation, e.character) && !fContextInfoPopup.isActive())
- showStyle= SHOW_CONTEXT_INFO;
- else {
- if (fThread != null && fThread.isAlive())
- stop();
- return;
- }
- }
-
- if (fThread != null && fThread.isAlive())
- reset(showStyle);
- else
- start(showStyle);
- }
-
- protected void showAssist(final int showStyle) {
- Control control= fViewer.getTextWidget();
- Display d= control.getDisplay();
- if (d != null) {
- try {
- d.syncExec(new Runnable() {
- public void run() {
- if (showStyle == SHOW_PROPOSALS)
- fProposalPopup.showProposals(true);
- else if (showStyle == SHOW_CONTEXT_INFO)
- fContextInfoPopup.showContextProposals(true);
- }
- });
- } catch (SWTError e) {
- }
- }
- }
- }
-
- /**
- * The laypout manager layouts the various
- * windows associated with the content assistant based on the
- * settings of the content assistant.
- */
- class LayoutManager implements Listener {
-
- // Presentation types.
- /** proposal selector */
- public final static int LAYOUT_PROPOSAL_SELECTOR= 0;
- /** context selector */
- public final static int LAYOUT_CONTEXT_SELECTOR= 1;
- /** context info */
- public final static int LAYOUT_CONTEXT_INFO_POPUP= 2;
-
- int fContextType= LAYOUT_CONTEXT_SELECTOR;
- Shell[] fShells= new Shell[3];
- Object[] fPopups= new Object[3];
-
- protected void add(Object popup, Shell shell, int type, int offset) {
- Assert.isNotNull(popup);
- Assert.isTrue(shell != null && !shell.isDisposed());
- checkType(type);
-
- if (fShells[type] != shell) {
- if (fShells[type] != null)
- fShells[type].removeListener(SWT.Dispose, this);
- shell.addListener(SWT.Dispose, this);
- fShells[type]= shell;
- }
-
- fPopups[type]= popup;
- if (type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP)
- fContextType= type;
-
- layout(type, offset);
- adjustListeners(type);
- }
-
- protected void checkType(int type) {
- Assert.isTrue(type == LAYOUT_PROPOSAL_SELECTOR ||
- type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP);
- }
-
- public void handleEvent(Event event) {
- Widget source= event.widget;
- source.removeListener(SWT.Dispose, this);
-
- int type= getShellType(source);
- checkType(type);
- fShells[type]= null;
-
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- if (fContextType == LAYOUT_CONTEXT_SELECTOR &&
- Helper2.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) {
- // Restore event notification to the tip popup.
- addContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR);
- }
- break;
-
- case LAYOUT_CONTEXT_SELECTOR:
- if (Helper2.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- if (fProposalPopupOrientation == PROPOSAL_STACKED)
- layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset());
- // Restore event notification to the proposal popup.
- addContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR);
- }
- fContextType= LAYOUT_CONTEXT_INFO_POPUP;
- break;
-
- case LAYOUT_CONTEXT_INFO_POPUP:
- if (Helper2.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- if (fContextInfoPopupOrientation == CONTEXT_INFO_BELOW)
- layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset());
- }
- fContextType= LAYOUT_CONTEXT_SELECTOR;
- break;
- }
- }
-
- protected int getShellType(Widget shell) {
- for (int i=0; i<fShells.length; i++) {
- if (fShells[i] == shell)
- return i;
- }
- return -1;
- }
-
- protected void layout(int type, int offset) {
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- layoutProposalSelector(offset);
- break;
- case LAYOUT_CONTEXT_SELECTOR:
- layoutContextSelector(offset);
- break;
- case LAYOUT_CONTEXT_INFO_POPUP:
- layoutContextInfoPopup(offset);
- break;
- }
- }
-
- protected void layoutProposalSelector(int offset) {
- if (fContextType == LAYOUT_CONTEXT_INFO_POPUP &&
- fContextInfoPopupOrientation == CONTEXT_INFO_BELOW &&
- Helper2.okToUse(fShells[LAYOUT_CONTEXT_INFO_POPUP])) {
- // Stack proposal selector beneath the tip box.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- shell.setLocation(getStackedLocation(shell, parent));
- } else if (fContextType != LAYOUT_CONTEXT_SELECTOR ||
- !Helper2.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) {
- // There are no other presentations to be concerned with,
- // so place the proposal selector beneath the cursor line.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- } else {
- switch (fProposalPopupOrientation) {
- case PROPOSAL_REMOVE: {
- // Remove the tip selector and place the
- // proposal selector beneath the cursor line.
- fShells[LAYOUT_CONTEXT_SELECTOR].dispose();
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- break;
- }
- case PROPOSAL_OVERLAY: {
- // Overlay the tip selector with the proposal selector.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- break;
- }
- case PROPOSAL_STACKED: {
- // Stack the proposal selector beneath the tip selector.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- break;
- }
- }
- }
- }
-
- protected void layoutContextSelector(int offset) {
- // Always place the context selector beneath the cursor line.
- Shell shell= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
-
- if (Helper2.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- switch (fProposalPopupOrientation) {
- case PROPOSAL_REMOVE:
- // Remove the proposal selector.
- fShells[LAYOUT_PROPOSAL_SELECTOR].dispose();
- break;
-
- case PROPOSAL_OVERLAY:
- // The proposal selector has been overlayed by the tip selector.
- break;
-
- case PROPOSAL_STACKED: {
- // Stack the proposal selector beneath the tip selector.
- shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- break;
- }
- }
- }
- }
-
- protected void layoutContextInfoPopup(int offset) {
- switch (fContextInfoPopupOrientation) {
- case CONTEXT_INFO_ABOVE: {
- // Place the popup above the cursor line.
- Shell shell= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- shell.setLocation(getAboveLocation(shell, offset));
- break;
- }
- case CONTEXT_INFO_BELOW: {
- // Place the popup beneath the cursor line.
- Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- parent.setLocation(getBelowLocation(parent, offset));
- if (Helper2.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- // Stack the proposal selector beneath the context info popup.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- }
- break;
- }
- }
- }
-
- protected void shiftHorizontalLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) {
- if (location.x + shellBounds.width > displayBounds.width)
- location.x= displayBounds.width - shellBounds.width;
-
- if (location.x < displayBounds.x)
- location.x= displayBounds.x;
- }
-
- protected void shiftVerticalLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) {
- if (location.y + shellBounds.height > displayBounds.height)
- location.y= displayBounds.height - shellBounds.height;
-
- if (location.y < displayBounds.y)
- location.y= displayBounds.y;
- }
-
- protected Point getAboveLocation(Shell shell, int offset) {
- StyledText text= fViewer.getTextWidget();
- Point location= text.getLocationAtOffset(offset);
- location= text.toDisplay(location);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
-
- location.y=location.y - shellBounds.height;
-
- shiftHorizontalLocation(location, shellBounds, displayBounds);
- shiftVerticalLocation(location, shellBounds, displayBounds);
-
- return location;
- }
-
- protected Point getBelowLocation(Shell shell, int offset) {
- StyledText text= fViewer.getTextWidget();
- Point location= text.getLocationAtOffset(offset);
- if (location.x < 0) location.x= 0;
- if (location.y < 0) location.y= 0;
- location= text.toDisplay(location);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
-
- location.y= location.y + text.getLineHeight();
- shiftHorizontalLocation(location, shellBounds, displayBounds);
- shiftVerticalLocation(location, shellBounds, displayBounds);
-
- return location;
- }
-
- protected Point getStackedLocation(Shell shell, Shell parent) {
- Point p= parent.getLocation();
- Point size= parent.getSize();
- p.x += size.x / 4;
- p.y += size.y;
-
- p= parent.toDisplay(p);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
- shiftHorizontalLocation(p, shellBounds, displayBounds);
- shiftVerticalLocation(p, shellBounds, displayBounds);
-
- return p;
- }
-
- protected void adjustListeners(int type) {
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- if (fContextType == LAYOUT_CONTEXT_SELECTOR &&
- Helper2.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR]))
- // Disable event notification to the tip selector.
- removeContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR);
- break;
- case LAYOUT_CONTEXT_SELECTOR:
- if (Helper2.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR]))
- // Disable event notification to the proposal selector.
- removeContentAssistListener((IContentAssistListener2) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR);
- break;
- case LAYOUT_CONTEXT_INFO_POPUP:
- break;
- }
- }
- }
-
- /**
- * Internal key listener and event consumer.
- */
- class InternalListener implements VerifyKeyListener, IEventConsumer {
-
- /**
- * Verifies key events by notifying the registered listeners.
- * Each listener is allowed to indicate that the event has been
- * handled and should not be further processed.
- *
- * @param e the verify event
- * @see VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
- */
- public void verifyKey(VerifyEvent e) {
- IContentAssistListener2[] listeners= (IContentAssistListener2[]) fListeners.clone();
- for (int i= 0; i < listeners.length; i++) {
- if (listeners[i] != null) {
- if (!listeners[i].verifyKey(e) || !e.doit)
- return;
- }
- }
- }
-
- /*
- * @see IEventConsumer#processEvent
- */
- public void processEvent(VerifyEvent event) {
-
- installKeyListener();
-
- IContentAssistListener2[] listeners= (IContentAssistListener2[])fListeners.clone();
- for (int i= 0; i < listeners.length; i++) {
- if (listeners[i] != null) {
- listeners[i].processEvent(event);
- if (!event.doit)
- return;
- }
- }
- }
- }
-
-
- // Content-Assist Listener types
- final static int CONTEXT_SELECTOR= 0;
- final static int PROPOSAL_SELECTOR= 1;
- final static int CONTEXT_INFO_POPUP= 2;
-
- /**
- * The popup priority: &gt; infopops, &lt; standard content assist.
- * Default value: <code>10</code>.
- *
- * @since 3.0
- */
- public static final int WIDGET_PRIORITY= 10;
-
-
- private static final int DEFAULT_AUTO_ACTIVATION_DELAY= 500;
-
- private IInformationControlCreator fInformationControlCreator;
- private int fAutoActivationDelay= DEFAULT_AUTO_ACTIVATION_DELAY;
- private boolean fIsAutoActivated= false;
- private boolean fIsAutoInserting= false;
- private int fProposalPopupOrientation= PROPOSAL_OVERLAY;
- private int fContextInfoPopupOrientation= CONTEXT_INFO_ABOVE;
- private Map fProcessors;
- private String fPartitioning;
-
- private Color fContextInfoPopupBackground;
- private Color fContextInfoPopupForeground;
- private Color fContextSelectorBackground;
- private Color fContextSelectorForeground;
- private Color fProposalSelectorBackground;
- private Color fProposalSelectorForeground;
-
- private ITextViewer fViewer;
- private String fLastErrorMessage;
-
- private Closer fCloser;
- private LayoutManager fLayoutManager;
- private AutoAssistListener fAutoAssistListener;
- private InternalListener fInternalListener;
- private CompletionProposalPopup2 fProposalPopup;
- private ContextInformationPopup2 fContextInfoPopup;
-
- private boolean fKeyListenerHooked= false;
- private IContentAssistListener2[] fListeners= new IContentAssistListener2[4];
- private int fCompletionPosition;
- private String[] fProposalStrings;
- private ICompletionProposal[] fProposals;
- private final List fProposalListeners= new ArrayList();
-
- /**
- * Creates a new content assistant. The content assistant is not automatically activated,
- * overlays the completion proposals with context information list if necessary, and
- * shows the context information above the location at which it was activated. If auto
- * activation will be enabled, without further configuration steps, this content assistant
- * is activated after a 500 ms delay. It uses the default partitioning.
- */
- public ContentAssistant2() {
- setContextInformationPopupOrientation(CONTEXT_INFO_ABOVE);
- setInformationControlCreator(getInformationControlCreator());
-
-// JavaTextTools textTools= JavaPlugin.getDefault().getJavaTextTools();
-// IColorManager manager= textTools.getColorManager();
-//
-// IPreferenceStore store= JavaPlugin.getDefault().getPreferenceStore();
-//
-// Color c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_FOREGROUND, manager);
-// setProposalSelectorForeground(c);
-//
-// c= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager);
-// setProposalSelectorBackground(c);
- }
-
- /**
- * Creates an <code>IInformationControlCreator</code> to be used to display context information.
- *
- * @return an <code>IInformationControlCreator</code> to be used to display context information
- */
- private IInformationControlCreator getInformationControlCreator() {
- return new IInformationControlCreator() {
- public IInformationControl createInformationControl(Shell parent) {
- return new DefaultInformationControl(parent, new HTMLTextPresenter());
- }
- };
- }
-
- /**
- * Sets the document partitioning this content assistant is using.
- *
- * @param partitioning the document partitioning for this content assistant
- */
- public void setDocumentPartitioning(String partitioning) {
- Assert.isNotNull(partitioning);
- fPartitioning= partitioning;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistantExtension#getDocumentPartitioning()
- * @since 3.0
- */
- public String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- /**
- * Registers a given content assist processor for a particular content type.
- * If there is already a processor registered for this type, the new processor
- * is registered instead of the old one.
- *
- * @param processor the content assist processor to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fProcessors == null)
- fProcessors= new HashMap();
-
- if (processor == null)
- fProcessors.remove(contentType);
- else
- fProcessors.put(contentType, processor);
- }
-
- /*
- * @see IContentAssistant#getContentAssistProcessor
- */
- public IContentAssistProcessor getContentAssistProcessor(String contentType) {
- if (fProcessors == null)
- return null;
-
- return (IContentAssistProcessor) fProcessors.get(contentType);
- }
-
- /**
- * Enables the content assistant's auto activation mode.
- *
- * @param enabled indicates whether auto activation is enabled or not
- */
- public void enableAutoActivation(boolean enabled) {
- fIsAutoActivated= enabled;
- manageAutoActivation(fIsAutoActivated);
- }
-
- /**
- * Enables the content assistant's auto insertion mode. If enabled,
- * the content assistant inserts a proposal automatically if it is
- * the only proposal. In the case of ambiguities, the user must
- * make the choice.
- *
- * @param enabled indicates whether auto insertion is enabled or not
- * @since 2.0
- */
- public void enableAutoInsert(boolean enabled) {
- fIsAutoInserting= enabled;
- }
-
- /**
- * Returns whether this content assistant is in the auto insertion
- * mode or not.
- *
- * @return <code>true</code> if in auto insertion mode
- * @since 2.0
- */
- boolean isAutoInserting() {
- return fIsAutoInserting;
- }
-
- /**
- * Installs and uninstall the listeners needed for autoactivation.
- * @param start <code>true</code> if listeners must be installed,
- * <code>false</code> if they must be removed
- * @since 2.0
- */
- private void manageAutoActivation(boolean start) {
- if (start) {
-
- if (fViewer != null && fAutoAssistListener == null) {
- fAutoAssistListener= new AutoAssistListener();
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fViewer;
- extension.appendVerifyKeyListener(fAutoAssistListener);
- } else {
- StyledText textWidget= fViewer.getTextWidget();
- if (Helper2.okToUse(textWidget))
- textWidget.addVerifyKeyListener(fAutoAssistListener);
- }
- }
-
- } else if (fAutoAssistListener != null) {
-
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fViewer;
- extension.removeVerifyKeyListener(fAutoAssistListener);
- } else {
- StyledText textWidget= fViewer.getTextWidget();
- if (Helper2.okToUse(textWidget))
- textWidget.removeVerifyKeyListener(fAutoAssistListener);
- }
-
- fAutoAssistListener= null;
- }
- }
-
- /**
- * Sets the delay after which the content assistant is automatically invoked
- * if the cursor is behind an auto activation character.
- *
- * @param delay the auto activation delay
- */
- public void setAutoActivationDelay(int delay) {
- fAutoActivationDelay= delay;
- }
-
- /**
- * Sets the proposal popups' orientation.
- * The following values may be used:
- * <ul>
- * <li>PROPOSAL_OVERLAY<p>
- * proposal popup windows should overlay each other
- * </li>
- * <li>PROPOSAL_REMOVE<p>
- * any currently shown proposal popup should be closed
- * </li>
- * <li>PROPOSAL_STACKED<p>
- * proposal popup windows should be vertical stacked, with no overlap,
- * beneath the line containing the current cursor location
- * </li>
- * </ul>
- *
- * @param orientation the popup's orientation
- */
- public void setProposalPopupOrientation(int orientation) {
- fProposalPopupOrientation= orientation;
- }
-
- /**
- * Sets the context information popup's orientation.
- * The following values may be used:
- * <ul>
- * <li>CONTEXT_ABOVE<p>
- * context information popup should always appear above the line containing
- * the current cursor location
- * </li>
- * <li>CONTEXT_BELOW<p>
- * context information popup should always appear below the line containing
- * the current cursor location
- * </li>
- * </ul>
- *
- * @param orientation the popup's orientation
- */
- public void setContextInformationPopupOrientation(int orientation) {
- fContextInfoPopupOrientation= orientation;
- }
-
- /**
- * Sets the context information popup's background color.
- *
- * @param background the background color
- */
- public void setContextInformationPopupBackground(Color background) {
- fContextInfoPopupBackground= background;
- }
-
- /**
- * Returns the background of the context information popup.
- *
- * @return the background of the context information popup
- * @since 2.0
- */
- Color getContextInformationPopupBackground() {
- return fContextInfoPopupBackground;
- }
-
- /**
- * Sets the context information popup's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setContextInformationPopupForeground(Color foreground) {
- fContextInfoPopupForeground= foreground;
- }
-
- /**
- * Returns the foreground of the context information popup.
- *
- * @return the foreground of the context information popup
- * @since 2.0
- */
- Color getContextInformationPopupForeground() {
- return fContextInfoPopupForeground;
- }
-
- /**
- * Sets the proposal selector's background color.
- *
- * @param background the background color
- * @since 2.0
- */
- public void setProposalSelectorBackground(Color background) {
- fProposalSelectorBackground= background;
- }
-
- /**
- * Returns the background of the proposal selector.
- *
- * @return the background of the proposal selector
- * @since 2.0
- */
- Color getProposalSelectorBackground() {
- return fProposalSelectorBackground;
- }
-
- /**
- * Sets the proposal's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setProposalSelectorForeground(Color foreground) {
- fProposalSelectorForeground= foreground;
- }
-
- /**
- * Returns the foreground of the proposal selector.
- *
- * @return the foreground of the proposal selector
- * @since 2.0
- */
- Color getProposalSelectorForeground() {
- return fProposalSelectorForeground;
- }
-
- /**
- * Sets the context selector's background color.
- *
- * @param background the background color
- * @since 2.0
- */
- public void setContextSelectorBackground(Color background) {
- fContextSelectorBackground= background;
- }
-
- /**
- * Returns the background of the context selector.
- *
- * @return the background of the context selector
- * @since 2.0
- */
- Color getContextSelectorBackground() {
- return fContextSelectorBackground;
- }
-
- /**
- * Sets the context selector's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setContextSelectorForeground(Color foreground) {
- fContextSelectorForeground= foreground;
- }
-
- /**
- * Returns the foreground of the context selector.
- *
- * @return the foreground of the context selector
- * @since 2.0
- */
- Color getContextSelectorForeground() {
- return fContextSelectorForeground;
- }
-
- /**
- * Sets the information control creator for the additional information control.
- *
- * @param creator the information control creator for the additional information control
- * @since 2.0
- */
- public void setInformationControlCreator(IInformationControlCreator creator) {
- fInformationControlCreator= creator;
- }
-
- /*
- * @see IContentAssist#install
- */
- public void install(ITextViewer textViewer) {
- Assert.isNotNull(textViewer);
-
- fViewer= textViewer;
-
- fLayoutManager= new LayoutManager();
- fInternalListener= new InternalListener();
-
- AdditionalInfoController2 controller= null;
- if (fInformationControlCreator != null) {
- int delay= fAutoActivationDelay;
- if (delay == 0)
- delay= DEFAULT_AUTO_ACTIVATION_DELAY;
- delay= Math.round(delay * 1.5f);
- controller= new AdditionalInfoController2(fInformationControlCreator, delay);
- }
- fContextInfoPopup= new ContextInformationPopup2(this, fViewer);
- fProposalPopup= new CompletionProposalPopup2(this, fViewer, controller);
-
- manageAutoActivation(fIsAutoActivated);
- }
-
- /*
- * @see IContentAssist#uninstall
- */
- public void uninstall() {
-
- if (fProposalPopup != null)
- fProposalPopup.hide();
-
- if (fContextInfoPopup != null)
- fContextInfoPopup.hide();
-
- manageAutoActivation(false);
-
- if (fCloser != null) {
- fCloser.uninstall();
- fCloser= null;
- }
-
- fViewer= null;
- }
-
- /**
- * Adds the given shell of the specified type to the layout.
- * Valid types are defined by <code>LayoutManager</code>.
- *
- * @param popup a content assist popup
- * @param shell the shell of the content-assist popup
- * @param type the type of popup
- * @param visibleOffset the offset at which to layout the popup relative to the offset of the viewer's visible region
- * @since 2.0
- */
- void addToLayout(Object popup, Shell shell, int type, int visibleOffset) {
- fLayoutManager.add(popup, shell, type, visibleOffset);
- }
-
- /**
- * Layouts the registered popup of the given type relative to the
- * given offset. The offset is relative to the offset of the viewer's visible region.
- * Valid types are defined by <code>LayoutManager</code>.
- *
- * @param type the type of popup to layout
- * @param visibleOffset the offset at which to layout relative to the offset of the viewer's visible region
- * @since 2.0
- */
- void layout(int type, int visibleOffset) {
- fLayoutManager.layout(type, visibleOffset);
- }
-
- /**
- * Notifies the controller that a popup has lost focus.
- *
- * @param e the focus event
- */
- void popupFocusLost(FocusEvent e) {
- fCloser.focusLost(e);
- }
-
- /**
- * Returns the offset of the selection relative to the offset of the visible region.
- *
- * @return the offset of the selection relative to the offset of the visible region
- * @since 2.0
- */
- int getSelectionOffset() {
- StyledText text= fViewer.getTextWidget();
- return text.getSelectionRange().x;
- }
-
- /**
- * Returns whether the widget token could be acquired.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- * @param type the listener type for which to acquire
- * @return <code>true</code> if the widget token could be acquired
- * @since 2.0
- */
- private boolean acquireWidgetToken(int type) {
- switch (type) {
- case CONTEXT_SELECTOR:
- case PROPOSAL_SELECTOR:
- if (fViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fViewer;
- return owner.requestWidgetToken(this);
- } else if (fViewer instanceof IWidgetTokenOwnerExtension) {
- IWidgetTokenOwnerExtension extension= (IWidgetTokenOwnerExtension) fViewer;
- return extension.requestWidgetToken(this, WIDGET_PRIORITY);
- }
- }
- return true;
- }
-
- /**
- * Registers a content assist listener.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- * Returns whether the listener could be added successfully. A listener
- * can not be added if the widget token could not be acquired.
- *
- * @param listener the listener to register
- * @param type the type of listener
- * @return <code>true</code> if the listener could be added
- */
- boolean addContentAssistListener(IContentAssistListener2 listener, int type) {
-
- if (acquireWidgetToken(type)) {
-
- fListeners[type]= listener;
-
- if (getNumberOfListeners() == 1) {
- fCloser= new Closer();
- fCloser.install();
- fViewer.setEventConsumer(fInternalListener);
- installKeyListener();
- }
- return true;
- }
-
- return false;
- }
-
- /**
- * Installs a key listener on the text viewer's widget.
- */
- private void installKeyListener() {
- if (!fKeyListenerHooked) {
- StyledText text= fViewer.getTextWidget();
- if (Helper2.okToUse(text)) {
-
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension e= (ITextViewerExtension) fViewer;
- e.prependVerifyKeyListener(fInternalListener);
- } else {
- text.addVerifyKeyListener(fInternalListener);
- }
-
- fKeyListenerHooked= true;
- }
- }
- }
-
- /**
- * Releases the previously acquired widget token if the token
- * is no longer necessary.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- *
- * @param type the listener type
- * @since 2.0
- */
- private void releaseWidgetToken(int type) {
- if (fListeners[CONTEXT_SELECTOR] == null && fListeners[PROPOSAL_SELECTOR] == null) {
- if (fViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fViewer;
- owner.releaseWidgetToken(this);
- }
- }
- }
-
- /**
- * Unregisters a content assist listener.
- *
- * @param listener the listener to unregister
- * @param type the type of listener
- *
- * @see #addContentAssistListener
- */
- void removeContentAssistListener(IContentAssistListener2 listener, int type) {
- fListeners[type]= null;
-
- if (getNumberOfListeners() == 0) {
-
- if (fCloser != null) {
- fCloser.uninstall();
- fCloser= null;
- }
-
- uninstallKeyListener();
- fViewer.setEventConsumer(null);
- }
-
- releaseWidgetToken(type);
- }
-
- /**
- * Uninstall the key listener from the text viewer's widget.
- */
- private void uninstallKeyListener() {
- if (fKeyListenerHooked) {
- StyledText text= fViewer.getTextWidget();
- if (Helper2.okToUse(text)) {
-
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension e= (ITextViewerExtension) fViewer;
- e.removeVerifyKeyListener(fInternalListener);
- } else {
- text.removeVerifyKeyListener(fInternalListener);
- }
-
- fKeyListenerHooked= false;
- }
- }
- }
-
- /**
- * Returns the number of listeners.
- *
- * @return the number of listeners
- * @since 2.0
- */
- private int getNumberOfListeners() {
- int count= 0;
- for (int i= 0; i <= CONTEXT_INFO_POPUP; i++) {
- if (fListeners[i] != null)
- ++ count;
- }
- return count;
- }
-
- /*
- * @see IContentAssist#showPossibleCompletions
- */
- public String showPossibleCompletions() {
- return fProposalPopup.showProposals(false);
- }
-
- /**
- * Hides the proposal popup.
- */
- public void hidePossibleCompletions() {
- if (fProposalPopup != null)
- fProposalPopup.hide();
- }
-
- /**
- * Callback to signal this content assistant that the presentation of the possible completions has been stopped.
- * @since 2.1
- */
- protected void possibleCompletionsClosed() {
- }
-
- /*
- * @see IContentAssist#showContextInformation
- */
- public String showContextInformation() {
- return fContextInfoPopup.showContextProposals(false);
- }
-
-
- /**
- * Callback to signal this content assistant that the presentation of the context information has been stopped.
- * @since 2.1
- */
- protected void contextInformationClosed() {
- }
-
- /**
- * Requests that the specified context information to be shown.
- *
- * @param contextInformation the context information to be shown
- * @param position the position to which the context information refers to
- * @since 2.0
- */
- void showContextInformation(IContextInformation contextInformation, int position) {
- fContextInfoPopup.showContextInformation(contextInformation, position);
- }
-
- /**
- * Returns the current content assist error message.
- *
- * @return an error message or <code>null</code> if no error has occurred
- */
- String getErrorMessage() {
- return fLastErrorMessage;
- }
-
- /**
- * Returns the content assist processor for the content
- * type of the specified document position.
- *
- * @param textViewer the text viewer
- * @param offset a offset within the document
- * @return a content-assist processor or <code>null</code> if none exists
- */
- private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) {
- try {
- String type= TextUtilities.getContentType(viewer.getDocument(), getDocumentPartitioning(), offset, true);
- return getContentAssistProcessor(type);
- } catch (BadLocationException x) {
- }
- return null;
- }
-
- /**
- * Returns an array of completion proposals computed based on
- * the specified document position. The position is used to
- * determine the appropriate content assist processor to invoke.
- *
- * @param viewer the viewer for which to compute the prosposals
- * @param position a document position
- * @return an array of completion proposals
- *
- * @see IContentAssistProcessor#computeCompletionProposals
- */
- ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int position) {
- if (fProposals != null) {
- return fProposals;
- } else if (fProposalStrings != null) {
- ICompletionProposal[] result= new ICompletionProposal[fProposalStrings.length];
- for (int i= 0; i < fProposalStrings.length; i++) {
- result[i]= new CompletionProposal(fProposalStrings[i], position, fProposalStrings[i].length(), fProposalStrings[i].length());
- }
- return result;
- } else return null;
- }
-
- /**
- * Returns an array of context information objects computed based
- * on the specified document position. The position is used to determine
- * the appropriate content assist processor to invoke.
- *
- * @param viewer the viewer for which to compute the context information
- * @param position a document position
- * @return an array of context information objects
- *
- * @see IContentAssistProcessor#computeContextInformation
- */
- IContextInformation[] computeContextInformation(ITextViewer viewer, int position) {
- fLastErrorMessage= null;
-
- IContextInformation[] result= null;
-
- IContentAssistProcessor p= getProcessor(viewer, position);
- if (p != null) {
- result= p.computeContextInformation(viewer, position);
- fLastErrorMessage= p.getErrorMessage();
- }
-
- return result;
- }
-
- /**
- * Returns the context information validator that should be used to
- * determine when the currently displayed context information should
- * be dismissed. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param textViewer the text viewer
- * @param offset a document offset
- * @return an validator
- *
- * @see IContentAssistProcessor#getContextInformationValidator
- */
- IContextInformationValidator getContextInformationValidator(ITextViewer textViewer, int offset) {
- IContentAssistProcessor p= getProcessor(textViewer, offset);
- return p != null ? p.getContextInformationValidator() : null;
- }
-
- /**
- * Returns the context information presenter that should be used to
- * display context information. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param textViewer the text viewer
- * @param offset a document offset
- * @return a presenter
- * @since 2.0
- */
- IContextInformationPresenter getContextInformationPresenter(ITextViewer textViewer, int offset) {
- IContextInformationValidator validator= getContextInformationValidator(textViewer, offset);
- if (validator instanceof IContextInformationPresenter)
- return (IContextInformationPresenter) validator;
- return null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate proposing completions. The position is used to determine the
- * appropriate content assist processor to invoke.
- *
- * @param textViewer the text viewer
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters
- */
- private char[] getCompletionProposalAutoActivationCharacters(ITextViewer textViewer, int offset) {
- IContentAssistProcessor p= getProcessor(textViewer, offset);
- return p != null ? p.getCompletionProposalAutoActivationCharacters() : null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate the presentation of context information. The position is used
- * to determine the appropriate content assist processor to invoke.
- *
- * @param textViewer the text viewer
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters
- */
- private char[] getContextInformationAutoActivationCharacters(ITextViewer textViewer, int offset) {
- IContentAssistProcessor p= getProcessor(textViewer, offset);
- return p != null ? p.getContextInformationAutoActivationCharacters() : null;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner)
- * @since 2.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner) {
- hidePossibleCompletions();
- return true;
- }
-
- /**
- * @param completionPosition
- */
- public void setCompletionPosition(int completionPosition) {
- fCompletionPosition= completionPosition;
- }
-
- /**
- * @return the completion position
- */
- public int getCompletionPosition() {
- return fCompletionPosition;
- }
-
- /**
- * @param proposals
- */
- public void setCompletions(String[] proposals) {
- fProposalStrings= proposals;
- }
-
- /**
- * @param proposals
- */
- public void setCompletions(ICompletionProposal[] proposals) {
- fProposals= proposals;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(org.eclipse.jface.text.IWidgetTokenOwner, int)
- * @since 3.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) {
- if (priority > WIDGET_PRIORITY) {
- hidePossibleCompletions();
- return true;
- } else
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#setFocus(org.eclipse.jface.text.IWidgetTokenOwner)
- * @since 3.0
- */
- public boolean setFocus(IWidgetTokenOwner owner) {
- if (fProposalPopup != null) {
- fProposalPopup.setFocus();
- return fProposalPopup.hasFocus();
- }
- return false;
- }
-
- /**
- * Returns whether any popups controlled by the receiver have the input focus.
- *
- * @return <code>true</code> if any of the managed popups have the focus, <code>false</code> otherwise
- */
- public boolean hasFocus() {
- return (fProposalPopup != null && fProposalPopup.hasFocus())
- || (fContextInfoPopup != null && fContextInfoPopup.hasFocus());
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistantExtension#completePrefix()
- */
- public String completePrefix() {
- // TODO Auto-generated method stub
- return null;
- }
-
- /**
- * @param proposal
- */
- public void fireProposalChosen(ICompletionProposal proposal) {
- List list= new ArrayList(fProposalListeners);
- for (Iterator it= list.iterator(); it.hasNext();) {
- IProposalListener listener= (IProposalListener) it.next();
- listener.proposalChosen(proposal);
- }
-
- }
-
- /**
- * @param listener
- */
- public void removeProposalListener(IProposalListener listener) {
- fProposalListeners.remove(listener);
- }
-
- /**
- * @param listener
- */
- public void addProposalListener(IProposalListener listener) {
- fProposalListeners.add(listener);
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java
deleted file mode 100644
index 5b1dea55cfc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/ContextInformationPopup2.java
+++ /dev/null
@@ -1,629 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.util.Stack;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.contentassist.IContextInformationExtension;
-import org.eclipse.jface.text.contentassist.IContextInformationPresenter;
-import org.eclipse.jface.text.contentassist.IContextInformationValidator;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-
-/**
- * This class is used to present context information to the user.
- * If multiple contexts are valid at the current cursor location,
- * a list is presented from which the user may choose one context.
- * Once the user makes their choice, or if there was only a single
- * possible context, the context information is shown in a tooltip like popup. <p>
- * If the tooltip is visible and the user wants to see context information of
- * a context embedded into the one for which context information is displayed,
- * context information for the embedded context is shown. As soon as the
- * cursor leaves the embedded context area, the context information for
- * the embedding context is shown again.
- *
- * @see IContextInformation
- * @see IContextInformationValidator
- */
-class ContextInformationPopup2 implements IContentAssistListener2 {
-
-
-
- /**
- * Represents the state necessary for embedding contexts.
- * @since 2.0
- */
- static class ContextFrame {
- public int fBeginOffset;
- public int fOffset;
- public int fVisibleOffset;
- public IContextInformation fInformation;
- public IContextInformationValidator fValidator;
- public IContextInformationPresenter fPresenter;
- }
-
- private ITextViewer fViewer;
- private ContentAssistant2 fContentAssistant;
-
- private PopupCloser2 fPopupCloser= new PopupCloser2();
- private Shell fContextSelectorShell;
- private Table fContextSelectorTable;
- private IContextInformation[] fContextSelectorInput;
- private String fLineDelimiter= null;
-
- private Shell fContextInfoPopup;
- private StyledText fContextInfoText;
- private TextPresentation fTextPresentation;
-
- private Stack fContextFrameStack= new Stack();
-
-
- /**
- * Creates a new context information popup.
- *
- * @param contentAssistant the content assist for computing the context information
- * @param viewer the viewer on top of which the context information is shown
- */
- public ContextInformationPopup2(ContentAssistant2 contentAssistant, ITextViewer viewer) {
- fContentAssistant= contentAssistant;
- fViewer= viewer;
- }
-
- /**
- * Shows all possible contexts for the given cursor position of the viewer.
- *
- * @param autoActivated <code>true</code> if auto activated
- * @return a potential error message or <code>null</code> in case of no error
- */
- public String showContextProposals(final boolean autoActivated) {
- final StyledText styledText= fViewer.getTextWidget();
- BusyIndicator.showWhile(styledText.getDisplay(), new Runnable() {
- public void run() {
-
- int position= fViewer.getSelectedRange().x;
-
- IContextInformation[] contexts= computeContextInformation(position);
- int count = (contexts == null ? 0 : contexts.length);
- if (count == 1) {
-
- // Show context information directly
- internalShowContextInfo(contexts[0], position);
-
- } else if (count > 0) {
- // Precise context must be selected
-
- if (fLineDelimiter == null)
- fLineDelimiter= styledText.getLineDelimiter();
-
- createContextSelector();
- setContexts(contexts);
- displayContextSelector();
- hideContextInfoPopup();
-
- } else if (!autoActivated) {
- styledText.getDisplay().beep();
- }
- }
- });
-
- return getErrorMessage();
- }
-
- /**
- * Displays the given context information for the given offset.
- *
- * @param info the context information
- * @param position the offset
- * @since 2.0
- */
- public void showContextInformation(final IContextInformation info, final int position) {
- Control control= fViewer.getTextWidget();
- BusyIndicator.showWhile(control.getDisplay(), new Runnable() {
- public void run() {
- internalShowContextInfo(info, position);
- hideContextSelector();
- }
- });
- }
-
- /**
- * Displays the given context information for the given offset.
- *
- * @param info the context information
- * @param position the offset
- * @since 2.0
- */
-
- private void internalShowContextInfo(IContextInformation information, int offset) {
-
- IContextInformationValidator validator= fContentAssistant.getContextInformationValidator(fViewer, offset);
-
- if (validator != null) {
- ContextFrame current= new ContextFrame();
- current.fInformation= information;
- current.fBeginOffset= (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information).getContextInformationPosition() : offset;
- if (current.fBeginOffset == -1) current.fBeginOffset= offset;
- current.fOffset= offset;
- current.fVisibleOffset= fViewer.getTextWidget().getSelectionRange().x - (offset - current.fBeginOffset);
- current.fValidator= validator;
- current.fPresenter= fContentAssistant.getContextInformationPresenter(fViewer, offset);
-
- fContextFrameStack.push(current);
-
- internalShowContextFrame(current, fContextFrameStack.size() == 1);
- }
- }
-
- /**
- * Shows the given context frame.
- *
- * @param frame the frane to display
- * @param initial <code>true</code> if this is the first frame to be displayed
- * @since 2.0
- */
- private void internalShowContextFrame(ContextFrame frame, boolean initial) {
-
- frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset);
-
- if (frame.fPresenter != null) {
- if (fTextPresentation == null)
- fTextPresentation= new TextPresentation();
- frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset);
- frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation);
- }
-
- createContextInfoPopup();
-
- fContextInfoText.setText(frame.fInformation.getInformationDisplayString());
- if (fTextPresentation != null)
- TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText);
- resize();
-
- if (initial) {
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_INFO_POPUP)) {
- fContentAssistant.addToLayout(this, fContextInfoPopup, ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset);
- fContextInfoPopup.setVisible(true);
- }
- } else {
- fContentAssistant.layout(ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset);
- }
- }
-
- /**
- * Computes all possible context information for the given offset.
- *
- * @param position the offset
- * @return all possible context information for the given offset
- * @since 2.0
- */
- private IContextInformation[] computeContextInformation(int position) {
- return fContentAssistant.computeContextInformation(fViewer, position);
- }
-
- /**
- *Returns the error message generated while computing context information.
- *
- * @return the error message
- */
- private String getErrorMessage() {
- return fContentAssistant.getErrorMessage();
- }
-
- /**
- * Creates the context information popup. This is the tooltip like overlay window.
- */
- private void createContextInfoPopup() {
- if (Helper2.okToUse(fContextInfoPopup))
- return;
-
- Control control= fViewer.getTextWidget();
- Display display= control.getDisplay();
-
- fContextInfoPopup= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP);
- fContextInfoPopup.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
-
- fContextInfoText= new StyledText(fContextInfoPopup, SWT.MULTI | SWT.READ_ONLY);
-
- Color c= fContentAssistant.getContextInformationPopupBackground();
- if (c == null)
- c= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fContextInfoText.setBackground(c);
-
- c= fContentAssistant.getContextInformationPopupForeground();
- if (c == null)
- c= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fContextInfoText.setForeground(c);
- }
-
- /**
- * Resizes the context information popup.
- * @since 2.0
- */
- private void resize() {
- Point size= fContextInfoText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- size.x += 3;
- fContextInfoText.setSize(size);
- fContextInfoText.setLocation(1,1);
- size.x += 2;
- size.y += 2;
- fContextInfoPopup.setSize(size);
- }
-
- /**
- *Hides the context information popup.
- */
- private void hideContextInfoPopup() {
-
- if (Helper2.okToUse(fContextInfoPopup)) {
-
- int size= fContextFrameStack.size();
- if (size > 0) {
- fContextFrameStack.pop();
- -- size;
- }
-
- if (size > 0) {
- ContextFrame current= (ContextFrame) fContextFrameStack.peek();
- internalShowContextFrame(current, false);
- } else {
-
- fContentAssistant.removeContentAssistListener(this, ContentAssistant2.CONTEXT_INFO_POPUP);
-
- fContextInfoPopup.setVisible(false);
- fContextInfoPopup.dispose();
- fContextInfoPopup= null;
-
- if (fTextPresentation != null) {
- fTextPresentation.clear();
- fTextPresentation= null;
- }
- }
- }
-
- if (fContextInfoPopup == null)
- fContentAssistant.contextInformationClosed();
- }
-
- /**
- * Creates the context selector in case the user has the choice between multiple valid contexts
- * at a given offset.
- */
- private void createContextSelector() {
- if (Helper2.okToUse(fContextSelectorShell))
- return;
-
- Control control= fViewer.getTextWidget();
- fContextSelectorShell= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP);
- fContextSelectorTable= new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
-
- int height= fContextSelectorTable.getItemHeight() * 10;
- fContextSelectorShell.setSize(302, height + 2);
- fContextSelectorTable.setSize(300, height);
- fContextSelectorTable.setLocation(1, 1);
-
- fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
- Color c= fContentAssistant.getContextSelectorBackground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fContextSelectorTable.setBackground(c);
-
- c= fContentAssistant.getContextSelectorForeground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fContextSelectorTable.setForeground(c);
-
- fContextSelectorTable.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- insertSelectedContext();
- hideContextSelector();
- }
- });
-
- fPopupCloser.install(fContentAssistant, fContextSelectorTable);
-
- fContextSelectorTable.setHeaderVisible(false);
- fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant2.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
- }
-
- /**
- * Causes the context information of the context selected in the context selector
- * to be displayed in the context information popup.
- */
- private void insertSelectedContext() {
- int i= fContextSelectorTable.getSelectionIndex();
-
- if (i < 0 || i >= fContextSelectorInput.length)
- return;
-
- int position= fViewer.getSelectedRange().x;
- internalShowContextInfo(fContextSelectorInput[i], position);
- }
-
- /**
- * Sets the contexts in the context selector to the given set.
- *
- * @param contexts the possible contexts
- */
- private void setContexts(IContextInformation[] contexts) {
- if (Helper2.okToUse(fContextSelectorTable)) {
-
- fContextSelectorInput= contexts;
-
- fContextSelectorTable.setRedraw(false);
- fContextSelectorTable.removeAll();
-
- TableItem item;
- IContextInformation t;
- for (int i= 0; i < contexts.length; i++) {
- t= contexts[i];
- item= new TableItem(fContextSelectorTable, SWT.NULL);
- if (t.getImage() != null)
- item.setImage(t.getImage());
- item.setText(t.getContextDisplayString());
- }
-
- fContextSelectorTable.select(0);
- fContextSelectorTable.setRedraw(true);
- }
- }
-
- /**
- * Displays the context selector.
- */
- private void displayContextSelector() {
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR))
- fContextSelectorShell.setVisible(true);
- }
-
- /**
- * Hodes the context selector.
- */
- private void hideContextSelector() {
- if (Helper2.okToUse(fContextSelectorShell)) {
- fContentAssistant.removeContentAssistListener(this, ContentAssistant2.CONTEXT_SELECTOR);
-
- fPopupCloser.uninstall();
- fContextSelectorShell.setVisible(false);
- fContextSelectorShell.dispose();
- fContextSelectorShell= null;
- }
-
- if (!Helper2.okToUse(fContextInfoPopup))
- fContentAssistant.contextInformationClosed();
- }
-
- /**
- *Returns whether the context selector has the focus.
- *
- * @return <code>true</code> if teh context selector has the focus
- */
- public boolean hasFocus() {
- if (Helper2.okToUse(fContextSelectorShell))
- return (fContextSelectorShell.isFocusControl() || fContextSelectorTable.isFocusControl());
-
- return false;
- }
-
- /**
- * Hides context selector and context information popup.
- */
- public void hide() {
- hideContextSelector();
- hideContextInfoPopup();
- }
-
- /**
- * Returns whether this context information popup is active. I.e., either
- * a context selector or context information is displayed.
- *
- * @return <code>true</code> if the context selector is active
- */
- public boolean isActive() {
- return (Helper2.okToUse(fContextInfoPopup) || Helper2.okToUse(fContextSelectorShell));
- }
-
- /*
- * @see IContentAssistListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent e) {
- if (Helper2.okToUse(fContextSelectorShell))
- return contextSelectorKeyPressed(e);
- if (Helper2.okToUse(fContextInfoPopup))
- return contextInfoPopupKeyPressed(e);
- return true;
- }
-
- /**
- * Processes a key stroke in the context selector.
- *
- * @param e the verify event describing the key stroke
- * @return <code>true</code> if processing can be stopped
- */
- private boolean contextSelectorKeyPressed(VerifyEvent e) {
-
- char key= e.character;
- if (key == 0) {
-
- int change;
- int visibleRows= (fContextSelectorTable.getSize().y / fContextSelectorTable.getItemHeight()) - 1;
- int selection= fContextSelectorTable.getSelectionIndex();
-
- switch (e.keyCode) {
-
- case SWT.ARROW_UP:
- change= (fContextSelectorTable.getSelectionIndex() > 0 ? -1 : 0);
- break;
-
- case SWT.ARROW_DOWN:
- change= (fContextSelectorTable.getSelectionIndex() < fContextSelectorTable.getItemCount() - 1 ? 1 : 0);
- break;
-
- case SWT.PAGE_DOWN :
- change= visibleRows;
- if (selection + change >= fContextSelectorTable.getItemCount())
- change= fContextSelectorTable.getItemCount() - selection;
- break;
-
- case SWT.PAGE_UP :
- change= -visibleRows;
- if (selection + change < 0)
- change= -selection;
- break;
-
- case SWT.HOME :
- change= -selection;
- break;
-
- case SWT.END :
- change= fContextSelectorTable.getItemCount() - selection;
- break;
-
- default:
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hideContextSelector();
- return true;
- }
-
- fContextSelectorTable.setSelection(selection + change);
- fContextSelectorTable.showSelection();
- e.doit= false;
- return false;
-
- } else if ('\t' == key) {
- // switch focus to selector shell
- e.doit= false;
- fContextSelectorShell.setFocus();
- return false;
- } else if (key == 0x1B) {
- // terminate on Esc
- hideContextSelector();
- }
-
- return true;
- }
-
- /**
- * Processes a key stroke while the info popup is up.
- *
- * @param e the verify event describing the key stroke
- * @return <code>true</code> if processing can be stopped
- */
- private boolean contextInfoPopupKeyPressed(KeyEvent e) {
-
- char key= e.character;
- if (key == 0) {
-
- switch (e.keyCode) {
-
- case SWT.ARROW_LEFT:
- case SWT.ARROW_RIGHT:
- validateContextInformation();
- break;
- default:
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hideContextInfoPopup();
- break;
- }
-
- } else if (key == 0x1B) {
- // terminate on Esc
- hideContextInfoPopup();
- } else {
- validateContextInformation();
- }
- return true;
- }
-
- /*
- * @see IEventConsumer#processEvent(VerifyEvent)
- */
- public void processEvent(VerifyEvent event) {
- if (Helper2.okToUse(fContextSelectorShell))
- contextSelectorProcessEvent(event);
- if (Helper2.okToUse(fContextInfoPopup))
- contextInfoPopupProcessEvent(event);
- }
-
- /**
- * Processes a key stroke in the context selector.
- *
- * @param e the verify event describing the key stroke
- */
- private void contextSelectorProcessEvent(VerifyEvent e) {
-
- if (e.start == e.end && e.text != null && e.text.equals(fLineDelimiter)) {
- e.doit= false;
- insertSelectedContext();
- }
-
- hideContextSelector();
- }
-
- /**
- * Processes a key stroke while the info popup is up.
- *
- * @param e the verify event describing the key stroke
- */
- private void contextInfoPopupProcessEvent(VerifyEvent e) {
- if (e.start != e.end && (e.text == null || e.text.length() == 0))
- validateContextInformation();
- }
-
- /**
- * Validates the context information for the viewer's actual cursor position.
- */
- private void validateContextInformation() {
- /*
- * Post the code in the event queue in order to ensure that the
- * action described by this verify key event has already beed executed.
- * Otherwise, we'd validate the context information based on the
- * pre-key-stroke state.
- */
- fContextInfoPopup.getDisplay().asyncExec(new Runnable() {
-
- private ContextFrame fFrame= (ContextFrame) fContextFrameStack.peek();
-
- public void run() {
- if (Helper2.okToUse(fContextInfoPopup) && fFrame == fContextFrameStack.peek()) {
- int offset= fViewer.getSelectedRange().x;
- if (fFrame.fValidator == null || !fFrame.fValidator.isContextInformationValid(offset)) {
- hideContextInfoPopup();
- } else if (fFrame.fPresenter != null && fFrame.fPresenter.updatePresentation(offset, fTextPresentation)) {
- TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText);
- resize();
- }
- }
- }
- });
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTML2TextReader.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTML2TextReader.java
deleted file mode 100644
index d22f786ee63..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTML2TextReader.java
+++ /dev/null
@@ -1,302 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-
-
-import java.io.IOException;
-import java.io.PushbackReader;
-import java.io.Reader;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyleRange;
-
-import org.eclipse.jface.text.TextPresentation;
-
-
-/**
- * Reads the text contents from a reader of HTML contents and translates
- * the tags or cut them out.
- */
-class HTML2TextReader extends SubstitutionTextReader {
-
- private static final String EMPTY_STRING= ""; //$NON-NLS-1$
- private static final Map fgEntityLookup;
- private static final Set fgTags;
-
- static {
-
- fgTags= new HashSet();
- fgTags.add("b"); //$NON-NLS-1$
- fgTags.add("br"); //$NON-NLS-1$
- fgTags.add("h5"); //$NON-NLS-1$
- fgTags.add("p"); //$NON-NLS-1$
- fgTags.add("dl"); //$NON-NLS-1$
- fgTags.add("dt"); //$NON-NLS-1$
- fgTags.add("dd"); //$NON-NLS-1$
- fgTags.add("li"); //$NON-NLS-1$
- fgTags.add("ul"); //$NON-NLS-1$
- fgTags.add("pre"); //$NON-NLS-1$
-
- fgEntityLookup= new HashMap(7);
- fgEntityLookup.put("lt", "<"); //$NON-NLS-1$ //$NON-NLS-2$
- fgEntityLookup.put("gt", ">"); //$NON-NLS-1$ //$NON-NLS-2$
- fgEntityLookup.put("nbsp", " "); //$NON-NLS-1$ //$NON-NLS-2$
- fgEntityLookup.put("amp", "&"); //$NON-NLS-1$ //$NON-NLS-2$
- fgEntityLookup.put("circ", "^"); //$NON-NLS-1$ //$NON-NLS-2$
- fgEntityLookup.put("tilde", "~"); //$NON-NLS-2$ //$NON-NLS-1$
- fgEntityLookup.put("quot", "\""); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- private int fCounter= 0;
- private TextPresentation fTextPresentation;
- private int fBold= 0;
- private int fStartOffset= -1;
- private boolean fInParagraph= false;
- private boolean fIsPreformattedText= false;
-
- /**
- * Transforms the HTML text from the reader to formatted text.
- *
- * @param reader the reader
- * @param presentation If not <code>null</code>, formattings will be applied to
- * the presentation.
- */
- public HTML2TextReader(Reader reader, TextPresentation presentation) {
- super(new PushbackReader(reader));
- fTextPresentation= presentation;
- }
-
- public int read() throws IOException {
- int c= super.read();
- if (c != -1)
- ++ fCounter;
- return c;
- }
-
- protected void startBold() {
- if (fBold == 0)
- fStartOffset= fCounter;
- ++ fBold;
- }
-
- protected void startPreformattedText() {
- fIsPreformattedText= true;
- setSkipWhitespace(false);
- }
-
- protected void stopPreformattedText() {
- fIsPreformattedText= false;
- setSkipWhitespace(true);
- }
-
- protected void stopBold() {
- -- fBold;
- if (fBold == 0) {
- if (fTextPresentation != null) {
- fTextPresentation.addStyleRange(new StyleRange(fStartOffset, fCounter - fStartOffset, null, null, SWT.BOLD));
- }
- fStartOffset= -1;
- }
- }
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.SubstitutionTextReader#computeSubstitution(int)
- */
- protected String computeSubstitution(int c) throws IOException {
-
- if (c == '<')
- return processHTMLTag();
- else if (c == '&')
- return processEntity();
- else if (fIsPreformattedText)
- return processPreformattedText(c);
-
- return null;
- }
-
- private String html2Text(String html) {
-
- if (html == null || html.length() == 0)
- return EMPTY_STRING;
-
- String tag= html;
- if ('/' == tag.charAt(0))
- tag= tag.substring(1);
-
- if (!fgTags.contains(tag))
- return EMPTY_STRING;
-
-
- if ("pre".equals(html)) { //$NON-NLS-1$
- startPreformattedText();
- return EMPTY_STRING;
- }
-
- if ("/pre".equals(html)) { //$NON-NLS-1$
- stopPreformattedText();
- return EMPTY_STRING;
- }
-
- if (fIsPreformattedText)
- return EMPTY_STRING;
-
- if ("b".equals(html)) { //$NON-NLS-1$
- startBold();
- return EMPTY_STRING;
- }
-
- if ("h5".equals(html) || "dt".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$
- startBold();
- return EMPTY_STRING;
- }
-
- if ("dl".equals(html)) //$NON-NLS-1$
- return LINE_DELIM;
-
- if ("dd".equals(html)) //$NON-NLS-1$
- return "\t"; //$NON-NLS-1$
-
- if ("li".equals(html)) //$NON-NLS-1$
- return LINE_DELIM + ContentAssistMessages.getString("HTML2TextReader.listItemPrefix"); //$NON-NLS-1$ //$NON-NLS-2$
-
- if ("/b".equals(html)) { //$NON-NLS-1$
- stopBold();
- return EMPTY_STRING;
- }
-
- if ("p".equals(html)) { //$NON-NLS-1$
- fInParagraph= true;
- return LINE_DELIM;
- }
-
- if ("br".equals(html)) //$NON-NLS-1$
- return LINE_DELIM;
-
- if ("/p".equals(html)) { //$NON-NLS-1$
- boolean inParagraph= fInParagraph;
- fInParagraph= false;
- return inParagraph ? EMPTY_STRING : LINE_DELIM;
- }
-
- if ("/h5".equals(html) || "/dt".equals(html)) { //$NON-NLS-1$ //$NON-NLS-2$
- stopBold();
- return LINE_DELIM;
- }
-
- if ("/dd".equals(html)) //$NON-NLS-1$
- return LINE_DELIM;
-
- return EMPTY_STRING;
- }
-
- /*
- * A '<' has been read. Process a HTML tag
- */
- private String processHTMLTag() throws IOException {
-
- StringBuffer buf= new StringBuffer();
- int ch;
- do {
-
- ch= nextChar();
-
- while (ch != -1 && ch != '>') {
- buf.append(Character.toLowerCase((char) ch));
- ch= nextChar();
- if (ch == '"'){
- buf.append(Character.toLowerCase((char) ch));
- ch= nextChar();
- while (ch != -1 && ch != '"'){
- buf.append(Character.toLowerCase((char) ch));
- ch= nextChar();
- }
- }
- if (ch == '<'){
- unread(ch);
- return '<' + buf.toString();
- }
- }
-
- if (ch == -1)
- return null;
-
- int tagLen= buf.length();
- // needs special treatment for comments
- if ((tagLen >= 3 && "!--".equals(buf.substring(0, 3))) //$NON-NLS-1$
- && !(tagLen >= 5 && "--!".equals(buf.substring(tagLen - 3)))) { //$NON-NLS-1$
- // unfinished comment
- buf.append(ch);
- } else {
- break;
- }
- } while (true);
-
- return html2Text(buf.toString());
- }
-
- private String processPreformattedText(int c) {
- if (c == '\r' || c == '\n')
- fCounter++;
- return null;
- }
-
-
- private void unread(int ch) throws IOException {
- ((PushbackReader) getReader()).unread(ch);
- }
-
- protected String entity2Text(String symbol) {
- if (symbol.length() > 1 && symbol.charAt(0) == '#') {
- int ch;
- try {
- if (symbol.charAt(1) == 'x') {
- ch= Integer.parseInt(symbol.substring(2), 16);
- } else {
- ch= Integer.parseInt(symbol.substring(1), 10);
- }
- return EMPTY_STRING + (char)ch;
- } catch (NumberFormatException e) {
- }
- } else {
- String str= (String) fgEntityLookup.get(symbol);
- if (str != null) {
- return str;
- }
- }
- return "&" + symbol; // not found //$NON-NLS-1$
- }
-
- /*
- * A '&' has been read. Process a entity
- */
- private String processEntity() throws IOException {
- StringBuffer buf= new StringBuffer();
- int ch= nextChar();
- while (Character.isLetterOrDigit((char)ch) || ch == '#') {
- buf.append((char) ch);
- ch= nextChar();
- }
-
- if (ch == ';')
- return entity2Text(buf.toString());
-
- buf.insert(0, '&');
- if (ch != -1)
- buf.append((char) ch);
- return buf.toString();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTMLTextPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTMLTextPresenter.java
deleted file mode 100644
index 3591392f56b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/HTMLTextPresenter.java
+++ /dev/null
@@ -1,191 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.util.Iterator;
-
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.DefaultInformationControl;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextPresentation;
-
-
-
-class HTMLTextPresenter implements DefaultInformationControl.IInformationPresenter {
-
- private static final String LINE_DELIM= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private int fCounter;
- private boolean fEnforceUpperLineLimit;
-
- public HTMLTextPresenter(boolean enforceUpperLineLimit) {
- super();
- fEnforceUpperLineLimit= enforceUpperLineLimit;
- }
-
- public HTMLTextPresenter() {
- this(true);
- }
-
- protected Reader createReader(String hoverInfo, TextPresentation presentation) {
- return new HTML2TextReader(new StringReader(hoverInfo), presentation);
- }
-
- protected void adaptTextPresentation(TextPresentation presentation, int offset, int insertLength) {
-
- int yoursStart= offset;
- int yoursEnd= offset + insertLength -1;
- yoursEnd= Math.max(yoursStart, yoursEnd);
-
- Iterator e= presentation.getAllStyleRangeIterator();
- while (e.hasNext()) {
-
- StyleRange range= (StyleRange) e.next();
-
- int myStart= range.start;
- int myEnd= range.start + range.length -1;
- myEnd= Math.max(myStart, myEnd);
-
- if (myEnd < yoursStart)
- continue;
-
- if (myStart < yoursStart)
- range.length += insertLength;
- else
- range.start += insertLength;
- }
- }
-
- private void append(StringBuffer buffer, String string, TextPresentation presentation) {
-
- int length= string.length();
- buffer.append(string);
-
- if (presentation != null)
- adaptTextPresentation(presentation, fCounter, length);
-
- fCounter += length;
- }
-
- private String getIndent(String line) {
- int length= line.length();
-
- int i= 0;
- while (i < length && Character.isWhitespace(line.charAt(i))) ++i;
-
- return (i == length ? line : line.substring(0, i)) + " "; //$NON-NLS-1$
- }
-
- /*
- * @see IHoverInformationPresenter#updatePresentation(Display display, String, TextPresentation, int, int)
- */
- public String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight) {
-
- if (hoverInfo == null)
- return null;
-
- GC gc= new GC(display);
- try {
-
- StringBuffer buffer= new StringBuffer();
- int maxNumberOfLines= Math.round(maxHeight / gc.getFontMetrics().getHeight());
-
- fCounter= 0;
- LineBreakingReader reader= new LineBreakingReader(createReader(hoverInfo, presentation), gc, maxWidth);
-
- boolean lastLineFormatted= false;
- String lastLineIndent= null;
-
- String line=reader.readLine();
- boolean lineFormatted= reader.isFormattedLine();
- boolean firstLineProcessed= false;
-
- while (line != null) {
-
- if (fEnforceUpperLineLimit && maxNumberOfLines <= 0)
- break;
-
- if (firstLineProcessed) {
- if (!lastLineFormatted)
- append(buffer, LINE_DELIM, null);
- else {
- append(buffer, LINE_DELIM, presentation);
- if (lastLineIndent != null)
- append(buffer, lastLineIndent, presentation);
- }
- }
-
- append(buffer, line, null);
- firstLineProcessed= true;
-
- lastLineFormatted= lineFormatted;
- if (!lineFormatted)
- lastLineIndent= null;
- else if (lastLineIndent == null)
- lastLineIndent= getIndent(line);
-
- line= reader.readLine();
- lineFormatted= reader.isFormattedLine();
-
- maxNumberOfLines--;
- }
-
- if (line != null) {
- append(buffer, LINE_DELIM, lineFormatted ? presentation : null);
- append(buffer, ContentAssistMessages.getString("HTMLTextPresenter.ellipse"), presentation); //$NON-NLS-1$
- }
-
- return trim(buffer, presentation);
-
- } catch (IOException e) {
-
- // ignore TODO do something else?
- return null;
-
- } finally {
- gc.dispose();
- }
- }
-
- private String trim(StringBuffer buffer, TextPresentation presentation) {
-
- int length= buffer.length();
-
- int end= length -1;
- while (end >= 0 && Character.isWhitespace(buffer.charAt(end)))
- -- end;
-
- if (end == -1)
- return ""; //$NON-NLS-1$
-
- if (end < length -1)
- buffer.delete(end + 1, length);
- else
- end= length;
-
- int start= 0;
- while (start < end && Character.isWhitespace(buffer.charAt(start)))
- ++ start;
-
- buffer.delete(0, start);
- presentation.setResultWindow(new Region(start, buffer.length()));
- return buffer.toString();
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/Helper2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/Helper2.java
deleted file mode 100644
index 463c395fb3f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/Helper2.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-
-import org.eclipse.swt.widgets.Widget;
-
-
-/**
- * Helper class for testing widget state.
- */
-class Helper2 {
-
- /**
- * Returns whether the widget is <code>null</code> or disposed.
- *
- * @param widget the widget to check
- * @return <code>true</code> if the widget is neither <code>null</code> nor disposed
- */
- public static boolean okToUse(Widget widget) {
- return (widget != null && !widget.isDisposed());
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IContentAssistListener2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IContentAssistListener2.java
deleted file mode 100644
index f8041937c72..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IContentAssistListener2.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-
-import org.eclipse.swt.events.VerifyEvent;
-
-import org.eclipse.jface.text.IEventConsumer;
-
-
-
-/**
- * An interface whereby listeners can not only receive key events,
- * but can also consume them to prevent subsequent listeners from
- * processing the event.
- */
-interface IContentAssistListener2 extends IEventConsumer {
-
- /**
- * Verifies the key event.
- *
- * @return <code>true</code> if processing should be continued by additional listeners
- * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent event);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IProposalListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IProposalListener.java
deleted file mode 100644
index 1e4924dc902..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/IProposalListener.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-
-
-/**
- *
- */
-public interface IProposalListener {
-
- /**
- * @param proposal
- */
- void proposalChosen(ICompletionProposal proposal);
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/LineBreakingReader.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/LineBreakingReader.java
deleted file mode 100644
index 100a2d4f2fc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/LineBreakingReader.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.Reader;
-
-import java.text.BreakIterator;
-import org.eclipse.swt.graphics.GC;
-
-/*
- * Not a real reader. Could change if requested
- */
-class LineBreakingReader {
-
- private BufferedReader fReader;
- private GC fGC;
- private int fMaxWidth;
-
- private String fLine;
- private int fOffset;
-
- private BreakIterator fLineBreakIterator;
-
- /**
- * Creates a reader that breaks an input text to fit in a given width.
- * @param reader Reader of the input text
- * @param gc The graphic context that defines the currently used font sizes
- * @param maxLineWidth The max width (pixes) where the text has to fit in
- */
- public LineBreakingReader(Reader reader, GC gc, int maxLineWidth) {
- fReader= new BufferedReader(reader);
- fGC= gc;
- fMaxWidth= maxLineWidth;
- fOffset= 0;
- fLine= null;
- fLineBreakIterator= BreakIterator.getLineInstance();
- }
-
- public boolean isFormattedLine() {
- return fLine != null;
- }
-
- /**
- * Reads the next line. The lengths of the line will not exceed the gived maximum
- * width.
- */
- public String readLine() throws IOException {
- if (fLine == null) {
- String line= fReader.readLine();
- if (line == null)
- return null;
-
- int lineLen= fGC.textExtent(line).x;
- if (lineLen < fMaxWidth) {
- return line;
- }
- fLine= line;
- fLineBreakIterator.setText(line);
- fOffset= 0;
- }
- int breakOffset= findNextBreakOffset(fOffset);
- String res;
- if (breakOffset != BreakIterator.DONE) {
- res= fLine.substring(fOffset, breakOffset);
- fOffset= findWordBegin(breakOffset);
- if (fOffset == fLine.length()) {
- fLine= null;
- }
- } else {
- res= fLine.substring(fOffset);
- fLine= null;
- }
- return res;
- }
-
- private int findNextBreakOffset(int currOffset) {
- int currWidth= 0;
- int nextOffset= fLineBreakIterator.following(currOffset);
- while (nextOffset != BreakIterator.DONE) {
- String word= fLine.substring(currOffset, nextOffset);
- int wordWidth= fGC.textExtent(word).x;
- int nextWidth= wordWidth + currWidth;
- if (nextWidth > fMaxWidth) {
- if (currWidth > 0) {
- return currOffset;
- } else {
- return nextOffset;
- }
- }
- currWidth= nextWidth;
- currOffset= nextOffset;
- nextOffset= fLineBreakIterator.next();
- }
- return nextOffset;
- }
-
- private int findWordBegin(int idx) {
- while (idx < fLine.length() && Character.isWhitespace(fLine.charAt(idx))) {
- idx++;
- }
- return idx;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java
deleted file mode 100644
index 842ab23c145..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/PopupCloser2.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.ScrollBar;
-import org.eclipse.swt.widgets.Table;
-
-
-/**
- * A generic closer class used to monitor various
- * interface events in order to determine whether
- * a content assistant should be terminated and all
- * associated windows be closed.
- */
-class PopupCloser2 implements FocusListener, SelectionListener {
-
- /** The content assistant to be monitored */
- private ContentAssistant2 fContentAssistant;
- /** The table of a selector popup opened by the content assistant */
- private Table fTable;
- /** The scrollbar of the table for the selector popup */
- private ScrollBar fScrollbar;
- /** Indicates whether the scrollbar thumb has been grabed */
- private boolean fScrollbarClicked= false;
-
- /**
- * Installs this closer on the given table opened by the given content assistant.
- *
- * @param contentAssistant the content assistant
- * @param table the table to be tracked
- */
- public void install(ContentAssistant2 contentAssistant, Table table) {
- fContentAssistant= contentAssistant;
- fTable= table;
- if (Helper2.okToUse(fTable)) {
- fTable.addFocusListener(this);
- fScrollbar= fTable.getVerticalBar();
- if (fScrollbar != null)
- fScrollbar.addSelectionListener(this);
- }
- }
-
- /**
- * Uninstalls this closer if previously installed.
- */
- public void uninstall() {
- if (Helper2.okToUse(fScrollbar))
- fScrollbar.removeSelectionListener(this);
- if (Helper2.okToUse(fTable))
- fTable.removeFocusListener(this);
- }
-
- /*
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- fScrollbarClicked= true;
- }
-
- /*
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- fScrollbarClicked= true;
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
- */
- public void focusLost(final FocusEvent e) {
- fScrollbarClicked= false;
- Display d= fTable.getDisplay();
- d.asyncExec(new Runnable() {
- public void run() {
- if (Helper2.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked)
- fContentAssistant.popupFocusLost(e);
- }
- });
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SingleCharReader.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SingleCharReader.java
deleted file mode 100644
index 0ed72714819..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SingleCharReader.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.io.IOException;
-import java.io.Reader;
-
-abstract class SingleCharReader extends Reader {
-
- /**
- * @see Reader#read()
- */
- public abstract int read() throws IOException;
-
- /**
- * @see Reader#read(char[],int,int)
- */
- public int read(char cbuf[], int off, int len) throws IOException {
- int end= off + len;
- for (int i= off; i < end; i++) {
- int ch= read();
- if (ch == -1) {
- if (i == off) {
- return -1;
- } else {
- return i - off;
- }
- }
- cbuf[i]= (char)ch;
- }
- return len;
- }
-
- /**
- * @see Reader#ready()
- */
- public boolean ready() throws IOException {
- return true;
- }
-
- /**
- * Gets the content as a String
- */
- public String getString() throws IOException {
- StringBuffer buf= new StringBuffer();
- int ch;
- while ((ch= read()) != -1) {
- buf.append((char)ch);
- }
- return buf.toString();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SubstitutionTextReader.java b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SubstitutionTextReader.java
deleted file mode 100644
index 3a129d371e6..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/SubstitutionTextReader.java
+++ /dev/null
@@ -1,151 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.internal.text.link.contentassist;
-
-
-import java.io.IOException;
-import java.io.Reader;
-
-
-/**
- * Reads the text contents from a reader and computes for each character
- * a potential substitution. The substitution may eat more characters than
- * only the one passed into the computation routine.
- */
-abstract class SubstitutionTextReader extends SingleCharReader {
-
- protected static final String LINE_DELIM= System.getProperty("line.separator", "\n"); //$NON-NLS-1$ //$NON-NLS-2$
-
- private Reader fReader;
- private boolean fWasWhiteSpace;
- private int fCharAfterWhiteSpace;
-
- /**
- * Tells whether white space characters are skipped.
- */
- private boolean fSkipWhiteSpace= true;
-
- private boolean fReadFromBuffer;
- private StringBuffer fBuffer;
- private int fIndex;
-
-
- protected SubstitutionTextReader(Reader reader) {
- fReader= reader;
- fBuffer= new StringBuffer();
- fIndex= 0;
- fReadFromBuffer= false;
- fCharAfterWhiteSpace= -1;
- fWasWhiteSpace= true;
- }
-
- /**
- * Implement to compute the substitution for the given character and
- * if necessary subsequent characters. Use <code>nextChar</code>
- * to read subsequent characters.
- */
- protected abstract String computeSubstitution(int c) throws IOException;
-
- /**
- * Returns the internal reader.
- */
- protected Reader getReader() {
- return fReader;
- }
-
- /**
- * Returns the next character.
- */
- protected int nextChar() throws IOException {
- fReadFromBuffer= (fBuffer.length() > 0);
- if (fReadFromBuffer) {
- char ch= fBuffer.charAt(fIndex++);
- if (fIndex >= fBuffer.length()) {
- fBuffer.setLength(0);
- fIndex= 0;
- }
- return ch;
- } else {
- int ch= fCharAfterWhiteSpace;
- if (ch == -1) {
- ch= fReader.read();
- }
- if (fSkipWhiteSpace && Character.isWhitespace((char)ch)) {
- do {
- ch= fReader.read();
- } while (Character.isWhitespace((char)ch));
- if (ch != -1) {
- fCharAfterWhiteSpace= ch;
- return ' ';
- }
- } else {
- fCharAfterWhiteSpace= -1;
- }
- return ch;
- }
- }
-
- /**
- * @see Reader#read()
- */
- public int read() throws IOException {
- int c;
- do {
-
- c= nextChar();
- while (!fReadFromBuffer) {
- String s= computeSubstitution(c);
- if (s == null)
- break;
- if (s.length() > 0)
- fBuffer.insert(0, s);
- c= nextChar();
- }
-
- } while (fSkipWhiteSpace && fWasWhiteSpace && (c == ' '));
- fWasWhiteSpace= (c == ' ' || c == '\r' || c == '\n');
- return c;
- }
-
- /**
- * @see Reader#ready()
- */
- public boolean ready() throws IOException {
- return fReader.ready();
- }
-
- /**
- * @see Reader#close()
- */
- public void close() throws IOException {
- fReader.close();
- }
-
- /**
- * @see Reader#reset()
- */
- public void reset() throws IOException {
- fReader.reset();
- fWasWhiteSpace= true;
- fCharAfterWhiteSpace= -1;
- fBuffer.setLength(0);
- fIndex= 0;
- }
-
- protected final void setSkipWhitespace(boolean state) {
- fSkipWhiteSpace= state;
- }
-
- protected final boolean isSkippingWhitespace() {
- return fSkipWhiteSpace;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/package.html
deleted file mode 100644
index 98a5bfbda2f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/internal/text/link/contentassist/package.html
+++ /dev/null
@@ -1,14 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- name="GENERATOR">
- <title>Linked Position Infrastructure - Internal Copy of Content Assistant</title>
-</head>
-<body>
-This package is a modified copy of <code>org.eclipse.jface.text.contentassist</code> that supports the linked mode proposals.
-This package is internal and may disappear if the changes are merged with the API content assist package. Subject to change without notice.
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java
deleted file mode 100644
index 965f6251b84..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractHoverInformationControlManager.java
+++ /dev/null
@@ -1,488 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.events.MouseTrackListener;
-import org.eclipse.swt.events.ShellAdapter;
-import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-
-/**
- * An information control manager that shows information on mouse hover events.
- * The mouse hover events are caught by registering a <code>MouseTrackListener</code>
- * on the manager's subject control. The manager has by default an information control closer
- * that closes the information control as soon as the mouse pointer leaves the subject area, the
- * user presses a key, or the subject control is resized, moved, or deactivated.<p>
- * When being activated by a mouse hover event, the manager disables itself, until the mouse
- * leaves the subject area. Thus, the manager is usually still disabled, when the information control
- * has already been closed by the closer.
- *
- * @see org.eclipse.swt.events.MouseTrackListener
- * @since 2.0
- */
-abstract public class AbstractHoverInformationControlManager extends AbstractInformationControlManager {
-
-
- /**
- * The information control closer for the hover information. Closes the information control as
- * soon as the mouse pointer leaves the subject area, a mouse button is pressed, the user presses a key,
- * or the subject control is resized or moved.
- */
- class Closer extends MouseTrackAdapter
- implements IInformationControlCloser, MouseListener, MouseMoveListener, ControlListener, KeyListener {
-
- /** The closer's subject control */
- private Control fSubjectControl;
- /** The subject area */
- private Rectangle fSubjectArea;
- /** Indicates whether this closer is active */
- private boolean fIsActive= false;
-
- /**
- * Creates a new information control closer.
- */
- public Closer() {
- }
-
- /*
- * @see IInformationControlCloser#setSubjectControl(Control)
- */
- public void setSubjectControl(Control control) {
- fSubjectControl= control;
- }
-
- /*
- * @see IInformationControlCloser#setHoverControl(IHoverControl)
- */
- public void setInformationControl(IInformationControl control) {
- }
-
- /*
- * @see IInformationControlCloser#start(Rectangle)
- */
- public void start(Rectangle subjectArea) {
-
- if (fIsActive) return;
- fIsActive= true;
-
- fSubjectArea= subjectArea;
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.addMouseListener(this);
- fSubjectControl.addMouseMoveListener(this);
- fSubjectControl.addMouseTrackListener(this);
- fSubjectControl.addControlListener(this);
- fSubjectControl.addKeyListener(this);
- }
- }
-
- /*
- * @see IInformationControlCloser#stop()
- */
- public void stop() {
- stop(false);
- }
-
- /**
- * Stops the information control and if <code>delayRestart</code> is set
- * allows restart only after a certain delay.
- *
- * @param delayRestart <code>true</code> if restart should be delayed
- */
- protected void stop(boolean delayRestart) {
-
- if (!fIsActive) return;
- fIsActive= false;
-
- hideInformationControl();
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeMouseListener(this);
- fSubjectControl.removeMouseMoveListener(this);
- fSubjectControl.removeMouseTrackListener(this);
- fSubjectControl.removeControlListener(this);
- fSubjectControl.removeKeyListener(this);
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
- if (!fSubjectArea.contains(event.x, event.y))
- stop();
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent event) {
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent event) {
- stop();
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent event) {
- stop();
- }
-
- /*
- * @see MouseTrackAdapter#mouseExit(MouseEvent)
- */
- public void mouseExit(MouseEvent event) {
- stop();
- }
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent event) {
- stop();
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent event) {
- stop();
- }
-
- /*
- * @see KeyListener#keyReleased(KeyEvent)
- */
- public void keyReleased(KeyEvent event) {
- }
-
- /*
- * @see KeyListener#keyPressed(KeyEvent)
- */
- public void keyPressed(KeyEvent event) {
- stop(true);
- }
- }
-
-
- /**
- * To be installed on the manager's subject control. Serves two different purposes:
- * <ul>
- * <li> start function: initiates the computation of the information to be presented. This happens on
- * receipt of a mouse hover event and disables the information control manager,
- * <li> restart function: tracks mouse move and shell activation event to determine when the information
- * control manager needs to be reactivated.
- * </ul>
- */
- class MouseTracker extends ShellAdapter implements MouseTrackListener, MouseMoveListener {
-
- /** Margin around the original hover event location for coputing the hover area. */
- private final static int EPSILON= 3;
-
- /** The area in which the original hover event occurred. */
- private Rectangle fHoverArea;
- /** The area for which is computed information is valid. */
- private Rectangle fSubjectArea;
- /** The tracker's subject control. */
- private Control fSubjectControl;
-
- /** Indicates whether the tracker is in restart mode ignoring hover events. */
- private boolean fIsInRestartMode= false;
- /** Indicates whether the tracker is computing the information to be presented. */
- private boolean fIsComputing= false;
- /** Indicates whether the mouse has been lost. */
- private boolean fMouseLostWhileComputing= false;
- /** Indicates whether the subject control's shell has been deactivated. */
- private boolean fShellDeactivatedWhileComputing= false;
-
- /**
- * Creates a new mouse tracker.
- */
- public MouseTracker() {
- }
-
- /**
- * Sets this mouse tracker's subject area, the area to be tracked in order
- * to re-enable the information control manager.
- *
- * @param subjectArea the subject area
- */
- public void setSubjectArea(Rectangle subjectArea) {
- Assert.isNotNull(subjectArea);
- fSubjectArea= subjectArea;
- }
-
- /**
- * Starts this mouse tracker. The given control becomes this tracker's subject control.
- * Installs itself as mouse track listener on the subject control.
- *
- * @param subjectControl the subject control
- */
- public void start(Control subjectControl) {
- fSubjectControl= subjectControl;
- if (fSubjectControl != null && !fSubjectControl.isDisposed())
- fSubjectControl.addMouseTrackListener(this);
-
- fIsInRestartMode= false;
- fIsComputing= false;
- fMouseLostWhileComputing= false;
- fShellDeactivatedWhileComputing= false;
- }
-
- /**
- * Stops this mouse tracker. Removes itself as mouse track, mouse move, and
- * shell listener from the subject control.
- */
- public void stop() {
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeMouseTrackListener(this);
- fSubjectControl.removeMouseMoveListener(this);
- fSubjectControl.getShell().removeShellListener(this);
- }
- }
-
- /**
- * Initiates the computation of the information to be presented. Sets the initial hover area
- * to a small rectangle around the hover event location. Adds mouse move and shell activation listeners
- * to track whether the computed information is, after completion, useful for presentation and to
- * implement the restart function.
- *
- * @param event the mouse hover event
- */
- public void mouseHover(MouseEvent event) {
-
- if (fIsComputing || fIsInRestartMode) return;
-
- fIsInRestartMode= true;
- fIsComputing= true;
- fMouseLostWhileComputing= false;
- fShellDeactivatedWhileComputing= false;
-
- fHoverEventStateMask= event.stateMask;
- fHoverEvent= event;
- fHoverArea= new Rectangle(event.x - EPSILON, event.y - EPSILON, 2 * EPSILON, 2 * EPSILON );
- if (fHoverArea.x < 0) fHoverArea.x= 0;
- if (fHoverArea.y < 0) fHoverArea.y= 0;
- setSubjectArea(fHoverArea);
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.addMouseMoveListener(this);
- fSubjectControl.getShell().addShellListener(this);
- }
- doShowInformation();
- }
-
- /**
- * Deactivates this tracker's restart function and enables the information control
- * manager. Does not have any effect if the tracker is still executing the start function (i.e.
- * computing the information to be presented.
- */
- protected void deactivate() {
- if (fIsComputing) return;
- fIsInRestartMode= false;
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeMouseMoveListener(this);
- fSubjectControl.getShell().removeShellListener(this);
- }
- }
-
- /*
- * @see MouseTrackListener#mouseEnter(MouseEvent)
- */
- public void mouseEnter(MouseEvent e) {
- }
-
- /*
- * @see MouseTrackListener#mouseExit(MouseEvent)
- */
- public void mouseExit(MouseEvent e) {
- fMouseLostWhileComputing= true;
- deactivate();
- }
-
- /*
- * @see MouseMoveListener#mouseMove(MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
- if (!fSubjectArea.contains(event.x, event.y))
- deactivate();
- }
-
- /*
- * @see ShellListener#shellDeactivated(ShellEvent)
- */
- public void shellDeactivated(ShellEvent e) {
- fShellDeactivatedWhileComputing= true;
- deactivate();
- }
-
- /*
- * @see ShellListener#shellIconified(ShellEvent)
- */
- public void shellIconified(ShellEvent e) {
- fShellDeactivatedWhileComputing= true;
- deactivate();
- }
-
- /**
- * Tells this tracker that the start function processing has been completed.
- */
- public void computationCompleted() {
- fIsComputing= false;
- fMouseLostWhileComputing= false;
- fShellDeactivatedWhileComputing= false;
- }
-
- /**
- * Determines whether the computed information is still useful for presentation.
- * This is not the case, if the shell of the subject control has been deactivated, the mouse
- * left the subject control, or the mouse moved on, so that it is no longer in the subject
- * area.
- *
- * @return <code>true</code> if information is still useful for presentation, <code>false</code> otherwise
- */
- public boolean isMouseLost() {
-
- if (fMouseLostWhileComputing || fShellDeactivatedWhileComputing)
- return true;
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- Display display= fSubjectControl.getDisplay();
- Point p= display.getCursorLocation();
- p= fSubjectControl.toControl(p);
- if (!fSubjectArea.contains(p) && !fHoverArea.contains(p))
- return true;
- }
-
- return false;
- }
- }
-
- /** The mouse tracker on the subject control */
- private MouseTracker fMouseTracker= new MouseTracker();
- /**
- * The remembered hover event.
- * @since 3.0
- */
- private MouseEvent fHoverEvent= null;
- /** The remembered hover event sate mask of the keyboard modifiers */
- private int fHoverEventStateMask= 0;
-
- /**
- * Creates a new hover information control manager using the given information control creator.
- * By default a <code>Closer</code> instance is set as this manager's closer.
- *
- * @param creator the information control creator
- */
- protected AbstractHoverInformationControlManager(IInformationControlCreator creator) {
- super(creator);
- setCloser(new Closer());
- }
-
- /*
- * @see AbstractInformationControlManager#presentInformation()
- */
- protected void presentInformation() {
- if (fMouseTracker == null) {
- super.presentInformation();
- return;
- }
-
- Rectangle area= getSubjectArea();
- if (area != null)
- fMouseTracker.setSubjectArea(area);
-
- if (fMouseTracker.isMouseLost()) {
- fMouseTracker.computationCompleted();
- fMouseTracker.deactivate();
- } else {
- fMouseTracker.computationCompleted();
- super.presentInformation();
- }
- }
-
- /*
- * @see AbstractInformationControlManager#setEnabled(boolean)
- */
- public void setEnabled(boolean enabled) {
-
- boolean was= isEnabled();
- super.setEnabled(enabled);
- boolean is= isEnabled();
-
- if (was != is && fMouseTracker != null) {
- if (is)
- fMouseTracker.start(getSubjectControl());
- else
- fMouseTracker.stop();
- }
- }
-
- /**
- * Disposes this manager's information control.
- */
- public void dispose() {
- if (fMouseTracker != null) {
- fMouseTracker.stop();
- fMouseTracker.fSubjectControl= null;
- fMouseTracker= null;
- }
- super.dispose();
- }
-
- /**
- * Returns the location at which the most recent mouse hover event
- * has been issued.
- *
- * @return the location of the most recent mouse hover event
- */
- protected Point getHoverEventLocation() {
- return fHoverEvent != null ? new Point(fHoverEvent.x, fHoverEvent.y) : new Point(-1, -1);
- }
-
- /**
- * Returns the most recent mouse hover event.
- *
- * @return the most recent mouse hover event or <code>null</code>
- * @since 3.0
- */
- protected MouseEvent getHoverEvent() {
- return fHoverEvent;
- }
-
- /**
- * Returns the SWT event state of the most recent mouse hover event.
- *
- * @return the SWT event state of the most recent mouse hover event
- */
- protected int getHoverEventStateMask() {
- return fHoverEventStateMask;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java
deleted file mode 100644
index 8044c9944a8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/AbstractInformationControlManager.java
+++ /dev/null
@@ -1,1011 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.dialogs.IDialogSettings;
-
-
-/**
- * Manages the life cycle, visibility, layout, and contents of an <code>IInformationControl</code>.
- * This manager can be installed on and uninstalled from a control, refered to as the subject control, i.e.
- * the one from which the subject of the information to be shown is retrieved. Also a manager can
- * be enabled or disabled. An installed and enabled manager can be forced to show information in
- * its information control using <code>showInformation</code>. An information control
- * manager uses an <code>IInformationControlCloser</code> to define the behavior when
- * a presented information control must be closed. The disposal of the subject and the information
- * control are internally handled by the information control manager and are not the responsibility
- * of the information control closer.
- *
- * @see org.eclipse.jface.text.IInformationControl
- * @since 2.0
- */
-abstract public class AbstractInformationControlManager {
-
- /**
- * Interface of a information control closer. An information control closer
- * monitors its information control and its subject control and closes
- * the information control if necessary. <p>
- * Clients must implement this interface in order to equipe an information
- * control manager accordingly.
- */
- public static interface IInformationControlCloser {
-
- /**
- * Sets the closer's subject control. This is the control that parents
- * the information control and from which the subject of the information
- * to be shown is retrieved. <p>
- * Must be called before <code>start</code>. May again be called
- * between <code>start</code> and <code>stop</code>.
- *
- * @param subject the subject control
- */
- public void setSubjectControl(Control subject);
-
- /**
- * Sets the closer's information control, the one to close if necessary. <p>
- * Must be called before <code>start</code>. May again be called
- * between <code>start</code> and <code>stop</code>.
- *
- * @param control the information control
- */
- public void setInformationControl(IInformationControl control);
-
- /**
- * Tells this closer to start monitoring the subject and the information
- * control. The presented information is considered valid for the given
- * area of the subject control's display.
- *
- * @param subjectArea the area for which the presented information is valid
- */
- public void start(Rectangle subjectArea);
-
- /**
- * Tells this closer to stop monitoring the subject and the information control.
- */
- public void stop();
- }
-
-
-
- /**
- * Constitutes entities to enumerate anchors for the layout of the information control.
- */
- public static final class Anchor {
- private Anchor() {
- }
- }
-
- /** Internal anchor list. */
- private final static Anchor[] ANCHORS= { new Anchor(), new Anchor(), new Anchor(), new Anchor() };
-
- /** Anchor representing the top of the information area */
- public final static Anchor ANCHOR_TOP= ANCHORS[0];
- /** Anchor representing the bottom of the information area */
- public final static Anchor ANCHOR_BOTTOM= ANCHORS[1];
- /** Anchor representing the left side of the information area */
- public final static Anchor ANCHOR_LEFT= ANCHORS[2];
- /** Anchor representing the right side of the information area */
- public final static Anchor ANCHOR_RIGHT= ANCHORS[3];
- /**
- * Anchor representing the middle of the subject control
- * @since 2.1
- */
- public final static Anchor ANCHOR_GLOBAL= new Anchor();
-
- /**
- * Dialog store constant for the location's x-coordinate.
- * @since 3.0
- */
- public static final String STORE_LOCATION_X= "location.x"; //$NON-NLS-1$
- /**
- * Dialog store constant for the location's y-coordinate.
- * @since 3.0
- */
- public static final String STORE_LOCATION_Y= "location.y"; //$NON-NLS-1$
- /**
- * Dialog store constant for the size's width.
- * @since 3.0
- */
- public static final String STORE_SIZE_WIDTH= "size.width"; //$NON-NLS-1$
- /**
- * Dialog store constant for the size's height.
- * @since 3.0
- */
- public static final String STORE_SIZE_HEIGHT= "size.height"; //$NON-NLS-1$
-
-
- /** The subject control of the information control */
- private Control fSubjectControl;
-
- /** The display area for which the information to be presented is valid */
- private Rectangle fSubjectArea;
-
- /** The information to be presented */
- private Object fInformation;
-
- /** Indicates whether the information control takes focus when visible */
- private boolean fTakesFocusWhenVisible= false;
-
- /** The information control */
- protected IInformationControl fInformationControl;
-
- /** The information control creator */
- protected IInformationControlCreator fInformationControlCreator;
-
- /** The information control closer */
- protected IInformationControlCloser fInformationControlCloser;
-
- /** Indicates that the information control has been disposed */
- protected boolean fDisposed= false;
-
- /** Indicates the enable state of this manager */
- private boolean fEnabled= false;
-
- /** Cached, computed size constraints of the information control in points */
- private Point fSizeConstraints;
-
- /** The y margin when laying out the information control */
- private int fMarginY= 5;
-
- /** The x margin when laying out the information control */
- private int fMarginX= 5;
-
- /** The width contraint of the information control in characters */
- private int fWidthConstraint= 60;
-
- /** The height constraint of the information control in characters */
- private int fHeightConstraint= 6;
-
- /** Indicates wether the size constraints should be enforced as minimal control size */
- private boolean fEnforceAsMinimalSize= false;
-
- /** Indicates whether the size constraints should be enforced as maximal control size */
- private boolean fEnforceAsMaximalSize= false;
-
- /** The anchor for laying out the information control in relation to the subject control */
- private Anchor fAnchor= ANCHOR_BOTTOM;
-
- /**
- * A list of anchors used to layout the information control if the original anchor can not
- * be used because the information control would not fit in the display client area.
- */
- private Anchor[] fFallbackAnchors= ANCHORS;
-
- /**
- * The custom information control creator.
- * @since 3.0
- */
- private volatile IInformationControlCreator fCustomInformationControlCreator;
-
- /**
- * Tells whether a custom information control is in use.
- * @since 3.0
- */
- private boolean fIsCustomInformationControl= false;
-
- /**
- * The dialog settings for the control's bounds.
- *
- * @since 3.0
- */
- private IDialogSettings fDialogSettings;
-
- /**
- * Tells whether the control's location should be read
- * from the dialog settings and whether the last
- * valid control's size is stored back into the settings.
- *
- * @since 3.0
- */
- private boolean fIsRestoringLocation;
-
- /**
- * Tells whether the control's size should be read
- * from the dialog settings and whether the last
- * valid control's size is stored back into the settings.
- *
- * @since 3.0
- */
- private boolean fIsRestoringSize;
-
-
- /**
- * Creates a new information control manager using the given information control creator.
- * By default the following configuration is given:
- * <ul>
- * <li> enabled == false
- * <li> x-margin == 5 points
- * <li> y-margin == 5 points
- * <li> width constraint == 60 characters
- * <li> height constraint == 6 characters
- * <li> enforce constraints as minimal size == false
- * <li> enforce constraints as maximal size == false
- * <li> layout anchor == ANCHOR_BOTTOM
- * <li> fallback anchors == { ANCHOR_TOP, ANCHOR_BOTTOM, ANCHOR_LEFT, ANCHOR_RIGHT, ANCHOR_GLOBAL }
- * <li> takes focus when visible == false
- * </ul>
- *
- * @param creator the information control creator
- */
- protected AbstractInformationControlManager(IInformationControlCreator creator) {
- Assert.isNotNull(creator);
- fInformationControlCreator= creator;
- }
-
- /**
- * Computes the information to be displayed and the area in which the computed
- * information is valid. Implementation of this method must finish their computation
- * by setting the computation results using <code>setInformation</code>.
- */
- abstract protected void computeInformation();
-
- /**
- * Sets the parameters of the information to be displayed. These are the information itself and
- * the area for which the given information is valid. This so called subject area is a graphical
- * region of the information control's subject control. This method calls <code>presentInformation()</code>
- * to trigger the presentation of the computed information.
- *
- * @param information the information
- * @param subjectArea the subject area
- */
- protected final void setInformation(String information, Rectangle subjectArea) {
- fInformation= information;
- fSubjectArea= subjectArea;
- presentInformation();
- }
-
- /**
- * Sets the parameters of the information to be displayed. These are the information itself and
- * the area for which the given information is valid. This so called subject area is a graphical
- * region of the information control's subject control. This method calls <code>presentInformation()</code>
- * to trigger the presentation of the computed information.
- *
- * @param information the information
- * @param subjectArea the subject area
- * @since 2.1
- */
- protected final void setInformation(Object information, Rectangle subjectArea) {
- fInformation= information;
- fSubjectArea= subjectArea;
- presentInformation();
- }
-
- /**
- * Sets the information control closer for this manager.
- *
- * @param closer the information control closer for this manager
- */
- protected void setCloser(IInformationControlCloser closer) {
- fInformationControlCloser= closer;
- }
-
- /**
- * Sets the x- and y- margin to be used when laying out the information control
- * relative to the subject control.
- *
- * @param xMargin the x-margin
- * @param yMargin the y-Margin
- */
- public void setMargins(int xMargin, int yMargin) {
- fMarginX= xMargin;
- fMarginY= yMargin;
- }
-
- /**
- * Sets the width- and height constraints of the information control.
- *
- * @param widthInChar the width constraint in number of characters
- * @param heightInChar the height constrain in number of characters
- * @param enforceAsMinimalSize indicates whether the constraints describe the minimal allowed size of the control
- * @param enforceAsMaximalSize indicates whether the constraints describe the maximal allowed size of the control
- */
- public void setSizeConstraints(int widthInChar, int heightInChar, boolean enforceAsMinimalSize, boolean enforceAsMaximalSize) {
- fSizeConstraints= null;
- fWidthConstraint= widthInChar;
- fHeightConstraint= heightInChar;
- fEnforceAsMinimalSize= enforceAsMinimalSize;
- fEnforceAsMaximalSize= enforceAsMaximalSize;
-
- }
-
- /**
- * Tells this information control manager to open the information
- * control with the values contained in the given dialog settings
- * and to store the control's last valid size in the given dialog
- * settings.
- * <p>
- * Note: This API is only valid if the information control implements
- * {@link IInformationControlExtension3}. Not following this restriction
- * will later result in an {@link UnsupportedOperationException}.
- * </p>
- * <p>
- * The constants used to store the values are:
- * <ul>
- * <li>{@link AbstractInformationControlManager#STORE_LOCATION_X}</li>
- * <li>{@link AbstractInformationControlManager#STORE_LOCATION_Y}</li>
- * <li>{@link AbstractInformationControlManager#STORE_SIZE_WIDTH}</li>
- * <li>{@link AbstractInformationControlManager#STORE_SIZE_HEIGHT}</li>
- * </ul>
- * </p>
- *
- * @param dialogSettings
- * @param restoreLocation <code>true</code> iff the location is must be (re-)stored
- * @param restoreSize <code>true</code>iff the size is (re-)stored
- * @since 3.0
- */
- public void setRestoreInformationControlBounds(IDialogSettings dialogSettings, boolean restoreLocation, boolean restoreSize) {
- Assert.isTrue(dialogSettings != null && (restoreLocation || restoreSize));
- fDialogSettings= dialogSettings;
- fIsRestoringLocation= restoreLocation;
- fIsRestoringSize= restoreSize;
- }
-
- /**
- * Sets the anchor used for laying out the information control relative to the
- * subject control. E.g, using <code>ANCHOR_TOP</code> indicates that the
- * information control is position above the area for which the information to
- * be displayed is valid.
- *
- * @param anchor the layout anchor
- */
- public void setAnchor(Anchor anchor) {
- fAnchor= anchor;
- }
-
- /**
- * Sets the sequence of anchors along which the information control is tried to
- * be laid out until it is fully visible. This fallback is initiated when the information
- * control does not fit into the client area of the subject control's display.
- *
- * @param fallbackAnchors the list of anchors to be tried
- */
- public void setFallbackAnchors(Anchor[] fallbackAnchors) {
- fFallbackAnchors= fallbackAnchors;
- }
-
- /**
- * Sets the temporary custom control creator, overriding this manager's default information control creator.
- *
- * @param informationControlCreator
- * @since 3.0
- */
- protected void setCustomInformationControlCreator(IInformationControlCreator informationControlCreator) {
- if (fCustomInformationControlCreator instanceof IInformationControlCreatorExtension) {
- IInformationControlCreatorExtension extension= (IInformationControlCreatorExtension) fCustomInformationControlCreator;
- if (extension.canReplace(informationControlCreator))
- return;
- }
- fCustomInformationControlCreator= informationControlCreator;
- }
-
- /**
- * Tells the manager whether it should set the focus to the information control when made visible.
- *
- * @param takesFocus <code>true</code> if information control should take focus when made visible
- */
- public void takesFocusWhenVisible(boolean takesFocus) {
- fTakesFocusWhenVisible= takesFocus;
- }
-
- /**
- * Handles the disposal of the subject control. By default, the information control
- * is disposed by calling <code>disposeInformationControl</code>. Subclasses may extend
- * this method.
- */
- protected void handleSubjectControlDisposed() {
- disposeInformationControl();
- }
-
- /**
- * Installs this manager on the given control. The control is now taking the role of
- * the subject control. This implementation sets the control also as the information
- * control closer's subject control and automatically enables this manager.
- *
- * @param subjectControl the subject control
- */
- public void install(Control subjectControl) {
- fSubjectControl= subjectControl;
-
- if (fSubjectControl != null) {
- fSubjectControl.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleSubjectControlDisposed();
- }
- });
- }
-
- if (fInformationControlCloser != null)
- fInformationControlCloser.setSubjectControl(subjectControl);
-
- setEnabled(true);
- fDisposed= false;
- }
-
- /**
- * Returns the subject control of this manager/information control.
- *
- * @return the subject control
- */
- protected Control getSubjectControl() {
- return fSubjectControl;
- }
-
- /**
- * Returns the actual subject area.
- *
- * @return the actual subject area
- */
- protected Rectangle getSubjectArea() {
- return fSubjectArea;
- }
-
- /**
- * Sets the enable state of this manager.
- *
- * @param enabled the enable state
- * @deprecated visibility will be changed to protected
- */
- public void setEnabled(boolean enabled) {
- fEnabled= enabled;
- }
-
- /**
- * Returns whether this manager is enabled or not.
- *
- * @return <code>true</code> if this manager is enabled otherwise <code>false</code>
- */
- protected boolean isEnabled() {
- return fEnabled;
- }
-
- /**
- * Computes the size constraints of the information control in points based on the
- * default font of the given subject control as well as the size constraints in character
- * width.
- *
- * @param subjectControl the subject control
- * @param informationControl the information control whose size constraints are computed
- * @return the computed size constraints in points
- */
- protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) {
-
- if (fSizeConstraints == null) {
-
- if (subjectControl == null)
- return null;
-
- GC gc= new GC(subjectControl);
- gc.setFont(subjectControl.getFont());
- int width= gc.getFontMetrics().getAverageCharWidth();
- int height = gc.getFontMetrics().getHeight();
- gc.dispose();
-
- fSizeConstraints= new Point (fWidthConstraint * width, fHeightConstraint * height);
- }
-
- return fSizeConstraints;
- }
-
- /**
- * Computes the size constraints of the information control in points.
- *
- * @param subjectControl the subject control
- * @param subjectArea the subject area
- * @param informationControl the information control whose size constraints are computed
- * @return the computed size constraints in points
- * @since 3.0
- */
- protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) {
- return computeSizeConstraints(subjectControl, informationControl);
- }
-
- /**
- * Handles the disposal of the information control. By default, the information
- * control closer is stopped.
- */
- protected void handleInformationControlDisposed() {
-
- storeInformationControlBounds();
-
- fInformationControl= null;
- if (fInformationControlCloser != null) {
- fInformationControlCloser.setInformationControl(null);
- fInformationControlCloser.stop();
- }
- }
-
- /**
- * Returns the information control. If the information control has not been created yet,
- * it is automatically created.
- *
- * @return the information control
- */
- protected IInformationControl getInformationControl() {
-
- if (fDisposed)
- return fInformationControl;
-
- IInformationControlCreator creator= null;
-
- if (fCustomInformationControlCreator == null) {
- creator= fInformationControlCreator;
- if (fIsCustomInformationControl && fInformationControl != null) {
- fInformationControl.dispose();
- fInformationControl= null;
- }
- fIsCustomInformationControl= false;
-
- } else {
-
- creator= fCustomInformationControlCreator;
- if (creator instanceof IInformationControlCreatorExtension) {
- IInformationControlCreatorExtension extension= (IInformationControlCreatorExtension) creator;
- if (extension.canReuse(fInformationControl))
- return fInformationControl;
- }
- if (fInformationControl != null) {
- fInformationControl.dispose();
- fInformationControl= null;
- }
- fIsCustomInformationControl= true;
- }
-
- if (fInformationControl == null) {
- fInformationControl= creator.createInformationControl(fSubjectControl.getShell());
- fInformationControl.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleInformationControlDisposed();
- }
- });
-
- if (fInformationControlCloser != null)
- fInformationControlCloser.setInformationControl(fInformationControl);
- }
-
- return fInformationControl;
- }
-
- /**
- * Computes the display location of the information control. The location is computed
- * considering the given subject area, the anchor at the subject area, and the
- * size of the information control. This method does not care about whether the information
- * control would be completely visible when placed at the result location.
- *
- * @param subjectArea the subject area
- * @param controlSize the size of the information control
- * @param anchor the anchor at the subject area
- * @return the display location of the information control
- */
- protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) {
-
- if (ANCHOR_GLOBAL == anchor) {
- Point subjectControlSize= fSubjectControl.getSize();
- Point location= new Point(subjectControlSize.x / 2, subjectControlSize.y / 2);
- location.x -= (controlSize.x / 2);
- location.y -= (controlSize.y / 2);
- return fSubjectControl.toDisplay(location);
- }
-
- int xShift= 0;
- int yShift= 0;
-
- if (ANCHOR_BOTTOM == anchor) {
- xShift= fMarginX;
- yShift= subjectArea.height + fMarginY;
- } else if (ANCHOR_RIGHT == anchor) {
- xShift= fMarginX + subjectArea.width;
- yShift= fMarginY;
- } else if (ANCHOR_TOP == anchor) {
- xShift= fMarginX;
- yShift= -controlSize.y - fMarginY;
- } else if (ANCHOR_LEFT == anchor) {
- xShift= -controlSize.x - fMarginX;
- yShift= fMarginY;
- }
-
- return fSubjectControl.toDisplay(new Point(subjectArea.x + xShift, subjectArea.y + yShift));
- }
-
- /**
- * Checks whether a control of the given size at the given location would be completely visible
- * in the given display area when laid out by using the given anchor. If not, this method tries
- * to shift the control orthogonal to the direction given by the anchor to make it visible. If possible
- * it updates the location.<p>
- * This method returns <code>true</code> if the potentially updated position results in a
- * completely visible control, or <code>false</code> otherwise.
- *
- *
- * @param location the location of the control
- * @param size the size of the control
- * @param displayArea the display area in which the control should be visible
- * @param anchor anchor for lying out the control
- * @return <code>true</code>if the updated location is useful
- */
- protected boolean updateLocation(Point location, Point size, Rectangle displayArea, Anchor anchor) {
-
- int displayLowerRightX= displayArea.x + displayArea.width;
- int displayLowerRightY= displayArea.y + displayArea.height;
- int lowerRightX= location.x + size.x;
- int lowerRightY= location.y + size.y;
-
- if (ANCHOR_BOTTOM == anchor || ANCHOR_TOP == anchor) {
-
- if (ANCHOR_BOTTOM == anchor) {
- if (lowerRightY > displayLowerRightY)
- return false;
- } else {
- if (location.y < displayArea.y)
- return false;
- }
-
- if (lowerRightX > displayLowerRightX)
- location.x= location.x - (lowerRightX - displayLowerRightX);
-
- return (location.x >= 0 && location.y >= 0);
-
- } else if (ANCHOR_RIGHT == anchor || ANCHOR_LEFT == anchor) {
-
- if (ANCHOR_RIGHT == anchor) {
- if (lowerRightX > displayLowerRightX)
- return false;
- } else {
- if (location.x < displayArea.x)
- return false;
- }
-
- if (lowerRightY > displayLowerRightY)
- location.y= location.y - (lowerRightY - displayLowerRightY);
-
- return (location.x >= 0 && location.y >= 0);
-
- } else if (ANCHOR_GLOBAL == anchor) {
-
- if (lowerRightX > displayLowerRightX)
- location.x= location.x - (lowerRightX - displayLowerRightX);
-
- if (lowerRightY > displayLowerRightY)
- location.y= location.y - (lowerRightY - displayLowerRightY);
-
- return (location.x >= 0 && location.y >= 0);
- }
-
- return false;
- }
-
- /**
- * Returns the next fallback anchor from this manager's list of fallback anchors.
- * If no more fallback anchor is available <code>null</code> is returned.
- *
- * @param anchor the current anchor
- * @return the next fallback anchor or <code>null</code> if no more anchor is available
- */
- protected Anchor getNextFallbackAnchor(Anchor anchor) {
-
- if (anchor == null || fFallbackAnchors == null)
- return null;
-
- for (int i= 0; i < fFallbackAnchors.length; i++) {
- if (fFallbackAnchors[i] == anchor)
- return fFallbackAnchors[i + 1 == fFallbackAnchors.length ? 0 : i + 1];
- }
-
- return null;
- }
-
- /**
- * Computes the location of the information control depending on the
- * subject area and the size of the information control. This method attempts
- * to find a location at which the information control lies completely in the display's
- * client area honoring the manager's default anchor. If this isn't possible using the
- * default anchor, the fallback anchors are tried out.
- *
- * @param subjectArea the information area
- * @param controlSize the size of the information control
- * @return the computed location of the information control
- */
- protected Point computeInformationControlLocation(Rectangle subjectArea, Point controlSize) {
-
- Rectangle displayBounds= fSubjectControl.getDisplay().getClientArea();
-
- Point upperLeft;
- Anchor testAnchor= fAnchor;
- do {
-
- upperLeft= computeLocation(subjectArea, controlSize, testAnchor);
- if (updateLocation(upperLeft, controlSize, displayBounds, testAnchor))
- break;
- testAnchor= getNextFallbackAnchor(testAnchor);
-
- } while (testAnchor != fAnchor && testAnchor != null);
-
- return upperLeft;
- }
-
- /**
- * Computes information to be displayed as well as the subject area
- * and initiates that this information is presented in the information control.
- * This happens only if this controller is enabled.
- */
- public void showInformation() {
- if (fEnabled)
- doShowInformation();
- }
-
- /**
- * Computes information to be displayed as well as the subject area
- * and initiates that this information is presented in the information control.
- */
- protected void doShowInformation() {
- fSubjectArea= null;
- fInformation= null;
- computeInformation();
- }
-
- /**
- * Presents the information in the information control or hides the information
- * control if no information should be presented. The information has previously
- * been set using <code>setInformation</code>.
- */
- protected void presentInformation() {
- boolean hasContents= false;
- if (fInformation instanceof String)
- hasContents= ((String)fInformation).trim().length() > 0;
- else
- hasContents= (fInformation != null);
-
- if (fSubjectArea != null && hasContents)
- internalShowInformationControl(fSubjectArea, fInformation);
- else
- hideInformationControl();
- }
-
- /**
- * Opens the information control with the given information and the specified
- * subject area. It also activates the information control closer.
- *
- * @param subjectArea the information area
- * @param information the information
- */
- private void internalShowInformationControl(Rectangle subjectArea, Object information) {
-
- IInformationControl informationControl= getInformationControl();
- if (informationControl != null) {
-
- Point sizeConstraints= computeSizeConstraints(fSubjectControl, fSubjectArea, informationControl);
- informationControl.setSizeConstraints(sizeConstraints.x, sizeConstraints.y);
-
- if (informationControl instanceof IInformationControlExtension2)
- ((IInformationControlExtension2)informationControl).setInput(information);
- else
- informationControl.setInformation(information.toString());
-
- if (informationControl instanceof IInformationControlExtension) {
- IInformationControlExtension extension= (IInformationControlExtension)informationControl;
- if (!extension.hasContents())
- return;
- }
-
- Point size= null;
- Point location= null;
- Rectangle bounds= restoreInformationControlBounds();
-
- if (bounds != null) {
- if (bounds.x > -1 && bounds.y > -1)
- location= new Point(bounds.x, bounds.y);
-
- if (bounds.width > -1 && bounds.height > -1)
- size= new Point(bounds.width, bounds.height);
- }
-
- if (size == null)
- size= informationControl.computeSizeHint();
-
- if (fEnforceAsMinimalSize) {
- if (size.x < sizeConstraints.x)
- size.x= sizeConstraints.x;
- if (size.y < sizeConstraints.y)
- size.y= sizeConstraints.y;
- }
-
- if (fEnforceAsMaximalSize) {
- if (size.x > sizeConstraints.x)
- size.x= sizeConstraints.x;
- if (size.y > sizeConstraints.y)
- size.y= sizeConstraints.y;
- }
-
- informationControl.setSize(size.x, size.y);
-
- if (location == null)
- location= computeInformationControlLocation(subjectArea, size);
-
- informationControl.setLocation(location);
-
- showInformationControl(subjectArea);
- }
- }
-
- /**
- * Hides the information control and stops the information control closer.
- */
- protected void hideInformationControl() {
- if (fInformationControl != null) {
- storeInformationControlBounds();
- fInformationControl.setVisible(false);
- if (fInformationControlCloser != null)
- fInformationControlCloser.stop();
- }
- }
-
- /**
- * Shows the information control and starts the information control closer.
- * This method may not be called by clients.
- *
- * @param subjectArea the information area
- */
- protected void showInformationControl(Rectangle subjectArea) {
- fInformationControl.setVisible(true);
-
- if (fTakesFocusWhenVisible)
- fInformationControl.setFocus();
-
- if (fInformationControlCloser != null)
- fInformationControlCloser.start(subjectArea);
- }
-
- /**
- * Disposes this manager's information control.
- */
- public void disposeInformationControl() {
- if (fInformationControl != null) {
- fInformationControl.dispose();
- handleInformationControlDisposed();
- }
- }
-
- /**
- * Disposes this manager and if necessary all dependent parts such as
- * the information control. For symmetry it first disables this manager.
- */
- public void dispose() {
- if (!fDisposed) {
-
- fDisposed= true;
-
- setEnabled(false);
- disposeInformationControl();
-
- fIsCustomInformationControl= false;
- fCustomInformationControlCreator= null;
- fInformationControlCreator= null;
- fInformationControlCloser= null;
- }
- }
-
- // ------ control's size handling dialog settings ------
-
- /**
- * Stores the information control's bounds.
- *
- * @since 3.0
- */
- protected void storeInformationControlBounds() {
- if (fDialogSettings == null || fInformationControl == null || !(fIsRestoringLocation || fIsRestoringSize))
- return;
-
- if (!(fInformationControl instanceof IInformationControlExtension3))
- throw new UnsupportedOperationException();
-
- boolean controlRestoresSize= ((IInformationControlExtension3)fInformationControl).restoresSize();
- boolean controlRestoresLocation= ((IInformationControlExtension3)fInformationControl).restoresLocation();
-
- Rectangle bounds= ((IInformationControlExtension3)fInformationControl).getBounds();
- if (bounds == null)
- return;
-
- if (fIsRestoringSize && controlRestoresSize) {
- fDialogSettings.put(STORE_SIZE_WIDTH, bounds.width);
- fDialogSettings.put(STORE_SIZE_HEIGHT, bounds.height);
- }
- if (fIsRestoringLocation && controlRestoresLocation) {
- fDialogSettings.put(STORE_LOCATION_X, bounds.x);
- fDialogSettings.put(STORE_LOCATION_Y, bounds.y);
- }
- }
- /**
- * Restores the information control's bounds.
- *
- * @return the stored bounds
- * @since 3.0
- */
- protected Rectangle restoreInformationControlBounds() {
- if (fDialogSettings == null || !(fIsRestoringLocation || fIsRestoringSize))
- return null;
-
- if (!(fInformationControl instanceof IInformationControlExtension3))
- throw new UnsupportedOperationException();
-
- boolean controlRestoresSize= ((IInformationControlExtension3)fInformationControl).restoresSize();
- boolean controlRestoresLocation= ((IInformationControlExtension3)fInformationControl).restoresLocation();
-
- Rectangle bounds= new Rectangle(-1, -1, -1, -1);
-
- if (fIsRestoringSize && controlRestoresSize) {
- try {
- bounds.width= fDialogSettings.getInt(STORE_SIZE_WIDTH);
- bounds.height= fDialogSettings.getInt(STORE_SIZE_HEIGHT);
- } catch (NumberFormatException ex) {
- bounds.width= -1;
- bounds.height= -1;
- }
- }
-
- if (fIsRestoringLocation && controlRestoresLocation) {
- try {
- bounds.x= fDialogSettings.getInt(STORE_LOCATION_X);
- bounds.y= fDialogSettings.getInt(STORE_LOCATION_Y);
- } catch (NumberFormatException ex) {
- bounds.x= -1;
- bounds.y= -1;
- }
- }
-
- // sanity check
- if (bounds.x == -1 && bounds.y == -1 && bounds.width == -1 && bounds.height == -1)
- return null;
-
- Rectangle maxBounds= null;
- if (fSubjectControl != null && !fSubjectControl.isDisposed())
- maxBounds= fSubjectControl.getDisplay().getBounds();
- else {
- // fallback
- Display display= Display.getCurrent();
- if (display == null)
- display= Display.getDefault();
- if (display != null && !display.isDisposed())
- maxBounds= display.getBounds();
- }
-
-
- if (bounds.width > -1 && bounds.height > -1) {
- if (maxBounds != null) {
- bounds.width= Math.min(bounds.width, maxBounds.width);
- bounds.height= Math.min(bounds.height, maxBounds.height);
- }
-
- // Enforce an absolute minimal size
- bounds.width= Math.max(bounds.width, 30);
- bounds.height= Math.max(bounds.height, 30);
- }
-
- if (bounds.x > -1 && bounds.y > -1 && maxBounds != null) {
- bounds.x= Math.max(bounds.x, maxBounds.x);
- bounds.y= Math.max(bounds.y, maxBounds.y);
-
- if (bounds .width > -1 && bounds.height > -1) {
- bounds.x= Math.min(bounds.x, maxBounds.width - bounds.width);
- bounds.y= Math.min(bounds.y, maxBounds.height - bounds.height);
- }
- }
-
- return bounds;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/CursorLinePainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/CursorLinePainter.java
deleted file mode 100644
index e827c409989..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/CursorLinePainter.java
+++ /dev/null
@@ -1,259 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.custom.LineBackgroundEvent;
-import org.eclipse.swt.custom.LineBackgroundListener;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-
-
-/**
- * A painter the draws the background of the cursor line in a configured color.
- * Clients usually instantiate and configure object of this class.<p>
- * This class is not intended to be subclassed.
- *
- * @since 2.1
- */
-public class CursorLinePainter implements IPainter, LineBackgroundListener {
-
- /** The viewer the painter works on */
- private final ITextViewer fViewer;
- /** The cursor line back ground color */
- private Color fHighlightColor;
- /** The paint position manager for managing the line coordinates */
- private IPaintPositionManager fPositionManager;
-
- /** Keeps track of the line to be painted */
- private Position fCurrentLine= new Position(0, 0);
- /** Keeps track of the line to be cleared */
- private Position fLastLine= new Position(0, 0);
- /** Keeps track of the line number of the last painted line */
- private int fLastLineNumber= -1;
- /** Indicates whether this painter is active */
- private boolean fIsActive;
-
- /**
- * Creates a new painter for the given source viewer.
- *
- * @param textViewer the source viewer for which to create a painter
- */
- public CursorLinePainter(ITextViewer textViewer) {
- fViewer= textViewer;
- }
-
- /**
- * Sets the color in which to draw the background of the cursor line.
- *
- * @param highlightColor the color in which to draw the background of the cursor line
- */
- public void setHighlightColor(Color highlightColor) {
- fHighlightColor= highlightColor;
- }
-
- /*
- * @see LineBackgroundListener#lineGetBackground(LineBackgroundEvent)
- */
- public void lineGetBackground(LineBackgroundEvent event) {
- // don't use cached line information because of asynch painting
-
- StyledText textWidget= fViewer.getTextWidget();
- if (textWidget != null) {
-
- int caret= textWidget.getCaretOffset();
- int length= event.lineText.length();
-
- if (event.lineOffset <= caret && caret <= event.lineOffset + length)
- event.lineBackground= fHighlightColor;
- else
- event.lineBackground= textWidget.getBackground();
- }
- }
-
- /**
- * Updates all the cached information about the lines to be painted and to be cleared. Returns <code>true</code>
- * if the line number of the cursor line has changed.
- *
- * @return <code>true</code> if cursor line changed
- */
- private boolean updateHighlightLine() {
- try {
-
- IDocument document= fViewer.getDocument();
- int lineNumber= document.getLineOfOffset(getModelCaret());
-
- // redraw if the current line number is different from the last line number we painted
- // initially fLastLineNumber is -1
- if (lineNumber != fLastLineNumber) {
-
- fLastLine.offset= fCurrentLine.offset;
- fLastLine.length= fCurrentLine.length;
- fLastLine.isDeleted= fCurrentLine.isDeleted;
-
- if (fCurrentLine.isDeleted) {
- fCurrentLine.isDeleted= false;
- fPositionManager.managePosition(fCurrentLine);
- }
-
- fCurrentLine.offset= document.getLineOffset(lineNumber);
- if (lineNumber == document.getNumberOfLines() - 1)
- fCurrentLine.length= document.getLength() - fCurrentLine.offset;
- else
- fCurrentLine.length= document.getLineOffset(lineNumber + 1) - fCurrentLine.offset;
-
- fLastLineNumber= lineNumber;
- return true;
-
- }
-
- } catch (BadLocationException e) {
- }
-
- return false;
- }
-
- /**
- * Returns the location of the caret as offset in the source viewer's
- * input document.
- *
- * @return the caret location
- */
- private int getModelCaret() {
- int widgetCaret= fViewer.getTextWidget().getCaretOffset();
- if (fViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer;
- return extension.widgetOffset2ModelOffset(widgetCaret);
- } else {
- IRegion visible= fViewer.getVisibleRegion();
- return widgetCaret + visible.getOffset();
- }
- }
-
- /**
- * Assumes the given position to specify offset and length of a line to be painted.
- *
- * @param position the specification of the line to be painted
- */
- private void drawHighlightLine(Position position) {
-
- // if the position that is about to be drawn was deleted then we can't
- if (position.isDeleted())
- return;
-
- int widgetOffset= 0;
- if (fViewer instanceof ITextViewerExtension5) {
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer;
- widgetOffset= extension.modelOffset2WidgetOffset(position.getOffset());
- if (widgetOffset == -1)
- return;
-
- } else {
-
- IRegion visible= fViewer.getVisibleRegion();
- widgetOffset= position.getOffset() - visible.getOffset();
- if (widgetOffset < 0 || visible.getLength() < widgetOffset )
- return;
- }
-
- StyledText textWidget= fViewer.getTextWidget();
- // check for https://bugs.eclipse.org/bugs/show_bug.cgi?id=64898
- // this is a guard against the symptoms but not the actual solution
- if (0 <= widgetOffset && widgetOffset <= textWidget.getCharCount()) {
- Point upperLeft= textWidget.getLocationAtOffset(widgetOffset);
- int width= textWidget.getClientArea().width + textWidget.getHorizontalPixel();
- int height= textWidget.getLineHeight();
- textWidget.redraw(0, upperLeft.y, width, height, false);
- }
- }
-
- /*
- * @see IPainter#deactivate(boolean)
- */
- public void deactivate(boolean redraw) {
- if (fIsActive) {
- fIsActive= false;
-
- /* on turning off the feature one has to paint the currently
- * highlighted line with the standard background color
- */
- if (redraw)
- drawHighlightLine(fCurrentLine);
-
- fViewer.getTextWidget().removeLineBackgroundListener(this);
-
- if (fPositionManager != null)
- fPositionManager.unmanagePosition(fCurrentLine);
-
- fLastLineNumber= -1;
- fCurrentLine.offset= 0;
- fCurrentLine.length= 0;
- }
- }
-
- /*
- * @see IPainter#dispose()
- */
- public void dispose() {
- }
-
- /*
- * @see IPainter#paint(int)
- */
- public void paint(int reason) {
- if (fViewer.getDocument() == null) {
- deactivate(false);
- return;
- }
-
- StyledText textWidget= fViewer.getTextWidget();
-
- // check selection
- Point selection= textWidget.getSelection();
- int startLine= textWidget.getLineAtOffset(selection.x);
- int endLine= textWidget.getLineAtOffset(selection.y);
- if (startLine != endLine) {
- deactivate(true);
- return;
- }
-
- // initialization
- if (!fIsActive) {
- textWidget.addLineBackgroundListener(this);
- fPositionManager.managePosition(fCurrentLine);
- fIsActive= true;
- }
-
- //redraw line highlight only if it hasn't been drawn yet on the respective line
- if (updateHighlightLine()) {
- // clear last line
- drawHighlightLine(fLastLine);
- // draw new line
- drawHighlightLine(fCurrentLine);
- }
- }
-
- /*
- * @see IPainter#setPositionManager(IPaintPositionManager)
- */
- public void setPositionManager(IPaintPositionManager manager) {
- fPositionManager = manager;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java
deleted file mode 100644
index 71a3f45a557..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultAutoIndentStrategy.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-
-/**
- * Default implementation of <code>IAutoIndentStrategy</code>.
- * This strategy always copies the indentation of the previous line.
- */
-public class DefaultAutoIndentStrategy implements IAutoIndentStrategy {
-
- /**
- * Creates a new default auto indent strategy which can be installed on
- * text viewers.
- */
- public DefaultAutoIndentStrategy() {
- }
-
- /**
- * Returns the first offset greater than <code>offset</code> and smaller than
- * <code>end</code> whose character is not a space or tab character. If no such
- * offset is found, <code>end</code> is returned.
- *
- * @param document the document to search in
- * @param offset the offset at which searching start
- * @param end the offset at which searching stops
- * @return the offset in the specifed range whose character is not a space or tab
- * @exception BadLocationException if position is an invalid range in the given document
- */
- protected int findEndOfWhiteSpace(IDocument document, int offset, int end) throws BadLocationException {
- while (offset < end) {
- char c= document.getChar(offset);
- if (c != ' ' && c != '\t') {
- return offset;
- }
- offset++;
- }
- return end;
- }
-
- /**
- * Copies the indentation of the previous line.
- *
- * @param d the document to work on
- * @param c the command to deal with
- */
- private void autoIndentAfterNewLine(IDocument d, DocumentCommand c) {
-
- if (c.offset == -1 || d.getLength() == 0)
- return;
-
- try {
- // find start of line
- int p= (c.offset == d.getLength() ? c.offset - 1 : c.offset);
- IRegion info= d.getLineInformationOfOffset(p);
- int start= info.getOffset();
-
- // find white spaces
- int end= findEndOfWhiteSpace(d, start, c.offset);
-
- StringBuffer buf= new StringBuffer(c.text);
- if (end > start) {
- // append to input
- buf.append(d.get(start, end - start));
- }
-
- c.text= buf.toString();
-
- } catch (BadLocationException excp) {
- // stop work
- }
- }
-
- /*
- * @see IAutoIndentStrategy#customizeDocumentCommand
- */
- public void customizeDocumentCommand(IDocument d, DocumentCommand c) {
- if (c.length == 0 && c.text != null && TextUtilities.endsWith(d.getLegalLineDelimiters(), c.text) != -1)
- autoIndentAfterNewLine(d, c);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
deleted file mode 100644
index bae74ebbf9c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultDocumentAdapter.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.TextChangeListener;
-import org.eclipse.swt.custom.TextChangedEvent;
-import org.eclipse.swt.custom.TextChangingEvent;
-
-
-/**
- * Adapts an <code>IDocument</code> to the <code>StyledTextContent</code> interface.
- */
-class DefaultDocumentAdapter implements IDocumentAdapter, IDocumentListener, IDocumentAdapterExtension {
-
- /** The adapted document. */
- private IDocument fDocument;
- /** The document clone for the non-forwarding case. */
- private IDocument fDocumentClone;
- /** The original content */
- private String fOriginalContent;
- /** The original line delimiters */
- private String[] fOriginalLineDelimiters;
- /** The registered text change listeners */
- private List fTextChangeListeners= new ArrayList(1);
- /**
- * The remembered document event
- * @since 2.0
- */
- private DocumentEvent fEvent;
- /** The line delimiter */
- private String fLineDelimiter= null;
- /**
- * Indicates whether this adapter is forwarding document changes
- * @since 2.0
- */
- private boolean fIsForwarding= true;
- /**
- * Length of document at receipt of <code>documentAboutToBeChanged</code>
- * @since 2.1
- */
- private int fRememberedLengthOfDocument;
- /**
- * Length of first document line at receipt of <code>documentAboutToBeChanged</code>
- * @since 2.1
- */
- private int fRememberedLengthOfFirstLine;
- /**
- * The data of the event at receipt of <code>documentAboutToBeChanged</code>
- * @since 2.1
- */
- private DocumentEvent fOriginalEvent= new DocumentEvent();
-
-
- /**
- * Creates a new document adapter which is initially not connected to
- * any document.
- */
- public DefaultDocumentAdapter() {
- }
-
- /**
- * Sets the given document as the document to be adapted.
- *
- * @param document the document to be adapted or <code>null</code> if there is no document
- */
- public void setDocument(IDocument document) {
-
- if (fDocument != null)
- fDocument.removePrenotifiedDocumentListener(this);
-
- fDocument= document;
- fLineDelimiter= null;
-
- if (!fIsForwarding) {
- fDocumentClone= null;
- fOriginalContent= fDocument.get();
- fOriginalLineDelimiters= fDocument.getLegalLineDelimiters();
- }
-
- if (fDocument != null)
- fDocument.addPrenotifiedDocumentListener(this);
- }
-
- /*
- * @see StyledTextContent#addTextChangeListener(TextChangeListener)
- */
- public void addTextChangeListener(TextChangeListener listener) {
- Assert.isNotNull(listener);
- if (! fTextChangeListeners.contains(listener))
- fTextChangeListeners.add(listener);
- }
-
- /*
- * @see StyledTextContent#removeTextChangeListener(TextChangeListener)
- */
- public void removeTextChangeListener(TextChangeListener listener) {
- Assert.isNotNull(listener);
- fTextChangeListeners.remove(listener);
- }
-
- /**
- * Tries to repair the line information.
- *
- * @see IRepairableDocument#repairLineInformation()
- * @since 3.0
- */
- private void repairLineInformation(IDocument document) {
- if (document instanceof IRepairableDocument) {
- IRepairableDocument repairable= (IRepairableDocument) document;
- repairable.repairLineInformation();
- }
- }
-
- /**
- * Returns the line for the given line number.
- *
- * @param line the line number
- * @return the line
- * @throws BadLocationException if the line number is invalid for the adapted document
- * @since 3.0
- */
- private String doGetLine(IDocument document, int line) throws BadLocationException {
- IRegion r= document.getLineInformation(line);
- return document.get(r.getOffset(), r.getLength());
- }
-
- private IDocument getDocumentForRead() {
- if (!fIsForwarding) {
- if (fDocumentClone == null) {
- String content= fOriginalContent == null ? "" : fOriginalContent;
- String[] delims= fOriginalLineDelimiters == null ? DefaultLineTracker.DELIMITERS : fOriginalLineDelimiters;
- fDocumentClone= new DocumentClone(content, delims);
- }
- return fDocumentClone;
- }
-
- return fDocument;
- }
-
- /*
- * @see StyledTextContent#getLine(int)
- */
- public String getLine(int line) {
-
- IDocument document= getDocumentForRead();
- try {
- return doGetLine(document, line);
- } catch (BadLocationException x) {
- repairLineInformation(document);
- try {
- return doGetLine(document, line);
- } catch (BadLocationException x2) {
- }
- }
-
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return null;
- }
-
- /*
- * @see StyledTextContent#getLineAtOffset(int)
- */
- public int getLineAtOffset(int offset) {
- IDocument document= getDocumentForRead();
- try {
- return document.getLineOfOffset(offset);
- } catch (BadLocationException x) {
- repairLineInformation(document);
- try {
- return document.getLineOfOffset(offset);
- } catch (BadLocationException x2) {
- }
- }
-
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return -1;
- }
-
- /*
- * @see StyledTextContent#getLineCount()
- */
- public int getLineCount() {
- return getDocumentForRead().getNumberOfLines();
- }
-
- /*
- * @see StyledTextContent#getOffsetAtLine(int)
- */
- public int getOffsetAtLine(int line) {
- IDocument document= getDocumentForRead();
- try {
- return document.getLineOffset(line);
- } catch (BadLocationException x) {
- repairLineInformation(document);
- try {
- return document.getLineOffset(line);
- } catch (BadLocationException x2) {
- }
- }
-
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return -1;
- }
-
- /*
- * @see StyledTextContent#getTextRange(int, int)
- */
- public String getTextRange(int offset, int length) {
- try {
- return getDocumentForRead().get(offset, length);
- } catch (BadLocationException x) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- return null;
- }
- }
-
- /*
- * @see StyledTextContent#replaceTextRange(int, int, String)
- */
- public void replaceTextRange(int pos, int length, String text) {
- try {
- fDocument.replace(pos, length, text);
- } catch (BadLocationException x) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-
- /*
- * @see StyledTextContent#setText(String)
- */
- public void setText(String text) {
- fDocument.set(text);
- }
-
- /*
- * @see StyledTextContent#getCharCount()
- */
- public int getCharCount() {
- return getDocumentForRead().getLength();
- }
-
- /*
- * @see StyledTextContent#getLineDelimiter()
- */
- public String getLineDelimiter() {
- if (fLineDelimiter == null)
- fLineDelimiter= TextUtilities.getDefaultLineDelimiter(fDocument);
- return fLineDelimiter;
- }
-
- /*
- * @see IDocumentListener#documentChanged(DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- // check whether the given event is the one which was remembered
- if (fEvent == null || event != fEvent)
- return;
-
- if (isPatchedEvent(event) || (event.getOffset() == 0 && event.getLength() == fRememberedLengthOfDocument)) {
- fLineDelimiter= null;
- fireTextSet();
- } else {
- if (event.getOffset() < fRememberedLengthOfFirstLine)
- fLineDelimiter= null;
- fireTextChanged();
- }
- }
-
- /*
- * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
-
- fRememberedLengthOfDocument= fDocument.getLength();
- try {
- fRememberedLengthOfFirstLine= fDocument.getLineLength(0);
- } catch (BadLocationException e) {
- fRememberedLengthOfFirstLine= -1;
- }
-
- fEvent= event;
- rememberEventData(fEvent);
- fireTextChanging();
- }
-
- /**
- * Checks whether this event has been changed between <code>documentAboutToBeChanged</code> and
- * <code>documentChanged</code>.
- *
- * @param event the event to be checked
- * @return <code>true</code> if the event has been changed, <code>false</code> otherwise
- */
- private boolean isPatchedEvent(DocumentEvent event) {
- return fOriginalEvent.fOffset != event.fOffset || fOriginalEvent.fLength != event.fLength || fOriginalEvent.fText != event.fText;
- }
-
- /**
- * Makes a copy of the given event and remembers it.
- *
- * @param event the event to be copied
- */
- private void rememberEventData(DocumentEvent event) {
- fOriginalEvent.fOffset= event.fOffset;
- fOriginalEvent.fLength= event.fLength;
- fOriginalEvent.fText= event.fText;
- }
-
- /**
- * Sends a text changed event to all registered listeners.
- */
- private void fireTextChanged() {
-
- if (!fIsForwarding)
- return;
-
- TextChangedEvent event= new TextChangedEvent(this);
-
- if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) {
- Iterator e= new ArrayList(fTextChangeListeners).iterator();
- while (e.hasNext())
- ((TextChangeListener) e.next()).textChanged(event);
- }
- }
-
- /**
- * Sends a text set event to all registered listeners.
- */
- private void fireTextSet() {
-
- if (!fIsForwarding)
- return;
-
- TextChangedEvent event = new TextChangedEvent(this);
-
- if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) {
- Iterator e= new ArrayList(fTextChangeListeners).iterator();
- while (e.hasNext())
- ((TextChangeListener) e.next()).textSet(event);
- }
- }
-
- /**
- * Sends the text changing event to all registered listeners.
- */
- private void fireTextChanging() {
-
- if (!fIsForwarding)
- return;
-
- try {
- IDocument document= fEvent.getDocument();
- if (document == null)
- return;
-
- TextChangingEvent event= new TextChangingEvent(this);
- event.start= fEvent.fOffset;
- event.replaceCharCount= fEvent.fLength;
- event.replaceLineCount= document.getNumberOfLines(fEvent.fOffset, fEvent.fLength) - 1;
- event.newText= fEvent.fText;
- event.newCharCount= (fEvent.fText == null ? 0 : fEvent.fText.length());
- event.newLineCount= (fEvent.fText == null ? 0 : document.computeNumberOfLines(fEvent.fText));
-
- if (fTextChangeListeners != null && fTextChangeListeners.size() > 0) {
- Iterator e= new ArrayList(fTextChangeListeners).iterator();
- while (e.hasNext())
- ((TextChangeListener) e.next()).textChanging(event);
- }
-
- } catch (BadLocationException e) {
- }
- }
-
- /*
- * @see IDocumentAdapterExtension#resumeForwardingDocumentChanges()
- * @since 2.0
- */
- public void resumeForwardingDocumentChanges() {
- fIsForwarding= true;
- fDocumentClone= null;
- fOriginalContent= null;
- fOriginalLineDelimiters= null;
- fireTextSet();
- }
-
- /*
- * @see IDocumentAdapterExtension#stopForwardingDocumentChanges()
- * @since 2.0
- */
- public void stopForwardingDocumentChanges() {
- fDocumentClone= null;
- fOriginalContent= fDocument.get();
- fOriginalLineDelimiters= fDocument.getLegalLineDelimiters();
- fIsForwarding= false;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java
deleted file mode 100644
index 619eafb7518..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultInformationControl.java
+++ /dev/null
@@ -1,420 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Label;
-import org.eclipse.swt.widgets.Shell;
-
-
-/**
- * Text based implementation of <code>IInformationControl</code>.
- * Displays information in a styled text widget. Before displaying, the
- * information set to this information control is processed by an
- * <code>IInformationPresenter</code>.
- *
- * @since 2.0
- */
-public class DefaultInformationControl implements IInformationControl, IInformationControlExtension, IInformationControlExtension3, DisposeListener {
-
- /**
- * An information presenter determines the style presentation
- * of information displayed in the default information control.
- * The interface can be implemented by clients.
- */
- public static interface IInformationPresenter {
-
- /**
- * Updates the given presentation of the given information and
- * thereby may manipulate the information to be displayed. The manipulation
- * could be the extraction of textual encoded style information etc. Returns the
- * manipulated information.
- *
- * @param display the display of the information control
- * @param hoverInfo the information to be presented
- * @param presentation the presentation to be updated
- * @param maxWidth the maximal width in pixels
- * @param maxHeight the maximal height in pixels
- *
- * @return the manipulated information
- */
- String updatePresentation(Display display, String hoverInfo, TextPresentation presentation, int maxWidth, int maxHeight);
- }
-
- /** Border thickness in pixels. */
- private static final int BORDER= 1;
-
- /** The control's shell */
- private Shell fShell;
- /** The control's text widget */
- private StyledText fText;
- /** The information presenter */
- private IInformationPresenter fPresenter;
- /** A cached text presentation */
- private TextPresentation fPresentation= new TextPresentation();
- /** The control width constraint */
- private int fMaxWidth= -1;
- /** The control height constraint */
- private int fMaxHeight= -1;
- /**
- * The font of the optional status text label.
- *
- * @since 3.0
- */
- private Font fStatusTextFont;
-
- /**
- * Creates a default information control with the given shell as parent. The given
- * information presenter is used to process the information to be displayed. The given
- * styles are applied to the created styled text widget.
- *
- * @param parent the parent shell
- * @param shellStyle the additional styles for the shell
- * @param style the additional styles for the styled text widget
- * @param presenter the presenter to be used
- */
- public DefaultInformationControl(Shell parent, int shellStyle, int style, IInformationPresenter presenter) {
- this(parent, shellStyle, style, presenter, null);
- }
-
- /**
- * Creates a default information control with the given shell as parent. The given
- * information presenter is used to process the information to be displayed. The given
- * styles are applied to the created styled text widget.
- *
- * @param parent the parent shell
- * @param shellStyle the additional styles for the shell
- * @param style the additional styles for the styled text widget
- * @param presenter the presenter to be used
- * @param statusFieldText the text to be used in the optional status field
- * or <code>null</code> if the status field should be hidden
- * @since 3.0
- */
- public DefaultInformationControl(Shell parent, int shellStyle, int style, IInformationPresenter presenter, String statusFieldText) {
- GridLayout layout;
- GridData gd;
-
- fShell= new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle);
- Display display= fShell.getDisplay();
- fShell.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
-
- Composite composite= fShell;
- layout= new GridLayout(1, false);
- int border= ((shellStyle & SWT.NO_TRIM) == 0) ? 0 : BORDER;
- layout.marginHeight= border;
- layout.marginWidth= border;
- composite.setLayout(layout);
- gd= new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
-
- if (statusFieldText != null) {
- composite= new Composite(composite, SWT.NONE);
- layout= new GridLayout(1, false);
- layout.marginHeight= 0;
- layout.marginWidth= 0;
- composite.setLayout(layout);
- gd= new GridData(GridData.FILL_BOTH);
- composite.setLayoutData(gd);
- composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- }
-
- // Text field
- fText= new StyledText(composite, SWT.MULTI | SWT.READ_ONLY | style);
- gd= new GridData(GridData.BEGINNING | GridData.FILL_BOTH);
- fText.setLayoutData(gd);
- fText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
- fText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- fText.addKeyListener(new KeyListener() {
-
- public void keyPressed(KeyEvent e) {
- if (e.character == 0x1B) // ESC
- fShell.dispose();
- }
-
- public void keyReleased(KeyEvent e) {}
- });
-
- fPresenter= presenter;
-
- // Status field
- if (statusFieldText != null) {
-
- // Horizontal separator line
- Label separator= new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT);
- separator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
-
- // Status field label
- Label statusField= new Label(composite, SWT.RIGHT);
- statusField.setText(statusFieldText);
- Font font= statusField.getFont();
- FontData[] fontDatas= font.getFontData();
- for (int i= 0; i < fontDatas.length; i++)
- fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10);
- fStatusTextFont= new Font(statusField.getDisplay(), fontDatas);
- statusField.setFont(fStatusTextFont);
- gd= new GridData(GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING);
- statusField.setLayoutData(gd);
-
- statusField.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
-
- statusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
- }
-
- addDisposeListener(this);
- }
-
- /**
- * Creates a default information control with the given shell as parent. The given
- * information presenter is used to process the information to be displayed. The given
- * styles are applied to the created styled text widget.
- *
- * @param parent the parent shell
- * @param style the additional styles for the styled text widget
- * @param presenter the presenter to be used
- */
- public DefaultInformationControl(Shell parent,int style, IInformationPresenter presenter) {
- this(parent, SWT.NO_TRIM, style, presenter);
- }
-
- /**
- * Creates a default information control with the given shell as parent. The given
- * information presenter is used to process the information to be displayed. The given
- * styles are applied to the created styled text widget.
- *
- * @param parent the parent shell
- * @param style the additional styles for the styled text widget
- * @param presenter the presenter to be used
- * @param statusFieldText the text to be used in the optional status field
- * or <code>null</code> if the status field should be hidden
- * @since 3.0
- */
- public DefaultInformationControl(Shell parent,int style, IInformationPresenter presenter, String statusFieldText) {
- this(parent, SWT.NO_TRIM, style, presenter, statusFieldText);
- }
-
- /**
- * Creates a default information control with the given shell as parent.
- * No information presenter is used to process the information
- * to be displayed. No additional styles are applied to the styled text widget.
- *
- * @param parent the parent shell
- */
- public DefaultInformationControl(Shell parent) {
- this(parent, SWT.NONE, null);
- }
-
- /**
- * Creates a default information control with the given shell as parent. The given
- * information presenter is used to process the information to be displayed.
- * No additional styles are applied to the styled text widget.
- *
- * @param parent the parent shell
- * @param presenter the presenter to be used
- */
- public DefaultInformationControl(Shell parent, IInformationPresenter presenter) {
- this(parent, SWT.NONE, presenter);
- }
-
- /*
- * @see IInformationControl#setInformation(String)
- */
- public void setInformation(String content) {
- if (fPresenter == null) {
- fText.setText(content);
- } else {
- fPresentation.clear();
- content= fPresenter.updatePresentation(fShell.getDisplay(), content, fPresentation, fMaxWidth, fMaxHeight);
- if (content != null) {
- fText.setText(content);
- TextPresentation.applyTextPresentation(fPresentation, fText);
- } else {
- fText.setText(""); //$NON-NLS-1$
- }
- }
- }
-
- /*
- * @see IInformationControl#setVisible(boolean)
- */
- public void setVisible(boolean visible) {
- fShell.setVisible(visible);
- }
-
- /*
- * @see IInformationControl#dispose()
- */
- public void dispose() {
- if (fShell != null && !fShell.isDisposed())
- fShell.dispose();
- else
- widgetDisposed(null);
- }
-
- /*
- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
- * @since 3.0
- */
- public void widgetDisposed(DisposeEvent event) {
- if (fStatusTextFont != null && !fStatusTextFont.isDisposed())
- fStatusTextFont.dispose();
-
- fShell= null;
- fText= null;
- fStatusTextFont= null;
- }
-
- /*
- * @see IInformationControl#setSize(int, int)
- */
- public void setSize(int width, int height) {
- fShell.setSize(width, height);
- }
-
- /*
- * @see IInformationControl#setLocation(Point)
- */
- public void setLocation(Point location) {
- Rectangle trim= fShell.computeTrim(0, 0, 0, 0);
- Point textLocation= fText.getLocation();
- location.x += trim.x - textLocation.x;
- location.y += trim.y - textLocation.y;
- fShell.setLocation(location);
- }
-
- /*
- * @see IInformationControl#setSizeConstraints(int, int)
- */
- public void setSizeConstraints(int maxWidth, int maxHeight) {
- fMaxWidth= maxWidth;
- fMaxHeight= maxHeight;
- }
-
- /*
- * @see IInformationControl#computeSizeHint()
- */
- public Point computeSizeHint() {
- return fShell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControlExtension3#computeTrim()
- * @since 3.0
- */
- public Rectangle computeTrim() {
- return fShell.computeTrim(0, 0, 0, 0);
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControlExtension3#getBounds()
- * @since 3.0
- */
- public Rectangle getBounds() {
- return fShell.getBounds();
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControlExtension3#restoresLocation()
- * @since 3.0
- */
- public boolean restoresLocation() {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IInformationControlExtension3#restoresSize()
- * @since 3.0
- */
- public boolean restoresSize() {
- return false;
- }
-
- /*
- * @see IInformationControl#addDisposeListener(DisposeListener)
- */
- public void addDisposeListener(DisposeListener listener) {
- fShell.addDisposeListener(listener);
- }
-
- /*
- * @see IInformationControl#removeDisposeListener(DisposeListener)
- */
- public void removeDisposeListener(DisposeListener listener) {
- fShell.removeDisposeListener(listener);
- }
-
- /*
- * @see IInformationControl#setForegroundColor(Color)
- */
- public void setForegroundColor(Color foreground) {
- fText.setForeground(foreground);
- }
-
- /*
- * @see IInformationControl#setBackgroundColor(Color)
- */
- public void setBackgroundColor(Color background) {
- fText.setBackground(background);
- }
-
- /*
- * @see IInformationControl#isFocusControl()
- */
- public boolean isFocusControl() {
- return fText.isFocusControl();
- }
-
- /*
- * @see IInformationControl#setFocus()
- */
- public void setFocus() {
- fShell.forceFocus();
- fText.setFocus();
- }
-
- /*
- * @see IInformationControl#addFocusListener(FocusListener)
- */
- public void addFocusListener(FocusListener listener) {
- fText.addFocusListener(listener);
- }
-
- /*
- * @see IInformationControl#removeFocusListener(FocusListener)
- */
- public void removeFocusListener(FocusListener listener) {
- fText.removeFocusListener(listener);
- }
-
- /*
- * @see IInformationControlExtension#hasContents()
- */
- public boolean hasContents() {
- return fText.getCharCount() > 0;
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
deleted file mode 100644
index 59c0c6f4049..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultTextDoubleClickStrategy.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-import java.text.BreakIterator;
-import java.text.CharacterIterator;
-
-
-/**
- * Standard implementation of <code>ITextDoubleClickStrategy</code>.
- * Selects words using <code>java.text.BreakIterator</code> for the
- * default locale. This class is not intended to be subclassed.
- *
- * @see java.text.BreakIterator
- */
-public class DefaultTextDoubleClickStrategy implements ITextDoubleClickStrategy {
-
-
- /**
- * Implements a character iterator that works directly on
- * instances of <code>IDocument</code>. Used to collaborate with
- * the break iterator.
- *
- * @see IDocument
- * @since 2.0
- */
- static class DocumentCharacterIterator implements CharacterIterator {
-
- /** Document to iterate over. */
- private IDocument fDocument;
- /** Start offset of iteration. */
- private int fOffset= -1;
- /** Endoffset of iteration. */
- private int fEndOffset= -1;
- /** Current offset of iteration. */
- private int fIndex= -1;
-
- /** Creates a new document iterator. */
- public DocumentCharacterIterator() {
- }
-
- /**
- * Configures this document iterator with the document section to be iteratored.
- *
- * @param document the document to be iterated
- * @param iteratorRange the range in the document to be iterated
- */
- public void setDocument(IDocument document, IRegion iteratorRange) {
- fDocument= document;
- fOffset= iteratorRange.getOffset();
- fEndOffset= fOffset + iteratorRange.getLength();
- }
-
- /*
- * @see CharacterIterator#first()
- */
- public char first() {
- fIndex= fOffset;
- return current();
- }
-
- /*
- * @see CharacterIterator#last()
- */
- public char last() {
- fIndex= fOffset < fEndOffset ? fEndOffset -1 : fEndOffset;
- return current();
- }
-
- /*
- * @see CharacterIterator#current()
- */
- public char current() {
- if (fOffset <= fIndex && fIndex < fEndOffset) {
- try {
- return fDocument.getChar(fIndex);
- } catch (BadLocationException x) {
- }
- }
- return DONE;
- }
-
- /*
- * @see CharacterIterator#next()
- */
- public char next() {
- if (fIndex == fEndOffset -1)
- return DONE;
-
- if (fIndex < fEndOffset)
- ++ fIndex;
-
- return current();
- }
-
- /*
- * @see CharacterIterator#previous()
- */
- public char previous() {
- if (fIndex == fOffset)
- return DONE;
-
- if (fIndex > fOffset)
- -- fIndex;
-
- return current();
- }
-
- /*
- * @see CharacterIterator#setIndex(int)
- */
- public char setIndex(int index) {
- fIndex= index;
- return current();
- }
-
- /*
- * @see CharacterIterator#getBeginIndex()
- */
- public int getBeginIndex() {
- return fOffset;
- }
-
- /*
- * @see CharacterIterator#getEndIndex()
- */
- public int getEndIndex() {
- return fEndOffset;
- }
-
- /*
- * @see CharacterIterator#getIndex()
- */
- public int getIndex() {
- return fIndex;
- }
-
- /*
- * @see CharacterIterator#clone()
- */
- public Object clone() {
- DocumentCharacterIterator i= new DocumentCharacterIterator();
- i.fDocument= fDocument;
- i.fIndex= fIndex;
- i.fOffset= fOffset;
- i.fEndOffset= fEndOffset;
- return i;
- }
- }
-
-
- /**
- * The document character iterator used by this strategy.
- * @since 2.0
- */
- private DocumentCharacterIterator fDocIter= new DocumentCharacterIterator();
-
-
- /**
- * Creates a new default text double click strategy.
- */
- public DefaultTextDoubleClickStrategy() {
- super();
- }
-
- /*
- * @see ITextDoubleClickStrategy#doubleClicked
- */
- public void doubleClicked(ITextViewer text) {
-
- int position= text.getSelectedRange().x;
-
- if (position < 0)
- return;
-
- try {
-
- IDocument document= text.getDocument();
- IRegion line= document.getLineInformationOfOffset(position);
- if (position == line.getOffset() + line.getLength())
- return;
-
- fDocIter.setDocument(document, line);
-
- BreakIterator breakIter= BreakIterator.getWordInstance();
- breakIter.setText(fDocIter);
-
- int start= breakIter.preceding(position);
- if (start == BreakIterator.DONE)
- start= line.getOffset();
-
- int end= breakIter.following(position);
- if (end == BreakIterator.DONE)
- end= line.getOffset() + line.getLength();
-
- if (breakIter.isBoundary(position)) {
- if (end - position > position- start)
- start= position;
- else
- end= position;
- }
-
- if (start != end)
- text.setSelectedRange(start, end - start);
-
- } catch (BadLocationException x) {
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java
deleted file mode 100644
index 2a29fcfd70f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DefaultUndoManager.java
+++ /dev/null
@@ -1,835 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.List;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-
-
-/**
- * Standard implementation of <code>IUndoManager</code>. It registers with
- * the connected text viewer as text input listener and document listener and
- * logs all changes. It also monitors mouse and keyboard activities in order to
- * partition the stream of text changes into undoable edit commands.
- * <p>
- * This class is not intended to be subclassed.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @see org.eclipse.jface.text.ITextInputListener
- * @see org.eclipse.jface.text.IDocumentListener
- * @see MouseListener
- * @see KeyListener
- */
-public class DefaultUndoManager implements IUndoManager {
-
- /**
- * Represents an undoable edit command.
- */
- class TextCommand {
-
- /** The start index of the replaced text */
- protected int fStart= -1;
- /** The end index of the replaced text */
- protected int fEnd= -1;
- /** The newly inserted text */
- protected String fText;
- /** The replaced text */
- protected String fPreservedText;
-
- /**
- * Reinitializes this text command.
- */
- protected void reinitialize() {
- fStart= fEnd= -1;
- fText= fPreservedText= null;
- }
-
- /**
- * Sets the start and the end index of this command.
- *
- * @param start the start index
- * @param end the end index
- */
- protected void set(int start, int end) {
- fStart= start;
- fEnd= end;
- fText= null;
- fPreservedText= null;
- }
-
- /**
- * Undo the change described by this command.
- *
- * @since 2.0
- */
- protected void undoTextChange() {
- try {
- fTextViewer.getDocument().replace(fStart, fText.length(), fPreservedText);
- } catch (BadLocationException x) {
- }
- }
-
- /**
- * Undo the change described by this command. Also selects and
- * reveals the change.
- */
- protected void undo() {
- undoTextChange();
- selectAndReveal(fStart, fPreservedText == null ? 0 : fPreservedText.length());
- }
-
- /**
- * Re-applies the change described by this command.
- *
- * @since 2.0
- */
- protected void redoTextChange() {
- try {
- fTextViewer.getDocument().replace(fStart, fEnd - fStart, fText);
- } catch (BadLocationException x) {
- }
- }
-
- /**
- * Re-applies the change described by this command that previously been
- * rolled back. Also selects and reveals the change.
- */
- protected void redo() {
- redoTextChange();
- selectAndReveal(fStart, fText == null ? 0 : fText.length());
- }
-
- /**
- * Updates the command stack in response to committing
- * the current change into this command.
- */
- protected void updateCommandStack() {
-
- int length= fCommandStack.size();
- for (int i= fCommandCounter + 1; i < length; i++)
- fCommandStack.remove(fCommandCounter + 1);
-
- fCommandStack.add(this);
-
- while (fCommandStack.size() > fUndoLevel)
- fCommandStack.remove(0);
-
- fCommandCounter= fCommandStack.size() - 1;
- }
-
- /**
- * Creates a new uncommitted text command depending on whether
- * a compound change is currently being executed.
- *
- * @return a new, uncommitted text command or a compound text command
- */
- protected TextCommand createCurrent() {
- return fFoldingIntoCompoundChange ? new CompoundTextCommand() : new TextCommand();
- }
-
- /**
- * Commits the current change into this command.
- */
- protected void commit() {
-
- if (fStart < 0) {
- reinitialize();
- } else {
-
- fText= fTextBuffer.toString();
- fTextBuffer.setLength(0);
- fPreservedText= fPreservedTextBuffer.toString();
- fPreservedTextBuffer.setLength(0);
-
- updateCommandStack();
- }
-
- fCurrent= createCurrent();
- }
- }
-
- /**
- * Represents an undoable edit command consisting of several
- * individual edit commands.
- */
- class CompoundTextCommand extends TextCommand {
-
- /** The list of individual commands */
- private List fCommands= new ArrayList();
-
- /**
- * Adds a new individual command to this compound command.
- *
- * @param command the command to be added
- */
- protected void add(TextCommand command) {
- fCommands.add(command);
- }
-
- /*
- * @see org.eclipse.jface.text.DefaultUndoManager2.TextCommand#undo()
- */
- protected void undo() {
- ITextViewerExtension extension= null;
- if (fTextViewer instanceof ITextViewerExtension)
- extension= (ITextViewerExtension) fTextViewer;
-
- if (extension != null)
- extension.setRedraw(false);
-
- try {
-
- int size= fCommands.size();
- if (size > 0) {
-
- TextCommand c;
-
- for (int i= size -1; i > 0; --i) {
- c= (TextCommand) fCommands.get(i);
- c.undoTextChange();
- }
-
- c= (TextCommand) fCommands.get(0);
- c.undo();
- }
-
- } finally {
- if (extension != null)
- extension.setRedraw(true);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.DefaultUndoManager2.TextCommand#redo()
- */
- protected void redo() {
-
- ITextViewerExtension extension= null;
- if (fTextViewer instanceof ITextViewerExtension)
- extension= (ITextViewerExtension) fTextViewer;
-
- if (extension != null)
- extension.setRedraw(false);
-
- try {
-
- int size= fCommands.size();
- if (size > 0) {
-
- TextCommand c;
-
- for (int i= 0; i < size -1; ++i) {
- c= (TextCommand) fCommands.get(i);
- c.redoTextChange();
- }
-
- c= (TextCommand) fCommands.get(size -1);
- c.redo();
- }
-
- } finally {
- if (extension != null)
- extension.setRedraw(true);
- }
- }
-
- /*
- * @see TextCommand#updateCommandStack
- */
- protected void updateCommandStack() {
- TextCommand c= new TextCommand();
- c.fStart= fStart;
- c.fEnd= fEnd;
- c.fText= fText;
- c.fPreservedText= fPreservedText;
-
- add(c);
-
- if (!fFoldingIntoCompoundChange)
- super.updateCommandStack();
- }
-
- /*
- * @see TextCommand#createCurrent
- */
- protected TextCommand createCurrent() {
-
- if (!fFoldingIntoCompoundChange)
- return new TextCommand();
-
- reinitialize();
- return this;
- }
-
- /*
- * @see org.eclipse.jface.text.DefaultUndoManager.TextCommand#commit()
- */
- protected void commit() {
- if (fStart < 0) {
- if (fCommands.size() > 0 && !fFoldingIntoCompoundChange) {
- super.updateCommandStack();
- fCurrent= createCurrent();
- return;
- }
- }
- super.commit();
- }
- }
-
- /**
- * Represents pretended <code>UndoManager</code> state.
- */
- class PretendedUndoManagerState {
- /** The counter in the undo stack */
- protected int cmdCounter= -1;
- /** The size of the undo stack */
- protected int stackSize= -1;
- }
-
- /**
- * Internal listener to mouse and key events.
- */
- class KeyAndMouseListener implements MouseListener, KeyListener {
-
- /*
- * @see MouseListener#mouseDoubleClick
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- /*
- * If the right mouse button is pressed, the current editing command is closed
- * @see MouseListener#mouseDown
- */
- public void mouseDown(MouseEvent e) {
- if (e.button == 1)
- commit();
- }
-
- /*
- * @see MouseListener#mouseUp
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /*
- * @see KeyListener#keyPressed
- */
- public void keyReleased(KeyEvent e) {
- }
-
- /*
- * On cursor keys, the current editing command is closed
- * @see KeyListener#keyPressed
- */
- public void keyPressed(KeyEvent e) {
- switch (e.keyCode) {
- case SWT.ARROW_UP:
- case SWT.ARROW_DOWN:
- case SWT.ARROW_LEFT:
- case SWT.ARROW_RIGHT:
- commit();
- break;
- }
- }
- }
-
- /**
- * Internal listener to document changes.
- */
- class DocumentListener implements IDocumentListener {
-
- private String fReplacedText;
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent event) {
- try {
- fReplacedText= event.getDocument().get(event.getOffset(), event.getLength());
- } catch (BadLocationException x) {
- fReplacedText= null;
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent)
- */
- public void documentChanged(DocumentEvent event) {
- processChange(event.getOffset(), event.getOffset() + event.getLength(), event.getText(), fReplacedText);
- }
- }
-
- /**
- * Internal text input listener.
- */
- class TextInputListener implements ITextInputListener {
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- if (oldInput != null && fDocumentListener != null) {
- oldInput.removeDocumentListener(fDocumentListener);
- commit();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- if (newInput != null) {
- if (fDocumentListener == null)
- fDocumentListener= new DocumentListener();
- newInput.addDocumentListener(fDocumentListener);
- }
- }
-
- }
-
-
- /** Text buffer to collect text which is inserted into the viewer */
- private StringBuffer fTextBuffer= new StringBuffer();
- /** Text buffer to collect viewer content which has been replaced */
- private StringBuffer fPreservedTextBuffer= new StringBuffer();
- /** Pretended undo manager state */
- private PretendedUndoManagerState fPretendedState= new PretendedUndoManagerState();
- /** The internal key and mouse event listener */
- private KeyAndMouseListener fKeyAndMouseListener;
- /** The internal document listener */
- private DocumentListener fDocumentListener;
- /** The internal text input listener */
- private TextInputListener fTextInputListener;
-
-
- /** Indicates inserting state */
- private boolean fInserting= false;
- /** Indicates overwriting state */
- private boolean fOverwriting= false;
- /** Indicates whether the current change belongs to a compound change */
- private boolean fFoldingIntoCompoundChange= false;
-
- /** The text viewer the undo manager is connected to */
- private ITextViewer fTextViewer;
-
- /** Supported undo level */
- private int fUndoLevel;
- /** The list of undoable edit commands */
- private List fCommandStack;
- /** The currently constructed edit command */
- private TextCommand fCurrent;
- /** The last delete edit command */
- private TextCommand fPreviousDelete;
- /** Command counter into the edit command stack */
- private int fCommandCounter= -1;
-
-
- /**
- * Creates a new undo manager who remembers the specified number of edit commands.
- *
- * @param undoLevel the length of this manager's history
- */
- public DefaultUndoManager(int undoLevel) {
- setMaximalUndoLevel(undoLevel);
- }
-
- /*
- * @see IUndoManager#beginCompoundChange
- */
- public void beginCompoundChange() {
- fFoldingIntoCompoundChange= true;
- commit();
- }
-
- /*
- * @see IUndoManager#endCompoundChange
- */
- public void endCompoundChange() {
- fFoldingIntoCompoundChange= false;
- commit();
- }
-
- /**
- * Registers all necessary listeners with the text viewer.
- */
- private void addListeners() {
- StyledText text= fTextViewer.getTextWidget();
- if (text != null) {
- fKeyAndMouseListener= new KeyAndMouseListener();
- text.addMouseListener(fKeyAndMouseListener);
- text.addKeyListener(fKeyAndMouseListener);
- fTextInputListener= new TextInputListener();
- fTextViewer.addTextInputListener(fTextInputListener);
- listenToTextChanges(true);
- }
- }
-
- /**
- * Unregister all previously installed listeners from the text viewer.
- */
- private void removeListeners() {
- StyledText text= fTextViewer.getTextWidget();
- if (text != null) {
- if (fKeyAndMouseListener != null) {
- text.removeMouseListener(fKeyAndMouseListener);
- text.removeKeyListener(fKeyAndMouseListener);
- fKeyAndMouseListener= null;
- }
- if (fTextInputListener != null) {
- fTextViewer.removeTextInputListener(fTextInputListener);
- fTextInputListener= null;
- }
- listenToTextChanges(false);
- }
- }
-
- /**
- * Switches the state of whether there is a text listener or not.
- *
- * @param listen the state which should be established
- */
- private void listenToTextChanges(boolean listen) {
- if (listen) {
- if (fDocumentListener == null && fTextViewer.getDocument() != null) {
- fDocumentListener= new DocumentListener();
- fTextViewer.getDocument().addDocumentListener(fDocumentListener);
- }
- } else if (!listen) {
- if (fDocumentListener != null && fTextViewer.getDocument() != null) {
- fTextViewer.getDocument().removeDocumentListener(fDocumentListener);
- fDocumentListener= null;
- }
- }
- }
-
- /**
- * Closes the current editing command and opens a new one.
- */
- private void commit() {
-
- fInserting= false;
- fOverwriting= false;
- fPreviousDelete.reinitialize();
-
- fCurrent.commit();
- }
-
- /**
- * Re-applies the previously undone editing command.
- */
- private void internalRedo() {
- ++fCommandCounter;
- TextCommand cmd= (TextCommand) fCommandStack.get(fCommandCounter);
-
- listenToTextChanges(false);
- cmd.redo();
- listenToTextChanges(true);
-
- fCurrent= new TextCommand();
- }
-
- /**
- * Does undo the last editing command.
- */
- private void internalUndo() {
- TextCommand cmd= (TextCommand) fCommandStack.get(fCommandCounter);
- -- fCommandCounter;
-
- listenToTextChanges(false);
- cmd.undo();
- listenToTextChanges(true);
-
- fCurrent= new TextCommand();
- }
-
- /**
- * Checks whether the given text starts with a line delimiter and
- * subsequently contains a white space only.
- *
- * @param text the text to check
- */
- private boolean isWhitespaceText(String text) {
-
- if (text == null || text.length() == 0)
- return false;
-
- String[] delimiters= fTextViewer.getDocument().getLegalLineDelimiters();
- int index= TextUtilities.startsWith(delimiters, text);
- if (index > -1) {
- char c;
- int length= text.length();
- for (int i= delimiters[index].length(); i < length; i++) {
- c= text.charAt(i);
- if (c != ' ' && c != '\t')
- return false;
- }
- return true;
- }
-
- return false;
- }
-
- /**
- * Returns the state the would result if the current editing command would be closed.
- *
- * @return the pretended state after closing the current editing command
- */
- private PretendedUndoManagerState pretendCommit() {
- if (fCurrent.fStart < 0) {
- fPretendedState.stackSize= fCommandStack.size();
- fPretendedState.cmdCounter= fCommandCounter;
- } else {
- int sz= Math.max(fCommandCounter, 0) + 1;
- if (sz > fUndoLevel)
- sz -= fUndoLevel;
- fPretendedState.stackSize= sz;
- fPretendedState.cmdCounter= sz - 1;
- }
- return fPretendedState;
- }
-
- private void processChange(int modelStart, int modelEnd, String insertedText, String replacedText) {
-
- if (insertedText == null)
- insertedText= ""; //$NON-NLS-1$
-
- if (replacedText == null)
- replacedText= ""; //$NON-NLS-1$
-
- int length= insertedText.length();
- int diff= modelEnd - modelStart;
-
- // normalize
- if (diff < 0) {
- int tmp= modelEnd;
- modelEnd= modelStart;
- modelStart= tmp;
- }
-
- if (modelStart == modelEnd) {
- // text will be inserted
- if ((length == 1) || isWhitespaceText(insertedText)) {
- // by typing or model manipulation
- if (!fInserting || (modelStart != fCurrent.fStart + fTextBuffer.length())) {
- commit();
- fInserting= true;
- }
- if (fCurrent.fStart < 0)
- fCurrent.fStart= fCurrent.fEnd= modelStart;
- if (length > 0)
- fTextBuffer.append(insertedText);
- } else if (length > 0) {
- // by pasting
- commit();
- fCurrent.fStart= fCurrent.fEnd= modelStart;
- fTextBuffer.append(insertedText);
- commit();
- }
- } else {
- if (length == 0) {
- // text will be deleted by backspace or DEL key or empty clipboard
- length= replacedText.length();
- String[] delimiters= fTextViewer.getDocument().getLegalLineDelimiters();
-
- if ((length == 1) || TextUtilities.equals(delimiters, replacedText) > -1) {
-
- // whereby selection is empty
-
- if (fPreviousDelete.fStart == modelStart && fPreviousDelete.fEnd == modelEnd) {
- // repeated DEL
-
- // correct wrong settings of fCurrent
- if (fCurrent.fStart == modelEnd && fCurrent.fEnd == modelStart) {
- fCurrent.fStart= modelStart;
- fCurrent.fEnd= modelEnd;
- }
- // append to buffer && extend command range
- fPreservedTextBuffer.append(replacedText);
- ++fCurrent.fEnd;
-
- } else if (fPreviousDelete.fStart == modelEnd) {
- // repeated backspace
-
- // insert in buffer and extend command range
- fPreservedTextBuffer.insert(0, replacedText);
- fCurrent.fStart= modelStart;
-
- } else {
- // either DEL or backspace for the first time
-
- commit();
-
- // as we can not decide whether it was DEL or backspace we initialize for backspace
- fPreservedTextBuffer.append(replacedText);
- fCurrent.fStart= modelStart;
- fCurrent.fEnd= modelEnd;
- }
-
- fPreviousDelete.set(modelStart, modelEnd);
-
- } else if (length > 0) {
- // whereby selection is not empty
- commit();
- fCurrent.fStart= modelStart;
- fCurrent.fEnd= modelEnd;
- fPreservedTextBuffer.append(replacedText);
- }
- } else {
- // text will be replaced
-
- if (length == 1) {
- length= replacedText.length();
- String[] delimiters= fTextViewer.getDocument().getLegalLineDelimiters();
-
- if ((length == 1) || TextUtilities.equals(delimiters, replacedText) > -1) {
- // because of overwrite mode or model manipulation
- if (!fOverwriting || (modelStart != fCurrent.fStart + fTextBuffer.length())) {
- commit();
- fOverwriting= true;
- }
-
- if (fCurrent.fStart < 0)
- fCurrent.fStart= modelStart;
-
- fCurrent.fEnd= modelEnd;
- fTextBuffer.append(insertedText);
- fPreservedTextBuffer.append(replacedText);
- return;
- }
- }
- // because of typing or pasting whereby selection is not empty
- commit();
- fCurrent.fStart= modelStart;
- fCurrent.fEnd= modelEnd;
- fTextBuffer.append(insertedText);
- fPreservedTextBuffer.append(replacedText);
- }
- }
- }
-
- /*
- * @see IUndoManager#setMaximalUndoLevel
- */
- public void setMaximalUndoLevel(int undoLevel) {
- fUndoLevel= undoLevel;
- }
-
- /*
- * @see IUndoManager#connect
- */
- public void connect(ITextViewer textViewer) {
- if (fTextViewer == null) {
- fTextViewer= textViewer;
- fCommandStack= new ArrayList();
- fCurrent= new TextCommand();
- fPreviousDelete= new TextCommand();
- addListeners();
- }
- }
-
- /*
- * @see IUndoManager#disconnect
- */
- public void disconnect() {
- if (fTextViewer != null) {
-
- removeListeners();
-
- fCurrent= null;
- if (fCommandStack != null) {
- fCommandStack.clear();
- fCommandStack= null;
- }
- fTextBuffer= null;
- fPreservedTextBuffer= null;
- fTextViewer= null;
- }
- }
-
- /*
- * @see IUndoManager#reset
- */
- public void reset() {
- if (fCommandStack != null)
- fCommandStack.clear();
- fCommandCounter= -1;
- if (fCurrent != null)
- fCurrent.reinitialize();
- fFoldingIntoCompoundChange= false;
- fInserting= false;
- fOverwriting= false;
- fTextBuffer.setLength(0);
- fPreservedTextBuffer.setLength(0);
- }
-
- /*
- * @see IUndoManager#redoable
- */
- public boolean redoable() {
- if (fCommandStack != null) {
- PretendedUndoManagerState s= pretendCommit();
- return (0 <= s.cmdCounter + 1) && (s.cmdCounter + 1 < s.stackSize);
- }
- return false;
- }
-
- /*
- * @see IUndoManager#undoable
- */
- public boolean undoable() {
- if (fCommandStack != null) {
- PretendedUndoManagerState s= pretendCommit();
- return (0 <= s.cmdCounter) && (s.cmdCounter < s.stackSize);
- }
- return false;
- }
-
- /*
- * @see IUndoManager#redo
- */
- public void redo() {
- if (redoable()) {
- commit();
- internalRedo();
- }
- }
-
- /*
- * @see IUndoManager#undo
- */
- public void undo() {
- if (undoable()) {
- fFoldingIntoCompoundChange= false;
- commit();
- internalUndo();
- }
- }
-
- protected void selectAndReveal(int offset, int length) {
- if (fTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- extension.exposeModelRange(new Region(offset, length));
- } else if (!fTextViewer.overlapsWithVisibleRegion(offset, length))
- fTextViewer.resetVisibleRegion();
-
- fTextViewer.setSelectedRange(offset, length);
- fTextViewer.revealRange(offset, length);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java
deleted file mode 100644
index add26238f0c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentClone.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * An {@link org.eclipse.jface.text.IDocument} that is a read-only clone of another document.
- *
- * @since 3.0
- */
-class DocumentClone extends AbstractDocument {
-
- private static class StringTextStore implements ITextStore {
-
- private String fContent;
-
- public StringTextStore(String content) {
- Assert.isNotNull(content);
- fContent= content;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#get(int)
- */
- public char get(int offset) {
- return fContent.charAt(offset);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#get(int, int)
- */
- public String get(int offset, int length) {
- return fContent.substring(offset, offset + length);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#getLength()
- */
- public int getLength() {
- return fContent.length();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#replace(int, int, java.lang.String)
- */
- public void replace(int offset, int length, String text) {
- }
-
- /*
- * @see org.eclipse.jface.text.ITextStore#set(java.lang.String)
- */
- public void set(String text) {
- }
-
- }
-
- public DocumentClone(String content, String[] lineDelimiters) {
- super();
- setTextStore(new StringTextStore(content));
- ConfigurableLineTracker tracker= new ConfigurableLineTracker(lineDelimiters);
- setLineTracker(tracker);
- getTracker().set(content);
- completeInitialization();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
deleted file mode 100644
index 8b26cbd0bff..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/DocumentCommand.java
+++ /dev/null
@@ -1,468 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import java.util.ListIterator;
-import java.util.NoSuchElementException;
-
-import org.eclipse.swt.events.VerifyEvent;
-
-
-/**
- * Represents a text modification as a document replace command. The text modification is given
- * as a <code>VerifyEvent</code> and translated into a document replace command relative
- * to a given offset. A document command can also be used to initialize a given <code>VerifyEvent</code>.<p>
- * A document command can also represent a list of related changes.
- */
-public class DocumentCommand {
-
- /**
- * A command which is added to document commands.
- * @since 2.1
- */
- private static class Command implements Comparable {
- /** The offset of the range to be replaced */
- private final int fOffset;
- /** The length of the range to be replaced. */
- private final int fLength;
- /** The replacement text */
- private final String fText;
- /** The listern who owns this command */
- private final IDocumentListener fOwner;
-
- /**
- * Creates a new command with the given specification.
- *
- * @param offset the offset of the replace command
- * @param length the length of the replace command
- * @param text the text to replace with, may be <code>null</code>
- * @param owner the document command owner, may be <code>null</code>
- * @since 3.0
- */
- public Command(int offset, int length, String text, IDocumentListener owner) {
- if (offset < 0 || length < 0)
- throw new IllegalArgumentException();
- fOffset= offset;
- fLength= length;
- fText= text;
- fOwner= owner;
- }
-
- /**
- * Returns the length delta for this command.
- *
- * @return the length delta for this command
- */
- public int getDeltaLength() {
- return (fText == null ? 0 : fText.length()) - fLength;
- }
-
- /**
- * Executes the document command on the specified document.
- *
- * @param document the document on which to execute the command.
- * @throws BadLocationException in case this commands cannot be executed
- */
- public void execute(IDocument document) throws BadLocationException {
-
- if (fLength == 0 && fText == null)
- return;
-
- if (fOwner != null)
- document.removeDocumentListener(fOwner);
-
- document.replace(fOffset, fLength, fText);
-
- if (fOwner != null)
- document.addDocumentListener(fOwner);
- }
-
- /*
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compareTo(final Object object) {
- if (equals(object))
- return 0;
-
- final Command command= (Command) object;
-
- // diff middle points if not intersecting
- if (fOffset + fLength <= command.fOffset || command.fOffset + command.fLength <= fOffset) {
- int value= (2 * fOffset + fLength) - (2 * command.fOffset + command.fLength);
- if (value != 0)
- return value;
- }
- // the answer
- return 42;
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object object) {
- if (object == this)
- return true;
- if (! (object instanceof Command))
- return false;
- final Command command= (Command) object;
- return command.fOffset == fOffset && command.fLength == fLength;
- }
- }
-
- /**
- * An iterator, which iterates in reverse over a list.
- */
- private static class ReverseListIterator implements Iterator {
-
- /** The list iterator. */
- private final ListIterator fListIterator;
-
- /**
- * Creates a reverse list iterator.
- * @param listIterator the iterator that this reverse iterator is based upon
- */
- public ReverseListIterator(ListIterator listIterator) {
- if (listIterator == null)
- throw new IllegalArgumentException();
- fListIterator= listIterator;
- }
-
- /*
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return fListIterator.hasPrevious();
- }
-
- /*
- * @see java.util.Iterator#next()
- */
- public Object next() {
- return fListIterator.previous();
- }
-
- /*
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * A command iterator.
- */
- private static class CommandIterator implements Iterator {
-
- /** The command iterator. */
- private final Iterator fIterator;
-
- /** The original command. */
- private Command fCommand;
-
- /** A flag indicating the direction of iteration. */
- private boolean fForward;
-
- /**
- * Creates a command iterator.
- *
- * @param commands an ascending ordered list of commands
- * @param command the original command
- * @param forward the direction
- */
- public CommandIterator(final List commands, final Command command, final boolean forward) {
- if (commands == null || command == null)
- throw new IllegalArgumentException();
- fIterator= forward ? commands.iterator() : new ReverseListIterator(commands.listIterator(commands.size()));
- fCommand= command;
- fForward= forward;
- }
-
- /*
- * @see java.util.Iterator#hasNext()
- */
- public boolean hasNext() {
- return fCommand != null || fIterator.hasNext();
- }
-
- /*
- * @see java.util.Iterator#next()
- */
- public Object next() {
-
- if (! hasNext())
- throw new NoSuchElementException();
-
- if (fCommand == null)
- return fIterator.next();
-
- if (!fIterator.hasNext()) {
- final Command tempCommand= fCommand;
- fCommand= null;
- return tempCommand;
- }
-
- final Command command= (Command) fIterator.next();
- final int compareValue= command.compareTo(fCommand);
-
- if ((compareValue < 0) ^ ! fForward) {
- return command;
-
- } else if ((compareValue > 0) ^ ! fForward) {
- final Command tempCommand= fCommand;
- fCommand= command;
- return tempCommand;
-
- } else {
- throw new IllegalArgumentException();
- }
- }
-
- /*
- * @see java.util.Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- /** Must the command be updated */
- public boolean doit= false;
- /** The offset of the command. */
- public int offset;
- /** The length of the command */
- public int length;
- /** The text to be inserted */
- public String text;
- /**
- * The owner of the document command which will not be notified.
- * @since 2.1
- */
- public IDocumentListener owner;
- /**
- * The caret offset with respect to the document before the document command is executed.
- * @since 2.1
- */
- public int caretOffset;
- /**
- * Additional document commands.
- * @since 2.1
- */
- private final List fCommands= new ArrayList();
- /**
- * Indicates whether the caret should be shifted by this command.
- *
- * @since 3.0
- */
- public boolean shiftsCaret;
-
-
- /**
- * Creates a new document command.
- */
- protected DocumentCommand() {
- }
-
- /**
- * Translates a verify event into a document replace command using the given offset.
- *
- * @param event the event to be translated
- * @param modelRange the event range as model range
- */
- void setEvent(VerifyEvent event, IRegion modelRange) {
-
- doit= true;
- text= event.text;
-
- offset= modelRange.getOffset();
- length= modelRange.getLength();
-
- owner= null;
- caretOffset= -1;
- shiftsCaret= true;
- fCommands.clear();
- }
-
- /**
- * Fills the given verify event with the replace text and the doit
- * flag of this document command. Returns whether the document command
- * covers the same range as the verify event considering the given offset.
- *
- * @param event the event to be changed
- * @param modelRange to be considered for range comparison
- * @return <code>true</code> if this command and the event cover the same range
- */
- boolean fillEvent(VerifyEvent event, IRegion modelRange) {
- event.text= text;
- event.doit= (offset == modelRange.getOffset() && length == modelRange.getLength() && doit && caretOffset == -1);
- return event.doit;
- }
-
- /**
- * Adds an additional replace command. The added replace command must not overlap
- * with existing ones. If the document command owner is not <code>null</code>, it will not
- * get document change notifications for the particular command.
- *
- * @param offset the offset of the region to replace
- * @param length the length of the region to replace
- * @param text the text to replace with, may be <code>null</code>
- * @param owner the command owner, may be <code>null</code>
- * @throws BadLocationException if the added command intersects with an existing one
- * @since 2.1
- */
- public void addCommand(int offset, int length, String text, IDocumentListener owner) throws BadLocationException {
- final Command command= new Command(offset, length, text, owner);
-
- if (intersects(command))
- throw new BadLocationException();
-
- final int index= Collections.binarySearch(fCommands, command);
-
- // a command with exactly the same ranges exists already
- if (index >= 0)
- throw new BadLocationException();
-
- // binary search result is defined as (-(insertionIndex) - 1)
- final int insertionIndex= -(index + 1);
-
- // overlaps to the right?
- if (insertionIndex != fCommands.size() && intersects((Command) fCommands.get(insertionIndex), command))
- throw new BadLocationException();
-
- // overlaps to the left?
- if (insertionIndex != 0 && intersects((Command) fCommands.get(insertionIndex - 1), command))
- throw new BadLocationException();
-
- fCommands.add(insertionIndex, command);
- }
-
- /**
- * Returns an iterator over the commands in ascending position order.
- * The iterator includes the original document command.
- * Commands cannot be removed.
- *
- * @return returns the command iterator
- */
- public Iterator getCommandIterator() {
- Command command= new Command(offset, length, text, owner);
- return new CommandIterator(fCommands, command, true);
- }
-
- /**
- * Returns the number of commands including the original document command.
- *
- * @return returns the number of commands
- * @since 2.1
- */
- public int getCommandCount() {
- return 1 + fCommands.size();
- }
-
- /**
- * Returns whether the two given commands intersect.
- *
- * @param command0 the first command
- * @param command1 the second command
- * @return <code>true</code> if the commands intersect
- * @since 2.1
- */
- private boolean intersects(Command command0, Command command1) {
- // diff middle points if not intersecting
- if (command0.fOffset + command0.fLength <= command1.fOffset || command1.fOffset + command1.fLength <= command0.fOffset)
- return (2 * command0.fOffset + command0.fLength) - (2 * command1.fOffset + command1.fLength) == 0;
- else
- return true;
- }
-
- /**
- * Returns whether the given command intersects with this command.
- *
- * @param command the command
- * @return <code>true</code> if the command intersects with this command
- * @since 2.1
- */
- private boolean intersects(Command command) {
- // diff middle points if not intersecting
- if (offset + length <= command.fOffset || command.fOffset + command.fLength <= offset)
- return (2 * offset + length) - (2 * command.fOffset + command.fLength) == 0;
- else
- return true;
- }
-
- /**
- * Executes the document commands on a document.
- *
- * @param document the document on which to execute the commands
- * @since 2.1
- */
- void execute(IDocument document) throws BadLocationException {
-
- if (length == 0 && text == null && fCommands.size() == 0)
- return;
-
- DefaultPositionUpdater updater= new DefaultPositionUpdater(getCategory());
- Position caretPosition= null;
- try {
- if (updateCaret()) {
- document.addPositionCategory(getCategory());
- document.addPositionUpdater(updater);
- caretPosition= new Position(caretOffset);
- document.addPosition(getCategory(), caretPosition);
- }
-
- final Command originalCommand= new Command(offset, length, text, owner);
- for (final Iterator iterator= new CommandIterator(fCommands, originalCommand, false); iterator.hasNext(); )
- ((Command) iterator.next()).execute(document);
-
- } catch (BadLocationException e) {
- // ignore
- } catch (BadPositionCategoryException e) {
- // ignore
- } finally {
- if (updateCaret()) {
- document.removePositionUpdater(updater);
- try {
- document.removePositionCategory(getCategory());
- } catch (BadPositionCategoryException e) {
- Assert.isTrue(false);
- }
- caretOffset= caretPosition.getOffset();
- }
- }
- }
-
- /**
- * Returns <code>true</code> if the caret offset should be updated, <code>false</code> otherwise.
- *
- * @return <code>true</code> if the caret offset should be updated, <code>false</code> otherwise
- * @since 3.0
- */
- private boolean updateCaret() {
- return shiftsCaret && caretOffset != -1;
- }
-
- /**
- * Returns the position category for the caret offset position.
- *
- * @return the position category for the caret offset position
- * @since 3.0
- */
- private String getCategory() {
- return toString();
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoEditStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoEditStrategy.java
deleted file mode 100644
index 514a4acadf5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoEditStrategy.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * An auto edit strategy can adapt changes that will be applied to
- * a text viewer's document. The strategy is informed by the text viewer
- * about each upcoming change in form of a document command. By manipulating
- * this document command, the strategy can influence in which way the text
- * viewer's document is changed. Clients may implement this interface.
- *
- * @since 2.1
- */
-public interface IAutoEditStrategy {
-
- /**
- * Allows the strategy to manipulate the document command.
- *
- * @param document the document that will be changed
- * @param command the document command describing the change
- */
- void customizeDocumentCommand(IDocument document, DocumentCommand command);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java
deleted file mode 100644
index dbbebb26391..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IAutoIndentStrategy.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Exists for backward compatibility.
- *
- * @deprecated since 3.0, use <code>IAutoEditStrategy</code> directly
- */
-public interface IAutoIndentStrategy extends IAutoEditStrategy {
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java
deleted file mode 100644
index db856dbef7d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapter.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-import org.eclipse.swt.custom.StyledTextContent;
-
-
-/**
- * Adapts an <code>IDocument</code> to the <code>StyledTextContent</code> interface.
- * The document adapter is used by <code>TextViewer</code> to translate document changes
- * into styled text content changes and vice versa.
- * Clients may implement this interface and override <code>TextViewer.createDocumentAdapter</code>
- * if they want to intercept the communication between the viewer's text widget and
- * the viewer's document.
- *
- * @see IDocument
- * @see StyledTextContent
- */
-public interface IDocumentAdapter extends StyledTextContent {
-
- /**
- * Sets the adapters document.
- *
- * @param document the document to be adapted
- */
- void setDocument(IDocument document);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java
deleted file mode 100644
index cc45fbb5926..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IDocumentAdapterExtension.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * Extension interface for <code>IDocumentAdapter</code>. Introduces the concepts of
- * batching a series of document changes into one styled text content change. Batching start
- * when a client calls <code>stopForwardingDocumentChanges</code>. After that call this document
- * adapter does not send out any styled text content change until
- * <code>resumeForwardingDocumentChanges</code> is called. Then, it sends out one styled text
- * content change that covers all changes that have been applied to the document since calling
- * <code>stopForwardingDocumentChanges</code>.
- *
- * @since 2.0
- */
-public interface IDocumentAdapterExtension {
-
- /**
- * Stops forwarding document changes to the styled text.
- */
- void stopForwardingDocumentChanges();
-
- /**
- * Resumes forwarding document changes to the styled text.
- * Also forces the styled text to catch up with all the changes
- * that have been applied since <code>stopForwardingDocumentChanges</code>
- * has been called.
- */
- void resumeForwardingDocumentChanges();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java
deleted file mode 100644
index 46937088228..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IEventConsumer.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-import org.eclipse.swt.events.VerifyEvent;
-
-/**
- * Implementers can register with a text viewer and
- * receive <code>VerifyEvent</code>s before the text viewer
- * they are registered with. If the event consumer marks events
- * as processed by turning their <code>doit</code> field to
- * <code>false</code> the text viewer subsequently ignores them.
- * Clients may implement this interface.<p>
- *
- * <code>ITextViewerExtension2</code> allows clients to manage the
- * <code>VerifyListener</code>s of a <code>TextViewer</code>. This makes
- * <code>IEventConsumer</code> obsolete.
- *
- * @see ITextViewer
- * @see org.eclipse.swt.events.VerifyEvent
- */
-public interface IEventConsumer {
-
- /**
- * Processes the given event and marks it as done if it should
- * be ignored by subsequent receivers.
- *
- * @param event the verify event which will be investigated
- */
- public void processEvent(VerifyEvent event);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java
deleted file mode 100644
index 3fa28d03084..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTarget.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-import org.eclipse.swt.graphics.Point;
-
-
-/**
- * Defines the interface for finding and replacing strings.
- */
-public interface IFindReplaceTarget {
-
- /**
- * Returns whether a find operation can be performed.
- *
- * @return whether a find operation can be performed
- */
- boolean canPerformFind();
-
- /**
- * Searches for a string starting at the given widget offset and using the specified search
- * directives. If a string has been found it is selected and its start offset is
- * returned.
- *
- * @param widgetOffset the widget offset at which searching starts
- * @param findString the string which should be found
- * @param searchForward <code>true</code> searches forward, <code>false</code> backwards
- * @param caseSensitive <code>true</code> performs a case sensitive search, <code>false</code> an insensitive search
- * @param wholeWord if <code>true</code> only occurrences are reported in which the findString stands as a word by itself
- * @return the position of the specified string, or -1 if the string has not been found
- */
- int findAndSelect(int widgetOffset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord);
-
- /**
- * Returns the currently selected range of characters as a offset and length in widget coordinates.
- *
- * @return the currently selected character range in widget coordinates
- */
- Point getSelection();
-
- /**
- * Returns the currently selected characters as a string.
- *
- * @return the currently selected characters
- */
- String getSelectionText();
-
- /**
- * Returns whether this target can be modified.
- *
- * @return <code>true</code> if target can be modified
- */
- boolean isEditable();
-
- /**
- * Replaces the currently selected range of characters with the given text.
- * This target must be editable. Otherwise nothing happens.
- *
- * @param text the substitution text
- */
- void replaceSelection(String text);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java
deleted file mode 100644
index 4a2cf2a0581..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-
-
-/**
- * Extension interface for <code>IFindReplaceTarget</code>. Extends the find replace target with
- * the concept of searching in a limiting scope and introduces a replace-all mode.
- *
- * @since 2.0
- */
-public interface IFindReplaceTargetExtension {
-
- /**
- * Indicates that a session with the target begins.
- * All calls except <code>beginSession()</code> and <code>endSession()</code> to
- * <code>IFindReplaceTarget</code> and
- * <code>IFindReplaceTargetExtension</code> must be embedded within calls to
- * <code>beginSession()</code> and <code>endSession()</code>.
- *
- * @see #endSession()
- */
- void beginSession();
-
- /**
- * Indicates that a session with the target ends.
- *
- * @see #beginSession()
- */
- void endSession();
-
- /**
- * Returns the find scope of the target, <code>null</code> for global scope.
- *
- * @return returns the find scope of the target, may be <code>null</code>
- */
- IRegion getScope();
-
- /**
- * Sets the find scope of the target to operate on. <code>null</code>
- * indicates that the global scope should be used.
- *
- * @param scope the find scope of the target, may be <code>null</code>
- */
- void setScope(IRegion scope);
-
- /**
- * Returns the currently selected range of lines as a offset and length.
- *
- * @return the currently selected line range
- */
- Point getLineSelection();
-
- /**
- * Sets a selection.
- *
- * @param offset the offset of the selection
- * @param length the length of the selection
- */
- void setSelection(int offset, int length);
-
- /**
- * Sets the scope highlight color
- *
- * @param color the color of the scope highlight
- */
- void setScopeHighlightColor(Color color);
-
-
- /**
- * Sets the target's replace-all mode.
- *
- * @param replaceAll <code>true</code> if this target should switch into replace-all mode,
- * <code>false</code> if it should leave the replace-all state
- */
- void setReplaceAllMode(boolean replaceAll);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension3.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension3.java
deleted file mode 100644
index 76637a2eadf..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IFindReplaceTargetExtension3.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * Extension interface for <code>IFindReplaceTarget</code>. Extends the find replace target's
- * findAndSelect method to allow regular expression find/replace.
- *
- * @since 3.0
- */
-public interface IFindReplaceTargetExtension3 {
-
- /**
- * Searches for a string starting at the given offset and using the specified search
- * directives. If a string has been found it is selected and its start offset is
- * returned. If regExSearch is <code>true</code> the findString is
- * interpreted as a regular expression for searching.
- *
- * @param offset the offset at which searching starts
- * @param findString the string which should be found
- * @param searchForward <code>true</code> searches forward, <code>false</code> backwards
- * @param caseSensitive <code>true</code> performes a case sensitve search, <code>false</code> an insensitive search
- * @param wholeWord if <code>true</code> only occurences are reported in which the findString stands as a word by itself.
- * Must not be used in combination with <code>regExSearch</code>.
- * @param regExSearch if <code>true</code> findString represents a regular expression
- * Must not be used in combination with <code>wholeWord</code>.
- * @return the position of the specified string, or -1 if the string has not been found
- * @throws PatternSyntaxException if regExSearch is <code>true</code> and findString is an invalid regular expression
- */
- int findAndSelect(int offset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch);
-
- /**
- * Replaces the currently selected range of characters with the given text.
- * If regExReplace is <code>true</code> the text is interpreted as a regular
- * expression for searching.
- * This target must be editable. Otherwise nothing happens.
- *
- * @param text the substitution text
- * @param regExReplace if <code>true</code> text represents a regular expression
- * @throws IllegalStateException if a REPLACE or REPLACE_FIND operation is not preceded by a successful FIND operation
- * @throws PatternSyntaxException if regExReplace is <code>true</code> and text is an invalid regular expression
- */
- void replaceSelection(String text, boolean regExReplace);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java
deleted file mode 100644
index 9d1f1477937..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControl.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-
-
-/**
- * Interface of a control presenting information. The information is given
- * in textual form. It can be either the content itself or a description
- * of the content. This specification is left to the implementers of this interface.<p>
- * The information control may not grap focus when made visible using
- * <code>setVisible(true)</code>.
- *
- * @since 2.0
- */
-public interface IInformationControl {
-
- /**
- * Sets the information to be presented by this information control.
- *
- * @param information the information to be presented
- */
- void setInformation(String information);
-
- /**
- * Sets the information control's size constraints. A constraint value of
- * <code>-1</code> indicates no constraint. This method must be called before
- * <code>computeSizeHint</code> is called.
- * <p>
- * Note: An information control which implements {@link IInformationControlExtension3}
- * can ignore this method or use it as hint for its very first appearance.
- * </p>
- * @param maxWidth the maximal width of the control to present the information, or <code>-1</code> for not constraint
- * @param maxHeight the maximal height of the control to present the information, or <code>-1</code> for not constraint
- */
- void setSizeConstraints(int maxWidth, int maxHeight);
-
- /**
- * Computes and returns a proposal for the size of this information control depending
- * on the information to present. The method tries to honor known size constraints but might
- * return a size that exceeds them.
- *
- * @return the computed size hint
- */
- Point computeSizeHint();
-
- /**
- * Controls the visibility of this information control.
- *
- * @param visible <code>true</code> if the control should be visible
- */
- void setVisible(boolean visible);
-
- /**
- * Sets the size of this information control.
- *
- * @param width the width of the control
- * @param height the height of the control
- */
- void setSize(int width, int height);
-
- /**
- * Sets the location of this information control.
- *
- * @param location the location
- */
- void setLocation(Point location);
-
- /**
- * Disposes this information control.
- */
- void dispose();
-
- /**
- * Adds the given listener to the list of dispose listeners.
- * If the listener is already registered it is not registered again.
- *
- * @param listener the listener to be added
- */
- void addDisposeListener(DisposeListener listener);
-
- /**
- * Removes the given listeners from the list of dispose listeners.
- * If the listener is not registered this call has no effect.
- *
- * @param listener the listener to be removed
- */
- void removeDisposeListener(DisposeListener listener);
-
- /**
- * Sets the foreground color of this information control.
- *
- * @param foreground the foreground color of this information control
- */
- void setForegroundColor(Color foreground);
-
- /**
- * Sets the background color of this information control.
- *
- * @param background the background color of this information control
- */
- void setBackgroundColor(Color background);
-
- /**
- * Returns whether this information control has the focus.
- *
- * @return <code>true</code> when the information control has the focus otherwise <code>false</code>
- */
- boolean isFocusControl();
-
- /**
- * Sets the keyboard focus to this information control.
- */
- void setFocus();
-
- /**
- * Adds the given listener to the list of focus listeners.
- * If the listener is already registered it is not registered again.
- *
- * @param listener the listener to be added
- */
- void addFocusListener(FocusListener listener);
-
- /**
- * Removes the given listeners from the list of focus listeners.
- * If the listener is not registered this call has no affect.
- *
- * @param listener the listener to be removed
- */
- void removeFocusListener(FocusListener listener);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java
deleted file mode 100644
index 35c882df0b8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreator.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.widgets.Shell;
-
-
-/**
- * Interface of a factory of information controls.
- *
- * @since 2.0
- */
-public interface IInformationControlCreator {
-
- /**
- * Creates a new information control with the given shell as the control's parent.
- *
- * @param parent the parent shell
- * @return the created information control
- */
- IInformationControl createInformationControl(Shell parent);
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreatorExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreatorExtension.java
deleted file mode 100644
index f9cbe605f7a..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlCreatorExtension.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * Extension to <code>IInformationControlCreator</code> which
- * tests if an existing information control can be reused.
- *
- * @see org.eclipse.jface.text.IInformationControlCreator
- * @see org.eclipse.jface.text.IInformationControl
- * @since 3.0
- */
-public interface IInformationControlCreatorExtension {
-
- /**
- * Tests if an existing information control can be reused.
- *
- * @param control the information control to test
- * @return <code>true</code> if the control can be reused
- */
- boolean canReuse(IInformationControl control);
-
- /**
- * Tests whether this information control creator can replace the given
- * information control creator. This is the case if the two creators create
- * the same kind of information controls.
- *
- * @param creator the creator to be checked
- * @return <code>true</code> if the given creator can be replaced,
- * <code>false</code> otherwise
- */
- boolean canReplace(IInformationControlCreator creator);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java
deleted file mode 100644
index 1315b31b971..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * Extension interface for <code>IInformationControl</code>. As it is the responsibility of
- * the implementer of <code>IInformationControl</code> to specify whether the information
- * set is the information itself or a description of the information, only the information control
- * can decide whether there is something that must be displayed.
- *
- * @since 2.0
- */
-public interface IInformationControlExtension {
-
- /**
- * Returns whether this information control has contents to be displayed.
- * @return <code>true</code> if there is contents to be displayed.
- */
- boolean hasContents();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension2.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension2.java
deleted file mode 100644
index 4e7829a91dc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension2.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-/**
- * Extension interface for <code>IInformationControl</code>. Replaces the concept of
- * textual information to be displayed with the more general concept of an input of the
- * information control. Text to be displayed set with <code>setInformation(String)</code>
- * is ignored.
- *
- * @see org.eclipse.jface.text.IInformationControl
- * @since 2.1
- */
-public interface IInformationControlExtension2 {
-
- /**
- * Sets the input to be presented in this information control.
- *
- * @param input the object to be used as input for this control
- */
- void setInput(Object input);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension3.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension3.java
deleted file mode 100644
index f9335f43b35..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IInformationControlExtension3.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-import org.eclipse.swt.graphics.Rectangle;
-
-
-/**
- * Extension interface for <code>IInformationControl</code>. Adds API which
- * allows to get this information control's bounds i.e. location and size.
- * <p>
- * Note: An information control which implements this interface can ignore
- * calls to {@link org.eclipse.jface.text.IInformationControl#setSizeConstraints(int, int)}
- * or use it as hint for its very first appearance.
- * </p>
- *
- * @see org.eclipse.jface.text.IInformationControl
- * @since 3.0
- */
-public interface IInformationControlExtension3 {
-
- /**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- * <p>
- * Note: If the receiver is already disposed then this methods must
- * return the last valid location and size.
- * </p>
- *
- * @return the receiver's bounding rectangle
- */
- Rectangle getBounds();
-
- /**
- * Computes the trim for this control.
- * x and y denote the upper left corner of the trimming relative
- * to this control's location i.e. this will most likely be
- * negative values. Width and height represent the border sizes.
- *
- * @return the receivers trim
- */
- Rectangle computeTrim();
-
- /**
- * Tells whether this control allows to restore the previously
- * used size.
- * <p>
- * Note: This is not a static property - it can change during the
- * lifetime of this control.</p>
- *
- * @return <code>true</code> if restoring size is supported
- */
- boolean restoresSize();
-
- /**
- * Tells whether this control allows to restore the previously
- * used location.
- * <p>
- * Note: This is not a static property - it can change during the
- * lifetime of this control.</p>
- *
- * @return <code>true</code> if restoring location is supported
- */
- boolean restoresLocation();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java
deleted file mode 100644
index c58a57953ae..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkRegionTarget.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * A mark region target to support marked regions as found in emacs.
- *
- * @since 2.0
- */
-public interface IMarkRegionTarget {
-
- /**
- * Sets or clears a mark at the current cursor position.
- *
- * @param set sets the mark if <code>true</code>, clears otherwise.
- */
- void setMarkAtCursor(boolean set);
-
- /**
- * Swaps the mark and cursor position if the mark is in the visible region.
- */
- void swapMarkAndCursor();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java
deleted file mode 100644
index 1391589c85d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IMarkSelection.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.jface.viewers.ISelection;
-
-
-/**
- * A mark selection. Can be returned by text viewers implementing the
- * <code>IMarkRegionTarget</code> interface.
- *
- * @since 2.0
- */
-public interface IMarkSelection extends ISelection {
-
- /**
- * Returns the marked document.
- *
- * @return the marked document
- */
- IDocument getDocument();
-
- /**
- * Returns the mark position. The offset may be <code>-1</code> if there's no marked region.
- *
- * @return the mark position or <code>-1</code> if there is no marked region
- */
- int getOffset();
-
- /**
- * Returns the length of the mark selection. The length may be negative, if the caret
- * is before the mark position. The length has no meaning if <code>getOffset()</code>
- * returns <code>-1</code>.
- *
- * @return the length of the mark selection. Result is undefined for <code>getOffset == -1</code>
- */
- int getLength();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IPaintPositionManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IPaintPositionManager.java
deleted file mode 100644
index fd5f315fc6b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IPaintPositionManager.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.jface.text.Position;
-
-/**
- * Manager that manages and updates positions used by <code>IPainter</code>s.
- *
- * @see org.eclipse.jface.text.IPainter
- * @since 2.1
- */
-public interface IPaintPositionManager {
-
- /**
- * Starts managing the given position until <code>unmanagePosition</code> is called.
- *
- * @param position the position to manage
- * @see #unmanagePosition(Position)
- */
- void managePosition(Position position);
-
- /**
- * Stops managing the given position. If the position is not managed
- * by this managed, this call has no effect.
- *
- * @param position the position that should no longer be managed
- */
- void unmanagePosition(Position position);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IPainter.java
deleted file mode 100644
index 20b3852b327..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IPainter.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * A painter is responsible for creating, managing, updating, and removing visual decorations of an <code>ITextViewer</code>. Examples are
- * the highlighting of the cursor line, the print marging, or the highlighting of matching peer characters such as pairs of brackets. Clients
- * may implement this interface. Painters should be registered with a <code>PaintManager</code>. The paint manager tracks several classes
- * of events issued by an <code>ITextViewer</code> and reacts by appropriately invoking the registered painters.<p>
- * Painters can be activated or deactivated. Usually, painters are initially deactivated and are activated by the first call to their <code>paint</code>
- * method. Painters can be deactivated by calling <code>deactivate</code>. Deactivated painter can be reactivated by calling <code>paint</code>
- * again.<p>
- * Painters usually have to manage state information. E.g., a painter painting a cursor line highlight must redraw the previous and the actual cursor
- * line in the advent of a change of the cursor position. This state information must usually be adapted to changes of the viewer's content. In order
- * to support this common scenario, the <code>PaintManager</code> gives a painter access to a <code>IPaintPositionUpdater</code>. The painter
- * can use this updater to manage its state information.<p>
- *
- * @see org.eclipse.jface.text.PaintManager
- * @since 2.1
- */
-public interface IPainter {
-
- /**
- * Constant describing the reason of a repaint request: selection changed.
- */
- int SELECTION= 0;
- /**
- * Constant describing the reason of a repaint request: text changed.
- */
- int TEXT_CHANGE= 1;
- /**
- * Constant describing the reason of a repaint request: key pressed.
- */
- int KEY_STROKE= 2;
- /**
- * Constant describing the reason of a repaint request: mouse button pressed.
- */
- int MOUSE_BUTTON= 4;
- /**
- * Constant describing the reason of a repaint request: paint manager internal change.
- */
- int INTERNAL= 8;
- /**
- * Constant describing the reason of a repaint request: paint manager or painter configuration changed.
- */
- int CONFIGURATION= 16;
-
-
- /**
- * Disposes this painter. Prior to disposing, a painter should be deactivated. A disposed
- * painter can not be reactivated.
- *
- * @see #deactivate(boolean)
- */
- void dispose();
-
- /**
- * Requests this painter to repaint because of the given reason. Based on the given reason
- * the painter can decide whether it will repaint or not. If it repaints and is not yet activated,
- * it wil activate itself.
- *
- * @param reason the repaint reason, value is one of the constants defined in this interface
- */
- void paint(int reason);
-
- /**
- * Deactivates this painter. If the painter has not been activated before, this call does not
- * have any effect. <code>redraw</code> indicates whether the painter should remove
- * any decoration it previously applied. A deactivated painter can be reactivated by calling
- * <code>paint</code>.
- *
- * @param redraw <code>true</code> if any previously applied decoration should be removed
- * @see #paint(int)
- */
- void deactivate(boolean redraw);
-
- /**
- * Sets the paint position manager that can be used by this painter or removes any previously
- * set paint position manager.
- *
- * @param manager the paint position manager or <code>null</code>
- */
- void setPositionManager(IPaintPositionManager manager);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java
deleted file mode 100644
index 1ad6bb12b01..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IRewriteTarget.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
- /**
- * A target publishing the required functions to modify a document that is displayed
- * in the ui, such as in a text viewer. It provides access to the document and control
- * over the redraw behavior and the batching of document changes into undo commands.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @see org.eclipse.jface.text.IDocument
- * @see org.eclipse.jface.text.IUndoManager
- * @since 2.0
- */
-public interface IRewriteTarget {
-
- /**
- * Returns the document of this target.
- *
- * @return the document of this target
- */
- IDocument getDocument();
-
- /**
- * Disables/enables redrawing of the ui while modifying the target's document.
- *
- * @param redraw <code>true</code> if the document's ui presentation should
- * be updated, <code>false</code> otherwise
- */
- void setRedraw(boolean redraw);
-
- /**
- * If an undo manager is connected to the document's ui presentation, this
- * method tells the undo manager to fold all subsequent changes into
- * one single undo command until <code>endCompoundChange</code> is called.
- */
- void beginCompoundChange();
-
- /**
- * If an undo manager is connected to the document's ui presentation, this method
- * tells the undo manager to stop the folding of changes into a single undo command.
- * After this call, all subsequent changes are considered to be individually undoable.
- */
- void endCompoundChange();
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ISelectionValidator.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ISelectionValidator.java
deleted file mode 100644
index f629f5f73c4..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ISelectionValidator.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-import org.eclipse.jface.viewers.ISelection;
-
-/**
- * A selection validator allows clients to test
- * whether the selection they received during selection
- * changed notification is still valid.
- * <p>
- * For example selection and document changes cause the
- * selection to be invalid.
- * </p>
- *
- * @since 3.0
- */
-public interface ISelectionValidator {
-
- /**
- * Tests whether the given post selection is still valid.
- *
- * @param selection
- * @return <code>true</code> if the selection is still valid
- */
- boolean isValid(ISelection selection);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java
deleted file mode 100644
index 3e9f1049113..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextDoubleClickStrategy.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * A text double click strategy defines the reaction of a text viewer
- * to mouse double click events. For that the strategy must be installed
- * on the text viewer.<p>
- * Clients may implements this interface or use the standard implementation
- * <code>DefaultTextDoubleClickStrategy</code>.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
-public interface ITextDoubleClickStrategy {
-
- /**
- * The mouse has been double clicked on the given text viewer.
- *
- * @param viewer the viewer into which has been double clicked
- */
- void doubleClicked(ITextViewer viewer);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java
deleted file mode 100644
index e3eb53eb398..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHover.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Provides a hover popup which appears on top of the text viewer with
- * relevant display information. If the text hover does not provide information
- * no hover popup is shown. Any implementer of this interface must be capable of
- * operating in a non-UI thread.<p>
- * Clients may implement this interface.
- *
- * @see org.eclipse.jface.text.ITextViewer
- */
-public interface ITextHover {
-
- /**
- * Returns the text which should be presented if a hover popup is shown
- * for the specified hover region. The hover region has the same semantics
- * as the region returned by <code>getHoverRegion</code>. If the returned
- * string is <code>null</code> or empty no hover popup will be shown.
- *
- * @param textViewer the viewer on which the hover popup should be shown
- * @param hoverRegion the text range in the viewer which is used to determine
- * the hover display information
- * @return the hover popup display information
- */
- String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion);
-
- /**
- * Returns the text region which should serve as the source of information
- * to compute the hover popup display information. The popup has been requested
- * for the given offset.<p>
- * For example, if hover information can be provided on a per method basis in a
- * source viewer, the offset should be used to find the enclosing method and the
- * source range of the method should be returned.
- *
- * @param textViewer the viewer on which the hover popup should be shown
- * @param offset the offset for which the hover request has been issued
- * @return the hover region used to compute the hover display information
- */
- IRegion getHoverRegion(ITextViewer textViewer, int offset);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHoverExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHoverExtension.java
deleted file mode 100644
index c25a4b2e9d8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextHoverExtension.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * Extension to <code>ITextHover</code> for providing its own information
- * control creator.
- *
- * @see org.eclipse.jface.text.IInformationControlCreator
- * @see org.eclipse.jface.text.ITextHover
- * @since 3.0
- */
-public interface ITextHoverExtension {
-
- /**
- * Returns the hover control creator of this text hover.
- *
- * @return the hover control creator
- */
- IInformationControlCreator getHoverControlCreator();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java
deleted file mode 100644
index 4b275161713..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextInputListener.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Text input listeners registered with an text viewer are informed
- * if the document serving as the text viewer's model is replaced.
- * Clients may implement this interface.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @see org.eclipse.jface.text.IDocument
- */
-public interface ITextInputListener {
-
- /**
- * Called before the input document is replaced.
- *
- * @param oldInput the text viewer's previous input document
- * @param newInput the text viewer's new input document
- */
- void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput);
-
- /**
- * Called after the input document has been replaced.
- *
- * @param oldInput the text viewer's previous input document
- * @param newInput the text viewer's new input document
- */
- void inputDocumentChanged(IDocument oldInput, IDocument newInput);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java
deleted file mode 100644
index 357e7ccc323..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextListener.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Text listeners registered with a text viewer are informed about
- * all text viewer modifications by means of text events. A text event
- * describes a change as a replace operation.<p>
- * The changes described in the event are the changes applied to the text viewer's
- * widget (i.e. its visual representation) and not those applied to the text viewer's
- * document. The text event can be asked to return the corresponding document
- * event. If a text listener receives a text event, it is guaranteed that
- * both the document and the viewer's visual representation are in sync.<p>
- * Clients may implement this interface.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @see org.eclipse.jface.text.TextEvent
- * @see org.eclipse.jface.text.DocumentEvent
- */
-public interface ITextListener {
-
- /**
- * The visual representation of a text viewer this listener is registered with
- * has been changed.
- *
- * @param event the description of the change
- */
- void textChanged(TextEvent event);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java
deleted file mode 100644
index 69c67b26c4a..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTarget.java
+++ /dev/null
@@ -1,101 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Defines the target for a text operation.
- */
-public interface ITextOperationTarget {
-
-
- /**
- * Text operation code for undoing the last edit command.
- */
- static final int UNDO= 1;
-
- /**
- * Text operation code for redoing the last undone edit command.
- */
- static final int REDO= 2;
-
- /**
- * Text operation code for moving the selected text to the clipboard.
- */
- static final int CUT= 3;
-
- /**
- * Text operation code for copying the selected text to the clipboard.
- */
- static final int COPY= 4;
-
- /**
- * Text operation code for inserting the clipboard content at the
- * current position.
- */
- static final int PASTE= 5;
-
- /**
- * Text operation code for deleting the selected text or if selection
- * is empty the character at the right of the current position.
- */
- static final int DELETE= 6;
-
- /**
- * Text operation code for selecting the complete text.
- */
- static final int SELECT_ALL= 7;
-
- /**
- * Text operation code for shifting the selected text block to the right.
- */
- static final int SHIFT_RIGHT= 8;
-
- /**
- * Text operation code for unshifting the selected text block to the left.
- */
- static final int SHIFT_LEFT= 9;
-
- /**
- * Text operation code for printing the complete text.
- */
- static final int PRINT= 10;
-
- /**
- * Text operation code for prefixing the selected text block.
- */
- static final int PREFIX= 11;
-
- /**
- * Text operation code for removing the prefix from the selected text block.
- */
- static final int STRIP_PREFIX= 12;
-
-
- /**
- * Returns whether the operation specified by the given operation code
- * can be performed.
- *
- * @param operation the operation code
- * @return <code>true</code> if the specified operation can be performed
- */
- boolean canDoOperation(int operation);
-
- /**
- * Performs the operation specified by the operation code on the target.
- * <code>doOperation</code> must only be called if <code>canDoOperation</code>
- * returns <code>true</code>.
- *
- * @param operation the operation code
- */
- void doOperation(int operation);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java
deleted file mode 100644
index 66804736c88..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextOperationTargetExtension.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * Extension interface to <code>ITextOperationTarget</code>. Allows a client to control
- * the enable state of operations provided by this target.
- *
- * @see org.eclipse.jface.text.ITextOperationTarget
- * @since 2.0
- */
-public interface ITextOperationTargetExtension {
-
- /**
- * Enables/disabled the given text operation.
- *
- * @param operation the operation to enable/disable
- * @param enable <code>true</code> to enable the operation otherwise <code>false</code>
- */
- void enableOperation(int operation, boolean enable);
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextPresentationListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextPresentationListener.java
deleted file mode 100644
index 92a76ff15d3..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextPresentationListener.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * Text presentation listeners registered with a text viewer are informed
- * when a text region is about to be drawn in order to get the text
- * presentation information.
- *
- * @since 3.0
- */
-public interface ITextPresentationListener {
-
- /**
- * This method is called when a region is about to be
- * drawn in order to get the text presentation information.
- * Even though the given text presentation may cover a wider
- * region than the given one clients should not modify text
- * presentation outside the given region since this might be
- * ignored.
- *
- * @param textPresentation the current text presentation
- */
- public void applyTextPresentation(TextPresentation textPresentation);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java
deleted file mode 100644
index 8820d06271d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextSelection.java
+++ /dev/null
@@ -1,84 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-import org.eclipse.jface.viewers.ISelection;
-
-
-/**
- * This interface represents a textual selection. A text selection is
- * a range of characters. Although a text selection is a snapshot taken
- * at a particular point in time, it must not copy the line information
- * and the selected text from the selection provider.<p>
- * If, for example, the selection provider is a source viewer, and a text
- * selection is created for the range [5, 10], the line formation for
- * the 5th character must not be determined and remembered at the point
- * of creation. It can rather be determined at the point, when
- * <code>getStartLine</code> is called. If the source viewer range [0, 15]
- * has been changed in the meantime between the creation of the text
- * selection object and the invocation of <code>getStartLine</code>, the returned
- * line number may differ from the line number of the 5th character at the
- * point of creation of the text selection object.<p> The contract of this
- * interface is that weak in order to allow for efficient implementations.<p>
- * Clients may implement this interface or use the default implementation provided
- * by <code>TextSelection</code>.
- *
- * @see org.eclipse.jface.text.TextSelection
- */
-public interface ITextSelection extends ISelection {
-
- /**
- * Returns the offset of the selected text.
- *
- * @return the offset of the selected text
- */
- int getOffset();
-
- /**
- * Returns the length of the selected text.
- *
- * @return the length of the selected text
- */
- int getLength();
-
- /**
- * Returns number of the line containing the offset of the selected text.
- * If the underlying text has been changed between the creation of this
- * selection object and the call of this method, the value returned might
- * differ from what it would have been at the point of creation.
- *
- * @return the start line of this selection or -1 if there is no valid line information
- */
- int getStartLine();
-
- /**
- * Returns the number of the line containing the last character of the selected text.
- * If the underlying text has been changed between the creation of this
- * selection object and the call of this method, the value returned might
- * differ from what it would have been at the point of creation.
- *
- * @return the end line of this selection or -1 if there is no valid line information
- */
- int getEndLine();
-
- /**
- * Returns the selected text.
- * If the underlying text has been changed between the creation of this
- * selection object and the call of this method, the value returned might
- * differ from what it would have been at the point of creation.
- *
- * @return the selected text or <code>null</code> if there is no valid text information
- */
- String getText();
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java
deleted file mode 100644
index b20dbda38f2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewer.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.viewers.ISelectionProvider;
-
-
-/**
- * A text viewer turns a text widget into a document-based text widget.
- * It supports the following kinds of listeners:
- * <ul>
- * <li> view port listeners to inform about changes of the viewer's view port
- * <li> text listeners to inform about changes of the document and the subsequent viewer change
- * <li> text input listeners to inform about changes of the viewer's input document.
- * </ul>
- * A text viewer supports a set of plug-ins which define its behavior:
- * <ul>
- * <li> undo manager
- * <li> double click behavior
- * <li> auto indentation
- * <li> text hover
- * </ul>
- * Installed plug-ins are not automatically activated. Plug-ins must be activated with the
- * <code>activatePlugins</code> call. Most plug-ins can be defined per content type.
- * Content types are derived from the partitioning of the text viewer's input document.<p>
- * A text viewer also provides the concept of event consumption. Events handled by the
- * viewer can be filtered and processed by a dynamic event consumer.<p>
- * A text viewer provides several text editing functions, some of them are configurable,
- * through a text operation target interface. It also supports a presentation mode
- * in which it only shows specified sections of its document. The viewer's presentation mode
- * does not affect any client of the viewer other than text listeners.<p>
- * Clients may implement this interface or use the standard implementation
- * <code>TextViewer</code>.
- *
- * @see IDocument
- * @see ITextInputListener
- * @see IViewportListener
- * @see ITextListener
- * @see IEventConsumer
- */
-public interface ITextViewer {
-
-
- /* ---------- widget --------- */
-
- /**
- * Returns this viewer's SWT control, <code>null</code> if the control is disposed.
- *
- * @return the SWT control
- */
- StyledText getTextWidget();
-
-
- /* --------- plug-ins --------- */
-
- /**
- * Sets this viewer's undo manager.
- *
- * @param undoManager the new undo manager. <code>null</code> is a valid argument.
- */
- void setUndoManager(IUndoManager undoManager);
-
- /**
- * Sets this viewer's text double click strategy for the given content type.
- *
- * @param strategy the new double click strategy. <code>null</code> is a valid argument.
- * @param contentType the type for which the strategy is registered
- */
- void setTextDoubleClickStrategy(ITextDoubleClickStrategy strategy, String contentType);
-
- /**
- * Sets this viewer's auto indent strategy for the given content type.
- *
- * @param strategy the new auto indent strategy. <code>null</code> is a valid argument.
- * @param contentType the type for which the strategy is registered
- */
- void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType);
-
- /**
- * Sets this viewer's text hover for the given content type.
- *
- * @param textViewerHover the new hover. <code>null</code> is a valid argument.
- * @param contentType the type for which the hover is registered
- */
- void setTextHover(ITextHover textViewerHover, String contentType);
-
- /**
- * Activates the installed plug-ins. If the plug-ins are already activated
- * this call has no effect.
- */
- void activatePlugins();
-
- /**
- * Resets the installed plug-ins. If plug-ins change their state or
- * behavior over the course of time, this method causes them to be set
- * back to their initial state and behavior. E.g., if an <code>IUndoManager</code>
- * has been installed on this text viewer, the manager's list of remembered
- * text editing operations is removed.
- */
- void resetPlugins();
-
-
-
- /* ---------- listeners ------------- */
-
- /**
- * Adds the given view port listener to this viewer. The listener
- * is informed about all changes to the visible area of this viewer.
- * If the listener is already registered with this viewer, this call
- * has no effect.
- *
- * @param listener the listener to be added
- */
- void addViewportListener(IViewportListener listener);
-
- /**
- * Removes the given listener from this viewer's set of view port listeners.
- * If the listener is not registered with this viewer, this call has
- * no effect.
- *
- * @param listener the listener to be removed
- */
- void removeViewportListener(IViewportListener listener);
-
- /**
- * Adds a text listener to this viewer. If the listener is already registered
- * with this viewer, this call has no effect.
- *
- * @param listener the listener to be added
- */
- void addTextListener(ITextListener listener);
-
- /**
- * Removes the given listener from this viewer's set of text listeners.
- * If the listener is not registered with this viewer, this call has
- * no effect.
- *
- * @param listener the listener to be removed
- */
- void removeTextListener(ITextListener listener);
-
- /**
- * Adds a text input listener to this viewer. If the listener is already registered
- * with this viewer, this call has no effect.
- *
- * @param listener the listener to be added
- */
- void addTextInputListener(ITextInputListener listener);
-
- /**
- * Removes the given listener from this viewer's set of text input listeners.
- * If the listener is not registered with this viewer, this call has
- * no effect.
- *
- * @param listener the listener to be removed
- */
- void removeTextInputListener(ITextInputListener listener);
-
-
-
- /* -------------- model manipulation ------------- */
-
- /**
- * Sets the given document as the text viewer's model and updates the
- * presentation accordingly. An appropriate <code>TextEvent</code> is
- * issued. This text event does not carry a related document event.
- *
- * @param document the viewer's new input document
- */
- void setDocument(IDocument document);
-
- /**
- * Returns the text viewer's input document.
- *
- * @return the viewer's input document
- */
- IDocument getDocument();
-
-
- /* -------------- event handling ----------------- */
-
- /**
- * Registers an event consumer with this viewer.
- *
- * @param consumer the viewer's event consumer. <code>null</code> is a valid argument.
- */
- void setEventConsumer(IEventConsumer consumer);
-
- /**
- * Sets the editable flag.
- *
- * @param editable the editable flag
- */
- void setEditable(boolean editable);
-
- /**
- * Returns whether the shown text can be manipulated.
- *
- * @return the viewer's editable flag
- */
- boolean isEditable();
-
-
- /* ----------- visible region support ------------- */
-
- /**
- * Sets the given document as this viewer's model and
- * exposes the specified region. An appropriate
- * <code>TextEvent</code> is issued. The text event does not carry a
- * related document event. This method is a convenience method for
- * <code>setDocument(document);setVisibleRegion(offset, length)</code>.
- *
- * @param document the new input document
- * @param modelRangeOffset the offset of the model range
- * @param modelRangeLength the length of the model range
- */
- void setDocument(IDocument document, int modelRangeOffset, int modelRangeLength);
-
- /**
- * Sets the region of this viewer's document which will be visible in the presentation.
- *
- * @param offset the offset of the visible region
- * @param length the length of the visible region
- */
- void setVisibleRegion(int offset, int length);
-
- /**
- * Resets the region of this viewer's document which is visible in the presentation.
- * Afterwards, the whole document is presented again.
- */
- void resetVisibleRegion();
-
- /**
- * Returns the current visible region of this viewer's document.
- * The result may differ from the argument passed to <code>setVisibleRegion</code>
- * if the document has been modified since then.
- *
- * @return this viewer's current visible region
- */
- IRegion getVisibleRegion();
-
- /**
- * Returns whether a given range overlaps with the visible region of this viewer's document.
- *
- * @param offset the offset
- * @param length the length
- * @return <code>true</code> if the specified range overlaps with the visible region
- */
- boolean overlapsWithVisibleRegion(int offset, int length);
-
-
-
- /* ------------- presentation manipulation ----------- */
-
- /**
- * Applies the color information encoded in the given text presentation.
- * <code>controlRedraw</code> tells this viewer whether it should take care of
- * redraw management or not. If, e.g., this call is one in a sequence of multiple
- * coloring calls, it is more appropriate to explicitly control redrawing at the
- * beginning and the end of the sequence.
- *
- * @param presentation the presentation to be applied to this viewer
- * @param controlRedraw indicates whether this viewer should manage redraws
- */
- void changeTextPresentation(TextPresentation presentation, boolean controlRedraw);
-
- /**
- * Marks the currently applied text presentation as invalid. It is the viewer's
- * responsibility to take any action it can to repair the text presentation.
- *
- * @since 2.0
- */
- void invalidateTextPresentation();
-
- /**
- * Applies the given color to this viewer's selection.
- *
- * @param color the color to be applied
- */
- void setTextColor(Color color);
-
- /**
- * Applies the given color to the specified section of this viewer.
- * <code>controlRedraw</code> tells this viewer whether it should take care of
- * redraw management or not.
- *
- * @param color the color to be applied
- * @param offset the offset of the range to be colored
- * @param length the length of the range to be colored
- * @param controlRedraw indicates whether this viewer should manage redraws
- */
- void setTextColor(Color color, int offset, int length, boolean controlRedraw);
-
-
- /* --------- target handling and configuration ------------ */
-
- /**
- * Returns the text operation target of this viewer.
- *
- * @return the text operation target of this viewer
- */
- ITextOperationTarget getTextOperationTarget();
-
- /**
- * Returns the find/replace operation target of this viewer.
- *
- * @return the find/replace operation target of this viewer
- */
- IFindReplaceTarget getFindReplaceTarget();
-
- /**
- * Sets the string that is used as prefix when lines of the given
- * content type are prefixed by the prefix text operation.
- * Sets the strings that are used as prefixes when lines of the given content type
- * are prefixed using the prefix text operation. The prefixes are considered equivalent.
- * Inserting a prefix always inserts the defaultPrefixes[0].
- * Removing a prefix removes all of the specified prefixes.
- *
- * @param defaultPrefixes the prefixes to be used
- * @param contentType the content type for which the prefixes are specified
- * @since 2.0
- */
- void setDefaultPrefixes(String[] defaultPrefixes, String contentType);
-
- /**
- * Sets the strings that are used as prefixes when lines of the given content type
- * are shifted using the shift text operation. The prefixes are considered equivalent.
- * Thus "\t" and " " can both be used as prefix characters.
- * Shift right always inserts the indentPrefixes[0].
- * Shift left removes all of the specified prefixes.
- *
- * @param indentPrefixes the prefixes to be used
- * @param contentType the content type for which the prefixes are specified
- */
- void setIndentPrefixes(String[] indentPrefixes, String contentType);
-
-
-
- /* --------- selection handling -------------- */
-
- /**
- * Sets the selection to the specified range.
- *
- * @param offset the offset of the selection range
- * @param length the length of the selection range
- */
- void setSelectedRange(int offset, int length);
-
- /**
- * Returns the range of the current selection in coordinates of this viewer's document.
- *
- * @return the current selection
- */
- Point getSelectedRange();
-
- /**
- * Returns a selection provider dedicated to this viewer. Subsequent
- * calls to this method return always the same selection provider.
- *
- * @return this viewer's selection provider
- */
- ISelectionProvider getSelectionProvider();
-
-
- /* ------------- appearance manipulation --------------- */
-
- /**
- * Ensures that the given range is visible.
- *
- * @param offset the offset of the range to be revealed
- * @param length the length of the range to be revealed
- */
- void revealRange(int offset, int length);
-
- /**
- * Scrolls the widget so the the given index is the line
- * with the smallest line number of all visible lines.
- *
- * @param index the line which should become the top most line
- */
- void setTopIndex(int index);
-
- /**
- * Returns the visible line with the smallest line number.
- *
- * @return the number of the top most visible line
- */
- int getTopIndex();
-
- /**
- * Returns the document offset of the upper left corner of this viewer's view port.
- *
- * @return the upper left corner offset
- */
- int getTopIndexStartOffset();
-
- /**
- * Returns the visible line with the highest line number.
- *
- * @return the number of the bottom most line
- */
- int getBottomIndex();
-
- /**
- * Returns the document offset of the lower right
- * corner of this viewer's view port. This is the visible character
- * with the highest character position. If the content of this viewer
- * is shorter, the position of the last character of the content is returned.
- *
- * @return the lower right corner offset
- */
- int getBottomIndexEndOffset();
-
- /**
- * Returns the vertical offset of the first visible line.
- *
- * @return the vertical offset of the first visible line
- */
- int getTopInset();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java
deleted file mode 100644
index c050e02ce2a..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.widgets.Control;
-
-
-/**
- * Extension interface for <code>ITextViewer</code>. Extends <code>ITextViewer</code> with
- * <ul>
- * <li> a replacement of the event consumer mechanism (methods dealing with <code>VerifyKeyListener</code>)
- * <li> access to the control of this viewer
- * <li> marked region support a la emacs
- * <li> control of the viewer's redraw behavior (@see #setRedraw)
- * <li> access to the viewer's rewrite target
- * </ul>
- *
- * @since 2.0
- */
-public interface ITextViewerExtension {
-
- /**
- * Inserts the verify key listener at the beginning of the viewer's
- * list of verify key listeners. If the listener is already registered
- * with the viewer this call moves the listener to the beginnng of
- * the list.
- *
- * @param listener the listener to be inserted
- */
- void prependVerifyKeyListener(VerifyKeyListener listener);
-
- /**
- * Appends a verify key listener to the viewer's list of verify
- * key listeners. If the listener is already registered with the viewer
- * this call moves the listener to the end of the list.
- *
- * @param listener the listener to be added
- */
- void appendVerifyKeyListener(VerifyKeyListener listener);
-
- /**
- * Removes the verify key listener from the viewer's list of verify key listeners.
- * If the listener is not registered with this viewer, this call has no effect.
- *
- * @param listener the listener to be removed
- */
- void removeVerifyKeyListener(VerifyKeyListener listener);
-
- /**
- * Returns the control of this viewer.
- *
- * @return the control of this viewer
- */
- Control getControl();
-
- /**
- * Sets or clears the mark. If offset is <code>-1</code>, the mark is cleared.
- * If a mark is set and the selection is empty, cut and copy actions performed on this
- * text viewer peform on the region limited by the positions of the mark and the cursor.
- *
- * @param offset the offset of the mark
- */
- void setMark(int offset);
-
- /**
- * Returns the mark position, <code>-1</code> if mark is not set.
- *
- * @return the mark position or <code>-1</code> if no mark is set
- */
- int getMark();
-
- /**
- * Enables/disables the redrawing of this text viewer. This temporarily disconnects
- * the viewer from its underlying StyledText widget. While being disconnected only
- * the viewer's selection may be changed using <code>setSelectedRange</code>.
- * Any direct manipulation of the widget as well as calls to methods that change the viewer's
- * presentation state (such as enabling the segmented view) are not allowed.
- * When redrawing is disabled the viewer does not send out any selection or
- * view port change notification. When redrawing is enabled again, a selection
- * change notification is sent out for the selected range and this range is revealed.
- *
- * @param redraw <code>true</code> to enable redrawing, <code>false</code> otherwise
- */
- void setRedraw(boolean redraw);
-
- /**
- * Returns the viewer's rewrite target.
- *
- * @return the viewer's rewrite target
- */
- IRewriteTarget getRewriteTarget();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension2.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension2.java
deleted file mode 100644
index 610661166bb..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension2.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-import org.eclipse.swt.graphics.Point;
-
-/**
- * Extension interface for <code>ITextViewer</code>. Extends <code>ITextViewer</code> with
- * <ul>
- * <li> a replacement of the <code>ITextViewer.invalidateTextPresentation</code> method
- * <li> a replacement of the <code>ITextViewer.setTextHover</code> method now accepting state masks
- * </ul>
- *
- * @since 2.1
- */
-public interface ITextViewerExtension2 {
-
- /**
- * The state mask of the default hover (value <code>0xff</code>).
- */
- final int DEFAULT_HOVER_STATE_MASK= 0xff;
-
- /**
- * Invalidates the viewer's text presentation for the given range.
- *
- * @param offset the offset of the first character to be redrawn
- * @param length the length of the range to be redrawn
- */
- void invalidateTextPresentation(int offset, int length);
-
- /**
- * Sets this viewer's text hover for the given content type and the given state mask. If the given text hower
- * is <code>null</code>, any hover installed for the given content type and state mask is uninstalled.
- *
- * @param textViewerHover the new hover or <code>null</code>
- * @param contentType the type for which the hover is to be registered or unregistered
- * @param stateMask the SWT event state mask; <code>DEFAULT_HOVER_STATE_MASK</code> indicates that
- * the hover is installed as the default hover.
- */
- void setTextHover(ITextHover textViewerHover, String contentType, int stateMask);
-
- /**
- * Removes all text hovers for the given content type.
- * <p>
- * Note: To remove a hover for a given content type and state mask
- * use {@link #setTextHover(ITextHover, String, int)} with <code>null</code>
- * as parameter for the text hover.
- * </p>
- * @param contentType the type for which all text hovers are to be unregistered
- */
- void removeTextHovers(String contentType);
-
- /**
- * Returns the currently displayed text hover if any, <code>null</code> otherwise.
- */
- ITextHover getCurrentTextHover();
-
- /**
- * Returns the location at which the most recent mouse hover event
- * has been issued.
- *
- * @return the location of the most recent mouse hover event
- */
- Point getHoverEventLocation();
-
- /**
- * Prepends the given auto edit strategy to the existing list of strategies for the
- * specified content type. The strategies are called in the order in which they appear in the
- * list of strategies.
- *
- * @param strategy the auto edit strategy
- * @param contentType the content type
- */
- void prependAutoEditStrategy(IAutoEditStrategy strategy, String contentType);
-
- /**
- * Removes the first occurrence of the given auto edit strategy in the list of strategies
- * registered under the specified content type.
- *
- * @param strategy the auto edit strategy
- * @param contentType the content type
- */
- void removeAutoEditStrategy(IAutoEditStrategy strategy, String contentType);
-
- /**
- * Adds the given painter to this viewer.
- *
- * @param painter the painter to be added
- */
- void addPainter(IPainter painter);
-
- /**
- * Removes the given painter from this viewer. If the painter has not been
- * added to this viewer, this call is without effect.
- *
- * @param painter the painter to be removed
- */
- void removePainter(IPainter painter);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension3.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension3.java
deleted file mode 100644
index 80baf883697..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension3.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-/**
- * Extension interface for <code>ITextViewer</code>. Extends <code>ITextViewer</code> with the explicit
- * concept of model and widget coordinates. For example, a selection returned by the text viewer's control is
- * a widget selection. A widget selection always maps to a certain range of the viewer's document. This
- * range is considered the model selection.<p>
- * This general concepts replaces the notion of <code>visible region</code>.
- *
- * @since 2.1
- * @deprecated completely replaced by <code>ITextViewerExtension5</code>
- */
-public interface ITextViewerExtension3 {
-
-
- /**
- * Returns the minimal region of the viewer's document that completely comprises everything that is
- * visible in the viewer's widget or <code>null</code> if there is no such region.
- *
- * @return the minimal region of the viewer's document comprising the contents of the viewer's widget or <code>null</code>
- */
- IRegion getModelCoverage();
-
-
- /**
- * Returns the widget line that corresponds to the given line of the viewer's document or <code>-1</code> if there is no such line.
- *
- * @param modelLine the line of the viewer's document
- * @return the corresponding widget line or <code>-1</code>
- */
- int modelLine2WidgetLine(int modelLine);
-
- /**
- * Returns the widget offset that corresponds to the given offset in the viewer's document
- * or <code>-1</code> if there is no such offset
- *
- * @param modelOffset the offset in the viewer's document
- * @return the corresponding widget offset or <code>-1</code>
- */
- int modelOffset2WidgetOffset(int modelOffset);
-
- /**
- * Returns the minimal region of the viewer's widget that completely comprises the given region of the
- * viewer's document or <code>null</code> if there is no such region.
- *
- * @param modelRange the region of the viewer's document
- * @return the minimal region of the widget comprising <code>modelRange</code> or <code>null</code>
- */
- IRegion modelRange2WidgetRange(IRegion modelRange);
-
-
- /**
- * Returns the offset of the viewer's document that corresponds to the given widget offset
- * or <code>-1</code> if there is no such offset
- *
- * @param widgetOffset the widget offset
- * @return the corresponding offset in the viewer's document or <code>-1</code>
- */
- int widgetOffset2ModelOffset(int widgetOffset);
-
- /**
- * Returns the minimal region of the viewer's document that completely comprises the given widget region
- * or <code>null</code> if there is no such region.
- *
- * @param widgetRange the widget region
- * @return the minimal region of the viewer's document comprising <code>widgetlRange</code> or <code>null</code>
- */
- IRegion widgetRange2ModelRange(IRegion widgetRange);
-
- /**
- * Returns the line of the viewer's document that corresponds to the given widget line or <code>-1</code> if there is no such line.
- *
- * @param widgetLine the widget line
- * @return the corresponding line of the viewer's document or <code>-1</code>
- */
- int widgetlLine2ModelLine(int widgetLine);
-
- /**
- * Returns the widget line of the given widget offset.
- *
- * @param widgetOffset the widget offset
- * @return the widget line of the widget offset
- */
- int widgetLineOfWidgetOffset(int widgetOffset);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension4.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension4.java
deleted file mode 100644
index bc9ee288498..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension4.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-/**
- * Extension interface for <code>ITextViewer</code>. Adds the following functionality:
- * <ul>
- * <li>focus handling for widget token keepers</li>
- * <li>introduces text presentation listener</li>
- * </ul>
- *
- * @since 3.0
- */
-public interface ITextViewerExtension4 {
-
- /**
- * Instructs the receiver to request the <code>IWidgetTokenKeeper</code>
- * currently holding the widget token to take the keyboard focus.
- *
- * @return <code>true</code> if there was any <code>IWidgetTokenKeeper</code> that was asked to take the focus, <code>false</code> otherwise
- */
- boolean moveFocusToWidgetToken();
-
- /**
- * Adds the given text presentation listener to this text viewer.
- * This call has no effect if the listener is already registered
- * with this text viewer.
- *
- * @param listener the text presentation listener
- */
- void addTextPresentationListener(ITextPresentationListener listener);
-
- /**
- * Removes the given text presentation listener from this text viewer.
- * This call has no effect if the listener is not registered with this
- * text viewer.
- *
- * @param listener the text presentation listener
- */
- void removeTextPresentationListener(ITextPresentationListener listener);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension5.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension5.java
deleted file mode 100644
index 64c2c182b2c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/ITextViewerExtension5.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * Extension interface to <code>ITextViewer</code>. Defines a complete
- * replacement of all visible region related methods defined in
- * <code>ITextViewer</code>.
- * <p>
- * Introduces the explicit concept of model and widget coordinates. For example,
- * a selection returned by the text viewer's control is a widget selection. A
- * widget selection always maps to a certain range of the viewer's document.
- * This range is considered the model selection.
- * <p>
- * All model ranges that have a corresponding widget ranges are considered
- * "exposed model ranges". The set of exposed model ranges can be defined to
- * contain only a single region using <code>setExposedModelRange</code>. The
- * viewer can be requested to expose a given model range.<p>
- *
- * @since 3.0
- */
-public interface ITextViewerExtension5 extends ITextViewerExtension3 {
-
- /**
- * Returns the minimal region of the viewer's document that completely comprises everything that is
- * visible in the viewer's widget or <code>null</code> if there is no such region.
- *
- * @return the minimal region of the viewer's document comprising the contents of the viewer's widget or <code>null</code>
- */
- IRegion getModelCoverage();
-
- /**
- * Returns the widget line that corresponds to the given line of the viewer's document or <code>-1</code> if there is no such line.
- *
- * @param modelLine the line of the viewer's document
- * @return the corresponding widget line or <code>-1</code>
- */
- int modelLine2WidgetLine(int modelLine);
-
- /**
- * Returns the widget offset that corresponds to the given offset in the viewer's document
- * or <code>-1</code> if there is no such offset
- *
- * @param modelOffset the offset in the viewer's document
- * @return the corresponding widget offset or <code>-1</code>
- */
- int modelOffset2WidgetOffset(int modelOffset);
-
- /**
- * Returns the minimal region of the viewer's widget that completely comprises the given region of the
- * viewer's document or <code>null</code> if there is no such region.
- *
- * @param modelRange the region of the viewer's document
- * @return the minimal region of the widget comprising <code>modelRange</code> or <code>null</code>
- */
- IRegion modelRange2WidgetRange(IRegion modelRange);
-
- /**
- * Returns the offset of the viewer's document that corresponds to the given widget offset
- * or <code>-1</code> if there is no such offset
- *
- * @param widgetOffset the widget offset
- * @return the corresponding offset in the viewer's document or <code>-1</code>
- */
- int widgetOffset2ModelOffset(int widgetOffset);
-
- /**
- * Returns the minimal region of the viewer's document that completely comprises the given widget region
- * or <code>null</code> if there is no such region.
- *
- * @param widgetRange the widget region
- * @return the minimal region of the viewer's document comprising <code>widgetlRange</code> or <code>null</code>
- */
- IRegion widgetRange2ModelRange(IRegion widgetRange);
-
- /**
- * Returns the line of the viewer's document that corresponds to the given widget line or <code>-1</code> if there is no such line.
- *
- * @param widgetLine the widget line
- * @return the corresponding line of the viewer's document or <code>-1</code>
- */
- int widgetLine2ModelLine(int widgetLine);
-
- /**
- * Returns the widget line of the given widget offset.
- *
- * @param widgetOffset the widget offset
- * @return the widget line of the widget offset
- */
- int widgetLineOfWidgetOffset(int widgetOffset);
-
-
- /**
- * Returns the maximal subranges of the given model range thus that there is
- * no offset inside a subrange for which there is no image offset.
- *
- * @param modelRange the model range
- * @return the list of subranges
- */
- IRegion[] getCoveredModelRanges(IRegion modelRange);
-
- /**
- * Exposes the given model range. Returns whether this call caused a change
- * of the set of exposed model ranges.
- *
- * @param modelRange the model range to be exposed
- * @return <code>true</code> if the set of exposed model ranges changed, <code>false</code> otherwise
- */
- boolean exposeModelRange(IRegion modelRange);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java
deleted file mode 100644
index c0049f40278..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IUndoManager.java
+++ /dev/null
@@ -1,94 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * An undo manager is connected to at most one text viewer.
- * It monitors the text viewer and keeps a history of the
- * changes applied to the viewer. The undo manager groups those
- * changes into user interactions which on an undo request are
- * rolled back in one atomic change. <p>
- * Clients may implement this interface or use the standard
- * implementation <code>DefaultUndoManager</code>.
- *
- * @see org.eclipse.jface.text.DefaultUndoManager
- */
-public interface IUndoManager {
-
- /**
- * Connects this undo manager to the given text viewer.
- *
- * @param viewer the viewer the undo manager is connected to
- */
- void connect(ITextViewer viewer);
-
- /**
- * Disconnects this undo manager from its text viewer.
- * If this undo manager hasn't been connected before this
- * operation has no effect.
- */
- void disconnect();
-
- /**
- * Signals the undo manager that all subsequent changes until
- * <code>endCompoundChange</code> is called are to be undone in one piece.
- */
- void beginCompoundChange();
-
- /**
- * Signals the undo manager that the sequence of changes which started with
- * <code>beginCompoundChange</code> has been finished. All subsequent changes
- * are considered to be individually undoable.
- */
- void endCompoundChange();
-
- /**
- * Resets the history of the undo manager. After that call,
- * there aren't any undoable or redoable text changes.
- */
- void reset();
-
- /**
- * The given parameter determines the maximal length of the history
- * remembered by the undo manager.
- *
- * @param undoLevel the length of this undo manager's history
- */
- void setMaximalUndoLevel(int undoLevel);
-
- /**
- * Returns whether at least one text change can be rolled back.
- *
- * @return <code>true</code> if at least one text change can be rolled back
- */
- boolean undoable();
-
- /**
- * Returns whether at least one text change can be repeated. A text change
- * can be repeated only if it was executed and rolled back.
- *
- * @return <code>true</code> if at least on text change can be repeated
- */
- boolean redoable();
-
- /**
- * Rolls back the most recently executed text change.
- */
- void undo();
-
- /**
- * Repeats the most recently rolled back text change.
- */
- void redo();
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java
deleted file mode 100644
index 7183b6382cc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IViewportListener.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-/**
- * Registered with a text viewer, viewport listeners are
- * informed about changes of a text viewer's viewport. The view port is that
- * portion of the viewer's document which is visible in the viewer. <p>
- * Clients may implement this interface.
- *
- * @see org.eclipse.jface.text.ITextViewer
- */
-public interface IViewportListener {
-
- /**
- * Informs about viewport changes. The given vertical position
- * is the new vertical scrolling offset measured in pixels.
- *
- * @param verticalOffset the vertical offset
- */
- void viewportChanged(int verticalOffset);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java
deleted file mode 100644
index 7c3add55dd3..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeper.java
+++ /dev/null
@@ -1,34 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-/**
- * A widget token keeper may require a widget token from an
- * <code>IWidgetTokenOwner</code> and release the token
- * to the owner after usage. A widget token owner may request
- * the token from the token keeper. The keeper may deny that.
- *
- * @since 2.0
- */
-public interface IWidgetTokenKeeper {
-
- /**
- * The given widget token owner requests the widget token from
- * this token keeper. Returns <code>true</code> if the token is released
- * by this token keeper. Note, the keeper must not call
- * <code>releaseWidgetToken(IWidgetTokenKeeper)</code> explicitly.
- *
- * @param owner the token owner
- * @return <code>true</code> if token has been released <code>false</code> otherwise
- */
- boolean requestWidgetToken(IWidgetTokenOwner owner);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeperExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeperExtension.java
deleted file mode 100644
index decde913798..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenKeeperExtension.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * Extension interface to <code>IWidgetTokenKeeper</code>. Replaces the original
- * <code>requestWidgetToken</code> functionality with a new priority based approach.
- * Adds the concept of focus handling.
- *
- * @since 3.0
- */
-public interface IWidgetTokenKeeperExtension {
-
- /**
- * The given widget token owner requests the widget token from
- * this token keeper. Returns <code>true</code> if the token is released
- * by this token keeper. Note, the keeper must not call
- * <code>releaseWidgetToken(IWidgetTokenKeeper)</code> explicitly.
- *
- * <p>The general contract is that the receiver should release the token
- * if <code>priority</code> exceeds the receiver's priority.</p>
- *
- * @param owner the token owner
- * @param priority the priority of the request
- * @return <code>true</code> if token has been released <code>false</code> otherwise
- */
- boolean requestWidgetToken(IWidgetTokenOwner owner, int priority);
-
- /**
- * Requests the receiver to give focus to its popup shell, hover, or similar. There is
- * no assumption made whether the receiver actually succeeded in taking the focus. The return
- * value gives a hint whether the receiver tried to take focus.
- *
- * @param owner the token owner
- * @return <code>true</code> if the receiver tried to take focus, <code>false</code> if it did not.
- */
- boolean setFocus(IWidgetTokenOwner owner);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java
deleted file mode 100644
index 8eed2af944d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwner.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * A widget token must be aquired in order to display
- * information in a temporary window. The intent behind this concept is that
- * only one temporary window should be presented at any moment in time and
- * also to avoid overlapping temporary windows.
- *
- * @since 2.0
- */
-public interface IWidgetTokenOwner {
-
- /**
- * Requests the widget token from this token owner. Returns
- * <code>true</code> if the token has been aquired or is
- * already owned by the requester. This method is non-blocking.
- *
- * @param requester the token requester
- * @return <code>true</code> if requester aquires the token,
- * <code>false</code> otherwise
- */
- boolean requestWidgetToken(IWidgetTokenKeeper requester);
-
- /**
- * The given token keeper releases the token to this
- * token owner. If the token has previously not been held
- * by the given token keeper, nothing happens. This
- * method is non-blocking.
- *
- * @param tokenKeeper the token keeper
- */
- void releaseWidgetToken(IWidgetTokenKeeper tokenKeeper);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwnerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwnerExtension.java
deleted file mode 100644
index 2e48c32e7e3..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/IWidgetTokenOwnerExtension.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-/**
- * Extension interface to <code>IWidgetTokenOwner</code>. Replaces the original
- * <code>requestWidgetToken</code> functionality with a new priority based approach.
- *
- * @since 3.0
- */
-public interface IWidgetTokenOwnerExtension {
-
- /**
- * Requests the widget token from this token owner. Returns
- * <code>true</code> if the token has been aquired or is
- * already owned by the requester. This method is non-blocking.
- *
- * <p><code>priority</code> is forwarded to any existing token keeper
- * to give it an estimate on whether the request has higher priority than
- * the current keeper's. There is, however, no guarantee that another keeper
- * will release the token even if it has a high priority.</p>
- *
- * @param requester the token requester
- * @param priority the priority of the request
- * @return <code>true</code> if requester aquires the token,
- * <code>false</code> otherwise
- */
- boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java
deleted file mode 100644
index 67fab7616de..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-class JFaceTextMessages {
-
- private static final String RESOURCE_BUNDLE= "org.eclipse.jface.text.JFaceTextMessages";//$NON-NLS-1$
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JFaceTextMessages() {
- }
-
- 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.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties
deleted file mode 100644
index 35a69719227..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/JFaceTextMessages.properties
+++ /dev/null
@@ -1,33 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-
-
-TextViewer.error.bad_location.WidgetCommand.setEvent=TextViewer.WidgetCommand.setEvent: BadLocationException
-TextViewer.error.bad_location.findAndSelect=TextViewer.findAndSelect: BadLocationException
-TextViewer.error.bad_location.getBottomIndex=TextViewer.getBottomIndex: BadLocationException
-TextViewer.error.bad_location.getBottomIndexEndOffset=TextViewer.getBottomIndexEndOffset: BadLocationException
-TextViewer.error.bad_location.getFirstCompleteLineOfRegion=TextViewer.getFirstCompleteLineOfRegion: BadLocationException
-TextViewer.error.bad_location.getTopIndex=TextViewer.getTopIndex: BadLocationException
-TextViewer.error.bad_location.getTopIndexStartOffset=TextViewer.getTopIndexStartOffset: BadLocationException
-TextViewer.error.bad_location.selectContentTypePlugin=TextViewer.selectContentTypePlugin: BadLocationException
-TextViewer.error.bad_location.setTopIndex_1=TextViewer.setTopIndex: BadLocationException
-TextViewer.error.bad_location.setTopIndex_2=TextViewer.setTopIndex: BadLocationException
-TextViewer.error.bad_location.shift_1=TextViewer.shift: BadLocationException
-TextViewer.error.bad_location.shift_2=TextViewer.shift: BadLocationException
-TextViewer.error.bad_location.verifyText=TextViewer.verifyText: BadLocationException
-TextViewer.error.invalid_range=Invalid range argument
-TextViewer.error.invalid_visible_region_1=Invalid visible region argument
-TextViewer.error.invalid_visible_region_2=Invalid visible region argument
-
-AbstractHoverInformationControlManager.hover.restarter=Hover Restart Delay
-
-# The first parameter is the annotation type label and the second is the number of annotations
-OverviewRulerHeader.toolTipTextEntry= {0}: {1}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/MarginPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/MarginPainter.java
deleted file mode 100644
index 5ebb74c49ce..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/MarginPainter.java
+++ /dev/null
@@ -1,171 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-
-
-/**
- * Paints a vertical line (margin line) after a given column respecting the text viewer's font.
- * Clients usually instantiate and configure objects of this class. <p>
- * This class is not intended to be subclassed.
- *
- * @since 2.1
- */
-public class MarginPainter implements IPainter, PaintListener {
-
- /** The widget of the text viewer */
- private StyledText fTextWidget;
-
- /** The column after which to paint the line, default value <code>80</code> */
- private int fMarginWidth= 80;
- /** The color in which to paint the line */
- private Color fColor;
- /** The line style of the line to be painted, default value <code>SWT.LINE_SOLID</code> */
- private int fLineStyle= SWT.LINE_SOLID;
- /** The line width of the line to be painted, default value <code>1</code> */
- private int fLineWidth= 1;
- /** The cached x-offset of the <code>fMarginWidth</code> for the current font */
- private int fCachedWidgetX= -1;
- /** The active state of this painter */
- private boolean fIsActive= false;
-
- /**
- * Creates a new painter for the given text viewer.
- *
- * @param textViewer the text viewer
- */
- public MarginPainter(ITextViewer textViewer) {
- fTextWidget= textViewer.getTextWidget();
- }
-
- /**
- * Sets the column after which to draw the margin line.
- *
- * @param width the column
- */
- public void setMarginRulerColumn(int width) {
- fMarginWidth= width;
- initialize();
- }
-
- /**
- * Sets the line style of the margin line.
- *
- * @param lineStyle a <code>SWT</code> style constant describing the line style
- */
- public void setMarginRulerStyle(int lineStyle) {
- fLineStyle= lineStyle;
- }
-
- /**
- * Sets the line width of the margin line.
- *
- * @param lineWidth the line width
- */
- public void setMarginRulerWidth(int lineWidth) {
- fLineWidth= lineWidth;
- }
-
- /**
- * Sets the color of the margin line. Must be called before <code>paint</code> is called the first time.
- *
- * @param color the color
- */
- public void setMarginRulerColor(Color color) {
- fColor= color;
- }
-
- /**
- * Initializes this painter, by flushing and recomputing all caches and causing
- * the widget to be redrawn. Must be called explicitly when font of text widget changes.
- */
- public void initialize() {
- computeWidgetX();
- fTextWidget.redraw();
- }
-
- /**
- * Computes and remembers the x-offset of the margin column for the
- * current widget font.
- */
- private void computeWidgetX() {
- GC gc= new GC(fTextWidget);
- int pixels= gc.getFontMetrics().getAverageCharWidth();
- gc.dispose();
-
- fCachedWidgetX= pixels * fMarginWidth;
- }
-
- /*
- * @see IPainter#deactivate(boolean)
- */
- public void deactivate(boolean redraw) {
- if (fIsActive) {
- fIsActive= false;
- fCachedWidgetX= -1;
- fTextWidget.removePaintListener(this);
- if (redraw)
- fTextWidget.redraw();
- }
- }
-
- /*
- * @see IPainter#dispose()
- */
- public void dispose() {
- fTextWidget= null;
- }
-
- /*
- * @see IPainter#paint(int)
- */
- public void paint(int reason) {
- if (!fIsActive) {
- fIsActive= true;
- fTextWidget.addPaintListener(this);
- if (fCachedWidgetX == -1)
- computeWidgetX();
- fTextWidget.redraw();
- } else if (CONFIGURATION == reason || INTERNAL == reason)
- fTextWidget.redraw();
- }
-
- /*
- * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
- */
- public void paintControl(PaintEvent e) {
- if (fTextWidget != null) {
- int x= fCachedWidgetX - fTextWidget.getHorizontalPixel();
- if (x >= 0) {
- Rectangle area= fTextWidget.getClientArea();
- e.gc.setForeground(fColor);
- e.gc.setLineStyle(fLineStyle);
- e.gc.setLineWidth(fLineWidth);
- e.gc.drawLine(x, 0, x, area.height);
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager)
- */
- public void setPositionManager(IPaintPositionManager manager) {
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java
deleted file mode 100644
index 749e1c69911..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/MarkSelection.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * Default implementation of <code>IMarkSelection</code>.
- * @since 2.0
- */
-public class MarkSelection implements IMarkSelection {
-
- /** The marked document. */
- private final IDocument fDocument;
- /** The offset of the mark selection. */
- private final int fOffset;
- /** The length of the mark selection. */
- private final int fLength;
-
- /**
- * Creates a MarkSelection.
- *
- * @param document the marked document
- * @param offset the offset of the mark
- * @param length the length of the mark, may be negative if caret before offset
- */
- public MarkSelection(IDocument document, int offset, int length) {
- fDocument= document;
- fOffset= offset;
- fLength= length;
- }
-
- /*
- * @see IMarkSelection#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @see IMarkSelection#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /*
- * @see IMarkSelection#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see ISelection#isEmpty()
- */
- public boolean isEmpty() {
- return fLength == 0;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/PaintManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/PaintManager.java
deleted file mode 100644
index dd6609f91f1..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/PaintManager.java
+++ /dev/null
@@ -1,380 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-
-
-/**
- * Manages the painters of a text viewer. Clients usually instantiate and configure
- * objects of this type.
- *
- * @since 2.1
- */
-public final class PaintManager implements KeyListener, MouseListener, ISelectionChangedListener, ITextListener, ITextInputListener {
-
- /**
- * Position updater used by the position manager. This position updater differes from the default position
- * updater in that it extends a position when an insertion happens at the position's offset and right behind
- * the position.
- */
- static class PaintPositionUpdater extends DefaultPositionUpdater {
-
- /**
- * Creates the position updater for the given category.
- *
- * @param category the position category
- */
- protected PaintPositionUpdater(String category) {
- super(category);
- }
-
- /**
- * If an insertion happens at a position's offset, the
- * position is extended rather than shifted. Also, if something is added
- * right behind the end of the position, the position is extended rather
- * than kept stable.
- */
- protected void adaptToInsert() {
-
- int myStart= fPosition.offset;
- int myEnd= fPosition.offset + fPosition.length;
- myEnd= Math.max(myStart, myEnd);
-
- int yoursStart= fOffset;
- int yoursEnd= fOffset + fReplaceLength;// - 1;
- yoursEnd= Math.max(yoursStart, yoursEnd);
-
- if (myEnd < yoursStart)
- return;
-
- if (myStart <= yoursStart)
- fPosition.length += fReplaceLength;
- else
- fPosition.offset += fReplaceLength;
- }
- }
-
- /**
- * The paint position manager used by this paint manager. The paint position
- * manager is installed on a single document and control the creation/disposed
- * and updating of a position category that will be used for managing positions.
- */
- static class PositionManager implements IPaintPositionManager {
-
- /** The document this positon manager works on */
- private IDocument fDocument;
- /** The position updater used for the managing position category */
- private IPositionUpdater fPositionUpdater;
- /** The managing position category */
- private String fCategory;
-
- /**
- * Creates a new position manager. Initializes the managing
- * position category using its class name and its hash value.
- */
- public PositionManager() {
- fCategory= getClass().getName() + hashCode();
- fPositionUpdater= new PaintPositionUpdater(fCategory);
- }
-
- /**
- * Installs this position manager in the given document. The position manager stays
- * active until <code>uninstall</code> or <code>dispose</code>
- * is called.
- *
- * @param document the document to be installed on
- */
- public void install(IDocument document) {
- fDocument= document;
- fDocument.addPositionCategory(fCategory);
- fDocument.addPositionUpdater(fPositionUpdater);
- }
-
- /**
- * Diposes this position manager. The position manager is automatically
- * uninstalled from the document it has previously been installed
- * on.
- */
- public void dispose() {
- uninstall(fDocument);
- }
-
- /**
- * Uninstalls this position manager form the given document. If the position
- * manager has no been installed on this document, this method is without effect.
- *
- * @param document the document form which to uninstall
- */
- public void uninstall(IDocument document) {
- if (document == fDocument && document != null) {
- try {
- fDocument.removePositionUpdater(fPositionUpdater);
- fDocument.removePositionCategory(fCategory);
- } catch (BadPositionCategoryException x) {
- // should not happen
- }
- fDocument= null;
- }
- }
-
- /*
- * @see IPositionManager#addManagedPosition(Position)
- */
- public void managePosition(Position position) {
- try {
- fDocument.addPosition(fCategory, position);
- } catch (BadPositionCategoryException x) {
- // should not happen
- } catch (BadLocationException x) {
- // should not happen
- }
- }
-
- /*
- * @see IPositionManager#removeManagedPosition(Position)
- */
- public void unmanagePosition(Position position) {
- try {
- fDocument.removePosition(fCategory, position);
- } catch (BadPositionCategoryException x) {
- // should not happen
- }
- }
- }
-
-
- /** The painters managed by this paint manager. */
- private List fPainters= new ArrayList(2);
- /** The position manager used by this paint manager */
- private PositionManager fManager;
- /** The associated text viewer */
- private ITextViewer fTextViewer;
-
- /**
- * Creates a new paint manager for the given text viewer.
- *
- * @param textViewer the text viewer associated to this newly created paint manager
- */
- public PaintManager(ITextViewer textViewer) {
- fTextViewer= textViewer;
- }
-
-
- /**
- * Adds the given painter to the list of painters managed by this paint manager.
- * If the painter is already registered with this paint manager, this method is
- * without effect.
- *
- * @param painter the painter to be added
- */
- public void addPainter(IPainter painter) {
- if (!fPainters.contains(painter)) {
- fPainters.add(painter);
- if (fPainters.size() == 1)
- install();
- painter.setPositionManager(fManager);
- painter.paint(IPainter.INTERNAL);
- }
- }
-
- /**
- * Removes the given painter from the list of painters managed by this
- * paint manager. If the painter has not previously been added to this
- * paint manager, this method is without effect.
- *
- * @param painter the painter to be removed
- */
- public void removePainter(IPainter painter) {
- if (fPainters.remove(painter)) {
- painter.deactivate(true);
- painter.setPositionManager(null);
- }
- if (fPainters.size() == 0)
- dispose();
- }
-
- /**
- * Installs/activates this paint manager. Is called as soon as the
- * first painter is to be managed by this paint manager.
- */
- private void install() {
-
- fManager= new PositionManager();
- if (fTextViewer.getDocument() != null)
- fManager.install(fTextViewer.getDocument());
-
- fTextViewer.addTextInputListener(this);
-
- addListeners();
- }
-
- /**
- * Installs our listener set on the text viewer and the text widget,
- * respectively.
- */
- private void addListeners() {
- ISelectionProvider provider= fTextViewer.getSelectionProvider();
- provider.addSelectionChangedListener(this);
-
- fTextViewer.addTextListener(this);
-
- StyledText text= fTextViewer.getTextWidget();
- text.addKeyListener(this);
- text.addMouseListener(this);
- }
-
- /**
- * Disposes this paint manager. The paint manager uninstalls itself
- * and clears all registered painters. This method is also called when the
- * last painter is removed from the list of managed painters.
- */
- public void dispose() {
-
- if (fManager != null) {
- fManager.dispose();
- fManager= null;
- }
-
- for (Iterator e = fPainters.iterator(); e.hasNext();)
- ((IPainter) e.next()).dispose();
- fPainters.clear();
-
- fTextViewer.removeTextInputListener(this);
-
- removeListeners();
- }
-
- /**
- * Removes our set of listeners from the text viewer and widget,
- * respectively.
- */
- private void removeListeners() {
- ISelectionProvider provider= fTextViewer.getSelectionProvider();
- if (provider != null)
- provider.removeSelectionChangedListener(this);
-
- fTextViewer.removeTextListener(this);
-
- StyledText text= fTextViewer.getTextWidget();
- if (text != null && !text.isDisposed()) {
- text.removeKeyListener(this);
- text.removeMouseListener(this);
- }
- }
-
- /**
- * Triggers all registered painters for the given reason.
- *
- * @param reason the reason
- * @see IPainter
- */
- private void paint(int reason) {
- for (Iterator e = fPainters.iterator(); e.hasNext();)
- ((IPainter) e.next()).paint(reason);
- }
-
- /*
- * @see KeyListener#keyPressed(KeyEvent)
- */
- public void keyPressed(KeyEvent e) {
- paint(IPainter.KEY_STROKE);
- }
-
- /*
- * @see KeyListener#keyReleased(KeyEvent)
- */
- public void keyReleased(KeyEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent e) {
- paint(IPainter.MOUSE_BUTTON);
- }
-
- /*
- * @see MouseListener#mouseUp(MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /*
- * @see ISelectionChangedListener#selectionChanged(SelectionChangedEvent)
- */
- public void selectionChanged(SelectionChangedEvent event) {
- paint(IPainter.SELECTION);
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent event) {
-
- if (!event.getViewerRedrawState())
- return;
-
- Control control= fTextViewer.getTextWidget();
- if (control != null) {
- control.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (fTextViewer != null)
- paint(IPainter.TEXT_CHANGE);
- }
- });
- }
- }
-
- /*
- * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- if (oldInput != null) {
- for (Iterator e = fPainters.iterator(); e.hasNext();)
- ((IPainter) e.next()).deactivate(false);
- fManager.uninstall(oldInput);
- removeListeners();
- }
- }
-
- /*
- * @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- if (newInput != null) {
- fManager.install(newInput);
- paint(IPainter.TEXT_CHANGE);
- addListeners();
- }
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java
deleted file mode 100644
index 61b8d47c69c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/PropagatingFontFieldEditor.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.graphics.FontData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Label;
-
-import org.eclipse.jface.preference.FontFieldEditor;
-import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
-import org.eclipse.jface.util.IPropertyChangeListener;
-import org.eclipse.jface.util.PropertyChangeEvent;
-
-
-/**
- * This font field editor implements chaining between a source preference
- * store and a target preference store. Any time the source preference
- * store changes, the change is propagated to the target store. Propagation
- * means that the actual value stored in the source store is set as default
- * value in the target store. If the target store does not contain a value
- * other than the default value, the new default value is immediately
- * effective.
- *
- * @see FontFieldEditor
- * @since 2.0
- * @deprecated since 3.0 not longer in use, no longer supported
- */
-public class PropagatingFontFieldEditor extends FontFieldEditor {
-
- /** The editor's parent widget */
- private Composite fParent;
- /** The representation of the default font choice */
- private String fDefaultFontLabel;
-
- /**
- * Creates a new font field editor with the given parameters.
- *
- * @param name the editor's name
- * @param labelText the text shown as editor description
- * @param parent the editor's parent widget
- * @param defaultFontLabel the label shown in the editor value field when the default value should be taken
- */
- public PropagatingFontFieldEditor(String name, String labelText, Composite parent, String defaultFontLabel) {
- super(name, labelText, parent);
- fParent= parent;
- fDefaultFontLabel= defaultFontLabel == null ? "" : defaultFontLabel; //$NON-NLS-1$
- }
-
- /*
- * @see FontFieldEditor#doLoad()
- */
- protected void doLoad() {
- if (getPreferenceStore().isDefault(getPreferenceName()))
- loadDefault();
- super.doLoad();
- checkForDefault();
- }
-
- /*
- * @see FontFieldEditor#doLoadDefault()
- */
- protected void doLoadDefault() {
- super.doLoadDefault();
- checkForDefault();
- }
-
- /**
- * Checks whether this editor presents the default value "inheritated"
- * from the workbench rather than its own font.
- */
- private void checkForDefault() {
- if (presentsDefaultValue()) {
- Control c= getValueControl(fParent);
- if (c instanceof Label)
- ((Label) c).setText(fDefaultFontLabel);
- }
- }
-
- /**
- * Propagates the font set in the source store to the
- * target store using the given keys.
- *
- * @param source the store from which to read the text font
- * @param sourceKey the key under which the font can be found
- * @param target the store to which to propagate the font
- * @param targetKey the key under which to store the font
- */
- private static void propagateFont(IPreferenceStore source, String sourceKey, IPreferenceStore target, String targetKey) {
- FontData fd= PreferenceConverter.getFontData(source, sourceKey);
- if (fd != null) {
- boolean isDefault= target.isDefault(targetKey); // save old state!
- PreferenceConverter.setDefault(target, targetKey, fd);
- if (isDefault) {
- // restore old state
- target.setToDefault(targetKey);
- }
- }
- }
-
- /**
- * Starts the propagation of the font preference stored in the source preference
- * store under the source key to the target preference store using the target
- * preference key.
- *
- * @param source the source preference store
- * @param sourceKey the key to be used in the source preference store
- * @param target the target preference store
- * @param targetKey the key to be used in the target preference store
- */
- public static void startPropagate(final IPreferenceStore source, final String sourceKey, final IPreferenceStore target, final String targetKey) {
- source.addPropertyChangeListener(new IPropertyChangeListener() {
- public void propertyChange(PropertyChangeEvent event) {
- if (sourceKey.equals(event.getProperty()))
- propagateFont(source, sourceKey, target, targetKey);
- }
- });
-
- propagateFont(source, sourceKey, target, targetKey);
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java
deleted file mode 100644
index 3be050845cf..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextAttribute.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-
-
-/**
- * Description of textual attributes such as color and style.
- * Text attributes are considered value objects.
- */
-public class TextAttribute {
-
- /** Foreground color */
- private Color foreground;
-
- /** Background color */
- private Color background;
-
- /** The text style */
- private int style;
-
- /**
- * Creates a text attribute with the given colors and style.
- *
- * @param foreground the foreground color
- * @param background the background color
- * @param style the style
- */
- public TextAttribute(Color foreground, Color background, int style) {
- this.foreground= foreground;
- this.background= background;
- this.style= style;
- }
-
- /**
- * Creates a text attribute for the given foreground color, no background color and
- * with the SWT normal style.
- *
- * @param foreground the foreground color
- */
- public TextAttribute(Color foreground) {
- this(foreground, null, SWT.NORMAL);
- }
-
- /*
- * @see Object#equals(Object)
- */
- public boolean equals(Object object) {
-
- if (object == this)
- return true;
-
- if (!(object instanceof TextAttribute))
- return false;
-
- TextAttribute a= (TextAttribute) object;
- return (a.style == style && equals(a.foreground, foreground) && equals(a.background, background));
- }
-
- /**
- * Returns whether the two given objects are equal.
- *
- * @param o1 the first object, can be <code>null</code>
- * @param o2 the second object, can be <code>null</code>
- * @return <code>true</code> if the given objects are equals
- * @since 2.0
- */
- private boolean equals(Object o1, Object o2) {
- if (o1 != null)
- return o1.equals(o2);
- return (o2 == null);
- }
-
- /*
- * @see Object#hashCode()
- */
- public int hashCode() {
- int foregroundHash= foreground == null ? 0 : foreground.hashCode();
- int backgroundHash= background == null ? 0 : background.hashCode();
- return (foregroundHash << 24) | (backgroundHash << 16) | style;
- }
-
- /**
- * Returns the attribute's foreground color.
- *
- * @return the attribute's foreground color
- */
- public Color getForeground() {
- return foreground;
- }
-
- /**
- * Returns the attribute's background color.
- *
- * @return the attribute's background color
- */
- public Color getBackground() {
- return background;
- }
-
- /**
- * Returns the attribute's style.
- *
- * @return the attribute's style
- */
- public int getStyle() {
- return style;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java
deleted file mode 100644
index 9d83d0fced8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextEvent.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-/**
- * This event is sent to implementers of <code>ITextListener</code>. It represents a
- * change applied to text viewer. The change is specified as a replace command using
- * offset, length, inserted text, and replaced text. The text viewer issues a text event
- * after the viewer has been changed either in response to a change of the viewer's document
- * or when the viewer's visual content has been changed. In the first case, the text event
- * also carries the original document event. Depending on the viewer's presentation mode,
- * the text event coordinates are different from the document event's coordinates.
- * Clients other than text viewer's don't create instances of this class.
- *
- * @see ITextListener
- * @see ITextViewer
- * @see DocumentEvent
- */
-public class TextEvent {
-
- /** Start offset of the change */
- private int fOffset;
- /** The length of the change */
- private int fLength;
- /** Inserted text */
- private String fText;
- /** Replaced text */
- private String fReplacedText;
- /** The original document event, may by null */
- private DocumentEvent fDocumentEvent;
- /**
- * The redraw state of the viewer issuing this event
- * @since 2.0
- */
- private boolean fViewerRedrawState;
-
- /**
- * Creates a new <code>TextEvent</code> based on the specification.
- *
- * @param offset the offset
- * @param length the length
- * @param text the inserted text
- * @param replacedText the replaced text
- * @param event the associated document event or <code>null</code> if none
- * @param viewerRedrawState the redraw state of the viewer
- */
- protected TextEvent(int offset, int length, String text, String replacedText, DocumentEvent event, boolean viewerRedrawState) {
- fOffset= offset;
- fLength= length;
- fText= text;
- fReplacedText= replacedText;
- fDocumentEvent= event;
- fViewerRedrawState= viewerRedrawState;
- }
-
- /**
- * Returns the offset of the event.
- *
- * @return the offset of the event
- */
- public int getOffset() {
- return fOffset;
- }
-
- /**
- * Returns the length of the event.
- *
- * @return the length of the event
- */
- public int getLength() {
- return fLength;
- }
-
- /**
- * Returns the text of the event.
- *
- * @return the text of the event
- */
- public String getText() {
- return fText;
- }
-
- /**
- * Returns the text replaced by this event.
- *
- * @return the text replaced by this event
- */
- public String getReplacedText() {
- return fReplacedText;
- }
-
- /**
- * Returns the corresponding document event that caused the viewer change
- *
- * @return the corresponding document event, <code>null</code> if a visual change only
- */
- public DocumentEvent getDocumentEvent() {
- return fDocumentEvent;
- }
-
- /**
- * Returns the viewer's redraw state.
- *
- * @return <code>true</code> if the viewer's redraw state is <code>true</code>
- * @since 2.0
- */
- public boolean getViewerRedrawState() {
- return fViewerRedrawState;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java
deleted file mode 100644
index 9ad1cb7ba87..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextPresentation.java
+++ /dev/null
@@ -1,699 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.NoSuchElementException;
-
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-
-
-/**
- * Describes the presentation styles for a section of an indexed text
- * such as a document or string. A text presentation defines a default style
- * for the whole section and in addition style differences for individual
- * subsections. Text presentations can be narrowed down to a particular
- * result window. All methods are result window aware, i.e. ranges outside
- * the result window are always ignored.<p>
- * All iterators provided by a text presentation assume that they enumerate
- * non overlapping, consecutive ranges inside the default range. Thus, all
- * these iterators do not include the default range. The default style range
- * must be explicitly asked for using <code>getDefaultStyleRange</code>.
- */
-public class TextPresentation {
-
- /**
- * Applies the given presentation to the given text widget. Helper method.
- *
- * @param presentation the style information
- * @param text the widget to which to apply the style information
- * @since 2.0
- */
- public static void applyTextPresentation(TextPresentation presentation, StyledText text) {
-
- StyleRange[] ranges= new StyleRange[presentation.getDenumerableRanges()];
-
- int i= 0;
- Iterator e= presentation.getAllStyleRangeIterator();
- while (e.hasNext())
- ranges[i++]= (StyleRange) e.next();
-
- text.setStyleRanges(ranges);
- }
-
-
-
-
- /**
- * Enumerates all the <code>StyleRange</code>s included in the presentation.
- */
- class FilterIterator implements Iterator {
-
- /** The index of the next style range to be enumerated */
- protected int fIndex;
- /** The upper bound of the indices of style ranges to be enumerated */
- protected int fLength;
- /** Indicates whether ranges similar to the default range should be enumerated */
- protected boolean fSkipDefaults;
- /** The result window */
- protected IRegion fWindow;
-
- /**
- * <code>skipDefaults</code> tells the enumeration to skip all those style ranges
- * which define the same style as the presentation's default style range.
- *
- * @param skipDefaults <code>false</code> if ranges similar to the default range should be enumerated
- */
- protected FilterIterator(boolean skipDefaults) {
-
- fSkipDefaults= skipDefaults;
-
- fWindow= fResultWindow;
- fIndex= getFirstIndexInWindow(fWindow);
- fLength= getFirstIndexAfterWindow(fWindow);
-
- if (fSkipDefaults)
- computeIndex();
- }
-
- /*
- * @see Iterator#next()
- */
- public Object next() {
- try {
- StyleRange r= (StyleRange) fRanges.get(fIndex++);
- return createWindowRelativeRange(fWindow, r);
- } catch (ArrayIndexOutOfBoundsException x) {
- throw new NoSuchElementException();
- } finally {
- if (fSkipDefaults)
- computeIndex();
- }
- }
-
- /*
- * @see Iterator#hasNext()
- */
- public boolean hasNext() {
- return fIndex < fLength;
- }
-
- /*
- * @see Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
-
- /**
- * Returns whether the given object should be skipped.
- *
- * @param o the object to be checked
- * @return <code>true</code> if the object should be skipped by the iterator
- */
- protected boolean skip(Object o) {
- StyleRange r= (StyleRange) o;
- return r.similarTo(fDefaultRange);
- }
-
- /**
- * Computes the index of the styled range that is the next to be enumerated.
- */
- protected void computeIndex() {
- while (fIndex < fLength && skip(fRanges.get(fIndex)))
- ++ fIndex;
- }
- }
-
- /** The style information for the range covered by the whole presentation */
- private StyleRange fDefaultRange;
- /** The member ranges of the presentation */
- private ArrayList fRanges;
- /** A clipping region against which the presentation can be clipped when asked for results */
- private IRegion fResultWindow;
- /**
- * The optional extent for this presentation.
- * @since 3.0
- */
- private IRegion fExtent;
-
-
- /**
- * Creates a new empty text presentation.
- */
- public TextPresentation() {
- fRanges= new ArrayList(50);
- }
-
- /**
- * Creates a new empty text presentation. <code>sizeHint</code> tells the
- * expected size of this presentation.
- *
- * @param sizeHint the expected size of this presentation
- */
- public TextPresentation(int sizeHint) {
- Assert.isTrue(sizeHint > 0);
- fRanges= new ArrayList(sizeHint);
- }
-
- /**
- * Creates a new empty text presentation with the given extent.
- * <code>sizeHint</code> tells the expected size of this presentation.
- *
- * @param extent the extent of the created <code>TextPresentation</code>
- * @param sizeHint the expected size of this presentation
- * @since 3.0
- */
- public TextPresentation(IRegion extent, int sizeHint) {
- this(sizeHint);
- Assert.isNotNull(extent);
- fExtent= extent;
- }
-
- /**
- * Sets the result window for this presentation. When dealing with
- * this presentation all ranges which are outside the result window
- * are ignored. For example, the size of the presentation is 0
- * when there is no range inside the window even if there are ranges
- * outside the window. All methods are aware of the result window.
- *
- * @param resultWindow the result window
- */
- public void setResultWindow(IRegion resultWindow) {
- fResultWindow= resultWindow;
- }
-
- /**
- * Set the default style range of this presentation.
- * The default style range defines the overall area covered
- * by this presentation and its style information.
- *
- * @param range the range describing the default region
- */
- public void setDefaultStyleRange(StyleRange range) {
- fDefaultRange= range;
- }
-
- /**
- * Returns this presentation's default style range. The returned <code>StyleRange</code>
- * is relative to the start of the result window.
- *
- * @return this presentation's default style range
- */
- public StyleRange getDefaultStyleRange() {
- StyleRange range= createWindowRelativeRange(fResultWindow, fDefaultRange);
- if (range == null)
- return null;
- else
- return (StyleRange)range.clone();
-
- }
-
- /**
- * Add the given range to the presentation. The range must be a
- * subrange of the presentation's default range.
- *
- * @param range the range to be added
- */
- public void addStyleRange(StyleRange range) {
- checkConsistency(range);
- fRanges.add(range);
- }
-
- /**
- * Replaces the given range in this presentation. The range must be a
- * subrange of the presentation's default range.
- *
- * @param range the range to be added
- * @since 3.0
- */
- public void replaceStyleRange(StyleRange range) {
- applyStyleRange(range, false);
- }
-
- /**
- * Merges the given range into this presentation. The range must be a
- * subrange of the presentation's default range.
- *
- * @param range the range to be added
- * @since 3.0
- */
- public void mergeStyleRange(StyleRange range) {
- applyStyleRange(range, true);
- }
-
- /**
- * Applies the given range to this presentation. The range must be a
- * subrange of the presentation's default range.
- *
- * @param range the range to be added
- * @param merge <code>true</code> if the style should be merged instead of replaced
- * @since 3.0
- */
- private void applyStyleRange(StyleRange range, boolean merge) {
- if (range.length == 0)
- return;
-
- checkConsistency(range);
-
- int start= range.start;
- int length= range.length;
- int end= start + length;
-
- if (fRanges.size() == 0) {
- StyleRange defaultRange= getDefaultStyleRange();
- if (defaultRange == null)
- defaultRange= range;
-
- defaultRange.start= start;
- defaultRange.length= length;
- applyStyle(range, defaultRange, merge);
- fRanges.add(defaultRange);
- } else {
- IRegion rangeRegion= new Region(start, length);
- int first= getFirstIndexInWindow(rangeRegion);
-
- if (first == fRanges.size()) {
- StyleRange defaultRange= getDefaultStyleRange();
- if (defaultRange == null)
- defaultRange= range;
- defaultRange.start= start;
- defaultRange.length= length;
- applyStyle(range, defaultRange, merge);
- fRanges.add(defaultRange);
- return;
- }
-
- int last= getFirstIndexAfterWindow(rangeRegion);
- for (int i= first; i < last && length > 0; i++) {
-
- StyleRange current= (StyleRange)fRanges.get(i);
- int currentStart= current.start;
- int currentEnd= currentStart + current.length;
-
- if (end <= currentStart) {
- fRanges.add(i, range);
- return;
- }
-
- if (start >= currentEnd)
- continue;
-
- StyleRange currentCopy= null;
- if (end < currentEnd)
- currentCopy= (StyleRange)current.clone();
-
- if (start < currentStart) {
- // Apply background to new default range and add it
- StyleRange defaultRange= getDefaultStyleRange();
- if (defaultRange == null)
- defaultRange= new StyleRange();
-
- defaultRange.start= start;
- defaultRange.length= currentStart - start;
- applyStyle(range, defaultRange, merge);
- fRanges.add(i, defaultRange);
- i++; last++;
-
-
- // Apply background to first part of current range
- current.length= Math.min(end, currentEnd) - currentStart;
- applyStyle(range, current, merge);
- }
-
- if (start >= currentStart) {
- // Shorten the current range
- current.length= start - currentStart;
-
- // Apply the background to the rest of the current range and add it
- if (current.length > 0) {
- current= (StyleRange)current.clone();
- i++; last++;
- fRanges.add(i, current);
- }
- applyStyle(range, current, merge);
- current.start= start;
- current.length= Math.min(end, currentEnd) - start;
- }
-
- if (end < currentEnd) {
- // Add rest of current range
- currentCopy.start= end;
- currentCopy.length= currentEnd - end;
- i++; last++;
- fRanges.add(i, currentCopy);
- }
-
- // Update range
- range.start= currentEnd;
- range.length= Math.max(end - currentEnd, 0);
- start= range.start;
- length= range.length;
- }
- if (length > 0) {
- // Apply background to new default range and add it
- StyleRange defaultRange= getDefaultStyleRange();
- if (defaultRange == null)
- defaultRange= range;
- defaultRange.start= start;
- defaultRange.length= end - start;
- defaultRange.background= range.background;
- fRanges.add(last, defaultRange);
- }
- }
- }
-
- /**
- * Replaces the given ranges in this presentation. Each range must be a
- * subrange of the presentation's default range. The ranges must be ordered
- * by increasing offset and must not overlap (but may be adjacent).
- *
- * @param ranges the ranges to be added
- * @since 3.0
- */
- public void replaceStyleRanges(StyleRange[] ranges) {
- applyStyleRanges(ranges, false);
- }
-
- /**
- * Merges the given ranges into this presentation. Each range must be a
- * subrange of the presentation's default range. The ranges must be ordered
- * by increasing offset and must not overlap (but may be adjacent).
- *
- * @param ranges the ranges to be added
- * @since 3.0
- */
- public void mergeStyleRanges(StyleRange[] ranges) {
- applyStyleRanges(ranges, true);
- }
-
- /**
- * Applies the given ranges to this presentation. Each range must be a
- * subrange of the presentation's default range. The ranges must be ordered
- * by increasing offset and must not overlap (but may be adjacent).
- *
- * @param ranges the ranges to be added
- * @param merge <code>true</code> if the style should be merged instead of replaced
- * @since 3.0
- */
- private void applyStyleRanges(StyleRange[] ranges, boolean merge) {
- int j= 0;
- ArrayList oldRanges= fRanges;
- ArrayList newRanges= new ArrayList(2*ranges.length + oldRanges.size());
- for (int i= 0, n= ranges.length; i < n; i++) {
- StyleRange range= ranges[i];
- fRanges= oldRanges; // for getFirstIndexAfterWindow(...)
- for (int m= getFirstIndexAfterWindow(new Region(range.start, range.length)); j < m; j++)
- newRanges.add(oldRanges.get(j));
- fRanges= newRanges; // for mergeStyleRange(...)
- applyStyleRange(range, merge);
- }
- for (int m= oldRanges.size(); j < m; j++)
- newRanges.add(oldRanges.get(j));
- fRanges= newRanges;
- }
-
- /**
- * Applies the template's style to the target.
- *
- * @param template the style range to be used as template
- * @param target the style range to which to apply the template
- * @param merge <code>true</code> if the style should be merged instead of replaced
- * @since 3.0
- */
- private void applyStyle(StyleRange template, StyleRange target, boolean merge) {
- if (merge) {
- if (template.foreground != null)
- target.foreground= template.foreground;
- if (template.background != null)
- target.background= template.background;
- target.fontStyle |= template.fontStyle;
- } else {
- target.foreground= template.foreground;
- target.background= template.background;
- target.fontStyle= template.fontStyle;
- }
- }
-
- /**
- * Checks whether the given range is a subrange of the presentation's
- * default style range.
- *
- * @param range the range to be checked
- * @exception IllegalArgumentAxception if range is not a subrange of the presentation's default range
- */
- private void checkConsistency(StyleRange range) {
-
- if (range == null)
- throw new IllegalArgumentException();
-
- if (fDefaultRange != null) {
-
- if (range.start < fDefaultRange.start)
- range.start= fDefaultRange.start;
-
- int defaultEnd= fDefaultRange.start + fDefaultRange.length;
- int end= range.start + range.length;
- if (end > defaultEnd)
- range.length -= (end - defaultEnd);
- }
- }
-
- /**
- * Returns the index of the first range which overlaps with the
- * specified window.
- *
- * @param window the window to be used for searching
- * @return the index of the first range overlapping with the window
- */
- private int getFirstIndexInWindow(IRegion window) {
- if (window != null) {
- int start= window.getOffset();
- int i= -1, j= fRanges.size();
- while (j - i > 1) {
- int k= (i + j) >> 1;
- StyleRange r= (StyleRange) fRanges.get(k);
- if (r.start + r.length > start)
- j= k;
- else
- i= k;
- }
- return j;
- }
- return 0;
- }
-
- /**
- * Returns the index of the first range which comes after the specified window and does
- * not overlap with this window.
- *
- * @param window the window to be used for searching
- * @return the index of the first range behind the window and not overlapping with the window
- */
- private int getFirstIndexAfterWindow(IRegion window) {
- if (window != null) {
- int end= window.getOffset() + window.getLength();
- int i= -1, j= fRanges.size();
- while (j - i > 1) {
- int k= (i + j) >> 1;
- StyleRange r= (StyleRange) fRanges.get(k);
- if (r.start < end)
- i= k;
- else
- j= k;
- }
- return j;
- }
- return fRanges.size();
- }
-
- /**
- * Returns a style range which is relative to the specified window and
- * appropriately clipped if necessary. The original style range is not
- * modified.
- *
- * @param window the reference window
- * @param range the absolute range
- * @return the window relative range based on the absolute range
- */
- private StyleRange createWindowRelativeRange(IRegion window, StyleRange range) {
- if (window == null || range == null)
- return range;
-
- int start= range.start - window.getOffset();
- if (start < 0)
- start= 0;
-
- int rangeEnd= range.start + range.length;
- int windowEnd= window.getOffset() + window.getLength();
- int end= (rangeEnd > windowEnd ? windowEnd : rangeEnd);
- end -= window.getOffset();
-
- StyleRange newRange= (StyleRange) range.clone();
- newRange.start= start;
- newRange.length= end - start;
- return newRange;
- }
-
- /**
- * Returns the region which is relative to the specified window and
- * appropriately clipped if necessary.
- *
- * @param coverage the absolute coverage
- * @return the window relative region based on the absolute coverage
- * @since 3.0
- */
- private IRegion createWindowRelativeRegion(IRegion coverage) {
- if (fResultWindow == null || coverage == null)
- return coverage;
-
- int start= coverage.getOffset() - fResultWindow.getOffset();
- if (start < 0)
- start= 0;
-
- int rangeEnd= coverage.getOffset() + coverage.getLength();
- int windowEnd= fResultWindow.getOffset() + fResultWindow.getLength();
- int end= (rangeEnd > windowEnd ? windowEnd : rangeEnd);
- end -= fResultWindow.getOffset();
-
- return new Region(start, end - start);
- }
-
- /**
- * Returns an iterator which enumerates all style ranged which define a style
- * different from the presentation's default style range. The default style range
- * is not enumerated.
- *
- * @return a style range iterator
- */
- public Iterator getNonDefaultStyleRangeIterator() {
- return new FilterIterator(fDefaultRange != null);
- }
-
- /**
- * Returns an iterator which enumerates all style ranges of this presentation
- * except the default style range. The returned <code>StyleRange</code>s
- * are relative to the start of the presentation's result window.
- *
- * @return a style range iterator
- */
- public Iterator getAllStyleRangeIterator() {
- return new FilterIterator(false);
- }
-
- /**
- * Returns whether this collection contains any style range including
- * the default style range.
- *
- * @return <code>true</code> if there is no style range in this presentation
- */
- public boolean isEmpty() {
- return (fDefaultRange == null && getDenumerableRanges() == 0);
- }
-
- /**
- * Returns the number of style ranges in the presentation not counting the default
- * style range.
- *
- * @return the number of style ranges in the presentation excluding the default style range
- */
- public int getDenumerableRanges() {
- int size= getFirstIndexAfterWindow(fResultWindow) - getFirstIndexInWindow(fResultWindow);
- return (size < 0 ? 0 : size);
- }
-
- /**
- * Returns the style range with the smallest offset ignoring the default style range or null
- * if the presentation is empty.
- *
- * @return the style range with the smallest offset different from the default style range
- */
- public StyleRange getFirstStyleRange() {
- try {
-
- StyleRange range= (StyleRange) fRanges.get(getFirstIndexInWindow(fResultWindow));
- return createWindowRelativeRange(fResultWindow, range);
-
- } catch (NoSuchElementException x) {
- }
-
- return null;
- }
-
- /**
- * Returns the style range with the highest offset ignoring the default style range.
- *
- * @return the style range with the highest offset different from the default style range
- */
- public StyleRange getLastStyleRange() {
- try {
-
- StyleRange range= (StyleRange) fRanges.get(getFirstIndexAfterWindow(fResultWindow) - 1);
- return createWindowRelativeRange(fResultWindow, range);
-
- } catch (NoSuchElementException x) {
- }
-
- return null;
- }
-
- /**
- * Returns the coverage of this presentation as clipped by the presentation's
- * result window.
- *
- * @return the coverage of this presentation
- */
- public IRegion getCoverage() {
-
- if (fDefaultRange != null) {
- StyleRange range= getDefaultStyleRange();
- return new Region(range.start, range.length);
- }
-
- StyleRange first= getFirstStyleRange();
- StyleRange last= getLastStyleRange();
-
- if (first == null || last == null)
- return null;
-
- return new Region(first.start, last.start - first. start + last.length);
- }
-
- /**
- * Returns the extent of this presentation clipped by the
- * presentation's result window.
- *
- * @return the clipped extent
- * @since 3.0
- */
- public IRegion getExtent() {
- if (fExtent != null)
- return createWindowRelativeRegion(fExtent);
- else
- return getCoverage();
- }
-
- /**
- * Clears this presentation by resetting all applied changes.
- * @since 2.0
- */
- public void clear() {
- fDefaultRange= null;
- fResultWindow= null;
- fRanges.clear();
- }
-
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
deleted file mode 100644
index 1c89cef7087..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextSelection.java
+++ /dev/null
@@ -1,189 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text;
-
-
-
-
-/**
- * Standard implementation of <code>ITextSelection</code>.
- * Makes advantage of the weak contract of correctness of its
- * interface. If generated from a selection provider, it only
- * remembers its offset and length and computes the remaining
- * information on request.
- */
-public class TextSelection implements ITextSelection {
-
- /** Internal empty text selection */
- private final static ITextSelection NULL= new TextSelection();
-
- /**
- * Returns a shared instance of an empty text selection.
- *
- * @return a shared instance of an empty text selection
- */
- public static ITextSelection emptySelection() {
- return NULL;
- }
-
- /** Document which delivers the data of the selection */
- private IDocument fDocument;
- /** Offset of the selection */
- private int fOffset;
- /** Length of the selection */
- private int fLength;
-
-
- /**
- * Creates an empty text selection.
- */
- private TextSelection() {
- this(null, -1, -1);
- }
-
- /**
- * Creates a text selection for the given range. This
- * selection object describes generically a text range and
- * is intended to be an argument for the <code>setSelection</code>
- * method of selection providers.
- *
- * @param offset the offset of the range
- * @param length the length of the range
- */
- public TextSelection(int offset, int length) {
- this(null, offset, length);
- }
-
- /**
- * Creates a text selection for the given range of the given document.
- * This selection object is created by selection providers in responds
- * <code>getSelection</code>.
- *
- * @param document the document whose text range is selected in a viewer
- * @param offset the offset of the selected range
- * @param length the length of the selected range
- */
- public TextSelection(IDocument document, int offset, int length) {
- fDocument= document;
- fOffset= offset;
- fLength= length;
- }
-
- /**
- *
- * Returns true if the offset and length are smaller than 0.
- * A selection of length 0, is a valid text selection as it
- * describes, e.g., the cursor position in a viewer.
- *
- * @return <code>true</code> if this selection is empty
- * @see org.eclipse.jface.viewers.ISelection#isEmpty()
- */
- public boolean isEmpty() {
- return fOffset < 0 || fLength < 0;
- }
-
- /*
- * @see ITextSelection#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /*
- * @see ITextSelection#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see ITextSelection#getStartLine()
- */
- public int getStartLine() {
-
- try {
- if (fDocument != null)
- return fDocument.getLineOfOffset(fOffset);
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see ITextSelection#getEndLine()
- */
- public int getEndLine() {
- try {
- if (fDocument != null) {
- int endOffset= fOffset + fLength;
- if (fLength != 0)
- endOffset--;
- return fDocument.getLineOfOffset(endOffset);
- }
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see ITextSelection#getText()
- */
- public String getText() {
- try {
- if (fDocument != null)
- return fDocument.get(fOffset, fLength);
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /*
- * @see java.lang.Object#equals(Object)
- */
- public boolean equals(Object obj) {
- if (obj == this)
- return true;
-
- if (obj == null || getClass() != obj.getClass())
- return false;
-
- TextSelection s= (TextSelection) obj;
- boolean sameRange= (s.fOffset == fOffset && s.fLength == fLength);
- if (sameRange) {
-
- if (s.fDocument == null && fDocument == null)
- return true;
- if (s.fDocument == null || fDocument == null)
- return false;
-
- try {
- String sContent= s.fDocument.get(fOffset, fLength);
- String content= fDocument.get(fOffset, fLength);
- return sContent.equals(content);
- } catch (BadLocationException x) {
- }
- }
-
- return false;
- }
-
- /*
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- int low= fDocument != null ? fDocument.hashCode() : 0;
- return (fOffset << 24) | (fLength << 16) | low;
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
deleted file mode 100644
index 7884aa6499d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewer.java
+++ /dev/null
@@ -1,4858 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.PatternSyntaxException;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.LineBackgroundEvent;
-import org.eclipse.swt.custom.LineBackgroundListener;
-import org.eclipse.swt.custom.ST;
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.TraverseEvent;
-import org.eclipse.swt.events.TraverseListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.events.VerifyListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.printing.PrintDialog;
-import org.eclipse.swt.printing.Printer;
-import org.eclipse.swt.printing.PrinterData;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.ScrollBar;
-
-import org.eclipse.jface.viewers.IPostSelectionProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.ISelectionProvider;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-import org.eclipse.jface.viewers.Viewer;
-
-import org.eclipse.jface.text.projection.ChildDocument;
-import org.eclipse.jface.text.projection.ChildDocumentManager;
-
-/**
- * SWT based implementation of <code>ITextViewer</code>. Once the viewer and its SWT control
- * have been created the viewer can only indirectly be disposed by disposing its SWT control.<p>
- * Clients are supposed to instantiate a text viewer and subsequently to communicate with it
- * exclusively using the <code>ITextViewer</code> interface or any of the implemented extension
- * interfaces. <p>
- * A text viewer serves as text operation target. It only partially supports the external control of
- * the enable state of its text operations. A text viewer is also a widget token owner. Anything that
- * wants to display an overlay window on top of a text viewer should implement the
- * <code>IWidgetTokenKeeper</code> interface and participate in the widget token negotiation between
- * the text viewer and all its potential widget token keepers.<p>
- * Clients should not subclass this class as it is rather likely that subclasses will be broken by
- * future releases.
- *
- * @see ITextViewer
- */
-public class TextViewer extends Viewer implements
- ITextViewer, ITextViewerExtension, ITextViewerExtension2, ITextViewerExtension4,
- ITextOperationTarget, ITextOperationTargetExtension,
- IWidgetTokenOwner, IWidgetTokenOwnerExtension, IPostSelectionProvider {
-
- /** Internal flag to indicate the debug state. */
- public static boolean TRACE_ERRORS= false;
-
- /**
- * Represents a replace command that brings the text viewer's text widget
- * back in sync with text viewer's document after the document has been changed.
- */
- protected class WidgetCommand {
-
- /** The document event encapsulated by this command. */
- public DocumentEvent event;
- /** The start and length fields of <code>event</code>. */
- public int start, length;
- /** The inserted and replaced text segments of <code>event</code>. */
- public String text, preservedText;
-
- /**
- * Translates a document event into the presentation coordinates of this text viewer.
- *
- * @param e the event to be translated
- */
- public void setEvent(DocumentEvent e) {
-
- event= e;
-
- start= e.getOffset();
- length= e.getLength();
- text= e.getText();
-
- if (length != 0) {
- try {
-
- if (e instanceof SlaveDocumentEvent) {
- SlaveDocumentEvent slave= (SlaveDocumentEvent) e;
- DocumentEvent master= slave.getMasterEvent();
- if (master != null)
- preservedText= master.getDocument().get(master.getOffset(), master.getLength());
- } else {
- preservedText= e.getDocument().get(e.getOffset(), e.getLength());
- }
-
- } catch (BadLocationException x) {
- preservedText= null;
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.WidgetCommand.setEvent")); //$NON-NLS-1$
- }
- } else
- preservedText= null;
- }
- }
-
- /**
- * Connects a text double click strategy to this viewer's text widget.
- * Calls the double click strategy when the mouse has been double clicked
- * inside the text editor.
- */
- class TextDoubleClickStrategyConnector extends MouseAdapter {
-
- /** Internal flag to remember that a double clicked occurred. */
- private boolean fDoubleClicked= false;
-
- public TextDoubleClickStrategyConnector() {
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- fDoubleClicked= true;
- }
-
- /*
- * @see MouseListener#mouseUp(MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- if (fDoubleClicked) {
- fDoubleClicked= false;
- ITextDoubleClickStrategy s= (ITextDoubleClickStrategy) selectContentTypePlugin(getSelectedRange().x, fDoubleClickStrategies);
- if (s != null)
- s.doubleClicked(TextViewer.this);
- }
- }
- }
-
- /**
- * Monitors the area of the viewer's document that is visible in the viewer.
- * If the area might have changed, it informs the text viewer about this
- * potential change and its origin. The origin is internally used for optimization
- * purposes.
- */
- class ViewportGuard extends MouseAdapter
- implements ControlListener, KeyListener, SelectionListener {
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent e) {
- updateViewportListeners(RESIZE);
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent e) {
- }
-
- /*
- * @see KeyListener#keyReleased
- */
- public void keyReleased(KeyEvent e) {
- updateViewportListeners(KEY);
- }
-
- /*
- * @see KeyListener#keyPressed
- */
- public void keyPressed(KeyEvent e) {
- updateViewportListeners(KEY);
- }
-
- /*
- * @see MouseListener#mouseUp
- */
- public void mouseUp(MouseEvent e) {
- if (fTextWidget != null)
- fTextWidget.removeSelectionListener(this);
- updateViewportListeners(MOUSE_END);
- }
-
- /*
- * @see MouseListener#mouseDown
- */
- public void mouseDown(MouseEvent e) {
- if (fTextWidget != null)
- fTextWidget.addSelectionListener(this);
- }
-
- /*
- * @see SelectionListener#widgetSelected
- */
- public void widgetSelected(SelectionEvent e) {
- if (e.widget == fScroller)
- updateViewportListeners(SCROLLER);
- else
- updateViewportListeners(MOUSE);
- }
-
- /*
- * @see SelectionListener#widgetDefaultSelected
- */
- public void widgetDefaultSelected(SelectionEvent e) {}
- }
-
- /**
- * This position updater is used to keep the selection during text shift operations.
- */
- static class ShiftPositionUpdater extends DefaultPositionUpdater {
-
- /**
- * Creates the position updater for the given category.
- *
- * @param category the category this updater takes care of
- */
- protected ShiftPositionUpdater(String category) {
- super(category);
- }
-
- /**
- * If an insertion happens at the selection's start offset,
- * the position is extended rather than shifted.
- */
- protected void adaptToInsert() {
-
- int myStart= fPosition.offset;
- int myEnd= fPosition.offset + fPosition.length -1;
- myEnd= Math.max(myStart, myEnd);
-
- int yoursStart= fOffset;
- int yoursEnd= fOffset + fReplaceLength -1;
- yoursEnd= Math.max(yoursStart, yoursEnd);
-
- if (myEnd < yoursStart)
- return;
-
- if (myStart <= yoursStart) {
- fPosition.length += fReplaceLength;
- return;
- }
-
- if (myStart > yoursStart)
- fPosition.offset += fReplaceLength;
- }
- }
-
- /**
- * Internal document listener on the visible document.
- */
- class VisibleDocumentListener implements IDocumentListener {
-
- /*
- * @see IDocumentListener#documentAboutToBeChanged
- */
- public void documentAboutToBeChanged(DocumentEvent e) {
- if (e.getDocument() == getVisibleDocument())
- fWidgetCommand.setEvent(e);
- handleVisibleDocumentAboutToBeChanged(e);
- }
-
- /*
- * @see IDocumentListener#documentChanged
- */
- public void documentChanged(DocumentEvent e) {
- if (fWidgetCommand.event == e)
- updateTextListeners(fWidgetCommand);
- fLastSentSelectionChange= null;
- handleVisibleDocumentChanged(e);
- }
- }
-
-
- /**
- * Internal verify listener.
- */
- class TextVerifyListener implements VerifyListener {
-
- /**
- * Indicates whether verify events are forwarded or ignored.
- * @since 2.0
- */
- private boolean fForward= true;
-
- /**
- * Tells the listener to forward received events.
- *
- * @param forward <code>true</code> if forwarding should be enabled.
- * @since 2.0
- */
- public void forward(boolean forward) {
- fForward= forward;
- }
-
- /*
- * @see VerifyListener#verifyText(VerifyEvent)
- */
- public void verifyText(VerifyEvent e) {
- if (fForward)
- handleVerifyEvent(e);
- }
- }
-
- /**
- * The viewer's manager responsible for registered verify key listeners.
- * Uses batches rather than robust iterators because of performance issues.
- * <p>
- * The implementation is reentrant, i.e. installed listeners may trigger
- * further <code>VerifyKeyEvent</code>s that may cause other listeners to be
- * installed, but not thread safe.
- * </p>
- * @since 2.0
- */
- class VerifyKeyListenersManager implements VerifyKeyListener {
-
- /**
- * Represents a batched addListener/removeListener command.
- */
- class Batch {
- /** The index at which to insert the listener. */
- int index;
- /** The listener to be inserted. */
- VerifyKeyListener listener;
-
- /**
- * Creates a new batch containing the given listener for the given index.
- *
- * @param l the listener to be added
- * @param i the index at which to insert the listener
- */
- public Batch(VerifyKeyListener l, int i) {
- listener= l;
- index= i;
- }
- }
-
- /** List of registered verify key listeners. */
- private List fListeners= new ArrayList();
- /** List of pending batches. */
- private List fBatched= new ArrayList();
- /** The reentrance count. */
- private int fReentranceCount= 0;
-
- /*
- * @see VerifyKeyListener#verifyKey(VerifyEvent)
- */
- public void verifyKey(VerifyEvent event) {
- if (fListeners.isEmpty())
- return;
-
- try {
- fReentranceCount++;
- Iterator iterator= fListeners.iterator();
- while (iterator.hasNext() && event.doit) {
- VerifyKeyListener listener= (VerifyKeyListener) iterator.next();
- listener.verifyKey(event); // we might trigger reentrant calls on GTK
- }
- } finally {
- fReentranceCount--;
- }
- if (fReentranceCount == 0)
- processBatchedRequests();
- }
-
- /**
- * Processes the pending batched requests.
- */
- private void processBatchedRequests() {
- if (!fBatched.isEmpty()) {
- Iterator e= fBatched.iterator();
- while (e.hasNext()) {
- Batch batch= (Batch) e.next();
- insertListener(batch.listener, batch.index);
- }
- fBatched.clear();
- }
- }
-
- /**
- * Returns the number of registered verify key listeners.
- *
- * @return the number of registered verify key listeners
- */
- public int numberOfListeners() {
- return fListeners.size();
- }
-
- /**
- * Inserts the given listener at the given index or moves it
- * to that index.
- *
- * @param listener the listener to be inserted
- * @param index the index of the listener or -1 for remove
- */
- public void insertListener(VerifyKeyListener listener, int index) {
-
- if (index == -1) {
- removeListener(listener);
- } else if (listener != null) {
-
- if (fReentranceCount > 0) {
-
- fBatched.add(new Batch(listener, index));
-
- } else {
-
- int idx= -1;
-
- // find index based on identity
- int size= fListeners.size();
- for (int i= 0; i < size; i++) {
- if (listener == fListeners.get(i)) {
- idx= i;
- break;
- }
- }
-
- // move or add it
- if (idx != index) {
-
- if (idx != -1)
- fListeners.remove(idx);
-
- if (index > fListeners.size())
- fListeners.add(listener);
- else
- fListeners.add(index, listener);
- }
-
- if (size == 0) // checking old size, i.e. current size == size + 1
- install();
- }
- }
- }
-
- /**
- * Removes the given listener.
- *
- * @param listener the listener to be removed
- */
- public void removeListener(VerifyKeyListener listener) {
- if (listener == null)
- return;
-
- if (fReentranceCount > 0) {
-
- fBatched.add(new Batch(listener, -1));
-
- } else {
-
- int size= fListeners.size();
- for (int i= 0; i < size; i++) {
- if (listener == fListeners.get(i)) {
- fListeners.remove(i);
- if (size == 1) // checking old size, i.e. current size == size - 1
- uninstall();
- return;
- }
- }
- }
- }
-
- /**
- * Installs this manager.
- */
- private void install() {
- StyledText textWidget= getTextWidget();
- if (textWidget != null && !textWidget.isDisposed())
- textWidget.addVerifyKeyListener(this);
- }
-
- /**
- * Uninstalls this manager.
- */
- private void uninstall() {
- StyledText textWidget= getTextWidget();
- if (textWidget != null && !textWidget.isDisposed())
- textWidget.removeVerifyKeyListener(this);
- }
- }
-
-
- /**
- * Reification of a range in which a find replace operation is performed. This range is visually
- * highlighted in the viewer as long as the replace operation is in progress.
- *
- * @since 2.0
- */
- class FindReplaceRange implements LineBackgroundListener, ITextListener, IPositionUpdater {
-
- /** Internal name for the position category used to update the range. */
- private final static String RANGE_CATEGORY= "org.eclipse.jface.text.TextViewer.find.range"; //$NON-NLS-1$
-
- /** The highlight color of this range. */
- private Color fHighlightColor;
- /** The position used to lively update this range's extent. */
- private Position fPosition;
-
- /** Creates a new find/replace range with the given extent.
- *
- * @param range the extent of this range
- */
- public FindReplaceRange(IRegion range) {
- setRange(range);
- }
-
- /**
- * Sets the extent of this range.
- *
- * @param range the extent of this range
- */
- public void setRange(IRegion range) {
- fPosition= new Position(range.getOffset(), range.getLength());
- }
-
- /**
- * Returns the extent of this range.
- *
- * @return the extent of this range
- */
- public IRegion getRange() {
- return new Region(fPosition.getOffset(), fPosition.getLength());
- }
-
- /**
- * Sets the highlight color of this range. Causes the range to be redrawn.
- *
- * @param color the highlight color
- */
- public void setHighlightColor(Color color) {
- fHighlightColor= color;
- paint();
- }
-
- /*
- * @see LineBackgroundListener#lineGetBackground(LineBackgroundEvent)
- * @since 2.0
- */
- public void lineGetBackground(LineBackgroundEvent event) {
- /* Don't use cached line information because of patched redrawing events. */
-
- if (fTextWidget != null) {
- int offset= widgetOffset2ModelOffset(event.lineOffset);
- if (fPosition.includes(offset))
- event.lineBackground= fHighlightColor;
- }
- }
-
- /**
- * Installs this range. The range registers itself as background
- * line painter and text listener. Also, it creates a category with the
- * viewer's document to maintain its own extent.
- */
- public void install() {
- TextViewer.this.addTextListener(this);
- fTextWidget.addLineBackgroundListener(this);
-
- IDocument document= TextViewer.this.getDocument();
- try {
- document.addPositionCategory(RANGE_CATEGORY);
- document.addPosition(RANGE_CATEGORY, fPosition);
- document.addPositionUpdater(this);
- } catch (BadPositionCategoryException e) {
- // should not happen
- } catch (BadLocationException e) {
- // should not happen
- }
-
- paint();
- }
-
- /**
- * Uninstalls this range.
- * @see #install()
- */
- public void uninstall() {
-
- // http://bugs.eclipse.org/bugs/show_bug.cgi?id=19612
-
- IDocument document= TextViewer.this.getDocument();
- if (document != null) {
- document.removePositionUpdater(this);
- document.removePosition(fPosition);
- }
-
- if (fTextWidget != null && !fTextWidget.isDisposed())
- fTextWidget.removeLineBackgroundListener(this);
-
- TextViewer.this.removeTextListener(this);
-
- clear();
- }
-
- /**
- * Clears the highlighting of this range.
- */
- private void clear() {
- if (fTextWidget != null && !fTextWidget.isDisposed())
- fTextWidget.redraw();
- }
-
- /**
- * Paints the highlighting of this range.
- */
- private void paint() {
-
- IRegion widgetRegion= modelRange2WidgetRange(fPosition);
- int offset= widgetRegion.getOffset();
- int length= widgetRegion.getLength();
-
- int count= fTextWidget.getCharCount();
- if (offset + length >= count) {
- length= count - offset; // clip
-
- Point upperLeft= fTextWidget.getLocationAtOffset(offset);
- Point lowerRight= fTextWidget.getLocationAtOffset(offset + length);
- int width= fTextWidget.getClientArea().width;
- int height= fTextWidget.getLineHeight() + lowerRight.y - upperLeft.y;
- fTextWidget.redraw(upperLeft.x, upperLeft.y, width, height, false);
- }
-
- fTextWidget.redrawRange(offset, length, true);
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- * @since 2.0
- */
- public void textChanged(TextEvent event) {
- if (event.getViewerRedrawState())
- paint();
- }
-
- /*
- * @see IPositionUpdater#update(DocumentEvent)
- * @since 2.0
- */
- public void update(DocumentEvent event) {
- int offset= event.getOffset();
- int length= event.getLength();
- int delta= event.getText().length() - length;
-
- if (offset < fPosition.getOffset())
- fPosition.setOffset(fPosition.getOffset() + delta);
- else if (offset < fPosition.getOffset() + fPosition.getLength())
- fPosition.setLength(fPosition.getLength() + delta);
- }
- }
-
- /**
- * This viewer's find/replace target.
- */
- class FindReplaceTarget implements IFindReplaceTarget, IFindReplaceTargetExtension, IFindReplaceTargetExtension3 {
-
- /** The range for this target. */
- private FindReplaceRange fRange;
- /** The highlight color of the range of this target. */
- private Color fScopeHighlightColor;
- /** The document partitioner remembered in case of a "Replace All". */
- private Map fRememberedPartitioners;
-
- /*
- * @see IFindReplaceTarget#getSelectionText()
- */
- public String getSelectionText() {
- Point s= TextViewer.this.getSelectedRange();
- if (s.x > -1 && s.y > -1) {
- try {
- IDocument document= TextViewer.this.getDocument();
- return document.get(s.x, s.y);
- } catch (BadLocationException x) {
- }
- }
- return null;
- }
-
- /*
- * @see IFindReplaceTarget#replaceSelection(String)
- */
- public void replaceSelection(String text) {
- replaceSelection(text, false);
- }
-
- /*
- * @see IFindReplaceTarget#replaceSelection(String)
- */
- public void replaceSelection(String text, boolean regExReplace) {
- Point s= TextViewer.this.getSelectedRange();
- if (s.x > -1 && s.y > -1) {
- try {
- IRegion matchRegion= TextViewer.this.getFindReplaceDocumentAdapter().replace(text, regExReplace);
- int length= -1;
- if (matchRegion != null)
- length= matchRegion.getLength();
-
- if (text != null && length > 0)
- TextViewer.this.setSelectedRange(s.x, length);
- } catch (BadLocationException x) {
- }
- }
- }
-
- /*
- * @see IFindReplaceTarget#isEditable()
- */
- public boolean isEditable() {
- return TextViewer.this.isEditable();
- }
-
- /*
- * @see IFindReplaceTarget#getSelection()
- */
- public Point getSelection() {
- Point modelSelection= TextViewer.this.getSelectedRange();
- return modelSelection2WidgetSelection(modelSelection);
- }
-
- /*
- * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean)
- */
- public int findAndSelect(int widgetOffset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord) {
- try {
- return findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord, false);
- } catch (PatternSyntaxException x) {
- return -1;
- }
- }
-
- /*
- * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean)
- */
- public int findAndSelect(int widgetOffset, String findString, boolean searchForward, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
-
- int modelOffset= widgetOffset == -1 ? -1 : widgetOffset2ModelOffset(widgetOffset);
-
- if (fRange != null) {
- IRegion range= fRange.getRange();
- modelOffset= TextViewer.this.findAndSelectInRange(modelOffset, findString, searchForward, caseSensitive, wholeWord, range.getOffset(), range.getLength(), regExSearch);
- } else {
- modelOffset= TextViewer.this.findAndSelect(modelOffset, findString, searchForward, caseSensitive, wholeWord, regExSearch);
- }
-
- widgetOffset= modelOffset == -1 ? -1 : modelOffset2WidgetOffset(modelOffset);
- return widgetOffset;
- }
-
- /*
- * @see IFindReplaceTarget#canPerformFind()
- */
- public boolean canPerformFind() {
- return TextViewer.this.canPerformFind();
- }
-
- /*
- * @see IFindReplaceTargetExtension#beginSession()
- * @since 2.0
- */
- public void beginSession() {
- fRange= null;
- }
-
- /*
- * @see IFindReplaceTargetExtension#endSession()
- * @since 2.0
- */
- public void endSession() {
- if (fRange != null) {
- fRange.uninstall();
- fRange= null;
- }
- }
-
- /*
- * @see IFindReplaceTargetExtension#getScope()
- * @since 2.0
- */
- public IRegion getScope() {
- return fRange == null ? null : fRange.getRange();
- }
-
- /*
- * @see IFindReplaceTargetExtension#getLineSelection()
- * @since 2.0
- */
- public Point getLineSelection() {
- Point point= TextViewer.this.getSelectedRange();
-
- try {
- IDocument document= TextViewer.this.getDocument();
-
- // beginning of line
- int line= document.getLineOfOffset(point.x);
- int offset= document.getLineOffset(line);
-
- // end of line
- IRegion lastLineInfo= document.getLineInformationOfOffset(point.x + point.y);
- int lastLine= document.getLineOfOffset(point.x + point.y);
- int length;
- if (lastLineInfo.getOffset() == point.x + point.y && lastLine > 0)
- length= document.getLineOffset(lastLine - 1) + document.getLineLength(lastLine - 1) - offset;
- else
- length= lastLineInfo.getOffset() + lastLineInfo.getLength() - offset;
-
- return new Point(offset, length);
-
- } catch (BadLocationException e) {
- // should not happen
- return new Point(point.x, 0);
- }
- }
-
- /*
- * @see IFindReplaceTargetExtension#setSelection(int, int)
- * @since 2.0
- */
- public void setSelection(int modelOffset, int modelLength) {
- TextViewer.this.setSelectedRange(modelOffset, modelLength);
- }
-
- /*
- * @see IFindReplaceTargetExtension#setScope(IRegion)
- * @since 2.0
- */
- public void setScope(IRegion scope) {
- if (fRange != null)
- fRange.uninstall();
-
- if (scope == null) {
- fRange= null;
- return;
- }
-
- fRange= new FindReplaceRange(scope);
- fRange.setHighlightColor(fScopeHighlightColor);
- fRange.install();
- }
-
- /*
- * @see IFindReplaceTargetExtension#setScopeHighlightColor(Color)
- * @since 2.0
- */
- public void setScopeHighlightColor(Color color) {
- if (fRange != null)
- fRange.setHighlightColor(color);
- fScopeHighlightColor= color;
- }
-
- /*
- * @see IFindReplaceTargetExtension#setReplaceAllMode(boolean)
- * @since 2.0
- */
- public void setReplaceAllMode(boolean replaceAll) {
-
- // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18232
-
- if (replaceAll) {
-
- TextViewer.this.setRedraw(false);
- TextViewer.this.startSequentialRewriteMode(false);
-
- if (fUndoManager != null)
- fUndoManager.beginCompoundChange();
-
- IDocument document= TextViewer.this.getDocument();
- fRememberedPartitioners= TextUtilities.removeDocumentPartitioners(document);
-
- } else {
-
- TextViewer.this.setRedraw(true);
- TextViewer.this.stopSequentialRewriteMode();
-
- if (fUndoManager != null)
- fUndoManager.endCompoundChange();
-
- if (fRememberedPartitioners != null) {
- IDocument document= TextViewer.this.getDocument();
- TextUtilities.addDocumentPartitioners(document, fRememberedPartitioners);
- }
- }
- }
- }
-
-
- /**
- * The viewer's rewrite target.
- * @since 2.0
- */
- class RewriteTarget implements IRewriteTarget {
-
- /*
- * @see org.eclipse.jface.text.IRewriteTarget#beginCompoundChange()
- */
- public void beginCompoundChange() {
- if (fUndoManager != null)
- fUndoManager.beginCompoundChange();
- }
-
- /*
- * @see org.eclipse.jface.text.IRewriteTarget#endCompoundChange()
- */
- public void endCompoundChange() {
- if (fUndoManager != null)
- fUndoManager.endCompoundChange();
- }
-
- /*
- * @see org.eclipse.jface.text.IRewriteTarget#getDocument()
- */
- public IDocument getDocument() {
- return TextViewer.this.getDocument();
- }
-
- /*
- * @see org.eclipse.jface.text.IRewriteTarget#setRedraw(boolean)
- */
- public void setRedraw(boolean redraw) {
- TextViewer.this.setRedraw(redraw);
- }
- }
-
- /**
- * Value object used as key in the text hover configuration table. It is
- * modifiable only inside this compilation unit to allow the reuse of created
- * objects for efficiency reasons
- *
- * @since 2.1
- */
- protected class TextHoverKey {
-
- /** The content type this key belongs to */
- private String fContentType;
- /** The state mask */
- private int fStateMask;
-
- /**
- * Creates a new text hover key for the given content type and state mask.
- *
- * @param contentType the content type
- * @param stateMask the state mask
- */
- protected TextHoverKey(String contentType, int stateMask) {
- Assert.isNotNull(contentType);
- fContentType= contentType;
- fStateMask= stateMask;
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object obj) {
- if (obj == null || obj.getClass() != getClass())
- return false;
- TextHoverKey textHoverKey= (TextHoverKey)obj;
- return textHoverKey.fContentType.equals(fContentType) && textHoverKey.fStateMask == fStateMask;
- }
-
- /*
- * @see java.lang.Object#hashCode()
- */
- public int hashCode() {
- return fStateMask << 16 | fContentType.hashCode();
- }
-
- /**
- * Sets the state mask of this text hover key.
- *
- * @param stateMask the state mask
- */
- private void setStateMask(int stateMask) {
- fStateMask= stateMask;
- }
- }
-
- /**
- * A position reflecting a viewer selection and the selection anchor.
- * The anchor is represented by the caret.
- *
- * @since 2.1
- */
- static class SelectionPosition extends Position {
-
- /** The flag indicating the anchor of this selection */
- private boolean reverse;
-
- /**
- * Creates a new selection position for the specified selection.
- *
- * @param point the specified selection
- */
- public SelectionPosition(Point point) {
- super();
- reverse= point.y < 0;
- if (reverse) {
- offset= point.x + point.y;
- length= -point.y;
- } else {
- offset= point.x;
- length= point.y;
- }
- }
-
- /**
- * Returns the selection in a format where the selection length
- * is always non-negative.
- *
- * @return the normalized selection
- */
- public Point getNormalizedSelection() {
- return new Point(offset, length);
- }
-
- /**
- * Returns the selection reflecting its anchor.
- *
- * @return the selection reflecting the selection anchor.
- */
- public Point getSelection() {
- return reverse ? new Point(offset - length, -length) : new Point(offset, length);
- }
- }
-
- /**
- * Internal cursor listener i.e. aggregation of mouse and key listener.
- *
- * @since 3.0
- */
- private class CursorListener implements KeyListener, MouseListener {
-
- /**
- * Installs this cursor listener.
- */
- private void install() {
- if (fTextWidget != null && !fTextWidget.isDisposed()) {
- fTextWidget.addKeyListener(this);
- fTextWidget.addMouseListener(this);
- }
- }
-
- /**
- * Uninstalls this cursor listener.
- */
- private void uninstall() {
- if (fTextWidget != null && !fTextWidget.isDisposed()) {
- fTextWidget.removeKeyListener(this);
- fTextWidget.removeMouseListener(this);
- }
- }
-
- /*
- * @see KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
- */
- public void keyPressed(KeyEvent event) {
- }
-
- /*
- * @see KeyListener#keyPressed(org.eclipse.swt.events.KeyEvent)
- */
- public void keyReleased(KeyEvent e) {
- if (fTextWidget.getSelectionCount() == 0)
- queuePostSelectionChanged();
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDown(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent event) {
- if (fTextWidget.getSelectionCount() == 0)
- queuePostSelectionChanged();
- }
- }
-
- /**
- * Identifies the scrollbars as originators of a view port change.
- */
- protected static final int SCROLLER= 1;
- /**
- * Identifies mouse moves as originators of a view port change.
- */
- protected static final int MOUSE= 2;
- /**
- * Identifies mouse button up as originator of a view port change.
- */
- protected static final int MOUSE_END= 3;
- /**
- * Identifies key strokes as originators of a view port change.
- */
- protected static final int KEY= 4;
- /**
- * Identifies window resizing as originator of a view port change.
- */
- protected static final int RESIZE= 5;
- /**
- * Identifies internal reasons as originators of a view port change.
- */
- protected static final int INTERNAL= 6;
-
- /** Internal name of the position category used selection preservation during shift. */
- protected static final String SHIFTING= "__TextViewer_shifting"; //$NON-NLS-1$
-
- /** The viewer's text widget */
- private StyledText fTextWidget;
- /** The viewer's input document */
- private IDocument fDocument;
- /** The viewer's visible document */
- private IDocument fVisibleDocument;
- /** The viewer's document adapter */
- private IDocumentAdapter fDocumentAdapter;
- /** The slave document manager */
- private ISlaveDocumentManager fSlaveDocumentManager;
- /** The text viewer's double click strategies connector */
- private TextDoubleClickStrategyConnector fDoubleClickStrategyConnector;
- /**
- * The text viewer's hovering controller
- * @since 2.0
- */
- private TextViewerHoverManager fTextHoverManager;
- /** The text viewer's view port guard */
- private ViewportGuard fViewportGuard;
- /** Caches the graphical coordinate of the first visible line */
- private int fTopInset= 0;
- /** The most recent document modification as widget command */
- private WidgetCommand fWidgetCommand= new WidgetCommand();
- /** The SWT control's scrollbars */
- private ScrollBar fScroller;
- /** Listener on the visible document */
- private VisibleDocumentListener fVisibleDocumentListener= new VisibleDocumentListener();
- /** Verify listener */
- private TextVerifyListener fVerifyListener= new TextVerifyListener();
- /** The most recent widget modification as document command */
- private DocumentCommand fDocumentCommand= new DocumentCommand();
- /** The viewer's find/replace target */
- private IFindReplaceTarget fFindReplaceTarget;
- /**
- * The viewer widget token keeper
- * @since 2.0
- */
- private IWidgetTokenKeeper fWidgetTokenKeeper;
- /**
- * The viewer's manager of verify key listeners
- * @since 2.0
- */
- private VerifyKeyListenersManager fVerifyKeyListenersManager= new VerifyKeyListenersManager();
- /**
- * The mark position.
- * @since 2.0
- */
- protected Position fMarkPosition;
- /**
- * The mark position category.
- * @since 2.0
- */
- private final String MARK_POSITION_CATEGORY="__mark_category_" + hashCode(); //$NON-NLS-1$
- /**
- * The mark position updater
- * @since 2.0
- */
- private final IPositionUpdater fMarkPositionUpdater= new DefaultPositionUpdater(MARK_POSITION_CATEGORY);
- /**
- * The flag indicating the redraw behavior
- * @since 2.0
- */
- private int fRedrawCounter= 0;
- /**
- * The selection when working in non-redraw state
- * @since 2.0
- */
- private SelectionPosition fDocumentSelection;
- /**
- * The viewer's rewrite target
- * @since 2.0
- */
- private IRewriteTarget fRewriteTarget;
- /**
- * The viewer's cursor listener.
- * @since 3.0
- */
- private CursorListener fCursorListener;
- /**
- * Last selection range sent to selection change listeners.
- * @since 3.0
- */
- private IRegion fLastSentSelectionChange;
- /**
- * The registered post selection changed listeners.
- * @since 3.0
- */
- private List fPostSelectionChangedListeners;
- /**
- * Queued post selection changed events count.
- * @since 3.0
- */
- private final int[] fNumberOfPostSelectionChangedEvents= new int[1];
- /**
- * Last selection range sent to post selection change listeners.
- * @since 3.0
- */
- private IRegion fLastSentPostSelectionChange;
-
- /**
- * The find/replace document adapter.
- *
- * @since 3.0
- */
- protected FindReplaceDocumentAdapter fFindReplaceDocumentAdapter;
-
- /** Should the auto indent strategies ignore the next edit operation */
- protected boolean fIgnoreAutoIndent= false;
- /** The strings a line is prefixed with on SHIFT_RIGHT and removed from each line on SHIFT_LEFT */
- protected Map fIndentChars;
- /** The string a line is prefixed with on PREFIX and removed from each line on STRIP_PREFIX */
- protected Map fDefaultPrefixChars;
- /** The text viewer's text double click strategies */
- protected Map fDoubleClickStrategies;
- /** The text viewer's undo manager */
- protected IUndoManager fUndoManager;
- /** The text viewer's auto indent strategies */
- protected Map fAutoIndentStrategies;
- /** The text viewer's text hovers */
- protected Map fTextHovers;
- /**
- * The creator of the text hover control
- * @since 2.0
- */
- protected IInformationControlCreator fHoverControlCreator;
- /** All registered view port listeners> */
- protected List fViewportListeners;
- /** The last visible vertical position of the top line */
- protected int fLastTopPixel;
- /** All registered text listeners */
- protected List fTextListeners;
- /** All registered text input listeners */
- protected List fTextInputListeners;
- /** The text viewer's event consumer */
- protected IEventConsumer fEventConsumer;
- /** Indicates whether the viewer's text presentation should be replaced are modified. */
- protected boolean fReplaceTextPresentation= false;
- /**
- * The mapping between model and visible document.
- * @since 2.1
- */
- protected IDocumentInformationMapping fInformationMapping;
- /**
- * The viewer's paint manager.
- * @since 2.1
- */
- protected PaintManager fPaintManager;
- /**
- * The viewers partitioning. I.e. the partitioning name the viewer uses to access partitioning information of its input document.
- * @since 3.0
- */
- protected String fPartitioning;
- /**
- * All registered text presentation listeners.
- * since 3.0
- */
- protected List fTextPresentationListeners;
-
-
-
- //---- Construction and disposal ------------------
-
-
- /**
- * Internal use only
- */
- protected TextViewer() {
- }
-
- /**
- * Create a new text viewer with the given SWT style bits.
- * The viewer is ready to use but does not have any plug-in installed.
- *
- * @param parent the parent of the viewer's control
- * @param styles the SWT style bits for the viewer's control
- */
- public TextViewer(Composite parent, int styles) {
- createControl(parent, styles);
- }
-
- /**
- * Factory method to create the text widget to be used as the viewer's text widget.
- *
- * @return the text widget to be used
- */
- protected StyledText createTextWidget(Composite parent, int styles) {
- return new StyledText(parent, styles);
- }
-
- /**
- * Factory method to create the document adapter to be used by this viewer.
- *
- * @return the document adapter to be used
- */
- protected IDocumentAdapter createDocumentAdapter() {
- return new DefaultDocumentAdapter();
- }
-
- /**
- * Creates the viewer's SWT control. The viewer's text widget either is
- * the control or is a child of the control.
- *
- * @param parent the parent of the viewer's control
- * @param styles the SWT style bits for the viewer's control
- */
- protected void createControl(Composite parent, int styles) {
-
- fTextWidget= createTextWidget(parent, styles);
- fTextWidget.addDisposeListener(
- new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- setDocument(null);
- handleDispose();
- fTextWidget= null;
- }
- }
- );
-
- fTextWidget.setFont(parent.getFont());
- fTextWidget.setDoubleClickEnabled(false);
-
- /*
- * Disable SWT Shift+TAB traversal in this viewer
- * 1GIYQ9K: ITPUI:WINNT - StyledText swallows Shift+TAB
- */
- fTextWidget.addTraverseListener(new TraverseListener() {
- public void keyTraversed(TraverseEvent e) {
- if ((SWT.SHIFT == e.stateMask) && ('\t' == e.character))
- e.doit = false;
- }
- });
-
- // where does the first line start
- fTopInset= -fTextWidget.computeTrim(0, 0, 0, 0).y;
-
- fVerifyListener.forward(true);
- fTextWidget.addVerifyListener(fVerifyListener);
-
- fTextWidget.addSelectionListener(new SelectionListener() {
- public void widgetDefaultSelected(SelectionEvent event) {
- selectionChanged(event.x, event.y - event.x);
- }
- public void widgetSelected(SelectionEvent event) {
- selectionChanged(event.x, event.y - event.x);
- }
- });
-
- fCursorListener= new CursorListener();
- fCursorListener.install();
-
- initializeViewportUpdate();
- }
-
- /*
- * @see Viewer#getControl()
- */
- public Control getControl() {
- return fTextWidget;
- }
-
- /*
- * @see ITextViewer#activatePlugins()
- */
- public void activatePlugins() {
-
- if (fDoubleClickStrategies != null && !fDoubleClickStrategies.isEmpty() && fDoubleClickStrategyConnector == null) {
- fDoubleClickStrategyConnector= new TextDoubleClickStrategyConnector();
- fTextWidget.addMouseListener(fDoubleClickStrategyConnector);
- }
-
- ensureHoverControlManagerInstalled();
-
- if (fUndoManager != null) {
- fUndoManager.connect(this);
- fUndoManager.reset();
- }
- }
-
- /**
- * After this method has been executed the caller knows that any installed text hover has been installed.
- */
- private void ensureHoverControlManagerInstalled() {
- if (fTextHovers != null && !fTextHovers.isEmpty() && fHoverControlCreator != null && fTextHoverManager == null) {
- fTextHoverManager= new TextViewerHoverManager(this, fHoverControlCreator);
- fTextHoverManager.install(this.getTextWidget());
- fTextHoverManager.setSizeConstraints(60, 10, false, true);
- }
- }
-
- /*
- * @see ITextViewer#resetPlugins()
- */
- public void resetPlugins() {
- if (fUndoManager != null)
- fUndoManager.reset();
- }
-
- /**
- * Frees all resources allocated by this viewer. Internally called when the viewer's
- * control has been disposed.
- */
- protected void handleDispose() {
-
- if (fPaintManager != null) {
- fPaintManager.dispose();
- fPaintManager= null;
- }
-
- removeViewPortUpdate();
- fViewportGuard= null;
-
- if (fViewportListeners != null) {
- fViewportListeners.clear();
- fViewportListeners= null;
- }
-
- if (fTextListeners != null) {
- fTextListeners.clear();
- fTextListeners= null;
- }
-
- if (fTextInputListeners != null) {
- fTextInputListeners.clear();
- fTextInputListeners= null;
- }
-
- if (fPostSelectionChangedListeners != null) {
- fPostSelectionChangedListeners.clear();
- fPostSelectionChangedListeners= null;
- }
-
- if (fAutoIndentStrategies != null) {
- fAutoIndentStrategies.clear();
- fAutoIndentStrategies= null;
- }
-
- if (fUndoManager != null) {
- fUndoManager.disconnect();
- fUndoManager= null;
- }
-
- if (fDoubleClickStrategies != null) {
- fDoubleClickStrategies.clear();
- fDoubleClickStrategies= null;
- }
-
- if (fTextHovers != null) {
- fTextHovers.clear();
- fTextHovers= null;
- }
-
- fDoubleClickStrategyConnector= null;
-
- if (fTextHoverManager != null) {
- fTextHoverManager.dispose();
- fTextHoverManager= null;
- }
-
- if (fVisibleDocumentListener !=null) {
- if (fVisibleDocument != null)
- fVisibleDocument.removeDocumentListener(fVisibleDocumentListener);
- fVisibleDocumentListener= null;
- }
-
- if (fDocumentAdapter != null) {
- fDocumentAdapter.setDocument(null);
- fDocumentAdapter= null;
- }
-
- if (fSlaveDocumentManager != null) {
- if (fVisibleDocument != null)
- fSlaveDocumentManager.freeSlaveDocument(fVisibleDocument);
- fSlaveDocumentManager= null;
- }
-
- if (fCursorListener != null) {
- fCursorListener.uninstall();
- fCursorListener= null;
- }
-
- fVisibleDocument= null;
- fDocument= null;
- fScroller= null;
- }
-
-
- //---- simple getters and setters
-
- /**
- * Returns viewer's text widget.
- */
- public StyledText getTextWidget() {
- return fTextWidget;
- }
-
- /**
- * The delay in milliseconds before an empty selection
- * changed event is sent by the cursor listener.
- * <p>
- * Note: The return value is used to initialize the cursor
- * listener. To return a non-constant value has no effect.</p>
- * <p>
- * The same value (<code>500</code>) is used in <code>OpenStrategy.TIME</code>.</p>
- *
- * @return delay in milliseconds
- * @see org.eclipse.jface.util.OpenStrategy
- * @since 3.0
- */
- protected int getEmptySelectionChangedEventDelay() {
- return 500;
- }
-
- /*
- * @see ITextViewer#setAutoIndentStrategy(IAutoIndentStrategy, String)
- */
- public void setAutoIndentStrategy(IAutoIndentStrategy strategy, String contentType) {
-
- if (fAutoIndentStrategies == null)
- fAutoIndentStrategies= new HashMap();
-
- List autoEditStrategies= (List) fAutoIndentStrategies.get(contentType);
-
- if (strategy == null) {
- if (autoEditStrategies == null)
- return;
-
- fAutoIndentStrategies.put(contentType, null);
-
- } else {
- if (autoEditStrategies == null) {
- autoEditStrategies= new ArrayList();
- fAutoIndentStrategies.put(contentType, autoEditStrategies);
- }
-
- autoEditStrategies.clear();
- autoEditStrategies.add(strategy);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension2#prependAutoEditStrategy(org.eclipse.jface.text.IAutoEditStrategy, java.lang.String)
- * @since 2.1
- */
- public void prependAutoEditStrategy(IAutoEditStrategy strategy, String contentType) {
-
- if (strategy == null || contentType == null)
- throw new IllegalArgumentException();
-
- if (fAutoIndentStrategies == null)
- fAutoIndentStrategies= new HashMap();
-
- List autoEditStrategies= (List) fAutoIndentStrategies.get(contentType);
- if (autoEditStrategies == null) {
- autoEditStrategies= new ArrayList();
- fAutoIndentStrategies.put(contentType, autoEditStrategies);
- }
-
- autoEditStrategies.add(0, strategy);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension2#removeAutoEditStrategy(org.eclipse.jface.text.IAutoEditStrategy, java.lang.String)
- * @since 2.1
- */
- public void removeAutoEditStrategy(IAutoEditStrategy strategy, String contentType) {
- if (fAutoIndentStrategies == null)
- return;
-
- List autoEditStrategies= (List) fAutoIndentStrategies.get(contentType);
- if (autoEditStrategies == null)
- return;
-
- for (final Iterator iterator= autoEditStrategies.iterator(); iterator.hasNext(); ) {
- if (iterator.next().equals(strategy)) {
- iterator.remove();
- break;
- }
- }
-
- if (autoEditStrategies.isEmpty())
- fAutoIndentStrategies.put(contentType, null);
- }
-
- /*
- * @see ITextViewer#setEventConsumer(IEventConsumer)
- */
- public void setEventConsumer(IEventConsumer consumer) {
- fEventConsumer= consumer;
- }
-
- /*
- * @see ITextViewer#setIndentPrefixes(String[], String)
- */
- public void setIndentPrefixes(String[] indentPrefixes, String contentType) {
-
- int i= -1;
- boolean ok= (indentPrefixes != null);
- while (ok && ++i < indentPrefixes.length)
- ok= (indentPrefixes[i] != null);
-
- if (ok) {
-
- if (fIndentChars == null)
- fIndentChars= new HashMap();
-
- fIndentChars.put(contentType, indentPrefixes);
-
- } else if (fIndentChars != null)
- fIndentChars.remove(contentType);
- }
-
- /*
- * @see ITextViewer#getTopInset()
- */
- public int getTopInset() {
- return fTopInset;
- }
-
- /*
- * @see ITextViewer#isEditable()
- */
- public boolean isEditable() {
- if (fTextWidget == null)
- return false;
- return fTextWidget.getEditable();
- }
-
- /*
- * @see ITextViewer#setEditable(boolean)
- */
- public void setEditable(boolean editable) {
- if (fTextWidget != null)
- fTextWidget.setEditable(editable);
- }
-
- /*
- * @see ITextViewer#setDefaultPrefixes
- * @since 2.0
- */
- public void setDefaultPrefixes(String[] defaultPrefixes, String contentType) {
-
- if (defaultPrefixes != null && defaultPrefixes.length > 0) {
- if (fDefaultPrefixChars == null)
- fDefaultPrefixChars= new HashMap();
- fDefaultPrefixChars.put(contentType, defaultPrefixes);
- } else if (fDefaultPrefixChars != null)
- fDefaultPrefixChars.remove(contentType);
- }
-
- /*
- * @see ITextViewer#setUndoManager(IUndoManager)
- */
- public void setUndoManager(IUndoManager undoManager) {
- fUndoManager= undoManager;
- }
-
- /*
- * @see ITextViewer#setTextHover(ITextHover, String)
- */
- public void setTextHover(ITextHover hover, String contentType) {
- setTextHover(hover, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
- }
-
- /*
- * @see ITextViewerExtension2#setTextHover(ITextHover, String, int)
- * @since 2.1
- */
- public void setTextHover(ITextHover hover, String contentType, int stateMask) {
- TextHoverKey key= new TextHoverKey(contentType, stateMask);
- if (hover != null) {
- if (fTextHovers == null) {
- fTextHovers= new HashMap();
- }
- fTextHovers.put(key, hover);
- } else if (fTextHovers != null)
- fTextHovers.remove(key);
-
- ensureHoverControlManagerInstalled();
- }
-
- /*
- * @see ITextViewerExtension2#removeTextHovers(String)
- * @since 2.1
- */
- public void removeTextHovers(String contentType) {
- if (fTextHovers == null)
- return;
-
- Iterator iter= new HashSet(fTextHovers.keySet()).iterator();
- while (iter.hasNext()) {
- TextHoverKey key= (TextHoverKey)iter.next();
- if (key.fContentType.equals(contentType))
- fTextHovers.remove(key);
- }
- }
-
- /**
- * Returns the text hover for a given offset.
- *
- * @param offset the offset for which to return the text hover
- * @return the text hover for the given offset
- */
- protected ITextHover getTextHover(int offset) {
- return getTextHover(offset, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
- }
-
- /**
- * Returns the text hover for a given offset and a given state mask.
- *
- * @param offset the offset for which to return the text hover
- * @param stateMask the SWT event state mask
- * @return the text hover for the given offset and state mask
- * @since 2.1
- */
- protected ITextHover getTextHover(int offset, int stateMask) {
- if (fTextHovers == null)
- return null;
-
- IDocument document= getDocument();
- if (document == null)
- return null;
-
- try {
- TextHoverKey key= new TextHoverKey(TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true), stateMask);
- Object textHover= fTextHovers.get(key);
- if (textHover == null) {
- // Use default text hover
- key.setStateMask(ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
- textHover= fTextHovers.get(key);
- }
- return (ITextHover) textHover;
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * Returns the text hovering controller of this viewer.
- *
- * @return the text hovering controller of this viewer
- * @since 2.0
- */
- protected AbstractInformationControlManager getTextHoveringController() {
- return fTextHoverManager;
- }
-
- /**
- * Sets the creator for the hover controls.
- *
- * @param creator the hover control creator
- * @since 2.0
- */
- public void setHoverControlCreator(IInformationControlCreator creator) {
- fHoverControlCreator= creator;
- }
-
- /*
- * @see IWidgetTokenOwner#requestWidgetToken(IWidgetTokenKeeper)
- * @since 2.0
- */
- public boolean requestWidgetToken(IWidgetTokenKeeper requester) {
- if (fTextWidget != null) {
- if (fWidgetTokenKeeper != null) {
- if (fWidgetTokenKeeper == requester)
- return true;
- if (fWidgetTokenKeeper.requestWidgetToken(this)) {
- fWidgetTokenKeeper= requester;
- return true;
- }
- } else {
- fWidgetTokenKeeper= requester;
- return true;
- }
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenOwnerExtension#requestWidgetToken(org.eclipse.jface.text.IWidgetTokenKeeper, int)
- * @since 3.0
- */
- public boolean requestWidgetToken(IWidgetTokenKeeper requester, int priority) {
- if (fTextWidget != null) {
- if (fWidgetTokenKeeper != null) {
-
- if (fWidgetTokenKeeper == requester)
- return true;
-
- boolean accepted= false;
- if (fWidgetTokenKeeper instanceof IWidgetTokenKeeperExtension) {
- IWidgetTokenKeeperExtension extension= (IWidgetTokenKeeperExtension) fWidgetTokenKeeper;
- accepted= extension.requestWidgetToken(this, priority);
- } else {
- accepted= fWidgetTokenKeeper.requestWidgetToken(this);
- }
-
- if (accepted) {
- fWidgetTokenKeeper= requester;
- return true;
- }
-
- } else {
- fWidgetTokenKeeper= requester;
- return true;
- }
- }
- return false;
- }
-
- /*
- * @see IWidgetTokenOwner#releaseWidgetToken(IWidgetTokenKeeper)
- * @since 2.0
- */
- public void releaseWidgetToken(IWidgetTokenKeeper tokenKeeper) {
- if (fWidgetTokenKeeper == tokenKeeper)
- fWidgetTokenKeeper= null;
- }
-
-
- //---- Selection
-
- /*
- * @see ITextViewer#getSelectedRange()
- */
- public Point getSelectedRange() {
-
- if (!redraws() && fDocumentSelection != null)
- return fDocumentSelection.getNormalizedSelection();
-
- if (fTextWidget != null) {
- Point p= fTextWidget.getSelectionRange();
- p= widgetSelection2ModelSelection(p);
- if (p != null)
- return p;
- }
-
- return new Point(-1, -1);
- }
-
- /*
- * @see ITextViewer#setSelectedRange(int, int)
- */
- public void setSelectedRange(int selectionOffset, int selectionLength) {
-
- if (!redraws()) {
- if (fDocumentSelection != null) {
- fDocumentSelection.offset= selectionOffset;
- fDocumentSelection.length= selectionLength;
- // http://bugs.eclipse.org/bugs/show_bug.cgi?id=32795
- fDocumentSelection.isDeleted= false;
- }
- return;
- }
-
- if (fTextWidget == null)
- return;
-
- IRegion widgetSelection= modelRange2WidgetRange(new Region(selectionOffset, selectionLength));
- if (widgetSelection != null) {
-
- int[] selectionRange= new int[] { widgetSelection.getOffset(), widgetSelection.getLength() };
- validateSelectionRange(selectionRange);
- if (selectionRange[0] >= 0) {
- fTextWidget.setSelectionRange(selectionRange[0], selectionRange[1]);
- selectionChanged(selectionRange[0], selectionRange[1]);
- }
- }
- }
-
- /**
- * Validates and adapts the given selection range if it is not a valid
- * widget selection. The widget selection is invalid if it starts or ends
- * inside a multi-character line delimiter. If so, the selection is adapted to
- * start <b>after</b> the divided line delimiter and to end <b>before</b>
- * the divided line delimiter. The parameter passed in is changed in-place
- * when being adapted. An adaptation to <code>[-1, -1]</code> indicates
- * that the selection range could not be validated.
- * Subclasses may reimplement this method.
- *
- * @param selectionRange selectionRange[0] is the offset, selectionRange[1]
- * the length of the selection to validate.
- * @since 2.0
- */
- protected void validateSelectionRange(int[] selectionRange) {
-
- IDocument document= getVisibleDocument();
- if (document == null) {
- selectionRange[0]= -1;
- selectionRange[1]= -1;
- return;
- }
-
- int documentLength= document.getLength();
- int offset= selectionRange[0];
- int length= selectionRange[1];
-
- if (length < 0) {
- length= - length;
- offset -= length;
- }
-
- if (offset <0)
- offset= 0;
-
- if (offset > documentLength)
- offset= documentLength;
-
- int delta= (offset + length) - documentLength;
- if (delta > 0)
- length -= delta;
-
- try {
-
- int lineNumber= document.getLineOfOffset(offset);
- IRegion lineInformation= document.getLineInformation(lineNumber);
-
- int lineEnd= lineInformation.getOffset() + lineInformation.getLength();
- delta= offset - lineEnd;
- if (delta > 0) {
- // in the middle of a multi-character line delimiter
- offset= lineEnd;
- String delimiter= document.getLineDelimiter(lineNumber);
- if (delimiter != null)
- offset += delimiter.length();
- }
-
- int end= offset + length;
- lineInformation= document.getLineInformationOfOffset(end);
- lineEnd= lineInformation.getOffset() + lineInformation.getLength();
- delta= end - lineEnd;
- if (delta > 0) {
- // in the middle of a multi-character line delimiter
- length -= delta;
- }
-
- } catch (BadLocationException x) {
- selectionRange[0]= -1;
- selectionRange[1]= -1;
- return;
- }
-
- if (selectionRange[1] < 0) {
- selectionRange[0]= offset + length;
- selectionRange[1]= -length;
- } else {
- selectionRange[0]= offset;
- selectionRange[1]= length;
- }
- }
-
- /*
- * @see Viewer#setSelection(ISelection)
- */
- public void setSelection(ISelection selection, boolean reveal) {
- if (selection instanceof ITextSelection) {
- ITextSelection s= (ITextSelection) selection;
- setSelectedRange(s.getOffset(), s.getLength());
- if (reveal)
- revealRange(s.getOffset(), s.getLength());
- }
- }
-
- /*
- * @see Viewer#getSelection()
- */
- public ISelection getSelection() {
- Point p= getSelectedRange();
- if (p.x == -1 || p.y == -1)
- return TextSelection.emptySelection();
-
- return new TextSelection(getDocument(), p.x, p.y);
- }
-
- /*
- * @see ITextViewer#getSelectionProvider()
- */
- public ISelectionProvider getSelectionProvider() {
- return this;
- }
-
- /*
- * @see org.eclipse.jface.text.IPostSelectionProvider#addPostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- * @since 3.0
- */
- public void addPostSelectionChangedListener(ISelectionChangedListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fPostSelectionChangedListeners == null)
- fPostSelectionChangedListeners= new ArrayList();
-
- if (! fPostSelectionChangedListeners.contains(listener))
- fPostSelectionChangedListeners.add(listener);
- }
-
- /*
- * @see org.eclipse.jface.text.IPostSelectionProvider#removePostSelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener)
- * @since 3.0
- */
- public void removePostSelectionChangedListener(ISelectionChangedListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fPostSelectionChangedListeners != null) {
- fPostSelectionChangedListeners.remove(listener);
- if (fPostSelectionChangedListeners.size() == 0)
- fPostSelectionChangedListeners= null;
- }
- }
-
- /**
- * Get the text widget's display.
- *
- * @return the display or <code>null</code> if the display cannot be retrieved or if the display is disposed
- * @since 3.0
- */
- private Display getDisplay() {
- if (fTextWidget == null || fTextWidget.isDisposed())
- return null;
-
- Display display= fTextWidget.getDisplay();
- if (display != null && display.isDisposed())
- return null;
-
- return display;
- }
-
- /**
- * Starts a timer to send out a post selection changed event.
- *
- * @since 3.0
- */
- private void queuePostSelectionChanged() {
- Display display= getDisplay();
- if (display == null)
- return;
-
- fNumberOfPostSelectionChangedEvents[0]++;
- display.timerExec(getEmptySelectionChangedEventDelay(), new Runnable() {
- final int id= fNumberOfPostSelectionChangedEvents[0];
- public void run() {
- if (id == fNumberOfPostSelectionChangedEvents[0]) {
- // Check again because this is executed after the delay
- if (getDisplay() != null) {
- Point selection= fTextWidget.getSelectionRange();
- if (selection != null)
- firePostSelectionChanged(selection.x, selection.y);
- }
- }
- }
- });
- }
-
- /**
- * Sends out a text selection changed event to all registered post selection changed listeners.
- *
- * @param offset the offset of the newly selected range in the visible document
- * @param length the length of the newly selected range in the visible document
- * @since 3.0
- */
- protected void firePostSelectionChanged(int offset, int length) {
- if (redraws()) {
- IRegion r= widgetRange2ModelRange(new Region(offset, length));
- if ((r != null && !r.equals(fLastSentPostSelectionChange)) || r == null) {
- fLastSentPostSelectionChange= r;
- ISelection selection= r != null ? new TextSelection(getDocument(), r.getOffset(), r.getLength()) : TextSelection.emptySelection();
- SelectionChangedEvent event= new SelectionChangedEvent(this, selection);
- firePostSelectionChanged(event);
- }
- }
- }
-
- /**
- * Sends out a text selection changed event to all registered listeners and
- * registers the selection changed event to be send out to all post selection
- * listeners.
- *
- * @param offset the offset of the newly selected range in the visible document
- * @param length the length of the newly selected range in the visible document
- */
- protected void selectionChanged(int offset, int length) {
- queuePostSelectionChanged();
- fireSelectionChanged(offset, length);
- }
-
- /**
- * Sends out a text selection changed event to all registered listeners.
- *
- * @param offset the offset of the newly selected range in the visible document
- * @param length the length of the newly selected range in the visible document
- * @since 3.0
- */
- protected void fireSelectionChanged(int offset, int length) {
- if (redraws()) {
- IRegion r= widgetRange2ModelRange(new Region(offset, length));
- if ((r != null && !r.equals(fLastSentSelectionChange)) || r == null) {
- fLastSentSelectionChange= r;
- ISelection selection= r != null ? new TextSelection(getDocument(), r.getOffset(), r.getLength()) : TextSelection.emptySelection();
- SelectionChangedEvent event= new SelectionChangedEvent(this, selection);
- fireSelectionChanged(event);
- }
- }
- }
-
- /**
- * Sends the given event to all registered post selection changed listeners.
- *
- * @param event the selection event
- * @since 3.0
- */
- private void firePostSelectionChanged(SelectionChangedEvent event) {
- if (fPostSelectionChangedListeners != null) {
- for (int i= 0; i < fPostSelectionChangedListeners.size(); i++) {
- ISelectionChangedListener l= (ISelectionChangedListener) fPostSelectionChangedListeners.get(i);
- l.selectionChanged(event);
- }
- }
- }
-
- /**
- * Sends out a mark selection changed event to all registered listeners.
- *
- * @param offset the offset of the mark selection in the visible document, the offset is <code>-1</code> if the mark was cleared
- * @param length the length of the mark selection, may be negative if the caret is before the mark.
- * @since 2.0
- */
- protected void markChanged(int offset, int length) {
- if (redraws()) {
-
- if (offset != -1) {
- IRegion r= widgetRange2ModelRange(new Region(offset, length));
- offset= r.getOffset();
- length= r.getLength();
- }
-
- ISelection selection= new MarkSelection(getDocument(), offset, length);
- SelectionChangedEvent event= new SelectionChangedEvent(this, selection);
- fireSelectionChanged(event);
- }
- }
-
-
- //---- Text listeners
-
- /*
- * @see ITextViewer#addTextListener(ITextListener)
- */
- public void addTextListener(ITextListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextListeners == null)
- fTextListeners= new ArrayList();
-
- if (!fTextListeners.contains(listener))
- fTextListeners.add(listener);
- }
-
- /*
- * @see ITextViewer#removeTextListener(ITextListener)
- */
- public void removeTextListener(ITextListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextListeners != null) {
- fTextListeners.remove(listener);
- if (fTextListeners.size() == 0)
- fTextListeners= null;
- }
- }
-
- /**
- * Informs all registered text listeners about the change specified by the
- * widget command. This method does not use a robust iterator.
- *
- * @param cmd the widget command translated into a text event sent to all text listeners
- */
- protected void updateTextListeners(WidgetCommand cmd) {
-
- if (fTextListeners != null) {
-
- DocumentEvent event= cmd.event;
- if (event instanceof SlaveDocumentEvent)
- event= ((SlaveDocumentEvent) event).getMasterEvent();
-
- TextEvent e= new TextEvent(cmd.start, cmd.length, cmd.text, cmd.preservedText, event, redraws());
- for (int i= 0; i < fTextListeners.size(); i++) {
- ITextListener l= (ITextListener) fTextListeners.get(i);
- l.textChanged(e);
- }
- }
- }
-
- //---- Text input listeners
-
- /*
- * @see ITextViewer#addTextInputListener(ITextInputListener)
- */
- public void addTextInputListener(ITextInputListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextInputListeners == null)
- fTextInputListeners= new ArrayList();
-
- if (!fTextInputListeners.contains(listener))
- fTextInputListeners.add(listener);
- }
-
- /*
- * @see ITextViewer#removeTextInputListener(ITextInputListener)
- */
- public void removeTextInputListener(ITextInputListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextInputListeners != null) {
- fTextInputListeners.remove(listener);
- if (fTextInputListeners.size() == 0)
- fTextInputListeners= null;
- }
- }
-
- /**
- * Informs all registered text input listeners about the forthcoming input change,
- * This method does not use a robust iterator.
- *
- * @param oldInput the old input document
- * @param newInput the new input document
- */
- protected void fireInputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- if (fTextInputListeners != null) {
- for (int i= 0; i < fTextInputListeners.size(); i++) {
- ITextInputListener l= (ITextInputListener) fTextInputListeners.get(i);
- l.inputDocumentAboutToBeChanged(oldInput, newInput);
- }
- }
- }
-
- /**
- * Informs all registered text input listeners about the successful input change,
- * This method does not use a robust iterator.
- *
- * @param oldInput the old input document
- * @param newInput the new input document
- */
- protected void fireInputDocumentChanged(IDocument oldInput, IDocument newInput) {
- if (fTextInputListeners != null) {
- for (int i= 0; i < fTextInputListeners.size(); i++) {
- ITextInputListener l= (ITextInputListener) fTextInputListeners.get(i);
- l.inputDocumentChanged(oldInput, newInput);
- }
- }
- }
-
- //---- Document
-
- /*
- * @see Viewer#getInput()
- */
- public Object getInput() {
- return getDocument();
- }
-
- /*
- * @see ITextViewer#getDocument()
- */
- public IDocument getDocument() {
- return fDocument;
- }
-
- /*
- * @see Viewer#setInput(Object)
- */
- public void setInput(Object input) {
-
- IDocument document= null;
- if (input instanceof IDocument)
- document= (IDocument) input;
-
- setDocument(document);
- }
-
- /*
- * @see ITextViewer#setDocument(IDocument)
- */
- public void setDocument(IDocument document) {
-
- fReplaceTextPresentation= true;
- fireInputDocumentAboutToBeChanged(fDocument, document);
-
- IDocument oldDocument= fDocument;
- fDocument= document;
-
- setVisibleDocument(fDocument);
-
- resetPlugins();
- inputChanged(fDocument, oldDocument);
-
- fireInputDocumentChanged(oldDocument, fDocument);
- fLastSentSelectionChange= null;
- fReplaceTextPresentation= false;
- }
-
- /*
- * @see ITextViewer#setDocument(IDocument, int, int)
- */
- public void setDocument(IDocument document, int modelRangeOffset, int modelRangeLength) {
-
- fReplaceTextPresentation= true;
- fireInputDocumentAboutToBeChanged(fDocument, document);
-
- IDocument oldDocument= fDocument;
- fDocument= document;
-
- try {
-
- IDocument slaveDocument= createSlaveDocument(document);
- updateSlaveDocument(slaveDocument, modelRangeOffset, modelRangeLength);
- setVisibleDocument(slaveDocument);
-
- } catch (BadLocationException x) {
- throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_visible_region_1")); //$NON-NLS-1$
- }
-
- resetPlugins();
- inputChanged(fDocument, oldDocument);
-
- fireInputDocumentChanged(oldDocument, fDocument);
- fLastSentSelectionChange= null;
- fReplaceTextPresentation= false;
- }
-
- /**
- * Creates a slave document for the given document if there is a slave document manager
- * associated with this viewer.
- *
- * @param document the master document
- * @return the newly created slave document
- * @since 2.1
- */
- protected IDocument createSlaveDocument(IDocument document) {
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- if (manager != null) {
- if (manager.isSlaveDocument(document))
- return document;
- return manager.createSlaveDocument(document);
- }
- return document;
- }
-
- /**
- * Sets the given slave document to the specified range of its master document.
- *
- * @param visibleDocument the slave document
- * @param visibleRegionOffset the offset of the master document range
- * @param visibleRegionLength the length of the master document range
- * @return <code>true</code> if the slave has been adapted successfully
- * @throws BadLocationException in case the specified range is not valid in the master document
- * @since 2.1
- * @deprecated use <code>updateSlaveDocument</code> instead
- */
- protected boolean updateVisibleDocument(IDocument visibleDocument, int visibleRegionOffset, int visibleRegionLength) throws BadLocationException {
- if (visibleDocument instanceof ChildDocument) {
- ChildDocument childDocument= (ChildDocument) visibleDocument;
-
- IDocument document= childDocument.getParentDocument();
- int line= document.getLineOfOffset(visibleRegionOffset);
- int offset= document.getLineOffset(line);
- int length= (visibleRegionOffset - offset) + visibleRegionLength;
-
- Position parentRange= childDocument.getParentDocumentRange();
- if (offset != parentRange.getOffset() || length != parentRange.getLength()) {
- childDocument.setParentDocumentRange(offset, length);
- return true;
- }
- }
- return false;
- }
-
- /**
- * Updates the given slave document to show the specified range of its master document.
- *
- * @param slaveDocument the slave document
- * @param modelRangeOffset the offset of the master document range
- * @param modelRangeLength the length of the master document range
- * @return <code>true</code> if the slave has been adapted successfully
- * @throws BadLocationException in case the specified range is not valid in the master document
- * @since 3.0
- */
- protected boolean updateSlaveDocument(IDocument slaveDocument, int modelRangeOffset, int modelRangeLength) throws BadLocationException {
- return updateVisibleDocument(slaveDocument, modelRangeOffset, modelRangeLength);
- }
-
-
-
- //---- View ports
-
- /**
- * Initializes all listeners and structures required to set up view port listeners.
- */
- private void initializeViewportUpdate() {
-
- if (fViewportGuard != null)
- return;
-
- if (fTextWidget != null) {
-
- fViewportGuard= new ViewportGuard();
- fLastTopPixel= -1;
-
- fTextWidget.addKeyListener(fViewportGuard);
- fTextWidget.addMouseListener(fViewportGuard);
-
- fScroller= fTextWidget.getVerticalBar();
- if (fScroller != null)
- fScroller.addSelectionListener(fViewportGuard);
- }
- }
-
- /**
- * Removes all listeners and structures required to set up view port listeners.
- */
- private void removeViewPortUpdate() {
-
- if (fTextWidget != null) {
-
- fTextWidget.removeKeyListener(fViewportGuard);
- fTextWidget.removeMouseListener(fViewportGuard);
-
- if (fScroller != null && !fScroller.isDisposed()) {
- fScroller.removeSelectionListener(fViewportGuard);
- fScroller= null;
- }
-
- fViewportGuard= null;
- }
- }
-
- /*
- * @see ITextViewer#addViewportListener(IViewportListener)
- */
- public void addViewportListener(IViewportListener listener) {
-
- if (fViewportListeners == null) {
- fViewportListeners= new ArrayList();
- initializeViewportUpdate();
- }
-
- if (!fViewportListeners.contains(listener))
- fViewportListeners.add(listener);
- }
-
- /*
- * @see ITextViewer#removeViewportListener(IVewportListener)
- */
- public void removeViewportListener(IViewportListener listener) {
- if (fViewportListeners != null)
- fViewportListeners.remove(listener);
- }
-
- /**
- * Checks whether the view port changed and if so informs all registered
- * listeners about the change.
- *
- * @param origin describes under which circumstances this method has been called.
- *
- * @see IViewportListener
- */
- protected void updateViewportListeners(int origin) {
-
- if (redraws()) {
- int topPixel= fTextWidget.getTopPixel();
- if (topPixel >= 0 && topPixel != fLastTopPixel) {
- if (fViewportListeners != null) {
- for (int i= 0; i < fViewportListeners.size(); i++) {
- IViewportListener l= (IViewportListener) fViewportListeners.get(i);
- l.viewportChanged(topPixel);
- }
- }
- fLastTopPixel= topPixel;
- }
- }
- }
-
- //---- scrolling and revealing
-
- /*
- * @see ITextViewer#getTopIndex()
- */
- public int getTopIndex() {
-
- if (fTextWidget != null) {
- int top= fTextWidget.getTopIndex();
- return widgetLine2ModelLine(top);
- }
-
- return -1;
- }
-
- /*
- * @see ITextViewer#setTopIndex(int)
- */
- public void setTopIndex(int index) {
-
- if (fTextWidget != null) {
-
- int widgetLine= modelLine2WidgetLine(index);
- if (widgetLine == -1)
- widgetLine= getClosestWidgetLineForModelLine(index);
-
- if (widgetLine > -1) {
- fTextWidget.setTopIndex(widgetLine);
- updateViewportListeners(INTERNAL);
- }
- }
- }
-
- /**
- * Returns the view port height in lines. The actual visible lines can be fewer if the
- * document is shorter than the view port.
- *
- * @return the view port height in lines
- */
- protected int getVisibleLinesInViewport() {
- if (fTextWidget != null) {
- Rectangle clArea= fTextWidget.getClientArea();
- if (!clArea.isEmpty())
- return clArea.height / fTextWidget.getLineHeight();
- }
- return -1;
- }
-
- /*
- * @see ITextViewer#getBottomIndex()
- */
- public int getBottomIndex() {
-
- if (fTextWidget == null)
- return -1;
-
- IRegion coverage= getModelCoverage();
- if (coverage == null)
- return -1;
-
- try {
-
- IDocument d= getDocument();
-
- if (d == null)
- return -1;
-
- int startLine= d.getLineOfOffset(coverage.getOffset());
- int endLine= d.getLineOfOffset(coverage.getOffset() + coverage.getLength() - 1);
- int lines= getVisibleLinesInViewport();
-
- if (startLine + lines < endLine) {
- int widgetTopIndex= fTextWidget.getTopIndex();
- int widgetBottomIndex= widgetTopIndex + lines -1;
- int modelLine= widgetLine2ModelLine(widgetBottomIndex);
- if (modelLine == -1)
- return endLine;
- return modelLine;
- }
-
- return endLine;
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getBottomIndex")); //$NON-NLS-1$
- }
-
- return -1;
- }
-
- /*
- * @see ITextViewer#getTopIndexStartOffset()
- */
- public int getTopIndexStartOffset() {
-
- if (fTextWidget != null) {
- int top= fTextWidget.getTopIndex();
- try {
- top= getVisibleDocument().getLineOffset(top);
- return widgetLine2ModelLine(top);
- } catch (BadLocationException ex) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getTopIndexStartOffset")); //$NON-NLS-1$
- }
- }
-
- return -1;
- }
-
- /*
- * @see ITextViewer#getBottomIndexEndOffset()
- */
- public int getBottomIndexEndOffset() {
- try {
-
- IRegion line= getDocument().getLineInformation(getBottomIndex());
- int bottomEndOffset= line.getOffset() + line.getLength() - 1;
-
- IRegion coverage= getModelCoverage();
- if (coverage == null)
- return -1;
-
- int coverageEndOffset= coverage.getOffset() + coverage.getLength() - 1;
- return Math.min(coverageEndOffset, bottomEndOffset);
-
- } catch (BadLocationException ex) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getBottomIndexEndOffset")); //$NON-NLS-1$
- return getDocument().getLength() - 1;
- }
- }
-
- /*
- * @see ITextViewer#revealRange(int, int)
- */
- public void revealRange(int start, int length) {
-
- if (fTextWidget == null || !redraws())
- return;
-
- IRegion modelRange= new Region(start, length);
- IRegion widgetRange= modelRange2WidgetRange(modelRange);
- if (widgetRange != null) {
-
- int[] range= new int[] { widgetRange.getOffset(), widgetRange.getLength() };
- validateSelectionRange(range);
- if (range[0] >= 0)
- internalRevealRange(range[0], range[0] + range[1]);
-
- } else {
-
- IRegion coverage= getModelCoverage();
- int cursor= (coverage == null || start < coverage.getOffset()) ? 0 : getVisibleDocument().getLength();
- internalRevealRange(cursor, cursor);
- }
- }
-
- /**
- * Reveals the given range of the visible document.
- *
- * @param start the start offset of the range
- * @param end the end offset of the range
- */
- protected void internalRevealRange(int start, int end) {
-
- try {
-
- IDocument doc= getVisibleDocument();
-
- int startLine= doc.getLineOfOffset(start);
- int endLine= doc.getLineOfOffset(end);
-
- int top= fTextWidget.getTopIndex();
- if (top > -1) {
-
- // scroll vertically
-
- int lines= getVisibleLinesInViewport();
- int bottom= top + lines;
-
- // two lines at the top and the bottom should always be left
- // if window is smaller than 5 lines, always center position is chosen
- int bufferZone= 2;
-
- if (startLine >= top + bufferZone
- && startLine <= bottom - bufferZone
- && endLine >= top + bufferZone
- && endLine <= bottom - bufferZone) {
-
- // do not scroll at all as it is already visible
-
- } else {
-
- int delta= Math.max(0, lines - (endLine - startLine));
- fTextWidget.setTopIndex(startLine - delta/3);
- updateViewportListeners(INTERNAL);
- }
-
- // scroll horizontally
-
- if (endLine < startLine) {
- endLine += startLine;
- startLine= endLine - startLine;
- endLine -= startLine;
- }
-
- int startPixel= -1;
- int endPixel= -1;
-
- if (endLine > startLine) {
- // reveal the beginning of the range in the start line
- IRegion extent= getExtent(start, start);
- startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel();
- endPixel= startPixel;
-
- } else {
- IRegion extent= getExtent(start, end);
- startPixel= extent.getOffset() + fTextWidget.getHorizontalPixel();
- endPixel= startPixel + extent.getLength();
- }
-
- int visibleStart= fTextWidget.getHorizontalPixel();
- int visibleEnd= visibleStart + fTextWidget.getClientArea().width;
-
- // scroll only if not yet visible
- if (startPixel < visibleStart || visibleEnd < endPixel) {
-
- // set buffer zone to 10 pixels
- bufferZone= 10;
-
- int newOffset= visibleStart;
-
- int visibleWidth= visibleEnd - visibleStart;
- int selectionPixelWidth= endPixel - startPixel;
-
- if (startPixel < visibleStart)
- newOffset= startPixel;
- else if (selectionPixelWidth + bufferZone < visibleWidth)
- newOffset= endPixel + bufferZone - visibleWidth;
- else
- newOffset= startPixel;
-
- float index= ((float)newOffset) / ((float)getAverageCharWidth());
-
- fTextWidget.setHorizontalIndex(Math.round(index));
- }
-
- }
- } catch (BadLocationException e) {
- throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_range")); //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the width of the text when being drawn into this viewer's widget.
- *
- * @param text the string to measure
- * @return the width of the presentation of the given string
- * @deprecated use <code>getWidthInPixels(int, int)</code> instead
- */
- final protected int getWidthInPixels(String text) {
- GC gc= new GC(fTextWidget);
- gc.setFont(fTextWidget.getFont());
- Point extent= gc.textExtent(text);
- gc.dispose();
- return extent.x;
- }
-
- /**
- * Returns the region covered by the given start and end offset.
- * The result is relative to the upper left corner of the widget
- * client area.
- *
- * @param start offset relative to the start of this viewer's view port
- * 0 <= offset <= getCharCount()
- * @param end offset relative to the start of this viewer's view port
- * 0 <= offset <= getCharCount()
- * @return the region covered by start and end offset
- */
- final protected IRegion getExtent(int start, int end) {
- Point left= fTextWidget.getLocationAtOffset(start);
- Point right= new Point(left.x, left.y);
-
- for (int i= start +1; i <= end; i++) {
-
- Point p= fTextWidget.getLocationAtOffset(i);
-
- if (left.x > p.x)
- left.x= p.x;
-
- if (right.x < p.x)
- right.x= p.x;
- }
-
- return new Region(left.x, right.x - left.x);
- }
-
- /**
- * Returns the width of the representation of a text range in the
- * visible region of the viewer's document as drawn in this viewer's
- * widget.
- *
- * @param offset the offset of the text range in the visible region
- * @param length the length of the text range in the visible region
- * @return the width of the presentation of the specified text range
- * @since 2.0
- */
- final protected int getWidthInPixels(int offset, int length) {
-
- Point left= fTextWidget.getLocationAtOffset(offset);
- Point right= new Point(left.x, left.y);
-
- int end= offset + length;
- for (int i= offset +1; i <= end; i++) {
-
- Point p= fTextWidget.getLocationAtOffset(i);
-
- if (left.x > p.x)
- left.x= p.x;
-
- if (right.x < p.x)
- right.x= p.x;
- }
-
- return right.x - left.x;
- }
-
- /**
- * Returns the average character width of this viewer's widget.
- *
- * @return the average character width of this viewer's widget
- */
- final protected int getAverageCharWidth() {
- GC gc= new GC(fTextWidget);
- gc.setFont(fTextWidget.getFont());
- int increment= gc.getFontMetrics().getAverageCharWidth();
- gc.dispose();
- return increment;
- }
-
- /*
- * @see Viewer#refresh()
- */
- public void refresh() {
- setDocument(getDocument());
- }
-
- //---- visible range support
-
- /**
- * Returns the slave document manager
- *
- * @return the slave document manager
- * @since 2.1
- */
- protected ISlaveDocumentManager getSlaveDocumentManager() {
- if (fSlaveDocumentManager == null)
- fSlaveDocumentManager= createSlaveDocumentManager();
- return fSlaveDocumentManager;
- }
-
- /**
- * Creates a new slave document manager. This implementation always
- * returns a <code>ChildDocumentManager</code>.
- *
- * @return ISlaveDocumentManager
- * @since 2.1
- */
- protected ISlaveDocumentManager createSlaveDocumentManager() {
- return new ChildDocumentManager();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewer#invalidateTextPresentation()
- */
- public final void invalidateTextPresentation() {
- if (fVisibleDocument != null) {
- fWidgetCommand.event= null;
- fWidgetCommand.start= 0;
- fWidgetCommand.length= fVisibleDocument.getLength();
- fWidgetCommand.text= fVisibleDocument.get();
- updateTextListeners(fWidgetCommand);
- }
- }
-
- /**
- * Invalidates the given range of the text presentation.
- *
- * @param offset the offset of the range to be invalidated
- * @param length the length of the range to be invalidated
- * @since 2.1
- */
- public final void invalidateTextPresentation(int offset, int length) {
- if (fVisibleDocument != null) {
-
- IRegion widgetRange= modelRange2WidgetRange(new Region(offset, length));
- if (widgetRange != null) {
-
- fWidgetCommand.event= null;
- fWidgetCommand.start= widgetRange.getOffset();
- fWidgetCommand.length= widgetRange.getLength();
-
- try {
- fWidgetCommand.text= fVisibleDocument.get(widgetRange.getOffset(), widgetRange.getLength());
- updateTextListeners(fWidgetCommand);
- } catch (BadLocationException x) {
- // can not happen because of previous checking
- }
- }
- }
- }
-
- /**
- * Initializes the text widget with the visual document and
- * invalidates the overall presentation.
- */
- private void initializeWidgetContents() {
-
- if (fTextWidget != null && fVisibleDocument != null) {
-
- // set widget content
- if (fDocumentAdapter == null)
- fDocumentAdapter= createDocumentAdapter();
-
- fDocumentAdapter.setDocument(fVisibleDocument);
- fTextWidget.setContent(fDocumentAdapter);
-
- // invalidate presentation
- invalidateTextPresentation();
- }
- }
-
- /**
- * Frees the given document if it is a slave document.
- *
- * @param slave the potential slave document
- * @since 3.0
- */
- protected void freeSlaveDocument(IDocument slave) {
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- if (manager != null && manager.isSlaveDocument(slave))
- manager.freeSlaveDocument(slave);
- }
-
- /**
- * Sets this viewer's visible document. The visible document represents the
- * visible region of the viewer's input document.
- *
- * @param document the visible document
- */
- protected void setVisibleDocument(IDocument document) {
-
- if (fVisibleDocument == document && fVisibleDocument instanceof ChildDocument) {
- // optimization for new child documents
- return;
- }
-
- if (fVisibleDocument != null) {
- if (fVisibleDocumentListener != null)
- fVisibleDocument.removeDocumentListener(fVisibleDocumentListener);
- if (fVisibleDocument != document)
- freeSlaveDocument(fVisibleDocument);
- }
-
- fVisibleDocument= document;
- initializeDocumentInformationMapping(fVisibleDocument);
-
- initializeWidgetContents();
-
- fFindReplaceDocumentAdapter= null;
- if (fVisibleDocument != null && fVisibleDocumentListener != null)
- fVisibleDocument.addDocumentListener(fVisibleDocumentListener);
- }
-
- /**
- * Hook method called when the visible document is about to be changed.
- * <p>
- * Subclasses may override.
- *
- * @param event the document event
- * @since 3.0
- */
- protected void handleVisibleDocumentAboutToBeChanged(DocumentEvent event) {
- }
-
- /**
- * Hook method called when the visible document has been changed.
- * <p>
- * Subclasses may override.
- *
- * @param event the document event
- * @since 3.0
- */
- protected void handleVisibleDocumentChanged(DocumentEvent event) {
- }
-
- /**
- * Initializes the document information mapping between the given slave document and
- * its master document.
- *
- * @param visibleDocument the slave document
- * @since 2.1
- */
- protected void initializeDocumentInformationMapping(IDocument visibleDocument) {
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- fInformationMapping= manager == null ? null : manager.createMasterSlaveMapping(visibleDocument);
- }
-
- /**
- * Returns the viewer's visible document.
- *
- * @return the viewer's visible document
- */
- protected IDocument getVisibleDocument() {
- return fVisibleDocument;
- }
-
- /**
- * Returns the offset of the visible region.
- *
- * @return the offset of the visible region
- */
- protected int _getVisibleRegionOffset() {
-
- IDocument document= getVisibleDocument();
- if (document instanceof ChildDocument) {
- ChildDocument cdoc= (ChildDocument) document;
- return cdoc.getParentDocumentRange().getOffset();
- }
-
- return 0;
- }
-
- /*
- * @see ITextViewer#getVisibleRegion()
- */
- public IRegion getVisibleRegion() {
-
- IDocument document= getVisibleDocument();
- if (document instanceof ChildDocument) {
- Position p= ((ChildDocument) document).getParentDocumentRange();
- return new Region(p.getOffset(), p.getLength());
- }
-
- return new Region(0, document == null ? 0 : document.getLength());
- }
-
- /*
- * @see ITextViewer#overlapsWithVisibleRegion(int, int)
- */
- public boolean overlapsWithVisibleRegion(int start, int length) {
- IDocument document= getVisibleDocument();
- if (document instanceof ChildDocument) {
- ChildDocument cdoc= (ChildDocument) document;
- return cdoc.getParentDocumentRange().overlapsWith(start, length);
- } else if (document != null) {
- int size= document.getLength();
- return (start >= 0 && length >= 0 && start + length <= size);
- }
- return false;
- }
-
- /*
- * @see ITextViewer#setVisibleRegion(int, int)
- */
- public void setVisibleRegion(int start, int length) {
-
- IRegion region= getVisibleRegion();
- if (start == region.getOffset() && length == region.getLength()) {
- // nothing to change
- return;
- }
-
- setRedraw(false);
- try {
-
- IDocument slaveDocument= createSlaveDocument(getVisibleDocument());
- if (updateSlaveDocument(slaveDocument, start, length))
- setVisibleDocument(slaveDocument);
-
- } catch (BadLocationException x) {
- throw new IllegalArgumentException(JFaceTextMessages.getString("TextViewer.error.invalid_visible_region_2")); //$NON-NLS-1$
- } finally {
- setRedraw(true);
- }
- }
-
- /*
- * @see ITextViewer#resetVisibleRegion()
- */
- public void resetVisibleRegion() {
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- if (manager != null) {
- IDocument slave= getVisibleDocument();
- IDocument master= manager.getMasterDocument(slave);
- if (master != null) {
- setVisibleDocument(master);
- manager.freeSlaveDocument(slave);
- }
- }
- }
-
-
- //--------------------------------------
-
- /*
- * @see ITextViewer#setTextDoubleClickStrategy(ITextDoubleClickStrategy, String)
- */
- public void setTextDoubleClickStrategy(ITextDoubleClickStrategy strategy, String contentType) {
-
- if (strategy != null) {
- if (fDoubleClickStrategies == null)
- fDoubleClickStrategies= new HashMap();
- fDoubleClickStrategies.put(contentType, strategy);
- } else if (fDoubleClickStrategies != null)
- fDoubleClickStrategies.remove(contentType);
- }
-
- /**
- * Selects from the given map the one which is registered under
- * the content type of the partition in which the given offset is located.
- *
- * @param plugins the map from which to choose
- * @param offset the offset for which to find the plug-in
- * @return the plug-in registered under the offset's content type
- */
- protected Object selectContentTypePlugin(int offset, Map plugins) {
- try {
- return selectContentTypePlugin(TextUtilities.getContentType(getDocument(), getDocumentPartitioning(), offset, true), plugins);
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.selectContentTypePlugin")); //$NON-NLS-1$
- }
- return null;
- }
-
- /**
- * Selects from the given <code>plug-ins</code> this one which is registered for
- * the given content <code>type</code>.
- *
- * @param type the type to be used as lookup key
- * @param plugins the table to be searched
- */
- private Object selectContentTypePlugin(String type, Map plugins) {
-
- if (plugins == null)
- return null;
-
- return plugins.get(type);
- }
-
- /**
- * Hook called on receipt of a <code>VerifyEvent</code>. The event has
- * been translated into a <code>DocumentCommand</code> which can now be
- * manipulated by interested parties. By default, the hook forwards the command
- * to the installed instances of <code>IAutoEditStrategy</code>.
- *
- * @param command the document command representing the verify event
- */
- protected void customizeDocumentCommand(DocumentCommand command) {
- if (isIgnoringAutoEditStrategies())
- return;
-
- List strategies= (List) selectContentTypePlugin(command.offset, fAutoIndentStrategies);
- if (strategies == null)
- return;
-
- switch (strategies.size()) {
- // optimization
- case 0:
- break;
-
- case 1:
- ((IAutoEditStrategy) strategies.iterator().next()).customizeDocumentCommand(getDocument(), command);
- break;
-
- // make iterator robust against adding/removing strategies from within strategies
- default:
- strategies= new ArrayList(strategies);
-
- IDocument document= getDocument();
- for (final Iterator iterator= strategies.iterator(); iterator.hasNext(); )
- ((IAutoEditStrategy) iterator.next()).customizeDocumentCommand(document, command);
-
- break;
- }
- }
-
- /**
- * @see VerifyListener#verifyText(VerifyEvent)
- */
- protected void handleVerifyEvent(VerifyEvent e) {
-
- if (fEventConsumer != null) {
- fEventConsumer.processEvent(e);
- if (!e.doit)
- return;
- }
-
- IRegion modelRange= event2ModelRange(e);
- fDocumentCommand.setEvent(e, modelRange);
- customizeDocumentCommand(fDocumentCommand);
- if (!fDocumentCommand.fillEvent(e, modelRange)) {
-
- boolean compoundChange= fDocumentCommand.getCommandCount() > 1;
- try {
-
- fVerifyListener.forward(false);
-
- if (compoundChange && fUndoManager != null)
- fUndoManager.beginCompoundChange();
-
- if (fSlaveDocumentManager != null) {
- IDocument visible= getVisibleDocument();
- try {
- fSlaveDocumentManager.setAutoExpandMode(visible, true);
- fDocumentCommand.execute(getDocument());
- } finally {
- fSlaveDocumentManager.setAutoExpandMode(visible, false);
- }
- } else {
- fDocumentCommand.execute(getDocument());
- }
-
- if (fTextWidget != null) {
- int documentCaret= fDocumentCommand.caretOffset;
- if (documentCaret == -1) {
- // old behavior of document command
- documentCaret= fDocumentCommand.offset + (fDocumentCommand.text == null ? 0 : fDocumentCommand.text.length());
- }
-
- int widgetCaret= modelOffset2WidgetOffset(documentCaret);
- if (widgetCaret == -1) {
- // try to move it to the closest spot
- IRegion region= getModelCoverage();
- if (region != null) {
- if (documentCaret <= region.getOffset())
- widgetCaret= 0;
- else if (documentCaret >= region.getOffset() + region.getLength())
- widgetCaret= getVisibleRegion().getLength();
- }
- }
-
- if (widgetCaret != -1) {
- // there is a valid widget caret
- fTextWidget.setCaretOffset(widgetCaret);
- }
-
- fTextWidget.showSelection();
- }
- } catch (BadLocationException x) {
-
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.verifyText")); //$NON-NLS-1$
-
- } finally {
-
- if (compoundChange && fUndoManager != null)
- fUndoManager.endCompoundChange();
-
- fVerifyListener.forward(true);
-
- }
- }
- }
-
- //---- text manipulation
-
- /**
- * Returns whether the marked region of this viewer is empty.
- *
- * @return <code>true</code> if the marked region of this viewer is empty, otherwise <code>false</code>
- * @since 2.0
- */
- private boolean isMarkedRegionEmpty() {
- return
- fTextWidget == null ||
- fMarkPosition == null ||
- fMarkPosition.isDeleted() ||
- modelRange2WidgetRange(fMarkPosition) == null;
- }
-
- /*
- * @see ITextViewer#canDoOperation(int)
- */
- public boolean canDoOperation(int operation) {
-
- if (fTextWidget == null || !redraws())
- return false;
-
- switch (operation) {
- case CUT:
- return isEditable() &&(fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty());
- case COPY:
- return fTextWidget.getSelectionCount() > 0 || !isMarkedRegionEmpty();
- case DELETE:
- case PASTE:
- return isEditable();
- case SELECT_ALL:
- return true;
- case SHIFT_LEFT:
- return isEditable() && fIndentChars != null;
- case SHIFT_RIGHT:
- return isEditable() && fIndentChars != null && areMultipleLinesSelected();
- case PREFIX:
- case STRIP_PREFIX:
- return isEditable() && fDefaultPrefixChars != null;
- case UNDO:
- return fUndoManager != null && fUndoManager.undoable();
- case REDO:
- return fUndoManager != null && fUndoManager.redoable();
- case PRINT:
- return isPrintable();
- }
-
- return false;
- }
-
- /*
- * @see ITextViewer#doOperation(int)
- */
- public void doOperation(int operation) {
-
- if (fTextWidget == null || !redraws())
- return;
-
- Point selection= null;
-
- switch (operation) {
-
- case UNDO:
- if (fUndoManager != null) {
- ignoreAutoEditStrategies(true);
- fUndoManager.undo();
- ignoreAutoEditStrategies(false);
- }
- break;
- case REDO:
- if (fUndoManager != null) {
- ignoreAutoEditStrategies(true);
- fUndoManager.redo();
- ignoreAutoEditStrategies(false);
- }
- break;
- case CUT:
- if (fTextWidget.getSelectionCount() == 0)
- copyMarkedRegion(true);
- else
- fTextWidget.cut();
-
- selection= fTextWidget.getSelectionRange();
- fireSelectionChanged(selection.x, selection.y);
-
- break;
- case COPY:
- if (fTextWidget.getSelectionCount() == 0)
- copyMarkedRegion(false);
- else
- fTextWidget.copy();
- break;
- case PASTE:
-// ignoreAutoEditStrategies(true);
- fTextWidget.paste();
- selection= fTextWidget.getSelectionRange();
- fireSelectionChanged(selection.x, selection.y);
-// ignoreAutoEditStrategies(false);
- break;
- case DELETE:
- deleteText();
- selection= fTextWidget.getSelectionRange();
- fireSelectionChanged(selection.x, selection.y);
- break;
- case SELECT_ALL: {
- if (getDocument() != null)
- setSelectedRange(0, getDocument().getLength());
- break;
- }
- case SHIFT_RIGHT:
- shift(false, true, false);
- break;
- case SHIFT_LEFT:
- shift(false, false, false);
- break;
- case PREFIX:
- shift(true, true, true);
- break;
- case STRIP_PREFIX:
- shift(true, false, true);
- break;
- case PRINT:
- print();
- break;
- }
- }
-
- /**
- * Tells this viewer whether the registered auto edit strategies should be ignored.
- *
- * @param ignore <code>true</code> if the strategies should be ignored.
- * @since 2.1
- */
- protected void ignoreAutoEditStrategies(boolean ignore) {
-
- fIgnoreAutoIndent= ignore;
-
- IDocument document= getDocument();
- if (document instanceof IDocumentExtension2) {
- IDocumentExtension2 extension= (IDocumentExtension2) document;
- if (ignore)
- extension.ignorePostNotificationReplaces();
- else
- extension.acceptPostNotificationReplaces();
- }
- }
-
- /**
- * Returns whether this viewer ignores the registered auto edit strategies.
- *
- * @return <code>true</code> if the strategies are ignored
- * @since 2.1
- */
- protected boolean isIgnoringAutoEditStrategies() {
- return fIgnoreAutoIndent;
- }
-
- /*
- * @see ITextOperationTargetExtension#enableOperation(int, boolean)
- * @since 2.0
- */
- public void enableOperation(int operation, boolean enable) {
- /*
- * No-op by default.
- * Will be changed to regularly disable the known operations.
- */
- }
-
- /**
- * Copies/cuts the marked region.
- *
- * @param delete <code>true</code> if the region should be deleted rather than copied.
- * @since 2.0
- */
- protected void copyMarkedRegion(boolean delete) {
-
- if (fTextWidget == null)
- return;
-
- if (fMarkPosition == null || fMarkPosition.isDeleted() || modelRange2WidgetRange(fMarkPosition) == null)
- return;
-
- int widgetMarkOffset= modelOffset2WidgetOffset(fMarkPosition.offset);
- Point selection= fTextWidget.getSelection();
- if (selection.x <= widgetMarkOffset)
- fTextWidget.setSelection(selection.x, widgetMarkOffset);
- else
- fTextWidget.setSelection(widgetMarkOffset, selection.x);
-
- if (delete) {
- fTextWidget.cut();
- } else {
- fTextWidget.copy();
- fTextWidget.setSelection(selection.x); // restore old cursor position
- }
- }
-
- /**
- * Deletes the current selection. If the selection has the length 0
- * the selection is automatically extended to the right - either by 1
- * or by the length of line delimiter if at the end of a line.
- *
- * @deprecated use <code>StyledText.invokeAction</code> instead
- */
- protected void deleteText() {
- fTextWidget.invokeAction(ST.DELETE_NEXT);
- }
-
- /**
- * A block is selected if the character preceding the start of the
- * selection is a new line character.
- *
- * @return <code>true</code> if a block is selected
- */
- protected boolean isBlockSelected() {
-
- Point s= getSelectedRange();
- if (s.y == 0)
- return false;
-
- try {
-
- IDocument document= getDocument();
- int line= document.getLineOfOffset(s.x);
- int start= document.getLineOffset(line);
- return (s.x == start);
-
- } catch (BadLocationException x) {
- }
-
- return false;
- }
-
- /**
- * Returns <code>true</code> if one line is completely selected or if multiple lines are selected.
- * Being completely selected means that all characters except the new line characters are
- * selected.
- *
- * @return <code>true</code> if one or multiple lines are selected
- * @since 2.0
- */
- protected boolean areMultipleLinesSelected() {
- Point s= getSelectedRange();
- if (s.y == 0)
- return false;
-
- try {
-
- IDocument document= getDocument();
- int startLine= document.getLineOfOffset(s.x);
- int endLine= document.getLineOfOffset(s.x + s.y);
- IRegion line= document.getLineInformation(startLine);
- return startLine != endLine || (s.x == line.getOffset() && s.y == line.getLength());
-
- } catch (BadLocationException x) {
- }
-
- return false;
- }
-
- /**
- * Returns the index of the first line whose start offset is in the given text range.
- *
- * @param region the text range in characters where to find the line
- * @return the first line whose start index is in the given range, -1 if there is no such line
- */
- private int getFirstCompleteLineOfRegion(IRegion region) {
-
- try {
-
- IDocument d= getDocument();
-
- int startLine= d.getLineOfOffset(region.getOffset());
-
- int offset= d.getLineOffset(startLine);
- if (offset >= region.getOffset())
- return startLine;
-
- offset= d.getLineOffset(startLine + 1);
- return (offset > region.getOffset() + region.getLength() ? -1 : startLine + 1);
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.getFirstCompleteLineOfRegion")); //$NON-NLS-1$
- }
-
- return -1;
- }
-
-
- /**
- * Creates a region describing the text block (something that starts at
- * the beginning of a line) completely containing the current selection.
- *
- * @param selection the selection to use
- * @return the region describing the text block comprising the given selection
- * @since 2.0
- */
- private IRegion getTextBlockFromSelection(Point selection) {
-
- try {
- IDocument document= getDocument();
- IRegion line= document.getLineInformationOfOffset(selection.x);
- int length= selection.y == 0 ? line.getLength() : selection.y + (selection.x - line.getOffset());
- return new Region(line.getOffset(), length);
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /**
- * Shifts a text block to the right or left using the specified set of prefix characters.
- * The prefixes must start at the beginning of the line.
- *
- * @param useDefaultPrefixes says whether the configured default or indent prefixes should be used
- * @param right says whether to shift to the right or the left
- *
- * @deprecated use shift(boolean, boolean, boolean) instead
- */
- protected void shift(boolean useDefaultPrefixes, boolean right) {
- shift(useDefaultPrefixes, right, false);
- }
-
- /**
- * Shifts a text block to the right or left using the specified set of prefix characters.
- * If white space should be ignored the prefix characters must not be at the beginning of
- * the line when shifting to the left. There may be whitespace in front of the prefixes.
- *
- * @param useDefaultPrefixes says whether the configured default or indent prefixes should be used
- * @param right says whether to shift to the right or the left
- * @param ignoreWhitespace says whether whitespace in front of prefixes is allowed
- * @since 2.0
- */
- protected void shift(boolean useDefaultPrefixes, boolean right, boolean ignoreWhitespace) {
-
- if (fUndoManager != null)
- fUndoManager.beginCompoundChange();
-
- setRedraw(false);
- startSequentialRewriteMode(true);
-
- IDocument d= getDocument();
- Map partitioners= null;
-
- try {
-
- Point selection= getSelectedRange();
- IRegion block= getTextBlockFromSelection(selection);
- ITypedRegion[] regions= TextUtilities.computePartitioning(d, getDocumentPartitioning(), block.getOffset(), block.getLength(), false);
-
- int lineCount= 0;
- int[] lines= new int[regions.length * 2]; // [startline, endline, startline, endline, ...]
- for (int i= 0, j= 0; i < regions.length; i++, j+= 2) {
- // start line of region
- lines[j]= getFirstCompleteLineOfRegion(regions[i]);
- // end line of region
- int length= regions[i].getLength();
- int offset= regions[i].getOffset() + length;
- if (length > 0)
- offset--;
- lines[j + 1]= (lines[j] == -1 ? -1 : d.getLineOfOffset(offset));
- lineCount += lines[j + 1] - lines[j] + 1;
- }
-
- if (lineCount >= 20)
- partitioners= TextUtilities.removeDocumentPartitioners(d);
-
- // Remember the selection range.
- IPositionUpdater positionUpdater= new ShiftPositionUpdater(SHIFTING);
- Position rememberedSelection= new Position(selection.x, selection.y);
- d.addPositionCategory(SHIFTING);
- d.addPositionUpdater(positionUpdater);
- try {
- d.addPosition(SHIFTING, rememberedSelection);
- } catch (BadPositionCategoryException ex) {
- // should not happen
- }
-
- // Perform the shift operation.
- Map map= (useDefaultPrefixes ? fDefaultPrefixChars : fIndentChars);
- for (int i= 0, j= 0; i < regions.length; i++, j += 2) {
- String[] prefixes= (String[]) selectContentTypePlugin(regions[i].getType(), map);
- if (prefixes != null && prefixes.length > 0 && lines[j] >= 0 && lines[j + 1] >= 0) {
- if (right)
- shiftRight(lines[j], lines[j + 1], prefixes[0]);
- else
- shiftLeft(lines[j], lines[j + 1], prefixes, ignoreWhitespace);
- }
- }
-
- // Restore the selection.
- setSelectedRange(rememberedSelection.getOffset(), rememberedSelection.getLength());
-
- try {
- d.removePositionUpdater(positionUpdater);
- d.removePositionCategory(SHIFTING);
- } catch (BadPositionCategoryException ex) {
- // should not happen
- }
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.shift_1")); //$NON-NLS-1$
-
- } finally {
-
- if (partitioners != null)
- TextUtilities.addDocumentPartitioners(d, partitioners);
-
- stopSequentialRewriteMode();
- setRedraw(true);
-
- if (fUndoManager != null)
- fUndoManager.endCompoundChange();
- }
- }
-
- /**
- * Shifts the specified lines to the right inserting the given prefix
- * at the beginning of each line
- *
- * @param prefix the prefix to be inserted
- * @param startLine the first line to shift
- * @param endLine the last line to shift
- * @since 2.0
- */
- private void shiftRight(int startLine, int endLine, String prefix) {
-
- try {
-
- IDocument d= getDocument();
- while (startLine <= endLine) {
- d.replace(d.getLineOffset(startLine++), 0, prefix);
- }
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println("TextViewer.shiftRight: BadLocationException"); //$NON-NLS-1$
- }
- }
-
- /**
- * Shifts the specified lines to the right or to the left. On shifting to the right
- * it insert <code>prefixes[0]</code> at the beginning of each line. On shifting to the
- * left it tests whether each of the specified lines starts with one of the specified
- * prefixes and if so, removes the prefix.
- *
- * @param prefixes the prefixes to be used for shifting
- * @param right if <code>true</code> shift to the right otherwise to the left
- * @param startLine the first line to shift
- * @param endLine the last line to shift
- * @since 2.0
- */
- private void shiftLeft(int startLine, int endLine, String[] prefixes, boolean ignoreWhitespace) {
-
- IDocument d= getDocument();
-
- try {
-
- IRegion[] occurrences= new IRegion[endLine - startLine + 1];
-
- // find all the first occurrences of prefix in the given lines
- for (int i= 0; i < occurrences.length; i++) {
-
- IRegion line= d.getLineInformation(startLine + i);
- String text= d.get(line.getOffset(), line.getLength());
-
- int index= -1;
- int[] found= TextUtilities.indexOf(prefixes, text, 0);
- if (found[0] != -1) {
- if (ignoreWhitespace) {
- String s= d.get(line.getOffset(), found[0]);
- s= s.trim();
- if (s.length() == 0)
- index= line.getOffset() + found[0];
- } else if (found[0] == 0)
- index= line.getOffset();
- }
-
- if (index > -1) {
- // remember where prefix is in line, so that it can be removed
- int length= prefixes[found[1]].length();
- if (length == 0 && !ignoreWhitespace && line.getLength() > 0) {
- // found a non-empty line which cannot be shifted
- return;
- } else
- occurrences[i]= new Region(index, length);
- } else {
- // found a line which cannot be shifted
- return;
- }
- }
-
- // ok - change the document
- int decrement= 0;
- for (int i= 0; i < occurrences.length; i++) {
- IRegion r= occurrences[i];
- d.replace(r.getOffset() - decrement, r.getLength(), ""); //$NON-NLS-1$
- decrement += r.getLength();
- }
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println("TextViewer.shiftLeft: BadLocationException"); //$NON-NLS-1$
- }
- }
-
- /**
- * Returns whether the shown text can be printed.
- *
- * @return the viewer's printable mode
- */
- protected boolean isPrintable() {
- /*
- * 1GK7Q10: ITPUI:WIN98 - internal error after invoking print at editor view
- * Changed from returning true to testing the length of the printer queue
- */
- PrinterData[] printerList= Printer.getPrinterList();
- return (printerList != null && printerList.length > 0);
- }
-
- /**
- * Brings up a print dialog and calls <code>printContents(Printer)</code> which
- * performs the actual print.
- */
- protected void print() {
-
- final PrintDialog dialog= new PrintDialog(fTextWidget.getShell(), SWT.PRIMARY_MODAL);
- final PrinterData data= dialog.open();
-
- if (data != null) {
-
- final Printer printer= new Printer(data);
- final Runnable styledTextPrinter= fTextWidget.print(printer);
-
- Thread printingThread= new Thread("Printing") { //$NON-NLS-1$
- public void run() {
- styledTextPrinter.run();
- printer.dispose();
- }
- };
- printingThread.start();
- }
- }
-
-
- //------ find support
-
- /**
- * @see IFindReplaceTarget#canPerformFind
- */
- protected boolean canPerformFind() {
- IDocument d= getVisibleDocument();
- return (fTextWidget != null && d != null && d.getLength() > 0);
- }
-
- /**
- * @see IFindReplaceTarget#findAndSelect(int, String, boolean, boolean, boolean)
- * @deprecated as of 3.0 use {@link #findAndSelect(int, String, boolean, boolean, boolean, boolean)}
- */
- protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord) {
- try {
- return findAndSelect(startPosition, findString, forwardSearch, caseSensitive, wholeWord, false);
- } catch (IllegalStateException ex) {
- return -1;
- } catch (PatternSyntaxException ex) {
- return -1;
- }
- }
-
- /**
- * @see IFindReplaceTargetExtension3#findAndSelect(int, String, boolean, boolean, boolean, boolean)
- */
- protected int findAndSelect(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, boolean regExSearch) {
- if (fTextWidget == null)
- return -1;
-
- try {
-
- int widgetOffset= (startPosition == -1 ? startPosition : modelOffset2WidgetOffset(startPosition));
- IRegion matchRegion= getFindReplaceDocumentAdapter().find(widgetOffset, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
- if (matchRegion != null) {
- int widgetPos= matchRegion.getOffset();
- int length= matchRegion.getLength();
- if (redraws()) {
- fTextWidget.setSelectionRange(widgetPos, length);
- internalRevealRange(widgetPos, widgetPos + length);
- selectionChanged(widgetPos, length);
- } else {
- setSelectedRange(widgetOffset2ModelOffset(widgetPos), length);
- }
-
- return widgetOffset2ModelOffset(widgetPos);
- }
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$
- }
-
- return -1;
- }
-
- /**
- * @see IFindReplaceTargetExtension3#findAndSelect(int, String, boolean, boolean, boolean, boolean)
- * @since 3.0
- */
- protected int findAndSelectInRange(int startPosition, String findString, boolean forwardSearch, boolean caseSensitive, boolean wholeWord, int rangeOffset, int rangeLength, boolean regExSearch) {
- if (fTextWidget == null)
- return -1;
-
- try {
-
- int modelOffset;
- if (forwardSearch && (startPosition == -1 || startPosition < rangeOffset)) {
- modelOffset= rangeOffset;
- } else if (!forwardSearch && (startPosition == -1 || startPosition > rangeOffset + rangeLength)) {
- modelOffset= rangeOffset + rangeLength;
- } else {
- modelOffset= startPosition;
- }
-
- int widgetOffset= modelOffset2WidgetOffset(modelOffset);
- if (widgetOffset == -1)
- return -1;
-
- IRegion matchRegion= getFindReplaceDocumentAdapter().find(widgetOffset, findString, forwardSearch, caseSensitive, wholeWord, regExSearch);
- int widgetPos= -1;
- int length= 0;
- if (matchRegion != null) {
- widgetPos= matchRegion.getOffset();
- length= matchRegion.getLength();
- }
- int modelPos= widgetPos == -1 ? -1 : widgetOffset2ModelOffset(widgetPos);
-
- if (widgetPos != -1 && (modelPos < rangeOffset || modelPos + length > rangeOffset + rangeLength))
- widgetPos= -1;
-
- if (widgetPos > -1) {
-
- if (redraws()) {
- fTextWidget.setSelectionRange(widgetPos, length);
- internalRevealRange(widgetPos, widgetPos + length);
- selectionChanged(widgetPos, length);
- } else {
- setSelectedRange(modelPos, length);
- }
-
- return modelPos;
- }
-
-
- } catch (BadLocationException x) {
- if (TRACE_ERRORS)
- System.out.println(JFaceTextMessages.getString("TextViewer.error.bad_location.findAndSelect")); //$NON-NLS-1$
- }
-
- return -1;
- }
-
- //---------- text presentation support
-
- /*
- * @see ITextViewer#setTextColor(Color)
- */
- public void setTextColor(Color color) {
- if (color != null)
- setTextColor(color, 0, getDocument().getLength(), true);
- }
-
- /*
- * @see ITextViewer#setTextColor(Color, start, length, boolean)
- */
- public void setTextColor(Color color, int start, int length, boolean controlRedraw) {
-
- if (fTextWidget != null) {
-
- if (controlRedraw)
- fTextWidget.setRedraw(false);
-
- StyleRange s= new StyleRange();
- s.foreground= color;
- s.start= start;
- s.length= length;
-
- s= modelStyleRange2WidgetStyleRange(s);
- if (s != null) {
-
- if (controlRedraw)
- fTextWidget.setRedraw(false);
-
- fTextWidget.setStyleRange(s);
-
- if (controlRedraw)
- fTextWidget.setRedraw(true);
- }
- }
- }
-
- /**
- * Adds the given presentation to the viewer's style information.
- *
- * @param presentation the presentation to be added
- */
- private void addPresentation(TextPresentation presentation) {
-
- StyleRange range= presentation.getDefaultStyleRange();
- if (range != null) {
-
- range= modelStyleRange2WidgetStyleRange(range);
- if (range != null)
- fTextWidget.setStyleRange(range);
-
- Iterator e= presentation.getNonDefaultStyleRangeIterator();
- while (e.hasNext()) {
- range= (StyleRange) e.next();
- range= modelStyleRange2WidgetStyleRange(range);
- if (range != null)
- fTextWidget.setStyleRange(range);
- }
-
- } else {
- IRegion region= modelRange2WidgetRange(presentation.getCoverage());
- if (region == null)
- return;
-
- List list= new ArrayList(presentation.getDenumerableRanges());
- Iterator e= presentation.getAllStyleRangeIterator();
- while (e.hasNext()) {
- range= (StyleRange) e.next();
- range= modelStyleRange2WidgetStyleRange(range);
- if (range != null)
- list.add(range);
- }
-
- if (!list.isEmpty()) {
- StyleRange[] ranges= new StyleRange[list.size()];
- list.toArray(ranges);
- fTextWidget.replaceStyleRanges(region.getOffset(), region.getLength(), ranges);
- }
- }
- }
-
- /**
- * Applies the given presentation to the given text widget. Helper method.
- *
- * @param presentation the style information
- * @since 2.1
- */
- private void applyTextPresentation(TextPresentation presentation) {
-
- List list= new ArrayList(presentation.getDenumerableRanges());
- Iterator e= presentation.getAllStyleRangeIterator();
- while (e.hasNext()) {
- StyleRange range= (StyleRange) e.next();
- range= modelStyleRange2WidgetStyleRange(range);
- if (range != null)
- list.add(range);
- }
-
- if (!list.isEmpty()) {
- StyleRange[] ranges= new StyleRange[list.size()];
- list.toArray(ranges);
- fTextWidget.setStyleRanges(ranges);
- }
- }
-
- /**
- * Returns the visible region if it is not equal to the whole document.
- * Otherwise returns <code>null</code>.
- *
- * @return the viewer's visible region if smaller than input document, otherwise <code>null</code>
- */
- protected IRegion _internalGetVisibleRegion() {
-
- IDocument document= getVisibleDocument();
- if (document instanceof ChildDocument) {
- Position p= ((ChildDocument) document).getParentDocumentRange();
- return new Region(p.getOffset(), p.getLength());
- }
-
- return null;
- }
-
- /*
- * @see ITextViewer#changeTextPresentation(TextPresentation, boolean)
- */
- public void changeTextPresentation(TextPresentation presentation, boolean controlRedraw) {
-
- if (presentation == null || !redraws())
- return;
-
- if (fTextWidget == null)
- return;
-
-
- /*
- * Call registered text presentation listeners
- * and let them apply their presentation.
- */
- if (fTextPresentationListeners != null) {
- ArrayList listeners= new ArrayList(fTextPresentationListeners);
- for (int i= 0, size= listeners.size(); i < size; i++) {
- ITextPresentationListener listener= (ITextPresentationListener)listeners.get(i);
- listener.applyTextPresentation(presentation);
- }
- }
-
- if (presentation.isEmpty())
- return;
-
- if (controlRedraw)
- fTextWidget.setRedraw(false);
-
- if (fReplaceTextPresentation)
- applyTextPresentation(presentation);
- else
- addPresentation(presentation);
-
- if (controlRedraw)
- fTextWidget.setRedraw(true);
- }
-
- /*
- * @see ITextViewer#getFindReplaceTarget()
- */
- public IFindReplaceTarget getFindReplaceTarget() {
- if (fFindReplaceTarget == null)
- fFindReplaceTarget= new FindReplaceTarget();
- return fFindReplaceTarget;
- }
-
- /**
- * Returns the find/replace document adapter.
- *
- * @return the find/replace document adapter.
- * @since 3.0
- */
- protected FindReplaceDocumentAdapter getFindReplaceDocumentAdapter() {
- if (fFindReplaceDocumentAdapter == null)
- fFindReplaceDocumentAdapter= new FindReplaceDocumentAdapter(getVisibleDocument());
- return fFindReplaceDocumentAdapter;
- }
-
- /*
- * @see ITextViewer#getTextOperationTarget()
- */
- public ITextOperationTarget getTextOperationTarget() {
- return this;
- }
-
- /*
- * @see ITextViewerExtension#appendVerifyKeyListener(VerifyKeyListener)
- * @since 2.0
- */
- public void appendVerifyKeyListener(VerifyKeyListener listener) {
- int index= fVerifyKeyListenersManager.numberOfListeners();
- fVerifyKeyListenersManager.insertListener(listener, index);
- }
-
- /*
- * @see ITextViewerExtension#prependVerifyKeyListener(VerifyKeyListener)
- * @since 2.0
- */
- public void prependVerifyKeyListener(VerifyKeyListener listener) {
- fVerifyKeyListenersManager.insertListener(listener, 0);
-
- }
-
- /*
- * @see ITextViewerExtension#removeVerifyKeyListener(VerifyKeyListener)
- * @since 2.0
- */
- public void removeVerifyKeyListener(VerifyKeyListener listener) {
- fVerifyKeyListenersManager.removeListener(listener);
- }
-
- /*
- * @see ITextViewerExtension#getMark()
- * @since 2.0
- */
- public int getMark() {
- return fMarkPosition == null || fMarkPosition.isDeleted() ? -1 : fMarkPosition.getOffset();
- }
-
- /*
- * @see ITextViewerExtension#setMark(int)
- * @since 2.0
- */
- public void setMark(int offset) {
-
- // clear
- if (offset == -1) {
- if (fMarkPosition != null && !fMarkPosition.isDeleted()) {
-
- IDocument document= getDocument();
- if (document != null)
- document.removePosition(fMarkPosition);
- }
-
- fMarkPosition= null;
-
- markChanged(-1, 0);
-
- // set
- } else {
-
- IDocument document= getDocument();
- if (document == null) {
- fMarkPosition= null;
- return;
- }
-
- if (fMarkPosition != null)
- document.removePosition(fMarkPosition);
-
- fMarkPosition= null;
-
- try {
-
- Position position= new Position(offset);
- document.addPosition(MARK_POSITION_CATEGORY, position);
- fMarkPosition= position;
-
- } catch (BadLocationException e) {
- return;
- } catch (BadPositionCategoryException e) {
- return;
- }
-
- markChanged(modelOffset2WidgetOffset(fMarkPosition.offset), 0);
- }
- }
-
- /*
- * @see Viewer#inputChanged(Object, Object)
- * @since 2.0
- */
- protected void inputChanged(Object newInput, Object oldInput) {
-
- IDocument oldDocument= (IDocument) oldInput;
- if (oldDocument != null) {
- if (fMarkPosition != null && !fMarkPosition.isDeleted())
- oldDocument.removePosition(fMarkPosition);
-
- try {
- oldDocument.removePositionUpdater(fMarkPositionUpdater);
- oldDocument.removePositionCategory(MARK_POSITION_CATEGORY);
-
- } catch (BadPositionCategoryException e) {
- }
- }
-
- fMarkPosition= null;
-
- super.inputChanged(newInput, oldInput);
-
- IDocument newDocument= (IDocument) newInput;
- if (newDocument != null) {
- newDocument.addPositionCategory(MARK_POSITION_CATEGORY);
- newDocument.addPositionUpdater(fMarkPositionUpdater);
- }
- }
-
- /**
- * Informs all text listeners about the change of the viewer's redraw state.
- * @since 2.0
- */
- private void fireRedrawChanged() {
- fWidgetCommand.start= 0;
- fWidgetCommand.length= 0;
- fWidgetCommand.text= null;
- fWidgetCommand.event= null;
- updateTextListeners(fWidgetCommand);
- }
-
- /**
- * Forgets the previously remembered selection position. After that
- * call the selection position can no longer be queried and is longer updated
- * in responds to content changes of the viewer.
- *
- * @return the remembered and updated selection position or <code>null</code> if no selection position has been remembered
- * @since 2.1
- */
- private Point forgetDocumentSelection() {
- if (fDocumentSelection == null)
- return null;
-
- Point selection= fDocumentSelection.isDeleted() ? null : fDocumentSelection.getSelection();
- IDocument document= getDocument();
- if (document != null)
- document.removePosition(fDocumentSelection);
- fDocumentSelection= null;
-
- return selection;
- }
-
- /**
- * Enables the redrawing of this text viewer.
- * @since 2.0
- */
- protected void enabledRedrawing() {
- enabledRedrawing(-1);
- }
- /**
- * Enables the redrawing of this text viewer.
- *
- * @param topIndex the top index to be set or <code>-1</code>
- * @since 3.0
- */
- protected void enabledRedrawing(int topIndex) {
- if (fDocumentAdapter instanceof IDocumentAdapterExtension) {
- IDocumentAdapterExtension extension= (IDocumentAdapterExtension) fDocumentAdapter;
- StyledText textWidget= getTextWidget();
- if (textWidget != null && !textWidget.isDisposed()) {
- int topPixel= textWidget.getTopPixel();
- extension.resumeForwardingDocumentChanges();
- if (topIndex > -1) {
- try {
- setTopIndex(topIndex);
- } catch (IllegalArgumentException x) {
- // changes don't allow for the previous top pixel
- }
- } else if (topPixel > -1) {
- try {
- textWidget.setTopPixel(topPixel);
- } catch (IllegalArgumentException x) {
- // changes don't allow for the previous top pixel
- }
- }
- }
- }
-
- Point selection= forgetDocumentSelection();
- if (selection != null) {
- setSelectedRange(selection.x, selection.y);
- if (topIndex == -1)
- revealRange(selection.x, selection.y);
- }
-
- if (fTextWidget != null && !fTextWidget.isDisposed())
- fTextWidget.setRedraw(true);
-
- fireRedrawChanged();
- }
-
- /**
- * Remembers the current selection in a <code>SelectionPosition</code> . The selection
- * position can be queried and is updated to changes made to the viewer's contents.
- * @since 2.1
- */
- private void rememberDocumentSelection() {
- Point selection= getSelectedRange();
- if (selection != null) {
- SelectionPosition p= new SelectionPosition(selection);
- IDocument document= getDocument();
- if (document != null) {
- try {
- document.addPosition(p);
- fDocumentSelection= p;
- } catch (BadLocationException x) {
- }
- }
- }
- }
-
- /**
- * Disables the redrawing of this text viewer. Subclasses may extend.
- * @since 2.0
- */
- protected void disableRedrawing() {
-
- rememberDocumentSelection();
-
- if (fDocumentAdapter instanceof IDocumentAdapterExtension) {
- IDocumentAdapterExtension extension= (IDocumentAdapterExtension) fDocumentAdapter;
- extension.stopForwardingDocumentChanges();
- }
-
- if (fTextWidget != null && !fTextWidget.isDisposed())
- fTextWidget.setRedraw(false);
-
- fireRedrawChanged();
- }
-
- /*
- * @see ITextViewerExtension#setRedraw(boolean)
- * @since 2.0
- */
- public final void setRedraw(boolean redraw) {
- setRedraw(redraw, -1);
- }
-
- /**
- * Basically same functionality as
- * <code>ITextViewerExtension.setRedraw(boolean)</code>. Adds a way for
- * subclasses to pass in a desired top index that should be used when
- * <code>redraw</code> is <code>true</code>. If <code>topIndex</code>
- * is -1, this method is identical to
- * <code>ITextViewerExtension.setRedraw(boolean)</code>.
- *
- * @see ITextViewerExtension#setRedraw(boolean)
- *
- * @param redraw
- * @param topIndex
- * @since 3.0
- */
- protected final void setRedraw(boolean redraw, int topIndex) {
- if (!redraw) {
-
- ++ fRedrawCounter;
- if (fRedrawCounter == 1)
- disableRedrawing();
-
- } else {
- -- fRedrawCounter;
- if (fRedrawCounter == 0) {
- if (topIndex == -1)
- enabledRedrawing();
- else
- enabledRedrawing(topIndex);
- }
- }
- }
-
- /**
- * Returns whether this viewer redraws itself.
- *
- * @return <code>true</code> if this viewer redraws itself
- * @since 2.0
- */
- protected final boolean redraws() {
- return fRedrawCounter <= 0;
- }
-
- /**
- * Starts the sequential rewrite mode of the viewer's document.
- *
- * @param normalized <code>true</code> if the rewrite is performed from the start to the end of the document
- * @since 2.0
- */
- protected final void startSequentialRewriteMode(boolean normalized) {
- IDocument document= getDocument();
- if (document instanceof IDocumentExtension) {
- IDocumentExtension extension= (IDocumentExtension) document;
- extension.startSequentialRewrite(normalized);
- }
- }
-
- /**
- * Sets the sequential rewrite mode of the viewer's document.
- * @since 2.0
- */
- protected final void stopSequentialRewriteMode() {
- IDocument document= getDocument();
- if (document instanceof IDocumentExtension) {
- IDocumentExtension extension= (IDocumentExtension) document;
- extension.stopSequentialRewrite();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension#getRewriteTarget()
- * @since 2.0
- */
- public IRewriteTarget getRewriteTarget() {
- if (fRewriteTarget == null)
- fRewriteTarget= new RewriteTarget();
- return fRewriteTarget;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension2#getCurrentTextHover()
- */
- public ITextHover getCurrentTextHover() {
- if (fTextHoverManager == null)
- return null;
- return fTextHoverManager.getCurrentTextHover();
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension2#getHoverEventLocation()
- */
- public Point getHoverEventLocation() {
- if (fTextHoverManager == null)
- return null;
- return fTextHoverManager.getHoverEventLocation();
- }
-
- /**
- * Returns the paint manager of this viewer.
- *
- * @return the paint manager of this viewer
- * @since 2.1
- */
- protected PaintManager getPaintManager() {
- if (fPaintManager == null)
- fPaintManager= new PaintManager(this);
- return fPaintManager;
- }
-
- /**
- * Adds the given painter to this viewer. If the painter is already registered
- * this method is without effect.
- *
- * @param painter the painter to be added
- * @since 2.1
- */
- public void addPainter(IPainter painter) {
- getPaintManager().addPainter(painter);
- }
-
- /**
- * Removes the given painter from this viewer. If the painter has previously not been
- * added to this viewer this method is without effect.
- *
- * @param painter the painter to be removed
- * @since 2.1
- */
- public void removePainter(IPainter painter) {
- getPaintManager().removePainter(painter);
- }
-
- // ----------------------------------- conversions -------------------------------------------------------
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#modelLine2WidgetLine(int)
- * @since 2.1
- */
- public int modelLine2WidgetLine(int modelLine) {
- if (fInformationMapping == null)
- return modelLine;
-
- try {
- return fInformationMapping.toImageLine(modelLine);
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#modelOffset2WidgetOffset(int)
- * @since 2.1
- */
- public int modelOffset2WidgetOffset(int modelOffset) {
- if (fInformationMapping == null)
- return modelOffset;
-
- try {
- return fInformationMapping.toImageOffset(modelOffset);
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#modelRange2WidgetRange(org.eclipse.jface.text.IRegion)
- * @since 2.1
- */
- public IRegion modelRange2WidgetRange(IRegion modelRange) {
- if (fInformationMapping == null)
- return modelRange;
-
- try {
-
- if (modelRange.getLength() < 0) {
- Region reversed= new Region(modelRange.getOffset() + modelRange.getLength(), -modelRange.getLength());
- IRegion result= fInformationMapping.toImageRegion(reversed);
- return new Region(result.getOffset() + result.getLength(), -result.getLength());
- } else {
- return fInformationMapping.toImageRegion(modelRange);
- }
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#widgetlLine2ModelLine(int)
- * @since 2.1
- */
- public int widgetlLine2ModelLine(int widgetLine) {
- return widgetLine2ModelLine(widgetLine);
- }
-
- /**
- * @see ITextViewerExtension5#widgetLine2ModelLine(int)
- * @since 3.0
- */
- public int widgetLine2ModelLine(int widgetLine) {
- if (fInformationMapping == null)
- return widgetLine;
-
- try {
- return fInformationMapping.toOriginLine(widgetLine);
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#widgetOffset2ModelOffset(int)
- * @since 2.1
- */
- public int widgetOffset2ModelOffset(int widgetOffset) {
- if (fInformationMapping == null)
- return widgetOffset;
-
- try {
- return fInformationMapping.toOriginOffset(widgetOffset);
- } catch (BadLocationException x) {
- if (widgetOffset == getVisibleDocument().getLength()) {
- IRegion coverage= fInformationMapping.getCoverage();
- return coverage.getOffset() + coverage.getLength();
- }
- }
-
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#widgetRange2ModelRange(org.eclipse.jface.text.IRegion)
- * @since 2.1
- */
- public IRegion widgetRange2ModelRange(IRegion widgetRange) {
- if (fInformationMapping == null)
- return widgetRange;
-
- try {
-
- if (widgetRange.getLength() < 0) {
- Region reveresed= new Region(widgetRange.getOffset() + widgetRange.getLength(), -widgetRange.getLength());
- IRegion result= fInformationMapping.toOriginRegion(reveresed);
- return new Region(result.getOffset() + result.getLength(), -result.getLength());
- } else {
- return fInformationMapping.toOriginRegion(widgetRange);
- }
-
- } catch (BadLocationException x) {
- int modelOffset= widgetOffset2ModelOffset(widgetRange.getOffset());
- if (modelOffset > -1) {
- int modelEndOffset= widgetOffset2ModelOffset(widgetRange.getOffset() + widgetRange.getLength());
- if (modelEndOffset > -1)
- return new Region(modelOffset, modelEndOffset - modelOffset);
- }
- }
-
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#getModelCoverage()
- * @since 2.1
- */
- public IRegion getModelCoverage() {
- if (fInformationMapping == null) {
- IDocument document= getDocument();
- if (document == null)
- return null;
- return new Region(0, document.getLength());
- }
-
- return fInformationMapping.getCoverage();
- }
-
- /**
- * Returns the line of the widget whose corresponding line in the viewer's document
- * is closest to the given line in the viewer's document.
- *
- * @param modelLine the line in the viewer's document
- * @return the line in the widget that corresponds best to the given line in the viewer's document
- * @since 2.1
- */
- protected int getClosestWidgetLineForModelLine(int modelLine) {
- if (fInformationMapping == null)
- return modelLine;
-
- try {
- return fInformationMapping.toClosestImageLine(modelLine);
- } catch (BadLocationException x) {
- }
-
- return -1;
- }
-
- /**
- * Translates a style range given relative to the viewer's document into style
- * ranges relative to the viewer's widget.
- *
- * @param range the style range in the coordinates of the viewer's document
- * @return the style range in the coordinates of the viewer's widget
- * @since 2.1
- */
- protected StyleRange modelStyleRange2WidgetStyleRange(StyleRange range) {
- IRegion region= modelRange2WidgetRange(new Region(range.start, range.length));
- if (region != null) {
- StyleRange result= (StyleRange) range.clone();
- result.start= region.getOffset();
- result.length= region.getLength();
- return result;
- }
- return null;
- }
-
- /**
- * @see #modelRange2WidgetRange(IRegion)
- *
- * @param modelPosition the position describing a range in the viewer's document
- * @return a region describing a range in the viewer's widget
- * @since 2.1
- */
- protected IRegion modelRange2WidgetRange(Position modelPosition) {
- return modelRange2WidgetRange(new Region(modelPosition.getOffset(), modelPosition.getLength()));
- }
-
- /**
- * Translates the widget region of the given verify event into
- * the corresponding region of the viewer's document.
- *
- * @param event the verify event
- * @return the region of the viewer's document corresponding to the verify event
- * @since 2.1
- */
- protected IRegion event2ModelRange(VerifyEvent event) {
-
- Region region= null;
- if (event.start <= event.end)
- region= new Region(event.start, event.end - event.start);
- else
- region= new Region(event.end, event.start - event.end);
-
- return widgetRange2ModelRange(region);
- }
-
- /**
- * Translates the given widget selection into the corresponding region
- * of the viewer's document.
- *
- * @param widgetSelection the widget selection
- * @return the region of the viewer's document corresponding to the widget selection
- * @since 2.1
- */
- protected Point widgetSelection2ModelSelection(Point widgetSelection) {
- IRegion region= new Region(widgetSelection.x, widgetSelection.y);
- region= widgetRange2ModelRange(region);
- return region == null ? null : new Point(region.getOffset(), region.getLength());
- }
-
- /**
- * Translates the given selection range of the viewer's document into
- * the corresponding widget range.
- *
- * @param modelSelection the selection range of the viewer's document
- * @return the widget range corresponding to the selection range
- * @since 2.1
- */
- protected Point modelSelection2WidgetSelection(Point modelSelection) {
- if (fInformationMapping == null)
- return modelSelection;
-
- try {
- IRegion region= new Region(modelSelection.x, modelSelection.y);
- region= fInformationMapping.toImageRegion(region);
- return new Point(region.getOffset(), region.getLength());
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension3#widgetLineOfWidgetOffset(int)
- */
- public int widgetLineOfWidgetOffset(int widgetOffset) {
- IDocument document= getVisibleDocument();
- if (document != null) {
- try {
- return document.getLineOfOffset(widgetOffset);
- } catch (BadLocationException e) {
- }
- }
- return -1;
- }
-
- /*
- * @see org.eclipse.jface.text.ITextViewerExtension4#moveFocusToWidgetToken()
- * @since 3.0
- */
- public boolean moveFocusToWidgetToken() {
- if (fWidgetTokenKeeper instanceof IWidgetTokenKeeperExtension) {
- IWidgetTokenKeeperExtension extension= (IWidgetTokenKeeperExtension) fWidgetTokenKeeper;
- return extension.setFocus(this);
- } else {
- return false;
- }
- }
-
- /**
- * Sets the document partitioning of this viewer. The partitioning is used by this viewer to
- * access partitioning information of the viewers input document.
- *
- * @param partitioning the partitioning name
- * @since 3.0
- */
- public void setDocumentPartitioning(String partitioning) {
- fPartitioning= partitioning;
- }
-
- /**
- * Returns the document partitioning for this viewer.
- *
- * @return the document partitioning for this viewer
- * @since 3.0
- */
- protected String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- //---- Text presentation listeners ----
-
- /*
- * @see ITextViewerExtension4#addTextPresentationListener(ITextPresentationListener)
- * @since 3.0
- */
- public void addTextPresentationListener(ITextPresentationListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextPresentationListeners == null)
- fTextPresentationListeners= new ArrayList();
-
- if (!fTextPresentationListeners.contains(listener))
- fTextPresentationListeners.add(listener);
- }
-
- /*
- * @see ITextViewerExtension4#removeTextPresentationListener(ITextPresentationListener)
- * @since 3.0
- */
- public void removeTextPresentationListener(ITextPresentationListener listener) {
-
- Assert.isNotNull(listener);
-
- if (fTextPresentationListeners != null) {
- fTextPresentationListeners.remove(listener);
- if (fTextPresentationListeners.size() == 0)
- fTextPresentationListeners= null;
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java
deleted file mode 100644
index 5277b8c8e6f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/TextViewerHoverManager.java
+++ /dev/null
@@ -1,417 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text;
-
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Display;
-
-
-/**
- * This manager controls the layout, content, and visibility of an information
- * control in reaction to mouse hover events issued by the text widget of a
- * text viewer. It overrides <code>computeInformation</code>, so that the
- * computation is performed in a dedicated background thread. This implies
- * that the used <code>ITextHover</code> objects must be capable of
- * operating in a non-UI thread.
- *
- * @since 2.0
- */
-class TextViewerHoverManager extends AbstractHoverInformationControlManager implements IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
-
-
- /**
- * Priority of the hovers managed by this manager.
- * Default value: <code>0</code>;
- * @since 3.0
- */
- public final static int WIDGET_PRIORITY= 0;
-
-
- /** The text viewer */
- private TextViewer fTextViewer;
- /** The hover information computation thread */
- private Thread fThread;
- /** The stopper of the computation thread */
- private ITextListener fStopper;
- /** Internal monitor */
- private Object fMutex= new Object();
- /** The currently shown text hover. */
- private volatile ITextHover fTextHover;
- /**
- * Tells whether the next mouse hover event
- * should be processed.
- * @since 3.0
- */
- private boolean fProcessMouseHoverEvent= true;
- /**
- * Internal mouse move listener.
- * @since 3.0
- */
- private MouseMoveListener fMouseMoveListener;
- /**
- * Internal viewport listener.
- * @since 3.0
- */
- private IViewportListener fViewportListener;
-
-
- /**
- * Creates a new text viewer hover manager specific for the given text viewer.
- * The manager uses the given information control creator.
- *
- * @param textViewer the viewer for which the controller is created
- * @param creator the information control creator
- */
- public TextViewerHoverManager(TextViewer textViewer, IInformationControlCreator creator) {
- super(creator);
- fTextViewer= textViewer;
- fStopper= new ITextListener() {
- public void textChanged(TextEvent event) {
- synchronized (fMutex) {
- if (fThread != null) {
- fThread.interrupt();
- fThread= null;
- }
- }
- }
- };
- fViewportListener= new IViewportListener() {
- /*
- * @see org.eclipse.jface.text.IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int verticalOffset) {
- fProcessMouseHoverEvent= false;
- }
- };
- fTextViewer.addViewportListener(fViewportListener);
- fMouseMoveListener= new MouseMoveListener() {
- /*
- * @see MouseMoveListener#mouseMove(MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
- fProcessMouseHoverEvent= true;
- }
- };
- fTextViewer.getTextWidget().addMouseMoveListener(fMouseMoveListener);
- }
-
- /**
- * Determines all necessary details and delegates the computation into
- * a background thread.
- */
- protected void computeInformation() {
-
- if (!fProcessMouseHoverEvent) {
- setInformation(null, null);
- return;
- }
-
- Point location= getHoverEventLocation();
- int offset= computeOffsetAtLocation(location.x, location.y);
- if (offset == -1) {
- setInformation(null, null);
- return;
- }
-
- final ITextHover hover= fTextViewer.getTextHover(offset, getHoverEventStateMask());
- if (hover == null) {
- setInformation(null, null);
- return;
- }
-
- final IRegion region= hover.getHoverRegion(fTextViewer, offset);
- if (region == null) {
- setInformation(null, null);
- return;
- }
-
- final Rectangle area= computeArea(region);
- if (area == null || area.isEmpty()) {
- setInformation(null, null);
- return;
- }
-
- if (fThread != null) {
- setInformation(null, null);
- return;
- }
-
- fThread= new Thread("Text Viewer Hover Presenter") { //$NON-NLS-1$
- public void run() {
- // http://bugs.eclipse.org/bugs/show_bug.cgi?id=17693
- boolean hasFinished= false;
- try {
- if (fThread != null) {
- String information;
- try {
- information= hover.getHoverInfo(fTextViewer, region);
- } catch (ArrayIndexOutOfBoundsException x) {
- /*
- * This code runs in a separate thread which can
- * lead to text offsets being out of bounds when
- * computing the hover info (see bug 32848).
- */
- information= null;
- }
-
- if (hover instanceof ITextHoverExtension)
- setCustomInformationControlCreator(((ITextHoverExtension) hover).getHoverControlCreator());
- else
- setCustomInformationControlCreator(null);
-
- setInformation(information, area);
- if (information != null && area != null)
- fTextHover= hover;
- } else {
- setInformation(null, null);
- }
- hasFinished= true;
- } finally {
- synchronized (fMutex) {
- if (fTextViewer != null)
- fTextViewer.removeTextListener(fStopper);
- fThread= null;
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=44756
- if (!hasFinished)
- setInformation(null, null);
- }
- }
- }
- };
-
- fThread.setDaemon(true);
- fThread.setPriority(Thread.MIN_PRIORITY);
- synchronized (fMutex) {
- fTextViewer.addTextListener(fStopper);
- fThread.start();
- }
- }
-
- /**
- * As computation is done in the background, this method is
- * also called in the background thread. Delegates the control
- * flow back into the ui thread, in order to allow displaying the
- * information in the information control.
- */
- protected void presentInformation() {
- if (fTextViewer == null)
- return;
-
- StyledText textWidget= fTextViewer.getTextWidget();
- if (textWidget != null && !textWidget.isDisposed()) {
- Display display= textWidget.getDisplay();
- if (display == null)
- return;
-
- display.asyncExec(new Runnable() {
- public void run() {
- doPresentInformation();
- }
- });
- }
- }
-
- /*
- * @see AbstractInformationControlManager#presentInformation()
- */
- protected void doPresentInformation() {
- super.presentInformation();
- }
-
- /**
- * Computes the document offset underlying the given text widget coordinates.
- * This method uses a linear search as it cannot make any assumption about
- * how the document is actually presented in the widget. (Covers cases such
- * as bidi text.)
- *
- * @param x the x coordinate inside the text widget
- * @param y the y coordinate inside the text widget
- * @return the document offset corresponding to the given point
- */
- private int computeOffsetAtLocation(int x, int y) {
-
- try {
-
- StyledText styledText= fTextViewer.getTextWidget();
- int widgetOffset= styledText.getOffsetAtLocation(new Point(x, y));
-
- if (fTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- return extension.widgetOffset2ModelOffset(widgetOffset);
- }
-
- return widgetOffset + fTextViewer._getVisibleRegionOffset();
-
- } catch (IllegalArgumentException e) {
- return -1;
- }
- }
-
- /**
- * Determines graphical area covered by the given text region.
- *
- * @param region the region whose graphical extend must be computed
- * @return the graphical extend of the given region
- */
- private Rectangle computeArea(IRegion region) {
-
- IRegion widgetRegion= modelRange2WidgetRange(region);
- int start= widgetRegion.getOffset();
- int end= widgetRegion.getOffset() + widgetRegion.getLength();
-
- StyledText styledText= fTextViewer.getTextWidget();
- Point upperLeft= styledText.getLocationAtOffset(start);
- Point lowerRight= new Point(upperLeft.x, upperLeft.y);
-
- for (int i= start +1; i < end; i++) {
-
- Point p= styledText.getLocationAtOffset(i);
-
- if (upperLeft.x > p.x)
- upperLeft.x= p.x;
-
- if (upperLeft.y > p.y)
- upperLeft.y= p.y;
-
- if (lowerRight.x < p.x)
- lowerRight.x= p.x;
-
- if (lowerRight.y < p.y)
- lowerRight.y= p.y;
- }
-
- lowerRight.x += fTextViewer.getAverageCharWidth();
- lowerRight.y += styledText.getLineHeight();
-
- int width= lowerRight.x - upperLeft.x;
- int height= lowerRight.y - upperLeft.y;
- return new Rectangle(upperLeft.x, upperLeft.y, width, height);
- }
-
- /**
- * Translates a given region of the text viewer's document into
- * the corresponding region of the viewer's widget.
- *
- * @param region the document region
- * @return the corresponding widget region
- * @since 2.1
- */
- private IRegion modelRange2WidgetRange(IRegion region) {
- if (fTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- return extension.modelRange2WidgetRange(region);
- }
-
- IRegion visibleRegion= fTextViewer.getVisibleRegion();
- int start= region.getOffset() - visibleRegion.getOffset();
- int end= start + region.getLength();
- if (end > visibleRegion.getLength())
- end= visibleRegion.getLength();
-
- return new Region(start, end - start);
- }
-
- /*
- * @see AbstractInformationControlManager#showInformationControl(Rectangle)
- */
- protected void showInformationControl(Rectangle subjectArea) {
- if (fTextViewer != null && fTextViewer.requestWidgetToken(this, WIDGET_PRIORITY))
- super.showInformationControl(subjectArea);
- }
-
- /*
- * @see AbstractInformationControlManager#hideInformationControl()
- */
- protected void hideInformationControl() {
- try {
- fTextHover= null;
- super.hideInformationControl();
- } finally {
- if (fTextViewer != null)
- fTextViewer.releaseWidgetToken(this);
- }
- }
-
- /*
- * @see AbstractInformationControlManager#handleInformationControlDisposed()
- */
- protected void handleInformationControlDisposed() {
- try {
- super.handleInformationControlDisposed();
- } finally {
- if (fTextViewer != null)
- fTextViewer.releaseWidgetToken(this);
- }
- }
-
- /*
- * @see IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner)
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner) {
- fTextHover= null;
- super.hideInformationControl();
- return true;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(org.eclipse.jface.text.IWidgetTokenOwner, int)
- * @since 3.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) {
- if (priority > WIDGET_PRIORITY) {
- fTextHover= null;
- super.hideInformationControl();
- return true;
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#setFocus(org.eclipse.jface.text.IWidgetTokenOwner)
- * @since 3.0
- */
- public boolean setFocus(IWidgetTokenOwner owner) {
- return false;
- }
-
- /**
- * Returns the currently shown text hover or <code>null</code> if no text
- * hover is shown.
- *
- * @return the currently shown text hover or <code>null</code>
- */
- protected ITextHover getCurrentTextHover() {
- return fTextHover;
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractHoverInformationControlManager#dispose()
- * @since 3.0
- */
- public void dispose() {
- if (fTextViewer != null) {
- fTextViewer.removeViewportListener(fViewportListener);
- fViewportListener= null;
-
- StyledText st= fTextViewer.getTextWidget();
- if (st != null && !st.isDisposed())
- st.removeMouseMoveListener(fMouseMoveListener);
- fMouseMoveListener= null;
- }
- super.dispose();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java
deleted file mode 100644
index 2d90eb24503..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/AdditionalInfoController.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-import org.eclipse.jface.text.AbstractInformationControlManager;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IInformationControlExtension3;
-
-
-
-/**
- * Displays the additional information available for a completion proposal.
- *
- * @since 2.0
- */
-class AdditionalInfoController extends AbstractInformationControlManager implements Runnable {
-
- /**
- * Internal table selection listener.
- */
- private class TableSelectionListener implements SelectionListener {
-
- /*
- * @see SelectionListener#widgetSelected(SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- handleTableSelectionChanged();
- }
-
- /*
- * @see SelectionListener#widgetDefaultSelected(SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- }
- }
-
-
- /** The proposal table */
- private Table fProposalTable;
- /** The thread controlling the delayed display of the additional info */
- private Thread fThread;
- /** Indicates whether the display delay has been reset */
- private boolean fIsReset= false;
- /** Object to synchronize display thread and table selection changes */
- private final Object fMutex= new Object();
- /**
- * Thread access lock.
- * since 3.0
- */
- private final Object fThreadAccess= new Object();
- /** Object to synchronize initial display of additonal info */
- private Object fStartSignal;
- /** The table selection listener */
- private SelectionListener fSelectionListener= new TableSelectionListener();
- /** The delay after which additional information is displayed */
- private int fDelay;
-
-
- /**
- * Creates a new additional information controller.
- *
- * @param creator the information control creator to be used by this controller
- * @param delay time in milliseconds after which additional info should be displayed
- */
- AdditionalInfoController(IInformationControlCreator creator, int delay) {
- super(creator);
- fDelay= delay;
- setAnchor(ANCHOR_RIGHT);
- setFallbackAnchors(new Anchor[] { ANCHOR_LEFT, ANCHOR_BOTTOM, ANCHOR_RIGHT });
- }
-
- /*
- * @see AbstractInformationControlManager#install(Control)
- */
- public void install(Control control) {
-
- if (fProposalTable == control) {
- // already installed
- return;
- }
-
- super.install(control);
-
- Assert.isTrue(control instanceof Table);
- fProposalTable= (Table) control;
- fProposalTable.addSelectionListener(fSelectionListener);
- synchronized (fThreadAccess) {
- if (fThread != null)
- fThread.interrupt();
- fThread= new Thread(this, JFaceTextMessages.getString("InfoPopup.info_delay_timer_name")); //$NON-NLS-1$
-
- fStartSignal= new Object();
- synchronized (fStartSignal) {
- fThread.start();
- try {
- // wait until thread is ready
- fStartSignal.wait();
- } catch (InterruptedException x) {
- }
- }
- }
- }
-
- /*
- * @see AbstractInformationControlManager#disposeInformationControl()
- */
- public void disposeInformationControl() {
-
- synchronized (fThreadAccess) {
- if (fThread != null) {
- fThread.interrupt();
- fThread= null;
- }
- }
-
- if (fProposalTable != null && !fProposalTable.isDisposed()) {
- fProposalTable.removeSelectionListener(fSelectionListener);
- fProposalTable= null;
- }
-
- super.disposeInformationControl();
- }
-
- /*
- * @see java.lang.Runnable#run()
- */
- public void run() {
- try {
- while (true) {
-
- synchronized (fMutex) {
-
- if (fStartSignal != null) {
- synchronized (fStartSignal) {
- fStartSignal.notifyAll();
- fStartSignal= null;
- }
- }
-
- // Wait for a selection event to occur.
- fMutex.wait();
-
- while (true) {
- fIsReset= false;
- // Delay before showing the popup.
- fMutex.wait(fDelay);
- if (!fIsReset)
- break;
- }
- }
-
- if (fProposalTable != null && !fProposalTable.isDisposed()) {
- fProposalTable.getDisplay().asyncExec(new Runnable() {
- public void run() {
- if (!fIsReset)
- showInformation();
- }
- });
- }
-
- }
- } catch (InterruptedException e) {
- }
-
- synchronized (fThreadAccess) {
- // only null fThread if it is us!
- if (Thread.currentThread() == fThread)
- fThread= null;
- }
- }
-
- /**
- *Handles a change of the line selected in the associated selector.
- */
- public void handleTableSelectionChanged() {
-
- if (fProposalTable != null && !fProposalTable.isDisposed() && fProposalTable.isVisible()) {
- synchronized (fMutex) {
- fIsReset= true;
- fMutex.notifyAll();
- }
- }
- }
-
- /*
- * @see AbstractInformationControlManager#computeInformation()
- */
- protected void computeInformation() {
-
- if (fProposalTable == null || fProposalTable.isDisposed())
- return;
-
- TableItem[] selection= fProposalTable.getSelection();
- if (selection != null && selection.length > 0) {
-
- TableItem item= selection[0];
-
- // compute information
- String information= null;
- Object d= item.getData();
-
- if (d instanceof ICompletionProposal) {
- ICompletionProposal p= (ICompletionProposal) d;
- information= p.getAdditionalProposalInfo();
- }
-
- if (d instanceof ICompletionProposalExtension3)
- setCustomInformationControlCreator(((ICompletionProposalExtension3) d).getInformationControlCreator());
- else
- setCustomInformationControlCreator(null);
-
- // compute subject area
- setMargins(4, -2);
- Rectangle area= fProposalTable.getBounds();
- area.x= 0; // subject area is the whole subject control
- area.y= 0;
-
- // set information & subject area
- setInformation(information, area);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractInformationControlManager#computeSizeConstraints(Control, IInformationControl)
- */
- protected Point computeSizeConstraints(Control subjectControl, IInformationControl informationControl) {
- Point sizeConstraint= super.computeSizeConstraints(subjectControl, informationControl);
- Point size= subjectControl.getSize();
-
- Rectangle otherTrim= subjectControl.getShell().computeTrim(0, 0, 0, 0);
- size.x += otherTrim.width;
- size.y += otherTrim.height;
-
- if (informationControl instanceof IInformationControlExtension3) {
- Rectangle thisTrim= ((IInformationControlExtension3)informationControl).computeTrim();
- size.x -= thisTrim.width;
- size.y -= thisTrim.height;
- }
-
- if (sizeConstraint.x < size.x)
- sizeConstraint.x= size.x;
- if (sizeConstraint.y < size.y)
- sizeConstraint.y= size.y;
- return sizeConstraint;
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java
deleted file mode 100644
index bcf3e9edec2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposal.java
+++ /dev/null
@@ -1,135 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-
-
-/**
- * The standard implementation of the <code>ICompletionProposal</code> interface.
- */
-public final class CompletionProposal implements ICompletionProposal {
-
- /** The string to be displayed in the completion proposal popup */
- private String fDisplayString;
- /** The replacement string */
- private String fReplacementString;
- /** The replacement offset */
- private int fReplacementOffset;
- /** The replacement length */
- private int fReplacementLength;
- /** The cursor position after this proposal has been applied */
- private int fCursorPosition;
- /** The image to be displayed in the completion proposal popup */
- private Image fImage;
- /** The context information of this proposal */
- private IContextInformation fContextInformation;
- /** The additional info of this proposal */
- private String fAdditionalProposalInfo;
-
- /**
- * Creates a new completion proposal based on the provided information. The replacement string is
- * considered being the display string too. All remaining fields are set to <code>null</code>.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset the offset of the text to be replaced
- * @param replacementLength the length of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- */
- public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition) {
- this(replacementString, replacementOffset, replacementLength, cursorPosition, null, null, null, null);
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementOffset the offset of the text to be replaced
- * @param replacementLength the length of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param contextInformation the context information associated with this proposal
- * @param additionalProposalInfo the additional information associated with this proposal
- */
- public CompletionProposal(String replacementString, int replacementOffset, int replacementLength, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
- Assert.isNotNull(replacementString);
- Assert.isTrue(replacementOffset >= 0);
- Assert.isTrue(replacementLength >= 0);
- Assert.isTrue(cursorPosition >= 0);
-
- fReplacementString= replacementString;
- fReplacementOffset= replacementOffset;
- fReplacementLength= replacementLength;
- fCursorPosition= cursorPosition;
- fImage= image;
- fDisplayString= displayString;
- fContextInformation= contextInformation;
- fAdditionalProposalInfo= additionalProposalInfo;
- }
-
- /*
- * @see ICompletionProposal#apply(IDocument)
- */
- public void apply(IDocument document) {
- try {
- document.replace(fReplacementOffset, fReplacementLength, fReplacementString);
- } catch (BadLocationException x) {
- // ignore
- }
- }
-
- /*
- * @see ICompletionProposal#getSelection(IDocument)
- */
- public Point getSelection(IDocument document) {
- return new Point(fReplacementOffset + fCursorPosition, 0);
- }
-
- /*
- * @see ICompletionProposal#getContextInformation()
- */
- public IContextInformation getContextInformation() {
- return fContextInformation;
- }
-
- /*
- * @see ICompletionProposal#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see ICompletionProposal#getDisplayString()
- */
- public String getDisplayString() {
- if (fDisplayString != null)
- return fDisplayString;
- return fReplacementString;
- }
-
- /*
- * @see ICompletionProposal#getAdditionalProposalInfo()
- */
- public String getAdditionalProposalInfo() {
- return fAdditionalProposalInfo;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
deleted file mode 100644
index 2bc09082da7..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/CompletionProposalPopup.java
+++ /dev/null
@@ -1,1107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-import org.eclipse.jface.contentassist.IContentAssistSubjectControl;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.TextUtilities;
-
-
-/**
- * This class is used to present proposals to the user. If additional
- * information exists for a proposal, then selecting that proposal
- * will result in the information being displayed in a secondary
- * window.
- *
- * @see org.eclipse.jface.text.contentassist.ICompletionProposal
- * @see org.eclipse.jface.text.contentassist.AdditionalInfoController
- */
-class CompletionProposalPopup implements IContentAssistListener {
-
- private final class ProposalSelectionListener implements KeyListener {
- public void keyPressed(KeyEvent e) {
- if (!Helper.okToUse(fProposalShell))
- return;
-
- if (e.character == 0 && e.keyCode == SWT.MOD1) {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
- int index= fProposalTable.getSelectionIndex();
- if (index >= 0)
- selectProposal(index, true);
- }
- }
-
- public void keyReleased(KeyEvent e) {
- if (!Helper.okToUse(fProposalShell))
- return;
-
- if (e.character == 0 && e.keyCode == SWT.MOD1) {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=34754
- int index= fProposalTable.getSelectionIndex();
- if (index >= 0)
- selectProposal(index, false);
- }
- }
- }
-
- /** The associated text viewer */
- private ITextViewer fViewer;
- /** The associated content assistant */
- private ContentAssistant fContentAssistant;
- /** The used additional info controller */
- private AdditionalInfoController fAdditionalInfoController;
- /** The closing strategy for this completion proposal popup */
- private PopupCloser fPopupCloser= new PopupCloser();
- /** The popup shell */
- private Shell fProposalShell;
- /** The proposal table */
- private Table fProposalTable;
- /** Indicates whether a completion proposal is being inserted */
- private boolean fInserting= false;
- /** The key listener to control navigation */
- private ProposalSelectionListener fKeyListener;
- /** List of document events used for filtering proposals */
- private List fDocumentEvents= new ArrayList();
- /** Listener filling the document event queue */
- private IDocumentListener fDocumentListener;
- /** Reentrance count for <code>filterProposals</code> */
- private long fInvocationCounter= 0;
- /** The filter list of proposals */
- private ICompletionProposal[] fFilteredProposals;
- /** The computed list of proposals */
- private ICompletionProposal[] fComputedProposals;
- /** The offset for which the proposals have been computed */
- private int fInvocationOffset;
- /** The offset for which the computed proposals have been filtered */
- private int fFilterOffset;
- /** The default line delimiter of the viewer's widget */
- private String fLineDelimiter;
- /**
- * The most recently selected proposal.
- * @since 3.0
- */
- private ICompletionProposal fLastProposal;
- /**
- * The content assist subject control.
- * This replaces <code>fViewer</code>
- *
- * @since 3.0
- */
- private IContentAssistSubjectControl fContentAssistSubjectControl;
- /**
- * The content assist subject control adapter.
- * This replaces <code>fViewer</code>
- *
- * @since 3.0
- */
- private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter;
- /**
- * Remembers the size for this completion proposal popup.
- * @since 3.0
- */
- private Point fSize;
-
- /**
- * Creates a new completion proposal popup for the given elements.
- *
- * @param contentAssistant the content assistant feeding this popup
- * @param viewer the viewer on top of which this popup appears
- * @param infoController the information control collaborating with this popup
- * @since 2.0
- */
- public CompletionProposalPopup(ContentAssistant contentAssistant, ITextViewer viewer, AdditionalInfoController infoController) {
- fContentAssistant= contentAssistant;
- fViewer= viewer;
- fAdditionalInfoController= infoController;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fViewer);
- }
-
- /**
- * Creates a new completion proposal popup for the given elements.
- *
- * @param contentAssistant the content assistant feeding this popup
- * @param contentAssistSubjectControl the content assist subject control on top of which this popup appears
- * @param infoController the information control collaborating with this popup
- * @since 3.0
- */
- public CompletionProposalPopup(ContentAssistant contentAssistant, IContentAssistSubjectControl contentAssistSubjectControl, AdditionalInfoController infoController) {
- fContentAssistant= contentAssistant;
- fContentAssistSubjectControl= contentAssistSubjectControl;
- fAdditionalInfoController= infoController;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl);
- }
-
- /**
- * Computes and presents completion proposals. The flag indicates whether this call has
- * be made out of an auto activation context.
- *
- * @param autoActivated <code>true</code> if auto activation context
- * @return an error message or <code>null</code> in case of no error
- */
- public String showProposals(final boolean autoActivated) {
-
- if (fKeyListener == null)
- fKeyListener= new ProposalSelectionListener();
-
- final Control control= fContentAssistSubjectControlAdapter.getControl();
-
- if (!Helper.okToUse(fProposalShell) && control != null && !control.isDisposed()) {
-
- // add the listener before computing the proposals so we don't move the caret
- // when the user types fast.
- fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener);
-
- BusyIndicator.showWhile(control.getDisplay(), new Runnable() {
- public void run() {
-
- fInvocationOffset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
- fFilterOffset= fInvocationOffset;
- fComputedProposals= computeProposals(fInvocationOffset);
-
- int count= (fComputedProposals == null ? 0 : fComputedProposals.length);
- if (count == 0) {
-
- if (!autoActivated)
- control.getDisplay().beep();
-
- hide();
-
- } else {
-
- if (count == 1 && !autoActivated && fContentAssistant.isAutoInserting()) {
-
- insertProposal(fComputedProposals[0], (char) 0, 0, fInvocationOffset);
- hide();
-
- } else {
-
- if (fLineDelimiter == null)
- fLineDelimiter= fContentAssistSubjectControlAdapter.getLineDelimiter();
-
- createProposalSelector();
- setProposals(fComputedProposals);
- displayProposals();
- }
- }
- }
- });
- }
-
- return getErrorMessage();
- }
-
- /**
- * Returns the completion proposal available at the given offset of the
- * viewer's document. Delegates the work to the content assistant.
- *
- * @param offset the offset
- * @return the completion proposals available at this offset
- */
- private ICompletionProposal[] computeProposals(int offset) {
- if (fContentAssistSubjectControl != null)
- return fContentAssistant.computeCompletionProposals(fContentAssistSubjectControl, offset);
- else
- return fContentAssistant.computeCompletionProposals(fViewer, offset);
- }
-
- /**
- * Returns the error message.
- *
- * @return the error message
- */
- private String getErrorMessage() {
- return fContentAssistant.getErrorMessage();
- }
-
- /**
- * Creates the proposal selector.
- */
- private void createProposalSelector() {
- if (Helper.okToUse(fProposalShell))
- return;
-
- Control control= fContentAssistSubjectControlAdapter.getControl();
- fProposalShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE );
- fProposalTable= new Table(fProposalShell, SWT.H_SCROLL | SWT.V_SCROLL);
-
- fProposalTable.setLocation(0, 0);
- if (fAdditionalInfoController != null)
- fAdditionalInfoController.setSizeConstraints(50, 10, true, false);
-
- GridLayout layout= new GridLayout();
- layout.marginWidth= 0;
- layout.marginHeight= 0;
- fProposalShell.setLayout(layout);
-
- GridData data= new GridData(GridData.FILL_BOTH);
-
-
- Point size= fContentAssistant.restoreCompletionProposalPopupSize();
- if (size != null) {
- fProposalTable.setLayoutData(data);
- fProposalShell.setSize(size);
- } else {
- data.heightHint= fProposalTable.getItemHeight() * 10;
- data.widthHint= 300;
- fProposalTable.setLayoutData(data);
- fProposalShell.pack();
- }
-
- fProposalShell.addControlListener(new ControlListener() {
-
- public void controlMoved(ControlEvent e) {}
-
- public void controlResized(ControlEvent e) {
- if (fAdditionalInfoController != null) {
- // reset the cached resize constraints
- fAdditionalInfoController.setSizeConstraints(50, 10, true, false);
- }
-
- fSize= fProposalShell.getSize();
- }
- });
-
- if (!"carbon".equals(SWT.getPlatform())) //$NON-NLS-1$
- fProposalShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
- Color c= fContentAssistant.getProposalSelectorBackground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fProposalTable.setBackground(c);
-
- c= fContentAssistant.getProposalSelectorForeground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fProposalTable.setForeground(c);
-
- fProposalTable.addSelectionListener(new SelectionListener() {
-
- public void widgetSelected(SelectionEvent e) {}
-
- public void widgetDefaultSelected(SelectionEvent e) {
- selectProposalWithMask(e.stateMask);
- }
- });
-
- fPopupCloser.install(fContentAssistant, fProposalTable);
-
- fProposalShell.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- unregister(); // but don't dispose the shell, since we're being called from its disposal event!
- }
- });
-
- fProposalTable.setHeaderVisible(false);
- fContentAssistant.addToLayout(this, fProposalShell, ContentAssistant.LayoutManager.LAYOUT_PROPOSAL_SELECTOR, fContentAssistant.getSelectionOffset());
- }
-
- /**
- * Returns the proposal selected in the proposal selector.
- *
- * @return the selected proposal
- * @since 2.0
- */
- private ICompletionProposal getSelectedProposal() {
- int i= fProposalTable.getSelectionIndex();
- if (fFilteredProposals == null || i < 0 || i >= fFilteredProposals.length)
- return null;
- return fFilteredProposals[i];
- }
-
- /**
- * Takes the selected proposal and applies it.
- *
- * @param stateMask the state mask
- * @since 2.1
- */
- private void selectProposalWithMask(int stateMask) {
- ICompletionProposal p= getSelectedProposal();
- hide();
- if (p != null)
- insertProposal(p, (char) 0, stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x);
- }
-
- /**
- * Applies the given proposal at the given offset. The given character is the
- * one that triggered the insertion of this proposal.
- *
- * @param p the completion proposal
- * @param trigger the trigger character
- * @param stateMask the state mask
- * @param offset the offset
- * @since 2.1
- */
- private void insertProposal(ICompletionProposal p, char trigger, int stateMask, int offset) {
-
- fInserting= true;
- IRewriteTarget target= null;
-
- try {
-
- IDocument document= fContentAssistSubjectControlAdapter.getDocument();
-
- if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fViewer;
- target= extension.getRewriteTarget();
- }
-
- if (target != null)
- target.beginCompoundChange();
-
- if (p instanceof ICompletionProposalExtension2 && fViewer != null) {
- ICompletionProposalExtension2 e= (ICompletionProposalExtension2) p;
- e.apply(fViewer, trigger, stateMask, offset);
- } else if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension e= (ICompletionProposalExtension) p;
- e.apply(document, trigger, offset);
- } else {
- p.apply(document);
- }
-
- Point selection= p.getSelection(document);
- if (selection != null) {
- fContentAssistSubjectControlAdapter.setSelectedRange(selection.x, selection.y);
- fContentAssistSubjectControlAdapter.revealRange(selection.x, selection.y);
- }
-
- IContextInformation info= p.getContextInformation();
- if (info != null) {
-
- int position;
- if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension e= (ICompletionProposalExtension) p;
- position= e.getContextInformationPosition();
- } else {
- if (selection == null)
- selection= fContentAssistSubjectControlAdapter.getSelectedRange();
- position= selection.x + selection.y;
- }
-
- fContentAssistant.showContextInformation(info, position);
- } else
- fContentAssistant.showContextInformation(null, -1);
-
-
- } finally {
- if (target != null)
- target.endCompoundChange();
- fInserting= false;
- }
- }
-
- /**
- * Returns whether this popup has the focus.
- *
- * @return <code>true</code> if the popup has the focus
- */
- public boolean hasFocus() {
- if (Helper.okToUse(fProposalShell))
- return (fProposalShell.isFocusControl() || fProposalTable.isFocusControl());
-
- return false;
- }
-
- /**
- * Hides this popup.
- */
- public void hide() {
-
- unregister();
-
- if (Helper.okToUse(fProposalShell)) {
-
- fContentAssistant.removeContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR);
-
- fPopupCloser.uninstall();
- fProposalShell.setVisible(false);
- fProposalShell.dispose();
- fProposalShell= null;
- }
- }
-
- /**
- * Unregister this completion proposal popup.
- *
- * @since 3.0
- */
- private void unregister() {
- if (fDocumentListener != null) {
- IDocument document= fContentAssistSubjectControlAdapter.getDocument();
- if (document != null)
- document.removeDocumentListener(fDocumentListener);
- fDocumentListener= null;
- }
- fDocumentEvents.clear();
-
- if (fKeyListener != null && fContentAssistSubjectControlAdapter.getControl() != null && !fContentAssistSubjectControlAdapter.getControl().isDisposed()) {
- fContentAssistSubjectControlAdapter.removeKeyListener(fKeyListener);
- fKeyListener= null;
- }
-
- if (fLastProposal != null) {
- if (fLastProposal instanceof ICompletionProposalExtension2 && fViewer != null) {
- ICompletionProposalExtension2 extension= (ICompletionProposalExtension2) fLastProposal;
- extension.unselected(fViewer);
- }
- fLastProposal= null;
- }
-
- fFilteredProposals= null;
- fComputedProposals= null;
-
- fContentAssistant.possibleCompletionsClosed();
- }
-
- /**
- *Returns whether this popup is active. It is active if the proposal selector is visible.
- *
- * @return <code>true</code> if this popup is active
- */
- public boolean isActive() {
- return fProposalShell != null && !fProposalShell.isDisposed();
- }
-
- /**
- * Initializes the proposal selector with these given proposals.
- *
- * @param proposals the proposals
- */
- private void setProposals(ICompletionProposal[] proposals) {
- if (Helper.okToUse(fProposalTable)) {
-
- ICompletionProposal oldProposal= getSelectedProposal();
- if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
- ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
-
- fFilteredProposals= proposals;
-
- fProposalTable.setRedraw(false);
- fProposalTable.removeAll();
-
- TableItem item;
- ICompletionProposal p;
- for (int i= 0; i < proposals.length; i++) {
- p= proposals[i];
- item= new TableItem(fProposalTable, SWT.NULL);
- if (p.getImage() != null)
- item.setImage(p.getImage());
- item.setText(p.getDisplayString());
- item.setData(p);
- }
-
- Point currentLocation= fProposalShell.getLocation();
- Point newLocation= getLocation();
- if ((newLocation.x < currentLocation.x && newLocation.y == currentLocation.y) || newLocation.y < currentLocation.y)
- fProposalShell.setLocation(newLocation);
-
- selectProposal(0, false);
- fProposalTable.setRedraw(true);
- }
- }
-
- /**
- * Returns the graphical location at which this popup should be made visible.
- *
- * @return the location of this popup
- */
- private Point getLocation() {
- int caret= fContentAssistSubjectControlAdapter.getCaretOffset();
- Point p= fContentAssistSubjectControlAdapter.getLocationAtOffset(caret);
- if (p.x < 0) p.x= 0;
- if (p.y < 0) p.y= 0;
- p= new Point(p.x, p.y + fContentAssistSubjectControlAdapter.getLineHeight());
- p= fContentAssistSubjectControlAdapter.getControl().toDisplay(p);
- if (p.x < 0) p.x= 0;
- if (p.y < 0) p.y= 0;
- return p;
- }
-
- /**
- * Returns the size of this completion proposal popup.
- *
- * @return a Point containing the size
- * @since 3.0
- */
- Point getSize() {
- return fSize;
- }
-
- /**
- * Displays this popup and install the additional info controller, so that additional info
- * is displayed when a proposal is selected and additional info is available.
- */
- private void displayProposals() {
-
- if (!Helper.okToUse(fProposalShell) || !Helper.okToUse(fProposalTable))
- return;
-
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant.PROPOSAL_SELECTOR)) {
-
- if (fDocumentListener == null)
- fDocumentListener= new IDocumentListener() {
- public void documentAboutToBeChanged(DocumentEvent event) {
- if (!fInserting)
- fDocumentEvents.add(event);
- }
-
- public void documentChanged(DocumentEvent event) {
- if (!fInserting)
- filterProposals();
- }
- };
- IDocument document= fContentAssistSubjectControlAdapter.getDocument();
- if (document != null)
- document.addDocumentListener(fDocumentListener);
-
- /* https://bugs.eclipse.org/bugs/show_bug.cgi?id=52646
- * on GTK, setVisible and such may run the event loop
- * (see also https://bugs.eclipse.org/bugs/show_bug.cgi?id=47511)
- * Since the user may have already canceled the popup or selected
- * an entry (ESC or RETURN), we have to double check whether
- * the table is still okToUse. See comments below
- */
- fProposalShell.setVisible(true); // may run event loop on GTK
- // XXX: transfer focus since no verify key listener can be attached
- if (!fContentAssistSubjectControlAdapter.supportsVerifyKeyListener() && Helper.okToUse(fProposalShell))
- fProposalShell.setFocus(); // may run event loop on GTK ??
-
- if (fAdditionalInfoController != null && Helper.okToUse(fProposalTable)) {
- fAdditionalInfoController.install(fProposalTable);
- fAdditionalInfoController.handleTableSelectionChanged();
- }
- }
- }
-
- /*
- * @see IContentAssistListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent e) {
- if (!Helper.okToUse(fProposalShell))
- return true;
-
- char key= e.character;
- if (key == 0) {
- int newSelection= fProposalTable.getSelectionIndex();
- int visibleRows= (fProposalTable.getSize().y / fProposalTable.getItemHeight()) - 1;
- boolean smartToggle= false;
- switch (e.keyCode) {
-
- case SWT.ARROW_LEFT :
- case SWT.ARROW_RIGHT :
- filterProposals();
- return true;
-
- case SWT.ARROW_UP :
- newSelection -= 1;
- if (newSelection < 0)
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- case SWT.ARROW_DOWN :
- newSelection += 1;
- if (newSelection > fProposalTable.getItemCount() - 1)
- newSelection= 0;
- break;
-
- case SWT.PAGE_DOWN :
- newSelection += visibleRows;
- if (newSelection >= fProposalTable.getItemCount())
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- case SWT.PAGE_UP :
- newSelection -= visibleRows;
- if (newSelection < 0)
- newSelection= 0;
- break;
-
- case SWT.HOME :
- newSelection= 0;
- break;
-
- case SWT.END :
- newSelection= fProposalTable.getItemCount() - 1;
- break;
-
- default :
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hide();
- return true;
- }
-
- selectProposal(newSelection, smartToggle);
-
- e.doit= false;
- return false;
-
- } else {
-
- switch (key) {
- case 0x1B: // Esc
- e.doit= false;
- hide();
- break;
-
- case '\n': // Ctrl-Enter on w2k
- case '\r': // Enter
- e.doit= false;
- selectProposalWithMask(e.stateMask);
- break;
-
- case '\t':
- e.doit= false;
- fProposalShell.setFocus();
- return false;
-
- default:
- ICompletionProposal p= getSelectedProposal();
- if (p instanceof ICompletionProposalExtension) {
- ICompletionProposalExtension t= (ICompletionProposalExtension) p;
- char[] triggers= t.getTriggerCharacters();
- if (contains(triggers, key)) {
- e.doit= false;
- hide();
- insertProposal(p, key, e.stateMask, fContentAssistSubjectControlAdapter.getSelectedRange().x);
- }
- }
- }
- }
-
- return true;
- }
-
- /**
- * Selects the entry with the given index in the proposal selector and feeds
- * the selection to the additional info controller.
- *
- * @param index the index in the list
- * @param smartToggle <code>true</code> if the smart toggle key has been pressed
- * @since 2.1
- */
- private void selectProposal(int index, boolean smartToggle) {
-
- if (fFilteredProposals == null)
- return;
-
- ICompletionProposal oldProposal= getSelectedProposal();
- if (oldProposal instanceof ICompletionProposalExtension2 && fViewer != null)
- ((ICompletionProposalExtension2) oldProposal).unselected(fViewer);
-
- ICompletionProposal proposal= fFilteredProposals[index];
- if (proposal instanceof ICompletionProposalExtension2 && fViewer != null)
- ((ICompletionProposalExtension2) proposal).selected(fViewer, smartToggle);
-
- fLastProposal= proposal;
-
- fProposalTable.setSelection(index);
- fProposalTable.showSelection();
- if (fAdditionalInfoController != null)
- fAdditionalInfoController.handleTableSelectionChanged();
- }
-
- /**
- * Returns whether the given character is contained in the given array of
- * characters.
- *
- * @param characters the list of characters
- * @param c the character to look for in the list
- * @return <code>true</code> if character belongs to the list
- * @since 2.0
- */
- private boolean contains(char[] characters, char c) {
-
- if (characters == null)
- return false;
-
- for (int i= 0; i < characters.length; i++) {
- if (c == characters[i])
- return true;
- }
-
- return false;
- }
-
- /*
- * @see IEventConsumer#processEvent(VerifyEvent)
- */
- public void processEvent(VerifyEvent e) {
- }
-
- /**
- * Filters the displayed proposal based on the given cursor position and the
- * offset of the original invocation of the content assistant.
- */
- private void filterProposals() {
- ++ fInvocationCounter;
- final Control control= fContentAssistSubjectControlAdapter.getControl();
- control.getDisplay().asyncExec(new Runnable() {
- long fCounter= fInvocationCounter;
- public void run() {
-
- if (fCounter != fInvocationCounter)
- return;
-
- if (control.isDisposed())
- return;
-
- int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
- ICompletionProposal[] proposals= null;
- try {
- if (offset > -1) {
- DocumentEvent event= TextUtilities.mergeProcessedDocumentEvents(fDocumentEvents);
- proposals= computeFilteredProposals(offset, event);
- }
- } catch (BadLocationException x) {
- } finally {
- fDocumentEvents.clear();
- }
- fFilterOffset= offset;
-
- if (proposals != null && proposals.length > 0)
- setProposals(proposals);
- else
- hide();
- }
- });
- }
-
- /**
- * Computes the subset of already computed proposals that are still valid for
- * the given offset.
- *
- * @param offset the offset
- * @param event the merged document event
- * @return the set of filtered proposals
- * @since 3.0
- */
- private ICompletionProposal[] computeFilteredProposals(int offset, DocumentEvent event) {
-
- if (offset == fInvocationOffset && event == null)
- return fComputedProposals;
-
- if (offset < fInvocationOffset) {
- fInvocationOffset= offset;
- fComputedProposals= computeProposals(fInvocationOffset);
- return fComputedProposals;
- }
-
- ICompletionProposal[] proposals= fComputedProposals;
- if (offset > fFilterOffset)
- proposals= fFilteredProposals;
-
- if (proposals == null)
- return null;
-
- IDocument document= fContentAssistSubjectControlAdapter.getDocument();
- int length= proposals.length;
- List filtered= new ArrayList(length);
- for (int i= 0; i < length; i++) {
-
- if (proposals[i] instanceof ICompletionProposalExtension2) {
-
- ICompletionProposalExtension2 p= (ICompletionProposalExtension2) proposals[i];
- if (p.validate(document, offset, event))
- filtered.add(p);
-
- } else if (proposals[i] instanceof ICompletionProposalExtension) {
-
- ICompletionProposalExtension p= (ICompletionProposalExtension) proposals[i];
- if (p.isValidFor(document, offset))
- filtered.add(p);
-
- } else {
- // restore original behavior
- fInvocationOffset= offset;
- fComputedProposals= computeProposals(fInvocationOffset);
- return fComputedProposals;
- }
- }
-
- ICompletionProposal[] p= new ICompletionProposal[filtered.size()];
- filtered.toArray(p);
- return p;
- }
-
- /**
- * Requests the proposal shell to take focus.
- *
- * @since 3.0
- */
- public void setFocus() {
- if (Helper.okToUse(fProposalShell)) {
- fProposalShell.setFocus();
- }
- }
-
- /**
- * Completes the common prefix of all proposals directly in the code. If no
- * common prefix can be found, the proposal popup is shown.
- *
- * @return an error message if completion failed.
- * @since 3.0
- */
- public String incrementalComplete() {
- if (Helper.okToUse(fProposalShell) && fFilteredProposals != null) {
- completeCommonPrefix();
- } else {
- final Control control= fContentAssistSubjectControlAdapter.getControl();
-
- if (fKeyListener == null)
- fKeyListener= new ProposalSelectionListener();
-
- if (!Helper.okToUse(fProposalShell) && !control.isDisposed())
- fContentAssistSubjectControlAdapter.addKeyListener(fKeyListener);
-
- BusyIndicator.showWhile(control.getDisplay(), new Runnable() {
- public void run() {
-
- fInvocationOffset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
- fFilterOffset= fInvocationOffset;
- fFilteredProposals= computeProposals(fInvocationOffset);
-
- int count= (fFilteredProposals == null ? 0 : fFilteredProposals.length);
- if (count == 0) {
- control.getDisplay().beep();
- hide();
- } else if (count == 1 && fContentAssistant.isAutoInserting()) {
- insertProposal(fFilteredProposals[0], (char) 0, 0, fInvocationOffset);
- hide();
- } else {
- if (fLineDelimiter == null)
- fLineDelimiter= fContentAssistSubjectControlAdapter.getLineDelimiter();
-
- if (completeCommonPrefix())
- hide(); // TODO add some caching? for now: just throw away the completions
- else {
- fComputedProposals= fFilteredProposals;
- createProposalSelector();
- setProposals(fComputedProposals);
- displayProposals();
- }
- }
- }
- });
- }
- return getErrorMessage();
- }
-
- /**
- * Acts upon <code>fFilteredProposals</code>: if there is just one valid
- * proposal, it is inserted, otherwise, the common prefix of all proposals
- * is inserted into the document. If there is no common prefix, <code>false</code>
- * is returned.
- *
- * @return <code>true</code> if common prefix insertion was successful, <code>false</code> otherwise
- * @since 3.0
- */
- private boolean completeCommonPrefix() {
-
- // 0: insert single proposals
- if (fFilteredProposals.length == 1) {
- insertProposal(fFilteredProposals[0], (char) 0, 0, fInvocationOffset);
- hide();
- return true;
- }
-
- // 1: get the common ignore-case prefix of all remaining proposals
- // note that the prefix still
- StringBuffer prefix= null; // the common prefix
- boolean isCaseCompatible= true;
- IDocument document= fContentAssistSubjectControlAdapter.getDocument();
- int startOffset= -1; // the location where the proposals would insert (< fInvocationOffset if invoked in the middle of an indent)
- String currentPrefix= null; // the prefix already in the document
- int currentPrefixLen= -1; // the length of the current prefix
- List caseFiltered= new ArrayList();
-
- for (int i= 0; i < fFilteredProposals.length; i++) {
- ICompletionProposal proposal= fFilteredProposals[i];
- CharSequence insertion= getReplacementString(proposal);
-
- if (currentPrefix == null) {
- startOffset= getReplacementOffset(proposal);
- currentPrefixLen= fFilterOffset - startOffset;
- try {
- // make sure we get the right case
- currentPrefix= document.get(startOffset, currentPrefixLen);
- } catch (BadLocationException e1) {
- // bail out silently
- return false;
- }
- }
-
- // prune ignore-case matches
- if (isCaseSensitive() && !insertion.toString().startsWith(currentPrefix))
- continue;
-
- caseFiltered.add(proposal);
-
- if (prefix == null)
- prefix= new StringBuffer(insertion.toString()); // initial
- else
- isCaseCompatible &= truncatePrefix(prefix, insertion);
-
- // early break computation if there is nothing left to check
- if (prefix.length() == 0)
- break;
- }
-
- if (prefix == null || currentPrefixLen > prefix.length() || prefix.toString().equals(currentPrefix))
- return false;
-
- // 2: replace / insert the common prefix in the document
-
- if (caseFiltered.size() == 1) {
- insertProposal((ICompletionProposal) caseFiltered.get(0), (char) 0, 0, fInvocationOffset);
- hide();
- return true;
- }
-
- try {
- String presentPart= prefix.substring(0, currentPrefixLen);
- int replaceOffset;
- int replaceLen;
- if (isCaseCompatible && !currentPrefix.equals(presentPart)) {
- // update case
- currentPrefixLen= 0;
- replaceOffset= startOffset;
- replaceLen= fFilterOffset - startOffset;
- } else {
- // only insert remaining part
- replaceOffset= fFilterOffset;
- replaceLen= 0;
- }
-
- int remainingLen= prefix.length() - currentPrefixLen;
- String remainingPrefix= prefix.subSequence(currentPrefixLen, currentPrefixLen + remainingLen).toString();
-
- document.replace(replaceOffset, replaceLen, remainingPrefix);
-
- fContentAssistSubjectControlAdapter.setSelectedRange(replaceOffset + remainingLen, 0);
- fContentAssistSubjectControlAdapter.revealRange(replaceOffset + remainingLen, 0);
-
- return true;
- } catch (BadLocationException e) {
- // ignore and return false
- return false;
- }
- }
-
- /**
- * Truncates <code>prefix</code> to the longest prefix it has in common with
- * <code>sequence</code> and returns <code>true</code> if the common prefix
- * has the same case for <code>prefix</code> and <code>sequence</code>.
- *
- * @param prefix the previous prefix that will get truncated to the prefix it has in common with <code>sequence</code>
- * @param sequence the character sequence to match
- * @return <code>true</code> if the match is case compatible, <code>false</code> if the common prefix differs in case
- * @since 3.0
- */
- private boolean truncatePrefix(StringBuffer prefix, CharSequence sequence) {
- // find common prefix
- int min= Math.min(prefix.length(), sequence.length());
- boolean caseCompatible= true;
- for (int c= 0; c < min; c++) {
- char compareChar= sequence.charAt(c);
- char prefixChar= prefix.charAt(c);
- if (prefixChar != compareChar) {
- if (isCaseSensitive() || Character.toLowerCase(prefixChar) != Character.toLowerCase(compareChar)) {
- prefix.delete(c, prefix.length());
- return caseCompatible;
- } else
- caseCompatible= false;
- }
- }
-
- prefix.delete(min, prefix.length());
- return caseCompatible;
- }
-
- /**
- * Returns whether common prefix completion should be case sensitive or not.
- * Returns <code>true</code> if no proposal popup is currently showing, <code>false</code> if there is.
- *
- * @return <code>true</code> if common prefix completion should be case sensitive, <code>false</code> otherwise
- * @since 3.0
- */
- private boolean isCaseSensitive() {
- return !Helper.okToUse(fProposalShell);
- }
-
- /**
- * Extracts the completion offset of an <code>ICompletionProposal</code>. If
- * <code>proposal</code> is a <code>ICompletionProposalExtension3</code>, its
- * <code>getCompletionOffset</code> method is called, otherwise, the invocation
- * offset of this popup is shown.
- *
- * @param proposal the proposal to extract the offset from
- * @return the proposals completion offset, or <code>fInvocationOffset</code>
- * @since 3.0
- */
- private int getReplacementOffset(ICompletionProposal proposal) {
- if (proposal instanceof ICompletionProposalExtension3)
- return ((ICompletionProposalExtension3) proposal).getPrefixCompletionStart(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
- else
- return fInvocationOffset;
- }
-
- /**
- * Extracts the replacement string from an <code>ICompletionProposal</code>.
- * If <code>proposal</code> is a <code>ICompletionProposalExtension3</code>, its
- * <code>getCompletionText</code> method is called, otherwise, the display
- * string is used.
- *
- * @param proposal the proposal to extract the text from
- * @return the proposals completion text
- * @since 3.0
- */
- private CharSequence getReplacementString(ICompletionProposal proposal) {
- CharSequence insertion= null;
- if (proposal instanceof ICompletionProposalExtension3)
- insertion= ((ICompletionProposalExtension3) proposal).getPrefixCompletionText(fContentAssistSubjectControlAdapter.getDocument(), fFilterOffset);
-
- if (insertion == null)
- insertion= proposal.getDisplayString();
-
- return insertion;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java
deleted file mode 100644
index c9e69756916..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistSubjectControlAdapter.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.contentassist.*;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IEventConsumer;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.contentassist.ContextInformationPopup.ContextFrame;
-
-/**
- * This content assist adapter delegates the calls either to
- * a text viewer or to a content assist subject control.
- *
- * @since 3.0
- */
-final class ContentAssistSubjectControlAdapter implements IContentAssistSubjectControl {
-
- /**
- * The text viewer which is used as content assist subject control.
- */
- private ITextViewer fViewer;
-
- /**
- * The content assist subject control.
- */
- private IContentAssistSubjectControl fContentAssistSubjectControl;
-
-
- /**
- * Creates an adapter for the given content assist subject control.
- *
- * @param contentAssistSubjectControl the content assist subject control
- */
- ContentAssistSubjectControlAdapter(IContentAssistSubjectControl contentAssistSubjectControl) {
- Assert.isNotNull(contentAssistSubjectControl);
- fContentAssistSubjectControl= contentAssistSubjectControl;
- }
-
- /**
- * Creates an adapter for the given text viewer.
- *
- * @param viewer the text viewer
- */
- public ContentAssistSubjectControlAdapter(ITextViewer viewer) {
- Assert.isNotNull(viewer);
- fViewer= viewer;
- }
-
- /*
- * @see IContentAssistSubjectControl#getLineHeight()
- */
- public int getLineHeight() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getLineHeight();
- else
- return fViewer.getTextWidget().getLineHeight();
- }
-
- /*
- * @see IContentAssistSubjectControl#getControl()
- */
- public Control getControl() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getControl();
- else
- return fViewer.getTextWidget();
- }
-
- /*
- * @see IContentAssistSubjectControl#getLocationAtOffset(int)
- */
- public Point getLocationAtOffset(int offset) {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getLocationAtOffset(offset);
- else
- return fViewer.getTextWidget().getLocationAtOffset(offset);
- }
-
- /*
- * @see IContentAssistSubjectControl#getWidgetSelectionRange()
- */
- public Point getWidgetSelectionRange() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getWidgetSelectionRange();
- else
- return fViewer.getTextWidget().getSelectionRange();
- }
-
- /*
- * @see IContentAssistSubjectControl#getSelectedRange()
- */
- public Point getSelectedRange() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getSelectedRange();
- else
- return fViewer.getSelectedRange();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getCaretOffset()
- */
- public int getCaretOffset() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getCaretOffset();
- else
- return fViewer.getTextWidget().getCaretOffset();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getLineDelimiter()
- */
- public String getLineDelimiter() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getLineDelimiter();
- else
- return fViewer.getTextWidget().getLineDelimiter();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#addKeyListener(org.eclipse.swt.events.KeyListener)
- */
- public void addKeyListener(KeyListener keyListener) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.addKeyListener(keyListener);
- else
- fViewer.getTextWidget().addKeyListener(keyListener);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#removeKeyListener(org.eclipse.swt.events.KeyListener)
- */
- public void removeKeyListener(KeyListener keyListener) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.removeKeyListener(keyListener);
- else
- fViewer.getTextWidget().removeKeyListener(keyListener);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#getDocument()
- */
- public IDocument getDocument() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.getDocument();
- else
- return fViewer.getDocument();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#prependVerifyKeyListener(VerifyKeyListener)
- */
- public boolean prependVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
- if (fContentAssistSubjectControl != null) {
- return fContentAssistSubjectControl.prependVerifyKeyListener(verifyKeyListener);
- } else if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension e= (ITextViewerExtension) fViewer;
- e.prependVerifyKeyListener(verifyKeyListener);
- return true;
- } else {
-
- StyledText textWidget= fViewer.getTextWidget();
- if (Helper.okToUse(textWidget)) {
- textWidget.addVerifyKeyListener(verifyKeyListener);
- return true;
- }
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#appendVerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener)
- */
- public boolean appendVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.appendVerifyKeyListener(verifyKeyListener);
- else if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension)fViewer;
- extension.appendVerifyKeyListener(verifyKeyListener);
- return true;
- } else {
- StyledText textWidget= fViewer.getTextWidget();
- if (Helper.okToUse(textWidget)) {
- textWidget.addVerifyKeyListener(verifyKeyListener);
- return true;
- }
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#removeVerifyKeyListener(org.eclipse.swt.custom.VerifyKeyListener)
- */
- public void removeVerifyKeyListener(VerifyKeyListener verifyKeyListener) {
- if (fContentAssistSubjectControl != null) {
- fContentAssistSubjectControl.removeVerifyKeyListener(verifyKeyListener);
- } else if (fViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fViewer;
- extension.removeVerifyKeyListener(verifyKeyListener);
- } else {
- StyledText textWidget= fViewer.getTextWidget();
- if (Helper.okToUse(textWidget))
- textWidget.removeVerifyKeyListener(verifyKeyListener);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#setEventConsumer(org.eclipse.jface.text.contentassist.ContentAssistant.InternalListener)
- */
- public void setEventConsumer(IEventConsumer eventConsumer) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.setEventConsumer(eventConsumer);
- else
- fViewer.setEventConsumer(eventConsumer);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#setSelectedRange(int, int)
- */
- public void setSelectedRange(int i, int j) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.setSelectedRange(i, j);
- else
- fViewer.setSelectedRange(i, j);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#revealRange(int, int)
- */
- public void revealRange(int i, int j) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.revealRange(i, j);
- else
- fViewer.revealRange(i, j);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistSubjectControl#canAddVerifyKeyListener()
- */
- public boolean supportsVerifyKeyListener() {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.supportsVerifyKeyListener();
- else
- return true;
- }
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate proposing completions. The position is used to determine the
- * appropriate content assist processor to invoke.
- *
- * @param contentAssistant the content assistant
- * @param offset a document offset
- * @return the auto activation characters
- * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- public char[] getCompletionProposalAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
- if (fContentAssistSubjectControl != null)
- return contentAssistant.getCompletionProposalAutoActivationCharacters(fContentAssistSubjectControl, offset);
- else
- return contentAssistant.getCompletionProposalAutoActivationCharacters(fViewer, offset);
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate the presentation of context information. The position is used
- * to determine the appropriate content assist processor to invoke.
- *
- * @param contentAssistant the content assistant
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- char[] getContextInformationAutoActivationCharacters(ContentAssistant contentAssistant, int offset) {
- if (fContentAssistSubjectControl != null)
- return contentAssistant.getContextInformationAutoActivationCharacters(fContentAssistSubjectControl, offset);
- else
- return contentAssistant.getContextInformationAutoActivationCharacters(fViewer, offset);
- }
-
- /**
- * Creates and returns a completion proposal popup for the given content assistant.
- *
- * @param contentAssistant the content assistant
- * @param controller the additional info controller
- * @return the completion proposal popup
- */
- CompletionProposalPopup createCompletionProposalPopup(ContentAssistant contentAssistant, AdditionalInfoController controller) {
- if (fContentAssistSubjectControl != null)
- return new CompletionProposalPopup(contentAssistant, fContentAssistSubjectControl, controller);
- else
- return new CompletionProposalPopup(contentAssistant, fViewer, controller);
-
- }
-
- /**
- * Creates and returns a context info popup for the given content assistant.
- *
- * @param contentAssistant the content assistant
- * @return the context info popup or <code>null</code>
- */
- ContextInformationPopup createContextInfoPopup(ContentAssistant contentAssistant) {
- if (fContentAssistSubjectControl != null)
- return new ContextInformationPopup(contentAssistant, fContentAssistSubjectControl);
- else
- return new ContextInformationPopup(contentAssistant, fViewer);
-
- }
-
- /**
- * @param contentAssistant
- * @param offset
- * @return
- */
- public IContextInformationValidator getContextInformationValidator(ContentAssistant contentAssistant, int offset) {
- if (fContentAssistSubjectControl != null)
- return contentAssistant.getContextInformationValidator(fContentAssistSubjectControl, offset);
- else
- return contentAssistant.getContextInformationValidator(fViewer, offset);
- }
-
- /**
- * @param contentAssistant
- * @param offset
- * @return
- */
- public IContextInformationPresenter getContextInformationPresenter(ContentAssistant contentAssistant, int offset) {
- if (fContentAssistSubjectControl != null)
- return contentAssistant.getContextInformationPresenter(fContentAssistSubjectControl, offset);
- else
- return contentAssistant.getContextInformationPresenter(fViewer, offset);
- }
-
- /**
- * @param frame
- */
- public void installValidator(ContextFrame frame) {
- if (fContentAssistSubjectControl != null) {
- if (frame.fValidator instanceof ISubjectControlContextInformationValidator)
- ((ISubjectControlContextInformationValidator)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fOffset);
- } else
- frame.fValidator.install(frame.fInformation, fViewer, frame.fOffset);
- }
-
- /**
- * @param frame
- */
- public void installContextInformationPresenter(ContextFrame frame) {
- if (fContentAssistSubjectControl != null) {
- if (frame.fPresenter instanceof ISubjectControlContextInformationPresenter)
- ((ISubjectControlContextInformationPresenter)frame.fValidator).install(frame.fInformation, fContentAssistSubjectControl, frame.fBeginOffset);
- } else
- frame.fPresenter.install(frame.fInformation, fViewer, frame.fBeginOffset);
- }
-
- /**
- * @param contentAssistant
- * @param position
- * @return
- */
- public IContextInformation[] computeContextInformation(ContentAssistant contentAssistant, int position) {
- if (fContentAssistSubjectControl != null)
- return contentAssistant.computeContextInformation(fContentAssistSubjectControl, position);
- else
- return contentAssistant.computeContextInformation(fViewer, position);
- }
-
- /*
- * @see IContentAssistSubjectControl#addSelectionListener(SelectionListener)
- */
- public boolean addSelectionListener(SelectionListener selectionListener) {
- if (fContentAssistSubjectControl != null)
- return fContentAssistSubjectControl.addSelectionListener(selectionListener);
- else {
- fViewer.getTextWidget().addSelectionListener(selectionListener);
- return true;
- }
- }
-
- /*
- * @see IContentAssistSubjectControl#removeSelectionListener(SelectionListener)
- */
- public void removeSelectionListener(SelectionListener selectionListener) {
- if (fContentAssistSubjectControl != null)
- fContentAssistSubjectControl.removeSelectionListener(selectionListener);
- else
- fViewer.getTextWidget().removeSelectionListener(selectionListener);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
deleted file mode 100644
index 84348334e32..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContentAssistant.java
+++ /dev/null
@@ -1,1803 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyAdapter;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Widget;
-
-import org.eclipse.jface.contentassist.*;
-import org.eclipse.jface.dialogs.IDialogSettings;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IEventConsumer;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.IWidgetTokenKeeper;
-import org.eclipse.jface.text.IWidgetTokenKeeperExtension;
-import org.eclipse.jface.text.IWidgetTokenOwner;
-import org.eclipse.jface.text.IWidgetTokenOwnerExtension;
-import org.eclipse.jface.text.TextUtilities;
-
-
-
-/**
- * The standard implementation of the <code>IContentAssistant</code> interface.
- * Usually, clients instantiate this class and configure it before using it.
- */
-public class ContentAssistant implements IContentAssistant, IContentAssistantExtension, IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
-
- /**
- * A generic closer class used to monitor various
- * interface events in order to determine whether
- * content-assist should be terminated and all
- * associated windows closed.
- */
- class Closer implements ControlListener, MouseListener, FocusListener, DisposeListener, IViewportListener {
-
- /** The shell that a <code>ControlListener</code> is registered with. */
- private Control fShell;
- /** The control that a <code>MouseListener</code>, a<code>FocusListener</code> and a <code>DisposeListener</code> are registered with. */
- private Control fControl;
-
- /**
- * Installs this closer on it's viewer's text widget.
- */
- protected void install() {
- Control control= fContentAssistSubjectControlAdapter.getControl();
- fControl= control;
- if (Helper.okToUse(control)) {
-
- Control shell= control.getShell();
- fShell= shell;
- shell.addControlListener(this);
-
- control.addMouseListener(this);
- control.addFocusListener(this);
-
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- control.addDisposeListener(this);
- }
- if (fViewer != null)
- fViewer.addViewportListener(this);
- }
-
- /**
- * Uninstalls this closer from the viewer's text widget.
- */
- protected void uninstall() {
- Control shell= fShell;
- fShell= null;
- if (Helper.okToUse(shell))
- shell.removeControlListener(this);
-
- Control control= fControl;
- fControl= null;
- if (Helper.okToUse(control)) {
-
- control.removeMouseListener(this);
- control.removeFocusListener(this);
-
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- control.removeDisposeListener(this);
- }
-
- if (fViewer != null)
- fViewer.removeViewportListener(this);
- }
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent e) {
- hide();
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent e) {
- hide();
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent e) {
- hide();
- }
-
- /*
- * @see MouseListener#mouseUp(MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- hide();
- }
-
- /*
- * @see FocusListener#focusGained(FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see FocusListener#focusLost(FocusEvent)
- */
- public void focusLost(FocusEvent e) {
- Control control= fControl;
- if (Helper.okToUse(control)) {
- Display d= control.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- if (!fProposalPopup.hasFocus() && (fContextInfoPopup == null || !fContextInfoPopup.hasFocus()))
- hide();
- }
- });
- }
- }
- }
-
- /*
- * @seeDisposeListener#widgetDisposed(DisposeEvent)
- */
- public void widgetDisposed(DisposeEvent e) {
- /*
- * 1GGYYWK: ITPJUI:ALL - Dismissing editor with code assist up causes lots of Internal Errors
- */
- hide();
- }
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int topIndex) {
- hide();
- }
- }
-
- /**
- * An implementation of <code>IContentAssistListener</code>, this class is
- * used to monitor key events in support of automatic activation
- * of the content assistant. If enabled, the implementation utilizes a
- * thread to watch for input characters matching the activation
- * characters specified by the content assist processor, and if
- * detected, will wait the indicated delay interval before
- * activating the content assistant.
- */
- class AutoAssistListener extends KeyAdapter implements KeyListener, Runnable, VerifyKeyListener {
-
- private Thread fThread;
- private boolean fIsReset= false;
- private Object fMutex= new Object();
- private int fShowStyle;
-
- private final static int SHOW_PROPOSALS= 1;
- private final static int SHOW_CONTEXT_INFO= 2;
-
- protected AutoAssistListener() {
- }
-
- protected void start(int showStyle) {
- fShowStyle= showStyle;
- fThread= new Thread(this, JFaceTextMessages.getString("ContentAssistant.assist_delay_timer_name")); //$NON-NLS-1$
- fThread.start();
- }
-
- public void run() {
- try {
- while (true) {
- synchronized (fMutex) {
- if (fAutoActivationDelay != 0)
- fMutex.wait(fAutoActivationDelay);
- if (fIsReset) {
- fIsReset= false;
- continue;
- }
- }
- showAssist(fShowStyle);
- break;
- }
- } catch (InterruptedException e) {
- }
- fThread= null;
- }
-
- protected void reset(int showStyle) {
- synchronized (fMutex) {
- fShowStyle= showStyle;
- fIsReset= true;
- fMutex.notifyAll();
- }
- }
-
- protected void stop() {
- if (fThread != null) {
- fThread.interrupt();
- }
- }
-
- private boolean contains(char[] characters, char character) {
- if (characters != null) {
- for (int i= 0; i < characters.length; i++) {
- if (character == characters[i])
- return true;
- }
- }
- return false;
- }
-
- public void keyPressed(KeyEvent e) {
- // Only act on typed characters and ignore modifier-only events
- if (e.character == 0 && (e.keyCode & SWT.KEYCODE_BIT) == 0)
- return;
-
- int showStyle;
- int pos= fContentAssistSubjectControlAdapter.getSelectedRange().x;
- char[] activation;
-
- activation= fContentAssistSubjectControlAdapter.getCompletionProposalAutoActivationCharacters(ContentAssistant.this, pos);
-
- if (contains(activation, e.character) && !fProposalPopup.isActive())
- showStyle= SHOW_PROPOSALS;
- else {
- activation= fContentAssistSubjectControlAdapter.getContextInformationAutoActivationCharacters(ContentAssistant.this, pos);
- if (contains(activation, e.character) && fContextInfoPopup != null && !fContextInfoPopup.isActive())
- showStyle= SHOW_CONTEXT_INFO;
- else {
- if (fThread != null && fThread.isAlive())
- stop();
- return;
- }
- }
-
- if (fThread != null && fThread.isAlive())
- reset(showStyle);
- else
- start(showStyle);
- }
-
- /*
- * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
- */
- public void verifyKey(VerifyEvent event) {
- keyPressed(event);
- }
-
- protected void showAssist(final int showStyle) {
- Display d= fContentAssistSubjectControlAdapter.getControl().getDisplay();
- if (d != null) {
- try {
- d.syncExec(new Runnable() {
- public void run() {
- if (showStyle == SHOW_PROPOSALS)
- fProposalPopup.showProposals(true);
- else if (showStyle == SHOW_CONTEXT_INFO && fContextInfoPopup != null)
- fContextInfoPopup.showContextProposals(true);
- }
- });
- } catch (SWTError e) {
- }
- }
- }
- }
-
- /**
- * The layout manager layouts the various
- * windows associated with the content assistant based on the
- * settings of the content assistant.
- */
- class LayoutManager implements Listener {
-
- // Presentation types.
- /** The presentation type for the proposal selection popup. */
- public final static int LAYOUT_PROPOSAL_SELECTOR= 0;
- /** The presentation type for the context selection popup. */
- public final static int LAYOUT_CONTEXT_SELECTOR= 1;
- /** The presentation type for the context information hover .*/
- public final static int LAYOUT_CONTEXT_INFO_POPUP= 2;
-
- int fContextType= LAYOUT_CONTEXT_SELECTOR;
- Shell[] fShells= new Shell[3];
- Object[] fPopups= new Object[3];
-
- protected void add(Object popup, Shell shell, int type, int offset) {
- Assert.isNotNull(popup);
- Assert.isTrue(shell != null && !shell.isDisposed());
- checkType(type);
-
- if (fShells[type] != shell) {
- if (fShells[type] != null)
- fShells[type].removeListener(SWT.Dispose, this);
- shell.addListener(SWT.Dispose, this);
- fShells[type]= shell;
- }
-
- fPopups[type]= popup;
- if (type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP)
- fContextType= type;
-
- layout(type, offset);
- adjustListeners(type);
- }
-
- protected void checkType(int type) {
- Assert.isTrue(type == LAYOUT_PROPOSAL_SELECTOR ||
- type == LAYOUT_CONTEXT_SELECTOR || type == LAYOUT_CONTEXT_INFO_POPUP);
- }
-
- public void handleEvent(Event event) {
- Widget source= event.widget;
- source.removeListener(SWT.Dispose, this);
-
- int type= getShellType(source);
- checkType(type);
- fShells[type]= null;
-
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- if (fContextType == LAYOUT_CONTEXT_SELECTOR &&
- Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) {
- // Restore event notification to the tip popup.
- addContentAssistListener((IContentAssistListener) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR);
- }
- break;
-
- case LAYOUT_CONTEXT_SELECTOR:
- if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- if (fProposalPopupOrientation == PROPOSAL_STACKED)
- layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset());
- // Restore event notification to the proposal popup.
- addContentAssistListener((IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR);
- }
- fContextType= LAYOUT_CONTEXT_INFO_POPUP;
- break;
-
- case LAYOUT_CONTEXT_INFO_POPUP:
- if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- if (fContextInfoPopupOrientation == CONTEXT_INFO_BELOW)
- layout(LAYOUT_PROPOSAL_SELECTOR, getSelectionOffset());
- }
- fContextType= LAYOUT_CONTEXT_SELECTOR;
- break;
- }
- }
-
- protected int getShellType(Widget shell) {
- for (int i=0; i<fShells.length; i++) {
- if (fShells[i] == shell)
- return i;
- }
- return -1;
- }
-
- protected void layout(int type, int offset) {
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- layoutProposalSelector(offset);
- break;
- case LAYOUT_CONTEXT_SELECTOR:
- layoutContextSelector(offset);
- break;
- case LAYOUT_CONTEXT_INFO_POPUP:
- layoutContextInfoPopup(offset);
- break;
- }
- }
-
- protected void layoutProposalSelector(int offset) {
- if (fContextType == LAYOUT_CONTEXT_INFO_POPUP &&
- fContextInfoPopupOrientation == CONTEXT_INFO_BELOW &&
- Helper.okToUse(fShells[LAYOUT_CONTEXT_INFO_POPUP])) {
- // Stack proposal selector beneath the tip box.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- shell.setLocation(getStackedLocation(shell, parent));
- } else if (fContextType != LAYOUT_CONTEXT_SELECTOR ||
- !Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR])) {
- // There are no other presentations to be concerned with,
- // so place the proposal selector beneath the cursor line.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- } else {
- switch (fProposalPopupOrientation) {
- case PROPOSAL_REMOVE: {
- // Remove the tip selector and place the
- // proposal selector beneath the cursor line.
- fShells[LAYOUT_CONTEXT_SELECTOR].dispose();
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- break;
- }
- case PROPOSAL_OVERLAY: {
- // Overlay the tip selector with the proposal selector.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
- break;
- }
- case PROPOSAL_STACKED: {
- // Stack the proposal selector beneath the tip selector.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- break;
- }
- }
- }
- }
-
- protected void layoutContextSelector(int offset) {
- // Always place the context selector beneath the cursor line.
- Shell shell= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getBelowLocation(shell, offset));
-
- if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- switch (fProposalPopupOrientation) {
- case PROPOSAL_REMOVE:
- // Remove the proposal selector.
- fShells[LAYOUT_PROPOSAL_SELECTOR].dispose();
- break;
-
- case PROPOSAL_OVERLAY:
- // The proposal selector has been overlayed by the tip selector.
- break;
-
- case PROPOSAL_STACKED: {
- // Stack the proposal selector beneath the tip selector.
- shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- Shell parent= fShells[LAYOUT_CONTEXT_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- break;
- }
- }
- }
- }
-
- protected void layoutContextInfoPopup(int offset) {
- switch (fContextInfoPopupOrientation) {
- case CONTEXT_INFO_ABOVE: {
- // Place the popup above the cursor line.
- Shell shell= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- shell.setLocation(getAboveLocation(shell, offset));
- break;
- }
- case CONTEXT_INFO_BELOW: {
- // Place the popup beneath the cursor line.
- Shell parent= fShells[LAYOUT_CONTEXT_INFO_POPUP];
- parent.setLocation(getBelowLocation(parent, offset));
- if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR])) {
- // Stack the proposal selector beneath the context info popup.
- Shell shell= fShells[LAYOUT_PROPOSAL_SELECTOR];
- shell.setLocation(getStackedLocation(shell, parent));
- }
- break;
- }
- }
- }
-
- protected void shiftHorizontalLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) {
- if (location.x + shellBounds.width > displayBounds.width)
- location.x= displayBounds.width - shellBounds.width;
-
- if (location.x < displayBounds.x)
- location.x= displayBounds.x;
- }
-
- protected void shiftVerticalLocation(Point location, Rectangle shellBounds, Rectangle displayBounds) {
- if (location.y + shellBounds.height > displayBounds.height)
- location.y= displayBounds.height - shellBounds.height;
-
- if (location.y < displayBounds.y)
- location.y= displayBounds.y;
- }
-
- protected Point getAboveLocation(Shell shell, int offset) {
- Point location= fContentAssistSubjectControlAdapter.getLocationAtOffset(offset);
- location= fContentAssistSubjectControlAdapter.getControl().toDisplay(location);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
-
- location.y=location.y - shellBounds.height;
-
- shiftHorizontalLocation(location, shellBounds, displayBounds);
- shiftVerticalLocation(location, shellBounds, displayBounds);
-
- return location;
- }
-
- protected Point getBelowLocation(Shell shell, int offset) {
- Point location= fContentAssistSubjectControlAdapter.getLocationAtOffset(offset);
- if (location.x < 0) location.x= 0;
- if (location.y < 0) location.y= 0;
- location= fContentAssistSubjectControlAdapter.getControl().toDisplay(location);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
-
- location.y= location.y + fContentAssistSubjectControlAdapter.getLineHeight();
- shiftHorizontalLocation(location, shellBounds, displayBounds);
- shiftVerticalLocation(location, shellBounds, displayBounds);
-
- return location;
- }
-
- protected Point getStackedLocation(Shell shell, Shell parent) {
- Point p= parent.getLocation();
- Point size= parent.getSize();
- p.x += size.x / 4;
- p.y += size.y;
-
- p= parent.toDisplay(p);
-
- Rectangle shellBounds= shell.getBounds();
- Rectangle displayBounds= shell.getDisplay().getClientArea();
- shiftHorizontalLocation(p, shellBounds, displayBounds);
- shiftVerticalLocation(p, shellBounds, displayBounds);
-
- return p;
- }
-
- protected void adjustListeners(int type) {
- switch (type) {
- case LAYOUT_PROPOSAL_SELECTOR:
- if (fContextType == LAYOUT_CONTEXT_SELECTOR &&
- Helper.okToUse(fShells[LAYOUT_CONTEXT_SELECTOR]))
- // Disable event notification to the tip selector.
- removeContentAssistListener((IContentAssistListener) fPopups[LAYOUT_CONTEXT_SELECTOR], CONTEXT_SELECTOR);
- break;
- case LAYOUT_CONTEXT_SELECTOR:
- if (Helper.okToUse(fShells[LAYOUT_PROPOSAL_SELECTOR]))
- // Disable event notification to the proposal selector.
- removeContentAssistListener((IContentAssistListener) fPopups[LAYOUT_PROPOSAL_SELECTOR], PROPOSAL_SELECTOR);
- break;
- case LAYOUT_CONTEXT_INFO_POPUP:
- break;
- }
- }
- }
-
- /**
- * Internal key listener and event consumer.
- */
- class InternalListener implements VerifyKeyListener, IEventConsumer {
-
- /**
- * Verifies key events by notifying the registered listeners.
- * Each listener is allowed to indicate that the event has been
- * handled and should not be further processed.
- *
- * @param e the verify event
- * @see VerifyKeyListener#verifyKey(org.eclipse.swt.events.VerifyEvent)
- */
- public void verifyKey(VerifyEvent e) {
- IContentAssistListener[] listeners= (IContentAssistListener[]) fListeners.clone();
- for (int i= 0; i < listeners.length; i++) {
- if (listeners[i] != null) {
- if (!listeners[i].verifyKey(e) || !e.doit)
- break;
- }
- }
- if (fAutoAssistListener != null)
- fAutoAssistListener.keyPressed(e);
- }
-
- /*
- * @see IEventConsumer#processEvent
- */
- public void processEvent(VerifyEvent event) {
-
- installKeyListener();
-
- IContentAssistListener[] listeners= (IContentAssistListener[])fListeners.clone();
- for (int i= 0; i < listeners.length; i++) {
- if (listeners[i] != null) {
- listeners[i].processEvent(event);
- if (!event.doit)
- return;
- }
- }
- }
- }
-
- /**
- * Dialog store constants.
- * @since 3.0
- */
- public static final String STORE_SIZE_X= "size.x"; //$NON-NLS-1$
- public static final String STORE_SIZE_Y= "size.y"; //$NON-NLS-1$
-
- // Content-Assist Listener types
- final static int CONTEXT_SELECTOR= 0;
- final static int PROPOSAL_SELECTOR= 1;
- final static int CONTEXT_INFO_POPUP= 2;
-
- /**
- * The popup priority: &gt; linked position proposals and hover popups.
- * Default value: <code>20</code>;
- *
- * @since 3.0
- */
- public static final int WIDGET_PRIORITY= 20;
-
- private static final int DEFAULT_AUTO_ACTIVATION_DELAY= 500;
-
- private IInformationControlCreator fInformationControlCreator;
- private int fAutoActivationDelay= DEFAULT_AUTO_ACTIVATION_DELAY;
- private boolean fIsAutoActivated= false;
- private boolean fIsAutoInserting= false;
- private int fProposalPopupOrientation= PROPOSAL_OVERLAY;
- private int fContextInfoPopupOrientation= CONTEXT_INFO_ABOVE;
- private Map fProcessors;
- private String fPartitioning;
-
- private Color fContextInfoPopupBackground;
- private Color fContextInfoPopupForeground;
- private Color fContextSelectorBackground;
- private Color fContextSelectorForeground;
- private Color fProposalSelectorBackground;
- private Color fProposalSelectorForeground;
-
- private ITextViewer fViewer;
- private String fLastErrorMessage;
-
- private Closer fCloser;
- private LayoutManager fLayoutManager;
- private AutoAssistListener fAutoAssistListener;
- private InternalListener fInternalListener;
- private CompletionProposalPopup fProposalPopup;
- private ContextInformationPopup fContextInfoPopup;
-
- private boolean fVerifyKeyListenerHooked= false;
- private IContentAssistListener[] fListeners= new IContentAssistListener[4];
- /**
- * The content assist subject control.
- *
- * @since 3.0
- */
- private IContentAssistSubjectControl fContentAssistSubjectControl;
- /**
- * The content assist subject control adapter.
- *
- * @since 3.0
- */
- private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter;
- /**
- * The dialog settings for the control's bounds.
- *
- * @since 3.0
- */
- private IDialogSettings fDialogSettings;
- /**
- * Prefix completion setting.
- *
- * @since 3.0
- */
- private boolean fIsPrefixCompletionEnabled= false;
-
- /**
- * Creates a new content assistant. The content assistant is not automatically activated,
- * overlays the completion proposals with context information list if necessary, and
- * shows the context information above the location at which it was activated. If auto
- * activation will be enabled, without further configuration steps, this content assistant
- * is activated after a 500 ms delay. It uses the default partitioning.
- */
- public ContentAssistant() {
- fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
- }
-
- /**
- * Sets the document partitioning this content assistant is using.
- *
- * @param partitioning the document partitioning for this content assistant
- */
- public void setDocumentPartitioning(String partitioning) {
- Assert.isNotNull(partitioning);
- fPartitioning= partitioning;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistantExtension#getDocumentPartitioning()
- * @since 3.0
- */
- public String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- /**
- * Registers a given content assist processor for a particular content type.
- * If there is already a processor registered for this type, the new processor
- * is registered instead of the old one.
- *
- * @param processor the content assist processor to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setContentAssistProcessor(IContentAssistProcessor processor, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fProcessors == null)
- fProcessors= new HashMap();
-
- if (processor == null)
- fProcessors.remove(contentType);
- else
- fProcessors.put(contentType, processor);
- }
-
- /*
- * @see IContentAssistant#getContentAssistProcessor
- */
- public IContentAssistProcessor getContentAssistProcessor(String contentType) {
- if (fProcessors == null)
- return null;
-
- return (IContentAssistProcessor) fProcessors.get(contentType);
- }
-
- /**
- * Enables the content assistant's auto activation mode.
- *
- * @param enabled indicates whether auto activation is enabled or not
- */
- public void enableAutoActivation(boolean enabled) {
- fIsAutoActivated= enabled;
- manageAutoActivation(fIsAutoActivated);
- }
-
- /**
- * Enables the content assistant's auto insertion mode. If enabled,
- * the content assistant inserts a proposal automatically if it is
- * the only proposal. In the case of ambiguities, the user must
- * make the choice.
- *
- * @param enabled indicates whether auto insertion is enabled or not
- * @since 2.0
- */
- public void enableAutoInsert(boolean enabled) {
- fIsAutoInserting= enabled;
- }
-
- /**
- * Returns whether this content assistant is in the auto insertion
- * mode or not.
- *
- * @return <code>true</code> if in auto insertion mode
- * @since 2.0
- */
- boolean isAutoInserting() {
- return fIsAutoInserting;
- }
-
- /**
- * Installs and uninstall the listeners needed for autoactivation.
- * @param start <code>true</code> if listeners must be installed,
- * <code>false</code> if they must be removed
- * @since 2.0
- */
- private void manageAutoActivation(boolean start) {
- if (start) {
-
- if ((fContentAssistSubjectControlAdapter != null) && fAutoAssistListener == null) {
- fAutoAssistListener= new AutoAssistListener();
- // TODO see bug 49212
- if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener())
- fContentAssistSubjectControlAdapter.appendVerifyKeyListener(fAutoAssistListener);
- else
- fContentAssistSubjectControlAdapter.addKeyListener(fAutoAssistListener);
- }
-
- } else if (fAutoAssistListener != null) {
- // TODO see bug 49212
- if (fContentAssistSubjectControlAdapter.supportsVerifyKeyListener())
- fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fAutoAssistListener);
- else
- fContentAssistSubjectControlAdapter.removeKeyListener(fAutoAssistListener);
- fAutoAssistListener= null;
- }
- }
-
- /**
- * Sets the delay after which the content assistant is automatically invoked
- * if the cursor is behind an auto activation character.
- *
- * @param delay the auto activation delay
- */
- public void setAutoActivationDelay(int delay) {
- fAutoActivationDelay= delay;
- }
-
- /**
- * Sets the proposal popups' orientation.
- * The following values may be used:
- * <ul>
- * <li>PROPOSAL_OVERLAY<p>
- * proposal popup windows should overlay each other
- * </li>
- * <li>PROPOSAL_REMOVE<p>
- * any currently shown proposal popup should be closed
- * </li>
- * <li>PROPOSAL_STACKED<p>
- * proposal popup windows should be vertical stacked, with no overlap,
- * beneath the line containing the current cursor location
- * </li>
- * </ul>
- *
- * @param orientation the popup's orientation
- */
- public void setProposalPopupOrientation(int orientation) {
- fProposalPopupOrientation= orientation;
- }
-
- /**
- * Sets the context information popup's orientation.
- * The following values may be used:
- * <ul>
- * <li>CONTEXT_ABOVE<p>
- * context information popup should always appear above the line containing
- * the current cursor location
- * </li>
- * <li>CONTEXT_BELOW<p>
- * context information popup should always appear below the line containing
- * the current cursor location
- * </li>
- * </ul>
- *
- * @param orientation the popup's orientation
- */
- public void setContextInformationPopupOrientation(int orientation) {
- fContextInfoPopupOrientation= orientation;
- }
-
- /**
- * Sets the context information popup's background color.
- *
- * @param background the background color
- */
- public void setContextInformationPopupBackground(Color background) {
- fContextInfoPopupBackground= background;
- }
-
- /**
- * Returns the background of the context information popup.
- *
- * @return the background of the context information popup
- * @since 2.0
- */
- Color getContextInformationPopupBackground() {
- return fContextInfoPopupBackground;
- }
-
- /**
- * Sets the context information popup's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setContextInformationPopupForeground(Color foreground) {
- fContextInfoPopupForeground= foreground;
- }
-
- /**
- * Returns the foreground of the context information popup.
- *
- * @return the foreground of the context information popup
- * @since 2.0
- */
- Color getContextInformationPopupForeground() {
- return fContextInfoPopupForeground;
- }
-
- /**
- * Sets the proposal selector's background color.
- *
- * @param background the background color
- * @since 2.0
- */
- public void setProposalSelectorBackground(Color background) {
- fProposalSelectorBackground= background;
- }
-
- /**
- * Returns the background of the proposal selector.
- *
- * @return the background of the proposal selector
- * @since 2.0
- */
- Color getProposalSelectorBackground() {
- return fProposalSelectorBackground;
- }
-
- /**
- * Sets the proposal's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setProposalSelectorForeground(Color foreground) {
- fProposalSelectorForeground= foreground;
- }
-
- /**
- * Returns the foreground of the proposal selector.
- *
- * @return the foreground of the proposal selector
- * @since 2.0
- */
- Color getProposalSelectorForeground() {
- return fProposalSelectorForeground;
- }
-
- /**
- * Sets the context selector's background color.
- *
- * @param background the background color
- * @since 2.0
- */
- public void setContextSelectorBackground(Color background) {
- fContextSelectorBackground= background;
- }
-
- /**
- * Returns the background of the context selector.
- *
- * @return the background of the context selector
- * @since 2.0
- */
- Color getContextSelectorBackground() {
- return fContextSelectorBackground;
- }
-
- /**
- * Sets the context selector's foreground color.
- *
- * @param foreground the foreground color
- * @since 2.0
- */
- public void setContextSelectorForeground(Color foreground) {
- fContextSelectorForeground= foreground;
- }
-
- /**
- * Returns the foreground of the context selector.
- *
- * @return the foreground of the context selector
- * @since 2.0
- */
- Color getContextSelectorForeground() {
- return fContextSelectorForeground;
- }
-
- /**
- * Sets the information control creator for the additional information control.
- *
- * @param creator the information control creator for the additional information control
- * @since 2.0
- */
- public void setInformationControlCreator(IInformationControlCreator creator) {
- fInformationControlCreator= creator;
- }
-
- /*
- * @see IControlContentAssistant#install(IContentAssistSubjectControl)
- */
- protected void install(IContentAssistSubjectControl contentAssistSubjectControl) {
- fContentAssistSubjectControl= contentAssistSubjectControl;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl);
- install();
- }
-
- /*
- * @see IContentAssist#install
- */
- public void install(ITextViewer textViewer) {
- fViewer= textViewer;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fViewer);
- install();
- }
-
- protected void install() {
-
- fLayoutManager= new LayoutManager();
- fInternalListener= new InternalListener();
-
- AdditionalInfoController controller= null;
- if (fInformationControlCreator != null) {
- int delay= fAutoActivationDelay;
- if (delay == 0)
- delay= DEFAULT_AUTO_ACTIVATION_DELAY;
- delay= Math.round(delay * 1.5f);
- controller= new AdditionalInfoController(fInformationControlCreator, delay);
- }
-
- fContextInfoPopup= fContentAssistSubjectControlAdapter.createContextInfoPopup(this);
- fProposalPopup= fContentAssistSubjectControlAdapter.createCompletionProposalPopup(this, controller);
-
- manageAutoActivation(fIsAutoActivated);
- }
-
- /*
- * @see IContentAssist#uninstall
- */
- public void uninstall() {
- hide();
- manageAutoActivation(false);
-
- if (fCloser != null) {
- fCloser.uninstall();
- fCloser= null;
- }
-
- fViewer= null;
- fContentAssistSubjectControl= null;
- fContentAssistSubjectControlAdapter= null;
- }
-
- /**
- * Adds the given shell of the specified type to the layout.
- * Valid types are defined by <code>LayoutManager</code>.
- *
- * @param popup a content assist popup
- * @param shell the shell of the content-assist popup
- * @param type the type of popup
- * @param visibleOffset the offset at which to layout the popup relative to the offset of the viewer's visible region
- * @since 2.0
- */
- void addToLayout(Object popup, Shell shell, int type, int visibleOffset) {
- fLayoutManager.add(popup, shell, type, visibleOffset);
- }
-
- /**
- * Layouts the registered popup of the given type relative to the
- * given offset. The offset is relative to the offset of the viewer's visible region.
- * Valid types are defined by <code>LayoutManager</code>.
- *
- * @param type the type of popup to layout
- * @param visibleOffset the offset at which to layout relative to the offset of the viewer's visible region
- * @since 2.0
- */
- void layout(int type, int visibleOffset) {
- fLayoutManager.layout(type, visibleOffset);
- }
-
- /**
- * Notifies the controller that a popup has lost focus.
- *
- * @param e the focus event
- */
- void popupFocusLost(FocusEvent e) {
- fCloser.focusLost(e);
- }
-
- /**
- * Returns the offset of the selection relative to the offset of the visible region.
- *
- * @return the offset of the selection relative to the offset of the visible region
- * @since 2.0
- */
- int getSelectionOffset() {
- return fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x;
- }
-
- /**
- * Returns whether the widget token could be acquired.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- * @param type the listener type for which to acquire
- * @return <code>true</code> if the widget token could be acquired
- * @since 2.0
- */
- private boolean acquireWidgetToken(int type) {
- switch (type) {
- case CONTEXT_SELECTOR:
- case PROPOSAL_SELECTOR:
- if (fContentAssistSubjectControl instanceof IWidgetTokenOwnerExtension) {
- IWidgetTokenOwnerExtension extension= (IWidgetTokenOwnerExtension)fContentAssistSubjectControl;
- return extension.requestWidgetToken(this, WIDGET_PRIORITY);
- } else if (fContentAssistSubjectControl instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner)fContentAssistSubjectControl;
- return owner.requestWidgetToken(this);
- } else if (fViewer instanceof IWidgetTokenOwnerExtension) {
- IWidgetTokenOwnerExtension extension= (IWidgetTokenOwnerExtension) fViewer;
- return extension.requestWidgetToken(this, WIDGET_PRIORITY);
- } else if (fViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fViewer;
- return owner.requestWidgetToken(this);
- }
- }
- return true;
- }
-
- /**
- * Registers a content assist listener.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- * Returns whether the listener could be added successfully. A listener
- * can not be added if the widget token could not be acquired.
- *
- * @param listener the listener to register
- * @param type the type of listener
- * @return <code>true</code> if the listener could be added
- */
- boolean addContentAssistListener(IContentAssistListener listener, int type) {
-
- if (acquireWidgetToken(type)) {
-
- fListeners[type]= listener;
-
- if (fCloser == null && getNumberOfListeners() == 1) {
- fCloser= new Closer();
- fCloser.install();
- fContentAssistSubjectControlAdapter.setEventConsumer(fInternalListener);
- installKeyListener();
- } else
- promoteKeyListener();
- return true;
- }
-
- return false;
- }
-
- /**
- * Repromotes the keylistener to the first position, using
- * prependVerifyKeyListener. This ensures no other instance is
- * filtering away the keystrokes underneath, if we've been up for a
- * while (e.g. when the context info is showing.
- *
- * @since 3.0
- */
- private void promoteKeyListener() {
- uninstallVerifyKeyListener();
- installKeyListener();
- }
-
- /**
- * Installs a key listener on the text viewer's widget.
- */
- private void installKeyListener() {
- if (!fVerifyKeyListenerHooked) {
- if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl())) {
- fVerifyKeyListenerHooked= fContentAssistSubjectControlAdapter.prependVerifyKeyListener(fInternalListener);
- }
- }
- }
-
- /**
- * Releases the previously acquired widget token if the token
- * is no longer necessary.
- * The following are valid listener types:
- * <ul>
- * <li>AUTO_ASSIST
- * <li>CONTEXT_SELECTOR
- * <li>PROPOSAL_SELECTOR
- * <li>CONTEXT_INFO_POPUP
- * <ul>
- *
- * @param type the listener type
- * @since 2.0
- */
- private void releaseWidgetToken(int type) {
- if (fListeners[CONTEXT_SELECTOR] == null && fListeners[PROPOSAL_SELECTOR] == null) {
- IWidgetTokenOwner owner= null;
- if (fContentAssistSubjectControl instanceof IWidgetTokenOwner)
- owner= (IWidgetTokenOwner)fContentAssistSubjectControl;
- else if (fViewer instanceof IWidgetTokenOwner)
- owner= (IWidgetTokenOwner)fViewer;
- if (owner != null)
- owner.releaseWidgetToken(this);
- }
- }
-
- /**
- * Unregisters a content assist listener.
- *
- * @param listener the listener to unregister
- * @param type the type of listener
- *
- * @see #addContentAssistListener(IContentAssistListener, int)
- */
- void removeContentAssistListener(IContentAssistListener listener, int type) {
- fListeners[type]= null;
-
- if (getNumberOfListeners() == 0) {
-
- if (fCloser != null) {
- fCloser.uninstall();
- fCloser= null;
- }
-
- uninstallVerifyKeyListener();
- fContentAssistSubjectControlAdapter.setEventConsumer(null);
- }
-
- releaseWidgetToken(type);
- }
-
- /**
- * Uninstall the key listener from the text viewer's widget.
- */
- private void uninstallVerifyKeyListener() {
- if (fVerifyKeyListenerHooked) {
- if (Helper.okToUse(fContentAssistSubjectControlAdapter.getControl()))
- fContentAssistSubjectControlAdapter.removeVerifyKeyListener(fInternalListener);
- fVerifyKeyListenerHooked= false;
- }
- }
-
- /**
- * Returns the number of listeners.
- *
- * @return the number of listeners
- * @since 2.0
- */
- private int getNumberOfListeners() {
- int count= 0;
- for (int i= 0; i <= CONTEXT_INFO_POPUP; i++) {
- if (fListeners[i] != null)
- ++ count;
- }
- return count;
- }
-
- /*
- * @see IContentAssist#showPossibleCompletions
- */
- public String showPossibleCompletions() {
- promoteKeyListener();
- if (fIsPrefixCompletionEnabled)
- return fProposalPopup.incrementalComplete();
- else
- return fProposalPopup.showProposals(false);
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistantExtension#completePrefix()
- */
- public String completePrefix() {
- promoteKeyListener();
- return fProposalPopup.incrementalComplete();
- }
-
- /**
- * Callback to signal this content assistant that the presentation of the possible completions has been stopped.
- * @since 2.1
- */
- protected void possibleCompletionsClosed() {
- storeCompletionProposalPopupSize();
- }
-
- /*
- * @see IContentAssist#showContextInformation
- */
- public String showContextInformation() {
- promoteKeyListener();
- if (fContextInfoPopup != null)
- return fContextInfoPopup.showContextProposals(false);
- else
- return null;
- }
-
- /**
- * Callback to signal this content assistant that the presentation of the context information has been stopped.
- * @since 2.1
- */
- protected void contextInformationClosed() {
- }
-
- /**
- * Requests that the specified context information to be shown.
- *
- * @param contextInformation the context information to be shown
- * @param position the position to which the context information refers to
- * @since 2.0
- */
- void showContextInformation(IContextInformation contextInformation, int position) {
- if (fContextInfoPopup != null)
- fContextInfoPopup.showContextInformation(contextInformation, position);
- }
-
- /**
- * Returns the current content assist error message.
- *
- * @return an error message or <code>null</code> if no error has occurred
- */
- String getErrorMessage() {
- return fLastErrorMessage;
- }
-
- /**
- * Returns the content assist processor for the content
- * type of the specified document position.
- *
- * @param viewer the text viewer
- * @param offset a offset within the document
- * @return a content-assist processor or <code>null</code> if none exists
- */
- private IContentAssistProcessor getProcessor(ITextViewer viewer, int offset) {
- try {
-
- IDocument document= viewer.getDocument();
- String type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
-
- return getContentAssistProcessor(type);
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /**
- * Returns the content assist processor for the content
- * type of the specified document position.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param offset a offset within the document
- * @return a content-assist processor or <code>null</code> if none exists
- */
- private IContentAssistProcessor getProcessor(IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
- try {
-
- IDocument document= contentAssistSubjectControl.getDocument();
- String type;
- if (document != null)
- type= TextUtilities.getContentType(document, getDocumentPartitioning(), offset, true);
- else
- type= IDocument.DEFAULT_CONTENT_TYPE;
-
- return getContentAssistProcessor(type);
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- /**
- * Returns an array of completion proposals computed based on
- * the specified document position. The position is used to
- * determine the appropriate content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param position a document position
- * @return an array of completion proposals
- *
- * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
- */
- ICompletionProposal[] computeCompletionProposals(IContentAssistSubjectControl contentAssistSubjectControl, int position) {
- fLastErrorMessage= null;
-
- ICompletionProposal[] result= null;
-
- IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, position);
- if (p instanceof ISubjectControlContentAssistProcessor) {
- result= ((ISubjectControlContentAssistProcessor)p).computeCompletionProposals(contentAssistSubjectControl, position);
- fLastErrorMessage= p.getErrorMessage();
- }
-
- return result;
- }
-
- /**
- * Returns an array of completion proposals computed based on
- * the specified document position. The position is used to
- * determine the appropriate content assist processor to invoke.
- *
- * @param viewer the viewer for which to compute the proposals
- * @param position a document position
- * @return an array of completion proposals
- *
- * @see IContentAssistProcessor#computeCompletionProposals(ITextViewer, int)
- */
- ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int position) {
- fLastErrorMessage= null;
-
- ICompletionProposal[] result= null;
-
- IContentAssistProcessor p= getProcessor(viewer, position);
- if (p != null) {
- result= p.computeCompletionProposals(viewer, position);
- fLastErrorMessage= p.getErrorMessage();
- }
-
- return result;
- }
-
- /**
- * Returns an array of context information objects computed based
- * on the specified document position. The position is used to determine
- * the appropriate content assist processor to invoke.
- *
- * @param viewer the viewer for which to compute the context information
- * @param position a document position
- * @return an array of context information objects
- *
- * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
- */
- IContextInformation[] computeContextInformation(ITextViewer viewer, int position) {
- fLastErrorMessage= null;
-
- IContextInformation[] result= null;
-
- IContentAssistProcessor p= getProcessor(viewer, position);
- if (p != null) {
- result= p.computeContextInformation(viewer, position);
- fLastErrorMessage= p.getErrorMessage();
- }
-
- return result;
- }
-
- /**
- * Returns an array of context information objects computed based
- * on the specified document position. The position is used to determine
- * the appropriate content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param position a document position
- * @return an array of context information objects
- *
- * @see IContentAssistProcessor#computeContextInformation(ITextViewer, int)
- */
- IContextInformation[] computeContextInformation(IContentAssistSubjectControl contentAssistSubjectControl, int position) {
- fLastErrorMessage= null;
-
- IContextInformation[] result= null;
-
- IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, position);
- if (p instanceof ISubjectControlContentAssistProcessor) {
- result= ((ISubjectControlContentAssistProcessor)p).computeContextInformation(contentAssistSubjectControl, position);
- fLastErrorMessage= p.getErrorMessage();
- }
-
- return result;
- }
-
- /**
- * Returns the context information validator that should be used to
- * determine when the currently displayed context information should
- * be dismissed. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param viewer the text viewer
- * @param offset a document offset
- * @return an validator
- *
- * @see IContentAssistProcessor#getContextInformationValidator()
- */
- IContextInformationValidator getContextInformationValidator(ITextViewer viewer, int offset) {
- IContentAssistProcessor p= getProcessor(viewer, offset);
- return p != null ? p.getContextInformationValidator() : null;
- }
-
- /**
- * Returns the context information validator that should be used to
- * determine when the currently displayed context information should
- * be dismissed. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param offset a document offset
- * @return an validator
- * @see IContentAssistProcessor#getContextInformationValidator()
- * @since 3.0
- */
- IContextInformationValidator getContextInformationValidator(IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
- IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset);
- return p != null ? p.getContextInformationValidator() : null;
- }
-
- /**
- * Returns the context information presenter that should be used to
- * display context information. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param viewer the text viewer
- * @param offset a document offset
- * @return a presenter
- * @since 2.0
- */
- IContextInformationPresenter getContextInformationPresenter(ITextViewer viewer, int offset) {
- IContextInformationValidator validator= getContextInformationValidator(viewer, offset);
- if (validator instanceof IContextInformationPresenter)
- return (IContextInformationPresenter) validator;
- return null;
- }
-
- /**
- * Returns the context information presenter that should be used to
- * display context information. The position is used to determine the appropriate
- * content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param offset a document offset
- * @return a presenter
- * @since 3.0
- */
- IContextInformationPresenter getContextInformationPresenter(IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
- IContextInformationValidator validator= getContextInformationValidator(contentAssistSubjectControl, offset);
- if (validator instanceof IContextInformationPresenter)
- return (IContextInformationPresenter) validator;
- return null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate proposing completions. The position is used to determine the
- * appropriate content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param offset a document offset
- * @return the auto activation characters
- * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- * @since 3.0
- */
- char[] getCompletionProposalAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
- IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset);
- return p != null ? p.getCompletionProposalAutoActivationCharacters() : null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate proposing completions. The position is used to determine the
- * appropriate content assist processor to invoke.
- *
- * @param viewer the text viewer
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- char[] getCompletionProposalAutoActivationCharacters(ITextViewer viewer, int offset) {
- IContentAssistProcessor p= getProcessor(viewer, offset);
- return p != null ? p.getCompletionProposalAutoActivationCharacters() : null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate the presentation of context information. The position is used
- * to determine the appropriate content assist processor to invoke.
- *
- * @param viewer the text viewer
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- char[] getContextInformationAutoActivationCharacters(ITextViewer viewer, int offset) {
- IContentAssistProcessor p= getProcessor(viewer, offset);
- return p != null ? p.getContextInformationAutoActivationCharacters() : null;
- }
-
- /**
- * Returns the characters which when typed by the user should automatically
- * initiate the presentation of context information. The position is used
- * to determine the appropriate content assist processor to invoke.
- *
- * @param contentAssistSubjectControl the content assist subject control
- * @param offset a document offset
- * @return the auto activation characters
- *
- * @see IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- char[] getContextInformationAutoActivationCharacters(IContentAssistSubjectControl contentAssistSubjectControl, int offset) {
- IContentAssistProcessor p= getProcessor(contentAssistSubjectControl, offset);
- return p != null ? p.getContextInformationAutoActivationCharacters() : null;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner)
- * @since 2.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(org.eclipse.jface.text.IWidgetTokenOwner, int)
- * @since 3.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) {
- if (priority > WIDGET_PRIORITY) {
- hide();
- return true;
- } else {
- return false;
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#setFocus(org.eclipse.jface.text.IWidgetTokenOwner)
- * @since 3.0
- */
- public boolean setFocus(IWidgetTokenOwner owner) {
- if (fProposalPopup != null) {
- fProposalPopup.setFocus();
- return fProposalPopup.hasFocus();
- }
- return false;
- }
-
- /**
- * Hides any open popups.
- */
- protected void hide() {
- if (fProposalPopup != null)
- fProposalPopup.hide();
-
- if (fContextInfoPopup != null)
- fContextInfoPopup.hide();
- }
- // ------ control's size handling dialog settings ------
-
- /**
- * Tells this information control manager to open the information control
- * with the values contained in the given dialog settings and to store the
- * control's last valid size in the given dialog settings.
- * <p>
- * Note: This API is only valid if the information control implements
- * {@link org.eclipse.jface.text.IInformationControlExtension3}. Not
- * following this restriction will later result in an
- * {@link UnsupportedOperationException}.
- * </p>
- * <p>
- * The constants used to store the values are:
- * <ul>
- * <li>{@link ContentAssistant#STORE_SIZE_X}</li>
- * <li>{@link ContentAssistant#STORE_SIZE_Y}</li>
- * </ul>
- * </p>
- *
- * @param dialogSettings
- * @since 3.0
- */
- public void setRestoreCompletionProposalSize(IDialogSettings dialogSettings) {
- Assert.isTrue(dialogSettings != null);
- fDialogSettings= dialogSettings;
- }
-
- /**
- * Stores the content assist pop-up's size.
- */
- protected void storeCompletionProposalPopupSize() {
- if (fDialogSettings == null || fProposalPopup == null)
- return;
-
- Point size= fProposalPopup.getSize();
- if (size == null)
- return;
-
- fDialogSettings.put(STORE_SIZE_X, size.x);
- fDialogSettings.put(STORE_SIZE_Y, size.y);
- }
-
- /**
- * Restores the content assist pop-up's size.
- *
- * @return the stored size
- * @since 3.0
- */
- protected Point restoreCompletionProposalPopupSize() {
- if (fDialogSettings == null)
- return null;
-
- Point size= new Point(-1, -1);
-
- try {
- size.x= fDialogSettings.getInt(STORE_SIZE_X);
- size.y= fDialogSettings.getInt(STORE_SIZE_Y);
- } catch (NumberFormatException ex) {
- size.x= -1;
- size.y= -1;
- }
-
- // sanity check
- if (size.x == -1 && size.y == -1)
- return null;
-
- Rectangle maxBounds= null;
- if (fContentAssistSubjectControl != null && !fContentAssistSubjectControl.getControl().isDisposed())
- maxBounds= fContentAssistSubjectControl.getControl().getDisplay().getBounds();
- else {
- // fallback
- Display display= Display.getCurrent();
- if (display == null)
- display= Display.getDefault();
- if (display != null && !display.isDisposed())
- maxBounds= display.getBounds();
- }
-
-
- if (size.x > -1 && size.y > -1) {
- if (maxBounds != null) {
- size.x= Math.min(size.x, maxBounds.width);
- size.y= Math.min(size.y, maxBounds.height);
- }
-
- // Enforce an absolute minimal size
- size.x= Math.max(size.x, 30);
- size.y= Math.max(size.y, 30);
- }
-
- return size;
- }
-
- /**
- * Sets the prefix completion property. If enabled, content assist delegates
- * completion to prefix completion.
- *
- * @param enabled <code>true</code> to enable prefix completion,
- * <code>false</code> to disable
- */
- public void enablePrefixCompletion(boolean enabled) {
- fIsPrefixCompletionEnabled= enabled;
- }
-
- /**
- * Returns whether the content assistant proposal popup has the focus.
- *
- * @return <code>true</code> if the proposal popup has the focus
- * @since 3.0
- */
- public boolean hasProposalPopupFocus() {
- return fProposalPopup.hasFocus();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java
deleted file mode 100644
index 67882131131..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformation.java
+++ /dev/null
@@ -1,96 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.swt.graphics.Image;
-
-import org.eclipse.jface.text.Assert;
-
-
-
-/**
- * A default implementation of the <code>IContextInformation</code> interface.
- */
-public final class ContextInformation implements IContextInformation {
-
- /** The name of the context */
- private String fContextDisplayString;
- /** The information to be displayed */
- private String fInformationDisplayString;
- /** The image to be displayed */
- private Image fImage;
-
- /**
- * Creates a new context information without an image.
- *
- * @param contextDisplayString the string to be used when presenting the context
- * @param informationDisplayString the string to be displayed when presenting the context information
- */
- public ContextInformation(String contextDisplayString, String informationDisplayString) {
- this(null, contextDisplayString, informationDisplayString);
- }
-
- /**
- * Creates a new context information with an image.
- *
- * @param image the image to display when presenting the context information
- * @param contextDisplayString the string to be used when presenting the context
- * @param informationDisplayString the string to be displayed when presenting the context information,
- * may not be <code>null</code>
- */
- public ContextInformation(Image image, String contextDisplayString, String informationDisplayString) {
-
- Assert.isNotNull(informationDisplayString);
-
- fImage= image;
- fContextDisplayString= contextDisplayString;
- fInformationDisplayString= informationDisplayString;
- }
-
- /*
- * @see IContextInformation#equals(Object)
- */
- public boolean equals(Object object) {
- if (object instanceof IContextInformation) {
- IContextInformation contextInformation= (IContextInformation) object;
- boolean equals= fInformationDisplayString.equalsIgnoreCase(contextInformation.getInformationDisplayString());
- if (fContextDisplayString != null)
- equals= equals && fContextDisplayString.equalsIgnoreCase(contextInformation.getContextDisplayString());
- return equals;
- }
- return false;
- }
-
- /*
- * @see IContextInformation#getInformationDisplayString()
- */
- public String getInformationDisplayString() {
- return fInformationDisplayString;
- }
-
- /*
- * @see IContextInformation#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see IContextInformation#getContextDisplayString()
- */
- public String getContextDisplayString() {
- if (fContextDisplayString != null)
- return fContextDisplayString;
- return fInformationDisplayString;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
deleted file mode 100644
index ea4427fcf68..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationPopup.java
+++ /dev/null
@@ -1,794 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import java.util.Iterator;
-import java.util.Stack;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.BusyIndicator;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Table;
-import org.eclipse.swt.widgets.TableItem;
-
-import org.eclipse.jface.contentassist.*;
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextPresentation;
-
-
-/**
- * This class is used to present context information to the user.
- * If multiple contexts are valid at the current cursor location,
- * a list is presented from which the user may choose one context.
- * Once the user makes their choice, or if there was only a single
- * possible context, the context information is shown in a tool tip like popup. <p>
- * If the tool tip is visible and the user wants to see context information of
- * a context embedded into the one for which context information is displayed,
- * context information for the embedded context is shown. As soon as the
- * cursor leaves the embedded context area, the context information for
- * the embedding context is shown again.
- *
- * @see IContextInformation
- * @see IContextInformationValidator
- */
-class ContextInformationPopup implements IContentAssistListener {
-
-
-
- /**
- * Represents the state necessary for embedding contexts.
- * @since 2.0
- */
- static class ContextFrame {
- public int fBeginOffset;
- public int fOffset;
- public int fVisibleOffset;
- public IContextInformation fInformation;
- public IContextInformationValidator fValidator;
- public IContextInformationPresenter fPresenter;
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- * @since 3.0
- */
- public boolean equals(Object obj) {
- if (obj instanceof ContextFrame) {
- ContextFrame frame= (ContextFrame) obj;
- return fInformation.equals(frame.fInformation) && fBeginOffset == frame.fBeginOffset;
- }
- return super.equals(obj);
- }
- }
-
- private ITextViewer fViewer;
- private ContentAssistant fContentAssistant;
-
- private PopupCloser fPopupCloser= new PopupCloser();
- private Shell fContextSelectorShell;
- private Table fContextSelectorTable;
- private IContextInformation[] fContextSelectorInput;
- private String fLineDelimiter= null;
-
- private Shell fContextInfoPopup;
- private StyledText fContextInfoText;
- private TextPresentation fTextPresentation;
-
- private Stack fContextFrameStack= new Stack();
- /**
- * The content assist subject control.
- *
- * @since 3.0
- */
- private IContentAssistSubjectControl fContentAssistSubjectControl;
- /**
- * The content assist subject control adapter.
- *
- * @since 3.0
- */
- private ContentAssistSubjectControlAdapter fContentAssistSubjectControlAdapter;
-
- /**
- * Selection listener on the text widget which is active
- * while a context information pop up is shown.
- *
- * @since 3.0
- */
- private SelectionListener fTextWidgetSelectionListener;
-
- /**
- * The last removed context frame is remembered in order to not re-query the
- * user about which context should be used.
- *
- * @since 3.0
- */
- private ContextFrame fLastContext= null;
-
- /**
- * Creates a new context information popup.
- *
- * @param contentAssistant the content assist for computing the context information
- * @param viewer the viewer on top of which the context information is shown
- */
- public ContextInformationPopup(ContentAssistant contentAssistant, ITextViewer viewer) {
- fContentAssistant= contentAssistant;
- fViewer= viewer;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fViewer);
- }
-
- /**
- * Creates a new context information popup.
- *
- * @param contentAssistant the content assist for computing the context information
- * @param contentAssistSubjectControl the content assist subject control on top of which the context information is shown
- * @since 3.0
- */
- public ContextInformationPopup(ContentAssistant contentAssistant, IContentAssistSubjectControl contentAssistSubjectControl) {
- fContentAssistant= contentAssistant;
- fContentAssistSubjectControl= contentAssistSubjectControl;
- fContentAssistSubjectControlAdapter= new ContentAssistSubjectControlAdapter(fContentAssistSubjectControl);
- }
-
- /**
- * Shows all possible contexts for the given cursor position of the viewer.
- *
- * @param autoActivated <code>true</code> if auto activated
- * @return a potential error message or <code>null</code> in case of no error
- */
- public String showContextProposals(final boolean autoActivated) {
- final Control control= fContentAssistSubjectControlAdapter.getControl();
- BusyIndicator.showWhile(control.getDisplay(), new Runnable() {
- public void run() {
-
- int position= fContentAssistSubjectControlAdapter.getSelectedRange().x;
-
- IContextInformation[] contexts= computeContextInformation(position);
- int count = (contexts == null ? 0 : contexts.length);
- if (count == 1) {
-
- ContextFrame frame= createContextFrame(contexts[0], position);
- if (isDuplicate(frame))
- validateContextInformation();
- else
- // Show context information directly
- internalShowContextInfo(frame);
-
- } else if (count > 0) {
-
- // if any of the proposed context matches the any of the contexts on the stack,
- // assume that one (so, if context info is invoked repeatedly, the current
- // info is kept)
- for (int i= 0; i < contexts.length; i++) {
- IContextInformation info= contexts[i];
- ContextFrame frame= createContextFrame(info, position);
-
- // check top of stack and stored context
- if (isDuplicate(frame)) {
- validateContextInformation();
- return;
- }
-
- if (isLastFrame(frame)) {
- internalShowContextInfo(frame);
- return;
- }
-
- // also check all other contexts
- for (Iterator it= fContextFrameStack.iterator(); it.hasNext(); ) {
- ContextFrame stackFrame= (ContextFrame) it.next();
- if (stackFrame.equals(frame)) {
- validateContextInformation();
- return;
- }
- }
- }
-
- // otherwise:
- // Precise context must be selected
-
- if (fLineDelimiter == null)
- fLineDelimiter= fContentAssistSubjectControlAdapter.getLineDelimiter();
-
- createContextSelector();
- setContexts(contexts);
- displayContextSelector();
- hideContextInfoPopup();
-
- } else if (!autoActivated) {
- control.getDisplay().beep();
- }
- }
- });
-
- return getErrorMessage();
- }
-
- /**
- * Displays the given context information for the given offset.
- *
- * @param info the context information
- * @param position the offset
- * @since 2.0
- */
- public void showContextInformation(final IContextInformation info, final int position) {
- Control control= fContentAssistSubjectControlAdapter.getControl();
- BusyIndicator.showWhile(control.getDisplay(), new Runnable() {
- public void run() {
- if (info == null)
- validateContextInformation();
- else {
- ContextFrame frame= createContextFrame(info, position);
- if (isDuplicate(frame))
- validateContextInformation();
- else
- internalShowContextInfo(frame);
- hideContextSelector();
- }
- }
- });
- }
-
- /**
- * Displays the given context information for the given offset.
- *
- * @param frame the context frame to display, or <code>null</code>
- * @since 3.0
- */
- private void internalShowContextInfo(ContextFrame frame) {
- if (frame != null) {
- fContextFrameStack.push(frame);
- if (fContextFrameStack.size() == 1)
- fLastContext= null;
- internalShowContextFrame(frame, fContextFrameStack.size() == 1);
- validateContextInformation();
- }
- }
-
- /**
- * Creates a context frame for the given offset.
- *
- * @param information the context information
- * @param offset the offset
- * @return the created context frame
- * @since 3.0
- */
- private ContextFrame createContextFrame(IContextInformation information, int offset) {
- IContextInformationValidator validator= fContentAssistSubjectControlAdapter.getContextInformationValidator(fContentAssistant, offset);
-
- if (validator != null) {
- ContextFrame current= new ContextFrame();
- current.fInformation= information;
- current.fBeginOffset= (information instanceof IContextInformationExtension) ? ((IContextInformationExtension) information).getContextInformationPosition() : offset;
- if (current.fBeginOffset == -1) current.fBeginOffset= offset;
- current.fOffset= offset;
- current.fVisibleOffset= fContentAssistSubjectControlAdapter.getWidgetSelectionRange().x - (offset - current.fBeginOffset);
- current.fValidator= validator;
- current.fPresenter= fContentAssistSubjectControlAdapter.getContextInformationPresenter(fContentAssistant, offset);
- return current;
- }
-
- return null;
- }
-
- /**
- * Compares <code>frame</code> with the top of the stack, returns <code>true</code>
- * if the frames are the same.
- *
- * @param frame the frame to check
- * @return <code>true</code> if <code>frame</code> matches the top of the stack
- * @since 3.0
- */
- private boolean isDuplicate(ContextFrame frame) {
- if (frame == null)
- return false;
- if (fContextFrameStack.isEmpty())
- return false;
- // stack not empty
- ContextFrame top= (ContextFrame) fContextFrameStack.peek();
- return frame.equals(top);
- }
-
- /**
- * Compares <code>frame</code> with most recently removed context frame, returns <code>true</code>
- * if the frames are the same.
- *
- * @param frame the frame to check
- * @return <code>true</code> if <code>frame</code> matches the most recently removed
- * @since 3.0
- */
- private boolean isLastFrame(ContextFrame frame) {
- return frame != null && frame.equals(fLastContext);
- }
-
- /**
- * Shows the given context frame.
- *
- * @param frame the frame to display
- * @param initial <code>true</code> if this is the first frame to be displayed
- * @since 2.0
- */
- private void internalShowContextFrame(ContextFrame frame, boolean initial) {
-
- fContentAssistSubjectControlAdapter.installValidator(frame);
-
- if (frame.fPresenter != null) {
- if (fTextPresentation == null)
- fTextPresentation= new TextPresentation();
- fContentAssistSubjectControlAdapter.installContextInformationPresenter(frame);
- frame.fPresenter.updatePresentation(frame.fOffset, fTextPresentation);
- }
-
- createContextInfoPopup();
-
- fContextInfoText.setText(frame.fInformation.getInformationDisplayString());
- if (fTextPresentation != null)
- TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText);
- resize();
-
- if (initial) {
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP)) {
- if (fContentAssistSubjectControlAdapter.getControl() != null) {
- fTextWidgetSelectionListener= new SelectionAdapter() {
- /*
- * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- validateContextInformation();
- }};
- fContentAssistSubjectControlAdapter.addSelectionListener(fTextWidgetSelectionListener);
- }
- fContentAssistant.addToLayout(this, fContextInfoPopup, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset);
- fContextInfoPopup.setVisible(true);
- }
- } else {
- fContentAssistant.layout(ContentAssistant.LayoutManager.LAYOUT_CONTEXT_INFO_POPUP, frame.fVisibleOffset);
- }
- }
-
- /**
- * Computes all possible context information for the given offset.
- *
- * @param position the offset
- * @return all possible context information for the given offset
- * @since 2.0
- */
- private IContextInformation[] computeContextInformation(int position) {
- return fContentAssistSubjectControlAdapter.computeContextInformation(fContentAssistant, position);
- }
-
- /**
- *Returns the error message generated while computing context information.
- *
- * @return the error message
- */
- private String getErrorMessage() {
- return fContentAssistant.getErrorMessage();
- }
-
- /**
- * Creates the context information popup. This is the tool tip like overlay window.
- */
- private void createContextInfoPopup() {
- if (Helper.okToUse(fContextInfoPopup))
- return;
-
- Control control= fContentAssistSubjectControlAdapter.getControl();
- Display display= control.getDisplay();
-
- fContextInfoPopup= new Shell(control.getShell(), SWT.NO_TRIM | SWT.ON_TOP);
- fContextInfoPopup.setBackground(display.getSystemColor(SWT.COLOR_BLACK));
-
- fContextInfoText= new StyledText(fContextInfoPopup, SWT.MULTI | SWT.READ_ONLY);
-
- Color c= fContentAssistant.getContextInformationPopupBackground();
- if (c == null)
- c= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fContextInfoText.setBackground(c);
-
- c= fContentAssistant.getContextInformationPopupForeground();
- if (c == null)
- c= display.getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fContextInfoText.setForeground(c);
- }
-
- /**
- * Resizes the context information popup.
- * @since 2.0
- */
- private void resize() {
- Point size= fContextInfoText.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
- size.x += 3;
- fContextInfoText.setSize(size);
- fContextInfoText.setLocation(1,1);
- size.x += 2;
- size.y += 2;
- fContextInfoPopup.setSize(size);
- }
-
- /**
- *Hides the context information popup.
- */
- private void hideContextInfoPopup() {
-
- if (Helper.okToUse(fContextInfoPopup)) {
-
- int size= fContextFrameStack.size();
- if (size > 0) {
- fLastContext= (ContextFrame) fContextFrameStack.pop();
- -- size;
- }
-
- if (size > 0) {
- ContextFrame current= (ContextFrame) fContextFrameStack.peek();
- internalShowContextFrame(current, false);
- } else {
-
- fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_INFO_POPUP);
-
- if (fContentAssistSubjectControlAdapter.getControl() != null)
- fContentAssistSubjectControlAdapter.removeSelectionListener(fTextWidgetSelectionListener);
- fTextWidgetSelectionListener= null;
-
- fContextInfoPopup.setVisible(false);
- fContextInfoPopup.dispose();
- fContextInfoPopup= null;
-
- if (fTextPresentation != null) {
- fTextPresentation.clear();
- fTextPresentation= null;
- }
- }
- }
-
- if (fContextInfoPopup == null)
- fContentAssistant.contextInformationClosed();
- }
-
- /**
- * Creates the context selector in case the user has the choice between multiple valid contexts
- * at a given offset.
- */
- private void createContextSelector() {
- if (Helper.okToUse(fContextSelectorShell))
- return;
-
- Control control= fContentAssistSubjectControlAdapter.getControl();
- fContextSelectorShell= new Shell(control.getShell(), SWT.ON_TOP | SWT.RESIZE);
- fContextSelectorTable= new Table(fContextSelectorShell, SWT.H_SCROLL | SWT.V_SCROLL);
-
- int height= fContextSelectorTable.getItemHeight() * 10;
- fContextSelectorShell.setSize(302, height + 2);
- fContextSelectorTable.setSize(300, height);
- fContextSelectorTable.setLocation(1, 1);
-
- fContextSelectorShell.setBackground(control.getDisplay().getSystemColor(SWT.COLOR_BLACK));
-
- Color c= fContentAssistant.getContextSelectorBackground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND);
- fContextSelectorTable.setBackground(c);
-
- c= fContentAssistant.getContextSelectorForeground();
- if (c == null)
- c= control.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND);
- fContextSelectorTable.setForeground(c);
-
- fContextSelectorTable.addSelectionListener(new SelectionListener() {
- public void widgetSelected(SelectionEvent e) {
- }
-
- public void widgetDefaultSelected(SelectionEvent e) {
- insertSelectedContext();
- hideContextSelector();
- }
- });
-
- fPopupCloser.install(fContentAssistant, fContextSelectorTable);
-
- fContextSelectorTable.setHeaderVisible(false);
- fContentAssistant.addToLayout(this, fContextSelectorShell, ContentAssistant.LayoutManager.LAYOUT_CONTEXT_SELECTOR, fContentAssistant.getSelectionOffset());
- }
-
- /**
- * Causes the context information of the context selected in the context selector
- * to be displayed in the context information popup.
- */
- private void insertSelectedContext() {
- int i= fContextSelectorTable.getSelectionIndex();
-
- if (i < 0 || i >= fContextSelectorInput.length)
- return;
-
- int position= fContentAssistSubjectControlAdapter.getSelectedRange().x;
- internalShowContextInfo(createContextFrame(fContextSelectorInput[i], position));
- }
-
- /**
- * Sets the contexts in the context selector to the given set.
- *
- * @param contexts the possible contexts
- */
- private void setContexts(IContextInformation[] contexts) {
- if (Helper.okToUse(fContextSelectorTable)) {
-
- fContextSelectorInput= contexts;
-
- fContextSelectorTable.setRedraw(false);
- fContextSelectorTable.removeAll();
-
- TableItem item;
- IContextInformation t;
- for (int i= 0; i < contexts.length; i++) {
- t= contexts[i];
- item= new TableItem(fContextSelectorTable, SWT.NULL);
- if (t.getImage() != null)
- item.setImage(t.getImage());
- item.setText(t.getContextDisplayString());
- }
-
- fContextSelectorTable.select(0);
- fContextSelectorTable.setRedraw(true);
- }
- }
-
- /**
- * Displays the context selector.
- */
- private void displayContextSelector() {
- if (fContentAssistant.addContentAssistListener(this, ContentAssistant.CONTEXT_SELECTOR))
- fContextSelectorShell.setVisible(true);
- }
-
- /**
- * Hides the context selector.
- */
- private void hideContextSelector() {
- if (Helper.okToUse(fContextSelectorShell)) {
- fContentAssistant.removeContentAssistListener(this, ContentAssistant.CONTEXT_SELECTOR);
-
- fPopupCloser.uninstall();
- fContextSelectorShell.setVisible(false);
- fContextSelectorShell.dispose();
- fContextSelectorShell= null;
- }
-
- if (!Helper.okToUse(fContextInfoPopup))
- fContentAssistant.contextInformationClosed();
- }
-
- /**
- *Returns whether the context selector has the focus.
- *
- * @return <code>true</code> if the context selector has the focus
- */
- public boolean hasFocus() {
- if (Helper.okToUse(fContextSelectorShell))
- return (fContextSelectorShell.isFocusControl() || fContextSelectorTable.isFocusControl());
-
- return false;
- }
-
- /**
- * Hides context selector and context information popup.
- */
- public void hide() {
- hideContextSelector();
- hideContextInfoPopup();
- }
-
- /**
- * Returns whether this context information popup is active. I.e., either
- * a context selector or context information is displayed.
- *
- * @return <code>true</code> if the context selector is active
- */
- public boolean isActive() {
- return (Helper.okToUse(fContextInfoPopup) || Helper.okToUse(fContextSelectorShell));
- }
-
- /*
- * @see IContentAssistListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent e) {
- if (Helper.okToUse(fContextSelectorShell))
- return contextSelectorKeyPressed(e);
- if (Helper.okToUse(fContextInfoPopup))
- return contextInfoPopupKeyPressed(e);
- return true;
- }
-
- /**
- * Processes a key stroke in the context selector.
- *
- * @param e the verify event describing the key stroke
- * @return <code>true</code> if processing can be stopped
- */
- private boolean contextSelectorKeyPressed(VerifyEvent e) {
-
- char key= e.character;
- if (key == 0) {
-
- int change;
- int visibleRows= (fContextSelectorTable.getSize().y / fContextSelectorTable.getItemHeight()) - 1;
- int selection= fContextSelectorTable.getSelectionIndex();
-
- switch (e.keyCode) {
-
- case SWT.ARROW_UP:
- change= (fContextSelectorTable.getSelectionIndex() > 0 ? -1 : 0);
- break;
-
- case SWT.ARROW_DOWN:
- change= (fContextSelectorTable.getSelectionIndex() < fContextSelectorTable.getItemCount() - 1 ? 1 : 0);
- break;
-
- case SWT.PAGE_DOWN :
- change= visibleRows;
- if (selection + change >= fContextSelectorTable.getItemCount())
- change= fContextSelectorTable.getItemCount() - selection;
- break;
-
- case SWT.PAGE_UP :
- change= -visibleRows;
- if (selection + change < 0)
- change= -selection;
- break;
-
- case SWT.HOME :
- change= -selection;
- break;
-
- case SWT.END :
- change= fContextSelectorTable.getItemCount() - selection;
- break;
-
- default:
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hideContextSelector();
- return true;
- }
-
- fContextSelectorTable.setSelection(selection + change);
- fContextSelectorTable.showSelection();
- e.doit= false;
- return false;
-
- } else if ('\t' == key) {
- // switch focus to selector shell
- e.doit= false;
- fContextSelectorShell.setFocus();
- return false;
- } else if (key == 0x1B) {
- // terminate on Esc
- hideContextSelector();
- }
-
- return true;
- }
-
- /**
- * Processes a key stroke while the info popup is up.
- *
- * @param e the verify event describing the key stroke
- * @return <code>true</code> if processing can be stopped
- */
- private boolean contextInfoPopupKeyPressed(KeyEvent e) {
-
- char key= e.character;
- if (key == 0) {
-
- switch (e.keyCode) {
-
- case SWT.ARROW_LEFT:
- case SWT.ARROW_RIGHT:
- validateContextInformation();
- break;
- default:
- if (e.keyCode != SWT.MOD1 && e.keyCode != SWT.MOD2 && e.keyCode != SWT.MOD3 && e.keyCode != SWT.MOD4)
- hideContextInfoPopup();
- break;
- }
-
- } else if (key == 0x1B) {
- // terminate on Esc
- hideContextInfoPopup();
- } else {
- validateContextInformation();
- }
- return true;
- }
-
- /*
- * @see IEventConsumer#processEvent(VerifyEvent)
- */
- public void processEvent(VerifyEvent event) {
- if (Helper.okToUse(fContextSelectorShell))
- contextSelectorProcessEvent(event);
- if (Helper.okToUse(fContextInfoPopup))
- contextInfoPopupProcessEvent(event);
- }
-
- /**
- * Processes a key stroke in the context selector.
- *
- * @param e the verify event describing the key stroke
- */
- private void contextSelectorProcessEvent(VerifyEvent e) {
-
- if (e.start == e.end && e.text != null && e.text.equals(fLineDelimiter)) {
- e.doit= false;
- insertSelectedContext();
- }
-
- hideContextSelector();
- }
-
- /**
- * Processes a key stroke while the info popup is up.
- *
- * @param e the verify event describing the key stroke
- */
- private void contextInfoPopupProcessEvent(VerifyEvent e) {
- if (e.start != e.end && (e.text == null || e.text.length() == 0))
- validateContextInformation();
- }
-
- /**
- * Validates the context information for the viewer's actual cursor position.
- */
- private void validateContextInformation() {
- /*
- * Post the code in the event queue in order to ensure that the
- * action described by this verify key event has already been executed.
- * Otherwise, we'd validate the context information based on the
- * pre-key-stroke state.
- */
- if (!Helper.okToUse(fContextInfoPopup))
- return;
-
- fContextInfoPopup.getDisplay().asyncExec(new Runnable() {
-
- private ContextFrame fFrame= (ContextFrame) fContextFrameStack.peek();
-
- public void run() {
- // only do this if no other frames have been added in between
- if (!fContextFrameStack.isEmpty() && fFrame == fContextFrameStack.peek()) {
- int offset= fContentAssistSubjectControlAdapter.getSelectedRange().x;
-
- // iterate all contexts on the stack
- while (Helper.okToUse(fContextInfoPopup) && !fContextFrameStack.isEmpty()) {
- ContextFrame top= (ContextFrame) fContextFrameStack.peek();
- if (top.fValidator == null || !top.fValidator.isContextInformationValid(offset)) {
- hideContextInfoPopup(); // loop variant: reduces the number of contexts on the stack
- } else if (top.fPresenter != null && top.fPresenter.updatePresentation(offset, fTextPresentation)) {
- TextPresentation.applyTextPresentation(fTextPresentation, fContextInfoText);
- resize();
- break;
- } else
- break;
- }
- }
- }
- });
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java
deleted file mode 100644
index bd4b3b7d4c7..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ContextInformationValidator.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * A default implementation of the <code>IContextInfomationValidator</code> interface.
- * This implementation determines whether the information is valid by asking the content
- * assist processor for all context information objects for the current position. If the
- * currently displayed information is in the result set, the context information is
- * considered valid.
- */
-public final class ContextInformationValidator implements IContextInformationValidator {
-
- /** The content assist processor */
- private IContentAssistProcessor fProcessor;
- /** The context information to be validated */
- private IContextInformation fContextInformation;
- /** The associated text viewer */
- private ITextViewer fViewer;
-
- /**
- * Creates a new context information validator which is ready to be installed on
- * a particular context information.
- *
- * @param processor the processor to be used for validation
- */
- public ContextInformationValidator(IContentAssistProcessor processor) {
- fProcessor= processor;
- }
-
- /*
- * @see IContextInformationValidator#install(IContextInformation, ITextViewer, int)
- */
- public void install(IContextInformation contextInformation, ITextViewer viewer, int position) {
- fContextInformation= contextInformation;
- fViewer= viewer;
- }
-
- /*
- * @see IContentAssistTipCloser#isContextInformationValid(int)
- */
- public boolean isContextInformationValid(int position) {
- IContextInformation[] infos= fProcessor.computeContextInformation(fViewer, position);
- if (infos != null && infos.length > 0) {
- for (int i= 0; i < infos.length; i++)
- if (fContextInformation.equals(infos[i]))
- return true;
- }
- return false;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java
deleted file mode 100644
index 735b8a863a9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/Helper.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.swt.widgets.Widget;
-
-
-/**
- * Helper class for testing widget state.
- */
-class Helper {
-
- /**
- * Returns whether the widget is <code>null</code> or disposed.
- *
- * @param widget the widget to check
- * @return <code>true</code> if the widget is neither <code>null</code> nor disposed
- */
- public static boolean okToUse(Widget widget) {
- return (widget != null && !widget.isDisposed());
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java
deleted file mode 100644
index 837dd796490..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposal.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * The interface of completion proposals generated by content assist processors.
- * A completion proposal contains information used to present the proposed completion
- * to the user, to insert the completion should the user select it, and to present
- * context information for the choosen completion once it has been inserted.<p>
- * The interface can be implemented by clients. By default, clients use
- * <code>CompletionProposal</code> as the standard implementer of this interface.
- *
- * @see IContentAssistProcessor
- */
-public interface ICompletionProposal {
-
- /**
- * Inserts the proposed completion into the given document.
- *
- * @param document the document into which to insert the proposed completion
- */
- void apply(IDocument document);
-
- /**
- * Returns the new selection after the proposal has been applied to
- * the given document in absolute document coordinates. If it returns
- * <code>null</code>, no new selection is set.
- *
- * A document change can trigger other document changes, which have
- * to be taken into account when calculating the new selection. Typically,
- * this would be done by installing a document listener or by using a
- * document position during apply().
- *
- * @param document the document into which the proposed completion has been inserted
- * @return the new selection in absolute document coordinates
- */
- Point getSelection(IDocument document);
-
- /**
- * Returns optional additional information about the proposal.
- * The additional information will be presented to assist the user
- * in deciding if the selected proposal is the desired choice.
- *
- * @return the additional information or <code>null</code>
- */
- String getAdditionalProposalInfo();
-
- /**
- * Returns the string to be displayed in the list of completion proposals.
- *
- * @return the string to be displayed
- */
- String getDisplayString();
-
- /**
- * Returns the image to be displayed in the list of completion proposals.
- * The image would typically be shown to the left of the display string.
- *
- * @return the image to be shown or <code>null</code> if no image is desired
- */
- Image getImage();
-
- /**
- * Returns optional context information associated with this proposal.
- * The context information will automatically be shown if the proposal
- * has been applied.
- *
- * @return the context information for this proposal or <code>null</code>
- */
- IContextInformation getContextInformation();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java
deleted file mode 100644
index c75872a9248..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * Extension interface to <code>ICompletionProposal</code>.
- * Add the following functions:
- * <ul>
- * <li> handling of trigger characters other then ENTER
- * <li> completion proposal validation for a given offset
- * <li> freely positionable context information
- * </ul>
- *
- * @since 2.0
- */
-public interface ICompletionProposalExtension {
-
- /**
- * Applies the proposed completion to the given document. The insertion
- * has been triggered by entering the given character at the given offset.
- * This method assumes that <code>isValidFor</code> returns
- * <code>true</code> if called for <code>offset</code>.
- *
- * @param document the document into which to insert the proposed completion
- * @param trigger the trigger to apply the completion
- * @param offset the offset at which the trigger has been activated
- */
- void apply(IDocument document, char trigger, int offset);
-
- /**
- * Returns whether this completion proposal is valid for the given
- * position in the given document.
- *
- * @param document the document for which the proposal is tested
- * @param offset the offset for which the proposal is tested
- * @return <code>true</code> iff valid
- */
- boolean isValidFor(IDocument document, int offset);
-
- /**
- * Returns the characters which trigger the application of this completion proposal.
- *
- * @return the completion characters for this completion proposal or <code>null</code>
- * if no completion other than the new line character is possible
- */
- char[] getTriggerCharacters();
-
- /**
- * Returns the position to which the computed context information refers to or
- * <code>-1</code> if no context information can be provided by this completion proposal.
- *
- * @return the position to which the context information refers to or <code>-1</code> for no information
- */
- int getContextInformationPosition();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension2.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension2.java
deleted file mode 100644
index a36514f0271..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension2.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * Extension interface to <code>ICompletionProposal</code>.
- * Add the following functions:
- * <ul>
- * <li> handling of trigger characters with modifiers
- * <li> visual indication for selection of a proposal
- * </ul>
- *
- * @since 2.1
- */
-public interface ICompletionProposalExtension2 {
-
- /**
- * Applies the proposed completion to the given document. The insertion
- * has been triggered by entering the given character with a modifier at the given offset.
- * This method assumes that <code>isValidFor</code> returns
- * <code>true</code> if called for <code>offset</code>.
- *
- * @param viewer the text viewer into which to insert the proposed completion
- * @param trigger the trigger to apply the completion
- * @param stateMask the state mask of the modifiers
- * @param offset the offset at which the trigger has been activated
- */
- void apply(ITextViewer viewer, char trigger, int stateMask, int offset);
-
- /**
- * Called when the proposal is selected.
- *
- * @param viewer the text viewer.
- * @param smartToggle the smart toggle key was pressed
- */
- void selected(ITextViewer viewer, boolean smartToggle);
-
- /**
- * Called when the proposal is unselected.
- *
- * @param viewer the text viewer.
- */
- void unselected(ITextViewer viewer);
-
- /**
- * Requests the proposal to be validated with respect to the document event.
- * If the proposal cannot be validated, the methods returns <code>false</code>.
- * If the document event was <code>null</code>, only the caret offset was changed, but not the document.
- *
- * This method deprecates ICompletionProposalExtension.isValidFor(IDocument, int)
- *
- * @param document the document
- * @param offset the caret offset
- * @param event the document event, may be <code>null</code>
- * @return boolean
- */
- boolean validate(IDocument document, int offset, DocumentEvent event);
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension3.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension3.java
deleted file mode 100644
index 78bb15abcab..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/ICompletionProposalExtension3.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControlCreator;
-
-
-/**
- * Extension interface to <code>ICompletionProposal</code>.
- * Add the following functions:
- * <ul>
- * <li>provision of a custom information control creator</li>
- * <li>provide a custom completion text and offset for prefix completion</li>
- * </ul>
- *
- * @since 3.0
- */
-public interface ICompletionProposalExtension3 {
- /**
- * Returns the information control creator of this completion proposal.
- *
- * @return the information control creator, or <code>null</code> if no custom control creater is available
- */
- IInformationControlCreator getInformationControlCreator();
-
- /**
- * Returns the string that would be inserted at the position returned from
- * <code>getPrefixCompletionStart(IDocument, int)</code> if this proposal was
- * applied. If the replacement string cannot be determined,
- * <code>null</code> may be returned.
- * <p>
- * If this interface is not implemented,
- * {@link ICompletionProposal#getDisplayString()} will be used instead.
- * </p>
- *
- * @param document the document that the receiver applies to
- * @param completionOffset the offset into <code>document</code> where the
- * completion takes place
- * @return the replacement string or <code>null</code> if it cannot be
- * determined
- */
- CharSequence getPrefixCompletionText(IDocument document, int completionOffset);
-
- /**
- * Returns the document offset at which the receiver would insert its
- * proposal.
- * <p>
- * If this interface is not implemented, <code>completionOffset</code> will
- * be used instead.
- * </p>
- *
- * @param document the document that the receiver applies to
- * @param completionOffset the offset into <code>document</code> where the
- * completion takes place
- * @return the offset at which the proposal would insert its proposal
- */
- int getPrefixCompletionStart(IDocument document, int completionOffset);
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java
deleted file mode 100644
index 1decc9fd020..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistListener.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.swt.events.VerifyEvent;
-
-import org.eclipse.jface.text.IEventConsumer;
-
-
-
-/**
- * An interface whereby listeners can not only receive key events,
- * but can also consume them to prevent subsequent listeners from
- * processing the event.
- */
-interface IContentAssistListener extends IEventConsumer {
-
- /**
- * Verifies the key event.
- *
- * @param event the verify event
- * @return <code>true</code> if processing should be continued by additional listeners
- * @see org.eclipse.swt.custom.VerifyKeyListener#verifyKey(VerifyEvent)
- */
- public boolean verifyKey(VerifyEvent event);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java
deleted file mode 100644
index 75435ea6d61..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistProcessor.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-
-/**
- * A content assist processor proposes completions and
- * computes context information for a particular content type.
- * A content assist processor is an <code>IContentAssistant</code>-plug-ins.
- * This interface must be implemented by clients. Implementers should be
- * registered with a content assistant in order to get involved in the
- * assisting process.
-*/
-public interface IContentAssistProcessor {
-
- /**
- * Returns a list of completion proposals based on the
- * specified location within the document that corresponds
- * to the current cursor position within the text viewer.
- *
- * @param viewer the viewer whose document is used to compute the proposals
- * @param documentOffset an offset within the document for which completions should be computed
- * @return an array of completion proposals or <code>null</code> if no proposals are possible
- */
- ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int documentOffset);
-
- /**
- * Returns information about possible contexts based on the
- * specified location within the document that corresponds
- * to the current cursor position within the text viewer.
- *
- * @param viewer the viewer whose document is used to compute the possible contexts
- * @param documentOffset an offset within the document for which context information should be computed
- * @return an array of context information objects or <code>null</code> if no context could be found
- */
- IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset);
-
- /**
- * Returns the characters which when entered by the user should
- * automatically trigger the presentation of possible completions.
- *
- * @return the auto activation characters for completion proposal or <code>null</code>
- * if no auto activation is desired
- */
- char[] getCompletionProposalAutoActivationCharacters();
-
- /**
- * Returns the characters which when entered by the user should
- * automatically trigger the presentation of context information.
- *
- * @return the auto activation characters for presenting context information
- * or <code>null</code> if no auto activation is desired
- */
- char[] getContextInformationAutoActivationCharacters();
-
- /**
- * Returns the reason why this content assist processor
- * was unable to produce any completion proposals or context information.
- *
- * @return an error message or <code>null</code> if no error occurred
- */
- String getErrorMessage();
-
- /**
- * Returns a validator used to determine when displayed context information
- * should be dismissed. May only return <code>null</code> if the processor is
- * incapable of computing context information. <p>
- *
- * @return a context information validator, or <code>null</code> if the processor
- * is incapable of computing context information
- */
- IContextInformationValidator getContextInformationValidator();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java
deleted file mode 100644
index 7a623c3efa1..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistant.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * An <code>IContentAssistant</code> provides support on interactive content completion.
- * The content assistant is a <code>ITextViewer</code> add-on. Its
- * purpose is to propose, display, and insert completions of the content
- * of the text viewer's document at the viewer's cursor position. In addition
- * to handle completions, a content assistant can also be requested to provide
- * context information. Context information is shown in a tooltip like popup.
- * As it is not always possible to determine the exact context at a given
- * document offset, a content assistant displays the possible contexts and requests
- * the user to choose the one whose information should be displayed.<p>
- * A content assistant has a list of <code>IContentAssistProcessor</code>
- * objects each of which is registered for a particular document content
- * type. The content assistant uses the processors to react on the request
- * of completing documents or presenting context information.<p>
- * The interface can be implemented by clients. By default, clients use
- * <code>ContentAssistant</code> as the standard implementer of this interface.
- *
- * @see ITextViewer
- * @see IContentAssistProcessor
- */
-
- public interface IContentAssistant {
-
- //------ proposal popup orientation styles ------------
- /** The context info list will overlay the list of completion proposals. */
- public final static int PROPOSAL_OVERLAY= 10;
- /** The completion proposal list will be removed before the context info list will be shown. */
- public final static int PROPOSAL_REMOVE= 11;
- /** The context info list will be presented without hiding or overlapping the completion proposal list. */
- public final static int PROPOSAL_STACKED= 12;
-
- //------ context info box orientation styles ----------
- /** Context info will be shown above the location it has been requested for without hiding the location. */
- public final static int CONTEXT_INFO_ABOVE= 20;
- /** Context info will be shown below the location it has been requested for without hiding the location. */
- public final static int CONTEXT_INFO_BELOW= 21;
-
-
- /**
- * Installs content assist support on the given text viewer.
- *
- * @param textViewer the text viewer on which content assist will work
- */
- void install(ITextViewer textViewer);
-
- /**
- * Uninstalls content assist support from the text viewer it has
- * previously be installed on.
- */
- void uninstall();
-
- /**
- * Shows all possible completions of the content at the viewer's cursor position.
- *
- * @return an optional error message if no proposals can be computed
- */
- String showPossibleCompletions();
-
- /**
- * Shows context information for the content at the viewer's cursor position.
- *
- * @return an optional error message if no context information can be computed
- */
- String showContextInformation();
-
- /**
- * Returns the content assist processor to be used for the given content type.
- *
- * @param contentType the type of the content for which this
- * content assistant is to be requested
- * @return an instance content assist processor or
- * <code>null</code> if none exists for the specified content type
- */
- IContentAssistProcessor getContentAssistProcessor(String contentType);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistantExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistantExtension.java
deleted file mode 100644
index 3892c4f30b6..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContentAssistantExtension.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-/**
- * Extension interface for <code>IContentAssistant</code>.
- * Updates the content assistant to be aware of documents with multiple partitions.
- *
- * @since 3.0
- */
-public interface IContentAssistantExtension {
-
- /**
- * Returns the document partitioning this content assistant is using.
- *
- * @return the document partitioning this content assistant is using
- */
- String getDocumentPartitioning();
-
- /**
- * Complete the common prefix of the available choices.
- *
- * @return an optional error message if no proposals can be computed
- */
- String completePrefix();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java
deleted file mode 100644
index 921817ba6d2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformation.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.swt.graphics.Image;
-
-
-/**
- * The inferface of context information presented to the user and
- * generated by content assist processors.
- * The interface can be implemented by clients. By default, clients use
- * <code>ContextInformation</code> as the standard implementer of this interface.
- *
- * @see IContentAssistProcessor
- */
-public interface IContextInformation {
-
- /**
- * Returns the string to be displayed in the list of contexts.
- * This method is used to supply a unique presentation for
- * situations where the context is ambiguous. These strings are
- * used to allow the user to select the specific context.
- *
- * @return the string to be displayed for the context
- */
- String getContextDisplayString();
-
- /**
- * Returns the image for this context information.
- * The image will be shown to the left of the display string.
- *
- * @return the image to be shown or <code>null</code> if no image is desired
- */
- Image getImage();
-
- /**
- * Returns the string to be displayed in the tooltip like information popup.
- *
- * @return the string to be displayed
- */
- String getInformationDisplayString();
-
- /**
- * Compares the given object with this receiver. Two context informations are
- * equal if there information display strings and their context display strings
- * are equal.
- *
- * @see Object#equals(Object)
- */
- boolean equals(Object object);
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java
deleted file mode 100644
index 2c51a4afcc4..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationExtension.java
+++ /dev/null
@@ -1,29 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-/**
- * Extension interface for <code>IContextInformation</code>.
- * Adds the functionality of freely positionable context information.
- *
- * @since 2.0
- */
-public interface IContextInformationExtension {
-
- /**
- * Returns the start offset of the range for which this context information is valid.
- *
- * @return the start offset of the range for which this context information is valid
- */
- int getContextInformationPosition();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java
deleted file mode 100644
index b6e6b8edab8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationPresenter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.TextPresentation;
-
-
-/**
- * A context information presenter determines the presentation
- * of context information depending on a given document position.
- * The interface can be implemented by clients.
- *
- * @since 2.0
- */
-public interface IContextInformationPresenter {
-
- /**
- * Installs this presenter for the given context information.
- *
- * @param info the context information which this presenter should style
- * @param viewer the text viewer on which the information is presented
- * @param documentPosition the document position for which the information has been computed
- */
- void install(IContextInformation info, ITextViewer viewer, int documentPosition);
-
- /**
- * Updates the given presentation of the given context information
- * at the given document position. Returns whether update changed the
- * presentation.
- *
- * @param documentPosition the current position within the document
- * @param presentation the presentation to be updated
- * @return <code>true</code> if the given presentation has been changed
- */
- boolean updatePresentation(int documentPosition, TextPresentation presentation);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java
deleted file mode 100644
index f5e75c73c36..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/IContextInformationValidator.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * A context information validator is used to determine if
- * a displayed context information is still valid or should
- * be dismissed. The interface can be implemented by clients.
- *
- * @see IContextInformationPresenter
- */
-public interface IContextInformationValidator {
-
- /**
- * Installs this validator for the given context information.
- *
- * @param info the context information which this validator should check
- * @param viewer the text viewer on which the information is presented
- * @param documentPosition the document position for which the information has been computed
- */
- void install(IContextInformation info, ITextViewer viewer, int documentPosition);
-
- /**
- * Returns whether the information this validator is installed on is still valid
- * at the given document position.
- *
- * @param documentPosition the current position within the document
- * @return <code>true</code> if the information also valid at the given document position
- */
- boolean isContextInformationValid(int documentPosition);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java
deleted file mode 100644
index bb7dca87ab8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/JFaceTextMessages.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-class JFaceTextMessages {
-
- private static final String RESOURCE_BUNDLE= "org.eclipse.jface.text.JFaceTextMessages";//$NON-NLS-1$
-
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JFaceTextMessages() {
- }
-
- 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.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java
deleted file mode 100644
index 22becc8884b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/PopupCloser.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.contentassist;
-
-
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.ScrollBar;
-import org.eclipse.swt.widgets.Table;
-
-
-/**
- * A generic closer class used to monitor various
- * interface events in order to determine whether
- * a content assistant should be terminated and all
- * associated windows be closed.
- */
-class PopupCloser implements FocusListener, SelectionListener {
-
- /** The content assistant to be monitored */
- private ContentAssistant fContentAssistant;
- /** The table of a selector popup opened by the content assistant */
- private Table fTable;
- /** The scrollbar of the table for the selector popup */
- private ScrollBar fScrollbar;
- /** Indicates whether the scrollbar thumb has been grabed */
- private boolean fScrollbarClicked= false;
-
- /**
- * Installs this closer on the given table opened by the given content assistant.
- *
- * @param contentAssistant the content assistant
- * @param table the table to be tracked
- */
- public void install(ContentAssistant contentAssistant, Table table) {
- fContentAssistant= contentAssistant;
- fTable= table;
- if (Helper.okToUse(fTable)) {
- fTable.addFocusListener(this);
- fScrollbar= fTable.getVerticalBar();
- if (fScrollbar != null)
- fScrollbar.addSelectionListener(this);
- }
- }
-
- /**
- * Uninstalls this closer if previously installed.
- */
- public void uninstall() {
- if (Helper.okToUse(fScrollbar))
- fScrollbar.removeSelectionListener(this);
- if (Helper.okToUse(fTable))
- fTable.removeFocusListener(this);
- }
-
- /*
- * @see org.eclipse.swt.events.SelectionListener#widgetSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetSelected(SelectionEvent e) {
- fScrollbarClicked= true;
- }
-
- /*
- * @see org.eclipse.swt.events.SelectionListener#widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent)
- */
- public void widgetDefaultSelected(SelectionEvent e) {
- fScrollbarClicked= true;
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusGained(org.eclipse.swt.events.FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see org.eclipse.swt.events.FocusListener#focusLost(org.eclipse.swt.events.FocusEvent)
- */
- public void focusLost(final FocusEvent e) {
- fScrollbarClicked= false;
- Display d= fTable.getDisplay();
- d.asyncExec(new Runnable() {
- public void run() {
- if (Helper.okToUse(fTable) && !fTable.isFocusControl() && !fScrollbarClicked)
- fContentAssistant.popupFocusLost(e);
- }
- });
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/package.html
deleted file mode 100644
index 2d94dfb3203..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/contentassist/package.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a content assist add-on for an <tt>ITextViewer</tt>.
-Content assist supports the user in writing&nbsp; by proposing context
-sensitive completions at a given document position. A completion can also
-be a incomplete in itself and content assist provides means to deal with
-nested completions.
-<h2>
-Package Specification</h2>
-<tt>IContentAssistant</tt> defines the concept of the content assist add-on.
-It collaborates with content type specific completion processors (<tt>IContentAssistProcessor</tt>)
-in order to generate completion proposals (<tt>ICompletionProposal</tt>)
-valid at the current document position. The package provides a default
-implementation <tt>ContentAssistant</tt> which completely defines and implements
-the UI and the control flow for content assist.
-<br>&nbsp;
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
deleted file mode 100644
index be12b1f9e4b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContentFormatter.java
+++ /dev/null
@@ -1,796 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.TypedPosition;
-
-
-/**
- * Standard implementation of <code>IContentFormatter</code>.
- * The formatter supports two operation modes: partition aware and
- * partition unaware. <p>
- * In the partition aware mode, the formatter determines the
- * partitioning of the document region to be formatted. For each
- * partition it determines all document positions which are affected
- * when text changes are applied to the partition. Those which overlap
- * with the partition are remembered as character positions. These
- * character positions are passed over to the formatting strategy
- * registered for the partition's content type. The formatting strategy
- * returns a string containing the formatted document partition as well
- * as the adapted character positions. The formatted partition replaces
- * the old content of the partition. The remembered document positions
- * are updated with the adapted character positions. In addition, all
- * other document positions are accordingly adapted to the formatting
- * changes.<p>
- * In the partition unaware mode, the document's partitioning is ignored
- * and the document is considered consisting of only one partition of
- * the content type <code>IDocument.DEFAULT_CONTENT_TYPE</code>. The
- * formatting process is similar to the partition aware mode, with the
- * exception of having only one partition.<p>
- * Usually, clients instantiate this class and configure it before using it.
- *
- * @see IContentFormatter
- * @see IDocument
- * @see ITypedRegion
- * @see Position
- */
-public class ContentFormatter implements IContentFormatter {
-
- /**
- * Defines a reference to either the offset or the end offset of
- * a particular position.
- */
- static class PositionReference implements Comparable {
-
- /** The referenced position */
- protected Position fPosition;
- /** The reference to either the offset or the end offset */
- protected boolean fRefersToOffset;
- /** The original category of the referenced position */
- protected String fCategory;
-
- /**
- * Creates a new position reference.
- *
- * @param position the position to be referenced
- * @param refersToOffset <code>true</code> if position offset should be referenced
- * @param category the category the given position belongs to
- */
- protected PositionReference(Position position, boolean refersToOffset, String category) {
- fPosition= position;
- fRefersToOffset= refersToOffset;
- fCategory= category;
- }
-
- /**
- * Returns the offset of the referenced position.
- *
- * @return the offset of the referenced position
- */
- protected int getOffset() {
- return fPosition.getOffset();
- }
-
- /**
- * Manipulates the offset of the referenced position.
- *
- * @param offset the new offset of the referenced position
- */
- protected void setOffset(int offset) {
- fPosition.setOffset(offset);
- }
-
- /**
- * Returns the length of the referenced position.
- *
- * @return the length of the referenced position
- */
- protected int getLength() {
- return fPosition.getLength();
- }
-
- /**
- * Manipulates the length of the referenced position.
- *
- * @param length the new length of the referenced position
- */
- protected void setLength(int length) {
- fPosition.setLength(length);
- }
-
- /**
- * Returns whether this reference points to the offset or end offset
- * of the references position.
- *
- * @return <code>true</code> if the offset of the position is referenced, <code>false</code> otherwise
- */
- protected boolean refersToOffset() {
- return fRefersToOffset;
- }
-
- /**
- * Returns the category of the referenced position.
- *
- * @return the category of the referenced position
- */
- protected String getCategory() {
- return fCategory;
- }
-
- /**
- * Returns the referenced position.
- *
- * @return the referenced position
- */
- protected Position getPosition() {
- return fPosition;
- }
-
- /**
- * Returns the referenced character position
- *
- * @return the referenced character position
- */
- protected int getCharacterPosition() {
- if (fRefersToOffset)
- return getOffset();
- return getOffset() + getLength();
- }
-
- /*
- * @see Comparable#compareTo(Object)
- */
- public int compareTo(Object obj) {
-
- if (obj instanceof PositionReference) {
- PositionReference r= (PositionReference) obj;
- return getCharacterPosition() - r.getCharacterPosition();
- }
-
- throw new ClassCastException();
- }
- }
-
- /**
- * The position updater used to update the remembered partitions.
- *
- * @see IPositionUpdater
- * @see DefaultPositionUpdater
- */
- class NonDeletingPositionUpdater extends DefaultPositionUpdater {
-
- /**
- * Creates a new updater for the given category.
- *
- * @param category the category
- */
- protected NonDeletingPositionUpdater(String category) {
- super(category);
- }
-
- /*
- * @see DefaultPositionUpdater#notDeleted()
- */
- protected boolean notDeleted() {
- return true;
- }
- }
-
- /**
- * The position updater which runs as first updater on the document's positions.
- * Used to remove all affected positions from their categories to avoid them
- * from being regularly updated.
- *
- * @see IPositionUpdater
- */
- class RemoveAffectedPositions implements IPositionUpdater {
- /**
- * @see IPositionUpdater#update(DocumentEvent)
- */
- public void update(DocumentEvent event) {
- removeAffectedPositions(event.getDocument());
- }
- }
-
- /**
- * The position updater which runs as last updater on the document's positions.
- * Used to update all affected positions and adding them back to their
- * original categories.
- *
- * @see IPositionUpdater
- */
- class UpdateAffectedPositions implements IPositionUpdater {
-
- /** The affected positions */
- private int[] fPositions;
- /** The offset */
- private int fOffset;
-
- /**
- * Creates a new updater.
- *
- * @param positions the affected positions
- * @param offset the offset
- */
- public UpdateAffectedPositions(int[] positions, int offset) {
- fPositions= positions;
- fOffset= offset;
- }
-
- /*
- * @see IPositionUpdater#update(DocumentEvent)
- */
- public void update(DocumentEvent event) {
- updateAffectedPositions(event.getDocument(), fPositions, fOffset);
- }
- }
-
-
- /** Internal position category used for the formatter partitioning */
- private final static String PARTITIONING= "__formatter_partitioning"; //$NON-NLS-1$
-
- /** The map of <code>IFormattingStrategy</code> objects */
- private Map fStrategies;
- /** The indicator of whether the formatter operates in partition aware mode or not */
- private boolean fIsPartitionAware= true;
-
- /** The partition information managing document position categories */
- private String[] fPartitionManagingCategories;
- /** The list of references to offset and end offset of all overlapping positions */
- private List fOverlappingPositionReferences;
- /** Position updater used for partitioning positions */
- private IPositionUpdater fPartitioningUpdater;
- /**
- * The document partitioning used by this formatter.
- * @since 3.0
- */
- private String fPartitioning;
- /**
- * The document this formatter works on.
- * @since 3.0
- */
- private IDocument fDocument;
- /**
- * The external partition managing categories.
- * @since 3.0
- */
- private String[] fExternalPartitonManagingCategories;
- /**
- * Indicates whether <code>fPartitionManagingCategories</code> must be computed.
- * @since 3.0
- */
- private boolean fNeedsComputation= true;
-
-
- /**
- * Creates a new content formatter. The content formatter operates by default
- * in the partition-aware mode. There are no preconfigured formatting strategies.
- * Will use the default document partitioning if not further configured.
- */
- public ContentFormatter() {
- fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
- }
-
- /**
- * Registers a strategy for a particular content type. If there is already a strategy
- * registered for this type, the new strategy is registered instead of the old one.
- * If the given content type is <code>null</code> the given strategy is registered for
- * all content types as is called only once per formatting session.
- *
- * @param strategy the formatting strategy to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register, or <code>null</code> for all content types
- */
- public void setFormattingStrategy(IFormattingStrategy strategy, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fStrategies == null)
- fStrategies= new HashMap();
-
- if (strategy == null)
- fStrategies.remove(contentType);
- else
- fStrategies.put(contentType, strategy);
- }
-
- /**
- * Informs this content formatter about the names of those position categories
- * which are used to manage the document's partitioning information and thus should
- * be ignored when this formatter updates positions.
- *
- * @param categories the categories to be ignored
- * @deprecated incompatible with an open set of document partitionings. The provided information is only used
- * if this formatter can not compute the partition managing position categories.
- */
- public void setPartitionManagingPositionCategories(String[] categories) {
- fExternalPartitonManagingCategories= categories;
- }
-
- /**
- * Sets the document partitioning to be used by this formatter.
- *
- * @param partitioning the document partitioning
- * @since 3.0
- */
- public void setDocumentPartitioning(String partitioning) {
- fPartitioning= partitioning;
- }
-
- /**
- * Sets the formatter's operation mode.
- *
- * @param enable indicates whether the formatting process should be partition ware
- */
- public void enablePartitionAwareFormatting(boolean enable) {
- fIsPartitionAware= enable;
- }
-
- /*
- * @see IContentFormatter#getFormattingStrategy(String)
- */
- public IFormattingStrategy getFormattingStrategy(String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fStrategies == null)
- return null;
-
- return (IFormattingStrategy) fStrategies.get(contentType);
- }
-
- /*
- * @see IContentFormatter#format(IDocument, IRegion)
- */
- public void format(IDocument document, IRegion region) {
- fNeedsComputation= true;
- fDocument= document;
- try {
-
- if (fIsPartitionAware)
- formatPartitions(region);
- else
- formatRegion(region);
-
- } finally {
- fNeedsComputation= true;
- fDocument= null;
- }
- }
-
- /**
- * Determines the partitioning of the given region of the document.
- * Informs the formatting strategies of each partition about the start,
- * the process, and the termination of the formatting session.
- *
- * @param region the document region to be formatted
- * @since 3.0
- */
- private void formatPartitions(IRegion region) {
-
- addPartitioningUpdater();
-
- try {
-
- TypedPosition[] ranges= getPartitioning(region);
- if (ranges != null) {
- start(ranges, getIndentation(region.getOffset()));
- format(ranges);
- stop(ranges);
- }
-
- } catch (BadLocationException x) {
- }
-
- removePartitioningUpdater();
- }
-
- /**
- * Formats the given region with the strategy registered for the default
- * content type. The strategy is informed about the start, the process, and
- * the termination of the formatting session.
- *
- * @param region the region to be formatted
- * @since 3.0
- */
- private void formatRegion(IRegion region) {
-
- IFormattingStrategy strategy= getFormattingStrategy(IDocument.DEFAULT_CONTENT_TYPE);
- if (strategy != null) {
- strategy.formatterStarts(getIndentation(region.getOffset()));
- format(strategy, new TypedPosition(region.getOffset(), region.getLength(), IDocument.DEFAULT_CONTENT_TYPE));
- strategy.formatterStops();
- }
- }
-
- /**
- * Returns the partitioning of the given region of the specified document.
- * As one partition after the other will be formatted and formatting will
- * probably change the length of the formatted partition, it must be kept
- * track of the modifications in order to submit the correct partition to all
- * formatting strategies. For this, all partitions are remembered as positions
- * in a dedicated position category. (As formatting strategies might rely on each
- * other, calling them in reversed order is not an option.)
- *
- * @param region the region for which the partitioning must be determined
- * @return the partitioning of the specified region
- * @exception BadLocationException of region is invalid in the document
- * @since 3.0
- */
- private TypedPosition[] getPartitioning(IRegion region) throws BadLocationException {
-
- ITypedRegion[] regions= TextUtilities.computePartitioning(fDocument, fPartitioning, region.getOffset(), region.getLength(), false);
- TypedPosition[] positions= new TypedPosition[regions.length];
-
- for (int i= 0; i < regions.length; i++) {
- positions[i]= new TypedPosition(regions[i]);
- try {
- fDocument.addPosition(PARTITIONING, positions[i]);
- } catch (BadPositionCategoryException x) {
- // should not happen
- }
- }
-
- return positions;
- }
-
- /**
- * Fires <code>formatterStarts</code> to all formatter strategies
- * which will be involved in the forthcoming formatting process.
- *
- * @param regions the partitioning of the document to be formatted
- * @param indentation the initial indentation
- */
- private void start(TypedPosition[] regions, String indentation) {
- for (int i= 0; i < regions.length; i++) {
- IFormattingStrategy s= getFormattingStrategy(regions[i].getType());
- if (s != null)
- s.formatterStarts(indentation);
- }
- }
-
- /**
- * Formats one partition after the other using the formatter strategy registered for
- * the partition's content type.
- *
- * @param ranges the partitioning of the document region to be formatted
- * @since 3.0
- */
- private void format(TypedPosition[] ranges) {
- for (int i= 0; i < ranges.length; i++) {
- IFormattingStrategy s= getFormattingStrategy(ranges[i].getType());
- if (s != null) {
- format(s, ranges[i]);
- }
- }
- }
-
- /**
- * Formats the given region of the document using the specified formatting
- * strategy. In order to maintain positions correctly, first all affected
- * positions determined, after all document listeners have been informed about
- * the coming change, the affected positions are removed to avoid that they
- * are regularly updated. After all position updaters have run, the affected
- * positions are updated with the formatter's information and added back to
- * their categories, right before the first document listener is informed about
- * that a change happened.
- *
- * @param strategy the strategy to be used
- * @param region the region to be formatted
- * @since 3.0
- */
- private void format(IFormattingStrategy strategy, TypedPosition region) {
- try {
-
- final int offset= region.getOffset();
- int length= region.getLength();
-
- String content= fDocument.get(offset, length);
- final int[] positions= getAffectedPositions(offset, length);
- String formatted= strategy.format(content, isLineStart(offset), getIndentation(offset), positions);
-
- if (formatted != null && !formatted.equals(content)) {
-
- IPositionUpdater first= new RemoveAffectedPositions();
- fDocument.insertPositionUpdater(first, 0);
- IPositionUpdater last= new UpdateAffectedPositions(positions, offset);
- fDocument.addPositionUpdater(last);
-
- fDocument.replace(offset, length, formatted);
-
- fDocument.removePositionUpdater(first);
- fDocument.removePositionUpdater(last);
- }
-
- } catch (BadLocationException x) {
- // should not happen
- }
- }
-
- /**
- * Fires <code>formatterStops</code> to all formatter strategies which were
- * involved in the formatting process which is about to terminate.
- *
- * @param regions the partitioning of the document which has been formatted
- */
- private void stop(TypedPosition[] regions) {
- for (int i= 0; i < regions.length; i++) {
- IFormattingStrategy s= getFormattingStrategy(regions[i].getType());
- if (s != null)
- s.formatterStops();
- }
- }
-
- /**
- * Installs those updaters which the formatter needs to keep track of the partitions.
- * @since 3.0
- */
- private void addPartitioningUpdater() {
- fPartitioningUpdater= new NonDeletingPositionUpdater(PARTITIONING);
- fDocument.addPositionCategory(PARTITIONING);
- fDocument.addPositionUpdater(fPartitioningUpdater);
- }
-
- /**
- * Removes the formatter's internal position updater and category.
- *
- * @since 3.0
- */
- private void removePartitioningUpdater() {
-
- try {
-
- fDocument.removePositionUpdater(fPartitioningUpdater);
- fDocument.removePositionCategory(PARTITIONING);
- fPartitioningUpdater= null;
-
- } catch (BadPositionCategoryException x) {
- // should not happen
- }
- }
-
- /**
- * Returns the partition managing position categories for the formatted document.
- *
- * @return the position managing position categories
- * @since 3.0
- */
- private String[] getPartitionManagingCategories() {
- if (fNeedsComputation) {
- fNeedsComputation= false;
- fPartitionManagingCategories= TextUtilities.computePartitionManagingCategories(fDocument);
- if (fPartitionManagingCategories == null)
- fPartitionManagingCategories= fExternalPartitonManagingCategories;
- }
- return fPartitionManagingCategories;
- }
-
- /**
- * Determines whether the given document position category should be ignored
- * by this formatter's position updating.
- *
- * @param category the category to check
- * @return <code>true</code> if the category should be ignored, <code>false</code> otherwise
- */
- private boolean ignoreCategory(String category) {
-
- if (PARTITIONING.equals(category))
- return true;
-
- String[] categories= getPartitionManagingCategories();
- if (categories != null) {
- for (int i= 0; i < categories.length; i++) {
- if (categories[i].equals(category))
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Determines all embracing, overlapping, and follow up positions
- * for the given region of the document.
- *
- * @param offset the offset of the document region to be formatted
- * @param length the length of the document to be formatted
- * @since 3.0
- */
- private void determinePositionsToUpdate(int offset, int length) {
-
- String[] categories= fDocument.getPositionCategories();
- if (categories != null) {
- for (int i= 0; i < categories.length; i++) {
-
- if (ignoreCategory(categories[i]))
- continue;
-
- try {
-
- Position[] positions= fDocument.getPositions(categories[i]);
-
- for (int j= 0; j < positions.length; j++) {
-
- Position p= positions[j];
- if (p.overlapsWith(offset, length)) {
-
- if (offset < p.getOffset())
- fOverlappingPositionReferences.add(new PositionReference(p, true, categories[i]));
-
- if (p.getOffset() + p.getLength() < offset + length)
- fOverlappingPositionReferences.add(new PositionReference(p, false, categories[i]));
- }
- }
-
- } catch (BadPositionCategoryException x) {
- // can not happen
- }
- }
- }
- }
-
- /**
- * Returns all offset and the end offset of all positions overlapping with the
- * specified document range.
- *
- * @param offset the offset of the document region to be formatted
- * @param length the length of the document to be formatted
- * @return all character positions of the interleaving positions
- * @since 3.0
- */
- private int[] getAffectedPositions(int offset, int length) {
-
- fOverlappingPositionReferences= new ArrayList();
-
- determinePositionsToUpdate(offset, length);
-
- Collections.sort(fOverlappingPositionReferences);
-
- int[] positions= new int[fOverlappingPositionReferences.size()];
- for (int i= 0; i < positions.length; i++) {
- PositionReference r= (PositionReference) fOverlappingPositionReferences.get(i);
- positions[i]= r.getCharacterPosition() - offset;
- }
-
- return positions;
- }
-
- /**
- * Removes the affected positions from their categories to avoid
- * that they are invalidly updated.
- *
- * @param document the document
- */
- private void removeAffectedPositions(IDocument document) {
- int size= fOverlappingPositionReferences.size();
- for (int i= 0; i < size; i++) {
- PositionReference r= (PositionReference) fOverlappingPositionReferences.get(i);
- try {
- document.removePosition(r.getCategory(), r.getPosition());
- } catch (BadPositionCategoryException x) {
- // can not happen
- }
- }
- }
-
- /**
- * Updates all the overlapping positions. Note, all other positions are
- * automatically updated by their document position updaters.
- *
- * @param document the document to has been formatted
- * @param positions the adapted character positions to be used to update the document positions
- * @param offset the offset of the document region that has been formatted
- */
- protected void updateAffectedPositions(IDocument document, int[] positions, int offset) {
-
- if (document != fDocument)
- return;
-
- if (positions.length == 0)
- return;
-
- for (int i= 0; i < positions.length; i++) {
-
- PositionReference r= (PositionReference) fOverlappingPositionReferences.get(i);
-
- if (r.refersToOffset())
- r.setOffset(offset + positions[i]);
- else
- r.setLength((offset + positions[i]) - r.getOffset());
-
- Position p= r.getPosition();
- String category= r.getCategory();
- if (!document.containsPosition(category, p.offset, p.length)) {
- try {
- if (positionAboutToBeAdded(document, category, p))
- document.addPosition(r.getCategory(), p);
- } catch (BadPositionCategoryException x) {
- // can not happen
- } catch (BadLocationException x) {
- // should not happen
- }
- }
-
- }
-
- fOverlappingPositionReferences= null;
- }
-
- /**
- * The given position is about to be added to the given position category of the given document. <p>
- * This default implementation return <code>true</code>.
- *
- * @param document the document
- * @param category the position category
- * @param position the position that will be added
- * @return <code>true</code> if the position can be added, <code>false</code> if it should be ignored
- */
- protected boolean positionAboutToBeAdded(IDocument document, String category, Position position) {
- return true;
- }
-
- /**
- * Returns the indentation of the line of the given offset.
- *
- * @param offset the offset
- * @return the indentation of the line of the offset
- */
- private String getIndentation(int offset) {
-
- try {
- int start= fDocument.getLineOfOffset(offset);
- start= fDocument.getLineOffset(start);
-
- int end= start;
- char c= fDocument.getChar(end);
- while ('\t' == c || ' ' == c)
- c= fDocument.getChar(++end);
-
- return fDocument.get(start, end - start);
- } catch (BadLocationException x) {
- }
-
- return ""; //$NON-NLS-1$
- }
-
- /**
- * Determines whether the offset is the beginning of a line in the given document.
- *
- * @param offset the offset
- * @return <code>true</code> if offset is the beginning of a line
- * @exception BadLocationException if offset is invalid in document
- * @since 3.0
- */
- private boolean isLineStart(int offset) throws BadLocationException {
- int start= fDocument.getLineOfOffset(offset);
- start= fDocument.getLineOffset(start);
- return (start == offset);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContextBasedFormattingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContextBasedFormattingStrategy.java
deleted file mode 100644
index 44942268b52..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/ContextBasedFormattingStrategy.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-import java.util.LinkedList;
-import java.util.Map;
-
-/**
- * Formatting strategy for context based content formatting.
- * <p>
- *
- * @since 3.0
- */
-public abstract class ContextBasedFormattingStrategy implements IFormattingStrategy, IFormattingStrategyExtension {
-
- /** The current preferences for formatting */
- private Map fCurrentPreferences= null;
-
- /** The list of preferences for initiated the formatting steps */
- private final LinkedList fPreferences= new LinkedList();
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#format()
- */
- public void format() {
- fCurrentPreferences= (Map)fPreferences.removeFirst();
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingStrategy#format(java.lang.String, boolean, java.lang.String, int[])
- */
- public String format(String content, boolean start, String indentation, int[] positions) {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStarts(org.eclipse.jface.text.formatter.IFormattingContext)
- */
- public void formatterStarts(final IFormattingContext context) {
- fPreferences.addLast(context.getProperty(FormattingContextProperties.CONTEXT_PREFERENCES));
- }
-
- /*
- * @see IFormattingStrategy#formatterStarts(String)
- */
- public void formatterStarts(final String indentation) {
- // Do nothing
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingStrategyExtension#formatterStops()
- */
- public void formatterStops() {
- fPreferences.clear();
-
- fCurrentPreferences= null;
- }
-
- /**
- * Returns the preferences used for the current formatting step.
- *
- * @return The preferences for the current formatting step
- */
- public final Map getPreferences() {
- return fCurrentPreferences;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContext.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContext.java
deleted file mode 100644
index 981c65bab72..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContext.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-
-/**
- * Default implementation of <code>IFormattingContext</code>.
- *
- * @since 3.0
- */
-public class FormattingContext implements IFormattingContext {
-
- /** Map to store the properties */
- private final Map fMap= new HashMap();
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#dispose()
- */
- public void dispose() {
- fMap.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#getPreferenceKeys()
- */
- public String[] getPreferenceKeys() {
- return new String[] {
- };
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#getProperty(java.lang.Object)
- */
- public Object getProperty(Object key) {
- return fMap.get(key);
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isBooleanPreference(java.lang.String)
- */
- public boolean isBooleanPreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isDoublePreference(java.lang.String)
- */
- public boolean isDoublePreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isFloatPreference(java.lang.String)
- */
- public boolean isFloatPreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isIntegerPreference(java.lang.String)
- */
- public boolean isIntegerPreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isLongPreference(java.lang.String)
- */
- public boolean isLongPreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#isStringPreference(java.lang.String)
- */
- public boolean isStringPreference(String key) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#mapToStore(java.util.Map, org.eclipse.jface.preference.IPreferenceStore)
- */
- public void mapToStore(Map map, IPreferenceStore store) {
-
- final String[] preferences= getPreferenceKeys();
-
- String result= null;
- String preference= null;
-
- for (int index= 0; index < preferences.length; index++) {
-
- preference= preferences[index];
- result= (String)map.get(preference);
-
- if (result != null) {
-
- try {
- if (isBooleanPreference(preference)) {
- store.setValue(preference, result.equals(IPreferenceStore.TRUE));
- } else if (isIntegerPreference(preference)) {
- store.setValue(preference, Integer.parseInt(result));
- } else if (isStringPreference(preference)) {
- store.setValue(preference, result);
- } else if (isDoublePreference(preference)) {
- store.setValue(preference, Double.parseDouble(result));
- } else if (isFloatPreference(preference)) {
- store.setValue(preference, Float.parseFloat(result));
- } else if (isLongPreference(preference)) {
- store.setValue(preference, Long.parseLong(result));
- }
- } catch (NumberFormatException exception) {
- // Do nothing
- }
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#setProperty(java.lang.Object, java.lang.Object)
- */
- public void setProperty(Object key, Object property) {
- fMap.put(key, property);
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IFormattingContext#storeToMap(org.eclipse.jface.preference.IPreferenceStore, java.util.Map, boolean)
- */
- public void storeToMap(IPreferenceStore store, Map map, boolean useDefault) {
-
- final String[] preferences= getPreferenceKeys();
-
- String preference= null;
- for (int index= 0; index < preferences.length; index++) {
-
- preference= preferences[index];
-
- if (isBooleanPreference(preference)) {
- map.put(preference, (useDefault ? store.getDefaultBoolean(preference) : store.getBoolean(preference)) ? IPreferenceStore.TRUE : IPreferenceStore.FALSE);
- } else if (isIntegerPreference(preference)) {
- map.put(preference, String.valueOf(useDefault ? store.getDefaultInt(preference) : store.getInt(preference)));
- } else if (isStringPreference(preference)) {
- map.put(preference, useDefault ? store.getDefaultString(preference) : store.getString(preference));
- } else if (isDoublePreference(preference)) {
- map.put(preference, String.valueOf(useDefault ? store.getDefaultDouble(preference) : store.getDouble(preference)));
- } else if (isFloatPreference(preference)) {
- map.put(preference, String.valueOf(useDefault ? store.getDefaultFloat(preference) : store.getFloat(preference)));
- } else if (isLongPreference(preference)) {
- map.put(preference, String.valueOf(useDefault ? store.getDefaultLong(preference) : store.getLong(preference)));
- }
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContextProperties.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContextProperties.java
deleted file mode 100644
index b8b569a14bb..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/FormattingContextProperties.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-/**
- * Keys used by <code>IFormattingContext</code> objects to register specific
- * properties needed during the formatting process of a content formatter
- * implementing <code>IContentFormatterExtension</code>.
- *
- * @see IFormattingContext
- * @see IFormattingStrategyExtension
- * @see IContentFormatterExtension
- * @since 3.0
- */
-public class FormattingContextProperties {
-
- /**
- * Property key of the document property. The property must implement
- * <code>java.lang#Boolean</code>.
- * <p>
- * Value: <code>"formatting.context.document"</code>
- */
- public static final String CONTEXT_DOCUMENT= "formatting.context.document"; //$NON-NLS-1$
-
- /**
- * Property key of the partition property. The property must implement
- * <code>org.eclipse.jface.text#TypedPosition</code>.
- * <p>
- * Value: <code>"formatting.context.partition"</code>
- */
- public static final String CONTEXT_PARTITION= "formatting.context.partition"; //$NON-NLS-1$
-
- /**
- * Property key of the preferences property. The property must implement
- * <code>java.util#Map</code>.
- * <p>
- * Value: <code>"formatting.context.preferences"</code>
- */
- public static final String CONTEXT_PREFERENCES= "formatting.context.preferences"; //$NON-NLS-1$
-
- /**
- * Property key of the region property. The property must implement <code>org.eclipse.jface.text#IRegion</code>.
- * <p>
- * Value: <code>"formatting.context.region"</code>
- */
- public static final String CONTEXT_REGION= "formatting.context.region"; //$NON-NLS-1$
-
- /**
- * Property key of the medium property. The property must implement <code>org.eclipse.jface.text#IDocument</code>.
- * <p>
- * Value: <code>"formatting.context.medium"</code>
- */
- public static final String CONTEXT_MEDIUM= "formatting.context.medium"; //$NON-NLS-1$
-
- /**
- * Ensure that this class cannot be instantiated.
- */
- private FormattingContextProperties() {
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java
deleted file mode 100644
index d8d2cb08536..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.formatter;
-
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-
-
-/**
- * The interface of a document content formatter. The formatter formats ranges
- * within documents. The documents are modified by the formatter.<p>
- * The content formatter is assumed to determine the partitioning of the document
- * range to be formatted. For each partition, the formatter determines based
- * on the partition's content type the formatting strategy to be used. Before
- * the first strategy is activated all strategies are informed about the
- * start of the formatting process. After that, the formatting strategies are
- * activated in the sequence defined by the partitioning of the document range to be
- * formatted. It is assumed that a strategy must be finished before the next strategy
- * can be activated. After the last strategy has been finished, all strategies are
- * informed about the termination of the formatting process.<p>
- * The interface can be implemented by clients. By default, clients use <code>ContentFormatter</code>
- * as the standard implementer of this interface.
- *
- * @see IDocument
- * @see IFormattingStrategy
- */
-public interface IContentFormatter {
-
- /**
- * Formats the given region of the specified document.The formatter may safely
- * assume that it is the only subject that modifies the document at this point in time.
- *
- * @param document the document to be formatted
- * @param region the region within the document to be formatted
- */
- void format(IDocument document, IRegion region);
-
- /**
- * Returns the formatting strategy registered for the given content type.
- *
- * @param contentType the content type for which to look up the formatting strategy
- * @return the formatting strategy for the given content type, or
- * <code>null</code> if there is no such strategy
- */
- IFormattingStrategy getFormattingStrategy(String contentType);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatterExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatterExtension.java
deleted file mode 100644
index 2b851d162ec..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IContentFormatterExtension.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-import org.eclipse.jface.text.IDocument;
-
-/**
- * Extension interface for <code>IContentFormatter</code>.
- * <p>
- * Updates the content formatter to be able to pass <code>IFormattingContext</code>
- * context objects to <code>IFormattingStrategyExtension<code> objects
- * operating in context based mode.
- * <p>
- * Clients using context based formatting call the method
- * <code>format(IDocument, IFormattingContext)</code> with a properly
- * initialized formatting context.<br>
- * The formatting context must be set up according to the desired formatting mode:
- * <ul>
- * <li>For whole document formatting set the property <code>CONTEXT_DOCUMENT</code>. This is
- * equivalent to setting <code>CONTEXT_REGION</code> with a region spanning the whole document.</li>
- * <li>For multiple region formatting set the property <code>CONTEXT_REGION</code>. Note that
- * the content formatter automatically aligns the region to a block selected region, and if the region spans
- * multiple partitions, it also completes eventual partitions covered only partially by the region.</li>
- * </ul>
- * Depending on the registered formatting strategies, more context information must
- * be passed in the formatting context, like e.g. <code>CONTEXT_PREFERENCES</code>.
- * <p>
- * Note that in context based mode the content formatter is fully reentrant, but not
- * thread-safe.
- * <p>
- *
- * @see IFormattingContext
- * @see FormattingContextProperties
- * @since 3.0
- */
-public interface IContentFormatterExtension {
-
- /**
- * Formats the given region of the specified document.
- * <p>
- * The formatter may safely assume that it is the only subject that
- * modifies the document at this point in time. This method is fully
- * reentrant, but not thread-safe.
- * <p>
- * The formatting process performed by <code>format(IDocument, IFormattingContext)</code>
- * happens as follows:
- * <ul>
- * <li>In a first pass the content formatter formats the range of the
- * document to be formatted by using the master formatting strategy. This
- * happens regardless of the content type of the underlying partition.
- * </li>
- * <li>In the second pass, the range is formatted again, this time using
- * the registered slave formatting strategies. For each partition contained
- * in the range to be formatted, the content formatter determines its
- * content type and formats the partition with the correct formatting
- * strategy.
- * </li>
- *
- * @param document
- * The document to be formatted
- * @param context
- * The formatting context to pass to the formatting strategies.
- * This argument must not be <code>null</code>.
- */
- void format(IDocument document, IFormattingContext context);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingContext.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingContext.java
deleted file mode 100644
index 5dfad9a878c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingContext.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-import java.util.Map;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-
-/**
- * Formatting context used in formatting strategies implementing interface
- * <code>IFormattingStrategyExtension</code>.
- *
- * @see IFormattingStrategyExtension
- * @since 3.0
- */
-public interface IFormattingContext {
-
- /**
- * Dispose of the formatting context.
- * <p>
- * Must be called after the formatting context has been used in a
- * formatting process.
- */
- void dispose();
-
- /**
- * Returns the preference keys used for the retrieval of formatting
- * preferences.
- *
- * @return The preference keys for formatting
- */
- String[] getPreferenceKeys();
-
- /**
- * Retrieves the property <code>key</code> from the formatting context
- *
- * @param key
- * Key of the property to store in the context
- * @return The property <code>key</code> if available, <code>null</code>
- * otherwise
- */
- Object getProperty(Object key);
-
- /**
- * Is this preference key for a boolean preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for a boolean preference,
- * <code>false</code> otherwise.
- */
- boolean isBooleanPreference(String key);
-
- /**
- * Is this preference key for a double preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for a double preference,
- * <code>false</code> otherwise.
- */
- boolean isDoublePreference(String key);
-
- /**
- * Is this preference key for a float preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for a float preference,
- * <code>false</code> otherwise.
- */
- boolean isFloatPreference(String key);
-
- /**
- * Is this preference key for an integer preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for an integer preference,
- * <code>false</code> otherwise.
- */
- boolean isIntegerPreference(String key);
-
- /**
- * Is this preference key for a long preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for a long preference,
- * <code>false</code> otherwise.
- */
- boolean isLongPreference(String key);
-
- /**
- * Is this preference key for a string preference?
- *
- * @param key
- * The preference key to query its type
- * @return <code>true</code> iff this key is for a string preference,
- * <code>false</code> otherwise.
- */
- boolean isStringPreference(String key);
-
- /**
- * Stores the preferences from a map to a preference store.
- * <p>
- * Note that the preference keys returned by
- * {@link #getPreferenceKeys()} must not be used in the preference store.
- * Otherwise the preferences are overwritten.
- * </p>
- *
- * @param map
- * Map to retrieve the preferences from
- * @param store
- * Preference store to store the preferences in
- */
- void mapToStore(Map map, IPreferenceStore store);
-
- /**
- * Stores the property <code>key</code> in the formatting context.
- *
- * @param key
- * Key of the property to store in the context
- * @param property
- * Property to store in the context. If already present, the new
- * property overwrites the present one.
- */
- void setProperty(Object key, Object property);
-
- /**
- * Retrieves the preferences from a preference store in a map.
- * <p>
- * Note that the preference keys returned by
- * {@link #getPreferenceKeys()} must not be used in the map. Otherwise the
- * preferences are overwritten.
- * </p>
- *
- * @param store
- * Preference store to retrieve the preferences from
- * @param map
- * Map to store the preferences in
- * @param useDefault
- * <code>true</code> if the default preferences should be
- * used, <code>false</code> otherwise
- */
- void storeToMap(IPreferenceStore store, Map map, boolean useDefault);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java
deleted file mode 100644
index b35b14d317c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategy.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-
-/**
- * A formatting strategy is assumed to be specialized on formatting text
- * of a particular content type. Each formatting process calls the strategy's
- * methods in the following sequence:
- * <ul>
- * <li><code>formatterStarts</code>
- * <li><code>format</code>
- * <li><code>formatterStops</code>
- * </ul>
- * This interface must be implemented by clients. Implementers should be registered with
- * a content formatter in order get involved in the formatting process.
- */
-public interface IFormattingStrategy {
-
- /**
- * Informs the strategy about the start of a formatting process in which it will
- * participate.
- *
- * @param initialIndentation the indent string of the first line at which the
- * overall formatting process starts.
- */
- void formatterStarts(String initialIndentation);
-
- /**
- * Formats the given string. During the formatting process this strategy must update
- * the given character positions according to the changes applied to the given string.
- *
- * @param content the initial string to be formatted
- * @param isLineStart indicates whether the beginning of content is a line start in its document
- * @param indentation the indentation string to be used
- * @param positions the character positions to be updated
- * @return the formatted string
- */
- String format(String content, boolean isLineStart, String indentation, int[] positions);
-
- /**
- * Informs the strategy that the formatting process in which it has participated
- * has been finished.
- */
- void formatterStops();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategyExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategyExtension.java
deleted file mode 100644
index cc31618b7fe..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/IFormattingStrategyExtension.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-/**
- * Extension interface for <code>IFormattingStrategy</code>.
- * <p>
- * Updates formatting strategies to be able to receive a more general <code>IFormattingContext</code>
- * object from its associated content formatters.
- * <p>
- * Each formatting process calls the strategy's methods in the following
- * sequence:
- * <ul>
- * <li><code>formatterStarts</code>
- * <li><code>format</code>
- * <li><code>formatterStops</code>
- * </ul>
- * <p>
- * Note that multiple calls to <code>formatterStarts</code> can be issued to
- * a strategy before launching the formatting process with <code>format</code>.
- * <p>
- * This interface must be implemented by clients. Implementers should be
- * registered with a content formatter in order get involved in the formatting
- * process.
- *
- * @see IFormattingContext
- * @since 3.0
- */
-public interface IFormattingStrategyExtension {
-
- /**
- * Formats the region with the properties indicated in the formatting
- * context previously supplied by <code>formatterStarts(IFormattingContext)</code>.
- */
- void format();
-
- /**
- * Informs the strategy about the start of a formatting process in which it
- * will participate.
- *
- * @param context
- * Formatting context used in the corresponding formatting
- * process.
- */
- void formatterStarts(IFormattingContext context);
-
- /**
- * Informs the strategy that the formatting process in which it has
- * participated has been finished.
- */
- void formatterStops();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java
deleted file mode 100644
index fc577438a84..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/MultiPassContentFormatter.java
+++ /dev/null
@@ -1,314 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.formatter;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.TypedPosition;
-
-/**
- * Content formatter for edit-based formatting strategies.
- * <p>
- * Two kinds of formatting strategies can be registered with this formatter:
- * <ul>
- * <li>Master formatting strategies</li>
- * <li>Slave formatting strategies</li>
- * </ul>
- * The master formatting strategy always formats the whole region to be
- * formatted in the first pass. In a second pass, all partitions of the region
- * to be formatted that are not of master content type are formatted using the
- * slave formatting strategy registered for the underlying content type.
- * <p>
- * Regions to be formatted with the master formatting strategy are always
- * aligned to block selections. Regions to be formatted with slave formatting
- * strategies are aligned on partition boundaries.
- *
- * @since 3.0
- */
-public class MultiPassContentFormatter implements IContentFormatter, IContentFormatterExtension {
-
- /**
- * Position updater that shifts otherwise deleted positions to the next
- * non-whitespace character. The length of the positions are truncated to
- * one if the position was shifted.
- */
- protected class NonDeletingPositionUpdater extends DefaultPositionUpdater {
-
- /**
- * Creates a new non-deleting position updater.
- *
- * @param category The position category to update its positions
- */
- public NonDeletingPositionUpdater(final String category) {
- super(category);
- }
-
- /*
- * @see org.eclipse.jface.text.DefaultPositionUpdater#notDeleted()
- */
- protected final boolean notDeleted() {
-
- if (fOffset < fPosition.offset && (fPosition.offset + fPosition.length < fOffset + fLength)) {
-
- int offset= fOffset + fLength;
- if (offset < fDocument.getLength()) {
-
- try {
-
- boolean moved= false;
- char character= fDocument.getChar(offset);
-
- while (offset < fDocument.getLength() && Character.isWhitespace(character)) {
-
- moved= true;
- character= fDocument.getChar(offset++);
- }
-
- if (moved)
- offset--;
-
- } catch (BadLocationException exception) {
- // Can not happen
- }
-
- fPosition.offset= offset;
- fPosition.length= 0;
- }
- }
- return true;
- }
- }
-
- /** The master formatting strategy */
- private IFormattingStrategyExtension fMaster= null;
- /** The partitioning of this content formatter */
- private final String fPartitioning;
- /** The slave formatting strategies */
- private final Map fSlaves= new HashMap();
- /** The default content type */
- private final String fType;
-
- /**
- * Creates a new content formatter.
- *
- * @param partitioning the document partitioning for this formatter
- * @param type the default content type
- */
- public MultiPassContentFormatter(final String partitioning, final String type) {
- fPartitioning= partitioning;
- fType= type;
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IContentFormatterExtension#format(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.formatter.IFormattingContext)
- */
- public final void format(final IDocument medium, final IFormattingContext context) {
-
- context.setProperty(FormattingContextProperties.CONTEXT_MEDIUM, medium);
-
- final Boolean document= (Boolean)context.getProperty(FormattingContextProperties.CONTEXT_DOCUMENT);
- if (document == null || !document.booleanValue()) {
-
- final IRegion region= (IRegion)context.getProperty(FormattingContextProperties.CONTEXT_REGION);
- if (region != null) {
- try {
- formatMaster(context, medium, region.getOffset(), region.getLength());
- } finally {
- formatSlaves(context, medium, region.getOffset(), region.getLength());
- }
- }
- } else {
- try {
- formatMaster(context, medium, 0, medium.getLength());
- } finally {
- formatSlaves(context, medium, 0, medium.getLength());
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IContentFormatter#format(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IRegion)
- */
- public final void format(final IDocument medium, final IRegion region) {
-
- final FormattingContext context= new FormattingContext();
-
- context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
- context.setProperty(FormattingContextProperties.CONTEXT_REGION, region);
-
- format(medium, context);
- }
-
- /**
- * Formats the document specified in the formatting context with the master
- * formatting strategy.
- * <p>
- * The master formatting strategy covers all regions of the document. The
- * offset of the region to be formatted is aligned on line start boundaries,
- * whereas the end index of the region remains the same. For this formatting
- * type the document partitioning is not taken into account.
- *
- * @param context The formatting context to use
- * @param document The document to operate on
- * @param offset The offset of the region to format
- * @param length The length of the region to format
- */
- protected void formatMaster(final IFormattingContext context, final IDocument document, int offset, int length) {
-
- try {
-
- final int delta= offset - document.getLineInformationOfOffset(offset).getOffset();
- offset -= delta;
- length += delta;
-
- } catch (BadLocationException exception) {
- // Do nothing
- }
-
- if (fMaster != null) {
-
- context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, fType));
-
- fMaster.formatterStarts(context);
- fMaster.format();
- fMaster.formatterStops();
- }
- }
-
- /**
- * Formats the document specified in the formatting context with the
- * formatting strategy registered for the content type.
- * <p>
- * For this formatting type only slave strategies are used. The region to be
- * formatted is aligned on partition boundaries of the underlying content
- * type. The exact formatting strategy is determined by the underlying
- * content type of the document partitioning.
- *
- * @param context The formatting context to use
- * @param document The document to operate on
- * @param offset The offset of the region to format
- * @param length The length of the region to format
- * @param type The content type of the region to format
- */
- protected void formatSlave(final IFormattingContext context, final IDocument document, final int offset, final int length, final String type) {
-
- final IFormattingStrategyExtension strategy= (IFormattingStrategyExtension)fSlaves.get(type);
- if (strategy != null) {
-
- context.setProperty(FormattingContextProperties.CONTEXT_PARTITION, new TypedPosition(offset, length, type));
-
- strategy.formatterStarts(context);
- strategy.format();
- strategy.formatterStops();
- }
- }
-
- /**
- * Formats the document specified in the formatting context with the slave
- * formatting strategies.
- * <p>
- * For each content type of the region to be formatted in the document
- * partitioning, the registered slave formatting strategy is used to format
- * that particular region. The region to be formatted is aligned on
- * partition boundaries of the underlying content type. If the content type
- * is the document's default content type, nothing happens.
- *
- * @param context The formatting context to use
- * @param document The document to operate on
- * @param offset The offset of the region to format
- * @param length The length of the region to format
- */
- protected void formatSlaves(final IFormattingContext context, final IDocument document, final int offset, final int length) {
-
- Map partitioners= new HashMap(0);
- try {
-
- final ITypedRegion[] partitions= TextUtilities.computePartitioning(document, fPartitioning, offset, length, false);
-
- if (!fType.equals(partitions[0].getType()))
- partitions[0]= TextUtilities.getPartition(document, fPartitioning, partitions[0].getOffset(), false);
-
- if (partitions.length > 1) {
-
- if (!fType.equals(partitions[partitions.length - 1].getType()))
- partitions[partitions.length - 1]= TextUtilities.getPartition(document, fPartitioning, partitions[partitions.length - 1].getOffset(), false);
- }
-
- String type= null;
- ITypedRegion partition= null;
-
- partitioners= TextUtilities.removeDocumentPartitioners(document);
-
- for (int index= partitions.length - 1; index >= 0; index--) {
-
- partition= partitions[index];
- type= partition.getType();
-
- if (!fType.equals(type))
- formatSlave(context, document, partition.getOffset(), partition.getLength(), type);
- }
-
- } catch (BadLocationException exception) {
- // Should not happen
- } finally {
- TextUtilities.addDocumentPartitioners(document, partitioners);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.formatter.IContentFormatter#getFormattingStrategy(java.lang.String)
- */
- public final IFormattingStrategy getFormattingStrategy(final String type) {
- return null;
- }
-
- /**
- * Registers a master formatting strategy.
- * <p>
- * The strategy may already be registered with a certain content type as
- * slave strategy. The master strategy is registered for the default content
- * type of documents. If a master strategy has already been registered, it
- * is overridden by the new one.
- *
- * @param strategy The master formatting strategy
- */
- public final void setMasterStrategy(final IFormattingStrategy strategy) {
- Assert.isTrue(strategy instanceof IFormattingStrategyExtension);
- fMaster= (IFormattingStrategyExtension) strategy;
- }
-
- /**
- * Registers a slave formatting strategy for a certain content type.
- * <p>
- * The strategy may already be registered as master strategy. If it is
- * already registered as slave strategy for the specified content type,
- * nothing happens. However, the same strategy may be registered with
- * several content types. Slave strategies cannot be registered for the
- * default content type of documents.
- *
- * @param strategy The slave formatting strategy
- * @param type The content type to register this strategy with
- */
- public final void setSlaveStrategy(final IFormattingStrategy strategy, final String type) {
- Assert.isTrue(strategy instanceof IFormattingStrategyExtension);
- if (!fType.equals(type))
- fSlaves.put(type, strategy);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/package.html
deleted file mode 100644
index 938929c7edd..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/formatter/package.html
+++ /dev/null
@@ -1,57 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a content formatter add-on for an <tt>ITextViewer</tt>.
-A content formatter changes the formatting of a document region while
-preserving and correctly updating the positions of the document.
-<h2>
-Package Specification</h2>
-<tt>IContentFormatter</tt> defines the concept of a text formatter. It
-collaborates with content type specific formatting stratgies (<tt>IFormattingStrategy</tt>)
-which for a given document region format the subregion with the matching
-content type. The package contains a default implementation of <tt>IContentFormatter</tt>
-(<tt>ContentFormatter</tt>).<br>Additionally, an implementation of <tt>IContentFormatter</tt> is provided
-for text edit based formatting strategies. This implementation only accepts formatting strategies
-implementing the extension interface <tt>IFormattingStrategyExtension</tt>. These formatting strategies are required to
-handle the position updating of the document. To facilitate the work with these text edit based formatting strategies, a default implementation called <tt>ContextBasedFormattingStrategy</tt>
-is provided. Formatting strategies inheriting from this class are text edit based and behave context dependent. Depending on the formatting context that is passed
-to the content formatter, different preferences and modes can be used to format different parts of a document.
-<p>
-To set up a proper working text edit based content formatter, the following steps are needed:
-<ul>
-<li>Create an instance of <tt>IFormattingContext</tt>. The default implementation <tt>FormattingContext</tt> already
-provides support for the conversion of preferences from a preference store to a map and vice versa. The method <tt>getPreferenceKeys</tt>
-usually has to be overridden to return the appropriate keys of the preferences used during the formatting process. Then register a map of preferences
-with the formatting context by calling <tt>setProperty(String, Object)</tt> with the property identifier <tt>FormattingContextProperties.CONTEXT_PREFERENCES</tt>.</li>
-<li>Create an instance of the text edit based content formatter class <tt>MultiPassContentFormatter</tt>. The document partitioning and its associated
-default content type have to be passed to the constructor. This information is needed since the content formatter is able to format documents
-according to arbitrary partitionings and default content types.</li>
-<li>Register the formatting strategies for the content types that have to be formatted. If a formatting strategy is
-registered as master strategy, it is automatically associated with the default content type of the specified partitioning.
-If the formatting strategy is registered as slave strategy, it is associated with the indicated content type during the registration.
-Note that the master strategy can also be registered as a slave strategy for a content type other than the default content type.</li>
-<li>Specify the proper formatting mode:
-<ul>
-<li>For whole document formatting set the property <tt>CONTEXT_DOCUMENT</tt> of the created formatting context to <tt>true</tt>. This is
-equivalent to setting <code>CONTEXT_REGION</code> with a region spanning the whole document.</li>
-<li>For multiple region formatting set the property <code>CONTEXT_REGION</code> of the formatting context. Note that
-the content formatter automatically aligns the region to a block selected region, and if the region spans
-multiple partitions, it also completes eventual partitions covered only partially by the region.</li>
-<li>For explicit formatting of a partition with the formatting strategy registered for a certain content type use the
-property <tt>CONTEXT_PARTITION</tt>. Note that the region denoted by this property must correspond to a partition relative
-to the specified partitioning in the document to be formatted. The content type of this property overrides the content type of the partition
-in the document.</li>
-</ul>
-</li>
-<li>Call the method <tt>MultiPassContentFormatter#format(IDocument, IFormattingContext)</tt> with the created formatting context
-and the document to be formatted.</li>
-</ul>
-</p>
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java
deleted file mode 100644
index f43adf0d7a2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenter.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.information;
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * An information presenter shows information available at the text viewer's
- * current document position. An <code>IInformationPresenter</code> is a
- * <code>ITextViewer</code> add-on.<p>
- * An information presenters has a list of <code>IInformationProvider</code> objects
- * each of which is registered for a particular document content type.
- * The presenter uses the strategy objects to retrieve the information to present.<p>
- * The interface can be implemented by clients. By default, clients use
- * <code>InformationPresenter</code> as the standard implementer of this interface.
- *
- * @see ITextViewer
- * @see IInformationProvider
- * @since 2.0
- */
-public interface IInformationPresenter {
-
- /**
- * Installs the information presenter on the given text viewer. After this method has been
- * finished, the presenter is operational. I.e., the method <code>showInformation</code>
- * can be called until <code>uninstall</code> is called.
- *
- * @param textViewer the viewer on which the presenter is installed
- */
- void install(ITextViewer textViewer);
-
- /**
- * Removes the information presenter from the text viewer it has previously been
- * installed on.
- */
- void uninstall();
-
- /**
- * Shows information related to the cursor position of the text viewer
- * this information presenter is installed on.
- */
- void showInformation();
-
- /**
- * Returns the information provider to be used for the given content type.
- *
- * @param contentType the type of the content for which information will be requested
- * @return an information provider or
- * <code>null</code> if none exists for the specified content type
- */
- IInformationProvider getInformationProvider(String contentType);
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenterExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenterExtension.java
deleted file mode 100644
index 806202a845f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationPresenterExtension.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.information;
-
-/**
- * Extension interface for <code>IInformationPresenter</code>.
- * Updates the information presenter to be aware of documents with multiple partitions.
- *
- * @since 3.0
- */
-public interface IInformationPresenterExtension {
-
- /**
- * Returns the document partitioning this information presenter is using.
- *
- * @return the document partitioning this information presenter is using
- */
- String getDocumentPartitioning();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java
deleted file mode 100644
index 98c7c4c5dea..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProvider.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.information;
-
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * Provides information related to the content of a text viewer.<p>
- * Clients may implement this interface.
- *
- * @see ITextViewer
- * @since 2.0
- */
-public interface IInformationProvider {
-
- /**
- * Returns the region of the text viewer's document close to the given
- * offset that contains a subject about which information can be provided.<p>
- * For example, if information can be provided on a per code block basis,
- * the offset should be used to find the enclosing code block and the source
- * range of the block should be returned.
- *
- * @param textViewer the text viewer in which informationhas been requested
- * @param offset the offset at which information has been requested
- * @return the region of the text viewer's document containing the information subject
- */
- IRegion getSubject(ITextViewer textViewer, int offset);
-
- /**
- * Returns the information about the given subject or <code>null</code> if
- * no information is available. It depends on the concrete configuration in which
- * format the information is to be provided. For example, information presented
- * in an information control displaying HTML, should be provided in HTML.
- *
- * @param textViewer the viewer in whose document the subject is contained
- * @param subject the text region constituting the information subject
- * @return the information about the subject
- * @see IInformationPresenter
- * @deprecated As of 2.1, replaced by {@link IInformationProviderExtension#getInformation2(ITextViewer, IRegion)}
- */
- String getInformation(ITextViewer textViewer, IRegion subject);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension.java
deleted file mode 100644
index d9432766f63..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.information;
-
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * Extension interface for <code>IInformationProvider</code> to provide
- * the element for a given subject.
- *
- * @see org.eclipse.jface.text.information.IInformationProvider
- * @since 2.1
- */
-public interface IInformationProviderExtension {
-
- /**
- * Returns the element for the given subject or <code>null</code> if
- * no element is available.
- * <p>
- * Implementers should ignore the text returned by <code>IInformationProvider.getInformation()</code>.
- * </p>
- *
- * @param textViewer the viewer in whose document the subject is contained
- * @param subject the text region constituting the information subject
- * @return the element for the subject
- *
- * @see IInformationProvider#getInformation(ITextViewer, IRegion)
- * @see org.eclipse.jface.text.ITextViewer
- */
- Object getInformation2(ITextViewer textViewer, IRegion subject);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension2.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension2.java
deleted file mode 100644
index 028891e4198..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/IInformationProviderExtension2.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.information;
-
-import org.eclipse.jface.text.IInformationControlCreator;
-
-/**
- * Extension interface for <code>IInformationProvider</code> to provide
- * its own information control creator.
- *
- * @see org.eclipse.jface.text.IInformationControlCreator
- * @see org.eclipse.jface.text.information.IInformationProvider
- * @since 3.0
- */
-public interface IInformationProviderExtension2 {
-
- /**
- * Returns the information control creator of this information provider.
- *
- * @return the information control creator
- */
- IInformationControlCreator getInformationPresenterControlCreator();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
deleted file mode 100644
index c4469df449c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/InformationPresenter.java
+++ /dev/null
@@ -1,494 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.information;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.FocusEvent;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.AbstractInformationControlManager;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.IWidgetTokenKeeper;
-import org.eclipse.jface.text.IWidgetTokenKeeperExtension;
-import org.eclipse.jface.text.IWidgetTokenOwner;
-import org.eclipse.jface.text.IWidgetTokenOwnerExtension;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextUtilities;
-
-
-/**
- * Standard implementation of <code>IInformationPresenter</code>.
- * This implementation extends <code>AbstractInformationControlManager</code>.
- * The information control is made visible on request by calling
- * <code>showInformation</code>.<p>
- * Usually, clients instantiate this class and configure it before using it. The configuration
- * must be consistent: This means the used <code>IInformationControlCreator</code>
- * must create an information control expecting information in the same format the configured
- * <code>IInformationProvider</code>s use to encode the information they provide.
- *
- * @since 2.0
- */
-public class InformationPresenter extends AbstractInformationControlManager implements IInformationPresenter, IInformationPresenterExtension, IWidgetTokenKeeper, IWidgetTokenKeeperExtension {
-
-
- /**
- * Priority of the info controls managed by this information presenter.
- * Default value: <code>5</code> in order to beat the hovers of <code>TextViewerHoverManager</code>
- * @since 3.0
- */
- public static final int WIDGET_PRIORITY= 5;
-
-
- /**
- * Internal information control closer. Listens to several events issued by its subject control
- * and closes the information control when necessary.
- */
- class Closer implements IInformationControlCloser, ControlListener, MouseListener, FocusListener, IViewportListener, KeyListener {
-
- /** The subject control */
- private Control fSubjectControl;
- /** The information control */
- private IInformationControl fInformationControl;
- /** Indicates whether this closer is active */
- private boolean fIsActive= false;
-
- /*
- * @see IInformationControlCloser#setSubjectControl(Control)
- */
- public void setSubjectControl(Control control) {
- fSubjectControl= control;
- }
-
- /*
- * @see IInformationControlCloser#setInformationControl(IInformationControl)
- */
- public void setInformationControl(IInformationControl control) {
- fInformationControl= control;
- }
-
- /*
- * @see IInformationControlCloser#start(Rectangle)
- */
- public void start(Rectangle informationArea) {
-
- if (fIsActive)
- return;
- fIsActive= true;
-
- if (fSubjectControl != null && ! fSubjectControl.isDisposed()) {
- fSubjectControl.addControlListener(this);
- fSubjectControl.addMouseListener(this);
- fSubjectControl.addFocusListener(this);
- fSubjectControl.addKeyListener(this);
- }
-
- if (fInformationControl != null)
- fInformationControl.addFocusListener(this);
-
- fTextViewer.addViewportListener(this);
- }
-
- /*
- * @see IInformationControlCloser#stop()
- */
- public void stop() {
-
- if (!fIsActive)
- return;
- fIsActive= false;
-
- fTextViewer.removeViewportListener(this);
-
- if (fInformationControl != null)
- fInformationControl.removeFocusListener(this);
-
- hideInformationControl();
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeControlListener(this);
- fSubjectControl.removeMouseListener(this);
- fSubjectControl.removeFocusListener(this);
- fSubjectControl.removeKeyListener(this);
- }
- }
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent e) {
- stop();
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent e) {
- stop();
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent e) {
- stop();
- }
-
- /*
- * @see MouseListener#mouseUp(MouseEvent)
- */
- public void mouseUp(MouseEvent e) {
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent e) {
- stop();
- }
-
- /*
- * @see FocusListener#focusGained(FocusEvent)
- */
- public void focusGained(FocusEvent e) {
- }
-
- /*
- * @see FocusListener#focusLost(FocusEvent)
- */
- public void focusLost(FocusEvent e) {
- Display d= fSubjectControl.getDisplay();
- d.asyncExec(new Runnable() {
- public void run() {
- if (fInformationControl == null || !fInformationControl.isFocusControl())
- stop();
- }
- });
- }
-
- /*
- * @see IViewportListenerListener#viewportChanged(int)
- */
- public void viewportChanged(int topIndex) {
- stop();
- }
-
- /*
- * @see KeyListener#keyPressed(KeyEvent)
- */
- public void keyPressed(KeyEvent e) {
- stop();
- }
-
- /*
- * @see KeyListener#keyReleased(KeyEvent)
- */
- public void keyReleased(KeyEvent e) {
- }
- }
-
-
- /** The text viewer this information presenter works on */
- private ITextViewer fTextViewer;
- /** The map of <code>IInformationProvider</code> objects */
- private Map fProviders;
- /** The offset to override selection. */
- private int fOffset= -1;
- /**
- * The document partitioning for this information presenter.
- * @since 3.0
- */
- private String fPartitioning;
-
- /**
- * Creates a new information presenter that uses the given information control creator.
- * The presenter is not installed on any text viewer yet. By default, an information
- * control closer is set that closes the information control in the event of key strokes,
- * resizing, moves, focus changes, mouse clicks, and disposal - all of those applied to
- * the information control's parent control. Also, the setup ensures that the information
- * control when made visible will request thel focus. By default, the default document
- * partitioning <code>IDocumentExtension3.DEFAULT_PARTITIONING</code> is used.
- *
- * @param creator the information control creator to be used
- */
- public InformationPresenter(IInformationControlCreator creator) {
- super(creator);
- setCloser(new Closer());
- takesFocusWhenVisible(true);
- fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
- }
-
- /**
- * Sets the document partitioning to be used by this information presenter.
- *
- * @param partitioning the document partitioning to be used by this information presenter
- * @since 3.0
- */
- public void setDocumentPartitioning(String partitioning) {
- Assert.isNotNull(partitioning);
- fPartitioning= partitioning;
- }
-
- /*
- * @see org.eclipse.jface.text.information.IInformationPresenterExtension#getDocumentPartitioning()
- * @since 3.0
- */
- public String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- /**
- * Registers a given information provider for a particular content type.
- * If there is already a provider registered for this type, the new provider
- * is registered instead of the old one.
- *
- * @param provider the information provider to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setInformationProvider(IInformationProvider provider, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fProviders == null)
- fProviders= new HashMap();
-
- if (provider == null)
- fProviders.remove(contentType);
- else
- fProviders.put(contentType, provider);
- }
-
- /*
- * @see IInformationPresenter#getInformationProvider(String)
- */
- public IInformationProvider getInformationProvider(String contentType) {
- if (fProviders == null)
- return null;
-
- return (IInformationProvider) fProviders.get(contentType);
- }
-
- /**
- * Sets a offset to override the selection. Setting the value to <code>-1</code> will disable
- * overriding.
- *
- * @param offset the offset to override selection or <code>-1</code>
- */
- public void setOffset(int offset) {
- fOffset= offset;
- }
-
- /*
- * @see AbstractInformationControlManager#computeInformation()
- */
- protected void computeInformation() {
-
- int offset= fOffset < 0 ? fTextViewer.getSelectedRange().x : fOffset;
- if (offset == -1)
- return;
-
- fOffset= -1;
-
- IInformationProvider provider= null;
- try {
- String contentType= TextUtilities.getContentType(fTextViewer.getDocument(), getDocumentPartitioning(), offset, true);
- provider= getInformationProvider(contentType);
- } catch (BadLocationException x) {
- }
- if (provider == null)
- return;
-
- IRegion subject= provider.getSubject(fTextViewer, offset);
- if (subject == null)
- return;
-
- if (provider instanceof IInformationProviderExtension2)
- setCustomInformationControlCreator(((IInformationProviderExtension2) provider).getInformationPresenterControlCreator());
- else
- setCustomInformationControlCreator(null);
-
- if (provider instanceof IInformationProviderExtension) {
- IInformationProviderExtension extension= (IInformationProviderExtension) provider;
- setInformation(extension.getInformation2(fTextViewer, subject), computeArea(subject));
- } else
- setInformation(provider.getInformation(fTextViewer, subject), computeArea(subject));
- }
-
- /**
- * Determines the graphical area covered by the given text region.
- *
- * @param region the region whose graphical extend must be computed
- * @return the graphical extend of the given region
- */
- private Rectangle computeArea(IRegion region) {
-
- IRegion widgetRegion= modelRange2WidgetRange(region);
- int start= widgetRegion.getOffset();
- int end= widgetRegion.getOffset() + widgetRegion.getLength();
-
- StyledText styledText= fTextViewer.getTextWidget();
- Point upperLeft= styledText.getLocationAtOffset(start);
- Point lowerRight= new Point(upperLeft.x, upperLeft.y);
-
- for (int i= start +1; i < end; i++) {
-
- Point p= styledText.getLocationAtOffset(i);
-
- if (upperLeft.x > p.x)
- upperLeft.x= p.x;
-
- if (upperLeft.y > p.y)
- upperLeft.y= p.y;
-
- if (lowerRight.x < p.x)
- lowerRight.x= p.x;
-
- if (lowerRight.y < p.y)
- lowerRight.y= p.y;
- }
-
- GC gc= new GC(styledText);
- lowerRight.x += gc.getFontMetrics().getAverageCharWidth();
- lowerRight.y += styledText.getLineHeight();
- gc.dispose();
-
- int width= lowerRight.x - upperLeft.x;
- int height= lowerRight.y - upperLeft.y;
- return new Rectangle(upperLeft.x, upperLeft.y, width, height);
- }
-
- /**
- * Translated the given range in the viewer's document into the corresponding
- * range of the viewer's widget.
- *
- * @param region the range in the viewer's document
- * @return the corresponding widget range
- * @since 2.1
- */
- private IRegion modelRange2WidgetRange(IRegion region) {
- if (fTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- return extension.modelRange2WidgetRange(region);
- }
-
- IRegion visibleRegion= fTextViewer.getVisibleRegion();
- int start= region.getOffset() - visibleRegion.getOffset();
- int end= start + region.getLength();
- if (end > visibleRegion.getLength())
- end= visibleRegion.getLength();
-
- return new Region(start, end - start);
- }
-
- /*
- * @see IInformationPresenter#install(ITextViewer)
- */
- public void install(ITextViewer textViewer) {
- fTextViewer= textViewer;
- install(fTextViewer.getTextWidget());
- }
-
- /*
- * @see IInformationPresenter#uninstall()
- */
- public void uninstall() {
- dispose();
- }
-
- /*
- * @see AbstractInformationControlManager#showInformationControl(Rectangle)
- */
- protected void showInformationControl(Rectangle subjectArea) {
- if (fTextViewer instanceof IWidgetTokenOwnerExtension) {
- IWidgetTokenOwnerExtension extension= (IWidgetTokenOwnerExtension) fTextViewer;
- if (extension.requestWidgetToken(this, WIDGET_PRIORITY))
- super.showInformationControl(subjectArea);
- } else if (fTextViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fTextViewer;
- if (owner.requestWidgetToken(this))
- super.showInformationControl(subjectArea);
-
- }
- }
-
- /*
- * @see AbstractInformationControlManager#hideInformationControl()
- */
- protected void hideInformationControl() {
- try {
- super.hideInformationControl();
- } finally {
- if (fTextViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fTextViewer;
- owner.releaseWidgetToken(this);
- }
- }
- }
-
- /*
- * @see AbstractInformationControlManager#handleInformationControlDisposed()
- */
- protected void handleInformationControlDisposed() {
- try {
- super.handleInformationControlDisposed();
- } finally {
- if (fTextViewer instanceof IWidgetTokenOwner) {
- IWidgetTokenOwner owner= (IWidgetTokenOwner) fTextViewer;
- owner.releaseWidgetToken(this);
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeper#requestWidgetToken(IWidgetTokenOwner)
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#requestWidgetToken(org.eclipse.jface.text.IWidgetTokenOwner, int)
- * @since 3.0
- */
- public boolean requestWidgetToken(IWidgetTokenOwner owner, int priority) {
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.IWidgetTokenKeeperExtension#setFocus(org.eclipse.jface.text.IWidgetTokenOwner)
- * @since 3.0
- */
- public boolean setFocus(IWidgetTokenOwner owner) {
- return false;
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/information/package.html
deleted file mode 100644
index 2c20da02084..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/information/package.html
+++ /dev/null
@@ -1,22 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides an information provider add-on for an <tt>ITextViewer</tt>.
-An information provider presents information for a certain subject in a
-specific information control. An information control usually is a floating
-window.
-<h2>
-Package Specification</h2>
-<tt>IInformationPresenter</tt> defines the concept of an information provider.
-It collaborates with content type specific information providers (<tt>IInformationProvider</tt>)
-which determine for a certain offset in a text viewer an information subject
-and the information available about this subject.. The package contains
-a default implementation of <tt>IInformationPresenter</tt> (<tt>InformationPresenter</tt>).
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java
deleted file mode 100644
index 22585291c81..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedModeUI.java
+++ /dev/null
@@ -1,1178 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.link;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.VerifyKeyListener;
-import org.eclipse.swt.events.ShellEvent;
-import org.eclipse.swt.events.ShellListener;
-import org.eclipse.swt.events.VerifyEvent;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.internal.text.link.contentassist.ContentAssistant2;
-import org.eclipse.jface.internal.text.link.contentassist.IProposalListener;
-import org.eclipse.jface.viewers.IPostSelectionProvider;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.ISelectionChangedListener;
-import org.eclipse.jface.viewers.SelectionChangedEvent;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPartitioningException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentCommand;
-import org.eclipse.jface.text.IAutoEditStrategy;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextOperationTarget;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.source.IAnnotationModel;
-import org.eclipse.jface.text.source.IAnnotationModelExtension;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * The UI for linked mode. Detects events that influence behavior of the linked mode
- * UI and acts upon them.
- * <p>
- * <code>LinkedModeUI</code> relies on all added
- * <code>LinkedModeUITarget</code>s to provide implementations of
- * <code>ITextViewer</code> that implement <code>ITextViewerExtension</code>,
- * and the documents being edited to implement <code>IDocumentExtension3</code>.
- * </p>
- * <p>
- * Clients may instantiate and extend this class.
- * </p>
- *
- * @since 3.0
- */
-public class LinkedModeUI {
-
- /* cycle constants */
- /**
- * Constant indicating that this UI should never cycle from the last
- * position to the first and vice versa.
- */
- public static final Object CYCLE_NEVER= new Object();
- /**
- * Constant indicating that this UI should always cycle from the last
- * position to the first and vice versa.
- */
- public static final Object CYCLE_ALWAYS= new Object();
- /**
- * Constant indicating that this UI should cycle from the last position to
- * the first and vice versa if its model is not nested.
- */
- public static final Object CYCLE_WHEN_NO_PARENT= new Object();
-
- /**
- * Listener that gets notified when the linked mode UI switches its focus position.
- * <p>
- * Clients may implement this interface.
- * </p>
- */
- public static interface ILinkedModeUIFocusListener {
- /**
- * Called when the UI for the linked mode leaves a linked position.
- *
- * @param position the position being left
- * @param target the target where <code>position</code> resides in
- */
- void linkingFocusLost(LinkedPosition position, LinkedModeUITarget target);
- /**
- * Called when the UI for the linked mode gives focus to a linked position.
- *
- * @param position the position being entered
- * @param target the target where <code>position</code> resides in
- */
- void linkingFocusGained(LinkedPosition position, LinkedModeUITarget target);
- }
-
- /**
- * Null object implementation of focus listener.
- */
- private static final class EmtpyFocusListener implements ILinkedModeUIFocusListener {
-
- public void linkingFocusGained(LinkedPosition position, LinkedModeUITarget target) {
- // ignore
- }
-
- public void linkingFocusLost(LinkedPosition position, LinkedModeUITarget target) {
- // ignore
- }
- }
-
- /**
- * A link target consists of a viewer and gets notified if the linked mode UI on
- * it is being shown.
- * <p>
- * Clients may extend this class.
- * </p>
- * @since 3.0
- */
- public static abstract class LinkedModeUITarget implements ILinkedModeUIFocusListener {
- /**
- * Returns the viewer represented by this target, never <code>null</code>.
- *
- * @return the viewer associated with this target.
- */
- public abstract ITextViewer getViewer();
-
- /**
- * The viewer's text widget is initialized when the UI first connects
- * to the viewer and never changed thereafter. This is to keep the
- * reference of the widget that we have registered our listeners with,
- * as the viewer, when it gets disposed, does not remember it, resulting
- * in a situation where we cannot uninstall the listeners and a memory leak.
- */
- StyledText fWidget;
-
- /** The cached shell - same reason as fWidget. */
- Shell fShell;
-
- /** The registered listener, or <code>null</code>. */
- KeyListener fKeyListener;
-
- /** The cached custom annotation model. */
- LinkedPositionAnnotations fAnnotationModel;
- }
-
- private static final class EmptyTarget extends LinkedModeUITarget {
-
- private ITextViewer fTextViewer;
-
- /**
- * @param viewer the viewer
- */
- public EmptyTarget(ITextViewer viewer) {
- Assert.isNotNull(viewer);
- fTextViewer= viewer;
- }
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.link2.LinkedModeUI.ILinkedUITarget#getViewer()
- */
- public ITextViewer getViewer() {
- return fTextViewer;
- }
-
- /**
- * {@inheritDoc}
- */
- public void linkingFocusLost(LinkedPosition position, LinkedModeUITarget target) {
- }
-
- /**
- * {@inheritDoc}
- */
- public void linkingFocusGained(LinkedPosition position, LinkedModeUITarget target) {
- }
-
- }
-
- /**
- * Listens for state changes in the model.
- */
- private final class ExitListener implements ILinkedModeListener {
- public void left(LinkedModeModel model, int flags) {
- leave(ILinkedModeListener.EXIT_ALL | flags);
- }
-
- public void suspend(LinkedModeModel model) {
- disconnect();
- redraw();
- }
-
- public void resume(LinkedModeModel model, int flags) {
- if ((flags & ILinkedModeListener.EXIT_ALL) != 0) {
- leave(flags);
- } else {
- connect();
- if ((flags & ILinkedModeListener.SELECT) != 0)
- select();
- ensureAnnotationModelInstalled();
- redraw();
- }
- }
- }
-
- /**
- * Exit flags returned if a custom exit policy wants to exit linked mode.
- * <p>
- * Clients may instantiate this class.
- * </p>
- */
- public static class ExitFlags {
- /** The flags to return in the <code>leave</code> method. */
- public int flags;
- /** The doit flag of the checked <code>VerifyKeyEvent</code>. */
- public boolean doit;
- /**
- * Creates a new instance.
- *
- * @param flags the exit flags
- * @param doit the doit flag for the verify event
- */
- public ExitFlags(int flags, boolean doit) {
- this.flags= flags;
- this.doit= doit;
- }
- }
-
- /**
- * An exit policy can be registered by a caller to get custom exit
- * behavior.
- * <p>
- * Clients may implement this interface.
- * </p>
- */
- public interface IExitPolicy {
- /**
- * Checks whether the linked mode should be left after receiving the
- * given <code>VerifyEvent</code> and selection. Note that the event
- * carries widget coordinates as opposed to <code>offset</code> and
- * <code>length</code> which are document coordinates.
- *
- * @param model the linked mode model
- * @param event the verify event
- * @param offset the offset of the current selection
- * @param length the length of the current selection
- * @return valid exit flags or <code>null</code> if no special action
- * should be taken
- */
- ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length);
- }
-
- /**
- * A NullObject implementation of <code>IExitPolicy</code>.
- */
- private static class NullExitPolicy implements IExitPolicy {
- /*
- * @see org.eclipse.jdt.internal.ui.text.link2.LinkedModeUI.IExitPolicy#doExit(org.eclipse.swt.events.VerifyEvent, int, int)
- */
- public ExitFlags doExit(LinkedModeModel model, VerifyEvent event, int offset, int length) {
- return null;
- }
- }
-
- /**
- * Listens for shell events and acts upon them.
- */
- private class Closer implements ShellListener, ITextInputListener {
-
- public void shellActivated(ShellEvent e) {
- }
-
- public void shellClosed(ShellEvent e) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
-
- public void shellDeactivated(ShellEvent e) {
-// T ODO reenable after debugging
-// if (true) return;
-
- // from LinkedPositionUI:
-
- // don't deactivate on focus lost, since the proposal popups may take focus
- // plus: it doesn't hurt if you can check with another window without losing linked mode
- // since there is no intrusive popup sticking out.
-
- // need to check first what happens on reentering based on an open action
- // Seems to be no problem
-
- // Better:
- // Check with content assistant and only leave if its not the proposal shell that took the
- // focus away.
-
- StyledText text;
- Display display;
-
- if (fAssistant == null || fCurrentTarget == null || (text= fCurrentTarget.fWidget) == null
- || text.isDisposed() || (display= text.getDisplay()) == null || display.isDisposed()) {
- leave(ILinkedModeListener.EXIT_ALL);
- } else {
- // Post in UI thread since the assistant popup will only get the focus after we lose it.
- display.asyncExec(new Runnable() {
- public void run() {
- if (fIsActive && (fAssistant == null || !fAssistant.hasFocus())) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
- }
- });
- }
- }
-
- public void shellDeiconified(ShellEvent e) {
- }
-
- public void shellIconified(ShellEvent e) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
-
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- }
-
- }
-
- /**
- * Listens for key events, checks the exit policy for custom exit
- * strategies but defaults to handling Tab, Enter, and Escape.
- */
- private class KeyListener implements VerifyKeyListener {
-
- private boolean fIsEnabled= true;
-
- public void verifyKey(VerifyEvent event) {
-
- if (!event.doit || !fIsEnabled)
- return;
-
- Point selection= fCurrentTarget.getViewer().getSelectedRange();
- int offset= selection.x;
- int length= selection.y;
-
- // if the custom exit policy returns anything, use that
- ExitFlags exitFlags= fExitPolicy.doExit(fEnvironment, event, offset, length);
- if (exitFlags != null) {
- leave(exitFlags.flags);
- event.doit= exitFlags.doit;
- return;
- }
-
- // standard behaviour:
- // (Shift+)Tab: jumps from position to position, depending on cycle mode
- // Enter: accepts all entries and leaves all (possibly stacked) environments, the last sets the caret
- // Esc: accepts all entries and leaves all (possibly stacked) environments, the caret stays
- // ? what do we do to leave one level of a cycling model that is stacked?
- // -> This is only the case if the level was set up with forced cycling (CYCLE_ALWAYS), in which case
- // the caller is sure that one does not need by-level exiting.
- switch (event.character) {
- // [SHIFT-]TAB = hop between edit boxes
- case 0x09:
- if (!(fExitPosition != null && fExitPosition.includes(offset)) && !fEnvironment.anyPositionContains(offset)) {
- // outside any edit box -> leave (all? TODO should only leave the affected, level and forward to the next upper)
- leave(ILinkedModeListener.EXIT_ALL);
- break;
- } else {
- if (event.stateMask == SWT.SHIFT)
- previous();
- else
- next();
- }
-
- event.doit= false;
- break;
-
- // ENTER
- case 0x0A:
- // Ctrl+Enter on WinXP
- case 0x0D:
-// if ((fExitPosition != null && fExitPosition.includes(offset)) || !fEnvironment.anyPositionContains(offset)) {
- if (!fEnvironment.anyPositionContains(offset)) {
-// if ((fExitPosition == null || !fExitPosition.includes(offset)) && !fEnvironment.anyPositionContains(offset)) {
- // outside any edit box or on exit position -> leave (all? TODO should only leave the affected, level and forward to the next upper)
- leave(ILinkedModeListener.EXIT_ALL);
- break;
- } else {
- // normal case: exit entire stack and put caret to final position
- leave(ILinkedModeListener.EXIT_ALL | ILinkedModeListener.UPDATE_CARET);
- event.doit= false;
- break;
- }
-
- // ESC
- case 0x1B:
- // exit entire stack and leave caret
- leave(ILinkedModeListener.EXIT_ALL);
- event.doit= false;
- break;
-
- default:
- if (event.character != 0) {
- if (!controlUndoBehavior(offset, length)) {
- leave(ILinkedModeListener.EXIT_ALL);
- break;
- }
- }
- }
- }
-
- private boolean controlUndoBehavior(int offset, int length) {
- LinkedPosition position= fEnvironment.findPosition(new LinkedPosition(fCurrentTarget.getViewer().getDocument(), offset, length, LinkedPositionGroup.NO_STOP));
- if (position != null) {
-
- // if the last position is not the same and there is an open change: close it.
- if (!position.equals(fPreviousPosition))
- endCompoundChange();
-
- beginCompoundChange();
- }
-
- fPreviousPosition= position;
- return fPreviousPosition != null;
- }
-
- /**
- * @param enabled the new enabled state
- */
- public void setEnabled(boolean enabled) {
- fIsEnabled= enabled;
- }
-
- }
-
- /**
- * Installed as post selection listener on the watched viewer. Updates the
- * linked position after cursor movement, even to positions not in the
- * iteration list.
- */
- private class MySelectionListener implements ISelectionChangedListener {
-
- /*
- * @see org.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.SelectionChangedEvent)
- */
- public void selectionChanged(SelectionChangedEvent event) {
- ISelection selection= event.getSelection();
- if (selection instanceof ITextSelection) {
- ITextSelection textsel= (ITextSelection) selection;
- if (event.getSelectionProvider() instanceof ITextViewer) {
- IDocument doc= ((ITextViewer) event.getSelectionProvider()).getDocument();
- if (doc != null) {
- int offset= textsel.getOffset();
- int length= textsel.getLength();
- if (offset >= 0 && length >= 0) {
- LinkedPosition find= new LinkedPosition(doc, offset, length, LinkedPositionGroup.NO_STOP);
- LinkedPosition pos= fEnvironment.findPosition(find);
- if (pos == null && fExitPosition != null && fExitPosition.includes(find))
- pos= fExitPosition;
-
- if (pos != null)
- switchPosition(pos, false, false);
- }
- }
- }
- }
- }
-
- }
-
- private class ProposalListener implements IProposalListener {
-
- /*
- * @see org.eclipse.jface.internal.text.link.contentassist.IProposalListener#proposalChosen(org.eclipse.jface.text.contentassist.ICompletionProposal)
- */
- public void proposalChosen(ICompletionProposal proposal) {
- next();
- }
- }
-
- /** The current viewer. */
- private LinkedModeUITarget fCurrentTarget;
- /** The manager of the linked positions we provide a UI for. */
- private LinkedModeModel fEnvironment;
- /** The set of viewers we manage. */
- private LinkedModeUITarget[] fTargets;
- /** The iterator over the tab stop positions. */
- private TabStopIterator fIterator;
-
- /* Our team of event listeners */
- /** The shell listener. */
- private Closer fCloser= new Closer();
- /** The linked mode listener. */
- private ILinkedModeListener fLinkedListener= new ExitListener();
- /** The selection listener. */
- private MySelectionListener fSelectionListener= new MySelectionListener();
- /** The content assist listener. */
- private ProposalListener fProposalListener= new ProposalListener();
-
- /** The last caret position, used by fCaretListener. */
- private final Position fCaretPosition= new Position(0, 0);
- /** The exit policy to control custom exit behaviour */
- private IExitPolicy fExitPolicy= new NullExitPolicy();
- /** The current frame position shown in the UI, or <code>null</code>. */
- private LinkedPosition fFramePosition;
- /** The last visisted position, used for undo / redo. */
- private LinkedPosition fPreviousPosition;
- /** The content assistant used to show proposals. */
- private ContentAssistant2 fAssistant;
- /** The exit position. */
- private LinkedPosition fExitPosition;
- /** State indicator to prevent multiple invocation of leave. */
- private boolean fIsActive= false;
- /** The position updater for the exit position. */
- private IPositionUpdater fPositionUpdater= new DefaultPositionUpdater(getCategory());
- /** Whether to show context info. */
- private boolean fDoContextInfo= false;
- /** Whether we have begun a compound change, but not yet closed. */
- private boolean fHasOpenCompoundChange= false;
- /** The position listener. */
- private ILinkedModeUIFocusListener fPositionListener= new EmtpyFocusListener();
- private IAutoEditStrategy fAutoEditVetoer= new IAutoEditStrategy() {
-
- /*
- * @see org.eclipse.jface.text.IAutoEditStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand)
- */
- public void customizeDocumentCommand(IDocument document, DocumentCommand command) {
- // invalidate the change to ensure that the change is performed on the document only.
- if (fEnvironment.anyPositionContains(command.offset)) {
- command.doit= false;
- command.caretOffset= command.offset + command.length;
- }
-
- }
- };
- /** Whether this UI is in simple highlighting mode or not. */
- private boolean fSimple;
-
- /**
- * Creates a new UI on the given model and the set of viewers. The model
- * must provide a tab stop sequence with a non-empty list of tab stops.
- *
- * @param model the linked mode model
- * @param targets the non-empty list of targets upon which the linked mode
- * UI should act
- */
- public LinkedModeUI(LinkedModeModel model, LinkedModeUITarget[] targets) {
- constructor(model, targets);
- }
-
- /**
- * Convenience constructor for just one viewer.
- *
- * @param model the linked mode model
- * @param viewer the viewer upon which the linked mode UI should act
- */
- public LinkedModeUI(LinkedModeModel model, ITextViewer viewer) {
- constructor(model, new LinkedModeUITarget[]{new EmptyTarget(viewer)});
- }
-
- /**
- * Convenience constructor for multiple viewers.
- *
- * @param model the linked mode model
- * @param viewers the non-empty list of viewers upon which the linked mode
- * UI should act
- */
- public LinkedModeUI(LinkedModeModel model, ITextViewer[] viewers) {
- LinkedModeUITarget[] array= new LinkedModeUITarget[viewers.length];
- for (int i= 0; i < array.length; i++) {
- array[i]= new EmptyTarget(viewers[i]);
- }
- constructor(model, array);
- }
-
- /**
- * Convenience constructor for one target.
- *
- * @param model the linked mode model
- * @param target the target upon which the linked mode UI should act
- */
- public LinkedModeUI(LinkedModeModel model, LinkedModeUITarget target) {
- constructor(model, new LinkedModeUITarget[]{target});
- }
-
- /**
- * This does the actual constructor work.
- *
- * @param model the linked mode model
- * @param targets the non-empty array of targets upon which the linked mode ui
- * should act
- */
- private void constructor(LinkedModeModel model, LinkedModeUITarget[] targets) {
- Assert.isNotNull(model);
- Assert.isNotNull(targets);
- Assert.isTrue(targets.length > 0);
- Assert.isTrue(model.getTabStopSequence().size() > 0);
-
- fEnvironment= model;
- fTargets= targets;
- fCurrentTarget= targets[0];
- fIterator= new TabStopIterator(fEnvironment.getTabStopSequence());
- fIterator.setCycling(!fEnvironment.isNested());
- fEnvironment.addLinkingListener(fLinkedListener);
-
- fAssistant= new ContentAssistant2();
- fAssistant.addProposalListener(fProposalListener);
- // TODO find a way to set up content assistant.
-// fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING);
-
- fCaretPosition.delete();
- }
-
- /**
- * Starts this UI on the first position.
- */
- public void enter() {
- fIsActive= true;
- connect();
- next();
- }
-
- /**
- * Sets an <code>IExitPolicy</code> to customize the exit behavior of
- * this linked mode UI.
- *
- * @param policy the exit policy to use.
- */
- public void setExitPolicy(IExitPolicy policy) {
- fExitPolicy= policy;
- }
-
- /**
- * Sets the exit position to move the caret to when linked mode mode is
- * exited.
- *
- * @param target the target where the exit position is located
- * @param offset the offset of the exit position
- * @param length the length of the exit position (in case there should be a
- * selection)
- * @param sequence set to the tab stop position of the exit position, or
- * <code>LinkedPositionGroup.NO_STOP</code> if there should be no
- * tab stop.
- * @throws BadLocationException if the position is not valid in the viewer's
- * document
- */
- public void setExitPosition(LinkedModeUITarget target, int offset, int length, int sequence) throws BadLocationException {
- // remove any existing exit position
- if (fExitPosition != null) {
- fExitPosition.getDocument().removePosition(fExitPosition);
- fIterator.removePosition(fExitPosition);
- fExitPosition= null;
- }
-
- IDocument doc= target.getViewer().getDocument();
- if (doc == null)
- return;
-
- fExitPosition= new LinkedPosition(doc, offset, length, sequence);
- doc.addPosition(fExitPosition); // gets removed in leave()
- if (sequence != LinkedPositionGroup.NO_STOP)
- fIterator.addPosition(fExitPosition);
-
- }
-
- /**
- * Sets the exit position to move the caret to when linked mode is exited.
- *
- * @param viewer the viewer where the exit position is located
- * @param offset the offset of the exit position
- * @param length the length of the exit position (in case there should be a
- * selection)
- * @param sequence set to the tab stop position of the exit position, or
- * <code>LinkedPositionGroup.NO_STOP</code> if there should be no tab stop.
- * @throws BadLocationException if the position is not valid in the
- * viewer's document
- */
- public void setExitPosition(ITextViewer viewer, int offset, int length, int sequence) throws BadLocationException {
- setExitPosition(new EmptyTarget(viewer), offset, length, sequence);
- }
-
- /**
- * Sets the cycling mode to either of <code>CYCLING_ALWAYS</code>,
- * <code>CYCLING_NEVER</code>, or <code>CYCLING_WHEN_NO_PARENT</code>,
- * which is the default.
- *
- * @param mode the new cycling mode.
- */
- public void setCyclingMode(Object mode) {
- if (mode != CYCLE_ALWAYS && mode != CYCLE_NEVER && mode != CYCLE_WHEN_NO_PARENT)
- throw new IllegalArgumentException();
-
- if (mode == CYCLE_ALWAYS || mode == CYCLE_WHEN_NO_PARENT && !fEnvironment.isNested())
- fIterator.setCycling(true);
- else
- fIterator.setCycling(false);
- }
-
- void next() {
- if (fIterator.hasNext(fFramePosition)) {
- switchPosition(fIterator.next(fFramePosition), true, true);
- return;
- } else
- leave(ILinkedModeListener.UPDATE_CARET);
- }
-
- void previous() {
- if (fIterator.hasPrevious(fFramePosition)) {
- switchPosition(fIterator.previous(fFramePosition), true, true);
- } else
- // dont't update caret, but rather select the current frame
- leave(ILinkedModeListener.SELECT);
- }
-
- private void triggerContextInfo() {
- ITextOperationTarget target= fCurrentTarget.getViewer().getTextOperationTarget();
- if (target != null) {
- if (target.canDoOperation(ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION))
- target.doOperation(ISourceViewer.CONTENTASSIST_CONTEXT_INFORMATION);
- }
- }
-
- /** Trigger content assist on choice positions */
- private void triggerContentAssist() {
- if (fFramePosition instanceof ProposalPosition) {
- ProposalPosition pp= (ProposalPosition) fFramePosition;
- ICompletionProposal[] choices= pp.getChoices();
- if (choices != null && choices.length > 0) {
- fAssistant.setCompletions(choices);
- fAssistant.showPossibleCompletions();
- return;
- }
- }
-
- fAssistant.setCompletions(new ICompletionProposal[0]);
- fAssistant.hidePossibleCompletions();
- }
-
- private void switchPosition(LinkedPosition pos, boolean select, boolean showProposals) {
- Assert.isNotNull(pos);
- if (pos.equals(fFramePosition))
- return;
-
- if (fFramePosition != null && fCurrentTarget != null)
- fPositionListener.linkingFocusLost(fFramePosition, fCurrentTarget);
-
- // undo
- endCompoundChange();
-
- redraw(); // redraw current position being left - usually not needed
- IDocument oldDoc= fFramePosition == null ? null : fFramePosition.getDocument();
- IDocument newDoc= pos.getDocument();
-
- switchViewer(oldDoc, newDoc, pos);
- fFramePosition= pos;
-
- if (select)
- select();
- if (fFramePosition == fExitPosition && !fIterator.isCycling())
- leave(ILinkedModeListener.NONE);
- else {
- redraw(); // redraw new position
- ensureAnnotationModelInstalled();
- }
- if (showProposals)
- triggerContentAssist();
- if (fFramePosition != fExitPosition && fDoContextInfo)
- triggerContextInfo();
-
- if (fFramePosition != null && fCurrentTarget != null)
- fPositionListener.linkingFocusGained(fFramePosition, fCurrentTarget);
-
- }
-
- private void ensureAnnotationModelInstalled() {
- LinkedPositionAnnotations lpa= fCurrentTarget.fAnnotationModel;
- if (lpa != null) {
- ITextViewer viewer= fCurrentTarget.getViewer();
- if (viewer instanceof ISourceViewer) {
- ISourceViewer sv= (ISourceViewer) viewer;
- IAnnotationModel model= sv.getAnnotationModel();
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension ext= (IAnnotationModelExtension) model;
- IAnnotationModel ourModel= ext.getAnnotationModel(getUniqueKey());
- if (ourModel == null) {
- ext.addAnnotationModel(getUniqueKey(), lpa);
- }
- }
- }
- }
- }
-
- private void uninstallAnnotationModel(LinkedModeUITarget target) {
- ITextViewer viewer= target.getViewer();
- if (viewer instanceof ISourceViewer) {
- ISourceViewer sv= (ISourceViewer) viewer;
- IAnnotationModel model= sv.getAnnotationModel();
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension ext= (IAnnotationModelExtension) model;
- ext.removeAnnotationModel(getUniqueKey());
- }
- }
- }
-
- private void switchViewer(IDocument oldDoc, IDocument newDoc, LinkedPosition pos) {
- if (oldDoc != newDoc) {
-
- // redraw current document with new position before switching viewer
- if (fCurrentTarget.fAnnotationModel != null)
- fCurrentTarget.fAnnotationModel.switchToPosition(fEnvironment, pos);
-
- LinkedModeUITarget target= null;
- for (int i= 0; i < fTargets.length; i++) {
- if (fTargets[i].getViewer().getDocument() == newDoc) {
- target= fTargets[i];
- break;
- }
- }
- if (target != fCurrentTarget) {
- disconnect();
- fCurrentTarget= target;
- target.linkingFocusLost(fFramePosition, target);
- connect();
- ensureAnnotationModelInstalled();
- if (fCurrentTarget != null)
- fCurrentTarget.linkingFocusGained(pos, fCurrentTarget);
- }
- }
- }
-
- private void select() {
- ITextViewer viewer= fCurrentTarget.getViewer();
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension5= (ITextViewerExtension5) viewer;
- extension5.exposeModelRange(new Region(fFramePosition.offset, fFramePosition.length));
- } else if (!viewer.overlapsWithVisibleRegion(fFramePosition.offset, fFramePosition.length)) {
- viewer.resetVisibleRegion();
- }
- viewer.revealRange(fFramePosition.offset, fFramePosition.length);
- viewer.setSelectedRange(fFramePosition.offset, fFramePosition.length);
- }
-
- private void redraw() {
- if (fCurrentTarget.fAnnotationModel != null)
- fCurrentTarget.fAnnotationModel.switchToPosition(fEnvironment, fFramePosition);
- }
-
- private void connect() {
- Assert.isNotNull(fCurrentTarget);
- ITextViewer viewer= fCurrentTarget.getViewer();
- Assert.isNotNull(viewer);
- fCurrentTarget.fWidget= viewer.getTextWidget();
- if (fCurrentTarget.fWidget == null)
- leave(ILinkedModeListener.EXIT_ALL);
-
- if (fCurrentTarget.fKeyListener == null) {
- fCurrentTarget.fKeyListener= new KeyListener();
- ((ITextViewerExtension) viewer).prependVerifyKeyListener(fCurrentTarget.fKeyListener);
- } else
- fCurrentTarget.fKeyListener.setEnabled(true);
-
- registerAutoEditVetoer(viewer);
-
- ((IPostSelectionProvider) viewer).addPostSelectionChangedListener(fSelectionListener);
-
- createAnnotationModel();
-
- showSelection();
-
- fCurrentTarget.fShell= fCurrentTarget.fWidget.getShell();
- if (fCurrentTarget.fShell == null)
- leave(ILinkedModeListener.EXIT_ALL);
- fCurrentTarget.fShell.addShellListener(fCloser);
-
- fAssistant.install(viewer);
-
- viewer.addTextInputListener(fCloser);
- }
-
- /**
- * Reveals the selection on the current target's widget, if it is valid.
- */
- private void showSelection() {
- try {
- fCurrentTarget.fWidget.showSelection();
- } catch (IllegalArgumentException e) {
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=66914
- // if the StyledText is in setRedraw(false) mode, its
- // selection may not be up2date and calling showSelection
- // will throw an IAE.
- // we don't have means to find out whether the selection is valid
- // or whether the widget is redrawing or not therefore we try
- // and ignore an IAE.
- }
- }
-
- /**
- * Registers our auto edit vetoer with the viewer.
- *
- * @param viewer the viewer we want to veto ui-triggered changes within
- * linked positions
- */
- private void registerAutoEditVetoer(ITextViewer viewer) {
- try {
- if (viewer.getDocument() instanceof IDocumentExtension3) {
- IDocumentExtension3 ext= (IDocumentExtension3) viewer.getDocument();
- String[] contentTypes= ext.getLegalContentTypes(IDocumentExtension3.DEFAULT_PARTITIONING);
- if (viewer instanceof ITextViewerExtension2) {
- ITextViewerExtension2 vExtension= ((ITextViewerExtension2) viewer);
- for (int i= 0; i < contentTypes.length; i++) {
- vExtension.prependAutoEditStrategy(fAutoEditVetoer, contentTypes[i]);
- }
- } else {
- Assert.isTrue(false);
- }
- }
-
- } catch (BadPartitioningException e) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
- }
-
- private void unregisterAutoEditVetoer(ITextViewer viewer) {
- try {
- if (viewer.getDocument() instanceof IDocumentExtension3) {
- IDocumentExtension3 ext= (IDocumentExtension3) viewer.getDocument();
- String[] contentTypes= ext.getLegalContentTypes(IDocumentExtension3.DEFAULT_PARTITIONING);
- if (viewer instanceof ITextViewerExtension2) {
- ITextViewerExtension2 vExtension= ((ITextViewerExtension2) viewer);
- for (int i= 0; i < contentTypes.length; i++) {
- vExtension.removeAutoEditStrategy(fAutoEditVetoer, contentTypes[i]);
- }
- }
- }
-
- } catch (BadPartitioningException e) {
- leave(ILinkedModeListener.EXIT_ALL);
- }
- }
-
- private void createAnnotationModel() {
- if (fCurrentTarget.fAnnotationModel == null) {
- LinkedPositionAnnotations lpa= new LinkedPositionAnnotations();
- if (fSimple) {
- lpa.markExitTarget(true);
- lpa.markFocus(false);
- lpa.markSlaves(false);
- lpa.markTargets(false);
- }
- lpa.setTargets(fIterator.getPositions());
- lpa.setExitTarget(fExitPosition);
- lpa.connect(fCurrentTarget.getViewer().getDocument());
- fCurrentTarget.fAnnotationModel= lpa;
- }
- }
-
- private String getUniqueKey() {
- return "linked.annotationmodelkey."+toString(); //$NON-NLS-1$
- }
-
- private void disconnect() {
- Assert.isNotNull(fCurrentTarget);
- ITextViewer viewer= fCurrentTarget.getViewer();
- Assert.isNotNull(viewer);
-
- fAssistant.uninstall();
- fAssistant.removeProposalListener(fProposalListener);
-
- fCurrentTarget.fWidget= null;
-
- Shell shell= fCurrentTarget.fShell;
- fCurrentTarget.fShell= null;
-
- if (shell != null && !shell.isDisposed())
- shell.removeShellListener(fCloser);
-
- // this one is asymmetric: we don't install the model in
- // connect, but leave it to its callers to ensure they
- // have the model installed if they need it
- uninstallAnnotationModel(fCurrentTarget);
-
- unregisterAutoEditVetoer(viewer);
-
- // don't remove the verify key listener to let it keep its position
- // in the listener queue
- fCurrentTarget.fKeyListener.setEnabled(false);
-
- ((IPostSelectionProvider) viewer).removePostSelectionChangedListener(fSelectionListener);
-
- redraw();
- }
-
- void leave(final int flags) {
- if (!fIsActive)
- return;
- fIsActive= false;
-
- endCompoundChange();
-
- Display display= null;
- if (fCurrentTarget.fWidget != null && !fCurrentTarget.fWidget.isDisposed())
- display= fCurrentTarget.fWidget.getDisplay();
-
-// // debug trace
-// JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "leaving linked mode", null));
- if (fCurrentTarget.fAnnotationModel != null)
- fCurrentTarget.fAnnotationModel.removeAllAnnotations();
- disconnect();
-
- for (int i= 0; i < fTargets.length; i++) {
- LinkedModeUITarget target= fTargets[i];
- ITextViewer viewer= target.getViewer();
- if (target.fKeyListener != null) {
- ((ITextViewerExtension) viewer).removeVerifyKeyListener(target.fKeyListener);
- target.fKeyListener= null;
- }
-
- viewer.removeTextInputListener(fCloser);
- }
-
- for (int i= 0; i < fTargets.length; i++) {
-
- if (fTargets[i].fAnnotationModel != null) {
- fTargets[i].fAnnotationModel.removeAllAnnotations();
- fTargets[i].fAnnotationModel.disconnect(fTargets[i].getViewer().getDocument());
- fTargets[i].fAnnotationModel= null;
- }
-
- uninstallAnnotationModel(fTargets[i]);
- }
-
-
- if (fExitPosition != null)
- fExitPosition.getDocument().removePosition(fExitPosition);
-
- if ((flags & ILinkedModeListener.UPDATE_CARET) != 0 && fExitPosition != null && fFramePosition != fExitPosition && !fExitPosition.isDeleted())
- switchPosition(fExitPosition, true, false);
-
- final List docs= new ArrayList();
- for (int i= 0; i < fTargets.length; i++) {
- IDocument doc= fTargets[i].getViewer().getDocument();
- if (doc != null)
- docs.add(doc);
- }
-
- Runnable runnable= new Runnable() {
- public void run() {
- for (Iterator iter = docs.iterator(); iter.hasNext(); ) {
- IDocument doc= (IDocument) iter.next();
- doc.removePositionUpdater(fPositionUpdater);
- boolean uninstallCat= false;
- String[] cats= doc.getPositionCategories();
- for (int j= 0; j < cats.length; j++) {
- if (getCategory().equals(cats[j])) {
- uninstallCat= true;
- break;
- }
- }
- if (uninstallCat)
- try {
- doc.removePositionCategory(getCategory());
- } catch (BadPositionCategoryException e) {
- // ignore
- }
- }
- fEnvironment.exit(flags);
- }
- };
-
- // remove positions (both exit positions AND linked positions in the
- // model) async to make sure that the annotation painter
- // gets correct document offsets.
- if (display != null)
- display.asyncExec(runnable);
- else
- runnable.run();
- }
-
- private void endCompoundChange() {
- if (fHasOpenCompoundChange) {
- ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
- IRewriteTarget target= extension.getRewriteTarget();
- target.endCompoundChange();
- fHasOpenCompoundChange= false;
- }
- }
-
- private void beginCompoundChange() {
- if (!fHasOpenCompoundChange) {
- ITextViewerExtension extension= (ITextViewerExtension) fCurrentTarget.getViewer();
- IRewriteTarget target= extension.getRewriteTarget();
- target.beginCompoundChange();
- fHasOpenCompoundChange= true;
- }
- }
-
- /**
- * Returns the currently selected region or <code>null</code>.
- *
- * @return the currently selected region or <code>null</code>
- */
- public IRegion getSelectedRegion() {
- if (fFramePosition == null)
- if (fExitPosition != null)
- return new Region(fExitPosition.getOffset(), fExitPosition.getLength());
- else
- return null;
- else
- return new Region(fFramePosition.getOffset(), fFramePosition.getLength());
- }
-
- private String getCategory() {
- return toString();
- }
-
- /**
- * Sets the context info property. If set to <code>true</code>, context
- * info will be invoked on the current target's viewer whenever a position
- * is switched.
- *
- * @param doContextInfo <code>true</code> if context information should be
- * displayed
- */
- public void setDoContextInfo(boolean doContextInfo) {
- fDoContextInfo= doContextInfo;
- }
-
- /**
- * Sets the focus callback which will get informed when the focus of the
- * linked mode UI changes.
- * <p>
- * If there is a listener installed already, it will be replaced.
- * </p>
- *
- * @param listener the new listener, never <code>null</code>.
- */
- protected void setPositionListener(ILinkedModeUIFocusListener listener) {
- Assert.isNotNull(listener);
- fPositionListener= listener;
- }
-
- /**
- * Sets the "simple" mode of the receiver. A linked mode UI in simple mode
- * merely draws the exit position, but not the target, focus, and slave
- * positions. Default is <code>false</code>. This method must be called
- * before it is entered.
- *
- * @param simple <code>true</code> if the UI should be in simple mode.
- */
- public void setSimpleMode(boolean simple) {
- fSimple= simple;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedPositionAnnotations.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedPositionAnnotations.java
deleted file mode 100644
index 92a7b4c7be2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/LinkedPositionAnnotations.java
+++ /dev/null
@@ -1,310 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.link;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.link.LinkedModeModel;
-import org.eclipse.jface.text.link.LinkedPosition;
-import org.eclipse.jface.text.link.LinkedPositionGroup;
-import org.eclipse.jface.text.source.Annotation;
-import org.eclipse.jface.text.source.AnnotationModel;
-
-/**
- * Internal class.
- *
- * @since 3.0
- */
-final class LinkedPositionAnnotations extends AnnotationModel {
-
- /* annotation types */
- private static final String TARGET_ANNOTATION_TYPE= "org.eclipse.jdt.ui.link.target"; //$NON-NLS-1$
- private static final String SLAVE_ANNOTATION_TYPE= "org.eclipse.jdt.ui.link.slave"; //$NON-NLS-1$
- private static final String FOCUS_ANNOTATION_TYPE= "org.eclipse.jdt.ui.link.master"; //$NON-NLS-1$
- private static final String EXIT_ANNOTATION_TYPE= "org.eclipse.jdt.ui.link.exit"; //$NON-NLS-1$
-
- /* configuration */
- private boolean fMarkTargets= true;
- private boolean fMarkSlaves= true;
- private boolean fMarkFocus= true;
- private boolean fMarkExitTarget= true;
-
- private Annotation fFocusAnnotation= null;
- private Annotation fExitAnnotation= null;
- private final Map fGroupAnnotations= new HashMap();
- private final Map fTargetAnnotations= new HashMap();
- private Position[] fTargets= new Position[0];
- private LinkedPosition fExitPosition= null;
-
- /**
- * Sets the position that should be highlighted as the focus position, i.e.
- * as the position whose changes are propagated to all its linked positions
- * by the linked environment.
- *
- * @param position the new focus position, or <code>null</code> if no focus is set.
- */
- private void setFocusPosition(Position position) throws BadLocationException {
- if (fMarkFocus && getPosition(fFocusAnnotation) != position) {
- removeAnnotation(fFocusAnnotation, false);
- if (position != null) {
- fFocusAnnotation= new Annotation(FOCUS_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$
- addAnnotation(fFocusAnnotation, position, false);
- } else
- fFocusAnnotation= null;
- }
- }
-
- /**
- * Sets the position that should be highlighted as the exit position, i.e.
- * as the position whose changes are propagated to all its linked positions
- * by the linked environment.
- *
- * @param position the new exit position, or <code>null</code> if no focus is set.
- */
- private void setExitPosition(Position position) throws BadLocationException {
- if (fMarkExitTarget && getPosition(fExitAnnotation) != position) {
- removeAnnotation(fExitAnnotation, false);
- if (position != null) {
- fExitAnnotation= new Annotation(EXIT_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$
- addAnnotation(fExitAnnotation, position, false);
- } else
- fExitAnnotation= null;
- }
- }
-
- /**
- * Sets the positions that should be highlighted as the slave positions, i.e.
- * as the positions that are linked to the focus position.
- *
- * @param positions the new slave positions, or <code>null</code> if no slave positions are to be set
- */
- private void setGroupPositions(List positions) throws BadLocationException {
- if (!fMarkSlaves)
- return;
-
- // remove all positions which are already there
- // algo: toRemove contains all mappings at first, but all that are in
- // positions get removed -> toRemove contains the difference set of previsous - new
- // toAdd are the new positions, which don't exist in previous = new - previous
- List toRemove= new ArrayList(fGroupAnnotations.values());
- Map toAdd= new HashMap();
- if (positions != null) {
- for (Iterator iter= positions.iterator(); iter.hasNext();) {
- Position p= (Position) iter.next();
- if (fGroupAnnotations.containsKey(p)) {
- toRemove.remove(fGroupAnnotations.get(p));
- } else {
- Annotation a= new Annotation(SLAVE_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$
- toAdd.put(a, p);
- fGroupAnnotations.put(p, a);
- }
- }
- }
- fGroupAnnotations.values().removeAll(toRemove);
-
- replaceAnnotations((Annotation[]) toRemove.toArray(new Annotation[0]), toAdd, false);
- }
-
- /**
- * Sets the positions that should be highlighted as the target positions, i.e.
- * as the positions that can be jumped to in a linked set up.
- *
- * @param positions the new target positions, or <code>null</code> if no target positions are to be set
- */
- private void setTargetPositions(List positions) throws BadLocationException {
- if (!fMarkTargets)
- return;
-
- // remove all positions which are already there
- // algo: toRemove contains all mappings at first, but all that are in
- // positions get removed -> toRemove contains the difference set of previsous - new
- // toAdd are the new positions, which don't exist in previous = new - previous
- List toRemove= new ArrayList(fTargetAnnotations.values());
- Map toAdd= new HashMap();
- if (positions != null) {
- for (Iterator iter= positions.iterator(); iter.hasNext();) {
- Position p= (Position) iter.next();
- if (fTargetAnnotations.containsKey(p)) {
- toRemove.remove(fTargetAnnotations.get(p));
- } else {
- Annotation a= new Annotation(TARGET_ANNOTATION_TYPE, false, ""); //$NON-NLS-1$
- toAdd.put(a, p);
- fTargetAnnotations.put(p, a);
- }
- }
- }
- fTargetAnnotations.values().removeAll(toRemove);
-
- replaceAnnotations((Annotation[]) toRemove.toArray(new Annotation[0]), toAdd, false);
- }
-
- /**
- * Switches the focus position to <code>position</code> given the
- * <code>LinkedModeModel env</code>. The slave positions for <code>position</code>
- * is extracted from the environment and set accordingly, the target positions
- * are updated as well.
- *
- * @param env
- * @param position
- */
- public void switchToPosition(LinkedModeModel env, LinkedPosition position) {
- if (fDocument == null ||
- (position != null && getPosition(fFocusAnnotation) == position) ||
- (position == null && fFocusAnnotation == null))
- return;
-
- LinkedPositionGroup linkedGroup= null;
- if (position != null)
- linkedGroup= env.getGroupForPosition(position);
-
- List targets= new ArrayList();
- targets.addAll(Arrays.asList(fTargets));
-
- List group;
- if (linkedGroup != null)
- group= new ArrayList(Arrays.asList(linkedGroup.getPositions()));
- else
- group= new ArrayList();
-
- if (position == null || !fDocument.equals(position.getDocument()))
- // position is not valid if not in this document
- position= null;
-
- LinkedPosition exit= fExitPosition;
- if (exit == null || !fDocument.equals(exit.getDocument()))
- // position is not valid if not in this document
- exit= null;
-
-
- if (exit != null) {
- group.remove(exit);
- targets.remove(exit);
- }
-
- group.removeAll(targets);
- targets.remove(position);
- group.remove(position);
- prune(targets);
- prune(group);
-
- try {
- setFocusPosition(position);
- setExitPosition(exit);
- setGroupPositions(group);
- setTargetPositions(targets);
- } catch (BadLocationException e) {
- // will never happen as we don't actually add/remove positions from the document
- // see the addPosition / removePosition methods
- Assert.isTrue(false);
- }
- fireModelChanged();
-
- }
-
- /**
- * Prune <code>list</code> of all <code>LinkedPosition</code>s that
- * do not belong to this model's <code>IDocument</code>.
- *
- * @param list the list of positions to prune
- */
- private void prune(List list) {
- for (Iterator iter= list.iterator(); iter.hasNext();) {
- LinkedPosition pos= (LinkedPosition) iter.next();
- if (!pos.getDocument().equals(fDocument))
- iter.remove();
- }
- }
-
- /**
- * Sets the target positions
- * @param positions
- */
- public void setTargets(Position[] positions) {
- fTargets= positions;
- }
-
- /**
- * Sets the exit position.
- *
- * @param position the new exit position, or <code>null</code> if no exit position should be set
- */
- public void setExitTarget(LinkedPosition position) {
- fExitPosition = position;
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationModel#addPosition(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position)
- */
- protected void addPosition(IDocument document, Position position) {
- // don't to anything as our positions are managed by custom
- // position updaters
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationModel#removePosition(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.Position)
- */
- protected void removePosition(IDocument document, Position pos) {
- // don't to anything as our positions are managed by custom
- // position updaters
- }
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationModel#fireModelChanged()
- */
- public void fireModelChanged() {
- super.fireModelChanged();
- }
-
- /**
- * Sets the drawing state for the exit target. Default is <code>true</code>.
- *
- * @param markExitTargets the new drawing state for exit targets
- */
- public void markExitTarget(boolean markExitTargets) {
- fMarkExitTarget= markExitTargets;
- }
-
- /**
- * Sets the drawing state for the focus position. Default is <code>true</code>.
- *
- * @param markFocus the new drawing state for exit targets
- */
- public void markFocus(boolean markFocus) {
- fMarkFocus= markFocus;
- }
-
- /**
- * Sets the drawing state for slave positions. Default is <code>true</code>.
- *
- * @param markSlaves the new drawing state for slaves
- */
- public void markSlaves(boolean markSlaves) {
- fMarkSlaves= markSlaves;
- }
-
- /**
- * Sets the drawing state for targets. Default is <code>true</code>.
- *
- * @param markTargets the new drawing state for targets
- */
- public void markTargets(boolean markTargets) {
- fMarkTargets= markTargets;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/ProposalPosition.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/link/ProposalPosition.java
deleted file mode 100644
index 3d20a2c9702..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/ProposalPosition.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.link;
-
-import java.util.Arrays;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-
-/**
- * LinkedPosition with added completion proposals.
- * <p>
- * Clients may instantiate or extend this class.
- * </p>
- *
- * @since 3.0
- */
-public class ProposalPosition extends LinkedPosition {
-
- /**
- * The proposals
- */
- private ICompletionProposal[] fProposals;
-
- /**
- * Creates a new instance.
- *
- * @param document the document
- * @param offset the offset of the position
- * @param length the length of the position
- * @param sequence the iteration sequence rank
- * @param proposals the proposals to be shown when entering this position
- */
- public ProposalPosition(IDocument document, int offset, int length, int sequence, ICompletionProposal[] proposals) {
- super(document, offset, length, sequence);
- fProposals= proposals;
- }
-
- /**
- * Creates a new instance, with no sequence number.
- *
- * @param document the document
- * @param offset the offset of the position
- * @param length the length of the position
- * @param proposals the proposals to be shown when entering this position
- */
- public ProposalPosition(IDocument document, int offset, int length, ICompletionProposal[] proposals) {
- super(document, offset, length, LinkedPositionGroup.NO_STOP);
- fProposals= proposals;
- }
-
- /*
- * @see java.lang.Object#equals(java.lang.Object)
- */
- public boolean equals(Object o) {
- if (o instanceof ProposalPosition) {
- if (super.equals(o)) {
- return Arrays.equals(fProposals, ((ProposalPosition)o).fProposals);
- }
- }
- return false;
- }
-
- /**
- * Returns the proposals attached to this position.
- *
- * @return an array of choices, including the initial one. Callers must not
- * modify it.
- */
- public ICompletionProposal[] getChoices() {
- return fProposals;
- }
-
- /*
- * @see org.eclipse.jdt.internal.ui.text.link.LinkedPosition#hashCode()
- */
- public int hashCode() {
- return super.hashCode() | (fProposals == null ? 0 : fProposals.hashCode());
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/TabStopIterator.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/link/TabStopIterator.java
deleted file mode 100644
index 51c56c0c37f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/TabStopIterator.java
+++ /dev/null
@@ -1,215 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.link;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.Iterator;
-import java.util.List;
-import java.util.NoSuchElementException;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.link.LinkedPosition;
-
-
-
-/**
- * Iterator that leaps over the double occurrence of an element when switching from forward
- * to backward iteration that is shown by <code>ListIterator</code>.
- * <p>
- * Package private, only for use by LinkedModeUI.
- * </p>
- * @since 3.0
- */
-class TabStopIterator {
- /**
- * Comparator for <code>LinkedPosition</code>s. If the sequence nr. of two positions is equal, the
- * offset is used.
- */
- private static class SequenceComparator implements Comparator {
-
- /**
- * {@inheritDoc}
- *
- * <p><code>o1</code> and <code>o2</code> are required to be instances
- * of <code>LinkedPosition</code>.</p>
- */
- public int compare(Object o1, Object o2) {
- LinkedPosition p1= (LinkedPosition)o1;
- LinkedPosition p2= (LinkedPosition)o2;
- int i= p1.getSequenceNumber() - p2.getSequenceNumber();
- if (i != 0)
- return i;
- else
- return p1.getOffset() - p2.getOffset();
- }
-
- }
-
- /** The comparator to sort the list of positions. */
- private static final Comparator fComparator= new SequenceComparator();
-
- /** The iteration sequence. */
- private final ArrayList fList;
- /** The size of <code>fList</code>. */
- private int fSize;
- /** Index of the current element, to the first one initially. */
- private int fIndex;
- /** Cycling property. */
- private boolean fIsCycling= false;
-
- TabStopIterator(List positionSequence) {
- Assert.isNotNull(positionSequence);
- fList= new ArrayList(positionSequence);
- Collections.sort(fList, fComparator);
- fSize= fList.size();
- fIndex= -1;
- Assert.isTrue(fSize > 0);
- }
-
- boolean hasNext(LinkedPosition current) {
- return getNextIndex(current) != fSize;
- }
-
- private int getNextIndex(LinkedPosition current) {
- if (current != null && fList.get(fIndex) != current)
- return findNext(current);
- else if (fIsCycling && fIndex == fSize - 1)
- return 0;
- else
- // default: increase
- return fIndex + 1;
- }
-
- /**
- * Finds the closest position in the iteration set that follows after
- * <code>current</code> and sets <code>fIndex</code> accordingly. If <code>current</code>
- * is in the iteration set, the next in turn is chosen.
- *
- * @param current the current position
- * @return <code>true</code> if there is a next position, <code>false</code> otherwise
- */
- private int findNext(LinkedPosition current) {
- Assert.isNotNull(current);
- // if the position is in the iteration set, jump to the next one
- int index= fList.indexOf(current);
- if (index != -1) {
- if (fIsCycling && index == fSize - 1)
- return 0;
- else
- return index + 1;
- } else {
- // find the position that follows closest to the current position
- LinkedPosition found= null;
- for (Iterator it= fList.iterator(); it.hasNext(); ) {
- LinkedPosition p= (LinkedPosition) it.next();
- if (p.offset > current.offset)
- if (found == null || found.offset > p.offset)
- found= p;
- }
- if (found != null) {
- return fList.indexOf(found);
- } else if (fIsCycling) {
- return 0;
- } else
- return fSize;
- }
- }
-
- boolean hasPrevious(LinkedPosition current) {
- return getPreviousIndex(current) != -1;
- }
-
- private int getPreviousIndex(LinkedPosition current) {
- if (current != null && fList.get(fIndex) != current)
- return findPrevious(current);
- else if (fIsCycling && fIndex == 0)
- return fSize - 1;
- else
- return fIndex - 1;
- }
-
- /**
- * Finds the closest position in the iteration set that precedes
- * <code>current</code>. If <code>current</code>
- * is in the iteration set, the previous in turn is chosen.
- *
- * @param current the current position
- * @return the index of the previous position
- */
- private int findPrevious(LinkedPosition current) {
- Assert.isNotNull(current);
- // if the position is in the iteration set, jump to the next one
- int index= fList.indexOf(current);
- if (index != -1) {
- if (fIsCycling && index == 0)
- return fSize - 1;
- else
- return index - 1;
- } else {
- // find the position that follows closest to the current position
- LinkedPosition found= null;
- for (Iterator it= fList.iterator(); it.hasNext(); ) {
- LinkedPosition p= (LinkedPosition) it.next();
- if (p.offset < current.offset)
- if (found == null || found.offset < p.offset)
- found= p;
- }
- if (found != null) {
- return fList.indexOf(found);
- } else if (fIsCycling) {
- return fSize - 1;
- } else
- return -1;
- }
- }
-
- LinkedPosition next(LinkedPosition current) {
- if (!hasNext(current))
- throw new NoSuchElementException();
- else
- return (LinkedPosition) fList.get(fIndex= getNextIndex(current));
- }
-
- LinkedPosition previous(LinkedPosition current) {
- if (!hasPrevious(current))
- throw new NoSuchElementException();
- else
- return (LinkedPosition) fList.get(fIndex= getPreviousIndex(current));
- }
-
- void setCycling(boolean mode) {
- fIsCycling= mode;
- }
-
- void addPosition(Position position) {
- fList.add(fSize++, position);
- Collections.sort(fList, fComparator);
- }
-
- void removePosition(Position position) {
- if (fList.remove(position))
- fSize--;
- }
-
- /**
- * @return Returns the isCycling.
- */
- boolean isCycling() {
- return fIsCycling;
- }
-
- LinkedPosition[] getPositions() {
- return (LinkedPosition[]) fList.toArray(new LinkedPosition[0]);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/link/package.html
deleted file mode 100644
index 153941b2c51..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/link/package.html
+++ /dev/null
@@ -1,71 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]"
- name="GENERATOR">
- <title>Linked Position Infrastructure</title>
-</head>
-<body>
-Application programming interfaces for interaction
-with the Eclipse Java User Interface text support.
-<h2>Linked Position Infrastructure</h2>
-<h3>package <span style="font-family: monospace;">org.eclipse.jface.text.link
-</span><span style="font-family: monospace;"></span></h3>
-<h3><code></code></h3>
-The Linked Position Infrastructure lets one set up a mode in an editor
-in which regions in a document (or several documents) are <em>linked</em>,
-i.e. editions
-of one linked position will be reflected in the others.
-<h4>Classes</h4>
-<ul>
- <li><code>LinkedPositionGroup</code>: a set of linked positions. Add
-positions to a group using the <code>addPosition</code> method. See <span
- style="font-family: monospace;">LinkedPosition</span><code><span
- style="font-family: helvetica,arial,sans-serif;"> and</span></code> <span
- style="font-family: monospace;">ProposalPosition</span><code><span
- style="font-family: helvetica,arial,sans-serif;"> </span></code><span
- style="font-family: helvetica,arial,sans-serif;">for a position type
-that lets one attach </span><span style="font-family: monospace;">ICompletionProposals</span><span
- style="font-family: monospace;"></span><span
- style="font-family: helvetica,arial,sans-serif;"> </span><span
- style="font-family: helvetica,arial,sans-serif;">to</span>
-be shown when the position is hit.</li>
- <li><code>LinkedModeModel</code>: umbrellas several <code>LinkedPositionGroup</code>s,
-e.g. in a template that has several groups of linked positions. Handles
-the forwarding of updates received via an IDocumentListener. Add <code>LinkedPositionGroup</code>s
-to
-an model using the <code>addGroup</code> method. Existence of a <span
- style="font-family: monospace;">LinkedModeModel </span>can be
-tested by one of the static methods.<br>
- </li>
- <li><code>LinkedModeUI</code>: The UI for linked mode (for one
-model, to be precise). Monitors key etc. activity, monitors exit
-conditions, creates a painter etc. <br>
-Properties:
- <ul>
- <li><b>cycling mode</b> (whether to jump to the first position
-after the last): either of <code>CYCLE_ALWAYS</code>, <code>CYCLE_NEVER</code>
-and <code>CYCLE_WHEN_NO_PARENT</code> (default).</li>
- <li><b>exit position</b>: where to jump upon leaving the linked
-mode (e.g. using Enter, or Tab from the last position when not
-cycling). Set <code>isTabStop</code> to <code>true</code> if tabbing
-should stop over when cycling.</li>
- <li><span style="font-weight: bold;">position listener</span>:
-extending classes may register a position listener which will get
-notified whenever
-the focus position changes. An example is <span
- style="font-family: monospace;">org.eclipse.ui.texteditor.link.EditorLinkedModeUI.EditorHistoryUpdater</span>
-which will store the edit location in the editor navigation history.<br>
- </li>
- </ul>
- </li>
-.
-</ul>
-<h4>Example</h4>
-<pre> IDocument doc1, doc2;<br> ITextViewer viewer1, viewer2;<br> <br> /* create groups - this step is independent of the linked mode */<br> LinkedPositionGroup group1= new LinkedPositionGroup();<br> group1.addPosition(new LinkedPosition(doc1, 3, 4));<br> group1.addPosition(new LinkedPosition(doc1, 7, 8));<br> <br> LinkedPositionGroup group2= new LinkedPositionGroup();<br> group2.addPosition(new LinkedPosition(doc1, 15, 25));<br> group2.addPosition(new LinkedPosition(doc2, 0, 10));<br> <br> /* set up linked mode */<br> LinkedModeModel model= new LinkedModeModel();<br> model.addGroup(group1);<br> model.addGroup(group2);<br> model.forceInstall();<br> <br> /* create UI */<br> LinkedModeUI ui= new LinkedModeUI(model, new ITextViewer[] { viewer1, viewer2 });<br> ui.enter();<span
- style="font-family: sans-serif;"><br><br></span></pre>
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/package.html
deleted file mode 100644
index 5561c3748e5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/package.html
+++ /dev/null
@@ -1,82 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a framework for creating, manipulating, displaying
-and editing text documents.
-<h2>
-Package Specification</h2>
-The packages is divided into two parts. The first part defines and implements
-the notion of text documents, whereas the second part defines and implements
-a viewer for text documents.
-<h3>
-Text Model</h3>
-<tt>IDocument</tt> is the major text model abstraction. It provides content
-management, position management using position categories, document partition
-management, searching, and change notification.&nbsp; In order to be notified
-about document changes, an object must implements <tt>IDocumentListener</tt>
-and must be registered with the document. Position updating in responds
-to a document change is performed by implementers of <tt>IDocumentPositionUpdater</tt>.
-Partition updating in responds to a document change is performed by implements
-of <tt>IDocumentPartitioner</tt>. In order to be notified about document
-partition changes, objects must implement <tt>IDocumentParititoningListener</tt>
-and must be registered with the document.
-<p>The package contains default implementations for document position updaters
-and for documents. <tt>AbstractDocument</tt> uses <tt>ITextStorage</tt>
-for storing and managing its content and <tt>ILineTracker</tt> to maintain
-a line structure of its content. As defaults a gap text implementation
-of <tt>ITextStore</tt> is provided, together with a line tracker understanding
-the three standard line delimiters ("\r", "\n", "\r\n") and a&nbsp; line
-tracker which can be freely configured to consider any given set of strings
-as valid line delimiters.
-<h3>
-Text Viewer</h3>
-<tt>ITextViewer</tt> defines the concept of a document based, editiable
-viewer. <tt>ITextViewer</tt> offers the following functionality:
-<ul>
-<li>
-present a document</li>
-
-<li>
-event consumption (<tt>IEventConsumer</tt>)</li>
-
-<li>
-viewport tracking and notification (<tt>IIViewportListener</tt>)</li>
-
-<li>
-change notification (<tt>ITextListener</tt>, <tt>ITextInputListener</tt>)</li>
-
-<li>
-listeners (combined view/model notification, input document)</li>
-
-<li>
-standard text editing functions plus text hover support</li>
-
-<li>
-visual region support</li>
-</ul>
-An ITextViewer supports the following plugins
-<ul>
-<li>
-<tt>IUndoManager</tt> for the undo/redo mechanism</li>
-
-<li>
-<tt>IDoubleClickStrategy</tt> for partition type specific behavior on mouse
-double click</li>
-
-<li>
-<tt>IAutoIndentStrategy</tt>&nbsp; for content type specific behavior on
-inserting a line break</li>
-
-<li>
-<tt>ITextHover</tt> for content type specific behavior when overing over
-text</li>
-</ul>
-The package provides default implementations for all these interfaces.
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java
deleted file mode 100644
index ba67aa67845..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationDamager.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.presentation;
-
-
-
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-
-
-/**
- * Presentation damagers are used by a presentation reconciler to determine the
- * region of the document's presentation which must be rebuilt because of the
- * occurrence of a document change. A presentation damager is assumed to be
- * specific for a particular document content type. A presentation damager is
- * expected to return a damage region which is a valid input for a presentation repairer.
- * I.e. having access to the damage region only the repairer must be able to derive
- * all the information needed to successfully repair this region.<p>
- * This interface must either be implemented by clients or clients use the rule-based
- * default implementation <code>RuleBasedDamagerRepairer</code>. Implementers should be
- * registered with a presentation reconciler in order get involved in the reconciling
- * process.
- *
- * @see IPresentationReconciler
- * @see IDocument
- * @see DocumentEvent
- * @see IPresentationRepairer
- */
-public interface IPresentationDamager {
-
- /**
- * Tells the presentation damager on which document it will work.
- *
- * @param document the damager's working document
- */
- void setDocument(IDocument document);
-
- /**
- * Returns the damage in the document's presentation caused by the given document change.
- * The damage is restricted to the specified partition for which the presentation damager is
- * responsible. The damage may also depend on whether the document change also caused changes
- * of the document's partitioning.
- *
- * @param partition the partition inside which the damage must be determined
- * @param event the event describing the change whose damage must be determined
- * @param documentPartitioningChanged indicates whether the given change changed the document's partitioning
- * @return the computed damage
- */
- IRegion getDamageRegion(ITypedRegion partition, DocumentEvent event, boolean documentPartitioningChanged);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java
deleted file mode 100644
index 6314b3203cd..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconciler.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.presentation;
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * An <code>IPresentationReconciler</code> defines and maintains the representation of a
- * text viewer's document in the presence of changes applied to the document.
- * An <code>IPresentationReconciler</code> is a <code>ITextViewer</code> add-on.<p>
- * The presentation reconciler keeps track of changes applied to the text viewer. It sends
- * each change to presentation damagers which are registered for the content types of the
- * regions in which the change occurred. The presentation reconciler passes the computed
- * damage to presentation repairers which construct text presentations. Those text presentation
- * when applied to the presentation reconciler's text viewer bring the document's presentation
- * in sync with the document's content and thus repair the damage. A presentation damager
- * is expected to return damage which is a valid input for a presentation repairer registered
- * for the same content type as the damager.<p>
- * A presentation reconciler should always be configured with damager/repairer pairs. I.e.
- * for each damager there should be a corresponding repairer.<p>
- * The interface can be implemented by clients. By default, clients use
- * <code>PresentationReconciler</code> as the standard implementer of this interface.
- *
- * @see ITextViewer
- * @see IPresentationDamager
- * @see IPresentationRepairer
- * @see org.eclipse.jface.text.TextPresentation
- */
-public interface IPresentationReconciler {
-
- /**
- * Installs this presentation reconciler on the given text viewer. After
- * this method has been finished, the reconciler is operational. I.e., it
- * works without requesting further client actions until <code>uninstall</code>
- * is called.
- *
- * @param viewer the viewer on which this presentation reconciler is installed
- */
- void install(ITextViewer viewer);
-
- /**
- * Removes the reconciler from the text viewer it has previously been
- * installed on.
- */
- void uninstall();
-
- /**
- * Returns the presentation damager registered with this presentation reconciler
- * for the specified content type.
- *
- * @param contentType the content type for which to determine the damager
- * @return the presentation damager registered for the given content type, or
- * <code>null</code> if there is no such strategy
- */
- IPresentationDamager getDamager(String contentType);
-
- /**
- * Returns the presentation repairer registered with this presentation reconciler
- * for the specified content type.
- *
- * @param contentType the content type for which to determine the repairer
- * @return the presentation repairer registered for the given content type, or
- * <code>null</code> if there is no such strategy
- */
- IPresentationRepairer getRepairer(String contentType);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java
deleted file mode 100644
index 28d7b631a1b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationReconcilerExtension.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.presentation;
-
-/**
- * Extension interface for <code>IPresentationReconciler</code>.
- * Updates the presentation reconciler to be aware of documents with multiple partitions.
- *
- * @since 3.0
- */
-public interface IPresentationReconcilerExtension {
-
- /**
- * Returns the document partitioning this presentation reconciler is using.
- *
- * @return the document partitioning this presentation reconciler is using
- */
- String getDocumentPartitioning();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java
deleted file mode 100644
index 8703f43bc06..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/IPresentationRepairer.java
+++ /dev/null
@@ -1,56 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.presentation;
-
-
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.TextPresentation;
-
-
-/**
- * Presentation repairers are used by a presentation reconciler
- * to rebuild a damaged region in a document's presentation. A presentation repairer
- * is assumed to be specific for a particular document content type. The presentation
- * repairer gets the region which it should repair and constructs a "repair description"
- * The presentation repairer adds the individual steps of this sequence into the
- * text presentation it gets passed in.<p>
- * This interface must either be implemented by clients or clients use the rule-based
- * default implementation <code>RuleBasedDamagerRepairer</code>. Implementers should be
- * registered with a presentation reconciler in order get involved in the reconciling
- * process.
- *
- * @see IPresentationReconciler
- * @see IDocument
- * @see org.eclipse.swt.custom.StyleRange
- * @see TextPresentation
- */
-public interface IPresentationRepairer {
-
-
- /**
- * Tells the presentation repairer on which document it will work.
- *
- * @param document the damager's working document
- */
- void setDocument(IDocument document);
-
- /**
- * Fills the given presentation with the style ranges which when applied to the
- * presentation reconciler's text viewer repair the presentational damage described by
- * the given region.
- *
- * @param presentation the text presentation to be filled by this repairer
- * @param damage the damage to be repaired
- */
- void createPresentation(TextPresentation presentation, ITypedRegion damage);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
deleted file mode 100644
index be85ba76494..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/PresentationReconciler.java
+++ /dev/null
@@ -1,583 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.presentation;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.swt.custom.StyleRange;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.DocumentPartitioningChangedEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.IDocumentPartitioningListener;
-import org.eclipse.jface.text.IDocumentPartitioningListenerExtension;
-import org.eclipse.jface.text.IDocumentPartitioningListenerExtension2;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.TypedPosition;
-
-
-
-/**
- * Standard implementation of <code>IPresentationReconciler</code>.
- * This implementation assumes that the tasks performed by its
- * presentation damagers and repairers are lightweight and of low cost.
- * This presentation reconciler runs in the UI thread and always repairs
- * the complete damage caused by a document change rather than just the
- * portion overlapping with the viewer's viewport.<p>
- * Usually, clients instantiate this class and configure it before using it.
- */
-public class PresentationReconciler implements IPresentationReconciler, IPresentationReconcilerExtension {
-
- /** Prefix of the name of the position category for tracking damage regions. */
- protected final static String TRACKED_PARTITION= "__reconciler_tracked_partition"; //$NON-NLS-1$
-
-
- /**
- * Internal listener class.
- */
- class InternalListener implements
- ITextInputListener, IDocumentListener, ITextListener,
- IDocumentPartitioningListener, IDocumentPartitioningListenerExtension, IDocumentPartitioningListenerExtension2 {
-
- /** Set to <code>true</code> if between a document about to be changed and a changed event. */
- private boolean fDocumentChanging= false;
- /**
- * The cached redraw state of the text viewer.
- * @since 3.0
- */
- private boolean fCachedRedrawState= true;
-
- /*
- * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldDocument, IDocument newDocument) {
- if (oldDocument != null) {
- try {
-
- fViewer.removeTextListener(this);
- oldDocument.removeDocumentListener(this);
- oldDocument.removeDocumentPartitioningListener(this);
-
- oldDocument.removePositionUpdater(fPositionUpdater);
- oldDocument.removePositionCategory(fPositionCategory);
-
- } catch (BadPositionCategoryException x) {
- // should not happend for former input documents;
- }
- }
- }
-
- /*
- * @see ITextInputListener#inputDocumenChanged(IDocument, IDocument)
- */
- public void inputDocumentChanged(IDocument oldDocument, IDocument newDocument) {
-
- fDocumentChanging= false;
- fCachedRedrawState= true;
-
- if (newDocument != null) {
-
- newDocument.addPositionCategory(fPositionCategory);
- newDocument.addPositionUpdater(fPositionUpdater);
-
- newDocument.addDocumentPartitioningListener(this);
- newDocument.addDocumentListener(this);
- fViewer.addTextListener(this);
-
- setDocumentToDamagers(newDocument);
- setDocumentToRepairers(newDocument);
- processDamage(new Region(0, newDocument.getLength()), newDocument);
- }
- }
-
- /*
- * @see IDocumentPartitioningListener#documentPartitioningChanged(IDocument)
- */
- public void documentPartitioningChanged(IDocument document) {
- if (!fDocumentChanging && fCachedRedrawState)
- processDamage(new Region(0, document.getLength()), document);
- else
- fDocumentPartitioningChanged= true;
- }
-
- /*
- * @see IDocumentPartitioningListenerExtension#documentPartitioningChanged(IDocument, IRegion)
- * @since 2.0
- */
- public void documentPartitioningChanged(IDocument document, IRegion changedRegion) {
- if (!fDocumentChanging && fCachedRedrawState) {
- processDamage(new Region(changedRegion.getOffset(), changedRegion.getLength()), document);
- } else {
- fDocumentPartitioningChanged= true;
- fChangedDocumentPartitions= changedRegion;
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitioningListenerExtension2#documentPartitioningChanged(org.eclipse.jface.text.DocumentPartitioningChangedEvent)
- * @since 3.0
- */
- public void documentPartitioningChanged(DocumentPartitioningChangedEvent event) {
- IRegion changedRegion= event.getChangedRegion(getDocumentPartitioning());
- if (changedRegion != null)
- documentPartitioningChanged(event.getDocument(), changedRegion);
- }
-
- /*
- * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent e) {
-
- fDocumentChanging= true;
- if (fCachedRedrawState) {
- try {
- int offset= e.getOffset() + e.getLength();
- ITypedRegion region= getPartition(e.getDocument(), offset);
- fRememberedPosition= new TypedPosition(region);
- e.getDocument().addPosition(fPositionCategory, fRememberedPosition);
- } catch (BadLocationException x) {
- // can not happen
- } catch (BadPositionCategoryException x) {
- // should not happen on input elements
- }
- }
- }
-
- /*
- * @see IDocumentListener#documentChanged(DocumentEvent)
- */
- public void documentChanged(DocumentEvent e) {
- if (fCachedRedrawState) {
- try {
- e.getDocument().removePosition(fPositionCategory, fRememberedPosition);
- } catch (BadPositionCategoryException x) {
- // can not happen on input documents
- }
- }
- fDocumentChanging= false;
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent e) {
-
- fCachedRedrawState= e.getViewerRedrawState();
- if (!fCachedRedrawState)
- return;
-
- IRegion damage= null;
- IDocument document= null;
-
- if (e.getDocumentEvent() == null) {
- document= fViewer.getDocument();
- if (document != null) {
- if (e.getOffset() == 0 && e.getLength() == 0 && e.getText() == null) {
- // redraw state change, damage the whole document
- damage= new Region(0, document.getLength());
- } else {
- IRegion region= widgetRegion2ModelRegion(e);
- try {
- String text= document.get(region.getOffset(), region.getLength());
- DocumentEvent de= new DocumentEvent(document, region.getOffset(), region.getLength(), text);
- damage= getDamage(de, false);
- } catch (BadLocationException x) {
- }
- }
- }
- } else {
- DocumentEvent de= e.getDocumentEvent();
- document= de.getDocument();
- damage= getDamage(de, true);
- }
-
- if (damage != null && document != null)
- processDamage(damage, document);
-
- fDocumentPartitioningChanged= false;
- fChangedDocumentPartitions= null;
- }
-
- /**
- * Translates the given text event into the corresponding range of the viewer's document.
- *
- * @param e the text event
- * @return the widget region corresponding the region of the given event
- * @since 2.1
- */
- protected IRegion widgetRegion2ModelRegion(TextEvent e) {
-
- String text= e.getText();
- int length= text == null ? 0 : text.length();
-
- if (fViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fViewer;
- return extension.widgetRange2ModelRange(new Region(e.getOffset(), length));
- }
-
- IRegion visible= fViewer.getVisibleRegion();
- IRegion region= new Region(e.getOffset() + visible.getOffset(), length);
- return region;
- }
- }
-
- /** The map of presentation damagers. */
- private Map fDamagers;
- /** The map of presentation repairers. */
- private Map fRepairers;
- /** The target viewer. */
- private ITextViewer fViewer;
- /** The internal listener. */
- private InternalListener fInternalListener= new InternalListener();
- /** The name of the position category to track damage regions. */
- private String fPositionCategory;
- /** The position updated for the damage regions' position category. */
- private IPositionUpdater fPositionUpdater;
- /** The positions representing the damage regions. */
- private TypedPosition fRememberedPosition;
- /** Flag indicating the receipt of a partitioning changed notification. */
- private boolean fDocumentPartitioningChanged= false;
- /** The range covering the changed partitioning. */
- private IRegion fChangedDocumentPartitions= null;
- /**
- * The partitioning used by this presentation reconciler.
- * @since 3.0
- */
- private String fPartitioning;
-
- /**
- * Creates a new presentation reconciler. There are no damagers or repairers
- * registered with this reconciler. The default partitioning
- * <code>IDocumentExtension3.DEFAULT_PARTITIONING</code> is used.
- */
- public PresentationReconciler() {
- super();
- fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
- fPositionCategory= TRACKED_PARTITION + hashCode();
- fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
- }
-
- /**
- * Sets the document partitioning for this presentation reconciler.
- *
- * @param partitioning the document partitioning for this presentation reconciler.
- * @since 3.0
- */
- public void setDocumentPartitioning(String partitioning) {
- Assert.isNotNull(partitioning);
- fPartitioning= partitioning;
- }
-
- /*
- * @see org.eclipse.jface.text.presentation.IPresentationReconcilerExtension#geDocumenttPartitioning()
- * @since 3.0
- */
- public String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- /**
- * Registers a given presentation damager for a particular content type.
- * If there is already a damager registered for this type, the new damager
- * is registered instead of the old one.
- *
- * @param damager the presentation damager to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setDamager(IPresentationDamager damager, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fDamagers == null)
- fDamagers= new HashMap();
-
- if (damager == null)
- fDamagers.remove(contentType);
- else
- fDamagers.put(contentType, damager);
- }
-
- /**
- * Registers a given presentation repairer for a particular content type.
- * If there is already a repairer registered for this type, the new repairer
- * is registered instead of the old one.
- *
- * @param repairer the presentation repairer to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setRepairer(IPresentationRepairer repairer, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fRepairers == null)
- fRepairers= new HashMap();
-
- if (repairer == null)
- fRepairers.remove(contentType);
- else
- fRepairers.put(contentType, repairer);
- }
-
- /*
- * @see IPresentationReconciler#install(ITextViewer)
- */
- public void install(ITextViewer viewer) {
- Assert.isNotNull(viewer);
-
- fViewer= viewer;
- fViewer.addTextInputListener(fInternalListener);
- }
-
- /*
- * @see IPresentationReconciler#uninstall()
- */
- public void uninstall() {
- fViewer.removeTextInputListener(fInternalListener);
-
- // Ensure we uninstall all listeners
- fInternalListener.inputDocumentAboutToBeChanged(fViewer.getDocument(), null);
- }
-
- /*
- * @see IPresentationReconciler#getDamager(String)
- */
- public IPresentationDamager getDamager(String contentType) {
-
- if (fDamagers == null)
- return null;
-
- return (IPresentationDamager) fDamagers.get(contentType);
- }
-
- /*
- * @see IPresentationReconciler#getRepairer(String)
- */
- public IPresentationRepairer getRepairer(String contentType) {
-
- if (fRepairers == null)
- return null;
-
- return (IPresentationRepairer) fRepairers.get(contentType);
- }
-
- /**
- * Informs all registed damagers about the document on which they will work.
- *
- * @param document the document on which to work
- */
- protected void setDocumentToDamagers(IDocument document) {
- if (fDamagers != null) {
- Iterator e= fDamagers.values().iterator();
- while (e.hasNext()) {
- IPresentationDamager damager= (IPresentationDamager) e.next();
- damager.setDocument(document);
- }
- }
- }
-
- /**
- * Informs all registed repairers about the document on which they will work.
- *
- * @param document the document on which to work
- */
- protected void setDocumentToRepairers(IDocument document) {
- if (fRepairers != null) {
- Iterator e= fRepairers.values().iterator();
- while (e.hasNext()) {
- IPresentationRepairer repairer= (IPresentationRepairer) e.next();
- repairer.setDocument(document);
- }
- }
- }
-
- /**
- * Constructs a "repair description" for the given damage and returns
- * this description as a text presentation. For this, it queries the
- * partitioning of the damage region and asks for each partition an
- * appropriate presentation repairer to construct the "repair description"
- * for this partition.
- *
- * @param damage the damage to be repaired
- * @param document the document whose presentation must be repaired
- * @return the presentation repair description as text presentation
- */
- protected TextPresentation createPresentation(IRegion damage, IDocument document) {
- try {
- if (fRepairers == null || fRepairers.isEmpty()) {
- TextPresentation presentation= new TextPresentation(damage, 1);
- presentation.setDefaultStyleRange(new StyleRange(damage.getOffset(), damage.getLength(), null, null));
- return presentation;
- }
-
- TextPresentation presentation= new TextPresentation(damage, 1000);
-
- ITypedRegion[] partitioning= TextUtilities.computePartitioning(document, getDocumentPartitioning(), damage.getOffset(), damage.getLength(), false);
- for (int i= 0; i < partitioning.length; i++) {
- ITypedRegion r= partitioning[i];
- IPresentationRepairer repairer= getRepairer(r.getType());
- if (repairer != null)
- repairer.createPresentation(presentation, r);
- }
-
- return presentation;
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
-
- /**
- * Checks for the first and the last affected partition and calls their damagers.
- * Invalidates everything from the start of the damage for the first partition
- * until the end of the damage for the last partition.
- *
- * @param e the event describing the document change
- * @param optimize <code>true</code> if partition changes should be considered for optimization
- * @return the damaged caused by the change
- * @since 3.0
- */
- private IRegion getDamage(DocumentEvent e, boolean optimize) {
-
- if (fDamagers == null || fDamagers.isEmpty()) {
- int length= e.getText() == null ? 0 : e.getText().length();
- length= Math.max(e.getLength(), length);
- length= Math.min(e.getDocument().getLength() - e.getOffset(), length);
- return new Region(e.getOffset(), length);
- }
-
- IRegion damage= null;
-
- try {
-
- ITypedRegion partition= getPartition(e.getDocument(), e.getOffset());
- IPresentationDamager damager= getDamager(partition.getType());
- if (damager == null)
- return null;
-
- IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
-
- if (!fDocumentPartitioningChanged && optimize) {
- damage= r;
- } else {
-
- int damageEnd= getDamageEndOffset(e);
-
- int parititionDamageEnd= -1;
- if (fChangedDocumentPartitions != null)
- parititionDamageEnd= fChangedDocumentPartitions.getOffset() + fChangedDocumentPartitions.getLength();
-
- int end= Math.max(damageEnd, parititionDamageEnd);
-
- damage= end == -1 ? r : new Region(r.getOffset(), end - r.getOffset());
- }
-
- } catch (BadLocationException x) {
- }
-
- return damage;
- }
-
- /**
- * Returns the end offset of the damage. If a partition has been splitted by
- * the given document event also the second half of the original
- * partition must be considered. This is achieved by using the remembered
- * partition range.
- *
- * @param e the event describing the change
- * @return the damage end offset (excluding)
- * @exception BadLocationException if method accesses invalid offset
- */
- private int getDamageEndOffset(DocumentEvent e) throws BadLocationException {
-
- IDocument d= e.getDocument();
-
- int length= 0;
- if (e.getText() != null) {
- length= e.getText().length();
- if (length > 0)
- -- length;
- }
-
- ITypedRegion partition= getPartition(d, e.getOffset() + length);
- int endOffset= partition.getOffset() + partition.getLength();
- if (endOffset == e.getOffset())
- return -1;
-
- int end= fRememberedPosition == null ? -1 : fRememberedPosition.getOffset() + fRememberedPosition.getLength();
- if (endOffset < end)
- partition= getPartition(d, end);
-
- IPresentationDamager damager= getDamager(partition.getType());
- if (damager == null)
- return -1;
-
- IRegion r= damager.getDamageRegion(partition, e, fDocumentPartitioningChanged);
-
- return r.getOffset() + r.getLength();
- }
-
- /**
- * Processes the given damage.
- * @param damage the damage to be repaired
- * @param document the document whose presentation must be repaired
- */
- private void processDamage(IRegion damage, IDocument document) {
- if (damage != null && damage.getLength() > 0) {
- TextPresentation p= createPresentation(damage, document);
- if (p != null)
- applyTextRegionCollection(p);
- }
- }
-
- /**
- * Applies the given text presentation to the text viewer the presentation
- * reconciler is installed on.
- *
- * @param presentation the text presentation to be applied to the text viewer
- */
- private void applyTextRegionCollection(TextPresentation presentation) {
- fViewer.changeTextPresentation(presentation, false);
- }
-
- /**
- * Returns the partition for the given offset in the given document.
- *
- * @param document the document
- * @param offset the offset
- * @return the partition
- * @throws BadLocationException if offset is invalid in the given document
- * @since 3.0
- */
- private ITypedRegion getPartition(IDocument document, int offset) throws BadLocationException {
- return TextUtilities.getPartition(document, getDocumentPartitioning(), offset, false);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/package.html
deleted file mode 100644
index 9574694de4e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/presentation/package.html
+++ /dev/null
@@ -1,24 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a presentation reconciler add-on for an <tt>ITextViewer</tt>.
-A presentation reconciler keep the presentation (styles and colors) in
-sync with the content of the document serving as the <tt>ITextViewer</tt>'s
-input.
-<h2>
-Package Specification</h2>
-<tt>IPresentationReconciler</tt> defines the concept of a presentation
-reconciler. It collaborates with content type specific presentation damagers
-(<tt>IPresentationDamager</tt>) which for a given document change determine
-the region of the presentation which must be rebuild, and content type
-specific presentation repairers (<tt>IPresentationRepairer</tt>) which
-construct for a given damage region the document presentation. The package
-contains a default implementation of <tt>IPresentationReconciler </tt>(<tt>PresentationReconciler</tt>).
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconcileStep.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconcileStep.java
deleted file mode 100644
index 925d755350e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconcileStep.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-
-/**
- * Abstract implementation of a reconcile step.
- *
- * @see org.eclipse.jface.text.reconciler.IReconcileStep
- * @since 3.0
- */
-public abstract class AbstractReconcileStep implements IReconcileStep {
-
- private IReconcileStep fNextStep;
- private IReconcileStep fPreviousStep;
- private IProgressMonitor fProgressMonitor;
- protected IReconcilableModel fInputModel;
-
- /**
- * Creates an intermediate reconcile step which adds
- * the given step to the pipe.
- *
- * @param step the reconcile step
- */
- public AbstractReconcileStep(IReconcileStep step) {
- Assert.isNotNull(step);
- fNextStep= step;
- fNextStep.setPreviousStep(this);
- }
-
- /**
- * Creates the last reconcile step of the pipe.
- */
- public AbstractReconcileStep() {
- }
-
- public boolean isLastStep() {
- return fNextStep == null;
- }
-
- public boolean isFirstStep() {
- return fPreviousStep == null;
- }
-
- /*
- * @see org.eclipse.text.reconcilerpipe.IReconcilerResultCollector#setProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor= monitor;
-
- if (!isLastStep())
- fNextStep.setProgressMonitor(monitor);
- }
-
- /*
- * @see org.eclipse.jface.text.reconciler.IReconcileStep#getProgressMonitor()
- */
- public IProgressMonitor getProgressMonitor() {
- return fProgressMonitor;
- }
-
- /*
- * @see IReconcileStep#reconcile(IRegion)
- */
- public final IReconcileResult[] reconcile(IRegion partition) {
- IReconcileResult[] result= reconcileModel(null, partition);
- if (!isLastStep()) {
- fNextStep.setInputModel(getModel());
- IReconcileResult[] nextResult= fNextStep.reconcile(partition);
- return merge(result, convertToInputModel(nextResult));
- } else
- return result;
- }
-
- /*
- * @see IReconcileStep#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
- */
- public final IReconcileResult[] reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
- IReconcileResult[] result= reconcileModel(dirtyRegion, subRegion);
- if (!isLastStep()) {
- fNextStep.setInputModel(getModel());
- IReconcileResult[] nextResult= fNextStep.reconcile(dirtyRegion, subRegion);
- return merge(result, convertToInputModel(nextResult));
- } else
- return result;
- }
-
-
- /**
- * Reconciles the model of this reconcile step. The
- * result is based on the input model.
- *
- * @param dirtyRegion the document region which has been changed
- * @param subRegion the sub region in the dirty region which should be reconciled
- * @return an array with reconcile results
- */
- abstract protected IReconcileResult[] reconcileModel(DirtyRegion dirtyRegion, IRegion subRegion);
-
- protected IReconcileResult[] convertToInputModel(IReconcileResult[] inputResults) {
- return inputResults;
- }
-
- private IReconcileResult[] merge(IReconcileResult[] results1, IReconcileResult[] results2) {
- if (results1 == null)
- return results2;
-
- if (results2 == null)
- return results1;
-
- // XXX: not yet performance optimized
- Collection collection= new ArrayList(Arrays.asList(results1));
- collection.addAll(Arrays.asList(results2));
- return (IReconcileResult[])collection.toArray(new IReconcileResult[collection.size()]);
- }
-
- /*
- * @see IProgressMonitor#isCanceled()
- */
- protected final boolean isCanceled() {
- return fProgressMonitor != null && fProgressMonitor.isCanceled();
- }
-
- /*
- * @see IReconcileStep#setPreviousStep(IReconcileStep)
- */
- public void setPreviousStep(IReconcileStep step) {
- Assert.isNotNull(step);
- Assert.isTrue(fPreviousStep == null);
- fPreviousStep= step;
- }
-
- /*
- * @see IReconcileStep#setInputModel(Object)
- */
- public void setInputModel(IReconcilableModel inputModel) {
- fInputModel= inputModel;
-
- if (!isLastStep())
- fNextStep.setInputModel(getModel());
- }
-
- public IReconcilableModel getInputModel() {
- return fInputModel;
- }
-
- abstract public IReconcilableModel getModel();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java
deleted file mode 100644
index ee785bc79ba..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/AbstractReconciler.java
+++ /dev/null
@@ -1,544 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentListener;
-import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextViewer;
-
-
-
-
-/**
- * Abstract implementation of <code>IReconciler</code>. The reconciler
- * listens to input document changes as well as changes of
- * the input document of the text viewer it is installed on. Depending on
- * its configuration it manages the received change notifications in a
- * queue folding neighboring or overlapping changes together. The reconciler
- * processes the dirty regions as a background activity after having waited for further
- * changes for the configured duration of time. A reconciler is started using its
- * <code>install</code> method. As a first step <code>initialProcess</code> is
- * executed in the background. Then, the reconciling thread waits for changes that
- * need to be reconciled. A reconciler can be resumed by calling <code>forceReconciling</code>
- * independent from the existence of actual changes. This mechanism is for subclasses only.
- * It is the clients responsibility to stop a reconciler using its <code>uninstall</code>
- * method. Unstopped reconcilers do not free their resources.<p>
- * It is subclass responsibility to specify how dirty regions are processed.
- *
- * @see IReconciler
- * @see IDocumentListener
- * @see ITextInputListener
- * @see DirtyRegion
- * @since 2.0
- */
-abstract public class AbstractReconciler implements IReconciler {
-
-
- /**
- * Background thread for the reconciling activity.
- */
- class BackgroundThread extends Thread {
-
- /** Has the reconciler been canceled. */
- private boolean fCanceled= false;
- /** Has the reconciler been reset. */
- private boolean fReset= false;
- /** Some changes need to be processed. */
- private boolean fIsDirty= false;
- /** Is a reconciling strategy active. */
- private boolean fIsActive= false;
-
- /**
- * Creates a new background thread. The thread
- * runs with minimal priority.
- *
- * @param name the thread's name
- */
- public BackgroundThread(String name) {
- super(name);
- setPriority(Thread.MIN_PRIORITY);
- setDaemon(true);
- }
-
- /**
- * Returns whether a reconciling strategy is active right now.
- *
- * @return <code>true</code> if a activity is active
- */
- public boolean isActive() {
- return fIsActive;
- }
-
- /**
- * Returns whether some changes need to be processed.
- *
- * @return <code>true</code> if changes wait to be processed
- */
- public synchronized boolean isDirty() {
- return fIsDirty;
- }
-
- /**
- * Cancels the background thread.
- */
- public void cancel() {
- fCanceled= true;
- IProgressMonitor pm= fProgressMonitor;
- if (pm != null)
- pm.setCanceled(true);
- synchronized (fDirtyRegionQueue) {
- fDirtyRegionQueue.notifyAll();
- }
- }
-
- /**
- * Suspends the caller of this method until this background thread has
- * emptied the dirty region queue.
- */
- public void suspendCallerWhileDirty() {
- boolean isDirty;
- do {
- synchronized (fDirtyRegionQueue) {
- isDirty= fDirtyRegionQueue.getSize() > 0;
- if (isDirty) {
- try {
- fDirtyRegionQueue.wait();
- } catch (InterruptedException x) {
- }
- }
- }
- } while (isDirty);
- }
-
- /**
- * Reset the background thread as the text viewer has been changed,
- */
- public void reset() {
-
- if (fDelay > 0) {
-
- synchronized (this) {
- fIsDirty= true;
- fReset= true;
- }
-
- } else {
-
- synchronized (this) {
- fIsDirty= true;
- }
-
- synchronized (fDirtyRegionQueue) {
- fDirtyRegionQueue.notifyAll();
- }
- }
-
- reconcilerReset();
- }
-
- /**
- * The background activity. Waits until there is something in the
- * queue managing the changes that have been applied to the text viewer.
- * Removes the first change from the queue and process it.<p>
- * Calls <code>initialProcess</code> on entrance.
- */
- public void run() {
-
- synchronized (fDirtyRegionQueue) {
- try {
- fDirtyRegionQueue.wait(fDelay);
- } catch (InterruptedException x) {
- }
- }
-
- initialProcess();
-
- while (!fCanceled) {
-
- synchronized (fDirtyRegionQueue) {
- try {
- fDirtyRegionQueue.wait(fDelay);
- } catch (InterruptedException x) {
- }
- }
-
- if (fCanceled)
- break;
-
- if (!isDirty())
- continue;
-
- synchronized (this) {
- if (fReset) {
- fReset= false;
- continue;
- }
- }
-
- DirtyRegion r= null;
- synchronized (fDirtyRegionQueue) {
- r= fDirtyRegionQueue.removeNextDirtyRegion();
- }
-
- fIsActive= true;
-
- if (fProgressMonitor != null)
- fProgressMonitor.setCanceled(false);
-
- process(r);
-
- synchronized (fDirtyRegionQueue) {
- if (0 == fDirtyRegionQueue.getSize()) {
- synchronized (this) {
- fIsDirty= fProgressMonitor != null ? fProgressMonitor.isCanceled() : false;
- }
- fDirtyRegionQueue.notifyAll();
- }
- }
-
- fIsActive= false;
- }
- }
- }
-
- /**
- * Internal document listener and text input listener.
- */
- class Listener implements IDocumentListener, ITextInputListener {
-
- /*
- * @see IDocumentListener#documentAboutToBeChanged(DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent e) {
- }
-
- /*
- * @see IDocumentListener#documentChanged(DocumentEvent)
- */
- public void documentChanged(DocumentEvent e) {
-
- if (!fThread.isDirty()&& fThread.isAlive())
- aboutToBeReconciled();
-
- if (fProgressMonitor != null && fThread.isActive())
- fProgressMonitor.setCanceled(true);
-
- if (fIsIncrementalReconciler)
- createDirtyRegion(e);
-
-
- fThread.reset();
-
- }
-
- /*
- * @see ITextInputListener#inputDocumentAboutToBeChanged(IDocument, IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
-
- if (oldInput == fDocument) {
-
- if (fDocument != null)
- fDocument.removeDocumentListener(this);
-
- if (fIsIncrementalReconciler) {
- fDirtyRegionQueue.purgeQueue();
- if (fDocument != null && fDocument.getLength() > 0) {
- DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), null);
- createDirtyRegion(e);
- fThread.reset();
- fThread.suspendCallerWhileDirty();
- }
- }
-
- fDocument= null;
- }
- }
-
- /*
- * @see ITextInputListener#inputDocumentChanged(IDocument, IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
-
- fDocument= newInput;
- if (fDocument == null)
- return;
-
-
- reconcilerDocumentChanged(fDocument);
-
- fDocument.addDocumentListener(this);
-
- if (!fThread.isDirty())
- aboutToBeReconciled();
-
- if (fIsIncrementalReconciler) {
- DocumentEvent e= new DocumentEvent(fDocument, 0, 0, fDocument.get());
- createDirtyRegion(e);
- }
-
- startReconciling();
- }
- }
-
- /** Queue to manage the changes applied to the text viewer */
- private DirtyRegionQueue fDirtyRegionQueue;
- /** The background thread */
- private BackgroundThread fThread;
- /** Internal document and text input listener */
- private Listener fListener;
- /** The background thread delay */
- private int fDelay= 500;
- /** Are there incremental reconciling strategies? */
- private boolean fIsIncrementalReconciler= true;
- /** The progress monitor used by this reconciler */
- private IProgressMonitor fProgressMonitor;
-
- /** The text viewer's document */
- private IDocument fDocument;
- /** The text viewer */
- private ITextViewer fViewer;
-
-
- /**
- * Processes a dirty region. If the dirty region is <code>null</code> the whole
- * document is consider being dirty. The dirty region is partitioned by the
- * document and each partition is handed over to a reconciling strategy registered
- * for the partition's content type.
- *
- * @param dirtyRegion the dirty region to be processed
- */
- abstract protected void process(DirtyRegion dirtyRegion);
-
- /**
- * Hook called when the document whose contents should be reconciled
- * has been changed, i.e., the input document of the text viewer this
- * reconciler is installed on. Usually, subclasses use this hook to
- * inform all their reconciling strategies about the change.
- *
- * @param newDocument the new reconciler document
- */
- abstract protected void reconcilerDocumentChanged(IDocument newDocument);
-
-
- /**
- * Creates a new reconciler without configuring it.
- */
- protected AbstractReconciler() {
- super();
- }
-
- /**
- * Tells the reconciler how long it should wait for further text changes before
- * activating the appropriate reconciling strategies.
- *
- * @param delay the duration in milliseconds of a change collection period.
- */
- public void setDelay(int delay) {
- fDelay= delay;
- }
-
- /**
- * Tells the reconciler whether any of the available reconciling strategies
- * is interested in getting detailed dirty region information or just in the
- * fact the the document has been changed. In the second case, the reconciling
- * can not incrementally be pursued.
- *
- * @param isIncremental indicates whether this reconciler will be configured with
- * incremental reconciling strategies
- *
- * @see DirtyRegion
- * @see IReconcilingStrategy
- */
- public void setIsIncrementalReconciler(boolean isIncremental) {
- fIsIncrementalReconciler= isIncremental;
- }
-
- /**
- * Sets the progress monitor of this reconciler.
- *
- * @param monitor the monitor to be used
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- fProgressMonitor= monitor;
- }
-
- /**
- * Returns whether any of the reconciling strategies is interested in
- * detailed dirty region information.
- *
- * @return whether this reconciler is incremental
- *
- * @see IReconcilingStrategy
- */
- protected boolean isIncrementalReconciler() {
- return fIsIncrementalReconciler;
- }
-
- /**
- * Returns the input document of the text viewer this reconciler is installed on.
- *
- * @return the reconciler document
- */
- protected IDocument getDocument() {
- return fDocument;
- }
-
- /**
- * Returns the text viewer this reconciler is installed on.
- *
- * @return the text viewer this reconciler is installed on
- */
- protected ITextViewer getTextViewer() {
- return fViewer;
- }
-
- /**
- * Returns the progress monitor of this reconciler.
- *
- * @return the progress monitor of this reconciler
- */
- protected IProgressMonitor getProgressMonitor() {
- return fProgressMonitor;
- }
-
- /*
- * @see IReconciler#install(ITextViewer)
- */
- public void install(ITextViewer textViewer) {
-
- Assert.isNotNull(textViewer);
- synchronized (this) {
- if (fThread != null)
- return;
- fThread= new BackgroundThread(getClass().getName());
- }
-
- fViewer= textViewer;
-
- fListener= new Listener();
- fViewer.addTextInputListener(fListener);
-
- fDirtyRegionQueue= new DirtyRegionQueue();
- }
-
- /*
- * @see IReconciler#uninstall()
- */
- public void uninstall() {
- if (fListener != null) {
-
- fViewer.removeTextInputListener(fListener);
- if (fDocument != null) fDocument.removeDocumentListener(fListener);
- fListener= null;
-
- synchronized (this) {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=19135
- BackgroundThread bt= fThread;
- fThread= null;
- bt.cancel();
- }
- }
- }
-
- /**
- * Creates a dirty region for a document event and adds it to the queue.
- *
- * @param e the document event for which to create a dirty region
- */
- private void createDirtyRegion(DocumentEvent e) {
-
- if (e.getLength() == 0 && e.getText() != null) {
- // Insert
- fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText()));
-
- } else if (e.getText() == null || e.getText().length() == 0) {
- // Remove
- fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null));
-
- } else {
- // Replace (Remove + Insert)
- fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getLength(), DirtyRegion.REMOVE, null));
- fDirtyRegionQueue.addDirtyRegion(new DirtyRegion(e.getOffset(), e.getText().length(), DirtyRegion.INSERT, e.getText()));
- }
- }
-
- /**
- * Hook for subclasses which want to perform some
- * action as soon as reconciliation is needed.
- * <p>
- * Default implementation is to do nothing.
- * </p>
- *
- * @since 3.0
- */
- protected void aboutToBeReconciled() {
- }
-
- /**
- * This method is called on startup of the background activity. It is called only
- * once during the life time of the reconciler. Clients may reimplement this method.
- */
- protected void initialProcess() {
- }
-
- /**
- * Forces the reconciler to reconcile the structure of the whole document.
- * Clients may extend this method.
- */
- protected void forceReconciling() {
-
- if (fDocument != null) {
-
- if (fIsIncrementalReconciler) {
- DocumentEvent e= new DocumentEvent(fDocument, 0, fDocument.getLength(), fDocument.get());
- createDirtyRegion(e);
- }
-
- startReconciling();
- }
- }
-
- /**
- * Starts the reconciler to reconcile the queued dirty-regions.
- * Clients may extend this method.
- */
- protected synchronized void startReconciling() {
- if (fThread == null)
- return;
-
- if (!fThread.isAlive()) {
- try {
- fThread.start();
- } catch (IllegalThreadStateException e) {
- // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=40549
- // This is the only instance where the thread is started; since
- // we checked that it is not alive, it must be dead already due
- // to a run-time exception or error. Exit.
- }
- } else {
- fThread.reset();
- }
- }
-
- /**
- * Hook that is called after the reconciler thread has been reset.
- */
- protected void reconcilerReset() {
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java
deleted file mode 100644
index 6cf1b7c889b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegion.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.reconciler;
-
-
-import org.eclipse.jface.text.ITypedRegion;
-
-/**
- * A dirty region describes a document range which has been changed.
- */
-public class DirtyRegion implements ITypedRegion {
-
- /**
- * Identifies an insert operation.
- */
- final static public String INSERT= "__insert"; //$NON-NLS-1$
- /**
- * Identifies a remove operation.
- */
- final static public String REMOVE= "__remove"; //$NON-NLS-1$
-
- /** The region's offset */
- private int fOffset;
- /** The region's length */
- private int fLength;
- /** Indicates the type of the applied change */
- private String fType;
- /** The text which has been inserted */
- private String fText;
-
- /**
- * Creates a new dirty region.
- *
- *
- * @param offset the offset within the document where the change occurred
- * @param length the length of the text within the document that changed
- * @param type the type of change that this region represents: <code>INSERT</code> or <code>REMOVE</code>
- * @param text the substitution text
- */
- public DirtyRegion(int offset, int length, String type, String text) {
- fOffset= offset;
- fLength= length;
- fType= type;
- fText= text;
- }
-
- /*
- * @see ITypedRegion#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /*
- * @see ITypedRegion#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see ITypedRegion#getType
- */
- public String getType() {
- return fType;
- }
-
- /**
- * Returns the text that changed as part of the region change.
- *
- * @return the changed text
- */
- public String getText() {
- return fText;
- }
-
- /**
- * Modify the receiver so that it encompasses the region specified by the dirty region.
- *
- * @param dr the dirty region with which to merge
- */
- void mergeWith(DirtyRegion dr) {
- int start= Math.min(fOffset, dr.fOffset);
- int end= Math.max(fOffset + fLength, dr.fOffset + dr.fLength);
- fOffset= start;
- fLength= end - start;
- fText= (dr.fText == null ? fText : (fText == null) ? dr.fText : fText + dr.fText);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java
deleted file mode 100644
index d74d3549a91..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/DirtyRegionQueue.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.reconciler;
-
-
-import java.util.List;
-import java.util.ArrayList;
-
-
-/**
- * Queue used by <code>Reconciler</code> to manage dirty regions. When a dirty region
- * is inserted into the queue, the queue tries to fold it into the neighboring dirty region.
- *
- * @see Reconciler
- * @see DirtyRegion
- */
-class DirtyRegionQueue {
-
- /** The list of dirty regions */
- private List fDirtyRegions= new ArrayList();
-
- /**
- * Creates a new empty dirty region.
- */
- public DirtyRegionQueue() {
- super();
- }
-
- /**
- * Adds a dirty region to the end of the dirty-region queue.
- *
- * @param dr the dirty region to add
- */
- public void addDirtyRegion(DirtyRegion dr) {
- // If the dirty region being added is directly after the last dirty
- // region on the queue then merge the two dirty regions together.
- DirtyRegion lastDR= getLastDirtyRegion();
- boolean wasMerged= false;
- if (lastDR != null)
- if (lastDR.getType() == dr.getType())
- if (lastDR.getType() == DirtyRegion.INSERT) {
- if (lastDR.getOffset() + lastDR.getLength() == dr.getOffset()) {
- lastDR.mergeWith(dr);
- wasMerged= true;
- }
- } else if (lastDR.getType() == DirtyRegion.REMOVE) {
- if (dr.getOffset() + dr.getLength() == lastDR.getOffset()) {
- lastDR.mergeWith(dr);
- wasMerged= true;
- }
- }
-
- if (!wasMerged)
- // Don't merge- just add the new one onto the queue.
- fDirtyRegions.add(dr);
- }
-
- /**
- * Returns the last dirty region that was added to the queue.
- *
- * @return the last DirtyRegion on the queue
- */
- private DirtyRegion getLastDirtyRegion() {
- int size= fDirtyRegions.size();
- return (size == 0 ? null : (DirtyRegion) fDirtyRegions.get(size - 1));
- }
-
- /**
- * Returns the number of regions in the queue.
- *
- * @return the dirty-region queue-size
- */
- public int getSize() {
- return fDirtyRegions.size();
- }
-
- /**
- * Throws away all entries in the queue.
- */
- public void purgeQueue() {
- fDirtyRegions.clear();
- }
-
- /**
- * Removes and returns the first dirty region in the queue
- *
- * @return the next dirty region on the queue
- */
- public DirtyRegion removeNextDirtyRegion() {
- if (fDirtyRegions.size() == 0)
- return null;
- DirtyRegion dr= (DirtyRegion) fDirtyRegions.get(0);
- fDirtyRegions.remove(0);
- return dr;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilableModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilableModel.java
deleted file mode 100644
index bd71f78995c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilableModel.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-/**
- * Tagging interface for a reconcilable model.
- *
- * @since 3.0
- */
-public interface IReconcilableModel {
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileResult.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileResult.java
deleted file mode 100644
index 89e080998dc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileResult.java
+++ /dev/null
@@ -1,22 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-/**
- * Tagging interface for the result reported by a reconcile step
- *
- * @see org.eclipse.jface.text.reconciler.IReconcileStep
- * @since 3.0
- */
-public interface IReconcileResult {
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileStep.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileStep.java
deleted file mode 100644
index b1d0e3d707f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcileStep.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.reconciler.DirtyRegion;
-
-/**
- * A reconcile step is one of n steps of a reconcile
- * strategy that consists of several steps.
- *
- * @see org.eclipse.jface.text.reconciler.IReconcilingStrategy
- * @since 3.0
- */
-public interface IReconcileStep {
-
- /**
- * Returns whether this is the last reconcile step or not.
- *
- * @return <code>true</code> if this is the last reconcile step
- */
- boolean isLastStep();
-
- /**
- * Returns whether this is the first reconcile step or not.
- *
- * @return <code>true</code> if this is the last reconcile step
- */
- boolean isFirstStep();
-
- /**
- * Sets the step which is in front of this step in the pipe.
- * <p>
- * Note: This method must be called at most once per reconcile step.
- * </p>
- *
- * @param step the previous step
- * @exception org.eclipse.jface.text.Assert#AssertionFailedException if called more than once
- */
- void setPreviousStep(IReconcileStep step);
-
- /**
- * Activates incremental reconciling of the specified dirty region.
- * As a dirty region might span multiple content types, the segment of the
- * dirty region which should be investigated is also provided to this
- * reconciling strategy. The given regions refer to the document passed into
- * the most recent call of <code>setDocument</code>.
- *
- * @param dirtyRegion the document region which has been changed
- * @param subRegion the sub region in the dirty region which should be reconciled
- * @return an array with reconcile results
- */
- IReconcileResult[] reconcile(DirtyRegion dirtyRegion, IRegion subRegion);
-
- /**
- * Activates non-incremental reconciling. The reconciling strategy is just told
- * that there are changes and that it should reconcile the given partition of the
- * document most recently passed into <code>setDocument</code>.
- *
- * @param partition the document partition to be reconciled
- * @return an array with reconcile results
- */
- IReconcileResult[] reconcile(IRegion partition);
-
- /**
- * Sets the progress monitor to this reconcile step.
- *
- * @param monitor the progress monitor to be used
- */
- void setProgressMonitor(IProgressMonitor monitor);
-
- /**
- * Returns the progress monitor used to report progress.
- *
- * @return a progress monitor or null if no progress monitor is provided
- */
- public IProgressMonitor getProgressMonitor();
-
- /**
- * Tells this reconcile step on which model it will
- * work. This method will be called before any other method
- * and can be called multiple times. The regions passed to the
- * other methods always refer to the most recent document
- * passed into this method.
- *
- * @param inputModel the model on which this strategy will work
- */
- void setInputModel(IReconcilableModel inputModel);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java
deleted file mode 100644
index 196015a59db..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconciler.java
+++ /dev/null
@@ -1,62 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.reconciler;
-
-
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-
-/**
- * An <code>IReconciler</code> defines and maintains a model of the content
- * of the text viewer's document in the presence of changes applied to this
- * document. An <code>IReconciler</code> is a <code>ITextViewer</code> add-on.<p>
- * Reconcilers are assumed to be asynchronous, i.e. they allow a certain
- * temporal window of inconsistency between the document and the model of
- * the content of this document. <p>
- * Reconcilers have a list of <code>IReconcilingStrategy</code> objects
- * each of which is registered for a particular document content type.
- * The reconciler uses the strategy objects to react on the changes applied
- * to the text viewer's document.<p>
- * The interface can be implemented by clients. By default, clients use
- * <code>Reconciler</code> as the standard implementer of this interface.
- *
- * @see ITextViewer
- * @see IReconcilingStrategy
- */
-public interface IReconciler {
-
- /**
- * Installs the reconciler on the given text viewer. After this method has been
- * finished, the reconciler is operational. I.e., it works without requesting
- * further client actions until <code>uninstall</code> is called.
- *
- * @param textViewer the viewer on which the reconciler is installed
- */
- void install(ITextViewer textViewer);
-
- /**
- * Removes the reconciler from the text viewer it has previously been
- * installed on.
- */
- void uninstall();
-
- /**
- * Returns the reconciling strategy registered with the reconciler
- * for the specified content type.
- *
- * @param contentType the content type for which to determine the reconciling strategy
- * @return the reconciling strategy registered for the given content type, or
- * <code>null</code> if there is no such strategy
- */
- IReconcilingStrategy getReconcilingStrategy(String contentType);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilerExtension.java
deleted file mode 100644
index dbfd2ec13c8..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilerExtension.java
+++ /dev/null
@@ -1,27 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.reconciler;
-
-/**
- * Extension interface for <code>IReconciler</code>.
- * Updates the reconciler to be aware of documents with multiple partitions.
- *
- * @since 3.0
- */
-public interface IReconcilerExtension {
-
- /**
- * Returns the partitioning this reconciler is using.
- *
- * @return the partitioning this reconciler is using
- */
- String getDocumentPartitioning();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java
deleted file mode 100644
index afc350cd2ed..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategy.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.reconciler;
-
-
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-
-
-/**
- * A reconciling strategy is used by an reconciler to reconcile a model
- * based on text of a particular content type. It provides methods for
- * incremental as well as non-incremental reconciling.<p>
- * This interface must be implemented by clients. Implementers should be
- * registered with a reconciler in order get involved in the reconciling
- * process.
- */
-public interface IReconcilingStrategy {
-
- /**
- * Tells this reconciling strategy on which document it will
- * work. This method will be called before any other method
- * and can be called multiple times. The regions passed to the
- * other methods always refer to the most recent document
- * passed into this method.
- *
- * @param document the document on which this strategy will work
- */
- void setDocument(IDocument document);
-
- /**
- * Activates incremental reconciling of the specified dirty region.
- * As a dirty region might span multiple content types, the segment of the
- * dirty region which should be investigated is also provided to this
- * reconciling strategy. The given regions refer to the document passed into
- * the most recent call of <code>setDocument</code>.
- *
- * @param dirtyRegion the document region which has been changed
- * @param subRegion the sub region in the dirty region which should be reconciled
- */
- void reconcile(DirtyRegion dirtyRegion, IRegion subRegion);
-
- /**
- * Activates non-incremental reconciling. The reconciling strategy is just told
- * that there are changes and that it should reconcile the given partition of the
- * document most recently passed into <code>setDocument</code>.
- *
- * @param partition the document partition to be reconciled
- */
- void reconcile(IRegion partition);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java
deleted file mode 100644
index 53bb1deaeee..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/IReconcilingStrategyExtension.java
+++ /dev/null
@@ -1,45 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-
-/**
- * Extension interface for <code>IReconcilingStrategy</code>.
- * The new functions are:
- * <ul>
- * <li> usage of a progress monitor
- * <li> initial reconciling step: If a reconciler runs as periodic activity in the background, this
- * methods offers the reconciler a chance for initializing its startegies and achieving a
- * reconciled state before the periodic activity starts.
- * </ul>
- *
- * @since 2.0
- */
-public interface IReconcilingStrategyExtension {
-
- /**
- * Tells this reconciling strategy with which progress monitor
- * it will work. This method will be called before any other
- * method and can be called multiple times.
- *
- * @param monitor the progress monitor with which this strategy will work
- */
- void setProgressMonitor(IProgressMonitor monitor);
-
- /**
- * Called only once in the life time of this reconciling strategy.
- */
- void initialReconcile();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java
deleted file mode 100644
index 39418e64995..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/MonoReconciler.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Region;
-
-
-/**
- * Standard implementation of <code>IReconciler</code>. The reconciler
- * is configured with a single <code>IReconcilingStrategy</code> that is
- * used independly from where a dirty region is located in the reconciler's
- * document. <p>
- * Usually, clients instantiate this class and configure it before using it.
- *
- * @see IReconciler
- * @see org.eclipse.jface.text.IDocumentListener
- * @see org.eclipse.jface.text.ITextInputListener
- * @see DirtyRegion
- * @since 2.0
- */
-public class MonoReconciler extends AbstractReconciler {
-
-
- /** The reconciling strategy */
- private IReconcilingStrategy fStrategy;
-
-
- /**
- * Creates a new reconciler that uses the same reconciling strategy to
- * reconcile its document independent of the type of the document's contents.
- *
- * @param strategy the reconciling strategy to be used
- * @param isIncremental the indication whether strategy is incremental or not
- */
- public MonoReconciler(IReconcilingStrategy strategy, boolean isIncremental) {
- super();
-
- Assert.isNotNull(strategy);
-
- fStrategy= strategy;
- setIsIncrementalReconciler(isIncremental);
- }
-
- /*
- * @see IReconciler#getReconcilingStrategy(String)
- */
- public IReconcilingStrategy getReconcilingStrategy(String contentType) {
- Assert.isNotNull(contentType);
- return fStrategy;
- }
-
- /*
- * @see AbstractReconciler#process(DirtyRegion)
- */
- protected void process(DirtyRegion dirtyRegion) {
-
- if(dirtyRegion != null)
- fStrategy.reconcile(dirtyRegion, dirtyRegion);
- else {
- IDocument document= getDocument();
- if (document != null)
- fStrategy.reconcile(new Region(0, document.getLength()));
- }
- }
-
- /*
- * @see AbstractReconciler#reconcilerDocumentChanged(IDocument)
- */
- protected void reconcilerDocumentChanged(IDocument document) {
- fStrategy.setDocument(document);
- }
-
- /*
- * @see AbstractReconciler#setProgressMonitor(IProgressMonitor)
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- super.setProgressMonitor(monitor);
- if (fStrategy instanceof IReconcilingStrategyExtension) {
- IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategy;
- extension.setProgressMonitor(monitor);
- }
- }
-
- /*
- * @see AbstractReconciler#initialProcess()
- */
- protected void initialProcess() {
- if (fStrategy instanceof IReconcilingStrategyExtension) {
- IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) fStrategy;
- extension.initialReconcile();
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
deleted file mode 100644
index 1ebbb12afdd..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/Reconciler.java
+++ /dev/null
@@ -1,219 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.reconciler;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import org.eclipse.core.runtime.IProgressMonitor;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextUtilities;
-import org.eclipse.jface.text.TypedRegion;
-
-/**
- * Standard implementation of <code>IReconciler</code>. The reconciler
- * is configured with a set of reconciling strategies each of which is
- * responsible for a particular content type. <p>
- * Usually, clients instantiate this class and configure it before using it.
- *
- * @see IReconciler
- * @see org.eclipse.jface.text.IDocumentListener
- * @see org.eclipse.jface.text.ITextInputListener
- * @see DirtyRegion
- */
-public class Reconciler extends AbstractReconciler implements IReconcilerExtension {
-
- /** The map of reconciling strategies */
- private Map fStrategies;
-
- /**
- * The partitioning this reconciler uses.
- *@since 3.0
- */
- private String fPartitioning;
-
- /**
- * Creates a new reconciler with the following configuration: it is
- * an incremental reconciler with a standard delay of 500 ms. There
- * are no predefined reconciling strategies. The partitioning it uses
- * is the default partitioning <code>IDocumentExtension3.DEFAULT_PARTITIONING</code>.
- */
- public Reconciler() {
- super();
- fPartitioning= IDocumentExtension3.DEFAULT_PARTITIONING;
- }
-
- /**
- * Sets the document partitioning for this reconciler.
- *
- * @param partitioning the document partitioning for this reconciler
- * @since 3.0
- */
- public void setDocumentPartitioning(String partitioning) {
- Assert.isNotNull(partitioning);
- fPartitioning= partitioning;
- }
-
- /*
- * @see org.eclipse.jface.text.reconciler.IReconcilerExtension#getDocumentPartitioning()
- * @since 3.0
- */
- public String getDocumentPartitioning() {
- return fPartitioning;
- }
-
- /**
- * Registers a given reconciling strategy for a particular content type.
- * If there is already a strategy registered for this type, the new strategy
- * is registered instead of the old one.
- *
- * @param strategy the reconciling strategy to register, or <code>null</code> to remove an existing one
- * @param contentType the content type under which to register
- */
- public void setReconcilingStrategy(IReconcilingStrategy strategy, String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fStrategies == null)
- fStrategies= new HashMap();
-
- if (strategy == null)
- fStrategies.remove(contentType);
- else {
- fStrategies.put(contentType, strategy);
- if (strategy instanceof IReconcilingStrategyExtension && getProgressMonitor() == null) {
- IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) strategy;
- extension.setProgressMonitor(getProgressMonitor());
- }
- }
- }
-
- /*
- * @see IReconciler#getReconcilingStrategy(String)
- */
- public IReconcilingStrategy getReconcilingStrategy(String contentType) {
-
- Assert.isNotNull(contentType);
-
- if (fStrategies == null)
- return null;
-
- return (IReconcilingStrategy) fStrategies.get(contentType);
- }
-
- /**
- * Processes a dirty region. If the dirty region is <code>null</code> the whole
- * document is consider being dirty. The dirty region is partitioned by the
- * document and each partition is handed over to a reconciling strategy registered
- * for the partition's content type.
- *
- * @param dirtyRegion the dirty region to be processed
- * @see AbstractReconciler#process(DirtyRegion)
- */
- protected void process(DirtyRegion dirtyRegion) {
-
- IRegion region= dirtyRegion;
-
- if (region == null)
- region= new Region(0, getDocument().getLength());
-
- ITypedRegion[] regions= computePartitioning(region.getOffset(), region.getLength());
-
- for (int i= 0; i < regions.length; i++) {
- ITypedRegion r= regions[i];
- IReconcilingStrategy s= getReconcilingStrategy(r.getType());
- if (s == null)
- continue;
-
- if(dirtyRegion != null)
- s.reconcile(dirtyRegion, r);
- else
- s.reconcile(r);
- }
- }
-
- /*
- * @see AbstractReconciler#reconcilerDocumentChanged(IDocument)
- * @since 2.0
- */
- protected void reconcilerDocumentChanged(IDocument document) {
- if (fStrategies != null) {
- Iterator e= fStrategies.values().iterator();
- while (e.hasNext()) {
- IReconcilingStrategy strategy= (IReconcilingStrategy) e.next();
- strategy.setDocument(document);
- }
- }
- }
-
- /*
- * @see AbstractReconciler#setProgressMonitor(IProgressMonitor)
- * @since 2.0
- */
- public void setProgressMonitor(IProgressMonitor monitor) {
- super.setProgressMonitor(monitor);
-
- if (fStrategies != null) {
- Iterator e= fStrategies.values().iterator();
- while (e.hasNext()) {
- IReconcilingStrategy strategy= (IReconcilingStrategy) e.next();
- if (strategy instanceof IReconcilingStrategyExtension) {
- IReconcilingStrategyExtension extension= (IReconcilingStrategyExtension) strategy;
- extension.setProgressMonitor(monitor);
- }
- }
- }
- }
-
- /*
- * @see AbstractReconciler#initialProcess()
- * @since 2.0
- */
- protected void initialProcess() {
- ITypedRegion[] regions= computePartitioning(0, getDocument().getLength());
- for (int i= 0; i < regions.length; i++) {
- ITypedRegion r= regions[i];
- IReconcilingStrategy s= getReconcilingStrategy(r.getType());
- if (s instanceof IReconcilingStrategyExtension) {
- IReconcilingStrategyExtension e= (IReconcilingStrategyExtension) s;
- e.initialReconcile();
- }
- }
- }
-
- /**
- * Computes and returns the partitioning for the given region of the input document
- * of the reconciler's connected text viewer.
- *
- * @param offset the region offset
- * @param length the region length
- * @return the computed partitioning
- * @since 3.0
- */
- private ITypedRegion[] computePartitioning(int offset, int length) {
- ITypedRegion[] regions= null;
- try {
- regions= TextUtilities.computePartitioning(getDocument(), getDocumentPartitioning(), offset, length, false);
- } catch (BadLocationException x) {
- regions= new TypedRegion[0];
- }
- return regions;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/package.html
deleted file mode 100644
index 8f46d6c7019..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/reconciler/package.html
+++ /dev/null
@@ -1,25 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.76 [en] (Windows NT 5.0; U) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a reconciler add-on for an <tt>ITextViewer</tt>.
-A&nbsp; reconciler provides generic synchronization support&nbsp; with
-the content of the document serving as the <tt>ITextViewer</tt>'s input.
-There is no explicit model of what is synchronized.
-<h2>
-Package Specification</h2>
-<tt>IReconciler</tt> defines the concept of a reconciler. It collaborates
-with content type specific reconciling strategies (<tt>IReconcilingStrategy</tt>)
-which perform the synchronization for a given dirty region. The package
-contains a default implementation of <tt>IReconciler</tt> (<tt>Reconciler</tt>).
-
-<tt>Reconciler</tt> and <tt>MonoReconciler</tt> implements reconciling
-as a periodic background activity and folds co-located changes while being
-inactive.
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
deleted file mode 100644
index 0d71229350e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/BufferedRuleBasedScanner.java
+++ /dev/null
@@ -1,133 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-/**
- * A buffered rule based scanner. The buffer always contains a section
- * of a fixed size of the document to be scanned. Completely adheres to
- * the contract of <code>RuleBasedScanner</code>.
- */
-public class BufferedRuleBasedScanner extends RuleBasedScanner {
-
- /** The default buffer size. Value = 500 */
- private final static int DEFAULT_BUFFER_SIZE= 500;
- /** The actual size of the buffer. Initially set to <code>DEFAULT_BUFFER_SIZE</code> */
- private int fBufferSize= DEFAULT_BUFFER_SIZE;
- /** The buffer */
- private char[] fBuffer= new char[DEFAULT_BUFFER_SIZE];
- /** The offset of the document at which the buffer starts */
- private int fStart;
- /** The offset of the document at which the buffer ends */
- private int fEnd;
- /** The cached length of the document */
- private int fDocumentLength;
-
-
- /**
- * Creates a new buffered rule based scanner which does
- * not have any rule and a default buffer size of 500 characters.
- */
- protected BufferedRuleBasedScanner() {
- super();
- }
-
- /**
- * Creates a new buffered rule based scanner which does
- * not have any rule. The buffer size is set to the given
- * number of characters.
- *
- * @param size the buffer size
- */
- public BufferedRuleBasedScanner(int size) {
- super();
- setBufferSize(size);
- }
-
- /**
- * Sets the buffer to the given number of characters.
- *
- * @param size the buffer size
- */
- protected void setBufferSize(int size) {
- Assert.isTrue(size > 0);
- fBufferSize= size;
- fBuffer= new char[size];
- }
-
- /**
- * Shifts the buffer so that the buffer starts at the
- * given document offset.
- *
- * @param offset the document offset at which the buffer starts
- */
- private void shiftBuffer(int offset) {
-
- fStart= offset;
- fEnd= fStart + fBufferSize;
- if (fEnd > fDocumentLength)
- fEnd= fDocumentLength;
-
- try {
-
- String content= fDocument.get(fStart, fEnd - fStart);
- content.getChars(0, fEnd - fStart, fBuffer, 0);
-
- } catch (BadLocationException x) {
- }
- }
-
- /*
- * @see RuleBasedScanner#setRange(IDocument, int, int)
- */
- public void setRange(IDocument document, int offset, int length) {
-
- super.setRange(document, offset, length);
-
- fDocumentLength= document.getLength();
- shiftBuffer(offset);
- }
-
- /*
- * @see RuleBasedScanner#read()
- */
- public int read() {
-
- if (fOffset >= fRangeEnd) {
- ++ fOffset;
- return EOF;
- }
-
- if (fOffset == fEnd)
- shiftBuffer(fEnd);
- else if (fOffset < fStart || fEnd < fOffset)
- shiftBuffer(fOffset);
-
- return fBuffer[fOffset++ - fStart];
- }
-
- /*
- * @see RuleBasedScanner#unread()
- */
- public void unread() {
-
- if (fOffset == fStart)
- shiftBuffer(Math.max(0, fStart - (fBufferSize / 2)));
-
- -- fOffset;
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java
deleted file mode 100644
index 06a84dd2e57..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultDamagerRepairer.java
+++ /dev/null
@@ -1,218 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.swt.custom.StyleRange;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextAttribute;
-import org.eclipse.jface.text.TextPresentation;
-import org.eclipse.jface.text.presentation.IPresentationDamager;
-import org.eclipse.jface.text.presentation.IPresentationRepairer;
-
-
-/**
- * A standard implementation of a syntax driven presentation damager
- * and presentation repairer. It uses a token scanner to scan
- * the document and to determine its damage and new text presentation.
- * The tokens returned by the scanner are supposed to return text attributes
- * as their data.
- *
- * @see ITokenScanner
- * @since 2.0
- */
-public class DefaultDamagerRepairer implements IPresentationDamager, IPresentationRepairer {
-
- /** The document this object works on */
- protected IDocument fDocument;
- /** The scanner it uses */
- protected ITokenScanner fScanner;
- /** The default text attribute if non is returned as data by the current token */
- protected TextAttribute fDefaultTextAttribute;
-
- /**
- * Creates a damager/repairer that uses the given scanner and returns the given default
- * text attribute if the current token does not carry a text attribute.
- *
- * @param scanner the token scanner to be used
- * @param defaultTextAttribute the text attribute to be returned if non is specified by the current token,
- * may not be <code>null</code>
- *
- * @deprecated use DefaultDamagerRepairer(ITokenScanner) instead
- */
- public DefaultDamagerRepairer(ITokenScanner scanner, TextAttribute defaultTextAttribute) {
-
- Assert.isNotNull(defaultTextAttribute);
-
- fScanner= scanner;
- fDefaultTextAttribute= defaultTextAttribute;
- }
-
- /**
- * Creates a damager/repairer that uses the given scanner. The scanner may not be <code>null</code>
- * and is assumed to return only token that carry text attributes.
- *
- * @param scanner the token scanner to be used, may not be <code>null</code>
- */
- public DefaultDamagerRepairer(ITokenScanner scanner) {
-
- Assert.isNotNull(scanner);
-
- fScanner= scanner;
- fDefaultTextAttribute= new TextAttribute(null);
- }
-
- /*
- * @see IPresentationDamager#setDocument(IDocument)
- * @see IPresentationRepairer#setDocument(IDocument)
- */
- public void setDocument(IDocument document) {
- fDocument= document;
- }
-
-
- //---- IPresentationDamager
-
- /**
- * Returns the end offset of the line that contains the specified offset or
- * if the offset is inside a line delimiter, the end offset of the next line.
- *
- * @param offset the offset whose line end offset must be computed
- * @return the line end offset for the given offset
- * @exception BadLocationException if offset is invalid in the current document
- */
- protected int endOfLineOf(int offset) throws BadLocationException {
-
- IRegion info= fDocument.getLineInformationOfOffset(offset);
- if (offset <= info.getOffset() + info.getLength())
- return info.getOffset() + info.getLength();
-
- int line= fDocument.getLineOfOffset(offset);
- try {
- info= fDocument.getLineInformation(line + 1);
- return info.getOffset() + info.getLength();
- } catch (BadLocationException x) {
- return fDocument.getLength();
- }
- }
-
- /*
- * @see IPresentationDamager#getDamageRegion(ITypedRegion, DocumentEvent, boolean)
- */
- public IRegion getDamageRegion(ITypedRegion partition, DocumentEvent e, boolean documentPartitioningChanged) {
-
- if (!documentPartitioningChanged) {
- try {
-
- IRegion info= fDocument.getLineInformationOfOffset(e.getOffset());
- int start= Math.max(partition.getOffset(), info.getOffset());
-
- int end= e.getOffset() + (e.getText() == null ? e.getLength() : e.getText().length());
-
- if (info.getOffset() <= end && end <= info.getOffset() + info.getLength()) {
- // optimize the case of the same line
- end= info.getOffset() + info.getLength();
- } else
- end= endOfLineOf(end);
-
- end= Math.min(partition.getOffset() + partition.getLength(), end);
- return new Region(start, end - start);
-
- } catch (BadLocationException x) {
- }
- }
-
- return partition;
- }
-
- //---- IPresentationRepairer
-
- /*
- * @see IPresentationRepairer#createPresentation(TextPresentation, ITypedRegion)
- */
- public void createPresentation(TextPresentation presentation, ITypedRegion region) {
-
- if (fScanner == null) {
- // will be removed if deprecated constructor will be removed
- addRange(presentation, region.getOffset(), region.getLength(), fDefaultTextAttribute);
- return;
- }
-
- int lastStart= region.getOffset();
- int length= 0;
- boolean firstToken= true;
- IToken lastToken= Token.UNDEFINED;
- TextAttribute lastAttribute= getTokenTextAttribute(lastToken);
-
- fScanner.setRange(fDocument, lastStart, region.getLength());
-
- while (true) {
- IToken token= fScanner.nextToken();
- if (token.isEOF())
- break;
-
- TextAttribute attribute= getTokenTextAttribute(token);
- if (lastAttribute != null && lastAttribute.equals(attribute)) {
- length += fScanner.getTokenLength();
- firstToken= false;
- } else {
- if (!firstToken)
- addRange(presentation, lastStart, length, lastAttribute);
- firstToken= false;
- lastToken= token;
- lastAttribute= attribute;
- lastStart= fScanner.getTokenOffset();
- length= fScanner.getTokenLength();
- }
- }
-
- addRange(presentation, lastStart, length, lastAttribute);
- }
-
- /**
- * Returns a text attribute encoded in the given token. If the token's
- * data is not <code>null</code> and a text attribute it is assumed that
- * it is the encoded text attribute. It returns the default text attribute
- * if there is no encoded text attribute found.
- *
- * @param token the token whose text attribute is to be determined
- * @return the token's text attribute
- */
- protected TextAttribute getTokenTextAttribute(IToken token) {
- Object data= token.getData();
- if (data instanceof TextAttribute)
- return (TextAttribute) data;
- return fDefaultTextAttribute;
- }
-
- /**
- * Adds style information to the given text presentation.
- *
- * @param presentation the text presentation to be extended
- * @param offset the offset of the range to be styled
- * @param length the length of the range to be styled
- * @param attr the attribute describing the style of the range to be styled
- */
- protected void addRange(TextPresentation presentation, int offset, int length, TextAttribute attr) {
- if (attr != null)
- presentation.addStyleRange(new StyleRange(offset, length, attr.getForeground(), attr.getBackground(), attr.getStyle()));
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
deleted file mode 100644
index c1125b16fbc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/DefaultPartitioner.java
+++ /dev/null
@@ -1,635 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.IDocumentPartitionerExtension;
-import org.eclipse.jface.text.IDocumentPartitionerExtension2;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TypedPosition;
-import org.eclipse.jface.text.TypedRegion;
-
-
-
-/**
- * A standard implementation of a document partitioner.
- * It uses a partition token scanner to scan the document and to determine
- * the document's partitioning. The tokens returned by the
- * scanner are supposed to return the partition type
- * as their data. The partitoner remembers the document's partitions
- * in the document itself rather than maintaining its own data structure.
- *
- * @see IPartitionTokenScanner
- * @since 2.0
- */
-public class DefaultPartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension, IDocumentPartitionerExtension2 {
-
- /**
- * The position category this partitioner uses to store the document's partitioning information.
- * @deprecated use <code>getManagingPositionCategories()</code>.
- */
- public final static String CONTENT_TYPES_CATEGORY= "__content_types_category"; //$NON-NLS-1$
-
-
- /** The partitioner's scanner */
- protected IPartitionTokenScanner fScanner;
- /** The legal content types of this partitioner */
- protected String[] fLegalContentTypes;
- /** The partitioner's document */
- protected IDocument fDocument;
- /** The document length before a document change occured */
- protected int fPreviousDocumentLength;
- /** The position updater used to for the default updating of partitions */
- protected DefaultPositionUpdater fPositionUpdater;
- /** The offset at which the first changed partition starts */
- protected int fStartOffset;
- /** The offset at which the last changed partition ends */
- protected int fEndOffset;
- /**The offset at which a partition has been deleted */
- protected int fDeleteOffset;
- /**
- * The position category this partitioner uses to store the document's partitioning information.
- * @since 3.0
- */
- private String fPositionCategory;
-
- /**
- * Creates a new partitioner that uses the given scanner and may return
- * partitions of the given legal content types.
- *
- * @param scanner the scanner this partitioner is supposed to use
- * @param legalContentTypes the legal content types of this partitioner
- */
- public DefaultPartitioner(IPartitionTokenScanner scanner, String[] legalContentTypes) {
- fScanner= scanner;
- fLegalContentTypes= legalContentTypes;
- fPositionCategory= CONTENT_TYPES_CATEGORY + hashCode();
- fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getManagingPositionCategories()
- * @since 3.0
- */
- public String[] getManagingPositionCategories() {
- return new String[] { fPositionCategory };
- }
-
- /*
- * @see IDocumentPartitioner#connect(IDocument)
- */
- public void connect(IDocument document) {
- Assert.isNotNull(document);
- Assert.isTrue(!document.containsPositionCategory(fPositionCategory));
-
- fDocument= document;
- fDocument.addPositionCategory(fPositionCategory);
-
- initialize();
- }
-
- /**
- * Performs the initial partitioning of the partitioner's document.
- */
- protected void initialize() {
-
- fScanner.setRange(fDocument, 0, fDocument.getLength());
-
- try {
- IToken token= fScanner.nextToken();
- while (!token.isEOF()) {
-
- String contentType= getTokenContentType(token);
-
- if (isSupportedContentType(contentType)) {
- TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
- fDocument.addPosition(fPositionCategory, p);
- }
-
- token= fScanner.nextToken();
- }
- } catch (BadLocationException x) {
- // cannot happen as offsets come from scanner
- } catch (BadPositionCategoryException x) {
- // cannot happen if document has been connected before
- }
- }
-
- /*
- * @see IDocumentPartitioner#disconnect()
- */
- public void disconnect() {
-
- Assert.isTrue(fDocument.containsPositionCategory(fPositionCategory));
-
- try {
- fDocument.removePositionCategory(fPositionCategory);
- } catch (BadPositionCategoryException x) {
- // can not happen because of Assert
- }
- }
-
- /*
- * @see IDocumentPartitioner#documentAboutToBeChanged(DocumentEvent)
- */
- public void documentAboutToBeChanged(DocumentEvent e) {
-
- Assert.isTrue(e.getDocument() == fDocument);
-
- fPreviousDocumentLength= e.getDocument().getLength();
- fStartOffset= -1;
- fEndOffset= -1;
- fDeleteOffset= -1;
- }
-
- /*
- * @see IDocumentPartitioner#documentChanged(DocumentEvent)
- */
- public boolean documentChanged(DocumentEvent e) {
- IRegion region= documentChanged2(e);
- return (region != null);
- }
-
- /**
- * Helper method for tracking the minimal region containg all partition changes.
- * If <code>offset</code> is smaller than the remembered offset, <code>offset</code>
- * will from now on be remembered. If <code>offset + length</code> is greater than
- * the remembered end offset, it will be remembered from now on.
- *
- * @param offset the offset
- * @param length the length
- */
- private void rememberRegion(int offset, int length) {
- // remember start offset
- if (fStartOffset == -1)
- fStartOffset= offset;
- else if (offset < fStartOffset)
- fStartOffset= offset;
-
- // remember end offset
- int endOffset= offset + length;
- if (fEndOffset == -1)
- fEndOffset= endOffset;
- else if (endOffset > fEndOffset)
- fEndOffset= endOffset;
- }
-
- /**
- * Remembers the given offset as the deletion offset.
- *
- * @param offset the offset
- */
- private void rememberDeletedOffset(int offset) {
- fDeleteOffset= offset;
- }
-
- /**
- * Creates the minimal region containing all partition changes using the
- * remembered offset, end offset, and deletion offset.
- *
- * @return the minimal region containing all the partition changes
- */
- private IRegion createRegion() {
- if (fDeleteOffset == -1) {
- if (fStartOffset == -1 || fEndOffset == -1)
- return null;
- return new Region(fStartOffset, fEndOffset - fStartOffset);
- } else if (fStartOffset == -1 || fEndOffset == -1) {
- return new Region(fDeleteOffset, 0);
- } else {
- int offset= Math.min(fDeleteOffset, fStartOffset);
- int endOffset= Math.max(fDeleteOffset, fEndOffset);
- return new Region(offset, endOffset - offset);
- }
- }
-
- /*
- * @see IDocumentPartitionerExtension#documentChanged2(DocumentEvent)
- * @since 2.0
- */
- public IRegion documentChanged2(DocumentEvent e) {
-
- try {
-
- IDocument d= e.getDocument();
- Position[] category= d.getPositions(fPositionCategory);
- IRegion line= d.getLineInformationOfOffset(e.getOffset());
- int reparseStart= line.getOffset();
- int partitionStart= -1;
- String contentType= null;
- int newLength= e.getText() == null ? 0 : e.getText().length();
-
- int first= d.computeIndexInCategory(fPositionCategory, reparseStart);
- if (first > 0) {
- TypedPosition partition= (TypedPosition) category[first - 1];
- if (partition.includes(reparseStart)) {
- partitionStart= partition.getOffset();
- contentType= partition.getType();
- if (e.getOffset() == partition.getOffset() + partition.getLength())
- reparseStart= partitionStart;
- -- first;
- } else if (reparseStart == e.getOffset() && reparseStart == partition.getOffset() + partition.getLength()) {
- partitionStart= partition.getOffset();
- contentType= partition.getType();
- reparseStart= partitionStart;
- -- first;
- } else {
- partitionStart= partition.getOffset() + partition.getLength();
- contentType= IDocument.DEFAULT_CONTENT_TYPE;
- }
- }
-
- fPositionUpdater.update(e);
- for (int i= first; i < category.length; i++) {
- Position p= category[i];
- if (p.isDeleted) {
- rememberDeletedOffset(e.getOffset());
- break;
- }
- }
- category= d.getPositions(fPositionCategory);
-
- fScanner.setPartialRange(d, reparseStart, d.getLength() - reparseStart, contentType, partitionStart);
-
- int lastScannedPosition= reparseStart;
- IToken token= fScanner.nextToken();
-
- while (!token.isEOF()) {
-
- contentType= getTokenContentType(token);
-
- if (!isSupportedContentType(contentType)) {
- token= fScanner.nextToken();
- continue;
- }
-
- int start= fScanner.getTokenOffset();
- int length= fScanner.getTokenLength();
-
- lastScannedPosition= start + length - 1;
-
- // remove all affected positions
- while (first < category.length) {
- TypedPosition p= (TypedPosition) category[first];
- if (lastScannedPosition >= p.offset + p.length ||
- (p.overlapsWith(start, length) &&
- (!d.containsPosition(fPositionCategory, start, length) ||
- !contentType.equals(p.getType())))) {
-
- rememberRegion(p.offset, p.length);
- d.removePosition(fPositionCategory, p);
- ++ first;
-
- } else
- break;
- }
-
- // if position already exists and we have scanned at least the
- // area covered by the event, we are done
- if (d.containsPosition(fPositionCategory, start, length)) {
- if (lastScannedPosition >= e.getOffset() + newLength)
- return createRegion();
- ++ first;
- } else {
- // insert the new type position
- try {
- d.addPosition(fPositionCategory, new TypedPosition(start, length, contentType));
- rememberRegion(start, length);
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
- }
-
- token= fScanner.nextToken();
- }
-
-
- // remove all positions behind lastScannedPosition since there aren't any further types
- if (lastScannedPosition != reparseStart) {
- // if this condition is not met, nothing has been scanned because of a deletion
- ++ lastScannedPosition;
- }
- first= d.computeIndexInCategory(fPositionCategory, lastScannedPosition);
-
- TypedPosition p;
- while (first < category.length) {
- p= (TypedPosition) category[first++];
- d.removePosition(fPositionCategory, p);
- rememberRegion(p.offset, p.length);
- }
-
- } catch (BadPositionCategoryException x) {
- // should never happen on connected documents
- } catch (BadLocationException x) {
- }
-
- return createRegion();
- }
-
-
- /**
- * Returns the position in the partitoner's position category which is
- * close to the given offset. This is, the position has either an offset which
- * is the same as the given offset or an offset which is smaller than the given
- * offset. This method profits from the knowledge that a partitioning is
- * a ordered set of disjoint position.
- *
- * @param offset the offset for which to search the closest position
- * @return the closest position in the partitioner's category
- */
- protected TypedPosition findClosestPosition(int offset) {
-
- try {
-
- int index= fDocument.computeIndexInCategory(fPositionCategory, offset);
- Position[] category= fDocument.getPositions(fPositionCategory);
-
- if (category.length == 0)
- return null;
-
- if (index < category.length) {
- if (offset == category[index].offset)
- return (TypedPosition) category[index];
- }
-
- if (index > 0)
- index--;
-
- return (TypedPosition) category[index];
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
-
- /*
- * @see IDocumentPartitioner#getContentType(int)
- */
- public String getContentType(int offset) {
-
- TypedPosition p= findClosestPosition(offset);
- if (p != null && p.includes(offset))
- return p.getType();
-
- return IDocument.DEFAULT_CONTENT_TYPE;
- }
-
- /*
- * @see IDocumentPartitioner#getPartition(int)
- */
- public ITypedRegion getPartition(int offset) {
-
- try {
-
- Position[] category = fDocument.getPositions(fPositionCategory);
-
- if (category == null || category.length == 0)
- return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
-
- int index= fDocument.computeIndexInCategory(fPositionCategory, offset);
-
- if (index < category.length) {
-
- TypedPosition next= (TypedPosition) category[index];
-
- if (offset == next.offset)
- return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
-
- if (index == 0)
- return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
-
- TypedPosition previous= (TypedPosition) category[index - 1];
- if (previous.includes(offset))
- return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
-
- int endOffset= previous.getOffset() + previous.getLength();
- return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
- }
-
- TypedPosition previous= (TypedPosition) category[category.length - 1];
- if (previous.includes(offset))
- return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
-
- int endOffset= previous.getOffset() + previous.getLength();
- return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
-
- return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
- }
-
- /*
- * @see IDocumentPartitioner#computePartitioning(int, int)
- */
- public ITypedRegion[] computePartitioning(int offset, int length) {
- return computePartitioning(offset, length, false);
- }
-
- /*
- * @see IDocumentPartitioner#getLegalContentTypes()
- */
- public String[] getLegalContentTypes() {
- return fLegalContentTypes;
- }
-
- /**
- * Returns whether the given type is one of the legal content types.
- *
- * @param contentType the content type to check
- * @return <code>true</code> if the content type is a legal content type
- */
- protected boolean isSupportedContentType(String contentType) {
- if (contentType != null) {
- for (int i= 0; i < fLegalContentTypes.length; i++) {
- if (fLegalContentTypes[i].equals(contentType))
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Returns a content type encoded in the given token. If the token's
- * data is not <code>null</code> and a string it is assumed that
- * it is the encoded content type.
- *
- * @param token the token whose content type is to be determined
- * @return the token's content type
- */
- protected String getTokenContentType(IToken token) {
- Object data= token.getData();
- if (data instanceof String)
- return (String) data;
- return null;
- }
-
- /* zero-length partition support */
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthContentType(int)
- * @since 3.0
- */
- public String getContentType(int offset, boolean preferOpenPartitions) {
- return getPartition(offset, preferOpenPartitions).getType();
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthPartition(int)
- * @since 3.0
- */
- public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
- ITypedRegion region= getPartition(offset);
- if (preferOpenPartitions) {
- if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
- if (offset > 0) {
- region= getPartition(offset - 1);
- if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
- return region;
- }
- return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
- }
- }
- return region;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#computePartitioning(int, int, boolean)
- * @since 3.0
- */
- public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
- List list= new ArrayList();
-
- try {
-
- int endOffset= offset + length;
-
- Position[] category= fDocument.getPositions(fPositionCategory);
-
- TypedPosition previous= null, current= null;
- int start, end, gapOffset;
- Position gap= new Position(0);
-
- int startIndex= getFirstIndexEndingAfterOffset(category, offset);
- int endIndex= getFirstIndexStartingAfterOffset(category, endOffset);
- for (int i= startIndex; i < endIndex; i++) {
-
- current= (TypedPosition) category[i];
-
- gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0;
- gap.setOffset(gapOffset);
- gap.setLength(current.getOffset() - gapOffset);
- if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) ||
- (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
- start= Math.max(offset, gapOffset);
- end= Math.min(endOffset, gap.getOffset() + gap.getLength());
- list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
- }
-
- if (current.overlapsWith(offset, length)) {
- start= Math.max(offset, current.getOffset());
- end= Math.min(endOffset, current.getOffset() + current.getLength());
- list.add(new TypedRegion(start, end - start, current.getType()));
- }
-
- previous= current;
- }
-
- if (previous != null) {
- gapOffset= previous.getOffset() + previous.getLength();
- gap.setOffset(gapOffset);
- gap.setLength(fDocument.getLength() - gapOffset);
- if ((includeZeroLengthPartitions && overlapsOrTouches(gap, offset, length)) ||
- (gap.getLength() > 0 && gap.overlapsWith(offset, length))) {
- start= Math.max(offset, gapOffset);
- end= Math.min(endOffset, fDocument.getLength());
- list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
- }
- }
-
- if (list.isEmpty())
- list.add(new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE));
-
- } catch (BadPositionCategoryException x) {
- }
-
- TypedRegion[] result= new TypedRegion[list.size()];
- list.toArray(result);
- return result;
- }
-
- private boolean overlapsOrTouches(Position gap, int offset, int length) {
- return gap.getOffset() <= offset + length && offset <= gap.getOffset() + gap.getLength();
- }
-
- /**
- * Returns the index of the first position which ends after the given offset.
- *
- * @param positions the positions in linear order
- * @param offset the offset
- * @return the index of the first position which ends after the offset
- *
- * @since 3.0
- */
- private int getFirstIndexEndingAfterOffset(Position[] positions, int offset) {
- int i= -1, j= positions.length;
- while (j - i > 1) {
- int k= (i + j) >> 1;
- Position p= positions[k];
- if (p.getOffset() + p.getLength() > offset)
- j= k;
- else
- i= k;
- }
- return j;
- }
-
- /**
- * Returns the index of the first position which starts at or after the given offset.
- *
- * @param positions the positions in linear order
- * @param offset the offset
- * @return the index of the first position which starts after the offset
- *
- * @since 3.0
- */
- private int getFirstIndexStartingAfterOffset(Position[] positions, int offset) {
- int i= -1, j= positions.length;
- while (j - i > 1) {
- int k= (i + j) >> 1;
- Position p= positions[k];
- if (p.getOffset() >= offset)
- j= k;
- else
- i= k;
- }
- return j;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
deleted file mode 100644
index 3679e99df54..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/EndOfLineRule.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- * Christopher Lenz (cmlenz@gmx.de) - support for line continuation
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * A specific configuration of a single line rule
- * whereby the pattern begins with a specific sequence but
- * is only ended by a line delimiter.
- */
-public class EndOfLineRule extends SingleLineRule {
-
- /**
- * Creates a rule for the given starting sequence
- * which, if detected, will return the specified token.
- *
- * @param startSequence the pattern's start sequence
- * @param token the token to be returned on success
- */
- public EndOfLineRule(String startSequence, IToken token) {
- this(startSequence, token, (char) 0);
- }
-
- /**
- * Creates a rule for the given starting sequence
- * which, if detected, will return the specified token.
- * Any character which follows the given escape character
- * will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- */
- public EndOfLineRule(String startSequence, IToken token, char escapeCharacter) {
- super(startSequence, null, token, escapeCharacter, true);
- }
-
- /**
- * Creates a rule for the given starting sequence
- * which, if detected, will return the specified token.
- * Any character which follows the given escape character
- * will be ignored. In addition, an escape character
- * immediately before an end of line can be set to continue
- * the line.
- *
- * @param startSequence the pattern's start sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- * @param escapeContinuesLine indicates whether the specified escape
- * character is used for line continuation, so that an end of
- * line immediately after the escape character does not
- * terminate the line, even if <code>breakOnEOL</code> is true
- * @since 3.0
- */
- public EndOfLineRule(String startSequence, IToken token, char escapeCharacter, boolean escapeContinuesLine) {
- super(startSequence, null, token, escapeCharacter, true, escapeContinuesLine);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java
deleted file mode 100644
index 95513f053d0..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ICharacterScanner.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * Defines the interface of a character scanner used by rules.
- * Rules may request the next character or ask the character
- * scanner to unread the last read character.
- */
-public interface ICharacterScanner {
-
- /**
- * The value returned when this scanner has read EOF.
- */
- public static final int EOF= -1;
-
- /**
- * Provides rules access to the legal line delimiters.
- *
- * @return the legal line delimiters
- */
- char[][] getLegalLineDelimiters();
-
- /**
- * Returns the column of the character scanner.
- *
- * @return the column of the character scanner
- */
- int getColumn();
-
- /**
- * Returns the next character or EOF if end of file has been reached
- *
- * @return the next character or EOF
- */
- int read();
-
- /**
- * Rewinds the scanner before the last read character.
- */
- void unread();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java
deleted file mode 100644
index b63f89246ca..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPartitionTokenScanner.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * A partition token scanner returns tokens that represent partitions. For that reason,
- * a partition token scanner is vulnerable in respect to the document offset it starts
- * scanning. In a simple case, a partition token scanner must always start at a partition
- * boundary. A partition token scanner can also start in the middle of a partition,
- * if it knows the type of the partition.
- *
- * @since 2.0
- */
-public interface IPartitionTokenScanner extends ITokenScanner {
-
- /**
- * Configures the scanner by providing access to the document range that should be scanned.
- * The range may no only contain complete partitions but starts at the beginning of a line in the
- * middle of a partition of the given content type. This requires that a partition delimiter can not
- * contain a line delimiter.
- *
- * @param document the document to scan
- * @param offset the offset of the document range to scan
- * @param length the length of the document range to scan
- * @param contentType the content type at the given offset
- * @param partitionOffset the offset at which the partition of the given offset starts
- */
- void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java
deleted file mode 100644
index 16c859616b9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IPredicateRule.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-/**
- * Defines the interface for a rule used in the scanning of text for the purpose of
- * document partitioning or text styling. A predicate rule can only return one single
- * token after having successfully detected content. This token is called success token.
- * Also, it also returns a token indicating that this rule has not been successful.
- *
- * @see ICharacterScanner
- * @since 2.0
- */
-public interface IPredicateRule extends IRule {
-
- /**
- * Returns the success token of this predicate rule.
- *
- * @return the success token of this rule
- */
- IToken getSuccessToken();
-
- /**
- * Evaluates the rule by examining the characters available from
- * the provided character scanner. The token returned by this rule
- * returns <code>true</code> when calling <code>isUndefined</code>,
- * if the text the rule investigated does not match the rule's requirements. Otherwise,
- * this method returns this rule's success token. If this rules relies on a text pattern
- * comprising a opening and a closing character sequence this method can also be called
- * when the scanner is positioned already between the opening and the closing sequence.
- * In this case, <code>resume</code> must be set to <code>true</code>.
- *
- * @param scanner the character scanner to be used by this rule
- * @param resume indicates that the rule starts working between the opening and the closing character sequence
- * @return the token computed by the rule
- */
- IToken evaluate(ICharacterScanner scanner, boolean resume);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java
deleted file mode 100644
index 501a3d85cd6..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IRule.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * Defines the interface for a rule used in the
- * scanning of text for the purpose of document
- * partitioning or text styling.
- *
- * @see ICharacterScanner
- */
-public interface IRule {
-
- /**
- * Evaluates the rule by examining the characters available from
- * the provided character scanner. The token returned by this rule
- * returns <code>true</code> when calling <code>isUndefined</code>,
- * if the text the rule investigated does not match the rule's requirements.
- *
- * @param scanner the character scanner to be used by this rule
- * @return the token computed by the rule
- */
- IToken evaluate(ICharacterScanner scanner);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java
deleted file mode 100644
index ff54ac95fb6..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IToken.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * A token to be returned by a rule.
- */
-public interface IToken {
-
- /**
- * Return whether this token is undefined.
- *
- * @return <code>true</code>if this token is undefined
- */
- boolean isUndefined();
-
- /**
- * Return whether this token represents a whitespace.
- *
- * @return <code>true</code>if this token represents a whitespace
- */
- boolean isWhitespace();
-
- /**
- * Return whether this token represents End Of File.
- *
- * @return <code>true</code>if this token represents EOF
- */
- boolean isEOF();
-
- /**
- * Return whether this token is neither undefined, nor whitespace, nor EOF.
- *
- * @return <code>true</code>if this token is not undefined, not a whitespace, and not EOF
- */
- boolean isOther();
-
- /**
- * Return a data attacted to this token. The semantics of this data kept undefined by this interface.
- *
- * @return the data attached to this token.
- */
- Object getData();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java
deleted file mode 100644
index 1b8561dac30..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/ITokenScanner.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * A token scanner scans a range of a document and reports about the token it finds.
- * A scanner has state. When asked, the scanner returns the offset and the length of the
- * last found token.
- *
- * @see org.eclipse.jface.text.rules.IToken
- * @since 2.0
- */
-public interface ITokenScanner {
-
- /**
- * Configures the scanner by providing access to the document range that should
- * be scanned.
- *
- * @param document the document to scan
- * @param offset the offset of the document range to scan
- * @param length the length of the document range to scan
- */
- void setRange(IDocument document, int offset, int length);
-
- /**
- * Returns the next token in the document.
- *
- * @return the next token in the document
- */
- IToken nextToken();
-
- /**
- * Returns the offset of the last token read by this scanner.
- *
- * @return the offset of the last token read by this scanner
- */
- int getTokenOffset();
-
- /**
- * Returns the length of the last token read by this scanner.
- *
- * @return the length of the last token read by this scanner
- */
- int getTokenLength();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java
deleted file mode 100644
index d8e658b04ef..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWhitespaceDetector.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * Defines the interface by which <code>WhitespaceRule</code>
- * determines whether a given character is to be considered
- * whitespace in the current context.
- */
-public interface IWhitespaceDetector {
-
- /**
- * Returns whether the specified character is whitespace.
- *
- * @param c the character to be checked
- * @return <code>true</code> if the specified character is a whitespace char
- */
- boolean isWhitespace(char c);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java
deleted file mode 100644
index 0936e617eda..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/IWordDetector.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * Defines the interface by which <code>WordRule</code>
- * determines whether a given character is valid as part
- * of a word in the current context.
- */
-public interface IWordDetector {
-
- /**
- * Returns whether the specified character is
- * valid as the first character in a word.
- *
- * @param c the character to be checked
- * @return <code>true</code> is a valid first character in a word, <code>false</code> otherwise
- */
- boolean isWordStart(char c);
-
- /**
- * Returns whether the specified character is
- * valid as a subsequent character in a word.
- *
- * @param c the character to be checked
- * @return <code>true</code> if the character is a valid word part, <code>false</code> otherwise
- */
- boolean isWordPart(char c);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
deleted file mode 100644
index 25677477dfc..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/MultiLineRule.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * A rule for detecting patterns which begin with a given
- * sequence and may end with a given sequence thereby spanning
- * multiple lines.
- */
-public class MultiLineRule extends PatternRule {
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specified token.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- */
- public MultiLineRule(String startSequence, String endSequence, IToken token) {
- this(startSequence, endSequence, token, (char) 0);
- }
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specific token.
- * Any character which follows the given escape character will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- */
- public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) {
- this(startSequence, endSequence, token, escapeCharacter, false);
- }
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specific token. Any character that follows the
- * given escape character will be ignored. <code>breakOnEOF</code> indicates whether
- * EOF is equivalent to detecting the <code>endSequence</code>.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- * @param breaksOnEOF indicates whether the end of the file terminates this rule successfully
- * @since 2.1
- */
- public MultiLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) {
- super(startSequence, endSequence, token, escapeCharacter, false, breaksOnEOF);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java
deleted file mode 100644
index b654fda55ad..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/NumberRule.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * An implementation of <code>IRule</code> capable of detecting a numerical value.
- */
-public class NumberRule implements IRule {
-
- /** Internal setting for the uninitialized column constraint */
- protected static final int UNDEFINED= -1;
- /** The token to be returned when this rule is successful */
- protected IToken fToken;
- /** The column constraint */
- protected int fColumn= UNDEFINED;
-
- /**
- * Creates a rule which will return the specified
- * token when a numerical sequence is detected.
- *
- * @param token the token to be returned
- */
- public NumberRule(IToken token) {
- Assert.isNotNull(token);
- fToken= token;
- }
-
- /**
- * Sets a column constraint for this rule. If set, the rule's token
- * will only be returned if the pattern is detected starting at the
- * specified column. If the column is smaller then 0, the column
- * constraint is considered removed.
- *
- * @param column the column in which the pattern starts
- */
- public void setColumnConstraint(int column) {
- if (column < 0)
- column= UNDEFINED;
- fColumn= column;
- }
-
- /*
- * @see IRule#evaluate(ICharacterScanner)
- */
- public IToken evaluate(ICharacterScanner scanner) {
- int c= scanner.read();
- if (Character.isDigit((char)c)) {
- if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
- do {
- c= scanner.read();
- } while (Character.isDigit((char) c));
- scanner.unread();
- return fToken;
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
deleted file mode 100644
index 9b041e20ad9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/PatternRule.java
+++ /dev/null
@@ -1,273 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- * Christopher Lenz (cmlenz@gmx.de) - support for line continuation
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-import org.eclipse.jface.text.Assert;
-
-
-
-
-/**
- * Standard implementation of <code>IPredicateRule</code>.
- * Is is capable of detecting a pattern which begins with a given start
- * sequence and ends with a given end sequence. If the end sequence is
- * not specified, it can be either end of line, end or file, or both. Additionally,
- * the pattern can be constrained to begin in a certain column. The rule can also
- * be used to check whether the text to scan covers half of the pattern, i.e. contains
- * the end sequence required by the rule.
- */
-public class PatternRule implements IPredicateRule {
-
- /** Internal setting for the uninitialized column constraint */
- protected static final int UNDEFINED= -1;
-
- /** The token to be returned on success */
- protected IToken fToken;
- /** The pattern's start sequence */
- protected char[] fStartSequence;
- /** The pattern's end sequence */
- protected char[] fEndSequence;
- /** The pattern's column constrain */
- protected int fColumn= UNDEFINED;
- /** The pattern's escape character */
- protected char fEscapeCharacter;
- /**
- * Indicates whether the escape character continues a line
- * @since 3.0
- */
- protected boolean fEscapeContinuesLine;
- /** Indicates whether end of line terminates the pattern */
- protected boolean fBreaksOnEOL;
- /** Indicates whether end of file terminates the pattern */
- protected boolean fBreaksOnEOF;
-
- /**
- * Creates a rule for the given starting and ending sequence.
- * When these sequences are detected the rule will return the specified token.
- * Alternatively, the sequence can also be ended by the end of the line.
- * Any character which follows the given escapeCharacter will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
- * @param token the token which will be returned on success
- * @param escapeCharacter any character following this one will be ignored
- * @param breaksOnEOL indicates whether the end of the line also terminates the pattern
- */
- public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL) {
- Assert.isTrue(startSequence != null && startSequence.length() > 0);
- Assert.isTrue(endSequence != null || breaksOnEOL);
- Assert.isNotNull(token);
-
- fStartSequence= startSequence.toCharArray();
- fEndSequence= (endSequence == null ? new char[0] : endSequence.toCharArray());
- fToken= token;
- fEscapeCharacter= escapeCharacter;
- fBreaksOnEOL= breaksOnEOL;
- }
-
- /**
- * Creates a rule for the given starting and ending sequence.
- * When these sequences are detected the rule will return the specified token.
- * Alternatively, the sequence can also be ended by the end of the line or the end of the file.
- * Any character which follows the given escapeCharacter will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
- * @param token the token which will be returned on success
- * @param escapeCharacter any character following this one will be ignored
- * @param breaksOnEOL indicates whether the end of the line also terminates the pattern
- * @param breaksOnEOF indicates whether the end of the file also terminates the pattern
- * @since 2.1
- */
- public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF) {
- this(startSequence, endSequence, token, escapeCharacter, breaksOnEOL);
- fBreaksOnEOF= breaksOnEOF;
- }
-
- /**
- * Creates a rule for the given starting and ending sequence.
- * When these sequences are detected the rule will return the specified token.
- * Alternatively, the sequence can also be ended by the end of the line or the end of the file.
- * Any character which follows the given escapeCharacter will be ignored. An end of line
- * immediately after the given <code>lineContinuationCharacter</code> will not cause the
- * pattern to terminate even if <code>breakOnEOL</code> is set to true.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence, <code>null</code> is a legal value
- * @param token the token which will be returned on success
- * @param escapeCharacter any character following this one will be ignored
- * @param breaksOnEOL indicates whether the end of the line also terminates the pattern
- * @param breaksOnEOF indicates whether the end of the file also terminates the pattern
- * @param escapeContinuesLine indicates whether the specified escape character is used for line
- * continuation, so that an end of line immediately after the escape character does not
- * terminate the pattern, even if <code>breakOnEOL</code> is set
- * @since 3.0
- */
- public PatternRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOL, boolean breaksOnEOF, boolean escapeContinuesLine) {
- this(startSequence, endSequence, token, escapeCharacter, breaksOnEOL, breaksOnEOF);
- fEscapeContinuesLine= escapeContinuesLine;
- }
-
- /**
- * Sets a column constraint for this rule. If set, the rule's token
- * will only be returned if the pattern is detected starting at the
- * specified column. If the column is smaller then 0, the column
- * constraint is considered removed.
- *
- * @param column the column in which the pattern starts
- */
- public void setColumnConstraint(int column) {
- if (column < 0)
- column= UNDEFINED;
- fColumn= column;
- }
-
-
- /**
- * Evaluates this rules without considering any column constraints.
- *
- * @param scanner the character scanner to be used
- * @return the token resulting from this evaluation
- */
- protected IToken doEvaluate(ICharacterScanner scanner) {
- return doEvaluate(scanner, false);
- }
-
- /**
- * Evaluates this rules without considering any column constraints. Resumes
- * detection, i.e. look sonly for the end sequence required by this rule if the
- * <code>resume</code> flag is set.
- *
- * @param scanner the character scanner to be used
- * @param resume <code>true</code> if detection should be resumed, <code>false</code> otherwise
- * @return the token resulting from this evaluation
- * @since 2.0
- */
- protected IToken doEvaluate(ICharacterScanner scanner, boolean resume) {
-
- if (resume) {
-
- if (endSequenceDetected(scanner))
- return fToken;
-
- } else {
-
- int c= scanner.read();
- if (c == fStartSequence[0]) {
- if (sequenceDetected(scanner, fStartSequence, false)) {
- if (endSequenceDetected(scanner))
- return fToken;
- }
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
-
- /*
- * @see IRule#evaluate(ICharacterScanner)
- */
- public IToken evaluate(ICharacterScanner scanner) {
- return evaluate(scanner, false);
- }
-
- /**
- * Returns whether the end sequence was detected. As the pattern can be considered
- * ended by a line delimiter, the result of this method is <code>true</code> if the
- * rule breaks on the end of the line, or if the EOF character is read.
- *
- * @param scanner the character scanner to be used
- * @return <code>true</code> if the end sequence has been detected
- */
- protected boolean endSequenceDetected(ICharacterScanner scanner) {
- int c;
- char[][] delimiters= scanner.getLegalLineDelimiters();
- boolean previousWasEscapeCharacter = false;
- while ((c= scanner.read()) != ICharacterScanner.EOF) {
- if (c == fEscapeCharacter) {
- // Skip the escaped character.
- scanner.read();
- } else if (fEndSequence.length > 0 && c == fEndSequence[0]) {
- // Check if the specified end sequence has been found.
- if (sequenceDetected(scanner, fEndSequence, true))
- return true;
- } else if (fBreaksOnEOL) {
- // Check for end of line since it can be used to terminate the pattern.
- for (int i= 0; i < delimiters.length; i++) {
- if (c == delimiters[i][0] && sequenceDetected(scanner, delimiters[i], true)) {
- if (!fEscapeContinuesLine || !previousWasEscapeCharacter)
- return true;
- }
- }
- }
- previousWasEscapeCharacter = (c == fEscapeCharacter);
- }
- if (fBreaksOnEOF) return true;
- scanner.unread();
- return false;
- }
-
- /**
- * Returns whether the next characters to be read by the character scanner
- * are an exact match with the given sequence. No escape characters are allowed
- * within the sequence. If specified the sequence is considered to be found
- * when reading the EOF character.
- *
- * @param scanner the character scanner to be used
- * @param sequence the sequence to be detected
- * @param eofAllowed indicated whether EOF terminates the pattern
- * @return <code>true</code> if the given sequence has been detected
- */
- protected boolean sequenceDetected(ICharacterScanner scanner, char[] sequence, boolean eofAllowed) {
- for (int i= 1; i < sequence.length; i++) {
- int c= scanner.read();
- if (c == ICharacterScanner.EOF && eofAllowed) {
- return true;
- } else if (c != sequence[i]) {
- // Non-matching character detected, rewind the scanner back to the start.
- // Do not unread the first character.
- scanner.unread();
- for (int j= i-1; j > 0; j--)
- scanner.unread();
- return false;
- }
- }
-
- return true;
- }
-
- /*
- * @see IPredicateRule#evaluate(ICharacterScanner, boolean)
- * @since 2.0
- */
- public IToken evaluate(ICharacterScanner scanner, boolean resume) {
- if (fColumn == UNDEFINED)
- return doEvaluate(scanner, resume);
-
- int c= scanner.read();
- scanner.unread();
- if (c == fStartSequence[0])
- return (fColumn == scanner.getColumn() ? doEvaluate(scanner, resume) : Token.UNDEFINED);
- else
- return Token.UNDEFINED;
- }
-
- /*
- * @see IPredicateRule#getSuccessToken()
- * @since 2.0
- */
- public IToken getSuccessToken() {
- return fToken;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java
deleted file mode 100644
index 22936f4152c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedDamagerRepairer.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.TextAttribute;
-
-
-/**
- * @deprecated use <code>DefaultDamagerRepairer</code>
- */
-public class RuleBasedDamagerRepairer extends DefaultDamagerRepairer {
-
- /**
- * Creates a damager/repairer that uses the given scanner and returns the given default
- * text attribute if the current token does not carry a text attribute.
- *
- * @param scanner the rule based scanner to be used
- * @param defaultTextAttribute the text attribute to be returned if non is specified by the current token,
- * may not be <code>null</code>
- *
- * @deprecated use RuleBasedDamagerRepairer(RuleBasedScanner) instead
- */
- public RuleBasedDamagerRepairer(RuleBasedScanner scanner, TextAttribute defaultTextAttribute) {
- super(scanner, defaultTextAttribute);
- }
-
- /**
- * Creates a damager/repairer that uses the given scanner. The scanner may not be <code>null</code>
- * and is assumed to return only token that carry text attributes.
- *
- * @param scanner the rule based scanner to be used, may not be <code>null</code>
- * @since 2.0
- */
- public RuleBasedDamagerRepairer(RuleBasedScanner scanner) {
- super(scanner);
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java
deleted file mode 100644
index 35ea30ddb15..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitionScanner.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * Scanner that exclusively uses predicate rules.
- * @since 2.0
- */
-public class RuleBasedPartitionScanner extends BufferedRuleBasedScanner implements IPartitionTokenScanner {
-
- /** The content type of the partition in which to resume scanning. */
- protected String fContentType;
- /** The offset of the partition inside which to resume. */
- protected int fPartitionOffset;
-
-
- /*
- * @see RuleBasedScanner#setRules(IRule[])
- */
- public void setRules(IRule[] rules) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * @see RuleBasedScanner#setRules(IRule[])
- */
- public void setPredicateRules(IPredicateRule[] rules) {
- super.setRules(rules);
- }
-
- /*
- * @see ITokenScanner#setRange(IDocument, int, int)
- */
- public void setRange(IDocument document, int offset, int length) {
- setPartialRange(document, offset, length, null, -1);
- }
-
- /*
- * @see IPartitionTokenScanner#setPartialRange(IDocument, int, int, String, int)
- */
- public void setPartialRange(IDocument document, int offset, int length, String contentType, int partitionOffset) {
- fContentType= contentType;
- fPartitionOffset= partitionOffset;
- if (partitionOffset > -1) {
- int delta= offset - partitionOffset;
- if (delta > 0) {
- super.setRange(document, partitionOffset, length + delta);
- fOffset= offset;
- return;
- }
- }
- super.setRange(document, offset, length);
- }
-
- /*
- * @see ITokenScanner#nextToken()
- */
- public IToken nextToken() {
-
-
- if (fContentType == null || fRules == null) {
- //don't try to resume
- return super.nextToken();
- }
-
- // inside a partition
-
- fColumn= UNDEFINED;
- boolean resume= (fPartitionOffset > -1 && fPartitionOffset < fOffset);
- fTokenOffset= resume ? fPartitionOffset : fOffset;
-
- IPredicateRule rule;
- IToken token;
-
- for (int i= 0; i < fRules.length; i++) {
- rule= (IPredicateRule) fRules[i];
- token= rule.getSuccessToken();
- if (fContentType.equals(token.getData())) {
- token= rule.evaluate(this, resume);
- if (!token.isUndefined()) {
- fContentType= null;
- return token;
- }
- }
- }
-
- // haven't found any rule for this type of partition
- fContentType= null;
- if (resume)
- fOffset= fPartitionOffset;
- return super.nextToken();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
deleted file mode 100644
index 78663dd0eb5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedPartitioner.java
+++ /dev/null
@@ -1,587 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DefaultPositionUpdater;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentPartitioner;
-import org.eclipse.jface.text.IDocumentPartitionerExtension;
-import org.eclipse.jface.text.IDocumentPartitionerExtension2;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITypedRegion;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TypedPosition;
-import org.eclipse.jface.text.TypedRegion;
-
-
-
-/**
- * A standard implementation of a syntax driven document partitioner.
- * It uses a rule based scanner to scan the document and to determine
- * the document's partitioning. The tokens returned by the rules the
- * scanner is configured with are supposed to return the partition type
- * as their data. The partitioner remembers the document's partitions
- * in the document itself rather than maintaining its own data structure.
- *
- * @see IRule
- * @see RuleBasedScanner
- *
- * @deprecated use <code>DefaultPartitioner</code> instead
- */
-public class RuleBasedPartitioner implements IDocumentPartitioner, IDocumentPartitionerExtension, IDocumentPartitionerExtension2 {
-
- /**
- * The position category this partitioner uses to store the document's partitioning information
- * @deprecated use <code>getManagingPositionCategories()</code>.
- */
- public final static String CONTENT_TYPES_CATEGORY= "__content_types_category"; //$NON-NLS-1$
-
-
- /** The partitioner's scanner */
- protected RuleBasedScanner fScanner;
- /** The legal content types of this partitioner */
- protected String[] fLegalContentTypes;
- /** The partitioner's document */
- protected IDocument fDocument;
- /** The document length before a document change occured */
- protected int fPreviousDocumentLength;
- /** The position updater used to for the default updating of partitions */
- protected DefaultPositionUpdater fPositionUpdater;
- /** The offset at which the first changed partition starts */
- protected int fStartOffset;
- /** The offset at which the last changed partition ends */
- protected int fEndOffset;
- /**The offset at which a partition has been deleted */
- protected int fDeleteOffset;
- /**
- * The position category for managing partitoning information.
- * @since 3.0
- */
- private String fPositionCategory;
-
-
- /**
- * Creates a new partitioner that uses the given scanner and may return
- * partitions of the given legal content types.
- *
- * @param scanner the scanner this partitioner is supposed to use
- * @param legalContentTypes the legal content types of this partitioner
- */
- public RuleBasedPartitioner(RuleBasedScanner scanner, String[] legalContentTypes) {
- fScanner= scanner;
- fLegalContentTypes= legalContentTypes;
- fPositionCategory= CONTENT_TYPES_CATEGORY + hashCode();
- fPositionUpdater= new DefaultPositionUpdater(fPositionCategory);
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getManagingPositionCategories()
- * @since 3.0
- */
- public String[] getManagingPositionCategories() {
- return new String[] { fPositionCategory };
- }
-
- /*
- * @see IDocumentPartitioner#connect
- */
- public void connect(IDocument document) {
- Assert.isNotNull(document);
- Assert.isTrue(!document.containsPositionCategory(fPositionCategory));
-
- fDocument= document;
- fDocument.addPositionCategory(fPositionCategory);
-
- initialize();
- }
-
- /**
- * Performs the initial partitioning of the partitioner's document.
- */
- protected void initialize() {
-
- fScanner.setRange(fDocument, 0, fDocument.getLength());
-
- try {
- IToken token= fScanner.nextToken();
- while (!token.isEOF()) {
-
- String contentType= getTokenContentType(token);
-
- if (isSupportedContentType(contentType)) {
- TypedPosition p= new TypedPosition(fScanner.getTokenOffset(), fScanner.getTokenLength(), contentType);
- fDocument.addPosition(fPositionCategory, p);
- }
-
- token= fScanner.nextToken();
- }
- } catch (BadLocationException x) {
- // cannot happen as offsets come from scanner
- } catch (BadPositionCategoryException x) {
- // cannot happen if document has been connected before
- }
- }
-
- /*
- * @see IDocumentPartitioner#disconnect
- */
- public void disconnect() {
-
- Assert.isTrue(fDocument.containsPositionCategory(fPositionCategory));
-
- try {
- fDocument.removePositionCategory(fPositionCategory);
- } catch (BadPositionCategoryException x) {
- // can not happen because of Assert
- }
- }
-
- /*
- * @see IDocumentPartitioner#documentAboutToBeChanged
- */
- public void documentAboutToBeChanged(DocumentEvent e) {
-
- Assert.isTrue(e.getDocument() == fDocument);
-
- fPreviousDocumentLength= e.getDocument().getLength();
- fStartOffset= -1;
- fEndOffset= -1;
- fDeleteOffset= -1;
- }
-
- /*
- * @see IDocumentPartitioner#documentChanged
- */
- public boolean documentChanged(DocumentEvent e) {
- IRegion region= documentChanged2(e);
- return (region != null);
- }
-
- /**
- * Helper method for tracking the minimal region containg all partition changes.
- * If <code>offset</code> is smaller than the remembered offset, <code>offset</code>
- * will from now on be remembered. If <code>offset + length</code> is greater than
- * the remembered end offset, it will be remembered from now on.
- *
- * @param offset the offset
- * @param length the length
- */
- private void rememberRegion(int offset, int length) {
- // remember start offset
- if (fStartOffset == -1)
- fStartOffset= offset;
- else if (offset < fStartOffset)
- fStartOffset= offset;
-
- // remember end offset
- int endOffset= offset + length;
- if (fEndOffset == -1)
- fEndOffset= endOffset;
- else if (endOffset > fEndOffset)
- fEndOffset= endOffset;
- }
-
- /**
- * Remembers the given offset as the deletion offset.
- *
- * @param offset the offset
- */
- private void rememberDeletedOffset(int offset) {
- fDeleteOffset= offset;
- }
-
- /**
- * Creates the minimal region containing all partition changes using the
- * remembered offset, end offset, and deletion offset.
- * @return the minimal region containing all the partition changes
- */
- private IRegion createRegion() {
- if (fDeleteOffset == -1) {
- if (fStartOffset == -1 || fEndOffset == -1)
- return null;
- return new Region(fStartOffset, fEndOffset - fStartOffset);
- } else if (fStartOffset == -1 || fEndOffset == -1) {
- return new Region(fDeleteOffset, 0);
- } else {
- int offset= Math.min(fDeleteOffset, fStartOffset);
- int endOffset= Math.max(fDeleteOffset, fEndOffset);
- return new Region(offset, endOffset - offset);
- }
- }
-
- /*
- * @see IDocumentPartitionerExtension#documentChanged2(DocumentEvent)
- * @since 2.0
- */
- public IRegion documentChanged2(DocumentEvent e) {
-
- try {
-
- IDocument d= e.getDocument();
- Position[] category= d.getPositions(fPositionCategory);
- int first= 0;
- int reparseStart= 0;
- int originalSize= category.length;
-
- if (originalSize > 0) {
-
- /*
- * determine character position at which the scanner starts:
- * first position behind the last non-default partition the actual position is not involved with
- */
-
- first= d.computeIndexInCategory(fPositionCategory, e.getOffset());
-
- Position p= null;
- do {
- --first;
- if (first < 0)
- break;
-
- p= category[first];
-
- } while (p.overlapsWith(e.getOffset(), e.getLength()) ||
- (e.getOffset() == fPreviousDocumentLength &&
- (p.getOffset() + p.getLength() == fPreviousDocumentLength)));
-
- fPositionUpdater.update(e);
- for (int i= 0; i < category.length; i++) {
- p= category[i];
- if (p.isDeleted) {
- rememberDeletedOffset(e.getOffset());
- break;
- }
- }
- category= d.getPositions(fPositionCategory);
-
- if (first >= 0) {
- p= category[first];
- reparseStart= p.getOffset() + p.getLength();
- }
-
- ++first;
- }
-
- fScanner.setRange(d, reparseStart, d.getLength() - reparseStart);
-
- int lastScannedPosition= reparseStart;
- IToken token= fScanner.nextToken();
-
- while (!token.isEOF()) {
-
-
- String contentType= getTokenContentType(token);
-
- if (!isSupportedContentType(contentType)) {
- token= fScanner.nextToken();
- continue;
- }
-
- int start= fScanner.getTokenOffset();
- int length= fScanner.getTokenLength();
-
- lastScannedPosition= start + length - 1;
-
- // remove all affected positions
- while (first < category.length) {
- TypedPosition p= (TypedPosition) category[first];
- if (lastScannedPosition >= p.offset + p.length ||
- (p.overlapsWith(start, length) &&
- (!d.containsPosition(fPositionCategory, start, length) ||
- !contentType.equals(p.getType())))) {
-
- rememberRegion(p.offset, p.length);
- d.removePosition(fPositionCategory, p);
- ++ first;
-
- } else
- break;
- }
-
- // if position already exists we are done
- if (d.containsPosition(fPositionCategory, start, length))
- return createRegion();
-
- // insert the new type position
- try {
- d.addPosition(fPositionCategory, new TypedPosition(start, length, contentType));
- rememberRegion(start, length);
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
-
- token= fScanner.nextToken();
- }
-
-
- // remove all positions behind lastScannedPosition since there aren't any further types
- if (lastScannedPosition != reparseStart) {
- // if this condition is not met, nothing has been scanned because of a delete
- ++ lastScannedPosition;
- }
- first= d.computeIndexInCategory(fPositionCategory, lastScannedPosition);
-
- TypedPosition p;
- while (first < category.length) {
- p= (TypedPosition) category[first++];
- d.removePosition(fPositionCategory, p);
- rememberRegion(p.offset, p.length);
- }
-
- } catch (BadPositionCategoryException x) {
- // should never happen on connected documents
- } catch (BadLocationException x) {
- }
-
- return createRegion();
- }
-
-
- /**
- * Returns the position in the partitoner's position category which is
- * close to the given offset. This is, the position has either an offset which
- * is the same as the given offset or an offset which is smaller than the given
- * offset. This method profits from the knowledge that a partitioning is
- * a ordered set of disjoint position.
- *
- * @param offset the offset for which to search the closest position
- * @return the closest position in the partitioner's category
- */
- protected TypedPosition findClosestPosition(int offset) {
-
- try {
-
- int index= fDocument.computeIndexInCategory(fPositionCategory, offset);
- Position[] category= fDocument.getPositions(fPositionCategory);
-
- if (category.length == 0)
- return null;
-
- if (index < category.length) {
- if (offset == category[index].offset)
- return (TypedPosition) category[index];
- }
-
- if (index > 0)
- index--;
-
- return (TypedPosition) category[index];
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
-
- /*
- * @see IDocumentPartitioner#getContentType
- */
- public String getContentType(int offset) {
-
- TypedPosition p= findClosestPosition(offset);
- if (p != null && p.includes(offset))
- return p.getType();
-
- return IDocument.DEFAULT_CONTENT_TYPE;
- }
-
- /*
- * @see IDocumentPartitioner#getPartition
- */
- public ITypedRegion getPartition(int offset) {
-
- try {
-
- Position[] category = fDocument.getPositions(fPositionCategory);
-
- if (category == null || category.length == 0)
- return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
-
- int index= fDocument.computeIndexInCategory(fPositionCategory, offset);
-
- if (index < category.length) {
-
- TypedPosition next= (TypedPosition) category[index];
-
- if (offset == next.offset)
- return new TypedRegion(next.getOffset(), next.getLength(), next.getType());
-
- if (index == 0)
- return new TypedRegion(0, next.offset, IDocument.DEFAULT_CONTENT_TYPE);
-
- TypedPosition previous= (TypedPosition) category[index - 1];
- if (previous.includes(offset))
- return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
-
- int endOffset= previous.getOffset() + previous.getLength();
- return new TypedRegion(endOffset, next.getOffset() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
- }
-
- TypedPosition previous= (TypedPosition) category[category.length - 1];
- if (previous.includes(offset))
- return new TypedRegion(previous.getOffset(), previous.getLength(), previous.getType());
-
- int endOffset= previous.getOffset() + previous.getLength();
- return new TypedRegion(endOffset, fDocument.getLength() - endOffset, IDocument.DEFAULT_CONTENT_TYPE);
-
- } catch (BadPositionCategoryException x) {
- } catch (BadLocationException x) {
- }
-
- return new TypedRegion(0, fDocument.getLength(), IDocument.DEFAULT_CONTENT_TYPE);
- }
-
- /*
- * @see IDocumentPartitioner#computePartitioning
- */
- public ITypedRegion[] computePartitioning(int offset, int length) {
- return computePartitioning(offset, length, false);
- }
-
- /*
- * @see IDocumentPartitioner#getLegalContentTypes
- */
- public String[] getLegalContentTypes() {
- return fLegalContentTypes;
- }
-
- /**
- * Returns whether the given type is one of the legal content types.
- *
- * @param contentType the content type to check
- * @return <code>true</code> if the content type is a legal content type
- */
- protected boolean isSupportedContentType(String contentType) {
- if (contentType != null) {
- for (int i= 0; i < fLegalContentTypes.length; i++) {
- if (fLegalContentTypes[i].equals(contentType))
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * Returns a content type encoded in the given token. If the token's
- * data is not <code>null</code> and a string it is assumed that
- * it is the encoded content type.
- *
- * @param token the token whose content type is to be determined
- * @return the token's content type
- */
- protected String getTokenContentType(IToken token) {
- Object data= token.getData();
- if (data instanceof String)
- return (String) data;
- return null;
- }
-
- /* zero-length partition support */
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthContentType(int)
- * @since 3.0
- */
- public String getContentType(int offset, boolean preferOpenPartitions) {
- return getPartition(offset, preferOpenPartitions).getType();
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#getZeroLengthPartition(int)
- * @since 3.0
- */
- public ITypedRegion getPartition(int offset, boolean preferOpenPartitions) {
- ITypedRegion region= getPartition(offset);
- if (preferOpenPartitions) {
- if (region.getOffset() == offset && !region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE)) {
- if (offset > 0) {
- region= getPartition(offset - 1);
- if (region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE))
- return region;
- }
- return new TypedRegion(offset, 0, IDocument.DEFAULT_CONTENT_TYPE);
- }
- }
- return region;
- }
-
- /*
- * @see org.eclipse.jface.text.IDocumentPartitionerExtension2#computeZeroLengthPartitioning(int, int)
- * @since 3.0
- */
- public ITypedRegion[] computePartitioning(int offset, int length, boolean includeZeroLengthPartitions) {
- List list= new ArrayList();
-
- try {
-
- int endOffset= offset + length;
-
- Position[] category= fDocument.getPositions(fPositionCategory);
-
- TypedPosition previous= null, current= null;
- int start, end, gapOffset;
- Position gap= null;
-
- for (int i= 0; i < category.length; i++) {
-
- current= (TypedPosition) category[i];
-
- gapOffset= (previous != null) ? previous.getOffset() + previous.getLength() : 0;
- gap= new Position(gapOffset, current.getOffset() - gapOffset);
- if ((includeZeroLengthPartitions || gap.getLength() > 0) && gap.overlapsWith(offset, length)) {
- start= Math.max(offset, gapOffset);
- end= Math.min(endOffset, gap.getOffset() + gap.getLength());
- list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
- }
-
- if (current.overlapsWith(offset, length)) {
- start= Math.max(offset, current.getOffset());
- end= Math.min(endOffset, current.getOffset() + current.getLength());
- list.add(new TypedRegion(start, end - start, current.getType()));
- }
-
- previous= current;
- }
-
- if (previous != null) {
- gapOffset= previous.getOffset() + previous.getLength();
- gap= new Position(gapOffset, fDocument.getLength() - gapOffset);
- if ((includeZeroLengthPartitions || gap.getLength() > 0) && ((includeZeroLengthPartitions && offset + length == gapOffset && gap.length == 0) || gap.overlapsWith(offset, length))) {
- start= Math.max(offset, gapOffset);
- end= Math.min(endOffset, fDocument.getLength());
- list.add(new TypedRegion(start, end - start, IDocument.DEFAULT_CONTENT_TYPE));
- }
- }
-
- if (list.isEmpty())
- list.add(new TypedRegion(offset, length, IDocument.DEFAULT_CONTENT_TYPE));
-
- } catch (BadPositionCategoryException x) {
- }
-
- TypedRegion[] result= new TypedRegion[list.size()];
- list.toArray(result);
- return result;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java
deleted file mode 100644
index ada89764fc4..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/RuleBasedScanner.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-
-
-/**
- * A generic scanner which can be "programmed" with a sequence of rules.
- * The scanner is used to get the next token by evaluating its rule in sequence until
- * one is successful. If a rule returns a token which is undefined, the scanner will proceed to
- * the next rule. Otherwise the token provided by the rule will be returned by
- * the scanner. If no rule returned a defined token, this scanner returns a token
- * which returns <code>true</code> when calling <code>isOther</code>, unless the end
- * of the file is reached. In this case the token returns <code>true</code> when calling
- * <code>isEOF</code>.
- *
- * @see IRule
- */
-public class RuleBasedScanner implements ICharacterScanner, ITokenScanner {
-
- /** The list of rules of this scanner */
- protected IRule[] fRules;
- /** The token to be returned by default if no rule fires */
- protected IToken fDefaultReturnToken;
- /** The document to be scanned */
- protected IDocument fDocument;
- /** The cached legal line delimiters of the document */
- protected char[][] fDelimiters;
- /** The offset of the next character to be read */
- protected int fOffset;
- /** The end offset of the range to be scanned */
- protected int fRangeEnd;
- /** The offset of the last read token */
- protected int fTokenOffset;
- /** The cached column of the current scanner position */
- protected int fColumn;
- /** Internal setting for the uninitialized column cache. */
- protected static final int UNDEFINED= -1;
-
- /**
- * Creates a new rule based scanner which does not have any rule.
- */
- public RuleBasedScanner() {
- }
-
- /**
- * Configures the scanner with the given sequence of rules.
- *
- * @param rules the sequence of rules controlling this scanner
- */
- public void setRules(IRule[] rules) {
- fRules= rules;
- }
-
- /**
- * Configures the scanner's default return token. This is the token
- * which is returned when non of the rules fired and EOF has not been
- * reached.
- *
- * @param defaultReturnToken the default return token
- * @since 2.0
- */
- public void setDefaultReturnToken(IToken defaultReturnToken) {
- Assert.isNotNull(defaultReturnToken.getData());
- fDefaultReturnToken= defaultReturnToken;
- }
-
- /*
- * @see ITokenScanner#setRange(IDocument, int, int)
- */
- public void setRange(IDocument document, int offset, int length) {
-
- fDocument= document;
- fOffset= offset;
- fColumn= UNDEFINED;
- fRangeEnd= Math.min(fDocument.getLength(), offset + length);
-
- String[] delimiters= fDocument.getLegalLineDelimiters();
- fDelimiters= new char[delimiters.length][];
- for (int i= 0; i < delimiters.length; i++)
- fDelimiters[i]= delimiters[i].toCharArray();
-
- if (fDefaultReturnToken == null)
- fDefaultReturnToken= new Token(null);
- }
-
- /*
- * @see ITokenScanner#getTokenOffset()
- */
- public int getTokenOffset() {
- return fTokenOffset;
- }
-
- /*
- * @see ITokenScanner#getTokenLength()
- */
- public int getTokenLength() {
- if (fOffset < fRangeEnd)
- return fOffset - getTokenOffset();
- return fRangeEnd - getTokenOffset();
- }
-
-
- /*
- * @see ICharacterScanner#getColumn()
- */
- public int getColumn() {
- if (fColumn == UNDEFINED) {
- try {
- int line= fDocument.getLineOfOffset(fOffset);
- int start= fDocument.getLineOffset(line);
-
- fColumn= fOffset - start;
-
- } catch (BadLocationException ex) {
- }
- }
- return fColumn;
- }
-
- /*
- * @see ICharacterScanner#getLegalLineDelimiters()
- */
- public char[][] getLegalLineDelimiters() {
- return fDelimiters;
- }
-
- /*
- * @see ITokenScanner#nextToken()
- */
- public IToken nextToken() {
-
- IToken token;
-
- while (true) {
-
- fTokenOffset= fOffset;
- fColumn= UNDEFINED;
-
- if (fRules != null) {
- for (int i= 0; i < fRules.length; i++) {
- token= (fRules[i].evaluate(this));
- if (!token.isUndefined())
- return token;
- }
- }
-
- if (read() == EOF)
- return Token.EOF;
- else
- return fDefaultReturnToken;
- }
- }
-
- /*
- * @see ICharacterScanner#read()
- */
- public int read() {
-
- try {
-
- if (fOffset < fRangeEnd) {
- try {
- return fDocument.getChar(fOffset);
- } catch (BadLocationException e) {
- }
- }
-
- return EOF;
-
- } finally {
- ++ fOffset;
- fColumn= UNDEFINED;
- }
- }
-
- /*
- * @see ICharacterScanner#unread()
- */
- public void unread() {
- --fOffset;
- }
-}
-
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
deleted file mode 100644
index feb2241c749..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/SingleLineRule.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- * Christopher Lenz (cmlenz@gmx.de) - support for line continuation
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-/**
- * A specific configuration of pattern rule whereby
- * the pattern begins with a specific sequence and may
- * end with a specific sequence, but will not span more
- * than a single line.
- */
-public class SingleLineRule extends PatternRule {
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specified token.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- */
- public SingleLineRule(String startSequence, String endSequence, IToken token) {
- this(startSequence, endSequence, token, (char) 0);
- }
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specified token.
- * Any character which follows the given escape character
- * will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- */
- public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter) {
- this(startSequence, endSequence, token, escapeCharacter, false);
- }
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specified token. Alternatively, the
- * line can also be ended with the end of the file.
- * Any character which follows the given escape character
- * will be ignored.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- * @param breaksOnEOF indicates whether the end of the file successfully terminates this rule
- * @since 2.1
- */
- public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF) {
- super(startSequence, endSequence, token, escapeCharacter, true, breaksOnEOF);
- }
-
- /**
- * Creates a rule for the given starting and ending sequence
- * which, if detected, will return the specified token. Alternatively, the
- * line can also be ended with the end of the file.
- * Any character which follows the given escape character
- * will be ignored. In addition, an escape character immediately before an
- * end of line can be set to continue the line.
- *
- * @param startSequence the pattern's start sequence
- * @param endSequence the pattern's end sequence
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- * @param breaksOnEOF indicates whether the end of the file successfully terminates this rule
- * @param escapeContinuesLine indicates whether the specified escape character is used for line
- * continuation, so that an end of line immediately after the escape character does not
- * terminate the line, even if <code>breakOnEOL</code> is true
- * @since 3.0
- */
- public SingleLineRule(String startSequence, String endSequence, IToken token, char escapeCharacter, boolean breaksOnEOF, boolean escapeContinuesLine) {
- super(startSequence, endSequence, token, escapeCharacter, true, breaksOnEOF, escapeContinuesLine);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java
deleted file mode 100644
index 928c1ba86a0..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/Token.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * Standard implementation of <code>IToken</code>.
- */
-public class Token implements IToken {
-
- /** Internal token type: Undefined */
- private static final int T_UNDEFINED= 0;
- /** Internal token type: EOF */
- private static final int T_EOF= 1;
- /** Internal token type: Whitespace */
- private static final int T_WHITESPACE= 2;
- /** Internal token type: Others */
- private static final int T_OTHER= 3;
-
-
- /**
- * Standard token: Undefined.
- */
- public static final IToken UNDEFINED= new Token(T_UNDEFINED);
- /**
- * Standard token: End Of File.
- */
- public static final IToken EOF= new Token(T_EOF);
- /**
- * Standard token: Whitespace.
- */
- public static final IToken WHITESPACE= new Token(T_WHITESPACE);
-
- /**
- * Standard token: Neither {@link #UNDEFINED}, {@link #WHITESPACE}, nor {@link #EOF}.
- * @deprecated will be removed
- */
- public static final IToken OTHER= new Token(T_OTHER);
-
- /** The type of this token */
- private int fType;
- /** The data associated with this token */
- private Object fData;
-
- /**
- * Creates a new token according to the given specification which does not
- * have any data attached to it.
- *
- * @param type the type of the token
- * @since 2.0
- */
- private Token(int type) {
- fType= type;
- fData= null;
- }
-
- /**
- * Creates a new token which represents neither undefined, whitespace, nor EOF.
- * The newly created token has the given data attached to it.
- *
- * @param data the data attached to the newly created token
- */
- public Token(Object data) {
- fType= T_OTHER;
- fData= data;
- }
-
- /**
- * Reinitializes the data of this token. The token may not represent
- * undefined, whitespace, or EOF.
- *
- * @param data to be attached to the token
- * @since 2.0
- */
- public void setData(Object data) {
- Assert.isTrue(isOther());
- fData= data;
- }
-
- /*
- * @see IToken#getData()
- */
- public Object getData() {
- return fData;
- }
-
- /*
- * @see IToken#isOther()
- */
- public boolean isOther() {
- return (fType == T_OTHER);
- }
-
- /*
- * @see IToken#isEOF()
- */
- public boolean isEOF() {
- return (fType == T_EOF);
- }
-
- /*
- * @see IToken#isWhitespace()
- */
- public boolean isWhitespace() {
- return (fType == T_WHITESPACE);
- }
-
- /*
- * @see IToken#isUndefined()
- */
- public boolean isUndefined() {
- return (fType == T_UNDEFINED);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java
deleted file mode 100644
index 284c1d75216..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WhitespaceRule.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * An implementation of <code>IRule</code> capable of detecting whitespace.
- * A whitespace rule uses a whitespace detector in order to find out which
- * characters are whitespace characters.
- *
- * @see IWhitespaceDetector
- */
-public class WhitespaceRule implements IRule {
-
- /** The whitespace detector used by this rule */
- protected IWhitespaceDetector fDetector;
-
- /**
- * Creates a rule which, with the help of an
- * whitespace detector, will return a whitespace
- * token when a whitespace is detected.
- *
- * @param detector the rule's whitespace detector, may not be <code>null</code>
- */
- public WhitespaceRule(IWhitespaceDetector detector) {
- Assert.isNotNull(detector);
- fDetector= detector;
- }
-
- /*
- * @see IRule#evaluate(ICharacterScanner)
- */
- public IToken evaluate(ICharacterScanner scanner) {
- int c= scanner.read();
- if (fDetector.isWhitespace((char) c)) {
- do {
- c= scanner.read();
- } while (fDetector.isWhitespace((char) c));
- scanner.unread();
- return Token.WHITESPACE;
- } else {
- scanner.unread();
- return Token.UNDEFINED;
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java
deleted file mode 100644
index b9014b833df..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordPatternRule.java
+++ /dev/null
@@ -1,108 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-import org.eclipse.jface.text.Assert;
-
-
-
-/**
- * A specific single line rule which stipulates that the start
- * and end sequence occur within a single word, as defined by a word detector.
- *
- * @see IWordDetector
- */
-public class WordPatternRule extends SingleLineRule {
-
- /** The word detector used by this rule */
- protected IWordDetector fDetector;
- /** The internal buffer used for pattern detection */
- private StringBuffer fBuffer= new StringBuffer();
-
- /**
- * Creates a rule for the given starting and ending word
- * pattern which, if detected, will return the specified token.
- * A word detector is used to identify words.
- *
- * @param detector the word detector to be used
- * @param startSequence the start sequence of the word pattern
- * @param endSequence the end sequence of the word pattern
- * @param token the token to be returned on success
- */
- public WordPatternRule(IWordDetector detector, String startSequence, String endSequence, IToken token) {
- this(detector, startSequence, endSequence, token, (char)0);
- }
-
- /**
- /**
- * Creates a rule for the given starting and ending word
- * pattern which, if detected, will return the specified token.
- * A word detector is used to identify words.
- * Any character which follows the given escapeCharacter will be ignored.
- *
- * @param detector the word detector to be used
- * @param startSequence the start sequence of the word pattern
- * @param endSequence the end sequence of the word pattern
- * @param token the token to be returned on success
- * @param escapeCharacter the escape character
- */
- public WordPatternRule(IWordDetector detector, String startSequence, String endSequence, IToken token, char escapeCharacter) {
- super(startSequence, endSequence, token, escapeCharacter);
- Assert.isNotNull(detector);
- fDetector= detector;
- }
-
- /**
- * Returns whether the end sequence was detected.
- * The rule acquires the rest of the word, using the
- * provided word detector, and tests to determine if
- * it ends with the end sequence.
- *
- * @param scanner the scanner to be used
- * @return <code>true</code> if the word ends on the given end sequence
- */
- protected boolean endSequenceDetected(ICharacterScanner scanner) {
- fBuffer.setLength(0);
- int c= scanner.read();
- while (fDetector.isWordPart((char) c)) {
- fBuffer.append((char) c);
- c= scanner.read();
- }
- scanner.unread();
-
- if (fBuffer.length() >= fEndSequence.length) {
- for (int i=fEndSequence.length - 1, j= fBuffer.length() - 1; i >= 0; i--, j--) {
- if (fEndSequence[i] != fBuffer.charAt(j)) {
- unreadBuffer(scanner);
- return false;
- }
- }
- return true;
- }
-
- unreadBuffer(scanner);
- return false;
- }
-
- /**
- * Returns the characters in the buffer to the scanner.
- * Note that the rule must also return the characters
- * read in as part of the start sequence expect the first one.
- *
- * @param scanner the scanner to be used
- */
- protected void unreadBuffer(ICharacterScanner scanner) {
- fBuffer.insert(0, fStartSequence);
- for (int i= fBuffer.length() - 1; i > 0; i--)
- scanner.unread();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java
deleted file mode 100644
index 5681074a65b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/WordRule.java
+++ /dev/null
@@ -1,145 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.rules;
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-import org.eclipse.jface.text.Assert;
-
-
-/**
- * An implementation of <code>IRule</code> capable of detecting words
- * Word rules also allow for the association of tokens with specific words.
- * That is, not only can the rule be used to provide tokens for exact matches,
- * but also for the generalized notion of a word in the context in which it is used.
- * A word rules uses a word detector to determine what a word is.
- *
- * @see IWordDetector
- */
-public class WordRule implements IRule {
-
- /** Internal setting for the uninitialized column constraint */
- protected static final int UNDEFINED= -1;
-
- /** The word detector used by this rule */
- protected IWordDetector fDetector;
- /** The default token to be returned on success and if nothing else has been specified. */
- protected IToken fDefaultToken;
- /** The column constraint */
- protected int fColumn= UNDEFINED;
- /** The table of predefined words and token for this rule */
- protected Map fWords= new HashMap();
- /** Buffer used for pattern detection */
- private StringBuffer fBuffer= new StringBuffer();
-
- /**
- * Creates a rule which, with the help of an word detector, will return the token
- * associated with the detected word. If no token has been associated, the scanner
- * will be rolled back and an undefined token will be returned in order to allow
- * any subsequent rules to analyze the characters.
- *
- * @param detector the word detector to be used by this rule, may not be <code>null</code>
- *
- * @see #addWord(String, IToken)
- */
- public WordRule(IWordDetector detector) {
- this(detector, Token.UNDEFINED);
- }
-
- /**
- * Creates a rule which, with the help of an word detector, will return the token
- * associated with the detected word. If no token has been associated, the
- * specified default token will be returned.
- *
- * @param detector the word detector to be used by this rule, may not be <code>null</code>
- * @param defaultToken the default token to be returned on success
- * if nothing else is specified, may not be <code>null</code>
- *
- * @see #addWord(String, IToken)
- */
- public WordRule(IWordDetector detector, IToken defaultToken) {
-
- Assert.isNotNull(detector);
- Assert.isNotNull(defaultToken);
-
- fDetector= detector;
- fDefaultToken= defaultToken;
- }
-
- /**
- * Adds a word and the token to be returned if it is detected.
- *
- * @param word the word this rule will search for, may not be <code>null</code>
- * @param token the token to be returned if the word has been found, may not be <code>null</code>
- */
- public void addWord(String word, IToken token) {
- Assert.isNotNull(word);
- Assert.isNotNull(token);
-
- fWords.put(word, token);
- }
-
- /**
- * Sets a column constraint for this rule. If set, the rule's token
- * will only be returned if the pattern is detected starting at the
- * specified column. If the column is smaller then 0, the column
- * constraint is considered removed.
- *
- * @param column the column in which the pattern starts
- */
- public void setColumnConstraint(int column) {
- if (column < 0)
- column= UNDEFINED;
- fColumn= column;
- }
-
- /*
- * @see IRule#evaluate(ICharacterScanner)
- */
- public IToken evaluate(ICharacterScanner scanner) {
- int c= scanner.read();
- if (fDetector.isWordStart((char) c)) {
- if (fColumn == UNDEFINED || (fColumn == scanner.getColumn() - 1)) {
-
- fBuffer.setLength(0);
- do {
- fBuffer.append((char) c);
- c= scanner.read();
- } while (c != ICharacterScanner.EOF && fDetector.isWordPart((char) c));
- scanner.unread();
-
- IToken token= (IToken) fWords.get(fBuffer.toString());
- if (token != null)
- return token;
-
- if (fDefaultToken.isUndefined())
- unreadBuffer(scanner);
-
- return fDefaultToken;
- }
- }
-
- scanner.unread();
- return Token.UNDEFINED;
- }
-
- /**
- * Returns the characters in the buffer to the scanner.
- *
- * @param scanner the scanner to be used
- */
- protected void unreadBuffer(ICharacterScanner scanner) {
- for (int i= fBuffer.length() - 1; i >= 0; i--)
- scanner.unread();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/package.html
deleted file mode 100644
index 253c05333b5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/rules/package.html
+++ /dev/null
@@ -1,21 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a framework for rule based text scanning
-and uses the framework to provide rule-driven default implementations of
-<tt>IPresentationDamager</tt>, <tt>IPresentationRepairer</tt> and <tt>IDocumentPartitioner</tt>.
-<h2>
-Package Specification</h2>
-<tt>RuleBasedScanner</tt> is a document-based scanner controlled by <tt>IRule</tt>
-objects. When evaluated an <tt>IRule</tt> always returns an <tt>IToken</tt>.
-The package provides a set of rules whereby <tt>PatternRule</tt> is the
-most important one. <tt>PatternRule</tt> defines a pattern-configurable
-rule.
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
deleted file mode 100644
index 0bdbd1b8640..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationBarHoverManager.java
+++ /dev/null
@@ -1,555 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import java.util.Iterator;
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlEvent;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackAdapter;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.text.AbstractHoverInformationControlManager;
-import org.eclipse.jface.text.AbstractInformationControlManager;
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextUtilities;
-
-
-/**
- * This manager controls the layout, content, and visibility of an information
- * control in reaction to mouse hover events issued by the vertical ruler of a
- * source viewer.
- * @since 2.0
- */
-public class AnnotationBarHoverManager extends AbstractHoverInformationControlManager {
-
- /**
- * The information control closer for the hover information. Closes the information control as
- * soon as the mouse pointer leaves the subject area, a mouse button is pressed, the user presses a key,
- * or the subject control is resized or moved.
- *
- * @since 3.0
- */
- protected class Closer extends MouseTrackAdapter
- implements IInformationControlCloser, MouseListener, MouseMoveListener, ControlListener, KeyListener, DisposeListener {
-
- /** The closer's subject control */
- private Control fSubjectControl;
- /** The subject area */
- private Rectangle fSubjectArea;
- /** Indicates whether this closer is active */
- private boolean fIsActive= false;
- /** The information control. */
- private IInformationControl fInformationControl;
-
- /**
- * Creates a new information control closer.
- */
- public Closer() {
- }
-
- /*
- * @see IInformationControlCloser#setSubjectControl(Control)
- */
- public void setSubjectControl(Control control) {
- fSubjectControl= control;
- }
-
- /*
- * @see IInformationControlCloser#setHoverControl(IHoverControl)
- */
- public void setInformationControl(IInformationControl control) {
- fInformationControl= control;
- }
-
- /*
- * @see IInformationControlCloser#start(Rectangle)
- */
- public void start(Rectangle subjectArea) {
-
- if (fIsActive) return;
- fIsActive= true;
-
- fSubjectArea= subjectArea;
-
- fInformationControl.addDisposeListener(this);
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.addMouseListener(this);
- fSubjectControl.addMouseMoveListener(this);
- fSubjectControl.addMouseTrackListener(this);
- }
-
- // install control and key listeners on subject control in any case
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.addControlListener(this);
- fSubjectControl.addKeyListener(this);
- }
- }
-
- /*
- * @see IInformationControlCloser#stop()
- */
- public void stop() {
- stop(false);
- }
-
- /**
- * Stops the information control and if <code>delayRestart</code> is set
- * allows restart only after a certain delay.
- *
- * @param delayRestart <code>true</code> if restart should be delayed
- */
- protected void stop(boolean delayRestart) {
-
- if (!fIsActive) return;
- fIsActive= false;
-
- hideInformationControl();
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeMouseListener(this);
- fSubjectControl.removeMouseMoveListener(this);
- fSubjectControl.removeMouseTrackListener(this);
- }
-
- if (fSubjectControl != null && !fSubjectControl.isDisposed()) {
- fSubjectControl.removeControlListener(this);
- fSubjectControl.removeKeyListener(this);
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
- if (!fSubjectArea.contains(event.x, event.y))
- stop();
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent event) {
- }
-
- /*
- * @see MouseListener#mouseDown(MouseEvent)
- */
- public void mouseDown(MouseEvent event) {
- stop();
- }
-
- /*
- * @see MouseListener#mouseDoubleClick(MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent event) {
- stop();
- }
-
- /*
- * @see MouseTrackAdapter#mouseExit(MouseEvent)
- */
- public void mouseExit(MouseEvent event) {
- if (!fAllowMouseExit)
- stop();
- }
-
- /*
- * @see ControlListener#controlResized(ControlEvent)
- */
- public void controlResized(ControlEvent event) {
- stop();
- }
-
- /*
- * @see ControlListener#controlMoved(ControlEvent)
- */
- public void controlMoved(ControlEvent event) {
- stop();
- }
-
- /*
- * @see KeyListener#keyReleased(KeyEvent)
- */
- public void keyReleased(KeyEvent event) {
- }
-
- /*
- * @see KeyListener#keyPressed(KeyEvent)
- */
- public void keyPressed(KeyEvent event) {
- stop(true);
- }
-
- /*
- * @see org.eclipse.swt.events.DisposeListener#widgetDisposed(org.eclipse.swt.events.DisposeEvent)
- */
- public void widgetDisposed(DisposeEvent e) {
- stop();
- }
- }
-
- /** The source viewer the manager is connected to */
- private ISourceViewer fSourceViewer;
- /** The vertical ruler the manager is registered with */
- private IVerticalRulerInfo fVerticalRulerInfo;
- /** The annotation hover the manager uses to retrieve the information to display */
- private IAnnotationHover fAnnotationHover;
- /**
- * Indicates whether the mouse cursor is allowed to leave the subject area without closing the hover.
- * @since 3.0
- */
- protected boolean fAllowMouseExit= false;
-
- /**
- * Creates an annotation hover manager with the given parameters. In addition,
- * the hovers anchor is RIGHT and the margin is 5 points to the right.
- *
- * @param sourceViewer the source viewer this manager connects to
- * @param ruler the vertical ruler this manager connects to
- * @param annotationHover the annotation hover providing the information to be displayed
- * @param creator the information control creator
- * @deprecated As of 2.1, replaced by {@link AnnotationBarHoverManager#AnnotationBarHoverManager(IVerticalRulerInfo, ISourceViewer, IAnnotationHover, IInformationControlCreator)}
- */
- public AnnotationBarHoverManager(ISourceViewer sourceViewer, IVerticalRuler ruler, IAnnotationHover annotationHover, IInformationControlCreator creator) {
- this(ruler, sourceViewer, annotationHover, creator);
- }
-
- /**
- * Creates an annotation hover manager with the given parameters. In addition,
- * the hovers anchor is RIGHT and the margin is 5 points to the right.
- *
- * @param rulerInfo the vertical ruler this manager connects to
- * @param sourceViewer the source viewer this manager connects to
- * @param annotationHover the annotation hover providing the information to be displayed
- * @param creator the information control creator
- * @since 2.1
- */
- public AnnotationBarHoverManager(IVerticalRulerInfo rulerInfo, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
- super(creator);
-
- Assert.isNotNull(sourceViewer);
- Assert.isNotNull(annotationHover);
-
- fSourceViewer= sourceViewer;
- fVerticalRulerInfo= rulerInfo;
- fAnnotationHover= annotationHover;
-
- setAnchor(ANCHOR_RIGHT);
- setMargins(5, 0);
- setCloser(new Closer());
- }
-
- /*
- * @see AbstractHoverInformationControlManager#computeInformation()
- */
- protected void computeInformation() {
- fAllowMouseExit= false;
- MouseEvent event= getHoverEvent();
- IAnnotationHover hover= getHover(event);
-
- int line= getHoverLine(event);
-
- if (hover instanceof IAnnotationHoverExtension) {
- IAnnotationHoverExtension extension= (IAnnotationHoverExtension) hover;
- setCustomInformationControlCreator(extension.getHoverControlCreator());
- ILineRange range= extension.getHoverLineRange(fSourceViewer, line);
- range= adaptLineRange(range, line);
- if (range != null)
- setInformation(extension.getHoverInfo(fSourceViewer, range, computeNumberOfVisibleLines()), computeArea(range));
- else
- setInformation(null, null);
-
- } else {
- setCustomInformationControlCreator(null);
- setInformation(hover.getHoverInfo(fSourceViewer, line), computeArea(line));
- }
-
- }
-
- private ILineRange adaptLineRange(ILineRange lineRange, int line) {
- if (lineRange != null) {
- lineRange= adaptLineRangeToFolding(lineRange, line);
- if (lineRange != null)
- return adaptLineRangeToViewport(lineRange);
- }
- return null;
- }
-
- private ILineRange adaptLineRangeToFolding(ILineRange lineRange, int line) {
-
- if (fSourceViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
-
- try {
- IRegion region= convertToRegion(lineRange);
- IRegion[] coverage= extension.getCoveredModelRanges(region);
- if (coverage != null && coverage.length > 0) {
- IRegion container= findRegionContainingLine(coverage, line);
- if (container != null)
- return convertToLineRange(container);
- }
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- return lineRange;
- }
-
- private ILineRange adaptLineRangeToViewport(ILineRange lineRange) {
-
- try {
- StyledText text= fSourceViewer.getTextWidget();
-
- int topLine= text.getTopIndex();
- int rangeTopLine= getWidgetLineNumber(lineRange.getStartLine());
- int topDelta= Math.max(topLine - rangeTopLine, 0);
-
- int lineHeight= text.getLineHeight();
- Rectangle size= text.getClientArea();
- Rectangle trim= text.computeTrim(0, 0, 0, 0);
- int height= size.height - trim.height;
-
- int bottomLine= topLine + (height / lineHeight);
- int rangeBottomLine= getWidgetLineNumber(lineRange.getStartLine() + lineRange.getNumberOfLines() - 1);
- int bottomDelta= Math.max(rangeBottomLine - bottomLine, 0);
-
- return new LineRange(lineRange.getStartLine() + topDelta, lineRange.getNumberOfLines() - bottomDelta);
-
- } catch (BadLocationException x) {
- }
-
- return null;
- }
-
- private IRegion convertToRegion(ILineRange lineRange) throws BadLocationException {
- IDocument document= fSourceViewer.getDocument();
- int startOffset= document.getLineOffset(lineRange.getStartLine());
- int endLine= lineRange.getStartLine() + Math.max(0, lineRange.getNumberOfLines() - 1);
- IRegion lineInfo= document.getLineInformation(endLine);
- int endOffset= lineInfo.getOffset() + lineInfo.getLength();
- return new Region(startOffset, endOffset - startOffset);
- }
-
- private IRegion findRegionContainingLine(IRegion[] regions, int line) throws BadLocationException {
- IDocument document= fSourceViewer.getDocument();
- IRegion lineInfo= document.getLineInformation(line);
- for (int i= 0; i < regions.length; i++) {
- if (TextUtilities.overlaps(regions[i], lineInfo))
- return regions[i];
- }
- return null;
- }
-
- private ILineRange convertToLineRange(IRegion region) throws BadLocationException {
- IDocument document= fSourceViewer.getDocument();
- int startLine= document.getLineOfOffset(region.getOffset());
- int endLine= document.getLineOfOffset(region.getOffset() + region.getLength());
- return new LineRange(startLine, endLine - startLine + 1);
- }
-
- private Rectangle computeArea(ILineRange lineRange) {
- try {
- StyledText text= fSourceViewer.getTextWidget();
- int lineHeight= text.getLineHeight();
- int y= getWidgetLineNumber(lineRange.getStartLine()) * lineHeight - text.getTopPixel();
- Point size= fVerticalRulerInfo.getControl().getSize();
- return new Rectangle(0, y, size.x, lineHeight * lineRange.getNumberOfLines());
- } catch (BadLocationException x) {
- }
- return null;
- }
-
- private int computeNumberOfVisibleLines() {
- StyledText text= fSourceViewer.getTextWidget();
- Point size= fVerticalRulerInfo.getControl().getSize();
- return size.y / text.getLineHeight();
- }
-
- /**
- * Determines the hover to be used to display information based on the source of the
- * mouse hover event. If <code>fVerticalRulerInfo</code> is not a composite ruler, the
- * standard hover is returned.
- *
- * @param event the source of the mouse hover event
- * @return the hover depending on <code>source</code>, or <code>fAnnotationHover</code> if none can be found.
- * @since 3.0
- */
- private IAnnotationHover getHover(MouseEvent event) {
- if (event == null || event.getSource() == null)
- return fAnnotationHover;
-
- if (fVerticalRulerInfo instanceof CompositeRuler) {
- CompositeRuler comp= (CompositeRuler) fVerticalRulerInfo;
- for (Iterator it= comp.getDecoratorIterator(); it.hasNext();) {
- Object o= it.next();
- if (o instanceof IVerticalRulerInfoExtension && o instanceof IVerticalRulerInfo) {
- if (((IVerticalRulerInfo) o).getControl() == event.getSource()) {
- IAnnotationHover hover= ((IVerticalRulerInfoExtension) o).getHover();
- if (hover != null)
- return hover;
- }
- }
- }
- }
- return fAnnotationHover;
- }
-
- /**
- * Returns the line of interest deduced from the mouse hover event.
- *
- * @param event a mouse hover event that triggered hovering
- * @return the document model line number on which the hover event occurred or <code>-1</code> if there is no event
- * @since 3.0
- */
- private int getHoverLine(MouseEvent event) {
- return event == null ? -1 : fVerticalRulerInfo.toDocumentLineNumber(event.y);
- }
-
- /**
- * Returns for the widget line number for the given document line number.
- *
- * @param line the absolute line number
- * @return the line number relative to the viewer's visible region
- * @throws BadLocationException if <code>line</code> is not valid in the viewer's document
- */
- private int getWidgetLineNumber(int line) throws BadLocationException {
- if (fSourceViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
- return extension.modelLine2WidgetLine(line);
- }
-
- IRegion region= fSourceViewer.getVisibleRegion();
- int firstLine= fSourceViewer.getDocument().getLineOfOffset(region.getOffset());
- return line - firstLine;
- }
-
- /**
- * Determines graphical area covered by the given line.
- *
- * @param line the number of the line in the viewer whose graphical extend in the vertical ruler must be computed
- * @return the graphical extend of the given line
- */
- private Rectangle computeArea(int line) {
- try {
- StyledText text= fSourceViewer.getTextWidget();
- int lineHeight= text.getLineHeight();
- int y= getWidgetLineNumber(line) * lineHeight - text.getTopPixel();
- Point size= fVerticalRulerInfo.getControl().getSize();
- return new Rectangle(0, y, size.x, lineHeight);
- } catch (BadLocationException x) {
- }
- return null;
- }
-
- /**
- * Returns the annotation hover for this hover manager.
- *
- * @return the annotation hover for this hover manager
- * @since 2.1
- */
- protected IAnnotationHover getAnnotationHover() {
- return fAnnotationHover;
- }
-
- /**
- * Returns the source viewer for this hover manager.
- *
- * @return the source viewer for this hover manager
- * @since 2.1
- */
- protected ISourceViewer getSourceViewer() {
- return fSourceViewer;
- }
-
- /**
- * Returns the vertical ruler info for this hover manager
- *
- * @return the vertical ruler info for this hover manager
- * @since 2.1
- */
- protected IVerticalRulerInfo getVerticalRulerInfo() {
- return fVerticalRulerInfo;
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractInformationControlManager#computeSizeConstraints(org.eclipse.swt.widgets.Control, org.eclipse.swt.graphics.Rectangle, org.eclipse.jface.text.IInformationControl)
- * @since 3.0
- */
- protected Point computeSizeConstraints(Control subjectControl, Rectangle subjectArea, IInformationControl informationControl) {
-
- Point constraints= super.computeSizeConstraints(subjectControl, subjectArea, informationControl);
-
- StyledText styledText= fSourceViewer.getTextWidget();
- if (styledText != null) {
- Rectangle r= styledText.getClientArea();
- if (r != null)
- constraints.x= r.width;
- }
-
- Point size= fVerticalRulerInfo.getControl().getSize();
- constraints.y= size.y - subjectArea.y;
-
- return constraints;
- }
-
- /*
- * @see org.eclipse.jface.text.AbstractInformationControlManager#computeLocation(org.eclipse.swt.graphics.Rectangle, org.eclipse.swt.graphics.Point, org.eclipse.jface.text.AbstractInformationControlManager.Anchor)
- * @since 3.0
- */
- protected Point computeLocation(Rectangle subjectArea, Point controlSize, Anchor anchor) {
- MouseEvent event= getHoverEvent();
- IAnnotationHover hover= getHover(event);
-
- boolean allowMouseExit= false;
- if (hover instanceof IAnnotationHoverExtension) {
- IAnnotationHoverExtension extension= (IAnnotationHoverExtension) hover;
- allowMouseExit= extension.canHandleMouseCursor();
- }
-
- if (allowMouseExit) {
- fAllowMouseExit= true;
-
- Control subjectControl= getSubjectControl();
- // return a location that just overlaps the annotation on the bar
- if (anchor == AbstractInformationControlManager.ANCHOR_RIGHT)
- return subjectControl.toDisplay(subjectArea.x - 4, subjectArea.y - 2);
- else if (anchor == AbstractHoverInformationControlManager.ANCHOR_LEFT)
- return subjectControl.toDisplay(subjectArea.x + subjectArea.width - controlSize.x + 4, subjectArea.y - 2);
- }
-
- fAllowMouseExit= false;
- return super.computeLocation(subjectArea, controlSize, anchor);
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java
deleted file mode 100644
index e021ffd3dc0..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationColumn.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-/**
- * @deprecated use <code>AnnotationRulerColumn</code> instead.
- * @since 2.0
- */
-public final class AnnotationColumn extends AnnotationRulerColumn {
-
- /**
- * Creates a new <code>AnnotationColumn</code> of the given width.
- *
- * @param width the width of this column
- * @deprecated
- */
- public AnnotationColumn(int width) {
- super(width);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
deleted file mode 100644
index 0636af3ad76..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationPainter.java
+++ /dev/null
@@ -1,1394 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.core.runtime.Platform;
-
-import org.eclipse.swt.custom.StyleRange;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IPaintPositionManager;
-import org.eclipse.jface.text.IPainter;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextInputListener;
-import org.eclipse.jface.text.ITextPresentationListener;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextPresentation;
-
-
-/**
- * Paints annotations provided by an annotation model as squiggly lines and/or
- * highlighted onto an associated source viewer.
- * Clients usually instantiate and configure objects of this class.
- *
- * @since 2.1
- */
-public class AnnotationPainter implements IPainter, PaintListener, IAnnotationModelListener, IAnnotationModelListenerExtension, ITextPresentationListener {
-
-
- /**
- * A drawing strategy responsible for drawing a certain decoration.
- *
- * @since 3.0
- */
- public interface IDrawingStrategy {
- /**
- * Draws a decoration of the given length start at the given offset in the
- * given color onto the specified GC.
- *
- * @param annotation the annotation to be drawn
- * @param gc the graphical context
- * @param textWidget the text widget to draw on
- * @param offset the offset of the line
- * @param length the length of the line
- * @param color the color of the line
- */
- void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color);
- }
-
- /**
- * Squiggles drawing strategy.
- *
- * @since 3.0
- */
- public static class SquigglesStrategy implements IDrawingStrategy {
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.jface.text.source.Annotation, org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color)
- * @since 3.0
- */
- public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
- if (gc != null) {
-
- Point left= textWidget.getLocationAtOffset(offset);
- Point right= textWidget.getLocationAtOffset(offset + length);
-
- gc.setForeground(color);
- int[] polyline= computePolyline(left, right, textWidget.getBaseline(), textWidget.getLineHeight());
- gc.drawPolyline(polyline);
-
- } else {
- textWidget.redrawRange(offset, length, true);
- }
- }
-
- /**
- * Computes an array of alternating x and y values which are the corners of the squiggly line of the
- * given height between the given end points.
- *
- * @param left the left end point
- * @param right the right end point
- * @param baseline the font's baseline
- * @param lineHeight the height of the line
- * @return the array of alternating x and y values which are the corners of the squiggly line
- */
- private int[] computePolyline(Point left, Point right, int baseline, int lineHeight) {
-
- final int WIDTH= 4; // must be even
- final int HEIGHT= 2; // can be any number
-// final int MINPEEKS= 2; // minimal number of peeks
-
- int peeks= (right.x - left.x) / WIDTH;
-// if (peeks < MINPEEKS) {
-// int missing= (MINPEEKS - peeks) * WIDTH;
-// left.x= Math.max(0, left.x - missing/2);
-// peeks= MINPEEKS;
-// }
-
- int leftX= left.x;
-
- // compute (number of point) * 2
- int length= ((2 * peeks) + 1) * 2;
- if (length < 0)
- return new int[0];
-
- int[] coordinates= new int[length];
-
- // cache peeks' y-coordinates
- int top= left.y + Math.min(baseline + 1, lineHeight - HEIGHT - 1);
- int bottom= top + HEIGHT;
-
- // populate array with peek coordinates
- for (int i= 0; i < peeks; i++) {
- int index= 4 * i;
- coordinates[index]= leftX + (WIDTH * i);
- coordinates[index+1]= bottom;
- coordinates[index+2]= coordinates[index] + WIDTH/2;
- coordinates[index+3]= top;
- }
-
- // the last down flank is missing
- coordinates[length-2]= left.x + (WIDTH * peeks);
- coordinates[length-1]= bottom;
-
- return coordinates;
- }
- }
-
- /**
- * Drawing strategy that does nothing.
- * @since 3.0
- */
- public static final class NullStrategy implements IDrawingStrategy {
-
- /*
- * @see org.eclipse.jface.text.source.AnnotationPainter.IDrawingStrategy#draw(org.eclipse.jface.text.source.Annotation, org.eclipse.swt.graphics.GC, org.eclipse.swt.custom.StyledText, int, int, org.eclipse.swt.graphics.Color)
- * @since 3.0
- */
- public void draw(Annotation annotation, GC gc, StyledText textWidget, int offset, int length, Color color) {
- // do nothing
- }
- }
-
- /**
- * Implementation of <code>IRegion</code> that can be reused
- * by setting the offset and the length.
- */
- private static class ReusableRegion implements IRegion {
-
- private int fOffset;
- private int fLength;
-
- /*
- * @see org.eclipse.jface.text.IRegion#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see org.eclipse.jface.text.IRegion#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /**
- * Updates this region.
- *
- * @param offset the new offset
- * @param length the new length
- */
- public void update(int offset, int length) {
- fOffset= offset;
- fLength= length;
- }
- }
-
- /**
- * Tells whether this class is in debug mode.
- * @since 3.0
- */
- private static boolean DEBUG= "true".equalsIgnoreCase(Platform.getDebugOption("org.eclipse.jface.text/debug/AnnotationPainter")); //$NON-NLS-1$//$NON-NLS-2$
- /**
- * The squiggly painter strategy.
- * @since 3.0
- */
- private static final IDrawingStrategy fgSquigglyDrawer= new SquigglesStrategy();
- /**
- * The squiggles painter id.
- * @since 3.0
- */
- private static final Object SQUIGGLES= new Object();
- /**
- * The default strategy that does nothing.
- * @since 3.0
- */
- private static final IDrawingStrategy fgNullDrawer= new NullStrategy();
-
- /**
- * The presentation information (decoration) for an annotation. Each such
- * object represents one decoration drawn on the text area, such as squiggly lines
- * and underlines.
- */
- private static class Decoration {
- /** The position of this decoration */
- private Position fPosition;
- /** The color of this decoration */
- private Color fColor;
- /**
- * The annotation's layer
- * @since 3.0
- */
- private int fLayer;
- /**
- * The painter strategy for this decoration.
- * @since 3.0
- */
- private IDrawingStrategy fPainter;
- }
-
- /** Indicates whether this painter is active */
- private boolean fIsActive= false;
- /** Indicates whether this painter is managing decorations */
- private boolean fIsPainting= false;
- /** Indicates whether this painter is setting its annotation model */
- private volatile boolean fIsSettingModel= false;
- /** The associated source viewer */
- private ISourceViewer fSourceViewer;
- /** The cached widget of the source viewer */
- private StyledText fTextWidget;
- /** The annotation model providing the annotations to be drawn */
- private IAnnotationModel fModel;
- /** The annotation access */
- private IAnnotationAccess fAnnotationAccess;
- /**
- * The map with decorations
- * @since 3.0
- */
- private Map fDecorationsMap= new HashMap(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767
- /**
- * The map with of highlighted decorations.
- * @since 3.0
- */
- private Map fHighlightedDecorationsMap= new HashMap(); // see https://bugs.eclipse.org/bugs/show_bug.cgi?id=50767
- /**
- * Mutex for highlighted decorations map.
- * @since 3.0
- */
- private Object fDecorationMapLock= new Object();
- /**
- * Mutex for for decorations map.
- * @since 3.0
- */
- private Object fHighlightedDecorationsMapLock= new Object();
- /** The internal color table */
- private Map fColorTable= new HashMap();
- /**
- * The list of configured annotation types for being painted by this painter.
- * @since 3.0
- */
- private Set fConfiguredAnnotationTypes= new HashSet();
- /**
- * The list of allowed annotation types for being painted by this painter.
- * @since 3.0
- */
- private Set fAllowedAnnotationTypes= new HashSet();
- /**
- * The list of configured annotation typed to be highlighted by this painter.
- * @since 3.0
- */
- private Set fConfiguredHighlightAnnotationTypes= new HashSet();
- /**
- * The list of allowed annotation types to be highlighted by this painter.
- * @since 3.0
- */
- private Set fAllowedHighlightAnnotationTypes= new HashSet();
- /**
- * The range in which the current highlight annotations can be found.
- * @since 3.0
- */
- private Position fCurrentHighlightAnnotationRange= null;
- /**
- * The range in which all add, removed and changed highlight
- * annotations can be found since the last world change.
- * @since 3.0
- */
- private Position fTotalHighlightAnnotationRange= null;
- /**
- * The text input listener.
- * @since 3.0
- */
- private ITextInputListener fTextInputListener;
- /**
- * Flag which tells that a new document input is currently being set.
- * @since 3.0
- */
- private boolean fInputDocumentAboutToBeChanged;
- /**
- * Maps annotation types to drawing strategy ids.
- * @since 3.0
- */
- private Map fAnnotationType2DrawingStrategyId= new HashMap();
- /**
- * Maps drawing strategy ids to drawing strategies.
- * @since 3.0
- */
- private Map fRegisteredDrawingStrategies= new HashMap();
-
-
- /**
- * Creates a new annotation painter for the given source viewer and with the given
- * annotation access. The painter is uninitialized, i.e. no annotation types are configured
- * to be painted.
- *
- * @param sourceViewer the source viewer for this painter
- * @param access the annotation access for this painter
- */
- public AnnotationPainter(ISourceViewer sourceViewer, IAnnotationAccess access) {
- fSourceViewer= sourceViewer;
- fAnnotationAccess= access;
- fTextWidget= sourceViewer.getTextWidget();
-
- // default drawing strategies: squiggles are the only pre-3.0 drawing style,
- fRegisteredDrawingStrategies.put(SQUIGGLES, fgSquigglyDrawer);
- }
-
- /**
- * Returns whether this painter has to draw any squiggles.
- *
- * @return <code>true</code> if there are squiggles to be drawn, <code>false</code> otherwise
- */
- private boolean hasDecorations() {
- synchronized (fDecorationMapLock) {
- return !fDecorationsMap.isEmpty();
- }
- }
-
- /**
- * Enables painting. This painter registers a paint listener with the
- * source viewer's widget.
- */
- private void enablePainting() {
- if (!fIsPainting && hasDecorations()) {
- fIsPainting= true;
- fTextWidget.addPaintListener(this);
- handleDrawRequest(null);
- }
- }
-
- /**
- * Disables painting, if is has previously been enabled. Removes
- * any paint listeners registered with the source viewer's widget.
- *
- * @param redraw <code>true</code> if the widget should be redrawn after disabling
- */
- private void disablePainting(boolean redraw) {
- if (fIsPainting) {
- fIsPainting= false;
- fTextWidget.removePaintListener(this);
- if (redraw && hasDecorations())
- handleDrawRequest(null);
- }
- }
-
- /**
- * Sets the annotation model for this painter. Registers this painter
- * as listener of the give model, if the model is not <code>null</code>.
- *
- * @param model the annotation model
- */
- private void setModel(IAnnotationModel model) {
- if (fModel != model) {
- if (fModel != null)
- fModel.removeAnnotationModelListener(this);
- fModel= model;
- if (fModel != null) {
- try {
- fIsSettingModel= true;
- fModel.addAnnotationModelListener(this);
- } finally {
- fIsSettingModel= false;
- }
- }
- }
- }
-
- /**
- * Updates the set of decorations based on the current state of
- * the painter's annotation model.
- *
- * @param event the annotation model event
- */
- private void catchupWithModel(AnnotationModelEvent event) {
-
- synchronized (fDecorationMapLock) {
- if (fDecorationsMap == null)
- return;
- }
-
- int highlightAnnotationRangeStart= Integer.MAX_VALUE;
- int highlightAnnotationRangeEnd= -1;
-
- if (fModel != null) {
-
- Map decorationsMap;
- Map highlightedDecorationsMap;
-
- // Clone decoration maps
- synchronized (fDecorationMapLock) {
- decorationsMap= new HashMap(fDecorationsMap);
- }
- synchronized (fHighlightedDecorationsMapLock) {
- highlightedDecorationsMap= new HashMap(fHighlightedDecorationsMap);
- }
-
- boolean isWorldChange= false;
-
- Iterator e;
- if (event == null || event.isWorldChange()) {
- isWorldChange= true;
-
- if (DEBUG && event == null)
- System.out.println("AP: INTERNAL CHANGE"); //$NON-NLS-1$
-
- decorationsMap.clear();
- highlightedDecorationsMap.clear();
-
- e= fModel.getAnnotationIterator();
-
-
- } else {
-
- // Remove annotations
- Annotation[] removedAnnotations= event.getRemovedAnnotations();
- for (int i=0, length= removedAnnotations.length; i < length; i++) {
- Annotation annotation= removedAnnotations[i];
- Decoration decoration= (Decoration)highlightedDecorationsMap.remove(annotation);
- if (decoration != null) {
- Position position= decoration.fPosition;
- if (position != null) {
- highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset);
- highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length);
- }
- }
- decorationsMap.remove(annotation);
- }
-
- // Update existing annotations
- Annotation[] changedAnnotations= event.getChangedAnnotations();
- for (int i=0, length= changedAnnotations.length; i < length; i++) {
- Annotation annotation= changedAnnotations[i];
-
- Object annotationType= annotation.getType();
- boolean isHighlighting= shouldBeHighlighted(annotationType);
- boolean isDrawingSquiggles= shouldBeDrawn(annotationType);
-
- Decoration decoration= (Decoration)highlightedDecorationsMap.get(annotation);
-
- if (decoration != null) {
- // The call below updates the decoration - no need to create new decoration
- decoration= getDecoration(annotation, decoration, isDrawingSquiggles, isHighlighting);
- if (decoration == null)
- highlightedDecorationsMap.remove(annotation);
- } else {
- decoration= getDecoration(annotation, decoration, isDrawingSquiggles, isHighlighting);
- if (decoration != null && isHighlighting)
- highlightedDecorationsMap.put(annotation, decoration);
- }
-
- Position position= null;
- if (decoration == null)
- position= fModel.getPosition(annotation);
- else
- position= decoration.fPosition;
-
- if (position != null && !position.isDeleted()) {
- highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, position.offset);
- highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, position.offset + position.length);
- } else {
- highlightedDecorationsMap.remove(annotation);
- }
-
- Decoration oldDecoration= (Decoration)decorationsMap.get(annotation);
- if (decoration != null && isDrawingSquiggles)
- decorationsMap.put(annotation, decoration);
- else if (oldDecoration != null)
- decorationsMap.remove(annotation);
- }
-
- e= Arrays.asList(event.getAddedAnnotations()).iterator();
- }
-
- // Add new annotations
- while (e.hasNext()) {
- Annotation annotation= (Annotation) e.next();
-
- Object annotationType= annotation.getType();
- boolean isHighlighting= shouldBeHighlighted(annotationType);
- boolean isDrawingSquiggles= shouldBeDrawn(annotationType);
-
- Decoration pp= getDecoration(annotation, null, isDrawingSquiggles, isHighlighting);
-
- if (pp != null) {
-
- if (isDrawingSquiggles)
- decorationsMap.put(annotation, pp);
-
- if (isHighlighting) {
- highlightedDecorationsMap.put(annotation, pp);
- highlightAnnotationRangeStart= Math.min(highlightAnnotationRangeStart, pp.fPosition.offset);
- highlightAnnotationRangeEnd= Math.max(highlightAnnotationRangeEnd, pp.fPosition.offset + pp.fPosition.length);
- }
- }
- }
-
- synchronized (fDecorationMapLock) {
- fDecorationsMap= decorationsMap;
- }
-
- synchronized (fHighlightedDecorationsMapLock) {
- fHighlightedDecorationsMap= highlightedDecorationsMap;
- updateHighlightRanges(highlightAnnotationRangeStart, highlightAnnotationRangeEnd, isWorldChange);
- }
- }
- }
-
- /**
- * Updates the remembered highlight ranges.
- *
- * @param highlightAnnotationRangeStart the start of the range
- * @param highlightAnnotationRangeEnd the end of the range
- * @param isWorldChange tells whether the range belongs to a annotation model event reporting a world change
- * @since 3.0
- */
- private void updateHighlightRanges(int highlightAnnotationRangeStart, int highlightAnnotationRangeEnd, boolean isWorldChange) {
- if (highlightAnnotationRangeStart != Integer.MAX_VALUE) {
-
- int maxRangeStart= highlightAnnotationRangeStart;
- int maxRangeEnd= highlightAnnotationRangeEnd;
-
- if (fTotalHighlightAnnotationRange != null) {
- maxRangeStart= Math.min(maxRangeStart, fTotalHighlightAnnotationRange.offset);
- maxRangeEnd= Math.max(maxRangeEnd, fTotalHighlightAnnotationRange.offset + fTotalHighlightAnnotationRange.length);
- }
-
- if (fTotalHighlightAnnotationRange == null)
- fTotalHighlightAnnotationRange= new Position(0);
- if (fCurrentHighlightAnnotationRange == null)
- fCurrentHighlightAnnotationRange= new Position(0);
-
- if (isWorldChange) {
- fTotalHighlightAnnotationRange.offset= highlightAnnotationRangeStart;
- fTotalHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart;
- fCurrentHighlightAnnotationRange.offset= maxRangeStart;
- fCurrentHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart;
- } else {
- fTotalHighlightAnnotationRange.offset= maxRangeStart;
- fTotalHighlightAnnotationRange.length= maxRangeEnd - maxRangeStart;
- fCurrentHighlightAnnotationRange.offset=highlightAnnotationRangeStart;
- fCurrentHighlightAnnotationRange.length= highlightAnnotationRangeEnd - highlightAnnotationRangeStart;
- }
- } else {
- if (isWorldChange) {
- fCurrentHighlightAnnotationRange= fTotalHighlightAnnotationRange;
- fTotalHighlightAnnotationRange= null;
- } else {
- fCurrentHighlightAnnotationRange= null;
- }
- }
-
- adaptToDocumentLength(fCurrentHighlightAnnotationRange);
- adaptToDocumentLength(fTotalHighlightAnnotationRange);
- }
-
- /**
- * Adapts the given position to the document length.
- *
- * @param position the position to adapt
- * @since 3.0
- */
- private void adaptToDocumentLength(Position position) {
- if (position == null)
- return;
-
- int length= fSourceViewer.getDocument().getLength();
- position.offset= Math.min(position.offset, length);
- position.length= Math.min(position.length, length - position.offset);
- }
-
- /**
- * Returns a decoration for the given annotation if this
- * annotation is valid and shown by this painter.
- *
- * @param annotation the annotation
- * @param decoration the decoration to be adapted and returned or <code>null</code> if a new one must be created
- * @param isDrawingSquiggles tells if squiggles should be drawn for this annotation
- * @param isHighlighting tells if this annotation should be highlighted
- * @return the decoration or <code>null</code> if there's no valid one
- * @since 3.0
- */
- private Decoration getDecoration(Annotation annotation, Decoration decoration, boolean isDrawingSquiggles, boolean isHighlighting) {
-
- if (annotation.isMarkedDeleted())
- return null;
-
- Color color= null;
-
- if (isDrawingSquiggles || isHighlighting)
- color= findColor(annotation.getType());
-
- if (color == null)
- return null;
-
- Position position= fModel.getPosition(annotation);
- if (position == null || position.isDeleted())
- return null;
-
- if (decoration == null)
- decoration= new Decoration();
-
- decoration.fPosition= position;
- decoration.fColor= color;
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- decoration.fLayer= extension.getLayer(annotation);
- } else {
- decoration.fLayer= IAnnotationAccessExtension.DEFAULT_LAYER;
- }
- decoration.fPainter= getDrawingStrategy(annotation);
-
- return decoration;
- }
-
- /**
- * Returns the drawing type for the given annotation.
- *
- * @param annotation the annotation
- * @return the annotation painter
- * @since 3.0
- */
- private IDrawingStrategy getDrawingStrategy(Annotation annotation) {
- String type= annotation.getType();
- IDrawingStrategy strategy = (IDrawingStrategy) fRegisteredDrawingStrategies.get(fAnnotationType2DrawingStrategyId.get(type));
- if (strategy != null)
- return strategy;
-
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension ext = (IAnnotationAccessExtension) fAnnotationAccess;
- Object[] sts = ext.getSupertypes(type);
- for (int i= 0; i < sts.length; i++) {
- strategy= (IDrawingStrategy) fRegisteredDrawingStrategies.get(fAnnotationType2DrawingStrategyId.get(sts[i]));
- if (strategy != null)
- return strategy;
- }
- }
-
- return fgNullDrawer;
-
- }
-
- /**
- * Returns whether the given annotation type should be drawn.
- *
- * @param annotationType the annotation type
- * @return <code>true</code> if annotation type should be drawn, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean shouldBeDrawn(Object annotationType) {
- return contains(annotationType, fAllowedAnnotationTypes, fConfiguredAnnotationTypes);
- }
-
- /**
- * Returns whether the given annotation type should be highlighted.
- *
- * @param annotationType the annotation type
- * @return <code>true</code> if annotation type should be highlighted, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean shouldBeHighlighted(Object annotationType) {
- return contains(annotationType, fAllowedHighlightAnnotationTypes, fConfiguredHighlightAnnotationTypes);
- }
-
- /**
- * Returns whether the given annotation type is contained in the given <code>allowed</code>
- * set. This is the case if the type is either in the set
- * or covered by the <code>configured</code> set.
- *
- * @param annotationType the annotation type
- * @param allowed set with allowed annotation types
- * @param configured set with configured annotation types
- * @return <code>true</code> if annotation is contained, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean contains(Object annotationType, Set allowed, Set configured) {
- if (allowed.contains(annotationType))
- return true;
-
- boolean covered= isCovered(annotationType, configured);
- if (covered)
- allowed.add(annotationType);
-
- return covered;
- }
-
- /**
- * Computes whether the annotations of the given type are covered by the given <code>configured</code>
- * set. This is the case if either the type of the annotation or any of its
- * super types is contained in the <code>configured</code> set.
- *
- * @param annotationType the annotation type
- * @param configured set with configured annotation types
- * @return <code>true</code> if annotation is covered, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean isCovered(Object annotationType, Set configured) {
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- Iterator e= configured.iterator();
- while (e.hasNext()) {
- if (extension.isSubtype(annotationType,e.next()))
- return true;
- }
- return false;
- }
- return configured.contains(annotationType);
- }
-
- /**
- * Returns the color for the given annotation type
- *
- * @param annotationType the annotation type
- * @return the color
- * @since 3.0
- */
- private Color findColor(Object annotationType) {
- Color color= (Color) fColorTable.get(annotationType);
- if (color != null)
- return color;
-
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- Object[] superTypes= extension.getSupertypes(annotationType);
- if (superTypes != null) {
- for (int i= 0; i < superTypes.length; i++) {
- color= (Color) fColorTable.get(superTypes[i]);
- if (color != null)
- return color;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Recomputes the squiggles to be drawn and redraws them.
- *
- * @param event the annotation model event
- * @since 3.0
- */
- private void updatePainting(AnnotationModelEvent event) {
- disablePainting(true);
-
- catchupWithModel(event);
-
- if (!fInputDocumentAboutToBeChanged)
- invalidateTextPresentation();
-
- enablePainting();
- }
-
- private void invalidateTextPresentation() {
- IRegion r= null;
- synchronized (fHighlightedDecorationsMapLock) {
- if (fCurrentHighlightAnnotationRange != null)
- r= new Region(fCurrentHighlightAnnotationRange.getOffset(), fCurrentHighlightAnnotationRange.getLength());
- }
- if (r == null)
- return;
-
- if (fSourceViewer instanceof ITextViewerExtension2) {
- if (DEBUG)
- System.out.println("AP: invalidating offset: " + r.getOffset() + ", length= " + r.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
-
- ((ITextViewerExtension2)fSourceViewer).invalidateTextPresentation(r.getOffset(), r.getLength());
-
- } else {
- fSourceViewer.invalidateTextPresentation();
- }
- }
-
- /*
- * @see ITextPresentationListener#applyTextPresentation(TextPresentation)
- * @since 3.0
- */
- public void applyTextPresentation(TextPresentation tp) {
- Set decorations;
-
- synchronized (fHighlightedDecorationsMapLock) {
- if (fHighlightedDecorationsMap == null || fHighlightedDecorationsMap.isEmpty())
- return;
-
- decorations= new HashSet(fHighlightedDecorationsMap.entrySet());
- }
-
- IRegion region= tp.getExtent();
-
- if (DEBUG)
- System.out.println("AP: applying text presentation offset: " + region.getOffset() + ", length= " + region.getLength()); //$NON-NLS-1$ //$NON-NLS-2$
-
- for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) {
-
- for (Iterator iter= decorations.iterator(); iter.hasNext();) {
- Map.Entry entry= (Map.Entry)iter.next();
-
- Annotation a= (Annotation)entry.getKey();
- if (a.isMarkedDeleted())
- continue;
-
- Decoration pp = (Decoration)entry.getValue();
-
- maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum
- if (pp.fLayer != layer) // wrong layer: skip annotation
- continue;
-
- Position p= pp.fPosition;
- if (fSourceViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension3= (ITextViewerExtension5) fSourceViewer;
- if (null == extension3.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength())))
- continue;
- } else if (!fSourceViewer.overlapsWithVisibleRegion(p.offset, p.length)) {
- continue;
- }
-
- int regionEnd= region.getOffset() + region.getLength();
- int pEnd= p.getOffset() + p.getLength();
- if (pEnd >= region.getOffset() && regionEnd > p.getOffset()) {
- int start= Math.max(p.getOffset(), region.getOffset());
- int end= Math.min(regionEnd, pEnd);
- int length= Math.max(end - start, 0);
- tp.mergeStyleRange(new StyleRange(start, length, null, pp.fColor));
- }
- }
- }
- }
-
- /*
- * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
- */
- public synchronized void modelChanged(final IAnnotationModel model) {
- if (DEBUG)
- System.err.println("AP: OLD API of AnnotationModelListener called"); //$NON-NLS-1$
-
- modelChanged(new AnnotationModelEvent(model));
- }
-
- /*
- * @see IAnnotationModelListenerExtension#modelChanged(AnnotationModelEvent)
- */
- public void modelChanged(final AnnotationModelEvent event) {
- if (fTextWidget != null && !fTextWidget.isDisposed()) {
- if (fIsSettingModel) {
- // inside the UI thread -> no need for posting
- if (fTextWidget.getDisplay() == Display.getCurrent())
- updatePainting(event);
- else {
- /*
- * we can throw away the changes since
- * further update painting will happen
- */
- return;
- }
- } else {
- Display d= fTextWidget.getDisplay();
- if (DEBUG && event != null && event.isWorldChange()) {
- System.out.println("AP: WORLD CHANGED, stack trace follows:"); //$NON-NLS-1$
- new Throwable().printStackTrace(System.out);
- }
-
- // TODO posting here is a problem for annotations that are being
- // removed and the positions of which are not updated to document
- // changes any more. If the document gets modified between
- // now and running the posted runnable, the position information
- // is not accurate any longer.
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- if (fTextWidget != null && !fTextWidget.isDisposed())
- updatePainting(event);
- }
- });
- }
- }
- }
- }
-
- /**
- * Sets the color in which the squiggly for the given annotation type should be drawn.
- *
- * @param annotationType the annotation type
- * @param color the color
- */
- public void setAnnotationTypeColor(Object annotationType, Color color) {
- if (color != null)
- fColorTable.put(annotationType, color);
- else
- fColorTable.remove(annotationType);
- }
-
- /**
- * Adds the given annotation type to the list of annotation types whose
- * annotations should be painted by this painter using squiggly drawing. If the annotation type
- * is already in this list, this method is without effect.
- *
- * @param annotationType the annotation type
- */
- public void addAnnotationType(Object annotationType) {
- addAnnotationType(annotationType, SQUIGGLES);
- }
-
- /**
- * Adds the given annotation type to the list of annotation types whose
- * annotations should be painted by this painter using the given drawing strategy.
- * If the annotation type is already in this list, the old drawing strategy gets replaced.
- *
- * <p>TODO This is new API and subject to change. </p>
- *
- * @param annotationType the annotation type
- * @param drawingStrategyID the id of the drawing strategy that should be used for this annotation type
- * @since 3.0
- */
- public void addAnnotationType(Object annotationType, Object drawingStrategyID) {
- fConfiguredAnnotationTypes.add(annotationType);
- fAnnotationType2DrawingStrategyId.put(annotationType, drawingStrategyID);
- }
-
- /**
- * Registers a new drawing strategy under the given ID. If there is already a
- * strategy registered under <code>id</code>, the old strategy gets replaced.
- * <p>The given id can be referenced when adding annotation types, see
- * {@link #addAnnotationType(Object, Object)}.</p>
- *
- * <p>TODO This is new API and subject to change. </p>
- *
- * @param id the identifier under which the strategy can be referenced, not <code>null</code>
- * @param strategy the new strategy
- * @since 3.0
- */
- public void addDrawingStrategy(Object id, IDrawingStrategy strategy) {
- // don't permit null as null is used to signal that an annotation type is not
- // registered with a specific strategy, and that its annotation hierarchy should be searched
- if (id == null)
- throw new IllegalArgumentException();
- fRegisteredDrawingStrategies.put(id, strategy);
- }
-
- /**
- * Adds the given annotation type to the list of annotation types whose
- * annotations should be highlighted this painter. If the annotation type
- * is already in this list, this method is without effect.
- *
- * @param annotationType the annotation type
- * @since 3.0
- */
- public void addHighlightAnnotationType(Object annotationType) {
- fConfiguredHighlightAnnotationTypes.add(annotationType);
- if (fTextInputListener == null) {
- fTextInputListener= new ITextInputListener() {
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentAboutToBeChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentAboutToBeChanged(IDocument oldInput, IDocument newInput) {
- fInputDocumentAboutToBeChanged= true;
- }
- /*
- * @see org.eclipse.jface.text.ITextInputListener#inputDocumentChanged(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.IDocument)
- */
- public void inputDocumentChanged(IDocument oldInput, IDocument newInput) {
- fInputDocumentAboutToBeChanged= false;
- }
- };
- fSourceViewer.addTextInputListener(fTextInputListener);
- }
- }
-
- /**
- * Removes the given annotation type from the list of annotation types whose
- * annotations are painted by this painter. If the annotation type is not
- * in this list, this method is without effect.
- *
- * @param annotationType the annotation type
- */
- public void removeAnnotationType(Object annotationType) {
- fConfiguredAnnotationTypes.remove(annotationType);
- fAllowedAnnotationTypes.clear();
- }
-
- /**
- * Removes the given annotation type from the list of annotation types whose
- * annotations are highlighted by this painter. If the annotation type is not
- * in this list, this method is without effect.
- *
- * @param annotationType the annotation type
- * @since 3.0
- */
- public void removeHighlightAnnotationType(Object annotationType) {
- fConfiguredHighlightAnnotationTypes.remove(annotationType);
- fAllowedHighlightAnnotationTypes.clear();
- if (fConfiguredHighlightAnnotationTypes.isEmpty() && fTextInputListener != null) {
- fSourceViewer.removeTextInputListener(fTextInputListener);
- fTextInputListener= null;
- fInputDocumentAboutToBeChanged= false;
- }
- }
-
- /**
- * Clears the list of annotation types whose annotations are
- * painted by this painter.
- */
- public void removeAllAnnotationTypes() {
- fConfiguredAnnotationTypes.clear();
- fAllowedAnnotationTypes.clear();
- fConfiguredHighlightAnnotationTypes.clear();
- fAllowedHighlightAnnotationTypes.clear();
- if (fTextInputListener != null) {
- fSourceViewer.removeTextInputListener(fTextInputListener);
- fTextInputListener= null;
- }
- }
-
- /**
- * Returns whether the list of annotation types whose annotations are painted
- * by this painter contains at least on element.
- *
- * @return <code>true</code> if there is an annotation type whose annotations are painted
- */
- public boolean isPaintingAnnotations() {
- return !fConfiguredAnnotationTypes.isEmpty() || !fConfiguredHighlightAnnotationTypes.isEmpty();
- }
-
- /*
- * @see IPainter#dispose()
- */
- public void dispose() {
-
- if (fColorTable != null)
- fColorTable.clear();
- fColorTable= null;
-
- if (fConfiguredAnnotationTypes != null)
- fConfiguredAnnotationTypes.clear();
- fConfiguredAnnotationTypes= null;
-
- if (fAllowedAnnotationTypes != null)
- fAllowedAnnotationTypes.clear();
- fAllowedAnnotationTypes= null;
-
- if (fConfiguredHighlightAnnotationTypes != null)
- fConfiguredHighlightAnnotationTypes.clear();
- fConfiguredHighlightAnnotationTypes= null;
-
- if (fAllowedHighlightAnnotationTypes != null)
- fAllowedHighlightAnnotationTypes.clear();
- fAllowedHighlightAnnotationTypes= null;
-
- fTextWidget= null;
- fSourceViewer= null;
- fAnnotationAccess= null;
- fModel= null;
- synchronized (fDecorationMapLock) {
- fDecorationsMap= null;
- }
- synchronized (fHighlightedDecorationsMapLock) {
- fHighlightedDecorationsMap= null;
- }
- }
-
- /**
- * Returns the document offset of the upper left corner of the source viewer's viewport,
- * possibly including partially visible lines.
- *
- * @return the document offset if the upper left corner of the viewport
- */
- private int getInclusiveTopIndexStartOffset() {
-
- if (fTextWidget != null && !fTextWidget.isDisposed()) {
- int top= -1;
- if (fSourceViewer instanceof ITextViewerExtension5) {
- top= fTextWidget.getTopIndex();
- if ((fTextWidget.getTopPixel() % fTextWidget.getLineHeight()) != 0)
- top--;
- ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
- top= extension.widgetLine2ModelLine(top);
- } else {
- top= fSourceViewer.getTopIndex();
- if ((fTextWidget.getTopPixel() % fTextWidget.getLineHeight()) != 0)
- top--;
- }
-
- try {
- IDocument document= fSourceViewer.getDocument();
- return document.getLineOffset(top);
- } catch (BadLocationException x) {
- }
- }
-
- return -1;
- }
-
- /**
- * Returns the first invisible document offset of the lower right corner of the source viewer's viewport,
- * possibly including partially visible lines.
- *
- * @return the first invisible document offset of the lower right corner of the viewport
- */
- private int getExclusiveBottomIndexEndOffset() {
-
- if (fTextWidget != null && !fTextWidget.isDisposed()) {
- int bottom= fSourceViewer.getBottomIndex();
- if (((fTextWidget.getTopPixel() + fTextWidget.getClientArea().height) % fTextWidget.getLineHeight()) != 0)
- bottom++;
- try {
- IDocument document= fSourceViewer.getDocument();
-
- if (bottom >= document.getNumberOfLines())
- bottom= document.getNumberOfLines() - 1;
-
- return document.getLineOffset(bottom) + document.getLineLength(bottom);
- } catch (BadLocationException x) {
- }
- }
-
- return -1;
- }
-
- /*
- * @see PaintListener#paintControl(PaintEvent)
- */
- public void paintControl(PaintEvent event) {
- if (fTextWidget != null)
- handleDrawRequest(event.gc);
- }
-
- /**
- * Handles the request to draw the annotations using the given graphical context.
- *
- * @param gc the graphical context
- */
- private void handleDrawRequest(GC gc) {
-
- if (fTextWidget == null) {
- // is already disposed
- return;
- }
-
- ReusableRegion range= new ReusableRegion();
-
- int vOffset= getInclusiveTopIndexStartOffset();
- // http://bugs.eclipse.org/bugs/show_bug.cgi?id=17147
- int vLength= getExclusiveBottomIndexEndOffset() - vOffset;
-
- Set decorations;
-
- // Clone decorations set
- synchronized (fDecorationMapLock) {
- decorations= new HashSet(fDecorationsMap.entrySet());
- }
-
- for (int layer= 0, maxLayer= 1; layer < maxLayer; layer++) {
-
- for (Iterator e = decorations.iterator(); e.hasNext();) {
- Map.Entry entry= (Map.Entry)e.next();
-
- Annotation a= (Annotation)entry.getKey();
- if (a.isMarkedDeleted())
- continue;
-
- Decoration pp = (Decoration)entry.getValue();
- if (pp.fPainter == fgNullDrawer)
- continue;
-
- if (skip(a))
- continue;
-
- maxLayer= Math.max(maxLayer, pp.fLayer + 1); // dynamically update layer maximum
- if (pp.fLayer != layer) // wrong layer: skip annotation
- continue;
-
- Position p= pp.fPosition;
- if (p.overlapsWith(vOffset, vLength)) {
-
- IDocument document= fSourceViewer.getDocument();
- try {
-
- int startLine= document.getLineOfOffset(p.getOffset());
- int lastInclusive= Math.max(p.getOffset(), p.getOffset() + p.getLength() - 1);
- int endLine= document.getLineOfOffset(lastInclusive);
-
- for (int i= startLine; i <= endLine; i++) {
- int lineOffset= document.getLineOffset(i);
- int paintStart= Math.max(lineOffset, p.getOffset());
- String lineDelimiter= document.getLineDelimiter(i);
- int delimiterLength= lineDelimiter != null ? lineDelimiter.length() : 0;
- int paintLength= Math.min(lineOffset + document.getLineLength(i) - delimiterLength, p.getOffset() + p.getLength()) - paintStart;
- if (paintLength >= 0 && overlapsWith(paintStart, paintLength, vOffset, vLength)) {
- // otherwise inside a line delimiter
- range.update(paintStart, paintLength);
- IRegion widgetRange= getWidgetRange(range);
- if (widgetRange != null)
- pp.fPainter.draw(a, gc, fTextWidget, widgetRange.getOffset(), widgetRange.getLength(), pp.fColor);
- }
- }
-
- } catch (BadLocationException x) {
- }
- }
- }
- }
- }
-
- /**
- * Should the given annotation be skipped when handling draw requests?
- *
- * @param annotation the annotation
- * @return <code>true</code> iff the given annotation should be
- * skipped when handling draw requests
- * @since 3.0
- */
- protected boolean skip(Annotation annotation) {
- return false;
- }
-
- /**
- * Returns the widget region that corresponds to the given region in the
- * viewer's document.
- *
- * @param p the region in the viewer's document
- * @return the corresponding widget region
- */
- private IRegion getWidgetRange(IRegion p) {
- if (p == null || p.getOffset() == Integer.MAX_VALUE)
- return null;
-
- if (fSourceViewer instanceof ITextViewerExtension5) {
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
- return extension.modelRange2WidgetRange(p);
-
- } else {
-
- IRegion region= fSourceViewer.getVisibleRegion();
- int offset= region.getOffset();
- int length= region.getLength();
-
- if (overlapsWith(p, region)) {
- int p1= Math.max(offset, p.getOffset());
- int p2= Math.min(offset + length, p.getOffset() + p.getLength());
- return new Region(p1 - offset, p2 - p1);
- }
- }
-
- return null;
- }
-
- /**
- * Checks whether the intersection of the given text ranges
- * is empty or not.
- *
- * @param range1 the first range to check
- * @param range2 the second range to check
- * @return <code>true</code> if intersection is not empty
- */
- private boolean overlapsWith(IRegion range1, IRegion range2) {
- return overlapsWith(range1.getOffset(), range1.getLength(), range2.getOffset(), range2.getLength());
- }
-
- /**
- * Checks whether the intersection of the given text ranges
- * is empty or not.
- *
- * @param offset1 offset of the first range
- * @param length1 length of the first range
- * @param offset2 offset of the second range
- * @param length2 length of the second range
- * @return <code>true</code> if intersection is not empty
- */
- private boolean overlapsWith(int offset1, int length1, int offset2, int length2) {
- int end= offset2 + length2;
- int thisEnd= offset1 + length1;
-
- if (length2 > 0) {
- if (length1 > 0)
- return offset1 < end && offset2 < thisEnd;
- return offset2 <= offset1 && offset1 < end;
- }
-
- if (length1 > 0)
- return offset1 <= offset2 && offset2 < thisEnd;
- return offset1 == offset2;
- }
-
- /*
- * @see IPainter#deactivate(boolean)
- */
- public void deactivate(boolean redraw) {
- if (fIsActive) {
- fIsActive= false;
- disablePainting(redraw);
- setModel(null);
- catchupWithModel(null);
- }
- }
-
- /**
- * Returns whether the given reason causes a repaint.
- *
- * @param reason the reason
- * @return <code>true</code> if repaint reason, <code>false</code> otherwise
- * @since 3.0
- */
- protected boolean isRepaintReason(int reason) {
- return CONFIGURATION == reason || INTERNAL == reason;
- }
-
- /**
- * Retrieves the annotation model from the given source viewer.
- *
- * @param sourceViewer the source viewer
- * @return the source viewer's annotation model or <code>null</code> if none can be found
- * @since 3.0
- */
- protected IAnnotationModel findAnnotationModel(ISourceViewer sourceViewer) {
- if(sourceViewer != null)
- return sourceViewer.getAnnotationModel();
- return null;
- }
-
- /*
- * @see IPainter#paint(int)
- */
- public void paint(int reason) {
- if (fSourceViewer.getDocument() == null) {
- deactivate(false);
- return;
- }
-
- if (!fIsActive) {
- IAnnotationModel model= findAnnotationModel(fSourceViewer);
- if (model != null) {
- fIsActive= true;
- setModel(model);
- }
- } else if (isRepaintReason(reason))
- updatePainting(null);
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager)
- */
- public void setPositionManager(IPaintPositionManager manager) {
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
deleted file mode 100644
index 355d9dc0faf..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/AnnotationRulerColumn.java
+++ /dev/null
@@ -1,985 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.TextViewer;
-
-
-/**
- * A vertical ruler column showing graphical representations of annotations.
- * Will become final. Do not subclass.
- * @since 2.0
- */
-public class AnnotationRulerColumn implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension {
-
- /**
- * Internal listener class.
- */
- class InternalListener implements IViewportListener, IAnnotationModelListener, ITextListener {
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int verticalPosition) {
- if (verticalPosition != fScrollPos)
- redraw();
- }
-
- /*
- * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- postRedraw();
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent e) {
- if (e.getViewerRedrawState())
- postRedraw();
- }
- }
-
- /**
- * Implementation of <code>IRegion</code> that can be reused
- * by setting the offset and the length.
- */
- private static class ReusableRegion implements IRegion {
-
- private int fOffset;
- private int fLength;
-
- /*
- * @see org.eclipse.jface.text.IRegion#getLength()
- */
- public int getLength() {
- return fLength;
- }
-
- /*
- * @see org.eclipse.jface.text.IRegion#getOffset()
- */
- public int getOffset() {
- return fOffset;
- }
-
- /**
- * Updates this region.
- *
- * @param offset the new offset
- * @param length the new length
- */
- public void update(int offset, int length) {
- fOffset= offset;
- fLength= length;
- }
- }
-
- /**
- * Pair of an annotation and their associated position. Used inside the paint method
- * for sorting annotations based on the offset of their position.
- * @since 3.0
- */
- private static class Tuple {
- Annotation annotation;
- Position position;
-
- Tuple(Annotation annotation, Position position) {
- this.annotation= annotation;
- this.position= position;
- }
- }
-
- /**
- * Comparator for <code>Tuple</code>s.
- * @since 3.0
- */
- private static class TupleComparator implements Comparator {
- /*
- * @see java.util.Comparator#compare(java.lang.Object, java.lang.Object)
- */
- public int compare(Object o1, Object o2) {
- Position p1= ((Tuple) o1).position;
- Position p2= ((Tuple) o2).position;
- return p1.getOffset() - p2.getOffset();
- }
- }
-
- /** This column's parent ruler */
- private CompositeRuler fParentRuler;
- /** The cached text viewer */
- private ITextViewer fCachedTextViewer;
- /** The cached text widget */
- private StyledText fCachedTextWidget;
- /** The ruler's canvas */
- private Canvas fCanvas;
- /** The vertical ruler's model */
- private IAnnotationModel fModel;
- /** Cache for the actual scroll position in pixels */
- private int fScrollPos;
- /** The drawable for double buffering */
- private Image fBuffer;
- /** The internal listener */
- private InternalListener fInternalListener= new InternalListener();
- /** The width of this vertical ruler */
- private int fWidth;
- /** Switch for enabling/disabling the setModel method. */
- private boolean fAllowSetModel= true;
- /**
- * The list of annotation types to be shown in this ruler.
- * @since 3.0
- */
- private Set fConfiguredAnnotationTypes= new HashSet();
- /**
- * The list of allowed annotation types to be shown in this ruler.
- * An allowed annotation type maps to <code>true</code>, a disallowed
- * to <code>false</code>.
- * @since 3.0
- */
- private Map fAllowedAnnotationTypes= new HashMap();
- /**
- * The annotation access extension.
- * @since 3.0
- */
- private IAnnotationAccessExtension fAnnotationAccessExtension;
- /**
- * The hover for this column.
- * @since 3.0
- */
- private IAnnotationHover fHover;
- /**
- * The cached annotations.
- * @since 3.0
- */
- private List fCachedAnnotations= new ArrayList();
- /**
- * The comparator for sorting annotations according to the offset of their position.
- * @since 3.0
- */
- private Comparator fTupleComparator= new TupleComparator();
- /**
- * The hit detection cursor.
- * @since 3.0
- */
- private Cursor fHitDetectionCursor;
- /**
- * The last cursor.
- * @since 3.0
- */
- private Cursor fLastCursor;
- /**
- * This ruler's mouse listener.
- * @since 3.0
- */
- private MouseListener fMouseListener;
-
- /**
- * Constructs this column with the given arguments.
- *
- * @param model the annotation model to get the annotations from
- * @param width the width of the vertical ruler
- * @param annotationAccess the annotation access
- * @since 3.0
- */
- public AnnotationRulerColumn(IAnnotationModel model, int width, IAnnotationAccess annotationAccess) {
- this(width, annotationAccess);
- fAllowSetModel= false;
- fModel= model;
- fModel.addAnnotationModelListener(fInternalListener);
- }
-
- /**
- * Constructs this column with the given arguments.
- *
- * @param width the width of the vertical ruler
- * @param annotationAccess the annotation access
- * @since 3.0
- */
- public AnnotationRulerColumn(int width, IAnnotationAccess annotationAccess) {
- fWidth= width;
- if (annotationAccess instanceof IAnnotationAccessExtension)
- fAnnotationAccessExtension= (IAnnotationAccessExtension) annotationAccess;
- }
-
- /**
- * Constructs this column with the given arguments.
- *
- * @param model the annotation model to get the annotations from
- * @param width the width of the vertical ruler
- */
- public AnnotationRulerColumn(IAnnotationModel model, int width) {
- fWidth= width;
- fAllowSetModel= false;
- fModel= model;
- fModel.addAnnotationModelListener(fInternalListener);
- }
-
- /**
- * Constructs this column with the given width.
- *
- * @param width the width of the vertical ruler
- */
- public AnnotationRulerColumn(int width) {
- fWidth= width;
- }
-
- /*
- * @see IVerticalRulerColumn#getControl()
- */
- public Control getControl() {
- return fCanvas;
- }
-
- /*
- * @see IVerticalRulerColumn#getWidth()
- */
- public int getWidth() {
- return fWidth;
- }
-
- /*
- * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite)
- */
- public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
-
- fParentRuler= parentRuler;
- fCachedTextViewer= parentRuler.getTextViewer();
- fCachedTextWidget= fCachedTextViewer.getTextWidget();
-
- fHitDetectionCursor= new Cursor(parentControl.getDisplay(), SWT.CURSOR_HAND);
-
- fCanvas= createCanvas(parentControl);
-
- fCanvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent event) {
- if (fCachedTextViewer != null)
- doubleBufferPaint(event.gc);
- }
- });
-
- fCanvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- fCachedTextViewer= null;
- fCachedTextWidget= null;
- }
- });
-
- fMouseListener= new MouseListener() {
- public void mouseUp(MouseEvent event) {
- int lineNumber;
- if (isPropagatingMouseListener()) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- lineNumber= fParentRuler.getLineOfLastMouseButtonActivity();
- } else
- lineNumber= fParentRuler.toDocumentLineNumber(event.y);
-
- if (1 == event.button)
- mouseClicked(lineNumber);
- }
-
- public void mouseDown(MouseEvent event) {
- if (isPropagatingMouseListener())
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- }
-
- public void mouseDoubleClick(MouseEvent event) {
- int lineNumber;
- if (isPropagatingMouseListener()) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- lineNumber= fParentRuler.getLineOfLastMouseButtonActivity();
- } else
- lineNumber= fParentRuler.toDocumentLineNumber(event.y);
-
- if (1 == event.button)
- mouseDoubleClicked(lineNumber);
- }
- };
- fCanvas.addMouseListener(fMouseListener);
-
- fCanvas.addMouseMoveListener(new MouseMoveListener() {
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- * @since 3.0
- */
- public void mouseMove(MouseEvent e) {
- handleMouseMove(e);
- }
- });
-
- if (fCachedTextViewer != null) {
- fCachedTextViewer.addViewportListener(fInternalListener);
- fCachedTextViewer.addTextListener(fInternalListener);
- }
-
- return fCanvas;
- }
-
- private Canvas createCanvas(Composite parent) {
- return new Canvas(parent, SWT.NO_BACKGROUND) {
- /*
- * @see org.eclipse.swt.widgets.Control#addMouseListener(org.eclipse.swt.events.MouseListener)
- * @since 3.0
- */
- public void addMouseListener(MouseListener listener) {
- if (isPropagatingMouseListener() || listener == fMouseListener)
- super.addMouseListener(listener);
- }
- };
- }
-
- /**
- * Tells whether this ruler column propagates mouse listener
- * events to its parent.
- *
- * @return <code>true</code> if propagating to parent
- * @since 3.0
- */
- protected boolean isPropagatingMouseListener() {
- return true;
- }
-
- /**
- * Hook method for a mouse double click event on the given ruler line.
- *
- * @param rulerLine the ruler line
- */
- protected void mouseDoubleClicked(int rulerLine) {
- }
-
- /**
- * Hook method for a mouse click event on the given ruler line.
- *
- * @param rulerLine the ruler line
- * @since 3.0
- */
- protected void mouseClicked(int rulerLine) {
- }
-
- /**
- * Handles mouse moves.
- *
- * @param event the mouse move event
- */
- private void handleMouseMove(MouseEvent event) {
- if (fCachedTextViewer != null) {
- int line= toDocumentLineNumber(event.y);
- Cursor cursor= (hasAnnotation(line) ? fHitDetectionCursor : null);
- if (cursor != fLastCursor) {
- fCanvas.setCursor(cursor);
- fLastCursor= cursor;
- }
- }
- }
-
- /**
- * Tells whether the given line contains an annotation.
- *
- * @param lineNumber the line number
- * @return <code>true</code> if the given line contains an annotation
- */
- protected boolean hasAnnotation(int lineNumber) {
-
- IAnnotationModel model= fModel;
- if (fModel instanceof IAnnotationModelExtension)
- model= ((IAnnotationModelExtension)fModel).getAnnotationModel(SourceViewer.MODEL_ANNOTATION_MODEL);
-
- if (model == null)
- return false;
-
- IRegion line;
- try {
- IDocument d= fCachedTextViewer.getDocument();
- line= d.getLineInformation(lineNumber);
- } catch (BadLocationException ex) {
- return false;
- }
-
- int lineStart= line.getOffset();
- int lineLength= line.getLength();
-
- Iterator e= model.getAnnotationIterator();
- while (e.hasNext()) {
- Annotation a= (Annotation) e.next();
-
- if (a.isMarkedDeleted())
- continue;
-
- if (skip(a))
- continue;
-
- Position p= model.getPosition(a);
- if (p == null || p.isDeleted())
- continue;
-
- if (p.overlapsWith(lineStart, lineLength))
- return true;
- }
-
- return false;
- }
-
- /**
- * Disposes the ruler's resources.
- */
- private void handleDispose() {
-
- if (fCachedTextViewer != null) {
- fCachedTextViewer.removeViewportListener(fInternalListener);
- fCachedTextViewer.removeTextListener(fInternalListener);
- }
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
-
- if (fHitDetectionCursor != null) {
- fHitDetectionCursor.dispose();
- fHitDetectionCursor= null;
- }
-
- fConfiguredAnnotationTypes.clear();
- fAllowedAnnotationTypes.clear();
- fAnnotationAccessExtension= null;
- }
-
- /**
- * Double buffer drawing.
- *
- * @param dest the GC to draw into
- */
- private void doubleBufferPaint(GC dest) {
-
- Point size= fCanvas.getSize();
-
- if (size.x <= 0 || size.y <= 0)
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- gc.setFont(fCachedTextWidget.getFont());
- try {
- gc.setBackground(fCanvas.getBackground());
- gc.fillRectangle(0, 0, size.x, size.y);
-
- if (fCachedTextViewer instanceof ITextViewerExtension5)
- doPaint1(gc);
- else
- doPaint(gc);
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- /**
- * Returns the document offset of the upper left corner of the source viewer's
- * viewport, possibly including partially visible lines.
- *
- * @return document offset of the upper left corner including partially visible lines
- */
- protected int getInclusiveTopIndexStartOffset() {
-
- if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) {
- int top= -1;
- if (fCachedTextViewer instanceof ITextViewerExtension5) {
- top= fCachedTextWidget.getTopIndex();
- if ((fCachedTextWidget.getTopPixel() % fCachedTextWidget.getLineHeight()) != 0)
- top--;
- ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
- top= extension.widgetLine2ModelLine(top);
- } else {
- top= fCachedTextViewer.getTopIndex();
- if ((fCachedTextWidget.getTopPixel() % fCachedTextWidget.getLineHeight()) != 0)
- top--;
- }
-
- try {
- IDocument document= fCachedTextViewer.getDocument();
- return document.getLineOffset(top);
- } catch (BadLocationException x) {
- }
- }
-
- return -1;
- }
-
- /**
- * Returns the first invisible document offset of the lower right corner of the source viewer's viewport,
- * possibly including partially visible lines.
- *
- * @return the first invisible document offset of the lower right corner of the viewport
- */
- private int getExclusiveBottomIndexEndOffset() {
-
- if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) {
- int bottom= fCachedTextViewer.getBottomIndex();
- if (((fCachedTextWidget.getTopPixel() + fCachedTextWidget.getClientArea().height) % fCachedTextWidget.getLineHeight()) != 0)
- bottom++;
- try {
- IDocument document= fCachedTextViewer.getDocument();
-
- if (bottom >= document.getNumberOfLines())
- bottom= document.getNumberOfLines() - 1;
-
- return document.getLineOffset(bottom) + document.getLineLength(bottom);
- } catch (BadLocationException x) {
- }
- }
-
- return -1;
- }
-
- /**
- * Draws the vertical ruler w/o drawing the Canvas background.
- *
- * @param gc the GC to draw into
- */
- protected void doPaint(GC gc) {
-
- if (fModel == null || fCachedTextViewer == null)
- return;
-
- int topLeft= getInclusiveTopIndexStartOffset();
- int bottomRight;
-
- IRegion coverage= null;
- if (fCachedTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
- coverage= extension.getModelCoverage();
- } else if (fCachedTextViewer instanceof TextViewer) {
- // TODO remove once TextViewer implements ITextViewerExtension5
- TextViewer extension= (TextViewer) fCachedTextViewer;
- coverage= extension.getModelCoverage();
- }
-
- if (coverage != null)
- bottomRight= coverage.getOffset() + coverage.getLength();
- else {
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=14938
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=22487
- // add 1 as getBottomIndexEndOffset returns the inclusive offset, but we want the exclusive offset (right after the last character)
- bottomRight= fCachedTextViewer.getBottomIndexEndOffset() + 1;
- }
- int viewPort= bottomRight - topLeft;
-
- fScrollPos= fCachedTextWidget.getTopPixel();
- int lineheight= fCachedTextWidget.getLineHeight();
- Point dimension= fCanvas.getSize();
- int shift= fCachedTextViewer.getTopInset();
-
- IDocument doc= fCachedTextViewer.getDocument();
-
- int topLine= -1, bottomLine= -1;
- try {
- IRegion region= fCachedTextViewer.getVisibleRegion();
- topLine= doc.getLineOfOffset(region.getOffset());
- bottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- } catch (BadLocationException x) {
- return;
- }
-
- // draw Annotations
- Rectangle r= new Rectangle(0, 0, 0, 0);
- int maxLayer= 1; // loop at least once through layers.
-
- for (int layer= 0; layer < maxLayer; layer++) {
- Iterator iter= fModel.getAnnotationIterator();
- while (iter.hasNext()) {
- Annotation annotation= (Annotation) iter.next();
-
- int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
- if (fAnnotationAccessExtension != null)
- lay= fAnnotationAccessExtension.getLayer(annotation);
- maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
- if (lay != layer) // wrong layer: skip annotation
- continue;
-
- if (skip(annotation))
- continue;
-
- Position position= fModel.getPosition(annotation);
- if (position == null)
- continue;
-
- // https://bugs.eclipse.org/bugs/show_bug.cgi?id=20284
- // Position.overlapsWith returns false if the position just starts at the end
- // of the specified range. If the position has zero length, we want to include it anyhow
- int viewPortSize= position.getLength() == 0 ? viewPort + 1 : viewPort;
- if (!position.overlapsWith(topLeft, viewPortSize))
- continue;
-
- try {
-
- int offset= position.getOffset();
- int length= position.getLength();
-
- int startLine= doc.getLineOfOffset(offset);
- if (startLine < topLine)
- startLine= topLine;
-
- int endLine= startLine;
- if (length > 0)
- endLine= doc.getLineOfOffset(offset + length - 1);
- if (endLine > bottomLine)
- endLine= bottomLine;
-
- startLine -= topLine;
- endLine -= topLine;
-
- r.x= 0;
- r.y= (startLine * lineheight) - fScrollPos + shift;
- r.width= dimension.x;
- int lines= endLine - startLine;
- if (lines < 0)
- lines= -lines;
- r.height= (lines+1) * lineheight;
-
- if (r.y < dimension.y && fAnnotationAccessExtension != null) // annotation within visible area
- fAnnotationAccessExtension.paint(annotation, gc, fCanvas, r);
-
- } catch (BadLocationException x) {
- }
- }
- }
- }
-
- /**
- * Draws the vertical ruler w/o drawing the Canvas background. Implementation based
- * on <code>ITextViewerExtension5</code>. Will replace <code>doPaint(GC)</code>.
- *
- * @param gc the GC to draw into
- */
- protected void doPaint1(GC gc) {
-
- if (fModel == null || fCachedTextViewer == null)
- return;
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
-
- fScrollPos= fCachedTextWidget.getTopPixel();
- int lineheight= fCachedTextWidget.getLineHeight();
- Point dimension= fCanvas.getSize();
- int shift= fCachedTextViewer.getTopInset();
-
- int vOffset= getInclusiveTopIndexStartOffset();
- int vLength= getExclusiveBottomIndexEndOffset() - vOffset;
-
- // draw Annotations
- Rectangle r= new Rectangle(0, 0, 0, 0);
- ReusableRegion range= new ReusableRegion();
-
- int minLayer= Integer.MAX_VALUE, maxLayer= Integer.MIN_VALUE;
- fCachedAnnotations.clear();
- Iterator iter= fModel.getAnnotationIterator();
- while (iter.hasNext()) {
- Annotation annotation= (Annotation) iter.next();
-
- if (skip(annotation))
- continue;
-
- Position position= fModel.getPosition(annotation);
- if (position == null)
- continue;
-
- if (!position.overlapsWith(vOffset, vLength))
- continue;
-
- int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
- if (fAnnotationAccessExtension != null)
- lay= fAnnotationAccessExtension.getLayer(annotation);
-
- minLayer= Math.min(minLayer, lay);
- maxLayer= Math.max(maxLayer, lay);
- fCachedAnnotations.add(new Tuple(annotation, position));
- }
- Collections.sort(fCachedAnnotations, fTupleComparator);
-
- for (int layer= minLayer; layer <= maxLayer; layer++) {
- for (int i= 0, n= fCachedAnnotations.size(); i < n; i++) {
- Tuple tuple= (Tuple) fCachedAnnotations.get(i);
- Annotation annotation= tuple.annotation;
- Position position= tuple.position;
-
- int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
- if (fAnnotationAccessExtension != null)
- lay= fAnnotationAccessExtension.getLayer(annotation);
- if (lay != layer) // wrong layer: skip annotation
- continue;
-
- range.update(position.getOffset(), position.getLength());
- IRegion widgetRegion= extension.modelRange2WidgetRange(range);
- if (widgetRegion == null)
- continue;
-
- int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
- if (startLine == -1)
- continue;
-
- int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0));
- if (endLine == -1)
- continue;
-
- r.x= 0;
- r.y= (startLine * lineheight) - fScrollPos + shift;
- r.width= dimension.x;
- int lines= endLine - startLine;
- if (lines < 0)
- lines= -lines;
- r.height= (lines+1) * lineheight;
-
- if (r.y < dimension.y && fAnnotationAccessExtension != null) // annotation within visible area
- fAnnotationAccessExtension.paint(annotation, gc, fCanvas, r);
- }
- }
-
- fCachedAnnotations.clear();
- }
-
-
- /**
- * Post a redraw request for this column into the UI thread.
- */
- private void postRedraw() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- Display d= fCanvas.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- redraw();
- }
- });
- }
- }
- }
-
- /*
- * @see IVerticalRulerColumn#redraw()
- */
- public void redraw() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- GC gc= new GC(fCanvas);
- doubleBufferPaint(gc);
- gc.dispose();
- }
- }
-
- /*
- * @see IVerticalRulerColumn#setModel
- */
- public void setModel(IAnnotationModel model) {
- if (fAllowSetModel && model != fModel) {
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- fModel= model;
-
- if (fModel != null)
- fModel.addAnnotationModelListener(fInternalListener);
-
- postRedraw();
- }
- }
-
- /*
- * @see IVerticalRulerColumn#setFont(Font)
- */
- public void setFont(Font font) {
- }
-
- /**
- * Returns the cached text viewer.
- *
- * @return the cached text viewer
- */
- protected ITextViewer getCachedTextViewer() {
- return fCachedTextViewer;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getModel()
- */
- public IAnnotationModel getModel() {
- return fModel;
- }
-
- /**
- * Adds the given annotation type to this annotation ruler column. Starting
- * with this call, annotations of the given type are shown in this annotation
- * ruler column.
- *
- * @param annotationType the annotation type
- * @since 3.0
- */
- public void addAnnotationType(Object annotationType) {
- fConfiguredAnnotationTypes.add(annotationType);
- fAllowedAnnotationTypes.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- * @since 3.0
- */
- public int getLineOfLastMouseButtonActivity() {
- return fParentRuler.getLineOfLastMouseButtonActivity();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int)
- * @since 3.0
- */
- public int toDocumentLineNumber(int y_coordinate) {
- return fParentRuler.toDocumentLineNumber(y_coordinate);
- }
-
- /**
- * Removes the given annotation type from this annotation ruler column.
- * Annotations of the given type are no longer shown in this annotation
- * ruler column.
- *
- * @param annotationType the annotation type
- * @since 3.0
- */
- public void removeAnnotationType(Object annotationType) {
- fConfiguredAnnotationTypes.remove(annotationType);
- fAllowedAnnotationTypes.clear();
- }
-
- /**
- * Returns whether the given annotation should be skipped by the drawing
- * routine.
- *
- * @param annotation the annotation
- * @return <code>true</code> if annotation of the given type should be
- * skipped, <code>false</code> otherwise
- * @since 3.0
- */
- private boolean skip(Annotation annotation) {
- Object annotationType= annotation.getType();
- Boolean allowed= (Boolean) fAllowedAnnotationTypes.get(annotationType);
- if (allowed != null)
- return !allowed.booleanValue();
-
- boolean skip= skip(annotationType);
- fAllowedAnnotationTypes.put(annotationType, !skip ? Boolean.TRUE : Boolean.FALSE);
- return skip;
- }
-
- /**
- * Computes whether the annotation of the given type should be skipped or
- * not.
- *
- * @param annotationType the annotation type
- * @return <code>true</code> if annotation should be skipped, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean skip(Object annotationType) {
- if (fAnnotationAccessExtension != null) {
- Iterator e= fConfiguredAnnotationTypes.iterator();
- while (e.hasNext()) {
- if (fAnnotationAccessExtension.isSubtype(annotationType, e.next()))
- return false;
- }
- return true;
- }
- return !fConfiguredAnnotationTypes.contains(annotationType);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover()
- * @since 3.0
- */
- public IAnnotationHover getHover() {
- return fHover;
- }
-
- /**
- * @param hover The hover to set.
- * @since 3.0
- */
- public void setHover(IAnnotationHover hover) {
- fHover= hover;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- * @since 3.0
- */
- public void addVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- * @since 3.0
- */
- public void removeVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java
deleted file mode 100644
index df44274e240..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ChangeRulerColumn.java
+++ /dev/null
@@ -1,665 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.TextEvent;
-
-/**
- * A vertical ruler column displaying line numbers and serving as a UI for quick diff.
- * Clients instantiate and configure object of this class.
- *
- * @since 3.0
- */
-public final class ChangeRulerColumn implements IVerticalRulerColumn, IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn {
-
- /**
- * Handles all the mouse interaction in this line number ruler column.
- */
- class MouseHandler implements MouseListener, MouseMoveListener {
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent event) {
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDown(MouseEvent event) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent event) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- }
-
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseMove(MouseEvent e) {
- }
-
- }
-
- /**
- * Internal listener class.
- */
- class InternalListener implements IViewportListener, ITextListener {
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int verticalPosition) {
- if (verticalPosition != fScrollPos)
- redraw();
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent event) {
-
- if (!event.getViewerRedrawState())
- return;
-
- if (fSensitiveToTextChanges || event.getDocumentEvent() == null)
- postRedraw();
-
- }
- }
-
- /**
- * Internal listener class that will update the ruler when the underlying model changes.
- */
- class AnnotationListener implements IAnnotationModelListener {
- /*
- * @see org.eclipse.jface.text.source.IAnnotationModelListener#modelChanged(org.eclipse.jface.text.source.IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- postRedraw();
- }
- }
-
- /** This column's parent ruler */
- private CompositeRuler fParentRuler;
- /** Cached text viewer */
- private ITextViewer fCachedTextViewer;
- /** Cached text widget */
- private StyledText fCachedTextWidget;
- /** The columns canvas */
- private Canvas fCanvas;
- /** Cache for the actual scroll position in pixels */
- private int fScrollPos;
- /** The drawable for double buffering */
- private Image fBuffer;
- /** The internal listener */
- private InternalListener fInternalListener= new InternalListener();
- /** Indicates whether this column reacts on text change events */
- private boolean fSensitiveToTextChanges= false;
- /** The foreground color */
- private Color fForeground;
- /** The background color */
- private Color fBackground;
- /** Color for changed lines */
- private Color fAddedColor;
- /** Color for added lines */
- private Color fChangedColor;
- /** Color for the deleted line indicator */
- private Color fDeletedColor;
- /** The ruler's annotation model. */
- private IAnnotationModel fAnnotationModel;
- /** The ruler's hover */
- private IAnnotationHover fHover;
- /** The internal listener */
- private AnnotationListener fAnnotationListener= new AnnotationListener();
- /** The width of the change ruler column. */
- private int fWidth= 5;
-
-
- /**
- * Returns the System background color for list widgets.
- *
- * @param display the display the drawing occurs on
- * @return the System background color for list widgets
- */
- protected Color getBackground(Display display) {
- if (fBackground == null)
- return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- return fBackground;
- }
-
- /*
- * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite)
- */
- public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
-
- fParentRuler= parentRuler;
- fCachedTextViewer= parentRuler.getTextViewer();
- fCachedTextWidget= fCachedTextViewer.getTextWidget();
-
- fCanvas= new Canvas(parentControl, SWT.NONE);
- fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
- fCanvas.setForeground(fForeground);
-
- fCanvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent event) {
- if (fCachedTextViewer != null)
- doubleBufferPaint(event.gc);
- }
- });
-
- fCanvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- fCachedTextViewer= null;
- fCachedTextWidget= null;
- }
- });
-
- MouseHandler mouseHandler= new MouseHandler();
-
- fCanvas.addMouseListener(mouseHandler);
-
- fCanvas.addMouseMoveListener(mouseHandler);
-
- if (fCachedTextViewer != null) {
-
- fCachedTextViewer.addViewportListener(fInternalListener);
- fCachedTextViewer.addTextListener(fInternalListener);
- }
-
- return fCanvas;
- }
-
- /**
- * Disposes the column's resources.
- */
- protected void handleDispose() {
-
- if (fAnnotationModel != null) {
- fAnnotationModel.removeAnnotationModelListener(fAnnotationListener);
- fAnnotationModel= null;
- }
-
- if (fCachedTextViewer != null) {
- fCachedTextViewer.removeViewportListener(fInternalListener);
- fCachedTextViewer.removeTextListener(fInternalListener);
- }
-
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
-
- /**
- * Double buffer drawing.
- *
- * @param dest the GC to draw into
- */
- private void doubleBufferPaint(GC dest) {
-
- Point size= fCanvas.getSize();
-
- if (size.x <= 0 || size.y <= 0)
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- gc.setFont(fCanvas.getFont());
- if (fForeground != null)
- gc.setForeground(fForeground);
-
- try {
- gc.setBackground(getBackground(fCanvas.getDisplay()));
- gc.fillRectangle(0, 0, size.x, size.y);
-
- if (fCachedTextViewer instanceof ITextViewerExtension5)
- doPaint1(gc);
- else
- doPaint(gc);
-
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- /**
- * Returns the viewport height in lines.
- *
- * @return the viewport height in lines
- */
- protected int getVisibleLinesInViewport() {
- Rectangle clArea= fCachedTextWidget.getClientArea();
- if (!clArea.isEmpty())
- return clArea.height / fCachedTextWidget.getLineHeight();
- return -1;
- }
-
- /**
- * Draws the ruler column.
- *
- * @param gc the GC to draw into
- */
- private void doPaint(GC gc) {
-
- if (fCachedTextViewer == null)
- return;
-
- if (fCachedTextWidget == null)
- return;
-
-
- int firstLine= 0;
-
- int topLine= fCachedTextViewer.getTopIndex() -1;
- int bottomLine= fCachedTextViewer.getBottomIndex() + 1;
-
- try {
-
- IRegion region= fCachedTextViewer.getVisibleRegion();
- IDocument doc= fCachedTextViewer.getDocument();
-
- if (doc == null)
- return;
-
- firstLine= doc.getLineOfOffset(region.getOffset());
- if (firstLine > topLine)
- topLine= firstLine;
-
- int lastLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- if (lastLine < bottomLine)
- bottomLine= lastLine;
-
- } catch (BadLocationException x) {
- return;
- }
-
- fSensitiveToTextChanges= bottomLine - topLine < getVisibleLinesInViewport();
-
- int lineheight= fCachedTextWidget.getLineHeight();
- fScrollPos= fCachedTextWidget.getTopPixel();
- int canvasheight= fCanvas.getSize().y;
-
- int y= ((topLine - firstLine) * lineheight) - fScrollPos + fCachedTextViewer.getTopInset();
- for (int line= topLine; line <= bottomLine; line++, y+= lineheight) {
-
- if (y >= canvasheight)
- break;
-
- paintLine(line, y, lineheight, gc, fCachedTextWidget.getDisplay());
- }
- }
-
- /**
- * Draws the ruler column. Uses <code>ITextViewerExtension5</code> for the
- * implementation. Will replace <code>doPinat(GC)</code>.
- *
- * @param gc the GC to draw into
- */
- private void doPaint1(GC gc) {
-
- if (fCachedTextViewer == null)
- return;
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
-
- int firstLine= 0;
-
-
- int widgetTopLine= fCachedTextWidget.getTopIndex();
- if (widgetTopLine > 0)
- -- widgetTopLine;
-
- int topLine= extension.widgetLine2ModelLine(widgetTopLine);
- int bottomLine= fCachedTextViewer.getBottomIndex();
- if (bottomLine >= 0)
- ++ bottomLine;
-
- try {
-
- IRegion region= extension.getModelCoverage();
- IDocument doc= fCachedTextViewer.getDocument();
-
- if (doc == null)
- return;
-
- firstLine= doc.getLineOfOffset(region.getOffset());
- if (firstLine > topLine || topLine == -1)
- topLine= firstLine;
-
- int lastLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- if (lastLine < bottomLine || bottomLine == -1)
- bottomLine= lastLine;
-
- } catch (BadLocationException x) {
- return;
- }
-
- fSensitiveToTextChanges= bottomLine - topLine < getVisibleLinesInViewport();
-
- int lineheight= fCachedTextWidget.getLineHeight();
- fScrollPos= fCachedTextWidget.getTopPixel();
- int canvasheight= fCanvas.getSize().y;
-
- int y= (widgetTopLine * lineheight) - fScrollPos + fCachedTextViewer.getTopInset();
- for (int modelLine= topLine; modelLine <= bottomLine; modelLine++) {
-
- if (y >= canvasheight)
- break;
-
- int widgetLine= extension.modelLine2WidgetLine(modelLine);
- if (widgetLine == -1)
- continue;
-
- paintLine(modelLine, y, lineheight, gc, fCachedTextWidget.getDisplay());
-
- y+= lineheight;
- }
- }
-
- /*
- * @see IVerticalRulerColumn#redraw()
- */
- public void redraw() {
-
- if (fCanvas != null && !fCanvas.isDisposed()) {
- GC gc= new GC(fCanvas);
- doubleBufferPaint(gc);
- gc.dispose();
- }
- }
-
- /*
- * @see IVerticalRulerColumn#setFont(Font)
- */
- public void setFont(Font font) {
- }
-
- /**
- * Returns the parent (composite) ruler of this ruler column.
- *
- * @return the parent ruler
- * @since 3.0
- */
- protected CompositeRuler getParentRuler() {
- return fParentRuler;
- }
-
- /*
- * @see org.eclipse.jface.text.source.LineNumberRulerColumn#paintLineHook(int, int, int, org.eclipse.swt.graphics.GC)
- */
- protected void paintLine(int line, int y, int lineheight, GC gc, Display display) {
- ILineDiffInfo info= getDiffInfo(line);
-
- if (info != null) {
- // width of the column
- int width= getWidth();
-
- // draw background color if special
- if (hasSpecialColor(info)) {
- gc.setBackground(getColor(info, display));
- gc.fillRectangle(0, y, width, lineheight);
- }
-
- /* Deletion Indicator: Simply a horizontal line */
- int delBefore= info.getRemovedLinesAbove();
- int delBelow= info.getRemovedLinesBelow();
- if (delBefore > 0 || delBelow > 0) {
- Color deletionColor= getDeletionColor(display);
- gc.setForeground(deletionColor);
-
- if (delBefore > 0) {
- gc.drawLine(0, y, width, y);
- }
-
- if (delBelow > 0) {
- gc.drawLine(0, y + lineheight - 1, width, y + lineheight - 1);
- }
- }
- }
- }
-
- /**
- * Returns whether the line background differs from the default.
- *
- * @param info the info being queried
- * @return <code>true</code> if <code>info</code> describes either a changed or an added line.
- */
- private boolean hasSpecialColor(ILineDiffInfo info) {
- return info.getChangeType() == ILineDiffInfo.ADDED || info.getChangeType() == ILineDiffInfo.CHANGED;
- }
-
- /**
- * Retrieves the <code>ILineDiffInfo</code> for <code>line</code> from the model.
- * There are optimizations for direct access and sequential access patterns.
- *
- * @param line the line we want the info for.
- * @return the <code>ILineDiffInfo</code> for <code>line</code>, or <code>null</code>.
- */
- private ILineDiffInfo getDiffInfo(int line) {
- if (fAnnotationModel == null)
- return null;
-
- // assume direct access
- if (fAnnotationModel instanceof ILineDiffer) {
- ILineDiffer differ= (ILineDiffer)fAnnotationModel;
- return differ.getLineInfo(line);
- }
-
- return null;
- }
-
- /**
- * Returns the color for deleted lines.
- *
- * @param display the display
- * @return the color to be used for the deletion indicator
- */
- private Color getDeletionColor(Display display) {
- return fDeletedColor == null ? getBackground(display) : fDeletedColor;
- }
-
- /**
- * Returns the color for the given line diff info.
- *
- * @param info the <code>ILineDiffInfo</code> being queried
- * @param display the display that the drawing occurs on
- * @return the correct background color for the line type being described by <code>info</code>
- */
- private Color getColor(ILineDiffInfo info, Display display) {
- Assert.isTrue(info != null && info.getChangeType() != ILineDiffInfo.UNCHANGED);
- Color ret= null;
- switch (info.getChangeType()) {
- case ILineDiffInfo.CHANGED :
- ret= fChangedColor;
- break;
- case ILineDiffInfo.ADDED :
- ret= fAddedColor;
- break;
- }
- return ret == null ? getBackground(display) : ret;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- */
- public int getLineOfLastMouseButtonActivity() {
- return getParentRuler().getLineOfLastMouseButtonActivity();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int)
- */
- public int toDocumentLineNumber(int y_coordinate) {
- return getParentRuler().toDocumentLineNumber(y_coordinate);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover()
- */
- public IAnnotationHover getHover() {
- return fHover;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IChangeRulerColumn#setHover(org.eclipse.jface.text.source.IAnnotationHover)
- */
- public void setHover(IAnnotationHover hover) {
- fHover= hover;
- }
-
- /*
- * @see IVerticalRulerColumn#setModel(IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- IAnnotationModel newModel;
- if (model instanceof IAnnotationModelExtension) {
- newModel= ((IAnnotationModelExtension)model).getAnnotationModel(QUICK_DIFF_MODEL_ID);
- } else {
- newModel= model;
- }
- if (fAnnotationModel != newModel) {
- if (fAnnotationModel != null) {
- fAnnotationModel.removeAnnotationModelListener(fAnnotationListener);
- }
- fAnnotationModel= newModel;
- if (fAnnotationModel != null) {
- fAnnotationModel.addAnnotationModelListener(fAnnotationListener);
- }
- redraw();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IChangeRulerColumn#setBackground(org.eclipse.swt.graphics.Color)
- */
- public void setBackground(Color background) {
- fBackground= background;
- if (fCanvas != null && !fCanvas.isDisposed())
- fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
- }
-
- /*
- * @see org.eclipse.jface.text.source.IChangeRulerColumn#setAddedColor(org.eclipse.swt.graphics.Color)
- */
- public void setAddedColor(Color addedColor) {
- fAddedColor= addedColor;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IChangeRulerColumn#setChangedColor(org.eclipse.swt.graphics.Color)
- */
- public void setChangedColor(Color changedColor) {
- fChangedColor= changedColor;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IChangeRulerColumn#setDeletedColor(org.eclipse.swt.graphics.Color)
- */
- public void setDeletedColor(Color deletedColor) {
- fDeletedColor= deletedColor;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getModel()
- */
- public IAnnotationModel getModel() {
- return fAnnotationModel;
- }
-
- /*
- * @see IVerticalRulerColumn#getControl()
- */
- public Control getControl() {
- return fCanvas;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getWidth()
- */
- public int getWidth() {
- return fWidth;
- }
-
- /**
- * Triggers a redraw in the display thread.
- */
- protected final void postRedraw() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- Display d= fCanvas.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- redraw();
- }
- });
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- */
- public void addVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- */
- public void removeVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java
deleted file mode 100644
index f0c9f0f87f2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/CompositeRuler.java
+++ /dev/null
@@ -1,856 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Set;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.ControlListener;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.FocusListener;
-import org.eclipse.swt.events.HelpListener;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackListener;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.events.TraverseListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.internal.SWTEventListener;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
-import org.eclipse.swt.widgets.Layout;
-import org.eclipse.swt.widgets.Listener;
-import org.eclipse.swt.widgets.Menu;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.ITextViewerExtension5;
-
-
-/**
- * Standard implementation of <code>IVerticalRuler</code>. This ruler does not have a
- * a visual representation of its own. The presentation comes from the configurable list
- * of decorators. Decorators must implement the <code>IVerticalRulerColumn</code>
- * interface.<p>
- * Clients may instantiate and configure this class.
- *
- * @see IVerticalRulerColumn
- * @see ITextViewer
- * @since 2.0
- */
-public class CompositeRuler implements IVerticalRuler, IVerticalRulerExtension, IVerticalRulerInfoExtension {
-
-
- /**
- * Layout of the composite vertical ruler. Arranges the list of decorators.
- */
- class RulerLayout extends Layout {
-
- /**
- * Creates the new ruler layout.
- */
- protected RulerLayout() {
- }
-
- /*
- * @see Layout#computeSize(Composite, int, int, boolean)
- */
- protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- Control[] children= composite.getChildren();
- Point size= new Point(0, 0);
- for (int i= 0; i < children.length; i++) {
- Point s= children[i].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
- size.x += s.x;
- size.y= Math.max(size.y, s.y);
- }
- size.x += (Math.max(0, children.length -1) * fGap);
- return size;
- }
-
- /*
- * @see Layout#layout(Composite, boolean)
- */
- protected void layout(Composite composite, boolean flushCache) {
- Rectangle clArea= composite.getClientArea();
- int rulerHeight= clArea.height;
-
- int x= 0;
- Iterator e= fDecorators.iterator();
- while (e.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
- int columnWidth= column.getWidth();
- column.getControl().setBounds(x, 0, columnWidth, rulerHeight);
- x += (columnWidth + fGap);
- }
- }
- }
-
- /**
- * A canvas that adds listeners to all its children. Used by the implementation of the
- * vertical ruler to propagate listener additions and removals to the ruler's columns.
- */
- static class CompositeRulerCanvas extends Canvas {
-
- /**
- * Keeps the information for which event type a listener object has been added.
- */
- static class ListenerInfo {
- Class fClass;
- SWTEventListener fListener;
- }
-
- /** The list of listeners added to this canvas. */
- private List fCachedListeners= new ArrayList();
- /**
- * Internal listener for opening the context menu.
- * @since 3.0
- */
- private Listener fMenuDetectListener;
-
- /**
- * Creates a new composite ruler canvas.
- *
- * @param parent the parent composite
- * @param style the SWT styles
- */
- public CompositeRulerCanvas(Composite parent, int style) {
- super(parent, style);
- fMenuDetectListener= new Listener() {
- public void handleEvent(Event event) {
- if (event.type == SWT.MenuDetect) {
- Menu menu= getMenu();
- if (menu != null) {
- menu.setLocation(event.x, event.y);
- menu.setVisible(true);
- }
- }
- }
- };
- super.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- if (fCachedListeners != null) {
- fCachedListeners.clear();
- fCachedListeners= null;
- }
- }
- });
- }
-
- /**
- * Adds the given listener object as listener of the given type (<code>clazz</code>) to
- * the given control.
- *
- * @param clazz the listener type
- * @param control the control to add the listener to
- * @param listener the listener to be added
- */
- private void addListener(Class clazz, Control control, SWTEventListener listener) {
- if (ControlListener.class.equals(clazz)) {
- control. addControlListener((ControlListener) listener);
- return;
- }
- if (FocusListener.class.equals(clazz)) {
- control. addFocusListener((FocusListener) listener);
- return;
- }
- if (HelpListener.class.equals(clazz)) {
- control. addHelpListener((HelpListener) listener);
- return;
- }
- if (KeyListener.class.equals(clazz)) {
- control. addKeyListener((KeyListener) listener);
- return;
- }
- if (MouseListener.class.equals(clazz)) {
- control. addMouseListener((MouseListener) listener);
- return;
- }
- if (MouseMoveListener.class.equals(clazz)) {
- control. addMouseMoveListener((MouseMoveListener) listener);
- return;
- }
- if (MouseTrackListener.class.equals(clazz)) {
- control. addMouseTrackListener((MouseTrackListener) listener);
- return;
- }
- if (PaintListener.class.equals(clazz)) {
- control. addPaintListener((PaintListener) listener);
- return;
- }
- if (TraverseListener.class.equals(clazz)) {
- control. addTraverseListener((TraverseListener) listener);
- return;
- }
- if (DisposeListener.class.equals(clazz)) {
- control. addDisposeListener((DisposeListener) listener);
- return;
- }
- }
-
- /**
- * Removes the given listener object as listner of the given type (<code>clazz</code>) from
- * the given control.
- *
- * @param clazz the listener type
- * @param control the control to remove the listener from
- * @param listener the listener to be removed
- */
- private void removeListener(Class clazz, Control control, SWTEventListener listener) {
- if (ControlListener.class.equals(clazz)) {
- control. removeControlListener((ControlListener) listener);
- return;
- }
- if (FocusListener.class.equals(clazz)) {
- control. removeFocusListener((FocusListener) listener);
- return;
- }
- if (HelpListener.class.equals(clazz)) {
- control. removeHelpListener((HelpListener) listener);
- return;
- }
- if (KeyListener.class.equals(clazz)) {
- control. removeKeyListener((KeyListener) listener);
- return;
- }
- if (MouseListener.class.equals(clazz)) {
- control. removeMouseListener((MouseListener) listener);
- return;
- }
- if (MouseMoveListener.class.equals(clazz)) {
- control. removeMouseMoveListener((MouseMoveListener) listener);
- return;
- }
- if (MouseTrackListener.class.equals(clazz)) {
- control. removeMouseTrackListener((MouseTrackListener) listener);
- return;
- }
- if (PaintListener.class.equals(clazz)) {
- control. removePaintListener((PaintListener) listener);
- return;
- }
- if (TraverseListener.class.equals(clazz)) {
- control. removeTraverseListener((TraverseListener) listener);
- return;
- }
- if (DisposeListener.class.equals(clazz)) {
- control. removeDisposeListener((DisposeListener) listener);
- return;
- }
- }
-
- /**
- * Adds the given listener object to the internal book keeping under
- * the given listener type (<code>clazz</code>).
- *
- * @param clazz the listener type
- * @param listener the listener object
- */
- private void addListener(Class clazz, SWTEventListener listener) {
- Control[] children= getChildren();
- for (int i= 0; i < children.length; i++) {
- if (children[i] != null && !children[i].isDisposed())
- addListener(clazz, children[i], listener);
- }
-
- ListenerInfo info= new ListenerInfo();
- info.fClass= clazz;
- info.fListener= listener;
- fCachedListeners.add(info);
- }
-
- /**
- * Removes the given listener object from the internal book keeping under
- * the given listener type (<code>clazz</code>).
- *
- * @param clazz the listener type
- * @param listener the listener object
- */
- private void removeListener(Class clazz, SWTEventListener listener) {
- int length= fCachedListeners.size();
- for (int i= 0; i < length; i++) {
- ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
- if (listener == info.fListener && clazz.equals(info.fClass)) {
- fCachedListeners.remove(i);
- break;
- }
- }
-
- Control[] children= getChildren();
- for (int i= 0; i < children.length; i++) {
- if (children[i] != null && !children[i].isDisposed())
- removeListener(clazz, children[i], listener);
- }
- }
-
- /**
- * Tells this canvas that a child has been added.
- *
- * @param child the child
- */
- public void childAdded(Control child) {
- if (child != null && !child.isDisposed()) {
- int length= fCachedListeners.size();
- for (int i= 0; i < length; i++) {
- ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
- addListener(info.fClass, child, info.fListener);
- }
- child.addListener(SWT.MenuDetect, fMenuDetectListener);
- }
- }
-
- /**
- * Tells this canvas that a child has been removed.
- *
- * @param child the child
- */
- public void childRemoved(Control child) {
- if (child != null && !child.isDisposed()) {
- int length= fCachedListeners.size();
- for (int i= 0; i < length; i++) {
- ListenerInfo info= (ListenerInfo) fCachedListeners.get(i);
- removeListener(info.fClass, child, info.fListener);
- }
- child.removeListener(SWT.MenuDetect, fMenuDetectListener);
- }
- }
-
- /*
- * @see Control#removeControlListener(ControlListener)
- */
- public void removeControlListener(ControlListener listener) {
- removeListener(ControlListener.class, listener);
- super.removeControlListener(listener);
- }
-
- /*
- * @see Control#removeFocusListener(FocusListener)
- */
- public void removeFocusListener(FocusListener listener) {
- removeListener(FocusListener.class, listener);
- super.removeFocusListener(listener);
- }
-
- /*
- * @see Control#removeHelpListener(HelpListener)
- */
- public void removeHelpListener(HelpListener listener) {
- removeListener(HelpListener.class, listener);
- super.removeHelpListener(listener);
- }
-
- /*
- * @see Control#removeKeyListener(KeyListener)
- */
- public void removeKeyListener(KeyListener listener) {
- removeListener(KeyListener.class, listener);
- super.removeKeyListener(listener);
- }
-
- /*
- * @see Control#removeMouseListener(MouseListener)
- */
- public void removeMouseListener(MouseListener listener) {
- removeListener(MouseListener.class, listener);
- super.removeMouseListener(listener);
- }
-
- /*
- * @see Control#removeMouseMoveListener(MouseMoveListener)
- */
- public void removeMouseMoveListener(MouseMoveListener listener) {
- removeListener(MouseMoveListener.class, listener);
- super.removeMouseMoveListener(listener);
- }
-
- /*
- * @see Control#removeMouseTrackListener(MouseTrackListener)
- */
- public void removeMouseTrackListener(MouseTrackListener listener) {
- removeListener(MouseTrackListener.class, listener);
- super.removeMouseTrackListener(listener);
- }
-
- /*
- * @see Control#removePaintListener(PaintListener)
- */
- public void removePaintListener(PaintListener listener) {
- removeListener(PaintListener.class, listener);
- super.removePaintListener(listener);
- }
-
- /*
- * @see Control#removeTraverseListener(TraverseListener)
- */
- public void removeTraverseListener(TraverseListener listener) {
- removeListener(TraverseListener.class, listener);
- super.removeTraverseListener(listener);
- }
-
- /*
- * @see Widget#removeDisposeListener(DisposeListener)
- */
- public void removeDisposeListener(DisposeListener listener) {
- removeListener(DisposeListener.class, listener);
- super.removeDisposeListener(listener);
- }
-
- /*
- * @seeControl#addControlListener(ControlListener)
- */
- public void addControlListener(ControlListener listener) {
- super.addControlListener(listener);
- addListener(ControlListener.class, listener);
- }
-
- /*
- * @see Control#addFocusListener(FocusListener)
- */
- public void addFocusListener(FocusListener listener) {
- super.addFocusListener(listener);
- addListener(FocusListener.class, listener);
- }
-
- /*
- * @see Control#addHelpListener(HelpListener)
- */
- public void addHelpListener(HelpListener listener) {
- super.addHelpListener(listener);
- addListener(HelpListener.class, listener);
- }
-
- /*
- * @see Control#addKeyListener(KeyListener)
- */
- public void addKeyListener(KeyListener listener) {
- super.addKeyListener(listener);
- addListener(KeyListener.class, listener);
- }
-
- /*
- * @see Control#addMouseListener(MouseListener)
- */
- public void addMouseListener(MouseListener listener) {
- super.addMouseListener(listener);
- addListener(MouseListener.class, listener);
- }
-
- /*
- * @see Control#addMouseMoveListener(MouseMoveListener)
- */
- public void addMouseMoveListener(MouseMoveListener listener) {
- super.addMouseMoveListener(listener);
- addListener(MouseMoveListener.class, listener);
- }
-
- /*
- * @see Control#addMouseTrackListener(MouseTrackListener)
- */
- public void addMouseTrackListener(MouseTrackListener listener) {
- super.addMouseTrackListener(listener);
- addListener(MouseTrackListener.class, listener);
- }
-
- /*
- * @seeControl#addPaintListener(PaintListener)
- */
- public void addPaintListener(PaintListener listener) {
- super.addPaintListener(listener);
- addListener(PaintListener.class, listener);
- }
-
- /*
- * @see Control#addTraverseListener(TraverseListener)
- */
- public void addTraverseListener(TraverseListener listener) {
- super.addTraverseListener(listener);
- addListener(TraverseListener.class, listener);
- }
-
- /*
- * @see Widget#addDisposeListener(DisposeListener)
- */
- public void addDisposeListener(DisposeListener listener) {
- super.addDisposeListener(listener);
- addListener(DisposeListener.class, listener);
- }
- }
-
- /** The ruler's viewer */
- private ITextViewer fTextViewer;
- /** The ruler's canvas to which to add the ruler columns */
- private CompositeRulerCanvas fComposite;
- /** The ruler's annotation model */
- private IAnnotationModel fModel;
- /** The list of decorators */
- private List fDecorators= new ArrayList(2);
- /** The cached location of the last mouse button activity */
- private Point fLocation= new Point(-1, -1);
- /** The cached line of the list mouse button activity */
- private int fLastMouseButtonActivityLine= -1;
- /** The gap between the individual columns of this composite ruler */
- private int fGap;
- /**
- * The set of annotation listeners.
- * @since 3.0
- */
- private Set fAnnotationListeners= new HashSet();
-
-
- /**
- * Constructs a new composite vertical ruler.
- */
- public CompositeRuler() {
- this(0);
- }
-
- /**
- * Constructs a new composite ruler with the given gap between its columns.
- *
- * @param gap
- */
- public CompositeRuler(int gap) {
- fGap= gap;
- }
-
- /**
- * Inserts the given decorator at the specfied slot to this composite ruler.
- * Decorators are counted from left to right.
- *
- * @param index the index
- * @param rulerColumn the decorator to be inserted
- */
- public void addDecorator(int index, IVerticalRulerColumn rulerColumn) {
- if (index > fDecorators.size())
- fDecorators.add(rulerColumn);
- else
- fDecorators.add(index, rulerColumn);
-
- if (fComposite != null && !fComposite.isDisposed()) {
- rulerColumn.createControl(this, fComposite);
- fComposite.childAdded(rulerColumn.getControl());
- layoutTextViewer();
- }
- }
-
- /**
- * Removes the decorator in the specified slot from this composite ruler.
- *
- * @param index the index
- */
- public void removeDecorator(int index) {
- IVerticalRulerColumn rulerColumn= (IVerticalRulerColumn) fDecorators.get(index);
- removeDecorator(rulerColumn);
- }
-
- /**
- * Removes the given decorator from the composite ruler.
- *
- * @param rulerColumn the ruler column to be removed
- * @since 3.0
- */
- public void removeDecorator(IVerticalRulerColumn rulerColumn) {
- fDecorators.remove(rulerColumn);
- if (rulerColumn != null) {
- Control cc= rulerColumn.getControl();
- if (cc != null && !cc.isDisposed()) {
- fComposite.childRemoved(cc);
- cc.dispose();
- }
- }
- layoutTextViewer();
- }
-
- /**
- * Relayouts the text viewer. This also causes this ruler to get
- * relayouted.
- */
- private void layoutTextViewer() {
-
- Control parent= fTextViewer.getTextWidget();
-
- if (fTextViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fTextViewer;
- parent= extension.getControl();
- }
-
- if (parent instanceof Composite && !parent.isDisposed())
- ((Composite) parent).layout(true);
- }
-
- /*
- * @see IVerticalRuler#getControl()
- */
- public Control getControl() {
- return fComposite;
- }
-
- /*
- * @see IVerticalRuler#createControl(Composite, ITextViewer)
- */
- public Control createControl(Composite parent, ITextViewer textViewer) {
-
- fTextViewer= textViewer;
-
- fComposite= new CompositeRulerCanvas(parent, SWT.NONE);
- fComposite.setLayout(new RulerLayout());
-
- Iterator iter= fDecorators.iterator();
- while (iter.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) iter.next();
- column.createControl(this, fComposite);
- fComposite.childAdded(column.getControl());
- }
-
- parent.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- fTextViewer= null;
- fComposite= null;
- fModel= null;
- fDecorators.clear();
- }
- });
-
- return fComposite;
- }
-
- /*
- * @see IVerticalRuler#setModel(IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
-
- fModel= model;
-
- Iterator e= fDecorators.iterator();
- while (e.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
- column.setModel(model);
- }
- }
-
- /*
- * @see IVerticalRuler#getModel()
- */
- public IAnnotationModel getModel() {
- return fModel;
- }
-
- /*
- * @see IVerticalRuler#update()
- */
- public void update() {
- if (fComposite != null && !fComposite.isDisposed()) {
- Display d= fComposite.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- Iterator e= fDecorators.iterator();
- while (e.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
- column.redraw();
- }
- }
- });
- }
- }
- }
-
- /*
- * @see IVerticalRulerExtension#setFont(Font)
- */
- public void setFont(Font font) {
- Iterator e= fDecorators.iterator();
- while (e.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
- column.setFont(font);
- }
- }
-
- /*
- * @see IVerticalRulerInfo#getWidth()
- */
- public int getWidth() {
- int width= 0;
- Iterator e= fDecorators.iterator();
- while (e.hasNext()) {
- IVerticalRulerColumn column= (IVerticalRulerColumn) e.next();
- width += (column.getWidth() + fGap);
- }
- return Math.max(0, width - fGap);
- }
-
- /*
- * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- */
- public int getLineOfLastMouseButtonActivity() {
- if (fLastMouseButtonActivityLine == -1)
- fLastMouseButtonActivityLine= toDocumentLineNumber(fLocation.y);
- return fLastMouseButtonActivityLine;
- }
-
- /*
- * @see IVerticalRulerInfo#toDocumentLineNumber(int)
- */
- public int toDocumentLineNumber(int y_coordinate) {
-
- if (fTextViewer == null || y_coordinate == -1)
- return -1;
-
- StyledText text= fTextViewer.getTextWidget();
- int line= ((y_coordinate + text.getTopPixel()) / text.getLineHeight());
- return widgetLine2ModelLine(fTextViewer, line);
- }
-
- /**
- * Returns the line in the given viewer's document that correspond to the given
- * line of the viewer's widget.
- *
- * @param viewer the viewer
- * @param widgetLine the widget line
- * @return the corresponding line the viewer's document
- * @since 2.1
- */
- protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
-
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
- return extension.widgetLine2ModelLine(widgetLine);
- }
-
- try {
- IRegion r= viewer.getVisibleRegion();
- IDocument d= viewer.getDocument();
- return widgetLine += d.getLineOfOffset(r.getOffset());
- } catch (BadLocationException x) {
- }
- return widgetLine;
- }
-
- /**
- * Returns this ruler's text viewer.
- *
- * @return this ruler's text viewer
- */
- public ITextViewer getTextViewer() {
- return fTextViewer;
- }
-
- /*
- * @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int)
- */
- public void setLocationOfLastMouseButtonActivity(int x, int y) {
- fLocation.x= x;
- fLocation.y= y;
- fLastMouseButtonActivityLine= -1;
- }
-
- /**
- * Returns an iterator over the <code>IVerticalRulerColumns</code> that make up this
- * composite column.
- *
- * @return an iterator over the contained columns.
- * @since 3.0
- */
- public Iterator getDecoratorIterator() {
- Assert.isNotNull(fDecorators, "fDecorators must be initialized"); //$NON-NLS-1$
- return fDecorators.iterator();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover()
- * @since 3.0
- */
- public IAnnotationHover getHover() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- * @since 3.0
- */
- public void addVerticalRulerListener(IVerticalRulerListener listener) {
- fAnnotationListeners.add(listener);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- * @since 3.0
- */
- public void removeVerticalRulerListener(IVerticalRulerListener listener) {
- fAnnotationListeners.remove(listener);
- }
-
- /**
- * Fires the annotation selected event to all registered vertical ruler
- * listeners.
- * TODO use robust iterators
- *
- * @param event the event to fire
- * @since 3.0
- */
- public void fireAnnotationSelected(VerticalRulerEvent event) {
- // forward to listeners
- for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
- IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
- listener.annotationSelected(event);
- }
- }
-
- /**
- * Fires the annotation default selected event to all registered vertical
- * ruler listeners.
- * TODO use robust iterators
- *
- * @param event the event to fire
- * @since 3.0
- */
- public void fireAnnotationDefaultSelected(VerticalRulerEvent event) {
- // forward to listeners
- for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
- IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
- listener.annotationDefaultSelected(event);
- }
- }
-
- /**
- * Informs all registered vertical ruler listeners that the content menu on a selected annotation\
- * is about to be shown.
- * TODO use robust iterators
- *
- * @param event the event to fire
- * @param menu the menu that is about to be shown
- * @since 3.0
- */
- public void fireAnnotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu) {
- // forward to listeners
- for (Iterator it= fAnnotationListeners.iterator(); it.hasNext();) {
- IVerticalRulerListener listener= (IVerticalRulerListener) it.next();
- listener.annotationContextMenuAboutToShow(event, menu);
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
deleted file mode 100644
index d666c6b296f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccess.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-/**
- * An annotation access provides access to information that is not available via the
- * API of <code>Annotation</code>. Clients usually implement this interface.
- *
- * @see org.eclipse.jface.text.source.Annotation
- * @since 2.1
- */
-public interface IAnnotationAccess {
-
- /**
- * Returns the type of the given annotation.
- *
- * @param annotation the annotation
- * @return the type of the given annotation or <code>null</code> if it has none.
- * @deprecated use <code>Annotation.getType()</code>
- */
- Object getType(Annotation annotation);
-
- /**
- * Returns whether the given annotation spans multiple lines.
- *
- * @param annotation the annotation
- * @return <code>true</code> if the annotation spans multiple lines,
- * <code>false</code> otherwise
- *
- * @deprecated assumed to always return <code>true</code>
- */
- boolean isMultiLine(Annotation annotation);
-
- /**
- * Returns whether the given annotation is temporary rather than persistent.
- *
- * @param annotation the annotation
- * @return <code>true</code> if the annotation is temporary,
- * <code>false</code> otherwise
- * @deprecated use <code>Annotation.isPersistent()</code>
- */
- boolean isTemporary(Annotation annotation);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
deleted file mode 100644
index c4e7c10c2a5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationAccessExtension.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-
-/**
- * Extension interface for <code>IAnnotationAccess</code>.
- * Allows to get a label for the annotation's type.
- * </code>.
- *
- * @since 3.0
- */
-public interface IAnnotationAccessExtension {
-
- /**
- * The default annotation layer.
- */
- static final int DEFAULT_LAYER= IAnnotationPresentation.DEFAULT_LAYER;
-
- /**
- * Returns the label for the given annotation's type.
- *
- * @param annotation the annotation
- * @return the label the given annotation's type or <code>null</code> if no such label exists
- */
- String getTypeLabel(Annotation annotation);
-
- /**
- * Returns the layer for given annotation. Annotations are considered
- * being located at layers and are considered being painted starting with
- * layer 0 upwards. Thus an annotation at layer 5 will be drawn on top of
- * all co-located annotations at the layers 4 - 0.
- *
- * @param annotation the annotation
- * @return the layer of the given annotation
- */
- int getLayer(Annotation annotation);
-
- /**
- * Draws a graphical representation of the given annotation within the given bounds.
- *
- * @param annotation the given annotation
- * @param gc the drawing GC
- * @param canvas the canvas to draw on
- * @param bounds the bounds inside the canvas to draw on
- */
- void paint(Annotation annotation, GC gc, Canvas canvas, Rectangle bounds);
-
- /**
- * Returns <code>true</code> if painting <code>annotation</code> will produce something
- * meaningful, <code>false</code> if not. E.g. if no image is available.
- *
- * @param annotation the annotation to check for paintability
- * @return <code>true</code> if painting <code>annotation</code> will succeed
- */
- boolean isPaintable(Annotation annotation);
-
- /**
- * Returns <code>true</code> if the given annotation is of the given type
- * or <code>false</code> otherwise.
- *
- * @param annotationType the annotation type
- * @param potentialSupertype the potential super annotation type
- * @return <code>true</code> if annotation type is a subtype of the potential annotation super type
- */
- boolean isSubtype(Object annotationType, Object potentialSupertype);
-
- /**
- * Returns the list of super types for the given annotation type. This does not include the type
- * itself. The index in the array of super types indicates the length of the path in the hierarchy
- * graph to the given annotation type.
- *
- * @param annotationType the annotation type to check
- * @return the super types for the given annotation type
- */
- Object[] getSupertypes(Object annotationType);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java
deleted file mode 100644
index 885c099e200..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHover.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-
-
-/**
- * Provides the information to be displayed in a hover popup window
- * which appears over the presentation area of annotations. Clients
- * may implement this interface.
- */
-public interface IAnnotationHover {
-
- /**
- * Returns the text which should be presented in the a
- * hover popup window. This information is requested based on
- * the specified line number.
- *
- * @param sourceViewer the source viewer this hover is registered with
- * @param lineNumber the line number for which information is requested
- * @return the requested information or <code>null</code> if no such information exists
- */
- String getHoverInfo(ISourceViewer sourceViewer, int lineNumber);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java
deleted file mode 100644
index 6a50ebb766d..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationHoverExtension.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.jface.text.IInformationControlCreator;
-
-/**
- * Extension to <code>IAnnotationHover</code> for
- * <ul>
- * <li>providing its own information control creator</li>
- * <li>providing the range of lines for which the hover for a given line is valid</li>
- * <li>providing whether the information control can interact with the mouse cursor</li>
- * </ul>
- *
- * @see org.eclipse.jface.text.IInformationControlCreator
- * @see org.eclipse.jface.text.source.IAnnotationHover
- * @since 3.0
- */
-public interface IAnnotationHoverExtension {
-
- /**
- * Returns the hover control creator of this annotation hover.
- *
- * @return the hover control creator
- */
- IInformationControlCreator getHoverControlCreator();
-
- /**
- * Returns whether the provided information control can interact with the mouse cursor. I.e. the
- * hover must implement custom information control management.
- *
- * @return <code>true</code> if the mouse cursor can be handled
- */
- boolean canHandleMouseCursor();
-
- /**
- * Returns the object which should be presented in the a
- * hover popup window. The information is requested based on
- * the specified line range.
- *
- * @param sourceViewer the source viewer this hover is registered with
- * @param lineRange the line range for which information is requested
- * @param visibleNumberOfLines the number of visible lines
- * @return the requested information or <code>null</code> if no such information exists
- */
- Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleNumberOfLines);
-
- /**
- * Returns the range of lines that include the given line number for which
- * the same hover information is valid.
- *
- * @param viewer the viewer which the hover is queried for
- * @param lineNumber the line number of the line for which a hover is displayed for
- * @return the computed line range
- */
- ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
deleted file mode 100644
index 784662ffc00..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IAnnotationPresentation.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-
-/**
- * Interface for annotations that know how to represent themselves.
- *
- * @since 3.0
- */
-public interface IAnnotationPresentation {
-
- /**
- * The default annotation layer.
- */
- static final int DEFAULT_LAYER= 0;
-
-
- /**
- * Returns the annotations drawing layer.
- *
- * @return the annotations drawing layer
- */
- int getLayer();
-
- /**
- * Implement this method to draw a graphical representation
- * of this annotation within the given bounds.
- *
- * @param gc the drawing GC
- * @param canvas the canvas to draw on
- * @param bounds the bounds inside the canvas to draw on
- */
- void paint(GC gc, Canvas canvas, Rectangle bounds);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IChangeRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IChangeRulerColumn.java
deleted file mode 100644
index 51a5c4fdfec..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IChangeRulerColumn.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.Color;
-
-/**
- * An <code>IChangeRulerColumn</code> can display quick diff information.
- *
- * @since 3.0
- */
-public interface IChangeRulerColumn extends IVerticalRulerColumn, IVerticalRulerInfoExtension {
-
- /** The ID under which the quick diff model is registered with a document's annotation model. */
- public static final String QUICK_DIFF_MODEL_ID= "diff"; //$NON-NLS-1$
-
- /**
- * Sets the hover of this ruler column.
- *
- * @param hover the hover that will produce hover information text for this ruler column
- */
- public abstract void setHover(IAnnotationHover hover);
-
- /**
- * Sets the background color for normal lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param addedColor the new color to be used as standard line background
- */
- public abstract void setBackground(Color addedColor);
-
- /**
- * Sets the background color for added lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param addedColor the new color to be used for the added lines background
- */
- public abstract void setAddedColor(Color addedColor);
-
- /**
- * Sets the background color for changed lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param changedColor the new color to be used for the changed lines background
- */
- public abstract void setChangedColor(Color changedColor);
-
- /**
- * Sets the color for the deleted lines indicator. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param deletedColor the new color to be used for the deleted lines indicator.
- */
- public abstract void setDeletedColor(Color deletedColor);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
deleted file mode 100644
index d999f67679e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ICharacterPairMatcher.java
+++ /dev/null
@@ -1,70 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-
-/**
- * A character pair matcher finds to a character at a certain document offset the matching peer character.
- * It is the matchers responsibility to define the concepts of "matching" and "peer". The matching process
- * starts at a given offset. Starting of this offset, the matcher chooses a character close to this offset. The
- * anchor defines whether the chosen character is left or right of the initial offset. The matcher then searches
- * for the matching peer character of the chosen character and if it finds one, delivers the minimal region of
- * the document that contains both characters.
- *
- * @since 2.1
- */
-public interface ICharacterPairMatcher {
-
- /**
- * Indicates the anchor value "right".
- */
- int RIGHT= 0;
- /**
- * Indicates the anchor value "left".
- */
- int LEFT= 1;
-
-
- /**
- * Disposes this pair matcher.
- */
- void dispose();
-
- /**
- * Clears this pair matcher. I.e. the matcher throws away all state it might
- * remember and prepares itself for a new call of the <code>match</code>
- * method.
- */
- void clear();
-
- /**
- * Starting at the given offset, the matcher chooses a character close to this offset.
- * The matcher then searches for the matching peer character of the chosen character
- * and if it finds one, returns the minimal region of the document that contains both characters.
- * It returns <code>null</code> if there is no peer character.
- *
- * @param iDocument the document to work on
- * @param i the start offset
- * @return the minimal region containg the peer characters
- */
- IRegion match(IDocument iDocument, int i);
-
- /**
- * Returns the anchor for the region of the matching peer characters. The anchor
- * says whether the character that has been chosen to search for its peer character
- * has been left or right of the initial offset.
- *
- * @return <code>RIGHT</code> or <code>LEFT</code>
- */
- int getAnchor();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java
deleted file mode 100644
index d90999a14e0..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffInfo.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-/**
- * Describes the change state of one line, which consists of the state of the line itself, which
- * can be <code>UNCHANGED</code>, <code>CHANGED</code> or <code>ADDED</code>, and the number of
- * deleted lines before and after this line.
- * <p>
- * This interface may be implemented by clients.
- * </p>
- *
- * @since 3.0
- */
-public interface ILineDiffInfo {
-
- /** Denotes an unchanged line. */
- static final int UNCHANGED= 0;
-
- /** Denotes an added line. */
- static final int ADDED= 1;
-
- /** Denotes a changed line. */
- static final int CHANGED= 2;
-
- /**
- * Returns the number of deleted lines after this line.
- *
- * @return the number of lines after this line.
- */
- int getRemovedLinesBelow();
-
- /**
- * Returns the number of deleted lines before this line.
- *
- * @return the number of lines before this line.
- */
- int getRemovedLinesAbove();
-
- /**
- * Returns the type of this line, one out of <code>UNCHANGED</code>, <code>CHANGED</code> or
- * <code>ADDED</code>.
- *
- * @return the type of this line.
- */
- int getChangeType();
-
- /**
- * Returns whether this line has any changes (to itself, or any deletions before or after it).
- *
- * @return <code>true</code>, if the line's state (as returned by <code>getType</code>) is
- * either <code>CHANGED</code> or <code>ADDED</code> or either of <code>getRemovedLinesBelow</code>
- * and <code>getRemovedLinesAbove</code> would return a number &gt; 0
- */
- boolean hasChanges();
-
- /**
- * Returns the original text of this changed region
- *
- * @return the original text of this changed region, including any deleted lines. The returned
- * value and its elements may not be <code>null/code>, it may however be of zero length
- */
- String[] getOriginalText();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffer.java
deleted file mode 100644
index e65873da562..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineDiffer.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.jface.text.BadLocationException;
-
-
-/**
- * Protocol that allows direct access to line information. Usually, implementations will also
- * implement <code>IAnnotationModel</code>, which only allows <code>Iterator</code> based access
- * to annotations.
- * <p>
- * This interface may be implemented by clients.
- * </p>
- *
- * @since 3.0
- */
-public interface ILineDiffer {
-
- /**
- * Determines the line state for line <code>line</code> in the targeted document.
- *
- * @param line the line to get diff information for
- * @return the line information object for <code>line</code>.
- */
- ILineDiffInfo getLineInfo(int line);
-
- /**
- * Reverts a single changed line to its original state, not touching any lines that
- * are deleted at its borders.
- *
- * @param line the line number of the line to be restored.
- * @throws BadLocationException if <code>line</code> is out of bounds.
- */
- void revertLine(int line) throws BadLocationException;
-
- /**
- * Reverts a block of modified / added lines to their original state, including any deleted
- * lines inside the block or at its borders. A block is considered to be a range of modified
- * (e.g. changed, or added) lines.
- *
- * @param line any line in the block to be reverted.
- * @throws BadLocationException if <code>line</code> is out of bounds.
- */
- void revertBlock(int line) throws BadLocationException;
-
- /**
- * Reverts a range of lines to their original state, including any deleted
- * lines inside the block or at its borders.
- *
- * @param line any line in the block to be reverted.
- * @param nLines the number of lines to be reverted, must be &gt; 0.
- * @throws BadLocationException if <code>line</code> is out of bounds.
- */
- void revertSelection(int line, int nLines) throws BadLocationException;
-
- /**
- * Restores the deleted lines after <code>line</code>.
- *
- * @param line the deleted lines following this line number are restored.
- * @return the number of restored lines.
- * @throws BadLocationException if <code>line</code> is out of bounds.
- */
- int restoreAfterLine(int line) throws BadLocationException;
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineRange.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineRange.java
deleted file mode 100644
index c14d22acc5b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ILineRange.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-/**
- * @since 3.0
- */
-public interface ILineRange {
-
- /**
- * Returns the start line of this line range.
- *
- * @return the start line of this line range or <code>-1</code> if this line range is invalid.
- */
- int getStartLine();
-
- /**
- * Returns the number of lines of this line range.
- *
- * @return the number of lines in this line range or <code>-1</code> if this line range is invalid.
- */
- int getNumberOfLines();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IOverviewRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IOverviewRuler.java
deleted file mode 100644
index cdd70424bbf..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IOverviewRuler.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Control;
-
-/**
- * This interface defines a visual component which may serve
- * text viewers as an overview annotation presentation area. This means,
- * presentation of annotations is independent from the actual viewport of
- * the text viewer. The annotations of the viewer's whole document are
- * visible in the overview ruler.
- *
- * This interfaces comprises three contracts:
- * <ul>
- * <li> The overview ruler retrieves the annotations it presents from an annotation model.
- * <li> The ruler is a visual component which must be integrated in a hierarchy of SWT controls.
- * <li> The ruler provides interested clients with mapping and
- * interaction information. This covers the mapping between
- * coordinates of the ruler's control and line numbers based
- * on the connected text viewer's document (<code>IVerticalRulerInfo</code>).
- * </ul>
- * Clients may implement this interface or use the default implementation provided
- * by <code>OverviewlRuler</code>.
- *
- * @see org.eclipse.jface.text.ITextViewer
- * @since 2.1
- */
-public interface IOverviewRuler extends IVerticalRuler {
-
- /**
- * Returns whether there is an annotation an the given y coordinate. This
- * method takes the compression factor of the overview ruler into account.
- *
- * @param y the y-coordinate
- * @return <code>true</code> if there is an annotation, <code>false</code> otherwise
- */
- boolean hasAnnotation(int y);
-
- /**
- * Returns the height of the visual presentation of an annotation in this
- * overview ruler. Assumes that all annotations are represented using the
- * same height.
- *
- * @return int the visual height of an annotation
- */
- int getAnnotationHeight();
-
- /**
- * Sets the color for the given annotation type in this overview ruler.
- *
- * @param annotationType the annotation type
- * @param color the color
- */
- void setAnnotationTypeColor(Object annotationType, Color color);
-
- /**
- * Sets the drawing layer for the given annotation type in this overview ruler.
- *
- * @param annotationType the annotation type
- * @param layer the drawing layer
- */
- void setAnnotationTypeLayer(Object annotationType, int layer);
-
- /**
- * Adds the given annotation type to this overview ruler. Starting with this
- * call, annotations of the given type are shown in the overview ruler.
- *
- * @param annotationType the annotation type
- */
- void addAnnotationType(Object annotationType);
-
- /**
- * Removes the given annotation type from this overview ruler. Annotations
- * of the given type are no longer shown in the overview ruler.
- *
- * @param annotationType the annotation type
- */
- void removeAnnotationType(Object annotationType);
-
- /**
- * Adds the given annotation type to the header of this ruler. Starting with
- * this call, the presence of annotations is tracked and the header is drawn
- * in the configured color.
- *
- * @param annotationType the annotation type to be tracked
- */
- void addHeaderAnnotationType(Object annotationType);
-
- /**
- * Removes the given annotation type from the header of this ruler. The
- * presence of annotations of the given type is no longer tracked and the
- * header is drawn in the default color, depending on the other configured
- * configured annotation types.
- *
- * @param annotationType the annotation type to be removed
- */
- void removeHeaderAnnotationType(Object annotationType);
-
- /**
- * Returns this rulers header control. This is the little area between the
- * top of the text widget and the top of this overview ruler.
- *
- * @return the header control of this overview ruler.
- */
- Control getHeaderControl();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISharedTextColors.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISharedTextColors.java
deleted file mode 100644
index 13ac9b1d6ea..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISharedTextColors.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.RGB;
-
-
-/**
- * Manages SWT color objects. Until the <code>dispose</code> method is called,
- * the same color object is returned for equal <code>RGB</code> values.
- * <p> This interface may be implemented by clients. </p>
- *
- * @since 2.1
- */
-public interface ISharedTextColors {
-
- /**
- * Returns the color object for the value represented by the given
- * <code>RGB</code> object.
- *
- * @param rgb the rgb color specification
- * @return the color object for the given rgb value
- */
- Color getColor(RGB rgb);
-
- /**
- * Tells this object to dispose all its managed colors.
- */
- void dispose();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java
deleted file mode 100644
index 16a1c30c720..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewer.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextOperationTarget;
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * In addition to the text viewer functionality a source viewer supports:
- * <ul>
- * <li> visual annotations based on an annotation model
- * <li> visual range indication
- * <li> management of text viewer add-ons
- * <li> explicit configuration
- * </ul>
- * It is assumed that range indication and visual annotations are shown
- * inside the same presentation area. There are no assumptions about
- * whether this area is different from the viewer's text widget.<p>
- * As the visibility of visual annotations can dynamically be changed,
- * it is assumed that the annotation presentation area can dynamically
- * be hidden if it is different from the text widget.<p>
- * Clients may implement this interface or use the default implementation provided
- * by <code>SourceViewer</code>.
- */
-public interface ISourceViewer extends ITextViewer {
-
- /**
- * Text operation code for requesting content assist to show completion
- * proposals for the current insert position.
- */
- static final int CONTENTASSIST_PROPOSALS= ITextOperationTarget.STRIP_PREFIX + 1;
-
- /**
- * Text operation code for requesting content assist to show
- * the content information for the current insert position.
- */
- static final int CONTENTASSIST_CONTEXT_INFORMATION= ITextOperationTarget.STRIP_PREFIX + 2;
-
- /**
- * Text operation code for formatting the selected text or complete document
- * of this viewer if the selection is empty.
- */
- static final int FORMAT= ITextOperationTarget.STRIP_PREFIX + 3;
-
- /**
- * Text operation code for requesting information at the current insertion position.
- * @since 2.0
- */
- static final int INFORMATION= ITextOperationTarget.STRIP_PREFIX + 4;
-
- /**
- * Configures the source viewer using the given configuration. Prior to 3.0 this
- * method can only be called once. Since 3.0 this method can be called again
- * after a call to {@link ISourceViewerExtension2#unconfigure()}.
- *
- * @param configuration the source viewer configuration to be used
- */
- void configure(SourceViewerConfiguration configuration);
-
- /**
- * Sets the annotation hover of this source viewer. The annotation hover
- * provides the information to be displayed in a hover popup window
- * if requested over the annotation presentation area. The annotation
- * hover is assumed to be line oriented.
- *
- * @param annotationHover the hover to be used, <code>null</code> is a valid argument
- */
- void setAnnotationHover(IAnnotationHover annotationHover);
-
- /**
- * Sets the given document as this viewer's text model and the
- * given annotation model as the model for this viewer's visual
- * annotations. The presentation is accordingly updated. An appropriate
- * <code>TextEvent</code> is issued. This text event does not carry
- * a related document event.
- *
- * @param document the viewer's new input document
- * @param annotationModel the model for the viewer's visual annotations
- *
- * @see ITextViewer#setDocument(IDocument)
- */
- void setDocument(IDocument document, IAnnotationModel annotationModel);
-
- /**
- * Sets the given document as this viewer's text model and the
- * given annotation model as the model for this viewer's visual
- * annotations. The presentation is accordingly updated whereby
- * only the specified region is exposed. An appropriate
- * <code>TextEvent</code> is issued. The text event does not carry a
- * related document event. This method is a convenience method for
- * <code>setDocument(document, annotationModel);setVisibleRegion(offset, length)</code>.
- *
- * @param document the new input document
- * @param annotationModel the model of the viewer's visual annotations
- * @param modelRangeOffset the offset of the model range
- * @param modelRangeLength the length of the model range
- *
- * @see ITextViewer#setDocument(IDocument, int, int)
- */
- void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength);
-
- /**
- * Returns this viewer's annotation model.
- *
- * @return this viewer's annotation model
- */
- IAnnotationModel getAnnotationModel();
-
- /**
- * Sets the annotation used by this viewer as range indicator. The
- * range covered by this annotation is referred to as range indication.
- *
- * @param rangeIndicator the annotation to be used as this viewer's range indicator
- */
- void setRangeIndicator(Annotation rangeIndicator);
-
- /**
- * Sets the viewers's range indication to the specified range. Its is indicated
- * whether the cursor should also be moved to the beginning of the specified range.
- *
- * @param offset the offset of the range
- * @param length the length of the range
- * @param moveCursor indicates whether the cursor should be moved to the given offset
- */
- void setRangeIndication(int offset, int length, boolean moveCursor);
-
- /**
- * Returns the viewer's range indication.
- *
- * @return the viewer's range indication.
- */
- IRegion getRangeIndication();
-
- /**
- * Removes the viewer's range indication. There is no visible range indication
- * after this method completed.
- */
- void removeRangeIndication();
-
- /**
- * Controls the visibility of annotations and in the case of separate
- * presentation areas of text and annotations, the visibility of the
- * annotation's presentation area.<p>
- * By default, annotations and their presentation area are visible.
- *
- * @param show indicates the visibility of annotations
- */
- void showAnnotations(boolean show);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension.java
deleted file mode 100644
index db4b8598d35..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-/**
- * Extension interface for <code>ISourceViewer</code>.
- * Extends the source viewer with the concept of an annotation overview.
- * The annotation overview differs from the annotation presentation in that it is
- * independent from the viewer's view port, i.e. the annotations of the
- * whole document are visible. There are no assumptions about
- * the area in which the annotation overview is shown.<p>
- * As the visibility of annotation overview can dynamically be changed,
- * it is assumed that the presentation area can dynamically
- * be hidden if it is different from the text widget.<p>
- * Clients may implement this interface or use the default implementation provided
- * by <code>SourceViewer</code>.
- *
- * @since 2.1
- */
-public interface ISourceViewerExtension {
-
- /**
- * Shows/hides an overview representation of the annotations of the whole document of this viewer.
- *
- * @param show <code>true</code> if annotation overview should be visible, <code>false</code> otherwise
- */
- void showAnnotationsOverview(boolean show);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java
deleted file mode 100644
index 434035bbcd9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ISourceViewerExtension2.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-/**
- * Extension interface for {@link ISourceViewer}.
- * Extends the source viewer with the functionality of explicit
- * unconfiguration.
- *
- * @since 3.0
- */
-public interface ISourceViewerExtension2 {
-
- /**
- * Unconfigures this source viewer. The source viewer can be configured again
- * after a call to this method. Unlike {@link ISourceViewer#configure(SourceViewerConfiguration)}
- * this method can be called more than once without interleaving calls to
- * {@link ISourceViewer#configure(SourceViewerConfiguration)}.
- */
- void unconfigure();
-
- /**
- * Returns the visual annotation model of this viewer.
- *
- * @return the visual annotation model of this viewer
- */
- IAnnotationModel getVisualAnnotationModel();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java
deleted file mode 100644
index afb7615ae37..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRuler.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-import org.eclipse.jface.text.ITextViewer;
-
-
-/**
- * This interface defines a visual component which may serve text viewers as an annotation presentation
- * area. Implementers of this interface have to define the presentation modus. This can either depend
- * on the connected viewer's view port or not. If the modus is view port dependent the ruler only shows
- * those annotations that are attached to document regions that are visible in the view port. If independent,
- * the presented annotations can also be attached to invisible document regions.
- *
- * This interfaces comprises three contracts:
- * <ul>
- * <li> The vertical ruler retrieves the annotations it presents from an annotation model.
- * <li> The ruler is a visual component which must be integrated in a hierarchy of SWT controls.
- * <li> The ruler provides interested clients with mapping and
- * interaction information. This covers the mapping between
- * coordinates of the ruler's control and line numbers based
- * on the connected text viewer's document (<code>IVerticalRulerInfo</code>).
- * </ul>
- * Clients may implement this interface or use the default implementation provided
- * by <code>CompositeRuler</code> and <code>VerticalRuler</code>.
- *
- * @see ITextViewer
- * @see IVerticalRulerInfo
- */
-public interface IVerticalRuler extends IVerticalRulerInfo {
-
- /**
- * Associates an annotation model with this ruler.
- * A value <code>null</code> is acceptable and clears the ruler.
- *
- * @param model the new annotation model, may be <code>null</code>
- */
- void setModel(IAnnotationModel model);
-
- /**
- * Returns the current annotation model of this ruler or <code>null</code>
- * if the ruler has no model.
- *
- * @return this ruler's annotation model or <code>null</code> if there is no model
- */
- IAnnotationModel getModel();
-
- /**
- * Forces the vertical ruler to synchronize itself with its
- * annotation model and its viewer's viewport.
- */
- void update();
-
- /**
- * Creates the ruler's SWT control.
- *
- * @param parent the parent control of the ruler's control
- * @param textViewer the text viewer to which this ruler belongs
- * @return the ruler's SWT control
- */
- Control createControl(Composite parent, ITextViewer textViewer);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java
deleted file mode 100644
index 1beb941445e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerColumn.java
+++ /dev/null
@@ -1,74 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-
-
-/**
- * A <code>IVerticalRulerColumn</code> is an element that can be added
- * to a composite vertical ruler. A composite vertical ruler is a vertical ruler
- * with a dynamically changing appearance and behavior depending on its
- * actual arrangement of ruler columns. A vertical ruler column supports a
- * subset of the contract of a vertical ruler.
- *
- * @see org.eclipse.jface.text.source.CompositeRuler
- * @since 2.0
- */
-public interface IVerticalRulerColumn {
-
- /**
- * Associates an annotation model with this ruler column.
- * A value <code>null</code> is acceptable and clears the ruler.
- *
- * @param model the new annotation model, may be <code>null</code>
- */
- void setModel(IAnnotationModel model);
-
- /**
- * Redraws this column.
- */
- void redraw();
-
- /**
- * Creates the column's SWT control.
- *
- * @param parentRuler the parent ruler of this column
- * @param parentControl the control of the parent ruler
- * @return the column's SWT control
- */
- Control createControl(CompositeRuler parentRuler, Composite parentControl);
-
- /**
- * Returns the column's SWT control.
- *
- * @return the column's SWT control
- */
- Control getControl();
-
- /**
- * Returns the width of this column's control.
- *
- * @return the width of this column's control
- */
- int getWidth();
-
- /**
- * Sets the font of this ruler column.
- *
- * @param font the new font of the ruler column
- */
- void setFont(Font font);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java
deleted file mode 100644
index 5eb8a1eeed0..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerExtension.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.graphics.Font;
-
-
-/**
- * Extension interface for <code>IVerticalRuler</code>. Allows to set the font of the
- * vertical ruler and to set the location of the last mouse button activity.
- *
- * @since 2.0
- */
-public interface IVerticalRulerExtension {
-
- /**
- * Sets the font of this vertical ruler.
- *
- * @param font the new font of the vertical ruler
- */
- void setFont(Font font);
-
- /**
- * Sets the location of the last mouse button activity. This method is used for
- * example by external mouse listeners.
- *
- * @param x the x-coordinate
- * @param y the y-coordinate
- */
- void setLocationOfLastMouseButtonActivity(int x, int y);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java
deleted file mode 100644
index 26120a1ca26..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfo.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.widgets.Control;
-
-
-/**
- * A vertical ruler is a visual component which may serve
- * text viewers as an annotation presentation
- * area. The vertical ruler info provides interested clients with the
- * mapping and interaction aspect of the vertical ruler. This
- * covers the mapping between coordinates of the ruler's
- * control and line numbers based on the connected text viewer's
- * document.
- *
- * @since 2.0
- */
-public interface IVerticalRulerInfo {
-
- /**
- * Returns the ruler's SWT control.
- *
- * @return the ruler's SWT control
- */
- Control getControl();
-
- /**
- * Returns the line number of the last mouse button activity.
- * Based on the input document of the connected text viewer.
- * The smallest possible line number is <code>0</code>.
- *
- * @return the line number of the last mouse button activity
- */
- int getLineOfLastMouseButtonActivity();
-
- /**
- * Translates a y-coordinate of the ruler's SWT control into
- * the according line number of the document of the connected text viewer.
- *
- * @param y_coordinate a y-coordinate of the ruler's SWT control
- * @return the line number of that coordinate or <code>-1</code> if that
- * coordinate does not correspond to a valid document line
- */
- int toDocumentLineNumber(int y_coordinate);
-
- /**
- * Returns the width of this ruler's control.
- *
- * @return the width of this ruler's control
- */
- int getWidth();
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfoExtension.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfoExtension.java
deleted file mode 100644
index d9369481460..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerInfoExtension.java
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-/**
- * Extends <code>IVerticalRulerInfo</code> with the ability to define a custom hover to be used
- * when hovering over the <code>IVerticalRuler</code> described by this info instance, and to
- * specify the <code>IAnnotationModel</code> used by it.
- * @since 3.0
- */
-public interface IVerticalRulerInfoExtension {
- /**
- * Returns the hover for this vertical ruler (column).
- * @return the hover for this column
- */
- IAnnotationHover getHover();
-
- /**
- * Returns the model currently used by the receiver.
- * @return the model of the receiver, or <code>null</code> if no model is installed.
- */
- IAnnotationModel getModel();
-
- /**
- * Registers a vertical ruler listener to be informed if an annotation gets
- * selected on the vertical ruler.
- *
- * @param listener the listener to be informed
- */
- void addVerticalRulerListener(IVerticalRulerListener listener);
-
- /**
- * Removes a previously registered listener. If <code>listener</code> is not registered
- * with the receiver, calling this method has no effect.
- *
- * @param listener the listener to be removed
- */
- void removeVerticalRulerListener(IVerticalRulerListener listener);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerListener.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerListener.java
deleted file mode 100644
index 1ee9aca0e9b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/IVerticalRulerListener.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.widgets.Menu;
-
-
-/**
- * Interface for listening to annotation related events happening on a vertical ruler.
- * <p>
- * This interface may be implemented by clients.
- * </p>
- *
- * @since 3.0
- */
-public interface IVerticalRulerListener {
-
- /**
- * Called when an annotation is selected in the UI.
- *
- * @param event the annotation event that occurred
- */
- void annotationSelected(VerticalRulerEvent event);
-
- /**
- * Called when a default selection occurs on an
- * annotation.
- *
- * @param event the annotation event that occurred
- */
- void annotationDefaultSelected(VerticalRulerEvent event);
-
- /**
- * Called when the context menu is opened on an annotation.
- *
- * @param event the annotation event that occurred
- * @param menu the menu that is about to be shown
- */
- void annotationContextMenuAboutToShow(VerticalRulerEvent event, Menu menu);
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java
deleted file mode 100644
index 473f646ec76..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/ImageUtilities.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-
-/**
- * Provides methods for drawing images onto a canvas.
- *
- * @since 3.0
- */
-public class ImageUtilities {
-
- /**
- * Draws an image aligned inside the given rectangle on the given canvas.
- *
- * @param image the image to be drawn
- * @param gc the drawing GC
- * @param canvas the canvas on which to draw
- * @param r the clipping rectangle
- * @param halign the horizontal alignment of the image to be drawn
- * @param valign the vertical alignment of the image to be drawn
- */
- public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int halign, int valign) {
- if (image != null) {
-
- Rectangle bounds= image.getBounds();
-
- int x= 0;
- switch(halign) {
- case SWT.LEFT:
- break;
- case SWT.CENTER:
- x= (r.width - bounds.width) / 2;
- break;
- case SWT.RIGHT:
- x= r.width - bounds.width;
- break;
- }
-
- int y= 0;
- switch (valign) {
- case SWT.TOP: {
- FontMetrics fontMetrics= gc.getFontMetrics();
- y= (fontMetrics.getHeight() - bounds.height)/2;
- break;
- }
- case SWT.CENTER:
- y= (r.height - bounds.height) / 2;
- break;
- case SWT.BOTTOM: {
- FontMetrics fontMetrics= gc.getFontMetrics();
- y= r.height - (fontMetrics.getHeight() + bounds.height)/2;
- break;
- }
- }
-
- gc.drawImage(image, r.x+x, r.y+y);
- }
- }
-
- /**
- * Draws an image aligned inside the given rectangle on the given canvas.
- *
- * @param image the image to be drawn
- * @param gc the drawing GC
- * @param canvas the canvas on which to draw
- * @param r the clipping rectangle
- * @param align the alignment of the image to be drawn
- */
- public static void drawImage(Image image, GC gc, Canvas canvas, Rectangle r, int align) {
- drawImage(image, gc, canvas, r, align, SWT.CENTER);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java
deleted file mode 100644
index 825a6ea0ee2..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/JFaceTextMessages.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * Accessor for the <code>JFaceTextMessages.properties</code> file in
- * package <code>org.eclipse.jface.text</code>.
- * @since 2.0
- */
-class JFaceTextMessages {
-
- /** The resource bundle name. */
- private static final String RESOURCE_BUNDLE= "org.eclipse.jface.text.JFaceTextMessages";//$NON-NLS-1$
-
- /** The resource bundle. */
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- /**
- * Prohibits the creation of accessor objects.
- */
- private JFaceTextMessages() {
- }
-
- /**
- * Returns the string found in the resource bundle under the given key or a place holder string.
- *
- * @param key the look up key
- * @return the value found under the given key
- */
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the argument
- *
- * @param key the string used to get the bundle value, must not be null
- * @param args arguments used when formatting the string
- * @return the formatted string
- * @since 3.0
- */
- public static String getFormattedString(String key, Object[] args) {
- String format= null;
- try {
- format= fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$
- }
- return MessageFormat.format(format, args);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
deleted file mode 100644
index 3cc171bf89f..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineChangeHover.java
+++ /dev/null
@@ -1,308 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.List;
-
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControlCreator;
-
-
-/**
- * A hover for line oriented diffs. It determines the text to show as hover for a certain line in the
- * document.
- *
- * @since 3.0
- */
-public class LineChangeHover implements IAnnotationHover, IAnnotationHoverExtension {
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int)
- */
- public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) {
- return null;
- }
-
- /**
- * Formats the source w/ syntax coloring etc. This implementation replaces tabs with spaces.
- * May be overridden by subclasses.
- *
- * @param content the hover content
- * @return <code>content</code> reformatted
- */
- protected String formatSource(String content) {
- if (content != null) {
- StringBuffer sb= new StringBuffer(content);
- final String tabReplacement= getTabReplacement();
- for (int pos= 0; pos < sb.length(); pos++) {
- if (sb.charAt(pos) == '\t')
- sb.replace(pos, pos + 1, tabReplacement);
- }
- return sb.toString();
- }
- return content;
- }
-
- /**
- * Returns a replacement for the tab character. The default implementation
- * returns a tabulator character, but subclasses may override to specify a
- * number of spaces.
- *
- * @return a whitespace String that will be substituted for the tabulator
- * character
- */
- protected String getTabReplacement() {
- return "\t"; //$NON-NLS-1$
- }
-
- /**
- * Computes the content of the hover for the document contained in <code>viewer</code> on
- * line <code>line</code>.
- *
- * @param viewer the connected viewer
- * @param first the first line in <code>viewer</code>'s document to consider
- * @param last the last line in <code>viewer</code>'s document to consider
- * @param maxLines the max number of lines
- * @return The hover content corresponding to the parameters
- * @see #getHoverInfo(ISourceViewer, int)
- * @see #getHoverInfo(ISourceViewer, ILineRange, int)
- */
- private String computeContent(ISourceViewer viewer, int first, int last, int maxLines) {
- ILineDiffer differ= getDiffer(viewer);
- if (differ == null)
- return null;
-
- final List lines= new LinkedList();
- for (int l= first; l <= last; l++) {
- ILineDiffInfo info= differ.getLineInfo(l);
- if (info != null)
- lines.add(info);
- }
-
- return decorateText(lines, maxLines);
- }
-
- /**
- * Takes a list of <code>ILineDiffInfo</code>s and computes a hover of at most <code>maxLines</code>.
- * Added lines are prefixed with a <code>'+'</code>, changed lines with <code>'>'</code> and
- * deleted lines with <code>'-'</code>.
- * <p>Deleted and added lines can even each other out, so that a number of deleted lines get
- * displayed where - in the current document - the added lines are.
- *
- * @param diffInfos a <code>List</code> of <code>ILineDiffInfo</code>
- * @param maxLines the maximum number of lines. Note that adding up all annotations might give
- * more than that due to deleted lines.
- * @return a <code>String</code> suitable for hover display
- */
- protected String decorateText(List diffInfos, int maxLines) {
- /* maxLines controls the size of the hover (not more than what fits into the display are of
- * the viewer).
- * added controls how many lines are added - added lines are
- */
- String text= new String();
- int added= 0;
- for (Iterator it= diffInfos.iterator(); it.hasNext();) {
- ILineDiffInfo info= (ILineDiffInfo)it.next();
- String[] original= info.getOriginalText();
- int type= info.getChangeType();
- int i= 0;
- if (type == ILineDiffInfo.ADDED)
- added++;
- else if (type == ILineDiffInfo.CHANGED) {
- text += "> " + (original.length > 0 ? original[i++] : ""); //$NON-NLS-1$ //$NON-NLS-2$
- maxLines--;
- } else if (type == ILineDiffInfo.UNCHANGED) {
- maxLines++;
- }
- if (maxLines == 0)
- return trimTrailing(text);
- for (; i < original.length; i++) {
- text += "- " + original[i]; //$NON-NLS-1$
- added--;
- if (--maxLines == 0)
- return trimTrailing(text);
- }
- }
- text= text.trim();
- if (text.length() == 0 && added-- > 0 && maxLines-- > 0)
- text += "+ "; //$NON-NLS-1$
- while (added-- > 0 && maxLines-- > 0)
- text += "\n+ "; //$NON-NLS-1$
- return text;
- }
-
- /**
- * Trims trailing spaces
- *
- * @param text a <code>String</code>
- * @return a copy of <code>text</code> with trailing spaces removed
- */
- private String trimTrailing(String text) {
- int pos= text.length() - 1;
- while (pos >= 0 && Character.isWhitespace(text.charAt(pos))) {
- pos--;
- }
- return text.substring(0, pos + 1);
- }
-
- /**
- * Extracts the line differ - if any - from the viewer's document's annotation model.
- * @param viewer the viewer
- * @return a line differ for the document displayed in viewer, or <code>null</code>.
- */
- private ILineDiffer getDiffer(ISourceViewer viewer) {
- IAnnotationModel model= viewer.getAnnotationModel();
-
- if (model == null)
- return null;
-
- if (model instanceof IAnnotationModelExtension) {
- IAnnotationModel diffModel= ((IAnnotationModelExtension)model).getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID);
- if (diffModel != null)
- model= diffModel;
- }
- if (model instanceof ILineDiffer)
- return (ILineDiffer)model;
- else
- return null;
- }
-
- /**
- * Computes the block of lines which form a contiguous block of changes covering <code>line</code>.
- *
- * @param viewer the source viewer showing
- * @param line the line which a hover is displayed for
- * @param min the first line in <code>viewer</code>'s document to consider
- * @param max the last line in <code>viewer</code>'s document to consider
- * @return the selection in the document displayed in <code>viewer</code> containing <code>line</code>
- * that is covered by the hover information returned by the receiver.
- */
- protected Point computeLineRange(ISourceViewer viewer, int line, int min, int max) {
- /* Algorithm:
- * All lines that have changes to themselves (added, changed) are taken that form a
- * contiguous block of lines that includes <code>line</code>.
- *
- * If <code>line</code> is itself unchanged, if there is a deleted line either above or
- * below, or both, the lines +/- 1 from <code>line</code> are included in the search as well,
- * without applying this last rule to them, though. (I.e., if <code>line</code> is unchanged,
- * but has a deleted line above, this one is taken in. If the line above has changes, the block
- * is extended from there. If the line has no changes itself, the search stops).
- *
- * The block never extends the visible line range of the viewer.
- */
-
- ILineDiffer differ= getDiffer(viewer);
- if (differ == null)
- return null;
-
- // backward search
-
- int l= line;
- ILineDiffInfo info= differ.getLineInfo(l);
- // search backwards until a line has no changes to itself
- while (l >= min && info != null && (info.getChangeType() == ILineDiffInfo.CHANGED || info.getChangeType() == ILineDiffInfo.ADDED)) {
- info= differ.getLineInfo(--l);
- }
-
- int first= Math.min(l + 1, line);
-
- // forward search
-
- l= line;
- info= differ.getLineInfo(l);
- // search forward until a line has no changes to itself
- while (l <= max && info != null && (info.getChangeType() == ILineDiffInfo.CHANGED || info.getChangeType() == ILineDiffInfo.ADDED)) {
- info= differ.getLineInfo(++l);
- }
-
- int last= Math.max(l - 1, line);
-
- return new Point(first, last);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverControlCreator()
- */
- public IInformationControlCreator getHoverControlCreator() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, org.eclipse.jface.text.source.ILineRange, int)
- */
- public Object getHoverInfo(ISourceViewer sourceViewer, ILineRange lineRange, int visibleLines) {
- int first= adaptFirstLine(sourceViewer, lineRange.getStartLine());
- int last= adaptLastLine(sourceViewer, lineRange.getStartLine() + lineRange.getNumberOfLines() - 1);
- String content= computeContent(sourceViewer, first, last, visibleLines);
- return formatSource(content);
- }
-
- /**
- * Adapts the start line to the implementation of <code>ILineDiffInfo</code>.
- *
- * @param startLine the line to adapt
- * @return <code>startLine - 1</code> if that line exists and is an
- * unchanged line followed by deletions, <code>startLine</code>
- * otherwise
- */
- private int adaptFirstLine(ISourceViewer viewer, int startLine) {
- ILineDiffer differ= getDiffer(viewer);
- if (differ != null && startLine > 0) {
- int l= startLine - 1;
- ILineDiffInfo info= differ.getLineInfo(l);
- if (info != null && info.getChangeType() == ILineDiffInfo.UNCHANGED && info.getRemovedLinesBelow() > 0)
- return l;
- }
- return startLine;
- }
-
- /**
- * Adapts the last line to the implementation of <code>ILineDiffInfo</code>.
- *
- * @param lastLine the line to adapt
- * @return <code>lastLine - 1</code> if that line exists and is an
- * unchanged line followed by deletions, <code>startLine</code>
- * otherwise
- */
- private int adaptLastLine(ISourceViewer viewer, int lastLine) {
- ILineDiffer differ= getDiffer(viewer);
- if (differ != null && lastLine > 0) {
- ILineDiffInfo info= differ.getLineInfo(lastLine);
- if (info != null && info.getChangeType() == ILineDiffInfo.UNCHANGED)
- return lastLine - 1;
- }
- return lastLine;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#getHoverLineRange(org.eclipse.jface.text.source.ISourceViewer, int)
- */
- public ILineRange getHoverLineRange(ISourceViewer viewer, int lineNumber) {
- IDocument document= viewer.getDocument();
- if (document != null) {
- Point range= computeLineRange(viewer, lineNumber, 0, Math.max(0, document.getNumberOfLines() - 1));
- if (range.x != -1 && range.y != -1)
- return new LineRange(range.x, range.y - range.x + 1);
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IAnnotationHoverExtension#canHandleMouseCursor()
- */
- public boolean canHandleMouseCursor() {
- return false;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java
deleted file mode 100644
index a5f42dd2b9c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberChangeRulerColumn.java
+++ /dev/null
@@ -1,434 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.Assert;
-
-/**
- * A vertical ruler column displaying line numbers and serving as a UI for quick diff.
- * Clients usually instantiate and configure object of this class.
- *
- * @since 3.0
- */
-public final class LineNumberChangeRulerColumn extends LineNumberRulerColumn implements IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn {
-
- /** Width of the triangle displayed for deleted lines. */
- private final static int fTriangleWidth= 7;
- /** The height of the triangle displayed for deleted lines. */
- private final static int fTriangleHeight= 3;
-
- /**
- * Internal listener class that will update the ruler when the underlying model changes.
- */
- class AnnotationListener implements IAnnotationModelListener {
- /*
- * @see org.eclipse.jface.text.source.IAnnotationModelListener#modelChanged(org.eclipse.jface.text.source.IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- postRedraw();
- }
- }
-
- /**
- * Returns a specification of a color that lies between the given
- * foreground and background color using the given scale factor.
- *
- * @param fg the foreground color
- * @param bg the background color
- * @param scale the scale factor
- * @return the interpolated color
- */
- private static RGB interpolate(RGB fg, RGB bg, double scale) {
- return new RGB(
- (int) ((1.0-scale) * fg.red + scale * bg.red),
- (int) ((1.0-scale) * fg.green + scale * bg.green),
- (int) ((1.0-scale) * fg.blue + scale * bg.blue)
- );
- }
-
- /**
- * Returns the grey value in which the given color would be drawn in grey-scale.
- *
- * @param rgb the color
- * @return the grey-scale value
- */
- private static double greyLevel(RGB rgb) {
- if (rgb.red == rgb.green && rgb.green == rgb.blue)
- return rgb.red;
- return (0.299 * rgb.red + 0.587 * rgb.green + 0.114 * rgb.blue + 0.5);
- }
-
- /**
- * Returns whether the given color is dark or light depending on the colors grey-scale level.
- *
- * @param rgb the color
- * @return <code>true</code> if the color is dark, <code>false</code> if it is light
- */
- private static boolean isDark(RGB rgb) {
- return greyLevel(rgb) > 128;
- }
-
- /** Color for changed lines. */
- private Color fAddedColor;
- /** Color for added lines. */
- private Color fChangedColor;
- /** Color for the deleted line indicator. */
- private Color fDeletedColor;
- /** The ruler's annotation model. */
- IAnnotationModel fAnnotationModel;
- /** The ruler's hover. */
- private IAnnotationHover fHover;
- /** The internal listener. */
- private AnnotationListener fAnnotationListener= new AnnotationListener();
- /** <code>true</code> if changes should be displayed using character indications instead of background colors. */
- private boolean fCharacterDisplay;
- /** The shared text colors. */
- private ISharedTextColors fSharedColors;
-
- /**
- * Creates a new instance.
- *
- * @param sharedColors the shared colors provider to use
- */
- public LineNumberChangeRulerColumn(ISharedTextColors sharedColors) {
- Assert.isNotNull(sharedColors);
- fSharedColors= sharedColors;
- }
-
- /*
- * @see org.eclipse.jface.text.source.LineNumberRulerColumn#handleDispose()
- */
- protected void handleDispose() {
- if (fAnnotationModel != null) {
- fAnnotationModel.removeAnnotationModelListener(fAnnotationListener);
- fAnnotationModel= null;
- }
- super.handleDispose();
- }
-
- /*
- * @see org.eclipse.jface.text.source.LineNumberRulerColumn#paintLine(int, int, int, org.eclipse.swt.graphics.GC, org.eclipse.swt.widgets.Display)
- */
- protected void paintLine(int line, int y, int lineheight, GC gc, Display display) {
- ILineDiffInfo info= getDiffInfo(line);
-
- if (info != null) {
- // width of the column
- int width= getWidth();
-
- // draw background color if special
- if (hasSpecialColor(info)) {
- gc.setBackground(getColor(info, display));
- gc.fillRectangle(0, y, width, lineheight);
- }
-
- /* Deletion Indicator
- * It consists of a line across the column and a triangle as shown for a deleted
- * line below the line 50:
- * ('x' means its colored)
- *
- * 1, 2, 3 show the points of the triangle painted.
- *
- * 0 width
- * | |
- * --------------------- - y
- * | --- -- |
- * | | | | 1_
- * | -- | | x| ^
- * | | | | xxx| | fTriangleHeight / 2
- * | --- -- xxxxx| |
- * xxxxxxxxxxxx0xxxxxxx2_ v _ y + lineheight
- * | |
- * <------>
- * fTriangleWidth
- */
- int delBefore= info.getRemovedLinesAbove();
- int delBelow= info.getRemovedLinesBelow();
- if (delBefore > 0 || delBelow > 0) {
- Color deletionColor= getDeletionColor(display);
- gc.setBackground(deletionColor);
- gc.setForeground(deletionColor);
-
- int[] triangle= new int[6];
- triangle[0]= width - fTriangleWidth;
- triangle[1]= y;
- triangle[2]= width;
- triangle[3]= y - fTriangleHeight;
- triangle[4]= width;
- triangle[5]= y + fTriangleHeight;
-
- if (delBefore > 0) {
- gc.drawLine(0, y, width, y);
- gc.fillPolygon(triangle);
- }
-
- if (delBelow > 0) {
- triangle[1] += lineheight;
- triangle[3] += lineheight;
- triangle[5] += lineheight;
-
- gc.drawLine(0, y + lineheight, width, y + lineheight);
- gc.fillPolygon(triangle);
- }
- gc.setForeground(getForeground());
- }
- }
- }
-
- /**
- * Returns whether the line background differs from the default.
- *
- * @param info the info being queried
- * @return <code>true</code> if <code>info</code> describes either a changed or an added line.
- */
- private boolean hasSpecialColor(ILineDiffInfo info) {
- return info.getChangeType() == ILineDiffInfo.ADDED || info.getChangeType() == ILineDiffInfo.CHANGED;
- }
-
- /**
- * Retrieves the <code>ILineDiffInfo</code> for <code>line</code> from the model.
- * There are optimizations for direct access and sequential access patterns.
- *
- * @param line the line we want the info for.
- * @return the <code>ILineDiffInfo</code> for <code>line</code>, or <code>null</code>.
- */
- private ILineDiffInfo getDiffInfo(int line) {
- if (fAnnotationModel == null)
- return null;
-
- // assume direct access
- if (fAnnotationModel instanceof ILineDiffer) {
- ILineDiffer differ= (ILineDiffer)fAnnotationModel;
- return differ.getLineInfo(line);
- }
-
- return null;
- }
-
- /**
- * Returns the color for deleted lines.
- *
- * @param display the display that the drawing occurs on
- * @return the color to be used for the deletion indicator
- */
- private Color getDeletionColor(Display display) {
- return fDeletedColor == null ? getBackground(display) : fDeletedColor;
- }
-
- /**
- * Returns the color for the given line diff info.
- *
- * @param info the <code>ILineDiffInfo</code> being queried
- * @param display the display that the drawing occurs on
- * @return the correct background color for the line type being described by <code>info</code>
- */
- private Color getColor(ILineDiffInfo info, Display display) {
- Assert.isTrue(info != null && info.getChangeType() != ILineDiffInfo.UNCHANGED);
- Color ret= null;
- switch (info.getChangeType()) {
- case ILineDiffInfo.CHANGED :
- ret= getShadedColor(fChangedColor, display);
- break;
- case ILineDiffInfo.ADDED :
- ret= getShadedColor(fAddedColor, display);
- break;
- }
- return ret == null ? getBackground(display) : ret;
- }
-
- /**
- * Returns the character to display in character display mode for the given <code>ILineDiffInfo</code>
- *
- * @param info the <code>ILineDiffInfo</code> being queried
- * @return the character indication for <code>info</code>
- */
- private String getDisplayCharacter(ILineDiffInfo info) {
- if (info == null)
- return ""; //$NON-NLS-1$
- switch (info.getChangeType()) {
- case ILineDiffInfo.CHANGED :
- return "~"; //$NON-NLS-1$
- case ILineDiffInfo.ADDED :
- return "+"; //$NON-NLS-1$
- }
- return " "; //$NON-NLS-1$
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- */
- public int getLineOfLastMouseButtonActivity() {
- return getParentRuler().getLineOfLastMouseButtonActivity();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int)
- */
- public int toDocumentLineNumber(int y_coordinate) {
- return getParentRuler().toDocumentLineNumber(y_coordinate);
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover()
- */
- public IAnnotationHover getHover() {
- return fHover;
- }
-
- /**
- * Sets the hover of this ruler column.
- * @param hover the hover that will produce hover information text for this ruler column
- */
- public void setHover(IAnnotationHover hover) {
- fHover= hover;
- }
-
- /*
- * @see IVerticalRulerColumn#setModel(IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- IAnnotationModel newModel;
- if (model instanceof IAnnotationModelExtension) {
- newModel= ((IAnnotationModelExtension)model).getAnnotationModel(QUICK_DIFF_MODEL_ID);
- } else {
- newModel= model;
- }
- if (fAnnotationModel != newModel) {
- if (fAnnotationModel != null) {
- fAnnotationModel.removeAnnotationModelListener(fAnnotationListener);
- }
- fAnnotationModel= newModel;
- if (fAnnotationModel != null) {
- fAnnotationModel.addAnnotationModelListener(fAnnotationListener);
- }
- updateNumberOfDigits();
- computeIndentations();
- layout(true);
- postRedraw();
- }
- }
-
- /**
- * Sets the background color for added lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param addedColor the new color to be used for the added lines background
- */
- public void setAddedColor(Color addedColor) {
- fAddedColor= addedColor;
- }
-
- /**
- * Sets the background color for changed lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param changedColor the new color to be used for the changed lines background
- */
- public void setChangedColor(Color changedColor) {
- fChangedColor= changedColor;
- }
-
- /**
- * Sets the background color for changed lines. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param color the new color to be used for the changed lines background
- * @param display the display
- * @return the shaded color
- */
- private Color getShadedColor(Color color, Display display) {
- if (color == null)
- return null;
-
- RGB baseRGB= color.getRGB();
- RGB background= getBackground(display).getRGB();
-
- boolean darkBase= isDark(baseRGB);
- boolean darkBackground= isDark(background);
- if (darkBase && darkBackground)
- background= new RGB(255, 255, 255);
- else if (!darkBase && !darkBackground)
- background= new RGB(0, 0, 0);
-
- return fSharedColors.getColor(interpolate(baseRGB, background, 0.6));
- }
-
- /**
- * Sets the color for the deleted lines indicator. The color has to be disposed of by the caller when
- * the receiver is no longer used.
- *
- * @param deletedColor the new color to be used for the deleted lines indicator.
- */
- public void setDeletedColor(Color deletedColor) {
- fDeletedColor= deletedColor;
- }
-
- /**
- * Sets the the display mode of the ruler. If character mode is set to <code>true</code>, diff
- * information will be displayed textually on the line number ruler.
- *
- * @param characterMode <code>true</code> if diff information is to be displayed textually.
- */
- public void setDisplayMode(boolean characterMode) {
- if (characterMode != fCharacterDisplay) {
- fCharacterDisplay= characterMode;
- updateNumberOfDigits();
- computeIndentations();
- layout(true);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getModel()
- */
- public IAnnotationModel getModel() {
- return fAnnotationModel;
- }
-
- /*
- * @see org.eclipse.jface.text.source.LineNumberRulerColumn#createDisplayString(int)
- */
- protected String createDisplayString(int line) {
- if (fCharacterDisplay && getModel() != null)
- return super.createDisplayString(line) + getDisplayCharacter(getDiffInfo(line));
- else
- return super.createDisplayString(line);
- }
-
- /*
- * @see org.eclipse.jface.text.source.LineNumberRulerColumn#computeNumberOfDigits()
- */
- protected int computeNumberOfDigits() {
- if (fCharacterDisplay && getModel() != null)
- return super.computeNumberOfDigits() + 1;
- else
- return super.computeNumberOfDigits();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- */
- public void addVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener)
- */
- public void removeVerticalRulerListener(IVerticalRulerListener listener) {
- throw new UnsupportedOperationException();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java
deleted file mode 100644
index 046f826ee53..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineNumberRulerColumn.java
+++ /dev/null
@@ -1,895 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.MouseTrackListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.FontMetrics;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.TextEvent;
-
-
-/**
- * A vertical ruler column displaying line numbers.
- * Clients usually instantiate and configure object of this class.
- *
- * @since 2.0
- */
-public class LineNumberRulerColumn implements IVerticalRulerColumn {
-
- /**
- * Internal listener class.
- */
- class InternalListener implements IViewportListener, ITextListener {
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int verticalPosition) {
- if (verticalPosition != fScrollPos)
- redraw();
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent event) {
-
- if (updateNumberOfDigits()) {
- computeIndentations();
- layout(event.getViewerRedrawState());
- return;
- }
-
- if (!event.getViewerRedrawState())
- return;
-
- if (fSensitiveToTextChanges || event.getDocumentEvent() == null)
- postRedraw();
-
- }
- }
-
- /**
- * Handles all the mouse interaction in this line number ruler column.
- */
- class MouseHandler implements MouseListener, MouseMoveListener, MouseTrackListener {
-
- /** The cached view port size */
- private int fCachedViewportSize;
- /** The area of the line at which line selection started */
- private IRegion fStartLine;
- /** The number of the line at which line selection started */
- private int fStartLineNumber;
- /** The auto scroll direction */
- private int fAutoScrollDirection;
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseUp(MouseEvent event) {
- // see bug 45700
- if (event.button == 1) {
- stopSelecting();
- stopAutoScroll();
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDown(MouseEvent event) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- // see bug 45700
- if (event.button == 1) {
- startSelecting();
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseDoubleClick(MouseEvent event) {
- fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y);
- stopSelecting();
- stopAutoScroll();
- }
-
- /*
- * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseMove(MouseEvent event) {
- if (!autoScroll(event)) {
- int newLine= fParentRuler.toDocumentLineNumber(event.y);
- expandSelection(newLine);
- }
- }
-
- /*
- * @see org.eclipse.swt.events.MouseTrackListener#mouseEnter(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseEnter(MouseEvent event) {
- }
-
- /*
- * @see org.eclipse.swt.events.MouseTrackListener#mouseExit(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseExit(MouseEvent event) {
- }
-
- /*
- * @see org.eclipse.swt.events.MouseTrackListener#mouseHover(org.eclipse.swt.events.MouseEvent)
- */
- public void mouseHover(MouseEvent event) {
- }
-
- /**
- * Called when line drag selection started. Adds mouse move and track
- * listeners to this column's control.
- */
- private void startSelecting() {
- try {
-
- // select line
- IDocument document= fCachedTextViewer.getDocument();
- fStartLineNumber= fParentRuler.getLineOfLastMouseButtonActivity();
- fStartLine= document.getLineInformation(fStartLineNumber);
- fCachedTextViewer.setSelectedRange(fStartLine.getOffset(), fStartLine.getLength());
- fCachedViewportSize= getVisibleLinesInViewport();
-
- // prepare for drag selection
- fCanvas.addMouseMoveListener(this);
- fCanvas.addMouseTrackListener(this);
-
- } catch (BadLocationException x) {
- }
- }
-
- /**
- * Called when line drag selection stopped. Removes all previously
- * installed listeners from this column's control.
- */
- private void stopSelecting() {
- // drag selection stopped
- fCanvas.removeMouseMoveListener(this);
- fCanvas.removeMouseTrackListener(this);
- }
-
- /**
- * Expands the line selection from the remembered start line to the
- * given line.
- *
- * @param lineNumber the line to which to expand the selection
- */
- private void expandSelection(int lineNumber) {
- try {
-
- IDocument document= fCachedTextViewer.getDocument();
- IRegion lineInfo= document.getLineInformation(lineNumber);
-
- int start= Math.min(fStartLine.getOffset(), lineInfo.getOffset());
- int end= Math.max(fStartLine.getOffset() + fStartLine.getLength(), lineInfo.getOffset() + lineInfo.getLength());
-
- if (lineNumber < fStartLineNumber)
- fCachedTextViewer.setSelectedRange(end, start - end);
- else
- fCachedTextViewer.setSelectedRange(start, end - start);
-
- } catch (BadLocationException x) {
- }
- }
-
- /**
- * Called when auto scrolling stopped. Clears the auto scroll direction.
- */
- private void stopAutoScroll() {
- fAutoScrollDirection= SWT.NULL;
- }
-
- /**
- * Called on drag selection.
- *
- * @param event the mouse event caught by the mouse move listener
- * @return <code>true</code> if scrolling happend, <code>false</code> otherwise
- */
- private boolean autoScroll(MouseEvent event) {
- Rectangle area= fCanvas.getClientArea();
-
- if (event.y > area.height) {
- autoScroll(SWT.DOWN);
- return true;
- }
-
- if (event.y < 0) {
- autoScroll(SWT.UP);
- return true;
- }
-
- stopAutoScroll();
- return false;
- }
-
- /**
- * Scrolls the viewer into the given direction.
- *
- * @param direction the scroll direction
- */
- private void autoScroll(int direction) {
-
- if (fAutoScrollDirection == direction)
- return;
-
- final int TIMER_INTERVAL= 5;
- final Display display = fCanvas.getDisplay();
- Runnable timer= null;
- switch (direction) {
- case SWT.UP:
- timer= new Runnable() {
- public void run() {
- if (fAutoScrollDirection == SWT.UP) {
- int top= getInclusiveTopIndex();
- if (top > 0) {
- fCachedTextViewer.setTopIndex(top -1);
- expandSelection(top -1);
- display.timerExec(TIMER_INTERVAL, this);
- }
- }
- }
- };
- break;
- case SWT.DOWN:
- timer = new Runnable() {
- public void run() {
- if (fAutoScrollDirection == SWT.DOWN) {
- int top= getInclusiveTopIndex();
- fCachedTextViewer.setTopIndex(top +1);
- expandSelection(top +1 + fCachedViewportSize);
- display.timerExec(TIMER_INTERVAL, this);
- }
- }
- };
- break;
- }
-
- if (timer != null) {
- fAutoScrollDirection= direction;
- display.timerExec(TIMER_INTERVAL, timer);
- }
- }
-
- /**
- * Returns the viewer's first visible line, even if only partially visible.
- *
- * @return the viewer's first visible line
- */
- private int getInclusiveTopIndex() {
- if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) {
- int top= fCachedTextViewer.getTopIndex();
- if ((fCachedTextWidget.getTopPixel() % fCachedTextWidget.getLineHeight()) != 0)
- -- top;
- return top;
- }
- return -1;
- }
- }
-
- /** This column's parent ruler */
- private CompositeRuler fParentRuler;
- /** Cached text viewer */
- private ITextViewer fCachedTextViewer;
- /** Cached text widget */
- private StyledText fCachedTextWidget;
- /** The columns canvas */
- private Canvas fCanvas;
- /** Cache for the actual scroll position in pixels */
- private int fScrollPos;
- /** The drawable for double buffering */
- private Image fBuffer;
- /** The internal listener */
- private InternalListener fInternalListener= new InternalListener();
- /** The font of this column */
- private Font fFont;
- /** The indentation cache */
- private int[] fIndentation;
- /** Indicates whether this column reacts on text change events */
- private boolean fSensitiveToTextChanges= false;
- /** The foreground color */
- private Color fForeground;
- /** The background color */
- private Color fBackground;
- /** Cached number of displayed digits */
- private int fCachedNumberOfDigits= -1;
- /** Flag indicating whether a relayout is required */
- private boolean fRelayoutRequired= false;
- /**
- * Redraw runnable lock
- * @since 3.0
- */
- private Object fRunnableLock= new Object();
- /**
- * Redraw runnable state
- * @since 3.0
- */
- private boolean fIsRunnablePosted= false;
- /**
- * Redraw runnable
- * @since 3.0
- */
- private Runnable fRunnable= new Runnable() {
- public void run() {
- synchronized (fRunnableLock) {
- fIsRunnablePosted= false;
- }
- redraw();
- }
- };
-
-
- /**
- * Constructs a new vertical ruler column.
- */
- public LineNumberRulerColumn() {
- }
-
- /**
- * Sets the foreground color of this column.
- *
- * @param foreground the foreground color
- */
- public void setForeground(Color foreground) {
- fForeground= foreground;
- }
-
- /**
- * Returns the foreground color being used to print the line numbers.
- *
- * @return the configured foreground color
- * @since 3.0
- */
- protected Color getForeground() {
- return fForeground;
- }
-
- /**
- * Sets the background color of this column.
- *
- * @param background the background color
- */
- public void setBackground(Color background) {
- fBackground= background;
- if (fCanvas != null && !fCanvas.isDisposed())
- fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
- }
-
- /**
- * Returns the System background color for list widgets.
- *
- * @param display the display
- * @return the System background color for list widgets
- */
- protected Color getBackground(Display display) {
- if (fBackground == null)
- return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND);
- return fBackground;
- }
-
- /*
- * @see IVerticalRulerColumn#getControl()
- */
- public Control getControl() {
- return fCanvas;
- }
-
- /*
- * @see IVerticalRuleColumnr#getWidth
- */
- public int getWidth() {
- return fIndentation[0];
- }
-
- /**
- * Computes the number of digits to be displayed. Returns
- * <code>true</code> if the number of digits changed compared
- * to the previous call of this method. If the method is called
- * for the first time, the return value is also <code>true</code>.
- *
- * @return whether the number of digits has been changed
- * @since 3.0
- */
- protected boolean updateNumberOfDigits() {
- if (fCachedTextViewer == null)
- return false;
-
- int digits= computeNumberOfDigits();
-
- if (fCachedNumberOfDigits != digits) {
- fCachedNumberOfDigits= digits;
- return true;
- }
-
- return false;
- }
-
- /**
- * Does the real computation of the number of digits. Subclasses may override this method if
- * they need extra space on the line number ruler.
- *
- * @return the number of digits to be displayed on the line number ruler.
- */
- protected int computeNumberOfDigits() {
- IDocument document= fCachedTextViewer.getDocument();
- int lines= document == null ? 0 : document.getNumberOfLines();
-
- int digits= 2;
- while (lines > Math.pow(10, digits) -1) {
- ++digits;
- }
- return digits;
- }
-
- /**
- * Layouts the enclosing viewer to adapt the layout to changes of the
- * size of the individual components.
- *
- * @param redraw <code>true</code> if this column can be redrawn
- */
- protected void layout(boolean redraw) {
- if (!redraw) {
- fRelayoutRequired= true;
- return;
- }
-
- fRelayoutRequired= false;
- if (fCachedTextViewer instanceof ITextViewerExtension) {
- ITextViewerExtension extension= (ITextViewerExtension) fCachedTextViewer;
- Control control= extension.getControl();
- if (control instanceof Composite && !control.isDisposed()) {
- Composite composite= (Composite) control;
- composite.layout(true);
- }
- }
- }
-
- /**
- * Computes the indentations for the given font and stores them in
- * <code>fIndentation</code>.
- */
- protected void computeIndentations() {
- if (fCanvas == null)
- return;
-
- GC gc= new GC(fCanvas);
- try {
-
- gc.setFont(fCanvas.getFont());
-
- fIndentation= new int[fCachedNumberOfDigits + 1];
-
- Float number= new Float(Math.pow(10, fCachedNumberOfDigits) - 1);
- Point p= gc.stringExtent(Integer.toString(number.intValue()));
- fIndentation[0]= p.x;
-
- for (int i= 1; i <= fCachedNumberOfDigits; i++) {
- number= new Float(Math.pow(10, i) - 1);
- p= gc.stringExtent(Integer.toString(number.intValue()));
- fIndentation[i]= fIndentation[0] - p.x;
- }
-
- } finally {
- gc.dispose();
- }
- }
-
- /*
- * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite)
- */
- public Control createControl(CompositeRuler parentRuler, Composite parentControl) {
-
- fParentRuler= parentRuler;
- fCachedTextViewer= parentRuler.getTextViewer();
- fCachedTextWidget= fCachedTextViewer.getTextWidget();
-
- fCanvas= new Canvas(parentControl, SWT.NONE);
- fCanvas.setBackground(getBackground(fCanvas.getDisplay()));
- fCanvas.setForeground(fForeground);
-
- fCanvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent event) {
- if (fCachedTextViewer != null)
- doubleBufferPaint(event.gc);
- }
- });
-
- fCanvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- fCachedTextViewer= null;
- fCachedTextWidget= null;
- }
- });
-
- fCanvas.addMouseListener(new MouseHandler());
-
- if (fCachedTextViewer != null) {
-
- fCachedTextViewer.addViewportListener(fInternalListener);
- fCachedTextViewer.addTextListener(fInternalListener);
-
- if (fFont == null) {
- if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed())
- fFont= fCachedTextWidget.getFont();
- }
- }
-
- if (fFont != null)
- fCanvas.setFont(fFont);
-
- updateNumberOfDigits();
- computeIndentations();
- return fCanvas;
- }
-
- /**
- * Disposes the column's resources.
- */
- protected void handleDispose() {
-
- if (fCachedTextViewer != null) {
- fCachedTextViewer.removeViewportListener(fInternalListener);
- fCachedTextViewer.removeTextListener(fInternalListener);
- }
-
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
-
- /**
- * Double buffer drawing.
- *
- * @param dest the gc to draw into
- */
- private void doubleBufferPaint(GC dest) {
-
- Point size= fCanvas.getSize();
-
- if (size.x <= 0 || size.y <= 0)
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- gc.setFont(fCanvas.getFont());
- if (fForeground != null)
- gc.setForeground(fForeground);
-
- try {
- gc.setBackground(getBackground(fCanvas.getDisplay()));
- gc.fillRectangle(0, 0, size.x, size.y);
-
- if (fCachedTextViewer instanceof ITextViewerExtension5)
- doPaint1(gc);
- else
- doPaint(gc);
-
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- /**
- * Returns the viewport height in lines.
- *
- * @return the viewport height in lines
- */
- protected int getVisibleLinesInViewport() {
- Rectangle clArea= fCachedTextWidget.getClientArea();
- if (!clArea.isEmpty())
- return clArea.height / fCachedTextWidget.getLineHeight();
- return -1;
- }
-
- /**
- * Draws the ruler column.
- *
- * @param gc the gc to draw into
- */
- private void doPaint(GC gc) {
-
- if (fCachedTextViewer == null)
- return;
-
- if (fCachedTextWidget == null)
- return;
-
-
- int firstLine= 0;
-
- int topLine= fCachedTextWidget.getTopIndex();
- fScrollPos= fCachedTextWidget.getTopPixel();
- int lineheight= fCachedTextWidget.getLineHeight();
- int partialLineHidden= fScrollPos % lineheight;
-
- if (partialLineHidden > 0 && topLine > 0) // widgetTopLine shows the first fully visible line
- -- topLine;
-
- int bottomLine= fCachedTextViewer.getBottomIndex() + 1;
-
- try {
-
- IRegion region= fCachedTextViewer.getVisibleRegion();
- IDocument doc= fCachedTextViewer.getDocument();
-
- if (doc == null)
- return;
-
- firstLine= doc.getLineOfOffset(region.getOffset());
- if (firstLine > topLine)
- topLine= firstLine;
-
- int lastLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- if (lastLine < bottomLine)
- bottomLine= lastLine;
-
- } catch (BadLocationException x) {
- return;
- }
-
- fSensitiveToTextChanges= bottomLine - topLine < getVisibleLinesInViewport();
-
- int baselineBias= getBaselineBias(gc);
-
- int topInset= fCachedTextViewer.getTopInset();
- int y= topInset - partialLineHidden;
- int canvasheight= fCanvas.getSize().y;
-
- for (int line= topLine; line <= bottomLine; line++, y+= lineheight) {
-
- if (y >= canvasheight)
- break;
-
- paintLine(line, y, lineheight, gc, fCachedTextWidget.getDisplay());
-
- String s= createDisplayString(line);
- int indentation= fIndentation[s.length()];
- gc.drawString(s, indentation, y + baselineBias, true);
- }
- }
-
- /**
- * Computes the string to be printed for <code>line</code>. The default implementation returns
- * <code>Integer.toString(line + 1)</code>.
- *
- * @param line the line number for which the line number string is generated
- * @return the string to be printed on the line number bar for <code>line</code>
- * @since 3.0
- */
- protected String createDisplayString(int line) {
- return Integer.toString(line + 1);
- }
-
- /**
- * Draws the ruler column. Uses <code>ITextViewerExtension5</code> for the
- * implementation. Will replace <code>doPinat(GC)</code>.
- *
- * @param gc the gc to draw into
- */
- private void doPaint1(GC gc) {
-
- if (fCachedTextViewer == null)
- return;
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fCachedTextViewer;
-
- int widgetTopLine= fCachedTextWidget.getTopIndex();
- fScrollPos= fCachedTextWidget.getTopPixel();
- int lineheight= fCachedTextWidget.getLineHeight();
- int partialLineHidden= fScrollPos % lineheight;
-
- if (partialLineHidden > 0 && widgetTopLine > 0) // widgetTopLine shows the first fully visible line
- -- widgetTopLine;
-
- int modelTopLine= extension.widgetLine2ModelLine(widgetTopLine);
- int modelBottomLine= fCachedTextViewer.getBottomIndex();
- if (modelBottomLine >= 0)
- ++ modelBottomLine;
-
- try {
-
- IRegion region= extension.getModelCoverage();
- IDocument doc= fCachedTextViewer.getDocument();
-
- if (doc == null)
- return;
-
- int coverageTopLine= doc.getLineOfOffset(region.getOffset());
- if (coverageTopLine > modelTopLine || modelTopLine == -1)
- modelTopLine= coverageTopLine;
-
- int coverageBottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- if (coverageBottomLine < modelBottomLine || modelBottomLine == -1)
- modelBottomLine= coverageBottomLine;
-
- } catch (BadLocationException x) {
- return;
- }
-
- fSensitiveToTextChanges= modelBottomLine - modelTopLine < getVisibleLinesInViewport();
-
- int baselineBias= getBaselineBias(gc);
-
- int topInset= fCachedTextViewer.getTopInset();
- int y= topInset - partialLineHidden;
- int canvasheight= fCanvas.getSize().y;
-
- for (int modelLine= modelTopLine; modelLine <= modelBottomLine; modelLine++) {
-
- if (y >= canvasheight)
- break;
-
- // don't draw hidden (e.g. folded) lines
- int widgetLine= extension.modelLine2WidgetLine(modelLine);
- if (widgetLine == -1)
- continue;
-
- paintLine(modelLine, y, lineheight, gc, fCachedTextWidget.getDisplay());
-
- String s= createDisplayString(modelLine);
- int indentation= fIndentation[s.length()];
- gc.drawString(s, indentation, y + baselineBias, true);
- y+= lineheight;
- }
- }
-
- /**
- * Returns the difference between the baseline of the widget and the
- * baseline as specified by the font for <code>gc</code>. When drawing
- * line numbers, the returned bias should be added to obtain text line up on
- * the correct base line of the text widget.
- *
- * @param gc the <code>GC</code> to get the font metrics from
- * @return the baseline bias to use when drawing text that is line up with
- * <code>fCachedTextWidget</code>
- */
- private int getBaselineBias(GC gc) {
- /*
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951
- * widget line height may be more than the font height used for the
- * linenumbers, since font styles (bold, italics...) can have larger
- * font metrics than the simple font used for the numbers.
- */
- int widgetBaseline= fCachedTextWidget.getBaseline();
- FontMetrics fm = gc.getFontMetrics();
- int fontBaseline = fm.getAscent() + fm.getLeading();
- Assert.isTrue(widgetBaseline >= fontBaseline);
- int baselineBias= widgetBaseline - fontBaseline;
- return baselineBias;
- }
-
- /**
- * Paints the line. After this method is called the line numbers are painted on top
- * of the result of this method.
- * <p>This default implementation does nothing.</p>
- *
- * @param line the line of the document which the ruler is painted for
- * @param y the y-coordinate of the box being painted for <code>line</code>, relative to <code>gc</code>
- * @param lineheight the height of one line (and therefore of the box being painted)
- * @param gc the drawing context the client may choose to draw on.
- * @param display the display the drawing occurs on
- * @since 3.0
- */
- protected void paintLine(int line, int y, int lineheight, GC gc, Display display) {
- }
-
- /**
- * Triggers a redraw in the display thread.
- *
- * @since 3.0
- */
- protected final void postRedraw() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- Display d= fCanvas.getDisplay();
- if (d != null) {
- synchronized (fRunnableLock) {
- if (fIsRunnablePosted)
- return;
- fIsRunnablePosted= true;
- }
- d.asyncExec(fRunnable);
- }
- }
- }
-
- /*
- * @see IVerticalRulerColumn#redraw()
- */
- public void redraw() {
-
- if (fRelayoutRequired) {
- layout(true);
- return;
- }
-
- if (fCanvas != null && !fCanvas.isDisposed()) {
- GC gc= new GC(fCanvas);
- doubleBufferPaint(gc);
- gc.dispose();
- }
- }
-
- /*
- * @see IVerticalRulerColumn#setModel(IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- }
-
- /*
- * @see IVerticalRulerColumn#setFont(Font)
- */
- public void setFont(Font font) {
- fFont= font;
- if (fCanvas != null && !fCanvas.isDisposed()) {
- fCanvas.setFont(fFont);
- updateNumberOfDigits();
- computeIndentations();
- }
- }
-
- /**
- * Returns the parent (composite) ruler of this ruler column.
- *
- * @return the parent ruler
- * @since 3.0
- */
- protected CompositeRuler getParentRuler() {
- return fParentRuler;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineRange.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineRange.java
deleted file mode 100644
index ca6f447faae..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/LineRange.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-/**
- * @since 3.0
- */
-public final class LineRange implements ILineRange {
-
- private int fStartLine;
- private int fNumberOfLines;
-
- public LineRange(int startLine, int numberOfLines) {
- fStartLine= startLine;
- fNumberOfLines= numberOfLines;
- }
-
- /*
- * @see org.eclipse.jface.text.source.ILineRange#getStartLine()
- */
- public int getStartLine() {
- return fStartLine;
- }
-
- /*
- * @see org.eclipse.jface.text.source.ILineRange#getNumberOfLines()
- */
- public int getNumberOfLines() {
- return fNumberOfLines;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
deleted file mode 100644
index e0329051d1b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/MatchingCharacterPainter.java
+++ /dev/null
@@ -1,262 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IPaintPositionManager;
-import org.eclipse.jface.text.IPainter;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-
-/**
- * Highlights the peer character matching the character near the caret position. This
- * painter can be configured with an <code>ICharacterPairMatcher</code>.
- * Clients instantiate and configure object of this class.
- *
- * @since 2.1
- */
-public final class MatchingCharacterPainter implements IPainter, PaintListener {
-
- /** Indicates whether this painter is active */
- private boolean fIsActive= false;
- /** The source viewer this painter is associated with */
- private ISourceViewer fSourceViewer;
- /** The viewer's widget */
- private StyledText fTextWidget;
- /** The color in which to highlight the peer character */
- private Color fColor;
- /** The paint position manager */
- private IPaintPositionManager fPaintPositionManager;
- /** The startegy for finding matching characters */
- private ICharacterPairMatcher fMatcher;
- /** The position tracking the matching characters */
- private Position fPairPosition= new Position(0, 0);
- /** The anchor indicating whether the character is left or right of the caret */
- private int fAnchor;
-
-
- /**
- * Creates a new MatchingCharacterPainter for the given source viewer using
- * the given character pair matcher. The character matcher is not adopted by
- * this painter. Thus, it is not disposed. However, this painter requires
- * exlucsive access to the given pair matcher.
- *
- * @param sourceViewer
- * @param matcher
- */
- public MatchingCharacterPainter(ISourceViewer sourceViewer, ICharacterPairMatcher matcher) {
- fSourceViewer= sourceViewer;
- fMatcher= matcher;
- fTextWidget= sourceViewer.getTextWidget();
- }
-
- /**
- * Sets the color in which to highlight the match character.
- *
- * @param color the color
- */
- public void setColor(Color color) {
- fColor= color;
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#dispose()
- */
- public void dispose() {
- if (fMatcher != null) {
- fMatcher.clear();
- fMatcher= null;
- }
-
- fColor= null;
- fTextWidget= null;
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#deactivate(boolean)
- */
- public void deactivate(boolean redraw) {
- if (fIsActive) {
- fIsActive= false;
- fTextWidget.removePaintListener(this);
- if (fPaintPositionManager != null)
- fPaintPositionManager.unmanagePosition(fPairPosition);
- if (redraw)
- handleDrawRequest(null);
- }
- }
-
- /*
- * @see org.eclipse.swt.events.PaintListener#paintControl(org.eclipse.swt.events.PaintEvent)
- */
- public void paintControl(PaintEvent event) {
- if (fTextWidget != null)
- handleDrawRequest(event.gc);
- }
-
- /**
- * Handles a redraw request.
- *
- * @param gc the gc to draw into.
- */
- private void handleDrawRequest(GC gc) {
-
- if (fPairPosition.isDeleted)
- return;
-
- int offset= fPairPosition.getOffset();
- int length= fPairPosition.getLength();
- if (length < 1)
- return;
-
- if (fSourceViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fSourceViewer;
- IRegion widgetRange= extension.modelRange2WidgetRange(new Region(offset, length));
- if (widgetRange == null)
- return;
-
- try {
- // don't draw if the pair position is really hidden and widgetRange just
- // marks the coverage around it.
- IDocument doc= fSourceViewer.getDocument();
- int startLine= doc.getLineOfOffset(offset);
- int endLine= doc.getLineOfOffset(offset + length);
- if (extension.modelLine2WidgetLine(startLine) == -1 || extension.modelLine2WidgetLine(endLine) == -1)
- return;
- } catch (BadLocationException e) {
- return;
- }
-
- offset= widgetRange.getOffset();
- length= widgetRange.getLength();
-
- } else {
- IRegion region= fSourceViewer.getVisibleRegion();
- if (region.getOffset() > offset || region.getOffset() + region.getLength() < offset + length)
- return;
- offset -= region.getOffset();
- }
-
- if (ICharacterPairMatcher.RIGHT == fAnchor)
- draw(gc, offset, 1);
- else
- draw(gc, offset + length -1, 1);
- }
-
- /**
- * Highlights the given widget region.
- *
- * @param gc the gc to draw into
- * @param offset the offset of the widget region
- * @param length the length of the widget region
- */
- private void draw(GC gc, int offset, int length) {
- if (gc != null) {
- Point left= fTextWidget.getLocationAtOffset(offset);
- Point right= fTextWidget.getLocationAtOffset(offset + length);
- gc.setForeground(fColor);
-
- // draw box around line segment
- gc.drawRectangle(left.x, left.y, right.x - left.x - 1, fTextWidget.getLineHeight() - 1);
-
- // draw box around character area
-// int widgetBaseline= fTextWidget.getBaseline();
-// FontMetrics fm= gc.getFontMetrics();
-// int fontBaseline= fm.getAscent() + fm.getLeading();
-// int fontBias= widgetBaseline - fontBaseline;
-
-// gc.drawRectangle(left.x, left.y + fontBias, right.x - left.x - 1, fm.getHeight() - 1);
-
- } else {
- fTextWidget.redrawRange(offset, length, true);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#paint(int)
- */
- public void paint(int reason) {
-
- IDocument document= fSourceViewer.getDocument();
- if (document == null) {
- deactivate(false);
- return;
- }
-
- Point selection= fSourceViewer.getSelectedRange();
- if (selection.y > 0) {
- deactivate(true);
- return;
- }
-
- IRegion pair= fMatcher.match(document, selection.x);
- if (pair == null) {
- deactivate(true);
- return;
- }
-
- if (fIsActive) {
-
- if (IPainter.CONFIGURATION == reason) {
-
- // redraw current highlighting
- handleDrawRequest(null);
-
- } else if (pair.getOffset() != fPairPosition.getOffset() ||
- pair.getLength() != fPairPosition.getLength() ||
- fMatcher.getAnchor() != fAnchor) {
-
- // otherwise only do something if position is different
-
- // remove old highlighting
- handleDrawRequest(null);
- // update position
- fPairPosition.isDeleted= false;
- fPairPosition.offset= pair.getOffset();
- fPairPosition.length= pair.getLength();
- fAnchor= fMatcher.getAnchor();
- // apply new highlighting
- handleDrawRequest(null);
-
- }
- } else {
-
- fIsActive= true;
-
- fPairPosition.isDeleted= false;
- fPairPosition.offset= pair.getOffset();
- fPairPosition.length= pair.getLength();
- fAnchor= fMatcher.getAnchor();
-
- fTextWidget.addPaintListener(this);
- fPaintPositionManager.managePosition(fPairPosition);
- handleDrawRequest(null);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.IPainter#setPositionManager(org.eclipse.jface.text.IPaintPositionManager)
- */
- public void setPositionManager(IPaintPositionManager manager) {
- fPaintPositionManager= manager;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
deleted file mode 100644
index aa5e95e2b3b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRuler.java
+++ /dev/null
@@ -1,1229 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.custom.ViewForm;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.MouseAdapter;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseMoveListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.graphics.Cursor;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextEvent;
-import org.eclipse.jface.text.source.projection.AnnotationBag;
-
-
-
-/**
- * Ruler presented next to a source viewer showing all annotations of the
- * viewer's annotation model in a compact format. The ruler has the same height
- * as the source viewer.<p>
- * Clients usually instantiate and configure objects of this class.
- *
- * @since 2.1
- */
-public class OverviewRuler implements IOverviewRuler {
-
- /**
- * Internal listener class.
- */
- class InternalListener implements ITextListener, IAnnotationModelListener {
-
- /*
- * @see ITextListener#textChanged
- */
- public void textChanged(TextEvent e) {
- if (fTextViewer != null && e.getDocumentEvent() == null && e.getViewerRedrawState()) {
- // handle only changes of visible document
- redraw();
- }
- }
-
- /*
- * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- update();
- }
- }
-
- /**
- * Enumerates the annotations of a specified type and characteristics
- * of the associated annotation model.
- */
- class FilterIterator implements Iterator {
-
- final static int TEMPORARY= 1 << 1;
- final static int PERSISTENT= 1 << 2;
- final static int IGNORE_BAGS= 1 << 3;
-
- private Iterator fIterator;
- private Object fType;
- private Annotation fNext;
- private int fStyle;
-
-
- public FilterIterator(Object annotationType, int style) {
- fType= annotationType;
- fStyle= style;
- if (fModel != null) {
- fIterator= fModel.getAnnotationIterator();
- skip();
- }
- }
-
- public FilterIterator(Object annotationType, int style, Iterator iterator) {
- fType= annotationType;
- fStyle= style;
- fIterator= iterator;
- skip();
- }
-
- private void skip() {
-
- boolean temp= (fStyle & TEMPORARY) != 0;
- boolean pers= (fStyle & PERSISTENT) != 0;
- boolean ignr= (fStyle & IGNORE_BAGS) != 0;
-
- while (fIterator.hasNext()) {
- Annotation next= (Annotation) fIterator.next();
-
- if (next.isMarkedDeleted())
- continue;
-
- if (ignr && (next instanceof AnnotationBag))
- continue;
-
- fNext= next;
- Object annotationType= next.getType();
- if (fType == null || isSubtype(annotationType)) {
- if (temp && pers) return;
- if (pers && next.isPersistent()) return;
- if (temp && !next.isPersistent()) return;
- }
- }
- fNext= null;
- }
-
- private boolean isSubtype(Object annotationType) {
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- return extension.isSubtype(annotationType, fType);
- }
- return fType.equals(annotationType);
- }
-
- /*
- * @see Iterator#hasNext()
- */
- public boolean hasNext() {
- return fNext != null;
- }
- /*
- * @see Iterator#next()
- */
- public Object next() {
- try {
- return fNext;
- } finally {
- if (fIterator != null)
- skip();
- }
- }
- /*
- * @see Iterator#remove()
- */
- public void remove() {
- throw new UnsupportedOperationException();
- }
- }
-
- /**
- * The painter of the overview ruler's header.
- */
- class HeaderPainter implements PaintListener {
-
- private Color fIndicatorColor;
- private Color fSeparatorColor;
-
- public HeaderPainter() {
- fSeparatorColor= fSharedTextColors.getColor(ViewForm.borderInsideRGB);
- }
-
- public void setColor(Color color) {
- fIndicatorColor= color;
- }
-
- private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topLeft, Color bottomRight) {
- gc.setForeground(topLeft == null ? fSeparatorColor : topLeft);
- gc.drawLine(x, y, x + w -1, y);
- gc.drawLine(x, y, x, y + h -1);
-
- gc.setForeground(bottomRight == null ? fSeparatorColor : bottomRight);
- gc.drawLine(x + w, y, x + w, y + h);
- gc.drawLine(x, y + h, x + w, y + h);
- }
-
- public void paintControl(PaintEvent e) {
-
- Point s= fHeader.getSize();
-
- if (fIndicatorColor != null) {
- e.gc.setBackground(fIndicatorColor);
- Rectangle r= new Rectangle(INSET, (s.y - (2*ANNOTATION_HEIGHT)) / 2, s.x - (2*INSET), 2*ANNOTATION_HEIGHT);
- e.gc.fillRectangle(r);
- Display d= fHeader.getDisplay();
- if (d != null)
-// drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW));
- drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, null, null);
- }
-
- e.gc.setForeground(fSeparatorColor);
- e.gc.setLineWidth(1);
- e.gc.drawLine(0, s.y -1, s.x -1, s.y -1);
- }
- }
-
- private static final int INSET= 2;
- private static final int ANNOTATION_HEIGHT= 4;
- private static boolean ANNOTATION_HEIGHT_SCALABLE= true;
-
-
- /** The model of the overview ruler */
- private IAnnotationModel fModel;
- /** The view to which this ruler is connected */
- private ITextViewer fTextViewer;
- /** The ruler's canvas */
- private Canvas fCanvas;
- /** The ruler's header */
- private Canvas fHeader;
- /** The drawable for double buffering */
- private Image fBuffer;
- /** The internal listener */
- private InternalListener fInternalListener= new InternalListener();
- /** The width of this vertical ruler */
- private int fWidth;
- /** The hit detection cursor */
- private Cursor fHitDetectionCursor;
- /** The last cursor */
- private Cursor fLastCursor;
- /** The line of the last mouse button activity */
- private int fLastMouseButtonActivityLine= -1;
- /** The actual annotation height */
- private int fAnnotationHeight= -1;
- /** The annotation access */
- private IAnnotationAccess fAnnotationAccess;
- /** The header painter */
- private HeaderPainter fHeaderPainter;
- /**
- * The list of annotation types to be shown in this ruler.
- * @since 3.0
- */
- private Set fConfiguredAnnotationTypes= new HashSet();
- /**
- * The list of annotation types to be shown in the header of this ruler.
- * @since 3.0
- */
- private Set fConfiguredHeaderAnnotationTypes= new HashSet();
- /** The mapping between annotation types and colors */
- private Map fAnnotationTypes2Colors= new HashMap();
- /** The color manager */
- private ISharedTextColors fSharedTextColors;
- /**
- * All available annotation types sorted by layer.
- *
- * @since 3.0
- */
- private List fAnnotationsSortedByLayer= new ArrayList();
- /**
- * All available layers sorted by layer.
- * This list may contain duplicates.
- * @since 3.0
- */
- private List fLayersSortedByLayer= new ArrayList();
- /**
- * Map of allowed annotation types.
- * An allowed annotation type maps to <code>true</code>, a disallowed
- * to <code>false</code>.
- * @since 3.0
- */
- private Map fAllowedAnnotationTypes= new HashMap();
- /**
- * Map of allowed header annotation types.
- * An allowed annotation type maps to <code>true</code>, a disallowed
- * to <code>false</code>.
- * @since 3.0
- */
- private Map fAllowedHeaderAnnotationTypes= new HashMap();
- /**
- * The cached annotations.
- * @since 3.0
- */
- private List fCachedAnnotations= new ArrayList();
-
-
- /**
- * Constructs a overview ruler of the given width using the given annotation access and the given
- * color manager.
- *
- * @param annotationAccess the annotation access
- * @param width the width of the vertical ruler
- * @param sharedColors the color manager
- */
- public OverviewRuler(IAnnotationAccess annotationAccess, int width, ISharedTextColors sharedColors) {
- fAnnotationAccess= annotationAccess;
- fWidth= width;
- fSharedTextColors= sharedColors;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getControl()
- */
- public Control getControl() {
- return fCanvas;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getWidth()
- */
- public int getWidth() {
- return fWidth;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRuler#setModel(org.eclipse.jface.text.source.IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- if (model != fModel || model != null) {
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- fModel= model;
-
- if (fModel != null)
- fModel.addAnnotationModelListener(fInternalListener);
-
- update();
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRuler#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.ITextViewer)
- */
- public Control createControl(Composite parent, ITextViewer textViewer) {
-
- fTextViewer= textViewer;
-
- fHitDetectionCursor= new Cursor(parent.getDisplay(), SWT.CURSOR_HAND);
-
- fHeader= new Canvas(parent, SWT.NONE);
-
- fCanvas= new Canvas(parent, SWT.NO_BACKGROUND);
-
- fCanvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent event) {
- if (fTextViewer != null && fModel != null)
- doubleBufferPaint(event.gc);
- }
- });
-
- fCanvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent event) {
- handleDispose();
- fTextViewer= null;
- }
- });
-
- fCanvas.addMouseListener(new MouseAdapter() {
- public void mouseDown(MouseEvent event) {
- handleMouseDown(event);
- }
- });
-
- fCanvas.addMouseMoveListener(new MouseMoveListener() {
- public void mouseMove(MouseEvent event) {
- handleMouseMove(event);
- }
- });
-
- if (fTextViewer != null)
- fTextViewer.addTextListener(fInternalListener);
-
- return fCanvas;
- }
-
- /**
- * Disposes the ruler's resources.
- */
- private void handleDispose() {
-
- if (fTextViewer != null) {
- fTextViewer.removeTextListener(fInternalListener);
- fTextViewer= null;
- }
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
-
- if (fHitDetectionCursor != null) {
- fHitDetectionCursor.dispose();
- fHitDetectionCursor= null;
- }
-
- fConfiguredAnnotationTypes.clear();
- fAllowedAnnotationTypes.clear();
- fConfiguredHeaderAnnotationTypes.clear();
- fAllowedHeaderAnnotationTypes.clear();
- fAnnotationTypes2Colors.clear();
- fAnnotationsSortedByLayer.clear();
- fLayersSortedByLayer.clear();
- }
-
- /**
- * Double buffer drawing.
- *
- * @param dest the GC to draw into
- */
- private void doubleBufferPaint(GC dest) {
-
- Point size= fCanvas.getSize();
-
- if (size.x <= 0 || size.y <= 0)
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- try {
- gc.setBackground(fCanvas.getBackground());
- gc.fillRectangle(0, 0, size.x, size.y);
-
- if (fTextViewer instanceof ITextViewerExtension5)
- doPaint1(gc);
- else
- doPaint(gc);
-
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- /**
- * Draws this overview ruler.
- *
- * @param gc the GC to draw into
- */
- private void doPaint(GC gc) {
-
- Rectangle r= new Rectangle(0, 0, 0, 0);
- int yy, hh= ANNOTATION_HEIGHT;
-
- IDocument document= fTextViewer.getDocument();
- IRegion visible= fTextViewer.getVisibleRegion();
-
- StyledText textWidget= fTextViewer.getTextWidget();
- int maxLines= textWidget.getLineCount();
-
- Point size= fCanvas.getSize();
- int writable= maxLines * textWidget.getLineHeight();
- if (size.y > writable)
- size.y= Math.max(writable - fHeader.getSize().y, 0);
-
- for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) {
- Object annotationType= iterator.next();
-
- if (skip(annotationType))
- continue;
-
- int[] style= new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY };
- for (int t=0; t < style.length; t++) {
-
- Iterator e= new FilterIterator(annotationType, style[t]);
- Color fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY);
- Color stroke= getStrokeColor(annotationType, style[t] == FilterIterator.TEMPORARY);
-
- for (int i= 0; e.hasNext(); i++) {
-
- Annotation a= (Annotation) e.next();
- Position p= fModel.getPosition(a);
-
- if (p == null || !p.overlapsWith(visible.getOffset(), visible.getLength()))
- continue;
-
- int annotationOffset= Math.max(p.getOffset(), visible.getOffset());
- int annotationEnd= Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength());
- int annotationLength= annotationEnd - annotationOffset;
-
- try {
- if (ANNOTATION_HEIGHT_SCALABLE) {
- int numbersOfLines= document.getNumberOfLines(annotationOffset, annotationLength);
- // don't count empty trailing lines
- IRegion lastLine= document.getLineInformationOfOffset(annotationOffset + annotationLength);
- if (lastLine.getOffset() == annotationOffset + annotationLength) {
- numbersOfLines -= 2;
- hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT;
- if (hh < ANNOTATION_HEIGHT)
- hh= ANNOTATION_HEIGHT;
- } else
- hh= ANNOTATION_HEIGHT;
- }
- fAnnotationHeight= hh;
-
- int startLine= textWidget.getLineAtOffset(annotationOffset - visible.getOffset());
- yy= Math.min((startLine * size.y) / maxLines, size.y - hh);
-
- if (fill != null) {
- gc.setBackground(fill);
- gc.fillRectangle(INSET, yy, size.x-(2*INSET), hh);
- }
-
- if (stroke != null) {
- gc.setForeground(stroke);
- r.x= INSET;
- r.y= yy;
- r.width= size.x - (2 * INSET) - 1;
- r.height= hh;
- gc.setLineWidth(1);
- gc.drawRectangle(r);
- }
- } catch (BadLocationException x) {
- }
- }
- }
- }
- }
-
- /**
- * Draws this overview ruler. Uses <code>ITextViewerExtension5</code> for
- * its implementation. Will replace <code>doPaint(GC)</code>.
- *
- * @param gc the GC to draw into
- */
- private void doPaint1(GC gc) {
-
- Rectangle r= new Rectangle(0, 0, 0, 0);
- int yy, hh= ANNOTATION_HEIGHT;
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- IDocument document= fTextViewer.getDocument();
- StyledText textWidget= fTextViewer.getTextWidget();
-
- int maxLines= textWidget.getLineCount();
- Point size= fCanvas.getSize();
- int writable= maxLines * textWidget.getLineHeight();
- if (size.y > writable)
- size.y= Math.max(writable - fHeader.getSize().y, 0);
-
- fCachedAnnotations.clear();
- Iterator iter= fModel.getAnnotationIterator();
- while (iter.hasNext()) {
- Annotation annotation= (Annotation) iter.next();
-
- if (annotation.isMarkedDeleted())
- continue;
-
- if (skip(annotation.getType()))
- continue;
-
- fCachedAnnotations.add(annotation);
- }
-
- for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) {
- Object annotationType= iterator.next();
-
- if (skip(annotationType))
- continue;
-
- int[] style= new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY };
- for (int t=0; t < style.length; t++) {
-
- Iterator e= new FilterIterator(annotationType, style[t], fCachedAnnotations.iterator());
- Color fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY);
- Color stroke= getStrokeColor(annotationType, style[t] == FilterIterator.TEMPORARY);
-
- for (int i= 0; e.hasNext(); i++) {
-
- Annotation a= (Annotation) e.next();
- Position p= fModel.getPosition(a);
-
- if (p == null)
- continue;
-
- IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength()));
- if (widgetRegion == null)
- continue;
-
- try {
- if (ANNOTATION_HEIGHT_SCALABLE) {
- int numbersOfLines= document.getNumberOfLines(p.getOffset(), p.getLength());
- // don't count empty trailing lines
- IRegion lastLine= document.getLineInformationOfOffset(p.getOffset() + p.getLength());
- if (lastLine.getOffset() == p.getOffset() + p.getLength()) {
- numbersOfLines -= 2;
- hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT;
- if (hh < ANNOTATION_HEIGHT)
- hh= ANNOTATION_HEIGHT;
- } else
- hh= ANNOTATION_HEIGHT;
- }
- fAnnotationHeight= hh;
-
- int startLine= textWidget.getLineAtOffset(widgetRegion.getOffset());
- yy= Math.min((startLine * size.y) / maxLines, size.y - hh);
-
- if (fill != null) {
- gc.setBackground(fill);
- gc.fillRectangle(INSET, yy, size.x-(2*INSET), hh);
- }
-
- if (stroke != null) {
- gc.setForeground(stroke);
- r.x= INSET;
- r.y= yy;
- r.width= size.x - (2 * INSET) - 1;
- r.height= hh;
- gc.setLineWidth(1);
- gc.drawRectangle(r);
- }
- } catch (BadLocationException x) {
- }
- }
- }
- }
- fCachedAnnotations.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRuler#update()
- */
- public void update() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- Display d= fCanvas.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- redraw();
- updateHeader();
- }
- });
- }
- }
- }
-
- /**
- * Redraws the overview ruler.
- */
- private void redraw() {
-
- if (fTextViewer == null || fModel == null)
- return;
-
- if (fCanvas != null && !fCanvas.isDisposed()) {
- GC gc= new GC(fCanvas);
- doubleBufferPaint(gc);
- gc.dispose();
- }
- }
-
- /**
- * Translates a given y-coordinate of this ruler into the corresponding
- * document lines. The number of lines depends on the concrete scaling
- * given as the ration between the height of this ruler and the length
- * of the document.
- *
- * @param y_coordinate the y-coordinate
- * @return the corresponding document lines
- */
- private int[] toLineNumbers(int y_coordinate) {
-
- StyledText textWidget= fTextViewer.getTextWidget();
- int maxLines= textWidget.getContent().getLineCount();
-
- int rulerLength= fCanvas.getSize().y;
- int writable= maxLines * textWidget.getLineHeight();
-
- if (rulerLength > writable)
- rulerLength= Math.max(writable - fHeader.getSize().y, 0);
-
- if (y_coordinate >= writable || y_coordinate >= rulerLength)
- return new int[] {-1, -1};
-
- int[] lines= new int[2];
-
- int pixel0= Math.max(y_coordinate - 1, 0);
- int pixel1= Math.min(rulerLength, y_coordinate + 1);
- rulerLength= Math.max(rulerLength, 1);
-
- lines[0]= (pixel0 * maxLines) / rulerLength;
- lines[1]= (pixel1 * maxLines) / rulerLength;
-
- if (fTextViewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- lines[0]= extension.widgetLine2ModelLine(lines[0]);
- lines[1]= extension.widgetLine2ModelLine(lines[1]);
- } else {
- try {
- IRegion visible= fTextViewer.getVisibleRegion();
- int lineNumber= fTextViewer.getDocument().getLineOfOffset(visible.getOffset());
- lines[0] += lineNumber;
- lines[1] += lineNumber;
- } catch (BadLocationException x) {
- }
- }
-
- return lines;
- }
-
- /**
- * Returns the position of the first annotation found in the given line range.
- *
- * @param lineNumbers the line range
- * @param ignoreSelectedAnnotation whether to ignore the current selection
- * @return the position of the first found annotation
- */
- private Position getAnnotationPosition(int[] lineNumbers, boolean ignoreSelectedAnnotation) {
- if (lineNumbers[0] == -1)
- return null;
-
- Position found= null;
-
- try {
- IDocument d= fTextViewer.getDocument();
- IRegion line= d.getLineInformation(lineNumbers[0]);
-
- Point currentSelection= fTextViewer.getSelectedRange();
-
- int start= line.getOffset();
-
- line= d.getLineInformation(lineNumbers[lineNumbers.length - 1]);
- int end= line.getOffset() + line.getLength();
-
- for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) {
-
- Object annotationType= fAnnotationsSortedByLayer.get(i);
-
- Iterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY);
- while (e.hasNext() && found == null) {
- Annotation a= (Annotation) e.next();
- if (a.isMarkedDeleted())
- continue;
-
- if (skip(a.getType()))
- continue;
-
- Position p= fModel.getPosition(a);
- if (p == null)
- continue;
-
- int posOffset= p.getOffset();
- int posEnd= posOffset + p.getLength();
- IRegion region= d.getLineInformationOfOffset(posEnd);
- // trailing empty lines don't count
- if (posEnd > posOffset && region.getOffset() == posEnd) {
- posEnd--;
- region= d.getLineInformationOfOffset(posEnd);
- }
-
- if (posOffset <= end && posEnd >= start) {
- if ((found == null || posOffset < found.getOffset()) && (ignoreSelectedAnnotation || currentSelection.x != posOffset || currentSelection.y != p.getLength()))
- found= p;
- }
- }
- }
- } catch (BadLocationException x) {
- }
-
- return found;
- }
-
- /**
- * Returns the line which corresponds best to one of
- * the underlying annotations at the given y-coordinate.
- *
- * @param lineNumbers the line numbers
- * @return the best matching line or <code>-1</code> if no such line can be found
- */
- private int findBestMatchingLineNumber(int[] lineNumbers) {
- if (lineNumbers == null || lineNumbers.length < 1)
- return -1;
-
- try {
- Position pos= getAnnotationPosition(lineNumbers, true);
- if (pos == null)
- return -1;
- return fTextViewer.getDocument().getLineOfOffset(pos.getOffset());
- } catch (BadLocationException ex) {
- return -1;
- }
- }
-
- /**
- * Handles mouse clicks.
- *
- * @param event the mouse button down event
- */
- private void handleMouseDown(MouseEvent event) {
- if (fTextViewer != null) {
- int[] lines= toLineNumbers(event.y);
- Position p= getAnnotationPosition(lines, false);
- if (p != null) {
- fTextViewer.revealRange(p.getOffset(), p.getLength());
- fTextViewer.setSelectedRange(p.getOffset(), p.getLength());
- }
- fTextViewer.getTextWidget().setFocus();
- }
- fLastMouseButtonActivityLine= toDocumentLineNumber(event.y);
- }
-
- /**
- * Handles mouse moves.
- *
- * @param event the mouse move event
- */
- private void handleMouseMove(MouseEvent event) {
- if (fTextViewer != null) {
- int[] lines= toLineNumbers(event.y);
- Position p= getAnnotationPosition(lines, true);
- Cursor cursor= (p != null ? fHitDetectionCursor : null);
- if (cursor != fLastCursor) {
- fCanvas.setCursor(cursor);
- fLastCursor= cursor;
- }
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#addAnnotationType(java.lang.Object)
- */
- public void addAnnotationType(Object annotationType) {
- fConfiguredAnnotationTypes.add(annotationType);
- fAllowedAnnotationTypes.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#removeAnnotationType(java.lang.Object)
- */
- public void removeAnnotationType(Object annotationType) {
- fConfiguredAnnotationTypes.remove(annotationType);
- fAllowedAnnotationTypes.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#setAnnotationTypeLayer(java.lang.Object, int)
- */
- public void setAnnotationTypeLayer(Object annotationType, int layer) {
- Integer layerObj= new Integer(layer);
- if (fAnnotationsSortedByLayer.remove(annotationType))
- fLayersSortedByLayer.remove(layerObj);
-
- if (layer >= 0) {
- int i= 0;
- int size= fLayersSortedByLayer.size();
- while (i < size && layer >= ((Integer)fLayersSortedByLayer.get(i)).intValue())
- i++;
- fLayersSortedByLayer.add(i, layerObj);
- fAnnotationsSortedByLayer.add(i, annotationType);
- }
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#setAnnotationTypeColor(java.lang.Object, org.eclipse.swt.graphics.Color)
- */
- public void setAnnotationTypeColor(Object annotationType, Color color) {
- if (color != null)
- fAnnotationTypes2Colors.put(annotationType, color);
- else
- fAnnotationTypes2Colors.remove(annotationType);
- }
-
- /**
- * Returns whether the given annotation type should be skipped by the drawing routine.
- *
- * @param annotationType the annotation type
- * @return <code>true</code> if annotation of the given type should be skipped
- */
- private boolean skip(Object annotationType) {
- return !contains(annotationType, fAllowedAnnotationTypes, fConfiguredAnnotationTypes);
- }
-
- /**
- * Returns whether the given annotation type should be skipped by the drawing routine of the header.
- *
- * @param annotationType the annotation type
- * @return <code>true</code> if annotation of the given type should be skipped
- * @since 3.0
- */
- private boolean skipInHeader(Object annotationType) {
- return !contains(annotationType, fAllowedHeaderAnnotationTypes, fConfiguredHeaderAnnotationTypes);
- }
-
- /**
- * Returns whether the given annotation type is mapped to <code>true</code>
- * in the given <code>allowed</code> map or covered by the <code>configured</code>
- * set.
- *
- * @param annotationType the annotation type
- * @param allowed the map with allowed annotation types mapped to booleans
- * @param configured the set with configured annotation types
- * @return <code>true</code> if annotation is contained, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean contains(Object annotationType, Map allowed, Set configured) {
- Boolean cached= (Boolean) allowed.get(annotationType);
- if (cached != null)
- return cached.booleanValue();
-
- boolean covered= isCovered(annotationType, configured);
- allowed.put(annotationType, covered ? Boolean.TRUE : Boolean.FALSE);
- return covered;
- }
-
- /**
- * Computes whether the annotations of the given type are covered by the given <code>configured</code>
- * set. This is the case if either the type of the annotation or any of its
- * super types is contained in the <code>configured</code> set.
- *
- * @param annotationType the annotation type
- * @param configured the set with configured annotation types
- * @return <code>true</code> if annotation is covered, <code>false</code>
- * otherwise
- * @since 3.0
- */
- private boolean isCovered(Object annotationType, Set configured) {
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- Iterator e= configured.iterator();
- while (e.hasNext()) {
- if (extension.isSubtype(annotationType,e.next()))
- return true;
- }
- return false;
- }
- return configured.contains(annotationType);
- }
-
- /**
- * Returns a specification of a color that lies between the given
- * foreground and background color using the given scale factor.
- *
- * @param fg the foreground color
- * @param bg the background color
- * @param scale the scale factor
- * @return the interpolated color
- */
- private static RGB interpolate(RGB fg, RGB bg, double scale) {
- return new RGB(
- (int) ((1.0-scale) * fg.red + scale * bg.red),
- (int) ((1.0-scale) * fg.green + scale * bg.green),
- (int) ((1.0-scale) * fg.blue + scale * bg.blue)
- );
- }
-
- /**
- * Returns the grey value in which the given color would be drawn in grey-scale.
- *
- * @param rgb the color
- * @return the grey-scale value
- */
- private static double greyLevel(RGB rgb) {
- if (rgb.red == rgb.green && rgb.green == rgb.blue)
- return rgb.red;
- return (0.299 * rgb.red + 0.587 * rgb.green + 0.114 * rgb.blue + 0.5);
- }
-
- /**
- * Returns whether the given color is dark or light depending on the colors grey-scale level.
- *
- * @param rgb the color
- * @return <code>true</code> if the color is dark, <code>false</code> if it is light
- */
- private static boolean isDark(RGB rgb) {
- return greyLevel(rgb) > 128;
- }
-
- /**
- * Returns a color based on the color configured for the given annotation type and the given scale factor.
- *
- * @param annotationType the annotation type
- * @param scale the scale factor
- * @return the computed color
- */
- private Color getColor(Object annotationType, double scale) {
- Color base= findColor(annotationType);
- if (base == null)
- return null;
-
- RGB baseRGB= base.getRGB();
- RGB background= fCanvas.getBackground().getRGB();
-
- boolean darkBase= isDark(baseRGB);
- boolean darkBackground= isDark(background);
- if (darkBase && darkBackground)
- background= new RGB(255, 255, 255);
- else if (!darkBase && !darkBackground)
- background= new RGB(0, 0, 0);
-
- return fSharedTextColors.getColor(interpolate(baseRGB, background, scale));
- }
-
- /**
- * Returns the color for the given annotation type
- *
- * @param annotationType the annotation type
- * @return the color
- * @since 3.0
- */
- private Color findColor(Object annotationType) {
- Color color= (Color) fAnnotationTypes2Colors.get(annotationType);
- if (color != null)
- return color;
-
- if (fAnnotationAccess instanceof IAnnotationAccessExtension) {
- IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess;
- Object[] superTypes= extension.getSupertypes(annotationType);
- if (superTypes != null) {
- for (int i= 0; i < superTypes.length; i++) {
- color= (Color) fAnnotationTypes2Colors.get(superTypes[i]);
- if (color != null)
- return color;
- }
- }
- }
-
- return null;
- }
-
- /**
- * Returns the stroke color for the given annotation type and characteristics.
- *
- * @param annotationType the annotation type
- * @param temporary <code>true</code> if for temporary annotations
- * @return the stroke color
- */
- private Color getStrokeColor(Object annotationType, boolean temporary) {
- return getColor(annotationType, temporary ? 0.5 : 0.2);
- }
-
- /**
- * Returns the fill color for the given annotation type and characteristics.
- *
- * @param annotationType the annotation type
- * @param temporary <code>true</code> if for temporary annotations
- * @return the fill color
- */
- private Color getFillColor(Object annotationType, boolean temporary) {
- return getColor(annotationType, temporary ? 0.9 : 0.6);
- }
-
- /*
- * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- */
- public int getLineOfLastMouseButtonActivity() {
- return fLastMouseButtonActivityLine;
- }
-
- /*
- * @see IVerticalRulerInfo#toDocumentLineNumber(int)
- */
- public int toDocumentLineNumber(int y_coordinate) {
-
- if (fTextViewer == null || y_coordinate == -1)
- return -1;
-
- int[] lineNumbers= toLineNumbers(y_coordinate);
- int bestLine= findBestMatchingLineNumber(lineNumbers);
- if (bestLine == -1 && lineNumbers.length > 0)
- return lineNumbers[0];
- return bestLine;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IVerticalRuler#getModel()
- */
- public IAnnotationModel getModel() {
- return fModel;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#getAnnotationHeight()
- */
- public int getAnnotationHeight() {
- return fAnnotationHeight;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int)
- */
- public boolean hasAnnotation(int y) {
- return findBestMatchingLineNumber(toLineNumbers(y)) != -1;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#getHeaderControl()
- */
- public Control getHeaderControl() {
- return fHeader;
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#addHeaderAnnotationType(java.lang.Object)
- */
- public void addHeaderAnnotationType(Object annotationType) {
- fConfiguredHeaderAnnotationTypes.add(annotationType);
- fAllowedHeaderAnnotationTypes.clear();
- }
-
- /*
- * @see org.eclipse.jface.text.source.IOverviewRuler#removeHeaderAnnotationType(java.lang.Object)
- */
- public void removeHeaderAnnotationType(Object annotationType) {
- fConfiguredHeaderAnnotationTypes.remove(annotationType);
- fAllowedHeaderAnnotationTypes.clear();
- }
-
- /**
- * Updates the header of this ruler.
- */
- private void updateHeader() {
-
- if (fHeader == null || fHeader.isDisposed())
- return;
-
- Object colorType= null;
- outer: for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) {
-
- Object annotationType= fAnnotationsSortedByLayer.get(i);
-
- if (skipInHeader(annotationType) || skip(annotationType))
- continue;
-
- for (Iterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY | FilterIterator.IGNORE_BAGS); e.hasNext();) {
- if (e.next() != null) {
- colorType= annotationType;
- break outer;
- }
- }
- }
-
- Color color= null;
- if (colorType != null)
- color= findColor(colorType);
-
- if (color == null) {
- if (fHeaderPainter != null)
- fHeaderPainter.setColor(null);
- } else {
- if (fHeaderPainter == null) {
- fHeaderPainter= new HeaderPainter();
- fHeader.addPaintListener(fHeaderPainter);
- }
- fHeaderPainter.setColor(color);
- }
-
- fHeader.redraw();
- updateHeaderToolTipText();
- }
-
- /**
- * Updates the tool tip text of the header of this ruler.
- *
- * @since 3.0
- */
- private void updateHeaderToolTipText() {
-
- if (fHeader == null || fHeader.isDisposed())
- return;
-
- fHeader.setToolTipText(null);
-
- if (!(fAnnotationAccess instanceof IAnnotationAccessExtension))
- return;
-
- String overview= ""; //$NON-NLS-1$
-
- for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) {
-
- Object annotationType= fAnnotationsSortedByLayer.get(i);
-
- if (skipInHeader(annotationType) || skip(annotationType))
- continue;
-
- int count= 0;
- String annotationTypeLabel= null;
-
- for (Iterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY | FilterIterator.IGNORE_BAGS); e.hasNext();) {
- Annotation annotation= (Annotation)e.next();
- if (annotation != null) {
- if (annotationTypeLabel == null)
- annotationTypeLabel= ((IAnnotationAccessExtension)fAnnotationAccess).getTypeLabel(annotation);
- count++;
- }
- }
-
- if (annotationTypeLabel != null) {
- if (overview.length() > 0)
- overview += "\n"; //$NON-NLS-1$
- overview += JFaceTextMessages.getFormattedString("OverviewRulerHeader.toolTipTextEntry", new Object[] {annotationTypeLabel, new Integer(count)}); //$NON-NLS-1$
- }
- }
- if (overview.length() > 0)
- fHeader.setToolTipText(overview);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRulerHoverManager.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRulerHoverManager.java
deleted file mode 100644
index 765d3ebdf21..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/OverviewRulerHoverManager.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.source.AnnotationBarHoverManager;
-import org.eclipse.jface.text.source.IAnnotationHover;
-import org.eclipse.jface.text.source.ISourceViewer;
-
-/**
- * This manager controls the layout, content, and visibility of an information
- * control in reaction to mouse hover events issued by the overview ruler of a
- * source viewer.
- *
- * @since 2.1
- */
-class OverviewRulerHoverManager extends AnnotationBarHoverManager {
-
- /**
- * Creates an overview hover manager with the given parameters. In addition,
- * the hovers anchor is RIGHT and the margin is 5 points to the right.
- *
- * @param ruler the overview ruler this manager connects to
- * @param sourceViewer the source viewer this manager connects to
- * @param annotationHover the annotation hover providing the information to be displayed
- * @param creator the information control creator
- */
- public OverviewRulerHoverManager(IOverviewRuler ruler, ISourceViewer sourceViewer, IAnnotationHover annotationHover, IInformationControlCreator creator) {
- super(ruler, sourceViewer, annotationHover, creator);
- setAnchor(ANCHOR_LEFT);
- }
-
- /*
- * @see AbstractHoverInformationControlManager#computeInformation()
- */
- protected void computeInformation() {
- Point location= getHoverEventLocation();
- int line= getVerticalRulerInfo().toDocumentLineNumber(location.y);
- setInformation(getAnnotationHover().getHoverInfo(getSourceViewer(), line), computeArea(location.y));
- }
-
- /**
- * Determines graphical area covered for which the hover is valid.
- *
- * @param y-coordinate in the vertical ruler
- * @return the graphical extend where the hover is valid
- */
- private Rectangle computeArea(int y) {
- // This is ok (see constructor)
- IOverviewRuler overviewRuler= (IOverviewRuler) getVerticalRulerInfo();
-
- int hover_height= overviewRuler.getAnnotationHeight();
- int hover_width= getVerticalRulerInfo().getControl().getSize().x;
-
- // Calculate y-coordinate for hover
- int hover_y= y;
- boolean hasAnnotation= true;
- while (hasAnnotation && hover_y > y - hover_height) {
- hover_y--;
- hasAnnotation= overviewRuler.hasAnnotation(hover_y);
- }
- hover_y++;
-
- return new Rectangle(0, hover_y, hover_width, hover_height);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java
deleted file mode 100644
index 7ad0d4f807e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewer.java
+++ /dev/null
@@ -1,902 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-import java.util.Stack;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Layout;
-
-import org.eclipse.jface.text.AbstractHoverInformationControlManager;
-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.IRegion;
-import org.eclipse.jface.text.IRewriteTarget;
-import org.eclipse.jface.text.ISlaveDocumentManager;
-import org.eclipse.jface.text.ISlaveDocumentManagerExtension;
-import org.eclipse.jface.text.ITextViewerExtension2;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextViewer;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.formatter.FormattingContext;
-import org.eclipse.jface.text.formatter.FormattingContextProperties;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.formatter.IContentFormatterExtension;
-import org.eclipse.jface.text.formatter.IFormattingContext;
-import org.eclipse.jface.text.information.IInformationPresenter;
-import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.projection.ChildDocument;
-import org.eclipse.jface.text.reconciler.IReconciler;
-
-/**
- * SWT based implementation of <code>ISourceViewer</code>. The same rules apply
- * as for <code>TextViewer</code>. A source viewer uses an <code>IVerticalRuler</code>
- * as its annotation presentation area. The vertical ruler is a small strip shown left
- * of the viewer's text widget. A source viewer uses an <code>IOverviewRuler</code>
- * as its presentation area for the annotation overview. The overview ruler is a small strip
- * shown right of the viewer's text widget.<p>
- * Clients are supposed to instantiate a source viewer and subsequently to communicate
- * with it exclusively using the <code>ISourceViewer</code> interface. Clients should not
- * subclass this class as it is rather likely that subclasses will be broken by future releases.
- */
-public class SourceViewer extends TextViewer implements ISourceViewer, ISourceViewerExtension, ISourceViewerExtension2 {
-
-
- /**
- * Layout of a source viewer. Vertical ruler, text widget, and overview ruler are shown side by side.
- */
- protected class RulerLayout extends Layout {
-
- /** The gap between the text viewer and the vertical ruler. */
- protected int fGap;
-
- /**
- * Creates a new ruler layout with the given gap between text viewer and vertical ruler.
- *
- * @param gap the gap between text viewer and vertical ruler
- */
- public RulerLayout(int gap) {
- fGap= gap;
- }
-
- /*
- * @see Layout#computeSize(Composite, int, int, boolean)
- */
- protected Point computeSize(Composite composite, int wHint, int hHint, boolean flushCache) {
- Control[] children= composite.getChildren();
- Point s= children[children.length - 1].computeSize(SWT.DEFAULT, SWT.DEFAULT, flushCache);
- if (fVerticalRuler != null && fIsVerticalRulerVisible)
- s.x += fVerticalRuler.getWidth() + fGap;
- return s;
- }
-
- /*
- * @see Layout#layout(Composite, boolean)
- */
- protected void layout(Composite composite, boolean flushCache) {
- Rectangle clArea= composite.getClientArea();
- if (fVerticalRuler != null && fIsVerticalRulerVisible) {
-
- Rectangle trim= getTextWidget().computeTrim(0, 0, 0, 0);
- int scrollbarHeight= trim.height;
-
- int verticalRulerWidth= fVerticalRuler.getWidth();
- int overviewRulerWidth= 0;
- if (fOverviewRuler != null && fIsOverviewRulerVisible) {
- overviewRulerWidth= fOverviewRuler.getWidth();
- fOverviewRuler.getControl().setBounds(clArea.width - overviewRulerWidth -1, scrollbarHeight, overviewRulerWidth, clArea.height - 3*scrollbarHeight);
- fOverviewRuler.getHeaderControl().setBounds(clArea.width - overviewRulerWidth -1, 0, overviewRulerWidth, scrollbarHeight);
- }
-
- getTextWidget().setBounds(verticalRulerWidth + fGap, 0, clArea.width - verticalRulerWidth - overviewRulerWidth - 2*fGap, clArea.height);
- fVerticalRuler.getControl().setBounds(0, 0, verticalRulerWidth, clArea.height - scrollbarHeight);
-
- } else
- getTextWidget().setBounds(0, 0, clArea.width, clArea.height);
- }
- }
-
- /** The size of the gap between the vertical ruler and the text widget */
- protected final static int GAP_SIZE= 2;
- /**
- * Partial name of the position category to manage remembered selections.
- * @since 3.0
- */
- protected final static String _SELECTION_POSITION_CATEGORY= "__selection_category"; //$NON-NLS-1$
- /**
- * Key of the model annotation model inside the visual annotation model.
- * @since 3.0
- */
- protected final static Object MODEL_ANNOTATION_MODEL= new Object();
-
- /** The viewer's content assistant */
- protected IContentAssistant fContentAssistant;
- /**
- * Flag indicating whether the viewer's content assistant is installed
- * @since 2.0
- */
- protected boolean fContentAssistantInstalled;
- /** The viewer's content formatter */
- protected IContentFormatter fContentFormatter;
- /** The viewer's model reconciler */
- protected IReconciler fReconciler;
- /** The viewer's presentation reconciler */
- protected IPresentationReconciler fPresentationReconciler;
- /** The viewer's annotation hover */
- protected IAnnotationHover fAnnotationHover;
- /**
- * Stack of saved selections in the underlying document
- * @since 3.0
- */
- protected final Stack fSelections= new Stack();
- /**
- * Position updater for saved selections
- * @since 3.0
- */
- protected IPositionUpdater fSelectionUpdater= null;
- /**
- * Position category used by the selection updater
- * @since 3.0
- */
- protected String fSelectionCategory;
- /**
- * The viewer's overview ruler annotation hover
- * @since 3.0
- */
- protected IAnnotationHover fOverviewRulerAnnotationHover;
- /**
- * The viewer's information presenter
- * @since 2.0
- */
- protected IInformationPresenter fInformationPresenter;
-
- /** Visual vertical ruler */
- private IVerticalRuler fVerticalRuler;
- /** Visibility of vertical ruler */
- private boolean fIsVerticalRulerVisible;
- /** The SWT widget used when supporting a vertical ruler */
- private Composite fComposite;
- /** The vertical ruler's annotation model */
- private IAnnotationModel fVisualAnnotationModel;
- /** The viewer's range indicator to be shown in the vertical ruler */
- private Annotation fRangeIndicator;
- /** The viewer's vertical ruler hovering controller */
- private AbstractHoverInformationControlManager fVerticalRulerHoveringController;
- /**
- * The viewer's overview ruler hovering controller
- * @since 2.1
- */
- private AbstractHoverInformationControlManager fOverviewRulerHoveringController;
-
- /**
- * The overview ruler.
- * @since 2.1
- */
- private IOverviewRuler fOverviewRuler;
- /**
- * The visibility of the overview ruler
- * @since 2.1
- */
- private boolean fIsOverviewRulerVisible;
-
-
- /**
- * Constructs a new source viewer. The vertical ruler is initially visible.
- * The viewer has not yet been initialized with a source viewer configuration.
- *
- * @param parent the parent of the viewer's control
- * @param ruler the vertical ruler used by this source viewer
- * @param styles the SWT style bits
- */
- public SourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
- this(parent, ruler, null, false, styles);
- }
-
- /**
- * Constructs a new source viewer. The vertical ruler is initially visible.
- * The overview ruler visibility is controlled by the value of <code>showAnnotationsOverview</code>.
- * The viewer has not yet been initialized with a source viewer configuration.
- *
- * @param parent the parent of the viewer's control
- * @param verticalRuler the vertical ruler used by this source viewer
- * @param overviewRuler the overview ruler
- * @param showAnnotationsOverview <code>true</code> if the overview ruler should be visible, <code>false</code> otherwise
- * @param styles the SWT style bits
- * @since 2.1
- */
- public SourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean showAnnotationsOverview, int styles) {
- super();
-
- fVerticalRuler= verticalRuler;
- fIsVerticalRulerVisible= (verticalRuler != null);
- fOverviewRuler= overviewRuler;
- fIsOverviewRulerVisible= (showAnnotationsOverview && overviewRuler != null);
-
- createControl(parent, styles);
- }
-
- /*
- * @see TextViewer#createControl(Composite, int)
- */
- protected void createControl(Composite parent, int styles) {
-
- if (fVerticalRuler != null || fOverviewRuler != null) {
- styles= (styles & ~SWT.BORDER);
- fComposite= new Canvas(parent, SWT.NONE);
- fComposite.setLayout(createLayout());
- parent= fComposite;
- }
-
- super.createControl(parent, styles);
-
- if (fVerticalRuler != null)
- fVerticalRuler.createControl(fComposite, this);
- if (fOverviewRuler != null)
- fOverviewRuler.createControl(fComposite, this);
- }
-
- /**
- * Creates the layout used for this viewer.
- * Subclasses may override this method.
- *
- * @return the layout used for this viewer
- * @since 3.0
- */
- protected Layout createLayout() {
- return new RulerLayout(GAP_SIZE);
- }
-
- /*
- * @see TextViewer#getControl()
- */
- public Control getControl() {
- if (fComposite != null)
- return fComposite;
- return super.getControl();
- }
-
- /*
- * @see ISourceViewer#setAnnotationHover(IAnnotationHover)
- */
- public void setAnnotationHover(IAnnotationHover annotationHover) {
- fAnnotationHover= annotationHover;
- }
-
- /**
- * Sets the overview ruler's annotation hover of this source viewer.
- * The annotation hover provides the information to be displayed in a hover
- * popup window if requested over the overview rulers area. The annotation
- * hover is assumed to be line oriented.
- *
- * @param annotationHover the hover to be used, <code>null</code> is a valid argument
- * @since 3.0
- */
- public void setOverviewRulerAnnotationHover(IAnnotationHover annotationHover) {
- fOverviewRulerAnnotationHover= annotationHover;
- }
-
- /*
- * @see ISourceViewer#configure(SourceViewerConfiguration)
- */
- public void configure(SourceViewerConfiguration configuration) {
-
- if (getTextWidget() == null)
- return;
-
- setDocumentPartitioning(configuration.getConfiguredDocumentPartitioning(this));
-
- // install content type independent plug-ins
- fPresentationReconciler= configuration.getPresentationReconciler(this);
- if (fPresentationReconciler != null)
- fPresentationReconciler.install(this);
-
- fReconciler= configuration.getReconciler(this);
- if (fReconciler != null)
- fReconciler.install(this);
-
- fContentAssistant= configuration.getContentAssistant(this);
- if (fContentAssistant != null) {
- fContentAssistant.install(this);
- fContentAssistantInstalled= true;
- }
-
- fContentFormatter= configuration.getContentFormatter(this);
-
- fInformationPresenter= configuration.getInformationPresenter(this);
- if (fInformationPresenter != null)
- fInformationPresenter.install(this);
-
- setUndoManager(configuration.getUndoManager(this));
-
- getTextWidget().setTabs(configuration.getTabWidth(this));
-
- setAnnotationHover(configuration.getAnnotationHover(this));
- setOverviewRulerAnnotationHover(configuration.getOverviewRulerAnnotationHover(this));
-
- setHoverControlCreator(configuration.getInformationControlCreator(this));
-
- // install content type specific plug-ins
- String[] types= configuration.getConfiguredContentTypes(this);
- for (int i= 0; i < types.length; i++) {
-
- String t= types[i];
-
- setAutoIndentStrategy(configuration.getAutoIndentStrategy(this, t), t);
- setTextDoubleClickStrategy(configuration.getDoubleClickStrategy(this, t), t);
-
- int[] stateMasks= configuration.getConfiguredTextHoverStateMasks(this, t);
- if (stateMasks != null) {
- for (int j= 0; j < stateMasks.length; j++) {
- int stateMask= stateMasks[j];
- setTextHover(configuration.getTextHover(this, t, stateMask), t, stateMask);
- }
- } else {
- setTextHover(configuration.getTextHover(this, t), t, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK);
- }
-
- String[] prefixes= configuration.getIndentPrefixes(this, t);
- if (prefixes != null && prefixes.length > 0)
- setIndentPrefixes(prefixes, t);
-
- prefixes= configuration.getDefaultPrefixes(this, t);
- if (prefixes != null && prefixes.length > 0)
- setDefaultPrefixes(prefixes, t);
- }
-
- activatePlugins();
- }
-
- /**
- * After this method has been executed the caller knows that any installed annotation hover has been installed.
- */
- protected void ensureAnnotationHoverManagerInstalled() {
- if (fVerticalRuler != null && fAnnotationHover != null && fVerticalRulerHoveringController == null && fHoverControlCreator != null) {
- fVerticalRulerHoveringController= new AnnotationBarHoverManager(fVerticalRuler, this, fAnnotationHover, fHoverControlCreator);
- fVerticalRulerHoveringController.install(fVerticalRuler.getControl());
- }
- }
-
- /**
- * After this method has been executed the caller knows that any installed overview hover has been installed.
- */
- protected void ensureOverviewHoverManagerInstalled() {
- if (fOverviewRuler != null && fOverviewRulerAnnotationHover != null && fOverviewRulerHoveringController == null && fHoverControlCreator != null) {
- fOverviewRulerHoveringController= new OverviewRulerHoverManager(fOverviewRuler, this, fOverviewRulerAnnotationHover, fHoverControlCreator);
- fOverviewRulerHoveringController.install(fOverviewRuler.getControl());
- }
- }
-
- /*
- * @see TextViewer#activatePlugins()
- */
- public void activatePlugins() {
- ensureAnnotationHoverManagerInstalled();
- ensureOverviewHoverManagerInstalled();
- super.activatePlugins();
- }
-
- /*
- * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
- */
- public void setDocument(IDocument document) {
- setDocument(document, null, -1, -1);
- }
-
- /*
- * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
- */
- public void setDocument(IDocument document, int visibleRegionOffset, int visibleRegionLength) {
- setDocument(document, null, visibleRegionOffset, visibleRegionLength);
- }
-
- /*
- * @see ISourceViewer#setDocument(IDocument, IAnnotationModel)
- */
- public void setDocument(IDocument document, IAnnotationModel annotationModel) {
- setDocument(document, annotationModel, -1, -1);
- }
-
- /**
- * Creates the visual annotation model on top of the given annotation model.
- *
- * @param annotationModel the wrapped annotation model
- * @return the visual annotation model on top of the given annotation model
- * @since 3.0
- */
- protected IAnnotationModel createVisualAnnotationModel(IAnnotationModel annotationModel) {
- IAnnotationModelExtension model= new AnnotationModel();
- model.addAnnotationModel(MODEL_ANNOTATION_MODEL, annotationModel);
- return (IAnnotationModel) model;
- }
-
- /*
- * @see ISourceViewer#setDocument(IDocument, IAnnotationModel, int, int)
- */
- public void setDocument(IDocument document, IAnnotationModel annotationModel, int modelRangeOffset, int modelRangeLength) {
- if (fVerticalRuler == null && fOverviewRuler == null) {
-
- if (modelRangeOffset == -1 && modelRangeLength == -1)
- super.setDocument(document);
- else
- super.setDocument(document, modelRangeOffset, modelRangeLength);
-
- } else {
-
- if (fVisualAnnotationModel != null && getDocument() != null)
- fVisualAnnotationModel.disconnect(getDocument());
-
- if (annotationModel != null && document != null) {
- fVisualAnnotationModel= createVisualAnnotationModel(annotationModel);
- fVisualAnnotationModel.connect(document);
- } else {
- fVisualAnnotationModel= null;
- }
-
- if (modelRangeOffset == -1 && modelRangeLength == -1)
- super.setDocument(document);
- else
- super.setDocument(document, modelRangeOffset, modelRangeLength);
-
- if (fVerticalRuler != null)
- fVerticalRuler.setModel(fVisualAnnotationModel);
-
- if (fOverviewRuler != null)
- fOverviewRuler.setModel(fVisualAnnotationModel);
- }
- }
-
- /*
- * @see ISourceViewer#getAnnotationModel()
- */
- public IAnnotationModel getAnnotationModel() {
- if (fVisualAnnotationModel instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) fVisualAnnotationModel;
- return extension.getAnnotationModel(MODEL_ANNOTATION_MODEL);
- }
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.source.ISourceViewerExtension2#getVisualAnnotationModel()
- * @since 3.0
- */
- public IAnnotationModel getVisualAnnotationModel() {
- return fVisualAnnotationModel;
- }
-
- /*
- * @see org.eclipse.jface.text.source.ISourceViewerExtension2#unconfigure()
- * @since 3.0
- */
- public void unconfigure() {
- clearRememberedSelection();
-
- if (fPresentationReconciler != null) {
- fPresentationReconciler.uninstall();
- fPresentationReconciler= null;
- }
-
- if (fReconciler != null) {
- fReconciler.uninstall();
- fReconciler= null;
- }
-
- if (fContentAssistant != null) {
- fContentAssistant.uninstall();
- fContentAssistantInstalled= false;
- fContentAssistant= null;
- }
-
- fContentFormatter= null;
-
- if (fInformationPresenter != null) {
- fInformationPresenter.uninstall();
- fInformationPresenter= null;
- }
-
- fAutoIndentStrategies= null;
- fDoubleClickStrategies= null;
- fTextHovers= null;
- fIndentChars= null;
- fDefaultPrefixChars= null;
-
- if (fVerticalRulerHoveringController != null) {
- fVerticalRulerHoveringController.dispose();
- fVerticalRulerHoveringController= null;
- }
-
- if (fOverviewRulerHoveringController != null) {
- fOverviewRulerHoveringController.dispose();
- fOverviewRulerHoveringController= null;
- }
- }
-
- /*
- * @see org.eclipse.jface.text.TextViewer#handleDispose()
- */
- protected void handleDispose() {
- unconfigure();
-
- if (fVisualAnnotationModel != null && getDocument() != null) {
- fVisualAnnotationModel.disconnect(getDocument());
- fVisualAnnotationModel= null;
- }
-
- fVerticalRuler= null;
-
- fOverviewRuler= null;
-
- // http://dev.eclipse.org/bugs/show_bug.cgi?id=15300
- fComposite= null;
-
- super.handleDispose();
- }
-
- /*
- * @see ITextOperationTarget#canDoOperation(int)
- */
- public boolean canDoOperation(int operation) {
-
- if (getTextWidget() == null || (!redraws() && operation != FORMAT))
- return false;
-
- if (operation == CONTENTASSIST_PROPOSALS)
- return fContentAssistant != null && fContentAssistantInstalled && isEditable();
-
- if (operation == CONTENTASSIST_CONTEXT_INFORMATION)
- return fContentAssistant != null && fContentAssistantInstalled && isEditable();
-
- if (operation == INFORMATION)
- return fInformationPresenter != null;
-
- if (operation == FORMAT) {
- return fContentFormatter != null && isEditable();
- }
-
- return super.canDoOperation(operation);
- }
-
- /**
- * Creates a new formatting context for a format operation.
- * <p>
- * After the use of the context, clients are required to call
- * its <code>dispose</code> method.
- *
- * @return The new formatting context
- * @since 3.0
- */
- protected IFormattingContext createFormattingContext() {
- return new FormattingContext();
- }
-
- /**
- * Remembers and returns the current selection. The saved selection can be restored
- * by calling <code>restoreSelection()</code>.
- *
- * @return the current selection
- * @see org.eclipse.jface.text.ITextViewer#getSelectedRange()
- * @since 3.0
- */
- protected Point rememberSelection() {
-
- final Point selection= getSelectedRange();
- final IDocument document= getDocument();
-
- if (fSelections.isEmpty()) {
- fSelectionCategory= _SELECTION_POSITION_CATEGORY + hashCode();
- fSelectionUpdater= new DefaultPositionUpdater(fSelectionCategory);
- document.addPositionCategory(fSelectionCategory);
- document.addPositionUpdater(fSelectionUpdater);
- }
-
- try {
-
- final Position position= new Position(selection.x, selection.y);
- document.addPosition(fSelectionCategory, position);
- fSelections.push(position);
-
- } catch (BadLocationException exception) {
- // Should not happen
- } catch (BadPositionCategoryException exception) {
- // Should not happen
- }
-
- return selection;
- }
-
- /**
- * Restores a previously saved selection in the document.
- * <p>
- * If no selection was previously saved, nothing happens.
- *
- * @since 3.0
- */
- protected void restoreSelection() {
-
- if (!fSelections.isEmpty()) {
-
- final IDocument document= getDocument();
- final Position position= (Position) fSelections.pop();
-
- try {
- document.removePosition(fSelectionCategory, position);
- setSelectedRange(position.getOffset(), position.getLength());
-
- if (fSelections.isEmpty()) {
-
- document.removePositionUpdater(fSelectionUpdater);
- fSelectionUpdater= null;
- document.removePositionCategory(fSelectionCategory);
- fSelectionCategory= null;
- }
- } catch (BadPositionCategoryException exception) {
- // Should not happen
- }
- }
- }
-
- protected void clearRememberedSelection() {
- if (fSelections.isEmpty())
- return;
- fSelections.clear();
-
- IDocument document= getDocument();
- document.removePositionUpdater(fSelectionUpdater);
- fSelectionUpdater= null;
-
- try {
- document.removePositionCategory(fSelectionCategory);
- } catch (BadPositionCategoryException e) {
- // ignore
- }
- fSelectionCategory= null;
- }
-
- /*
- * @see ITextOperationTarget#doOperation(int)
- */
- public void doOperation(int operation) {
-
- if (getTextWidget() == null || (!redraws() && operation != FORMAT))
- return;
-
- switch (operation) {
- case CONTENTASSIST_PROPOSALS:
- fContentAssistant.showPossibleCompletions();
- return;
- case CONTENTASSIST_CONTEXT_INFORMATION:
- fContentAssistant.showContextInformation();
- return;
- case INFORMATION:
- fInformationPresenter.showInformation();
- return;
- case FORMAT:
- {
- final Point selection= rememberSelection();
- final IRewriteTarget target= getRewriteTarget();
- IFormattingContext context= null;
-
- try {
- setRedraw(false);
- startSequentialRewriteMode(false);
- target.beginCompoundChange();
-
- final IDocument document= getDocument();
- final String rememberedContents= document.get();
-
- try {
-
- if (fContentFormatter instanceof IContentFormatterExtension) {
- final IContentFormatterExtension extension= (IContentFormatterExtension) fContentFormatter;
- context= createFormattingContext();
- if (selection.y == 0) {
- context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.TRUE);
- } else {
- context.setProperty(FormattingContextProperties.CONTEXT_DOCUMENT, Boolean.FALSE);
- context.setProperty(FormattingContextProperties.CONTEXT_REGION, new Region(selection.x, selection.y));
- }
- extension.format(document, context);
- } else {
- IRegion r;
- if (selection.y == 0) {
- IRegion coverage= getModelCoverage();
- r= coverage == null ? new Region(0, 0) : coverage;
- } else {
- r= new Region(selection.x, selection.y);
- }
- fContentFormatter.format(document, r);
- }
-
- updateSlaveDocuments(document);
-
- } catch (RuntimeException x) {
- // fire wall for https://bugs.eclipse.org/bugs/show_bug.cgi?id=47472
- // if something went wrong we undo the changes we just did
- // TODO to be removed after 3.0 M8
- document.set(rememberedContents);
- throw x;
- }
-
- } finally {
-
- target.endCompoundChange();
- stopSequentialRewriteMode();
- setRedraw(true);
-
- restoreSelection();
- if (context != null)
- context.dispose();
- }
- return;
- }
- default:
- super.doOperation(operation);
- }
- }
-
- /**
- * Updates all slave documents of the given document. This default implementation calls <code>updateSlaveDocument</code>
- * for their current visible range. Subclasses may reimplement.
- *
- * @param masterDocument the master document
- * @since 3.0
- */
- protected void updateSlaveDocuments(IDocument masterDocument) {
- ISlaveDocumentManager manager= getSlaveDocumentManager();
- if (manager instanceof ISlaveDocumentManagerExtension) {
- ISlaveDocumentManagerExtension extension= (ISlaveDocumentManagerExtension) manager;
- IDocument[] slaves= extension.getSlaveDocuments(masterDocument);
- if (slaves != null) {
- for (int i= 0; i < slaves.length; i++) {
- if (slaves[i] instanceof ChildDocument) {
- ChildDocument child= (ChildDocument) slaves[i];
- Position p= child.getParentDocumentRange();
- try {
-
- if (!updateSlaveDocument(child, p.getOffset(), p.getLength()))
- child.repairLineInformation();
-
- } catch (BadLocationException e) {
- // ignore
- }
- }
- }
- }
- }
- }
-
- /*
- * @see ITextOperationTargetExtension#enableOperation(int, boolean)
- * @since 2.0
- */
- public void enableOperation(int operation, boolean enable) {
-
- switch (operation) {
- case CONTENTASSIST_PROPOSALS:
- case CONTENTASSIST_CONTEXT_INFORMATION: {
-
- if (fContentAssistant == null)
- return;
-
- if (enable) {
- if (!fContentAssistantInstalled) {
- fContentAssistant.install(this);
- fContentAssistantInstalled= true;
- }
- } else if (fContentAssistantInstalled) {
- fContentAssistant.uninstall();
- fContentAssistantInstalled= false;
- }
- }
- }
- }
-
- /*
- * @see ISourceViewer#setRangeIndicator(Annotation)
- */
- public void setRangeIndicator(Annotation rangeIndicator) {
- fRangeIndicator= rangeIndicator;
- }
-
- /*
- * @see ISourceViewer#setRangeIndication(int, int, boolean)
- */
- public void setRangeIndication(int start, int length, boolean moveCursor) {
-
- if (moveCursor) {
- setSelectedRange(start, 0);
- revealRange(start, length);
- }
-
- if (fRangeIndicator != null && fVisualAnnotationModel instanceof IAnnotationModelExtension) {
- IAnnotationModelExtension extension= (IAnnotationModelExtension) fVisualAnnotationModel;
- extension.modifyAnnotationPosition(fRangeIndicator, new Position(start, length));
- }
- }
-
- /*
- * @see ISourceViewer#getRangeIndication()
- */
- public IRegion getRangeIndication() {
- if (fRangeIndicator != null && fVisualAnnotationModel != null) {
- Position position= fVisualAnnotationModel.getPosition(fRangeIndicator);
- if (position != null)
- return new Region(position.getOffset(), position.getLength());
- }
-
- return null;
- }
-
- /*
- * @see ISourceViewer#removeRangeIndication()
- */
- public void removeRangeIndication() {
- if (fRangeIndicator != null && fVisualAnnotationModel != null)
- fVisualAnnotationModel.removeAnnotation(fRangeIndicator);
- }
-
- /*
- * @see ISourceViewer#showAnnotations(boolean)
- */
- public void showAnnotations(boolean show) {
- boolean old= fIsVerticalRulerVisible;
- fIsVerticalRulerVisible= (show && fVerticalRuler != null);
- if (old != fIsVerticalRulerVisible) {
- if (fComposite != null && !fComposite.isDisposed())
- fComposite.layout();
- if (fIsVerticalRulerVisible) {
- ensureAnnotationHoverManagerInstalled();
- } else if (fVerticalRulerHoveringController != null) {
- fVerticalRulerHoveringController.dispose();
- fVerticalRulerHoveringController= null;
- }
- }
- }
-
- /**
- * Returns the vertical ruler of this viewer.
- *
- * @return the vertical ruler of this viewer
- * @since 3.0
- */
- protected final IVerticalRuler getVerticalRuler() {
- return fVerticalRuler;
- }
-
- /*
- * @see org.eclipse.jface.text.source.ISourceViewerExtension#showAnnotationsOverview(boolean)
- * @since 2.1
- */
- public void showAnnotationsOverview(boolean show) {
- boolean old= fIsOverviewRulerVisible;
- fIsOverviewRulerVisible= (show && fOverviewRuler != null);
- if (old != fIsOverviewRulerVisible) {
- if (fComposite != null && !fComposite.isDisposed())
- fComposite.layout();
- if (fIsOverviewRulerVisible) {
- ensureOverviewHoverManagerInstalled();
- } else if (fOverviewRulerHoveringController != null) {
- fOverviewRulerHoveringController.dispose();
- fOverviewRulerHoveringController= null;
- }
- }
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
deleted file mode 100644
index cf803ad251a..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/SourceViewerConfiguration.java
+++ /dev/null
@@ -1,309 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.source;
-
-
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.text.DefaultAutoIndentStrategy;
-import org.eclipse.jface.text.DefaultInformationControl;
-import org.eclipse.jface.text.DefaultTextDoubleClickStrategy;
-import org.eclipse.jface.text.DefaultUndoManager;
-import org.eclipse.jface.text.IAutoIndentStrategy;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IDocumentExtension3;
-import org.eclipse.jface.text.IInformationControl;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.ITextDoubleClickStrategy;
-import org.eclipse.jface.text.ITextHover;
-import org.eclipse.jface.text.IUndoManager;
-import org.eclipse.jface.text.contentassist.IContentAssistant;
-import org.eclipse.jface.text.formatter.IContentFormatter;
-import org.eclipse.jface.text.information.IInformationPresenter;
-import org.eclipse.jface.text.presentation.IPresentationReconciler;
-import org.eclipse.jface.text.presentation.PresentationReconciler;
-import org.eclipse.jface.text.reconciler.IReconciler;
-
-
-/**
- * This class bundles the whole configuration space of a source viewer.
- * Instances of this class are passed to the <code>configure</code> method of
- * <code>ISourceViewer</code>.<p>
- * Each method in this class get as argument the source viewer for which it should
- * provide a particular configurational setting such as a presentation reconciler.
- * Based on its specific knowledge about the returned object, the configuration
- * might share such objects or compute them according to some rules.<p>
- * Clients should subclass and override just those methods which must be specific to
- * their needs.
- *
- * @see ISourceViewer
- */
-public class SourceViewerConfiguration {
-
-
- /**
- * Creates a new source viewer configuration that behaves according to
- * specification of this class' methods.
- */
- public SourceViewerConfiguration() {
- super();
- }
-
- /**
- * Returns the visual width of the tab character. This implementation always
- * returns 4.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return the tab width
- */
- public int getTabWidth(ISourceViewer sourceViewer) {
- return 4;
- }
-
- /**
- * Returns the undo manager for the given source viewer. This implementation
- * always returns a new instance of <code>DefaultUndoManager</code> whose
- * history length is set to 25.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return an undo manager or <code>null</code> if no undo/redo should not be supported
- */
- public IUndoManager getUndoManager(ISourceViewer sourceViewer) {
- return new DefaultUndoManager(25);
- }
-
- /**
- * Returns the reconciler ready to be used with the given source viewer.
- * This implementation always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return a reconciler or <code>null</code> if reconciling should not be supported
- */
- public IReconciler getReconciler(ISourceViewer sourceViewer) {
- return null;
- }
-
- /**
- * Returns the presentation reconciler ready to be used with the given source viewer.
- * This implementation always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer
- * @return the presentation reconciler or <code>null</code> if presentation reconciling should not be supported
- */
- public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
- PresentationReconciler reconciler= new PresentationReconciler();
- reconciler.setDocumentPartitioning(getConfiguredDocumentPartitioning(sourceViewer));
-
- return reconciler;
- }
-
- /**
- * Returns the content formatter ready to be used with the given source viewer.
- * This implementation always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return a content formatter or <code>null</code> if formatting should not be supported
- */
- public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) {
- return null;
- }
-
- /**
- * Returns the content assistant ready to be used with the given source viewer.
- * This implementation always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return a content assistant or <code>null</code> if content assist should not be supported
- */
- public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {
- return null;
- }
-
- /**
- * Returns the auto indentation strategy ready to be used with the given source viewer
- * when manipulating text of the given content type. This implementation always
- * returns an new instance of <code>DefaultAutoIndentStrategy</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type for which the strategy is applicable
- * @return the auto indent strategy or <code>null</code> if automatic indentation is not to be enabled
- */
- public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
- return new DefaultAutoIndentStrategy();
- }
- /**
- * Returns the default prefixes to be used by the line-prefix operation
- * in the given source viewer for text of the given content type. This implementation always
- * returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type for which the prefix is applicable
- * @return the default prefixes or <code>null</code> if the prefix operation should not be supported
- * @since 2.0
- */
- public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) {
- return null;
- }
-
- /**
- * Returns the double-click strategy ready to be used in this viewer when double clicking
- * onto text of the given content type. This implementation always returns a new instance of
- * <code>DefaultTextDoubleClickStrategy</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type for which the strategy is applicable
- * @return a double-click strategy or <code>null</code> if double clicking should not be supported
- */
- public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) {
- return new DefaultTextDoubleClickStrategy();
- }
-
- /**
- * Returns the prefixes to be used by the line-shift operation. This implementation
- * always returns <code>new String[] { "\t", " " }</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type for which the prefix is applicable
- * @return the prefixes or <code>null</code> if the prefix operation should not be supported
- */
- public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) {
- return new String[] { "\t", " ", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- /**
- * Returns the annotation hover which will provide the information to be
- * shown in a hover popup window when requested for the given
- * source viewer.This implementation always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return an annotation hover or <code>null</code> if no hover support should be installed
- */
- public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) {
- return null;
- }
-
- /**
- * Returns the annotation hover which will provide the information to be
- * shown in a hover popup window when requested for the overview ruler
- * of the given source viewer.This implementation always returns the general
- * annotation hover returned by <code>getAnnotationHover</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return an annotation hover or <code>null</code> if no hover support should be installed
- * @since 3.0
- */
- public IAnnotationHover getOverviewRulerAnnotationHover(ISourceViewer sourceViewer) {
- return getAnnotationHover(sourceViewer);
- }
-
- /**
- * Returns the SWT event state masks for which text hover are configured for
- * the given content type.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type
- * @return an <code>int</code> array with the configured SWT event state masks
- * or <code>null</code> if text hovers are not supported for the given content type
- * @since 2.1
- */
- public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) {
- return null;
- }
-
- /**
- * Returns the text hover which will provide the information to be shown
- * in a text hover popup window when requested for the given source viewer and
- * the given content type. This implementation always returns <code>
- * null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type
- * @param stateMask the SWT event state mask
- * @return a text hover or <code>null</code> if no hover support should be installed
- * @since 2.1
- */
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) {
- return null;
- }
-
- /**
- * Returns the text hover which will provide the information to be shown
- * in a text hover popup window when requested for the given source viewer and
- * the given content type. This implementation always returns <code>
- * null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @param contentType the content type
- * @return a text hover or <code>null</code> if no hover support should be installed
- */
- public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) {
- return null;
- }
-
- /**
- * Returns the information control creator. The creator is a factory creating information
- * controls for the given source viewer. This implementation always returns a creator for
- * <code>DefaultInformationControl</code> instances.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return the information control creator or <code>null</code> if no information support should be installed
- * @since 2.0
- */
- public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) {
- return new IInformationControlCreator() {
- public IInformationControl createInformationControl(Shell parent) {
- return new DefaultInformationControl(parent);
- }
- };
- }
-
- /**
- * Returns the information presenter which will determine and shown
- * information requested for the current cursor position. This implementation
- * always returns <code>null</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return an information presenter <code>null</code> if no information presenter should be installed
- * @since 2.0
- */
- public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
- return null;
- }
-
- /**
- * Returns all configured content types for the given source viewer. This list
- * tells the caller which content types must be configured for the given source
- * viewer, i.e. for which content types the given source viewer's functionalities
- * must be specified. This implementation always returns <code>
- * new String[] { IDocument.DEFAULT_CONTENT_TYPE }</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return the configured content types for the given viewer
- */
- public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
- return new String[] { IDocument.DEFAULT_CONTENT_TYPE };
- }
-
- /**
- * Returns the configured partitioning for the given source viewer. The partitioning is
- * used when the querying content types from the source viewer's input document. This
- * implementation always returns <code>IDocumentExtension3.DEFAULT_PARTITIONING</code>.
- *
- * @param sourceViewer the source viewer to be configured by this configuration
- * @return the configured partitioning
- * @see #getConfiguredContentTypes(ISourceViewer)
- * @since 3.0
- */
- public String getConfiguredDocumentPartitioning(ISourceViewer sourceViewer) {
- return IDocumentExtension3.DEFAULT_PARTITIONING;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
deleted file mode 100644
index 4f91520a741..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRuler.java
+++ /dev/null
@@ -1,588 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-
-
-import java.util.Iterator;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.custom.StyledText;
-import org.eclipse.swt.events.DisposeEvent;
-import org.eclipse.swt.events.DisposeListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
-import org.eclipse.swt.events.PaintEvent;
-import org.eclipse.swt.events.PaintListener;
-import org.eclipse.swt.graphics.Font;
-import org.eclipse.swt.graphics.GC;
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.Rectangle;
-import org.eclipse.swt.widgets.Canvas;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextListener;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.ITextViewerExtension5;
-import org.eclipse.jface.text.IViewportListener;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.TextEvent;
-
-
-/**
- * A vertical ruler which is connected to a text viewer. Single column standard
- * implementation of <code>IVerticalRuler</code>. The same can be achieved by
- * using <code>CompositeRuler</code> configured with an <code>AnnotationRulerColumn</code>.
- * Clients may use this class as is.
- *
- * @see ITextViewer
- */
-public final class VerticalRuler implements IVerticalRuler, IVerticalRulerExtension {
-
- /**
- * Internal listener class.
- */
- class InternalListener implements IViewportListener, IAnnotationModelListener, ITextListener {
-
- /*
- * @see IViewportListener#viewportChanged(int)
- */
- public void viewportChanged(int verticalPosition) {
- if (verticalPosition != fScrollPos)
- redraw();
- }
-
- /*
- * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- update();
- }
-
- /*
- * @see ITextListener#textChanged(TextEvent)
- */
- public void textChanged(TextEvent e) {
- if (fTextViewer != null && e.getViewerRedrawState())
- redraw();
- }
- }
-
- /** The vertical ruler's text viewer */
- private ITextViewer fTextViewer;
- /** The ruler's canvas */
- private Canvas fCanvas;
- /** The vertical ruler's model */
- private IAnnotationModel fModel;
- /** Cache for the actual scroll position in pixels */
- private int fScrollPos;
- /** The drawable for double buffering */
- private Image fBuffer;
- /** The line of the last mouse button activity */
- private int fLastMouseButtonActivityLine= -1;
- /** The internal listener */
- private InternalListener fInternalListener= new InternalListener();
- /** The width of this vertical ruler */
- private int fWidth;
- /**
- * The annotation access of this vertical ruler
- * @since 3.0
- */
- private IAnnotationAccess fAnnotationAccess;
-
- /**
- * Constructs a vertical ruler with the given width.
- *
- * @param width the width of the vertical ruler
- */
- public VerticalRuler(int width) {
- this(width, null);
- }
-
- /**
- * Constructs a vertical ruler with the given width and the given annotation
- * access.
- *
- * @param width the width of the vertical ruler
- * @param annotationAcccess the annotation access
- * @since 3.0
- */
- public VerticalRuler(int width, IAnnotationAccess annotationAcccess) {
- fWidth= width;
- fAnnotationAccess= annotationAcccess;
- }
-
- /*
- * @see IVerticalRuler#getControl()
- */
- public Control getControl() {
- return fCanvas;
- }
-
- /*
- * @see IVerticalRuler#createControl(Composite, ITextViewer)
- */
- public Control createControl(Composite parent, ITextViewer textViewer) {
-
- fTextViewer= textViewer;
-
- fCanvas= new Canvas(parent, SWT.NO_BACKGROUND);
-
- fCanvas.addPaintListener(new PaintListener() {
- public void paintControl(PaintEvent event) {
- if (fTextViewer != null)
- doubleBufferPaint(event.gc);
- }
- });
-
- fCanvas.addDisposeListener(new DisposeListener() {
- public void widgetDisposed(DisposeEvent e) {
- handleDispose();
- fTextViewer= null;
- }
- });
-
- fCanvas.addMouseListener(new MouseListener() {
- public void mouseUp(MouseEvent event) {
- }
-
- public void mouseDown(MouseEvent event) {
- fLastMouseButtonActivityLine= toDocumentLineNumber(event.y);
- }
-
- public void mouseDoubleClick(MouseEvent event) {
- fLastMouseButtonActivityLine= toDocumentLineNumber(event.y);
- }
- });
-
- if (fTextViewer != null) {
- fTextViewer.addViewportListener(fInternalListener);
- fTextViewer.addTextListener(fInternalListener);
- }
-
- return fCanvas;
- }
-
- /**
- * Disposes the ruler's resources.
- */
- private void handleDispose() {
-
- if (fTextViewer != null) {
- fTextViewer.removeViewportListener(fInternalListener);
- fTextViewer.removeTextListener(fInternalListener);
- fTextViewer= null;
- }
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- if (fBuffer != null) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
-
-
- /**
- * Double buffer drawing.
- *
- * @param dest the GC to draw into
- */
- private void doubleBufferPaint(GC dest) {
-
- Point size= fCanvas.getSize();
-
- if (size.x <= 0 || size.y <= 0)
- return;
-
- if (fBuffer != null) {
- Rectangle r= fBuffer.getBounds();
- if (r.width != size.x || r.height != size.y) {
- fBuffer.dispose();
- fBuffer= null;
- }
- }
- if (fBuffer == null)
- fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y);
-
- GC gc= new GC(fBuffer);
- gc.setFont(fTextViewer.getTextWidget().getFont());
- try {
- gc.setBackground(fCanvas.getBackground());
- gc.fillRectangle(0, 0, size.x, size.y);
-
- if (fTextViewer instanceof ITextViewerExtension5)
- doPaint1(gc);
- else
- doPaint(gc);
-
- } finally {
- gc.dispose();
- }
-
- dest.drawImage(fBuffer, 0, 0);
- }
-
- /**
- * Returns the document offset of the upper left corner of the
- * widgets viewport, possibly including partially visible lines.
- *
- * @return the document offset of the upper left corner including partially visible lines
- * @since 2.0
- */
- private int getInclusiveTopIndexStartOffset() {
-
- StyledText textWidget= fTextViewer.getTextWidget();
- if (textWidget != null && !textWidget.isDisposed()) {
- int top= -1;
- if (fTextViewer instanceof ITextViewerExtension5) {
- top= textWidget.getTopIndex();
- if ((textWidget.getTopPixel() % textWidget.getLineHeight()) != 0)
- top--;
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- top= extension.widgetLine2ModelLine(top);
- } else {
- top= fTextViewer.getTopIndex();
- if ((textWidget.getTopPixel() % textWidget.getLineHeight()) != 0)
- top--;
- }
-
- try {
- IDocument document= fTextViewer.getDocument();
- return document.getLineOffset(top);
- } catch (BadLocationException x) {
- }
- }
-
- return -1;
- }
-
-
-
- /**
- * Draws the vertical ruler w/o drawing the Canvas background.
- *
- * @param gc the GC to draw into
- */
- protected void doPaint(GC gc) {
-
- if (fModel == null || fTextViewer == null)
- return;
-
- IAnnotationAccessExtension annotationAccessExtension= null;
- if (fAnnotationAccess instanceof IAnnotationAccessExtension)
- annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
-
- StyledText styledText= fTextViewer.getTextWidget();
- IDocument doc= fTextViewer.getDocument();
-
- int topLeft= getInclusiveTopIndexStartOffset();
- int bottomRight= fTextViewer.getBottomIndexEndOffset();
- int viewPort= bottomRight - topLeft;
-
- Point d= fCanvas.getSize();
- fScrollPos= styledText.getTopPixel();
- int lineheight= styledText.getLineHeight();
-
- int shift= fTextViewer.getTopInset();
-
- int topLine= -1, bottomLine= -1;
- try {
- IRegion region= fTextViewer.getVisibleRegion();
- topLine= doc.getLineOfOffset(region.getOffset());
- bottomLine= doc.getLineOfOffset(region.getOffset() + region.getLength());
- } catch (BadLocationException x) {
- return;
- }
-
- // draw Annotations
- Rectangle r= new Rectangle(0, 0, 0, 0);
- int maxLayer= 1; // loop at least once though layers.
-
- for (int layer= 0; layer < maxLayer; layer++) {
- Iterator iter= fModel.getAnnotationIterator();
- while (iter.hasNext()) {
- Annotation annotation= (Annotation) iter.next();
-
- int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
- if (annotationAccessExtension != null)
- lay= annotationAccessExtension.getLayer(annotation);
- maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
- if (lay != layer) // wrong layer: skip annotation
- continue;
-
- Position position= fModel.getPosition(annotation);
- if (position == null)
- continue;
-
- if (!position.overlapsWith(topLeft, viewPort))
- continue;
-
- try {
-
- int offset= position.getOffset();
- int length= position.getLength();
-
- int startLine= doc.getLineOfOffset(offset);
- if (startLine < topLine)
- startLine= topLine;
-
- int endLine= startLine;
- if (length > 0)
- endLine= doc.getLineOfOffset(offset + length - 1);
- if (endLine > bottomLine)
- endLine= bottomLine;
-
- startLine -= topLine;
- endLine -= topLine;
-
- r.x= 0;
- r.y= (startLine * lineheight) - fScrollPos + shift;
- r.width= d.x;
- int lines= endLine - startLine;
- if (lines < 0)
- lines= -lines;
- r.height= (lines+1) * lineheight;
-
- if (r.y < d.y && annotationAccessExtension != null) // annotation within visible area
- annotationAccessExtension.paint(annotation, gc, fCanvas, r);
-
- } catch (BadLocationException e) {
- }
- }
- }
- }
-
- /**
- * Draws the vertical ruler w/o drawing the Canvas background. Uses
- * <code>ITextViewerExtension5</code> for its implementation. Will replace
- * <code>doPaint(GC)</code>.
- *
- * @param gc the GC to draw into
- */
- protected void doPaint1(GC gc) {
-
- if (fModel == null || fTextViewer == null)
- return;
-
- IAnnotationAccessExtension annotationAccessExtension= null;
- if (fAnnotationAccess instanceof IAnnotationAccessExtension)
- annotationAccessExtension= (IAnnotationAccessExtension) fAnnotationAccess;
-
- ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer;
- StyledText textWidget= fTextViewer.getTextWidget();
-
- fScrollPos= textWidget.getTopPixel();
- int lineheight= textWidget.getLineHeight();
- Point dimension= fCanvas.getSize();
- int shift= fTextViewer.getTopInset();
-
- // draw Annotations
- Rectangle r= new Rectangle(0, 0, 0, 0);
- int maxLayer= 1; // loop at least once through layers.
-
- for (int layer= 0; layer < maxLayer; layer++) {
- Iterator iter= fModel.getAnnotationIterator();
- while (iter.hasNext()) {
- Annotation annotation= (Annotation) iter.next();
-
- int lay= IAnnotationAccessExtension.DEFAULT_LAYER;
- if (annotationAccessExtension != null)
- lay= annotationAccessExtension.getLayer(annotation);
- maxLayer= Math.max(maxLayer, lay+1); // dynamically update layer maximum
- if (lay != layer) // wrong layer: skip annotation
- continue;
-
- Position position= fModel.getPosition(annotation);
- if (position == null)
- continue;
-
- IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(position.getOffset(), position.getLength()));
- if (widgetRegion == null)
- continue;
-
- int startLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset());
- if (startLine == -1)
- continue;
-
- int endLine= extension.widgetLineOfWidgetOffset(widgetRegion.getOffset() + Math.max(widgetRegion.getLength() -1, 0));
- if (endLine == -1)
- continue;
-
- r.x= 0;
- r.y= (startLine * lineheight) - fScrollPos + shift;
- r.width= dimension.x;
- int lines= endLine - startLine;
- if (lines < 0)
- lines= -lines;
- r.height= (lines+1) * lineheight;
-
- if (r.y < dimension.y && annotationAccessExtension != null) // annotation within visible area
- annotationAccessExtension.paint(annotation, gc, fCanvas, r);
- }
- }
- }
-
- /**
- * Thread-safe implementation.
- * Can be called from any thread.
- */
- /*
- * @see IVerticalRuler#update()
- */
- public void update() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- Display d= fCanvas.getDisplay();
- if (d != null) {
- d.asyncExec(new Runnable() {
- public void run() {
- redraw();
- }
- });
- }
- }
- }
-
- /**
- * Redraws the vertical ruler.
- */
- private void redraw() {
- if (fCanvas != null && !fCanvas.isDisposed()) {
- GC gc= new GC(fCanvas);
- doubleBufferPaint(gc);
- gc.dispose();
- }
- }
-
- /*
- * @see IVerticalRuler#setModel(IAnnotationModel)
- */
- public void setModel(IAnnotationModel model) {
- if (model != fModel) {
-
- if (fModel != null)
- fModel.removeAnnotationModelListener(fInternalListener);
-
- fModel= model;
-
- if (fModel != null)
- fModel.addAnnotationModelListener(fInternalListener);
-
- update();
- }
- }
-
- /*
- * @see IVerticalRuler#getModel()
- */
- public IAnnotationModel getModel() {
- return fModel;
- }
-
- /*
- * @see IVerticalRulerInfo#getWidth()
- */
- public int getWidth() {
- return fWidth;
- }
-
- /*
- * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity()
- */
- public int getLineOfLastMouseButtonActivity() {
- return fLastMouseButtonActivityLine;
- }
-
- /*
- * @see IVerticalRulerInfo#toDocumentLineNumber(int)
- */
- public int toDocumentLineNumber(int y_coordinate) {
-
- if (fTextViewer == null)
- return -1;
-
- StyledText text= fTextViewer.getTextWidget();
- int line= ((y_coordinate + fScrollPos) / text.getLineHeight());
- return widgetLine2ModelLine(fTextViewer, line);
- }
-
- /**
- * Returns the line of the viewer's document that corresponds to the given widget line.
- *
- * @param viewer the viewer
- * @param widgetLine the widget line
- * @return the corresponding line of the viewer's document
- * @since 2.1
- */
- protected final static int widgetLine2ModelLine(ITextViewer viewer, int widgetLine) {
-
- if (viewer instanceof ITextViewerExtension5) {
- ITextViewerExtension5 extension= (ITextViewerExtension5) viewer;
- return extension.widgetLine2ModelLine(widgetLine);
- }
-
- try {
- IRegion r= viewer.getVisibleRegion();
- IDocument d= viewer.getDocument();
- return widgetLine += d.getLineOfOffset(r.getOffset());
- } catch (BadLocationException x) {
- }
- return widgetLine;
- }
-
- /*
- * @see IVerticalRulerExtension#setFont(Font)
- * @since 2.0
- */
- public void setFont(Font font) {
- }
-
- /*
- * @see IVerticalRulerExtension#setLocationOfLastMouseButtonActivity(int, int)
- * @since 2.0
- */
- public void setLocationOfLastMouseButtonActivity(int x, int y) {
- fLastMouseButtonActivityLine= toDocumentLineNumber(y);
- }
-
- /**
- * Adds the given mouse listener.
- *
- * @param listener the listener to be added
- * @deprecated will be removed
- * @since 2.0
- */
- public void addMouseListener(MouseListener listener) {
- if (fCanvas != null && !fCanvas.isDisposed())
- fCanvas.addMouseListener(listener);
- }
-
- /**
- * Removes the given mouse listener.
- *
- * @param listener the listener to be removed
- * @deprecated will be removed
- * @since 2.0
- */
- public void removeMouseListener(MouseListener listener) {
- if (fCanvas != null && !fCanvas.isDisposed())
- fCanvas.removeMouseListener(listener);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRulerEvent.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRulerEvent.java
deleted file mode 100644
index d134940ade1..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VerticalRulerEvent.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-/**
- * An event sent to {@link org.eclipse.jface.text.source.IVerticalRulerListener} instances when annotation
- * related event occurs on the vertical ruler.
- *
- * @since 3.0
- */
-public class VerticalRulerEvent {
-
- private Annotation fAnnotation;
-
- /**
- * Creates a new event.
- *
- * @param annotation the annotation concerned, or <code>null</code>
- */
- public VerticalRulerEvent(Annotation annotation) {
- fAnnotation= annotation;
- }
-
- /**
- * @return the concerned annotation or <code>null</code>
- */
- public Annotation getSelectedAnnotation() {
- return fAnnotation;
- }
-
- /**
- * @param annotation the concerned annotation, or <code>null</code>
- */
- public void setSelectedAnnotation(Annotation annotation) {
- fAnnotation= annotation;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
deleted file mode 100644
index 7c160f2b3e9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/VisualAnnotationModel.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.source;
-
-
-
-
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.Position;
-
-
-
-/**
- * Annotation model for visual annotations. Assume a viewer's input element is annotated with
- * some semantic annotation such as a breakpoint and that it is simultanously shown in multiple
- * viewers. A source viewer, e.g., supports visual range indication for which it utilizes
- * annotations. The range indicating annotation is specific to the visual presentation
- * of the input element in this viewer and thus should only be visible in this viewer. The
- * breakpoints however are independent from the input element's presentation and thus should
- * be shown in all viewers in which the element is shown. As a viewer supports one vertical
- * ruler which is based on one annotation model, there must be a visual annotation model for
- * each viewer which all wrap the same element specific model annotation model.
- */
-class VisualAnnotationModel extends AnnotationModel implements IAnnotationModelListener {
-
- /** The wrapped model annotation model */
- private IAnnotationModel fModel;
-
- /**
- * Constructs a visual annotation model which wraps the given
- * model based annotation model
- *
- * @param modelAnnotationModel the model based annotation model
- */
- public VisualAnnotationModel(IAnnotationModel modelAnnotationModel) {
- fModel= modelAnnotationModel;
- }
-
- /**
- * Returns the visual annotation model's wrapped model based annotation model.
- *
- * @return the model based annotation model
- */
- public IAnnotationModel getModelAnnotationModel() {
- return fModel;
- }
-
- /*
- * @see IAnnotationModel#addAnnotationModelListener(IAnnotationModelListener)
- */
- public void addAnnotationModelListener(IAnnotationModelListener listener) {
-
- if (fModel != null && fAnnotationModelListeners.isEmpty())
- fModel.addAnnotationModelListener(this);
-
- super.addAnnotationModelListener(listener);
- }
-
- /*
- * @see IAnnotationModel#connect(IDocument)
- */
- public void connect(IDocument document) {
- super.connect(document);
- if (fModel != null)
- fModel.connect(document);
- }
-
- /*
- * @see IAnnotationModel#disconnect(IDocument)
- */
- public void disconnect(IDocument document) {
- super.disconnect(document);
- if (fModel != null)
- fModel.disconnect(document);
- }
-
- /*
- * @see IAnnotationModel#getAnnotationIterator()
- */
- public Iterator getAnnotationIterator() {
-
- if (fModel == null)
- return super.getAnnotationIterator();
-
- ArrayList a= new ArrayList(20);
-
- Iterator e= fModel.getAnnotationIterator();
- while (e.hasNext())
- a.add(e.next());
-
- e= super.getAnnotationIterator();
- while (e.hasNext())
- a.add(e.next());
-
- return a.iterator();
- }
-
- /*
- * @see IAnnotationModel#getPosition(Annotation)
- */
- public Position getPosition(Annotation annotation) {
-
- Position p= (Position) getAnnotationMap().get(annotation);
- if (p != null)
- return p;
-
- if (fModel != null)
- return fModel.getPosition(annotation);
-
- return null;
- }
-
- /*
- * @see IAnnotationModelListener#modelChanged(IAnnotationModel)
- */
- public void modelChanged(IAnnotationModel model) {
- if (model == fModel) {
- Iterator iter= new ArrayList(fAnnotationModelListeners).iterator();
- while (iter.hasNext()) {
- IAnnotationModelListener l= (IAnnotationModelListener)iter.next();
- l.modelChanged(this);
- }
- }
- }
-
- /*
- * @see IAnnotationModel#removeAnnotationModelListener(IAnnotationModelListener)
- */
- public void removeAnnotationModelListener(IAnnotationModelListener listener) {
- super.removeAnnotationModelListener(listener);
-
- if (fModel != null && fAnnotationModelListeners.isEmpty())
- fModel.removeAnnotationModelListener(this);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/source/package.html
deleted file mode 100644
index e03b1940302..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/source/package.html
+++ /dev/null
@@ -1,26 +0,0 @@
-<!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="Author" content="IBM">
- <meta name="GENERATOR" content="Mozilla/4.51 [en] (WinNT; I) [Netscape]">
- <title>Package-level Javadoc</title>
-</head>
-<body>
-Provides a framework for connecting document regions
-with annotations and for displaying those annotations in combination with
-an <tt>ITextViewer</tt>. <tt>ISourceViewer</tt> combines annotation support
-and all text viewer add-ons.
-<h2>
-Package Specification</h2>
-&nbsp;<tt>ISourceViewer</tt> defines the concept of a document based, editable
-viewer supporting visual annotations. <tt>ISourceViewer</tt> supports document-specific
-and viewer-specific annotations attached to the viewer's input document.
-An <tt>ISourceViewer</tt> uses an <tt>IAnnotationModel</tt> to manage annotations
-and to inform implementers of <tt>IAnnotationModelListener</tt> about changes
-in respect to annotations. An <tt>IVerticalRuler</tt> represents an <tt>IAnnotationModel</tt>
-access adapter for an SWT widget capapble of display annotations.&nbsp;
-This package also provides default implementations for all defined interfaces.
-<br>&nbsp;
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java
deleted file mode 100644
index 6ce4c27a86c..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/ContextTypeRegistry.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-/**
- * A registry for context types. Editor implementors will usually instantiate a
- * registry and configure the context types available in their editor.
- *
- * @since 3.0
- */
-public class ContextTypeRegistry {
-
- /** all known context types */
- private final Map fContextTypes= new HashMap();
-
- /**
- * Adds a context type to the registry.
- *
- * @param contextType the context type to add
- */
- public void addContextType(TemplateContextType contextType) {
- fContextTypes.put(contextType.getId(), contextType);
- }
-
- /**
- * Returns the context type if the id is valid, <code>null</code> otherwise.
- *
- * @param id the id of the context type to retrieve
- * @return the context type if <code>name</code> is valid, <code>null</code> otherwise
- */
- public TemplateContextType getContextType(String id) {
- return (TemplateContextType) fContextTypes.get(id);
- }
-
- /**
- * Returns an iterator over all registered context types.
- *
- * @return an iterator over all registered context types
- */
- public Iterator contextTypes() {
- return fContextTypes.values().iterator();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java
deleted file mode 100644
index 6cfc0512158..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/InclusivePositionUpdater.java
+++ /dev/null
@@ -1,103 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IPositionUpdater;
-import org.eclipse.jface.text.Position;
-
-/**
- * Position updater that takes any change in [position.offset, position.offset + position.length] as
- * belonging to the position.
- *
- * @since 3.0
- */
-class InclusivePositionUpdater implements IPositionUpdater {
-
- /** The position category. */
- private final String fCategory;
-
- /**
- * Creates a new updater for the given <code>category</code>.
- *
- * @param category the new category.
- */
- public InclusivePositionUpdater(String category) {
- fCategory= category;
- }
-
- /*
- * @see org.eclipse.jface.text.IPositionUpdater#update(org.eclipse.jface.text.DocumentEvent)
- */
- public void update(DocumentEvent event) {
-
- int eventOffset= event.getOffset();
- int eventOldLength= event.getLength();
- int eventNewLength= event.getText() == null ? 0 : event.getText().length();
- int deltaLength= eventNewLength - eventOldLength;
-
- try {
- Position[] positions= event.getDocument().getPositions(fCategory);
-
- for (int i= 0; i != positions.length; i++) {
-
- Position position= positions[i];
-
- if (position.isDeleted())
- continue;
-
- int offset= position.getOffset();
- int length= position.getLength();
- int end= offset + length;
-
- if (offset > eventOffset + eventOldLength)
- // position comes way
- // after change - shift
- position.setOffset(offset + deltaLength);
- else if (end < eventOffset) {
- // position comes way before change -
- // leave alone
- } else if (offset <= eventOffset && end >= eventOffset + eventOldLength) {
- // event completely internal to the position - adjust length
- position.setLength(length + deltaLength);
- } else if (offset < eventOffset) {
- // event extends over end of position - adjust length
- int newEnd= eventOffset + eventNewLength;
- position.setLength(newEnd - offset);
- } else if (end > eventOffset + eventOldLength) {
- // event extends from before position into it - adjust offset
- // and length
- // offset becomes end of event, length ajusted acordingly
- // we want to recycle the overlapping part
- position.setOffset(eventOffset);
- int deleted= eventOffset + eventOldLength - offset;
- position.setLength(length - deleted + eventNewLength);
- } else {
- // event consumes the position - delete it
- position.delete();
- }
- }
- } catch (BadPositionCategoryException e) {
- // ignore and return
- }
- }
-
- /**
- * Returns the position category.
- *
- * @return the position category
- */
- public String getCategory() {
- return fCategory;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java
deleted file mode 100644
index 5d63874d1e5..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 3.0
- */
-class JFaceTextTemplateMessages {
-
- private static final String RESOURCE_BUNDLE= JFaceTextTemplateMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private JFaceTextTemplateMessages() {
- }
-
- /**
- * @param key
- * @return
- */
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the argument
- *
- * @param key the string used to get the bundle value, must not be null
- * @param arg
- * @return
- */
- public static String getFormattedString(String key, Object arg) {
- return MessageFormat.format(getString(key), new Object[] { arg });
- }
-
-
- /**
- * Gets a string from the resource bundle and formats it with arguments
- * @param key
- * @param args
- * @return
- */
- public static String getFormattedString(String key, Object[] args) {
- return MessageFormat.format(getString(key), args);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties
deleted file mode 100644
index 6fa3272a684..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/JFaceTextTemplateMessages.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-
-# template proposal
-TemplateProposal.delimiter=\ -
-TemplateProposal.errorDialog.title=Template Evaluation Error
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java
deleted file mode 100644
index 6213f6226e3..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/PositionBasedCompletionProposal.java
+++ /dev/null
@@ -1,168 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-
-package org.eclipse.jface.text.templates;
-
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-
-
-/**
- * An enhanced implementation of the <code>ICompletionProposal</code> interface implementing all the extension interfaces.
- *
- * @since 3.0
- */
-final class PositionBasedCompletionProposal implements ICompletionProposal, ICompletionProposalExtension2 {
-
- /** The string to be displayed in the completion proposal popup */
- private String fDisplayString;
- /** The replacement string */
- private String fReplacementString;
- /** The replacement position. */
- private Position fReplacementPosition;
- /** The cursor position after this proposal has been applied */
- private int fCursorPosition;
- /** The image to be displayed in the completion proposal popup */
- private Image fImage;
- /** The context information of this proposal */
- private IContextInformation fContextInformation;
- /** The additional info of this proposal */
- private String fAdditionalProposalInfo;
-
- /**
- * Creates a new completion proposal based on the provided information. The replacement string is
- * considered being the display string too. All remaining fields are set to <code>null</code>.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementPosition the position of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- */
- public PositionBasedCompletionProposal(String replacementString, Position replacementPosition, int cursorPosition) {
- this(replacementString, replacementPosition, cursorPosition, null, null, null, null);
- }
-
- /**
- * Creates a new completion proposal. All fields are initialized based on the provided information.
- *
- * @param replacementString the actual string to be inserted into the document
- * @param replacementPosition the position of the text to be replaced
- * @param cursorPosition the position of the cursor following the insert relative to replacementOffset
- * @param image the image to display for this proposal
- * @param displayString the string to be displayed for the proposal
- * @param contextInformation the context information associated with this proposal
- * @param additionalProposalInfo the additional information associated with this proposal
- */
- public PositionBasedCompletionProposal(String replacementString, Position replacementPosition, int cursorPosition, Image image, String displayString, IContextInformation contextInformation, String additionalProposalInfo) {
- Assert.isNotNull(replacementString);
- Assert.isTrue(replacementPosition != null);
-
- fReplacementString= replacementString;
- fReplacementPosition= replacementPosition;
- fCursorPosition= cursorPosition;
- fImage= image;
- fDisplayString= displayString;
- fContextInformation= contextInformation;
- fAdditionalProposalInfo= additionalProposalInfo;
- }
-
- /*
- * @see ICompletionProposal#apply(IDocument)
- */
- public void apply(IDocument document) {
- try {
- document.replace(fReplacementPosition.getOffset(), fReplacementPosition.getLength(), fReplacementString);
- } catch (BadLocationException x) {
- // ignore
- }
- }
-
- /*
- * @see ICompletionProposal#getSelection(IDocument)
- */
- public Point getSelection(IDocument document) {
- return new Point(fReplacementPosition.getOffset() + fCursorPosition, 0);
- }
-
- /*
- * @see ICompletionProposal#getContextInformation()
- */
- public IContextInformation getContextInformation() {
- return fContextInformation;
- }
-
- /*
- * @see ICompletionProposal#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposal#getDisplayString()
- */
- public String getDisplayString() {
- if (fDisplayString != null)
- return fDisplayString;
- return fReplacementString;
- }
-
- /*
- * @see ICompletionProposal#getAdditionalProposalInfo()
- */
- public String getAdditionalProposalInfo() {
- return fAdditionalProposalInfo;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
- */
- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
- apply(viewer.getDocument());
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
- */
- public void selected(ITextViewer viewer, boolean smartToggle) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
- */
- public void unselected(ITextViewer viewer) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
- */
- public boolean validate(IDocument document, int offset, DocumentEvent event) {
- try {
- String content= document.get(fReplacementPosition.getOffset(), fReplacementPosition.getLength());
- if (content.startsWith(fReplacementString))
- return true;
- } catch (BadLocationException e) {
- // ignore concurrently modified document
- }
- return false;
- }
-
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java
deleted file mode 100644
index f247354b0bd..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateCompletionProcessor.java
+++ /dev/null
@@ -1,228 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-
-import org.eclipse.swt.graphics.Image;
-
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Region;
-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;
-
-
-/**
- * A completion processor that computes template proposals.
- *
- * @since 3.0
- */
-public abstract class TemplateCompletionProcessor implements IContentAssistProcessor {
-
- private static final class ProposalComparator implements Comparator {
- public int compare(Object o1, Object o2) {
- return ((TemplateProposal) o2).getRelevance() - ((TemplateProposal) o1).getRelevance();
- }
- }
-
- private static final Comparator fgProposalComparator= new ProposalComparator();
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeCompletionProposals(org.eclipse.jface.text.ITextViewer,
- * int)
- */
- public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) {
-
- ITextSelection selection= (ITextSelection) viewer.getSelectionProvider().getSelection();
-
- // adjust offset to end of normalized selection
- if (selection.getOffset() == offset)
- offset= selection.getOffset() + selection.getLength();
-
- String prefix= extractPrefix(viewer, offset);
- Region region= new Region(offset - prefix.length(), prefix.length());
- TemplateContext context= createContext(viewer, region);
- if (context == null)
- return new ICompletionProposal[0];
-
- context.setVariable("selection", selection.getText()); // name of the selection variables {line, word}_selection //$NON-NLS-1$
-
- Template[] templates= getTemplates(context.getContextType().getId());
-
- List matches= new ArrayList();
- for (int i= 0; i < templates.length; i++) {
- Template template= templates[i];
- try {
- context.getContextType().validate(template.getPattern());
- } catch (TemplateException e) {
- continue;
- }
- if (template.matches(prefix, context.getContextType().getId()))
- matches.add(createProposal(template, context, region, getRelevance(template, prefix)));
- }
-
- Collections.sort(matches, fgProposalComparator);
-
- return (ICompletionProposal[]) matches.toArray(new ICompletionProposal[matches.size()]);
- }
-
- /**
- * Creates a new proposal.
- * <p>
- * The default implementation returns an instance of
- * {@link TemplateProposal}. Subclasses may override to provide their own
- * implementations.
- * </p>
- *
- * @param template the template to be applied by the proposal
- * @param context the context for the proposal
- * @param region the region the proposal applies to
- * @param relevance the relevance of the proposal
- * @return a new <code>ICompletionProposal</code> for <code>template</code>
- */
- protected ICompletionProposal createProposal(Template template, TemplateContext context, Region region, int relevance) {
- return new TemplateProposal(template, context, region, getImage(template), relevance);
- }
-
- /**
- * Returns the templates valid for the context type specified by <code>contextTypeId</code>.
- *
- * @param contextTypeId the context type id
- * @return the templates valid for this context type id
- */
- protected abstract Template[] getTemplates(String contextTypeId);
-
- /**
- * Creates a concrete template context for the given region in the document. This involves finding out which
- * context type is valid at the given location, and then creating a context of this type. The default implementation
- * returns a <code>DocumentTemplateContext</code> for the context type at the given location.
- *
- * @param viewer the viewer for which the context is created
- * @param region the region into <code>document</code> for which the context is created
- * @return a template context that can handle template insertion at the given location, or <code>null</code>
- */
- protected TemplateContext createContext(ITextViewer viewer, IRegion region) {
- TemplateContextType contextType= getContextType(viewer, region);
- if (contextType != null) {
- IDocument document= viewer.getDocument();
- return new DocumentTemplateContext(contextType, document, region.getOffset(), region.getLength());
- }
- return null;
- }
-
- /**
- * Returns the context type that can handle template insertion at the given region
- * in the viewer's document.
- *
- * @param viewer the text viewer
- * @param region the region into the document displayed by viewer
- * @return the context type that can handle template expansion for the given location, or <code>null</code> if none exists
- */
- protected abstract TemplateContextType getContextType(ITextViewer viewer, IRegion region);
-
- /**
- * Returns the relevance of a template given a prefix. The default
- * implementation returns a number greater than zero if the template name
- * starts with the prefix, and zero otherwise.
- *
- * @param template the template to compute the relevance for
- * @param prefix the prefix after which content assist was requested
- * @return the relevance of <code>template</code>
- * @see #extractPrefix(ITextViewer, int)
- */
- protected int getRelevance(Template template, String prefix) {
- if (template.getName().startsWith(prefix))
- return 90;
- return 0;
- }
-
- /**
- * Heuristically extracts the prefix used for determining template relevance
- * from the viewer's document. The default implementation returns the String from
- * offset backwards that forms a java identifier.
- *
- * @param viewer the viewer
- * @param offset offset into document
- * @return the prefix to consider
- * @see #getRelevance(Template, String)
- */
- protected String extractPrefix(ITextViewer viewer, int offset) {
- int i= offset;
- IDocument document= viewer.getDocument();
- if (i > document.getLength())
- return ""; //$NON-NLS-1$
-
- try {
- while (i > 0) {
- char ch= document.getChar(i - 1);
- if (!Character.isJavaIdentifierPart(ch))
- break;
- i--;
- }
-
- return document.get(i, offset - i);
- } catch (BadLocationException e) {
- return ""; //$NON-NLS-1$
- }
- }
-
- /**
- * Returns the image to be used for the proposal for <code>template</code>.
- *
- * @param template the template for which an image should be returned
- * @return the image for <code>template</code>
- */
- protected abstract Image getImage(Template template);
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#computeContextInformation(org.eclipse.jface.text.ITextViewer, int)
- */
- public IContextInformation[] computeContextInformation(ITextViewer viewer, int documentOffset) {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getCompletionProposalAutoActivationCharacters()
- */
- public char[] getCompletionProposalAutoActivationCharacters() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationAutoActivationCharacters()
- */
- public char[] getContextInformationAutoActivationCharacters() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getErrorMessage()
- */
- public String getErrorMessage() {
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.IContentAssistProcessor#getContextInformationValidator()
- */
- public IContextInformationValidator getContextInformationValidator() {
- return null;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
deleted file mode 100644
index 0ff9f82d33b..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/TemplateProposal.java
+++ /dev/null
@@ -1,408 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates;
-
-import org.eclipse.swt.graphics.Image;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.widgets.Shell;
-
-import org.eclipse.jface.dialogs.MessageDialog;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.BadLocationException;
-import org.eclipse.jface.text.BadPositionCategoryException;
-import org.eclipse.jface.text.DocumentEvent;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IInformationControlCreator;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.jface.text.ITextViewer;
-import org.eclipse.jface.text.Position;
-import org.eclipse.jface.text.Region;
-import org.eclipse.jface.text.contentassist.ICompletionProposal;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension2;
-import org.eclipse.jface.text.contentassist.ICompletionProposalExtension3;
-import org.eclipse.jface.text.contentassist.IContextInformation;
-import org.eclipse.jface.text.link.ILinkedModeListener;
-import org.eclipse.jface.text.link.LinkedModeModel;
-import org.eclipse.jface.text.link.LinkedModeUI;
-import org.eclipse.jface.text.link.LinkedPosition;
-import org.eclipse.jface.text.link.LinkedPositionGroup;
-import org.eclipse.jface.text.link.ProposalPosition;
-
-
-/**
- * A template proposal.
- *
- * @since 3.0
- */
-public class TemplateProposal implements ICompletionProposal, ICompletionProposalExtension, ICompletionProposalExtension2, ICompletionProposalExtension3 {
-
- private final Template fTemplate;
- private final TemplateContext fContext;
- private final Image fImage;
- private final IRegion fRegion;
- private int fRelevance;
-
- private IRegion fSelectedRegion; // initialized by apply()
- private String fDisplayString;
- private InclusivePositionUpdater fUpdater;
-
- /**
- * Creates a template proposal with a template and its context.
- * @param template the template
- * @param context the context in which the template was requested.
- * @param region the region this proposal is applied to
- * @param image the icon of the proposal.
- */
- public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image) {
- this(template, context, region, image, 0);
- }
-
- /**
- * Creates a template proposal with a template and its context.
- * @param template the template
- * @param context the context in which the template was requested.
- * @param image the icon of the proposal.
- * @param region the region this proposal is applied to
- * @param relevance the relevance of the proposal
- */
- public TemplateProposal(Template template, TemplateContext context, IRegion region, Image image, int relevance) {
- Assert.isNotNull(template);
- Assert.isNotNull(context);
- Assert.isNotNull(region);
-
- fTemplate= template;
- fContext= context;
- fImage= image;
- fRegion= region;
-
- fDisplayString= null;
-
- fRelevance= relevance;
- }
-
- /*
- * @see ICompletionProposal#apply(IDocument)
- */
- public final void apply(IDocument document) {
- // not called anymore
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#apply(org.eclipse.jface.text.ITextViewer, char, int, int)
- */
- public void apply(ITextViewer viewer, char trigger, int stateMask, int offset) {
-
- IDocument document= viewer.getDocument();
- try {
- fContext.setReadOnly(false);
- TemplateBuffer templateBuffer;
- try {
- templateBuffer= fContext.evaluate(fTemplate);
- } catch (TemplateException e1) {
- fSelectedRegion= fRegion;
- return;
- }
-
- int start= getReplaceOffset();
- int end= Math.max(getReplaceEndOffset(), offset);
-
- // insert template string
- String templateString= templateBuffer.getString();
- document.replace(start, end - start, templateString);
-
-
- // translate positions
- LinkedModeModel model= new LinkedModeModel();
- TemplateVariable[] variables= templateBuffer.getVariables();
- boolean hasPositions= false;
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
-
- if (variable.isUnambiguous())
- continue;
-
- LinkedPositionGroup group= new LinkedPositionGroup();
-
- int[] offsets= variable.getOffsets();
- int length= variable.getLength();
-
- String[] values= variable.getValues();
- ICompletionProposal[] proposals= new ICompletionProposal[values.length];
- for (int j= 0; j < values.length; j++) {
- ensurePositionCategoryInstalled(document, model);
- Position pos= new Position(offsets[0] + start, length);
- document.addPosition(getCategory(), pos);
- proposals[j]= new PositionBasedCompletionProposal(values[j], pos, length);
- }
-
- for (int j= 0; j != offsets.length; j++)
- if (j == 0 && proposals.length > 1)
- group.addPosition(new ProposalPosition(document, offsets[j] + start, length, proposals));
- else
- group.addPosition(new LinkedPosition(document, offsets[j] + start, length));
-
- model.addGroup(group);
- hasPositions= true;
- }
-
- if (hasPositions) {
- model.forceInstall();
- LinkedModeUI ui= new LinkedModeUI(model, viewer);
- ui.setExitPosition(viewer, getCaretOffset(templateBuffer) + start, 0, Integer.MAX_VALUE);
- ui.enter();
-
- fSelectedRegion= ui.getSelectedRegion();
- } else {
- ensurePositionCategoryRemoved(document);
- fSelectedRegion= new Region(getCaretOffset(templateBuffer) + start, 0);
- }
-
- } catch (BadLocationException e) {
- openErrorDialog(viewer.getTextWidget().getShell(), e);
- ensurePositionCategoryRemoved(document);
- fSelectedRegion= fRegion;
- } catch (BadPositionCategoryException e) {
- openErrorDialog(viewer.getTextWidget().getShell(), e);
- fSelectedRegion= fRegion;
- }
-
- }
-
- private void ensurePositionCategoryInstalled(final IDocument document, LinkedModeModel model) {
- if (!document.containsPositionCategory(getCategory())) {
- document.addPositionCategory(getCategory());
- fUpdater= new InclusivePositionUpdater(getCategory());
- document.addPositionUpdater(fUpdater);
-
- model.addLinkingListener(new ILinkedModeListener() {
-
- /*
- * @see org.eclipse.jface.text.link.ILinkedModeListener#left(org.eclipse.jface.text.link.LinkedModeModel, int)
- */
- public void left(LinkedModeModel environment, int flags) {
- ensurePositionCategoryRemoved(document);
- }
-
- public void suspend(LinkedModeModel environment) {}
- public void resume(LinkedModeModel environment, int flags) {}
- });
- }
- }
-
- private void ensurePositionCategoryRemoved(IDocument document) {
- if (document.containsPositionCategory(getCategory())) {
- try {
- document.removePositionCategory(getCategory());
- } catch (BadPositionCategoryException e) {
- // ignore
- }
- document.removePositionUpdater(fUpdater);
- }
- }
-
- private String getCategory() {
- return "TemplateProposalCategory_" + toString(); //$NON-NLS-1$
- }
-
- private int getCaretOffset(TemplateBuffer buffer) {
-
- TemplateVariable[] variables= buffer.getVariables();
- for (int i= 0; i != variables.length; i++) {
- TemplateVariable variable= variables[i];
- if (variable.getType().equals(GlobalTemplateVariables.Cursor.NAME))
- return variable.getOffsets()[0];
- }
-
- return buffer.getString().length();
- }
-
- /**
- * Returns the offset of the range in the document that will be replaced by
- * applying this template.
- *
- * @return the offset of the range in the document that will be replaced by
- * applying this template
- */
- private int getReplaceOffset() {
- int start;
- if (fContext instanceof DocumentTemplateContext) {
- DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
- start= docContext.getStart();
- } else {
- start= fRegion.getOffset();
- }
- return start;
- }
-
- /**
- * Returns the end offset of the range in the document that will be replaced
- * by applying this template.
- *
- * @return the end offset of the range in the document that will be replaced
- * by applying this template
- */
- private int getReplaceEndOffset() {
- int end;
- if (fContext instanceof DocumentTemplateContext) {
- DocumentTemplateContext docContext = (DocumentTemplateContext)fContext;
- end= docContext.getEnd();
- } else {
- end= fRegion.getOffset() + fRegion.getLength();
- }
- return end;
- }
-
- /*
- * @see ICompletionProposal#getSelection(IDocument)
- */
- public Point getSelection(IDocument document) {
- return new Point(fSelectedRegion.getOffset(), fSelectedRegion.getLength());
- }
-
- /*
- * @see ICompletionProposal#getAdditionalProposalInfo()
- */
- public String getAdditionalProposalInfo() {
- try {
- fContext.setReadOnly(true);
- TemplateBuffer templateBuffer;
- try {
- templateBuffer= fContext.evaluate(fTemplate);
- } catch (TemplateException e) {
- return null;
- }
-
- return templateBuffer.getString();
-
- } catch (BadLocationException e) {
- return null;
- }
- }
-
- /*
- * @see ICompletionProposal#getDisplayString()
- */
- public String getDisplayString() {
- if (fDisplayString == null) {
- fDisplayString= fTemplate.getName() + JFaceTextTemplateMessages.getString("TemplateProposal.delimiter") + fTemplate.getDescription(); //$NON-NLS-1$
- }
- return fDisplayString;
- }
-
- /*
- * @see ICompletionProposal#getImage()
- */
- public Image getImage() {
- return fImage;
- }
-
- /*
- * @see ICompletionProposal#getContextInformation()
- */
- public IContextInformation getContextInformation() {
- return null;
- }
-
- private void openErrorDialog(Shell shell, Exception e) {
- MessageDialog.openError(shell, JFaceTextTemplateMessages.getString("TemplateProposal.errorDialog.title"), e.getMessage()); //$NON-NLS-1$
- }
-
- /**
- * Returns the relevance.
- *
- * @return the relevance
- */
- public int getRelevance() {
- return fRelevance;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getInformationControlCreator()
- */
- public IInformationControlCreator getInformationControlCreator() {
-// return new TemplateInformationControlCreator();
- return null;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#selected(org.eclipse.jface.text.ITextViewer, boolean)
- */
- public void selected(ITextViewer viewer, boolean smartToggle) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#unselected(org.eclipse.jface.text.ITextViewer)
- */
- public void unselected(ITextViewer viewer) {
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension2#validate(org.eclipse.jface.text.IDocument, int, org.eclipse.jface.text.DocumentEvent)
- */
- public boolean validate(IDocument document, int offset, DocumentEvent event) {
- try {
- int replaceOffset= getReplaceOffset();
- if (offset >= replaceOffset) {
- String content= document.get(replaceOffset, offset - replaceOffset);
- return fTemplate.getName().startsWith(content);
- }
- } catch (BadLocationException e) {
- // concurrent modification - ignore
- }
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getReplacementString()
- */
- public CharSequence getPrefixCompletionText(IDocument document, int completionOffset) {
- return fTemplate.getName();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension3#getReplacementOffset()
- */
- public int getPrefixCompletionStart(IDocument document, int completionOffset) {
- return getReplaceOffset();
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#apply(org.eclipse.jface.text.IDocument, char, int)
- */
- public void apply(IDocument document, char trigger, int offset) {
- // not called any longer
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#isValidFor(org.eclipse.jface.text.IDocument, int)
- */
- public boolean isValidFor(IDocument document, int offset) {
- // not called any longer
- return false;
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getTriggerCharacters()
- */
- public char[] getTriggerCharacters() {
- // no triggers
- return new char[0];
- }
-
- /*
- * @see org.eclipse.jface.text.contentassist.ICompletionProposalExtension#getContextInformationPosition()
- */
- public int getContextInformationPosition() {
- return fRegion.getOffset();
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html
deleted file mode 100644
index e70145a0f58..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/package.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]"
- name="GENERATOR">
- <title>Templates</title>
- <meta content="Template Infrastructure package description"
- name="description">
-</head>
-<body>
-Application programming interfaces for interaction
-with the Eclipse Java User Interface text support.
-<h2>Templates<br>
-</h2>
-<h3>packages</h3>
-<ul>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.jface.text.templates</span></big></li>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.ui.workbench.texteditor.templates</span><br>
- <span style="font-family: monospace;"></span></big></li>
- <li><big><span style="font-family: monospace; font-weight: bold;">org.eclipse.ui.editors.templates</span></big><br>
- <span style="font-family: monospace;"></span></li>
-</ul>
-<h3><code></code></h3>
-Templates are shortcuts for frequently used fragments of text such as
-code patterns or complex text entities. They may contain variables
-which are only resolved at the time when the template is inserted
-within a context. Together with linked mode, inserting a template can
-create a on-the-fly edit mask within a text viewer.<br>
-<br>
-Templates are specified as text, variables are defined using the <span
- style="font-family: monospace;">${variable}</span> notation known from
-Ant, for example. The following snippet shows an example template for
-an instance check in Java:<br>
-<pre>if (${name} instanceof ${type}) {<br>&nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};<br>&nbsp;&nbsp;&nbsp; ${cursor}<br>}<br></pre>
-In this template, the variables (<span style="font-family: monospace;">name,
-type, ...</span><span style="font-family: sans-serif;">) are resolved
-when inserted into java source and changing one variable instance will
-also change the other. When leaving linked mode, the caret is placed at
-the </span><span style="font-family: monospace;">cursor</span><span
- style="font-family: sans-serif;"> variable.<br>
-<br>
-Template functionality can be added to a custom text editor by offering
-</span><span style="font-family: monospace;">TemplateProposal</span><span
- style="font-family: sans-serif;">s as content assist choices, which is
-simplified by using a </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;">subclass of </span></span><span
- style="font-family: monospace;">TemplateCompletionProcessor</span><span
- style="font-family: sans-serif;">. User template management can be
-offered by including a </span><span style="font-family: monospace;">TemplatePreferencePage</span><span
- style="font-family: sans-serif;"> which uses a </span><span
- style="font-family: monospace;">TemplateStore</span><span
- style="font-family: sans-serif;"> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> as the
-underlying model to store templates. The <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point can be used to allow other plug-ins to contribute
-templates to an editor. This is accomplished by using the <span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-subclasses of the above types.<br>
-<br>
-Template variables are resolved by a <span
- style="font-family: monospace;">TemplateVariableResolver.</span> <span
- style="font-family: monospace;">GlobalTemplateVariables</span> offers
-some default variables such as date, user, and selection, but advanced
-features such as resolving to language constructs can be performed in
-subclasses.<br>
-</span>
-<h4>Classes</h4>
-<ul>
- <li><span style="font-family: monospace;">Template</span><span
- style="font-family: sans-serif;"> a template consists of name, context
-type identifier, and a pattern.</span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateTranslator</span> and <span
- style="font-family: monospace;">TemplateBuffer</span> are used to
-parse the template grammar and don't need to be used usually.</span></li>
- <li><span style="font-family: sans-serif;">A <span
- style="font-family: monospace;">TemplateProposal </span>can be
-offered in content assist, possibly created by a subclass of <span
- style="font-family: monospace;">TemplateCompletionProcessor.</span></span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateStore</span> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> manage a
-set of templates within a plug-in and offer ways to store them in the
-preferences or externally in XML streams via a <span
- style="font-family: monospace;">TemplateReaderWriter</span>.<br>
- </span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-add awareness for the </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;"> <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point.</span></span></li>
- <li style="font-family: monospace;"><span
- style="font-family: sans-serif;"><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplatePreferencePage</span> allows
-the user to access the templates within a <span
- style="font-family: monospace;">TemplateStore</span>.</span></span></li>
-</ul>
-<ul>
-</ul>
-<h4>Example</h4>
-<pre><span style="font-family: sans-serif;">See the Template Editor Example in the <span
- style="font-weight: bold;">org.eclipse.ui.examples.javaeditor</span> project.<br></span></pre>
-</body>
-</html>
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
deleted file mode 100644
index 560185275e9..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceData.java
+++ /dev/null
@@ -1,173 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.Template;
-
-
-/**
- * TemplatePersistenceData stores information about a template. It uniquely
- * references contributed templates via their id. Contributed templates may be
- * deleted or modified. All template may be enabled or not.
- *
- * @since 3.0
- */
-public class TemplatePersistenceData {
- private final Template fOriginalTemplate;
- private final String fId;
- private final boolean fOriginalIsEnabled;
-
- private Template fCustomTemplate= null;
- private boolean fIsDeleted= false;
- private boolean fCustomIsEnabled= true;
-
- /**
- * Creates a new, user-added instance that is not linked to a contributed
- * template.
- *
- * @param template the template which is stored by the new instance
- * @param enabled whether the template is enabled
- */
- public TemplatePersistenceData(Template template, boolean enabled) {
- this(template, enabled, null);
- }
-
- /**
- * Creates a new instance. If <code>id</code> is not <code>null</code>,
- * the instance is represents a template that is contributed and can be
- * identified via its id.
- *
- * @param template the template which is stored by the new instance
- * @param enabled whether the template is enabled
- * @param id the id of the template, or <code>null</code> if a user-added
- * instance should be created
- */
- public TemplatePersistenceData(Template template, boolean enabled, String id) {
- Assert.isNotNull(template);
- fOriginalTemplate= template;
- fCustomTemplate= template;
- fOriginalIsEnabled= enabled;
- fCustomIsEnabled= enabled;
- fId= id;
- }
-
- /**
- * Returs the id of this template store, or <code>null</code> if there is none.
- *
- * @return the id of this template store
- */
- public String getId() {
- return fId;
- }
-
- /**
- * Returns the deletion state of the stored template. This is only relevant
- * of contributed templates.
- *
- * @return the deletion state of the stored template
- */
- public boolean isDeleted() {
- return fIsDeleted;
- }
-
- /**
- * Sets the deletion state of the stored template.
- *
- * @param isDeleted the deletion state of the stored template
- */
- public void setDeleted(boolean isDeleted) {
- fIsDeleted= isDeleted;
- }
-
- /**
- * Returns the template encapsulated by the receiver.
- *
- * @return the template encapsulated by the receiver
- */
- public Template getTemplate() {
- return fCustomTemplate;
- }
-
-
- /**
- * Sets the template encapsulated by the receiver.
- *
- * @param template the new template
- */
- public void setTemplate(Template template) {
- fCustomTemplate= template;
- }
-
- /**
- * Returns whether the receiver represents a custom template, i.e. is either
- * a user-added template or a contributed template that has been modified.
- *
- * @return <code>true</code> if the contained template is a custom
- * template and cannot be reconstructed from the contributed
- * templates
- */
- public boolean isCustom() {
- return fId == null
- || fIsDeleted
- || fOriginalIsEnabled != fCustomIsEnabled
- || !fOriginalTemplate.equals(fCustomTemplate);
- }
-
- /**
- * Returns whether the receiver represents a modified template, i.e. a
- * contributed template that has been changed.
- *
- * @return <code>true</code> if the contained template is contributed but has been modified, <code>false</code> otherwise
- */
- public boolean isModified() {
- return isCustom() && !isUserAdded();
- }
-
- /**
- * Returns <code>true</code> if the contained template was added by a
- * user, i.e. does not reference a contributed template.
- *
- * @return <code>true</code> if the contained template was added by a user, <code>false</code> otherwise
- */
- public boolean isUserAdded() {
- return fId == null;
- }
-
-
- /**
- * Reverts the template to its original setting.
- */
- public void revert() {
- fCustomTemplate= fOriginalTemplate;
- fCustomIsEnabled= fOriginalIsEnabled;
- fIsDeleted= false;
- }
-
-
- /**
- * Returns the enablement state of the contained template.
- *
- * @return the enablement state of the contained template
- */
- public boolean isEnabled() {
- return fCustomIsEnabled;
- }
-
- /**
- * Sets the enablement state of the contained template.
- *
- * @param isEnabled the new enablement state of the contained template
- */
- public void setEnabled(boolean isEnabled) {
- fCustomIsEnabled= isEnabled;
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java
deleted file mode 100644
index 064fc83eb2e..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.text.MessageFormat;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-
-/**
- * @since 3.0
- */
-class TemplatePersistenceMessages {
-
- private static final String RESOURCE_BUNDLE= TemplatePersistenceMessages.class.getName();
- private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE);
-
- private TemplatePersistenceMessages() {
- }
-
- /**
- * @param key
- * @return
- */
- public static String getString(String key) {
- try {
- return fgResourceBundle.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- }
-
- /**
- * Gets a string from the resource bundle and formats it with the argument
- *
- * @param key the string used to get the bundle value, must not be null
- * @param arg
- * @return
- */
- public static String getFormattedString(String key, Object arg) {
- return MessageFormat.format(getString(key), new Object[] { arg });
- }
-
-
- /**
- * Gets a string from the resource bundle and formats it with arguments
- * @param key
- * @param args
- * @return
- */
- public static String getFormattedString(String key, Object[] args) {
- return MessageFormat.format(getString(key), args);
- }
-}
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties
deleted file mode 100644
index 7d00d3dc501..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplatePersistenceMessages.properties
+++ /dev/null
@@ -1,14 +0,0 @@
-###############################################################################
-# Copyright (c) 2000, 2004 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
-###############################################################################
-
-TemplateReaderWriter.duplicate.id= Duplicate template id
-TemplateReaderWriter.error.missing_attribute= Missing required attribute
-TemplateReaderWriter.error.illegal_boolean_attribute= Illegal boolean attribute, must be "true" or "false".
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java
deleted file mode 100644
index e2ec4596ef1..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateReaderWriter.java
+++ /dev/null
@@ -1,345 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.Reader;
-import java.io.Writer;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.MissingResourceException;
-import java.util.ResourceBundle;
-import java.util.Set;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
-import javax.xml.transform.stream.StreamResult;
-
-import org.w3c.dom.Attr;
-import org.w3c.dom.Document;
-import org.w3c.dom.NamedNodeMap;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.w3c.dom.Text;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.Template;
-
-/**
- * Serializes templates as character stream and reads the same format back.
- * Clients may instantiate this class, it is not intended to be subclassed.
- *
- * @since 3.0
- */
-public class TemplateReaderWriter {
-
- private static final String TEMPLATE_ROOT = "templates"; //$NON-NLS-1$
- private static final String TEMPLATE_ELEMENT = "template"; //$NON-NLS-1$
- private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$
- private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$
- private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$
- private static final String CONTEXT_ATTRIBUTE= "context"; //$NON-NLS-1$
- private static final String ENABLED_ATTRIBUTE= "enabled"; //$NON-NLS-1$
- private static final String DELETED_ATTRIBUTE= "deleted"; //$NON-NLS-1$
-
- /**
- * Create a new instance.
- */
- public TemplateReaderWriter() {
- }
-
- /**
- * Reads templates from a reader and returns them. The reader must present
- * a serialized form as produced by the <code>save</code> method.
- *
- * @param reader the reader to read templates from
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(Reader reader) throws IOException {
- return read(reader, null);
- }
-
- /**
- * Reads templates from a stream and adds them to the templates.
- *
- * @param reader the reader to read templates from
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(Reader reader, ResourceBundle bundle) throws IOException {
- return read(new InputSource(reader), bundle);
- }
-
- /**
- * Reads templates from a stream and adds them to the templates.
- *
- * @param stream the byte stream to read templates from
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- public TemplatePersistenceData[] read(InputStream stream, ResourceBundle bundle) throws IOException {
- return read(new InputSource(stream), bundle);
- }
-
- /**
- * Reads templates from an InputSource and adds them to the templates.
- *
- * @param source the input source
- * @param bundle a resource bundle to use for translating the read templates, or <code>null</code> if no translation should occur
- * @return the read templates, encapsulated in instances of <code>TemplatePersistenceData</code>
- * @throws IOException if reading from the stream fails
- */
- private TemplatePersistenceData[] read(InputSource source, ResourceBundle bundle) throws IOException {
- try {
- Collection templates= new ArrayList();
- Set ids= new HashSet();
-
- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
- DocumentBuilder parser= factory.newDocumentBuilder();
- Document document= parser.parse(source);
-
- NodeList elements= document.getElementsByTagName(TEMPLATE_ELEMENT);
-
- int count= elements.getLength();
- for (int i= 0; i != count; i++) {
- Node node= elements.item(i);
- NamedNodeMap attributes= node.getAttributes();
-
- if (attributes == null)
- continue;
-
- String id= getStringValue(attributes, ID_ATTRIBUTE, null);
- if (id != null && ids.contains(id))
- throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.duplicate.id")); //$NON-NLS-1$
-
- boolean deleted = getBooleanValue(attributes, DELETED_ATTRIBUTE, false);
-
- String name= getStringValue(attributes, NAME_ATTRIBUTE);
- name= translateString(name, bundle);
-
- String description= getStringValue(attributes, DESCRIPTION_ATTRIBUTE, ""); //$NON-NLS-1$
- description= translateString(description, bundle);
-
- String context= getStringValue(attributes, CONTEXT_ATTRIBUTE);
-
- if (name == null || context == null)
- throw new IOException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$
-
- boolean enabled = getBooleanValue(attributes, ENABLED_ATTRIBUTE, true);
-
- StringBuffer buffer= new StringBuffer();
- NodeList children= node.getChildNodes();
- for (int j= 0; j != children.getLength(); j++) {
- String value= children.item(j).getNodeValue();
- if (value != null)
- buffer.append(value);
- }
- String pattern= buffer.toString();
- pattern= translateString(pattern, bundle);
-
- Template template= new Template(name, description, context, pattern);
- TemplatePersistenceData data= new TemplatePersistenceData(template, enabled, id);
- data.setDeleted(deleted);
-
- templates.add(data);
- }
-
- return (TemplatePersistenceData[]) templates.toArray(new TemplatePersistenceData[templates.size()]);
-
- } catch (ParserConfigurationException e) {
- Assert.isTrue(false);
- } catch (SAXException e) {
- Throwable t= e.getCause();
- if (t instanceof IOException)
- throw (IOException) t;
- else
- throw new IOException(t.getMessage());
- }
-
- return null; // dummy
- }
-
- /**
- * Saves the templates as XML, encoded as UTF-8 onto the given byte stream.
- *
- * @param templates the templates to save
- * @param stream the byte output to write the templates to in XML
- * @throws IOException if writing the templates fails
- */
- public void save(TemplatePersistenceData[] templates, OutputStream stream) throws IOException {
- save(templates, new StreamResult(stream));
- }
-
- /**
- * Saves the templates as XML.
- *
- * @param templates the templates to save
- * @param writer the writer to write the templates to in XML
- * @throws IOException if writing the templates fails
- */
- public void save(TemplatePersistenceData[] templates, Writer writer) throws IOException {
- save(templates, new StreamResult(writer));
- }
-
- /**
- * Saves the templates as XML.
- *
- * @param templates the templates to save
- * @param result the stream result to write to
- * @throws IOException if writing the templates fails
- */
- private void save(TemplatePersistenceData[] templates, StreamResult result) throws IOException {
- try {
- DocumentBuilderFactory factory= DocumentBuilderFactory.newInstance();
- DocumentBuilder builder= factory.newDocumentBuilder();
- Document document= builder.newDocument();
-
- Node root= document.createElement(TEMPLATE_ROOT); //$NON-NLS-1$
- document.appendChild(root);
-
- for (int i= 0; i < templates.length; i++) {
- TemplatePersistenceData data= templates[i];
- Template template= data.getTemplate();
-
- Node node= document.createElement(TEMPLATE_ELEMENT);
- root.appendChild(node);
-
- NamedNodeMap attributes= node.getAttributes();
-
- String id= data.getId();
- if (id != null) {
- Attr idAttr= document.createAttribute(ID_ATTRIBUTE);
- idAttr.setValue(id);
- attributes.setNamedItem(idAttr);
- }
-
- if (template != null) {
- Attr name= document.createAttribute(NAME_ATTRIBUTE);
- name.setValue(template.getName());
- attributes.setNamedItem(name);
- }
-
- if (template != null) {
- Attr description= document.createAttribute(DESCRIPTION_ATTRIBUTE);
- description.setValue(template.getDescription());
- attributes.setNamedItem(description);
- }
-
- if (template != null) {
- Attr context= document.createAttribute(CONTEXT_ATTRIBUTE);
- context.setValue(template.getContextTypeId());
- attributes.setNamedItem(context);
- }
-
- Attr enabled= document.createAttribute(ENABLED_ATTRIBUTE);
- enabled.setValue(data.isEnabled() ? Boolean.toString(true) : Boolean.toString(false)); //$NON-NLS-1$ //$NON-NLS-2$
- attributes.setNamedItem(enabled);
-
- Attr deleted= document.createAttribute(DELETED_ATTRIBUTE);
- deleted.setValue(data.isDeleted() ? Boolean.toString(true) : Boolean.toString(false)); //$NON-NLS-1$ //$NON-NLS-2$
- attributes.setNamedItem(deleted);
-
- if (template != null) {
- Text pattern= document.createTextNode(template.getPattern());
- node.appendChild(pattern);
- }
- }
-
-
- Transformer transformer=TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); //$NON-NLS-1$
- DOMSource source = new DOMSource(document);
-
- transformer.transform(source, result);
-
- } catch (ParserConfigurationException e) {
- Assert.isTrue(false);
- } catch (TransformerException e) {
- if (e.getException() instanceof IOException)
- throw (IOException) e.getException();
- Assert.isTrue(false);
- }
- }
-
- private boolean getBooleanValue(NamedNodeMap attributes, String attribute, boolean defaultValue) throws SAXException {
- Node enabledNode= attributes.getNamedItem(attribute);
- if (enabledNode == null)
- return defaultValue;
- else if (enabledNode.getNodeValue().equals(Boolean.toString(true)))
- return true;
- else if (enabledNode.getNodeValue().equals(Boolean.toString(false)))
- return false;
- else
- throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.illegal_boolean_attribute")); //$NON-NLS-1$
- }
-
- private String getStringValue(NamedNodeMap attributes, String name) throws SAXException {
- String val= getStringValue(attributes, name, null);
- if (val == null)
- throw new SAXException(TemplatePersistenceMessages.getString("TemplateReaderWriter.error.missing_attribute")); //$NON-NLS-1$
- return val;
- }
-
- private String getStringValue(NamedNodeMap attributes, String name, String defaultValue) {
- Node node= attributes.getNamedItem(name);
- return node == null ? defaultValue : node.getNodeValue();
- }
-
- private String translateString(String str, ResourceBundle bundle) {
- if (bundle == null)
- return str;
-
- int idx= str.indexOf('%');
- if (idx == -1) {
- return str;
- }
- StringBuffer buf= new StringBuffer();
- int k= 0;
- while (idx != -1) {
- buf.append(str.substring(k, idx));
- for (k= idx + 1; k < str.length() && !Character.isWhitespace(str.charAt(k)); k++) {
- // loop
- }
- String key= str.substring(idx + 1, k);
- buf.append(getBundleString(key, bundle));
- idx= str.indexOf('%', k);
- }
- buf.append(str.substring(k));
- return buf.toString();
- }
-
- private String getBundleString(String key, ResourceBundle bundle) {
- if (bundle != null) {
- try {
- return bundle.getString(key);
- } catch (MissingResourceException e) {
- return '!' + key + '!';
- }
- } else
- return TemplatePersistenceMessages.getString(key); // default messages
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java
deleted file mode 100644
index fdfde5a2646..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/TemplateStore.java
+++ /dev/null
@@ -1,344 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2004 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
- *******************************************************************************/
-package org.eclipse.jface.text.templates.persistence;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.StringReader;
-import java.io.StringWriter;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.jface.preference.IPreferenceStore;
-
-import org.eclipse.jface.text.Assert;
-import org.eclipse.jface.text.templates.ContextTypeRegistry;
-import org.eclipse.jface.text.templates.Template;
-import org.eclipse.jface.text.templates.TemplateException;
-
-/**
- * A collection of templates. Clients may instantiate this class.
- *
- * @since 3.0
- */
-public class TemplateStore {
- /** The stored templates. */
- private final List fTemplates= new ArrayList();
- /** The preference store. */
- private IPreferenceStore fPreferenceStore;
- /**
- * The key into <code>fPreferenceStore</code> the value of which holds custom templates
- * encoded as XML.
- */
- private String fKey;
- /**
- * The context type registry, or <code>null</code> if all templates regardless
- * of context type should be loaded.
- */
- private ContextTypeRegistry fRegistry;
-
-
- /**
- * Creates a new template store.
- *
- * @param store the preference store in which to store custom templates
- * under <code>key</code>
- * @param key the key into <code>store</code> where to store custom
- * templates
- */
- public TemplateStore(IPreferenceStore store, String key) {
- Assert.isNotNull(store);
- Assert.isNotNull(key);
- fPreferenceStore= store;
- fKey= key;
- }
-
- /**
- * Creates a new template store with a context type registry. Only templates
- * that specify a context type contained in the registry will be loaded by
- * this store if the registry is not <code>null</code>.
- *
- * @param registry a context type registry, or <code>null</code> if all
- * templates should be loaded
- * @param store the preference store in which to store custom templates
- * under <code>key</code>
- * @param key the key into <code>store</code> where to store custom
- * templates
- */
- public TemplateStore(ContextTypeRegistry registry, IPreferenceStore store, String key) {
- this(store, key);
- fRegistry= registry;
- }
-
- /**
- * Loads the templates from contributions and preferences.
- *
- * @throws IOException if loading fails.
- */
- public void load() throws IOException {
- fTemplates.clear();
- loadContributedTemplates();
- loadCustomTemplates();
- }
-
- /**
- * Hook method to load contributed templates. Contributed templates are superseded
- * by customized versions of user added templates stored in the preferences.
- * <p>
- * The default implementation does nothing.</p>
- *
- * @throws IOException if loading fails
- */
- protected void loadContributedTemplates() throws IOException {
- }
-
- /**
- * Adds a template to the internal store. The added templates must have
- * a unique id.
- *
- * @param data the template data to add
- */
- protected void internalAdd(TemplatePersistenceData data) {
- if (!data.isCustom()) {
- // check if the added template is not a duplicate id
- String id= data.getId();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData d2= (TemplatePersistenceData) it.next();
- if (d2.getId() != null && d2.getId().equals(id))
- return;
- }
- fTemplates.add(data);
- }
- }
-
- /**
- * Saves the templates to the preferences.
- *
- * @throws IOException if the templates cannot be written
- */
- public void save() throws IOException {
- ArrayList custom= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isCustom() && !(data.isUserAdded() && data.isDeleted())) // don't save deleted user-added templates
- custom.add(data);
- }
-
- StringWriter output= new StringWriter();
- TemplateReaderWriter writer= new TemplateReaderWriter();
- writer.save((TemplatePersistenceData[]) custom.toArray(new TemplatePersistenceData[custom.size()]), output);
-
- fPreferenceStore.setValue(fKey, output.toString());
- }
-
- /**
- * Adds a template encapsulated in its persistent form.
- *
- * @param data the template to add
- */
- public void add(TemplatePersistenceData data) {
-
- if (!validateTemplate(data.getTemplate()))
- return;
-
- if (data.isUserAdded()) {
- fTemplates.add(data);
- } else {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData d2= (TemplatePersistenceData) it.next();
- if (d2.getId() != null && d2.getId().equals(data.getId())) {
- d2.setTemplate(data.getTemplate());
- d2.setDeleted(data.isDeleted());
- d2.setEnabled(data.isEnabled());
- return;
- }
- }
-
- // add an id which is not contributed as add-on
- if (data.getTemplate() != null) {
- TemplatePersistenceData newData= new TemplatePersistenceData(data.getTemplate(), data.isEnabled());
- fTemplates.add(newData);
- }
- }
- }
-
- /**
- * Removes a template from the store.
- *
- * @param data the template to remove
- */
- public void delete(TemplatePersistenceData data) {
- if (data.isUserAdded())
- fTemplates.remove(data);
- else
- data.setDeleted(true);
- }
-
- /**
- * Restores all contributed templates that have been deleted.
- */
- public void restoreDeleted() {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isDeleted())
- data.setDeleted(false);
- }
- }
-
- /**
- * Deletes all user-added templates and reverts all contributed templates.
- */
- public void restoreDefaults() {
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isUserAdded())
- it.remove();
- else
- data.revert();
- }
- }
-
- /**
- * Returns all enabled templates.
- *
- * @return all enabled templates
- */
- public Template[] getTemplates() {
- return getTemplates(null);
- }
-
- /**
- * Returns all enabled templates for the given context type.
- *
- * @param contextTypeId the id of the context type of the requested templates, or <code>null</code> if all templates should be returned
- * @return all enabled templates for the given context type
- */
- public Template[] getTemplates(String contextTypeId) {
- List templates= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (data.isEnabled() && !data.isDeleted() && (contextTypeId == null || contextTypeId.equals(data.getTemplate().getContextTypeId())))
- templates.add(data.getTemplate());
- }
-
- return (Template[]) templates.toArray(new Template[templates.size()]);
- }
-
- /**
- * Returns the first enabled template that matches the name.
- *
- * @param name the name of the template searched for
- * @return the first enabled template that matches both name and context type id, or <code>null</code> if none is found
- */
- public Template findTemplate(String name) {
- return findTemplate(name, null);
- }
-
- /**
- * Returns the first enabled template that matches both name and context type id.
- *
- * @param name the name of the template searched for
- * @param contextTypeId the context type id to clip unwanted templates, or <code>null</code> if any context type is ok
- * @return the first enabled template that matches both name and context type id, or <code>null</code> if none is found
- */
- public Template findTemplate(String name, String contextTypeId) {
- Assert.isNotNull(name);
-
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- Template template= data.getTemplate();
- if (data.isEnabled() && !data.isDeleted()
- && (contextTypeId == null || contextTypeId.equals(template.getContextTypeId()))
- && name.equals(template.getName()))
- return template;
- }
-
- return null;
- }
-
- /**
- * Returns all template datas.
- *
- * @param includeDeleted whether to include deleted datas
- * @return all template datas, whether enabled or not
- */
- public TemplatePersistenceData[] getTemplateData(boolean includeDeleted) {
- List datas= new ArrayList();
- for (Iterator it= fTemplates.iterator(); it.hasNext();) {
- TemplatePersistenceData data= (TemplatePersistenceData) it.next();
- if (includeDeleted || !data.isDeleted())
- datas.add(data);
- }
-
- return (TemplatePersistenceData[]) datas.toArray(new TemplatePersistenceData[datas.size()]);
- }
-
- private void loadCustomTemplates() throws IOException {
- String pref= fPreferenceStore.getString(fKey);
- if (pref != null && pref.trim().length() > 0) {
- Reader input= new StringReader(pref);
- TemplateReaderWriter reader= new TemplateReaderWriter();
- TemplatePersistenceData[] datas= reader.read(input);
- for (int i= 0; i < datas.length; i++) {
- TemplatePersistenceData data= datas[i];
- add(data);
- }
- }
- }
-
- /**
- * Validates a template against the context type registered in the context
- * type registry. Returns always <code>true</code> if no registry is
- * present.
- *
- * @param template the template to validate
- * @return <code>true</code> if validation is successful or no context
- * type registry is specified, <code>false</code> if validation
- * fails
- */
- private boolean validateTemplate(Template template) {
- String contextTypeId= template.getContextTypeId();
- if (contextExists(contextTypeId)) {
- if (fRegistry != null)
- try {
- fRegistry.getContextType(contextTypeId).validate(template.getPattern());
- } catch (TemplateException e) {
- return false;
- }
- return true;
- } else
- return false;
- }
-
- /**
- * Returns <code>true</code> if a context type id specifies a valid context type
- * or if no context type registry is present.
- *
- * @param contextTypeId the context type id to look for
- * @return <code>true</code> if the context type specified by the id
- * is present in the context type registry, or if no registry is
- * specified
- */
- private boolean contextExists(String contextTypeId) {
- return contextTypeId != null && (fRegistry == null || fRegistry.getContextType(contextTypeId) != null);
- }
-
- /**
- * Returns the registry.
- *
- * @return Returns the registry
- */
- protected final ContextTypeRegistry getRegistry() {
- return fRegistry;
- }
-}
-
diff --git a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html b/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html
deleted file mode 100644
index e70145a0f58..00000000000
--- a/org.eclipse.jface.text/src/org/eclipse/jface/text/templates/persistence/package.html
+++ /dev/null
@@ -1,113 +0,0 @@
-<!DOCTYPE html PUBLIC "-//w3c//dtd html 4.0 transitional//en">
-<html>
-<head>
- <meta content="text/html; charset=iso-8859-1"
- http-equiv="Content-Type">
- <meta content="IBM" name="Author">
- <meta content="Mozilla/4.75 [en] (Windows NT 5.0; U) [Netscape]"
- name="GENERATOR">
- <title>Templates</title>
- <meta content="Template Infrastructure package description"
- name="description">
-</head>
-<body>
-Application programming interfaces for interaction
-with the Eclipse Java User Interface text support.
-<h2>Templates<br>
-</h2>
-<h3>packages</h3>
-<ul>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.jface.text.templates</span></big></li>
- <li style="font-weight: bold;"><big><span
- style="font-family: monospace;">org.eclipse.ui.workbench.texteditor.templates</span><br>
- <span style="font-family: monospace;"></span></big></li>
- <li><big><span style="font-family: monospace; font-weight: bold;">org.eclipse.ui.editors.templates</span></big><br>
- <span style="font-family: monospace;"></span></li>
-</ul>
-<h3><code></code></h3>
-Templates are shortcuts for frequently used fragments of text such as
-code patterns or complex text entities. They may contain variables
-which are only resolved at the time when the template is inserted
-within a context. Together with linked mode, inserting a template can
-create a on-the-fly edit mask within a text viewer.<br>
-<br>
-Templates are specified as text, variables are defined using the <span
- style="font-family: monospace;">${variable}</span> notation known from
-Ant, for example. The following snippet shows an example template for
-an instance check in Java:<br>
-<pre>if (${name} instanceof ${type}) {<br>&nbsp;&nbsp;&nbsp; ${type} ${new_name} = (${type})${name};<br>&nbsp;&nbsp;&nbsp; ${cursor}<br>}<br></pre>
-In this template, the variables (<span style="font-family: monospace;">name,
-type, ...</span><span style="font-family: sans-serif;">) are resolved
-when inserted into java source and changing one variable instance will
-also change the other. When leaving linked mode, the caret is placed at
-the </span><span style="font-family: monospace;">cursor</span><span
- style="font-family: sans-serif;"> variable.<br>
-<br>
-Template functionality can be added to a custom text editor by offering
-</span><span style="font-family: monospace;">TemplateProposal</span><span
- style="font-family: sans-serif;">s as content assist choices, which is
-simplified by using a </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;">subclass of </span></span><span
- style="font-family: monospace;">TemplateCompletionProcessor</span><span
- style="font-family: sans-serif;">. User template management can be
-offered by including a </span><span style="font-family: monospace;">TemplatePreferencePage</span><span
- style="font-family: sans-serif;"> which uses a </span><span
- style="font-family: monospace;">TemplateStore</span><span
- style="font-family: sans-serif;"> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> as the
-underlying model to store templates. The <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point can be used to allow other plug-ins to contribute
-templates to an editor. This is accomplished by using the <span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-subclasses of the above types.<br>
-<br>
-Template variables are resolved by a <span
- style="font-family: monospace;">TemplateVariableResolver.</span> <span
- style="font-family: monospace;">GlobalTemplateVariables</span> offers
-some default variables such as date, user, and selection, but advanced
-features such as resolving to language constructs can be performed in
-subclasses.<br>
-</span>
-<h4>Classes</h4>
-<ul>
- <li><span style="font-family: monospace;">Template</span><span
- style="font-family: sans-serif;"> a template consists of name, context
-type identifier, and a pattern.</span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateTranslator</span> and <span
- style="font-family: monospace;">TemplateBuffer</span> are used to
-parse the template grammar and don't need to be used usually.</span></li>
- <li><span style="font-family: sans-serif;">A <span
- style="font-family: monospace;">TemplateProposal </span>can be
-offered in content assist, possibly created by a subclass of <span
- style="font-family: monospace;">TemplateCompletionProcessor.</span></span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplateStore</span> and <span
- style="font-family: monospace;">ContextTypeRegistry</span> manage a
-set of templates within a plug-in and offer ways to store them in the
-preferences or externally in XML streams via a <span
- style="font-family: monospace;">TemplateReaderWriter</span>.<br>
- </span></li>
- <li><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">ContributionTemplateStore</span> and <span
- style="font-family: monospace;">ContributionContextTypeRegistry</span>
-add awareness for the </span><span style="font-family: sans-serif;"><span
- style="font-family: sans-serif;"> <span
- style="font-family: monospace;">org.eclipse.ui.editors.templates</span>
-extension point.</span></span></li>
- <li style="font-family: monospace;"><span
- style="font-family: sans-serif;"><span style="font-family: sans-serif;"><span
- style="font-family: monospace;">TemplatePreferencePage</span> allows
-the user to access the templates within a <span
- style="font-family: monospace;">TemplateStore</span>.</span></span></li>
-</ul>
-<ul>
-</ul>
-<h4>Example</h4>
-<pre><span style="font-family: sans-serif;">See the Template Editor Example in the <span
- style="font-weight: bold;">org.eclipse.ui.examples.javaeditor</span> project.<br></span></pre>
-</body>
-</html>

Back to the top